@@ -56,7 +56,7 @@ const (
5656 defaultNFSSharesRoot = "/xhyve-nfsshares"
5757 rootVolumeName = "root-volume"
5858 defaultDiskNumber = - 1
59- defaultVirtio9p = false
59+ defaultVirtio9pRoot = "/xhyve-virtio9p"
6060 defaultQcow2 = false
6161 defaultRawDisk = false
6262)
@@ -69,19 +69,19 @@ type Driver struct {
6969 CaCertPath string
7070 PrivateKeyPath string
7171
72- CPU int
73- Memory int
74- DiskSize int64
75- DiskNumber int
76- MacAddr string
77- UUID string
78- Qcow2 bool
79- RawDisk bool
80- NFSShares []string
81- NFSSharesRoot string
82- Virtio9p bool
83- Virtio9pFolder string
84- NFSShare bool
72+ CPU int
73+ Memory int
74+ DiskSize int64
75+ DiskNumber int
76+ MacAddr string
77+ UUID string
78+ Qcow2 bool
79+ RawDisk bool
80+ NFSShares []string
81+ NFSSharesRoot string
82+ Virtio9p [] string
83+ Virtio9pRoot string
84+ NFSShare bool
8585
8686 BootCmd string
8787 BootKernel string
@@ -116,9 +116,9 @@ func NewDriver(hostName, storePath string) *Driver {
116116 Memory : defaultMemory ,
117117 PrivateKeyPath : defaultPrivateKeyPath ,
118118 UUID : defaultUUID ,
119+ Virtio9pRoot : defaultVirtio9pRoot ,
119120 NFSSharesRoot : defaultNFSSharesRoot ,
120121 DiskNumber : defaultDiskNumber ,
121- Virtio9p : defaultVirtio9p ,
122122 Qcow2 : defaultQcow2 ,
123123 RawDisk : defaultRawDisk ,
124124 }
@@ -186,10 +186,16 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
186186 Usage : "The UUID for the machine" ,
187187 Value : defaultUUID ,
188188 },
189- mcnflag.BoolFlag {
189+ mcnflag.StringSliceFlag {
190190 EnvVar : "XHYVE_VIRTIO_9P" ,
191191 Name : "xhyve-virtio-9p" ,
192- Usage : "Setup virtio-9p folder share" ,
192+ Usage : "Setup virtio-9p folder share(s)" ,
193+ },
194+ mcnflag.StringFlag {
195+ EnvVar : "XHYVE_VIRTIO_9P_ROOT" ,
196+ Name : "xhyve-virtio-9p-root" ,
197+ Usage : "root directory where the virtio shared folder will be mounted inside the machine" ,
198+ Value : defaultVirtio9pRoot ,
193199 },
194200 mcnflag.StringSliceFlag {
195201 EnvVar : "XHYVE_EXPERIMENTAL_NFS_SHARE" ,
@@ -256,8 +262,8 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
256262 d .SwarmHost = flags .String ("swarm-host" )
257263 d .SwarmMaster = flags .Bool ("swarm-master" )
258264 d .UUID = flags .String ("xhyve-uuid" )
259- d .Virtio9p = flags .Bool ("xhyve-virtio-9p" )
260- d .Virtio9pFolder = "/Users"
265+ d .Virtio9p = flags .StringSlice ("xhyve-virtio-9p" )
266+ d .Virtio9pRoot = flags . String ( "xhyve-virtio-9p-root" )
261267 d .NFSShares = flags .StringSlice ("xhyve-experimental-nfs-share" )
262268 d .NFSSharesRoot = flags .String ("xhyve-experimental-nfs-share-root" )
263269
@@ -497,8 +503,14 @@ func (d *Driver) Start() error {
497503
498504 args := d .xhyveArgs ()
499505 args = append (args , "-F" , fmt .Sprintf ("%s" , pid ))
500- if d .Virtio9p {
501- args = append (args , "-s" , fmt .Sprintf ("5,virtio-9p,host=%s" , d .Virtio9pFolder ))
506+ if len (d .Virtio9p ) > 0 {
507+ const virtio9pPciStartValue = 5
508+ i := virtio9pPciStartValue
509+ for _ , virtioshare := range d .Virtio9p {
510+ // In the following line, i-virtio9pPciStartValue is just so that the string "host-" starts from 0 and not from 5
511+ args = append (args , "-s" , fmt .Sprintf ("%d,virtio-9p,host-%d=%s" , i , i - virtio9pPciStartValue , virtioshare ))
512+ i ++
513+ }
502514 }
503515
504516 log .Debug (args )
@@ -814,7 +826,7 @@ func (d *Driver) generateQcow2Image(size int64) error {
814826}
815827
816828func (d * Driver ) setupMounts () error {
817- if d .Virtio9p {
829+ if len ( d .Virtio9p ) > 0 {
818830 err := d .setupVirt9pShare ()
819831 if err != nil {
820832 log .Errorf ("virtio-9p setup failed: %s" , err .Error ())
@@ -983,9 +995,16 @@ func (d *Driver) setupVirt9pShare() error {
983995 return err
984996 }
985997 bootScriptName := "/var/lib/boot2docker/bootlocal.sh"
986- bootScript := fmt .Sprintf ("#/bin/bash\\ n" +
987- "sudo mkdir -p %s\\ n" +
988- "sudo mount -t 9p -o version=9p2000 -o trans=virtio -o uname=%s -o dfltuid=$(id -u docker) -o dfltgid=50 -o access=any host %s" , d .Virtio9pFolder , user .Username , d .Virtio9pFolder )
998+
999+ bootScript := fmt .Sprintf ("#/bin/bash\\ n" )
1000+ i := 0
1001+ for _ , virtioShare := range d .Virtio9p {
1002+ bootScript = fmt .Sprintf ("%s\\ n" , bootScript )
1003+ fullMountPath := path .Clean (d .Virtio9pRoot + "/" + virtioShare )
1004+ bootScript += fmt .Sprintf ("sudo mkdir -p %s\\ n" , fullMountPath )
1005+ bootScript += fmt .Sprintf ("sudo mount -t 9p -o version=9p2000 -o trans=virtio -o uname=%s -o dfltuid=$(id -u docker) -o dfltgid=50 -o access=any host-%d %s" , user .Username , i , fullMountPath )
1006+ i ++
1007+ }
9891008
9901009 writeScriptCmd := fmt .Sprintf ("echo -e \" %s\" | sudo tee %s && sudo chmod +x %s && %s" ,
9911010 bootScript , bootScriptName , bootScriptName , bootScriptName )
0 commit comments