github.com/stackdocker/rkt@v0.10.1-0.20151109095037-1aa827478248/stage1/init/common/mount.go (about) 1 // Copyright 2015 The rkt Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package common 16 17 import ( 18 "fmt" 19 20 "github.com/coreos/rkt/Godeps/_workspace/src/github.com/appc/spec/schema" 21 "github.com/coreos/rkt/Godeps/_workspace/src/github.com/appc/spec/schema/types" 22 ) 23 24 func isMPReadOnly(mountPoints []types.MountPoint, name types.ACName) bool { 25 for _, mp := range mountPoints { 26 if mp.Name == name { 27 return mp.ReadOnly 28 } 29 } 30 31 return false 32 } 33 34 // IsMountReadOnly returns if a mount should be readOnly. 35 // If the readOnly flag in the pod manifest is not nil, it overrides the 36 // readOnly flag in the image manifest. 37 func IsMountReadOnly(vol types.Volume, mountPoints []types.MountPoint) bool { 38 if vol.ReadOnly != nil { 39 return *vol.ReadOnly 40 } 41 42 return isMPReadOnly(mountPoints, vol.Name) 43 } 44 45 func GenerateMounts(ra *schema.RuntimeApp, volumes map[types.ACName]types.Volume) ([]schema.Mount, error) { 46 appName := ra.Name 47 id := ra.Image.ID 48 app := ra.App 49 50 mnts := make(map[string]schema.Mount) 51 for _, m := range ra.Mounts { 52 mnts[m.Path] = m 53 } 54 55 for _, mp := range app.MountPoints { 56 // there's already an injected mount for this target path, skip 57 if _, ok := mnts[mp.Path]; ok { 58 continue 59 } 60 vol, ok := volumes[mp.Name] 61 if !ok { 62 catCmd := fmt.Sprintf("sudo rkt image cat-manifest --pretty-print %v", id) 63 volumeCmd := "" 64 for _, mp := range app.MountPoints { 65 volumeCmd += fmt.Sprintf("--volume %s,kind=host,source=/some/path ", mp.Name) 66 } 67 68 return nil, fmt.Errorf("no volume for mountpoint %q:%q in app %q.\n"+ 69 "You can inspect the volumes with:\n\t%v\n"+ 70 "App %q requires the following volumes:\n\t%v", 71 mp.Name, mp.Path, appName, catCmd, appName, volumeCmd) 72 } 73 ra.Mounts = append(ra.Mounts, schema.Mount{Volume: vol.Name, Path: mp.Path}) 74 } 75 76 return ra.Mounts, nil 77 }