Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61ca2c4

Browse files
sargunamschuma-ntap
authored andcommitted
NFS: Only reference user namespace from nfs4idmap struct instead of cred
The nfs4idmapper only needs access to the user namespace, and not the entire cred struct. This replaces the struct cred* member with struct user_namespace*. This is mostly hygiene, so we don't have to hold onto the cred object, which has extraneous references to things like user_struct. This also makes switching away from init_user_ns more straightforward in the future. Signed-off-by: Sargun Dhillon <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent a2d24bc commit 61ca2c4

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

fs/nfs/nfs4idmap.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <keys/user-type.h>
4747
#include <keys/request_key_auth-type.h>
4848
#include <linux/module.h>
49+
#include <linux/user_namespace.h>
4950

5051
#include "internal.h"
5152
#include "netns.h"
@@ -69,13 +70,13 @@ struct idmap {
6970
struct rpc_pipe *idmap_pipe;
7071
struct idmap_legacy_upcalldata *idmap_upcall_data;
7172
struct mutex idmap_mutex;
72-
const struct cred *cred;
73+
struct user_namespace *user_ns;
7374
};
7475

7576
static struct user_namespace *idmap_userns(const struct idmap *idmap)
7677
{
77-
if (idmap && idmap->cred)
78-
return idmap->cred->user_ns;
78+
if (idmap && idmap->user_ns)
79+
return idmap->user_ns;
7980
return &init_user_ns;
8081
}
8182

@@ -286,7 +287,7 @@ static struct key *nfs_idmap_request_key(const char *name, size_t namelen,
286287
if (ret < 0)
287288
return ERR_PTR(ret);
288289

289-
if (!idmap->cred || idmap->cred->user_ns == &init_user_ns)
290+
if (!idmap->user_ns || idmap->user_ns == &init_user_ns)
290291
rkey = request_key(&key_type_id_resolver, desc, "");
291292
if (IS_ERR(rkey)) {
292293
mutex_lock(&idmap->idmap_mutex);
@@ -462,7 +463,7 @@ nfs_idmap_new(struct nfs_client *clp)
462463
return -ENOMEM;
463464

464465
mutex_init(&idmap->idmap_mutex);
465-
idmap->cred = get_cred(clp->cl_rpcclient->cl_cred);
466+
idmap->user_ns = get_user_ns(clp->cl_rpcclient->cl_cred->user_ns);
466467

467468
rpc_init_pipe_dir_object(&idmap->idmap_pdo,
468469
&nfs_idmap_pipe_dir_object_ops,
@@ -486,7 +487,7 @@ nfs_idmap_new(struct nfs_client *clp)
486487
err_destroy_pipe:
487488
rpc_destroy_pipe_data(idmap->idmap_pipe);
488489
err:
489-
put_cred(idmap->cred);
490+
get_user_ns(idmap->user_ns);
490491
kfree(idmap);
491492
return error;
492493
}
@@ -503,7 +504,7 @@ nfs_idmap_delete(struct nfs_client *clp)
503504
&clp->cl_rpcclient->cl_pipedir_objects,
504505
&idmap->idmap_pdo);
505506
rpc_destroy_pipe_data(idmap->idmap_pipe);
506-
put_cred(idmap->cred);
507+
put_user_ns(idmap->user_ns);
507508
kfree(idmap);
508509
}
509510

0 commit comments

Comments
 (0)