15
15
* Lesser General Public License for more details.
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/>.
21
21
* Author: Daniel P. Berrange <berrange@redhat.com>
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"),
111
virReportError(VIR_ERR_INTERNAL_ERROR,
112
_("cannot probe backing volume format: %s"),
121
116
*backingStoreFormat = ret;
191
186
path = groups[0];
193
name = strrchr(path, '/');
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);
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);
206
200
if (!(src = virStoragePoolSourceListNewSource(&state->list)))
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) {
215
209
if (!(src->hosts[0].name = strdup(state->host)) ||
216
210
!(src->dir = strdup(path))) {
257
const char *prog[] = { SHOWMOUNT, "--no-headers", "--exports", NULL, NULL };
258
249
virStoragePoolSourcePtr source = NULL;
259
250
char *retval = NULL;
252
virCommandPtr cmd = NULL;
262
254
virCheckFlags(0, NULL);
264
source = virStoragePoolDefParseSourceString(srcSpec,
265
VIR_STORAGE_POOL_NETFS);
257
virReportError(VIR_ERR_INVALID_ARG,
258
"%s", _("hostname must be specified for netfs sources"));
262
if (!(source = virStoragePoolDefParseSourceString(srcSpec,
263
VIR_STORAGE_POOL_NETFS)))
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"));
275
272
state.host = source->hosts[0].name;
276
prog[3] = source->hosts[0].name;
278
if (virStorageBackendRunProgRegex(NULL, prog, 1, regexes, vars,
274
cmd = virCommandNewArgList(SHOWMOUNT,
277
source->hosts[0].name,
280
if (virStorageBackendRunProgRegex(NULL, cmd, 1, regexes, vars,
279
281
virStorageBackendFileSystemNetFindPoolSourcesFunc,
280
282
&state, NULL) < 0)
342
344
virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) {
344
const char **mntargv;
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);
356
const char *netfs_auto_argv[] = {
358
NULL, /* source path */
359
pool->def->target.path,
363
const char *fs_argv[] = {
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
371
pool->def->target.path,
375
const char *glusterfs_argv[] = {
378
pool->def->type == VIR_STORAGE_POOL_FS ?
379
virStoragePoolFormatFileSystemTypeToString(pool->def->source.format) :
380
virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format),
384
pool->def->target.path,
389
mntargv = netfs_auto_argv;
391
} else if (glusterfs) {
392
mntargv = glusterfs_argv;
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;
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"));
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"));
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"));
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"));
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);
447
mntargv[source_index] = src;
449
if (virRun(mntargv, NULL) < 0) {
404
cmd = virCommandNewArgList(MOUNT,
406
pool->def->target.path,
409
cmd = virCommandNewArgList( MOUNT,
411
(pool->def->type == VIR_STORAGE_POOL_FS ?
412
virStoragePoolFormatFileSystemTypeToString(pool->def->source.format) :
413
virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format)),
417
pool->def->target.path,
420
cmd = virCommandNewArgList(MOUNT,
422
(pool->def->type == VIR_STORAGE_POOL_FS ?
423
virStoragePoolFormatFileSystemTypeToString(pool->def->source.format) :
424
virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format)),
426
pool->def->target.path,
429
if (virCommandRun(cmd, NULL) < 0)
467
449
virStorageBackendFileSystemUnmount(virStoragePoolObjPtr pool) {
468
const char *mntargv[3];
450
virCommandPtr cmd = NULL;
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"));
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"));
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"));
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"));
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"),
560
virReportError(VIR_ERR_STORAGE_PROBE_FAILED,
561
_("Not capable of probing for "
562
"filesystem of type %s"),
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 "
569
virReportError(VIR_ERR_STORAGE_PROBE_FAILED,
570
_("Failed to create filesystem probe "
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 "
593
virReportError(VIR_ERR_STORAGE_POOL_BUILT,
594
_("Existing filesystem of type '%s' found on "
612
597
ret = FILESYSTEM_PROBE_FOUND;
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;
673
658
virStorageBackendExecuteMKFS(const char *device ATTRIBUTE_UNUSED,
674
659
const char *format ATTRIBUTE_UNUSED)
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'"),
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'"),
683
668
#endif /* #ifdef MKFS */
758
743
if (flags == (VIR_STORAGE_POOL_BUILD_OVERWRITE |
759
744
VIR_STORAGE_POOL_BUILD_NO_OVERWRITE)) {
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"));
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
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;
800
777
if ((err = virDirCreate(pool->def->target.path,
801
778
pool->def->target.perms.mode,
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
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);
1047
1025
virCheckFlags(0, -1);
1049
1027
if (inputvol) {
1050
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
1052
_("cannot copy from volume to a directory volume"));
1028
virReportError(VIR_ERR_INTERNAL_ERROR,
1030
_("cannot copy from volume to a directory volume"));
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;
1061
1034
if ((err = virDirCreate(vol->target.path, vol->target.perms.mode,
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) {
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 "
1059
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
1060
"%s", _("storage pool does not support "
1061
"building encrypted volumes from "
1091
1065
create_func = virStorageBackendGetBuildVolFromFunction(vol,
1152
1126
virCheckFlags(0, -1);
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'"),
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);
1148
case VIR_STORAGE_VOL_BLOCK:
1149
case VIR_STORAGE_VOL_NETWORK:
1151
virReportError(VIR_ERR_NO_SUPPORT,
1152
_("removing block or network volumes is not supported: %s"),