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

SCSI ensure filesystem #1757

Conversation

katiewasnothere
Copy link
Contributor

@katiewasnothere katiewasnothere commented May 5, 2023

This PR is based on #1747, which is in turn based on the below PRs:

This PR additionally has one temporary commit that was used for testing. When the PRs that this PR is based on are updated, this PR will also need to be updated and will likely have some rebase conflicts. You can find the target code changes in the last commit on this PR.

The main work in this PR is the creation of two new options on an LCOW scsi mount EnsureFilesystem and Filesystem. These options are added to light up the ability to optionally ensure that a disk has a specific filesystem configured on it in the guest.

This PR does the following:

  • Add new EnsureFilesystem and Filesystem options on LCOWMappedVirtualDisk
  • Add matching EnsureFilesystem and Filesystem options on scsi MountConfig
  • Set EnsureFilesystem and Filesystem when attaching scratch devices
  • New package for formatting using xfs
  • Add plumbing in guest scsi package to support EnsureFilesystem and Filesystem.
  • Create new Config type in guest scsi package for passing in setup/cleanup configuration settings
  • Move wait for scsi /dev device before other actions are taken during mount.
  • Add new call to get a device's filesystem by reading its superblock
  • Add new scsi unit tests for new features and update existing tests

Note: it is expected that this PR does not currently pass the linter or integration tests in the CI.

@katiewasnothere katiewasnothere requested a review from a team as a code owner May 5, 2023 01:14
@katiewasnothere katiewasnothere changed the title Kabaldau/scsi ensure filesystem SCSI ensure filesystem May 5, 2023
// wait for `source` to show up.
for {
if _, err := osStat(source); err != nil {
if errors.Is(err, fs.ErrNotExist) || errors.Is(err, unix.ENOENT) || errors.Is(err, unix.ENXIO) {
Copy link
Member

Choose a reason for hiding this comment

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

Previously we were checking the error from unix.Mount against ENOENT and ENXIO. Now we are checking the error from os.Stat against those as well as ErrNotExist. What's the reasoning behind the set of errors checked here? Do we expect it will always be ErrNotExist, and we are keeping the previous errors just in case, but don't think they are needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The man page for stat does mention ENOENT (see here), but doesn't directly mention ENXIO. The page could just be out of date though.

I also did some testing where I ran Test_70LayerImagesWithNoVPmemForLayers, recommended by Amit, roughly 150 times. I only ever saw ErrNotExist and ENOENT (at the same time), but I'm not confident we'd never hit ENXIO so I left it.

Copy link
Member

Choose a reason for hiding this comment

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

syscall.ENOENT is implemented such that it will always be equal to fs.ErrNotExist, so I don't think we need to check both of those. I'd also be in favor of either removing ENXIO from the set unless we have a reason to keep it in. Maybe @anmaxvl has context here?

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 removed the ENOENT option. Waiting to hear from Maksim or Amit on the ENXIO error.

Copy link
Contributor

@anmaxvl anmaxvl May 9, 2023

Choose a reason for hiding this comment

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

sorry, just saw the ping. I think Amit was the one who was hitting ENXIO with newer kernel. In my case, I was running into ENODEV, when trying to format/encrypt scratch...
Edit:
It could've also been when mounting layers with verity actually, now that I think about it... formatting scratch won't return an actual error, but rather we parse through the mkfs.xfs or cryptsetup output. I believe @KenGordon actually saw "device not found" errors when adding scratch.

@katiewasnothere katiewasnothere force-pushed the kabaldau/scsi_ensure_filesystem branch 2 times, most recently from fbd2f91 to 67676d2 Compare May 6, 2023 00:11
@katiewasnothere
Copy link
Contributor Author

After finding some issues with busybox's blkid, I decided to switch this PR instead to read the device's superblock directly to get the filesystem type. Unfortunately, this means we are limited in what filesystem types we "get for free" from pre-formatted devices. However, since we only use ext4 and xfs today, the impact should be minimal to none.

I first intended to include code here to determine if a device was formatted with xfs and code to format devices with xfs if requested when EnsureFilesystem is set. However, our standard LCOW image does not include xfs support so I felt it wasn't necessary to include right now.

internal/layers/layers.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
@katiewasnothere katiewasnothere force-pushed the kabaldau/scsi_ensure_filesystem branch 2 times, most recently from 8f08336 to 246204e Compare May 12, 2023 00:51
@katiewasnothere
Copy link
Contributor Author

Rebased with latest changes from #1744, #1745, and #1747

Copy link
Member

@kevpar kevpar left a comment

Choose a reason for hiding this comment

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

LGTM pending the following:

  • Final rebase on earlier PRs once they are merged.
  • Rebase to combine commits in this PR into a good set.
  • CI green.

@katiewasnothere katiewasnothere force-pushed the kabaldau/scsi_ensure_filesystem branch 2 times, most recently from 2a76b0d to 0415226 Compare May 15, 2023 20:20
@katiewasnothere katiewasnothere force-pushed the kabaldau/scsi_ensure_filesystem branch 2 times, most recently from 059cb9a to 507bf4c Compare May 15, 2023 20:55
Copy link
Member

@kevpar kevpar left a comment

Choose a reason for hiding this comment

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

LGTM

* Add new `EnsureFilesystem` and `Filesystem` options on
LCOWMappedVirtualDisk
* Add matching `EnsureFilesystem` and `Filesystem` options on scsi
MountConfig
* Set `EnsureFilesystem` and `Filesystem` when attaching scratch devices
* Add plumbing in guest scsi package to support `EnsureFilesystem` and
`Filesystem`.
* Create new `Config` type in guest scsi package for passing in
setup/cleanup configuration settings
* Add new call to get a device's filesystem by reading its superblock
* Add new scsi unit tests for new features and update existing tests
* New package for formatting using xfs
* Move xfs formatting for encrypted devices out of crypt pkg into scsi

Signed-off-by: Kathryn Baldauf <kabaldau@microsoft.com>
@katiewasnothere katiewasnothere force-pushed the kabaldau/scsi_ensure_filesystem branch from 507bf4c to af8c444 Compare May 15, 2023 22:08
@katiewasnothere
Copy link
Contributor Author

Rebased. Will merge on CI passing.

@katiewasnothere katiewasnothere merged commit 7769a64 into microsoft:main May 15, 2023
14 of 16 checks passed
@katiewasnothere katiewasnothere deleted the kabaldau/scsi_ensure_filesystem branch May 15, 2023 23:01
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
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.

None yet

4 participants