From b4daac19883180a1b2584d3f7c3b81132582b539 Mon Sep 17 00:00:00 2001 From: fuletian Date: Thu, 10 Jul 2025 15:22:47 +0800 Subject: [PATCH 01/14] modify_real_dst Signed-off-by: fuletian --- fs/hmdfs/hmdfs_merge_view.h | 2 +- fs/hmdfs/inode.c | 27 ++++++++ fs/hmdfs/inode.h | 4 ++ fs/hmdfs/inode_cloud_merge.c | 89 +++++++++--------------- fs/hmdfs/inode_merge.c | 128 ++++++++++++++--------------------- 5 files changed, 115 insertions(+), 135 deletions(-) diff --git a/fs/hmdfs/hmdfs_merge_view.h b/fs/hmdfs/hmdfs_merge_view.h index 940741a5b920..103236f772ab 100644 --- a/fs/hmdfs/hmdfs_merge_view.h +++ b/fs/hmdfs/hmdfs_merge_view.h @@ -112,7 +112,7 @@ void update_inode_attr(struct inode *inode, struct dentry *child_dentry); int get_num_comrades(struct dentry *dentry); void assign_comrades_unlocked(struct dentry *child_dentry, struct list_head *onstack_comrades_head); -struct hmdfs_dentry_comrade *lookup_comrade(struct path lower_path, +struct hmdfs_dentry_comrade *lookup_comrade(struct dentry lower_dentry, const char *d_name, int dev_id, unsigned int flags); diff --git a/fs/hmdfs/inode.c b/fs/hmdfs/inode.c index 33cc8c7419d5..a3ab37eb94ce 100644 --- a/fs/hmdfs/inode.c +++ b/fs/hmdfs/inode.c @@ -4,6 +4,7 @@ * * Copyright (c) 2020-2021 Huawei Device Co., Ltd. */ +#include #include "hmdfs_device_view.h" #include "inode.h" @@ -354,4 +355,30 @@ void hmdfs_update_upper_file(struct file *upper_file, struct file *lower_file) i_size_write(upper_file->f_inode, lower_size); truncate_inode_pages(upper_file->f_inode->i_mapping, 0); } +} + +struct dentry *lookup_multi_dir(struct dentry *root_dentry, + const char *name, + unsigned int flags) +{ + struct dentry *current_dentry = root_dentry; + struct dentry *ret_dentry = NULL; + const char *start = name; + const char *end = NULL; + + while (*start) { + end = strchr(start, '/'); + if (!end) { + end = start + strlen(start); + } + ret_dentry = lookup_one_len(start current_dentry, end - start); + if (IS_ERR(ret_dentry)) { + dput(current_dentry); + return ret_dentry; + } + dput(current_dentry); + current_dentry = ret_dentry; + start = end; + } + return ret_dentry; } \ No newline at end of file diff --git a/fs/hmdfs/inode.h b/fs/hmdfs/inode.h index fb9bd2929d58..78346806c218 100644 --- a/fs/hmdfs/inode.h +++ b/fs/hmdfs/inode.h @@ -261,4 +261,8 @@ struct inode *hmdfs_iget5_locked_cloud(struct super_block *sb, void hmdfs_update_upper_file(struct file *upper_file, struct file *lower_file); uint32_t make_ino_raw_cloud(uint8_t *cloud_id); + +struct dentry *lookup_multi_dir(struct dentry *root_dentry, + const char *name, + unsigned int flags); #endif // INODE_H diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index a6f0b150fcfc..39f0db5f58b4 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -94,28 +94,16 @@ cloud_merge_lookup_comrade(struct hmdfs_sb_info *sbi, int devid, unsigned int flags) { - int err; - struct path root, path; + struct dentry *dentry = NULL; struct hmdfs_dentry_comrade *comrade = NULL; - err = kern_path(sbi->real_dst, LOOKUP_DIRECTORY, &root); - if (err) { - comrade = ERR_PTR(err); - goto out; - } - - err = vfs_path_lookup(root.dentry, root.mnt, name, flags, &path); - if (err) { - comrade = ERR_PTR(err); - goto root_put; + dentry = lookup_multi_dir(sbi->sb->s_root, name, root); + if (IS_ERR(dentry)) { + return ERR_PTR(PTR_ERR(dentry)); } - comrade = alloc_comrade(path.dentry, devid); - - path_put(&path); -root_put: - path_put(&root); -out: + comrade = alloc_comrade(dentry, devid); + dput(dentry); return comrade; } @@ -202,7 +190,7 @@ static int lookup_merge_normal(struct dentry *dentry, unsigned int flags) * It's common for a network filesystem to incur various of faults, so we * intent to show mercy for faults here, except faults reported by the local. */ -static int do_lookup_cloud_merge_root(struct path path_dev, +static int do_lookup_cloud_merge_root(struct dentry *dentry_dev, struct dentry *child_dentry, unsigned int flags) { struct hmdfs_dentry_comrade *comrade; @@ -217,7 +205,7 @@ static int do_lookup_cloud_merge_root(struct path path_dev, // lookup real_dst/device_view/local memcpy(buf, DEVICE_VIEW_LOCAL, sizeof(DEVICE_VIEW_LOCAL)); - comrade = lookup_comrade(path_dev, buf, HMDFS_DEVID_LOCAL, flags); + comrade = lookup_comrade(dentry_dev, buf, HMDFS_DEVID_LOCAL, flags); if (IS_ERR(comrade)) { ret = PTR_ERR(comrade); goto out; @@ -226,7 +214,7 @@ static int do_lookup_cloud_merge_root(struct path path_dev, memcpy(buf, CLOUD_CID, 6); buf[5] = '\0'; - comrade = lookup_comrade(path_dev, buf, CLOUD_DEVICE, flags); + comrade = lookup_comrade(dentry_dev, buf, CLOUD_DEVICE, flags); if (IS_ERR(comrade)) { ret = 0; goto out; @@ -246,33 +234,22 @@ static int lookup_cloud_merge_root(struct inode *root_inode, struct dentry *child_dentry, unsigned int flags) { struct hmdfs_sb_info *sbi = hmdfs_sb(child_dentry->d_sb); - struct path path_dev; + struct dentry *dentry_dev = NULL; int ret = -ENOENT; - int buf_len; - char *buf = NULL; bool locked, down; - // consider additional one slash and one '\0' - buf_len = strlen(sbi->real_dst) + 1 + sizeof(DEVICE_VIEW_ROOT); - if (buf_len > PATH_MAX) - return -ENAMETOOLONG; - - buf = kmalloc(buf_len, GFP_KERNEL); - if (unlikely(!buf)) - return -ENOMEM; + dentry_dev = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); + if (IS_ERR(dentry_dev)) { + ret = PTR_ERR(dentry_dev); + goto out; + } - sprintf(buf, "%s/%s", sbi->real_dst, DEVICE_VIEW_ROOT); lock_root_inode_shared(root_inode, &locked, &down); - ret = hmdfs_get_path_in_sb(child_dentry->d_sb, buf, LOOKUP_DIRECTORY, - &path_dev); - if (ret) - goto free_buf; - ret = do_lookup_cloud_merge_root(path_dev, child_dentry, flags); - path_put(&path_dev); + ret = do_lookup_cloud_merge_root(dentry_dev, child_dentry, flags); + dput(dentry_dev) -free_buf: - kfree(buf); +out: restore_root_inode_sem(root_inode, locked, down); return ret; } @@ -414,7 +391,7 @@ int do_create_cloud_merge(struct inode *parent_inode, struct dentry *child_dentr } int hmdfs_do_ops_cloud_merge(struct inode *i_parent, struct dentry *d_child, - struct dentry *lo_d_child, struct path path, + struct dentry *lo_d_child, struct dentry *lo_d_parent, struct hmdfs_recursive_para *rec_op_para) { int ret = 0; @@ -424,20 +401,20 @@ int hmdfs_do_ops_cloud_merge(struct inode *i_parent, struct dentry *d_child, case F_MKDIR_MERGE: ret = do_mkdir_cloud_merge(i_parent, d_child, rec_op_para->mode, - d_inode(path.dentry), lo_d_child); + d_inode(lo_d_parent), lo_d_child); break; case F_CREATE_MERGE: ret = do_create_cloud_merge(i_parent, d_child, rec_op_para->mode, rec_op_para->want_excl, - d_inode(path.dentry), lo_d_child); + d_inode(lo_d_parent), lo_d_child); break; default: ret = -EINVAL; break; } } else { - ret = vfs_mkdir(&nop_mnt_idmap, d_inode(path.dentry), lo_d_child, + ret = vfs_mkdir(&nop_mnt_idmap, d_inode(lo_d_parent), lo_d_child, rec_op_para->mode); } if (ret) @@ -456,7 +433,6 @@ int hmdfs_create_lower_cloud_dentry(struct inode *i_parent, struct dentry *d_chi char *path_buf = kmalloc(PATH_MAX, GFP_KERNEL); char *absolute_path_buf = kmalloc(PATH_MAX, GFP_KERNEL); char *path_name = NULL; - struct path path = { .mnt = NULL, .dentry = NULL }; int ret = 0; if (unlikely(!path_buf || !absolute_path_buf)) { @@ -469,28 +445,27 @@ int hmdfs_create_lower_cloud_dentry(struct inode *i_parent, struct dentry *d_chi ret = PTR_ERR(path_name); goto out; } - if ((strlen(sbi->real_dst) + strlen(path_name) + - strlen(d_child->d_name.name) + 2) > PATH_MAX) { + if (strlen(path_name) + strlen(d_child->d_name.name) + 1 > PATH_MAX) { ret = -ENAMETOOLONG; goto out; } - sprintf(absolute_path_buf, "%s%s/%s", sbi->real_dst, path_name, - d_child->d_name.name); + sprintf(absolute_path_buf, "%s/%s", path_name, d_child->d_name.name); if (is_dir) - lo_d_child = kern_path_create(AT_FDCWD, absolute_path_buf, - &path, LOOKUP_DIRECTORY); + lo_d_child = lookup_multi_dir(sbi->sb->s_root, absolute_path_buf, LOOKUP_DIRECTORY); else - lo_d_child = kern_path_create(AT_FDCWD, absolute_path_buf, - &path, 0); + lo_d_child = lookup_multi_dir(sbi->sb->s_root, absolute_path_buf, 0); if (IS_ERR(lo_d_child)) { ret = PTR_ERR(lo_d_child); goto out; } + if (d_is_positive(lo_d_child)) { + ret = -EEXIST; + goto out; + } // to ensure link_comrade after vfs_mkdir succeed - ret = hmdfs_do_ops_cloud_merge(i_parent, d_child, lo_d_child, path, - rec_op_para); + ret = hmdfs_do_ops_cloud_merge(i_parent, d_child, lo_d_child, lo_d_parent, rec_op_para); if (ret) goto out_put; new_comrade = alloc_comrade(lo_d_child, HMDFS_DEVID_LOCAL); @@ -504,7 +479,7 @@ int hmdfs_create_lower_cloud_dentry(struct inode *i_parent, struct dentry *d_chi update_inode_attr(d_inode(d_child), d_child); out_put: - done_path_create(&path, lo_d_child); + dput(lo_d_child); out: kfree(absolute_path_buf); kfree(path_buf); diff --git a/fs/hmdfs/inode_merge.c b/fs/hmdfs/inode_merge.c index 7c1e1e4f8539..8b869e789fe9 100644 --- a/fs/hmdfs/inode_merge.c +++ b/fs/hmdfs/inode_merge.c @@ -222,17 +222,16 @@ struct hmdfs_dentry_comrade *lookup_comrade(struct path lower_path, int dev_id, unsigned int flags) { - struct path path; + struct dentry *dentry = NULL; struct hmdfs_dentry_comrade *comrade = NULL; - int err; - err = vfs_path_lookup(lower_path.dentry, lower_path.mnt, d_name, flags, - &path); - if (err) - return ERR_PTR(err); + dentry = lookup_multi_dir(sbi->sb->s_root, name, root); + if (IS_ERR(dentry)) { + return ERR_PTR(PTR_ERR(dentry)); + } - comrade = alloc_comrade(path.dentry, dev_id); - path_put(&path); + comrade = alloc_comrade(dentry, devid); + dput(dentry); return comrade; } @@ -346,28 +345,19 @@ static struct hmdfs_dentry_comrade *merge_lookup_comrade( struct hmdfs_sb_info *sbi, const char *name, int devid, unsigned int flags) { - int err; - struct path root, path; + struct dentry *dentry = NULL; struct hmdfs_dentry_comrade *comrade = NULL; const struct cred *old_cred = hmdfs_override_creds(sbi->cred); - err = kern_path(sbi->real_dst, LOOKUP_DIRECTORY, &root); - if (err) { - comrade = ERR_PTR(err); + dentry = lookup_multi_dir(sbi->sb->s_root, name, root); + if (IS_ERR(dentry)) { + comrade = ERR_PTR(PTR_ERR(dentry)); goto out; } - err = vfs_path_lookup(root.dentry, root.mnt, name, flags, &path); - if (err) { - comrade = ERR_PTR(err); - goto root_put; - } + comrade = alloc_comrade(dentry, devid); + dput(dentry); - comrade = alloc_comrade(path.dentry, devid); - - path_put(&path); -root_put: - path_put(&root); out: hmdfs_revert_creds(old_cred); return comrade; @@ -550,7 +540,7 @@ static int lookup_merge_normal(struct dentry *dentry, unsigned int flags) * It's common for a network filesystem to incur various of faults, so we * intent to show mercy for faults here, except faults reported by the local. */ -static int do_lookup_merge_root(struct path path_dev, +static int do_lookup_merge_root(struct dentry *dentry_dev, struct dentry *child_dentry, unsigned int flags) { struct hmdfs_sb_info *sbi = hmdfs_sb(child_dentry->d_sb); @@ -567,7 +557,7 @@ static int do_lookup_merge_root(struct path path_dev, // lookup real_dst/device_view/local memcpy(buf, DEVICE_VIEW_LOCAL, sizeof(DEVICE_VIEW_LOCAL)); - comrade = lookup_comrade(path_dev, buf, HMDFS_DEVID_LOCAL, flags); + comrade = lookup_comrade(dentry_dev, buf, HMDFS_DEVID_LOCAL, flags); if (IS_ERR(comrade)) { ret = PTR_ERR(comrade); goto out; @@ -579,7 +569,7 @@ static int do_lookup_merge_root(struct path path_dev, list_for_each_entry(peer, &sbi->connections.node_list, list) { mutex_unlock(&sbi->connections.node_lock); memcpy(buf, peer->cid, HMDFS_CID_SIZE); - comrade = lookup_comrade(path_dev, buf, peer->device_id, flags); + comrade = lookup_comrade(dentry_dev, buf, peer->device_id, flags); if (IS_ERR(comrade)) continue; @@ -641,33 +631,20 @@ static int lookup_merge_root(struct inode *root_inode, struct dentry *child_dentry, unsigned int flags) { struct hmdfs_sb_info *sbi = hmdfs_sb(child_dentry->d_sb); - struct path path_dev; + struct dentry *dentry_dev = NULL; int ret = -ENOENT; - int buf_len; - char *buf = NULL; bool locked, down; - // consider additional one slash and one '\0' - buf_len = strlen(sbi->real_dst) + 1 + sizeof(DEVICE_VIEW_ROOT); - if (buf_len > PATH_MAX) - return -ENAMETOOLONG; - - buf = kmalloc(buf_len, GFP_KERNEL); - if (unlikely(!buf)) - return -ENOMEM; - - sprintf(buf, "%s/%s", sbi->real_dst, DEVICE_VIEW_ROOT); - lock_root_inode_shared(root_inode, &locked, &down); - ret = hmdfs_get_path_in_sb(child_dentry->d_sb, buf, LOOKUP_DIRECTORY, - &path_dev); - if (ret) - goto free_buf; + dentry_dev = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); + if (IS_ERR(dentry_dev)) { + ret = PTR_ERR(dentry_dev); + goto out; + } - ret = do_lookup_merge_root(path_dev, child_dentry, flags); - path_put(&path_dev); + ret = do_lookup_merge_root(dentry_dev, child_dentry, flags); + dput(dev_dentry) -free_buf: - kfree(buf); +out: restore_root_inode_sem(root_inode, locked, down); return ret; } @@ -893,7 +870,7 @@ int do_create_merge(struct inode *parent_inode, struct dentry *child_dentry, } int hmdfs_do_ops_merge(struct inode *i_parent, struct dentry *d_child, - struct dentry *lo_d_child, struct path path, + struct dentry *lo_d_child, struct dentry *lo_d_parent, struct hmdfs_recursive_para *rec_op_para) { int ret = 0; @@ -903,20 +880,20 @@ int hmdfs_do_ops_merge(struct inode *i_parent, struct dentry *d_child, case F_MKDIR_MERGE: ret = do_mkdir_merge(i_parent, d_child, rec_op_para->mode, - d_inode(path.dentry), lo_d_child); + d_inode(lo_d_parent), lo_d_child); break; case F_CREATE_MERGE: ret = do_create_merge(i_parent, d_child, rec_op_para->mode, rec_op_para->want_excl, - d_inode(path.dentry), lo_d_child); + d_inode(lo_d_parent), lo_d_child); break; default: ret = -EINVAL; break; } } else { - ret = vfs_mkdir(&nop_mnt_idmap, d_inode(path.dentry), lo_d_child, + ret = vfs_mkdir(&nop_mnt_idmap, d_inode(lo_d_parent), lo_d_child, rec_op_para->mode); } if (ret) @@ -935,7 +912,6 @@ int hmdfs_create_lower_dentry(struct inode *i_parent, struct dentry *d_child, char *path_buf = kmalloc(PATH_MAX, GFP_KERNEL); char *absolute_path_buf = kmalloc(PATH_MAX, GFP_KERNEL); char *path_name = NULL; - struct path path = { .mnt = NULL, .dentry = NULL }; int ret = 0; if (unlikely(!path_buf || !absolute_path_buf)) { @@ -948,28 +924,28 @@ int hmdfs_create_lower_dentry(struct inode *i_parent, struct dentry *d_child, ret = PTR_ERR(path_name); goto out; } - if ((strlen(sbi->real_dst) + strlen(path_name) + - strlen(d_child->d_name.name) + 2) > PATH_MAX) { + if ((strlen(path_name) + strlen(d_child->d_name.name) + 1) > PATH_MAX) { ret = -ENAMETOOLONG; goto out; } - sprintf(absolute_path_buf, "%s%s/%s", sbi->real_dst, path_name, - d_child->d_name.name); + sprintf(absolute_path_buf, "%s/%s", path_name, d_child->d_name.name); if (is_dir) - lo_d_child = kern_path_create(AT_FDCWD, absolute_path_buf, - &path, LOOKUP_DIRECTORY); + lo_d_child = lookup_multi_dir(sbi->sb->s_root, absolute_path_buf, LOOKUP_DIRECTORY); else - lo_d_child = kern_path_create(AT_FDCWD, absolute_path_buf, - &path, 0); + lo_d_child = lookup_multi_dir(sbi->sb->s_root, absolute_path_buf, 0); + if (IS_ERR(lo_d_child)) { ret = PTR_ERR(lo_d_child); goto out; } + if (d_is_positive(lo_d_child)) { + ret = -EEXIST; + goto out; + } // to ensure link_comrade after vfs_mkdir succeed - ret = hmdfs_do_ops_merge(i_parent, d_child, lo_d_child, path, - rec_op_para); + ret = hmdfs_do_ops_merge(i_parent, d_child, lo_d_child, lo_d_parent, rec_op_para); if (ret) goto out_put; new_comrade = alloc_comrade(lo_d_child, HMDFS_DEVID_LOCAL); @@ -983,7 +959,7 @@ int hmdfs_create_lower_dentry(struct inode *i_parent, struct dentry *d_child, update_inode_attr(d_inode(d_child), d_child); out_put: - done_path_create(&path, lo_d_child); + dput(lo_d_child); out: kfree(absolute_path_buf); kfree(path_buf); @@ -1242,7 +1218,6 @@ int do_rename_merge(struct inode *old_dir, struct dentry *old_dentry, struct hmdfs_sb_info *sbi = (old_dir->i_sb)->s_fs_info; struct hmdfs_dentry_info_merge *dim = hmdfs_dm(old_dentry); struct hmdfs_dentry_comrade *comrade = NULL, *new_comrade = NULL; - struct path lo_p_new = { .mnt = NULL, .dentry = NULL }; struct inode *lo_i_old_dir = NULL, *lo_i_new_dir = NULL; struct dentry *lo_d_old_dir = NULL, *lo_d_old = NULL, *lo_d_new_dir = NULL, *lo_d_new = NULL; @@ -1282,26 +1257,25 @@ int do_rename_merge(struct inode *old_dir, struct dentry *old_dentry, continue; } - if (strlen(sbi->real_dst) + strlen(path_name) + - strlen(new_dentry->d_name.name) + 2 > PATH_MAX) { + if (strlen(path_name) + strlen(new_dentry->d_name.name) + 1 > PATH_MAX) { ret = -ENAMETOOLONG; goto out; } - snprintf(abs_path_buf, PATH_MAX, "%s%s/%s", sbi->real_dst, - path_name, new_dentry->d_name.name); + snprintf(abs_path_buf, PATH_MAX, "%s/%s", path_name, new_dentry->d_name.name); if (S_ISDIR(d_inode(old_dentry)->i_mode)) - lo_d_new = kern_path_create(AT_FDCWD, abs_path_buf, - &lo_p_new, - LOOKUP_DIRECTORY); + lo_d_new = lookup_multi_dir(sbi->sb->s_root, abs_path_buf, LOOKUP_DIRECTORY); else - lo_d_new = kern_path_create(AT_FDCWD, abs_path_buf, - &lo_p_new, 0); + lo_d_new = lookup_multi_dir(sbi->sb->s_root, abs_path_buf, 0); + if (IS_ERR(lo_d_new)) { ret = PTR_ERR(lo_d_new); goto out; } - + if (d_is_positive(lo_d_child)) { + ret = -EEXIST; + goto out; + } lo_d_new_dir = dget_parent(lo_d_new); lo_i_new_dir = d_inode(lo_d_new_dir); lo_d_old_dir = dget_parent(lo_d_old); @@ -1316,7 +1290,7 @@ int do_rename_merge(struct inode *old_dir, struct dentry *old_dentry, rename_data.flags = flags; ret = vfs_rename(&rename_data); - new_comrade = alloc_comrade(lo_p_new.dentry, comrade->dev_id); + new_comrade = alloc_comrade(lo_d_new_dir, comrade->dev_id); if (IS_ERR(new_comrade)) { ret = PTR_ERR(new_comrade); goto no_comrade; @@ -1324,7 +1298,7 @@ int do_rename_merge(struct inode *old_dir, struct dentry *old_dentry, link_comrade_unlocked(new_dentry, new_comrade); no_comrade: - done_path_create(&lo_p_new, lo_d_new); + dput(lo_d_new); dput(lo_d_old_dir); dput(lo_d_new_dir); } -- Gitee From 374564c2cf196883b331e9ef3121fc2a223f4610 Mon Sep 17 00:00:00 2001 From: fuletian Date: Thu, 10 Jul 2025 16:54:41 +0800 Subject: [PATCH 02/14] modify_real_dst Signed-off-by: fuletian --- fs/hmdfs/inode_cloud_merge.c | 3 +-- fs/hmdfs/inode_merge.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index 39f0db5f58b4..ea3c32dead92 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -238,14 +238,13 @@ static int lookup_cloud_merge_root(struct inode *root_inode, int ret = -ENOENT; bool locked, down; + lock_root_inode_shared(root_inode, &locked, &down); dentry_dev = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); if (IS_ERR(dentry_dev)) { ret = PTR_ERR(dentry_dev); goto out; } - lock_root_inode_shared(root_inode, &locked, &down); - ret = do_lookup_cloud_merge_root(dentry_dev, child_dentry, flags); dput(dentry_dev) diff --git a/fs/hmdfs/inode_merge.c b/fs/hmdfs/inode_merge.c index 8b869e789fe9..4d6487d92f3d 100644 --- a/fs/hmdfs/inode_merge.c +++ b/fs/hmdfs/inode_merge.c @@ -230,7 +230,7 @@ struct hmdfs_dentry_comrade *lookup_comrade(struct path lower_path, return ERR_PTR(PTR_ERR(dentry)); } - comrade = alloc_comrade(dentry, devid); + comrade = alloc_comrade(dentry, dev_id); dput(dentry); return comrade; } -- Gitee From fbe9e0b2ccc4d6bf5ed733d270087a635b0f5635 Mon Sep 17 00:00:00 2001 From: fuletian Date: Thu, 10 Jul 2025 17:35:40 +0800 Subject: [PATCH 03/14] modify_real_dst Signed-off-by: fuletian --- fs/hmdfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/hmdfs/inode.c b/fs/hmdfs/inode.c index a3ab37eb94ce..b6dbf2528d34 100644 --- a/fs/hmdfs/inode.c +++ b/fs/hmdfs/inode.c @@ -371,7 +371,7 @@ struct dentry *lookup_multi_dir(struct dentry *root_dentry, if (!end) { end = start + strlen(start); } - ret_dentry = lookup_one_len(start current_dentry, end - start); + ret_dentry = lookup_one_len(start, current_dentry, end - start); if (IS_ERR(ret_dentry)) { dput(current_dentry); return ret_dentry; -- Gitee From 769ac055ce99f3f7a725fd7de095ae978dda23b9 Mon Sep 17 00:00:00 2001 From: fuletian Date: Thu, 10 Jul 2025 17:56:53 +0800 Subject: [PATCH 04/14] modify_real_dst Signed-off-by: fuletian --- fs/hmdfs/hmdfs_merge_view.h | 2 +- fs/hmdfs/inode_cloud_merge.c | 2 +- fs/hmdfs/inode_merge.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/hmdfs/hmdfs_merge_view.h b/fs/hmdfs/hmdfs_merge_view.h index 103236f772ab..2218baec1ec8 100644 --- a/fs/hmdfs/hmdfs_merge_view.h +++ b/fs/hmdfs/hmdfs_merge_view.h @@ -112,7 +112,7 @@ void update_inode_attr(struct inode *inode, struct dentry *child_dentry); int get_num_comrades(struct dentry *dentry); void assign_comrades_unlocked(struct dentry *child_dentry, struct list_head *onstack_comrades_head); -struct hmdfs_dentry_comrade *lookup_comrade(struct dentry lower_dentry, +struct hmdfs_dentry_comrade *lookup_comrade(struct dentry *lower_dentry, const char *d_name, int dev_id, unsigned int flags); diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index ea3c32dead92..b659417a2bb0 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -97,7 +97,7 @@ cloud_merge_lookup_comrade(struct hmdfs_sb_info *sbi, struct dentry *dentry = NULL; struct hmdfs_dentry_comrade *comrade = NULL; - dentry = lookup_multi_dir(sbi->sb->s_root, name, root); + dentry = lookup_multi_dir(sbi->sb->s_root, name, flags ); if (IS_ERR(dentry)) { return ERR_PTR(PTR_ERR(dentry)); } diff --git a/fs/hmdfs/inode_merge.c b/fs/hmdfs/inode_merge.c index 4d6487d92f3d..02f74f858543 100644 --- a/fs/hmdfs/inode_merge.c +++ b/fs/hmdfs/inode_merge.c @@ -217,7 +217,7 @@ void assign_comrades_unlocked(struct dentry *child_dentry, mutex_unlock(&cdi->comrade_list_lock); } -struct hmdfs_dentry_comrade *lookup_comrade(struct path lower_path, +struct hmdfs_dentry_comrade *lookup_comrade(struct dentry *lower_dentry, const char *d_name, int dev_id, unsigned int flags) @@ -225,7 +225,7 @@ struct hmdfs_dentry_comrade *lookup_comrade(struct path lower_path, struct dentry *dentry = NULL; struct hmdfs_dentry_comrade *comrade = NULL; - dentry = lookup_multi_dir(sbi->sb->s_root, name, root); + dentry = lookup_multi_dir(lower_dentry, d_name, flags); if (IS_ERR(dentry)) { return ERR_PTR(PTR_ERR(dentry)); } @@ -349,7 +349,7 @@ static struct hmdfs_dentry_comrade *merge_lookup_comrade( struct hmdfs_dentry_comrade *comrade = NULL; const struct cred *old_cred = hmdfs_override_creds(sbi->cred); - dentry = lookup_multi_dir(sbi->sb->s_root, name, root); + dentry = lookup_multi_dir(sbi->sb->s_root, name, flags); if (IS_ERR(dentry)) { comrade = ERR_PTR(PTR_ERR(dentry)); goto out; -- Gitee From 8f4a3ca8be600a8de0473de8ea534522c0d0166e Mon Sep 17 00:00:00 2001 From: fuletian Date: Thu, 10 Jul 2025 19:06:12 +0800 Subject: [PATCH 05/14] modify_real_dst Signed-off-by: fuletian --- fs/hmdfs/inode_cloud_merge.c | 4 ++-- fs/hmdfs/inode_merge.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index b659417a2bb0..850b82ebf56a 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -97,7 +97,7 @@ cloud_merge_lookup_comrade(struct hmdfs_sb_info *sbi, struct dentry *dentry = NULL; struct hmdfs_dentry_comrade *comrade = NULL; - dentry = lookup_multi_dir(sbi->sb->s_root, name, flags ); + dentry = lookup_multi_dir(sbi->sb->s_root, name, flags); if (IS_ERR(dentry)) { return ERR_PTR(PTR_ERR(dentry)); } @@ -246,7 +246,7 @@ static int lookup_cloud_merge_root(struct inode *root_inode, } ret = do_lookup_cloud_merge_root(dentry_dev, child_dentry, flags); - dput(dentry_dev) + dput(dentry_dev); out: restore_root_inode_sem(root_inode, locked, down); diff --git a/fs/hmdfs/inode_merge.c b/fs/hmdfs/inode_merge.c index 02f74f858543..67dc9f7b97ca 100644 --- a/fs/hmdfs/inode_merge.c +++ b/fs/hmdfs/inode_merge.c @@ -642,7 +642,7 @@ static int lookup_merge_root(struct inode *root_inode, } ret = do_lookup_merge_root(dentry_dev, child_dentry, flags); - dput(dev_dentry) + dput(dev_dentry); out: restore_root_inode_sem(root_inode, locked, down); @@ -1272,7 +1272,7 @@ int do_rename_merge(struct inode *old_dir, struct dentry *old_dentry, ret = PTR_ERR(lo_d_new); goto out; } - if (d_is_positive(lo_d_child)) { + if (d_is_positive(lo_d_new)) { ret = -EEXIST; goto out; } -- Gitee From de0206be1c97c4c8246f41053a9ca6a02b64777b Mon Sep 17 00:00:00 2001 From: fuletian Date: Thu, 10 Jul 2025 20:28:42 +0800 Subject: [PATCH 06/14] modify_real_dst Signed-off-by: fuletian --- fs/hmdfs/inode_merge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/hmdfs/inode_merge.c b/fs/hmdfs/inode_merge.c index 67dc9f7b97ca..6d347ddf0b25 100644 --- a/fs/hmdfs/inode_merge.c +++ b/fs/hmdfs/inode_merge.c @@ -642,7 +642,7 @@ static int lookup_merge_root(struct inode *root_inode, } ret = do_lookup_merge_root(dentry_dev, child_dentry, flags); - dput(dev_dentry); + dput(dentry_dev); out: restore_root_inode_sem(root_inode, locked, down); -- Gitee From 86316d321c104ec2fd0d2d6fdf47cb15b10fdc86 Mon Sep 17 00:00:00 2001 From: fuletian Date: Thu, 10 Jul 2025 21:09:43 +0800 Subject: [PATCH 07/14] modify_real_dst Signed-off-by: fuletian --- fs/hmdfs/inode_merge.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/hmdfs/inode_merge.c b/fs/hmdfs/inode_merge.c index 6d347ddf0b25..5cd9a3590784 100644 --- a/fs/hmdfs/inode_merge.c +++ b/fs/hmdfs/inode_merge.c @@ -635,6 +635,7 @@ static int lookup_merge_root(struct inode *root_inode, int ret = -ENOENT; bool locked, down; + lock_root_inode_shared(root_inode, &locked, &down); dentry_dev = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); if (IS_ERR(dentry_dev)) { ret = PTR_ERR(dentry_dev); -- Gitee From 2f06d5846e0c0830b249b3f72b293a673e597499 Mon Sep 17 00:00:00 2001 From: fuletian Date: Fri, 11 Jul 2025 14:37:52 +0800 Subject: [PATCH 08/14] updata Signed-off-by: fuletian --- fs/hmdfs/inode.c | 4 ++++ fs/hmdfs/inode_cloud_merge.c | 6 +++--- fs/hmdfs/inode_merge.c | 10 +++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/fs/hmdfs/inode.c b/fs/hmdfs/inode.c index b6dbf2528d34..f3278cb673d8 100644 --- a/fs/hmdfs/inode.c +++ b/fs/hmdfs/inode.c @@ -366,6 +366,10 @@ struct dentry *lookup_multi_dir(struct dentry *root_dentry, const char *start = name; const char *end = NULL; + if (*start) { + dget(root_dentry); + } + while (*start) { end = strchr(start, '/'); if (!end) { diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index 850b82ebf56a..99bc45513913 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -98,7 +98,7 @@ cloud_merge_lookup_comrade(struct hmdfs_sb_info *sbi, struct hmdfs_dentry_comrade *comrade = NULL; dentry = lookup_multi_dir(sbi->sb->s_root, name, flags); - if (IS_ERR(dentry)) { + if (dentry == NULL || IS_ERR(dentry)) { return ERR_PTR(PTR_ERR(dentry)); } @@ -240,7 +240,7 @@ static int lookup_cloud_merge_root(struct inode *root_inode, lock_root_inode_shared(root_inode, &locked, &down); dentry_dev = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); - if (IS_ERR(dentry_dev)) { + if (dentry_dev == NULL || IS_ERR(dentry_dev)) { ret = PTR_ERR(dentry_dev); goto out; } @@ -455,7 +455,7 @@ int hmdfs_create_lower_cloud_dentry(struct inode *i_parent, struct dentry *d_chi lo_d_child = lookup_multi_dir(sbi->sb->s_root, absolute_path_buf, LOOKUP_DIRECTORY); else lo_d_child = lookup_multi_dir(sbi->sb->s_root, absolute_path_buf, 0); - if (IS_ERR(lo_d_child)) { + if (lo_d_child == NULL || IS_ERR(lo_d_child)) { ret = PTR_ERR(lo_d_child); goto out; } diff --git a/fs/hmdfs/inode_merge.c b/fs/hmdfs/inode_merge.c index 5cd9a3590784..5c0639ce4b7d 100644 --- a/fs/hmdfs/inode_merge.c +++ b/fs/hmdfs/inode_merge.c @@ -226,7 +226,7 @@ struct hmdfs_dentry_comrade *lookup_comrade(struct dentry *lower_dentry, struct hmdfs_dentry_comrade *comrade = NULL; dentry = lookup_multi_dir(lower_dentry, d_name, flags); - if (IS_ERR(dentry)) { + if (dentry == NULL || IS_ERR(dentry)) { return ERR_PTR(PTR_ERR(dentry)); } @@ -350,7 +350,7 @@ static struct hmdfs_dentry_comrade *merge_lookup_comrade( const struct cred *old_cred = hmdfs_override_creds(sbi->cred); dentry = lookup_multi_dir(sbi->sb->s_root, name, flags); - if (IS_ERR(dentry)) { + if (dentry == NULL || IS_ERR(dentry)) { comrade = ERR_PTR(PTR_ERR(dentry)); goto out; } @@ -637,7 +637,7 @@ static int lookup_merge_root(struct inode *root_inode, lock_root_inode_shared(root_inode, &locked, &down); dentry_dev = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); - if (IS_ERR(dentry_dev)) { + if (dentry_dev == NULL || IS_ERR(dentry_dev)) { ret = PTR_ERR(dentry_dev); goto out; } @@ -937,7 +937,7 @@ int hmdfs_create_lower_dentry(struct inode *i_parent, struct dentry *d_child, else lo_d_child = lookup_multi_dir(sbi->sb->s_root, absolute_path_buf, 0); - if (IS_ERR(lo_d_child)) { + if (lo_d_child == NULL == IS_ERR(lo_d_child)) { ret = PTR_ERR(lo_d_child); goto out; } @@ -1269,7 +1269,7 @@ int do_rename_merge(struct inode *old_dir, struct dentry *old_dentry, else lo_d_new = lookup_multi_dir(sbi->sb->s_root, abs_path_buf, 0); - if (IS_ERR(lo_d_new)) { + if (lo_d_new == NULL || IS_ERR(lo_d_new)) { ret = PTR_ERR(lo_d_new); goto out; } -- Gitee From 07b96df5b4ed537d27b9089a3460b2ea5d9ed37f Mon Sep 17 00:00:00 2001 From: fuletian Date: Fri, 11 Jul 2025 17:51:12 +0800 Subject: [PATCH 09/14] updata Signed-off-by: fuletian --- fs/hmdfs/inode.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/hmdfs/inode.c b/fs/hmdfs/inode.c index f3278cb673d8..e6391f61e844 100644 --- a/fs/hmdfs/inode.c +++ b/fs/hmdfs/inode.c @@ -382,7 +382,11 @@ struct dentry *lookup_multi_dir(struct dentry *root_dentry, } dput(current_dentry); current_dentry = ret_dentry; - start = end; + if (*end == '/') { + start = end + 1; + } else { + start = end; + } } return ret_dentry; } \ No newline at end of file -- Gitee From fd9b0988796ce599b95a96fcae477375b7eec009 Mon Sep 17 00:00:00 2001 From: fuletian Date: Fri, 11 Jul 2025 17:57:05 +0800 Subject: [PATCH 10/14] updata Signed-off-by: fuletian --- fs/hmdfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/hmdfs/inode.c b/fs/hmdfs/inode.c index e6391f61e844..7e93a932ce12 100644 --- a/fs/hmdfs/inode.c +++ b/fs/hmdfs/inode.c @@ -385,7 +385,7 @@ struct dentry *lookup_multi_dir(struct dentry *root_dentry, if (*end == '/') { start = end + 1; } else { - start = end; + break; } } return ret_dentry; -- Gitee From cf990cc767ca256027b20fcda4e2be800159a6ac Mon Sep 17 00:00:00 2001 From: fuletian Date: Wed, 16 Jul 2025 14:11:33 +0800 Subject: [PATCH 11/14] upload Signed-off-by: fuletian --- fs/hmdfs/inode.c | 20 ++++++++++++-------- fs/hmdfs/inode_cloud_merge.c | 17 +++++++++++++---- fs/hmdfs/inode_merge.c | 25 +++++++++++++++++++------ 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/fs/hmdfs/inode.c b/fs/hmdfs/inode.c index 7e93a932ce12..206db5877570 100644 --- a/fs/hmdfs/inode.c +++ b/fs/hmdfs/inode.c @@ -370,23 +370,27 @@ struct dentry *lookup_multi_dir(struct dentry *root_dentry, dget(root_dentry); } - while (*start) { + while (*start) { + if (*start == '/') { + start = start + 1; + continue; + } end = strchr(start, '/'); - if (!end) { + if (!end) end = start + strlen(start); - } ret_dentry = lookup_one_len(start, current_dentry, end - start); if (IS_ERR(ret_dentry)) { dput(current_dentry); return ret_dentry; } + if (d_is_negative(ret_dentry)) { + dput(current_dentry); + hmdfs_err("flt :: ret_dentry is negative!!!!!!!"); + return ret_dentry; + } dput(current_dentry); current_dentry = ret_dentry; - if (*end == '/') { - start = end + 1; - } else { - break; - } + start = end; } return ret_dentry; } \ No newline at end of file diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index 99bc45513913..4c78e9b9184d 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -98,9 +98,13 @@ cloud_merge_lookup_comrade(struct hmdfs_sb_info *sbi, struct hmdfs_dentry_comrade *comrade = NULL; dentry = lookup_multi_dir(sbi->sb->s_root, name, flags); - if (dentry == NULL || IS_ERR(dentry)) { + if (IS_ERR(dentry)) { return ERR_PTR(PTR_ERR(dentry)); } + if (d_is_negative(dentry)) { + dput(dentry); + return ERR_PTR(-ENOENT); + } comrade = alloc_comrade(dentry, devid); dput(dentry); @@ -240,10 +244,15 @@ static int lookup_cloud_merge_root(struct inode *root_inode, lock_root_inode_shared(root_inode, &locked, &down); dentry_dev = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); - if (dentry_dev == NULL || IS_ERR(dentry_dev)) { + if (IS_ERR(dentry_dev)) { ret = PTR_ERR(dentry_dev); goto out; } + if (d_is_negative(dentry_dev)) { + dput(dentry_dev); + ret = -ENOENT; + goto out; + } ret = do_lookup_cloud_merge_root(dentry_dev, child_dentry, flags); dput(dentry_dev); @@ -455,13 +464,13 @@ int hmdfs_create_lower_cloud_dentry(struct inode *i_parent, struct dentry *d_chi lo_d_child = lookup_multi_dir(sbi->sb->s_root, absolute_path_buf, LOOKUP_DIRECTORY); else lo_d_child = lookup_multi_dir(sbi->sb->s_root, absolute_path_buf, 0); - if (lo_d_child == NULL || IS_ERR(lo_d_child)) { + if (IS_ERR(lo_d_child)) { ret = PTR_ERR(lo_d_child); goto out; } if (d_is_positive(lo_d_child)) { ret = -EEXIST; - goto out; + goto out_put; } // to ensure link_comrade after vfs_mkdir succeed ret = hmdfs_do_ops_cloud_merge(i_parent, d_child, lo_d_child, lo_d_parent, rec_op_para); diff --git a/fs/hmdfs/inode_merge.c b/fs/hmdfs/inode_merge.c index 5c0639ce4b7d..147785542991 100644 --- a/fs/hmdfs/inode_merge.c +++ b/fs/hmdfs/inode_merge.c @@ -226,9 +226,13 @@ struct hmdfs_dentry_comrade *lookup_comrade(struct dentry *lower_dentry, struct hmdfs_dentry_comrade *comrade = NULL; dentry = lookup_multi_dir(lower_dentry, d_name, flags); - if (dentry == NULL || IS_ERR(dentry)) { + if (IS_ERR(dentry)) { return ERR_PTR(PTR_ERR(dentry)); } + if (d_is_negative(dentry)) { + dput(dentry); + return ERR_PTR(-ENOENT); + } comrade = alloc_comrade(dentry, dev_id); dput(dentry); @@ -350,10 +354,14 @@ static struct hmdfs_dentry_comrade *merge_lookup_comrade( const struct cred *old_cred = hmdfs_override_creds(sbi->cred); dentry = lookup_multi_dir(sbi->sb->s_root, name, flags); - if (dentry == NULL || IS_ERR(dentry)) { + if (IS_ERR(dentry)) { comrade = ERR_PTR(PTR_ERR(dentry)); goto out; } + if (d_is_negative(dentry)) { + dput(dentry); + return ERR_PTR(-ENOENT); + } comrade = alloc_comrade(dentry, devid); dput(dentry); @@ -637,10 +645,14 @@ static int lookup_merge_root(struct inode *root_inode, lock_root_inode_shared(root_inode, &locked, &down); dentry_dev = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); - if (dentry_dev == NULL || IS_ERR(dentry_dev)) { + if (IS_ERR(dentry_dev)) { ret = PTR_ERR(dentry_dev); goto out; } + if (d_is_negative(dentry_dev)) { + dput(dentry_dev); + return ERR_PTR(-ENOENT); + } ret = do_lookup_merge_root(dentry_dev, child_dentry, flags); dput(dentry_dev); @@ -937,13 +949,13 @@ int hmdfs_create_lower_dentry(struct inode *i_parent, struct dentry *d_child, else lo_d_child = lookup_multi_dir(sbi->sb->s_root, absolute_path_buf, 0); - if (lo_d_child == NULL == IS_ERR(lo_d_child)) { + if (IS_ERR(lo_d_child)) { ret = PTR_ERR(lo_d_child); goto out; } if (d_is_positive(lo_d_child)) { ret = -EEXIST; - goto out; + goto out_put; } // to ensure link_comrade after vfs_mkdir succeed ret = hmdfs_do_ops_merge(i_parent, d_child, lo_d_child, lo_d_parent, rec_op_para); @@ -1269,12 +1281,13 @@ int do_rename_merge(struct inode *old_dir, struct dentry *old_dentry, else lo_d_new = lookup_multi_dir(sbi->sb->s_root, abs_path_buf, 0); - if (lo_d_new == NULL || IS_ERR(lo_d_new)) { + if (IS_ERR(lo_d_new)) { ret = PTR_ERR(lo_d_new); goto out; } if (d_is_positive(lo_d_new)) { ret = -EEXIST; + dput(lo_d_new); goto out; } lo_d_new_dir = dget_parent(lo_d_new); -- Gitee From b7aab2e7c6d4fd66c1caedc0cc23c9b46944fd72 Mon Sep 17 00:00:00 2001 From: fuletian Date: Fri, 18 Jul 2025 09:50:10 +0800 Subject: [PATCH 12/14] updata Signed-off-by: fuletian --- fs/hmdfs/inode.c | 13 +++++-------- fs/hmdfs/inode_cloud_merge.c | 3 +-- fs/hmdfs/inode_merge.c | 3 +-- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/fs/hmdfs/inode.c b/fs/hmdfs/inode.c index 206db5877570..87c2ad430341 100644 --- a/fs/hmdfs/inode.c +++ b/fs/hmdfs/inode.c @@ -366,9 +366,11 @@ struct dentry *lookup_multi_dir(struct dentry *root_dentry, const char *start = name; const char *end = NULL; - if (*start) { + while (*start == '/') + start = start + 1; + + if (*start) dget(root_dentry); - } while (*start) { if (*start == '/') { @@ -379,13 +381,8 @@ struct dentry *lookup_multi_dir(struct dentry *root_dentry, if (!end) end = start + strlen(start); ret_dentry = lookup_one_len(start, current_dentry, end - start); - if (IS_ERR(ret_dentry)) { - dput(current_dentry); - return ret_dentry; - } - if (d_is_negative(ret_dentry)) { + if (IS_ERR(ret_dentry) || d_is_negative(ret_dentry)) { dput(current_dentry); - hmdfs_err("flt :: ret_dentry is negative!!!!!!!"); return ret_dentry; } dput(current_dentry); diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index 4c78e9b9184d..d7cec4795935 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -98,9 +98,8 @@ cloud_merge_lookup_comrade(struct hmdfs_sb_info *sbi, struct hmdfs_dentry_comrade *comrade = NULL; dentry = lookup_multi_dir(sbi->sb->s_root, name, flags); - if (IS_ERR(dentry)) { + if (IS_ERR(dentry)) return ERR_PTR(PTR_ERR(dentry)); - } if (d_is_negative(dentry)) { dput(dentry); return ERR_PTR(-ENOENT); diff --git a/fs/hmdfs/inode_merge.c b/fs/hmdfs/inode_merge.c index 147785542991..5d081332561f 100644 --- a/fs/hmdfs/inode_merge.c +++ b/fs/hmdfs/inode_merge.c @@ -226,9 +226,8 @@ struct hmdfs_dentry_comrade *lookup_comrade(struct dentry *lower_dentry, struct hmdfs_dentry_comrade *comrade = NULL; dentry = lookup_multi_dir(lower_dentry, d_name, flags); - if (IS_ERR(dentry)) { + if (IS_ERR(dentry)) return ERR_PTR(PTR_ERR(dentry)); - } if (d_is_negative(dentry)) { dput(dentry); return ERR_PTR(-ENOENT); -- Gitee From b03d1444e791ee7a146bda4399c319f9fa96b20f Mon Sep 17 00:00:00 2001 From: fuletian Date: Thu, 31 Jul 2025 09:28:11 +0800 Subject: [PATCH 13/14] updata_0731 Signed-off-by: fuletian --- fs/hmdfs/inode.c | 2 ++ fs/hmdfs/inode_cloud_merge.c | 21 +++++++++------------ fs/hmdfs/inode_merge.c | 16 +++++++--------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/fs/hmdfs/inode.c b/fs/hmdfs/inode.c index 87c2ad430341..2b63e367de2f 100644 --- a/fs/hmdfs/inode.c +++ b/fs/hmdfs/inode.c @@ -380,12 +380,14 @@ struct dentry *lookup_multi_dir(struct dentry *root_dentry, end = strchr(start, '/'); if (!end) end = start + strlen(start); + inode_lock(current_dentry->d_inode); ret_dentry = lookup_one_len(start, current_dentry, end - start); if (IS_ERR(ret_dentry) || d_is_negative(ret_dentry)) { dput(current_dentry); return ret_dentry; } dput(current_dentry); + inode_unlock(current_dentry->d_inode); current_dentry = ret_dentry; start = end; } diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index d7cec4795935..d7bfb1a97139 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -99,7 +99,7 @@ cloud_merge_lookup_comrade(struct hmdfs_sb_info *sbi, dentry = lookup_multi_dir(sbi->sb->s_root, name, flags); if (IS_ERR(dentry)) - return ERR_PTR(PTR_ERR(dentry)); + return ERR_CAST(dentry); if (d_is_negative(dentry)) { dput(dentry); return ERR_PTR(-ENOENT); @@ -241,23 +241,17 @@ static int lookup_cloud_merge_root(struct inode *root_inode, int ret = -ENOENT; bool locked, down; - lock_root_inode_shared(root_inode, &locked, &down); dentry_dev = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); - if (IS_ERR(dentry_dev)) { - ret = PTR_ERR(dentry_dev); - goto out; - } + if (IS_ERR(dentry_dev)) + return PTR_ERR(dentry_dev); if (d_is_negative(dentry_dev)) { dput(dentry_dev); - ret = -ENOENT; - goto out; + return -ENOENT; } ret = do_lookup_cloud_merge_root(dentry_dev, child_dentry, flags); dput(dentry_dev); -out: - restore_root_inode_sem(root_inode, locked, down); return ret; } @@ -471,20 +465,23 @@ int hmdfs_create_lower_cloud_dentry(struct inode *i_parent, struct dentry *d_chi ret = -EEXIST; goto out_put; } + inode_lock(lo_d_parent->d_inode); // to ensure link_comrade after vfs_mkdir succeed ret = hmdfs_do_ops_cloud_merge(i_parent, d_child, lo_d_child, lo_d_parent, rec_op_para); if (ret) - goto out_put; + goto unlock; new_comrade = alloc_comrade(lo_d_child, HMDFS_DEVID_LOCAL); if (IS_ERR(new_comrade)) { ret = PTR_ERR(new_comrade); - goto out_put; + goto unlock; } else { link_comrade_unlocked(d_child, new_comrade); } update_inode_attr(d_inode(d_child), d_child); +unlock: + inode_unlock(lo_d_parent->d_inode); out_put: dput(lo_d_child); out: diff --git a/fs/hmdfs/inode_merge.c b/fs/hmdfs/inode_merge.c index 5d081332561f..3c73190a9738 100644 --- a/fs/hmdfs/inode_merge.c +++ b/fs/hmdfs/inode_merge.c @@ -227,7 +227,7 @@ struct hmdfs_dentry_comrade *lookup_comrade(struct dentry *lower_dentry, dentry = lookup_multi_dir(lower_dentry, d_name, flags); if (IS_ERR(dentry)) - return ERR_PTR(PTR_ERR(dentry)); + return ERR_CAST(dentry); if (d_is_negative(dentry)) { dput(dentry); return ERR_PTR(-ENOENT); @@ -354,7 +354,7 @@ static struct hmdfs_dentry_comrade *merge_lookup_comrade( dentry = lookup_multi_dir(sbi->sb->s_root, name, flags); if (IS_ERR(dentry)) { - comrade = ERR_PTR(PTR_ERR(dentry)); + comrade = ERR_CAST(dentry); goto out; } if (d_is_negative(dentry)) { @@ -956,20 +956,23 @@ int hmdfs_create_lower_dentry(struct inode *i_parent, struct dentry *d_child, ret = -EEXIST; goto out_put; } + inode_lock(lo_d_parent->d_inode); // to ensure link_comrade after vfs_mkdir succeed ret = hmdfs_do_ops_merge(i_parent, d_child, lo_d_child, lo_d_parent, rec_op_para); if (ret) - goto out_put; + goto unlock; new_comrade = alloc_comrade(lo_d_child, HMDFS_DEVID_LOCAL); if (IS_ERR(new_comrade)) { ret = PTR_ERR(new_comrade); - goto out_put; + goto unlock; } else { link_comrade_unlocked(d_child, new_comrade); } update_inode_attr(d_inode(d_child), d_child); +unlock: + inode_unlock(lo_d_parent->d_inode); out_put: dput(lo_d_child); out: @@ -1284,11 +1287,6 @@ int do_rename_merge(struct inode *old_dir, struct dentry *old_dentry, ret = PTR_ERR(lo_d_new); goto out; } - if (d_is_positive(lo_d_new)) { - ret = -EEXIST; - dput(lo_d_new); - goto out; - } lo_d_new_dir = dget_parent(lo_d_new); lo_i_new_dir = d_inode(lo_d_new_dir); lo_d_old_dir = dget_parent(lo_d_old); -- Gitee From d587dd01e6dd8da76753ecb57276cb98807fc5bc Mon Sep 17 00:00:00 2001 From: fuletian Date: Thu, 31 Jul 2025 16:44:07 +0800 Subject: [PATCH 14/14] updatatest Signed-off-by: fuletian --- fs/hmdfs/inode.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/hmdfs/inode.c b/fs/hmdfs/inode.c index 2b63e367de2f..d85e213dac1a 100644 --- a/fs/hmdfs/inode.c +++ b/fs/hmdfs/inode.c @@ -380,14 +380,15 @@ struct dentry *lookup_multi_dir(struct dentry *root_dentry, end = strchr(start, '/'); if (!end) end = start + strlen(start); - inode_lock(current_dentry->d_inode); +// inode_lock(current_dentry->d_inode); ret_dentry = lookup_one_len(start, current_dentry, end - start); if (IS_ERR(ret_dentry) || d_is_negative(ret_dentry)) { +// inode_unlock(current_dentry->d_inode); dput(current_dentry); return ret_dentry; } dput(current_dentry); - inode_unlock(current_dentry->d_inode); +// inode_unlock(current_dentry->d_inode); current_dentry = ret_dentry; start = end; } -- Gitee