From patchwork Tue Oct 31 14:10:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 10034611 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 C2A7D60291 for ; Tue, 31 Oct 2017 14:10:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56EA8287E9 for ; Tue, 31 Oct 2017 14:10:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 439F72895F; Tue, 31 Oct 2017 14:10:20 +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 C7DC928713 for ; Tue, 31 Oct 2017 14:10:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752369AbdJaOKT (ORCPT ); Tue, 31 Oct 2017 10:10:19 -0400 Received: from mx2.suse.de ([195.135.220.15]:48987 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752209AbdJaOKR (ORCPT ); Tue, 31 Oct 2017 10:10:17 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id DA002ADE5; Tue, 31 Oct 2017 14:10:15 +0000 (UTC) From: Nikolay Borisov To: linux-xfs@vger.kernel.org Cc: fstests@vger.kernel.org, darrick.wong@oracle.com, Nikolay Borisov Subject: [PATCH v2 1/2] fiemap: Factor out actual fiemap call code Date: Tue, 31 Oct 2017 16:10:10 +0200 Message-Id: <1509459011-7398-1-git-send-email-nborisov@suse.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509107832-22286-1-git-send-email-nborisov@suse.com> References: <1509107832-22286-1-git-send-email-nborisov@suse.com> Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This will be needed to in a subsequent patch to avoid code duplication Signed-off-by: Nikolay Borisov --- v2: * Incorporated Daricks feedback - removed variables which weren't introduced until the next patch as a result the build with this patch was broken. This is fixed now io/fiemap.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/io/fiemap.c b/io/fiemap.c index e6fd66da753d..08391f69d9bd 100644 --- a/io/fiemap.c +++ b/io/fiemap.c @@ -211,6 +211,31 @@ calc_print_format( } } +static int +__fiemap( + struct fiemap * fiemap, + int mapsize, + __u32 flags, + __u64 start, + __u64 length) { + + int ret; + + memset(fiemap, 0, mapsize); + fiemap->fm_flags = flags; + fiemap->fm_start = start; + fiemap->fm_length = length; + fiemap->fm_extent_count = EXTENT_BATCH; + ret = ioctl(file->fd, FS_IOC_FIEMAP, fiemap); + if (ret < 0) { + fprintf(stderr, "%s: ioctl(FS_IOC_FIEMAP) [\"%s\"]: " + "%s\n", progname, file->name, strerror(errno)); + return ret; + } + + return 0; +} + int fiemap_f( int argc, @@ -266,19 +291,11 @@ fiemap_f( while (!last && (cur_extent != max_extents)) { - memset(fiemap, 0, map_size); - fiemap->fm_flags = fiemap_flags; - fiemap->fm_start = last_logical; - fiemap->fm_length = -1LL; - fiemap->fm_extent_count = EXTENT_BATCH; - - ret = ioctl(file->fd, FS_IOC_FIEMAP, (unsigned long)fiemap); + ret = __fiemap(fiemap, map_size, fiemap_flags, last_logical, + -1LL); if (ret < 0) { - fprintf(stderr, "%s: ioctl(FS_IOC_FIEMAP) [\"%s\"]: " - "%s\n", progname, file->name, strerror(errno)); - free(fiemap); exitcode = 1; - return 0; + goto out; } /* No more extents to map, exit */