[libvirt] [PATCH v2] virsh: Honor reedit opts printing to a function
by Michal Privoznik
When printing reedit options we make stdin raw. However,
this results in stdout being raw as well. Therefore we need
to return carriage when doing new line. Unfortunately,
'\r' cannot be part of internationalized messages hence
we must move them to formatting string which then in turn
become huge and disarranged. To solve this, a new function
is introduced which takes variable string arguments and
prepend each with "\r\n" just before printing.
---
tools/virsh.c | 24 ++++++++++++++++++++----
1 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index 98305c0..11dc0e7 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -655,6 +655,19 @@ vshReconnect(vshControl *ctl)
ctl->useSnapshotOld = false;
}
+static void
+vshPrintRaw(vshControl *ctl, ...)
+{
+ va_list ap;
+ char *key;
+
+ va_start(ap, ctl);
+ while ((key = va_arg(ap, char *)) != NULL) {
+ vshPrint(ctl, "\r\n%s", key);
+ }
+ va_end(ap);
+}
+
/**
* vshAskReedit:
* @msg: Question to ask user
@@ -690,10 +703,13 @@ vshAskReedit(vshControl *ctl, const char *msg)
c = c_tolower(getchar());
if (c == '?') {
- vshPrint(ctl, "\r\n%s", _("y - yes, start editor again\n"
- "n - no, throw away my changes\n"
- "f - force, try to redefine again\n"
- "? - print this help\n"));
+ vshPrintRaw(ctl,
+ _("y - yes, start editor again"),
+ _("n - no, throw away my changes"),
+ _("f - force, try to redefine again"),
+ _("? - print this help"),
+ "",
+ NULL);
continue;
} else if (c == 'y' || c == 'n' || c == 'f') {
break;
--
1.7.8.5
12 years, 5 months
[libvirt] [PATCH 0/8] API to list all snapshots
by Eric Blake
Requires these 11 patches to be reviewed first:
https://www.redhat.com/archives/libvir-list/2012-June/msg00273.html
https://www.redhat.com/archives/libvir-list/2012-June/msg00267.html
https://www.redhat.com/archives/libvir-list/2012-May/msg01196.html
I'm still working on at least two more patches (actually wiring up
domain_conf.c to create the snapshot list, and then fixing
qemu_driver.c to use the new domain_conf.c helpers), but wanted to
get this out for review, especially since it has some interaction
with Peter's series for listing all domains (translation: I've tried
to make sure this series complies with the review comments I made
against his series):
https://www.redhat.com/archives/libvir-list/2012-June/msg00113.html
I suppose that means that I technically haven't done any testing
other than compilation so far, at least until I post the last two
patches for qemu... And I suppose I also ought to try my hand
at vbox and esx patches, even though I can't test those (it would
be basically copy-and-paste from existing code in those drivers).
And if I'm really up to it, I'll add snapshot support to
test:///default.
Eric Blake (6):
snapshot: add additional filters when getting lists
snapshot: expose new flags in virsh
list: add virDomainListAllSnapshots API
list: use the new snapshot API in virsh when possible
list: provide python bindings for snapshots
list: provide RPC call for snapshots
daemon/remote.c | 126 ++++++++++++
include/libvirt/libvirt.h.in | 35 +++-
python/Makefile.am | 2 +
python/generator.py | 2 +
python/libvirt-override-api.xml | 16 +-
python/libvirt-override-virDomain.py | 11 +
python/libvirt-override-virDomainSnapshot.py | 11 +
python/libvirt-override.c | 90 +++++++++
src/conf/domain_conf.c | 53 ++++-
src/driver.h | 12 ++
src/libvirt.c | 281 ++++++++++++++++++++++----
src/libvirt_public.syms | 2 +
src/remote/remote_driver.c | 126 ++++++++++++
src/remote/remote_protocol.x | 26 ++-
src/remote_protocol-structs | 26 +++
tools/virsh.c | 83 +++++++-
tools/virsh.pod | 14 +-
17 files changed, 849 insertions(+), 67 deletions(-)
create mode 100644 python/libvirt-override-virDomain.py
create mode 100644 python/libvirt-override-virDomainSnapshot.py
--
1.7.10.2
12 years, 5 months
[libvirt] [PATCH 0/6] refactor 'virsh snapshot-list'
by Eric Blake
I'm in the middle of writing a patch series for virDomainListAllSnapshots;
this series is preliminary to that, and I'd like to get the review
started now.
The end result of this series is a net gain in lines of code, but a
much nicer framework for changing just one point in the code to use
new APIs and having everything else continue to work as before.
Eric Blake (6):
buf: support peeking at string contents
virsh: remove limits on tree listing
virsh: make tree listing more flexible
snapshot: virsh indentation cleanup
snapshot: new virsh function factored from snapshot-list
snapshot: use new virsh function for snapshot-list
src/libvirt_private.syms | 1 +
src/util/buf.c | 22 +-
src/util/buf.h | 1 +
tests/virbuftest.c | 8 +
tools/virsh.c | 735 +++++++++++++++++++++++++++-------------------
5 files changed, 466 insertions(+), 301 deletions(-)
--
1.7.10.2
12 years, 5 months
Re: [libvirt] [Qemu-devel] [PATCH v2 1/4] qapi: Convert getfd and closefd
by Luiz Capitulino
On Fri, 8 Jun 2012 11:42:56 -0400
Corey Bryant <coreyb(a)linux.vnet.ibm.com> wrote:
> v2:
> - Convert getfd and closefd to QAPI (lcapitulino(a)redhat.com)
> - Remove changes that returned fd from getfd (lcapitulino(a)redhat.com)
> - Wrap hmp_* functions around qmp_* functions (kwolf(a)redhat.com)
> - Move hmp_* functions to hmp.c (lcapitulino(a)redhat.com)
> - Drop .user_print lines (lcapitulino(a)redhat.com)
> - Use 'cmd' instead of 'cmd_new' for HMP (lcapitulino(a)redhat.com)
> - Change QMP command existance back to 0.14 (lcapitulino(a)redhat.com)
Btw, having the changelog like this is not nice because it becomes part
of the history. It's better to move it after the '---' line, so that
git ignores it.
>
> Signed-off-by: Corey Bryant <coreyb(a)linux.vnet.ibm.com>
> ---
> hmp-commands.hx | 6 ++----
> hmp.c | 18 ++++++++++++++++++
> hmp.h | 2 ++
> monitor.c | 34 ++++++++++++++++------------------
> qapi-schema.json | 29 +++++++++++++++++++++++++++++
> qmp-commands.hx | 6 ++----
> 6 files changed, 69 insertions(+), 26 deletions(-)
>
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index f5d9d91..eea8b32 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -1236,8 +1236,7 @@ ETEXI
> .args_type = "fdname:s",
> .params = "getfd name",
> .help = "receive a file descriptor via SCM rights and assign it a name",
> - .user_print = monitor_user_noop,
> - .mhandler.cmd_new = do_getfd,
> + .mhandler.cmd = hmp_getfd,
> },
>
> STEXI
> @@ -1253,8 +1252,7 @@ ETEXI
> .args_type = "fdname:s",
> .params = "closefd name",
> .help = "close a file descriptor previously passed via SCM rights",
> - .user_print = monitor_user_noop,
> - .mhandler.cmd_new = do_closefd,
> + .mhandler.cmd = hmp_closefd,
> },
>
> STEXI
> diff --git a/hmp.c b/hmp.c
> index 2ce8cb9..6241856 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -999,3 +999,21 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict)
> qmp_netdev_del(id, &err);
> hmp_handle_error(mon, &err);
> }
> +
> +void hmp_getfd(Monitor *mon, const QDict *qdict)
> +{
> + const char *fdname = qdict_get_str(qdict, "fdname");
> + Error *errp = NULL;
> +
> + qmp_getfd(fdname, &errp);
> + hmp_handle_error(mon, &errp);
> +}
> +
> +void hmp_closefd(Monitor *mon, const QDict *qdict)
> +{
> + const char *fdname = qdict_get_str(qdict, "fdname");
> + Error *errp = NULL;
> +
> + qmp_closefd(fdname, &errp);
> + hmp_handle_error(mon, &errp);
> +}
> diff --git a/hmp.h b/hmp.h
> index 79d138d..8d2b0d7 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -64,5 +64,7 @@ void hmp_device_del(Monitor *mon, const QDict *qdict);
> void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict);
> void hmp_netdev_add(Monitor *mon, const QDict *qdict);
> void hmp_netdev_del(Monitor *mon, const QDict *qdict);
> +void hmp_getfd(Monitor *mon, const QDict *qdict);
> +void hmp_closefd(Monitor *mon, const QDict *qdict);
>
> #endif
> diff --git a/monitor.c b/monitor.c
> index a3bc2c7..4c53cb6 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -2182,48 +2182,46 @@ static void do_inject_mce(Monitor *mon, const QDict *qdict)
> }
> #endif
>
> -static int do_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data)
> +void qmp_getfd(const char *fdname, Error **errp)
> {
> - const char *fdname = qdict_get_str(qdict, "fdname");
> mon_fd_t *monfd;
> int fd;
>
> - fd = qemu_chr_fe_get_msgfd(mon->chr);
> + fd = qemu_chr_fe_get_msgfd(cur_mon->chr);
> if (fd == -1) {
> - qerror_report(QERR_FD_NOT_SUPPLIED);
> - return -1;
> + error_set(errp, QERR_FD_NOT_SUPPLIED);
> + return;
> }
>
> if (qemu_isdigit(fdname[0])) {
> - qerror_report(QERR_INVALID_PARAMETER_VALUE, "fdname",
> - "a name not starting with a digit");
> - return -1;
> + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdname",
> + "a name not starting with a digit");
> + return;
> }
>
> - QLIST_FOREACH(monfd, &mon->fds, next) {
> + QLIST_FOREACH(monfd, &cur_mon->fds, next) {
> if (strcmp(monfd->name, fdname) != 0) {
> continue;
> }
>
> close(monfd->fd);
> monfd->fd = fd;
> - return 0;
> + return;
> }
>
> monfd = g_malloc0(sizeof(mon_fd_t));
> monfd->name = g_strdup(fdname);
> monfd->fd = fd;
>
> - QLIST_INSERT_HEAD(&mon->fds, monfd, next);
> - return 0;
> + QLIST_INSERT_HEAD(&cur_mon->fds, monfd, next);
> + return;
> }
>
> -static int do_closefd(Monitor *mon, const QDict *qdict, QObject **ret_data)
> +void qmp_closefd(const char *fdname, Error **errp)
> {
> - const char *fdname = qdict_get_str(qdict, "fdname");
> mon_fd_t *monfd;
>
> - QLIST_FOREACH(monfd, &mon->fds, next) {
> + QLIST_FOREACH(monfd, &cur_mon->fds, next) {
> if (strcmp(monfd->name, fdname) != 0) {
> continue;
> }
> @@ -2232,11 +2230,11 @@ static int do_closefd(Monitor *mon, const QDict *qdict, QObject **ret_data)
> close(monfd->fd);
> g_free(monfd->name);
> g_free(monfd);
> - return 0;
> + return;
> }
>
> - qerror_report(QERR_FD_NOT_FOUND, fdname);
> - return -1;
> + error_set(errp, QERR_FD_NOT_FOUND, fdname);
> + return;
> }
>
> static void do_loadvm(Monitor *mon, const QDict *qdict)
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 3b6e346..6be1d90 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -1862,3 +1862,32 @@
> # Since: 0.14.0
> ##
> { 'command': 'netdev_del', 'data': {'id': 'str'} }
> +
> +##
> +# @getfd:
> +#
> +# Receive a file descriptor via SCM rights and assign it a name
> +#
> +# @fdname: file descriptor name
> +#
> +# Returns: Nothing on success
> +# If file descriptor was not received, FdNotSupplied
> +# If @fdname is not valid, InvalidParameterType
> +#
> +# Since: 0.14.0
> +##
> +{ 'command': 'getfd', 'data': {'fdname': 'str'} }
> +
> +##
> +# @closefd:
> +#
> +# Close a file descriptor previously passed via SCM rights
> +#
> +# @fdname: file descriptor name
> +#
> +# Returns: Nothing on success
> +# If @fdname is not found, FdNotFound
> +#
> +# Since: 0.14.0
> +##
> +{ 'command': 'closefd', 'data': {'fdname': 'str'} }
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index 2e1a38e..f8c0f68 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -873,8 +873,7 @@ EQMP
> .args_type = "fdname:s",
> .params = "getfd name",
> .help = "receive a file descriptor via SCM rights and assign it a name",
> - .user_print = monitor_user_noop,
> - .mhandler.cmd_new = do_getfd,
> + .mhandler.cmd_new = qmp_marshal_input_getfd,
> },
>
> SQMP
> @@ -899,8 +898,7 @@ EQMP
> .args_type = "fdname:s",
> .params = "closefd name",
> .help = "close a file descriptor previously passed via SCM rights",
> - .user_print = monitor_user_noop,
> - .mhandler.cmd_new = do_closefd,
> + .mhandler.cmd_new = qmp_marshal_input_closefd,
> },
>
> SQMP
12 years, 5 months
Re: [libvirt] [Qemu-devel] [PATCH v2 1/4] qapi: Convert getfd and closefd
by Luiz Capitulino
On Fri, 8 Jun 2012 11:42:56 -0400
Corey Bryant <coreyb(a)linux.vnet.ibm.com> wrote:
> v2:
> - Convert getfd and closefd to QAPI (lcapitulino(a)redhat.com)
> - Remove changes that returned fd from getfd (lcapitulino(a)redhat.com)
> - Wrap hmp_* functions around qmp_* functions (kwolf(a)redhat.com)
> - Move hmp_* functions to hmp.c (lcapitulino(a)redhat.com)
> - Drop .user_print lines (lcapitulino(a)redhat.com)
> - Use 'cmd' instead of 'cmd_new' for HMP (lcapitulino(a)redhat.com)
> - Change QMP command existance back to 0.14 (lcapitulino(a)redhat.com)
>
> Signed-off-by: Corey Bryant <coreyb(a)linux.vnet.ibm.com>
> ---
> hmp-commands.hx | 6 ++----
> hmp.c | 18 ++++++++++++++++++
> hmp.h | 2 ++
> monitor.c | 34 ++++++++++++++++------------------
> qapi-schema.json | 29 +++++++++++++++++++++++++++++
> qmp-commands.hx | 6 ++----
> 6 files changed, 69 insertions(+), 26 deletions(-)
>
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index f5d9d91..eea8b32 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -1236,8 +1236,7 @@ ETEXI
> .args_type = "fdname:s",
> .params = "getfd name",
> .help = "receive a file descriptor via SCM rights and assign it a name",
> - .user_print = monitor_user_noop,
> - .mhandler.cmd_new = do_getfd,
> + .mhandler.cmd = hmp_getfd,
> },
>
> STEXI
> @@ -1253,8 +1252,7 @@ ETEXI
> .args_type = "fdname:s",
> .params = "closefd name",
> .help = "close a file descriptor previously passed via SCM rights",
> - .user_print = monitor_user_noop,
> - .mhandler.cmd_new = do_closefd,
> + .mhandler.cmd = hmp_closefd,
> },
>
> STEXI
> diff --git a/hmp.c b/hmp.c
> index 2ce8cb9..6241856 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -999,3 +999,21 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict)
> qmp_netdev_del(id, &err);
> hmp_handle_error(mon, &err);
> }
> +
> +void hmp_getfd(Monitor *mon, const QDict *qdict)
> +{
> + const char *fdname = qdict_get_str(qdict, "fdname");
> + Error *errp = NULL;
> +
> + qmp_getfd(fdname, &errp);
> + hmp_handle_error(mon, &errp);
> +}
> +
> +void hmp_closefd(Monitor *mon, const QDict *qdict)
> +{
> + const char *fdname = qdict_get_str(qdict, "fdname");
> + Error *errp = NULL;
> +
> + qmp_closefd(fdname, &errp);
> + hmp_handle_error(mon, &errp);
> +}
> diff --git a/hmp.h b/hmp.h
> index 79d138d..8d2b0d7 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -64,5 +64,7 @@ void hmp_device_del(Monitor *mon, const QDict *qdict);
> void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict);
> void hmp_netdev_add(Monitor *mon, const QDict *qdict);
> void hmp_netdev_del(Monitor *mon, const QDict *qdict);
> +void hmp_getfd(Monitor *mon, const QDict *qdict);
> +void hmp_closefd(Monitor *mon, const QDict *qdict);
>
> #endif
> diff --git a/monitor.c b/monitor.c
> index a3bc2c7..4c53cb6 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -2182,48 +2182,46 @@ static void do_inject_mce(Monitor *mon, const QDict *qdict)
> }
> #endif
>
> -static int do_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data)
> +void qmp_getfd(const char *fdname, Error **errp)
> {
> - const char *fdname = qdict_get_str(qdict, "fdname");
> mon_fd_t *monfd;
> int fd;
>
> - fd = qemu_chr_fe_get_msgfd(mon->chr);
> + fd = qemu_chr_fe_get_msgfd(cur_mon->chr);
> if (fd == -1) {
> - qerror_report(QERR_FD_NOT_SUPPLIED);
> - return -1;
> + error_set(errp, QERR_FD_NOT_SUPPLIED);
> + return;
> }
>
> if (qemu_isdigit(fdname[0])) {
> - qerror_report(QERR_INVALID_PARAMETER_VALUE, "fdname",
> - "a name not starting with a digit");
> - return -1;
> + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdname",
> + "a name not starting with a digit");
> + return;
> }
>
> - QLIST_FOREACH(monfd, &mon->fds, next) {
> + QLIST_FOREACH(monfd, &cur_mon->fds, next) {
> if (strcmp(monfd->name, fdname) != 0) {
> continue;
> }
>
> close(monfd->fd);
> monfd->fd = fd;
> - return 0;
> + return;
> }
>
> monfd = g_malloc0(sizeof(mon_fd_t));
> monfd->name = g_strdup(fdname);
> monfd->fd = fd;
>
> - QLIST_INSERT_HEAD(&mon->fds, monfd, next);
> - return 0;
> + QLIST_INSERT_HEAD(&cur_mon->fds, monfd, next);
> + return;
You have a few of this kind of gratuitous return, please drop 'em.
> }
>
> -static int do_closefd(Monitor *mon, const QDict *qdict, QObject **ret_data)
> +void qmp_closefd(const char *fdname, Error **errp)
> {
> - const char *fdname = qdict_get_str(qdict, "fdname");
> mon_fd_t *monfd;
>
> - QLIST_FOREACH(monfd, &mon->fds, next) {
> + QLIST_FOREACH(monfd, &cur_mon->fds, next) {
> if (strcmp(monfd->name, fdname) != 0) {
> continue;
> }
> @@ -2232,11 +2230,11 @@ static int do_closefd(Monitor *mon, const QDict *qdict, QObject **ret_data)
> close(monfd->fd);
> g_free(monfd->name);
> g_free(monfd);
> - return 0;
> + return;
> }
>
> - qerror_report(QERR_FD_NOT_FOUND, fdname);
> - return -1;
> + error_set(errp, QERR_FD_NOT_FOUND, fdname);
> + return;
> }
>
> static void do_loadvm(Monitor *mon, const QDict *qdict)
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 3b6e346..6be1d90 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -1862,3 +1862,32 @@
> # Since: 0.14.0
> ##
> { 'command': 'netdev_del', 'data': {'id': 'str'} }
> +
> +##
> +# @getfd:
> +#
> +# Receive a file descriptor via SCM rights and assign it a name
> +#
> +# @fdname: file descriptor name
> +#
> +# Returns: Nothing on success
> +# If file descriptor was not received, FdNotSupplied
> +# If @fdname is not valid, InvalidParameterType
Please, add a note explaining that getfd automatically closes fds if
fdname matches an existing name.
Otherwise this conversion looks very good to me.
> +#
> +# Since: 0.14.0
> +##
> +{ 'command': 'getfd', 'data': {'fdname': 'str'} }
> +
> +##
> +# @closefd:
> +#
> +# Close a file descriptor previously passed via SCM rights
> +#
> +# @fdname: file descriptor name
> +#
> +# Returns: Nothing on success
> +# If @fdname is not found, FdNotFound
> +#
> +# Since: 0.14.0
> +##
> +{ 'command': 'closefd', 'data': {'fdname': 'str'} }
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index 2e1a38e..f8c0f68 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -873,8 +873,7 @@ EQMP
> .args_type = "fdname:s",
> .params = "getfd name",
> .help = "receive a file descriptor via SCM rights and assign it a name",
> - .user_print = monitor_user_noop,
> - .mhandler.cmd_new = do_getfd,
> + .mhandler.cmd_new = qmp_marshal_input_getfd,
> },
>
> SQMP
> @@ -899,8 +898,7 @@ EQMP
> .args_type = "fdname:s",
> .params = "closefd name",
> .help = "close a file descriptor previously passed via SCM rights",
> - .user_print = monitor_user_noop,
> - .mhandler.cmd_new = do_closefd,
> + .mhandler.cmd_new = qmp_marshal_input_closefd,
> },
>
> SQMP
12 years, 5 months
[libvirt] [PATCH] network: fully support/use VIR_NETWORK_XML_INACTIVE flag
by Laine Stump
commit 52d064f42dbc857f4096dc60c0335395ffac73aa added
VIR_NETWORK_XML_INACTIVE in order to allow suppressing the
auto-generated list of VFs in network definitions, and a --inactive
flag to virsh net-dumpxml to take advantage of the flag. However, it
missed out on two oppurtunities:
1) Use INACTIVE to get the current config of the network as it
exists on disk, rather than the currently active config.
2) Add INACTIVE to the flags used for the virsh net-edit command, so
that it won't include the forward-pool interfaces that were
autogenerated, and so that a re-edit of the network prior to
restarting it will show any other edits made since the last restart
of the network. (prior to this patch, if you edited a network a 2nd
time without restarting, all of the previous edits would magically
disappear).
In order to fit with the new #define-based generic edit function in
virsh.c, a new function vshNetworkGetXMLDesc() was added. This
function first tries to call virNetworkGetXMLDesc with the INACTIVE
flag added, then retries without if the first attempt fails (in the
manner expected when the server doesn't support it).,
---
src/network/bridge_driver.c | 8 +++++++-
tools/virsh.c | 20 ++++++++++++++++++--
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 5f3132c..79d3010 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -2533,6 +2533,7 @@ static char *networkGetXMLDesc(virNetworkPtr net,
{
struct network_driver *driver = net->conn->networkPrivateData;
virNetworkObjPtr network;
+ virNetworkDefPtr def;
char *ret = NULL;
virCheckFlags(VIR_NETWORK_XML_INACTIVE, NULL);
@@ -2547,7 +2548,12 @@ static char *networkGetXMLDesc(virNetworkPtr net,
goto cleanup;
}
- ret = virNetworkDefFormat(network->def, flags);
+ if ((flags & VIR_NETWORK_XML_INACTIVE) && network->newDef)
+ def = network->newDef;
+ else
+ def = network->def;
+
+ ret = virNetworkDefFormat(def, flags);
cleanup:
if (network)
diff --git a/tools/virsh.c b/tools/virsh.c
index 0453b95..1c9e44a 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -15806,13 +15806,29 @@ static const vshCmdOptDef opts_network_edit[] = {
{NULL, 0, 0, NULL}
};
+static char *vshNetworkGetXMLDesc(virNetworkPtr network)
+{
+ unsigned int flags = VIR_NETWORK_XML_INACTIVE;
+ char *doc = virNetworkGetXMLDesc(network, flags);
+
+ if (!doc && last_error->code == VIR_ERR_INVALID_ARG) {
+ /* The server side libvirt doesn't support
+ * VIR_NETWORK_XML_INACTIVE, so retry without it.
+ */
+ virFreeError(last_error);
+ last_error = NULL;
+ flags &= ~VIR_NETWORK_XML_INACTIVE;
+ doc = virNetworkGetXMLDesc(network, flags);
+ }
+ return doc;
+}
+
static bool
cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
{
bool ret = false;
virNetworkPtr network = NULL;
virNetworkPtr network_edited = NULL;
- unsigned int flags = 0;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
@@ -15821,7 +15837,7 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
if (network == NULL)
goto cleanup;
-#define EDIT_GET_XML virNetworkGetXMLDesc(network, flags)
+#define EDIT_GET_XML vshNetworkGetXMLDesc(network)
#define EDIT_NOT_CHANGED \
vshPrint(ctl, _("Network %s XML configuration not changed.\n"), \
virNetworkGetName (network)); \
--
1.7.10.2
12 years, 5 months
[libvirt] [PATCH] storage backend: Add sheepdog support
by Sebastian Wiedenroth
Signed-off-by: Sebastian Wiedenroth <wiedi(a)frubar.net>
---
This patch adds support for sheepdog pools and volumes.
Thanks go to Frank Spijkerman who started the initial work on this
and Wido den Hollander for his RBD support on which this is partly based.
configure.ac | 23 ++
docs/drivers.html.in | 1 +
docs/schemas/storagepool.rng | 17 ++
docs/schemas/storagevol.rng | 3 +-
docs/storage.html.in | 62 +++++
po/POTFILES.in | 1 +
src/Makefile.am | 8 +
src/conf/storage_conf.c | 17 +-
src/conf/storage_conf.h | 1 +
src/storage/storage_backend.c | 6 +
src/storage/storage_backend_sheepdog.c | 323 +++++++++++++++++++++++++
src/storage/storage_backend_sheepdog.h | 39 +++
tests/Makefile.am | 13 +
tests/storagebackendsheepdogtest.c | 196 +++++++++++++++
tests/storagepoolxml2xmlin/pool-sheepdog.xml | 8 +
tests/storagepoolxml2xmlout/pool-sheepdog.xml | 11 +
tests/storagepoolxml2xmltest.c | 1 +
tests/storagevolxml2xmlin/vol-sheepdog.xml | 10 +
tests/storagevolxml2xmlout/vol-sheepdog.xml | 17 ++
tests/storagevolxml2xmltest.c | 1 +
tools/virsh.c | 3 +
21 files changed, 757 insertions(+), 4 deletions(-)
create mode 100644 src/storage/storage_backend_sheepdog.c
create mode 100644 src/storage/storage_backend_sheepdog.h
create mode 100644 tests/storagebackendsheepdogtest.c
create mode 100644 tests/storagepoolxml2xmlin/pool-sheepdog.xml
create mode 100644 tests/storagepoolxml2xmlout/pool-sheepdog.xml
create mode 100644 tests/storagevolxml2xmlin/vol-sheepdog.xml
create mode 100644 tests/storagevolxml2xmlout/vol-sheepdog.xml
diff --git a/configure.ac b/configure.ac
index dda764d..774a9dd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1807,6 +1807,8 @@ AC_ARG_WITH([storage-disk],
AC_HELP_STRING([--with-storage-disk], [with GPartd Disk backend for the storage driver @<:@default=check@:>@]),[],[with_storage_disk=check])
AC_ARG_WITH([storage-rbd],
AC_HELP_STRING([--with-storage-rbd], [with RADOS Block Device backend for the storage driver @<:@default=check@:>@]),[],[with_storage_rbd=check])
+AC_ARG_WITH([storage-sheepdog],
+ AC_HELP_STRING([--with-storage-sheepdog], [with Sheepdog backend for the storage driver @<:@default=check@:>@]),[],[with_storage_sheepdog=check])
if test "$with_libvirtd" = "no"; then
with_storage_dir=no
@@ -1817,6 +1819,7 @@ if test "$with_libvirtd" = "no"; then
with_storage_mpath=no
with_storage_disk=no
with_storage_rbd=no
+ with_storage_sheepdog=no
fi
if test "$with_storage_dir" = "yes" ; then
AC_DEFINE_UNQUOTED([WITH_STORAGE_DIR], 1, [whether directory backend for storage driver is enabled])
@@ -1991,6 +1994,25 @@ fi
AM_CONDITIONAL([WITH_STORAGE_RBD], [test "$with_storage_rbd" = "yes"])
AC_SUBST([LIBRBD_LIBS])
+if test "$with_storage_sheepdog" = "yes" || test "$with_storage_sheepdog" = "check"; then
+ AC_PATH_PROG([COLLIE], [collie], [], [$PATH:/sbin:/usr/sbin])
+
+ if test "$with_storage_sheepdog" = "yes" ; then
+ if test -z "$COLLIE" ; then AC_MSG_ERROR([We need collie for Sheepdog storage driver]) ; fi
+ else
+ if test -z "$COLLIE" ; then with_storage_sheepdog=no ; fi
+
+ if test "$with_storage_sheepdog" = "check" ; then with_storage_sheepdog=yes ; fi
+ fi
+
+ if test "$with_storage_sheepdog" = "yes" ; then
+ AC_DEFINE_UNQUOTED([WITH_STORAGE_SHEEPDOG], 1, [whether Sheepdog backend for storage driver is enabled])
+ AC_DEFINE_UNQUOTED([COLLIE],["$COLLIE"],[Location of collie program])
+ fi
+fi
+AM_CONDITIONAL([WITH_STORAGE_SHEEPDOG], [test "$with_storage_sheepdog" = "yes"])
+
+
LIBPARTED_CFLAGS=
LIBPARTED_LIBS=
if test "$with_storage_disk" = "yes" ||
@@ -2806,6 +2828,7 @@ AC_MSG_NOTICE([ SCSI: $with_storage_scsi])
AC_MSG_NOTICE([ mpath: $with_storage_mpath])
AC_MSG_NOTICE([ Disk: $with_storage_disk])
AC_MSG_NOTICE([ RBD: $with_storage_rbd])
+AC_MSG_NOTICE([Sheepdog: $with_storage_sheepdog])
AC_MSG_NOTICE([])
AC_MSG_NOTICE([Security Drivers])
AC_MSG_NOTICE([])
diff --git a/docs/drivers.html.in b/docs/drivers.html.in
index 8ad2c33..90b6196 100644
--- a/docs/drivers.html.in
+++ b/docs/drivers.html.in
@@ -43,6 +43,7 @@
<li><strong><a href="storage.html#StorageBackendSCSI">SCSI backend</a></strong></li>
<li><strong><a href="storage.html#StorageBackendMultipath">Multipath backend</a></strong></li>
<li><strong><a href="storage.html#StorageBackendRBD">RBD (RADOS Block Device) backend</a></strong></li>
+ <li><strong><a href="storage.html#StorageBackendSheepdog">Sheepdog backend</a></strong></li>
</ul>
</body>
</html>
diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng
index 75b6b51..039798a 100644
--- a/docs/schemas/storagepool.rng
+++ b/docs/schemas/storagepool.rng
@@ -20,6 +20,7 @@
<ref name='poolscsi'/>
<ref name='poolmpath'/>
<ref name='poolrbd'/>
+ <ref name='poolsheepdog'/>
</choice>
</element>
</define>
@@ -115,6 +116,15 @@
<ref name='sourcerbd'/>
</define>
+ <define name='poolsheepdog'>
+ <attribute name='type'>
+ <value>sheepdog</value>
+ </attribute>
+ <ref name='commonmetadata'/>
+ <ref name='sizing'/>
+ <ref name='sourcesheepdog'/>
+ </define>
+
<define name='sourceinfovendor'>
<optional>
<element name='vendor'>
@@ -496,6 +506,13 @@
</element>
</define>
+ <define name='sourcesheepdog'>
+ <element name='source'>
+ <ref name='sourceinfohost'/>
+ <ref name='sourceinfoname'/>
+ </element>
+ </define>
+
<define name='name'>
<data type='string'>
<param name="pattern">[a-zA-Z0-9_\+\-]+</param>
diff --git a/docs/schemas/storagevol.rng b/docs/schemas/storagevol.rng
index 8edb877..83148ca 100644
--- a/docs/schemas/storagevol.rng
+++ b/docs/schemas/storagevol.rng
@@ -67,7 +67,7 @@
<element name='target'>
<optional>
<element name='path'>
- <ref name='absFilePath'/>
+ <data type='anyURI'/>
</element>
</optional>
<ref name='format'/>
@@ -144,6 +144,7 @@
<define name='formatfile'>
<choice>
+ <value>unknown</value>
<value>raw</value>
<value>dir</value>
<value>bochs</value>
diff --git a/docs/storage.html.in b/docs/storage.html.in
index b3484e8..8730164 100644
--- a/docs/storage.html.in
+++ b/docs/storage.html.in
@@ -110,6 +110,9 @@
<li>
<a href="#StorageBackendRBD">RBD (RADOS Block Device) backend</a>
</li>
+ <li>
+ <a href="#StorageBackendSheepdog">Sheepdog backend</a>
+ </li>
</ul>
<h2><a name="StorageBackendDir">Directory pool</a></h2>
@@ -565,5 +568,64 @@
The RBD pool does not use the volume format type element.
</p>
+ <h2><a name="StorageBackendSheepdog">Sheepdog pools</a></h2>
+ <p>
+ This provides a pool based on a Sheepdog Cluster.
+ Sheepdog is a distributed storage system for QEMU/KVM.
+ It provides highly available block level storage volumes that
+ can be attached to QEMU/KVM virtual machines.
+
+ The cluster must already be formated.
+
+ <span class="since">Since 0.9.13</span>
+ </p>
+
+ <h3>Example pool input</h3>
+ <pre>
+ <pool type="sheepdog">
+ <name>mysheeppool</name>
+ <source>
+ <name>mysheeppool</name>
+ <host name='localhost' port='7000'/>
+ </source>
+ </pool></pre>
+
+ <h3>Example volume output</h3>
+ <pre>
+ <volume>
+ <name>myvol</name>
+ <key>sheep/myvol</key>
+ <source>
+ </source>
+ <capacity unit='bytes'>53687091200</capacity>
+ <allocation unit='bytes'>53687091200</allocation>
+ <target>
+ <path>sheepdog:myvol</path>
+ <format type='unknown'/>
+ <permissions>
+ <mode>00</mode>
+ <owner>0</owner>
+ <group>0</group>
+ </permissions>
+ </target>
+ </volume></pre>
+
+ <h3>Example disk attachement</h3>
+ <p>Sheepdog images can be attached to Qemu guests.
+ Information about attaching a Sheepdog image to a
+ guest can be found
+ at the <a href="formatdomain.html#elementsDisks">format domain</a>
+ page.</p>
+
+ <h3>Valid pool format types</h3>
+ <p>
+ The Sheepdog pool does not use the pool format type element.
+ </p>
+
+ <h3>Valid volume format types</h3>
+ <p>
+ The Sheepdog pool does not use the volume format type element.
+ </p>
+
</body>
</html>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 31246f7..33a2ace 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -108,6 +108,7 @@ src/storage/storage_backend_logical.c
src/storage/storage_backend_mpath.c
src/storage/storage_backend_rbd.c
src/storage/storage_backend_scsi.c
+src/storage/storage_backend_sheepdog.c
src/storage/storage_driver.c
src/test/test_driver.c
src/uml/uml_conf.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 60f5442..82238b9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -506,6 +506,9 @@ STORAGE_DRIVER_DISK_SOURCES = \
STORAGE_DRIVER_RBD_SOURCES = \
storage/storage_backend_rbd.h storage/storage_backend_rbd.c
+STORAGE_DRIVER_SHEEPDOG_SOURCES = \
+ storage/storage_backend_sheepdog.h storage/storage_backend_sheepdog.c
+
STORAGE_HELPER_DISK_SOURCES = \
storage/parthelper.c
@@ -1009,6 +1012,10 @@ libvirt_driver_storage_la_SOURCES += $(STORAGE_DRIVER_RBD_SOURCES)
libvirt_driver_storage_la_LIBADD += $(LIBRBD_LIBS)
endif
+if WITH_STORAGE_SHEEPDOG
+libvirt_driver_storage_la_SOURCES += $(STORAGE_DRIVER_SHEEPDOG_SOURCES)
+endif
+
if WITH_NODE_DEVICES
# Needed to keep automake quiet about conditionals
if WITH_DRIVER_MODULES
@@ -1107,6 +1114,7 @@ EXTRA_DIST += \
$(STORAGE_DRIVER_MPATH_SOURCES) \
$(STORAGE_DRIVER_DISK_SOURCES) \
$(STORAGE_DRIVER_RBD_SOURCES) \
+ $(STORAGE_DRIVER_SHEEPDOG_SOURCES) \
$(NODE_DEVICE_DRIVER_SOURCES) \
$(NODE_DEVICE_DRIVER_HAL_SOURCES) \
$(NODE_DEVICE_DRIVER_UDEV_SOURCES) \
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index bf4567f..8ca6b1e 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -52,7 +52,7 @@ VIR_ENUM_IMPL(virStoragePool,
VIR_STORAGE_POOL_LAST,
"dir", "fs", "netfs",
"logical", "disk", "iscsi",
- "scsi", "mpath", "rbd")
+ "scsi", "mpath", "rbd", "sheepdog")
VIR_ENUM_IMPL(virStoragePoolFormatFileSystem,
VIR_STORAGE_POOL_FS_LAST,
@@ -206,6 +206,17 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
.formatToString = virStoragePoolFormatDiskTypeToString,
}
},
+ { .poolType = VIR_STORAGE_POOL_SHEEPDOG,
+ .poolOptions = {
+ .flags = (VIR_STORAGE_POOL_SOURCE_HOST |
+ VIR_STORAGE_POOL_SOURCE_NETWORK |
+ VIR_STORAGE_POOL_SOURCE_NAME),
+ },
+ .volOptions = {
+ .defaultFormat = VIR_STORAGE_FILE_RAW,
+ .formatToString = virStoragePoolFormatDiskTypeToString,
+ }
+ },
{ .poolType = VIR_STORAGE_POOL_MPATH,
.volOptions = {
.formatToString = virStoragePoolFormatDiskTypeToString,
@@ -1011,9 +1022,9 @@ virStoragePoolDefFormat(virStoragePoolDefPtr def) {
if (virStoragePoolSourceFormat(&buf, options, &def->source) < 0)
goto cleanup;
- /* RBD devices are not local block devs nor files, so it doesn't
+ /* RBD and Sheepdog devices are not local block devs nor files, so it doesn't
* have a target */
- if (def->type != VIR_STORAGE_POOL_RBD) {
+ if (def->type != VIR_STORAGE_POOL_RBD && def->type != VIR_STORAGE_POOL_SHEEPDOG) {
virBufferAddLit(&buf," <target>\n");
if (def->target.path)
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 5733b57..dcf976f 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -121,6 +121,7 @@ enum virStoragePoolType {
VIR_STORAGE_POOL_SCSI, /* SCSI HBA */
VIR_STORAGE_POOL_MPATH, /* Multipath devices */
VIR_STORAGE_POOL_RBD, /* RADOS Block Device */
+ VIR_STORAGE_POOL_SHEEPDOG, /* Sheepdog device */
VIR_STORAGE_POOL_LAST,
};
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index e2e9b51..93964d6 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -80,6 +80,9 @@
#if WITH_STORAGE_RBD
# include "storage_backend_rbd.h"
#endif
+#if WITH_STORAGE_SHEEPDOG
+# include "storage_backend_sheepdog.h"
+#endif
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -109,6 +112,9 @@ static virStorageBackendPtr backends[] = {
#if WITH_STORAGE_RBD
&virStorageBackendRBD,
#endif
+#if WITH_STORAGE_SHEEPDOG
+ &virStorageBackendSheepdog,
+#endif
NULL
};
diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c
new file mode 100644
index 0000000..b003856
--- /dev/null
+++ b/src/storage/storage_backend_sheepdog.c
@@ -0,0 +1,323 @@
+/*
+ * storage_backend_sheepdog.c: storage backend for Sheepdog handling
+ *
+ * Copyright (C) 2012 Wido den Hollander
+ * Copyright (C) 2012 Frank Spijkerman
+ * Copyright (C) 2012 Sebastian Wiedenroth
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Wido den Hollander <wido(a)widodh.nl>
+ * Frank Spijkerman <frank.spijkerman(a)avira.com>
+ * Sebastian Wiedenroth <sebastian.wiedenroth(a)skylime.net>
+ */
+
+#include <config.h>
+
+#include "virterror_internal.h"
+#include "storage_backend_sheepdog.h"
+#include "storage_conf.h"
+#include "util/command.h"
+#include "util.h"
+#include "memory.h"
+#include "logging.h"
+
+#define VIR_FROM_THIS VIR_FROM_STORAGE
+
+static int virStorageBackendSheepdogRefreshVol(virConnectPtr conn,
+ virStoragePoolObjPtr pool,
+ virStorageVolDefPtr vol);
+
+void virStorageBackendSheepdogAddHostArg(virCommandPtr cmd,
+ virStoragePoolObjPtr pool);
+
+int
+virStorageBackendSheepdogParseNodeInfo(virStoragePoolDefPtr pool,
+ char *output)
+{
+ /* example output:
+ * 0 15245667872 117571104 0%
+ * Total 15245667872 117571104 0% 20972341
+ */
+
+ const char *p, *next;
+
+ pool->allocation = pool->capacity = pool->available = 0;
+
+ p = output;
+ do {
+ char *end;
+
+ if ((next = strchr(p, '\n')))
+ ++next;
+ else
+ return -1;
+
+ if (!STRPREFIX(p, "Total "))
+ continue;
+
+ p = p + 6;
+
+ if (virStrToLong_ull(p, &end, 10, &pool->capacity) < 0)
+ return -1;
+
+ if ((p = end + 1) > next)
+ return -1;
+
+ if (virStrToLong_ull(p, &end, 10, &pool->allocation) < 0)
+ return -1;
+
+ pool->available = pool->capacity - pool->allocation;
+ return 0;
+
+ } while ((p = next));
+
+ return -1;
+}
+
+void virStorageBackendSheepdogAddHostArg(virCommandPtr cmd, virStoragePoolObjPtr pool)
+{
+ const char *address = "localhost";
+ int port = 7000;
+ if (pool->def->source.nhost > 0) {
+ if (pool->def->source.hosts[0].name != NULL) {
+ address = pool->def->source.hosts[0].name;
+ }
+ if (pool->def->source.hosts[0].port) {
+ port = pool->def->source.hosts[0].port;
+ }
+ }
+ virCommandAddArg(cmd, "-a");
+ virCommandAddArgFormat(cmd, "%s", address);
+ virCommandAddArg(cmd, "-p");
+ virCommandAddArgFormat(cmd, "%d", port);
+}
+
+
+static int
+virStorageBackendSheepdogRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virStoragePoolObjPtr pool)
+{
+ int ret;
+
+ char *output = NULL;
+
+ virCommandPtr cmd;
+
+ cmd = virCommandNew(COLLIE);
+ virCommandAddArgList(cmd, "node", "info", "-r", NULL);
+ virStorageBackendSheepdogAddHostArg(cmd, pool);
+ virCommandSetOutputBuffer(cmd, &output);
+ ret = virCommandRun(cmd, NULL);
+ if (ret == 0)
+ ret = virStorageBackendSheepdogParseNodeInfo(pool->def, output);
+
+ virCommandFree(cmd);
+ VIR_FREE(output);
+ return ret;
+}
+
+
+static int
+virStorageBackendSheepdogDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virStoragePoolObjPtr pool
+ ATTRIBUTE_UNUSED,
+ virStorageVolDefPtr vol,
+ unsigned int flags)
+{
+
+ if (flags & VIR_STORAGE_VOL_DELETE_ZEROED) {
+ VIR_WARN("%s", _("This storage backend does not supported zeroed removal of volumes"));
+ }
+
+ virCommandPtr cmd = virCommandNew(COLLIE);
+
+ virCommandAddArgList(cmd, "vdi", "delete", vol->name, NULL);
+ virStorageBackendSheepdogAddHostArg(cmd, pool);
+ int ret = virCommandRun(cmd, NULL);
+
+ virCommandFree(cmd);
+ return ret;
+}
+
+
+static int
+virStorageBackendSheepdogCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virStoragePoolObjPtr pool
+ ATTRIBUTE_UNUSED,
+ virStorageVolDefPtr vol)
+{
+
+ int ret;
+
+ if (vol->target.encryption != NULL) {
+ virStorageReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("storage pool does not support encrypted volumes"));
+ return -1;
+ }
+
+ virCommandPtr cmd = virCommandNew(COLLIE);
+
+ virCommandAddArgList(cmd, "vdi", "create", vol->name, NULL);
+ virCommandAddArgFormat(cmd, "%llu", vol->capacity);
+ virStorageBackendSheepdogAddHostArg(cmd, pool);
+ ret = virCommandRun(cmd, NULL);
+
+ virStorageBackendSheepdogRefreshVol(conn, pool, vol);
+
+ virCommandFree(cmd);
+ return ret;
+}
+
+
+int
+virStorageBackendSheepdogParseVdiList(virStorageVolDefPtr vol,
+ char *output)
+{
+ /* 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
+ */
+
+ int id;
+
+ const char *p, *next;
+
+ vol->allocation = vol->capacity = 0;
+
+ p = output;
+ do {
+ char *end;
+
+ if ((next = strchr(p, '\n')))
+ ++next;
+
+ /* ignore snapshots */
+ if (*p != '=')
+ continue;
+
+ /* skip space */
+ if (p + 2 < next) {
+ p += 2;
+ } else {
+ return -1;
+ }
+
+ /* skip name */
+ while (*p != '\0'
+ && (*p != ' ' || (*p == ' ' && (*(p - 1) == '\\'))))
+ ++p;
+
+ if (virStrToLong_i(p, &end, 10, &id) < 0)
+ return -1;
+
+ p = end + 1;
+
+ if (virStrToLong_ull(p, &end, 10, &vol->capacity) < 0)
+ return -1;
+
+ p = end + 1;
+
+ if (virStrToLong_ull(p, &end, 10, &vol->allocation) < 0)
+ return -1;
+
+ return 0;
+ } while ((p = next));
+
+ return -1;
+}
+
+static int
+virStorageBackendSheepdogRefreshVol(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virStoragePoolObjPtr pool
+ ATTRIBUTE_UNUSED,
+ virStorageVolDefPtr vol)
+{
+ int ret;
+
+ char *output = NULL;
+
+ virCommandPtr cmd;
+
+ cmd = virCommandNew(COLLIE);
+ virCommandAddArgList(cmd, "vdi", "list", vol->name, "-r", NULL);
+ virStorageBackendSheepdogAddHostArg(cmd, pool);
+ virCommandSetOutputBuffer(cmd, &output);
+ ret = virCommandRun(cmd, NULL);
+
+ if (ret < 0)
+ goto cleanup;
+
+ if ((ret = virStorageBackendSheepdogParseVdiList(vol, output)) < 0)
+ goto cleanup;
+
+ vol->type = VIR_STORAGE_VOL_NETWORK;
+
+ VIR_FREE(vol->key);
+ if (virAsprintf(&vol->key, "%s/%s",
+ pool->def->source.name, vol->name) == -1) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ VIR_FREE(vol->target.path);
+ if (virAsprintf(&vol->target.path, "sheepdog:%s", vol->name) == -1) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+
+
+cleanup:
+ virCommandFree(cmd);
+ return ret;
+}
+
+
+static int
+virStorageBackendSheepdogResizeVol(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virStoragePoolObjPtr pool
+ ATTRIBUTE_UNUSED,
+ virStorageVolDefPtr vol,
+ unsigned long long capacity,
+ unsigned int flags)
+{
+
+ virCheckFlags(0, -1);
+
+ virCommandPtr cmd = virCommandNew(COLLIE);
+
+ virCommandAddArgList(cmd, "vdi", "resize", vol->name, NULL);
+ virCommandAddArgFormat(cmd, "%llu", capacity);
+ virStorageBackendSheepdogAddHostArg(cmd, pool);
+ int ret = virCommandRun(cmd, NULL);
+
+ virCommandFree(cmd);
+ return ret;
+
+}
+
+
+
+virStorageBackend virStorageBackendSheepdog = {
+ .type = VIR_STORAGE_POOL_SHEEPDOG,
+
+ .refreshPool = virStorageBackendSheepdogRefreshPool,
+ .createVol = virStorageBackendSheepdogCreateVol,
+ .refreshVol = virStorageBackendSheepdogRefreshVol,
+ .deleteVol = virStorageBackendSheepdogDeleteVol,
+ .resizeVol = virStorageBackendSheepdogResizeVol,
+};
diff --git a/src/storage/storage_backend_sheepdog.h b/src/storage/storage_backend_sheepdog.h
new file mode 100644
index 0000000..51ef7a4
--- /dev/null
+++ b/src/storage/storage_backend_sheepdog.h
@@ -0,0 +1,39 @@
+/*
+ * storage_backend_sheepog.h: storage backend for Sheepdog handling
+ *
+ * Copyright (C) 2012 Wido den Hollander
+ * Copyright (C) 2012 Frank Spijkerman
+ * Copyright (C) 2012 Sebastian Wiedenroth
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Wido den Hollander <wido(a)widodh.nl>
+ * Frank Spijkerman <frank.spijkerman(a)avira.com>
+ * Sebastian Wiedenroth <sebastian.wiedenroth(a)skylime.net>
+ */
+
+#ifndef __VIR_STORAGE_BACKEND_SHEEPDOG_H__
+# define __VIR_STORAGE_BACKEND_SHEEPDOG_H__
+
+# include "storage_backend.h"
+
+int virStorageBackendSheepdogParseNodeInfo(virStoragePoolDefPtr pool,
+ char *output);
+int virStorageBackendSheepdogParseVdiList(virStorageVolDefPtr vol,
+ char *output);
+
+extern virStorageBackend virStorageBackendSheepdog;
+
+#endif /* __VIR_STORAGE_BACKEND_SHEEPDOG_H__ */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e3bd6d1..a466480 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -141,6 +141,10 @@ if WITH_NETWORK
test_programs += networkxml2argvtest
endif
+if WITH_STORAGE_SHEEPDOG
+test_programs += storagebackendsheepdogtest
+endif
+
test_programs += nwfilterxml2xmltest
test_programs += storagevolxml2xmltest storagepoolxml2xmltest
@@ -398,6 +402,15 @@ else
EXTRA_DIST += networkxml2argvtest.c
endif
+if WITH_STORAGE_SHEEPDOG
+storagebackendsheepdogtest_SOURCES = \
+ storagebackendsheepdogtest.c \
+ testutils.c testutils.h
+storagebackendsheepdogtest_LDADD = ../src/libvirt_driver_storage.la $(LDADDS)
+else
+EXTRA_DIST += storagebackendsheepdogtest.c
+endif
+
nwfilterxml2xmltest_SOURCES = \
nwfilterxml2xmltest.c \
testutils.c testutils.h
diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheepdogtest.c
new file mode 100644
index 0000000..a8f62a4
--- /dev/null
+++ b/tests/storagebackendsheepdogtest.c
@@ -0,0 +1,196 @@
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include "internal.h"
+#include "testutils.h"
+#include "storage/storage_backend_sheepdog.h"
+
+
+typedef struct {
+ const char *output;
+ int expected_return;
+ uint64_t expected_capacity;
+ uint64_t expected_allocation;
+} collie_test;
+
+
+static int
+test_node_info_parser(collie_test test, char *poolxml)
+{
+ int ret = -1;
+ char *output = NULL;
+ char *poolXmlData = NULL;
+ virStoragePoolDefPtr pool = NULL;
+
+ if (virtTestLoadFile(poolxml, &poolXmlData) < 0)
+ goto cleanup;
+
+ if (!(pool = virStoragePoolDefParseString(poolXmlData)))
+ goto cleanup;
+
+ output = strdup(test.output);
+ if(!output) {
+ goto cleanup;
+ }
+
+ ret = virStorageBackendSheepdogParseNodeInfo(pool, output);
+
+ if (ret != test.expected_return)
+ goto cleanup;
+
+ if (ret != 0) {
+ ret = 0;
+ goto cleanup;
+ }
+
+ if (pool->capacity == test.expected_capacity
+ && pool->allocation == test.expected_allocation)
+ ret = 0;
+
+ cleanup:
+ VIR_FREE(output);
+ VIR_FREE(poolXmlData);
+ virStoragePoolDefFree(pool);
+ return ret;
+}
+
+static int
+test_vdi_list_parser(collie_test test, char *poolxml, char *volxml)
+{
+ int ret = -1;
+ char *poolXmlData = NULL;
+ char *volXmlData = NULL;
+ char *output = NULL;
+ virStoragePoolDefPtr pool = NULL;
+ virStorageVolDefPtr vol = NULL;
+
+ if (virtTestLoadFile(poolxml, &poolXmlData) < 0)
+ goto cleanup;
+ if (virtTestLoadFile(volxml, &volXmlData) < 0)
+ goto cleanup;
+
+ if (!(pool = virStoragePoolDefParseString(poolXmlData)))
+ goto cleanup;
+
+ if (!(vol = virStorageVolDefParseString(pool, volXmlData)))
+ goto cleanup;
+
+ output = strdup(test.output);
+ if(!output) {
+ goto cleanup;
+ }
+
+ ret = virStorageBackendSheepdogParseVdiList(vol, output);
+
+
+ if (ret != test.expected_return)
+ goto cleanup;
+
+ if (ret != 0) {
+ ret = 0;
+ goto cleanup;
+ }
+
+ if (vol->capacity == test.expected_capacity
+ && vol->allocation == test.expected_allocation)
+ ret = 0;
+
+ cleanup:
+ VIR_FREE(output);
+ VIR_FREE(poolXmlData);
+ VIR_FREE(volXmlData);
+ virStoragePoolDefFree(pool);
+ virStorageVolDefFree(vol);
+ return ret;
+}
+
+
+static int
+mymain(void)
+{
+ int ret = -1;
+ char *poolxml = NULL;
+ 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}
+ };
+
+ 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},
+ {"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}
+ };
+
+ collie_test *test = node_info_tests;
+
+ if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/pool-sheepdog.xml",
+ abs_srcdir) < 0)
+ goto cleanup;
+
+ if (virAsprintf(&volxml, "%s/storagevolxml2xmlin/vol-sheepdog.xml",
+ abs_srcdir) < 0)
+ goto cleanup;
+
+ while (test->output != NULL) {
+ ret = test_node_info_parser(*test, poolxml);
+ virtTestResult("node_info_parser", ret, NULL);
+ ++test;
+ if (ret < 0)
+ return EXIT_FAILURE;
+ }
+
+ test = vdi_list_tests;
+
+ while (test->output != NULL) {
+ ret = test_vdi_list_parser(*test, poolxml, volxml);
+ virtTestResult("vdi_list_parser", ret, NULL);
+ ++test;
+ if (ret < 0)
+ return EXIT_FAILURE;
+ }
+
+ ret = 0;
+
+ cleanup:
+ VIR_FREE(poolxml);
+ VIR_FREE(volxml);
+ return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIRT_TEST_MAIN(mymain)
diff --git a/tests/storagepoolxml2xmlin/pool-sheepdog.xml b/tests/storagepoolxml2xmlin/pool-sheepdog.xml
new file mode 100644
index 0000000..1287047
--- /dev/null
+++ b/tests/storagepoolxml2xmlin/pool-sheepdog.xml
@@ -0,0 +1,8 @@
+<pool type='sheepdog'>
+ <name>sheepdog</name>
+ <uuid>65fcba04-5b13-bd93-cff3-52ce48e11ad7</uuid>
+ <source>
+ <host name='localhost' port='7000'/>
+ <name>sheepdog</name>
+ </source>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-sheepdog.xml b/tests/storagepoolxml2xmlout/pool-sheepdog.xml
new file mode 100644
index 0000000..000c068
--- /dev/null
+++ b/tests/storagepoolxml2xmlout/pool-sheepdog.xml
@@ -0,0 +1,11 @@
+<pool type='sheepdog'>
+ <name>sheepdog</name>
+ <uuid>65fcba04-5b13-bd93-cff3-52ce48e11ad7</uuid>
+ <capacity unit='bytes'>0</capacity>
+ <allocation unit='bytes'>0</allocation>
+ <available unit='bytes'>0</available>
+ <source>
+ <host name='localhost' port='7000'/>
+ <name>sheepdog</name>
+ </source>
+</pool>
diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c
index d73fc8a..8cac978 100644
--- a/tests/storagepoolxml2xmltest.c
+++ b/tests/storagepoolxml2xmltest.c
@@ -93,6 +93,7 @@ mymain(void)
DO_TEST("pool-mpath");
DO_TEST("pool-iscsi-multiiqn");
DO_TEST("pool-iscsi-vendor-product");
+ DO_TEST("pool-sheepdog");
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/tests/storagevolxml2xmlin/vol-sheepdog.xml b/tests/storagevolxml2xmlin/vol-sheepdog.xml
new file mode 100644
index 0000000..49e221c
--- /dev/null
+++ b/tests/storagevolxml2xmlin/vol-sheepdog.xml
@@ -0,0 +1,10 @@
+<volume>
+ <name>test2</name>
+ <source>
+ </source>
+ <capacity unit='bytes'>1024</capacity>
+ <allocation unit='bytes'>0</allocation>
+ <target>
+ <path>sheepdog:test2</path>
+ </target>
+</volume>
diff --git a/tests/storagevolxml2xmlout/vol-sheepdog.xml b/tests/storagevolxml2xmlout/vol-sheepdog.xml
new file mode 100644
index 0000000..2f19af8
--- /dev/null
+++ b/tests/storagevolxml2xmlout/vol-sheepdog.xml
@@ -0,0 +1,17 @@
+<volume>
+ <name>test2</name>
+ <key>(null)</key>
+ <source>
+ </source>
+ <capacity unit='bytes'>1024</capacity>
+ <allocation unit='bytes'>0</allocation>
+ <target>
+ <path>sheepdog:test2</path>
+ <format type='unknown'/>
+ <permissions>
+ <mode>0600</mode>
+ <owner>4294967295</owner>
+ <group>4294967295</group>
+ </permissions>
+ </target>
+</volume>
diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c
index 37c92cd..ee85988 100644
--- a/tests/storagevolxml2xmltest.c
+++ b/tests/storagevolxml2xmltest.c
@@ -112,6 +112,7 @@ mymain(void)
DO_TEST("pool-disk", "vol-partition");
DO_TEST("pool-logical", "vol-logical");
DO_TEST("pool-logical", "vol-logical-backing");
+ DO_TEST("pool-sheepdog", "vol-sheepdog");
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/tools/virsh.c b/tools/virsh.c
index 744b629..3f24a34 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -20229,6 +20229,9 @@ vshShowVersion(vshControl *ctl ATTRIBUTE_UNUSED)
#ifdef WITH_STORAGE_RBD
vshPrint(ctl, " RBD");
#endif
+#ifdef WITH_STORAGE_SHEEPDOG
+ vshPrint(ctl, " Sheepdog");
+#endif
vshPrint(ctl, "\n");
vshPrint(ctl, "%s", _(" Miscellaneous:"));
--
1.7.9.4
12 years, 5 months
[libvirt] [libvirt-glib] build: allow building with newer glibc-headers and -O0
by Christophe Fergeau
Commit log and autoconf snippet written by Eric Blake for libvirt.
glibc 2.15 (on Fedora 17) coupled with explicit disabling of
optimization during development dies a painful death:
In file included from /usr/include/limits.h:27:0,
from /usr/lib/gcc/x86_64-redhat-linux/4.7.0/include/limits.h:169,.
from /usr/lib/gcc/x86_64-redhat-linux/4.7.0/include/syslimits.h:7,
from /usr/lib/gcc/x86_64-redhat-linux/4.7.0/include/limits.h:34,
from util/bitmap.c:26:
/usr/include/features.h:314:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
cc1: all warnings being treated as errors
Work around this by only conditionally defining _FORTIFY_SOURCE,
in the case where glibc can actually use it. The trick is using
AH_VERBATIM instead of AC_DEFINE.
* m4/virt-compile-warnings.m4 (LIBOSINFO_COMPILE_WARNINGS): Squelch
_FORTIFY_SOURCE when needed to avoid glibc #warnings.
---
m4/virt-compile-warnings.m4 | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4
index de542cc..99d214e 100644
--- a/m4/virt-compile-warnings.m4
+++ b/m4/virt-compile-warnings.m4
@@ -84,8 +84,13 @@ AC_DEFUN([LIBVIRT_GLIB_COMPILE_WARNINGS],[
gl_WARN_ADD([-Wframe-larger-than=4096])
# Use improved glibc headers
- AC_DEFINE([_FORTIFY_SOURCE], [2],
- [enable compile-time and run-time bounds-checking, and some warnings])
+ AH_VERBATIM([FORTIFY_SOURCE],
+ [/* Enable compile-time and run-time bounds-checking, and some warnings,
+ without upsetting newer glibc. */
+ #if defined __OPTIMIZE__ && __OPTIMIZE__
+ # define _FORTIFY_SOURCE 2
+ #endif
+ ])
# Extra special flags
dnl -fstack-protector stuff passes gl_WARN_ADD with gcc
--
1.7.10.2
12 years, 5 months
[libvirt] [sandbox]console-rpc: fix segfault on null stdin
by Radu Caragea
If gvir_sandbox_console_attach is called with NULL as the stdin
parameter it results in a segfault in the console-rpc module from
libvirt-sandbox.
Calling with NULL is of course useful when running something
noninteractive and you don't want it to grab the stdin or pass any fd
whatsoever.
12 years, 5 months
Re: [libvirt] [Qemu-devel] [PATCH v2 0/4] file descriptor passing using passfd
by Kevin Wolf
Am 08.06.2012 17:42, schrieb 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 passfd 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 (4):
> qapi: Convert getfd and closefd
> qapi: Add passfd QMP command
> osdep: Enable qemu_open to dup pre-opened fd
> block: Convert open calls to qemu_open
>
> block/raw-posix.c | 18 +++++++++---------
> block/raw-win32.c | 4 ++--
> block/vdi.c | 5 +++--
> block/vmdk.c | 21 +++++++++------------
> block/vpc.c | 2 +-
> block/vvfat.c | 21 +++++++++++----------
> hmp-commands.hx | 6 ++----
> hmp.c | 18 ++++++++++++++++++
> hmp.h | 2 ++
> monitor.c | 36 ++++++++++++++++++++----------------
> osdep.c | 13 +++++++++++++
> qapi-schema.json | 44 ++++++++++++++++++++++++++++++++++++++++++++
> qmp-commands.hx | 33 +++++++++++++++++++++++++++++----
> 13 files changed, 163 insertions(+), 60 deletions(-)
Looks good to me. If Luiz is okay with the QMP part, I'm going to apply
this to the block branch.
Corey, please make sure to check the host_floppy problem and send a
patch if necessary.
Kevin
12 years, 5 months