This file is indexed.

/usr/share/doc/libvirt-doc/examples/dommigrate/dommigrate.c is in libvirt-doc 4.0.0-1ubuntu8.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * 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/>.
 *
 * Sahid Orentino Ferdjaoui <sahid.ferdjaoui@cloudwatt.com>
 */

#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;
}