From: David van Moolenbroek Date: Fri, 26 Jul 2013 22:49:49 +0000 (+0200) Subject: Block protocol: add user endpoint to IOCTL request X-Git-Tag: v3.3.0~592 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/index.css?a=commitdiff_plain;h=95624ae072fe1aad7bce9f6e144b7dc3b94abb71;p=minix.git 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 --- diff --git a/drivers/ahci/ahci.c b/drivers/ahci/ahci.c index a695702ee..b3dfc59f9 100644 --- a/drivers/ahci/ahci.c +++ b/drivers/ahci/ahci.c @@ -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. */ diff --git a/drivers/at_wini/at_wini.c b/drivers/at_wini/at_wini.c index dc87257cb..e33ed009b 100644 --- a/drivers/at_wini/at_wini.c +++ b/drivers/at_wini/at_wini.c @@ -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; diff --git a/drivers/cat24c256/cat24c256.c b/drivers/cat24c256/cat24c256.c index fbd4eb081..5a97ca091 100644 --- a/drivers/cat24c256/cat24c256.c +++ b/drivers/cat24c256/cat24c256.c @@ -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 */ diff --git a/drivers/fbd/fbd.c b/drivers/fbd/fbd.c index 9b0dbdc4d..6e86eb934 100644 --- a/drivers/fbd/fbd.c +++ b/drivers/fbd/fbd.c @@ -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) diff --git a/drivers/filter/driver.c b/drivers/filter/driver.c index 131ccbd78..478c3e597 100644 --- a/drivers/filter/driver.c +++ b/drivers/filter/driver.c @@ -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); diff --git a/drivers/memory/memory.c b/drivers/memory/memory.c index 3c8e5bdef..45bf5bdb7 100644 --- a/drivers/memory/memory.c +++ b/drivers/memory/memory.c @@ -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: diff --git a/drivers/mmc/mmcblk.c b/drivers/mmc/mmcblk.c index 71ce29a1d..8a6353f54 100644 --- a/drivers/mmc/mmcblk.c +++ b/drivers/mmc/mmcblk.c @@ -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; diff --git a/drivers/tda19988/tda19988.c b/drivers/tda19988/tda19988.c index 551ee4f9e..8e2225a52 100644 --- a/drivers/tda19988/tda19988.c +++ b/drivers/tda19988/tda19988.c @@ -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 */ diff --git a/drivers/virtio_blk/virtio_blk.c b/drivers/virtio_blk/virtio_blk.c index cef52ee46..5a13619c6 100644 --- a/drivers/virtio_blk/virtio_blk.c +++ b/drivers/virtio_blk/virtio_blk.c @@ -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) { diff --git a/include/minix/bdev.h b/include/minix/bdev.h index dce412a4c..0aca2887a 100644 --- a/include/minix/bdev.h +++ b/include/minix/bdev.h @@ -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); diff --git a/include/minix/blockdriver.h b/include/minix/blockdriver.h index 3bc058cf3..0c172182b 100644 --- a/include/minix/blockdriver.h +++ b/include/minix/blockdriver.h @@ -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); diff --git a/include/minix/com.h b/include/minix/com.h index 520836722..2bf4be570 100644 --- a/include/minix/com.h +++ b/include/minix/com.h @@ -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) */ diff --git a/lib/libbdev/bdev.c b/lib/libbdev/bdev.c index f8eafb9c9..b4037f963 100644 --- a/lib/libbdev/bdev.c +++ b/lib/libbdev/bdev.c @@ -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; diff --git a/lib/libblockdriver/driver.c b/lib/libblockdriver/driver.c index 04a095df0..aadc9b0a3 100644 --- a/lib/libblockdriver/driver.c +++ b/lib/libblockdriver/driver.c @@ -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; } diff --git a/servers/vfs/device.c b/servers/vfs/device.c index 7e7111c36..090f3aa36 100644 --- a/servers/vfs/device.c +++ b/servers/vfs/device.c @@ -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. */ diff --git a/test/blocktest/blocktest.c b/test/blocktest/blocktest.c index ee0f149e7..8f12f25bf 100644 --- a/test/blocktest/blocktest.c +++ b/test/blocktest/blocktest.c @@ -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);