fs/nfs/nfs4idmap.c
Source file repositories/reference/linux-study-clean/fs/nfs/nfs4idmap.c
File Facts
- System
- Linux kernel
- Corpus path
fs/nfs/nfs4idmap.c- Extension
.c- Size
- 20215 bytes
- Lines
- 794
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/parser.hlinux/fs.hnet/net_namespace.hlinux/sunrpc/rpc_pipe_fs.hlinux/nfs_fs.hlinux/nfs_fs_sb.hlinux/key.hlinux/keyctl.hlinux/key-type.hkeys/user-type.hkeys/request_key_auth-type.hlinux/module.hlinux/user_namespace.hinternal.hnetns.hnfs4idmap.hnfs4trace.h
Detected Declarations
struct idmap_legacy_upcalldatastruct idmapfunction nfs_fattr_init_namesfunction nfs_fattr_free_owner_namefunction nfs_fattr_free_group_namefunction nfs_fattr_map_owner_namefunction nfs_fattr_map_group_namefunction nfs_fattr_free_namesfunction nfs_fattr_map_and_free_namesfunction nfs_map_string_to_numericfunction nfs_map_numeric_to_stringfunction nfs_idmap_initfunction nfs_idmap_quitfunction request_keyfunction nfs_idmap_get_keyfunction nfs_idmap_lookup_namefunction nfs_idmap_lookup_idfunction nfs_idmap_pipe_destroyfunction nfs_idmap_pipe_createfunction nfs_idmap_newfunction nfs_idmap_deletefunction nfs_idmap_prepare_messagefunction nfs_idmap_prepare_pipe_upcallfunction nfs_idmap_complete_pipe_upcallfunction nfs_idmap_abort_pipe_upcallfunction nfs_idmap_legacy_upcallfunction nfs_idmap_instantiatefunction nfs_idmap_read_and_verify_messagefunction idmap_pipe_downcallfunction idmap_pipe_destroy_msgfunction idmap_release_pipefunction nfs_map_name_to_uidfunction nfs_map_group_to_gidfunction nfs_map_uid_to_namefunction nfs_map_gid_to_groupexport nfs_map_string_to_numeric
Annotated Snippet
struct idmap_legacy_upcalldata {
struct rpc_pipe_msg pipe_msg;
struct idmap_msg idmap_msg;
struct key *authkey;
struct idmap *idmap;
};
struct idmap {
struct rpc_pipe_dir_object idmap_pdo;
struct rpc_pipe *idmap_pipe;
struct idmap_legacy_upcalldata *idmap_upcall_data;
struct mutex idmap_mutex;
struct user_namespace *user_ns;
};
static struct user_namespace *idmap_userns(const struct idmap *idmap)
{
if (idmap && idmap->user_ns)
return idmap->user_ns;
return &init_user_ns;
}
/**
* nfs_fattr_init_names - initialise the nfs_fattr owner_name/group_name fields
* @fattr: fully initialised struct nfs_fattr
* @owner_name: owner name string cache
* @group_name: group name string cache
*/
void nfs_fattr_init_names(struct nfs_fattr *fattr,
struct nfs4_string *owner_name,
struct nfs4_string *group_name)
{
fattr->owner_name = owner_name;
fattr->group_name = group_name;
}
static void nfs_fattr_free_owner_name(struct nfs_fattr *fattr)
{
fattr->valid &= ~NFS_ATTR_FATTR_OWNER_NAME;
kfree(fattr->owner_name->data);
}
static void nfs_fattr_free_group_name(struct nfs_fattr *fattr)
{
fattr->valid &= ~NFS_ATTR_FATTR_GROUP_NAME;
kfree(fattr->group_name->data);
}
static bool nfs_fattr_map_owner_name(struct nfs_server *server, struct nfs_fattr *fattr)
{
struct nfs4_string *owner = fattr->owner_name;
kuid_t uid;
if (!(fattr->valid & NFS_ATTR_FATTR_OWNER_NAME))
return false;
if (nfs_map_name_to_uid(server, owner->data, owner->len, &uid) == 0) {
fattr->uid = uid;
fattr->valid |= NFS_ATTR_FATTR_OWNER;
}
return true;
}
static bool nfs_fattr_map_group_name(struct nfs_server *server, struct nfs_fattr *fattr)
{
struct nfs4_string *group = fattr->group_name;
kgid_t gid;
if (!(fattr->valid & NFS_ATTR_FATTR_GROUP_NAME))
return false;
if (nfs_map_group_to_gid(server, group->data, group->len, &gid) == 0) {
fattr->gid = gid;
fattr->valid |= NFS_ATTR_FATTR_GROUP;
}
return true;
}
/**
* nfs_fattr_free_names - free up the NFSv4 owner and group strings
* @fattr: a fully initialised nfs_fattr structure
*/
void nfs_fattr_free_names(struct nfs_fattr *fattr)
{
if (fattr->valid & NFS_ATTR_FATTR_OWNER_NAME)
nfs_fattr_free_owner_name(fattr);
if (fattr->valid & NFS_ATTR_FATTR_GROUP_NAME)
nfs_fattr_free_group_name(fattr);
}
/**
* nfs_fattr_map_and_free_names - map owner/group strings into uid/gid and free
Annotation
- Immediate include surface: `linux/types.h`, `linux/parser.h`, `linux/fs.h`, `net/net_namespace.h`, `linux/sunrpc/rpc_pipe_fs.h`, `linux/nfs_fs.h`, `linux/nfs_fs_sb.h`, `linux/key.h`.
- Detected declarations: `struct idmap_legacy_upcalldata`, `struct idmap`, `function nfs_fattr_init_names`, `function nfs_fattr_free_owner_name`, `function nfs_fattr_free_group_name`, `function nfs_fattr_map_owner_name`, `function nfs_fattr_map_group_name`, `function nfs_fattr_free_names`, `function nfs_fattr_map_and_free_names`, `function nfs_map_string_to_numeric`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.