Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #133 from amshinde/scsi-data-plane
Browse files Browse the repository at this point in the history
iothread support for virtio-scsi
  • Loading branch information
bergwolf authored Apr 4, 2018
2 parents dda4a44 + 204e402 commit 0e8b6dc
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

[[constraint]]
name = "github.com/intel/govmm"
revision = "82c67ab9b21e8cd0042b6c2d3be2d3705a511603"
revision = "1509acf1862ae5154c5c096f9318bd3eb434d816"

[[constraint]]
name = "github.com/kata-containers/agent"
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ DEFNETWORKMODEL := macvtap

DEFDISABLEBLOCK := false
DEFBLOCKSTORAGEDRIVER := virtio-scsi
DEFENABLEIOTHREADS := false
DEFENABLEMEMPREALLOC := false
DEFENABLEHUGEPAGES := false
DEFENABLESWAP := false
Expand Down Expand Up @@ -172,6 +173,7 @@ USER_VARS += DEFBRIDGES
USER_VARS += DEFNETWORKMODEL
USER_VARS += DEFDISABLEBLOCK
USER_VARS += DEFBLOCKSTORAGEDRIVER
USER_VARS += DEFENABLEIOTHREADS
USER_VARS += DEFENABLEMEMPREALLOC
USER_VARS += DEFENABLEHUGEPAGES
USER_VARS += DEFENABLESWAP
Expand Down Expand Up @@ -263,6 +265,7 @@ const defaultBridgesCount uint32 = $(DEFBRIDGES)
const defaultInterNetworkingModel = "$(DEFNETWORKMODEL)"
const defaultDisableBlockDeviceUse bool = $(DEFDISABLEBLOCK)
const defaultBlockDeviceDriver = "$(DEFBLOCKSTORAGEDRIVER)"
const defaultEnableIOThreads bool = $(DEFENABLEIOTHREADS)
const defaultEnableMemPrealloc bool = $(DEFENABLEMEMPREALLOC)
const defaultEnableHugePages bool = $(DEFENABLEHUGEPAGES)
const defaultEnableSwap bool = $(DEFENABLESWAP)
Expand Down Expand Up @@ -346,6 +349,7 @@ $(GENERATED_FILES): %: %.in Makefile VERSION
-e "s|@DEFNETWORKMODEL@|$(DEFNETWORKMODEL)|g" \
-e "s|@DEFDISABLEBLOCK@|$(DEFDISABLEBLOCK)|g" \
-e "s|@DEFBLOCKSTORAGEDRIVER@|$(DEFBLOCKSTORAGEDRIVER)|g" \
-e "s|@DEFENABLEIOTHREADS@|$(DEFENABLEIOTHREADS)|g" \
-e "s|@DEFENABLEMEMPREALLOC@|$(DEFENABLEMEMPREALLOC)|g" \
-e "s|@DEFENABLEHUGEPAGES@|$(DEFENABLEHUGEPAGES)|g" \
-e "s|@DEFENABLEMSWAP@|$(DEFENABLESWAP)|g" \
Expand Down
3 changes: 3 additions & 0 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type hypervisor struct {
Swap bool `toml:"enable_swap"`
Debug bool `toml:"enable_debug"`
DisableNestingChecks bool `toml:"disable_nesting_checks"`
EnableIOThreads bool `toml:"enable_iothreads"`
}

type proxy struct {
Expand Down Expand Up @@ -321,6 +322,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
Debug: h.Debug,
DisableNestingChecks: h.DisableNestingChecks,
BlockDeviceDriver: blockDriver,
EnableIOThreads: h.EnableIOThreads,
}, nil
}

Expand Down Expand Up @@ -423,6 +425,7 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat
Debug: defaultEnableDebug,
DisableNestingChecks: defaultDisableNestingChecks,
BlockDeviceDriver: defaultBlockDeviceDriver,
EnableIOThreads: defaultEnableIOThreads,
}

err = config.InterNetworkModel.SetModel(defaultInterNetworkingModel)
Expand Down
6 changes: 6 additions & 0 deletions cli/config/configuration.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ disable_block_device_use = @DEFDISABLEBLOCK@
# virtio-blk.
block_device_driver = "@DEFBLOCKSTORAGEDRIVER@"

# Enable iothreads (data-plane) to be used. This causes IO to be
# handled in a separate IO thread. This is currently only implemented
# for SCSI.
#
enable_iothreads = @DEFENABLEIOTHREADS@

# Enable pre allocation of VM RAM, default false
# Enabling this will result in lower container density
# as all of the memory will be allocated and locked
Expand Down
13 changes: 11 additions & 2 deletions cli/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type testRuntimeConfig struct {
LogPath string
}

func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, kernelParams, machineType, shimPath, proxyPath, logPath string, disableBlock bool, blockDeviceDriver string) string {
func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, kernelParams, machineType, shimPath, proxyPath, logPath string, disableBlock bool, blockDeviceDriver string, enableIOThreads bool) string {
return `
# Runtime configuration file
Expand All @@ -55,6 +55,7 @@ func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath
default_vcpus = ` + strconv.FormatUint(uint64(defaultVCPUCount), 10) + `
default_memory = ` + strconv.FormatUint(uint64(defaultMemSize), 10) + `
disable_block_device_use = ` + strconv.FormatBool(disableBlock) + `
enable_iothreads = ` + strconv.FormatBool(enableIOThreads) + `
[proxy.kata]
path = "` + proxyPath + `"
Expand Down Expand Up @@ -101,8 +102,9 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
machineType := "machineType"
disableBlockDevice := true
blockDeviceDriver := "virtio-scsi"
enableIOThreads := true

runtimeConfigFileData := makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, kernelParams, machineType, shimPath, proxyPath, logPath, disableBlockDevice, blockDeviceDriver)
runtimeConfigFileData := makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, kernelParams, machineType, shimPath, proxyPath, logPath, disableBlockDevice, blockDeviceDriver, enableIOThreads)

configPath := path.Join(dir, "runtime.toml")
err = createConfig(configPath, runtimeConfigFileData)
Expand Down Expand Up @@ -140,6 +142,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
BlockDeviceDriver: defaultBlockDeviceDriver,
DefaultBridges: defaultBridgesCount,
Mlock: !defaultEnableSwap,
EnableIOThreads: enableIOThreads,
}

agentConfig := vc.KataAgentConfig{}
Expand Down Expand Up @@ -569,13 +572,15 @@ func TestNewQemuHypervisorConfig(t *testing.T) {
imagePath := path.Join(dir, "image")
machineType := "machineType"
disableBlock := true
enableIOThreads := true

hypervisor := hypervisor{
Path: hypervisorPath,
Kernel: kernelPath,
Image: imagePath,
MachineType: machineType,
DisableBlockDeviceUse: disableBlock,
EnableIOThreads: enableIOThreads,
}

files := []string{hypervisorPath, kernelPath, imagePath}
Expand Down Expand Up @@ -617,6 +622,10 @@ func TestNewQemuHypervisorConfig(t *testing.T) {
t.Errorf("Expected value for disable block usage %v, got %v", disableBlock, config.DisableBlockDeviceUse)
}

if config.EnableIOThreads != enableIOThreads {
t.Errorf("Expected value for enable IOThreads %v, got %v", enableIOThreads, config.EnableIOThreads)
}

}

func TestNewShimConfig(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion cli/kata-env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
proxyPath := filepath.Join(prefixDir, "proxy")
disableBlock := true
blockStorageDriver := "virtio-scsi"
enableIOThreads := true

// override
defaultProxyPath = proxyPath
Expand Down Expand Up @@ -112,7 +113,9 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
testProxyURL,
logPath,
disableBlock,
blockStorageDriver)
blockStorageDriver,
enableIOThreads,
)

configFile = path.Join(prefixDir, "runtime.toml")
err = createConfig(configFile, runtimeConfig)
Expand Down
23 changes: 23 additions & 0 deletions vendor/github.com/intel/govmm/qemu/qemu.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions virtcontainers/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ type HypervisorConfig struct {
// DisableBlockDeviceUse disallows a block device from being used.
DisableBlockDeviceUse bool

// EnableIOThreads enables IO to be processed in a separate thread.
// Supported currently for virtio-scsi driver.
EnableIOThreads bool

// Debug changes the default hypervisor and kernel parameters to
// enable debug output where available.
Debug bool
Expand Down
7 changes: 6 additions & 1 deletion virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,9 @@ func (q *qemu) createPod(podConfig PodConfig) error {
return err
}

var ioThread *govmmQemu.IOThread
if q.config.BlockDeviceDriver == VirtioSCSI {
devices = q.arch.appendSCSIController(devices)
devices, ioThread = q.arch.appendSCSIController(devices, q.config.EnableIOThreads)
}

cpuModel := q.arch.cpuModel()
Expand Down Expand Up @@ -414,6 +415,10 @@ func (q *qemu) createPod(podConfig PodConfig) error {
Bios: firmwarePath,
}

if ioThread != nil {
qemuConfig.IOThreads = []govmmQemu.IOThread{*ioThread}
}

q.qemuConfig = qemuConfig

return nil
Expand Down
18 changes: 15 additions & 3 deletions virtcontainers/qemu_arch_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type qemuArch interface {
appendImage(devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error)

// appendSCSIController appens a SCSI controller to devices
appendSCSIController(devices []govmmQemu.Device) []govmmQemu.Device
appendSCSIController(devices []govmmQemu.Device, enableIOThreads bool) ([]govmmQemu.Device, *govmmQemu.IOThread)

// appendBridges appends bridges to devices
appendBridges(devices []govmmQemu.Device, bridges []Bridge) []govmmQemu.Device
Expand Down Expand Up @@ -300,15 +300,27 @@ func (q *qemuArchBase) appendImage(devices []govmmQemu.Device, path string) ([]g
return q.appendBlockDevice(devices, drive), nil
}

func (q *qemuArchBase) appendSCSIController(devices []govmmQemu.Device) []govmmQemu.Device {
func (q *qemuArchBase) appendSCSIController(devices []govmmQemu.Device, enableIOThreads bool) ([]govmmQemu.Device, *govmmQemu.IOThread) {
scsiController := govmmQemu.SCSIController{
ID: scsiControllerID,
DisableModern: q.nestedRun,
}

var t *govmmQemu.IOThread

if enableIOThreads {
randBytes, _ := generateRandomBytes(8)

t = &govmmQemu.IOThread{
ID: fmt.Sprintf("%s-%s", "iothread", hex.EncodeToString(randBytes)),
}

scsiController.IOThread = t.ID
}

devices = append(devices, scsiController)

return devices
return devices, t
}

// appendBridges appends to devices the given bridges
Expand Down
6 changes: 5 additions & 1 deletion virtcontainers/qemu_arch_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ func TestQemuArchBaseAppendSCSIController(t *testing.T) {
},
}

devices = qemuArchBase.appendSCSIController(devices)
devices, ioThread := qemuArchBase.appendSCSIController(devices, false)
assert.Equal(expectedOut, devices)
assert.Nil(ioThread)

_, ioThread = qemuArchBase.appendSCSIController(devices, true)
assert.NotNil(ioThread)
}

0 comments on commit 0e8b6dc

Please sign in to comment.