From patchwork Tue Jan 19 08:25:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fan Li X-Patchwork-Id: 8059121 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 96843BEEE5 for ; Tue, 19 Jan 2016 08:26:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9D89B2034C for ; Tue, 19 Jan 2016 08:26:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3456220328 for ; Tue, 19 Jan 2016 08:26:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932445AbcASI03 (ORCPT ); Tue, 19 Jan 2016 03:26:29 -0500 Received: from mailout3.samsung.com ([203.254.224.33]:42493 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751786AbcASI02 (ORCPT ); Tue, 19 Jan 2016 03:26:28 -0500 Received: from epcpsbgm2new.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O1600GX6Y3VMQ20@mailout3.samsung.com> for linux-fsdevel@vger.kernel.org; Tue, 19 Jan 2016 17:26:26 +0900 (KST) X-AuditID: cbfee61b-f793c6d00000236c-ca-569df3326328 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id C1.6A.09068.233FD965; Tue, 19 Jan 2016 17:26:26 +0900 (KST) Received: from lifan ([109.123.105.144]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O160030ZY32IS90@mmp2.samsung.com>; Tue, 19 Jan 2016 17:26:26 +0900 (KST) From: Fan Li To: 'Andreas Dilger' Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v2 3/3] rewrite __generic_block_fiemap() Date: Tue, 19 Jan 2016 16:25:50 +0800 Message-id: <003c01d15293$16806b40$438141c0$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=windows-1252 Content-transfer-encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-index: AdFSknQZlEFnwgM5Rh2V52ZP969HSA== Content-language: en-us X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrPLMWRmVeSWpSXmKPExsVy+t9jQV2jz3PDDCYskLRYdvIRk8WevSdZ HJg8WjaXe3zeJBfAFMVlk5Kak1mWWqRvl8CVsfbBKsaCCyoVZ9b9Ympg3C3VxcjJISFgIjHh +DsWCFtM4sK99WwgtpDALEaJt022XYxcQPYrRombG46DJdgE1CW2zOxmArFFBDQk2id8YQax mQUUJX6/nA42SFjAQmL+/ousIDaLgKrE3qOLwGxeAUuJt9sWM0PYghI/Jt8DqucA6tWTuH9R C2KMvMTmNW+ZIe5RkNhx9jUjxCo9iaO7D7FC1IhLTHrwkH0CI9CRCJNmIUyahWTSLCQdCxhZ VjFKpBYkFxQnpeca5aWW6xUn5haX5qXrJefnbmIEB+sz6R2Mh3e5H2IU4GBU4uGdYD83TIg1 say4MvcQowQHs5II77T3QCHelMTKqtSi/Pii0pzU4kOM0hwsSuK8+y5FhgkJpCeWpGanphak FsFkmTg4pRoYD0xayqGWMydG9Cvz0s8KXaIRL63nLV2lrl4wJeH+JnPJpjMz+lf6GKsvlLw0 p/KHRmqYagKHs22TW1EHfxbnq/uP3u6qsTddvemwo0WG+w6rrtlTnqct6ltvE8sqyvL75+7q WpF8sVOceQeFmyx61z5Lmfzs0e3NLRPiHmjPP8C5hCFJ185NiaU4I9FQi7moOBEAriBbQ1IC AAA= Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are a few redundant branches in this function and if there are more than two blocks of holes after the last extent of file, it would fail to add FIEMAP_EXTENT_LAST to the last extent. Simplify the codes in this patch. Signed-off-by: Fan Li --- fs/ioctl.c | 99 ++++++++++++++---------------------------------------------- 1 file changed, 23 insertions(+), 76 deletions(-) diff --git a/fs/ioctl.c b/fs/ioctl.c index 5d54377..04e4120 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -256,7 +256,6 @@ int __generic_block_fiemap(struct inode *inode, loff_t isize = i_size_read(inode); u64 logical = 0, phys = 0, size = 0; u32 flags = FIEMAP_EXTENT_MERGED; - bool past_eof = false, whole_file = false; int ret = 0; ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC); @@ -271,10 +270,8 @@ int __generic_block_fiemap(struct inode *inode, if (start >= isize) return 0; - if (start + len > isize) { - whole_file = true; + if (start + len > isize) len = isize - start; - } start_blk = logical_to_blk(inode, start); last_blk = logical_to_blk(inode, start + len - 1); @@ -300,91 +297,41 @@ int __generic_block_fiemap(struct inode *inode, if (!buffer_mapped(&map_bh)) { start_blk++; - /* - * We want to handle the case where there is an - * allocated block at the front of the file, and then - * nothing but holes up to the end of the file properly, - * to make sure that extent at the front gets properly - * marked with FIEMAP_EXTENT_LAST - */ - if (!past_eof && - blk_to_logical(inode, start_blk) >= isize) - past_eof = 1; - + /* Skip holes unless it indicates the EOF */ + if (blk_to_logical(inode, start_blk) < isize) + goto next; /* * First hole after going past the EOF, this is our * last extent */ - if (past_eof && size) { - flags = FIEMAP_EXTENT_MERGED|FIEMAP_EXTENT_LAST; - ret = fiemap_fill_next_extent(fieinfo, logical, - phys, size, - flags); - } else if (size) { - ret = fiemap_fill_next_extent(fieinfo, logical, - phys, size, flags); - size = 0; - } - - /* if we have holes up to/past EOF then we're done */ - if (start_blk > last_blk || past_eof || ret) - break; - } else { - /* - * We have gone over the length of what we wanted to - * map, and it wasn't the entire file, so add the extent - * we got last time and exit. - * - * This is for the case where say we want to map all the - * way up to the second to the last block in a file, but - * the last block is a hole, making the second to last - * block FIEMAP_EXTENT_LAST. In this case we want to - * see if there is a hole after the second to last block - * so we can mark it properly. If we found data after - * we exceeded the length we were requesting, then we - * are good to go, just add the extent to the fieinfo - * and break - */ - if (start_blk > last_blk && !whole_file) { - ret = fiemap_fill_next_extent(fieinfo, logical, - phys, size, - flags); - break; - } + flags |= FIEMAP_EXTENT_LAST; + } - /* - * if size != 0 then we know we already have an extent - * to add, so add it. - */ - if (size) { - ret = fiemap_fill_next_extent(fieinfo, logical, - phys, size, - flags); - if (ret) - break; - } + /* + * if size != 0 then we know we already have an extent + * to add, so add it. + */ + if (size) + ret = fiemap_fill_next_extent(fieinfo, logical, + phys, size, + flags); - logical = blk_to_logical(inode, start_blk); - phys = blk_to_logical(inode, map_bh.b_blocknr); - size = map_bh.b_size; - flags = FIEMAP_EXTENT_MERGED; + if (start_blk > last_blk || ret) + break; - start_blk += logical_to_blk(inode, size); + /* reset values for the next extent */ + logical = blk_to_logical(inode, start_blk); + phys = blk_to_logical(inode, map_bh.b_blocknr); + size = map_bh.b_size; + flags = FIEMAP_EXTENT_MERGED; - /* - * If we are past the EOF, then we need to make sure as - * soon as we find a hole that the last extent we found - * is marked with FIEMAP_EXTENT_LAST - */ - if (!past_eof && logical + size >= isize) - past_eof = true; - } + start_blk += logical_to_blk(inode, size); +next: cond_resched(); if (fatal_signal_pending(current)) { ret = -EINTR; break; } - } while (1); /* If ret is 1 then we just hit the end of the extent array */