Commit 67c0496e authored by Tejun Heo's avatar Tejun Heo
Browse files

kernfs: convert kernfs_node->id from union kernfs_node_id to u64



kernfs_node->id is currently a union kernfs_node_id which represents
either a 32bit (ino, gen) pair or u64 value.  I can't see much value
in the usage of the union - all that's needed is a 64bit ID which the
current code is already limited to.  Using a union makes the code
unnecessarily complicated and prevents using 64bit ino without adding
practical benefits.

This patch drops union kernfs_node_id and makes kernfs_node->id a u64.
ino is stored in the lower 32bits and gen upper.  Accessors -
kernfs[_id]_ino() and kernfs[_id]_gen() - are added to retrieve the
ino and gen.  This simplifies ID handling less cumbersome and will
allow using 64bit inos on supported archs.

This patch doesn't make any functional changes.

Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Alexei Starovoitov <ast@kernel.org>
parent 880df131
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -532,7 +532,7 @@ void kernfs_put(struct kernfs_node *kn)
		kmem_cache_free(kernfs_iattrs_cache, kn->iattr);
	}
	spin_lock(&kernfs_idr_lock);
	idr_remove(&root->ino_idr, kn->id.ino);
	idr_remove(&root->ino_idr, kernfs_ino(kn));
	spin_unlock(&kernfs_idr_lock);
	kmem_cache_free(kernfs_node_cache, kn);

@@ -639,8 +639,8 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
	idr_preload_end();
	if (ret < 0)
		goto err_out2;
	kn->id.ino = ret;
	kn->id.generation = gen;

	kn->id = (u64)gen << 32 | ret;

	atomic_set(&kn->count, 1);
	atomic_set(&kn->active, KN_DEACTIVATED_BIAS);
@@ -671,7 +671,7 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
	return kn;

 err_out3:
	idr_remove(&root->ino_idr, kn->id.ino);
	idr_remove(&root->ino_idr, kernfs_ino(kn));
 err_out2:
	kmem_cache_free(kernfs_node_cache, kn);
 err_out1:
@@ -1656,7 +1656,7 @@ static int kernfs_fop_readdir(struct file *file, struct dir_context *ctx)
		const char *name = pos->name;
		unsigned int type = dt_type(pos);
		int len = strlen(name);
		ino_t ino = pos->id.ino;
		ino_t ino = kernfs_ino(pos);

		ctx->pos = pos->hash;
		file->private_data = pos;
+2 −2
Original line number Diff line number Diff line
@@ -892,7 +892,7 @@ repeat:
		 * have the matching @file available.  Look up the inodes
		 * and generate the events manually.
		 */
		inode = ilookup(info->sb, kn->id.ino);
		inode = ilookup(info->sb, kernfs_ino(kn));
		if (!inode)
			continue;

@@ -901,7 +901,7 @@ repeat:
		if (parent) {
			struct inode *p_inode;

			p_inode = ilookup(info->sb, parent->id.ino);
			p_inode = ilookup(info->sb, kernfs_ino(parent));
			if (p_inode) {
				fsnotify(p_inode, FS_MODIFY | FS_EVENT_ON_CHILD,
					 inode, FSNOTIFY_EVENT_INODE, &name, 0);
+2 −2
Original line number Diff line number Diff line
@@ -201,7 +201,7 @@ static void kernfs_init_inode(struct kernfs_node *kn, struct inode *inode)
	inode->i_private = kn;
	inode->i_mapping->a_ops = &kernfs_aops;
	inode->i_op = &kernfs_iops;
	inode->i_generation = kn->id.generation;
	inode->i_generation = kernfs_gen(kn);

	set_default_inode_attr(inode, kn->mode);
	kernfs_refresh_inode(kn, inode);
@@ -247,7 +247,7 @@ struct inode *kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn)
{
	struct inode *inode;

	inode = iget_locked(sb, kn->id.ino);
	inode = iget_locked(sb, kernfs_ino(kn));
	if (inode && (inode->i_state & I_NEW))
		kernfs_init_inode(kn, inode);

+3 −4
Original line number Diff line number Diff line
@@ -57,15 +57,14 @@ const struct super_operations kernfs_sops = {
 * Similar to kernfs_fh_get_inode, this one gets kernfs node from inode
 * number and generation
 */
struct kernfs_node *kernfs_get_node_by_id(struct kernfs_root *root,
	const union kernfs_node_id *id)
struct kernfs_node *kernfs_get_node_by_id(struct kernfs_root *root, u64 id)
{
	struct kernfs_node *kn;

	kn = kernfs_find_and_get_node_by_ino(root, id->ino);
	kn = kernfs_find_and_get_node_by_ino(root, kernfs_id_ino(id));
	if (!kn)
		return NULL;
	if (kn->id.generation != id->generation) {
	if (kernfs_gen(kn) != kernfs_id_gen(id)) {
		kernfs_put(kn);
		return NULL;
	}
+8 −9
Original line number Diff line number Diff line
@@ -616,7 +616,7 @@ static inline bool cgroup_is_populated(struct cgroup *cgrp)
/* returns ino associated with a cgroup */
static inline ino_t cgroup_ino(struct cgroup *cgrp)
{
	return cgrp->kn->id.ino;
	return kernfs_ino(cgrp->kn);
}

/* cft/css accessors for cftype->write() operation */
@@ -687,13 +687,12 @@ static inline void cgroup_kthread_ready(void)
	current->no_cgroup_migration = 0;
}

static inline union kernfs_node_id *cgroup_get_kernfs_id(struct cgroup *cgrp)
static inline u64 cgroup_get_kernfs_id(struct cgroup *cgrp)
{
	return &cgrp->kn->id;
	return cgrp->kn->id;
}

void cgroup_path_from_kernfs_id(const union kernfs_node_id *id,
					char *buf, size_t buflen);
void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen);
#else /* !CONFIG_CGROUPS */

struct cgroup_subsys_state;
@@ -718,9 +717,9 @@ static inline int cgroup_init_early(void) { return 0; }
static inline int cgroup_init(void) { return 0; }
static inline void cgroup_init_kthreadd(void) {}
static inline void cgroup_kthread_ready(void) {}
static inline union kernfs_node_id *cgroup_get_kernfs_id(struct cgroup *cgrp)
static inline union u64 cgroup_get_kernfs_id(struct cgroup *cgrp)
{
	return NULL;
	return 0;
}

static inline struct cgroup *cgroup_parent(struct cgroup *cgrp)
@@ -739,8 +738,8 @@ static inline bool task_under_cgroup_hierarchy(struct task_struct *task,
	return true;
}

static inline void cgroup_path_from_kernfs_id(const union kernfs_node_id *id,
	char *buf, size_t buflen) {}
static inline void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen)
{}
#endif /* !CONFIG_CGROUPS */

#ifdef CONFIG_CGROUPS
Loading