From nobody Fri Dec 19 19:23:34 2025 Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A387623D7E3 for ; Thu, 4 Dec 2025 04:59:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824387; cv=none; b=fX2le2kTFb2Ib941i594q6vTRQJD+cqCuJsQ8l2zCCguimoB7m/vZO8JbE5bwFoxM33GTrVt268DybrxjIdNxwMb96ttTClYw5OXcMcFG2OwAvv5pLJwmKynzXrvtg+JItvR5cKgv1XygCokbgCj8d39uKuLAn/jhoUtbp8LqGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824387; c=relaxed/simple; bh=6aXn44a1M6nJNTujS0JveAqJewtw4mFPNA/YcXrkO6Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QD9wNVM3aycPKHCpxFqFbSGwjKOt1R7HUAICNrzgvozaJCa35URd+JyFf1rlb1mew+nJHGAiGbllhwUYeLUwfDGY3ugspxKA/w2SfrG/K8x1dydvTTPdgN3ENZMd8+TyGHGsa2YEx2puxzONevn6Ys1OXA9dXzMr0uhcD3o9EBE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=La6ekXPl; arc=none smtp.client-ip=95.215.58.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="La6ekXPl" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1764824383; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9E4YQC4tLUss3JEGgnYG4E8jlhj+nguaNxjZ4U4/UwY=; b=La6ekXPlqOMsGhBixHtv6DGY2oHK+2cbf9HSjixNQ/XxHFZmuaEH1fOBK3vWcLsgIXy7tO eNrN35nM0tJVU4if1D2/4Vtza5tWIEkWpTiyvYA0cZnfaAjcZZwerjYtt5VSYUg5EfeNZT Nyd1itTB+Kq8pl3NJfC4RO3Z3LuB3GM= From: chenxiaosong.chenxiaosong@linux.dev To: sfrench@samba.org, smfrench@gmail.com, linkinjeon@kernel.org, linkinjeon@samba.org Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, chenxiaosong@chenxiaosong.com, ChenXiaoSong Subject: [PATCH 01/10] smb/client: reduce loop count in map_smb2_to_linux_error() by half Date: Thu, 4 Dec 2025 12:58:09 +0800 Message-ID: <20251204045818.2590727-2-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: ChenXiaoSong The smb2_error_map_table array currently has 1740 elements. When searching for the last element and calling smb2_print_status(), 3480 comparisons are needed. The loop in smb2_print_status() is unnecessary, smb2_print_status() can be removed, and only iterate over the array once, printing the message when the target status code is found. Signed-off-by: ChenXiaoSong --- fs/smb/client/smb2maperror.c | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/fs/smb/client/smb2maperror.c b/fs/smb/client/smb2maperror.c index 12c2b868789f..d1df6e518d21 100644 --- a/fs/smb/client/smb2maperror.c +++ b/fs/smb/client/smb2maperror.c @@ -2418,24 +2418,6 @@ static const struct status_to_posix_error smb2_error= _map_table[] =3D { {0, 0, NULL} }; =20 -/*************************************************************************= **** - Print an error message from the status code - *************************************************************************= ****/ -static void -smb2_print_status(__le32 status) -{ - int idx =3D 0; - - while (smb2_error_map_table[idx].status_string !=3D NULL) { - if ((smb2_error_map_table[idx].smb2_status) =3D=3D status) { - pr_notice("Status code returned 0x%08x %s\n", status, - smb2_error_map_table[idx].status_string); - } - idx++; - } - return; -} - int map_smb2_to_linux_error(char *buf, bool log_err) { @@ -2452,16 +2434,16 @@ map_smb2_to_linux_error(char *buf, bool log_err) return 0; } =20 - /* mask facility */ - if (log_err && (smb2err !=3D STATUS_MORE_PROCESSING_REQUIRED) && - (smb2err !=3D STATUS_END_OF_FILE)) - smb2_print_status(smb2err); - else if (cifsFYI & CIFS_RC) - smb2_print_status(smb2err); + log_err =3D (log_err && (smb2err !=3D STATUS_MORE_PROCESSING_REQUIRED) && + (smb2err !=3D STATUS_END_OF_FILE)) || + (cifsFYI & CIFS_RC); =20 for (i =3D 0; i < sizeof(smb2_error_map_table) / sizeof(struct status_to_posix_error); i++) { if (smb2_error_map_table[i].smb2_status =3D=3D smb2err) { + if (log_err) + pr_notice("Status code returned 0x%08x %s\n", smb2err, + smb2_error_map_table[i].status_string); rc =3D smb2_error_map_table[i].posix_error; break; } --=20 2.43.0 From nobody Fri Dec 19 19:23:34 2025 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0E9A2FC038 for ; Thu, 4 Dec 2025 04:59:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824391; cv=none; b=mBASnBp/nJRxiFVY6+ierLU3iFEcKF9PooAphGqpbdOwrfbSOWlCAfjLQAn4oCZPZiKP7erbUdC7vyUYKeDD2yYVTKaQ7ANRkxAJ4y1zOJWEzoKstp9admfj+/8UztUCDlyhCo56rnd8dHxF7SiZUVJAxzMBxoKDcDxSJwKngho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824391; c=relaxed/simple; bh=pkfzsbbhoS8dSc0sCXHcgR0baQMXz4nmCTpdqOcLZkM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NPjVhpE3+AjwpXAOfzIwa5hWhkoWCHjceVY++k4BpWSJBq58zy/uV8BWCC/AHjGBAYAd9jLEJHdaoAyuQUvBUEe04/6Dx6epA4sRiXSVZU+GuPXROAy87FsUHXL4/6g1CJ4H8+ntnkSrh69jlLHWdgexYvNFa06AL11Fg7lN6ps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=qrJRreqU; arc=none smtp.client-ip=95.215.58.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="qrJRreqU" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1764824386; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tpu2+fHhdm+SVBxmfXBwkvLZquyK3vrWeg83HtvStqA=; b=qrJRreqUBYM7lO0FSS+ISqvDYcsWIkW7FTyM5RppZ6AKqQ528+HXN7gGlJWNfoxAyr5pFn qaprrb2wD+5Ur79JzaNzcViC/uoRtUz1moAMHVLcY5PsBtWmD/5rxxKDHiq+jvfre9bnUE 9oSdgrHxPNvzl4YM2K2VLGFS0GSCKlk= From: chenxiaosong.chenxiaosong@linux.dev To: sfrench@samba.org, smfrench@gmail.com, linkinjeon@kernel.org, linkinjeon@samba.org Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, chenxiaosong@chenxiaosong.com, ChenXiaoSong Subject: [PATCH 02/10] smb/client: remove unused elements from smb2_error_map_table array Date: Thu, 4 Dec 2025 12:58:10 +0800 Message-ID: <20251204045818.2590727-3-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: ChenXiaoSong STATUS_SUCCESS and STATUS_WAIT_0 are both zero, and since zero indicates success, they are not needed. Since smb2_print_status() has been removed, the last element in the array is no longer needed. Signed-off-by: ChenXiaoSong --- fs/smb/client/smb2maperror.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fs/smb/client/smb2maperror.c b/fs/smb/client/smb2maperror.c index d1df6e518d21..118e32cc8edc 100644 --- a/fs/smb/client/smb2maperror.c +++ b/fs/smb/client/smb2maperror.c @@ -23,8 +23,6 @@ struct status_to_posix_error { }; =20 static const struct status_to_posix_error smb2_error_map_table[] =3D { - {STATUS_SUCCESS, 0, "STATUS_SUCCESS"}, - {STATUS_WAIT_0, 0, "STATUS_WAIT_0"}, {STATUS_WAIT_1, -EIO, "STATUS_WAIT_1"}, {STATUS_WAIT_2, -EIO, "STATUS_WAIT_2"}, {STATUS_WAIT_3, -EIO, "STATUS_WAIT_3"}, @@ -2415,7 +2413,6 @@ static const struct status_to_posix_error smb2_error_= map_table[] =3D { {STATUS_IPSEC_INTEGRITY_CHECK_FAILED, -EIO, "STATUS_IPSEC_INTEGRITY_CHECK_FAILED"}, {STATUS_IPSEC_CLEAR_TEXT_DROP, -EIO, "STATUS_IPSEC_CLEAR_TEXT_DROP"}, - {0, 0, NULL} }; =20 int --=20 2.43.0 From nobody Fri Dec 19 19:23:34 2025 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25BF92D321B for ; Thu, 4 Dec 2025 04:59:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824393; cv=none; b=QV/Lm/43Cy9wu0lCj3tKooWDRs/d3blPeA3H7MptjU+2DWAoP3A2A3dCchyUbmR3MQ826Xo4+b4Lvkq0WxZWMR/iX2KIH1Kmx+ujn1zUaGIpvgJze1TeLvEYB8fG2vgv31NQG34RjiqCINlb/xK3zAgDXzjHnOmrclClolDky7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824393; c=relaxed/simple; bh=wHQHPGOBL67LojJYdHJntJqg3PyDMhkYPnnAIameZCs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IpfuWm94AomqVoed1w/DMYEdhaDPabadfOiYjuvHzIEmNRlcOOP9mtji2Pqe67IIU4FFHzNUQi6POBkfWEcR1jKdpiwZrK/2iTWA6ZdsHa97mcqjM2ig1TkNHr7I/cXpjsekgRVjqwM/aK8kZYm34DUXmh9vJcrI3/J+BR3MTKg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=H74RaZP/; arc=none smtp.client-ip=95.215.58.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="H74RaZP/" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1764824388; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=spW3FIUdbUtBzBiQQzKvx4iZUCmDJ5m4MvmIKanhjUw=; b=H74RaZP/lLXfRt1P0F0FIlEfUiHIFXRDGa+c2NIQTowszxo7Zn+y5tP6eqszofzTFdXIJR IQK0MG+PFcU9c+2WKrJZCuJovFm7Ed5X5278NMR02UpPWCSRs8559epPEoKWnSMmgUNCCa hFWyjkP+eY7MAIGfOj1YrVDby4vS/Ik= From: chenxiaosong.chenxiaosong@linux.dev To: sfrench@samba.org, smfrench@gmail.com, linkinjeon@kernel.org, linkinjeon@samba.org Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, chenxiaosong@chenxiaosong.com, ChenXiaoSong Subject: [PATCH 03/10] smb: add two elements to smb2_error_map_table array Date: Thu, 4 Dec 2025 12:58:11 +0800 Message-ID: <20251204045818.2590727-4-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: ChenXiaoSong Both status codes are mapped to -EIO. STATUS_NO_PREAUTH_INTEGRITY_HASH_OVERLAP -> STATUS_SMB_NO_PREAUTH_INTEGRITY= _HASH_OVERLAP, to keep it consistent with the documentation. Signed-off-by: ChenXiaoSong --- fs/smb/client/smb2maperror.c | 3 +++ fs/smb/common/smb2status.h | 5 +++-- fs/smb/server/smb2pdu.c | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/smb/client/smb2maperror.c b/fs/smb/client/smb2maperror.c index 118e32cc8edc..a77467d2d81c 100644 --- a/fs/smb/client/smb2maperror.c +++ b/fs/smb/client/smb2maperror.c @@ -734,6 +734,7 @@ static const struct status_to_posix_error smb2_error_ma= p_table[] =3D { {STATUS_FS_DRIVER_REQUIRED, -EOPNOTSUPP, "STATUS_FS_DRIVER_REQUIRED"}, {STATUS_IMAGE_ALREADY_LOADED_AS_DLL, -EIO, "STATUS_IMAGE_ALREADY_LOADED_AS_DLL"}, + {STATUS_INVALID_LOCK_RANGE, -EIO, "STATUS_INVALID_LOCK_RANGE"}, {STATUS_NETWORK_OPEN_RESTRICTION, -EIO, "STATUS_NETWORK_OPEN_RESTRICTION"}, {STATUS_NO_USER_SESSION_KEY, -EIO, "STATUS_NO_USER_SESSION_KEY"}, @@ -2413,6 +2414,8 @@ static const struct status_to_posix_error smb2_error_= map_table[] =3D { {STATUS_IPSEC_INTEGRITY_CHECK_FAILED, -EIO, "STATUS_IPSEC_INTEGRITY_CHECK_FAILED"}, {STATUS_IPSEC_CLEAR_TEXT_DROP, -EIO, "STATUS_IPSEC_CLEAR_TEXT_DROP"}, + {STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP, -EIO, + "STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP"}, }; =20 int diff --git a/fs/smb/common/smb2status.h b/fs/smb/common/smb2status.h index 14b4a5f04564..7d6b8ed304fc 100644 --- a/fs/smb/common/smb2status.h +++ b/fs/smb/common/smb2status.h @@ -631,6 +631,7 @@ struct ntstatus { #define STATUS_DOMAIN_TRUST_INCONSISTENT cpu_to_le32(0xC000019B) #define STATUS_FS_DRIVER_REQUIRED cpu_to_le32(0xC000019C) #define STATUS_IMAGE_ALREADY_LOADED_AS_DLL cpu_to_le32(0xC000019D) +#define STATUS_INVALID_LOCK_RANGE cpu_to_le32(0xC00001A1) #define STATUS_NETWORK_OPEN_RESTRICTION cpu_to_le32(0xC0000201) #define STATUS_NO_USER_SESSION_KEY cpu_to_le32(0xC0000202) #define STATUS_USER_SESSION_DELETED cpu_to_le32(0xC0000203) @@ -1773,5 +1774,5 @@ struct ntstatus { #define STATUS_IPSEC_INVALID_PACKET cpu_to_le32(0xC0360005) #define STATUS_IPSEC_INTEGRITY_CHECK_FAILED cpu_to_le32(0xC0360006) #define STATUS_IPSEC_CLEAR_TEXT_DROP cpu_to_le32(0xC0360007) -#define STATUS_NO_PREAUTH_INTEGRITY_HASH_OVERLAP cpu_to_le32(0xC05D0000) -#define STATUS_INVALID_LOCK_RANGE cpu_to_le32(0xC00001a1) +/* See MS-SMB2 3.3.5.4 */ +#define STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP cpu_to_le32(0xC05D000= 0) diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index 60839850025d..d70b4d32e8bc 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -896,7 +896,7 @@ static __le32 decode_preauth_ctxt(struct ksmbd_conn *co= nn, return STATUS_INVALID_PARAMETER; =20 if (pneg_ctxt->HashAlgorithms !=3D SMB2_PREAUTH_INTEGRITY_SHA512) - return STATUS_NO_PREAUTH_INTEGRITY_HASH_OVERLAP; + return STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP; =20 conn->preauth_info->Preauth_HashId =3D SMB2_PREAUTH_INTEGRITY_SHA512; return STATUS_SUCCESS; --=20 2.43.0 From nobody Fri Dec 19 19:23:34 2025 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C3ED1DE89A for ; Thu, 4 Dec 2025 04:59:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824395; cv=none; b=UcP/mu+2u7yCzCkEb/JNnk9ADB1Iiwyw9Bft9wizZNoAWo1LH+PEm0F93MpCa83UlNf8w9jdFR1P/ur6yqkZjh+V6ZzKkJsoWGAL8ky2lsLp9GZwtxEoyskJlBmEIoRDkxkk407mtUeOSG7wf8D19YvUMOJjutescqQO+KEubtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824395; c=relaxed/simple; bh=IBYCJ0URnZmHAFg6rVEL8/OhHpGcyVNVskFuPS8njGA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DqH4+yagKPtCVYgIpH0+8wICyP1qjcUFN7Ny0s+OYzSo6cO7LXbmWtTvIqPZ139Fcpt+HldHYlduCPUvM+jZv70Do61u9OBh1lSXKjSUkhe9hWviKxQFRq5L8MM5MbDi/GUj0EIrVz0O8d62cS7nT779Vi5yUsco+clmBdKnbno= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Q1RhsfUj; arc=none smtp.client-ip=95.215.58.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Q1RhsfUj" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1764824391; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dwt91f0JwYANteB0KGN5KnaqVqKN9Td/UOVyuvc+nkw=; b=Q1RhsfUjnszoMkw5Z56ZiTv6rKSw2p+I+BvEFjEPKyAAnyYNvDM7d/HPiSJbtyGqFORyOg cg0rkRMFfv+ut95vt8zo8TK1z2xHYypwavurEqW/sFDzfDD41TVSvGCS3juppN8khBZg6F YdYxgRbyNlhv6GZggj17juQbvbDg/iE= From: chenxiaosong.chenxiaosong@linux.dev To: sfrench@samba.org, smfrench@gmail.com, linkinjeon@kernel.org, linkinjeon@samba.org Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, chenxiaosong@chenxiaosong.com, ChenXiaoSong Subject: [PATCH 04/10] smb/client: sort smb2_error_map_table array Date: Thu, 4 Dec 2025 12:58:12 +0800 Message-ID: <20251204045818.2590727-5-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: ChenXiaoSong Sort the array in ascending order, and then we can use binary search algorithm to quickly find the target status code. Since the smb2_init_maperror() is called only once when the module is loaded, the array is sorted just once. Signed-off-by: ChenXiaoSong --- fs/smb/client/cifsfs.c | 2 ++ fs/smb/client/smb2maperror.c | 25 ++++++++++++++++++++++++- fs/smb/client/smb2proto.h | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c index 6eccb9ed9daa..77d14b3dd650 100644 --- a/fs/smb/client/cifsfs.c +++ b/fs/smb/client/cifsfs.c @@ -49,6 +49,7 @@ #endif #include "fs_context.h" #include "cached_dir.h" +#include "smb2proto.h" =20 /* * DOS dates from 1980/1/1 through 2107/12/31 @@ -1908,6 +1909,7 @@ static int __init init_cifs(void) { int rc =3D 0; + smb2_init_maperror(); cifs_proc_init(); INIT_LIST_HEAD(&cifs_tcp_ses_list); /* diff --git a/fs/smb/client/smb2maperror.c b/fs/smb/client/smb2maperror.c index a77467d2d81c..1bd4196386dd 100644 --- a/fs/smb/client/smb2maperror.c +++ b/fs/smb/client/smb2maperror.c @@ -8,6 +8,7 @@ * */ #include +#include #include "cifsglob.h" #include "cifs_debug.h" #include "smb2pdu.h" @@ -22,7 +23,7 @@ struct status_to_posix_error { char *status_string; }; =20 -static const struct status_to_posix_error smb2_error_map_table[] =3D { +static struct status_to_posix_error smb2_error_map_table[] =3D { {STATUS_WAIT_1, -EIO, "STATUS_WAIT_1"}, {STATUS_WAIT_2, -EIO, "STATUS_WAIT_2"}, {STATUS_WAIT_3, -EIO, "STATUS_WAIT_3"}, @@ -2418,6 +2419,20 @@ static const struct status_to_posix_error smb2_error= _map_table[] =3D { "STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP"}, }; =20 +static unsigned int err_map_num =3D sizeof(smb2_error_map_table) / + sizeof(struct status_to_posix_error); + +static int cmp_smb2_status(const void *_a, const void *_b) +{ + const struct status_to_posix_error *a =3D _a, *b =3D _b; + + if (a->smb2_status < b->smb2_status) + return -1; + if (a->smb2_status > b->smb2_status) + return 1; + return 0; +} + int map_smb2_to_linux_error(char *buf, bool log_err) { @@ -2461,3 +2476,11 @@ map_smb2_to_linux_error(char *buf, bool log_err) le32_to_cpu(smb2err), rc); return rc; } + +void smb2_init_maperror(void) +{ + /* Sort in ascending order */ + sort(smb2_error_map_table, err_map_num, + sizeof(struct status_to_posix_error), + cmp_smb2_status, NULL); +} diff --git a/fs/smb/client/smb2proto.h b/fs/smb/client/smb2proto.h index 5241daaae543..c988f6b37a1b 100644 --- a/fs/smb/client/smb2proto.h +++ b/fs/smb/client/smb2proto.h @@ -21,6 +21,7 @@ struct smb_rqst; ***************************************************************** */ extern int map_smb2_to_linux_error(char *buf, bool log_err); +extern void smb2_init_maperror(void); extern int smb2_check_message(char *buf, unsigned int length, struct TCP_Server_Info *server); extern unsigned int smb2_calc_size(void *buf); --=20 2.43.0 From nobody Fri Dec 19 19:23:34 2025 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 745E2288C2C for ; Thu, 4 Dec 2025 04:59:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824397; cv=none; b=BPD4uPfTUdt3t3nHUewPIwM+CRTgd6sMfeaOW3sng9DIgh3xwBCDk4Uf5Mo5PtGiSkS0kGQbRIdhcmxcq+y21CX4HReXCMfgEw88JQFqxbk1qH+c2B5GEvpWXuGFGpOlm9Zo5r7/kXeiYX6FsLBUsVq/ZI6a0TCNogAXxWJNFws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824397; c=relaxed/simple; bh=GpiP28Us9v7/dQoXwcAvnftubvrrsWxq7Q4tJTESinM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VTNGQh+Ky1xYoOzggLX7X/Q77sRpNEMF0ttizo+tQhEtqLJmWhGBGqRAYg5/+R/KcMXVVAEaNk0Zq9zKVTJAgx8uFVPck2cX8RkYm6YyjyGGUIKoYtNGKhZy26qCjIz9fccbOgtDa893YYGr5qG66si9BH6FaqgqSUoZ8AbZVJg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=X4pOXzZA; arc=none smtp.client-ip=95.215.58.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="X4pOXzZA" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1764824393; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CCS9W0lF6HDGhdijp7vL3LJGT24noIkWUUQS/1Ee9+o=; b=X4pOXzZAphkjm1PliFqquNW9NEKklaTCK7rzT1nNEn5efFy0d9jyrx5IIOJPv5weVsCllD 2aVbIEbqH8uloaIOrOJMM5t5R5MLljfToMpndCo3+SQhZOM6+NPjxi3/s9Jlcb6REQ+4gp SEszs7MLwIlsxzrMvB52oDCe3e8ZD4g= From: chenxiaosong.chenxiaosong@linux.dev To: sfrench@samba.org, smfrench@gmail.com, linkinjeon@kernel.org, linkinjeon@samba.org Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, chenxiaosong@chenxiaosong.com, ChenXiaoSong Subject: [PATCH 05/10] smb/client: use bsearch() to find target status code Date: Thu, 4 Dec 2025 12:58:13 +0800 Message-ID: <20251204045818.2590727-6-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: ChenXiaoSong The smb2_error_map_table array currently has 1742 elements. When searching for the last element, the original loop-based search method requires 1742 comparisons, while binary search algorithm requires only 10 comparisons. Signed-off-by: ChenXiaoSong --- fs/smb/client/smb2maperror.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/fs/smb/client/smb2maperror.c b/fs/smb/client/smb2maperror.c index 1bd4196386dd..df8db12ff7a9 100644 --- a/fs/smb/client/smb2maperror.c +++ b/fs/smb/client/smb2maperror.c @@ -2437,9 +2437,9 @@ int map_smb2_to_linux_error(char *buf, bool log_err) { struct smb2_hdr *shdr =3D (struct smb2_hdr *)buf; - unsigned int i; int rc =3D -EIO; __le32 smb2err =3D shdr->Status; + struct status_to_posix_error *err_map, key; =20 if (smb2err =3D=3D 0) { trace_smb3_cmd_done(le32_to_cpu(shdr->Id.SyncId.TreeId), @@ -2453,17 +2453,21 @@ map_smb2_to_linux_error(char *buf, bool log_err) (smb2err !=3D STATUS_END_OF_FILE)) || (cifsFYI & CIFS_RC); =20 - for (i =3D 0; i < sizeof(smb2_error_map_table) / - sizeof(struct status_to_posix_error); i++) { - if (smb2_error_map_table[i].smb2_status =3D=3D smb2err) { - if (log_err) - pr_notice("Status code returned 0x%08x %s\n", smb2err, - smb2_error_map_table[i].status_string); - rc =3D smb2_error_map_table[i].posix_error; - break; - } - } + key =3D (struct status_to_posix_error) { + .smb2_status =3D smb2err, + }; + err_map =3D bsearch(&key, smb2_error_map_table, err_map_num, + sizeof(struct status_to_posix_error), + cmp_smb2_status); + if (!err_map) + goto out; + + rc =3D err_map->posix_error; + if (log_err) + pr_notice("Status code returned 0x%08x %s\n", smb2err, + err_map->status_string); =20 +out: /* on error mapping not found - return EIO */ =20 cifs_dbg(FYI, "Mapping SMB2 status code 0x%08x to POSIX err %d\n", --=20 2.43.0 From nobody Fri Dec 19 19:23:34 2025 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4585E2F5A2A for ; Thu, 4 Dec 2025 04:59:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.186 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824400; cv=none; b=h+7RMYevWE2TjiYVVbGne2ZPwVCPYGehmVUubFK8XRKLDe36TfjRfiRYzJ+rdI4hfi3ELQ4XiOzDvuRF2fxO31HOP/pw+CXQaBwYGGB8GShoWATp1RbgrWZ5nlgoSlWDA+AHt446oJmzecBt8vG6JNCl5ywnh2px0dFCnBdPQ4w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824400; c=relaxed/simple; bh=a4niZBR3NqXVCxmEEdM4gbzE6T5TiwG9k+62K89uHYg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FitW3qaL5k/G96DanwpdPFwUDdH0x3fnF3+X3HSHRKgeLsKuLBm3QI4rQr1e3+B61zZCAZULo+YvuwVAWO27vFfT2Nw3kwMCika1OOOnz8koDaZmZ3rU3OuUw+AggYguXtiGnYkaHdqzilaqFPOlz6FtmlYUNFMya2DupOR/cgA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=FtaA7YEk; arc=none smtp.client-ip=95.215.58.186 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="FtaA7YEk" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1764824396; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VZIEA7m/p4sRFl+N9lWSpTrYU+e/rIgvWYLIQkCdILQ=; b=FtaA7YEkKF87twDIMtuME8LH5kDfR7wVC28M2r6XZU+zCOPPWu3ycAWK+H5OZWblbtI6O3 vev74UuuW5TxpZR81IRM6Tj3Euy3cwIE+dYEnYkfZbmjptSXb0uW0/xcFPvQJ/wdf9hl73 CzQNnjV3wNudUPT1L/g5m54ird4Fchw= From: chenxiaosong.chenxiaosong@linux.dev To: sfrench@samba.org, smfrench@gmail.com, linkinjeon@kernel.org, linkinjeon@samba.org Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, chenxiaosong@chenxiaosong.com, ChenXiaoSong Subject: [PATCH 06/10] smb/client: introduce smb2_get_err_map() Date: Thu, 4 Dec 2025 12:58:14 +0800 Message-ID: <20251204045818.2590727-7-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: ChenXiaoSong Preparation for KUnit tests. Signed-off-by: ChenXiaoSong --- fs/smb/client/smb2maperror.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/fs/smb/client/smb2maperror.c b/fs/smb/client/smb2maperror.c index df8db12ff7a9..f5d999f3b569 100644 --- a/fs/smb/client/smb2maperror.c +++ b/fs/smb/client/smb2maperror.c @@ -2433,13 +2433,27 @@ static int cmp_smb2_status(const void *_a, const vo= id *_b) return 0; } =20 +static struct status_to_posix_error * +smb2_get_err_map(__le32 smb2_status) +{ + struct status_to_posix_error *err_map, key; + + key =3D (struct status_to_posix_error) { + .smb2_status =3D smb2_status, + }; + err_map =3D bsearch(&key, smb2_error_map_table, err_map_num, + sizeof(struct status_to_posix_error), + cmp_smb2_status); + return err_map; +} + int map_smb2_to_linux_error(char *buf, bool log_err) { struct smb2_hdr *shdr =3D (struct smb2_hdr *)buf; int rc =3D -EIO; __le32 smb2err =3D shdr->Status; - struct status_to_posix_error *err_map, key; + struct status_to_posix_error *err_map; =20 if (smb2err =3D=3D 0) { trace_smb3_cmd_done(le32_to_cpu(shdr->Id.SyncId.TreeId), @@ -2453,12 +2467,7 @@ map_smb2_to_linux_error(char *buf, bool log_err) (smb2err !=3D STATUS_END_OF_FILE)) || (cifsFYI & CIFS_RC); =20 - key =3D (struct status_to_posix_error) { - .smb2_status =3D smb2err, - }; - err_map =3D bsearch(&key, smb2_error_map_table, err_map_num, - sizeof(struct status_to_posix_error), - cmp_smb2_status); + err_map =3D smb2_get_err_map(smb2err); if (!err_map) goto out; =20 --=20 2.43.0 From nobody Fri Dec 19 19:23:34 2025 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C25D3009F5 for ; Thu, 4 Dec 2025 04:59:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824403; cv=none; b=ss2Olvc3QgXMQJoaDlE77mvi5fVyPHIkYEBqYJ6hhFIMQLlGZIvBlTi1gqtVWyLP8Q54lK028qe+TONB5D1q6UV6R/jnl88L9FtGSUApaLJ7kfpHtKW0/Dbk74EUaUg/ftWAP79nNyVTGlBZcbK/lBnnOnxJKMsBejgLKenBT+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824403; c=relaxed/simple; bh=4+703upttbLBXrs3HCR/osHe0MWHMFb29STOXf/zQlw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iMYwaLR5YVKzRtYpvuRI8G4zxgOqq5WShyGQH6guxxiNHMLQr64HgHMMHDpvkFYHzEzL6fK6uf5kIFUwbV57P55I3Lg3EZszX9Y7wZdt7IrtDjl40+V8RcL6KFMC61LzisPSVO86O4NEUM0QUTOXF84kRWrDWGf3b2RXNs/vSuM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=QQ8J43FU; arc=none smtp.client-ip=95.215.58.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="QQ8J43FU" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1764824398; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/IbInYvILPYcoixt21Z2SWUU0ENgDuclZexoYjmKwdA=; b=QQ8J43FU7vXA9gornvj10rsWDLILzH2n09kzLp482izhx8quqiH4BcUWNRT3lkpgB8VFXZ CEo5Rg8eAQQne0uP90loN+LpECh+cymdFtzyMrdr4sjTi/3iGmsQpFV5uH8dtFS3mtH6kG KNLgBsLjI81NE+92vbRIdnpWI+bUQUw= From: chenxiaosong.chenxiaosong@linux.dev To: sfrench@samba.org, smfrench@gmail.com, linkinjeon@kernel.org, linkinjeon@samba.org Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, chenxiaosong@chenxiaosong.com, ChenXiaoSong Subject: [PATCH 07/10] smb/client: introduce smb2maperror KUnit tests Date: Thu, 4 Dec 2025 12:58:15 +0800 Message-ID: <20251204045818.2590727-8-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: ChenXiaoSong The KUnit tests are executed when cifs.ko is loaded. The maperror_test_check_sort() checks whether the array is properly sorted. The maperror_test_get_err_map() checks whether the expected element can be correctly searched for in the smb2_error_map_table array. Signed-off-by: ChenXiaoSong --- fs/smb/Kconfig | 13 ++++++ fs/smb/client/smb2maperror.c | 77 ++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/fs/smb/Kconfig b/fs/smb/Kconfig index ef425789fa6a..95b29d089e60 100644 --- a/fs/smb/Kconfig +++ b/fs/smb/Kconfig @@ -9,3 +9,16 @@ config SMBFS tristate default y if CIFS=3Dy || SMB_SERVER=3Dy default m if CIFS=3Dm || SMB_SERVER=3Dm + +config SMB_KUNIT_TEST + bool "SMB KUnit tests" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + Only useful for kernel devs running KUnit test harness and are not + for inclusion into a production build. + + For more information on KUnit and unit tests in general please refer + to the KUnit documentation in Documentation/dev-tools/kunit/. + + If unsure, say N. diff --git a/fs/smb/client/smb2maperror.c b/fs/smb/client/smb2maperror.c index f5d999f3b569..95e4a41ecc5a 100644 --- a/fs/smb/client/smb2maperror.c +++ b/fs/smb/client/smb2maperror.c @@ -2497,3 +2497,80 @@ void smb2_init_maperror(void) sizeof(struct status_to_posix_error), cmp_smb2_status, NULL); } + +#if IS_ENABLED(CONFIG_SMB_KUNIT_TEST) +#include + +static void maperror_test_check_sort(struct kunit *test) +{ + bool is_sorted =3D true; + unsigned int i; + + for (i =3D 1; i < err_map_num; i++) { + if (smb2_error_map_table[i].smb2_status >=3D + smb2_error_map_table[i - 1].smb2_status) + continue; + + pr_err("smb2_error_map_table array order is incorrect\n"); + is_sorted =3D false; + break; + } + + KUNIT_EXPECT_EQ(test, true, is_sorted); +} + +static void +get_and_cmp_err_map(struct kunit *test, struct status_to_posix_error *expe= ct) +{ + struct status_to_posix_error *result; + + result =3D smb2_get_err_map(expect->smb2_status); + KUNIT_EXPECT_PTR_NE(test, NULL, result); + KUNIT_EXPECT_EQ(test, expect->posix_error, result->posix_error); + KUNIT_EXPECT_STREQ(test, expect->status_string, result->status_string); +} + +static void maperror_test_get_err_map(struct kunit *test) +{ + struct status_to_posix_error expect; + + /* first element */ + expect =3D smb2_error_map_table[0]; + get_and_cmp_err_map(test, &expect); + + /* last element */ + expect =3D smb2_error_map_table[err_map_num - 1]; + get_and_cmp_err_map(test, &expect); + + expect =3D (struct status_to_posix_error) { + .smb2_status =3D STATUS_SERIAL_COUNTER_TIMEOUT, + .posix_error =3D -ETIMEDOUT, + .status_string =3D "STATUS_SERIAL_COUNTER_TIMEOUT", + }; + get_and_cmp_err_map(test, &expect); + + expect =3D (struct status_to_posix_error) { + .smb2_status =3D STATUS_IO_REPARSE_TAG_NOT_HANDLED, + .posix_error =3D -EOPNOTSUPP, + .status_string =3D "STATUS_REPARSE_NOT_HANDLED", + }; + get_and_cmp_err_map(test, &expect); +} + +/* + * Before running these test cases, the smb2_init_maperror() + * function is called first. + */ +static struct kunit_case maperror_test_cases[] =3D { + KUNIT_CASE(maperror_test_check_sort), + KUNIT_CASE(maperror_test_get_err_map), + {} +}; + +static struct kunit_suite maperror_suite =3D { + .name =3D "smb2-maperror", + .test_cases =3D maperror_test_cases, +}; + +kunit_test_suite(maperror_suite); +#endif /* CONFIG_SMB_KUNIT_TEST */ --=20 2.43.0 From nobody Fri Dec 19 19:23:34 2025 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E7CE2F83A5 for ; Thu, 4 Dec 2025 05:00:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824404; cv=none; b=pRzdXPt6rK/TiFgGZOTERGAdrE69kLVreq4KLZx/5GepoQG+D5V7aIniQHcEiggp7nAgzZH9ksdUXjZkmrihx45f4/Yv2iYLjRCm2RQjJ1k5GPRhJ5yQu7zzvUuQSUkRuoLnYBwmi4oRFqtAHcS6S6bfzZxeTWIRYhUkahu+ueE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824404; c=relaxed/simple; bh=kIB9E0S4MLXrqcQMCK41YTJVE8Ih+JwGuHTZBMonWCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rcGpZZ6KD7JsOHHfENKbFiK5p2T7uRvL36cVHnRT8h+x9rgk3ZfIu6Bc1/nUpsjdxigzcT14j1WHIeckjocBGcRqkq7trME5hli/jOFkAucbdx5x9HWR1emIQ+WXPAMCgB8zaD2hP3E951wGOsSi/E3rRzebx6PWp3KId9Hb4cg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=e+Pcjfi5; arc=none smtp.client-ip=95.215.58.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="e+Pcjfi5" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1764824400; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e9cc8Nr2lduaK+xF7eBStk2AhlwQzHHel2LcG+oQ/q0=; b=e+Pcjfi5V7Id4QXL7bPTpctQWL64AXxqG1CnqyjJJ8MnqP5w5eG2ZMhCjszMutwIBbgjG6 /jAFko6VBYb0EnZVhCMEBCHlDGoB33AYl+18wFwxp6+DTpnTrkfph2gzWdiDK3HglXXsG6 ifu9QOnTSn7tabtDWm7AbbUfAvQQrRU= From: chenxiaosong.chenxiaosong@linux.dev To: sfrench@samba.org, smfrench@gmail.com, linkinjeon@kernel.org, linkinjeon@samba.org Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, chenxiaosong@chenxiaosong.com, ChenXiaoSong Subject: [PATCH 08/10] smb/server: rename include guard in smb_common.h Date: Thu, 4 Dec 2025 12:58:16 +0800 Message-ID: <20251204045818.2590727-9-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: ChenXiaoSong To avoid conflicts with the include guard in the soon-to-be-created common/common.h header. Signed-off-by: ChenXiaoSong --- fs/smb/server/smb_common.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/smb/server/smb_common.h b/fs/smb/server/smb_common.h index ae4dac515b6c..8cea25c01d81 100644 --- a/fs/smb/server/smb_common.h +++ b/fs/smb/server/smb_common.h @@ -3,8 +3,8 @@ * Copyright (C) 2018 Samsung Electronics Co., Ltd. */ =20 -#ifndef __SMB_COMMON_H__ -#define __SMB_COMMON_H__ +#ifndef __SMB_SERVER_COMMON_H__ +#define __SMB_SERVER_COMMON_H__ =20 #include =20 @@ -196,4 +196,4 @@ unsigned int ksmbd_server_side_copy_max_chunk_size(void= ); unsigned int ksmbd_server_side_copy_max_total_size(void); bool is_asterisk(char *p); __le32 smb_map_generic_desired_access(__le32 daccess); -#endif /* __SMB_COMMON_H__ */ +#endif /* __SMB_SERVER_COMMON_H__ */ --=20 2.43.0 From nobody Fri Dec 19 19:23:34 2025 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5A92304985 for ; Thu, 4 Dec 2025 05:00:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824409; cv=none; b=fuImuly4PC8jMLMXwnYAKrGSKJXqCalGR/jCHx4Kf6sp0R86ITA3UIVFO9PUSs4JFXicxYwIdLTigAxNrlRLGgRXC8TyYTu/Vmu8K8DLRxIUalAraS2cSLTKcOlHHxCwc4r2xba20l8n8M035z/ccIUEiDnCdw/Y5opSlh7ypwo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824409; c=relaxed/simple; bh=FntEXDEilc4dKtFA300LaBptfch7n2a6/jxLKrcwXjE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=USRLP+H+CBBzqEzOJ/Bk1MojrYfp3eEeQ7CGL1tDYFM2+/LRd2iCPvLfzlsAnf9hLxuVbQKj4YVILHGTffhOQ8LqpWDCMWlog+GUgF4FX1DKBaMMlqK2EDL0U3TdVjH9Q3b9oT1Tpu3T2t+J83QJcJyMbKATUQM4tvPcCY0HYq4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=LYVRtQP1; arc=none smtp.client-ip=95.215.58.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="LYVRtQP1" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1764824402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LtxePjWpMJc4YcyMV/WO2g/5lhEnkqKOVHXZHFiGmM0=; b=LYVRtQP1FbhwjBgO0Y3aOh/DPbq/okZoK+pcwYWnA1wapWrG7bjka+rzr2YlS+nPWEV2Hi BkfZcOdWJFibCImOKdiTbpAeXfvUUcY+hGa3vKAzai0yJO1gNGmUVrKmqX/hoOqAQYYcdj xQmjzC20z91K4TYvVrfwzuk+Ins5WFU= From: chenxiaosong.chenxiaosong@linux.dev To: sfrench@samba.org, smfrench@gmail.com, linkinjeon@kernel.org, linkinjeon@samba.org Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, chenxiaosong@chenxiaosong.com, ChenXiaoSong Subject: [PATCH 09/10] smb: create common/common.h and common/common.c Date: Thu, 4 Dec 2025 12:58:17 +0800 Message-ID: <20251204045818.2590727-10-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: ChenXiaoSong Preparation for moving client/smb2maperror.c to common/. We can put cifs_md4 and smb2maperror into a single smb_common.ko, instead of creating two separate .ko (cifs_md4.ko and smb2maperror.ko). - rename md4.h -> common.h, and update include guard - create common.c, and move module info from cifs_md4.c into common.c Signed-off-by: ChenXiaoSong --- fs/smb/client/smbencrypt.c | 2 +- fs/smb/common/Makefile | 3 ++- fs/smb/common/cifs_md4.c | 5 +---- fs/smb/common/common.c | 28 ++++++++++++++++++++++++++++ fs/smb/common/{md4.h =3D> common.h} | 14 +++++++------- 5 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 fs/smb/common/common.c rename fs/smb/common/{md4.h =3D> common.h} (86%) diff --git a/fs/smb/client/smbencrypt.c b/fs/smb/client/smbencrypt.c index 1d1ee9f18f37..abbedcdf7613 100644 --- a/fs/smb/client/smbencrypt.c +++ b/fs/smb/client/smbencrypt.c @@ -24,7 +24,7 @@ #include "cifsglob.h" #include "cifs_debug.h" #include "cifsproto.h" -#include "../common/md4.h" +#include "../common/common.h" =20 /* following came from the other byteorder.h to avoid include conflicts */ #define CVAL(buf,pos) (((unsigned char *)(buf))[pos]) diff --git a/fs/smb/common/Makefile b/fs/smb/common/Makefile index 9e0730a385fb..4f1dc5123e99 100644 --- a/fs/smb/common/Makefile +++ b/fs/smb/common/Makefile @@ -3,4 +3,5 @@ # Makefile for Linux filesystem routines that are shared by client and ser= ver. # =20 -obj-$(CONFIG_SMBFS) +=3D cifs_md4.o +obj-$(CONFIG_SMBFS) +=3D smb_common.o +smb_common-objs :=3D common.o cifs_md4.o diff --git a/fs/smb/common/cifs_md4.c b/fs/smb/common/cifs_md4.c index 7ee7f4dad90c..c619c0daf217 100644 --- a/fs/smb/common/cifs_md4.c +++ b/fs/smb/common/cifs_md4.c @@ -22,10 +22,7 @@ #include #include #include -#include "md4.h" - -MODULE_DESCRIPTION("MD4 Message Digest Algorithm (RFC1320)"); -MODULE_LICENSE("GPL"); +#include "common.h" =20 static inline u32 lshift(u32 x, unsigned int s) { diff --git a/fs/smb/common/common.c b/fs/smb/common/common.c new file mode 100644 index 000000000000..4142e05039c0 --- /dev/null +++ b/fs/smb/common/common.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) International Business Machines Corp., 2009 + * 2018 Samsung Electronics Co., Ltd. + * Author(s): Steve French + * Namjae Jeon + */ + +#include +#include "common.h" + +static int __init smb_common_init(void) +{ + int rc =3D 0; + + return rc; +} + +static void __exit smb_common_exit(void) +{ +} + +MODULE_AUTHOR("Steve French "); +MODULE_AUTHOR("Namjae Jeon "); +MODULE_DESCRIPTION("Linux kernel SMB common"); +MODULE_LICENSE("GPL"); +module_init(smb_common_init) +module_exit(smb_common_exit) diff --git a/fs/smb/common/md4.h b/fs/smb/common/common.h similarity index 86% rename from fs/smb/common/md4.h rename to fs/smb/common/common.h index 5337becc699a..07ee24ecccb8 100644 --- a/fs/smb/common/md4.h +++ b/fs/smb/common/common.h @@ -1,13 +1,14 @@ /* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Common values for ARC4 Cipher Algorithm - */ =20 -#ifndef _CIFS_MD4_H -#define _CIFS_MD4_H +#ifndef __SMB_COMMON_H__ +#define __SMB_COMMON_H__ =20 #include =20 +/* + * Common values for ARC4 Cipher Algorithm + */ + #define MD4_DIGEST_SIZE 16 #define MD4_HMAC_BLOCK_SIZE 64 #define MD4_BLOCK_WORDS 16 @@ -19,9 +20,8 @@ struct md4_ctx { u64 byte_count; }; =20 - int cifs_md4_init(struct md4_ctx *mctx); int cifs_md4_update(struct md4_ctx *mctx, const u8 *data, unsigned int len= ); int cifs_md4_final(struct md4_ctx *mctx, u8 *out); =20 -#endif /* _CIFS_MD4_H */ +#endif /* __SMB_COMMON_H__ */ --=20 2.43.0 From nobody Fri Dec 19 19:23:34 2025 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1058A1F7098 for ; Thu, 4 Dec 2025 05:00:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824410; cv=none; b=SlqLyKvAhRMFR1sEWZxe8+DmraqxcxMWZVqZNbjJOpVTSY1IFnWT5vDzILNW05ClUcOVRuOwfh4EEKjab7oaVtF+6wb/44WClS3Y4CB7zzhkK48ipBF4RgbaO681zWFfBxRvZ9i5vxvn6jSrho4ktpGfwX7zPggEXnUlxO5GKmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824410; c=relaxed/simple; bh=irGUp7ucdaAS65wOUUfmsAJ/emdWlpyAPbRDWpJm5wA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ABBQhDl7sDOzEf4Usc5KJ3em2J+hxJB/f/fXA98fviNJMDNv66u2nziiDvRrOkTWLdMJ3LXK3scMZzswnA5Q5LimQiCtkmOt8SwEQvNQn8b2sC9SH5RZImJwzCL2qiwsVddbKZ+StR0TSg1q6UrdFMiWMDqrhSdSD6aVDQfXIdo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Wn2deWCN; arc=none smtp.client-ip=95.215.58.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Wn2deWCN" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1764824406; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oQWSTfTqfi36TPw1mkYlE01yHaaPSEMaXv1EtrdIBH8=; b=Wn2deWCNwpH0/hdFxIEwP5iVoDnMZWb0gMnk00UW7l0snn5uDpUerTuDFbAQ38I3A9Ci9g q5mMODgGuZ80h1BsS8CZggk39ELyUHq/6auvm9ExAyZ/Uwc7Lvp7TSFgKSxu56j+HGrdcV A47CITO/99a0jBmrFTIhtgIf6BbDDY0= From: chenxiaosong.chenxiaosong@linux.dev To: sfrench@samba.org, smfrench@gmail.com, linkinjeon@kernel.org, linkinjeon@samba.org Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, chenxiaosong@chenxiaosong.com, ChenXiaoSong Subject: [PATCH 10/10] smb: move client/smb2maperror.c to common/ Date: Thu, 4 Dec 2025 12:58:18 +0800 Message-ID: <20251204045818.2590727-11-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251204045818.2590727-1-chenxiaosong.chenxiaosong@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: ChenXiaoSong The maperror can also be used by ksmbd, so move it to common/. - client/smb2maperror.c -> common/smb2maperror.c - Move map_smb2_to_linux_error() into client/smb2misc.c - smb2_init_maperror() is called from smb_common_init() - Move struct status_to_posix_error into common/common.h - Export symbol smb2_get_err_map() - The KUnit tests are executed when smb_common.ko is loaded Signed-off-by: ChenXiaoSong --- fs/smb/client/Makefile | 2 +- fs/smb/client/cifsfs.c | 2 - fs/smb/client/smb2misc.c | 44 ++++++++++++++++ fs/smb/client/smb2proto.h | 1 - fs/smb/common/Makefile | 2 +- fs/smb/common/common.c | 2 + fs/smb/common/common.h | 13 +++++ fs/smb/{client =3D> common}/smb2maperror.c | 64 +++--------------------- 8 files changed, 67 insertions(+), 63 deletions(-) rename fs/smb/{client =3D> common}/smb2maperror.c (98%) diff --git a/fs/smb/client/Makefile b/fs/smb/client/Makefile index 4c97b31a25c2..e84df2af8be6 100644 --- a/fs/smb/client/Makefile +++ b/fs/smb/client/Makefile @@ -9,7 +9,7 @@ cifs-y :=3D trace.o cifsfs.o cifs_debug.o connect.o dir.o f= ile.o \ inode.o link.o misc.o netmisc.o smbencrypt.o transport.o \ cached_dir.o cifs_unicode.o nterr.o cifsencrypt.o \ readdir.o ioctl.o sess.o export.o unc.o winucase.o \ - smb2ops.o smb2maperror.o smb2transport.o \ + smb2ops.o smb2transport.o \ smb2misc.o smb2pdu.o smb2inode.o smb2file.o cifsacl.o fs_context.o \ dns_resolve.o cifs_spnego_negtokeninit.asn1.o asn1.o \ namespace.o reparse.o diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c index 77d14b3dd650..6eccb9ed9daa 100644 --- a/fs/smb/client/cifsfs.c +++ b/fs/smb/client/cifsfs.c @@ -49,7 +49,6 @@ #endif #include "fs_context.h" #include "cached_dir.h" -#include "smb2proto.h" =20 /* * DOS dates from 1980/1/1 through 2107/12/31 @@ -1909,7 +1908,6 @@ static int __init init_cifs(void) { int rc =3D 0; - smb2_init_maperror(); cifs_proc_init(); INIT_LIST_HEAD(&cifs_tcp_ses_list); /* diff --git a/fs/smb/client/smb2misc.c b/fs/smb/client/smb2misc.c index 96bfe4c63ccf..2cdcc9e6f47f 100644 --- a/fs/smb/client/smb2misc.c +++ b/fs/smb/client/smb2misc.c @@ -18,6 +18,7 @@ #include "smb2glob.h" #include "nterr.h" #include "cached_dir.h" +#include "../common/common.h" =20 static int check_smb2_hdr(struct smb2_hdr *shdr, __u64 mid) @@ -927,3 +928,46 @@ smb311_update_preauth_hash(struct cifs_ses *ses, struc= t TCP_Server_Info *server, sha512_update(&sha_ctx, iov[i].iov_base, iov[i].iov_len); sha512_final(&sha_ctx, ses->preauth_sha_hash); } + +int +map_smb2_to_linux_error(char *buf, bool log_err) +{ + struct smb2_hdr *shdr =3D (struct smb2_hdr *)buf; + int rc =3D -EIO; + __le32 smb2err =3D shdr->Status; + struct status_to_posix_error *err_map; + + if (smb2err =3D=3D 0) { + trace_smb3_cmd_done(le32_to_cpu(shdr->Id.SyncId.TreeId), + le64_to_cpu(shdr->SessionId), + le16_to_cpu(shdr->Command), + le64_to_cpu(shdr->MessageId)); + return 0; + } + + log_err =3D (log_err && (smb2err !=3D STATUS_MORE_PROCESSING_REQUIRED) && + (smb2err !=3D STATUS_END_OF_FILE)) || + (cifsFYI & CIFS_RC); + + err_map =3D smb2_get_err_map(smb2err); + if (!err_map) + goto out; + + rc =3D err_map->posix_error; + if (log_err) + pr_notice("Status code returned 0x%08x %s\n", smb2err, + err_map->status_string); + +out: + /* on error mapping not found - return EIO */ + + cifs_dbg(FYI, "Mapping SMB2 status code 0x%08x to POSIX err %d\n", + __le32_to_cpu(smb2err), rc); + + trace_smb3_cmd_err(le32_to_cpu(shdr->Id.SyncId.TreeId), + le64_to_cpu(shdr->SessionId), + le16_to_cpu(shdr->Command), + le64_to_cpu(shdr->MessageId), + le32_to_cpu(smb2err), rc); + return rc; +} diff --git a/fs/smb/client/smb2proto.h b/fs/smb/client/smb2proto.h index c988f6b37a1b..5241daaae543 100644 --- a/fs/smb/client/smb2proto.h +++ b/fs/smb/client/smb2proto.h @@ -21,7 +21,6 @@ struct smb_rqst; ***************************************************************** */ extern int map_smb2_to_linux_error(char *buf, bool log_err); -extern void smb2_init_maperror(void); extern int smb2_check_message(char *buf, unsigned int length, struct TCP_Server_Info *server); extern unsigned int smb2_calc_size(void *buf); diff --git a/fs/smb/common/Makefile b/fs/smb/common/Makefile index 4f1dc5123e99..3bfd510a5204 100644 --- a/fs/smb/common/Makefile +++ b/fs/smb/common/Makefile @@ -4,4 +4,4 @@ # =20 obj-$(CONFIG_SMBFS) +=3D smb_common.o -smb_common-objs :=3D common.o cifs_md4.o +smb_common-objs :=3D common.o cifs_md4.o smb2maperror.o diff --git a/fs/smb/common/common.c b/fs/smb/common/common.c index 4142e05039c0..eb3703b3cc22 100644 --- a/fs/smb/common/common.c +++ b/fs/smb/common/common.c @@ -13,6 +13,8 @@ static int __init smb_common_init(void) { int rc =3D 0; =20 + smb2_init_maperror(); + return rc; } =20 diff --git a/fs/smb/common/common.h b/fs/smb/common/common.h index 07ee24ecccb8..71933f8497b8 100644 --- a/fs/smb/common/common.h +++ b/fs/smb/common/common.h @@ -24,4 +24,17 @@ int cifs_md4_init(struct md4_ctx *mctx); int cifs_md4_update(struct md4_ctx *mctx, const u8 *data, unsigned int len= ); int cifs_md4_final(struct md4_ctx *mctx, u8 *out); =20 +/* + * Definitions for smb2 map error + */ + +struct status_to_posix_error { + __le32 smb2_status; + int posix_error; + char *status_string; +}; + +struct status_to_posix_error *smb2_get_err_map(__le32 smb2_status); +void smb2_init_maperror(void); + #endif /* __SMB_COMMON_H__ */ diff --git a/fs/smb/client/smb2maperror.c b/fs/smb/common/smb2maperror.c similarity index 98% rename from fs/smb/client/smb2maperror.c rename to fs/smb/common/smb2maperror.c index 95e4a41ecc5a..c4109fc6320f 100644 --- a/fs/smb/client/smb2maperror.c +++ b/fs/smb/common/smb2maperror.c @@ -7,21 +7,11 @@ * Author(s): Steve French (sfrench@us.ibm.com) * */ -#include +#include #include -#include "cifsglob.h" -#include "cifs_debug.h" -#include "smb2pdu.h" -#include "smb2proto.h" -#include "../common/smb2status.h" -#include "smb2glob.h" -#include "trace.h" - -struct status_to_posix_error { - __le32 smb2_status; - int posix_error; - char *status_string; -}; +#include +#include "common.h" +#include "smb2status.h" =20 static struct status_to_posix_error smb2_error_map_table[] =3D { {STATUS_WAIT_1, -EIO, "STATUS_WAIT_1"}, @@ -2433,7 +2423,7 @@ static int cmp_smb2_status(const void *_a, const void= *_b) return 0; } =20 -static struct status_to_posix_error * +struct status_to_posix_error * smb2_get_err_map(__le32 smb2_status) { struct status_to_posix_error *err_map, key; @@ -2446,49 +2436,7 @@ smb2_get_err_map(__le32 smb2_status) cmp_smb2_status); return err_map; } - -int -map_smb2_to_linux_error(char *buf, bool log_err) -{ - struct smb2_hdr *shdr =3D (struct smb2_hdr *)buf; - int rc =3D -EIO; - __le32 smb2err =3D shdr->Status; - struct status_to_posix_error *err_map; - - if (smb2err =3D=3D 0) { - trace_smb3_cmd_done(le32_to_cpu(shdr->Id.SyncId.TreeId), - le64_to_cpu(shdr->SessionId), - le16_to_cpu(shdr->Command), - le64_to_cpu(shdr->MessageId)); - return 0; - } - - log_err =3D (log_err && (smb2err !=3D STATUS_MORE_PROCESSING_REQUIRED) && - (smb2err !=3D STATUS_END_OF_FILE)) || - (cifsFYI & CIFS_RC); - - err_map =3D smb2_get_err_map(smb2err); - if (!err_map) - goto out; - - rc =3D err_map->posix_error; - if (log_err) - pr_notice("Status code returned 0x%08x %s\n", smb2err, - err_map->status_string); - -out: - /* on error mapping not found - return EIO */ - - cifs_dbg(FYI, "Mapping SMB2 status code 0x%08x to POSIX err %d\n", - __le32_to_cpu(smb2err), rc); - - trace_smb3_cmd_err(le32_to_cpu(shdr->Id.SyncId.TreeId), - le64_to_cpu(shdr->SessionId), - le16_to_cpu(shdr->Command), - le64_to_cpu(shdr->MessageId), - le32_to_cpu(smb2err), rc); - return rc; -} +EXPORT_SYMBOL_GPL(smb2_get_err_map); =20 void smb2_init_maperror(void) { --=20 2.43.0