All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Christoph Hellwig <hch@infradead.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>, Jan Kara <jack@suse.cz>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-api@vger.kernel.org, kernel@pengutronix.de,
	Jan Kara <jack@suse.com>, Richard Weinberger <richard@nod.at>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <christian.brauner@ubuntu.com>
Subject: Re: [PATCH v3 0/2] quota: Add mountpath based quota support
Date: Tue, 25 May 2021 18:19:25 +0200	[thread overview]
Message-ID: <20210525161925.GF4112@quack2.suse.cz> (raw)
In-Reply-To: <YKyv3sFKLKDWUZ3C@infradead.org>

[-- Attachment #1: Type: text/plain, Size: 705 bytes --]

On Tue 25-05-21 09:05:50, Christoph Hellwig wrote:
> Adding the dfd argument should be as simple as this patch (which also
> moves the cmd argument later to match typical calling conventions).
> 
> It might be worth to rename the syscall to quotactlat to better match
> other syscalls.  A flags argument doesn't make much sense here, as the
> cmd argument can be used for extensions and is properly checked for
> unknown values.

Thanks for the patch! So I was actually thinking about going to completely
fd-based syscall like ioctl(2) and then we don't have to worry about lookup
flags or paths at all. What do people thing about attached patch?

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

[-- Attachment #2: 0001-quota-Change-quotactl_path-systcall-to-an-fd-based-o.patch --]
[-- Type: text/x-patch, Size: 3346 bytes --]

From 359222f02ff7b69668a493207e3b84d53195f818 Mon Sep 17 00:00:00 2001
From: Jan Kara <jack@suse.cz>
Date: Tue, 25 May 2021 16:07:48 +0200
Subject: [PATCH] quota: Change quotactl_path() systcall to an fd-based one

Some users have pointed out that path-based syscalls are problematic in
some environments and at least directory fd argument and possibly also
resolve flags are desirable for such syscalls. Rather than
reimplementing all details of pathname lookup and following where it may
eventually evolve, let's go for full file descriptor based syscall
similar to how ioctl(2) works since the beginning. Managing of quotas
isn't performance sensitive so the extra overhead of open does not
matter and we are able to consume O_PATH descriptors as well which makes
open cheap anyway. Also for frequent operations (such as retrieving
usage information for all users) we can reuse single fd and in fact get
even better performance as well as avoiding races with possible remounts
etc.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/quota/quota.c         | 27 ++++++++++++---------------
 include/linux/syscalls.h |  4 ++--
 2 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/fs/quota/quota.c b/fs/quota/quota.c
index 05e4bd9ab6d6..8450bb6186f4 100644
--- a/fs/quota/quota.c
+++ b/fs/quota/quota.c
@@ -968,31 +968,29 @@ SYSCALL_DEFINE4(quotactl, unsigned int, cmd, const char __user *, special,
 	return ret;
 }
 
-SYSCALL_DEFINE4(quotactl_path, unsigned int, cmd, const char __user *,
-		mountpoint, qid_t, id, void __user *, addr)
+SYSCALL_DEFINE4(quotactl_fd, unsigned int, fd, unsigned int, cmd,
+		qid_t, id, void __user *, addr)
 {
 	struct super_block *sb;
-	struct path mountpath;
 	unsigned int cmds = cmd >> SUBCMDSHIFT;
 	unsigned int type = cmd & SUBCMDMASK;
+	struct fd f = fdget_raw(fd);
 	int ret;
 
-	if (type >= MAXQUOTAS)
-		return -EINVAL;
+	if (!f.file)
+		return -EBADF;
 
-	ret = user_path_at(AT_FDCWD, mountpoint,
-			     LOOKUP_FOLLOW | LOOKUP_AUTOMOUNT, &mountpath);
-	if (ret)
-		return ret;
-
-	sb = mountpath.mnt->mnt_sb;
+	ret = -EINVAL;
+	if (type >= MAXQUOTAS)
+		goto out;
 
 	if (quotactl_cmd_write(cmds)) {
-		ret = mnt_want_write(mountpath.mnt);
+		ret = mnt_want_write(f.file->f_path.mnt);
 		if (ret)
 			goto out;
 	}
 
+	sb = f.file->f_path.mnt->mnt_sb;
 	if (quotactl_cmd_onoff(cmds))
 		down_write(&sb->s_umount);
 	else
@@ -1006,9 +1004,8 @@ SYSCALL_DEFINE4(quotactl_path, unsigned int, cmd, const char __user *,
 		up_read(&sb->s_umount);
 
 	if (quotactl_cmd_write(cmds))
-		mnt_drop_write(mountpath.mnt);
+		mnt_drop_write(f.file->f_path.mnt);
 out:
-	path_put(&mountpath);
-
+	fdput(f);
 	return ret;
 }
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 050511e8f1f8..586128d5c3b8 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -485,8 +485,8 @@ asmlinkage long sys_pipe2(int __user *fildes, int flags);
 /* fs/quota.c */
 asmlinkage long sys_quotactl(unsigned int cmd, const char __user *special,
 				qid_t id, void __user *addr);
-asmlinkage long sys_quotactl_path(unsigned int cmd, const char __user *mountpoint,
-				  qid_t id, void __user *addr);
+asmlinkage long sys_quotactl_fd(unsigned int fd, unsigned int cmd, qid_t id,
+				void __user *addr);
 
 /* fs/readdir.c */
 asmlinkage long sys_getdents64(unsigned int fd,
-- 
2.26.2


      reply	other threads:[~2021-05-25 16:19 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-04 12:35 [PATCH v3 0/2] quota: Add mountpath based quota support Sascha Hauer
2021-03-04 12:35 ` [PATCH 1/2] " Sascha Hauer
2021-03-04 12:35 ` [PATCH 2/2] quota: wire up quotactl_path Sascha Hauer
2021-03-04 16:41   ` kernel test robot
2021-03-04 17:08   ` kernel test robot
2021-03-04 12:35 ` [PATCH] quotactl.2: Add documentation for quotactl_path() Sascha Hauer
2021-03-16 11:29 ` [PATCH v3 0/2] quota: Add mountpath based quota support Jan Kara
2021-03-24 15:43   ` Sascha Hauer
2021-05-12 11:01   ` Jan Kara
2021-05-12 12:53     ` Christian Brauner
2021-05-12 13:14       ` Jan Kara
2021-05-12 15:36         ` Christian Brauner
2021-05-17 12:50           ` Jan Kara
2021-05-12 15:03     ` Sascha Hauer
2021-05-24  8:49       ` Jan Kara
2021-05-25  7:26         ` Sascha Hauer
2021-05-25  8:05           ` Christoph Hellwig
2021-05-25 16:19             ` Jan Kara [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210525161925.GF4112@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=christian.brauner@ubuntu.com \
    --cc=hch@infradead.org \
    --cc=jack@suse.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=richard@nod.at \
    --cc=s.hauer@pengutronix.de \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.