Skip to contentSkip to conversation

ivshmem: use error_report

PATCH Superseded Andrew Jones 2 participants 3 messages Sep 18, 2014

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ivshmem: use error_report

Replace all the fprintf(stderr, ...) calls with error_report.

---
 hw/misc/ivshmem.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)
hw/misc/ivshmem.c +13 -14
index bf585b7691998..d285df7d65a9f 100644
@@ -300,7 +300,7 @@ static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier *
     chr = qemu_chr_open_eventfd(eventfd);
 
     if (chr == NULL) {
-        fprintf(stderr, "creating eventfd for eventfd %d failed\n", eventfd);
+        error_report("creating eventfd for eventfd %d failed\n", eventfd);
         exit(-1);
     }
     qemu_chr_fe_claim_no_fail(chr);
@@ -328,14 +328,13 @@ static int check_shm_size(IVShmemState *s, int fd) {
     struct stat buf;
 
     if (fstat(fd, &buf) < 0) {
-        fprintf(stderr, "ivshmem: exiting: fstat on fd %d failed: %s\n",
+        error_report("exiting: fstat on fd %d failed: %s\n",
                 fd, strerror(errno));
         return -1;
     }
 
     if (s->ivshmem_size > buf.st_size) {
-        fprintf(stderr,
-                "IVSHMEM ERROR: Requested memory size greater"
+        error_report("Requested memory size greater"
                 " than shared object size (%" PRIu64 " > %" PRIu64")\n",
                 s->ivshmem_size, (uint64_t)buf.st_size);
         return -1;
@@ -510,7 +509,7 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
     incoming_fd = dup(tmp_fd);
 
     if (incoming_fd == -1) {
-        fprintf(stderr, "could not allocate file descriptor %s\n",
+        error_report("could not allocate file descriptor %s\n",
                                                             strerror(errno));
         close(tmp_fd);
         return;
@@ -618,13 +617,13 @@ static uint64_t ivshmem_get_size(IVShmemState * s) {
             value <<= 30;
             break;
         default:
-            fprintf(stderr, "qemu: invalid ram size: %s\n", s->sizearg);
+            error_report("invalid ram size: %s\n", s->sizearg);
             exit(1);
     }
 
     /* BARs must be a power of 2 */
     if (!is_power_of_two(value)) {
-        fprintf(stderr, "ivshmem: size must be power of 2\n");
+        error_report("size must be power of 2\n");
         exit(1);
     }
 
@@ -676,7 +675,7 @@ static int ivshmem_load(QEMUFile* f, void *opaque, int version_id)
     }
 
     if (proxy->role_val == IVSHMEM_PEER) {
-        fprintf(stderr, "ivshmem: 'peer' devices are not migratable\n");
+        error_report("'peer' devices are not migratable\n");
         return -EINVAL;
     }
 
@@ -722,7 +721,7 @@ static int pci_ivshmem_init(PCIDevice *dev)
     /* IRQFD requires MSI */
     if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD) &&
         !ivshmem_has_feature(s, IVSHMEM_MSI)) {
-        fprintf(stderr, "ivshmem: ioeventfd/irqfd requires MSI\n");
+        error_report("ioeventfd/irqfd requires MSI\n");
         exit(1);
     }
 
@@ -733,7 +732,7 @@ static int pci_ivshmem_init(PCIDevice *dev)
         } else if (strncmp(s->role, "master", 7) == 0) {
             s->role_val = IVSHMEM_MASTER;
         } else {
-            fprintf(stderr, "ivshmem: 'role' must be 'peer' or 'master'\n");
+            error_report("'role' must be 'peer' or 'master'\n");
             exit(1);
         }
     } else {
@@ -773,7 +772,7 @@ static int pci_ivshmem_init(PCIDevice *dev)
          * to the ivshmem server to receive the memory region */
 
         if (s->shmobj != NULL) {
-            fprintf(stderr, "WARNING: do not specify both 'chardev' "
+            error_report("WARNING: do not specify both 'chardev' "
                                                 "and 'shm' with ivshmem\n");
         }
 
@@ -802,7 +801,7 @@ static int pci_ivshmem_init(PCIDevice *dev)
         int fd;
 
         if (s->shmobj == NULL) {
-            fprintf(stderr, "Must specify 'chardev' or 'shm' to ivshmem\n");
+            error_report("Must specify 'chardev' or 'shm' to ivshmem\n");
             exit(1);
         }
 
@@ -814,12 +813,12 @@ static int pci_ivshmem_init(PCIDevice *dev)
                         S_IRWXU|S_IRWXG|S_IRWXO)) > 0) {
            /* truncate file to length PCI device's memory */
             if (ftruncate(fd, s->ivshmem_size) != 0) {
-                fprintf(stderr, "ivshmem: could not truncate shared file\n");
+                error_report("could not truncate shared file\n");
             }
 
         } else if ((fd = shm_open(s->shmobj, O_CREAT|O_RDWR,
                         S_IRWXU|S_IRWXG|S_IRWXO)) < 0) {
-            fprintf(stderr, "ivshmem: could not open shared file\n");
+            error_report("could not open shared file\n");
             exit(-1);
 
         }
Signature · 1 line
1.9.3
#1 lore raw
Quoted 12 lines · Andrew Jones

Replace all the fprintf(stderr, ...) calls with error_report.

---
 hw/misc/ivshmem.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)
hw/misc/ivshmem.c +0 -0
index bf585b7691998..d285df7d65a9f 100644

hw/misc/ivshmem.c static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier * · line 303

Quoted 5 lines
hw/misc/ivshmem.c +1 -1
@@ -300,7 +300,7 @@ static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier *
     chr = qemu_chr_open_eventfd(eventfd);
 
     if (chr == NULL) {
-        fprintf(stderr, "creating eventfd for eventfd %d failed\n", eventfd);
+        error_report("creating eventfd for eventfd %d failed\n", eventfd);

The conversion to error_report() should also drop trailing \n.

hw/misc/ivshmem.c static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier * · line 304

Quoted 1 line
hw/misc/ivshmem.c +0 -0
         exit(-1);

Another bug (but probably worth cleaning up in a separate patch) - exit(-1) is the same as exit(255), which is not a usual exit status (although it DOES make xargs behave differently).

hw/misc/ivshmem.c static uint64_t ivshmem_get_size(IVShmemState * s) { · line 627

Quoted 5 lines
hw/misc/ivshmem.c +1 -1
     /* BARs must be a power of 2 */
     if (!is_power_of_two(value)) {
-        fprintf(stderr, "ivshmem: size must be power of 2\n");
+        error_report("size must be power of 2\n");
         exit(1);

But seeing as how much of this file uses the more typical exit(1), we should consistently use 1 in all places where we exit early.

hw/misc/ivshmem.c static int pci_ivshmem_init(PCIDevice *dev) · line 822

Quoted 5 lines
         } else if ((fd = shm_open(s->shmobj, O_CREAT|O_RDWR,
                         S_IRWXU|S_IRWXG|S_IRWXO)) < 0) {
hw/misc/ivshmem.c +1 -1
-            fprintf(stderr, "ivshmem: could not open shared file\n");
+            error_report("could not open shared file\n");
             exit(-1);

Another weird use of exit(-1).

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 15 lines · Eric Blake
Quoted 14 lines · Andrew Jones

Replace all the fprintf(stderr, ...) calls with error_report.

---
 hw/misc/ivshmem.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)
hw/misc/ivshmem.c +0 -0
index bf585b7691998..d285df7d65a9f 100644
@@ -300,7 +300,7 @@ static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier *
     chr = qemu_chr_open_eventfd(eventfd);
 
Quoted 5 lines

hw/misc/ivshmem.c static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier * · line 303

Quoted 3 lines
hw/misc/ivshmem.c +1 -1
     if (chr == NULL) {
-        fprintf(stderr, "creating eventfd for eventfd %d failed\n", eventfd);
+        error_report("creating eventfd for eventfd %d failed\n", eventfd);

The conversion to error_report() should also drop trailing \n.

Thanks for the quick review. I'll send a v2 with this change.

Quoted 6 lines

hw/misc/ivshmem.c static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier * · line 304

Quoted 2 lines
hw/misc/ivshmem.c +0 -0
         exit(-1);

Another bug (but probably worth cleaning up in a separate patch) - exit(-1) is the same as exit(255), which is not a usual exit status (although it DOES make xargs behave differently).

I'll go ahead an squeeze a s/-1/1/ exit code change into this patch too. I think it's a similar enough cleanup.

Quoted 23 lines

hw/misc/ivshmem.c static uint64_t ivshmem_get_size(IVShmemState * s) { · line 627

Quoted 7 lines
hw/misc/ivshmem.c +1 -1
     /* BARs must be a power of 2 */
     if (!is_power_of_two(value)) {
-        fprintf(stderr, "ivshmem: size must be power of 2\n");
+        error_report("size must be power of 2\n");
         exit(1);

But seeing as how much of this file uses the more typical exit(1), we should consistently use 1 in all places where we exit early.

hw/misc/ivshmem.c static int pci_ivshmem_init(PCIDevice *dev) · line 822

Quoted 5 lines
         } else if ((fd = shm_open(s->shmobj, O_CREAT|O_RDWR,
                         S_IRWXU|S_IRWXG|S_IRWXO)) < 0) {
hw/misc/ivshmem.c +1 -1
-            fprintf(stderr, "ivshmem: could not open shared file\n");
+            error_report("could not open shared file\n");
             exit(-1);

Another weird use of exit(-1).

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org