New RS and new signal handling for system processes.
UPDATING INFO:
20100317:
/usr/src/etc/system.conf updated to ignore default kernel calls: copy
it (or merge it) to /etc/system.conf.
The hello driver (/dev/hello) added to the distribution:
# cd /usr/src/commands/scripts && make clean install
# cd /dev && MAKEDEV hello
KERNEL CHANGES:
- Generic signal handling support. The kernel no longer assumes PM as a signal
manager for every process. The signal manager of a given process can now be
specified in its privilege slot. When a signal has to be delivered, the kernel
performs the lookup and forwards the signal to the appropriate signal manager.
PM is the default signal manager for user processes, RS is the default signal
manager for system processes. To enable ptrace()ing for system processes, it
is sufficient to change the default signal manager to PM. This will temporarily
disable crash recovery, though.
- sys_exit() is now split into sys_exit() (i.e. exit() for system processes,
which generates a self-termination signal), and sys_clear() (i.e. used by PM
to ask the kernel to clear a process slot when a process exits).
- Added a new kernel call (i.e. sys_update()) to swap two process slots and
implement live update.
PM CHANGES:
- Posix signal handling is no longer allowed for system processes. System
signals are split into two fixed categories: termination and non-termination
signals. When a non-termination signaled is processed, PM transforms the signal
into an IPC message and delivers the message to the system process. When a
termination signal is processed, PM terminates the process.
- PM no longer assumes itself as the signal manager for system processes. It now
makes sure that every system signal goes through the kernel before being
actually processes. The kernel will then dispatch the signal to the appropriate
signal manager which may or may not be PM.
SYSLIB CHANGES:
- Simplified SEF init and LU callbacks.
- Added additional predefined SEF callbacks to debug crash recovery and
live update.
- Fixed a temporary ack in the SEF init protocol. SEF init reply is now
completely synchronous.
- Added SEF signal event type to provide a uniform interface for system
processes to deal with signals. A sef_cb_signal_handler() callback is
available for system processes to handle every received signal. A
sef_cb_signal_manager() callback is used by signal managers to process
system signals on behalf of the kernel.
- Fixed a few bugs with memory mapping and DS.
VM CHANGES:
- Page faults and memory requests coming from the kernel are now implemented
using signals.
- Added a new VM call to swap two process slots and implement live update.
- The call is used by RS at update time and in turn invokes the kernel call
sys_update().
RS CHANGES:
- RS has been reworked with a better functional decomposition.
- Better kernel call masks. com.h now defines the set of very basic kernel calls
every system service is allowed to use. This makes system.conf simpler and
easier to maintain. In addition, this guarantees a higher level of isolation
for system libraries that use one or more kernel calls internally (e.g. printf).
- RS is the default signal manager for system processes. By default, RS
intercepts every signal delivered to every system process. This makes crash
recovery possible before bringing PM and friends in the loop.
- RS now supports fast rollback when something goes wrong while initializing
the new version during a live update.
- Live update is now implemented by keeping the two versions side-by-side and
swapping the process slots when the old version is ready to update.
- Crash recovery is now implemented by keeping the two versions side-by-side
and cleaning up the old version only when the recovery process is complete.
DS CHANGES:
- Fixed a bug when the process doing ds_publish() or ds_delete() is not known
by DS.
- Fixed the completely broken support for strings. String publishing is now
implemented in the system library and simply wraps publishing of memory ranges.
Ideally, we should adopt a similar approach for other data types as well.
- Test suite fixed.
DRIVER CHANGES:
- The hello driver has been added to the Minix distribution to demonstrate basic
live update and crash recovery functionalities.
- Other drivers have been adapted to conform the new SEF interface.
This commit is contained in:
@@ -48,7 +48,7 @@ const char *_sys_errlist[] = {
|
||||
"Function not implemented", /* ENOSYS */
|
||||
"Directory not empty", /* ENOTEMPTY */
|
||||
"Too many levels of symbolic links", /* ELOOP */
|
||||
"Driver restarted", /* ERESTART */
|
||||
"Service restarted", /* ERESTART */
|
||||
unknown, /* 42 */
|
||||
"Identifier removed", /* EIDRM */
|
||||
"Illegal byte sequence", /* EILSEQ */
|
||||
|
||||
@@ -33,6 +33,7 @@ SRCS+= \
|
||||
_sysuname.c \
|
||||
_vm_dmacalls.c \
|
||||
_vm_set_priv.c \
|
||||
_vm_update.c \
|
||||
_vm_query_exit.c \
|
||||
asynchio.c \
|
||||
basename.c \
|
||||
|
||||
12
lib/libc/other/_vm_update.c
Normal file
12
lib/libc/other/_vm_update.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <lib.h>
|
||||
#define vm_update _vm_update
|
||||
#include <unistd.h>
|
||||
|
||||
PUBLIC int vm_update(endpoint_t src_e, endpoint_t dst_e)
|
||||
{
|
||||
message m;
|
||||
m.VM_RS_SRC_ENDPT = src_e;
|
||||
m.VM_RS_DST_ENDPT = dst_e;
|
||||
|
||||
return _syscall(VM_PROC_NR, VM_RS_UPDATE, &m);
|
||||
}
|
||||
@@ -74,6 +74,7 @@ SRCS+= \
|
||||
vm_remap.S \
|
||||
vm_unmap.S \
|
||||
vm_set_priv.S \
|
||||
vm_update.S \
|
||||
vm_query_exit.S \
|
||||
mount.S \
|
||||
nanosleep.S \
|
||||
|
||||
7
lib/libc/syscall/vm_update.S
Normal file
7
lib/libc/syscall/vm_update.S
Normal file
@@ -0,0 +1,7 @@
|
||||
.text
|
||||
.extern __vm_update
|
||||
.globl _vm_update
|
||||
.balign 2
|
||||
|
||||
_vm_update:
|
||||
jmp __vm_update
|
||||
@@ -29,10 +29,12 @@ SRCS= \
|
||||
pci_slot_name.c \
|
||||
safecopies.c \
|
||||
sef.c \
|
||||
sef_init.c \
|
||||
sef_liveupdate.c \
|
||||
sef_ping.c \
|
||||
sef_init.c \
|
||||
sef_signal.c \
|
||||
sys_abort.c \
|
||||
sys_clear.c \
|
||||
sys_mcontext.c \
|
||||
sys_cprof.c \
|
||||
sys_endsig.c \
|
||||
@@ -53,6 +55,7 @@ SRCS= \
|
||||
sys_physcopy.c \
|
||||
sys_readbios.c \
|
||||
sys_runctl.c \
|
||||
sys_update.c \
|
||||
sys_safecopy.c \
|
||||
sys_safemap.c \
|
||||
sys_sysctl.c \
|
||||
|
||||
@@ -49,16 +49,8 @@ int ds_publish_u32(const char *ds_name, u32_t value, int flags)
|
||||
return do_invoke_ds(DS_PUBLISH, ds_name);
|
||||
}
|
||||
|
||||
int ds_publish_str(const char *ds_name, char *value, int flags)
|
||||
{
|
||||
if(strlen(value) >= DS_MAX_STRLEN)
|
||||
return EINVAL;
|
||||
strcpy((char *)(&m.DS_STRING), value);
|
||||
m.DS_FLAGS = DSF_TYPE_STR | flags;
|
||||
return do_invoke_ds(DS_PUBLISH, ds_name);
|
||||
}
|
||||
|
||||
int ds_publish_mem(const char *ds_name, void *vaddr, size_t length, int flags)
|
||||
static int ds_publish_raw(const char *ds_name, void *vaddr, size_t length,
|
||||
int flags)
|
||||
{
|
||||
cp_grant_id_t gid;
|
||||
int r;
|
||||
@@ -70,7 +62,7 @@ int ds_publish_mem(const char *ds_name, void *vaddr, size_t length, int flags)
|
||||
|
||||
m.DS_VAL = gid;
|
||||
m.DS_VAL_LEN = length;
|
||||
m.DS_FLAGS = DSF_TYPE_MEM | flags;
|
||||
m.DS_FLAGS = flags;
|
||||
|
||||
r = do_invoke_ds(DS_PUBLISH, ds_name);
|
||||
cpf_revoke(gid);
|
||||
@@ -78,6 +70,19 @@ int ds_publish_mem(const char *ds_name, void *vaddr, size_t length, int flags)
|
||||
return r;
|
||||
}
|
||||
|
||||
int ds_publish_str(const char *ds_name, char *value, int flags)
|
||||
{
|
||||
size_t length;
|
||||
length = strlen(value) + 1;
|
||||
value[length - 1] = '\0';
|
||||
return ds_publish_raw(ds_name, value, length, flags | DSF_TYPE_STR);
|
||||
}
|
||||
|
||||
int ds_publish_mem(const char *ds_name, void *vaddr, size_t length, int flags)
|
||||
{
|
||||
return ds_publish_raw(ds_name, vaddr, length, flags | DSF_TYPE_MEM);
|
||||
}
|
||||
|
||||
int ds_publish_map(const char *ds_name, void *vaddr, size_t length, int flags)
|
||||
{
|
||||
cp_grant_id_t gid;
|
||||
@@ -97,7 +102,6 @@ int ds_publish_map(const char *ds_name, void *vaddr, size_t length, int flags)
|
||||
m.DS_FLAGS = DSF_TYPE_MAP | flags;
|
||||
|
||||
r = do_invoke_ds(DS_PUBLISH, ds_name);
|
||||
cpf_revoke(gid);
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -136,17 +140,8 @@ int ds_retrieve_u32(const char *ds_name, u32_t *value)
|
||||
return r;
|
||||
}
|
||||
|
||||
int ds_retrieve_str(const char *ds_name, char *value, size_t len_str)
|
||||
{
|
||||
int r;
|
||||
m.DS_FLAGS = DSF_TYPE_STR;
|
||||
r = do_invoke_ds(DS_RETRIEVE, ds_name);
|
||||
strncpy(value, (char *)(&m.DS_STRING), DS_MAX_STRLEN);
|
||||
value[DS_MAX_STRLEN - 1] = '\0';
|
||||
return r;
|
||||
}
|
||||
|
||||
int ds_retrieve_mem(const char *ds_name, char *vaddr, size_t *length)
|
||||
static int ds_retrieve_raw(const char *ds_name, char *vaddr, size_t *length,
|
||||
int flags)
|
||||
{
|
||||
cp_grant_id_t gid;
|
||||
int r;
|
||||
@@ -158,7 +153,7 @@ int ds_retrieve_mem(const char *ds_name, char *vaddr, size_t *length)
|
||||
|
||||
m.DS_VAL = gid;
|
||||
m.DS_VAL_LEN = *length;
|
||||
m.DS_FLAGS = DSF_TYPE_MEM;
|
||||
m.DS_FLAGS = flags;
|
||||
r = do_invoke_ds(DS_RETRIEVE, ds_name);
|
||||
*length = m.DS_VAL_LEN;
|
||||
cpf_revoke(gid);
|
||||
@@ -166,6 +161,20 @@ int ds_retrieve_mem(const char *ds_name, char *vaddr, size_t *length)
|
||||
return r;
|
||||
}
|
||||
|
||||
int ds_retrieve_str(const char *ds_name, char *value, size_t len_str)
|
||||
{
|
||||
int r;
|
||||
size_t length = len_str + 1;
|
||||
r = ds_retrieve_raw(ds_name, value, &length, DSF_TYPE_STR);
|
||||
value[length - 1] = '\0';
|
||||
return r;
|
||||
}
|
||||
|
||||
int ds_retrieve_mem(const char *ds_name, char *vaddr, size_t *length)
|
||||
{
|
||||
return ds_retrieve_raw(ds_name, vaddr, length, DSF_TYPE_MEM);
|
||||
}
|
||||
|
||||
int ds_retrieve_map(const char *ds_name, char *vaddr, size_t *length,
|
||||
int nr_snapshot, int flags)
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
/* Self variables. */
|
||||
#define SEF_SELF_NAME_MAXLEN 20
|
||||
PRIVATE char sef_self_name[SEF_SELF_NAME_MAXLEN];
|
||||
PRIVATE endpoint_t sef_self_endpoint;
|
||||
PUBLIC char sef_self_name[SEF_SELF_NAME_MAXLEN];
|
||||
PUBLIC endpoint_t sef_self_endpoint;
|
||||
|
||||
/* Debug. */
|
||||
#define SEF_DEBUG_HEADER_MAXLEN 32
|
||||
@@ -22,19 +22,22 @@ PUBLIC _PROTOTYPE( char* sef_debug_header, (void) );
|
||||
EXTERN _PROTOTYPE( int do_sef_rs_init, (void) );
|
||||
EXTERN _PROTOTYPE( int do_sef_init_request, (message *m_ptr) );
|
||||
|
||||
/* SEF Ping prototypes. */
|
||||
EXTERN _PROTOTYPE( int do_sef_ping_request, (message *m_ptr) );
|
||||
|
||||
/* SEF Live update prototypes. */
|
||||
EXTERN _PROTOTYPE( void do_sef_lu_before_receive, (void) );
|
||||
EXTERN _PROTOTYPE( int do_sef_lu_request, (message *m_ptr) );
|
||||
|
||||
/* SEF Ping prototypes. */
|
||||
EXTERN _PROTOTYPE( int do_sef_ping_request, (message *m_ptr) );
|
||||
/* SEF Signal prototypes. */
|
||||
EXTERN _PROTOTYPE( int do_sef_signal_request, (message *m_ptr) );
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_startup *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sef_startup()
|
||||
{
|
||||
/* SEF startup interface for system processes. */
|
||||
/* SEF startup interface for system services. */
|
||||
int r;
|
||||
|
||||
/* Get information about self. */
|
||||
@@ -63,7 +66,7 @@ PUBLIC void sef_startup()
|
||||
}
|
||||
}
|
||||
else {
|
||||
panic("unable to receive init request");
|
||||
panic("got an unexpected message type %d", m.m_type);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -74,7 +77,7 @@ PUBLIC void sef_startup()
|
||||
*===========================================================================*/
|
||||
PUBLIC int sef_receive(endpoint_t src, message *m_ptr)
|
||||
{
|
||||
/* SEF receive() interface for system processes. */
|
||||
/* SEF receive() interface for system services. */
|
||||
int r;
|
||||
|
||||
while(TRUE) {
|
||||
@@ -108,6 +111,15 @@ PUBLIC int sef_receive(endpoint_t src, message *m_ptr)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if INTERCEPT_SEF_SIGNAL_REQUESTS
|
||||
/* Intercept SEF Signal requests. */
|
||||
if(IS_SEF_SIGNAL_REQUEST(m_ptr)) {
|
||||
if(do_sef_signal_request(m_ptr) == OK) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If we get this far, this is not a valid SEF request, return and
|
||||
* let the caller deal with that.
|
||||
*/
|
||||
@@ -117,6 +129,46 @@ PUBLIC int sef_receive(endpoint_t src, message *m_ptr)
|
||||
return r;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_exit *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sef_exit(int status)
|
||||
{
|
||||
/* System services use a special version of exit() that generates a
|
||||
* self-termination signal.
|
||||
*/
|
||||
message m;
|
||||
|
||||
/* Ask the kernel to exit. */
|
||||
sys_exit();
|
||||
|
||||
/* If sys_exit() fails, this is not a system service. Exit through PM. */
|
||||
m.m1_i1 = status;
|
||||
_syscall(PM_PROC_NR, EXIT, &m);
|
||||
|
||||
/* If everything else fails, hang. */
|
||||
printf("Warning: system service %d couldn't exit\n", sef_self_endpoint);
|
||||
for(;;) { }
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* _exit *
|
||||
*===========================================================================*/
|
||||
PUBLIC void _exit(int status)
|
||||
{
|
||||
/* Make exit() an alias for sef_exit() for system services. */
|
||||
sef_exit(status);
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* __exit *
|
||||
*===========================================================================*/
|
||||
PUBLIC void __exit(int status)
|
||||
{
|
||||
/* Make exit() an alias for sef_exit() for system services. */
|
||||
sef_exit(status);
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_debug_refresh_params *
|
||||
*===========================================================================*/
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
/* SEF Init callbacks. */
|
||||
PRIVATE struct sef_cbs {
|
||||
sef_cb_init_fresh_t sef_cb_init_fresh;
|
||||
sef_cb_init_lu_t sef_cb_init_lu;
|
||||
sef_cb_init_restart_t sef_cb_init_restart;
|
||||
sef_cb_init_t sef_cb_init_fresh;
|
||||
sef_cb_init_t sef_cb_init_lu;
|
||||
sef_cb_init_t sef_cb_init_restart;
|
||||
} sef_cbs = {
|
||||
SEF_CB_INIT_FRESH_DEFAULT,
|
||||
SEF_CB_INIT_LU_DEFAULT,
|
||||
@@ -67,11 +67,9 @@ PUBLIC int do_sef_init_request(message *m_ptr)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Report back to RS. XXX FIXME: we should use send, but this would cause
|
||||
* a deadlock due to the current blocking nature of mapdriver().
|
||||
*/
|
||||
/* Report back to RS. */
|
||||
m_ptr->RS_INIT_RESULT = r;
|
||||
r = asynsend(RS_PROC_NR, m_ptr);
|
||||
r = sendrec(RS_PROC_NR, m_ptr);
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -79,7 +77,7 @@ PUBLIC int do_sef_init_request(message *m_ptr)
|
||||
/*===========================================================================*
|
||||
* sef_setcb_init_fresh *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sef_setcb_init_fresh(sef_cb_init_fresh_t cb)
|
||||
PUBLIC void sef_setcb_init_fresh(sef_cb_init_t cb)
|
||||
{
|
||||
assert(cb != NULL);
|
||||
sef_cbs.sef_cb_init_fresh = cb;
|
||||
@@ -88,7 +86,7 @@ PUBLIC void sef_setcb_init_fresh(sef_cb_init_fresh_t cb)
|
||||
/*===========================================================================*
|
||||
* sef_setcb_init_lu *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sef_setcb_init_lu(sef_cb_init_lu_t cb)
|
||||
PUBLIC void sef_setcb_init_lu(sef_cb_init_t cb)
|
||||
{
|
||||
assert(cb != NULL);
|
||||
sef_cbs.sef_cb_init_lu = cb;
|
||||
@@ -97,44 +95,36 @@ PUBLIC void sef_setcb_init_lu(sef_cb_init_lu_t cb)
|
||||
/*===========================================================================*
|
||||
* sef_setcb_init_restart *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sef_setcb_init_restart(sef_cb_init_restart_t cb)
|
||||
PUBLIC void sef_setcb_init_restart(sef_cb_init_t cb)
|
||||
{
|
||||
assert(cb != NULL);
|
||||
sef_cbs.sef_cb_init_restart = cb;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_cb_init_fresh_null *
|
||||
* sef_cb_init_null *
|
||||
*===========================================================================*/
|
||||
PUBLIC int sef_cb_init_fresh_null(int UNUSED(type),
|
||||
PUBLIC int sef_cb_init_null(int UNUSED(type),
|
||||
sef_init_info_t *UNUSED(info))
|
||||
{
|
||||
return(OK);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_cb_init_lu_null *
|
||||
* sef_cb_init_fail *
|
||||
*===========================================================================*/
|
||||
PUBLIC int sef_cb_init_lu_null(int UNUSED(type), sef_init_info_t *UNUSED(info))
|
||||
PUBLIC int sef_cb_init_fail(int UNUSED(type), sef_init_info_t *UNUSED(info))
|
||||
{
|
||||
return(OK);
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_cb_init_restart_null *
|
||||
* sef_cb_init_crash *
|
||||
*===========================================================================*/
|
||||
PUBLIC int sef_cb_init_restart_null(int UNUSED(type),
|
||||
sef_init_info_t *UNUSED(info))
|
||||
PUBLIC int sef_cb_init_crash(int UNUSED(type), sef_init_info_t *UNUSED(info))
|
||||
{
|
||||
return(OK);
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_cb_init_restart_fail *
|
||||
*===========================================================================*/
|
||||
PUBLIC int sef_cb_init_restart_fail(int UNUSED(type),
|
||||
sef_init_info_t *UNUSED(info))
|
||||
{
|
||||
return(ENOSYS);
|
||||
panic("Simulating a crash at initialization time...");
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,19 +11,22 @@ PRIVATE struct sef_cbs {
|
||||
sef_cb_lu_state_isvalid_t sef_cb_lu_state_isvalid;
|
||||
sef_cb_lu_state_changed_t sef_cb_lu_state_changed;
|
||||
sef_cb_lu_state_dump_t sef_cb_lu_state_dump;
|
||||
sef_cb_lu_ready_pre_t sef_cb_lu_ready_pre;
|
||||
sef_cb_lu_state_save_t sef_cb_lu_state_save;
|
||||
} sef_cbs = {
|
||||
SEF_CB_LU_PREPARE_DEFAULT,
|
||||
SEF_CB_LU_STATE_ISVALID_DEFAULT,
|
||||
SEF_CB_LU_STATE_CHANGED_DEFAULT,
|
||||
SEF_CB_LU_STATE_DUMP_DEFAULT,
|
||||
SEF_CB_LU_READY_PRE_DEFAULT,
|
||||
SEF_CB_LU_STATE_SAVE_DEFAULT,
|
||||
};
|
||||
|
||||
/* SEF Live update prototypes for sef_receive(). */
|
||||
PUBLIC _PROTOTYPE( void do_sef_lu_before_receive, (void) );
|
||||
PUBLIC _PROTOTYPE( int do_sef_lu_request, (message *m_ptr) );
|
||||
|
||||
/* SEF Live update helpers. */
|
||||
PRIVATE _PROTOTYPE( void sef_lu_ready, (int result) );
|
||||
|
||||
/* Debug. */
|
||||
EXTERN _PROTOTYPE( char* sef_debug_header, (void) );
|
||||
PRIVATE int sef_lu_debug_cycle = 0;
|
||||
@@ -34,6 +37,7 @@ PRIVATE int sef_lu_debug_cycle = 0;
|
||||
PUBLIC void do_sef_lu_before_receive()
|
||||
{
|
||||
/* Handle SEF Live update before receive events. */
|
||||
int r;
|
||||
|
||||
/* Nothing to do if we are not preparing for a live update. */
|
||||
if(sef_lu_state == SEF_LU_STATE_NULL) {
|
||||
@@ -53,11 +57,12 @@ PUBLIC void do_sef_lu_before_receive()
|
||||
/* Let the callback code handle the event.
|
||||
* For SEF_LU_STATE_WORK_FREE, we're always ready, tell immediately.
|
||||
*/
|
||||
if(sef_lu_state == SEF_LU_STATE_WORK_FREE) {
|
||||
sef_lu_ready(OK);
|
||||
r = OK;
|
||||
if(sef_lu_state != SEF_LU_STATE_WORK_FREE) {
|
||||
r = sef_cbs.sef_cb_lu_prepare(sef_lu_state);
|
||||
}
|
||||
else {
|
||||
sef_cbs.sef_cb_lu_prepare(sef_lu_state);
|
||||
if(r == OK) {
|
||||
sef_lu_ready(OK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,19 +72,28 @@ PUBLIC void do_sef_lu_before_receive()
|
||||
PUBLIC int do_sef_lu_request(message *m_ptr)
|
||||
{
|
||||
/* Handle a SEF Live update request. */
|
||||
int old_state, is_valid_state;
|
||||
int state, old_state, is_valid_state;
|
||||
|
||||
sef_lu_debug_cycle = 0;
|
||||
old_state = sef_lu_state;
|
||||
state = m_ptr->RS_LU_STATE;
|
||||
|
||||
/* Only accept live update requests with a valid state. */
|
||||
is_valid_state = sef_cbs.sef_cb_lu_state_isvalid(m_ptr->RS_LU_STATE);
|
||||
/* Deal with prepare cancel requests first. */
|
||||
is_valid_state = (state == SEF_LU_STATE_NULL);
|
||||
|
||||
/* Otherwise only accept live update requests with a valid state. */
|
||||
is_valid_state = is_valid_state || sef_cbs.sef_cb_lu_state_isvalid(state);
|
||||
if(!is_valid_state) {
|
||||
sef_lu_ready(EINVAL);
|
||||
if(sef_cbs.sef_cb_lu_state_isvalid == SEF_CB_LU_STATE_ISVALID_NULL) {
|
||||
sef_lu_ready(ENOSYS);
|
||||
}
|
||||
else {
|
||||
sef_lu_ready(EINVAL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Set the new live update state. */
|
||||
sef_lu_state = m_ptr->RS_LU_STATE;
|
||||
sef_lu_state = state;
|
||||
|
||||
/* If the live update state changed, let the callback code
|
||||
* handle the rest.
|
||||
@@ -96,10 +110,10 @@ PUBLIC int do_sef_lu_request(message *m_ptr)
|
||||
/*===========================================================================*
|
||||
* sef_lu_ready *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sef_lu_ready(int result)
|
||||
PRIVATE void sef_lu_ready(int result)
|
||||
{
|
||||
message m;
|
||||
int old_state, r;
|
||||
int old_state, rs_result, r;
|
||||
|
||||
#if SEF_LU_DEBUG
|
||||
sef_lu_debug_begin();
|
||||
@@ -109,28 +123,33 @@ PUBLIC void sef_lu_ready(int result)
|
||||
sef_lu_debug_end();
|
||||
#endif
|
||||
|
||||
/* Let the callback code perform any pre-ready operations. */
|
||||
r = sef_cbs.sef_cb_lu_ready_pre(result);
|
||||
if(r != OK) {
|
||||
/* Abort update if callback returned error. */
|
||||
result = r;
|
||||
}
|
||||
else {
|
||||
/* Inform RS that we're ready with the given result. */
|
||||
m.m_type = RS_LU_PREPARE;
|
||||
m.RS_LU_STATE = sef_lu_state;
|
||||
m.RS_LU_RESULT = result;
|
||||
r = sendrec(RS_PROC_NR, &m);
|
||||
if ( r != OK) {
|
||||
panic("sendrec failed: %d", r);
|
||||
/* If result is OK, let the callback code save
|
||||
* any state that must be carried over to the new version.
|
||||
*/
|
||||
if(result == OK) {
|
||||
r = sef_cbs.sef_cb_lu_state_save(sef_lu_state);
|
||||
if(r != OK) {
|
||||
/* Abort update if callback returned error. */
|
||||
result = r;
|
||||
}
|
||||
}
|
||||
|
||||
/* Inform RS that we're ready with the given result. */
|
||||
m.m_type = RS_LU_PREPARE;
|
||||
m.RS_LU_STATE = sef_lu_state;
|
||||
m.RS_LU_RESULT = result;
|
||||
r = sendrec(RS_PROC_NR, &m);
|
||||
if ( r != OK) {
|
||||
panic("sendrec failed: %d", r);
|
||||
}
|
||||
|
||||
#if SEF_LU_DEBUG
|
||||
rs_result = m.m_type == RS_LU_PREPARE ? EINTR : m.m_type;
|
||||
sef_lu_debug_begin();
|
||||
sef_lu_dprint("%s, cycle=%d. The %s aborted the update!\n",
|
||||
sef_lu_dprint("%s, cycle=%d. The %s aborted the update with result %d!\n",
|
||||
sef_debug_header(), sef_lu_debug_cycle,
|
||||
(result == OK ? "server" : "client"));
|
||||
(result == OK ? "server" : "client"),
|
||||
(result == OK ? rs_result : result)); /* EINTR if update was canceled. */
|
||||
sef_lu_debug_end();
|
||||
#endif
|
||||
|
||||
@@ -181,19 +200,20 @@ PUBLIC void sef_setcb_lu_state_dump(sef_cb_lu_state_dump_t cb)
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_setcb_lu_ready_pre *
|
||||
* sef_setcb_lu_state_save *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sef_setcb_lu_ready_pre(sef_cb_lu_ready_pre_t cb)
|
||||
PUBLIC void sef_setcb_lu_state_save(sef_cb_lu_state_save_t cb)
|
||||
{
|
||||
assert(cb != NULL);
|
||||
sef_cbs.sef_cb_lu_ready_pre = cb;
|
||||
sef_cbs.sef_cb_lu_state_save = cb;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_cb_lu_prepare_null *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sef_cb_lu_prepare_null(int UNUSED(state))
|
||||
PUBLIC int sef_cb_lu_prepare_null(int UNUSED(state))
|
||||
{
|
||||
return ENOTREADY;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
@@ -221,19 +241,44 @@ PUBLIC void sef_cb_lu_state_dump_null(int UNUSED(state))
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_cb_lu_ready_pre_null *
|
||||
* sef_cb_lu_state_save_null *
|
||||
*===========================================================================*/
|
||||
PUBLIC int sef_cb_lu_ready_pre_null(int UNUSED(result))
|
||||
PUBLIC int sef_cb_lu_state_save_null(int UNUSED(result))
|
||||
{
|
||||
return(OK);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_cb_lu_prepare_always_ready *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sef_cb_lu_prepare_always_ready(int UNUSED(state))
|
||||
PUBLIC int sef_cb_lu_prepare_always_ready(int UNUSED(state))
|
||||
{
|
||||
sef_lu_ready(OK);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_cb_lu_prepare_never_ready *
|
||||
*===========================================================================*/
|
||||
PUBLIC int sef_cb_lu_prepare_never_ready(int UNUSED(state))
|
||||
{
|
||||
#if SEF_LU_DEBUG
|
||||
sef_lu_debug_begin();
|
||||
sef_lu_dprint("%s, cycle=%d. Simulating a service never ready to update...\n",
|
||||
sef_debug_header(), sef_lu_debug_cycle);
|
||||
sef_lu_debug_end();
|
||||
#endif
|
||||
|
||||
return ENOTREADY;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_cb_lu_prepare_crash *
|
||||
*===========================================================================*/
|
||||
PUBLIC int sef_cb_lu_prepare_crash(int UNUSED(state))
|
||||
{
|
||||
panic("Simulating a crash at update prepare time...");
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
|
||||
@@ -31,7 +31,7 @@ PUBLIC int do_sef_ping_request(message *m_ptr)
|
||||
#endif
|
||||
|
||||
/* Let the callback code handle the request. */
|
||||
sef_cbs.sef_cb_ping_reply(m_ptr);
|
||||
sef_cbs.sef_cb_ping_reply(m_ptr->m_source);
|
||||
|
||||
/* Return OK not to let anybody else intercept the request. */
|
||||
return(OK);
|
||||
@@ -49,15 +49,15 @@ PUBLIC void sef_setcb_ping_reply(sef_cb_ping_reply_t cb)
|
||||
/*===========================================================================*
|
||||
* sef_cb_ping_reply_null *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sef_cb_ping_reply_null(message *UNUSED(m_ptr))
|
||||
PUBLIC void sef_cb_ping_reply_null(endpoint_t UNUSED(source))
|
||||
{
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_cb_ping_reply_pong *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sef_cb_ping_reply_pong(message *m_ptr)
|
||||
PUBLIC void sef_cb_ping_reply_pong(endpoint_t source)
|
||||
{
|
||||
notify(m_ptr->m_source);
|
||||
notify(source);
|
||||
}
|
||||
|
||||
|
||||
196
lib/libsys/sef_signal.c
Normal file
196
lib/libsys/sef_signal.c
Normal file
@@ -0,0 +1,196 @@
|
||||
#include "syslib.h"
|
||||
#include <assert.h>
|
||||
#include <signal.h>
|
||||
#include <minix/sysutil.h>
|
||||
|
||||
/* SEF Signal callbacks. */
|
||||
PRIVATE struct sef_cbs {
|
||||
sef_cb_signal_handler_t sef_cb_signal_handler;
|
||||
sef_cb_signal_manager_t sef_cb_signal_manager;
|
||||
} sef_cbs = {
|
||||
SEF_CB_SIGNAL_HANDLER_DEFAULT,
|
||||
SEF_CB_SIGNAL_MANAGER_DEFAULT
|
||||
};
|
||||
|
||||
/* SEF Signal prototypes for sef_receive(). */
|
||||
PUBLIC _PROTOTYPE( int do_sef_signal_request, (message *m_ptr) );
|
||||
|
||||
/* Debug. */
|
||||
EXTERN _PROTOTYPE( char* sef_debug_header, (void) );
|
||||
|
||||
/* Information about SELF. */
|
||||
EXTERN endpoint_t sef_self_endpoint;
|
||||
|
||||
/*===========================================================================*
|
||||
* process_sigmgr_signals *
|
||||
*===========================================================================*/
|
||||
PRIVATE void process_sigmgr_signals(void)
|
||||
{
|
||||
/* A signal manager has pending signals in the kernel. Process them. */
|
||||
endpoint_t target;
|
||||
sigset_t sigset;
|
||||
int signo, r;
|
||||
|
||||
while (TRUE) {
|
||||
/* Get an arbitrary pending signal. */
|
||||
if((r=sys_getksig(&target, &sigset)) != OK)
|
||||
panic("SEF", "sys_getksig failed", r);
|
||||
|
||||
if (target == NONE) {
|
||||
/* Stop if there are no more pending signals. */
|
||||
break;
|
||||
} else {
|
||||
/* Process every signal in the signal set. */
|
||||
r = OK;
|
||||
for(signo = 1; signo < _NSIG; signo++) {
|
||||
if(sigismember(&sigset, signo)) {
|
||||
/* Let the callback code process the signal. */
|
||||
r = sef_cbs.sef_cb_signal_manager(target, signo);
|
||||
|
||||
/* Stop if process is gone. */
|
||||
if(r == EDEADSRCDST) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Tell the kernel we are done if the target is still alive. */
|
||||
if(r == OK) {
|
||||
if((r=sys_endksig(target)) != OK)
|
||||
panic("SEF","sys_endksig failed", r);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* process_sigmgr_self_signals *
|
||||
*===========================================================================*/
|
||||
PRIVATE void process_sigmgr_self_signals(sigset_t sigset)
|
||||
{
|
||||
/* A signal manager has pending signals for itself. Process them. */
|
||||
int signo;
|
||||
|
||||
for(signo = 1; signo < _NSIG; signo++) {
|
||||
if(sigismember(&sigset, signo)) {
|
||||
/* Let the callback code process the signal. */
|
||||
sef_cbs.sef_cb_signal_handler(signo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* do_sef_signal_request *
|
||||
*===========================================================================*/
|
||||
PUBLIC int do_sef_signal_request(message *m_ptr)
|
||||
{
|
||||
/* Handle a SEF Signal request. */
|
||||
int signo;
|
||||
sigset_t sigset;
|
||||
|
||||
if(m_ptr->m_source == SYSTEM) {
|
||||
/* Handle kernel signals. */
|
||||
sigset = m_ptr->NOTIFY_ARG;
|
||||
for (signo = SIGK_FIRST; signo <= SIGK_LAST; signo++) {
|
||||
if (sigismember(&sigset, signo)) {
|
||||
/* Let the callback code handle the kernel signal. */
|
||||
sef_cbs.sef_cb_signal_handler(signo);
|
||||
|
||||
/* Handle SIGKSIG for a signal manager. */
|
||||
if(signo == SIGKSIG) {
|
||||
process_sigmgr_signals();
|
||||
}
|
||||
/* Handle SIGKSIGSM for a signal manager. */
|
||||
else if(signo == SIGKSIGSM) {
|
||||
process_sigmgr_self_signals(sigset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Handle system signals from a signal manager. */
|
||||
signo = m_ptr->SIGS_SIG_NUM;
|
||||
|
||||
/* Debug. */
|
||||
#if SEF_SIGNAL_DEBUG
|
||||
sef_signal_debug_begin();
|
||||
sef_signal_dprint("%s. Got a SEF Signal request for signal %d! About to handle signal.\n",
|
||||
sef_debug_header(), signo);
|
||||
sef_signal_debug_end();
|
||||
#endif
|
||||
|
||||
/* Let the callback code handle the signal. */
|
||||
sef_cbs.sef_cb_signal_handler(signo);
|
||||
}
|
||||
|
||||
/* Return OK not to let anybody else intercept the request. */
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_setcb_signal_handler *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sef_setcb_signal_handler(sef_cb_signal_handler_t cb)
|
||||
{
|
||||
assert(cb != NULL);
|
||||
sef_cbs.sef_cb_signal_handler = cb;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_setcb_signal_manager *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sef_setcb_signal_manager(sef_cb_signal_manager_t cb)
|
||||
{
|
||||
assert(cb != NULL);
|
||||
sef_cbs.sef_cb_signal_manager = cb;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_cb_signal_handler_null *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sef_cb_signal_handler_null(int signo)
|
||||
{
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_cb_signal_manager_null *
|
||||
*===========================================================================*/
|
||||
PUBLIC int sef_cb_signal_manager_null(endpoint_t target, int signo)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_cb_signal_handler_term *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sef_cb_signal_handler_term(int signo)
|
||||
{
|
||||
/* Terminate in case of SIGTERM, ignore other signals. */
|
||||
if(signo == SIGTERM) {
|
||||
sef_exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sef_cb_signal_handler_posix_default *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sef_cb_signal_handler_posix_default(int signo)
|
||||
{
|
||||
switch(signo) {
|
||||
/* Ignore when possible. */
|
||||
case SIGCHLD:
|
||||
case SIGWINCH:
|
||||
case SIGCONT:
|
||||
case SIGTSTP:
|
||||
case SIGTTIN:
|
||||
case SIGTTOU:
|
||||
break;
|
||||
|
||||
/* Terminate in any other case unless it is a kernel signal. */
|
||||
default:
|
||||
if(!IS_SIGK(signo)) {
|
||||
sef_exit(1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
15
lib/libsys/sys_clear.c
Normal file
15
lib/libsys/sys_clear.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "syslib.h"
|
||||
|
||||
/*===========================================================================*
|
||||
* sys_clear *
|
||||
*===========================================================================*/
|
||||
PUBLIC int sys_clear(proc_ep)
|
||||
endpoint_t proc_ep; /* which process has exited */
|
||||
{
|
||||
/* A process has exited. PM tells the kernel.
|
||||
*/
|
||||
message m;
|
||||
|
||||
m.PR_ENDPT = proc_ep;
|
||||
return(_kernel_call(SYS_CLEAR, &m));
|
||||
}
|
||||
@@ -3,15 +3,10 @@
|
||||
/*===========================================================================*
|
||||
* sys_exit *
|
||||
*===========================================================================*/
|
||||
PUBLIC int sys_exit(proc_ep)
|
||||
endpoint_t proc_ep; /* which process has exited */
|
||||
PUBLIC int sys_exit()
|
||||
{
|
||||
/* A process has exited. PM tells the kernel. In addition this call can be
|
||||
* used by system processes to directly exit without passing through the
|
||||
* PM. This should be used with care to prevent inconsistent PM tables.
|
||||
*/
|
||||
/* A system process requests to exit. */
|
||||
message m;
|
||||
|
||||
m.PR_ENDPT = proc_ep;
|
||||
return(_kernel_call(SYS_EXIT, &m));
|
||||
}
|
||||
|
||||
11
lib/libsys/sys_update.c
Normal file
11
lib/libsys/sys_update.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "syslib.h"
|
||||
|
||||
int sys_update(endpoint_t src_ep, endpoint_t dst_ep)
|
||||
{
|
||||
message m;
|
||||
|
||||
m.SYS_UPD_SRC_ENDPT = src_ep;
|
||||
m.SYS_UPD_DST_ENDPT = dst_ep;
|
||||
|
||||
return _kernel_call(SYS_UPDATE, &m);
|
||||
}
|
||||
Reference in New Issue
Block a user