1433d6423SLionel Sambuc #include "fs.h"
2433d6423SLionel Sambuc #include "buf.h"
3433d6423SLionel Sambuc #include "inode.h"
4433d6423SLionel Sambuc
5433d6423SLionel Sambuc
6433d6423SLionel Sambuc /* SEF functions and variables. */
7433d6423SLionel Sambuc static void sef_local_startup(void);
8433d6423SLionel Sambuc static int sef_cb_init_fresh(int type, sef_init_info_t *info);
9433d6423SLionel Sambuc static void sef_cb_signal_handler(int signo);
10433d6423SLionel Sambuc
11433d6423SLionel Sambuc /*===========================================================================*
12433d6423SLionel Sambuc * main *
13433d6423SLionel Sambuc *===========================================================================*/
main(int argc,char * argv[])14433d6423SLionel Sambuc int main(int argc, char *argv[])
15433d6423SLionel Sambuc {
16ccaeedb2SDavid van Moolenbroek /* This is the main routine of this service. */
17433d6423SLionel Sambuc
18433d6423SLionel Sambuc /* SEF local startup. */
19433d6423SLionel Sambuc env_setargs(argc, argv);
20433d6423SLionel Sambuc sef_local_startup();
21433d6423SLionel Sambuc
22ccaeedb2SDavid van Moolenbroek /* The fsdriver library does the actual work here. */
23ccaeedb2SDavid van Moolenbroek fsdriver_task(&mfs_table);
24433d6423SLionel Sambuc
25ccaeedb2SDavid van Moolenbroek return(0);
26433d6423SLionel Sambuc }
27433d6423SLionel Sambuc
28433d6423SLionel Sambuc /*===========================================================================*
29433d6423SLionel Sambuc * sef_local_startup *
30433d6423SLionel Sambuc *===========================================================================*/
sef_local_startup()31433d6423SLionel Sambuc static void sef_local_startup()
32433d6423SLionel Sambuc {
33433d6423SLionel Sambuc /* Register init callbacks. */
34433d6423SLionel Sambuc sef_setcb_init_fresh(sef_cb_init_fresh);
35*3f82ac6aSCristiano Giuffrida sef_setcb_init_restart(SEF_CB_INIT_RESTART_STATEFUL);
36433d6423SLionel Sambuc
37433d6423SLionel Sambuc /* Register signal callbacks. */
38433d6423SLionel Sambuc sef_setcb_signal_handler(sef_cb_signal_handler);
39433d6423SLionel Sambuc
40433d6423SLionel Sambuc /* Let SEF perform startup. */
41433d6423SLionel Sambuc sef_startup();
42433d6423SLionel Sambuc }
43433d6423SLionel Sambuc
44433d6423SLionel Sambuc /*===========================================================================*
45433d6423SLionel Sambuc * sef_cb_init_fresh *
46433d6423SLionel Sambuc *===========================================================================*/
sef_cb_init_fresh(int UNUSED (type),sef_init_info_t * UNUSED (info))47433d6423SLionel Sambuc static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
48433d6423SLionel Sambuc {
49433d6423SLionel Sambuc /* Initialize the Minix file server. */
50433d6423SLionel Sambuc int i;
51433d6423SLionel Sambuc
52433d6423SLionel Sambuc lmfs_may_use_vmcache(1);
53433d6423SLionel Sambuc
54433d6423SLionel Sambuc /* Init inode table */
55433d6423SLionel Sambuc for (i = 0; i < NR_INODES; ++i) {
56433d6423SLionel Sambuc inode[i].i_count = 0;
57433d6423SLionel Sambuc cch[i] = 0;
58433d6423SLionel Sambuc }
59433d6423SLionel Sambuc
60433d6423SLionel Sambuc init_inode_cache();
61433d6423SLionel Sambuc
62433d6423SLionel Sambuc lmfs_buf_pool(DEFAULT_NR_BUFS);
63433d6423SLionel Sambuc
64433d6423SLionel Sambuc return(OK);
65433d6423SLionel Sambuc }
66433d6423SLionel Sambuc
67433d6423SLionel Sambuc /*===========================================================================*
68433d6423SLionel Sambuc * sef_cb_signal_handler *
69433d6423SLionel Sambuc *===========================================================================*/
sef_cb_signal_handler(int signo)70433d6423SLionel Sambuc static void sef_cb_signal_handler(int signo)
71433d6423SLionel Sambuc {
72433d6423SLionel Sambuc /* Only check for termination signal, ignore anything else. */
73433d6423SLionel Sambuc if (signo != SIGTERM) return;
74433d6423SLionel Sambuc
75ccaeedb2SDavid van Moolenbroek fs_sync();
76433d6423SLionel Sambuc
77ccaeedb2SDavid van Moolenbroek fsdriver_terminate();
78433d6423SLionel Sambuc }
79433d6423SLionel Sambuc
80433d6423SLionel Sambuc
81433d6423SLionel Sambuc #if 0
82433d6423SLionel Sambuc /*===========================================================================*
83433d6423SLionel Sambuc * cch_check *
84433d6423SLionel Sambuc *===========================================================================*/
85433d6423SLionel Sambuc static void cch_check(void)
86433d6423SLionel Sambuc {
87433d6423SLionel Sambuc int i;
88433d6423SLionel Sambuc
89433d6423SLionel Sambuc for (i = 0; i < NR_INODES; ++i) {
90433d6423SLionel Sambuc if (inode[i].i_count != cch[i] && req_nr != REQ_GETNODE &&
91433d6423SLionel Sambuc req_nr != REQ_PUTNODE && req_nr != REQ_READSUPER &&
92433d6423SLionel Sambuc req_nr != REQ_MOUNTPOINT && req_nr != REQ_UNMOUNT &&
93433d6423SLionel Sambuc req_nr != REQ_SYNC && req_nr != REQ_LOOKUP) {
94433d6423SLionel Sambuc printf("MFS(%d) inode(%lu) cc: %d req_nr: %d\n", sef_self(),
95433d6423SLionel Sambuc inode[i].i_num, inode[i].i_count - cch[i], req_nr);
96433d6423SLionel Sambuc }
97433d6423SLionel Sambuc
98433d6423SLionel Sambuc cch[i] = inode[i].i_count;
99433d6423SLionel Sambuc }
100433d6423SLionel Sambuc }
101433d6423SLionel Sambuc #endif
102433d6423SLionel Sambuc
103