git.iko.soy/typeable/nixpkgs
on master help sign in
Revert "virtualization/qemu-vm: fix and improve virtio/scsi switching"

This reverts commit f777d2b719be0db4cb7819d5b6dbdd121db29a37. cc #34409 This breaks evaluation of the tested job: attribute 'diskInterface' missing, at /nix/store/5k9kk52bv6zsvsyyvpxhm8xmwyn2yjvx-source/pkgs/build-support/vm/default.nix:316:24

commitded8f28c3a3bd0204738275362dc9450755f9e6b authorSarah Brofeldt <sbrofeldt@gmail.com> dateTue 25 Sep 2018, 10:41 (8 years ago) parent61abf3b
2 files changed+21−39
nixos/modules/virtualisation/qemu-vm.nix+18−26 pkgs/build-support/vm/default.nix+3−13
nixos/modules/virtualisation/qemu-vm.nix+18−26
@@ -32,21 +32,15 @@ let
3232 # expressions and shell script stuff.
3333 mkDiskIfaceDriveFlag = idx: driveArgs: let
3434 inherit (cfg.qemu) diskInterface;
35− isSCSI = diskInterface == "scsi";
3635 # The drive identifier created by incrementing the index by one using the
3736 # shell.
3837 drvId = "drive$((${idx} + 1))";
39− dvcId = "${diskInterface}$((${idx} + 1))";
4038 # NOTE: DO NOT shell escape, because this may contain shell variables.
41− commonDriveArgs = "media=disk,id=${drvId},${driveArgs}";
42− commonInterfaceArgs = "drive=${drvId},id=${dvcId},bootindex=${idx}";
43− in lib.concatStrings [
44− "-drive ${commonDriveArgs},if=none "
45− ''${if isSCSI then
46− "-device lsi53c895a -device ${diskInterface}-hd,${commonInterfaceArgs}"
47− else
48− "-device virtio-blk-pci,scsi=off,${commonInterfaceArgs}"} ''
49− ];
39+ commonArgs = "index=${idx},id=${drvId},${driveArgs}";
40+ isSCSI = diskInterface == "scsi";
41+ devArgs = "${diskInterface}-hd,drive=${drvId}";
42+ args = "-drive ${commonArgs},if=none -device lsi53c895a -device ${devArgs}";
43+ in if isSCSI then args else "-drive ${commonArgs},if=${diskInterface}";
5044
5145 # Shell script to start the VM.
5246 startVM =
@@ -103,15 +97,15 @@ let
10397 -virtfs local,path=/nix/store,security_model=none,mount_tag=store \
10498 -virtfs local,path=$TMPDIR/xchg,security_model=none,mount_tag=xchg \
10599 -virtfs local,path=''${SHARED_DIR:-$TMPDIR/xchg},security_model=none,mount_tag=shared \
106− ${mkDiskIfaceDriveFlag "1" "file=$NIX_DISK_IMAGE,media=disk,cache=writeback,werror=report"} \
107100 ${if cfg.useBootLoader then ''
108− -boot menu=on \
109− ${mkDiskIfaceDriveFlag "0" "file=$TMPDIR/disk.img,media=disk"} \
101+ ${mkDiskIfaceDriveFlag "0" "file=$NIX_DISK_IMAGE,cache=writeback,werror=report"} \
102+ ${mkDiskIfaceDriveFlag "1" "file=$TMPDIR/disk.img,media=disk"} \
110103 ${if cfg.useEFIBoot then ''
111104 -pflash $TMPDIR/bios.bin \
112105 '' else ''
113− \''}
114− '' else '' \
106+ ''}
107+ '' else ''
108+ ${mkDiskIfaceDriveFlag "0" "file=$NIX_DISK_IMAGE,cache=writeback,werror=report"} \
115109 -kernel ${config.system.build.toplevel}/kernel \
116110 -initrd ${config.system.build.toplevel}/initrd \
117111 -append "$(cat ${config.system.build.toplevel}/kernel-params) init=${config.system.build.toplevel}/init regInfo=${regInfo}/registration ${consoles} $QEMU_KERNEL_PARAMS" \
@@ -147,9 +141,8 @@ let
147141 '';
148142 buildInputs = [ pkgs.utillinux ];
149143 QEMU_OPTS = if cfg.useEFIBoot
150− then "-pflash $out/bios.bin -nographic"
151− else "-nographic";
152− diskInterface = cfg.qemu.diskInterface;
144+ then "-pflash $out/bios.bin -nographic -serial pty"
145+ else "-nographic -serial pty";
153146 }
154147 ''
155148 # Create a /boot EFI partition with 40M and arbitrary but fixed GUIDs for reproducibility
@@ -162,10 +155,10 @@ let
162155 --partition-guid=1:1C06F03B-704E-4657-B9CD-681A087A2FDC \
163156 --partition-guid=2:970C694F-AFD0-4B99-B750-CDB7A329AB6F \
164157 --hybrid 2 \
165− --recompute-chs ${config.virtualisation.bootDevice}
166− ${pkgs.dosfstools}/bin/mkfs.fat -F16 ${config.virtualisation.bootDevice}2
158+ --recompute-chs /dev/vda
159+ ${pkgs.dosfstools}/bin/mkfs.fat -F16 /dev/vda2
167160 export MTOOLS_SKIP_CHECK=1
168− ${pkgs.mtools}/bin/mlabel -i ${config.virtualisation.bootDevice}2 ::boot
161+ ${pkgs.mtools}/bin/mlabel -i /dev/vda2 ::boot
169162
170163 # Mount /boot; load necessary modules first.
171164 ${pkgs.kmod}/bin/insmod ${pkgs.linux}/lib/modules/*/kernel/fs/nls/nls_cp437.ko.xz || true
@@ -174,11 +167,11 @@ let
174167 ${pkgs.kmod}/bin/insmod ${pkgs.linux}/lib/modules/*/kernel/fs/fat/vfat.ko.xz || true
175168 ${pkgs.kmod}/bin/insmod ${pkgs.linux}/lib/modules/*/kernel/fs/efivarfs/efivarfs.ko.xz || true
176169 mkdir /boot
177− mount ${config.virtualisation.bootDevice}2 /boot
170+ mount /dev/vda2 /boot
178171
179172 # This is needed for GRUB 0.97, which doesn't know about virtio devices.
180173 mkdir /boot/grub
181− echo '(hd0) ${config.virtualisation.bootDevice}' > /boot/grub/device.map
174+ echo '(hd0) /dev/vda' > /boot/grub/device.map
182175
183176 # Install GRUB and generate the GRUB boot menu.
184177 touch /etc/NIXOS
@@ -471,8 +464,7 @@ in
471464
472465 boot.initrd.availableKernelModules =
473466 optional cfg.writableStore "overlay"
474− ++ optional (cfg.qemu.diskInterface == "scsi") "sym53c8xx"
475− ++ optional (cfg.qemu.diskInterface == "scsi") "virtio_scsi";
467+ ++ optional (cfg.qemu.diskInterface == "scsi") "sym53c8xx";
476468
477469 virtualisation.bootDevice =
478470 mkDefault (if cfg.qemu.diskInterface == "scsi" then "/dev/sda" else "/dev/vda");
pkgs/build-support/vm/default.nix+3−13
@@ -3,9 +3,8 @@
33, img ? pkgs.stdenv.hostPlatform.platform.kernelTarget
44, storeDir ? builtins.storeDir
55, rootModules ?
6− [ "virtio_pci" "virtio_mmio" "virtio_blk" "virtio_balloon" "virtio_rng" "ext4" "unix" "9p" "9pnet_virtio" "crc32c_generic" "sym53c8xx" "virtio_scsi" "ahci "]
6+ [ "virtio_pci" "virtio_mmio" "virtio_blk" "virtio_balloon" "virtio_rng" "ext4" "unix" "9p" "9pnet_virtio" "crc32c_generic" ]
77 ++ pkgs.lib.optional (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) "rtc_cmos"
8−, config
98}:
109
1110with pkgs;
@@ -197,17 +196,9 @@ rec {
197196 ${qemuBinary qemu} \
198197 -nographic -no-reboot \
199198 -device virtio-rng-pci \
200− ${if "$diskInterface" == "scsi" then '' \
201− \ # FIXME: /dev/sda is not created within the VM
202− -device lsi53c895a \
203− -device scsi-hd,drive=hd,id=scsi1,bootindex=1 \
204− ''${diskImage:+-drive file=$diskImage,media=disk,if=none,id=hd,cache=unsafe,werror=report} \
205− '' else '' \
206− -drive file=$diskImage,media=disk,if=none,id=hd \
207− -device virtio-blk-pci,scsi=off,drive=hd,id=virtio0,bootindex=1 \
208− \''}
209199 -virtfs local,path=${storeDir},security_model=none,mount_tag=store \
210200 -virtfs local,path=$TMPDIR/xchg,security_model=none,mount_tag=xchg \
201+ ''${diskImage:+-drive file=$diskImage,if=virtio,cache=unsafe,werror=report} \
211202 -kernel ${kernel}/${img} \
212203 -initrd ${initrd}/initrd \
213204 -append "console=${qemuSerialDevice} panic=1 command=${stage2Init} out=$out mountDisk=$mountDisk loglevel=4" \
@@ -307,13 +298,12 @@ rec {
307298 `run-vm' will be left behind in the temporary build directory
308299 that allows you to boot into the VM and debug it interactively. */
309300
310− runInLinuxVM = drv: lib.overrideDerivation drv ({ memSize ? 512, QEMU_OPTS ? "", args, builder, ... } @ moreArgs : {
301+ runInLinuxVM = drv: lib.overrideDerivation drv ({ memSize ? 512, QEMU_OPTS ? "", args, builder, ... }: {
311302 requiredSystemFeatures = [ "kvm" ];
312303 builder = "${bash}/bin/sh";
313304 args = ["-e" (vmRunCommand qemuCommandLinux)];
314305 origArgs = args;
315306 origBuilder = builder;
316− diskInterface = "${moreArgs.diskInterface}";
317307 QEMU_OPTS = "${QEMU_OPTS} -m ${toString memSize}";
318308 passAsFile = []; # HACK fix - see https://github.com/NixOS/nixpkgs/issues/16742
319309 });