Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp981175ybt; Wed, 17 Jun 2020 19:50:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoP6t05LrNrPqWDoLwUfnsnIVJUqXyKFchrKXKZYg9nm0L3WWNjRgaAH2GzFhfRFkVZAzb X-Received: by 2002:aa7:c2d3:: with SMTP id m19mr1993360edp.382.1592448625109; Wed, 17 Jun 2020 19:50:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592448625; cv=none; d=google.com; s=arc-20160816; b=yqGLgUcfHeWFKAFKZBfDq2Rd8py7ANDtRV/OvFritoCUCypkATYd2i54FmcgiUyOF4 aLNIOX7hjbntQ6t5+KpEwF89AyEXPOCg/w2ca8OAIVQdNH/JWsA2e9Cv2Lba2ynXTgYH yWCs1QBzyK03RW6KOiaNV4W2cWz/fehaRuiHTKTBqGbrGTq+bmOsfY+1bbVP158NZerW kDJDsSKGrkWaQv7neNCATp20ufYqa3D4a8hYv1KsMkd97vXKe1oJ5s9TdnnOZzyHIpma NR3OeePLPhV6SBKwps9b9Xb+1AQi5aNY5kvlxaXrmaN97UGuABcblOeqsSclTGCIpYui UhPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6dIZvFtGvlm48aq+2ydf0GJXRXiqRIBYpwRXHQLwq+A=; b=QY6B1Whe+hxo/VzwyIyWDbtoPIJBhwhbSOxp1c+ePvbY9ksOfVymMxIH49XShpg82n PivvgZKO3UhUUOqOA47Hver1yV/QTOSRWHDZRbpfz42w4TlXmYipP2YKTbvo71uI7Whl OEWo9IEnELFmPHAIBzvsJ4mgy9/Lo4wtn7srP8l7c+7ALA2VY32IZQmg2twcT3pnZp6X C8zx1fucHFYL1LI03Rqj8RZYxoQQ0eyxDwc4C7us8u4sxuF2eMhITxPav2LFccOwVGm3 Pr+U0qXq9C9/u1nsH9S2OOc6LMhUshvsNbC84QTEz+9d8DXhO5wBgCNlPtw/IDyujneN Ioxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Ii3/40K0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dm22si1262995ejc.535.2020.06.17.19.50.02; Wed, 17 Jun 2020 19:50:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Ii3/40K0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728367AbgFRBKB (ORCPT + 99 others); Wed, 17 Jun 2020 21:10:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:36706 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728343AbgFRBJ4 (ORCPT ); Wed, 17 Jun 2020 21:09:56 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DCB4221D92; Thu, 18 Jun 2020 01:09:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592442595; bh=LOq9WDryFQBQbvgVCaB1OKHLeNMRXnbcTegbuYzqQAY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ii3/40K02JKSed7s3eqJNmXksE8hBl7aS2hoX0UxhNZTvD6ryV+vNXr4LXAnZsbYT C0GZiGSLfAXdz/HFp+P2tkaVlBYIUNjdXtLk1YfG6SiccSgj8CalYUvAHLj1uqa8m1 bsCL8SIfFZqkdTqfSN8r5JVurMnEOhLkI6l7W2yA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Paulo Alcantara , Aurelien Aptel , Steve French , Sasha Levin , linux-cifs@vger.kernel.org, samba-technical@lists.samba.org Subject: [PATCH AUTOSEL 5.7 084/388] cifs: set up next DFS target before generic_ip_connect() Date: Wed, 17 Jun 2020 21:03:01 -0400 Message-Id: <20200618010805.600873-84-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200618010805.600873-1-sashal@kernel.org> References: <20200618010805.600873-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paulo Alcantara [ Upstream commit aaa3aef34d3ab9499a5c7633823429f7a24e6dff ] If we mount a very specific DFS link \\FS0.FOO.COM\dfs\link -> \FS0\share1, \FS1\share2 where its target list contains NB names ("FS0" & "FS1") rather than FQDN ones ("FS0.FOO.COM" & "FS1.FOO.COM"), we end up connecting to \FOO\share1 but server->hostname will have "FOO.COM". The reason is because both "FS0" and "FS0.FOO.COM" resolve to same IP address and they share same TCP server connection, but "FS0.FOO.COM" was the first hostname set -- which is OK. However, if the echo thread timeouts and we still have a good connection to "FS0", in cifs_reconnect() rc = generic_ip_connect(server) -> success if (rc) { ... reconn_inval_dfs_target(server, cifs_sb, &tgt_list, &tgt_it); ... } ... it successfully reconnects to "FS0" server but does not set up next DFS target - which should be the same target server "\FS0\share1" - and server->hostname remains set to "FS0.FOO.COM" rather than "FS0", as reconn_inval_dfs_target() would have it set to "FS0" if called earlier. Finally, in __smb2_reconnect(), the reconnect of tcons would fail because tcon->ses->server->hostname (FS0.FOO.COM) does not match DFS target's hostname (FS0). Fix that by calling reconn_inval_dfs_target() before generic_ip_connect() so server->hostname will get updated correctly prior to reconnecting its tcons in __smb2_reconnect(). With "cifs: handle hostnames that resolve to same ip in failover" patch - The above problem would not occur. - We could save an DNS query to find out that they both resolve to the same ip address. Signed-off-by: Paulo Alcantara (SUSE) Reviewed-by: Aurelien Aptel Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/cifs/connect.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 28268ed461b8..47b9fbb70bf5 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -572,26 +572,26 @@ cifs_reconnect(struct TCP_Server_Info *server) try_to_freeze(); mutex_lock(&server->srv_mutex); +#ifdef CONFIG_CIFS_DFS_UPCALL /* * Set up next DFS target server (if any) for reconnect. If DFS * feature is disabled, then we will retry last server we * connected to before. */ + reconn_inval_dfs_target(server, cifs_sb, &tgt_list, &tgt_it); +#endif + rc = reconn_set_ipaddr(server); + if (rc) { + cifs_dbg(FYI, "%s: failed to resolve hostname: %d\n", + __func__, rc); + } + if (cifs_rdma_enabled(server)) rc = smbd_reconnect(server); else rc = generic_ip_connect(server); if (rc) { cifs_dbg(FYI, "reconnect error %d\n", rc); -#ifdef CONFIG_CIFS_DFS_UPCALL - reconn_inval_dfs_target(server, cifs_sb, &tgt_list, - &tgt_it); -#endif - rc = reconn_set_ipaddr(server); - if (rc) { - cifs_dbg(FYI, "%s: failed to resolve hostname: %d\n", - __func__, rc); - } mutex_unlock(&server->srv_mutex); msleep(3000); } else { -- 2.25.1