diff --git a/app/cmd/dmsetup/dmsetup.go b/app/cmd/dmsetup/dmsetup.go index 53e39c9..6f09dcd 100644 --- a/app/cmd/dmsetup/dmsetup.go +++ b/app/cmd/dmsetup/dmsetup.go @@ -6,7 +6,7 @@ import ( "github.com/sirupsen/logrus" "github.com/urfave/cli" - commonTypes "github.com/longhorn/go-common-libs/types" + commontypes "github.com/longhorn/go-common-libs/types" "github.com/longhorn/go-spdk-helper/pkg/util" ) @@ -16,8 +16,8 @@ func Cmd() cli.Command { Flags: []cli.Flag{ cli.StringFlag{ Name: "host-proc", - Usage: fmt.Sprintf("The host proc path of namespace executor. By default %v", commonTypes.ProcDirectory), - Value: commonTypes.ProcDirectory, + Usage: fmt.Sprintf("The host proc path of namespace executor. By default %v", commontypes.ProcDirectory), + Value: commontypes.ProcDirectory, }, }, Subcommands: []cli.Command{ diff --git a/app/cmd/nvmecli/nvmecli.go b/app/cmd/nvmecli/nvmecli.go index d152140..b468752 100644 --- a/app/cmd/nvmecli/nvmecli.go +++ b/app/cmd/nvmecli/nvmecli.go @@ -6,7 +6,7 @@ import ( "github.com/sirupsen/logrus" "github.com/urfave/cli" - commonTypes "github.com/longhorn/go-common-libs/types" + commontypes "github.com/longhorn/go-common-libs/types" "github.com/longhorn/go-spdk-helper/pkg/nvme" "github.com/longhorn/go-spdk-helper/pkg/types" @@ -19,8 +19,8 @@ func Cmd() cli.Command { Flags: []cli.Flag{ cli.StringFlag{ Name: "host-proc", - Usage: fmt.Sprintf("The host proc path of namespace executor. By default %v", commonTypes.ProcDirectory), - Value: commonTypes.ProcDirectory, + Usage: fmt.Sprintf("The host proc path of namespace executor. By default %v", commontypes.ProcDirectory), + Value: commontypes.ProcDirectory, }, }, Subcommands: []cli.Command{ diff --git a/app/cmd/spdksetup/spdksetup.go b/app/cmd/spdksetup/spdksetup.go index 9a97e6d..6a8f794 100644 --- a/app/cmd/spdksetup/spdksetup.go +++ b/app/cmd/spdksetup/spdksetup.go @@ -7,7 +7,7 @@ import ( "github.com/sirupsen/logrus" "github.com/urfave/cli" - 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" "github.com/longhorn/go-spdk-helper/pkg/util" ) @@ -19,8 +19,8 @@ func Cmd() cli.Command { Flags: []cli.Flag{ cli.StringFlag{ Name: "host-proc", - Usage: fmt.Sprintf("The host proc path of namespace executor. By default %v", commonTypes.ProcDirectory), - Value: commonTypes.ProcDirectory, + Usage: fmt.Sprintf("The host proc path of namespace executor. By default %v", commontypes.ProcDirectory), + Value: commontypes.ProcDirectory, }, }, Subcommands: []cli.Command{ diff --git a/app/cmd/spdktgt/spdktgt.go b/app/cmd/spdktgt/spdktgt.go index 283860b..f6ee6ca 100644 --- a/app/cmd/spdktgt/spdktgt.go +++ b/app/cmd/spdktgt/spdktgt.go @@ -7,7 +7,7 @@ import ( "github.com/sirupsen/logrus" "github.com/urfave/cli" - commonTypes "github.com/longhorn/go-common-libs/types" + commontypes "github.com/longhorn/go-common-libs/types" "github.com/longhorn/go-spdk-helper/pkg/spdk/target" "github.com/longhorn/go-spdk-helper/pkg/util" @@ -44,7 +44,7 @@ func Cmd() cli.Command { } func spdkTGT(c *cli.Context) error { - ne, err := util.NewExecutor(commonTypes.ProcDirectory) + ne, err := util.NewExecutor(commontypes.ProcDirectory) if err != nil { return err } diff --git a/pkg/nvme/initiator.go b/pkg/nvme/initiator.go index efc5762..0190aaa 100644 --- a/pkg/nvme/initiator.go +++ b/pkg/nvme/initiator.go @@ -10,8 +10,8 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" - commonNs "github.com/longhorn/go-common-libs/ns" - commonTypes "github.com/longhorn/go-common-libs/types" + commonns "github.com/longhorn/go-common-libs/ns" + commontypes "github.com/longhorn/go-common-libs/types" "github.com/longhorn/nsfilelock" "github.com/longhorn/go-spdk-helper/pkg/types" @@ -47,7 +47,7 @@ type Initiator struct { isUp bool hostProc string - executor *commonNs.Executor + executor *commonns.Executor logger logrus.FieldLogger } @@ -59,7 +59,7 @@ func NewInitiator(name, subsystemNQN, hostProc string) (*Initiator, error) { } // If transportAddress or transportServiceID is empty, the initiator is still valid for stopping - executor, err := util.NewExecutor(commonTypes.ProcDirectory) + executor, err := util.NewExecutor(commontypes.ProcDirectory) if err != nil { return nil, err } diff --git a/pkg/nvme/nvme.go b/pkg/nvme/nvme.go index 88ed9c7..75e26da 100644 --- a/pkg/nvme/nvme.go +++ b/pkg/nvme/nvme.go @@ -7,7 +7,7 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" - commonNs "github.com/longhorn/go-common-libs/ns" + commonns "github.com/longhorn/go-common-libs/ns" ) const ( @@ -15,7 +15,7 @@ const ( ) // DiscoverTarget discovers a target -func DiscoverTarget(ip, port string, executor *commonNs.Executor) (subnqn string, err error) { +func DiscoverTarget(ip, port string, executor *commonns.Executor) (subnqn string, err error) { hostID, err := getHostID(executor) if err != nil { return "", err @@ -40,7 +40,7 @@ func DiscoverTarget(ip, port string, executor *commonNs.Executor) (subnqn string } // ConnectTarget connects to a target -func ConnectTarget(ip, port, nqn string, executor *commonNs.Executor) (controllerName string, err error) { +func ConnectTarget(ip, port, nqn string, executor *commonns.Executor) (controllerName string, err error) { // Trying to connect an existing subsystem will error out with exit code 114. // Hence, it's better to check the existence first. if devices, err := GetDevices(ip, port, nqn, executor); err == nil && len(devices) > 0 { @@ -60,12 +60,12 @@ func ConnectTarget(ip, port, nqn string, executor *commonNs.Executor) (controlle } // DisconnectTarget disconnects a target -func DisconnectTarget(nqn string, executor *commonNs.Executor) error { +func DisconnectTarget(nqn string, executor *commonns.Executor) error { return disconnect(nqn, executor) } // GetDevices returns all devices -func GetDevices(ip, port, nqn string, executor *commonNs.Executor) (devices []Device, err error) { +func GetDevices(ip, port, nqn string, executor *commonns.Executor) (devices []Device, err error) { defer func() { err = errors.Wrapf(err, "failed to get devices for address %s:%s and nqn %s", ip, port, nqn) }() @@ -172,11 +172,11 @@ func GetDevices(ip, port, nqn string, executor *commonNs.Executor) (devices []De } // GetSubsystems returns all devices -func GetSubsystems(executor *commonNs.Executor) (subsystems []Subsystem, err error) { +func GetSubsystems(executor *commonns.Executor) (subsystems []Subsystem, err error) { return listSubsystems("", executor) } // Flush commits data and metadata associated with the specified namespace(s) to nonvolatile media. -func Flush(device, namespaceID string, executor *commonNs.Executor) (output string, err error) { +func Flush(device, namespaceID string, executor *commonns.Executor) (output string, err error) { return flush(device, namespaceID, executor) } diff --git a/pkg/nvme/nvmecli.go b/pkg/nvme/nvmecli.go index 91a6300..35aada9 100644 --- a/pkg/nvme/nvmecli.go +++ b/pkg/nvme/nvmecli.go @@ -6,7 +6,7 @@ import ( "strconv" "strings" - commonNs "github.com/longhorn/go-common-libs/ns" + commonns "github.com/longhorn/go-common-libs/ns" "github.com/longhorn/go-spdk-helper/pkg/types" ) @@ -67,7 +67,7 @@ type Path struct { State string `json:"State,omitempty"` } -func cliVersion(executor *commonNs.Executor) (major, minor int, err error) { +func cliVersion(executor *commonns.Executor) (major, minor int, err error) { opts := []string{ "--version", } @@ -105,7 +105,7 @@ func cliVersion(executor *commonNs.Executor) (major, minor int, err error) { return major, minor, nil } -func showHostNQN(executor *commonNs.Executor) (string, error) { +func showHostNQN(executor *commonns.Executor) (string, error) { opts := []string{ "--show-hostnqn", } @@ -124,7 +124,7 @@ func showHostNQN(executor *commonNs.Executor) (string, error) { return "", fmt.Errorf("failed to get host NQN from %s", outputStr) } -func listSubsystems(devicePath string, executor *commonNs.Executor) ([]Subsystem, error) { +func listSubsystems(devicePath string, executor *commonns.Executor) ([]Subsystem, error) { major, _, err := cliVersion(executor) if err != nil { return nil, err @@ -154,7 +154,7 @@ func listSubsystems(devicePath string, executor *commonNs.Executor) ([]Subsystem return listSubsystemsV2(jsonStr, executor) } -func listSubsystemsV1(jsonStr string, executor *commonNs.Executor) ([]Subsystem, error) { +func listSubsystemsV1(jsonStr string, executor *commonns.Executor) ([]Subsystem, error) { output := map[string][]Subsystem{} if err := json.Unmarshal([]byte(jsonStr), &output); err != nil { return nil, err @@ -169,7 +169,7 @@ type ListSubsystemsV2Output struct { Subsystems []Subsystem `json:"Subsystems"` } -func listSubsystemsV2(jsonStr string, executor *commonNs.Executor) ([]Subsystem, error) { +func listSubsystemsV2(jsonStr string, executor *commonns.Executor) ([]Subsystem, error) { var output []ListSubsystemsV2Output if err := json.Unmarshal([]byte(jsonStr), &output); err != nil { return nil, err @@ -197,7 +197,7 @@ type CliDevice struct { SectorSize int32 `json:"SectorSize,omitempty"` } -func listControllers(executor *commonNs.Executor) ([]CliDevice, error) { +func listControllers(executor *commonns.Executor) ([]CliDevice, error) { opts := []string{ "list", "-o", "json", @@ -218,7 +218,7 @@ func listControllers(executor *commonNs.Executor) ([]CliDevice, error) { return output["Devices"], nil } -func getHostID(executor *commonNs.Executor) (string, error) { +func getHostID(executor *commonns.Executor) (string, error) { outputStr, err := executor.Execute(nil, "cat", []string{"/etc/nvme/hostid"}, types.ExecuteTimeout) if err == nil { return strings.TrimSpace(string(outputStr)), nil @@ -232,7 +232,7 @@ func getHostID(executor *commonNs.Executor) (string, error) { return "", err } -func discovery(hostID, hostNQN, ip, port string, executor *commonNs.Executor) ([]DiscoveryPageEntry, error) { +func discovery(hostID, hostNQN, ip, port string, executor *commonns.Executor) ([]DiscoveryPageEntry, error) { opts := []string{ "discover", "-t", DefaultTransportType, @@ -301,7 +301,7 @@ func discovery(hostID, hostNQN, ip, port string, executor *commonNs.Executor) ([ return output.Entries, nil } -func connect(hostID, hostNQN, nqn, transpotType, ip, port string, executor *commonNs.Executor) (string, error) { +func connect(hostID, hostNQN, nqn, transpotType, ip, port string, executor *commonns.Executor) (string, error) { var err error opts := []string{ @@ -349,7 +349,7 @@ func connect(hostID, hostNQN, nqn, transpotType, ip, port string, executor *comm return output["device"], nil } -func disconnect(nqn string, executor *commonNs.Executor) error { +func disconnect(nqn string, executor *commonns.Executor) error { opts := []string{ "disconnect", "--nqn", nqn, @@ -414,7 +414,7 @@ func GetIPAndPortFromControllerAddress(address string) (string, string) { return traddr, trsvcid } -func flush(devicePath, namespaceID string, executor *commonNs.Executor) (string, error) { +func flush(devicePath, namespaceID string, executor *commonns.Executor) (string, error) { opts := []string{ "flush", diff --git a/pkg/spdk/setup/setup.go b/pkg/spdk/setup/setup.go index 0e84861..b6e58dd 100644 --- a/pkg/spdk/setup/setup.go +++ b/pkg/spdk/setup/setup.go @@ -7,7 +7,7 @@ import ( "github.com/pkg/errors" - commonNs "github.com/longhorn/go-common-libs/ns" + commonns "github.com/longhorn/go-common-libs/ns" "github.com/longhorn/go-spdk-helper/pkg/types" ) @@ -16,7 +16,7 @@ const ( spdkSetupPath = "/usr/src/spdk/scripts/setup.sh" ) -func Bind(deviceAddr, deviceDriver string, executor *commonNs.Executor) (string, error) { +func Bind(deviceAddr, deviceDriver string, executor *commonns.Executor) (string, error) { if deviceAddr == "" { return "", fmt.Errorf("device address is empty") } @@ -40,7 +40,7 @@ func Bind(deviceAddr, deviceDriver string, executor *commonNs.Executor) (string, return outputStr, nil } -func Unbind(deviceAddr string, executor *commonNs.Executor) (string, error) { +func Unbind(deviceAddr string, executor *commonns.Executor) (string, error) { if deviceAddr == "" { return "", fmt.Errorf("device address is empty") } @@ -59,7 +59,7 @@ func Unbind(deviceAddr string, executor *commonNs.Executor) (string, error) { return outputStr, nil } -func GetDiskDriver(deviceAddr string, executor *commonNs.Executor) (string, error) { +func GetDiskDriver(deviceAddr string, executor *commonns.Executor) (string, error) { if deviceAddr == "" { return "", fmt.Errorf("device address is empty") } @@ -78,7 +78,7 @@ func GetDiskDriver(deviceAddr string, executor *commonNs.Executor) (string, erro return extractJSON(outputStr) } -func GetDiskStatus(deviceAddr string, executor *commonNs.Executor) (*types.DiskStatus, error) { +func GetDiskStatus(deviceAddr string, executor *commonns.Executor) (*types.DiskStatus, error) { if deviceAddr == "" { return nil, fmt.Errorf("device address is empty") } diff --git a/pkg/spdk/spdk_test.go b/pkg/spdk/spdk_test.go index 2181ece..513b43f 100644 --- a/pkg/spdk/spdk_test.go +++ b/pkg/spdk/spdk_test.go @@ -11,7 +11,7 @@ import ( . "gopkg.in/check.v1" - commonTypes "github.com/longhorn/go-common-libs/types" + commontypes "github.com/longhorn/go-common-libs/types" "github.com/longhorn/go-spdk-helper/pkg/jsonrpc" "github.com/longhorn/go-spdk-helper/pkg/nvme" @@ -91,7 +91,7 @@ func PrepareDeviceFile(c *C) { func (s *TestSuite) TestSPDKTargetWithHostNamespace(c *C) { fmt.Println("Testing SPDK Target With Host Namespace") - ne, err := util.NewExecutor(commonTypes.HostProcDirectory) + ne, err := util.NewExecutor(commontypes.HostProcDirectory) c.Assert(err, IsNil) LaunchTestSPDKTarget(c, ne.Execute) @@ -100,7 +100,7 @@ func (s *TestSuite) TestSPDKTargetWithHostNamespace(c *C) { func (s *TestSuite) TestSPDKBasic(c *C) { fmt.Println("Testing SPDK Basic") - ne, err := util.NewExecutor(commonTypes.ProcDirectory) + ne, err := util.NewExecutor(commontypes.ProcDirectory) c.Assert(err, IsNil) LaunchTestSPDKTarget(c, ne.Execute) @@ -346,7 +346,7 @@ func (s *TestSuite) TestSPDKBasic(c *C) { // Use Linux nvme driver to attach to our RAID1 exported via NVMe-oF and create a filesystem on it // The creation of a filesystem will write some data on the lvol - executor, err := util.NewExecutor(commonTypes.ProcDirectory) + executor, err := util.NewExecutor(commontypes.ProcDirectory) c.Assert(err, IsNil) _, err = executor.Execute(nil, "ls", []string{"/dev/longhorn/"}, types.ExecuteTimeout) c.Assert(err, IsNil) @@ -387,7 +387,7 @@ func (s *TestSuite) TestSPDKBasic(c *C) { func (s *TestSuite) TestSPDKClientMultiThread(c *C) { fmt.Println("Testing SPDK Client Multi Thread") - ne, err := util.NewExecutor(commonTypes.ProcDirectory) + ne, err := util.NewExecutor(commontypes.ProcDirectory) c.Assert(err, IsNil) LaunchTestSPDKTarget(c, ne.Execute) @@ -474,7 +474,7 @@ func (s *TestSuite) TestSPDKClientMultiThread(c *C) { func (s *TestSuite) TestSPDKEngineSuspend(c *C) { fmt.Println("Testing Engine Suspend") - ne, err := util.NewExecutor(commonTypes.ProcDirectory) + ne, err := util.NewExecutor(commontypes.ProcDirectory) c.Assert(err, IsNil) LaunchTestSPDKTarget(c, ne.Execute) diff --git a/pkg/util/device.go b/pkg/util/device.go index f55f4fd..3200987 100644 --- a/pkg/util/device.go +++ b/pkg/util/device.go @@ -14,7 +14,7 @@ import ( "github.com/sirupsen/logrus" "golang.org/x/sys/unix" - commonNs "github.com/longhorn/go-common-libs/ns" + commonns "github.com/longhorn/go-common-libs/ns" "github.com/longhorn/go-spdk-helper/pkg/types" ) @@ -51,7 +51,7 @@ func RemoveDevice(dev string) error { } // GetKnownDevices returns the path of the device with the given major and minor numbers -func GetKnownDevices(executor *commonNs.Executor) (map[string]*LonghornBlockDevice, error) { +func GetKnownDevices(executor *commonns.Executor) (map[string]*LonghornBlockDevice, error) { knownDevices := make(map[string]*LonghornBlockDevice) // Example command output @@ -94,7 +94,7 @@ func GetKnownDevices(executor *commonNs.Executor) (map[string]*LonghornBlockDevi } // DetectDevice detects the device with the given path -func DetectDevice(path string, executor *commonNs.Executor) (*BlockDevice, error) { +func DetectDevice(path string, executor *commonns.Executor) (*BlockDevice, error) { // Example command output // $ lsblk -l -n -o NAME,MAJ:MIN // nvme1n1 259:3 @@ -180,7 +180,7 @@ func parseNumber(str string) (int, error) { } // GetDeviceSectorSize returns the sector size of the given device -func GetDeviceSectorSize(devPath string, executor *commonNs.Executor) (int64, error) { +func GetDeviceSectorSize(devPath string, executor *commonns.Executor) (int64, error) { opts := []string{ "--getsz", devPath, } @@ -194,7 +194,7 @@ func GetDeviceSectorSize(devPath string, executor *commonNs.Executor) (int64, er } // GetDeviceNumbers returns the major and minor numbers of the given device -func GetDeviceNumbers(devPath string, executor *commonNs.Executor) (int, int, error) { +func GetDeviceNumbers(devPath string, executor *commonns.Executor) (int, int, error) { opts := []string{ "-l", "-J", "-n", "-o", "MAJ:MIN", devPath, } diff --git a/pkg/util/dmsetup.go b/pkg/util/dmsetup.go index 591012c..6f57fb9 100644 --- a/pkg/util/dmsetup.go +++ b/pkg/util/dmsetup.go @@ -5,7 +5,7 @@ import ( "regexp" "strings" - commonNs "github.com/longhorn/go-common-libs/ns" + commonns "github.com/longhorn/go-common-libs/ns" "github.com/longhorn/go-spdk-helper/pkg/types" ) @@ -15,7 +15,7 @@ const ( ) // DmsetupCreate creates a device mapper device with the given name and table -func DmsetupCreate(dmDeviceName, table string, executor *commonNs.Executor) error { +func DmsetupCreate(dmDeviceName, table string, executor *commonns.Executor) error { opts := []string{ "create", dmDeviceName, "--table", table, } @@ -24,7 +24,7 @@ func DmsetupCreate(dmDeviceName, table string, executor *commonNs.Executor) erro } // DmsetupSuspend suspends the device mapper device with the given name -func DmsetupSuspend(dmDeviceName string, noflush, nolockfs bool, executor *commonNs.Executor) error { +func DmsetupSuspend(dmDeviceName string, noflush, nolockfs bool, executor *commonns.Executor) error { opts := []string{ "suspend", dmDeviceName, } @@ -42,7 +42,7 @@ func DmsetupSuspend(dmDeviceName string, noflush, nolockfs bool, executor *commo } // DmsetupResume removes the device mapper device with the given name -func DmsetupResume(dmDeviceName string, executor *commonNs.Executor) error { +func DmsetupResume(dmDeviceName string, executor *commonns.Executor) error { opts := []string{ "resume", dmDeviceName, } @@ -51,7 +51,7 @@ func DmsetupResume(dmDeviceName string, executor *commonNs.Executor) error { } // DmsetupReload reloads the table of the device mapper device with the given name and table -func DmsetupReload(dmDeviceName, table string, executor *commonNs.Executor) error { +func DmsetupReload(dmDeviceName, table string, executor *commonns.Executor) error { opts := []string{ "reload", dmDeviceName, "--table", table, } @@ -60,7 +60,7 @@ func DmsetupReload(dmDeviceName, table string, executor *commonNs.Executor) erro } // DmsetupRemove removes the device mapper device with the given name -func DmsetupRemove(dmDeviceName string, force, deferred bool, executor *commonNs.Executor) error { +func DmsetupRemove(dmDeviceName string, force, deferred bool, executor *commonns.Executor) error { opts := []string{ "remove", dmDeviceName, } @@ -75,7 +75,7 @@ func DmsetupRemove(dmDeviceName string, force, deferred bool, executor *commonNs } // DmsetupDeps returns the dependent devices of the device mapper device with the given name -func DmsetupDeps(dmDeviceName string, executor *commonNs.Executor) ([]string, error) { +func DmsetupDeps(dmDeviceName string, executor *commonns.Executor) ([]string, error) { opts := []string{ "deps", dmDeviceName, "-o", "devname", } @@ -116,7 +116,7 @@ type DeviceInfo struct { } // DmsetupInfo returns the information of the device mapper device with the given name -func DmsetupInfo(dmDeviceName string, executor *commonNs.Executor) ([]*DeviceInfo, error) { +func DmsetupInfo(dmDeviceName string, executor *commonns.Executor) ([]*DeviceInfo, error) { opts := []string{ "info", "--columns", diff --git a/pkg/util/executor.go b/pkg/util/executor.go index 96f56e8..694961e 100644 --- a/pkg/util/executor.go +++ b/pkg/util/executor.go @@ -1,13 +1,13 @@ package util import ( - commonNs "github.com/longhorn/go-common-libs/ns" - commonTypes "github.com/longhorn/go-common-libs/types" + commonns "github.com/longhorn/go-common-libs/ns" + commontypes "github.com/longhorn/go-common-libs/types" ) // NewExecutor creates a new namespaced executor -func NewExecutor(hostProc string) (*commonNs.Executor, error) { - namespaces := []commonTypes.Namespace{commonTypes.NamespaceMnt, commonTypes.NamespaceIpc, commonTypes.NamespaceNet} +func NewExecutor(hostProc string) (*commonns.Executor, error) { + namespaces := []commontypes.Namespace{commontypes.NamespaceMnt, commontypes.NamespaceIpc, commontypes.NamespaceNet} - return commonNs.NewNamespaceExecutor(commonTypes.ProcessNone, hostProc, namespaces) + return commonns.NewNamespaceExecutor(commontypes.ProcessNone, hostProc, namespaces) }