fs/nfsd/nfs4idmap.c

Source file repositories/reference/linux-study-clean/fs/nfsd/nfs4idmap.c

File Facts

System
Linux kernel
Corpus path
fs/nfsd/nfs4idmap.c
Extension
.c
Size
18390 bytes
Lines
733
Domain
Core OS
Bucket
VFS And Filesystem Core
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

struct ent {
	struct cache_head h;
	int               type;		       /* User / Group */
	u32               id;
	char              name[IDMAP_NAMESZ];
	char              authname[IDMAP_NAMESZ];
	struct rcu_head	  rcu_head;
};

/* Common entry handling */

#define ENT_HASHBITS          8
#define ENT_HASHMAX           (1 << ENT_HASHBITS)

static void
ent_init(struct cache_head *cnew, struct cache_head *citm)
{
	struct ent *new = container_of(cnew, struct ent, h);
	struct ent *itm = container_of(citm, struct ent, h);

	new->id = itm->id;
	new->type = itm->type;

	strscpy(new->name, itm->name, sizeof(new->name));
	strscpy(new->authname, itm->authname, sizeof(new->authname));
}

static void
ent_put(struct kref *ref)
{
	struct ent *map = container_of(ref, struct ent, h.ref);
	kfree_rcu(map, rcu_head);
}

static struct cache_head *
ent_alloc(void)
{
	struct ent *e = kmalloc_obj(*e);
	if (e)
		return &e->h;
	else
		return NULL;
}

/*
 * ID -> Name cache
 */

static uint32_t
idtoname_hash(struct ent *ent)
{
	uint32_t hash;

	hash = hash_str(ent->authname, ENT_HASHBITS);
	hash = hash_long(hash ^ ent->id, ENT_HASHBITS);

	/* Flip LSB for user/group */
	if (ent->type == IDMAP_TYPE_GROUP)
		hash ^= 1;

	return hash;
}

static int
idtoname_upcall(struct cache_detail *cd, struct cache_head *h)
{
	return sunrpc_cache_upcall_warn(cd, h);
}

static void
idtoname_request(struct cache_detail *cd, struct cache_head *ch, char **bpp,
    int *blen)
{
 	struct ent *ent = container_of(ch, struct ent, h);
	char idstr[11];

	qword_add(bpp, blen, ent->authname);
	snprintf(idstr, sizeof(idstr), "%u", ent->id);
	qword_add(bpp, blen, ent->type == IDMAP_TYPE_GROUP ? "group" : "user");
	qword_add(bpp, blen, idstr);

	(*bpp)[-1] = '\n';
}

static int
idtoname_match(struct cache_head *ca, struct cache_head *cb)
{
	struct ent *a = container_of(ca, struct ent, h);
	struct ent *b = container_of(cb, struct ent, h);

Annotation

Implementation Notes