remote_driver.c 187.6 KB
Newer Older
1
/*
2
 * remote_driver.c: driver to provide access to libvirtd running
3 4
 *   on a remote machine
 *
5
 * Copyright (C) 2007-2012 Red Hat, Inc.
6 7 8 9 10 11 12 13 14 15 16 17
 *
 * 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
O
Osier Yang 已提交
18 19
 * License along with this library;  If not, see
 * <http://www.gnu.org/licenses/>.
20 21 22 23
 *
 * Author: Richard Jones <rjones@redhat.com>
 */

24
#include <config.h>
25

26 27
#include <unistd.h>
#include <assert.h>
28

29 30 31
#include "virnetclient.h"
#include "virnetclientprogram.h"
#include "virnetclientstream.h"
32
#include "virterror_internal.h"
33
#include "logging.h"
34
#include "datatypes.h"
35
#include "domain_event.h"
36
#include "driver.h"
37
#include "buf.h"
38
#include "remote_driver.h"
39
#include "remote_protocol.h"
C
Chris Lalancette 已提交
40
#include "qemu_protocol.h"
41
#include "memory.h"
42
#include "util.h"
E
Eric Blake 已提交
43
#include "virfile.h"
44
#include "command.h"
45
#include "intprops.h"
A
Alex Jia 已提交
46
#include "virtypedparam.h"
M
Martin Kletzander 已提交
47
#include "viruri.h"
48 49
#include "virauth.h"
#include "virauthconfig.h"
50

51 52
#define VIR_FROM_THIS VIR_FROM_REMOTE

53 54 55 56
#if SIZEOF_LONG < 8
# define HYPER_TO_TYPE(_type, _to, _from)                                     \
    do {                                                                      \
        if ((_from) != (_type)(_from)) {                                      \
57 58
            virReportError(VIR_ERR_INTERNAL_ERROR,                               \
                           _("conversion from hyper to %s overflowed"), #_type); \
59 60 61 62 63 64 65 66 67 68 69 70
            goto done;                                                        \
        }                                                                     \
        (_to) = (_from);                                                      \
    } while (0)

# define HYPER_TO_LONG(_to, _from) HYPER_TO_TYPE(long, _to, _from)
# define HYPER_TO_ULONG(_to, _from) HYPER_TO_TYPE(unsigned long, _to, _from)
#else
# define HYPER_TO_LONG(_to, _from) (_to) = (_from)
# define HYPER_TO_ULONG(_to, _from) (_to) = (_from)
#endif

71
static int inside_daemon = 0;
72
static virDriverPtr remoteDriver = NULL;
73

74 75
struct private_data {
    virMutex lock;
76

77 78 79
    virNetClientPtr client;
    virNetClientProgramPtr remoteProgram;
    virNetClientProgramPtr qemuProgram;
80

81
    int counter; /* Serial number for RPC */
82

83
    virNetTLSContextPtr tls;
84

85
    int is_secure;              /* Secure if TLS or SASL or UNIX sockets */
86
    char *type;                 /* Cached return from remoteType. */
87
    int localUses;              /* Ref count for private data */
88
    char *hostname;             /* Original hostname */
89
    bool serverKeepAlive;       /* Does server support keepalive protocol? */
90

91
    virDomainEventStatePtr domainEventState;
92 93
};

94
enum {
95
    REMOTE_CALL_QEMU              = (1 << 0),
96 97 98
};


99 100 101 102 103 104 105 106 107 108
static void remoteDriverLock(struct private_data *driver)
{
    virMutexLock(&driver->lock);
}

static void remoteDriverUnlock(struct private_data *driver)
{
    virMutexUnlock(&driver->lock);
}

109 110 111 112 113 114 115 116
static int call(virConnectPtr conn, struct private_data *priv,
                unsigned int flags, int proc_nr,
                xdrproc_t args_filter, char *args,
                xdrproc_t ret_filter, char *ret);
static int callWithFD(virConnectPtr conn, struct private_data *priv,
                      unsigned int flags, int fd, int proc_nr,
                      xdrproc_t args_filter, char *args,
                      xdrproc_t ret_filter, char *ret);
117
static int remoteAuthenticate (virConnectPtr conn, struct private_data *priv,
118
                               virConnectAuthPtr auth, const char *authtype);
119
#if HAVE_SASL
120
static int remoteAuthSASL (virConnectPtr conn, struct private_data *priv,
121
                           virConnectAuthPtr auth, const char *mech);
122
#endif
123
#if HAVE_POLKIT
124
static int remoteAuthPolkit (virConnectPtr conn, struct private_data *priv,
125
                             virConnectAuthPtr auth);
126
#endif /* HAVE_POLKIT */
127

128 129
static virDomainPtr get_nonnull_domain (virConnectPtr conn, remote_nonnull_domain domain);
static virNetworkPtr get_nonnull_network (virConnectPtr conn, remote_nonnull_network network);
130
static virNWFilterPtr get_nonnull_nwfilter (virConnectPtr conn, remote_nonnull_nwfilter nwfilter);
131
static virInterfacePtr get_nonnull_interface (virConnectPtr conn, remote_nonnull_interface iface);
132 133
static virStoragePoolPtr get_nonnull_storage_pool (virConnectPtr conn, remote_nonnull_storage_pool pool);
static virStorageVolPtr get_nonnull_storage_vol (virConnectPtr conn, remote_nonnull_storage_vol vol);
134
static virNodeDevicePtr get_nonnull_node_device (virConnectPtr conn, remote_nonnull_node_device dev);
135
static virSecretPtr get_nonnull_secret (virConnectPtr conn, remote_nonnull_secret secret);
C
Chris Lalancette 已提交
136
static virDomainSnapshotPtr get_nonnull_domain_snapshot (virDomainPtr domain, remote_nonnull_domain_snapshot snapshot);
137 138
static void make_nonnull_domain (remote_nonnull_domain *dom_dst, virDomainPtr dom_src);
static void make_nonnull_network (remote_nonnull_network *net_dst, virNetworkPtr net_src);
D
Daniel Veillard 已提交
139
static void make_nonnull_interface (remote_nonnull_interface *interface_dst, virInterfacePtr interface_src);
140 141
static void make_nonnull_storage_pool (remote_nonnull_storage_pool *pool_dst, virStoragePoolPtr vol_src);
static void make_nonnull_storage_vol (remote_nonnull_storage_vol *vol_dst, virStorageVolPtr vol_src);
142
static void make_nonnull_secret (remote_nonnull_secret *secret_dst, virSecretPtr secret_src);
143
static void make_nonnull_nwfilter (remote_nonnull_nwfilter *nwfilter_dst, virNWFilterPtr nwfilter_src);
C
Chris Lalancette 已提交
144
static void make_nonnull_domain_snapshot (remote_nonnull_domain_snapshot *snapshot_dst, virDomainSnapshotPtr snapshot_src);
145
static void remoteDomainEventQueue(struct private_data *priv, virDomainEventPtr event);
146 147 148 149 150
/*----------------------------------------------------------------------*/

/* Helper functions for remoteOpen. */
static char *get_transport_from_scheme (char *scheme);

A
Atsushi SAKAI 已提交
151
#ifdef WITH_LIBVIRTD
152
static int
153
remoteStartup(int privileged ATTRIBUTE_UNUSED)
154 155 156 157 158 159 160
{
    /* Mark that we're inside the daemon so we can avoid
     * re-entering ourselves
     */
    inside_daemon = 1;
    return 0;
}
A
Atsushi SAKAI 已提交
161
#endif
162

163
#ifndef WIN32
164
/**
165
 * remoteFindDaemonPath:
166 167
 *
 * Tries to find the path to the libvirtd binary.
168
 *
169 170 171 172 173 174 175 176 177 178 179 180 181 182
 * Returns path on success or NULL in case of error.
 */
static const char *
remoteFindDaemonPath(void)
{
    static const char *serverPaths[] = {
        SBINDIR "/libvirtd",
        SBINDIR "/libvirtd_dbg",
        NULL
    };
    int i;
    const char *customDaemon = getenv("LIBVIRTD_PATH");

    if (customDaemon)
183
        return customDaemon;
184 185

    for (i = 0; serverPaths[i]; i++) {
E
Eric Blake 已提交
186
        if (virFileIsExecutable(serverPaths[i])) {
187 188 189 190 191
            return serverPaths[i];
        }
    }
    return NULL;
}
192
#endif
193

194

195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
static void
remoteDomainBuildEventLifecycle(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                                virNetClientPtr client ATTRIBUTE_UNUSED,
                                void *evdata, void *opaque);
static void
remoteDomainBuildEventReboot(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                             virNetClientPtr client ATTRIBUTE_UNUSED,
                             void *evdata, void *opaque);
static void
remoteDomainBuildEventRTCChange(virNetClientProgramPtr prog,
                                virNetClientPtr client,
                                void *evdata, void *opaque);
static void
remoteDomainBuildEventWatchdog(virNetClientProgramPtr prog,
                               virNetClientPtr client,
                               void *evdata, void *opaque);
static void
remoteDomainBuildEventIOError(virNetClientProgramPtr prog,
                              virNetClientPtr client,
                              void *evdata, void *opaque);
static void
remoteDomainBuildEventIOErrorReason(virNetClientProgramPtr prog,
                                    virNetClientPtr client,
                                    void *evdata, void *opaque);
static void
remoteDomainBuildEventGraphics(virNetClientProgramPtr prog,
                               virNetClientPtr client,
                               void *evdata, void *opaque);
static void
remoteDomainBuildEventControlError(virNetClientProgramPtr prog,
                                   virNetClientPtr client,
                                   void *evdata, void *opaque);

228 229 230 231 232
static void
remoteDomainBuildEventBlockJob(virNetClientProgramPtr prog,
                               virNetClientPtr client,
                               void *evdata, void *opaque);

233 234 235 236 237
static void
remoteDomainBuildEventDiskChange(virNetClientProgramPtr prog,
                                 virNetClientPtr client,
                                 void *evdata, void *opaque);

238 239 240 241 242
static void
remoteDomainBuildEventTrayChange(virNetClientProgramPtr prog,
                                 virNetClientPtr client,
                                 void *evdata, void *opaque);

O
Osier Yang 已提交
243 244 245 246 247
static void
remoteDomainBuildEventPMWakeup(virNetClientProgramPtr prog,
                               virNetClientPtr client,
                               void *evdata, void *opaque);

O
Osier Yang 已提交
248 249 250 251
static void
remoteDomainBuildEventPMSuspend(virNetClientProgramPtr prog,
                                virNetClientPtr client,
                                void *evdata, void *opaque);
252 253 254 255
static void
remoteDomainBuildEventBalloonChange(virNetClientProgramPtr prog,
                                    virNetClientPtr client,
                                    void *evdata, void *opaque);
O
Osier Yang 已提交
256

257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
static virNetClientProgramEvent remoteDomainEvents[] = {
    { REMOTE_PROC_DOMAIN_EVENT_RTC_CHANGE,
      remoteDomainBuildEventRTCChange,
      sizeof(remote_domain_event_rtc_change_msg),
      (xdrproc_t)xdr_remote_domain_event_rtc_change_msg },
    { REMOTE_PROC_DOMAIN_EVENT_REBOOT,
      remoteDomainBuildEventReboot,
      sizeof(remote_domain_event_reboot_msg),
      (xdrproc_t)xdr_remote_domain_event_reboot_msg },
    { REMOTE_PROC_DOMAIN_EVENT_LIFECYCLE,
      remoteDomainBuildEventLifecycle,
      sizeof(remote_domain_event_lifecycle_msg),
      (xdrproc_t)xdr_remote_domain_event_lifecycle_msg },
    { REMOTE_PROC_DOMAIN_EVENT_WATCHDOG,
      remoteDomainBuildEventWatchdog,
      sizeof(remote_domain_event_watchdog_msg),
      (xdrproc_t)xdr_remote_domain_event_watchdog_msg},
    { REMOTE_PROC_DOMAIN_EVENT_IO_ERROR,
      remoteDomainBuildEventIOError,
      sizeof(remote_domain_event_io_error_msg),
      (xdrproc_t)xdr_remote_domain_event_io_error_msg },
    { REMOTE_PROC_DOMAIN_EVENT_IO_ERROR_REASON,
      remoteDomainBuildEventIOErrorReason,
      sizeof(remote_domain_event_io_error_reason_msg),
      (xdrproc_t)xdr_remote_domain_event_io_error_reason_msg },
    { REMOTE_PROC_DOMAIN_EVENT_GRAPHICS,
      remoteDomainBuildEventGraphics,
      sizeof(remote_domain_event_graphics_msg),
      (xdrproc_t)xdr_remote_domain_event_graphics_msg },
    { REMOTE_PROC_DOMAIN_EVENT_CONTROL_ERROR,
      remoteDomainBuildEventControlError,
      sizeof(remote_domain_event_control_error_msg),
      (xdrproc_t)xdr_remote_domain_event_control_error_msg },
290 291 292 293
    { REMOTE_PROC_DOMAIN_EVENT_BLOCK_JOB,
      remoteDomainBuildEventBlockJob,
      sizeof(remote_domain_event_block_job_msg),
      (xdrproc_t)xdr_remote_domain_event_block_job_msg },
294 295 296 297
    { REMOTE_PROC_DOMAIN_EVENT_DISK_CHANGE,
      remoteDomainBuildEventDiskChange,
      sizeof(remote_domain_event_disk_change_msg),
      (xdrproc_t)xdr_remote_domain_event_disk_change_msg },
298 299 300 301
    { REMOTE_PROC_DOMAIN_EVENT_TRAY_CHANGE,
      remoteDomainBuildEventTrayChange,
      sizeof(remote_domain_event_tray_change_msg),
      (xdrproc_t)xdr_remote_domain_event_tray_change_msg },
O
Osier Yang 已提交
302 303 304 305
    { REMOTE_PROC_DOMAIN_EVENT_PMWAKEUP,
      remoteDomainBuildEventPMWakeup,
      sizeof(remote_domain_event_pmwakeup_msg),
      (xdrproc_t)xdr_remote_domain_event_pmwakeup_msg },
O
Osier Yang 已提交
306 307 308 309
    { REMOTE_PROC_DOMAIN_EVENT_PMSUSPEND,
      remoteDomainBuildEventPMSuspend,
      sizeof(remote_domain_event_pmsuspend_msg),
      (xdrproc_t)xdr_remote_domain_event_pmsuspend_msg },
310 311 312 313
    { REMOTE_PROC_DOMAIN_EVENT_BALLOON_CHANGE,
      remoteDomainBuildEventBalloonChange,
      sizeof(remote_domain_event_balloon_change_msg),
      (xdrproc_t)xdr_remote_domain_event_balloon_change_msg },
314
};
315

316
enum virDrvOpenRemoteFlags {
317
    VIR_DRV_OPEN_REMOTE_RO = (1 << 0),
318 319
    VIR_DRV_OPEN_REMOTE_USER      = (1 << 1), /* Use the per-user socket path */
    VIR_DRV_OPEN_REMOTE_AUTOSTART = (1 << 2), /* Autostart a per-user daemon */
320
};
321

322

323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
static void remoteClientCloseFunc(virNetClientPtr client ATTRIBUTE_UNUSED,
                                  int reason,
                                  void *opaque)
{
    virConnectPtr conn = opaque;

    virMutexLock(&conn->lock);
    if (conn->closeCallback) {
        virConnectCloseFunc closeCallback = conn->closeCallback;
        void *closeOpaque = conn->closeOpaque;
        virFreeCallback closeFreeCallback = conn->closeFreeCallback;
        unsigned closeUnregisterCount = conn->closeUnregisterCount;

        VIR_DEBUG("Triggering connection close callback %p reason=%d",
                  conn->closeCallback, reason);
        conn->closeDispatch = true;
        virMutexUnlock(&conn->lock);
        closeCallback(conn, reason, closeOpaque);
        virMutexLock(&conn->lock);
        conn->closeDispatch = false;
        if (conn->closeUnregisterCount != closeUnregisterCount)
            closeFreeCallback(closeOpaque);
    }
    virMutexUnlock(&conn->lock);
}

349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
/* helper macro to ease extraction of arguments from the URI */
#define EXTRACT_URI_ARG_STR(ARG_NAME, ARG_VAR)          \
    if (STRCASEEQ(var->name, ARG_NAME)) {               \
        VIR_FREE(ARG_VAR);                              \
        if (!(ARG_VAR = strdup(var->value)))            \
            goto no_memory;                             \
        var->ignore = 1;                                \
        continue;                                       \
    }

#define EXTRACT_URI_ARG_BOOL(ARG_NAME, ARG_VAR)                             \
    if (STRCASEEQ(var->name, ARG_NAME)) {                                   \
        int tmp;                                                            \
        if (virStrToLong_i(var->value, NULL, 10, &tmp) < 0) {               \
            virReportError(VIR_ERR_INVALID_ARG,                             \
                           _("Failed to parse value of URI component %s"),  \
                           var->name);                                      \
            goto failed;                                                    \
        }                                                                   \
        ARG_VAR = tmp == 0;                                                 \
        var->ignore = 1;                                                    \
        continue;                                                           \
    }
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
/*
 * URIs that this driver needs to handle:
 *
 * The easy answer:
 *   - Everything that no one else has yet claimed, but nothing if
 *     we're inside the libvirtd daemon
 *
 * The hard answer:
 *   - Plain paths (///var/lib/xen/xend-socket)  -> UNIX domain socket
 *   - xxx://servername/      -> TLS connection
 *   - xxx+tls://servername/  -> TLS connection
 *   - xxx+tls:///            -> TLS connection to localhost
 *   - xxx+tcp://servername/  -> TCP connection
 *   - xxx+tcp:///            -> TCP connection to localhost
 *   - xxx+unix:///           -> UNIX domain socket
 *   - xxx:///                -> UNIX domain socket
388 389
 *   - xxx+ssh:///            -> SSH connection (legacy)
 *   - xxx+libssh2:///        -> SSH connection (using libssh2)
390
 */
391
static int
392 393 394 395
doRemoteOpen(virConnectPtr conn,
             struct private_data *priv,
             virConnectAuthPtr auth ATTRIBUTE_UNUSED,
             unsigned int flags)
396
{
397
    char *transport_str = NULL;
398 399 400 401
    enum {
        trans_tls,
        trans_unix,
        trans_ssh,
402
        trans_libssh2,
403 404 405
        trans_ext,
        trans_tcp,
    } transport;
406
#ifndef WIN32
407
    const char *daemonPath;
408
#endif
409

410
    /* We handle *ALL* URIs here. The caller has rejected any
411
     * URIs we don't care about */
412

413 414 415
    if (conn->uri) {
        if (!conn->uri->scheme) {
            /* This is the ///var/lib/xen/xend-socket local path style */
416 417 418 419 420
            if (!conn->uri->path)
                return VIR_DRV_OPEN_DECLINED;
            if (conn->uri->path[0] != '/')
                return VIR_DRV_OPEN_DECLINED;

421
            transport = trans_unix;
422
        } else {
423
            transport_str = get_transport_from_scheme(conn->uri->scheme);
424

425 426 427 428 429 430
            if (!transport_str) {
                if (conn->uri->server)
                    transport = trans_tls;
                else
                    transport = trans_unix;
            } else {
431
                if (STRCASEEQ(transport_str, "tls"))
432
                    transport = trans_tls;
433
                else if (STRCASEEQ(transport_str, "unix")) {
434
                    if (conn->uri->server) {
435 436 437 438
                        virReportError(VIR_ERR_INVALID_ARG,
                                       _("using unix socket and remote "
                                         "server '%s' is not supported."),
                                       conn->uri->server);
439 440 441 442
                        return VIR_DRV_OPEN_ERROR;
                    } else {
                        transport = trans_unix;
                    }
443
                } else if (STRCASEEQ(transport_str, "ssh"))
444
                    transport = trans_ssh;
445 446
                else if (STRCASEEQ(transport_str, "libssh2"))
                    transport = trans_libssh2;
447
                else if (STRCASEEQ(transport_str, "ext"))
448
                    transport = trans_ext;
449
                else if (STRCASEEQ(transport_str, "tcp"))
450 451
                    transport = trans_tcp;
                else {
452 453
                    virReportError(VIR_ERR_INVALID_ARG, "%s",
                                   _("remote_open: transport in URL not recognised "
454
                                     "(should be tls|unix|ssh|ext|tcp|libssh2)"));
455 456 457 458 459 460 461
                    return VIR_DRV_OPEN_ERROR;
                }
            }
        }
    } else {
        /* No URI, then must be probing so use UNIX socket */
        transport = trans_unix;
462
    }
463

E
Eric Blake 已提交
464
    /* Local variables which we will initialize. These can
465 466
     * get freed in the failed: path.
     */
467 468
    char *name = NULL, *command = NULL, *sockname = NULL, *netcat = NULL;
    char *port = NULL, *authtype = NULL, *username = NULL;
L
Laine Stump 已提交
469
    bool sanity = true, verify = true, tty ATTRIBUTE_UNUSED = true;
470 471 472
    char *pkipath = NULL, *keyfile = NULL, *sshauth = NULL;

    char *knownHostsVerify = NULL,  *knownHosts = NULL;
473

474 475 476
    /* Return code from this function, and the private data. */
    int retcode = VIR_DRV_OPEN_ERROR;

477
    /* Remote server defaults to "localhost" if not specified. */
478
    if (conn->uri && conn->uri->port != 0) {
479 480
        if (virAsprintf(&port, "%d", conn->uri->port) < 0)
            goto no_memory;
481
    } else if (transport == trans_tls) {
482 483
        if (!(port = strdup(LIBVIRTD_TLS_PORT)))
            goto no_memory;
484
    } else if (transport == trans_tcp) {
485 486 487
        if (!(port = strdup(LIBVIRTD_TCP_PORT)))
            goto no_memory;
    } /* Port not used for unix, ext., default for ssh */
488

489 490 491 492
    if (conn->uri && conn->uri->server)
        priv->hostname = strdup(conn->uri->server);
    else
        priv->hostname = strdup("localhost");
493

494
    if (!priv->hostname)
495 496 497 498 499
        goto no_memory;

    if (conn->uri && conn->uri->user &&
        !(username = strdup (conn->uri->user)))
        goto no_memory;
500

501 502 503 504 505
    /* Get the variables from the query string.
     * Then we need to reconstruct the query string (because
     * feasibly it might contain variables needed by the real driver,
     * although that won't be the case for now).
     */
506
    int i;
507

508
    if (conn->uri) {
509 510
        for (i = 0; i < conn->uri->paramsCount ; i++) {
            virURIParamPtr var = &conn->uri->params[i];
511 512 513 514
            EXTRACT_URI_ARG_STR("name", name);
            EXTRACT_URI_ARG_STR("command", command);
            EXTRACT_URI_ARG_STR("socket", sockname);
            EXTRACT_URI_ARG_STR("auth", authtype);
515
            EXTRACT_URI_ARG_STR("sshauth", sshauth);
516 517 518
            EXTRACT_URI_ARG_STR("netcat", netcat);
            EXTRACT_URI_ARG_STR("keyfile", keyfile);
            EXTRACT_URI_ARG_STR("pkipath", pkipath);
519 520
            EXTRACT_URI_ARG_STR("known_hosts", knownHosts);
            EXTRACT_URI_ARG_STR("known_hosts_verify", knownHostsVerify);
521 522 523 524 525 526

            EXTRACT_URI_ARG_BOOL("no_sanity", sanity);
            EXTRACT_URI_ARG_BOOL("no_verify", verify);
            EXTRACT_URI_ARG_BOOL("no_tty", tty);

            if (STRCASEEQ(var->name, "authfile")) {
527 528
                /* Strip this param, used by virauth.c */
                var->ignore = 1;
529
                continue;
530
            }
531 532 533

            VIR_DEBUG("passing through variable '%s' ('%s') to remote end",
                       var->name, var->value);
534
        }
535

536 537
        /* Construct the original name. */
        if (!name) {
538 539 540
            if (conn->uri->scheme &&
                (STREQ(conn->uri->scheme, "remote") ||
                 STRPREFIX(conn->uri->scheme, "remote+"))) {
541
                /* Allow remote serve to probe */
542
                if (!(name = strdup("")))
543
                    goto no_memory;
544
            } else {
M
Martin Kletzander 已提交
545
                virURI tmpuri = {
546
                    .scheme = conn->uri->scheme,
547
                    .query = virURIFormatParams(conn->uri),
548 549 550 551 552 553
                    .path = conn->uri->path,
                    .fragment = conn->uri->fragment,
                };

                /* Evil, blank out transport scheme temporarily */
                if (transport_str) {
554
                    assert(transport_str[-1] == '+');
555 556
                    transport_str[-1] = '\0';
                }
557

M
Martin Kletzander 已提交
558
                name = virURIFormat(&tmpuri);
559

560 561 562 563 564
                VIR_FREE(tmpuri.query);

                /* Restore transport scheme */
                if (transport_str)
                    transport_str[-1] = '+';
565 566 567

                if (!name)
                    goto failed;
568
            }
569
        }
570 571
    } else {
        /* Probe URI server side */
572
        if (!(name = strdup("")))
573
            goto no_memory;
574 575
    }

576
    VIR_DEBUG("proceeding with name = %s", name);
577

578 579
    /* For ext transport, command is required. */
    if (transport == trans_ext && !command) {
580 581
        virReportError(VIR_ERR_INVALID_ARG, "%s",
                       _("remote_open: for 'ext' transport, command is required"));
582 583 584
        goto failed;
    }

585
    VIR_DEBUG("Connecting with transport %d", transport);
586 587 588
    /* Connect to the remote service. */
    switch (transport) {
    case trans_tls:
589 590
        priv->tls = virNetTLSContextNewClientPath(pkipath,
                                                  geteuid() != 0 ? true : false,
591
                                                  sanity, verify);
592 593
        if (!priv->tls)
            goto failed;
594
        priv->is_secure = 1;
595 596

        /*FALLTHROUGH*/
597 598 599
    case trans_tcp:
        priv->client = virNetClientNewTCP(priv->hostname, port);
        if (!priv->client)
600 601
            goto failed;

602 603 604 605
        if (priv->tls) {
            VIR_DEBUG("Starting TLS session");
            if (virNetClientSetTLSSession(priv->client, priv->tls) < 0)
                goto failed;
606 607 608 609
        }

        break;

610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
    case trans_libssh2:
        if (!sockname) {
            if (flags & VIR_DRV_OPEN_REMOTE_RO)
                sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET_RO);
            else
                sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET);

            if (sockname == NULL)
                goto no_memory;
        }

        VIR_DEBUG("Starting LibSSH2 session");

        priv->client = virNetClientNewLibSSH2(priv->hostname,
                                              port,
                                              username,
                                              keyfile,
                                              knownHosts,
                                              knownHostsVerify,
                                              sshauth,
                                              netcat,
                                              sockname,
                                              auth);
        if (!priv->client)
            goto failed;

        priv->is_secure = 1;
        break;

639
#ifndef WIN32
640
    case trans_unix:
641
        if (!sockname) {
642
            if (flags & VIR_DRV_OPEN_REMOTE_USER) {
643
                char *userdir = virGetUserRuntimeDirectory();
644

645
                if (!userdir)
646
                    goto failed;
647

648
                if (virAsprintf(&sockname, "%s/" LIBVIRTD_USER_UNIX_SOCKET, userdir) < 0) {
649
                    VIR_FREE(userdir);
650
                    goto no_memory;
651 652
                }
                VIR_FREE(userdir);
653
            } else {
654
                if (flags & VIR_DRV_OPEN_REMOTE_RO)
655
                    sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET_RO);
656
                else
657
                    sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET);
658
                if (sockname == NULL)
659
                    goto no_memory;
660
            }
661
            VIR_DEBUG("Proceeding with sockname %s", sockname);
662 663
        }

664
        if (!(daemonPath = remoteFindDaemonPath())) {
665 666
            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                           _("Unable to locate libvirtd daemon in $PATH"));
667 668
            goto failed;
        }
669 670
        if (!(priv->client = virNetClientNewUNIX(sockname,
                                                 flags & VIR_DRV_OPEN_REMOTE_AUTOSTART,
671
                                                 daemonPath)))
C
Chris Lalancette 已提交
672
            goto failed;
673

674
        priv->is_secure = 1;
675 676
        break;

677
    case trans_ssh:
678 679
        if (!command && !(command = strdup("ssh")))
            goto no_memory;
J
Jim Meyering 已提交
680

681 682 683 684 685
        if (!sockname) {
            if (flags & VIR_DRV_OPEN_REMOTE_RO)
                sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET_RO);
            else
                sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET);
686 687
            if (!sockname)
                goto no_memory;
688 689 690 691 692 693
        }

        if (!(priv->client = virNetClientNewSSH(priv->hostname,
                                                port,
                                                command,
                                                username,
694 695
                                                !tty,
                                                !verify,
696
                                                netcat ? netcat : "nc",
697
                                                keyfile,
698 699
                                                sockname)))
            goto failed;
700 701

        priv->is_secure = 1;
702
        break;
703 704

    case trans_ext: {
705 706
        char const *cmd_argv[] = { command, NULL };
        if (!(priv->client = virNetClientNewExternal(cmd_argv)))
707 708
            goto failed;

E
Eric Blake 已提交
709
        /* Do not set 'is_secure' flag since we can't guarantee
710 711
         * an external program is secure, and this flag must be
         * pessimistic */
712 713
    }   break;

714 715 716 717 718
#else /* WIN32 */

    case trans_unix:
    case trans_ssh:
    case trans_ext:
719 720 721
        virReportError(VIR_ERR_INVALID_ARG, "%s",
                       _("transport methods unix, ssh and ext are not supported "
                         "under Windows"));
722
        goto failed;
723 724

#endif /* WIN32 */
725 726
    } /* switch (transport) */

727

728 729 730 731 732 733 734 735 736
    if (virNetClientRegisterAsyncIO(priv->client) < 0) {
        VIR_DEBUG("Failed to add event watch, disabling events and support for"
                  " keepalive messages");
        virResetLastError();
    } else {
        if (virNetClientRegisterKeepAlive(priv->client) < 0)
            goto failed;
    }

737 738 739 740
    virNetClientSetCloseCallback(priv->client,
                                 remoteClientCloseFunc,
                                 conn, NULL);

741 742 743 744 745
    if (!(priv->remoteProgram = virNetClientProgramNew(REMOTE_PROGRAM,
                                                       REMOTE_PROTOCOL_VERSION,
                                                       remoteDomainEvents,
                                                       ARRAY_CARDINALITY(remoteDomainEvents),
                                                       conn)))
746
        goto failed;
747 748 749 750 751
    if (!(priv->qemuProgram = virNetClientProgramNew(QEMU_PROGRAM,
                                                     QEMU_PROTOCOL_VERSION,
                                                     NULL,
                                                     0,
                                                     NULL)))
752 753
        goto failed;

754 755
    if (virNetClientAddProgram(priv->client, priv->remoteProgram) < 0 ||
        virNetClientAddProgram(priv->client, priv->qemuProgram) < 0)
756
        goto failed;
757 758

    /* Try and authenticate with server */
759 760
    VIR_DEBUG("Trying authentication");
    if (remoteAuthenticate(conn, priv, auth, authtype) == -1)
761 762
        goto failed;

763 764 765 766 767 768 769 770 771 772
    if (virNetClientKeepAliveIsSupported(priv->client)) {
        remote_supports_feature_args args =
            { VIR_DRV_FEATURE_PROGRAM_KEEPALIVE };
        remote_supports_feature_ret ret = { 0 };
        int rc;

        rc = call(conn, priv, 0, REMOTE_PROC_SUPPORTS_FEATURE,
                  (xdrproc_t)xdr_remote_supports_feature_args, (char *) &args,
                  (xdrproc_t)xdr_remote_supports_feature_ret, (char *) &ret);

773
        if (rc != -1 && ret.supported) {
774 775 776 777 778 779 780
            priv->serverKeepAlive = true;
        } else {
            VIR_INFO("Disabling keepalive protocol since it is not supported"
                     " by the server");
        }
    }

781
    /* Finally we can call the remote side's open function. */
782 783
    {
        remote_open_args args = { &name, flags };
784

785
        VIR_DEBUG("Trying to open URI %s", name);
786 787 788
        if (call(conn, priv, 0, REMOTE_PROC_OPEN,
                 (xdrproc_t) xdr_remote_open_args, (char *) &args,
                 (xdrproc_t) xdr_void, (char *) NULL) == -1)
789 790
            goto failed;
    }
791

792 793 794 795
    /* Now try and find out what URI the daemon used */
    if (conn->uri == NULL) {
        remote_get_uri_ret uriret;

796
        VIR_DEBUG("Trying to query remote URI");
797 798 799 800 801
        memset(&uriret, 0, sizeof(uriret));
        if (call(conn, priv, 0,
                 REMOTE_PROC_GET_URI,
                 (xdrproc_t) xdr_void, (char *) NULL,
                 (xdrproc_t) xdr_remote_get_uri_ret, (char *) &uriret) < 0)
802 803
            goto failed;

804
        VIR_DEBUG("Auto-probed URI is %s", uriret.uri);
M
Martin Kletzander 已提交
805
        conn->uri = virURIParse(uriret.uri);
806
        VIR_FREE(uriret.uri);
807
        if (!conn->uri)
808 809 810
            goto failed;
    }

811
    if (!(priv->domainEventState = virDomainEventStateNew()))
812 813
        goto failed;

814 815 816
    /* Successful. */
    retcode = VIR_DRV_OPEN_SUCCESS;

817
 cleanup:
818
    /* Free up the URL and strings. */
819 820 821 822 823
    VIR_FREE(name);
    VIR_FREE(command);
    VIR_FREE(sockname);
    VIR_FREE(authtype);
    VIR_FREE(netcat);
824
    VIR_FREE(sshauth);
825
    VIR_FREE(keyfile);
826 827
    VIR_FREE(username);
    VIR_FREE(port);
828
    VIR_FREE(pkipath);
829 830
    VIR_FREE(knownHostsVerify);
    VIR_FREE(knownHosts);
831 832

    return retcode;
833

834
no_memory:
835
    virReportOOMError();
836 837

 failed:
838 839
    virObjectUnref(priv->remoteProgram);
    virObjectUnref(priv->qemuProgram);
840
    virNetClientClose(priv->client);
841
    virObjectUnref(priv->client);
842
    priv->client = NULL;
843

844
    VIR_FREE(priv->hostname);
845
    goto cleanup;
846
}
847 848
#undef EXTRACT_URI_ARG_STR
#undef EXTRACT_URI_ARG_BOOL
849

850
static struct private_data *
851
remoteAllocPrivateData(void)
852
{
853
    struct private_data *priv;
854
    if (VIR_ALLOC(priv) < 0) {
855
        virReportOOMError();
856
        return NULL;
857 858
    }

859
    if (virMutexInit(&priv->lock) < 0) {
860 861
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("cannot initialize mutex"));
862
        VIR_FREE(priv);
863
        return NULL;
864 865 866
    }
    remoteDriverLock(priv);
    priv->localUses = 1;
867 868 869 870 871 872 873

    return priv;
}

static int
remoteOpenSecondaryDriver(virConnectPtr conn,
                          virConnectAuthPtr auth,
E
Eric Blake 已提交
874
                          unsigned int flags,
875 876 877 878 879
                          struct private_data **priv)
{
    int ret;
    int rflags = 0;

880
    if (!((*priv) = remoteAllocPrivateData()))
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900
        return VIR_DRV_OPEN_ERROR;

    if (flags & VIR_CONNECT_RO)
        rflags |= VIR_DRV_OPEN_REMOTE_RO;

    ret = doRemoteOpen(conn, *priv, auth, rflags);
    if (ret != VIR_DRV_OPEN_SUCCESS) {
        remoteDriverUnlock(*priv);
        VIR_FREE(*priv);
    } else {
        (*priv)->localUses = 1;
        remoteDriverUnlock(*priv);
    }

    return ret;
}

static virDrvOpenStatus
remoteOpen (virConnectPtr conn,
            virConnectAuthPtr auth,
901
            unsigned int flags)
902 903 904
{
    struct private_data *priv;
    int ret, rflags = 0;
905
    const char *autostart = getenv("LIBVIRT_AUTOSTART");
906

907
    if (inside_daemon && (!conn->uri || (conn->uri && !conn->uri->server)))
908 909
        return VIR_DRV_OPEN_DECLINED;

910
    if (!(priv = remoteAllocPrivateData()))
911
        return VIR_DRV_OPEN_ERROR;
912

913
    if (flags & VIR_CONNECT_RO)
914 915
        rflags |= VIR_DRV_OPEN_REMOTE_RO;

916 917 918 919 920 921 922 923 924
    /*
     * If no servername is given, and no +XXX
     * transport is listed, or transport is unix,
     * and path is /session, and uid is unprivileged
     * then auto-spawn a daemon.
     */
    if (conn->uri &&
        !conn->uri->server &&
        conn->uri->path &&
D
Daniel P. Berrange 已提交
925
        conn->uri->scheme &&
926 927
        ((strchr(conn->uri->scheme, '+') == 0)||
         (strstr(conn->uri->scheme, "+unix") != NULL)) &&
928 929
        (STREQ(conn->uri->path, "/session") ||
         STRPREFIX(conn->uri->scheme, "test+")) &&
930
        getuid() > 0) {
931
        VIR_DEBUG("Auto-spawn user daemon instance");
932
        rflags |= VIR_DRV_OPEN_REMOTE_USER;
933 934 935
        if (!autostart ||
            STRNEQ(autostart, "0"))
            rflags |= VIR_DRV_OPEN_REMOTE_AUTOSTART;
936 937 938
    }

    /*
J
John Levon 已提交
939 940 941 942
     * If URI is NULL, then do a UNIX connection possibly auto-spawning
     * unprivileged server and probe remote server for URI. On Solaris,
     * this isn't supported, but we may be privileged enough to connect
     * to the UNIX socket anyway.
943 944
     */
    if (!conn->uri) {
945
        VIR_DEBUG("Auto-probe remote URI");
J
John Levon 已提交
946
#ifndef __sun
947
        if (getuid() > 0) {
948
            VIR_DEBUG("Auto-spawn user daemon instance");
949
            rflags |= VIR_DRV_OPEN_REMOTE_USER;
950 951 952
            if (!autostart ||
                STRNEQ(autostart, "0"))
                rflags |= VIR_DRV_OPEN_REMOTE_AUTOSTART;
953
        }
J
John Levon 已提交
954
#endif
955
    }
956

957
    ret = doRemoteOpen(conn, priv, auth, rflags);
958 959
    if (ret != VIR_DRV_OPEN_SUCCESS) {
        conn->privateData = NULL;
960
        remoteDriverUnlock(priv);
961
        VIR_FREE(priv);
962 963
    } else {
        conn->privateData = priv;
964
        remoteDriverUnlock(priv);
965 966 967 968 969
    }
    return ret;
}


970 971
/* In a string "driver+transport" return a pointer to "transport". */
static char *
972
get_transport_from_scheme(char *scheme)
973
{
974 975
    char *p = strchr(scheme, '+');
    return p ? p + 1 : NULL;
976 977
}

978
/*----------------------------------------------------------------------*/
979

980 981

static int
982
doRemoteClose(virConnectPtr conn, struct private_data *priv)
983
{
984 985
    int ret = 0;

986 987 988
    if (call(conn, priv, 0, REMOTE_PROC_CLOSE,
             (xdrproc_t) xdr_void, (char *) NULL,
             (xdrproc_t) xdr_void, (char *) NULL) == -1)
989
        ret = -1;
990

991
    virObjectUnref(priv->tls);
992
    priv->tls = NULL;
993
    virNetClientClose(priv->client);
994
    virObjectUnref(priv->client);
995
    priv->client = NULL;
996 997
    virObjectUnref(priv->remoteProgram);
    virObjectUnref(priv->qemuProgram);
998 999 1000 1001 1002 1003 1004 1005 1006 1007
    priv->remoteProgram = priv->qemuProgram = NULL;

    /* Free hostname copy */
    VIR_FREE(priv->hostname);

    /* See comment for remoteType. */
    VIR_FREE(priv->type);

    virDomainEventStateFree(priv->domainEventState);
    priv->domainEventState = NULL;
1008

1009
    return ret;
1010 1011
}

1012
static int
1013
remoteClose(virConnectPtr conn)
1014
{
1015 1016
    int ret = 0;
    struct private_data *priv = conn->privateData;
1017

1018 1019 1020 1021 1022 1023 1024 1025
    remoteDriverLock(priv);
    priv->localUses--;
    if (!priv->localUses) {
        ret = doRemoteClose(conn, priv);
        conn->privateData = NULL;
        remoteDriverUnlock(priv);
        virMutexDestroy(&priv->lock);
        VIR_FREE (priv);
1026
    }
1027 1028
    if (priv)
        remoteDriverUnlock(priv);
1029

1030 1031
    return ret;
}
1032

1033

1034 1035 1036 1037 1038 1039 1040 1041 1042
/* Unfortunately this function is defined to return a static string.
 * Since the remote end always answers with the same type (for a
 * single connection anyway) we cache the type in the connection's
 * private data, and free it when we close the connection.
 *
 * See also:
 * http://www.redhat.com/archives/libvir-list/2007-February/msg00096.html
 */
static const char *
1043
remoteType(virConnectPtr conn)
1044 1045 1046 1047
{
    char *rv = NULL;
    remote_get_type_ret ret;
    struct private_data *priv = conn->privateData;
1048

1049
    remoteDriverLock(priv);
1050

1051 1052 1053 1054 1055
    /* Cached? */
    if (priv->type) {
        rv = priv->type;
        goto done;
    }
1056

1057 1058 1059 1060
    memset(&ret, 0, sizeof(ret));
    if (call(conn, priv, 0, REMOTE_PROC_GET_TYPE,
             (xdrproc_t) xdr_void, (char *) NULL,
             (xdrproc_t) xdr_remote_get_type_ret, (char *) &ret) == -1)
1061
        goto done;
1062

1063 1064
    /* Stash. */
    rv = priv->type = ret.type;
1065

1066 1067 1068 1069
done:
    remoteDriverUnlock(priv);
    return rv;
}
1070

1071 1072 1073 1074 1075 1076
static int remoteIsSecure(virConnectPtr conn)
{
    int rv = -1;
    struct private_data *priv = conn->privateData;
    remote_is_secure_ret ret;
    remoteDriverLock(priv);
1077

1078 1079 1080 1081
    memset(&ret, 0, sizeof(ret));
    if (call(conn, priv, 0, REMOTE_PROC_IS_SECURE,
             (xdrproc_t) xdr_void, (char *) NULL,
             (xdrproc_t) xdr_remote_is_secure_ret, (char *) &ret) == -1)
1082
        goto done;
1083

1084 1085 1086 1087 1088 1089 1090 1091 1092
    /* We claim to be secure, if the remote driver
     * transport itself is secure, and the remote
     * HV connection is secure
     *
     * ie, we don't want to claim to be secure if the
     * remote driver is used to connect to a XenD
     * driver using unencrypted HTTP:/// access
     */
    rv = priv->is_secure && ret.secure ? 1 : 0;
1093

1094 1095 1096 1097
done:
    remoteDriverUnlock(priv);
    return rv;
}
1098

1099 1100 1101 1102 1103 1104 1105
static int remoteIsEncrypted(virConnectPtr conn)
{
    int rv = -1;
    int encrypted = 0;
    struct private_data *priv = conn->privateData;
    remote_is_secure_ret ret;
    remoteDriverLock(priv);
1106

1107 1108 1109 1110
    memset(&ret, 0, sizeof(ret));
    if (call(conn, priv, 0, REMOTE_PROC_IS_SECURE,
             (xdrproc_t) xdr_void, (char *) NULL,
             (xdrproc_t) xdr_remote_is_secure_ret, (char *) &ret) == -1)
1111
        goto done;
1112

1113 1114
    if (virNetClientIsEncrypted(priv->client))
        encrypted = 1;
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130

    /* We claim to be encrypted, if the remote driver
     * transport itself is encrypted, and the remote
     * HV connection is secure.
     *
     * Yes, we really don't check the remote 'encrypted'
     * option, since it will almost always be false,
     * even if secure (eg UNIX sockets).
     */
    rv = encrypted && ret.secure ? 1 : 0;

done:
    remoteDriverUnlock(priv);
    return rv;
}

1131
static int
1132 1133 1134 1135
remoteNodeGetCPUStats(virConnectPtr conn,
                      int cpuNum,
                      virNodeCPUStatsPtr params, int *nparams,
                      unsigned int flags)
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
{
    int rv = -1;
    remote_node_get_cpu_stats_args args;
    remote_node_get_cpu_stats_ret ret;
    int i = -1;
    struct private_data *priv = conn->privateData;

    remoteDriverLock(priv);

    args.nparams = *nparams;
    args.cpuNum = cpuNum;
    args.flags = flags;

1149 1150 1151 1152 1153 1154
    memset(&ret, 0, sizeof(ret));
    if (call(conn, priv, 0, REMOTE_PROC_NODE_GET_CPU_STATS,
             (xdrproc_t) xdr_remote_node_get_cpu_stats_args,
             (char *) &args,
             (xdrproc_t) xdr_remote_node_get_cpu_stats_ret,
             (char *) &ret) == -1)
1155 1156 1157 1158 1159
        goto done;

    /* Check the length of the returned list carefully. */
    if (ret.params.params_len > REMOTE_NODE_CPU_STATS_MAX ||
        ret.params.params_len > *nparams) {
1160 1161 1162
        virReportError(VIR_ERR_RPC, "%s",
                       _("remoteNodeGetCPUStats: "
                         "returned number of stats exceeds limit"));
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178
        goto cleanup;
    }
    /* Handle the case when the caller does not know the number of stats
     * and is asking for the number of stats supported
     */
    if (*nparams == 0) {
        *nparams = ret.nparams;
        rv = 0;
        goto cleanup;
    }

    *nparams = ret.params.params_len;

    /* Deserialise the result. */
    for (i = 0; i < *nparams; ++i) {
        if (virStrcpyStatic(params[i].field, ret.params.params_val[i].field) == NULL) {
1179 1180 1181
            virReportError(VIR_ERR_INTERNAL_ERROR,
                           _("Stats %s too big for destination"),
                           ret.params.params_val[i].field);
1182 1183 1184 1185 1186 1187 1188 1189
            goto cleanup;
        }
        params[i].value = ret.params.params_val[i].value;
    }

    rv = 0;

cleanup:
1190
    xdr_free((xdrproc_t) xdr_remote_node_get_cpu_stats_ret, (char *) &ret);
1191 1192 1193 1194 1195
done:
    remoteDriverUnlock(priv);
    return rv;
}

1196
static int
1197 1198 1199 1200 1201
remoteNodeGetMemoryStats(virConnectPtr conn,
                         int cellNum,
                         virNodeMemoryStatsPtr params,
                         int *nparams,
                         unsigned int flags)
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214
{
    int rv = -1;
    remote_node_get_memory_stats_args args;
    remote_node_get_memory_stats_ret ret;
    int i = -1;
    struct private_data *priv = conn->privateData;

    remoteDriverLock(priv);

    args.nparams = *nparams;
    args.cellNum = cellNum;
    args.flags = flags;

1215
    memset (&ret, 0, sizeof(ret));
1216 1217 1218
    if (call(conn, priv, 0, REMOTE_PROC_NODE_GET_MEMORY_STATS,
             (xdrproc_t) xdr_remote_node_get_memory_stats_args, (char *) &args,
             (xdrproc_t) xdr_remote_node_get_memory_stats_ret, (char *) &ret) == -1)
1219 1220 1221 1222 1223
        goto done;

    /* Check the length of the returned list carefully. */
    if (ret.params.params_len > REMOTE_NODE_MEMORY_STATS_MAX ||
        ret.params.params_len > *nparams) {
1224 1225 1226
        virReportError(VIR_ERR_RPC, "%s",
                       _("remoteNodeGetMemoryStats: "
                         "returned number of stats exceeds limit"));
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242
        goto cleanup;
    }
    /* Handle the case when the caller does not know the number of stats
     * and is asking for the number of stats supported
     */
    if (*nparams == 0) {
        *nparams = ret.nparams;
        rv = 0;
        goto cleanup;
    }

    *nparams = ret.params.params_len;

    /* Deserialise the result. */
    for (i = 0; i < *nparams; ++i) {
        if (virStrcpyStatic(params[i].field, ret.params.params_val[i].field) == NULL) {
1243 1244 1245
            virReportError(VIR_ERR_INTERNAL_ERROR,
                           _("Stats %s too big for destination"),
                           ret.params.params_val[i].field);
1246 1247 1248 1249 1250 1251 1252 1253
            goto cleanup;
        }
        params[i].value = ret.params.params_val[i].value;
    }

    rv = 0;

cleanup:
1254
    xdr_free((xdrproc_t) xdr_remote_node_get_memory_stats_ret, (char *) &ret);
1255 1256 1257 1258 1259
done:
    remoteDriverUnlock(priv);
    return rv;
}

1260 1261
static int
remoteNodeGetCellsFreeMemory(virConnectPtr conn,
1262 1263 1264
                             unsigned long long *freeMems,
                             int startCell,
                             int maxCells)
1265
{
1266
    int rv = -1;
1267 1268 1269
    remote_node_get_cells_free_memory_args args;
    remote_node_get_cells_free_memory_ret ret;
    int i;
1270
    struct private_data *priv = conn->privateData;
1271

1272 1273
    remoteDriverLock(priv);

1274
    if (maxCells > REMOTE_NODE_MAX_CELLS) {
1275 1276 1277
        virReportError(VIR_ERR_RPC,
                       _("too many NUMA cells: %d > %d"),
                       maxCells, REMOTE_NODE_MAX_CELLS);
1278
        goto done;
1279 1280 1281
    }

    args.startCell = startCell;
1282
    args.maxcells = maxCells;
1283

1284 1285 1286 1287
    memset(&ret, 0, sizeof(ret));
    if (call(conn, priv, 0, REMOTE_PROC_NODE_GET_CELLS_FREE_MEMORY,
             (xdrproc_t) xdr_remote_node_get_cells_free_memory_args, (char *)&args,
             (xdrproc_t) xdr_remote_node_get_cells_free_memory_ret, (char *)&ret) == -1)
1288
        goto done;
1289

1290 1291
    for (i = 0 ; i < ret.cells.cells_len ; i++)
        freeMems[i] = ret.cells.cells_val[i];
1292 1293 1294

    xdr_free((xdrproc_t) xdr_remote_node_get_cells_free_memory_ret, (char *) &ret);

1295
    rv = ret.cells.cells_len;
1296 1297

done:
1298
    remoteDriverUnlock(priv);
1299
    return rv;
1300 1301
}

1302
static int
1303
remoteListDomains(virConnectPtr conn, int *ids, int maxids)
1304
{
1305
    int rv = -1;
1306 1307 1308
    int i;
    remote_list_domains_args args;
    remote_list_domains_ret ret;
1309
    struct private_data *priv = conn->privateData;
1310

1311 1312
    remoteDriverLock(priv);

1313
    if (maxids > REMOTE_DOMAIN_ID_LIST_MAX) {
1314 1315 1316
        virReportError(VIR_ERR_RPC,
                       _("too many remote domain IDs: %d > %d"),
                       maxids, REMOTE_DOMAIN_ID_LIST_MAX);
1317
        goto done;
1318 1319 1320
    }
    args.maxids = maxids;

1321 1322 1323 1324
    memset(&ret, 0, sizeof(ret));
    if (call(conn, priv, 0, REMOTE_PROC_LIST_DOMAINS,
             (xdrproc_t) xdr_remote_list_domains_args, (char *) &args,
             (xdrproc_t) xdr_remote_list_domains_ret, (char *) &ret) == -1)
1325
        goto done;
1326 1327

    if (ret.ids.ids_len > maxids) {
1328 1329 1330
        virReportError(VIR_ERR_RPC,
                       _("too many remote domain IDs: %d > %d"),
                       ret.ids.ids_len, maxids);
1331
        goto cleanup;
1332 1333 1334 1335 1336
    }

    for (i = 0; i < ret.ids.ids_len; ++i)
        ids[i] = ret.ids.ids_val[i];

1337 1338 1339
    rv = ret.ids.ids_len;

cleanup:
1340
    xdr_free((xdrproc_t) xdr_remote_list_domains_ret, (char *) &ret);
1341

1342
done:
1343
    remoteDriverUnlock(priv);
1344
    return rv;
1345 1346
}

1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409
static int
remoteConnectListAllDomains(virConnectPtr conn,
                            virDomainPtr **domains,
                            unsigned int flags)
{
    int rv = -1;
    int i;
    virDomainPtr *doms = NULL;
    remote_connect_list_all_domains_args args;
    remote_connect_list_all_domains_ret ret;

    struct private_data *priv = conn->privateData;

    remoteDriverLock(priv);

    args.need_results = !!domains;
    args.flags = flags;

    memset(&ret, 0, sizeof(ret));
    if (call(conn,
             priv,
             0,
             REMOTE_PROC_CONNECT_LIST_ALL_DOMAINS,
             (xdrproc_t) xdr_remote_connect_list_all_domains_args,
             (char *) &args,
             (xdrproc_t) xdr_remote_connect_list_all_domains_ret,
             (char *) &ret) == -1)
        goto done;

    if (domains) {
        if (VIR_ALLOC_N(doms, ret.domains.domains_len + 1) < 0) {
            virReportOOMError();
            goto cleanup;
        }

        for (i = 0; i < ret.domains.domains_len; i++) {
            doms[i] = get_nonnull_domain(conn, ret.domains.domains_val[i]);
            if (!doms[i]) {
                virReportOOMError();
                goto cleanup;
            }
        }
        *domains = doms;
        doms = NULL;
    }

    rv = ret.ret;

cleanup:
    if (doms) {
        for (i = 0; i < ret.domains.domains_len; i++)
            if (doms[i])
                virDomainFree(doms[i]);
        VIR_FREE(doms);
    }

    xdr_free((xdrproc_t) xdr_remote_connect_list_all_domains_ret, (char *) &ret);

done:
    remoteDriverUnlock(priv);
    return rv;
}

1410 1411 1412 1413 1414 1415 1416 1417 1418 1419
/* Helper to free typed parameters. */
static void
remoteFreeTypedParameters(remote_typed_param *args_params_val,
                          u_int args_params_len)
{
    u_int i;

    if (args_params_val == NULL)
        return;

1420
    for (i = 0; i < args_params_len; i++) {
1421
        VIR_FREE(args_params_val[i].field);
1422 1423 1424
        if (args_params_val[i].value.type == VIR_TYPED_PARAM_STRING)
            VIR_FREE(args_params_val[i].value.remote_typed_param_value_u.s);
    }
1425 1426 1427 1428

    VIR_FREE(args_params_val);
}

1429
/* Helper to serialize typed parameters. */
1430
static int
1431 1432
remoteSerializeTypedParameters(virTypedParameterPtr params,
                               int nparams,
1433 1434
                               remote_typed_param **args_params_val,
                               u_int *args_params_len)
1435
{
1436
    int i;
1437
    int rv = -1;
1438
    remote_typed_param *val;
1439

1440 1441
    *args_params_len = nparams;
    if (VIR_ALLOC_N(val, nparams) < 0) {
1442
        virReportOOMError();
1443
        goto cleanup;
1444 1445 1446
    }

    for (i = 0; i < nparams; ++i) {
1447
        /* call() will free this: */
1448 1449
        val[i].field = strdup (params[i].field);
        if (val[i].field == NULL) {
1450
            virReportOOMError();
1451
            goto cleanup;
1452
        }
1453
        val[i].value.type = params[i].type;
1454
        switch (params[i].type) {
1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472
        case VIR_TYPED_PARAM_INT:
            val[i].value.remote_typed_param_value_u.i = params[i].value.i;
            break;
        case VIR_TYPED_PARAM_UINT:
            val[i].value.remote_typed_param_value_u.ui = params[i].value.ui;
            break;
        case VIR_TYPED_PARAM_LLONG:
            val[i].value.remote_typed_param_value_u.l = params[i].value.l;
            break;
        case VIR_TYPED_PARAM_ULLONG:
            val[i].value.remote_typed_param_value_u.ul = params[i].value.ul;
            break;
        case VIR_TYPED_PARAM_DOUBLE:
            val[i].value.remote_typed_param_value_u.d = params[i].value.d;
            break;
        case VIR_TYPED_PARAM_BOOLEAN:
            val[i].value.remote_typed_param_value_u.b = params[i].value.b;
            break;
1473 1474 1475 1476 1477 1478 1479
        case VIR_TYPED_PARAM_STRING:
            val[i].value.remote_typed_param_value_u.s = strdup(params[i].value.s);
            if (val[i].value.remote_typed_param_value_u.s == NULL) {
                virReportOOMError();
                goto cleanup;
            }
            break;
1480
        default:
1481 1482
            virReportError(VIR_ERR_RPC, _("unknown parameter type: %d"),
                           params[i].type);
1483
            goto cleanup;
1484 1485 1486
        }
    }

1487 1488 1489 1490 1491
    *args_params_val = val;
    val = NULL;
    rv = 0;

cleanup:
1492
    remoteFreeTypedParameters(val, nparams);
1493 1494 1495 1496 1497
    return rv;
}

/* Helper to deserialize typed parameters. */
static int
1498 1499
remoteDeserializeTypedParameters(remote_typed_param *ret_params_val,
                                 u_int ret_params_len,
1500 1501 1502 1503
                                 int limit,
                                 virTypedParameterPtr params,
                                 int *nparams)
{
1504
    int i = 0;
1505 1506 1507 1508
    int rv = -1;

    /* Check the length of the returned list carefully. */
    if (ret_params_len > limit || ret_params_len > *nparams) {
1509 1510
        virReportError(VIR_ERR_RPC, "%s",
                       _("returned number of parameters exceeds limit"));
1511 1512 1513 1514 1515 1516 1517 1518 1519
        goto cleanup;
    }

    *nparams = ret_params_len;

    /* Deserialise the result. */
    for (i = 0; i < ret_params_len; ++i) {
        if (virStrcpyStatic(params[i].field,
                            ret_params_val[i].field) == NULL) {
1520 1521 1522
            virReportError(VIR_ERR_INTERNAL_ERROR,
                           _("Parameter %s too big for destination"),
                           ret_params_val[i].field);
1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550
            goto cleanup;
        }
        params[i].type = ret_params_val[i].value.type;
        switch (params[i].type) {
        case VIR_TYPED_PARAM_INT:
            params[i].value.i =
                ret_params_val[i].value.remote_typed_param_value_u.i;
            break;
        case VIR_TYPED_PARAM_UINT:
            params[i].value.ui =
                ret_params_val[i].value.remote_typed_param_value_u.ui;
            break;
        case VIR_TYPED_PARAM_LLONG:
            params[i].value.l =
                ret_params_val[i].value.remote_typed_param_value_u.l;
            break;
        case VIR_TYPED_PARAM_ULLONG:
            params[i].value.ul =
                ret_params_val[i].value.remote_typed_param_value_u.ul;
            break;
        case VIR_TYPED_PARAM_DOUBLE:
            params[i].value.d =
                ret_params_val[i].value.remote_typed_param_value_u.d;
            break;
        case VIR_TYPED_PARAM_BOOLEAN:
            params[i].value.b =
                ret_params_val[i].value.remote_typed_param_value_u.b;
            break;
1551 1552 1553 1554 1555 1556 1557 1558
        case VIR_TYPED_PARAM_STRING:
            params[i].value.s =
                strdup(ret_params_val[i].value.remote_typed_param_value_u.s);
            if (params[i].value.s == NULL) {
                virReportOOMError();
                goto cleanup;
            }
            break;
1559
        default:
1560 1561
            virReportError(VIR_ERR_RPC, _("unknown parameter type: %d"),
                           params[i].type);
1562 1563 1564 1565 1566 1567 1568
            goto cleanup;
        }
    }

    rv = 0;

cleanup:
A
Alex Jia 已提交
1569 1570
    if (rv < 0)
        virTypedParameterArrayClear(params, i);
1571 1572 1573
    return rv;
}

1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584
static int
remoteDeserializeDomainDiskErrors(remote_domain_disk_error *ret_errors_val,
                                  u_int ret_errors_len,
                                  int limit,
                                  virDomainDiskErrorPtr errors,
                                  int maxerrors)
{
    int i = 0;
    int j;

    if (ret_errors_len > limit || ret_errors_len > maxerrors) {
1585 1586
        virReportError(VIR_ERR_RPC, "%s",
                       _("returned number of disk errors exceeds limit"));
1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606
        goto error;
    }

    for (i = 0; i < ret_errors_len; i++) {
        if (!(errors[i].disk = strdup(ret_errors_val[i].disk))) {
            virReportOOMError();
            goto error;
        }
        errors[i].error = ret_errors_val[i].error;
    }

    return 0;

error:
    for (j = 0; j < i; j++)
        VIR_FREE(errors[i].disk);

    return -1;
}

1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625
static int
remoteDomainBlockStatsFlags(virDomainPtr domain,
                            const char *path,
                            virTypedParameterPtr params,
                            int *nparams,
                            unsigned int flags)
{
    int rv = -1;
    remote_domain_block_stats_flags_args args;
    remote_domain_block_stats_flags_ret ret;
    struct private_data *priv = domain->conn->privateData;

    remoteDriverLock(priv);

    make_nonnull_domain (&args.dom, domain);
    args.nparams = *nparams;
    args.path = (char *) path;
    args.flags = flags;

1626
    memset (&ret, 0, sizeof(ret));
1627 1628 1629 1630 1631 1632 1633 1634
    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_BLOCK_STATS_FLAGS,
              (xdrproc_t) xdr_remote_domain_block_stats_flags_args, (char *) &args,
              (xdrproc_t) xdr_remote_domain_block_stats_flags_ret, (char *) &ret) == -1)
        goto done;

    /* Check the length of the returned list carefully. */
    if (ret.params.params_len > REMOTE_DOMAIN_BLOCK_STATS_PARAMETERS_MAX ||
        ret.params.params_len > *nparams) {
1635 1636 1637
        virReportError(VIR_ERR_RPC, "%s",
                       _("remoteDomainBlockStatsFlags: "
                         "returned number of stats exceeds limit"));
1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669
        goto cleanup;
    }

    /* Handle the case when the caller does not know the number of stats
     * and is asking for the number of stats supported
     */
    if (*nparams == 0) {
        *nparams = ret.nparams;
        rv = 0;
        goto cleanup;
    }

    *nparams = ret.params.params_len;

    /* Deserialise the result. */
    if (remoteDeserializeTypedParameters(ret.params.params_val,
                                         ret.params.params_len,
                                         REMOTE_DOMAIN_MEMORY_PARAMETERS_MAX,
                                         params,
                                         nparams) < 0)
        goto cleanup;

    rv = 0;

cleanup:
    xdr_free ((xdrproc_t) xdr_remote_domain_block_stats_flags_ret,
              (char *) &ret);
done:
    remoteDriverUnlock(priv);
    return rv;
}

1670 1671
static int
remoteDomainGetMemoryParameters (virDomainPtr domain,
1672
                                 virTypedParameterPtr params, int *nparams,
1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685
                                 unsigned int flags)
{
    int rv = -1;
    remote_domain_get_memory_parameters_args args;
    remote_domain_get_memory_parameters_ret ret;
    struct private_data *priv = domain->conn->privateData;

    remoteDriverLock(priv);

    make_nonnull_domain (&args.dom, domain);
    args.nparams = *nparams;
    args.flags = flags;

1686
    memset (&ret, 0, sizeof(ret));
1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700
    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_MEMORY_PARAMETERS,
              (xdrproc_t) xdr_remote_domain_get_memory_parameters_args, (char *) &args,
              (xdrproc_t) xdr_remote_domain_get_memory_parameters_ret, (char *) &ret) == -1)
        goto done;

    /* Handle the case when the caller does not know the number of parameters
     * and is asking for the number of parameters supported
     */
    if (*nparams == 0) {
        *nparams = ret.nparams;
        rv = 0;
        goto cleanup;
    }

1701 1702
    if (remoteDeserializeTypedParameters(ret.params.params_val,
                                         ret.params.params_len,
1703 1704 1705 1706
                                         REMOTE_DOMAIN_MEMORY_PARAMETERS_MAX,
                                         params,
                                         nparams) < 0)
        goto cleanup;
1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717

    rv = 0;

cleanup:
    xdr_free ((xdrproc_t) xdr_remote_domain_get_memory_parameters_ret,
              (char *) &ret);
done:
    remoteDriverUnlock(priv);
    return rv;
}

1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733
static int
remoteDomainGetNumaParameters (virDomainPtr domain,
                               virTypedParameterPtr params, int *nparams,
                               unsigned int flags)
{
    int rv = -1;
    remote_domain_get_numa_parameters_args args;
    remote_domain_get_numa_parameters_ret ret;
    struct private_data *priv = domain->conn->privateData;

    remoteDriverLock(priv);

    make_nonnull_domain (&args.dom, domain);
    args.nparams = *nparams;
    args.flags = flags;

1734
    memset (&ret, 0, sizeof(ret));
1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765
    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_NUMA_PARAMETERS,
              (xdrproc_t) xdr_remote_domain_get_numa_parameters_args, (char *) &args,
              (xdrproc_t) xdr_remote_domain_get_numa_parameters_ret, (char *) &ret) == -1)
        goto done;

    /* Handle the case when the caller does not know the number of parameters
     * and is asking for the number of parameters supported
     */
    if (*nparams == 0) {
        *nparams = ret.nparams;
        rv = 0;
        goto cleanup;
    }

    if (remoteDeserializeTypedParameters(ret.params.params_val,
                                         ret.params.params_len,
                                         REMOTE_DOMAIN_NUMA_PARAMETERS_MAX,
                                         params,
                                         nparams) < 0)
        goto cleanup;

    rv = 0;

cleanup:
    xdr_free ((xdrproc_t) xdr_remote_domain_get_numa_parameters_ret,
              (char *) &ret);
done:
    remoteDriverUnlock(priv);
    return rv;
}

1766 1767
static int
remoteDomainGetBlkioParameters (virDomainPtr domain,
1768 1769
                                virTypedParameterPtr params, int *nparams,
                                unsigned int flags)
1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781
{
    int rv = -1;
    remote_domain_get_blkio_parameters_args args;
    remote_domain_get_blkio_parameters_ret ret;
    struct private_data *priv = domain->conn->privateData;

    remoteDriverLock(priv);

    make_nonnull_domain (&args.dom, domain);
    args.nparams = *nparams;
    args.flags = flags;

1782
    memset (&ret, 0, sizeof(ret));
1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796
    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_BLKIO_PARAMETERS,
              (xdrproc_t) xdr_remote_domain_get_blkio_parameters_args, (char *) &args,
              (xdrproc_t) xdr_remote_domain_get_blkio_parameters_ret, (char *) &ret) == -1)
        goto done;

    /* Handle the case when the caller does not know the number of parameters
     * and is asking for the number of parameters supported
     */
    if (*nparams == 0) {
        *nparams = ret.nparams;
        rv = 0;
        goto cleanup;
    }

1797 1798
    if (remoteDeserializeTypedParameters(ret.params.params_val,
                                         ret.params.params_len,
1799 1800 1801 1802
                                         REMOTE_DOMAIN_BLKIO_PARAMETERS_MAX,
                                         params,
                                         nparams) < 0)
        goto cleanup;
1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813

    rv = 0;

cleanup:
    xdr_free ((xdrproc_t) xdr_remote_domain_get_blkio_parameters_ret,
              (char *) &ret);
done:
    remoteDriverUnlock(priv);
    return rv;
}

1814
static int
E
Eric Blake 已提交
1815
remoteDomainGetVcpuPinInfo (virDomainPtr domain,
1816 1817 1818 1819 1820 1821 1822
                            int ncpumaps,
                            unsigned char *cpumaps,
                            int maplen,
                            unsigned int flags)
{
    int rv = -1;
    int i;
E
Eric Blake 已提交
1823 1824
    remote_domain_get_vcpu_pin_info_args args;
    remote_domain_get_vcpu_pin_info_ret ret;
1825 1826 1827 1828 1829
    struct private_data *priv = domain->conn->privateData;

    remoteDriverLock(priv);

    if (ncpumaps > REMOTE_VCPUINFO_MAX) {
1830 1831 1832
        virReportError(VIR_ERR_RPC,
                       _("vCPU count exceeds maximum: %d > %d"),
                       ncpumaps, REMOTE_VCPUINFO_MAX);
1833 1834 1835 1836 1837
        goto done;
    }

    if (INT_MULTIPLY_OVERFLOW(ncpumaps, maplen) ||
        ncpumaps * maplen > REMOTE_CPUMAPS_MAX) {
1838 1839 1840
        virReportError(VIR_ERR_RPC,
                       _("vCPU map buffer length exceeds maximum: %d > %d"),
                       ncpumaps * maplen, REMOTE_CPUMAPS_MAX);
1841 1842 1843 1844 1845 1846 1847 1848
        goto done;
    }

    make_nonnull_domain (&args.dom, domain);
    args.ncpumaps = ncpumaps;
    args.maplen = maplen;
    args.flags = flags;

1849
    memset (&ret, 0, sizeof(ret));
1850

E
Eric Blake 已提交
1851 1852
    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_VCPU_PIN_INFO,
              (xdrproc_t) xdr_remote_domain_get_vcpu_pin_info_args,
1853
              (char *) &args,
E
Eric Blake 已提交
1854
              (xdrproc_t) xdr_remote_domain_get_vcpu_pin_info_ret,
1855 1856 1857 1858
              (char *) &ret) == -1)
        goto done;

    if (ret.num > ncpumaps) {
1859 1860 1861
        virReportError(VIR_ERR_RPC,
                       _("host reports too many vCPUs: %d > %d"),
                       ret.num, ncpumaps);
1862 1863 1864 1865
        goto cleanup;
    }

    if (ret.cpumaps.cpumaps_len > ncpumaps * maplen) {
1866 1867 1868
        virReportError(VIR_ERR_RPC,
                       _("host reports map buffer length exceeds maximum: %d > %d"),
                       ret.cpumaps.cpumaps_len, ncpumaps * maplen);
1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879
        goto cleanup;
    }

    memset (cpumaps, 0, ncpumaps * maplen);

    for (i = 0; i < ret.cpumaps.cpumaps_len; ++i)
        cpumaps[i] = ret.cpumaps.cpumaps_val[i];

    rv = ret.num;

cleanup:
E
Eric Blake 已提交
1880
    xdr_free ((xdrproc_t) xdr_remote_domain_get_vcpu_pin_info_ret, (char *) &ret);
1881 1882 1883 1884 1885 1886

done:
    remoteDriverUnlock(priv);
    return rv;
}

1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983
static int
remoteDomainPinEmulator (virDomainPtr dom,
                         unsigned char *cpumap,
                         int cpumaplen,
                         unsigned int flags)
{
    int rv = -1;
    struct private_data *priv = dom->conn->privateData;
    remote_domain_pin_emulator_args args;

    remoteDriverLock(priv);

    if (cpumaplen > REMOTE_CPUMAP_MAX) {
        virReportError(VIR_ERR_RPC,
                       _("%s length greater than maximum: %d > %d"),
                       "cpumap", cpumaplen, REMOTE_CPUMAP_MAX);
        goto done;
    }

    make_nonnull_domain(&args.dom, dom);
    args.cpumap.cpumap_val = (char *)cpumap;
    args.cpumap.cpumap_len = cpumaplen;
    args.flags = flags;

    if (call(dom->conn, priv, 0, REMOTE_PROC_DOMAIN_PIN_EMULATOR,
             (xdrproc_t) xdr_remote_domain_pin_emulator_args,
             (char *) &args,
             (xdrproc_t) xdr_void, (char *) NULL) == -1) {
        goto done;
    }

    rv = 0;

done:
    remoteDriverUnlock(priv);
    return rv;
}


static int
remoteDomainGetEmulatorPinInfo (virDomainPtr domain,
                                unsigned char *cpumaps,
                                int maplen,
                                unsigned int flags)
{
    int rv = -1;
    int i;
    remote_domain_get_emulator_pin_info_args args;
    remote_domain_get_emulator_pin_info_ret ret;
    struct private_data *priv = domain->conn->privateData;

    remoteDriverLock(priv);

    /* There is only one cpumap for all emulator threads */
    if (maplen > REMOTE_CPUMAPS_MAX) {
        virReportError(VIR_ERR_RPC,
                       _("vCPU map buffer length exceeds maximum: %d > %d"),
                       maplen, REMOTE_CPUMAPS_MAX);
        goto done;
    }

    make_nonnull_domain(&args.dom, domain);
    args.maplen = maplen;
    args.flags = flags;

    memset(&ret, 0, sizeof(ret));

    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_EMULATOR_PIN_INFO,
              (xdrproc_t) xdr_remote_domain_get_emulator_pin_info_args,
              (char *) &args,
              (xdrproc_t) xdr_remote_domain_get_emulator_pin_info_ret,
              (char *) &ret) == -1)
        goto done;

    if (ret.cpumaps.cpumaps_len > maplen) {
        virReportError(VIR_ERR_RPC,
                       _("host reports map buffer length exceeds maximum: %d > %d"),
                       ret.cpumaps.cpumaps_len, maplen);
        goto cleanup;
    }

    memset(cpumaps, 0, maplen);

    for (i = 0; i < ret.cpumaps.cpumaps_len; ++i)
        cpumaps[i] = ret.cpumaps.cpumaps_val[i];

    rv = ret.ret;

cleanup:
    xdr_free ((xdrproc_t) xdr_remote_domain_get_emulator_pin_info_ret,
              (char *) &ret);

done:
    remoteDriverUnlock(priv);
    return rv;
}

1984 1985 1986 1987 1988 1989 1990
static int
remoteDomainGetVcpus (virDomainPtr domain,
                      virVcpuInfoPtr info,
                      int maxinfo,
                      unsigned char *cpumaps,
                      int maplen)
{
1991
    int rv = -1;
1992 1993 1994
    int i;
    remote_domain_get_vcpus_args args;
    remote_domain_get_vcpus_ret ret;
1995
    struct private_data *priv = domain->conn->privateData;
1996

1997 1998
    remoteDriverLock(priv);

1999
    if (maxinfo > REMOTE_VCPUINFO_MAX) {
2000 2001 2002
        virReportError(VIR_ERR_RPC,
                       _("vCPU count exceeds maximum: %d > %d"),
                       maxinfo, REMOTE_VCPUINFO_MAX);
2003
        goto done;
2004
    }
2005 2006
    if (INT_MULTIPLY_OVERFLOW(maxinfo, maplen) ||
        maxinfo * maplen > REMOTE_CPUMAPS_MAX) {
2007 2008 2009
        virReportError(VIR_ERR_RPC,
                       _("vCPU map buffer length exceeds maximum: %d > %d"),
                       maxinfo * maplen, REMOTE_CPUMAPS_MAX);
2010
        goto done;
2011 2012 2013 2014 2015 2016
    }

    make_nonnull_domain (&args.dom, domain);
    args.maxinfo = maxinfo;
    args.maplen = maplen;

2017
    memset (&ret, 0, sizeof(ret));
2018 2019 2020
    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_VCPUS,
              (xdrproc_t) xdr_remote_domain_get_vcpus_args, (char *) &args,
              (xdrproc_t) xdr_remote_domain_get_vcpus_ret, (char *) &ret) == -1)
2021
        goto done;
2022 2023

    if (ret.info.info_len > maxinfo) {
2024 2025 2026
        virReportError(VIR_ERR_RPC,
                       _("host reports too many vCPUs: %d > %d"),
                       ret.info.info_len, maxinfo);
2027
        goto cleanup;
2028
    }
2029
    if (ret.cpumaps.cpumaps_len > maxinfo * maplen) {
2030 2031 2032
        virReportError(VIR_ERR_RPC,
                       _("host reports map buffer length exceeds maximum: %d > %d"),
                       ret.cpumaps.cpumaps_len, maxinfo * maplen);
2033
        goto cleanup;
2034 2035
    }

2036
    memset (info, 0, sizeof(virVcpuInfo) * maxinfo);
2037 2038
    memset (cpumaps, 0, maxinfo * maplen);

2039 2040 2041 2042 2043 2044 2045 2046 2047 2048
    for (i = 0; i < ret.info.info_len; ++i) {
        info[i].number = ret.info.info_val[i].number;
        info[i].state = ret.info.info_val[i].state;
        info[i].cpuTime = ret.info.info_val[i].cpu_time;
        info[i].cpu = ret.info.info_val[i].cpu;
    }

    for (i = 0; i < ret.cpumaps.cpumaps_len; ++i)
        cpumaps[i] = ret.cpumaps.cpumaps_val[i];

2049 2050 2051
    rv = ret.info.info_len;

cleanup:
2052
    xdr_free ((xdrproc_t) xdr_remote_domain_get_vcpus_ret, (char *) &ret);
2053 2054

done:
2055
    remoteDriverUnlock(priv);
2056
    return rv;
2057 2058
}

2059 2060 2061 2062 2063 2064
static int
remoteDomainGetSecurityLabel (virDomainPtr domain, virSecurityLabelPtr seclabel)
{
    remote_domain_get_security_label_args args;
    remote_domain_get_security_label_ret ret;
    struct private_data *priv = domain->conn->privateData;
2065 2066 2067
    int rv = -1;

    remoteDriverLock(priv);
2068 2069

    make_nonnull_domain (&args.dom, domain);
2070 2071
    memset (&ret, 0, sizeof(ret));
    memset (seclabel, 0, sizeof(*seclabel));
2072

2073 2074 2075
    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_SECURITY_LABEL,
              (xdrproc_t) xdr_remote_domain_get_security_label_args, (char *)&args,
              (xdrproc_t) xdr_remote_domain_get_security_label_ret, (char *)&ret) == -1) {
2076
        goto done;
2077 2078 2079
    }

    if (ret.label.label_val != NULL) {
2080
        if (strlen (ret.label.label_val) >= sizeof(seclabel->label)) {
2081 2082
            virReportError(VIR_ERR_RPC, _("security label exceeds maximum: %zu"),
                           sizeof(seclabel->label) - 1);
A
Alex Jia 已提交
2083
            goto cleanup;
2084 2085 2086 2087 2088
        }
        strcpy (seclabel->label, ret.label.label_val);
        seclabel->enforcing = ret.enforcing;
    }

2089 2090
    rv = 0;

A
Alex Jia 已提交
2091 2092 2093
cleanup:
    xdr_free((xdrproc_t) xdr_remote_domain_get_security_label_ret, (char *)&ret);

2094 2095 2096
done:
    remoteDriverUnlock(priv);
    return rv;
2097 2098
}

M
Marcelo Cerri 已提交
2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143
static int
remoteDomainGetSecurityLabelList (virDomainPtr domain, virSecurityLabelPtr* seclabels)
{
    remote_domain_get_security_label_list_args args;
    remote_domain_get_security_label_list_ret ret;
    struct private_data *priv = domain->conn->privateData;
    int i, rv = -1;

    remoteDriverLock(priv);

    make_nonnull_domain (&args.dom, domain);
    memset(&ret, 0, sizeof(ret));

    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_SECURITY_LABEL_LIST,
              (xdrproc_t) xdr_remote_domain_get_security_label_list_args, (char *)&args,
              (xdrproc_t) xdr_remote_domain_get_security_label_list_ret, (char *)&ret) == -1) {
        goto done;
    }

    if (VIR_ALLOC_N(*seclabels, ret.labels.labels_len) < 0)
        goto cleanup;

    for (i = 0; i < ret.labels.labels_len; i++) {
        remote_domain_get_security_label_ret *cur = &ret.labels.labels_val[i];
        if (cur->label.label_val != NULL) {
            if (strlen(cur->label.label_val) >= sizeof((*seclabels)->label)) {
                virReportError(VIR_ERR_RPC, _("security label exceeds maximum: %zd"),
                               sizeof((*seclabels)->label) - 1);
                VIR_FREE(*seclabels);
                goto cleanup;
            }
            strcpy((*seclabels)[i].label, cur->label.label_val);
            (*seclabels)[i].enforcing = cur->enforcing;
        }
    }
    rv = ret.ret;

cleanup:
    xdr_free((xdrproc_t) xdr_remote_domain_get_security_label_list_ret, (char *)&ret);

done:
    remoteDriverUnlock(priv);
    return rv;
}

2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159
static int
remoteDomainGetState(virDomainPtr domain,
                     int *state,
                     int *reason,
                     unsigned int flags)
{
    int rv = -1;
    remote_domain_get_state_args args;
    remote_domain_get_state_ret ret;
    struct private_data *priv = domain->conn->privateData;

    remoteDriverLock(priv);

    make_nonnull_domain(&args.dom, domain);
    args.flags = flags;

2160
    memset(&ret, 0, sizeof(ret));
2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176
    if (call(domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_STATE,
             (xdrproc_t) xdr_remote_domain_get_state_args, (char *) &args,
             (xdrproc_t) xdr_remote_domain_get_state_ret, (char *) &ret) == -1)
        goto done;

    *state = ret.state;
    if (reason)
        *reason = ret.reason;

    rv = 0;

done:
    remoteDriverUnlock(priv);
    return rv;
}

2177 2178 2179 2180 2181
static int
remoteNodeGetSecurityModel (virConnectPtr conn, virSecurityModelPtr secmodel)
{
    remote_node_get_security_model_ret ret;
    struct private_data *priv = conn->privateData;
2182 2183 2184
    int rv = -1;

    remoteDriverLock(priv);
2185

2186 2187
    memset (&ret, 0, sizeof(ret));
    memset (secmodel, 0, sizeof(*secmodel));
2188

2189 2190 2191
    if (call (conn, priv, 0, REMOTE_PROC_NODE_GET_SECURITY_MODEL,
              (xdrproc_t) xdr_void, NULL,
              (xdrproc_t) xdr_remote_node_get_security_model_ret, (char *)&ret) == -1) {
2192
        goto done;
2193 2194 2195
    }

    if (ret.model.model_val != NULL) {
2196
        if (strlen (ret.model.model_val) >= sizeof(secmodel->model)) {
2197 2198
            virReportError(VIR_ERR_RPC, _("security model exceeds maximum: %zu"),
                           sizeof(secmodel->model) - 1);
A
Alex Jia 已提交
2199
            goto cleanup;
2200 2201 2202 2203 2204
        }
        strcpy (secmodel->model, ret.model.model_val);
    }

    if (ret.doi.doi_val != NULL) {
2205
        if (strlen (ret.doi.doi_val) >= sizeof(secmodel->doi)) {
2206 2207
            virReportError(VIR_ERR_RPC, _("security doi exceeds maximum: %zu"),
                           sizeof(secmodel->doi) - 1);
A
Alex Jia 已提交
2208
            goto cleanup;
2209 2210 2211
        }
        strcpy (secmodel->doi, ret.doi.doi_val);
    }
2212 2213 2214

    rv = 0;

A
Alex Jia 已提交
2215 2216 2217
cleanup:
    xdr_free((xdrproc_t) xdr_remote_node_get_security_model_ret, (char *)&ret);

2218 2219 2220
done:
    remoteDriverUnlock(priv);
    return rv;
2221 2222
}

2223 2224 2225 2226 2227 2228 2229
static int
remoteDomainMigratePrepare (virConnectPtr dconn,
                            char **cookie, int *cookielen,
                            const char *uri_in, char **uri_out,
                            unsigned long flags, const char *dname,
                            unsigned long resource)
{
2230
    int rv = -1;
2231 2232
    remote_domain_migrate_prepare_args args;
    remote_domain_migrate_prepare_ret ret;
2233
    struct private_data *priv = dconn->privateData;
2234

2235 2236
    remoteDriverLock(priv);

2237 2238 2239 2240 2241
    args.uri_in = uri_in == NULL ? NULL : (char **) &uri_in;
    args.flags = flags;
    args.dname = dname == NULL ? NULL : (char **) &dname;
    args.resource = resource;

2242
    memset (&ret, 0, sizeof(ret));
2243 2244 2245
    if (call (dconn, priv, 0, REMOTE_PROC_DOMAIN_MIGRATE_PREPARE,
              (xdrproc_t) xdr_remote_domain_migrate_prepare_args, (char *) &args,
              (xdrproc_t) xdr_remote_domain_migrate_prepare_ret, (char *) &ret) == -1)
2246
        goto done;
2247 2248 2249 2250 2251 2252 2253 2254

    if (ret.cookie.cookie_len > 0) {
        *cookie = ret.cookie.cookie_val; /* Caller frees. */
        *cookielen = ret.cookie.cookie_len;
    }
    if (ret.uri_out)
        *uri_out = *ret.uri_out; /* Caller frees. */

O
Osier Yang 已提交
2255
    VIR_FREE(ret.uri_out);
2256 2257 2258
    rv = 0;

done:
2259
    remoteDriverUnlock(priv);
2260
    return rv;
2261 2262
}

D
Daniel Veillard 已提交
2263 2264 2265 2266 2267 2268 2269 2270
static int
remoteDomainMigratePrepare2 (virConnectPtr dconn,
                             char **cookie, int *cookielen,
                             const char *uri_in, char **uri_out,
                             unsigned long flags, const char *dname,
                             unsigned long resource,
                             const char *dom_xml)
{
2271
    int rv = -1;
D
Daniel Veillard 已提交
2272 2273
    remote_domain_migrate_prepare2_args args;
    remote_domain_migrate_prepare2_ret ret;
2274
    struct private_data *priv = dconn->privateData;
D
Daniel Veillard 已提交
2275

2276 2277
    remoteDriverLock(priv);

D
Daniel Veillard 已提交
2278 2279 2280 2281 2282 2283
    args.uri_in = uri_in == NULL ? NULL : (char **) &uri_in;
    args.flags = flags;
    args.dname = dname == NULL ? NULL : (char **) &dname;
    args.resource = resource;
    args.dom_xml = (char *) dom_xml;

2284
    memset (&ret, 0, sizeof(ret));
D
Daniel Veillard 已提交
2285 2286 2287
    if (call (dconn, priv, 0, REMOTE_PROC_DOMAIN_MIGRATE_PREPARE2,
              (xdrproc_t) xdr_remote_domain_migrate_prepare2_args, (char *) &args,
              (xdrproc_t) xdr_remote_domain_migrate_prepare2_ret, (char *) &ret) == -1)
2288
        goto done;
D
Daniel Veillard 已提交
2289 2290

    if (ret.cookie.cookie_len > 0) {
2291
        if (!cookie || !cookielen) {
2292 2293
            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                           _("caller ignores cookie or cookielen"));
2294 2295
            goto error;
        }
D
Daniel Veillard 已提交
2296 2297 2298
        *cookie = ret.cookie.cookie_val; /* Caller frees. */
        *cookielen = ret.cookie.cookie_len;
    }
2299 2300
    if (ret.uri_out) {
        if (!uri_out) {
2301 2302
            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                           _("caller ignores uri_out"));
2303 2304
            goto error;
        }
D
Daniel Veillard 已提交
2305
        *uri_out = *ret.uri_out; /* Caller frees. */
2306
    }
D
Daniel Veillard 已提交
2307

2308 2309 2310
    rv = 0;

done:
O
Osier Yang 已提交
2311
    VIR_FREE(ret.uri_out);
2312
    remoteDriverUnlock(priv);
2313
    return rv;
2314 2315 2316 2317 2318 2319
error:
    if (ret.cookie.cookie_len)
        VIR_FREE(ret.cookie.cookie_val);
    if (ret.uri_out)
        VIR_FREE(*ret.uri_out);
    goto done;
D
Daniel Veillard 已提交
2320 2321
}

2322 2323 2324
static int
remoteDomainCreate (virDomainPtr domain)
{
2325
    int rv = -1;
2326
    remote_domain_create_args args;
2327 2328
    remote_domain_lookup_by_uuid_args args2;
    remote_domain_lookup_by_uuid_ret ret2;
2329
    struct private_data *priv = domain->conn->privateData;
2330

2331 2332
    remoteDriverLock(priv);

2333 2334 2335 2336 2337
    make_nonnull_domain (&args.dom, domain);

    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_CREATE,
              (xdrproc_t) xdr_remote_domain_create_args, (char *) &args,
              (xdrproc_t) xdr_void, (char *) NULL) == -1)
2338
        goto done;
2339

2340 2341 2342 2343 2344
    /* Need to do a lookup figure out ID of newly started guest, because
     * bug in design of REMOTE_PROC_DOMAIN_CREATE means we aren't getting
     * it returned.
     */
    memcpy (args2.uuid, domain->uuid, VIR_UUID_BUFLEN);
D
Daniel P. Berrange 已提交
2345
    memset (&ret2, 0, sizeof(ret2));
2346 2347 2348 2349 2350 2351 2352 2353
    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_LOOKUP_BY_UUID,
              (xdrproc_t) xdr_remote_domain_lookup_by_uuid_args, (char *) &args2,
              (xdrproc_t) xdr_remote_domain_lookup_by_uuid_ret, (char *) &ret2) == -1)
        goto done;

    domain->id = ret2.dom.id;
    xdr_free ((xdrproc_t) &xdr_remote_domain_lookup_by_uuid_ret, (char *) &ret2);

2354 2355 2356
    rv = 0;

done:
2357
    remoteDriverUnlock(priv);
2358
    return rv;
2359 2360
}

2361 2362
static char *
remoteDomainGetSchedulerType (virDomainPtr domain, int *nparams)
2363
{
2364 2365 2366
    char *rv = NULL;
    remote_domain_get_scheduler_type_args args;
    remote_domain_get_scheduler_type_ret ret;
2367
    struct private_data *priv = domain->conn->privateData;
2368

2369 2370
    remoteDriverLock(priv);

2371 2372
    make_nonnull_domain (&args.dom, domain);

2373
    memset (&ret, 0, sizeof(ret));
2374 2375 2376
    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_SCHEDULER_TYPE,
              (xdrproc_t) xdr_remote_domain_get_scheduler_type_args, (char *) &args,
              (xdrproc_t) xdr_remote_domain_get_scheduler_type_ret, (char *) &ret) == -1)
2377
        goto done;
2378 2379 2380 2381

    if (nparams) *nparams = ret.nparams;

    /* Caller frees this. */
2382 2383 2384
    rv = ret.type;

done:
2385
    remoteDriverUnlock(priv);
2386
    return rv;
2387 2388
}

2389 2390 2391
static int
remoteDomainMemoryStats (virDomainPtr domain,
                         struct _virDomainMemoryStat *stats,
2392 2393
                         unsigned int nr_stats,
                         unsigned int flags)
2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404
{
    int rv = -1;
    remote_domain_memory_stats_args args;
    remote_domain_memory_stats_ret ret;
    struct private_data *priv = domain->conn->privateData;
    unsigned int i;

    remoteDriverLock(priv);

    make_nonnull_domain (&args.dom, domain);
    if (nr_stats > REMOTE_DOMAIN_MEMORY_STATS_MAX) {
2405 2406 2407
        virReportError(VIR_ERR_RPC,
                       _("too many memory stats requested: %d > %d"), nr_stats,
                       REMOTE_DOMAIN_MEMORY_STATS_MAX);
2408 2409 2410
        goto done;
    }
    args.maxStats = nr_stats;
2411
    args.flags = flags;
2412
    memset (&ret, 0, sizeof(ret));
2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432

    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_MEMORY_STATS,
              (xdrproc_t) xdr_remote_domain_memory_stats_args,
                (char *) &args,
              (xdrproc_t) xdr_remote_domain_memory_stats_ret,
                (char *) &ret) == -1)
        goto done;

    for (i = 0; i < ret.stats.stats_len; i++) {
        stats[i].tag = ret.stats.stats_val[i].tag;
        stats[i].val = ret.stats.stats_val[i].val;
    }
    rv = ret.stats.stats_len;
    xdr_free((xdrproc_t) xdr_remote_domain_memory_stats_ret, (char *) &ret);

done:
    remoteDriverUnlock(priv);
    return rv;
}

2433 2434 2435 2436 2437 2438 2439 2440
static int
remoteDomainBlockPeek (virDomainPtr domain,
                       const char *path,
                       unsigned long long offset,
                       size_t size,
                       void *buffer,
                       unsigned int flags)
{
2441
    int rv = -1;
2442 2443
    remote_domain_block_peek_args args;
    remote_domain_block_peek_ret ret;
2444
    struct private_data *priv = domain->conn->privateData;
2445

2446 2447
    remoteDriverLock(priv);

2448
    if (size > REMOTE_DOMAIN_BLOCK_PEEK_BUFFER_MAX) {
2449 2450 2451
        virReportError(VIR_ERR_RPC,
                       _("block peek request too large for remote protocol, %zi > %d"),
                       size, REMOTE_DOMAIN_BLOCK_PEEK_BUFFER_MAX);
2452
        goto done;
2453 2454 2455 2456 2457 2458 2459 2460
    }

    make_nonnull_domain (&args.dom, domain);
    args.path = (char *) path;
    args.offset = offset;
    args.size = size;
    args.flags = flags;

2461
    memset (&ret, 0, sizeof(ret));
2462 2463 2464 2465 2466
    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_BLOCK_PEEK,
              (xdrproc_t) xdr_remote_domain_block_peek_args,
                (char *) &args,
              (xdrproc_t) xdr_remote_domain_block_peek_ret,
                (char *) &ret) == -1)
2467
        goto done;
2468 2469

    if (ret.buffer.buffer_len != size) {
2470 2471
        virReportError(VIR_ERR_RPC, "%s",
                       _("returned buffer is not same size as requested"));
2472
        goto cleanup;
2473 2474 2475
    }

    memcpy (buffer, ret.buffer.buffer_val, size);
2476 2477 2478
    rv = 0;

cleanup:
2479
    VIR_FREE(ret.buffer.buffer_val);
2480

2481
done:
2482
    remoteDriverUnlock(priv);
2483
    return rv;
2484 2485
}

R
Richard W.M. Jones 已提交
2486 2487 2488 2489 2490 2491 2492
static int
remoteDomainMemoryPeek (virDomainPtr domain,
                        unsigned long long offset,
                        size_t size,
                        void *buffer,
                        unsigned int flags)
{
2493
    int rv = -1;
R
Richard W.M. Jones 已提交
2494 2495
    remote_domain_memory_peek_args args;
    remote_domain_memory_peek_ret ret;
2496
    struct private_data *priv = domain->conn->privateData;
R
Richard W.M. Jones 已提交
2497

2498 2499
    remoteDriverLock(priv);

R
Richard W.M. Jones 已提交
2500
    if (size > REMOTE_DOMAIN_MEMORY_PEEK_BUFFER_MAX) {
2501 2502 2503
        virReportError(VIR_ERR_RPC,
                       _("memory peek request too large for remote protocol, %zi > %d"),
                       size, REMOTE_DOMAIN_MEMORY_PEEK_BUFFER_MAX);
2504
        goto done;
R
Richard W.M. Jones 已提交
2505 2506 2507 2508 2509 2510 2511
    }

    make_nonnull_domain (&args.dom, domain);
    args.offset = offset;
    args.size = size;
    args.flags = flags;

2512
    memset (&ret, 0, sizeof(ret));
R
Richard W.M. Jones 已提交
2513 2514 2515 2516 2517
    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_MEMORY_PEEK,
              (xdrproc_t) xdr_remote_domain_memory_peek_args,
                (char *) &args,
              (xdrproc_t) xdr_remote_domain_memory_peek_ret,
                (char *) &ret) == -1)
2518
        goto done;
R
Richard W.M. Jones 已提交
2519 2520

    if (ret.buffer.buffer_len != size) {
2521 2522
        virReportError(VIR_ERR_RPC, "%s",
                       _("returned buffer is not same size as requested"));
2523
        goto cleanup;
R
Richard W.M. Jones 已提交
2524 2525 2526
    }

    memcpy (buffer, ret.buffer.buffer_val, size);
2527 2528 2529
    rv = 0;

cleanup:
2530
    VIR_FREE(ret.buffer.buffer_val);
R
Richard W.M. Jones 已提交
2531

2532
done:
2533
    remoteDriverUnlock(priv);
2534
    return rv;
R
Richard W.M. Jones 已提交
2535 2536
}

2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574
static int remoteDomainGetBlockJobInfo(virDomainPtr domain,
                                       const char *path,
                                       virDomainBlockJobInfoPtr info,
                                       unsigned int flags)
{
    int rv = -1;
    remote_domain_get_block_job_info_args args;
    remote_domain_get_block_job_info_ret ret;
    struct private_data *priv = domain->conn->privateData;

    remoteDriverLock(priv);

    make_nonnull_domain(&args.dom, domain);
    args.path = (char *)path;
    args.flags = flags;

    if (call(domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_BLOCK_JOB_INFO,
             (xdrproc_t)xdr_remote_domain_get_block_job_info_args,
               (char *)&args,
             (xdrproc_t)xdr_remote_domain_get_block_job_info_ret,
               (char *)&ret) == -1)
        goto done;

    if (ret.found) {
        info->type = ret.type;
        info->bandwidth = ret.bandwidth;
        info->cur = ret.cur;
        info->end = ret.end;
        rv = 1;
    } else {
        rv = 0;
    }

done:
    remoteDriverUnlock(priv);
    return rv;
}

2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629
static int remoteDomainGetBlockIoTune(virDomainPtr domain,
                                      const char *disk,
                                      virTypedParameterPtr params,
                                      int *nparams,
                                      unsigned int flags)
{
    int rv = -1;
    remote_domain_get_block_io_tune_args args;
    remote_domain_get_block_io_tune_ret ret;
    struct private_data *priv = domain->conn->privateData;

    remoteDriverLock(priv);

    make_nonnull_domain(&args.dom, domain);
    args.disk = disk ? (char **)&disk : NULL;
    args.nparams = *nparams;
    args.flags = flags;

    memset(&ret, 0, sizeof(ret));


    if (call(domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_BLOCK_IO_TUNE,
             (xdrproc_t) xdr_remote_domain_get_block_io_tune_args,
               (char *) &args,
             (xdrproc_t) xdr_remote_domain_get_block_io_tune_ret,
               (char *) &ret) == -1) {
        goto done;
    }

    /* Handle the case when the caller does not know the number of parameters
     * and is asking for the number of parameters supported
     */
    if (*nparams == 0) {
        *nparams = ret.nparams;
        rv = 0;
        goto cleanup;
    }

    if (remoteDeserializeTypedParameters(ret.params.params_val,
                                         ret.params.params_len,
                                         REMOTE_DOMAIN_MEMORY_PARAMETERS_MAX,
                                         params,
                                         nparams) < 0)
        goto cleanup;

    rv = 0;

cleanup:
    xdr_free ((xdrproc_t) xdr_remote_domain_get_block_io_tune_ret,
              (char *) &ret);
done:
    remoteDriverUnlock(priv);
    return rv;
}

2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645
static int remoteDomainGetCPUStats(virDomainPtr domain,
                                   virTypedParameterPtr params,
                                   unsigned int nparams,
                                   int start_cpu,
                                   unsigned int ncpus,
                                   unsigned int flags)
{
    struct private_data *priv = domain->conn->privateData;
    remote_domain_get_cpu_stats_args args;
    remote_domain_get_cpu_stats_ret ret;
    int rv = -1;
    int cpu;

    remoteDriverLock(priv);

    if (nparams > REMOTE_NODE_CPU_STATS_MAX) {
2646 2647 2648
        virReportError(VIR_ERR_RPC,
                       _("nparams count exceeds maximum: %u > %u"),
                       nparams, REMOTE_NODE_CPU_STATS_MAX);
2649 2650 2651
        goto done;
    }
    if (ncpus > REMOTE_DOMAIN_GET_CPU_STATS_NCPUS_MAX) {
2652 2653 2654
        virReportError(VIR_ERR_RPC,
                       _("ncpus count exceeds maximum: %u > %u"),
                       ncpus, REMOTE_DOMAIN_GET_CPU_STATS_NCPUS_MAX);
2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675
        goto done;
    }

    make_nonnull_domain(&args.dom, domain);
    args.nparams = nparams;
    args.start_cpu = start_cpu;
    args.ncpus = ncpus;
    args.flags = flags;

    memset(&ret, 0, sizeof(ret));

    if (call(domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_CPU_STATS,
             (xdrproc_t) xdr_remote_domain_get_cpu_stats_args,
             (char *) &args,
             (xdrproc_t) xdr_remote_domain_get_cpu_stats_ret,
             (char *) &ret) == -1)
        goto done;

    /* Check the length of the returned list carefully. */
    if (ret.params.params_len > nparams * ncpus ||
        (ret.params.params_len &&
2676
         ((ret.params.params_len % ret.nparams) || ret.nparams > nparams))) {
2677 2678 2679
        virReportError(VIR_ERR_RPC, "%s",
                       _("remoteDomainGetCPUStats: "
                         "returned number of stats exceeds limit"));
2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692
        memset(params, 0, sizeof(*params) * nparams * ncpus);
        goto cleanup;
    }

    /* Handle the case when the caller does not know the number of stats
     * and is asking for the number of stats supported
     */
    if (nparams == 0) {
        rv = ret.nparams;
        goto cleanup;
    }

    /* The remote side did not send back any zero entries, so we have
2693 2694
     * to expand things back into a possibly sparse array, where the
     * tail of the array may be omitted.
2695 2696
     */
    memset(params, 0, sizeof(*params) * nparams * ncpus);
2697
    ncpus = ret.params.params_len / ret.nparams;
2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710
    for (cpu = 0; cpu < ncpus; cpu++) {
        int tmp = nparams;
        remote_typed_param *stride = &ret.params.params_val[cpu * ret.nparams];

        if (remoteDeserializeTypedParameters(stride, ret.nparams,
                                             REMOTE_NODE_CPU_STATS_MAX,
                                             &params[cpu * nparams],
                                             &tmp) < 0)
            goto cleanup;
    }

    rv = ret.nparams;
cleanup:
A
Alex Jia 已提交
2711 2712
    if (rv < 0)
        virTypedParameterArrayClear(params, nparams * ncpus);
2713 2714 2715 2716 2717 2718 2719 2720

    xdr_free ((xdrproc_t) xdr_remote_domain_get_cpu_stats_ret,
              (char *) &ret);
done:
    remoteDriverUnlock(priv);
    return rv;
}

2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783
static int
remoteConnectListAllNetworks(virConnectPtr conn,
                             virNetworkPtr **nets,
                             unsigned int flags)
{
    int rv = -1;
    int i;
    virNetworkPtr *tmp_nets = NULL;
    remote_connect_list_all_networks_args args;
    remote_connect_list_all_networks_ret ret;

    struct private_data *priv = conn->privateData;

    remoteDriverLock(priv);

    args.need_results = !!nets;
    args.flags = flags;

    memset(&ret, 0, sizeof(ret));
    if (call(conn,
             priv,
             0,
             REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS,
             (xdrproc_t) xdr_remote_connect_list_all_networks_args,
             (char *) &args,
             (xdrproc_t) xdr_remote_connect_list_all_networks_ret,
             (char *) &ret) == -1)
        goto done;

    if (nets) {
        if (VIR_ALLOC_N(tmp_nets, ret.nets.nets_len + 1) < 0) {
            virReportOOMError();
            goto cleanup;
        }

        for (i = 0; i < ret.nets.nets_len; i++) {
            tmp_nets[i] = get_nonnull_network (conn, ret.nets.nets_val[i]);
            if (!tmp_nets[i]) {
                virReportOOMError();
                goto cleanup;
            }
        }
        *nets = tmp_nets;
        tmp_nets = NULL;
    }

    rv = ret.ret;

cleanup:
    if (tmp_nets) {
        for (i = 0; i < ret.nets.nets_len; i++)
            if (tmp_nets[i])
                virNetworkFree(tmp_nets[i]);
        VIR_FREE(tmp_nets);
    }

    xdr_free((xdrproc_t) xdr_remote_connect_list_all_networks_ret, (char *) &ret);

done:
    remoteDriverUnlock(priv);
    return rv;
}

2784

2785 2786
/*----------------------------------------------------------------------*/

J
Jim Meyering 已提交
2787
static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
2788
remoteGenericOpen(virConnectPtr conn, virConnectAuthPtr auth,
2789
                  unsigned int flags, void **genericPrivateData)
2790
{
2791 2792 2793
    if (inside_daemon)
        return VIR_DRV_OPEN_DECLINED;

J
Jim Meyering 已提交
2794
    if (conn->driver &&
2795
        STREQ (conn->driver->name, "remote")) {
2796 2797
        struct private_data *priv;

2798
        /* If we're here, the remote driver is already
2799
         * in use due to a) a QEMU uri, or b) a remote
2800
         * URI. So we can re-use existing connection */
2801 2802 2803
        priv = conn->privateData;
        remoteDriverLock(priv);
        priv->localUses++;
2804 2805 2806 2807 2808 2809 2810 2811 2812
        *genericPrivateData = priv;
        remoteDriverUnlock(priv);
        return VIR_DRV_OPEN_SUCCESS;
    } else if (conn->networkDriver &&
               STREQ (conn->networkDriver->name, "remote")) {
        struct private_data *priv = conn->networkPrivateData;
        remoteDriverLock(priv);
        *genericPrivateData = priv;
        priv->localUses++;
2813
        remoteDriverUnlock(priv);
2814
        return VIR_DRV_OPEN_SUCCESS;
2815 2816 2817
    } else {
        /* Using a non-remote driver, so we need to open a
         * new connection for network APIs, forcing it to
2818
         * use the UNIX transport. This handles Xen driver
2819
         * which doesn't have its own impl of the network APIs. */
2820
        struct private_data *priv;
2821 2822
        int ret = remoteOpenSecondaryDriver(conn, auth, flags, &priv);
        *genericPrivateData = priv;
2823 2824
        return ret;
    }
2825 2826 2827
}

static int
2828
remoteGenericClose(virConnectPtr conn, void **genericPrivateData)
2829
{
2830
    int rv = 0;
2831
    struct private_data *priv = *genericPrivateData;
2832

2833 2834 2835 2836
    remoteDriverLock(priv);
    priv->localUses--;
    if (!priv->localUses) {
        rv = doRemoteClose(conn, priv);
2837
        *genericPrivateData = NULL;
2838 2839 2840
        remoteDriverUnlock(priv);
        virMutexDestroy(&priv->lock);
        VIR_FREE(priv);
2841
    }
2842 2843
    if (priv)
        remoteDriverUnlock(priv);
2844
    return rv;
2845 2846
}

2847
static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
2848 2849
remoteNetworkOpen(virConnectPtr conn, virConnectAuthPtr auth,
                  unsigned int flags)
2850 2851 2852 2853 2854 2855 2856 2857 2858 2859
{
    return remoteGenericOpen(conn, auth, flags, &conn->networkPrivateData);
}

static int
remoteNetworkClose(virConnectPtr conn)
{
    return remoteGenericClose(conn, &conn->networkPrivateData);
}

D
Daniel Veillard 已提交
2860 2861
/*----------------------------------------------------------------------*/

J
Jim Meyering 已提交
2862
static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
2863 2864
remoteInterfaceOpen(virConnectPtr conn, virConnectAuthPtr auth,
                    unsigned int flags)
D
Daniel Veillard 已提交
2865
{
2866
    return remoteGenericOpen(conn, auth, flags, &conn->interfacePrivateData);
D
Daniel Veillard 已提交
2867 2868 2869
}

static int
2870
remoteInterfaceClose(virConnectPtr conn)
D
Daniel Veillard 已提交
2871
{
2872
    return remoteGenericClose(conn, &conn->interfacePrivateData);
D
Daniel Veillard 已提交
2873 2874
}

2875 2876
/*----------------------------------------------------------------------*/

J
Jim Meyering 已提交
2877
static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
2878 2879
remoteStorageOpen(virConnectPtr conn, virConnectAuthPtr auth,
                  unsigned int flags)
2880
{
2881
    return remoteGenericOpen(conn, auth, flags, &conn->storagePrivateData);
2882 2883 2884
}

static int
2885
remoteStorageClose(virConnectPtr conn)
2886
{
2887
    return remoteGenericClose(conn, &conn->storagePrivateData);
2888 2889
}

2890 2891 2892 2893 2894 2895
static char *
remoteFindStoragePoolSources (virConnectPtr conn,
                              const char *type,
                              const char *srcSpec,
                              unsigned int flags)
{
2896
    char *rv = NULL;
2897 2898
    remote_find_storage_pool_sources_args args;
    remote_find_storage_pool_sources_ret ret;
2899
    struct private_data *priv = conn->storagePrivateData;
2900

2901 2902
    remoteDriverLock(priv);

2903
    args.type = (char*)type;
2904
    args.srcSpec = srcSpec ? (char **)&srcSpec : NULL;
2905 2906
    args.flags = flags;

2907
    memset (&ret, 0, sizeof(ret));
2908 2909
    if (call (conn, priv, 0, REMOTE_PROC_FIND_STORAGE_POOL_SOURCES,
              (xdrproc_t) xdr_remote_find_storage_pool_sources_args, (char *) &args,
2910
              (xdrproc_t) xdr_remote_find_storage_pool_sources_ret, (char *) &ret) == -1)
2911
        goto done;
2912

2913 2914 2915 2916
    rv = ret.xml;
    ret.xml = NULL; /* To stop xdr_free free'ing it */

    xdr_free ((xdrproc_t) xdr_remote_find_storage_pool_sources_ret, (char *) &ret);
2917 2918

done:
2919
    remoteDriverUnlock(priv);
2920
    return rv;
2921 2922
}

2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985
static int
remoteConnectListAllStoragePools (virConnectPtr conn,
                                  virStoragePoolPtr **pools,
                                  unsigned int flags)
{
    int rv = -1;
    int i;
    virStoragePoolPtr *tmp_pools = NULL;
    remote_connect_list_all_storage_pools_args args;
    remote_connect_list_all_storage_pools_ret ret;

    struct private_data *priv = conn->privateData;

    remoteDriverLock(priv);

    args.need_results = !!pools;
    args.flags = flags;

    memset(&ret, 0, sizeof(ret));
    if (call(conn,
             priv,
             0,
             REMOTE_PROC_CONNECT_LIST_ALL_STORAGE_POOLS,
             (xdrproc_t) xdr_remote_connect_list_all_storage_pools_args,
             (char *) &args,
             (xdrproc_t) xdr_remote_connect_list_all_storage_pools_ret,
             (char *) &ret) == -1)
        goto done;

    if (pools) {
        if (VIR_ALLOC_N(tmp_pools, ret.pools.pools_len + 1) < 0) {
            virReportOOMError();
            goto cleanup;
        }

        for (i = 0; i < ret.pools.pools_len; i++) {
            tmp_pools[i] = get_nonnull_storage_pool(conn, ret.pools.pools_val[i]);
            if (!tmp_pools[i]) {
                virReportOOMError();
                goto cleanup;
            }
        }
        *pools = tmp_pools;
        tmp_pools = NULL;
    }

    rv = ret.ret;

cleanup:
    if (tmp_pools) {
        for (i = 0; i < ret.pools.pools_len; i++)
            if (tmp_pools[i])
                virStoragePoolFree(tmp_pools[i]);
        VIR_FREE(tmp_pools);
    }

    xdr_free((xdrproc_t) xdr_remote_connect_list_all_storage_pools_ret, (char *) &ret);

done:
    remoteDriverUnlock(priv);
    return rv;
}

2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050
static int
remoteStoragePoolListAllVolumes(virStoragePoolPtr pool,
                                virStorageVolPtr **vols,
                                unsigned int flags)
{
    int rv = -1;
    int i;
    virStorageVolPtr *tmp_vols = NULL;
    remote_storage_pool_list_all_volumes_args args;
    remote_storage_pool_list_all_volumes_ret ret;

    struct private_data *priv = pool->conn->privateData;

    remoteDriverLock(priv);

    make_nonnull_storage_pool(&args.pool, pool);
    args.need_results = !!vols;
    args.flags = flags;

    memset(&ret, 0, sizeof(ret));
    if (call(pool->conn,
             priv,
             0,
             REMOTE_PROC_STORAGE_POOL_LIST_ALL_VOLUMES,
             (xdrproc_t) xdr_remote_storage_pool_list_all_volumes_args,
             (char *) &args,
             (xdrproc_t) xdr_remote_storage_pool_list_all_volumes_ret,
             (char *) &ret) == -1)
        goto done;

    if (vols) {
        if (VIR_ALLOC_N(tmp_vols, ret.vols.vols_len + 1) < 0) {
            virReportOOMError();
            goto cleanup;
        }

        for (i = 0; i < ret.vols.vols_len; i++) {
            tmp_vols[i] = get_nonnull_storage_vol(pool->conn, ret.vols.vols_val[i]);
            if (!tmp_vols[i]) {
                virReportOOMError();
                goto cleanup;
            }
        }
        *vols = tmp_vols;
        tmp_vols = NULL;
    }

    rv = ret.ret;

cleanup:
    if (tmp_vols) {
        for (i = 0; i < ret.vols.vols_len; i++)
            if (tmp_vols[i])
                virStorageVolFree(tmp_vols[i]);
        VIR_FREE(tmp_vols);
    }

    xdr_free((xdrproc_t) xdr_remote_storage_pool_list_all_volumes_ret, (char *) &ret);

done:
    remoteDriverUnlock(priv);
    return rv;
}


3051 3052
/*----------------------------------------------------------------------*/

J
Jim Meyering 已提交
3053
static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
3054 3055
remoteDevMonOpen(virConnectPtr conn, virConnectAuthPtr auth,
                 unsigned int flags)
3056
{
3057
    return remoteGenericOpen(conn, auth, flags, &conn->devMonPrivateData);
3058 3059
}

3060 3061
static int
remoteDevMonClose(virConnectPtr conn)
3062
{
3063
    return remoteGenericClose(conn, &conn->devMonPrivateData);
3064 3065
}

3066 3067 3068 3069 3070
static int
remoteNodeDeviceDettach (virNodeDevicePtr dev)
{
    int rv = -1;
    remote_node_device_dettach_args args;
3071 3072
    /* This method is unusual in that it uses the HV driver, not the devMon driver
     * hence its use of privateData, instead of devMonPrivateData */
3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095
    struct private_data *priv = dev->conn->privateData;

    remoteDriverLock(priv);

    args.name = dev->name;

    if (call (dev->conn, priv, 0, REMOTE_PROC_NODE_DEVICE_DETTACH,
              (xdrproc_t) xdr_remote_node_device_dettach_args, (char *) &args,
              (xdrproc_t) xdr_void, (char *) NULL) == -1)
        goto done;

    rv = 0;

done:
    remoteDriverUnlock(priv);
    return rv;
}

static int
remoteNodeDeviceReAttach (virNodeDevicePtr dev)
{
    int rv = -1;
    remote_node_device_re_attach_args args;
3096 3097
    /* This method is unusual in that it uses the HV driver, not the devMon driver
     * hence its use of privateData, instead of devMonPrivateData */
3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120
    struct private_data *priv = dev->conn->privateData;

    remoteDriverLock(priv);

    args.name = dev->name;

    if (call (dev->conn, priv, 0, REMOTE_PROC_NODE_DEVICE_RE_ATTACH,
              (xdrproc_t) xdr_remote_node_device_re_attach_args, (char *) &args,
              (xdrproc_t) xdr_void, (char *) NULL) == -1)
        goto done;

    rv = 0;

done:
    remoteDriverUnlock(priv);
    return rv;
}

static int
remoteNodeDeviceReset (virNodeDevicePtr dev)
{
    int rv = -1;
    remote_node_device_reset_args args;
3121 3122
    /* This method is unusual in that it uses the HV driver, not the devMon driver
     * hence its use of privateData, instead of devMonPrivateData */
3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140
    struct private_data *priv = dev->conn->privateData;

    remoteDriverLock(priv);

    args.name = dev->name;

    if (call (dev->conn, priv, 0, REMOTE_PROC_NODE_DEVICE_RESET,
              (xdrproc_t) xdr_remote_node_device_reset_args, (char *) &args,
              (xdrproc_t) xdr_void, (char *) NULL) == -1)
        goto done;

    rv = 0;

done:
    remoteDriverUnlock(priv);
    return rv;
}

3141 3142 3143
/* ------------------------------------------------------------- */

static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
3144 3145
remoteNWFilterOpen(virConnectPtr conn, virConnectAuthPtr auth,
                   unsigned int flags)
3146
{
3147
    return remoteGenericOpen(conn, auth, flags, &conn->nwfilterPrivateData);
3148 3149 3150
}

static int
3151
remoteNWFilterClose(virConnectPtr conn)
3152
{
3153
    return remoteGenericClose(conn, &conn->nwfilterPrivateData);
3154 3155
}

3156 3157
/*----------------------------------------------------------------------*/

3158
static int
E
Eric Blake 已提交
3159 3160
remoteAuthenticate (virConnectPtr conn, struct private_data *priv,
                    virConnectAuthPtr auth ATTRIBUTE_UNUSED,
3161
                    const char *authtype)
3162 3163
{
    struct remote_auth_list_ret ret;
3164
    int err, type = REMOTE_AUTH_NONE;
3165

3166
    memset(&ret, 0, sizeof(ret));
3167
    err = call (conn, priv, 0,
3168 3169 3170
                REMOTE_PROC_AUTH_LIST,
                (xdrproc_t) xdr_void, (char *) NULL,
                (xdrproc_t) xdr_remote_auth_list_ret, (char *) &ret);
3171 3172 3173 3174 3175 3176 3177
    if (err < 0) {
        virErrorPtr verr = virGetLastError();
        if (verr && verr->code == VIR_ERR_NO_SUPPORT) {
            /* Missing RPC - old server - ignore */
            virResetLastError();
            return 0;
        }
3178
        return -1;
3179
    }
3180 3181 3182 3183

    if (ret.types.types_len == 0)
        return 0;

3184 3185 3186 3187 3188 3189 3190 3191
    if (authtype) {
        int want, i;
        if (STRCASEEQ(authtype, "sasl") ||
            STRCASEEQLEN(authtype, "sasl.", 5)) {
            want = REMOTE_AUTH_SASL;
        } else if (STRCASEEQ(authtype, "polkit")) {
            want = REMOTE_AUTH_POLKIT;
        } else {
3192 3193
            virReportError(VIR_ERR_AUTH_FAILED,
                           _("unknown authentication type %s"), authtype);
3194 3195 3196 3197 3198 3199 3200
            return -1;
        }
        for (i = 0 ; i < ret.types.types_len ; i++) {
            if (ret.types.types_val[i] == want)
                type = want;
        }
        if (type == REMOTE_AUTH_NONE) {
3201 3202 3203
            virReportError(VIR_ERR_AUTH_FAILED,
                           _("requested authentication type %s rejected"),
                           authtype);
3204 3205 3206 3207 3208 3209 3210
            return -1;
        }
    } else {
        type = ret.types.types_val[0];
    }

    switch (type) {
3211
#if HAVE_SASL
3212 3213 3214 3215 3216 3217
    case REMOTE_AUTH_SASL: {
        const char *mech = NULL;
        if (authtype &&
            STRCASEEQLEN(authtype, "sasl.", 5))
            mech = authtype + 5;

3218
        if (remoteAuthSASL(conn, priv, auth, mech) < 0) {
3219
            VIR_FREE(ret.types.types_val);
3220 3221 3222
            return -1;
        }
        break;
3223
    }
3224 3225
#endif

3226 3227
#if HAVE_POLKIT
    case REMOTE_AUTH_POLKIT:
3228
        if (remoteAuthPolkit(conn, priv, auth) < 0) {
3229
            VIR_FREE(ret.types.types_val);
3230 3231 3232 3233 3234
            return -1;
        }
        break;
#endif

3235 3236 3237 3238 3239
    case REMOTE_AUTH_NONE:
        /* Nothing todo, hurrah ! */
        break;

    default:
3240 3241 3242
        virReportError(VIR_ERR_AUTH_FAILED,
                       _("unsupported authentication type %d"),
                       ret.types.types_val[0]);
3243
        VIR_FREE(ret.types.types_val);
3244 3245 3246
        return -1;
    }

3247
    VIR_FREE(ret.types.types_val);
3248 3249 3250 3251 3252 3253 3254

    return 0;
}



#if HAVE_SASL
3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332
static int remoteAuthCredVir2SASL(int vircred)
{
    switch (vircred) {
    case VIR_CRED_USERNAME:
        return SASL_CB_USER;

    case VIR_CRED_AUTHNAME:
        return SASL_CB_AUTHNAME;

    case VIR_CRED_LANGUAGE:
        return SASL_CB_LANGUAGE;

    case VIR_CRED_CNONCE:
        return SASL_CB_CNONCE;

    case VIR_CRED_PASSPHRASE:
        return SASL_CB_PASS;

    case VIR_CRED_ECHOPROMPT:
        return SASL_CB_ECHOPROMPT;

    case VIR_CRED_NOECHOPROMPT:
        return SASL_CB_NOECHOPROMPT;

    case VIR_CRED_REALM:
        return SASL_CB_GETREALM;
    }

    return 0;
}

static int remoteAuthCredSASL2Vir(int vircred)
{
    switch (vircred) {
    case SASL_CB_USER:
        return VIR_CRED_USERNAME;

    case SASL_CB_AUTHNAME:
        return VIR_CRED_AUTHNAME;

    case SASL_CB_LANGUAGE:
        return VIR_CRED_LANGUAGE;

    case SASL_CB_CNONCE:
        return VIR_CRED_CNONCE;

    case SASL_CB_PASS:
        return VIR_CRED_PASSPHRASE;

    case SASL_CB_ECHOPROMPT:
        return VIR_CRED_ECHOPROMPT;

    case SASL_CB_NOECHOPROMPT:
        return VIR_CRED_NOECHOPROMPT;

    case SASL_CB_GETREALM:
        return VIR_CRED_REALM;
    }

    return 0;
}

/*
 * @param credtype array of credential types client supports
 * @param ncredtype size of credtype array
 * @return the SASL callback structure, or NULL on error
 *
 * Build up the SASL callback structure. We register one callback for
 * each credential type that the libvirt client indicated they support.
 * We explicitly leav the callback function pointer at NULL though,
 * because we don't actually want to get SASL callbacks triggered.
 * Instead, we want the start/step functions to return SASL_INTERACT.
 * This lets us give the libvirt client a list of all required
 * credentials in one go, rather than triggering the callback one
 * credential at a time,
 */
static sasl_callback_t *remoteAuthMakeCallbacks(int *credtype, int ncredtype)
{
3333
    sasl_callback_t *cbs;
3334
    int i, n;
3335
    if (VIR_ALLOC_N(cbs, ncredtype+1) < 0) {
3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354
        return NULL;
    }

    for (i = 0, n = 0 ; i < ncredtype ; i++) {
        int id = remoteAuthCredVir2SASL(credtype[i]);
        if (id != 0)
            cbs[n++].id = id;
        /* Don't fill proc or context fields of sasl_callback_t
         * because we want to use interactions instead */
    }
    cbs[n].id = 0;
    return cbs;
}


/*
 * @param interact SASL interactions required
 * @param cred populated with libvirt credential metadata
 * @return the size of the cred array returned
3355
 *
3356 3357 3358 3359 3360
 * Builds up an array of libvirt credential structs, populating
 * with data from the SASL interaction struct. These two structs
 * are basically a 1-to-1 copy of each other.
 */
static int remoteAuthMakeCredentials(sasl_interact_t *interact,
3361 3362
                                     virConnectCredentialPtr *cred,
                                     size_t *ncred)
3363 3364 3365 3366 3367
{
    int ninteract;
    if (!cred)
        return -1;

3368 3369 3370 3371 3372
    for (ninteract = 0, *ncred = 0 ; interact[ninteract].id != 0 ; ninteract++) {
        if (interact[ninteract].result)
            continue;
        (*ncred)++;
    }
3373

3374
    if (VIR_ALLOC_N(*cred, *ncred) < 0)
3375 3376
        return -1;

3377 3378 3379 3380 3381 3382 3383
    for (ninteract = 0, *ncred = 0 ; interact[ninteract].id != 0 ; ninteract++) {
        if (interact[ninteract].result)
            continue;

        (*cred)[*ncred].type = remoteAuthCredSASL2Vir(interact[ninteract].id);
        if (!(*cred)[*ncred].type) {
            *ncred = 0;
3384
            VIR_FREE(*cred);
3385 3386
            return -1;
        }
3387 3388 3389 3390 3391 3392 3393 3394
        if (interact[*ncred].challenge)
            (*cred)[*ncred].challenge = interact[ninteract].challenge;
        (*cred)[*ncred].prompt = interact[ninteract].prompt;
        if (interact[*ncred].defresult)
            (*cred)[*ncred].defresult = interact[ninteract].defresult;
        (*cred)[*ncred].result = NULL;

        (*ncred)++;
3395 3396
    }

3397
    return 0;
3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410
}


/*
 * @param cred the populated libvirt credentials
 * @param interact the SASL interactions to fill in results for
 *
 * Fills the SASL interactions with the result from the libvirt
 * callbacks
 */
static void remoteAuthFillInteract(virConnectCredentialPtr cred,
                                   sasl_interact_t *interact)
{
3411 3412 3413 3414 3415 3416 3417
    int ninteract, ncred;
    for (ninteract = 0, ncred = 0 ; interact[ninteract].id != 0 ; ninteract++) {
        if (interact[ninteract].result)
            continue;
        interact[ninteract].result = cred[ncred].result;
        interact[ninteract].len = cred[ncred].resultlen;
        ncred++;
3418 3419 3420
    }
}

3421 3422 3423 3424
struct remoteAuthInteractState {
    sasl_interact_t *interact;
    virConnectCredentialPtr cred;
    size_t ncred;
3425
    virAuthConfigPtr config;
3426 3427 3428
};


3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495

static int remoteAuthFillFromConfig(virConnectPtr conn,
                                    struct remoteAuthInteractState *state)
{
    int ret = -1;
    int ninteract;
    const char *credname;
    char *path = NULL;

    VIR_DEBUG("Trying to fill auth parameters from config file");

    if (!state->config) {
        if (virAuthGetConfigFilePath(conn, &path) < 0)
            goto cleanup;
        if (path == NULL) {
            ret = 0;
            goto cleanup;
        }

        if (!(state->config = virAuthConfigNew(path)))
            goto cleanup;
    }

    for (ninteract = 0 ; state->interact[ninteract].id != 0 ; ninteract++) {
        const char *value = NULL;

        switch (state->interact[ninteract].id) {
        case SASL_CB_USER:
            credname = "username";
            break;
        case SASL_CB_AUTHNAME:
            credname = "authname";
            break;
        case SASL_CB_PASS:
            credname = "password";
            break;
        case SASL_CB_GETREALM:
            credname = "realm";
            break;
        default:
            credname = NULL;
            break;
        }

        if (virAuthConfigLookup(state->config,
                                "libvirt",
                                conn->uri->server,
                                credname,
                                &value) < 0)
            goto cleanup;

        if (value) {
            state->interact[ninteract].result = value;
            state->interact[ninteract].len = strlen(value);
        }
    }

    ret = 0;

cleanup:
    VIR_FREE(path);
    return ret;
}


static void remoteAuthInteractStateClear(struct remoteAuthInteractState *state,
                                         bool final)
3496 3497 3498 3499 3500 3501 3502 3503 3504
{
    size_t i;
    if (!state)
        return;

    for (i = 0 ; i < state->ncred ; i++)
        VIR_FREE(state->cred[i].result);
    VIR_FREE(state->cred);
    state->ncred = 0;
3505 3506 3507

    if (final)
        virAuthConfigFree(state->config);
3508 3509 3510
}


3511 3512
static int remoteAuthInteract(virConnectPtr conn,
                              struct remoteAuthInteractState *state,
3513 3514 3515 3516
                              virConnectAuthPtr auth)
{
    int ret = -1;

3517 3518 3519 3520 3521
    VIR_DEBUG("Starting SASL interaction");
    remoteAuthInteractStateClear(state, false);

    if (remoteAuthFillFromConfig(conn, state) < 0)
        goto cleanup;
3522 3523

    if (remoteAuthMakeCredentials(state->interact, &state->cred, &state->ncred) < 0) {
3524 3525
        virReportError(VIR_ERR_AUTH_FAILED, "%s",
                       _("Failed to make auth credentials"));
3526 3527 3528 3529 3530
        goto cleanup;
    }

    /* Run the authentication callback */
    if (!auth || !auth->cb) {
3531 3532
        virReportError(VIR_ERR_AUTH_FAILED, "%s",
                       _("No authentication callback available"));
3533 3534 3535 3536
        goto cleanup;
    }

    if ((*(auth->cb))(state->cred, state->ncred, auth->cbdata) < 0) {
3537 3538
        virReportError(VIR_ERR_AUTH_FAILED, "%s",
                       _("Failed to collect auth credentials"));
3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557
        goto cleanup;
    }

    remoteAuthFillInteract(state->cred, state->interact);
    /*
     * 'interact' now has pointers to strings in 'state->cred'
     * so we must not free state->cred until the *next*
     * sasl_start/step function is complete. Hence we
     * call remoteAuthInteractStateClear() at the *start*
     * of this method, rather than the end.
     */

    ret = 0;

cleanup:
    return ret;
}


3558
/* Perform the SASL authentication process
3559 3560
 */
static int
3561
remoteAuthSASL (virConnectPtr conn, struct private_data *priv,
3562
                virConnectAuthPtr auth, const char *wantmech)
3563 3564 3565 3566 3567 3568 3569
{
    remote_auth_sasl_init_ret iret;
    remote_auth_sasl_start_args sargs;
    remote_auth_sasl_start_ret sret;
    remote_auth_sasl_step_args pargs;
    remote_auth_sasl_step_ret pret;
    const char *clientout;
3570
    char *serverin = NULL;
3571
    size_t clientoutlen, serverinlen;
3572 3573
    const char *mech;
    int err, complete;
3574
    int ssf;
3575 3576 3577
    sasl_callback_t *saslcb = NULL;
    int ret = -1;
    const char *mechlist;
3578
    virNetSASLContextPtr saslCtxt;
E
Eric Blake 已提交
3579
    virNetSASLSessionPtr sasl = NULL;
3580 3581 3582
    struct remoteAuthInteractState state;

    memset(&state, 0, sizeof(state));
3583

3584
    VIR_DEBUG("Client initialize SASL authentication");
3585

3586
    if (!(saslCtxt = virNetSASLContextNewClient()))
3587 3588
        goto cleanup;

3589 3590 3591 3592 3593 3594
    if (auth) {
        if ((saslcb = remoteAuthMakeCallbacks(auth->credtype, auth->ncredtype)) == NULL)
            goto cleanup;
    } else {
        saslcb = NULL;
    }
3595 3596

    /* Setup a handle for being a client */
3597 3598 3599 3600 3601 3602
    if (!(sasl = virNetSASLSessionNewClient(saslCtxt,
                                            "libvirt",
                                            priv->hostname,
                                            virNetClientLocalAddrString(priv->client),
                                            virNetClientRemoteAddrString(priv->client),
                                            saslcb)))
3603
        goto cleanup;
3604

3605
    /* Initialize some connection props we care about */
3606 3607
    if (priv->tls) {
        if ((ssf = virNetClientGetTLSKeySize(priv->client)) < 0)
3608
            goto cleanup;
3609

3610 3611
        ssf *= 8; /* key size is bytes, sasl wants bits */

3612
        VIR_DEBUG("Setting external SSF %d", ssf);
3613
        if (virNetSASLSessionExtKeySize(sasl, ssf) < 0)
3614
            goto cleanup;
3615 3616
    }

3617 3618
    /* If we've got a secure channel (TLS or UNIX sock), we don't care about SSF */
    /* If we're not secure, then forbid any anonymous or trivially crackable auth */
3619 3620 3621 3622
    if (virNetSASLSessionSecProps(sasl,
                                  priv->is_secure ? 0 : 56, /* Equiv to DES supported by all Kerberos */
                                  priv->is_secure ? 0 : 100000, /* Very strong ! AES == 256 */
                                  priv->is_secure ? true : false) < 0)
3623
        goto cleanup;
3624

3625
    /* First call is to inquire about supported mechanisms in the server */
3626
    memset (&iret, 0, sizeof(iret));
3627
    if (call (conn, priv, 0, REMOTE_PROC_AUTH_SASL_INIT,
3628
              (xdrproc_t) xdr_void, (char *)NULL,
3629 3630
              (xdrproc_t) xdr_remote_auth_sasl_init_ret, (char *) &iret) != 0)
        goto cleanup;
3631 3632


3633 3634 3635
    mechlist = iret.mechlist;
    if (wantmech) {
        if (strstr(mechlist, wantmech) == NULL) {
3636 3637 3638
            virReportError(VIR_ERR_AUTH_FAILED,
                           _("SASL mechanism %s not supported by server"),
                           wantmech);
3639
            VIR_FREE(iret.mechlist);
3640 3641 3642 3643 3644
            goto cleanup;
        }
        mechlist = wantmech;
    }
 restart:
3645
    /* Start the auth negotiation on the client end first */
3646
    VIR_DEBUG("Client start negotiation mechlist '%s'", mechlist);
3647 3648
    if ((err = virNetSASLSessionClientStart(sasl,
                                            mechlist,
3649
                                            &state.interact,
3650 3651 3652
                                            &clientout,
                                            &clientoutlen,
                                            &mech)) < 0)
3653 3654 3655
        goto cleanup;

    /* Need to gather some credentials from the client */
3656
    if (err == VIR_NET_SASL_INTERACT) {
3657
        if (remoteAuthInteract(conn, &state, auth) < 0) {
3658
            VIR_FREE(iret.mechlist);
3659 3660
            goto cleanup;
        }
3661
        goto restart;
3662
    }
3663
    VIR_FREE(iret.mechlist);
3664 3665

    if (clientoutlen > REMOTE_AUTH_SASL_DATA_MAX) {
3666 3667 3668
        virReportError(VIR_ERR_AUTH_FAILED,
                       _("SASL negotiation data too long: %zu bytes"),
                       clientoutlen);
3669
        goto cleanup;
3670 3671
    }
    /* NB, distinction of NULL vs "" is *critical* in SASL */
3672
    memset(&sargs, 0, sizeof(sargs));
3673 3674 3675 3676
    sargs.nil = clientout ? 0 : 1;
    sargs.data.data_val = (char*)clientout;
    sargs.data.data_len = clientoutlen;
    sargs.mech = (char*)mech;
3677 3678
    VIR_DEBUG("Server start negotiation with mech %s. Data %zu bytes %p",
              mech, clientoutlen, clientout);
3679 3680

    /* Now send the initial auth data to the server */
3681
    memset (&sret, 0, sizeof(sret));
3682
    if (call (conn, priv, 0, REMOTE_PROC_AUTH_SASL_START,
3683
              (xdrproc_t) xdr_remote_auth_sasl_start_args, (char *) &sargs,
3684 3685
              (xdrproc_t) xdr_remote_auth_sasl_start_ret, (char *) &sret) != 0)
        goto cleanup;
3686 3687 3688 3689 3690

    complete = sret.complete;
    /* NB, distinction of NULL vs "" is *critical* in SASL */
    serverin = sret.nil ? NULL : sret.data.data_val;
    serverinlen = sret.data.data_len;
3691 3692
    VIR_DEBUG("Client step result complete: %d. Data %zu bytes %p",
              complete, serverinlen, serverin);
3693 3694 3695

    /* Loop-the-loop...
     * Even if the server has completed, the client must *always* do at least one step
D
Daniel Veillard 已提交
3696
     * in this loop to verify the server isn't lying about something. Mutual auth */
3697
    for (;;) {
3698
    restep:
3699 3700 3701
        if ((err = virNetSASLSessionClientStep(sasl,
                                               serverin,
                                               serverinlen,
3702
                                               &state.interact,
3703 3704
                                               &clientout,
                                               &clientoutlen)) < 0)
3705
            goto cleanup;
3706

3707
        /* Need to gather some credentials from the client */
3708
        if (err == VIR_NET_SASL_INTERACT) {
3709
            if (remoteAuthInteract(conn, &state, auth) < 0) {
3710
                VIR_FREE(iret.mechlist);
3711 3712
                goto cleanup;
            }
3713
            goto restep;
3714 3715
        }

3716
        VIR_FREE(serverin);
3717 3718
        VIR_DEBUG("Client step result %d. Data %zu bytes %p",
                  err, clientoutlen, clientout);
3719 3720

        /* Previous server call showed completion & we're now locally complete too */
3721
        if (complete && err == VIR_NET_SASL_COMPLETE)
3722 3723 3724 3725
            break;

        /* Not done, prepare to talk with the server for another iteration */
        /* NB, distinction of NULL vs "" is *critical* in SASL */
3726
        memset(&pargs, 0, sizeof(pargs));
3727 3728 3729
        pargs.nil = clientout ? 0 : 1;
        pargs.data.data_val = (char*)clientout;
        pargs.data.data_len = clientoutlen;
3730 3731
        VIR_DEBUG("Server step with %zu bytes %p",
                  clientoutlen, clientout);
3732

3733
        memset (&pret, 0, sizeof(pret));
3734
        if (call (conn, priv, 0, REMOTE_PROC_AUTH_SASL_STEP,
3735
                  (xdrproc_t) xdr_remote_auth_sasl_step_args, (char *) &pargs,
3736 3737
                  (xdrproc_t) xdr_remote_auth_sasl_step_ret, (char *) &pret) != 0)
            goto cleanup;
3738 3739 3740 3741 3742 3743

        complete = pret.complete;
        /* NB, distinction of NULL vs "" is *critical* in SASL */
        serverin = pret.nil ? NULL : pret.data.data_val;
        serverinlen = pret.data.data_len;

3744 3745
        VIR_DEBUG("Client step result complete: %d. Data %zu bytes %p",
                  complete, serverinlen, serverin);
3746 3747

        /* This server call shows complete, and earlier client step was OK */
3748
        if (complete && err == VIR_NET_SASL_COMPLETE) {
3749
            VIR_FREE(serverin);
3750 3751 3752 3753
            break;
        }
    }

3754 3755
    /* Check for suitable SSF if not already secure (TLS or UNIX sock) */
    if (!priv->is_secure) {
3756
        if ((ssf = virNetSASLSessionGetKeySize(sasl)) < 0)
3757
            goto cleanup;
3758

3759
        VIR_DEBUG("SASL SSF value %d", ssf);
3760
        if (ssf < 56) { /* 56 == DES level, good for Kerberos */
3761 3762
            virReportError(VIR_ERR_AUTH_FAILED,
                           _("negotiation SSF %d was not strong enough"), ssf);
3763
            goto cleanup;
3764
        }
3765
        priv->is_secure = 1;
3766 3767
    }

3768
    VIR_DEBUG("SASL authentication complete");
3769
    virNetClientSetSASLSession(priv->client, sasl);
3770 3771 3772
    ret = 0;

 cleanup:
3773
    VIR_FREE(serverin);
3774

3775
    remoteAuthInteractStateClear(&state, true);
3776
    VIR_FREE(saslcb);
3777 3778
    virObjectUnref(sasl);
    virObjectUnref(saslCtxt);
3779

3780
    return ret;
3781 3782 3783
}
#endif /* HAVE_SASL */

3784 3785

#if HAVE_POLKIT
3786
# if HAVE_POLKIT1
3787
static int
3788
remoteAuthPolkit (virConnectPtr conn, struct private_data *priv,
3789 3790 3791
                  virConnectAuthPtr auth ATTRIBUTE_UNUSED)
{
    remote_auth_polkit_ret ret;
3792
    VIR_DEBUG("Client initialize PolicyKit-1 authentication");
3793

3794
    memset (&ret, 0, sizeof(ret));
3795
    if (call (conn, priv, 0, REMOTE_PROC_AUTH_POLKIT,
3796 3797 3798 3799 3800
              (xdrproc_t) xdr_void, (char *)NULL,
              (xdrproc_t) xdr_remote_auth_polkit_ret, (char *) &ret) != 0) {
        return -1; /* virError already set by call */
    }

3801
    VIR_DEBUG("PolicyKit-1 authentication complete");
3802 3803
    return 0;
}
3804
# elif HAVE_POLKIT0
3805 3806 3807
/* Perform the PolicyKit authentication process
 */
static int
3808
remoteAuthPolkit (virConnectPtr conn, struct private_data *priv,
3809 3810 3811
                  virConnectAuthPtr auth)
{
    remote_auth_polkit_ret ret;
3812
    int i, allowcb = 0;
3813 3814 3815 3816 3817 3818 3819 3820
    virConnectCredential cred = {
        VIR_CRED_EXTERNAL,
        conn->flags & VIR_CONNECT_RO ? "org.libvirt.unix.monitor" : "org.libvirt.unix.manage",
        "PolicyKit",
        NULL,
        NULL,
        0,
    };
3821
    VIR_DEBUG("Client initialize PolicyKit-0 authentication");
3822

3823
    /* Check auth first and if it succeeds we are done. */
3824
    memset (&ret, 0, sizeof(ret));
3825 3826 3827 3828 3829 3830
    if (call (conn, priv, 0, REMOTE_PROC_AUTH_POLKIT,
              (xdrproc_t) xdr_void, (char *)NULL,
              (xdrproc_t) xdr_remote_auth_polkit_ret, (char *) &ret) == 0)
        goto out;

    /* Auth failed.  Ask client to obtain it and check again. */
3831
    if (auth && auth->cb) {
3832
        /* Check if the necessary credential type for PolicyKit is supported */
3833 3834 3835 3836
        for (i = 0 ; i < auth->ncredtype ; i++) {
            if (auth->credtype[i] == VIR_CRED_EXTERNAL)
                allowcb = 1;
        }
3837

3838
        if (allowcb) {
3839
            VIR_DEBUG("Client run callback for PolicyKit authentication");
3840 3841
            /* Run the authentication callback */
            if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) {
3842 3843
                virReportError(VIR_ERR_AUTH_FAILED, "%s",
                               _("Failed to collect auth credentials"));
3844 3845
                return -1;
            }
3846
        } else {
3847
            VIR_DEBUG("Client auth callback does not support PolicyKit");
3848
            return -1;
3849 3850
        }
    } else {
3851
        VIR_DEBUG("No auth callback provided");
3852
        return -1;
3853 3854
    }

3855
    memset (&ret, 0, sizeof(ret));
3856
    if (call (conn, priv, 0, REMOTE_PROC_AUTH_POLKIT,
3857 3858 3859 3860 3861
              (xdrproc_t) xdr_void, (char *)NULL,
              (xdrproc_t) xdr_remote_auth_polkit_ret, (char *) &ret) != 0) {
        return -1; /* virError already set by call */
    }

3862
out:
3863
    VIR_DEBUG("PolicyKit-0 authentication complete");
3864 3865
    return 0;
}
3866
# endif /* HAVE_POLKIT0 */
3867
#endif /* HAVE_POLKIT */
3868 3869
/*----------------------------------------------------------------------*/

3870 3871 3872 3873
static int remoteDomainEventRegister(virConnectPtr conn,
                                     virConnectDomainEventCallback callback,
                                     void *opaque,
                                     virFreeCallback freecb)
3874
{
3875
    int rv = -1;
3876
    struct private_data *priv = conn->privateData;
3877
    int count;
3878

3879 3880
    remoteDriverLock(priv);

3881 3882
    if ((count = virDomainEventStateRegister(conn, priv->domainEventState,
                                             callback, opaque, freecb)) < 0) {
3883
         virReportError(VIR_ERR_RPC, "%s", _("adding cb to list"));
3884
         goto done;
3885 3886
    }

3887
    if (count == 1) {
3888 3889 3890 3891
        /* Tell the server when we are the first callback deregistering */
        if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_EVENTS_REGISTER,
                (xdrproc_t) xdr_void, (char *) NULL,
                (xdrproc_t) xdr_void, (char *) NULL) == -1)
3892
            goto done;
3893 3894
    }

3895 3896 3897
    rv = 0;

done:
3898
    remoteDriverUnlock(priv);
3899
    return rv;
3900 3901
}

3902 3903
static int remoteDomainEventDeregister(virConnectPtr conn,
                                       virConnectDomainEventCallback callback)
3904 3905
{
    struct private_data *priv = conn->privateData;
3906
    int rv = -1;
3907
    int count;
3908

3909 3910
    remoteDriverLock(priv);

3911 3912 3913
    if ((count = virDomainEventStateDeregister(conn,
                                               priv->domainEventState,
                                               callback)) < 0)
3914
        goto done;
3915

3916
    if (count == 0) {
3917 3918 3919 3920 3921
        /* Tell the server when we are the last callback deregistering */
        if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER,
                  (xdrproc_t) xdr_void, (char *) NULL,
                  (xdrproc_t) xdr_void, (char *) NULL) == -1)
            goto done;
3922 3923
    }

3924 3925 3926
    rv = 0;

done:
3927
    remoteDriverUnlock(priv);
3928
    return rv;
3929
}
3930

3931 3932 3933 3934 3935

static void
remoteDomainBuildEventLifecycle(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                                virNetClientPtr client ATTRIBUTE_UNUSED,
                                void *evdata, void *opaque)
3936
{
3937 3938 3939
    virConnectPtr conn = opaque;
    struct private_data *priv = conn->privateData;
    remote_domain_event_lifecycle_msg *msg = evdata;
3940 3941 3942
    virDomainPtr dom;
    virDomainEventPtr event = NULL;

3943
    dom = get_nonnull_domain(conn, msg->dom);
3944
    if (!dom)
3945
        return;
3946

3947
    event = virDomainEventNewFromDom(dom, msg->event, msg->detail);
3948
    virDomainFree(dom);
3949 3950

    remoteDomainEventQueue(priv, event);
3951 3952 3953
}


3954 3955 3956 3957
static void
remoteDomainBuildEventReboot(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                             virNetClientPtr client ATTRIBUTE_UNUSED,
                             void *evdata, void *opaque)
3958
{
3959 3960 3961
    virConnectPtr conn = opaque;
    struct private_data *priv = conn->privateData;
    remote_domain_event_reboot_msg *msg = evdata;
3962 3963 3964
    virDomainPtr dom;
    virDomainEventPtr event = NULL;

3965
    dom = get_nonnull_domain(conn, msg->dom);
3966
    if (!dom)
3967
        return;
3968 3969 3970

    event = virDomainEventRebootNewFromDom(dom);
    virDomainFree(dom);
3971 3972

    remoteDomainEventQueue(priv, event);
3973 3974 3975
}


3976 3977 3978 3979
static void
remoteDomainBuildEventRTCChange(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                                virNetClientPtr client ATTRIBUTE_UNUSED,
                                void *evdata, void *opaque)
3980
{
3981 3982 3983
    virConnectPtr conn = opaque;
    struct private_data *priv = conn->privateData;
    remote_domain_event_rtc_change_msg *msg = evdata;
3984 3985 3986
    virDomainPtr dom;
    virDomainEventPtr event = NULL;

3987
    dom = get_nonnull_domain(conn, msg->dom);
3988
    if (!dom)
3989
        return;
3990

3991
    event = virDomainEventRTCChangeNewFromDom(dom, msg->offset);
3992
    virDomainFree(dom);
3993 3994

    remoteDomainEventQueue(priv, event);
3995 3996 3997
}


3998 3999 4000 4001
static void
remoteDomainBuildEventWatchdog(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                               virNetClientPtr client ATTRIBUTE_UNUSED,
                               void *evdata, void *opaque)
4002
{
4003 4004 4005
    virConnectPtr conn = opaque;
    struct private_data *priv = conn->privateData;
    remote_domain_event_watchdog_msg *msg = evdata;
4006 4007 4008
    virDomainPtr dom;
    virDomainEventPtr event = NULL;

4009
    dom = get_nonnull_domain(conn, msg->dom);
4010
    if (!dom)
4011
        return;
4012

4013
    event = virDomainEventWatchdogNewFromDom(dom, msg->action);
4014
    virDomainFree(dom);
4015 4016

    remoteDomainEventQueue(priv, event);
4017 4018 4019
}


4020 4021 4022 4023
static void
remoteDomainBuildEventIOError(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                              virNetClientPtr client ATTRIBUTE_UNUSED,
                              void *evdata, void *opaque)
4024
{
4025 4026 4027
    virConnectPtr conn = opaque;
    struct private_data *priv = conn->privateData;
    remote_domain_event_io_error_msg *msg = evdata;
4028 4029 4030
    virDomainPtr dom;
    virDomainEventPtr event = NULL;

4031
    dom = get_nonnull_domain(conn, msg->dom);
4032
    if (!dom)
4033
        return;
4034 4035

    event = virDomainEventIOErrorNewFromDom(dom,
4036 4037 4038
                                            msg->srcPath,
                                            msg->devAlias,
                                            msg->action);
4039
    virDomainFree(dom);
4040 4041

    remoteDomainEventQueue(priv, event);
4042 4043 4044
}


4045 4046 4047 4048
static void
remoteDomainBuildEventIOErrorReason(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                                    virNetClientPtr client ATTRIBUTE_UNUSED,
                                    void *evdata, void *opaque)
4049
{
4050 4051 4052
    virConnectPtr conn = opaque;
    struct private_data *priv = conn->privateData;
    remote_domain_event_io_error_reason_msg *msg = evdata;
4053 4054 4055
    virDomainPtr dom;
    virDomainEventPtr event = NULL;

4056
    dom = get_nonnull_domain(conn,msg->dom);
4057
    if (!dom)
4058
        return;
4059 4060

    event = virDomainEventIOErrorReasonNewFromDom(dom,
4061 4062 4063 4064
                                                  msg->srcPath,
                                                  msg->devAlias,
                                                  msg->action,
                                                  msg->reason);
4065 4066

    virDomainFree(dom);
4067 4068

    remoteDomainEventQueue(priv, event);
4069 4070
}

4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092
static void
remoteDomainBuildEventBlockJob(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                               virNetClientPtr client ATTRIBUTE_UNUSED,
                               void *evdata, void *opaque)
{
    virConnectPtr conn = opaque;
    struct private_data *priv = conn->privateData;
    remote_domain_event_block_job_msg *msg = evdata;
    virDomainPtr dom;
    virDomainEventPtr event = NULL;

    dom = get_nonnull_domain(conn, msg->dom);
    if (!dom)
        return;

    event = virDomainEventBlockJobNewFromDom(dom, msg->path, msg->type,
                                             msg->status);

    virDomainFree(dom);

    remoteDomainEventQueue(priv, event);
}
4093

4094 4095 4096 4097
static void
remoteDomainBuildEventGraphics(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                               virNetClientPtr client ATTRIBUTE_UNUSED,
                               void *evdata, void *opaque)
4098
{
4099 4100 4101
    virConnectPtr conn = opaque;
    struct private_data *priv = conn->privateData;
    remote_domain_event_graphics_msg *msg = evdata;
4102 4103 4104 4105 4106 4107 4108
    virDomainPtr dom;
    virDomainEventPtr event = NULL;
    virDomainEventGraphicsAddressPtr localAddr = NULL;
    virDomainEventGraphicsAddressPtr remoteAddr = NULL;
    virDomainEventGraphicsSubjectPtr subject = NULL;
    int i;

4109
    dom = get_nonnull_domain(conn, msg->dom);
4110
    if (!dom)
4111
        return;
4112 4113 4114

    if (VIR_ALLOC(localAddr) < 0)
        goto no_memory;
4115 4116 4117
    localAddr->family = msg->local.family;
    if (!(localAddr->service = strdup(msg->local.service)) ||
        !(localAddr->node = strdup(msg->local.node)))
4118 4119 4120 4121
        goto no_memory;

    if (VIR_ALLOC(remoteAddr) < 0)
        goto no_memory;
4122 4123 4124
    remoteAddr->family = msg->remote.family;
    if (!(remoteAddr->service = strdup(msg->remote.service)) ||
        !(remoteAddr->node = strdup(msg->remote.node)))
4125 4126 4127 4128
        goto no_memory;

    if (VIR_ALLOC(subject) < 0)
        goto no_memory;
4129
    if (VIR_ALLOC_N(subject->identities, msg->subject.subject_len) < 0)
4130
        goto no_memory;
4131
    subject->nidentity = msg->subject.subject_len;
4132
    for (i = 0 ; i < subject->nidentity ; i++) {
4133 4134
        if (!(subject->identities[i].type = strdup(msg->subject.subject_val[i].type)) ||
            !(subject->identities[i].name = strdup(msg->subject.subject_val[i].name)))
4135 4136 4137 4138
            goto no_memory;
    }

    event = virDomainEventGraphicsNewFromDom(dom,
4139
                                             msg->phase,
4140 4141
                                             localAddr,
                                             remoteAddr,
4142
                                             msg->authScheme,
4143 4144 4145 4146
                                             subject);

    virDomainFree(dom);

4147 4148
    remoteDomainEventQueue(priv, event);
    return;
4149

4150
no_memory:
4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168
    if (localAddr) {
        VIR_FREE(localAddr->service);
        VIR_FREE(localAddr->node);
        VIR_FREE(localAddr);
    }
    if (remoteAddr) {
        VIR_FREE(remoteAddr->service);
        VIR_FREE(remoteAddr->node);
        VIR_FREE(remoteAddr);
    }
    if (subject) {
        for (i = 0 ; i < subject->nidentity ; i++) {
            VIR_FREE(subject->identities[i].type);
            VIR_FREE(subject->identities[i].name);
        }
        VIR_FREE(subject->identities);
        VIR_FREE(subject);
    }
A
ajia@redhat.com 已提交
4169
    virDomainFree(dom);
4170
    return;
4171 4172 4173
}


4174 4175 4176 4177
static void
remoteDomainBuildEventControlError(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                                   virNetClientPtr client ATTRIBUTE_UNUSED,
                                   void *evdata, void *opaque)
4178
{
4179 4180 4181
    virConnectPtr conn = opaque;
    struct private_data *priv = conn->privateData;
    remote_domain_event_control_error_msg *msg = evdata;
4182 4183 4184
    virDomainPtr dom;
    virDomainEventPtr event = NULL;

4185
    dom = get_nonnull_domain(conn, msg->dom);
4186
    if (!dom)
4187
        return;
4188 4189 4190 4191

    event = virDomainEventControlErrorNewFromDom(dom);

    virDomainFree(dom);
4192 4193

    remoteDomainEventQueue(priv, event);
4194 4195 4196
}


4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223
static void
remoteDomainBuildEventDiskChange(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                                 virNetClientPtr client ATTRIBUTE_UNUSED,
                                 void *evdata, void *opaque)
{
    virConnectPtr conn = opaque;
    struct private_data *priv = conn->privateData;
    remote_domain_event_disk_change_msg *msg = evdata;
    virDomainPtr dom;
    virDomainEventPtr event = NULL;

    dom = get_nonnull_domain(conn, msg->dom);
    if (!dom)
        return;

    event = virDomainEventDiskChangeNewFromDom(dom,
                                               msg->oldSrcPath ? *msg->oldSrcPath : NULL,
                                               msg->newSrcPath ? *msg->newSrcPath : NULL,
                                               msg->devAlias,
                                               msg->reason);

    virDomainFree(dom);

    remoteDomainEventQueue(priv, event);
}


4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247
static void
remoteDomainBuildEventTrayChange(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                                 virNetClientPtr client ATTRIBUTE_UNUSED,
                                 void *evdata, void *opaque)
{
    virConnectPtr conn = opaque;
    struct private_data *priv = conn->privateData;
    remote_domain_event_tray_change_msg *msg = evdata;
    virDomainPtr dom;
    virDomainEventPtr event = NULL;

    dom = get_nonnull_domain(conn, msg->dom);
    if (!dom)
        return;

    event = virDomainEventTrayChangeNewFromDom(dom,
                                               msg->devAlias,
                                               msg->reason);

    virDomainFree(dom);

    remoteDomainEventQueue(priv, event);
}

O
Osier Yang 已提交
4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268
static void
remoteDomainBuildEventPMWakeup(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                               virNetClientPtr client ATTRIBUTE_UNUSED,
                               void *evdata, void *opaque)
{
    virConnectPtr conn = opaque;
    struct private_data *priv = conn->privateData;
    remote_domain_event_pmwakeup_msg *msg = evdata;
    virDomainPtr dom;
    virDomainEventPtr event = NULL;

    dom = get_nonnull_domain(conn, msg->dom);
    if (!dom)
        return;

    event = virDomainEventPMWakeupNewFromDom(dom);

    virDomainFree(dom);

    remoteDomainEventQueue(priv, event);
}
4269

O
Osier Yang 已提交
4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291
static void
remoteDomainBuildEventPMSuspend(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                                virNetClientPtr client ATTRIBUTE_UNUSED,
                                void *evdata, void *opaque)
{
    virConnectPtr conn = opaque;
    struct private_data *priv = conn->privateData;
    remote_domain_event_pmsuspend_msg *msg = evdata;
    virDomainPtr dom;
    virDomainEventPtr event = NULL;

    dom = get_nonnull_domain(conn, msg->dom);
    if (!dom)
        return;

    event = virDomainEventPMSuspendNewFromDom(dom);

    virDomainFree(dom);

    remoteDomainEventQueue(priv, event);
}

4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314

static void
remoteDomainBuildEventBalloonChange(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                                    virNetClientPtr client ATTRIBUTE_UNUSED,
                                    void *evdata, void *opaque)
{
    virConnectPtr conn = opaque;
    struct private_data *priv = conn->privateData;
    remote_domain_event_balloon_change_msg *msg = evdata;
    virDomainPtr dom;
    virDomainEventPtr event = NULL;

    dom = get_nonnull_domain(conn, msg->dom);
    if (!dom)
        return;

    event = virDomainEventBalloonChangeNewFromDom(dom, msg->actual);
    virDomainFree(dom);

    remoteDomainEventQueue(priv, event);
}


J
Jim Meyering 已提交
4315
static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
4316 4317
remoteSecretOpen(virConnectPtr conn, virConnectAuthPtr auth,
                 unsigned int flags)
4318
{
4319
    return remoteGenericOpen(conn, auth, flags, &conn->secretPrivateData);
4320 4321 4322 4323 4324
}

static int
remoteSecretClose (virConnectPtr conn)
{
4325
    return remoteGenericClose(conn, &conn->secretPrivateData);
4326 4327 4328 4329
}

static unsigned char *
remoteSecretGetValue (virSecretPtr secret, size_t *value_size,
4330
                      unsigned int flags, unsigned int internalFlags)
4331 4332 4333 4334 4335 4336 4337 4338
{
    unsigned char *rv = NULL;
    remote_secret_get_value_args args;
    remote_secret_get_value_ret ret;
    struct private_data *priv = secret->conn->secretPrivateData;

    remoteDriverLock (priv);

4339 4340
    /* internalFlags intentionally do not go over the wire */
    if (internalFlags) {
4341
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no internalFlags support"));
4342 4343 4344
        goto done;
    }

4345 4346 4347
    make_nonnull_secret (&args.secret, secret);
    args.flags = flags;

4348
    memset (&ret, 0, sizeof(ret));
4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361
    if (call (secret->conn, priv, 0, REMOTE_PROC_SECRET_GET_VALUE,
              (xdrproc_t) xdr_remote_secret_get_value_args, (char *) &args,
              (xdrproc_t) xdr_remote_secret_get_value_ret, (char *) &ret) == -1)
        goto done;

    *value_size = ret.value.value_len;
    rv = (unsigned char *) ret.value.value_val; /* Caller frees. */

done:
    remoteDriverUnlock (priv);
    return rv;
}

4362 4363 4364 4365 4366 4367

static int
remoteStreamSend(virStreamPtr st,
                 const char *data,
                 size_t nbytes)
{
4368
    VIR_DEBUG("st=%p data=%p nbytes=%zu", st, data, nbytes);
4369
    struct private_data *priv = st->conn->privateData;
4370
    virNetClientStreamPtr privst = st->privateData;
4371
    int rv;
4372

4373
    if (virNetClientStreamRaiseError(privst))
4374 4375 4376 4377 4378
        return -1;

    remoteDriverLock(priv);
    priv->localUses++;
    remoteDriverUnlock(priv);
4379

4380 4381 4382 4383 4384
    rv = virNetClientStreamSendPacket(privst,
                                      priv->client,
                                      VIR_NET_CONTINUE,
                                      data,
                                      nbytes);
4385

4386 4387
    remoteDriverLock(priv);
    priv->localUses--;
4388 4389 4390 4391 4392 4393 4394 4395 4396 4397
    remoteDriverUnlock(priv);
    return rv;
}


static int
remoteStreamRecv(virStreamPtr st,
                 char *data,
                 size_t nbytes)
{
4398
    VIR_DEBUG("st=%p data=%p nbytes=%zu", st, data, nbytes);
4399
    struct private_data *priv = st->conn->privateData;
4400
    virNetClientStreamPtr privst = st->privateData;
4401
    int rv;
4402

4403
    if (virNetClientStreamRaiseError(privst))
4404 4405 4406 4407 4408
        return -1;

    remoteDriverLock(priv);
    priv->localUses++;
    remoteDriverUnlock(priv);
4409

4410 4411 4412 4413 4414
    rv = virNetClientStreamRecvPacket(privst,
                                      priv->client,
                                      data,
                                      nbytes,
                                      (st->flags & VIR_STREAM_NONBLOCK));
4415

4416
    VIR_DEBUG("Done %d", rv);
4417

4418 4419
    remoteDriverLock(priv);
    priv->localUses--;
4420 4421 4422 4423
    remoteDriverUnlock(priv);
    return rv;
}

4424 4425 4426 4427 4428 4429
struct remoteStreamCallbackData {
    virStreamPtr st;
    virStreamEventCallback cb;
    void *opaque;
    virFreeCallback ff;
};
4430

4431 4432 4433
static void remoteStreamEventCallback(virNetClientStreamPtr stream ATTRIBUTE_UNUSED,
                                      int events,
                                      void *opaque)
4434
{
4435
    struct remoteStreamCallbackData *cbdata = opaque;
4436

4437
    (cbdata->cb)(cbdata->st, events, cbdata->opaque);
4438 4439 4440
}


4441
static void remoteStreamCallbackFree(void *opaque)
4442
{
4443 4444 4445 4446 4447 4448 4449
    struct remoteStreamCallbackData *cbdata = opaque;

    if (!cbdata->cb && cbdata->ff)
        (cbdata->ff)(cbdata->opaque);

    virStreamFree(cbdata->st);
    VIR_FREE(opaque);
4450 4451 4452
}


4453
static int
4454 4455 4456 4457 4458
remoteStreamEventAddCallback(virStreamPtr st,
                             int events,
                             virStreamEventCallback cb,
                             void *opaque,
                             virFreeCallback ff)
4459
{
4460
    struct private_data *priv = st->conn->privateData;
4461
    virNetClientStreamPtr privst = st->privateData;
4462
    int ret = -1;
4463
    struct remoteStreamCallbackData *cbdata;
4464

4465 4466 4467
    if (VIR_ALLOC(cbdata) < 0) {
        virReportOOMError();
        return -1;
4468
    }
4469 4470 4471 4472
    cbdata->cb = cb;
    cbdata->opaque = opaque;
    cbdata->ff = ff;
    cbdata->st = st;
4473 4474
    virStreamRef(st);

4475
    remoteDriverLock(priv);
4476

4477 4478 4479 4480 4481 4482 4483 4484
    if ((ret = virNetClientStreamEventAddCallback(privst,
                                                  events,
                                                  remoteStreamEventCallback,
                                                  cbdata,
                                                  remoteStreamCallbackFree)) < 0) {
        VIR_FREE(cbdata);
        goto cleanup;
    }
4485 4486 4487 4488

cleanup:
    remoteDriverUnlock(priv);
    return ret;
4489 4490
}

4491

4492
static int
4493 4494
remoteStreamEventUpdateCallback(virStreamPtr st,
                                int events)
4495
{
4496
    struct private_data *priv = st->conn->privateData;
4497
    virNetClientStreamPtr privst = st->privateData;
4498 4499 4500 4501
    int ret = -1;

    remoteDriverLock(priv);

4502
    ret = virNetClientStreamEventUpdateCallback(privst, events);
4503

4504 4505 4506
    remoteDriverUnlock(priv);
    return ret;
}
4507 4508 4509


static int
4510
remoteStreamEventRemoveCallback(virStreamPtr st)
4511
{
4512
    struct private_data *priv = st->conn->privateData;
4513
    virNetClientStreamPtr privst = st->privateData;
4514 4515 4516 4517
    int ret = -1;

    remoteDriverLock(priv);

4518
    ret = virNetClientStreamEventRemoveCallback(privst);
4519 4520 4521

    remoteDriverUnlock(priv);
    return ret;
4522 4523
}

4524

4525 4526 4527 4528
static int
remoteStreamFinish(virStreamPtr st)
{
    struct private_data *priv = st->conn->privateData;
4529
    virNetClientStreamPtr privst = st->privateData;
4530 4531 4532 4533
    int ret = -1;

    remoteDriverLock(priv);

4534
    if (virNetClientStreamRaiseError(privst))
4535 4536
        goto cleanup;

4537 4538 4539
    priv->localUses++;
    remoteDriverUnlock(priv);

4540 4541 4542 4543 4544
    ret = virNetClientStreamSendPacket(privst,
                                       priv->client,
                                       VIR_NET_OK,
                                       NULL,
                                       0);
4545

4546 4547 4548
    remoteDriverLock(priv);
    priv->localUses--;

4549
cleanup:
4550
    virNetClientRemoveStream(priv->client, privst);
4551
    virObjectUnref(privst);
4552 4553
    st->privateData = NULL;
    st->driver = NULL;
4554 4555 4556 4557 4558

    remoteDriverUnlock(priv);
    return ret;
}

4559

4560 4561 4562 4563
static int
remoteStreamAbort(virStreamPtr st)
{
    struct private_data *priv = st->conn->privateData;
4564
    virNetClientStreamPtr privst = st->privateData;
4565 4566 4567 4568
    int ret = -1;

    remoteDriverLock(priv);

4569
    if (virNetClientStreamRaiseError(privst))
4570 4571
        goto cleanup;

4572 4573 4574
    priv->localUses++;
    remoteDriverUnlock(priv);

4575 4576 4577 4578 4579
    ret = virNetClientStreamSendPacket(privst,
                                       priv->client,
                                       VIR_NET_ERROR,
                                       NULL,
                                       0);
4580

4581 4582 4583
    remoteDriverLock(priv);
    priv->localUses--;

4584
cleanup:
4585
    virNetClientRemoveStream(priv->client, privst);
4586
    virObjectUnref(privst);
4587 4588
    st->privateData = NULL;
    st->driver = NULL;
4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604

    remoteDriverUnlock(priv);
    return ret;
}


static virStreamDriver remoteStreamDrv = {
    .streamRecv = remoteStreamRecv,
    .streamSend = remoteStreamSend,
    .streamFinish = remoteStreamFinish,
    .streamAbort = remoteStreamAbort,
    .streamAddCallback = remoteStreamEventAddCallback,
    .streamUpdateCallback = remoteStreamEventUpdateCallback,
    .streamRemoveCallback = remoteStreamEventRemoveCallback,
};

4605

4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616
static int remoteDomainEventRegisterAny(virConnectPtr conn,
                                        virDomainPtr dom,
                                        int eventID,
                                        virConnectDomainEventGenericCallback callback,
                                        void *opaque,
                                        virFreeCallback freecb)
{
    int rv = -1;
    struct private_data *priv = conn->privateData;
    remote_domain_events_register_any_args args;
    int callbackID;
4617
    int count;
4618 4619 4620

    remoteDriverLock(priv);

4621 4622 4623 4624 4625
    if ((count = virDomainEventStateRegisterID(conn,
                                               priv->domainEventState,
                                               dom, eventID,
                                               callback, opaque, freecb,
                                               &callbackID)) < 0) {
4626
        virReportError(VIR_ERR_RPC, "%s", _("adding cb to list"));
4627
        goto done;
4628 4629 4630 4631
    }

    /* If this is the first callback for this eventID, we need to enable
     * events on the server */
4632
    if (count == 1) {
4633 4634 4635 4636 4637
        args.eventID = eventID;

        if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_EVENTS_REGISTER_ANY,
                  (xdrproc_t) xdr_remote_domain_events_register_any_args, (char *) &args,
                  (xdrproc_t) xdr_void, (char *)NULL) == -1) {
4638 4639 4640
            virDomainEventStateDeregisterID(conn,
                                            priv->domainEventState,
                                            callbackID);
4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659
            goto done;
        }
    }

    rv = callbackID;

done:
    remoteDriverUnlock(priv);
    return rv;
}


static int remoteDomainEventDeregisterAny(virConnectPtr conn,
                                          int callbackID)
{
    struct private_data *priv = conn->privateData;
    int rv = -1;
    remote_domain_events_deregister_any_args args;
    int eventID;
4660
    int count;
4661 4662 4663

    remoteDriverLock(priv);

4664 4665 4666
    if ((eventID = virDomainEventStateEventID(conn,
                                              priv->domainEventState,
                                              callbackID)) < 0) {
4667
        virReportError(VIR_ERR_RPC, _("unable to find callback ID %d"), callbackID);
4668 4669 4670
        goto done;
    }

4671 4672 4673
    if ((count = virDomainEventStateDeregisterID(conn,
                                                 priv->domainEventState,
                                                 callbackID)) < 0) {
4674
        virReportError(VIR_ERR_RPC, _("unable to find callback ID %d"), callbackID);
4675
        goto done;
4676
    }
4677 4678 4679

    /* If that was the last callback for this eventID, we need to disable
     * events on the server */
4680 4681
    if (count == 0) {
        args.eventID = callbackID;
4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695

        if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER_ANY,
                  (xdrproc_t) xdr_remote_domain_events_deregister_any_args, (char *) &args,
                  (xdrproc_t) xdr_void, (char *) NULL) == -1)
            goto done;
    }

    rv = 0;

done:
    remoteDriverUnlock(priv);
    return rv;
}

4696

4697 4698
/*----------------------------------------------------------------------*/

C
Chris Lalancette 已提交
4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709
static int
remoteQemuDomainMonitorCommand (virDomainPtr domain, const char *cmd,
                                char **result, unsigned int flags)
{
    int rv = -1;
    qemu_monitor_command_args args;
    qemu_monitor_command_ret ret;
    struct private_data *priv = domain->conn->privateData;

    remoteDriverLock(priv);

4710
    make_nonnull_domain(&args.dom, domain);
C
Chris Lalancette 已提交
4711 4712 4713
    args.cmd = (char *)cmd;
    args.flags = flags;

4714
    memset (&ret, 0, sizeof(ret));
4715
    if (call (domain->conn, priv, REMOTE_CALL_QEMU, QEMU_PROC_MONITOR_COMMAND,
C
Chris Lalancette 已提交
4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735
              (xdrproc_t) xdr_qemu_monitor_command_args, (char *) &args,
              (xdrproc_t) xdr_qemu_monitor_command_ret, (char *) &ret) == -1)
        goto done;

    *result = strdup(ret.result);
    if (*result == NULL) {
        virReportOOMError();
        goto cleanup;
    }

    rv = 0;

cleanup:
    xdr_free ((xdrproc_t) xdr_qemu_monitor_command_ret, (char *) &ret);

done:
    remoteDriverUnlock(priv);
    return rv;
}

4736 4737 4738

static char *
remoteDomainMigrateBegin3(virDomainPtr domain,
4739
                          const char *xmlin,
4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756
                          char **cookieout,
                          int *cookieoutlen,
                          unsigned long flags,
                          const char *dname,
                          unsigned long resource)
{
    char *rv = NULL;
    remote_domain_migrate_begin3_args args;
    remote_domain_migrate_begin3_ret ret;
    struct private_data *priv = domain->conn->privateData;

    remoteDriverLock(priv);

    memset(&args, 0, sizeof(args));
    memset(&ret, 0, sizeof(ret));

    make_nonnull_domain (&args.dom, domain);
4757
    args.xmlin = xmlin == NULL ? NULL : (char **) &xmlin;
4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768
    args.flags = flags;
    args.dname = dname == NULL ? NULL : (char **) &dname;
    args.resource = resource;

    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_MIGRATE_BEGIN3,
              (xdrproc_t) xdr_remote_domain_migrate_begin3_args, (char *) &args,
              (xdrproc_t) xdr_remote_domain_migrate_begin3_ret, (char *) &ret) == -1)
        goto done;

    if (ret.cookie_out.cookie_out_len > 0) {
        if (!cookieout || !cookieoutlen) {
4769 4770
            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                           _("caller ignores cookieout or cookieoutlen"));
4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819
            goto error;
        }
        *cookieout = ret.cookie_out.cookie_out_val; /* Caller frees. */
        *cookieoutlen = ret.cookie_out.cookie_out_len;
    }

    rv = ret.xml; /* caller frees */

done:
    remoteDriverUnlock(priv);
    return rv;

error:
    VIR_FREE(ret.cookie_out.cookie_out_val);
    goto done;
}


static int
remoteDomainMigratePrepare3(virConnectPtr dconn,
                            const char *cookiein,
                            int cookieinlen,
                            char **cookieout,
                            int *cookieoutlen,
                            const char *uri_in,
                            char **uri_out,
                            unsigned long flags,
                            const char *dname,
                            unsigned long resource,
                            const char *dom_xml)
{
    int rv = -1;
    remote_domain_migrate_prepare3_args args;
    remote_domain_migrate_prepare3_ret ret;
    struct private_data *priv = dconn->privateData;

    remoteDriverLock(priv);

    memset(&args, 0, sizeof(args));
    memset(&ret, 0, sizeof(ret));

    args.cookie_in.cookie_in_val = (char *)cookiein;
    args.cookie_in.cookie_in_len = cookieinlen;
    args.uri_in = uri_in == NULL ? NULL : (char **) &uri_in;
    args.flags = flags;
    args.dname = dname == NULL ? NULL : (char **) &dname;
    args.resource = resource;
    args.dom_xml = (char *) dom_xml;

4820
    memset (&ret, 0, sizeof(ret));
4821 4822 4823 4824 4825 4826 4827
    if (call (dconn, priv, 0, REMOTE_PROC_DOMAIN_MIGRATE_PREPARE3,
              (xdrproc_t) xdr_remote_domain_migrate_prepare3_args, (char *) &args,
              (xdrproc_t) xdr_remote_domain_migrate_prepare3_ret, (char *) &ret) == -1)
        goto done;

    if (ret.cookie_out.cookie_out_len > 0) {
        if (!cookieout || !cookieoutlen) {
4828 4829
            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                           _("caller ignores cookieout or cookieoutlen"));
4830 4831 4832 4833 4834 4835 4836
            goto error;
        }
        *cookieout = ret.cookie_out.cookie_out_val; /* Caller frees. */
        *cookieoutlen = ret.cookie_out.cookie_out_len;
    }
    if (ret.uri_out) {
        if (!uri_out) {
4837 4838
            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                           _("caller ignores uri_out"));
4839 4840 4841 4842 4843 4844 4845 4846
            goto error;
        }
        *uri_out = *ret.uri_out; /* Caller frees. */
    }

    rv = 0;

done:
O
Osier Yang 已提交
4847
    VIR_FREE(ret.uri_out);
4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873
    remoteDriverUnlock(priv);
    return rv;
error:
    VIR_FREE(ret.cookie_out.cookie_out_val);
    if (ret.uri_out)
        VIR_FREE(*ret.uri_out);
    goto done;
}


static int
remoteDomainMigratePrepareTunnel3(virConnectPtr dconn,
                                  virStreamPtr st,
                                  const char *cookiein,
                                  int cookieinlen,
                                  char **cookieout,
                                  int *cookieoutlen,
                                  unsigned long flags,
                                  const char *dname,
                                  unsigned long resource,
                                  const char *dom_xml)
{
    struct private_data *priv = dconn->privateData;
    int rv = -1;
    remote_domain_migrate_prepare_tunnel3_args args;
    remote_domain_migrate_prepare_tunnel3_ret ret;
4874
    virNetClientStreamPtr netst;
4875 4876 4877 4878 4879 4880

    remoteDriverLock(priv);

    memset(&args, 0, sizeof(args));
    memset(&ret, 0, sizeof(ret));

4881
    if (!(netst = virNetClientStreamNew(priv->remoteProgram,
4882
                                        REMOTE_PROC_DOMAIN_MIGRATE_PREPARE_TUNNEL3,
4883
                                        priv->counter)))
4884 4885
        goto done;

4886
    if (virNetClientAddStream(priv->client, netst) < 0) {
4887
        virObjectUnref(netst);
4888 4889 4890
        goto done;
    }

4891
    st->driver = &remoteStreamDrv;
4892
    st->privateData = netst;
4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903

    args.cookie_in.cookie_in_val = (char *)cookiein;
    args.cookie_in.cookie_in_len = cookieinlen;
    args.flags = flags;
    args.dname = dname == NULL ? NULL : (char **) &dname;
    args.resource = resource;
    args.dom_xml = (char *) dom_xml;

    if (call(dconn, priv, 0, REMOTE_PROC_DOMAIN_MIGRATE_PREPARE_TUNNEL3,
             (xdrproc_t) xdr_remote_domain_migrate_prepare_tunnel3_args, (char *) &args,
             (xdrproc_t) xdr_remote_domain_migrate_prepare_tunnel3_ret, (char *) &ret) == -1) {
4904
        virNetClientRemoveStream(priv->client, netst);
4905
        virObjectUnref(netst);
4906 4907 4908 4909 4910
        goto done;
    }

    if (ret.cookie_out.cookie_out_len > 0) {
        if (!cookieout || !cookieoutlen) {
4911 4912
            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                           _("caller ignores cookieout or cookieoutlen"));
4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932
            goto error;
        }
        *cookieout = ret.cookie_out.cookie_out_val; /* Caller frees. */
        *cookieoutlen = ret.cookie_out.cookie_out_len;
    }

    rv = 0;

done:
    remoteDriverUnlock(priv);
    return rv;

error:
    VIR_FREE(ret.cookie_out.cookie_out_val);
    goto done;
}


static int
remoteDomainMigratePerform3(virDomainPtr dom,
4933
                            const char *xmlin,
4934 4935 4936 4937
                            const char *cookiein,
                            int cookieinlen,
                            char **cookieout,
                            int *cookieoutlen,
4938
                            const char *dconnuri,
4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955
                            const char *uri,
                            unsigned long flags,
                            const char *dname,
                            unsigned long resource)
{
    int rv = -1;
    remote_domain_migrate_perform3_args args;
    remote_domain_migrate_perform3_ret ret;
    struct private_data *priv = dom->conn->privateData;

    remoteDriverLock(priv);

    memset(&args, 0, sizeof(args));
    memset(&ret, 0, sizeof(ret));

    make_nonnull_domain(&args.dom, dom);

4956
    args.xmlin = xmlin == NULL ? NULL : (char **) &xmlin;
4957 4958 4959 4960
    args.cookie_in.cookie_in_val = (char *)cookiein;
    args.cookie_in.cookie_in_len = cookieinlen;
    args.flags = flags;
    args.dname = dname == NULL ? NULL : (char **) &dname;
4961 4962
    args.uri = uri == NULL ? NULL : (char **) &uri;
    args.dconnuri = dconnuri == NULL ? NULL : (char **) &dconnuri;
4963 4964 4965 4966 4967 4968 4969 4970 4971
    args.resource = resource;

    if (call (dom->conn, priv, 0, REMOTE_PROC_DOMAIN_MIGRATE_PERFORM3,
              (xdrproc_t) xdr_remote_domain_migrate_perform3_args, (char *) &args,
              (xdrproc_t) xdr_remote_domain_migrate_perform3_ret, (char *) &ret) == -1)
        goto done;

    if (ret.cookie_out.cookie_out_len > 0) {
        if (!cookieout || !cookieoutlen) {
4972 4973
            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                           _("caller ignores cookieout or cookieoutlen"));
4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991
            goto error;
        }
        *cookieout = ret.cookie_out.cookie_out_val; /* Caller frees. */
        *cookieoutlen = ret.cookie_out.cookie_out_len;
    }

    rv = 0;

done:
    remoteDriverUnlock(priv);
    return rv;

error:
    VIR_FREE(ret.cookie_out.cookie_out_val);
    goto done;
}


4992
static virDomainPtr
4993 4994 4995 4996 4997 4998
remoteDomainMigrateFinish3(virConnectPtr dconn,
                           const char *dname,
                           const char *cookiein,
                           int cookieinlen,
                           char **cookieout,
                           int *cookieoutlen,
4999
                           const char *dconnuri,
5000 5001
                           const char *uri,
                           unsigned long flags,
5002
                           int cancelled)
5003 5004 5005 5006
{
    remote_domain_migrate_finish3_args args;
    remote_domain_migrate_finish3_ret ret;
    struct private_data *priv = dconn->privateData;
5007
    virDomainPtr rv = NULL;
5008 5009 5010 5011 5012 5013 5014 5015 5016

    remoteDriverLock(priv);

    memset(&args, 0, sizeof(args));
    memset(&ret, 0, sizeof(ret));

    args.cookie_in.cookie_in_val = (char *)cookiein;
    args.cookie_in.cookie_in_len = cookieinlen;
    args.dname = (char *) dname;
5017 5018
    args.uri = uri == NULL ? NULL : (char **) &uri;
    args.dconnuri = dconnuri == NULL ? NULL : (char **) &dconnuri;
5019 5020 5021 5022 5023 5024 5025 5026
    args.flags = flags;
    args.cancelled = cancelled;

    if (call (dconn, priv, 0, REMOTE_PROC_DOMAIN_MIGRATE_FINISH3,
              (xdrproc_t) xdr_remote_domain_migrate_finish3_args, (char *) &args,
              (xdrproc_t) xdr_remote_domain_migrate_finish3_ret, (char *) &ret) == -1)
        goto done;

5027
    rv = get_nonnull_domain(dconn, ret.dom);
5028 5029 5030

    if (ret.cookie_out.cookie_out_len > 0) {
        if (!cookieout || !cookieoutlen) {
5031 5032
            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                           _("caller ignores cookieout or cookieoutlen"));
5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086
            goto error;
        }
        *cookieout = ret.cookie_out.cookie_out_val; /* Caller frees. */
        *cookieoutlen = ret.cookie_out.cookie_out_len;
        ret.cookie_out.cookie_out_val = NULL;
        ret.cookie_out.cookie_out_len = 0;
    }

    xdr_free ((xdrproc_t) &xdr_remote_domain_migrate_finish3_ret, (char *) &ret);

done:
    remoteDriverUnlock(priv);
    return rv;

error:
    VIR_FREE(ret.cookie_out.cookie_out_val);
    goto done;
}


static int
remoteDomainMigrateConfirm3(virDomainPtr domain,
                            const char *cookiein,
                            int cookieinlen,
                            unsigned long flags,
                            int cancelled)
{
    int rv = -1;
    remote_domain_migrate_confirm3_args args;
    struct private_data *priv = domain->conn->privateData;

    remoteDriverLock(priv);

    memset(&args, 0, sizeof(args));

    make_nonnull_domain (&args.dom, domain);
    args.cookie_in.cookie_in_len = cookieinlen;
    args.cookie_in.cookie_in_val = (char *) cookiein;
    args.flags = flags;
    args.cancelled = cancelled;

    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_MIGRATE_CONFIRM3,
              (xdrproc_t) xdr_remote_domain_migrate_confirm3_args, (char *) &args,
              (xdrproc_t) xdr_void, (char *) NULL) == -1)
        goto done;

    rv = 0;

done:
    remoteDriverUnlock(priv);
    return rv;
}


5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116
static int
remoteDomainOpenGraphics(virDomainPtr dom,
                         unsigned int idx,
                         int fd,
                         unsigned int flags)
{
    int rv = -1;
    remote_domain_open_graphics_args args;
    struct private_data *priv = dom->conn->privateData;

    remoteDriverLock(priv);

    make_nonnull_domain (&args.dom, dom);
    args.idx = idx;
    args.flags = flags;

    if (callWithFD(dom->conn, priv, 0, fd, REMOTE_PROC_DOMAIN_OPEN_GRAPHICS,
                   (xdrproc_t) xdr_remote_domain_open_graphics_args, (char *) &args,
                   (xdrproc_t) xdr_void, NULL) == -1)
        goto done;

    rv = 0;

done:
    remoteDriverUnlock(priv);

    return rv;
}


5117 5118 5119 5120 5121 5122 5123 5124
static int
remoteSetKeepAlive(virConnectPtr conn, int interval, unsigned int count)
{
    struct private_data *priv = conn->privateData;
    int ret = -1;

    remoteDriverLock(priv);
    if (!virNetClientKeepAliveIsSupported(priv->client)) {
5125 5126 5127
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("the caller doesn't support keepalive protocol;"
                         " perhaps it's missing event loop implementation"));
5128 5129 5130 5131 5132 5133 5134 5135
        goto cleanup;
    }

    if (!priv->serverKeepAlive) {
        ret = 1;
        goto cleanup;
    }

5136 5137 5138 5139 5140 5141
    if (interval > 0) {
        ret = virNetClientKeepAliveStart(priv->client, interval, count);
    } else {
        virNetClientKeepAliveStop(priv->client);
        ret = 0;
    }
5142 5143 5144 5145 5146 5147 5148

cleanup:
    remoteDriverUnlock(priv);
    return ret;
}


5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165
static int
remoteIsAlive(virConnectPtr conn)
{
    struct private_data *priv = conn->privateData;
    bool ret;

    remoteDriverLock(priv);
    ret = virNetClientIsOpen(priv->client);
    remoteDriverUnlock(priv);

    if (ret)
        return 1;
    else
        return 0;
}


5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182
static int
remoteDomainGetDiskErrors(virDomainPtr dom,
                          virDomainDiskErrorPtr errors,
                          unsigned int maxerrors,
                          unsigned int flags)
{
    int rv = -1;
    struct private_data *priv = dom->conn->privateData;
    remote_domain_get_disk_errors_args args;
    remote_domain_get_disk_errors_ret ret;

    remoteDriverLock(priv);

    make_nonnull_domain(&args.dom, dom);
    args.maxerrors = maxerrors;
    args.flags = flags;

5183
    memset(&ret, 0, sizeof(ret));
5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208

    if (call(dom->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_DISK_ERRORS,
             (xdrproc_t) xdr_remote_domain_get_disk_errors_args,
             (char *) &args,
             (xdrproc_t) xdr_remote_domain_get_disk_errors_ret,
             (char *) &ret) == -1)
        goto done;

    if (remoteDeserializeDomainDiskErrors(ret.errors.errors_val,
                                          ret.errors.errors_len,
                                          REMOTE_DOMAIN_DISK_ERRORS_MAX,
                                          errors,
                                          maxerrors) < 0)
        goto cleanup;

    rv = ret.nerrors;

cleanup:
    xdr_free((xdrproc_t) xdr_remote_domain_get_disk_errors_ret, (char *) &ret);

done:
    remoteDriverUnlock(priv);
    return rv;
}

5209 5210
#include "remote_client_bodies.h"
#include "qemu_client_bodies.h"
5211

5212 5213 5214 5215 5216
/*
 * Serial a set of arguments into a method call message,
 * send that to the server and wait for reply
 */
static int
5217 5218 5219 5220 5221 5222 5223
callWithFD(virConnectPtr conn ATTRIBUTE_UNUSED,
           struct private_data *priv,
           unsigned int flags,
           int fd,
           int proc_nr,
           xdrproc_t args_filter, char *args,
           xdrproc_t ret_filter, char *ret)
5224
{
5225
    int rv;
5226 5227 5228
    virNetClientProgramPtr prog = flags & REMOTE_CALL_QEMU ? priv->qemuProgram : priv->remoteProgram;
    int counter = priv->counter++;
    virNetClientPtr client = priv->client;
5229 5230
    int fds[] = { fd };
    size_t nfds = fd == -1 ? 0 : 1;
5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241
    priv->localUses++;

    /* Unlock, so that if we get any async events/stream data
     * while processing the RPC, we don't deadlock when our
     * callbacks for those are invoked
     */
    remoteDriverUnlock(priv);
    rv = virNetClientProgramCall(prog,
                                 client,
                                 counter,
                                 proc_nr,
5242
                                 nfds, nfds ? fds : NULL, NULL, NULL,
5243 5244 5245 5246
                                 args_filter, args,
                                 ret_filter, ret);
    remoteDriverLock(priv);
    priv->localUses--;
5247

5248
    return rv;
5249 5250
}

5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263
static int
call (virConnectPtr conn,
      struct private_data *priv,
      unsigned int flags,
      int proc_nr,
      xdrproc_t args_filter, char *args,
      xdrproc_t ret_filter, char *ret)
{
    return callWithFD(conn, priv, flags, -1, proc_nr,
                      args_filter, args,
                      ret_filter, ret);
}

5264

5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282
static int
remoteDomainGetInterfaceParameters (virDomainPtr domain,
                                    const char *device,
                                    virTypedParameterPtr params, int *nparams,
                                    unsigned int flags)
{
    int rv = -1;
    remote_domain_get_interface_parameters_args args;
    remote_domain_get_interface_parameters_ret ret;
    struct private_data *priv = domain->conn->privateData;

    remoteDriverLock(priv);

    make_nonnull_domain (&args.dom, domain);
    args.device = (char *)device;
    args.nparams = *nparams;
    args.flags = flags;

5283
    memset (&ret, 0, sizeof(ret));
5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314
    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_INTERFACE_PARAMETERS,
              (xdrproc_t) xdr_remote_domain_get_interface_parameters_args, (char *) &args,
              (xdrproc_t) xdr_remote_domain_get_interface_parameters_ret, (char *) &ret) == -1)
        goto done;

    /* Handle the case when the caller does not know the number of parameters
     * and is asking for the number of parameters supported
     */
    if (*nparams == 0) {
        *nparams = ret.nparams;
        rv = 0;
        goto cleanup;
    }

    if (remoteDeserializeTypedParameters(ret.params.params_val,
                                         ret.params.params_len,
                                         REMOTE_DOMAIN_INTERFACE_PARAMETERS_MAX,
                                         params,
                                         nparams) < 0)
        goto cleanup;

    rv = 0;

cleanup:
    xdr_free ((xdrproc_t) xdr_remote_domain_get_interface_parameters_ret,
              (char *) &ret);
done:
    remoteDriverUnlock(priv);
    return rv;
}

5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329
static int
remoteDomainListAllSnapshots(virDomainPtr dom,
                             virDomainSnapshotPtr **snapshots,
                             unsigned int flags)
{
    int rv = -1;
    int i;
    virDomainSnapshotPtr *snaps = NULL;
    remote_domain_list_all_snapshots_args args;
    remote_domain_list_all_snapshots_ret ret;

    struct private_data *priv = dom->conn->privateData;

    remoteDriverLock(priv);

5330
    make_nonnull_domain(&args.dom, dom);
5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394
    args.need_results = !!snapshots;
    args.flags = flags;

    memset(&ret, 0, sizeof(ret));
    if (call (dom->conn,
              priv,
              0,
              REMOTE_PROC_DOMAIN_LIST_ALL_SNAPSHOTS,
              (xdrproc_t) xdr_remote_domain_list_all_snapshots_args,
              (char *) &args,
              (xdrproc_t) xdr_remote_domain_list_all_snapshots_ret,
              (char *) &ret) == -1)
        goto done;

    if (snapshots) {
        if (VIR_ALLOC_N(snaps, ret.snapshots.snapshots_len + 1) < 0) {
            virReportOOMError();
            goto cleanup;
        }
        for (i = 0; i < ret.snapshots.snapshots_len; i++) {
            snaps[i] = get_nonnull_domain_snapshot(dom, ret.snapshots.snapshots_val[i]);
            if (!snaps[i]) {
                virReportOOMError();
                goto cleanup;
            }
        }
        *snapshots = snaps;
        snaps = NULL;
    }

    rv = ret.ret;

cleanup:
    if (snaps) {
        for (i = 0; i < ret.snapshots.snapshots_len; i++)
            if (snaps[i])
                virDomainSnapshotFree(snaps[i]);
        VIR_FREE(snaps);
    }

    xdr_free((xdrproc_t) xdr_remote_domain_list_all_snapshots_ret, (char *) &ret);

done:
    remoteDriverUnlock(priv);
    return rv;
}

static int
remoteDomainSnapshotListAllChildren(virDomainSnapshotPtr parent,
                                    virDomainSnapshotPtr **snapshots,
                                    unsigned int flags)
{
    int rv = -1;
    int i;
    virDomainSnapshotPtr *snaps = NULL;
    remote_domain_snapshot_list_all_children_args args;
    remote_domain_snapshot_list_all_children_ret ret;

    struct private_data *priv = parent->domain->conn->privateData;

    remoteDriverLock(priv);

    args.need_results = !!snapshots;
    args.flags = flags;
5395
    make_nonnull_domain_snapshot(&args.snapshot, parent);
5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440

    memset(&ret, 0, sizeof(ret));
    if (call (parent->domain->conn,
              priv,
              0,
              REMOTE_PROC_DOMAIN_SNAPSHOT_LIST_ALL_CHILDREN,
              (xdrproc_t) xdr_remote_domain_snapshot_list_all_children_args,
              (char *) &args,
              (xdrproc_t) xdr_remote_domain_snapshot_list_all_children_ret,
              (char *) &ret) == -1)
        goto done;

    if (snapshots) {
        if (VIR_ALLOC_N(snaps, ret.snapshots.snapshots_len + 1) < 0) {
            virReportOOMError();
            goto cleanup;
        }
        for (i = 0; i < ret.snapshots.snapshots_len; i++) {
            snaps[i] = get_nonnull_domain_snapshot(parent->domain, ret.snapshots.snapshots_val[i]);
            if (!snaps[i]) {
                virReportOOMError();
                goto cleanup;
            }
        }
        *snapshots = snaps;
        snaps = NULL;
    }

    rv = ret.ret;

cleanup:
    if (snaps) {
        for (i = 0; i < ret.snapshots.snapshots_len; i++)
            if (snaps[i])
                virDomainSnapshotFree(snaps[i]);
        VIR_FREE(snaps);
    }

    xdr_free((xdrproc_t) xdr_remote_domain_snapshot_list_all_children_ret, (char *) &ret);

done:
    remoteDriverUnlock(priv);
    return rv;
}

5441
static void
5442 5443 5444 5445
remoteDomainEventQueue(struct private_data *priv, virDomainEventPtr event)
{
    virDomainEventStateQueue(priv->domainEventState, event);
}
5446

5447 5448 5449 5450 5451 5452
/* 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,
 * but if they do then virterror_internal.has been set.
 */
static virDomainPtr
5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466
get_nonnull_domain (virConnectPtr conn, remote_nonnull_domain domain)
{
    virDomainPtr dom;
    dom = virGetDomain (conn, domain.name, BAD_CAST domain.uuid);
    if (dom) dom->id = domain.id;
    return dom;
}

static virNetworkPtr
get_nonnull_network (virConnectPtr conn, remote_nonnull_network network)
{
    return virGetNetwork (conn, network.name, BAD_CAST network.uuid);
}

D
Daniel Veillard 已提交
5467
static virInterfacePtr
5468
get_nonnull_interface (virConnectPtr conn, remote_nonnull_interface iface)
D
Daniel Veillard 已提交
5469
{
5470
    return virGetInterface (conn, iface.name, iface.mac);
D
Daniel Veillard 已提交
5471 5472
}

5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484
static virStoragePoolPtr
get_nonnull_storage_pool (virConnectPtr conn, remote_nonnull_storage_pool pool)
{
    return virGetStoragePool (conn, pool.name, BAD_CAST pool.uuid);
}

static virStorageVolPtr
get_nonnull_storage_vol (virConnectPtr conn, remote_nonnull_storage_vol vol)
{
    return virGetStorageVol (conn, vol.pool, vol.name, vol.key);
}

5485 5486 5487 5488 5489 5490
static virNodeDevicePtr
get_nonnull_node_device (virConnectPtr conn, remote_nonnull_node_device dev)
{
    return virGetNodeDevice(conn, dev.name);
}

5491 5492 5493
static virSecretPtr
get_nonnull_secret (virConnectPtr conn, remote_nonnull_secret secret)
{
5494
    return virGetSecret(conn, BAD_CAST secret.uuid, secret.usageType, secret.usageID);
5495 5496
}

5497 5498 5499 5500 5501 5502
static virNWFilterPtr
get_nonnull_nwfilter (virConnectPtr conn, remote_nonnull_nwfilter nwfilter)
{
    return virGetNWFilter (conn, nwfilter.name, BAD_CAST nwfilter.uuid);
}

C
Chris Lalancette 已提交
5503 5504 5505 5506 5507 5508
static virDomainSnapshotPtr
get_nonnull_domain_snapshot (virDomainPtr domain, remote_nonnull_domain_snapshot snapshot)
{
    return virGetDomainSnapshot(domain, snapshot.name);
}

5509

5510 5511 5512 5513
/* Make remote_nonnull_domain and remote_nonnull_network. */
static void
make_nonnull_domain (remote_nonnull_domain *dom_dst, virDomainPtr dom_src)
{
5514
    dom_dst->id = dom_src->id;
5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525
    dom_dst->name = dom_src->name;
    memcpy (dom_dst->uuid, dom_src->uuid, VIR_UUID_BUFLEN);
}

static void
make_nonnull_network (remote_nonnull_network *net_dst, virNetworkPtr net_src)
{
    net_dst->name = net_src->name;
    memcpy (net_dst->uuid, net_src->uuid, VIR_UUID_BUFLEN);
}

D
Daniel Veillard 已提交
5526 5527 5528 5529 5530 5531 5532 5533
static void
make_nonnull_interface (remote_nonnull_interface *interface_dst,
                        virInterfacePtr interface_src)
{
    interface_dst->name = interface_src->name;
    interface_dst->mac = interface_src->mac;
}

5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548
static void
make_nonnull_storage_pool (remote_nonnull_storage_pool *pool_dst, virStoragePoolPtr pool_src)
{
    pool_dst->name = pool_src->name;
    memcpy (pool_dst->uuid, pool_src->uuid, VIR_UUID_BUFLEN);
}

static void
make_nonnull_storage_vol (remote_nonnull_storage_vol *vol_dst, virStorageVolPtr vol_src)
{
    vol_dst->pool = vol_src->pool;
    vol_dst->name = vol_src->name;
    vol_dst->key = vol_src->key;
}

5549 5550 5551
static void
make_nonnull_secret (remote_nonnull_secret *secret_dst, virSecretPtr secret_src)
{
5552
    memcpy (secret_dst->uuid, secret_src->uuid, VIR_UUID_BUFLEN);
5553 5554
    secret_dst->usageType = secret_src->usageType;
    secret_dst->usageID = secret_src->usageID;
5555 5556
}

5557 5558 5559 5560 5561 5562 5563
static void
make_nonnull_nwfilter (remote_nonnull_nwfilter *nwfilter_dst, virNWFilterPtr nwfilter_src)
{
    nwfilter_dst->name = nwfilter_src->name;
    memcpy (nwfilter_dst->uuid, nwfilter_src->uuid, VIR_UUID_BUFLEN);
}

C
Chris Lalancette 已提交
5564 5565 5566 5567
static void
make_nonnull_domain_snapshot (remote_nonnull_domain_snapshot *snapshot_dst, virDomainSnapshotPtr snapshot_src)
{
    snapshot_dst->name = snapshot_src->name;
5568
    make_nonnull_domain(&snapshot_dst->dom, snapshot_src->domain);
C
Chris Lalancette 已提交
5569 5570
}

5571 5572
/*----------------------------------------------------------------------*/

5573 5574 5575 5576 5577
unsigned long remoteVersion(void)
{
    return REMOTE_PROTOCOL_VERSION;
}

5578
static virDriver remote_driver = {
5579 5580
    .no = VIR_DRV_REMOTE,
    .name = "remote",
5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593
    .open = remoteOpen, /* 0.3.0 */
    .close = remoteClose, /* 0.3.0 */
    .supports_feature = remoteSupportsFeature, /* 0.3.0 */
    .type = remoteType, /* 0.3.0 */
    .version = remoteGetVersion, /* 0.3.0 */
    .libvirtVersion = remoteGetLibVersion, /* 0.7.3 */
    .getHostname = remoteGetHostname, /* 0.3.0 */
    .getSysinfo = remoteGetSysinfo, /* 0.8.8 */
    .getMaxVcpus = remoteGetMaxVcpus, /* 0.3.0 */
    .nodeGetInfo = remoteNodeGetInfo, /* 0.3.0 */
    .getCapabilities = remoteGetCapabilities, /* 0.3.0 */
    .listDomains = remoteListDomains, /* 0.3.0 */
    .numOfDomains = remoteNumOfDomains, /* 0.3.0 */
5594
    .listAllDomains = remoteConnectListAllDomains, /* 0.9.13 */
5595 5596 5597 5598 5599 5600
    .domainCreateXML = remoteDomainCreateXML, /* 0.3.0 */
    .domainLookupByID = remoteDomainLookupByID, /* 0.3.0 */
    .domainLookupByUUID = remoteDomainLookupByUUID, /* 0.3.0 */
    .domainLookupByName = remoteDomainLookupByName, /* 0.3.0 */
    .domainSuspend = remoteDomainSuspend, /* 0.3.0 */
    .domainResume = remoteDomainResume, /* 0.3.0 */
5601
    .domainPMSuspendForDuration = remoteDomainPMSuspendForDuration, /* 0.9.10 */
5602
    .domainPMWakeup = remoteDomainPMWakeup, /* 0.9.11 */
5603
    .domainShutdown = remoteDomainShutdown, /* 0.3.0 */
5604
    .domainShutdownFlags = remoteDomainShutdownFlags, /* 0.9.10 */
5605
    .domainReboot = remoteDomainReboot, /* 0.3.0 */
5606
    .domainReset = remoteDomainReset, /* 0.9.7 */
5607
    .domainDestroy = remoteDomainDestroy, /* 0.3.0 */
5608
    .domainDestroyFlags = remoteDomainDestroyFlags, /* 0.9.4 */
5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619
    .domainGetOSType = remoteDomainGetOSType, /* 0.3.0 */
    .domainGetMaxMemory = remoteDomainGetMaxMemory, /* 0.3.0 */
    .domainSetMaxMemory = remoteDomainSetMaxMemory, /* 0.3.0 */
    .domainSetMemory = remoteDomainSetMemory, /* 0.3.0 */
    .domainSetMemoryFlags = remoteDomainSetMemoryFlags, /* 0.9.0 */
    .domainSetMemoryParameters = remoteDomainSetMemoryParameters, /* 0.8.5 */
    .domainGetMemoryParameters = remoteDomainGetMemoryParameters, /* 0.8.5 */
    .domainSetBlkioParameters = remoteDomainSetBlkioParameters, /* 0.9.0 */
    .domainGetBlkioParameters = remoteDomainGetBlkioParameters, /* 0.9.0 */
    .domainGetInfo = remoteDomainGetInfo, /* 0.3.0 */
    .domainGetState = remoteDomainGetState, /* 0.9.2 */
5620
    .domainGetControlInfo = remoteDomainGetControlInfo, /* 0.9.3 */
5621
    .domainSave = remoteDomainSave, /* 0.3.0 */
E
Eric Blake 已提交
5622
    .domainSaveFlags = remoteDomainSaveFlags, /* 0.9.4 */
5623
    .domainRestore = remoteDomainRestore, /* 0.3.0 */
E
Eric Blake 已提交
5624
    .domainRestoreFlags = remoteDomainRestoreFlags, /* 0.9.4 */
E
Eric Blake 已提交
5625 5626
    .domainSaveImageGetXMLDesc = remoteDomainSaveImageGetXMLDesc, /* 0.9.4 */
    .domainSaveImageDefineXML = remoteDomainSaveImageDefineXML, /* 0.9.4 */
5627 5628 5629 5630 5631 5632
    .domainCoreDump = remoteDomainCoreDump, /* 0.3.0 */
    .domainScreenshot = remoteDomainScreenshot, /* 0.9.2 */
    .domainSetVcpus = remoteDomainSetVcpus, /* 0.3.0 */
    .domainSetVcpusFlags = remoteDomainSetVcpusFlags, /* 0.8.5 */
    .domainGetVcpusFlags = remoteDomainGetVcpusFlags, /* 0.8.5 */
    .domainPinVcpu = remoteDomainPinVcpu, /* 0.3.0 */
5633
    .domainPinVcpuFlags = remoteDomainPinVcpuFlags, /* 0.9.3 */
E
Eric Blake 已提交
5634
    .domainGetVcpuPinInfo = remoteDomainGetVcpuPinInfo, /* 0.9.3 */
5635 5636
    .domainPinEmulator = remoteDomainPinEmulator, /* 0.10.0 */
    .domainGetEmulatorPinInfo = remoteDomainGetEmulatorPinInfo, /* 0.10.0 */
5637 5638 5639
    .domainGetVcpus = remoteDomainGetVcpus, /* 0.3.0 */
    .domainGetMaxVcpus = remoteDomainGetMaxVcpus, /* 0.3.0 */
    .domainGetSecurityLabel = remoteDomainGetSecurityLabel, /* 0.6.1 */
M
Marcelo Cerri 已提交
5640
    .domainGetSecurityLabelList = remoteDomainGetSecurityLabelList, /* 0.10.0 */
5641 5642 5643 5644 5645 5646 5647 5648 5649 5650
    .nodeGetSecurityModel = remoteNodeGetSecurityModel, /* 0.6.1 */
    .domainGetXMLDesc = remoteDomainGetXMLDesc, /* 0.3.0 */
    .domainXMLFromNative = remoteDomainXMLFromNative, /* 0.6.4 */
    .domainXMLToNative = remoteDomainXMLToNative, /* 0.6.4 */
    .listDefinedDomains = remoteListDefinedDomains, /* 0.3.0 */
    .numOfDefinedDomains = remoteNumOfDefinedDomains, /* 0.3.0 */
    .domainCreate = remoteDomainCreate, /* 0.3.0 */
    .domainCreateWithFlags = remoteDomainCreateWithFlags, /* 0.8.2 */
    .domainDefineXML = remoteDomainDefineXML, /* 0.3.0 */
    .domainUndefine = remoteDomainUndefine, /* 0.3.0 */
5651
    .domainUndefineFlags = remoteDomainUndefineFlags, /* 0.9.4 */
5652 5653 5654 5655 5656 5657 5658 5659 5660
    .domainAttachDevice = remoteDomainAttachDevice, /* 0.3.0 */
    .domainAttachDeviceFlags = remoteDomainAttachDeviceFlags, /* 0.7.7 */
    .domainDetachDevice = remoteDomainDetachDevice, /* 0.3.0 */
    .domainDetachDeviceFlags = remoteDomainDetachDeviceFlags, /* 0.7.7 */
    .domainUpdateDeviceFlags = remoteDomainUpdateDeviceFlags, /* 0.8.0 */
    .domainGetAutostart = remoteDomainGetAutostart, /* 0.3.0 */
    .domainSetAutostart = remoteDomainSetAutostart, /* 0.3.0 */
    .domainGetSchedulerType = remoteDomainGetSchedulerType, /* 0.3.0 */
    .domainGetSchedulerParameters = remoteDomainGetSchedulerParameters, /* 0.3.0 */
5661
    .domainGetSchedulerParametersFlags = remoteDomainGetSchedulerParametersFlags, /* 0.9.2 */
5662
    .domainSetSchedulerParameters = remoteDomainSetSchedulerParameters, /* 0.3.0 */
5663
    .domainSetSchedulerParametersFlags = remoteDomainSetSchedulerParametersFlags, /* 0.9.2 */
5664 5665 5666
    .domainMigratePrepare = remoteDomainMigratePrepare, /* 0.3.2 */
    .domainMigratePerform = remoteDomainMigratePerform, /* 0.3.2 */
    .domainMigrateFinish = remoteDomainMigrateFinish, /* 0.3.2 */
5667
    .domainBlockResize = remoteDomainBlockResize, /* 0.9.8 */
5668
    .domainBlockStats = remoteDomainBlockStats, /* 0.3.2 */
5669
    .domainBlockStatsFlags = remoteDomainBlockStatsFlags, /* 0.9.5 */
5670
    .domainInterfaceStats = remoteDomainInterfaceStats, /* 0.3.2 */
5671 5672
    .domainSetInterfaceParameters = remoteDomainSetInterfaceParameters, /* 0.9.9 */
    .domainGetInterfaceParameters = remoteDomainGetInterfaceParameters, /* 0.9.9 */
5673 5674 5675 5676
    .domainMemoryStats = remoteDomainMemoryStats, /* 0.7.5 */
    .domainBlockPeek = remoteDomainBlockPeek, /* 0.4.2 */
    .domainMemoryPeek = remoteDomainMemoryPeek, /* 0.4.2 */
    .domainGetBlockInfo = remoteDomainGetBlockInfo, /* 0.8.1 */
5677
    .nodeGetCPUStats = remoteNodeGetCPUStats, /* 0.9.3 */
5678
    .nodeGetMemoryStats = remoteNodeGetMemoryStats, /* 0.9.3 */
5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699
    .nodeGetCellsFreeMemory = remoteNodeGetCellsFreeMemory, /* 0.3.3 */
    .nodeGetFreeMemory = remoteNodeGetFreeMemory, /* 0.3.3 */
    .domainEventRegister = remoteDomainEventRegister, /* 0.5.0 */
    .domainEventDeregister = remoteDomainEventDeregister, /* 0.5.0 */
    .domainMigratePrepare2 = remoteDomainMigratePrepare2, /* 0.5.0 */
    .domainMigrateFinish2 = remoteDomainMigrateFinish2, /* 0.5.0 */
    .nodeDeviceDettach = remoteNodeDeviceDettach, /* 0.6.1 */
    .nodeDeviceReAttach = remoteNodeDeviceReAttach, /* 0.6.1 */
    .nodeDeviceReset = remoteNodeDeviceReset, /* 0.6.1 */
    .domainMigratePrepareTunnel = remoteDomainMigratePrepareTunnel, /* 0.7.2 */
    .isEncrypted = remoteIsEncrypted, /* 0.7.3 */
    .isSecure = remoteIsSecure, /* 0.7.3 */
    .domainIsActive = remoteDomainIsActive, /* 0.7.3 */
    .domainIsPersistent = remoteDomainIsPersistent, /* 0.7.3 */
    .domainIsUpdated = remoteDomainIsUpdated, /* 0.8.6 */
    .cpuCompare = remoteCPUCompare, /* 0.7.5 */
    .cpuBaseline = remoteCPUBaseline, /* 0.7.7 */
    .domainGetJobInfo = remoteDomainGetJobInfo, /* 0.7.7 */
    .domainAbortJob = remoteDomainAbortJob, /* 0.7.7 */
    .domainMigrateSetMaxDowntime = remoteDomainMigrateSetMaxDowntime, /* 0.8.0 */
    .domainMigrateSetMaxSpeed = remoteDomainMigrateSetMaxSpeed, /* 0.9.0 */
5700
    .domainMigrateGetMaxSpeed = remoteDomainMigrateGetMaxSpeed, /* 0.9.5 */
5701 5702 5703 5704 5705 5706 5707 5708 5709
    .domainEventRegisterAny = remoteDomainEventRegisterAny, /* 0.8.0 */
    .domainEventDeregisterAny = remoteDomainEventDeregisterAny, /* 0.8.0 */
    .domainManagedSave = remoteDomainManagedSave, /* 0.8.0 */
    .domainHasManagedSaveImage = remoteDomainHasManagedSaveImage, /* 0.8.0 */
    .domainManagedSaveRemove = remoteDomainManagedSaveRemove, /* 0.8.0 */
    .domainSnapshotCreateXML = remoteDomainSnapshotCreateXML, /* 0.8.0 */
    .domainSnapshotGetXMLDesc = remoteDomainSnapshotGetXMLDesc, /* 0.8.0 */
    .domainSnapshotNum = remoteDomainSnapshotNum, /* 0.8.0 */
    .domainSnapshotListNames = remoteDomainSnapshotListNames, /* 0.8.0 */
5710
    .domainListAllSnapshots = remoteDomainListAllSnapshots, /* 0.9.13 */
5711
    .domainSnapshotNumChildren = remoteDomainSnapshotNumChildren, /* 0.9.7 */
5712
    .domainSnapshotListAllChildren = remoteDomainSnapshotListAllChildren, /* 0.9.13 */
5713
    .domainSnapshotListChildrenNames = remoteDomainSnapshotListChildrenNames, /* 0.9.7 */
5714 5715
    .domainSnapshotLookupByName = remoteDomainSnapshotLookupByName, /* 0.8.0 */
    .domainHasCurrentSnapshot = remoteDomainHasCurrentSnapshot, /* 0.8.0 */
5716
    .domainSnapshotGetParent = remoteDomainSnapshotGetParent, /* 0.9.7 */
5717 5718
    .domainSnapshotCurrent = remoteDomainSnapshotCurrent, /* 0.8.0 */
    .domainRevertToSnapshot = remoteDomainRevertToSnapshot, /* 0.8.0 */
E
Eric Blake 已提交
5719 5720
    .domainSnapshotIsCurrent = remoteDomainSnapshotIsCurrent, /* 0.9.13 */
    .domainSnapshotHasMetadata = remoteDomainSnapshotHasMetadata, /* 0.9.13 */
5721 5722
    .domainSnapshotDelete = remoteDomainSnapshotDelete, /* 0.8.0 */
    .qemuDomainMonitorCommand = remoteQemuDomainMonitorCommand, /* 0.8.3 */
5723
    .qemuDomainAttach = qemuDomainAttach, /* 0.9.4 */
E
Eric Blake 已提交
5724
    .qemuDomainArbitraryAgentCommand = qemuDomainAgentCommand, /* 0.10.0 */
5725
    .domainOpenConsole = remoteDomainOpenConsole, /* 0.8.6 */
5726
    .domainOpenGraphics = remoteDomainOpenGraphics, /* 0.9.7 */
5727
    .domainInjectNMI = remoteDomainInjectNMI, /* 0.9.2 */
5728 5729 5730 5731 5732 5733
    .domainMigrateBegin3 = remoteDomainMigrateBegin3, /* 0.9.2 */
    .domainMigratePrepare3 = remoteDomainMigratePrepare3, /* 0.9.2 */
    .domainMigratePrepareTunnel3 = remoteDomainMigratePrepareTunnel3, /* 0.9.2 */
    .domainMigratePerform3 = remoteDomainMigratePerform3, /* 0.9.2 */
    .domainMigrateFinish3 = remoteDomainMigrateFinish3, /* 0.9.2 */
    .domainMigrateConfirm3 = remoteDomainMigrateConfirm3, /* 0.9.2 */
5734
    .domainSendKey = remoteDomainSendKey, /* 0.9.3 */
5735 5736 5737 5738
    .domainBlockJobAbort = remoteDomainBlockJobAbort, /* 0.9.4 */
    .domainGetBlockJobInfo = remoteDomainGetBlockJobInfo, /* 0.9.4 */
    .domainBlockJobSetSpeed = remoteDomainBlockJobSetSpeed, /* 0.9.4 */
    .domainBlockPull = remoteDomainBlockPull, /* 0.9.4 */
5739
    .domainBlockRebase = remoteDomainBlockRebase, /* 0.9.10 */
5740 5741
    .setKeepAlive = remoteSetKeepAlive, /* 0.9.8 */
    .isAlive = remoteIsAlive, /* 0.9.8 */
5742
    .nodeSuspendForDuration = remoteNodeSuspendForDuration, /* 0.9.8 */
5743 5744
    .domainSetBlockIoTune = remoteDomainSetBlockIoTune, /* 0.9.8 */
    .domainGetBlockIoTune = remoteDomainGetBlockIoTune, /* 0.9.8 */
5745 5746
    .domainSetNumaParameters = remoteDomainSetNumaParameters, /* 0.9.9 */
    .domainGetNumaParameters = remoteDomainGetNumaParameters, /* 0.9.9 */
5747
    .domainGetCPUStats = remoteDomainGetCPUStats, /* 0.9.10 */
5748
    .domainGetDiskErrors = remoteDomainGetDiskErrors, /* 0.9.10 */
5749 5750
    .domainSetMetadata = remoteDomainSetMetadata, /* 0.9.10 */
    .domainGetMetadata = remoteDomainGetMetadata, /* 0.9.10 */
5751
    .domainGetHostname = remoteDomainGetHostname, /* 0.10.0 */
5752 5753 5754
};

static virNetworkDriver network_driver = {
5755
    .name = "remote",
5756 5757 5758 5759 5760 5761
    .open = remoteNetworkOpen, /* 0.3.0 */
    .close = remoteNetworkClose, /* 0.3.0 */
    .numOfNetworks = remoteNumOfNetworks, /* 0.3.0 */
    .listNetworks = remoteListNetworks, /* 0.3.0 */
    .numOfDefinedNetworks = remoteNumOfDefinedNetworks, /* 0.3.0 */
    .listDefinedNetworks = remoteListDefinedNetworks, /* 0.3.0 */
5762
    .listAllNetworks = remoteConnectListAllNetworks, /* 0.10.2 */
5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775
    .networkLookupByUUID = remoteNetworkLookupByUUID, /* 0.3.0 */
    .networkLookupByName = remoteNetworkLookupByName, /* 0.3.0 */
    .networkCreateXML = remoteNetworkCreateXML, /* 0.3.0 */
    .networkDefineXML = remoteNetworkDefineXML, /* 0.3.0 */
    .networkUndefine = remoteNetworkUndefine, /* 0.3.0 */
    .networkCreate = remoteNetworkCreate, /* 0.3.0 */
    .networkDestroy = remoteNetworkDestroy, /* 0.3.0 */
    .networkGetXMLDesc = remoteNetworkGetXMLDesc, /* 0.3.0 */
    .networkGetBridgeName = remoteNetworkGetBridgeName, /* 0.3.0 */
    .networkGetAutostart = remoteNetworkGetAutostart, /* 0.3.0 */
    .networkSetAutostart = remoteNetworkSetAutostart, /* 0.3.0 */
    .networkIsActive = remoteNetworkIsActive, /* 0.7.3 */
    .networkIsPersistent = remoteNetworkIsPersistent, /* 0.7.3 */
5776 5777
};

D
Daniel Veillard 已提交
5778 5779
static virInterfaceDriver interface_driver = {
    .name = "remote",
5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793
    .open = remoteInterfaceOpen, /* 0.7.2 */
    .close = remoteInterfaceClose, /* 0.7.2 */
    .numOfInterfaces = remoteNumOfInterfaces, /* 0.7.2 */
    .listInterfaces = remoteListInterfaces, /* 0.7.2 */
    .numOfDefinedInterfaces = remoteNumOfDefinedInterfaces, /* 0.7.2 */
    .listDefinedInterfaces = remoteListDefinedInterfaces, /* 0.7.2 */
    .interfaceLookupByName = remoteInterfaceLookupByName, /* 0.7.2 */
    .interfaceLookupByMACString = remoteInterfaceLookupByMACString, /* 0.7.2 */
    .interfaceGetXMLDesc = remoteInterfaceGetXMLDesc, /* 0.7.2 */
    .interfaceDefineXML = remoteInterfaceDefineXML, /* 0.7.2 */
    .interfaceUndefine = remoteInterfaceUndefine, /* 0.7.2 */
    .interfaceCreate = remoteInterfaceCreate, /* 0.7.2 */
    .interfaceDestroy = remoteInterfaceDestroy, /* 0.7.2 */
    .interfaceIsActive = remoteInterfaceIsActive, /* 0.7.3 */
5794 5795 5796
    .interfaceChangeBegin = remoteInterfaceChangeBegin, /* 0.9.2 */
    .interfaceChangeCommit = remoteInterfaceChangeCommit, /* 0.9.2 */
    .interfaceChangeRollback = remoteInterfaceChangeRollback, /* 0.9.2 */
D
Daniel Veillard 已提交
5797 5798
};

5799 5800
static virStorageDriver storage_driver = {
    .name = "remote",
5801 5802 5803 5804 5805 5806
    .open = remoteStorageOpen, /* 0.4.1 */
    .close = remoteStorageClose, /* 0.4.1 */
    .numOfPools = remoteNumOfStoragePools, /* 0.4.1 */
    .listPools = remoteListStoragePools, /* 0.4.1 */
    .numOfDefinedPools = remoteNumOfDefinedStoragePools, /* 0.4.1 */
    .listDefinedPools = remoteListDefinedStoragePools, /* 0.4.1 */
5807
    .listAllPools = remoteConnectListAllStoragePools, /* 0.10.2 */
5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825
    .findPoolSources = remoteFindStoragePoolSources, /* 0.4.5 */
    .poolLookupByName = remoteStoragePoolLookupByName, /* 0.4.1 */
    .poolLookupByUUID = remoteStoragePoolLookupByUUID, /* 0.4.1 */
    .poolLookupByVolume = remoteStoragePoolLookupByVolume, /* 0.4.1 */
    .poolCreateXML = remoteStoragePoolCreateXML, /* 0.4.1 */
    .poolDefineXML = remoteStoragePoolDefineXML, /* 0.4.1 */
    .poolBuild = remoteStoragePoolBuild, /* 0.4.1 */
    .poolUndefine = remoteStoragePoolUndefine, /* 0.4.1 */
    .poolCreate = remoteStoragePoolCreate, /* 0.4.1 */
    .poolDestroy = remoteStoragePoolDestroy, /* 0.4.1 */
    .poolDelete = remoteStoragePoolDelete, /* 0.4.1 */
    .poolRefresh = remoteStoragePoolRefresh, /* 0.4.1 */
    .poolGetInfo = remoteStoragePoolGetInfo, /* 0.4.1 */
    .poolGetXMLDesc = remoteStoragePoolGetXMLDesc, /* 0.4.1 */
    .poolGetAutostart = remoteStoragePoolGetAutostart, /* 0.4.1 */
    .poolSetAutostart = remoteStoragePoolSetAutostart, /* 0.4.1 */
    .poolNumOfVolumes = remoteStoragePoolNumOfVolumes, /* 0.4.1 */
    .poolListVolumes = remoteStoragePoolListVolumes, /* 0.4.1 */
5826
    .poolListAllVolumes = remoteStoragePoolListAllVolumes, /* 0.10.0 */
5827 5828 5829 5830 5831 5832 5833 5834 5835 5836

    .volLookupByName = remoteStorageVolLookupByName, /* 0.4.1 */
    .volLookupByKey = remoteStorageVolLookupByKey, /* 0.4.1 */
    .volLookupByPath = remoteStorageVolLookupByPath, /* 0.4.1 */
    .volCreateXML = remoteStorageVolCreateXML, /* 0.4.1 */
    .volCreateXMLFrom = remoteStorageVolCreateXMLFrom, /* 0.6.4 */
    .volDownload = remoteStorageVolDownload, /* 0.9.0 */
    .volUpload = remoteStorageVolUpload, /* 0.9.0 */
    .volDelete = remoteStorageVolDelete, /* 0.4.1 */
    .volWipe = remoteStorageVolWipe, /* 0.8.0 */
5837
    .volWipePattern = remoteStorageVolWipePattern, /* 0.9.10 */
5838 5839 5840
    .volGetInfo = remoteStorageVolGetInfo, /* 0.4.1 */
    .volGetXMLDesc = remoteStorageVolGetXMLDesc, /* 0.4.1 */
    .volGetPath = remoteStorageVolGetPath, /* 0.4.1 */
5841
    .volResize = remoteStorageVolResize, /* 0.9.10 */
5842 5843
    .poolIsActive = remoteStoragePoolIsActive, /* 0.7.3 */
    .poolIsPersistent = remoteStoragePoolIsPersistent, /* 0.7.3 */
5844 5845
};

5846 5847
static virSecretDriver secret_driver = {
    .name = "remote",
5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858
    .open = remoteSecretOpen, /* 0.7.1 */
    .close = remoteSecretClose, /* 0.7.1 */
    .numOfSecrets = remoteNumOfSecrets, /* 0.7.1 */
    .listSecrets = remoteListSecrets, /* 0.7.1 */
    .lookupByUUID = remoteSecretLookupByUUID, /* 0.7.1 */
    .lookupByUsage = remoteSecretLookupByUsage, /* 0.7.1 */
    .defineXML = remoteSecretDefineXML, /* 0.7.1 */
    .getXMLDesc = remoteSecretGetXMLDesc, /* 0.7.1 */
    .setValue = remoteSecretSetValue, /* 0.7.1 */
    .getValue = remoteSecretGetValue, /* 0.7.1 */
    .undefine = remoteSecretUndefine /* 0.7.1 */
5859 5860
};

5861 5862
static virDeviceMonitor dev_monitor = {
    .name = "remote",
5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873
    .open = remoteDevMonOpen, /* 0.5.0 */
    .close = remoteDevMonClose, /* 0.5.0 */
    .numOfDevices = remoteNodeNumOfDevices, /* 0.5.0 */
    .listDevices = remoteNodeListDevices, /* 0.5.0 */
    .deviceLookupByName = remoteNodeDeviceLookupByName, /* 0.5.0 */
    .deviceGetXMLDesc = remoteNodeDeviceGetXMLDesc, /* 0.5.0 */
    .deviceGetParent = remoteNodeDeviceGetParent, /* 0.5.0 */
    .deviceNumOfCaps = remoteNodeDeviceNumOfCaps, /* 0.5.0 */
    .deviceListCaps = remoteNodeDeviceListCaps, /* 0.5.0 */
    .deviceCreateXML = remoteNodeDeviceCreateXML, /* 0.6.3 */
    .deviceDestroy = remoteNodeDeviceDestroy /* 0.6.3 */
5874 5875
};

5876 5877
static virNWFilterDriver nwfilter_driver = {
    .name = "remote",
5878 5879 5880 5881 5882 5883 5884 5885 5886
    .open = remoteNWFilterOpen, /* 0.8.0 */
    .close = remoteNWFilterClose, /* 0.8.0 */
    .nwfilterLookupByUUID = remoteNWFilterLookupByUUID, /* 0.8.0 */
    .nwfilterLookupByName = remoteNWFilterLookupByName, /* 0.8.0 */
    .getXMLDesc           = remoteNWFilterGetXMLDesc, /* 0.8.0 */
    .defineXML            = remoteNWFilterDefineXML, /* 0.8.0 */
    .undefine             = remoteNWFilterUndefine, /* 0.8.0 */
    .numOfNWFilters       = remoteNumOfNWFilters, /* 0.8.0 */
    .listNWFilters        = remoteListNWFilters, /* 0.8.0 */
5887 5888
};

5889

A
Atsushi SAKAI 已提交
5890
#ifdef WITH_LIBVIRTD
5891
static virStateDriver state_driver = {
5892
    .name = "Remote",
5893
    .initialize = remoteStartup,
5894
};
A
Atsushi SAKAI 已提交
5895
#endif
5896 5897


5898
/** remoteRegister:
5899 5900
 *
 * Register driver with libvirt driver system.
5901 5902
 *
 * Returns -1 on error.
5903 5904 5905 5906
 */
int
remoteRegister (void)
{
5907 5908
    remoteDriver = &remote_driver;

5909
    if (virRegisterDriver (&remote_driver) == -1) return -1;
5910
    if (virRegisterNetworkDriver (&network_driver) == -1) return -1;
D
Daniel Veillard 已提交
5911
    if (virRegisterInterfaceDriver (&interface_driver) == -1) return -1;
5912
    if (virRegisterStorageDriver (&storage_driver) == -1) return -1;
5913
    if (virRegisterDeviceMonitor (&dev_monitor) == -1) return -1;
5914
    if (virRegisterSecretDriver (&secret_driver) == -1) return -1;
5915
    if (virRegisterNWFilterDriver(&nwfilter_driver) == -1) return -1;
A
Atsushi SAKAI 已提交
5916
#ifdef WITH_LIBVIRTD
5917
    if (virRegisterStateDriver (&state_driver) == -1) return -1;
A
Atsushi SAKAI 已提交
5918
#endif
5919 5920 5921

    return 0;
}