~ubuntu-branches/ubuntu/raring/libvirt/raring

« back to all changes in this revision

Viewing changes to src/storage/storage_backend_fs.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-11-19 10:41:02 UTC
  • mfrom: (1.2.15) (223.1.2 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121119104102-l6ewdppikysbzztu
Tags: 1.0.0-0ubuntu2
debian/patches/add-armhf-sysinfo-infomration.patch: Disable
to fix FTBFS on arm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * storage_backend_fs.c: storage backend for FS and directory handling
3
3
 *
4
 
 * Copyright (C) 2007-2011 Red Hat, Inc.
 
4
 * Copyright (C) 2007-2012 Red Hat, Inc.
5
5
 * Copyright (C) 2007-2008 Daniel P. Berrange
6
6
 *
7
7
 * This library is free software; you can redistribute it and/or
15
15
 * Lesser General Public License for more details.
16
16
 *
17
17
 * You should have received a copy of the GNU Lesser General Public
18
 
 * License along with this library; if not, write to the Free Software
19
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 
18
 * License along with this library.  If not, see
 
19
 * <http://www.gnu.org/licenses/>.
20
20
 *
21
21
 * Author: Daniel P. Berrange <berrange@redhat.com>
22
22
 */
68
68
{
69
69
    int fd = -1;
70
70
    int ret = -1;
71
 
    virStorageFileMetadata *meta;
72
 
 
73
 
    if (VIR_ALLOC(meta) < 0) {
74
 
        virReportOOMError();
75
 
        return ret;
76
 
    }
 
71
    virStorageFileMetadata *meta = NULL;
77
72
 
78
73
    *backingStore = NULL;
79
74
    *backingStoreFormat = VIR_STORAGE_FILE_AUTO;
96
91
        goto error;
97
92
    }
98
93
 
99
 
    if (virStorageFileGetMetadataFromFD(target->path, fd,
100
 
                                        target->format,
101
 
                                        meta) < 0) {
 
94
    if (!(meta = virStorageFileGetMetadataFromFD(target->path, fd,
 
95
                                                 target->format))) {
102
96
        ret = -1;
103
97
        goto error;
104
98
    }
108
102
    if (meta->backingStore) {
109
103
        *backingStore = meta->backingStore;
110
104
        meta->backingStore = NULL;
111
 
        if (meta->backingStoreFormat == VIR_STORAGE_FILE_AUTO) {
112
 
            if ((ret = virStorageFileProbeFormat(*backingStore)) < 0) {
 
105
        if (meta->backingStoreFormat == VIR_STORAGE_FILE_AUTO &&
 
106
            meta->backingStoreIsFile) {
 
107
            if ((ret = virStorageFileProbeFormat(*backingStore, -1, -1)) < 0) {
113
108
                /* If the backing file is currently unavailable, only log an error,
114
109
                 * but continue. Returning -1 here would disable the whole storage
115
110
                 * pool, making it unavailable for even maintenance. */
116
 
                virStorageReportError(VIR_ERR_INTERNAL_ERROR,
117
 
                                      _("cannot probe backing volume format: %s"),
118
 
                                      *backingStore);
 
111
                virReportError(VIR_ERR_INTERNAL_ERROR,
 
112
                               _("cannot probe backing volume format: %s"),
 
113
                               *backingStore);
119
114
                ret = -3;
120
115
            } else {
121
116
                *backingStoreFormat = ret;
190
185
 
191
186
    path = groups[0];
192
187
 
193
 
    name = strrchr(path, '/');
194
 
    if (name == NULL) {
195
 
        virStorageReportError(VIR_ERR_INTERNAL_ERROR,
196
 
                              _("invalid netfs path (no /): %s"), path);
 
188
    if (!(name = strrchr(path, '/'))) {
 
189
        virReportError(VIR_ERR_INTERNAL_ERROR,
 
190
                       _("invalid netfs path (no /): %s"), path);
197
191
        goto cleanup;
198
192
    }
199
193
    name += 1;
200
194
    if (*name == '\0') {
201
 
        virStorageReportError(VIR_ERR_INTERNAL_ERROR,
202
 
                              _("invalid netfs path (ends in /): %s"), path);
 
195
        virReportError(VIR_ERR_INTERNAL_ERROR,
 
196
                       _("invalid netfs path (ends in /): %s"), path);
203
197
        goto cleanup;
204
198
    }
205
199
 
206
200
    if (!(src = virStoragePoolSourceListNewSource(&state->list)))
207
201
        goto cleanup;
208
202
 
209
 
    if (src->nhost != 1) {
210
 
        virStorageReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
211
 
                              _("Expected exactly 1 host for the storage pool"));
 
203
    if (VIR_ALLOC_N(src->hosts, 1) < 0) {
 
204
        virReportOOMError();
212
205
        goto cleanup;
213
206
    }
 
207
    src->nhost = 1;
214
208
 
215
209
    if (!(src->hosts[0].name = strdup(state->host)) ||
216
210
        !(src->dir = strdup(path))) {
219
213
    }
220
214
    src->format = VIR_STORAGE_POOL_NETFS_NFS;
221
215
 
222
 
    src = NULL;
223
216
    ret = 0;
224
217
cleanup:
225
 
    virStoragePoolSourceFree(src);
226
218
    return ret;
227
219
}
228
220
 
254
246
            .sources = NULL
255
247
        }
256
248
    };
257
 
    const char *prog[] = { SHOWMOUNT, "--no-headers", "--exports", NULL, NULL };
258
249
    virStoragePoolSourcePtr source = NULL;
259
250
    char *retval = NULL;
260
251
    unsigned int i;
 
252
    virCommandPtr cmd = NULL;
261
253
 
262
254
    virCheckFlags(0, NULL);
263
255
 
264
 
    source = virStoragePoolDefParseSourceString(srcSpec,
265
 
                                                VIR_STORAGE_POOL_NETFS);
266
 
    if (!source)
267
 
        goto cleanup;
 
256
    if (!srcSpec) {
 
257
        virReportError(VIR_ERR_INVALID_ARG,
 
258
                       "%s", _("hostname must be specified for netfs sources"));
 
259
        return NULL;
 
260
    }
 
261
 
 
262
    if (!(source = virStoragePoolDefParseSourceString(srcSpec,
 
263
                                                      VIR_STORAGE_POOL_NETFS)))
 
264
        return NULL;
268
265
 
269
266
    if (source->nhost != 1) {
270
 
        virStorageReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
271
 
                              _("Expected exactly 1 host for the storage pool"));
 
267
        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
 
268
                       _("Expected exactly 1 host for the storage pool"));
272
269
        goto cleanup;
273
270
    }
274
271
 
275
272
    state.host = source->hosts[0].name;
276
 
    prog[3] = source->hosts[0].name;
277
 
 
278
 
    if (virStorageBackendRunProgRegex(NULL, prog, 1, regexes, vars,
 
273
 
 
274
    cmd = virCommandNewArgList(SHOWMOUNT,
 
275
                               "--no-headers",
 
276
                               "--exports",
 
277
                               source->hosts[0].name,
 
278
                               NULL);
 
279
 
 
280
    if (virStorageBackendRunProgRegex(NULL, cmd, 1, regexes, vars,
279
281
                            virStorageBackendFileSystemNetFindPoolSourcesFunc,
280
282
                            &state, NULL) < 0)
281
283
        goto cleanup;
292
294
    VIR_FREE(state.list.sources);
293
295
 
294
296
    virStoragePoolSourceFree(source);
295
 
 
 
297
    virCommandFree(cmd);
296
298
    return retval;
297
299
}
298
300
 
340
342
 */
341
343
static int
342
344
virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) {
343
 
    char *src;
344
 
    const char **mntargv;
345
 
 
 
345
    char *src = NULL;
346
346
    /* 'mount -t auto' doesn't seem to auto determine nfs (or cifs),
347
347
     *  while plain 'mount' does. We have to craft separate argvs to
348
348
     *  accommodate this */
349
 
    int netauto = (pool->def->type == VIR_STORAGE_POOL_NETFS &&
350
 
                   pool->def->source.format == VIR_STORAGE_POOL_NETFS_AUTO);
351
 
    int glusterfs = (pool->def->type == VIR_STORAGE_POOL_NETFS &&
352
 
                 pool->def->source.format == VIR_STORAGE_POOL_NETFS_GLUSTERFS);
353
 
 
354
 
    int source_index;
355
 
 
356
 
    const char *netfs_auto_argv[] = {
357
 
        MOUNT,
358
 
        NULL, /* source path */
359
 
        pool->def->target.path,
360
 
        NULL,
361
 
    };
362
 
 
363
 
    const char *fs_argv[] =  {
364
 
        MOUNT,
365
 
        "-t",
366
 
        pool->def->type == VIR_STORAGE_POOL_FS ?
367
 
        virStoragePoolFormatFileSystemTypeToString(pool->def->source.format) :
368
 
        virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format),
369
 
        NULL, /* Fill in shortly - careful not to add extra fields
370
 
                 before this */
371
 
        pool->def->target.path,
372
 
        NULL,
373
 
    };
374
 
 
375
 
    const char *glusterfs_argv[] = {
376
 
        MOUNT,
377
 
        "-t",
378
 
        pool->def->type == VIR_STORAGE_POOL_FS ?
379
 
        virStoragePoolFormatFileSystemTypeToString(pool->def->source.format) :
380
 
        virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format),
381
 
        NULL,
382
 
        "-o",
383
 
        "direct-io-mode=1",
384
 
        pool->def->target.path,
385
 
        NULL,
386
 
    };
387
 
 
388
 
    if (netauto) {
389
 
        mntargv = netfs_auto_argv;
390
 
        source_index = 1;
391
 
    } else if (glusterfs) {
392
 
        mntargv = glusterfs_argv;
393
 
        source_index = 3;
394
 
    } else {
395
 
        mntargv = fs_argv;
396
 
        source_index = 3;
397
 
    }
398
 
 
399
 
    int ret;
 
349
    bool netauto = (pool->def->type == VIR_STORAGE_POOL_NETFS &&
 
350
                    pool->def->source.format == VIR_STORAGE_POOL_NETFS_AUTO);
 
351
    bool glusterfs = (pool->def->type == VIR_STORAGE_POOL_NETFS &&
 
352
                      pool->def->source.format == VIR_STORAGE_POOL_NETFS_GLUSTERFS);
 
353
    virCommandPtr cmd = NULL;
 
354
    int ret = -1;
400
355
 
401
356
    if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
402
357
        if (pool->def->source.nhost != 1) {
403
 
            virStorageReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
404
 
                                  _("Expected exactly 1 host for the storage pool"));
 
358
            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
 
359
                           _("Expected exactly 1 host for the storage pool"));
405
360
            return -1;
406
361
        }
407
362
        if (pool->def->source.hosts[0].name == NULL) {
408
 
            virStorageReportError(VIR_ERR_INTERNAL_ERROR,
409
 
                                  "%s", _("missing source host"));
 
363
            virReportError(VIR_ERR_INTERNAL_ERROR,
 
364
                           "%s", _("missing source host"));
410
365
            return -1;
411
366
        }
412
367
        if (pool->def->source.dir == NULL) {
413
 
            virStorageReportError(VIR_ERR_INTERNAL_ERROR,
414
 
                                  "%s", _("missing source path"));
 
368
            virReportError(VIR_ERR_INTERNAL_ERROR,
 
369
                           "%s", _("missing source path"));
415
370
            return -1;
416
371
        }
417
372
    } else {
418
373
        if (pool->def->source.ndevice != 1) {
419
 
            virStorageReportError(VIR_ERR_INTERNAL_ERROR,
420
 
                                  "%s", _("missing source device"));
 
374
            virReportError(VIR_ERR_INTERNAL_ERROR,
 
375
                           "%s", _("missing source device"));
421
376
            return -1;
422
377
        }
423
378
    }
424
379
 
425
380
    /* Short-circuit if already mounted */
426
381
    if ((ret = virStorageBackendFileSystemIsMounted(pool)) != 0) {
427
 
        virStorageReportError(VIR_ERR_OPERATION_INVALID,
428
 
                              _("Target '%s' is already mounted"),
429
 
                              pool->def->target.path);
 
382
        virReportError(VIR_ERR_OPERATION_INVALID,
 
383
                       _("Target '%s' is already mounted"),
 
384
                       pool->def->target.path);
430
385
        return -1;
431
386
    }
432
387
 
444
399
            return -1;
445
400
        }
446
401
    }
447
 
    mntargv[source_index] = src;
448
 
 
449
 
    if (virRun(mntargv, NULL) < 0) {
450
 
        VIR_FREE(src);
451
 
        return -1;
452
 
    }
 
402
 
 
403
    if (netauto)
 
404
        cmd = virCommandNewArgList(MOUNT,
 
405
                                   src,
 
406
                                   pool->def->target.path,
 
407
                                   NULL);
 
408
    else if (glusterfs)
 
409
        cmd = virCommandNewArgList( MOUNT,
 
410
                                    "-t",
 
411
                                    (pool->def->type == VIR_STORAGE_POOL_FS ?
 
412
                                     virStoragePoolFormatFileSystemTypeToString(pool->def->source.format) :
 
413
                                     virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format)),
 
414
                                    src,
 
415
                                    "-o",
 
416
                                    "direct-io-mode=1",
 
417
                                    pool->def->target.path,
 
418
                                    NULL);
 
419
    else
 
420
        cmd = virCommandNewArgList(MOUNT,
 
421
                                   "-t",
 
422
                                   (pool->def->type == VIR_STORAGE_POOL_FS ?
 
423
                                    virStoragePoolFormatFileSystemTypeToString(pool->def->source.format) :
 
424
                                    virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format)),
 
425
                                   src,
 
426
                                   pool->def->target.path,
 
427
                                   NULL);
 
428
 
 
429
    if (virCommandRun(cmd, NULL) < 0)
 
430
        goto cleanup;
 
431
 
 
432
    ret = 0;
 
433
cleanup:
 
434
    virCommandFree(cmd);
453
435
    VIR_FREE(src);
454
 
    return 0;
 
436
    return ret;
455
437
}
456
438
 
457
439
/**
465
447
 */
466
448
static int
467
449
virStorageBackendFileSystemUnmount(virStoragePoolObjPtr pool) {
468
 
    const char *mntargv[3];
469
 
    int ret;
 
450
    virCommandPtr cmd = NULL;
 
451
    int ret = -1;
470
452
 
471
453
    if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
472
454
        if (pool->def->source.nhost != 1) {
473
 
            virStorageReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
474
 
                                  _("Expected exactly 1 host for the storage pool"));
 
455
            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
 
456
                           _("Expected exactly 1 host for the storage pool"));
475
457
            return -1;
476
458
        }
477
459
        if (pool->def->source.hosts[0].name == NULL) {
478
 
            virStorageReportError(VIR_ERR_INTERNAL_ERROR,
479
 
                                  "%s", _("missing source host"));
 
460
            virReportError(VIR_ERR_INTERNAL_ERROR,
 
461
                           "%s", _("missing source host"));
480
462
            return -1;
481
463
        }
482
464
        if (pool->def->source.dir == NULL) {
483
 
            virStorageReportError(VIR_ERR_INTERNAL_ERROR,
484
 
                                  "%s", _("missing source dir"));
 
465
            virReportError(VIR_ERR_INTERNAL_ERROR,
 
466
                           "%s", _("missing source dir"));
485
467
            return -1;
486
468
        }
487
469
    } else {
488
470
        if (pool->def->source.ndevice != 1) {
489
 
            virStorageReportError(VIR_ERR_INTERNAL_ERROR,
490
 
                                  "%s", _("missing source device"));
 
471
            virReportError(VIR_ERR_INTERNAL_ERROR,
 
472
                           "%s", _("missing source device"));
491
473
            return -1;
492
474
        }
493
475
    }
500
482
            return 0;
501
483
    }
502
484
 
503
 
    mntargv[0] = UMOUNT;
504
 
    mntargv[1] = pool->def->target.path;
505
 
    mntargv[2] = NULL;
506
 
 
507
 
    if (virRun(mntargv, NULL) < 0) {
508
 
        return -1;
509
 
    }
510
 
    return 0;
 
485
    cmd = virCommandNewArgList(UMOUNT,
 
486
                               pool->def->target.path,
 
487
                               NULL);
 
488
 
 
489
    if (virCommandRun(cmd, NULL) < 0)
 
490
        goto cleanup;
 
491
 
 
492
    ret = 0;
 
493
cleanup:
 
494
    virCommandFree(cmd);
 
495
    return ret;
511
496
}
512
497
#endif /* WITH_STORAGE_FS */
513
498
 
572
557
              format, device);
573
558
 
574
559
    if (blkid_known_fstype(format) == 0) {
575
 
        virStorageReportError(VIR_ERR_STORAGE_PROBE_FAILED,
576
 
                              _("Not capable of probing for "
577
 
                                "filesystem of type %s"),
578
 
                              format);
 
560
        virReportError(VIR_ERR_STORAGE_PROBE_FAILED,
 
561
                       _("Not capable of probing for "
 
562
                         "filesystem of type %s"),
 
563
                       format);
579
564
        goto error;
580
565
    }
581
566
 
582
567
    probe = blkid_new_probe_from_filename(device);
583
568
    if (probe == NULL) {
584
 
        virStorageReportError(VIR_ERR_STORAGE_PROBE_FAILED,
585
 
                                  _("Failed to create filesystem probe "
586
 
                                  "for device %s"),
587
 
                                  device);
 
569
        virReportError(VIR_ERR_STORAGE_PROBE_FAILED,
 
570
                       _("Failed to create filesystem probe "
 
571
                         "for device %s"),
 
572
                       device);
588
573
        goto error;
589
574
    }
590
575
 
605
590
                 format, device);
606
591
        ret = FILESYSTEM_PROBE_NOT_FOUND;
607
592
    } else if (blkid_probe_lookup_value(probe, "TYPE", &fstype, NULL) == 0) {
608
 
        virStorageReportError(VIR_ERR_STORAGE_POOL_BUILT,
609
 
                              _("Existing filesystem of type '%s' found on "
610
 
                                "device '%s'"),
611
 
                              fstype, device);
 
593
        virReportError(VIR_ERR_STORAGE_POOL_BUILT,
 
594
                       _("Existing filesystem of type '%s' found on "
 
595
                         "device '%s'"),
 
596
                       fstype, device);
612
597
        ret = FILESYSTEM_PROBE_FOUND;
613
598
    }
614
599
 
615
600
    if (blkid_do_probe(probe) != 1) {
616
 
        virStorageReportError(VIR_ERR_STORAGE_PROBE_FAILED,
617
 
                                  _("Found additional probes to run, "
618
 
                                    "filesystem probing may be incorrect"));
 
601
        virReportError(VIR_ERR_STORAGE_PROBE_FAILED, "%s",
 
602
                       _("Found additional probes to run, "
 
603
                         "filesystem probing may be incorrect"));
619
604
        ret = FILESYSTEM_PROBE_ERROR;
620
605
    }
621
606
 
635
620
virStorageBackendFileSystemProbe(const char *device ATTRIBUTE_UNUSED,
636
621
                                 const char *format ATTRIBUTE_UNUSED)
637
622
{
638
 
    virStorageReportError(VIR_ERR_OPERATION_INVALID,
639
 
                          _("probing for filesystems is unsupported "
640
 
                            "by this build"));
 
623
    virReportError(VIR_ERR_OPERATION_INVALID, "%s",
 
624
                   _("probing for filesystems is unsupported "
 
625
                     "by this build"));
641
626
 
642
627
    return FILESYSTEM_PROBE_ERROR;
643
628
}
673
658
virStorageBackendExecuteMKFS(const char *device ATTRIBUTE_UNUSED,
674
659
                             const char *format ATTRIBUTE_UNUSED)
675
660
{
676
 
    virStorageReportError(VIR_ERR_INTERNAL_ERROR,
677
 
                              _("mkfs is not supported on this platform: "
678
 
                                "Failed to make filesystem of "
679
 
                               "type '%s' on device '%s'"),
680
 
                             format, device);
 
661
    virReportError(VIR_ERR_INTERNAL_ERROR,
 
662
                   _("mkfs is not supported on this platform: "
 
663
                     "Failed to make filesystem of "
 
664
                     "type '%s' on device '%s'"),
 
665
                   format, device);
681
666
    return -1;
682
667
}
683
668
#endif /* #ifdef MKFS */
691
676
    int ret = -1;
692
677
 
693
678
    if (pool->def->source.devices == NULL) {
694
 
        virStorageReportError(VIR_ERR_OPERATION_INVALID,
695
 
                              _("No source device specified when formatting pool '%s'"),
696
 
                              pool->def->name);
 
679
        virReportError(VIR_ERR_OPERATION_INVALID,
 
680
                       _("No source device specified when formatting pool '%s'"),
 
681
                       pool->def->name);
697
682
        goto error;
698
683
    }
699
684
 
702
687
    VIR_DEBUG("source device: '%s' format: '%s'", device, format);
703
688
 
704
689
    if (!virFileExists(device)) {
705
 
        virStorageReportError(VIR_ERR_OPERATION_INVALID,
706
 
                              _("Source device does not exist when formatting pool '%s'"),
707
 
                              pool->def->name);
 
690
        virReportError(VIR_ERR_OPERATION_INVALID,
 
691
                       _("Source device does not exist when formatting pool '%s'"),
 
692
                       pool->def->name);
708
693
        goto error;
709
694
    }
710
695
 
758
743
    if (flags == (VIR_STORAGE_POOL_BUILD_OVERWRITE |
759
744
                  VIR_STORAGE_POOL_BUILD_NO_OVERWRITE)) {
760
745
 
761
 
        virStorageReportError(VIR_ERR_OPERATION_INVALID,
762
 
                              _("Overwrite and no overwrite flags"
763
 
                                " are mutually exclusive"));
 
746
        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
 
747
                       _("Overwrite and no overwrite flags"
 
748
                         " are mutually exclusive"));
764
749
        goto error;
765
750
    }
766
751
 
769
754
        goto error;
770
755
    }
771
756
    if (!(p = strrchr(parent, '/'))) {
772
 
        virStorageReportError(VIR_ERR_INVALID_ARG,
773
 
                              _("path '%s' is not absolute"),
774
 
                              pool->def->target.path);
 
757
        virReportError(VIR_ERR_INVALID_ARG,
 
758
                       _("path '%s' is not absolute"),
 
759
                       pool->def->target.path);
775
760
        goto error;
776
761
    }
777
762
 
789
774
    /* Now create the final dir in the path with the uid/gid/mode
790
775
     * requested in the config. If the dir already exists, just set
791
776
     * the perms. */
792
 
    uid_t uid;
793
 
    gid_t gid;
794
 
 
795
 
    uid = (pool->def->target.perms.uid == (uid_t) -1)
796
 
        ? getuid() : pool->def->target.perms.uid;
797
 
    gid = (pool->def->target.perms.gid == (gid_t) -1)
798
 
        ? getgid() : pool->def->target.perms.gid;
799
 
 
800
777
    if ((err = virDirCreate(pool->def->target.path,
801
778
                            pool->def->target.perms.mode,
802
 
                            uid, gid,
 
779
                            pool->def->target.perms.uid,
 
780
                            pool->def->target.perms.gid,
803
781
                            VIR_DIR_CREATE_FORCE_PERMS |
804
782
                            VIR_DIR_CREATE_ALLOW_EXIST |
805
783
                            (pool->def->type == VIR_STORAGE_POOL_NETFS
811
789
 
812
790
    /* Reflect the actual uid and gid to the config. */
813
791
    if (pool->def->target.perms.uid == (uid_t) -1)
814
 
        pool->def->target.perms.uid = uid;
 
792
        pool->def->target.perms.uid = getuid();
815
793
    if (pool->def->target.perms.gid == (gid_t) -1)
816
 
        pool->def->target.perms.gid = gid;
 
794
        pool->def->target.perms.gid = getgid();
817
795
 
818
796
    if (flags != 0) {
819
797
        ret = virStorageBackendMakeFileSystem(pool, flags);
908
886
                 * Unfortunately virStorageBackendProbeTarget() might already
909
887
                 * have logged a similar message for the same problem, but only
910
888
                 * if AUTO format detection was used. */
911
 
                virStorageReportError(VIR_ERR_INTERNAL_ERROR,
912
 
                                      _("cannot probe backing volume info: %s"),
913
 
                                      vol->backingStore.path);
 
889
                virReportError(VIR_ERR_INTERNAL_ERROR,
 
890
                               _("cannot probe backing volume info: %s"),
 
891
                               vol->backingStore.path);
914
892
            }
915
893
        }
916
894
 
1047
1025
    virCheckFlags(0, -1);
1048
1026
 
1049
1027
    if (inputvol) {
1050
 
        virStorageReportError(VIR_ERR_INTERNAL_ERROR,
1051
 
                              "%s",
1052
 
                              _("cannot copy from volume to a directory volume"));
 
1028
        virReportError(VIR_ERR_INTERNAL_ERROR,
 
1029
                       "%s",
 
1030
                       _("cannot copy from volume to a directory volume"));
1053
1031
        return -1;
1054
1032
    }
1055
1033
 
1056
 
    uid_t uid = (vol->target.perms.uid == -1)
1057
 
        ? getuid() : vol->target.perms.uid;
1058
 
    gid_t gid = (vol->target.perms.gid == -1)
1059
 
        ? getgid() : vol->target.perms.gid;
1060
 
 
1061
1034
    if ((err = virDirCreate(vol->target.path, vol->target.perms.mode,
1062
 
                            uid, gid,
 
1035
                            vol->target.perms.uid,
 
1036
                            vol->target.perms.gid,
1063
1037
                            VIR_DIR_CREATE_FORCE_PERMS |
1064
1038
                            (pool->def->type == VIR_STORAGE_POOL_NETFS
1065
1039
                             ? VIR_DIR_CREATE_AS_UID : 0))) < 0) {
1082
1056
 
1083
1057
    if (inputvol) {
1084
1058
        if (vol->target.encryption != NULL) {
1085
 
            virStorageReportError(VIR_ERR_CONFIG_UNSUPPORTED,
1086
 
                                  "%s", _("storage pool does not support "
1087
 
                                          "building encrypted volumes from "
1088
 
                                          "other volumes"));
 
1059
            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
 
1060
                           "%s", _("storage pool does not support "
 
1061
                                   "building encrypted volumes from "
 
1062
                                   "other volumes"));
1089
1063
            return -1;
1090
1064
        }
1091
1065
        create_func = virStorageBackendGetBuildVolFromFunction(vol,
1102
1076
        if (!create_func)
1103
1077
            return -1;
1104
1078
    } else {
1105
 
        virStorageReportError(VIR_ERR_INTERNAL_ERROR,
1106
 
                              "%s", _("creation of non-raw images "
1107
 
                                      "is not supported without qemu-img"));
 
1079
        virReportError(VIR_ERR_INTERNAL_ERROR,
 
1080
                       "%s", _("creation of non-raw images "
 
1081
                               "is not supported without qemu-img"));
1108
1082
        return -1;
1109
1083
    }
1110
1084
 
1141
1115
}
1142
1116
 
1143
1117
/**
1144
 
 * Remove a volume - just unlinks for now
 
1118
 * Remove a volume - no support for BLOCK and NETWORK yet
1145
1119
 */
1146
1120
static int
1147
1121
virStorageBackendFileSystemVolDelete(virConnectPtr conn ATTRIBUTE_UNUSED,
1151
1125
{
1152
1126
    virCheckFlags(0, -1);
1153
1127
 
1154
 
    if (unlink(vol->target.path) < 0) {
1155
 
        /* Silently ignore failures where the vol has already gone away */
1156
 
        if (errno != ENOENT) {
 
1128
    switch (vol->type) {
 
1129
    case VIR_STORAGE_VOL_FILE:
 
1130
        if (unlink(vol->target.path) < 0) {
 
1131
            /* Silently ignore failures where the vol has already gone away */
 
1132
            if (errno != ENOENT) {
 
1133
                virReportSystemError(errno,
 
1134
                                     _("cannot unlink file '%s'"),
 
1135
                                     vol->target.path);
 
1136
                return -1;
 
1137
            }
 
1138
        }
 
1139
        break;
 
1140
    case VIR_STORAGE_VOL_DIR:
 
1141
        if (rmdir(vol->target.path) < 0) {
1157
1142
            virReportSystemError(errno,
1158
 
                                 _("cannot unlink file '%s'"),
 
1143
                                 _("cannot remove directory '%s'"),
1159
1144
                                 vol->target.path);
1160
1145
            return -1;
1161
1146
        }
 
1147
        break;
 
1148
    case VIR_STORAGE_VOL_BLOCK:
 
1149
    case VIR_STORAGE_VOL_NETWORK:
 
1150
    default:
 
1151
        virReportError(VIR_ERR_NO_SUPPORT,
 
1152
                       _("removing block or network volumes is not supported: %s"),
 
1153
                       vol->target.path);
 
1154
        return -1;
1162
1155
    }
1163
1156
    return 0;
1164
1157
}
1225
1218
        img_tool = virFindFileInPath("qemu-img");
1226
1219
 
1227
1220
    if (!img_tool) {
1228
 
        virStorageReportError(VIR_ERR_INTERNAL_ERROR,
1229
 
                              "%s", _("unable to find kvm-img or qemu-img"));
 
1221
        virReportError(VIR_ERR_INTERNAL_ERROR,
 
1222
                       "%s", _("unable to find kvm-img or qemu-img"));
1230
1223
        return -1;
1231
1224
    }
1232
1225