qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, kwolf@redhat.com, famz@redhat.com,
	stefanha@redhat.com, Max Reitz <mreitz@redhat.com>,
	Ronnie Sahlberg <ronniesahlberg@gmail.com>,
	Paolo Bonzini <pbonzini@redhat.com>, Peter Lieven <pl@kamp.de>
Subject: [Qemu-devel] [PATCH v3 22/22] block: Use bool as appropriate for BDS members
Date: Thu, 23 Jun 2016 16:37:26 -0600	[thread overview]
Message-ID: <1466721446-27737-23-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1466721446-27737-1-git-send-email-eblake@redhat.com>

Using int for values that are only used as booleans is confusing.
While at it, rearrange a couple of members so that all the bools
are contiguous.

Signed-off-by: Eric Blake <eblake@redhat.com>

---
v3: new patch
---
 include/block/block.h     |  8 ++++----
 include/block/block_int.h | 13 +++++++------
 block.c                   | 22 +++++++++++-----------
 block/bochs.c             |  2 +-
 block/cloop.c             |  2 +-
 block/crypto.c            |  4 ++--
 block/dmg.c               |  2 +-
 block/iscsi.c             |  2 +-
 block/qcow.c              |  2 +-
 block/qcow2.c             |  2 +-
 block/vvfat.c             |  4 ++--
 11 files changed, 32 insertions(+), 31 deletions(-)

diff --git a/include/block/block.h b/include/block/block.h
index 733a8ec..211a0f2 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -362,8 +362,8 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
 int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base,
                             int64_t sector_num, int nb_sectors, int *pnum);

-int bdrv_is_read_only(BlockDriverState *bs);
-int bdrv_is_sg(BlockDriverState *bs);
+bool bdrv_is_read_only(BlockDriverState *bs);
+bool bdrv_is_sg(BlockDriverState *bs);
 bool bdrv_is_inserted(BlockDriverState *bs);
 int bdrv_media_changed(BlockDriverState *bs);
 void bdrv_lock_medium(BlockDriverState *bs, bool locked);
@@ -390,8 +390,8 @@ BlockDriverState *bdrv_first(BdrvNextIterator *it);
 BlockDriverState *bdrv_next(BdrvNextIterator *it);

 BlockDriverState *bdrv_next_monitor_owned(BlockDriverState *bs);
-int bdrv_is_encrypted(BlockDriverState *bs);
-int bdrv_key_required(BlockDriverState *bs);
+bool bdrv_is_encrypted(BlockDriverState *bs);
+bool bdrv_key_required(BlockDriverState *bs);
 int bdrv_set_key(BlockDriverState *bs, const char *key);
 void bdrv_add_key(BlockDriverState *bs, const char *key, Error **errp);
 int bdrv_query_missing_keys(void);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 845800e..206f982 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -429,14 +429,15 @@ struct BdrvChild {
 struct BlockDriverState {
     int64_t total_sectors; /* if we are reading a disk image, give its
                               size in sectors */
-    int read_only; /* if true, the media is read only */
     int open_flags; /* flags used to open the file, re-used for re-open */
-    int encrypted; /* if true, the media is encrypted */
-    int valid_key; /* if true, a valid encryption key has been set */
-    int sg;        /* if true, the device is a /dev/sg* */
-    int copy_on_read; /* if true, copy read backing sectors into image
+    bool read_only; /* if true, the media is read only */
+    bool encrypted; /* if true, the media is encrypted */
+    bool valid_key; /* if true, a valid encryption key has been set */
+    bool sg;        /* if true, the device is a /dev/sg* */
+    bool probed;    /* if true, format was probed rather than specified */
+
+    int copy_on_read; /* if nonzero, copy read backing sectors into image.
                          note this is a reference count */
-    bool probed;

     BlockDriver *drv; /* NULL means no media */
     void *opaque;
diff --git a/block.c b/block.c
index 34894ad..947df29 100644
--- a/block.c
+++ b/block.c
@@ -2183,9 +2183,9 @@ static void bdrv_close(BlockDriverState *bs)
         bs->backing_file[0] = '\0';
         bs->backing_format[0] = '\0';
         bs->total_sectors = 0;
-        bs->encrypted = 0;
-        bs->valid_key = 0;
-        bs->sg = 0;
+        bs->encrypted = false;
+        bs->valid_key = false;
+        bs->sg = false;
         QDECREF(bs->options);
         QDECREF(bs->explicit_options);
         bs->options = NULL;
@@ -2643,30 +2643,30 @@ void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr)
     *nb_sectors_ptr = nb_sectors < 0 ? 0 : nb_sectors;
 }

-int bdrv_is_read_only(BlockDriverState *bs)
+bool bdrv_is_read_only(BlockDriverState *bs)
 {
     return bs->read_only;
 }

-int bdrv_is_sg(BlockDriverState *bs)
+bool bdrv_is_sg(BlockDriverState *bs)
 {
     return bs->sg;
 }

-int bdrv_is_encrypted(BlockDriverState *bs)
+bool bdrv_is_encrypted(BlockDriverState *bs)
 {
     if (bs->backing && bs->backing->bs->encrypted) {
-        return 1;
+        return true;
     }
     return bs->encrypted;
 }

-int bdrv_key_required(BlockDriverState *bs)
+bool bdrv_key_required(BlockDriverState *bs)
 {
     BdrvChild *backing = bs->backing;

     if (backing && backing->bs->encrypted && !backing->bs->valid_key) {
-        return 1;
+        return true;
     }
     return (bs->encrypted && !bs->valid_key);
 }
@@ -2688,10 +2688,10 @@ int bdrv_set_key(BlockDriverState *bs, const char *key)
     }
     ret = bs->drv->bdrv_set_key(bs, key);
     if (ret < 0) {
-        bs->valid_key = 0;
+        bs->valid_key = false;
     } else if (!bs->valid_key) {
         /* call the change callback now, we skipped it on open */
-        bs->valid_key = 1;
+        bs->valid_key = true;
         bdrv_parent_cb_change_media(bs, true);
     }
     return ret;
diff --git a/block/bochs.c b/block/bochs.c
index 4194f1d..6427ad4 100644
--- a/block/bochs.c
+++ b/block/bochs.c
@@ -104,7 +104,7 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags,
     struct bochs_header bochs;
     int ret;

-    bs->read_only = 1; // no write support yet
+    bs->read_only = true; /* no write support yet */

     ret = bdrv_pread(bs->file->bs, 0, &bochs, sizeof(bochs));
     if (ret < 0) {
diff --git a/block/cloop.c b/block/cloop.c
index b5dc286..8f046e1 100644
--- a/block/cloop.c
+++ b/block/cloop.c
@@ -66,7 +66,7 @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags,
     uint32_t offsets_size, max_compressed_block_size = 1, i;
     int ret;

-    bs->read_only = 1;
+    bs->read_only = true;

     /* read header */
     ret = bdrv_pread(bs->file->bs, 128, &s->block_size, 4);
diff --git a/block/crypto.c b/block/crypto.c
index 758e14e..ec1f247 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -322,8 +322,8 @@ static int block_crypto_open_generic(QCryptoBlockFormat format,
         goto cleanup;
     }

-    bs->encrypted = 1;
-    bs->valid_key = 1;
+    bs->encrypted = true;
+    bs->valid_key = true;

     ret = 0;
  cleanup:
diff --git a/block/dmg.c b/block/dmg.c
index 9612c21..11a0673 100644
--- a/block/dmg.c
+++ b/block/dmg.c
@@ -438,7 +438,7 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags,
     int64_t offset;
     int ret;

-    bs->read_only = 1;
+    bs->read_only = true;

     s->n_chunks = 0;
     s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL;
diff --git a/block/iscsi.c b/block/iscsi.c
index 6e8d4fe..ac351f3 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1596,7 +1596,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
      * will try to read from the device to guess the image format.
      */
     if (iscsilun->type != TYPE_DISK && iscsilun->type != TYPE_ROM) {
-        bs->sg = 1;
+        bs->sg = true;
     }

     task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 1,
diff --git a/block/qcow.c b/block/qcow.c
index 312af52..e4175b8 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -174,7 +174,7 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,
             goto fail;
         }

-        bs->encrypted = 1;
+        bs->encrypted = true;
     }
     s->cluster_bits = header.cluster_bits;
     s->cluster_size = 1 << s->cluster_bits;
diff --git a/block/qcow2.c b/block/qcow2.c
index fdf13cb..0178931 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -980,7 +980,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
             goto fail;
         }

-        bs->encrypted = 1;
+        bs->encrypted = true;
     }

     s->l2_bits = s->cluster_bits - 3; /* L2 is always one cluster */
diff --git a/block/vvfat.c b/block/vvfat.c
index fc948cb..55b5759 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -1158,7 +1158,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
     s->current_cluster=0xffffffff;

     /* read only is the default for safety */
-    bs->read_only = 1;
+    bs->read_only = true;
     s->qcow = s->write_target = NULL;
     s->qcow_filename = NULL;
     s->fat2 = NULL;
@@ -1174,7 +1174,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
         if (ret < 0) {
             goto fail;
         }
-        bs->read_only = 0;
+        bs->read_only = false;
     }

     bs->total_sectors = cyls * heads * secs;
-- 
2.5.5

  parent reply	other threads:[~2016-06-23 22:37 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-23 22:37 [Qemu-devel] [PATCH v3 00/22] Byte-based block limits Eric Blake
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 01/22] block: Tighter assertions on bdrv_aligned_pwritev() Eric Blake
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 02/22] block: Document supported flags during bdrv_aligned_preadv() Eric Blake
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 03/22] block: Fix harmless off-by-one in bdrv_aligned_preadv() Eric Blake
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 04/22] nbd: Allow larger requests Eric Blake
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 05/22] nbd: Advertise realistic limits to block layer Eric Blake
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 06/22] iscsi: " Eric Blake
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 07/22] scsi: Advertise limits by blocksize, not 512 Eric Blake
2016-06-24  5:22   ` Fam Zheng
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 08/22] block: Give nonzero result to blk_get_max_transfer_length() Eric Blake
2016-06-24  5:24   ` Fam Zheng
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 09/22] blkdebug: Set request_alignment during .bdrv_refresh_limits() Eric Blake
2016-06-24  5:42   ` Fam Zheng
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 10/22] iscsi: " Eric Blake
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 11/22] qcow2: " Eric Blake
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 12/22] raw-win32: " Eric Blake
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 13/22] block: " Eric Blake
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 14/22] block: Set default request_alignment during bdrv_refresh_limits() Eric Blake
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 15/22] block: Switch transfer length bounds to byte-based Eric Blake
2016-06-24  6:06   ` Fam Zheng
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 16/22] block: Wording tweaks to write zeroes limits Eric Blake
2016-06-24  6:12   ` Fam Zheng
2016-06-24 14:10     ` Eric Blake
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 17/22] block: Switch discard length bounds to byte-based Eric Blake
2016-06-24  6:43   ` Fam Zheng
2016-06-24 14:15     ` Eric Blake
2016-06-24 14:29       ` Kevin Wolf
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 18/22] block: Drop raw_refresh_limits() Eric Blake
2016-06-24  6:44   ` Fam Zheng
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 19/22] block: Split bdrv_merge_limits() from bdrv_refresh_limits() Eric Blake
2016-06-24  6:48   ` Fam Zheng
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 20/22] block: Move request_alignment into BlockLimit Eric Blake
2016-06-24  7:07   ` Fam Zheng
2016-06-24 13:45   ` Kevin Wolf
2016-06-24 14:17     ` Eric Blake
2016-06-23 22:37 ` [Qemu-devel] [PATCH v3 21/22] block: Fix error message style Eric Blake
2016-06-24  7:09   ` Fam Zheng
2016-06-23 22:37 ` Eric Blake [this message]
2016-06-24  7:12   ` [Qemu-devel] [PATCH v3 22/22] block: Use bool as appropriate for BDS members Fam Zheng
2016-06-24 14:32 ` [Qemu-devel] [PATCH v3 00/22] Byte-based block limits Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1466721446-27737-23-git-send-email-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=pl@kamp.de \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).