diff options
author | David Sterba <dsterba@suse.com> | 2016-12-12 18:38:47 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-12-14 15:06:36 +0100 |
commit | 281e476b4dd89d1e1314d3123d566c83b4253a2d (patch) | |
tree | 09462e84d1cba5041791650cf6fdd0378ccd85b3 /cmds-filesystem.c | |
parent | cc0a80b8f2fc36ca486ae224a4bea6d3e89917bd (diff) |
btrfs-progs: defrag: warn when deframgenting directories without -r
The current implementaion of defrag ioctl on directoreis does not do
what users expect. The -r needs to be specified, but we should also
print a warning to avoid confusion.
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-filesystem.c')
-rw-r--r-- | cmds-filesystem.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/cmds-filesystem.c b/cmds-filesystem.c index eb16875d..c66709b3 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -1109,6 +1109,35 @@ static int cmd_filesystem_defrag(int argc, char **argv) if (flush) defrag_global_range.flags |= BTRFS_DEFRAG_RANGE_START_IO; + /* + * Look for directory arguments and warn if the recursive mode is not + * requested, as this is not implemented as recursive defragmentation + * in kernel. The stat errors are silent here as we check them below. + */ + if (!recursive) { + int found = 0; + + for (i = optind; i < argc; i++) { + struct stat st; + + if (stat(argv[i], &st)) + continue; + + if (S_ISDIR(st.st_mode)) { + warning( + "directory specified but recursive mode not requested: %s", + argv[i]); + found = 1; + } + } + if (found) { + warning( +"a directory passed to the defrag ioctl will not process the files\n" +"recursively but will defragment the subvolume tree and the extent tree.\n" +"If this is not intended, please use option -r ."); + } + } + for (i = optind; i < argc; i++) { struct stat st; int defrag_err = 0; |