diff --git a/cmd/rmr.go b/cmd/rmr.go index b2bbf328e9be..21f0ae3d9d23 100644 --- a/cmd/rmr.go +++ b/cmd/rmr.go @@ -42,14 +42,17 @@ $ juicefs rmr /mnt/jfs/foo`, } } -func openController(path string) (*os.File, error) { - mp, err := findMountpoint(path) +func openController(dpath string) (*os.File, error) { + st, err := os.Stat(dpath) if err != nil { return nil, err } - fp, err := os.OpenFile(filepath.Join(mp, ".jfs.control"), os.O_RDWR, 0) + if !st.IsDir() { + dpath = filepath.Dir(dpath) + } + fp, err := os.OpenFile(filepath.Join(dpath, ".jfs.control"), os.O_RDWR, 0) if os.IsNotExist(err) { - fp, err = os.OpenFile(filepath.Join(mp, ".control"), os.O_RDWR, 0) + fp, err = os.OpenFile(filepath.Join(dpath, ".control"), os.O_RDWR, 0) } return fp, err } diff --git a/cmd/warmup.go b/cmd/warmup.go index 7927c55f73c1..8f2c7f3b3801 100644 --- a/cmd/warmup.go +++ b/cmd/warmup.go @@ -192,16 +192,23 @@ func warmup(ctx *cli.Context) error { // find mount point first := paths[0] - mp, err := findMountpoint(first) - if err != nil { - return err - } - controller, err := openController(mp) + controller, err := openController(first) if err != nil { return fmt.Errorf("open control file for %s: %s", first, err) } defer controller.Close() + mp := first + for ; mp != "/"; mp = filepath.Dir(mp) { + inode, err := utils.GetFileInode(mp) + if err != nil { + logger.Fatalf("lookup inode for %s: %s", mp, err) + } + if inode == uint64(meta.RootInode) { + break + } + } + threads := ctx.Uint("threads") if threads == 0 { logger.Warnf("threads should be larger than 0, reset it to 1")