1ec26815aSDavid Howells /* AFS client file system 21da177e4SLinus Torvalds * 39b3f26c9SDavid Howells * Copyright (C) 2002,5 Red Hat, Inc. All Rights Reserved. 41da177e4SLinus Torvalds * Written by David Howells (dhowells@redhat.com) 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or 71da177e4SLinus Torvalds * modify it under the terms of the GNU General Public License 81da177e4SLinus Torvalds * as published by the Free Software Foundation; either version 91da177e4SLinus Torvalds * 2 of the License, or (at your option) any later version. 101da177e4SLinus Torvalds */ 111da177e4SLinus Torvalds 121da177e4SLinus Torvalds #include <linux/module.h> 131da177e4SLinus Torvalds #include <linux/moduleparam.h> 141da177e4SLinus Torvalds #include <linux/init.h> 151da177e4SLinus Torvalds #include <linux/completion.h> 16e8edc6e0SAlexey Dobriyan #include <linux/sched.h> 17*e0661dfcSDavid Howells #include <linux/random.h> 181da177e4SLinus Torvalds #include "internal.h" 191da177e4SLinus Torvalds 201da177e4SLinus Torvalds MODULE_DESCRIPTION("AFS Client File System"); 211da177e4SLinus Torvalds MODULE_AUTHOR("Red Hat, Inc."); 221da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 231da177e4SLinus Torvalds 2408e0e7c8SDavid Howells unsigned afs_debug; 2508e0e7c8SDavid Howells module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO); 26424b00e2SPaul Bolle MODULE_PARM_DESC(debug, "AFS debugging mask"); 2708e0e7c8SDavid Howells 281da177e4SLinus Torvalds static char *rootcell; 291da177e4SLinus Torvalds 301da177e4SLinus Torvalds module_param(rootcell, charp, 0); 311da177e4SLinus Torvalds MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list"); 321da177e4SLinus Torvalds 33b908fe6bSDavid Howells struct afs_uuid afs_uuid; 340ad53eeeSTejun Heo struct workqueue_struct *afs_wq; 35b908fe6bSDavid Howells 36b908fe6bSDavid Howells /* 37b908fe6bSDavid Howells * get a client UUID 38b908fe6bSDavid Howells */ 39b908fe6bSDavid Howells static int __init afs_get_client_UUID(void) 40b908fe6bSDavid Howells { 41b908fe6bSDavid Howells struct timespec ts; 42b908fe6bSDavid Howells u64 uuidtime; 43b908fe6bSDavid Howells u16 clockseq; 44b908fe6bSDavid Howells int ret; 45b908fe6bSDavid Howells 46b908fe6bSDavid Howells /* read the MAC address of one of the external interfaces and construct 47b908fe6bSDavid Howells * a UUID from it */ 48ec9c9485SDavid Howells ret = afs_get_MAC_address(afs_uuid.node, sizeof(afs_uuid.node)); 49b908fe6bSDavid Howells if (ret < 0) 50b908fe6bSDavid Howells return ret; 51b908fe6bSDavid Howells 52b908fe6bSDavid Howells getnstimeofday(&ts); 53b908fe6bSDavid Howells uuidtime = (u64) ts.tv_sec * 1000 * 1000 * 10; 54b908fe6bSDavid Howells uuidtime += ts.tv_nsec / 100; 55b908fe6bSDavid Howells uuidtime += AFS_UUID_TO_UNIX_TIME; 56b908fe6bSDavid Howells afs_uuid.time_low = uuidtime; 57b908fe6bSDavid Howells afs_uuid.time_mid = uuidtime >> 32; 58b908fe6bSDavid Howells afs_uuid.time_hi_and_version = (uuidtime >> 48) & AFS_UUID_TIMEHI_MASK; 590ef13515SDavid Howells afs_uuid.time_hi_and_version |= AFS_UUID_VERSION_TIME; 60b908fe6bSDavid Howells 61b908fe6bSDavid Howells get_random_bytes(&clockseq, 2); 62b908fe6bSDavid Howells afs_uuid.clock_seq_low = clockseq; 63b908fe6bSDavid Howells afs_uuid.clock_seq_hi_and_reserved = 64b908fe6bSDavid Howells (clockseq >> 8) & AFS_UUID_CLOCKHI_MASK; 650ef13515SDavid Howells afs_uuid.clock_seq_hi_and_reserved |= AFS_UUID_VARIANT_STD; 66b908fe6bSDavid Howells 67b908fe6bSDavid Howells _debug("AFS UUID: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", 68b908fe6bSDavid Howells afs_uuid.time_low, 69b908fe6bSDavid Howells afs_uuid.time_mid, 70b908fe6bSDavid Howells afs_uuid.time_hi_and_version, 71b908fe6bSDavid Howells afs_uuid.clock_seq_hi_and_reserved, 72b908fe6bSDavid Howells afs_uuid.clock_seq_low, 73b908fe6bSDavid Howells afs_uuid.node[0], afs_uuid.node[1], afs_uuid.node[2], 74b908fe6bSDavid Howells afs_uuid.node[3], afs_uuid.node[4], afs_uuid.node[5]); 75b908fe6bSDavid Howells 76b908fe6bSDavid Howells return 0; 77b908fe6bSDavid Howells } 78b908fe6bSDavid Howells 791da177e4SLinus Torvalds /* 801da177e4SLinus Torvalds * initialise the AFS client FS module 811da177e4SLinus Torvalds */ 821da177e4SLinus Torvalds static int __init afs_init(void) 831da177e4SLinus Torvalds { 8408e0e7c8SDavid Howells int ret; 851da177e4SLinus Torvalds 861da177e4SLinus Torvalds printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n"); 871da177e4SLinus Torvalds 88b908fe6bSDavid Howells ret = afs_get_client_UUID(); 89b908fe6bSDavid Howells if (ret < 0) 90b908fe6bSDavid Howells return ret; 91b908fe6bSDavid Howells 920ad53eeeSTejun Heo /* create workqueue */ 930ad53eeeSTejun Heo ret = -ENOMEM; 940ad53eeeSTejun Heo afs_wq = alloc_workqueue("afs", 0, 0); 950ad53eeeSTejun Heo if (!afs_wq) 960ad53eeeSTejun Heo return ret; 970ad53eeeSTejun Heo 981da177e4SLinus Torvalds /* register the /proc stuff */ 991da177e4SLinus Torvalds ret = afs_proc_init(); 1001da177e4SLinus Torvalds if (ret < 0) 1010ad53eeeSTejun Heo goto error_proc; 1021da177e4SLinus Torvalds 1039b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 1041da177e4SLinus Torvalds /* we want to be able to cache */ 1059b3f26c9SDavid Howells ret = fscache_register_netfs(&afs_cache_netfs); 1061da177e4SLinus Torvalds if (ret < 0) 1071da177e4SLinus Torvalds goto error_cache; 1081da177e4SLinus Torvalds #endif 1091da177e4SLinus Torvalds 1101da177e4SLinus Torvalds /* initialise the cell DB */ 1111da177e4SLinus Torvalds ret = afs_cell_init(rootcell); 1121da177e4SLinus Torvalds if (ret < 0) 113ec26815aSDavid Howells goto error_cell_init; 1141da177e4SLinus Torvalds 11508e0e7c8SDavid Howells /* initialise the VL update process */ 11608e0e7c8SDavid Howells ret = afs_vlocation_update_init(); 1171da177e4SLinus Torvalds if (ret < 0) 11808e0e7c8SDavid Howells goto error_vl_update_init; 1191da177e4SLinus Torvalds 12008e0e7c8SDavid Howells /* initialise the callback update process */ 12108e0e7c8SDavid Howells ret = afs_callback_update_init(); 122df44f9f4SDavid Howells if (ret < 0) 123df44f9f4SDavid Howells goto error_callback_update_init; 1241da177e4SLinus Torvalds 1251da177e4SLinus Torvalds /* create the RxRPC transport */ 12608e0e7c8SDavid Howells ret = afs_open_socket(); 1271da177e4SLinus Torvalds if (ret < 0) 12808e0e7c8SDavid Howells goto error_open_socket; 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds /* register the filesystems */ 1311da177e4SLinus Torvalds ret = afs_fs_init(); 1321da177e4SLinus Torvalds if (ret < 0) 133ec26815aSDavid Howells goto error_fs; 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds return ret; 1361da177e4SLinus Torvalds 137ec26815aSDavid Howells error_fs: 13808e0e7c8SDavid Howells afs_close_socket(); 13908e0e7c8SDavid Howells error_open_socket: 140df44f9f4SDavid Howells afs_callback_update_kill(); 141df44f9f4SDavid Howells error_callback_update_init: 142df44f9f4SDavid Howells afs_vlocation_purge(); 14308e0e7c8SDavid Howells error_vl_update_init: 144df44f9f4SDavid Howells afs_cell_purge(); 145ec26815aSDavid Howells error_cell_init: 1469b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 1479b3f26c9SDavid Howells fscache_unregister_netfs(&afs_cache_netfs); 148ec26815aSDavid Howells error_cache: 1491da177e4SLinus Torvalds #endif 1501da177e4SLinus Torvalds afs_proc_cleanup(); 1510ad53eeeSTejun Heo error_proc: 1520ad53eeeSTejun Heo destroy_workqueue(afs_wq); 153416351f2SDavid Howells rcu_barrier(); 1541da177e4SLinus Torvalds printk(KERN_ERR "kAFS: failed to register: %d\n", ret); 1551da177e4SLinus Torvalds return ret; 156ec26815aSDavid Howells } 1571da177e4SLinus Torvalds 1581da177e4SLinus Torvalds /* XXX late_initcall is kludgy, but the only alternative seems to create 1591da177e4SLinus Torvalds * a transport upon the first mount, which is worse. Or is it? 1601da177e4SLinus Torvalds */ 1611da177e4SLinus Torvalds late_initcall(afs_init); /* must be called after net/ to create socket */ 162ec26815aSDavid Howells 1631da177e4SLinus Torvalds /* 1641da177e4SLinus Torvalds * clean up on module removal 1651da177e4SLinus Torvalds */ 1661da177e4SLinus Torvalds static void __exit afs_exit(void) 1671da177e4SLinus Torvalds { 1681da177e4SLinus Torvalds printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n"); 1691da177e4SLinus Torvalds 1701da177e4SLinus Torvalds afs_fs_exit(); 171e8d6c554SDavid Howells afs_kill_lock_manager(); 17208e0e7c8SDavid Howells afs_close_socket(); 17308e0e7c8SDavid Howells afs_purge_servers(); 17408e0e7c8SDavid Howells afs_callback_update_kill(); 17508e0e7c8SDavid Howells afs_vlocation_purge(); 1760ad53eeeSTejun Heo destroy_workqueue(afs_wq); 1771da177e4SLinus Torvalds afs_cell_purge(); 1789b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 1799b3f26c9SDavid Howells fscache_unregister_netfs(&afs_cache_netfs); 1801da177e4SLinus Torvalds #endif 1811da177e4SLinus Torvalds afs_proc_cleanup(); 182416351f2SDavid Howells rcu_barrier(); 183ec26815aSDavid Howells } 1841da177e4SLinus Torvalds 1851da177e4SLinus Torvalds module_exit(afs_exit); 186