Skip to content

Commit

Permalink
style(import): remove camel casing in alias
Browse files Browse the repository at this point in the history
Signed-off-by: Chin-Ya Huang <chin-ya.huang@suse.com>
  • Loading branch information
c3y1huang authored and derekbit committed Sep 20, 2024
1 parent ac00cae commit 24cbc38
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 114 deletions.
16 changes: 8 additions & 8 deletions pkg/spdk/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (

"github.com/longhorn/backupstore"
btypes "github.com/longhorn/backupstore/types"
commonBitmap "github.com/longhorn/go-common-libs/bitmap"
commonNet "github.com/longhorn/go-common-libs/net"
commonNs "github.com/longhorn/go-common-libs/ns"
commonTypes "github.com/longhorn/go-common-libs/types"
commonbitmap "github.com/longhorn/go-common-libs/bitmap"
commonnet "github.com/longhorn/go-common-libs/net"
commonns "github.com/longhorn/go-common-libs/ns"
commontypes "github.com/longhorn/go-common-libs/types"
"github.com/longhorn/go-spdk-helper/pkg/nvme"
spdkclient "github.com/longhorn/go-spdk-helper/pkg/spdk/client"
helpertypes "github.com/longhorn/go-spdk-helper/pkg/types"
Expand Down Expand Up @@ -58,13 +58,13 @@ type Backup struct {
controllerName string
initiator *nvme.Initiator
devFh *os.File
executor *commonNs.Executor
executor *commonns.Executor

log logrus.FieldLogger
}

// NewBackup creates a new backup instance
func NewBackup(spdkClient *spdkclient.Client, backupName, volumeName, snapshotName string, replica *Replica, superiorPortAllocator *commonBitmap.Bitmap) (*Backup, error) {
func NewBackup(spdkClient *spdkclient.Client, backupName, volumeName, snapshotName string, replica *Replica, superiorPortAllocator *commonbitmap.Bitmap) (*Backup, error) {
log := logrus.WithFields(logrus.Fields{
"backupName": backupName,
"volumeName": volumeName,
Expand All @@ -73,7 +73,7 @@ func NewBackup(spdkClient *spdkclient.Client, backupName, volumeName, snapshotNa

log.Info("Initializing backup")

podIP, err := commonNet.GetIPForPod()
podIP, err := commonnet.GetIPForPod()
if err != nil {
return nil, err
}
Expand All @@ -83,7 +83,7 @@ func NewBackup(spdkClient *spdkclient.Client, backupName, volumeName, snapshotNa
return nil, err
}

executor, err := helperutil.NewExecutor(commonTypes.ProcDirectory)
executor, err := helperutil.NewExecutor(commontypes.ProcDirectory)
if err != nil {
return nil, errors.Wrapf(err, "failed to create executor")
}
Expand Down
26 changes: 13 additions & 13 deletions pkg/spdk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
grpcstatus "google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"

commonTypes "github.com/longhorn/go-common-libs/types"
commontypes "github.com/longhorn/go-common-libs/types"
"github.com/longhorn/go-spdk-helper/pkg/jsonrpc"
spdkclient "github.com/longhorn/go-spdk-helper/pkg/spdk/client"
spdktypes "github.com/longhorn/go-spdk-helper/pkg/spdk/types"
Expand Down Expand Up @@ -55,7 +55,7 @@ func svcDiskCreate(spdkClient *spdkclient.Client, diskName, diskUUID, diskPath,
return nil, grpcstatus.Error(grpccodes.InvalidArgument, "disk name and disk path are required")
}

exactDiskDriver, err := disk.GetDiskDriver(commonTypes.DiskDriver(diskDriver), diskPath)
exactDiskDriver, err := disk.GetDiskDriver(commontypes.DiskDriver(diskDriver), diskPath)
if err != nil {
return nil, errors.Wrapf(err, "failed to get disk driver for disk %s", diskName)
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func svcDiskGet(spdkClient *spdkclient.Client, diskName, diskPath, diskDriver st
}

var targetBdev *spdktypes.BdevInfo
var exactDiskDriver commonTypes.DiskDriver
var exactDiskDriver commontypes.DiskDriver

for i, bdev := range bdevs {
switch bdev.ProductName {
Expand All @@ -167,15 +167,15 @@ func svcDiskGet(spdkClient *spdkclient.Client, diskName, diskPath, diskDriver st
targetBdev = &bdevs[i]
diskPath = util.RemovePrefix(bdev.DriverSpecific.Aio.FileName, hostPrefix)
}
exactDiskDriver = commonTypes.DiskDriverAio
exactDiskDriver = commontypes.DiskDriverAio
case spdktypes.BdevProductNameVirtioBlk:
exactDiskDriver = commonTypes.DiskDriverVirtioBlk
exactDiskDriver = commontypes.DiskDriverVirtioBlk
targetBdev = &bdevs[i]
case spdktypes.BdevProductNameVirtioScsi:
exactDiskDriver = commonTypes.DiskDriverVirtioScsi
exactDiskDriver = commontypes.DiskDriverVirtioScsi
targetBdev = &bdevs[i]
case spdktypes.BdevProductNameNvme:
exactDiskDriver = commonTypes.DiskDriverNvme
exactDiskDriver = commontypes.DiskDriverNvme
targetBdev = &bdevs[i]
}
if targetBdev != nil {
Expand All @@ -195,7 +195,7 @@ func getDiskPath(path string) string {
}

func getDiskID(filename string) (string, error) {
executor, err := spdkutil.NewExecutor(commonTypes.ProcDirectory)
executor, err := spdkutil.NewExecutor(commontypes.ProcDirectory)
if err != nil {
return "", err
}
Expand All @@ -208,7 +208,7 @@ func getDiskID(filename string) (string, error) {
return fmt.Sprintf("%d-%d", dev.Major, dev.Minor), nil
}

func validateAioDiskCreation(spdkClient *spdkclient.Client, diskPath string, diskDriver commonTypes.DiskDriver) error {
func validateAioDiskCreation(spdkClient *spdkclient.Client, diskPath string, diskDriver commontypes.DiskDriver) error {
diskID, err := getDiskID(getDiskPath(diskPath))
if err != nil {
return errors.Wrap(err, "failed to get disk device number")
Expand All @@ -233,7 +233,7 @@ func validateAioDiskCreation(spdkClient *spdkclient.Client, diskPath string, dis
return nil
}

func addBlockDevice(spdkClient *spdkclient.Client, diskName, diskUUID, originalDiskPath string, diskDriver commonTypes.DiskDriver, blockSize int64) (string, error) {
func addBlockDevice(spdkClient *spdkclient.Client, diskName, diskUUID, originalDiskPath string, diskDriver commontypes.DiskDriver, blockSize int64) (string, error) {
log := logrus.WithFields(logrus.Fields{
"diskName": diskName,
"diskUUID": diskUUID,
Expand All @@ -243,7 +243,7 @@ func addBlockDevice(spdkClient *spdkclient.Client, diskName, diskUUID, originalD
})

diskPath := originalDiskPath
if diskDriver == commonTypes.DiskDriverAio {
if diskDriver == commontypes.DiskDriverAio {
if err := validateAioDiskCreation(spdkClient, diskPath, diskDriver); err != nil {
return "", errors.Wrap(err, "failed to validate disk creation")
}
Expand Down Expand Up @@ -316,7 +316,7 @@ func addBlockDevice(spdkClient *spdkclient.Client, diskName, diskUUID, originalD
return "", grpcstatus.Error(grpccodes.NotFound, fmt.Sprintf("cannot find lvstore with UUID %v", diskUUID))
}

func lvstoreToDisk(spdkClient *spdkclient.Client, diskPath, lvstoreName, lvstoreUUID string, diskDriver commonTypes.DiskDriver) (*spdkrpc.Disk, error) {
func lvstoreToDisk(spdkClient *spdkclient.Client, diskPath, lvstoreName, lvstoreUUID string, diskDriver commontypes.DiskDriver) (*spdkrpc.Disk, error) {
lvstores, err := spdkClient.BdevLvolGetLvstore(lvstoreName, lvstoreUUID)
if err != nil {
return nil, errors.Wrapf(err, "failed to get lvstore with name %v and UUID %v", lvstoreName, lvstoreUUID)
Expand All @@ -325,7 +325,7 @@ func lvstoreToDisk(spdkClient *spdkclient.Client, diskPath, lvstoreName, lvstore

// A disk does not have a fsid, so we use the device number as the disk ID
diskID := diskPath
if diskDriver == commonTypes.DiskDriverAio {
if diskDriver == commontypes.DiskDriverAio {
diskID, err = getDiskID(getDiskPath(diskPath))
if err != nil {
return nil, errors.Wrapf(err, "failed to get disk ID")
Expand Down
4 changes: 2 additions & 2 deletions pkg/spdk/disk/aio/aio.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/pkg/errors"

commonTypes "github.com/longhorn/go-common-libs/types"
commontypes "github.com/longhorn/go-common-libs/types"
spdkclient "github.com/longhorn/go-spdk-helper/pkg/spdk/client"
spdktypes "github.com/longhorn/go-spdk-helper/pkg/spdk/types"
spdkutil "github.com/longhorn/go-spdk-helper/pkg/util"
Expand All @@ -20,7 +20,7 @@ type DiskDriverAio struct {

func init() {
driver := &DiskDriverAio{}
disk.RegisterDiskDriver(string(commonTypes.DiskDriverAio), driver)
disk.RegisterDiskDriver(string(commontypes.DiskDriverAio), driver)
}

func (d *DiskDriverAio) DiskCreate(spdkClient *spdkclient.Client, diskName, diskPath string, blockSize uint64) (string, error) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/spdk/disk/nvme/nvme.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

commonTypes "github.com/longhorn/go-common-libs/types"
commontypes "github.com/longhorn/go-common-libs/types"
spdkclient "github.com/longhorn/go-spdk-helper/pkg/spdk/client"
spdksetup "github.com/longhorn/go-spdk-helper/pkg/spdk/setup"
spdktypes "github.com/longhorn/go-spdk-helper/pkg/spdk/types"
Expand All @@ -21,12 +21,12 @@ type DiskDriverNvme struct {

func init() {
driver := &DiskDriverNvme{}
disk.RegisterDiskDriver(string(commonTypes.DiskDriverNvme), driver)
disk.RegisterDiskDriver(string(commontypes.DiskDriverNvme), driver)
}

func (d *DiskDriverNvme) DiskCreate(spdkClient *spdkclient.Client, diskName, diskPath string, blockSize uint64) (string, error) {
// TODO: validate the diskPath
executor, err := helperutil.NewExecutor(commonTypes.ProcDirectory)
executor, err := helperutil.NewExecutor(commontypes.ProcDirectory)
if err != nil {
return "", errors.Wrapf(err, "failed to get the executor for NVMe disk create %v", diskPath)
}
Expand Down Expand Up @@ -58,7 +58,7 @@ func (d *DiskDriverNvme) DiskCreate(spdkClient *spdkclient.Client, diskName, dis
}

func (d *DiskDriverNvme) DiskDelete(spdkClient *spdkclient.Client, diskName, diskPath string) (deleted bool, err error) {
executor, err := helperutil.NewExecutor(commonTypes.ProcDirectory)
executor, err := helperutil.NewExecutor(commontypes.ProcDirectory)
if err != nil {
return false, errors.Wrapf(err, "failed to get the executor for NVMe disk %v deletion", diskName)
}
Expand Down
44 changes: 22 additions & 22 deletions pkg/spdk/disk/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/pkg/errors"

commonTypes "github.com/longhorn/go-common-libs/types"
commontypes "github.com/longhorn/go-common-libs/types"
spdksetup "github.com/longhorn/go-spdk-helper/pkg/spdk/setup"
helpertypes "github.com/longhorn/go-spdk-helper/pkg/types"
helperutil "github.com/longhorn/go-spdk-helper/pkg/util"
Expand All @@ -31,16 +31,16 @@ const (
BlockDiskTypeLoop = BlockDiskType("loop")
)

func GetDiskDriver(diskDriver commonTypes.DiskDriver, diskPathOrBdf string) (commonTypes.DiskDriver, error) {
func GetDiskDriver(diskDriver commontypes.DiskDriver, diskPathOrBdf string) (commontypes.DiskDriver, error) {
if isBDF(diskPathOrBdf) {
return getDiskDriverForBDF(diskDriver, diskPathOrBdf)
}

return getDiskDriverForPath(diskDriver, diskPathOrBdf)
}

func getDiskDriverForBDF(diskDriver commonTypes.DiskDriver, bdf string) (commonTypes.DiskDriver, error) {
executor, err := helperutil.NewExecutor(commonTypes.ProcDirectory)
func getDiskDriverForBDF(diskDriver commontypes.DiskDriver, bdf string) (commontypes.DiskDriver, error) {
executor, err := helperutil.NewExecutor(commontypes.ProcDirectory)
if err != nil {
return "", errors.Wrapf(err, "failed to get the executor for disk driver detection")
}
Expand All @@ -51,25 +51,25 @@ func getDiskDriverForBDF(diskDriver commonTypes.DiskDriver, bdf string) (commonT
}

switch diskDriver {
case commonTypes.DiskDriverAuto:
case commontypes.DiskDriverAuto:
diskPath := ""
if diskStatus.Driver != string(commonTypes.DiskDriverVfioPci) &&
diskStatus.Driver != string(commonTypes.DiskDriverUioPciGeneric) {
if diskStatus.Driver != string(commontypes.DiskDriverVfioPci) &&
diskStatus.Driver != string(commontypes.DiskDriverUioPciGeneric) {
devName, err := util.GetDevNameFromBDF(bdf)
if err != nil {
return "", errors.Wrapf(err, "failed to get device name from BDF %s", bdf)
}
diskPath = fmt.Sprintf("/dev/%s", devName)
}
return getDriverForAuto(diskStatus, diskPath)
case commonTypes.DiskDriverAio, commonTypes.DiskDriverNvme, commonTypes.DiskDriverVirtioScsi, commonTypes.DiskDriverVirtioBlk:
case commontypes.DiskDriverAio, commontypes.DiskDriverNvme, commontypes.DiskDriverVirtioScsi, commontypes.DiskDriverVirtioBlk:
return diskDriver, nil
default:
return commonTypes.DiskDriverNone, fmt.Errorf("unsupported disk driver %s for BDF %s", diskDriver, bdf)
return commontypes.DiskDriverNone, fmt.Errorf("unsupported disk driver %s for BDF %s", diskDriver, bdf)
}
}

func getDriverForAuto(diskStatus *helpertypes.DiskStatus, diskPath string) (commonTypes.DiskDriver, error) {
func getDriverForAuto(diskStatus *helpertypes.DiskStatus, diskPath string) (commontypes.DiskDriver, error) {
// SPDK supports various types of disks, including NVMe, virtio-blk, and virtio-scsi.
//
// NVMe disks can be managed by either NVMe bdev or AIO bdev.
Expand All @@ -80,34 +80,34 @@ func getDriverForAuto(diskStatus *helpertypes.DiskStatus, diskPath string) (comm
// - If a block device uses the subsystems virtio and pci, it's a virtio-blk disk.
// - If it uses the subsystems virtio, pci, and scsi, it's a virtio-scsi disk.
switch diskStatus.Driver {
case string(commonTypes.DiskDriverNvme):
return commonTypes.DiskDriverNvme, nil
case string(commonTypes.DiskDriverVirtioPci):
case string(commontypes.DiskDriverNvme):
return commontypes.DiskDriverNvme, nil
case string(commontypes.DiskDriverVirtioPci):
blockdevice, err := util.GetBlockDevice(diskPath)
if err != nil {
return commonTypes.DiskDriverNone, errors.Wrapf(err, "failed to get blockdevice info for %s", diskPath)
return commontypes.DiskDriverNone, errors.Wrapf(err, "failed to get blockdevice info for %s", diskPath)
}

if slices.Contains(blockdevice.Subsystems, string(BlockDiskSubsystemVirtio)) && slices.Contains(blockdevice.Subsystems, string(BlockDiskSubsystemPci)) {
diskDriver := commonTypes.DiskDriverVirtioBlk
diskDriver := commontypes.DiskDriverVirtioBlk
if slices.Contains(blockdevice.Subsystems, string(BlockDiskSubsystemScsi)) {
diskDriver = commonTypes.DiskDriverVirtioScsi
diskDriver = commontypes.DiskDriverVirtioScsi
}
return diskDriver, nil
}

return commonTypes.DiskDriverNone, fmt.Errorf("unsupported disk driver %s for disk path %s", diskStatus.Driver, diskPath)
return commontypes.DiskDriverNone, fmt.Errorf("unsupported disk driver %s for disk path %s", diskStatus.Driver, diskPath)
default:
return commonTypes.DiskDriverNone, fmt.Errorf("unsupported disk driver %s for disk path %s", diskStatus.Driver, diskPath)
return commontypes.DiskDriverNone, fmt.Errorf("unsupported disk driver %s for disk path %s", diskStatus.Driver, diskPath)
}
}

func getDiskDriverForPath(diskDriver commonTypes.DiskDriver, diskPath string) (commonTypes.DiskDriver, error) {
func getDiskDriverForPath(diskDriver commontypes.DiskDriver, diskPath string) (commontypes.DiskDriver, error) {
switch diskDriver {
case commonTypes.DiskDriverAuto, commonTypes.DiskDriverAio:
return commonTypes.DiskDriverAio, nil
case commontypes.DiskDriverAuto, commontypes.DiskDriverAio:
return commontypes.DiskDriverAio, nil
default:
return commonTypes.DiskDriverNone, fmt.Errorf("unsupported disk driver %s for disk path %s", diskDriver, diskPath)
return commontypes.DiskDriverNone, fmt.Errorf("unsupported disk driver %s for disk path %s", diskDriver, diskPath)
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/spdk/disk/virtio-blk/virtio-blk.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

commonTypes "github.com/longhorn/go-common-libs/types"
commontypes "github.com/longhorn/go-common-libs/types"
"github.com/longhorn/go-spdk-helper/pkg/jsonrpc"
spdkclient "github.com/longhorn/go-spdk-helper/pkg/spdk/client"
spdksetup "github.com/longhorn/go-spdk-helper/pkg/spdk/setup"
Expand All @@ -19,12 +19,12 @@ type DiskDriverVirtioBlk struct {

func init() {
driver := &DiskDriverVirtioBlk{}
disk.RegisterDiskDriver(string(commonTypes.DiskDriverVirtioBlk), driver)
disk.RegisterDiskDriver(string(commontypes.DiskDriverVirtioBlk), driver)
}

func (d *DiskDriverVirtioBlk) DiskCreate(spdkClient *spdkclient.Client, diskName, diskPath string, blockSize uint64) (string, error) {
// TODO: validate the diskPath
executor, err := helperutil.NewExecutor(commonTypes.ProcDirectory)
executor, err := helperutil.NewExecutor(commontypes.ProcDirectory)
if err != nil {
return "", errors.Wrapf(err, "failed to get the executor for virtio-blk disk create %v", diskPath)
}
Expand Down Expand Up @@ -55,7 +55,7 @@ func (d *DiskDriverVirtioBlk) DiskCreate(spdkClient *spdkclient.Client, diskName
}

func (d *DiskDriverVirtioBlk) DiskDelete(spdkClient *spdkclient.Client, diskName, diskPath string) (deleted bool, err error) {
executor, err := helperutil.NewExecutor(commonTypes.ProcDirectory)
executor, err := helperutil.NewExecutor(commontypes.ProcDirectory)
if err != nil {
return false, errors.Wrapf(err, "failed to get the executor for virtio-blk disk %v deletion", diskName)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/spdk/disk/virtio-scsi/virtio-scsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

commonTypes "github.com/longhorn/go-common-libs/types"
commontypes "github.com/longhorn/go-common-libs/types"
"github.com/longhorn/go-spdk-helper/pkg/jsonrpc"
spdkclient "github.com/longhorn/go-spdk-helper/pkg/spdk/client"
spdksetup "github.com/longhorn/go-spdk-helper/pkg/spdk/setup"
Expand All @@ -19,12 +19,12 @@ type DiskDriverVirtioScsi struct {

func init() {
driver := &DiskDriverVirtioScsi{}
disk.RegisterDiskDriver(string(commonTypes.DiskDriverVirtioScsi), driver)
disk.RegisterDiskDriver(string(commontypes.DiskDriverVirtioScsi), driver)
}

func (d *DiskDriverVirtioScsi) DiskCreate(spdkClient *spdkclient.Client, diskName, diskPath string, blockSize uint64) (string, error) {
// TODO: validate the diskPath
executor, err := helperutil.NewExecutor(commonTypes.ProcDirectory)
executor, err := helperutil.NewExecutor(commontypes.ProcDirectory)
if err != nil {
return "", errors.Wrapf(err, "failed to get the executor for virtio-scsi disk create %v", diskPath)
}
Expand Down Expand Up @@ -55,7 +55,7 @@ func (d *DiskDriverVirtioScsi) DiskCreate(spdkClient *spdkclient.Client, diskNam
}

func (d *DiskDriverVirtioScsi) DiskDelete(spdkClient *spdkclient.Client, diskName, diskPath string) (deleted bool, err error) {
executor, err := helperutil.NewExecutor(commonTypes.ProcDirectory)
executor, err := helperutil.NewExecutor(commontypes.ProcDirectory)
if err != nil {
return false, errors.Wrapf(err, "failed to get the executor for virtio-scsi disk %v deletion", diskName)
}
Expand Down
Loading

0 comments on commit 24cbc38

Please sign in to comment.