Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7297862pxb; Thu, 18 Feb 2021 06:39:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbfOnAQ3yWi62J0VKZSFoZHGdWf8hVrvn13AR/BXrf4YufyPzTiuZLH2doWOFRgX34d8HQ X-Received: by 2002:a50:a45b:: with SMTP id v27mr4364660edb.141.1613659169880; Thu, 18 Feb 2021 06:39:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613659169; cv=none; d=google.com; s=arc-20160816; b=WMNBRU5ndRiAzarpx+KiSj8E2vkTAJYMD/gD4pBJsUiwNoCVVngctLJd2VlAgGG+Fq fxWUcsvlt3BaQH+d5Jsd75IGqJU+C+DnJL0+gRW19sRMA7NkLmyLZaNmvWWjvr7f9qSc m9QeyUNiQgyXdaT0ZBKmAZ/UwgbAY2XvJb18mj8CEjSKoIic8LRUm2vaLiGNOSZ49vdS D2Bl6P+60YxMQUqA6Ca68StTq3IM354IeACHAjuJliicNPcLxJPu/n1CPFFPLyXhG6Jz 7ZB3w0EEkDNPDTOcrALgK+3PcVBl5i/ce5jh+9GegV1IvQahzq3f26kjiHfqelmNFSiO WBsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=7RgXvNqb47FSqiUcN/6htxtgjTcReAeQ44YVeUy8ahw=; b=L3+ma3LTWK56o4d7KyKG3uz95CqtBnK81KhLCEK/IoDkSYHSE0c+yORrIrmJzVturO IYQVAuRkyKtMeeAL1fz7+xVL6ri8A05FXuiHeg6cKBOPW7mFy8SQa/rf3ioedD4RGTiJ a/Maga8xCm+fhw3co/FQAiyktTTFUPiC32OI0ELPYGfWvX8QyJYlEsWyv+Ydnkqy+wI2 YeBQvn6vqQxYc4w5tHyD0hL04ZLrkj5EyJ61ryBlS7loy6FdMJMtsDQiuORDROqEtguI AxXQhKl5WO7oOd7WmJs7b2AlQCIT++DQYIuHTfqUIvEAKTPYSN/EBotLBtL5lb+ccSFY h2+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a11si3771870edn.318.2021.02.18.06.39.03; Thu, 18 Feb 2021 06:39:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230239AbhBROad (ORCPT + 99 others); Thu, 18 Feb 2021 09:30:33 -0500 Received: from hmm.wantstofly.org ([213.239.204.108]:57150 "EHLO mail.wantstofly.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232800AbhBRM2x (ORCPT ); Thu, 18 Feb 2021 07:28:53 -0500 Received: by mail.wantstofly.org (Postfix, from userid 1000) id 4DB447F4BD; Thu, 18 Feb 2021 14:27:21 +0200 (EET) Date: Thu, 18 Feb 2021 14:27:21 +0200 From: Lennert Buytenhek To: Jens Axboe , Al Viro , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org Cc: David Laight , Matthew Wilcox Subject: [PATCH v3 1/2] readdir: split the core of getdents64(2) out into vfs_getdents() Message-ID: <20210218122721.GB334506@wantstofly.org> References: <20210218122640.GA334506@wantstofly.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210218122640.GA334506@wantstofly.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org So that IORING_OP_GETDENTS may use it, split out the core of the getdents64(2) syscall into a helper function, vfs_getdents(). vfs_getdents() calls into filesystems' ->iterate{,_shared}() which expect serialization on struct file, which means that callers of vfs_getdents() are responsible for either using fdget_pos() or performing the equivalent serialization by hand. Cc: Al Viro Signed-off-by: Lennert Buytenhek --- fs/readdir.c | 25 +++++++++++++++++-------- include/linux/fs.h | 4 ++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/fs/readdir.c b/fs/readdir.c index 19434b3c982c..f52167c1eb61 100644 --- a/fs/readdir.c +++ b/fs/readdir.c @@ -348,10 +348,9 @@ static int filldir64(struct dir_context *ctx, const char *name, int namlen, return -EFAULT; } -SYSCALL_DEFINE3(getdents64, unsigned int, fd, - struct linux_dirent64 __user *, dirent, unsigned int, count) +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, @@ -359,11 +358,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) { @@ -376,6 +371,20 @@ 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; } diff --git a/include/linux/fs.h b/include/linux/fs.h index fd47deea7c17..114885d3f6c4 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3109,6 +3109,10 @@ extern const struct inode_operations simple_symlink_inode_operations; extern int iterate_dir(struct file *, struct dir_context *); +struct linux_dirent64; +int vfs_getdents(struct file *file, struct linux_dirent64 __user *dirent, + unsigned int count); + int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat, int flags); int vfs_fstat(int fd, struct kstat *stat); -- 2.29.2