+
+ memset(&args, 0, sizeof(args));
+
+ path = argv[optind];
+ fd = btrfs_open_dir(path, &dirstream, 1);
+ if (fd < 0)
+ return 1;
+
+ ret = ioctl(fd, ioctlnum, &args);
+ e = errno;
+
+ if (ioctlnum == BTRFS_IOC_QUOTA_RESCAN_STATUS) {
+ close_file_or_dir(fd, dirstream);
+ if (ret < 0) {
+ error("could not obtain quota rescan status: %m");
+ return 1;
+ }
+ if (!args.flags)
+ printf("no rescan operation in progress\n");
+ 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;