1 /* VTreeFS - vtreefs.c - initialization and message loop */ 2 3 #include "inc.h" 4 5 static unsigned int inodes; 6 static struct inode_stat *root_stat; 7 static index_t root_entries; 8 static size_t buf_size; 9 static size_t extra_size; 10 11 /* 12 * Initialize internal state. This is the only place where dynamic memory 13 * allocation takes place. 14 */ 15 static int 16 init_server(int __unused type, sef_init_info_t * __unused info) 17 { 18 int r; 19 20 /* Initialize the virtual tree. */ 21 if ((r = init_inodes(inodes, root_stat, root_entries)) != OK) 22 panic("init_inodes failed: %d", r); 23 24 /* Initialize extra data. */ 25 if ((r = init_extra(inodes, extra_size)) != OK) 26 panic("init_extra failed: %d", r); 27 28 /* Initialize the I/O buffer. */ 29 if ((r = init_buf(buf_size)) != OK) 30 panic("init_buf failed: %d", r); 31 32 return OK; 33 } 34 35 /* 36 * We received a signal. 37 */ 38 static void 39 got_signal(int signal) 40 { 41 42 if (signal != SIGTERM) 43 return; 44 45 fsdriver_terminate(); 46 } 47 48 /* 49 * SEF initialization. 50 */ 51 static void 52 sef_local_startup(void) 53 { 54 55 sef_setcb_init_fresh(init_server); 56 sef_setcb_init_restart(init_server); 57 58 sef_setcb_signal_handler(got_signal); 59 60 /* No support for live update yet. */ 61 62 sef_startup(); 63 } 64 65 /* 66 * We have received a message that is not a file system request from VFS. 67 * Call the message hook, if there is one. 68 */ 69 void 70 fs_other(const message * m_ptr, int ipc_status) 71 { 72 message msg; 73 74 if (vtreefs_hooks->message_hook != NULL) { 75 /* 76 * Not all of vtreefs's users play nice with the message, so 77 * make a copy to allow it to be modified. 78 */ 79 msg = *m_ptr; 80 81 vtreefs_hooks->message_hook(&msg, ipc_status); 82 } 83 } 84 85 /* 86 * This is the main routine of this service. It uses the main loop as provided 87 * by the fsdriver library. The routine returns once the file system has been 88 * unmounted and the process is signaled to exit. 89 */ 90 void 91 run_vtreefs(struct fs_hooks * hooks, unsigned int nr_inodes, 92 size_t inode_extra, struct inode_stat * stat, 93 index_t nr_indexed_entries, size_t bufsize) 94 { 95 96 /* 97 * Use global variables to work around the inability to pass parameters 98 * through SEF to the initialization function.. 99 */ 100 vtreefs_hooks = hooks; 101 inodes = nr_inodes; 102 extra_size = inode_extra; 103 root_stat = stat; 104 root_entries = nr_indexed_entries; 105 buf_size = bufsize; 106 107 sef_local_startup(); 108 109 fsdriver_task(&vtreefs_table); 110 111 cleanup_buf(); 112 cleanup_inodes(); 113 } 114