From b4daac19883180a1b2584d3f7c3b81132582b539 Mon Sep 17 00:00:00 2001 From: fuletian Date: Thu, 10 Jul 2025 15:22:47 +0800 Subject: [PATCH 01/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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 ddd871325c6712ddcb4a0bc04d162bf8f4ac3050 Mon Sep 17 00:00:00 2001 From: fuletian Date: Fri, 11 Jul 2025 11:33:02 +0000 Subject: [PATCH 11/28] update fs/hmdfs/inode.c. Signed-off-by: fuletian --- fs/hmdfs/inode.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/hmdfs/inode.c b/fs/hmdfs/inode.c index 7e93a932ce12..f9c1cef4ef24 100644 --- a/fs/hmdfs/inode.c +++ b/fs/hmdfs/inode.c @@ -382,11 +382,10 @@ struct dentry *lookup_multi_dir(struct dentry *root_dentry, } dput(current_dentry); current_dentry = ret_dentry; - if (*end == '/') { - start = end + 1; - } else { - break; + while (*end == '/') { + end = end + 1; } + start = end; } return ret_dentry; } \ No newline at end of file -- Gitee From 85c567326732b4fd470fd9602a61214a11a0718f Mon Sep 17 00:00:00 2001 From: fuletian Date: Sun, 13 Jul 2025 02:45:06 +0000 Subject: [PATCH 12/28] update fs/hmdfs/inode.c. Signed-off-by: fuletian --- fs/hmdfs/inode.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/hmdfs/inode.c b/fs/hmdfs/inode.c index f9c1cef4ef24..0bb561851c34 100644 --- a/fs/hmdfs/inode.c +++ b/fs/hmdfs/inode.c @@ -376,6 +376,9 @@ struct dentry *lookup_multi_dir(struct dentry *root_dentry, end = start + strlen(start); } ret_dentry = lookup_one_len(start, current_dentry, end - start); + if (d_is_negative(ret_dentry)){ + ret_dentry = ERR_PTR(-ENOENT); + } if (IS_ERR(ret_dentry)) { dput(current_dentry); return ret_dentry; -- Gitee From 5b828b23b88765d8fe0fa331d85be205ed3170df Mon Sep 17 00:00:00 2001 From: fuletian Date: Mon, 14 Jul 2025 02:36:23 +0000 Subject: [PATCH 13/28] update fs/hmdfs/inode.c. Signed-off-by: fuletian --- fs/hmdfs/inode.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/fs/hmdfs/inode.c b/fs/hmdfs/inode.c index 0bb561851c34..58f81a88b91e 100644 --- a/fs/hmdfs/inode.c +++ b/fs/hmdfs/inode.c @@ -370,25 +370,26 @@ 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 (d_is_negative(ret_dentry)){ - ret_dentry = ERR_PTR(-ENOENT); - } + if (d_is_negative(ret_dentry)) { + dput(ret_dentry); + ret_dentry = ERR_PTR(-ENOENT); + } if (IS_ERR(ret_dentry)) { dput(current_dentry); return ret_dentry; } dput(current_dentry); current_dentry = ret_dentry; - while (*end == '/') { - end = end + 1; - } - start = end; + start = end; } return ret_dentry; } \ No newline at end of file -- Gitee From ef85057bca7577a888736b31c20b147191626d16 Mon Sep 17 00:00:00 2001 From: fuletian Date: Mon, 14 Jul 2025 07:34:00 +0000 Subject: [PATCH 14/28] update fs/hmdfs/inode_merge.c. Signed-off-by: fuletian --- fs/hmdfs/inode_merge.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/fs/hmdfs/inode_merge.c b/fs/hmdfs/inode_merge.c index 5c0639ce4b7d..296b89aa7412 100644 --- a/fs/hmdfs/inode_merge.c +++ b/fs/hmdfs/inode_merge.c @@ -226,6 +226,10 @@ 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 (d_is_negative(dentry)) { + dput(dentry); + dentry = ERR_PTR(-ENOENT); + } if (dentry == NULL || IS_ERR(dentry)) { return ERR_PTR(PTR_ERR(dentry)); } @@ -350,6 +354,10 @@ 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 (d_is_negative(dentry)) { + dput(dentry); + dentry = ERR_PTR(-ENOENT); + } if (dentry == NULL || IS_ERR(dentry)) { comrade = ERR_PTR(PTR_ERR(dentry)); goto out; @@ -637,6 +645,10 @@ 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 (d_is_negative(dentry_dev)) { + dput(dentry_dev); + dentry_dev = ERR_PTR(-ENOENT); + } if (dentry_dev == NULL || IS_ERR(dentry_dev)) { ret = PTR_ERR(dentry_dev); goto out; @@ -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 (lo_d_child == NULL || 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); @@ -1275,6 +1287,7 @@ int do_rename_merge(struct inode *old_dir, struct dentry *old_dentry, } 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 94283de0a1b7b111dccd2a159e7fa944b0b43bc2 Mon Sep 17 00:00:00 2001 From: fuletian Date: Mon, 14 Jul 2025 07:37:04 +0000 Subject: [PATCH 15/28] update fs/hmdfs/inode_cloud_merge.c. Signed-off-by: fuletian --- fs/hmdfs/inode_cloud_merge.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index 99bc45513913..a9912aacf005 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -98,6 +98,10 @@ 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 (d_is_negative(dentry)) { + dput(dentry); + dentry = ERR_PTR(-ENOENT); + } if (dentry == NULL || IS_ERR(dentry)) { return ERR_PTR(PTR_ERR(dentry)); } @@ -240,6 +244,10 @@ 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 (d_is_negative(dentry_dev)) { + dput(dentry_dev); + dentry_dev = ERR_PTR(-ENOENT); + } if (dentry_dev == NULL || IS_ERR(dentry_dev)) { ret = PTR_ERR(dentry_dev); goto out; @@ -461,7 +469,7 @@ int hmdfs_create_lower_cloud_dentry(struct inode *i_parent, struct dentry *d_chi } 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); -- Gitee From b75c85807ba420d53491d9fcaf48a841ba43be85 Mon Sep 17 00:00:00 2001 From: fuletian Date: Mon, 14 Jul 2025 07:38:33 +0000 Subject: [PATCH 16/28] update fs/hmdfs/inode.c. Signed-off-by: fuletian --- fs/hmdfs/inode.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fs/hmdfs/inode.c b/fs/hmdfs/inode.c index 58f81a88b91e..1a03f3072378 100644 --- a/fs/hmdfs/inode.c +++ b/fs/hmdfs/inode.c @@ -379,10 +379,6 @@ 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 (d_is_negative(ret_dentry)) { - dput(ret_dentry); - ret_dentry = ERR_PTR(-ENOENT); - } if (IS_ERR(ret_dentry)) { dput(current_dentry); return ret_dentry; -- Gitee From cd4bca81840579cc58a75cdecc532df4d95a85d6 Mon Sep 17 00:00:00 2001 From: fuletian Date: Mon, 14 Jul 2025 09:04:05 +0000 Subject: [PATCH 17/28] update fs/hmdfs/inode_cloud_merge.c. Signed-off-by: fuletian --- fs/hmdfs/inode_cloud_merge.c | 98 +++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 40 deletions(-) diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index a9912aacf005..a6f0b150fcfc 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -94,20 +94,28 @@ cloud_merge_lookup_comrade(struct hmdfs_sb_info *sbi, int devid, unsigned int flags) { - struct dentry *dentry = NULL; + int err; + struct path root, path; struct hmdfs_dentry_comrade *comrade = NULL; - dentry = lookup_multi_dir(sbi->sb->s_root, name, flags); - if (d_is_negative(dentry)) { - dput(dentry); - dentry = ERR_PTR(-ENOENT); + err = kern_path(sbi->real_dst, LOOKUP_DIRECTORY, &root); + if (err) { + comrade = ERR_PTR(err); + goto out; } - if (dentry == NULL || IS_ERR(dentry)) { - return ERR_PTR(PTR_ERR(dentry)); + + 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: return comrade; } @@ -194,7 +202,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 dentry *dentry_dev, +static int do_lookup_cloud_merge_root(struct path path_dev, struct dentry *child_dentry, unsigned int flags) { struct hmdfs_dentry_comrade *comrade; @@ -209,7 +217,7 @@ static int do_lookup_cloud_merge_root(struct dentry *dentry_dev, // lookup real_dst/device_view/local memcpy(buf, DEVICE_VIEW_LOCAL, sizeof(DEVICE_VIEW_LOCAL)); - comrade = lookup_comrade(dentry_dev, buf, HMDFS_DEVID_LOCAL, flags); + comrade = lookup_comrade(path_dev, buf, HMDFS_DEVID_LOCAL, flags); if (IS_ERR(comrade)) { ret = PTR_ERR(comrade); goto out; @@ -218,7 +226,7 @@ static int do_lookup_cloud_merge_root(struct dentry *dentry_dev, memcpy(buf, CLOUD_CID, 6); buf[5] = '\0'; - comrade = lookup_comrade(dentry_dev, buf, CLOUD_DEVICE, flags); + comrade = lookup_comrade(path_dev, buf, CLOUD_DEVICE, flags); if (IS_ERR(comrade)) { ret = 0; goto out; @@ -238,25 +246,33 @@ 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 dentry *dentry_dev = NULL; + struct path path_dev; 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); - dentry_dev = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); - if (d_is_negative(dentry_dev)) { - dput(dentry_dev); - dentry_dev = ERR_PTR(-ENOENT); - } - if (dentry_dev == NULL || IS_ERR(dentry_dev)) { - ret = PTR_ERR(dentry_dev); - goto out; - } + 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(dentry_dev, child_dentry, flags); - dput(dentry_dev); + ret = do_lookup_cloud_merge_root(path_dev, child_dentry, flags); + path_put(&path_dev); -out: +free_buf: + kfree(buf); restore_root_inode_sem(root_inode, locked, down); return ret; } @@ -398,7 +414,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 dentry *lo_d_parent, + struct dentry *lo_d_child, struct path path, struct hmdfs_recursive_para *rec_op_para) { int ret = 0; @@ -408,20 +424,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(lo_d_parent), lo_d_child); + d_inode(path.dentry), 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(lo_d_parent), lo_d_child); + d_inode(path.dentry), lo_d_child); break; default: ret = -EINVAL; break; } } else { - ret = vfs_mkdir(&nop_mnt_idmap, d_inode(lo_d_parent), lo_d_child, + ret = vfs_mkdir(&nop_mnt_idmap, d_inode(path.dentry), lo_d_child, rec_op_para->mode); } if (ret) @@ -440,6 +456,7 @@ 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)) { @@ -452,27 +469,28 @@ int hmdfs_create_lower_cloud_dentry(struct inode *i_parent, struct dentry *d_chi ret = PTR_ERR(path_name); goto out; } - if (strlen(path_name) + strlen(d_child->d_name.name) + 1 > PATH_MAX) { + if ((strlen(sbi->real_dst) + strlen(path_name) + + strlen(d_child->d_name.name) + 2) > PATH_MAX) { ret = -ENAMETOOLONG; goto out; } - sprintf(absolute_path_buf, "%s/%s", path_name, d_child->d_name.name); + sprintf(absolute_path_buf, "%s%s/%s", sbi->real_dst, path_name, + d_child->d_name.name); if (is_dir) - lo_d_child = lookup_multi_dir(sbi->sb->s_root, absolute_path_buf, LOOKUP_DIRECTORY); + lo_d_child = kern_path_create(AT_FDCWD, absolute_path_buf, + &path, 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)) { + lo_d_child = kern_path_create(AT_FDCWD, absolute_path_buf, + &path, 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_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); + ret = hmdfs_do_ops_cloud_merge(i_parent, d_child, lo_d_child, path, + rec_op_para); if (ret) goto out_put; new_comrade = alloc_comrade(lo_d_child, HMDFS_DEVID_LOCAL); @@ -486,7 +504,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: - dput(lo_d_child); + done_path_create(&path, lo_d_child); out: kfree(absolute_path_buf); kfree(path_buf); -- Gitee From b8c5e78210b2e78fd13a02a6a7940c1db5ac59cd Mon Sep 17 00:00:00 2001 From: fuletian Date: Mon, 14 Jul 2025 09:43:30 +0000 Subject: [PATCH 18/28] update fs/hmdfs/inode_merge.c. Signed-off-by: fuletian --- fs/hmdfs/inode_merge.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/fs/hmdfs/inode_merge.c b/fs/hmdfs/inode_merge.c index 296b89aa7412..50d42c077d75 100644 --- a/fs/hmdfs/inode_merge.c +++ b/fs/hmdfs/inode_merge.c @@ -226,13 +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 (d_is_negative(dentry)) { - dput(dentry); - dentry = ERR_PTR(-ENOENT); - } if (dentry == NULL || 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); @@ -354,14 +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 (d_is_negative(dentry)) { - dput(dentry); - dentry = ERR_PTR(-ENOENT); - } if (dentry == NULL || 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); @@ -645,14 +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 (d_is_negative(dentry_dev)) { - dput(dentry_dev); - dentry_dev = ERR_PTR(-ENOENT); - } if (dentry_dev == NULL || 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); -- Gitee From 8cef08de50088f37617395b1a6e6d6e51a89821a Mon Sep 17 00:00:00 2001 From: fuletian Date: Mon, 14 Jul 2025 09:45:36 +0000 Subject: [PATCH 19/28] update fs/hmdfs/inode_cloud_merge.c. Signed-off-by: fuletian --- fs/hmdfs/inode_cloud_merge.c | 98 +++++++++++++++--------------------- 1 file changed, 40 insertions(+), 58 deletions(-) diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index a6f0b150fcfc..49f09636bdd4 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -94,28 +94,20 @@ 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; + dentry = lookup_multi_dir(sbi->sb->s_root, name, flags); + if (dentry == NULL || IS_ERR(dentry)) { + return ERR_PTR(PTR_ERR(dentry)); } - - err = vfs_path_lookup(root.dentry, root.mnt, name, flags, &path); - if (err) { - comrade = ERR_PTR(err); - goto root_put; + if (d_is_negative(dentry)) { + dput(dentry); + return ERR_PTR(-ENOENT); } - 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 +194,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 +209,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 +218,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 +238,25 @@ 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; - - 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 (dentry_dev == NULL || 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_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 +398,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 +408,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 +440,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 +452,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); - if (IS_ERR(lo_d_child)) { + lo_d_child = lookup_multi_dir(sbi->sb->s_root, absolute_path_buf, 0); + if (lo_d_child == NULL || IS_ERR(lo_d_child)) { ret = PTR_ERR(lo_d_child); goto out; } + if (d_is_positive(lo_d_child)) { + ret = -EEXIST; + goto out_put; + } // 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 +486,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); -- Gitee From 2c6cdecfd7e47a6786dffbc601af080e868a98fa Mon Sep 17 00:00:00 2001 From: fuletian Date: Mon, 14 Jul 2025 12:29:46 +0000 Subject: [PATCH 20/28] update fs/hmdfs/inode_cloud_merge.c. Signed-off-by: fuletian --- fs/hmdfs/inode_cloud_merge.c | 98 +++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 40 deletions(-) diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index 49f09636bdd4..a6f0b150fcfc 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -94,20 +94,28 @@ cloud_merge_lookup_comrade(struct hmdfs_sb_info *sbi, int devid, unsigned int flags) { - struct dentry *dentry = NULL; + int err; + struct path root, path; struct hmdfs_dentry_comrade *comrade = NULL; - dentry = lookup_multi_dir(sbi->sb->s_root, name, flags); - if (dentry == NULL || IS_ERR(dentry)) { - return ERR_PTR(PTR_ERR(dentry)); + err = kern_path(sbi->real_dst, LOOKUP_DIRECTORY, &root); + if (err) { + comrade = ERR_PTR(err); + goto out; } - if (d_is_negative(dentry)) { - dput(dentry); - return ERR_PTR(-ENOENT); + + 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: return comrade; } @@ -194,7 +202,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 dentry *dentry_dev, +static int do_lookup_cloud_merge_root(struct path path_dev, struct dentry *child_dentry, unsigned int flags) { struct hmdfs_dentry_comrade *comrade; @@ -209,7 +217,7 @@ static int do_lookup_cloud_merge_root(struct dentry *dentry_dev, // lookup real_dst/device_view/local memcpy(buf, DEVICE_VIEW_LOCAL, sizeof(DEVICE_VIEW_LOCAL)); - comrade = lookup_comrade(dentry_dev, buf, HMDFS_DEVID_LOCAL, flags); + comrade = lookup_comrade(path_dev, buf, HMDFS_DEVID_LOCAL, flags); if (IS_ERR(comrade)) { ret = PTR_ERR(comrade); goto out; @@ -218,7 +226,7 @@ static int do_lookup_cloud_merge_root(struct dentry *dentry_dev, memcpy(buf, CLOUD_CID, 6); buf[5] = '\0'; - comrade = lookup_comrade(dentry_dev, buf, CLOUD_DEVICE, flags); + comrade = lookup_comrade(path_dev, buf, CLOUD_DEVICE, flags); if (IS_ERR(comrade)) { ret = 0; goto out; @@ -238,25 +246,33 @@ 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 dentry *dentry_dev = NULL; + struct path path_dev; 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); - dentry_dev = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); - if (dentry_dev == NULL || 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 = 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(dentry_dev, child_dentry, flags); - dput(dentry_dev); + ret = do_lookup_cloud_merge_root(path_dev, child_dentry, flags); + path_put(&path_dev); -out: +free_buf: + kfree(buf); restore_root_inode_sem(root_inode, locked, down); return ret; } @@ -398,7 +414,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 dentry *lo_d_parent, + struct dentry *lo_d_child, struct path path, struct hmdfs_recursive_para *rec_op_para) { int ret = 0; @@ -408,20 +424,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(lo_d_parent), lo_d_child); + d_inode(path.dentry), 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(lo_d_parent), lo_d_child); + d_inode(path.dentry), lo_d_child); break; default: ret = -EINVAL; break; } } else { - ret = vfs_mkdir(&nop_mnt_idmap, d_inode(lo_d_parent), lo_d_child, + ret = vfs_mkdir(&nop_mnt_idmap, d_inode(path.dentry), lo_d_child, rec_op_para->mode); } if (ret) @@ -440,6 +456,7 @@ 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)) { @@ -452,27 +469,28 @@ int hmdfs_create_lower_cloud_dentry(struct inode *i_parent, struct dentry *d_chi ret = PTR_ERR(path_name); goto out; } - if (strlen(path_name) + strlen(d_child->d_name.name) + 1 > PATH_MAX) { + if ((strlen(sbi->real_dst) + strlen(path_name) + + strlen(d_child->d_name.name) + 2) > PATH_MAX) { ret = -ENAMETOOLONG; goto out; } - sprintf(absolute_path_buf, "%s/%s", path_name, d_child->d_name.name); + sprintf(absolute_path_buf, "%s%s/%s", sbi->real_dst, path_name, + d_child->d_name.name); if (is_dir) - lo_d_child = lookup_multi_dir(sbi->sb->s_root, absolute_path_buf, LOOKUP_DIRECTORY); + lo_d_child = kern_path_create(AT_FDCWD, absolute_path_buf, + &path, 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)) { + lo_d_child = kern_path_create(AT_FDCWD, absolute_path_buf, + &path, 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_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); + ret = hmdfs_do_ops_cloud_merge(i_parent, d_child, lo_d_child, path, + rec_op_para); if (ret) goto out_put; new_comrade = alloc_comrade(lo_d_child, HMDFS_DEVID_LOCAL); @@ -486,7 +504,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: - dput(lo_d_child); + done_path_create(&path, lo_d_child); out: kfree(absolute_path_buf); kfree(path_buf); -- Gitee From 93382c686fe464d5c7971b3eadac8f0426d915d3 Mon Sep 17 00:00:00 2001 From: fuletian Date: Mon, 14 Jul 2025 12:32:34 +0000 Subject: [PATCH 21/28] update fs/hmdfs/inode_cloud_merge.c. Signed-off-by: fuletian --- fs/hmdfs/inode_cloud_merge.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index a6f0b150fcfc..fef4b5bd392e 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -19,6 +19,25 @@ #include "authority/authentication.h" #include "hmdfs_trace.h" +struct hmdfs_dentry_comrade *cloud_lookup_comrade(struct path lower_path, + const char *d_name, + int dev_id, + unsigned int flags) +{ + struct path path; + 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); + + comrade = alloc_comrade(path.dentry, dev_id); + path_put(&path); + return comrade; +} + static struct inode *fill_inode_merge(struct super_block *sb, struct inode *parent_inode, struct dentry *child_dentry, @@ -217,7 +236,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 = cloud_lookup_comrade(path_dev, buf, HMDFS_DEVID_LOCAL, flags); if (IS_ERR(comrade)) { ret = PTR_ERR(comrade); goto out; @@ -226,7 +245,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 = cloud_lookup_comrade(path_dev, buf, CLOUD_DEVICE, flags); if (IS_ERR(comrade)) { ret = 0; goto out; -- Gitee From e3ae0011f0af4cb94e7149f213ef061f8eaee2e4 Mon Sep 17 00:00:00 2001 From: fuletian Date: Mon, 14 Jul 2025 14:17:05 +0000 Subject: [PATCH 22/28] update fs/hmdfs/inode_cloud_merge.c. Signed-off-by: fuletian --- fs/hmdfs/inode_cloud_merge.c | 58 ++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index fef4b5bd392e..80c3b5db7724 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -116,7 +116,9 @@ cloud_merge_lookup_comrade(struct hmdfs_sb_info *sbi, int err; struct path root, path; struct hmdfs_dentry_comrade *comrade = NULL; - + struct dentry *tmp_dentry = NULL; + struct dentry *p_dentry = NULL; + struct dentry *dentry = NULL; err = kern_path(sbi->real_dst, LOOKUP_DIRECTORY, &root); if (err) { comrade = ERR_PTR(err); @@ -128,7 +130,31 @@ cloud_merge_lookup_comrade(struct hmdfs_sb_info *sbi, comrade = ERR_PTR(err); goto root_put; } - + tmp_dentry = path.dentry; + p_dentry = tmp_dentry->d_parent; + hmdfs_err("flt :: in cloud_merge_lookup_comrade BEFORE dentry_name = %s, node = %lu, d_parent = %x, parent_name = %s", + tmp_dentry->d_name.name, tmp_dentry->d_inode->i_ino, + p_dentry, p_dentry->d_name.name); + + dentry = lookup_multi_dir(sbi->sb->s_root, name, flags); + if (dentry == NULL || IS_ERR(dentry)) { + hmdfs_err("flt :: in cloud_merge_lookup_comrade lookup_multi_dir FAILED!"); + if (dentry == NULL) { + hmdfs_err("flt :: dentry == NULL"); + } else { + hmdfs_err("flt :: IS_ERR(dentry)"); + } + } else if (d_is_negative(dentry)) { + dput(dentry); + hmdfs_err("flt :: d_is_negative(dentry)"); + } else { + tmp_dentry = dentry; + p_dentry = tmp_dentry->d_parent; + hmdfs_err("flt :: in cloud_merge_lookup_comrade AFTER dentry_name = %s, node = %lu, d_parent = %x, parent_name = %s", + tmp_dentry->d_name.name, tmp_dentry->d_inode->i_ino, + p_dentry, p_dentry->d_name.name); + dput(dentry); + } comrade = alloc_comrade(path.dentry, devid); path_put(&path); @@ -270,6 +296,9 @@ static int lookup_cloud_merge_root(struct inode *root_inode, int buf_len; char *buf = NULL; bool locked, down; + struct dentry *tmp_dentry = NULL; + struct dentry *p_dentry = NULL; + struct dentry *dentry = NULL; // consider additional one slash and one '\0' buf_len = strlen(sbi->real_dst) + 1 + sizeof(DEVICE_VIEW_ROOT); @@ -286,6 +315,31 @@ static int lookup_cloud_merge_root(struct inode *root_inode, &path_dev); if (ret) goto free_buf; + tmp_dentry = path_dev.dentry; + p_dentry = tmp_dentry->d_parent; + hmdfs_err("flt :: in cloud_merge_lookup_comrade BEFORE dentry_name = %s, node = %lu, d_parent = %x, parent_name = %s", + tmp_dentry->d_name.name, tmp_dentry->d_inode->i_ino, + p_dentry, p_dentry->d_name.name); + + dentry_dev = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); + if (dentry == NULL || IS_ERR(dentry)) { + hmdfs_err("flt :: in cloud_merge_lookup_comrade lookup_multi_dir FAILED!"); + if (dentry == NULL) { + hmdfs_err("flt :: dentry == NULL"); + } else { + hmdfs_err("flt :: IS_ERR(dentry)"); + } + } else if (d_is_negative(dentry)) { + dput(dentry); + hmdfs_err("flt :: d_is_negative(dentry)"); + } else { + tmp_dentry = dentry; + p_dentry = tmp_dentry->d_parent; + hmdfs_err("flt :: in cloud_merge_lookup_comrade AFTER dentry_name = %s, node = %lu, d_parent = %x, parent_name = %s", + tmp_dentry->d_name.name, tmp_dentry->d_inode->i_ino, + p_dentry, p_dentry->d_name.name); + dput(dentry); + } ret = do_lookup_cloud_merge_root(path_dev, child_dentry, flags); path_put(&path_dev); -- Gitee From 8aec1579bfbb611690849a9589806d7742bb404a Mon Sep 17 00:00:00 2001 From: fuletian Date: Mon, 14 Jul 2025 14:18:22 +0000 Subject: [PATCH 23/28] update fs/hmdfs/inode.c. Signed-off-by: fuletian --- fs/hmdfs/inode.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/hmdfs/inode.c b/fs/hmdfs/inode.c index 1a03f3072378..f5a475585f4d 100644 --- a/fs/hmdfs/inode.c +++ b/fs/hmdfs/inode.c @@ -378,6 +378,7 @@ struct dentry *lookup_multi_dir(struct dentry *root_dentry, end = strchr(start, '/'); if (!end) end = start + strlen(start); + hmdfs_err("flt 2222 :: goto lookup_one_len name = %s, len = %d\n", start, end - start); ret_dentry = lookup_one_len(start, current_dentry, end - start); if (IS_ERR(ret_dentry)) { dput(current_dentry); -- Gitee From 72115969c8aefe45e37dd34d75d2f5a14ef083c0 Mon Sep 17 00:00:00 2001 From: fuletian Date: Tue, 15 Jul 2025 01:31:05 +0000 Subject: [PATCH 24/28] update fs/hmdfs/inode_cloud_merge.c. Signed-off-by: fuletian --- fs/hmdfs/inode_cloud_merge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index 80c3b5db7724..a5e337974c7b 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -321,7 +321,7 @@ static int lookup_cloud_merge_root(struct inode *root_inode, tmp_dentry->d_name.name, tmp_dentry->d_inode->i_ino, p_dentry, p_dentry->d_name.name); - dentry_dev = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); + dentry = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); if (dentry == NULL || IS_ERR(dentry)) { hmdfs_err("flt :: in cloud_merge_lookup_comrade lookup_multi_dir FAILED!"); if (dentry == NULL) { -- Gitee From 935f217e8d30c39300e940cf21df2e2fe3e00a77 Mon Sep 17 00:00:00 2001 From: fuletian Date: Tue, 15 Jul 2025 03:09:21 +0000 Subject: [PATCH 25/28] update fs/hmdfs/inode_cloud_merge.c. Signed-off-by: fuletian --- fs/hmdfs/inode_cloud_merge.c | 138 +++++++---------------------------- 1 file changed, 25 insertions(+), 113 deletions(-) diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index a5e337974c7b..629557ca316c 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -19,25 +19,6 @@ #include "authority/authentication.h" #include "hmdfs_trace.h" -struct hmdfs_dentry_comrade *cloud_lookup_comrade(struct path lower_path, - const char *d_name, - int dev_id, - unsigned int flags) -{ - struct path path; - 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); - - comrade = alloc_comrade(path.dentry, dev_id); - path_put(&path); - return comrade; -} - static struct inode *fill_inode_merge(struct super_block *sb, struct inode *parent_inode, struct dentry *child_dentry, @@ -113,54 +94,20 @@ cloud_merge_lookup_comrade(struct hmdfs_sb_info *sbi, int devid, unsigned int flags) { - int err; - struct path root, path; - struct hmdfs_dentry_comrade *comrade = NULL; - struct dentry *tmp_dentry = NULL; - struct dentry *p_dentry = NULL; struct dentry *dentry = NULL; - err = kern_path(sbi->real_dst, LOOKUP_DIRECTORY, &root); - if (err) { - comrade = ERR_PTR(err); - goto out; - } + struct hmdfs_dentry_comrade *comrade = NULL; - err = vfs_path_lookup(root.dentry, root.mnt, name, flags, &path); - if (err) { - comrade = ERR_PTR(err); - goto root_put; - } - tmp_dentry = path.dentry; - p_dentry = tmp_dentry->d_parent; - hmdfs_err("flt :: in cloud_merge_lookup_comrade BEFORE dentry_name = %s, node = %lu, d_parent = %x, parent_name = %s", - tmp_dentry->d_name.name, tmp_dentry->d_inode->i_ino, - p_dentry, p_dentry->d_name.name); - dentry = lookup_multi_dir(sbi->sb->s_root, name, flags); if (dentry == NULL || IS_ERR(dentry)) { - hmdfs_err("flt :: in cloud_merge_lookup_comrade lookup_multi_dir FAILED!"); - if (dentry == NULL) { - hmdfs_err("flt :: dentry == NULL"); - } else { - hmdfs_err("flt :: IS_ERR(dentry)"); - } - } else if (d_is_negative(dentry)) { + return ERR_PTR(PTR_ERR(dentry)); + } + if (d_is_negative(dentry)) { dput(dentry); - hmdfs_err("flt :: d_is_negative(dentry)"); - } else { - tmp_dentry = dentry; - p_dentry = tmp_dentry->d_parent; - hmdfs_err("flt :: in cloud_merge_lookup_comrade AFTER dentry_name = %s, node = %lu, d_parent = %x, parent_name = %s", - tmp_dentry->d_name.name, tmp_dentry->d_inode->i_ino, - p_dentry, p_dentry->d_name.name); - dput(dentry); - } - comrade = alloc_comrade(path.dentry, devid); - - path_put(&path); -root_put: - path_put(&root); -out: + return ERR_PTR(-ENOENT); + } + + comrade = alloc_comrade(dentry, devid); + dput(dentry); return comrade; } @@ -247,7 +194,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; @@ -262,7 +209,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 = cloud_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; @@ -271,7 +218,7 @@ static int do_lookup_cloud_merge_root(struct path path_dev, memcpy(buf, CLOUD_CID, 6); buf[5] = '\0'; - comrade = cloud_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; @@ -291,61 +238,26 @@ 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; - struct dentry *tmp_dentry = NULL; - struct dentry *p_dentry = NULL; - struct dentry *dentry = NULL; - - // 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; - tmp_dentry = path_dev.dentry; - p_dentry = tmp_dentry->d_parent; - hmdfs_err("flt :: in cloud_merge_lookup_comrade BEFORE dentry_name = %s, node = %lu, d_parent = %x, parent_name = %s", - tmp_dentry->d_name.name, tmp_dentry->d_inode->i_ino, - p_dentry, p_dentry->d_name.name); - - dentry = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); - if (dentry == NULL || IS_ERR(dentry)) { - hmdfs_err("flt :: in cloud_merge_lookup_comrade lookup_multi_dir FAILED!"); - if (dentry == NULL) { - hmdfs_err("flt :: dentry == NULL"); - } else { - hmdfs_err("flt :: IS_ERR(dentry)"); - } - } else if (d_is_negative(dentry)) { - dput(dentry); - hmdfs_err("flt :: d_is_negative(dentry)"); - } else { - tmp_dentry = dentry; - p_dentry = tmp_dentry->d_parent; - hmdfs_err("flt :: in cloud_merge_lookup_comrade AFTER dentry_name = %s, node = %lu, d_parent = %x, parent_name = %s", - tmp_dentry->d_name.name, tmp_dentry->d_inode->i_ino, - p_dentry, p_dentry->d_name.name); - dput(dentry); + dentry_dev = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); + if (dentry_dev == NULL || 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(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; } -- Gitee From 93c637ff7c501b63b5a497e97914dfe4b9275959 Mon Sep 17 00:00:00 2001 From: fuletian Date: Tue, 15 Jul 2025 08:05:30 +0000 Subject: [PATCH 26/28] update fs/hmdfs/inode_cloud_merge.c. Signed-off-by: fuletian --- fs/hmdfs/inode_cloud_merge.c | 139 +++++++++++++++++++++++++++++------ 1 file changed, 116 insertions(+), 23 deletions(-) diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index 629557ca316c..d4d247a50975 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -19,6 +19,25 @@ #include "authority/authentication.h" #include "hmdfs_trace.h" +struct hmdfs_dentry_comrade *cloud_lookup_comrade(struct path lower_path, + const char *d_name, + int dev_id, + unsigned int flags) +{ + struct path path; + 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); + + comrade = alloc_comrade(path.dentry, dev_id); + path_put(&path); + return comrade; +} + static struct inode *fill_inode_merge(struct super_block *sb, struct inode *parent_inode, struct dentry *child_dentry, @@ -94,20 +113,59 @@ cloud_merge_lookup_comrade(struct hmdfs_sb_info *sbi, int devid, unsigned int flags) { - struct dentry *dentry = NULL; + int err; + struct path root, path; struct hmdfs_dentry_comrade *comrade = NULL; + struct dentry *tmp_dentry = NULL; + struct dentry *p_dentry = NULL; + struct dentry *dentry = 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; + } + tmp_dentry = path.dentry; + p_dentry = tmp_dentry->d_parent; + hmdfs_err("flt :: in cloud_merge_lookup_comrade BEFORE dentry_name = %s, node = %lu, d_parent = %x, parent_name = %s", + tmp_dentry->d_name.name, tmp_dentry->d_inode->i_ino, + p_dentry, p_dentry->d_name.name); + dentry = lookup_multi_dir(sbi->sb->s_root, name, flags); if (dentry == NULL || IS_ERR(dentry)) { - return ERR_PTR(PTR_ERR(dentry)); - } - if (d_is_negative(dentry)) { + hmdfs_err("flt :: in cloud_merge_lookup_comrade lookup_multi_dir FAILED!"); + if (dentry == NULL) { + hmdfs_err("flt :: dentry == NULL"); + } else { + hmdfs_err("flt :: IS_ERR(dentry)"); + } + path_put(&path); + path_put(&root); + return ERR_PTR(-EINVAL); + } else if (d_is_negative(dentry)) { dput(dentry); - return ERR_PTR(-ENOENT); + hmdfs_err("flt :: d_is_negative(dentry)"); + path_put(&path); + path_put(&root); + return ERR_PTR(-ENOENT); + } else { + tmp_dentry = dentry; + p_dentry = tmp_dentry->d_parent; + hmdfs_err("flt :: in cloud_merge_lookup_comrade AFTER dentry_name = %s, node = %lu, d_parent = %x, parent_name = %s", + tmp_dentry->d_name.name, tmp_dentry->d_inode->i_ino, + p_dentry, p_dentry->d_name.name); } - comrade = alloc_comrade(dentry, devid); - dput(dentry); + dput(dentry); + path_put(&path); +root_put: + path_put(&root); +out: return comrade; } @@ -194,7 +252,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 dentry *dentry_dev, +static int do_lookup_cloud_merge_root(struct path path_dev, struct dentry *child_dentry, unsigned int flags) { struct hmdfs_dentry_comrade *comrade; @@ -209,7 +267,7 @@ static int do_lookup_cloud_merge_root(struct dentry *dentry_dev, // lookup real_dst/device_view/local memcpy(buf, DEVICE_VIEW_LOCAL, sizeof(DEVICE_VIEW_LOCAL)); - comrade = lookup_comrade(dentry_dev, buf, HMDFS_DEVID_LOCAL, flags); + comrade = cloud_lookup_comrade(path_dev, buf, HMDFS_DEVID_LOCAL, flags); if (IS_ERR(comrade)) { ret = PTR_ERR(comrade); goto out; @@ -218,7 +276,7 @@ static int do_lookup_cloud_merge_root(struct dentry *dentry_dev, memcpy(buf, CLOUD_CID, 6); buf[5] = '\0'; - comrade = lookup_comrade(dentry_dev, buf, CLOUD_DEVICE, flags); + comrade = cloud_lookup_comrade(path_dev, buf, CLOUD_DEVICE, flags); if (IS_ERR(comrade)) { ret = 0; goto out; @@ -238,26 +296,61 @@ 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 dentry *dentry_dev = NULL; + struct path path_dev; int ret = -ENOENT; + int buf_len; + char *buf = NULL; bool locked, down; + struct dentry *tmp_dentry = NULL; + struct dentry *p_dentry = NULL; + struct dentry *dentry = NULL; + + // 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); - dentry_dev = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); - if (dentry_dev == NULL || 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 = hmdfs_get_path_in_sb(child_dentry->d_sb, buf, LOOKUP_DIRECTORY, + &path_dev); + if (ret) + goto free_buf; + tmp_dentry = path_dev.dentry; + p_dentry = tmp_dentry->d_parent; + hmdfs_err("flt :: in cloud_merge_lookup_comrade BEFORE dentry_name = %s, node = %lu, d_parent = %x, parent_name = %s", + tmp_dentry->d_name.name, tmp_dentry->d_inode->i_ino, + p_dentry, p_dentry->d_name.name); + + dentry = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); + if (dentry == NULL || IS_ERR(dentry)) { + hmdfs_err("flt :: in cloud_merge_lookup_comrade lookup_multi_dir FAILED!"); + if (dentry == NULL) { + hmdfs_err("flt :: dentry == NULL"); + } else { + hmdfs_err("flt :: IS_ERR(dentry)"); + } + } else if (d_is_negative(dentry)) { + dput(dentry); + hmdfs_err("flt :: d_is_negative(dentry)"); + } else { + tmp_dentry = dentry; + p_dentry = tmp_dentry->d_parent; + hmdfs_err("flt :: in cloud_merge_lookup_comrade AFTER dentry_name = %s, node = %lu, d_parent = %x, parent_name = %s", + tmp_dentry->d_name.name, tmp_dentry->d_inode->i_ino, + p_dentry, p_dentry->d_name.name); + dput(dentry); } - ret = do_lookup_cloud_merge_root(dentry_dev, child_dentry, flags); - dput(dentry_dev); + ret = do_lookup_cloud_merge_root(path_dev, child_dentry, flags); + path_put(&path_dev); -out: +free_buf: + kfree(buf); restore_root_inode_sem(root_inode, locked, down); return ret; } -- Gitee From f34282206b0dc51c81d9d64574347ffe24ee589c Mon Sep 17 00:00:00 2001 From: fuletian Date: Tue, 15 Jul 2025 11:48:11 +0000 Subject: [PATCH 27/28] update fs/hmdfs/inode_cloud_merge.c. Signed-off-by: fuletian --- fs/hmdfs/inode_cloud_merge.c | 62 ++++++------------------------------ 1 file changed, 9 insertions(+), 53 deletions(-) diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index d4d247a50975..de33f3503544 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -113,59 +113,20 @@ cloud_merge_lookup_comrade(struct hmdfs_sb_info *sbi, int devid, unsigned int flags) { - int err; - struct path root, path; - struct hmdfs_dentry_comrade *comrade = NULL; - struct dentry *tmp_dentry = NULL; - struct dentry *p_dentry = NULL; struct dentry *dentry = NULL; - err = kern_path(sbi->real_dst, LOOKUP_DIRECTORY, &root); - if (err) { - comrade = ERR_PTR(err); - goto out; - } + struct hmdfs_dentry_comrade *comrade = NULL; - err = vfs_path_lookup(root.dentry, root.mnt, name, flags, &path); - if (err) { - comrade = ERR_PTR(err); - goto root_put; - } - tmp_dentry = path.dentry; - p_dentry = tmp_dentry->d_parent; - hmdfs_err("flt :: in cloud_merge_lookup_comrade BEFORE dentry_name = %s, node = %lu, d_parent = %x, parent_name = %s", - tmp_dentry->d_name.name, tmp_dentry->d_inode->i_ino, - p_dentry, p_dentry->d_name.name); - dentry = lookup_multi_dir(sbi->sb->s_root, name, flags); - if (dentry == NULL || IS_ERR(dentry)) { - hmdfs_err("flt :: in cloud_merge_lookup_comrade lookup_multi_dir FAILED!"); - if (dentry == NULL) { - hmdfs_err("flt :: dentry == NULL"); - } else { - hmdfs_err("flt :: IS_ERR(dentry)"); - } - path_put(&path); - path_put(&root); - return ERR_PTR(-EINVAL); - } else if (d_is_negative(dentry)) { + if (IS_ERR(dentry)) { + return ERR_PTR(PTR_ERR(dentry)); + } + if (d_is_negative(dentry)) { dput(dentry); - hmdfs_err("flt :: d_is_negative(dentry)"); - path_put(&path); - path_put(&root); - return ERR_PTR(-ENOENT); - } else { - tmp_dentry = dentry; - p_dentry = tmp_dentry->d_parent; - hmdfs_err("flt :: in cloud_merge_lookup_comrade AFTER dentry_name = %s, node = %lu, d_parent = %x, parent_name = %s", - tmp_dentry->d_name.name, tmp_dentry->d_inode->i_ino, - p_dentry, p_dentry->d_name.name); + return ERR_PTR(-ENOENT); } + comrade = alloc_comrade(dentry, devid); - dput(dentry); - path_put(&path); -root_put: - path_put(&root); -out: + dput(dentry); return comrade; } @@ -327,13 +288,8 @@ static int lookup_cloud_merge_root(struct inode *root_inode, p_dentry, p_dentry->d_name.name); dentry = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); - if (dentry == NULL || IS_ERR(dentry)) { + if (IS_ERR(dentry)) { hmdfs_err("flt :: in cloud_merge_lookup_comrade lookup_multi_dir FAILED!"); - if (dentry == NULL) { - hmdfs_err("flt :: dentry == NULL"); - } else { - hmdfs_err("flt :: IS_ERR(dentry)"); - } } else if (d_is_negative(dentry)) { dput(dentry); hmdfs_err("flt :: d_is_negative(dentry)"); -- Gitee From 2c6fcfe775e0ee34e851f604c659586ce87848df Mon Sep 17 00:00:00 2001 From: fuletian Date: Tue, 15 Jul 2025 12:34:34 +0000 Subject: [PATCH 28/28] update fs/hmdfs/inode_cloud_merge.c. Signed-off-by: fuletian --- fs/hmdfs/inode_cloud_merge.c | 139 ++++++++++++----------------------- 1 file changed, 48 insertions(+), 91 deletions(-) diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index de33f3503544..593672e2cdee 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -19,25 +19,6 @@ #include "authority/authentication.h" #include "hmdfs_trace.h" -struct hmdfs_dentry_comrade *cloud_lookup_comrade(struct path lower_path, - const char *d_name, - int dev_id, - unsigned int flags) -{ - struct path path; - 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); - - comrade = alloc_comrade(path.dentry, dev_id); - path_put(&path); - return comrade; -} - static struct inode *fill_inode_merge(struct super_block *sb, struct inode *parent_inode, struct dentry *child_dentry, @@ -113,20 +94,28 @@ cloud_merge_lookup_comrade(struct hmdfs_sb_info *sbi, int devid, unsigned int flags) { - struct dentry *dentry = NULL; + int err; + struct path root, path; struct hmdfs_dentry_comrade *comrade = NULL; - dentry = lookup_multi_dir(sbi->sb->s_root, name, flags); - if (IS_ERR(dentry)) { - return ERR_PTR(PTR_ERR(dentry)); + err = kern_path(sbi->real_dst, LOOKUP_DIRECTORY, &root); + if (err) { + comrade = ERR_PTR(err); + goto out; } - if (d_is_negative(dentry)) { - dput(dentry); - return ERR_PTR(-ENOENT); + + 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: return comrade; } @@ -213,7 +202,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; @@ -228,7 +217,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 = cloud_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; @@ -237,7 +226,7 @@ static int do_lookup_cloud_merge_root(struct path path_dev, memcpy(buf, CLOUD_CID, 6); buf[5] = '\0'; - comrade = cloud_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; @@ -257,56 +246,26 @@ 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; - struct dentry *tmp_dentry = NULL; - struct dentry *p_dentry = NULL; - struct dentry *dentry = NULL; - // 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; - tmp_dentry = path_dev.dentry; - p_dentry = tmp_dentry->d_parent; - hmdfs_err("flt :: in cloud_merge_lookup_comrade BEFORE dentry_name = %s, node = %lu, d_parent = %x, parent_name = %s", - tmp_dentry->d_name.name, tmp_dentry->d_inode->i_ino, - p_dentry, p_dentry->d_name.name); - - dentry = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); - if (IS_ERR(dentry)) { - hmdfs_err("flt :: in cloud_merge_lookup_comrade lookup_multi_dir FAILED!"); - } else if (d_is_negative(dentry)) { - dput(dentry); - hmdfs_err("flt :: d_is_negative(dentry)"); - } else { - tmp_dentry = dentry; - p_dentry = tmp_dentry->d_parent; - hmdfs_err("flt :: in cloud_merge_lookup_comrade AFTER dentry_name = %s, node = %lu, d_parent = %x, parent_name = %s", - tmp_dentry->d_name.name, tmp_dentry->d_inode->i_ino, - p_dentry, p_dentry->d_name.name); - dput(dentry); + dentry_dev = lookup_multi_dir(sbi->sb->s_root, DEVICE_VIEW_ROOT, flags); + if (dentry_dev == NULL || 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(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; } @@ -448,7 +407,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; @@ -458,20 +417,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) @@ -490,7 +449,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)) { @@ -503,28 +461,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); - if (IS_ERR(lo_d_child)) { + lo_d_child = lookup_multi_dir(sbi->sb->s_root, absolute_path_buf, 0); + if (lo_d_child == NULL || IS_ERR(lo_d_child)) { ret = PTR_ERR(lo_d_child); goto out; } + if (d_is_positive(lo_d_child)) { + ret = -EEXIST; + goto out_put; + } // 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); @@ -538,7 +495,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); -- Gitee