X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=cmds-quota.c;h=745889d125236e71e9fe096974f8e3ae26794eec;hb=30b852cd7e2299ba7795cd302d783724d88e101f;hp=89cc89cc6be39008274c3dadaa7867915f972e8c;hpb=92319d74d4799c9b3b32080a59cb3f999931a681;p=platform%2Fupstream%2Fbtrfs-progs.git diff --git a/cmds-quota.c b/cmds-quota.c index 89cc89c..745889d 100644 --- a/cmds-quota.c +++ b/cmds-quota.c @@ -24,6 +24,7 @@ #include "commands.h" #include "utils.h" +#include "help.h" static const char * const quota_cmd_group_usage[] = { "btrfs quota [options] ", @@ -34,7 +35,6 @@ static int quota_ctl(int cmd, int argc, char **argv) { int ret = 0; int fd; - int e; char *path = argv[1]; struct btrfs_ioctl_quota_ctl_args args; DIR *dirstream = NULL; @@ -45,18 +45,14 @@ static int quota_ctl(int cmd, int argc, char **argv) memset(&args, 0, sizeof(args)); args.cmd = cmd; - fd = open_file_or_dir(path, &dirstream); - if (fd < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", path); + fd = btrfs_open_dir(path, &dirstream, 1); + if (fd < 0) return 1; - } ret = ioctl(fd, BTRFS_IOC_QUOTA_CTL, &args); - e = errno; close_file_or_dir(fd, dirstream); if (ret < 0) { - fprintf(stderr, "ERROR: quota command failed: %s\n", - strerror(e)); + error("quota command failed: %m"); return 1; } return 0; @@ -73,7 +69,12 @@ static const char * const cmd_quota_enable_usage[] = { static int cmd_quota_enable(int argc, char **argv) { - int ret = quota_ctl(BTRFS_QUOTA_CTL_ENABLE, argc, argv); + int ret; + + clean_args_no_options(argc, argv, cmd_quota_enable_usage); + + ret = quota_ctl(BTRFS_QUOTA_CTL_ENABLE, argc, argv); + if (ret < 0) usage(cmd_quota_enable_usage); return ret; @@ -87,7 +88,12 @@ static const char * const cmd_quota_disable_usage[] = { static int cmd_quota_disable(int argc, char **argv) { - int ret = quota_ctl(BTRFS_QUOTA_CTL_DISABLE, argc, argv); + int ret; + + clean_args_no_options(argc, argv, cmd_quota_disable_usage); + + ret = quota_ctl(BTRFS_QUOTA_CTL_DISABLE, argc, argv); + if (ret < 0) usage(cmd_quota_disable_usage); return ret; @@ -109,11 +115,10 @@ static int cmd_quota_rescan(int argc, char **argv) int e; char *path = NULL; struct btrfs_ioctl_quota_rescan_args args; - int ioctlnum = BTRFS_IOC_QUOTA_RESCAN; + unsigned long ioctlnum = BTRFS_IOC_QUOTA_RESCAN; DIR *dirstream = NULL; int wait_for_completion = 0; - optind = 1; while (1) { int c = getopt(argc, argv, "sw"); if (c < 0) @@ -131,7 +136,7 @@ static int cmd_quota_rescan(int argc, char **argv) } if (ioctlnum != BTRFS_IOC_QUOTA_RESCAN && wait_for_completion) { - fprintf(stderr, "ERROR: -w cannot be used with -s\n"); + error("switch -w cannot be used with -s"); return 1; } @@ -141,43 +146,55 @@ static int cmd_quota_rescan(int argc, char **argv) memset(&args, 0, sizeof(args)); path = argv[optind]; - fd = open_file_or_dir(path, &dirstream); - if (fd < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", path); + fd = btrfs_open_dir(path, &dirstream, 1); + if (fd < 0) return 1; - } ret = ioctl(fd, ioctlnum, &args); e = errno; - if (wait_for_completion && (ret == 0 || e == EINPROGRESS)) { - ret = ioctl(fd, BTRFS_IOC_QUOTA_RESCAN_WAIT, &args); - e = errno; - } - close_file_or_dir(fd, dirstream); - - if (ioctlnum == BTRFS_IOC_QUOTA_RESCAN) { + if (ioctlnum == BTRFS_IOC_QUOTA_RESCAN_STATUS) { + close_file_or_dir(fd, dirstream); if (ret < 0) { - fprintf(stderr, "ERROR: quota rescan failed: " - "%s\n", strerror(e)); + error("could not obtain quota rescan status: %m"); return 1; - } else { - printf("quota rescan started\n"); } - } else { - if (!args.flags) { + if (!args.flags) printf("no rescan operation in progress\n"); - } else { + else printf("rescan operation running (current key %lld)\n", args.progress); + return 0; + } + + if (ret == 0) { + printf("quota rescan started\n"); + fflush(stdout); + } else if (ret < 0 && (!wait_for_completion || e != EINPROGRESS)) { + error("quota rescan failed: %m"); + close_file_or_dir(fd, dirstream); + return 1; + } + + if (wait_for_completion) { + ret = ioctl(fd, BTRFS_IOC_QUOTA_RESCAN_WAIT, &args); + e = errno; + if (ret < 0) { + error("quota rescan wait failed: %m"); + close_file_or_dir(fd, dirstream); + return 1; } } + close_file_or_dir(fd, dirstream); return 0; } +static const char quota_cmd_group_info[] = +"manage filesystem quota settings"; + const struct cmd_group quota_cmd_group = { - quota_cmd_group_usage, NULL, { + quota_cmd_group_usage, quota_cmd_group_info, { { "enable", cmd_quota_enable, cmd_quota_enable_usage, NULL, 0 }, { "disable", cmd_quota_disable, cmd_quota_disable_usage, NULL, 0 },