linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Can we autogenerate smb2_error_map_table[]?
@ 2025-12-10 23:03 David Howells
  2025-12-10 23:40 ` ChenXiaoSong
  0 siblings, 1 reply; 15+ messages in thread
From: David Howells @ 2025-12-10 23:03 UTC (permalink / raw)
  To: ChenXiaoSong
  Cc: dhowells, Steve French, ChenXiaoSong, liuzhengyuan, huhai,
	liuyun01, Paulo Alcantara, linux-cifs

Hi Chenxiaosong,

Can I suggest that rather than doing your "[PATCH v4 05/10] smb/client: sort
smb2_error_map_table array", we autogenerate the table from the header file,
putting all the info there?

One problem that we have is that we have multiple copies of the error table -
and keeping them up to date and strictly ordered is problematic (hence your
kunit test).  Further, each error number is mapped to an error string with the
name of the symbol (I think they're all exactly equivalent).

So, for example, I do this for the ASN.1 Object Identifier (OID) registry.  I
have a perl script:

	lib/build_OID_registry

that parses the enum here:

	include/linux/oid_registry.h

including the comments and generating tables for looking up OIDs:

	enum OID {
		OID_id_dsa_with_sha1,		/* 1.2.840.10030.4.3 */
		OID_id_dsa,			/* 1.2.840.10040.4.1 */

This is built by rules in lib/Makefile:

	#
	# Build a fast OID lookip registry from include/linux/oid_registry.h
	#
	obj-$(CONFIG_OID_REGISTRY) += oid_registry.o

	$(obj)/oid_registry.o: $(obj)/oid_registry_data.c

	$(obj)/oid_registry_data.c: $(srctree)/include/linux/oid_registry.h \
				    $(src)/build_OID_registry
		$(call cmd,build_OID_registry)

	quiet_cmd_build_OID_registry = GEN     $@
	      cmd_build_OID_registry = perl $(src)/build_OID_registry $< $@

	clean-files	+= oid_registry_data.c

Now, looking at smb2status.h, for example, we have a lot of:

	#define STATUS_SUCCESS cpu_to_le32(0x00000000)
	#define STATUS_WAIT_0 cpu_to_le32(0x00000000)
	#define STATUS_WAIT_1 cpu_to_le32(0x00000001)
	...

and we could generate two parts of the table from this.  The third part could
be placed in the header as well:

	#define STATUS_SUCCESS	cpu_to_le32(0x00000000)	// 0
	#define STATUS_WAIT_0	cpu_to_le32(0x00000000)	// -EIO
	#define STATUS_WAIT_1	cpu_to_le32(0x00000001)	// -EIO
	...

(There's also the possibility that we don't necessarily want to list all
statuses in the table.)

David


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2025-12-12 10:20 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-10 23:03 Can we autogenerate smb2_error_map_table[]? David Howells
2025-12-10 23:40 ` ChenXiaoSong
     [not found]   ` <CAH2r5msTSRvKRwQYjuVP62KB5beoS99e4eYKYHQ9ZPTYejykRA@mail.gmail.com>
2025-12-11  0:11     ` ChenXiaoSong
2025-12-11 15:03     ` [PATCH 1/2] cifs: Label SMB2 statuses with errors David Howells
2025-12-12  0:19       ` ChenXiaoSong
2025-12-12  0:29         ` ChenXiaoSong
2025-12-12  9:35       ` David Howells
2025-12-11 15:04     ` [PATCH 2/2] cifs: Autogenerate SMB2 error mapping table David Howells
2025-12-11 15:33       ` ChenXiaoSong
2025-12-11 15:43       ` David Howells
2025-12-12  2:09       ` ChenXiaoSong
2025-12-12  9:41       ` David Howells
2025-12-12 10:19         ` ChenXiaoSong
2025-12-12  9:48       ` David Howells
2025-12-11 15:11     ` Can we autogenerate smb2_error_map_table[]? David Howells

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).