From patchwork Mon Nov 13 15:47:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 10056331 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 D634960365 for ; Mon, 13 Nov 2017 15:48:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C833D2923C for ; Mon, 13 Nov 2017 15:48:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD0C82945D; Mon, 13 Nov 2017 15:48:03 +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 54C352937C for ; Mon, 13 Nov 2017 15:48:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753350AbdKMPsC (ORCPT ); Mon, 13 Nov 2017 10:48:02 -0500 Received: from mx2.suse.de ([195.135.220.15]:33282 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753342AbdKMPsC (ORCPT ); Mon, 13 Nov 2017 10:48:02 -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 6E807AAF1; Mon, 13 Nov 2017 15:48:00 +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 v3 1/2] fiemap: Factor out actual fiemap call code Date: Mon, 13 Nov 2017 17:47:52 +0200 Message-Id: <1510588073-5665-1-git-send-email-nborisov@suse.com> X-Mailer: git-send-email 2.7.4 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 --- V3: No change V2: No change 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 */