From patchwork Fri Aug 25 13:54:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 13365734 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B0B2C3DA6F for ; Fri, 25 Aug 2023 13:55:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A85AD2800AB; Fri, 25 Aug 2023 09:55:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0E538E0015; Fri, 25 Aug 2023 09:55:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 889002800AB; Fri, 25 Aug 2023 09:55:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7242D8E0015 for ; Fri, 25 Aug 2023 09:55:22 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 49D7FB26A4 for ; Fri, 25 Aug 2023 13:55:22 +0000 (UTC) X-FDA: 81162774084.21.EFDAF27 Received: from out-247.mta1.migadu.com (out-247.mta1.migadu.com [95.215.58.247]) by imf06.hostedemail.com (Postfix) with ESMTP id 88338180028 for ; Fri, 25 Aug 2023 13:55:19 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=sf0c3BaV; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.247 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692971719; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=M7eywqhb1fMAXTeyjh6BJsPONBLehGvo8wJ7nQSmBJs=; b=HcqfK5/ViBc7HcMwyTiOoVrXA1UgvMDCheoUsoBw0X3LnFGljRJ60I1Wv9Ho93WcseGDvA iLe4k+BAjlQ+q5HRjD0CJX5nVjnVzoGotFWxDKVYnSpBje3OGgn0WsHMhs2bgkGMalRHJC Zz2tCBywJDtEsA7coXNSlEzniKedS5w= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=sf0c3BaV; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.247 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692971719; a=rsa-sha256; cv=none; b=O+qNH5ZNwlbXYKlcN6x0bQUmSRL2hWglZdBsWIALyYuiANirZqJl4pii8OKDl/NTNTGnsp Av6AbEaGI6dIZSJxEZ8WiYH1rHFmM2SS9ThfwPge3ehlJbtIAef3E+DYDWFBkJ/NvEodDC HM7qBDZrZN0bucnyY22VmgCsaEKXH9Q= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1692971717; h=from:from:reply-to:subject:subject: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=M7eywqhb1fMAXTeyjh6BJsPONBLehGvo8wJ7nQSmBJs=; b=sf0c3BaV5zKRH4Bb8TUwfPopplZAFyQJxSB3uPd/Bru862GHE/6uLEqra/FCbrZoDX4RQi CIrt1XneKgBJ/A8gWA/etx0kgRlpMUcGJTfa14yTcf5Kv3L0Wt8Br8rgcIz1PY9X6AeQ+Q Vrx6zJaXOEDBrQhrS+G7Zr51TGkx4FM= From: Hao Xu To: io-uring@vger.kernel.org, Jens Axboe Cc: Dominique Martinet , Pavel Begunkov , Christian Brauner , Alexander Viro , Stefan Roesch , Clay Harris , Dave Chinner , "Darrick J . Wong" , linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-cachefs@redhat.com, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, codalist@coda.cs.cmu.edu, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, devel@lists.orangefs.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-mtd@lists.infradead.org, Wanpeng Li Subject: [PATCH 01/29] fs: split off vfs_getdents function of getdents64 syscall Date: Fri, 25 Aug 2023 21:54:03 +0800 Message-Id: <20230825135431.1317785-2-hao.xu@linux.dev> In-Reply-To: <20230825135431.1317785-1-hao.xu@linux.dev> References: <20230825135431.1317785-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 88338180028 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 7ds9xzfq5d7infapnga6fkuyzu4bubk4 X-HE-Tag: 1692971719-390689 X-HE-Meta: U2FsdGVkX1+YRqrN9QQSmmwi6ZRj1oqoyINQd0zZOKaa+quHWqK2wtb8h5Q5NNxG4yxd+mZtEXff4L8wljXwl/9g9dFdVsZbDLEVSJy23QTGXfOcE8C8uRaCktG4GEKUtXym0o1KX9QjuySnYm0Fc/wbCaNTHQcJR9PAouzNmbRI/CAsgyEXB0kA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VWWGZTuz1QPKEebrqPKLJnNFngtAoINfvfyMRWLgDHV77vLEuo2VQNQVXySq0p0Up8AdKU4pWsEXVjOw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Dominique Martinet This splits off the vfs_getdents function from the getdents64 system call. This will allow io_uring to call the vfs_getdents function. Co-developed-by: Stefan Roesch Signed-off-by: Stefan Roesch Signed-off-by: Dominique Martinet Signed-off-by: Hao Xu --- fs/internal.h | 8 ++++++++ fs/readdir.c | 34 ++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/fs/internal.h b/fs/internal.h index f7a3dc111026..b1f66e52d61b 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -304,3 +304,11 @@ ssize_t __kernel_write_iter(struct file *file, struct iov_iter *from, loff_t *po struct mnt_idmap *alloc_mnt_idmap(struct user_namespace *mnt_userns); struct mnt_idmap *mnt_idmap_get(struct mnt_idmap *idmap); void mnt_idmap_put(struct mnt_idmap *idmap); + +/* + * fs/readdir.c + */ +struct linux_dirent64; + +int vfs_getdents(struct file *file, struct linux_dirent64 __user *dirent, + unsigned int count); diff --git a/fs/readdir.c b/fs/readdir.c index b264ce60114d..9592259b7e7f 100644 --- a/fs/readdir.c +++ b/fs/readdir.c @@ -21,6 +21,7 @@ #include #include #include +#include "internal.h" #include @@ -351,10 +352,16 @@ static bool filldir64(struct dir_context *ctx, const char *name, int namlen, return false; } -SYSCALL_DEFINE3(getdents64, unsigned int, fd, - struct linux_dirent64 __user *, dirent, unsigned int, count) + +/** + * vfs_getdents - getdents without fdget + * @file : pointer to file struct of directory + * @dirent : pointer to user directory structure + * @count : size of buffer + */ +int vfs_getdents(struct file *file, struct linux_dirent64 __user *dirent, + unsigned int count) { - struct fd f; struct getdents_callback64 buf = { .ctx.actor = filldir64, .count = count, @@ -362,11 +369,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd, }; int error; - f = fdget_pos(fd); - if (!f.file) - return -EBADF; - - error = iterate_dir(f.file, &buf.ctx); + error = iterate_dir(file, &buf.ctx); if (error >= 0) error = buf.error; if (buf.prev_reclen) { @@ -379,6 +382,21 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd, else error = count - buf.count; } + return error; +} + +SYSCALL_DEFINE3(getdents64, unsigned int, fd, + struct linux_dirent64 __user *, dirent, unsigned int, count) +{ + struct fd f; + int error; + + f = fdget_pos(fd); + if (!f.file) + return -EBADF; + + error = vfs_getdents(f.file, dirent, count); + fdput_pos(f); return error; }