ceph: ensure d_name stability in ceph_dentry_hash() [Linux 3.16.72]

This Linux kernel change "ceph: ensure d_name stability in ceph_dentry_hash()" is included in the Linux 3.16.72 release. This change is authored by Jeff Layton <jlayton [at] kernel.org> on Wed Apr 17 12:58:28 2019 -0400. The commit for this change in Linux stable tree is 213bca6 (patch) which is from upstream commit 76a495d. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 76a495d.

ceph: ensure d_name stability in ceph_dentry_hash()

commit 76a495d666e5043ffc315695f8241f5e94a98849 upstream.

Take the d_lock here to ensure that d_name doesn't change.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: "Yan, Zheng" <zyan@redhat.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

There are 6 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 fs/ceph/dir.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index 5e20050..bdda508 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -1327,6 +1327,7 @@ void ceph_dentry_lru_del(struct dentry *dn)
 unsigned ceph_dentry_hash(struct inode *dir, struct dentry *dn)
    struct ceph_inode_info *dci = ceph_inode(dir);
+   unsigned hash;

    switch (dci->i_dir_layout.dl_dir_hash) {
    case 0: /* for backward compat */
@@ -1334,8 +1335,11 @@ unsigned ceph_dentry_hash(struct inode *dir, struct dentry *dn)
        return dn->d_name.hash;

-       return ceph_str_hash(dci->i_dir_layout.dl_dir_hash,
+       spin_lock(&dn->d_lock);
+       hash = ceph_str_hash(dci->i_dir_layout.dl_dir_hash,
                     dn->d_name.name, dn->d_name.len);
+       spin_unlock(&dn->d_lock);
+       return hash;

Leave a Reply

Your email address will not be published. Required fields are marked *