2010-03-22 22:25:22 +01:00
|
|
|
#include <minix/drivers.h>
|
|
|
|
#include <minix/driver.h>
|
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.
2010-03-17 02:15:29 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <minix/ds.h>
|
|
|
|
#include "hello.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function prototypes for the hello driver.
|
|
|
|
*/
|
|
|
|
FORWARD _PROTOTYPE( char * hello_name, (void) );
|
|
|
|
FORWARD _PROTOTYPE( int hello_open, (struct driver *d, message *m) );
|
|
|
|
FORWARD _PROTOTYPE( int hello_close, (struct driver *d, message *m) );
|
|
|
|
FORWARD _PROTOTYPE( struct device * hello_prepare, (int device) );
|
|
|
|
FORWARD _PROTOTYPE( int hello_transfer, (int procnr, int opcode,
|
|
|
|
u64_t position, iovec_t *iov,
|
|
|
|
unsigned nr_req) );
|
|
|
|
FORWARD _PROTOTYPE( void hello_geometry, (struct partition *entry) );
|
|
|
|
|
|
|
|
/* SEF functions and variables. */
|
|
|
|
FORWARD _PROTOTYPE( void sef_local_startup, (void) );
|
|
|
|
FORWARD _PROTOTYPE( int sef_cb_init, (int type, sef_init_info_t *info) );
|
|
|
|
FORWARD _PROTOTYPE( int sef_cb_lu_state_save, (int) );
|
|
|
|
FORWARD _PROTOTYPE( int lu_state_restore, (void) );
|
|
|
|
|
|
|
|
/* Entry points to the hello driver. */
|
|
|
|
PRIVATE struct driver hello_tab =
|
|
|
|
{
|
|
|
|
hello_name,
|
|
|
|
hello_open,
|
|
|
|
hello_close,
|
|
|
|
nop_ioctl,
|
|
|
|
hello_prepare,
|
|
|
|
hello_transfer,
|
|
|
|
nop_cleanup,
|
|
|
|
hello_geometry,
|
|
|
|
nop_alarm,
|
|
|
|
nop_cancel,
|
|
|
|
nop_select,
|
|
|
|
nop_ioctl,
|
|
|
|
do_nop,
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Represents the /dev/hello device. */
|
|
|
|
PRIVATE struct device hello_device;
|
|
|
|
|
|
|
|
/** State variable to count the number of times the device has been opened. */
|
|
|
|
PRIVATE int open_counter;
|
|
|
|
|
|
|
|
PRIVATE char * hello_name(void)
|
|
|
|
{
|
|
|
|
printf("hello_name()\n");
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE int hello_open(d, m)
|
|
|
|
struct driver *d;
|
|
|
|
message *m;
|
|
|
|
{
|
|
|
|
printf("hello_open(). Called %d time(s).\n", ++open_counter);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE int hello_close(d, m)
|
|
|
|
struct driver *d;
|
|
|
|
message *m;
|
|
|
|
{
|
|
|
|
printf("hello_close()\n");
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE struct device * hello_prepare(dev)
|
|
|
|
int dev;
|
|
|
|
{
|
|
|
|
hello_device.dv_base.lo = 0;
|
|
|
|
hello_device.dv_base.hi = 0;
|
|
|
|
hello_device.dv_size.lo = strlen(HELLO_MESSAGE);
|
|
|
|
hello_device.dv_size.hi = 0;
|
|
|
|
return &hello_device;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE int hello_transfer(proc_nr, opcode, position, iov, nr_req)
|
|
|
|
int proc_nr;
|
|
|
|
int opcode;
|
|
|
|
u64_t position;
|
|
|
|
iovec_t *iov;
|
|
|
|
unsigned nr_req;
|
|
|
|
{
|
|
|
|
int bytes, ret;
|
|
|
|
|
|
|
|
printf("hello_transfer()\n");
|
|
|
|
|
|
|
|
bytes = strlen(HELLO_MESSAGE) - position.lo < iov->iov_size ?
|
|
|
|
strlen(HELLO_MESSAGE) - position.lo : iov->iov_size;
|
|
|
|
|
|
|
|
if (bytes <= 0)
|
|
|
|
{
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
switch (opcode)
|
|
|
|
{
|
|
|
|
case DEV_GATHER_S:
|
|
|
|
ret = sys_safecopyto(proc_nr, iov->iov_addr, 0,
|
|
|
|
(vir_bytes) (HELLO_MESSAGE + position.lo),
|
|
|
|
bytes, D);
|
|
|
|
iov->iov_size -= bytes;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE void hello_geometry(entry)
|
|
|
|
struct partition *entry;
|
|
|
|
{
|
|
|
|
printf("hello_geometry()\n");
|
|
|
|
entry->cylinders = 0;
|
|
|
|
entry->heads = 0;
|
|
|
|
entry->sectors = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE int sef_cb_lu_state_save(int state) {
|
|
|
|
/* Save the state. */
|
|
|
|
ds_publish_u32("open_counter", open_counter, DSF_OVERWRITE);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE int lu_state_restore() {
|
|
|
|
/* Restore the state. */
|
|
|
|
u32_t value;
|
|
|
|
|
|
|
|
ds_retrieve_u32("open_counter", &value);
|
|
|
|
ds_delete_u32("open_counter");
|
|
|
|
open_counter = (int) value;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE void sef_local_startup()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Register init callbacks. Use the same function for all event types
|
|
|
|
*/
|
|
|
|
sef_setcb_init_fresh(sef_cb_init);
|
|
|
|
sef_setcb_init_lu(sef_cb_init);
|
|
|
|
sef_setcb_init_restart(sef_cb_init);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register live update callbacks.
|
|
|
|
*/
|
|
|
|
/* - Agree to update immediately when LU is requested in a valid state. */
|
|
|
|
sef_setcb_lu_prepare(sef_cb_lu_prepare_always_ready);
|
|
|
|
/* - Support live update starting from any standard state. */
|
|
|
|
sef_setcb_lu_state_isvalid(sef_cb_lu_state_isvalid_standard);
|
|
|
|
/* - Register a custom routine to save the state. */
|
|
|
|
sef_setcb_lu_state_save(sef_cb_lu_state_save);
|
|
|
|
|
|
|
|
/* Let SEF perform startup. */
|
|
|
|
sef_startup();
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE int sef_cb_init(int type, sef_init_info_t *info)
|
|
|
|
{
|
|
|
|
/* Initialize the hello driver. */
|
|
|
|
int do_mapdriver = TRUE;
|
|
|
|
|
|
|
|
open_counter = 0;
|
|
|
|
switch(type) {
|
|
|
|
case SEF_INIT_FRESH:
|
|
|
|
printf("%s", HELLO_MESSAGE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SEF_INIT_LU:
|
|
|
|
/* Restore the state. */
|
|
|
|
lu_state_restore();
|
|
|
|
do_mapdriver = FALSE;
|
|
|
|
|
|
|
|
printf("%sHey, I'm a new version!\n", HELLO_MESSAGE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SEF_INIT_RESTART:
|
|
|
|
printf("%sHey, I've just been restarted!\n", HELLO_MESSAGE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Map major number to our process. */
|
|
|
|
if (do_mapdriver && mapdriver("hello", HELLO_MAJOR, STYLE_DEV, TRUE) != OK)
|
|
|
|
{
|
|
|
|
printf("hello: mapdriver() failed: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialization completed successfully. */
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PUBLIC int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Perform initialization.
|
|
|
|
*/
|
|
|
|
sef_local_startup();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run the main loop.
|
|
|
|
*/
|
|
|
|
driver_task(&hello_tab, DRIVER_STD);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|