Merge lp:~smoser/curtin/trunk.lp1716028-hack-file-locking-in-qemu into lp:~curtin-dev/curtin/trunk

Proposed by Scott Moser
Status: Merged
Merged at revision: 539
Proposed branch: lp:~smoser/curtin/trunk.lp1716028-hack-file-locking-in-qemu
Merge into: lp:~curtin-dev/curtin/trunk
Diff against target: 170 lines (+47/-25)
3 files modified
tests/vmtests/__init__.py (+13/-14)
tools/launch (+10/-10)
tools/xkvm (+24/-1)
To merge this branch: bzr merge lp:~smoser/curtin/trunk.lp1716028-hack-file-locking-in-qemu
Reviewer Review Type Date Requested Status
Ryan Harper (community) Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+330456@code.launchpad.net

Commit message

vmtest: Support newer qemu and multipath.

If you pass the same backing device for a disk to qemu, newer
versions (2.10+) will fail. In order to allow this, it requires
you to pass 'file.locking=off'.

This change makes the multipath tests add a 'file.locking=off' argument
to the disks that are actually intended to be added more than once.
xkvm is modified to remove that flag if the qemu being used does not
support it.

In order to accomplish this:
a.) make launch use xkvm '--disk' for all its disks rather than
    passing -drive and -device. This is good in that we know have
    a single way of passing disks around.
b.) fix a logic bug in xkvm when --disk= specified format= on it.

vmtest and launch now only use '--disk=' args, which are interpreted
by xkvm rather than using a mix of '--disk=' and '-drive'.

To post a comment you must log in.
527. By Scott Moser

cleanup

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
528. By Scott Moser

do not override _QEMU_SUPPORTS_FILE_LOCKING in environment.

Revision history for this message
Ryan Harper (raharper) wrote :

+1 on the cls.multipath append of file.locking=off; that's cleaner than putting it in everywhere.

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
529. By Scott Moser

use share-rw presense rather than looking for binary string search.

Revision history for this message
Scott Moser (smoser) wrote :

Note, i put this branch
 https://code.launchpad.net/~smoser/curtin/trunk.lp1716028-better-file-locking/
it has some code that i think is cleaner to turn --disk into -drive and -device
support, but I ended up shelving it because we couldn't use share-rw anyway
due to that not really working with -drive (see comments in bug).

Revision history for this message
Ryan Harper (raharper) wrote :

This looks good. I really like having vmtest pass the locking in and xkvm handling/setting if available.

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

launch: unrecognized option '--disk,file.locking=off'
launch: unrecognized option '--disk,file.locking=off'

Revision history for this message
Ryan Harper (raharper) wrote :

http://paste.ubuntu.com/25522510/

This helps get it on the disk parameter as a devopt; but xkvm puts those on under -device parameters to qemu, however, file.locking is a -drive parameter.

review: Needs Fixing
530. By Scott Moser

xkvm: fix logic bug in xkvm if user provided format, it got set to raw

531. By Scott Moser

tools/launch: make 'launch' pass --disk to xkvm rather than -drive/-device

532. By Scott Moser

vmtests: make multipath disks use file.locking=off

533. By Scott Moser

merge with trunk

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

I really want to have xkvm just always disable file.locking (if a qemu has it enabled).

But I do understand that it's reasonable for the test to declare that
it doesn't want/need file locking.

Revision history for this message
Ryan Harper (raharper) :
534. By Scott Moser

make multipath versions for both install and boot.

535. By Scott Moser

fix one last '-drive' usage with equivalent --disk

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
536. By Scott Moser

and the last -drive from tools/launch

Revision history for this message
Scott Moser (smoser) wrote :

I notice now that
 cls.mpath_args(cls.mpath_diskargs(target_disks + extra_disks + nvme_disks)
is not really the same as waht we did before, which was effectively:
cls.mpath_diskargs(target_disks) + cls.mpath_diskargs(extra_disks) + cls.mpath_diskargs(nvme_disks)

the difference is really just in order, effectively
new: [a,b,c] * 2 = [a, b, c, a, b, c]
where before we had
 [a] * 2 + b * 2 + c * 2 = [a, a, b, b, c, c]

it all should really come out the same just different order of -drive options/-device options.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

> I notice now that
> cls.mpath_args(cls.mpath_diskargs(target_disks + extra_disks + nvme_disks)
> is not really the same as waht we did before, which was effectively:
> cls.mpath_diskargs(target_disks) + cls.mpath_diskargs(extra_disks) +
> cls.mpath_diskargs(nvme_disks)
>
> the difference is really just in order, effectively
> new: [a,b,c] * 2 = [a, b, c, a, b, c]
> where before we had
> [a] * 2 + b * 2 + c * 2 = [a, a, b, b, c, c]
>
> it all should really come out the same just different order of -drive
> options/-device options.

You're right that the order is different, but I think you've got them backwards:

For the multi-list-join path:

cls.mpath_disks([a, b] + [c, d] + [e, f])

We used to get:
[a, b, a, b, c, d, c, d, e, f, e, f]

and with this new code we'll get:

[a, a, b, b, c, c, d, d, e, e, f, f]

Since we iterate over the combined list and multiply out each element of the list times the multiplier.

I *think* we'll be fine, specifically in the multipath case, the devices are paired by their serial number/model not by their placement on the PCI bus.

Revision history for this message
Ryan Harper (raharper) :
review: Approve
Revision history for this message
Scott Moser (smoser) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/vmtests/__init__.py'
--- tests/vmtests/__init__.py 2017-10-11 13:55:42 +0000
+++ tests/vmtests/__init__.py 2017-10-19 20:20:00 +0000
@@ -699,9 +699,6 @@
699 logger.info('Detected centos, adding default config %s',699 logger.info('Detected centos, adding default config %s',
700 centos_default)700 centos_default)
701701
702 if cls.multipath:
703 disks = disks * cls.multipath_num_paths
704
705 # set reporting logger702 # set reporting logger
706 cls.reporting_log = os.path.join(cls.td.logs, 'webhooks-events.json')703 cls.reporting_log = os.path.join(cls.td.logs, 'webhooks-events.json')
707 reporting_logger = CaptureReporting(cls.reporting_log)704 reporting_logger = CaptureReporting(cls.reporting_log)
@@ -727,7 +724,7 @@
727 }))724 }))
728 configs.append(reporting_config)725 configs.append(reporting_config)
729726
730 cmd.extend(uefi_flags + netdevs + disks +727 cmd.extend(uefi_flags + netdevs + cls.mpath_diskargs(disks) +
731 [ftypes['vmtest.root-image'], "--kernel=%s" %728 [ftypes['vmtest.root-image'], "--kernel=%s" %
732 ftypes['boot-kernel'], "--initrd=%s" %729 ftypes['boot-kernel'], "--initrd=%s" %
733 ftypes['boot-initrd'], "--", "curtin", "-vv", "install"] +730 ftypes['boot-initrd'], "--", "curtin", "-vv", "install"] +
@@ -825,11 +822,6 @@
825 # unlike NVMe disks, we do not want to configure the iSCSI disks822 # unlike NVMe disks, we do not want to configure the iSCSI disks
826 # via KVM, which would use qemu's iSCSI target layer.823 # via KVM, which would use qemu's iSCSI target layer.
827824
828 if cls.multipath:
829 target_disks = target_disks * cls.multipath_num_paths
830 extra_disks = extra_disks * cls.multipath_num_paths
831 nvme_disks = nvme_disks * cls.multipath_num_paths
832
833 # output disk is always virtio-blk, with serial of output_disk.img825 # output disk is always virtio-blk, with serial of output_disk.img
834 output_disk = '--disk={},driver={},format={},{},{}'.format(826 output_disk = '--disk={},driver={},format={},{},{}'.format(
835 cls.td.output_disk, 'virtio-blk',827 cls.td.output_disk, 'virtio-blk',
@@ -840,11 +832,9 @@
840 # create xkvm cmd832 # create xkvm cmd
841 cmd = (["tools/xkvm", "-v", dowait] +833 cmd = (["tools/xkvm", "-v", dowait] +
842 uefi_flags + netdevs +834 uefi_flags + netdevs +
843 target_disks + extra_disks + nvme_disks +835 cls.mpath_diskargs(target_disks + extra_disks + nvme_disks) +
844 ["--", "-drive",836 ["--disk=file=%s,if=virtio,media=cdrom" % cls.td.seed_disk] +
845 "file=%s,if=virtio,media=cdrom" % cls.td.seed_disk,837 ["--", "-smp", cls.get_config_smp(), "-m", "1024"])
846 "-smp", cls.get_config_smp(),
847 "-m", "1024"])
848838
849 if not cls.interactive:839 if not cls.interactive:
850 if cls.arch == 's390x':840 if cls.arch == 's390x':
@@ -1007,6 +997,15 @@
1007 # prepending ./ makes '/root/file' or 'root/file' work as expected.997 # prepending ./ makes '/root/file' or 'root/file' work as expected.
1008 return os.path.normpath(os.path.join(cls.td.collect, "./" + path))998 return os.path.normpath(os.path.join(cls.td.collect, "./" + path))
1009999
1000 @classmethod
1001 def mpath_diskargs(cls, disks):
1002 """make multipath versions of --disk args in disks."""
1003 if not cls.multipath:
1004 return disks
1005 opt = ",file.locking=off"
1006 return ([d if d == "--disk" else d + opt for d in disks] *
1007 cls.multipath_num_paths)
1008
1010 # Misc functions that are useful for many tests1009 # Misc functions that are useful for many tests
1011 def output_files_exist(self, files):1010 def output_files_exist(self, files):
1012 logger.debug('checking files exist: %s', files)1011 logger.debug('checking files exist: %s', files)
10131012
=== modified file 'tools/launch'
--- tools/launch 2017-07-25 15:15:09 +0000
+++ tools/launch 2017-10-19 20:20:00 +0000
@@ -583,11 +583,10 @@
583 bs_args="${bs_args},physical_block_size=$phybs"583 bs_args="${bs_args},physical_block_size=$phybs"
584 bs_args="${bs_args},min_io_size=$logbs"584 bs_args="${bs_args},min_io_size=$logbs"
585585
586 disk_args=( "${disk_args[@]}" "-drive"586 t="file=${src},if=none,cache=unsafe,format=$fmt,"
587 "file=${src},if=none,cache=unsafe,format=$fmt,id=drv${id},index=$id" )587 t="${t}id=drv${id},index=$id,"
588588 t="${t}driver=${driver},${bs_args}${devopts}"
589 disk_args=( "${disk_args[@]}" "-device"589 disk_args[${#disk_args[@]}]="--disk=$t"
590 "${driver},drive=drv${id},${bs_args}${devopts}" )
591590
592 done591 done
593592
@@ -754,7 +753,7 @@
754 seed="${TEMP_D}/seed.img"753 seed="${TEMP_D}/seed.img"
755 cloud-localds "$seed" "$udata" "$mdata" ||754 cloud-localds "$seed" "$udata" "$mdata" ||
756 { error "failed cloud-localds"; return 1; }755 { error "failed cloud-localds"; return 1; }
757 seedargs=( "-drive" "file=${seed},if=virtio,media=cdrom" )756 seedargs=( "--disk=file=${seed},if=virtio,media=cdrom" )
758 fi757 fi
759758
760 local netargs759 local netargs
@@ -779,13 +778,14 @@
779 fi778 fi
780 fi779 fi
781 # -monitor stdio780 # -monitor stdio
781 local bootdisk="--disk=file=$bootimg,id=boot,index=1,cache=unsafe"
782 cmd=(782 cmd=(
783 xkvm "${pt[@]}" "${netargs[@]}" --783 xkvm "${pt[@]}" "${netargs[@]}"
784 "$bootdisk"
785 "${disk_args[@]}"
786 --
784 -smp ${smp}787 -smp ${smp}
785 -m ${mem} ${serial_args} ${video}788 -m ${mem} ${serial_args} ${video}
786 -drive "file=$bootimg,if=none,cache=unsafe,format=qcow2,id=boot,index=0"
787 -device "virtio-blk,drive=boot"
788 "${disk_args[@]}"
789 "${seedargs[@]}"789 "${seedargs[@]}"
790 )790 )
791791
792792
=== modified file 'tools/xkvm'
--- tools/xkvm 2016-10-07 19:31:01 +0000
+++ tools/xkvm 2017-10-19 20:20:00 +0000
@@ -11,6 +11,8 @@
11# OVS_CLEANUP gets populated with bridge:devname pairs used with ovs11# OVS_CLEANUP gets populated with bridge:devname pairs used with ovs
12OVS_CLEANUP=( )12OVS_CLEANUP=( )
13MAC_PREFIX="52:54:00:12:34"13MAC_PREFIX="52:54:00:12:34"
14# allow this to be set externally.
15_QEMU_SUPPORTS_FILE_LOCKING="${_QEMU_SUPPORTS_FILE_LOCKING}"
14KVM="kvm"16KVM="kvm"
15declare -A KVM_DEVOPTS17declare -A KVM_DEVOPTS
1618
@@ -119,6 +121,21 @@
119 return 1121 return 1
120}122}
121123
124qemu_supports_file_locking() {
125 # hackily check if qemu has file.locking in -drive params (LP: #1716028)
126 if [ -z "$_QEMU_SUPPORTS_FILE_LOCKING" ]; then
127 # The only way we could find to check presense of file.locking is
128 # qmp (query-qmp-schema). Simply checking if the virtio-blk driver
129 # supports 'share-rw' is expected to be equivalent and simpler.
130 isdevopt virtio-blk share-rw &&
131 _QEMU_SUPPORTS_FILE_LOCKING=true ||
132 _QEMU_SUPPORTS_FILE_LOCKING=false
133 debug 1 "qemu supports file locking = ${_QEMU_SUPPORTS_FILE_LOCKING}"
134 fi
135 [ "$_QEMU_SUPPORTS_FILE_LOCKING" = "true" ]
136 return
137}
138
122padmac() {139padmac() {
123 # return a full mac, given a subset.140 # return a full mac, given a subset.
124 # assume whatever is input is the last portion to be141 # assume whatever is input is the last portion to be
@@ -443,7 +460,7 @@
443 out=$(LANG=C qemu-img info "$file") &&460 out=$(LANG=C qemu-img info "$file") &&
444 fmt=$(echo "$out" | awk '$0 ~ /^file format:/ { print $3 }') ||461 fmt=$(echo "$out" | awk '$0 ~ /^file format:/ { print $3 }') ||
445 { error "failed to determine format of $file"; return 1; }462 { error "failed to determine format of $file"; return 1; }
446 else463 elif [ -z "$fmt" ]; then
447 fmt=raw464 fmt=raw
448 fi465 fi
449 if [ -z "$driver" ]; then466 if [ -z "$driver" ]; then
@@ -470,6 +487,12 @@
470 id=*|if=*|driver=*|$file|file=*) continue;;487 id=*|if=*|driver=*|$file|file=*) continue;;
471 fmt=*|format=*) continue;;488 fmt=*|format=*) continue;;
472 serial=*|bus=*|unit=*|index=*) continue;;489 serial=*|bus=*|unit=*|index=*) continue;;
490 file.locking=*)
491 qemu_supports_file_locking || {
492 debug 2 "qemu has no file locking." \
493 "Dropping '$tok' from: $cur"
494 continue
495 };;
473 esac496 esac
474 isdevopt "$driver" "$tok" && devopts="${devopts},$tok" ||497 isdevopt "$driver" "$tok" && devopts="${devopts},$tok" ||
475 diskopts="${diskopts},${tok}"498 diskopts="${diskopts},${tok}"

Subscribers

People subscribed via source and target branches