mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-11-03 20:01:16 +00:00
acf522e85a
Commit0c6ad476
updated gnulib, which rearranged some of the conditions in gnulib wrapper headers such that compilation started failing on BSD systems when the normal system <unistd.h> tried to include another system header but instead got a gnulib wrapper header in an incomplete state; this is because gnulib headers only work if <config.h> is included first. Commitb6f78259
papered over the symptoms of that by including <config.h> in all the examples. But this logic is backwards - if our examples are truly meant to be stand-alone, they should NOT depend on how libvirt was configured, and should NOT depend on the gnulib fixes for system quirks. In particular, if an example does not need to link against libgnulib.la, then it also does not need to use -Ignulib in its compile flags, and likewise does not need to include <config.h> since none of the gnulib wrapper headers should be interfering. So, revert (most of)b6f78259
(except for the bogus pre-patch use of "config.h" in admin/logging.c: if config.h is included, it should be via <> rather than "", and must be before any system headers); then additionally nuke all mention of <config.h>, -Ignulib, and -llibgnu.la, making all of the examples truly standalone. Signed-off-by: Eric Blake <eblake@redhat.com> Acked-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
88 lines
2.4 KiB
C
88 lines
2.4 KiB
C
/*
|
|
* dommigrate.c: This file is largely inspired from hellolibvirt and
|
|
* contains a trivial example that illustrate p2p domain
|
|
* migration with libvirt.
|
|
*
|
|
* Copyright (C) 2014 Cloudwatt
|
|
*
|
|
* 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>
|
|
#include <libvirt/virterror.h>
|
|
|
|
|
|
static int
|
|
usage(char *prgn, int ret)
|
|
{
|
|
printf("Usage: %s <src uri> <dst uri> <domain name>\n", prgn);
|
|
return ret;
|
|
}
|
|
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
char *src_uri, *dst_uri, *domname;
|
|
int ret = 0;
|
|
virConnectPtr conn = NULL;
|
|
virDomainPtr dom = NULL;
|
|
|
|
if (argc < 4) {
|
|
ret = usage(argv[0], 1);
|
|
goto out;
|
|
}
|
|
|
|
src_uri = argv[1];
|
|
dst_uri = argv[2];
|
|
domname = argv[3];
|
|
|
|
printf("Attempting to connect to the source hypervisor...\n");
|
|
conn = virConnectOpenAuth(src_uri, virConnectAuthPtrDefault, 0);
|
|
if (!conn) {
|
|
ret = 1;
|
|
fprintf(stderr, "No connection to the source hypervisor: %s.\n",
|
|
virGetLastErrorMessage());
|
|
goto out;
|
|
}
|
|
|
|
printf("Attempting to retrieve domain %s...\n", domname);
|
|
dom = virDomainLookupByName(conn, domname);
|
|
if (!dom) {
|
|
fprintf(stderr, "Failed to find domain %s.\n", domname);
|
|
goto cleanup;
|
|
}
|
|
|
|
printf("Attempting to migrate %s to %s...\n", domname, dst_uri);
|
|
if ((ret = virDomainMigrateToURI(dom, dst_uri,
|
|
VIR_MIGRATE_PEER2PEER,
|
|
NULL, 0)) != 0) {
|
|
fprintf(stderr, "Failed to migrate domain %s.\n", domname);
|
|
goto cleanup;
|
|
}
|
|
|
|
printf("Migration finished with success.\n");
|
|
|
|
cleanup:
|
|
if (dom != NULL)
|
|
virDomainFree(dom);
|
|
if (conn != NULL)
|
|
virConnectClose(conn);
|
|
|
|
out:
|
|
return ret;
|
|
}
|