mm/shmem_quota.c

Source file repositories/reference/linux-study-clean/mm/shmem_quota.c

File Facts

System
Linux kernel
Corpus path
mm/shmem_quota.c
Extension
.c
Size
9619 bytes
Lines
352
Domain
Core OS
Bucket
Memory Management
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 quota_id {
	struct rb_node	node;
	qid_t		id;
	qsize_t		bhardlimit;
	qsize_t		bsoftlimit;
	qsize_t		ihardlimit;
	qsize_t		isoftlimit;
};

static int shmem_check_quota_file(struct super_block *sb, int type)
{
	/* There is no real quota file, nothing to do */
	return 1;
}

/*
 * There is no real quota file. Just allocate rb_root for quota ids and
 * set limits
 */
static int shmem_read_file_info(struct super_block *sb, int type)
{
	struct quota_info *dqopt = sb_dqopt(sb);
	struct mem_dqinfo *info = &dqopt->info[type];

	info->dqi_priv = kzalloc_obj(struct rb_root, GFP_NOFS);
	if (!info->dqi_priv)
		return -ENOMEM;

	info->dqi_max_spc_limit = SHMEM_QUOTA_MAX_SPC_LIMIT;
	info->dqi_max_ino_limit = SHMEM_QUOTA_MAX_INO_LIMIT;

	info->dqi_bgrace = SHMEM_MAX_DQ_TIME;
	info->dqi_igrace = SHMEM_MAX_IQ_TIME;
	info->dqi_flags = 0;

	return 0;
}

static int shmem_write_file_info(struct super_block *sb, int type)
{
	/* There is no real quota file, nothing to do */
	return 0;
}

/*
 * Free all the quota_id entries in the rb tree and rb_root.
 */
static int shmem_free_file_info(struct super_block *sb, int type)
{
	struct mem_dqinfo *info = &sb_dqopt(sb)->info[type];
	struct rb_root *root = info->dqi_priv;
	struct quota_id *entry;
	struct rb_node *node;

	info->dqi_priv = NULL;
	node = rb_first(root);
	while (node) {
		entry = rb_entry(node, struct quota_id, node);
		node = rb_next(&entry->node);

		rb_erase(&entry->node, root);
		kfree(entry);
	}

	kfree(root);
	return 0;
}

static int shmem_get_next_id(struct super_block *sb, struct kqid *qid)
{
	struct mem_dqinfo *info = sb_dqinfo(sb, qid->type);
	struct rb_node *node;
	qid_t id = from_kqid(&init_user_ns, *qid);
	struct quota_info *dqopt = sb_dqopt(sb);
	struct quota_id *entry = NULL;
	int ret = 0;

	if (!sb_has_quota_active(sb, qid->type))
		return -ESRCH;

	down_read(&dqopt->dqio_sem);
	node = ((struct rb_root *)info->dqi_priv)->rb_node;
	while (node) {
		entry = rb_entry(node, struct quota_id, node);

		if (id < entry->id)
			node = node->rb_left;
		else if (id > entry->id)
			node = node->rb_right;
		else

Annotation

Implementation Notes