10000 stage1/init/common: GenerateMounts refactoring by ybubnov · Pull Request #3589 · rkt/rkt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Feb 24, 2020. It is now read-only.

stage1/init/common: GenerateMounts refactoring #3589

Closed
wants to merge 1 commit into from
Closed

stage1/init/common: GenerateMounts refactoring #3589

wants to merge 1 commit into from

Conversation

ybubnov
Copy link
Contributor
@ybubnov ybubnov commented Feb 11, 2017

This patch provides a refactoring of the GenerateMounts function from
the "stage1/init/common" package in order to reduce the amount of the
loops over the mount points.

The implementation replaces the old function "GenerateMounts" and ships
a new type called "RuntimeMounts" that provides "Mounts" to reproduce
previous behavior and a new function "MountsFunc" that calls a
user-defined function for each mount point.

closes #2380

@ghost
Copy link
ghost commented Feb 11, 2017

Can one of the admins verify this patch?

@lucab
Copy link
Member
lucab commented Feb 12, 2017

ok to test

@lucab
Copy link
Member
lucab commented Feb 12, 2017

note to self: this embeds a copy of #3590, see tracking in there.

@ybubnov
Copy link
Contributor Author
ybubnov commented Feb 17, 2017

@alban, @lucab, apologies for being too noisy. I just wanted to ask if these changes are useful, as I didn't get any feedback.

@lucab
Copy link
Member
lucab commented Feb 17, 2017

Sorry for the delay, we have been traveling a bit recently and still going through backlog. I'll try to have a review pass on this soon, in the meanwhile I think the test change (in rkt_non_root_test.go) is superfluous now.

@ybubnov
Copy link
Contributor Author
ybubnov commented Feb 17, 2017

@lucab, thank you, I will rebase a commit with the latest changes in the master branch.

@ybubnov
Copy link
Contributor Author
ybubnov commented Feb 22, 2017

Not sure if the failures in the debian-testing caused by introduces changes, any help appreciated.


// Map of hostpath -> Mount
mnts := make(map[string]schema.Mount)
// mountsMap is a mapping of mount point path to mount point details.
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor doc issue: this is a mapping from mount point name, right?

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 name in this context means a file-system path, like /mnt/dir1, this is why I decided to make it clear and call it a "path". If the "mount point name" is preferable I will change it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see. the fact that it's a types.ACName is a bit confusing, as UNIX paths can have more characters than an ACName.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@squeed, sorry, it was my incorrect understanding, I looked closely at the manifest specification, and this is really a name of the mount point, not a path:

"mountPoints": [
  {
    "name": "work",
    "path": "/var/lib/work",
    "readOnly": false
  }
]

Source: https://github.com/appc/spec/blob/master/spec/aci.md I will update the comments accordingly.

@lucab
Copy link
Member
lucab commented Mar 22, 2017

I think this PR is mostly fine from my point of view, but I'll wait for @squeed to come back for the final review.


// processed defines a set of processed mount points, so we don't
// have to walk though them multiple times.
processed map[string]struct{}
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to indicate that RuntimeMounts is essentially only iterable once.

That makes me a bit uncomfortable - this sort of subtle side-effecting behaviour - I could easily see another developer calling MountsFunc() more than once.

Either RuntimeMounts should error / panic if called twice, or should be non-side-effecting.

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 idea was to decouple the implementation into multiple small functions, but it resulted in a need to share the state between them. Thereby I moved this state into a structure, but now it really makes more sense to define a separate type to bypass that state, in order to get rid of undesirable side-effect.

@squeed
Copy link
Contributor
squeed commented Mar 27, 2017

Can you add some documentation to the mounted and nonmounted functions - their usage isn't quite clear.

It does make me uncomfortable to have so hidden state - the "processed" array is a bit "spooky". Would you mind documenting its use as a shortcut?

@ybubnov
Copy link
Contributor Author
ybubnov commented Mar 27, 2017

Sure, I will update the documentation with more details.

@ybubnov
Copy link
Contributor Author
ybubnov commented Apr 4, 2017

I've moved the state to a separate type rtmState, which is created for each call of both Mounts and MountsFunc, such that it does not lead to any side-effects.

Additionally I've renamed functions mounted and nonmounted to traverseMounts and traverseMountPoints respectively (I hope, such names better describe their purposes). Have updated the documentation with more details.

@ghost
Copy link
ghost commented Apr 7, 2017

Can one of the admins verify this patch?

@ybubnov
Copy link
Contributor Author
ybubnov commented May 1, 2017

For some reason semaphoreci does not pick up a job, I will try to re-open a pull-request to see if it helps.

@ybubnov ybubnov closed this May 1, 2017
@ybubnov ybubnov reopened this May 1, 2017
@ghost
Copy link
ghost commented May 1, 2017

Can one of the admins verify this patch?

@lucab
Copy link
Member
lucab commented May 9, 2017

Rebasing on top of current master (ie. after #3670) would probably help on the testing side.

@ybubnov
Copy link
Contributor Author
ybubnov commented May 9, 2017

@lucab, thank you! I'll give it a try.

Copy link
Member
@euank euank left a comment

Choose a reason for hiding this comment

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

Other than my logline nit, this looked good to me.

UID: &defaultUID,
GID: &defaultGID,
}
log.Printf("warning: no volume specified for mount point "+
Copy link
Member

Choose a reason for hiding this comment

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

I prefer not breaking long loglines to make sure they remain greppable.

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've squashed comment into a single line.

This patch provides a refactoring of the GenerateMounts function from
the "stage1/init/common" package in order to reduce the amount of the
loops over the mount points.

The implementation replaces the old function "GenerateMounts" and ships
a new type called "RuntimeMounts" that provides "Mounts" to reproduce
previous behavior and a new function "MountsFunc" that calls a
user-defined function for each mount point.
@lucab
Copy link
Member
lucab commented Jun 7, 2017

It seems fine overall. @squeed can you please have a final pass on this?

@lucab lucab added this to the 1.27.0 milestone Jun 7, 2017
break
}
}
mpoint, _ := s.mountPointOf(m.Volume)
Copy link
Contributor
@squeed squeed Jun 8, 2017

Choose a reason for hiding this comment

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

What happens if mpoint is nil?

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 function returns instance of types.MountPoint, which is a structure and default value for it is an empty structure. Therefore, when mount point was not found, it returns types.MountPoint{}, where ReadOnly attribute is set to false - a default value for boolean type.

The answer is mpoint is never going to be equal to nil.

@ybubnov
Copy link
Contributor Author
ybubnov commented Jun 16, 2017

Hi, do I need to perform any additional changes or to explain unclear implementation? The review got stuck for a week, apologies for being too noisy.

@lucab lucab modified the milestones: 1.28.0, 1.27.0 Jun 19, 2017
@lucab lucab modified the milestones: 1.29.0, 1.28.0 Jul 18, 2017
@lucab lucab modified the milestones: 1.29.0, 1.30.0 Sep 21, 2017
@iaguis iaguis modified the milestones: 1.30.0, v1.31.0 Apr 11, 2018
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.

stage1/kvm: Refactor generateMounts
5 participants
0