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> 17e0661dfcSDavid Howells #include <linux/random.h> 188e8d7f13SDavid Howells #define CREATE_TRACE_POINTS 191da177e4SLinus Torvalds #include "internal.h" 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds MODULE_DESCRIPTION("AFS Client File System"); 221da177e4SLinus Torvalds MODULE_AUTHOR("Red Hat, Inc."); 231da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 241da177e4SLinus Torvalds 2508e0e7c8SDavid Howells unsigned afs_debug; 2608e0e7c8SDavid Howells module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO); 27424b00e2SPaul Bolle MODULE_PARM_DESC(debug, "AFS debugging mask"); 2808e0e7c8SDavid Howells 291da177e4SLinus Torvalds static char *rootcell; 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds module_param(rootcell, charp, 0); 321da177e4SLinus Torvalds MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list"); 331da177e4SLinus Torvalds 34b908fe6bSDavid Howells struct afs_uuid afs_uuid; 350ad53eeeSTejun Heo struct workqueue_struct *afs_wq; 36b908fe6bSDavid Howells 37b908fe6bSDavid Howells /* 38b908fe6bSDavid Howells * get a client UUID 39b908fe6bSDavid Howells */ 40b908fe6bSDavid Howells static int __init afs_get_client_UUID(void) 41b908fe6bSDavid Howells { 42b908fe6bSDavid Howells struct timespec ts; 43b908fe6bSDavid Howells u64 uuidtime; 44b908fe6bSDavid Howells u16 clockseq; 45b908fe6bSDavid Howells int ret; 46b908fe6bSDavid Howells 47b908fe6bSDavid Howells /* read the MAC address of one of the external interfaces and construct 48b908fe6bSDavid Howells * a UUID from it */ 49ec9c9485SDavid Howells ret = afs_get_MAC_address(afs_uuid.node, sizeof(afs_uuid.node)); 50b908fe6bSDavid Howells if (ret < 0) 51b908fe6bSDavid Howells return ret; 52b908fe6bSDavid Howells 53b908fe6bSDavid Howells getnstimeofday(&ts); 54b908fe6bSDavid Howells uuidtime = (u64) ts.tv_sec * 1000 * 1000 * 10; 55b908fe6bSDavid Howells uuidtime += ts.tv_nsec / 100; 56b908fe6bSDavid Howells uuidtime += AFS_UUID_TO_UNIX_TIME; 57b908fe6bSDavid Howells afs_uuid.time_low = uuidtime; 58b908fe6bSDavid Howells afs_uuid.time_mid = uuidtime >> 32; 59b908fe6bSDavid Howells afs_uuid.time_hi_and_version = (uuidtime >> 48) & AFS_UUID_TIMEHI_MASK; 600ef13515SDavid Howells afs_uuid.time_hi_and_version |= AFS_UUID_VERSION_TIME; 61b908fe6bSDavid Howells 62b908fe6bSDavid Howells get_random_bytes(&clockseq, 2); 63b908fe6bSDavid Howells afs_uuid.clock_seq_low = clockseq; 64b908fe6bSDavid Howells afs_uuid.clock_seq_hi_and_reserved = 65b908fe6bSDavid Howells (clockseq >> 8) & AFS_UUID_CLOCKHI_MASK; 660ef13515SDavid Howells afs_uuid.clock_seq_hi_and_reserved |= AFS_UUID_VARIANT_STD; 67b908fe6bSDavid Howells 68b908fe6bSDavid Howells _debug("AFS UUID: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", 69b908fe6bSDavid Howells afs_uuid.time_low, 70b908fe6bSDavid Howells afs_uuid.time_mid, 71b908fe6bSDavid Howells afs_uuid.time_hi_and_version, 72b908fe6bSDavid Howells afs_uuid.clock_seq_hi_and_reserved, 73b908fe6bSDavid Howells afs_uuid.clock_seq_low, 74b908fe6bSDavid Howells afs_uuid.node[0], afs_uuid.node[1], afs_uuid.node[2], 75b908fe6bSDavid Howells afs_uuid.node[3], afs_uuid.node[4], afs_uuid.node[5]); 76b908fe6bSDavid Howells 77b908fe6bSDavid Howells return 0; 78b908fe6bSDavid Howells } 79b908fe6bSDavid Howells 801da177e4SLinus Torvalds /* 811da177e4SLinus Torvalds * initialise the AFS client FS module 821da177e4SLinus Torvalds */ 831da177e4SLinus Torvalds static int __init afs_init(void) 841da177e4SLinus Torvalds { 8508e0e7c8SDavid Howells int ret; 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n"); 881da177e4SLinus Torvalds 89b908fe6bSDavid Howells ret = afs_get_client_UUID(); 90b908fe6bSDavid Howells if (ret < 0) 91b908fe6bSDavid Howells return ret; 92b908fe6bSDavid Howells 930ad53eeeSTejun Heo /* create workqueue */ 940ad53eeeSTejun Heo ret = -ENOMEM; 950ad53eeeSTejun Heo afs_wq = alloc_workqueue("afs", 0, 0); 960ad53eeeSTejun Heo if (!afs_wq) 970ad53eeeSTejun Heo return ret; 980ad53eeeSTejun Heo 991da177e4SLinus Torvalds /* register the /proc stuff */ 1001da177e4SLinus Torvalds ret = afs_proc_init(); 1011da177e4SLinus Torvalds if (ret < 0) 1020ad53eeeSTejun Heo goto error_proc; 1031da177e4SLinus Torvalds 1049b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 1051da177e4SLinus Torvalds /* we want to be able to cache */ 1069b3f26c9SDavid Howells ret = fscache_register_netfs(&afs_cache_netfs); 1071da177e4SLinus Torvalds if (ret < 0) 1081da177e4SLinus Torvalds goto error_cache; 1091da177e4SLinus Torvalds #endif 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds /* initialise the cell DB */ 1121da177e4SLinus Torvalds ret = afs_cell_init(rootcell); 1131da177e4SLinus Torvalds if (ret < 0) 114ec26815aSDavid Howells goto error_cell_init; 1151da177e4SLinus Torvalds 11608e0e7c8SDavid Howells /* initialise the VL update process */ 11708e0e7c8SDavid Howells ret = afs_vlocation_update_init(); 1181da177e4SLinus Torvalds if (ret < 0) 11908e0e7c8SDavid Howells goto error_vl_update_init; 1201da177e4SLinus Torvalds 12108e0e7c8SDavid Howells /* initialise the callback update process */ 12208e0e7c8SDavid Howells ret = afs_callback_update_init(); 123df44f9f4SDavid Howells if (ret < 0) 124df44f9f4SDavid Howells goto error_callback_update_init; 1251da177e4SLinus Torvalds 1261da177e4SLinus Torvalds /* create the RxRPC transport */ 12708e0e7c8SDavid Howells ret = afs_open_socket(); 1281da177e4SLinus Torvalds if (ret < 0) 12908e0e7c8SDavid Howells goto error_open_socket; 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds /* register the filesystems */ 1321da177e4SLinus Torvalds ret = afs_fs_init(); 1331da177e4SLinus Torvalds if (ret < 0) 134ec26815aSDavid Howells goto error_fs; 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds return ret; 1371da177e4SLinus Torvalds 138ec26815aSDavid Howells error_fs: 13908e0e7c8SDavid Howells afs_close_socket(); 14008e0e7c8SDavid Howells error_open_socket: 141df44f9f4SDavid Howells afs_callback_update_kill(); 142df44f9f4SDavid Howells error_callback_update_init: 143df44f9f4SDavid Howells afs_vlocation_purge(); 14408e0e7c8SDavid Howells error_vl_update_init: 145df44f9f4SDavid Howells afs_cell_purge(); 146ec26815aSDavid Howells error_cell_init: 1479b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 1489b3f26c9SDavid Howells fscache_unregister_netfs(&afs_cache_netfs); 149ec26815aSDavid Howells error_cache: 1501da177e4SLinus Torvalds #endif 1511da177e4SLinus Torvalds afs_proc_cleanup(); 1520ad53eeeSTejun Heo error_proc: 1530ad53eeeSTejun Heo destroy_workqueue(afs_wq); 154416351f2SDavid Howells rcu_barrier(); 1551da177e4SLinus Torvalds printk(KERN_ERR "kAFS: failed to register: %d\n", ret); 1561da177e4SLinus Torvalds return ret; 157ec26815aSDavid Howells } 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvalds /* XXX late_initcall is kludgy, but the only alternative seems to create 1601da177e4SLinus Torvalds * a transport upon the first mount, which is worse. Or is it? 1611da177e4SLinus Torvalds */ 1621da177e4SLinus Torvalds late_initcall(afs_init); /* must be called after net/ to create socket */ 163ec26815aSDavid Howells 1641da177e4SLinus Torvalds /* 1651da177e4SLinus Torvalds * clean up on module removal 1661da177e4SLinus Torvalds */ 1671da177e4SLinus Torvalds static void __exit afs_exit(void) 1681da177e4SLinus Torvalds { 1691da177e4SLinus Torvalds printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n"); 1701da177e4SLinus Torvalds 1711da177e4SLinus Torvalds afs_fs_exit(); 172e8d6c554SDavid Howells afs_kill_lock_manager(); 17308e0e7c8SDavid Howells afs_close_socket(); 17408e0e7c8SDavid Howells afs_purge_servers(); 17508e0e7c8SDavid Howells afs_callback_update_kill(); 17608e0e7c8SDavid Howells afs_vlocation_purge(); 1770ad53eeeSTejun Heo destroy_workqueue(afs_wq); 1781da177e4SLinus Torvalds afs_cell_purge(); 1799b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 1809b3f26c9SDavid Howells fscache_unregister_netfs(&afs_cache_netfs); 1811da177e4SLinus Torvalds #endif 1821da177e4SLinus Torvalds afs_proc_cleanup(); 183416351f2SDavid Howells rcu_barrier(); 184ec26815aSDavid Howells } 1851da177e4SLinus Torvalds 1861da177e4SLinus Torvalds module_exit(afs_exit); 187