From nobody Fri Dec 19 16:17:12 2025 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (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 37CF71624D5 for ; Fri, 5 Dec 2025 04:31:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909064; cv=none; b=d08FkOqic+nyeBfUkNi8yJbSnT23CE7wDjAGa/QeAcBbHCxozdRUrBUn3udvKkWSrZwbJJlOXr+WYgiHvPEGuSYnJWDW9B9BHnYdGnki0Ycrfh91QlqXqWuO5uLbe3stJFAHnaPYKXMqQCzW5SIAaCkF/8wXvrgoCdl0dBdKOCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909064; c=relaxed/simple; bh=zUYUihyU+5bVpkT+6WKXmtpr0BGZrQLsvYStT4Koz0c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z34lbWhuzmtk951zs2D/YJ6e6kkcrh0epaqmiDZy/kdydVCMSLMObrkkgIzAitHNDxJeRSulVSfVXQr3m1Jwe2O6RivfMpBIyFvSPah9uSAaR5z3iDpbDU1xVy5N8U5/48y4/DvtdI4np0Ky+sn4RBrAbi1gMx5c4bUs1SEdgyc= 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=NYukjVk3; arc=none smtp.client-ip=91.218.175.183 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="NYukjVk3" 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=1764909060; 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=VOu/pciDgcF7ZyY8CZ3QBp/GQHrh32EkE7MVswuQoHU=; b=NYukjVk3OBPq7PhpCJ5ut56Zgy21bbhYeeTjhaOyNRz9cSoItFG9hJxqAijd0DP8FGr1fq GXtVTQMWm3sHqm7WMkzSVYoUWJz6UEX85uCE8ORPUO+MnQFTIJnLyZGKx/kvbr4DOJtE/1 W7/zB5zK8GHSY6Eqaj67cb7+A7D3p6Q= 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 v2 1/9] smb/client: reduce loop count in map_smb2_to_linux_error() by half Date: Fri, 5 Dec 2025 12:29:49 +0800 Message-ID: <20251205042958.2658496-2-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251205042958.2658496-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251205042958.2658496-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 1743 elements. When searching for the last element and calling smb2_print_status(), 3486 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 16:17:12 2025 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.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 0D2102DC346 for ; Fri, 5 Dec 2025 04:31:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909066; cv=none; b=BrFSNLCUncNKKCwYSuf44XETjCVdTZaXwA2AxKNCSo1DcWubeDUtHNUxgxbBd0UO3hheaYPnSqf85JfNJA4fd2yWJIiKqvPYcamdFNxgSedCZZMvvKMGQ5Owxv+Ckub03JqV5FzCiQUCdpy3c31Wj/YJXztJyqTNHZIfLjHB9Ww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909066; c=relaxed/simple; bh=pkfzsbbhoS8dSc0sCXHcgR0baQMXz4nmCTpdqOcLZkM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L+WE29j5HYaWDWl27qHVZuQsVf07+gUifuY895rUpU/sg3eH1RFo4GWUWB2W6QzQmogc80zl28v6UKEcy3V666DNsizGt81KLXo0HeKUs9MY2pmhuD6XeIVjj4mqoZWlIIF8IDQe2tgPEcOVmWhb+ZNu/aOYXBgkaGHavJk2unQ= 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=v0taEtME; arc=none smtp.client-ip=91.218.175.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="v0taEtME" 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=1764909062; 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=v0taEtME+BG3vZlfk5gwqaGz+QU58nt3+WLD3tQ7g0XMAQLyprSQIYOUfwuypwxK95cwRt 7KOsjxj0asCwhv6ULR28PaR9eqEyZLpu4qLA8nQ6KSGy27n2QSraj0Qjk1PpTcKp3kcbpS h/NBxQAnMSM2uPg7/AQER2sxAYnJTjg= 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 v2 2/9] smb/client: remove unused elements from smb2_error_map_table array Date: Fri, 5 Dec 2025 12:29:50 +0800 Message-ID: <20251205042958.2658496-3-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251205042958.2658496-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251205042958.2658496-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 16:17:12 2025 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (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 555A62DAFB8 for ; Fri, 5 Dec 2025 04:31:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909069; cv=none; b=a1/4A/bN5RzFTLCDRxN1uvTz/tW/BCefsBK2VL2ZeQeg3hjt0f5A1L7vcYdky/A75GMWsBO8MrCzKxwU8sNB70x8jhXMOG2wSL4sNJV+Rh9AjIvnLmFgyEd7c1lLs2Gz2D+2cuWxv/34g9/XhS+h+xsRrzT/Ea/Uaer1NX/6LoI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909069; c=relaxed/simple; bh=4JJp2NWhr5BTXdht9jh/3UFu2aqUDb0sNi6TkyC1740=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uaG91lNdYwj0SB43pVCMNsr1gPX6aeM578W5toED6YM63SSuburlt9BBBBPmPD0UVmYt+3Kw13cIXYbp7OA8xVzCBowrnW9QXgi9K27OObDYssao424NnV1Ke21hTgOsAxllTCV0/yUf93goVbLTO1GyyyauhlClUKlTUSbE4Hw= 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=iZcwCUf8; arc=none smtp.client-ip=91.218.175.188 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="iZcwCUf8" 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=1764909065; 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=OpT0hLrQO7wTfJ3bQS8ehrjwnJyCu8VpuzDETsNFyMs=; b=iZcwCUf8AtmOzIHUBXtcU/mX43Ub76l8QBmY80WXOxMOTz76fd1m4vRRYhS45D0g0zzuEb feOE3mUzYaOmg/soa26MzK+hoR46zrfHMcNhTY78RKQUM0Q6wc1HldRHXcjW1pEjMn6xZh 5S3dwd5T99D2jbjj+WYttJgR5CSPdNk= 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 v2 3/9] smb: rename to STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP Date: Fri, 5 Dec 2025 12:29:51 +0800 Message-ID: <20251205042958.2658496-4-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251205042958.2658496-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251205042958.2658496-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 See MS-SMB2 3.3.5.4. To keep the name consistent with the documentation. Additionally, move STATUS_INVALID_LOCK_RANGE to correct position in order. Signed-off-by: ChenXiaoSong --- fs/smb/common/smb2status.h | 5 +++-- fs/smb/server/smb2pdu.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) 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 a4f6de350df8..b1323f1b100e 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 16:17:12 2025 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (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 368872DC346 for ; Fri, 5 Dec 2025 04:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909072; cv=none; b=fV8U9eEPJj/fDSAB4x4KT2NqyB5gZBMCBYUjqGKySDoJtkIwHAelQNH02wKnJs4O5ZFWmTKzEFPwzY2zpAs8kTJuxoSLcPqzeoDDikbvCBlE1I/3GZXMPSOdIPa/NmpzNdtz311IwEFK1nEayoI8f5zCZp72uh4Q8W/wJ9/sluQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909072; c=relaxed/simple; bh=6HJEMr5X59OEb8//cubWzNJerCMISoQtM0zHJvgTDYc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vGqZdEw1+PAE9yOmj4ByOeDqrd1ZnAcQkrvRbu/7trlWVrcsNpoqprSI29FNwQG/tTWb5DCMew1Nz7uwOpX04duNr8zV8udwF6pbFwibylSdThJQ6CjSZFkX7fsJ4YMIzv5sqv5aZSwdAD4Xb439EYws/iB10upHqx7paAShhK0= 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=tKbhg3X+; arc=none smtp.client-ip=91.218.175.172 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="tKbhg3X+" 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=1764909068; 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=k+idk5A+mq8aU5amT3grfojWt2+XsKPXn7rdBgtsvkw=; b=tKbhg3X+0aIg/R79yoLq+UvKVTRk72dxBCc6JBiCWRP7aU5TO2e8SHW9IAYgCHO/rDg43L gmU3dINUgIV+nXmGoJKf0JVJybQRHyp25POa/FGmyY/IvTMsNeQpZ+nasmcaTv3ZCtSS0t kmGJN1mBNcgtBzIGMpnpimeeeIp1G4g= 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 v2 4/9] smb/client: add two elements to smb2_error_map_table array Date: Fri, 5 Dec 2025 12:29:52 +0800 Message-ID: <20251205042958.2658496-5-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251205042958.2658496-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251205042958.2658496-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. Now all status codes from common/smb2status.h are included in the smb2_error_map_table array(except for the first two zero definitions). Signed-off-by: ChenXiaoSong --- fs/smb/client/smb2maperror.c | 3 +++ 1 file changed, 3 insertions(+) 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 --=20 2.43.0 From nobody Fri Dec 19 16:17:12 2025 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (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 BB781275AFB for ; Fri, 5 Dec 2025 04:31:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909074; cv=none; b=emCoVW877X1nDENnNzIQCmvyxi62T4Jey1PEThxI55jdSjqhaPbxpcMyVIuzSgMbQYEbak7Bxr/pxAqG/XvGUrhD0MJg7PDzoakqio/5N101g9gYbjVckzvXnhC6YvH1loz4ky6jl5gfyzkQ9pnd3bqbup0n9dRuV+Q5Uu/cPRQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909074; c=relaxed/simple; bh=IBYCJ0URnZmHAFg6rVEL8/OhHpGcyVNVskFuPS8njGA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dLqkwztrGJ5cmoXcOGRrDH111mXV5Z21KxrhwCKCSHmzuvLw79V5WMxIkjgur4D3Z/MO8U/QG9E500dsCAOY/m/VPJJlfp7Md4N36b2Hq4yX6KMQhiahczO9qOWmEv/HQ4gvADCZXyGUQeBbQ3CJ3Vm6ElSi5rHYGwRAKhmuePk= 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=r1FBaJ/K; arc=none smtp.client-ip=91.218.175.183 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="r1FBaJ/K" 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=1764909071; 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=r1FBaJ/K3fH6QQIiRtYikyS0/rxcNvgNKeTTxzSDvClyjvR0dA7aKYnA4BlrokZcfYgw/x 7St2SLOZ5V+ldnDtOAiDLUAOsyV/exoOG+qSyOqIUg6+Ida2ROWtUMQCPnh/XCn0Qdwn0s 6VULoeG4SbaJ/5XxQjoV8KflMxVA3K0= 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 v2 5/9] smb/client: sort smb2_error_map_table array Date: Fri, 5 Dec 2025 12:29:53 +0800 Message-ID: <20251205042958.2658496-6-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251205042958.2658496-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251205042958.2658496-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 16:17:12 2025 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.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 99449261B8C for ; Fri, 5 Dec 2025 04:31:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909078; cv=none; b=l9pZUP5L5OEZ5KgWfea+ckIeJQusr88GxKXazB2etkOVisd+EMgcl/zOodRRJMbT9YsezaSVinWaXhiCOiFf8PkxVl7iwzRnIJgtIheKliG3qyk6uo/WMor/lrqsJ2CAPXsbW9f/TIbDBG8f1606NqY37LwHJqknUdsTPNFmqkw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909078; c=relaxed/simple; bh=GpiP28Us9v7/dQoXwcAvnftubvrrsWxq7Q4tJTESinM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k9ExKqCCdBy/m0ned9RNFiulc75vxYF8ksusTxzoRJm4kKB67bjum7zQ89Ix90faupEETk14QDZd75+kvB8vyiDbgxv7n5hmleqNANPEOy180bcdnZqD+fLijlwMA3adejr89o/vPBc0Ro2RJ3YnrDw7WqWnloLfjlbM2JHMdTY= 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=OtMUz/MG; arc=none smtp.client-ip=91.218.175.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="OtMUz/MG" 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=1764909073; 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=OtMUz/MGyYlQnkPUOkGBkRzM6htb0FtQo8yS1cgiMzaS6PlNei8lR3PZRL5i1kRsEAmciM NiuBWvUNioZj4z3LoizYW2t8Xp94iVL55Aos3DeXXO3up+JZYZYdhPOfvzdviMisWEODDL /HqXeQCzRvGfpCd1iiSrpZPbYNvpPbI= 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 v2 6/9] smb/client: use bsearch() to find target status code Date: Fri, 5 Dec 2025 12:29:54 +0800 Message-ID: <20251205042958.2658496-7-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251205042958.2658496-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251205042958.2658496-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 16:17:12 2025 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (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 427541A9F90 for ; Fri, 5 Dec 2025 04:31:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909079; cv=none; b=lG+TQ+DedwvXX8cmk+5cNSh0GCjDTuRQ9mPJHHNdv1l/Lt+wvfIhiIjMGplvQBDQkgfMamUGmDcMEXr/eRpB+Ofhn9J+rtqn+J4tAaN4bSCa+6W1p9dUAZLbLGZev5978MEeHQcrUsFak60aGNteOv+/O9js9aReb3SK6/+X5EM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909079; c=relaxed/simple; bh=a4niZBR3NqXVCxmEEdM4gbzE6T5TiwG9k+62K89uHYg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lNv9K6/9izjc5Nxb/akdBp9EKnK6+PGsI3NtVXXj1BuDcqyQ/NAh8GrLOyz41rixJnAJyscxm3GlffyLZFw/Aso4bksdEdfea8jXCBVTAywyWmQ+Sz1dIp458DDXoroggQjkVDb5pW/fLwcJyHo6YtBX49ugu46Dv0yHgJWQchE= 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=n3bxJkUo; arc=none smtp.client-ip=91.218.175.188 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="n3bxJkUo" 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=1764909076; 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=n3bxJkUoDTJ1OZGwTkpi+u46rVifQsjbhcSKBbHaCiUppevfXkvxu0NT718MYRrl/Bdi16 6j2OcBLjEu43yugNUiZdtk1tuILr53vXxea4rn0E6aL4qnSXrx0MzozW1plGvuHEVStJsu GT0fe2Pj9LOWHWf/z174X3ymn6iPAYc= 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 v2 7/9] smb/client: introduce smb2_get_err_map() Date: Fri, 5 Dec 2025 12:29:55 +0800 Message-ID: <20251205042958.2658496-8-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251205042958.2658496-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251205042958.2658496-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 16:17:12 2025 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (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 AF5EB4D8CE for ; Fri, 5 Dec 2025 04:31:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909082; cv=none; b=fWaW5gZuaCrDez8il5xtReiVirVCMS9BosJzr7PpYOESxg0Ty8hhOPO7A+7b3HQ1DTRyL9OGrnm2t/D3XTxzDNNGqsewkJY0Qae2KM9Doy2F4apmQLkkb283ESCcER+daqqMI8/FVrouteOF7v42KKEuiFNopz4C5InNTc6v6M4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909082; c=relaxed/simple; bh=4+703upttbLBXrs3HCR/osHe0MWHMFb29STOXf/zQlw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PUnHRKSzVwI6oZs9CgJXf56R1+2UNg2S/bl1gpurA2xFx2uDHIdpbNKOJ2jRxv9QyF1x5+R5yqcl24+tu4eYWWbRYSHYm9NGFTLoZHiQgL1VBWqmt4uN5ncMDJr6trtvlO8nyxglQQg9Kqj+8Y2pI2TWXT4T7EkU5pmyhSTNBLY= 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=TKM9D1Ho; arc=none smtp.client-ip=91.218.175.172 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="TKM9D1Ho" 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=1764909079; 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=TKM9D1HoXxt9Y5NphY20zpbQ6r9CFJNwnoLhfjUAeUCi8hl4ZAA9TASk4eGqXSP7NM12cs +eugVup//dbEbol8cFusnZTGmBA8cBXs4xvBsC8sQgKJwB59Ug8RVMJ202IbF9Ax8zCIX1 HzEuhj0tDkjKhuQVexyh1xZJr0OFl4c= 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 v2 8/9] smb/client: introduce smb2maperror KUnit tests Date: Fri, 5 Dec 2025 12:29:56 +0800 Message-ID: <20251205042958.2658496-9-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251205042958.2658496-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251205042958.2658496-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 16:17:12 2025 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (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 A4E012D5924 for ; Fri, 5 Dec 2025 04:31:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909086; cv=none; b=JrGffzjqBm5WplpeEjVfqxhaFEeBmxnfS/KfeFmzRue+Him8esTRBbyzjo1G3/UxgSGtMvFsHxHA2yANqoBSZ7QKHV04SjPP95nn7vmPT8nt43/H/Jng+ovYlGV4KMGPBrck7nYPQTd+2LTSw2kSo6uQu+i2FtAD+xvVn+/Asw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764909086; c=relaxed/simple; bh=j3TQkQqNjc21JofRmx5Cs1kYMv81xgaBLuCylqL/OV8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RIuk7gch6T7En8ybXc+DfbuFabiZfosRFdMovreQIgAB4YpldQ8rnApO2cmLh7hX70dM0+VR6X4W02Lx6TcL/7qUgjRhJzxFtEdvyMJ9qIZCBDX7MguCbc7fT3D0jlkz12qevnpyElLbUpxEPvcdp0EUGiYryGlQI2OnMqv6fTs= 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=HC2GT+Cj; arc=none smtp.client-ip=91.218.175.180 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="HC2GT+Cj" 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=1764909081; 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=LhTKXZUsKs6yApgm9M0oyCa/GcapnLfnpclZk/b8UoI=; b=HC2GT+Cj4J9Tf8xykcaT1MJ1tIUg2CqtZzCnlSXIDriRLFIaqcf0JXT6VdCla2lgYoAjHu /iy413jBIRSMFUuL9X+SwUflZY0qgYeWqPRHWaSdSiBnHiJDSY4iUxIeGy74E64qIUDDWE 4zFseiUPw8JxCrEGfwY7sxvWf01Uvvs= 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 v2 9/9] smb/server: rename include guard in smb_common.h Date: Fri, 5 Dec 2025 12:29:57 +0800 Message-ID: <20251205042958.2658496-10-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251205042958.2658496-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251205042958.2658496-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 Make the include guard more descriptive to avoid conflicts with include guards that may be used in the future. 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 f47ce4a6719c..302c82480799 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