From 296f6db80331f7709faad753cdb6dea98b1700d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20A=2E=20Fern=C3=A1ndez?= Date: Sat, 7 Sep 2019 17:36:21 -0300 Subject: [PATCH] apfs: use a wrapper for the name of an orphan link MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move the code that names the fake link of an orphan inode from apfs_create_orphan_link() to a new helper, apfs_orphan_name(). The intention is to reuse the code when evicting the inode. Signed-off-by: Ernesto A. Fernández --- fs/apfs/dir.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/fs/apfs/dir.c b/fs/apfs/dir.c index dbe84e6d2f17..7ff7ad1c6fdb 100644 --- a/fs/apfs/dir.c +++ b/fs/apfs/dir.c @@ -909,6 +909,29 @@ fail: return err; } +/** + * apfs_orphan_name - Get the name for an orphan inode's invisible link + * @inode: the vfs inode + * @qname: on return, the name assigned to the link + * + * Returns 0 on success; the caller must remember to free @qname->name after + * use. Returns a negative error code in case of failure. + */ +static int apfs_orphan_name(struct inode *inode, struct qstr *qname) +{ + int max_len; + char *name; + + /* The name is the inode number in hex, with 'linux' prefix */ + max_len = 5 + 16 + 1; + name = kmalloc(max_len, GFP_KERNEL); + if (!name) + return -ENOMEM; + qname->len = snprintf(name, max_len, "linux%llx", apfs_ino(inode)); + qname->name = name; + return 0; +} + /** * apfs_create_orphan_link - Create a link for an orphan inode under private-dir * @inode: the vfs inode @@ -932,17 +955,11 @@ static int apfs_create_orphan_link(struct inode *inode, char **name, struct apfs_inode_val *inode_val; char *node_raw; struct qstr qname; - int max_namelen; int err; - /* The name is the inode number in hex, with 'linux' prefix */ - max_namelen = 5 + 16 + 1; - qname.name = kmalloc(max_namelen, GFP_KERNEL); - if (!qname.name) - return -ENOMEM; - qname.len = snprintf((char *)qname.name, max_namelen, - "linux%llx", apfs_ino(inode)); - + err = apfs_orphan_name(inode, &qname); + if (err) + return err; err = apfs_create_dentry_rec(inode, &qname, APFS_PRIV_DIR_INO_NUM, 0 /* sibling_id */); if (err)