-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Ensure dev/, proc/, and alloc/ are mounted every time a task is run #2394
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ba87cb8
Fix typos
schmichael 94ce9d2
unlinkDir should not error if already unlinked
schmichael ad4559d
Safely ensure {dev,proc,alloc} are mounted
schmichael 866600e
Cleanup comments/names
schmichael 6535aa8
Fix API breaks in tests
schmichael 16fb45e
Fix tests broken by API change
schmichael 833b4bd
Merge branch 'master' into b-remount
dadgar 9497415
Mkdir -> MkdirAll to avoid error when folder already exists
dadgar fbfeecb
Fix TestAllocRunner_SaveRestoreState
dadgar 50fafa2
Fix lint errors
dadgar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,8 +57,10 @@ func newTaskDir(logger *log.Logger, allocDir, taskName string) *TaskDir { | |
} | ||
} | ||
|
||
// Build default directories and permissions in a task directory. | ||
func (t *TaskDir) Build(chroot map[string]string, fsi cstructs.FSIsolation) error { | ||
// Build default directories and permissions in a task directory. If the built | ||
// boolean is true Build assumes the task dir has already been built and skips | ||
// expensive operations like chroot creation. | ||
func (t *TaskDir) Build(built bool, chroot map[string]string, fsi cstructs.FSIsolation) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like |
||
if err := os.MkdirAll(t.Dir, 0777); err != nil { | ||
return err | ||
} | ||
|
@@ -69,7 +71,7 @@ func (t *TaskDir) Build(chroot map[string]string, fsi cstructs.FSIsolation) erro | |
} | ||
|
||
// Create a local directory that each task can use. | ||
if err := os.MkdirAll(t.LocalDir, 0777); err != nil { | ||
if err := os.Mkdir(t.LocalDir, 0777); err != nil { | ||
return err | ||
} | ||
|
||
|
@@ -94,8 +96,12 @@ func (t *TaskDir) Build(chroot map[string]string, fsi cstructs.FSIsolation) erro | |
// If there's no isolation the task will use the host path to the | ||
// shared alloc dir. | ||
if fsi == cstructs.FSIsolationChroot { | ||
if err := linkDir(t.SharedAllocDir, t.SharedTaskDir); err != nil { | ||
return fmt.Errorf("Failed to mount shared directory for task: %v", err) | ||
// If the path doesn't exist OR it exists and is empty, link it | ||
empty, _ := pathEmpty(t.SharedTaskDir) | ||
if !pathExists(t.SharedTaskDir) || empty { | ||
if err := linkDir(t.SharedAllocDir, t.SharedTaskDir); err != nil { | ||
return fmt.Errorf("Failed to mount shared directory for task: %v", err) | ||
} | ||
} | ||
} | ||
|
||
|
@@ -110,7 +116,7 @@ func (t *TaskDir) Build(chroot map[string]string, fsi cstructs.FSIsolation) erro | |
|
||
// Build chroot if chroot filesystem isolation is going to be used | ||
if fsi == cstructs.FSIsolationChroot { | ||
if err := t.buildChroot(chroot); err != nil { | ||
if err := t.buildChroot(built, chroot); err != nil { | ||
return err | ||
} | ||
} | ||
|
@@ -122,10 +128,15 @@ func (t *TaskDir) Build(chroot map[string]string, fsi cstructs.FSIsolation) erro | |
// to their intended, relative location within the task directory. This | ||
// attempts hardlink and then defaults to copying. If the path exists on the | ||
// host and can't be embedded an error is returned. | ||
func (t *TaskDir) buildChroot(entries map[string]string) error { | ||
// Link/copy chroot entries | ||
if err := t.embedDirs(entries); err != nil { | ||
return err | ||
// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments here |
||
// If built is true the chroot is assumed to have been built already and only | ||
// ephemeral operations (eg mounting /dev) are done. | ||
func (t *TaskDir) buildChroot(built bool, entries map[string]string) error { | ||
if !built { | ||
// Link/copy chroot entries | ||
if err := t.embedDirs(entries); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// Mount special dirs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit pick but can you just add that to the existing comment. No need for extra line