mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-22 10:31:35 +00:00
Add virtualization framework virtiofs command line option
Signed-off-by: Frédéric Dalleau <frederic.dalleau@docker.com>
This commit is contained in:
parent
13426fe805
commit
e4b1a5b192
@ -14,23 +14,25 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type virtualizationFramwworkConfig struct {
|
type virtualizationFramwworkConfig struct {
|
||||||
cpus uint
|
cpus uint
|
||||||
mem uint64
|
mem uint64
|
||||||
disks Disks
|
disks Disks
|
||||||
data string
|
data string
|
||||||
dataPath string
|
dataPath string
|
||||||
state string
|
state string
|
||||||
networking string
|
networking string
|
||||||
kernelBoot bool
|
kernelBoot bool
|
||||||
|
virtiofsShares []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func runVirtualizationFrameworkCmd() *cobra.Command {
|
func runVirtualizationFrameworkCmd() *cobra.Command {
|
||||||
var (
|
var (
|
||||||
data string
|
data string
|
||||||
dataPath string
|
dataPath string
|
||||||
state string
|
state string
|
||||||
networking string
|
networking string
|
||||||
kernelBoot bool
|
kernelBoot bool
|
||||||
|
virtiofsShares []string
|
||||||
)
|
)
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
@ -43,14 +45,15 @@ func runVirtualizationFrameworkCmd() *cobra.Command {
|
|||||||
Example: "linuxkit run virtualization [options] prefix",
|
Example: "linuxkit run virtualization [options] prefix",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
cfg := virtualizationFramwworkConfig{
|
cfg := virtualizationFramwworkConfig{
|
||||||
cpus: uint(cpus),
|
cpus: uint(cpus),
|
||||||
mem: uint64(mem) * 1024 * 1024,
|
mem: uint64(mem) * 1024 * 1024,
|
||||||
disks: disks,
|
disks: disks,
|
||||||
data: data,
|
data: data,
|
||||||
dataPath: dataPath,
|
dataPath: dataPath,
|
||||||
state: state,
|
state: state,
|
||||||
networking: networking,
|
networking: networking,
|
||||||
kernelBoot: kernelBoot,
|
kernelBoot: kernelBoot,
|
||||||
|
virtiofsShares: virtiofsShares,
|
||||||
}
|
}
|
||||||
return runVirtualizationFramework(cfg, args[0])
|
return runVirtualizationFramework(cfg, args[0])
|
||||||
},
|
},
|
||||||
@ -63,6 +66,7 @@ func runVirtualizationFrameworkCmd() *cobra.Command {
|
|||||||
cmd.Flags().StringVar(&networking, "networking", virtualizationNetworkingDefault, "Networking mode. Valid options are 'default', 'vmnet' and 'none'. 'vmnet' uses the Apple vmnet framework. 'none' disables networking.`")
|
cmd.Flags().StringVar(&networking, "networking", virtualizationNetworkingDefault, "Networking mode. Valid options are 'default', 'vmnet' and 'none'. 'vmnet' uses the Apple vmnet framework. 'none' disables networking.`")
|
||||||
|
|
||||||
cmd.Flags().BoolVar(&kernelBoot, "kernel", false, "Boot image is kernel+initrd+cmdline 'path'-kernel/-initrd/-cmdline")
|
cmd.Flags().BoolVar(&kernelBoot, "kernel", false, "Boot image is kernel+initrd+cmdline 'path'-kernel/-initrd/-cmdline")
|
||||||
|
cmd.Flags().StringArrayVar(&virtiofsShares, "virtiofs", []string{}, "Directory shared on virtiofs")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -239,6 +239,30 @@ func runVirtualizationFramework(cfg virtualizationFramwworkConfig, path string)
|
|||||||
config.SetSocketDevicesVirtualMachineConfiguration([]vz.SocketDeviceConfiguration{
|
config.SetSocketDevicesVirtualMachineConfiguration([]vz.SocketDeviceConfiguration{
|
||||||
socketDeviceConfiguration,
|
socketDeviceConfiguration,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if len(cfg.virtiofsShares) > 0 {
|
||||||
|
var cs []vz.DirectorySharingDeviceConfiguration
|
||||||
|
|
||||||
|
for idx, share := range cfg.virtiofsShares {
|
||||||
|
tag := fmt.Sprintf("virtiofs%d", idx)
|
||||||
|
device, err := vz.NewVirtioFileSystemDeviceConfiguration(tag)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("virtiofs device configuration failed", err)
|
||||||
|
}
|
||||||
|
dir, err := vz.NewSharedDirectory(share, false)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("virtiofs shared directory failed", err)
|
||||||
|
}
|
||||||
|
single, err := vz.NewSingleDirectoryShare(dir)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("virtiofs single directory share failed", err)
|
||||||
|
}
|
||||||
|
device.SetDirectoryShare(single)
|
||||||
|
cs = append(cs, device)
|
||||||
|
}
|
||||||
|
config.SetDirectorySharingDevicesVirtualMachineConfiguration(cs)
|
||||||
|
}
|
||||||
|
|
||||||
validated, err := config.Validate()
|
validated, err := config.Validate()
|
||||||
if !validated || err != nil {
|
if !validated || err != nil {
|
||||||
log.Fatal("validation failed", err)
|
log.Fatal("validation failed", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user