diff --git a/fs/hmdfs/Kconfig b/fs/hmdfs/Kconfig index 379606a6f46630df6aa76b36c30993f682c8f353..1bb5c23476303a1aa371f5a344bd3ec88e49143b 100644 --- a/fs/hmdfs/Kconfig +++ b/fs/hmdfs/Kconfig @@ -38,11 +38,3 @@ config HMDFS_FS_DEBUG it works. If unsure, say N. - -config HMDFS_FS_FAULT_INJECT - bool "HMDFS fault inject" - depends on HMDFS_FS - help - HMDFS provide fault inject for test. - - If unsure, say N. diff --git a/fs/hmdfs/Makefile b/fs/hmdfs/Makefile index 6f38c843664e131d98ec1c325e86459e31311015..48a64acc8331c364a73711ea0041ae05af017602 100644 --- a/fs/hmdfs/Makefile +++ b/fs/hmdfs/Makefile @@ -12,5 +12,3 @@ hmdfs-y += comm/connection.o comm/socket_adapter.o comm/transport.o hmdfs-$(CONFIG_HMDFS_FS_ENCRYPTION) += comm/crypto.o hmdfs-$(CONFIG_HMDFS_FS_PERMISSION) += authority/authentication.o hmdfs-$(CONFIG_HMDFS_FS_PERMISSION) += authority/config.o - -hmdfs-$(CONFIG_FS_FAULT_INJECTION) += comm/fault_inject.o diff --git a/fs/hmdfs/comm/fault_inject.c b/fs/hmdfs/comm/fault_inject.c deleted file mode 100644 index 11779b53b0ea38e6daebcf03d4a27edc07b46a47..0000000000000000000000000000000000000000 --- a/fs/hmdfs/comm/fault_inject.c +++ /dev/null @@ -1,134 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * fs/hmdfs/comm/fault_inject.c - * - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - */ - -#include "hmdfs.h" -#include "fault_inject.h" -#include "connection.h" - -static DECLARE_FAULT_ATTR(fail_default_attr); -static struct dentry *hmdfs_debugfs_root; - -void __init hmdfs_create_debugfs_root(void) -{ - hmdfs_debugfs_root = debugfs_create_dir("hmdfs", NULL); - if (!hmdfs_debugfs_root) - hmdfs_warning("failed to create debugfs directory"); -} - -void hmdfs_destroy_debugfs_root(void) -{ - debugfs_remove_recursive(hmdfs_debugfs_root); - hmdfs_debugfs_root = NULL; -} - -void hmdfs_fault_inject_init(struct hmdfs_fault_inject *fault_inject, - const char *name) -{ - struct dentry *dir = NULL; - struct dentry *parent = NULL; - struct fault_attr *attr = &fault_inject->attr; - - if (!hmdfs_debugfs_root) - return; - - parent = debugfs_create_dir(name, hmdfs_debugfs_root); - if (!parent) { - hmdfs_warning("failed to create %s debugfs directory", name); - return; - } - - *attr = fail_default_attr; - dir = fault_create_debugfs_attr("fault_inject", parent, attr); - if (IS_ERR(dir)) { - hmdfs_warning("hmdfs: failed to create debugfs attr"); - debugfs_remove_recursive(parent); - return; - } - fault_inject->parent = parent; - debugfs_create_ulong("op_mask", 0600, dir, &fault_inject->op_mask); - debugfs_create_ulong("fail_send_message", 0600, dir, - &fault_inject->fail_send_message); - debugfs_create_ulong("fake_fid_ver", 0600, dir, - &fault_inject->fake_fid_ver); - debugfs_create_bool("fail_req", 0600, dir, &fault_inject->fail_req); -} - -void hmdfs_fault_inject_fini(struct hmdfs_fault_inject *fault_inject) -{ - debugfs_remove_recursive(fault_inject->parent); -} - -bool hmdfs_should_fail_sendmsg(struct hmdfs_fault_inject *fault_inject, - struct hmdfs_peer *con, - struct hmdfs_send_data *msg, int *err) -{ - struct hmdfs_head_cmd *head = (struct hmdfs_head_cmd *)msg->head; - unsigned long type = fault_inject->fail_send_message; - - if (!test_bit(head->operations.command, &fault_inject->op_mask)) - return false; - - if (type != T_MSG_FAIL && type != T_MSG_DISCARD) - return false; - - if (!should_fail(&fault_inject->attr, 1)) - return false; - - if (type == T_MSG_FAIL) - *err = -EINVAL; - else if (type == T_MSG_DISCARD) - *err = 0; - - hmdfs_err( - "fault injection err %d, %s message, device_id %llu, msg_id %u, cmd %d", - *err, (type == T_MSG_FAIL) ? "fail" : "discard", con->device_id, - le32_to_cpu(head->msg_id), head->operations.command); - return true; -} - -bool hmdfs_should_fail_req(struct hmdfs_fault_inject *fault_inject, - struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, - int *err) -{ - if (!test_bit(cmd->operations.command, &fault_inject->op_mask)) - return false; - - if (!fault_inject->fail_req) - return false; - - if (!should_fail(&fault_inject->attr, 1)) - return false; - - *err = -EIO; - hmdfs_err("fault injection err %d, device_id %llu, msg_id %u, cmd %d", - *err, con->device_id, le32_to_cpu(cmd->msg_id), - cmd->operations.command); - return true; -} - -bool hmdfs_should_fake_fid_ver(struct hmdfs_fault_inject *fault_inject, - struct hmdfs_peer *con, - struct hmdfs_head_cmd *cmd, - enum CHANGE_FID_VER_TYPE fake_type) -{ - unsigned long type = fault_inject->fake_fid_ver; - - if (!test_bit(cmd->operations.command, &fault_inject->op_mask)) - return false; - - if (type != fake_type) - return false; - - if (!should_fail(&fault_inject->attr, 1)) - return false; - - hmdfs_err( - "fault injection to change fid ver by %s cookie, device_id %llu, msg_id %u, cmd %d", - (type == T_BOOT_COOKIE) ? "boot" : "con", con->device_id, - le32_to_cpu(cmd->msg_id), cmd->operations.command); - return true; -} diff --git a/fs/hmdfs/comm/fault_inject.h b/fs/hmdfs/comm/fault_inject.h deleted file mode 100644 index be8876ab0328e4a1aa1d71b5aa1f2b9946db348b..0000000000000000000000000000000000000000 --- a/fs/hmdfs/comm/fault_inject.h +++ /dev/null @@ -1,88 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * fs/hmdfs/comm/fault_inject.h - * - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - */ - -#ifndef HMDFS_FAULT_INJECT_H -#define HMDFS_FAULT_INJECT_H - -#include -#include "protocol.h" - -struct hmdfs_fault_inject { -#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS - struct fault_attr attr; - struct dentry *parent; - unsigned long op_mask; - unsigned long fail_send_message; - unsigned long fake_fid_ver; - bool fail_req; -#endif -}; - -enum FAIL_MESSAGE_TYPE { - T_MSG_FAIL = 1, - T_MSG_DISCARD = 2, -}; - -enum CHANGE_FID_VER_TYPE { - T_BOOT_COOKIE = 1, - T_CON_COOKIE = 2, -}; - -#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS -void __init hmdfs_create_debugfs_root(void); -void hmdfs_destroy_debugfs_root(void); - -void hmdfs_fault_inject_init(struct hmdfs_fault_inject *fault_inject, - const char *name); -void hmdfs_fault_inject_fini(struct hmdfs_fault_inject *fault_inject); -bool hmdfs_should_fail_sendmsg(struct hmdfs_fault_inject *fault_inject, - struct hmdfs_peer *con, - struct hmdfs_send_data *msg, int *err); -bool hmdfs_should_fail_req(struct hmdfs_fault_inject *fault_inject, - struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, - int *err); -bool hmdfs_should_fake_fid_ver(struct hmdfs_fault_inject *fault_inject, - struct hmdfs_peer *con, - struct hmdfs_head_cmd *cmd, - enum CHANGE_FID_VER_TYPE fake_type); -#else -static inline void __init hmdfs_create_debugfs_root(void) {} -static inline void hmdfs_destroy_debugfs_root(void) {} - -static inline void -hmdfs_fault_inject_init(struct hmdfs_fault_inject *fault_inject, - const char *name) -{ -} -static inline void -hmdfs_fault_inject_fini(struct hmdfs_fault_inject *fault_inject) -{ -} -static inline bool -hmdfs_should_fail_sendmsg(struct hmdfs_fault_inject *fault_inject, - struct hmdfs_peer *con, struct hmdfs_send_data *msg, - int *err) -{ - return false; -} -static inline bool -hmdfs_should_fail_req(struct hmdfs_fault_inject *fault_inject, - struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, - int *err) -{ - return false; -} -static inline bool -hmdfs_should_fake_fid_ver(struct hmdfs_fault_inject *fault_inject, - struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, - enum CHANGE_FID_VER_TYPE fake_type) -{ - return false; -} -#endif - -#endif // HMDFS_FAULT_INJECT_H diff --git a/fs/hmdfs/comm/socket_adapter.c b/fs/hmdfs/comm/socket_adapter.c index 769b6d28ebcef214973e36d9d19bb9bbe254f4f5..eff3d3e1c044d43160176e237f465968500a5283 100644 --- a/fs/hmdfs/comm/socket_adapter.c +++ b/fs/hmdfs/comm/socket_adapter.c @@ -142,10 +142,6 @@ int hmdfs_sendmessage(struct hmdfs_peer *node, struct hmdfs_send_data *msg) goto out; } - if (hmdfs_should_fail_sendmsg(&node->sbi->fault_inject, node, msg, - &ret)) - goto out; - old_cred = hmdfs_override_creds(node->sbi->system_cred); do { diff --git a/fs/hmdfs/hmdfs.h b/fs/hmdfs/hmdfs.h index 4228bb64c43eca5b9e0ddfbfb41b26529c7eb287..0c5cce32e30a665ddc94bd35dd9d9f0a1e490791 100644 --- a/fs/hmdfs/hmdfs.h +++ b/fs/hmdfs/hmdfs.h @@ -16,7 +16,6 @@ #include #include "comm/protocol.h" -#include "comm/fault_inject.h" #if KERNEL_VERSION(4, 15, 0) < LINUX_VERSION_CODE #define hmdfs_time_t timespec64 @@ -185,7 +184,6 @@ struct hmdfs_sb_info { /* To bridge the userspace utils */ struct kfifo notify_fifo; spinlock_t notify_fifo_lock; - struct hmdfs_fault_inject fault_inject; /* For reboot detect */ uint64_t boot_cookie; diff --git a/fs/hmdfs/hmdfs_dentryfile.c b/fs/hmdfs/hmdfs_dentryfile.c index e034cb8071f0a70e9ae89d04aca00df345916758..bb9faff3e027c3c95dfab368357aabd7f65544c6 100644 --- a/fs/hmdfs/hmdfs_dentryfile.c +++ b/fs/hmdfs/hmdfs_dentryfile.c @@ -489,9 +489,8 @@ int read_dentry(struct hmdfs_sb_info *sbi, char *file_name, else if (S_ISREG(le16_to_cpu( dentry_group->nsl[j].i_mode))) file_type = DT_REG; - else if (S_ISLNK(le16_to_cpu( - dentry_group->nsl[j].i_mode))) - file_type = DT_LNK; + else + continue; pos = hmdfs_set_pos(0, i, j); is_continue = dir_emit( @@ -684,25 +683,14 @@ void update_dentry(struct hmdfs_dentry_group *d, struct dentry *child_dentry, struct inode *inode, __u32 name_hash, unsigned int bit_pos) { struct hmdfs_dentry *de; - struct hmdfs_dentry_info *gdi = hmdfs_d(child_dentry); const struct qstr name = child_dentry->d_name; int slots = get_dentry_slots(name.len); int i; unsigned long ino; __u32 igen; - /* - * If the dentry's inode is symlink, it must be lower inode, - * and we should use the upper ino and generation to fill - * the dentryfile. - */ - if (!gdi && S_ISLNK(d_inode(child_dentry)->i_mode)) { - ino = d_inode(child_dentry)->i_ino; - igen = d_inode(child_dentry)->i_generation; - } else { - ino = inode->i_ino; - igen = inode->i_generation; - } + ino = inode->i_ino; + igen = inode->i_generation; de = &d->nsl[bit_pos]; de->hash = cpu_to_le32(name_hash); @@ -713,21 +701,7 @@ void update_dentry(struct hmdfs_dentry_group *d, struct dentry *child_dentry, de->i_size = cpu_to_le64(inode->i_size); de->i_ino = cpu_to_le64(generate_u64_ino(ino, igen)); de->i_flag = 0; - - /* - * If the dentry has fsdata, we just assume it must be - * hmdfs filesystem's dentry. - * Only client may update it's info in dentryfile when rename - * the remote file. - * Since the symlink mtime and size is from server's lower - * inode, we should just use it and only set S_IFLNK in mode. - */ - if (gdi && hm_islnk(gdi->file_type)) - de->i_mode = cpu_to_le16(S_IFLNK); - else if (!gdi && S_ISLNK(d_inode(child_dentry)->i_mode)) - de->i_mode = d_inode(child_dentry)->i_mode; - else - de->i_mode = cpu_to_le16(inode->i_mode); + de->i_mode = cpu_to_le16(inode->i_mode); for (i = 0; i < slots; i++) { __set_bit_le(bit_pos + i, d->bitmap); diff --git a/fs/hmdfs/hmdfs_merge_view.h b/fs/hmdfs/hmdfs_merge_view.h index 01064b3d98dfb2e092b7d83268628631e25ba2c3..ad9eff5cb5c3c70bcad25c21b2db6e5fe3444f8d 100644 --- a/fs/hmdfs/hmdfs_merge_view.h +++ b/fs/hmdfs/hmdfs_merge_view.h @@ -34,7 +34,6 @@ struct hmdfs_dentry_comrade { enum FILE_CMD_MERGE { F_MKDIR_MERGE = 0, F_CREATE_MERGE = 1, - F_SYMLINK_MERGE = 2, }; struct hmdfs_recursive_para { @@ -140,7 +139,6 @@ struct dentry *hmdfs_get_fst_lo_d(struct dentry *dentry); extern const struct inode_operations hmdfs_file_iops_merge; extern const struct file_operations hmdfs_file_fops_merge; -extern const struct inode_operations hmdfs_symlink_iops_merge; extern const struct inode_operations hmdfs_dir_iops_merge; extern const struct file_operations hmdfs_dir_fops_merge; extern const struct dentry_operations hmdfs_dops_merge; diff --git a/fs/hmdfs/hmdfs_server.c b/fs/hmdfs/hmdfs_server.c index ea3697f331282180adb1012743e06ced3cb841e7..ccf8170b9b4dbaf73265dd10ff53f23e2d5dbcb5 100644 --- a/fs/hmdfs/hmdfs_server.c +++ b/fs/hmdfs/hmdfs_server.c @@ -14,7 +14,6 @@ #include #include "authority/authentication.h" -#include "comm/fault_inject.h" #include "hmdfs.h" #include "hmdfs_dentryfile.h" #include "hmdfs_trace.h" @@ -73,39 +72,6 @@ void remove_file_from_conn(struct hmdfs_peer *conn, __u32 file_id) spin_unlock(lock); } -struct file *hmdfs_open_photokit_path(struct hmdfs_sb_info *sbi, - const char *path) -{ - struct file *file; - int err; - const char *root_name = sbi->local_dst; - char *real_path; - int path_len; - - path_len = strlen(root_name) + strlen(path) + 2; - if (path_len >= PATH_MAX) { - err = -EINVAL; - return ERR_PTR(err); - } - real_path = kzalloc(path_len, GFP_KERNEL); - if (!real_path) { - err = -ENOMEM; - return ERR_PTR(err); - } - - sprintf(real_path, "%s/%s", root_name, path); - file = filp_open(real_path, O_RDWR | O_LARGEFILE, 0644); - if (IS_ERR(file)) { - hmdfs_info("filp_open failed: %ld", PTR_ERR(file)); - } else { - hmdfs_info("get file with magic %lu", - file->f_inode->i_sb->s_magic); - } - - kfree(real_path); - return file; -} - struct file *hmdfs_open_path(struct hmdfs_sb_info *sbi, const char *path) { struct path root_path; @@ -212,38 +178,6 @@ void __init hmdfs_server_add_node_evt_cb(void) hmdfs_node_add_evt_cb(server_cb, ARRAY_SIZE(server_cb)); } -static int hmdfs_get_inode_by_name(struct hmdfs_peer *con, const char *filename, - uint64_t *ino) -{ - int ret = 0; - struct path root_path; - struct path dst_path; - struct inode *inode = NULL; - - ret = kern_path(con->sbi->local_dst, 0, &root_path); - if (ret) { - hmdfs_err("kern_path failed err = %d", ret); - return ret; - } - - ret = vfs_path_lookup(root_path.dentry, root_path.mnt, filename, 0, - &dst_path); - if (ret) { - path_put(&root_path); - return ret; - } - - inode = d_inode(dst_path.dentry); - if (con->sbi->sb == inode->i_sb) - inode = hmdfs_i(inode)->lower_inode; - *ino = generate_u64_ino(inode->i_ino, inode->i_generation); - - path_put(&dst_path); - path_put(&root_path); - - return 0; -} - static const char *datasl_str[] = { "s0", "s1", "s2", "s3", "s4" }; @@ -349,17 +283,14 @@ static struct file *hmdfs_open_file(struct hmdfs_peer *con, return ERR_PTR(-EACCES); } - if (hm_islnk(file_type)) - file = hmdfs_open_photokit_path(con->sbi, filename); - else { - if (hm_isshare(file_type)) { - err = hmdfs_check_share_access_permission(con->sbi, - filename, con->cid, &item); - if (err) - return ERR_PTR(err); - } - file = hmdfs_open_path(con->sbi, filename); + if (hm_isshare(file_type)) { + err = hmdfs_check_share_access_permission(con->sbi, + filename, con->cid, &item); + if (err) + return ERR_PTR(err); } + file = hmdfs_open_path(con->sbi, filename); + if (IS_ERR(file)) return file; @@ -413,14 +344,6 @@ static uint64_t hmdfs_server_pack_fid_ver(struct hmdfs_peer *con, uint64_t boot_cookie = con->sbi->boot_cookie; uint16_t con_cookie = con->fid_cookie; - if (hmdfs_should_fake_fid_ver(&con->sbi->fault_inject, con, - cmd, T_BOOT_COOKIE)) - boot_cookie = hmdfs_gen_boot_cookie(); - - if (hmdfs_should_fake_fid_ver(&con->sbi->fault_inject, con, - cmd, T_CON_COOKIE)) - con_cookie++; - return (boot_cookie | (con_cookie & ((1 << HMDFS_FID_VER_BOOT_COOKIE_SHIFT) - 1))); } @@ -520,15 +443,8 @@ static int hmdfs_get_open_info(struct hmdfs_peer *con, uint8_t file_type, info->stat_valid = true; } - /* if open a link file, get ino from link inode */ - if (hm_islnk(file_type)) { - ret = hmdfs_get_inode_by_name(con, filename, &info->real_ino); - if (ret) - return ret; - } else { - info->real_ino = generate_u64_ino(info->inode->i_ino, + info->real_ino = generate_u64_ino(info->inode->i_ino, info->inode->i_generation); - } return 0; } @@ -543,8 +459,6 @@ void hmdfs_server_open(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, int ret = 0; trace_hmdfs_server_open_enter(con, recv); - if (hmdfs_should_fail_req(&con->sbi->fault_inject, con, cmd, &ret)) - goto out_err; resp = kzalloc(sizeread, GFP_KERNEL); info = kmalloc(sizeof(*info), GFP_KERNEL); @@ -584,7 +498,6 @@ void hmdfs_server_open(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, err_free: kfree(resp); kfree(info); -out_err: trace_hmdfs_server_open_exit(con, NULL, NULL, ret); hmdfs_send_err_response(con, cmd, ret); } @@ -605,9 +518,7 @@ static int hmdfs_check_and_create(struct path *path_parent, } else { if (is_excl) err = -EEXIST; - /* if inode aready exist, see if it's symlink */ - else if (S_ISREG(d_inode(dentry)->i_mode) && - hm_islnk(hmdfs_d(dentry)->file_type)) + else if (S_ISLNK(d_inode(dentry)->i_mode)) err = -EINVAL; else if (S_ISDIR(d_inode(dentry)->i_mode)) err = -EISDIR; @@ -741,9 +652,6 @@ void hmdfs_server_atomic_open(struct hmdfs_peer *con, struct atomic_open_response *resp = NULL; struct hmdfs_open_info *info = NULL; - if (hmdfs_should_fail_req(&con->sbi->fault_inject, con, cmd, &err)) - goto out; - info = kmalloc(sizeof(*info), GFP_KERNEL); resp = kzalloc(sizeof(*resp), GFP_KERNEL); if (!resp || !info) { @@ -860,14 +768,10 @@ void hmdfs_server_fsync(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, goto out; } - if (hmdfs_should_fail_req(&con->sbi->fault_inject, con, cmd, &ret)) - goto out_put_file; - ret = vfs_fsync_range(file, start, end, datasync); if (ret) hmdfs_err("fsync fail, ret %d", ret); -out_put_file: hmdfs_close_path(file); out: hmdfs_send_err_response(con, cmd, ret); @@ -897,9 +801,6 @@ void hmdfs_server_readpage(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, goto fail; } - if (hmdfs_should_fail_req(&con->sbi->fault_inject, con, cmd, &ret)) - goto fail_put_file; - read_len = (size_t)le32_to_cpu(readpage_recv->size); if (read_len == 0) goto fail_put_file; @@ -1052,9 +953,6 @@ void hmdfs_server_readpages_open(struct hmdfs_peer *con, size_t resp_len = 0; struct hmdfs_open_info *info = NULL; - if (hmdfs_should_fail_req(&con->sbi->fault_inject, con, cmd, &ret)) - goto fail; - info = kmalloc(sizeof(*info), GFP_KERNEL); if (!info) { ret = -ENOMEM; @@ -1283,9 +1181,6 @@ void hmdfs_server_readdir(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, goto send_err; } - if (hmdfs_should_fail_req(&con->sbi->fault_inject, con, cmd, &err)) - goto err_lookup_path; - if (le32_to_cpu(readdir_recv->verify_cache)) { if (hmdfs_client_cache_validate(con->sbi, readdir_recv, &lo_p)) goto out_response; @@ -1417,9 +1312,6 @@ void hmdfs_server_rmdir(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, char *name = NULL; struct rmdir_request *rmdir_recv = data; - if (hmdfs_should_fail_req(&con->sbi->fault_inject, con, cmd, &err)) - goto out; - path = rmdir_recv->path; name = rmdir_recv->path + le32_to_cpu(rmdir_recv->path_len) + 1; err = kern_path(con->sbi->local_dst, 0, &root_path); @@ -1427,7 +1319,7 @@ void hmdfs_server_rmdir(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, err = hmdfs_root_rmdir(con->device_id, &root_path, path, name); path_put(&root_path); } -out: + hmdfs_send_err_response(con, cmd, err); } @@ -1440,9 +1332,6 @@ void hmdfs_server_unlink(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, char *name = NULL; struct unlink_request *unlink_recv = data; - if (hmdfs_should_fail_req(&con->sbi->fault_inject, con, cmd, &err)) - goto out; - path = unlink_recv->path; name = unlink_recv->path + le32_to_cpu(unlink_recv->path_len) + 1; err = kern_path(con->sbi->local_dst, 0, &root_path); @@ -1450,7 +1339,7 @@ void hmdfs_server_unlink(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, err = hmdfs_root_unlink(con->device_id, &root_path, path, name); path_put(&root_path); } -out: + hmdfs_send_err_response(con, cmd, err); } @@ -1469,9 +1358,6 @@ void hmdfs_server_rename(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, char *name_new = NULL; struct rename_request *recv = data; - if (hmdfs_should_fail_req(&con->sbi->fault_inject, con, cmd, &err)) - goto out; - old_path_len = le32_to_cpu(recv->old_path_len); new_path_len = le32_to_cpu(recv->new_path_len); old_name_len = le32_to_cpu(recv->old_name_len); @@ -1486,50 +1372,8 @@ void hmdfs_server_rename(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, err = hmdfs_root_rename(con->sbi, con->device_id, path_old, name_old, path_new, name_new, flags); -out: - hmdfs_send_err_response(con, cmd, err); -} - -static int hmdfs_lookup_symlink(struct path *link_path, const char *path_fmt, - ...) -{ - int ret; - va_list args; - char *path = kmalloc(PATH_MAX, GFP_KERNEL); - if (!path) - return -ENOMEM; - - va_start(args, path_fmt); - ret = vsnprintf(path, PATH_MAX, path_fmt, args); - va_end(args); - - if (ret >= PATH_MAX) { - ret = -ENAMETOOLONG; - goto out; - } - - /* - * Todo: when rebuild dentryfile, there maybe deadlock - * because iterate_dir already hold the parent - * lock, but now, we didn't know the symlink - * src's parent. - */ - ret = kern_path(path, LOOKUP_FOLLOW, link_path); - if (ret) { - hmdfs_err("kern_path failed err = %d", ret); - goto out; - } - - if (!S_ISREG(d_inode(link_path->dentry)->i_mode)) { - hmdfs_err("path is dir symlink"); - path_put(link_path); - ret = -EOPNOTSUPP; - goto out; - } -out: - kfree(path); - return ret; + hmdfs_send_err_response(con, cmd, err); } static int hmdfs_filldir_real(struct dir_context *ctx, const char *name, @@ -1572,25 +1416,6 @@ static int hmdfs_filldir_real(struct dir_context *ctx, const char *name, if (d_type == DT_REG || d_type == DT_DIR) { create_dentry(child, d_inode(child), gc->file, gc->sbi); gc->num++; - } else if (d_type == DT_LNK) { - struct path link_path; - - res = hmdfs_lookup_symlink(&link_path, "%s/%s/%s", - gc->sbi->local_src, gc->dir, - namestr); - if (!res) { - create_dentry(child, d_inode(link_path.dentry), - gc->file, gc->sbi); - path_put(&link_path); - gc->num++; - } else if (res == -ENOENT) { - /* - * If source file do not exist, use the info from link - * inode. - */ - create_dentry(child, d_inode(child), gc->file, gc->sbi); - gc->num++; - } } dput(child); @@ -1702,16 +1527,12 @@ void hmdfs_server_writepage(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, goto out; } - if (hmdfs_should_fail_req(&con->sbi->fault_inject, con, cmd, &err)) - goto out_put_file; - pos = (loff_t)le64_to_cpu(writepage_recv->index) << HMDFS_PAGE_OFFSET; count = le32_to_cpu(writepage_recv->count); ret = kernel_write(file, writepage_recv->buf, count, &pos); if (ret != count) err = -EIO; -out_put_file: hmdfs_close_path(file); out: hmdfs_send_err_response(con, cmd, err); @@ -1721,27 +1542,6 @@ void hmdfs_server_writepage(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, hmdfs_server_check_writeback(hswb); } -static int hmdfs_lookup_linkpath(struct hmdfs_sb_info *sbi, - const char *path_name, struct path *dst_path) -{ - struct path link_path; - int err; - - err = hmdfs_lookup_symlink(&link_path, "%s/%s", sbi->local_dst, - path_name); - if (err) - return err; - - if (d_inode(link_path.dentry)->i_sb != sbi->sb) { - path_put(dst_path); - *dst_path = link_path; - } else { - path_put(&link_path); - } - - return 0; -} - static struct inode *hmdfs_verify_path(struct dentry *dentry, char *recv_buf, struct super_block *sb) { @@ -1791,9 +1591,6 @@ void hmdfs_server_setattr(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, struct iattr attr; __u32 valid = le32_to_cpu(recv->valid); - if (hmdfs_should_fail_req(&con->sbi->fault_inject, con, cmd, &err)) - goto out; - err = kern_path(con->sbi->local_dst, 0, &root_path); if (err) { hmdfs_err("kern_path failed err = %d", err); @@ -1811,14 +1608,9 @@ void hmdfs_server_setattr(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, goto out_put_dst; } - /* We need to follow if symlink was found */ if (S_ISLNK(inode->i_mode)) { - err = hmdfs_lookup_linkpath(con->sbi, recv->buf, &dst_path); - /* if source file doesn't exist, use link inode */ - if (err == -ENOENT) - err = 0; - else if (err) - goto out_put_dst; + err = -EPERM; + goto out_put_dst; } dentry = dst_path.dentry; @@ -1884,9 +1676,6 @@ void hmdfs_server_getattr(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, unsigned int recv_flags = le32_to_cpu(recv->lookup_flags); unsigned int lookup_flags = 0; - if (hmdfs_should_fail_req(&con->sbi->fault_inject, con, cmd, &err)) - goto err; - err = hmdfs_convert_lookup_flags(recv_flags, &lookup_flags); if (err) goto err; @@ -1901,7 +1690,7 @@ void hmdfs_server_getattr(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, hmdfs_err("kern_path failed err = %d", err); goto err_free_resp; } - //TODO: local_dst -->local_src + err = vfs_path_lookup(root_path.dentry, root_path.mnt, recv->buf, lookup_flags, &dst_path); if (err) @@ -1912,12 +1701,10 @@ void hmdfs_server_getattr(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, err = -ENOENT; goto out_put_dst; } - /* We need to follow if symlink was found */ + if (S_ISLNK(inode->i_mode)) { - err = hmdfs_lookup_linkpath(con->sbi, recv->buf, &dst_path); - /* if source file doesn't exist, use link inode */ - if (err && err != -ENOENT) - goto out_put_dst; + err = -EPERM; + goto out_put_dst; } err = vfs_getattr(&dst_path, &ks, STATX_BASIC_STATS | STATX_BTIME, 0); @@ -1979,9 +1766,6 @@ void hmdfs_server_statfs(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, struct kstatfs *st = NULL; int err = 0; - if (hmdfs_should_fail_req(&con->sbi->fault_inject, con, cmd, &err)) - goto out; - st = kzalloc(sizeof(*st), GFP_KERNEL); if (!st) { err = -ENOMEM; @@ -2038,11 +1822,6 @@ void hmdfs_server_syncfs(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, */ int ret = 0; - if (hmdfs_should_fail_req(&con->sbi->fault_inject, con, cmd, &ret)) { - hmdfs_send_err_response(con, cmd, ret); - return; - } - hmdfs_send_err_response(con, cmd, ret); } diff --git a/fs/hmdfs/hmdfs_trace.h b/fs/hmdfs/hmdfs_trace.h index 51ecdb9abbc4911051adb73a5cc17c15d8a32ab8..d3c5262b5f462638435ba435832240426b01dbe6 100644 --- a/fs/hmdfs/hmdfs_trace.h +++ b/fs/hmdfs/hmdfs_trace.h @@ -205,12 +205,6 @@ define_hmdfs_lookup_op_end_event(hmdfs_create_merge); define_hmdfs_lookup_op_end_event(hmdfs_lookup_share); define_hmdfs_lookup_op_end_event(hmdfs_lookup_share_end); -define_hmdfs_lookup_op_end_event(hmdfs_symlink_merge); -define_hmdfs_lookup_op_end_event(hmdfs_symlink_local); - -define_hmdfs_lookup_op_end_event(hmdfs_get_link_merge); -define_hmdfs_lookup_op_end_event(hmdfs_get_link_local); - TRACE_EVENT(hmdfs_show_comrade, TP_PROTO(struct dentry *d, struct dentry *lo_d, uint64_t devid), diff --git a/fs/hmdfs/inode_local.c b/fs/hmdfs/inode_local.c index 561b45dbb4654ea3139b7eea476956341c148304..04388c808c970dce864afebfec7c386871ef20c7 100644 --- a/fs/hmdfs/inode_local.c +++ b/fs/hmdfs/inode_local.c @@ -22,11 +22,6 @@ extern struct kmem_cache *hmdfs_dentry_cachep; -static const char *const symlink_tgt_white_list[] = { - "/storage/", - "/sdcard/", -}; - struct hmdfs_name_data { struct dir_context ctx; const struct qstr *to_find; @@ -61,11 +56,6 @@ int init_hmdfs_dentry_info(struct hmdfs_sb_info *sbi, struct dentry *dentry, return 0; } -static inline void set_symlink_flag(struct hmdfs_dentry_info *gdi) -{ - gdi->file_type = HM_SYMLINK; -} - static inline void set_sharefile_flag(struct hmdfs_dentry_info *gdi) { gdi->file_type = HM_SHARE; @@ -86,6 +76,7 @@ static inline void check_and_fixup_share_ops(struct inode *inode, struct inode *fill_inode_local(struct super_block *sb, struct inode *lower_inode, const char *name) { + int ret = 0; struct inode *inode; struct hmdfs_inode_info *info; @@ -113,8 +104,6 @@ struct inode *fill_inode_local(struct super_block *sb, else if (S_ISREG(lower_inode->i_mode)) inode->i_mode = (lower_inode->i_mode & S_IFMT) | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; - else if (S_ISLNK(lower_inode->i_mode)) - inode->i_mode = S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; #ifdef CONFIG_HMDFS_FS_PERMISSION inode->i_uid = lower_inode->i_uid; @@ -136,15 +125,18 @@ struct inode *fill_inode_local(struct super_block *sb, } else if (S_ISREG(lower_inode->i_mode)) { inode->i_op = &hmdfs_file_iops_local; inode->i_fop = &hmdfs_file_fops_local; - } else if (S_ISLNK(lower_inode->i_mode)) { - inode->i_op = &hmdfs_symlink_iops_local; - inode->i_fop = &hmdfs_file_fops_local; + } else { + ret = -EIO; + goto bad_inode; } fsstack_copy_inode_size(inode, lower_inode); check_and_fixup_share_ops(inode, name); unlock_new_inode(inode); return inode; +bad_inode: + iget_failed(inode); + return ERR_PTR(ret); } /* hmdfs_convert_lookup_flags - covert hmdfs lookup flags to vfs lookup flags @@ -270,8 +262,7 @@ struct dentry *hmdfs_lookup_local(struct inode *parent_inode, child_inode = fill_inode_local(parent_inode->i_sb, d_inode(lower_path.dentry), child_dentry->d_name.name); - if (S_ISLNK(d_inode(lower_path.dentry)->i_mode)) - set_symlink_flag(gdi); + if (IS_ERR(child_inode)) { err = PTR_ERR(child_inode); ret = ERR_PTR(err); @@ -702,145 +693,6 @@ int hmdfs_rename_local(struct inode *old_dir, struct dentry *old_dentry, return err; } -static bool symname_is_allowed(const char *symname) -{ - size_t symname_len = strlen(symname); - const char *prefix = NULL; - int i, total; - - /** - * Adjacent dots are prohibited. - * Note that vfs has escaped back slashes yet. - */ - for (i = 0; i < symname_len - 1; ++i) - if (symname[i] == '.' && symname[i + 1] == '.') - goto out_fail; - - /** - * Check if the symname is included in the whitelist - * Note that we skipped cmping strlen because symname is end with '\0' - */ - total = sizeof(symlink_tgt_white_list) / - sizeof(*symlink_tgt_white_list); - for (i = 0; i < total; ++i) { - prefix = symlink_tgt_white_list[i]; - if (!strncmp(symname, prefix, strlen(prefix))) - goto out_succ; - } - -out_fail: - hmdfs_err("Prohibited link path"); - return false; -out_succ: - return true; -} - -int hmdfs_symlink_local(struct inode *dir, struct dentry *dentry, - const char *symname) -{ - int err; - struct dentry *lower_dentry = NULL; - struct dentry *lower_parent_dentry = NULL; - struct path lower_path; - struct inode *child_inode = NULL; - struct inode *lower_dir_inode = hmdfs_i(dir)->lower_inode; - struct hmdfs_dentry_info *gdi = hmdfs_d(dentry); - kuid_t tmp_uid; -#ifdef CONFIG_HMDFS_FS_PERMISSION - const struct cred *saved_cred = NULL; - struct fs_struct *saved_fs = NULL, *copied_fs = NULL; - __u16 child_perm; -#endif - - if (unlikely(!symname_is_allowed(symname))) { - err = -EPERM; - goto path_err; - } - -#ifdef CONFIG_HMDFS_FS_PERMISSION - saved_cred = hmdfs_override_file_fsids(dir, &child_perm); - if (!saved_cred) { - err = -ENOMEM; - goto path_err; - } - - saved_fs = current->fs; - copied_fs = hmdfs_override_fsstruct(saved_fs); - if (!copied_fs) { - err = -ENOMEM; - goto revert_fsids; - } -#endif - hmdfs_get_lower_path(dentry, &lower_path); - lower_dentry = lower_path.dentry; - lower_parent_dentry = lock_parent(lower_dentry); - tmp_uid = hmdfs_override_inode_uid(lower_dir_inode); - err = vfs_symlink(lower_dir_inode, lower_dentry, symname); - hmdfs_revert_inode_uid(lower_dir_inode, tmp_uid); - unlock_dir(lower_parent_dentry); - if (err) - goto out_err; - set_symlink_flag(gdi); -#ifdef CONFIG_HMDFS_FS_PERMISSION - err = hmdfs_persist_perm(lower_dentry, &child_perm); -#endif - child_inode = fill_inode_local(dir->i_sb, d_inode(lower_dentry), - dentry->d_name.name); - if (IS_ERR(child_inode)) { - err = PTR_ERR(child_inode); - goto out_err; - } - d_add(dentry, child_inode); - fsstack_copy_attr_times(dir, lower_dir_inode); - fsstack_copy_inode_size(dir, lower_dir_inode); - -out_err: - hmdfs_put_lower_path(&lower_path); -#ifdef CONFIG_HMDFS_FS_PERMISSION - hmdfs_revert_fsstruct(saved_fs, copied_fs); -revert_fsids: - hmdfs_revert_fsids(saved_cred); -#endif -path_err: - trace_hmdfs_symlink_local(dir, dentry, err); - return err; -} - -static const char *hmdfs_get_link_local(struct dentry *dentry, - struct inode *inode, - struct delayed_call *done) -{ - const char *link = NULL; - struct dentry *lower_dentry = NULL; - struct inode *lower_inode = NULL; - struct path lower_path; - - if (!dentry) { - hmdfs_err("dentry NULL"); - link = ERR_PTR(-ECHILD); - goto link_out; - } - - hmdfs_get_lower_path(dentry, &lower_path); - lower_dentry = lower_path.dentry; - lower_inode = d_inode(lower_dentry); - if (!lower_inode->i_op || !lower_inode->i_op->get_link) { - hmdfs_err("The lower inode doesn't support get_link i_op"); - link = ERR_PTR(-EINVAL); - goto out; - } - - link = lower_inode->i_op->get_link(lower_dentry, lower_inode, done); - if (IS_ERR_OR_NULL(link)) - goto out; - fsstack_copy_attr_atime(inode, lower_inode); -out: - hmdfs_put_lower_path(&lower_path); - trace_hmdfs_get_link_local(inode, dentry, PTR_ERR_OR_ZERO(link)); -link_out: - return link; -} - static int hmdfs_setattr_local(struct dentry *dentry, struct iattr *ia) { struct inode *inode = d_inode(dentry); @@ -1037,19 +889,12 @@ struct dentry *hmdfs_lookup_share(struct inode *parent_inode, return ret; } -const struct inode_operations hmdfs_symlink_iops_local = { - .get_link = hmdfs_get_link_local, - .permission = hmdfs_permission, - .setattr = hmdfs_setattr_local, -}; - const struct inode_operations hmdfs_dir_inode_ops_local = { .lookup = hmdfs_lookup_local, .mkdir = hmdfs_mkdir_local, .create = hmdfs_create_local, .rmdir = hmdfs_rmdir_local, .unlink = hmdfs_unlink_local, - .symlink = hmdfs_symlink_local, .rename = hmdfs_rename_local, .permission = hmdfs_permission, .setattr = hmdfs_setattr_local, diff --git a/fs/hmdfs/inode_merge.c b/fs/hmdfs/inode_merge.c index f84f57d5e85c3664768b5c732f257fd765059ade..8315eba05cfcf094e8cfe75d18842a07904607a2 100644 --- a/fs/hmdfs/inode_merge.c +++ b/fs/hmdfs/inode_merge.c @@ -100,6 +100,7 @@ static struct inode *fill_inode_merge(struct super_block *sb, struct dentry *child_dentry, struct dentry *lo_d_dentry) { + int ret = 0; struct dentry *fst_lo_d = NULL; struct hmdfs_inode_info *info = NULL; struct inode *inode = NULL; @@ -138,32 +139,29 @@ static struct inode *fill_inode_merge(struct super_block *sb, update_inode_attr(inode, child_dentry); mode = d_inode(fst_lo_d)->i_mode; - /* remote symlink need to treat as regfile, - * the specific operation is performed by device_view. - * local symlink is managed by merge_view. - */ - if (hm_islnk(hmdfs_d(fst_lo_d)->file_type) && - hmdfs_d(fst_lo_d)->device_id == 0) { - inode->i_mode = S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; - inode->i_op = &hmdfs_symlink_iops_merge; - inode->i_fop = &hmdfs_file_fops_merge; - set_nlink(inode, 1); - } else if (S_ISREG(mode)) { // Reguler file 0660 + + if (S_ISREG(mode)) { inode->i_mode = S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; inode->i_op = &hmdfs_file_iops_merge; inode->i_fop = &hmdfs_file_fops_merge; set_nlink(inode, 1); - } else if (S_ISDIR(mode)) { // Directory 0771 + } else if (S_ISDIR(mode)) { inode->i_mode = S_IFDIR | S_IRWXU | S_IRWXG | S_IXOTH; inode->i_op = &hmdfs_dir_iops_merge; inode->i_fop = &hmdfs_dir_fops_merge; set_nlink(inode, get_num_comrades(child_dentry) + 2); + } else { + ret = -EIO; + goto bad_inode; } unlock_new_inode(inode); out: dput(fst_lo_d); return inode; +bad_inode: + iget_failed(inode); + return ERR_PTR(ret); } struct hmdfs_dentry_comrade *alloc_comrade(struct dentry *lo_d, int dev_id) @@ -596,10 +594,9 @@ struct dentry *hmdfs_lookup_merge(struct inode *parent_inode, /* * Internal flags like LOOKUP_CREATE should not pass to device view. * LOOKUP_REVAL is needed because dentry cache in hmdfs might be stale - * after rename in lower fs. LOOKUP_FOLLOW is not needed because - * get_link is defined for symlink inode in merge_view. - * LOOKUP_DIRECTORY is not needed because merge_view can do the - * judgement that whether result is directory or not. + * after rename in lower fs. LOOKUP_DIRECTORY is not needed because + * merge_view can do the judgement that whether result is directory or + * not. */ flags = flags & LOOKUP_REVAL; @@ -771,32 +768,6 @@ int do_create_merge(struct inode *parent_inode, struct dentry *child_dentry, return ret; } -int do_symlink_merge(struct inode *parent_inode, struct dentry *child_dentry, - const char *symname, struct inode *lower_parent_inode, - struct dentry *lo_d_child) -{ - int ret = 0; - struct super_block *sb = parent_inode->i_sb; - struct inode *child_inode = NULL; - - ret = vfs_symlink(lower_parent_inode, lo_d_child, symname); - if (ret) - goto out; - - child_inode = - fill_inode_merge(sb, parent_inode, child_dentry, lo_d_child); - if (IS_ERR(child_inode)) { - ret = PTR_ERR(child_inode); - goto out; - } - - d_add(child_dentry, child_inode); - fsstack_copy_attr_times(parent_inode, lower_parent_inode); - fsstack_copy_inode_size(parent_inode, lower_parent_inode); -out: - return ret; -} - int hmdfs_do_ops_merge(struct inode *i_parent, struct dentry *d_child, struct dentry *lo_d_child, struct path path, struct hmdfs_recursive_para *rec_op_para) @@ -816,12 +787,6 @@ int hmdfs_do_ops_merge(struct inode *i_parent, struct dentry *d_child, rec_op_para->want_excl, d_inode(path.dentry), lo_d_child); break; - case F_SYMLINK_MERGE: - ret = do_symlink_merge(i_parent, d_child, - rec_op_para->name, - d_inode(path.dentry), - lo_d_child); - break; default: ret = -EINVAL; break; @@ -1036,16 +1001,11 @@ int do_rmdir_merge(struct inode *dir, struct dentry *dentry) struct dentry *lo_d_dir = NULL; struct inode *lo_i_dir = NULL; - //TODO: 当前只删本地,因不会影响到图库场景 - //TODO:图库重启清除软连接?或者什么场景会删除 - //TODO: remove 调用同时删除空目录以及非空目录,结果不一致 - //TODO: 如果校验会不会有并发问题?就算锁,也只能锁自己 mutex_lock(&dim->comrade_list_lock); list_for_each_entry(comrade, &(dim->comrade_list), list) { lo_d = comrade->lo_d; lo_d_dir = lock_parent(lo_d); lo_i_dir = d_inode(lo_d_dir); - //TODO: 部分成功,lo_d确认 ret = vfs_rmdir(lo_i_dir, lo_d); unlock_dir(lo_d_dir); if (ret) @@ -1085,7 +1045,7 @@ int do_unlink_merge(struct inode *dir, struct dentry *dentry) struct dentry *lo_d = NULL; struct dentry *lo_d_dir = NULL; struct inode *lo_i_dir = NULL; - // TODO:文件场景 list_first_entry + mutex_lock(&dim->comrade_list_lock); list_for_each_entry(comrade, &(dim->comrade_list), list) { lo_d = comrade->lo_d; @@ -1121,34 +1081,6 @@ int hmdfs_unlink_merge(struct inode *dir, struct dentry *dentry) return ret; } -int hmdfs_symlink_merge(struct inode *dir, struct dentry *dentry, - const char *symname) -{ - int ret = 0; - struct hmdfs_recursive_para *rec_op_para = NULL; - - if (hmdfs_file_type(dentry->d_name.name) != HMDFS_TYPE_COMMON) { - ret = -EACCES; - goto out; - } - - rec_op_para = kmalloc(sizeof(*rec_op_para), GFP_KERNEL); - if (!rec_op_para) { - ret = -ENOMEM; - goto out; - } - hmdfs_init_recursive_para(rec_op_para, F_SYMLINK_MERGE, 0, false, - symname); - ret = create_lo_d_child(dir, dentry, false, rec_op_para); - -out: - trace_hmdfs_symlink_merge(dir, dentry, ret); - if (ret) - d_drop(dentry); - kfree(rec_op_para); - return ret; -} - int do_rename_merge(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags) @@ -1166,11 +1098,6 @@ 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; - /* TODO: Will WPS rename a temporary file to another directory? - * could flags with replace bit result in rename ops - * cross_devices? - * currently does not support replace flags. - */ if (flags & ~RENAME_NOREPLACE) { ret = -EINVAL; goto out; @@ -1302,56 +1229,12 @@ int hmdfs_rename_merge(struct inode *old_dir, struct dentry *old_dentry, return ret; } -static const char *hmdfs_get_link_merge(struct dentry *dentry, - struct inode *inode, - struct delayed_call *done) -{ - const char *link = NULL; - struct dentry *lower_dentry = NULL; - struct inode *lower_inode = NULL; - - if (!dentry) { - hmdfs_err("dentry NULL"); - link = ERR_PTR(-ECHILD); - goto link_out; - } - - lower_dentry = hmdfs_get_fst_lo_d(dentry); - if (!lower_dentry) { - WARN_ON(1); - link = ERR_PTR(-EINVAL); - goto out; - } - lower_inode = d_inode(lower_dentry); - if (!lower_inode->i_op || !lower_inode->i_op->get_link) { - hmdfs_err("lower inode hold no operations"); - link = ERR_PTR(-EINVAL); - goto out; - } - - link = lower_inode->i_op->get_link(lower_dentry, lower_inode, done); - if (IS_ERR_OR_NULL(link)) - goto out; - fsstack_copy_attr_atime(inode, lower_inode); -out: - dput(lower_dentry); - trace_hmdfs_get_link_merge(inode, dentry, PTR_ERR_OR_ZERO(link)); -link_out: - return link; -} - -const struct inode_operations hmdfs_symlink_iops_merge = { - .get_link = hmdfs_get_link_merge, - .permission = hmdfs_permission, -}; - const struct inode_operations hmdfs_dir_iops_merge = { .lookup = hmdfs_lookup_merge, .mkdir = hmdfs_mkdir_merge, .create = hmdfs_create_merge, .rmdir = hmdfs_rmdir_merge, .unlink = hmdfs_unlink_merge, - .symlink = hmdfs_symlink_merge, .rename = hmdfs_rename_merge, .permission = hmdfs_permission, }; diff --git a/fs/hmdfs/inode_remote.c b/fs/hmdfs/inode_remote.c index 78f04bdc4813985a9c1f10c1d546bca84cd038ac..32692b9ac67d6ada0dc18ca7a559bba63b06eda6 100644 --- a/fs/hmdfs/inode_remote.c +++ b/fs/hmdfs/inode_remote.c @@ -339,6 +339,7 @@ static void hmdfs_fill_inode_android(struct inode *inode, struct inode *dir, struct inode *fill_inode_remote(struct super_block *sb, struct hmdfs_peer *con, struct hmdfs_lookup_ret *res, struct inode *dir) { + int ret = 0; struct inode *inode = NULL; struct hmdfs_inode_info *info; umode_t mode = res->i_mode; @@ -372,24 +373,33 @@ struct inode *fill_inode_remote(struct super_block *sb, struct hmdfs_peer *con, inode->i_mode = S_IFDIR | S_IRWXU | S_IRWXG | S_IXOTH; else if (S_ISREG(mode)) inode->i_mode = S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; - else if (S_ISLNK(mode)) - inode->i_mode = S_IFREG | S_IRWXU | S_IRWXG; + else { + ret = -EIO; + goto bad_inode; + } - if (S_ISREG(mode) || S_ISLNK(mode)) { // Reguler file + if (S_ISREG(mode)) { inode->i_op = con->conn_operations->remote_file_iops; inode->i_fop = con->conn_operations->remote_file_fops; inode->i_size = res->i_size; set_nlink(inode, 1); - } else if (S_ISDIR(mode)) { // Directory + } else if (S_ISDIR(mode)) { inode->i_op = &hmdfs_dev_dir_inode_ops_remote; inode->i_fop = &hmdfs_dev_dir_ops_remote; set_nlink(inode, 2); + } else { + ret = -EIO; + goto bad_inode; } + inode->i_mapping->a_ops = con->conn_operations->remote_file_aops; hmdfs_fill_inode_android(inode, dir, mode); unlock_new_inode(inode); return inode; +bad_inode: + iget_failed(inode); + return ERR_PTR(ret); } static bool in_share_dir(struct dentry *child_dentry) @@ -447,8 +457,6 @@ static struct dentry *hmdfs_lookup_remote_dentry(struct inode *parent_inode, lookup_result = hmdfs_lookup_by_con(con, child_dentry, &qstr, flags, relative_path); if (lookup_result != NULL) { - if (S_ISLNK(lookup_result->i_mode)) - gdi->file_type = HM_SYMLINK; if (in_share_dir(child_dentry)) gdi->file_type = HM_SHARE; inode = fill_inode_remote(sb, con, lookup_result, parent_inode); diff --git a/fs/hmdfs/main.c b/fs/hmdfs/main.c index a490d069d239ebe101fb790a70df6a42a0b6a602..f692cfa8974787891ed4d3521764a717522b008b 100644 --- a/fs/hmdfs/main.c +++ b/fs/hmdfs/main.c @@ -238,7 +238,6 @@ void hmdfs_put_super(struct super_block *sb) hmdfs_info("local_dst is %s, local_src is %s", sbi->local_dst, sbi->local_src); - hmdfs_fault_inject_fini(&sbi->fault_inject); hmdfs_cfn_destroy(sbi); hmdfs_unregister_sysfs(sbi); hmdfs_connections_stop(sbi); @@ -923,7 +922,6 @@ static int hmdfs_fill_super(struct super_block *sb, void *data, int silent) INIT_LIST_HEAD(&sbi->hsi.wait_list); INIT_LIST_HEAD(&sbi->hsi.pending_list); spin_lock_init(&sbi->hsi.list_lock); - hmdfs_fault_inject_init(&sbi->fault_inject, ctrl_path); return err; out_freeroot: @@ -1054,7 +1052,6 @@ static int __init hmdfs_init(void) goto out_err; hmdfs_message_verify_init(); - hmdfs_create_debugfs_root(); return 0; out_err: hmdfs_sysfs_exit(); @@ -1067,7 +1064,6 @@ static int __init hmdfs_init(void) static void __exit hmdfs_exit(void) { - hmdfs_destroy_debugfs_root(); hmdfs_sysfs_exit(); hmdfs_exit_configfs(); unregister_filesystem(&hmdfs_fs_type); diff --git a/fs/hmdfs/stash.c b/fs/hmdfs/stash.c index c320af7f60e0d42372c39a74709e1cdff7f36c74..413720404cc707bc72561c195054cfea9dbdb244 100644 --- a/fs/hmdfs/stash.c +++ b/fs/hmdfs/stash.c @@ -2179,7 +2179,7 @@ hmdfs_need_rebuild_inode_stash_status(struct hmdfs_peer *conn, umode_t mode) { return hmdfs_is_stash_enabled(conn->sbi) && READ_ONCE(conn->need_rebuild_stash_list) && - (S_ISREG(mode) || S_ISLNK(mode)); + S_ISREG(mode); } void hmdfs_remote_init_stash_status(struct hmdfs_peer *conn,