Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net/p9: load default transports

Now that all transports are split into modules it may happen that no
transports are registered when v9fs_get_default_trans() is called.
When that is the case try to load more transports from modules.

Link: https://lkml.kernel.org/r/20211103193823.111007-5-linux@weissschuh.net
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
[Dominique: constify v9fs_get_trans_by_name argument as per patch1v2]
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>

authored by

Thomas Weißschuh and committed by
Dominique Martinet
019641d1 99aa673e

+12 -3
+1 -1
include/net/9p/transport.h
··· 54 54 55 55 void v9fs_register_trans(struct p9_trans_module *m); 56 56 void v9fs_unregister_trans(struct p9_trans_module *m); 57 - struct p9_trans_module *v9fs_get_trans_by_name(char *s); 57 + struct p9_trans_module *v9fs_get_trans_by_name(const char *s); 58 58 struct p9_trans_module *v9fs_get_default_trans(void); 59 59 void v9fs_put_trans(struct p9_trans_module *m); 60 60
+11 -2
net/9p/mod.c
··· 83 83 } 84 84 EXPORT_SYMBOL(v9fs_unregister_trans); 85 85 86 - static struct p9_trans_module *_p9_get_trans_by_name(char *s) 86 + static struct p9_trans_module *_p9_get_trans_by_name(const char *s) 87 87 { 88 88 struct p9_trans_module *t, *found = NULL; 89 89 ··· 106 106 * @s: string identifying transport 107 107 * 108 108 */ 109 - struct p9_trans_module *v9fs_get_trans_by_name(char *s) 109 + struct p9_trans_module *v9fs_get_trans_by_name(const char *s) 110 110 { 111 111 struct p9_trans_module *found = NULL; 112 112 ··· 123 123 } 124 124 EXPORT_SYMBOL(v9fs_get_trans_by_name); 125 125 126 + static const char * const v9fs_default_transports[] = { 127 + "virtio", "tcp", "fd", "unix", "xen", "rdma", 128 + }; 129 + 126 130 /** 127 131 * v9fs_get_default_trans - get the default transport 128 132 * ··· 135 131 struct p9_trans_module *v9fs_get_default_trans(void) 136 132 { 137 133 struct p9_trans_module *t, *found = NULL; 134 + int i; 138 135 139 136 spin_lock(&v9fs_trans_lock); 140 137 ··· 153 148 } 154 149 155 150 spin_unlock(&v9fs_trans_lock); 151 + 152 + for (i = 0; !found && i < ARRAY_SIZE(v9fs_default_transports); i++) 153 + found = v9fs_get_trans_by_name(v9fs_default_transports[i]); 154 + 156 155 return found; 157 156 } 158 157 EXPORT_SYMBOL(v9fs_get_default_trans);