3 #include <minix/callnr.h>
7 #include <minix/dmap.h>
8 #include <minix/endpoint.h>
9 #include <minix/vfsif.h>
14 /* Declare some local functions. */
15 static void get_work(message
*m_in
);
16 static void reply(endpoint_t who
, message
*m_out
);
18 /* SEF functions and variables. */
19 static void sef_local_startup(void);
20 static int sef_cb_init_fresh(int type
, sef_init_info_t
*info
);
21 static void sef_cb_signal_handler(int signo
);
23 /*===========================================================================*
25 *===========================================================================*/
26 int main(int argc
, char *argv
[])
28 /* This is the main routine of this service. The main loop consists of
29 * three major activities: getting new work, processing the work, and
30 * sending the reply. The loop never terminates, unless a panic occurs.
32 int error
= OK
, ind
, transid
;
34 /* SEF local startup. */
35 env_setargs(argc
, argv
);
38 while(!unmountdone
|| !exitsignaled
) {
41 /* Wait for request message. */
44 transid
= TRNS_GET_ID(fs_m_in
.m_type
);
45 fs_m_in
.m_type
= TRNS_DEL_ID(fs_m_in
.m_type
);
46 if (fs_m_in
.m_type
== 0) {
47 assert(!IS_VFS_FS_TRANSID(transid
));
48 fs_m_in
.m_type
= transid
; /* Backwards compat. */
51 assert(IS_VFS_FS_TRANSID(transid
));
53 src
= fs_m_in
.m_source
;
54 caller_uid
= INVAL_UID
; /* To trap errors */
55 caller_gid
= INVAL_GID
;
56 req_nr
= fs_m_in
.m_type
;
58 if (req_nr
< VFS_BASE
) {
59 fs_m_in
.m_type
+= VFS_BASE
;
60 req_nr
= fs_m_in
.m_type
;
62 ind
= req_nr
- VFS_BASE
;
64 if (ind
< 0 || ind
>= NREQS
) {
65 printf("MFS: bad request %d from %d\n", req_nr
, src
);
66 printf("ind = %d\n", ind
);
69 error
= (*fs_call_vec
[ind
])();
73 fs_m_out
.m_type
= error
;
74 if (IS_VFS_FS_TRANSID(transid
)) {
75 /* If a transaction ID was set, reset it */
76 fs_m_out
.m_type
= TRNS_ADD_ID(fs_m_out
.m_type
, transid
);
78 reply(src
, &fs_m_out
);
84 /*===========================================================================*
86 *===========================================================================*/
87 static void sef_local_startup()
89 /* Register init callbacks. */
90 sef_setcb_init_fresh(sef_cb_init_fresh
);
91 sef_setcb_init_restart(sef_cb_init_fail
);
93 /* No live update support for now. */
95 /* Register signal callbacks. */
96 sef_setcb_signal_handler(sef_cb_signal_handler
);
98 /* Let SEF perform startup. */
102 /*===========================================================================*
103 * sef_cb_init_fresh *
104 *===========================================================================*/
105 static int sef_cb_init_fresh(int UNUSED(type
), sef_init_info_t
*UNUSED(info
))
107 /* Initialize the Minix file server. */
110 lmfs_may_use_vmcache(1);
112 /* Init inode table */
113 for (i
= 0; i
< NR_INODES
; ++i
) {
114 inode
[i
].i_count
= 0;
120 SELF_E
= getprocnr();
121 lmfs_buf_pool(DEFAULT_NR_BUFS
);
126 /*===========================================================================*
127 * sef_cb_signal_handler *
128 *===========================================================================*/
129 static void sef_cb_signal_handler(int signo
)
131 /* Only check for termination signal, ignore anything else. */
132 if (signo
!= SIGTERM
) return;
137 /* If unmounting has already been performed, exit immediately.
138 * We might not get another message.
140 if (unmountdone
) exit(0);
143 /*===========================================================================*
145 *===========================================================================*/
146 static void get_work(m_in
)
147 message
*m_in
; /* pointer to message */
153 if ((r
= sef_receive(ANY
, m_in
)) != OK
) /* wait for message */
154 panic("sef_receive failed: %d", r
);
155 src
= m_in
->m_source
;
157 if(src
== VFS_PROC_NR
) {
159 printf("MFS: unmounted: unexpected message from FS\n");
161 srcok
= 1; /* Normal FS request. */
164 printf("MFS: unexpected source %d\n", src
);
167 assert((src
== VFS_PROC_NR
&& !unmountdone
));
171 /*===========================================================================*
173 *===========================================================================*/
176 message
*m_out
/* report result */
179 if (OK
!= send(who
, m_out
)) /* send the message */
180 printf("MFS(%d) was unable to send reply\n", SELF_E
);
185 /*===========================================================================*
187 *===========================================================================*/
188 static void cch_check(void)
192 for (i
= 0; i
< NR_INODES
; ++i
) {
193 if (inode
[i
].i_count
!= cch
[i
] && req_nr
!= REQ_GETNODE
&&
194 req_nr
!= REQ_PUTNODE
&& req_nr
!= REQ_READSUPER
&&
195 req_nr
!= REQ_MOUNTPOINT
&& req_nr
!= REQ_UNMOUNT
&&
196 req_nr
!= REQ_SYNC
&& req_nr
!= REQ_LOOKUP
) {
197 printf("MFS(%d) inode(%lu) cc: %d req_nr: %d\n", SELF_E
,
198 inode
[i
].i_num
, inode
[i
].i_count
- cch
[i
], req_nr
);
201 cch
[i
] = inode
[i
].i_count
;