[libvirt] [PATCH] storage sheepdog: allow to specify redundancy level
by Vasiliy Tolstov
Signed-off-by: Vasiliy Tolstov <v.tolstov(a)selfip.ru>
---
docs/schemas/storagevol.rng | 3 ++
src/conf/storage_conf.c | 2 +
src/storage/storage_backend_sheepdog.c | 38 +++++++++--------
src/util/virstoragefile.c | 4 +-
src/util/virstoragefile.h | 2 +
tests/storagebackendsheepdogtest.c | 68 +++++++++++++++---------------
tests/storagevolxml2xmlin/vol-sheepdog.xml | 1 +
7 files changed, 66 insertions(+), 52 deletions(-)
diff --git a/docs/schemas/storagevol.rng b/docs/schemas/storagevol.rng
index 7450547..068993f 100644
--- a/docs/schemas/storagevol.rng
+++ b/docs/schemas/storagevol.rng
@@ -55,6 +55,9 @@
<element name='allocation'>
<ref name='scaledInteger'/>
</element>
+ <element name='redundancy'>
+ <ref name='string'/>
+ </element>
</optional>
</interleave>
</define>
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 9b8abea..d37c93a 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1345,6 +1345,8 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
ret->target.allocation = ret->target.capacity;
}
+ ret->target.redundancy = virXPathString("string(./redundancy)", ctxt);
+
ret->target.path = virXPathString("string(./target/path)", ctxt);
if (options->formatFromString) {
char *format = virXPathString("string(./target/format/@type)", ctxt);
diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c
index 1200813..565cfd0 100644
--- a/src/storage/storage_backend_sheepdog.c
+++ b/src/storage/storage_backend_sheepdog.c
@@ -275,6 +275,10 @@ virStorageBackendSheepdogBuildVol(virConnectPtr conn ATTRIBUTE_UNUSED,
cmd = virCommandNewArgList(SHEEPDOGCLI, "vdi", "create", vol->name, NULL);
virCommandAddArgFormat(cmd, "%llu", vol->target.capacity);
+
+ if(NULL != vol->target.redundancy)
+ virCommandAddArgFormat(cmd, "-c %s", vol->target.redundancy);
+
virStorageBackendSheepdogAddHostArg(cmd, pool);
if (virCommandRun(cmd, NULL) < 0)
goto cleanup;
@@ -291,18 +295,19 @@ virStorageBackendSheepdogParseVdiList(virStorageVolDefPtr vol,
char *output)
{
/* fields:
- * current/clone/snapshot, name, id, size, used, shared, creation time, vdi id, [tag]
+ * current/clone/snapshot, name, id, size, used, shared, creation time, vdi id, redundancy, [tag], size shift
*
* example output:
- * s test 1 10 0 0 1336556634 7c2b25
- * s test 2 10 0 0 1336557203 7c2b26
- * = test 3 10 0 0 1336557216 7c2b27
+ * s test 1 10 0 0 1336556634 7c2b25 1 tt 22
+ * s test 2 10 0 0 1336557203 7c2b26 2 zz 22
+ * = test 3 10 0 0 1336557216 7c2b27 3 xx 22
*/
- int id;
+ char **args;
const char *p, *next;
vol->target.allocation = vol->target.capacity = 0;
+ vol->target.redundancy = NULL;
p = output;
do {
@@ -327,24 +332,21 @@ virStorageBackendSheepdogParseVdiList(virStorageVolDefPtr vol,
++p;
++p;
}
+ }
+ args = virStringSplit(p, " ", 9);
- if (virStrToLong_i(p, &end, 10, &id) < 0)
- return -1;
-
- p = end + 1;
-
- if (virStrToLong_ull(p, &end, 10, &vol->target.capacity) < 0)
- return -1;
+ if (virStrToLong_ull(args[1], strlen(args[1]), 10, &vol->target.capacity) < 0)
+ return -1;
- p = end + 1;
+ if (virStrToLong_ull(args[2], strlen(args[2]), 10, &vol->target.allocation) < 0)
+ return -1;
- if (virStrToLong_ull(p, &end, 10, &vol->target.allocation) < 0)
- return -1;
+ if (VIR_STRNDUP(vol->target.redundancy, args[5], strlen(args[2])) < 0)
+ return -1;
- return 0;
- } while ((p = next));
+ virStringFreeList(args);
- return -1;
+ return 0;
}
static int
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 2aa1d90..9cdc90d 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1846,7 +1846,8 @@ virStorageSourceCopy(const virStorageSource *src,
VIR_STRDUP(ret->backingStoreRaw, src->backingStoreRaw) < 0 ||
VIR_STRDUP(ret->snapshot, src->snapshot) < 0 ||
VIR_STRDUP(ret->configFile, src->configFile) < 0 ||
- VIR_STRDUP(ret->compat, src->compat) < 0)
+ VIR_STRDUP(ret->compat, src->compat) < 0 ||
+ VIR_STRDUP(ret->redundancy, src->redundancy) < 0)
goto error;
if (src->nhosts) {
@@ -2040,6 +2041,7 @@ virStorageSourceClear(virStorageSourcePtr def)
VIR_FREE(def->volume);
VIR_FREE(def->snapshot);
VIR_FREE(def->configFile);
+ VIR_FREE(def->redundancy);
virStorageSourcePoolDefFree(def->srcpool);
VIR_FREE(def->driverName);
virBitmapFree(def->features);
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index b98fe25..c37cfc2 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -282,6 +282,8 @@ struct _virStorageSource {
/* Name of the child backing store recorded in metadata of the
* current file. */
char *backingStoreRaw;
+ /* redundancy level, may be used by sheepdog or ceph */
+ char *redundancy;
};
diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheepdogtest.c
index 2b0f4db..c037ebe 100644
--- a/tests/storagebackendsheepdogtest.c
+++ b/tests/storagebackendsheepdogtest.c
@@ -42,6 +42,7 @@ typedef struct {
int expected_return;
uint64_t expected_capacity;
uint64_t expected_allocation;
+ const char *expected_redundancy;
} collie_test;
struct testNodeInfoParserData {
@@ -119,7 +120,8 @@ test_vdi_list_parser(const void *opaque)
}
if (vol->target.capacity == test.expected_capacity &&
- vol->target.allocation == test.expected_allocation)
+ vol->target.allocation == test.expected_allocation &&
+ !strcmp(vol->target.redundancy, test.expected_redundancy))
ret = 0;
cleanup:
@@ -138,41 +140,41 @@ mymain(void)
char *volxml = NULL;
collie_test node_info_tests[] = {
- {"", -1, 0, 0},
- {"Total 15245667872 117571104 0% 20972341\n", 0, 15245667872, 117571104},
- {"To", -1, 0, 0},
- {"asdf\nasdf", -1, 0, 0},
- {"Total ", -1, 0, 0},
- {"Total 1", -1, 0, 0},
- {"Total 1\n", -1, 0, 0},
- {"Total 1 ", -1, 0, 0},
- {"Total 1 2", -1, 0, 0},
- {"Total 1 2 ", -1, 0, 0},
- {"Total 1 2\n", 0, 1, 2},
- {"Total 1 2 \n", 0, 1, 2},
- {"Total a 2 \n", -1, 0, 0},
- {"Total 1 b \n", -1, 0, 0},
- {"Total a b \n", -1, 0, 0},
- {"stuff\nTotal 1 2 \n", 0, 1, 2},
- {"0 1 2 3\nTotal 1 2 \n", 0, 1, 2},
- {NULL, 0, 0, 0}
+ {"", -1, 0, 0,"0"},
+ {"Total 15245667872 117571104 1 0% 20972341\n", 0, 15245667872, 117571104,"1"},
+ {"To", -1, 0, 0," "},
+ {"asdf\nasdf", -1, 0, 0," "},
+ {"Total ", -1, 0, 0, " "},
+ {"Total 1", -1, 0, 0, " "},
+ {"Total 1\n", -1, 0, 0," "},
+ {"Total 1 ", -1, 0, 0, " "},
+ {"Total 1 2", -1, 0, 0, " "},
+ {"Total 1 2 ", -1, 0, 0," "},
+ {"Total 1 2 1:1\n", 0, 1, 2,"1:1"},
+ {"Total 1 2 3:4\n", 0, 1, 2,"3:4"},
+ {"Total a 2 \n", -1, 0, 0," "},
+ {"Total 1 b \n", -1, 0, 0," "},
+ {"Total a b \n", -1, 0, 0,"sss"},
+ {"stuff\nTotal 1 2 1:2\n", 0, 1, 2,"1:2"},
+ {"0 1 2 3\nTotal 1 2 3\n", 0, 1, 2,"3"},
+ {NULL, 0, 0, 0, NULL}
};
collie_test vdi_list_tests[] = {
- {"", -1, 0, 0},
- {"= test 3 10 20 0 1336557216 7c2b27\n", 0, 10, 20},
- {"= test\\ with\\ spaces 3 10 20 0 1336557216 7c2b27\n", 0, 10, 20},
- {"= backslashattheend\\\\ 3 10 20 0 1336557216 7c2b27\n", 0, 10, 20},
- {"s test 1 10 20 0 1336556634 7c2b25\n= test 3 50 60 0 1336557216 7c2b27\n", 0, 50, 60},
- {"=", -1, 0, 0},
- {"= test", -1, 0, 0},
- {"= test ", -1, 0, 0},
- {"= test 1", -1, 0, 0},
- {"= test 1 ", -1, 0, 0},
- {"= test 1 2", -1, 0, 0},
- {"= test 1 2 ", -1, 0, 0},
- {"= test 1 2 3", -1, 0, 0},
- {NULL, 0, 0, 0}
+ {"", -1, 0, 0,NULL},
+ {"= test 3 10 20 1 0 1336557216 7c2b27 1\n", 0, 10, 20, "1"},
+ {"= test\\ with\\ spaces 3 10 20 0 1336557216 7c2b27 3:4\n", 0, 10, 20, "3:4"},
+ {"= backslashattheend\\\\ 3 10 20 0 1336557216 7c2b27 1\n", 0, 10, 20, "1"},
+ {"s test 1 10 20 0 1336556634 7c2b25 2\n= test 3 50 60 0 1336557216 7c2b27 2:3\n", 0, 50, 60, "2:3"},
+ {"=", -1, 0, 0," "},
+ {"= test", -1, 0, 0," "},
+ {"= test ", -1, 0, 0," "},
+ {"= test 1", -1, 0, 0," "},
+ {"= test 1 ", -1, 0, 0," "},
+ {"= test 1 2", -1, 0, 0," "},
+ {"= test 1 2 ", -1, 0, 0," "},
+ {"= test 1 2 3", -1, 0, 0," "},
+ {NULL, 0, 0, 0,NULL}
};
collie_test *test = node_info_tests;
diff --git a/tests/storagevolxml2xmlin/vol-sheepdog.xml b/tests/storagevolxml2xmlin/vol-sheepdog.xml
index d6e920b..f88e6db 100644
--- a/tests/storagevolxml2xmlin/vol-sheepdog.xml
+++ b/tests/storagevolxml2xmlin/vol-sheepdog.xml
@@ -4,6 +4,7 @@
</source>
<capacity unit='bytes'>1024</capacity>
<allocation unit='bytes'>0</allocation>
+ <redundancy unit='string'>3</redundancy>
<target>
<path>sheepdog:test2</path>
</target>
--
2.5.0
9 years, 5 months
[libvirt] [PATCH] bhyve: monitor: do not override domain's privateData
by Roman Bogorodskiy
Current monitor code overrides domain object's privateData, e.g.
in virBhyveProcessStart():
vm->privateData = bhyveMonitorOpen(vm, driver);
where bhyveMonitorPtr() returns bhyveMonitorPtr.
This is not right thing to do, so make bhyveMonitorPtr
a part of the bhyveDomainObjPrivate struct and change related code
accordingly.
---
src/bhyve/bhyve_domain.h | 4 ++++
src/bhyve/bhyve_monitor.c | 36 +++++++++++++++++++-----------------
src/bhyve/bhyve_process.c | 11 +++++++----
3 files changed, 30 insertions(+), 21 deletions(-)
diff --git a/src/bhyve/bhyve_domain.h b/src/bhyve/bhyve_domain.h
index b8ef22a..0a60392 100644
--- a/src/bhyve/bhyve_domain.h
+++ b/src/bhyve/bhyve_domain.h
@@ -26,11 +26,15 @@
# include "domain_addr.h"
# include "domain_conf.h"
+# include "bhyve_monitor.h"
+
typedef struct _bhyveDomainObjPrivate bhyveDomainObjPrivate;
typedef bhyveDomainObjPrivate *bhyveDomainObjPrivatePtr;
struct _bhyveDomainObjPrivate {
virDomainPCIAddressSetPtr pciaddrs;
bool persistentAddrs;
+
+ bhyveMonitorPtr mon;
};
extern virDomainXMLPrivateDataCallbacks virBhyveDriverPrivateDataCallbacks;
diff --git a/src/bhyve/bhyve_monitor.c b/src/bhyve/bhyve_monitor.c
index 1316720..37c9e79 100644
--- a/src/bhyve/bhyve_monitor.c
+++ b/src/bhyve/bhyve_monitor.c
@@ -27,6 +27,7 @@
#include <sys/time.h>
#include <sys/wait.h>
+#include "bhyve_domain.h"
#include "bhyve_monitor.h"
#include "bhyve_process.h"
#include "viralloc.h"
@@ -41,7 +42,6 @@ VIR_LOG_INIT("bhyve.bhyve_monitor");
struct _bhyveMonitor {
int kq;
int watch;
- virDomainObjPtr vm;
bhyveConnPtr driver;
};
@@ -49,7 +49,9 @@ static void
bhyveMonitorIO(int watch, int kq, int events ATTRIBUTE_UNUSED, void *opaque)
{
const struct timespec zerowait = { 0, 0 };
- bhyveMonitorPtr mon = opaque;
+ virDomainObjPtr vm = opaque;
+ bhyveDomainObjPrivatePtr priv = vm->privateData;
+ bhyveMonitorPtr mon = priv->mon;
struct kevent kev;
int rc, status;
@@ -75,10 +77,10 @@ bhyveMonitorIO(int watch, int kq, int events ATTRIBUTE_UNUSED, void *opaque)
}
if (kev.filter == EVFILT_PROC && (kev.fflags & NOTE_EXIT) != 0) {
- if ((pid_t)kev.ident != mon->vm->pid) {
+ if ((pid_t)kev.ident != vm->pid) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("event from unexpected proc %ju!=%ju"),
- (uintmax_t)mon->vm->pid, (uintmax_t)kev.ident);
+ (uintmax_t)vm->pid, (uintmax_t)kev.ident);
return;
}
@@ -86,28 +88,28 @@ bhyveMonitorIO(int watch, int kq, int events ATTRIBUTE_UNUSED, void *opaque)
if (WIFSIGNALED(status) && WCOREDUMP(status)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Guest %s got signal %d and crashed"),
- mon->vm->def->name,
+ vm->def->name,
WTERMSIG(status));
- virBhyveProcessStop(mon->driver, mon->vm,
+ virBhyveProcessStop(mon->driver, vm,
VIR_DOMAIN_SHUTOFF_CRASHED);
} else if (WIFEXITED(status)) {
if (WEXITSTATUS(status) == 0) {
/* 0 - reboot */
/* TODO: Implementing reboot is a little more complicated. */
VIR_INFO("Guest %s rebooted; destroying domain.",
- mon->vm->def->name);
- virBhyveProcessStop(mon->driver, mon->vm,
+ vm->def->name);
+ virBhyveProcessStop(mon->driver, vm,
VIR_DOMAIN_SHUTOFF_SHUTDOWN);
} else if (WEXITSTATUS(status) < 3) {
/* 1 - shutdown, 2 - halt, 3 - triple fault. others - error */
VIR_INFO("Guest %s shut itself down; destroying domain.",
- mon->vm->def->name);
- virBhyveProcessStop(mon->driver, mon->vm,
+ vm->def->name);
+ virBhyveProcessStop(mon->driver, vm,
VIR_DOMAIN_SHUTOFF_SHUTDOWN);
} else {
VIR_INFO("Guest %s had an error and exited with status %d; destroying domain.",
- mon->vm->def->name, WEXITSTATUS(status));
- virBhyveProcessStop(mon->driver, mon->vm,
+ vm->def->name, WEXITSTATUS(status));
+ virBhyveProcessStop(mon->driver, vm,
VIR_DOMAIN_SHUTOFF_UNKNOWN);
}
}
@@ -117,24 +119,24 @@ bhyveMonitorIO(int watch, int kq, int events ATTRIBUTE_UNUSED, void *opaque)
static void
bhyveMonitorRelease(void *opaque)
{
- bhyveMonitorPtr mon = opaque;
+ virDomainObjPtr vm = opaque;
+ bhyveDomainObjPrivatePtr priv = vm->privateData;
+ bhyveMonitorPtr mon = priv->mon;
VIR_FORCE_CLOSE(mon->kq);
- virObjectUnref(mon->vm);
VIR_FREE(mon);
}
bhyveMonitorPtr
bhyveMonitorOpen(virDomainObjPtr vm, bhyveConnPtr driver)
{
- bhyveMonitorPtr mon;
+ bhyveMonitorPtr mon = NULL;
struct kevent kev;
int rc;
if (VIR_ALLOC(mon) < 0)
return NULL;
- mon->vm = virObjectRef(vm);
mon->driver = driver;
mon->kq = kqueue();
@@ -157,7 +159,7 @@ bhyveMonitorOpen(virDomainObjPtr vm, bhyveConnPtr driver)
VIR_EVENT_HANDLE_ERROR |
VIR_EVENT_HANDLE_HANGUP,
bhyveMonitorIO,
- mon,
+ vm,
bhyveMonitorRelease);
if (mon->watch < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c
index 284641a..42255d2 100644
--- a/src/bhyve/bhyve_process.c
+++ b/src/bhyve/bhyve_process.c
@@ -113,6 +113,7 @@ virBhyveProcessStart(virConnectPtr conn,
virCommandPtr cmd = NULL;
virCommandPtr load_cmd = NULL;
bhyveConnPtr privconn = conn->privateData;
+ bhyveDomainObjPrivatePtr priv = vm->privateData;
int ret = -1, rc;
if (virAsprintf(&logfile, "%s/%s.log",
@@ -210,7 +211,7 @@ virBhyveProcessStart(virConnectPtr conn,
vm->def->id = vm->pid;
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason);
- vm->privateData = bhyveMonitorOpen(vm, driver);
+ priv->mon = bhyveMonitorOpen(vm, driver);
if (virDomainSaveStatus(driver->xmlopt,
BHYVE_STATE_DIR,
@@ -257,6 +258,7 @@ virBhyveProcessStop(bhyveConnPtr driver,
{
int ret = -1;
virCommandPtr cmd = NULL;
+ bhyveDomainObjPrivatePtr priv = vm->privateData;
if (!virDomainObjIsActive(vm)) {
VIR_DEBUG("VM '%s' not active", vm->def->name);
@@ -270,8 +272,8 @@ virBhyveProcessStop(bhyveConnPtr driver,
return -1;
}
- if (vm->privateData != NULL)
- bhyveMonitorClose((bhyveMonitorPtr)vm->privateData);
+ if ((priv != NULL) && (priv->mon != NULL))
+ bhyveMonitorClose(priv->mon);
/* First, try to kill 'bhyve' process */
if (virProcessKillPainfully(vm->pid, true) != 0)
@@ -358,6 +360,7 @@ virBhyveProcessReconnect(virDomainObjPtr vm,
int nprocs;
char **proc_argv;
char *expected_proctitle = NULL;
+ bhyveDomainObjPrivatePtr priv = vm->privateData;
int ret = -1;
if (!virDomainObjIsActive(vm))
@@ -379,7 +382,7 @@ virBhyveProcessReconnect(virDomainObjPtr vm,
if (proc_argv && proc_argv[0]) {
if (STREQ(expected_proctitle, proc_argv[0])) {
ret = 0;
- vm->privateData = bhyveMonitorOpen(vm, data->driver);
+ priv->mon = bhyveMonitorOpen(vm, data->driver);
}
}
--
2.6.1
9 years, 5 months
[libvirt] split string into tokens via libvirt
by Vasiliy Tolstov
Hi. I'm need to parse string like "= test\ aaa 3 10 0 0 1336557216 7c2b27 3 22"
I can use virStringSplitCount, but second word contains space and
splitting not works right.
Does this need i need to parse string by hand via strtok ?
--
Vasiliy Tolstov,
e-mail: v.tolstov(a)selfip.ru
9 years, 5 months
[libvirt] [PATCH v2] syntax-check: Add prohibit_space_in_label rule
by Andrea Bolognani
This guards against code such as
cleanup :
which is happily accepted by the compiler but does not conform
to our style guidelines.
---
cfg.mk | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/cfg.mk b/cfg.mk
index a9bba38..7a5a1de 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -919,6 +919,15 @@ sc_require_space_before_label:
halt="Top-level labels should be indented by one space" \
$(_sc_search_regexp)
+# Allow for up to three spaces before the label: this is to avoid running
+# into situations where require_space_before_label is not applied, eg. a
+# line matching ^[a-zA-Z0-9]+ :$
+sc_prohibit_space_in_label:
+ @prohibit='^ ? ? ?[_a-zA-Z0-9]+ +:$$' \
+ in_vc_files='\.[ch]$$' \
+ halt="There should be no space between label name and colon" \
+ $(_sc_search_regexp)
+
# Doesn't catch all cases of mismatched braces across if-else, but it helps
sc_require_if_else_matching_braces:
@prohibit='( else( if .*\))? {|} else( if .*\))?$$)' \
--
2.4.3
9 years, 5 months
[libvirt] [PATCH] util: remove unnecessary needSize
by Chen Hanxiao
From: Chen Hanxiao <chenhanxiao(a)gmail.com>
Use toadd->use directly.
Signed-off-by: Chen Hanxiao <chenhanxiao(a)gmail.com>
---
src/util/virbuffer.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c
index 5b338f8..55dad37 100644
--- a/src/util/virbuffer.c
+++ b/src/util/virbuffer.c
@@ -186,8 +186,6 @@ virBufferAdd(virBufferPtr buf, const char *str, int len)
void
virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd)
{
- unsigned int needSize;
-
if (!toadd)
return;
@@ -200,8 +198,7 @@ virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd)
goto done;
}
- needSize = buf->use + toadd->use;
- if (virBufferGrow(buf, needSize - buf->use) < 0)
+ if (virBufferGrow(buf, toadd->use) < 0)
goto done;
memcpy(&buf->content[buf->use], toadd->content, toadd->use);
--
1.9.0
9 years, 5 months
[libvirt] [PATCH v2] gobject: Add wrapper virDomainSetTime()
by Zeeshan Ali (Khattak)
---
This version:
* Replaces the seconds and nseconds arguments by a GDateTime.
* Drops the use of flags argument, since caller can specify the only flag currently possible (VIR_DOMAIN_TIME_SYNC) by simply passing a NULL as the GDateTime argument.
* Add some needed articles to doc comment.
libvirt-gobject/libvirt-gobject-domain.c | 121 +++++++++++++++++++++++++++++++
libvirt-gobject/libvirt-gobject-domain.h | 15 +++-
libvirt-gobject/libvirt-gobject.sym | 9 +++
3 files changed, 144 insertions(+), 1 deletion(-)
diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
index 34eb7ca..debae2d 100644
--- a/libvirt-gobject/libvirt-gobject-domain.c
+++ b/libvirt-gobject/libvirt-gobject-domain.c
@@ -1886,3 +1886,124 @@ gboolean gvir_domain_get_has_current_snapshot(GVirDomain *dom,
return TRUE;
}
+
+/**
+ * gvir_domain_set_time:
+ * @dom: the domain
+ * @date_time: (allow-none)(transfer none): the time to set as #GDateTime.
+ * @flags: Unused, Pass 0.
+ *
+ * This function tries to set guest time to the given value. The passed
+ * time must in UTC.
+ *
+ * If @date_time is %NULL, the time is reset using the domain's RTC.
+ *
+ * Please note that some hypervisors may require guest agent to be configured
+ * and running in order for this function to work.
+ */
+gboolean gvir_domain_set_time(GVirDomain *dom,
+ GDateTime *date_time,
+ guint flags G_GNUC_UNUSED,
+ GError **err)
+{
+ GVirDomainPrivate *priv;
+ int ret;
+ GTimeVal tv;
+ gint64 seconds;
+ guint nseconds;
+ guint settime_flags;
+
+ g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+ g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+ if (date_time != NULL) {
+ if (!g_date_time_to_timeval(date_time, &tv)) {
+ gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
+ 0,
+ "Failed to parse given time argument");
+ return FALSE;
+ }
+
+ seconds = tv.tv_sec;
+ nseconds = tv.tv_usec * 1000;
+ settime_flags = 0;
+ } else {
+ seconds = 0;
+ nseconds = 0;
+ settime_flags = VIR_DOMAIN_TIME_SYNC;
+ }
+
+ priv = dom->priv;
+ ret = virDomainSetTime(priv->handle, seconds, nseconds, settime_flags);
+ if (ret < 0) {
+ gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
+ 0,
+ "Unable to set domain time");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void
+gvir_domain_set_time_helper(GTask *task,
+ gpointer object,
+ gpointer task_data,
+ GCancellable *cancellable G_GNUC_UNUSED)
+{
+ GVirDomain *dom = GVIR_DOMAIN(object);
+ GDateTime *date_time = (GDateTime *) task_data;
+ GError *err = NULL;
+
+ if (!gvir_domain_set_time(dom, date_time, 0, &err))
+ g_task_return_error(task, err);
+ else
+ g_task_return_boolean(task, TRUE);
+}
+
+/**
+ * gvir_domain_set_time_async:
+ * @dom: the domain
+ * @date_time: (allow-none)(transfer none): the time to set as #GDateTime.
+ * @flags: bitwise-OR of #GVirDomainSetTimeFlags.
+ * @cancellable: (allow-none)(transfer none): cancellation object
+ * @callback: (scope async): completion callback
+ * @user_data: (closure): opaque data for callback
+ *
+ * Asynchronous variant of #gvir_domain_set_time.
+ */
+void gvir_domain_set_time_async(GVirDomain *dom,
+ GDateTime *date_time,
+ guint flags G_GNUC_UNUSED,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task;
+
+ g_return_if_fail(GVIR_IS_DOMAIN(dom));
+ g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
+
+ task = g_task_new(G_OBJECT(dom),
+ cancellable,
+ callback,
+ user_data);
+ if (date_time != NULL)
+ g_task_set_task_data(task,
+ g_date_time_ref(date_time),
+ (GDestroyNotify)g_date_time_unref);
+ g_task_run_in_thread(task, gvir_domain_set_time_helper);
+
+ g_object_unref(task);
+}
+
+gboolean gvir_domain_set_time_finish(GVirDomain *dom,
+ GAsyncResult *result,
+ GError **err)
+{
+ g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+ g_return_val_if_fail(g_task_is_valid(result, G_OBJECT(dom)), FALSE);
+ g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+ return g_task_propagate_boolean(G_TASK(result), err);
+}
diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h
index 4fe381e..099cde3 100644
--- a/libvirt-gobject/libvirt-gobject-domain.h
+++ b/libvirt-gobject/libvirt-gobject-domain.h
@@ -215,7 +215,6 @@ typedef enum {
GVIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL = VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL
} GVirDomainSnapshotListFlags;
-
typedef struct _GVirDomainInfo GVirDomainInfo;
struct _GVirDomainInfo
{
@@ -401,6 +400,20 @@ gboolean gvir_domain_get_has_current_snapshot(GVirDomain *dom,
gboolean *has_current_snapshot,
GError **error);
+gboolean gvir_domain_set_time(GVirDomain *dom,
+ GDateTime *date_time,
+ guint flags,
+ GError **err);
+void gvir_domain_set_time_async(GVirDomain *dom,
+ GDateTime *date_time,
+ guint flags,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean gvir_domain_set_time_finish(GVirDomain *dom,
+ GAsyncResult *result,
+ GError **err);
+
G_END_DECLS
#endif /* __LIBVIRT_GOBJECT_DOMAIN_H__ */
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
index ca89a45..cbfaa71 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -304,4 +304,13 @@ LIBVIRT_GOBJECT_0.2.2 {
gvir_network_get_dhcp_leases;
} LIBVIRT_GOBJECT_0.2.1;
+LIBVIRT_GOBJECT_0.2.3 {
+ global:
+ gvir_domain_set_time_flags_get_type;
+
+ gvir_domain_set_time;
+ gvir_domain_set_time_async;
+ gvir_domain_set_time_finish;
+} LIBVIRT_GOBJECT_0.2.2;
+
# .... define new API here using predicted next version number ....
--
2.5.0
9 years, 5 months
[libvirt] [PATCH] util: remove unnecessary needSize
by Chen Hanxiao
From: Chen Hanxiao <chenhanxiao(a)gmail.com>
Use toadd->use directly.
Signed-off-by: Chen Hanxiao <chenhanxiao(a)gmail.com>
---
src/util/virbuffer.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c
index 5b338f8..55dad37 100644
--- a/src/util/virbuffer.c
+++ b/src/util/virbuffer.c
@@ -186,8 +186,6 @@ virBufferAdd(virBufferPtr buf, const char *str, int len)
void
virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd)
{
- unsigned int needSize;
-
if (!toadd)
return;
@@ -200,8 +198,7 @@ virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd)
goto done;
}
- needSize = buf->use + toadd->use;
- if (virBufferGrow(buf, needSize - buf->use) < 0)
+ if (virBufferGrow(buf, toadd->use) < 0)
goto done;
memcpy(&buf->content[buf->use], toadd->content, toadd->use);
--
1.9.0
9 years, 5 months
[libvirt] [PATCH 0/4] Fix crash resuling from script doing FC/SCSI pool-create destroy
by John Ferlan
Details in the patches - essentially testing found an issue creating
and destroying an FC/SCSI pool due to the refresh thread created for
bz 1152382 running after the destroy.
Seen using script which has
for i in 1 2 3 ; \
do virsh pool-create /tmp/test.xml; \
sleep 1; \
virsh pool-destroy p1; \
sleep 1; \
done
John Ferlan (4):
storage: Make active boolean
storage: Change cbdata scsi refresh thread field name
storage: Introduce virStoragePoolObjFindPoolByUUID
storage: Don't assume storage pool exists for scsi refresh thread
src/conf/storage_conf.h | 2 +-
src/storage/storage_backend_scsi.c | 30 +++++++++++++++++-------------
src/storage/storage_driver.c | 31 ++++++++++++++++++++++++++-----
src/storage/storage_driver.h | 3 +++
4 files changed, 47 insertions(+), 19 deletions(-)
--
2.1.0
9 years, 5 months
[libvirt] [PATCH] vz: add func to set shared drivers after libvirtd init
by Mikhail Feoktistov
Built-in drivers in libvirt are initialized before libvirtd initialization.
Libvirt loads shared drivers on libvirtd initialization step.
For built-in drivers we can't set shared drivers, because they are not initialized yet.
This patch adds function to set shared drivers after libvirtd init.
---
daemon/libvirtd.c | 4 ++++
src/libvirt.c | 41 +++++++++++++++++++++++++++++++++++++++++
src/libvirt_internal.h | 1 +
src/libvirt_private.syms | 1 +
4 files changed, 47 insertions(+)
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 250094b..aac1826 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -431,6 +431,10 @@ static void daemonInitialize(void)
bhyveRegister();
# endif
#endif
+# ifdef WITH_VZ
+ virAssignSharedDrivers("vz");
+ virAssignSharedDrivers("Parallels");
+# endif
}
diff --git a/src/libvirt.c b/src/libvirt.c
index 2602dde..4c4b7bd 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -1433,3 +1433,44 @@ virTypedParameterValidateSet(virConnectPtr conn,
}
return 0;
}
+
+/**
+ * virAssignSharedDrivers:
+ * @name: name of connection driver
+ *
+ * This function fills in any empty pointers for shared drivers
+ * in connect driver structure
+ *
+ * Returns 0 in case of success, -1 in case of error
+*/
+int
+virAssignSharedDrivers(const char *name)
+{
+ size_t i;
+
+ if (name == NULL) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Driver name must be specified"));
+ return -1;
+ }
+
+ for (i = 0; i < virConnectDriverTabCount; i++) {
+ if (STREQ(virConnectDriverTab[i]->hypervisorDriver->name, name)) {
+ if (virConnectDriverTab[i]->interfaceDriver == NULL)
+ virConnectDriverTab[i]->interfaceDriver = virSharedInterfaceDriver;
+ if (virConnectDriverTab[i]->networkDriver == NULL)
+ virConnectDriverTab[i]->networkDriver = virSharedNetworkDriver;
+ if (virConnectDriverTab[i]->nodeDeviceDriver == NULL)
+ virConnectDriverTab[i]->nodeDeviceDriver = virSharedNodeDeviceDriver;
+ if (virConnectDriverTab[i]->nwfilterDriver == NULL)
+ virConnectDriverTab[i]->nwfilterDriver = virSharedNWFilterDriver;
+ if (virConnectDriverTab[i]->secretDriver == NULL)
+ virConnectDriverTab[i]->secretDriver = virSharedSecretDriver;
+ if (virConnectDriverTab[i]->storageDriver == NULL)
+ virConnectDriverTab[i]->storageDriver = virSharedStorageDriver;
+ break;
+ }
+ }
+
+ return 0;
+}
diff --git a/src/libvirt_internal.h b/src/libvirt_internal.h
index 1313b58..2a7227b 100644
--- a/src/libvirt_internal.h
+++ b/src/libvirt_internal.h
@@ -289,4 +289,5 @@ virTypedParameterValidateSet(virConnectPtr conn,
virTypedParameterPtr params,
int nparams);
+int virAssignSharedDrivers(const char *name);
#endif
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index be6ee19..340555a 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -943,6 +943,7 @@ virFDStreamSetInternalCloseCb;
# libvirt_internal.h
+virAssignSharedDrivers;
virConnectSupportsFeature;
virDomainMigrateBegin3;
virDomainMigrateBegin3Params;
--
1.8.3.1
9 years, 5 months
[libvirt] [PATCHv3 0/4] Hyper-v crash feature support
by Dmitry Andreev
A new Hyper-V cpu feature 'hv_crash' was added to QEMU. The feature
will become available in v2.5.0.
This patch adds support for this feature.
The previous version of this patch is
https://www.redhat.com/archives/libvir-list/2015-November/msg00400.html
What is changed:
* 'model' is an optional attribute and will not be added
if it wasn't specified by the user [1/4]
* docs text fixed [1/4] [3/4]
* schema and code allows multiple panic devices [3/4]
* more tests is added and all changes in old tests
are removed [4/4]
What isn't changed:
I didn't add <code> tag around model values in docs because there
are many examples of "<ul><li> 'value' —" without a <code> tag.
Dmitry Andreev (4):
conf: add 'model' attribute for panic device with values isa, pseries,
hyperv
qemu: add support for hv_crash feature as a panic device
schema: allow multiple panic devices
tests: add tests for panic models and multiple panic devices
docs/formatdomain.html.in | 19 +++-
docs/schemas/domaincommon.rng | 13 ++-
src/conf/domain_conf.c | 101 ++++++++++++---------
src/conf/domain_conf.h | 15 ++-
src/qemu/qemu_command.c | 84 +++++++++++++++--
src/qemu/qemu_domain.c | 21 ++++-
tests/qemuargv2xmltest.c | 1 +
.../qemuxml2argv-hyperv-panic.args | 21 +++++
.../qemuxml2argvdata/qemuxml2argv-hyperv-panic.xml | 25 +++++
.../qemuxml2argv-panic-double.args | 21 +++++
.../qemuxml2argvdata/qemuxml2argv-panic-double.xml | 28 ++++++
tests/qemuxml2argvdata/qemuxml2argv-panic-isa.xml | 31 +++++++
.../qemuxml2argv-panic-pseries.xml | 30 ++++++
tests/qemuxml2argvtest.c | 3 +
tests/qemuxml2xmltest.c | 4 +
15 files changed, 353 insertions(+), 64 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-hyperv-panic.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-hyperv-panic.xml
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-panic-double.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-panic-double.xml
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-panic-isa.xml
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-panic-pseries.xml
--
1.8.3.1
9 years, 5 months