From patchwork Fri Aug 23 16:27:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Harmstone X-Patchwork-Id: 13775573 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A671118E052 for ; Fri, 23 Aug 2024 16:28:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.145.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724430517; cv=none; b=t+mHxnZmOrCkVX/HeL260eYH1fSPF+uStbdUDmcAH6SCsKOJmH9ENXQ9ZoRWwvQSz5uoMoLFmUXg9YkclpQVUa7gCD6H2HNc8v3UcQF61D4pCS5+WYuwILnEj0OH/MtDzcY1+4vR+AxYc77IysPO1bDEbIv+F26hTJZcaxilYCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724430517; c=relaxed/simple; bh=i58b04qaxPVST6vUqbZGlxk/Pj6JQzbPpV+FhClYSkM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aEjeQxG34syk+Y6Q8zUzzigenb/bjN6Fhl+j5V2rmUw2zjYPwCsVS5RPScsUge1FgyoxxqkpU/iv8GgD164jq1rGkucynFJGITGIP1GuWqcVdyFm/dFa8BPCw0/1EN74p/Pu8N+uDYDLEOkjmsvTHCC04hxa/4ADU9QiliLdAWw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fb.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b=fRoDFgyV; arc=none smtp.client-ip=67.231.145.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fb.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="fRoDFgyV" Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47NETb5S003019 for ; Fri, 23 Aug 2024 09:28:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= facebook; bh=56tSw8LAbfe/7f+rOT6P2Pmfo9Da5NoPKXydiAMzV08=; b=fRo DFgyVhfnjSQvHiHS+VsGfkVc+MlNmzFGR7suUeGCDWUAdlcKZ/8/i8FLYkkGLaFY mhcdEhnCBkMFiPBH/bbYzaPxe9zmYwCwShV3hfxqSG5L15wzXmuTxYJ9fKMas4hL HhkixNs80JunvJapIzE0nirkR68Mv9/Q+9OBoi74= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 416v82gt3g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 23 Aug 2024 09:28:34 -0700 (PDT) Received: from twshared4354.35.frc1.facebook.com (2620:10d:c0a8:1c::1b) by mail.thefacebook.com (2620:10d:c0a9:6f::8fd4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.11; Fri, 23 Aug 2024 16:28:19 +0000 Received: by devbig276.nha1.facebook.com (Postfix, from userid 660015) id 385C65CB7F77; Fri, 23 Aug 2024 17:28:13 +0100 (BST) From: Mark Harmstone To: , CC: Mark Harmstone Subject: [PATCH 1/6] btrfs: remove iocb from btrfs_encoded_read Date: Fri, 23 Aug 2024 17:27:43 +0100 Message-ID: <20240823162810.1668399-2-maharmstone@fb.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240823162810.1668399-1-maharmstone@fb.com> References: <20240823162810.1668399-1-maharmstone@fb.com> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: JQeWWJU3s1mGri_hR6jnSQ-cb2hzi3DQ X-Proofpoint-ORIG-GUID: JQeWWJU3s1mGri_hR6jnSQ-cb2hzi3DQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-23_13,2024-08-22_01,2024-05-17_01 We initialize a struct kiocb for encoded reads, but this never gets passed outside the driver. Simplify things by replacing it with a file, offset pair. Signed-off-by: Mark Harmstone --- fs/btrfs/btrfs_inode.h | 3 ++- fs/btrfs/inode.c | 59 ++++++++++++++++++++---------------------- fs/btrfs/ioctl.c | 6 +---- 3 files changed, 31 insertions(+), 37 deletions(-) diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index 3056c8aed8ef..affe70929234 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -605,7 +605,8 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode, u64 file_offset, u64 disk_bytenr, u64 disk_io_size, struct page **pages); -ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter, +ssize_t btrfs_encoded_read(struct file *file, loff_t offset, + struct iov_iter *iter, struct btrfs_ioctl_encoded_io_args *encoded); ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from, const struct btrfs_ioctl_encoded_io_args *encoded); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index b1b6564ab68f..a0cc029d95ed 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8993,7 +8993,7 @@ int btrfs_encoded_io_compression_from_extent(struct btrfs_fs_info *fs_info, } static ssize_t btrfs_encoded_read_inline( - struct kiocb *iocb, + struct btrfs_inode *inode, loff_t pos, struct iov_iter *iter, u64 start, u64 lockend, struct extent_state **cached_state, @@ -9001,7 +9001,6 @@ static ssize_t btrfs_encoded_read_inline( struct btrfs_ioctl_encoded_io_args *encoded, bool *unlocked) { - struct btrfs_inode *inode = BTRFS_I(file_inode(iocb->ki_filp)); struct btrfs_root *root = inode->root; struct btrfs_fs_info *fs_info = root->fs_info; struct extent_io_tree *io_tree = &inode->io_tree; @@ -9034,7 +9033,7 @@ static ssize_t btrfs_encoded_read_inline( ptr = btrfs_file_extent_inline_start(item); encoded->len = min_t(u64, extent_start + ram_bytes, - inode->vfs_inode.i_size) - iocb->ki_pos; + inode->vfs_inode.i_size) - pos; ret = btrfs_encoded_io_compression_from_extent(fs_info, btrfs_file_extent_compression(leaf, item)); if (ret < 0) @@ -9051,12 +9050,12 @@ static ssize_t btrfs_encoded_read_inline( } count = inline_size; encoded->unencoded_len = ram_bytes; - encoded->unencoded_offset = iocb->ki_pos - extent_start; + encoded->unencoded_offset = pos - extent_start; } else { count = min_t(u64, count, encoded->len); encoded->len = count; encoded->unencoded_len = count; - ptr += iocb->ki_pos - extent_start; + ptr += pos - extent_start; } tmp = kmalloc(count, GFP_NOFS); @@ -9151,15 +9150,14 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode, return blk_status_to_errno(READ_ONCE(priv.status)); } -static ssize_t btrfs_encoded_read_regular(struct kiocb *iocb, - struct iov_iter *iter, +static ssize_t btrfs_encoded_read_regular(struct btrfs_inode *inode, + loff_t offset, struct iov_iter *iter, u64 start, u64 lockend, struct extent_state **cached_state, u64 disk_bytenr, u64 disk_io_size, size_t count, bool compressed, bool *unlocked) { - struct btrfs_inode *inode = BTRFS_I(file_inode(iocb->ki_filp)); struct extent_io_tree *io_tree = &inode->io_tree; struct page **pages; unsigned long nr_pages, i; @@ -9190,8 +9188,8 @@ static ssize_t btrfs_encoded_read_regular(struct kiocb *iocb, i = 0; page_offset = 0; } else { - i = (iocb->ki_pos - start) >> PAGE_SHIFT; - page_offset = (iocb->ki_pos - start) & (PAGE_SIZE - 1); + i = (offset - start) >> PAGE_SHIFT; + page_offset = (offset - start) & (PAGE_SIZE - 1); } cur = 0; while (cur < count) { @@ -9217,10 +9215,11 @@ static ssize_t btrfs_encoded_read_regular(struct kiocb *iocb, return ret; } -ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter, +ssize_t btrfs_encoded_read(struct file *file, loff_t offset, + struct iov_iter *iter, struct btrfs_ioctl_encoded_io_args *encoded) { - struct btrfs_inode *inode = BTRFS_I(file_inode(iocb->ki_filp)); + struct btrfs_inode *inode = BTRFS_I(file_inode(file)); struct btrfs_fs_info *fs_info = inode->root->fs_info; struct extent_io_tree *io_tree = &inode->io_tree; ssize_t ret; @@ -9230,17 +9229,17 @@ ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter, struct extent_map *em; bool unlocked = false; - file_accessed(iocb->ki_filp); + file_accessed(file); btrfs_inode_lock(inode, BTRFS_ILOCK_SHARED); - if (iocb->ki_pos >= inode->vfs_inode.i_size) { + if (offset >= inode->vfs_inode.i_size) { btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED); return 0; } - start = ALIGN_DOWN(iocb->ki_pos, fs_info->sectorsize); + start = ALIGN_DOWN(offset, fs_info->sectorsize); /* - * We don't know how long the extent containing iocb->ki_pos is, but if + * We don't know how long the extent containing offset is, but if * it's compressed we know that it won't be longer than this. */ lockend = start + BTRFS_MAX_UNCOMPRESSED - 1; @@ -9277,10 +9276,11 @@ ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter, */ free_extent_map(em); em = NULL; - ret = btrfs_encoded_read_inline(iocb, iter, start, lockend, - &cached_state, extent_start, - count, encoded, &unlocked); - goto out; + ret = btrfs_encoded_read_inline(inode, offset, iter, start, + lockend, &cached_state, + extent_start, count, encoded, + &unlocked); + goto out_em; } /* @@ -9288,7 +9288,7 @@ ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter, * that. */ encoded->len = min_t(u64, extent_map_end(em), - inode->vfs_inode.i_size) - iocb->ki_pos; + inode->vfs_inode.i_size) - offset; if (em->disk_bytenr == EXTENT_MAP_HOLE || (em->flags & EXTENT_FLAG_PREALLOC)) { disk_bytenr = EXTENT_MAP_HOLE; @@ -9308,7 +9308,7 @@ ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter, disk_io_size = em->disk_num_bytes; count = em->disk_num_bytes; encoded->unencoded_len = em->ram_bytes; - encoded->unencoded_offset = iocb->ki_pos - (em->start - em->offset); + encoded->unencoded_offset = offset - (em->start - em->offset); ret = btrfs_encoded_io_compression_from_extent(fs_info, extent_map_compression(em)); if (ret < 0) @@ -9322,8 +9322,8 @@ ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter, * Don't read beyond what we locked. This also limits the page * allocations that we'll do. */ - disk_io_size = min(lockend + 1, iocb->ki_pos + encoded->len) - start; - count = start + disk_io_size - iocb->ki_pos; + disk_io_size = min(lockend + 1, offset + encoded->len) - start; + count = start + disk_io_size - offset; encoded->len = count; encoded->unencoded_len = count; disk_io_size = ALIGN(disk_io_size, fs_info->sectorsize); @@ -9339,16 +9339,13 @@ ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter, if (ret != count) ret = -EFAULT; } else { - ret = btrfs_encoded_read_regular(iocb, iter, start, lockend, - &cached_state, disk_bytenr, - disk_io_size, count, - encoded->compression, + ret = btrfs_encoded_read_regular(inode, offset, iter, start, + lockend, &cached_state, + disk_bytenr, disk_io_size, + count, encoded->compression, &unlocked); } -out: - if (ret >= 0) - iocb->ki_pos += encoded->len; out_em: free_extent_map(em); out_unlock_extent: diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index e0a664b8a46a..406ed70814f5 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4520,7 +4520,6 @@ static int btrfs_ioctl_encoded_read(struct file *file, void __user *argp, struct iovec *iov = iovstack; struct iov_iter iter; loff_t pos; - struct kiocb kiocb; ssize_t ret; if (!capable(CAP_SYS_ADMIN)) { @@ -4571,10 +4570,7 @@ static int btrfs_ioctl_encoded_read(struct file *file, void __user *argp, if (ret < 0) goto out_iov; - init_sync_kiocb(&kiocb, file); - kiocb.ki_pos = pos; - - ret = btrfs_encoded_read(&kiocb, &iter, &args); + ret = btrfs_encoded_read(file, pos, &iter, &args); if (ret >= 0) { fsnotify_access(file); if (copy_to_user(argp + copy_end,