diff --git a/go.mod b/go.mod index 8fe8dde14..ec62ac57e 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/google/uuid v1.6.0 github.com/longhorn/backupstore v0.0.0-20240219094812-3a87ee02df77 github.com/longhorn/go-common-libs v0.0.0-20240319112414-b75404dc7fbc - github.com/longhorn/go-spdk-helper v0.0.0-20240319142717-116729b98b89 + github.com/longhorn/go-spdk-helper v0.0.0-20240320070503-b4a1af9f0800 github.com/longhorn/longhorn-engine v1.6.0-dev-20240105.0.20240126141003-067f67803ee8 github.com/longhorn/longhorn-spdk-engine v0.0.0-20240319114738-c9046e18cf8c github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 22e6762d3..b9ffa1f58 100644 --- a/go.sum +++ b/go.sum @@ -83,6 +83,8 @@ github.com/longhorn/go-spdk-helper v0.0.0-20240315133419-fd71aaab4a11 h1:qfr6EjG github.com/longhorn/go-spdk-helper v0.0.0-20240315133419-fd71aaab4a11/go.mod h1:ByXr0dR+YNz0H1+k8aBXjSzQ7R2Y2UI6f4+d90YTM/M= github.com/longhorn/go-spdk-helper v0.0.0-20240319142717-116729b98b89 h1:NdWVJURZRFnyLDIpw/Ocx9bsQCdHpBkr0BOuQQCyPtg= github.com/longhorn/go-spdk-helper v0.0.0-20240319142717-116729b98b89/go.mod h1:do6+0y096uk/gW1d5iOKMuebFcf/OiIhyOtIUVamReU= +github.com/longhorn/go-spdk-helper v0.0.0-20240320070503-b4a1af9f0800 h1:ThB03ABY//RSD8umQNLTzuU4QNG2YfWUASJP6+nTeow= +github.com/longhorn/go-spdk-helper v0.0.0-20240320070503-b4a1af9f0800/go.mod h1:WGm84AyXymx7L0CqOw8KEr9okywD+Cj5xZi+eKeOoiU= github.com/longhorn/longhorn-engine v1.6.0-dev-20240105.0.20240126141003-067f67803ee8 h1:Oj5bAlKBzS+qPxA8lfpUcbllrVjnHVCuhPcQv/V98xw= github.com/longhorn/longhorn-engine v1.6.0-dev-20240105.0.20240126141003-067f67803ee8/go.mod h1:Snkv3gy4AUOhZSYMI7g7lVX/OOB8DTo28eJwsEfbAwM= github.com/longhorn/longhorn-spdk-engine v0.0.0-20240315010143-da2a02e86462 h1:eVMZH4r+v1NwBbsuxdTmiJD4odWQ0GmuYgS1KN93nss= 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 038162f16..6b4ee9623 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 @@ -4,6 +4,8 @@ import ( "encoding/json" "strings" + "github.com/pkg/errors" + spdktypes "github.com/longhorn/go-spdk-helper/pkg/spdk/types" ) @@ -1045,3 +1047,50 @@ func (c *Client) LogGetPrintLevel() (string, error) { return strings.Trim(string(level), "\"\n"), nil } + +// BdevVirtioAttachController creates new initiator Virtio SCSI or Virtio Block and expose all found bdevs. +// +// "name": Required. Use this name as base for new created bdevs. +// +// "trtype": Required. Transport type, "user" or "pci". +// +// "traddr": Required. Transport type specific target address: e.g. UNIX domain socket path or BDF. +// +// "devType": Required. Device type, "scsi" or "blk". +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. +// +// "name": Required. Use this name as base for new created bdevs. +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/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 27c40da85..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 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/modules.txt b/vendor/modules.txt index 1ed5aea53..2c612cc3e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -157,7 +157,7 @@ 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-20240319142717-116729b98b89 +# github.com/longhorn/go-spdk-helper v0.0.0-20240320070503-b4a1af9f0800 ## explicit; go 1.21 github.com/longhorn/go-spdk-helper/pkg/jsonrpc github.com/longhorn/go-spdk-helper/pkg/nvme