storage_backend_fs.c 21.4 KB
Newer Older
1 2 3
/*
 * storage_backend_fs.c: storage backend for FS and directory handling
 *
4
 * Copyright (C) 2007-2015 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17
 * 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
 */

#include <config.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

28
#include "virerror.h"
29
#include "storage_backend_fs.h"
30
#include "storage_util.h"
31
#include "storage_conf.h"
32
#include "vircommand.h"
33
#include "viralloc.h"
E
Eric Blake 已提交
34
#include "virfile.h"
35
#include "virlog.h"
36
#include "virstring.h"
37

38
#define VIR_FROM_THIS VIR_FROM_STORAGE
39

40 41
VIR_LOG_INIT("storage.storage_backend_fs");

42
#if WITH_STORAGE_FS
43

44
# include <libxml/xpathInternals.h>
45
# include <mntent.h>
46

47 48
struct _virNetfsDiscoverState {
    const char *host;
49
    virStoragePoolSourceList list;
50 51 52 53 54
};

typedef struct _virNetfsDiscoverState virNetfsDiscoverState;

static int
55
virStorageBackendFileSystemNetFindPoolSourcesFunc(char **const groups,
56 57 58 59
                                                  void *data)
{
    virNetfsDiscoverState *state = data;
    const char *name, *path;
60 61
    virStoragePoolSource *src = NULL;
    int ret = -1;
62 63 64

    path = groups[0];

65
    if (!(name = strrchr(path, '/'))) {
66 67
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("invalid netfs path (no /): %s"), path);
68
        goto cleanup;
69 70 71
    }
    name += 1;
    if (*name == '\0') {
72 73
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("invalid netfs path (ends in /): %s"), path);
74
        goto cleanup;
75 76
    }

77
    if (!(src = virStoragePoolSourceListNewSource(&state->list)))
78
        goto cleanup;
79

80
    if (VIR_ALLOC_N(src->hosts, 1) < 0)
81
        goto cleanup;
82
    src->nhost = 1;
83

84 85
    if (VIR_STRDUP(src->hosts[0].name, state->host) < 0 ||
        VIR_STRDUP(src->dir, path) < 0)
86
        goto cleanup;
87
    src->format = VIR_STORAGE_POOL_NETFS_NFS;
88

89
    ret = 0;
90
 cleanup:
91
    return ret;
92 93
}

94

95
static int
96
virStorageBackendFileSystemNetFindNFSPoolSources(virNetfsDiscoverState *state)
97
{
98 99
    int ret = -1;

100 101 102 103 104 105 106 107 108 109 110 111 112 113
    /*
     *  # 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
    };
114 115 116 117 118 119 120 121 122 123 124

    virCommandPtr cmd = NULL;

    cmd = virCommandNewArgList(SHOWMOUNT,
                               "--no-headers",
                               "--exports",
                               state->host,
                               NULL);

    if (virCommandRunRegex(cmd, 1, regexes, vars,
                           virStorageBackendFileSystemNetFindPoolSourcesFunc,
125
                           state, NULL, NULL) < 0)
126
        goto cleanup;
127

128 129 130
    ret = 0;

 cleanup:
131
    virCommandFree(cmd);
132
    return ret;
133 134 135 136
}


static char *
137
virStorageBackendFileSystemNetFindPoolSources(const char *srcSpec,
138 139
                                              unsigned int flags)
{
140 141 142 143 144 145 146 147
    virNetfsDiscoverState state = {
        .host = NULL,
        .list = {
            .type = VIR_STORAGE_POOL_NETFS,
            .nsources = 0,
            .sources = NULL
        }
    };
148
    virStoragePoolSourcePtr source = NULL;
149
    char *ret = NULL;
150
    size_t i;
151 152
    int retNFS = -1;
    int retGluster = 0;
153

E
Eric Blake 已提交
154 155
    virCheckFlags(0, NULL);

156
    if (!srcSpec) {
157 158
        virReportError(VIR_ERR_INVALID_ARG, "%s",
                       _("hostname must be specified for netfs sources"));
159 160 161 162 163 164
        return NULL;
    }

    if (!(source = virStoragePoolDefParseSourceString(srcSpec,
                                                      VIR_STORAGE_POOL_NETFS)))
        return NULL;
165

166
    if (source->nhost != 1) {
167 168
        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                       _("Expected exactly 1 host for the storage pool"));
169 170 171 172
        goto cleanup;
    }

    state.host = source->hosts[0].name;
173

174
    retNFS = virStorageBackendFileSystemNetFindNFSPoolSources(&state);
175

176
    retGluster = virStorageBackendFindGlusterPoolSources(state.host,
177
                                                         VIR_STORAGE_POOL_NETFS,
178
                                                         &state.list, false);
179 180 181 182

    if (retGluster < 0)
        goto cleanup;

183
    /* If both fail, then we won't return an empty list - return an error */
184 185 186 187
    if (retNFS < 0 && retGluster == 0) {
        virReportError(VIR_ERR_OPERATION_FAILED,
                       _("no storage pools were found on host '%s'"),
                       state.host);
188
        goto cleanup;
189
    }
190

191
    if (!(ret = virStoragePoolSourceListFormat(&state.list)))
192 193 194
        goto cleanup;

 cleanup:
195
    for (i = 0; i < state.list.nsources; i++)
196 197
        virStoragePoolSourceClear(&state.list.sources[i]);
    VIR_FREE(state.list.sources);
198

199
    virStoragePoolSourceFree(source);
200
    return ret;
201 202
}

203 204 205 206 207 208 209 210 211 212
/**
 * @pool storage pool to check FS types
 *
 * Determine if storage pool FS types are properly set up
 *
 * Return 0 if everything's OK, -1 on error
 */
static int
virStorageBackendFileSystemIsValid(virStoragePoolObjPtr pool)
{
213 214 215 216
    virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);

    if (def->type == VIR_STORAGE_POOL_NETFS) {
        if (def->source.nhost != 1) {
217 218 219 220
            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                           _("expected exactly 1 host for the storage pool"));
            return -1;
        }
221
        if (def->source.hosts[0].name == NULL) {
222 223 224 225
            virReportError(VIR_ERR_INTERNAL_ERROR,
                           "%s", _("missing source host"));
            return -1;
        }
226
        if (def->source.dir == NULL) {
227 228 229 230 231
            virReportError(VIR_ERR_INTERNAL_ERROR,
                           "%s", _("missing source path"));
            return -1;
        }
    } else {
232 233
        if (def->source.ndevice != 1) {
            if (def->source.ndevice == 0)
234 235 236 237 238 239
                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                               _("missing source device"));
            else
                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                               _("expected exactly 1 device for the "
                                 "storage pool"));
240 241 242 243 244
            return -1;
        }
    }
    return 0;
}
245

246

247 248 249 250 251 252 253 254
/**
 * @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
255 256
virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool)
{
257
    int ret = -1;
258
    virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
259
    char *src = NULL;
260
    FILE *mtab;
261 262
    struct mntent ent;
    char buf[1024];
263
    int rc1, rc2;
264 265

    if ((mtab = fopen(_PATH_MOUNTED, "r")) == NULL) {
266
        virReportSystemError(errno,
267 268
                             _("cannot read mount list '%s'"),
                             _PATH_MOUNTED);
269
        goto cleanup;
270 271
    }

272
    while ((getmntent_r(mtab, &ent, buf, sizeof(buf))) != NULL) {
273 274 275
        if (!(src = virStorageBackendFileSystemGetPoolSource(pool)))
            goto cleanup;

276 277 278
        /* compare both mount destinations and sources to be sure the mounted
         * FS pool is really the one we're looking for
         */
279
        if ((rc1 = virFileComparePaths(ent.mnt_dir, def->target.path)) < 0 ||
280 281 282 283
            (rc2 = virFileComparePaths(ent.mnt_fsname, src)) < 0)
            goto cleanup;

        if (rc1 && rc2) {
284 285
            ret = 1;
            goto cleanup;
286
        }
287 288

        VIR_FREE(src);
289 290
    }

291 292 293
    ret = 0;

 cleanup:
294
    VIR_FORCE_FCLOSE(mtab);
295
    VIR_FREE(src);
296
    return ret;
297 298
}

299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331

/**
 * @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(virStoragePoolObjPtr pool)
{
    virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
    char *src = NULL;
    virCommandPtr cmd = NULL;
    int ret = -1;
    int rc;

    if (virStorageBackendFileSystemIsValid(pool) < 0)
        return -1;

    if ((rc = virStorageBackendFileSystemIsMounted(pool)) < 0)
        return -1;

    /* Short-circuit if already mounted */
    if (rc == 1) {
        VIR_INFO("Target '%s' is already mounted", def->target.path);
        return 0;
    }

    if (!(src = virStorageBackendFileSystemGetPoolSource(pool)))
        return -1;

332
    cmd = virStorageBackendFileSystemMountCmd(MOUNT, def, src);
333 334 335 336
    if (virCommandRun(cmd, NULL) < 0)
        goto cleanup;

    ret = 0;
337
 cleanup:
338
    virCommandFree(cmd);
339
    VIR_FREE(src);
340
    return ret;
341 342
}

343

344
/**
345 346 347 348 349 350 351 352
 * @pool storage pool to start
 *
 * Starts a directory or FS based storage pool.  The underlying source
 * device will be mounted for FS based pools.
 *
 * Returns 0 on success, -1 on error
 */
static int
353
virStorageBackendFileSystemStart(virStoragePoolObjPtr pool)
354
{
355 356 357
    virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);

    if (def->type != VIR_STORAGE_POOL_DIR &&
358 359 360 361 362 363 364 365
        virStorageBackendFileSystemMount(pool) < 0)
        return -1;

    return 0;
}


/**
366 367
 * @pool storage pool to unmount
 *
368 369 370
 * Stops a file storage pool.  The underlying source device is unmounted
 * for FS based pools.  Any cached data about volumes is released.
 *
371
 * Ensure that a FS storage pool is not mounted on its target location.
372
 * If already unmounted, this is a no-op.
373 374 375 376
 *
 * Returns 0 if successfully unmounted, -1 on error
 */
static int
377
virStorageBackendFileSystemStop(virStoragePoolObjPtr pool)
378
{
379
    virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
380 381
    virCommandPtr cmd = NULL;
    int ret = -1;
382
    int rc;
383

384 385
    if (virStorageBackendFileSystemIsValid(pool) < 0)
        return -1;
386 387

    /* Short-circuit if already unmounted */
388 389
    if ((rc = virStorageBackendFileSystemIsMounted(pool)) != 1)
        return rc;
390

391
    cmd = virCommandNewArgList(UMOUNT, def->target.path, NULL);
392 393 394 395 396 397 398
    if (virCommandRun(cmd, NULL) < 0)
        goto cleanup;

    ret = 0;
 cleanup:
    virCommandFree(cmd);
    return ret;
399 400 401 402
}
#endif /* WITH_STORAGE_FS */


403
static int
404
virStorageBackendFileSystemCheck(virStoragePoolObjPtr pool,
405 406
                                 bool *isActive)
{
407 408 409 410
    virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);

    if (def->type == VIR_STORAGE_POOL_DIR) {
        *isActive = virFileExists(def->target.path);
411 412 413
#if WITH_STORAGE_FS
    } else {
        int ret;
414
        *isActive = false;
415 416 417 418

        if (virStorageBackendFileSystemIsValid(pool) < 0)
            return -1;

419 420 421 422 423 424 425 426 427 428 429
        if ((ret = virStorageBackendFileSystemIsMounted(pool)) != 0) {
            if (ret < 0)
                return -1;
            *isActive = true;
        }
#endif /* WITH_STORAGE_FS */
    }

    return 0;
}

430 431
/* some platforms don't support mkfs */
#ifdef MKFS
O
Osier Yang 已提交
432 433 434 435 436 437 438
static int
virStorageBackendExecuteMKFS(const char *device,
                             const char *format)
{
    int ret = 0;
    virCommandPtr cmd = NULL;

J
Ján Tomko 已提交
439 440
    cmd = virCommandNewArgList(MKFS, "-t", format, NULL);

441 442 443
    /* use the force, otherwise mkfs.xfs won't overwrite existing fs.
     * Similarly mkfs.ext2, mkfs.ext3, and mkfs.ext4 require supplying -F
     * and mkfs.vfat uses -I */
J
Ján Tomko 已提交
444 445
    if (STREQ(format, "xfs"))
        virCommandAddArg(cmd, "-f");
446 447 448 449 450 451
    else if (STREQ(format, "ext2") ||
             STREQ(format, "ext3") ||
             STREQ(format, "ext4"))
        virCommandAddArg(cmd, "-F");
    else if (STREQ(format, "vfat"))
        virCommandAddArg(cmd, "-I");
J
Ján Tomko 已提交
452 453

    virCommandAddArg(cmd, device);
O
Osier Yang 已提交
454 455 456 457 458 459 460 461

    if (virCommandRun(cmd, NULL) < 0) {
        virReportSystemError(errno,
                             _("Failed to make filesystem of "
                               "type '%s' on device '%s'"),
                             format, device);
        ret = -1;
    }
462 463

    virCommandFree(cmd);
O
Osier Yang 已提交
464 465
    return ret;
}
466 467 468 469 470
#else /* #ifdef MKFS */
static int
virStorageBackendExecuteMKFS(const char *device ATTRIBUTE_UNUSED,
                             const char *format ATTRIBUTE_UNUSED)
{
471 472 473 474 475
    virReportError(VIR_ERR_INTERNAL_ERROR,
                   _("mkfs is not supported on this platform: "
                     "Failed to make filesystem of "
                     "type '%s' on device '%s'"),
                   format, device);
476 477 478
    return -1;
}
#endif /* #ifdef MKFS */
O
Osier Yang 已提交
479 480 481 482 483

static int
virStorageBackendMakeFileSystem(virStoragePoolObjPtr pool,
                                unsigned int flags)
{
484
    virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
O
Osier Yang 已提交
485 486 487 488
    const char *device = NULL, *format = NULL;
    bool ok_to_mkfs = false;
    int ret = -1;

489
    if (def->source.devices == NULL) {
490 491
        virReportError(VIR_ERR_OPERATION_INVALID,
                       _("No source device specified when formatting pool '%s'"),
492
                       def->name);
O
Osier Yang 已提交
493 494 495
        goto error;
    }

496 497
    device = def->source.devices[0].path;
    format = virStoragePoolFormatFileSystemTypeToString(def->source.format);
O
Osier Yang 已提交
498 499 500
    VIR_DEBUG("source device: '%s' format: '%s'", device, format);

    if (!virFileExists(device)) {
501 502
        virReportError(VIR_ERR_OPERATION_INVALID,
                       _("Source device does not exist when formatting pool '%s'"),
503
                       def->name);
O
Osier Yang 已提交
504 505 506 507 508 509
        goto error;
    }

    if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) {
        ok_to_mkfs = true;
    } else if (flags & VIR_STORAGE_POOL_BUILD_NO_OVERWRITE &&
510
               virStorageBackendDeviceIsEmpty(device, format, true)) {
O
Osier Yang 已提交
511 512 513
        ok_to_mkfs = true;
    }

514
    if (ok_to_mkfs)
O
Osier Yang 已提交
515 516
        ret = virStorageBackendExecuteMKFS(device, format);

517
 error:
O
Osier Yang 已提交
518 519 520
    return ret;
}

521 522 523

/**
 * @pool storage pool to build
E
Eric Blake 已提交
524
 * @flags controls the pool formatting behaviour
525 526 527
 *
 * Build a directory or FS based storage pool.
 *
528 529 530 531 532 533 534 535 536
 * If no flag is set, it only makes the directory.
 *
 * If VIR_STORAGE_POOL_BUILD_NO_OVERWRITE set, it probes to determine if
 * any filesystem already exists on the target device, returning an error
 * if one exists. If no filesystem already exists, use mkfs to format the
 * target device.
 *
 * If VIR_STORAGE_POOL_BUILD_OVERWRITE is set, mkfs is always executed and
 * any existing data on the target device is overwritten unconditionally.
O
Osier Yang 已提交
537
 *
538
 * The underlying source device is mounted for FS based pools.
539 540 541 542
 *
 * Returns 0 on success, -1 on error
 */
static int
543
virStorageBackendFileSystemBuild(virStoragePoolObjPtr pool,
E
Eric Blake 已提交
544
                                 unsigned int flags)
545
{
O
Osier Yang 已提交
546
    virCheckFlags(VIR_STORAGE_POOL_BUILD_OVERWRITE |
547
                  VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, -1);
O
Osier Yang 已提交
548

549 550 551
    VIR_EXCLUSIVE_FLAGS_RET(VIR_STORAGE_POOL_BUILD_OVERWRITE,
                            VIR_STORAGE_POOL_BUILD_NO_OVERWRITE,
                            -1);
552

553
    if (virStorageBackendBuildLocal(pool) < 0)
554
        return -1;
555 556 557

    if (flags != 0)
        return virStorageBackendMakeFileSystem(pool, flags);
558 559 560 561 562

    return 0;
}


563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
#if WITH_STORAGE_FS

# define STORAGE_POOL_FS_NAMESPACE_HREF "http://libvirt.org/schemas/storagepool/source/fs/1.0"

/* Backend XML Namespace handling for fs or netfs specific mount options to
 * be added to the mount -o {options_list} command line that are not otherwise
 * supplied by supported XML. The XML will use the format, such as:
 *
 *     <fs:mount_opts>
 *       <fs:option name='sync'/>
 *       <fs:option name='lazytime'/>
 *     </fs:mount_opts>
 *
 * and the <pool type='fs'> or <pool type='netfs'> is required to have a
 * "xmlns:fs='%s'" attribute using the STORAGE_POOL_FS_NAMESPACE_HREF
 */

static void
virStoragePoolDefFSNamespaceFree(void *nsdata)
{
    virStoragePoolFSMountOptionsDefPtr cmdopts = nsdata;
    size_t i;

    if (!cmdopts)
        return;

    for (i = 0; i < cmdopts->noptions; i++)
        VIR_FREE(cmdopts->options[i]);
    VIR_FREE(cmdopts->options);

    VIR_FREE(cmdopts);
}


static int
virStoragePoolDefFSNamespaceParse(xmlXPathContextPtr ctxt,
                                  void **data)
{
    virStoragePoolFSMountOptionsDefPtr cmdopts = NULL;
    xmlNodePtr *nodes = NULL;
    int nnodes;
    size_t i;
    int ret = -1;

    if (xmlXPathRegisterNs(ctxt, BAD_CAST "fs",
                           BAD_CAST STORAGE_POOL_FS_NAMESPACE_HREF) < 0) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("Failed to register xml namespace '%s'"),
                       STORAGE_POOL_FS_NAMESPACE_HREF);
        return -1;
    }

    nnodes = virXPathNodeSet("./fs:mount_opts/fs:option", ctxt, &nodes);
    if (nnodes < 0)
        return -1;

    if (nnodes == 0)
        return 0;

    if (VIR_ALLOC(cmdopts) < 0 ||
        VIR_ALLOC_N(cmdopts->options, nnodes) < 0)
        goto cleanup;

    for (i = 0; i < nnodes; i++) {
        if (!(cmdopts->options[cmdopts->noptions] =
              virXMLPropString(nodes[i], "name"))) {
            virReportError(VIR_ERR_XML_ERROR, "%s",
                           _("no fs mount option name specified"));
            goto cleanup;
        }
        cmdopts->noptions++;
    }

    VIR_STEAL_PTR(*data, cmdopts);
    ret = 0;

 cleanup:
    VIR_FREE(nodes);
    virStoragePoolDefFSNamespaceFree(cmdopts);
    return ret;
}


static int
virStoragePoolDefFSNamespaceFormatXML(virBufferPtr buf,
                                      void *nsdata)
{
    size_t i;
    virStoragePoolFSMountOptionsDefPtr def = nsdata;

    if (!def)
        return 0;

    virBufferAddLit(buf, "<fs:mount_opts>\n");
    virBufferAdjustIndent(buf, 2);

    for (i = 0; i < def->noptions; i++)
        virBufferEscapeString(buf, "<fs:option name='%s'/>\n",
                              def->options[i]);

    virBufferAdjustIndent(buf, -2);
    virBufferAddLit(buf, "</fs:mount_opts>\n");

    return 0;
}


static const char *
virStoragePoolDefFSNamespaceHref(void)
{
    return "xmlns:fs='" STORAGE_POOL_FS_NAMESPACE_HREF "'";
}

#endif /* WITH_STORAGE_FS */


679 680 681 682
virStorageBackend virStorageBackendDirectory = {
    .type = VIR_STORAGE_POOL_DIR,

    .buildPool = virStorageBackendFileSystemBuild,
683
    .checkPool = virStorageBackendFileSystemCheck,
684 685
    .refreshPool = virStorageBackendRefreshLocal,
    .deletePool = virStorageBackendDeleteLocal,
686 687 688 689 690 691
    .buildVol = virStorageBackendVolBuildLocal,
    .buildVolFrom = virStorageBackendVolBuildFromLocal,
    .createVol = virStorageBackendVolCreateLocal,
    .refreshVol = virStorageBackendVolRefreshLocal,
    .deleteVol = virStorageBackendVolDeleteLocal,
    .resizeVol = virStorageBackendVolResizeLocal,
692 693
    .uploadVol = virStorageBackendVolUploadLocal,
    .downloadVol = virStorageBackendVolDownloadLocal,
694
    .wipeVol = virStorageBackendVolWipeLocal,
695 696 697 698 699 700 701
};

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

    .buildPool = virStorageBackendFileSystemBuild,
702
    .checkPool = virStorageBackendFileSystemCheck,
703
    .startPool = virStorageBackendFileSystemStart,
704
    .refreshPool = virStorageBackendRefreshLocal,
705
    .stopPool = virStorageBackendFileSystemStop,
706
    .deletePool = virStorageBackendDeleteLocal,
707 708 709 710 711 712
    .buildVol = virStorageBackendVolBuildLocal,
    .buildVolFrom = virStorageBackendVolBuildFromLocal,
    .createVol = virStorageBackendVolCreateLocal,
    .refreshVol = virStorageBackendVolRefreshLocal,
    .deleteVol = virStorageBackendVolDeleteLocal,
    .resizeVol = virStorageBackendVolResizeLocal,
713 714
    .uploadVol = virStorageBackendVolUploadLocal,
    .downloadVol = virStorageBackendVolDownloadLocal,
715
    .wipeVol = virStorageBackendVolWipeLocal,
716 717 718 719 720
};
virStorageBackend virStorageBackendNetFileSystem = {
    .type = VIR_STORAGE_POOL_NETFS,

    .buildPool = virStorageBackendFileSystemBuild,
721
    .checkPool = virStorageBackendFileSystemCheck,
722
    .startPool = virStorageBackendFileSystemStart,
723
    .findPoolSources = virStorageBackendFileSystemNetFindPoolSources,
724
    .refreshPool = virStorageBackendRefreshLocal,
725
    .stopPool = virStorageBackendFileSystemStop,
726
    .deletePool = virStorageBackendDeleteLocal,
727 728 729 730 731 732
    .buildVol = virStorageBackendVolBuildLocal,
    .buildVolFrom = virStorageBackendVolBuildFromLocal,
    .createVol = virStorageBackendVolCreateLocal,
    .refreshVol = virStorageBackendVolRefreshLocal,
    .deleteVol = virStorageBackendVolDeleteLocal,
    .resizeVol = virStorageBackendVolResizeLocal,
733 734
    .uploadVol = virStorageBackendVolUploadLocal,
    .downloadVol = virStorageBackendVolDownloadLocal,
735
    .wipeVol = virStorageBackendVolWipeLocal,
736
};
737 738 739 740 741 742 743

static virStoragePoolXMLNamespace virStoragePoolFSXMLNamespace = {
    .parse = virStoragePoolDefFSNamespaceParse,
    .free = virStoragePoolDefFSNamespaceFree,
    .format = virStoragePoolDefFSNamespaceFormatXML,
    .href = virStoragePoolDefFSNamespaceHref,
};
744
#endif /* WITH_STORAGE_FS */
745 746


747 748 749 750 751 752 753 754 755 756
int
virStorageBackendFsRegister(void)
{
    if (virStorageBackendRegister(&virStorageBackendDirectory) < 0)
        return -1;

#if WITH_STORAGE_FS
    if (virStorageBackendRegister(&virStorageBackendFileSystem) < 0)
        return -1;

757 758 759 760
    if (virStorageBackendNamespaceInit(VIR_STORAGE_POOL_FS,
                                       &virStoragePoolFSXMLNamespace) < 0)
        return -1;

761 762
    if (virStorageBackendRegister(&virStorageBackendNetFileSystem) < 0)
        return -1;
763 764 765 766

    if (virStorageBackendNamespaceInit(VIR_STORAGE_POOL_NETFS,
                                       &virStoragePoolFSXMLNamespace) < 0)
        return -1;
767 768 769 770
#endif /* WITH_STORAGE_FS */

    return 0;
}