Skip to content

Commit 153a49b

Browse files
committed
Hhandle -o nouuid for XFS and detach via subprocess
1 parent 4e4d978 commit 153a49b

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ go mod tidy
2121
```
2222

2323
## Test
24-
TODO:
25-
- check if xfs bug manifests after fallocate
26-
- check if xfs bug manifests via docker containers
27-
- check if '-o nouuid' works with ext4
28-
- add '-o nouuid'
29-
3024
on ext4/xfs vs ext3
3125

3226
uid/gid - default & custom

manager/manager.go

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ import (
1515
var (
1616
NamePattern = `^[a-zA-Z0-9][\w\-]{1,250}$`
1717
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+
}
1828
)
1929

2030
type Manager struct {
@@ -126,12 +136,8 @@ func (m Manager) Create(name string, sizeInBytes int64, sparse bool, fs string,
126136
}
127137

128138
// 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 {
135141
return errors.Errorf(
136142
"Error creating volume '%s' - only xfs and ext4 filesystems are supported, '%s' requested",
137143
name, fs)
@@ -299,13 +305,18 @@ func (m Manager) Mount(name string, lease string) (string, error) {
299305
"Error mounting volume '%s' - cannot create mount point dir",
300306
name)
301307
}
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()
304314
if err != nil {
315+
errStr := strings.TrimSpace(string(errBytes[:]))
305316
_ = os.Remove(leaseFile) // attempt to cleanup
306317
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)
309320
}
310321
}
311322
return vol.MountPointPath, nil
@@ -349,11 +360,15 @@ func (m Manager) UnMount(name string, lease string) error {
349360
name, lease)
350361
}
351362

352-
err := syscall.Unmount(vol.MountPointPath, syscall.MNT_DETACH)
363+
errBytes, err := exec.Command(
364+
"umount",
365+
"-ld", vol.MountPointPath,
366+
).CombinedOutput()
353367
if err != nil {
368+
errStr := strings.TrimSpace(string(errBytes[:]))
354369
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)
357372
}
358373
err = os.RemoveAll(vol.MountPointPath)
359374
if err != nil {

0 commit comments

Comments
 (0)