Block protocol: add user endpoint to IOCTL request
I/O control requests now come with the endpoint of the user process that initiated the ioctl(2) call. It is stored in a new BDEV_USER field, which is an alias for BDEV_FLAGS. The contents of this field are to be used only in highly specific situations. It should be preserved (not replaced!) by services that forward IOCTL requests, and may be set to NONE for service-initiated IOCTL requests. Change-Id: I68a01b9ce43eca00e61b985a9cf87f55ba683de4
This commit is contained in:
parent
113635b019
commit
95624ae072
16 changed files with 43 additions and 32 deletions
|
@ -243,7 +243,7 @@ static ssize_t ahci_transfer(devminor_t minor, int do_write, u64_t position,
|
|||
static struct device *ahci_part(devminor_t minor);
|
||||
static void ahci_alarm(clock_t stamp);
|
||||
static int ahci_ioctl(devminor_t minor, unsigned int request, endpoint_t endpt,
|
||||
cp_grant_id_t grant);
|
||||
cp_grant_id_t grant, endpoint_t user_endpt);
|
||||
static void ahci_intr(unsigned int mask);
|
||||
static int ahci_device(devminor_t minor, device_id_t *id);
|
||||
static struct port_state *ahci_get_port(devminor_t minor);
|
||||
|
@ -2632,7 +2632,7 @@ static ssize_t ahci_transfer(devminor_t minor, int do_write, u64_t position,
|
|||
* ahci_ioctl *
|
||||
*===========================================================================*/
|
||||
static int ahci_ioctl(devminor_t minor, unsigned int request, endpoint_t endpt,
|
||||
cp_grant_id_t grant)
|
||||
cp_grant_id_t grant, endpoint_t UNUSED(user_endpt))
|
||||
{
|
||||
/* Process I/O control requests.
|
||||
*/
|
||||
|
|
|
@ -157,7 +157,7 @@ static void w_need_reset(void);
|
|||
static void ack_irqs(unsigned int);
|
||||
static int w_do_close(devminor_t minor);
|
||||
static int w_ioctl(devminor_t minor, unsigned int request, endpoint_t endpt,
|
||||
cp_grant_id_t grant);
|
||||
cp_grant_id_t grant, endpoint_t user_endpt);
|
||||
static void w_hw_int(unsigned int irqs);
|
||||
static int com_simple(struct command *cmd);
|
||||
static void w_timeout(void);
|
||||
|
@ -2212,7 +2212,7 @@ int do_dma;
|
|||
* w_ioctl *
|
||||
*===========================================================================*/
|
||||
static int w_ioctl(devminor_t minor, unsigned int request, endpoint_t endpt,
|
||||
cp_grant_id_t grant)
|
||||
cp_grant_id_t grant, endpoint_t UNUSED(user_endpt))
|
||||
{
|
||||
int r, timeout, prev, count;
|
||||
struct command cmd;
|
||||
|
|
|
@ -34,7 +34,7 @@ static int cat24c256_blk_close(devminor_t minor);
|
|||
static ssize_t cat24c256_blk_transfer(devminor_t minor, int do_write,
|
||||
u64_t pos, endpoint_t endpt, iovec_t * iov, unsigned int count, int flags);
|
||||
static int cat24c256_blk_ioctl(devminor_t minor, unsigned int request,
|
||||
endpoint_t endpt, cp_grant_id_t grant);
|
||||
endpoint_t endpt, cp_grant_id_t grant, endpoint_t user_endpt);
|
||||
static struct device *cat24c256_blk_part(devminor_t minor);
|
||||
static void cat24c256_blk_other(message * m, int ipc_status);
|
||||
|
||||
|
@ -210,7 +210,7 @@ cat24c256_blk_transfer(devminor_t minor, int do_write, u64_t pos64,
|
|||
|
||||
static int
|
||||
cat24c256_blk_ioctl(devminor_t minor, unsigned int request, endpoint_t endpt,
|
||||
cp_grant_id_t grant)
|
||||
cp_grant_id_t grant, endpoint_t UNUSED(user_endpt))
|
||||
{
|
||||
log_trace(&log, "cat24c256_blk_ioctl(%d)\n", minor);
|
||||
/* no supported ioctls for this device */
|
||||
|
|
|
@ -20,7 +20,7 @@ static int fbd_close(devminor_t minor);
|
|||
static int fbd_transfer(devminor_t minor, int do_write, u64_t position,
|
||||
endpoint_t endpt, iovec_t *iov, unsigned int nr_req, int flags);
|
||||
static int fbd_ioctl(devminor_t minor, unsigned int request, endpoint_t endpt,
|
||||
cp_grant_id_t grant);
|
||||
cp_grant_id_t grant, endpoint_t user_endpt);
|
||||
|
||||
/* Variables. */
|
||||
static char *fbd_buf; /* scratch buffer */
|
||||
|
@ -190,7 +190,7 @@ static int fbd_close(devminor_t UNUSED(minor))
|
|||
* fbd_ioctl *
|
||||
*===========================================================================*/
|
||||
static int fbd_ioctl(devminor_t UNUSED(minor), unsigned int request,
|
||||
endpoint_t endpt, cp_grant_id_t grant)
|
||||
endpoint_t endpt, cp_grant_id_t grant, endpoint_t UNUSED(user_endpt))
|
||||
{
|
||||
/* Handle an I/O control request. */
|
||||
cp_grant_id_t gid;
|
||||
|
@ -215,6 +215,7 @@ static int fbd_ioctl(devminor_t UNUSED(minor), unsigned int request,
|
|||
m.BDEV_MINOR = driver_minor;
|
||||
m.BDEV_REQUEST = request;
|
||||
m.BDEV_GRANT = gid;
|
||||
m.BDEV_USER = NONE;
|
||||
m.BDEV_ID = 0;
|
||||
|
||||
if ((r = sendrec(driver_endpt, &m)) != OK)
|
||||
|
|
|
@ -60,6 +60,7 @@ static int driver_open(int which)
|
|||
msg.BDEV_MINOR = driver[which].minor;
|
||||
msg.BDEV_REQUEST = DIOCGETP;
|
||||
msg.BDEV_GRANT = gid;
|
||||
msg.BDEV_USER = NONE;
|
||||
msg.BDEV_ID = 0;
|
||||
|
||||
r = sendrec(driver[which].endpt, &msg);
|
||||
|
|
|
@ -58,7 +58,7 @@ static int m_block_transfer(devminor_t minor, int do_write, u64_t position,
|
|||
static int m_block_open(devminor_t minor, int access);
|
||||
static int m_block_close(devminor_t minor);
|
||||
static int m_block_ioctl(devminor_t minor, unsigned int request, endpoint_t
|
||||
endpt, cp_grant_id_t grant);
|
||||
endpt, cp_grant_id_t grant, endpoint_t user_endpt);
|
||||
|
||||
/* Entry points to the CHARACTER part of this driver. */
|
||||
static struct chardriver m_cdtab = {
|
||||
|
@ -512,7 +512,7 @@ static int m_block_close(devminor_t minor)
|
|||
* m_block_ioctl *
|
||||
*===========================================================================*/
|
||||
static int m_block_ioctl(devminor_t minor, unsigned int request,
|
||||
endpoint_t endpt, cp_grant_id_t grant)
|
||||
endpoint_t endpt, cp_grant_id_t grant, endpoint_t UNUSED(user_endpt))
|
||||
{
|
||||
/* I/O controls for the block devices of the memory driver. Currently there is
|
||||
* one I/O control specific to the memory driver:
|
||||
|
|
|
@ -49,8 +49,8 @@ static int block_transfer(devminor_t minor,
|
|||
u64_t position,
|
||||
endpoint_t endpt, iovec_t * iov, unsigned int nr_req, int flags);
|
||||
|
||||
static int block_ioctl(devminor_t minor,
|
||||
unsigned int request, endpoint_t endpt, cp_grant_id_t grant);
|
||||
static int block_ioctl(devminor_t minor, unsigned int request,
|
||||
endpoint_t endpt, cp_grant_id_t grant, endpoint_t user_endpt);
|
||||
static struct device *block_part(devminor_t minor);
|
||||
|
||||
/* System even handling */
|
||||
|
@ -435,8 +435,8 @@ block_transfer(
|
|||
* block_ioctl *
|
||||
*===========================================================================*/
|
||||
static int
|
||||
block_ioctl(devminor_t minor,
|
||||
unsigned int request, endpoint_t endpt, cp_grant_id_t grant)
|
||||
block_ioctl(devminor_t minor, unsigned int request, endpoint_t endpt,
|
||||
cp_grant_id_t grant, endpoint_t UNUSED(user_endpt))
|
||||
{
|
||||
/* IOCTL handling */
|
||||
struct sd_slot *slot;
|
||||
|
|
|
@ -168,7 +168,7 @@ static int tda19988_blk_close(devminor_t minor);
|
|||
static ssize_t tda19988_blk_transfer(devminor_t minor, int do_write, u64_t pos,
|
||||
endpoint_t endpt, iovec_t * iov, unsigned int count, int flags);
|
||||
static int tda19988_blk_ioctl(devminor_t minor, unsigned int request,
|
||||
endpoint_t endpt, cp_grant_id_t grant);
|
||||
endpoint_t endpt, cp_grant_id_t grant, endpoint_t user_endpt);
|
||||
static struct device *tda19988_blk_part(devminor_t minor);
|
||||
static void tda19988_blk_other(message * m, int ipc_status);
|
||||
|
||||
|
@ -315,7 +315,7 @@ tda19988_blk_transfer(devminor_t minor, int do_write, u64_t pos64,
|
|||
|
||||
static int
|
||||
tda19988_blk_ioctl(devminor_t minor, unsigned int request, endpoint_t endpt,
|
||||
cp_grant_id_t grant)
|
||||
cp_grant_id_t grant, endpoint_t UNUSED(user_endpt))
|
||||
{
|
||||
log_trace(&log, "tda19988_blk_ioctl(%d)\n", minor);
|
||||
/* no supported ioctls for this device */
|
||||
|
|
|
@ -83,7 +83,7 @@ static ssize_t virtio_blk_transfer(devminor_t minor, int write, u64_t position,
|
|||
endpoint_t endpt, iovec_t *iovec,
|
||||
unsigned int cnt, int flags);
|
||||
static int virtio_blk_ioctl(devminor_t minor, unsigned int req,
|
||||
endpoint_t endpt, cp_grant_id_t grant);
|
||||
endpoint_t endpt, cp_grant_id_t grant, endpoint_t user_endpt);
|
||||
static struct device * virtio_blk_part(devminor_t minor);
|
||||
static void virtio_blk_geometry(devminor_t minor, struct part_geom *entry);
|
||||
static void virtio_blk_device_intr(void);
|
||||
|
@ -376,7 +376,7 @@ virtio_blk_transfer(devminor_t minor, int write, u64_t position,
|
|||
|
||||
static int
|
||||
virtio_blk_ioctl(devminor_t minor, unsigned int req, endpoint_t endpt,
|
||||
cp_grant_id_t grant)
|
||||
cp_grant_id_t grant, endpoint_t UNUSED(user_endpt))
|
||||
{
|
||||
switch (req) {
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@ extern ssize_t bdev_gather(dev_t dev, u64_t pos, iovec_t *vec, int count,
|
|||
int flags);
|
||||
extern ssize_t bdev_scatter(dev_t dev, u64_t pos, iovec_t *vec, int count,
|
||||
int flags);
|
||||
extern int bdev_ioctl(dev_t dev, int request, void *buf);
|
||||
extern int bdev_ioctl(dev_t dev, int request, void *buf,
|
||||
endpoint_t user_endpt);
|
||||
|
||||
/* Asynchronous API. */
|
||||
typedef int bdev_id_t;
|
||||
|
@ -36,7 +37,7 @@ extern bdev_id_t bdev_gather_asyn(dev_t dev, u64_t pos, iovec_t *vec,
|
|||
extern bdev_id_t bdev_scatter_asyn(dev_t dev, u64_t pos, iovec_t *vec,
|
||||
int count, int flags, bdev_callback_t callback, bdev_param_t param);
|
||||
extern bdev_id_t bdev_ioctl_asyn(dev_t dev, int request, void *buf,
|
||||
bdev_callback_t callback, bdev_param_t param);
|
||||
endpoint_t user_endpt, bdev_callback_t callback, bdev_param_t param);
|
||||
|
||||
extern int bdev_wait_asyn(bdev_id_t id);
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ struct blockdriver {
|
|||
ssize_t (*bdr_transfer)(devminor_t minor, int do_write, u64_t pos,
|
||||
endpoint_t endpt, iovec_t *iov, unsigned int count, int flags);
|
||||
int (*bdr_ioctl)(devminor_t minor, unsigned int request, endpoint_t endpt,
|
||||
cp_grant_id_t grant);
|
||||
cp_grant_id_t grant, endpoint_t user_endpt);
|
||||
void (*bdr_cleanup)(void);
|
||||
struct device *(*bdr_part)(devminor_t minor);
|
||||
void (*bdr_geometry)(devminor_t minor, struct part_geom *part);
|
||||
|
|
|
@ -1325,6 +1325,7 @@
|
|||
#define BDEV_COUNT m10_i2 /* number of bytes or elements in transfer */
|
||||
#define BDEV_GRANT m10_i3 /* grant ID of buffer or vector */
|
||||
#define BDEV_FLAGS m10_i4 /* transfer flags */
|
||||
#define BDEV_USER m10_i4 /* user endpoint requesting I/O control */
|
||||
#define BDEV_ID m10_l1 /* opaque request ID */
|
||||
#define BDEV_POS_LO m10_l2 /* transfer position (low bits) */
|
||||
#define BDEV_POS_HI m10_l3 /* transfer position (high bits) */
|
||||
|
|
|
@ -305,7 +305,8 @@ ssize_t bdev_scatter(dev_t dev, u64_t pos, iovec_t *vec, int count, int flags)
|
|||
return bdev_vrdwt(BDEV_SCATTER, dev, pos, vec, count, flags);
|
||||
}
|
||||
|
||||
static int bdev_ioctl_setup(dev_t dev, int request, void *buf, message *m)
|
||||
static int bdev_ioctl_setup(dev_t dev, int request, void *buf,
|
||||
endpoint_t user_endpt, message *m)
|
||||
{
|
||||
/* Set up an I/O control request.
|
||||
*/
|
||||
|
@ -339,6 +340,7 @@ static int bdev_ioctl_setup(dev_t dev, int request, void *buf, message *m)
|
|||
m->BDEV_MINOR = minor(dev);
|
||||
m->BDEV_REQUEST = request;
|
||||
m->BDEV_GRANT = grant;
|
||||
m->BDEV_USER = user_endpt;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
@ -351,7 +353,7 @@ static void bdev_ioctl_cleanup(const message *m)
|
|||
cpf_revoke(m->BDEV_GRANT);
|
||||
}
|
||||
|
||||
int bdev_ioctl(dev_t dev, int request, void *buf)
|
||||
int bdev_ioctl(dev_t dev, int request, void *buf, endpoint_t user_endpt)
|
||||
{
|
||||
/* Perform a synchronous I/O control request.
|
||||
*/
|
||||
|
@ -359,7 +361,7 @@ int bdev_ioctl(dev_t dev, int request, void *buf)
|
|||
int r, driver_tries = 0;
|
||||
|
||||
do {
|
||||
if ((r = bdev_ioctl_setup(dev, request, buf, &m)) != OK)
|
||||
if ((r = bdev_ioctl_setup(dev, request, buf, user_endpt, &m)) != OK)
|
||||
break;
|
||||
|
||||
r = bdev_sendrec(dev, &m);
|
||||
|
@ -496,7 +498,7 @@ bdev_id_t bdev_scatter_asyn(dev_t dev, u64_t pos, iovec_t *vec, int count,
|
|||
}
|
||||
|
||||
bdev_id_t bdev_ioctl_asyn(dev_t dev, int request, void *buf,
|
||||
bdev_callback_t callback, bdev_param_t param)
|
||||
endpoint_t user_endpt, bdev_callback_t callback, bdev_param_t param)
|
||||
{
|
||||
/* Perform an asynchronous I/O control request.
|
||||
*/
|
||||
|
@ -506,7 +508,8 @@ bdev_id_t bdev_ioctl_asyn(dev_t dev, int request, void *buf,
|
|||
if ((call = bdev_call_alloc(1)) == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
if ((r = bdev_ioctl_setup(dev, request, buf, &call->msg)) != OK) {
|
||||
if ((r = bdev_ioctl_setup(dev, request, buf, user_endpt,
|
||||
&call->msg)) != OK) {
|
||||
bdev_call_free(call);
|
||||
|
||||
return r;
|
||||
|
@ -623,7 +626,8 @@ int bdev_restart_asyn(bdev_call_t *call)
|
|||
bdev_ioctl_cleanup(&call->msg);
|
||||
|
||||
r = bdev_ioctl_setup(call->dev, call->msg.BDEV_REQUEST,
|
||||
(char *) call->vec[0].iov_addr, &call->msg);
|
||||
(char *) call->vec[0].iov_addr, call->msg.BDEV_USER,
|
||||
&call->msg);
|
||||
|
||||
break;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Block drivers support the following requests. Message format m10 is used.
|
||||
* Field names are prefixed with BDEV_. Separate field names are used for the
|
||||
* "access" and "request" fields.
|
||||
* "access", "request", and "user" fields.
|
||||
*
|
||||
* m_type MINOR COUNT GRANT FLAGS ID POS_LO POS_HI
|
||||
* +--------------+--------+----------+-------+-------+------+------+------+
|
||||
|
@ -18,7 +18,7 @@
|
|||
* |--------------+--------+----------+-------+-------+------+------+------|
|
||||
* | BDEV_SCATTER | minor | elements | grant | flags | id | position |
|
||||
* |--------------+--------+----------+-------+-------+------+------+------|
|
||||
* | BDEV_IOCTL | minor | request | grant | flags | id | | |
|
||||
* | BDEV_IOCTL | minor | request | grant | user | id | | |
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* The following reply message is used for all requests.
|
||||
|
@ -320,11 +320,13 @@ static int do_ioctl(struct blockdriver *bdp, message *mp)
|
|||
dev_t minor;
|
||||
unsigned int request;
|
||||
cp_grant_id_t grant;
|
||||
endpoint_t user_endpt;
|
||||
int r;
|
||||
|
||||
minor = mp->BDEV_MINOR;
|
||||
request = mp->BDEV_REQUEST;
|
||||
grant = mp->BDEV_GRANT;
|
||||
user_endpt = mp->BDEV_USER;
|
||||
|
||||
switch (request) {
|
||||
case BIOCTRACEBUF:
|
||||
|
@ -348,7 +350,8 @@ static int do_ioctl(struct blockdriver *bdp, message *mp)
|
|||
/* fall-through */
|
||||
default:
|
||||
if (bdp->bdr_ioctl)
|
||||
r = (*bdp->bdr_ioctl)(minor, request, mp->m_source, grant);
|
||||
r = (*bdp->bdr_ioctl)(minor, request, mp->m_source, grant,
|
||||
user_endpt);
|
||||
else
|
||||
r = ENOTTY;
|
||||
}
|
||||
|
|
|
@ -185,6 +185,7 @@ static int bdev_ioctl(dev_t dev, endpoint_t proc_e, int req, void *buf)
|
|||
dev_mess.BDEV_MINOR = minor_dev;
|
||||
dev_mess.BDEV_REQUEST = req;
|
||||
dev_mess.BDEV_GRANT = gid;
|
||||
dev_mess.BDEV_USER = proc_e;
|
||||
dev_mess.BDEV_ID = 0;
|
||||
|
||||
/* Call the task. */
|
||||
|
|
|
@ -1090,10 +1090,9 @@ static int vir_ioctl(dev_t minor, int req, void *ptr, ssize_t exp,
|
|||
memset(&m, 0, sizeof(m));
|
||||
m.m_type = BDEV_IOCTL;
|
||||
m.BDEV_MINOR = minor;
|
||||
m.BDEV_POS_LO = 0L;
|
||||
m.BDEV_POS_HI = 0L;
|
||||
m.BDEV_REQUEST = req;
|
||||
m.BDEV_GRANT = grant;
|
||||
m.BDEV_USER = NONE;
|
||||
m.BDEV_ID = lrand48();
|
||||
|
||||
r = sendrec_driver(&m, exp, res);
|
||||
|
|
Loading…
Reference in a new issue