Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Copy files from host to guest #1041

Merged
merged 5 commits into from
Dec 19, 2018

Conversation

devimc
Copy link

@devimc devimc commented Dec 17, 2018

No description provided.

@devimc devimc force-pushed the topic/no9pCopyFiles branch from ea1982f to 96c3e34 Compare December 17, 2018 15:15
@devimc devimc mentioned this pull request Dec 17, 2018
virtcontainers/capabilities.go Outdated Show resolved Hide resolved
virtcontainers/capabilities.go Outdated Show resolved Hide resolved
virtcontainers/capabilities.go Outdated Show resolved Hide resolved
virtcontainers/kata_agent.go Outdated Show resolved Hide resolved
if !caps.is9pSupported() {
return nil
}

// Adding the shared volume.
// This volume contains all bind mounted container bundles.
Copy link

Choose a reason for hiding this comment

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

Please extend the comment here, saying that this code path should only be executed when 9p is supported.

@@ -1003,6 +1054,14 @@ func (k *kataAgent) createContainer(sandbox *Sandbox, c *Container) (p *Process,

k.handleShm(grpcSpec, sandbox)

caps := sandbox.hypervisor.capabilities()
if !caps.is9pSupported() {
Copy link

Choose a reason for hiding this comment

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

I would do this check and the file copy from c.mountSharedDirMounts() instead. This means we centralize everything in the container.go implementation. But that also means that you need to define copyFile() as part of the agent interface, which makes sense to me as you're asking to copy a file to the guest through the agent support.

@devimc devimc force-pushed the topic/no9pCopyFiles branch from 96c3e34 to bd2de8c Compare December 17, 2018 18:05
@egernst
Copy link
Member

egernst commented Dec 17, 2018

I am having mixed-thoughts regarding the capability flag for the hypervisor. I would like this to be .toml based in addition, perhaps. WDYT? @mcastelino @sboeuf @devimc @sameo

@sboeuf
Copy link

sboeuf commented Dec 17, 2018

@egernst

I am having mixed-thoughts regarding the capability flag for the hypervisor. I would like this to be .toml based in addition, perhaps. WDYT? @mcastelino @sboeuf @devimc @sameo

Mid-term, definitely. If we think about real use cases, then we might need to cover the case where we want to use QEMU without 9pfs (even if 9p is supported), which means the internal decision should be based on hypervisor capabilities AND input from user (configuration.toml basically).

Long term, maybe we simply want to get rid of 9p, and we could call this capability filesystemSharingSupport, which would be covered by virtio-fs in case of QEMU, and which would be false in case of FC for instance.

Copy link
Contributor

@mcastelino mcastelino left a comment

Choose a reason for hiding this comment

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

It would be helpful at the top level to explain what we lose when we lose 9p.
Also what features we lose. The code that handles storage seem to indicate we lost volume support, which means configmaps for example. Is this true?

caps.flags |= hotplugUnsupported
}

func (caps *capabilities) is9pSupported() bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

@egernst instead of calling this is9pSupported, should this not be something more generic. 9p is one way to share files between host and the VM?

Copy link

Choose a reason for hiding this comment

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

Yeah we could call it filesystemSharingSupport. @egernst @devimc ?

Copy link
Author

Choose a reason for hiding this comment

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

+1 , @egernst ?

@@ -9,6 +9,8 @@ const (
blockDeviceSupport = 1 << iota
blockDeviceHotplugSupport
multiQueueSupport
hotplugUnsupported
plan9FSUnsupported
Copy link
Contributor

Choose a reason for hiding this comment

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

@egernst instead of calling this is9pSupported, should this not be something more generic. 9p is one way to share files between host and the VM?

caps := sandbox.hypervisor.capabilities()
if !caps.is9pSupported() {
// 9p is not supported, files must be copied
if err := k.copyFiles(c.mounts, newMounts); 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.

@egernst does this mean even files coming in from tmpfs, secrets all of them get copied? What happens to volumes.

// This is where at least some of the host config files
// (resolv.conf, etc...) and potentially all container
// rootfs will reside.
sharedVolume := &grpc.Storage{
Copy link
Contributor

Choose a reason for hiding this comment

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

@egernst what is the else case here. Do we lose support for volumes?

@mcastelino
Copy link
Contributor

Long term, maybe we simply want to get rid of 9p, and we could call this capability filesystemSharingSupport, which would be covered by virtio-fs in case of QEMU, and which would be false in case of FC for instance.

Yes, this will decouple it from the specific implementation.

@devimc devimc force-pushed the topic/no9pCopyFiles branch from bd2de8c to aab7c26 Compare December 17, 2018 20:07
@devimc
Copy link
Author

devimc commented Dec 17, 2018

Depends-on kata-containers/agent#433

@sboeuf
Copy link

sboeuf commented Dec 17, 2018

/test

@sboeuf
Copy link

sboeuf commented Dec 18, 2018

@devimc kata-containers/agent#433 got merged! Could you please update this PR :)

@devimc devimc force-pushed the topic/no9pCopyFiles branch from cc72c85 to efe4298 Compare December 18, 2018 20:26
// bind mount it in the shared directory.
caps := c.sandbox.hypervisor.capabilities()
if !caps.isFsSharingSupported() {
// filesystem sharing is not supported, files must be copied
Copy link
Contributor

Choose a reason for hiding this comment

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

How about converting this comment into a log call?


func (h *hyper) copyFile(src, dst string) error {
// hyperstart-agent does not support copyFile
return nil
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...

Suggested change
return nil
return errors.New("hyperstart-agent does not support copyFile")

Copy link
Author

Choose a reason for hiding this comment

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


err := unix.Stat(src, &st)
if err != nil {
return fmt.Errorf("Could get file %s information", src)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("Could get file %s information", src)
return fmt.Errorf("Could not get file %s information: %v", src, err)

Copy link
Author

Choose a reason for hiding this comment

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

good catch! thanks


b, err := ioutil.ReadFile(src)
if err != nil {
return fmt.Errorf("Could not read file %s", src)
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, it would help to include the error so the user can see why the read failed.

Copy link
Author

Choose a reason for hiding this comment

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

yes, thanks 😄

@devimc devimc force-pushed the topic/no9pCopyFiles branch 2 times, most recently from 996970e to d038fd8 Compare December 19, 2018 15:08
Brings support to copy file from host to guest

shortlog:
169d755 protocols/grpc: implement function to copy files
ff87c26 virtio-mmio: Add support for virtio-mmio blk devices
b9c5d5b libcontainer: use /run as root containers path
092f1a0 block: add support of block storage driver "nvdimm"

Signed-off-by: Julio Montes <[email protected]>
@devimc devimc force-pushed the topic/no9pCopyFiles branch 2 times, most recently from c39b991 to 483aab9 Compare December 19, 2018 15:20
@devimc
Copy link
Author

devimc commented Dec 19, 2018

/test

Copy link
Member

@egernst egernst left a comment

Choose a reason for hiding this comment

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

@devimc can you update commit msg/header for

vc: capabilities: add capability flags for 9p

I like the new name - let's update the msg for this.

Eric Ernst and others added 2 commits December 19, 2018 09:54
Not all hypervisors support filesystem sharing. Add capability flags to track
this. Since most hypervisor implementations in Kata *do* support this, the set
semantices are reversed (ie, set the flag if you do not support the feature).

Fixes: kata-containers#1022

Signed-off-by: Eric Ernst <[email protected]>
Signed-off-by: Julio Montes <[email protected]>
Files are copied over gRPC and there is no limit in size of the files that
can be copied. Small files are copied using just one gRPC call while big files
are copied by parts.

Signed-off-by: Julio Montes <[email protected]>
@devimc devimc force-pushed the topic/no9pCopyFiles branch from 483aab9 to 87509c5 Compare December 19, 2018 15:55
@devimc
Copy link
Author

devimc commented Dec 19, 2018

@egernst changes applied, thanks

@devimc
Copy link
Author

devimc commented Dec 19, 2018

/test

@devimc
Copy link
Author

devimc commented Dec 19, 2018

@jodh-intel changes applied, thanks

Copy link
Member

@egernst egernst left a comment

Choose a reason for hiding this comment

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

"Neither create shared directory nor add 9p device if hypervisor doesn't support
file sharing since files will be copied over gRPC using agent's copyFile
function."

Suggested reword:
"If the hypervisor does not support filesystem sharing (for example, 9p), files will be copied over gRPC using the copyFile request function"

Julio Montes added 2 commits December 19, 2018 09:58
If the hypervisor does not support filesystem sharing (for example, 9p),
files will be copied over gRPC using the copyFile request function.

Signed-off-by: Julio Montes <[email protected]>
Copy files to contaier's rootfs if hypervisor doesn't supports filesystem
sharing, otherwise bind mount them in the shared directory.

see kata-containers#1031

Signed-off-by: Julio Montes <[email protected]>
@devimc devimc force-pushed the topic/no9pCopyFiles branch from 87509c5 to 378d815 Compare December 19, 2018 15:58
@devimc
Copy link
Author

devimc commented Dec 19, 2018

@egernst ok, sounds good

Copy link

@sameo sameo left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -63,6 +65,7 @@ var (
shmDir = "shm"
kataEphemeralDevType = "ephemeral"
ephemeralPath = filepath.Join(kataGuestSandboxDir, kataEphemeralDevType)
grpcMaxDataSize = int64(1024 * 1024)
Copy link

Choose a reason for hiding this comment

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

Where is that value coming from?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good question! @devimc - is this just a restriction added to avoid a DoS or something?

Copy link

Choose a reason for hiding this comment

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

In other words: Is this related to any gRPC limitations?

Copy link
Author

Choose a reason for hiding this comment

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

yes, it's to avoid DoS attacks, I'd prefer to use small chunks, but I can change it if you want

Copy link
Author

Choose a reason for hiding this comment

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

according with this https://godoc.org/google.golang.org/grpc#MaxRecvMsgSize the default size 4MB , I can use it but if the value changes to 1000MB probably we'll face DoS attacks

Copy link
Contributor

@jodh-intel jodh-intel left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -63,6 +65,7 @@ var (
shmDir = "shm"
kataEphemeralDevType = "ephemeral"
ephemeralPath = filepath.Join(kataGuestSandboxDir, kataEphemeralDevType)
grpcMaxDataSize = int64(1024 * 1024)
Copy link
Contributor

Choose a reason for hiding this comment

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

Good question! @devimc - is this just a restriction added to avoid a DoS or something?

@devimc
Copy link
Author

devimc commented Dec 19, 2018

/test

@egernst egernst merged commit b51c57e into kata-containers:master Dec 19, 2018
@devimc devimc deleted the topic/no9pCopyFiles branch April 8, 2019 14:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants