-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
WIP Support nfs local volume mounts #2415
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
package libpod | ||
|
||
import ( | ||
"net" | ||
"strings" | ||
|
||
"github.com/containers/storage/pkg/mount" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// Volume is the type used to create named volumes | ||
// TODO: all volumes should be created using this and the Volume API | ||
type Volume struct { | ||
|
@@ -70,3 +78,57 @@ func (v *Volume) Scope() string { | |
func (v *Volume) IsCtrSpecific() bool { | ||
return v.config.IsCtrSpecific | ||
} | ||
|
||
// Mount the volume | ||
func (v *Volume) Mount() error { | ||
if v.MountPoint() == "" { | ||
return errors.Errorf("missing device in volume options") | ||
} | ||
mounted, err := mount.Mounted(v.MountPoint()) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to determine if %v is mounted", v.Name()) | ||
} | ||
if mounted { | ||
return nil | ||
} | ||
options := v.Options() | ||
if len(options) == 0 { | ||
return errors.Errorf("volume %v is not mountable, no options available", v.Name()) | ||
} | ||
mountOpts := options["o"] | ||
device := options["device"] | ||
if options["type"] == "nfs" { | ||
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. This should not be an option. Volume has a "type" field, and that is what we should be using. 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. Correction, I meant Or we should add a type field. Let's not stuff critical information into maps. Make this top-level. 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. We can add this under the covers, but if we want to follow the Docker CLI, we have to allow users to specify nfs in the manner. 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. Sure, matching their CLI is fine, but let's not let the CLI determine how we set up internal data structures |
||
if addrValue := getAddress(mountOpts); addrValue != "" && net.ParseIP(addrValue).To4() == nil { | ||
ipAddr, err := net.ResolveIPAddr("ip", addrValue) | ||
if err != nil { | ||
return errors.Wrapf(err, "error resolving passed in nfs address") | ||
} | ||
mountOpts = strings.Replace(mountOpts, "addr="+addrValue, "addr="+ipAddr.String(), 1) | ||
} | ||
if device[0] != ':' { | ||
device = ":" + device | ||
} | ||
} | ||
err = mount.Mount(device, v.MountPoint(), options["type"], mountOpts) | ||
return errors.Wrap(err, "failed to mount local volume") | ||
} | ||
|
||
// Unmount the volume from the system | ||
func (v *Volume) Unmount() error { | ||
if v.MountPoint() == "" { | ||
return errors.Errorf("missing device in volume options") | ||
} | ||
return mount.Unmount(v.MountPoint()) | ||
} | ||
|
||
// getAddress finds out address/hostname from options | ||
func getAddress(opts string) string { | ||
optsList := strings.Split(opts, ",") | ||
for i := 0; i < len(optsList); i++ { | ||
if strings.HasPrefix(optsList[i], "addr=") { | ||
addr := strings.SplitN(optsList[i], "=", 2)[1] | ||
return addr | ||
} | ||
} | ||
return "" | ||
} | ||
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. Should this function live in common instead? 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. It is only used in volume now. |
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.
I've been trying to keep these to three examples. Could we kill line 31 and add '--label foo=bar' to line 29?
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.
Fixed