From 51eacaed96b7bf6f98a117fdcc7ec03ba30a731d Mon Sep 17 00:00:00 2001 From: y30045862 Date: Thu, 12 Sep 2024 18:03:23 +0800 Subject: [PATCH] cherry-pick recent changes from 5.10 Signed-off-by: yangjingbo10 --- fs/hmdfs/comm/connection.c | 5 ---- fs/hmdfs/inode_cloud.c | 6 ++++- fs/hmdfs/inode_local.c | 7 +++++- fs/sharefs/authentication.c | 2 +- fs/sharefs/authentication.h | 4 +++ fs/sharefs/file.c | 6 ++--- fs/sharefs/inode.c | 49 ++----------------------------------- fs/sharefs/main.c | 10 ++++---- fs/sharefs/sharefs.h | 2 ++ fs/sharefs/super.c | 14 +++++++++-- 10 files changed, 39 insertions(+), 66 deletions(-) diff --git a/fs/hmdfs/comm/connection.c b/fs/hmdfs/comm/connection.c index 046688747d83..44a4cb93354f 100644 --- a/fs/hmdfs/comm/connection.c +++ b/fs/hmdfs/comm/connection.c @@ -640,11 +640,6 @@ void connection_handshake_recv_handler(struct connection *conn_impl, void *buf, hmdfs_info( "Recved handshake response: device_id = %llu, cmd->status = %hhu, tcp->fd = %d", conn_impl->node->device_id, status, fd); - if (status == CONNECT_STAT_WAIT_REQUEST) { - // must be 10.1 device, no need to set ktls - connection_to_working(conn_impl->node); - goto out; - } ret = hs_proc_msg_data(conn_impl, ops, data, data_len); if (ret) diff --git a/fs/hmdfs/inode_cloud.c b/fs/hmdfs/inode_cloud.c index 4f1caf7bd325..6099f1336f3d 100644 --- a/fs/hmdfs/inode_cloud.c +++ b/fs/hmdfs/inode_cloud.c @@ -286,6 +286,10 @@ static struct dentry *hmdfs_lookup_cloud_dentry(struct inode *parent_inode, if (in_share_dir(child_dentry)) gdi->file_type = HM_SHARE; inode = fill_inode_cloud(sb, lookup_result, parent_inode); + if (IS_ERR(inode)) { + ret = ERR_CAST(inode); + goto out; + } check_and_fixup_ownership_remote(parent_inode, inode, @@ -296,7 +300,7 @@ static struct dentry *hmdfs_lookup_cloud_dentry(struct inode *parent_inode, } else { ret = ERR_PTR(-ENOENT); } - +out: kfree(lookup_result); return ret; } diff --git a/fs/hmdfs/inode_local.c b/fs/hmdfs/inode_local.c index 4fd799a21645..e18fd022cd01 100644 --- a/fs/hmdfs/inode_local.c +++ b/fs/hmdfs/inode_local.c @@ -38,7 +38,6 @@ int init_hmdfs_dentry_info(struct hmdfs_sb_info *sbi, struct dentry *dentry, if (!info) return -ENOMEM; - dentry->d_fsdata = info; INIT_LIST_HEAD(&info->cache_list_head); INIT_LIST_HEAD(&info->remote_cache_list_head); spin_lock_init(&info->cache_list_lock); @@ -47,6 +46,7 @@ int init_hmdfs_dentry_info(struct hmdfs_sb_info *sbi, struct dentry *dentry, spin_lock_init(&info->lock); info->dentry_type = dentry_type; info->device_id = 0; + dentry->d_fsdata = info; if (dentry_type == HMDFS_LAYER_ZERO || dentry_type == HMDFS_LAYER_FIRST_DEVICE || dentry_type == HMDFS_LAYER_SECOND_LOCAL || @@ -920,6 +920,11 @@ static int hmdfs_getattr_local(struct mnt_idmap *idmap, const struct path *path, struct path lower_path; int ret; + if (path->dentry == NULL || hmdfs_d(path->dentry) == NULL) { + hmdfs_err("dentry is NULL"); + return -ENOENT; + } + hmdfs_get_lower_path(path->dentry, &lower_path); ret = vfs_getattr(&lower_path, stat, request_mask, flags); stat->ino = d_inode(path->dentry)->i_ino; diff --git a/fs/sharefs/authentication.c b/fs/sharefs/authentication.c index bc6e825092fa..39997c632491 100644 --- a/fs/sharefs/authentication.c +++ b/fs/sharefs/authentication.c @@ -95,4 +95,4 @@ void sharefs_revert_fsids(const struct cred *old_cred) revert_creds(old_cred); put_cred(cur_cred); } -#endif +#endif \ No newline at end of file diff --git a/fs/sharefs/authentication.h b/fs/sharefs/authentication.h index 165b66fc9c4f..c9875d376545 100644 --- a/fs/sharefs/authentication.h +++ b/fs/sharefs/authentication.h @@ -4,6 +4,8 @@ * * Copyright (c) 2023 Huawei Device Co., Ltd. */ +#ifndef AUTHENTICATION_H +#define AUTHENTICATION_H #include "sharefs.h" @@ -73,3 +75,5 @@ static inline int get_bundle_uid(struct sharefs_sb_info *sbi, const char *bname) { return sbi->user_id * BASE_USER_RANGE + get_bid_config(bname); } + +#endif //_AUTHENTICATION_H_ \ No newline at end of file diff --git a/fs/sharefs/file.c b/fs/sharefs/file.c index 97547da440b3..bf5dbb34608b 100644 --- a/fs/sharefs/file.c +++ b/fs/sharefs/file.c @@ -157,8 +157,7 @@ static loff_t sharefs_file_llseek(struct file *file, loff_t offset, int whence) /* * Sharefs read_iter, redirect modified iocb to lower read_iter */ -ssize_t -sharefs_read_iter(struct kiocb *iocb, struct iov_iter *iter) +ssize_t sharefs_read_iter(struct kiocb *iocb, struct iov_iter *iter) { int err; struct file *file = iocb->ki_filp; @@ -188,8 +187,7 @@ sharefs_read_iter(struct kiocb *iocb, struct iov_iter *iter) /* * Sharefs write_iter, redirect modified iocb to lower write_iter */ -ssize_t -sharefs_write_iter(struct kiocb *iocb, struct iov_iter *iter) +ssize_t sharefs_write_iter(struct kiocb *iocb, struct iov_iter *iter) { int err; struct file *file = iocb->ki_filp; diff --git a/fs/sharefs/inode.c b/fs/sharefs/inode.c index 79a3f841e4a2..e31baf4bd415 100644 --- a/fs/sharefs/inode.c +++ b/fs/sharefs/inode.c @@ -14,50 +14,6 @@ #include "authentication.h" #endif -static const char *sharefs_get_link(struct dentry *dentry, struct inode *inode, - struct delayed_call *done) -{ - DEFINE_DELAYED_CALL(lower_done); - struct dentry *lower_dentry; - struct path lower_path; - char *buf; - const char *lower_link; - - if (!dentry) - return ERR_PTR(-ECHILD); - - sharefs_get_lower_path(dentry, &lower_path); - lower_dentry = lower_path.dentry; - - /* - * get link from lower file system, but use a separate - * delayed_call callback. - */ - lower_link = vfs_get_link(lower_dentry, &lower_done); - if (IS_ERR(lower_link)) { - buf = ERR_CAST(lower_link); - goto out; - } - - /* - * we can't pass lower link up: have to make private copy and - * pass that. - */ - buf = kstrdup(lower_link, GFP_KERNEL); - do_delayed_call(&lower_done); - if (!buf) { - buf = ERR_PTR(-ENOMEM); - goto out; - } - - fsstack_copy_attr_atime(d_inode(dentry), d_inode(lower_dentry)); - - set_delayed_call(done, kfree_link, buf); -out: - sharefs_put_lower_path(dentry, &lower_path); - return buf; -} - static int sharefs_getattr(struct mnt_idmap *idmap, const struct path *path, struct kstat *stat, u32 request_mask, unsigned int flags) { @@ -77,8 +33,7 @@ static int sharefs_getattr(struct mnt_idmap *idmap, const struct path *path, str return ret; } -static ssize_t -sharefs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size) +static ssize_t sharefs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size) { int err; struct dentry *lower_dentry; @@ -393,7 +348,7 @@ static int sharefs_setattr(struct dentry *dentry, struct iattr *ia) const struct inode_operations sharefs_symlink_iops = { .permission = sharefs_permission, .getattr = sharefs_getattr, - .get_link = sharefs_get_link, + .get_link = NULL, .listxattr = sharefs_listxattr, }; diff --git a/fs/sharefs/main.c b/fs/sharefs/main.c index 6a858b49f73b..f83d5e71df4c 100644 --- a/fs/sharefs/main.c +++ b/fs/sharefs/main.c @@ -145,7 +145,6 @@ static struct file_system_type sharefs_fs_type = { .kill_sb = generic_shutdown_super, .fs_flags = 0, }; -MODULE_ALIAS_FS(SHAREFS_NAME); static int __init init_sharefs_fs(void) { @@ -182,12 +181,13 @@ static void __exit exit_sharefs_fs(void) sharefs_destroy_inode_cache(); sharefs_destroy_dentry_cache(); unregister_filesystem(&sharefs_fs_type); + sharefs_exit_configfs(); pr_info("Completed sharefs module unload\n"); } -MODULE_AUTHOR("Jingjing Mao"); -MODULE_DESCRIPTION("Sharefs"); -MODULE_LICENSE("GPL"); - module_init(init_sharefs_fs); module_exit(exit_sharefs_fs); + +MODULE_LICENSE("GPL V2"); +MODULE_DESCRIPTION("Share File System"); +MODULE_ALIAS_FS("sharefs"); \ No newline at end of file diff --git a/fs/sharefs/sharefs.h b/fs/sharefs/sharefs.h index 5ac090fc96ae..fe3067ce5124 100644 --- a/fs/sharefs/sharefs.h +++ b/fs/sharefs/sharefs.h @@ -64,6 +64,8 @@ struct sharefs_sb_info { struct super_block *lower_sb; /* multi user */ unsigned int user_id; + bool override; + bool override_support_delete; }; /* operations vectors defined in specific files */ diff --git a/fs/sharefs/super.c b/fs/sharefs/super.c index bbe65944647f..cba0d2206615 100644 --- a/fs/sharefs/super.c +++ b/fs/sharefs/super.c @@ -13,12 +13,16 @@ enum { OPT_USER_ID, - OPT_ERR, + OPT_OVERRIDE, + OPT_OVERRIDE_SUPPORT_DELETE, + OPT_ERR, }; static match_table_t sharefs_tokens = { { OPT_USER_ID, "user_id=%s" }, - { OPT_ERR, NULL } + { OPT_OVERRIDE, "override" }, + { OPT_OVERRIDE_SUPPORT_DELETE, "override_support_delete" }, + { OPT_ERR, NULL } }; int sharefs_parse_options(struct sharefs_sb_info *sbi, const char *data) @@ -58,6 +62,12 @@ int sharefs_parse_options(struct sharefs_sb_info *sbi, const char *data) sbi->user_id = user_id; } break; + case OPT_OVERRIDE: + sbi->override = true; + break; + case OPT_OVERRIDE_SUPPORT_DELETE: + sbi->override_support_delete = true; + break; default: err = -EINVAL; goto out; -- Gitee