From patchwork Fri Oct 22 20:15:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12579013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 202B3C433EF for ; Fri, 22 Oct 2021 20:15:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF54A610CB for ; Fri, 22 Oct 2021 20:15:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233973AbhJVURq (ORCPT ); Fri, 22 Oct 2021 16:17:46 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:57130 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233848AbhJVURp (ORCPT ); Fri, 22 Oct 2021 16:17:45 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 51AC81FD61; Fri, 22 Oct 2021 20:15:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1634933726; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b5ZL8IsddVC5wtGTez6QqQY4LXm+jrHqut3eC/YGm54=; b=1VbQ5d4RHkVLYopROQIv5DlRaCivowZ1m4uf7LZVUaLX9c4UQYVF8isoj7rEvdnuo3+lWY e3v14ZTWCHa8rmVAW45mR+Ydt5iupoqYhRL2cJ3DHUmCJdc333dy+JwegakiNhMeHqc7/e fEvkJ0zkV0h0P/dD0hA8j/1ZRIuM/QE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1634933726; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b5ZL8IsddVC5wtGTez6QqQY4LXm+jrHqut3eC/YGm54=; b=WRAdleFPEf/SVTjmtn5SiKeluyzzqciVHyIb99DKKjviD/TrtC/uQMD+uX60rFsW0DJH5p TVicBjjSoYyrkvCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DADFF1348D; Fri, 22 Oct 2021 20:15:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MvXaGN0bc2HjdgAAMHmgww (envelope-from ); Fri, 22 Oct 2021 20:15:25 +0000 From: Goldwyn Rodrigues To: linux-fsdevel@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Goldwyn Rodrigues Subject: [RFC PATCH 1/5] mm: Use file parameter to determine bdi Date: Fri, 22 Oct 2021 15:15:01 -0500 Message-Id: <11dbd8d715fab9c7fe8536552c18fcb44a36b849.1634933121.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Goldwyn Rodrigues This is done so the bdi inode is derived correctly when file->f_mapping is not the same as mapping passed. Set conditionally because some callee pass NULL for file pointer. Signed-off-by: Goldwyn Rodrigues --- mm/readahead.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/readahead.c b/mm/readahead.c index d589f147f4c2..9f303a31f650 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -443,6 +443,9 @@ static void ondemand_readahead(struct readahead_control *ractl, unsigned long index = readahead_index(ractl); pgoff_t prev_index; + if (ractl->file) + bdi = inode_to_bdi(file_inode(ractl->file)); + /* * If the request exceeds the readahead window, allow the read to * be up to the optimal hardware IO size From patchwork Fri Oct 22 20:15:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12579015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C58C5C433F5 for ; Fri, 22 Oct 2021 20:15:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9EA46610CB for ; Fri, 22 Oct 2021 20:15:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234226AbhJVURy (ORCPT ); Fri, 22 Oct 2021 16:17:54 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:43424 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233848AbhJVURt (ORCPT ); Fri, 22 Oct 2021 16:17:49 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0E4AA212C6; Fri, 22 Oct 2021 20:15:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1634933730; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gruAYj2W5+dSZFH6GAIlb+7UeTkm9JbN30KUB4RxUoM=; b=WZd9SxStwDM7gIonuhJ1Px+SYVoT7BnaBv+KwiApusk1M+fGIzqRv9kwbYt2m+RB0PshWs woZc1zOLriMi7YPywiPD58+3vUxzD/bfYtGAyr79/WzN2ByvNoB5i54P5jI+VnJliS+Y2/ a+xufXkNSd2mpUeOlPJjFmiEEBVXYEA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1634933730; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gruAYj2W5+dSZFH6GAIlb+7UeTkm9JbN30KUB4RxUoM=; b=8SaHPDeCComtBMUwV/6i4n8zWUrJefXNNs1pGsL9mS0TWCPVCGipMYjNwWm9a+4z0m5JS5 BzXZXYXEaC9YroBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 910601348D; Fri, 22 Oct 2021 20:15:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YTJbFeEbc2HmdgAAMHmgww (envelope-from ); Fri, 22 Oct 2021 20:15:29 +0000 From: Goldwyn Rodrigues To: linux-fsdevel@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Goldwyn Rodrigues Subject: [RFC PATCH 2/5] mm: Switch mapping to device mapping Date: Fri, 22 Oct 2021 15:15:02 -0500 Message-Id: <98a26b87716dd6eec5214ee0dc2eac10eb47439d.1634933121.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Goldwyn Rodrigues Get the device offset and last_index from the filesystem and read it from the device directly. If the device page(s) have been read before, it can be picked up directly for reads. If not the page is read from the device. The page would be added to device's mapping instead of the file. Con: This moves the read from file's readpage to block device's readpage. Post read filesystem checks such as data CRC will be ignored. An option is to change readpage() prototype to include file offset and call file->f_mapping->a_ops->readpage(). Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/file.c | 2 +- include/linux/fs.h | 7 ++++++- mm/filemap.c | 34 ++++++++++++++++++++++++++-------- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index ba44039071e5..e171d822a05e 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -3654,7 +3654,7 @@ static ssize_t btrfs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) return ret; } - return filemap_read(iocb, to, ret); + return filemap_read(iocb, to, ret, NULL); } const struct file_operations btrfs_file_operations = { diff --git a/include/linux/fs.h b/include/linux/fs.h index 640574294216..9409f703bcd1 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3229,8 +3229,13 @@ extern ssize_t generic_write_checks(struct kiocb *, struct iov_iter *); extern int generic_write_check_limits(struct file *file, loff_t pos, loff_t *count); extern int generic_file_rw_checks(struct file *file_in, struct file *file_out); + +typedef pgoff_t (*file_offset_to_device_t)(struct file *filp, loff_t pos, + size_t len, pgoff_t *last_index); + ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *to, - ssize_t already_read); + ssize_t already_read, + file_offset_to_device_t file_offset_to_device); extern ssize_t generic_file_read_iter(struct kiocb *, struct iov_iter *); extern ssize_t __generic_file_write_iter(struct kiocb *, struct iov_iter *); extern ssize_t generic_file_write_iter(struct kiocb *, struct iov_iter *); diff --git a/mm/filemap.c b/mm/filemap.c index d1458ecf2f51..21033503b0a1 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2445,14 +2445,17 @@ static int filemap_readahead(struct kiocb *iocb, struct file *file, } static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter, - struct pagevec *pvec) + struct pagevec *pvec, + file_offset_to_device_t file_offset_to_device) { struct file *filp = iocb->ki_filp; struct address_space *mapping = filp->f_mapping; struct file_ra_state *ra = &filp->f_ra; + struct super_block *sb = file_inode(filp)->i_sb; pgoff_t index = iocb->ki_pos >> PAGE_SHIFT; pgoff_t last_index; struct page *page; + bool switched = false; int err = 0; last_index = DIV_ROUND_UP(iocb->ki_pos + iter->count, PAGE_SIZE); @@ -2461,6 +2464,19 @@ static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter, return -EINTR; filemap_get_read_batch(mapping, index, last_index, pvec); + if (!pagevec_count(pvec) && !switched && file_offset_to_device) { + pgoff_t idx, lidx; + + idx = file_offset_to_device(filp, iocb->ki_pos, + iter->count, &lidx); + if (idx) { + mapping = sb->s_bdev->bd_inode->i_mapping; + index = idx; + last_index = lidx; + switched = true; + goto retry; + } + } if (!pagevec_count(pvec)) { if (iocb->ki_flags & IOCB_NOIO) return -EAGAIN; @@ -2471,8 +2487,7 @@ static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter, if (!pagevec_count(pvec)) { if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ)) return -EAGAIN; - err = filemap_create_page(filp, mapping, - iocb->ki_pos >> PAGE_SHIFT, pvec); + err = filemap_create_page(filp, mapping, index, pvec); if (err == AOP_TRUNCATED_PAGE) goto retry; return err; @@ -2517,12 +2532,13 @@ static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter, * a negative error number. */ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter, - ssize_t already_read) + ssize_t already_read, + file_offset_to_device_t file_offset_to_device) { struct file *filp = iocb->ki_filp; struct file_ra_state *ra = &filp->f_ra; struct address_space *mapping = filp->f_mapping; - struct inode *inode = mapping->host; + struct inode *inode = file_inode(filp); struct pagevec pvec; int i, error = 0; bool writably_mapped; @@ -2547,7 +2563,8 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter, if ((iocb->ki_flags & IOCB_WAITQ) && already_read) iocb->ki_flags |= IOCB_NOWAIT; - error = filemap_get_pages(iocb, iter, &pvec); + error = filemap_get_pages(iocb, iter, &pvec, + file_offset_to_device); if (error < 0) break; @@ -2560,6 +2577,7 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter, * another truncate extends the file - this is desired though). */ isize = i_size_read(inode); + if (unlikely(iocb->ki_pos >= isize)) goto put_pages; end_offset = min_t(loff_t, isize, iocb->ki_pos + iter->count); @@ -2586,7 +2604,7 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter, page_size - offset); size_t copied; - if (end_offset < page_offset(page)) + if (!file_offset_to_device && (end_offset < page_offset(page))) break; if (i > 0) mark_page_accessed(page); @@ -2698,7 +2716,7 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) return retval; } - return filemap_read(iocb, iter, retval); + return filemap_read(iocb, iter, retval, NULL); } EXPORT_SYMBOL(generic_file_read_iter); From patchwork Fri Oct 22 20:15:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12579017 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08DF5C433FE for ; Fri, 22 Oct 2021 20:15:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB0CD61183 for ; Fri, 22 Oct 2021 20:15:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234235AbhJVUSB (ORCPT ); Fri, 22 Oct 2021 16:18:01 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:43434 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234176AbhJVURw (ORCPT ); Fri, 22 Oct 2021 16:17:52 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1FA5F212C6; Fri, 22 Oct 2021 20:15:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1634933734; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cNU+rWeDc4fnlH5M93y+Bu51/poFzNxm0nK8OEDtSz0=; b=Oyzn9CdUQC444jBRn9aDwK5Nc/QrFClXXJL+++OjZLRFlSkTrU6prGnCZzKAebwOzlsn11 sZIv6vUz0cxfTrrVrStpOB+3NaRLayBpZrLD+nr0YMOxhQfLlte7KC/V81tO/18K28iBTN ebD8nlbo7Jg2DulE/MfVPOM+D9zMOOQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1634933734; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cNU+rWeDc4fnlH5M93y+Bu51/poFzNxm0nK8OEDtSz0=; b=WXL7jFAIrRMQiEB8/i22yp920bW/o/c+bj+Od2RKTs6aQ1f1GPqfSWTWdm89+e4R3qqUL6 JxezbOGjfKNw0GDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 740021348D; Fri, 22 Oct 2021 20:15:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ueE3DOUbc2H0dgAAMHmgww (envelope-from ); Fri, 22 Oct 2021 20:15:33 +0000 From: Goldwyn Rodrigues To: linux-fsdevel@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Goldwyn Rodrigues Subject: [RFC PATCH 3/5] btrfs: Add sharedext mount option Date: Fri, 22 Oct 2021 15:15:03 -0500 Message-Id: <3905859891d47e0666737fa4c2d4459bd4178221.1634933122.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Goldwyn Rodrigues The mount option to use shared pages for shared extents. If set, pass custom file_offset_to_device function to filemap_read(). sharedext may not describe it well. Suggest a better name? TODO Checks: Check if the pagesize == blocksize Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/ctree.h | 1 + fs/btrfs/super.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 4aa4f4760b72..5c97112143d6 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1415,6 +1415,7 @@ enum { BTRFS_MOUNT_DISCARD_ASYNC = (1UL << 28), BTRFS_MOUNT_IGNOREBADROOTS = (1UL << 29), BTRFS_MOUNT_IGNOREDATACSUMS = (1UL << 30), + BTRFS_MOUNT_SHAREDEXT = (1UL << 31), }; #define BTRFS_DEFAULT_COMMIT_INTERVAL (30) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index d07b18b2b250..432f40f72466 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -397,6 +397,7 @@ enum { #ifdef CONFIG_BTRFS_FS_REF_VERIFY Opt_ref_verify, #endif + Opt_sharedext, Opt_err, }; @@ -471,6 +472,7 @@ static const match_table_t tokens = { #ifdef CONFIG_BTRFS_FS_REF_VERIFY {Opt_ref_verify, "ref_verify"}, #endif + {Opt_sharedext, "sharedext"}, {Opt_err, NULL}, }; @@ -1013,6 +1015,10 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, btrfs_set_opt(info->mount_opt, REF_VERIFY); break; #endif + case Opt_sharedext: + btrfs_info(info, "enabling shared memory for shared extents"); + btrfs_set_opt(info->mount_opt, SHAREDEXT); + break; case Opt_err: btrfs_err(info, "unrecognized mount option '%s'", p); ret = -EINVAL; From patchwork Fri Oct 22 20:15:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12579019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9344C43217 for ; Fri, 22 Oct 2021 20:15:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C22E9610CB for ; Fri, 22 Oct 2021 20:15:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234251AbhJVUSC (ORCPT ); Fri, 22 Oct 2021 16:18:02 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:57138 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234228AbhJVURz (ORCPT ); Fri, 22 Oct 2021 16:17:55 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E386C1FD61; Fri, 22 Oct 2021 20:15:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1634933736; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6s0KWIoYU1fvFLOFfccODUHj8eFbZXTXmCH1ca4A95w=; b=04IYGaz6ruYhvJErFgLXiTwFkKLfHhY2C4Dq9da0ZEq3I/rCs8rEDoJnwLze0nLkys3c9u pJXaWUH87sVLUuYVZyTLV6oOnzdTGx/Z3ejdQ1PIJtsc6gCxdEWU89zMTR2CednaF2MyIV rhdNPupUrSIjH80D2e0aPZj6ap9iNJM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1634933736; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6s0KWIoYU1fvFLOFfccODUHj8eFbZXTXmCH1ca4A95w=; b=jPzncAv+ma4xZKL7zVZLAalKsEoY/DCRxft8tlQL+RJRW8YLMr35Nsi3imn9rntMrYnapJ CzKvdAtMMLX1dVDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 790FB1348D; Fri, 22 Oct 2021 20:15:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id r4E2EOgbc2H6dgAAMHmgww (envelope-from ); Fri, 22 Oct 2021 20:15:36 +0000 From: Goldwyn Rodrigues To: linux-fsdevel@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Goldwyn Rodrigues Subject: [RFC PATCH 4/5] btrfs: Set s_bdev for btrfs super block Date: Fri, 22 Oct 2021 15:15:04 -0500 Message-Id: <0dfdf1aea018b4a06774f0117ef0af51944ecb46.1634933122.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Goldwyn Rodrigues s_bdev is not set. Use the latest bdev to setup s_bdev. reads are performed on block device directly and derived from super block ->s_bdev field. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/super.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 432f40f72466..9588a42d7a49 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1749,6 +1749,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, deactivate_locked_super(s); return ERR_PTR(error); } + s->s_bdev = bdev; return dget(s->s_root); From patchwork Fri Oct 22 20:15:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12579021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97876C433F5 for ; Fri, 22 Oct 2021 20:15:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7772D611F2 for ; Fri, 22 Oct 2021 20:15:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234256AbhJVUSD (ORCPT ); Fri, 22 Oct 2021 16:18:03 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:57146 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233918AbhJVUR6 (ORCPT ); Fri, 22 Oct 2021 16:17:58 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A9DFF1FD63; Fri, 22 Oct 2021 20:15:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1634933739; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MpD9AU6mFSzq/UrIZ82eenxsvTEJbrN/1mPlrY2rh/o=; b=wrtAC4psBbwmYIMYvx1KS+FlcizjWTjwKYKVbTJvzeqf7XYWynoKzAIMiuVtNK7rmFc/cU PZzP570F3JHE31T5Vu5W7OCzLnbN55RekCnVZ5ErXfsg84luommP4BFUyMj6t1b7J7/SDK blATlEsId/0Tq+9apJkjmySutYFJHQ4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1634933739; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MpD9AU6mFSzq/UrIZ82eenxsvTEJbrN/1mPlrY2rh/o=; b=M9qe3dwXjS2cOYG+Lgk4sNlJ28rvx5KOAYOYqUsUpBfZaqDvNyTBwlk2EVSRhz3YOxc4Zn IRMuCEZP3X3Cw+CA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4FF7E1348D; Fri, 22 Oct 2021 20:15:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id JLWzCesbc2ECdwAAMHmgww (envelope-from ); Fri, 22 Oct 2021 20:15:39 +0000 From: Goldwyn Rodrigues To: linux-fsdevel@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Goldwyn Rodrigues Subject: [RFC PATCH 5/5] btrfs: function to convert file offset to device offset Date: Fri, 22 Oct 2021 15:15:05 -0500 Message-Id: <2be14d6e2e1e888f2a0f1f272c1fd6cc0b681e97.1634933122.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Goldwyn Rodrigues btrfs_file_to_device_offset() converts a file offset to device offset. It also calculates the last_index which represents the last page in the range which is within the extent. btrfs_file_to_device_offset() is only passed conditionally based on if BTRFS_SHAREDEXT is set in the mount flag. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/file.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index e171d822a05e..f0b97d020575 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -3643,18 +3643,56 @@ static ssize_t btrfs_direct_read(struct kiocb *iocb, struct iov_iter *to) return ret; } +static pgoff_t btrfs_file_offset_to_device(struct file *filp, loff_t pos, + size_t len, pgoff_t *last_index) +{ + struct extent_map *em; + struct btrfs_inode *inode = BTRFS_I(file_inode(filp)); + u64 device_offset; + u64 device_len; + + if (inode->flags & BTRFS_INODE_NODATACOW) + return 0; + + em = btrfs_get_extent(inode, NULL, 0, pos, len); + + device_offset = em->block_start; + if (device_offset == EXTENT_MAP_HOLE) { + free_extent_map(em); + return 0; + } + + /* Delalloc should be in file's pagecache */ + BUG_ON(device_offset == EXTENT_MAP_DELALLOC); + + device_offset = (device_offset + (pos - em->start)) >> PAGE_SHIFT; + device_len = (em->len - (pos - em->start)) >> PAGE_SHIFT; + *last_index = device_offset + device_len; + + free_extent_map(em); + + return device_offset; +} + static ssize_t btrfs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) { ssize_t ret = 0; + struct inode *inode = file_inode(iocb->ki_filp); + struct btrfs_fs_info *fs_info; + file_offset_to_device_t file_offset_to_device = NULL; if (iocb->ki_flags & IOCB_DIRECT) { ret = btrfs_direct_read(iocb, to); if (ret < 0 || !iov_iter_count(to) || - iocb->ki_pos >= i_size_read(file_inode(iocb->ki_filp))) + iocb->ki_pos >= i_size_read(inode)) return ret; } - return filemap_read(iocb, to, ret, NULL); + fs_info = btrfs_sb(inode->i_sb); + if (btrfs_test_opt(fs_info, SHAREDEXT)) + file_offset_to_device = btrfs_file_offset_to_device; + + return filemap_read(iocb, to, ret, file_offset_to_device); } const struct file_operations btrfs_file_operations = {