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

Commit

Permalink
qemu: pass guest image file readonly
Browse files Browse the repository at this point in the history
So that we fobid guest from making changes to it.

Fixes: #2476
Signed-off-by: Peng Tao <bergwolf@hyper.sh>
  • Loading branch information
bergwolf committed Feb 26, 2020
1 parent 63fdf53 commit 4639294
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions virtcontainers/device/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ type BlockDrive struct {

// ShareRW enables multiple qemu instances to share the File
ShareRW bool

// ReadOnly sets the device file readonly
ReadOnly bool
}

// VFIODeviceType indicates VFIO device type
Expand Down
10 changes: 6 additions & 4 deletions virtcontainers/qemu_arch_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,11 @@ func genericImage(path string) (config.BlockDrive, error) {
id := utils.MakeNameID("image", hex.EncodeToString(randBytes), maxDevIDSize)

drive := config.BlockDrive{
File: path,
Format: "raw",
ID: id,
ShareRW: true,
File: path,
Format: "raw",
ID: id,
ShareRW: true,
ReadOnly: true,
}

return drive, nil
Expand Down Expand Up @@ -603,6 +604,7 @@ func genericBlockDevice(drive config.BlockDrive, nestedRun bool) (govmmQemu.Bloc
Interface: "none",
DisableModern: nestedRun,
ShareRW: drive.ShareRW,
ReadOnly: drive.ReadOnly,
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions virtcontainers/qemu_arch_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ func TestQemuArchBaseAppendImage(t *testing.T) {
Format: "raw",
Interface: "none",
ShareRW: true,
ReadOnly: true,
},
}

Expand Down

0 comments on commit 4639294

Please sign in to comment.