2009-12-20 21:41:50 +01:00
|
|
|
#include "fs.h"
|
|
|
|
#include <assert.h>
|
|
|
|
#include <minix/dmap.h>
|
|
|
|
#include <minix/endpoint.h>
|
|
|
|
#include <minix/vfsif.h>
|
|
|
|
#include "buf.h"
|
|
|
|
#include "inode.h"
|
|
|
|
#include "drivers.h"
|
|
|
|
|
|
|
|
FORWARD _PROTOTYPE(void init_server, (void) );
|
|
|
|
FORWARD _PROTOTYPE(void get_work, (message *m_in) );
|
|
|
|
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
/* SEF functions and variables. */
|
|
|
|
FORWARD _PROTOTYPE( void sef_local_startup, (void) );
|
|
|
|
|
2009-12-20 21:41:50 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* main *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
/* This is the main routine of this service. The main loop consists of
|
|
|
|
* three major activities: getting new work, processing the work, and
|
|
|
|
* sending the reply. The loop never terminates, unless a panic occurs.
|
|
|
|
*/
|
|
|
|
int error, ind;
|
|
|
|
message m;
|
|
|
|
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
/* SEF local startup. */
|
|
|
|
sef_local_startup();
|
|
|
|
|
2009-12-20 21:41:50 +01:00
|
|
|
/* Initialize the server, then go to work. */
|
|
|
|
init_server();
|
|
|
|
|
|
|
|
while(!exitsignaled || busy) {
|
|
|
|
endpoint_t src;
|
|
|
|
|
|
|
|
/* Wait for request message. */
|
|
|
|
get_work(&fs_m_in);
|
|
|
|
|
|
|
|
src = fs_m_in.m_source;
|
|
|
|
error = OK;
|
|
|
|
caller_uid = -1; /* To trap errors */
|
|
|
|
caller_gid = -1;
|
|
|
|
|
|
|
|
if (src == PM_PROC_NR) continue; /* Exit signal */
|
|
|
|
assert(src == VFS_PROC_NR); /* Otherwise this must be VFS talking */
|
|
|
|
req_nr = fs_m_in.m_type;
|
|
|
|
if (req_nr < VFS_BASE) {
|
|
|
|
fs_m_in.m_type += VFS_BASE;
|
|
|
|
req_nr = fs_m_in.m_type;
|
|
|
|
}
|
|
|
|
ind = req_nr - VFS_BASE;
|
|
|
|
|
|
|
|
if (ind < 0 || ind >= NREQS) {
|
2009-12-21 14:59:04 +01:00
|
|
|
printf("pfs: bad request %d\n", req_nr);
|
2009-12-20 21:41:50 +01:00
|
|
|
printf("ind = %d\n", ind);
|
|
|
|
error = EINVAL;
|
|
|
|
} else {
|
|
|
|
error = (*fs_call_vec[ind])();
|
|
|
|
}
|
|
|
|
|
|
|
|
fs_m_out.m_type = error;
|
|
|
|
reply(src, &fs_m_out);
|
|
|
|
|
|
|
|
}
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* sef_local_startup *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void sef_local_startup()
|
|
|
|
{
|
|
|
|
/* No live update support for now. */
|
|
|
|
|
|
|
|
/* Let SEF perform startup. */
|
|
|
|
sef_startup();
|
|
|
|
}
|
2009-12-20 21:41:50 +01:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* init_server *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void init_server(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Initialize main loop parameters. */
|
|
|
|
exitsignaled = 0; /* No exit request seen yet. */
|
|
|
|
busy = 0; /* Server is not 'busy' (i.e., inodes in use). */
|
|
|
|
|
|
|
|
/* Init inode table */
|
|
|
|
for (i = 0; i < NR_INODES; ++i) {
|
|
|
|
inode[i].i_count = 0;
|
|
|
|
cch[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
init_inode_cache();
|
|
|
|
|
|
|
|
/* Init driver mapping */
|
|
|
|
for (i = 0; i < NR_DEVICES; ++i)
|
|
|
|
driver_endpoints[i].driver_e = NONE;
|
|
|
|
|
|
|
|
SELF_E = getprocnr();
|
|
|
|
buf_pool();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* get_work *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void get_work(m_in)
|
|
|
|
message *m_in; /* pointer to message */
|
|
|
|
{
|
|
|
|
int r, srcok = 0;
|
|
|
|
endpoint_t src;
|
|
|
|
|
|
|
|
do {
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
if ((r = sef_receive(ANY, m_in)) != OK) /* wait for message */
|
|
|
|
panic("PFS","sef_receive failed", r);
|
2009-12-20 21:41:50 +01:00
|
|
|
src = fs_m_in.m_source;
|
|
|
|
|
|
|
|
if (src != VFS_PROC_NR) {
|
|
|
|
if(src == PM_PROC_NR) {
|
|
|
|
if(is_notify(fs_m_in.m_type)) {
|
|
|
|
exitsignaled = 1; /* Normal exit request. */
|
|
|
|
srcok = 1;
|
|
|
|
} else
|
|
|
|
printf("PFS: unexpected message from PM\n");
|
|
|
|
} else
|
|
|
|
printf("PFS: unexpected source %d\n", src);
|
|
|
|
} else if(src == VFS_PROC_NR) {
|
|
|
|
srcok = 1; /* Normal FS request. */
|
|
|
|
} else
|
|
|
|
printf("PFS: unexpected source %d\n", src);
|
|
|
|
} while(!srcok);
|
|
|
|
|
|
|
|
assert( src == VFS_PROC_NR ||
|
|
|
|
(src == PM_PROC_NR && is_notify(fs_m_in.m_type))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* reply *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void reply(who, m_out)
|
|
|
|
int who;
|
|
|
|
message *m_out; /* report result */
|
|
|
|
{
|
|
|
|
if (OK != send(who, m_out)) /* send the message */
|
|
|
|
printf("PFS(%d) was unable to send reply\n", SELF_E);
|
|
|
|
}
|
|
|
|
|