You need to sign in or sign up before continuing.
storage_backend_fs.c 42.5 KB
Newer Older
1 2 3
/*
 * storage_backend_fs.c: storage backend for FS and directory handling
 *
4
 * Copyright (C) 2007-2009 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 * 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
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
 * Author: Daniel P. Berrange <berrange@redhat.com>
 */

#include <config.h>

#include <sys/statvfs.h>
#include <sys/types.h>
#include <sys/stat.h>
29
#include <stdbool.h>
30 31 32 33 34 35 36
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

37 38 39 40
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xpath.h>

41
#include "virterror_internal.h"
42 43
#include "storage_backend_fs.h"
#include "storage_conf.h"
44
#include "storage_file.h"
45
#include "util.h"
46
#include "memory.h"
47
#include "xml.h"
48

49 50 51 52
enum lv_endian {
    LV_LITTLE_ENDIAN = 1, /* 1234 */
    LV_BIG_ENDIAN         /* 4321 */
};
53

54 55 56 57 58 59 60 61 62 63 64 65 66
enum {
    BACKING_STORE_OK,
    BACKING_STORE_INVALID,
    BACKING_STORE_ERROR,
};

static int cowGetBackingStore(virConnectPtr, char **,
                              const unsigned char *, size_t);
static int qcowXGetBackingStore(virConnectPtr, char **,
                                const unsigned char *, size_t);
static int vmdk4GetBackingStore(virConnectPtr, char **,
                                const unsigned char *, size_t);

67
/* Either 'magic' or 'extension' *must* be provided */
J
Jim Meyering 已提交
68
struct FileTypeInfo {
69 70 71 72
    int type;           /* One of the constants above */
    const char *magic;  /* Optional string of file magic
                         * to check at head of file */
    const char *extension; /* Optional file extension to check */
73
    enum lv_endian endian; /* Endianness of file format */
74 75 76 77 78 79 80 81 82
    int versionOffset;    /* Byte offset from start of file
                           * where we find version number,
                           * -1 to skip version test */
    int versionNumber;    /* Version number to validate */
    int sizeOffset;       /* Byte offset from start of file
                           * where we find capacity info,
                           * -1 to use st_size as capacity */
    int sizeBytes;        /* Number of bytes for size field */
    int sizeMultiplier;   /* A scaling factor if size is not in bytes */
83 84 85
                          /* Store a COW base image path (possibly relative),
                           * or NULL if there is no COW base image, to RES;
                           * return BACKING_STORE_* */
86 87 88
    int qcowCryptOffset;  /* Byte offset from start of file
                           * where to find encryption mode,
                           * -1 if encryption is not used */
89 90
    int (*getBackingStore)(virConnectPtr conn, char **res,
                           const unsigned char *buf, size_t buf_size);
J
Jim Meyering 已提交
91
};
92
struct FileTypeInfo const fileTypeInfo[] = {
93 94
    /* Bochs */
    /* XXX Untested
95
    { VIR_STORAGE_FILE_BOCHS, "Bochs Virtual HD Image", NULL,
96
      LV_LITTLE_ENDIAN, 64, 0x20000,
97
      32+16+16+4+4+4+4+4, 8, 1, -1, NULL },*/
98 99 100
    /* CLoop */
    /* XXX Untested
    { VIR_STORAGE_VOL_CLOOP, "#!/bin/sh\n#V2.0 Format\nmodprobe cloop file=$0 && mount -r -t iso9660 /dev/cloop $1\n", NULL,
101
      LV_LITTLE_ENDIAN, -1, 0,
102
      -1, 0, 0, -1, NULL }, */
103
    /* Cow */
104
    { VIR_STORAGE_FILE_COW, "OOOM", NULL,
105
      LV_BIG_ENDIAN, 4, 2,
106
      4+4+1024+4, 8, 1, -1, cowGetBackingStore },
107 108
    /* DMG */
    /* XXX QEMU says there's no magic for dmg, but we should check... */
109
    { VIR_STORAGE_FILE_DMG, NULL, ".dmg",
110
      0, -1, 0,
111
      -1, 0, 0, -1, NULL },
112
    /* XXX there's probably some magic for iso we can validate too... */
113
    { VIR_STORAGE_FILE_ISO, NULL, ".iso",
114
      0, -1, 0,
115
      -1, 0, 0, -1, NULL },
116 117
    /* Parallels */
    /* XXX Untested
118
    { VIR_STORAGE_FILE_PARALLELS, "WithoutFreeSpace", NULL,
119
      LV_LITTLE_ENDIAN, 16, 2,
120
      16+4+4+4+4, 4, 512, -1, NULL },
121 122
    */
    /* QCow */
123
    { VIR_STORAGE_FILE_QCOW, "QFI", NULL,
124
      LV_BIG_ENDIAN, 4, 1,
125
      4+4+8+4+4, 8, 1, 4+4+8+4+4+8+1+1+2, qcowXGetBackingStore },
126
    /* QCow 2 */
127
    { VIR_STORAGE_FILE_QCOW2, "QFI", NULL,
128
      LV_BIG_ENDIAN, 4, 2,
129
      4+4+8+4+4, 8, 1, 4+4+8+4+4+8, qcowXGetBackingStore },
130 131
    /* VMDK 3 */
    /* XXX Untested
132
    { VIR_STORAGE_FILE_VMDK, "COWD", NULL,
133
      LV_LITTLE_ENDIAN, 4, 1,
134
      4+4+4, 4, 512, -1, NULL },
135 136
    */
    /* VMDK 4 */
137
    { VIR_STORAGE_FILE_VMDK, "KDMV", NULL,
138
      LV_LITTLE_ENDIAN, 4, 1,
139
      4+4+4, 8, 512, -1, vmdk4GetBackingStore },
140 141
    /* Connectix / VirtualPC */
    /* XXX Untested
142
    { VIR_STORAGE_FILE_VPC, "conectix", NULL,
143
      LV_BIG_ENDIAN, -1, 0,
144
      -1, 0, 0, -1, NULL},
145 146 147
    */
};

148
#define VIR_FROM_THIS VIR_FROM_STORAGE
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
static int
cowGetBackingStore(virConnectPtr conn,
                   char **res,
                   const unsigned char *buf,
                   size_t buf_size)
{
#define COW_FILENAME_MAXLEN 1024
    *res = NULL;
    if (buf_size < 4+4+ COW_FILENAME_MAXLEN)
        return BACKING_STORE_INVALID;
    if (buf[4+4] == '\0') /* cow_header_v2.backing_file[0] */
        return BACKING_STORE_OK;

    *res = strndup ((const char*)buf + 4+4, COW_FILENAME_MAXLEN);
    if (*res == NULL) {
        virReportOOMError(conn);
        return BACKING_STORE_ERROR;
    }
    return BACKING_STORE_OK;
}

static int
qcowXGetBackingStore(virConnectPtr conn,
                     char **res,
                     const unsigned char *buf,
                     size_t buf_size)
{
    unsigned long long offset;
    unsigned long size;

    *res = NULL;
    if (buf_size < 4+4+8+4)
        return BACKING_STORE_INVALID;
    offset = (((unsigned long long)buf[4+4] << 56)
              | ((unsigned long long)buf[4+4+1] << 48)
              | ((unsigned long long)buf[4+4+2] << 40)
              | ((unsigned long long)buf[4+4+3] << 32)
              | ((unsigned long long)buf[4+4+4] << 24)
              | ((unsigned long long)buf[4+4+5] << 16)
              | ((unsigned long long)buf[4+4+6] << 8)
              | buf[4+4+7]); /* QCowHeader.backing_file_offset */
    if (offset > buf_size)
        return BACKING_STORE_INVALID;
    size = ((buf[4+4+8] << 24)
            | (buf[4+4+8+1] << 16)
            | (buf[4+4+8+2] << 8)
            | buf[4+4+8+3]); /* QCowHeader.backing_file_size */
    if (size == 0)
        return BACKING_STORE_OK;
    if (offset + size > buf_size || offset + size < offset)
        return BACKING_STORE_INVALID;
    if (size + 1 == 0)
        return BACKING_STORE_INVALID;
    if (VIR_ALLOC_N(*res, size + 1) < 0) {
204
        virReportOOMError(conn);
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
        return BACKING_STORE_ERROR;
    }
    memcpy(*res, buf + offset, size);
    (*res)[size] = '\0';
    return BACKING_STORE_OK;
}


static int
vmdk4GetBackingStore(virConnectPtr conn,
                     char **res,
                     const unsigned char *buf,
                     size_t buf_size)
{
    static const char prefix[] = "parentFileNameHint=\"";

    char desc[20*512 + 1], *start, *end;
    size_t len;

    *res = NULL;

    if (buf_size <= 0x200)
        return BACKING_STORE_INVALID;
    len = buf_size - 0x200;
    if (len > sizeof(desc) - 1)
        len = sizeof(desc) - 1;
    memcpy(desc, buf + 0x200, len);
    desc[len] = '\0';
    start = strstr(desc, prefix);
    if (start == NULL)
        return BACKING_STORE_OK;
    start += strlen(prefix);
    end = strchr(start, '"');
    if (end == NULL)
        return BACKING_STORE_INVALID;
    if (end == start)
        return BACKING_STORE_OK;
    *end = '\0';
    *res = strdup(start);
    if (*res == NULL) {
245
        virReportOOMError(conn);
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
        return BACKING_STORE_ERROR;
    }
    return BACKING_STORE_OK;
}

/**
 * Return an absolute path corresponding to PATH, which is absolute or relative
 * to the directory containing BASE_FILE, or NULL on error
 */
static char *absolutePathFromBaseFile(const char *base_file, const char *path)
{
    size_t base_size, path_size;
    char *res, *p;

    if (*path == '/')
        return strdup(path);

    base_size = strlen(base_file) + 1;
    path_size = strlen(path) + 1;
    if (VIR_ALLOC_N(res, base_size - 1 + path_size) < 0)
        return NULL;
    memcpy(res, base_file, base_size);
    p = strrchr(res, '/');
    if (p != NULL)
        p++;
    else
        p = res;
    memcpy(p, path, path_size);
    if (VIR_REALLOC_N(res, (p + path_size) - res) < 0) {
        /* Ignore failure */
    }
    return res;
}

280 281 282 283 284 285


/**
 * Probe the header of a file to determine what type of disk image
 * it is, and info about its capacity if available.
 */
286 287 288 289
static int
virStorageGetMetadataFromFD(virConnectPtr conn,
                            const char *path,
                            int fd,
290
                            virStorageFileMetadata *meta)
291
{
292
    unsigned char head[20*512]; /* vmdk4GetBackingStore needs this much. */
293
    int len, i;
294

295 296
    /* If all else fails, call it a raw file */
    meta->format = VIR_STORAGE_FILE_RAW;
297 298

    if ((len = read(fd, head, sizeof(head))) < 0) {
299
        virReportSystemError(conn, errno, _("cannot read header '%s'"), path);
300 301 302 303
        return -1;
    }

    /* First check file magic */
J
Jim Meyering 已提交
304
    for (i = 0 ; i < ARRAY_CARDINALITY(fileTypeInfo) ; i++) {
305
        int mlen;
306

307 308 309 310 311 312 313 314 315 316 317 318 319 320
        if (fileTypeInfo[i].magic == NULL)
            continue;

        /* Validate magic data */
        mlen = strlen(fileTypeInfo[i].magic);
        if (mlen > len)
            continue;
        if (memcmp(head, fileTypeInfo[i].magic, mlen) != 0)
            continue;

        /* Validate version number info */
        if (fileTypeInfo[i].versionNumber != -1) {
            int version;

321
            if (fileTypeInfo[i].endian == LV_LITTLE_ENDIAN) {
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
                version = (head[fileTypeInfo[i].versionOffset+3] << 24) |
                    (head[fileTypeInfo[i].versionOffset+2] << 16) |
                    (head[fileTypeInfo[i].versionOffset+1] << 8) |
                    head[fileTypeInfo[i].versionOffset];
            } else {
                version = (head[fileTypeInfo[i].versionOffset] << 24) |
                    (head[fileTypeInfo[i].versionOffset+1] << 16) |
                    (head[fileTypeInfo[i].versionOffset+2] << 8) |
                    head[fileTypeInfo[i].versionOffset+3];
            }
            if (version != fileTypeInfo[i].versionNumber)
                continue;
        }

        /* Optionally extract capacity from file */
337
        if (fileTypeInfo[i].sizeOffset != -1) {
338
            if (fileTypeInfo[i].endian == LV_LITTLE_ENDIAN) {
339
                meta->capacity =
340 341 342 343 344 345 346 347 348
                    ((unsigned long long)head[fileTypeInfo[i].sizeOffset+7] << 56) |
                    ((unsigned long long)head[fileTypeInfo[i].sizeOffset+6] << 48) |
                    ((unsigned long long)head[fileTypeInfo[i].sizeOffset+5] << 40) |
                    ((unsigned long long)head[fileTypeInfo[i].sizeOffset+4] << 32) |
                    ((unsigned long long)head[fileTypeInfo[i].sizeOffset+3] << 24) |
                    ((unsigned long long)head[fileTypeInfo[i].sizeOffset+2] << 16) |
                    ((unsigned long long)head[fileTypeInfo[i].sizeOffset+1] << 8) |
                    ((unsigned long long)head[fileTypeInfo[i].sizeOffset]);
            } else {
349
                meta->capacity =
350 351 352 353 354 355 356 357 358 359
                    ((unsigned long long)head[fileTypeInfo[i].sizeOffset] << 56) |
                    ((unsigned long long)head[fileTypeInfo[i].sizeOffset+1] << 48) |
                    ((unsigned long long)head[fileTypeInfo[i].sizeOffset+2] << 40) |
                    ((unsigned long long)head[fileTypeInfo[i].sizeOffset+3] << 32) |
                    ((unsigned long long)head[fileTypeInfo[i].sizeOffset+4] << 24) |
                    ((unsigned long long)head[fileTypeInfo[i].sizeOffset+5] << 16) |
                    ((unsigned long long)head[fileTypeInfo[i].sizeOffset+6] << 8) |
                    ((unsigned long long)head[fileTypeInfo[i].sizeOffset+7]);
            }
            /* Avoid unlikely, but theoretically possible overflow */
360
            if (meta->capacity > (ULLONG_MAX / fileTypeInfo[i].sizeMultiplier))
361
                continue;
362
            meta->capacity *= fileTypeInfo[i].sizeMultiplier;
363 364
        }

365
        if (fileTypeInfo[i].qcowCryptOffset != -1) {
366 367 368 369 370 371
            int crypt_format;

            crypt_format = (head[fileTypeInfo[i].qcowCryptOffset] << 24) |
                (head[fileTypeInfo[i].qcowCryptOffset+1] << 16) |
                (head[fileTypeInfo[i].qcowCryptOffset+2] << 8) |
                head[fileTypeInfo[i].qcowCryptOffset+3];
372
            meta->encrypted = crypt_format != 0;
373 374
        }

375
        /* Validation passed, we know the file format now */
376 377
        meta->format = fileTypeInfo[i].type;
        if (fileTypeInfo[i].getBackingStore != NULL) {
378 379 380 381 382 383 384 385 386 387 388 389 390
            char *base;

            switch (fileTypeInfo[i].getBackingStore(conn, &base, head, len)) {
            case BACKING_STORE_OK:
                break;

            case BACKING_STORE_INVALID:
                continue;

            case BACKING_STORE_ERROR:
                return -1;
            }
            if (base != NULL) {
391
                meta->backingStore = absolutePathFromBaseFile(path, base);
392
                VIR_FREE(base);
393
                if (meta->backingStore == NULL) {
394
                    virReportOOMError(conn);
395 396 397 398
                    return -1;
                }
            }
        }
399 400 401 402
        return 0;
    }

    /* No magic, so check file extension */
J
Jim Meyering 已提交
403
    for (i = 0 ; i < ARRAY_CARDINALITY(fileTypeInfo) ; i++) {
404 405 406
        if (fileTypeInfo[i].extension == NULL)
            continue;

407
        if (!virFileHasSuffix(path, fileTypeInfo[i].extension))
408 409
            continue;

410
        meta->format = fileTypeInfo[i].type;
411 412 413
        return 0;
    }

414 415 416 417 418 419 420 421 422 423 424 425
    return 0;
}

static int
virStorageBackendProbeTarget(virConnectPtr conn,
                             virStorageVolTargetPtr target,
                             char **backingStore,
                             unsigned long long *allocation,
                             unsigned long long *capacity,
                             virStorageEncryptionPtr *encryption)
{
    int fd, ret;
426
    virStorageFileMetadata meta;
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444

    if (encryption)
        *encryption = NULL;

    if ((fd = open(target->path, O_RDONLY)) < 0) {
        virReportSystemError(conn, errno,
                             _("cannot open volume '%s'"),
                             target->path);
        return -1;
    }

    if ((ret = virStorageBackendUpdateVolTargetInfoFD(conn, target, fd,
                                                      allocation,
                                                      capacity)) < 0) {
        close(fd);
        return ret; /* Take care to propagate ret, it is not always -1 */
    }

445 446 447
    memset(&meta, 0, sizeof(meta));

    if (virStorageGetMetadataFromFD(conn, target->path, fd, &meta) < 0) {
448 449 450 451 452 453
        close(fd);
        return -1;
    }

    close(fd);

454 455 456 457 458 459 460 461 462 463 464 465 466
    target->format = meta.format;

    if (backingStore) {
        *backingStore = meta.backingStore;
        meta.backingStore = NULL;
    }

    VIR_FREE(meta.backingStore);

    if (capacity && meta.capacity)
        *capacity = meta.capacity;

    if (encryption != NULL && meta.encrypted) {
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
        if (VIR_ALLOC(*encryption) < 0) {
            virReportOOMError(conn);
            if (backingStore)
                VIR_FREE(*backingStore);
            return -1;
        }

        switch (target->format) {
        case VIR_STORAGE_FILE_QCOW:
        case VIR_STORAGE_FILE_QCOW2:
            (*encryption)->format = VIR_STORAGE_ENCRYPTION_FORMAT_QCOW;
            break;
        default:
            break;
        }

        /* XXX ideally we'd fill in secret UUID here
         * but we cannot guarentee 'conn' is non-NULL
         * at this point in time :-(  So we only fill
         * in secrets when someone first queries a vol
         */
    }

490 491 492 493
    return 0;
}

#if WITH_STORAGE_FS
494 495 496

#include <mntent.h>

497 498
struct _virNetfsDiscoverState {
    const char *host;
499
    virStoragePoolSourceList list;
500 501 502 503 504 505 506 507 508 509 510 511
};

typedef struct _virNetfsDiscoverState virNetfsDiscoverState;

static int
virStorageBackendFileSystemNetFindPoolSourcesFunc(virConnectPtr conn ATTRIBUTE_UNUSED,
                                                  virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
                                                  char **const groups,
                                                  void *data)
{
    virNetfsDiscoverState *state = data;
    const char *name, *path;
512
    virStoragePoolSource *src;
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528

    path = groups[0];

    name = strrchr(path, '/');
    if (name == NULL) {
        virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
                              _("invalid netfs path (no /): %s"), path);
        return -1;
    }
    name += 1;
    if (*name == '\0') {
        virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
                              _("invalid netfs path (ends in /): %s"), path);
        return -1;
    }

529
    if (VIR_REALLOC_N(state->list.sources, state->list.nsources+1) < 0) {
530
        virReportOOMError(conn);
531 532
        return -1;
    }
533
    memset(state->list.sources + state->list.nsources, 0, sizeof(*state->list.sources));
534

535 536 537
    src = state->list.sources + state->list.nsources++;
    if (!(src->host.name = strdup(state->host)) ||
        !(src->dir = strdup(path)))
538
        return -1;
539
    src->format = VIR_STORAGE_POOL_NETFS_NFS;
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

    return 0;
}

static char *
virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn,
                                              const char *srcSpec,
                                              unsigned int flags ATTRIBUTE_UNUSED)
{
    /*
     *  # showmount --no-headers -e HOSTNAME
     *  /tmp   *
     *  /A dir demo1.foo.bar,demo2.foo.bar
     *
     * Extract directory name (including possible interior spaces ...).
     */

    const char *regexes[] = {
        "^(/.*\\S) +\\S+$"
    };
    int vars[] = {
        1
    };
    xmlDocPtr doc = NULL;
    xmlXPathContextPtr xpath_ctxt = NULL;
565 566 567 568 569 570 571 572
    virNetfsDiscoverState state = {
        .host = NULL,
        .list = {
            .type = VIR_STORAGE_POOL_NETFS,
            .nsources = 0,
            .sources = NULL
        }
    };
573 574 575
    const char *prog[] = { SHOWMOUNT, "--no-headers", "--exports", NULL, NULL };
    int exitstatus;
    char *retval = NULL;
576
    unsigned int i;
577 578 579 580 581 582 583 584 585 586 587

    doc = xmlReadDoc((const xmlChar *)srcSpec, "srcSpec.xml", NULL,
                     XML_PARSE_NOENT | XML_PARSE_NONET |
                     XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
    if (doc == NULL) {
        virStorageReportError(conn, VIR_ERR_XML_ERROR, "%s", _("bad <source> spec"));
        goto cleanup;
    }

    xpath_ctxt = xmlXPathNewContext(doc);
    if (xpath_ctxt == NULL) {
588
        virReportOOMError(conn);
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
        goto cleanup;
    }

    state.host = virXPathString(conn, "string(/source/host/@name)", xpath_ctxt);
    if (!state.host || !state.host[0]) {
        virStorageReportError(conn, VIR_ERR_XML_ERROR, "%s",
                              _("missing <host> in <source> spec"));
        goto cleanup;
    }
    prog[3] = state.host;

    if (virStorageBackendRunProgRegex(conn, NULL, prog, 1, regexes, vars,
                                      virStorageBackendFileSystemNetFindPoolSourcesFunc,
                                      &state, &exitstatus) < 0)
        goto cleanup;

605
    retval = virStoragePoolSourceListFormat(conn, &state.list);
606
    if (retval == NULL) {
607
        virReportOOMError(conn);
608 609 610 611
        goto cleanup;
    }

 cleanup:
612 613 614 615 616 617
    for (i = 0; i < state.list.nsources; i++)
        virStoragePoolSourceFree(&state.list.sources[i]);

    VIR_FREE(state.list.sources);
    VIR_FREE(state.host);

618 619 620 621 622 623 624
    xmlFreeDoc(doc);
    xmlXPathFreeContext(xpath_ctxt);

    return retval;
}


625 626 627 628 629 630 631 632 633 634 635 636
/**
 * @conn connection to report errors against
 * @pool storage pool to check for status
 *
 * Determine if a storage pool is already mounted
 *
 * Return 0 if not mounted, 1 if mounted, -1 on error
 */
static int
virStorageBackendFileSystemIsMounted(virConnectPtr conn,
                                     virStoragePoolObjPtr pool) {
    FILE *mtab;
637 638
    struct mntent ent;
    char buf[1024];
639 640

    if ((mtab = fopen(_PATH_MOUNTED, "r")) == NULL) {
641 642 643
        virReportSystemError(conn, errno,
                             _("cannot read mount list '%s'"),
                             _PATH_MOUNTED);
644 645 646
        return -1;
    }

647 648
    while ((getmntent_r(mtab, &ent, buf, sizeof(buf))) != NULL) {
        if (STREQ(ent.mnt_dir, pool->def->target.path)) {
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
            fclose(mtab);
            return 1;
        }
    }

    fclose(mtab);
    return 0;
}

/**
 * @conn connection to report errors against
 * @pool storage pool to mount
 *
 * Ensure that a FS storage pool is mounted on its target location.
 * If already mounted, this is a no-op
 *
 * Returns 0 if successfully mounted, -1 on error
 */
static int
virStorageBackendFileSystemMount(virConnectPtr conn,
                                 virStoragePoolObjPtr pool) {
    char *src;
671
    char *options;
672 673 674 675 676 677 678
    const char **mntargv;

    /* 'mount -t auto' doesn't seem to auto determine nfs (or cifs),
     *  while plain 'mount' does. We have to craft separate argvs to
     *  accommodate this */
    int netauto = (pool->def->type == VIR_STORAGE_POOL_NETFS &&
                   pool->def->source.format == VIR_STORAGE_POOL_NETFS_AUTO);
679 680 681 682
    int glusterfs = (pool->def->type == VIR_STORAGE_POOL_NETFS &&
                 pool->def->source.format == VIR_STORAGE_POOL_NETFS_GLUSTERFS);

    int option_index;
683 684 685 686 687 688 689 690 691 692
    int source_index;

    const char *netfs_auto_argv[] = {
        MOUNT,
        NULL, /* source path */
        pool->def->target.path,
        NULL,
    };

    const char *fs_argv[] =  {
693 694 695
        MOUNT,
        "-t",
        pool->def->type == VIR_STORAGE_POOL_FS ?
696 697
        virStoragePoolFormatFileSystemTypeToString(pool->def->source.format) :
        virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format),
698 699
        NULL, /* Fill in shortly - careful not to add extra fields
                 before this */
700 701 702
        pool->def->target.path,
        NULL,
    };
703

704 705 706 707 708 709 710 711 712 713 714 715 716
    const char *glusterfs_argv[] = {
        MOUNT,
        "-t",
        pool->def->type == VIR_STORAGE_POOL_FS ?
        virStoragePoolFormatFileSystemTypeToString(pool->def->source.format) :
        virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format),
        NULL,
        "-o",
        NULL,
        pool->def->target.path,
        NULL,
    };

717 718 719
    if (netauto) {
        mntargv = netfs_auto_argv;
        source_index = 1;
720 721 722 723
    } else if (glusterfs) {
        mntargv = glusterfs_argv;
        source_index = 3;
        option_index = 5;
724 725 726 727 728
    } else {
        mntargv = fs_argv;
        source_index = 3;
    }

729 730 731 732 733
    int ret;

    if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
        if (pool->def->source.host.name == NULL) {
            virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
734
                                  "%s", _("missing source host"));
735 736 737 738
            return -1;
        }
        if (pool->def->source.dir == NULL) {
            virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
739
                                  "%s", _("missing source path"));
740 741 742 743 744
            return -1;
        }
    } else {
        if (pool->def->source.ndevice != 1) {
            virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
745
                                  "%s", _("missing source device"));
746 747 748 749
            return -1;
        }
    }

J
Jim Meyering 已提交
750
    /* Short-circuit if already mounted */
751 752 753 754 755 756 757 758
    if ((ret = virStorageBackendFileSystemIsMounted(conn, pool)) != 0) {
        if (ret < 0)
            return -1;
        else
            return 0;
    }

    if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
759
        if (pool->def->source.format == VIR_STORAGE_POOL_NETFS_GLUSTERFS) {
760 761 762 763 764
            if (virAsprintf(&options, "direct-io-mode=1") == -1) {
                virReportOOMError(conn);
                return -1;
            }
        }
765 766 767
        if (virAsprintf(&src, "%s:%s",
                        pool->def->source.host.name,
                        pool->def->source.dir) == -1) {
768
            virReportOOMError(conn);
769 770
            return -1;
        }
771

772
    } else {
773
        if ((src = strdup(pool->def->source.devices[0].path)) == NULL) {
774
            virReportOOMError(conn);
775 776
            return -1;
        }
777
    }
778
    mntargv[source_index] = src;
779

780 781 782 783
    if (glusterfs) {
        mntargv[option_index] = options;
    }

784
    if (virRun(conn, mntargv, NULL) < 0) {
785
        VIR_FREE(src);
786 787
        return -1;
    }
788
    VIR_FREE(src);
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
    return 0;
}

/**
 * @conn connection to report errors against
 * @pool storage pool to unmount
 *
 * Ensure that a FS storage pool is not mounted on its target location.
 * If already unmounted, this is a no-op
 *
 * Returns 0 if successfully unmounted, -1 on error
 */
static int
virStorageBackendFileSystemUnmount(virConnectPtr conn,
                                   virStoragePoolObjPtr pool) {
    const char *mntargv[3];
    int ret;

    if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
        if (pool->def->source.host.name == NULL) {
            virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
810
                                  "%s", _("missing source host"));
811 812 813 814
            return -1;
        }
        if (pool->def->source.dir == NULL) {
            virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
815
                                  "%s", _("missing source dir"));
816 817 818 819 820
            return -1;
        }
    } else {
        if (pool->def->source.ndevice != 1) {
            virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
821
                                  "%s", _("missing source device"));
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
            return -1;
        }
    }

    /* Short-circuit if already unmounted */
    if ((ret = virStorageBackendFileSystemIsMounted(conn, pool)) != 1) {
        if (ret < 0)
            return -1;
        else
            return 0;
    }

    mntargv[0] = UMOUNT;
    mntargv[1] = pool->def->target.path;
    mntargv[2] = NULL;

838
    if (virRun(conn, mntargv, NULL) < 0) {
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
        return -1;
    }
    return 0;
}
#endif /* WITH_STORAGE_FS */


/**
 * @conn connection to report errors against
 * @pool storage pool to start
 *
 * Starts a directory or FS based storage pool.
 *
 *  - If it is a FS based pool, mounts the unlying source device on the pool
 *
 * Returns 0 on success, -1 on error
 */
#if WITH_STORAGE_FS
static int
virStorageBackendFileSystemStart(virConnectPtr conn,
                                 virStoragePoolObjPtr pool)
{
    if (pool->def->type != VIR_STORAGE_POOL_DIR &&
        virStorageBackendFileSystemMount(conn, pool) < 0)
        return -1;

    return 0;
}
#endif /* WITH_STORAGE_FS */


/**
 * @conn connection to report errors against
 * @pool storage pool to build
 *
 * Build a directory or FS based storage pool.
 *
 *  - If it is a FS based pool, mounts the unlying source device on the pool
 *
 * Returns 0 on success, -1 on error
 */
static int
virStorageBackendFileSystemBuild(virConnectPtr conn,
                                 virStoragePoolObjPtr pool,
                                 unsigned int flags ATTRIBUTE_UNUSED)
{
885 886 887 888 889
    int err;
    if ((err = virFileMakePath(pool->def->target.path)) < 0) {
        virReportSystemError(conn, err,
                             _("cannot create path '%s'"),
                             pool->def->target.path);
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907
        return -1;
    }

    return 0;
}


/**
 * Iterate over the pool's directory and enumerate all disk images
 * within it. This is non-recursive.
 */
static int
virStorageBackendFileSystemRefresh(virConnectPtr conn,
                                   virStoragePoolObjPtr pool)
{
    DIR *dir;
    struct dirent *ent;
    struct statvfs sb;
908
    virStorageVolDefPtr vol = NULL;
909 910

    if (!(dir = opendir(pool->def->target.path))) {
911 912 913
        virReportSystemError(conn, errno,
                             _("cannot open path '%s'"),
                             pool->def->target.path);
914 915 916 917 918
        goto cleanup;
    }

    while ((ent = readdir(dir)) != NULL) {
        int ret;
919
        char *backingStore;
920

921 922
        if (VIR_ALLOC(vol) < 0)
            goto no_memory;
923

924 925
        if ((vol->name = strdup(ent->d_name)) == NULL)
            goto no_memory;
926

927
        vol->type = VIR_STORAGE_VOL_FILE;
928
        vol->target.format = VIR_STORAGE_FILE_RAW; /* Real value is filled in during probe */
929 930 931
        if (virAsprintf(&vol->target.path, "%s/%s",
                        pool->def->target.path,
                        vol->name) == -1)
932 933 934 935
            goto no_memory;

        if ((vol->key = strdup(vol->target.path)) == NULL)
            goto no_memory;
936

937 938 939 940
        if ((ret = virStorageBackendProbeTarget(conn,
                                                &vol->target,
                                                &backingStore,
                                                &vol->allocation,
941 942
                                                &vol->capacity,
                                                &vol->target.encryption) < 0)) {
943
            if (ret == -1)
944
                goto cleanup;
945
            else {
946 947
                /* Silently ignore non-regular files,
                 * eg '.' '..', 'lost+found' */
948 949
                virStorageVolDefFree(vol);
                vol = NULL;
950
                continue;
951
            }
952 953
        }

954
        if (backingStore != NULL) {
955
            if (vol->target.format == VIR_STORAGE_FILE_QCOW2 &&
956 957 958 959 960 961 962 963
                STRPREFIX("fmt:", backingStore)) {
                char *fmtstr = backingStore + 4;
                char *path = strchr(fmtstr, ':');
                if (!path) {
                    VIR_FREE(backingStore);
                } else {
                    *path = '\0';
                    if ((vol->backingStore.format =
964
                         virStorageFileFormatTypeFromString(fmtstr)) < 0) {
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
                        VIR_FREE(backingStore);
                    } else {
                        memmove(backingStore, path, strlen(path) + 1);
                        vol->backingStore.path = backingStore;

                        if (virStorageBackendUpdateVolTargetInfo(conn,
                                                                 &vol->backingStore,
                                                                 NULL,
                                                                 NULL) < 0)
                            VIR_FREE(vol->backingStore);
                    }
                }
            } else {
                vol->backingStore.path = backingStore;

                if ((ret = virStorageBackendProbeTarget(conn,
                                                        &vol->backingStore,
982 983
                                                        NULL, NULL, NULL,
                                                        NULL)) < 0) {
984
                    if (ret == -1)
985
                        goto cleanup;
986 987 988 989 990 991 992 993 994 995 996
                    else {
                        /* Silently ignore non-regular files,
                         * eg '.' '..', 'lost+found' */
                        VIR_FREE(vol->backingStore);
                    }
                }
            }
        }



997 998 999 1000 1001
        if (VIR_REALLOC_N(pool->volumes.objs,
                          pool->volumes.count+1) < 0)
            goto no_memory;
        pool->volumes.objs[pool->volumes.count++] = vol;
        vol = NULL;
1002 1003 1004 1005 1006
    }
    closedir(dir);


    if (statvfs(pool->def->target.path, &sb) < 0) {
1007 1008 1009
        virReportSystemError(conn, errno,
                             _("cannot statvfs path '%s'"),
                             pool->def->target.path);
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
        return -1;
    }
    pool->def->capacity = ((unsigned long long)sb.f_frsize *
                           (unsigned long long)sb.f_blocks);
    pool->def->available = ((unsigned long long)sb.f_bfree *
                            (unsigned long long)sb.f_bsize);
    pool->def->allocation = pool->def->capacity - pool->def->available;

    return 0;

1020
no_memory:
1021
    virReportOOMError(conn);
1022 1023
    /* fallthrough */

1024
 cleanup:
1025 1026
    if (dir)
        closedir(dir);
1027
    virStorageVolDefFree(vol);
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
    virStoragePoolObjClearVols(pool);
    return -1;
}


/**
 * @conn connection to report errors against
 * @pool storage pool to start
 *
 * Stops a directory or FS based storage pool.
 *
 *  - If it is a FS based pool, unmounts the unlying source device on the pool
 *  - Releases all cached data about volumes
 */
#if WITH_STORAGE_FS
static int
virStorageBackendFileSystemStop(virConnectPtr conn,
                                virStoragePoolObjPtr pool)
{
    if (pool->def->type != VIR_STORAGE_POOL_DIR &&
        virStorageBackendFileSystemUnmount(conn, pool) < 0)
        return -1;

    return 0;
}
#endif /* WITH_STORAGE_FS */


/**
 * @conn connection to report errors against
 * @pool storage pool to build
 *
 * Build a directory or FS based storage pool.
 *
 *  - If it is a FS based pool, mounts the unlying source device on the pool
 *
 * Returns 0 on success, -1 on error
 */
static int
virStorageBackendFileSystemDelete(virConnectPtr conn,
                                  virStoragePoolObjPtr pool,
                                  unsigned int flags ATTRIBUTE_UNUSED)
{
    /* XXX delete all vols first ? */

    if (unlink(pool->def->target.path) < 0) {
1074 1075 1076
        virReportSystemError(conn, errno,
                             _("cannot unlink path '%s'"),
                             pool->def->target.path);
1077 1078 1079 1080 1081 1082 1083 1084
        return -1;
    }

    return 0;
}


/**
1085 1086 1087 1088
 * Set up a volume definition to be added to a pool's volume list, but
 * don't do any file creation or allocation. By separating the two processes,
 * we allow allocation progress reporting (by polling the volume's 'info'
 * function), and can drop the parent pool lock during the (slow) allocation.
1089 1090 1091 1092 1093 1094 1095
 */
static int
virStorageBackendFileSystemVolCreate(virConnectPtr conn,
                                     virStoragePoolObjPtr pool,
                                     virStorageVolDefPtr vol)
{

1096 1097
    vol->type = VIR_STORAGE_VOL_FILE;

R
Ryota Ozaki 已提交
1098
    VIR_FREE(vol->target.path);
1099 1100 1101
    if (virAsprintf(&vol->target.path, "%s/%s",
                    pool->def->target.path,
                    vol->name) == -1) {
1102
        virReportOOMError(conn);
1103 1104
        return -1;
    }
1105

R
Ryota Ozaki 已提交
1106
    VIR_FREE(vol->key);
1107 1108
    vol->key = strdup(vol->target.path);
    if (vol->key == NULL) {
1109
        virReportOOMError(conn);
1110 1111 1112
        return -1;
    }

1113 1114 1115
    return 0;
}

1116
static int createFileDir(virConnectPtr conn,
1117
                         virStorageVolDefPtr vol,
1118 1119
                         virStorageVolDefPtr inputvol,
                         unsigned int flags ATTRIBUTE_UNUSED) {
1120 1121 1122 1123 1124 1125 1126
    if (inputvol) {
        virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
                              "%s",
                              _("cannot copy from volume to a directory volume"));
        return -1;
    }

1127 1128 1129 1130 1131 1132
    if (mkdir(vol->target.path, vol->target.perms.mode) < 0) {
        virReportSystemError(conn, errno,
                             _("cannot create path '%s'"),
                             vol->target.path);
        return -1;
    }
1133

1134 1135
    return 0;
}
1136

1137
static int
1138 1139 1140
_virStorageBackendFileSystemVolBuild(virConnectPtr conn,
                                     virStorageVolDefPtr vol,
                                     virStorageVolDefPtr inputvol)
1141 1142
{
    int fd;
1143
    virStorageBackendBuildVolFrom create_func;
1144
    int tool_type;
1145

1146
    if (inputvol) {
1147 1148 1149 1150 1151 1152 1153
        if (vol->target.encryption != NULL) {
            virStorageReportError(conn, VIR_ERR_NO_SUPPORT,
                                  "%s", _("storage pool does not support "
                                          "building encrypted volumes from "
                                          "other volumes"));
            return -1;
        }
1154 1155
        create_func = virStorageBackendGetBuildVolFromFunction(conn, vol,
                                                               inputvol);
1156 1157
        if (!create_func)
            return -1;
1158
    } else if (vol->target.format == VIR_STORAGE_FILE_RAW) {
1159
        create_func = virStorageBackendCreateRaw;
1160
    } else if (vol->target.format == VIR_STORAGE_FILE_DIR) {
1161
        create_func = createFileDir;
1162 1163 1164 1165
    } else if ((tool_type = virStorageBackendFindFSImageTool(NULL)) != -1) {
        create_func = virStorageBackendFSImageToolTypeToFunc(conn, tool_type);

        if (!create_func)
1166
            return -1;
1167
    } else {
1168
        virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
1169 1170
                              "%s", _("creation of non-raw images "
                                      "is not supported without qemu-img"));
1171 1172 1173
        return -1;
    }

1174
    if (create_func(conn, vol, inputvol, 0) < 0)
1175 1176 1177 1178 1179 1180 1181 1182 1183
        return -1;

    if ((fd = open(vol->target.path, O_RDONLY)) < 0) {
        virReportSystemError(conn, errno,
                             _("cannot read path '%s'"),
                             vol->target.path);
        return -1;
    }

1184 1185 1186
    /* We can only chown/grp if root */
    if (getuid() == 0) {
        if (fchown(fd, vol->target.perms.uid, vol->target.perms.gid) < 0) {
1187 1188 1189
            virReportSystemError(conn, errno,
                                 _("cannot set file owner '%s'"),
                                 vol->target.path);
1190 1191 1192 1193 1194
            close(fd);
            return -1;
        }
    }
    if (fchmod(fd, vol->target.perms.mode) < 0) {
1195 1196 1197
        virReportSystemError(conn, errno,
                             _("cannot set file mode '%s'"),
                             vol->target.path);
1198 1199 1200 1201 1202
        close(fd);
        return -1;
    }

    /* Refresh allocation / permissions info, but not capacity */
1203 1204 1205
    if (virStorageBackendUpdateVolTargetInfoFD(conn, &vol->target, fd,
                                               &vol->allocation,
                                               NULL) < 0) {
1206 1207 1208 1209 1210
        close(fd);
        return -1;
    }

    if (close(fd) < 0) {
1211 1212 1213
        virReportSystemError(conn, errno,
                             _("cannot close file '%s'"),
                             vol->target.path);
1214 1215 1216 1217 1218 1219
        return -1;
    }

    return 0;
}

1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
/**
 * Allocate a new file as a volume. This is either done directly
 * for raw/sparse files, or by calling qemu-img/qcow-create for
 * special kinds of files
 */
static int
virStorageBackendFileSystemVolBuild(virConnectPtr conn,
                                    virStorageVolDefPtr vol) {
    return _virStorageBackendFileSystemVolBuild(conn, vol, NULL);
}

/*
 * Create a storage vol using 'inputvol' as input
 */
static int
virStorageBackendFileSystemVolBuildFrom(virConnectPtr conn,
                                        virStorageVolDefPtr vol,
                                        virStorageVolDefPtr inputvol,
                                        unsigned int flags ATTRIBUTE_UNUSED) {
    return _virStorageBackendFileSystemVolBuild(conn, vol, inputvol);
}
1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253

/**
 * Remove a volume - just unlinks for now
 */
static int
virStorageBackendFileSystemVolDelete(virConnectPtr conn,
                                     virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
                                     virStorageVolDefPtr vol,
                                     unsigned int flags ATTRIBUTE_UNUSED)
{
    if (unlink(vol->target.path) < 0) {
        /* Silently ignore failures where the vol has already gone away */
        if (errno != ENOENT) {
1254 1255 1256
            virReportSystemError(conn, errno,
                                 _("cannot unlink file '%s'"),
                                 vol->target.path);
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271
            return -1;
        }
    }
    return 0;
}


/**
 * Update info about a volume's capacity/allocation
 */
static int
virStorageBackendFileSystemVolRefresh(virConnectPtr conn,
                                      virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
                                      virStorageVolDefPtr vol)
{
1272 1273
    int ret;

1274
    /* Refresh allocation / permissions info in case its changed */
1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307
    ret = virStorageBackendUpdateVolInfo(conn, vol, 0);
    if (ret < 0)
        return ret;

    /* Load any secrets if posible */
    if (vol->target.encryption &&
        vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_QCOW &&
        vol->target.encryption->nsecrets == 0) {
        virSecretPtr sec;
        virStorageEncryptionSecretPtr encsec = NULL;

        sec = virSecretLookupByUsage(conn,
                                     VIR_SECRET_USAGE_TYPE_VOLUME,
                                     vol->target.path);
        if (sec) {
            if (VIR_ALLOC_N(vol->target.encryption->secrets, 1) < 0 ||
                VIR_ALLOC(encsec) < 0) {
                VIR_FREE(vol->target.encryption->secrets);
                virReportOOMError(conn);
                virSecretFree(sec);
                return -1;
            }

            vol->target.encryption->nsecrets = 1;
            vol->target.encryption->secrets[0] = encsec;

            encsec->type = VIR_STORAGE_ENCRYPTION_SECRET_TYPE_PASSPHRASE;
            virSecretGetUUID(sec, encsec->uuid);
            virSecretFree(sec);
        }
    }

    return 0;
1308 1309 1310 1311 1312 1313 1314 1315
}

virStorageBackend virStorageBackendDirectory = {
    .type = VIR_STORAGE_POOL_DIR,

    .buildPool = virStorageBackendFileSystemBuild,
    .refreshPool = virStorageBackendFileSystemRefresh,
    .deletePool = virStorageBackendFileSystemDelete,
1316
    .buildVol = virStorageBackendFileSystemVolBuild,
1317
    .buildVolFrom = virStorageBackendFileSystemVolBuildFrom,
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331
    .createVol = virStorageBackendFileSystemVolCreate,
    .refreshVol = virStorageBackendFileSystemVolRefresh,
    .deleteVol = virStorageBackendFileSystemVolDelete,
};

#if WITH_STORAGE_FS
virStorageBackend virStorageBackendFileSystem = {
    .type = VIR_STORAGE_POOL_FS,

    .buildPool = virStorageBackendFileSystemBuild,
    .startPool = virStorageBackendFileSystemStart,
    .refreshPool = virStorageBackendFileSystemRefresh,
    .stopPool = virStorageBackendFileSystemStop,
    .deletePool = virStorageBackendFileSystemDelete,
1332
    .buildVol = virStorageBackendFileSystemVolBuild,
1333
    .buildVolFrom = virStorageBackendFileSystemVolBuildFrom,
1334 1335 1336 1337 1338 1339 1340 1341 1342
    .createVol = virStorageBackendFileSystemVolCreate,
    .refreshVol = virStorageBackendFileSystemVolRefresh,
    .deleteVol = virStorageBackendFileSystemVolDelete,
};
virStorageBackend virStorageBackendNetFileSystem = {
    .type = VIR_STORAGE_POOL_NETFS,

    .buildPool = virStorageBackendFileSystemBuild,
    .startPool = virStorageBackendFileSystemStart,
1343
    .findPoolSources = virStorageBackendFileSystemNetFindPoolSources,
1344 1345 1346
    .refreshPool = virStorageBackendFileSystemRefresh,
    .stopPool = virStorageBackendFileSystemStop,
    .deletePool = virStorageBackendFileSystemDelete,
1347
    .buildVol = virStorageBackendFileSystemVolBuild,
1348
    .buildVolFrom = virStorageBackendFileSystemVolBuildFrom,
1349 1350 1351 1352 1353
    .createVol = virStorageBackendFileSystemVolCreate,
    .refreshVol = virStorageBackendFileSystemVolRefresh,
    .deleteVol = virStorageBackendFileSystemVolDelete,
};
#endif /* WITH_STORAGE_FS */