Skip to contentSkip to conversation

block/vhdx: Use IEC binary prefixes from "qemu/units.h"

PATCH Applied Stefano Garzarella 5 participants 12 messages Mar 27, 2019 – Apr 11, 2019 Block layer

lore
Share & tools
lore
#0 lore raw

v2 cover block/vhdx: Use IEC binary prefixes from "qemu/units.h"

v2:
- Included units.h directly in the vhdx.h header file (John, Philippe)
- Added a comment next to DEFAULT_LOG_SIZE definition (Kevin)
- Added a second patch where I fixed some size constants using IEC binary prefixes.
Note: checkpatch is not happy about a change in vhdx.h but all the comments in that file doesn't respect the new coding style so I left the comment as is

Stefano Garzarella (2):
block/vhdx: Remove redundant IEC binary prefixes definition block/vhdx: Use IEC binary prefixes for size constants

 block/vhdx-log.c |  2 +-
 block/vhdx.c     |  7 ++++---
 block/vhdx.h     | 16 +++++++---------
 3 files changed, 12 insertions(+), 13 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/2 block/vhdx: Remove redundant IEC binary prefixes definition

IEC binary prefixes are already defined in "qemu/units.h", so we can remove redundant definitions in "block/vhdx.h".

---
 block/vhdx.c | 3 ++-
 block/vhdx.h | 6 +-----
 2 files changed, 3 insertions(+), 6 deletions(-)
block/vhdx.c +2 -1
index b785aef4b7..7cd1fc3731 100644
@@ -1889,7 +1889,8 @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts,
         return -EINVAL;
     }
     if (block_size > VHDX_BLOCK_SIZE_MAX) {
-        error_setg(errp, "Block size must not exceed %d", VHDX_BLOCK_SIZE_MAX);
+        error_setg(errp, "Block size must not exceed %" PRId64,
+                   VHDX_BLOCK_SIZE_MAX);
         return -EINVAL;
     }
 
block/vhdx.h +1 -5
index 1bfb4e4f73..bf72090c8f 100644
@@ -17,11 +17,7 @@
 
 #ifndef BLOCK_VHDX_H
 #define BLOCK_VHDX_H
-
-#define KiB              (1 * 1024)
-#define MiB            (KiB * 1024)
-#define GiB            (MiB * 1024)
-#define TiB ((uint64_t) GiB * 1024)
+#include "qemu/units.h"
 
 #define DEFAULT_LOG_SIZE 1048576 /* 1MiB */
 /* Structures and fields present in the VHDX file */
Signature · 1 line
2.20.1
Reviewed-by on v2 1/2
#2 lore raw

Re: [Qemu-trivial] [PATCH v2 1/2] block/vhdx: Remove redundant IEC binary prefixes definition

Le mer. 27 mars 2019 10:56, Stefano Garzarella <[email protected]> a écrit :

Quoted 43 lines

IEC binary prefixes are already defined in "qemu/units.h", so we can remove redundant definitions in "block/vhdx.h".

---
 block/vhdx.c | 3 ++-
 block/vhdx.h | 6 +-----
 2 files changed, 3 insertions(+), 6 deletions(-)
block/vhdx.c +2 -1
index b785aef4b7..7cd1fc3731 100644
@@ -1889,7 +1889,8 @@ static int coroutine_fn
 vhdx_co_create(BlockdevCreateOptions *opts,
         return -EINVAL;
     }
     if (block_size > VHDX_BLOCK_SIZE_MAX) {
-        error_setg(errp, "Block size must not exceed %d",
 VHDX_BLOCK_SIZE_MAX);
+        error_setg(errp, "Block size must not exceed %" PRId64,
+                   VHDX_BLOCK_SIZE_MAX);
         return -EINVAL;
     }
block/vhdx.h +1 -6
index 1bfb4e4f73..bf72090c8f 100644
@@ -17,11 +17,7 @@
 
 #ifndef BLOCK_VHDX_H
 #define BLOCK_VHDX_H
-
-#define KiB              (1 * 1024)
-#define MiB            (KiB * 1024)
-#define GiB            (MiB * 1024)
-#define TiB ((uint64_t) GiB * 1024)
+#include "qemu/units.h"
 
 #define DEFAULT_LOG_SIZE 1048576 /* 1MiB */
 /* Structures and fields present in the VHDX file */
--
Quoted 2 lines

2.20.1

Quoted 1 line
Reviewed-by on v2 1/2
#3 lore raw

Re: [Qemu-trivial] [PATCH v2 1/2] block/vhdx: Remove redundant IEC binary prefixes definition

In reply to Stefano Garzarella
Quoted 31 lines · Stefano Garzarella

IEC binary prefixes are already defined in "qemu/units.h", so we can remove redundant definitions in "block/vhdx.h".

---
 block/vhdx.c | 3 ++-
 block/vhdx.h | 6 +-----
 2 files changed, 3 insertions(+), 6 deletions(-)
block/vhdx.c +2 -1
index b785aef4b7..7cd1fc3731 100644
@@ -1889,7 +1889,8 @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts,
         return -EINVAL;
     }
     if (block_size > VHDX_BLOCK_SIZE_MAX) {
-        error_setg(errp, "Block size must not exceed %d", VHDX_BLOCK_SIZE_MAX);
+        error_setg(errp, "Block size must not exceed %" PRId64,
+                   VHDX_BLOCK_SIZE_MAX);
         return -EINVAL;
     }
 
block/vhdx.h +0 -0
index 1bfb4e4f73..bf72090c8f 100644
@@ -17,11 +17,7 @@
 
 #ifndef BLOCK_VHDX_H

block/vhdx.h line 23

Quoted 10 lines
block/vhdx.h +1 -5
 #define BLOCK_VHDX_H
-
-#define KiB              (1 * 1024)
-#define MiB            (KiB * 1024)
-#define GiB            (MiB * 1024)
-#define TiB ((uint64_t) GiB * 1024)
+#include "qemu/units.h"
 
 #define DEFAULT_LOG_SIZE 1048576 /* 1MiB */
 /* Structures and fields present in the VHDX file */

Looks good. By the way, you may want to consider adding to your git config rules that put the .h file diff changes above the .c file.

Look at qemu/scripts/git.orderfile

(I know I'm one to talk, I still haven't set mine up...)

#4 lore raw

Re: [Qemu-trivial] [PATCH v2 1/2] block/vhdx: Remove redundant IEC binary prefixes definition

Quoted 41 lines · John Snow
Quoted 38 lines · Stefano Garzarella

IEC binary prefixes are already defined in "qemu/units.h", so we can remove redundant definitions in "block/vhdx.h".

---
 block/vhdx.c | 3 ++-
 block/vhdx.h | 6 +-----
 2 files changed, 3 insertions(+), 6 deletions(-)
block/vhdx.c +2 -1
index b785aef4b7..7cd1fc3731 100644
@@ -1889,7 +1889,8 @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts,
         return -EINVAL;
     }
     if (block_size > VHDX_BLOCK_SIZE_MAX) {
-        error_setg(errp, "Block size must not exceed %d", VHDX_BLOCK_SIZE_MAX);
+        error_setg(errp, "Block size must not exceed %" PRId64,
+                   VHDX_BLOCK_SIZE_MAX);
         return -EINVAL;
     }
 
block/vhdx.h +1 -5
index 1bfb4e4f73..bf72090c8f 100644
@@ -17,11 +17,7 @@
 
 #ifndef BLOCK_VHDX_H
 #define BLOCK_VHDX_H
-
-#define KiB              (1 * 1024)
-#define MiB            (KiB * 1024)
-#define GiB            (MiB * 1024)
-#define TiB ((uint64_t) GiB * 1024)
+#include "qemu/units.h"
 
Quoted 8 lines

block/vhdx.h line 23

Quoted 3 lines
block/vhdx.h +0 -0
 #define DEFAULT_LOG_SIZE 1048576 /* 1MiB */
 /* Structures and fields present in the VHDX file */

Looks good. By the way, you may want to consider adding to your git config rules that put the .h file diff changes above the .c file.

Look at qemu/scripts/git.orderfile

Thank you very much! It is very useful!

Quoted 2 lines

(I know I'm one to talk, I still haven't set mine up...)

:)

Quoted 2 lines

Thanks,
Stefano

#5 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH v2 1/2] block/vhdx: Remove redundant IEC binary prefixes definition

In reply to John Snow
Quoted 50 lines · John Snow

block/vhdx.c static int coroutine_fn

Quoted 14 lines · Stefano Garzarella

IEC binary prefixes are already defined in "qemu/units.h", so we can remove redundant definitions in "block/vhdx.h".

---
 block/vhdx.c | 3 ++-
 block/vhdx.h | 6 +-----
 2 files changed, 3 insertions(+), 6 deletions(-)
block/vhdx.c +0 -0
index b785aef4b7..7cd1fc3731 100644
@@ -1889,7 +1889,8 @@ static int coroutine_fn

vhdx_co_create(BlockdevCreateOptions *opts,

block/vhdx.c static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts,

Quoted 4 lines
block/vhdx.c +0 -1
         return -EINVAL;
     }
     if (block_size > VHDX_BLOCK_SIZE_MAX) {
-        error_setg(errp, "Block size must not exceed %d",

VHDX_BLOCK_SIZE_MAX);

Quoted 13 lines
block/vhdx.c +2 -0
+        error_setg(errp, "Block size must not exceed %" PRId64,
+                   VHDX_BLOCK_SIZE_MAX);
         return -EINVAL;
     }
 
block/vhdx.h +0 -0
index 1bfb4e4f73..bf72090c8f 100644
@@ -17,11 +17,7 @@
 
 #ifndef BLOCK_VHDX_H

block/vhdx.h line 23

Quoted 10 lines
block/vhdx.h +1 -5
 #define BLOCK_VHDX_H
-
-#define KiB              (1 * 1024)
-#define MiB            (KiB * 1024)
-#define GiB            (MiB * 1024)
-#define TiB ((uint64_t) GiB * 1024)
+#include "qemu/units.h"
 
 #define DEFAULT_LOG_SIZE 1048576 /* 1MiB */
 /* Structures and fields present in the VHDX file */

Looks good. By the way, you may want to consider adding to your git config rules that put the .h file diff changes above the .c file.

Quoted 4 lines

Look at qemu/scripts/git.orderfile

(I know I'm one to talk, I still haven't set mine up...)

=)

Quoted 3 lines
#6 lore raw

Re: [Qemu-devel] [Qemu-trivial] [PATCH v2 1/2] block/vhdx: Remove redundant IEC binary prefixes definition

In reply to Stefano Garzarella
Quoted 31 lines · Stefano Garzarella

IEC binary prefixes are already defined in "qemu/units.h", so we can remove redundant definitions in "block/vhdx.h".

---
 block/vhdx.c | 3 ++-
 block/vhdx.h | 6 +-----
 2 files changed, 3 insertions(+), 6 deletions(-)
block/vhdx.c +2 -1
index b785aef4b7..7cd1fc3731 100644
@@ -1889,7 +1889,8 @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts,
         return -EINVAL;
     }
     if (block_size > VHDX_BLOCK_SIZE_MAX) {
-        error_setg(errp, "Block size must not exceed %d", VHDX_BLOCK_SIZE_MAX);
+        error_setg(errp, "Block size must not exceed %" PRId64,
+                   VHDX_BLOCK_SIZE_MAX);
         return -EINVAL;
     }
 
block/vhdx.h +0 -0
index 1bfb4e4f73..bf72090c8f 100644
@@ -17,11 +17,7 @@
 
 #ifndef BLOCK_VHDX_H

block/vhdx.h line 23

Quoted 10 lines
block/vhdx.h +1 -5
 #define BLOCK_VHDX_H
-
-#define KiB              (1 * 1024)
-#define MiB            (KiB * 1024)
-#define GiB            (MiB * 1024)
-#define TiB ((uint64_t) GiB * 1024)
+#include "qemu/units.h"
 
 #define DEFAULT_LOG_SIZE 1048576 /* 1MiB */
 /* Structures and fields present in the VHDX file */

Applied to my trivial-patches branch.

Thanks,
Laurent

#7 lore raw

Re: [Qemu-devel] [Qemu-trivial] [PATCH v2 1/2] block/vhdx: Remove redundant IEC binary prefixes definition

Quoted 39 lines · Laurent Vivier
Quoted 38 lines · Stefano Garzarella

IEC binary prefixes are already defined in "qemu/units.h", so we can remove redundant definitions in "block/vhdx.h".

---
 block/vhdx.c | 3 ++-
 block/vhdx.h | 6 +-----
 2 files changed, 3 insertions(+), 6 deletions(-)
block/vhdx.c +2 -1
index b785aef4b7..7cd1fc3731 100644
@@ -1889,7 +1889,8 @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts,
         return -EINVAL;
     }
     if (block_size > VHDX_BLOCK_SIZE_MAX) {
-        error_setg(errp, "Block size must not exceed %d", VHDX_BLOCK_SIZE_MAX);
+        error_setg(errp, "Block size must not exceed %" PRId64,
+                   VHDX_BLOCK_SIZE_MAX);
         return -EINVAL;
     }
 
block/vhdx.h +1 -5
index 1bfb4e4f73..bf72090c8f 100644
@@ -17,11 +17,7 @@
 
 #ifndef BLOCK_VHDX_H
 #define BLOCK_VHDX_H
-
-#define KiB              (1 * 1024)
-#define MiB            (KiB * 1024)
-#define GiB            (MiB * 1024)
-#define TiB ((uint64_t) GiB * 1024)
+#include "qemu/units.h"
 
Quoted 5 lines

block/vhdx.h line 23

Quoted 3 lines
block/vhdx.h +0 -0
 #define DEFAULT_LOG_SIZE 1048576 /* 1MiB */
 /* Structures and fields present in the VHDX file */

Applied to my trivial-patches branch.

Removed as Kevin already applied it to block-next.

Thanks,
Laurent

#8 lore raw

PATCH v2 2/2 block/vhdx: Use IEC binary prefixes for size constants

In reply to Stefano Garzarella

Using IEC binary prefixes in order to make the code more readable, with the exception of DEFAULT_LOG_SIZE because it's passed to stringify().

---
 block/vhdx-log.c |  2 +-
 block/vhdx.c     |  4 ++--
 block/vhdx.h     | 10 ++++++----
 3 files changed, 9 insertions(+), 7 deletions(-)
block/vhdx-log.c +1 -1
index 3149ff08d8..5e946846f1 100644
@@ -551,7 +551,7 @@ static int vhdx_log_flush(BlockDriverState *bs, BDRVVHDXState *s,
         }
         if (file_length < desc_entries->hdr.last_file_offset) {
             new_file_size = desc_entries->hdr.last_file_offset;
-            if (new_file_size % (1024*1024)) {
+            if (new_file_size % (1 * MiB)) {
                 /* round up to nearest 1MB boundary */
                 new_file_size = QEMU_ALIGN_UP(new_file_size, MiB);
                 if (new_file_size > INT64_MAX) {
block/vhdx.c +2 -2
index 7cd1fc3731..a143a57657 100644
@@ -1175,7 +1175,7 @@ static int vhdx_allocate_block(BlockDriverState *bs, BDRVVHDXState *s,
     *new_offset = current_len;
 
     /* per the spec, the address for a block is in units of 1MB */
-    *new_offset = ROUND_UP(*new_offset, 1024 * 1024);
+    *new_offset = ROUND_UP(*new_offset, 1 * MiB);
     if (*new_offset > INT64_MAX) {
         return -EINVAL;
     }
@@ -1338,7 +1338,7 @@ static coroutine_fn int vhdx_co_writev(BlockDriverState *bs, int64_t sector_num,
             case PAYLOAD_BLOCK_FULLY_PRESENT:
                 /* if the file offset address is in the header zone,
                  * there is a problem */
-                if (sinfo.file_offset < (1024 * 1024)) {
+                if (sinfo.file_offset < (1 * MiB)) {
                     ret = -EFAULT;
                     goto error_bat_restore;
                 }
block/vhdx.h +6 -4
index bf72090c8f..0b74924cee 100644
@@ -20,6 +20,8 @@
 #include "qemu/units.h"
 
 #define DEFAULT_LOG_SIZE 1048576 /* 1MiB */
+/* Note: can't use 1 * MiB, because it's passed to stringify() */
+
 /* Structures and fields present in the VHDX file */
 
 /* The header section has the following blocks,
@@ -32,7 +34,7 @@
  * 0.........64KB...........128KB........192KB..........256KB................1MB
  */
 
-#define VHDX_HEADER_BLOCK_SIZE      (64 * 1024)
+#define VHDX_HEADER_BLOCK_SIZE      (64 * KiB)
 
 #define VHDX_FILE_ID_OFFSET         0
 #define VHDX_HEADER1_OFFSET         (VHDX_HEADER_BLOCK_SIZE * 1)
@@ -81,7 +83,7 @@ typedef struct QEMU_PACKED MSGUID {
 #define guid_eq(a, b) \
     (memcmp(&(a), &(b), sizeof(MSGUID)) == 0)
 
-#define VHDX_HEADER_SIZE (4 * 1024)   /* although the vhdx_header struct in disk
+#define VHDX_HEADER_SIZE (4 * KiB)    /* although the vhdx_header struct in disk
                                          is only 582 bytes, for purposes of crc
                                          the header is the first 4KB of the 64KB
                                          block */
@@ -157,8 +159,8 @@ typedef struct QEMU_PACKED VHDXRegionTableEntry {
 
 
 /* ---- LOG ENTRY STRUCTURES ---- */
-#define VHDX_LOG_MIN_SIZE (1024 * 1024)
-#define VHDX_LOG_SECTOR_SIZE 4096
+#define VHDX_LOG_MIN_SIZE (1 * MiB)
+#define VHDX_LOG_SECTOR_SIZE (4 * KiB)
 #define VHDX_LOG_HDR_SIZE 64
 #define VHDX_LOG_SIGNATURE 0x65676f6c
 typedef struct QEMU_PACKED VHDXLogEntryHeader {
Signature · 1 line
2.20.1
Reviewed-by on v2 2/2
#9 lore raw

Re: [Qemu-trivial] [PATCH v2 2/2] block/vhdx: Use IEC binary prefixes for size constants

Le mer. 27 mars 2019 10:56, Stefano Garzarella <[email protected]> a écrit :

Quoted 88 lines

Using IEC binary prefixes in order to make the code more readable, with the exception of DEFAULT_LOG_SIZE because it's passed to stringify().

---
 block/vhdx-log.c |  2 +-
 block/vhdx.c     |  4 ++--
 block/vhdx.h     | 10 ++++++----
 3 files changed, 9 insertions(+), 7 deletions(-)
block/vhdx-log.c +1 -1
index 3149ff08d8..5e946846f1 100644
@@ -551,7 +551,7 @@ static int vhdx_log_flush(BlockDriverState *bs,
 BDRVVHDXState *s,
         }
         if (file_length < desc_entries->hdr.last_file_offset) {
             new_file_size = desc_entries->hdr.last_file_offset;
-            if (new_file_size % (1024*1024)) {
+            if (new_file_size % (1 * MiB)) {
                 /* round up to nearest 1MB boundary */
                 new_file_size = QEMU_ALIGN_UP(new_file_size, MiB);
                 if (new_file_size > INT64_MAX) {
block/vhdx.c +1 -1
index 7cd1fc3731..a143a57657 100644
@@ -1175,7 +1175,7 @@ static int vhdx_allocate_block(BlockDriverState *bs,
 BDRVVHDXState *s,
     *new_offset = current_len;
 
     /* per the spec, the address for a block is in units of 1MB */
-    *new_offset = ROUND_UP(*new_offset, 1024 * 1024);
+    *new_offset = ROUND_UP(*new_offset, 1 * MiB);
     if (*new_offset > INT64_MAX) {
         return -EINVAL;
     }
block/vhdx.c +1 -1
@@ -1338,7 +1338,7 @@ static coroutine_fn int
 vhdx_co_writev(BlockDriverState *bs, int64_t sector_num,
             case PAYLOAD_BLOCK_FULLY_PRESENT:
                 /* if the file offset address is in the header zone,
                  * there is a problem */
-                if (sinfo.file_offset < (1024 * 1024)) {
+                if (sinfo.file_offset < (1 * MiB)) {
                     ret = -EFAULT;
                     goto error_bat_restore;
                 }
block/vhdx.h +2 -0
index bf72090c8f..0b74924cee 100644
@@ -20,6 +20,8 @@
 #include "qemu/units.h"
 
 #define DEFAULT_LOG_SIZE 1048576 /* 1MiB */
+/* Note: can't use 1 * MiB, because it's passed to stringify() */
+
 /* Structures and fields present in the VHDX file */
 
 /* The header section has the following blocks,
@@ -32,7 +34,7 @@
  *

0.........64KB...........128KB........192KB..........256KB................1MB
*/

block/vhdx.h +1 -2
-#define VHDX_HEADER_BLOCK_SIZE      (64 * 1024)
+#define VHDX_HEADER_BLOCK_SIZE      (64 * KiB)
 
 #define VHDX_FILE_ID_OFFSET         0
 #define VHDX_HEADER1_OFFSET         (VHDX_HEADER_BLOCK_SIZE * 1)
@@ -81,7 +83,7 @@ typedef struct QEMU_PACKED MSGUID {
 #define guid_eq(a, b) \
     (memcmp(&(a), &(b), sizeof(MSGUID)) == 0)
 
-#define VHDX_HEADER_SIZE (4 * 1024)   /* although the vhdx_header struct

in disk
+#define VHDX_HEADER_SIZE (4 * KiB) /* although the vhdx_header struct
in disk
is only 582 bytes, for purposes
of crc
the header is the first 4KB of
the 64KB
block */

block/vhdx.h +0 -0
@@ -157,8 +159,8 @@ typedef struct QEMU_PACKED VHDXRegionTableEntry {
 

block/vhdx.h typedef struct QEMU_PACKED VHDXRegionTableEntry {

Quoted 10 lines
block/vhdx.h +2 -3
 
 /* ---- LOG ENTRY STRUCTURES ---- */
-#define VHDX_LOG_MIN_SIZE (1024 * 1024)
-#define VHDX_LOG_SECTOR_SIZE 4096
+#define VHDX_LOG_MIN_SIZE (1 * MiB)
+#define VHDX_LOG_SECTOR_SIZE (4 * KiB)
 #define VHDX_LOG_HDR_SIZE 64
 #define VHDX_LOG_SIGNATURE 0x65676f6c
 typedef struct QEMU_PACKED VHDXLogEntryHeader {
-- 2.20.1
Quoted 1 line
Applied
#11 lore raw
In reply to Stefano Garzarella

Am 27.03.2019 um 10:56 hat Stefano Garzarella geschrieben:

Quoted 7 lines

v2:
- Included units.h directly in the vhdx.h header file (John, Philippe)
- Added a comment next to DEFAULT_LOG_SIZE definition (Kevin)
- Added a second patch where I fixed some size constants using IEC binary prefixes.
Note: checkpatch is not happy about a change in vhdx.h but all the comments in that file doesn't respect the new coding style so I left the comment as is

Thanks, applied to the block-next branch for 4.1.

Kevin