1693ad767SDavid van Moolenbroek /* VTreeFS - vtreefs.c - initialization and message loop */
2433d6423SLionel Sambuc
3433d6423SLionel Sambuc #include "inc.h"
4433d6423SLionel Sambuc
5433d6423SLionel Sambuc static unsigned int inodes;
6433d6423SLionel Sambuc static struct inode_stat *root_stat;
7433d6423SLionel Sambuc static index_t root_entries;
85eefd0feSDavid van Moolenbroek static size_t buf_size;
952be5c0aSDavid van Moolenbroek static size_t extra_size;
10433d6423SLionel Sambuc
11693ad767SDavid van Moolenbroek /*
125eefd0feSDavid van Moolenbroek * Initialize internal state. This is the only place where dynamic memory
135eefd0feSDavid van Moolenbroek * allocation takes place.
14433d6423SLionel Sambuc */
15693ad767SDavid van Moolenbroek static int
init_server(int __unused type,sef_init_info_t * __unused info)16693ad767SDavid van Moolenbroek init_server(int __unused type, sef_init_info_t * __unused info)
17693ad767SDavid van Moolenbroek {
185eefd0feSDavid van Moolenbroek int r;
19433d6423SLionel Sambuc
20433d6423SLionel Sambuc /* Initialize the virtual tree. */
215eefd0feSDavid van Moolenbroek if ((r = init_inodes(inodes, root_stat, root_entries)) != OK)
225eefd0feSDavid van Moolenbroek panic("init_inodes failed: %d", r);
235eefd0feSDavid van Moolenbroek
2452be5c0aSDavid van Moolenbroek /* Initialize extra data. */
2552be5c0aSDavid van Moolenbroek if ((r = init_extra(inodes, extra_size)) != OK)
2652be5c0aSDavid van Moolenbroek panic("init_extra failed: %d", r);
2752be5c0aSDavid van Moolenbroek
285eefd0feSDavid van Moolenbroek /* Initialize the I/O buffer. */
295eefd0feSDavid van Moolenbroek if ((r = init_buf(buf_size)) != OK)
305eefd0feSDavid van Moolenbroek panic("init_buf failed: %d", r);
31433d6423SLionel Sambuc
32433d6423SLionel Sambuc return OK;
33433d6423SLionel Sambuc }
34433d6423SLionel Sambuc
35693ad767SDavid van Moolenbroek /*
36693ad767SDavid van Moolenbroek * We received a signal.
370dc5c83eSDavid van Moolenbroek */
38693ad767SDavid van Moolenbroek static void
got_signal(int sig)39*7c48de6cSDavid van Moolenbroek got_signal(int sig)
40693ad767SDavid van Moolenbroek {
410dc5c83eSDavid van Moolenbroek
42*7c48de6cSDavid van Moolenbroek if (sig != SIGTERM)
430dc5c83eSDavid van Moolenbroek return;
440dc5c83eSDavid van Moolenbroek
450dc5c83eSDavid van Moolenbroek fsdriver_terminate();
460dc5c83eSDavid van Moolenbroek }
470dc5c83eSDavid van Moolenbroek
48693ad767SDavid van Moolenbroek /*
49693ad767SDavid van Moolenbroek * SEF initialization.
50693ad767SDavid van Moolenbroek */
51693ad767SDavid van Moolenbroek static void
sef_local_startup(void)52693ad767SDavid van Moolenbroek sef_local_startup(void)
53433d6423SLionel Sambuc {
54433d6423SLionel Sambuc sef_setcb_init_fresh(init_server);
553f82ac6aSCristiano Giuffrida sef_setcb_init_restart(SEF_CB_INIT_RESTART_STATEFUL);
56433d6423SLionel Sambuc
57433d6423SLionel Sambuc sef_setcb_signal_handler(got_signal);
58433d6423SLionel Sambuc
59433d6423SLionel Sambuc sef_startup();
60433d6423SLionel Sambuc }
61433d6423SLionel Sambuc
62693ad767SDavid van Moolenbroek /*
63693ad767SDavid van Moolenbroek * We have received a message that is not a file system request from VFS.
64693ad767SDavid van Moolenbroek * Call the message hook, if there is one.
650dc5c83eSDavid van Moolenbroek */
66693ad767SDavid van Moolenbroek void
fs_other(const message * m_ptr,int ipc_status)675eefd0feSDavid van Moolenbroek fs_other(const message * m_ptr, int ipc_status)
68693ad767SDavid van Moolenbroek {
690dc5c83eSDavid van Moolenbroek message msg;
700dc5c83eSDavid van Moolenbroek
710dc5c83eSDavid van Moolenbroek if (vtreefs_hooks->message_hook != NULL) {
72693ad767SDavid van Moolenbroek /*
73693ad767SDavid van Moolenbroek * Not all of vtreefs's users play nice with the message, so
740dc5c83eSDavid van Moolenbroek * make a copy to allow it to be modified.
750dc5c83eSDavid van Moolenbroek */
760dc5c83eSDavid van Moolenbroek msg = *m_ptr;
770dc5c83eSDavid van Moolenbroek
785eefd0feSDavid van Moolenbroek vtreefs_hooks->message_hook(&msg, ipc_status);
790dc5c83eSDavid van Moolenbroek }
800dc5c83eSDavid van Moolenbroek }
810dc5c83eSDavid van Moolenbroek
82693ad767SDavid van Moolenbroek /*
83693ad767SDavid van Moolenbroek * This is the main routine of this service. It uses the main loop as provided
84693ad767SDavid van Moolenbroek * by the fsdriver library. The routine returns once the file system has been
85693ad767SDavid van Moolenbroek * unmounted and the process is signaled to exit.
86693ad767SDavid van Moolenbroek */
87693ad767SDavid van Moolenbroek void
run_vtreefs(struct fs_hooks * hooks,unsigned int nr_inodes,size_t inode_extra,struct inode_stat * istat,index_t nr_indexed_entries,size_t bufsize)8852be5c0aSDavid van Moolenbroek run_vtreefs(struct fs_hooks * hooks, unsigned int nr_inodes,
89*7c48de6cSDavid van Moolenbroek size_t inode_extra, struct inode_stat * istat,
9052be5c0aSDavid van Moolenbroek index_t nr_indexed_entries, size_t bufsize)
91433d6423SLionel Sambuc {
92433d6423SLionel Sambuc
93693ad767SDavid van Moolenbroek /*
94693ad767SDavid van Moolenbroek * Use global variables to work around the inability to pass parameters
95433d6423SLionel Sambuc * through SEF to the initialization function..
96433d6423SLionel Sambuc */
97433d6423SLionel Sambuc vtreefs_hooks = hooks;
98433d6423SLionel Sambuc inodes = nr_inodes;
9952be5c0aSDavid van Moolenbroek extra_size = inode_extra;
100*7c48de6cSDavid van Moolenbroek root_stat = istat;
101433d6423SLionel Sambuc root_entries = nr_indexed_entries;
1025eefd0feSDavid van Moolenbroek buf_size = bufsize;
103433d6423SLionel Sambuc
104433d6423SLionel Sambuc sef_local_startup();
105433d6423SLionel Sambuc
1060dc5c83eSDavid van Moolenbroek fsdriver_task(&vtreefs_table);
107433d6423SLionel Sambuc
1085eefd0feSDavid van Moolenbroek cleanup_buf();
109433d6423SLionel Sambuc cleanup_inodes();
110433d6423SLionel Sambuc }
111