2005-01-18 19:38:16

by Andreas Gruenbacher

[permalink] [raw]
Subject: [kbuild 4/5] Include type information as module info where possible

Originally-from: Rusty Russell <[email protected]>
Subject: Include type information as module info where possible
References: 48396

Module parameters no longer have a type in general, as we use a callback
system (module_param_call()). However, it's useful to include type
information in the commonly-used wrappers: module_param,
module_param_string and module_param_array.

This adds a parmtype modinfo tag for each parameter defined using
module_param() or MODULE_PARM(). This allows modinfo to easily print all
parameters and their types, independent of whether or not the parameter
has a description (MODULE_PARM_DESC()).

Originally-signed-off-by: Rusty Russell <[email protected]>
Signed-off-by: Andreas Gruenbacher <[email protected]>

Index: linux-2.6.11-rc1-bk6/include/linux/moduleparam.h
===================================================================
--- linux-2.6.11-rc1-bk6.orig/include/linux/moduleparam.h
+++ linux-2.6.11-rc1-bk6/include/linux/moduleparam.h
@@ -64,7 +64,8 @@ struct kparam_array
param_set_XXX and param_check_XXX. */
#define module_param_named(name, value, type, perm) \
param_check_##type(name, &(value)); \
- module_param_call(name, param_set_##type, param_get_##type, &value, perm)
+ module_param_call(name, param_set_##type, param_get_##type, &value, perm); \
+ MODULE_PARM_TYPE(name, #type)

#define module_param(name, type, perm) \
module_param_named(name, name, type, perm)
@@ -74,7 +75,8 @@ struct kparam_array
static struct kparam_string __param_string_##name \
= { len, string }; \
module_param_call(name, param_set_copystring, param_get_string, \
- &__param_string_##name, perm)
+ &__param_string_##name, perm); \
+ MODULE_PARM_TYPE(name, "string")

/* Called on module insert or kernel boot */
extern int parse_args(const char *name,
@@ -135,7 +137,8 @@ extern int param_get_invbool(char *buffe
= { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\
sizeof(array[0]), array }; \
module_param_call(name, param_array_set, param_array_get, \
- &__param_arr_##name, perm)
+ &__param_arr_##name, perm); \
+ MODULE_PARM_TYPE(name, "array of " #type)

#define module_param_array(name, type, nump, perm) \
module_param_array_named(name, name, type, nump, perm)
Index: linux-2.6.11-rc1-bk6/include/linux/module.h
===================================================================
--- linux-2.6.11-rc1-bk6.orig/include/linux/module.h
+++ linux-2.6.11-rc1-bk6/include/linux/module.h
@@ -138,6 +138,10 @@ extern struct module __this_module;
/* What your module does. */
#define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)

+/* Type information for a module parameter. */
+#define MODULE_PARM_TYPE(name, _type) \
+ __MODULE_INFO(parmtype, name##type, #name ":" _type)
+
/* One for each parameter, describing how to use it. Some files do
multiple of these per line, so can't just use MODULE_INFO. */
#define MODULE_PARM_DESC(_parm, desc) \
@@ -560,7 +564,8 @@ static inline void MODULE_PARM_(void) {
/* DEPRECATED: Do not use. */
#define MODULE_PARM(var,type) \
struct obsolete_modparm __parm_##var __attribute__((section("__obsparm"))) = \
-{ __stringify(var), type, &MODULE_PARM_ };
+{ __stringify(var), type, &MODULE_PARM_ }; \
+MODULE_PARM_TYPE(var, type);
#else
#define MODULE_PARM(var,type) static void __attribute__((__unused__)) *__parm_##var = &MODULE_PARM_;
#endif

--
Andreas Gruenbacher <[email protected]>
SUSE Labs, SUSE LINUX PRODUCTS GMBH


2005-01-19 16:14:28

by Andreas Gruenbacher

[permalink] [raw]
Subject: Re: [kbuild 4/5] Include type information as module info where possible

Hello,

MODULE_PARM_TYPE needs to be moved to moduleparam.h: several files
include moduleparam.h but not module.h.

Regards,
--
Andreas Gruenbacher <[email protected]>
SUSE Labs, SUSE LINUX GMBH


Attachments:
mod_param-typeinfo.diff (3.38 kB)

2005-01-20 11:54:54

by Andreas Gruenbacher

[permalink] [raw]
Subject: Re: [kbuild 4/5] Include type information as module info where possible

On Wednesday 19 January 2005 17:14, you wrote:
> Hello,
>
> MODULE_PARM_TYPE needs to be moved to moduleparam.h: several files
> include moduleparam.h but not module.h.

Ah, and __MODULE_INFO needs to be moved to moduleparam.h now as well:


Index: linux-2.6.10/include/linux/moduleparam.h
===================================================================
--- linux-2.6.10.orig/include/linux/moduleparam.h
+++ linux-2.6.10/include/linux/moduleparam.h
@@ -13,6 +13,21 @@
#define MODULE_PARAM_PREFIX __stringify(KBUILD_MODNAME) "."
#endif

+#ifdef MODULE
+#define ___module_cat(a,b) __mod_ ## a ## b
+#define __module_cat(a,b) ___module_cat(a,b)
+#define __MODULE_INFO(tag, name, info) \
+static const char __module_cat(name,__LINE__)[] \
+ __attribute_used__ \
+ __attribute__((section(".modinfo"),unused)) = __stringify(tag) "=" info
+#else /* !MODULE */
+#define __MODULE_INFO(tag, name, info)
+#endif
+
+/* Type information for a module parameter. */
+#define MODULE_PARM_TYPE(name, _type) \
+ __MODULE_INFO(parmtype, name##type, #name ":" _type)
+
struct kernel_param;

/* Returns 0, or -errno. arg is in kp->arg. */
@@ -64,7 +79,8 @@ struct kparam_array
param_set_XXX and param_check_XXX. */
#define module_param_named(name, value, type, perm) \
param_check_##type(name, &(value)); \
- module_param_call(name, param_set_##type, param_get_##type, &value, perm)
+ module_param_call(name, param_set_##type, param_get_##type, &value, perm); \
+ MODULE_PARM_TYPE(name, #type)

#define module_param(name, type, perm) \
module_param_named(name, name, type, perm)
@@ -74,7 +90,8 @@ struct kparam_array
static struct kparam_string __param_string_##name \
= { len, string }; \
module_param_call(name, param_set_copystring, param_get_string, \
- &__param_string_##name, perm)
+ &__param_string_##name, perm); \
+ MODULE_PARM_TYPE(name, "string")

/* Called on module insert or kernel boot */
extern int parse_args(const char *name,
@@ -135,7 +152,8 @@ extern int param_get_invbool(char *buffe
= { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\
sizeof(array[0]), array }; \
module_param_call(name, param_array_set, param_array_get, \
- &__param_arr_##name, perm)
+ &__param_arr_##name, perm); \
+ MODULE_PARM_TYPE(name, "array of " #type)

#define module_param_array(name, type, nump, perm) \
module_param_array_named(name, name, type, nump, perm)
Index: linux-2.6.10/include/linux/module.h
===================================================================
--- linux-2.6.10.orig/include/linux/module.h
+++ linux-2.6.10/include/linux/module.h
@@ -76,13 +76,6 @@ void sort_main_extable(void);
extern struct subsystem module_subsys;

#ifdef MODULE
-#define ___module_cat(a,b) __mod_ ## a ## b
-#define __module_cat(a,b) ___module_cat(a,b)
-#define __MODULE_INFO(tag, name, info) \
-static const char __module_cat(name,__LINE__)[] \
- __attribute_used__ \
- __attribute__((section(".modinfo"),unused)) = __stringify(tag) "=" info
-
#define MODULE_GENERIC_TABLE(gtype,name) \
extern const struct gtype##_id __mod_##gtype##_table \
__attribute__ ((unused, alias(__stringify(name))))
@@ -93,7 +86,6 @@ extern struct module __this_module;
#else /* !MODULE */

#define MODULE_GENERIC_TABLE(gtype,name)
-#define __MODULE_INFO(tag, name, info)
#define THIS_MODULE ((struct module *)0)
#endif

@@ -564,7 +556,8 @@ static inline void MODULE_PARM_(void) {
/* DEPRECATED: Do not use. */
#define MODULE_PARM(var,type) \
struct obsolete_modparm __parm_##var __attribute__((section("__obsparm"))) = \
-{ __stringify(var), type, &MODULE_PARM_ };
+{ __stringify(var), type, &MODULE_PARM_ }; \
+MODULE_PARM_TYPE(var, type);
#else
#define MODULE_PARM(var,type) static void __attribute__((__unused__)) *__parm_##var = &MODULE_PARM_;
#endif


Regards,
--
Andreas Gruenbacher <[email protected]>
SUSE Labs, SUSE LINUX PRODUCTS GMBH

2005-01-30 15:54:40

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [kbuild 4/5] Include type information as module info where possible

On Thu, Jan 20, 2005 at 12:54:46PM +0100, Andreas Gruenbacher wrote:
> On Wednesday 19 January 2005 17:14, you wrote:
> > Hello,
> >
> > MODULE_PARM_TYPE needs to be moved to moduleparam.h: several files
> > include moduleparam.h but not module.h.
>
> Ah, and __MODULE_INFO needs to be moved to moduleparam.h now as well:

Rusty got the original patch applied.
Can you please update this to latest kernel and resend including updated
changelog.

Thanks,
Sam

2005-01-30 22:06:22

by Andreas Gruenbacher

[permalink] [raw]
Subject: Re: [kbuild 4/5] Include type information as module info where possible

On Sunday 30 January 2005 16:56, Sam Ravnborg wrote:
> Rusty got the original patch applied.

Not completely. The fix is attached.

Cheers,
--
Andreas Gruenbacher <[email protected]>
SUSE Labs, SUSE LINUX PRODUCTS GMBH


Attachments:
(No filename) (217.00 B)
module-parmtype.diff (4.37 kB)
Download all attachments

2005-01-30 22:18:01

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [kbuild 4/5] Include type information as module info where possible

On Sun, Jan 30, 2005 at 11:06:11PM +0100, Andreas Gruenbacher wrote:
> On Sunday 30 January 2005 16:56, Sam Ravnborg wrote:
> > Rusty got the original patch applied.
>
> Not completely. The fix is attached.

Applied.

Sam