X-Spam-Checker-Version: SpamAssassin 3.4.0-r929098 (2010-03-30) on oss.sgi.com X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,J_CHICKENPOX_66 autolearn=no version=3.4.0-r929098 Received: from cuda.sgi.com (cuda2.sgi.com [192.48.176.25]) by oss.sgi.com (8.14.3/8.14.3/SuSE Linux 0.8) with ESMTP id o5BFpH6o144740 for ; Fri, 11 Jun 2010 10:51:17 -0500 X-ASG-Debug-ID: 1276271630-1f4d034b0000-NocioJ X-Barracuda-URL: http://cuda.sgi.com:80/cgi-bin/mark.cgi Received: from mail.sandeen.net (localhost [127.0.0.1]) by cuda.sgi.com (Spam Firewall) with ESMTP id 3F9283BF314 for ; Fri, 11 Jun 2010 08:53:51 -0700 (PDT) Received: from mail.sandeen.net (64-131-60-146.usfamily.net [64.131.60.146]) by cuda.sgi.com with ESMTP id 9HBYgAbMIC7fL0Jt for ; Fri, 11 Jun 2010 08:53:51 -0700 (PDT) Received: from liberator.sandeen.net (liberator.sandeen.net [10.0.0.4]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.sandeen.net (Postfix) with ESMTP id 346EA42B9C5D; Fri, 11 Jun 2010 10:53:50 -0500 (CDT) Message-ID: <4C125C0D.4080600@sandeen.net> Date: Fri, 11 Jun 2010 10:53:49 -0500 From: Eric Sandeen User-Agent: Thunderbird 2.0.0.24 (Macintosh/20100228) MIME-Version: 1.0 To: Tao Ma CC: xfs@oss.sgi.com, Christoph Hellwig , linux-kernel@vger.kernel.org, Alex Elder X-ASG-Orig-Subj: Re: [PATCH] xfs: Make fiemap works with sparse file. Subject: Re: [PATCH] xfs: Make fiemap works with sparse file. References: <1276236135-12051-1-git-send-email-tao.ma@oracle.com> In-Reply-To: <1276236135-12051-1-git-send-email-tao.ma@oracle.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Barracuda-Connect: 64-131-60-146.usfamily.net[64.131.60.146] X-Barracuda-Start-Time: 1276271631 X-Barracuda-Bayes: INNOCENT GLOBAL 0.0000 1.0000 -2.0210 X-Barracuda-Virus-Scanned: by cuda.sgi.com at sgi.com X-Barracuda-Spam-Score: -1.92 X-Barracuda-Spam-Status: No, SCORE=-1.92 using per-user scores of TAG_LEVEL=2.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=2.1 tests=RDNS_DYNAMIC X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.2.32250 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.10 RDNS_DYNAMIC Delivered to trusted network by host with dynamic-looking rDNS X-Virus-Scanned: ClamAV version 0.94.2, clamav-milter version 0.94.2 on oss.sgi.com X-Virus-Status: Clean Tao Ma wrote: > In xfs_vn_fiemap, we set bvm_count to fi_extent_max + 1 and want > to return fi_extent_max extents, but actually it won't work for > a sparse file. The reason is that in xfs_getbmap we will > calculate holes and set it in 'out', while out is malloced by > bmv_count(fi_extent_max+1) which didn't consider holes. So in the > worst case, if 'out' vector looks like > [hole, extent, hole, extent, hole, ... hole, extent, hole], > we will only return half of fi_extent_max extents. > > So in xfs_vn_fiemap, we should consider this worst case. If the > user wants fi_extent_max extents, we need a 'out' with size of > 2 *fi_extent_max + 1. This all seems right to me, though your commit message above (+1) doesn't match the comment and code in the patch (+2) -Eric > Cc: Alex Elder > Cc: Christoph Hellwig > Cc: Dave Chinner > Signed-off-by: Tao Ma > --- > fs/xfs/linux-2.6/xfs_iops.c | 16 ++++++++++++++-- > 1 files changed, 14 insertions(+), 2 deletions(-) > > diff --git a/fs/xfs/linux-2.6/xfs_iops.c b/fs/xfs/linux-2.6/xfs_iops.c > index 9c8019c..1db92e3 100644 > --- a/fs/xfs/linux-2.6/xfs_iops.c > +++ b/fs/xfs/linux-2.6/xfs_iops.c > @@ -672,9 +672,21 @@ xfs_vn_fiemap( > else > bm.bmv_length = BTOBB(length); > > - /* We add one because in getbmap world count includes the header */ > + /* > + * It is a bit tricky for us to calculate the bmv_count from > + * fi_extent_max. > + * If we support to return fi_extent_max extents to the user, > + * we need at most 2 * fi_extent_max + 1 for bmv_count since > + * in xfs_getbmap we will calculate holes while fi_extent_max > + * don't have them. So in the worst case, bmv can looks like > + * [hole, extent, hole, extent, hole, ... hole, extent, hole]. > + * So there will be 2 *fi_extent_max + 1. > + * What's more, in getbmap world count have to include the > + * header, so we need another bmv. So the total number will > + * be 2 * fieinfo->fi_extents_max + 2. > + */ > bm.bmv_count = !fieinfo->fi_extents_max ? MAXEXTNUM : > - fieinfo->fi_extents_max + 1; > + 2 * fieinfo->fi_extents_max + 2; > bm.bmv_count = min_t(__s32, bm.bmv_count, > (PAGE_SIZE * 16 / sizeof(struct getbmapx))); > bm.bmv_iflags = BMV_IF_PREALLOC;