// gcTreeStore removes all treeStoreIDs not referenced by any non garbage // collected pod from the store. func gcTreeStore(ts *treestore.Store) error { // Take an exclusive lock to block other pods being created. // This is needed to avoid races between the below steps (getting the // list of referenced treeStoreIDs, getting the list of treeStoreIDs // from the store, removal of unreferenced treeStoreIDs) and new // pods/treeStores being created/referenced keyLock, err := lock.ExclusiveKeyLock(lockDir(), common.PrepareLock) if err != nil { return errwrap.Wrap(errors.New("cannot get exclusive prepare lock"), err) } defer keyLock.Close() referencedTreeStoreIDs, err := getReferencedTreeStoreIDs() if err != nil { return errwrap.Wrap(errors.New("cannot get referenced treestoreIDs"), err) } treeStoreIDs, err := ts.GetIDs() if err != nil { return errwrap.Wrap(errors.New("cannot get treestoreIDs from the store"), err) } for _, treeStoreID := range treeStoreIDs { if _, ok := referencedTreeStoreIDs[treeStoreID]; !ok { if err := ts.Remove(treeStoreID); err != nil { stderr.PrintE(fmt.Sprintf("error removing treestore %q", treeStoreID), err) } else { stderr.Printf("removed treestore %q", treeStoreID) } } } return nil }
func mountPodStage1(ts *treestore.Store, p *pkgPod.Pod) error { if !p.UsesOverlay() { return nil } s1Id, err := p.GetStage1TreeStoreID() if err != nil { return errwrap.Wrap(errors.New("error getting stage1 treeStoreID"), err) } s1rootfs := ts.GetRootFS(s1Id) stage1Dir := common.Stage1RootfsPath(p.Path()) overlayDir := filepath.Join(p.Path(), "overlay") imgDir := filepath.Join(overlayDir, s1Id) upperDir := filepath.Join(imgDir, "upper") workDir := filepath.Join(imgDir, "work") opts := fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", s1rootfs, upperDir, workDir) if err := syscall.Mount("overlay", stage1Dir, "overlay", 0, opts); err != nil { return errwrap.Wrap(errors.New("error mounting stage1"), err) } return nil }