From patchwork Fri Sep 30 20:56:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 9485645 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 0AA961431 for ; Fri, 30 Sep 2016 15:55:37 -0500 (CDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751712AbcI3U4I (ORCPT ); Fri, 30 Sep 2016 16:56:08 -0400 Received: from sandeen.net ([63.231.237.45]:57364 "EHLO sandeen.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751400AbcI3U4H (ORCPT ); Fri, 30 Sep 2016 16:56:07 -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 EF05D1431; Fri, 30 Sep 2016 15:55:34 -0500 (CDT) Subject: [PATCH 4/5] xfs_io: refactor inode command To: Eric Sandeen , linux-xfs References: <9f126dc7-3b1e-a1ed-7f23-48410a76adc2@redhat.com> From: Eric Sandeen Message-ID: <4862fa94-e367-88fd-056a-c9748b6965de@sandeen.net> Date: Fri, 30 Sep 2016 15:56:06 -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_f function is a bit convoluted; the default find-last-inode case appears at the end, there are several return points, we print the same basic information using 2 different variables in 2 different locations depending on the mode we're in, the "inode not found" was a printf & exit in the middle of the function, etc. Move the default case up to the top so it's more obvious, not buried. Make a new var, result_ino, which holds whatever we want to print regardless of the mode, and then handle all the output at the end. Signed-off-by: Eric Sandeen --- io/open.c | 65 ++++++++++++++++++++++++++++-------------------------------- 1 files changed, 30 insertions(+), 35 deletions(-) diff --git a/io/open.c b/io/open.c index ba8b243..7d952a0 100644 --- a/io/open.c +++ b/io/open.c @@ -812,7 +812,7 @@ inode_f( char **argv) { __s32 count = 0; - __u64 lastino = 0; + __u64 result_ino = 0; __u64 userino = NULLFSINO; char *p; int c; @@ -855,8 +855,14 @@ inode_f( if (ret_next && userino == NULLFSINO) return command_usage(&inode_cmd); - if (userino != NULLFSINO) { - + if (userino == NULLFSINO) { + /* We are finding last inode in use */ + result_ino = get_last_inode(); + if (!result_ino) { + exitcode = 1; + return 0; + } + } else { if (ret_next) /* get next inode */ cmd = XFS_IOC_FSBULKSTAT; else /* get this inode */ @@ -868,43 +874,32 @@ inode_f( bulkreq.ocount = &count; if (xfsctl(file->name, file->fd, cmd, &bulkreq)) { - if (errno == EINVAL) { - if (!ret_next) - printf("0\n"); + if (!ret_next && errno == EINVAL) { + /* Not in use */ + result_ino = 0; } else { perror("xfsctl"); + exitcode = 1; + return 0; } - exitcode = 1; - return 0; - } - - if (ret_next) - userino = bstat.bs_ino; - - if (verbose) - printf("%llu:%d\n", - userino, - userino > XFS_MAXINUMBER_32 ? 64 : 32); - else - /* Inode in use */ - printf("%llu\n", userino); - return 0; - - } - - /* We are finding last inode in use */ - lastino = get_last_inode(); - if (!lastino) { - exitcode = 1; - return 0; + } else if (ret_next) /* The next inode in use */ + result_ino = bstat.bs_ino; + else /* The inode we asked about */ + result_ino = userino; + } + + if (verbose && result_ino) { + /* Requested verbose and we have an answer */ + printf("%llu:%d\n", result_ino, + result_ino > XFS_MAXINUMBER_32 ? 64 : 32); + } else if (userino == NULLFSINO) { + /* Just checking 32 or 64 bit presence, non-verbose */ + printf("%d\n", result_ino > XFS_MAXINUMBER_32 ? 1 : 0); + } else { + /* We asked about a specific inode, non-verbose */ + printf("%llu\n", result_ino); } - if (verbose) - printf("%llu:%d\n", lastino, - lastino > XFS_MAXINUMBER_32 ? 64 : 32); - else - printf("%d\n", lastino > XFS_MAXINUMBER_32 ? 1 : 0); - return 0; }