qemu: add block device readonly support

So that we can attach it readonly.

Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
Peng Tao
2020-02-19 05:21:18 -08:00
committed by Samuel Ortiz
parent 37b0d9c12f
commit 3700c55dd7
4 changed files with 11 additions and 2 deletions

View File

@@ -971,6 +971,9 @@ type BlockDevice struct {
// ShareRW enables multiple qemu instances to share the File
ShareRW bool
// ReadOnly sets the block device in readonly mode
ReadOnly bool
// Transport is the virtio transport for this device.
Transport VirtioTransport
}
@@ -1029,6 +1032,10 @@ func (blkdev BlockDevice) QemuParams(config *Config) []string {
blkParams = append(blkParams, fmt.Sprintf(",format=%s", blkdev.Format))
blkParams = append(blkParams, fmt.Sprintf(",if=%s", blkdev.Interface))
if blkdev.ReadOnly {
blkParams = append(blkParams, ",readonly")
}
qemuParams = append(qemuParams, "-device")
qemuParams = append(qemuParams, strings.Join(deviceParams, ""))