From 1c4e6829cdb0335ae6e6580ff645368fa6a6f768 Mon Sep 17 00:00:00 2001 From: gueFDF <3237455241@qq.com> Date: Tue, 19 Sep 2023 19:52:10 +0800 Subject: [PATCH] add: dcache parametersupport and file system improvement --- 0003-file-system-improvement.patch | 967 ++++++++++++++++++++++++ 0004-add-dcache-parameter-support.patch | 49 ++ 2 files changed, 1016 insertions(+) create mode 100644 0003-file-system-improvement.patch create mode 100644 0004-add-dcache-parameter-support.patch diff --git a/0003-file-system-improvement.patch b/0003-file-system-improvement.patch new file mode 100644 index 0000000..762d8ec --- /dev/null +++ b/0003-file-system-improvement.patch @@ -0,0 +1,967 @@ +diff --git a/authority/authentication.c b/authority/authentication.c +index 076e738..51f46c8 100644 +--- a/authority/authentication.c ++++ b/authority/authentication.c +@@ -219,8 +219,8 @@ int hmdfs_persist_perm(struct dentry *dentry, __u16 *perm) + return -EINVAL; + + inode_lock(minode); +- err = __vfs_setxattr(dentry, minode, HMDFS_PERM_XATTR, perm, +- sizeof(*perm), XATTR_CREATE); ++ err = __vfs_setxattr(&nop_mnt_idmap, dentry, minode, HMDFS_PERM_XATTR, perm, ++ sizeof(*perm), XATTR_CREATE); + if (!err) + fsnotify_xattr(dentry); + else if (err && err != -EEXIST) +diff --git a/comm/device_node.c b/comm/device_node.c +index 0f2585d..8771285 100644 +--- a/comm/device_node.c ++++ b/comm/device_node.c +@@ -1288,6 +1288,10 @@ static struct attribute *sbi_attrs[] = { + NULL, + }; + ++static struct attribute_group sbi_attribute_group = { ++ .attrs = sbi_attrs, ++}; ++ + static ssize_t sbi_attr_show(struct kobject *kobj, struct attribute *attr, + char *buf) + { +@@ -1322,7 +1326,10 @@ static void sbi_release(struct kobject *kobj) + + static struct kobj_type sbi_ktype = { + .sysfs_ops = &sbi_sysfs_ops, +- .default_attrs = sbi_attrs, ++ .default_groups = (const struct attribute_group *[]) { ++ &sbi_attribute_group, ++ NULL, ++ }, + .release = sbi_release, + }; + +@@ -1404,6 +1411,10 @@ static struct attribute *sbi_timeout_attrs[] = { + NULL + }; + ++static struct attribute_group sbi_timeout_group = { ++ .attrs = sbi_timeout_attrs, ++}; ++ + static const struct sysfs_ops sbi_cmd_sysfs_ops = { + .show = cmd_timeout_show, + .store = cmd_timeout_store, +@@ -1419,7 +1430,11 @@ static void sbi_timeout_release(struct kobject *kobj) + + static struct kobj_type sbi_timeout_ktype = { + .sysfs_ops = &sbi_cmd_sysfs_ops, +- .default_attrs = sbi_timeout_attrs, ++ .default_groups = (const struct attribute_group *[]) { ++ &sbi_timeout_group, ++ NULL, ++ }, ++ // .default_groups = &sbi_timeout_group, + .release = sbi_timeout_release, + }; + +@@ -1606,6 +1621,11 @@ static struct attribute *peer_attrs[] = { + NULL, + }; + ++ ++static struct attribute_group peer_group = { ++ .attrs = peer_attrs, ++}; ++ + static ssize_t peer_attr_show(struct kobject *kobj, struct attribute *attr, + char *buf) + { +@@ -1640,7 +1660,11 @@ static void peer_sysfs_release(struct kobject *kobj) + + static struct kobj_type peer_ktype = { + .sysfs_ops = &peer_sysfs_ops, +- .default_attrs = peer_attrs, ++ //.default_groups = &peer_group, ++ .default_groups = (const struct attribute_group *[]) { ++ &peer_group, ++ NULL, ++ }, + .release = peer_sysfs_release, + }; + +diff --git a/file_merge.c b/file_merge.c +index e7b75b6..3b506a9 100644 +--- a/file_merge.c ++++ b/file_merge.c +@@ -199,7 +199,7 @@ static void rename_conflicting_directory(char *dentry_name, int *len) + *len += strlen(CONFLICTING_DIR_SUFFIX); + } + +-static int hmdfs_actor_merge(struct dir_context *ctx, const char *name, ++static bool hmdfs_actor_merge(struct dir_context *ctx, const char *name, + int namelen, loff_t offset, u64 ino, + unsigned int d_type) + { +@@ -213,13 +213,13 @@ static int hmdfs_actor_merge(struct dir_context *ctx, const char *name, + struct dir_context *org_ctx = NULL; + + if (hmdfs_file_type(name) != HMDFS_TYPE_COMMON) +- return 0; ++ return true; + + if (namelen > NAME_MAX) +- return -EINVAL; ++ return false; + dentry_name = kzalloc(NAME_MAX + 1, GFP_KERNEL); + if (!dentry_name) +- return -ENOMEM; ++ return false; + + strncpy(dentry_name, name, dentry_len); + +@@ -270,7 +270,7 @@ delete: + delete_filename(iterate_callback_merge->root, cache_entry); + done: + kfree(dentry_name); +- return ret; ++ return ret==0; + } + + struct hmdfs_file_info * +diff --git a/file_remote.c b/file_remote.c +index f9a77dd..81ba692 100644 +--- a/file_remote.c ++++ b/file_remote.c +@@ -793,7 +793,7 @@ static int hmdfs_write_begin_remote(struct file *file, + int ret = 0; + + start: +- page = grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); ++ page = grab_cache_page_write_begin(mapping, index); + if (!page) + return -ENOMEM; + *pagep = page; +@@ -818,9 +818,9 @@ start: + ret = hmdfs_readpage_remote(file, page); + if (!ret) { + if (PageLocked(page)) { +- ret = __lock_page_killable(page); ++ // ret = __lock_page_killable(page); //? + if (!ret) +- unlock_page(page); ++ unlock_page(page); + } + + if (!ret && PageUptodate(page)) { +diff --git a/hmdfs.h b/hmdfs.h +index 45fcf9f..4dba2b0 100644 +--- a/hmdfs.h ++++ b/hmdfs.h +@@ -5,8 +5,8 @@ + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + */ + +-#ifndef HMDFS_H +-#define HMDFS_H ++#ifndef HMDFS ++#define HMDFS + + #include + #include +@@ -277,7 +277,7 @@ extern ssize_t hmdfs_remote_listxattr(struct dentry *dentry, char *buffer, + + int check_filename(const char *name, int len); + +-int hmdfs_permission(struct inode *inode, int mask); ++int hmdfs_permission(struct mnt_idmap *idmp, struct inode *inode, int mask); + + int hmdfs_parse_options(struct hmdfs_sb_info *sbi, const char *data); + +@@ -342,4 +342,4 @@ extern const struct inode_operations hmdfs_root_ops; + extern const struct file_operations hmdfs_root_fops; + extern const struct file_operations hmdfs_device_fops; + +-#endif // HMDFS_H ++#endif /* HMDFS */ +diff --git a/hmdfs_dentryfile.c b/hmdfs_dentryfile.c +index 1a65e3f..6c3596e 100644 +--- a/hmdfs_dentryfile.c ++++ b/hmdfs_dentryfile.c +@@ -14,6 +14,7 @@ + #include + #include + #include ++#include + + #include "authority/authentication.h" + #include "comm/transport.h" +@@ -1067,7 +1068,7 @@ static int hmdfs_linkat(struct path *old_path, const char *newname) + if (old_path->mnt != new_path.mnt) + goto out_dput; + +- error = vfs_link(old_path->dentry, new_path.dentry->d_inode, new_dentry, ++ error = vfs_link(old_path->dentry, &nop_mnt_idmap, new_path.dentry->d_inode, new_dentry, + NULL); + + out_dput: +@@ -1085,7 +1086,7 @@ static int cache_file_mkdir(const char *name, umode_t mode) + if (IS_ERR(dentry)) + return PTR_ERR(dentry); + +- err = vfs_mkdir(d_inode(path.dentry), dentry, mode); ++ err = vfs_mkdir(&nop_mnt_idmap, d_inode(path.dentry), dentry, mode); + if (err && err != -EEXIST) + hmdfs_err("vfs_mkdir failed, err = %d", err); + +@@ -1328,7 +1329,7 @@ struct file *cache_file_persistent(struct hmdfs_peer *con, struct file *filp, + if (err) + goto out; + +- err = __vfs_setxattr(file_dentry(filp), file_inode(filp), ++ err = __vfs_setxattr(&nop_mnt_idmap, file_dentry(filp), file_inode(filp), + DENTRY_FILE_XATTR_NAME, relative_path, + strlen(relative_path), 0); + if (err) { +@@ -1673,7 +1674,7 @@ out: + kfree(fullname); + } + +-static int cache_file_iterate(struct dir_context *ctx, const char *name, ++static bool cache_file_iterate(struct dir_context *ctx, const char *name, + int name_len, loff_t offset, u64 ino, + unsigned int d_type) + { +@@ -1683,25 +1684,25 @@ static int cache_file_iterate(struct dir_context *ctx, const char *name, + + if (name_len > NAME_MAX) { + hmdfs_err("name_len:%d NAME_MAX:%u", name_len, NAME_MAX); +- return 0; ++ return true; + } + + if (d_type != DT_REG) +- return 0; ++ return true; + + cfi = kmalloc(sizeof(*cfi), GFP_KERNEL); + if (!cfi) +- return -ENOMEM; ++ return false; + + cfi->name = kstrndup(name, name_len, GFP_KERNEL); + if (!cfi->name) { + kfree(cfi); +- return -ENOMEM; ++ return false; + } + + list_add_tail(&cfi->list, &cb->list); + +- return 0; ++ return true; + } + + void hmdfs_do_load(struct hmdfs_sb_info *sbi, const char *fullname, bool server) +@@ -1760,7 +1761,7 @@ int delete_dentry_file(struct file *filp) + + if (dentry->d_parent == parent) { + dget(dentry); +- err = vfs_unlink(d_inode(parent), dentry, NULL); ++ err = vfs_unlink(&nop_mnt_idmap, d_inode(parent), dentry, NULL); + dput(dentry); + } + unlock_dir(parent); +@@ -2379,6 +2380,7 @@ static void hmdfs_rename_bak(struct dentry *dentry) + char *name = NULL; + int len = 0; + int err = 0; ++ struct renamedata rd; + + hmdfs_get_lower_path(dentry, &lower_path); + lower_dentry = lower_path.dentry; +@@ -2409,8 +2411,19 @@ static void hmdfs_rename_bak(struct dentry *dentry) + goto unlock_parent; + } + +- err = vfs_rename(d_inode(lower_parent), lower_dentry, +- d_inode(lower_parent), new_dentry, NULL, 0); ++ rd.old_mnt_idmap = &nop_mnt_idmap; ++ rd.old_dir = d_inode(lower_parent); ++ rd.old_dentry = lower_dentry; ++ rd.new_mnt_idmap = &nop_mnt_idmap; ++ rd.new_dir = d_inode(lower_parent); ++ rd.new_dentry = new_dentry; ++ rd.delegated_inode = NULL; ++ rd.flags = 0; ++ ++ // err = vfs_rename(d_inode(lower_parent), lower_dentry, ++ // d_inode(lower_parent), new_dentry, NULL, 0); ++ ++ err = vfs_rename(&rd); + + dput(new_dentry); + unlock_parent: +@@ -2464,7 +2477,7 @@ int hmdfs_root_unlink(uint64_t device_id, struct path *root_path, + + hmdfs_mark_drop_flag(device_id, path.dentry); + ihold(child_inode); +- err = vfs_unlink(dir, child_dentry, NULL); ++ err = vfs_unlink(&nop_mnt_idmap, dir, child_dentry, NULL); + /* + * -EOWNERDEAD means we want to put the file in a specail dir instead of + * deleting it, specifically dustbin in phone, so that user can +@@ -2517,7 +2530,7 @@ struct dentry *hmdfs_root_mkdir(uint64_t device_id, const char *local_dst_path, + } + + hmdfs_mark_drop_flag(device_id, child_dentry->d_parent); +- err = vfs_mkdir(d_inode(path.dentry), child_dentry, mode); ++ err = vfs_mkdir(&nop_mnt_idmap, d_inode(path.dentry), child_dentry, mode); + if (err) { + hmdfs_err("mkdir failed! err=%d", err); + ret = ERR_PTR(err); +@@ -2562,7 +2575,7 @@ struct dentry *hmdfs_root_create(uint64_t device_id, const char *local_dst_path, + goto out; + } + hmdfs_mark_drop_flag(device_id, child_dentry->d_parent); +- err = vfs_create(d_inode(path.dentry), child_dentry, mode, want_excl); ++ err = vfs_create(&nop_mnt_idmap, d_inode(path.dentry), child_dentry, mode, want_excl); + if (err) { + hmdfs_err("path create failed! err=%d", err); + ret = ERR_PTR(err); +@@ -2608,7 +2621,7 @@ int hmdfs_root_rmdir(uint64_t device_id, struct path *root_path, + } + + hmdfs_mark_drop_flag(device_id, path.dentry); +- err = vfs_rmdir(dir, child_dentry); ++ err = vfs_rmdir(&nop_mnt_idmap, dir, child_dentry); + if (err) + hmdfs_err("rmdir failed err = %d", err); + dput(child_dentry); +@@ -2631,6 +2644,7 @@ int hmdfs_root_rename(struct hmdfs_sb_info *sbi, uint64_t device_id, + struct dentry *trap = NULL; + struct dentry *old_dentry = NULL; + struct dentry *new_dentry = NULL; ++ struct renamedata rd; + + err = kern_path(sbi->local_dst, 0, &path_dst); + if (err) { +@@ -2699,8 +2713,20 @@ int hmdfs_root_rename(struct hmdfs_sb_info *sbi, uint64_t device_id, + if (path_old.dentry != path_new.dentry) + hmdfs_mark_drop_flag(device_id, path_new.dentry); + +- err = vfs_rename(d_inode(path_old.dentry), old_dentry, +- d_inode(path_new.dentry), new_dentry, NULL, 0); ++ ++ rd.old_mnt_idmap = &nop_mnt_idmap; ++ rd.old_dir = d_inode(path_old.dentry); ++ rd.old_dentry = old_dentry; ++ rd.new_mnt_idmap = &nop_mnt_idmap; ++ rd.new_dir = d_inode(path_new.dentry); ++ rd.new_dentry = new_dentry; ++ rd.delegated_inode = NULL; ++ rd.flags = 0; ++ ++ // err = vfs_rename(d_inode(path_old.dentry), old_dentry, ++ // d_inode(path_new.dentry), new_dentry, NULL, 0); ++ ++ err = vfs_rename(&rd); + + put_new_dentry: + dput(new_dentry); +diff --git a/hmdfs_server.c b/hmdfs_server.c +index fc02742..ffec3ca 100644 +--- a/hmdfs_server.c ++++ b/hmdfs_server.c +@@ -208,7 +208,7 @@ static int check_sec_level(struct hmdfs_peer *node, const char *file_name) + goto out_err; + } + +- err = vfs_getxattr(file_path.dentry, DATA_SEC_LEVEL_LABEL, value, ++ err = vfs_getxattr(&nop_mnt_idmap, file_path.dentry, DATA_SEC_LEVEL_LABEL, value, + value_len); + if (err <= 0 && node->devsl >= DATA_SEC_LEVEL3) + goto out; +@@ -470,7 +470,7 @@ static int hmdfs_check_and_create(struct path *path_parent, + /* if inode doesn't exist, create it */ + if (d_is_negative(dentry)) { + hmdfs_mark_drop_flag(device_id, path_parent->dentry); +- err = vfs_create(d_inode(path_parent->dentry), dentry, mode, ++ err = vfs_create(&nop_mnt_idmap, d_inode(path_parent->dentry), dentry, mode, + is_excl); + if (err) + hmdfs_err("create failed, err %d", err); +@@ -1299,7 +1299,7 @@ void hmdfs_server_rename(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, + hmdfs_send_err_response(con, cmd, err); + } + +-static int hmdfs_filldir_real(struct dir_context *ctx, const char *name, ++static bool hmdfs_filldir_real(struct dir_context *ctx, const char *name, + int name_len, loff_t offset, u64 ino, + unsigned int d_type) + { +@@ -1348,7 +1348,7 @@ out: + * we always return 0 here, so that the caller can continue to next + * dentry even if failed on this dentry somehow. + */ +- return 0; ++ return true; + } + + static void hmdfs_server_set_header(struct hmdfs_dcache_header *header, +@@ -1491,7 +1491,7 @@ static struct inode *hmdfs_verify_path(struct dentry *dentry, char *recv_buf, + return NULL; + } + +-static int hmdfs_notify_change(struct vfsmount *mnt, struct dentry *dentry, ++static int hmdfs_notify_change(struct mnt_idmap *idmp, struct vfsmount *mnt, struct dentry *dentry, + struct iattr *attr, + struct inode **delegated_inode) + { +@@ -1499,7 +1499,7 @@ static int hmdfs_notify_change(struct vfsmount *mnt, struct dentry *dentry, + /* sdcard_fs need to call setattr2, notify_change will call setattr */ + return notify_change2(mnt, dentry, attr, delegated_inode); + #else +- return notify_change(dentry, attr, delegated_inode); ++ return notify_change(&nop_mnt_idmap, dentry, attr, delegated_inode); + #endif + } + +@@ -1547,7 +1547,7 @@ void hmdfs_server_setattr(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, + attr.ia_mtime.tv_nsec = le32_to_cpu(recv->mtime_nsec); + + inode_lock(dentry->d_inode); +- err = hmdfs_notify_change(dst_path.mnt, dentry, &attr, NULL); ++ err = hmdfs_notify_change(&nop_mnt_idmap, dst_path.mnt, dentry, &attr, NULL); + inode_unlock(dentry->d_inode); + + out_put_dst: +@@ -1779,9 +1779,9 @@ void hmdfs_server_getxattr(struct hmdfs_peer *con, + } + + if (!size) +- err = vfs_getxattr(path.dentry, name, NULL, size); ++ err = vfs_getxattr(&nop_mnt_idmap, path.dentry, name, NULL, size); + else +- err = vfs_getxattr(path.dentry, name, resp->value, size); ++ err = vfs_getxattr(&nop_mnt_idmap, path.dentry, name, resp->value, size); + if (err < 0) { + hmdfs_info("getxattr failed err %d", err); + goto err_put_path; +@@ -1836,9 +1836,9 @@ void hmdfs_server_setxattr(struct hmdfs_peer *con, + + if (del) { + WARN_ON(flags != XATTR_REPLACE); +- err = vfs_removexattr(path.dentry, name); ++ err = vfs_removexattr(&nop_mnt_idmap, path.dentry, name); + } else { +- err = vfs_setxattr(path.dentry, name, value, size, flags); ++ err = vfs_setxattr(&nop_mnt_idmap, path.dentry, name, value, size, flags); + } + + path_put(&path); +diff --git a/inode_local.c b/inode_local.c +index 2470c5f..a70d0e8 100644 +--- a/inode_local.c ++++ b/inode_local.c +@@ -159,7 +159,7 @@ int hmdfs_convert_lookup_flags(unsigned int hmdfs_flags, + return 0; + } + +-static int hmdfs_name_match(struct dir_context *ctx, const char *name, ++static bool hmdfs_name_match(struct dir_context *ctx, const char *name, + int namelen, loff_t offset, u64 ino, + unsigned int d_type) + { +@@ -171,9 +171,9 @@ static int hmdfs_name_match(struct dir_context *ctx, const char *name, + memcpy(buf->name, name, namelen); + buf->name[namelen] = 0; + buf->found = true; +- return 1; ++ return false; + } +- return 0; ++ return true; + } + + static int __lookup_nosensitive(struct path *lower_parent_path, +@@ -332,7 +332,7 @@ int hmdfs_mkdir_local_dentry(struct inode *dir, struct dentry *dentry, + tmp_uid = hmdfs_override_inode_uid(lower_dir); + mode = (mode & S_IFMT) | 00771; + +- error = vfs_mkdir(lower_dir, lower_dentry, mode); ++ error = vfs_mkdir(&nop_mnt_idmap, lower_dir, lower_dentry, mode); + hmdfs_revert_inode_uid(lower_dir, tmp_uid); + if (error) { + hmdfs_err("vfs_mkdir() error:%d", error); +@@ -365,7 +365,7 @@ cleanup: + return error; + } + +-int hmdfs_mkdir_local(struct inode *dir, struct dentry *dentry, umode_t mode) ++int hmdfs_mkdir_local(struct mnt_idmap *idmp, struct inode *dir, struct dentry *dentry, umode_t mode) + { + int err = 0; + +@@ -421,7 +421,7 @@ int hmdfs_create_local_dentry(struct inode *dir, struct dentry *dentry, + lower_dir_dentry = lock_parent(lower_dentry); + lower_dir = d_inode(lower_dir_dentry); + tmp_uid = hmdfs_override_inode_uid(lower_dir); +- error = vfs_create(lower_dir, lower_dentry, mode, want_excl); ++ error = vfs_create(&nop_mnt_idmap, lower_dir, lower_dentry, mode, want_excl); + hmdfs_revert_inode_uid(lower_dir, tmp_uid); + unlock_dir(lower_dir_dentry); + if (error) +@@ -458,7 +458,7 @@ path_err: + return error; + } + +-int hmdfs_create_local(struct inode *dir, struct dentry *child_dentry, ++int hmdfs_create_local(struct mnt_idmap *idmp, struct inode *dir, struct dentry *child_dentry, + umode_t mode, bool want_excl) + { + int err = 0; +@@ -495,7 +495,7 @@ int hmdfs_rmdir_local_dentry(struct inode *dir, struct dentry *dentry) + lower_dir = d_inode(lower_dir_dentry); + tmp_uid = hmdfs_override_inode_uid(lower_dir); + +- error = vfs_rmdir(lower_dir, lower_dentry); ++ error = vfs_rmdir(&nop_mnt_idmap, lower_dir, lower_dentry); + hmdfs_revert_inode_uid(lower_dir, tmp_uid); + unlock_dir(lower_dir_dentry); + hmdfs_put_lower_path(&lower_path); +@@ -548,7 +548,7 @@ int hmdfs_unlink_local_dentry(struct inode *dir, struct dentry *dentry) + dget(lower_dentry); + lower_dir_dentry = lock_parent(lower_dentry); + tmp_uid = hmdfs_override_inode_uid(lower_dir); +- error = vfs_unlink(lower_dir, lower_dentry, NULL); ++ error = vfs_unlink(&nop_mnt_idmap, lower_dir, lower_dentry, NULL); + hmdfs_revert_inode_uid(lower_dir, tmp_uid); + set_nlink(d_inode(dentry), + hmdfs_i(d_inode(dentry))->lower_inode->i_nlink); +@@ -587,6 +587,7 @@ int hmdfs_rename_local_dentry(struct inode *old_dir, struct dentry *old_dentry, + struct dentry *lower_new_dir_dentry = NULL; + struct dentry *trap = NULL; + int rc = 0; ++ struct renamedata rd; + kuid_t old_dir_uid, new_dir_uid; + + if (flags) +@@ -625,9 +626,20 @@ int hmdfs_rename_local_dentry(struct inode *old_dir, struct dentry *old_dentry, + goto out_lock; + } + +- rc = vfs_rename(d_inode(lower_old_dir_dentry), lower_old_dentry, +- d_inode(lower_new_dir_dentry), lower_new_dentry, NULL, +- flags); ++ rd.old_mnt_idmap = &nop_mnt_idmap; ++ rd.old_dir = d_inode(lower_old_dir_dentry); ++ rd.old_dentry = lower_old_dentry; ++ rd.new_mnt_idmap = &nop_mnt_idmap; ++ rd.new_dir = d_inode(lower_new_dir_dentry); ++ rd.new_dentry = lower_new_dentry; ++ rd.delegated_inode = NULL; ++ rd.flags = flags; ++ ++ // rc = vfs_rename(d_inode(lower_old_dir_dentry), lower_old_dentry, ++ // d_inode(lower_new_dir_dentry), lower_new_dentry, NULL, ++ // flags); ++ ++ rc = vfs_rename(&rd); + out_lock: + dget(old_dentry); + +@@ -657,7 +669,7 @@ out_put_old_path: + return rc; + } + +-int hmdfs_rename_local(struct inode *old_dir, struct dentry *old_dentry, ++int hmdfs_rename_local(struct mnt_idmap *idmp, struct inode *old_dir, struct dentry *old_dentry, + struct inode *new_dir, struct dentry *new_dentry, + unsigned int flags) + { +@@ -691,7 +703,7 @@ rename_out: + return err; + } + +-static int hmdfs_setattr_local(struct dentry *dentry, struct iattr *ia) ++static int hmdfs_setattr_local(struct mnt_idmap *idmp, struct dentry *dentry, struct iattr *ia) + { + struct inode *inode = d_inode(dentry); + struct inode *lower_inode = hmdfs_i(inode)->lower_inode; +@@ -717,7 +729,7 @@ static int hmdfs_setattr_local(struct dentry *dentry, struct iattr *ia) + inode_lock(lower_inode); + tmp_uid = hmdfs_override_inode_uid(lower_inode); + +- err = notify_change(lower_dentry, &lower_ia, NULL); ++ err = notify_change(&nop_mnt_idmap, lower_dentry, &lower_ia, NULL); + i_size_write(inode, i_size_read(lower_inode)); + inode->i_atime = lower_inode->i_atime; + inode->i_mtime = lower_inode->i_mtime; +@@ -731,7 +743,7 @@ out: + return err; + } + +-static int hmdfs_getattr_local(const struct path *path, struct kstat *stat, ++static int hmdfs_getattr_local(struct mnt_idmap *idmp, const struct path *path, struct kstat *stat, + u32 request_mask, unsigned int flags) + { + struct path lower_path; +@@ -747,7 +759,7 @@ static int hmdfs_getattr_local(const struct path *path, struct kstat *stat, + return ret; + } + +-int hmdfs_permission(struct inode *inode, int mask) ++int hmdfs_permission(struct mnt_idmap *idmp, struct inode *inode, int mask) + { + #ifdef CONFIG_HMDFS_FS_PERMISSION + unsigned int mode = inode->i_mode; +diff --git a/inode_merge.c b/inode_merge.c +index ab6ea96..52a9b75 100644 +--- a/inode_merge.c ++++ b/inode_merge.c +@@ -785,7 +785,7 @@ out: + return err ? ERR_PTR(err) : ret_dentry; + } + +-static int hmdfs_getattr_merge(const struct path *path, struct kstat *stat, ++static int hmdfs_getattr_merge(struct mnt_idmap *idmap, const struct path *path, struct kstat *stat, + u32 request_mask, unsigned int flags) + { + int ret; +@@ -806,7 +806,7 @@ out: + return ret; + } + +-static int hmdfs_setattr_merge(struct dentry *dentry, struct iattr *ia) ++static int hmdfs_setattr_merge(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *ia) + { + struct inode *inode = d_inode(dentry); + struct dentry *lower_dentry = hmdfs_get_fst_lo_d(dentry); +@@ -831,7 +831,7 @@ static int hmdfs_setattr_merge(struct dentry *dentry, struct iattr *ia) + inode_lock(lower_inode); + tmp_uid = hmdfs_override_inode_uid(lower_inode); + +- err = notify_change(lower_dentry, &lower_ia, NULL); ++ err = notify_change(&nop_mnt_idmap, lower_dentry, &lower_ia, NULL); + i_size_write(inode, i_size_read(lower_inode)); + inode->i_atime = lower_inode->i_atime; + inode->i_mtime = lower_inode->i_mtime; +@@ -859,7 +859,7 @@ int do_mkdir_merge(struct inode *parent_inode, struct dentry *child_dentry, + struct super_block *sb = parent_inode->i_sb; + struct inode *child_inode = NULL; + +- ret = vfs_mkdir(lo_i_parent, lo_d_child, mode); ++ ret = vfs_mkdir(&nop_mnt_idmap, lo_i_parent, lo_d_child, mode); + if (ret) + goto out; + +@@ -887,7 +887,7 @@ int do_create_merge(struct inode *parent_inode, struct dentry *child_dentry, + struct super_block *sb = parent_inode->i_sb; + struct inode *child_inode = NULL; + +- ret = vfs_create(lo_i_parent, lo_d_child, mode, want_excl); ++ ret = vfs_create(&nop_mnt_idmap, lo_i_parent, lo_d_child, mode, want_excl); + if (ret) + goto out; + +@@ -931,7 +931,7 @@ int hmdfs_do_ops_merge(struct inode *i_parent, struct dentry *d_child, + break; + } + } else { +- ret = vfs_mkdir(d_inode(path.dentry), lo_d_child, ++ ret = vfs_mkdir(&nop_mnt_idmap, d_inode(path.dentry), lo_d_child, + rec_op_para->mode); + } + if (ret) +@@ -1087,7 +1087,7 @@ void hmdfs_init_recursive_para(struct hmdfs_recursive_para *rec_op_para, + rec_op_para->name = name; + } + +-int hmdfs_mkdir_merge(struct inode *dir, struct dentry *dentry, umode_t mode) ++int hmdfs_mkdir_merge(struct mnt_idmap *idmap, struct inode *dir, struct dentry *dentry, umode_t mode) + { + int ret = 0; + struct hmdfs_recursive_para *rec_op_para = NULL; +@@ -1114,7 +1114,7 @@ out: + return ret; + } + +-int hmdfs_create_merge(struct inode *dir, struct dentry *dentry, umode_t mode, ++int hmdfs_create_merge(struct mnt_idmap *idmap, struct inode *dir, struct dentry *dentry, umode_t mode, + bool want_excl) + { + struct hmdfs_recursive_para *rec_op_para = NULL; +@@ -1153,7 +1153,7 @@ int do_rmdir_merge(struct inode *dir, struct dentry *dentry) + lo_d = comrade->lo_d; + lo_d_dir = lock_parent(lo_d); + lo_i_dir = d_inode(lo_d_dir); +- ret = vfs_rmdir(lo_i_dir, lo_d); ++ ret = vfs_rmdir(&nop_mnt_idmap, lo_i_dir, lo_d); + unlock_dir(lo_d_dir); + if (ret) + break; +@@ -1200,7 +1200,7 @@ int do_unlink_merge(struct inode *dir, struct dentry *dentry) + lo_d = comrade->lo_d; + lo_d_dir = lock_parent(lo_d); + lo_i_dir = d_inode(lo_d_dir); +- ret = vfs_unlink(lo_i_dir, lo_d, NULL); // lo_d GET ++ ret = vfs_unlink(&nop_mnt_idmap, lo_i_dir, lo_d, NULL); // lo_d GET + unlock_dir(lo_d_dir); + if (ret) + break; +@@ -1247,7 +1247,7 @@ int do_rename_merge(struct inode *old_dir, struct dentry *old_dentry, + char *abs_path_buf = kmalloc(PATH_MAX, GFP_KERNEL); + char *path_name = NULL; + struct hmdfs_dentry_info_merge *pmdi = NULL; +- ++ struct renamedata rd; + if (flags & ~RENAME_NOREPLACE) { + ret = -EINVAL; + goto out; +@@ -1300,8 +1300,19 @@ int do_rename_merge(struct inode *old_dir, struct dentry *old_dentry, + lo_d_old_dir = dget_parent(lo_d_old); + lo_i_old_dir = d_inode(lo_d_old_dir); + +- ret = vfs_rename(lo_i_old_dir, lo_d_old, lo_i_new_dir, lo_d_new, +- NULL, flags); ++ rd.old_mnt_idmap = &nop_mnt_idmap; ++ rd.old_dir = lo_i_old_dir; ++ rd.old_dentry = lo_d_old; ++ rd.new_mnt_idmap = &nop_mnt_idmap; ++ rd.new_dir = lo_i_new_dir; ++ rd.new_dentry = lo_d_new; ++ rd.delegated_inode = NULL; ++ rd.flags = flags; ++ ++ // ret = vfs_rename(lo_i_old_dir, lo_d_old, lo_i_new_dir, lo_d_new, ++ // NULL, flags); ++ ret = vfs_rename(&rd); ++ + new_comrade = alloc_comrade(lo_p_new.dentry, comrade->dev_id); + if (IS_ERR(new_comrade)) { + ret = PTR_ERR(new_comrade); +@@ -1320,7 +1331,7 @@ out: + return ret; + } + +-int hmdfs_rename_merge(struct inode *old_dir, struct dentry *old_dentry, ++int hmdfs_rename_merge(struct mnt_idmap *idmap, struct inode *old_dir, struct dentry *old_dentry, + struct inode *new_dir, struct dentry *new_dentry, + unsigned int flags) + { +diff --git a/inode_remote.c b/inode_remote.c +index 6a19e6e..ff750e2 100644 +--- a/inode_remote.c ++++ b/inode_remote.c +@@ -574,7 +574,7 @@ mkdir_out: + return err; + } + +-int hmdfs_mkdir_remote(struct inode *dir, struct dentry *dentry, umode_t mode) ++int hmdfs_mkdir_remote(struct mnt_idmap *idmp, struct inode *dir, struct dentry *dentry, umode_t mode) + { + int err = 0; + struct hmdfs_inode_info *info = hmdfs_i(dir); +@@ -645,7 +645,7 @@ create_out: + return err; + } + +-int hmdfs_create_remote(struct inode *dir, struct dentry *dentry, umode_t mode, ++int hmdfs_create_remote(struct mnt_idmap *idmp, struct inode *dir, struct dentry *dentry, umode_t mode, + bool want_excl) + { + int err = 0; +@@ -786,7 +786,7 @@ static void rename_in_cache_file(uint64_t dev_id, struct dentry *old_dentry, + kref_put(&new_item->ref, release_cache_item); + } + +-int hmdfs_rename_remote(struct inode *old_dir, struct dentry *old_dentry, ++int hmdfs_rename_remote(struct mnt_idmap *idmp, struct inode *old_dir, struct dentry *old_dentry, + struct inode *new_dir, struct dentry *new_dentry, + unsigned int flags) + { +@@ -852,7 +852,7 @@ rename_out: + return err; + } + +-static int hmdfs_dir_setattr_remote(struct dentry *dentry, struct iattr *ia) ++static int hmdfs_dir_setattr_remote(struct mnt_idmap *idmp, struct dentry *dentry, struct iattr *ia) + { + // Do not support dir setattr + return 0; +@@ -869,7 +869,7 @@ const struct inode_operations hmdfs_dev_dir_inode_ops_remote = { + .permission = hmdfs_permission, + }; + +-static int hmdfs_setattr_remote(struct dentry *dentry, struct iattr *ia) ++static int hmdfs_setattr_remote(struct mnt_idmap *idmsp, struct dentry *dentry, struct iattr *ia) + { + struct hmdfs_inode_info *info = hmdfs_i(d_inode(dentry)); + struct hmdfs_peer *conn = info->conn; +@@ -942,7 +942,7 @@ int hmdfs_remote_getattr(struct hmdfs_peer *conn, struct dentry *dentry, + return 0; + } + +-static int hmdfs_get_cached_attr_remote(const struct path *path, ++static int hmdfs_get_cached_attr_remote(struct mnt_idmap *idmp, const struct path *path, + struct kstat *stat, u32 request_mask, + unsigned int flags) + { +diff --git a/main.c b/main.c +index f57d675..90142e1 100644 +--- a/main.c ++++ b/main.c +@@ -71,7 +71,7 @@ static int hmdfs_xattr_local_get(struct dentry *dentry, const char *name, + ssize_t res = 0; + + hmdfs_get_lower_path(dentry, &lower_path); +- res = vfs_getxattr(lower_path.dentry, name, value, size); ++ res = vfs_getxattr(&nop_mnt_idmap, lower_path.dentry, name, value, size); + hmdfs_put_lower_path(&lower_path); + return res; + } +@@ -133,10 +133,10 @@ static int hmdfs_xattr_local_set(struct dentry *dentry, const char *name, + + hmdfs_get_lower_path(dentry, &lower_path); + if (value) { +- res = vfs_setxattr(lower_path.dentry, name, value, size, flags); ++ res = vfs_setxattr(&nop_mnt_idmap, lower_path.dentry, name, value, size, flags); + } else { + WARN_ON(flags != XATTR_REPLACE); +- res = vfs_removexattr(lower_path.dentry, name); ++ res = vfs_removexattr(&nop_mnt_idmap, lower_path.dentry, name); + } + + hmdfs_put_lower_path(&lower_path); +@@ -178,6 +178,7 @@ out: + } + + static int hmdfs_xattr_set(const struct xattr_handler *handler, ++ struct mnt_idmap *idmap, + struct dentry *dentry, struct inode *inode, + const char *name, const void *value, + size_t size, int flags) +@@ -817,7 +818,7 @@ uint64_t hmdfs_gen_boot_cookie(void) + uint16_t rand; + + now = ktime_to_ms(ktime_get()); +- prandom_bytes(&rand, sizeof(rand)); ++ get_random_bytes(&rand, sizeof(rand)); + + now &= (1ULL << HMDFS_BOOT_COOKIE_RAND_SHIFT) - 1; + now |= ((uint64_t)rand << HMDFS_BOOT_COOKIE_RAND_SHIFT); +diff --git a/stash.c b/stash.c +index 4137204..8eb2d44 100644 +--- a/stash.c ++++ b/stash.c +@@ -174,7 +174,7 @@ static struct dentry *hmdfs_do_vfs_mkdir(struct dentry *parent, + goto out; + } + +- err = vfs_mkdir(dir, child, mode); ++ err = vfs_mkdir(&nop_mnt_idmap, dir, child, mode); + if (err) { + dput(child); + child = ERR_PTR(err); +@@ -218,7 +218,9 @@ static struct file *hmdfs_new_stash_file(struct path *d_path, const char *cid) + goto mkdir_err; + } + +- child = vfs_tmpfile(parent, S_IFREG | 0600, 0); ++ child = vfs_tmpfile(&nop_mnt_idmap, parent, S_IFREG | 0600, 0); ++ //kernel_tmpfile_open(&nop_mnt_idmap, d_path, S_IFREG | 0600, 0, current_cred()); ++ + if (IS_ERR(child)) { + err = PTR_ERR(child); + hmdfs_err("new stash file error %d", err); +@@ -490,7 +492,7 @@ lookup_again: + hmdfs_warning("%s exists (mode 0%o)", + name, d_inode(child)->i_mode); + +- err = vfs_unlink(dir, child, NULL); ++ err = vfs_unlink(&nop_mnt_idmap, dir, child, NULL); + if (err) { + hmdfs_err("unlink %s err %d", name, err); + goto out; +@@ -505,7 +507,7 @@ lookup_again: + goto lookup_again; + } + +- err = vfs_link(stash, dir, child, NULL); ++ err = vfs_link(stash, &nop_mnt_idmap, dir, child, NULL); + if (err) { + hmdfs_err("link stash file to %s err %d", name, err); + goto out; +@@ -1020,7 +1022,7 @@ static int hmdfs_parse_stash_file_name(struct dir_context *dctx, + return 1; + } + +-static int hmdfs_has_stash_file(struct dir_context *dctx, const char *name, ++static bool hmdfs_has_stash_file(struct dir_context *dctx, const char *name, + int namelen, loff_t offset, + u64 inum, unsigned int d_type) + { +@@ -1032,13 +1034,13 @@ static int hmdfs_has_stash_file(struct dir_context *dctx, const char *name, + err = hmdfs_parse_stash_file_name(dctx, name, namelen, + d_type, &stash_inum); + if (!err) +- return 0; ++ return true; + + ctx->tbl->cnt++; +- return 1; ++ return false; + } + +-static int hmdfs_fill_stash_file(struct dir_context *dctx, const char *name, ++static bool hmdfs_fill_stash_file(struct dir_context *dctx, const char *name, + int namelen, loff_t offset, + u64 inum, unsigned int d_type) + { +@@ -1050,13 +1052,13 @@ static int hmdfs_fill_stash_file(struct dir_context *dctx, const char *name, + err = hmdfs_parse_stash_file_name(dctx, name, namelen, + d_type, &stash_inum); + if (!err) +- return 0; ++ return true; + if (ctx->tbl->cnt >= ctx->tbl->max) +- return 1; ++ return false; + + ctx->tbl->inodes[ctx->tbl->cnt++] = stash_inum; + +- return 0; ++ return true; + } + + static int hmdfs_del_stash_file(struct dentry *parent, struct dentry *child) +@@ -1068,7 +1070,7 @@ static int hmdfs_del_stash_file(struct dentry *parent, struct dentry *child) + dget(child); + + inode_lock_nested(dir, I_MUTEX_PARENT); +- err = vfs_unlink(dir, child, NULL); ++ err = vfs_unlink(&nop_mnt_idmap, dir, child, NULL); + if (err) + hmdfs_err("remove stash file err %d", err); + inode_unlock(dir); +@@ -1327,7 +1329,9 @@ static ssize_t hmdfs_write_dst(struct hmdfs_peer *conn, struct file *filp, + + file_start_write(filp); + +- old_fs = force_uaccess_begin(); ++ //old_fs = force_uaccess_begin(); ++ old_fs=get_fs(); ++ set_fs(USER_DS); + + init_sync_kiocb(&kiocb, filp); + kiocb.ki_pos = pos; +@@ -1338,7 +1342,8 @@ static ssize_t hmdfs_write_dst(struct hmdfs_peer *conn, struct file *filp, + + wr = hmdfs_file_write_iter_remote_nocheck(&kiocb, &iter); + +- force_uaccess_end(old_fs); ++ //force_uaccess_end(old_fs); ++ set_fs(old_fs); + + file_end_write(filp); + diff --git a/0004-add-dcache-parameter-support.patch b/0004-add-dcache-parameter-support.patch new file mode 100644 index 0000000..bd8102b --- /dev/null +++ b/0004-add-dcache-parameter-support.patch @@ -0,0 +1,49 @@ +diff --git a/super.c b/super.c +index 18f222c..aee7d47 100644 +--- a/super.c ++++ b/super.c +@@ -21,6 +21,9 @@ enum { + OPT_NO_OFFLINE_STASH, + OPT_NO_DENTRY_CACHE, + OPT_USER_ID, ++ OPT_DCACHE_THRESHOLD, ++ OPT_DCACHE_PRECISION, ++ OPT_DCACHE_TIMEOUT, + OPT_ERR, + }; + +@@ -33,6 +36,9 @@ static match_table_t hmdfs_tokens = { + { OPT_NO_OFFLINE_STASH, "no_offline_stash" }, + { OPT_NO_DENTRY_CACHE, "no_dentry_cache" }, + { OPT_USER_ID, "user_id=%s"}, ++ {OPT_DCACHE_THRESHOLD, "dcache_threshold=%d"}, ++ {OPT_DCACHE_PRECISION, "dcache_precision=%d"}, ++ {OPT_DCACHE_TIMEOUT, "dcache_timeout=%d"}, + { OPT_ERR, NULL }, + }; + +@@ -150,6 +156,24 @@ int hmdfs_parse_options(struct hmdfs_sb_info *sbi, const char *data) + sbi->user_id = user_id; + } + break; ++ case OPT_DCACHE_THRESHOLD: ++ err = match_int(&args[0], &decache); ++ if (err) ++ goto out; ++ sbi->dcache_threshold = decache; ++ break; ++ case OPT_DCACHE_PRECISION: ++ err = match_int(&args[0], &decache); ++ if (err) ++ goto out; ++ sbi->dcache_precision = decache; ++ break; ++ case OPT_DCACHE_TIMEOUT: ++ err = match_int(&args[0], &decache); ++ if (err) ++ goto out; ++ sbi->dcache_timeout = decache; ++ break; + default: + err = -EINVAL; + goto out; \ No newline at end of file -- Gitee