[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v9 3/5] move logical block size check function to a common utilit
From: |
Coiby Xu |
Subject: |
[PATCH v9 3/5] move logical block size check function to a common utility function |
Date: |
Mon, 15 Jun 2020 02:39:05 +0800 |
Move logical block size check function in
hw/core/qdev-properties.c:set_blocksize() to util/block-helpers.c
Signed-off-by: Coiby Xu <coiby.xu@gmail.com>
---
hw/core/qdev-properties.c | 18 +++------------
util/Makefile.objs | 1 +
util/block-helpers.c | 46 +++++++++++++++++++++++++++++++++++++++
util/block-helpers.h | 7 ++++++
4 files changed, 57 insertions(+), 15 deletions(-)
create mode 100644 util/block-helpers.c
create mode 100644 util/block-helpers.h
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index cc924815da..a4a6aa5204 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -14,6 +14,7 @@
#include "qapi/visitor.h"
#include "chardev/char.h"
#include "qemu/uuid.h"
+#include "util/block-helpers.h"
void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
Error **errp)
@@ -736,8 +737,6 @@ static void set_blocksize(Object *obj, Visitor *v, const
char *name,
Property *prop = opaque;
uint16_t value, *ptr = qdev_get_prop_ptr(dev, prop);
Error *local_err = NULL;
- const int64_t min = 512;
- const int64_t max = 32768;
if (dev->realized) {
qdev_prop_set_after_realize(dev, name, errp);
@@ -749,21 +748,10 @@ static void set_blocksize(Object *obj, Visitor *v, const
char *name,
error_propagate(errp, local_err);
return;
}
- /* value of 0 means "unset" */
- if (value && (value < min || value > max)) {
- error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
- dev->id ? : "", name, (int64_t)value, min, max);
+ check_logical_block_size(dev->id ? : "", name, value, errp);
+ if (errp) {
return;
}
-
- /* We rely on power-of-2 blocksizes for bitmasks */
- if ((value & (value - 1)) != 0) {
- error_setg(errp,
- "Property %s.%s doesn't take value '%" PRId64 "', it's not a
power of 2",
- dev->id ?: "", name, (int64_t)value);
- return;
- }
-
*ptr = value;
}
diff --git a/util/Makefile.objs b/util/Makefile.objs
index b4d4af06dc..fa5380ddab 100644
--- a/util/Makefile.objs
+++ b/util/Makefile.objs
@@ -66,6 +66,7 @@ util-obj-y += hbitmap.o
util-obj-y += main-loop.o
util-obj-y += nvdimm-utils.o
util-obj-y += qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o
+util-obj-y += block-helpers.o
util-obj-$(CONFIG_LINUX) += vhost-user-server.o
util-obj-y += qemu-coroutine-sleep.o
util-obj-y += qemu-co-shared-resource.o
diff --git a/util/block-helpers.c b/util/block-helpers.c
new file mode 100644
index 0000000000..d31309cc0e
--- /dev/null
+++ b/util/block-helpers.c
@@ -0,0 +1,46 @@
+/*
+ * Block utility functions
+ *
+ * Copyright (c) 2020 Coiby Xu <coiby.xu@gmail.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qapi/qmp/qerror.h"
+#include "block-helpers.h"
+
+/*
+ * Logical block size input validation
+ *
+ * The size should meet the following conditions:
+ * 1. min=512
+ * 2. max=32768
+ * 3. a power of 2
+ *
+ * Moved from hw/core/qdev-properties.c:set_blocksize()
+ */
+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)) {
+ error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
+ id, name, (int64_t)value, min, max);
+ return;
+ }
+
+ /* We rely on power-of-2 blocksizes for bitmasks */
+ if ((value & (value - 1)) != 0) {
+ error_setg(errp,
+ "Property %s.%s doesn't take value '%" PRId64
+ "', it's not a power of 2",
+ id, name, (int64_t)value);
+ return;
+ }
+}
diff --git a/util/block-helpers.h b/util/block-helpers.h
new file mode 100644
index 0000000000..f06be282a1
--- /dev/null
+++ b/util/block-helpers.h
@@ -0,0 +1,7 @@
+#ifndef BLOCK_HELPERS_H
+#define BLOCK_HELPERS_H
+
+void check_logical_block_size(const char *id, const char *name, uint16_t value,
+ Error **errp);
+
+#endif /* BLOCK_HELPERS_H */
--
2.27.0
- Re: [PATCH v9 1/5] Allow vu_message_read to be replaced, (continued)
- [PATCH v9 2/5] generic vhost user server, Coiby Xu, 2020/06/14
- Re: [PATCH v9 2/5] generic vhost user server, Kevin Wolf, 2020/06/18
- [PATCH 1/6] vhost-user-server: fix VHOST_MEMORY_MAX_REGIONS compiler error, Stefan Hajnoczi, 2020/06/19
- [PATCH 3/6] vhost-user-server: adjust vhost_user_server_set_aio_context() arguments, Stefan Hajnoczi, 2020/06/19
- [PATCH 2/6] vhost-user-server: drop unused #include <eventfd.h>, Stefan Hajnoczi, 2020/06/19
- [PATCH 5/6] vhost-user-server: fix s/initialized/initialize/ typo, Stefan Hajnoczi, 2020/06/19
- [PATCH 6/6] vhost-user-server: use DevicePanicNotifierFn everywhere, Stefan Hajnoczi, 2020/06/19
- [PATCH 4/6] vhost-user-server: mark fd handlers "external", Stefan Hajnoczi, 2020/06/19
- Re: [PATCH v9 2/5] generic vhost user server, Stefan Hajnoczi, 2020/06/19
- [PATCH v9 3/5] move logical block size check function to a common utility function,
Coiby Xu <=
- Re: [PATCH v9 3/5] move logical block size check function to a common utility function, Kevin Wolf, 2020/06/18
- [PATCH 1/6] block-helpers: move MIN/MAX_BLOCK_SIZE constants into header file, Stefan Hajnoczi, 2020/06/19
- [PATCH 2/6] block-helpers: switch to int64_t block size values, Stefan Hajnoczi, 2020/06/19
- [PATCH 3/6] block-helpers: rename check_logical_block_size() to check_block_size(), Stefan Hajnoczi, 2020/06/19
- [PATCH 4/6] block-helpers: use local_err in case errp is NULL, Stefan Hajnoczi, 2020/06/19
- [PATCH 5/6] block-helpers: keep the copyright line from the original file, Stefan Hajnoczi, 2020/06/19
- [PATCH 6/6] block-helpers: update doc comment in gtkdoc style, Stefan Hajnoczi, 2020/06/19
- [PATCH v9 4/5] vhost-user block device backend server, Coiby Xu, 2020/06/14