[libvirt] CPU tuning in containers
by Sukadev Bhattiprolu
Following section indicates that CPU tuning with <period> and <quota>
tags are only supported for QEMU
http://libvirt.org/formatdomain.html#elementsCPUTuning
I see this commit in libvirt.git:
commit d9724a81b3c53a40f45bf76067a976cce73ed278
Author: Daniel P. Berrange <berrange(a)redhat.com>
Date: Thu Nov 10 12:16:26 2011 +0000
Add support for CPU quota/period to LXC driver
and the code seems to be included in libvirt-0.9.10-21.el6.
I have not had a chance to try on latest libvirt yet, but is it just
that the CPUTuning section on the above wiki needs an update ?
12 years, 5 months
[libvirt] [PATCH v4 0/7] file descriptor passing using pass-fd
by Corey Bryant
libvirt's sVirt security driver provides SELinux MAC isolation for
Qemu guest processes and their corresponding image files. In other
words, sVirt uses SELinux to prevent a QEMU process from opening
files that do not belong to it.
sVirt provides this support by labeling guests and resources with
security labels that are stored in file system extended attributes.
Some file systems, such as NFS, do not support the extended
attribute security namespace, and therefore cannot support sVirt
isolation.
A solution to this problem is to provide fd passing support, where
libvirt opens files and passes file descriptors to QEMU. This,
along with SELinux policy to prevent QEMU from opening files, can
provide image file isolation for NFS files stored on the same NFS
mount.
This patch series adds the pass-fd QMP monitor command, which allows
an fd to be passed via SCM_RIGHTS, and returns the received file
descriptor. Support is also added to the block layer to allow QEMU
to dup the fd when the filename is of the /dev/fd/X format. This
is useful if MAC policy prevents QEMU from opening specific types
of files.
One nice thing about this approach is that no new SELinux policy is
required to prevent open of NFS files (files with type nfs_t). The
virt_use_nfs boolean type simply needs to be set to false, and open
will be prevented (and dup will be allowed). For example:
# setsebool virt_use_nfs 0
# getsebool virt_use_nfs
virt_use_nfs --> off
Corey Bryant (7):
qemu-char: Add MSG_CMSG_CLOEXEC flag to recvmsg
qapi: Convert getfd and closefd
qapi: Add pass-fd QMP command
qapi: Re-arrange monitor.c functions
block: Prevent /dev/fd/X filename from being detected as floppy
block: Convert open calls to qemu_open
osdep: Enable qemu_open to dup pre-opened fd
block/raw-posix.c | 22 +++++-----
block/raw-win32.c | 4 +-
block/vdi.c | 5 ++-
block/vmdk.c | 21 ++++------
block/vpc.c | 2 +-
block/vvfat.c | 21 +++++-----
cutils.c | 26 +++++++++---
dump.c | 3 +-
hmp-commands.hx | 6 +--
hmp.c | 18 ++++++++
hmp.h | 2 +
main-loop.c | 6 +--
migration-fd.c | 2 +-
monitor.c | 120 ++++++++++++++++++++++++++++++++---------------------
monitor.h | 2 +-
net.c | 6 ++-
osdep.c | 91 ++++++++++++++++++++++++++++++++++++++++
qapi-schema.json | 71 +++++++++++++++++++++++++++++++
qemu-char.c | 2 +-
qemu-common.h | 2 +-
qmp-commands.hx | 56 ++++++++++++++++++++++---
21 files changed, 378 insertions(+), 110 deletions(-)
--
1.7.10.2
12 years, 5 months
[libvirt] [PATCH] Support creation of sparse LVM volumes
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
When calling 'lvcreate' if specifying both the '-L' and
'--virtualsize' options, the latter will be treated as
the capacity and the former as the allocation. This can
be used to support sparse volume creation. In addition,
when listing volumes it is neccessary to include the 'size'
field in lvs output, so that we can detect sparse volume
allocation correctly.
---
src/storage/storage_backend_logical.c | 27 ++++++++++++++++++---------
1 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index 9fe769b..c6e09e6 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -171,6 +171,11 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool,
"%s", _("malformed volume extent size value"));
goto cleanup;
}
+ if (virStrToLong_ull(groups[8], NULL, 10, &vol->allocation) < 0) {
+ virStorageReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("malformed volume allocation value"));
+ goto cleanup;
+ }
/* Now parse the "devices" field separately */
regex = strdup(regex_unit);
@@ -271,12 +276,12 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
virStorageVolDefPtr vol)
{
/*
- * # lvs --separator , --noheadings --units b --unbuffered --nosuffix --options "lv_name,origin,uuid,devices,seg_size,vg_extent_size" VGNAME
- * RootLV,,06UgP5-2rhb-w3Bo-3mdR-WeoL-pytO-SAa2ky,/dev/hda2(0),5234491392,33554432
- * SwapLV,,oHviCK-8Ik0-paqS-V20c-nkhY-Bm1e-zgzU0M,/dev/hda2(156),1040187392,33554432
- * Test2,,3pg3he-mQsA-5Sui-h0i6-HNmc-Cz7W-QSndcR,/dev/hda2(219),1073741824,33554432
- * Test3,,UB5hFw-kmlm-LSoX-EI1t-ioVd-h7GL-M0W8Ht,/dev/hda2(251),2181038080,33554432
- * Test3,Test2,UB5hFw-kmlm-LSoX-EI1t-ioVd-h7GL-M0W8Ht,/dev/hda2(187),1040187392,33554432
+ * # lvs --separator , --noheadings --units b --unbuffered --nosuffix --options "lv_name,origin,uuid,devices,seg_size,vg_extent_size,size" VGNAME
+ * RootLV,,06UgP5-2rhb-w3Bo-3mdR-WeoL-pytO-SAa2ky,/dev/hda2(0),5234491392,33554432,5234491392
+ * SwapLV,,oHviCK-8Ik0-paqS-V20c-nkhY-Bm1e-zgzU0M,/dev/hda2(156),1040187392,33554432,1040187392
+ * Test2,,3pg3he-mQsA-5Sui-h0i6-HNmc-Cz7W-QSndcR,/dev/hda2(219),1073741824,33554432,1073741824
+ * Test3,,UB5hFw-kmlm-LSoX-EI1t-ioVd-h7GL-M0W8Ht,/dev/hda2(251),2181038080,33554432,2181038080
+ * Test3,Test2,UB5hFw-kmlm-LSoX-EI1t-ioVd-h7GL-M0W8Ht,/dev/hda2(187),1040187392,33554432,1040187392
*
* Pull out name, origin, & uuid, device, device extent start #, segment size, extent size.
*
@@ -290,10 +295,10 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
* striped, so "," is not a suitable separator either (rhbz 727474).
*/
const char *regexes[] = {
- "^\\s*(\\S+)#(\\S*)#(\\S+)#(\\S+)#(\\S+)#([0-9]+)#(\\S+)#([0-9]+)#?\\s*$"
+ "^\\s*(\\S+)#(\\S*)#(\\S+)#(\\S+)#(\\S+)#([0-9]+)#(\\S+)#([0-9]+)#([0-9]+)#?\\s*$"
};
int vars[] = {
- 8
+ 9
};
int ret = -1;
virCommandPtr cmd;
@@ -304,7 +309,7 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
"--units", "b",
"--unbuffered",
"--nosuffix",
- "--options", "lv_name,origin,uuid,devices,segtype,stripes,seg_size,vg_extent_size",
+ "--options", "lv_name,origin,uuid,devices,segtype,stripes,seg_size,vg_extent_size,size",
pool->def->source.name,
NULL);
if (virStorageBackendRunProgRegex(pool,
@@ -718,6 +723,10 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
"--name", vol->name,
NULL);
virCommandAddArg(cmd, "-L");
+ if (vol->capacity != vol->allocation) {
+ virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->allocation, 1024));
+ virCommandAddArg(cmd, "--virtualsize");
+ }
virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->capacity, 1024));
if (vol->backingStore.path)
virCommandAddArgPair(cmd, "-s", vol->backingStore.path);
--
1.7.7.6
12 years, 5 months
[libvirt] [PATCH] Remove all use of virRun in storage code
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
To make it easier to dynamically change the command line ARGV,
switch all storage code over to use virCommandPtr APIs for
running programs
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/storage/storage_backend.c | 15 +--
src/storage/storage_backend.h | 5 +-
src/storage/storage_backend_disk.c | 93 +++++++--------
src/storage/storage_backend_fs.c | 134 +++++++++-----------
src/storage/storage_backend_iscsi.c | 107 +++++++++-------
src/storage/storage_backend_logical.c | 225 ++++++++++++++++++---------------
6 files changed, 294 insertions(+), 285 deletions(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index e2e9b51..e0ff717 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -57,7 +57,6 @@
#include "storage_backend.h"
#include "logging.h"
#include "virfile.h"
-#include "command.h"
#if WITH_STORAGE_LVM
# include "storage_backend_logical.h"
@@ -1418,7 +1417,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
*/
int
virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
- const char *const*prog,
+ virCommandPtr cmd,
int nregex,
const char **regex,
int *nvars,
@@ -1433,7 +1432,6 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
int maxReg = 0, i, j;
int totgroups = 0, ngroup = 0, maxvars = 0;
char **groups;
- virCommandPtr cmd = NULL;
/* Compile all regular expressions */
if (VIR_ALLOC_N(reg, nregex) < 0) {
@@ -1470,7 +1468,6 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
goto cleanup;
}
- cmd = virCommandNewArgs(prog);
virCommandSetOutputFD(cmd, &fd);
if (virCommandRunAsync(cmd, NULL) < 0) {
goto cleanup;
@@ -1541,7 +1538,6 @@ cleanup:
regfree(®[i]);
VIR_FREE(reg);
- virCommandFree(cmd);
VIR_FORCE_FCLOSE(list);
VIR_FORCE_CLOSE(fd);
@@ -1562,7 +1558,7 @@ cleanup:
*/
int
virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
- const char **prog,
+ virCommandPtr cmd,
size_t n_columns,
virStorageBackendListVolNulFunc func,
void *data)
@@ -1573,7 +1569,6 @@ virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
char **v;
int ret = -1;
int i;
- virCommandPtr cmd = NULL;
if (n_columns == 0)
return -1;
@@ -1585,7 +1580,6 @@ virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
for (i = 0; i < n_columns; i++)
v[i] = NULL;
- cmd = virCommandNewArgs(prog);
virCommandSetOutputFD(cmd, &fd);
if (virCommandRunAsync(cmd, NULL) < 0) {
goto cleanup;
@@ -1623,8 +1617,8 @@ virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
}
if (feof (fp) < 0) {
- virReportSystemError(errno,
- _("read error on pipe to '%s'"), prog[0]);
+ virReportSystemError(errno, "%s",
+ _("read error on pipe"));
goto cleanup;
}
@@ -1633,7 +1627,6 @@ virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
for (i = 0; i < n_columns; i++)
VIR_FREE(v[i]);
VIR_FREE(v);
- virCommandFree(cmd);
VIR_FORCE_FCLOSE(fp);
VIR_FORCE_CLOSE(fd);
diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h
index a37bf7c..4c371fb 100644
--- a/src/storage/storage_backend.h
+++ b/src/storage/storage_backend.h
@@ -27,6 +27,7 @@
# include <stdint.h>
# include "internal.h"
# include "storage_conf.h"
+# include "command.h"
typedef char * (*virStorageBackendFindPoolSources)(virConnectPtr conn, const char *srcSpec, unsigned int flags);
typedef int (*virStorageBackendCheckPool)(virConnectPtr conn, virStoragePoolObjPtr pool, bool *active);
@@ -141,7 +142,7 @@ typedef int (*virStorageBackendListVolNulFunc)(virStoragePoolObjPtr pool,
void *data);
int virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
- const char *const*prog,
+ virCommandPtr cmd,
int nregex,
const char **regex,
int *nvars,
@@ -149,7 +150,7 @@ int virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
void *data, const char *cmd_to_ignore);
int virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
- const char **prog,
+ virCommandPtr cmd,
size_t n_columns,
virStorageBackendListVolNulFunc func,
void *data);
diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index 995ad2f..ecc51fd 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -269,17 +269,20 @@ virStorageBackendDiskReadPartitions(virStoragePoolObjPtr pool,
* - normal metadata 100027630080 100030242304 2612736
*
*/
- const char *prog[] = {
- PARTHELPER, pool->def->source.devices[0].path, NULL,
- };
+ virCommandPtr cmd = virCommandNewArgList(PARTHELPER,
+ pool->def->source.devices[0].path,
+ NULL);
+ int ret;
pool->def->allocation = pool->def->capacity = pool->def->available = 0;
- return virStorageBackendRunProgNul(pool,
- prog,
- 6,
- virStorageBackendDiskMakeVol,
- vol);
+ ret = virStorageBackendRunProgNul(pool,
+ cmd,
+ 6,
+ virStorageBackendDiskMakeVol,
+ vol);
+ virCommandFree(cmd);
+ return ret;
}
static int
@@ -299,15 +302,19 @@ virStorageBackendDiskMakePoolGeometry(virStoragePoolObjPtr pool,
static int
virStorageBackendDiskReadGeometry(virStoragePoolObjPtr pool)
{
- const char *prog[] = {
- PARTHELPER, pool->def->source.devices[0].path, "-g", NULL,
- };
-
- return virStorageBackendRunProgNul(pool,
- prog,
- 3,
- virStorageBackendDiskMakePoolGeometry,
- NULL);
+ virCommandPtr cmd = virCommandNewArgList(PARTHELPER,
+ pool->def->source.devices[0].path,
+ "-g",
+ NULL);
+ int ret;
+
+ ret = virStorageBackendRunProgNul(pool,
+ cmd,
+ 3,
+ virStorageBackendDiskMakePoolGeometry,
+ NULL);
+ virCommandFree(cmd);
+ return ret;
}
static int
@@ -379,15 +386,13 @@ virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
bool ok_to_mklabel = false;
int ret = -1;
/* eg parted /dev/sda mklabel msdos */
- const char *prog[] = {
- PARTED,
- pool->def->source.devices[0].path,
- "mklabel",
- "--script",
- ((pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) ? "msdos" :
- virStoragePoolFormatDiskTypeToString(pool->def->source.format)),
- NULL,
- };
+ virCommandPtr cmd = virCommandNewArgList(PARTED,
+ pool->def->source.devices[0].path,
+ "mklabel",
+ "--script",
+ ((pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) ? "msdos" :
+ virStoragePoolFormatDiskTypeToString(pool->def->source.format)),
+ NULL);
virCheckFlags(VIR_STORAGE_POOL_BUILD_OVERWRITE |
VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, ret);
@@ -419,9 +424,10 @@ virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
}
if (ok_to_mklabel)
- ret = virRun(prog, NULL);
+ ret = virCommandRun(cmd, NULL);
error:
+ virCommandFree(cmd);
return ret;
}
@@ -628,20 +634,13 @@ virStorageBackendDiskCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
virStorageVolDefPtr vol)
{
int res = -1;
- char *start = NULL;
- char *end = NULL;
char *partFormat;
unsigned long long startOffset = 0, endOffset = 0;
- const char *cmdargv[] = {
- PARTED,
- pool->def->source.devices[0].path,
- "mkpart",
- "--script",
- NULL /*partFormat*/,
- NULL /*start*/,
- NULL /*end*/,
- NULL
- };
+ virCommandPtr cmd = virCommandNewArgList(PARTED,
+ pool->def->source.devices[0].path,
+ "mkpart",
+ "--script",
+ NULL);
if (vol->target.encryption != NULL) {
virStorageReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -653,7 +652,7 @@ virStorageBackendDiskCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
if (virStorageBackendDiskPartFormat(pool, vol, &partFormat) != 0) {
return -1;
}
- cmdargv[4] = partFormat;
+ virCommandAddArg(cmd, partFormat);
if (virStorageBackendDiskPartBoundries(pool, &startOffset,
&endOffset,
@@ -661,15 +660,10 @@ virStorageBackendDiskCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virAsprintf(&start, "%lluB", startOffset) < 0 ||
- virAsprintf(&end, "%lluB", endOffset) < 0) {
- virReportOOMError();
- goto cleanup;
- }
- cmdargv[5] = start;
- cmdargv[6] = end;
+ virCommandAddArgFormat(cmd, "%lluB", startOffset);
+ virCommandAddArgFormat(cmd, "%lluB", endOffset);
- if (virRun(cmdargv, NULL) < 0)
+ if (virCommandRun(cmd, NULL) < 0)
goto cleanup;
/* wait for device node to show up */
@@ -690,8 +684,7 @@ virStorageBackendDiskCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
cleanup:
VIR_FREE(partFormat);
- VIR_FREE(start);
- VIR_FREE(end);
+ virCommandFree(cmd);
return res;
}
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 4894994..b6ca858 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -251,10 +251,10 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE
.sources = NULL
}
};
- const char *prog[] = { SHOWMOUNT, "--no-headers", "--exports", NULL, NULL };
virStoragePoolSourcePtr source = NULL;
char *retval = NULL;
unsigned int i;
+ virCommandPtr cmd = NULL;
virCheckFlags(0, NULL);
@@ -270,9 +270,14 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE
}
state.host = source->hosts[0].name;
- prog[3] = source->hosts[0].name;
- if (virStorageBackendRunProgRegex(NULL, prog, 1, regexes, vars,
+ cmd = virCommandNewArgList(SHOWMOUNT,
+ "--no-headers",
+ "--exports",
+ source->hosts[0].name,
+ NULL);
+
+ if (virStorageBackendRunProgRegex(NULL, cmd, 1, regexes, vars,
virStorageBackendFileSystemNetFindPoolSourcesFunc,
&state, NULL) < 0)
goto cleanup;
@@ -289,7 +294,7 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE
VIR_FREE(state.list.sources);
virStoragePoolSourceFree(source);
-
+ virCommandFree(cmd);
return retval;
}
@@ -337,63 +342,16 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool) {
*/
static int
virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) {
- char *src;
- const char **mntargv;
-
+ char *src = NULL;
/* 'mount -t auto' doesn't seem to auto determine nfs (or cifs),
* while plain 'mount' does. We have to craft separate argvs to
* accommodate this */
- int netauto = (pool->def->type == VIR_STORAGE_POOL_NETFS &&
- pool->def->source.format == VIR_STORAGE_POOL_NETFS_AUTO);
- int glusterfs = (pool->def->type == VIR_STORAGE_POOL_NETFS &&
- pool->def->source.format == VIR_STORAGE_POOL_NETFS_GLUSTERFS);
-
- int source_index;
-
- const char *netfs_auto_argv[] = {
- MOUNT,
- NULL, /* source path */
- pool->def->target.path,
- NULL,
- };
-
- const char *fs_argv[] = {
- MOUNT,
- "-t",
- pool->def->type == VIR_STORAGE_POOL_FS ?
- virStoragePoolFormatFileSystemTypeToString(pool->def->source.format) :
- virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format),
- NULL, /* Fill in shortly - careful not to add extra fields
- before this */
- pool->def->target.path,
- NULL,
- };
-
- const char *glusterfs_argv[] = {
- MOUNT,
- "-t",
- pool->def->type == VIR_STORAGE_POOL_FS ?
- virStoragePoolFormatFileSystemTypeToString(pool->def->source.format) :
- virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format),
- NULL,
- "-o",
- "direct-io-mode=1",
- pool->def->target.path,
- NULL,
- };
-
- if (netauto) {
- mntargv = netfs_auto_argv;
- source_index = 1;
- } else if (glusterfs) {
- mntargv = glusterfs_argv;
- source_index = 3;
- } else {
- mntargv = fs_argv;
- source_index = 3;
- }
-
- int ret;
+ bool netauto = (pool->def->type == VIR_STORAGE_POOL_NETFS &&
+ pool->def->source.format == VIR_STORAGE_POOL_NETFS_AUTO);
+ bool glusterfs = (pool->def->type == VIR_STORAGE_POOL_NETFS &&
+ pool->def->source.format == VIR_STORAGE_POOL_NETFS_GLUSTERFS);
+ virCommandPtr cmd = NULL;
+ int ret = -1;
if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
if (pool->def->source.nhost != 1) {
@@ -441,14 +399,41 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) {
return -1;
}
}
- mntargv[source_index] = src;
- if (virRun(mntargv, NULL) < 0) {
- VIR_FREE(src);
- return -1;
- }
+ if (netauto)
+ cmd = virCommandNewArgList(MOUNT,
+ src,
+ pool->def->target.path,
+ NULL);
+ else if (glusterfs)
+ cmd = virCommandNewArgList( MOUNT,
+ "-t",
+ (pool->def->type == VIR_STORAGE_POOL_FS ?
+ virStoragePoolFormatFileSystemTypeToString(pool->def->source.format) :
+ virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format)),
+ src,
+ "-o",
+ "direct-io-mode=1",
+ pool->def->target.path,
+ NULL);
+ else
+ cmd = virCommandNewArgList(MOUNT,
+ "-t",
+ (pool->def->type == VIR_STORAGE_POOL_FS ?
+ virStoragePoolFormatFileSystemTypeToString(pool->def->source.format) :
+ virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format)),
+ src,
+ pool->def->target.path,
+ NULL);
+
+ if (virCommandRun(cmd, NULL) < 0)
+ goto cleanup;
+
+ ret = 0;
+cleanup:
+ virCommandFree(cmd);
VIR_FREE(src);
- return 0;
+ return ret;
}
/**
@@ -462,8 +447,8 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) {
*/
static int
virStorageBackendFileSystemUnmount(virStoragePoolObjPtr pool) {
- const char *mntargv[3];
- int ret;
+ virCommandPtr cmd = NULL;
+ int ret = -1;
if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
if (pool->def->source.nhost != 1) {
@@ -497,14 +482,17 @@ virStorageBackendFileSystemUnmount(virStoragePoolObjPtr pool) {
return 0;
}
- mntargv[0] = UMOUNT;
- mntargv[1] = pool->def->target.path;
- mntargv[2] = NULL;
+ cmd = virCommandNewArgList(UMOUNT,
+ pool->def->target.path,
+ NULL);
- if (virRun(mntargv, NULL) < 0) {
- return -1;
- }
- return 0;
+ if (virCommandRun(cmd, NULL) < 0)
+ goto cleanup;
+
+ ret = 0;
+cleanup:
+ virCommandFree(cmd);
+ return ret;
}
#endif /* WITH_STORAGE_FS */
diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
index e286c84..88de9fd 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -151,31 +151,32 @@ virStorageBackendISCSISession(virStoragePoolObjPtr pool,
int vars[] = {
2,
};
- const char *const prog[] = {
- ISCSIADM, "--mode", "session", NULL
- };
char *session = NULL;
+ virCommandPtr cmd = virCommandNewArgList(ISCSIADM, "--mode", "session", NULL);
+
/* Note that we ignore the exitstatus. Older versions of iscsiadm tools
* returned an exit status of > 0, even if they succeeded. We will just
* rely on whether session got filled in properly.
*/
if (virStorageBackendRunProgRegex(pool,
- prog,
+ cmd,
1,
regexes,
vars,
virStorageBackendISCSIExtractSession,
&session, NULL) < 0)
- return NULL;
+ goto cleanup;
if (session == NULL &&
!probe) {
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot find session"));
- return NULL;
+ goto cleanup;
}
+cleanup:
+ virCommandFree(cmd);
return session;
}
@@ -279,42 +280,52 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriqn,
char **ifacename)
{
int ret = -1, exitstatus = -1;
- char temp_ifacename[32];
- const char *const cmdargv1[] = {
- ISCSIADM, "--mode", "iface", "--interface",
- temp_ifacename, "--op", "new", NULL
- };
- const char *const cmdargv2[] = {
- ISCSIADM, "--mode", "iface", "--interface", temp_ifacename,
- "--op", "update", "--name", "iface.initiatorname", "--value",
- initiatoriqn, NULL
- };
+ char *temp_ifacename;
+ virCommandPtr cmd = NULL;
- snprintf(temp_ifacename, sizeof(temp_ifacename), "libvirt-iface-%08llx",
- (unsigned long long)virRandomBits(30));
+ if (virAsprintf(&temp_ifacename,
+ "libvirt-iface-%08llx",
+ (unsigned long long)virRandomBits(30)) < 0) {
+ virReportOOMError();
+ return -1;
+ }
VIR_DEBUG("Attempting to create interface '%s' with IQN '%s'",
- &temp_ifacename[0], initiatoriqn);
+ temp_ifacename, initiatoriqn);
+ cmd = virCommandNewArgList(ISCSIADM,
+ "--mode", "iface",
+ "--interface", temp_ifacename,
+ "--op", "new",
+ NULL);
/* Note that we ignore the exitstatus. Older versions of iscsiadm
* tools returned an exit status of > 0, even if they succeeded.
* We will just rely on whether the interface got created
* properly. */
- if (virRun(cmdargv1, &exitstatus) < 0) {
+ if (virCommandRun(cmd, &exitstatus) < 0) {
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to run command '%s' to create new iscsi interface"),
- cmdargv1[0]);
- goto out;
+ ISCSIADM);
+ goto cleanup;
}
+ virCommandFree(cmd);
+ cmd = virCommandNewArgList(ISCSIADM,
+ "--mode", "iface",
+ "--interface", temp_ifacename,
+ "--op", "update",
+ "--name", "iface.initiatorname",
+ "--value",
+ initiatoriqn,
+ NULL);
/* Note that we ignore the exitstatus. Older versions of iscsiadm tools
* returned an exit status of > 0, even if they succeeded. We will just
* rely on whether iface file got updated properly. */
- if (virRun(cmdargv2, &exitstatus) < 0) {
+ if (virCommandRun(cmd, &exitstatus) < 0) {
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to run command '%s' to update iscsi interface with IQN '%s'"),
- cmdargv2[0], initiatoriqn);
- goto out;
+ ISCSIADM, initiatoriqn);
+ goto cleanup;
}
/* Check again to make sure the interface was created. */
@@ -322,7 +333,7 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriqn,
VIR_DEBUG("Failed to find interface '%s' with IQN '%s' "
"after attempting to create it",
&temp_ifacename[0], initiatoriqn);
- goto out;
+ goto cleanup;
} else {
VIR_DEBUG("Interface '%s' with IQN '%s' was created successfully",
*ifacename, initiatoriqn);
@@ -330,7 +341,9 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriqn,
ret = 0;
-out:
+cleanup:
+ virCommandFree(cmd);
+ VIR_FREE(temp_ifacename);
if (ret != 0)
VIR_FREE(*ifacename);
return ret;
@@ -426,14 +439,14 @@ static int
virStorageBackendISCSIRescanLUNs(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
const char *session)
{
- const char *const cmdargv[] = {
- ISCSIADM, "--mode", "session", "-r", session, "-R", NULL,
- };
-
- if (virRun(cmdargv, NULL) < 0)
- return -1;
-
- return 0;
+ virCommandPtr cmd = virCommandNewArgList(ISCSIADM,
+ "--mode", "session",
+ "-r", session,
+ "-R",
+ NULL);
+ int ret = virCommandRun(cmd, NULL);
+ virCommandFree(cmd);
+ return ret;
}
struct virStorageBackendISCSITargetList {
@@ -501,24 +514,25 @@ virStorageBackendISCSIScanTargets(const char *portal,
"^\\s*(\\S+)\\s+(\\S+)\\s*$"
};
int vars[] = { 2 };
- const char *const cmdsendtarget[] = {
- ISCSIADM, "--mode", "discovery", "--type", "sendtargets",
- "--portal", portal, NULL
- };
struct virStorageBackendISCSITargetList list;
- int i;
+ size_t i;
+ int ret = -1;
+ virCommandPtr cmd = virCommandNewArgList(ISCSIADM,
+ "--mode", "discovery",
+ "--type", "sendtargets",
+ "--portal", portal,
+ NULL);
memset(&list, 0, sizeof(list));
if (virStorageBackendRunProgRegex(NULL, /* No pool for callback */
- cmdsendtarget,
+ cmd,
1,
regexes,
vars,
virStorageBackendISCSIGetTargets,
- &list, NULL) < 0) {
- return -1;
- }
+ &list, NULL) < 0)
+ goto cleanup;
for (i = 0 ; i < list.ntargets ; i++) {
/* We have to ignore failure, because we can't undo
@@ -542,7 +556,10 @@ virStorageBackendISCSIScanTargets(const char *portal,
VIR_FREE(list.targets);
}
- return 0;
+ ret = 0;
+cleanup:
+ virCommandFree(cmd);
+ return ret;
}
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index 9a91dd9..9fe769b 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -48,17 +48,16 @@ static int
virStorageBackendLogicalSetActive(virStoragePoolObjPtr pool,
int on)
{
- const char *cmdargv[4];
-
- cmdargv[0] = VGCHANGE;
- cmdargv[1] = on ? "-aly" : "-aln";
- cmdargv[2] = pool->def->source.name;
- cmdargv[3] = NULL;
-
- if (virRun(cmdargv, NULL) < 0)
- return -1;
-
- return 0;
+ int ret;
+ virCommandPtr cmd =
+ virCommandNewArgList(VGCHANGE,
+ on ? "-aly" : "-aln",
+ pool->def->source.name,
+ NULL);
+
+ ret = virCommandRun(cmd, NULL);
+ virCommandFree(cmd);
+ return ret;
}
@@ -296,24 +295,31 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
int vars[] = {
8
};
- const char *prog[] = {
- LVS, "--separator", "#", "--noheadings", "--units", "b",
- "--unbuffered", "--nosuffix", "--options",
- "lv_name,origin,uuid,devices,segtype,stripes,seg_size,vg_extent_size",
- pool->def->source.name, NULL
- };
-
+ int ret = -1;
+ virCommandPtr cmd;
+
+ cmd = virCommandNewArgList(LVS,
+ "--separator", "#",
+ "--noheadings",
+ "--units", "b",
+ "--unbuffered",
+ "--nosuffix",
+ "--options", "lv_name,origin,uuid,devices,segtype,stripes,seg_size,vg_extent_size",
+ pool->def->source.name,
+ NULL);
if (virStorageBackendRunProgRegex(pool,
- prog,
+ cmd,
1,
regexes,
vars,
virStorageBackendLogicalMakeVol,
- vol, "lvs") < 0) {
- return -1;
- }
+ vol, "lvs") < 0)
+ goto cleanup;
- return 0;
+ ret = 0;
+cleanup:
+ virCommandFree(cmd);
+ return ret;
}
static int
@@ -405,8 +411,7 @@ virStorageBackendLogicalFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
int vars[] = {
2
};
- const char *const prog[] = { PVS, "--noheadings", "-o", "pv_name,vg_name", NULL };
- const char *const scanprog[] = { VGSCAN, NULL };
+ virCommandPtr cmd;
char *retval = NULL;
virStoragePoolSourceList sourceList;
int i;
@@ -418,17 +423,25 @@ virStorageBackendLogicalFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
* that might be hanging around, so if this fails for some reason, the
* worst that happens is that scanning doesn't pick everything up
*/
- if (virRun(scanprog, NULL) < 0) {
+ cmd = virCommandNew(VGSCAN);
+ if (virCommandRun(cmd, NULL) < 0)
VIR_WARN("Failure when running vgscan to refresh physical volumes");
- }
+ virCommandFree(cmd);
memset(&sourceList, 0, sizeof(sourceList));
sourceList.type = VIR_STORAGE_POOL_LOGICAL;
- if (virStorageBackendRunProgRegex(NULL, prog, 1, regexes, vars,
- virStorageBackendLogicalFindPoolSourcesFunc,
- &sourceList, "pvs") < 0)
+ cmd = virCommandNewArgList(PVS,
+ "--noheadings",
+ "-o", "pv_name,vg_name",
+ NULL);
+ if (virStorageBackendRunProgRegex(NULL, cmd, 1, regexes, vars,
+ virStorageBackendLogicalFindPoolSourcesFunc,
+ &sourceList, "pvs") < 0) {
+ virCommandFree(cmd);
return NULL;
+ }
+ virCommandFree(cmd);
retval = virStoragePoolSourceListFormat(&sourceList);
if (retval == NULL) {
@@ -483,26 +496,20 @@ virStorageBackendLogicalBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool,
unsigned int flags)
{
- const char **vgargv;
- const char *pvargv[3];
- int n = 0, i, fd;
+ virCommandPtr vgcmd;
+ int fd;
char zeros[PV_BLANK_SECTOR_SIZE];
+ int ret = -1;
+ size_t i;
virCheckFlags(0, -1);
memset(zeros, 0, sizeof(zeros));
- if (VIR_ALLOC_N(vgargv, 3 + pool->def->source.ndevice) < 0) {
- virReportOOMError();
- return -1;
- }
+ vgcmd = virCommandNewArgList(VGCREATE, pool->def->source.name, NULL);
- vgargv[n++] = VGCREATE;
- vgargv[n++] = pool->def->source.name;
-
- pvargv[0] = PVCREATE;
- pvargv[2] = NULL;
for (i = 0 ; i < pool->def->source.ndevice ; i++) {
+ virCommandPtr pvcmd;
/*
* LVM requires that the first sector is blanked if using
* a whole disk as a PV. So we just blank them out regardless
@@ -539,25 +546,27 @@ virStorageBackendLogicalBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
* Initialize the physical volume because vgcreate is not
* clever enough todo this for us :-(
*/
- vgargv[n++] = pool->def->source.devices[i].path;
- pvargv[1] = pool->def->source.devices[i].path;
- if (virRun(pvargv, NULL) < 0)
+ pvcmd = virCommandNewArgList(PVCREATE,
+ pool->def->source.devices[i].path,
+ NULL);
+ if (virCommandRun(pvcmd, NULL) < 0) {
+ virCommandFree(pvcmd);
goto cleanup;
- }
+ }
+ virCommandFree(pvcmd);
- vgargv[n] = NULL;
+ virCommandAddArg(vgcmd, pool->def->source.devices[i].path);
+ }
/* Now create the volume group itself */
- if (virRun(vgargv, NULL) < 0)
+ if (virCommandRun(vgcmd, NULL) < 0)
goto cleanup;
- VIR_FREE(vgargv);
-
- return 0;
+ ret = 0;
- cleanup:
- VIR_FREE(vgargv);
- return -1;
+cleanup:
+ virCommandFree(vgcmd);
+ return ret;
}
@@ -579,33 +588,42 @@ virStorageBackendLogicalRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
int vars[] = {
2
};
- const char *prog[] = {
- VGS, "--separator", ":", "--noheadings", "--units", "b", "--unbuffered",
- "--nosuffix", "--options", "vg_size,vg_free",
- pool->def->source.name, NULL
- };
+ virCommandPtr cmd = NULL;
+ int ret = -1;
virFileWaitForDevices();
/* Get list of all logical volumes */
- if (virStorageBackendLogicalFindLVs(pool, NULL) < 0) {
- virStoragePoolObjClearVols(pool);
- return -1;
- }
+ if (virStorageBackendLogicalFindLVs(pool, NULL) < 0)
+ goto cleanup;
+
+ cmd = virCommandNewArgList(VGS,
+ "--separator", ":",
+ "--noheadings",
+ "--units", "b",
+ "--unbuffered",
+ "--nosuffix",
+ "--options", "vg_size,vg_free",
+ pool->def->source.name,
+ NULL);
/* Now get basic volgrp metadata */
if (virStorageBackendRunProgRegex(pool,
- prog,
+ cmd,
1,
regexes,
vars,
virStorageBackendLogicalRefreshPoolFunc,
- NULL, "vgs") < 0) {
- virStoragePoolObjClearVols(pool);
- return -1;
- }
+ NULL, "vgs") < 0)
+ goto cleanup;
- return 0;
+ ret = 0;
+
+cleanup:
+ virCommandFree(cmd);
+ if (ret < 0)
+ virStoragePoolObjClearVols(pool);
+ return ret;
}
/*
@@ -628,31 +646,37 @@ virStorageBackendLogicalDeletePool(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool,
unsigned int flags)
{
- const char *cmdargv[] = {
- VGREMOVE, "-f", pool->def->source.name, NULL
- };
- const char *pvargv[3];
- int i, error;
+ virCommandPtr cmd = NULL;
+ size_t i;
+ int ret = -1;
virCheckFlags(0, -1);
/* first remove the volume group */
- if (virRun(cmdargv, NULL) < 0)
- return -1;
+ cmd = virCommandNewArgList(VGREMOVE,
+ "-f", pool->def->source.name,
+ NULL);
+ if (virCommandRun(cmd, NULL) < 0)
+ goto cleanup;
+ virCommandFree(cmd);
/* now remove the pv devices and clear them out */
- error = 0;
- pvargv[0] = PVREMOVE;
- pvargv[2] = NULL;
+ ret = 0;
for (i = 0 ; i < pool->def->source.ndevice ; i++) {
- pvargv[1] = pool->def->source.devices[i].path;
- if (virRun(pvargv, NULL) < 0) {
- error = -1;
+ cmd = virCommandNewArgList(PVREMOVE,
+ pool->def->source.devices[i].path,
+ NULL);
+ if (virCommandRun(cmd, NULL) < 0) {
+ ret = -1;
break;
}
+ virCommandFree(cmd);
+ cmd = NULL;
}
- return error;
+cleanup:
+ virCommandFree(cmd);
+ return ret;
}
@@ -669,16 +693,7 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
virStorageVolDefPtr vol)
{
int fdret, fd = -1;
- char size[100];
- const char *cmdargvnew[] = {
- LVCREATE, "--name", vol->name, "-L", size,
- pool->def->source.name, NULL
- };
- const char *cmdargvsnap[] = {
- LVCREATE, "--name", vol->name, "-L", size,
- "-s", vol->backingStore.path, NULL
- };
- const char **cmdargv = cmdargvnew;
+ virCommandPtr cmd = NULL;
if (vol->target.encryption != NULL) {
virStorageReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -687,15 +702,6 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
return -1;
}
- if (vol->backingStore.path) {
- cmdargv = cmdargvsnap;
- }
-
- snprintf(size, sizeof(size)-1, "%lluK", VIR_DIV_UP(vol->capacity, 1024));
- size[sizeof(size)-1] = '\0';
-
- vol->type = VIR_STORAGE_VOL_BLOCK;
-
if (vol->target.path != NULL) {
/* A target path passed to CreateVol has no meaning */
VIR_FREE(vol->target.path);
@@ -708,8 +714,18 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
return -1;
}
- if (virRun(cmdargv, NULL) < 0)
- return -1;
+ cmd = virCommandNewArgList(LVCREATE,
+ "--name", vol->name,
+ NULL);
+ virCommandAddArg(cmd, "-L");
+ virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->capacity, 1024));
+ if (vol->backingStore.path)
+ virCommandAddArgPair(cmd, "-s", vol->backingStore.path);
+ else
+ virCommandAddArg(cmd, pool->def->source.name);
+
+ if (virCommandRun(cmd, NULL) < 0)
+ goto cleanup;
if ((fdret = virStorageBackendVolOpen(vol->target.path)) < 0)
goto cleanup;
@@ -752,6 +768,7 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
cleanup:
VIR_FORCE_CLOSE(fd);
virStorageBackendLogicalDeleteVol(conn, pool, vol, 0);
+ virCommandFree(cmd);
return -1;
}
--
1.7.7.6
12 years, 5 months
[libvirt] [glib PATCH] Add gvir_connection_domain_restore() and gvir_connection_domain_restore_async()
by Jovanka Gulicoska
---
libvirt-gobject/libvirt-gobject-connection.c | 136 ++++++++++++++++++++++++++
libvirt-gobject/libvirt-gobject-connection.h | 19 ++++
libvirt-gobject/libvirt-gobject.sym | 3 +
3 files changed, 158 insertions(+)
diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
index 3a99034..2302328 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -57,6 +57,7 @@ enum {
VIR_CONNECTION_CLOSED,
VIR_DOMAIN_ADDED,
VIR_DOMAIN_REMOVED,
+ VIR_DOMAIN_RESTORED,
LAST_SIGNAL
};
@@ -228,6 +229,15 @@ static void gvir_connection_class_init(GVirConnectionClass *klass)
1,
GVIR_TYPE_DOMAIN);
+ signals[VIR_DOMAIN_RESTORED] = g_signal_new("domain-restored",
+ G_OBJECT_CLASS_TYPE(object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET(GVirConnectionClass, domain_restored),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 0);
+
g_type_class_add_private(klass, sizeof(GVirConnectionPrivate));
}
@@ -1605,3 +1615,129 @@ gvir_connection_get_capabilities_finish(GVirConnection *conn,
return g_object_ref(caps);
}
+
+/*
+ * gvir_connection_domain_restore
+ */
+gboolean gvir_connection_domain_restore(GVirConnection *conn,
+ gchar *filename,
+ GVirConfigDomain *conf,
+ guint flags,
+ GError **err)
+{
+ GVirConnectionPrivate *priv;
+ gchar *custom_xml;
+ int ret;
+
+ g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
+ g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN (conf), FALSE);
+ g_return_val_if_fail((err == NULL) || (*err == NULL), FALSE);
+
+ priv = conn->priv;
+ custom_xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
+
+ g_return_val_if_fail(custom_xml != NULL, FALSE);
+
+ if(flags || custom_xml) {
+ ret = virDomainRestoreFlags(priv->conn, filename, custom_xml, flags);
+ g_free (custom_xml);
+ }
+ else {
+ ret = virDomainRestore(priv->conn, filename);
+ g_free (custom_xml);
+ }
+
+ if(ret < 0) {
+ gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
+ 0,
+ "Unable to restore domain");
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef struct {
+ gchar *filename;
+ gchar *custom_xml;
+ guint flags;
+} DomainRestoreFromFileData;
+
+static void domain_restore_from_file_data_free(DomainRestoreFromFileData *data)
+{
+ g_slice_free(DomainRestoreFromFileData, data);
+}
+
+static void
+gvir_connection_domain_restore_helper(GSimpleAsyncResult *res,
+ GObject *object,
+ GCancellable *cancellable G_GNUC_UNUSED)
+{
+ GVirConnection *conn = GVIR_CONNECTION(object);
+ DomainRestoreFromFileData *data;
+ GVirConfigDomain *conf;
+ GError *err = NULL;
+
+ data = g_simple_async_result_get_op_res_gpointer(res);
+ conf = gvir_config_domain_new_from_xml(data->custom_xml, &err);
+
+ if(!gvir_connection_domain_restore(conn, data->filename, conf, data->flags, &err))
+ g_simple_async_result_take_error(res, err);
+}
+
+/*
+ * Async function of gvir_connection_domain_restore
+ */
+void gvir_connection_domain_restore_async(GVirConnection *conn,
+ gchar *filename,
+ GVirConfigDomain *conf,
+ guint flags,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *res;
+ DomainRestoreFromFileData *data;
+ gchar *custom_xml;
+
+ g_return_if_fail(GVIR_IS_CONNECTION(conn));
+ g_return_if_fail(GVIR_CONFIG_IS_DOMAIN (conf));
+ g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
+
+ custom_xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
+
+ data = g_slice_new0(DomainRestoreFromFileData);
+ data->filename = filename;
+ data->custom_xml = custom_xml;
+ data->flags = flags;
+
+ res = g_simple_async_result_new(G_OBJECT(conn),
+ callback,
+ user_data,
+ gvir_connection_domain_restore_async);
+ g_simple_async_result_set_op_res_gpointer(res, data,
+ (GDestroyNotify)domain_restore_from_file_data_free);
+
+ g_simple_async_result_run_in_thread(res,
+ gvir_connection_domain_restore_helper,
+ G_PRIORITY_DEFAULT,
+ cancellable);
+
+ g_object_unref(res);
+}
+
+gboolean gvir_connection_domain_restore_finish(GVirConnection *conn,
+ GAsyncResult *result,
+ GError **err)
+{
+ g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
+ g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(conn),
+ gvir_connection_domain_restore_async),
+ FALSE);
+
+ if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
+ return FALSE;
+
+ return TRUE;
+}
diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h
index c80eecf..01d5d0b 100644
--- a/libvirt-gobject/libvirt-gobject-connection.h
+++ b/libvirt-gobject/libvirt-gobject-connection.h
@@ -75,6 +75,8 @@ struct _GVirConnectionClass
void (*domain_added)(GVirConnection *conn, GVirDomain *dom);
void (*domain_removed)(GVirConnection *conn, GVirDomain *dom);
+ void (*domain_restored)(GVirConnection *conn);
+
GVirStream *(*stream_new)(GVirConnection *conn, gpointer handle);
gpointer padding[20];
@@ -202,6 +204,23 @@ gvir_connection_get_capabilities_finish(GVirConnection *conn,
GAsyncResult *result,
GError **err);
+gboolean gvir_connection_domain_restore(GVirConnection *conn,
+ gchar *filename,
+ GVirConfigDomain *conf,
+ guint flags,
+ GError **err);
+
+void gvir_connection_domain_restore_async(GVirConnection *conn,
+ gchar *filename,
+ GVirConfigDomain *conf,
+ guint flags,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+gboolean gvir_connection_domain_restore_finish(GVirConnection *conn,
+ GAsyncResult *result,
+ GError **err);
G_END_DECLS
#endif /* __LIBVIRT_GOBJECT_CONNECTION_H__ */
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
index 8ff9e24..0aaefa2 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -31,6 +31,9 @@ LIBVIRT_GOBJECT_0.0.8 {
gvir_connection_create_storage_pool;
gvir_connection_start_domain;
gvir_connection_get_node_info;
+ gvir_connection_domain_restore;
+ gvir_connection_domain_restore_async;
+ gvir_connection_domain_restore_finish;
gvir_domain_device_get_type;
gvir_domain_device_get_domain;
--
1.7.10.4
12 years, 5 months
[libvirt] [glib PATCH] Add bindings for virDomainSnapshotCreateXML()
by Jovanka Gulicoska
---
libvirt-gobject/libvirt-gobject-domain.c | 39 ++++++++++++++++++++++++++++++
libvirt-gobject/libvirt-gobject-domain.h | 4 +++
2 files changed, 43 insertions(+)
diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
index eda2427..ea621ff 100644
--- a/libvirt-gobject/libvirt-gobject-domain.c
+++ b/libvirt-gobject/libvirt-gobject-domain.c
@@ -1270,3 +1270,42 @@ GList *gvir_domain_get_devices(GVirDomain *domain,
return g_list_reverse (ret);
}
+
+/**
+ * gvir_domain_snapshot_create_xml:
+ * @dom: the domain
+ * @conf: configuration of domain
+ * @flags: the flags
+ * @err: (allow-none):Place-holder for error or NULL
+ *
+ * Returns: snapshot of existing domain
+ */
+GVirConfigDomainSnapshot *gvir_domain_snapshot_create_xml(GVirDomain *dom,
+ GVirConfigDomain *conf,
+ guint flags,
+ GError **err)
+{
+ GVirDomainPrivate *priv;
+ virDomainSnapshot *snapshot;
+ gchar *xml_desc;
+
+ g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+ g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN (conf), FALSE);
+ g_return_val_if_fail(err == NULL || *err == NULL, NULL);
+
+ priv = dom->priv;
+ xml_desc = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
+
+ if(!(snapshot = virDomainSnapshotCreateXML(priv->handle, xml_desc, flags))) {
+ gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
+ 0,
+ "Unable to create snapshot of domain");
+ return NULL;
+
+ }
+
+ GVirConfigDomainSnapshot *conf_snapshot = gvir_config_domain_snapshot_new_from_xml(xml_desc, err);
+
+ g_free(xml_desc);
+ return conf_snapshot;
+}
diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h
index 49516a7..6540f64 100644
--- a/libvirt-gobject/libvirt-gobject-domain.h
+++ b/libvirt-gobject/libvirt-gobject-domain.h
@@ -220,6 +220,10 @@ gboolean gvir_domain_get_saved(GVirDomain *dom);
GList *gvir_domain_get_devices(GVirDomain *domain,
GError **err);
+GVirConfigDomainSnapshot *gvir_domain_snapshot_create_xml(GVirDomain *dom,
+ GVirConfigDomain *conf,
+ guint flags,
+ GError **err);
G_END_DECLS
#endif /* __LIBVIRT_GOBJECT_DOMAIN_H__ */
--
1.7.10.4
12 years, 5 months
[libvirt] [glib PATCH V2] Add bindings for virStorageVolDownload() and virStorageVolUpload()
by Jovanka Gulicoska
---
libvirt-gobject/libvirt-gobject-storage-vol.c | 75 +++++++++++++++++++++++++
libvirt-gobject/libvirt-gobject-storage-vol.h | 14 +++++
libvirt-gobject/libvirt-gobject.h | 1 +
libvirt-gobject/libvirt-gobject.sym | 2 +
4 files changed, 92 insertions(+)
diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c b/libvirt-gobject/libvirt-gobject-storage-vol.c
index 6f60fcd..7f9aeb7 100644
--- a/libvirt-gobject/libvirt-gobject-storage-vol.c
+++ b/libvirt-gobject/libvirt-gobject-storage-vol.c
@@ -349,3 +349,78 @@ gboolean gvir_storage_vol_resize(GVirStorageVol *vol,
return TRUE;
}
+
+/**
+ * gvir_storage_vol_download:
+ * @vol: the storage volume to download from
+ * @stream: stream to use as output
+ * @offset: position in @vol to start reading from
+ * @length: limit on amount of data to download
+ * @flags: extra flags, not used yet, pass 0
+ *
+ * Returns: #TRUE of success, #FALSE otherwise
+ */
+gboolean gvir_storage_vol_download(GVirStorageVol *vol,
+ GVirStream *stream,
+ unsigned long long offset,
+ unsigned long long length,
+ guint flags,
+ GError **err)
+{
+ virStreamPtr st = NULL;
+
+ g_object_get(stream, "handle", &st, NULL);
+
+ g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE);
+ g_return_val_if_fail(GVIR_IS_STREAM(stream), FALSE);
+ g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+ if(virStorageVolDownload(vol->priv->handle, st, offset, length, 0) < 0) {
+ gvir_set_error_literal(err,
+ GVIR_STORAGE_VOL_ERROR,
+ 0,
+ "Unable to downlaod volume storage");
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
+ * gvir_storage_vol_upload:
+ * @vol: the storage volume to upload
+ * @stream: stream to use as input
+ * @offset: position in @vol to start to write to
+ * @length: limit on amount of data to upload
+ * @flags: the flags, not set yet, pass 0
+ *
+ * Returns: #TRUE of success, #FALSE otherwise
+ */
+gboolean gvir_storage_vol_upload(GVirStorageVol *vol,
+ GVirStream *stream,
+ unsigned long long offset,
+ unsigned long long length,
+ guint flags,
+ GError **err)
+{
+ virStreamPtr st = NULL;
+
+ g_object_get(stream, "handle", &st, NULL);
+
+ g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE);
+ g_return_val_if_fail(GVIR_IS_STREAM(stream), FALSE);
+ g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+ if(virStorageVolUpload(vol->priv->handle, st, offset, length, 0) < 0) {
+ gvir_set_error_literal(err,
+ GVIR_STORAGE_VOL_ERROR,
+ 0,
+ "Unable to upload to stream");
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.h b/libvirt-gobject/libvirt-gobject-storage-vol.h
index b425f0a..e156792 100644
--- a/libvirt-gobject/libvirt-gobject-storage-vol.h
+++ b/libvirt-gobject/libvirt-gobject-storage-vol.h
@@ -110,6 +110,20 @@ gboolean gvir_storage_vol_resize(GVirStorageVol *vol,
guint flags,
GError **err);
+gboolean gvir_storage_vol_download(GVirStorageVol *vol,
+ GVirStream *stream,
+ unsigned long long offset,
+ unsigned long long length,
+ guint flags,
+ GError **err);
+
+gboolean gvir_storage_vol_upload(GVirStorageVol *vol,
+ GVirStream *stream,
+ unsigned long long offset,
+ unsigned long long length,
+ guint flags,
+ GError **err);
+
G_END_DECLS
#endif /* __LIBVIRT_GOBJECT_STORAGE_VOL_H__ */
diff --git a/libvirt-gobject/libvirt-gobject.h b/libvirt-gobject/libvirt-gobject.h
index f52cc00..b1158f7 100644
--- a/libvirt-gobject/libvirt-gobject.h
+++ b/libvirt-gobject/libvirt-gobject.h
@@ -44,5 +44,6 @@
#include <libvirt-gobject/libvirt-gobject-storage-pool.h>
#include <libvirt-gobject/libvirt-gobject-connection.h>
#include <libvirt-gobject/libvirt-gobject-manager.h>
+#include <libvirt-gobject/libvirt-gobject-stream.h>
#endif /* __LIBVIRT_GOBJECT_H__ */
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
index db32c7f..478881b 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -143,6 +143,8 @@ LIBVIRT_GOBJECT_0.0.8 {
gvir_storage_vol_get_info;
gvir_storage_vol_delete;
gvir_storage_vol_resize;
+ gvir_storage_vol_download;
+ gvir_storage_vol_upload;
gvir_connection_handle_get_type;
--
1.7.10.4
12 years, 5 months
[libvirt] [glib PATCH V2] Add bindings for virDomainRestore*()
by Jovanka Gulicoska
---
libvirt-gobject/libvirt-gobject-connection.c | 153 ++++++++++++++++++++++++++
libvirt-gobject/libvirt-gobject-connection.h | 19 ++++
libvirt-gobject/libvirt-gobject.sym | 3 +
3 files changed, 175 insertions(+)
diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
index 3a99034..6fbf86b 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -1605,3 +1605,156 @@ gvir_connection_get_capabilities_finish(GVirConnection *conn,
return g_object_ref(caps);
}
+
+/**
+ * gvir_connection_domain_restore:
+ * @conn: a #GVirConnection
+ * @filename: path to input file
+ * @conf: configuration for domain
+ * @flags: the flags
+ *
+ * Returns: TRUE on success, FALSe otherwise
+ */
+gboolean gvir_connection_domain_restore(GVirConnection *conn,
+ gchar *filename,
+ GVirConfigDomain *conf,
+ guint flags,
+ GError **err)
+{
+ GVirConnectionPrivate *priv;
+ gchar *custom_xml;
+ int ret;
+
+ g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
+ g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN (conf), FALSE);
+ g_return_val_if_fail((err == NULL) || (*err == NULL), FALSE);
+
+ priv = conn->priv;
+ custom_xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
+
+ g_return_val_if_fail(custom_xml != NULL, FALSE);
+
+ if(flags || (custom_xml != NULL)) {
+ ret = virDomainRestoreFlags(priv->conn, filename, custom_xml, flags);
+ g_free (custom_xml);
+ }
+ else {
+ ret = virDomainRestore(priv->conn, filename);
+ g_free (custom_xml);
+ }
+
+ if(ret < 0) {
+ gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
+ 0,
+ "Unable to restore domain");
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef struct {
+ gchar *filename;
+ gchar *custom_xml;
+ guint flags;
+} DomainRestoreFromFileData;
+
+static void domain_restore_from_file_data_free(DomainRestoreFromFileData *data)
+{
+ g_free(data->filename);
+ g_free(data->custom_xml);
+ g_slice_free(DomainRestoreFromFileData, data);
+}
+
+static void
+gvir_connection_domain_restore_helper(GSimpleAsyncResult *res,
+ GObject *object,
+ GCancellable *cancellable G_GNUC_UNUSED)
+{
+ GVirConnection *conn = GVIR_CONNECTION(object);
+ DomainRestoreFromFileData *data;
+ GVirConfigDomain *conf;
+ GError *err = NULL;
+
+ data = g_simple_async_result_get_op_res_gpointer(res);
+ conf = gvir_config_domain_new_from_xml(data->custom_xml, &err);
+
+ if(!gvir_connection_domain_restore(conn, data->filename, conf, data->flags, &err))
+ g_simple_async_result_take_error(res, err);
+}
+
+/**
+ * gvir_connection_domain_restore_async:
+ * @conn: a #GVirConnection
+ * @filename: path to input file
+ * @conf: configuration for domain
+ * @flags: the flags
+ * @cancellable: cancallation object
+ * @callback: (scope async): completion callback
+ * @user_data: (closure): opaque data for callback
+ *
+ * Asynchronous variant of #gvir_connection_domain_restore
+ */
+void gvir_connection_domain_restore_async(GVirConnection *conn,
+ gchar *filename,
+ GVirConfigDomain *conf,
+ guint flags,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *res;
+ DomainRestoreFromFileData *data;
+ gchar *custom_xml;
+
+ g_return_if_fail(GVIR_IS_CONNECTION(conn));
+ g_return_if_fail(GVIR_CONFIG_IS_DOMAIN (conf));
+ g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
+
+ custom_xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
+
+ data = g_slice_new0(DomainRestoreFromFileData);
+ data->filename = g_strdup(filename);
+ data->custom_xml = g_strdup(custom_xml);
+ data->flags = flags;
+
+ res = g_simple_async_result_new(G_OBJECT(conn),
+ callback,
+ user_data,
+ gvir_connection_domain_restore_async);
+ g_simple_async_result_set_op_res_gpointer(res, data,
+ (GDestroyNotify)domain_restore_from_file_data_free);
+
+ g_simple_async_result_run_in_thread(res,
+ gvir_connection_domain_restore_helper,
+ G_PRIORITY_DEFAULT,
+ cancellable);
+
+ g_object_unref(res);
+}
+
+/**
+ * gvir_connection_domain_finish:
+ * @conn: a #GVirConnection
+ * @result: (transfer none): async method result
+ * @err: Place-holder for possible errors
+ *
+ * Finishes the operation started by #gvir_domain_restore_async.
+ *
+ * Returns: TRUE if domain was restored successfully, FALSE otherwise.
+ */
+gboolean gvir_connection_domain_restore_finish(GVirConnection *conn,
+ GAsyncResult *result,
+ GError **err)
+{
+ g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
+ g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(conn),
+ gvir_connection_domain_restore_async),
+ FALSE);
+
+ if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
+ return FALSE;
+
+ return TRUE;
+}
diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h
index c80eecf..01d5d0b 100644
--- a/libvirt-gobject/libvirt-gobject-connection.h
+++ b/libvirt-gobject/libvirt-gobject-connection.h
@@ -75,6 +75,8 @@ struct _GVirConnectionClass
void (*domain_added)(GVirConnection *conn, GVirDomain *dom);
void (*domain_removed)(GVirConnection *conn, GVirDomain *dom);
+ void (*domain_restored)(GVirConnection *conn);
+
GVirStream *(*stream_new)(GVirConnection *conn, gpointer handle);
gpointer padding[20];
@@ -202,6 +204,23 @@ gvir_connection_get_capabilities_finish(GVirConnection *conn,
GAsyncResult *result,
GError **err);
+gboolean gvir_connection_domain_restore(GVirConnection *conn,
+ gchar *filename,
+ GVirConfigDomain *conf,
+ guint flags,
+ GError **err);
+
+void gvir_connection_domain_restore_async(GVirConnection *conn,
+ gchar *filename,
+ GVirConfigDomain *conf,
+ guint flags,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+gboolean gvir_connection_domain_restore_finish(GVirConnection *conn,
+ GAsyncResult *result,
+ GError **err);
G_END_DECLS
#endif /* __LIBVIRT_GOBJECT_CONNECTION_H__ */
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
index 54a093a..db32c7f 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -31,6 +31,9 @@ LIBVIRT_GOBJECT_0.0.8 {
gvir_connection_create_storage_pool;
gvir_connection_start_domain;
gvir_connection_get_node_info;
+ gvir_connection_domain_restore;
+ gvir_connection_domain_restore_async;
+ gvir_connection_domain_restore_finish;
gvir_domain_device_get_type;
gvir_domain_device_get_domain;
--
1.7.10.4
12 years, 5 months
[libvirt] [glib PATCH V2] Add bindings for virDomainSave*()
by Jovanka Gulicoska
---
libvirt-gobject/libvirt-gobject-domain.c | 149 +++++++++++++++++++++++++++++-
libvirt-gobject/libvirt-gobject-domain.h | 20 +++-
libvirt-gobject/libvirt-gobject.sym | 3 +
3 files changed, 170 insertions(+), 2 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
index 088cd33..eda2427 100644
--- a/libvirt-gobject/libvirt-gobject-domain.c
+++ b/libvirt-gobject/libvirt-gobject-domain.c
@@ -54,7 +54,7 @@ enum {
VIR_SUSPENDED,
VIR_RESUMED,
VIR_STOPPED,
- VIR_UPDATED,
+ VIR_UPDATED,
LAST_SIGNAL
};
@@ -557,6 +557,153 @@ gboolean gvir_domain_reboot(GVirDomain *dom,
}
/**
+ * gvir_domain_save_to_file:
+ * @dom: the domain
+ * @filename: path to the output file
+ * @conf: configuration for domain
+ * @flags: the flags
+ *
+ * Returns: TRUE on success, FALSE otherwise
+ */
+gboolean gvir_domain_save_to_file(GVirDomain *dom,
+ gchar *filename,
+ GVirConfigDomain *conf,
+ guint flags,
+ GError **err)
+{
+ GVirDomainPrivate *priv;
+ gchar *custom_xml;
+ int ret;
+
+ g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+ g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN (conf), FALSE);
+ g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+ priv = dom->priv;
+ custom_xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
+
+ if (flags || (custom_xml != NULL)) {
+ ret = virDomainSaveFlags(priv->handle, filename, custom_xml, flags);
+ g_free (custom_xml);
+ }
+ else {
+ ret = virDomainSave(priv->handle, filename);
+ g_free (custom_xml);
+ }
+ if (ret < 0) {
+ gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
+ 0,
+ "Unable to save domain to file");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+typedef struct {
+ gchar *filename;
+ gchar *custom_xml;
+ guint flags;
+} DomainSaveToFileData;
+
+static void domain_save_to_file_data_free(DomainSaveToFileData *data)
+{
+ g_free(data->filename);
+ g_free(data->custom_xml);
+ g_slice_free(DomainSaveToFileData, data);
+}
+
+static void
+gvir_domain_save_to_file_helper(GSimpleAsyncResult *res,
+ GObject *object,
+ GCancellable *cancellable G_GNUC_UNUSED)
+{
+ GVirDomain *dom = GVIR_DOMAIN(object);
+ DomainSaveToFileData *data;
+ GVirConfigDomain *conf;
+ GError *err = NULL;
+
+ data = g_simple_async_result_get_op_res_gpointer(res);
+ conf = gvir_domain_get_config(dom, data->flags, &err);
+
+ if (!gvir_domain_save_to_file(dom, data->filename, conf, data->flags, &err))
+ g_simple_async_result_take_error(res, err);
+ }
+
+/**
+ * gvir_domain_save_to_file_async:
+ * @dom: the domain
+ * @filename: path to output file
+ * @conf: configuration for domain
+ * @flags: the flags
+ * @cancellable: cancallation object
+ * @callback: (scope async): completion callback
+ * @user_data: (closure): opaque data for callback
+ *
+ * Asynchronous variant of #gvir_domain_save_to_file
+ */
+void gvir_domain_save_to_file_async (GVirDomain *dom,
+ gchar *filename,
+ GVirConfigDomain *conf,
+ guint flags,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *res;
+ DomainSaveToFileData *data;
+ gchar *xml;
+
+ g_return_if_fail(GVIR_IS_DOMAIN(dom));
+ g_return_if_fail(GVIR_CONFIG_IS_DOMAIN (conf));
+ g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
+
+ xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
+
+ data = g_slice_new0(DomainSaveToFileData);
+ data->filename = g_strdup(filename);
+ data->custom_xml = g_strdup(xml);
+ data->flags = flags;
+
+ res = g_simple_async_result_new(G_OBJECT(dom),
+ callback,
+ user_data,
+ gvir_domain_save_to_file_async);
+ g_simple_async_result_set_op_res_gpointer(res, data, (GDestroyNotify)domain_save_to_file_data_free);
+
+ g_simple_async_result_run_in_thread(res,
+ gvir_domain_save_to_file_helper,
+ G_PRIORITY_DEFAULT,
+ cancellable);
+
+ g_object_unref(res);
+}
+
+/**
+ * gvir_domain_save_to_file_finish:
+ * @dom: the domain to save
+ * @result: (transfer none): async method result
+ * @err: Place-holder for possible errors
+ *
+ * Finishes the operation started by #gvir_domain_save_to_file_async.
+ *
+ * Returns: TRUE if domain was saved successfully, FALSE otherwise.
+ */
+gboolean gvir_domain_save_to_file_finish(GVirDomain *dom,
+ GAsyncResult *result,
+ GError **err)
+{
+ g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+ g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom), gvir_domain_save_to_file_async), FALSE);
+ g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+ if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
+ return FALSE;
+
+ return TRUE;
+}
+
+/**
* gvir_domain_get_config:
* @dom: the domain
* @flags: the flags
diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h
index 87b94f4..49516a7 100644
--- a/libvirt-gobject/libvirt-gobject-domain.h
+++ b/libvirt-gobject/libvirt-gobject-domain.h
@@ -65,7 +65,7 @@ struct _GVirDomainClass
void (*resumed)(GVirDomain *dom);
void (*updated)(GVirDomain *dom);
void (*suspended)(GVirDomain *dom);
-
+
gpointer padding[20];
};
@@ -148,6 +148,24 @@ gboolean gvir_domain_reboot(GVirDomain *dom,
guint flags,
GError **err);
+void gvir_domain_save_to_file_async (GVirDomain *dom,
+ gchar *filename,
+ GVirConfigDomain *conf,
+ guint flags,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+gboolean gvir_domain_save_to_file_finish(GVirDomain *dom,
+ GAsyncResult *result,
+ GError **err);
+
+gboolean gvir_domain_save_to_file(GVirDomain *dom,
+ gchar *filename,
+ GVirConfigDomain *conf,
+ guint flags,
+ GError **err);
+
GVirDomainInfo *gvir_domain_get_info(GVirDomain *dom,
GError **err);
void gvir_domain_get_info_async(GVirDomain *dom,
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
index 94e441a..54a093a 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -75,6 +75,9 @@ LIBVIRT_GOBJECT_0.0.8 {
gvir_domain_get_persistent;
gvir_domain_get_saved;
gvir_domain_screenshot;
+ gvir_domain_save_to_file;
+ gvir_domain_save_to_file_async;
+ gvir_domain_save_to_file_finish;
gvir_domain_snapshot_get_type;
gvir_domain_snapshot_handle_get_type;
--
1.7.10.4
12 years, 5 months
[libvirt] [PATCH]POWER Hypervisor: Fix the segment fault issue for the "list" command
by Dennis Chen
When connect to the remote IBM HMC/IVM server, the remoteNetworkOpen() called
after the phypOpen() in do_open function will re-assign a NULL pointer to the
virConnectPtr conn->networkPrivateData which is allocated in phypOpen(), this
will result in a segment fault issue when execute the following commands,
eg, "virsh# list --all"
Signed-off-by: Dennis Chen<dennis.chen(a)tnsoft.com.cn>
---
src/remote/remote_driver.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index eac50e6..22ef129 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2504,7 +2504,8 @@ static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
remoteGenericOpen(virConnectPtr conn, virConnectAuthPtr auth,
unsigned int flags, void **genericPrivateData)
{
- if (inside_daemon)
+ if (inside_daemon ||
+ STREQ (conn->driver->name, "PHYP"))
return VIR_DRV_OPEN_DECLINED;
if (conn->driver&&
BRs,
Dennis
12 years, 5 months