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:
David van Moolenbroek
2011-11-23 14:06:37 +01:00
parent 7643f2b25e
commit b4d909d415
114 changed files with 2682 additions and 2148 deletions
+11 -15
View File
@@ -12,7 +12,8 @@ static void bdev_cancel(dev_t dev)
* permanently unusable, and clean up any associated calls and resources.
*/
printf("bdev: driver for major %d crashed\n", major(dev));
printf("bdev: driver for major %d (endpoint %d) crashed\n",
major(dev), bdev_driver_get(dev));
/* Mark the driver as unusable. */
bdev_driver_clear(dev);
@@ -27,18 +28,13 @@ void bdev_update(dev_t dev, endpoint_t endpt)
old_endpt = bdev_driver_get(dev);
bdev_driver_set(dev, endpt);
/* If updating the driver causes an endpoint change, the driver has
* restarted.
*/
if (old_endpt != NONE && old_endpt != endpt)
bdev_cancel(dev);
}
int bdev_sendrec(dev_t dev, const message *m_orig)
{
/* Send a request to the given device, and wait for the reply.
*/
static long id = 0;
endpoint_t endpt;
message m;
int r;
@@ -49,7 +45,7 @@ int bdev_sendrec(dev_t dev, const message *m_orig)
/* Send the request and block until we receive a reply. */
m = *m_orig;
m.USER_ENDPT = (endpoint_t) -1; /* synchronous request; no ID */
m.BDEV_ID = ++id;
r = sendrec(endpt, &m);
@@ -65,25 +61,25 @@ int bdev_sendrec(dev_t dev, const message *m_orig)
return r;
}
if (m.m_type != TASK_REPLY) {
if (m.m_type != BDEV_REPLY) {
printf("bdev: driver (%d) sent weird response (%d)\n",
endpt, m.m_type);
return EIO;
}
/* ERESTART signifies a driver restart. Again, we do not support this yet. */
if (m.REP_STATUS == ERESTART) {
if (m.BDEV_STATUS == ERESTART) {
bdev_cancel(dev);
return EDEADSRCDST;
}
if (m.REP_ENDPT != (endpoint_t) -1) {
printf("bdev: driver (%d) sent invalid response (%d)\n",
endpt, m.REP_ENDPT);
if (m.BDEV_ID != id) {
printf("bdev: driver (%d) sent invalid response (%ld)\n",
endpt, m.BDEV_ID);
return EIO;
}
/* We got a reply to our request. */
return m.REP_STATUS;
/* Return the result of our request. */
return m.BDEV_STATUS;
}