Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

mount: ensure empty volume paths exist for copy-up #3468

Merged
merged 2 commits into from
Dec 12, 2016

Conversation

euank
Copy link
Member

@euank euank commented Dec 9, 2016

Before this change, the copy-up operation could fail with:
stage1: could not prepare mountpoint: mkdir sharedVolumes/foo: no such file or directory

This would occur because CopyTree does not implicitly create the
target directory, so we must create it prior to calling.

cc @squeed

TODO:

  • A functional test for this

@euank euank force-pushed the rkt-mkdir-implicit-mount branch from 9f027c4 to 2f61bdf Compare December 9, 2016 22:30
@jonboulle
Copy link
Contributor

lgtm

@euank
Copy link
Member Author

euank commented Dec 9, 2016

Alternative fixes include:

  1. Making CopyTree make the target directory itself prior to doing other copy operations. This makes it have a slightly nicer api I think, and I might switch it to that.
  2. Changing the walkFunc to MkdirAll instead of Mkdir... This feels wrong because Walk will progress through directories in depth-order, so that should never be necessary if the original root exists.

@jonboulle
Copy link
Contributor

I think this is the right fix for now and we can change the CopyTree behaviour separately.

@euank
Copy link
Member Author

euank commented Dec 9, 2016

Well, based on the spectacular test failures, I'm wrong about something. I'll add more debug output and figure out with more confidence what was broken.

@jonboulle
Copy link
Contributor

breaks into profuse sweat

Before this change, the `copy-up` operation could fail with:
`stage1: could not prepare mountpoint: mkdir sharedVolumes/foo: no such file or directory`

This would occur because `CopyTree` does not implicitly create the
target directory, so we must create it prior to calling.
@euank euank force-pushed the rkt-mkdir-implicit-mount branch from 2f61bdf to 25284c0 Compare December 10, 2016 00:56
@euank
Copy link
Member Author

euank commented Dec 10, 2016

Actual bug was these lines being missed when copying over to per-app-stuff: https://github.com/coreos/rkt/blob/cdb6a446c8ed064bfe96c845330cd05d3d9df0b6/stage1/init/common/pod.go#L467-L473

It was sharedVolumes that didn't exist, not sharedVolumes/foo (whoops).

@@ -342,6 +350,7 @@ func AppAddMounts(p *stage1commontypes.Pod, ra *schema.RuntimeApp, enterCmd []st
log.FatalE("Unable to setup app mounts", err)
Copy link
Member Author

@euank euank Dec 10, 2016

Choose a reason for hiding this comment

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

TODO in a followup PR; make everything here return err instead of FatalE-ing

@jonboulle
Copy link
Contributor

whoops, good find! lgtm

@@ -300,7 +300,15 @@ func ensureDestinationExists(source, destination string) error {
return nil
}

func AppAddMounts(p *stage1commontypes.Pod, ra *schema.RuntimeApp, enterCmd []string) {
func AppAddMounts(p *stage1commontypes.Pod, ra *schema.RuntimeApp, enterCmd []string) error {
sharedVolPath := common.SharedVolumesPath(p.Root)
Copy link
Member Author

Choose a reason for hiding this comment

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

this is called in two places, honestly this whole thing should probably be in common. maybe as sharedVolPath, err := common.InitSharedVolumePath()

@euank
Copy link
Member Author

euank commented Dec 10, 2016

I did a bit more refactoring. I pushed the duplicated shared volume path creation up to common.

If the tests are happy with this change then it should be fine to merge.

if err := os.MkdirAll(sharedVolPath, SharedVolumePerm); err != nil {
return "", errwrap.Wrap(errors.New("could not create shared volumes directory"), err)
}
if err := os.Chmod(sharedVolPath, SharedVolumePerm); 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.

I guess we Chmod because the directory might already be present and in this case not catched the perm parm in MkdirAll? It may seem obvious, but can we leave a small comment for the rationale?

Copy link
Contributor

@s-urbaniak s-urbaniak left a comment

Choose a reason for hiding this comment

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

I have only one question regarding error handling.

func AppAddMounts(p *stage1commontypes.Pod, ra *schema.RuntimeApp, enterCmd []string) {
func AppAddMounts(p *stage1commontypes.Pod, ra *schema.RuntimeApp, enterCmd []string) error {
sharedVolPath, err := common.CreateSharedVolumesPath(p.Root)

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 we bail out in case err != nil?

@euank euank force-pushed the rkt-mkdir-implicit-mount branch from c15f66a to a64181f Compare December 12, 2016 18:01
@euank
Copy link
Member Author

euank commented Dec 12, 2016

Addressed your comments, @s-urbaniak.

Seems very likely the chmod is overtly-defensive and could be removed since we largely control stage1, but seems outta scope for this change.

Copy link
Contributor

@s-urbaniak s-urbaniak left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@euank euank merged commit 6b3852f into rkt:master Dec 12, 2016
@euank euank deleted the rkt-mkdir-implicit-mount branch December 12, 2016 21:21
@lucab lucab mentioned this pull request Jan 5, 2017
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.

3 participants