Message type for BDEV_REPLY.

Change-Id: I48ca5a4f77cc9e924e8aee2fe6c32e0da9b42560
This commit is contained in:
Lionel Sambuc 2014-07-25 20:39:06 +02:00
parent 8644f25feb
commit 0522c9d0c1
10 changed files with 87 additions and 60 deletions

View file

@ -159,7 +159,7 @@ static int fbd_open(devminor_t UNUSED(minor), int access)
if (m.m_type != BDEV_REPLY) if (m.m_type != BDEV_REPLY)
panic("invalid reply from driver (%d)\n", m.m_type); 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) if (m.m_type != BDEV_REPLY)
panic("invalid reply from driver (%d)\n", m.m_type); 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); 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++) for (i = 0; i < count; i++)
cpf_revoke(iovec[i].iov_grant); 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); rule_io_hook(ptr, size, position, FBD_FLAG_READ);
/* Upon success, copy back whatever has been processed. */ /* 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++) { for (i = j = off = 0; rsize > 0 && i < count; i++) {
len = MIN(rsize, iov[i].iov_size); 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) if (ptr != fbd_buf)
free_contig(ptr, size); free_contig(ptr, size);
return m.BDEV_STATUS; return m.m_lblockdriver_lbdev_reply.status;
} }
/*===========================================================================* /*===========================================================================*

View file

@ -42,9 +42,10 @@ static int driver_open(int which)
return RET_REDO; 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", 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; return RET_REDO;
} }
@ -67,7 +68,8 @@ static int driver_open(int which)
cpf_revoke(gid); 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. */ /* Not sure what to do here, either. */
printf("Filter: ioctl(DIOCGETP) returned (%d, %d)\n", printf("Filter: ioctl(DIOCGETP) returned (%d, %d)\n",
r, msg.m_type); r, msg.m_type);
@ -122,9 +124,10 @@ static int driver_close(int which)
return RET_REDO; 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", 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; return RET_REDO;
} }
@ -938,52 +941,60 @@ int read_write(u64_t pos, char *bufa, char *bufb, size_t *sizep, int request)
return r; 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: " 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, 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"); printf("Filter: truncated reply from main driver\n");
/* If the driver returned a value *larger* than we requested, /* If the driver returned a value *larger* than we requested,
* OR if we did NOT exceed the disk size, then we should * OR if we did NOT exceed the disk size, then we should
* report the driver for acting strangely! * report the driver for acting strangely!
*/ */
if (m1.BDEV_STATUS > (ssize_t) *sizep || if (m1.m_lblockdriver_lbdev_reply.status > (ssize_t) *sizep ||
(pos + (unsigned int) m1.BDEV_STATUS < disk_size)) (pos + (unsigned int)
m1.m_lblockdriver_lbdev_reply.status < disk_size))
return bad_driver(DRIVER_MAIN, BD_PROTO, EFAULT); return bad_driver(DRIVER_MAIN, BD_PROTO, EFAULT);
/* Return the actual size. */ /* Return the actual size. */
*sizep = m1.BDEV_STATUS; *sizep = m1.m_lblockdriver_lbdev_reply.status;
} }
if (both) { 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 " printf("Filter: unexpected/invalid reply from "
"backup driver (%x, %d)\n", "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, 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); 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"); printf("Filter: truncated reply from backup driver\n");
/* As above */ /* As above */
if (m2.BDEV_STATUS > (ssize_t) *sizep || if (m2.m_lblockdriver_lbdev_reply.status > (ssize_t) *sizep ||
(pos + (unsigned int) m2.BDEV_STATUS < (pos + (unsigned int)
disk_size)) m2.m_lblockdriver_lbdev_reply.status
< disk_size))
return bad_driver(DRIVER_BACKUP, BD_PROTO, return bad_driver(DRIVER_BACKUP, BD_PROTO,
EFAULT); EFAULT);
/* Return the actual size. */ /* Return the actual size. */
if ((ssize_t) *sizep >= m2.BDEV_STATUS) if ((ssize_t)*sizep >= m2.m_lblockdriver_lbdev_reply.status)
*sizep = m2.BDEV_STATUS; *sizep = m2.m_lblockdriver_lbdev_reply.status;
} }
} }

View file

@ -928,7 +928,6 @@
/* Field names for block device messages. */ /* Field names for block device messages. */
#define BDEV_MINOR m10_i1 /* minor device number */ #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_ACCESS m10_i2 /* access bits for open requests */
#define BDEV_COUNT m10_i2 /* number of bytes or elements in transfer */ #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_GRANT m10_i3 /* grant ID of buffer or vector */

View file

@ -124,6 +124,14 @@ typedef struct {
} mess_lsys_krn_readbios; } mess_lsys_krn_readbios;
_ASSERT_MSG_SIZE(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 { typedef struct {
int action; int action;
int freq; int freq;
@ -2032,6 +2040,7 @@ typedef struct {
mess_notify m_notify; mess_notify m_notify;
mess_sigcalls m_sigcalls; mess_sigcalls m_sigcalls;
mess_lblockdriver_lbdev_reply m_lblockdriver_lbdev_reply;
mess_lc_pm_cprof m_lc_pm_cprof; mess_lc_pm_cprof m_lc_pm_cprof;
mess_lc_pm_sprof m_lc_pm_sprof; mess_lc_pm_sprof m_lc_pm_sprof;
mess_lsys_krn_sys_diagctl m_lsys_krn_sys_diagctl; mess_lsys_krn_sys_diagctl m_lsys_krn_sys_diagctl;

View file

@ -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 /* The protocol contract states that no asynchronous reply can satisfy a
* synchronous SENDREC call, so we can never get an asynchronous reply here. * synchronous SENDREC call, so we can never get an asynchronous reply here.
*/ */
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); printf("bdev: driver (%d) sent invalid ID (%d)\n", endpt,
m.m_lblockdriver_lbdev_reply.id);
return EINVAL; 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 * device, and then resend the request. If the call keeps failing, the caller
* will eventually give up. * 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", printf("bdev: got ERESTART from driver (%d), sleeping for reopen\n",
endpt); endpt);
@ -208,7 +209,7 @@ int bdev_sendrec(dev_t dev, const message *m_orig)
} }
/* Return the result of our request. */ /* 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) 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); assert(m->m_type == BDEV_REPLY);
/* Get the corresponding asynchronous call structure. */ /* Get the corresponding asynchronous call structure. */
id = m->BDEV_ID; id = m->m_lblockdriver_lbdev_reply.id;
if ((call = bdev_call_get(id)) == NULL) { if ((call = bdev_call_get(id)) == NULL) {
printf("bdev: driver (%d) replied to unknown request (%ld)\n", printf("bdev: driver (%d) replied to unknown request (%d)\n",
m->m_source, m->BDEV_ID); m->m_source, m->m_lblockdriver_lbdev_reply.id);
return; return;
} }
@ -298,7 +299,7 @@ void bdev_reply_asyn(message *m)
} }
/* See the ERESTART comment in bdev_sendrec(). */ /* 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", printf("bdev: got ERESTART from driver (%d), sleeping for reopen\n",
endpt); endpt);
@ -310,7 +311,7 @@ void bdev_reply_asyn(message *m)
return; 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) int bdev_wait_asyn(bdev_id_t id)

View file

@ -58,13 +58,13 @@ int bdev_minor_reopen(dev_t dev)
return EINVAL; 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", printf("bdev: driver (%d) sent invalid ID (%ld)\n",
endpt, m.BDEV_ID); endpt, m.m_lblockdriver_lbdev_reply.id);
return EINVAL; 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", printf("bdev: driver (%d) failed device reopen (%d)\n",
endpt, r); endpt, r);
return r; return r;

View file

@ -161,8 +161,8 @@ void blockdriver_reply(message *m_ptr, int ipc_status, int reply)
memset(&m_reply, 0, sizeof(m_reply)); memset(&m_reply, 0, sizeof(m_reply));
m_reply.m_type = BDEV_REPLY; m_reply.m_type = BDEV_REPLY;
m_reply.BDEV_STATUS = reply; m_reply.m_lblockdriver_lbdev_reply.status = reply;
m_reply.BDEV_ID = m_ptr->BDEV_ID; m_reply.m_lblockdriver_lbdev_reply.id = m_ptr->BDEV_ID;
send_reply(m_ptr->m_source, &m_reply, ipc_status); send_reply(m_ptr->m_source, &m_reply, ipc_status);
} }

View file

@ -442,8 +442,8 @@ static void do_block_open(message *m_ptr, int ipc_status)
memset(&m_reply, 0, sizeof(m_reply)); memset(&m_reply, 0, sizeof(m_reply));
m_reply.m_type = BDEV_REPLY; m_reply.m_type = BDEV_REPLY;
m_reply.BDEV_STATUS = ENXIO; m_reply.m_lblockdriver_lbdev_reply.status = ENXIO;
m_reply.BDEV_ID = m_ptr->BDEV_ID; m_reply.m_lblockdriver_lbdev_reply.id = m_ptr->BDEV_ID;
send_reply(m_ptr->m_source, &m_reply, ipc_status); send_reply(m_ptr->m_source, &m_reply, ipc_status);
} }

View file

@ -67,7 +67,7 @@ int bdev_open(dev_t dev, int access)
if (r != OK) if (r != OK)
return r; 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) if (r != OK)
return r; 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) if (r != OK)
return(r); 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) if (r != OK)
return r; return r;
status = mess_ptr->BDEV_STATUS; status = mess_ptr->m_lblockdriver_lbdev_reply.status;
if (status == ERESTART) { if (status == ERESTART) {
r = EDEADEPT; r = EDEADEPT;
*mess_ptr = mess_retry; *mess_ptr = mess_retry;

View file

@ -279,12 +279,15 @@ static int sendrec_driver(message *m_ptr, ssize_t exp, result_t *res)
if (m_ptr->m_type != BDEV_REPLY) if (m_ptr->m_type != BDEV_REPLY)
return set_result(res, RESULT_BADTYPE, m_ptr->m_type); return set_result(res, RESULT_BADTYPE, m_ptr->m_type);
if (m_ptr->BDEV_ID != m_orig.BDEV_ID) if (m_ptr->m_lblockdriver_lbdev_reply.id != m_orig.BDEV_ID)
return set_result(res, RESULT_BADID, m_ptr->BDEV_ID); return set_result(res, RESULT_BADID,
m_ptr->m_lblockdriver_lbdev_reply.id);
if ((exp < 0 && m_ptr->BDEV_STATUS >= 0) || if ((exp < 0 && m_ptr->m_lblockdriver_lbdev_reply.status >= 0) ||
(exp >= 0 && m_ptr->BDEV_STATUS < 0)) (exp >= 0 &&
return set_result(res, RESULT_BADSTATUS, m_ptr->BDEV_STATUS); 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); 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) if (r != RESULT_OK)
return; return;
if (m.BDEV_STATUS == exp) if (m.m_lblockdriver_lbdev_reply.status == exp)
return; return;
if (exp < 0) if (exp < 0)
set_result(res, RESULT_BADSTATUS, m.BDEV_STATUS); set_result(res, RESULT_BADSTATUS,
m.m_lblockdriver_lbdev_reply.status);
else 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, 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); 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.type = RESULT_TRUNC;
res.value = m.BDEV_STATUS; res.value = m.m_lblockdriver_lbdev_reply.status;
} }
got_result(&res, "normal request"); got_result(&res, "normal request");
@ -489,9 +495,10 @@ static void bad_read1(void)
sendrec_driver(&m, OK, &res); 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.type = RESULT_TRUNC;
res.value = m.BDEV_STATUS; res.value = m.m_lblockdriver_lbdev_reply.status;
} }
got_result(&res, "normal request"); got_result(&res, "normal request");