Support multiple ips per hostname
Subsystems (2)
cover Support multiple ips per hostname
Steve,
Follow a series to handle multiple ip addresses per hostame when mounting, chasing DFS referrals and reconnecting.
We've defined a maximum number of 16 addresses a hostname can handle as we did in mount.cifs (resolve_host.c::resolve_host). If that's not OK, then we could make it flexible by creating a new mount option like 'maxaddrs=N' or just increase it in both sides.
The mount.cifs(8) patch that passes multiple 'ip=' options to handle all resolved addresses will be posted soon.
Paulo Alcantara (3):
cifs: introduce smb3_options_for_each() helper
cifs: handle multiple ip addresses per hostname
cifs: fix find_root_ses() when refresing dfs cache
fs/cifs/cifs_dfs_ref.c | 48 +- fs/cifs/cifsglob.h | 24 +- fs/cifs/connect.c | 1042 ++++++++++++++++++++++++---------------- fs/cifs/dfs_cache.c | 12 +- fs/cifs/dns_resolve.c | 72 +-- fs/cifs/dns_resolve.h | 5 +- fs/cifs/fs_context.c | 22 +- fs/cifs/fs_context.h | 4 +- fs/cifs/misc.c | 95 +++- 9 files changed, 828 insertions(+), 496 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/3 cifs: introduce smb3_options_for_each() helper
Introduce a new helper to walk through the mount options and avoid duplicating it all over the cifs code.
--- fs/cifs/cifsglob.h | 16 ++++++++++++++++ fs/cifs/misc.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+)
fs/cifs/cifsglob.h +16 -0
@@ -1960,4 +1960,20 @@ static inline bool is_tcon_dfs(struct cifs_tcon *tcon) tcon->share_flags & (SHI1005_FLAGS_DFS | SHI1005_FLAGS_DFS_ROOT); } +char *smb3_parse_option (char *options,char sep,char **nkey,char **nval); + +static inline char *smb3_parse_options_sep (char *options,char *sep,char **nkey,char **nval) +{ + *sep =',' ; +if (!strncmp (options,"sep=" ,4 )) { + *sep = options[4 ]; + options +=5 ; + } +return smb3_parse_option (options, *sep, nkey, nval); +} + +#define smb3_options_for_each (opts, nopts, sep, key, val) \ + for (nopts = (opts), nopts = smb3_parse_options_sep(nopts, &sep, &(key), &(val)); \ + (key); nopts = smb3_parse_option(nopts, sep, &(key), &(val))) +#endif /* _CIFS_GLOB_H */
fs/cifs/misc.c +48 -0
51 lines not on this page · raw message
Signature · 1 line
2.31.1
kernel test robot
build botRe: [PATCH 1/3] cifs: introduce smb3_options_for_each() helper
Thank you for the patch! Perhaps something to improve:
Hi Paulo,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on cifs/for-next]
[also build test WARNING on v5.13-rc1 next-20210511]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Paulo-Alcantara/Support-multiple-ips-per-hostname/20210512-003751 base: git://git.samba.org/sfrench/cifs-2.6.git for-next config: microblaze-randconfig-s032-20210511 (attached as .config) compiler: microblaze-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.3-341-g8af24329-dirty
# https://github.com/0day-ci/linux/commit/9d073f7c6b721cd2d1ed181b3ec7880bf421d689
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Paulo-Alcantara/Support-multiple-ips-per-hostname/20210512-003751
git checkout 9d073f7c6b721cd2d1ed181b3ec7880bf421d689
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' W=1 ARCH=microblaze
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
fs/cifs/misc.c:614: warning: Function parameter or member 'cfile' not described in 'cifs_queue_oplock_break' fs/cifs/misc.c:1017: warning: Function parameter or member 'name' not described in 'cifs_alloc_hash' fs/cifs/misc.c:1017: warning: Function parameter or member 'shash' not described in 'cifs_alloc_hash' fs/cifs/misc.c:1017: warning: Function parameter or member 'sdesc' not described in 'cifs_alloc_hash' fs/cifs/misc.c:1053: warning: Function parameter or member 'shash' not described in 'cifs_free_hash' fs/cifs/misc.c:1053: warning: Function parameter or member 'sdesc' not described in 'cifs_free_hash' fs/cifs/misc.c:1068: warning: Function parameter or member 'rqst' not described in 'rqst_page_get_length' fs/cifs/misc.c:1068: warning: Function parameter or member 'page' not described in 'rqst_page_get_length' fs/cifs/misc.c:1068: warning: Function parameter or member 'len' not described in 'rqst_page_get_length' fs/cifs/misc.c:1068: warning: Function parameter or member 'offset' not described in 'rqst_page_get_length' fs/cifs/misc.c:1101: warning: Function parameter or member 'dst' not described in 'copy_path_name' fs/cifs/misc.c:1101: warning: Function parameter or member 'src' not described in 'copy_path_name'
>> fs/cifs/misc.c:1289: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* Parse a string that is in key[=val][,key[=val]]* form.
vim +1289 fs/cifs/misc.c
1287
1288 /**
> 1289 * Parse a string that is in key[=val][,key[=val]]* form.
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH 2/3 cifs: handle multiple ip addresses per hostname
In reply to Paulo AlcantaraDefine a maximum number of 16 (CIFS_MAX_ADDR_COUNT) ip addresses the client can handle per hostname at mount and reconnect time. mount.cifs(8) will be responsible for passing multiple 'ip=' options in order to tell what ip addresses the given hostname resolved to.
cifs.ko will now connect to all resolved ip addresses and pick up the one that got connected first. In case there is no upcall or it failed for some reason, the client will reuse the resolved ip addresses that came from userspace mount.cifs(8).
--- fs/cifs/cifs_dfs_ref.c | 48 +- fs/cifs/cifsglob.h | 8 +- fs/cifs/connect.c | 1042 ++++++++++++++++++++++++---------------- fs/cifs/dfs_cache.c | 6 +- fs/cifs/dns_resolve.c | 72 +-- fs/cifs/dns_resolve.h | 5 +- fs/cifs/fs_context.c | 22 +- fs/cifs/fs_context.h | 4 +- fs/cifs/misc.c | 47 +- 9 files changed, 758 insertions(+), 496 deletions(-)
fs/cifs/cifs_dfs_ref.c +35 -13
@@ -143,8 +143,10 @@ char *cifs_compose_mount_options(const char *sb_mountdata,const char *prepath =NULL ;int md_len;char *tkn_e; -char *srvIP =NULL ;char sep =',' ; +struct sockaddr_storage *addrs =NULL ; +char ip[INET6_ADDRSTRLEN +1 ]; +int numaddrs, i;int off, noff;if (sb_mountdata ==NULL )
@@ -173,21 +175,28 @@ char *cifs_compose_mount_options(const char *sb_mountdata, } } - rc =dns_resolve_server_name_to_ip (name, &srvIP); -if (rc <0 ) { + addrs =kmalloc (CIFS_MAX_ADDR_COUNT *sizeof (*addrs),GFP_KERNEL ); +if (!addrs) { + rc = -ENOMEM ; + goto compose_mount_options_err; + } + + rc = numaddrs =dns_resolve_server_name_to_addrs (name, addrs,CIFS_MAX_ADDR_COUNT ); +if (rc <=0 ) {cifs_dbg (FYI ,"%s: Failed to resolve server part of %s to IP: %d\n" , __func__, name, rc); + rc = rc ==0 ? -EINVAL : rc; goto compose_mount_options_err; }/* -* In most cases, we'll be building a shorter string than the original, -* but we do have to assume that the address in the ip= option may be -* much longer than the original. Add the max length of an address -* string to the length of the original string to allow for worst case. +* In most cases, we'll be building a shorter string than the original, but we do have to +* assume that the address in the ip= option may be much longer than the original. +* Add the max length of CIFS_MAX_ADDR_COUNT * an address string to the length of the +* original string to allow for worst case. */ - md_len =strlen (sb_mountdata) +INET6_ADDRSTRLEN ; - mountdata =kzalloc (md_len +sizeof ("ip=" ) +1 ,GFP_KERNEL ); + md_len =strlen (sb_mountdata) +CIFS_MAX_ADDR_COUNT * (INET6_ADDRSTRLEN +sizeof (",ip=" )); + mountdata =kzalloc (md_len +1 ,GFP_KERNEL );if (mountdata ==NULL ) { rc = -ENOMEM ; goto compose_mount_options_err;
@@ -227,10 +236,23 @@ char *cifs_compose_mount_options(const char *sb_mountdata, mountdata[md_len] ='\0' ;/* copy new IP and ref share name */ -if (mountdata[strlen (mountdata) -1 ] != sep) +if (mountdata[strlen (mountdata) -1 ] == sep) + mountdata[strlen (mountdata) -1 ] ='\0' ; + +for (i =0 ; i < numaddrs; i++) { +struct sockaddr_storage *addr = &addrs[i]; + +if (addr->ss_family ==AF_INET6 ) { +scnprintf (ip,sizeof (ip),"%pI6" , + &((struct sockaddr_in6 *)addr)->sin6_addr); + }else +scnprintf (ip,sizeof (ip),"%pI4" , &((struct sockaddr_in *)addr)->sin_addr);strncat (mountdata, &sep,1 ); -strcat (mountdata,"ip=" ); -strcat (mountdata, srvIP); +strcat (mountdata,"ip=" ); +strcat (mountdata, ip); + } + +kfree (addrs);if (devname) *devname = name;
@@ -241,13 +263,13 @@ char *cifs_compose_mount_options(const char *sb_mountdata,/*cifs_dbg(FYI, "%s: submount mountdata: %s\n", __func__, mountdata );*/ compose_mount_options_out: -kfree (srvIP);return mountdata; compose_mount_options_err:kfree (mountdata); mountdata =ERR_PTR (rc);kfree (name); +kfree (addrs); goto compose_mount_options_out; }
fs/cifs/cifsglob.h +7 -1
@@ -87,6 +87,9 @@/* maximum number of PDUs in one compound */ #define MAX_COMPOUND 5 +/* maximum number of addresses we can handle from a resolved hostname */ +#define CIFS_MAX_ADDR_COUNT 16 +/* * Default number of credits to keep available for SMB3. * This value is chosen somewhat arbitrarily. The Windows client
@@ -589,8 +592,11 @@ struct TCP_Server_Info {enum statusEnum tcpStatus;/* what we think the status is */ char *hostname;/* hostname portion of UNC string */ struct socket *ssocket; -struct sockaddr_storage dstaddr; +struct sockaddr_storage dst_addr_list[CIFS_MAX_ADDR_COUNT ]; +unsigned int dst_addr_count; +struct sockaddr_storage dstaddr;/* current destination address */ struct sockaddr_storage srcaddr;/* locally bind to this IP */ +unsigned short port_num;#ifdef CONFIG_NET_NS struct net *net;#endif
fs/cifs/connect.c +616 -426
1,178 lines not on this page · raw message
fs/cifs/dfs_cache.c +4 -2
@@ -1235,8 +1235,10 @@ int dfs_cache_update_vol(const char *fullpath, struct TCP_Server_Info *server)cifs_dbg (FYI ,"%s: updating volume info\n" , __func__);spin_lock (&vi->ctx_lock); -memcpy (&vi->ctx.dstaddr, &server->dstaddr, -sizeof (vi->ctx.dstaddr)); +memcpy (vi->ctx.dst_addr_list, server->dst_addr_list, + server->dst_addr_count *sizeof (server->dst_addr_list[0 ])); + vi->ctx.dst_addr_count = server->dst_addr_count; +memcpy (&vi->ctx.dstaddr, &server->dstaddr,sizeof (vi->ctx.dstaddr));spin_unlock (&vi->ctx_lock);kref_put (&vi->refcnt, vol_release);
fs/cifs/dns_resolve.c +41 -31
94 lines not on this page · raw message
fs/cifs/dns_resolve.h +4 -1
@@ -23,8 +23,11 @@#ifndef _DNS_RESOLVE_H#define _DNS_RESOLVE_H +#include <linux/net.h> +#ifdef __KERNEL__ -extern int dns_resolve_server_name_to_ip (const char *unc,char **ip_addr); +extern int dns_resolve_server_name_to_addrs (const char *unc,struct sockaddr_storage *addrs, +int maxaddrs);#endif /* KERNEL */ #endif /* _DNS_RESOLVE_H */
fs/cifs/fs_context.c +20 -2
@@ -591,6 +591,7 @@ static int smb3_fs_context_parse_monolithic(struct fs_context *fc,static int smb3_fs_context_validate (struct fs_context *fc) {struct smb3_fs_context *ctx =smb3_fc2context (fc); +unsigned int i;if (ctx->rdma && ctx->vals->protocol_id <SMB30_PROT_ID ) {cifs_errorf (fc,"SMB Direct requires Version >=3.0\n" );
@@ -633,9 +634,12 @@ static int smb3_fs_context_validate(struct fs_context *fc)pr_err ("Unable to determine destination address\n" );return -EHOSTUNREACH ; } + ctx->dst_addr_list[ctx->dst_addr_count++] = ctx->dstaddr; }/* set the port that we got earlier */ +for (i =0 ; i < ctx->dst_addr_count; i++) +cifs_set_port ((struct sockaddr *)&ctx->dst_addr_list[i], ctx->port);cifs_set_port ((struct sockaddr *)&ctx->dstaddr, ctx->port);if (ctx->override_uid && !ctx->uid_specified) {
@@ -792,6 +796,7 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,int i, opt;bool is_smb3 = !strcmp (fc->fs_type->name,"smb3" );bool skip_parsing = false; +struct sockaddr_storage dstaddr;cifs_dbg (FYI ,"CIFS: parsing cifs mount option '%s'\n" , param->key);
@@ -1096,12 +1101,25 @@ static int smb3_fs_context_parse_param(struct fs_context *fc, ctx->got_ip = false;break ; } -if (!cifs_convert_address ((struct sockaddr *)&ctx->dstaddr, - param->string, + +if (ctx->dst_addr_count >=CIFS_MAX_ADDR_COUNT ) { +cifs_errorf (fc,"reached max number (%u) of ip addresses. ignoring ip=%s option.\n" , +CIFS_MAX_ADDR_COUNT , param->string); +break ; + } + +if (!cifs_convert_address ((struct sockaddr *)&dstaddr, param->string,strlen (param->string))) {pr_err ("bad ip= option (%s)\n" , param->string); goto cifs_parse_mount_err; } + +if (ctx->dst_addr_count ==0 ) + ctx->dstaddr = dstaddr; + +cifs_dbg (FYI ,"%s: add \'%s\' to the list of destination addresses\n" , __func__, + param->string); + ctx->dst_addr_list[ctx->dst_addr_count++] = dstaddr; ctx->got_ip = true;break ;case Opt_domain:
fs/cifs/fs_context.h +3 -1
@@ -247,7 +247,9 @@ struct smb3_fs_context {struct smb_version_operations *ops;struct smb_version_values *vals;char *prepath; -struct sockaddr_storage dstaddr;/* destination address */ +struct sockaddr_storage dst_addr_list[CIFS_MAX_ADDR_COUNT ];/* list of dest addresses */ +unsigned int dst_addr_count;/* number of dest addresses */ +struct sockaddr_storage dstaddr;/* current destination address */ struct sockaddr_storage srcaddr;/* allow binding to a local IP */ struct nls_table *local_nls;/* This is a copy of the pointer in cifs_sb */ unsigned int echo_interval;/* echo interval in secs */
fs/cifs/misc.c +28 -19
71 lines not on this page · raw message
Signature · 1 line
2.31.1
kernel test robot
build botRe: [PATCH 2/3] cifs: handle multiple ip addresses per hostname
Thank you for the patch! Yet something to improve:
Hi Paulo,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on cifs/for-next]
[also build test ERROR on v5.13-rc1 next-20210511]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Paulo-Alcantara/Support-multiple-ips-per-hostname/20210512-003751 base: git://git.samba.org/sfrench/cifs-2.6.git for-next config: microblaze-randconfig-s032-20210511 (attached as .config) compiler: microblaze-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.3-341-g8af24329-dirty
# https://github.com/0day-ci/linux/commit/210f8e08a6bb153136929af6da6e0a7289ba5931
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Paulo-Alcantara/Support-multiple-ips-per-hostname/20210512-003751
git checkout 210f8e08a6bb153136929af6da6e0a7289ba5931
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' W=1 ARCH=microblaze
If you fix the issue, kindly add following tag as appropriate
All error/warnings (new ones prefixed by >>):
fs/cifs/connect.c: In function 'cifs_create_socket':
>> fs/cifs/connect.c:177:6: warning: variable 'slen' set but not used [-Wunused-but-set-variable]
177 | int slen, sfamily;
| ^~~~
fs/cifs/connect.c: In function 'cifs_reconnect':
>> fs/cifs/connect.c:726:46: error: 'cifs_sb' undeclared (first use in this function); did you mean 'cifs_ses'?
726 | if (IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) && cifs_sb &&
| ^~~~~~~
| cifs_ses
fs/cifs/connect.c:726:46: note: each undeclared identifier is reported only once for each function it appears in
>> fs/cifs/connect.c:733:5: error: implicit declaration of function 'reconn_set_next_dfs_target' [-Werror=implicit-function-declaration]
733 | reconn_set_next_dfs_target(server, cifs_sb, &tgt_list, &tgt_it);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
>> fs/cifs/connect.c:733:50: error: 'tgt_list' undeclared (first use in this function)
733 | reconn_set_next_dfs_target(server, cifs_sb, &tgt_list, &tgt_it);
| ^~~~~~~~
>> fs/cifs/connect.c:733:61: error: 'tgt_it' undeclared (first use in this function)
733 | reconn_set_next_dfs_target(server, cifs_sb, &tgt_list, &tgt_it);
| ^~~~~~
cc1: some warnings being treated as errors
--
fs/cifs/sess.c: In function 'cifs_ses_add_channel':
>> fs/cifs/sess.c:310:1: warning: the frame size of 2608 bytes is larger than 1024 bytes [-Wframe-larger-than=]
310 | }
| ^vim +726 fs/cifs/connect.c
577
578 /*
579 * cifs tcp session reconnection
580 *
581 * mark tcp session as reconnecting so temporarily locked
582 * mark all smb sessions as reconnecting for tcp session
583 * reconnect tcp session
584 * wake up waiters on reconnection? - (not needed currently)
585 */
586 int
587 cifs_reconnect(struct TCP_Server_Info *server)
588 {
589 int rc = 0;
590 struct list_head *tmp, *tmp2;
591 struct cifs_ses *ses;
592 struct cifs_tcon *tcon;
593 struct mid_q_entry *mid_entry;
594 struct list_head retry_list;
595 #ifdef CONFIG_CIFS_DFS_UPCALL
596 struct super_block *sb = NULL;
597 struct cifs_sb_info *cifs_sb = NULL;
598 struct dfs_cache_tgt_list tgt_list = {0};
599 struct dfs_cache_tgt_iterator *tgt_it = NULL;
600 #endif
601 struct sockaddr_storage *addrs = NULL;
602 unsigned int numaddrs;
603
604 addrs = kmalloc(sizeof(*addrs) * CIFS_MAX_ADDR_COUNT, GFP_KERNEL);
605 if (!addrs) {
606 rc = -ENOMEM;
607 goto out;
608 }
609
610 spin_lock(&GlobalMid_Lock);
611 server->nr_targets = 1;
612 #ifdef CONFIG_CIFS_DFS_UPCALL
613 spin_unlock(&GlobalMid_Lock);
614 sb = cifs_get_tcp_super(server);
615 if (IS_ERR(sb)) {
616 rc = PTR_ERR(sb);
617 cifs_dbg(FYI, "%s: will not do DFS failover: rc = %d\n",
618 __func__, rc);
619 sb = NULL;
620 } else {
621 cifs_sb = CIFS_SB(sb);
622 rc = reconn_setup_dfs_targets(cifs_sb, &tgt_list);
623 if (rc) {
624 cifs_sb = NULL;
625 if (rc != -EOPNOTSUPP) {
626 cifs_server_dbg(VFS, "%s: no target servers for DFS failover\n",
627 __func__);
628 }
629 } else {
630 server->nr_targets = dfs_cache_get_nr_tgts(&tgt_list);
631 }
632 }
633 cifs_dbg(FYI, "%s: will retry %d target(s)\n", __func__,
634 server->nr_targets);
635 spin_lock(&GlobalMid_Lock);
636 #endif
637 if (server->tcpStatus == CifsExiting) {
638 /* the demux thread will exit normally
639 next time through the loop */
640 spin_unlock(&GlobalMid_Lock);
641 #ifdef CONFIG_CIFS_DFS_UPCALL
642 dfs_cache_free_tgts(&tgt_list);
643 cifs_put_tcp_super(sb);
644 #endif
645 goto out;
646 } else
647 server->tcpStatus = CifsNeedReconnect;
648 spin_unlock(&GlobalMid_Lock);
649 server->maxBuf = 0;
650 server->max_read = 0;
651
652 cifs_dbg(FYI, "Mark tcp session as need reconnect\n");
653 trace_smb3_reconnect(server->CurrentMid, server->conn_id, server->hostname);
654
655 /* before reconnecting the tcp session, mark the smb session (uid)
656 and the tid bad so they are not used until reconnected */
657 cifs_dbg(FYI, "%s: marking sessions and tcons for reconnect\n",
658 __func__);
659 spin_lock(&cifs_tcp_ses_lock);
660 list_for_each(tmp, &server->smb_ses_list) {
661 ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
662 ses->need_reconnect = true;
663 list_for_each(tmp2, &ses->tcon_list) {
664 tcon = list_entry(tmp2, struct cifs_tcon, tcon_list);
665 tcon->need_reconnect = true;
666 }
667 if (ses->tcon_ipc)
668 ses->tcon_ipc->need_reconnect = true;
669 }
670 spin_unlock(&cifs_tcp_ses_lock);
671
672 /* do not want to be sending data on a socket we are freeing */
673 cifs_dbg(FYI, "%s: tearing down socket\n", __func__);
674 mutex_lock(&server->srv_mutex);
675 if (server->ssocket) {
676 cifs_dbg(FYI, "State: 0x%x Flags: 0x%lx\n",
677 server->ssocket->state, server->ssocket->flags);
678 kernel_sock_shutdown(server->ssocket, SHUT_WR);
679 cifs_dbg(FYI, "Post shutdown state: 0x%x Flags: 0x%lx\n",
680 server->ssocket->state, server->ssocket->flags);
681 sock_release(server->ssocket);
682 server->ssocket = NULL;
683 }
684 server->sequence_number = 0;
685 server->session_estab = false;
686 kfree(server->session_key.response);
687 server->session_key.response = NULL;
688 server->session_key.len = 0;
689 server->lstrp = jiffies;
690
691 /* mark submitted MIDs for retry and issue callback */
692 INIT_LIST_HEAD(&retry_list);
693 cifs_dbg(FYI, "%s: moving mids to private list\n", __func__);
694 spin_lock(&GlobalMid_Lock);
695 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
696 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
697 kref_get(&mid_entry->refcount);
698 if (mid_entry->mid_state == MID_REQUEST_SUBMITTED)
699 mid_entry->mid_state = MID_RETRY_NEEDED;
700 list_move(&mid_entry->qhead, &retry_list);
701 mid_entry->mid_flags |= MID_DELETED;
702 }
703 spin_unlock(&GlobalMid_Lock);
704 mutex_unlock(&server->srv_mutex);
705
706 cifs_dbg(FYI, "%s: issuing mid callbacks\n", __func__);
707 list_for_each_safe(tmp, tmp2, &retry_list) {
708 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
709 list_del_init(&mid_entry->qhead);
710 mid_entry->callback(mid_entry);
711 cifs_mid_q_entry_release(mid_entry);
712 }
713
714 if (cifs_rdma_enabled(server)) {
715 mutex_lock(&server->srv_mutex);
716 smbd_destroy(server);
717 mutex_unlock(&server->srv_mutex);
718 }
719
720 do {
721 try_to_freeze();
722
723 mutex_lock(&server->srv_mutex);
724
725 if (!cifs_swn_set_server_dstaddr(server)) {
> 726 if (IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) && cifs_sb &&
727 cifs_sb->origin_fullpath) {
728 /*
729 * Set up next DFS target server (if any) for reconnect. If DFS
730 * feature is disabled, then we will retry last server we
731 * connected to before.
732 */
> 733 reconn_set_next_dfs_target(server, cifs_sb, &tgt_list, &tgt_it); 734 }
735 /*
736 * Resolve the hostname again to make sure that IP address is up-to-date.
737 */
738 numaddrs = CIFS_MAX_ADDR_COUNT;
739 reconn_resolve_hostname(server, addrs, &numaddrs);
740
741 if (cifs_rdma_enabled(server)) {
742 /* FIXME: handle multiple ips for RDMA */
743 server->dst_addr_list[0] = server->dstaddr = addrs[0];
744 server->dst_addr_count = 1;
745 }
746 } else {
747 addrs[0] = server->dstaddr;
748 numaddrs = 1;
749 }
750
751 if (cifs_rdma_enabled(server)) {
752 rc = smbd_reconnect(server);
753 } else {
754 struct socket **socks, *sock;
755
756 socks = connect_all_ips(server, addrs, numaddrs);
757 if (IS_ERR(socks)) {
758 rc = PTR_ERR(socks);
759 cifs_server_dbg(VFS, "%s: connect_all_ips() failed: %d\n", __func__, rc);
760 } else {
761 mutex_unlock(&server->srv_mutex);
762 sock = get_first_connected_socket(socks, addrs, numaddrs, true);
763 release_sockets(socks, numaddrs);
764 mutex_lock(&server->srv_mutex);
765
766 if (IS_ERR(sock)) {
767 rc = PTR_ERR(sock);
768 cifs_server_dbg(FYI, "%s: couldn't find a connected socket: %d\n", __func__, rc);
769 } else {
770 rc = kernel_getpeername(sock, (struct sockaddr *)&server->dstaddr);
771 if (rc < 0) {
772 cifs_server_dbg(VFS, "%s: getpeername() failed: %d\n", __func__, rc);
773 sock_release(sock);
774 } else
775 rc = 0;
776 }
777 if (!rc) {
778 memcpy(server->dst_addr_list, addrs,
779 sizeof(addrs[0]) * numaddrs);
780 server->dst_addr_count = numaddrs;
781 server->ssocket = sock;
782 }
783 }
784 }
785
786 if (rc) {
787 mutex_unlock(&server->srv_mutex);
788 cifs_server_dbg(FYI, "%s: reconnect error %d\n", __func__, rc);
789 msleep(3000);
790 } else {
791 atomic_inc(&tcpSesReconnectCount);
792 set_credits(server, 1);
793 spin_lock(&GlobalMid_Lock);
794 if (server->tcpStatus != CifsExiting)
795 server->tcpStatus = CifsNeedNegotiate;
796 spin_unlock(&GlobalMid_Lock);
797 cifs_swn_reset_server_dstaddr(server);
798 mutex_unlock(&server->srv_mutex);
799 }
800 } while (server->tcpStatus == CifsNeedReconnect);
801
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH 2/3] cifs: handle multiple ip addresses per hostname
In reply to Paulo AlcantaraThank you for the patch! Perhaps something to improve:
Hi Paulo,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on cifs/for-next]
[also build test WARNING on v5.13-rc1 next-20210511]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Paulo-Alcantara/Support-multiple-ips-per-hostname/20210512-003751 base: git://git.samba.org/sfrench/cifs-2.6.git for-next config: arc-allyesconfig (attached as .config) compiler: arceb-elf-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/210f8e08a6bb153136929af6da6e0a7289ba5931
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Paulo-Alcantara/Support-multiple-ips-per-hostname/20210512-003751 git checkout 210f8e08a6bb153136929af6da6e0a7289ba5931
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross W=1 ARCH=arc
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
fs/cifs/connect.c: In function 'cifs_create_socket':
fs/cifs/connect.c:177:6: warning: variable 'slen' set but not used [-Wunused-but-set-variable]
177 | int slen, sfamily;
| ^~~~
fs/cifs/connect.c: In function 'next_dfs_prepath':
>> fs/cifs/connect.c:3540:1: warning: the frame size of 2516 bytes is larger than 1024 bytes [-Wframe-larger-than=]
3540 | }
| ^
fs/cifs/connect.c: In function 'do_dfs_failover':
fs/cifs/connect.c:3313:1: warning: the frame size of 2584 bytes is larger than 1024 bytes [-Wframe-larger-than=]
3313 | }
| ^
--
fs/cifs/dfs_cache.c: In function 'find_root_ses.isra.0':
>> fs/cifs/dfs_cache.c:1483:1: warning: the frame size of 2548 bytes is larger than 1024 bytes [-Wframe-larger-than=]
1483 | }
| ^vim +3540 fs/cifs/connect.c
7efd081582619e Paulo Alcantara 2020-07-21 3497
ff2c54a04097de Paulo Alcantara 2021-02-24 3498 /* Set up next dfs prefix path in @dfs_path */
ff2c54a04097de Paulo Alcantara 2021-02-24 3499 static int next_dfs_prepath(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx,
7efd081582619e Paulo Alcantara 2020-07-21 3500 const unsigned int xid, struct TCP_Server_Info *server,
7efd081582619e Paulo Alcantara 2020-07-21 3501 struct cifs_tcon *tcon, char **dfs_path)
56c762eb9bee33 Paulo Alcantara 2018-11-14 3502 {
ff2c54a04097de Paulo Alcantara 2021-02-24 3503 char *path, *npath;
ff2c54a04097de Paulo Alcantara 2021-02-24 3504 int added_treename = is_tcon_dfs(tcon);
ff2c54a04097de Paulo Alcantara 2021-02-24 3505 int rc;
7efd081582619e Paulo Alcantara 2020-07-21 3506
3fa1c6d1b8f5c3 Ronnie Sahlberg 2020-12-09 3507 path = cifs_build_path_to_root(ctx, cifs_sb, tcon, added_treename);
7efd081582619e Paulo Alcantara 2020-07-21 3508 if (!path)
7efd081582619e Paulo Alcantara 2020-07-21 3509 return -ENOMEM;
ce558b0e17f8a6 Steve French 2018-05-31 3510
ff2c54a04097de Paulo Alcantara 2021-02-24 3511 rc = is_path_remote(cifs_sb, ctx, xid, server, tcon);
ff2c54a04097de Paulo Alcantara 2021-02-24 3512 if (rc == -EREMOTE) {
3fa1c6d1b8f5c3 Ronnie Sahlberg 2020-12-09 3513 struct smb3_fs_context v = {NULL};
7efd081582619e Paulo Alcantara 2020-07-21 3514 /* if @path contains a tree name, skip it in the prefix path */
7efd081582619e Paulo Alcantara 2020-07-21 3515 if (added_treename) {
66e7b09c731175 Ronnie Sahlberg 2020-11-05 3516 rc = smb3_parse_devname(path, &v);
7efd081582619e Paulo Alcantara 2020-07-21 3517 if (rc)
ff2c54a04097de Paulo Alcantara 2021-02-24 3518 goto out;
7efd081582619e Paulo Alcantara 2020-07-21 3519 npath = build_unc_path_to_root(&v, cifs_sb, true);
c741cba2cd1d14 Ronnie Sahlberg 2020-12-14 3520 smb3_cleanup_fs_context_contents(&v);
7efd081582619e Paulo Alcantara 2020-07-21 3521 } else {
3fa1c6d1b8f5c3 Ronnie Sahlberg 2020-12-09 3522 v.UNC = ctx->UNC;
7efd081582619e Paulo Alcantara 2020-07-21 3523 v.prepath = path + 1;
7efd081582619e Paulo Alcantara 2020-07-21 3524 npath = build_unc_path_to_root(&v, cifs_sb, true);
5072010ccf0592 Paulo Alcantara (SUSE 2019-03-19 3525) }
ff2c54a04097de Paulo Alcantara 2021-02-24 3526
7efd081582619e Paulo Alcantara 2020-07-21 3527 if (IS_ERR(npath)) {
7efd081582619e Paulo Alcantara 2020-07-21 3528 rc = PTR_ERR(npath);
ff2c54a04097de Paulo Alcantara 2021-02-24 3529 goto out;
a6b5058fafdf50 Aurelien Aptel 2016-05-25 3530 }
ff2c54a04097de Paulo Alcantara 2021-02-24 3531
7efd081582619e Paulo Alcantara 2020-07-21 3532 kfree(*dfs_path);
7efd081582619e Paulo Alcantara 2020-07-21 3533 *dfs_path = npath;
ff2c54a04097de Paulo Alcantara 2021-02-24 3534 rc = -EREMOTE;
1bfe73c258addc Igor Mammedov 2009-04-01 3535 }
1bfe73c258addc Igor Mammedov 2009-04-01 3536
ff2c54a04097de Paulo Alcantara 2021-02-24 3537 out:
7efd081582619e Paulo Alcantara 2020-07-21 3538 kfree(path);
7efd081582619e Paulo Alcantara 2020-07-21 3539 return rc;
4a367dc0443566 Paulo Alcantara 2018-11-14 @3540 }
4a367dc0443566 Paulo Alcantara 2018-11-14 3541 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH 3/3 cifs: fix find_root_ses() when refresing dfs cache
In reply to Paulo Alcantaraget_tcp_server() and cifs_get_smb_ses() require most of the fs context info in order to find the respective tcp and ses pointers, so before calling them, dup original fs context and set new unc path with cifs_setup_volume_info().
--- fs/cifs/dfs_cache.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/cifs/dfs_cache.c +6 -0
@@ -1430,6 +1430,12 @@ static struct cifs_ses *find_root_ses(struct vol_info *vi,if (IS_ERR (rpath))return ERR_CAST (rpath); + rc =smb3_fs_context_dup (&ctx, &vi->ctx); +if (rc) { + ses =ERR_PTR (rc); + goto out; + } +down_read (&htable_rw_lock); ce =lookup_cache_entry (rpath,NULL );
Signature · 1 line
2.31.1