qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/6] block-helpers: move MIN/MAX_BLOCK_SIZE constants into header


From: Stefan Hajnoczi
Subject: [PATCH 1/6] block-helpers: move MIN/MAX_BLOCK_SIZE constants into header file
Date: Fri, 19 Jun 2020 13:01:52 +0100

Move the constants from hw/core/qdev-properties.c to
util/block-helpers.h so that knowledge of the min/max values is
encapsulated in block-helpers code.

Callers should not assume specific min/max values. In fact, the values
in hw/core/qdev-properties.c and util/block-helpers.c did not match. Use
the hw/core/qdev-properties.c values since that's what existing code
expects.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 util/block-helpers.h      | 12 ++++++++++++
 hw/core/qdev-properties.c | 11 -----------
 util/block-helpers.c      |  7 ++-----
 3 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/util/block-helpers.h b/util/block-helpers.h
index f06be282a1..46975ca7af 100644
--- a/util/block-helpers.h
+++ b/util/block-helpers.h
@@ -1,6 +1,18 @@
 #ifndef BLOCK_HELPERS_H
 #define BLOCK_HELPERS_H
 
+#include "qemu/units.h"
+
+/* lower limit is sector size */
+#define MIN_BLOCK_SIZE          INT64_C(512)
+#define MIN_BLOCK_SIZE_STR      "512 B"
+/*
+ * upper limit is arbitrary, 2 MiB looks sufficient for all sensible uses, and
+ * matches qcow2 cluster size limit
+ */
+#define MAX_BLOCK_SIZE          (2 * MiB)
+#define MAX_BLOCK_SIZE_STR      "2 MiB"
+
 void check_logical_block_size(const char *id, const char *name, uint16_t value,
                      Error **errp);
 
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index b478f100af..03981feb02 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -14,7 +14,6 @@
 #include "qapi/visitor.h"
 #include "chardev/char.h"
 #include "qemu/uuid.h"
-#include "qemu/units.h"
 #include "util/block-helpers.h"
 
 void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
@@ -782,16 +781,6 @@ const PropertyInfo qdev_prop_size32 = {
 
 /* --- blocksize --- */
 
-/* lower limit is sector size */
-#define MIN_BLOCK_SIZE          512
-#define MIN_BLOCK_SIZE_STR      "512 B"
-/*
- * upper limit is arbitrary, 2 MiB looks sufficient for all sensible uses, and
- * matches qcow2 cluster size limit
- */
-#define MAX_BLOCK_SIZE          (2 * MiB)
-#define MAX_BLOCK_SIZE_STR      "2 MiB"
-
 static void set_blocksize(Object *obj, Visitor *v, const char *name,
                           void *opaque, Error **errp)
 {
diff --git a/util/block-helpers.c b/util/block-helpers.c
index d31309cc0e..089fe3401d 100644
--- a/util/block-helpers.c
+++ b/util/block-helpers.c
@@ -25,13 +25,10 @@
 void check_logical_block_size(const char *id, const char *name, uint16_t value,
                      Error **errp)
 {
-    const int64_t min = 512;
-    const int64_t max = 32768;
-
     /* value of 0 means "unset" */
-    if (value && (value < min || value > max)) {
+    if (value && (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE)) {
         error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
-                   id, name, (int64_t)value, min, max);
+                   id, name, value, MIN_BLOCK_SIZE, MAX_BLOCK_SIZE);
         return;
     }
 
-- 
2.26.2


reply via email to

[Prev in Thread] Current Thread [Next in Thread]