From patchwork Wed Dec 5 09:17:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 10713401 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 691FE18B8 for ; Wed, 5 Dec 2018 09:17:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59D2D2CD0E for ; Wed, 5 Dec 2018 09:17:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E25E2CD16; Wed, 5 Dec 2018 09:17:41 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 B1E6A2CD12 for ; Wed, 5 Dec 2018 09:17:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726924AbeLEJRk (ORCPT ); Wed, 5 Dec 2018 04:17:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36822 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726351AbeLEJRk (ORCPT ); Wed, 5 Dec 2018 04:17:40 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 475695F722; Wed, 5 Dec 2018 09:17:39 +0000 (UTC) Received: from hades.usersys.redhat.com (unknown [10.43.17.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08BED5D965; Wed, 5 Dec 2018 09:17:37 +0000 (UTC) From: Carlos Maiolino To: linux-fsdevel@vger.kernel.org Cc: hch@lst.de, adilger@dilger.ca, sandeen@redhat.com, david@fromorbit.com Subject: [PATCH 01/10] fs: Enable bmap() function to properly return errors Date: Wed, 5 Dec 2018 10:17:19 +0100 Message-Id: <20181205091728.29903-2-cmaiolino@redhat.com> In-Reply-To: <20181205091728.29903-1-cmaiolino@redhat.com> References: <20181205091728.29903-1-cmaiolino@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 05 Dec 2018 09:17:39 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP By now, bmap() will either return the physical block number related to the requested file offset or 0 in case of error or the requested offset maps into a hole. This patch makes the needed changes to enable bmap() to proper return errors, using the return value as an error return, and now, a pointer must be passed to bmap() to be filled with the mapped physical block. It will change the behavior of bmap() on return: - negative value in case of error - zero on success or map fell into a hole In case of a hole, the *block will be zero too Since this is a prep patch, by now, the only error return is -EINVAL if ->bmap doesn't exist. Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- drivers/md/md-bitmap.c | 16 ++++++++++------ fs/inode.c | 30 +++++++++++++++++------------- fs/jbd2/journal.c | 22 +++++++++++++++------- include/linux/fs.h | 2 +- mm/page_io.c | 11 +++++++---- 5 files changed, 50 insertions(+), 31 deletions(-) diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c index 1cd4f991792c..0668b2dd290e 100644 --- a/drivers/md/md-bitmap.c +++ b/drivers/md/md-bitmap.c @@ -363,7 +363,7 @@ static int read_page(struct file *file, unsigned long index, int ret = 0; struct inode *inode = file_inode(file); struct buffer_head *bh; - sector_t block; + sector_t block, blk_cur; pr_debug("read bitmap file (%dB @ %llu)\n", (int)PAGE_SIZE, (unsigned long long)index << PAGE_SHIFT); @@ -374,17 +374,21 @@ static int read_page(struct file *file, unsigned long index, goto out; } attach_page_buffers(page, bh); - block = index << (PAGE_SHIFT - inode->i_blkbits); + blk_cur = index << (PAGE_SHIFT - inode->i_blkbits); while (bh) { + block = blk_cur; + if (count == 0) bh->b_blocknr = 0; else { - bh->b_blocknr = bmap(inode, block); - if (bh->b_blocknr == 0) { - /* Cannot use this file! */ + ret = bmap(inode, &block); + if (ret || !block) { ret = -EINVAL; + bh->b_blocknr = 0; goto out; } + + bh->b_blocknr = block; bh->b_bdev = inode->i_sb->s_bdev; if (count < (1<i_blkbits)) count = 0; @@ -398,7 +402,7 @@ static int read_page(struct file *file, unsigned long index, set_buffer_mapped(bh); submit_bh(REQ_OP_READ, 0, bh); } - block++; + blk_cur++; bh = bh->b_this_page; } page->index = index; diff --git a/fs/inode.c b/fs/inode.c index 0cd47fe0dbe5..db681d310465 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1580,21 +1580,25 @@ EXPORT_SYMBOL(iput); /** * bmap - find a block number in a file - * @inode: inode of file - * @block: block to find - * - * Returns the block number on the device holding the inode that - * is the disk block number for the block of the file requested. - * That is, asked for block 4 of inode 1 the function will return the - * disk block relative to the disk start that holds that block of the - * file. + * @inode: inode owning the block number being requested + * @*block: pointer containing the block to find + * + * Replaces the value in *block with the block number on the device holding + * corresponding to the requested block number in the file. + * That is, asked for block 4 of inode 1 the function will replace the + * 4 in *block, with disk block relative to the disk start that holds that + * block of the file. + * + * Returns -EINVAL in case of error, 0 otherwise. If mapping falls into a + * hole, returns 0 and *block is also set to 0. */ -sector_t bmap(struct inode *inode, sector_t block) +int bmap(struct inode *inode, sector_t *block) { - sector_t res = 0; - if (inode->i_mapping->a_ops->bmap) - res = inode->i_mapping->a_ops->bmap(inode->i_mapping, block); - return res; + if (!inode->i_mapping->a_ops->bmap) + return -EINVAL; + + *block = inode->i_mapping->a_ops->bmap(inode->i_mapping, *block); + return 0; } EXPORT_SYMBOL(bmap); diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 8ef6b6daaa7a..7acaf6f55404 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -814,18 +814,23 @@ int jbd2_journal_bmap(journal_t *journal, unsigned long blocknr, { int err = 0; unsigned long long ret; + sector_t block = 0; if (journal->j_inode) { - ret = bmap(journal->j_inode, blocknr); - if (ret) - *retp = ret; - else { + block = blocknr; + ret = bmap(journal->j_inode, &block); + + if (ret || !block) { printk(KERN_ALERT "%s: journal block not found " "at offset %lu on %s\n", __func__, blocknr, journal->j_devname); err = -EIO; __journal_abort_soft(journal, err); + + } else { + *retp = block; } + } else { *retp = blocknr; /* +journal->j_blk_offset */ } @@ -1251,11 +1256,14 @@ journal_t *jbd2_journal_init_dev(struct block_device *bdev, journal_t *jbd2_journal_init_inode(struct inode *inode) { journal_t *journal; + sector_t blocknr; char *p; - unsigned long long blocknr; + int err = 0; + + blocknr = 0; + err = bmap(inode, &blocknr); - blocknr = bmap(inode, 0); - if (!blocknr) { + if (err || !blocknr) { pr_err("%s: Cannot locate journal superblock\n", __func__); return NULL; diff --git a/include/linux/fs.h b/include/linux/fs.h index 5f7f67bd33a5..71dac6e00e27 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2811,7 +2811,7 @@ static inline ssize_t generic_write_sync(struct kiocb *iocb, ssize_t count) extern void emergency_sync(void); extern void emergency_remount(void); #ifdef CONFIG_BLOCK -extern sector_t bmap(struct inode *, sector_t); +extern int bmap(struct inode *, sector_t *); #endif extern int notify_change(struct dentry *, struct iattr *, struct inode **); extern int inode_permission(struct inode *, int); diff --git a/mm/page_io.c b/mm/page_io.c index 57572ff46016..b52e3e2ec13c 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -177,8 +177,9 @@ int generic_swapfile_activate(struct swap_info_struct *sis, cond_resched(); - first_block = bmap(inode, probe_block); - if (first_block == 0) + first_block = probe_block; + ret = bmap(inode, &first_block); + if (ret || !first_block) goto bad_bmap; /* @@ -193,9 +194,11 @@ int generic_swapfile_activate(struct swap_info_struct *sis, block_in_page++) { sector_t block; - block = bmap(inode, probe_block + block_in_page); - if (block == 0) + block = probe_block + block_in_page; + ret = bmap(inode, &block); + if (ret || !block) goto bad_bmap; + if (block != first_block + block_in_page) { /* Discontiguity */ probe_block++; From patchwork Wed Dec 5 09:17:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 10713403 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9BFB41057 for ; Wed, 5 Dec 2018 09:17:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CA7E2CD18 for ; Wed, 5 Dec 2018 09:17:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80E422CD1A; Wed, 5 Dec 2018 09:17:59 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 264522CD18 for ; Wed, 5 Dec 2018 09:17:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726944AbeLEJR6 (ORCPT ); Wed, 5 Dec 2018 04:17:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53916 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726351AbeLEJR6 (ORCPT ); Wed, 5 Dec 2018 04:17:58 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3489B8553D; Wed, 5 Dec 2018 09:17:58 +0000 (UTC) Received: from hades.usersys.redhat.com (unknown [10.43.17.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id E35EE4DC3A; Wed, 5 Dec 2018 09:17:52 +0000 (UTC) From: Carlos Maiolino To: linux-fsdevel@vger.kernel.org Cc: hch@lst.de, adilger@dilger.ca, sandeen@redhat.com, david@fromorbit.com Subject: [PATCH 02/10] cachefiles: drop direct usage of ->bmap method. Date: Wed, 5 Dec 2018 10:17:20 +0100 Message-Id: <20181205091728.29903-3-cmaiolino@redhat.com> In-Reply-To: <20181205091728.29903-1-cmaiolino@redhat.com> References: <20181205091728.29903-1-cmaiolino@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 05 Dec 2018 09:17:58 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace the direct usage of ->bmap method by a bmap() call. Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- fs/cachefiles/rdwr.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c index 40f7595aad10..a3ee23fe9269 100644 --- a/fs/cachefiles/rdwr.c +++ b/fs/cachefiles/rdwr.c @@ -400,7 +400,7 @@ int cachefiles_read_or_alloc_page(struct fscache_retrieval *op, struct cachefiles_object *object; struct cachefiles_cache *cache; struct inode *inode; - sector_t block0, block; + sector_t block; unsigned shift; int ret; @@ -416,7 +416,6 @@ int cachefiles_read_or_alloc_page(struct fscache_retrieval *op, inode = d_backing_inode(object->backer); ASSERT(S_ISREG(inode->i_mode)); - ASSERT(inode->i_mapping->a_ops->bmap); ASSERT(inode->i_mapping->a_ops->readpages); /* calculate the shift required to use bmap */ @@ -432,12 +431,14 @@ int cachefiles_read_or_alloc_page(struct fscache_retrieval *op, * enough for this as it doesn't indicate errors, but it's all we've * got for the moment */ - block0 = page->index; - block0 <<= shift; + block = page->index; + block <<= shift; + + ret = bmap(inode, &block); + ASSERT(!ret); - block = inode->i_mapping->a_ops->bmap(inode->i_mapping, block0); _debug("%llx -> %llx", - (unsigned long long) block0, + (unsigned long long) (page->index << shift), (unsigned long long) block); if (block) { @@ -709,7 +710,6 @@ int cachefiles_read_or_alloc_pages(struct fscache_retrieval *op, inode = d_backing_inode(object->backer); ASSERT(S_ISREG(inode->i_mode)); - ASSERT(inode->i_mapping->a_ops->bmap); ASSERT(inode->i_mapping->a_ops->readpages); /* calculate the shift required to use bmap */ @@ -726,7 +726,7 @@ int cachefiles_read_or_alloc_pages(struct fscache_retrieval *op, ret = space ? -ENODATA : -ENOBUFS; list_for_each_entry_safe(page, _n, pages, lru) { - sector_t block0, block; + sector_t block; /* we assume the absence or presence of the first block is a * good enough indication for the page as a whole @@ -734,13 +734,14 @@ int cachefiles_read_or_alloc_pages(struct fscache_retrieval *op, * good enough for this as it doesn't indicate errors, but * it's all we've got for the moment */ - block0 = page->index; - block0 <<= shift; + block = page->index; + block <<= shift; + + ret = bmap(inode, &block); + ASSERT(!ret); - block = inode->i_mapping->a_ops->bmap(inode->i_mapping, - block0); _debug("%llx -> %llx", - (unsigned long long) block0, + (unsigned long long) (page->index << shift), (unsigned long long) block); if (block) { From patchwork Wed Dec 5 09:17:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 10713405 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 34DC41057 for ; Wed, 5 Dec 2018 09:18:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 265FF2BE54 for ; Wed, 5 Dec 2018 09:18:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1AAF92CD16; Wed, 5 Dec 2018 09:18:02 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 B97CA2BE54 for ; Wed, 5 Dec 2018 09:18:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726979AbeLEJSB (ORCPT ); Wed, 5 Dec 2018 04:18:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49968 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726351AbeLEJSB (ORCPT ); Wed, 5 Dec 2018 04:18:01 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 173C387621; Wed, 5 Dec 2018 09:18:01 +0000 (UTC) Received: from hades.usersys.redhat.com (unknown [10.43.17.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id E1D475D967; Wed, 5 Dec 2018 09:17:59 +0000 (UTC) From: Carlos Maiolino To: linux-fsdevel@vger.kernel.org Cc: hch@lst.de, adilger@dilger.ca, sandeen@redhat.com, david@fromorbit.com Subject: [PATCH 03/10] ecryptfs: drop direct calls to ->bmap Date: Wed, 5 Dec 2018 10:17:21 +0100 Message-Id: <20181205091728.29903-4-cmaiolino@redhat.com> In-Reply-To: <20181205091728.29903-1-cmaiolino@redhat.com> References: <20181205091728.29903-1-cmaiolino@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 05 Dec 2018 09:18:01 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace direct ->bmap calls by bmap() method. Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- fs/ecryptfs/mmap.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index cdf358b209d9..ff323dccef36 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -538,16 +538,12 @@ static int ecryptfs_write_end(struct file *file, static sector_t ecryptfs_bmap(struct address_space *mapping, sector_t block) { - int rc = 0; - struct inode *inode; - struct inode *lower_inode; - - inode = (struct inode *)mapping->host; - lower_inode = ecryptfs_inode_to_lower(inode); - if (lower_inode->i_mapping->a_ops->bmap) - rc = lower_inode->i_mapping->a_ops->bmap(lower_inode->i_mapping, - block); - return rc; + struct inode *lower_inode = ecryptfs_inode_to_lower(mapping->host); + int ret = bmap(lower_inode, &block); + + if (ret) + return 0; + return block; } const struct address_space_operations ecryptfs_aops = { From patchwork Wed Dec 5 09:17:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 10713407 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD497109C for ; Wed, 5 Dec 2018 09:18:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E3C82BE54 for ; Wed, 5 Dec 2018 09:18:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 92C092CD12; Wed, 5 Dec 2018 09:18: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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 43A642BE54 for ; Wed, 5 Dec 2018 09:18:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727025AbeLEJSC (ORCPT ); Wed, 5 Dec 2018 04:18:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:13096 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726351AbeLEJSC (ORCPT ); Wed, 5 Dec 2018 04:18:02 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 880E489AE6; Wed, 5 Dec 2018 09:18:02 +0000 (UTC) Received: from hades.usersys.redhat.com (unknown [10.43.17.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5ED845D967; Wed, 5 Dec 2018 09:18:01 +0000 (UTC) From: Carlos Maiolino To: linux-fsdevel@vger.kernel.org Cc: hch@lst.de, adilger@dilger.ca, sandeen@redhat.com, david@fromorbit.com Subject: [PATCH 04/10 V2] fibmap: Use bmap instead of ->bmap method in ioctl_fibmap Date: Wed, 5 Dec 2018 10:17:22 +0100 Message-Id: <20181205091728.29903-5-cmaiolino@redhat.com> In-Reply-To: <20181205091728.29903-1-cmaiolino@redhat.com> References: <20181205091728.29903-1-cmaiolino@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 05 Dec 2018 09:18:02 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Now we have the possibility of proper error return in bmap, use bmap() function in ioctl_fibmap() instead of calling ->bmap method directly. V2: - Use a local sector_t variable to asign the block number instead of using direct casting. Signed-off-by: Carlos Maiolino --- fs/ioctl.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/fs/ioctl.c b/fs/ioctl.c index d64f622cac8b..e0cc0dd5f9aa 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -53,19 +53,26 @@ EXPORT_SYMBOL(vfs_ioctl); static int ioctl_fibmap(struct file *filp, int __user *p) { - struct address_space *mapping = filp->f_mapping; - int res, block; + struct inode *inode = file_inode(filp); + int error, usr_blk; + sector_t block; - /* do we support this mess? */ - if (!mapping->a_ops->bmap) - return -EINVAL; if (!capable(CAP_SYS_RAWIO)) return -EPERM; - res = get_user(block, p); - if (res) - return res; - res = mapping->a_ops->bmap(mapping, block); - return put_user(res, p); + + error = get_user(usr_blk, p); + if (error) + return error; + + block = usr_blk; + error = bmap(inode, &block); + if (error) + return error; + usr_blk = block; + + error = put_user(usr_blk, p); + + return error; } /** From patchwork Wed Dec 5 09:17:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 10713409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 56C5D109C for ; Wed, 5 Dec 2018 09:18:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46D492BE54 for ; Wed, 5 Dec 2018 09:18:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B52B2CD12; Wed, 5 Dec 2018 09:18:06 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 2B1072BE54 for ; Wed, 5 Dec 2018 09:18:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727135AbeLEJSE (ORCPT ); Wed, 5 Dec 2018 04:18:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42268 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726351AbeLEJSE (ORCPT ); Wed, 5 Dec 2018 04:18:04 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2F76FC02834C; Wed, 5 Dec 2018 09:18:04 +0000 (UTC) Received: from hades.usersys.redhat.com (unknown [10.43.17.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id D04235D967; Wed, 5 Dec 2018 09:18:02 +0000 (UTC) From: Carlos Maiolino To: linux-fsdevel@vger.kernel.org Cc: hch@lst.de, adilger@dilger.ca, sandeen@redhat.com, david@fromorbit.com Subject: [PATCH 05/10] fs: Move start and length fiemap fields into fiemap_extent_info Date: Wed, 5 Dec 2018 10:17:23 +0100 Message-Id: <20181205091728.29903-6-cmaiolino@redhat.com> In-Reply-To: <20181205091728.29903-1-cmaiolino@redhat.com> References: <20181205091728.29903-1-cmaiolino@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 05 Dec 2018 09:18:04 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As the overall goal to deprecate fibmap, Christoph suggested a rework of the ->fiemap API, in a way we could pass to it a callback to fill the fiemap structure (one of these callbacks being fiemap_fill_next_extent). To avoid the need to add several fields into the ->fiemap method, aggregate everything into a single data structure, and pass it along. This patch isn't suppose to add any functional change, only to update filesystems providing ->fiemap() method. Signed-off-by: Carlos Maiolino Reviewed-by: Christoph Hellwig --- fs/bad_inode.c | 3 +-- fs/btrfs/inode.c | 5 +++-- fs/ext2/ext2.h | 3 +-- fs/ext2/inode.c | 6 ++---- fs/ext4/ext4.h | 3 +-- fs/ext4/extents.c | 8 ++++---- fs/f2fs/data.c | 5 +++-- fs/f2fs/f2fs.h | 3 +-- fs/gfs2/inode.c | 5 +++-- fs/hpfs/file.c | 4 ++-- fs/ioctl.c | 16 ++++++++++------ fs/nilfs2/inode.c | 5 +++-- fs/nilfs2/nilfs.h | 3 +-- fs/ocfs2/extent_map.c | 5 +++-- fs/ocfs2/extent_map.h | 3 +-- fs/overlayfs/inode.c | 5 ++--- fs/xfs/xfs_iops.c | 10 +++++----- include/linux/fs.h | 21 +++++++++++---------- 18 files changed, 57 insertions(+), 56 deletions(-) diff --git a/fs/bad_inode.c b/fs/bad_inode.c index 8035d2a44561..21dfaf876814 100644 --- a/fs/bad_inode.c +++ b/fs/bad_inode.c @@ -120,8 +120,7 @@ static struct posix_acl *bad_inode_get_acl(struct inode *inode, int type) } static int bad_inode_fiemap(struct inode *inode, - struct fiemap_extent_info *fieinfo, u64 start, - u64 len) + struct fiemap_extent_info *fieinfo) { return -EIO; } diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 4a2f9f7fd96e..8afa1ac3d5e9 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8619,9 +8619,10 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) #define BTRFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC) -static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - __u64 start, __u64 len) +static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo) { + u64 start = fieinfo->fi_start; + u64 len = fieinfo->fi_len; int ret; ret = fiemap_check_flags(fieinfo, BTRFS_FIEMAP_FLAGS); diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h index e770cd100a6a..368e3e1f201f 100644 --- a/fs/ext2/ext2.h +++ b/fs/ext2/ext2.h @@ -775,8 +775,7 @@ extern void ext2_evict_inode(struct inode *); extern int ext2_get_block(struct inode *, sector_t, struct buffer_head *, int); extern int ext2_setattr (struct dentry *, struct iattr *); extern void ext2_set_inode_flags(struct inode *inode); -extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - u64 start, u64 len); +extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo); /* ioctl.c */ extern long ext2_ioctl(struct file *, unsigned int, unsigned long); diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index e4bb9386c045..98c932167fa8 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -855,11 +855,9 @@ const struct iomap_ops ext2_iomap_ops = { const struct iomap_ops ext2_iomap_ops; #endif /* CONFIG_FS_DAX */ -int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - u64 start, u64 len) +int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo) { - return generic_block_fiemap(inode, fieinfo, start, len, - ext2_get_block); + return generic_block_fiemap(inode, fieinfo, ext2_get_block); } static int ext2_writepage(struct page *page, struct writeback_control *wbc) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 3f89d0ab08fc..4ff340688b7b 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3140,8 +3140,7 @@ extern struct ext4_ext_path *ext4_find_extent(struct inode *, ext4_lblk_t, extern void ext4_ext_drop_refs(struct ext4_ext_path *); extern int ext4_ext_check_inode(struct inode *inode); extern ext4_lblk_t ext4_ext_next_allocated_block(struct ext4_ext_path *path); -extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - __u64 start, __u64 len); +extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo); extern int ext4_ext_precache(struct inode *inode); extern int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len); extern int ext4_insert_range(struct inode *inode, loff_t offset, loff_t len); diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 240b6dea5441..4efd8e5225ec 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -5045,9 +5045,10 @@ static int ext4_xattr_fiemap(struct inode *inode, return (error < 0 ? error : 0); } -int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - __u64 start, __u64 len) +int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo) { + u64 start = fieinfo->fi_start; + u64 len = fieinfo->fi_len; ext4_lblk_t start_blk; int error = 0; @@ -5069,8 +5070,7 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, /* fallback to generic here if not in extents fmt */ if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) - return generic_block_fiemap(inode, fieinfo, start, len, - ext4_get_block); + return generic_block_fiemap(inode, fieinfo, ext4_get_block); if (fiemap_check_flags(fieinfo, EXT4_FIEMAP_FLAGS)) return -EBADR; diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index b293cb3e27a2..3ef592ebab1c 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1401,9 +1401,10 @@ static int f2fs_xattr_fiemap(struct inode *inode, return (err < 0 ? err : 0); } -int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - u64 start, u64 len) +int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo) { + u64 start = fieinfo->fi_start; + u64 len = fieinfo->fi_len; struct buffer_head map_bh; sector_t start_blk, last_blk; pgoff_t next_pgofs; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 1e031971a466..c2d0ab85d22a 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3096,8 +3096,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio); void __do_map_lock(struct f2fs_sb_info *sbi, int flag, bool lock); int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int create, int flag); -int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - u64 start, u64 len); +int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo); bool f2fs_should_update_inplace(struct inode *inode, struct f2fs_io_info *fio); bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio); void f2fs_invalidate_page(struct page *page, unsigned int offset, diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 648f0ca1ad57..9669ad6224da 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -2004,9 +2004,10 @@ static int gfs2_getattr(const struct path *path, struct kstat *stat, return 0; } -static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - u64 start, u64 len) +static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo) { + u64 start = fieinfo->fi_start; + u64 len = fieinfo->fi_len; struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_holder gh; int ret; diff --git a/fs/hpfs/file.c b/fs/hpfs/file.c index 1ecec124e76f..0eece4ae1f11 100644 --- a/fs/hpfs/file.c +++ b/fs/hpfs/file.c @@ -190,9 +190,9 @@ static sector_t _hpfs_bmap(struct address_space *mapping, sector_t block) return generic_block_bmap(mapping, block, hpfs_get_block); } -static int hpfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, u64 start, u64 len) +static int hpfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo) { - return generic_block_fiemap(inode, fieinfo, start, len, hpfs_get_block); + return generic_block_fiemap(inode, fieinfo, hpfs_get_block); } const struct address_space_operations hpfs_aops = { diff --git a/fs/ioctl.c b/fs/ioctl.c index e0cc0dd5f9aa..a8eae8916e01 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -208,6 +208,8 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg) fieinfo.fi_flags = fiemap.fm_flags; fieinfo.fi_extents_max = fiemap.fm_extent_count; fieinfo.fi_extents_start = ufiemap->fm_extents; + fieinfo.fi_start = fiemap.fm_start; + fieinfo.fi_len = len; if (fiemap.fm_extent_count != 0 && !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start, @@ -217,7 +219,7 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg) if (fieinfo.fi_flags & FIEMAP_FLAG_SYNC) filemap_write_and_wait(inode->i_mapping); - error = inode->i_op->fiemap(inode, &fieinfo, fiemap.fm_start, len); + error = inode->i_op->fiemap(inode, &fieinfo); fiemap.fm_flags = fieinfo.fi_flags; fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped; if (copy_to_user(ufiemap, &fiemap, sizeof(fiemap))) @@ -294,9 +296,11 @@ static inline loff_t blk_to_logical(struct inode *inode, sector_t blk) */ int __generic_block_fiemap(struct inode *inode, - struct fiemap_extent_info *fieinfo, loff_t start, - loff_t len, get_block_t *get_block) + struct fiemap_extent_info *fieinfo, + get_block_t *get_block) { + loff_t start = fieinfo->fi_start; + loff_t len = fieinfo->fi_len; struct buffer_head map_bh; sector_t start_blk, last_blk; loff_t isize = i_size_read(inode); @@ -453,12 +457,12 @@ EXPORT_SYMBOL(__generic_block_fiemap); */ int generic_block_fiemap(struct inode *inode, - struct fiemap_extent_info *fieinfo, u64 start, - u64 len, get_block_t *get_block) + struct fiemap_extent_info *fieinfo, + get_block_t *get_block) { int ret; inode_lock(inode); - ret = __generic_block_fiemap(inode, fieinfo, start, len, get_block); + ret = __generic_block_fiemap(inode, fieinfo, get_block); inode_unlock(inode); return ret; } diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c index 671085512e0f..1f37d086371c 100644 --- a/fs/nilfs2/inode.c +++ b/fs/nilfs2/inode.c @@ -992,9 +992,10 @@ void nilfs_dirty_inode(struct inode *inode, int flags) nilfs_transaction_commit(inode->i_sb); /* never fails */ } -int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - __u64 start, __u64 len) +int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo) { + u64 start = fieinfo->fi_start; + u64 len = fieinfo->fi_len; struct the_nilfs *nilfs = inode->i_sb->s_fs_info; __u64 logical = 0, phys = 0, size = 0; __u32 flags = 0; diff --git a/fs/nilfs2/nilfs.h b/fs/nilfs2/nilfs.h index a2f247b6a209..55d1307ed710 100644 --- a/fs/nilfs2/nilfs.h +++ b/fs/nilfs2/nilfs.h @@ -276,8 +276,7 @@ extern int nilfs_inode_dirty(struct inode *); int nilfs_set_file_dirty(struct inode *inode, unsigned int nr_dirty); extern int __nilfs_mark_inode_dirty(struct inode *, int); extern void nilfs_dirty_inode(struct inode *, int flags); -int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - __u64 start, __u64 len); +int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo); static inline int nilfs_mark_inode_dirty(struct inode *inode) { return __nilfs_mark_inode_dirty(inode, I_DIRTY); diff --git a/fs/ocfs2/extent_map.c b/fs/ocfs2/extent_map.c index 06cb96462bf9..e01fd38ea935 100644 --- a/fs/ocfs2/extent_map.c +++ b/fs/ocfs2/extent_map.c @@ -749,8 +749,7 @@ static int ocfs2_fiemap_inline(struct inode *inode, struct buffer_head *di_bh, #define OCFS2_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC) -int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - u64 map_start, u64 map_len) +int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo) { int ret, is_last; u32 mapping_end, cpos; @@ -759,6 +758,8 @@ int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, u64 len_bytes, phys_bytes, virt_bytes; struct buffer_head *di_bh = NULL; struct ocfs2_extent_rec rec; + u64 map_start = fieinfo->fi_start; + u64 map_len = fieinfo->fi_len; ret = fiemap_check_flags(fieinfo, OCFS2_FIEMAP_FLAGS); if (ret) diff --git a/fs/ocfs2/extent_map.h b/fs/ocfs2/extent_map.h index 1057586ec19f..793be96099c0 100644 --- a/fs/ocfs2/extent_map.h +++ b/fs/ocfs2/extent_map.h @@ -50,8 +50,7 @@ int ocfs2_get_clusters(struct inode *inode, u32 v_cluster, u32 *p_cluster, int ocfs2_extent_map_get_blocks(struct inode *inode, u64 v_blkno, u64 *p_blkno, u64 *ret_count, unsigned int *extent_flags); -int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - u64 map_start, u64 map_len); +int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo); int ocfs2_overwrite_io(struct inode *inode, struct buffer_head *di_bh, u64 map_start, u64 map_len); diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c index 6bcc9dedc342..d69c2528673f 100644 --- a/fs/overlayfs/inode.c +++ b/fs/overlayfs/inode.c @@ -465,8 +465,7 @@ int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags) return 0; } -static int ovl_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - u64 start, u64 len) +static int ovl_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo) { int err; struct inode *realinode = ovl_inode_real(inode); @@ -480,7 +479,7 @@ static int ovl_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, if (fieinfo->fi_flags & FIEMAP_FLAG_SYNC) filemap_write_and_wait(realinode->i_mapping); - err = realinode->i_op->fiemap(realinode, fieinfo, start, len); + err = realinode->i_op->fiemap(realinode, fieinfo,); revert_creds(old_cred); return err; diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index f48ffd7a8d3e..1040e8346286 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -1092,12 +1092,12 @@ xfs_vn_update_time( STATIC int xfs_vn_fiemap( - struct inode *inode, - struct fiemap_extent_info *fieinfo, - u64 start, - u64 length) + struct inode *inode, + struct fiemap_extent_info *fieinfo) { - int error; + u64 start = fieinfo->fi_start; + u64 length = fieinfo->fi_len; + int error; xfs_ilock(XFS_I(inode), XFS_IOLOCK_SHARED); if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR) { diff --git a/include/linux/fs.h b/include/linux/fs.h index 71dac6e00e27..a7ca228bd191 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1696,11 +1696,14 @@ extern bool may_open_dev(const struct path *path); * VFS FS_IOC_FIEMAP helper definitions. */ struct fiemap_extent_info { - unsigned int fi_flags; /* Flags as passed from user */ - unsigned int fi_extents_mapped; /* Number of mapped extents */ - unsigned int fi_extents_max; /* Size of fiemap_extent array */ - struct fiemap_extent __user *fi_extents_start; /* Start of - fiemap_extent array */ + unsigned int fi_flags; /* Flags as passed from user */ + u64 fi_start; + u64 fi_len; + unsigned int fi_extents_mapped; /* Number of mapped extents */ + unsigned int fi_extents_max; /* Size of fiemap_extent array */ + struct fiemap_extent __user *fi_extents_start; /* Start of + fiemap_extent + array */ }; int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical, u64 phys, u64 len, u32 flags); @@ -1847,8 +1850,7 @@ struct inode_operations { int (*setattr) (struct dentry *, struct iattr *); int (*getattr) (const struct path *, struct kstat *, u32, unsigned int); ssize_t (*listxattr) (struct dentry *, char *, size_t); - int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, - u64 len); + int (*fiemap)(struct inode *, struct fiemap_extent_info *); int (*update_time)(struct inode *, struct timespec64 *, int); int (*atomic_open)(struct inode *, struct dentry *, struct file *, unsigned open_flag, @@ -3207,11 +3209,10 @@ extern int vfs_readlink(struct dentry *, char __user *, int); extern int __generic_block_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - loff_t start, loff_t len, get_block_t *get_block); extern int generic_block_fiemap(struct inode *inode, - struct fiemap_extent_info *fieinfo, u64 start, - u64 len, get_block_t *get_block); + struct fiemap_extent_info *fieinfo, + get_block_t *get_block); extern struct file_system_type *get_filesystem(struct file_system_type *fs); extern void put_filesystem(struct file_system_type *fs); From patchwork Wed Dec 5 09:17:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 10713411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 801241057 for ; Wed, 5 Dec 2018 09:18:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 708972BE54 for ; Wed, 5 Dec 2018 09:18:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64E7A2CD12; Wed, 5 Dec 2018 09:18:07 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 07C0B2BE54 for ; Wed, 5 Dec 2018 09:18:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727182AbeLEJSG (ORCPT ); Wed, 5 Dec 2018 04:18:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59880 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727084AbeLEJSG (ORCPT ); Wed, 5 Dec 2018 04:18:06 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A1AE316972C; Wed, 5 Dec 2018 09:18:05 +0000 (UTC) Received: from hades.usersys.redhat.com (unknown [10.43.17.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 775025D967; Wed, 5 Dec 2018 09:18:04 +0000 (UTC) From: Carlos Maiolino To: linux-fsdevel@vger.kernel.org Cc: hch@lst.de, adilger@dilger.ca, sandeen@redhat.com, david@fromorbit.com Subject: [PATCH 06/10] iomap: Remove length and start fields from iomap_fiemap Date: Wed, 5 Dec 2018 10:17:24 +0100 Message-Id: <20181205091728.29903-7-cmaiolino@redhat.com> In-Reply-To: <20181205091728.29903-1-cmaiolino@redhat.com> References: <20181205091728.29903-1-cmaiolino@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 05 Dec 2018 09:18:05 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP fiemap_extent_info now embeds start and length parameters, users of iomap_fiemap() doesn't need to pass it individually anymore. Signed-off-by: Carlos Maiolino Reviewed-by: Christoph Hellwig --- fs/gfs2/inode.c | 4 +--- fs/iomap.c | 4 +++- fs/xfs/xfs_iops.c | 8 ++------ include/linux/iomap.h | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 9669ad6224da..f728f00c9998 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -2006,8 +2006,6 @@ static int gfs2_getattr(const struct path *path, struct kstat *stat, static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo) { - u64 start = fieinfo->fi_start; - u64 len = fieinfo->fi_len; struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_holder gh; int ret; @@ -2018,7 +2016,7 @@ static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo) if (ret) goto out; - ret = iomap_fiemap(inode, fieinfo, start, len, &gfs2_iomap_ops); + ret = iomap_fiemap(inode, fieinfo, &gfs2_iomap_ops); gfs2_glock_dq_uninit(&gh); diff --git a/fs/iomap.c b/fs/iomap.c index b0462b363bad..64cee9b6f133 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -1156,9 +1156,11 @@ iomap_fiemap_actor(struct inode *inode, loff_t pos, loff_t length, void *data, } int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fi, - loff_t start, loff_t len, const struct iomap_ops *ops) + const struct iomap_ops *ops) { struct fiemap_ctx ctx; + loff_t start = fi->fi_start; + loff_t len = fi->fi_len; loff_t ret; memset(&ctx, 0, sizeof(ctx)); diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 1040e8346286..2b04f69c2c58 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -1095,18 +1095,14 @@ xfs_vn_fiemap( struct inode *inode, struct fiemap_extent_info *fieinfo) { - u64 start = fieinfo->fi_start; - u64 length = fieinfo->fi_len; int error; xfs_ilock(XFS_I(inode), XFS_IOLOCK_SHARED); if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR) { fieinfo->fi_flags &= ~FIEMAP_FLAG_XATTR; - error = iomap_fiemap(inode, fieinfo, start, length, - &xfs_xattr_iomap_ops); + error = iomap_fiemap(inode, fieinfo, &xfs_xattr_iomap_ops); } else { - error = iomap_fiemap(inode, fieinfo, start, length, - &xfs_iomap_ops); + error = iomap_fiemap(inode, fieinfo, &xfs_iomap_ops); } xfs_iunlock(XFS_I(inode), XFS_IOLOCK_SHARED); diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 9a4258154b25..c2b5542694a2 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -145,7 +145,7 @@ int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops); int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - loff_t start, loff_t len, const struct iomap_ops *ops); + const struct iomap_ops *ops); loff_t iomap_seek_hole(struct inode *inode, loff_t offset, const struct iomap_ops *ops); loff_t iomap_seek_data(struct inode *inode, loff_t offset, From patchwork Wed Dec 5 09:17:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 10713413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A26A109C for ; Wed, 5 Dec 2018 09:18:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 693FE2BE54 for ; Wed, 5 Dec 2018 09:18:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5DD0A2CD12; Wed, 5 Dec 2018 09:18:08 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 176702BE54 for ; Wed, 5 Dec 2018 09:18:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727297AbeLEJSH (ORCPT ); Wed, 5 Dec 2018 04:18:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54180 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727084AbeLEJSH (ORCPT ); Wed, 5 Dec 2018 04:18:07 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E813308A946; Wed, 5 Dec 2018 09:18:07 +0000 (UTC) Received: from hades.usersys.redhat.com (unknown [10.43.17.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id E88875D967; Wed, 5 Dec 2018 09:18:05 +0000 (UTC) From: Carlos Maiolino To: linux-fsdevel@vger.kernel.org Cc: hch@lst.de, adilger@dilger.ca, sandeen@redhat.com, david@fromorbit.com Subject: [PATCH 07/10] fs: Use a void pointer to store fiemap_extent Date: Wed, 5 Dec 2018 10:17:25 +0100 Message-Id: <20181205091728.29903-8-cmaiolino@redhat.com> In-Reply-To: <20181205091728.29903-1-cmaiolino@redhat.com> References: <20181205091728.29903-1-cmaiolino@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 05 Dec 2018 09:18:07 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Once fieinfo will carry either a kernel pointer or a user pointer for holding struct fiemap_extent location , use a void pointer to hold its address. Signed-off-by: Carlos Maiolino --- include/linux/fs.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index a7ca228bd191..16a58dfe09cc 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1701,9 +1701,8 @@ struct fiemap_extent_info { u64 fi_len; unsigned int fi_extents_mapped; /* Number of mapped extents */ unsigned int fi_extents_max; /* Size of fiemap_extent array */ - struct fiemap_extent __user *fi_extents_start; /* Start of - fiemap_extent - array */ + void *fi_extents_start; /* Start of fiemap_extent + array */ }; int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical, u64 phys, u64 len, u32 flags); From patchwork Wed Dec 5 09:17:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 10713415 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F196109C for ; Wed, 5 Dec 2018 09:18:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 505A92BE54 for ; Wed, 5 Dec 2018 09:18:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 449B82CD12; Wed, 5 Dec 2018 09:18:10 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 C8F1F2BE54 for ; Wed, 5 Dec 2018 09:18:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727332AbeLEJSJ (ORCPT ); Wed, 5 Dec 2018 04:18:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57418 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727084AbeLEJSJ (ORCPT ); Wed, 5 Dec 2018 04:18:09 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 90A2130820EE; Wed, 5 Dec 2018 09:18:08 +0000 (UTC) Received: from hades.usersys.redhat.com (unknown [10.43.17.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64BAC5D967; Wed, 5 Dec 2018 09:18:07 +0000 (UTC) From: Carlos Maiolino To: linux-fsdevel@vger.kernel.org Cc: hch@lst.de, adilger@dilger.ca, sandeen@redhat.com, david@fromorbit.com Subject: [PATCH 08/10 V2] fiemap: Use a callback to fill fiemap extents Date: Wed, 5 Dec 2018 10:17:26 +0100 Message-Id: <20181205091728.29903-9-cmaiolino@redhat.com> In-Reply-To: <20181205091728.29903-1-cmaiolino@redhat.com> References: <20181205091728.29903-1-cmaiolino@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 05 Dec 2018 09:18:08 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As a goal to enable fiemap infrastructure to be used by fibmap too, we need a way to use different helpers to fill extent data, depending on its usage. One helper to fill extent data stored in user address space (used in fiemap), and another fo fill extent data stored in kernel address space (will be used in fibmap). This patch sets up the usage of a callback to be used to fill in the extents. It transforms the current fiemap_fill_next_extent, into a simple helper to call the callback, avoiding unneeded changes on any filesystem, and reutilizes the original function as the callback used by FIEMAP. V2: - Now based on the rework on fiemap_extent_info (previous was based on fiemap_ctx) Signed-off-by: Carlos Maiolino --- fs/ioctl.c | 39 +++++++++++++++++++++++---------------- include/linux/fs.h | 7 +++++++ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/fs/ioctl.c b/fs/ioctl.c index a8eae8916e01..6086978fe01e 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -75,25 +75,10 @@ static int ioctl_fibmap(struct file *filp, int __user *p) return error; } -/** - * fiemap_fill_next_extent - Fiemap helper function - * @fieinfo: Fiemap context passed into ->fiemap - * @logical: Extent logical start offset, in bytes - * @phys: Extent physical start offset, in bytes - * @len: Extent length, in bytes - * @flags: FIEMAP_EXTENT flags that describe this extent - * - * Called from file system ->fiemap callback. Will populate extent - * info as passed in via arguments and copy to user memory. On - * success, extent count on fieinfo is incremented. - * - * Returns 0 on success, -errno on error, 1 if this was the last - * extent that will fit in user array. - */ #define SET_UNKNOWN_FLAGS (FIEMAP_EXTENT_DELALLOC) #define SET_NO_UNMOUNTED_IO_FLAGS (FIEMAP_EXTENT_DATA_ENCRYPTED) #define SET_NOT_ALIGNED_FLAGS (FIEMAP_EXTENT_DATA_TAIL|FIEMAP_EXTENT_DATA_INLINE) -int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical, +int fiemap_fill_user_extent(struct fiemap_extent_info *fieinfo, u64 logical, u64 phys, u64 len, u32 flags) { struct fiemap_extent extent; @@ -130,6 +115,27 @@ int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical, return 1; return (flags & FIEMAP_EXTENT_LAST) ? 1 : 0; } + +/** + * fiemap_fill_next_extent - Fiemap helper function + * @fieinfo: Fiemap context passed into ->fiemap + * @logical: Extent logical start offset, in bytes + * @phys: Extent physical start offset, in bytes + * @len: Extent length, in bytes + * @flags: FIEMAP_EXTENT flags that describe this extent + * + * Called from file system ->fiemap callback. Will populate extent + * info as passed in via arguments and copy to user memory. On + * success, extent count on fieinfo is incremented. + * + * Returns 0 on success, -errno on error, 1 if this was the last + * extent that will fit in user array. + */ +int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical, + u64 phys, u64 len, u32 flags) +{ + return fieinfo->fi_cb(fieinfo, logical, phys, len, flags); +} EXPORT_SYMBOL(fiemap_fill_next_extent); /** @@ -210,6 +216,7 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg) fieinfo.fi_extents_start = ufiemap->fm_extents; fieinfo.fi_start = fiemap.fm_start; fieinfo.fi_len = len; + fieinfo.fi_cb = fiemap_fill_user_extent; if (fiemap.fm_extent_count != 0 && !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start, diff --git a/include/linux/fs.h b/include/linux/fs.h index 16a58dfe09cc..7a434979201c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -64,6 +64,7 @@ struct fscrypt_operations; struct fs_context; struct fs_parameter_description; struct fsinfo_kparams; +struct fiemap_extent_info; enum fsinfo_attribute; extern void __init inode_init(void); @@ -1695,6 +1696,10 @@ extern bool may_open_dev(const struct path *path); /* * VFS FS_IOC_FIEMAP helper definitions. */ + +typedef int (*fiemap_fill_cb)(struct fiemap_extent_info *fieinfo, u64 logical, + u64 phys, u64 len, u32 flags); + struct fiemap_extent_info { unsigned int fi_flags; /* Flags as passed from user */ u64 fi_start; @@ -1703,7 +1708,9 @@ struct fiemap_extent_info { unsigned int fi_extents_max; /* Size of fiemap_extent array */ void *fi_extents_start; /* Start of fiemap_extent array */ + fiemap_fill_cb fi_cb; }; + int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical, u64 phys, u64 len, u32 flags); int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags); From patchwork Wed Dec 5 09:17:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 10713417 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 41A121057 for ; Wed, 5 Dec 2018 09:18:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32CAC2BE54 for ; Wed, 5 Dec 2018 09:18:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 271D92CD12; Wed, 5 Dec 2018 09:18:12 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 B1B0C2BE54 for ; Wed, 5 Dec 2018 09:18:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727349AbeLEJSL (ORCPT ); Wed, 5 Dec 2018 04:18:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54206 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727347AbeLEJSK (ORCPT ); Wed, 5 Dec 2018 04:18:10 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F911315486E; Wed, 5 Dec 2018 09:18:10 +0000 (UTC) Received: from hades.usersys.redhat.com (unknown [10.43.17.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7D235D967; Wed, 5 Dec 2018 09:18:08 +0000 (UTC) From: Carlos Maiolino To: linux-fsdevel@vger.kernel.org Cc: hch@lst.de, adilger@dilger.ca, sandeen@redhat.com, david@fromorbit.com Subject: [PATCH 09/10 V2] Use FIEMAP for FIBMAP calls Date: Wed, 5 Dec 2018 10:17:27 +0100 Message-Id: <20181205091728.29903-10-cmaiolino@redhat.com> In-Reply-To: <20181205091728.29903-1-cmaiolino@redhat.com> References: <20181205091728.29903-1-cmaiolino@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 05 Dec 2018 09:18:10 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Enables the usage of FIEMAP ioctl infrastructure to handle FIBMAP calls. From now on, ->bmap() methods can start to be removed from filesystems which already provides ->fiemap(). This adds a new helper - bmap_fiemap() - which is used to fill in the fiemap request, call into the underlying filesystem and check the flags set in the extent requested. Add a new fiemap fill extent callback to handl the in-kernel only fiemap_extent structure used for FIBMAP. V2: - Now based on the updated fiemap_extent_info, - move the fiemap call itself to a new helper Signed-off-by: Carlos Maiolino --- fs/inode.c | 42 ++++++++++++++++++++++++++++++++++++++++-- fs/ioctl.c | 32 ++++++++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index db681d310465..f07cc183ddbd 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1578,6 +1578,40 @@ void iput(struct inode *inode) } EXPORT_SYMBOL(iput); +static int bmap_fiemap(struct inode *inode, sector_t *block) +{ + struct fiemap_extent_info fieinfo = { 0, }; + struct fiemap_extent fextent; + u64 start = *block << inode->i_blkbits; + int error = -EINVAL; + + fextent.fe_logical = 0; + fextent.fe_physical = 0; + fieinfo.fi_extents_max = 1; + fieinfo.fi_extents_mapped = 0; + fieinfo.fi_extents_start = &fextent; + fieinfo.fi_start = start; + fieinfo.fi_len = 1 << inode->i_blkbits; + fieinfo.fi_flags = 0; + fieinfo.fi_cb = fiemap_fill_kernel_extent; + + error = inode->i_op->fiemap(inode, &fieinfo); + + if (error) + return error; + + if (fieinfo.fi_flags & (FIEMAP_EXTENT_UNKNOWN | + FIEMAP_EXTENT_ENCODED | + FIEMAP_EXTENT_DATA_INLINE | + FIEMAP_EXTENT_UNWRITTEN)) + return -EINVAL; + + *block = (fextent.fe_physical + + (start - fextent.fe_logical)) >> inode->i_blkbits; + + return error; +} + /** * bmap - find a block number in a file * @inode: inode owning the block number being requested @@ -1594,10 +1628,14 @@ EXPORT_SYMBOL(iput); */ int bmap(struct inode *inode, sector_t *block) { - if (!inode->i_mapping->a_ops->bmap) + if (inode->i_op->fiemap) + return bmap_fiemap(inode, block); + else if (inode->i_mapping->a_ops->bmap) + *block = inode->i_mapping->a_ops->bmap(inode->i_mapping, + *block); + else return -EINVAL; - *block = inode->i_mapping->a_ops->bmap(inode->i_mapping, *block); return 0; } EXPORT_SYMBOL(bmap); diff --git a/fs/ioctl.c b/fs/ioctl.c index 6086978fe01e..bfa59df332bf 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -116,6 +116,38 @@ int fiemap_fill_user_extent(struct fiemap_extent_info *fieinfo, u64 logical, return (flags & FIEMAP_EXTENT_LAST) ? 1 : 0; } +int fiemap_fill_kernel_extent(struct fiemap_extent_info *fieinfo, u64 logical, + u64 phys, u64 len, u32 flags) +{ + struct fiemap_extent *extent = fieinfo->fi_extents_start; + + /* only count the extents */ + if (fieinfo->fi_extents_max == 0) { + fieinfo->fi_extents_mapped++; + return (flags & FIEMAP_EXTENT_LAST) ? 1 : 0; + } + + if (fieinfo->fi_extents_mapped >= fieinfo->fi_extents_max) + return 1; + + if (flags & SET_UNKNOWN_FLAGS) + flags |= FIEMAP_EXTENT_UNKNOWN; + if (flags & SET_NO_UNMOUNTED_IO_FLAGS) + flags |= FIEMAP_EXTENT_ENCODED; + if (flags & SET_NOT_ALIGNED_FLAGS) + flags |= FIEMAP_EXTENT_NOT_ALIGNED; + + extent->fe_logical = logical; + extent->fe_physical = phys; + extent->fe_length = len; + extent->fe_flags = flags; + + fieinfo->fi_extents_mapped++; + + if (fieinfo->fi_extents_mapped == fieinfo->fi_extents_max) + return 1; + return (flags & FIEMAP_EXTENT_LAST) ? 1 : 0; +} /** * fiemap_fill_next_extent - Fiemap helper function * @fieinfo: Fiemap context passed into ->fiemap diff --git a/include/linux/fs.h b/include/linux/fs.h index 7a434979201c..28bb523d532a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1711,6 +1711,8 @@ struct fiemap_extent_info { fiemap_fill_cb fi_cb; }; +int fiemap_fill_kernel_extent(struct fiemap_extent_info *info, u64 logical, + u64 phys, u64 len, u32 flags); int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical, u64 phys, u64 len, u32 flags); int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags); From patchwork Wed Dec 5 09:17:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 10713419 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2FFB1057 for ; Wed, 5 Dec 2018 09:18:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E35432BE54 for ; Wed, 5 Dec 2018 09:18:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7DB92CD12; Wed, 5 Dec 2018 09:18:12 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 85E702BE54 for ; Wed, 5 Dec 2018 09:18:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727382AbeLEJSM (ORCPT ); Wed, 5 Dec 2018 04:18:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54220 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727347AbeLEJSL (ORCPT ); Wed, 5 Dec 2018 04:18:11 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8055C306B661; Wed, 5 Dec 2018 09:18:11 +0000 (UTC) Received: from hades.usersys.redhat.com (unknown [10.43.17.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 56B0D5D967; Wed, 5 Dec 2018 09:18:10 +0000 (UTC) From: Carlos Maiolino To: linux-fsdevel@vger.kernel.org Cc: hch@lst.de, adilger@dilger.ca, sandeen@redhat.com, david@fromorbit.com Subject: [PATCH 10/10] xfs: Get rid of ->bmap Date: Wed, 5 Dec 2018 10:17:28 +0100 Message-Id: <20181205091728.29903-11-cmaiolino@redhat.com> In-Reply-To: <20181205091728.29903-1-cmaiolino@redhat.com> References: <20181205091728.29903-1-cmaiolino@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 05 Dec 2018 09:18:11 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We don't need ->bmap anymore, only usage for it was FIBMAP, which is now gone. Signed-off-by: Carlos Maiolino --- fs/xfs/xfs_aops.c | 24 ------------------------ fs/xfs/xfs_trace.h | 1 - 2 files changed, 25 deletions(-) diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 338b9d9984e0..26f5bb80d007 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -963,29 +963,6 @@ xfs_vm_releasepage( return iomap_releasepage(page, gfp_mask); } -STATIC sector_t -xfs_vm_bmap( - struct address_space *mapping, - sector_t block) -{ - struct xfs_inode *ip = XFS_I(mapping->host); - - trace_xfs_vm_bmap(ip); - - /* - * The swap code (ab-)uses ->bmap to get a block mapping and then - * bypasses the file system for actual I/O. We really can't allow - * that on reflinks inodes, so we have to skip out here. And yes, - * 0 is the magic code for a bmap error. - * - * Since we don't pass back blockdev info, we can't return bmap - * information for rt files either. - */ - if (xfs_is_reflink_inode(ip) || XFS_IS_REALTIME_INODE(ip)) - return 0; - return iomap_bmap(mapping, block, &xfs_iomap_ops); -} - STATIC int xfs_vm_readpage( struct file *unused, @@ -1024,7 +1001,6 @@ const struct address_space_operations xfs_address_space_operations = { .set_page_dirty = iomap_set_page_dirty, .releasepage = xfs_vm_releasepage, .invalidatepage = xfs_vm_invalidatepage, - .bmap = xfs_vm_bmap, .direct_IO = noop_direct_IO, .migratepage = iomap_migrate_page, .is_partially_uptodate = iomap_is_partially_uptodate, diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index 3043e5ed6495..d836b9b84aae 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -618,7 +618,6 @@ DEFINE_INODE_EVENT(xfs_readdir); #ifdef CONFIG_XFS_POSIX_ACL DEFINE_INODE_EVENT(xfs_get_acl); #endif -DEFINE_INODE_EVENT(xfs_vm_bmap); DEFINE_INODE_EVENT(xfs_file_ioctl); DEFINE_INODE_EVENT(xfs_file_compat_ioctl); DEFINE_INODE_EVENT(xfs_ioctl_setattr);