qemu_monitor.c 24.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/*
 * qemu_monitor.c: interaction with QEMU monitor console
 *
 * Copyright (C) 2006-2009 Red Hat, Inc.
 * Copyright (C) 2006 Daniel P. Berrange
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
 * Author: Daniel P. Berrange <berrange@redhat.com>
 */

#include <config.h>

#include <poll.h>
#include <sys/un.h>
#include <unistd.h>
#include <fcntl.h>

#include "qemu_monitor.h"
32
#include "qemu_monitor_text.h"
33 34 35
#include "qemu_conf.h"
#include "event.h"
#include "virterror_internal.h"
36 37
#include "memory.h"
#include "logging.h"
38 39 40

#define VIR_FROM_THIS VIR_FROM_QEMU

41
struct _qemuMonitor {
42
    virMutex lock;
43 44 45
    virCond notify;

    virDomainObjPtr dom;
46

47 48 49 50 51 52 53
    int fd;
    int watch;
    int hasSendFD;

    virDomainObjPtr vm;

    qemuMonitorEOFNotify eofCB;
54
    qemuMonitorDiskSecretLookup secretCB;
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

    /* If there's a command being processed this will be
     * non-NULL */
    qemuMonitorMessagePtr msg;

    /* Buffer incoming data ready for Text/QMP monitor
     * code to process & find message boundaries */
    size_t bufferOffset;
    size_t bufferLength;
    char *buffer;

    /* If anything went wrong, this will be fed back
     * the next monitor msg */
    int lastErrno;

    /* If the monitor callback is currently active */
    unsigned eofcb: 1;
    /* If the monitor callback should free the closed monitor */
    unsigned closed: 1;
74 75
};

76 77 78 79 80 81 82 83 84 85
void qemuMonitorLock(qemuMonitorPtr mon)
{
    virMutexLock(&mon->lock);
}

void qemuMonitorUnlock(qemuMonitorPtr mon)
{
    virMutexUnlock(&mon->lock);
}

86

87
static void qemuMonitorFree(qemuMonitorPtr mon, int lockDomain)
88
{
89 90 91 92 93 94
    VIR_DEBUG("mon=%p, lockDomain=%d", mon, lockDomain);
    if (mon->vm) {
        if (lockDomain)
            virDomainObjLock(mon->vm);
        if (!virDomainObjUnref(mon->vm) && lockDomain)
            virDomainObjUnlock(mon->vm);
95
    }
96 97 98 99
    if (virCondDestroy(&mon->notify) < 0)
    {}
    virMutexDestroy(&mon->lock);
    VIR_FREE(mon);
100 101 102 103
}


static int
104
qemuMonitorOpenUnix(const char *monitor)
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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
{
    struct sockaddr_un addr;
    int monfd;
    int timeout = 3; /* In seconds */
    int ret, i = 0;

    if ((monfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
        virReportSystemError(NULL, errno,
                             "%s", _("failed to create socket"));
        return -1;
    }

    memset(&addr, 0, sizeof(addr));
    addr.sun_family = AF_UNIX;
    if (virStrcpyStatic(addr.sun_path, monitor) == NULL) {
        qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                         _("Monitor path %s too big for destination"), monitor);
        goto error;
    }

    do {
        ret = connect(monfd, (struct sockaddr *) &addr, sizeof(addr));

        if (ret == 0)
            break;

        if (errno == ENOENT || errno == ECONNREFUSED) {
            /* ENOENT       : Socket may not have shown up yet
             * ECONNREFUSED : Leftover socket hasn't been removed yet */
            continue;
        }

        virReportSystemError(NULL, errno, "%s",
                             _("failed to connect to monitor socket"));
        goto error;

    } while ((++i <= timeout*5) && (usleep(.2 * 1000000) <= 0));

    if (ret != 0) {
        virReportSystemError(NULL, errno, "%s",
                             _("monitor socket did not show up."));
        goto error;
    }

149
    return monfd;
150 151 152 153 154 155 156

error:
    close(monfd);
    return -1;
}

static int
157
qemuMonitorOpenPty(const char *monitor)
158 159 160 161 162 163 164 165 166
{
    int monfd;

    if ((monfd = open(monitor, O_RDWR)) < 0) {
        qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                         _("Unable to open monitor path %s"), monitor);
        return -1;
    }

167
    return monfd;
168
}
169

170 171 172 173 174 175 176 177 178 179 180 181

static int
qemuMonitorIOProcess(qemuMonitorPtr mon)
{
    int len;
    qemuMonitorMessagePtr msg = NULL;

    /* See if there's a message & whether its ready for its reply
     * ie whether its completed writing all its data */
    if (mon->msg && mon->msg->txOffset == mon->msg->txLength)
        msg = mon->msg;

182
    VIR_DEBUG("Process %d", (int)mon->bufferOffset);
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
    len = qemuMonitorTextIOProcess(mon,
                                   mon->buffer, mon->bufferOffset,
                                   msg);

    if (len < 0) {
        mon->lastErrno = errno;
        return -1;
    }

    if (len < mon->bufferOffset) {
        memmove(mon->buffer, mon->buffer + len, mon->bufferOffset - len);
        mon->bufferOffset -= len;
    } else {
        VIR_FREE(mon->buffer);
        mon->bufferOffset = mon->bufferLength = 0;
    }
199
    VIR_DEBUG("Process done %d used %d", (int)mon->bufferOffset, len);
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
    if (msg && msg->finished)
        virCondBroadcast(&mon->notify);
    return len;
}


static int
qemuMonitorIOWriteWithFD(qemuMonitorPtr mon,
                         const char *data,
                         size_t len,
                         int fd)
{
    struct msghdr msg;
    struct iovec iov[1];
    int ret;
    char control[CMSG_SPACE(sizeof(int))];
    struct cmsghdr *cmsg;

    if (!mon->hasSendFD) {
        errno = EINVAL;
        return -1;
    }

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

    iov[0].iov_base = (void *)data;
    iov[0].iov_len = len;

    msg.msg_iov = iov;
    msg.msg_iovlen = 1;

    msg.msg_control = control;
    msg.msg_controllen = sizeof(control);

    cmsg = CMSG_FIRSTHDR(&msg);
    cmsg->cmsg_len = CMSG_LEN(sizeof(int));
    cmsg->cmsg_level = SOL_SOCKET;
    cmsg->cmsg_type = SCM_RIGHTS;
    memcpy(CMSG_DATA(cmsg), &fd, sizeof(int));

    do {
        ret = sendmsg(mon->fd, &msg, 0);
    } while (ret < 0 && errno == EINTR);

    return ret;
}

/* Called when the monitor is able to write data */
static int
qemuMonitorIOWrite(qemuMonitorPtr mon)
{
    int done;

    /* If no active message, or fully transmitted, the no-op */
    if (!mon->msg || mon->msg->txOffset == mon->msg->txLength)
        return 0;

    if (mon->msg->txFD == -1)
        done = write(mon->fd,
                     mon->msg->txBuffer + mon->msg->txOffset,
                     mon->msg->txLength - mon->msg->txOffset);
    else
        done = qemuMonitorIOWriteWithFD(mon,
                                        mon->msg->txBuffer + mon->msg->txOffset,
                                        mon->msg->txLength - mon->msg->txOffset,
                                        mon->msg->txFD);

    if (done < 0) {
        if (errno == EAGAIN)
            return 0;

        mon->lastErrno = errno;
        return -1;
    }
    mon->msg->txOffset += done;
    return done;
}

/*
 * Called when the monitor has incoming data to read
 *
 * Returns -1 on error, or number of bytes read
 */
static int
qemuMonitorIORead(qemuMonitorPtr mon)
{
    size_t avail = mon->bufferLength - mon->bufferOffset;
    int ret = 0;

    if (avail < 1024) {
        if (VIR_REALLOC_N(mon->buffer,
                          mon->bufferLength + 1024) < 0) {
            errno = ENOMEM;
            return -1;
        }
        mon->bufferLength += 1024;
        avail += 1024;
    }

    /* Read as much as we can get into our buffer,
       until we block on EAGAIN, or hit EOF */
    while (avail > 1) {
        int got;
        got = read(mon->fd,
                   mon->buffer + mon->bufferOffset,
                   avail - 1);
        if (got < 0) {
            if (errno == EAGAIN)
                break;
            mon->lastErrno = errno;
            ret = -1;
            break;
        }
        if (got == 0)
            break;

        ret += got;
        avail -= got;
        mon->bufferOffset += got;
        mon->buffer[mon->bufferOffset] = '\0';
    }

322
    VIR_DEBUG("Now read %d bytes of data", (int)mon->bufferOffset);
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341

    return ret;
}


static void qemuMonitorUpdateWatch(qemuMonitorPtr mon)
{
    int events =
        VIR_EVENT_HANDLE_HANGUP |
        VIR_EVENT_HANDLE_ERROR;

    if (!mon->lastErrno) {
        events |= VIR_EVENT_HANDLE_READABLE;

        if (mon->msg && mon->msg->txOffset < mon->msg->txLength)
            events |= VIR_EVENT_HANDLE_WRITABLE;
    }

    virEventUpdateHandle(mon->watch, events);
342 343
}

344 345 346 347 348 349

static void
qemuMonitorIO(int watch, int fd, int events, void *opaque) {
    qemuMonitorPtr mon = opaque;
    int quit = 0, failed = 0;

350 351 352
    qemuMonitorLock(mon);
    VIR_DEBUG("Monitor %p I/O on watch %d fd %d events %d", mon, watch, fd, events);

353
    if (mon->fd != fd || mon->watch != watch) {
354
        VIR_ERROR("event from unexpected fd %d!=%d / watch %d!=%d", mon->fd, fd, mon->watch, watch);
355 356
        failed = 1;
    } else {
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
        if (!mon->lastErrno &&
            events & VIR_EVENT_HANDLE_WRITABLE) {
            int done = qemuMonitorIOWrite(mon);
            if (done < 0)
                failed = 1;
            events &= ~VIR_EVENT_HANDLE_WRITABLE;
        }
        if (!mon->lastErrno &&
            events & VIR_EVENT_HANDLE_READABLE) {
            int got = qemuMonitorIORead(mon);
            if (got < 0)
                failed = 1;
            /* Ignore hangup/error events if we read some data, to
             * give time for that data to be consumed */
            if (got > 0) {
                events = 0;

                if (qemuMonitorIOProcess(mon) < 0)
                    failed = 1;
            } else
                events &= ~VIR_EVENT_HANDLE_READABLE;
        }

        /* If IO process resulted in an error & we have a message,
         * then wakeup that waiter */
        if (mon->lastErrno && mon->msg && !mon->msg->finished) {
            mon->msg->lastErrno = mon->lastErrno;
            mon->msg->finished = 1;
            virCondSignal(&mon->notify);
        }

        qemuMonitorUpdateWatch(mon);

        if (events & VIR_EVENT_HANDLE_HANGUP) {
            /* If IO process resulted in EOF & we have a message,
             * then wakeup that waiter */
            if (mon->msg && !mon->msg->finished) {
                mon->msg->finished = 1;
                mon->msg->lastErrno = EIO;
                virCondSignal(&mon->notify);
            }
398
            quit = 1;
399
        } else if (events) {
400 401 402 403 404 405
            VIR_ERROR(_("unhandled fd event %d for monitor fd %d"),
                      events, mon->fd);
            failed = 1;
        }
    }

406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
    /* We have to unlock to avoid deadlock against command thread,
     * but is this safe ?  I think it is, because the callback
     * will try to acquire the virDomainObjPtr mutex next */
    if (failed || quit) {
        /* Make sure anyone waiting wakes up now */
        virCondSignal(&mon->notify);
        mon->eofcb = 1;
        qemuMonitorUnlock(mon);
        VIR_DEBUG("Triggering EOF callback error? %d", failed);
        mon->eofCB(mon, mon->vm, failed);

        qemuMonitorLock(mon);
        if (mon->closed) {
            qemuMonitorUnlock(mon);
            VIR_DEBUG("Delayed free of monitor %p", mon);
            qemuMonitorFree(mon, 1);
        } else {
            qemuMonitorUnlock(mon);
        }
    } else {
        qemuMonitorUnlock(mon);
    }
428 429 430 431
}


qemuMonitorPtr
432
qemuMonitorOpen(virDomainObjPtr vm,
433
                qemuMonitorEOFNotify eofCB)
434
{
435 436 437 438 439 440 441
    qemuMonitorPtr mon;

    if (VIR_ALLOC(mon) < 0) {
        virReportOOMError(NULL);
        return NULL;
    }

442 443 444 445 446 447
    if (virMutexInit(&mon->lock) < 0) {
        qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
                         _("cannot initialize monitor mutex"));
        VIR_FREE(mon);
        return NULL;
    }
448 449 450 451 452 453 454
    if (virCondInit(&mon->notify) < 0) {
        qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
                         _("cannot initialize monitor condition"));
        virMutexDestroy(&mon->lock);
        VIR_FREE(mon);
        return NULL;
    }
455 456 457
    mon->fd = -1;
    mon->vm = vm;
    mon->eofCB = eofCB;
458
    qemuMonitorLock(mon);
459

460 461
    switch (vm->monitor_chr->type) {
    case VIR_DOMAIN_CHR_TYPE_UNIX:
462
        mon->hasSendFD = 1;
463
        mon->fd = qemuMonitorOpenUnix(vm->monitor_chr->data.nix.path);
464 465
        break;

466
    case VIR_DOMAIN_CHR_TYPE_PTY:
467
        mon->fd = qemuMonitorOpenPty(vm->monitor_chr->data.file.path);
468 469
        break;

470 471 472 473
    default:
        qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                         _("unable to handle monitor type: %s"),
                         virDomainChrTypeToString(vm->monitor_chr->type));
474 475 476
        goto cleanup;
    }

477 478 479 480 481 482 483 484 485 486 487 488
    if (virSetCloseExec(mon->fd) < 0) {
        qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                         "%s", _("Unable to set monitor close-on-exec flag"));
        goto cleanup;
    }
    if (virSetNonBlock(mon->fd) < 0) {
        qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                         "%s", _("Unable to put monitor into non-blocking mode"));
        goto cleanup;
    }


489
    if ((mon->watch = virEventAddHandle(mon->fd,
490 491 492
                                        VIR_EVENT_HANDLE_HANGUP |
                                        VIR_EVENT_HANDLE_ERROR |
                                        VIR_EVENT_HANDLE_READABLE,
493 494 495 496 497 498 499
                                        qemuMonitorIO,
                                        mon, NULL)) < 0) {
        qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
                         _("unable to register monitor events"));
        goto cleanup;
    }

500 501 502 503
    virDomainObjRef(vm);

    VIR_DEBUG("New mon %p fd =%d watch=%d", mon, mon->fd, mon->watch);
    qemuMonitorUnlock(mon);
504

505 506 507
    return mon;

cleanup:
508
    qemuMonitorUnlock(mon);
509 510 511 512 513 514 515 516 517 518
    qemuMonitorClose(mon);
    return NULL;
}


void qemuMonitorClose(qemuMonitorPtr mon)
{
    if (!mon)
        return;

519 520 521 522 523 524 525 526 527 528
    qemuMonitorLock(mon);
    if (!mon->closed) {
        if (mon->watch)
            virEventRemoveHandle(mon->watch);
        if (mon->fd != -1)
            close(mon->fd);
        /* NB: don't reset  fd / watch fields, since active
         * callback may still want them */
        mon->closed = 1;
    }
529

530 531 532 533 534 535 536
    if (mon->eofcb) {
        VIR_DEBUG("Mark monitor to be deleted %p", mon);
        qemuMonitorUnlock(mon);
    } else {
        VIR_DEBUG("Delete monitor now %p", mon);
        qemuMonitorFree(mon, 0);
    }
537 538 539
}


540 541 542 543 544 545 546
void qemuMonitorRegisterDiskSecretLookup(qemuMonitorPtr mon,
                                         qemuMonitorDiskSecretLookup secretCB)
{
    mon->secretCB = secretCB;
}


547 548
int qemuMonitorSend(qemuMonitorPtr mon,
                    qemuMonitorMessagePtr msg)
549
{
550
    int ret = -1;
551

552 553 554
    if (mon->eofcb) {
        msg->lastErrno = EIO;
        qemuMonitorUnlock(mon);
555 556
        return -1;
    }
557

558 559
    mon->msg = msg;
    qemuMonitorUpdateWatch(mon);
560

561 562 563 564
    while (!mon->msg->finished) {
        if (virCondWait(&mon->notify, &mon->lock) < 0)
            goto cleanup;
    }
565

566 567
    if (mon->lastErrno == 0)
        ret = 0;
568

569 570 571
cleanup:
    mon->msg = NULL;
    qemuMonitorUpdateWatch(mon);
572

573
    return ret;
574
}
575 576 577 578 579 580 581 582 583 584 585 586 587


int qemuMonitorGetDiskSecret(qemuMonitorPtr mon,
                             virConnectPtr conn,
                             const char *path,
                             char **secret,
                             size_t *secretLen)
{
    *secret = NULL;
    *secretLen = 0;

    return mon->secretCB(mon, conn, mon->vm, path, secret, secretLen);
}
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 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 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 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 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 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 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905


int
qemuMonitorStartCPUs(qemuMonitorPtr mon,
                     virConnectPtr conn)
{
    DEBUG("mon=%p, fd=%d", mon, mon->fd);

    return qemuMonitorTextStartCPUs(mon, conn);
}


int
qemuMonitorStopCPUs(qemuMonitorPtr mon)
{
    DEBUG("mon=%p, fd=%d", mon, mon->fd);

    return qemuMonitorTextStopCPUs(mon);
}


int qemuMonitorSystemPowerdown(qemuMonitorPtr mon)
{
    DEBUG("mon=%p, fd=%d", mon, mon->fd);

    return qemuMonitorTextSystemPowerdown(mon);
}


int qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
                          int **pids)
{
    DEBUG("mon=%p, fd=%d", mon, mon->fd);

    return qemuMonitorTextGetCPUInfo(mon, pids);
}

int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
                              unsigned long *currmem)
{
    DEBUG("mon=%p, fd=%d", mon, mon->fd);

    return qemuMonitorTextGetBalloonInfo(mon, currmem);
}


int qemuMonitorGetBlockStatsInfo(qemuMonitorPtr mon,
                                 const char *devname,
                                 long long *rd_req,
                                 long long *rd_bytes,
                                 long long *wr_req,
                                 long long *wr_bytes,
                                 long long *errs)
{
    DEBUG("mon=%p, fd=%d dev=%s", mon, mon->fd, devname);

    return qemuMonitorTextGetBlockStatsInfo(mon, devname,
                                            rd_req, rd_bytes,
                                            wr_req, wr_bytes,
                                            errs);
}


int qemuMonitorSetVNCPassword(qemuMonitorPtr mon,
                              const char *password)
{
    DEBUG("mon=%p, fd=%d", mon, mon->fd);

    return qemuMonitorTextSetVNCPassword(mon, password);
}


int qemuMonitorSetBalloon(qemuMonitorPtr mon,
                          unsigned long newmem)
{
    DEBUG("mon=%p, fd=%d newmem=%lu", mon, mon->fd, newmem);

    return qemuMonitorTextSetBalloon(mon, newmem);
}

int qemuMonitorEjectMedia(qemuMonitorPtr mon,
                          const char *devname)
{
    DEBUG("mon=%p, fd=%d devname=%s", mon, mon->fd, devname);

    return qemuMonitorTextEjectMedia(mon, devname);
}


int qemuMonitorChangeMedia(qemuMonitorPtr mon,
                           const char *devname,
                           const char *newmedia)
{
    DEBUG("mon=%p, fd=%d devname=%s newmedia=%s",
          mon, mon->fd, devname, newmedia);

    return qemuMonitorTextChangeMedia(mon, devname, newmedia);
}


int qemuMonitorSaveVirtualMemory(qemuMonitorPtr mon,
                                 unsigned long long offset,
                                 size_t length,
                                 const char *path)
{
    DEBUG("mon=%p, fd=%d offset=%llu length=%zu path=%s",
          mon, mon->fd, offset, length, path);

    return qemuMonitorTextSaveVirtualMemory(mon, offset, length, path);
}

int qemuMonitorSavePhysicalMemory(qemuMonitorPtr mon,
                                  unsigned long long offset,
                                  size_t length,
                                  const char *path)
{
    DEBUG("mon=%p, fd=%d offset=%llu length=%zu path=%s",
          mon, mon->fd, offset, length, path);

    return qemuMonitorTextSavePhysicalMemory(mon, offset, length, path);
}


int qemuMonitorSetMigrationSpeed(qemuMonitorPtr mon,
                                 unsigned long bandwidth)
{
    DEBUG("mon=%p, fd=%d bandwidth=%lu", mon, mon->fd, bandwidth);

    return qemuMonitorTextSetMigrationSpeed(mon, bandwidth);
}

int qemuMonitorGetMigrationStatus(qemuMonitorPtr mon,
                                  int *status,
                                  unsigned long long *transferred,
                                  unsigned long long *remaining,
                                  unsigned long long *total)
{
    DEBUG("mon=%p, fd=%d", mon, mon->fd);

    return qemuMonitorTextGetMigrationStatus(mon, status,
                                             transferred,
                                             remaining,
                                             total);
}


int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
                             int background,
                             const char *hostname,
                             int port)
{
    DEBUG("mon=%p, fd=%d hostname=%s port=%d",
          mon, mon->fd, hostname, port);

    return qemuMonitorTextMigrateToHost(mon, background, hostname, port);
}


int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
                                int background,
                                const char * const *argv,
                                const char *target)
{
    DEBUG("mon=%p, fd=%d argv=%p target=%s",
          mon, mon->fd, argv, target);

    return qemuMonitorTextMigrateToCommand(mon, background, argv, target);
}

int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
                             int background,
                             const char *unixfile)
{
    DEBUG("mon=%p fd=%d unixfile=%s",
          mon, mon->fd, unixfile);

    return qemuMonitorTextMigrateToUnix(mon, background, unixfile);
}

int qemuMonitorMigrateCancel(qemuMonitorPtr mon)
{
    DEBUG("mon=%p fd=%d", mon, mon->fd);

    return qemuMonitorTextMigrateCancel(mon);
}

int qemuMonitorAddUSBDisk(qemuMonitorPtr mon,
                          const char *path)
{
    DEBUG("mon=%p, fd=%d path=%s", mon, mon->fd, path);

    return qemuMonitorTextAddUSBDisk(mon, path);
}


int qemuMonitorAddUSBDeviceExact(qemuMonitorPtr mon,
                                 int bus,
                                 int dev)
{
    DEBUG("mon=%p, fd=%d bus=%d dev=%d", mon, mon->fd, bus, dev);

    return qemuMonitorTextAddUSBDeviceExact(mon, bus, dev);
}

int qemuMonitorAddUSBDeviceMatch(qemuMonitorPtr mon,
                                 int vendor,
                                 int product)
{
    DEBUG("mon=%p, fd=%d vendor=%d product=%d",
          mon, mon->fd, vendor, product);

    return qemuMonitorTextAddUSBDeviceMatch(mon, vendor, product);
}


int qemuMonitorAddPCIHostDevice(qemuMonitorPtr mon,
                                unsigned hostDomain,
                                unsigned hostBus,
                                unsigned hostSlot,
                                unsigned hostFunction,
                                unsigned *guestDomain,
                                unsigned *guestBus,
                                unsigned *guestSlot)
{
    DEBUG("mon=%p, fd=%d domain=%d bus=%d slot=%d function=%d",
          mon, mon->fd,
          hostDomain, hostBus, hostSlot, hostFunction);

    return qemuMonitorTextAddPCIHostDevice(mon, hostDomain,
                                           hostBus, hostSlot,
                                           hostFunction,
                                           guestDomain,
                                           guestBus,
                                           guestSlot);
}


int qemuMonitorAddPCIDisk(qemuMonitorPtr mon,
                          const char *path,
                          const char *bus,
                          unsigned *guestDomain,
                          unsigned *guestBus,
                          unsigned *guestSlot)
{
    DEBUG("mon=%p, fd=%d path=%s bus=%s",
          mon, mon->fd, path, bus);

    return qemuMonitorTextAddPCIDisk(mon, path, bus,
                                     guestDomain, guestBus, guestSlot);
}


int qemuMonitorAddPCINetwork(qemuMonitorPtr mon,
                             const char *nicstr,
                             unsigned *guestDomain,
                             unsigned *guestBus,
                             unsigned *guestSlot)
{
    DEBUG("mon=%p, fd=%d nicstr=%s", mon, mon->fd, nicstr);

    return qemuMonitorTextAddPCINetwork(mon, nicstr, guestDomain,
                                        guestBus, guestSlot);
}


int qemuMonitorRemovePCIDevice(qemuMonitorPtr mon,
                               unsigned guestDomain,
                               unsigned guestBus,
                               unsigned guestSlot)
{
    DEBUG("mon=%p, fd=%d domain=%d bus=%d slot=%d",
          mon, mon->fd, guestDomain, guestBus, guestSlot);

    return qemuMonitorTextRemovePCIDevice(mon, guestDomain,
                                          guestBus, guestSlot);
}


int qemuMonitorSendFileHandle(qemuMonitorPtr mon,
                              const char *fdname,
                              int fd)
{
    DEBUG("mon=%p, fd=%d fdname=%s fd=%d",
          mon, mon->fd, fdname, fd);

    return qemuMonitorTextSendFileHandle(mon, fdname, fd);
}


int qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
                               const char *fdname)
{
    DEBUG("mon=%p, fd=%d fdname=%s",
          mon, mon->fd, fdname);

    return qemuMonitorTextCloseFileHandle(mon, fdname);
}


int qemuMonitorAddHostNetwork(qemuMonitorPtr mon,
                              const char *netstr)
{
    DEBUG("mon=%p, fd=%d netstr=%s",
          mon, mon->fd, netstr);

    return qemuMonitorTextAddHostNetwork(mon, netstr);
}


int qemuMonitorRemoveHostNetwork(qemuMonitorPtr mon,
                                 int vlan,
                                 const char *netname)
{
    DEBUG("mon=%p, fd=%d netname=%s",
          mon, mon->fd, netname);

    return qemuMonitorTextRemoveHostNetwork(mon, vlan, netname);
}