size_t size,
void *buffer,
unsigned int flags);
+
+/**
+ * virDomainBlockResizeFlags:
+ *
+ * Flags available for virDomainBlockResize().
+ */
+typedef enum {
+ VIR_DOMAIN_BLOCK_RESIZE_BYTES = 1 << 0, /* size in bytes instead of KiB */
+} virDomainBlockResizeFlags;
+
int virDomainBlockResize (virDomainPtr dom,
const char *disk,
unsigned long long size,
* virDomainBlockResize:
* @dom: pointer to the domain object
* @disk: path to the block image, or shorthand
- * @size: new size of the block image in kilobytes
- * @flags: extra flags; not used yet, so callers should always pass 0
+ * @size: new size of the block image, see below for unit
+ * @flags: bitwise-OR of virDomainBlockResizeFlags
*
- * Note that this call may fail if the underlying virtualization hypervisor
- * does not support it. And this call requires privileged access to the
- * hypervisor.
+ * Resize a block device of domain while the domain is running. If
+ * @flags is 0, then @size is in kibibytes (blocks of 1024); since
+ * 0.9.11, if @flags includes VIR_DOMAIN_BLOCK_RESIZE_BYTES, @size is
+ * in bytes instead. @size is taken directly as the new size.
+ * Depending on the file format, the hypervisor may round up to the
+ * next alignment boundary.
*
* The @disk parameter is either an unambiguous source name of the
* block device (the <source file='...'/> sub-element, such as
* can be found by calling virDomainGetXMLDesc() and inspecting
* elements within //domain/devices/disk.
*
- * Resize a block device of domain while the domain is running.
+ * Note that this call may fail if the underlying virtualization hypervisor
+ * does not support it; this call requires privileged access to the
+ * hypervisor.
*
* Returns: 0 in case of success or -1 in case of failure.
*/
* like LVM volumes.
*/
static int
-qemuDomainBlockResize (virDomainPtr dom,
- const char *path,
- unsigned long long size,
- unsigned int flags)
+qemuDomainBlockResize(virDomainPtr dom,
+ const char *path,
+ unsigned long long size,
+ unsigned int flags)
{
struct qemud_driver *driver = dom->conn->privateData;
virDomainObjPtr vm;
char *device = NULL;
virDomainDiskDefPtr disk = NULL;
- virCheckFlags(0, -1);
+ virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES, -1);
if (path[0] == '\0') {
qemuReportError(VIR_ERR_INVALID_ARG,
return -1;
}
- if (size > ULLONG_MAX / 1024) {
- qemuReportError(VIR_ERR_INVALID_ARG,
- _("size must be less than %llu"),
- ULLONG_MAX / 1024);
- return -1;
+ /* We prefer operating on bytes. */
+ if ((flags & VIR_DOMAIN_BLOCK_RESIZE_BYTES) == 0) {
+ if (size > ULLONG_MAX / 1024) {
+ qemuReportError(VIR_ERR_INVALID_ARG,
+ _("size must be less than %llu"),
+ ULLONG_MAX / 1024);
+ return -1;
+ }
+ size *= 1024;
}
qemuDriverLock(driver);
return ret;
}
-/* Return 0 on success, -1 on failure, or -2 if not supported. */
+/* Return 0 on success, -1 on failure, or -2 if not supported. Size
+ * is in bytes. */
int qemuMonitorJSONBlockResize(qemuMonitorPtr mon,
const char *device,
unsigned long long size)
cmd = qemuMonitorJSONMakeCommand("block_resize",
"s:device", device,
- "U:size", size * 1024,
+ "U:size", size,
NULL);
if (!cmd)
return -1;
return -1;
}
-/* Return 0 on success, -1 on failure, or -2 if not supported. */
+/* Return 0 on success, -1 on failure, or -2 if not supported. Size
+ * is in bytes. */
int qemuMonitorTextBlockResize(qemuMonitorPtr mon,
const char *device,
unsigned long long size)
char *reply = NULL;
int ret = -1;
- if (virAsprintf(&cmd, "block_resize %s %llu",
- device, VIR_DIV_UP(size, 1024)) < 0) {
+ if (virAsprintf(&cmd, "block_resize %s %lluB", device, size) < 0) {
virReportOOMError();
goto cleanup;
}