From patchwork Wed Jan 18 01:56:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Mahoney X-Patchwork-Id: 9522489 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5F41260449 for ; Wed, 18 Jan 2017 02:15:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E9132854A for ; Wed, 18 Jan 2017 02:15:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 432FF28557; Wed, 18 Jan 2017 02:15:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7754F28554 for ; Wed, 18 Jan 2017 02:15:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751624AbdARCOO (ORCPT ); Tue, 17 Jan 2017 21:14:14 -0500 Received: from mx2.suse.de ([195.135.220.15]:49161 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751518AbdARCOM (ORCPT ); Tue, 17 Jan 2017 21:14:12 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id A71A7AB1D for ; Wed, 18 Jan 2017 01:56:48 +0000 (UTC) Received: by starscream.home.jeffm.io (Postfix, from userid 1000) id 36DC38BAF8; Tue, 17 Jan 2017 20:56:44 -0500 (EST) From: jeffm@suse.com To: linux-btrfs@vger.kernel.org Cc: Jeff Mahoney Subject: [PATCH 1/2] btrfs-progs: quota: fix printing during wait mode Date: Tue, 17 Jan 2017 20:56:39 -0500 Message-Id: <1484704600-16079-1-git-send-email-jeffm@suse.com> X-Mailer: git-send-email 2.7.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jeff Mahoney 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 --- 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; }