fix mount xfs

This commit is contained in:
wanyaoqi
2020-08-10 16:07:41 +08:00
parent cad24ac69b
commit cdaff21269
2 changed files with 64 additions and 2 deletions
+24 -2
View File
@@ -103,7 +103,7 @@ func (p *SKVMGuestDiskPartition) MountPartReadOnly() bool {
func (p *SKVMGuestDiskPartition) Mount() bool {
if len(p.fs) == 0 || utils.IsInStringArray(p.fs, []string{"swap", "btrfs"}) {
log.Errorf("Mount fs failed: %s", p.fs)
log.Errorf("Mount fs failed: unsupport fs %s on %s", p.fs, p.partDev)
return false
}
err := p.fsck()
@@ -127,6 +127,7 @@ func (p *SKVMGuestDiskPartition) Mount() bool {
p.readonly = true
}
}
log.Infof("mount fs %s on %s success", p.fs, p.partDev)
return true
}
@@ -154,7 +155,21 @@ func (p *SKVMGuestDiskPartition) mount(readonly bool) error {
cmds = append(cmds, "-o", opt)
}
cmds = append(cmds, p.partDev, p.mountPath)
_, err := procutils.NewCommand(cmds[0], cmds[1:]...).Output()
var err error
if fsType == "xfs" {
uuids := fileutils2.GetDevUuid(p.partDev)
uuid := uuids["UUID"]
if len(uuid) > 0 {
LockXfsPartition(uuid)
defer func() {
if err != nil {
UnlockXfsPartition(uuid)
}
}()
}
}
_, err = procutils.NewCommand(cmds[0], cmds[1:]...).Output()
return err
}
@@ -217,6 +232,13 @@ func (p *SKVMGuestDiskPartition) Umount() bool {
tries += 1
_, err := procutils.NewCommand("umount", p.mountPath).Output()
if err == nil {
if p.fs == "xfs" {
uuids := fileutils2.GetDevUuid(p.partDev)
uuid := uuids["UUID"]
if len(uuid) > 0 {
UnlockXfsPartition(uuid)
}
}
procutils.NewCommand("blockdev", "--flushbufs", p.partDev).Output()
os.Remove(p.mountPath)
return true
+40
View File
@@ -0,0 +1,40 @@
package guestfs
import (
"sync"
"yunion.io/x/log"
)
func LockXfsPartition(uuid string) {
log.Infof("xfs lock %s", uuid)
var (
xfsLock *sync.Mutex
ok bool
)
mapLock.Lock()
xfsLock, ok = xfsMountUniqueTool[uuid]
if !ok {
xfsLock = new(sync.Mutex)
xfsMountUniqueTool[uuid] = xfsLock
}
mapLock.Unlock()
xfsLock.Lock()
}
func UnlockXfsPartition(uuid string) {
log.Infof("xfs unlock %s", uuid)
mapLock.Lock()
xfsLock := xfsMountUniqueTool[uuid]
mapLock.Unlock()
xfsLock.Unlock()
}
var (
mapLock = sync.Mutex{}
xfsMountUniqueTool = map[string]*sync.Mutex{}
)