From patchwork Wed Nov 15 12:10:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 10059271 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 5EA566019D for ; Wed, 15 Nov 2017 12:10:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 588DA29F31 for ; Wed, 15 Nov 2017 12:10:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D51F29F33; Wed, 15 Nov 2017 12:10:29 +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 EEF2429F2C for ; Wed, 15 Nov 2017 12:10:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757354AbdKOMK1 (ORCPT ); Wed, 15 Nov 2017 07:10:27 -0500 Received: from mx2.suse.de ([195.135.220.15]:46090 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757342AbdKOMK0 (ORCPT ); Wed, 15 Nov 2017 07:10:26 -0500 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 7C364AB9A; Wed, 15 Nov 2017 12:10:25 +0000 (UTC) From: Nikolay Borisov To: linux-xfs@vger.kernel.org Cc: fstests@vger.kernel.org, eguan@redhat.com, david@fromorbit.com, darrick.wong@oracle.com, Nikolay Borisov Subject: [PATCH v4 1/2] fiemap: Factor out actual fiemap call code Date: Wed, 15 Nov 2017 14:10:20 +0200 Message-Id: <1510747821-13270-1-git-send-email-nborisov@suse.com> X-Mailer: git-send-email 2.7.4 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@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 --- 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 */