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,
liuzhengyuan@kylinos.cn, huhai@kylinos.cn, liuyun01@kylinos.cn,
ChenXiaoSong <chenxiaosong@kylinos.cn>
Subject: [PATCH 16/30] smb/client: sort nt_errs array
Date: Mon, 8 Dec 2025 14:20:46 +0800 [thread overview]
Message-ID: <20251208062100.3268777-17-chenxiaosong.chenxiaosong@linux.dev> (raw)
In-Reply-To: <20251208062100.3268777-1-chenxiaosong.chenxiaosong@linux.dev>
From: ChenXiaoSong <chenxiaosong@kylinos.cn>
Sort the array in ascending order, and then we can use binary search
algorithm to quickly find the target NT error code.
The array is sorted only once when cifs.ko is loaded.
Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
---
fs/smb/client/netmisc.c | 4 ++++
fs/smb/client/nterr.c | 5 ++++-
fs/smb/client/nterr.h | 3 ++-
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/fs/smb/client/netmisc.c b/fs/smb/client/netmisc.c
index 4e6312593d6f..c6fa1389683b 100644
--- a/fs/smb/client/netmisc.c
+++ b/fs/smb/client/netmisc.c
@@ -801,6 +801,8 @@ static unsigned int ntstatus_to_dos_num = sizeof(ntstatus_to_dos_map) /
/* cmp_ntstatus_to_dos */
DEFINE_CMP_FUNC(ntstatus_to_dos, ntstatus);
+/* cmp_nt_err_code_struct */
+DEFINE_CMP_FUNC(nt_err_code_struct, nt_errcode);
/* search_in_ntstatus_to_dos_map */
DEFINE_SEARCH_FUNC(ntstatus_to_dos, ntstatus, ntstatus_to_dos_map, ntstatus_to_dos_num);
@@ -1075,6 +1077,8 @@ void smb_init_maperror(void)
/* Sort in ascending order */
sort(ntstatus_to_dos_map, ntstatus_to_dos_num,
sizeof(struct ntstatus_to_dos), cmp_ntstatus_to_dos, NULL);
+ sort(nt_errs, nt_err_num, sizeof(struct nt_err_code_struct),
+ cmp_nt_err_code_struct, NULL);
}
#if IS_ENABLED(CONFIG_SMB_KUNIT_TESTS)
diff --git a/fs/smb/client/nterr.c b/fs/smb/client/nterr.c
index 77f84767b7df..8d0007db6af9 100644
--- a/fs/smb/client/nterr.c
+++ b/fs/smb/client/nterr.c
@@ -11,7 +11,7 @@
#include <linux/fs.h>
#include "nterr.h"
-const struct nt_err_code_struct nt_errs[] = {
+struct nt_err_code_struct nt_errs[] = {
{"NT_STATUS_OK", NT_STATUS_OK},
{"NT_STATUS_PENDING", NT_STATUS_PENDING},
{"NT_STATUS_MEDIA_CHANGED", NT_STATUS_MEDIA_CHANGED},
@@ -686,3 +686,6 @@ const struct nt_err_code_struct nt_errs[] = {
NT_STATUS_NO_PREAUTH_INTEGRITY_HASH_OVERLAP},
{NULL, 0}
};
+
+unsigned int nt_err_num = sizeof(nt_errs) /
+ sizeof(struct nt_err_code_struct);
diff --git a/fs/smb/client/nterr.h b/fs/smb/client/nterr.h
index 81f1a78cf41f..e85e65278fb5 100644
--- a/fs/smb/client/nterr.h
+++ b/fs/smb/client/nterr.h
@@ -20,7 +20,8 @@ struct nt_err_code_struct {
__u32 nt_errcode;
};
-extern const struct nt_err_code_struct nt_errs[];
+extern struct nt_err_code_struct nt_errs[];
+extern unsigned int nt_err_num;
/* Win32 Status codes. */
#define NT_STATUS_MORE_ENTRIES 0x0105
--
2.43.0
next prev parent reply other threads:[~2025-12-08 6:23 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-08 6:20 [PATCH 00/30] smb: improve search speed of SMB1 maperror chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 01/30] smb/client: fix NT_STATUS_NO_DATA_DETECTED value chenxiaosong.chenxiaosong
2025-12-09 0:17 ` ChenXiaoSong
2025-12-09 0:29 ` Steve French
2025-12-09 0:45 ` ChenXiaoSong
2025-12-08 6:20 ` [PATCH 02/30] smb/client: fix NT_STATUS_DEVICE_DOOR_OPEN value chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 03/30] smb/client: fix NT_STATUS_UNABLE_TO_FREE_VM value chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 04/30] smb/server: remove unused nterr.h chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 05/30] smb/client: add 4 NT error code definitions chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 06/30] smb/client: add parentheses to NT error code definitions containing bitwise OR operator chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 07/30] smb/client: introduce DEFINE_CMP_FUNC() chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 08/30] smb/client: sort ntstatus_to_dos_map array chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 09/30] smb/client: create netmisc_test.c and introduce DEFINE_CHECK_SORT_FUNC() chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 10/30] smb/client: introduce KUnit test to check sort result of ntstatus_to_dos_map array chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 11/30] smb/client: introduce DEFINE_SEARCH_FUNC() chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 12/30] smb/client: use bsearch() to find target in ntstatus_to_dos_map array chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 13/30] smb/client: remove useless elements from " chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 14/30] smb/client: introduce DEFINE_CHECK_SEARCH_FUNC() chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 15/30] smb/client: introduce KUnit test to check search result of ntstatus_to_dos_map array chenxiaosong.chenxiaosong
2025-12-08 6:20 ` chenxiaosong.chenxiaosong [this message]
2025-12-08 6:20 ` [PATCH 17/30] smb/client: introduce KUnit test to check sort result of nt_errs array chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 18/30] smb/client: use bsearch() to find target in " chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 19/30] smb/client: remove useless elements from " chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 20/30] smb/client: introduce KUnit test to check search result of " chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 21/30] smb/client: sort mapping_table_ERRDOS array chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 22/30] smb/client: introduce KUnit test to check sort result of " chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 23/30] smb/client: use bsearch() to find target in " chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 24/30] smb/client: remove useless elements from " chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 25/30] smb/client: introduce KUnit test to check search result of " chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 26/30] smb/client: sort mapping_table_ERRSRV array chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 27/30] smb/client: introduce KUnit test to check sort result of " chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 28/30] smb/client: use bsearch() to find target in " chenxiaosong.chenxiaosong
2025-12-08 6:20 ` [PATCH 29/30] smb/client: remove useless elements from " chenxiaosong.chenxiaosong
2025-12-08 6:21 ` [PATCH 30/30] smb/client: introduce KUnit test to check search result of " chenxiaosong.chenxiaosong
2025-12-09 23:41 ` [PATCH 00/30] smb: improve search speed of SMB1 maperror Steve French
2025-12-10 2:48 ` ChenXiaoSong
2025-12-10 4:32 ` ChenXiaoSong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251208062100.3268777-17-chenxiaosong.chenxiaosong@linux.dev \
--to=chenxiaosong.chenxiaosong@linux.dev \
--cc=chenxiaosong@kylinos.cn \
--cc=huhai@kylinos.cn \
--cc=linkinjeon@kernel.org \
--cc=linkinjeon@samba.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuyun01@kylinos.cn \
--cc=liuzhengyuan@kylinos.cn \
--cc=sfrench@samba.org \
--cc=smfrench@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).