proxy_internal.c 20.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * proxy_client.c: client side of the communication with the libvirt proxy.
 *
 * Copyright (C) 2006 Red Hat, Inc.
 *
 * See COPYING.LIB for the License of this software
 *
 * Daniel Veillard <veillard@redhat.com>
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/poll.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/wait.h>
#include "internal.h"
22 23
#include "driver.h"
#include "proxy_internal.h"
24 25 26

#define STANDALONE

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
static int debug = 0;

static int xenProxyClose(virConnectPtr conn);
static int xenProxyOpen(virConnectPtr conn, const char *name, int flags);
static int xenProxyGetVersion(virConnectPtr conn, unsigned long *hvVer);
static int xenProxyNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info);
static int xenProxyListDomains(virConnectPtr conn, int *ids, int maxids);
static int xenProxyNumOfDomains(virConnectPtr conn);
static virDomainPtr xenProxyLookupByID(virConnectPtr conn, int id);
static virDomainPtr xenProxyLookupByUUID(virConnectPtr conn,
					 const unsigned char *uuid);
static virDomainPtr xenProxyDomainLookupByName(virConnectPtr conn,
					       const char *domname);
static unsigned long xenProxyDomainGetMaxMemory(virDomainPtr domain);
static int xenProxyDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info);

static virDriver xenProxyDriver = {
    VIR_DRV_XEN_PROXY,
    "XenProxy",
    0,
    NULL, /* init */
    xenProxyOpen, /* open */
    xenProxyClose, /* close */
    NULL, /* type */
    xenProxyGetVersion, /* version */
    NULL, /* nodeGetInfo */
    xenProxyListDomains, /* listDomains */
    xenProxyNumOfDomains, /* numOfDomains */
    NULL, /* domainCreateLinux */
    xenProxyLookupByID, /* domainLookupByID */
    xenProxyLookupByUUID, /* domainLookupByUUID */
    xenProxyDomainLookupByName, /* domainLookupByName */
    NULL, /* domainSuspend */
    NULL, /* domainResume */
    NULL, /* domainShutdown */
    NULL, /* domainReboot */
    NULL, /* domainDestroy */
    NULL, /* domainFree */
    NULL, /* domainGetName */
    NULL, /* domainGetID */
    NULL, /* domainGetUUID */
    NULL, /* domainGetOSType */
    xenProxyDomainGetMaxMemory, /* domainGetMaxMemory */
    NULL, /* domainSetMaxMemory */
    NULL, /* domainSetMemory */
    xenProxyDomainGetInfo, /* domainGetInfo */
    NULL, /* domainSave */
    NULL /* domainRestore */
};
76

77 78 79 80 81 82 83 84 85
/**
 * xenProxyRegister:
 *
 * Registers the xenHypervisor driver
 */
void xenProxyRegister(void)
{
    virRegisterDriver(&xenProxyDriver);
}
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
/************************************************************************
 *									*
 *			Error handling					*
 *									*
 ************************************************************************/

/**
 * virProxyError:
 * @conn: the connection if available
 * @error: the error noumber
 * @info: extra information string
 *
 * Handle an error at the xend daemon interface
 */
static void
virProxyError(virConnectPtr conn, virErrorNumber error, const char *info)
{
103 104
    const char *errmsg;

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
    if (error == VIR_ERR_OK)
        return;

    errmsg = __virErrorMsg(error, info);
    __virRaiseError(conn, NULL, VIR_FROM_XEND, error, VIR_ERR_ERROR,
                    errmsg, info, NULL, 0, 0, errmsg, info);
}

/************************************************************************
 *									*
 *	Automatic startup of the proxy server if it is not running	*
 *									*
 ************************************************************************/
/**
 * virProxyFindServerPath:
 *
 * Tries to find the path to the gam_server binary.
 * 
 * Returns path on success or NULL in case of error.
 */
static const char *
virProxyFindServerPath(void)
{
    static const char *serverPaths[] = {
        BINDIR "/libvirt_proxy",
130
        "/usr/bin/libvirt_proxy_dbg",
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 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 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 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 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
        NULL
    };
    int i;
    const char *debugProxy = getenv("LIBVIRT_DEBUG_PROXY");

    if (debugProxy)
        return(debugProxy);

    for (i = 0; serverPaths[i]; i++) {
        if (access(serverPaths[i], X_OK | R_OK) == 0) {
            return serverPaths[i];
        }
    }
    return NULL;
}

/**
 * virProxyForkServer:
 *
 * Forks and try to launch the proxy server processing the requests for
 * libvirt when communicating with Xen.
 *
 * Returns 0 in case of success or -1 in case of detected error.
 */
static int
virProxyForkServer(void)
{
    const char *proxyPath = virProxyFindServerPath();
    int ret, pid, status;

    if (!proxyPath) {
        fprintf(stderr, "failed to find libvirt_proxy\n");
	return(-1);
    }

    if (debug)
        fprintf(stderr, "Asking to launch %s\n", proxyPath);

    /* Become a daemon */
    pid = fork();
    if (pid == 0) {
        long open_max;
	long i;

        /* don't hold open fd opened from the client of the library */
	open_max = sysconf (_SC_OPEN_MAX);
	for (i = 0; i < open_max; i++)
	    fcntl (i, F_SETFD, FD_CLOEXEC);

        setsid();
        if (fork() == 0) {
            execl(proxyPath, proxyPath, NULL);
            fprintf(stderr, "failed to exec %s\n", proxyPath);
        }
        /*
         * calling exit() generate troubles for termination handlers
         */
        _exit(0);
    }

    /*
     * do a waitpid on the intermediate process to avoid zombies.
     */
retry_wait:
    ret = waitpid(pid, &status, 0);
    if (ret < 0) {
        if (errno == EINTR)
            goto retry_wait;
    }

    return (0);
}

/************************************************************************
 *									*
 *		Processing of client sockets				*
 *									*
 ************************************************************************/

/**
 * virProxyOpenClientSocket:
 * @path: the fileame for the socket
 *
 * try to connect to the socket open by libvirt_proxy
 *
 * Returns the associated file descriptor or -1 in case of failure
 */
static int
virProxyOpenClientSocket(const char *path) {
    int fd;
    struct sockaddr_un addr;
    int trials = 0;

retry:
    fd = socket(PF_UNIX, SOCK_STREAM, 0);
    if (fd < 0) {
	return(-1);
    }

    /*
     * Abstract socket do not hit the filesystem, way more secure and 
     * garanteed to be atomic
     */
    memset(&addr, 0, sizeof(addr));
    addr.sun_family = AF_UNIX;
    addr.sun_path[0] = '\0';
    strncpy(&addr.sun_path[1], path, (sizeof(addr) - 4) - 2);

    /*
     * now bind the socket to that address and listen on it
     */
    if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
	close(fd);
	if (trials < 3) {
	    if (virProxyForkServer() < 0)
	        return(-1);
	    trials++;
	    usleep(5000 * trials * trials);
	    goto retry;
	}
	return (-1);
    }

    if (debug > 0)
        fprintf(stderr, "connected to unix socket %s via %d\n", path, fd);

    return (fd);
}

/**
 * virProxyCloseClientSocket:
 * @fd: the file descriptor for the socket
 *
 * Close the socket from that client
 *
 * Returns 0 in case of success and -1 in case of error
 */
static int
virProxyCloseClientSocket(int fd) {
    int ret;

    if (fd < 0)
        return(-1);

    ret = close(fd);
    if (ret != 0)
	fprintf(stderr, "Failed to close socket %d\n", fd);
    else if (debug > 0)
	fprintf(stderr, "Closed socket %d\n", fd);
    return(ret);
}

/**
 * virProxyReadClientSocket:
 * @fd: the socket 
 * @buffer: the target memory area
 * @len: the lenght in bytes
 *
 * Process a read from a client socket
 *
 * Returns the number of byte read or -1 in case of error.
 */
static int
virProxyReadClientSocket(int fd, char *buffer, int len) {
    int ret;

    if ((fd < 0) || (buffer == NULL) || (len < 0))
        return(-1);

retry:
    ret = read(fd, buffer, len);
    if (ret < 0) {
        if (errno == EINTR) {
	    if (debug > 0)
	        fprintf(stderr, "read socket %d interrupted\n", fd);
	    goto retry;
	}
        fprintf(stderr, "Failed to read socket %d\n", fd);
	return(-1);
    }

    if (debug)
	fprintf(stderr, "read %d bytes from socket %d\n",
		ret, fd);
    return(ret);
}

/**
 * virProxyWriteClientSocket:
 * @fd: the socket 
 * @data: the data
 * @len: the lenght of data in bytes
 *
 * Process a read from a client socket
 */
static int
virProxyWriteClientSocket(int fd, const char *data, int len) {
    int ret;

    if ((fd < 0) || (data == NULL) || (len < 0))
        return(-1);

retry:
    ret = write(fd, data, len);
    if (ret < 0) {
        if (errno == EINTR) {
	    if (debug > 0)
	        fprintf(stderr, "write socket %d, %d bytes interrupted\n",
		        fd, len);
	    goto retry;
	}
        fprintf(stderr, "Failed to write to socket %d\n", fd);
	return(-1);
    }
    if (debug)
	fprintf(stderr, "wrote %d bytes to socket %d\n",
		len, fd);

    return(0);
}

/************************************************************************
 *									*
 *			Proxy commands processing			*
 *									*
 ************************************************************************/

/**
 * xenProxyClose:
 * @conn: pointer to the hypervisor connection
 *
 * Shutdown the Xen proxy communication layer
 */
364
static int
365 366
xenProxyClose(virConnectPtr conn) {
    if ((conn == NULL) || (conn->proxy < 0))
367
        return(-1);
368 369
    virProxyCloseClientSocket(conn->proxy);
    conn->proxy = -1;
370
    return (0);
371 372 373 374
}

static int 
xenProxyCommand(virConnectPtr conn, virProxyPacketPtr request,
375
                virProxyFullPacketPtr answer) {
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
    static int serial = 0;
    int ret;
    virProxyPacketPtr res = NULL;

    if ((conn == NULL) || (conn->proxy < 0))
        return(-1);

    /*
     * normal communication serial numbers are in 0..4095
     */
    ++serial;
    if (serial >= 4096)
        serial = 0;
    request->version = PROXY_PROTO_VERSION;
    request->serial = serial;
    ret  = virProxyWriteClientSocket(conn->proxy, (const char *) request,
                                     request->len);
    if (ret < 0)
        return(-1);
retry:
    if (answer == NULL) {
        /* read in situ */
	ret  = virProxyReadClientSocket(conn->proxy, (char *) request,
	                                sizeof(virProxyPacket));
	if (ret < 0)
	    return(-1);
	if (ret != sizeof(virProxyPacket)) {
	    fprintf(stderr,
		"Communication error with proxy: got %d bytes of %d\n",
		    ret, sizeof(virProxyPacket));
	    xenProxyClose(conn);
	    return(-1);
	}
	res = request;
	if (res->len != sizeof(virProxyPacket)) {
	    fprintf(stderr,
		"Communication error with proxy: expected %d bytes got %d\n",
		    sizeof(virProxyPacket), res->len);
	    xenProxyClose(conn);
	    return(-1);
	}
    } else {
418 419
        /* read in packet provided */
        ret  = virProxyReadClientSocket(conn->proxy, (char *) answer,
420 421 422 423 424 425 426 427 428 429
	                                sizeof(virProxyPacket));
	if (ret < 0)
	    return(-1);
	if (ret != sizeof(virProxyPacket)) {
	    fprintf(stderr,
		"Communication error with proxy: got %d bytes of %d\n",
		    ret, sizeof(virProxyPacket));
	    xenProxyClose(conn);
	    return(-1);
	}
430
	res = (virProxyPacketPtr) answer;
431
	if ((res->len < sizeof(virProxyPacket)) ||
432
	    (res->len > sizeof(virProxyFullPacket))) {
433 434 435 436 437 438 439
	    fprintf(stderr,
		"Communication error with proxy: got %d bytes packet\n",
		    res->len);
	    xenProxyClose(conn);
	    return(-1);
	}
	if (res->len > sizeof(virProxyPacket)) {
440
	    ret  = virProxyReadClientSocket(conn->proxy,
441
	                           (char *) &(answer->extra.arg[0]),
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
	                                    res->len - ret);
	    if (ret != (int) (res->len - sizeof(virProxyPacket))) {
		fprintf(stderr,
		    "Communication error with proxy: got %d bytes of %d\n",
			ret, sizeof(virProxyPacket));
		xenProxyClose(conn);
		return(-1);
	    }
	}
    }
    /*
     * do more checks on the incoming packet.
     */
    if ((res == NULL) || (res->version != PROXY_PROTO_VERSION) ||
        (res->len < sizeof(virProxyPacket))) {
	fprintf(stderr,
	    "Communication error with proxy: malformed packet\n");
	xenProxyClose(conn);
	return(-1);
    }
    if (res->serial != serial) {
        TODO /* Asynchronous communication */
	fprintf(stderr, "gor asynchronous packet number %d\n", res->serial);
        goto retry;
    }
    return(0);
}

/**
 * xenProxyInit:
 * @conn: pointer to the hypervisor connection
473 474
 * @name: URL for the target, NULL for local
 * @flags: combination of virDrvOpenFlag(s)
475 476
 *
 * Try to initialize the Xen proxy communication layer
477
 * This can be opened only for a read-only kind of access
478 479 480 481
 *
 * Returns 0 in case of success, and -1 in case of failure
 */
int
482 483
xenProxyOpen(virConnectPtr conn, const char *name, int flags)
{
484 485 486
    virProxyPacket req;
    int ret;
    int fd;
487 488 489 490 491
    
    if ((name != NULL) && (strcasecmp(name, "xen")))
        return(-1);
    if (!(flags & VIR_DRV_OPEN_RO))
        return(-1);
492
        
493 494 495 496 497 498
    conn->proxy = -1;
    fd = virProxyOpenClientSocket(PROXY_SOCKET_PATH);
    if (fd < 0) {
        if (!(flags & VIR_DRV_OPEN_QUIET))
	    virProxyError(conn, VIR_ERR_NO_XEN, PROXY_SOCKET_PATH);
	return(-1);
499
    }
500
    conn->proxy = fd;
501 502 503 504 505 506

    memset(&req, 0, sizeof(req));
    req.command = VIR_PROXY_NONE;
    req.len = sizeof(req);
    ret = xenProxyCommand(conn, &req, NULL);
    if ((ret < 0) || (req.command != VIR_PROXY_NONE)) {
507
        virProxyError(conn, VIR_ERR_OPERATION_FAILED, __FUNCTION__);
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
        xenProxyClose(conn);
	return(-1);
    }
    return(0);
}

/************************************************************************
 *									*
 *			Driver entry points				*
 *									*
 ************************************************************************/

/**
 * xenProxyGetVersion:
 * @conn: pointer to the Xen Daemon block
 * @hvVer: return value for the version of the running hypervisor (OUT)
 *
 * Get the version level of the Hypervisor running.
 *
 * Returns -1 in case of error, 0 otherwise. if the version can't be
 *    extracted by lack of capacities returns 0 and @hvVer is 0, otherwise
 *    @hvVer value is major * 1,000,000 + minor * 1,000 + release
 */
static int
xenProxyGetVersion(virConnectPtr conn, unsigned long *hvVer)
{
    virProxyPacket req;
    int ret;

    if (!VIR_IS_CONNECT(conn)) {
        virProxyError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
        return (-1);
    }
    if (hvVer == NULL) {
        virProxyError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
	return (-1);
    }
    memset(&req, 0, sizeof(req));
    req.command = VIR_PROXY_VERSION;
    req.len = sizeof(req);
    ret = xenProxyCommand(conn, &req, NULL);
    if (ret < 0) {
        xenProxyClose(conn);
	return(-1);
    }
    *hvVer = req.data.larg;
    return(0);
}

/**
 * xenProxyListDomains:
 * @conn: pointer to the hypervisor connection
 * @ids: array to collect the list of IDs of active domains
 * @maxids: size of @ids
 *
 * Collect the list of active domains, and store their ID in @maxids
 *
 * Returns the number of domain found or -1 in case of error
 */
static int
xenProxyListDomains(virConnectPtr conn, int *ids, int maxids)
{
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
    virProxyPacket req;
    virProxyFullPacket ans;
    int ret;
    int nb;

    if (!VIR_IS_CONNECT(conn)) {
        virProxyError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
        return (-1);
    }
    if ((ids == NULL) || (maxids <= 0)) {
        virProxyError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
	return (-1);
    }
    memset(&req, 0, sizeof(req));
    req.command = VIR_PROXY_LIST;
    req.len = sizeof(req);
    ret = xenProxyCommand(conn, &req, &ans);
    if (ret < 0) {
        xenProxyClose(conn);
	return(-1);
    }
    nb = ans.data.arg;
592 593 594 595
    if ((nb > 1020) || (nb <= 0) ||
        (ans.len <= sizeof(virProxyPacket)) ||
	(ans.len > sizeof(virProxyFullPacket))) {
        virProxyError(conn, VIR_ERR_OPERATION_FAILED, __FUNCTION__);
596
        return(-1);
597
    }
598 599 600 601 602
    if (nb > maxids)
        nb = maxids;
    memmove(ids, &ans.extra.arg[0], nb * sizeof(int));

    return(nb);
603 604 605 606 607 608 609 610 611 612 613 614 615
}

/**
 * xenProxyNumOfDomains:
 * @conn: pointer to the hypervisor connection
 *
 * Provides the number of active domains.
 *
 * Returns the number of domain found or -1 in case of error
 */
static int
xenProxyNumOfDomains(virConnectPtr conn)
{
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631
    virProxyPacket req;
    int ret;

    if (!VIR_IS_CONNECT(conn)) {
        virProxyError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
        return (-1);
    }
    memset(&req, 0, sizeof(req));
    req.command = VIR_PROXY_NUM_DOMAIN;
    req.len = sizeof(req);
    ret = xenProxyCommand(conn, &req, NULL);
    if (ret < 0) {
        xenProxyClose(conn);
	return(-1);
    }
    return(req.data.arg);
632 633
}

634

635
/**
636
 * xenProxyDomainGetDomMaxMemory:
637 638 639
 * @conn: pointer to the hypervisor connection
 * @id: the domain ID number
 *
640
 * Ask the Xen Daemon for the maximum memory allowed for a domain
641
 *
642
 * Returns the memory size in kilobytes or 0 in case of error.
643
 */
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
static unsigned long
xenProxyDomainGetDomMaxMemory(virConnectPtr conn, int id)
{
    virProxyPacket req;
    int ret;

    if (!VIR_IS_CONNECT(conn)) {
        virProxyError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
        return (-1);
    }
    memset(&req, 0, sizeof(req));
    req.command = VIR_PROXY_MAX_MEMORY;
    req.data.arg = id;
    req.len = sizeof(req);
    ret = xenProxyCommand(conn, &req, NULL);
    if (ret < 0) {
        xenProxyClose(conn);
	return(-1);
    }
    return(req.data.larg);
664 665 666
}

/**
667 668
 * xenProxyDomainGetMaxMemory:
 * @domain: pointer to the domain block
669
 *
670
 * Ask the Xen Daemon for the maximum memory allowed for a domain
671
 *
672
 * Returns the memory size in kilobytes or 0 in case of error.
673
 */
674 675
static unsigned long
xenProxyDomainGetMaxMemory(virDomainPtr domain)
676
{
677 678 679 680 681 682 683 684
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
	if (domain == NULL)
	    virProxyError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
	else
	    virProxyError(domain->conn, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
        return (0);
    }
    return(xenProxyDomainGetDomMaxMemory(domain->conn, domain->handle));
685 686 687
}

/**
688 689 690
 * xenProxyDomainGetInfo:
 * @domain: a domain object
 * @info: pointer to a virDomainInfo structure allocated by the user
691
 *
692 693
 * This method looks up information about a domain and update the
 * information block provided.
694
 *
695
 * Returns 0 in case of success, -1 in case of error
696 697
 */
static int
698
xenProxyDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
699
{
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
    virProxyPacket req;
    virProxyFullPacket ans;
    int ret;

    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
	if (domain == NULL)
	    virProxyError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
	else
	    virProxyError(domain->conn, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
        return (0);
    }
    if (info == NULL) {
        virProxyError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
	return (-1);
    }
    memset(&req, 0, sizeof(req));
    req.command = VIR_PROXY_DOMAIN_INFO;
    req.len = sizeof(req);
    ret = xenProxyCommand(domain->conn, &req, &ans);
    if (ret < 0) {
        xenProxyClose(domain->conn);
	return(-1);
    }
    if (ans.len != sizeof(virProxyPacket) + sizeof(virDomainInfo)) {
        virProxyError(domain->conn, VIR_ERR_OPERATION_FAILED, __FUNCTION__);
	return (-1);
    }
    memmove(info, &ans.extra.dinfo, sizeof(virDomainInfo));
728

729 730
    return(0);
}
731 732

/**
733 734 735
 * xenProxyLookupByID:
 * @conn: pointer to the hypervisor connection
 * @id: the domain ID number
736
 *
737
 * Try to find a domain based on the hypervisor ID number
738
 *
739
 * Returns a new domain object or NULL in case of failure
740
 */
741 742
static virDomainPtr
xenProxyLookupByID(virConnectPtr conn, int id)
743
{
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
    virProxyPacket req;
    virProxyFullPacket ans;
    unsigned char uuid[16];
    const char *name;
    int ret;
    virDomainPtr res;

    if (!VIR_IS_CONNECT(conn)) {
        virProxyError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
        return (NULL);
    }
    memset(&req, 0, sizeof(req));
    req.command = VIR_PROXY_LOOKUP_ID;
    req.data.arg = id;
    req.len = sizeof(req);
    ret = xenProxyCommand(conn, &req, &ans);
    if (ret < 0) {
        xenProxyClose(conn);
	return(NULL);
    }
    if (req.data.arg == -1) {
	return(NULL);
    }
    memcpy(uuid, &ans.extra.str[0], 16);
    name = &ans.extra.str[16];
    res = virGetDomain(conn, name, uuid);

    if (res == NULL)
        virProxyError(conn, VIR_ERR_NO_MEMORY, "Allocating domain");
    else
	res->handle = id;
    
    return(res);
777 778 779
}

/**
780 781 782
 * xenProxyLookupByUUID:
 * @conn: pointer to the hypervisor connection
 * @uuid: the raw UUID for the domain
783
 *
784
 * Try to lookup a domain on xend based on its UUID.
785
 *
786
 * Returns a new domain object or NULL in case of failure
787
 */
788 789
static virDomainPtr
xenProxyLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
790
{
791 792
    TODO
    return(NULL);
793 794
}

795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
/**
 * xenProxyDomainLookupByName:
 * @conn: A xend instance
 * @name: The name of the domain
 *
 * This method looks up information about a domain based on its name
 *
 * Returns a new domain object or NULL in case of failure
 */
static virDomainPtr
xenProxyDomainLookupByName(virConnectPtr conn, const char *domname)
{
    TODO
    return(NULL);
}
810

811 812 813 814 815 816 817 818 819 820 821 822 823
/**
 * xenProxyNodeGetInfo:
 * @conn: pointer to the Xen Daemon block
 * @info: pointer to a virNodeInfo structure allocated by the user
 * 
 * Extract hardware information about the node.
 *
 * Returns 0 in case of success and -1 in case of failure.
 */
static int
xenProxyNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) {
    TODO
    return(-1);
824
}
825