Skip to content

Commit

Permalink
net/9p: autoload transport modules
Browse files Browse the repository at this point in the history
Automatically load transport modules based on the trans= parameter
passed to mount.
This removes the requirement for the user to know which module to use.

Link: http://lkml.kernel.org/r/20211017134611.4330-1-linux@weissschuh.net
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
  • Loading branch information
Thomas Weißschuh authored and Dominique Martinet committed Nov 3, 2021
1 parent 27eb4c3 commit 4cd82a5
Showing 5 changed files with 33 additions and 6 deletions.
6 changes: 6 additions & 0 deletions include/net/9p/transport.h
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@
#ifndef NET_9P_TRANSPORT_H
#define NET_9P_TRANSPORT_H

#include <linux/module.h>

#define P9_DEF_MIN_RESVPORT (665U)
#define P9_DEF_MAX_RESVPORT (1023U)

@@ -55,4 +57,8 @@ void v9fs_unregister_trans(struct p9_trans_module *m);
struct p9_trans_module *v9fs_get_trans_by_name(char *s);
struct p9_trans_module *v9fs_get_default_trans(void);
void v9fs_put_trans(struct p9_trans_module *m);

#define MODULE_ALIAS_9P(transport) \
MODULE_ALIAS("9p-" transport)

#endif /* NET_9P_TRANSPORT_H */
30 changes: 24 additions & 6 deletions net/9p/mod.c
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/module.h>
#include <linux/kmod.h>
#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/moduleparam.h>
@@ -87,12 +88,7 @@ void v9fs_unregister_trans(struct p9_trans_module *m)
}
EXPORT_SYMBOL(v9fs_unregister_trans);

/**
* v9fs_get_trans_by_name - get transport with the matching name
* @s: string identifying transport
*
*/
struct p9_trans_module *v9fs_get_trans_by_name(char *s)
static struct p9_trans_module *_p9_get_trans_by_name(char *s)
{
struct p9_trans_module *t, *found = NULL;

@@ -106,6 +102,28 @@ struct p9_trans_module *v9fs_get_trans_by_name(char *s)
}

spin_unlock(&v9fs_trans_lock);

return found;
}

/**
* v9fs_get_trans_by_name - get transport with the matching name
* @s: string identifying transport
*
*/
struct p9_trans_module *v9fs_get_trans_by_name(char *s)
{
struct p9_trans_module *found = NULL;

found = _p9_get_trans_by_name(s);

#ifdef CONFIG_MODULES
if (!found) {
request_module("9p-%s", s);
found = _p9_get_trans_by_name(s);
}
#endif

return found;
}
EXPORT_SYMBOL(v9fs_get_trans_by_name);
1 change: 1 addition & 0 deletions net/9p/trans_rdma.c
Original file line number Diff line number Diff line change
@@ -767,6 +767,7 @@ static void __exit p9_trans_rdma_exit(void)

module_init(p9_trans_rdma_init);
module_exit(p9_trans_rdma_exit);
MODULE_ALIAS_9P("rdma");

MODULE_AUTHOR("Tom Tucker <tom@opengridcomputing.com>");
MODULE_DESCRIPTION("RDMA Transport for 9P");
1 change: 1 addition & 0 deletions net/9p/trans_virtio.c
Original file line number Diff line number Diff line change
@@ -794,6 +794,7 @@ static void __exit p9_virtio_cleanup(void)

module_init(p9_virtio_init);
module_exit(p9_virtio_cleanup);
MODULE_ALIAS_9P("virtio");

MODULE_DEVICE_TABLE(virtio, id_table);
MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
1 change: 1 addition & 0 deletions net/9p/trans_xen.c
Original file line number Diff line number Diff line change
@@ -552,6 +552,7 @@ static int p9_trans_xen_init(void)
return rc;
}
module_init(p9_trans_xen_init);
MODULE_ALIAS_9P("xen");

static void p9_trans_xen_exit(void)
{

0 comments on commit 4cd82a5

Please sign in to comment.