node_device_driver.c 20.1 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
/*
 * node_device.c: node device enumeration
 *
 * Copyright (C) 2008 Virtual Iron Software, Inc.
 * Copyright (C) 2008 David F. Lively
 *
 * 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: David F. Lively <dlively@virtualiron.com>
 */

#include <config.h>

#include <unistd.h>
#include <errno.h>
28 29
#include <fcntl.h>
#include <time.h>
30 31 32 33

#include "virterror_internal.h"
#include "datatypes.h"
#include "memory.h"
34
#include "logging.h"
35
#include "node_device_conf.h"
36
#include "node_device_hal.h"
37
#include "node_device_driver.h"
D
Daniel P. Berrange 已提交
38
#include "util.h"
39

40 41
#define VIR_FROM_THIS VIR_FROM_NODEDEV

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

static int update_caps(virNodeDeviceObjPtr dev)
{
    virNodeDevCapsDefPtr cap = dev->def->caps;

    while (cap) {
        /* The only cap that currently needs updating is the WWN of FC HBAs. */
        if (cap->type == VIR_NODE_DEV_CAP_SCSI_HOST) {
            if (cap->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {
                if (read_wwn(cap->data.scsi_host.host,
                            "port_name",
                            &cap->data.scsi_host.wwpn) == -1) {
                    VIR_ERROR(_("Failed to refresh WWPN for host%d"),
                              cap->data.scsi_host.host);
                }

                if (read_wwn(cap->data.scsi_host.host,
                            "node_name",
                            &cap->data.scsi_host.wwnn) == -1) {
                    VIR_ERROR(_("Failed to refresh WWNN for host%d"),
                              cap->data.scsi_host.host);
                }
            }
        }
66
        cap = cap->next;
67 68 69 70 71 72
    }

    return 0;
}


73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
#ifdef __linux__
static int update_driver_name(virConnectPtr conn,
                              virNodeDeviceObjPtr dev)
{
    char *driver_link = NULL;
    char devpath[PATH_MAX];
    char *p;
    int ret = -1;
    int n;

    VIR_FREE(dev->def->driver);

    if (virAsprintf(&driver_link, "%s/driver", dev->devicePath) < 0) {
        virReportOOMError(conn);
        goto cleanup;
    }

    /* Some devices don't have an explicit driver, so just return
       without a name */
    if (access(driver_link, R_OK) < 0) {
        ret = 0;
        goto cleanup;
    }

    if ((n = readlink(driver_link, devpath, sizeof devpath)) < 0) {
        virReportSystemError(conn, errno,
                             _("cannot resolve driver link %s"), driver_link);
        goto cleanup;
    }
    devpath[n] = '\0';

    p = strrchr(devpath, '/');
    if (p) {
        dev->def->driver = strdup(p+1);
        if (!dev->def->driver) {
            virReportOOMError(conn);
            goto cleanup;
        }
    }
    ret = 0;

cleanup:
    VIR_FREE(driver_link);
    return ret;
}
#else
/* XXX: Implement me for non-linux */
static int update_driver_name(virConnectPtr conn ATTRIBUTE_UNUSED,
                              virNodeDeviceObjPtr dev ATTRIBUTE_UNUSED)
{
    return 0;
}
#endif

127

128 129
void nodeDeviceLock(virDeviceMonitorStatePtr driver)
{
130
    virMutexLock(&driver->lock);
131 132 133
}
void nodeDeviceUnlock(virDeviceMonitorStatePtr driver)
{
134
    virMutexUnlock(&driver->lock);
135 136
}

137 138 139 140 141 142 143 144
static int nodeNumOfDevices(virConnectPtr conn,
                            const char *cap,
                            unsigned int flags ATTRIBUTE_UNUSED)
{
    virDeviceMonitorStatePtr driver = conn->devMonPrivateData;
    int ndevs = 0;
    unsigned int i;

145 146 147
    nodeDeviceLock(driver);
    for (i = 0; i < driver->devs.count; i++) {
        virNodeDeviceObjLock(driver->devs.objs[i]);
148
        if ((cap == NULL) ||
149
            virNodeDeviceHasCap(driver->devs.objs[i], cap))
150
            ++ndevs;
151 152 153
        virNodeDeviceObjUnlock(driver->devs.objs[i]);
    }
    nodeDeviceUnlock(driver);
154 155 156 157 158 159 160 161 162 163 164 165 166 167

    return ndevs;
}

static int
nodeListDevices(virConnectPtr conn,
                const char *cap,
                char **const names, int maxnames,
                unsigned int flags ATTRIBUTE_UNUSED)
{
    virDeviceMonitorStatePtr driver = conn->devMonPrivateData;
    int ndevs = 0;
    unsigned int i;

168 169 170
    nodeDeviceLock(driver);
    for (i = 0; i < driver->devs.count && ndevs < maxnames; i++) {
        virNodeDeviceObjLock(driver->devs.objs[i]);
171
        if (cap == NULL ||
172
            virNodeDeviceHasCap(driver->devs.objs[i], cap)) {
173 174
            if ((names[ndevs++] = strdup(driver->devs.objs[i]->def->name)) == NULL) {
                virNodeDeviceObjUnlock(driver->devs.objs[i]);
175
                goto failure;
176 177 178 179 180
            }
        }
        virNodeDeviceObjUnlock(driver->devs.objs[i]);
    }
    nodeDeviceUnlock(driver);
181 182 183 184

    return ndevs;

 failure:
185
    nodeDeviceUnlock(driver);
186 187 188 189 190 191 192 193 194 195 196
    --ndevs;
    while (--ndevs >= 0)
        VIR_FREE(names[ndevs]);
    return -1;
}


static virNodeDevicePtr nodeDeviceLookupByName(virConnectPtr conn,
                                               const char *name)
{
    virDeviceMonitorStatePtr driver = conn->devMonPrivateData;
197 198
    virNodeDeviceObjPtr obj;
    virNodeDevicePtr ret = NULL;
199

200
    nodeDeviceLock(driver);
201
    obj = virNodeDeviceFindByName(&driver->devs, name);
202 203
    nodeDeviceUnlock(driver);

204
    if (!obj) {
205
        virNodeDeviceReportError(conn, VIR_ERR_NO_NODE_DEVICE, NULL);
206
        goto cleanup;
207 208
    }

209
    ret = virGetNodeDevice(conn, name);
210

211
cleanup:
212 213
    if (obj)
        virNodeDeviceObjUnlock(obj);
214
    return ret;
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

static virNodeDevicePtr
nodeDeviceLookupByWWN(virConnectPtr conn,
                      const char *wwnn,
                      const char *wwpn)
{
    unsigned int i;
    virDeviceMonitorStatePtr driver = conn->devMonPrivateData;
    virNodeDeviceObjListPtr devs = &driver->devs;
    virNodeDevCapsDefPtr cap = NULL;
    virNodeDeviceObjPtr obj = NULL;
    virNodeDevicePtr dev = NULL;

    nodeDeviceLock(driver);

    for (i = 0; i < devs->count; i++) {

        obj = devs->objs[i];
        virNodeDeviceObjLock(obj);
        cap = obj->def->caps;

        while (cap) {

            if (cap->type == VIR_NODE_DEV_CAP_SCSI_HOST) {
                if (cap->data.scsi_host.flags &
                    VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {

                    if (STREQ(cap->data.scsi_host.wwnn, wwnn) &&
                        STREQ(cap->data.scsi_host.wwpn, wwpn)) {
                        dev = virGetNodeDevice(conn, obj->def->name);
                        virNodeDeviceObjUnlock(obj);
                        goto out;
                    }
                }
            }
            cap = cap->next;
        }

        virNodeDeviceObjUnlock(obj);
    }

out:
    nodeDeviceUnlock(driver);
    return dev;
}


264 265 266 267
static char *nodeDeviceDumpXML(virNodeDevicePtr dev,
                               unsigned int flags ATTRIBUTE_UNUSED)
{
    virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData;
268 269
    virNodeDeviceObjPtr obj;
    char *ret = NULL;
270

271
    nodeDeviceLock(driver);
272
    obj = virNodeDeviceFindByName(&driver->devs, dev->name);
273 274
    nodeDeviceUnlock(driver);

275
    if (!obj) {
276 277 278
        virNodeDeviceReportError(dev->conn, VIR_ERR_NO_NODE_DEVICE,
                                _("no node device with matching name '%s'"),
                                 dev->name);
279
        goto cleanup;
280 281
    }

282
    update_driver_name(dev->conn, obj);
283 284
    update_caps(obj);

285 286 287
    ret = virNodeDeviceDefFormat(dev->conn, obj->def);

cleanup:
288 289
    if (obj)
        virNodeDeviceObjUnlock(obj);
290
    return ret;
291 292 293 294 295 296
}


static char *nodeDeviceGetParent(virNodeDevicePtr dev)
{
    virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData;
297 298
    virNodeDeviceObjPtr obj;
    char *ret = NULL;
299

300
    nodeDeviceLock(driver);
301
    obj = virNodeDeviceFindByName(&driver->devs, dev->name);
302 303
    nodeDeviceUnlock(driver);

304
    if (!obj) {
305 306 307
        virNodeDeviceReportError(dev->conn, VIR_ERR_NO_NODE_DEVICE,
                                _("no node device with matching name '%s'"),
                                 dev->name);
308
        goto cleanup;
309 310
    }

311 312 313 314 315 316 317 318
    if (obj->def->parent) {
        ret = strdup(obj->def->parent);
        if (!ret)
            virReportOOMError(dev->conn);
    } else {
        virNodeDeviceReportError(dev->conn, VIR_ERR_INTERNAL_ERROR,
                                 "%s", _("no parent for this device"));
    }
319 320

cleanup:
321 322
    if (obj)
        virNodeDeviceObjUnlock(obj);
323
    return ret;
324 325 326 327 328 329
}


static int nodeDeviceNumOfCaps(virNodeDevicePtr dev)
{
    virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData;
330
    virNodeDeviceObjPtr obj;
331 332
    virNodeDevCapsDefPtr caps;
    int ncaps = 0;
333
    int ret = -1;
334

335
    nodeDeviceLock(driver);
336
    obj = virNodeDeviceFindByName(&driver->devs, dev->name);
337 338
    nodeDeviceUnlock(driver);

339
    if (!obj) {
340 341 342
        virNodeDeviceReportError(dev->conn, VIR_ERR_NO_NODE_DEVICE,
                                _("no node device with matching name '%s'"),
                                 dev->name);
343
        goto cleanup;
344 345 346 347
    }

    for (caps = obj->def->caps; caps; caps = caps->next)
        ++ncaps;
348
    ret = ncaps;
349

350
cleanup:
351 352
    if (obj)
        virNodeDeviceObjUnlock(obj);
353
    return ret;
354 355 356 357 358 359 360
}


static int
nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames)
{
    virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData;
361
    virNodeDeviceObjPtr obj;
362 363
    virNodeDevCapsDefPtr caps;
    int ncaps = 0;
364
    int ret = -1;
365

366
    nodeDeviceLock(driver);
367
    obj = virNodeDeviceFindByName(&driver->devs, dev->name);
368 369
    nodeDeviceUnlock(driver);

370
    if (!obj) {
371 372 373
        virNodeDeviceReportError(dev->conn, VIR_ERR_NO_NODE_DEVICE,
                                _("no node device with matching name '%s'"),
                                 dev->name);
374
        goto cleanup;
375 376 377 378 379
    }

    for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) {
        names[ncaps] = strdup(virNodeDevCapTypeToString(caps->type));
        if (names[ncaps++] == NULL)
380
            goto cleanup;
381
    }
382
    ret = ncaps;
383

384
cleanup:
385 386
    if (obj)
        virNodeDeviceObjUnlock(obj);
387 388 389 390 391 392
    if (ret == -1) {
        --ncaps;
        while (--ncaps >= 0)
            VIR_FREE(names[ncaps]);
    }
    return ret;
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
static int
nodeDeviceVportCreateDelete(virConnectPtr conn,
                            const int parent_host,
                            const char *wwpn,
                            const char *wwnn,
                            int operation)
{
    int retval = 0;
    char *operation_path = NULL, *vport_name = NULL;
    const char *operation_file = NULL;

    switch (operation) {
    case VPORT_CREATE:
        operation_file = LINUX_SYSFS_VPORT_CREATE_POSTFIX;
        break;
    case VPORT_DELETE:
        operation_file = LINUX_SYSFS_VPORT_DELETE_POSTFIX;
        break;
    default:
        virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR,
                                 _("Invalid vport operation (%d)"), operation);
        retval = -1;
        goto cleanup;
        break;
    }

    if (virAsprintf(&operation_path,
                    "%shost%d%s",
                    LINUX_SYSFS_FC_HOST_PREFIX,
                    parent_host,
                    operation_file) < 0) {

        virReportOOMError(conn);
        retval = -1;
        goto cleanup;
    }

    VIR_DEBUG(_("Vport operation path is '%s'"), operation_path);

    if (virAsprintf(&vport_name,
                    "%s:%s",
                    wwpn,
                    wwnn) < 0) {

        virReportOOMError(conn);
        retval = -1;
        goto cleanup;
    }

    if (virFileWriteStr(operation_path, vport_name) == -1) {
        virReportSystemError(conn, errno,
                             _("Write of '%s' to '%s' during "
                               "vport create/delete failed"),
                             vport_name, operation_path);
        retval = -1;
    }

cleanup:
    VIR_FREE(vport_name);
    VIR_FREE(operation_path);
    VIR_DEBUG("%s", _("Vport operation complete"));
    return retval;
}


static int
get_wwns(virConnectPtr conn,
         virNodeDeviceDefPtr def,
         char **wwnn,
         char **wwpn)
{
    virNodeDevCapsDefPtr cap = NULL;
    int ret = 0;

    cap = def->caps;
    while (cap != NULL) {
        if (cap->type == VIR_NODE_DEV_CAP_SCSI_HOST &&
            cap->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {
            *wwnn = strdup(cap->data.scsi_host.wwnn);
            *wwpn = strdup(cap->data.scsi_host.wwpn);
            break;
        }

        cap = cap->next;
    }

    if (cap == NULL) {
        virNodeDeviceReportError(conn, VIR_ERR_NO_SUPPORT,
                                 "%s", _("Device is not a fibre channel HBA"));
        ret = -1;
    }

    if (*wwnn == NULL || *wwpn == NULL) {
        /* Free the other one, if allocated... */
        VIR_FREE(wwnn);
        VIR_FREE(wwpn);
        ret = -1;
        virReportOOMError(conn);
    }

    return ret;
}


static int
get_parent_host(virConnectPtr conn,
                virDeviceMonitorStatePtr driver,
                const char *dev_name,
                const char *parent_name,
                int *parent_host)
{
    virNodeDeviceObjPtr parent = NULL;
    virNodeDevCapsDefPtr cap = NULL;
    int ret = 0;

    parent = virNodeDeviceFindByName(&driver->devs, parent_name);
    if (parent == NULL) {
        virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR,
                                 _("Could not find parent HBA for '%s'"),
                                 dev_name);
        ret = -1;
        goto out;
    }

    cap = parent->def->caps;
    while (cap != NULL) {
        if (cap->type == VIR_NODE_DEV_CAP_SCSI_HOST &&
            (cap->data.scsi_host.flags &
             VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS)) {
                *parent_host = cap->data.scsi_host.host;
                break;
        }

        cap = cap->next;
    }

    if (cap == NULL) {
        virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR,
                                 _("Parent HBA %s is not capable "
                                   "of vport operations"),
                                 parent->def->name);
        ret = -1;
    }

    virNodeDeviceObjUnlock(parent);

out:
    return ret;
}


static int
get_time(virConnectPtr conn, time_t *t)
{
    int ret = 0;

    *t = time(NULL);
    if (*t == (time_t)-1) {
        virNodeDeviceReportError(conn, VIR_ERR_INTERNAL_ERROR,
                                 "%s", _("Could not get current time"));

        *t = 0;
        ret = -1;
    }

    return ret;
}


/* When large numbers of devices are present on the host, it's
 * possible for udev not to realize that it has work to do before we
 * get here.  We thus keep trying to find the new device we just
 * created for up to LINUX_NEW_DEVICE_WAIT_TIME.  Note that udev's
 * default settle time is 180 seconds, so once udev realizes that it
 * has work to do, it might take that long for the udev wait to
 * return.  Thus the total maximum time for this function to return is
 * the udev settle time plus LINUX_NEW_DEVICE_WAIT_TIME.
 *
 * This whole area is a race, but if we retry the udev wait for
 * LINUX_NEW_DEVICE_WAIT_TIME seconds and there's still no device,
 * it's probably safe to assume it's not going to appear.
 */
static virNodeDevicePtr
find_new_device(virConnectPtr conn, const char *wwnn, const char *wwpn)
{
    virDeviceMonitorStatePtr driver = conn->devMonPrivateData;
    virNodeDevicePtr dev = NULL;
    time_t start = 0, now = 0;

    /* The thread that creates the device takes the driver lock, so we
     * must release it in order to allow the device to be created.
     * We're not doing anything with the driver pointer at this point,
     * so it's safe to release it, assuming that the pointer itself
     * doesn't become invalid.  */
    nodeDeviceUnlock(driver);

    get_time(conn, &start);

    while ((now - start) < LINUX_NEW_DEVICE_WAIT_TIME) {

D
Daniel P. Berrange 已提交
596
        virFileWaitForDevices(conn);
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

        dev = nodeDeviceLookupByWWN(conn, wwnn, wwpn);

        if (dev != NULL) {
            break;
        }

        sleep(5);
        if (get_time(conn, &now) == -1) {
            break;
        }
    }

    nodeDeviceLock(driver);

    return dev;
}

static virNodeDevicePtr
nodeDeviceCreateXML(virConnectPtr conn,
                    const char *xmlDesc,
                    unsigned int flags ATTRIBUTE_UNUSED)
{
    virDeviceMonitorStatePtr driver = conn->devMonPrivateData;
    virNodeDeviceDefPtr def = NULL;
    char *wwnn = NULL, *wwpn = NULL;
    int parent_host = -1;
    virNodeDevicePtr dev = NULL;

    nodeDeviceLock(driver);

    def = virNodeDeviceDefParseString(conn, xmlDesc, CREATE_DEVICE);
    if (def == NULL) {
        goto cleanup;
    }

    if (get_wwns(conn, def, &wwnn, &wwpn) == -1) {
        goto cleanup;
    }

    if (get_parent_host(conn,
                        driver,
                        def->name,
                        def->parent,
                        &parent_host) == -1) {
        goto cleanup;
    }

    if (nodeDeviceVportCreateDelete(conn,
                                    parent_host,
                                    wwpn,
                                    wwnn,
                                    VPORT_CREATE) == -1) {
        goto cleanup;
    }

    dev = find_new_device(conn, wwnn, wwpn);
    /* We don't check the return value, because one way or another,
     * we're returning what we get... */

    if (dev == NULL) {
        virNodeDeviceReportError(conn, VIR_ERR_NO_NODE_DEVICE, NULL);
    }

cleanup:
    nodeDeviceUnlock(driver);
    virNodeDeviceDefFree(def);
    VIR_FREE(wwnn);
    VIR_FREE(wwpn);
    return dev;
}


static int
nodeDeviceDestroy(virNodeDevicePtr dev)
{
    int ret = 0;
    virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData;
    virNodeDeviceObjPtr obj = NULL;
    char *parent_name = NULL, *wwnn = NULL, *wwpn = NULL;
    int parent_host = -1;

    nodeDeviceLock(driver);
    obj = virNodeDeviceFindByName(&driver->devs, dev->name);
    nodeDeviceUnlock(driver);

    if (!obj) {
        virNodeDeviceReportError(dev->conn, VIR_ERR_NO_NODE_DEVICE, NULL);
        goto out;
    }

    if (get_wwns(dev->conn, obj->def, &wwnn, &wwpn) == -1) {
        goto out;
    }

    parent_name = strdup(obj->def->parent);

    /* get_parent_host will cause the device object's lock to be
     * taken, so we have to dup the parent's name and drop the lock
     * before calling it.  We don't need the reference to the object
     * any more once we have the parent's name.  */
    virNodeDeviceObjUnlock(obj);
    obj = NULL;

    if (parent_name == NULL) {
        virReportOOMError(dev->conn);
        goto out;
    }

    if (get_parent_host(dev->conn,
                        driver,
                        dev->name,
                        parent_name,
                        &parent_host) == -1) {
        goto out;
    }

    if (nodeDeviceVportCreateDelete(dev->conn,
                                    parent_host,
                                    wwpn,
                                    wwnn,
                                    VPORT_DELETE) == -1) {
        goto out;
    }

out:
723 724
    if (obj)
        virNodeDeviceObjUnlock(obj);
725 726 727 728 729 730 731
    VIR_FREE(parent_name);
    VIR_FREE(wwnn);
    VIR_FREE(wwpn);
    return ret;
}


732 733 734 735 736 737 738 739 740
void registerCommonNodeFuncs(virDeviceMonitorPtr driver)
{
    driver->numOfDevices = nodeNumOfDevices;
    driver->listDevices = nodeListDevices;
    driver->deviceLookupByName = nodeDeviceLookupByName;
    driver->deviceDumpXML = nodeDeviceDumpXML;
    driver->deviceGetParent = nodeDeviceGetParent;
    driver->deviceNumOfCaps = nodeDeviceNumOfCaps;
    driver->deviceListCaps = nodeDeviceListCaps;
741 742
    driver->deviceCreateXML = nodeDeviceCreateXML;
    driver->deviceDestroy = nodeDeviceDestroy;
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
}


int nodedevRegister(void) {
#if defined(HAVE_HAL) && defined(HAVE_DEVKIT)
    /* Register only one of these two - they conflict */
    if (halNodeRegister() == -1)
        return devkitNodeRegister();
    return 0;
#else
#ifdef HAVE_HAL
    return halNodeRegister();
#endif
#ifdef HAVE_DEVKIT
    return devkitNodeRegister();
#endif
#endif
}