Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for NBD #212

Merged
merged 3 commits into from
Nov 25, 2024
Merged

feat: add support for NBD #212

merged 3 commits into from
Nov 25, 2024

Conversation

lstocchi
Copy link
Contributor

@lstocchi lstocchi commented Oct 30, 2024

This patch adds support for NBD. The NetworkBlockDevice protocol allows remote block devices to be accessed over the network. By leveraging it we can connect our VM to a remote block device and use it as a local disk.

User can specify the timeout and the synchronization mode (none or full). More info at https://developer.apple.com/documentation/virtualization/vzdisksynchronizationmode?language=objc

It also listens to changes to the network block device attachment, so if there is some connectivity changes (connect, disconnect), the user is informed. To achieve it, it leverages the delegate provided by the Virtualization Framework. More info at https://developer.apple.com/documentation/virtualization/vznetworkblockdevicestoragedeviceattachmentdelegate?language=objc

This feature is only available for macOS 14.0+ and requires an update to the VZ library. So this implementation could be modified based on the work done there.

It needs Code-Hex/vz#156 and Code-Hex/vz#166

It resolves #129

Copy link

openshift-ci bot commented Oct 30, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@lstocchi
Copy link
Contributor Author

Added initial tests and documentation. I plan to also add an e2e test.
I'll wait the vz patch to be merged before refining everything but ready for an early review if you want

@lstocchi
Copy link
Contributor Author

Added initial tests and documentation. I plan to also add an e2e test. I'll wait the vz patch to be merged before refining everything but ready for an early review if you want

After looking again, I'll skip the e2e test bc I need Mac 14 to work and the current workflow skip it, so maybe we can work on it in a separate PR if we want to do it.

For the rest it should be ready for a review. We just need to merge #214 and rebase it.
@cfergeau

pkg/vf/virtio.go Outdated
@@ -289,6 +290,73 @@ func (dev *VirtioVsock) AddToVirtualMachineConfig(vmConfig *VirtualMachineConfig
return nil
}

func (dev *NetworkBlockDevice) toVz() (vz.StorageDeviceConfiguration, error) {
if dev.Uri == "" || dev.DeviceIdentifier == "" {
return nil, fmt.Errorf("missing required options for NBD device: 'uri' and 'deviceId' must be specified")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you check for empty options, but do you ever check to see if they are valid? If you do and you confident in that, maybe move this to that section?

pkg/vf/virtio.go Outdated
}

func (dev *NetworkBlockDevice) SyncronizationModeVZ() vz.DiskSynchronizationMode {
switch dev.SynchronizationMode {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if with an early return and then return the default ?

pkg/vf/virtio.go Outdated
attachment := dev.Attachment()
if nbdAttachment, isNbdAttachment := attachment.(*vz.NetworkBlockDeviceStorageDeviceAttachment); isNbdAttachment {
nbdId, err := dev.(*vz.VirtioBlockDeviceConfiguration).BlockDeviceIdentifier()
if err != nil || nbdId == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like we have comingled errors here ... or is it not possible to have an error when calling BlockDeviceIdentifier? Maybe that func should return a defined error like ErrNoBlockDevID so you can later compare it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot change BlockDeviceIdentifier directly as it is part of an external dep but I think the nbdID check can also be omitted here. I already verify if the identifier is set by the user earlier. Here I just retrieve it

@lstocchi lstocchi force-pushed the i129 branch 2 times, most recently from 53125ed to 26dd623 Compare November 13, 2024 13:35
@lstocchi lstocchi requested a review from baude November 13, 2024 13:43
@lstocchi
Copy link
Contributor Author

@baude updated 👍

@lstocchi lstocchi marked this pull request as ready for review November 14, 2024 10:26
@openshift-ci openshift-ci bot requested a review from anjannath November 14, 2024 10:26
@lstocchi
Copy link
Contributor Author

Forgot to mark it ready 😄

pkg/vf/virtio.go Show resolved Hide resolved
pkg/vf/virtio.go Outdated Show resolved Hide resolved
pkg/config/json_test.go Outdated Show resolved Hide resolved
pkg/config/config.go Show resolved Hide resolved
pkg/vf/virtio.go Outdated Show resolved Hide resolved
pkg/config/virtio.go Show resolved Hide resolved
pkg/config/virtio.go Show resolved Hide resolved
pkg/config/virtio.go Show resolved Hide resolved
pkg/vf/virtio.go Outdated Show resolved Hide resolved
pkg/vf/virtio.go Outdated Show resolved Hide resolved
This patch adds support for NBD. The NetworkBlockDevice protocol allows remote block devices to be accessed over the network. By leveraging it we can connect our VM to a remote block device and use it as a local disk.

User can specify the timeout and the synchronization mode (none or full). More info ati https://developer.apple.com/documentation/virtualization/vzdisksynchronizationmode?language=objc

It also listens to changes to the network block device attachment, so if there is some connectivity changes (connect, disconnect), the user is informed.
To achieve it, it leverages the delegate provided by the Virtualization Framework. More info at https://developer.apple.com/documentation/virtualization/vznetworkblockdevicestoragedeviceattachmentdelegate?language=objc

This feature is only available for macOS 14.0+

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
add documentation to explain how to use the new NetworkBlockDevice device.
Args list and examples are provided in the usage.md file

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
@cfergeau
Copy link
Collaborator

/lgtm
/approve

Copy link

openshift-ci bot commented Nov 25, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfergeau

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit 4af22e9 into crc-org:main Nov 25, 2024
5 checks passed
@lstocchi lstocchi deleted the i129 branch November 25, 2024 12:55
lstocchi added a commit to lstocchi/vfkit that referenced this pull request Nov 25, 2024
crc-org#212 introduced a new property to the StorageConfig struct (URI) and, by doing so, now we have to check if we are dealing with a disk storage or a remote disk device by checking imagePath and Uri fields. An idea that came up in crc-org#212 (comment) was to refactor the StorageConfig struct to be extended by a DiskStorageConfig and a NetworkBlockStorageConfig.

This PR refactors the code based on that suggestion.

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add NBD support
3 participants