ceph: use ceph_mdsc_build_path instead of clone_dentry_name

While it may be slightly more efficient, it's probably not worthwhile to
optimize for the case that clone_dentry_name handles. We can get the
same result by just calling ceph_mdsc_build_path when the parent isn't
locked, with less code duplication.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: "Yan, Zheng" <zyan@redhat.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
This commit is contained in:
Jeff Layton 2019-04-29 11:51:02 -04:00 коммит произвёл Ilya Dryomov
Родитель 69a10fb3f4
Коммит 964fff7491
1 изменённых файлов: 3 добавлений и 39 удалений

Просмотреть файл

@ -2172,56 +2172,20 @@ retry:
return path; return path;
} }
/* Duplicate the dentry->d_name.name safely */
static int clone_dentry_name(struct dentry *dentry, const char **ppath,
int *ppathlen)
{
u32 len;
char *name;
retry:
len = READ_ONCE(dentry->d_name.len);
name = kmalloc(len + 1, GFP_NOFS);
if (!name)
return -ENOMEM;
spin_lock(&dentry->d_lock);
if (dentry->d_name.len != len) {
spin_unlock(&dentry->d_lock);
kfree(name);
goto retry;
}
memcpy(name, dentry->d_name.name, len);
spin_unlock(&dentry->d_lock);
name[len] = '\0';
*ppath = name;
*ppathlen = len;
return 0;
}
static int build_dentry_path(struct dentry *dentry, struct inode *dir, static int build_dentry_path(struct dentry *dentry, struct inode *dir,
const char **ppath, int *ppathlen, u64 *pino, const char **ppath, int *ppathlen, u64 *pino,
bool *pfreepath, bool parent_locked) bool *pfreepath, bool parent_locked)
{ {
int ret;
char *path; char *path;
rcu_read_lock(); rcu_read_lock();
if (!dir) if (!dir)
dir = d_inode_rcu(dentry->d_parent); dir = d_inode_rcu(dentry->d_parent);
if (dir && ceph_snap(dir) == CEPH_NOSNAP) { if (dir && parent_locked && ceph_snap(dir) == CEPH_NOSNAP) {
*pino = ceph_ino(dir); *pino = ceph_ino(dir);
rcu_read_unlock(); rcu_read_unlock();
if (parent_locked) {
*ppath = dentry->d_name.name; *ppath = dentry->d_name.name;
*ppathlen = dentry->d_name.len; *ppathlen = dentry->d_name.len;
} else {
ret = clone_dentry_name(dentry, ppath, ppathlen);
if (ret)
return ret;
*pfreepath = true;
}
return 0; return 0;
} }
rcu_read_unlock(); rcu_read_unlock();