@@ -15,6 +15,16 @@ import (
15
15
var (
16
16
NamePattern = `^[a-zA-Z0-9][\w\-]{1,250}$`
17
17
NameRegex = regexp .MustCompile (NamePattern )
18
+
19
+ MkFsOptions = map [string ][]string {
20
+ "ext4" : {"-F" },
21
+ "xfs" : {},
22
+ }
23
+
24
+ MountOptions = map [string ][]string {
25
+ "ext4" : {},
26
+ "xfs" : {"-o" , "nouuid" },
27
+ }
18
28
)
19
29
20
30
type Manager struct {
@@ -126,12 +136,8 @@ func (m Manager) Create(name string, sizeInBytes int64, sparse bool, fs string,
126
136
}
127
137
128
138
// We perform fs validation and construct mkfs flags array on the way
129
- var mkfsFlags []string
130
- if fs == "xfs" {
131
- mkfsFlags = []string {}
132
- } else if fs == "ext4" {
133
- mkfsFlags = []string {"-F" }
134
- } else {
139
+ mkfsFlags , ok := MkFsOptions [fs ]
140
+ if ! ok {
135
141
return errors .Errorf (
136
142
"Error creating volume '%s' - only xfs and ext4 filesystems are supported, '%s' requested" ,
137
143
name , fs )
@@ -299,13 +305,18 @@ func (m Manager) Mount(name string, lease string) (string, error) {
299
305
"Error mounting volume '%s' - cannot create mount point dir" ,
300
306
name )
301
307
}
302
- mountCmd := exec .Command ("mount" , vol .DataFilePath , vol .MountPointPath )
303
- _ , err = mountCmd .Output ()
308
+ // we should've validated FS by now if it's not found then we will get empty list of options
309
+ mountFlags := MountOptions [vol .Fs ]
310
+ errBytes , err := exec .Command (
311
+ "mount" ,
312
+ append (mountFlags , vol .DataFilePath , vol .MountPointPath )... ,
313
+ ).CombinedOutput ()
304
314
if err != nil {
315
+ errStr := strings .TrimSpace (string (errBytes [:]))
305
316
_ = os .Remove (leaseFile ) // attempt to cleanup
306
317
return failedResult , errors .Wrapf (err ,
307
- "Error mounting volume '%s' - cannot mount vessel '%s' at '%s'" ,
308
- name , vol .DataFilePath , vol .MountPointPath )
318
+ "Error mounting volume '%s' - cannot mount data file '%s' at '%s': %s " ,
319
+ name , vol .DataFilePath , vol .MountPointPath , errStr )
309
320
}
310
321
}
311
322
return vol .MountPointPath , nil
@@ -349,11 +360,15 @@ func (m Manager) UnMount(name string, lease string) error {
349
360
name , lease )
350
361
}
351
362
352
- err := syscall .Unmount (vol .MountPointPath , syscall .MNT_DETACH )
363
+ errBytes , err := exec .Command (
364
+ "umount" ,
365
+ "-ld" , vol .MountPointPath ,
366
+ ).CombinedOutput ()
353
367
if err != nil {
368
+ errStr := strings .TrimSpace (string (errBytes [:]))
354
369
return errors .Wrapf (err ,
355
- "Error un-mounting volume '%s' - cannot unmount vessel '%s' from mount point '%s'" ,
356
- name , vol .DataFilePath , vol .MountPointPath )
370
+ "Error un-mounting volume '%s' - cannot unmount data file '%s' from mount point '%s': %s " ,
371
+ name , vol .DataFilePath , vol .MountPointPath , errStr )
357
372
}
358
373
err = os .RemoveAll (vol .MountPointPath )
359
374
if err != nil {
0 commit comments