From 0522c9d0c1a691465e555e62e393e87f5620a692 Mon Sep 17 00:00:00 2001 From: Lionel Sambuc Date: Fri, 25 Jul 2014 20:39:06 +0200 Subject: [PATCH] Message type for BDEV_REPLY. Change-Id: I48ca5a4f77cc9e924e8aee2fe6c32e0da9b42560 --- drivers/fbd/fbd.c | 12 ++++---- drivers/filter/driver.c | 53 ++++++++++++++++++++-------------- include/minix/com.h | 1 - include/minix/ipc.h | 9 ++++++ lib/libbdev/ipc.c | 19 ++++++------ lib/libbdev/minor.c | 6 ++-- lib/libblockdriver/driver.c | 4 +-- lib/libchardriver/chardriver.c | 4 +-- servers/vfs/device.c | 8 ++--- test/blocktest/blocktest.c | 31 ++++++++++++-------- 10 files changed, 87 insertions(+), 60 deletions(-) diff --git a/drivers/fbd/fbd.c b/drivers/fbd/fbd.c index 5ffe9a365..40eb3527e 100644 --- a/drivers/fbd/fbd.c +++ b/drivers/fbd/fbd.c @@ -159,7 +159,7 @@ static int fbd_open(devminor_t UNUSED(minor), int access) if (m.m_type != BDEV_REPLY) panic("invalid reply from driver (%d)\n", m.m_type); - return m.BDEV_STATUS; + return m.m_lblockdriver_lbdev_reply.status; } /*===========================================================================* @@ -183,7 +183,7 @@ static int fbd_close(devminor_t UNUSED(minor)) if (m.m_type != BDEV_REPLY) panic("invalid reply from driver (%d)\n", m.m_type); - return m.BDEV_STATUS; + return m.m_lblockdriver_lbdev_reply.status; } /*===========================================================================* @@ -226,7 +226,7 @@ static int fbd_ioctl(devminor_t UNUSED(minor), unsigned long request, cpf_revoke(gid); - return m.BDEV_STATUS; + return m.m_lblockdriver_lbdev_reply.status; } /*===========================================================================* @@ -271,7 +271,7 @@ static ssize_t fbd_transfer_direct(int do_write, u64_t position, for (i = 0; i < count; i++) cpf_revoke(iovec[i].iov_grant); - return m.BDEV_STATUS; + return m.m_lblockdriver_lbdev_reply.status; } /*===========================================================================* @@ -369,7 +369,7 @@ static ssize_t fbd_transfer_copy(int do_write, u64_t position, rule_io_hook(ptr, size, position, FBD_FLAG_READ); /* Upon success, copy back whatever has been processed. */ - rsize = m.BDEV_STATUS; + rsize = m.m_lblockdriver_lbdev_reply.status; for (i = j = off = 0; rsize > 0 && i < count; i++) { len = MIN(rsize, iov[i].iov_size); @@ -392,7 +392,7 @@ static ssize_t fbd_transfer_copy(int do_write, u64_t position, if (ptr != fbd_buf) free_contig(ptr, size); - return m.BDEV_STATUS; + return m.m_lblockdriver_lbdev_reply.status; } /*===========================================================================* diff --git a/drivers/filter/driver.c b/drivers/filter/driver.c index e4cf2128f..be0e9c460 100644 --- a/drivers/filter/driver.c +++ b/drivers/filter/driver.c @@ -42,9 +42,10 @@ static int driver_open(int which) return RET_REDO; } - if(msg.m_type != BDEV_REPLY || msg.BDEV_STATUS != OK) { + if(msg.m_type != BDEV_REPLY || + msg.m_lblockdriver_lbdev_reply.status != OK) { printf("Filter: driver_open: ipc_sendrec returned %d, %d\n", - msg.m_type, msg.BDEV_STATUS); + msg.m_type, msg.m_lblockdriver_lbdev_reply.status); return RET_REDO; } @@ -67,7 +68,8 @@ static int driver_open(int which) cpf_revoke(gid); - if (r != OK || msg.m_type != BDEV_REPLY || msg.BDEV_STATUS != OK) { + if (r != OK || msg.m_type != BDEV_REPLY || + msg.m_lblockdriver_lbdev_reply.status != OK) { /* Not sure what to do here, either. */ printf("Filter: ioctl(DIOCGETP) returned (%d, %d)\n", r, msg.m_type); @@ -122,9 +124,10 @@ static int driver_close(int which) return RET_REDO; } - if(msg.m_type != BDEV_REPLY || msg.BDEV_STATUS != OK) { + if(msg.m_type != BDEV_REPLY || + msg.m_lblockdriver_lbdev_reply.status != OK) { printf("Filter: driver_close: ipc_sendrec returned %d, %d\n", - msg.m_type, msg.BDEV_STATUS); + msg.m_type, msg.m_lblockdriver_lbdev_reply.status); return RET_REDO; } @@ -938,52 +941,60 @@ int read_write(u64_t pos, char *bufa, char *bufb, size_t *sizep, int request) return r; } - if (m1.m_type != BDEV_REPLY || m1.BDEV_STATUS < 0) { + if (m1.m_type != BDEV_REPLY || + m1.m_lblockdriver_lbdev_reply.status < 0) { printf("Filter: unexpected/invalid reply from main driver: " - "(%x, %d)\n", m1.m_type, m1.BDEV_STATUS); + "(%x, %d)\n", m1.m_type, + m1.m_lblockdriver_lbdev_reply.status); return bad_driver(DRIVER_MAIN, BD_PROTO, - (m1.m_type == BDEV_REPLY) ? m1.BDEV_STATUS : EFAULT); + (m1.m_type == BDEV_REPLY) ? + m1.m_lblockdriver_lbdev_reply.status : EFAULT); } - if (m1.BDEV_STATUS != (ssize_t) *sizep) { + if (m1.m_lblockdriver_lbdev_reply.status != (ssize_t) *sizep) { printf("Filter: truncated reply from main driver\n"); /* If the driver returned a value *larger* than we requested, * OR if we did NOT exceed the disk size, then we should * report the driver for acting strangely! */ - if (m1.BDEV_STATUS > (ssize_t) *sizep || - (pos + (unsigned int) m1.BDEV_STATUS < disk_size)) + if (m1.m_lblockdriver_lbdev_reply.status > (ssize_t) *sizep || + (pos + (unsigned int) + m1.m_lblockdriver_lbdev_reply.status < disk_size)) return bad_driver(DRIVER_MAIN, BD_PROTO, EFAULT); /* Return the actual size. */ - *sizep = m1.BDEV_STATUS; + *sizep = m1.m_lblockdriver_lbdev_reply.status; } if (both) { - if (m2.m_type != BDEV_REPLY || m2.BDEV_STATUS < 0) { + if (m2.m_type != BDEV_REPLY || + m2.m_lblockdriver_lbdev_reply.status < 0) { printf("Filter: unexpected/invalid reply from " "backup driver (%x, %d)\n", - m2.m_type, m2.BDEV_STATUS); + m2.m_type, + m2.m_lblockdriver_lbdev_reply.status); return bad_driver(DRIVER_BACKUP, BD_PROTO, - m2.m_type == BDEV_REPLY ? m2.BDEV_STATUS : + m2.m_type == BDEV_REPLY ? + m2.m_lblockdriver_lbdev_reply.status : EFAULT); } - if (m2.BDEV_STATUS != (ssize_t) *sizep) { + if (m2.m_lblockdriver_lbdev_reply.status != (ssize_t) *sizep) { printf("Filter: truncated reply from backup driver\n"); /* As above */ - if (m2.BDEV_STATUS > (ssize_t) *sizep || - (pos + (unsigned int) m2.BDEV_STATUS < - disk_size)) + if (m2.m_lblockdriver_lbdev_reply.status > (ssize_t) *sizep || + (pos + (unsigned int) + m2.m_lblockdriver_lbdev_reply.status + < disk_size)) return bad_driver(DRIVER_BACKUP, BD_PROTO, EFAULT); /* Return the actual size. */ - if ((ssize_t) *sizep >= m2.BDEV_STATUS) - *sizep = m2.BDEV_STATUS; + if ((ssize_t)*sizep >= m2.m_lblockdriver_lbdev_reply.status) + *sizep = m2.m_lblockdriver_lbdev_reply.status; } } diff --git a/include/minix/com.h b/include/minix/com.h index e4d9da24f..7756c58b3 100644 --- a/include/minix/com.h +++ b/include/minix/com.h @@ -928,7 +928,6 @@ /* Field names for block device messages. */ #define BDEV_MINOR m10_i1 /* minor device number */ -#define BDEV_STATUS m10_i1 /* OK or error code */ #define BDEV_ACCESS m10_i2 /* access bits for open requests */ #define BDEV_COUNT m10_i2 /* number of bytes or elements in transfer */ #define BDEV_GRANT m10_i3 /* grant ID of buffer or vector */ diff --git a/include/minix/ipc.h b/include/minix/ipc.h index 4de52c274..7b1667e0a 100644 --- a/include/minix/ipc.h +++ b/include/minix/ipc.h @@ -124,6 +124,14 @@ typedef struct { } mess_lsys_krn_readbios; _ASSERT_MSG_SIZE(mess_lsys_krn_readbios); +typedef struct { + int status; + int id; + + uint8_t padding[48]; +} mess_lblockdriver_lbdev_reply; +_ASSERT_MSG_SIZE(mess_lblockdriver_lbdev_reply); + typedef struct { int action; int freq; @@ -2032,6 +2040,7 @@ typedef struct { mess_notify m_notify; mess_sigcalls m_sigcalls; + mess_lblockdriver_lbdev_reply m_lblockdriver_lbdev_reply; mess_lc_pm_cprof m_lc_pm_cprof; mess_lc_pm_sprof m_lc_pm_sprof; mess_lsys_krn_sys_diagctl m_lsys_krn_sys_diagctl; diff --git a/lib/libbdev/ipc.c b/lib/libbdev/ipc.c index ed92ebf7a..53ce3977c 100644 --- a/lib/libbdev/ipc.c +++ b/lib/libbdev/ipc.c @@ -185,8 +185,9 @@ int bdev_sendrec(dev_t dev, const message *m_orig) /* The protocol contract states that no asynchronous reply can satisfy a * synchronous SENDREC call, so we can never get an asynchronous reply here. */ - if (m.BDEV_ID != NO_ID) { - printf("bdev: driver (%d) sent invalid ID (%ld)\n", endpt, m.BDEV_ID); + if (m.m_lblockdriver_lbdev_reply.id != NO_ID) { + printf("bdev: driver (%d) sent invalid ID (%d)\n", endpt, + m.m_lblockdriver_lbdev_reply.id); return EINVAL; } @@ -198,7 +199,7 @@ int bdev_sendrec(dev_t dev, const message *m_orig) * device, and then resend the request. If the call keeps failing, the caller * will eventually give up. */ - if (m.BDEV_STATUS == ERESTART) { + if (m.m_lblockdriver_lbdev_reply.status == ERESTART) { printf("bdev: got ERESTART from driver (%d), sleeping for reopen\n", endpt); @@ -208,7 +209,7 @@ int bdev_sendrec(dev_t dev, const message *m_orig) } /* Return the result of our request. */ - return m.BDEV_STATUS; + return m.m_lblockdriver_lbdev_reply.status; } static int bdev_receive(dev_t dev, message *m) @@ -278,11 +279,11 @@ void bdev_reply_asyn(message *m) assert(m->m_type == BDEV_REPLY); /* Get the corresponding asynchronous call structure. */ - id = m->BDEV_ID; + id = m->m_lblockdriver_lbdev_reply.id; if ((call = bdev_call_get(id)) == NULL) { - printf("bdev: driver (%d) replied to unknown request (%ld)\n", - m->m_source, m->BDEV_ID); + printf("bdev: driver (%d) replied to unknown request (%d)\n", + m->m_source, m->m_lblockdriver_lbdev_reply.id); return; } @@ -298,7 +299,7 @@ void bdev_reply_asyn(message *m) } /* See the ERESTART comment in bdev_sendrec(). */ - if (m->BDEV_STATUS == ERESTART) { + if (m->m_lblockdriver_lbdev_reply.status == ERESTART) { printf("bdev: got ERESTART from driver (%d), sleeping for reopen\n", endpt); @@ -310,7 +311,7 @@ void bdev_reply_asyn(message *m) return; } - bdev_callback_asyn(call, m->BDEV_STATUS); + bdev_callback_asyn(call, m->m_lblockdriver_lbdev_reply.status); } int bdev_wait_asyn(bdev_id_t id) diff --git a/lib/libbdev/minor.c b/lib/libbdev/minor.c index fc5af9817..4f1aeb74e 100644 --- a/lib/libbdev/minor.c +++ b/lib/libbdev/minor.c @@ -58,13 +58,13 @@ int bdev_minor_reopen(dev_t dev) return EINVAL; } - if (m.BDEV_ID != NO_ID) { + if (m.m_lblockdriver_lbdev_reply.id != NO_ID) { printf("bdev: driver (%d) sent invalid ID (%ld)\n", - endpt, m.BDEV_ID); + endpt, m.m_lblockdriver_lbdev_reply.id); return EINVAL; } - if ((r = m.BDEV_STATUS) != OK) { + if ((r = m.m_lblockdriver_lbdev_reply.status) != OK) { printf("bdev: driver (%d) failed device reopen (%d)\n", endpt, r); return r; diff --git a/lib/libblockdriver/driver.c b/lib/libblockdriver/driver.c index 55e716f49..fd55aa7c3 100644 --- a/lib/libblockdriver/driver.c +++ b/lib/libblockdriver/driver.c @@ -161,8 +161,8 @@ void blockdriver_reply(message *m_ptr, int ipc_status, int reply) memset(&m_reply, 0, sizeof(m_reply)); m_reply.m_type = BDEV_REPLY; - m_reply.BDEV_STATUS = reply; - m_reply.BDEV_ID = m_ptr->BDEV_ID; + m_reply.m_lblockdriver_lbdev_reply.status = reply; + m_reply.m_lblockdriver_lbdev_reply.id = m_ptr->BDEV_ID; send_reply(m_ptr->m_source, &m_reply, ipc_status); } diff --git a/lib/libchardriver/chardriver.c b/lib/libchardriver/chardriver.c index 0890d5bf8..292eb4dcd 100644 --- a/lib/libchardriver/chardriver.c +++ b/lib/libchardriver/chardriver.c @@ -442,8 +442,8 @@ static void do_block_open(message *m_ptr, int ipc_status) memset(&m_reply, 0, sizeof(m_reply)); m_reply.m_type = BDEV_REPLY; - m_reply.BDEV_STATUS = ENXIO; - m_reply.BDEV_ID = m_ptr->BDEV_ID; + m_reply.m_lblockdriver_lbdev_reply.status = ENXIO; + m_reply.m_lblockdriver_lbdev_reply.id = m_ptr->BDEV_ID; send_reply(m_ptr->m_source, &m_reply, ipc_status); } diff --git a/servers/vfs/device.c b/servers/vfs/device.c index d9ea8f29d..06eec3984 100644 --- a/servers/vfs/device.c +++ b/servers/vfs/device.c @@ -67,7 +67,7 @@ int bdev_open(dev_t dev, int access) if (r != OK) return r; - return dev_mess.BDEV_STATUS; + return dev_mess.m_lblockdriver_lbdev_reply.status; } @@ -96,7 +96,7 @@ int bdev_close(dev_t dev) if (r != OK) return r; - return dev_mess.BDEV_STATUS; + return dev_mess.m_lblockdriver_lbdev_reply.status; } @@ -147,7 +147,7 @@ static int bdev_ioctl(dev_t dev, endpoint_t proc_e, unsigned long req, if (r != OK) return(r); - return(dev_mess.BDEV_STATUS); + return(dev_mess.m_lblockdriver_lbdev_reply.status); } @@ -623,7 +623,7 @@ static int block_io(endpoint_t driver_e, message *mess_ptr) if (r != OK) return r; - status = mess_ptr->BDEV_STATUS; + status = mess_ptr->m_lblockdriver_lbdev_reply.status; if (status == ERESTART) { r = EDEADEPT; *mess_ptr = mess_retry; diff --git a/test/blocktest/blocktest.c b/test/blocktest/blocktest.c index 14563185d..ffd9f3f98 100644 --- a/test/blocktest/blocktest.c +++ b/test/blocktest/blocktest.c @@ -279,12 +279,15 @@ static int sendrec_driver(message *m_ptr, ssize_t exp, result_t *res) if (m_ptr->m_type != BDEV_REPLY) return set_result(res, RESULT_BADTYPE, m_ptr->m_type); - if (m_ptr->BDEV_ID != m_orig.BDEV_ID) - return set_result(res, RESULT_BADID, m_ptr->BDEV_ID); + if (m_ptr->m_lblockdriver_lbdev_reply.id != m_orig.BDEV_ID) + return set_result(res, RESULT_BADID, + m_ptr->m_lblockdriver_lbdev_reply.id); - if ((exp < 0 && m_ptr->BDEV_STATUS >= 0) || - (exp >= 0 && m_ptr->BDEV_STATUS < 0)) - return set_result(res, RESULT_BADSTATUS, m_ptr->BDEV_STATUS); + if ((exp < 0 && m_ptr->m_lblockdriver_lbdev_reply.status >= 0) || + (exp >= 0 && + m_ptr->m_lblockdriver_lbdev_reply.status < 0)) + return set_result(res, RESULT_BADSTATUS, + m_ptr->m_lblockdriver_lbdev_reply.status); return set_result(res, RESULT_OK, 0); } @@ -321,13 +324,15 @@ static void raw_xfer(dev_t minor, u64_t pos, iovec_s_t *iovec, int nr_req, if (r != RESULT_OK) return; - if (m.BDEV_STATUS == exp) + if (m.m_lblockdriver_lbdev_reply.status == exp) return; if (exp < 0) - set_result(res, RESULT_BADSTATUS, m.BDEV_STATUS); + set_result(res, RESULT_BADSTATUS, + m.m_lblockdriver_lbdev_reply.status); else - set_result(res, RESULT_TRUNC, exp - m.BDEV_STATUS); + set_result(res, RESULT_TRUNC, + exp - m.m_lblockdriver_lbdev_reply.status); } static void vir_xfer(dev_t minor, u64_t pos, iovec_t *iovec, int nr_req, @@ -439,9 +444,10 @@ static void bad_read1(void) sendrec_driver(&m, OK, &res); - if (res.type == RESULT_OK && m.BDEV_STATUS != (ssize_t) iov.iov_size) { + if (res.type == RESULT_OK && + m.m_lblockdriver_lbdev_reply.status != (ssize_t) iov.iov_size) { res.type = RESULT_TRUNC; - res.value = m.BDEV_STATUS; + res.value = m.m_lblockdriver_lbdev_reply.status; } got_result(&res, "normal request"); @@ -489,9 +495,10 @@ static void bad_read1(void) sendrec_driver(&m, OK, &res); - if (res.type == RESULT_OK && m.BDEV_STATUS != (ssize_t) iov.iov_size) { + if (res.type == RESULT_OK && + m.m_lblockdriver_lbdev_reply.status != (ssize_t) iov.iov_size) { res.type = RESULT_TRUNC; - res.value = m.BDEV_STATUS; + res.value = m.m_lblockdriver_lbdev_reply.status; } got_result(&res, "normal request"); -- 2.44.0