mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 09:16:29 +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 {
|
||||
cpus uint
|
||||
mem uint64
|
||||
disks Disks
|
||||
data string
|
||||
dataPath string
|
||||
state string
|
||||
networking string
|
||||
kernelBoot bool
|
||||
cpus uint
|
||||
mem uint64
|
||||
disks Disks
|
||||
data string
|
||||
dataPath string
|
||||
state string
|
||||
networking string
|
||||
kernelBoot bool
|
||||
virtiofsShares []string
|
||||
}
|
||||
|
||||
func runVirtualizationFrameworkCmd() *cobra.Command {
|
||||
var (
|
||||
data string
|
||||
dataPath string
|
||||
state string
|
||||
networking string
|
||||
kernelBoot bool
|
||||
data string
|
||||
dataPath string
|
||||
state string
|
||||
networking string
|
||||
kernelBoot bool
|
||||
virtiofsShares []string
|
||||
)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@ -43,14 +45,15 @@ func runVirtualizationFrameworkCmd() *cobra.Command {
|
||||
Example: "linuxkit run virtualization [options] prefix",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cfg := virtualizationFramwworkConfig{
|
||||
cpus: uint(cpus),
|
||||
mem: uint64(mem) * 1024 * 1024,
|
||||
disks: disks,
|
||||
data: data,
|
||||
dataPath: dataPath,
|
||||
state: state,
|
||||
networking: networking,
|
||||
kernelBoot: kernelBoot,
|
||||
cpus: uint(cpus),
|
||||
mem: uint64(mem) * 1024 * 1024,
|
||||
disks: disks,
|
||||
data: data,
|
||||
dataPath: dataPath,
|
||||
state: state,
|
||||
networking: networking,
|
||||
kernelBoot: kernelBoot,
|
||||
virtiofsShares: virtiofsShares,
|
||||
}
|
||||
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().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
|
||||
}
|
||||
|
@ -239,6 +239,30 @@ func runVirtualizationFramework(cfg virtualizationFramwworkConfig, path string)
|
||||
config.SetSocketDevicesVirtualMachineConfiguration([]vz.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()
|
||||
if !validated || err != nil {
|
||||
log.Fatal("validation failed", err)
|
||||
|
Loading…
Reference in New Issue
Block a user