From c22561e9f59c3126c3febbc29f74975f17dc1f77 Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Mon, 17 Dec 2018 13:33:08 +0800 Subject: [PATCH] temp --- pkg/hostman/guestfs/core.go | 36 +++++++++++++++++++++-------- pkg/hostman/storageman/core.go | 6 ++--- pkg/hostman/storageman/diskutils.go | 1 + 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/pkg/hostman/guestfs/core.go b/pkg/hostman/guestfs/core.go index 2a1fb7dd34..071bbb6c3e 100644 --- a/pkg/hostman/guestfs/core.go +++ b/pkg/hostman/guestfs/core.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "math/rand" "os" + "path" "strings" "yunion.io/x/jsonutils" @@ -38,21 +39,31 @@ func (f *SLocalGuestFS) isReadonly() bool { } } -func (f *SLocalGuestFS) getLocalPath(path string, caseInsensitive bool) string { +func (f *SLocalGuestFS) getLocalPath(sPath string, caseInsensitive bool) string { var fullPath = f.mountPath - pathSegs := strings.Split(path, "/") - for i := 0; i < len(pathSegs); i++ { - if len(pathSegs[i]) > 0 { - var readSeg string + pathSegs := strings.Split(sPath, "/") + for _, seg := range pathSegs { + if len(seg) > 0 { + var realSeg string files, _ := ioutil.ReadDir(fullPath) for _, file := range files { - if file.Name() == pathSegs[i] - || (caseInsensitive && strings.ToLower(file.Name())) == strings.ToLower(pathSegs[i]) { - + var f = file.Name() + if f == seg || (caseInsensitive && (strings.ToLower(f)) == strings.ToLower(seg)) || + (seg[len(seg)-1] == '*' && strings.HasPrefix(f, seg[:len(seg)-1])) || + (caseInsensitive && strings.HasPrefix(strings.ToLower(f), + strings.ToLower(seg[:len(seg)]))) { + realSeg = f + break } } + if len(realSeg) > 0 { + fullPath = path.Join(fullPath, realSeg) + } else { + return "" + } } } + return fullPath } func (f *SLocalGuestFS) Remove(path string, caseInsensitive bool) { @@ -69,11 +80,18 @@ func NewLocalGuestFS(mountPath string) *SLocalGuestFS { } type IRootFsDriver interface { + GetPartition() *SKVMGuestDiskPartition + String() string + TestRootfs() bool } var rootfsDrivers map[string]IRootFsDriver func DetectRootFs(part *SKVMGuestDiskPartition) IRootFsDriver { - //TODO + for k, v := range rootfsDrivers { + if v.TestRootfs(part) { + return v + } + } return nil } diff --git a/pkg/hostman/storageman/core.go b/pkg/hostman/storageman/core.go index b0741dabd4..eddebcc9a3 100644 --- a/pkg/hostman/storageman/core.go +++ b/pkg/hostman/storageman/core.go @@ -68,9 +68,9 @@ func (d *SBaseDisk) DeployGuestFs( if kvmDisk.Connect() { defer kvmDisk.Disconnect() log.Infof("Kvm Disk Connect Success !!") - if part := kvmDisk.Mount(); part != nil { - defer kvmDisk.Umount(part) - return part.DeployGuestFs(guestdesc, deployInfo) + if root := kvmDisk.Mount(); root != nil { + defer kvmDisk.Umount(root) + return root.DeployGuestFs(guestDesc, deployInfo) } } return nil, fmt.Errorf("Kvm disk connect or mount error") diff --git a/pkg/hostman/storageman/diskutils.go b/pkg/hostman/storageman/diskutils.go index 920a3b9eb4..3e7ac3b433 100644 --- a/pkg/hostman/storageman/diskutils.go +++ b/pkg/hostman/storageman/diskutils.go @@ -121,6 +121,7 @@ func (d *SKVMGuestDisk) Mount() guestfs.IRootFsDriver { for i := 0; i < d.partitions; i++ { if d.partitions[i].Mount() { if fs := guestfs.DetectRootFs(d.partitions[i]); fs != nil { + log.Infof("Use rootfs %s", fs) return fs } else { d.partitions[i].Umount()