.d_release = kernfs_dop_release,
};
-struct kernfs_node *kernfs_new_node(struct kernfs_root *root, const char *name,
- umode_t mode, unsigned flags)
+static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
+ const char *name, umode_t mode,
+ unsigned flags)
{
char *dup_name = NULL;
struct kernfs_node *kn;
return NULL;
}
+struct kernfs_node *kernfs_new_node(struct kernfs_node *parent,
+ const char *name, umode_t mode,
+ unsigned flags)
+{
+ struct kernfs_node *kn;
+
+ kn = __kernfs_new_node(kernfs_root(parent), name, mode, flags);
+ if (kn) {
+ kernfs_get(parent);
+ kn->parent = parent;
+ }
+ return kn;
+}
+
/**
* kernfs_addrm_start - prepare for kernfs_node add/remove
* @acxt: pointer to kernfs_addrm_cxt to be used
* kernfs_add_one - add kernfs_node to parent without warning
* @acxt: addrm context to use
* @kn: kernfs_node to be added
- * @parent: the parent kernfs_node to add @kn to
*
- * Get @parent and set @kn->parent to it and increment nlink of the
- * parent inode if @kn is a directory and link into the children list
- * of the parent.
+ * The caller must already have initialized @kn->parent. This
+ * function increments nlink of the parent's inode if @kn is a
+ * directory and link into the children list of the parent.
*
* This function should be called between calls to
* kernfs_addrm_start() and kernfs_addrm_finish() and should be passed
* 0 on success, -EEXIST if entry with the given name already
* exists.
*/
-int kernfs_add_one(struct kernfs_addrm_cxt *acxt, struct kernfs_node *kn,
- struct kernfs_node *parent)
+int kernfs_add_one(struct kernfs_addrm_cxt *acxt, struct kernfs_node *kn)
{
+ struct kernfs_node *parent = kn->parent;
bool has_ns = kernfs_ns_enabled(parent);
struct kernfs_iattrs *ps_iattr;
int ret;
return -ENOENT;
kn->hash = kernfs_name_hash(kn->name, kn->ns);
- kn->parent = parent;
- kernfs_get(parent);
ret = kernfs_link_sibling(kn);
if (ret)
ida_init(&root->ino_ida);
- kn = kernfs_new_node(root, "", S_IFDIR | S_IRUGO | S_IXUGO, KERNFS_DIR);
+ kn = __kernfs_new_node(root, "", S_IFDIR | S_IRUGO | S_IXUGO,
+ KERNFS_DIR);
if (!kn) {
ida_destroy(&root->ino_ida);
kfree(root);
int rc;
/* allocate */
- kn = kernfs_new_node(kernfs_root(parent), name, mode | S_IFDIR,
- KERNFS_DIR);
+ kn = kernfs_new_node(parent, name, mode | S_IFDIR, KERNFS_DIR);
if (!kn)
return ERR_PTR(-ENOMEM);
/* link in */
kernfs_addrm_start(&acxt);
- rc = kernfs_add_one(&acxt, kn, parent);
+ rc = kernfs_add_one(&acxt, kn);
kernfs_addrm_finish(&acxt);
if (!rc)
if (name_is_static)
flags |= KERNFS_STATIC_NAME;
- kn = kernfs_new_node(kernfs_root(parent), name,
- (mode & S_IALLUGO) | S_IFREG, flags);
+ kn = kernfs_new_node(parent, name, (mode & S_IALLUGO) | S_IFREG, flags);
if (!kn)
return ERR_PTR(-ENOMEM);
kn->flags |= KERNFS_HAS_MMAP;
kernfs_addrm_start(&acxt);
- rc = kernfs_add_one(&acxt, kn, parent);
+ rc = kernfs_add_one(&acxt, kn);
kernfs_addrm_finish(&acxt);
if (rc) {
struct kernfs_node *kernfs_get_active(struct kernfs_node *kn);
void kernfs_put_active(struct kernfs_node *kn);
void kernfs_addrm_start(struct kernfs_addrm_cxt *acxt);
-int kernfs_add_one(struct kernfs_addrm_cxt *acxt, struct kernfs_node *kn,
- struct kernfs_node *parent);
+int kernfs_add_one(struct kernfs_addrm_cxt *acxt, struct kernfs_node *kn);
void kernfs_addrm_finish(struct kernfs_addrm_cxt *acxt);
-struct kernfs_node *kernfs_new_node(struct kernfs_root *root, const char *name,
- umode_t mode, unsigned flags);
+struct kernfs_node *kernfs_new_node(struct kernfs_node *parent,
+ const char *name, umode_t mode,
+ unsigned flags);
/*
* file.c
struct kernfs_addrm_cxt acxt;
int error;
- kn = kernfs_new_node(kernfs_root(parent), name, S_IFLNK|S_IRWXUGO,
- KERNFS_LINK);
+ kn = kernfs_new_node(parent, name, S_IFLNK|S_IRWXUGO, KERNFS_LINK);
if (!kn)
return ERR_PTR(-ENOMEM);
kernfs_get(target); /* ref owned by symlink */
kernfs_addrm_start(&acxt);
- error = kernfs_add_one(&acxt, kn, parent);
+ error = kernfs_add_one(&acxt, kn);
kernfs_addrm_finish(&acxt);
if (!error)