Skip to content

Commit db259de

Browse files
committed
kola/qemu: add support for simulating 512e disks
It's come up a few times now that we need to dig into 512e-specific behaviours (most recently in OCPBUGS-35410). Let's add a knob for this in the qemu platform just like the one we have for 4Kn.
1 parent f85cc74 commit db259de

File tree

6 files changed

+52
-29
lines changed

6 files changed

+52
-29
lines changed

docs/cosa/run.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Additional disks CLI arguments support optional flags using the `--add-disk
8787

8888
- `mpath`: enables multipathing for the disk (see below for details).
8989
- `4k`: sets the disk as 4Kn (4096 physical sector size)
90+
- `512e`: sets the disk as 512e (4096 physical sector size, 512 logical sector size)
9091
- `channel=CHANNEL`: set the channel type (e.g. `virtio`, `nvme`, `scsi`)
9192
- `serial=NAME`: sets the disk serial; this can then be used to customize the
9293
default `diskN` naming documented above (e.g. `serial=foobar` will make the

mantle/cmd/kola/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func init() {
157157
bv(&kola.QEMUOptions.NbdDisk, "qemu-nbd-socket", false, "Present the disks over NBD socket to qemu")
158158
bv(&kola.QEMUOptions.MultiPathDisk, "qemu-multipath", false, "Enable multiple paths for the main disk")
159159
bv(&kola.QEMUOptions.Native4k, "qemu-native-4k", false, "Force 4k sectors for main disk")
160+
bv(&kola.QEMUOptions.Disk512e, "qemu-512e", false, "Force 512e layout for main disk")
160161
bv(&kola.QEMUOptions.Nvme, "qemu-nvme", false, "Use NVMe for main disk")
161162
bv(&kola.QEMUOptions.Swtpm, "qemu-swtpm", true, "Create temporary software TPM")
162163
ssv(&kola.QEMUOptions.BindRO, "qemu-bind-ro", nil, "Inject a host directory; this does not automatically mount in the guest")

mantle/cmd/kola/qemuexec.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,12 @@ func buildDiskFromOptions() *platform.Disk {
139139
channel = "nvme"
140140
}
141141
sectorSize := 0
142+
logicalSectorSize := 0
142143
if kola.QEMUOptions.Native4k {
143144
sectorSize = 4096
145+
} else if kola.QEMUOptions.Disk512e {
146+
sectorSize = 4096
147+
logicalSectorSize = 512
144148
}
145149
options := []string{}
146150
if kola.QEMUOptions.DriveOpts != "" {
@@ -155,13 +159,14 @@ func buildDiskFromOptions() *platform.Disk {
155159
// Build the disk definition. Note that if kola.QEMUOptions.DiskImage is
156160
// "" we'll just end up with a blank disk image, which is what we want.
157161
disk := &platform.Disk{
158-
BackingFile: kola.QEMUOptions.DiskImage,
159-
Channel: channel,
160-
Size: size,
161-
SectorSize: sectorSize,
162-
DriveOpts: options,
163-
MultiPathDisk: kola.QEMUOptions.MultiPathDisk,
164-
NbdDisk: kola.QEMUOptions.NbdDisk,
162+
BackingFile: kola.QEMUOptions.DiskImage,
163+
Channel: channel,
164+
Size: size,
165+
SectorSize: sectorSize,
166+
LogicalSectorSize: logicalSectorSize,
167+
DriveOpts: options,
168+
MultiPathDisk: kola.QEMUOptions.MultiPathDisk,
169+
NbdDisk: kola.QEMUOptions.NbdDisk,
165170
}
166171
return disk
167172
}

mantle/platform/machine/qemu/cluster.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,12 @@ func (qc *Cluster) NewMachineWithQemuOptions(userdata *conf.UserData, options pl
145145
channel = "nvme"
146146
}
147147
sectorSize := 0
148+
logicalSectorSize := 0
148149
if qc.flight.opts.Native4k {
149150
sectorSize = 4096
151+
} else if qc.flight.opts.Disk512e {
152+
sectorSize = 4096
153+
logicalSectorSize = 512
150154
}
151155
multiPathDisk := options.MultiPathDisk || qc.flight.opts.MultiPathDisk
152156
var diskSize string
@@ -156,11 +160,12 @@ func (qc *Cluster) NewMachineWithQemuOptions(userdata *conf.UserData, options pl
156160
diskSize = qc.flight.opts.DiskSize
157161
}
158162
primaryDisk := platform.Disk{
159-
BackingFile: qc.flight.opts.DiskImage,
160-
Channel: channel,
161-
Size: diskSize,
162-
SectorSize: sectorSize,
163-
MultiPathDisk: multiPathDisk,
163+
BackingFile: qc.flight.opts.DiskImage,
164+
Channel: channel,
165+
Size: diskSize,
166+
SectorSize: sectorSize,
167+
LogicalSectorSize: logicalSectorSize,
168+
MultiPathDisk: multiPathDisk,
164169
}
165170

166171
if options.OverrideBackingFile != "" {

mantle/platform/machine/qemu/flight.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Options struct {
4141
NbdDisk bool
4242
MultiPathDisk bool
4343
Native4k bool
44+
Disk512e bool
4445
Nvme bool
4546

4647
//Option to create a temporary software TPM - true by default

mantle/platform/qemu.go

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,17 @@ type QEMUMachine interface {
8989

9090
// Disk holds the details of a virtual disk.
9191
type Disk struct {
92-
Size string // disk image size in bytes, optional suffixes "K", "M", "G", "T" allowed.
93-
BackingFile string // raw disk image to use.
94-
BackingFormat string // qcow2, raw, etc. If unspecified will be autodetected.
95-
Channel string // virtio (default), nvme, scsi
96-
DeviceOpts []string // extra options to pass to qemu -device. "serial=XXXX" makes disks show up as /dev/disk/by-id/virtio-<serial>
97-
DriveOpts []string // extra options to pass to -drive
98-
SectorSize int // if not 0, override disk sector size
99-
NbdDisk bool // if true, the disks should be presented over nbd:unix socket
100-
MultiPathDisk bool // if true, present multiple paths
101-
Wwn uint64 // Optional World wide name for the SCSI disk. If not set or set to 0, a random one will be generated. Used only with "channel=scsi". Must be an integer
92+
Size string // disk image size in bytes, optional suffixes "K", "M", "G", "T" allowed.
93+
BackingFile string // raw disk image to use.
94+
BackingFormat string // qcow2, raw, etc. If unspecified will be autodetected.
95+
Channel string // virtio (default), nvme, scsi
96+
DeviceOpts []string // extra options to pass to qemu -device. "serial=XXXX" makes disks show up as /dev/disk/by-id/virtio-<serial>
97+
DriveOpts []string // extra options to pass to -drive
98+
SectorSize int // if not 0, override disk sector size
99+
LogicalSectorSize int // if not 0, override disk sector size
100+
NbdDisk bool // if true, the disks should be presented over nbd:unix socket
101+
MultiPathDisk bool // if true, present multiple paths
102+
Wwn uint64 // Optional World wide name for the SCSI disk. If not set or set to 0, a random one will be generated. Used only with "channel=scsi". Must be an integer
102103

103104
attachEndPoint string // qemuPath to attach to
104105
dstFileName string // the prepared file
@@ -108,6 +109,7 @@ type Disk struct {
108109
func ParseDisk(spec string) (*Disk, error) {
109110
var channel string
110111
sectorSize := 0
112+
logicalSectorSize := 0
111113
serialOpt := []string{}
112114
multipathed := false
113115
var wwn uint64
@@ -123,6 +125,9 @@ func ParseDisk(spec string) (*Disk, error) {
123125
channel = value
124126
case "4k":
125127
sectorSize = 4096
128+
case "512e":
129+
sectorSize = 4096
130+
logicalSectorSize = 512
126131
case "mpath":
127132
multipathed = true
128133
case "serial":
@@ -139,12 +144,13 @@ func ParseDisk(spec string) (*Disk, error) {
139144
}
140145

141146
return &Disk{
142-
Size: fmt.Sprintf("%dG", size),
143-
Channel: channel,
144-
DeviceOpts: serialOpt,
145-
SectorSize: sectorSize,
146-
MultiPathDisk: multipathed,
147-
Wwn: wwn,
147+
Size: fmt.Sprintf("%dG", size),
148+
Channel: channel,
149+
DeviceOpts: serialOpt,
150+
SectorSize: sectorSize,
151+
LogicalSectorSize: logicalSectorSize,
152+
MultiPathDisk: multipathed,
153+
Wwn: wwn,
148154
}, nil
149155
}
150156

@@ -1171,7 +1177,11 @@ func (builder *QemuBuilder) addDiskImpl(disk *Disk, primary bool) error {
11711177
channel = "virtio"
11721178
}
11731179
if disk.SectorSize != 0 {
1174-
diskOpts = append(diskOpts, fmt.Sprintf("physical_block_size=%[1]d,logical_block_size=%[1]d", disk.SectorSize))
1180+
logical := disk.LogicalSectorSize
1181+
if logical == 0 {
1182+
logical = disk.SectorSize
1183+
}
1184+
diskOpts = append(diskOpts, fmt.Sprintf("physical_block_size=%d,logical_block_size=%d", disk.SectorSize, logical))
11751185
}
11761186
// Primary disk gets bootindex 1, all other disks have unspecified
11771187
// bootindex, which means lower priority.

0 commit comments

Comments
 (0)