Merge pull request #12412 from ioito/hotfix/qx-xfs-lock

fix(host): xfs unlock
This commit is contained in:
Zexi Li
2021-10-15 09:46:28 +08:00
committed by GitHub
3 changed files with 20 additions and 19 deletions
+2 -2
View File
@@ -228,8 +228,8 @@ func ResizePartitionFs(fpath, fs string, raiseError bool) (error, bool) {
return nil, false
}
var (
cmds = [][]string{}
uuids = fileutils2.GetDevUuid(fpath)
cmds = [][]string{}
uuids, _ = fileutils2.GetDevUuid(fpath)
)
if strings.HasPrefix(fs, "linux-swap") {
if v, ok := uuids["UUID"]; ok {
+13 -13
View File
@@ -36,6 +36,7 @@ type SKVMGuestDiskPartition struct {
*SLocalGuestFS
partDev string
fs string
uuid string
readonly bool
sourceDev string
@@ -164,13 +165,13 @@ func (p *SKVMGuestDiskPartition) mount(readonly bool) error {
var err error
if fsType == "xfs" {
uuids := fileutils2.GetDevUuid(p.partDev)
uuid := uuids["UUID"]
if len(uuid) > 0 {
LockXfsPartition(uuid)
uuids, _ := fileutils2.GetDevUuid(p.partDev)
p.uuid, _ = uuids["UUID"]
if len(p.uuid) > 0 {
LockXfsPartition(p.uuid)
defer func() {
if err != nil {
UnlockXfsPartition(uuid)
UnlockXfsPartition(p.uuid)
}
}()
}
@@ -250,19 +251,18 @@ func (p *SKVMGuestDiskPartition) Umount() error {
return nil
}
defer func() {
if p.fs == "xfs" && len(p.uuid) > 0 {
UnlockXfsPartition(p.uuid)
}
}()
var tries = 0
var err error
for tries < 10 {
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)
}
}
if _, err := procutils.NewCommand("blockdev", "--flushbufs", p.partDev).Output(); err != nil {
log.Warningf("blockdev --flushbufs %s error: %v", p.partDev, err)
}
@@ -292,7 +292,7 @@ func (p *SKVMGuestDiskPartition) Zerofree() {
}
func (p *SKVMGuestDiskPartition) zerofreeSwap() {
uuids := fileutils2.GetDevUuid(p.partDev)
uuids, _ := fileutils2.GetDevUuid(p.partDev)
output, err := procutils.NewCommand("shred", "-n", "0", "-z", p.partDev).Output()
if err != nil {
log.Errorf("zerofree swap error: %s, %s", err, output)
+5 -4
View File
@@ -349,10 +349,11 @@ func GetDevId(spath string) string {
return strings.Join(data, ":")
}
func GetDevUuid(dev string) map[string]string {
func GetDevUuid(dev string) (map[string]string, error) {
lines, err := procutils.NewCommand("blkid", dev).Output()
if err != nil {
return nil
log.Errorf("GetDevUuid %s error: %v", dev, err)
return map[string]string{}, errors.Wrapf(err, "blkid")
}
for _, l := range strings.Split(string(lines), "\n") {
if strings.HasPrefix(l, dev) {
@@ -367,8 +368,8 @@ func GetDevUuid(dev string) map[string]string {
}
}
}
return ret
return ret, nil
}
}
return nil
return map[string]string{}, nil
}