storage_backend_scsi.c 20.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * storage_backend_scsi.c: storage backend for SCSI handling
 *
 * Copyright (C) 2007-2008 Red Hat, Inc.
 * Copyright (C) 2007-2008 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
18
 * License along with this library.  If not, see
O
Osier Yang 已提交
19
 * <http://www.gnu.org/licenses/>.
20 21 22 23 24 25 26 27 28 29 30
 *
 * Author: Daniel P. Berrange <berrange redhat com>
 */

#include <config.h>

#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <fcntl.h>

31
#include "virerror.h"
32
#include "storage_backend_scsi.h"
33
#include "viralloc.h"
34
#include "virlog.h"
E
Eric Blake 已提交
35
#include "virfile.h"
36
#include "vircommand.h"
37
#include "virstring.h"
38 39 40 41 42 43 44 45

#define VIR_FROM_THIS VIR_FROM_STORAGE

/* Function to check if the type file in the given sysfs_path is a
 * Direct-Access device (i.e. type 0).  Return -1 on failure, type of
 * the device otherwise.
 */
static int
46
getDeviceType(uint32_t host,
47 48 49 50 51 52 53 54 55 56 57 58 59
              uint32_t bus,
              uint32_t target,
              uint32_t lun,
              int *type)
{
    char *type_path = NULL;
    char typestr[3];
    char *gottype, *p;
    FILE *typefile;
    int retval = 0;

    if (virAsprintf(&type_path, "/sys/bus/scsi/devices/%u:%u:%u:%u/type",
                    host, bus, target, lun) < 0) {
60
        virReportOOMError();
61 62 63 64 65
        goto out;
    }

    typefile = fopen(type_path, "r");
    if (typefile == NULL) {
66
        virReportSystemError(errno,
67 68 69 70 71 72 73 74
                             _("Could not find typefile '%s'"),
                             type_path);
        /* there was no type file; that doesn't seem right */
        retval = -1;
        goto out;
    }

    gottype = fgets(typestr, 3, typefile);
75
    VIR_FORCE_FCLOSE(typefile);
76 77

    if (gottype == NULL) {
78
        virReportSystemError(errno,
79 80 81 82 83 84 85 86 87 88 89
                             _("Could not read typefile '%s'"),
                             type_path);
        /* we couldn't read the type file; have to give up */
        retval = -1;
        goto out;
    }

    /* we don't actually care about p, but if you pass NULL and the last
     * character is not \0, virStrToLong_i complains
     */
    if (virStrToLong_i(typestr, &p, 10, type) < 0) {
90 91 92
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("Device type '%s' is not an integer"),
                       typestr);
93 94 95 96 97
        /* Hm, type wasn't an integer; seems strange */
        retval = -1;
        goto out;
    }

98
    VIR_DEBUG("Device type is %d", *type);
99 100 101 102 103 104

out:
    VIR_FREE(type_path);
    return retval;
}

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
struct diskType {
    int part_table_type;
    unsigned short offset;
    unsigned short length;
    unsigned long long magic;
};

static struct diskType const disk_types[] = {
    { VIR_STORAGE_POOL_DISK_LVM2, 0x218, 8, 0x31303020324D564CULL },
    { VIR_STORAGE_POOL_DISK_GPT,  0x200, 8, 0x5452415020494645ULL },
    { VIR_STORAGE_POOL_DISK_DVH,  0x0,   4, 0x41A9E50BULL },
    { VIR_STORAGE_POOL_DISK_MAC,  0x0,   2, 0x5245ULL },
    { VIR_STORAGE_POOL_DISK_BSD,  0x40,  4, 0x82564557ULL },
    { VIR_STORAGE_POOL_DISK_SUN,  0x1fc, 2, 0xBEDAULL },
    /*
     * NOTE: pc98 is funky; the actual signature is 0x55AA (just like dos), so
     * we can't use that.  At the moment I'm relying on the "dummy" IPL
     * bootloader data that comes from parted.  Luckily, the chances of running
     * into a pc98 machine running libvirt are approximately nil.
     */
    /*{ 0x1fe, 2, 0xAA55UL },*/
    { VIR_STORAGE_POOL_DISK_PC98, 0x0,   8, 0x314C5049000000CBULL },
    /*
     * NOTE: the order is important here; some other disk types (like GPT and
     * and PC98) also have 0x55AA at this offset.  For that reason, the DOS
     * one must be the last one.
     */
    { VIR_STORAGE_POOL_DISK_DOS,  0x1fe, 2, 0xAA55ULL },
    { -1,                         0x0,   0, 0x0ULL },
};

static int
137
virStorageBackendSCSIUpdateVolTargetInfo(virStorageVolTargetPtr target,
138 139 140
                                         unsigned long long *allocation,
                                         unsigned long long *capacity)
{
141 142
    int fdret, fd = -1;
    int ret = -1;
143

144 145 146
    if ((fdret = virStorageBackendVolOpen(target->path)) < 0)
        goto cleanup;
    fd = fdret;
147

148
    if (virStorageBackendUpdateVolTargetInfoFD(target,
149 150 151
                                               fd,
                                               allocation,
                                               capacity) < 0)
152
        goto cleanup;
153

154
    if (virStorageBackendDetectBlockVolFormatFD(target, fd) < 0)
155
        goto cleanup;
156

157 158
    ret = 0;

159
cleanup:
160
    VIR_FORCE_CLOSE(fd);
161 162

    return ret;
163
}
164

165 166 167 168 169

static char *
virStorageBackendSCSISerial(const char *dev)
{
    char *serial = NULL;
170
#ifdef WITH_UDEV
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
    virCommandPtr cmd = virCommandNewArgList(
        "/lib/udev/scsi_id",
        "--replace-whitespace",
        "--whitelisted",
        "--device", dev,
        NULL
        );

    /* Run the program and capture its output */
    virCommandSetOutputBuffer(cmd, &serial);
    if (virCommandRun(cmd, NULL) < 0)
        goto cleanup;
#endif

    if (serial && STRNEQ(serial, "")) {
        char *nl = strchr(serial, '\n');
        if (nl)
            *nl = '\0';
    } else {
        VIR_FREE(serial);
        if (!(serial = strdup(dev)))
            virReportOOMError();
    }

195
#ifdef WITH_UDEV
196 197 198 199 200 201 202 203
cleanup:
    virCommandFree(cmd);
#endif

    return serial;
}


204
static int
205
virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
206
                            uint32_t host ATTRIBUTE_UNUSED,
207 208 209 210 211 212 213 214 215 216
                            uint32_t bus,
                            uint32_t target,
                            uint32_t lun,
                            const char *dev)
{
    virStorageVolDefPtr vol;
    char *devpath = NULL;
    int retval = 0;

    if (VIR_ALLOC(vol) < 0) {
217
        virReportOOMError();
218 219 220 221 222 223
        retval = -1;
        goto out;
    }

    vol->type = VIR_STORAGE_VOL_BLOCK;

224 225 226 227 228 229
    /* 'host' is dynamically allocated by the kernel, first come,
     * first served, per HBA. As such it isn't suitable for use
     * in the volume name. We only need uniqueness per-pool, so
     * just leave 'host' out
     */
    if (virAsprintf(&(vol->name), "unit:%u:%u:%u", bus, target, lun) < 0) {
230
        virReportOOMError();
231 232 233 234 235
        retval = -1;
        goto free_vol;
    }

    if (virAsprintf(&devpath, "/dev/%s", dev) < 0) {
236
        virReportOOMError();
237 238 239 240
        retval = -1;
        goto free_vol;
    }

241
    VIR_DEBUG("Trying to create volume for '%s'", devpath);
242 243 244 245 246 247 248

    /* Now figure out the stable path
     *
     * XXX this method is O(N) because it scans the pool target
     * dir every time its run. Should figure out a more efficient
     * way of doing this...
     */
249
    if ((vol->target.path = virStorageBackendStablePath(pool,
250 251
                                                        devpath,
                                                        true)) == NULL) {
252 253 254 255
        retval = -1;
        goto free_vol;
    }

256
    if (STREQ(devpath, vol->target.path) &&
257 258 259
        !(STREQ(pool->def->target.path, "/dev") ||
          STREQ(pool->def->target.path, "/dev/"))) {

260
        VIR_DEBUG("No stable path found for '%s' in '%s'",
261 262 263 264 265 266
                  devpath, pool->def->target.path);

        retval = -1;
        goto free_vol;
    }

267
    if (virStorageBackendSCSIUpdateVolTargetInfo(&vol->target,
268 269
                                                 &vol->allocation,
                                                 &vol->capacity) < 0) {
270

271 272 273
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("Failed to update volume for '%s'"),
                       devpath);
274 275 276 277
        retval = -1;
        goto free_vol;
    }

278
    if (!(vol->key = virStorageBackendSCSISerial(vol->target.path))) {
279 280 281 282 283 284 285 286 287
        retval = -1;
        goto free_vol;
    }

    pool->def->capacity += vol->capacity;
    pool->def->allocation += vol->allocation;

    if (VIR_REALLOC_N(pool->volumes.objs,
                      pool->volumes.count + 1) < 0) {
288
        virReportOOMError();
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
        retval = -1;
        goto free_vol;
    }
    pool->volumes.objs[pool->volumes.count++] = vol;

    goto out;

free_vol:
    virStorageVolDefFree(vol);
out:
    VIR_FREE(devpath);
    return retval;
}


static int
305
getNewStyleBlockDevice(const char *lun_path,
306 307 308 309 310 311 312 313 314
                       const char *block_name ATTRIBUTE_UNUSED,
                       char **block_device)
{
    char *block_path = NULL;
    DIR *block_dir = NULL;
    struct dirent *block_dirent = NULL;
    int retval = 0;

    if (virAsprintf(&block_path, "%s/block", lun_path) < 0) {
315
        virReportOOMError();
316 317 318
        goto out;
    }

319
    VIR_DEBUG("Looking for block device in '%s'", block_path);
320 321 322

    block_dir = opendir(block_path);
    if (block_dir == NULL) {
323
        virReportSystemError(errno,
324 325 326 327 328 329 330 331 332 333 334 335 336
                             _("Failed to opendir sysfs path '%s'"),
                             block_path);
        retval = -1;
        goto out;
    }

    while ((block_dirent = readdir(block_dir))) {

        if (STREQLEN(block_dirent->d_name, ".", 1)) {
            continue;
        }

        *block_device = strdup(block_dirent->d_name);
337 338

        if (*block_device == NULL) {
339
            virReportOOMError();
340 341 342 343 344
            closedir(block_dir);
            retval = -1;
            goto out;
        }

345
        VIR_DEBUG("Block device is '%s'", *block_device);
346 347 348 349 350 351 352 353 354 355 356 357 358

        break;
    }

    closedir(block_dir);

out:
    VIR_FREE(block_path);
    return retval;
}


static int
359
getOldStyleBlockDevice(const char *lun_path ATTRIBUTE_UNUSED,
360 361 362 363 364 365 366 367 368 369
                       const char *block_name,
                       char **block_device)
{
    char *blockp = NULL;
    int retval = 0;

    /* old-style; just parse out the sd */
    blockp = strrchr(block_name, ':');
    if (blockp == NULL) {
        /* Hm, wasn't what we were expecting; have to give up */
370 371 372
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("Failed to parse block name %s"),
                       block_name);
373 374 375 376 377
        retval = -1;
    } else {
        blockp++;
        *block_device = strdup(blockp);

378
        if (*block_device == NULL) {
379
            virReportOOMError();
380 381 382 383
            retval = -1;
            goto out;
        }

384
        VIR_DEBUG("Block device is '%s'", *block_device);
385 386
    }

387
out:
388 389 390 391 392
    return retval;
}


static int
393
getBlockDevice(uint32_t host,
394 395 396 397 398 399 400 401 402 403 404 405
               uint32_t bus,
               uint32_t target,
               uint32_t lun,
               char **block_device)
{
    char *lun_path = NULL;
    DIR *lun_dir = NULL;
    struct dirent *lun_dirent = NULL;
    int retval = 0;

    if (virAsprintf(&lun_path, "/sys/bus/scsi/devices/%u:%u:%u:%u",
                    host, bus, target, lun) < 0) {
406
        virReportOOMError();
407 408 409 410 411
        goto out;
    }

    lun_dir = opendir(lun_path);
    if (lun_dir == NULL) {
412
        virReportSystemError(errno,
413 414 415 416 417 418 419 420 421
                             _("Failed to opendir sysfs path '%s'"),
                             lun_path);
        retval = -1;
        goto out;
    }

    while ((lun_dirent = readdir(lun_dir))) {
        if (STREQLEN(lun_dirent->d_name, "block", 5)) {
            if (strlen(lun_dirent->d_name) == 5) {
422
                retval = getNewStyleBlockDevice(lun_path,
423 424 425
                                                lun_dirent->d_name,
                                                block_device);
            } else {
426
                retval = getOldStyleBlockDevice(lun_path,
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
                                                lun_dirent->d_name,
                                                block_device);
            }
            break;
        }
    }

    closedir(lun_dir);

out:
    VIR_FREE(lun_path);
    return retval;
}


static int
443
processLU(virStoragePoolObjPtr pool,
444 445 446 447 448 449 450 451 452 453
          uint32_t host,
          uint32_t bus,
          uint32_t target,
          uint32_t lun)
{
    char *type_path = NULL;
    int retval = 0;
    int device_type;
    char *block_device = NULL;

454
    VIR_DEBUG("Processing LU %u:%u:%u:%u",
455 456
              host, bus, target, lun);

457
    if (getDeviceType(host, bus, target, lun, &device_type) < 0) {
458 459 460
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("Failed to determine if %u:%u:%u:%u is a Direct-Access LUN"),
                       host, bus, target, lun);
461 462 463 464 465 466 467 468 469 470 471 472 473 474
        retval = -1;
        goto out;
    }

    /* We don't create volumes for devices other than disk and cdrom
     * devices, but finding a device that isn't one of those types
     * isn't an error, either. */
    if (!(device_type == VIR_STORAGE_DEVICE_TYPE_DISK ||
          device_type == VIR_STORAGE_DEVICE_TYPE_ROM))
    {
        retval = 0;
        goto out;
    }

475
    VIR_DEBUG("%u:%u:%u:%u is a Direct-Access LUN",
476 477
              host, bus, target, lun);

478
    if (getBlockDevice(host, bus, target, lun, &block_device) < 0) {
479 480 481
        goto out;
    }

482
    if (virStorageBackendSCSINewLun(pool,
483 484
                                    host, bus, target, lun,
                                    block_device) < 0) {
485
        VIR_DEBUG("Failed to create new storage volume for %u:%u:%u:%u",
486 487 488 489 490
                  host, bus, target, lun);
        retval = -1;
        goto out;
    }

491
    VIR_DEBUG("Created new storage volume for %u:%u:%u:%u successfully",
492 493 494 495 496
              host, bus, target, lun);

    VIR_FREE(type_path);

out:
497
    VIR_FREE(block_device);
498 499 500 501 502
    return retval;
}


int
503
virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
504 505 506 507 508 509 510 511 512
                             uint32_t scanhost)
{
    int retval = 0;
    uint32_t bus, target, lun;
    char *device_path = NULL;
    DIR *devicedir = NULL;
    struct dirent *lun_dirent = NULL;
    char devicepattern[64];

513
    VIR_DEBUG("Discovering LUs on host %u", scanhost);
514

515
    virFileWaitForDevices();
516 517

    if (virAsprintf(&device_path, "/sys/bus/scsi/devices") < 0) {
518
        virReportOOMError();
519 520 521 522 523 524
        goto out;
    }

    devicedir = opendir(device_path);

    if (devicedir == NULL) {
525
        virReportSystemError(errno,
526 527 528 529 530 531 532 533 534 535 536 537 538
                             _("Failed to opendir path '%s'"), device_path);
        retval = -1;
        goto out;
    }

    snprintf(devicepattern, sizeof(devicepattern), "%u:%%u:%%u:%%u\n", scanhost);

    while ((lun_dirent = readdir(devicedir))) {
        if (sscanf(lun_dirent->d_name, devicepattern,
                   &bus, &target, &lun) != 3) {
            continue;
        }

539
        VIR_DEBUG("Found LU '%s'", lun_dirent->d_name);
540

541
        processLU(pool, scanhost, bus, target, lun);
542 543 544 545 546 547 548 549 550
    }

    closedir(devicedir);

out:
    VIR_FREE(device_path);
    return retval;
}

551
static int
552
virStorageBackendSCSITriggerRescan(uint32_t host)
553 554 555 556 557
{
    int fd = -1;
    int retval = 0;
    char *path;

558
    VIR_DEBUG("Triggering rescan of host %d", host);
559 560

    if (virAsprintf(&path, "/sys/class/scsi_host/host%u/scan", host) < 0) {
561
        virReportOOMError();
562 563 564 565
        retval = -1;
        goto out;
    }

566
    VIR_DEBUG("Scan trigger path is '%s'", path);
567 568 569 570

    fd = open(path, O_WRONLY);

    if (fd < 0) {
571
        virReportSystemError(errno,
572 573 574 575 576 577 578 579 580
                             _("Could not open '%s' to trigger host scan"),
                             path);
        retval = -1;
        goto free_path;
    }

    if (safewrite(fd,
                  LINUX_SYSFS_SCSI_HOST_SCAN_STRING,
                  sizeof(LINUX_SYSFS_SCSI_HOST_SCAN_STRING)) < 0) {
581
        VIR_FORCE_CLOSE(fd);
582
        virReportSystemError(errno,
583 584 585 586 587
                             _("Write to '%s' to trigger host scan failed"),
                             path);
        retval = -1;
    }

588
    VIR_FORCE_CLOSE(fd);
589 590 591
free_path:
    VIR_FREE(path);
out:
592
    VIR_DEBUG("Rescan of host %d complete", host);
593 594 595
    return retval;
}

596 597 598 599 600 601 602 603 604 605 606
static int
getHostNumber(const char *adapter_name,
              unsigned int *result)
{
    char *host = (char *)adapter_name;

    /* Specifying adapter like 'host5' is still supported for
     * back-compat reason.
     */
    if (STRPREFIX(host, "scsi_host")) {
        host += strlen("scsi_host");
607 608
    } else if (STRPREFIX(host, "fc_host")) {
        host += strlen("fc_host");
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
    } else if (STRPREFIX(host, "host")) {
        host += strlen("host");
    } else {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("Invalid adapter name '%s' for SCSI pool"),
                       adapter_name);
        return -1;
    }

    if (result && virStrToLong_ui(host, NULL, 10, result) == -1) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("Invalid adapter name '%s' for SCSI pool"),
                       adapter_name);
        return -1;
    }

    return 0;
}

628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
static char *
getAdapterName(virStoragePoolSourceAdapter adapter)
{
    char *name = NULL;

    if (adapter.type != VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST)
        return strdup(adapter.data.name);

    if (!(name = virGetFCHostNameByWWN(NULL,
                                       adapter.data.fchost.wwnn,
                                       adapter.data.fchost.wwpn))) {
        virReportError(VIR_ERR_XML_ERROR,
                       _("Failed to find SCSI host with wwnn='%s', "
                         "wwpn='%s'"), adapter.data.fchost.wwnn,
                       adapter.data.fchost.wwpn);
    }

    return name;
}

648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
static int
createVport(virStoragePoolSourceAdapter adapter)
{
    unsigned int parent_host;
    char *name = NULL;

    if (adapter.type != VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST)
        return 0;

    /* This filters either HBA or already created vHBA */
    if ((name = virGetFCHostNameByWWN(NULL, adapter.data.fchost.wwnn,
                                      adapter.data.fchost.wwpn))) {
        VIR_FREE(name);
        return 0;
    }

664 665 666 667 668 669
    if (!adapter.data.fchost.parent &&
        !(adapter.data.fchost.parent = virFindFCHostCapableVport(NULL))) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                       _("'parent' for vHBA not specified, and "
                         "cannot find one on this host"));
         return -1;
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
    }

    if (getHostNumber(adapter.data.fchost.parent, &parent_host) < 0)
        return -1;

    if (virManageVport(parent_host, adapter.data.fchost.wwnn,
                       adapter.data.fchost.wwpn, VPORT_CREATE) < 0)
        return -1;

    virFileWaitForDevices();
    return 0;
}

static int
deleteVport(virStoragePoolSourceAdapter adapter)
{
    unsigned int parent_host;

    if (adapter.type != VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST)
        return 0;

    if (!(virGetFCHostNameByWWN(NULL, adapter.data.fchost.wwnn,
                                adapter.data.fchost.wwpn)))
        return -1;

    if (getHostNumber(adapter.data.fchost.parent, &parent_host) < 0)
        return -1;

    if (virManageVport(parent_host, adapter.data.fchost.wwnn,
                       adapter.data.fchost.wwpn, VPORT_DELETE) < 0)
        return -1;

    return 0;
}


706 707 708 709 710
static int
virStorageBackendSCSICheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
                               virStoragePoolObjPtr pool,
                               bool *isActive)
{
711 712
    char *path = NULL;
    char *name = NULL;
713
    unsigned int host;
714
    int ret = -1;
715 716

    *isActive = false;
717

718
    if (!(name = getAdapterName(pool->def->source.adapter)))
719 720
        return -1;

721 722 723
    if (getHostNumber(name, &host) < 0)
        goto cleanup;

724
    if (virAsprintf(&path, "/sys/class/scsi_host/host%d", host) < 0) {
725
        virReportOOMError();
726
        goto cleanup;
727 728 729 730 731
    }

    if (access(path, F_OK) == 0)
        *isActive = true;

732 733
    ret = 0;
cleanup:
734
    VIR_FREE(path);
735 736
    VIR_FREE(name);
    return ret;
737
}
738

739
static int
740
virStorageBackendSCSIRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
741 742
                                 virStoragePoolObjPtr pool)
{
743
    char *name = NULL;
744
    unsigned int host;
745
    int ret = -1;
746 747 748

    pool->def->allocation = pool->def->capacity = pool->def->available = 0;

749 750 751 752
    if (!(name = getAdapterName(pool->def->source.adapter)))
        return -1;

    if (getHostNumber(name, &host) < 0)
753 754
        goto out;

755
    VIR_DEBUG("Scanning host%u", host);
756

757
    if (virStorageBackendSCSITriggerRescan(host) < 0)
758 759
        goto out;

760
    virStorageBackendSCSIFindLUs(pool, host);
761

762
    ret = 0;
763
out:
764
    VIR_FREE(name);
765
    return ret;
766 767
}

768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
static int
virStorageBackendSCSIStartPool(virConnectPtr conn ATTRIBUTE_UNUSED,
                               virStoragePoolObjPtr pool)
{
    virStoragePoolSourceAdapter adapter = pool->def->source.adapter;
    return createVport(adapter);
}

static int
virStorageBackendSCSIStopPool(virConnectPtr conn ATTRIBUTE_UNUSED,
                              virStoragePoolObjPtr pool)
{
    virStoragePoolSourceAdapter adapter = pool->def->source.adapter;
    return deleteVport(adapter);
}
783 784 785 786

virStorageBackend virStorageBackendSCSI = {
    .type = VIR_STORAGE_POOL_SCSI,

787
    .checkPool = virStorageBackendSCSICheckPool,
788
    .refreshPool = virStorageBackendSCSIRefreshPool,
789 790
    .startPool = virStorageBackendSCSIStartPool,
    .stopPool = virStorageBackendSCSIStopPool,
791
};