Message ID | 20180601162749.27406-6-marcandre.lureau@redhat.com |
---|---|
State | New |
Headers | show |
Series | vhost-user for input & GPU | expand |
On 06/01/2018 01:27 PM, Marc-André Lureau wrote: > Split vhost_user_read(), so only header can be read with > vhost_user_read_header(). > > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> > --- > hw/virtio/vhost-user.c | 27 +++++++++++++++++++-------- > 1 file changed, 19 insertions(+), 8 deletions(-) > > diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c > index cc9298792d..a87db01e55 100644 > --- a/hw/virtio/vhost-user.c > +++ b/hw/virtio/vhost-user.c > @@ -196,7 +196,7 @@ static bool ioeventfd_enabled(void) > return kvm_enabled() && kvm_eventfds_enabled(); > } > > -static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) > +static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg) Can this be simply: static int vhost_user_read_header(CharBackend *chr, VhostUserMsg *msg) ? > { > struct vhost_user *u = dev->opaque; > CharBackend *chr = u->chr; > @@ -207,7 +207,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) > if (r != size) { > error_report("Failed to read msg header. Read %d instead of %d." > " Original request %d.", r, size, msg->hdr.request); > - goto fail; > + return -1; > } > > /* validate received flags */ > @@ -215,7 +215,21 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) > error_report("Failed to read msg header." > " Flags 0x%x instead of 0x%x.", msg->hdr.flags, > VHOST_USER_REPLY_MASK | VHOST_USER_VERSION); > - goto fail; > + return -1; > + } > + > + return 0; > +} > + > +static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) > +{ > + struct vhost_user *u = dev->opaque; > + CharBackend *chr = u->chr; > + uint8_t *p = (uint8_t *) msg; > + int r, size; > + > + if (vhost_user_read_header(dev, msg) < 0) { > + return -1; > } > > /* validate message size is sane */ > @@ -223,7 +237,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) > error_report("Failed to read msg header." > " Size %d exceeds the maximum %zu.", msg->hdr.size, > VHOST_USER_PAYLOAD_SIZE); > - goto fail; > + return -1; > } > > if (msg->hdr.size) { > @@ -233,14 +247,11 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) > if (r != size) { > error_report("Failed to read msg payload." > " Read %d instead of %d.", r, msg->hdr.size); > - goto fail; > + return -1; > } > } > > return 0; > - > -fail: > - return -1; > } > > static int process_message_reply(struct vhost_dev *dev, >
Hi On Fri, Jun 8, 2018 at 4:57 PM, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote: > On 06/01/2018 01:27 PM, Marc-André Lureau wrote: >> Split vhost_user_read(), so only header can be read with >> vhost_user_read_header(). >> >> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> >> --- >> hw/virtio/vhost-user.c | 27 +++++++++++++++++++-------- >> 1 file changed, 19 insertions(+), 8 deletions(-) >> >> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c >> index cc9298792d..a87db01e55 100644 >> --- a/hw/virtio/vhost-user.c >> +++ b/hw/virtio/vhost-user.c >> @@ -196,7 +196,7 @@ static bool ioeventfd_enabled(void) >> return kvm_enabled() && kvm_eventfds_enabled(); >> } >> >> -static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) >> +static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg) > > Can this be simply: > > static int vhost_user_read_header(CharBackend *chr, VhostUserMsg *msg) ? It's more convenient and uniform with vhost_user_read() and friends if it takes vhost_dev as argument. You can also see in patch "vhost-user: add vhost_user_input_get_config()" that vhost_user_read_header() is called fromwithout CharBackend* as variable in the caller. >> { >> struct vhost_user *u = dev->opaque; >> CharBackend *chr = u->chr; >> @@ -207,7 +207,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) >> if (r != size) { >> error_report("Failed to read msg header. Read %d instead of %d." >> " Original request %d.", r, size, msg->hdr.request); >> - goto fail; >> + return -1; >> } >> >> /* validate received flags */ >> @@ -215,7 +215,21 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) >> error_report("Failed to read msg header." >> " Flags 0x%x instead of 0x%x.", msg->hdr.flags, >> VHOST_USER_REPLY_MASK | VHOST_USER_VERSION); >> - goto fail; >> + return -1; >> + } >> + >> + return 0; >> +} >> + >> +static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) >> +{ >> + struct vhost_user *u = dev->opaque; >> + CharBackend *chr = u->chr; >> + uint8_t *p = (uint8_t *) msg; >> + int r, size; >> + >> + if (vhost_user_read_header(dev, msg) < 0) { >> + return -1; >> } >> >> /* validate message size is sane */ >> @@ -223,7 +237,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) >> error_report("Failed to read msg header." >> " Size %d exceeds the maximum %zu.", msg->hdr.size, >> VHOST_USER_PAYLOAD_SIZE); >> - goto fail; >> + return -1; >> } >> >> if (msg->hdr.size) { >> @@ -233,14 +247,11 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) >> if (r != size) { >> error_report("Failed to read msg payload." >> " Read %d instead of %d.", r, msg->hdr.size); >> - goto fail; >> + return -1; >> } >> } >> >> return 0; >> - >> -fail: >> - return -1; >> } >> >> static int process_message_reply(struct vhost_dev *dev, >>
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index cc9298792d..a87db01e55 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -196,7 +196,7 @@ static bool ioeventfd_enabled(void) return kvm_enabled() && kvm_eventfds_enabled(); } -static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) +static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg) { struct vhost_user *u = dev->opaque; CharBackend *chr = u->chr; @@ -207,7 +207,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) if (r != size) { error_report("Failed to read msg header. Read %d instead of %d." " Original request %d.", r, size, msg->hdr.request); - goto fail; + return -1; } /* validate received flags */ @@ -215,7 +215,21 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) error_report("Failed to read msg header." " Flags 0x%x instead of 0x%x.", msg->hdr.flags, VHOST_USER_REPLY_MASK | VHOST_USER_VERSION); - goto fail; + return -1; + } + + return 0; +} + +static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) +{ + struct vhost_user *u = dev->opaque; + CharBackend *chr = u->chr; + uint8_t *p = (uint8_t *) msg; + int r, size; + + if (vhost_user_read_header(dev, msg) < 0) { + return -1; } /* validate message size is sane */ @@ -223,7 +237,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) error_report("Failed to read msg header." " Size %d exceeds the maximum %zu.", msg->hdr.size, VHOST_USER_PAYLOAD_SIZE); - goto fail; + return -1; } if (msg->hdr.size) { @@ -233,14 +247,11 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) if (r != size) { error_report("Failed to read msg payload." " Read %d instead of %d.", r, msg->hdr.size); - goto fail; + return -1; } } return 0; - -fail: - return -1; } static int process_message_reply(struct vhost_dev *dev,
Split vhost_user_read(), so only header can be read with vhost_user_read_header(). Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- hw/virtio/vhost-user.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)