Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /* AFS client file system
0003  *
0004  * Copyright (C) 2002,5 Red Hat, Inc. All Rights Reserved.
0005  * Written by David Howells (dhowells@redhat.com)
0006  */
0007 
0008 #include <linux/module.h>
0009 #include <linux/moduleparam.h>
0010 #include <linux/init.h>
0011 #include <linux/completion.h>
0012 #include <linux/sched.h>
0013 #include <linux/random.h>
0014 #include <linux/proc_fs.h>
0015 #define CREATE_TRACE_POINTS
0016 #include "internal.h"
0017 
0018 MODULE_DESCRIPTION("AFS Client File System");
0019 MODULE_AUTHOR("Red Hat, Inc.");
0020 MODULE_LICENSE("GPL");
0021 
0022 unsigned afs_debug;
0023 module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO);
0024 MODULE_PARM_DESC(debug, "AFS debugging mask");
0025 
0026 static char *rootcell;
0027 
0028 module_param(rootcell, charp, 0);
0029 MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
0030 
0031 struct workqueue_struct *afs_wq;
0032 static struct proc_dir_entry *afs_proc_symlink;
0033 
0034 #if defined(CONFIG_ALPHA)
0035 const char afs_init_sysname[] = "alpha_linux26";
0036 #elif defined(CONFIG_X86_64)
0037 const char afs_init_sysname[] = "amd64_linux26";
0038 #elif defined(CONFIG_ARM)
0039 const char afs_init_sysname[] = "arm_linux26";
0040 #elif defined(CONFIG_ARM64)
0041 const char afs_init_sysname[] = "aarch64_linux26";
0042 #elif defined(CONFIG_X86_32)
0043 const char afs_init_sysname[] = "i386_linux26";
0044 #elif defined(CONFIG_IA64)
0045 const char afs_init_sysname[] = "ia64_linux26";
0046 #elif defined(CONFIG_PPC64)
0047 const char afs_init_sysname[] = "ppc64_linux26";
0048 #elif defined(CONFIG_PPC32)
0049 const char afs_init_sysname[] = "ppc_linux26";
0050 #elif defined(CONFIG_S390)
0051 #ifdef CONFIG_64BIT
0052 const char afs_init_sysname[] = "s390x_linux26";
0053 #else
0054 const char afs_init_sysname[] = "s390_linux26";
0055 #endif
0056 #elif defined(CONFIG_SPARC64)
0057 const char afs_init_sysname[] = "sparc64_linux26";
0058 #elif defined(CONFIG_SPARC32)
0059 const char afs_init_sysname[] = "sparc_linux26";
0060 #else
0061 const char afs_init_sysname[] = "unknown_linux26";
0062 #endif
0063 
0064 /*
0065  * Initialise an AFS network namespace record.
0066  */
0067 static int __net_init afs_net_init(struct net *net_ns)
0068 {
0069     struct afs_sysnames *sysnames;
0070     struct afs_net *net = afs_net(net_ns);
0071     int ret;
0072 
0073     net->net = net_ns;
0074     net->live = true;
0075     generate_random_uuid((unsigned char *)&net->uuid);
0076 
0077     INIT_WORK(&net->charge_preallocation_work, afs_charge_preallocation);
0078     mutex_init(&net->socket_mutex);
0079 
0080     net->cells = RB_ROOT;
0081     init_rwsem(&net->cells_lock);
0082     INIT_WORK(&net->cells_manager, afs_manage_cells);
0083     timer_setup(&net->cells_timer, afs_cells_timer, 0);
0084 
0085     mutex_init(&net->cells_alias_lock);
0086     mutex_init(&net->proc_cells_lock);
0087     INIT_HLIST_HEAD(&net->proc_cells);
0088 
0089     seqlock_init(&net->fs_lock);
0090     net->fs_servers = RB_ROOT;
0091     INIT_LIST_HEAD(&net->fs_probe_fast);
0092     INIT_LIST_HEAD(&net->fs_probe_slow);
0093     INIT_HLIST_HEAD(&net->fs_proc);
0094 
0095     INIT_HLIST_HEAD(&net->fs_addresses4);
0096     INIT_HLIST_HEAD(&net->fs_addresses6);
0097     seqlock_init(&net->fs_addr_lock);
0098 
0099     INIT_WORK(&net->fs_manager, afs_manage_servers);
0100     timer_setup(&net->fs_timer, afs_servers_timer, 0);
0101     INIT_WORK(&net->fs_prober, afs_fs_probe_dispatcher);
0102     timer_setup(&net->fs_probe_timer, afs_fs_probe_timer, 0);
0103     atomic_set(&net->servers_outstanding, 1);
0104 
0105     ret = -ENOMEM;
0106     sysnames = kzalloc(sizeof(*sysnames), GFP_KERNEL);
0107     if (!sysnames)
0108         goto error_sysnames;
0109     sysnames->subs[0] = (char *)&afs_init_sysname;
0110     sysnames->nr = 1;
0111     refcount_set(&sysnames->usage, 1);
0112     net->sysnames = sysnames;
0113     rwlock_init(&net->sysnames_lock);
0114 
0115     /* Register the /proc stuff */
0116     ret = afs_proc_init(net);
0117     if (ret < 0)
0118         goto error_proc;
0119 
0120     /* Initialise the cell DB */
0121     ret = afs_cell_init(net, rootcell);
0122     if (ret < 0)
0123         goto error_cell_init;
0124 
0125     /* Create the RxRPC transport */
0126     ret = afs_open_socket(net);
0127     if (ret < 0)
0128         goto error_open_socket;
0129 
0130     return 0;
0131 
0132 error_open_socket:
0133     net->live = false;
0134     afs_fs_probe_cleanup(net);
0135     afs_cell_purge(net);
0136     afs_purge_servers(net);
0137 error_cell_init:
0138     net->live = false;
0139     afs_proc_cleanup(net);
0140 error_proc:
0141     afs_put_sysnames(net->sysnames);
0142 error_sysnames:
0143     net->live = false;
0144     return ret;
0145 }
0146 
0147 /*
0148  * Clean up and destroy an AFS network namespace record.
0149  */
0150 static void __net_exit afs_net_exit(struct net *net_ns)
0151 {
0152     struct afs_net *net = afs_net(net_ns);
0153 
0154     net->live = false;
0155     afs_fs_probe_cleanup(net);
0156     afs_cell_purge(net);
0157     afs_purge_servers(net);
0158     afs_close_socket(net);
0159     afs_proc_cleanup(net);
0160     afs_put_sysnames(net->sysnames);
0161 }
0162 
0163 static struct pernet_operations afs_net_ops = {
0164     .init   = afs_net_init,
0165     .exit   = afs_net_exit,
0166     .id = &afs_net_id,
0167     .size   = sizeof(struct afs_net),
0168 };
0169 
0170 /*
0171  * initialise the AFS client FS module
0172  */
0173 static int __init afs_init(void)
0174 {
0175     int ret = -ENOMEM;
0176 
0177     printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
0178 
0179     afs_wq = alloc_workqueue("afs", 0, 0);
0180     if (!afs_wq)
0181         goto error_afs_wq;
0182     afs_async_calls = alloc_workqueue("kafsd", WQ_MEM_RECLAIM, 0);
0183     if (!afs_async_calls)
0184         goto error_async;
0185     afs_lock_manager = alloc_workqueue("kafs_lockd", WQ_MEM_RECLAIM, 0);
0186     if (!afs_lock_manager)
0187         goto error_lockmgr;
0188 
0189     ret = register_pernet_device(&afs_net_ops);
0190     if (ret < 0)
0191         goto error_net;
0192 
0193     /* register the filesystems */
0194     ret = afs_fs_init();
0195     if (ret < 0)
0196         goto error_fs;
0197 
0198     afs_proc_symlink = proc_symlink("fs/afs", NULL, "../self/net/afs");
0199     if (!afs_proc_symlink) {
0200         ret = -ENOMEM;
0201         goto error_proc;
0202     }
0203 
0204     return ret;
0205 
0206 error_proc:
0207     afs_fs_exit();
0208 error_fs:
0209     unregister_pernet_device(&afs_net_ops);
0210 error_net:
0211     destroy_workqueue(afs_lock_manager);
0212 error_lockmgr:
0213     destroy_workqueue(afs_async_calls);
0214 error_async:
0215     destroy_workqueue(afs_wq);
0216 error_afs_wq:
0217     rcu_barrier();
0218     printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
0219     return ret;
0220 }
0221 
0222 /* XXX late_initcall is kludgy, but the only alternative seems to create
0223  * a transport upon the first mount, which is worse. Or is it?
0224  */
0225 late_initcall(afs_init);    /* must be called after net/ to create socket */
0226 
0227 /*
0228  * clean up on module removal
0229  */
0230 static void __exit afs_exit(void)
0231 {
0232     printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
0233 
0234     proc_remove(afs_proc_symlink);
0235     afs_fs_exit();
0236     unregister_pernet_device(&afs_net_ops);
0237     destroy_workqueue(afs_lock_manager);
0238     destroy_workqueue(afs_async_calls);
0239     destroy_workqueue(afs_wq);
0240     afs_clean_up_permit_cache();
0241     rcu_barrier();
0242 }
0243 
0244 module_exit(afs_exit);