[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 33/40] ivshmem: Inline check_shm_size() into its
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH v3 33/40] ivshmem: Inline check_shm_size() into its only caller |
Date: |
Tue, 15 Mar 2016 19:34:48 +0100 |
Improve the error messages while there.
Signed-off-by: Markus Armbruster <address@hidden>
---
hw/misc/ivshmem.c | 37 +++++++++++--------------------------
1 file changed, 11 insertions(+), 26 deletions(-)
diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index 1b1de65..e6282ab 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -343,29 +343,6 @@ static void watch_vector_notifier(IVShmemState *s,
EventNotifier *n,
NULL, &s->msi_vectors[vector]);
}
-static int check_shm_size(IVShmemState *s, int fd, Error **errp)
-{
- /* check that the guest isn't going to try and map more memory than the
- * the object has allocated return -1 to indicate error */
-
- struct stat buf;
-
- if (fstat(fd, &buf) < 0) {
- error_setg(errp, "exiting: fstat on fd %d failed: %s",
- fd, strerror(errno));
- return -1;
- }
-
- if (s->ivshmem_size > buf.st_size) {
- error_setg(errp, "Requested memory size greater"
- " than shared object size (%zu > %" PRIu64")",
- s->ivshmem_size, (uint64_t)buf.st_size);
- return -1;
- } else {
- return 0;
- }
-}
-
static void ivshmem_add_eventfd(IVShmemState *s, int posn, int i)
{
memory_region_add_eventfd(&s->ivshmem_mmio,
@@ -480,7 +457,7 @@ static void setup_interrupt(IVShmemState *s, int vector,
Error **errp)
static void process_msg_shmem(IVShmemState *s, int fd, Error **errp)
{
- Error *err = NULL;
+ struct stat buf;
void *ptr;
if (s->ivshmem_bar2) {
@@ -489,8 +466,16 @@ static void process_msg_shmem(IVShmemState *s, int fd,
Error **errp)
return;
}
- if (check_shm_size(s, fd, &err) == -1) {
- error_propagate(errp, err);
+ if (fstat(fd, &buf) < 0) {
+ error_setg_errno(errp, errno,
+ "can't determine size of shared memory sent by server");
+ close(fd);
+ return;
+ }
+
+ if (s->ivshmem_size > buf.st_size) {
+ error_setg(errp, "server sent only %zd bytes of shared memory",
+ (size_t)buf.st_size);
close(fd);
return;
}
--
2.4.3
- [Qemu-devel] [PATCH v3 17/40] ivshmem: Failed realize() can leave migration blocker behind, (continued)
- [Qemu-devel] [PATCH v3 17/40] ivshmem: Failed realize() can leave migration blocker behind, Markus Armbruster, 2016/03/15
- [Qemu-devel] [PATCH v3 20/40] ivshmem: Leave INTx alone when using MSI-X, Markus Armbruster, 2016/03/15
- [Qemu-devel] [PATCH v3 25/40] ivshmem: Receive shared memory synchronously in realize(), Markus Armbruster, 2016/03/15
- [Qemu-devel] [PATCH v3 18/40] ivshmem: Clean up register callbacks, Markus Armbruster, 2016/03/15
- [Qemu-devel] [PATCH v3 11/40] ivshmem: Add missing newlines to debug printfs, Markus Armbruster, 2016/03/15
- [Qemu-devel] [PATCH v3 23/40] ivshmem: Disentangle ivshmem_read(), Markus Armbruster, 2016/03/15
- [Qemu-devel] [PATCH v3 22/40] ivshmem: Simplify rejection of invalid peer ID from server, Markus Armbruster, 2016/03/15
- [Qemu-devel] [PATCH v3 35/40] ivshmem: Replace int role_val by OnOffAuto master, Markus Armbruster, 2016/03/15
- [Qemu-devel] [PATCH v3 15/40] ivshmem: Don't destroy the chardev on version mismatch, Markus Armbruster, 2016/03/15
- [Qemu-devel] [PATCH v3 21/40] ivshmem: Assert interrupts are set up once, Markus Armbruster, 2016/03/15
- [Qemu-devel] [PATCH v3 33/40] ivshmem: Inline check_shm_size() into its only caller,
Markus Armbruster <=
- [Qemu-devel] [PATCH v3 40/40] contrib/ivshmem-server: Print "not for production" warning, Markus Armbruster, 2016/03/15
- [Qemu-devel] [PATCH v3 27/40] ivshmem: Rely on server sending the ID right after the version, Markus Armbruster, 2016/03/15
- [Qemu-devel] [PATCH v3 26/40] ivshmem: Propagate errors through ivshmem_recv_setup(), Markus Armbruster, 2016/03/15
- [Qemu-devel] [PATCH v3 10/40] ivshmem: Rewrite specification document, Markus Armbruster, 2016/03/15
- [Qemu-devel] [PATCH v3 36/40] ivshmem: Split ivshmem-plain, ivshmem-doorbell off ivshmem, Markus Armbruster, 2016/03/15
- [Qemu-devel] [PATCH v3 30/40] ivshmem: Tighten check of property "size", Markus Armbruster, 2016/03/15