Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func doMount(source string, target string, fstype string, options []string) (string, error) {
- // Build mount command as follows:
- // mount [-t $fstype] [-o $options] [--source $source] --target $target
- mountArgs := []string{}
- if len(fstype) > 0 {
- mountArgs = append(mountArgs, "-t", fstype)
- }
- if options != nil && len(options) > 0 {
- mountArgs = append(mountArgs, "-o", strings.Join(options, ","))
- }
- if len(source) > 0 {
- mountArgs = append(mountArgs, "--source", source)
- }
- mountArgs = append(mountArgs, "--target", target)
- command := exec.Command("mount", mountArgs...)
- return command.CombinedOutput()
- }
- func (mounter *Mounter) Mount(source string, target string, fstype string, options []string) error {
- remountOpts := []string{"remount"}
- if options != nil {
- for _, option := range options {
- switch option {
- case "bind":
- remountOpts = append(remountOpts, options)
- options = "bind"
- break
- case "remount":
- err := fmt.Errorf("invalid mount option 'remount'\n")
- glog.Errorf("Mount failed: %v\nMounting arguments: %s %s %s %v\n", err, source, target, fstype)
- return err
- }
- }
- }
- glog.V(5).Infof("Mounting %s %s %s %v", source, target, fstype, options)
- output, err := doMount(source, target, fstype, options)
- if err != nil {
- glog.Errorf("Mount failed: %v\nMounting arguments: %s %s %s %v\nOutput: %s\n",
- err, source, target, fstype, options, string(output))
- return err
- }
- if len(remountOpts) == 1 {
- return nil
- }
- // Bind mounts do not respect mount options, so we have to do those as a remount
- glog.V(5).Infof("Remounting %s as to support VFS args (like ro)", target)
- output, err = doMount(source, target, fstype, remountOpts)
- if err != nil {
- glog.Errorf("Remount failed: %v\nMounting arguments: %s %s %s %v\nOutput: %s\n",
- err, source, target, fstype, options, string(output))
- return err
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement