btrfs-progs: quota: fix printing during wait mode
Subsystems (2)
PATCH 1/2 btrfs-progs: quota: fix printing during wait mode
From: Jeff Mahoney <[email protected]>
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.
--- cmds-quota.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-)
cmds-quota.c +27 -13
@@ -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 ; }
Signature · 1 line
2.7.1
PATCH 2/2 btrfs-progs: quota: Add -W option to rescan to wait without starting rescan
From: Jeff Mahoney <[email protected]>
This patch adds a new -W option to wait for a rescan without starting a new operation. This is useful for things like xfstests where we want do to do a "btrfs quota enable" and not continue until the subsequent rescan has finished.
In addition to documenting the new option in the man page, I've cleaned up the rescan entry to document the -w option a bit better.
--- Documentation/btrfs-quota.asciidoc | 10 +++++++--- cmds-quota.c | 21 +++++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-)
Documentation/btrfs-quota.asciidoc +7 -3
@@ -222,15 +222,19 @@ Disable subvolume quota support for a filesystem. *enable* <path>:: Enable subvolume quota support for a filesystem. -*rescan* [-s] <path>:: +*rescan* [-s|-w|-W] <path>:: Trash all qgroup numbers and scan the metadata again with the current config. + `Options` + -s:::: -show status of a running rescan operation. +Show status of a running rescan operation. + -w:::: -wait for rescan operation to finish(can be already in progress). +Start rescan operation and wait until it has finished before exiting. If a rescan is already running, wait until it finishes and then exit without starting a new one. + +-W:::: +Wait for rescan operation to finish and then exit. If a rescan is not already running, exit silently. EXIT STATUS -----------
cmds-quota.c +15 -6
@@ -121,14 +121,20 @@ static int cmd_quota_rescan(int argc, char **argv)int wait_for_completion =0 ;while (1 ) { -int c =getopt (argc, argv,"sw" ); +int c =getopt (argc, argv,"swW" );if (c <0 )break ;switch (c) {case 's' : ioctlnum =BTRFS_IOC_QUOTA_RESCAN_STATUS ;break ; +case 'W' : + ioctlnum =0 ; + wait_for_completion =1 ; +break ;case 'w' : +/* Reset it in case the user did both -W and -w */ + ioctlnum =BTRFS_IOC_QUOTA_RESCAN ; wait_for_completion =1 ;break ;default :
@@ -136,8 +142,9 @@ static int cmd_quota_rescan(int argc, char **argv) } } -if (ioctlnum !=BTRFS_IOC_QUOTA_RESCAN && wait_for_completion) { -error ("switch -w cannot be used with -s" ); +if (ioctlnum ==BTRFS_IOC_QUOTA_RESCAN_STATUS && wait_for_completion) { +error ("switch -%c cannot be used with -s" , + ioctlnum ?'w' :'W' );return 1 ; }
@@ -151,8 +158,10 @@ static int cmd_quota_rescan(int argc, char **argv)if (fd <0 )return 1 ; - ret =ioctl (fd, ioctlnum, &args); - e = errno; +if (ioctlnum) { + ret =ioctl (fd, ioctlnum, &args); + e = errno; + }if (ioctlnum ==BTRFS_IOC_QUOTA_RESCAN_STATUS ) {close_file_or_dir (fd, dirstream);
@@ -169,7 +178,7 @@ static int cmd_quota_rescan(int argc, char **argv)return 0 ; } -if (ret ==0 ) { +if (ioctlnum ==BTRFS_IOC_QUOTA_RESCAN && ret ==0 ) {printf ("quota rescan started\n" );fflush (stdout); }else if (ret <0 && (!wait_for_completion || e !=EINPROGRESS )) {
Signature · 1 line
2.7.1
David Sterba
AppliedQuoted 7 lines · On Tue, Jan 17, 2017 at 08:56:39PM -0500, [email protected] wrote:
From: Jeff Mahoney <[email protected]>
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.
Quoted 6 lines
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 <[email protected]>
Applied, thanks.
I need to think about the 2nd patch, the command line option naming. The semantics is clear.