diff --git a/go.mod b/go.mod index d4d020315..a4742efdd 100644 --- a/go.mod +++ b/go.mod @@ -53,3 +53,7 @@ require ( k8s.io/mount-utils v0.26.0 // indirect k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect ) + +replace github.com/longhorn/go-spdk-helper v0.0.0-20240117135122-26f8acb2a13d => github.com/derekbit/go-spdk-helper v0.0.0-20240216014357-3c42253cb60f + +replace github.com/longhorn/go-common-libs v0.0.0-20240103081802-3993c5908447 => github.com/derekbit/go-common-libs v0.0.0-20240207042018-b592223bef9f diff --git a/go.sum b/go.sum index c48d52b05..a463f5c52 100644 --- a/go.sum +++ b/go.sum @@ -16,6 +16,10 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/derekbit/go-common-libs v0.0.0-20240207042018-b592223bef9f h1:P4QUupwbUO+lDtyP+nbAKwjTy0aYT1XWyJWEZIbEQuQ= +github.com/derekbit/go-common-libs v0.0.0-20240207042018-b592223bef9f/go.mod h1:nIECQARppamt2zwFSdzADRTVKo/7izFwWIS3VWi7D/s= +github.com/derekbit/go-spdk-helper v0.0.0-20240216014357-3c42253cb60f h1:tg+l9L+A8T8HuLKmjVk8DmlpIDxNxloDgdLCpgei8So= +github.com/derekbit/go-spdk-helper v0.0.0-20240216014357-3c42253cb60f/go.mod h1:s5tYjx1UXqhxzLErWULhfIfLRGMAZNh6L3K2xKZeWhk= github.com/gammazero/deque v0.1.0 h1:f9LnNmq66VDeuAlSAapemq/U7hJ2jpIWa4c09q8Dlik= github.com/gammazero/deque v0.1.0/go.mod h1:KQw7vFau1hHuM8xmI9RbgKFbAsQFWmBpqQ2KenFLk6M= github.com/gammazero/workerpool v1.1.2 h1:vuioDQbgrz4HoaCi2q1HLlOXdpbap5AET7xu5/qj87g= @@ -44,10 +48,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/longhorn/backupstore v0.0.0-20240110081942-bd231cfb0c7b h1:euBbfDb6bnp8KQ5qmbvWWEG7KP6nxhUotLCPGU/x3v0= github.com/longhorn/backupstore v0.0.0-20240110081942-bd231cfb0c7b/go.mod h1:4cbJWtlrD2cGTQxQLtdlPTYopiJiusXH7CpOBrn/s3k= -github.com/longhorn/go-common-libs v0.0.0-20240103081802-3993c5908447 h1:NwR+xCGLpAORmB1UwNfDkQj3vPNIVikJe/hZe9+BQe0= -github.com/longhorn/go-common-libs v0.0.0-20240103081802-3993c5908447/go.mod h1:nIECQARppamt2zwFSdzADRTVKo/7izFwWIS3VWi7D/s= -github.com/longhorn/go-spdk-helper v0.0.0-20240117135122-26f8acb2a13d h1:Yqt7DL478ir9LwHmuRRXWzKKyzKbvPkGadCeRQ3pv1o= -github.com/longhorn/go-spdk-helper v0.0.0-20240117135122-26f8acb2a13d/go.mod h1:9nZ5HbwviggK6l792X4l9fTivEWmiK3sXFaroiRp2yw= github.com/longhorn/nsfilelock v0.0.0-20200723175406-fa7c83ad0003 h1:Jw9uANsGcHTxp6HcC++/vN17LfeuDmozHI2j6DoZf5E= github.com/longhorn/nsfilelock v0.0.0-20200723175406-fa7c83ad0003/go.mod h1:0CLeXlf59Lg6C0kjLSDf47ft73Dh37CwymYRKWwAn04= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= diff --git a/vendor/github.com/longhorn/go-common-libs/io/file.go b/vendor/github.com/longhorn/go-common-libs/io/file.go index 957b2d7e6..6bcd47146 100644 --- a/vendor/github.com/longhorn/go-common-libs/io/file.go +++ b/vendor/github.com/longhorn/go-common-libs/io/file.go @@ -233,6 +233,7 @@ func GetDiskStat(path string) (diskStat types.DiskStat, err error) { DiskID: fsidFormatted, Path: path, Type: usage.Fstype, + Driver: "", FreeBlocks: int64(statfs.Bfree), TotalBlocks: int64(statfs.Blocks), BlockSize: statfs.Bsize, diff --git a/vendor/github.com/longhorn/go-common-libs/ns/crypto.go b/vendor/github.com/longhorn/go-common-libs/ns/crypto.go index d8988ddaf..5638b37dd 100644 --- a/vendor/github.com/longhorn/go-common-libs/ns/crypto.go +++ b/vendor/github.com/longhorn/go-common-libs/ns/crypto.go @@ -65,5 +65,5 @@ func (nsexec *Executor) CryptsetupWithPassphrase(passphrase string, args []strin // For Talos Linux, cryptsetup comes pre-installed in the host namespace // (ref: https://github.com/siderolabs/pkgs/blob/release-1.4/reproducibility/pkg.yaml#L10) // for the [Disk Encryption](https://www.talos.dev/v1.4/talos-guides/configuration/disk-encryption/). - return nsexec.ExecuteWithStdin(types.BinaryCryptsetup, args, passphrase, timeout) + return nsexec.ExecuteWithStdin(nil, types.BinaryCryptsetup, args, passphrase, timeout) } diff --git a/vendor/github.com/longhorn/go-common-libs/ns/executor.go b/vendor/github.com/longhorn/go-common-libs/ns/executor.go index 617f21e0a..108aceccc 100644 --- a/vendor/github.com/longhorn/go-common-libs/ns/executor.go +++ b/vendor/github.com/longhorn/go-common-libs/ns/executor.go @@ -46,7 +46,7 @@ func NewNamespaceExecutor(processName, procDirectory string, namespaces []types. } // prepareCommandArgs prepares the nsenter command arguments. -func (nsexec *Executor) prepareCommandArgs(binary string, args []string) []string { +func (nsexec *Executor) prepareCommandArgs(envs []string, binary string, args []string) []string { cmdArgs := []string{} for _, ns := range nsexec.namespaces { nsPath := filepath.Join(nsexec.nsDirectory, ns.String()) @@ -59,24 +59,29 @@ func (nsexec *Executor) prepareCommandArgs(binary string, args []string) []strin cmdArgs = append(cmdArgs, "--net="+nsPath) } } + if len(envs) > 0 { + cmdArgs = append(cmdArgs, "env", "-i") + cmdArgs = append(cmdArgs, envs...) + } + cmdArgs = append(cmdArgs, binary) return append(cmdArgs, args...) } // Execute executes the command in the namespace. If NsDirectory is empty, // it will execute the command in the current namespace. -func (nsexec *Executor) Execute(binary string, args []string, timeout time.Duration) (string, error) { - return nsexec.executor.Execute(nil, types.NsBinary, nsexec.prepareCommandArgs(binary, args), timeout) +func (nsexec *Executor) Execute(envs []string, binary string, args []string, timeout time.Duration) (string, error) { + return nsexec.executor.Execute(nil, types.NsBinary, nsexec.prepareCommandArgs(envs, binary, args), timeout) } // ExecuteWithStdin executes the command in the namespace with stdin. // If NsDirectory is empty, it will execute the command in the current namespace. -func (nsexec *Executor) ExecuteWithStdin(binary string, args []string, stdinString string, timeout time.Duration) (string, error) { - return nsexec.executor.ExecuteWithStdin(types.NsBinary, nsexec.prepareCommandArgs(binary, args), stdinString, timeout) +func (nsexec *Executor) ExecuteWithStdin(envs []string, binary string, args []string, stdinString string, timeout time.Duration) (string, error) { + return nsexec.executor.ExecuteWithStdin(types.NsBinary, nsexec.prepareCommandArgs(envs, binary, args), stdinString, timeout) } // ExecuteWithStdinPipe executes the command in the namespace with stdin pipe. // If NsDirectory is empty, it will execute the command in the current namespace. -func (nsexec *Executor) ExecuteWithStdinPipe(binary string, args []string, stdinString string, timeout time.Duration) (string, error) { - return nsexec.executor.ExecuteWithStdinPipe(types.NsBinary, nsexec.prepareCommandArgs(binary, args), stdinString, timeout) +func (nsexec *Executor) ExecuteWithStdinPipe(envs []string, binary string, args []string, stdinString string, timeout time.Duration) (string, error) { + return nsexec.executor.ExecuteWithStdinPipe(types.NsBinary, nsexec.prepareCommandArgs(envs, binary, args), stdinString, timeout) } diff --git a/vendor/github.com/longhorn/go-common-libs/types/file.go b/vendor/github.com/longhorn/go-common-libs/types/file.go index 3ebb6c9e7..484c00e76 100644 --- a/vendor/github.com/longhorn/go-common-libs/types/file.go +++ b/vendor/github.com/longhorn/go-common-libs/types/file.go @@ -8,8 +8,10 @@ var FileLockDefaultTimeout = 24 * time.Hour type DiskStat struct { DiskID string + Name string Path string Type string + Driver string FreeBlocks int64 TotalBlocks int64 BlockSize int64 diff --git a/vendor/github.com/longhorn/go-spdk-helper/pkg/nvme/initiator.go b/vendor/github.com/longhorn/go-spdk-helper/pkg/nvme/initiator.go index c44c78ed5..f387e93c8 100644 --- a/vendor/github.com/longhorn/go-spdk-helper/pkg/nvme/initiator.go +++ b/vendor/github.com/longhorn/go-spdk-helper/pkg/nvme/initiator.go @@ -485,7 +485,7 @@ func (i *Initiator) reloadLinearDmDevice() error { opts := []string{ "--getsize", devPath, } - output, err := i.executor.Execute(util.BlockdevBinary, opts, types.ExecuteTimeout) + output, err := i.executor.Execute(nil, util.BlockdevBinary, opts, types.ExecuteTimeout) if err != nil { return err } diff --git a/vendor/github.com/longhorn/go-spdk-helper/pkg/nvme/nvmecli.go b/vendor/github.com/longhorn/go-spdk-helper/pkg/nvme/nvmecli.go index e82fab100..2477a0d20 100644 --- a/vendor/github.com/longhorn/go-spdk-helper/pkg/nvme/nvmecli.go +++ b/vendor/github.com/longhorn/go-spdk-helper/pkg/nvme/nvmecli.go @@ -69,7 +69,7 @@ func cliVersion(executor *commonNs.Executor) (major, minor int, err error) { opts := []string{ "--version", } - outputStr, err := executor.Execute(nvmeBinary, opts, types.ExecuteTimeout) + outputStr, err := executor.Execute(nil, nvmeBinary, opts, types.ExecuteTimeout) if err != nil { return 0, 0, err } @@ -108,7 +108,7 @@ func showHostNQN(executor *commonNs.Executor) (string, error) { "--show-hostnqn", } - outputStr, err := executor.Execute(nvmeBinary, opts, types.ExecuteTimeout) + outputStr, err := executor.Execute(nil, nvmeBinary, opts, types.ExecuteTimeout) if err != nil { return "", err } @@ -137,7 +137,7 @@ func listSubsystems(devicePath string, executor *commonNs.Executor) ([]Subsystem opts = append(opts, devicePath) } - outputStr, err := executor.Execute(nvmeBinary, opts, types.ExecuteTimeout) + outputStr, err := executor.Execute(nil, nvmeBinary, opts, types.ExecuteTimeout) if err != nil { return nil, err } @@ -200,7 +200,7 @@ func listControllers(executor *commonNs.Executor) ([]CliDevice, error) { "list", "-o", "json", } - outputStr, err := executor.Execute(nvmeBinary, opts, types.ExecuteTimeout) + outputStr, err := executor.Execute(nil, nvmeBinary, opts, types.ExecuteTimeout) if err != nil { return nil, err } @@ -217,12 +217,12 @@ func listControllers(executor *commonNs.Executor) ([]CliDevice, error) { } func getHostID(executor *commonNs.Executor) (string, error) { - outputStr, err := executor.Execute("cat", []string{"/etc/nvme/hostid"}, types.ExecuteTimeout) + outputStr, err := executor.Execute(nil, "cat", []string{"/etc/nvme/hostid"}, types.ExecuteTimeout) if err == nil { return strings.TrimSpace(string(outputStr)), nil } - outputStr, err = executor.Execute("cat", []string{"/sys/class/dmi/id/product_uuid"}, types.ExecuteTimeout) + outputStr, err = executor.Execute(nil, "cat", []string{"/sys/class/dmi/id/product_uuid"}, types.ExecuteTimeout) if err == nil { return strings.TrimSpace(string(outputStr)), nil } @@ -277,7 +277,7 @@ func discovery(hostID, hostNQN, ip, port string, executor *commonNs.Executor) ([ // } // nvme discover does not respect the -s option, so we need to filter the output - outputStr, err := executor.Execute(nvmeBinary, opts, types.ExecuteTimeout) + outputStr, err := executor.Execute(nil, nvmeBinary, opts, types.ExecuteTimeout) if err != nil { return nil, err } @@ -327,7 +327,7 @@ func connect(hostID, hostNQN, nqn, transpotType, ip, port string, executor *comm // { // "device" : "nvme0" // } - outputStr, err := executor.Execute(nvmeBinary, opts, types.ExecuteTimeout) + outputStr, err := executor.Execute(nil, nvmeBinary, opts, types.ExecuteTimeout) if err != nil { return "", err } @@ -355,7 +355,7 @@ func disconnect(nqn string, executor *commonNs.Executor) error { // NQN:nqn.2023-01.io.spdk:raid01 disconnected 1 controller(s) // // And trying to disconnect a non-existing target would return exit code 0 - _, err := executor.Execute(nvmeBinary, opts, types.ExecuteTimeout) + _, err := executor.Execute(nil, nvmeBinary, opts, types.ExecuteTimeout) return err } diff --git a/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/client/basic.go b/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/client/basic.go index 36dc9c4fd..5225042c3 100644 --- a/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/client/basic.go +++ b/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/client/basic.go @@ -3,9 +3,21 @@ package client import ( "encoding/json" + "github.com/pkg/errors" + spdktypes "github.com/longhorn/go-spdk-helper/pkg/spdk/types" ) +type Xattr struct { + Name string + Value string +} + +const ( + UserCreated = "user_created" + SnapshotTimestamp = "snapshot_timestamp" +) + // BdevGetBdevs get information about block devices (bdevs). // // "name": Optional. If this is not specified, the function will list all block devices. @@ -255,6 +267,17 @@ func (c *Client) BdevLvolGet(name string, timeout uint64) (bdevLvolInfoList []sp if spdktypes.GetBdevType(&b) != spdktypes.BdevTypeLvol { continue } + + b.DriverSpecific.Lvol.Xattrs = make(map[string]string) + user_created, err := c.BdevLvolGetXattr(name, UserCreated) + if err == nil { + b.DriverSpecific.Lvol.Xattrs[UserCreated] = user_created + } + snapshot_timestamp, err := c.BdevLvolGetXattr(name, SnapshotTimestamp) + if err == nil { + b.DriverSpecific.Lvol.Xattrs[SnapshotTimestamp] = snapshot_timestamp + } + bdevLvolInfoList = append(bdevLvolInfoList, b) } @@ -266,12 +289,17 @@ func (c *Client) BdevLvolGet(name string, timeout uint64) (bdevLvolInfoList []sp // "name": Required. UUID or alias of the logical volume to create a snapshot from. The alias of a lvol is /. // // "snapshotName": Required. the logical volume name for the newly created snapshot. -func (c *Client) BdevLvolSnapshot(name, snapshotName string) (uuid string, err error) { +func (c *Client) BdevLvolSnapshot(name, snapshotName string, xattrs []Xattr) (uuid string, err error) { req := spdktypes.BdevLvolSnapshotRequest{ LvolName: name, SnapshotName: snapshotName, } + req.Xattrs = make(map[string]string) + for _, s := range xattrs { + req.Xattrs[s.Name] = s.Value + } + cmdOutput, err := c.jsonCli.SendCommand("bdev_lvol_snapshot", req) if err != nil { return "", err @@ -918,3 +946,40 @@ func (c *Client) NvmfSubsystemGetListeners(nqn, tgtName string) (listenerList [] return listenerList, json.Unmarshal(cmdOutput, &listenerList) } + +// BdevVirtioAttachController creates new initiator Virtio SCSI or Virtio Block and expose all found bdevs. +func (c *Client) BdevVirtioAttachController(name, trtype, traddr, devType string) ([]string, error) { + req := spdktypes.BdevVirtioAttachControllerRequest{ + Name: name, + Trtype: trtype, + Traddr: traddr, + DevType: devType, + } + + cmdOutput, err := c.jsonCli.SendCommand("bdev_virtio_attach_controller", req) + if err != nil { + return nil, err + } + + var disks []string + err = json.Unmarshal([]byte(cmdOutput), &disks) + if err != nil { + return nil, errors.Wrapf(err, "failed to unmarshal disks: %s", cmdOutput) + } + + return disks, nil +} + +// BdevVirtioDetachController removes a Virtio device. +func (c *Client) BdevVirtioDetachController(name string) (deleted bool, err error) { + req := spdktypes.BdevVirtioDetachControllerRequest{ + Name: name, + } + + cmdOutput, err := c.jsonCli.SendCommand("bdev_virtio_detach_controller", req) + if err != nil { + return false, err + } + + return deleted, json.Unmarshal(cmdOutput, &deleted) +} diff --git a/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/setup/setup.go b/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/setup/setup.go new file mode 100644 index 000000000..f3e927e1d --- /dev/null +++ b/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/setup/setup.go @@ -0,0 +1,85 @@ +package setup + +import ( + "fmt" + "strings" + + commonNs "github.com/longhorn/go-common-libs/ns" + + "github.com/longhorn/go-spdk-helper/pkg/types" +) + +const ( + spdkSetupPath = "/usr/src/spdk/scripts/setup.sh" +) + +func Bind(deviceAddr, deviceDriver string, executor *commonNs.Executor) (string, error) { + if deviceAddr == "" { + return "", fmt.Errorf("device address is empty") + } + + envs := []string{ + fmt.Sprintf("%s=%s", "PCI_ALLOWED", deviceAddr), + fmt.Sprintf("%s=%s", "DRIVER_OVERRIDE", deviceDriver), + } + + cmdArgs := []string{ + spdkSetupPath, + "bind", + } + + outputStr, err := executor.Execute(envs, "bash", cmdArgs, types.ExecuteTimeout) + if err != nil { + return "", err + } + + return outputStr, nil +} + +func Unbind(deviceAddr string, executor *commonNs.Executor) (string, error) { + if deviceAddr == "" { + return "", fmt.Errorf("device address is empty") + } + + cmdArgs := []string{ + spdkSetupPath, + "unbind", + deviceAddr, + } + + outputStr, err := executor.Execute(nil, "bash", cmdArgs, types.ExecuteTimeout) + if err != nil { + return "", err + } + + return outputStr, nil +} + +func GetDeviceDriver(deviceAddr string, executor *commonNs.Executor) (string, error) { + if deviceAddr == "" { + return "", fmt.Errorf("device address is empty") + } + + cmdArgs := []string{ + spdkSetupPath, + "get-device-driver", + deviceAddr, + } + + outputStr, err := executor.Execute(nil, "bash", cmdArgs, types.ExecuteTimeout) + if err != nil { + return "", err + } + + return extractJSON(outputStr) +} + +func extractJSON(outputStr string) (string, error) { + // Find the first '{' and last '}' characters, assuming valid JSON format + start := strings.Index(outputStr, "{") + end := strings.LastIndex(outputStr, "}") + if start != -1 && end != -1 { + return outputStr[start : end+1], nil + } + return "", fmt.Errorf("failed to extract JSON from output: %s", outputStr) +} diff --git a/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/target/target.go b/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/target/target.go index d01a701ba..cdf7ed560 100644 --- a/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/target/target.go +++ b/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/target/target.go @@ -47,7 +47,7 @@ func SetupTarget(spdkDir string, setupArgs []string, execute func(name string, a } // StartTarget starts the spdk_tgt with the given args -func StartTarget(spdkDir string, args []string, execute func(binary string, args []string, timeout time.Duration) (string, error)) (err error) { +func StartTarget(spdkDir string, args []string, execute func(envs []string, binary string, args []string, timeout time.Duration) (string, error)) (err error) { if spdkCli, err := client.NewClient(context.Background()); err == nil { if _, err := spdkCli.BdevGetBdevs("", 0); err == nil { logrus.Info("Detected running spdk_tgt, skipped the target starting") @@ -64,6 +64,6 @@ func StartTarget(spdkDir string, args []string, execute func(binary string, args fmt.Sprintf("%s %s", filepath.Join(spdkDir, SPDKTGTBinary), argsInStr), } - _, err = execute("sh", tgtOpts, types.ExecuteTimeout) + _, err = execute(nil, "sh", tgtOpts, types.ExecuteTimeout) return err } diff --git a/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/aio.go b/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/aio.go index 015ade311..404e305c2 100644 --- a/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/aio.go +++ b/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/aio.go @@ -15,7 +15,7 @@ type BdevAioDriverSpecificInfo struct { type BdevAioCreateRequest struct { Name string `json:"name"` Filename string `json:"filename"` - BlockSize uint64 `json:"block_size"` + BlockSize uint64 `json:"block_size,omitzero"` } type BdevAioDeleteRequest struct { diff --git a/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/bdev.go b/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/bdev.go index c693cd224..3ae95f72d 100644 --- a/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/bdev.go +++ b/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/bdev.go @@ -3,10 +3,12 @@ package types type BdevProductName string const ( - BdevProductNameAio = BdevProductName("AIO disk") - BdevProductNameLvol = BdevProductName("Logical Volume") - BdevProductNameRaid = BdevProductName("Raid Volume") - BdevProductNameNvme = BdevProductName("NVMe disk") + BdevProductNameAio = BdevProductName("AIO disk") + BdevProductNameLvol = BdevProductName("Logical Volume") + BdevProductNameRaid = BdevProductName("Raid Volume") + BdevProductNameNvme = BdevProductName("NVMe disk") + BdevProductNameVirtioBlk = BdevProductName("VirtioBlk Disk") + BdevProductNameVirtioScsi = BdevProductName("Virtio SCSI Disk") ) type BdevType string @@ -19,7 +21,7 @@ const ( ) func GetBdevType(bdev *BdevInfo) BdevType { - if bdev == nil { + if bdev == nil || bdev.DriverSpecific == nil { return "" } if bdev.ProductName == BdevProductNameAio && bdev.DriverSpecific.Aio != nil { diff --git a/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/lvol.go b/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/lvol.go index 0d7a8dea2..74735a5e0 100644 --- a/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/lvol.go +++ b/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/lvol.go @@ -6,14 +6,15 @@ import ( ) type BdevDriverSpecificLvol struct { - LvolStoreUUID string `json:"lvol_store_uuid"` - BaseBdev string `json:"base_bdev"` - BaseSnapshot string `json:"base_snapshot,omitempty"` - ThinProvision bool `json:"thin_provision"` - NumAllocatedClusters uint64 `json:"num_allocated_clusters"` - Snapshot bool `json:"snapshot"` - Clone bool `json:"clone"` - Clones []string `json:"clones,omitempty"` + LvolStoreUUID string `json:"lvol_store_uuid"` + BaseBdev string `json:"base_bdev"` + BaseSnapshot string `json:"base_snapshot,omitempty"` + ThinProvision bool `json:"thin_provision"` + NumAllocatedClusters uint64 `json:"num_allocated_clusters"` + Snapshot bool `json:"snapshot"` + Clone bool `json:"clone"` + Clones []string `json:"clones,omitempty"` + Xattrs map[string]string `json:"xattrs,omitempty"` } type LvstoreInfo struct { @@ -92,8 +93,9 @@ type BdevLvolDeleteRequest struct { } type BdevLvolSnapshotRequest struct { - LvolName string `json:"lvol_name"` - SnapshotName string `json:"snapshot_name"` + LvolName string `json:"lvol_name"` + SnapshotName string `json:"snapshot_name"` + Xattrs map[string]string `json:"xattrs,omitempty"` } type BdevLvolCloneRequest struct { diff --git a/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/nvme.go b/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/nvme.go index 76afe25df..b7fe46911 100644 --- a/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/nvme.go +++ b/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/nvme.go @@ -21,10 +21,11 @@ const ( type BdevDriverSpecificNvme []NvmeNamespaceInfo type NvmeNamespaceInfo struct { - CtrlrData NvmeCtrlrData `json:"ctrlr_data"` - NsData NvmeNsData `json:"ns_data"` - Trid NvmeTransportID `json:"trid"` - VS NvmeVendorSpecific `json:"vs"` + PciAddress string `json:"pci_address,omitempty"` + CtrlrData NvmeCtrlrData `json:"ctrlr_data"` + NsData NvmeNsData `json:"ns_data"` + Trid NvmeTransportID `json:"trid"` + VS NvmeVendorSpecific `json:"vs"` } type NvmeCtrlrData struct { diff --git a/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/virtio.go b/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/virtio.go new file mode 100644 index 000000000..2d240aac9 --- /dev/null +++ b/vendor/github.com/longhorn/go-spdk-helper/pkg/spdk/types/virtio.go @@ -0,0 +1,12 @@ +package types + +type BdevVirtioAttachControllerRequest struct { + Name string `json:"name"` + Trtype string `json:"trtype"` + Traddr string `json:"traddr"` + DevType string `json:"dev_type"` +} + +type BdevVirtioDetachControllerRequest struct { + Name string `json:"name"` +} diff --git a/vendor/github.com/longhorn/go-spdk-helper/pkg/util/device.go b/vendor/github.com/longhorn/go-spdk-helper/pkg/util/device.go index c1af63551..f09bfd4a7 100644 --- a/vendor/github.com/longhorn/go-spdk-helper/pkg/util/device.go +++ b/vendor/github.com/longhorn/go-spdk-helper/pkg/util/device.go @@ -69,7 +69,7 @@ func GetKnownDevices(executor *commonNs.Executor) (map[string]*KernelDevice, err "-l", "-n", "-o", "NAME,MAJ:MIN", } - output, err := executor.Execute(lsblkBinary, opts, types.ExecuteTimeout) + output, err := executor.Execute(nil, lsblkBinary, opts, types.ExecuteTimeout) if err != nil { return knownDevices, err } @@ -105,7 +105,7 @@ func DetectDevice(path string, executor *commonNs.Executor) (*KernelDevice, erro "-l", "-n", path, "-o", "NAME,MAJ:MIN", } - output, err := executor.Execute(lsblkBinary, opts, types.ExecuteTimeout) + output, err := executor.Execute(nil, lsblkBinary, opts, types.ExecuteTimeout) if err != nil { return nil, err } @@ -188,7 +188,7 @@ func GetDeviceSectorSize(devPath string, executor *commonNs.Executor) (int64, er "--getsz", devPath, } - output, err := executor.Execute(BlockdevBinary, opts, types.ExecuteTimeout) + output, err := executor.Execute(nil, BlockdevBinary, opts, types.ExecuteTimeout) if err != nil { return -1, err } @@ -201,7 +201,7 @@ func GetDeviceNumbers(devPath string, executor *commonNs.Executor) (int, int, er opts := []string{ "-l", "-J", "-n", "-o", "MAJ:MIN", devPath, } - output, err := executor.Execute(lsblkBinary, opts, types.ExecuteTimeout) + output, err := executor.Execute(nil, lsblkBinary, opts, types.ExecuteTimeout) if err != nil { return -1, -1, err } diff --git a/vendor/github.com/longhorn/go-spdk-helper/pkg/util/dmsetup.go b/vendor/github.com/longhorn/go-spdk-helper/pkg/util/dmsetup.go index 4fab02167..c761ca0c2 100644 --- a/vendor/github.com/longhorn/go-spdk-helper/pkg/util/dmsetup.go +++ b/vendor/github.com/longhorn/go-spdk-helper/pkg/util/dmsetup.go @@ -17,7 +17,7 @@ func DmsetupCreate(dmDeviceName, table string, executor *commonNs.Executor) erro opts := []string{ "create", dmDeviceName, "--table", table, } - _, err := executor.Execute(dmsetupBinary, opts, types.ExecuteTimeout) + _, err := executor.Execute(nil, dmsetupBinary, opts, types.ExecuteTimeout) return err } @@ -35,7 +35,7 @@ func DmsetupSuspend(dmDeviceName string, noflush, nolockfs bool, executor *commo opts = append(opts, "--nolockfs") } - _, err := executor.Execute(dmsetupBinary, opts, types.ExecuteTimeout) + _, err := executor.Execute(nil, dmsetupBinary, opts, types.ExecuteTimeout) return err } @@ -44,7 +44,7 @@ func DmsetupResume(dmDeviceName string, executor *commonNs.Executor) error { opts := []string{ "resume", dmDeviceName, } - _, err := executor.Execute(dmsetupBinary, opts, types.ExecuteTimeout) + _, err := executor.Execute(nil, dmsetupBinary, opts, types.ExecuteTimeout) return err } @@ -53,7 +53,7 @@ func DmsetupReload(dmDeviceName, table string, executor *commonNs.Executor) erro opts := []string{ "reload", dmDeviceName, "--table", table, } - _, err := executor.Execute(dmsetupBinary, opts, types.ExecuteTimeout) + _, err := executor.Execute(nil, dmsetupBinary, opts, types.ExecuteTimeout) return err } @@ -68,7 +68,7 @@ func DmsetupRemove(dmDeviceName string, force, deferred bool, executor *commonNs if deferred { opts = append(opts, "--deferred") } - _, err := executor.Execute(dmsetupBinary, opts, types.ExecuteTimeout) + _, err := executor.Execute(nil, dmsetupBinary, opts, types.ExecuteTimeout) return err } @@ -78,7 +78,7 @@ func DmsetupDeps(dmDeviceName string, executor *commonNs.Executor) ([]string, er "deps", dmDeviceName, "-o", "devname", } - outputStr, err := executor.Execute(dmsetupBinary, opts, types.ExecuteTimeout) + outputStr, err := executor.Execute(nil, dmsetupBinary, opts, types.ExecuteTimeout) if err != nil { return nil, err } diff --git a/vendor/modules.txt b/vendor/modules.txt index da9b2b52d..056e89cd2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -53,7 +53,7 @@ github.com/longhorn/backupstore github.com/longhorn/backupstore/logging github.com/longhorn/backupstore/types github.com/longhorn/backupstore/util -# github.com/longhorn/go-common-libs v0.0.0-20240103081802-3993c5908447 +# github.com/longhorn/go-common-libs v0.0.0-20240103081802-3993c5908447 => github.com/derekbit/go-common-libs v0.0.0-20240207042018-b592223bef9f ## explicit; go 1.21 github.com/longhorn/go-common-libs/exec github.com/longhorn/go-common-libs/io @@ -64,11 +64,12 @@ github.com/longhorn/go-common-libs/sync github.com/longhorn/go-common-libs/sys github.com/longhorn/go-common-libs/types github.com/longhorn/go-common-libs/utils -# github.com/longhorn/go-spdk-helper v0.0.0-20240117135122-26f8acb2a13d +# github.com/longhorn/go-spdk-helper v0.0.0-20240117135122-26f8acb2a13d => github.com/derekbit/go-spdk-helper v0.0.0-20240216014357-3c42253cb60f ## explicit; go 1.21 github.com/longhorn/go-spdk-helper/pkg/jsonrpc github.com/longhorn/go-spdk-helper/pkg/nvme github.com/longhorn/go-spdk-helper/pkg/spdk/client +github.com/longhorn/go-spdk-helper/pkg/spdk/setup github.com/longhorn/go-spdk-helper/pkg/spdk/target github.com/longhorn/go-spdk-helper/pkg/spdk/types github.com/longhorn/go-spdk-helper/pkg/types