From 13c075feec55c40a27f7182865e26e7b00e57c9a Mon Sep 17 00:00:00 2001 From: zhangguodong Date: Thu, 18 Dec 2025 16:23:28 +0800 Subject: [PATCH] nfs/enfs: wrap some functions and patch formatting kylin inclusion category: cleanup bugzilla: https://gitee.com/openeuler/kernel/issues/IDE2UT -------------------------------- Kylin checks the relevant patch formats mainly to avoid CamelCase. At the same time, some functions were also wrapped. Co-developed-by: ChenXiaoSong Signed-off-by: ChenXiaoSong Signed-off-by: ZhangGuoDong --- fs/nfs/client.c | 2 +- fs/nfs/dir.c | 4 - fs/nfs/enfs/dns_process.c | 170 ++++++++++----------- fs/nfs/enfs_adapter.h | 5 + fs/nfs/nfs3xdr.c | 3 - include/linux/sunrpc/sched.h | 2 +- include/linux/sunrpc/sunrpc_enfs_adapter.h | 28 ++++ net/sunrpc/clnt.c | 9 -- net/sunrpc/xprt.c | 10 -- 9 files changed, 117 insertions(+), 116 deletions(-) diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 87a58ee29aa6..5b559312ab92 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c @@ -318,7 +318,7 @@ static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *dat /* Match the full socket address */ if (!rpc_cmp_addr_port(sap, clap)) { #if IS_ENABLED(CONFIG_ENFS) - if (data->enfs_option != NULL) + if (data->enfs_option) continue; #endif /* Match all xprt_switch full socket addresses */ diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index d6f6170a9e47..5713fd6489d6 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1499,11 +1499,7 @@ static int nfs_dentry_verify_change(struct inode *dir, struct dentry *dentry) bool nfs_check_have_lookup_cache_flag(struct nfs_server *server, int flag) { -#if IS_ENABLED(CONFIG_ENFS) return enfs_check_have_lookup_cache_flag(server, flag); -#else - return (server->flags & NFS_MOUNT_LOOKUP_CACHE_NONE); -#endif } /* diff --git a/fs/nfs/enfs/dns_process.c b/fs/nfs/enfs/dns_process.c index 719b51fe2616..a5072b58e099 100644 --- a/fs/nfs/enfs/dns_process.c +++ b/fs/nfs/enfs/dns_process.c @@ -70,15 +70,13 @@ void enfs_debug_print_name_list(void) list_for_each_entry(list, &dns_cache_list, next) { enfs_log_info("domain name:%s\n", list->name); for (i = 0; i < list->inet.count; i++) { - sockaddr_ip_to_str( - (struct sockaddr *)&list->inet.address[i], buf, - 128); + sockaddr_ip_to_str((struct sockaddr *)&list->inet.address[i], + buf, 128); enfs_log_info("%s\n", buf); } for (i = 0; i < list->inet6.count; i++) { - sockaddr_ip_to_str( - (struct sockaddr *)&list->inet6.address[i], buf, - 128); + sockaddr_ip_to_str((struct sockaddr *)&list->inet6.address[i], + buf, 128); enfs_log_info("%s\n", buf); } } @@ -100,16 +98,14 @@ void enfs_update_domain_name(char *name, struct nfs_ip_list *ip_list) addr = (struct sockaddr *)&ip_list->address[i]; switch (addr->sa_family) { case AF_INET: - enfs_insert_ip_list( - &name_list->inet, - enfs_get_config_link_count_per_mount(), - &ip_list->address[i]); + enfs_insert_ip_list(&name_list->inet, + enfs_get_config_link_count_per_mount(), + &ip_list->address[i]); break; case AF_INET6: - enfs_insert_ip_list( - &name_list->inet6, - enfs_get_config_link_count_per_mount(), - &ip_list->address[i]); + enfs_insert_ip_list(&name_list->inet6, + enfs_get_config_link_count_per_mount(), + &ip_list->address[i]); break; } } @@ -280,7 +276,7 @@ static int multi_query_dns(struct nfs_ip_list *ip_list, char *name, int slot, net = current->nsproxy->net_ns; enfs_log_debug("domain_name:%s option:%s\n", name, options); ip_len = dns_query(net, NULL, name, strlen(name), options, - &ip_addr, NULL, true); + &ip_addr, NULL, true); if (ip_len <= 0) { enfs_log_debug("dns query:%s error.\n", ip_addr); return -ESRCH; @@ -354,161 +350,162 @@ static bool query_domain_name_in_cache(struct nfs_ip_list *ip_list, char *name, return ret; } -int enfs_quick_sort(int low, int high, struct enfs_dns_query_ip_info_single *dnsQueryIpInfo) +int enfs_quick_sort(int low, int high, struct enfs_dns_query_ip_info_single *dns_query_ip_info) { int i = low; int j = high; - uint64_t key = dnsQueryIpInfo[i].lsId; + u64 key = dns_query_ip_info[i].lsId; - strscpy(dns_sort_ip, dnsQueryIpInfo[i].ipAddr, IP_ADDRESS_LEN_MAX); + strscpy(dns_sort_ip, dns_query_ip_info[i].ipAddr, IP_ADDRESS_LEN_MAX); while (i < j) { - while (i < j && dnsQueryIpInfo[j].lsId >= key) + while (i < j && dns_query_ip_info[j].lsId >= key) j--; - dnsQueryIpInfo[i].lsId = dnsQueryIpInfo[j].lsId; - strscpy(dnsQueryIpInfo[i].ipAddr, dnsQueryIpInfo[j].ipAddr, IP_ADDRESS_LEN_MAX); + dns_query_ip_info[i].lsId = dns_query_ip_info[j].lsId; + strscpy(dns_query_ip_info[i].ipAddr, + dns_query_ip_info[j].ipAddr, IP_ADDRESS_LEN_MAX); - while (i < j && dnsQueryIpInfo[i].lsId <= key) + while (i < j && dns_query_ip_info[i].lsId <= key) i++; - dnsQueryIpInfo[j].lsId = dnsQueryIpInfo[i].lsId; - strscpy(dnsQueryIpInfo[j].ipAddr, dnsQueryIpInfo[i].ipAddr, IP_ADDRESS_LEN_MAX); + dns_query_ip_info[j].lsId = dns_query_ip_info[i].lsId; + strscpy(dns_query_ip_info[j].ipAddr, + dns_query_ip_info[i].ipAddr, IP_ADDRESS_LEN_MAX); } - dnsQueryIpInfo[i].lsId = key; - strscpy(dnsQueryIpInfo[i].ipAddr, dns_sort_ip, IP_ADDRESS_LEN_MAX); + dns_query_ip_info[i].lsId = key; + strscpy(dns_query_ip_info[i].ipAddr, dns_sort_ip, IP_ADDRESS_LEN_MAX); if (i - 1 > low) - enfs_quick_sort(low, i - 1, dnsQueryIpInfo); + enfs_quick_sort(low, i - 1, dns_query_ip_info); if (i + 1 < high) - enfs_quick_sort(i + 1, high, dnsQueryIpInfo); + enfs_quick_sort(i + 1, high, dns_query_ip_info); memset(dns_sort_ip, 0, sizeof(dns_sort_ip)); return 0; } -int enfs_dns_process_ip(struct enfs_dns_query_ip_info_single *dnsQueryIpInfo, - struct enfs_dns_query_lsid_rsp **dnsQueryLsidInfo, int *lsidCount, +int enfs_dns_process_ip(struct enfs_dns_query_ip_info_single *dns_query_ip_info, + struct enfs_dns_query_lsid_rsp **dns_query_lsid_info, int *lsid_count, int ipNumber) { int i; int index = 0; int count = 1; - struct enfs_dns_query_lsid_rsp *lsIdInfo = NULL; + struct enfs_dns_query_lsid_rsp *ls_id_info = NULL; // sort all ip by lsid - enfs_quick_sort(0, ipNumber - 1, dnsQueryIpInfo); + enfs_quick_sort(0, ipNumber - 1, dns_query_ip_info); for (i = 1; i < ipNumber; i++) { - if (dnsQueryIpInfo[i - 1].lsId != dnsQueryIpInfo[i].lsId) + if (dns_query_ip_info[i - 1].lsId != dns_query_ip_info[i].lsId) count++; } - *lsidCount = count; + *lsid_count = count; // combine ip by lsis,while ip's lsid is same,all of them combined to one structure - lsIdInfo = kmalloc_array(count, sizeof(struct enfs_dns_query_lsid_rsp), GFP_KERNEL); - if (lsIdInfo == NULL) + ls_id_info = kmalloc_array(count, sizeof(struct enfs_dns_query_lsid_rsp), GFP_KERNEL); + if (!ls_id_info) return -ENOMEM; for (i = 0; i < ipNumber; i++) { if (i != 0 && - dnsQueryIpInfo[i - 1].lsId == dnsQueryIpInfo[i].lsId) { - lsIdInfo[index].count++; + dns_query_ip_info[i - 1].lsId == dns_query_ip_info[i].lsId) { + ls_id_info[index].count++; continue; } if (i != 0) index++; - lsIdInfo[index].lsId = dnsQueryIpInfo[i].lsId; - lsIdInfo[index].offset = 0; - lsIdInfo[index].count = 0; - lsIdInfo[index].count++; + ls_id_info[index].lsId = dns_query_ip_info[i].lsId; + ls_id_info[index].offset = 0; + ls_id_info[index].count = 0; + ls_id_info[index].count++; } - *dnsQueryLsidInfo = lsIdInfo; + *dns_query_lsid_info = ls_id_info; return 0; } int enfs_server_query_dns(struct rpc_clnt *clnt, struct enfs_route_dns_info *dns_info, - struct nfs_ip_list *ipList, int slot, - uint32_t ip_type, uint32_t dnsNamecount, - char *dnsName) + struct nfs_ip_list *ip_list, int slot, + u32 ip_type, u32 dns_namecount, + char *dns_name) { int ret; int i = 0; int offset = 0; - int tmpSlot = slot; - struct enfs_dns_query_lsid_rsp *dnsQueryLsidInfo = NULL; - struct enfs_dns_query_ip_info_single *dnsQueryIpInfo = NULL; + int tmp_slot = slot; + struct enfs_dns_query_lsid_rsp *dns_query_lsid_info = NULL; + struct enfs_dns_query_ip_info_single *dns_query_ip_info = NULL; // malloc max node 256 int ipNumber; - int lsidCount; + int lsid_count; - ret = dorado_query_dns(clnt, &dnsQueryIpInfo, ip_type, dnsNamecount, - dnsName, &ipNumber); + ret = dorado_query_dns(clnt, &dns_query_ip_info, ip_type, dns_namecount, + dns_name, &ipNumber); if (ret) return ret; - if (dnsQueryIpInfo == NULL) + if (!dns_query_ip_info) return ret; - ret = enfs_dns_process_ip(dnsQueryIpInfo, &dnsQueryLsidInfo, &lsidCount, + ret = enfs_dns_process_ip(dns_query_ip_info, &dns_query_lsid_info, &lsid_count, ipNumber); if (ret) return ret; i = 0; - while (ipList->count < + while (ip_list->count < (enfs_get_config_link_count_per_mount() < ipNumber ? enfs_get_config_link_count_per_mount() : ipNumber)) { - if (dnsQueryLsidInfo[i].offset < dnsQueryLsidInfo[i].count) { + if (dns_query_lsid_info[i].offset < dns_query_lsid_info[i].count) { if (i != 0) - offset += dnsQueryLsidInfo[i - 1].count; + offset += dns_query_lsid_info[i - 1].count; ret = dns_resolver_name_list( - dnsQueryIpInfo[offset + - dnsQueryLsidInfo[i].offset] - .ipAddr, - &tmpSlot, ipList); + dns_query_ip_info[offset + + dns_query_lsid_info[i].offset].ipAddr, + &tmp_slot, ip_list); if (ret) goto out; - dnsQueryLsidInfo[i].offset++; + dns_query_lsid_info[i].offset++; i++; } else { i++; } - if (i == lsidCount) { + if (i == lsid_count) { offset = 0; i = 0; } } out: - kfree(dnsQueryIpInfo); - kfree(dnsQueryLsidInfo); + kfree(dns_query_ip_info); + kfree(dns_query_lsid_info); return ret; } void query_dns_each_name(struct enfs_route_dns_info *dns_info, int slot, - struct nfs_ip_list *ipList, unsigned short family, + struct nfs_ip_list *ip_list, unsigned short family, bool use_cache) { int ret; int i; - char *dnsName = NULL; + char *dns_name = NULL; for (i = 0; i < dns_info->dnsNameCount; i++) { - dnsName = dns_info->routeRemoteDnsList[i].dnsname; - enfs_log_debug("query DNS:%s\n", dnsName); + dns_name = dns_info->routeRemoteDnsList[i].dnsname; + enfs_log_debug("query DNS:%s\n", dns_name); if (use_cache && - query_domain_name_in_cache(ipList, dnsName, slot, family)) { - enfs_log_debug("cache name:%s.\n", dnsName); + query_domain_name_in_cache(ip_list, dns_name, slot, family)) { + enfs_log_debug("cache name:%s.\n", dns_name); continue; } - ret = query_dns_cross_protocol(ipList, dnsName, slot, family); + ret = query_dns_cross_protocol(ip_list, dns_name, slot, family); if (ret != 0) enfs_log_debug("dns multi query dns failed.\n"); else - enfs_update_domain_name(dnsName, ipList); + enfs_update_domain_name(dns_name, ip_list); } } @@ -520,9 +517,9 @@ int multipath_query_dns(struct multipath_mount_options *opt, int i; int slot = 0; struct enfs_route_dns_info *dns_info; - char *dnsName = NULL; + char *dns_name = NULL; struct nfs_ip_list *ip_list; - uint32_t ip_type = 0; + u32 ip_type = 0; if (!opt->pRemoteDnsInfo || opt->pRemoteDnsInfo->dnsNameCount <= 0 || opt->pRemoteDnsInfo->dnsNameCount > MAX_DNS_SUPPORTED) { @@ -534,8 +531,8 @@ int multipath_query_dns(struct multipath_mount_options *opt, return -ENOMEM; ip_list->count = 0; dns_info = opt->pRemoteDnsInfo; - dnsName = kmalloc(dns_info->dnsNameCount * EXTEND_MAX_DNS_NAME_LEN, GFP_KERNEL); - if (!dnsName) { + dns_name = kmalloc(dns_info->dnsNameCount * EXTEND_MAX_DNS_NAME_LEN, GFP_KERNEL); + if (!dns_name) { kfree(ip_list); return -ENOMEM; } @@ -544,16 +541,15 @@ int multipath_query_dns(struct multipath_mount_options *opt, if (family == AF_INET6) ip_type = IP_TYPE_BOTH; for (i = 0; i < dns_info->dnsNameCount; i++) { - sprintf(dnsName + i * EXTEND_MAX_DNS_NAME_LEN, "%s", + sprintf(dns_name + i * EXTEND_MAX_DNS_NAME_LEN, "%s", dns_info->routeRemoteDnsList[i].dnsname); } slot = enfs_get_config_link_count_per_mount() / dns_info->dnsNameCount; - ret = enfs_server_query_dns( - clnt, dns_info, ip_list, - enfs_get_config_link_count_per_mount(), ip_type, - dns_info->dnsNameCount, dnsName); + ret = enfs_server_query_dns(clnt, dns_info, ip_list, + enfs_get_config_link_count_per_mount(), ip_type, + dns_info->dnsNameCount, dns_name); if (ret != 0) { query_dns_each_name(dns_info, slot, ip_list, family, use_cache); @@ -562,7 +558,7 @@ int multipath_query_dns(struct multipath_mount_options *opt, query_dns_each_name(dns_info, slot, ip_list, family, use_cache); } - kfree(dnsName); + kfree(dns_name); if (ip_list->count == 0) { enfs_log_debug("query dns failed, no IP is found.\n"); kfree(ip_list); @@ -585,7 +581,7 @@ int enfs_iter_nfs_clnt(enfs_iter_clnt fn, void *data) rcu_read_lock(); for_each_net_rcu(net) { nn = net_generic(net, nfs_net_id); - if (nn == NULL) + if (!nn) continue; if (list_empty(&nn->nfs_client_list)) @@ -616,8 +612,7 @@ void enfs_add_domain_name(struct multipath_mount_options *opt) for (i = 0; i < MAX_DNS_SUPPORTED && i < opt->pRemoteDnsInfo->dnsNameCount; i++) { - enfs_domain_inc( - opt->pRemoteDnsInfo->routeRemoteDnsList[i].dnsname); + enfs_domain_inc(opt->pRemoteDnsInfo->routeRemoteDnsList[i].dnsname); } } @@ -629,8 +624,7 @@ static int collect_clnt_name(struct nfs_client *clp, void *data) for (i = 0; i < MAX_DNS_SUPPORTED && i < clp_info->pRemoteDnsInfo->dnsNameCount; i++) { - enfs_domain_inc( - clp_info->pRemoteDnsInfo->routeRemoteDnsList[i].dnsname); + enfs_domain_inc(clp_info->pRemoteDnsInfo->routeRemoteDnsList[i].dnsname); } return 0; } diff --git a/fs/nfs/enfs_adapter.h b/fs/nfs/enfs_adapter.h index e6f127181278..4573da2d89f8 100644 --- a/fs/nfs/enfs_adapter.h +++ b/fs/nfs/enfs_adapter.h @@ -120,5 +120,10 @@ static inline void nfs_multipath_set_mount_data(void **opt, const char *hostname { } +static inline bool enfs_check_have_lookup_cache_flag(struct nfs_server *server, int flag) +{ + return (server->flags & NFS_MOUNT_LOOKUP_CACHE_NONE); +} + #endif // CONFIG_ENFS #endif diff --git a/fs/nfs/nfs3xdr.c b/fs/nfs/nfs3xdr.c index d22a8d752f98..af11b71deab8 100644 --- a/fs/nfs/nfs3xdr.c +++ b/fs/nfs/nfs3xdr.c @@ -29,7 +29,6 @@ #endif #define NFSDBG_FACILITY NFSDBG_XDR - /* Mapping from NFS error code to "errno" error code. */ #define errno_NFSERR_IO EIO @@ -2509,11 +2508,9 @@ static int nfs3_xdr_dec_extend3res(struct rpc_rqst *req, struct xdr_stream *xdr, memcpy(decArg->pBuf, p, decArg->buflen); dprintk("NFS: extend response size (%u)\n", length); - out: return error; - out_default: return nfs3_stat_to_errno(status); } diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h index ebdc1376bde6..035a09fef5fd 100644 --- a/include/linux/sunrpc/sched.h +++ b/include/linux/sunrpc/sched.h @@ -149,7 +149,7 @@ struct rpc_task_setup { #define RPC_TASK_CRED_NOREF 0x8000 /* No refcount on the credential */ #if IS_ENABLED(CONFIG_SUNRPC_ENFS) #define RPC_TASK_FIXED 0x0040 -#define RPC_TASK_ENFS 0x0008 /* enfs rpc program task */ +#define RPC_TASK_ENFS 0x0008 /* enfs rpc program task */ #endif #define RPC_IS_ASYNC(t) ((t)->tk_flags & RPC_TASK_ASYNC) #define RPC_IS_SWAPPER(t) ((t)->tk_flags & RPC_TASK_SWAPPER) diff --git a/include/linux/sunrpc/sunrpc_enfs_adapter.h b/include/linux/sunrpc/sunrpc_enfs_adapter.h index a3fd9db71d00..bcbc36818b9e 100644 --- a/include/linux/sunrpc/sunrpc_enfs_adapter.h +++ b/include/linux/sunrpc/sunrpc_enfs_adapter.h @@ -158,5 +158,33 @@ static inline void rpc_multipath_ops_inc_queuelen(struct rpc_xprt *xprt) static inline void rpc_multipath_ops_dec_queuelen(struct rpc_xprt *xprt) { } + +static inline const char *rpc_multipath_set_servername(const char *s, gfp_t gfp) +{ + return kstrdup(s, gfp); +} + +static inline bool rpc_multipath_ops_create_xprt(struct rpc_xprt *xprt) +{ + return true; +} + +static inline void rpc_multipath_free_servername(struct rpc_xprt *xprt) +{ + kfree(xprt->servername); +} + +static inline void rpc_multipath_switch_set_roundrobin(struct rpc_clnt *clnt, + struct rpc_xprt_switch *xps) +{ + rpc_xprt_switch_set_roundrobin(xps); +} + +#define RPC_MULTIPAHT_UPDATE_RPC_PROC(task, p, clnt) \ + do { \ + *p++ = cpu_to_be32(clnt->cl_prog); \ + *p++ = cpu_to_be32(clnt->cl_vers); \ + } while (0) + #endif #endif // _SUNRPC_ENFS_ADAPTER_H_ diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index 73b4f8c0e8cd..20ee258f0103 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c @@ -2697,12 +2697,7 @@ rpc_encode_header(struct rpc_task *task, struct xdr_stream *xdr) *p++ = req->rq_xid; *p++ = rpc_call; *p++ = cpu_to_be32(RPC_VERSION); -#if IS_ENABLED(CONFIG_SUNRPC_ENFS) RPC_MULTIPAHT_UPDATE_RPC_PROC(task, p, clnt); -#else - *p++ = cpu_to_be32(clnt->cl_prog); - *p++ = cpu_to_be32(clnt->cl_vers); -#endif *p = cpu_to_be32(task->tk_msg.rpc_proc->p_proc); error = rpcauth_marshcred(task, xdr); @@ -3180,11 +3175,7 @@ int rpc_clnt_add_xprt(struct rpc_clnt *clnt, connect_timeout, reconnect_timeout); -#if IS_ENABLED(CONFIG_SUNRPC_ENFS) rpc_multipath_switch_set_roundrobin(clnt, xps); -#else - rpc_xprt_switch_set_roundrobin(xps); -#endif if (setup) { ret = setup(clnt, xps, xprt, data); diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c index 3e90d0eae8df..96e2cb96182d 100644 --- a/net/sunrpc/xprt.c +++ b/net/sunrpc/xprt.c @@ -2074,22 +2074,16 @@ struct rpc_xprt *xprt_create_transport(struct xprt_create *args) xprt_destroy(xprt); return ERR_PTR(-EINVAL); } -#if IS_ENABLED(CONFIG_SUNRPC_ENFS) xprt->servername = rpc_multipath_set_servername(args->servername, GFP_KERNEL); -#else - xprt->servername = kstrdup(args->servername, GFP_KERNEL); -#endif if (xprt->servername == NULL) { xprt_destroy(xprt); return ERR_PTR(-ENOMEM); } -#if IS_ENABLED(CONFIG_SUNRPC_ENFS) if (!rpc_multipath_ops_create_xprt(xprt)) { xprt_destroy(xprt); return ERR_PTR(-ENOMEM); } -#endif rpc_xprt_debugfs_register(xprt); @@ -2110,11 +2104,7 @@ static void xprt_destroy_cb(struct work_struct *work) rpc_destroy_wait_queue(&xprt->pending); rpc_destroy_wait_queue(&xprt->sending); rpc_destroy_wait_queue(&xprt->backlog); -#if IS_ENABLED(CONFIG_SUNRPC_ENFS) rpc_multipath_free_servername(xprt); -#else - kfree(xprt->servername); -#endif /* * Destroy any existing back channel */ -- Gitee