1. 25 3月, 2019 6 次提交
    • E
      snapshot: Add tests of virsh -c test:///default snapshot* · 280a2b41
      Eric Blake 提交于
      Had this been in place earlier, I would have avoided the bugs in
      commit 0baf6945 and 55c2ab3e. Writing the test required me to extend
      the power of virsh - creating enough snapshots to cause fanout
      requires enough input in a single session that adding comments and
      markers makes it easier to check that output is correct. It's still a
      bit odd that with test:///default, reverting to a snapshot changes the
      domain from running to paused (possibly a bug in how the test driver
      copied from the qemu driver) - but the important part is that the test
      is reproducible, and any future tweaks we make to snapshot code have
      less chance of breaking successful command sequences.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Acked-by: NMichal Privoznik <mprivozn@redhat.com>
      280a2b41
    • E
      virsh: Add 'echo --err' option · 2efb42e9
      Eric Blake 提交于
      Since test:///default resets state on every connection, writing a test
      that covers a sequence of commands must be done from a single
      session. But if the test wants to exercise particular failure modes as
      well as successes, it can be nice to leave witnesses in the stderr
      stream immediately before and after the spot where the expected error
      should be, to ensure the rest of the script is not causing errors.
      
      Do this by adding an --err option.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Acked-by: NMichal Privoznik <mprivozn@redhat.com>
      2efb42e9
    • E
      virsh: Treat any command name starting with # as comment · 4e650259
      Eric Blake 提交于
      As the previous commit mentioned, argv mode (such as when you feed
      virsh via stdin with <<\EOF instead of via a single shell argument)
      didn't permit comments. Do this by treating any command name token
      that starts with # as a comment which silently eats all remaining
      arguments to the next newline or semicolon.
      
      Note that batch mode recognizes unquoted # at the start of any word as
      a command as part of the tokenizer, while this patch only treats # at
      the start of the command word as a comment (any other # remaining by
      the time vshCommandParse() is processing things was already quoted
      during the tokenzier, and as such was probably intended as the actual
      argument to the command word earlier in the line).
      
      Now I can do something like:
      
      $ virsh -c test:///default <<EOF
        # setup
        snapshot-create-as test s1
        snapshot-create-as test s2
        # check
        snapshot-list test --name
      EOF
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Acked-by: NMichal Privoznik <mprivozn@redhat.com>
      4e650259
    • E
      virsh: Parse # comments in batch mode · 834f64ca
      Eric Blake 提交于
      Continuing from what I did in commit 4817dec0, now I want to write a
      sequence that is self-documenting.  So I need comments :)
      
      Now I can do something like:
      
      $ virsh -c test:///default '
        # setup
        snapshot-create-as test s1
        snapshot-create-as test s2
        # check
        snapshot-list test --name
      '
      
      Note that this does NOT accept comments in argv mode, another patch
      will tackle that.
      
      (If I'm not careful, I might turn virsh into a full-fledged 'sh'
      replacement? Here's hoping I don't go that far...)
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Acked-by: NMichal Privoznik <mprivozn@redhat.com>
      834f64ca
    • E
      snapshot: Avoid infloop during REDEFINE · 9884b2d1
      Eric Blake 提交于
      Commit 55c2ab3e accidentally introduced an infinite loop while
      checking whether a redefined snapshot would cause an infinite loop in
      chasing its parents back to a root.  Alas, 'make check' did not catch
      it, so my next patch will be a testsuite improvement that would have
      hung and prevented the bug from being checked in to begin with.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Acked-by: NMichal Privoznik <mprivozn@redhat.com>
      9884b2d1
    • D
      domain_conf: check device address before attach · f1d65853
      Daniel Henrique Barboza 提交于
      In a case where we want to hotplug the following disk:
      
      <disk type='file' device='disk'>
          (...)
          <address type='drive' controller='0' bus='0' target='0' unit='0'/>
      </disk>
      
      In a QEMU guest that has a single OS disk, as follows:
      
      <disk type='file' device='disk'>
          (...)
          <address type='drive' controller='0' bus='0' target='0' unit='0'/>
      </disk>
      
      What happens is that the existing guest disk will receive the ID
      'scsi0-0-0-0' due to how Libvirt calculate the alias based on
      the address in qemu_alias.c, qemuAssignDeviceDiskAlias. When hotplugging
      a disk that happens to have the same address, Libvirt will calculate
      the same ID to it and attempt to device_add. QEMU will refuse it:
      
      $ virsh attach-device ub1810 hp-disk-dup.xml
      error: Failed to attach device from hp-disk-dup.xml
      error: internal error: unable to execute QEMU command 'device_add': Duplicate ID 'scsi0-0-0-0' for device
      
      And Libvirt follows it up with a cleanup code in qemuDomainAttachDiskGeneric
      that ends up removing what supposedly is a faulty hotplugged disk but, in
      this case, ends up being the original guest disk.
      
      This patch adds an address verification for all attached devices, avoid
      calling the driver attach() function using a device with duplicated address.
      The change is done in virDomainDefCompatibleDevice when @action is equal
      to VIR_DOMAIN_DEVICE_ACTION_ATTACH. The affected callers are:
      
      - qemuDomainAttachDeviceLiveAndConfig, both LIVE and CONFIG cases;
      - lxcDomainAttachDeviceFlags, both LIVE and CONFIG.
      
      The check is done using the virDomainDefHasDeviceAddress, a generic
      function that can check address duplicates for all supported device
      types, not limiting just to DeviceDisk type.
      
      After this patch, this is the result of the previous attach-device call:
      
      $ ./run tools/virsh attach-device ub1810 hp-disk-dup.xml
      error: Failed to attach device from hp-disk-dup.xml
      error: Requested operation is not valid: Domain already contains a device with the same address
      Reported-by: NSrikanth Aithal <bssrikanth@in.ibm.com>
      Signed-off-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
      Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
      f1d65853
  2. 22 3月, 2019 34 次提交