From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=144.76.82.148 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796391275; b=Dks0MieQtyeKDkW3dCkWRVh2cmEqOdk/5tQWx4IkqE+e4xiFscghHkjzZlIWGZMUZtUi S3xChs743qMQKAW0ujYAOf9uS8YuFDT2cPn/EYr1sMIjq1fVfjlfSswQ/iTCrQry9z/nX Cl9grzRsztaRkMZxe3quflyKHNLXZq65d9/gIKJwhK+RkXv/Nu8LNNHcpCI3B36Yt/zCz JX1VVwgEbWtkAczBPwHMFeHf1lz6wNZqMffqde6limsXKmZVHb1nMjHmeYS7dvxuHpOVm SjXYEyi65QLgpUZDvvKGKPXUbxMazsvdLxi8H4Am2xJbomySKuxQMt5gKjZ5Sqy4iRQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796391275; 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=C6IUEKqAgzxxQFNzxcjG5RvJXr46U9GUuHvf8NFHw7o=; b=P5df5SZaqbtwKwBZnhgG/o2LVbP5bN5huELJp3jMNy6aXE4bhFdG3vsIzM7rGYE6XsJn TtBIqGeIkfGQT5GpMXz3SFEjL4eA/7P6IKgZ4GuOFu6DpUShCS2sIkNaAswLf2qrqxqxH iJ3rQ9nbLPqig3/IBM6N3sY9wCqbc1TwaMYU97f23J9GI+o/w7mwk7oBREZcxLKPgCCmO BH4gEZvpERwlmjTPpHUPfou6CiQHBc4Boxl6RTPTP7Cdi/HTncsD0otx2GWuClCqP913Y 3JFKdR+yO8AzjRrAi/rOVtb1eYRrSSSsoS47ZALxLtz6TGF0H10P322BP9GkvqukcRg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=samba.org; spf=pass smtp.mailfrom=samba.org; dkim=pass header.d=samba.org header.i=@samba.org header.a=rsa-sha256 header.s=42 header.b=c2xnyVfb; arc=none smtp.remote-ip=144.76.82.148 Received: from hr2.samba.org (hr2.samba.org [144.76.82.148]) (using TLSv1.3 with cipher TLS_CHACHA20_POLY1305_SHA256 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 445EA606A32C; Fri, 4 Dec 2026 13:34:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 445EA606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=samba.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samba.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (3072-bit key) header.d=samba.org header.i=@samba.org header.a=rsa-sha256 header.s=42 header.b=c2xnyVfb DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=samba.org; s=42; h=Message-ID:Date:Cc:To:From; bh=C6IUEKqAgzxxQFNzxcjG5RvJXr46U9GUuHvf8NFHw7o=; b=c2xnyVfbbP1sY2H1528S/+vqjt KGa5PjAmliTvak1/4BXkxDlxkzfUuS5xp/f5iTo1D4O0xT3w3LEozxzakoimI+K9/iL516BlDwe7i J5PyTx5/lAZ3PcqXu2b8nqyu90as3pcyjeogP9Gm5KPltcIUQQhsZx+q4dJVPBhgGOwI1WHi1vQHt /mxt2vwE6ysLyw7vl+yCMlIohdzIjIT1/qcH9zI/JWJLkgLBJ1aapwodaiJi/D2XNIQ9LK2mJ8Yo4 ntfQFGLzlheWpHjECaXMx55Tkrpj8kbdbWqrLwFQbEvIMrc0ZZoDP/Sc1HOEzNx1+lYgOWTkbx4iE XoDvlvyhs5ufG1lDdqkma6NOZpix3/CxDHVBsItMUJfLVVDz0vQkGujupiC2pea1jO4wvft0aiq/5 lpDpFvIGENYhHZlXxyzQyRzh8bu9EaZc6EQ77YMdObDP9zHDJh5//qGCLsL72SByDCrhiszg0VIZT d5S+RxJ6QrYxhzVEQrGfeyNv; Received: from [127.0.0.2] (localhost [127.0.0.1]) by hr2.samba.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__ECDSA_SECP256R1_SHA256__CHACHA20_POLY1305:256) (Exim) id 1xZTQk-00000000IBu-24CL; Fri, 04 Dec 2026 13:34:30 +0000 From: Stefan Metzmacher To: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org Cc: metze@samba.org, stable@vger.kernel.org, Paulo Alcantara , Namjae Jeon , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Bharath SM , linux-kernel@vger.kernel.org Subject: [PATCH v2 08/12] smb: client: add cifs_server_wait_for_exit_ms() Date: Fri, 4 Dec 2026 14:33:33 +0100 Message-ID: <2ea5cac93cf8ffbd523a4952eee83b420a80e96e.1796391093.git.metze@samba.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: X-Mailing-List: linux-kernel@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 It sleeps for at most the given time, but stops early once the server is exiting, as cifs_put_tcp_session() and clean_demultiplex_info() wake up server->response_q after setting CifsExiting. Use it to replace the msleep() calls in the demultiplex thread, which retries after a failed buffer allocation and waits after a negative RFC 1002 session response, so that they don't delay the exit of the server. This is also a prerequisite for "smb: client: use cifs_server_wait_for_exit_ms() for the replay back-off", so it carries the Fixes tag of that patch as well. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Fixes: 665e18794804 ("cifs: Improve handling of NetBIOS packets") Fixes: 4f1fffa23769 ("cifs: commands that are retried should have replay flag set") Cc: stable@vger.kernel.org Cc: Paulo Alcantara Cc: Namjae Jeon Cc: Ronnie Sahlberg Cc: Shyam Prasad N Cc: Tom Talpey Cc: Bharath SM Cc: linux-cifs@vger.kernel.org Cc: samba-technical@lists.samba.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Stefan Metzmacher --- fs/smb/client/cifsproto.h | 2 ++ fs/smb/client/connect.c | 6 +++--- fs/smb/client/misc.c | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h index 402446435105..c9ae85422f10 100644 --- a/fs/smb/client/cifsproto.h +++ b/fs/smb/client/cifsproto.h @@ -450,6 +450,8 @@ void cifs_wake_ses_waiters(struct cifs_ses *ses); int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, struct cifs_tcon *tcon, int aborts, bool nowait); +bool cifs_server_wait_for_exit_ms(struct TCP_Server_Info *server, + unsigned int msecs); static inline void cifs_put_smb_ses(struct cifs_ses *ses) { diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c index ff26b1980bb7..c5fa675e6a11 100644 --- a/fs/smb/client/connect.c +++ b/fs/smb/client/connect.c @@ -690,7 +690,7 @@ allocate_buffers(struct TCP_Server_Info *server) server->bigbuf = (char *)cifs_buf_get(); if (!server->bigbuf) { cifs_server_dbg(VFS, "No memory for large SMB response\n"); - msleep(3000); + cifs_server_wait_for_exit_ms(server, 3000); /* retry will check if exiting */ return false; } @@ -703,7 +703,7 @@ allocate_buffers(struct TCP_Server_Info *server) server->smallbuf = (char *)cifs_small_buf_get(); if (!server->smallbuf) { cifs_server_dbg(VFS, "No memory for SMB response\n"); - msleep(1000); + cifs_server_wait_for_exit_ms(server, 1000); /* retry will check if exiting */ return false; } @@ -976,7 +976,7 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type) * mount context will fail at all. */ if (rc != 0) - msleep(2000); + cifs_server_wait_for_exit_ms(server, 2000); } else { cifs_server_dbg(VFS, "RFC 1002 negative session response (unexpected)\n"); cifs_reconnect(server, true); diff --git a/fs/smb/client/misc.c b/fs/smb/client/misc.c index a0e7818d3c8d..197f39c23119 100644 --- a/fs/smb/client/misc.c +++ b/fs/smb/client/misc.c @@ -1078,6 +1078,23 @@ int cifs_inval_name_dfs_link_error(const unsigned int xid, } #endif +/* + * Sleep for at most @msecs, but stop early once the server is exiting, + * cifs_put_tcp_session() and clean_demultiplex_info() wake up + * server->response_q after setting CifsExiting. + * + * Returns true if the server is exiting. + */ +bool cifs_server_wait_for_exit_ms(struct TCP_Server_Info *server, + unsigned int msecs) +{ + wait_event_timeout(server->response_q, + READ_ONCE(server->tcpStatus) == CifsExiting, + msecs_to_jiffies(msecs)); + + return READ_ONCE(server->tcpStatus) == CifsExiting; +} + static bool reco_wait_done(struct TCP_Server_Info *server, struct cifs_tcon *tcon, int aborts) { -- 2.43.0