aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/ar71xx/patches-4.9/506-MIPS-ath79-prom-parse-redboot-args.patch
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2020-02-27 22:32:54 +0100
committerJo-Philipp Wich <jo@mein.io>2020-02-27 22:32:54 +0100
commitc3bd1321de1e0d814f5cfc4f494f6b2fb1f5133b (patch)
treee09b089d5fe4f35542290429953543c6a482b688 /target/linux/ar71xx/patches-4.9/506-MIPS-ath79-prom-parse-redboot-args.patch
parent82fbd857471292ca71dc06b05f11089962f33a4f (diff)
downloadupstream-18.06.8.tar.gz
upstream-18.06.8.tar.bz2
upstream-18.06.8.zip
OpenWrt v18.06.8: adjust config defaultsv18.06.8
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'target/linux/ar71xx/patches-4.9/506-MIPS-ath79-prom-parse-redboot-args.patch')
0 files changed, 0 insertions, 0 deletions
href='#n148'>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 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 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 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 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 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 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 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
/*
 * Copyright (c) 2006-2007 XenSource, Inc.
 *
 * 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
 */

#define _GNU_SOURCE
#include <assert.h>
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <libxml/parser.h>
#include <curl/curl.h>
#include <xen/api/xen_all.h>

//#define PRINT_XML

static void usage()
{
    fprintf(stderr,
"Usage:\n"
"\n"
"    test_bindings <url> <username> <password>\n"
"\n"
"where\n"
"        <url>      is a fragment of the server's URL, e.g. localhost:8005/RPC2;\n"
"        <username> is the username to use at the server; and\n"
"        <password> is the password.\n");

    exit(EXIT_FAILURE);
}


static char *url;


typedef struct
{
    xen_result_func func;
    void *handle;
} xen_comms;


static xen_vm create_new_vm(xen_session *session, bool hvm);
static void print_session_info(xen_session *session);
static void print_methods(xen_session *session);
static void print_vm_power_state(xen_session *session, xen_vm vm);
static void print_vm_metrics(xen_session *session, xen_vm vm);


static size_t
write_func(void *ptr, size_t size, size_t nmemb, xen_comms *comms)
{
    size_t n = size * nmemb;
#ifdef PRINT_XML
    printf("\n\n---Result from server -----------------------\n");
    printf("%s\n",((char*) ptr));
    fflush(stdout);
#endif
    return comms->func(ptr, n, comms->handle) ? n : 0;
}


static int
call_func(const void *data, size_t len, void *user_handle,
          void *result_handle, xen_result_func result_func)
{
    (void)user_handle;

#ifdef PRINT_XML
    printf("\n\n---Data to server: -----------------------\n");
    printf("%s\n",((char*) data));
    fflush(stdout);
#endif

    CURL *curl = curl_easy_init();
    if (!curl) {
        return -1;
    }

    xen_comms comms = {
        .func = result_func,
        .handle = result_handle
    };

    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
    curl_easy_setopt(curl, CURLOPT_MUTE, 1);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_func);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &comms);
    curl_easy_setopt(curl, CURLOPT_POST, 1);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, len);

    CURLcode result = curl_easy_perform(curl);

    curl_easy_cleanup(curl);

    return result;
}


static void print_error(xen_session *session)
{
    fprintf(stderr, "Error: %d", session->error_description_count);
    for (int i = 0; i < session->error_description_count; i++)
    {
        fprintf(stderr, "%s ", session->error_description[i]);
    }
    fprintf(stderr, "\n");
}


int main(int argc, char **argv)
{
    if (argc != 4)
    {
        usage();
    }

    url = argv[1];
    char *username = argv[2];
    char *password = argv[3];

    xmlInitParser();
    xen_init();
    curl_global_init(CURL_GLOBAL_ALL);

#define CLEANUP                                 \
    do {                                        \
        xen_session_logout(session);            \
        curl_global_cleanup();                  \
        xen_fini();                             \
        xmlCleanupParser();                     \
    } while(0)                                  \

    
    xen_session *session =
        xen_session_login_with_password(call_func, NULL, username, password);

    print_session_info(session);
    if (!session->ok)
    {
        /* Error has been logged, just clean up. */
        CLEANUP;
        return 1;
    }

    print_methods(session);
    if (!session->ok)
    {
        /* Error has been logged, just clean up. */
        CLEANUP;
        return 1;
    }

    xen_vm vm;
    if (!xen_vm_get_by_uuid(session, &vm,
                            "00000000-0000-0000-0000-000000000000"))
    {
        print_error(session);
        CLEANUP;
        return 1;
    }

    char *vm_uuid;
    if (!xen_vm_get_uuid(session, &vm_uuid, vm))
    {
        print_error(session);
        xen_vm_free(vm);
        CLEANUP;
        return 1;
    }

    char *vm_uuid_bytes;
    if (!xen_uuid_string_to_bytes(vm_uuid, &vm_uuid_bytes))
    {
        fprintf(stderr, "xen_uuid_string_to_bytes failed.\n");
        xen_uuid_free(vm_uuid);
        xen_vm_free(vm);
        CLEANUP;
        return 1;
    }

    xen_vm_record *vm_record;
    if (!xen_vm_get_record(session, &vm_record, vm))
    {
        print_error(session);
        xen_uuid_bytes_free(vm_uuid_bytes);
        xen_uuid_free(vm_uuid);
        xen_vm_free(vm);
        CLEANUP;
        return 1;
    }

    xen_host host;
    if (!xen_session_get_this_host(session, &host, session))
    {
        print_error(session);
        xen_vm_record_free(vm_record);
        xen_uuid_bytes_free(vm_uuid_bytes);
        xen_uuid_free(vm_uuid);
        xen_vm_free(vm);
        CLEANUP;
        return 1;
    }

    xen_string_string_map *versions;
    if (!xen_host_get_software_version(session, &versions, host))
    {
        print_error(session);
        xen_host_free(host);
        xen_vm_record_free(vm_record);
        xen_uuid_bytes_free(vm_uuid_bytes);
        xen_uuid_free(vm_uuid);
        xen_vm_free(vm);
        CLEANUP;
        return 1;
    }

    char *dmesg;
    if (!xen_host_dmesg(session, &dmesg, host))
    {
        print_error(session);
        xen_string_string_map_free(versions);
        xen_host_free(host);
        xen_vm_record_free(vm_record);
        xen_uuid_bytes_free(vm_uuid_bytes);
        xen_uuid_free(vm_uuid);
        xen_vm_free(vm);
        CLEANUP;
        return 1;
    }

    xen_string_set *supported_bootloaders;
    if (!xen_host_get_supported_bootloaders(session, &supported_bootloaders,
                                            host))
    {
        print_error(session);
        free(dmesg);
        xen_string_string_map_free(versions);
        xen_host_free(host);
        xen_vm_record_free(vm_record);
        xen_uuid_bytes_free(vm_uuid_bytes);
        xen_uuid_free(vm_uuid);
        xen_vm_free(vm);
        CLEANUP;
        return 1;
    }

    xen_string_set *capabilities;
    if (!xen_host_get_capabilities(session, &capabilities, host))
    {
        print_error(session);
        free(dmesg);
        xen_string_set_free(supported_bootloaders);
        xen_string_string_map_free(versions);
        xen_host_free(host);
        xen_vm_record_free(vm_record);
        xen_uuid_bytes_free(vm_uuid_bytes);
        xen_uuid_free(vm_uuid);
        xen_vm_free(vm);
        CLEANUP;
        return 1;
    }

    xen_string_string_map *cpu_configuration;
    if (!xen_host_get_cpu_configuration(session, &cpu_configuration, host))
    {
        print_error(session);
        free(dmesg);
        xen_string_set_free(capabilities);
        xen_string_set_free(supported_bootloaders);
        xen_string_string_map_free(versions);
        xen_host_free(host);
        xen_vm_record_free(vm_record);
        xen_uuid_bytes_free(vm_uuid_bytes);
        xen_uuid_free(vm_uuid);
        xen_vm_free(vm);
        CLEANUP;
        return 1;
    }

    char *sched_policy;
    if (!xen_host_get_sched_policy(session, &sched_policy, host))
    {
        print_error(session);
        xen_string_string_map_free(cpu_configuration);
        xen_string_set_free(capabilities);
        xen_string_set_free(supported_bootloaders);
        xen_string_string_map_free(versions);
        xen_host_free(host);
        xen_vm_record_free(vm_record);
        xen_uuid_bytes_free(vm_uuid_bytes);
        xen_uuid_free(vm_uuid);
        xen_vm_free(vm);
        CLEANUP;
        return 1;
    }

    printf("%s.\n", vm_uuid);

    printf("In bytes, the VM UUID is ");
    for (int i = 0; i < 15; i++)
    {
        printf("%x, ", (unsigned int)vm_uuid_bytes[i]);
    }
    printf("%x.\n", (unsigned int)vm_uuid_bytes[15]);

    printf("%zd.\n", versions->size);

    for (size_t i = 0; i < versions->size; i++)
    {
        printf("%s -> %s.\n", versions->contents[i].key,
               versions->contents[i].val);
    }

    printf("Host dmesg follows:\n%s\n\n", dmesg);

    printf("Host supports the following bootloaders:");
    for (size_t i = 0; i < supported_bootloaders->size; i++)
    {
        printf(" %s", supported_bootloaders->contents[i]);
    }
    printf("\n");

    printf("Host has the following capabilities:");
    for (size_t i = 0; i < capabilities->size; i++)
    {
        printf(" %s", capabilities->contents[i]);
    }
    printf("\n");

    printf("Host has the following CPU configuration:\n");
    for (size_t i = 0; i < cpu_configuration->size; i++)
    {
        printf("  %s -> %s.\n", cpu_configuration->contents[i].key,
               cpu_configuration->contents[i].val);
    }

    printf("Current scheduler policy: %s.\n\n", sched_policy);

    printf("%s.\n", vm_record->uuid);

    printf("Resident on %s.\n", (char *)vm_record->resident_on->u.handle);

    printf("%s.\n", xen_vm_power_state_to_string(vm_record->power_state));

    xen_uuid_bytes_free(vm_uuid_bytes);
    xen_uuid_free(vm_uuid);

    xen_vm_record_free(vm_record);

    xen_host_free(host);
    xen_string_string_map_free(versions);
    free(dmesg);
    xen_string_set_free(supported_bootloaders);
    xen_string_set_free(capabilities);
    xen_string_string_map_free(cpu_configuration);
    free(sched_policy);

    print_vm_metrics(session, vm);
    if (!session->ok)
    {
        /* Error has been logged, just clean up. */
        xen_vm_free(vm);
        CLEANUP;
        return 1;
    }

    xen_vm_free(vm);

    xen_vm new_vm = create_new_vm(session, true);
    if (!session->ok)
    {
        /* Error has been logged, just clean up. */
        CLEANUP;
        return 1;
    }

    print_vm_power_state(session, new_vm);
    if (!session->ok)
    {
        /* Error has been logged, just clean up. */
        xen_vm_free(new_vm);
        CLEANUP;
        return 1;
    }

    xen_vm_free(new_vm);
    CLEANUP;

    return 0;
}


/**
 * Creation of a new VM, using the Named Parameters idiom.  Allocate the
 * xen_vm_record here, but the sets through the library.  Either
 * allocation patterns can be used, as long as the allocation and free are
 * paired correctly.
 */
static xen_vm create_new_vm(xen_session *session, bool hvm)
{
    xen_string_string_map *vcpus_params = xen_string_string_map_alloc(1);
    vcpus_params->contents[0].key = strdup("weight");
    vcpus_params->contents[0].val = strdup("300");

    xen_string_string_map *hvm_boot_params;
    if (hvm)
    {
        hvm_boot_params = xen_string_string_map_alloc(1);
        hvm_boot_params->contents[0].key = strdup("order");
        hvm_boot_params->contents[0].val = strdup("cd");
    }
    else
    {
        hvm_boot_params = NULL;
    }

    xen_vm_record vm_record =
        {
            .name_label = hvm ? "NewHVM" : "NewPV",
            .name_description = hvm ? "New HVM VM" : "New PV VM",
            .user_version = 1,
            .is_a_template = false,
            .memory_static_max = 256 * 1024 * 1024,
            .memory_dynamic_max = 256 * 1024 * 1024,
            .memory_dynamic_min = 128 * 1024 * 1024,
            .memory_static_min = 128 * 1024 * 1024,
            .vcpus_params = vcpus_params,
            .vcpus_max = 4,
            .vcpus_at_startup = 2,
            .actions_after_shutdown = XEN_ON_NORMAL_EXIT_DESTROY,
            .actions_after_reboot = XEN_ON_NORMAL_EXIT_RESTART,
            .actions_after_crash = XEN_ON_CRASH_BEHAVIOUR_RESTART,
            .hvm_boot_policy = hvm ? "BIOS order" : NULL,
            .hvm_boot_params = hvm ? hvm_boot_params : NULL,
            .pv_bootloader   = hvm ? NULL : "pygrub",
            .pv_kernel       = hvm ? NULL : "/boot/vmlinuz-2.6.16.33-xen",
        };

    xen_vm vm;
    xen_vm_create(session, &vm, &vm_record);

    xen_string_string_map_free(vcpus_params);
    xen_string_string_map_free(hvm_boot_params);

    if (!session->ok)
    {
        fprintf(stderr, "VM creation failed.\n");
        print_error(session);
        return NULL;
    }


    /*
     * Create a new disk for the new VM.
     */
    xen_sr_set *srs;
    if (!xen_sr_get_by_name_label(session, &srs, "QCoW") ||
        srs->size < 1)
    {
        fprintf(stderr, "SR lookup failed.\n");
        print_error(session);
        xen_vm_free(vm);
        return NULL;
    }

    xen_sr_record_opt sr_record =
        {
            .u.handle = srs->contents[0]
        };
    xen_vdi_record vdi0_record =
        {
            .name_label = "MyRootFS",
            .name_description = "MyRootFS description",
            .sr = &sr_record,
            .virtual_size = (INT64_C(1) << 30),  // 1GiB
            .type = XEN_VDI_TYPE_SYSTEM,
            .sharable = false,
            .read_only = false
        };
    
    xen_vdi vdi0;
    if (!xen_vdi_create(session, &vdi0, &vdi0_record))
    {
        fprintf(stderr, "VDI creation failed.\n");
        print_error(session);

        xen_sr_set_free(srs);
        xen_vm_free(vm);
        return NULL;
    }


    xen_vm_record_opt vm_record_opt =
        {
            .u.handle = vm
        };
    xen_vdi_record_opt vdi0_record_opt =
        {
            .u.handle = vdi0
        };
    xen_vbd_record vbd0_record =
        {
            .vm = &vm_record_opt,
            .vdi = &vdi0_record_opt,
            .device = "xvda1",
            .mode = XEN_VBD_MODE_RW,
            .bootable = 1,
        };

    xen_vbd vbd0;
    if (!xen_vbd_create(session, &vbd0, &vbd0_record))
    {
        fprintf(stderr, "VBD creation failed.\n");
        print_error(session);

        xen_vdi_free(vdi0);
        xen_sr_set_free(srs);
        xen_vm_free(vm);
        return NULL;
    }

    xen_console vnc_console = NULL;
    if (hvm) {
        xen_console_record vnc_console_record =
            {
                .protocol = XEN_CONSOLE_PROTOCOL_RFB,
                .vm = &vm_record_opt,
            };

        if (!xen_console_create(session, &vnc_console, &vnc_console_record))
        {
            fprintf(stderr, "VNC console creation failed.\n");
            print_error(session);

            xen_vbd_free(vbd0);
            xen_vdi_free(vdi0);
            xen_sr_set_free(srs);
            xen_vm_free(vm);
            return NULL;
        }
    }

    char *vm_uuid;
    char *vdi0_uuid;
    char *vbd0_uuid;
    char *vnc_uuid = NULL;

    xen_vm_get_uuid(session,  &vm_uuid,   vm);
    xen_vdi_get_uuid(session, &vdi0_uuid, vdi0);
    xen_vbd_get_uuid(session, &vbd0_uuid, vbd0); 
    if (hvm) {
        xen_console_get_uuid(session, &vnc_uuid, vnc_console);
    }

    if (!session->ok)
    {
        fprintf(stderr, "get_uuid call failed.\n");
        print_error(session);

        xen_uuid_free(vm_uuid);
        xen_uuid_free(vdi0_uuid);
        xen_uuid_free(vbd0_uuid);
        xen_uuid_free(vnc_uuid);
        xen_vbd_free(vbd0);
        xen_vdi_free(vdi0);
        xen_console_free(vnc_console);
        xen_sr_set_free(srs);
        xen_vm_free(vm);
        return NULL;
    }

    if (hvm) {
        printf("Created a new HVM VM, with UUID %s, VDI UUID %s, VBD "
               "UUID %s, and VNC console UUID %s.\n",
               vm_uuid, vdi0_uuid, vbd0_uuid, vnc_uuid);
    }
    else {
        printf("Created a new PV VM, with UUID %s, VDI UUID %s, and VBD "
               "UUID %s.\n",
               vm_uuid, vdi0_uuid, vbd0_uuid);
    }

    xen_uuid_free(vm_uuid);
    xen_uuid_free(vdi0_uuid);
    xen_uuid_free(vbd0_uuid);
    xen_uuid_free(vnc_uuid);
    xen_vbd_free(vbd0);
    xen_vdi_free(vdi0);
    xen_console_free(vnc_console);
    xen_sr_set_free(srs);

    return vm;
}


/**
 * Print the power state for the given VM.
 */
static void print_vm_power_state(xen_session *session, xen_vm vm)
{
    char *vm_uuid;
    enum xen_vm_power_state power_state;

    if (!xen_vm_get_uuid(session, &vm_uuid, vm))
    {
        print_error(session);
        return;
    }

    if (!xen_vm_get_power_state(session, &power_state, vm))
    {
        xen_uuid_free(vm_uuid);
        print_error(session);
        return;
    }

    printf("VM %s power state is %s.\n", vm_uuid,
           xen_vm_power_state_to_string(power_state));

    xen_uuid_free(vm_uuid);

    fflush(stdout);
}


/**
 * Workaround for whinging GCCs, as suggested by strftime(3).
 */
static size_t my_strftime(char *s, size_t max, const char *fmt,
                          const struct tm *tm)
{
    return strftime(s, max, fmt, tm);
}


/**
 * Print some session details.
 */
static void print_session_info(xen_session *session)
{
    xen_session_record *record;
    if (!xen_session_get_record(session, &record, session))
    {
        print_error(session);
        return;
    }

    printf("Session UUID: %s.\n", record->uuid);
    printf("Session user: %s.\n", record->this_user);
    char time[256];
    struct tm *tm = localtime(&record->last_active);
    my_strftime(time, 256, "Session last active: %c, local time.\n", tm);
    printf(time);

    char *uuid = NULL;
    char *this_user = NULL;
    xen_session_get_uuid(session, &uuid, session);
    xen_session_get_this_user(session, &this_user, session);

    if (!session->ok)
    {
        free(uuid);
        free(this_user);
        xen_session_record_free(record);
        print_error(session);
        return;
    }

    assert(!strcmp(record->uuid, uuid));
    assert(!strcmp(record->this_user, this_user));

    free(uuid);
    free(this_user);
    xen_session_record_free(record);

    fflush(stdout);
}


static int pstrcmp(const void *p1, const void *p2)
{
    return strcmp(*(char **)p1, *(char **)p2);
}


/**
 * Print the list of supported methods.
 */
static void print_methods(xen_session *session)
{
    xen_string_set *methods;

    if (!xen_host_list_methods(session, &methods))
    {
        print_error(session);
        goto done;
    }

    printf("%zd.\n", methods->size);
    qsort(methods->contents, methods->size, sizeof(char *), pstrcmp);

    printf("Supported methods:\n");
    for (size_t i = 0; i < methods->size; i++)
    {
        printf("  %s\n", methods->contents[i]);
    }
    fflush(stdout);

done:
    xen_string_set_free(methods);
}


/**
 * Print the metrics for the given VM.
 */
static void print_vm_metrics(xen_session *session, xen_vm vm)
{
    xen_vm_metrics vm_metrics;
    if (!xen_vm_get_metrics(session, &vm_metrics, vm))
    {
        print_error(session);
        return;
    }

    xen_vm_metrics_record *vm_metrics_record;
    if (!xen_vm_metrics_get_record(session, &vm_metrics_record, vm_metrics))
    {
        xen_vm_metrics_free(vm_metrics);
        print_error(session);
        return;
    }

    char time[256];
    struct tm *tm = localtime(&vm_metrics_record->last_updated);
    my_strftime(time, 256, "Metrics updated at %c, local time.\n", tm);
    printf(time);

    tm = localtime(&vm_metrics_record->start_time);
    my_strftime(time, 256, "VM running since %c, local time.\n", tm);
    printf(time);

    for (size_t i = 0; i < vm_metrics_record->vcpus_utilisation->size; i++)
    {
        printf("%"PRId64" -> %lf.\n",
               vm_metrics_record->vcpus_utilisation->contents[i].key,
               vm_metrics_record->vcpus_utilisation->contents[i].val);
    }

    printf("VCPU -> PCPU mapping:\n");
    for (size_t i = 0; i < vm_metrics_record->vcpus_cpu->size; i++)
    {
        printf("  %"PRId64" -> %"PRId64".\n",
               vm_metrics_record->vcpus_cpu->contents[i].key,
               vm_metrics_record->vcpus_cpu->contents[i].val);
    }

    printf("Live scheduling parameters:\n");
    for (size_t i = 0; i < vm_metrics_record->vcpus_params->size; i++)
    {
        printf("  %s -> %s.\n",
               vm_metrics_record->vcpus_params->contents[i].key,
               vm_metrics_record->vcpus_params->contents[i].val);
    }

    for (size_t i = 0; i < vm_metrics_record->vcpus_flags->size; i++)
    {
        printf("%"PRId64" -> ",
               vm_metrics_record->vcpus_flags->contents[i].key);
        xen_string_set *s = vm_metrics_record->vcpus_flags->contents[i].val;
        for (size_t j = 0; j < s->size; j++)
        {
            printf("%s", s->contents[j]);
            if (j + 1 != s->size)
            {
                printf(", ");
            }
        }
        printf("\n");
    }

    xen_vm_metrics_record_free(vm_metrics_record);
    xen_vm_metrics_free(vm_metrics);

    fflush(stdout);
}