File 0001-libxl-add-support-for-BlockResize-API.patch of Package libvirt
xxxxxxxxxx
1
From 661298572a5499ccfafcd36d30d66d091a5be9b6 Mon Sep 17 00:00:00 2001
2
From: Jim Fehlig <jfehlig@suse.com>
3
Date: Fri, 23 Mar 2018 17:41:51 -0600
4
Subject: [PATCH] libxl: add support for BlockResize API
5
6
Add support in the libxl driver for the BlockResize API. Use libxl's
7
libxl_qemu_monitor_command API to issue the block_resize command to qemu.
8
9
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
10
11
Note: In its current form, this patch is not upstream material IMO. It uses
12
the unsupported libxl_qemu_monitor_command() API. Before it can be considered
13
upstream, we need an upstream solution in qemu and Xen. Bruce will work on
14
the qemu part. Once done we can consider how to do the Xen part. And only
15
after we have a supported blockresize API in Xen (libxl) can we consider
16
reworking this patch and submitting it to upstream libvirt.
17
18
---
19
src/libxl/libxl_driver.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
20
1 file changed, 91 insertions(+)
21
22
Index: libvirt-7.1.0/src/libxl/libxl_driver.c
23
===================================================================
24
--- libvirt-7.1.0.orig/src/libxl/libxl_driver.c
25
+++ libvirt-7.1.0/src/libxl/libxl_driver.c
26
27
28
#undef LIBXL_SET_MEMSTAT
29
30
+/**
31
+ * Resize a block device while a guest is running. Resize to a lower size
32
+ * is supported, but should be used with extreme caution. Note that it
33
+ * only supports to resize image files, it can't resize block devices
34
+ * like LVM volumes.
35
+ */
36
+static int
37
+libxlDomainBlockResize(virDomainPtr dom,
38
+ const char *path,
39
+ unsigned long long size,
40
+ unsigned int flags)
41
+{
42
+ libxlDriverPrivatePtr driver = dom->conn->privateData;
43
+ libxlDriverConfigPtr cfg;
44
+ virDomainObjPtr vm;
45
+ int ret = -1;
46
+ virDomainDiskDefPtr disk = NULL;
47
+ char *moncmd = NULL;
48
+ char *monreply = NULL;
49
+
50
+ virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES, -1);
51
+
52
+ if (path[0] == '\0') {
53
+ virReportError(VIR_ERR_INVALID_ARG,
54
+ "%s", _("empty path"));
55
+ return -1;
56
+ }
57
+
58
+ /* We prefer operating on bytes. */
59
+ if ((flags & VIR_DOMAIN_BLOCK_RESIZE_BYTES) == 0) {
60
+ if (size > ULLONG_MAX / 1024) {
61
+ virReportError(VIR_ERR_OVERFLOW,
62
+ _("size must be less than %llu"),
63
+ ULLONG_MAX / 1024);
64
+ return -1;
65
+ }
66
+ size *= 1024;
67
+ }
68
+
69
+ cfg = libxlDriverConfigGet(driver);
70
+ if (!(vm = libxlDomObjFromDomain(dom)))
71
+ goto cleanup;
72
+
73
+ if (virDomainBlockResizeEnsureACL(dom->conn, vm->def) < 0)
74
+ goto cleanup;
75
+
76
+ if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
77
+ goto cleanup;
78
+
79
+ if (!virDomainObjIsActive(vm)) {
80
+ virReportError(VIR_ERR_OPERATION_INVALID,
81
+ "%s", _("domain is not running"));
82
+ goto endjob;
83
+ }
84
+
85
+ if (!(disk = virDomainDiskByName(vm->def, path, false))) {
86
+ virReportError(VIR_ERR_INVALID_ARG,
87
+ _("invalid path: %s"), path);
88
+ goto endjob;
89
+ }
90
+
91
+ /* qcow2 and qed must be sized on 512 byte blocks/sectors,
92
+ * so adjust size if necessary to round up.
93
+ */
94
+ if (disk->src->format == VIR_STORAGE_FILE_QCOW2 ||
95
+ disk->src->format == VIR_STORAGE_FILE_QED)
96
+ size = VIR_ROUND_UP(size, 512);
97
+
98
+ moncmd = g_strdup_printf("block_resize %s %lluB", disk->dst, size);
99
+
100
+ if (libxl_qemu_monitor_command(cfg->ctx, vm->def->id, moncmd, &monreply) != 0) {
101
+ virReportError(VIR_ERR_OPERATION_FAILED,
102
+ _("block_resize command failed for device '%s' on domain '%d'"),
103
+ disk->dst, vm->def->id);
104
+ goto endjob;
105
+ }
106
+
107
+ ret = 0;
108
+
109
+ endjob:
110
+ libxlDomainObjEndJob(driver, vm);
111
+
112
+ cleanup:
113
+ VIR_FREE(moncmd);
114
+ VIR_FREE(monreply);
115
+ virDomainObjEndAPI(&vm);
116
+ virObjectUnref(cfg);
117
+ return ret;
118
+}
119
+
120
static int
121
libxlDomainGetJobInfo(virDomainPtr dom,
122
virDomainJobInfoPtr info)
123
124
#endif
125
.nodeGetFreeMemory = libxlNodeGetFreeMemory, /* 0.9.0 */
126
.nodeGetCellsFreeMemory = libxlNodeGetCellsFreeMemory, /* 1.1.1 */
127
+ .domainBlockResize = libxlDomainBlockResize, /* 4.2.0 */
128
.domainGetJobInfo = libxlDomainGetJobInfo, /* 1.3.1 */
129
.domainGetJobStats = libxlDomainGetJobStats, /* 1.3.1 */
130
.domainMemoryStats = libxlDomainMemoryStats, /* 1.3.0 */
131