2011-11-02 17:31:38 +01:00
|
|
|
/* This file contains a simple message queue implementation to support both
|
|
|
|
* the singlethread and the multithreaded driver implementation.
|
|
|
|
*
|
|
|
|
* Changes:
|
|
|
|
* Oct 27, 2011 rewritten to use sys/queue.h (D.C. van Moolenbroek)
|
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.
2011-11-22 13:27:53 +01:00
|
|
|
* Aug 27, 2011 integrated into libblockdriver (A. Welzel)
|
2011-11-02 17:31:38 +01:00
|
|
|
*/
|
2007-01-12 14:33:12 +01:00
|
|
|
|
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.
2011-11-22 13:27:53 +01:00
|
|
|
#include <minix/blockdriver_mt.h>
|
2011-11-02 17:31:38 +01:00
|
|
|
#include <sys/queue.h>
|
2007-01-12 14:33:12 +01:00
|
|
|
#include <assert.h>
|
|
|
|
|
2011-12-07 15:44:28 +01:00
|
|
|
#include "const.h"
|
2011-11-02 17:31:38 +01:00
|
|
|
#include "mq.h"
|
2007-01-12 14:33:12 +01:00
|
|
|
|
|
|
|
#define MQ_SIZE 128
|
|
|
|
|
2011-11-02 17:31:38 +01:00
|
|
|
struct mq_cell {
|
|
|
|
message mess;
|
|
|
|
int ipc_status;
|
|
|
|
STAILQ_ENTRY(mq_cell) next;
|
|
|
|
};
|
2007-01-12 14:33:12 +01:00
|
|
|
|
2011-11-02 17:31:38 +01:00
|
|
|
PRIVATE struct mq_cell pool[MQ_SIZE];
|
2011-12-07 15:44:28 +01:00
|
|
|
PRIVATE STAILQ_HEAD(queue, mq_cell) queue[MAX_DEVICES];
|
2011-11-02 17:31:38 +01:00
|
|
|
PRIVATE STAILQ_HEAD(free_list, mq_cell) free_list;
|
2007-01-12 14:33:12 +01:00
|
|
|
|
2011-11-02 17:31:38 +01:00
|
|
|
/*===========================================================================*
|
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.
2011-11-22 13:27:53 +01:00
|
|
|
* mq_init *
|
2011-11-02 17:31:38 +01:00
|
|
|
*===========================================================================*/
|
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.
2011-11-22 13:27:53 +01:00
|
|
|
PUBLIC void mq_init(void)
|
2007-01-12 14:33:12 +01:00
|
|
|
{
|
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.
2011-11-22 13:27:53 +01:00
|
|
|
/* Initialize the message queues and message cells.
|
2011-11-02 17:31:38 +01:00
|
|
|
*/
|
|
|
|
int i;
|
|
|
|
|
|
|
|
STAILQ_INIT(&free_list);
|
2007-01-12 14:33:12 +01:00
|
|
|
|
2011-12-07 15:44:28 +01:00
|
|
|
for (i = 0; i < MAX_DEVICES; i++)
|
2011-11-02 17:31:38 +01:00
|
|
|
STAILQ_INIT(&queue[i]);
|
2007-01-12 14:33:12 +01:00
|
|
|
|
2011-11-02 17:31:38 +01:00
|
|
|
for (i = 0; i < MQ_SIZE; i++)
|
|
|
|
STAILQ_INSERT_HEAD(&free_list, &pool[i], next);
|
2007-01-12 14:33:12 +01:00
|
|
|
}
|
|
|
|
|
2011-11-02 17:31:38 +01:00
|
|
|
/*===========================================================================*
|
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.
2011-11-22 13:27:53 +01:00
|
|
|
* mq_enqueue *
|
2011-11-02 17:31:38 +01:00
|
|
|
*===========================================================================*/
|
2011-12-07 15:44:28 +01:00
|
|
|
PUBLIC int mq_enqueue(device_id_t device_id, const message *mess,
|
2011-11-02 17:31:38 +01:00
|
|
|
int ipc_status)
|
2007-01-12 14:33:12 +01:00
|
|
|
{
|
2011-12-07 15:44:28 +01:00
|
|
|
/* Add a message, including its IPC status, to the message queue of a device.
|
2011-11-02 17:31:38 +01:00
|
|
|
* Return TRUE iff the message was added successfully.
|
|
|
|
*/
|
|
|
|
struct mq_cell *cell;
|
|
|
|
|
2011-12-07 15:44:28 +01:00
|
|
|
assert(device_id >= 0 && device_id < MAX_DEVICES);
|
2011-11-02 17:31:38 +01:00
|
|
|
|
|
|
|
if (STAILQ_EMPTY(&free_list))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
cell = STAILQ_FIRST(&free_list);
|
|
|
|
STAILQ_REMOVE_HEAD(&free_list, next);
|
|
|
|
|
|
|
|
cell->mess = *mess;
|
|
|
|
cell->ipc_status = ipc_status;
|
|
|
|
|
2011-12-07 15:44:28 +01:00
|
|
|
STAILQ_INSERT_TAIL(&queue[device_id], cell, next);
|
2011-11-02 17:31:38 +01:00
|
|
|
|
|
|
|
return TRUE;
|
2007-01-12 14:33:12 +01:00
|
|
|
}
|
|
|
|
|
2011-11-02 17:31:38 +01:00
|
|
|
/*===========================================================================*
|
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.
2011-11-22 13:27:53 +01:00
|
|
|
* mq_dequeue *
|
2011-11-02 17:31:38 +01:00
|
|
|
*===========================================================================*/
|
2011-12-07 15:44:28 +01:00
|
|
|
PUBLIC int mq_dequeue(device_id_t device_id, message *mess, int *ipc_status)
|
2011-11-02 17:31:38 +01:00
|
|
|
{
|
|
|
|
/* Return and remove a message, including its IPC status, from the message
|
|
|
|
* queue of a thread. Return TRUE iff a message was available.
|
2007-01-12 14:33:12 +01:00
|
|
|
*/
|
2011-11-02 17:31:38 +01:00
|
|
|
struct mq_cell *cell;
|
|
|
|
|
2011-12-07 15:44:28 +01:00
|
|
|
assert(device_id >= 0 && device_id < MAX_DEVICES);
|
2011-11-02 17:31:38 +01:00
|
|
|
|
2011-12-07 15:44:28 +01:00
|
|
|
if (STAILQ_EMPTY(&queue[device_id]))
|
2011-11-02 17:31:38 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2011-12-07 15:44:28 +01:00
|
|
|
cell = STAILQ_FIRST(&queue[device_id]);
|
|
|
|
STAILQ_REMOVE_HEAD(&queue[device_id], next);
|
2011-11-02 17:31:38 +01:00
|
|
|
|
|
|
|
*mess = cell->mess;
|
|
|
|
*ipc_status = cell->ipc_status;
|
|
|
|
|
|
|
|
STAILQ_INSERT_HEAD(&free_list, cell, next);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|