From: Linus Walleij <linus.walleij@linaro.org>
To: Namjae Jeon <linkinjeon@kernel.org>,
Steve French <smfrench@gmail.com>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Tom Talpey <tom@talpey.com>
Cc: linux-cifs@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Rosen Penev <rosenp@gmail.com>,
Linus Walleij <linus.walleij@linaro.org>
Subject: [PATCH v2] RFC: ksmbd: Create module_kobject if builtin
Date: Fri, 24 Oct 2025 00:49:44 +0200 [thread overview]
Message-ID: <20251024-ksmbd-sysfs-module-v2-1-acba8159dbe5@linaro.org> (raw)
Adding a call to lookup_or_create_module_kobject() to ksmbd
makes /sys/modules/ksmbd appear even when ksmbd is compiled
into the kernel.
This is nice when you boot a custom kernel on OpenWrt because
the startup script does things such as:
[ ! -e /sys/module/ksmbd ] && modprobe ksmbd 2> /dev/null
if [ ! -e /sys/module/ksmbd ]; then
logger -p daemon.error -t 'ksmbd' "modprobe of ksmbd "
"module failed, can\'t start ksmbd!"
exit 1
fi
which makes the script not work with a compiled-in ksmbd.
Since I actually turn off modules and compile all my modules
into the kernel, I can't change the script to just check
cat /lib/modules/$(uname -r)/modules.builtin | grep ksmbd
either: no /lib/modules directory.
An option would be to change the script to proceed and
just assume the module is compiled in but it feels wrong.
If this approach is acceptable I am happy to generalize this
to something that any module that wants a /sys/modules/foo
file can use to get just that.
I can think of other ways to just create a dummy dir in
/sys/modules but it is probably unwise if someone would later
actually add a parameter or version string to the module and
get unpredictable bugs. It's probably better like this if
we do this thing.
Cc: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
Changes in v2:
- Adding MODULE_VERSION() just to get /sys/module/ksmbd was wrong.
- Try this other approach to call lookup_or_create_module_kobject()
if and only if ksmbd is compiled in.
- Link to v1: https://lore.kernel.org/r/20250531-ksmbd-sysfs-module-v1-1-248cf10fa87d@linaro.org
---
fs/smb/server/server.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/fs/smb/server/server.c b/fs/smb/server/server.c
index 40420544cc25a2f7767695641e85d126022a30f9..f12ec149899664efdc9587db749dc8a1d6ccfdae 100644
--- a/fs/smb/server/server.c
+++ b/fs/smb/server/server.c
@@ -588,8 +588,24 @@ static int __init ksmbd_server_init(void)
if (ret)
goto err_crypto_destroy;
+ if (IS_BUILTIN(CONFIG_SMB_SERVER)) {
+ static struct module_kobject *mk;
+
+ /*
+ * All this does is assure that /sys/module/ksmbd comes
+ * into existence if ksmbd is compiled in so that userspace
+ * can rely on its existence to identify that ksmbd is
+ * available.
+ */
+ mk = lookup_or_create_module_kobject(KBUILD_MODNAME);
+ if (!mk)
+ goto err_workqueue_destroy;
+ }
+
return 0;
+err_workqueue_destroy:
+ ksmbd_workqueue_destroy();
err_crypto_destroy:
ksmbd_crypto_destroy();
err_release_inode_hash:
---
base-commit: 3a8660878839faadb4f1a6dd72c3179c1df56787
change-id: 20250531-ksmbd-sysfs-module-efaf2d1a86ca
Best regards,
--
Linus Walleij <linus.walleij@linaro.org>
next reply other threads:[~2025-10-23 22:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-23 22:49 Linus Walleij [this message]
2025-10-24 5:08 ` [PATCH v2] RFC: ksmbd: Create module_kobject if builtin Greg Kroah-Hartman
2025-10-24 6:05 ` Linus Walleij
2025-10-24 6:37 ` Greg Kroah-Hartman
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=20251024-ksmbd-sysfs-module-v2-1-acba8159dbe5@linaro.org \
--to=linus.walleij@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=rosenp@gmail.com \
--cc=senozhatsky@chromium.org \
--cc=smfrench@gmail.com \
--cc=tom@talpey.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).