diff --git a/internal/virt/guest/bot.go b/internal/virt/guest/bot.go index 749ff3d..59fe3d0 100644 --- a/internal/virt/guest/bot.go +++ b/internal/virt/guest/bot.go @@ -15,7 +15,6 @@ import ( "github.com/projecteru2/yavirt/internal/virt/domain" "github.com/projecteru2/yavirt/internal/virt/nic" "github.com/projecteru2/yavirt/internal/volume" - "github.com/projecteru2/yavirt/internal/volume/base" volFact "github.com/projecteru2/yavirt/internal/volume/factory" "github.com/projecteru2/yavirt/pkg/libvirt" "github.com/projecteru2/yavirt/pkg/terrors" @@ -245,7 +244,6 @@ func (v *bot) RestoreSnapshot(volmod volume.Volume, snapID string) error { // AttachVolume . func (v *bot) AttachVolume(vol volume.Volume) (rollback func(), err error) { - devName := vol.GetDevice() dom, err := v.dom.Lookup() if err != nil { return nil, errors.Wrap(err, "") @@ -271,7 +269,7 @@ func (v *bot) AttachVolume(vol volume.Volume) (rollback func(), err error) { st, err = dom.AttachDevice(string(buf)) if err == nil && st == libvirt.DomainRunning && configs.Conf.Storage.InitGuestVolume { log.Debugf(context.TODO(), "Mount(%s): start to mount volume(%s)", v.guest.ID, vol.GetMountDir()) - err = volFact.Mount(vol, v.ga, base.GetDevicePathByName(devName)) + err = volFact.Mount(vol, v.ga) } return } @@ -360,11 +358,11 @@ func (v *bot) setupVols() (err error) { if !configs.Conf.Storage.InitGuestVolume { return nil } - v.guest.rangeVolumes(func(sn int, vol volume.Volume) bool { + v.guest.rangeVolumes(func(_ int, vol volume.Volume) bool { if vol.IsSys() { return true } - err = volFact.Mount(vol, v.ga, base.GetDevicePathBySerialNumber(sn)) + err = volFact.Mount(vol, v.ga) return err == nil }) return diff --git a/internal/volume/factory/guest.go b/internal/volume/factory/guest.go index 960ee9c..57f90ac 100644 --- a/internal/volume/factory/guest.go +++ b/internal/volume/factory/guest.go @@ -193,7 +193,7 @@ func Umount(vol volume.Volume, ga agent.Interface) error { } // Mount . -func Mount(vol volume.Volume, ga agent.Interface, devPath string) error { +func Mount(vol volume.Volume, ga agent.Interface) error { if err := vol.Lock(); err != nil { return errors.Wrap(err, "") } @@ -201,5 +201,5 @@ func Mount(vol volume.Volume, ga agent.Interface, devPath string) error { var ctx, cancel = context.WithTimeout(context.Background(), configs.Conf.GADiskTimeout) defer cancel() - return vol.Mount(ctx, ga, devPath) + return vol.Mount(ctx, ga) } diff --git a/internal/volume/hostdir/volume.go b/internal/volume/hostdir/volume.go index c6ef886..4bf5460 100644 --- a/internal/volume/hostdir/volume.go +++ b/internal/volume/hostdir/volume.go @@ -99,7 +99,7 @@ func (v *Volume) Repair() error { // mount -t virtiofs mount_tag /mnt/mount/path // we use destination as mount tag -func (v *Volume) Mount(ctx context.Context, ga agent.Interface, _ string) error { +func (v *Volume) Mount(ctx context.Context, ga agent.Interface) error { const ( fs = "virtiofs" backupDump = 0 diff --git a/internal/volume/local/volume.go b/internal/volume/local/volume.go index aec41a3..f1ed5f6 100644 --- a/internal/volume/local/volume.go +++ b/internal/volume/local/volume.go @@ -246,7 +246,8 @@ func (v *Volume) Repair() error { return interutils.Repair(context.Background(), v.Filepath()) } -func (v *Volume) Mount(ctx context.Context, ga agent.Interface, devPath string) error { +func (v *Volume) Mount(ctx context.Context, ga agent.Interface) error { + devPath := base.GetDevicePathByName(v.GetDevice()) return base.MountBlockDevice(ctx, ga, v.Name(), devPath, v.GetMountDir()) } diff --git a/internal/volume/mocks/Volume.go b/internal/volume/mocks/Volume.go index 03d3648..0a7b4a7 100644 --- a/internal/volume/mocks/Volume.go +++ b/internal/volume/mocks/Volume.go @@ -446,17 +446,17 @@ func (_m *Volume) MetaKey() string { return r0 } -// Mount provides a mock function with given fields: ctx, ga, devPath -func (_m *Volume) Mount(ctx context.Context, ga agent.Interface, devPath string) error { - ret := _m.Called(ctx, ga, devPath) +// Mount provides a mock function with given fields: ctx, ga +func (_m *Volume) Mount(ctx context.Context, ga agent.Interface) error { + ret := _m.Called(ctx, ga) if len(ret) == 0 { panic("no return value specified for Mount") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, agent.Interface, string) error); ok { - r0 = rf(ctx, ga, devPath) + if rf, ok := ret.Get(0).(func(context.Context, agent.Interface) error); ok { + r0 = rf(ctx, ga) } else { r0 = ret.Error(0) } diff --git a/internal/volume/rbd/volume.go b/internal/volume/rbd/volume.go index 13eac08..2cd6bc3 100644 --- a/internal/volume/rbd/volume.go +++ b/internal/volume/rbd/volume.go @@ -147,7 +147,8 @@ func (v *Volume) Repair() error { return nil } -func (v *Volume) Mount(ctx context.Context, ga agent.Interface, devPath string) error { +func (v *Volume) Mount(ctx context.Context, ga agent.Interface) error { + devPath := base.GetDevicePathByName(v.GetDevice()) return base.MountBlockDevice(ctx, ga, v.Name(), devPath, v.GetMountDir()) } diff --git a/internal/volume/volume.go b/internal/volume/volume.go index 8e7a74b..100e553 100644 --- a/internal/volume/volume.go +++ b/internal/volume/volume.go @@ -36,7 +36,7 @@ type Volume interface { //nolint:interfacebloat Repair() error IsSys() bool - Mount(ctx context.Context, ga agent.Interface, devPath string) error + Mount(ctx context.Context, ga agent.Interface) error Umount(ctx context.Context, ga agent.Interface) error AmplifyOffline(ctx context.Context, delta int64) error AmplifyOnline(newCap int64, dom libvirt.Domain, ga agent.Interface) error