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

Commit dcaabed

Browse files
committed
blk-dev: hotplug read only if applicable
If a block based volume is read only, let's make sure we add as a RO device Fixes: #3114 Signed-off-by: Eric Ernst <[email protected]>
1 parent 76ca708 commit dcaabed

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

virtcontainers/container.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ func (c *Container) createBlockDevices() error {
680680
DevType: "b",
681681
Major: int64(unix.Major(stat.Rdev)),
682682
Minor: int64(unix.Minor(stat.Rdev)),
683+
ReadOnly: m.ReadOnly,
683684
}
684685
// check whether source can be used as a pmem device
685686
} else if di, err = config.PmemDeviceInfo(m.Source, m.Destination); err != nil {

virtcontainers/device/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ type DeviceInfo struct {
114114
// for a nvdimm device in the guest.
115115
Pmem bool
116116

117+
// If applicable, should this device be considered RO
118+
ReadOnly bool
119+
117120
// ColdPlug specifies whether the device must be cold plugged (true)
118121
// or hot plugged (false).
119122
ColdPlug bool

virtcontainers/device/drivers/block.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ func (device *BlockDevice) Attach(devReceiver api.DeviceReceiver) (err error) {
6161
}
6262

6363
drive := &config.BlockDrive{
64-
File: device.DeviceInfo.HostPath,
65-
Format: "raw",
66-
ID: utils.MakeNameID("drive", device.DeviceInfo.ID, maxDevIDSize),
67-
Index: index,
68-
Pmem: device.DeviceInfo.Pmem,
64+
File: device.DeviceInfo.HostPath,
65+
Format: "raw",
66+
ID: utils.MakeNameID("drive", device.DeviceInfo.ID, maxDevIDSize),
67+
Index: index,
68+
Pmem: device.DeviceInfo.Pmem,
69+
ReadOnly: device.DeviceInfo.ReadOnly,
6970
}
7071

7172
if fs, ok := device.DeviceInfo.DriverOptions["fstype"]; ok {

virtcontainers/qemu.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,9 +1105,9 @@ func (q *qemu) hotplugAddBlockDevice(drive *config.BlockDrive, op operation, dev
11051105
}
11061106

11071107
if q.config.BlockDeviceCacheSet {
1108-
err = q.qmpMonitorCh.qmp.ExecuteBlockdevAddWithCache(q.qmpMonitorCh.ctx, drive.File, drive.ID, q.config.BlockDeviceCacheDirect, q.config.BlockDeviceCacheNoflush, false)
1108+
err = q.qmpMonitorCh.qmp.ExecuteBlockdevAddWithCache(q.qmpMonitorCh.ctx, drive.File, drive.ID, q.config.BlockDeviceCacheDirect, q.config.BlockDeviceCacheNoflush, drive.ReadOnly)
11091109
} else {
1110-
err = q.qmpMonitorCh.qmp.ExecuteBlockdevAdd(q.qmpMonitorCh.ctx, drive.File, drive.ID, false)
1110+
err = q.qmpMonitorCh.qmp.ExecuteBlockdevAdd(q.qmpMonitorCh.ctx, drive.File, drive.ID, drive.ReadOnly)
11111111
}
11121112
if err != nil {
11131113
return err

0 commit comments

Comments
 (0)