From 068e87b7ffc2d168cedd409e48e262b8dc0b9017 Mon Sep 17 00:00:00 2001 From: ChenXiaoSong Date: Thu, 7 Aug 2025 23:46:45 +0800 Subject: [PATCH 1/9] nfs/enfs: fix memory leak of shard_view_ctrl when removing nfs module kylin inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ICRY17 -------------------------------- The original shard_view_ctrl cannot be found when adding the enfs module for the second time. Fix this by freeing shard_view_ctrl when removing the enfs module. Fixes: 18e360871c3f ("add enfs feature") Signed-off-by: ChenXiaoSong --- fs/nfs/enfs/shard_route.c | 15 ++++++--------- fs/nfs/enfs_adapter.c | 13 ------------- fs/nfs/enfs_adapter.h | 3 --- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/fs/nfs/enfs/shard_route.c b/fs/nfs/enfs/shard_route.c index 94de3886e9bc..105753d464f4 100644 --- a/fs/nfs/enfs/shard_route.c +++ b/fs/nfs/enfs/shard_route.c @@ -1683,7 +1683,7 @@ static int shard_update_loop(void *data) return 0; } -static void enfs_clear_shard_ctrl(void) +static void enfs_shard_ctrl_clear(void) { struct clnt_uuid_info *info, *tmp_info; struct view_table *table, *tmp_table; @@ -1700,18 +1700,15 @@ static void enfs_clear_shard_ctrl(void) enfs_free_view_table(table); } write_unlock(&shard_ctrl->view_lock); + + kfree(shard_ctrl); + shard_ctrl = NULL; } static struct shard_view_ctrl *enfs_shard_ctrl_init(void) { struct shard_view_ctrl *ctrl; - ctrl = enfs_adapter_get_data(); - if (ctrl) { - enfs_log_info("existing shard ctrl is obtained.\n"); - return ctrl; - } - ctrl = kmalloc(sizeof(*ctrl), GFP_KERNEL); if (!ctrl) { enfs_log_error("shard view ctrl alloc failed.\n"); @@ -1722,7 +1719,6 @@ static struct shard_view_ctrl *enfs_shard_ctrl_init(void) rwlock_init(&ctrl->view_lock); INIT_LIST_HEAD(&ctrl->clnt_info_list); rwlock_init(&ctrl->clnt_info_lock); - enfs_adapter_set_data((void *)ctrl); return ctrl; } @@ -1759,5 +1755,6 @@ void enfs_shard_exit(void) destroy_workqueue(shard_workq); } - enfs_clear_shard_ctrl(); + if (shard_ctrl) + enfs_shard_ctrl_clear(); } diff --git a/fs/nfs/enfs_adapter.c b/fs/nfs/enfs_adapter.c index 470eef06eb21..1d3c3a3c9f20 100644 --- a/fs/nfs/enfs_adapter.c +++ b/fs/nfs/enfs_adapter.c @@ -19,19 +19,6 @@ static struct enfs_adapter_ops __rcu *enfs_adapter; static DEFINE_MUTEX(enfs_module_mutex); -static void *enfs_adapter_data; - -void *enfs_adapter_get_data(void) -{ - return enfs_adapter_data; -} -EXPORT_SYMBOL_GPL(enfs_adapter_get_data); - -void enfs_adapter_set_data(void *data) -{ - enfs_adapter_data = data; -} -EXPORT_SYMBOL_GPL(enfs_adapter_set_data); int enfs_adapter_register(struct enfs_adapter_ops *ops) { diff --git a/fs/nfs/enfs_adapter.h b/fs/nfs/enfs_adapter.h index 9cd2e2acdfd3..e6f127181278 100644 --- a/fs/nfs/enfs_adapter.h +++ b/fs/nfs/enfs_adapter.h @@ -47,9 +47,6 @@ struct enfs_adapter_ops { void (*trigger_get_capability)(struct nfs_server *server); }; -void *enfs_adapter_get_data(void); -void enfs_adapter_set_data(void *data); - int enfs_parse_mount_options(enum nfsmultipathoptions option, char *str, struct nfs_fs_context *mnt, struct fs_context *fc); void enfs_free_mount_options(struct nfs_fs_context *data); -- Gitee From 0b85eddf5ae7ab0cf1aec485e0e2fbd13b38ff1b Mon Sep 17 00:00:00 2001 From: ChenXiaoSong Date: Thu, 7 Aug 2025 19:56:58 +0800 Subject: [PATCH 2/9] nfs/enfs: set CONFIG_SUNRPC_ENFS=y by default kylin inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ICRY17 -------------------------------- CONFIG_SUNRPC_ENFS has already been changed from a tristate to a bool. Fixes: 2b5eae5c990f ("sunrpc, nfs: fix build errors when CONFIG_SUNRPC_ENFS=m && CONFIG_ENFS=m && CONFIG_NFS=y") Signed-off-by: ChenXiaoSong --- arch/arm64/configs/openeuler_defconfig | 2 +- arch/x86/configs/openeuler_defconfig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/configs/openeuler_defconfig b/arch/arm64/configs/openeuler_defconfig index 773389ef1565..37c970407d37 100644 --- a/arch/arm64/configs/openeuler_defconfig +++ b/arch/arm64/configs/openeuler_defconfig @@ -7266,7 +7266,7 @@ CONFIG_NFS_ACL_SUPPORT=m CONFIG_NFS_COMMON=y CONFIG_NFS_V4_2_SSC_HELPER=y CONFIG_ENFS=m -CONFIG_SUNRPC_ENFS=m +CONFIG_SUNRPC_ENFS=y CONFIG_SUNRPC=m CONFIG_SUNRPC_GSS=m CONFIG_SUNRPC_BACKCHANNEL=y diff --git a/arch/x86/configs/openeuler_defconfig b/arch/x86/configs/openeuler_defconfig index 52e6ccad8aa8..d00c4dd20b0f 100644 --- a/arch/x86/configs/openeuler_defconfig +++ b/arch/x86/configs/openeuler_defconfig @@ -8455,7 +8455,7 @@ CONFIG_NFS_ACL_SUPPORT=m CONFIG_NFS_COMMON=y CONFIG_NFS_V4_2_SSC_HELPER=y CONFIG_ENFS=m -CONFIG_SUNRPC_ENFS=m +CONFIG_SUNRPC_ENFS=y CONFIG_SUNRPC=m CONFIG_SUNRPC_GSS=m CONFIG_SUNRPC_BACKCHANNEL=y -- Gitee From 59da5fcc7897637e47a2f7c63535379b01e26909 Mon Sep 17 00:00:00 2001 From: ChenXiaoSong Date: Mon, 11 Aug 2025 21:19:58 +0800 Subject: [PATCH 3/9] nfs/enfs: fix alignment between struct rpc_clnt and rpc_clnt_reserve kylin inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ICRY17 -------------------------------- In order to maintain the code more easily, remove struct rpc_clnt_reserve, and add cl_enfs field to struct rpc_clnt. Fixes: 18e360871c3f ("add enfs feature") Signed-off-by: ChenXiaoSong --- fs/nfs/enfs/enfs_multipath.c | 9 +-------- fs/nfs/enfs/enfs_proc.c | 16 ++++------------ fs/nfs/enfs/enfs_roundrobin.c | 7 ++----- fs/nfs/enfs/failover_com.h | 12 +++++------- fs/nfs/enfs/failover_path.c | 6 ++---- fs/nfs/enfs/pm_ping.c | 4 +--- include/linux/sunrpc/clnt.h | 32 +++++--------------------------- net/sunrpc/sunrpc_enfs_adapter.c | 6 +----- 8 files changed, 21 insertions(+), 71 deletions(-) diff --git a/fs/nfs/enfs/enfs_multipath.c b/fs/nfs/enfs/enfs_multipath.c index 297b4737647c..fd7990b54742 100644 --- a/fs/nfs/enfs/enfs_multipath.c +++ b/fs/nfs/enfs/enfs_multipath.c @@ -669,13 +669,6 @@ struct xprts_options_and_clnt { void *data; }; -static void set_clnt_enfs_flag(struct rpc_clnt *clnt) -{ - struct rpc_clnt_reserve *clnt_reserve = (struct rpc_clnt_reserve *)clnt; - - clnt_reserve->cl_enfs = 1; -} - int enfs_config_xprt_create_args(struct xprt_create *xprtargs, struct rpc_create_args *args, char *servername, size_t length) @@ -882,7 +875,7 @@ int enfs_multipath_create_thread(void *data) if (errno != 0) enfs_log_error("create clnt proc failed.\n"); - set_clnt_enfs_flag(create_args->clnt); + create_args->clnt->cl_enfs = 1; enfs_xprt_ippair_create(&xprtargs, create_args->clnt, mount_options); kfree(create_args->args); diff --git a/fs/nfs/enfs/enfs_proc.c b/fs/nfs/enfs/enfs_proc.c index 1b15102bdd64..ba3d19d1e58c 100644 --- a/fs/nfs/enfs/enfs_proc.c +++ b/fs/nfs/enfs/enfs_proc.c @@ -97,10 +97,8 @@ static int debug_show_xprt(struct rpc_clnt *clnt, struct rpc_xprt *xprt, static int debug_show_clnt(struct rpc_clnt *clnt, void *data) { - struct rpc_clnt_reserve *clnt_reserve = (struct rpc_clnt_reserve *)clnt; - enfs_log_info("clnt %d addr:%p enfs:%d\n", clnt->cl_clid, clnt, - clnt_reserve->cl_enfs); + clnt->cl_enfs); rpc_clnt_iterate_for_each_xprt(clnt, debug_show_xprt, NULL); return 0; } @@ -504,9 +502,7 @@ int enfs_proc_create_clnt(struct rpc_clnt *clnt) void enfs_proc_delete_clnt(struct rpc_clnt *clnt) { - struct rpc_clnt_reserve *clnt_reserve = (struct rpc_clnt_reserve *)clnt; - - if (clnt_reserve->cl_enfs == 1) { + if (clnt->cl_enfs == 1) { enfs_proc_delete_file(clnt); enfs_clnt_release_linkcap(clnt); } @@ -598,9 +594,7 @@ static void enfs_proc_delete_parent(void) static int enfs_proc_init_create_clnt(struct rpc_clnt *clnt, void *data) { - struct rpc_clnt_reserve *clnt_reserve = (struct rpc_clnt_reserve *)clnt; - - if (clnt_reserve->cl_enfs == 1) { + if (clnt->cl_enfs == 1) { enfs_proc_create_file(clnt); enfs_clnt_get_linkcap(clnt); } @@ -609,9 +603,7 @@ static int enfs_proc_init_create_clnt(struct rpc_clnt *clnt, void *data) static int enfs_proc_destroy_clnt(struct rpc_clnt *clnt, void *data) { - struct rpc_clnt_reserve *clnt_reserve = (struct rpc_clnt_reserve *)clnt; - - if (clnt_reserve->cl_enfs == 1) + if (clnt->cl_enfs == 1) enfs_proc_delete_file(clnt); return 0; } diff --git a/fs/nfs/enfs/enfs_roundrobin.c b/fs/nfs/enfs/enfs_roundrobin.c index 45ad65c52120..8129c461e24d 100644 --- a/fs/nfs/enfs/enfs_roundrobin.c +++ b/fs/nfs/enfs/enfs_roundrobin.c @@ -263,9 +263,7 @@ static struct rpc_xprt *enfs_lb_iter_current_entry(struct rpc_xprt_iter *xpi) int enfs_lb_set_policy(struct rpc_clnt *clnt, void *data) { - struct rpc_clnt_reserve *clnt_reserve = (struct rpc_clnt_reserve *)clnt; - - if (clnt_reserve->cl_enfs == 1) + if (clnt->cl_enfs == 1) enfs_lb_switch_set_roundrobin(clnt); return 0; @@ -332,9 +330,8 @@ bool enfs_is_singularr_route(struct rpc_clnt *clnt) int enfs_lb_revert_policy(struct rpc_clnt *clnt, void *data) { struct rpc_xprt_switch *xps; - struct rpc_clnt_reserve *clnt_reserve = (struct rpc_clnt_reserve *)clnt; - if (clnt_reserve->cl_enfs == 1) { + if (clnt->cl_enfs == 1) { rcu_read_lock(); xps = rcu_dereference(clnt->cl_xpi.xpi_xpswitch); rcu_read_unlock(); diff --git a/fs/nfs/enfs/failover_com.h b/fs/nfs/enfs/failover_com.h index bcf29a6d54be..691be28f0d2c 100644 --- a/fs/nfs/enfs/failover_com.h +++ b/fs/nfs/enfs/failover_com.h @@ -9,19 +9,17 @@ static inline bool failover_is_enfs_clnt(struct rpc_clnt *clnt) { struct rpc_clnt *next = clnt->cl_parent; - struct rpc_clnt_reserve *clnt_reserve; + struct rpc_clnt *target = clnt; while (next) { if (next == next->cl_parent) break; next = next->cl_parent; } - if (next != NULL) { - clnt_reserve = (struct rpc_clnt_reserve *)next; - return clnt_reserve->cl_enfs == 1 ? true : false; - } - clnt_reserve = (struct rpc_clnt_reserve *)clnt; - return clnt_reserve->cl_enfs == 1 ? true : false; + + if (next != NULL) + target = next; + return target->cl_enfs == 1 ? true : false; } #endif // FAILOVER_COMMON_H diff --git a/fs/nfs/enfs/failover_path.c b/fs/nfs/enfs/failover_path.c index 8e4dd8a7416a..59b40bd73597 100644 --- a/fs/nfs/enfs/failover_path.c +++ b/fs/nfs/enfs/failover_path.c @@ -251,7 +251,6 @@ void failover_reselect_transport(struct rpc_task *task, struct rpc_clnt *clnt) struct rpc_xprt *old; struct rpc_xprt *parent_cursor; struct rpc_clnt *parent_clnt = clnt; - struct rpc_clnt_reserve *clnt_reserve; if (task->tk_xprt && !failover_prepare_transmit(task)) { reselect_xprt(task); @@ -264,9 +263,8 @@ void failover_reselect_transport(struct rpc_task *task, struct rpc_clnt *clnt) parent_clnt = parent_clnt->cl_parent; } while (parent_clnt); - clnt_reserve = (struct rpc_clnt_reserve *)parent_clnt; - if (task->tk_xprt && clnt->cl_vers == 4 && clnt_reserve && - clnt_reserve->cl_enfs) { + if (task->tk_xprt && clnt->cl_vers == 4 && parent_clnt && + parent_clnt->cl_enfs) { old = smp_load_acquire(cursor); // multi thread to access parent_cursor = xprt_iter_get_xprt(&parent_clnt->cl_xpi); if (parent_cursor != old) diff --git a/fs/nfs/enfs/pm_ping.c b/fs/nfs/enfs/pm_ping.c index aa0514768aee..934ec656b5b8 100644 --- a/fs/nfs/enfs/pm_ping.c +++ b/fs/nfs/enfs/pm_ping.c @@ -294,13 +294,11 @@ static int pm_ping_execute_xprt_test(struct rpc_clnt *clnt, static void pm_ping_loop_rpclnt(struct sunrpc_net *sn) { struct rpc_clnt *clnt; - struct rpc_clnt_reserve *clnt_reserve; LIST_HEAD(free_list); spin_lock(&sn->rpc_client_lock); list_for_each_entry_rcu(clnt, &sn->all_clients, cl_clients) { - clnt_reserve = (struct rpc_clnt_reserve *)clnt; - if (clnt_reserve->cl_enfs == 1) { + if (clnt->cl_enfs == 1) { enfs_log_debug("find rpc_clnt. %p\n", clnt); rpc_clnt_iterate_for_each_xprt(clnt, pm_ping_execute_xprt_test, (void *)&free_list); diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h index 09b35d932c70..0fb4b34b184c 100644 --- a/include/linux/sunrpc/clnt.h +++ b/include/linux/sunrpc/clnt.h @@ -38,33 +38,6 @@ struct rpc_sysfs_client { struct rpc_xprt_switch *xprt_switch; }; -#if IS_ENABLED(CONFIG_SUNRPC_ENFS) -struct rpc_clnt_reserve { - atomic_t cl_count; /* Number of references */ - unsigned int cl_clid; /* client id */ - struct list_head cl_clients; /* Global list of clients */ - struct list_head cl_tasks; /* List of tasks */ - spinlock_t cl_lock; /* spinlock */ - struct rpc_xprt __rcu *cl_xprt; /* transport */ - const struct rpc_procinfo *cl_procinfo; /* procedure info */ - u32 cl_prog, /* RPC program number */ - cl_vers, /* RPC version number */ - cl_maxproc; /* max procedure number */ - - struct rpc_auth *cl_auth; /* authenticator */ - struct rpc_stat *cl_stats; /* per-program statistics */ - struct rpc_iostats *cl_metrics; /* per-client statistics */ - - unsigned int cl_softrtry : 1,/* soft timeouts */ - cl_discrtry : 1,/* disconnect before retry */ - cl_noretranstimeo: 1,/* No retransmit timeouts */ - cl_autobind : 1,/* use getport() */ - cl_chatty : 1,/* be verbose */ - cl_reserve : 11,/* reserve bits */ - cl_enfs : 1;/* be enfs */ -}; -#endif - /* * The high-level client handle */ @@ -91,7 +64,12 @@ struct rpc_clnt { cl_noretranstimeo: 1,/* No retransmit timeouts */ cl_autobind : 1,/* use getport() */ cl_chatty : 1,/* be verbose */ +#if defined(__GENKSYMS__) || !IS_ENABLED(CONFIG_SUNRPC_ENFS) cl_shutdown : 1;/* rpc immediate -EIO */ +#else + cl_shutdown : 1,/* rpc immediate -EIO */ + cl_enfs : 1;/* be enfs */ +#endif struct xprtsec_parms cl_xprtsec; /* transport security policy */ struct rpc_rtt * cl_rtt; /* RTO estimator data */ diff --git a/net/sunrpc/sunrpc_enfs_adapter.c b/net/sunrpc/sunrpc_enfs_adapter.c index 2515a9945d43..5905b9ccde4c 100644 --- a/net/sunrpc/sunrpc_enfs_adapter.c +++ b/net/sunrpc/sunrpc_enfs_adapter.c @@ -216,11 +216,7 @@ void rpc_multipath_ops_update_rpc_program(struct rpc_task *task, u32 *cl_prog, u bool rpc_clnt_has_multipath(struct rpc_clnt *clnt) { - struct rpc_clnt_reserve *clnt_reserve; - - clnt_reserve = (struct rpc_clnt_reserve *)clnt; - - return clnt_reserve->cl_enfs ? true : false; + return clnt->cl_enfs ? true : false; } void rpc_multipath_ops_xprt_iostat(struct rpc_task *task) -- Gitee From ef21a71a781b6fb424d5aa0229b37be4788e3136 Mon Sep 17 00:00:00 2001 From: ChenXiaoSong Date: Tue, 12 Aug 2025 21:08:02 +0800 Subject: [PATCH 4/9] nfs/enfs: fix error when showing dns list kylin inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ICRY17 -------------------------------- There is error when showing dns list: mount -t nfs -o vers=3,...,remoteaddrs=server1.com~server2.com server2.com:/svr/export /mnt/ mount | grep nfs server2.com:/svr/export on /mnt type nfs (...,remoteaddrs=server1.com~server1.com~server2.com,...) "server1.com" is printed twice. Fix this by adding the missing "else". Fixes: 18e360871c3f ("add enfs feature") Signed-off-by: ChenXiaoSong --- fs/nfs/enfs/enfs_multipath_client.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/nfs/enfs/enfs_multipath_client.c b/fs/nfs/enfs/enfs_multipath_client.c index 916e065622af..ec9c6703bc67 100644 --- a/fs/nfs/enfs/enfs_multipath_client.c +++ b/fs/nfs/enfs/enfs_multipath_client.c @@ -340,7 +340,8 @@ void print_dns_info(struct seq_file *seq, struct enfs_route_dns_info *pRemoteDns name = pRemoteDnsInfo->routeRemoteDnsList[i].dnsname; if (i == 0) seq_printf(seq, "%s", name); - seq_printf(seq, "~%s", name); + else + seq_printf(seq, "~%s", name); } } -- Gitee From 7d7c14ce5591646018ff176c1e232eef23c332fb Mon Sep 17 00:00:00 2001 From: ChenXiaoSong Date: Tue, 12 Aug 2025 21:33:50 +0800 Subject: [PATCH 5/9] nfs/enfs: support debugging ip and dns list kylin inclusion category: cleanup bugzilla: https://gitee.com/openeuler/kernel/issues/ICRY17 -------------------------------- Preparation for debugging ip and dns list. Signed-off-by: ChenXiaoSong --- fs/nfs/enfs/enfs_multipath_client.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/fs/nfs/enfs/enfs_multipath_client.c b/fs/nfs/enfs/enfs_multipath_client.c index ec9c6703bc67..15cfbec89282 100644 --- a/fs/nfs/enfs/enfs_multipath_client.c +++ b/fs/nfs/enfs/enfs_multipath_client.c @@ -307,25 +307,29 @@ int nfs4_multipath_client_info_match(void *src, void *dst) return ret; } -void print_ip_info(struct seq_file *mount_option, struct nfs_ip_list *ip_list, +void print_ip_info(struct seq_file *seq, struct nfs_ip_list *ip_list, const char *type) { char buf[IP_ADDRESS_LEN_MAX + 1]; int len = 0; int i = 0; - seq_printf(mount_option, ",%s=", type); + if (seq) + seq_printf(seq, ",%s=", type); + enfs_log_debug("%s ip list:\n", type); + for (i = 0; i < ip_list->count; i++) { len = rpc_ntop((struct sockaddr *)&ip_list->address[i], buf, IP_ADDRESS_LEN_MAX); if (len > 0 && len < IP_ADDRESS_LEN_MAX) buf[len] = '\0'; - if (i == 0) - seq_printf(mount_option, "%s", buf); - else - seq_printf(mount_option, "~%s", buf); - enfs_log_debug("show nfs mount option type:%s %s\n", type, buf); + if (i != 0 && seq) + seq_printf(seq, "~"); + if (seq) + seq_printf(seq, "%s", buf); + + enfs_log_debug("\t%s\n", buf); } } @@ -335,13 +339,16 @@ void print_dns_info(struct seq_file *seq, struct enfs_route_dns_info *pRemoteDns int i = 0; char *name; - seq_printf(seq, ",%s=", type); + if (seq) + seq_printf(seq, ",%s=", type); + enfs_log_debug("%s dns list:\n", type); for (i = 0; i < pRemoteDnsInfo->dnsNameCount; i++) { name = pRemoteDnsInfo->routeRemoteDnsList[i].dnsname; - if (i == 0) + if (i != 0 && seq) + seq_printf(seq, "~"); + if (seq) seq_printf(seq, "%s", name); - else - seq_printf(seq, "~%s", name); + enfs_log_debug("\t%s\n", name); } } -- Gitee From c214f46042043f23f8b916a8f7275dc49c773999 Mon Sep 17 00:00:00 2001 From: ChenXiaoSong Date: Tue, 12 Aug 2025 11:06:02 +0800 Subject: [PATCH 6/9] nfs/enfs: unlock uniformly at the end of function in shard_route.c kylin inclusion category: cleanup bugzilla: https://gitee.com/openeuler/kernel/issues/ICRY17 -------------------------------- Make the code more readable and easier to maintain. Signed-off-by: ChenXiaoSong --- fs/nfs/enfs/shard_route.c | 94 +++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/fs/nfs/enfs/shard_route.c b/fs/nfs/enfs/shard_route.c index 105753d464f4..4f95e2cc2bd8 100644 --- a/fs/nfs/enfs/shard_route.c +++ b/fs/nfs/enfs/shard_route.c @@ -114,37 +114,40 @@ static bool delete_view_table(uint64_t devId); static int enfs_find_clnt_root(struct rpc_clnt *clnt, struct enfs_file_uuid *root_uuid) { + int ret = 0; struct clnt_uuid_info *info; read_lock(&shard_ctrl->clnt_info_lock); list_for_each_entry(info, &shard_ctrl->clnt_info_list, next) { if (info->clnt == clnt) { *root_uuid = info->root_uuid; - read_unlock(&shard_ctrl->clnt_info_lock); - return 0; + goto out; } } + ret = -1; + +out: read_unlock(&shard_ctrl->clnt_info_lock); - return -1; + return ret; } static int enfs_insert_clnt_root(struct rpc_clnt *clnt, struct enfs_file_uuid *root_uuid) { + int ret = 0; struct clnt_uuid_info *info; write_lock(&shard_ctrl->clnt_info_lock); list_for_each_entry(info, &shard_ctrl->clnt_info_list, next) { if (info->clnt == clnt) { info->root_uuid = *root_uuid; - write_unlock(&shard_ctrl->clnt_info_lock); - return 0; + goto out; } } info = kmalloc(sizeof(*info), GFP_KERNEL); if (!info) { - write_unlock(&shard_ctrl->clnt_info_lock); - return -1; + ret = -1; + goto out; } info->clnt = clnt; @@ -152,12 +155,14 @@ static int enfs_insert_clnt_root(struct rpc_clnt *clnt, struct enfs_file_uuid *r list_add_tail(&info->next, &shard_ctrl->clnt_info_list); info->updating = false; +out: write_unlock(&shard_ctrl->clnt_info_lock); - return 0; + return ret; } int enfs_delete_clnt_shard_cache(struct rpc_clnt *clnt) { + int ret = 0; struct clnt_uuid_info *info; uint64_t devId = 0; @@ -170,10 +175,8 @@ int enfs_delete_clnt_shard_cache(struct rpc_clnt *clnt) break; } } - if (devId == 0) { - write_unlock(&shard_ctrl->clnt_info_lock); - return 0; - } + if (devId == 0) + goto out; list_for_each_entry(info, &shard_ctrl->clnt_info_list, next) { if (devId == GET_DEVID_FROM_UUID(&info->root_uuid)) { @@ -188,8 +191,9 @@ int enfs_delete_clnt_shard_cache(struct rpc_clnt *clnt) write_unlock(&shard_ctrl->view_lock); } +out: write_unlock(&shard_ctrl->clnt_info_lock); - return 0; + return ret; } static struct view_table *create_view_table(uint64_t devId) @@ -327,7 +331,7 @@ static int get_ls_and_cpu_id(struct view_table *table, uint64_t clusterId, static int enfs_query_lif_info(struct rpc_clnt *clnt, struct enfs_file_uuid *file_uuid, uint64_t *lsid, uint32_t *cpuId) { - int ret; + int ret = 0; struct view_table *table; struct fs_info *info; uint32_t shardId; @@ -335,25 +339,25 @@ static int enfs_query_lif_info(struct rpc_clnt *clnt, struct enfs_file_uuid *fil read_lock(&shard_ctrl->view_lock); table = get_view_table(GET_DEVID_FROM_UUID(file_uuid), false); if (!table) { - read_unlock(&shard_ctrl->view_lock); - return -1; + ret = -1; + goto out; } info = get_fsinfo(table, GET_FSID_FROM_UUID(file_uuid)); if (!info) { - read_unlock(&shard_ctrl->view_lock); - return -1; + ret = -1; + goto out; } shardId = get_shardid_from_uuid(file_uuid); - ret = - get_ls_and_cpu_id(table, info->clusterId, info->storagePoolId, - shardId, lsid, cpuId); + ret = get_ls_and_cpu_id(table, info->clusterId, info->storagePoolId, + shardId, lsid, cpuId); if (ret) { - read_unlock(&shard_ctrl->view_lock); enfs_log_error("get lsid failed.\n"); - return ret; + goto out; } + +out: read_unlock(&shard_ctrl->view_lock); return ret; } @@ -426,33 +430,32 @@ static int update_shard_view(struct view_table *table, static int enfs_update_fsshard(uint64_t devId, struct enfs_shard_view *fs_shard_view, int *flag) { - int ret; + int ret = 0; struct view_table *table; write_lock(&shard_ctrl->view_lock); table = get_view_table(devId, true); if (!table) { - write_unlock(&shard_ctrl->view_lock); enfs_log_error("get view table failed.\n"); - return -ENOMEM; + ret = -ENOMEM; + goto out; } ret = update_fs_info(table, fs_shard_view); if (ret) { - write_unlock(&shard_ctrl->view_lock); enfs_log_error("update fs info err:%d\n", ret); - return ret; + goto out; } ret = update_shard_view(table, fs_shard_view, flag); if (ret) { - write_unlock(&shard_ctrl->view_lock); enfs_log_error("update shard view err:%d\n", ret); - return ret; + goto out; } +out: write_unlock(&shard_ctrl->view_lock); - return 0; + return ret; } static int find_same_lsid(struct ls_info *info, int size, int target_lsId) @@ -520,26 +523,26 @@ static int update_ls_info(struct view_table *table, static int enfs_update_lsinfo(uint64_t devId, struct enfs_get_ls_version_rsp *ls_view, int *flag) { - int ret; + int ret = 0; struct view_table *table; write_lock(&shard_ctrl->view_lock); table = get_view_table(devId, true); if (!table) { - write_unlock(&shard_ctrl->view_lock); enfs_log_error("get view table failed.\n"); - return -ENOMEM; + ret = -ENOMEM; + goto out; } ret = update_ls_info(table, ls_view, flag); if (ret) { - write_unlock(&shard_ctrl->view_lock); enfs_log_error("update ls info err:%d\n", ret); - return ret; + goto out; } +out: write_unlock(&shard_ctrl->view_lock); - return 0; + return ret; } // getattr,fsstat,fsinfo,pathconf @@ -930,17 +933,15 @@ static struct rpc_xprt *enfs_get_shard_xport(struct rpc_clnt *clnt, uint32_t cpuId) { struct rpc_xprt *old; - struct rpc_xprt *xprt; + struct rpc_xprt *xprt = NULL; struct rpc_xprt_switch *xps; struct rpc_xprt_iter *xpi = &clnt->cl_xpi; struct enfs_xprt_context *context; rcu_read_lock(); xps = rcu_dereference(xpi->xpi_xpswitch); - if (xps == NULL) { - rcu_read_unlock(); - return NULL; - } + if (xps == NULL) + goto out; old = smp_load_acquire(&xpi->xpi_cursor); // multi thread access xprt = enfs_choose_shard_xport(xps, old, lsid, clnt, cpuId); smp_store_release(&xpi->xpi_cursor, xprt); // multi thread access @@ -951,17 +952,16 @@ static struct rpc_xprt *enfs_get_shard_xport(struct rpc_clnt *clnt, rpc_task_release_transport(task); } - if (xprt == NULL) { - rcu_read_unlock(); - return NULL; - } + if (xprt == NULL) + goto out; xprt = xprt_get(xprt); context = xprt_get_reserve_context(xprt); if (context) atomic_long_inc(&context->queuelen); - rcu_read_unlock(); +out: + rcu_read_unlock(); return xprt; } -- Gitee From c591cbd938429333b46451adc60a30c967b50e33 Mon Sep 17 00:00:00 2001 From: ChenXiaoSong Date: Tue, 12 Aug 2025 14:39:25 +0800 Subject: [PATCH 7/9] nfs/enfs: format get_ip_to_str() in shard_route.c kylin inclusion category: cleanup bugzilla: https://gitee.com/openeuler/kernel/issues/ICRY17 -------------------------------- Fixed up coding style. Signed-off-by: ChenXiaoSong --- fs/nfs/enfs/shard_route.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/fs/nfs/enfs/shard_route.c b/fs/nfs/enfs/shard_route.c index 4f95e2cc2bd8..9a55fbd15f2c 100644 --- a/fs/nfs/enfs/shard_route.c +++ b/fs/nfs/enfs/shard_route.c @@ -1153,19 +1153,18 @@ static void debug_show_shardinfo(int argc, char *argv[]) static int get_ip_to_str(struct sockaddr *addr, char *buf, int len) { - switch (addr->sa_family) { - case AF_INET:{ - struct sockaddr_in *sin = (struct sockaddr_in *)addr; + struct sockaddr_in *sin; + struct sockaddr_in6 *sin6; - snprintf(buf, len, "%pI4", &sin->sin_addr); - return 0; - } - case AF_INET6:{ - struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addr; - - snprintf(buf, len, "%pI6c", &sin6->sin6_addr); - return 0; - } + switch (addr->sa_family) { + case AF_INET: + sin = (struct sockaddr_in *)addr; + snprintf(buf, len, "%pI4", &sin->sin_addr); + return 0; + case AF_INET6: + sin6 = (struct sockaddr_in6 *)addr; + snprintf(buf, len, "%pI6c", &sin6->sin6_addr); + return 0; default: break; } -- Gitee From 5c582afec12819031e40ac56ad6f77adccfde048 Mon Sep 17 00:00:00 2001 From: ChenXiaoSong Date: Tue, 12 Aug 2025 15:02:39 +0800 Subject: [PATCH 8/9] nfs/enfs: remove enfs_init() and enfs_fini() kylin inclusion category: cleanup bugzilla: https://gitee.com/openeuler/kernel/issues/ICRY17 -------------------------------- Make the code more readable. Signed-off-by: ChenXiaoSong --- fs/nfs/enfs/enfs_init.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/fs/nfs/enfs/enfs_init.c b/fs/nfs/enfs/enfs_init.c index 6f4ddd565541..7ce4a117e816 100644 --- a/fs/nfs/enfs/enfs_init.c +++ b/fs/nfs/enfs/enfs_init.c @@ -88,16 +88,6 @@ static struct enfs_init_entry init_entry[] = { { "dns", enfs_dns_init, enfs_dns_exit }, }; -int32_t enfs_init(void) -{ - return init_helper_init(init_entry, ARRAY_SIZE(init_entry)); -} - -void enfs_fini(void) -{ - init_helper_finalize(init_entry, ARRAY_SIZE(init_entry)); -} - static int __init init_enfs(void) { int ret; @@ -108,7 +98,7 @@ static int __init init_enfs(void) return -1; } - ret = enfs_init(); + ret = init_helper_init(init_entry, ARRAY_SIZE(init_entry)); if (ret) { enfs_adapter_unregister(&enfs_adapter); return -1; @@ -126,7 +116,7 @@ static int __init init_enfs(void) static void __exit exit_enfs(void) { enfs_lookupcache_fini(); - enfs_fini(); + init_helper_finalize(init_entry, ARRAY_SIZE(init_entry)); enfs_adapter_unregister(&enfs_adapter); } -- Gitee From bc954e6ba5c80f2f7fafde7cd2eb818628421786 Mon Sep 17 00:00:00 2001 From: ChenXiaoSong Date: Tue, 12 Aug 2025 20:13:23 +0800 Subject: [PATCH 9/9] nfs/enfs: make some functions static in enfs_multipath_client.c kylin inclusion category: cleanup bugzilla: https://gitee.com/openeuler/kernel/issues/ICRY17 -------------------------------- These functions are used only in enfs_multipath_client.c. Signed-off-by: ChenXiaoSong --- fs/nfs/enfs/enfs_multipath_client.c | 30 ++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/fs/nfs/enfs/enfs_multipath_client.c b/fs/nfs/enfs/enfs_multipath_client.c index 15cfbec89282..4d5eb61dc1fa 100644 --- a/fs/nfs/enfs/enfs_multipath_client.c +++ b/fs/nfs/enfs/enfs_multipath_client.c @@ -69,7 +69,8 @@ void enfs_free_nfsclient_info(struct multipath_client_info *client_info) kfree(client_info); } -int nfs_multipath_client_mount_info_init( +static int +nfs_multipath_client_mount_info_init( struct multipath_client_info *client_info, const struct nfs_client_initdata *cl_init) { @@ -170,8 +171,10 @@ int nfs_multipath_client_info_init(void **data, return rc; } -bool nfs_multipath_ip_list_info_match(const struct nfs_ip_list *ip_list_src, - const struct nfs_ip_list *ip_list_dst) +static bool +nfs_multipath_ip_list_info_match( + const struct nfs_ip_list *ip_list_src, + const struct nfs_ip_list *ip_list_dst) { int i; int j; @@ -307,8 +310,11 @@ int nfs4_multipath_client_info_match(void *src, void *dst) return ret; } -void print_ip_info(struct seq_file *seq, struct nfs_ip_list *ip_list, - const char *type) +static void +print_ip_info( + struct seq_file *seq, + struct nfs_ip_list *ip_list, + const char *type) { char buf[IP_ADDRESS_LEN_MAX + 1]; int len = 0; @@ -333,8 +339,11 @@ void print_ip_info(struct seq_file *seq, struct nfs_ip_list *ip_list, } } -void print_dns_info(struct seq_file *seq, struct enfs_route_dns_info *pRemoteDnsInfo, - const char *type) +static void +print_dns_info( + struct seq_file *seq, + struct enfs_route_dns_info *pRemoteDnsInfo, + const char *type) { int i = 0; char *name; @@ -374,8 +383,11 @@ static void multipath_print_sockaddr(struct seq_file *seq, enfs_log_error("unsupport family:%d\n", addr->sa_family); } -void convert_lookup_cache_str(struct nfs_server *server, char **server_lookup, - char **actual_lookup) +static void +convert_lookup_cache_str( + struct nfs_server *server, + char **server_lookup, + char **actual_lookup) { if ((server->enfs_flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) && (server->enfs_flags & NFS_MOUNT_LOOKUP_CACHE_NONE)) { -- Gitee