Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=143.255.12.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793827703; b=Rx1bzJ3rhR65hlsUmsK6DO+e9wmSq5kOQceVsGpzmD5lpiq1LWW7H1vn/6qdFNBp2vXM WEO9xe+TSM9GRc0N9pOBpWNhU9WaTI1rA1ZbuIy2ju2Tcdls4XllX1MgsQJFRHjDE+YOW B1sgUsjLDaRGPPHR4lvUY01iMQpoQUIhGxDcmlLPFl3ecYhhAgsjOn3wLRnyti+kcNOjI dSww/YwHd2r6p5PqRmIgAJ44bb3PbeT/Y5iXCQV8y2115GhGbIod/umJWSs4X5L+3SDLc O5RhBoFV+QJmD2tFFGP9kUwHmJ0634hxxEPngFieDZzq5Pm1SEvqq2TjpwkyA8I/1Iw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793827703; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=86Puqo14GUvykkFIIhNOK9+1OUPeTJlYvOahdnnC/zs=; b=LFlX6KLiC/+icHe+a9lUJU/zJGAeeXBOyn9Zmq9ENCpTBhbJr+shRADaWunQz7GsoOku 01pJeevsofV1ugSuMXdV5Q5Kc9NjyB4JsQPNxI5BHjnTQpwyGgPmMjzncJFea943CsJPj sdffBcyln+k+dFSiShKTR54d2yZR/LNh5an4zCsk6FWZzh0e+0eaWvr6l2lJca6tW8YH8 /SyDQocd+ABLU2jZRFyPHUXPhQNbEiAs9ZfkB9GuszGzkoIgF9T5xPn9F8fmg0GWT3Hsr XDEzBQl73k3SZfTJBB3dFRNN9dO+8Dh0s0KbNOWlaLjUfokNpIZpDOrVXf6v5pSM6ig== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=manguebit.org; spf=pass smtp.mailfrom=manguebit.org; dkim=pass header.d=manguebit.org header.i=@manguebit.org header.a=rsa-sha256 header.s=dkim header.b=NOrmRrls; arc=none smtp.remote-ip=143.255.12.172 Received: from mx1.manguebit.org (mx1.manguebit.org [143.255.12.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BB97606C910; Wed, 4 Nov 2026 21:28:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3BB97606C910 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manguebit.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=manguebit.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=manguebit.org header.i=@manguebit.org header.a=rsa-sha256 header.s=dkim header.b=NOrmRrls DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=manguebit.org; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Content-Type:Reply-To: Content-ID:Content-Description; bh=86Puqo14GUvykkFIIhNOK9+1OUPeTJlYvOahdnnC/zs=; b=NOrmRrlsC3aOpBTUHF9KdGVW9C dxrsmidzmlb/J08lpsPC7Ujt2at+sUsvxFOWD+krMiGRBPX/hc9Re0AtCWjGeApHZcydBb2Ch6VN5 7Qeri+uFKVasWCTuK5y/2DvkZ2o0GcvUaKYbYxJ7U60OusfUX81dnhM9rozmLgxt8j/KrTlVwKj+m bMlw86FDFjfDgLQgbSEkkYK1ZAvkroC+KJzeupNtNj4i1UVzu4c+1zLm15bIq1hT7glWXGU14Xoie 3rgAfE7DOG6Sx3wDLvvpAHY2wdHlowDqwvn8+U+A7cX8eB6xUu4XOqV5nkYfCifX2EUhodF2WJKAD hWa5h3NQ==; Received: from pc by mx1.manguebit.org with local (Exim 4.100.1) id 1xOiWl-00000000rIv-0skD; Wed, 04 Nov 2026 18:28:16 -0300 From: Paulo Alcantara To: linux-cifs@vger.kernel.org, netfs@lists.linux.dev, David Howells Cc: Namjae Jeon , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Bharath SM , Christian Brauner , stable@vger.kernel.org Subject: [PATCH v4 16/17] smb: client: fail writeback sends and reopens fast when the server is gone Date: Wed, 4 Nov 2026 18:28:09 -0300 Message-ID: <20261104212810.1935575-17-pc@manguebit.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261104212810.1935575-1-pc@manguebit.org> References: <20261104212810.1935575-1-pc@manguebit.org> X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A writeback whose send or handle reopen finds the server needing reconnect waits in smb2_reconnect() -> cifs_wait_for_server_reconnect() for the reconnect to finish - on a hard mount until the server returns or umount -f. But umount -f only breaks that wait for a request that entered it before the abort count was bumped; a send or reopen that enters afterwards, including the writeback that generic_shutdown_super() -> sync_filesystem() starts during the unmount itself, snapshots the already-bumped count and waits forever, hanging the unmount. Issue writeback sends and reopens without waiting for the reconnect: pass a nowait flag down to smb2_reconnect() and have it return -EAGAIN from every point it would otherwise wait in or loop back to cifs_wait_for_server_reconnect() - the initial need-reconnect check, the wait itself, a need-reconnect seen after taking the session mutex, and a failed renegotiation - not just the first. The subrequest is then retried from the netfs collector, which backs off and re-checks umount -f and the retry window before trying again. Reads, direct writes and every other command keep waiting as before. Fixes: 3ee1a1fc3981 ("cifs: Cut over to using netfslib") Signed-off-by: Paulo Alcantara Cc: stable@vger.kernel.org --- fs/smb/client/cifsglob.h | 1 + fs/smb/client/cifsproto.h | 3 ++- fs/smb/client/cifssmb.c | 2 +- fs/smb/client/file.c | 4 +++ fs/smb/client/misc.c | 7 +++++- fs/smb/client/smb2pdu.c | 52 ++++++++++++++++++++++++++++++++------- 6 files changed, 57 insertions(+), 12 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index 65f7a08eb751..0cc43ea48b77 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -1409,6 +1409,7 @@ struct cifs_open_parms { bool reconnect:1; bool replay:1; /* indicates that this open is for a replay */ bool no_replay:1; /* don't replay this open internally */ + bool no_reconnect_wait:1; /* fail fast, don't wait for reconnect */ struct kvec *ea_cctx; __le32 lease_flags; }; diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h index 8b7914dd13af..935fb31912ac 100644 --- a/fs/smb/client/cifsproto.h +++ b/fs/smb/client/cifsproto.h @@ -443,7 +443,8 @@ static inline int cifs_create_options(struct cifs_sb_info *cifs_sb, int options) } int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, - struct cifs_tcon *tcon, int aborts); + struct cifs_tcon *tcon, int aborts, + bool nowait); static inline void cifs_put_smb_ses(struct cifs_ses *ses) { diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index 712086eb3d1f..68f05a52605f 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -105,7 +105,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) spin_unlock(&tcon->tc_lock); again: - rc = cifs_wait_for_server_reconnect(server, tcon, aborts); + rc = cifs_wait_for_server_reconnect(server, tcon, aborts, false); if (rc) return rc; diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c index 724523c0cb4a..ad7ff7d2fdda 100644 --- a/fs/smb/client/file.c +++ b/fs/smb/client/file.c @@ -40,6 +40,7 @@ /* flags for cifs_reopen_file() */ #define CIFS_REOPEN_BOUND BIT(0) /* caller bounds the retries */ #define CIFS_REOPEN_REPLAY BIT(1) /* replay: reuse GUID + REPLAY op */ +#define CIFS_REOPEN_NOWAIT BIT(2) /* fail fast, skip reconnect wait */ static int cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush, unsigned int flags); @@ -176,6 +177,8 @@ static int cifs_reopen_file_retry(struct cifsFileInfo *cfile, bool can_flush, return -EIO; if (retrying) flags |= CIFS_REOPEN_REPLAY; + if (writeback) + flags |= CIFS_REOPEN_NOWAIT; reconnects = cifs_ses_reconnects(ses); rc = cifs_reopen_file(cfile, can_flush, flags); retrying = true; @@ -1656,6 +1659,7 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush, unsigned int flags) .reconnect = true, .no_replay = !!(flags & CIFS_REOPEN_BOUND), .replay = !!(flags & CIFS_REOPEN_REPLAY), + .no_reconnect_wait = !!(flags & CIFS_REOPEN_NOWAIT), }; /* diff --git a/fs/smb/client/misc.c b/fs/smb/client/misc.c index 13eb067ad88a..4a3ecf5c80f7 100644 --- a/fs/smb/client/misc.c +++ b/fs/smb/client/misc.c @@ -1081,7 +1081,8 @@ static bool reco_wait_done(struct TCP_Server_Info *server, } int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, - struct cifs_tcon *tcon, int aborts) + struct cifs_tcon *tcon, int aborts, + bool nowait) { int timeout = 10; int rc; @@ -1091,6 +1092,10 @@ int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, spin_unlock(&server->srv_lock); return 0; } + if (nowait) { + spin_unlock(&server->srv_lock); + return -EAGAIN; + } timeout *= server->nr_targets; spin_unlock(&server->srv_lock); diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index 7240910f60f1..e404351d577c 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -248,7 +248,8 @@ int smb3_update_ses_channels(struct cifs_ses *ses, struct TCP_Server_Info *serve static int smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, - struct TCP_Server_Info *server, bool from_reconnect) + struct TCP_Server_Info *server, bool from_reconnect, + bool nowait) { struct cifs_ses *ses; int aborts; @@ -311,6 +312,10 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, spin_unlock(&server->srv_lock); return -EAGAIN; } + if (nowait) { + spin_unlock(&server->srv_lock); + return -EAGAIN; + } } /* if server is marked for termination, cifsd will cleanup */ @@ -321,7 +326,7 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, spin_unlock(&server->srv_lock); again: - rc = cifs_wait_for_server_reconnect(server, tcon, aborts); + rc = cifs_wait_for_server_reconnect(server, tcon, aborts, nowait); if (rc) return rc; @@ -349,6 +354,8 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, case CifsNeedReconnect: spin_unlock(&server->srv_lock); mutex_unlock(&ses->session_mutex); + if (nowait) + return -EAGAIN; if (!cifs_tcon_retry(tcon, aborts)) return -EHOSTDOWN; goto again; @@ -380,6 +387,8 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, rc = cifs_negotiate_protocol(0, ses, server); if (rc) { mutex_unlock(&ses->session_mutex); + if (nowait) + return -EAGAIN; if (!cifs_tcon_retry(tcon, aborts)) return -EHOSTDOWN; goto again; @@ -592,7 +601,22 @@ static int smb2_plain_req_init(__le16 smb2_command, struct cifs_tcon *tcon, { int rc; - rc = smb2_reconnect(smb2_command, tcon, server, false); + rc = smb2_reconnect(smb2_command, tcon, server, false, false); + if (rc) + return rc; + + return __smb2_plain_req_init(smb2_command, tcon, server, request_buf, + total_len); +} + +/* As smb2_plain_req_init(), but fail fast instead of waiting for reconnect. */ +static int smb2_io_req_init(__le16 smb2_command, struct cifs_tcon *tcon, + struct TCP_Server_Info *server, + void **request_buf, unsigned int *total_len) +{ + int rc; + + rc = smb2_reconnect(smb2_command, tcon, server, false, true); if (rc) return rc; @@ -3147,8 +3171,12 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, __le16 *copy_path; int rc; - rc = smb2_plain_req_init(SMB2_CREATE, tcon, server, - (void **) &req, &total_len); + if (oparms->no_reconnect_wait) + rc = smb2_io_req_init(SMB2_CREATE, tcon, server, + (void **) &req, &total_len); + else + rc = smb2_plain_req_init(SMB2_CREATE, tcon, server, + (void **) &req, &total_len); if (rc) return rc; @@ -4359,7 +4387,8 @@ void smb2_reconnect_server(struct work_struct *work) spin_unlock(&cifs_tcp_ses_lock); list_for_each_entry_safe(tcon, tcon2, &tmp_list, rlist) { - rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon, server, true); + rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon, server, true, + false); if (!rc) { cifs_renegotiate_iosize(server, tcon); cifs_reopen_persistent_handles(tcon); @@ -4391,7 +4420,8 @@ void smb2_reconnect_server(struct work_struct *work) /* now reconnect sessions for necessary channels */ list_for_each_entry_safe(ses, ses2, &tmp_ses_list, rlist) { tcon->ses = ses; - rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon, server, true); + rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon, server, true, + false); if (rc) resched = true; list_del_init(&ses->rlist); @@ -5208,8 +5238,12 @@ smb2_async_writev(struct cifs_io_subrequest *wdata) }; io_parms = &_io_parms; - rc = smb2_plain_req_init(SMB2_WRITE, tcon, server, - (void **) &req, &total_len); + if (wdata->subreq.rreq->origin == NETFS_WRITEBACK) + rc = smb2_io_req_init(SMB2_WRITE, tcon, server, + (void **) &req, &total_len); + else + rc = smb2_plain_req_init(SMB2_WRITE, tcon, server, + (void **) &req, &total_len); if (rc) goto out; -- 2.56.0