qemu: pass guest image file readonly

So that we fobid guest from making changes to it.

Fixes: #2476
Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
Peng Tao 2020-02-19 05:50:57 -08:00
parent 63fdf5328f
commit 46392945c6
3 changed files with 10 additions and 4 deletions

View File

@ -153,6 +153,9 @@ type BlockDrive struct {
// ShareRW enables multiple qemu instances to share the File // ShareRW enables multiple qemu instances to share the File
ShareRW bool ShareRW bool
// ReadOnly sets the device file readonly
ReadOnly bool
} }
// VFIODeviceType indicates VFIO device type // VFIODeviceType indicates VFIO device type

View File

@ -347,6 +347,7 @@ func genericImage(path string) (config.BlockDrive, error) {
Format: "raw", Format: "raw",
ID: id, ID: id,
ShareRW: true, ShareRW: true,
ReadOnly: true,
} }
return drive, nil return drive, nil
@ -603,6 +604,7 @@ func genericBlockDevice(drive config.BlockDrive, nestedRun bool) (govmmQemu.Bloc
Interface: "none", Interface: "none",
DisableModern: nestedRun, DisableModern: nestedRun,
ShareRW: drive.ShareRW, ShareRW: drive.ShareRW,
ReadOnly: drive.ReadOnly,
}, nil }, nil
} }

View File

@ -308,6 +308,7 @@ func TestQemuArchBaseAppendImage(t *testing.T) {
Format: "raw", Format: "raw",
Interface: "none", Interface: "none",
ShareRW: true, ShareRW: true,
ReadOnly: true,
}, },
} }