Split block/character protocols and libdriver
This patch separates the character and block driver communication protocols. The old character protocol remains the same, but a new block protocol is introduced. The libdriver library is replaced by two new libraries: libchardriver and libblockdriver. Their exposed API, and drivers that use them, have been updated accordingly. Together, libbdev and libblockdriver now completely abstract away the message format used by the block protocol. As the memory driver is both a character and a block device driver, it now implements its own message loop. The most important semantic change made to the block protocol is that it is no longer possible to return both partial results and an error for a single transfer. This simplifies the interaction between the caller and the driver, as the I/O vector no longer needs to be copied back. Also, drivers are now no longer supposed to decide based on the layout of the I/O vector when a transfer should be cut short. Put simply, transfers are now supposed to either succeed completely, or result in an error. After this patch, the state of the various pieces is as follows: - block protocol: stable - libbdev API: stable for synchronous communication - libblockdriver API: needs slight revision (the drvlib/partition API in particular; the threading API will also change shortly) - character protocol: needs cleanup - libchardriver API: needs cleanup accordingly - driver restarts: largely unsupported until endpoint changes are reintroduced As a side effect, this patch eliminates several bugs, hacks, and gcc -Wall and -W warnings all over the place. It probably introduces a few new ones, too. Update warning: this patch changes the protocol between MFS and disk drivers, so in order to use old/new images, the MFS from the ramdisk must be used to mount all file systems.
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
PROG= hello
|
||||
SRCS= hello.c
|
||||
|
||||
DPADD+= ${LIBDRIVER} ${LIBSYS}
|
||||
LDADD+= -ldriver -lsys
|
||||
DPADD+= ${LIBCHARDRIVER} ${LIBSYS}
|
||||
LDADD+= -lchardriver -lsys
|
||||
|
||||
MAN=
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <minix/drivers.h>
|
||||
#include <minix/driver.h>
|
||||
#include <minix/chardriver.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <minix/ds.h>
|
||||
@@ -8,14 +8,13 @@
|
||||
/*
|
||||
* 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,
|
||||
FORWARD _PROTOTYPE( int hello_open, (message *m) );
|
||||
FORWARD _PROTOTYPE( int hello_close, (message *m) );
|
||||
FORWARD _PROTOTYPE( struct device * hello_prepare, (dev_t device) );
|
||||
FORWARD _PROTOTYPE( int hello_transfer, (endpoint_t endpt, int opcode,
|
||||
u64_t position, iovec_t *iov,
|
||||
unsigned nr_req) );
|
||||
FORWARD _PROTOTYPE( void hello_geometry, (struct partition *entry) );
|
||||
unsigned int nr_req,
|
||||
endpoint_t user_endpt) );
|
||||
|
||||
/* SEF functions and variables. */
|
||||
FORWARD _PROTOTYPE( void sef_local_startup, (void) );
|
||||
@@ -24,21 +23,17 @@ 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 =
|
||||
PRIVATE struct chardriver 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,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
@@ -48,47 +43,38 @@ 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;
|
||||
PRIVATE int hello_open(message *UNUSED(m))
|
||||
{
|
||||
printf("hello_open(). Called %d time(s).\n", ++open_counter);
|
||||
return OK;
|
||||
}
|
||||
|
||||
PRIVATE int hello_close(d, m)
|
||||
struct driver *d;
|
||||
message *m;
|
||||
PRIVATE int hello_close(message *UNUSED(m))
|
||||
{
|
||||
printf("hello_close()\n");
|
||||
return OK;
|
||||
}
|
||||
|
||||
PRIVATE struct device * hello_prepare(dev)
|
||||
int dev;
|
||||
PRIVATE struct device * hello_prepare(dev_t UNUSED(dev))
|
||||
{
|
||||
hello_device.dv_base = make64(0, 0);
|
||||
hello_device.dv_size = make64(strlen(HELLO_MESSAGE), 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;
|
||||
PRIVATE int hello_transfer(endpoint_t endpt, int opcode, u64_t position,
|
||||
iovec_t *iov, unsigned nr_req, endpoint_t UNUSED(user_endpt))
|
||||
{
|
||||
int bytes, ret;
|
||||
|
||||
printf("hello_transfer()\n");
|
||||
|
||||
if (nr_req != 1)
|
||||
{
|
||||
/* This should never trigger for character drivers at the moment. */
|
||||
printf("HELLO: vectored transfer request, using first element only\n");
|
||||
}
|
||||
|
||||
bytes = strlen(HELLO_MESSAGE) - ex64lo(position) < iov->iov_size ?
|
||||
strlen(HELLO_MESSAGE) - ex64lo(position) : iov->iov_size;
|
||||
|
||||
@@ -99,7 +85,7 @@ PRIVATE int hello_transfer(proc_nr, opcode, position, iov, nr_req)
|
||||
switch (opcode)
|
||||
{
|
||||
case DEV_GATHER_S:
|
||||
ret = sys_safecopyto(proc_nr, iov->iov_addr, 0,
|
||||
ret = sys_safecopyto(endpt, (cp_grant_id_t) iov->iov_addr, 0,
|
||||
(vir_bytes) (HELLO_MESSAGE + ex64lo(position)),
|
||||
bytes, D);
|
||||
iov->iov_size -= bytes;
|
||||
@@ -111,16 +97,7 @@ PRIVATE int hello_transfer(proc_nr, opcode, position, iov, nr_req)
|
||||
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) {
|
||||
PRIVATE int sef_cb_lu_state_save(int UNUSED(state)) {
|
||||
/* Save the state. */
|
||||
ds_publish_u32("open_counter", open_counter, DSF_OVERWRITE);
|
||||
|
||||
@@ -161,7 +138,7 @@ PRIVATE void sef_local_startup()
|
||||
sef_startup();
|
||||
}
|
||||
|
||||
PRIVATE int sef_cb_init(int type, sef_init_info_t *info)
|
||||
PRIVATE int sef_cb_init(int type, sef_init_info_t *UNUSED(info))
|
||||
{
|
||||
/* Initialize the hello driver. */
|
||||
int do_announce_driver = TRUE;
|
||||
@@ -187,14 +164,14 @@ PRIVATE int sef_cb_init(int type, sef_init_info_t *info)
|
||||
|
||||
/* Announce we are up when necessary. */
|
||||
if (do_announce_driver) {
|
||||
driver_announce();
|
||||
chardriver_announce();
|
||||
}
|
||||
|
||||
/* Initialization completed successfully. */
|
||||
return OK;
|
||||
}
|
||||
|
||||
PUBLIC int main(int argc, char **argv)
|
||||
PUBLIC int main(void)
|
||||
{
|
||||
/*
|
||||
* Perform initialization.
|
||||
@@ -204,7 +181,7 @@ PUBLIC int main(int argc, char **argv)
|
||||
/*
|
||||
* Run the main loop.
|
||||
*/
|
||||
driver_task(&hello_tab, DRIVER_STD);
|
||||
chardriver_task(&hello_tab, CHARDRIVER_SYNC);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user