Skip to contentSkip to conversation

block: replace fprintf(stderr, ...) with error_report()

PATCH Superseded Le Tan 3 participants 5 messages May 25, 2014 Block layer

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Le Tan

author
#0 lore raw

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

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. Also fix some coding style issues.

---
 block-migration.c      |    7 +-
 block.c                |   58 +++++-----
 block/qcow2-refcount.c |  274 ++++++++++++++++++++++++------------------------
 block/qcow2.c          |   54 +++++-----
 block/raw-posix.c      |  122 ++++++++++-----------
 block/raw-win32.c      |   59 ++++++-----
 block/ssh.c            |   26 ++---
 block/vdi.c            |   19 ++--
 block/vmdk.c           |   62 ++++++-----
 block/vpc.c            |   22 ++--
 block/vvfat.c          |  143 ++++++++++++-------------
 blockdev.c             |   27 +++--
 12 files changed, 441 insertions(+), 432 deletions(-)
block-migration.c +3 -4
index 56951e0..004f548 100644
@@ -33,7 +33,7 @@
 
 #define MAX_IS_ALLOCATED_SEARCH 65536
 
-//#define DEBUG_BLK_MIGRATION
+/* #define DEBUG_BLK_MIGRATION */
 
 #ifdef DEBUG_BLK_MIGRATION
 #define DPRINTF(fmt, ...) \
@@ -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 +32 -26

159 lines not on this page · raw message

block/qcow2-refcount.c +136 -138

621 lines not on this page · raw message

block/qcow2.c +27 -27

161 lines not on this page · raw message

block/raw-posix.c +63 -59

306 lines not on this page · raw message

block/raw-win32.c +30 -29

156 lines not on this page · raw message

block/ssh.c +14 -12
index aa63c9d..8dc4e80 100644
@@ -191,7 +191,7 @@ static int parse_uri(const char *filename, QDict *options, Error **errp)
         goto err;
     }
 
-    if(uri->user && strcmp(uri->user, "") != 0) {
+    if (uri->user && strcmp(uri->user, "") != 0) {
         qdict_put(options, "user", qstring_from_str(uri->user));
     }
 
@@ -219,10 +219,10 @@ static int parse_uri(const char *filename, QDict *options, Error **errp)
 
  err:
     if (qp) {
-      query_params_free(qp);
+        query_params_free(qp);
     }
     if (uri) {
-      uri_free(uri);
+        uri_free(uri);
     }
     return -EINVAL;
 }
@@ -235,7 +235,8 @@ static void ssh_parse_filename(const char *filename, QDict *options,
         qdict_haskey(options, "port") ||
         qdict_haskey(options, "path") ||
         qdict_haskey(options, "host_key_check")) {
-        error_setg(errp, "user, host, port, path, host_key_check cannot be used at the same time as a file option");
+        error_setg(errp, "user, host, port, path, host_key_check cannot be "
+                   "used at the same time as a file option");
         return;
     }
 
@@ -289,8 +290,8 @@ static int check_host_key_knownhosts(BDRVSSHState *s,
         break;
     case LIBSSH2_KNOWNHOST_CHECK_MISMATCH:
         ret = -EINVAL;
-        session_error_report(s, "host key does not match the one in known_hosts (found key %s)",
-                             found->key);
+        session_error_report(s, "host key does not match the one in "
+                             "known_hosts (found key %s)", found->key);
         goto out;
     case LIBSSH2_KNOWNHOST_CHECK_NOTFOUND:
         ret = -EINVAL;
@@ -302,8 +303,8 @@ static int check_host_key_knownhosts(BDRVSSHState *s,
         goto out;
     default:
         ret = -EINVAL;
-        session_error_report(s, "unknown error matching the host key with known_hosts (%d)",
-                             r);
+        session_error_report(s, "unknown error matching the host key with "
+                             "known_hosts (%d)", r);
         goto out;
     }
 
@@ -368,7 +369,7 @@ check_host_key_hash(BDRVSSHState *s, const char *hash,
         return -EINVAL;
     }
 
-    if(compare_fingerprint((unsigned char *) fingerprint, fingerprint_len,
+    if (compare_fingerprint((unsigned char *) fingerprint, fingerprint_len,
                            hash) != 0) {
         error_report("remote host key does not match host_key_check '%s'",
                      hash);
@@ -418,7 +419,8 @@ static int authenticate(BDRVSSHState *s, const char *user)
     userauthlist = libssh2_userauth_list(s->session, user, strlen(user));
     if (strstr(userauthlist, "publickey") == NULL) {
         ret = -EPERM;
-        error_report("remote server does not support \"publickey\" authentication");
+        error_report("remote server does not support \"publickey\" "
+                     "authentication");
         goto out;
     }
 
@@ -440,7 +442,7 @@ static int authenticate(BDRVSSHState *s, const char *user)
         goto out;
     }
 
-    for(;;) {
+    for (;;) {
         r = libssh2_agent_get_identity(agent, &identity, prev_identity);
         if (r == 1) {           /* end of list */
             break;
@@ -1060,7 +1062,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 +10 -9
index 27737af..2883066 100644
@@ -65,7 +65,7 @@ typedef unsigned char uuid_t[16];
 /* Code configuration options. */
 
 /* Enable debug messages. */
-//~ #define CONFIG_VDI_DEBUG
+/* ~ #define CONFIG_VDI_DEBUG */
 
 /* Support write operations on VDI images. */
 #define CONFIG_VDI_WRITE
@@ -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++;
     }
 
@@ -730,7 +731,7 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options,
     blocks = (bytes + block_size - 1) / block_size;
 
     bmap_size = blocks * sizeof(uint32_t);
-    bmap_size = ((bmap_size + SECTOR_SIZE - 1) & ~(SECTOR_SIZE -1));
+    bmap_size = ((bmap_size + SECTOR_SIZE - 1) & ~(SECTOR_SIZE - 1));
 
     memset(&header, 0, sizeof(header));
     pstrcpy(header.text, sizeof(header.text), VDI_TEXT);
block/vmdk.c +30 -32

113 lines not on this page · raw message

block/vpc.c +11 -11
index 2e25f57..e0bb333 100644
@@ -138,7 +138,7 @@ typedef struct BDRVVPCState {
     Error *migration_blocker;
 } BDRVVPCState;
 
-static uint32_t vpc_checksum(uint8_t* buf, size_t size)
+static uint32_t vpc_checksum(uint8_t *buf, size_t size)
 {
     uint32_t res = 0;
     int i;
@@ -153,7 +153,7 @@ static uint32_t vpc_checksum(uint8_t* buf, size_t size)
 static int vpc_probe(const uint8_t *buf, int buf_size, const char *filename)
 {
     if (buf_size >= 8 && !strncmp((char *)buf, "conectix", 8))
-	return 100;
+        return 100;
     return 0;
 }
 
@@ -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);
@@ -353,7 +353,8 @@ static inline int64_t get_sector_offset(BlockDriverState *bs,
     pagetable_index = offset / s->block_size;
     pageentry_index = (offset % s->block_size) / 512;
 
-    if (pagetable_index >= s->max_table_entries || s->pagetable[pagetable_index] == 0xffffffff)
+    if (pagetable_index >= s->max_table_entries ||
+        s->pagetable[pagetable_index] == 0xffffffff)
         return -1; // not allocated
 
     bitmap_offset = 512 * (uint64_t) s->pagetable[pagetable_index];
@@ -413,7 +414,7 @@ static inline int64_t get_sector_offset(BlockDriverState *bs,
  *
  * Returns 0 on success and < 0 on error
  */
-static int rewrite_footer(BlockDriverState* bs)
+static int rewrite_footer(BlockDriverState *bs)
 {
     int ret;
     BDRVVPCState *s = bs->opaque;
@@ -433,7 +434,7 @@ static int rewrite_footer(BlockDriverState* bs)
  *
  * Returns the sectors' offset in the image file on success and < 0 on error
  */
-static int64_t alloc_block(BlockDriverState* bs, int64_t sector_num)
+static int64_t alloc_block(BlockDriverState *bs, int64_t sector_num)
 {
     BDRVVPCState *s = bs->opaque;
     int64_t bat_offset;
@@ -605,8 +606,8 @@ static coroutine_fn int vpc_co_write(BlockDriverState *bs, int64_t sector_num,
  * the hardware EIDE and ATA-2 limit of 16 heads (max disk size of 127 GB)
  * and instead allow up to 255 heads.
  */
-static int calculate_geometry(int64_t total_sectors, uint16_t* cyls,
-    uint8_t* heads, uint8_t* secs_per_cyl)
+static int calculate_geometry(int64_t total_sectors, uint16_t *cyls,
+    uint8_t *heads, uint8_t *secs_per_cyl)
 {
     uint32_t cyls_times_heads;
 
@@ -783,8 +784,7 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options,
     total_sectors = total_size / BDRV_SECTOR_SIZE;
     for (i = 0; total_sectors > (int64_t)cyls * heads * secs_per_cyl; i++) {
         if (calculate_geometry(total_sectors + i, &cyls, &heads,
-                               &secs_per_cyl))
-        {
+                               &secs_per_cyl)) {
             ret = -EFBIG;
             goto fail;
         }
block/vvfat.c +72 -71

335 lines not on this page · raw message

blockdev.c +13 -14
index 7810e9f..2c6f559 100644
@@ -158,8 +158,8 @@ DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit)
 
     QTAILQ_FOREACH(dinfo, &drives, next) {
         if (dinfo->type == type &&
-	    dinfo->bus == bus &&
-	    dinfo->unit == unit)
+            dinfo->bus == bus &&
+            dinfo->unit == unit)
             return dinfo;
     }
 
@@ -180,8 +180,8 @@ int drive_get_max_bus(BlockInterfaceType type)
 
     max_bus = -1;
     QTAILQ_FOREACH(dinfo, &drives, next) {
-        if(dinfo->type == type &&
-           dinfo->bus > max_bus)
+        if (dinfo->type == type &&
+            dinfo->bus > max_bus)
             max_bus = dinfo->bus;
     }
     return max_bus;
@@ -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 */
@@ -729,7 +729,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
     qdict_put(bs_opts, "read-only",
               qstring_from_str(read_only ? "on" : "off"));
     qdict_put(bs_opts, "copy-on-read",
-              qstring_from_str(copy_on_read ? "on" :"off"));
+              qstring_from_str(copy_on_read ? "on" : "off"));
 
     /* Controller type */
     value = qemu_opt_get(legacy_opts, "if");
@@ -815,14 +815,14 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
     }
 
     if (unit_id == -1) {
-       unit_id = 0;
-       while (drive_get(type, bus_id, unit_id) != NULL) {
+        unit_id = 0;
+        while (drive_get(type, bus_id, unit_id) != NULL) {
            unit_id++;
            if (max_devs && unit_id >= max_devs) {
                unit_id -= max_devs;
                bus_id++;
            }
-       }
+        }
     }
 
     if (max_devs && unit_id >= max_devs) {
@@ -925,7 +925,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
     dinfo->unit = unit_id;
     dinfo->devaddr = devaddr;
 
-    switch(type) {
+    switch (type) {
     case IF_IDE:
     case IF_SCSI:
     case IF_XEN:
@@ -2139,8 +2139,7 @@ void qmp_drive_mirror(const char *device, const char *target,
     }
 
     if ((sync == MIRROR_SYNC_MODE_FULL || !source)
-        && mode != NEW_IMAGE_MODE_EXISTING)
-    {
+        && mode != NEW_IMAGE_MODE_EXISTING) {
         /* create new image w/o backing file */
         assert(format && drv);
         bdrv_img_create(target, format,
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 4 lines · On 2014-05-25 10:44, 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. Also fix some coding style issues.

Let's do the "also" part in a separate patch. It's more than one or two trivial pass-by style fixes, and some people may like the fprintf conversion while having different views on the other changes.

Jan

#2 lore raw
Quoted 9 lines · Jan Kiszka
Quoted 4 lines · On 2014-05-25 10:44, 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. Also fix some coding style issues.

Let's do the "also" part in a separate patch. It's more than one or two trivial pass-by style fixes, and some people may like the fprintf conversion while having different views on the other changes.

I think he misunderstood.

I told him that his previous patch had its own whitespace issues, ie, it _adds_ whitespace errors.

In another reply I told him it is usually a good idea to fix style issues in the code the patch touches -- this means, close to, if a line being changed for something else has an unrelated style issue, it should be fixed too. (An example was space between function name and its arguments in fprintf argument list, while converting that fprintf to error_report).

But it looks like he took this advise in much more broad way and fixed _all_ whitespace/style issues in the files he touches. Oh well.. :)

And yes, definitely, please don't mix it like this. Usually, these code style issues should not be touched by its own, only if you change nearby code.

Thanks,

/mjt

author
#3 lore raw

Oh, yes, I may misunderstood it. I just ran ./scripts/checkpatch.pl to check files that I touched and fixed those I can fix. So I will send the v4 of this patch which just fix the whitespace issues based on v2. Is that right? Forgive my being naive. :)
Thanks very much for all!

Le

2014-05-25 22:36 GMT+08:00 Michael Tokarev <[email protected]>:

Quoted 34 lines
Quoted 9 lines · Jan Kiszka
Quoted 4 lines · On 2014-05-25 10:44, 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. Also fix some coding style issues.

Let's do the "also" part in a separate patch. It's more than one or two trivial pass-by style fixes, and some people may like the fprintf conversion while having different views on the other changes.

I think he misunderstood.

I told him that his previous patch had its own whitespace issues, ie, it _adds_ whitespace errors.

In another reply I told him it is usually a good idea to fix style issues in the code the patch touches -- this means, close to, if a line being changed for something else has an unrelated style issue, it should be fixed too. (An example was space between function name and its arguments in fprintf argument list, while converting that fprintf to error_report).

But it looks like he took this advise in much more broad way and fixed _all_ whitespace/style issues in the files he touches. Oh well.. :)

And yes, definitely, please don't mix it like this. Usually, these code style issues should not be touched by its own, only if you change nearby code.

Thanks,

/mjt

#4 lore raw
Quoted 4 lines · 25.05.2014 18:45, Le Tan wrote:

Oh, yes, I may misunderstood it. I just ran ./scripts/checkpatch.pl to check files that I touched and fixed those I can fix. So I will send the v4 of this patch which just fix the whitespace issues based on v2. Is that right? Forgive my being naive. :)

Please stop top-posting.

I told you to use checkpatch against your _patches_, not against the files you touch.. ;)

Thank you,

/mjt