ivshmem: use error_report

Replace all the fprintf(stderr, ...) calls with error_report.
Also make sure exit() consistently uses the error code 1. A few calls
used -1. While at it cleanup some indentation in the printf argument
lists.

Signed-off-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Andrew Jones 2014-10-07 13:24:02 +02:00 committed by Paolo Bonzini
parent 3a31cff112
commit dbc464d401

View File

@ -300,8 +300,8 @@ static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier *
chr = qemu_chr_open_eventfd(eventfd); chr = qemu_chr_open_eventfd(eventfd);
if (chr == NULL) { if (chr == NULL) {
fprintf(stderr, "creating eventfd for eventfd %d failed\n", eventfd); error_report("creating eventfd for eventfd %d failed", eventfd);
exit(-1); exit(1);
} }
qemu_chr_fe_claim_no_fail(chr); qemu_chr_fe_claim_no_fail(chr);
@ -328,15 +328,14 @@ static int check_shm_size(IVShmemState *s, int fd) {
struct stat buf; struct stat buf;
if (fstat(fd, &buf) < 0) { 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",
fd, strerror(errno)); fd, strerror(errno));
return -1; return -1;
} }
if (s->ivshmem_size > buf.st_size) { if (s->ivshmem_size > buf.st_size) {
fprintf(stderr, error_report("Requested memory size greater"
"IVSHMEM ERROR: Requested memory size greater" " than shared object size (%" PRIu64 " > %" PRIu64")",
" than shared object size (%" PRIu64 " > %" PRIu64")\n",
s->ivshmem_size, (uint64_t)buf.st_size); s->ivshmem_size, (uint64_t)buf.st_size);
return -1; return -1;
} else { } else {
@ -510,8 +509,7 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
incoming_fd = dup(tmp_fd); incoming_fd = dup(tmp_fd);
if (incoming_fd == -1) { if (incoming_fd == -1) {
fprintf(stderr, "could not allocate file descriptor %s\n", error_report("could not allocate file descriptor %s", strerror(errno));
strerror(errno));
close(tmp_fd); close(tmp_fd);
return; return;
} }
@ -524,7 +522,7 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
s->max_peer = 0; s->max_peer = 0;
if (check_shm_size(s, incoming_fd) == -1) { if (check_shm_size(s, incoming_fd) == -1) {
exit(-1); exit(1);
} }
/* mmap the region and map into the BAR2 */ /* mmap the region and map into the BAR2 */
@ -618,13 +616,13 @@ static uint64_t ivshmem_get_size(IVShmemState * s) {
value <<= 30; value <<= 30;
break; break;
default: default:
fprintf(stderr, "qemu: invalid ram size: %s\n", s->sizearg); error_report("invalid ram size: %s", s->sizearg);
exit(1); exit(1);
} }
/* BARs must be a power of 2 */ /* BARs must be a power of 2 */
if (!is_power_of_two(value)) { if (!is_power_of_two(value)) {
fprintf(stderr, "ivshmem: size must be power of 2\n"); error_report("size must be power of 2");
exit(1); exit(1);
} }
@ -676,7 +674,7 @@ static int ivshmem_load(QEMUFile* f, void *opaque, int version_id)
} }
if (proxy->role_val == IVSHMEM_PEER) { if (proxy->role_val == IVSHMEM_PEER) {
fprintf(stderr, "ivshmem: 'peer' devices are not migratable\n"); error_report("'peer' devices are not migratable");
return -EINVAL; return -EINVAL;
} }
@ -722,7 +720,7 @@ static int pci_ivshmem_init(PCIDevice *dev)
/* IRQFD requires MSI */ /* IRQFD requires MSI */
if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD) && if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD) &&
!ivshmem_has_feature(s, IVSHMEM_MSI)) { !ivshmem_has_feature(s, IVSHMEM_MSI)) {
fprintf(stderr, "ivshmem: ioeventfd/irqfd requires MSI\n"); error_report("ioeventfd/irqfd requires MSI");
exit(1); exit(1);
} }
@ -733,7 +731,7 @@ static int pci_ivshmem_init(PCIDevice *dev)
} else if (strncmp(s->role, "master", 7) == 0) { } else if (strncmp(s->role, "master", 7) == 0) {
s->role_val = IVSHMEM_MASTER; s->role_val = IVSHMEM_MASTER;
} else { } else {
fprintf(stderr, "ivshmem: 'role' must be 'peer' or 'master'\n"); error_report("'role' must be 'peer' or 'master'");
exit(1); exit(1);
} }
} else { } else {
@ -773,8 +771,8 @@ static int pci_ivshmem_init(PCIDevice *dev)
* to the ivshmem server to receive the memory region */ * to the ivshmem server to receive the memory region */
if (s->shmobj != NULL) { 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"); "and 'shm' with ivshmem");
} }
IVSHMEM_DPRINTF("using shared memory server (socket = %s)\n", IVSHMEM_DPRINTF("using shared memory server (socket = %s)\n",
@ -802,7 +800,7 @@ static int pci_ivshmem_init(PCIDevice *dev)
int fd; int fd;
if (s->shmobj == NULL) { if (s->shmobj == NULL) {
fprintf(stderr, "Must specify 'chardev' or 'shm' to ivshmem\n"); error_report("Must specify 'chardev' or 'shm' to ivshmem");
exit(1); exit(1);
} }
@ -814,18 +812,18 @@ static int pci_ivshmem_init(PCIDevice *dev)
S_IRWXU|S_IRWXG|S_IRWXO)) > 0) { S_IRWXU|S_IRWXG|S_IRWXO)) > 0) {
/* truncate file to length PCI device's memory */ /* truncate file to length PCI device's memory */
if (ftruncate(fd, s->ivshmem_size) != 0) { if (ftruncate(fd, s->ivshmem_size) != 0) {
fprintf(stderr, "ivshmem: could not truncate shared file\n"); error_report("could not truncate shared file");
} }
} else if ((fd = shm_open(s->shmobj, O_CREAT|O_RDWR, } else if ((fd = shm_open(s->shmobj, O_CREAT|O_RDWR,
S_IRWXU|S_IRWXG|S_IRWXO)) < 0) { S_IRWXU|S_IRWXG|S_IRWXO)) < 0) {
fprintf(stderr, "ivshmem: could not open shared file\n"); error_report("could not open shared file");
exit(-1); exit(1);
} }
if (check_shm_size(s, fd) == -1) { if (check_shm_size(s, fd) == -1) {
exit(-1); exit(1);
} }
create_shared_memory_BAR(s, fd); create_shared_memory_BAR(s, fd);