From patchwork Thu Sep 15 23:23:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 9334907 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 AEBC160839 for ; Thu, 15 Sep 2016 23:24:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A1AA29C62 for ; Thu, 15 Sep 2016 23:24:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EC3929C88; Thu, 15 Sep 2016 23:24:06 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from oss.sgi.com (oss.sgi.com [192.48.182.195]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 986C029C62 for ; Thu, 15 Sep 2016 23:24:04 +0000 (UTC) Received: from oss.sgi.com (localhost [IPv6:::1]) by oss.sgi.com (Postfix) with ESMTP id 999E37CA1; Thu, 15 Sep 2016 18:24:03 -0500 (CDT) X-Original-To: xfs@oss.sgi.com Delivered-To: xfs@oss.sgi.com Received: from relay.sgi.com (relay2.corp.sgi.com [137.38.102.29]) by oss.sgi.com (Postfix) with ESMTP id 6C7C37CA0 for ; Thu, 15 Sep 2016 18:24:01 -0500 (CDT) Received: from cuda.sgi.com (cuda2.sgi.com [192.48.176.25]) by relay2.corp.sgi.com (Postfix) with ESMTP id 3946530407A for ; Thu, 15 Sep 2016 16:24:01 -0700 (PDT) X-ASG-Debug-ID: 1473981839-0bf57b0f533278b0001-NocioJ Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by cuda.sgi.com with ESMTP id X9W2cFXmzLjveEso (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 15 Sep 2016 16:24:00 -0700 (PDT) X-Barracuda-Envelope-From: sandeen@redhat.com X-Barracuda-Effective-Source-IP: mx1.redhat.com[209.132.183.28] X-Barracuda-Apparent-Source-IP: 209.132.183.28 X-ASG-Whitelist: Client Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 313674DD58; Thu, 15 Sep 2016 23:23:59 +0000 (UTC) Received: from Liberator.example.com (ovpn03.gateway.prod.ext.phx2.redhat.com [10.5.9.3]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8FNNwOY012295 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 15 Sep 2016 19:23:58 -0400 To: xfs-oss , linux-xfs@vger.kernel.org From: Eric Sandeen Subject: [PATCH] xfs_quota: fix free command for foreign fs Message-ID: <4a5fdfec-d1a7-cef6-ba3d-50703dc56d44@redhat.com> X-ASG-Orig-Subj: [PATCH] xfs_quota: fix free command for foreign fs Date: Thu, 15 Sep 2016 18:23:58 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 15 Sep 2016 23:23:59 +0000 (UTC) X-Barracuda-Connect: mx1.redhat.com[209.132.183.28] X-Barracuda-Start-Time: 1473981839 X-Barracuda-Encrypted: ECDHE-RSA-AES256-GCM-SHA384 X-Barracuda-URL: https://192.48.176.25:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 3189 X-Virus-Scanned: by bsmtpd at sgi.com X-Barracuda-BRTS-Status: 1 X-BeenThere: xfs@oss.sgi.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: XFS Filesystem from SGI List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: xfs-bounces@oss.sgi.com Sender: xfs-bounces@oss.sgi.com X-Virus-Scanned: ClamAV using ClamSMTP The "free" command is really just a fancy df that knows about log space and realtime blocks for an xfs filesystem. We can simply use statfs to get more or less the same thing on a non-xfs filesystem, so, ah, do that I guess, and re-enable it. # quota/xfs_quota -f -x -c path -c free /mnt/test Filesystem Pathname [000] (F) /mnt/test /dev/sdb1 (uquota) Filesystem 1K-blocks Used Available Use% Pathname /dev/sdb1 20511356 45000 20466356 0% /mnt/test Fix the short help text for -N while we're at it. Signed-off-by: Eric Sandeen Reviewed-by: Bill O'Donnell diff --git a/quota/free.c b/quota/free.c index 3c8a5ce..cee15ee 100644 --- a/quota/free.c +++ b/quota/free.c @@ -77,34 +77,50 @@ mount_free_space_data( close(fd); return 0; } - if ((xfsctl(mount->fs_dir, fd, XFS_IOC_FSGEOMETRY_V1, &fsgeo)) < 0) { - perror("XFS_IOC_FSGEOMETRY_V1"); - close(fd); - return 0; - } - if ((xfsctl(mount->fs_dir, fd, XFS_IOC_FSCOUNTS, &fscounts)) < 0) { - perror("XFS_IOC_FSCOUNTS"); - close(fd); - return 0; + + if (!(mount->fs_flags & FS_FOREIGN)) { + if ((xfsctl(mount->fs_dir, fd, XFS_IOC_FSGEOMETRY_V1, + &fsgeo)) < 0) { + perror("XFS_IOC_FSGEOMETRY_V1"); + close(fd); + return 0; + } + if ((xfsctl(mount->fs_dir, fd, XFS_IOC_FSCOUNTS, + &fscounts)) < 0) { + perror("XFS_IOC_FSCOUNTS"); + close(fd); + return 0; + } + + logsize = fsgeo.logstart ? fsgeo.logblocks : 0; + count = (fsgeo.datablocks - logsize) * fsgeo.blocksize; + free = fscounts.freedata * fsgeo.blocksize; + *bcount = BTOBB(count); + *bfree = BTOBB(free); + *bused = BTOBB(count - free); + + count = fsgeo.rtextents * fsgeo.rtextsize * fsgeo.blocksize; + free = fscounts.freertx * fsgeo.rtextsize * fsgeo.blocksize; + *rcount = BTOBB(count); + *rfree = BTOBB(free); + *rused = BTOBB(count - free); + } else { + count = st.f_blocks * st.f_bsize; + free = st.f_bfree * st.f_bsize; + *bcount = BTOBB(count); + *bfree = BTOBB(free); + *bused = BTOBB(count - free); + + *rcount = BTOBB(0); + *rfree = BTOBB(0); + *rused = BTOBB(0); } - logsize = fsgeo.logstart ? fsgeo.logblocks : 0; - count = (fsgeo.datablocks - logsize) * fsgeo.blocksize; - free = fscounts.freedata * fsgeo.blocksize; - *bcount = BTOBB(count); - *bfree = BTOBB(free); - *bused = BTOBB(count - free); *icount = st.f_files; *ifree = st.f_ffree; *iused = st.f_files - st.f_ffree; - count = fsgeo.rtextents * fsgeo.rtextsize * fsgeo.blocksize; - free = fscounts.freertx * fsgeo.rtextsize * fsgeo.blocksize; - *rcount = BTOBB(count); - *rfree = BTOBB(free); - *rused = BTOBB(count - free); - close(fd); return 1; } @@ -369,9 +385,10 @@ free_init(void) free_cmd.cfunc = free_f; free_cmd.argmin = 0; free_cmd.argmax = -1; - free_cmd.args = _("[-bir] [-hn] [-f file]"); + free_cmd.args = _("[-bir] [-hN] [-f file]"); free_cmd.oneline = _("show free and used counts for blocks and inodes"); free_cmd.help = free_help; + free_cmd.flags = CMD_FLAG_FOREIGN_OK; add_command(&free_cmd); }