All of lore.kernel.org
 help / color / mirror / Atom feed
From: jeffm@suse.com
To: linux-btrfs@vger.kernel.org
Cc: Jeff Mahoney <jeffm@suse.com>
Subject: [PATCH 1/2] btrfs-progs: quota: fix printing during wait mode
Date: Tue, 17 Jan 2017 20:56:39 -0500	[thread overview]
Message-ID: <1484704600-16079-1-git-send-email-jeffm@suse.com> (raw)

From: Jeff Mahoney <jeffm@suse.com>

If we call "btrfs quota rescan -w", it will attempt to start the rescan
operation, wait for it, and then print the "quota rescan started" message.
The wait could last an arbitrary amount of time, so printing it after
the wait isn't very helpful.

This patch reworks how we print the rescan started message as well as the
printing of the messages, including adding an error message for status
query failures (which could be EPERM/EFAULT/ENOMEM, not just no rescan
in progress) and wait failures.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 cmds-quota.c | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/cmds-quota.c b/cmds-quota.c
index 75c032b..f9b422d 100644
--- a/cmds-quota.c
+++ b/cmds-quota.c
@@ -154,28 +154,42 @@ static int cmd_quota_rescan(int argc, char **argv)
 	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) {
-			error("quota rescan failed: %s", strerror(e));
+			error("could not obtain quota rescan status: %s",
+			      strerror(e));
 			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: %s", strerror(e));
+		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: %s",
+			      strerror(e));
+			close_file_or_dir(fd, dirstream);
+			return 1;
 		}
 	}
 
+	close_file_or_dir(fd, dirstream);
 	return 0;
 }
 
-- 
2.7.1


             reply	other threads:[~2017-01-18  2:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-18  1:56 jeffm [this message]
2017-01-18  1:56 ` [PATCH 2/2] btrfs-progs: quota: Add -W option to rescan to wait without starting rescan jeffm
2017-01-24 10:59 ` [PATCH 1/2] btrfs-progs: quota: fix printing during wait mode David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1484704600-16079-1-git-send-email-jeffm@suse.com \
    --to=jeffm@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.