virsh-completer.c 18.3 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
/*
 * virsh-completer.c: virsh completer callbacks
 *
 * Copyright (C) 2017 Red Hat, 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, see
 * <http://www.gnu.org/licenses/>.
 *
 * Author: Michal Privoznik <mprivozn@redhat.com>
 */

#include <config.h>

#include "virsh-completer.h"
26
#include "virsh-domain.h"
27
#include "virsh.h"
28
#include "virsh-pool.h"
29
#include "virsh-nodedev.h"
30
#include "virsh-util.h"
31
#include "virsh-secret.h"
32
#include "internal.h"
33
#include "virutil.h"
34 35
#include "viralloc.h"
#include "virstring.h"
36
#include "virxml.h"
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51


char **
virshDomainNameCompleter(vshControl *ctl,
                         const vshCmd *cmd ATTRIBUTE_UNUSED,
                         unsigned int flags)
{
    virshControlPtr priv = ctl->privData;
    virDomainPtr *domains = NULL;
    int ndomains = 0;
    size_t i = 0;
    char **ret = NULL;

    virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE |
                  VIR_CONNECT_LIST_DOMAINS_INACTIVE |
52 53
                  VIR_CONNECT_LIST_DOMAINS_OTHER |
                  VIR_CONNECT_LIST_DOMAINS_PAUSED |
54 55
                  VIR_CONNECT_LIST_DOMAINS_PERSISTENT |
                  VIR_CONNECT_LIST_DOMAINS_RUNNING |
56
                  VIR_CONNECT_LIST_DOMAINS_SHUTOFF,
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
                  NULL);

    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
        return NULL;

    if ((ndomains = virConnectListAllDomains(priv->conn, &domains, flags)) < 0)
        return NULL;

    if (VIR_ALLOC_N(ret, ndomains + 1) < 0)
        goto error;

    for (i = 0; i < ndomains; i++) {
        const char *name = virDomainGetName(domains[i]);

        if (VIR_STRDUP(ret[i], name) < 0)
            goto error;

        virshDomainFree(domains[i]);
    }
    VIR_FREE(domains);

    return ret;

 error:
    for (; i < ndomains; i++)
        virshDomainFree(domains[i]);
    VIR_FREE(domains);
    for (i = 0; i < ndomains; i++)
        VIR_FREE(ret[i]);
    VIR_FREE(ret);
    return NULL;
}
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103


char **
virshDomainInterfaceCompleter(vshControl *ctl,
                              const vshCmd *cmd,
                              unsigned int flags)
{
    virshControlPtr priv = ctl->privData;
    xmlDocPtr xmldoc = NULL;
    xmlXPathContextPtr ctxt = NULL;
    int ninterfaces;
    xmlNodePtr *interfaces = NULL;
    size_t i;
    unsigned int domainXMLFlags = 0;
    char **ret = NULL;
104
    char **tmp = NULL;
105 106 107 108 109 110 111 112 113 114

    virCheckFlags(VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC, NULL);

    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
        return NULL;

    if (vshCommandOptBool(cmd, "config"))
        domainXMLFlags = VIR_DOMAIN_XML_INACTIVE;

    if (virshDomainGetXML(ctl, cmd, domainXMLFlags, &xmldoc, &ctxt) < 0)
115
        goto cleanup;
116 117 118

    ninterfaces = virXPathNodeSet("./devices/interface", ctxt, &interfaces);
    if (ninterfaces < 0)
119
        goto cleanup;
120

121 122
    if (VIR_ALLOC_N(tmp, ninterfaces + 1) < 0)
        goto cleanup;
123 124 125 126 127

    for (i = 0; i < ninterfaces; i++) {
        ctxt->node = interfaces[i];

        if (!(flags & VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC) &&
128
            (tmp[i] = virXPathString("string(./target/@dev)", ctxt)))
129 130 131 132
            continue;

        /* In case we are dealing with inactive domain XML there's no
         * <target dev=''/>. Offer MAC addresses then. */
133 134
        if (!(tmp[i] = virXPathString("string(./mac/@address)", ctxt)))
            goto cleanup;
135 136
    }

137 138
    VIR_STEAL_PTR(ret, tmp);
 cleanup:
139 140 141
    VIR_FREE(interfaces);
    xmlFreeDoc(xmldoc);
    xmlXPathFreeContext(ctxt);
142
    virStringListFree(tmp);
143 144
    return ret;
}
145 146


147 148 149 150 151 152 153 154 155 156 157
char **
virshDomainDiskTargetCompleter(vshControl *ctl,
                               const vshCmd *cmd,
                               unsigned int flags)
{
    virshControlPtr priv = ctl->privData;
    xmlDocPtr xmldoc = NULL;
    xmlXPathContextPtr ctxt = NULL;
    xmlNodePtr *disks = NULL;
    int ndisks;
    size_t i;
158
    char **tmp = NULL;
159 160 161 162 163 164 165 166
    char **ret = NULL;

    virCheckFlags(0, NULL);

    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
        return NULL;

    if (virshDomainGetXML(ctl, cmd, 0, &xmldoc, &ctxt) < 0)
167
        goto cleanup;
168 169 170

    ndisks = virXPathNodeSet("./devices/disk", ctxt, &disks);
    if (ndisks < 0)
171
        goto cleanup;
172

173 174
    if (VIR_ALLOC_N(tmp, ndisks + 1) < 0)
        goto cleanup;
175 176 177

    for (i = 0; i < ndisks; i++) {
        ctxt->node = disks[i];
178 179
        if (!(tmp[i] = virXPathString("string(./target/@dev)", ctxt)))
            goto cleanup;
180 181
    }

182 183
    VIR_STEAL_PTR(ret, tmp);
 cleanup:
184 185 186
    VIR_FREE(disks);
    xmlFreeDoc(xmldoc);
    xmlXPathFreeContext(ctxt);
187
    virStringListFree(tmp);
188 189 190 191
    return ret;
}


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
char **
virshStoragePoolNameCompleter(vshControl *ctl,
                              const vshCmd *cmd ATTRIBUTE_UNUSED,
                              unsigned int flags)
{
    virshControlPtr priv = ctl->privData;
    virStoragePoolPtr *pools = NULL;
    int npools = 0;
    size_t i = 0;
    char **ret = NULL;

    virCheckFlags(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE |
                  VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE |
                  VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT,
                  NULL);

    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
        return NULL;

    if ((npools = virConnectListAllStoragePools(priv->conn, &pools, flags)) < 0)
        return NULL;

    if (VIR_ALLOC_N(ret, npools + 1) < 0)
        goto error;

    for (i = 0; i < npools; i++) {
        const char *name = virStoragePoolGetName(pools[i]);

        if (VIR_STRDUP(ret[i], name) < 0)
            goto error;

        virStoragePoolFree(pools[i]);
    }
    VIR_FREE(pools);

    return ret;

 error:
    for (; i < npools; i++)
        virStoragePoolFree(pools[i]);
    VIR_FREE(pools);
    for (i = 0; i < npools; i++)
        VIR_FREE(ret[i]);
    VIR_FREE(ret);
    return NULL;
}
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


char **
virshStorageVolNameCompleter(vshControl *ctl,
                             const vshCmd *cmd,
                             unsigned int flags)
{
    virshControlPtr priv = ctl->privData;
    virStoragePoolPtr pool = NULL;
    virStorageVolPtr *vols = NULL;
    int nvols = 0;
    size_t i = 0;
    char **ret = NULL;

    virCheckFlags(0, NULL);

    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
        return NULL;

    if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
        return false;

    if ((nvols = virStoragePoolListAllVolumes(pool, &vols, flags)) < 0)
        goto error;

    if (VIR_ALLOC_N(ret, nvols + 1) < 0)
        goto error;

    for (i = 0; i < nvols; i++) {
        const char *name = virStorageVolGetName(vols[i]);

        if (VIR_STRDUP(ret[i], name) < 0)
            goto error;

        virStorageVolFree(vols[i]);
    }
    VIR_FREE(vols);
    virStoragePoolFree(pool);

    return ret;

 error:
    for (; i < nvols; i++)
        virStorageVolFree(vols[i]);
    VIR_FREE(vols);
    for (i = 0; i < nvols; i++)
        VIR_FREE(ret[i]);
    VIR_FREE(ret);
    virStoragePoolFree(pool);
    return NULL;
}
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


char **
virshInterfaceNameCompleter(vshControl *ctl,
                            const vshCmd *cmd ATTRIBUTE_UNUSED,
                            unsigned int flags)
{
    virshControlPtr priv = ctl->privData;
    virInterfacePtr *ifaces = NULL;
    int nifaces = 0;
    size_t i = 0;
    char **ret = NULL;

    virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE |
                  VIR_CONNECT_LIST_INTERFACES_INACTIVE,
                  NULL);

    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
        return NULL;

    if ((nifaces = virConnectListAllInterfaces(priv->conn, &ifaces, flags)) < 0)
        return NULL;

    if (VIR_ALLOC_N(ret, nifaces + 1) < 0)
        goto error;

    for (i = 0; i < nifaces; i++) {
        const char *name = virInterfaceGetName(ifaces[i]);

        if (VIR_STRDUP(ret[i], name) < 0)
            goto error;

        virInterfaceFree(ifaces[i]);
    }
    VIR_FREE(ifaces);

    return ret;

 error:
    for (; i < nifaces; i++)
        virInterfaceFree(ifaces[i]);
    VIR_FREE(ifaces);
    for (i = 0; i < nifaces; i++)
        VIR_FREE(ret[i]);
    VIR_FREE(ret);
    return NULL;
}
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


char **
virshNetworkNameCompleter(vshControl *ctl,
                          const vshCmd *cmd ATTRIBUTE_UNUSED,
                          unsigned int flags)
{
    virshControlPtr priv = ctl->privData;
    virNetworkPtr *nets = NULL;
    int nnets = 0;
    size_t i = 0;
    char **ret = NULL;

    virCheckFlags(VIR_CONNECT_LIST_NETWORKS_INACTIVE |
                  VIR_CONNECT_LIST_NETWORKS_ACTIVE |
                  VIR_CONNECT_LIST_NETWORKS_PERSISTENT,
                  NULL);

    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
        return NULL;

    if ((nnets = virConnectListAllNetworks(priv->conn, &nets, flags)) < 0)
        return NULL;

    if (VIR_ALLOC_N(ret, nnets + 1) < 0)
        goto error;

    for (i = 0; i < nnets; i++) {
        const char *name = virNetworkGetName(nets[i]);

        if (VIR_STRDUP(ret[i], name) < 0)
            goto error;

        virNetworkFree(nets[i]);
    }
    VIR_FREE(nets);

    return ret;

 error:
    for (; i < nnets; i++)
        virNetworkFree(nets[i]);
    VIR_FREE(nets);
    for (i = 0; i < nnets; i++)
        VIR_FREE(ret[i]);
    VIR_FREE(ret);
    return NULL;
}
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


char **
virshNodeDeviceNameCompleter(vshControl *ctl,
                             const vshCmd *cmd ATTRIBUTE_UNUSED,
                             unsigned int flags)
{
    virshControlPtr priv = ctl->privData;
    virNodeDevicePtr *devs = NULL;
    int ndevs = 0;
    size_t i = 0;
    char **ret = NULL;

    virCheckFlags(0, NULL);

    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
        return NULL;

    if ((ndevs = virConnectListAllNodeDevices(priv->conn, &devs, flags)) < 0)
        return NULL;

    if (VIR_ALLOC_N(ret, ndevs + 1) < 0)
        goto error;

    for (i = 0; i < ndevs; i++) {
        const char *name = virNodeDeviceGetName(devs[i]);

        if (VIR_STRDUP(ret[i], name) < 0)
            goto error;

        virNodeDeviceFree(devs[i]);
    }
    VIR_FREE(devs);

    return ret;

 error:
    for (; i < ndevs; i++)
        virNodeDeviceFree(devs[i]);
    VIR_FREE(devs);
    for (i = 0; i < ndevs; i++)
        VIR_FREE(ret[i]);
    VIR_FREE(ret);
    return NULL;
}
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


char **
virshNWFilterNameCompleter(vshControl *ctl,
                           const vshCmd *cmd ATTRIBUTE_UNUSED,
                           unsigned int flags)
{
    virshControlPtr priv = ctl->privData;
    virNWFilterPtr *nwfilters = NULL;
    int nnwfilters = 0;
    size_t i = 0;
    char **ret = NULL;

    virCheckFlags(0, NULL);

    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
        return NULL;

    if ((nnwfilters = virConnectListAllNWFilters(priv->conn, &nwfilters, flags)) < 0)
        return NULL;

    if (VIR_ALLOC_N(ret, nnwfilters + 1) < 0)
        goto error;

    for (i = 0; i < nnwfilters; i++) {
        const char *name = virNWFilterGetName(nwfilters[i]);

        if (VIR_STRDUP(ret[i], name) < 0)
            goto error;

        virNWFilterFree(nwfilters[i]);
    }
    VIR_FREE(nwfilters);

    return ret;

 error:
    for (; i < nnwfilters; i++)
        virNWFilterFree(nwfilters[i]);
    VIR_FREE(nwfilters);
    for (i = 0; i < nnwfilters; i++)
        VIR_FREE(ret[i]);
    VIR_FREE(ret);
    return NULL;
}
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


char **
virshSecretUUIDCompleter(vshControl *ctl,
                         const vshCmd *cmd ATTRIBUTE_UNUSED,
                         unsigned int flags)
{
    virshControlPtr priv = ctl->privData;
    virSecretPtr *secrets = NULL;
    int nsecrets = 0;
    size_t i = 0;
    char **ret = NULL;

    virCheckFlags(0, NULL);

    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
        return NULL;

    if ((nsecrets = virConnectListAllSecrets(priv->conn, &secrets, flags)) < 0)
        return NULL;

    if (VIR_ALLOC_N(ret, nsecrets + 1) < 0)
        goto error;

    for (i = 0; i < nsecrets; i++) {
        char uuid[VIR_UUID_STRING_BUFLEN];

        if (virSecretGetUUIDString(secrets[i], uuid) < 0 ||
            VIR_STRDUP(ret[i], uuid) < 0)
            goto error;

        virSecretFree(secrets[i]);
    }
    VIR_FREE(secrets);

    return ret;

 error:
    for (; i < nsecrets; i++)
        virSecretFree(secrets[i]);
    VIR_FREE(secrets);
    for (i = 0; i < nsecrets; i++)
        VIR_FREE(ret[i]);
    VIR_FREE(ret);
    return NULL;
}
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


char **
virshSnapshotNameCompleter(vshControl *ctl,
                           const vshCmd *cmd,
                           unsigned int flags)
{
    virshControlPtr priv = ctl->privData;
    virDomainPtr dom = NULL;
    virDomainSnapshotPtr *snapshots = NULL;
    int nsnapshots = 0;
    size_t i = 0;
    char **ret = NULL;

    virCheckFlags(0, NULL);

    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
        return NULL;

    if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
        return NULL;

    if ((nsnapshots = virDomainListAllSnapshots(dom, &snapshots, flags)) < 0)
        goto error;

    if (VIR_ALLOC_N(ret, nsnapshots + 1) < 0)
        goto error;

    for (i = 0; i < nsnapshots; i++) {
        const char *name = virDomainSnapshotGetName(snapshots[i]);

        if (VIR_STRDUP(ret[i], name) < 0)
            goto error;

        virshDomainSnapshotFree(snapshots[i]);
    }
    VIR_FREE(snapshots);
    virshDomainFree(dom);

    return ret;

 error:
    for (; i < nsnapshots; i++)
        virshDomainSnapshotFree(snapshots[i]);
    VIR_FREE(snapshots);
    for (i = 0; i < nsnapshots; i++)
        VIR_FREE(ret[i]);
    VIR_FREE(ret);
    virshDomainFree(dom);
    return NULL;
}
571 572 573 574 575 576 577 578 579 580 581

char **
virshAllocpagesPagesizeCompleter(vshControl *ctl,
                        const vshCmd *cmd ATTRIBUTE_UNUSED,
                        unsigned int flags)
{
    unsigned long long byteval = 0;
    xmlXPathContextPtr ctxt = NULL;
    virshControlPtr priv = ctl->privData;
    unsigned int npages = 0;
    xmlNodePtr *pages = NULL;
582
    xmlDocPtr doc = NULL;
583 584 585
    double size = 0;
    size_t i = 0;
    const char *suffix = NULL;
586 587 588
    const char *cellnum = NULL;
    bool cellno = vshCommandOptBool(cmd, "cellno");
    char *path = NULL;
589 590 591 592 593 594 595 596 597 598 599 600 601
    char *pagesize = NULL;
    char *cap_xml = NULL;
    char **ret = NULL;
    char *unit = NULL;

    virCheckFlags(0, NULL);

    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
        goto error;

    if (!(cap_xml = virConnectGetCapabilities(priv->conn)))
        goto error;

602
    if (!(doc = virXMLParseStringCtxt(cap_xml, _("capabilities"), &ctxt)))
603 604
        goto error;

605 606 607 608 609 610 611 612 613 614 615
    if (cellno && vshCommandOptStringQuiet(ctl, cmd, "cellno", &cellnum) > 0) {
        if (virAsprintf(&path,
                        "/capabilities/host/topology/cells/cell[@id=\"%s\"]/pages",
                        cellnum) < 0)
            goto error;
    } else {
        if (virAsprintf(&path, "/capabilities/host/cpu/pages") < 0)
            goto error;
    }

    npages = virXPathNodeSet(path, ctxt, &pages);
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
    if (npages <= 0)
        goto error;

    if (VIR_ALLOC_N(ret, npages + 1) < 0)
        goto error;

    for (i = 0; i < npages; i++) {
        VIR_FREE(pagesize);
        VIR_FREE(unit);
        pagesize = virXMLPropString(pages[i], "size");
        unit = virXMLPropString(pages[i], "unit");
        if (virStrToLong_ull(pagesize, NULL, 10, &byteval) < 0)
            goto error;
        if (virScaleInteger(&byteval, unit, 1024, UINT_MAX) < 0)
            goto error;
        size = vshPrettyCapacity(byteval, &suffix);
        if (virAsprintf(&ret[i], "%.0f%s", size, suffix) < 0)
            goto error;
    }

 cleanup:
    xmlXPathFreeContext(ctxt);
    VIR_FREE(pages);
639
    xmlFreeDoc(doc);
640
    VIR_FREE(path);
641
    VIR_FREE(pagesize);
642
    VIR_FREE(cap_xml);
643 644 645 646 647 648 649 650 651 652 653 654
    VIR_FREE(unit);

    return ret;

 error:
    if (ret) {
        for (i = 0; i < npages; i++)
            VIR_FREE(ret[i]);
    }
    VIR_FREE(ret);
    goto cleanup;
}
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


char **
virshSecretEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
                              const vshCmd *cmd ATTRIBUTE_UNUSED,
                              unsigned int flags)
{
    size_t i;
    char **ret = NULL;

    virCheckFlags(0, NULL);

    if (VIR_ALLOC_N(ret, VIR_SECRET_EVENT_ID_LAST) < 0)
        goto error;

    for (i = 0; i < VIR_SECRET_EVENT_ID_LAST; i++) {
        if (VIR_STRDUP(ret[i], virshSecretEventCallbacks[i].name) < 0)
            goto error;
    }

    return ret;

 error:
    virStringListFree(ret);
    return NULL;
}
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


char **
virshDomainEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
                              const vshCmd *cmd ATTRIBUTE_UNUSED,
                              unsigned int flags)
{
    size_t i = 0;
    char **ret = NULL;

    virCheckFlags(0, NULL);

    if (VIR_ALLOC_N(ret, VIR_DOMAIN_EVENT_ID_LAST + 1) < 0)
        goto error;

    for (i = 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) {
        if (VIR_STRDUP(ret[i], virshDomainEventCallbacks[i].name) < 0)
            goto error;
    }

    return ret;

 error:
    virStringListFree(ret);
    return NULL;
}
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


char **
virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
                            const vshCmd *cmd ATTRIBUTE_UNUSED,
                            unsigned int flags)
{
    size_t i = 0;
    char **ret = NULL;

    virCheckFlags(0, NULL);

    if (VIR_ALLOC_N(ret, VIR_STORAGE_POOL_EVENT_ID_LAST) < 0)
        goto error;

    for (i = 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++) {
        if (VIR_STRDUP(ret[i], virshPoolEventCallbacks[i].name) < 0)
            goto error;
    }

    return ret;

 error:
    virStringListFree(ret);
    return NULL;
}
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


char **
virshNodedevEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
                               const vshCmd *cmd ATTRIBUTE_UNUSED,
                               unsigned int flags)
{
    size_t i = 0;
    char **ret = NULL;

    virCheckFlags(0, NULL);

    if (VIR_ALLOC_N(ret, VIR_NODE_DEVICE_EVENT_ID_LAST) < 0)
        goto error;

    for (i = 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) {
        if (VIR_STRDUP(ret[i], virshNodedevEventCallbacks[i].name) < 0)
            goto error;
    }

    return ret;

 error:
    virStringListFree(ret);
    return NULL;
}