ceph-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6 00/15] ceph: support idmapped mounts
@ 2023-06-09  9:31 Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 01/15] fs: export mnt_idmap_get/mnt_idmap_put Alexander Mikhalitsyn
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: Alexander Mikhalitsyn @ 2023-06-09  9:31 UTC (permalink / raw)
  To: xiubli
  Cc: brauner, stgraber, linux-fsdevel, Alexander Mikhalitsyn,
	Ilya Dryomov, Jeff Layton, ceph-devel, linux-kernel

Dear friends,

This patchset was originally developed by Christian Brauner but I'll continue
to push it forward. Christian allowed me to do that :)

This feature is already actively used/tested with LXD/LXC project.

Git tree (based on https://github.com/ceph/ceph-client.git testing):
v6: https://github.com/mihalicyn/linux/commits/fs.idmapped.ceph.v6
current: https://github.com/mihalicyn/linux/tree/fs.idmapped.ceph

In the version 3 I've changed only two commits:
- fs: export mnt_idmap_get/mnt_idmap_put
- ceph: allow idmapped setattr inode op
and added a new one:
- ceph: pass idmap to __ceph_setattr

In the version 4 I've reworked the ("ceph: stash idmapping in mdsc request")
commit. Now we take idmap refcounter just in place where req->r_mnt_idmap
is filled. It's more safer approach and prevents possible refcounter underflow
on error paths where __register_request wasn't called but ceph_mdsc_release_request is
called.

Changelog for version 5:
- a few commits were squashed into one (as suggested by Xiubo Li)
- started passing an idmapping everywhere (if possible), so a caller
UID/GID-s will be mapped almost everywhere (as suggested by Xiubo Li)

Changelog for version 6:
- rebased on top of testing branch
- passed an idmapping in a few places (readdir, ceph_netfs_issue_op_inline)

Note. There is a known issue that idmapped mounts are not fully compatible with
MDS (server side) UID/GID-based path restriction, and full support of this requires
massive VFS changes or Cephfs protocol change. Anyway, we've tested the first version
of this patchset for more that a year with the container workloads and it works perfecly
well and it seems that even with this limitation it worth adding support of idmapped mounts.

I can confirm that this version passes xfstests.

Links to previous versions:
v1: https://lore.kernel.org/all/20220104140414.155198-1-brauner@kernel.org/
v2: https://lore.kernel.org/lkml/20230524153316.476973-1-aleksandr.mikhalitsyn@canonical.com/
tree: https://github.com/mihalicyn/linux/commits/fs.idmapped.ceph.v2
v3: https://lore.kernel.org/lkml/20230607152038.469739-1-aleksandr.mikhalitsyn@canonical.com/#t
v4: https://lore.kernel.org/lkml/20230607180958.645115-1-aleksandr.mikhalitsyn@canonical.com/#t
tree: https://github.com/mihalicyn/linux/commits/fs.idmapped.ceph.v4
v5: https://lore.kernel.org/lkml/20230608154256.562906-1-aleksandr.mikhalitsyn@canonical.com/#t
tree: https://github.com/mihalicyn/linux/commits/fs.idmapped.ceph.v5

Kind regards,
Alex

Original description from Christian:
========================================================================
This patch series enables cephfs to support idmapped mounts, i.e. the
ability to alter ownership information on a per-mount basis.

Container managers such as LXD support sharaing data via cephfs between
the host and unprivileged containers and between unprivileged containers.
They may all use different idmappings. Idmapped mounts can be used to
create mounts with the idmapping used for the container (or a different
one specific to the use-case).

There are in fact more use-cases such as remapping ownership for
mountpoints on the host itself to grant or restrict access to different
users or to make it possible to enforce that programs running as root
will write with a non-zero {g,u}id to disk.

The patch series is simple overall and few changes are needed to cephfs.
There is one cephfs specific issue that I would like to discuss and
solve which I explain in detail in:

[PATCH 02/12] ceph: handle idmapped mounts in create_request_message()

It has to do with how to handle mds serves which have id-based access
restrictions configured. I would ask you to please take a look at the
explanation in the aforementioned patch.

The patch series passes the vfs and idmapped mount testsuite as part of
xfstests. To run it you will need a config like:

[ceph]
export FSTYP=ceph
export TEST_DIR=/mnt/test
export TEST_DEV=10.103.182.10:6789:/
export TEST_FS_MOUNT_OPTS="-o name=admin,secret=$password

and then simply call

sudo ./check -g idmapped

========================================================================

Alexander Mikhalitsyn (6):
  fs: export mnt_idmap_get/mnt_idmap_put
  ceph: pass idmap to __ceph_setattr
  ceph: pass idmap to ceph_do_getattr
  ceph: pass idmap to __ceph_setxattr
  ceph: pass idmap to ceph_open/ioctl_set_layout/readdir
  ceph: pass idmap to ceph_netfs_issue_op_inline

Christian Brauner (9):
  ceph: stash idmapping in mdsc request
  ceph: handle idmapped mounts in create_request_message()
  ceph: pass an idmapping to mknod/symlink/mkdir/rename
  ceph: allow idmapped getattr inode op
  ceph: allow idmapped permission inode op
  ceph: allow idmapped setattr inode op
  ceph/acl: allow idmapped set_acl inode op
  ceph/file: allow idmapped atomic_open inode op
  ceph: allow idmapped mounts

 fs/ceph/acl.c                 |  8 +++----
 fs/ceph/addr.c                | 15 +++++++++++-
 fs/ceph/caps.c                | 10 ++++----
 fs/ceph/crypto.c              |  2 +-
 fs/ceph/dir.c                 |  6 +++++
 fs/ceph/export.c              |  2 +-
 fs/ceph/file.c                | 28 ++++++++++++++++------
 fs/ceph/inode.c               | 45 +++++++++++++++++++++--------------
 fs/ceph/ioctl.c               |  9 +++++--
 fs/ceph/mds_client.c          | 27 +++++++++++++++++----
 fs/ceph/mds_client.h          |  1 +
 fs/ceph/quota.c               |  2 +-
 fs/ceph/super.c               |  6 ++---
 fs/ceph/super.h               | 21 ++++++++++------
 fs/ceph/xattr.c               | 18 +++++++-------
 fs/mnt_idmapping.c            |  2 ++
 include/linux/mnt_idmapping.h |  3 +++
 17 files changed, 144 insertions(+), 61 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v6 01/15] fs: export mnt_idmap_get/mnt_idmap_put
  2023-06-09  9:31 [PATCH v6 00/15] ceph: support idmapped mounts Alexander Mikhalitsyn
@ 2023-06-09  9:31 ` Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 02/15] ceph: stash idmapping in mdsc request Alexander Mikhalitsyn
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Alexander Mikhalitsyn @ 2023-06-09  9:31 UTC (permalink / raw)
  To: xiubli
  Cc: brauner, stgraber, linux-fsdevel, Alexander Mikhalitsyn,
	Jeff Layton, Ilya Dryomov, ceph-devel, Alexander Viro,
	Seth Forshee, linux-kernel

These helpers are required to support idmapped mounts in the Cephfs.

Cc: Christian Brauner <brauner@kernel.org>
Cc: Xiubo Li <xiubli@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: ceph-devel@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Reviewed-by: Christian Brauner <brauner@kernel.org>
---
v3:
	- EXPORT_SYMBOL -> EXPORT_SYMBOL_GPL as Christoph Hellwig suggested
---
 fs/mnt_idmapping.c            | 2 ++
 include/linux/mnt_idmapping.h | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/fs/mnt_idmapping.c b/fs/mnt_idmapping.c
index 4905665c47d0..57d1dedf3f8f 100644
--- a/fs/mnt_idmapping.c
+++ b/fs/mnt_idmapping.c
@@ -256,6 +256,7 @@ struct mnt_idmap *mnt_idmap_get(struct mnt_idmap *idmap)
 
 	return idmap;
 }
+EXPORT_SYMBOL_GPL(mnt_idmap_get);
 
 /**
  * mnt_idmap_put - put a reference to an idmapping
@@ -271,3 +272,4 @@ void mnt_idmap_put(struct mnt_idmap *idmap)
 		kfree(idmap);
 	}
 }
+EXPORT_SYMBOL_GPL(mnt_idmap_put);
diff --git a/include/linux/mnt_idmapping.h b/include/linux/mnt_idmapping.h
index 057c89867aa2..b8da2db4ecd2 100644
--- a/include/linux/mnt_idmapping.h
+++ b/include/linux/mnt_idmapping.h
@@ -115,6 +115,9 @@ static inline bool vfsgid_eq_kgid(vfsgid_t vfsgid, kgid_t kgid)
 
 int vfsgid_in_group_p(vfsgid_t vfsgid);
 
+struct mnt_idmap *mnt_idmap_get(struct mnt_idmap *idmap);
+void mnt_idmap_put(struct mnt_idmap *idmap);
+
 vfsuid_t make_vfsuid(struct mnt_idmap *idmap,
 		     struct user_namespace *fs_userns, kuid_t kuid);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v6 02/15] ceph: stash idmapping in mdsc request
  2023-06-09  9:31 [PATCH v6 00/15] ceph: support idmapped mounts Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 01/15] fs: export mnt_idmap_get/mnt_idmap_put Alexander Mikhalitsyn
@ 2023-06-09  9:31 ` Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 03/15] ceph: handle idmapped mounts in create_request_message() Alexander Mikhalitsyn
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Alexander Mikhalitsyn @ 2023-06-09  9:31 UTC (permalink / raw)
  To: xiubli
  Cc: brauner, stgraber, linux-fsdevel, Christian Brauner, Jeff Layton,
	Ilya Dryomov, ceph-devel, Alexander Mikhalitsyn, linux-kernel

From: Christian Brauner <christian.brauner@ubuntu.com>

When sending a mds request cephfs will send relevant data for the
requested operation. For creation requests the caller's fs{g,u}id is
used to set the ownership of the newly created filesystem object. For
setattr requests the caller can pass in arbitrary {g,u}id values to
which the relevant filesystem object is supposed to be changed.

If the caller is performing the relevant operation via an idmapped mount
cephfs simply needs to take the idmapping into account when it sends the
relevant mds request.

In order to support idmapped mounts for cephfs we stash the idmapping
whenever they are relevant for the operation for the duration of the
request. Since mds requests can be queued and performed asynchronously
we make sure to keep the idmapping around and release it once the
request has finished.

In follow-up patches we will use this to send correct ownership
information over the wire. This patch just adds the basic infrastructure
to keep the idmapping around. The actual conversion patches are all
fairly minimal.

Cc: Xiubo Li <xiubli@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: ceph-devel@vger.kernel.org
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
---
v4:
	- don't call mnt_idmap_get(..) in __register_request
---
 fs/ceph/mds_client.c | 5 +++++
 fs/ceph/mds_client.h | 1 +
 2 files changed, 6 insertions(+)

diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index c808270a2f5d..083d0329f62d 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -12,6 +12,7 @@
 #include <linux/bits.h>
 #include <linux/ktime.h>
 #include <linux/bitmap.h>
+#include <linux/mnt_idmapping.h>
 
 #include "super.h"
 #include "crypto.h"
@@ -1115,6 +1116,8 @@ void ceph_mdsc_release_request(struct kref *kref)
 	kfree(req->r_path1);
 	kfree(req->r_path2);
 	put_cred(req->r_cred);
+	if (req->r_mnt_idmap)
+		mnt_idmap_put(req->r_mnt_idmap);
 	if (req->r_pagelist)
 		ceph_pagelist_release(req->r_pagelist);
 	kfree(req->r_fscrypt_auth);
@@ -1173,6 +1176,8 @@ static void __register_request(struct ceph_mds_client *mdsc,
 	insert_request(&mdsc->request_tree, req);
 
 	req->r_cred = get_current_cred();
+	if (!req->r_mnt_idmap)
+		req->r_mnt_idmap = &nop_mnt_idmap;
 
 	if (mdsc->oldest_tid == 0 && req->r_op != CEPH_MDS_OP_SETFILELOCK)
 		mdsc->oldest_tid = req->r_tid;
diff --git a/fs/ceph/mds_client.h b/fs/ceph/mds_client.h
index 351d92f7fc4f..89799becec90 100644
--- a/fs/ceph/mds_client.h
+++ b/fs/ceph/mds_client.h
@@ -298,6 +298,7 @@ struct ceph_mds_request {
 	int r_fmode;        /* file mode, if expecting cap */
 	int r_request_release_offset;
 	const struct cred *r_cred;
+	struct mnt_idmap *r_mnt_idmap;
 	struct timespec64 r_stamp;
 
 	/* for choosing which mds to send this request to */
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v6 03/15] ceph: handle idmapped mounts in create_request_message()
  2023-06-09  9:31 [PATCH v6 00/15] ceph: support idmapped mounts Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 01/15] fs: export mnt_idmap_get/mnt_idmap_put Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 02/15] ceph: stash idmapping in mdsc request Alexander Mikhalitsyn
@ 2023-06-09  9:31 ` Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 04/15] ceph: pass an idmapping to mknod/symlink/mkdir/rename Alexander Mikhalitsyn
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Alexander Mikhalitsyn @ 2023-06-09  9:31 UTC (permalink / raw)
  To: xiubli
  Cc: brauner, stgraber, linux-fsdevel, Christian Brauner, Jeff Layton,
	Ilya Dryomov, ceph-devel, Alexander Mikhalitsyn, linux-kernel

From: Christian Brauner <christian.brauner@ubuntu.com>

Inode operations that create a new filesystem object such as ->mknod,
->create, ->mkdir() and others don't take a {g,u}id argument explicitly.
Instead the caller's fs{g,u}id is used for the {g,u}id of the new
filesystem object.

Cephfs mds creation request argument structures mirror this filesystem
behavior. They don't encode a {g,u}id explicitly. Instead the caller's
fs{g,u}id that is always sent as part of any mds request is used by the
servers to set the {g,u}id of the new filesystem object.

In order to ensure that the correct {g,u}id is used map the caller's
fs{g,u}id for creation requests. This doesn't require complex changes.
It suffices to pass in the relevant idmapping recorded in the request
message. If this request message was triggered from an inode operation
that creates filesystem objects it will have passed down the relevant
idmaping. If this is a request message that was triggered from an inode
operation that doens't need to take idmappings into account the initial
idmapping is passed down which is an identity mapping and thus is
guaranteed to leave the caller's fs{g,u}id unchanged.,u}id is sent.

The last few weeks before Christmas 2021 I have spent time not just
reading and poking the cephfs kernel code but also took a look at the
ceph mds server userspace to ensure I didn't miss some subtlety.

This made me aware of one complication to solve. All requests send the
caller's fs{g,u}id over the wire. The caller's fs{g,u}id matters for the
server in exactly two cases:

1. to set the ownership for creation requests
2. to determine whether this client is allowed access on this server

Case 1. we already covered and explained. Case 2. is only relevant for
servers where an explicit uid access restriction has been set. That is
to say the mds server restricts access to requests coming from a
specific uid. Servers without uid restrictions will grant access to
requests from any uid by setting MDS_AUTH_UID_ANY.

Case 2. introduces the complication because the caller's fs{g,u}id is
not just used to record ownership but also serves as the {g,u}id used
when checking access to the server.

Consider a user mounting a cephfs client and creating an idmapped mount
from it that maps files owned by uid 1000 to be owned uid 0:

mount -t cephfs -o [...] /unmapped
mount-idmapped --map-mount 1000:0:1 /idmapped

That is to say if the mounted cephfs filesystem contains a file "file1"
which is owned by uid 1000:

- looking at it via /unmapped/file1 will report it as owned by uid 1000
  (One can think of this as the on-disk value.)
- looking at it via /idmapped/file1 will report it as owned by uid 0

Now, consider creating new files via the idmapped mount at /idmapped.
When a caller with fs{g,u}id 1000 creates a file "file2" by going
through the idmapped mount mounted at /idmapped it will create a file
that is owned by uid 1000 on-disk, i.e.:

- looking at it via /unmapped/file2 will report it as owned by uid 1000
- looking at it via /idmapped/file2 will report it as owned by uid 0

Now consider an mds server that has a uid access restriction set and
only grants access to requests from uid 0.

If the client sends a creation request for a file e.g. /idmapped/file2
it will send the caller's fs{g,u}id idmapped according to the idmapped
mount. So if the caller has fs{g,u}id 1000 it will be mapped to {g,u}id
0 in the idmapped mount and will be sent over the wire allowing the
caller access to the mds server.

However, if the caller is not issuing a creation request the caller's
fs{g,u}id will be send without the mount's idmapping applied. So if the
caller that just successfully created a new file on the restricted mds
server sends a request as fs{g,u}id 1000 access will be refused. This
however is inconsistent.

From my perspective the root of the problem lies in the fact that
creation requests implicitly infer the ownership from the {g,u}id that
gets sent along with every mds request.

I have thought of multiple ways of addressing this problem but the one I
prefer is to give all mds requests that create a filesystem object a
proper, separate {g,u}id field entry in the argument struct. This is,
for example how ->setattr mds requests work.

This way the caller's fs{g,u}id can be used consistenly for server
access checks and is separated from the ownership for new filesystem
objects.

Servers could then be updated to refuse creation requests whenever the
{g,u}id used for access checking doesn't match the {g,u}id used for
creating the filesystem object just as is done for setattr requests on a
uid restricted server. But I am, of course, open to other suggestions.

Cc: Xiubo Li <xiubli@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: ceph-devel@vger.kernel.org
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
---
 fs/ceph/mds_client.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 083d0329f62d..73fd5784daf8 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -2887,6 +2887,8 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session,
 	void *p, *end;
 	int ret;
 	bool legacy = !(session->s_con.peer_features & CEPH_FEATURE_FS_BTIME);
+	kuid_t caller_fsuid;
+	kgid_t caller_fsgid;
 
 	ret = set_request_path_attr(req->r_inode, req->r_dentry,
 			      req->r_parent, req->r_path1, req->r_ino1.ino,
@@ -2984,10 +2986,22 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session,
 
 	head->mdsmap_epoch = cpu_to_le32(mdsc->mdsmap->m_epoch);
 	head->op = cpu_to_le32(req->r_op);
-	head->caller_uid = cpu_to_le32(from_kuid(&init_user_ns,
-						 req->r_cred->fsuid));
-	head->caller_gid = cpu_to_le32(from_kgid(&init_user_ns,
-						 req->r_cred->fsgid));
+	/*
+	 * Inode operations that create filesystem objects based on the
+	 * caller's fs{g,u}id like ->mknod(), ->create(), ->mkdir() etc. don't
+	 * have separate {g,u}id fields in their respective structs in the
+	 * ceph_mds_request_args union. Instead the caller_{g,u}id field is
+	 * used to set ownership of the newly created inode by the mds server.
+	 * For these inode operations we need to send the mapped fs{g,u}id over
+	 * the wire. For other cases we simple set req->r_mnt_idmap to the
+	 * initial idmapping meaning the unmapped fs{g,u}id is sent.
+	 */
+	caller_fsuid = from_vfsuid(req->r_mnt_idmap, &init_user_ns,
+					VFSUIDT_INIT(req->r_cred->fsuid));
+	caller_fsgid = from_vfsgid(req->r_mnt_idmap, &init_user_ns,
+					VFSGIDT_INIT(req->r_cred->fsgid));
+	head->caller_uid = cpu_to_le32(from_kuid(&init_user_ns, caller_fsuid));
+	head->caller_gid = cpu_to_le32(from_kgid(&init_user_ns, caller_fsgid));
 	head->ino = cpu_to_le64(req->r_deleg_ino);
 	head->args = req->r_args;
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v6 04/15] ceph: pass an idmapping to mknod/symlink/mkdir/rename
  2023-06-09  9:31 [PATCH v6 00/15] ceph: support idmapped mounts Alexander Mikhalitsyn
                   ` (2 preceding siblings ...)
  2023-06-09  9:31 ` [PATCH v6 03/15] ceph: handle idmapped mounts in create_request_message() Alexander Mikhalitsyn
@ 2023-06-09  9:31 ` Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 05/15] ceph: allow idmapped getattr inode op Alexander Mikhalitsyn
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Alexander Mikhalitsyn @ 2023-06-09  9:31 UTC (permalink / raw)
  To: xiubli
  Cc: brauner, stgraber, linux-fsdevel, Christian Brauner, Jeff Layton,
	Ilya Dryomov, ceph-devel, Alexander Mikhalitsyn, linux-kernel

From: Christian Brauner <christian.brauner@ubuntu.com>

Enable mknod/symlink/mkdir/rename iops to handle idmapped mounts.
This is just a matter of passing down the mount's idmapping.

Cc: Xiubo Li <xiubli@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: ceph-devel@vger.kernel.org
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
---
v4:
	- call mnt_idmap_get
---
 fs/ceph/dir.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index 1b46f2b998c3..2c0c2c98085b 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -923,6 +923,7 @@ static int ceph_mknod(struct mnt_idmap *idmap, struct inode *dir,
 	req->r_parent = dir;
 	ihold(dir);
 	set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
+	req->r_mnt_idmap = mnt_idmap_get(idmap);
 	req->r_args.mknod.mode = cpu_to_le32(mode);
 	req->r_args.mknod.rdev = cpu_to_le32(rdev);
 	req->r_dentry_drop = CEPH_CAP_FILE_SHARED | CEPH_CAP_AUTH_EXCL | CEPH_CAP_XATTR_EXCL;
@@ -1035,6 +1036,7 @@ static int ceph_symlink(struct mnt_idmap *idmap, struct inode *dir,
 	}
 
 	set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
+	req->r_mnt_idmap = mnt_idmap_get(idmap);
 	req->r_dentry = dget(dentry);
 	req->r_num_caps = 2;
 	req->r_dentry_drop = CEPH_CAP_FILE_SHARED | CEPH_CAP_AUTH_EXCL | CEPH_CAP_XATTR_EXCL;
@@ -1111,6 +1113,7 @@ static int ceph_mkdir(struct mnt_idmap *idmap, struct inode *dir,
 	req->r_parent = dir;
 	ihold(dir);
 	set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
+	req->r_mnt_idmap = mnt_idmap_get(idmap);
 	req->r_args.mkdir.mode = cpu_to_le32(mode);
 	req->r_dentry_drop = CEPH_CAP_FILE_SHARED | CEPH_CAP_AUTH_EXCL | CEPH_CAP_XATTR_EXCL;
 	req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
@@ -1422,6 +1425,7 @@ static int ceph_rename(struct mnt_idmap *idmap, struct inode *old_dir,
 	req->r_old_dentry_unless = CEPH_CAP_FILE_EXCL;
 	req->r_dentry_drop = CEPH_CAP_FILE_SHARED | CEPH_CAP_XATTR_EXCL;
 	req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
+	req->r_mnt_idmap = mnt_idmap_get(idmap);
 	/* release LINK_RDCACHE on source inode (mds will lock it) */
 	req->r_old_inode_drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL;
 	if (d_really_is_positive(new_dentry)) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v6 05/15] ceph: allow idmapped getattr inode op
  2023-06-09  9:31 [PATCH v6 00/15] ceph: support idmapped mounts Alexander Mikhalitsyn
                   ` (3 preceding siblings ...)
  2023-06-09  9:31 ` [PATCH v6 04/15] ceph: pass an idmapping to mknod/symlink/mkdir/rename Alexander Mikhalitsyn
@ 2023-06-09  9:31 ` Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 06/15] ceph: allow idmapped permission " Alexander Mikhalitsyn
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Alexander Mikhalitsyn @ 2023-06-09  9:31 UTC (permalink / raw)
  To: xiubli
  Cc: brauner, stgraber, linux-fsdevel, Christian Brauner, Jeff Layton,
	Ilya Dryomov, ceph-devel, Alexander Mikhalitsyn, linux-kernel

From: Christian Brauner <christian.brauner@ubuntu.com>

Enable ceph_getattr() to handle idmapped mounts. This is just a matter
of passing down the mount's idmapping.

Cc: Xiubo Li <xiubli@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: ceph-devel@vger.kernel.org
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
---
 fs/ceph/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index fe8adb9d67a6..533349fe542f 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -2979,7 +2979,7 @@ int ceph_getattr(struct mnt_idmap *idmap, const struct path *path,
 			return err;
 	}
 
-	generic_fillattr(&nop_mnt_idmap, inode, stat);
+	generic_fillattr(idmap, inode, stat);
 	stat->ino = ceph_present_inode(inode);
 
 	/*
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v6 06/15] ceph: allow idmapped permission inode op
  2023-06-09  9:31 [PATCH v6 00/15] ceph: support idmapped mounts Alexander Mikhalitsyn
                   ` (4 preceding siblings ...)
  2023-06-09  9:31 ` [PATCH v6 05/15] ceph: allow idmapped getattr inode op Alexander Mikhalitsyn
@ 2023-06-09  9:31 ` Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 07/15] ceph: pass idmap to __ceph_setattr Alexander Mikhalitsyn
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Alexander Mikhalitsyn @ 2023-06-09  9:31 UTC (permalink / raw)
  To: xiubli
  Cc: brauner, stgraber, linux-fsdevel, Christian Brauner, Jeff Layton,
	Ilya Dryomov, ceph-devel, Alexander Mikhalitsyn, linux-kernel

From: Christian Brauner <christian.brauner@ubuntu.com>

Enable ceph_permission() to handle idmapped mounts. This is just a
matter of passing down the mount's idmapping.

Cc: Xiubo Li <xiubli@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: ceph-devel@vger.kernel.org
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
---
 fs/ceph/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index 533349fe542f..f45d9c066523 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -2922,7 +2922,7 @@ int ceph_permission(struct mnt_idmap *idmap, struct inode *inode,
 	err = ceph_do_getattr(inode, CEPH_CAP_AUTH_SHARED, false);
 
 	if (!err)
-		err = generic_permission(&nop_mnt_idmap, inode, mask);
+		err = generic_permission(idmap, inode, mask);
 	return err;
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v6 07/15] ceph: pass idmap to __ceph_setattr
  2023-06-09  9:31 [PATCH v6 00/15] ceph: support idmapped mounts Alexander Mikhalitsyn
                   ` (5 preceding siblings ...)
  2023-06-09  9:31 ` [PATCH v6 06/15] ceph: allow idmapped permission " Alexander Mikhalitsyn
@ 2023-06-09  9:31 ` Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 08/15] ceph: allow idmapped setattr inode op Alexander Mikhalitsyn
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Alexander Mikhalitsyn @ 2023-06-09  9:31 UTC (permalink / raw)
  To: xiubli
  Cc: brauner, stgraber, linux-fsdevel, Alexander Mikhalitsyn,
	Jeff Layton, Ilya Dryomov, ceph-devel, linux-kernel

Just pass down the mount's idmapping to __ceph_setattr,
because we will need it later.

Cc: Xiubo Li <xiubli@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: brauner@kernel.org
Cc: ceph-devel@vger.kernel.org
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
---
 fs/ceph/acl.c    | 4 ++--
 fs/ceph/crypto.c | 2 +-
 fs/ceph/inode.c  | 6 ++++--
 fs/ceph/super.h  | 3 ++-
 4 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/fs/ceph/acl.c b/fs/ceph/acl.c
index 8a56f979c7cb..f53f7a758c05 100644
--- a/fs/ceph/acl.c
+++ b/fs/ceph/acl.c
@@ -140,7 +140,7 @@ int ceph_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
 		newattrs.ia_ctime = current_time(inode);
 		newattrs.ia_mode = new_mode;
 		newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
-		ret = __ceph_setattr(inode, &newattrs, NULL);
+		ret = __ceph_setattr(idmap, inode, &newattrs, NULL);
 		if (ret)
 			goto out_free;
 	}
@@ -151,7 +151,7 @@ int ceph_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
 			newattrs.ia_ctime = old_ctime;
 			newattrs.ia_mode = old_mode;
 			newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
-			__ceph_setattr(inode, &newattrs, NULL);
+			__ceph_setattr(idmap, inode, &newattrs, NULL);
 		}
 		goto out_free;
 	}
diff --git a/fs/ceph/crypto.c b/fs/ceph/crypto.c
index e72bab29d5e1..8e298d7bf570 100644
--- a/fs/ceph/crypto.c
+++ b/fs/ceph/crypto.c
@@ -112,7 +112,7 @@ static int ceph_crypt_set_context(struct inode *inode, const void *ctx, size_t l
 
 	cia.fscrypt_auth = cfa;
 
-	ret = __ceph_setattr(inode, &attr, &cia);
+	ret = __ceph_setattr(&nop_mnt_idmap, inode, &attr, &cia);
 	if (ret == 0)
 		inode_set_flags(inode, S_ENCRYPTED, S_ENCRYPTED);
 	kfree(cia.fscrypt_auth);
diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index f45d9c066523..9a4579da32f8 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -2424,7 +2424,8 @@ static int fill_fscrypt_truncate(struct inode *inode,
 	return ret;
 }
 
-int __ceph_setattr(struct inode *inode, struct iattr *attr, struct ceph_iattr *cia)
+int __ceph_setattr(struct mnt_idmap *idmap, struct inode *inode,
+		   struct iattr *attr, struct ceph_iattr *cia)
 {
 	struct ceph_inode_info *ci = ceph_inode(inode);
 	unsigned int ia_valid = attr->ia_valid;
@@ -2695,6 +2696,7 @@ int __ceph_setattr(struct inode *inode, struct iattr *attr, struct ceph_iattr *c
 	if (mask) {
 		req->r_inode = inode;
 		ihold(inode);
+		req->r_mnt_idmap = mnt_idmap_get(idmap);
 		req->r_inode_drop = release;
 		req->r_args.setattr.mask = cpu_to_le32(mask);
 		req->r_num_caps = 1;
@@ -2766,7 +2768,7 @@ int ceph_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 	    ceph_quota_is_max_bytes_exceeded(inode, attr->ia_size))
 		return -EDQUOT;
 
-	err = __ceph_setattr(inode, attr, NULL);
+	err = __ceph_setattr(idmap, inode, attr, NULL);
 
 	if (err >= 0 && (attr->ia_valid & ATTR_MODE))
 		err = posix_acl_chmod(&nop_mnt_idmap, dentry, attr->ia_mode);
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index 107a9d16a4e8..8516ac571da9 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -1095,7 +1095,8 @@ struct ceph_iattr {
 	struct ceph_fscrypt_auth	*fscrypt_auth;
 };
 
-extern int __ceph_setattr(struct inode *inode, struct iattr *attr, struct ceph_iattr *cia);
+extern int __ceph_setattr(struct mnt_idmap *idmap, struct inode *inode,
+			  struct iattr *attr, struct ceph_iattr *cia);
 extern int ceph_setattr(struct mnt_idmap *idmap,
 			struct dentry *dentry, struct iattr *attr);
 extern int ceph_getattr(struct mnt_idmap *idmap,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v6 08/15] ceph: allow idmapped setattr inode op
  2023-06-09  9:31 [PATCH v6 00/15] ceph: support idmapped mounts Alexander Mikhalitsyn
                   ` (6 preceding siblings ...)
  2023-06-09  9:31 ` [PATCH v6 07/15] ceph: pass idmap to __ceph_setattr Alexander Mikhalitsyn
@ 2023-06-09  9:31 ` Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 09/15] ceph/acl: allow idmapped set_acl " Alexander Mikhalitsyn
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Alexander Mikhalitsyn @ 2023-06-09  9:31 UTC (permalink / raw)
  To: xiubli
  Cc: brauner, stgraber, linux-fsdevel, Christian Brauner, Jeff Layton,
	Ilya Dryomov, ceph-devel, Alexander Mikhalitsyn, linux-kernel

From: Christian Brauner <christian.brauner@ubuntu.com>

Enable __ceph_setattr() to handle idmapped mounts. This is just a matter
of passing down the mount's idmapping.

Cc: Xiubo Li <xiubli@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: ceph-devel@vger.kernel.org
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
[ adapted to b27c82e12965 ("attr: port attribute changes to new types") ]
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
---
v4:
	- introduced fsuid/fsgid local variables
v3:
	- reworked as Christian suggested here:
	https://lore.kernel.org/lkml/20230602-vorzeichen-praktikum-f17931692301@brauner/
---
 fs/ceph/inode.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index 9a4579da32f8..6a8aeb4b8fb8 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -2509,31 +2509,35 @@ int __ceph_setattr(struct mnt_idmap *idmap, struct inode *inode,
 #endif /* CONFIG_FS_ENCRYPTION */
 
 	if (ia_valid & ATTR_UID) {
+		kuid_t fsuid = from_vfsuid(idmap, i_user_ns(inode), attr->ia_vfsuid);
+
 		dout("setattr %p uid %d -> %d\n", inode,
 		     from_kuid(&init_user_ns, inode->i_uid),
 		     from_kuid(&init_user_ns, attr->ia_uid));
 		if (issued & CEPH_CAP_AUTH_EXCL) {
-			inode->i_uid = attr->ia_uid;
+			inode->i_uid = fsuid;
 			dirtied |= CEPH_CAP_AUTH_EXCL;
 		} else if ((issued & CEPH_CAP_AUTH_SHARED) == 0 ||
-			   !uid_eq(attr->ia_uid, inode->i_uid)) {
+			   !uid_eq(fsuid, inode->i_uid)) {
 			req->r_args.setattr.uid = cpu_to_le32(
-				from_kuid(&init_user_ns, attr->ia_uid));
+				from_kuid(&init_user_ns, fsuid));
 			mask |= CEPH_SETATTR_UID;
 			release |= CEPH_CAP_AUTH_SHARED;
 		}
 	}
 	if (ia_valid & ATTR_GID) {
+		kgid_t fsgid = from_vfsgid(idmap, i_user_ns(inode), attr->ia_vfsgid);
+
 		dout("setattr %p gid %d -> %d\n", inode,
 		     from_kgid(&init_user_ns, inode->i_gid),
 		     from_kgid(&init_user_ns, attr->ia_gid));
 		if (issued & CEPH_CAP_AUTH_EXCL) {
-			inode->i_gid = attr->ia_gid;
+			inode->i_gid = fsgid;
 			dirtied |= CEPH_CAP_AUTH_EXCL;
 		} else if ((issued & CEPH_CAP_AUTH_SHARED) == 0 ||
-			   !gid_eq(attr->ia_gid, inode->i_gid)) {
+			   !gid_eq(fsgid, inode->i_gid)) {
 			req->r_args.setattr.gid = cpu_to_le32(
-				from_kgid(&init_user_ns, attr->ia_gid));
+				from_kgid(&init_user_ns, fsgid));
 			mask |= CEPH_SETATTR_GID;
 			release |= CEPH_CAP_AUTH_SHARED;
 		}
@@ -2756,7 +2760,7 @@ int ceph_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 	if (err)
 		return err;
 
-	err = setattr_prepare(&nop_mnt_idmap, dentry, attr);
+	err = setattr_prepare(idmap, dentry, attr);
 	if (err != 0)
 		return err;
 
@@ -2771,7 +2775,7 @@ int ceph_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 	err = __ceph_setattr(idmap, inode, attr, NULL);
 
 	if (err >= 0 && (attr->ia_valid & ATTR_MODE))
-		err = posix_acl_chmod(&nop_mnt_idmap, dentry, attr->ia_mode);
+		err = posix_acl_chmod(idmap, dentry, attr->ia_mode);
 
 	return err;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v6 09/15] ceph/acl: allow idmapped set_acl inode op
  2023-06-09  9:31 [PATCH v6 00/15] ceph: support idmapped mounts Alexander Mikhalitsyn
                   ` (7 preceding siblings ...)
  2023-06-09  9:31 ` [PATCH v6 08/15] ceph: allow idmapped setattr inode op Alexander Mikhalitsyn
@ 2023-06-09  9:31 ` Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 10/15] ceph/file: allow idmapped atomic_open " Alexander Mikhalitsyn
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Alexander Mikhalitsyn @ 2023-06-09  9:31 UTC (permalink / raw)
  To: xiubli
  Cc: brauner, stgraber, linux-fsdevel, Christian Brauner, Jeff Layton,
	Ilya Dryomov, ceph-devel, Alexander Mikhalitsyn, linux-kernel

From: Christian Brauner <christian.brauner@ubuntu.com>

Enable ceph_set_acl() to handle idmapped mounts. This is just a matter
of passing down the mount's idmapping.

Cc: Xiubo Li <xiubli@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: ceph-devel@vger.kernel.org
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
---
 fs/ceph/acl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ceph/acl.c b/fs/ceph/acl.c
index f53f7a758c05..d4be4c2d63c3 100644
--- a/fs/ceph/acl.c
+++ b/fs/ceph/acl.c
@@ -105,7 +105,7 @@ int ceph_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
 	case ACL_TYPE_ACCESS:
 		name = XATTR_NAME_POSIX_ACL_ACCESS;
 		if (acl) {
-			ret = posix_acl_update_mode(&nop_mnt_idmap, inode,
+			ret = posix_acl_update_mode(idmap, inode,
 						    &new_mode, &acl);
 			if (ret)
 				goto out;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v6 10/15] ceph/file: allow idmapped atomic_open inode op
  2023-06-09  9:31 [PATCH v6 00/15] ceph: support idmapped mounts Alexander Mikhalitsyn
                   ` (8 preceding siblings ...)
  2023-06-09  9:31 ` [PATCH v6 09/15] ceph/acl: allow idmapped set_acl " Alexander Mikhalitsyn
@ 2023-06-09  9:31 ` Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 11/15] ceph: pass idmap to ceph_do_getattr Alexander Mikhalitsyn
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Alexander Mikhalitsyn @ 2023-06-09  9:31 UTC (permalink / raw)
  To: xiubli
  Cc: brauner, stgraber, linux-fsdevel, Christian Brauner, Jeff Layton,
	Ilya Dryomov, ceph-devel, Alexander Mikhalitsyn, linux-kernel

From: Christian Brauner <christian.brauner@ubuntu.com>

Enable ceph_atomic_open() to handle idmapped mounts. This is just a
matter of passing down the mount's idmapping.

Cc: Xiubo Li <xiubli@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: ceph-devel@vger.kernel.org
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
[ adapted to 5fadbd9929 ("ceph: rely on vfs for setgid stripping") ]
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
---
v4:
	- call mnt_idmap_get
---
 fs/ceph/file.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index e878a462c7c3..7be172f29c0b 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -655,7 +655,9 @@ static int ceph_finish_async_create(struct inode *dir, struct inode *inode,
 	in.truncate_seq = cpu_to_le32(1);
 	in.truncate_size = cpu_to_le64(-1ULL);
 	in.xattr_version = cpu_to_le64(1);
-	in.uid = cpu_to_le32(from_kuid(&init_user_ns, current_fsuid()));
+	in.uid = cpu_to_le32(from_kuid(&init_user_ns,
+				       mapped_fsuid(req->r_mnt_idmap,
+						    &init_user_ns)));
 	if (dir->i_mode & S_ISGID) {
 		in.gid = cpu_to_le32(from_kgid(&init_user_ns, dir->i_gid));
 
@@ -663,7 +665,9 @@ static int ceph_finish_async_create(struct inode *dir, struct inode *inode,
 		if (S_ISDIR(mode))
 			mode |= S_ISGID;
 	} else {
-		in.gid = cpu_to_le32(from_kgid(&init_user_ns, current_fsgid()));
+		in.gid = cpu_to_le32(from_kgid(&init_user_ns,
+				     mapped_fsgid(req->r_mnt_idmap,
+						  &init_user_ns)));
 	}
 	in.mode = cpu_to_le32((u32)mode);
 
@@ -731,6 +735,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
 		     struct file *file, unsigned flags, umode_t mode)
 {
 	struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
+	struct mnt_idmap *idmap = file_mnt_idmap(file);
 	struct ceph_mds_client *mdsc = fsc->mdsc;
 	struct ceph_mds_request *req;
 	struct inode *new_inode = NULL;
@@ -788,6 +793,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
 		mask |= CEPH_CAP_XATTR_SHARED;
 	req->r_args.open.mask = cpu_to_le32(mask);
 	req->r_parent = dir;
+	req->r_mnt_idmap = mnt_idmap_get(idmap);
 	ihold(dir);
 	if (IS_ENCRYPTED(dir)) {
 		set_bit(CEPH_MDS_R_FSCRYPT_FILE, &req->r_req_flags);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v6 11/15] ceph: pass idmap to ceph_do_getattr
  2023-06-09  9:31 [PATCH v6 00/15] ceph: support idmapped mounts Alexander Mikhalitsyn
                   ` (9 preceding siblings ...)
  2023-06-09  9:31 ` [PATCH v6 10/15] ceph/file: allow idmapped atomic_open " Alexander Mikhalitsyn
@ 2023-06-09  9:31 ` Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 12/15] ceph: pass idmap to __ceph_setxattr Alexander Mikhalitsyn
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Alexander Mikhalitsyn @ 2023-06-09  9:31 UTC (permalink / raw)
  To: xiubli
  Cc: brauner, stgraber, linux-fsdevel, Alexander Mikhalitsyn,
	Jeff Layton, Ilya Dryomov, ceph-devel, linux-kernel

Just pass down the mount's idmapping to *ceph_do_getattr,
everywhere when possible, because we will need it later.

Here we have two cases:
- filemap_fault/read/write/lseek (when idmap is accessible)
- export_ops/list_xattr/get_xattr (when idmap is not accessible)
in this case we pass &nop_mnt_idmap.

So we can meet permission issue when MDS UID/GID-based path
restriction is used.

Cc: Xiubo Li <xiubli@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: brauner@kernel.org
Cc: ceph-devel@vger.kernel.org
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
---
v6:
	- fscrypt rebase
---
 fs/ceph/addr.c   |  3 ++-
 fs/ceph/caps.c   |  8 +++++---
 fs/ceph/export.c |  2 +-
 fs/ceph/file.c   |  9 ++++++---
 fs/ceph/inode.c  | 15 +++++++++------
 fs/ceph/ioctl.c  |  6 ++++--
 fs/ceph/quota.c  |  2 +-
 fs/ceph/super.c  |  4 ++--
 fs/ceph/super.h  | 11 +++++++----
 fs/ceph/xattr.c  |  6 +++---
 10 files changed, 40 insertions(+), 26 deletions(-)

diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index de9b82905f18..0a32475ed034 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -1630,6 +1630,7 @@ static vm_fault_t ceph_filemap_fault(struct vm_fault *vmf)
 		/* does not support inline data > PAGE_SIZE */
 		ret = VM_FAULT_SIGBUS;
 	} else {
+		struct mnt_idmap *idmap = file_mnt_idmap(vma->vm_file);
 		struct address_space *mapping = inode->i_mapping;
 		struct page *page;
 
@@ -1640,7 +1641,7 @@ static vm_fault_t ceph_filemap_fault(struct vm_fault *vmf)
 			ret = VM_FAULT_OOM;
 			goto out_inline;
 		}
-		err = __ceph_do_getattr(inode, page,
+		err = __ceph_do_getattr(idmap, inode, page,
 					 CEPH_STAT_CAP_INLINE_DATA, true);
 		if (err < 0 || off >= i_size_read(inode)) {
 			unlock_page(page);
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 5498bc36c1e7..b432f29e80dd 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -2958,7 +2958,8 @@ int ceph_try_get_caps(struct inode *inode, int need, int want,
  * due to a small max_size, make sure we check_max_size (and possibly
  * ask the mds) so we don't get hung up indefinitely.
  */
-int __ceph_get_caps(struct inode *inode, struct ceph_file_info *fi, int need,
+int __ceph_get_caps(struct mnt_idmap *idmap, struct inode *inode,
+		    struct ceph_file_info *fi, int need,
 		    int want, loff_t endoff, int *got)
 {
 	struct ceph_inode_info *ci = ceph_inode(inode);
@@ -3072,7 +3073,7 @@ int __ceph_get_caps(struct inode *inode, struct ceph_file_info *fi, int need,
 			 * getattr request will bring inline data into
 			 * page cache
 			 */
-			ret = __ceph_do_getattr(inode, NULL,
+			ret = __ceph_do_getattr(idmap, inode, NULL,
 						CEPH_STAT_CAP_INLINE_DATA,
 						true);
 			if (ret < 0)
@@ -3089,8 +3090,9 @@ int ceph_get_caps(struct file *filp, int need, int want, loff_t endoff, int *got
 {
 	struct ceph_file_info *fi = filp->private_data;
 	struct inode *inode = file_inode(filp);
+	struct mnt_idmap *idmap = file_mnt_idmap(filp);
 
-	return __ceph_get_caps(inode, fi, need, want, endoff, got);
+	return __ceph_get_caps(idmap, inode, fi, need, want, endoff, got);
 }
 
 /*
diff --git a/fs/ceph/export.c b/fs/ceph/export.c
index 8559990a59a5..4b422070ca2b 100644
--- a/fs/ceph/export.c
+++ b/fs/ceph/export.c
@@ -188,7 +188,7 @@ static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino)
 	if (IS_ERR(inode))
 		return ERR_CAST(inode);
 	/* We need LINK caps to reliably check i_nlink */
-	err = ceph_do_getattr(inode, CEPH_CAP_LINK_SHARED, false);
+	err = ceph_do_getattr(&nop_mnt_idmap, inode, CEPH_CAP_LINK_SHARED, false);
 	if (err) {
 		iput(inode);
 		return ERR_PTR(err);
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index 7be172f29c0b..c2bb8f5fd345 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -2009,6 +2009,7 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to)
 	size_t len = iov_iter_count(to);
 	struct inode *inode = file_inode(filp);
 	struct ceph_inode_info *ci = ceph_inode(inode);
+	struct mnt_idmap *idmap = file_mnt_idmap(filp);
 	bool direct_lock = iocb->ki_flags & IOCB_DIRECT;
 	ssize_t ret;
 	int want = 0, got = 0;
@@ -2091,7 +2092,7 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to)
 				return -ENOMEM;
 		}
 
-		statret = __ceph_do_getattr(inode, page,
+		statret = __ceph_do_getattr(idmap, inode, page,
 					    CEPH_STAT_CAP_INLINE_DATA, !!page);
 		if (statret < 0) {
 			if (page)
@@ -2166,6 +2167,7 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	struct inode *inode = file_inode(file);
 	struct ceph_inode_info *ci = ceph_inode(inode);
 	struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
+	struct mnt_idmap *idmap = file_mnt_idmap(file);
 	struct ceph_osd_client *osdc = &fsc->client->osdc;
 	struct ceph_cap_flush *prealloc_cf;
 	ssize_t count, written = 0;
@@ -2199,7 +2201,7 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	current->backing_dev_info = inode_to_bdi(inode);
 
 	if (iocb->ki_flags & IOCB_APPEND) {
-		err = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE, false);
+		err = ceph_do_getattr(idmap, inode, CEPH_STAT_CAP_SIZE, false);
 		if (err < 0)
 			goto out;
 	}
@@ -2355,9 +2357,10 @@ static loff_t ceph_llseek(struct file *file, loff_t offset, int whence)
 {
 	if (whence == SEEK_END || whence == SEEK_DATA || whence == SEEK_HOLE) {
 		struct inode *inode = file_inode(file);
+		struct mnt_idmap *idmap = file_mnt_idmap(file);
 		int ret;
 
-		ret = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE, false);
+		ret = ceph_do_getattr(idmap, inode, CEPH_STAT_CAP_SIZE, false);
 		if (ret < 0)
 			return ret;
 	}
diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index 6a8aeb4b8fb8..49ca13c5b9d8 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -2292,7 +2292,8 @@ static const struct inode_operations ceph_encrypted_symlink_iops = {
  * We don't support a PAGE_SIZE that is smaller than the
  * CEPH_FSCRYPT_BLOCK_SIZE.
  */
-static int fill_fscrypt_truncate(struct inode *inode,
+static int fill_fscrypt_truncate(struct mnt_idmap *idmap,
+				 struct inode *inode,
 				 struct ceph_mds_request *req,
 				 struct iattr *attr)
 {
@@ -2311,7 +2312,7 @@ static int fill_fscrypt_truncate(struct inode *inode,
 	int got, ret, issued;
 	u64 objver;
 
-	ret = __ceph_get_caps(inode, NULL, CEPH_CAP_FILE_RD, 0, -1, &got);
+	ret = __ceph_get_caps(idmap, inode, NULL, CEPH_CAP_FILE_RD, 0, -1, &got);
 	if (ret < 0)
 		return ret;
 
@@ -2706,7 +2707,7 @@ int __ceph_setattr(struct mnt_idmap *idmap, struct inode *inode,
 		req->r_num_caps = 1;
 		req->r_stamp = attr->ia_ctime;
 		if (fill_fscrypt) {
-			err = fill_fscrypt_truncate(inode, req, attr);
+			err = fill_fscrypt_truncate(idmap, inode, req, attr);
 			if (err)
 				goto out;
 		}
@@ -2814,7 +2815,8 @@ int ceph_try_to_choose_auth_mds(struct inode *inode, int mask)
  * Verify that we have a lease on the given mask.  If not,
  * do a getattr against an mds.
  */
-int __ceph_do_getattr(struct inode *inode, struct page *locked_page,
+int __ceph_do_getattr(struct mnt_idmap *idmap, struct inode *inode,
+		      struct page *locked_page,
 		      int mask, bool force)
 {
 	struct ceph_fs_client *fsc = ceph_sb_to_client(inode->i_sb);
@@ -2839,6 +2841,7 @@ int __ceph_do_getattr(struct inode *inode, struct page *locked_page,
 		return PTR_ERR(req);
 	req->r_inode = inode;
 	ihold(inode);
+	req->r_mnt_idmap = mnt_idmap_get(idmap);
 	req->r_num_caps = 1;
 	req->r_args.getattr.mask = cpu_to_le32(mask);
 	req->r_locked_page = locked_page;
@@ -2925,7 +2928,7 @@ int ceph_permission(struct mnt_idmap *idmap, struct inode *inode,
 	if (mask & MAY_NOT_BLOCK)
 		return -ECHILD;
 
-	err = ceph_do_getattr(inode, CEPH_CAP_AUTH_SHARED, false);
+	err = ceph_do_getattr(idmap, inode, CEPH_CAP_AUTH_SHARED, false);
 
 	if (!err)
 		err = generic_permission(idmap, inode, mask);
@@ -2978,7 +2981,7 @@ int ceph_getattr(struct mnt_idmap *idmap, const struct path *path,
 
 	/* Skip the getattr altogether if we're asked not to sync */
 	if ((flags & AT_STATX_SYNC_TYPE) != AT_STATX_DONT_SYNC) {
-		err = ceph_do_getattr(inode,
+		err = ceph_do_getattr(idmap, inode,
 				statx_to_caps(request_mask, inode->i_mode),
 				flags & AT_STATX_FORCE_SYNC);
 		if (err)
diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c
index 679402bd80ba..6fa021b973e5 100644
--- a/fs/ceph/ioctl.c
+++ b/fs/ceph/ioctl.c
@@ -18,10 +18,11 @@
 static long ceph_ioctl_get_layout(struct file *file, void __user *arg)
 {
 	struct ceph_inode_info *ci = ceph_inode(file_inode(file));
+	struct mnt_idmap *idmap = file_mnt_idmap(file);
 	struct ceph_ioctl_layout l;
 	int err;
 
-	err = ceph_do_getattr(file_inode(file), CEPH_STAT_CAP_LAYOUT, false);
+	err = ceph_do_getattr(idmap, file_inode(file), CEPH_STAT_CAP_LAYOUT, false);
 	if (!err) {
 		l.stripe_unit = ci->i_layout.stripe_unit;
 		l.stripe_count = ci->i_layout.stripe_count;
@@ -65,6 +66,7 @@ static long __validate_layout(struct ceph_mds_client *mdsc,
 static long ceph_ioctl_set_layout(struct file *file, void __user *arg)
 {
 	struct inode *inode = file_inode(file);
+	struct mnt_idmap *idmap = file_mnt_idmap(file);
 	struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc;
 	struct ceph_mds_request *req;
 	struct ceph_ioctl_layout l;
@@ -76,7 +78,7 @@ static long ceph_ioctl_set_layout(struct file *file, void __user *arg)
 		return -EFAULT;
 
 	/* validate changed params against current layout */
-	err = ceph_do_getattr(file_inode(file), CEPH_STAT_CAP_LAYOUT, false);
+	err = ceph_do_getattr(idmap, file_inode(file), CEPH_STAT_CAP_LAYOUT, false);
 	if (err)
 		return err;
 
diff --git a/fs/ceph/quota.c b/fs/ceph/quota.c
index f7fcf7f08ec6..515423b3ddea 100644
--- a/fs/ceph/quota.c
+++ b/fs/ceph/quota.c
@@ -150,7 +150,7 @@ static struct inode *lookup_quotarealm_inode(struct ceph_mds_client *mdsc,
 	}
 	if (qri->inode) {
 		/* get caps */
-		int ret = __ceph_do_getattr(qri->inode, NULL,
+		int ret = __ceph_do_getattr(&nop_mnt_idmap, qri->inode, NULL,
 					    CEPH_STAT_CAP_INODE, true);
 		if (ret >= 0)
 			in = qri->inode;
diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index 070b3150d267..3d6d0010d638 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -1607,8 +1607,8 @@ int ceph_force_reconnect(struct super_block *sb)
 	fsc->mount_state = CEPH_MOUNT_MOUNTED;
 
 	if (sb->s_root) {
-		err = __ceph_do_getattr(d_inode(sb->s_root), NULL,
-					CEPH_STAT_CAP_INODE, true);
+		err = __ceph_do_getattr(&nop_mnt_idmap, d_inode(sb->s_root),
+					NULL, CEPH_STAT_CAP_INODE, true);
 	}
 	return err;
 }
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index 8516ac571da9..57cbb69a17c8 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -1082,11 +1082,13 @@ static inline void ceph_queue_flush_snaps(struct inode *inode)
 }
 
 extern int ceph_try_to_choose_auth_mds(struct inode *inode, int mask);
-extern int __ceph_do_getattr(struct inode *inode, struct page *locked_page,
+extern int __ceph_do_getattr(struct mnt_idmap *idmap, struct inode *inode,
+			     struct page *locked_page,
 			     int mask, bool force);
-static inline int ceph_do_getattr(struct inode *inode, int mask, bool force)
+static inline int ceph_do_getattr(struct mnt_idmap *idmap, struct inode *inode,
+				  int mask, bool force)
 {
-	return __ceph_do_getattr(inode, NULL, mask, force);
+	return __ceph_do_getattr(idmap, inode, NULL, mask, force);
 }
 extern int ceph_permission(struct mnt_idmap *idmap,
 			   struct inode *inode, int mask);
@@ -1271,7 +1273,8 @@ extern int ceph_encode_dentry_release(void **p, struct dentry *dn,
 				      struct inode *dir,
 				      int mds, int drop, int unless);
 
-extern int __ceph_get_caps(struct inode *inode, struct ceph_file_info *fi,
+extern int __ceph_get_caps(struct mnt_idmap *idmap, struct inode *inode,
+			   struct ceph_file_info *fi,
 			   int need, int want, loff_t endoff, int *got);
 extern int ceph_get_caps(struct file *filp, int need, int want,
 			 loff_t endoff, int *got);
diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
index 76680e5c2f82..d11295e0a115 100644
--- a/fs/ceph/xattr.c
+++ b/fs/ceph/xattr.c
@@ -978,7 +978,7 @@ ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value,
 			mask |= CEPH_STAT_RSTAT;
 		if (vxattr->flags & VXATTR_FLAG_DIRSTAT)
 			mask |= CEPH_CAP_FILE_SHARED;
-		err = ceph_do_getattr(inode, mask, true);
+		err = ceph_do_getattr(&nop_mnt_idmap, inode, mask, true);
 		if (err)
 			return err;
 		err = -ENODATA;
@@ -1015,7 +1015,7 @@ ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value,
 		}
 
 		/* get xattrs from mds (if we don't already have them) */
-		err = ceph_do_getattr(inode, CEPH_STAT_CAP_XATTR, true);
+		err = ceph_do_getattr(&nop_mnt_idmap, inode, CEPH_STAT_CAP_XATTR, true);
 		if (err)
 			return err;
 		spin_lock(&ci->i_ceph_lock);
@@ -1064,7 +1064,7 @@ ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size)
 	if (ci->i_xattrs.version == 0 ||
 	    !__ceph_caps_issued_mask_metric(ci, CEPH_CAP_XATTR_SHARED, 1)) {
 		spin_unlock(&ci->i_ceph_lock);
-		err = ceph_do_getattr(inode, CEPH_STAT_CAP_XATTR, true);
+		err = ceph_do_getattr(&nop_mnt_idmap, inode, CEPH_STAT_CAP_XATTR, true);
 		if (err)
 			return err;
 		spin_lock(&ci->i_ceph_lock);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v6 12/15] ceph: pass idmap to __ceph_setxattr
  2023-06-09  9:31 [PATCH v6 00/15] ceph: support idmapped mounts Alexander Mikhalitsyn
                   ` (10 preceding siblings ...)
  2023-06-09  9:31 ` [PATCH v6 11/15] ceph: pass idmap to ceph_do_getattr Alexander Mikhalitsyn
@ 2023-06-09  9:31 ` Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 13/15] ceph: pass idmap to ceph_open/ioctl_set_layout/readdir Alexander Mikhalitsyn
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Alexander Mikhalitsyn @ 2023-06-09  9:31 UTC (permalink / raw)
  To: xiubli
  Cc: brauner, stgraber, linux-fsdevel, Alexander Mikhalitsyn,
	Jeff Layton, Ilya Dryomov, ceph-devel, linux-kernel

Just pass down the mount's idmapping to __ceph_setxattr.

Cc: Xiubo Li <xiubli@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: brauner@kernel.org
Cc: ceph-devel@vger.kernel.org
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
---
 fs/ceph/acl.c   |  2 +-
 fs/ceph/super.h |  3 ++-
 fs/ceph/xattr.c | 12 +++++++-----
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/fs/ceph/acl.c b/fs/ceph/acl.c
index d4be4c2d63c3..e34b4e859b82 100644
--- a/fs/ceph/acl.c
+++ b/fs/ceph/acl.c
@@ -145,7 +145,7 @@ int ceph_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
 			goto out_free;
 	}
 
-	ret = __ceph_setxattr(inode, name, value, size, 0);
+	ret = __ceph_setxattr(idmap, inode, name, value, size, 0);
 	if (ret) {
 		if (new_mode != old_mode) {
 			newattrs.ia_ctime = old_ctime;
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index 57cbb69a17c8..05dbae76087c 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -1116,7 +1116,8 @@ static inline bool ceph_inode_is_shutdown(struct inode *inode)
 }
 
 /* xattr.c */
-int __ceph_setxattr(struct inode *, const char *, const void *, size_t, int);
+int __ceph_setxattr(struct mnt_idmap *, struct inode *,
+		    const char *, const void *, size_t, int);
 int ceph_do_getvxattr(struct inode *inode, const char *name, void *value, size_t size);
 ssize_t __ceph_getxattr(struct inode *, const char *, void *, size_t);
 extern ssize_t ceph_listxattr(struct dentry *, char *, size_t);
diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
index d11295e0a115..663267bbee3c 100644
--- a/fs/ceph/xattr.c
+++ b/fs/ceph/xattr.c
@@ -1090,7 +1090,8 @@ ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size)
 	return err;
 }
 
-static int ceph_sync_setxattr(struct inode *inode, const char *name,
+static int ceph_sync_setxattr(struct mnt_idmap *idmap,
+			      struct inode *inode, const char *name,
 			      const char *value, size_t size, int flags)
 {
 	struct ceph_fs_client *fsc = ceph_sb_to_client(inode->i_sb);
@@ -1144,6 +1145,7 @@ static int ceph_sync_setxattr(struct inode *inode, const char *name,
 
 	req->r_inode = inode;
 	ihold(inode);
+	req->r_mnt_idmap = mnt_idmap_get(idmap);
 	req->r_num_caps = 1;
 	req->r_inode_drop = CEPH_CAP_XATTR_SHARED;
 
@@ -1158,8 +1160,8 @@ static int ceph_sync_setxattr(struct inode *inode, const char *name,
 	return err;
 }
 
-int __ceph_setxattr(struct inode *inode, const char *name,
-			const void *value, size_t size, int flags)
+int __ceph_setxattr(struct mnt_idmap *idmap, struct inode *inode,
+		    const char *name, const void *value, size_t size, int flags)
 {
 	struct ceph_vxattr *vxattr;
 	struct ceph_inode_info *ci = ceph_inode(inode);
@@ -1288,7 +1290,7 @@ int __ceph_setxattr(struct inode *inode, const char *name,
 				    "during filling trace\n", inode);
 		err = -EBUSY;
 	} else {
-		err = ceph_sync_setxattr(inode, name, value, size, flags);
+		err = ceph_sync_setxattr(idmap, inode, name, value, size, flags);
 		if (err >= 0 && check_realm) {
 			/* check if snaprealm was created for quota inode */
 			spin_lock(&ci->i_ceph_lock);
@@ -1324,7 +1326,7 @@ static int ceph_set_xattr_handler(const struct xattr_handler *handler,
 {
 	if (!ceph_is_valid_xattr(name))
 		return -EOPNOTSUPP;
-	return __ceph_setxattr(inode, name, value, size, flags);
+	return __ceph_setxattr(idmap, inode, name, value, size, flags);
 }
 
 static const struct xattr_handler ceph_other_xattr_handler = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v6 13/15] ceph: pass idmap to ceph_open/ioctl_set_layout/readdir
  2023-06-09  9:31 [PATCH v6 00/15] ceph: support idmapped mounts Alexander Mikhalitsyn
                   ` (11 preceding siblings ...)
  2023-06-09  9:31 ` [PATCH v6 12/15] ceph: pass idmap to __ceph_setxattr Alexander Mikhalitsyn
@ 2023-06-09  9:31 ` Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 14/15] ceph: pass idmap to ceph_netfs_issue_op_inline Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 15/15] ceph: allow idmapped mounts Alexander Mikhalitsyn
  14 siblings, 0 replies; 16+ messages in thread
From: Alexander Mikhalitsyn @ 2023-06-09  9:31 UTC (permalink / raw)
  To: xiubli
  Cc: brauner, stgraber, linux-fsdevel, Alexander Mikhalitsyn,
	Jeff Layton, Ilya Dryomov, ceph-devel, linux-kernel

Pass an idmapping to:
- ceph_open
- ceph_ioctl_set_layout
- ceph_readdir

Cc: Xiubo Li <xiubli@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: brauner@kernel.org
Cc: ceph-devel@vger.kernel.org
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
---
v6:
	- pass idmap to ceph_readdir
---
 fs/ceph/caps.c  | 2 +-
 fs/ceph/dir.c   | 2 ++
 fs/ceph/file.c  | 9 +++++++--
 fs/ceph/ioctl.c | 3 +++
 fs/ceph/super.h | 2 +-
 5 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index b432f29e80dd..13c231258153 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -3042,7 +3042,7 @@ int __ceph_get_caps(struct mnt_idmap *idmap, struct inode *inode,
 			}
 			if (ret == -EUCLEAN) {
 				/* session was killed, try renew caps */
-				ret = ceph_renew_caps(inode, flags);
+				ret = ceph_renew_caps(idmap, inode, flags);
 				if (ret == 0)
 					continue;
 			}
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index 2c0c2c98085b..26335c025f50 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -308,6 +308,7 @@ static bool need_send_readdir(struct ceph_dir_file_info *dfi, loff_t pos)
 static int ceph_readdir(struct file *file, struct dir_context *ctx)
 {
 	struct ceph_dir_file_info *dfi = file->private_data;
+	struct mnt_idmap *idmap = file_mnt_idmap(file);
 	struct inode *inode = file_inode(file);
 	struct ceph_inode_info *ci = ceph_inode(inode);
 	struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
@@ -440,6 +441,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
 		req->r_inode = inode;
 		ihold(inode);
 		req->r_dentry = dget(file->f_path.dentry);
+		req->r_mnt_idmap = mnt_idmap_get(idmap);
 		err = ceph_mdsc_do_request(mdsc, NULL, req);
 		if (err < 0) {
 			ceph_mdsc_put_request(req);
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index c2bb8f5fd345..9671b0e77faf 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -175,7 +175,8 @@ static void put_bvecs(struct bio_vec *bvecs, int num_bvecs, bool should_dirty)
  * inopportune ENOMEM later.
  */
 static struct ceph_mds_request *
-prepare_open_request(struct super_block *sb, int flags, int create_mode)
+prepare_open_request(struct super_block *sb,
+		     int flags, int create_mode)
 {
 	struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(sb);
 	struct ceph_mds_request *req;
@@ -293,7 +294,7 @@ static int ceph_init_file(struct inode *inode, struct file *file, int fmode)
 /*
  * try renew caps after session gets killed.
  */
-int ceph_renew_caps(struct inode *inode, int fmode)
+int ceph_renew_caps(struct mnt_idmap *idmap, struct inode *inode, int fmode)
 {
 	struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(inode->i_sb);
 	struct ceph_inode_info *ci = ceph_inode(inode);
@@ -336,6 +337,8 @@ int ceph_renew_caps(struct inode *inode, int fmode)
 	ihold(inode);
 	req->r_num_caps = 1;
 
+	req->r_mnt_idmap = mnt_idmap_get(idmap);
+
 	err = ceph_mdsc_do_request(mdsc, NULL, req);
 	ceph_mdsc_put_request(req);
 out:
@@ -356,6 +359,7 @@ int ceph_open(struct inode *inode, struct file *file)
 	struct ceph_mds_client *mdsc = fsc->mdsc;
 	struct ceph_mds_request *req;
 	struct ceph_file_info *fi = file->private_data;
+	struct mnt_idmap *idmap = file_mnt_idmap(file);
 	int err;
 	int flags, fmode, wanted;
 
@@ -431,6 +435,7 @@ int ceph_open(struct inode *inode, struct file *file)
 	ihold(inode);
 
 	req->r_num_caps = 1;
+	req->r_mnt_idmap = mnt_idmap_get(idmap);
 	err = ceph_mdsc_do_request(mdsc, NULL, req);
 	if (!err)
 		err = ceph_init_file(inode, file, req->r_fmode);
diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c
index 6fa021b973e5..69efd446a9e1 100644
--- a/fs/ceph/ioctl.c
+++ b/fs/ceph/ioctl.c
@@ -114,6 +114,7 @@ static long ceph_ioctl_set_layout(struct file *file, void __user *arg)
 	req->r_inode = inode;
 	ihold(inode);
 	req->r_num_caps = 1;
+	req->r_mnt_idmap = mnt_idmap_get(idmap);
 
 	req->r_inode_drop = CEPH_CAP_FILE_SHARED | CEPH_CAP_FILE_EXCL;
 
@@ -139,6 +140,7 @@ static long ceph_ioctl_set_layout(struct file *file, void __user *arg)
 static long ceph_ioctl_set_layout_policy (struct file *file, void __user *arg)
 {
 	struct inode *inode = file_inode(file);
+	struct mnt_idmap *idmap = file_mnt_idmap(file);
 	struct ceph_mds_request *req;
 	struct ceph_ioctl_layout l;
 	int err;
@@ -160,6 +162,7 @@ static long ceph_ioctl_set_layout_policy (struct file *file, void __user *arg)
 	req->r_inode = inode;
 	ihold(inode);
 	req->r_num_caps = 1;
+	req->r_mnt_idmap = mnt_idmap_get(idmap);
 
 	req->r_args.setlayout.layout.fl_stripe_unit =
 			cpu_to_le32(l.stripe_unit);
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index 05dbae76087c..d89e7b99ac5f 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -1308,7 +1308,7 @@ static inline bool ceph_has_inline_data(struct ceph_inode_info *ci)
 /* file.c */
 extern const struct file_operations ceph_file_fops;
 
-extern int ceph_renew_caps(struct inode *inode, int fmode);
+extern int ceph_renew_caps(struct mnt_idmap *idmap, struct inode *inode, int fmode);
 extern int ceph_open(struct inode *inode, struct file *file);
 extern int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
 			    struct file *file, unsigned flags, umode_t mode);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v6 14/15] ceph: pass idmap to ceph_netfs_issue_op_inline
  2023-06-09  9:31 [PATCH v6 00/15] ceph: support idmapped mounts Alexander Mikhalitsyn
                   ` (12 preceding siblings ...)
  2023-06-09  9:31 ` [PATCH v6 13/15] ceph: pass idmap to ceph_open/ioctl_set_layout/readdir Alexander Mikhalitsyn
@ 2023-06-09  9:31 ` Alexander Mikhalitsyn
  2023-06-09  9:31 ` [PATCH v6 15/15] ceph: allow idmapped mounts Alexander Mikhalitsyn
  14 siblings, 0 replies; 16+ messages in thread
From: Alexander Mikhalitsyn @ 2023-06-09  9:31 UTC (permalink / raw)
  To: xiubli
  Cc: brauner, stgraber, linux-fsdevel, Alexander Mikhalitsyn,
	Jeff Layton, Ilya Dryomov, ceph-devel, linux-kernel

Just pass down the mount's idmapping to ceph_netfs_issue_op_inline.

Cc: Xiubo Li <xiubli@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: brauner@kernel.org
Cc: ceph-devel@vger.kernel.org
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
---
 fs/ceph/addr.c  | 12 ++++++++++++
 fs/ceph/super.h |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index 0a32475ed034..2759a0cf2381 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -291,6 +291,8 @@ static bool ceph_netfs_issue_op_inline(struct netfs_io_subrequest *subreq)
 {
 	struct netfs_io_request *rreq = subreq->rreq;
 	struct inode *inode = rreq->inode;
+	struct ceph_netfs_request_data *priv = rreq->netfs_priv;
+	struct mnt_idmap *idmap = priv->mnt_idmap;
 	struct ceph_mds_reply_info_parsed *rinfo;
 	struct ceph_mds_reply_info_in *iinfo;
 	struct ceph_mds_request *req;
@@ -318,6 +320,8 @@ static bool ceph_netfs_issue_op_inline(struct netfs_io_subrequest *subreq)
 	req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INLINE_DATA);
 	req->r_num_caps = 2;
 
+	req->r_mnt_idmap = mnt_idmap_get(idmap);
+
 	err = ceph_mdsc_do_request(mdsc, NULL, req);
 	if (err < 0)
 		goto out;
@@ -443,13 +447,18 @@ static int ceph_init_request(struct netfs_io_request *rreq, struct file *file)
 	if (!priv)
 		return -ENOMEM;
 
+	priv->mnt_idmap = &nop_mnt_idmap;
+
 	if (file) {
 		struct ceph_rw_context *rw_ctx;
 		struct ceph_file_info *fi = file->private_data;
+		struct mnt_idmap *idmap = file_mnt_idmap(file);
 
 		priv->file_ra_pages = file->f_ra.ra_pages;
 		priv->file_ra_disabled = file->f_mode & FMODE_RANDOM;
 
+		priv->mnt_idmap = mnt_idmap_get(idmap);
+
 		rw_ctx = ceph_find_rw_context(fi);
 		if (rw_ctx) {
 			rreq->netfs_priv = priv;
@@ -496,6 +505,9 @@ static void ceph_netfs_free_request(struct netfs_io_request *rreq)
 
 	if (priv->caps)
 		ceph_put_cap_refs(ceph_inode(rreq->inode), priv->caps);
+
+	mnt_idmap_put(priv->mnt_idmap);
+
 	kfree(priv);
 	rreq->netfs_priv = NULL;
 }
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index d89e7b99ac5f..0badf58fb5fc 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -481,6 +481,8 @@ struct ceph_netfs_request_data {
 
 	/* Set it if fadvise disables file readahead entirely */
 	bool file_ra_disabled;
+
+	struct mnt_idmap *mnt_idmap;
 };
 
 static inline struct ceph_inode_info *
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v6 15/15] ceph: allow idmapped mounts
  2023-06-09  9:31 [PATCH v6 00/15] ceph: support idmapped mounts Alexander Mikhalitsyn
                   ` (13 preceding siblings ...)
  2023-06-09  9:31 ` [PATCH v6 14/15] ceph: pass idmap to ceph_netfs_issue_op_inline Alexander Mikhalitsyn
@ 2023-06-09  9:31 ` Alexander Mikhalitsyn
  14 siblings, 0 replies; 16+ messages in thread
From: Alexander Mikhalitsyn @ 2023-06-09  9:31 UTC (permalink / raw)
  To: xiubli
  Cc: brauner, stgraber, linux-fsdevel, Christian Brauner, Jeff Layton,
	Ilya Dryomov, ceph-devel, Alexander Mikhalitsyn, linux-kernel

From: Christian Brauner <christian.brauner@ubuntu.com>

Now that we converted cephfs internally to account for idmapped mounts
allow the creation of idmapped mounts on by setting the FS_ALLOW_IDMAP
flag.

Cc: Xiubo Li <xiubli@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: ceph-devel@vger.kernel.org
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
---
 fs/ceph/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index 3d6d0010d638..aabc8ac90ead 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -1581,7 +1581,7 @@ static struct file_system_type ceph_fs_type = {
 	.name		= "ceph",
 	.init_fs_context = ceph_init_fs_context,
 	.kill_sb	= ceph_kill_sb,
-	.fs_flags	= FS_RENAME_DOES_D_MOVE,
+	.fs_flags	= FS_RENAME_DOES_D_MOVE | FS_ALLOW_IDMAP,
 };
 MODULE_ALIAS_FS("ceph");
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-06-09 10:12 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-09  9:31 [PATCH v6 00/15] ceph: support idmapped mounts Alexander Mikhalitsyn
2023-06-09  9:31 ` [PATCH v6 01/15] fs: export mnt_idmap_get/mnt_idmap_put Alexander Mikhalitsyn
2023-06-09  9:31 ` [PATCH v6 02/15] ceph: stash idmapping in mdsc request Alexander Mikhalitsyn
2023-06-09  9:31 ` [PATCH v6 03/15] ceph: handle idmapped mounts in create_request_message() Alexander Mikhalitsyn
2023-06-09  9:31 ` [PATCH v6 04/15] ceph: pass an idmapping to mknod/symlink/mkdir/rename Alexander Mikhalitsyn
2023-06-09  9:31 ` [PATCH v6 05/15] ceph: allow idmapped getattr inode op Alexander Mikhalitsyn
2023-06-09  9:31 ` [PATCH v6 06/15] ceph: allow idmapped permission " Alexander Mikhalitsyn
2023-06-09  9:31 ` [PATCH v6 07/15] ceph: pass idmap to __ceph_setattr Alexander Mikhalitsyn
2023-06-09  9:31 ` [PATCH v6 08/15] ceph: allow idmapped setattr inode op Alexander Mikhalitsyn
2023-06-09  9:31 ` [PATCH v6 09/15] ceph/acl: allow idmapped set_acl " Alexander Mikhalitsyn
2023-06-09  9:31 ` [PATCH v6 10/15] ceph/file: allow idmapped atomic_open " Alexander Mikhalitsyn
2023-06-09  9:31 ` [PATCH v6 11/15] ceph: pass idmap to ceph_do_getattr Alexander Mikhalitsyn
2023-06-09  9:31 ` [PATCH v6 12/15] ceph: pass idmap to __ceph_setxattr Alexander Mikhalitsyn
2023-06-09  9:31 ` [PATCH v6 13/15] ceph: pass idmap to ceph_open/ioctl_set_layout/readdir Alexander Mikhalitsyn
2023-06-09  9:31 ` [PATCH v6 14/15] ceph: pass idmap to ceph_netfs_issue_op_inline Alexander Mikhalitsyn
2023-06-09  9:31 ` [PATCH v6 15/15] ceph: allow idmapped mounts Alexander Mikhalitsyn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).