Skip to contentSkip to conversation

replace some fprintf(stderr, ...) with error_report()

PATCH Applied Le Tan 3 participants 8 messages May 21, 2014 – May 24, 2014 Block layer

v1 of 4 Applied Latest is v4 →

lore
Share & tools
lore

Le Tan

author
#0 lore raw

cover replace some fprintf(stderr, ...) with error_report()

This series of patches replaces some more occurrences of fprintf(stderr, ...) with error_report() and removes the trailing "\n". Those for debugging are not changed.

Le Tan (2):
arch_init: replace fprintf(stderr,...) with error_report()
block: replace fprintf(stderr,...) with error_report()

 arch_init.c            |   32 +++++++-------
 block-migration.c      |    5 +--
 block.c                |    4 +-
 block/qcow2-refcount.c |  114 ++++++++++++++++++++++++------------------------
 block/qcow2.c          |   18 ++++----
 block/raw-posix.c      |   10 ++---
 block/raw-win32.c      |    6 +--
 block/ssh.c            |    2 +-
 block/vdi.c            |   15 ++++---
 block/vmdk.c           |   15 +++----
 block/vpc.c            |    4 +-
 block/vvfat.c          |   69 +++++++++++++++--------------
 blockdev.c             |    6 +--
 13 files changed, 147 insertions(+), 153 deletions(-)
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH 1/2 arch_init: replace fprintf(stderr, ...) with error_report()

Replace fprintf(stderr,...) with error_report() in the file arch_init.c. The trailing "\n"s of the @fmt argument have been removed because @fmt of error_report() should not contain newline.

---
 arch_init.c |   32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)
arch_init.c +15 -17
index 685ba0e..9f1a174 100644
@@ -975,12 +975,12 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host)
     xh_len = qemu_get_be16(f);
 
     if (xh_flags != ENCODING_FLAG_XBZRLE) {
-        fprintf(stderr, "Failed to load XBZRLE page - wrong compression!\n");
+        error_report("Failed to load XBZRLE page - wrong compression!");
         return -1;
     }
 
     if (xh_len > TARGET_PAGE_SIZE) {
-        fprintf(stderr, "Failed to load XBZRLE page - len overflow!\n");
+        error_report("Failed to load XBZRLE page - len overflow!");
         return -1;
     }
     /* load data and decode */
@@ -989,7 +989,7 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host)
     /* decode RLE */
     if (xbzrle_decode_buffer(xbzrle_decoded_buf, xh_len, host,
                              TARGET_PAGE_SIZE) == -1) {
-        fprintf(stderr, "Failed to load XBZRLE page - decode error!\n");
+        error_report("Failed to load XBZRLE page - decode error!");
         return -1;
     }
 
@@ -1006,7 +1006,7 @@ static inline void *host_from_stream_offset(QEMUFile *f,
 
     if (flags & RAM_SAVE_FLAG_CONTINUE) {
         if (!block) {
-            fprintf(stderr, "Ack, bad migration stream!\n");
+            error_report("Ack, bad migration stream!");
             return NULL;
         }
 
@@ -1022,7 +1022,7 @@ static inline void *host_from_stream_offset(QEMUFile *f,
             return memory_region_get_ram_ptr(block->mr) + offset;
     }
 
-    fprintf(stderr, "Can't find block %s!\n", id);
+    error_report("Can't find block %s!", id);
     return NULL;
 }
 
@@ -1075,10 +1075,9 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
                 QTAILQ_FOREACH(block, &ram_list.blocks, next) {
                     if (!strncmp(id, block->idstr, sizeof(id))) {
                         if (block->length != length) {
-                            fprintf(stderr,
-                                    "Length mismatch: %s: " RAM_ADDR_FMT
-                                    " in != " RAM_ADDR_FMT "\n", id, length,
-                                    block->length);
+                            error_report("Length mismatch: %s: " RAM_ADDR_FMT
+                                         " in != " RAM_ADDR_FMT, id, length,
+                                         block->length);
                             ret =  -EINVAL;
                             goto done;
                         }
@@ -1087,8 +1086,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
                 }
 
                 if (!block) {
-                    fprintf(stderr, "Unknown ramblock \"%s\", cannot "
-                            "accept migration\n", id);
+                    error_report("Unknown ramblock \"%s\", cannot "
+                                 "accept migration", id);
                     ret = -EINVAL;
                     goto done;
                 }
@@ -1243,12 +1242,11 @@ void select_soundhw(const char *optarg)
 
             if (!c->name) {
                 if (l > 80) {
-                    fprintf(stderr,
-                            "Unknown sound card name (too big to show)\n");
+                    error_report("Unknown sound card name (too big to show)");
                 }
                 else {
-                    fprintf(stderr, "Unknown sound card name `%.*s'\n",
-                            (int) l, p);
+                    error_report("Unknown sound card name `%.*s'",
+                                 (int) l, p);
                 }
                 bad_card = 1;
             }
@@ -1271,13 +1269,13 @@ void audio_init(void)
         if (c->enabled) {
             if (c->isa) {
                 if (!isa_bus) {
-                    fprintf(stderr, "ISA bus not available for %s\n", c->name);
+                    error_report("ISA bus not available for %s", c->name);
                     exit(1);
                 }
                 c->init.init_isa(isa_bus);
             } else {
                 if (!pci_bus) {
-                    fprintf(stderr, "PCI bus not available for %s\n", c->name);
+                    error_report("PCI bus not available for %s", c->name);
                     exit(1);
                 }
                 c->init.init_pci(pci_bus);
Signature · 1 line
1.7.9.5
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] arch_init: replace fprintf(stderr, ...) with error_report()

Am 21.05.2014 02:10, schrieb Le Tan:

Quoted 8 lines

Replace fprintf(stderr,...) with error_report() in the file arch_init.c. The trailing "\n"s of the @fmt argument have been removed because @fmt of error_report() should not contain newline.

---
 arch_init.c |   32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)

Regards,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw

Re: [Qemu-devel] [Qemu-trivial] [PATCH 1/2] arch_init: replace fprintf(stderr, ...) with error_report()

In reply to Le Tan
Quoted 3 lines · 21.05.2014 04:10, Le Tan wrote:

Replace fprintf(stderr,...) with error_report() in the file arch_init.c. The trailing "\n"s of the @fmt argument have been removed because @fmt of error_report() should not contain newline.

Applied to -trivial queue. Thank you for the work!

/mjt

author
#4 lore raw

PATCH 2/2 block: replace fprintf(stderr, ...) with error_report()

In reply to Le Tan

Replace fprintf(stderr,...) with error_report() in files block/*, block.c, block-migration.c and blockdev.c. The trailing "\n"s of the @fmt argument have been removed because @fmt of error_report() should not contain newline.

---
 block-migration.c      |    5 +--
 block.c                |    4 +-
 block/qcow2-refcount.c |  114 ++++++++++++++++++++++++------------------------
 block/qcow2.c          |   18 ++++----
 block/raw-posix.c      |   10 ++---
 block/raw-win32.c      |    6 +--
 block/ssh.c            |    2 +-
 block/vdi.c            |   15 ++++---
 block/vmdk.c           |   15 +++----
 block/vpc.c            |    4 +-
 block/vvfat.c          |   69 +++++++++++++++--------------
 blockdev.c             |    6 +--
 12 files changed, 132 insertions(+), 136 deletions(-)
block-migration.c +2 -3
index 56951e0..1660565 100644
@@ -790,8 +790,7 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
 
             bs = bdrv_find(device_name);
             if (!bs) {
-                fprintf(stderr, "Error unknown block device %s\n",
-                        device_name);
+                error_report("Error unknown block device %s", device_name);
                 return -EINVAL;
             }
 
@@ -833,7 +832,7 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
                    (addr == 100) ? '\n' : '\r');
             fflush(stdout);
         } else if (!(flags & BLK_MIG_FLAG_EOS)) {
-            fprintf(stderr, "Unknown block migration flags: %#x\n", flags);
+            error_report("Unknown block migration flags: %#x", flags);
             return -EINVAL;
         }
         ret = qemu_file_get_error(f);
block.c +2 -2
index c90c71a..14f581b 100644
@@ -2698,8 +2698,8 @@ static int bdrv_prwv_co(BlockDriverState *bs, int64_t offset,
      * if it has been enabled.
      */
     if (bs->io_limits_enabled) {
-        fprintf(stderr, "Disabling I/O throttling on '%s' due "
-                        "to synchronous I/O.\n", bdrv_get_device_name(bs));
+        error_report("Disabling I/O throttling on '%s' due "
+                     "to synchronous I/O.", bdrv_get_device_name(bs));
         bdrv_io_limits_disable(bs);
     }
 
block/qcow2-refcount.c +57 -57

254 lines not on this page · raw message

block/qcow2.c +9 -9
index a4b97e8..38da14d 100644
@@ -2225,12 +2225,12 @@ static int qcow2_amend_options(BlockDriverState *bs,
             } else if (!strcmp(options[i].value.s, "1.1")) {
                 new_version = 3;
             } else {
-                fprintf(stderr, "Unknown compatibility level %s.\n",
-                        options[i].value.s);
+                error_report("Unknown compatibility level %s.",
+                             options[i].value.s);
                 return -EINVAL;
             }
         } else if (!strcmp(options[i].name, "preallocation")) {
-            fprintf(stderr, "Cannot change preallocation mode.\n");
+            error_report("Cannot change preallocation mode.");
             return -ENOTSUP;
         } else if (!strcmp(options[i].name, "size")) {
             new_size = options[i].value.n;
@@ -2240,14 +2240,14 @@ static int qcow2_amend_options(BlockDriverState *bs,
             backing_format = options[i].value.s;
         } else if (!strcmp(options[i].name, "encryption")) {
             if ((options[i].value.n != !!s->crypt_method)) {
-                fprintf(stderr, "Changing the encryption flag is not "
-                        "supported.\n");
+                error_report("Changing the encryption flag is not "
+                             "supported.");
                 return -ENOTSUP;
             }
         } else if (!strcmp(options[i].name, "cluster_size")) {
             if (options[i].value.n != s->cluster_size) {
-                fprintf(stderr, "Changing the cluster size is not "
-                        "supported.\n");
+                error_report("Changing the cluster size is not "
+                             "supported.");
                 return -ENOTSUP;
             }
         } else if (!strcmp(options[i].name, "lazy_refcounts")) {
@@ -2287,8 +2287,8 @@ static int qcow2_amend_options(BlockDriverState *bs,
     if (s->use_lazy_refcounts != lazy_refcounts) {
         if (lazy_refcounts) {
             if (s->qcow_version < 3) {
-                fprintf(stderr, "Lazy refcounts only supported with compatibility "
-                        "level 1.1 and above (use compat=1.1 or greater)\n");
+                error_report("Lazy refcounts only supported with compatibility "
+                             "level 1.1 and above (use compat=1.1 or greater)");
                 return -EINVAL;
             }
             s->compatible_features |= QCOW2_COMPAT_LAZY_REFCOUNTS;
block/raw-posix.c +5 -5
index 6586a0c..bd8b65e 100644
@@ -190,8 +190,8 @@ static int raw_normalize_devicepath(const char **filename)
     fname = *filename;
     dp = strrchr(fname, '/');
     if (lstat(fname, &sb) < 0) {
-        fprintf(stderr, "%s: stat failed: %s\n",
-            fname, strerror(errno));
+        error_report("%s: stat failed: %s",
+                     fname, strerror(errno));
         return -errno;
     }
 
@@ -205,9 +205,9 @@ static int raw_normalize_devicepath(const char **filename)
         snprintf(namebuf, PATH_MAX, "%.*s/r%s",
             (int)(dp - fname), fname, dp + 1);
     }
-    fprintf(stderr, "%s is a block device", fname);
+    
     *filename = namebuf;
-    fprintf(stderr, ", using %s\n", *filename);
+    error_report("%s is a block device, using %s", fname, *filename);
 
     return 0;
 }
@@ -945,7 +945,7 @@ static int aio_worker(void *arg)
         ret = handle_aiocb_write_zeroes(aiocb);
         break;
     default:
-        fprintf(stderr, "invalid aio request (0x%x)\n", aiocb->aio_type);
+        error_report("invalid aio request (0x%x)", aiocb->aio_type);
         ret = -EINVAL;
         break;
     }
block/raw-win32.c +3 -3
index 064ea31..5f67285 100644
@@ -131,7 +131,7 @@ static int aio_worker(void *arg)
         }
         break;
     default:
-        fprintf(stderr, "invalid aio request (0x%x)\n", aiocb->aio_type);
+        error_report("invalid aio request (0x%x)", aiocb->aio_type);
         ret = -EINVAL;
         break;
     }
@@ -410,11 +410,11 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset)
      */
     dwPtrLow = SetFilePointer(s->hfile, low, &high, FILE_BEGIN);
     if (dwPtrLow == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) {
-        fprintf(stderr, "SetFilePointer error: %lu\n", GetLastError());
+        error_report("SetFilePointer error: %lu", GetLastError());
         return -EIO;
     }
     if (SetEndOfFile(s->hfile) == 0) {
-        fprintf(stderr, "SetEndOfFile error: %lu\n", GetLastError());
+        error_report("SetEndOfFile error: %lu", GetLastError());
         return -EIO;
     }
     return 0;
block/ssh.c +1 -1
index aa63c9d..6932905 100644
@@ -1060,7 +1060,7 @@ static void bdrv_ssh_init(void)
 
     r = libssh2_init(0);
     if (r != 0) {
-        fprintf(stderr, "libssh2 initialization failed, %d\n", r);
+        error_report("libssh2 initialization failed, %d", r);
         exit(EXIT_FAILURE);
     }
 
block/vdi.c +8 -7
index 27737af..53ada34 100644
@@ -305,21 +305,22 @@ static int vdi_check(BlockDriverState *bs, BdrvCheckResult *res,
                 if (!VDI_IS_ALLOCATED(bmap[bmap_entry])) {
                     bmap[bmap_entry] = bmap_entry;
                 } else {
-                    fprintf(stderr, "ERROR: block index %" PRIu32
-                            " also used by %" PRIu32 "\n", bmap[bmap_entry], bmap_entry);
+                    error_report("ERROR: block index %" PRIu32
+                                 " also used by %" PRIu32,
+                                 bmap[bmap_entry], bmap_entry);
                     res->corruptions++;
                 }
             } else {
-                fprintf(stderr, "ERROR: block index %" PRIu32
-                        " too large, is %" PRIu32 "\n", block, bmap_entry);
+                error_report("ERROR: block index %" PRIu32
+                             " too large, is %" PRIu32, block, bmap_entry);
                 res->corruptions++;
             }
         }
     }
     if (blocks_allocated != s->header.blocks_allocated) {
-        fprintf(stderr, "ERROR: allocated blocks mismatch, is %" PRIu32
-               ", should be %" PRIu32 "\n",
-               blocks_allocated, s->header.blocks_allocated);
+        error_report("ERROR: allocated blocks mismatch, is %" PRIu32
+                     ", should be %" PRIu32,
+                     blocks_allocated, s->header.blocks_allocated);
         res->corruptions++;
     }
 
block/vmdk.c +6 -9
index 480ea37..fe6fd74 100644
@@ -2018,24 +2018,21 @@ static int vmdk_check(BlockDriverState *bs, BdrvCheckResult *result,
         }
         extent = find_extent(s, sector_num, extent);
         if (!extent) {
-            fprintf(stderr,
-                    "ERROR: could not find extent for sector %" PRId64 "\n",
-                    sector_num);
+            error_report("ERROR: could not find extent for sector %" PRId64,
+                         sector_num);
             break;
         }
         ret = get_cluster_offset(bs, extent, NULL,
                                  sector_num << BDRV_SECTOR_BITS,
                                  0, &cluster_offset);
         if (ret == VMDK_ERROR) {
-            fprintf(stderr,
-                    "ERROR: could not get cluster_offset for sector %"
-                    PRId64 "\n", sector_num);
+            error_report("ERROR: could not get cluster_offset for sector %"
+                         PRId64, sector_num);
             break;
         }
         if (ret == VMDK_OK && cluster_offset >= bdrv_getlength(extent->file)) {
-            fprintf(stderr,
-                    "ERROR: cluster offset for sector %"
-                    PRId64 " points after EOF\n", sector_num);
+            error_report("ERROR: cluster offset for sector %"
+                         PRId64 " points after EOF", sector_num);
             break;
         }
         sector_num += extent->cluster_sectors;
block/vpc.c +2 -2
index 2e25f57..86f7890 100644
@@ -203,8 +203,8 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
     checksum = be32_to_cpu(footer->checksum);
     footer->checksum = 0;
     if (vpc_checksum(s->footer_buf, HEADER_SIZE) != checksum)
-        fprintf(stderr, "block-vpc: The header checksum of '%s' is "
-            "incorrect.\n", bs->filename);
+        error_report("block-vpc: The header checksum of '%s' is "
+                     "incorrect.", bs->filename);
 
     /* Write 'checksum' back to footer, or else will leave it with zero. */
     footer->checksum = be32_to_cpu(checksum);
block/vvfat.c +34 -35

187 lines not on this page · raw message

blockdev.c +3 -3
index 7810e9f..e36e731 100644
@@ -698,9 +698,9 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
 
     /* Deprecated option boot=[on|off] */
     if (qemu_opt_get(legacy_opts, "boot") != NULL) {
-        fprintf(stderr, "qemu-kvm: boot=on|off is deprecated and will be "
-                "ignored. Future versions will reject this parameter. Please "
-                "update your scripts.\n");
+        error_report("qemu-kvm: boot=on|off is deprecated and will be "
+                     "ignored. Future versions will reject this parameter. "
+                     "Please update your scripts.");
     }
 
     /* Media type */
Signature · 1 line
1.7.9.5
#5 lore raw

Re: [Qemu-devel] [Qemu-trivial] [PATCH 2/2] block: replace fprintf(stderr, ...) with error_report()

Quoted 5 lines · 21.05.2014 04:10, Le Tan wrote:

Replace fprintf(stderr,...) with error_report() in files block/*, block.c, block-migration.c and blockdev.c. The trailing "\n"s of the @fmt argument have been removed because @fmt of error_report() should not contain newline.

Quoted 14 lines
---
 block-migration.c      |    5 +--
 block.c                |    4 +-
 block/qcow2-refcount.c |  114 ++++++++++++++++++++++++------------------------
 block/qcow2.c          |   18 ++++----
 block/raw-posix.c      |   10 ++---
 block/raw-win32.c      |    6 +--
 block/ssh.c            |    2 +-
 block/vdi.c            |   15 ++++---
 block/vmdk.c           |   15 +++----
 block/vpc.c            |    4 +-
 block/vvfat.c          |   69 +++++++++++++++--------------
 blockdev.c             |    6 +--
 12 files changed, 132 insertions(+), 136 deletions(-)

That's a rather large -trivial patch... ;)

Please check this patch using ./tools/checkpatch.pl - it will show many whitespace issues.

I'd apply it to -trivial (after fixing the whitespace issues), all the actual changes look sane. But Cc'ing kwolf and stefanha too (who are the block subsystem maintainers), because the patch touches too many of block code.

Thanks,

/mjt

author
#6 lore raw

Re: [Qemu-devel] [Qemu-trivial] [PATCH 2/2] block: replace fprintf(stderr, ...) with error_report()

I will fix the whitespace issues and resend this series with a new version later.
Thanks very much! ;)

Le

2014-05-24 4:27 GMT+08:00 Michael Tokarev <[email protected]>:

Quoted 35 lines
Quoted 5 lines · 21.05.2014 04:10, Le Tan wrote:

Replace fprintf(stderr,...) with error_report() in files block/*, block.c, block-migration.c and blockdev.c. The trailing "\n"s of the @fmt argument have been removed because @fmt of error_report() should not contain newline.

Quoted 14 lines
---
 block-migration.c      |    5 +--
 block.c                |    4 +-
 block/qcow2-refcount.c |  114 ++++++++++++++++++++++++------------------------
 block/qcow2.c          |   18 ++++----
 block/raw-posix.c      |   10 ++---
 block/raw-win32.c      |    6 +--
 block/ssh.c            |    2 +-
 block/vdi.c            |   15 ++++---
 block/vmdk.c           |   15 +++----
 block/vpc.c            |    4 +-
 block/vvfat.c          |   69 +++++++++++++++--------------
 blockdev.c             |    6 +--
 12 files changed, 132 insertions(+), 136 deletions(-)

That's a rather large -trivial patch... ;)

Please check this patch using ./tools/checkpatch.pl - it will show many whitespace issues.

I'd apply it to -trivial (after fixing the whitespace issues), all the actual changes look sane. But Cc'ing kwolf and stefanha too (who are the block subsystem maintainers), because the patch touches too many of block code.

Thanks,

/mjt

#7 lore raw

Re: [Qemu-devel] [Qemu-trivial] [PATCH 2/2] block: replace fprintf(stderr, ...) with error_report()

24.05.2014 10:01, Le Tan пишет:

Quoted 2 lines

I will fix the whitespace issues and resend this series with a new version later.

Please note, once again: I applied (with fixups) other 3 your patches, so there's no need to resend those 3.

This one, besides a whitespace problem, needs an ACK from block subsystem maintainers, because it touches too much code there.

Thanks,

/mjt