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

Rewrite SCSI support in new package #1744

Merged
merged 1 commit into from
May 15, 2023
Merged

Rewrite SCSI support in new package #1744

merged 1 commit into from
May 15, 2023

Conversation

kevpar
Copy link
Member

@kevpar kevpar commented Apr 23, 2023

This is commit 5/6 in a chain. Recommended to review in order. If reviewing a later PR in the chain, you can view individual commits to see just what that PR changes.

The existing SCSI implementation in internal/uvm has evolved organically
over time into what it is today. This creates unecessary difficulty when
adding new features to the code, makes it harder to maintain, and has
been a source of bugs.

Additionally, there is a significant functional issue that the current
scsi code tightly couples the idea of attaching a SCSI device to a VM,
with the use/mounting of that device inside the VM. This creates
difficulty when we want to re-use the same SCSI attachment multiple
times, especially in the future when we will need to mount multiple
partitions from a device.

This is addressed here by largely rewriting the shim's SCSI code, and
moving it to a new internal/uvm/scsi package. The new code features a
main Manager type, which delegates to attachManager and mountManager for
tracking of attachments to the VM, and mounting of devices inside the
VM, respectively. attachManager and mountManager also rely on a set of
interfaces for the actual backend implementation of interacting with a
VM. This will also allow for easier testing of the scsi package in
isolation in the future.

One consequence of this change is it is no longer possible for the
caller to request a specific UVM path for a SCSI mount. The support for
this was already kind of a sham, because if the disk was already
mounted, you would get back its existing mount path instead of the one
you wanted, so the caller already had to handle that case. Additionally,
I'm not aware of any reason why the specific location the disk is
mounted is actually relevant. Because of these reasons, and to simplify
the overall package interface, the mount path is determined by the scsi
package, using a format string passed to the Manager at creation time.

internal/uvm/scsi/manager.go Show resolved Hide resolved
internal/uvm/scsi/README.md Show resolved Hide resolved
internal/uvm/scsi/manager.go Show resolved Hide resolved
internal/uvm/scsi/mount.go Outdated Show resolved Hide resolved
internal/uvm/scsi/mount.go Outdated Show resolved Hide resolved
internal/uvm/scsi/mount.go Show resolved Hide resolved
internal/uvm/scsi/mount.go Outdated Show resolved Hide resolved
@katiewasnothere
Copy link
Contributor

Could you elaborate more on the reasoning behind the "unplugger" type? There's never a time where a call to detach an attachment wouldn't also come with an unplug call right? Why not just have "unplug" be another function call on the "attacher"?

@katiewasnothere
Copy link
Contributor

Are we tracking somewhere that there will need to be changes to support confidential containers as a result of this PR?

@kevpar
Copy link
Member Author

kevpar commented Apr 25, 2023

Could you elaborate more on the reasoning behind the "unplugger" type? There's never a time where a call to detach an attachment wouldn't also come with an unplug call right? Why not just have "unplug" be another function call on the "attacher"?

The intent was to decouple "VM" operations from "guest" operations. Since in the future we probably want to move these parts of the code further apart, as e.g. we may have different components managing VM vs guest.

Are we tracking somewhere that there will need to be changes to support confidential containers as a result of this PR?

Not currently. Is there some specific support you're thinking of that should be tracked?

@kevpar kevpar force-pushed the new-scsi branch 2 times, most recently from 48302df to 7397839 Compare April 25, 2023 17:44
@katiewasnothere
Copy link
Contributor

The intent was to decouple "VM" operations from "guest" operations. Since in the future we probably want to move these parts of the code further apart, as e.g. we may have different components managing VM vs guest.

Ah okay, that seems reasonable to me.

Not currently. Is there some specific support you're thinking of that should be tracked?

I was thinking specifically for the new bridge calls. They will need to add new policies for those calls.

@kevpar
Copy link
Member Author

kevpar commented Apr 25, 2023

I was thinking specifically for the new bridge calls. They will need to add new policies for those calls.

Are you referring to the SCSIDevice resource type for "new bridge calls"? If so I agree that is something that needs looking into.

@anmaxvl what is the plan for how we keep policy up to date with bridge protocol changes?

@kevpar
Copy link
Member Author

kevpar commented Apr 26, 2023

I was thinking specifically for the new bridge calls. They will need to add new policies for those calls.

Are you referring to the SCSIDevice resource type for "new bridge calls"? If so I agree that is something that needs looking into.

@anmaxvl what is the plan for how we keep policy up to date with bridge protocol changes?

I discussed offline with Maksim. We agreed there is no need to address this right now. In the future we can add a policy enforcement point for SCSIDevice removal.

internal/uvm/scsi/attach.go Outdated Show resolved Hide resolved
internal/uvm/scsi/mount.go Outdated Show resolved Hide resolved
internal/uvm/scsi/mount.go Outdated Show resolved Hide resolved
Copy link
Contributor

@helsaawy helsaawy left a comment

Choose a reason for hiding this comment

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

Im worried this design is over-complicated and exposes a lot to the uVM client.

Now the clients have to

  1. worry about calling GrantVmAccess before Add, regardless of whether the VHD was already attached (whereas before this was taken care of automatically) and is a requirement that isnt documented for the manager;
  2. create the appropriate Attacher/Mounter/Unpluger even though the scsi package could have taken care of that by exposing dedicated NewBridgeManager/NewHCSManager; and
  3. ensure they don't erroneously mix and match bridge and HCS (eg, an hcsMounter and a bridgeUnplugger).

I doubt the client needs to worry about the individual low-level components, since they should be dictated by the type of uVM we have, so exposing them feels unnecessary.

internal/uvm/scsi/README.md Outdated Show resolved Hide resolved
internal/uvm/scsi/README.md Show resolved Hide resolved
internal/uvm/vpmem.go Outdated Show resolved Hide resolved
internal/uvm/scsi/backend.go Outdated Show resolved Hide resolved
internal/uvm/scsi/manager.go Show resolved Hide resolved
@kevpar kevpar force-pushed the new-scsi branch 2 times, most recently from cb906a3 to 83bf282 Compare May 3, 2023 08:57
@katiewasnothere
Copy link
Contributor

katiewasnothere commented May 5, 2023

Actually, do we really need to be able to support only attaching a scsi device and not mounting it? As far as I can tell, we only do that in two places: in this runhcs code that I'm pretty sure we don't use anymore to "prepare" a disk AND in the code to create a scratch disk here.

For creating the scratch, couldn't we make use of the changes I made here #1757 to EnsureFilesystem on the device? I'm not sure if adding in a mount for the scratch formatting would slow down the whole operation or by how much, since the create scratch code does already require making a call into the UVM to run mkfs anyways and we could get that for free as part of the mount call with EnsureFilesystem.

@kevpar
Copy link
Member Author

kevpar commented May 8, 2023

Actually, do we really need to be able to support only attaching a scsi device and not mounting it? As far as I can tell, we only do that in two places: in this runhcs code that I'm pretty sure we don't use anymore to "prepare" a disk AND in the code to create a scratch disk here.

For creating the scratch, couldn't we make use of the changes I made here #1757 to EnsureFilesystem on the device? I'm not sure if adding in a mount for the scratch formatting would slow down the whole operation or by how much, since the create scratch code does already require making a call into the UVM to run mkfs anyways and we could get that for free as part of the mount call with EnsureFilesystem.

That's a good point, but I think we should keep the ability to attach without mounting. There's a good possibility in the future we will want to do something like expose a block device directly into a container, and we would need this ability to do that (e.g. if there is no filesystem on the device).

@katiewasnothere
Copy link
Contributor

Why did we move around verity code in this PR? Just cleaning?

@kevpar
Copy link
Member Author

kevpar commented May 9, 2023

Why did we move around verity code in this PR? Just cleaning?

Yeah, it has no relation to SCSI, so didn't make sense to be in the scsi package.

@katiewasnothere
Copy link
Contributor

Have you run the cri-containerd tests with these changes?

@kevpar
Copy link
Member Author

kevpar commented May 9, 2023

Have you run the cri-containerd tests with these changes?

I ran them a bit ago, hit a bunch of unrelated failures, but mostly things seemed okay. I can do another run to see how it looks now.

Copy link
Contributor

@katiewasnothere katiewasnothere left a comment

Choose a reason for hiding this comment

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

lgtm if the cri-containerd tests pass

internal/uvm/scsi/attach.go Outdated Show resolved Hide resolved
internal/uvm/scsi/attach.go Show resolved Hide resolved
internal/uvm/scsi/manager.go Show resolved Hide resolved
internal/uvm/scsi/manager.go Outdated Show resolved Hide resolved
internal/uvm/scsi/manager.go Show resolved Hide resolved
internal/uvm/scsi/mount.go Outdated Show resolved Hide resolved
internal/uvm/types.go Show resolved Hide resolved
@kevpar
Copy link
Member Author

kevpar commented May 12, 2023

@helsaawy I pushed a temporary commit addressing your feedback, so it is easier to view it separately.

The existing SCSI implementation in internal/uvm has evolved organically
over time into what it is today. This creates unecessary difficulty when
adding new features to the code, makes it harder to maintain, and has
been a source of bugs.

Additionally, there is a significant functional issue that the current
scsi code tightly couples the idea of attaching a SCSI device to a VM,
with the use/mounting of that device inside the VM. This creates
difficulty when we want to re-use the same SCSI attachment multiple
times, especially in the future when we will need to mount multiple
partitions from a device.

This is addressed here by largely rewriting the shim's SCSI code, and
moving it to a new internal/uvm/scsi package. The new code features a
main Manager type, which delegates to attachManager and mountManager for
tracking of attachments to the VM, and mounting of devices inside the
VM, respectively. attachManager and mountManager also rely on a set of
interfaces for the actual backend implementation of interacting with a
VM. This will also allow for easier testing of the scsi package in
isolation in the future.

One consequence of this change is it is no longer possible for the
caller to request a specific UVM path for a SCSI mount. The support for
this was already kind of a sham, because if the disk was already
mounted, you would get back its existing mount path instead of the one
you wanted, so the caller already had to handle that case. Additionally,
I'm not aware of any reason why the specific location the disk is
mounted is actually relevant. Because of these reasons, and to simplify
the overall package interface, the mount path is determined by the scsi
package, using a format string passed to the Manager at creation time.

Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
@kevpar kevpar merged commit 5c5d85c into microsoft:main May 15, 2023
anmaxvl pushed a commit that referenced this pull request Oct 20, 2023
This PR updates our ADO fork to commits in hcsshim up to commit hash [7769a64](7769a64). This includes support for partitioned scsi devices and ensuring filesystem format for lcow scsi devices.

Related work items: #1728, #1740, #1741, #1742, #1743, #1744, #1745, #1747, #1748, #1749, #1750, #1752, #1754, #1756, #1757, #1767, #1769, #1771, #1772, #1773, #1779
princepereira pushed a commit to princepereira/hcsshim that referenced this pull request Aug 29, 2024
Rewrite SCSI support in new package
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants