Skip to content

Conversation

@darstahl
Copy link
Contributor

@darstahl darstahl commented Oct 6, 2017

This is a work in progress (nearly finished) implementation of snapshotter and differ on Windows and the corresponding changes in ctr and Windows runtime to use the new snapshotter/differ.

PS H:\git\go\src\github.com\containerd\containerd> ctr.exe pull docker.io/microsoft/nanoserver:latest
docker.io/microsoft/nanoserver:latest:                                            resolved       |++++++++++++++++++++++++++++++++++++++|
manifest-sha256:8b4ab2db6fd93063b50233a17fc0084015a3fcc774d7b17528bb4baf97aa7949: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:5cd49617cf500abea7b9f47d82b70455d816ae6b497cabc1fc86a9522d19a828:    done           |++++++++++++++++++++++++++++++++++++++|
config-sha256:00f2c6e8b100efb59b4febf77b09b2588b3fc55f45e2e035e8208e1cceb94339:   done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:bce2fbc256ea437a87dadac2f69aabd25bed4f56255549090056c1131fad0277:    done           |++++++++++++++++++++++++++++++++++++++|
elapsed: 25.0s                                                                    total:  374.8  (15.0 MiB/s)
unpacking sha256:8b4ab2db6fd93063b50233a17fc0084015a3fcc774d7b17528bb4baf97aa7949...
done
PS H:\git\go\src\github.com\containerd\containerd> ctr.exe run --rm docker.io/microsoft/nanoserver:latest test
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\>exit
exit
PS H:\git\go\src\github.com\containerd\containerd>

Work left to be done is as follows:

  • Implement snapshotter to manage Windows sandbox layers
  • Implement Apply in the differ to enable pulling of images
  • Implement mount.All/mount.UnmountAll on Windows. mount.Mount is left unimplemented, as the concept of mounting an individual layer does not make sense in the context of Windows. Also target is ignored as it is not specifiable on Windows
  • Remove runtime image management and remove the assumptions made using Docker layers (including removing the db from the Windows runtime)
  • Enable tests removing the shims used on Windows
  • Get Diff to work, currently untested
  • Validate and pass tests without using Docker created layers
  • Allow configuration of sandbox size during snapshot create (or update). May be a followup
  • Merge layer extraction and diffing with archiver. The current interface does not have enough context to use on Windows. This needs to be reworked. Some code will likely move to hcsshim as part of this
  • Move layer extraction to a re-exec model to prevent elevating privilege in the main containerd.exe process. This will take some designing with the above archive integration.
  • Figure out how to make the snapshotter work for non-container purposes as well. The current implementation creates a Sandbox, which I think is needed, but that means that if a container is not run (or a diff applied) into the current layer, a new layer cannot be created. This breaks the idea that the snapshotter can be used for non-container operations.
  • Implement snapshot disk usage on Windows. Currently hard-coded to 0, as the existing disk usage methods attempt to read the raw layers, which is not permitted on Windows

cc @mlaventure @dmcgowan @stevvooe @crosbymichael

Signed-off-by: Darren Stahl [email protected]

@darstahl darstahl force-pushed the WindowsSnapshotter branch from 38400c4 to 9b3b782 Compare October 6, 2017 23:46
Copy link
Member

@AkihiroSuda AkihiroSuda Oct 7, 2017

Choose a reason for hiding this comment

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

if s := strings.ToLower(fsType); s != "ntfs" {
	return nil, errors.Wrapf(errdefs.ErrInvalidArgument, "%s is on an non-NTFS volume (%s) - only NTFS volumes are  supported", root, s)
}

Copy link
Member

Choose a reason for hiding this comment

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

Question: why single-mount is unimplementable?
If unimplementable, please add a comment to the source code?

Copy link
Contributor Author

@darstahl darstahl Oct 9, 2017

Choose a reason for hiding this comment

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

I'll add a comment. This is due to the filesystem filter on Windows. When accessing a file in an underlying layer, there needs to be a target in the current layer, so a hardlink is created, pointing to the lower layer file (essentially). This means that without the lower layers, the current layer would be full of dead links. As a result, mounting a single layer would be all but useless, so the only API exposed to mount layers on Windows requires all layers.

Copy link
Member

Choose a reason for hiding this comment

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

Is this constant can be defined in hccshim package?

Copy link
Contributor

Choose a reason for hiding this comment

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

If not, can we have it exported to use outside of this package (I've left a comment a bit above asking to add a constant)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this will be a constant in hcsshim package and not hard coded.

Copy link
Contributor

@mlaventure mlaventure left a comment

Choose a reason for hiding this comment

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

Looks like a promising start! 🎉

Copy link
Contributor

Choose a reason for hiding this comment

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

you can just remove that function, it does nothing on other platforms either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: merge in the var () block below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. FYI I plan to move some of the responsibility here to hcsshim, so the differ will still be undergoing some largeish changes

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: s/NewWindowsDiff/It/

also, is that true even unix FS? (e.g. zfs)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy paste error. This is expected to only work on NTFS (and is not a generic implementation, but a Windows container specific one)

Copy link
Contributor

Choose a reason for hiding this comment

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

This part (all the way down to digester :=...) should probably be extracted into an utility function.

/cc @dmcgowan @stevvooe to see if it makes sense

Actually once the archiver can get access to the parent ctx in a generic way, I guess this would just be a copy of walkingDiff.Apply()

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: just a preference, I think a switch construct here would make it easier to read (feel free to ignore if you like it that way 😇)

Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to call t.Rollback() here? maybe put it in a defer.

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 think a Rollback is needed. Other snapshotters have the same function without a rollback (I see a few missing Rollbacks in Naive and Overlay actually). I think we might need to do a pass on all snapshotters.

Copy link
Contributor Author

@darstahl darstahl Oct 10, 2017

Choose a reason for hiding this comment

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

I'm not sure I like the defer, as some functions have a return t.Commit(), which looks fine, and could easily be introduced again if changed to err = t.Commit(); return err but would not trigger the defer on failure. I'm not sure what the pattern should be. Maybe a defer with an explicit variable such as doNotRollback which must be set on a Commit succeeding?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that if the function returned are named, you should be able to rely on this and only rollback if err != nil.

Copy link
Contributor

Choose a reason for hiding this comment

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

remove?

Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be done later? Otherwise we're not going to rollback the transaction here.

Copy link
Contributor

Choose a reason for hiding this comment

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

todo missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ID is only needed to get the disk usage. Removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

return "", errors....

Copy link
Member

Choose a reason for hiding this comment

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

Why is there another fork of the tar package?

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'll get back to you on this. There was something that needed to be forked due to layer implementation on Windows IIRC, but this was done a long time ago

Copy link
Member

Choose a reason for hiding this comment

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

Could you leave the type definition near the New function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do

Copy link
Member

Choose a reason for hiding this comment

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

Do we want to upstream this to continuity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds good to me.

@stevvooe
Copy link
Member

@darrenstahlmsft This is a really solid start! The snapshotter model seems to be holding up, although we may need to rethink how the related mounts work. Would it be possible to get the whole structure into a single mount call?

Copy link
Member

Choose a reason for hiding this comment

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

Afaics this function doesn't actually mount anything and the actual mount is in https://github.com/containerd/containerd/pull/1613/files#diff-c3cba80ac2b534161f3d1259da272c21R80 and doesn't have really much to do with snapshots as all the inputs come from a spec. This makes the API very inconsistent for anything that calls this function directly instead of just creating a container what internally calls here and atm there isn't a public method for mounting a snapshot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This does do the mount to host (PrepareLayer mounts the layers), but on Windows, you cannot specify a target location. Instead, the layers are exposed as a VHD mounted on the host. The linked code just retrieves the already mounted path from HCS.

I agree that this function does not do what it says on the box here on Windows. We'll need to work out a way to expose what this really does via a different function, or otherwise make it do what it says. Having target as a parameter to the mount does not really make sense on Windows layer mounting.

@darstahl darstahl force-pushed the WindowsSnapshotter branch 2 times, most recently from 4633a57 to 30b412e Compare October 11, 2017 22:49
@darstahl
Copy link
Contributor Author

Running tests is timing out on Windows waiting for start. I'm not sure why yet.

@darstahl
Copy link
Contributor Author

darstahl commented Oct 11, 2017

Pushed an update to address most of the feeback, and rebased

Next step: Moving archive logic around into more permanent locations

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.

6 participants