From patchwork Fri Sep 30 20:53:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 9485649 X-Mozilla-Keys: nonjunk Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on sandeen.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RP_MATCHES_RCVD autolearn=ham autolearn_force=no version=3.4.0 X-Spam-HP: BAYES_00=-1.9,HEADER_FROM_DIFFERENT_DOMAINS=0.001, RP_MATCHES_RCVD=-0.1 X-Original-To: sandeen@sandeen.net Delivered-To: sandeen@sandeen.net Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by sandeen.net (Postfix) with ESMTP id 06C2F1431 for ; Fri, 30 Sep 2016 15:52:34 -0500 (CDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932382AbcI3UxF (ORCPT ); Fri, 30 Sep 2016 16:53:05 -0400 Received: from sandeen.net ([63.231.237.45]:57028 "EHLO sandeen.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751712AbcI3UxE (ORCPT ); Fri, 30 Sep 2016 16:53:04 -0400 Received: from Liberator.example.com (74-95-67-117-Minnesota.hfc.comcastbusiness.net [74.95.67.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by sandeen.net (Postfix) with ESMTPSA id 996771431; Fri, 30 Sep 2016 15:52:31 -0500 (CDT) Subject: [PATCH 2/5] xfs_io: factor out new get_last_inode() helper To: Eric Sandeen , linux-xfs References: <9f126dc7-3b1e-a1ed-7f23-48410a76adc2@redhat.com> From: Eric Sandeen Message-ID: Date: Fri, 30 Sep 2016 15:53:03 -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 In-Reply-To: <9f126dc7-3b1e-a1ed-7f23-48410a76adc2@redhat.com> Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org The inode command by default finds the last allocated inode in the filesystem via bulkstat, and this specific function is open-coded after other cases are handled, leading to a fairly long inode_f function and confusing code flow. Clean it up by factoring it into a new function, more refactoring will follow. Signed-off-by: Eric Sandeen --- io/open.c | 68 +++++++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 44 insertions(+), 24 deletions(-) diff --git a/io/open.c b/io/open.c index 5efa739..c8c82b7 100644 --- a/io/open.c +++ b/io/open.c @@ -767,14 +767,51 @@ inode_help(void) "\n")); } +static __u64 +get_last_inode(void) +{ + __u64 lastip = 0; + __u64 lastgrp = 0; + __s32 ocount = 0; + __u64 last_ino; + struct xfs_inogrp igroup[1024]; + struct xfs_fsop_bulkreq bulkreq; + + bulkreq.lastip = &lastip; + bulkreq.ubuffer = &igroup; + bulkreq.icount = sizeof(igroup) / sizeof(struct xfs_inogrp); + bulkreq.ocount = &ocount; + + for (;;) { + if (xfsctl(file->name, file->fd, XFS_IOC_FSINUMBERS, + &bulkreq)) { + perror("XFS_IOC_FSINUMBERS"); + return 0; + } + + /* Did we reach the last inode? */ + if (ocount == 0) + break; + + /* last inode in igroup table */ + lastgrp = ocount; + } + + lastgrp--; + + /* The last inode number in use */ + last_ino = igroup[lastgrp].xi_startino + + libxfs_highbit64(igroup[lastgrp].xi_allocmask); + + return last_ino; +} + static int inode_f( int argc, char **argv) { __s32 count = 0; - __s32 lastgrp = 0; - __u64 last = 0; __u64 lastino = 0; __u64 userino = 0; char *p; @@ -782,7 +819,6 @@ inode_f( int verbose = 0; int ret_next = 0; int cmd = 0; - struct xfs_inogrp igroup[1024]; struct xfs_fsop_bulkreq bulkreq; struct xfs_bstat bstat; @@ -854,29 +890,13 @@ inode_f( return command_usage(&inode_cmd); } - bulkreq.lastip = &last; - bulkreq.icount = 1024; /* User-defined maybe!? */ - bulkreq.ubuffer = &igroup; - bulkreq.ocount = &count; - - for (;;) { - if (xfsctl(file->name, file->fd, XFS_IOC_FSINUMBERS, - &bulkreq)) { - perror("XFS_IOC_FSINUMBERS"); - exitcode = 1; - return 0; - } - - if (count == 0) - break; - - lastgrp = count; + /* We are finding last inode in use */ + lastino = get_last_inode(); + if (!lastino) { + exitcode = 1; + return 0; } - lastgrp--; - lastino = igroup[lastgrp].xi_startino + - libxfs_highbit64(igroup[lastgrp].xi_allocmask); - if (verbose) printf("%llu:%d\n", lastino, lastino > XFS_MAXINUMBER_32 ? 64 : 32);