[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 7/7] iscsi: Move iqn generation code to util
From: |
Fam Zheng |
Subject: |
[Qemu-devel] [PATCH v2 7/7] iscsi: Move iqn generation code to util |
Date: |
Fri, 22 Aug 2014 18:54:23 +0800 |
Function qmp_query_uuid, even with a version in libqemustub.a, is not
linked in qemu-img, unless we use it in somewhere that is linked into
qemu-img. For example util-obj-y - since iqn generation a general
function, not iscsi specific, moving it to util makes some sense, and
more importantly this will allow us to build iscsi as a dynamic module.
Signed-off-by: Fam Zheng <address@hidden>
---
block/iscsi.c | 15 +--------------
include/qemu-common.h | 3 +++
util/Makefile.objs | 1 +
util/iqn.c | 37 +++++++++++++++++++++++++++++++++++++
4 files changed, 42 insertions(+), 14 deletions(-)
create mode 100644 util/iqn.c
diff --git a/block/iscsi.c b/block/iscsi.c
index 2c9cfc1..4436156 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -37,8 +37,6 @@
#include "trace.h"
#include "block/scsi.h"
#include "qemu/iov.h"
-#include "sysemu/sysemu.h"
-#include "qmp-commands.h"
#include <iscsi/iscsi.h>
#include <iscsi/scsi-lowlevel.h>
@@ -1034,8 +1032,6 @@ static char *parse_initiator_name(const char *target)
QemuOptsList *list;
QemuOpts *opts;
const char *name;
- char *iscsi_name;
- UuidInfo *uuid_info;
list = qemu_find_opts("iscsi");
if (list) {
@@ -1051,16 +1047,7 @@ static char *parse_initiator_name(const char *target)
}
}
- uuid_info = qmp_query_uuid(NULL);
- if (strcmp(uuid_info->UUID, UUID_NONE) == 0) {
- name = qemu_get_vm_name();
- } else {
- name = uuid_info->UUID;
- }
- iscsi_name = g_strdup_printf("iqn.2008-11.org.linux-kvm%s%s",
- name ? ":" : "", name ? name : "");
- qapi_free_UuidInfo(uuid_info);
- return iscsi_name;
+ return iqn_generate();
}
static void iscsi_nop_timed_event(void *opaque)
diff --git a/include/qemu-common.h b/include/qemu-common.h
index bcf7a6a..69505b5 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -420,6 +420,9 @@ int uleb128_decode_small(const uint8_t *in, uint32_t *n);
/* unicode.c */
int mod_utf8_codepoint(const char *s, size_t n, char **end);
+/* iqn.c */
+char *iqn_generate(void);
+
/*
* Hexdump a buffer to a file. An optional string prefix is added to every line
*/
diff --git a/util/Makefile.objs b/util/Makefile.objs
index 5940acc..30a3c77 100644
--- a/util/Makefile.objs
+++ b/util/Makefile.objs
@@ -13,3 +13,4 @@ util-obj-y += crc32c.o
util-obj-y += getauxval.o
util-obj-y += readline.o
util-obj-y += rfifolock.o
+util-obj-y += iqn.o
diff --git a/util/iqn.c b/util/iqn.c
new file mode 100644
index 0000000..ed30f0f
--- /dev/null
+++ b/util/iqn.c
@@ -0,0 +1,37 @@
+/*
+ * iqn generate function
+ *
+ * Copyright Red Hat, Inc., 2014
+ *
+ * Author: Paolo Bonzini <address@hidden>
+ * Fam Zheng <address@hidden>
+ *
+ * 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 <glib.h>
+#include "qemu/error-report.h"
+#include "qemu-common.h"
+#include "sysemu/sysemu.h"
+#include "qmp-commands.h"
+
+char *iqn_generate(void)
+{
+ const char *name;
+ char *iqn;
+ UuidInfo *uuid_info;
+
+ uuid_info = qmp_query_uuid(NULL);
+ if (strcmp(uuid_info->UUID, UUID_NONE) == 0) {
+ name = qemu_get_vm_name();
+ } else {
+ name = uuid_info->UUID;
+ }
+ iqn = g_strdup_printf("iqn.2008-11.org.linux-kvm%s%s",
+ name ? ":" : "",
+ name ? : "");
+ qapi_free_UuidInfo(uuid_info);
+
+ return iqn;
+}
--
2.0.3
- [Qemu-devel] [PATCH v2 0/7] build-sys: Fix iscsi module loading failure, Fam Zheng, 2014/08/22
- [Qemu-devel] [PATCH v2 1/7] build-sys: Move fifo8.c to hw/misc, Fam Zheng, 2014/08/22
- [Qemu-devel] [PATCH v2 2/7] configure: Add -lutil to libs_qga if necessary, Fam Zheng, 2014/08/22
- [Qemu-devel] [PATCH v2 3/7] stubs: Add iohandler.c, Fam Zheng, 2014/08/22
- [Qemu-devel] [PATCH v2 4/7] stubs: Merge set-fd-handler.c into iohandler.c, Fam Zheng, 2014/08/22
- [Qemu-devel] [PATCH v2 6/7] build-sys: Change libqemuutil.a to qemuutil.o and link whole object, Fam Zheng, 2014/08/22
- [Qemu-devel] [PATCH v2 5/7] util: Move throttle.c out to top level, Fam Zheng, 2014/08/22
- [Qemu-devel] [PATCH v2 7/7] iscsi: Move iqn generation code to util,
Fam Zheng <=
- Re: [Qemu-devel] [PATCH v2 0/7] build-sys: Fix iscsi module loading failure, Stefan Hajnoczi, 2014/08/22