[libvirt] [PATCH 0/2] Change name of the domain upon successful rename

Try running the example added in 1/2 before and after applying 2/2. Martin Kletzander (2): Add example that renames domain there and back Change name of the domain upon successful rename .gitignore | 1 + configure.ac | 1 + examples/rename/Makefile.am | 24 +++++++++++++++ examples/rename/rename.c | 73 ++++++++++++++++++++++++++++++++++++++++++++ src/remote/remote_driver.c | 41 +++++++++++++++++++++++++ src/remote/remote_protocol.x | 2 +- 6 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 examples/rename/Makefile.am create mode 100644 examples/rename/rename.c -- 2.5.1

And in the middle it prints out its name to demonstrate changes in later patch(es). Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- .gitignore | 1 + configure.ac | 1 + examples/rename/Makefile.am | 24 +++++++++++++++ examples/rename/rename.c | 73 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 examples/rename/Makefile.am create mode 100644 examples/rename/rename.c diff --git a/.gitignore b/.gitignore index 6bd41be9db89..19402f5b8cd2 100644 --- a/.gitignore +++ b/.gitignore @@ -83,6 +83,7 @@ /examples/domtop/domtop /examples/hellolibvirt/hellolibvirt /examples/openauth/openauth +/examples/rename/test /gnulib/lib/* /gnulib/m4/* /gnulib/tests/* diff --git a/configure.ac b/configure.ac index 8471a4659464..de31486792fb 100644 --- a/configure.ac +++ b/configure.ac @@ -2806,6 +2806,7 @@ AC_CONFIG_FILES([\ examples/domtop/Makefile \ examples/openauth/Makefile \ examples/hellolibvirt/Makefile \ + examples/rename/Makefile \ examples/systemtap/Makefile \ examples/xml/nwfilter/Makefile \ examples/lxcconvert/Makefile \ diff --git a/examples/rename/Makefile.am b/examples/rename/Makefile.am new file mode 100644 index 000000000000..1b3484c1f30e --- /dev/null +++ b/examples/rename/Makefile.am @@ -0,0 +1,24 @@ +## Copyright (C) 2005-2013 Red Hat, Inc. +## +## 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, see +## <http://www.gnu.org/licenses/>. + +INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include +LDADDS = $(STATIC_BINARIES) $(WARN_CFLAGS) $(top_builddir)/src/libvirt.la \ + $(COVERAGE_LDFLAGS) + +noinst_PROGRAMS=rename + +rename_SOURCES=rename.c +rename_LDADD= $(LDADDS) diff --git a/examples/rename/rename.c b/examples/rename/rename.c new file mode 100644 index 000000000000..85f18e9df32d --- /dev/null +++ b/examples/rename/rename.c @@ -0,0 +1,73 @@ +/* + * rename.c + * + * 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, see + * <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <libvirt/libvirt.h> + +int main(int argc, char **argv) +{ + virConnectPtr conn = NULL; /* the hypervisor connection */ + virDomainPtr dom = NULL; /* the domain being checked */ + int ret = EXIT_FAILURE; + + if (argc != 3) { + fprintf(stderr, "Usage: %s <current_domname> <temporary_domname>\n", + argv[0]); + goto error; + } + + conn = virConnectOpen(NULL); + if (conn == NULL) { + fprintf(stderr, "Failed to connect to hypervisor\n"); + goto error; + } + + dom = virDomainLookupByName(conn, argv[1]); + if (dom == NULL) { + fprintf(stderr, "Failed to find domain\n"); + goto error; + } + + printf("Before first rename: %s\n", virDomainGetName(dom)); + + /* Get the information */ + ret = virDomainRename(dom, argv[2], 0); + if (ret < 0) { + fprintf(stderr, "Failed to rename domain\n"); + goto error; + } + + printf("After first rename: %s\n", virDomainGetName(dom)); + + /* Get the information */ + ret = virDomainRename(dom, argv[1], 0); + if (ret < 0) { + fprintf(stderr, "Failed to rename domain\n"); + goto error; + } + + printf("After second rename: %s\n", virDomainGetName(dom)); + + error: + if (dom != NULL) + virDomainFree(dom); + if (conn != NULL) + virConnectClose(conn); + return ret; +} -- 2.5.1

On Fri, Sep 04, 2015 at 02:10:07PM +0200, Martin Kletzander wrote:
And in the middle it prints out its name to demonstrate changes in later patch(es).
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- .gitignore | 1 + configure.ac | 1 + examples/rename/Makefile.am | 24 +++++++++++++++ examples/rename/rename.c | 73 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 examples/rename/Makefile.am create mode 100644 examples/rename/rename.c
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/remote/remote_driver.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/remote/remote_protocol.x | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index aca00c0974e5..a1dd64087b3b 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8038,6 +8038,47 @@ remoteDomainInterfaceAddresses(virDomainPtr dom, } +static int +remoteDomainRename(virDomainPtr dom, const char *new_name, unsigned int flags) +{ + int rv = -1; + struct private_data *priv = dom->conn->privateData; + remote_domain_rename_args args; + remote_domain_rename_ret ret; + char *tmp = NULL; + + if (VIR_STRDUP(tmp, new_name) < 0) + return -1; + + remoteDriverLock(priv); + + make_nonnull_domain(&args.dom, dom); + args.new_name = new_name ? (char **)&new_name : NULL; + args.flags = flags; + + memset(&ret, 0, sizeof(ret)); + + if (call(dom->conn, priv, 0, REMOTE_PROC_DOMAIN_RENAME, + (xdrproc_t)xdr_remote_domain_rename_args, (char *)&args, + (xdrproc_t)xdr_remote_domain_rename_ret, (char *)&ret) == -1) { + goto done; + } + + rv = ret.retcode; + + if (rv == 0) { + VIR_FREE(dom->name); + dom->name = tmp; + tmp = NULL; + } + + done: + remoteDriverUnlock(priv); + VIR_FREE(tmp); + return rv; +} + + /* get_nonnull_domain and get_nonnull_network turn an on-wire * (name, uuid) pair into virDomainPtr or virNetworkPtr object. * These can return NULL if underlying memory allocations fail, diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 92a92e2bfa24..80f4a8b3a181 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -5708,7 +5708,7 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_SET_USER_PASSWORD = 357, /** - * @generate: both + * @generate: server * @acl: domain:write * @acl: domain:save */ -- 2.5.1

On Fri, Sep 04, 2015 at 02:10:08PM +0200, Martin Kletzander wrote:
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/remote/remote_driver.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/remote/remote_protocol.x | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (2)
-
Daniel P. Berrange
-
Martin Kletzander