1. 03 3月, 2014 2 次提交
    • D
      Generate a unique journald log for QEMU capabilities failure · 36ff4ed1
      Daniel P. Berrange 提交于
      When probing QEMU capabilities fails for a binary generate a
      log message with MESSAGE_ID==8ae2f3fb-2dbe-498e-8fbd-012d40afa361.
      
      This can be directly queried from journald based on the UUID
      instead of needing string grep. This lets tools like libguestfs'
      bug reporting tool trivially do automated sanity tests on the
      host they're running on.
      
       $ journalctl MESSAGE_ID=8ae2f3fb-2dbe-498e-8fbd-012d40afa361
       Feb 21 17:11:01 localhost.localdomain lt-libvirtd[9196]:
       Failed to probe capabilities for /bin/qemu-system-alpha:
       internal error: Child process (LC_ALL=C LD_LIBRARY_PATH=
       /home/berrange/src/virt/libvirt/src/.libs PATH=/usr/lib64/
       ccache:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:
       /usr/bin:/root/bin HOME=/root USER=root LOGNAME=root
       /bin/qemu-system-alpha -help) unexpected exit status 127:
       /bin/qemu-system-alpha: error while loading shared libraries:
       libglapi.so.0: cannot open shared object file: No such file
       or directory
      
       $ journalctl MESSAGE_ID=8ae2f3fb-2dbe-498e-8fbd-012d40afa361 --output=json
       { ...snip...
        "LIBVIRT_SOURCE" : "file",
        "PRIORITY" : "3",
        "CODE_FILE" : "qemu/qemu_capabilities.c",
        "CODE_LINE" : "2770",
        "CODE_FUNC" : "virQEMUCapsLogProbeFailure",
        "MESSAGE_ID" : "8ae2f3fb-2dbe-498e-8fbd-012d40afa361",
        "LIBVIRT_QEMU_BINARY" : "/bin/qemu-system-xtensa",
        "MESSAGE" : "Failed to probe capabilities for /bin/qemu-system-xtensa:
         internal error: Child process (LC_ALL=C LD_LIBRARY_PATH=/home/berrange
         /src/virt/libvirt/src/.libs PATH=/usr/lib64/ccache:/usr/local/sbin:
         /usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin HOME=/root
         USER=root LOGNAME=root /bin/qemu-system-xtensa -help) unexpected
         exit status 127: /bin/qemu-system-xtensa: error while loading shared
         libraries: libglapi.so.0: cannot open shared object file: No such
          file or directory\n" }
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      36ff4ed1
    • M
      Bump version to 1.2.3 for new dev cycle · 852582ea
      Michal Privoznik 提交于
      Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
      852582ea
  2. 02 3月, 2014 2 次提交
  3. 01 3月, 2014 12 次提交
    • R
      bhyve: defined domains should be persistent · ae49a093
      Roman Bogorodskiy 提交于
      ae49a093
    • E
      virsh: add --all flag to 'event' command · 0e16ae40
      Eric Blake 提交于
      Similar to our event-test demo program, it's nice to be able to
      have a mode where we can sniff all events at once, rather than
      having to spawn multiple virsh in parallel with one for each
      event type.
      
      (Can I just say our RegisterAny design is lousy?  The fact that
      the majority of our callback pointers have a function signature
      with the opaque data in a different position, and that we have
      to cast the function signature before registering it, makes it
      hard to write a generic callback function; we have to write one
      for every type of event id.  Life would have been easier if we
      had designed the callback as a fixed signature with a void*
      and size parameter, and then allowed the caller to downcast
      the void* to a particular struct for data specific to their
      callback id, where we could have then had a single function
      with a switch statement for each event id, and register that
      one function for all types of events.  It would also be nicer
      if the callback functions knew which callbackID was being used
      when invoking that callback, so that I could use a common data
      structure among all registrations instead of having to create
      an array of one data per callback.  But I really don't want to
      go add yet another event API design.)
      
      * tools/virsh-domain.c (cmdEvent): Add --all parameter; convert
      all callbacks to support shared counter.
      * tools/virsh.pod (event): Document it.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      0e16ae40
    • E
      virsh: support remaining domain events · bb4a9a52
      Eric Blake 提交于
      Earlier, I added 'virsh event' for lifecycle events, to get the
      concept approved; this patch finishes the support for all other
      events, although the user still has to register for one event
      type at a time.  A future patch may add an --all parameter to
      make it possible to register for all events through a single
      call.
      
      * tools/virsh-domain.c (vshDomainEventWatchdogToString)
      (vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
      (vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
      (vshDomainEventDiskChangeToString)
      (vshDomainEventTrayChangeToString, vshEventGenericPrint)
      (vshEventRTCChangePrint, vshEventWatchdogPrint)
      (vshEventIOErrorPrint, vshEventGraphicsPrint)
      (vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
      (vshEventDiskChangePrint, vshEventTrayChangePrint)
      (vshEventPMChangePrint, vshEventBalloonChangePrint)
      (vshEventDeviceRemovedPrint): New helper routines.
      (cmdEvent): Support full array of event callbacks.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      bb4a9a52
    • R
      bhyve: support domain undefine · 91f396b3
      Roman Bogorodskiy 提交于
      Implement domainUndefine and required helper functions:
       - domainIsActive
       - domainIsPersistent
      91f396b3
    • D
      f223b960
    • D
      Include error domain and code in log messages from errors · 0915053e
      Daniel P. Berrange 提交于
      When a virError is raised, pass the error domain and code
      onto the systemd journald using metadata fields.
      
      This allows error messages to be queried by code eg
      
        $ journalctl LIBVIRT_CODE=43
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      0915053e
    • D
      Add docs about use of systemd journal for logging · c6cae570
      Daniel P. Berrange 提交于
      Document the various fields that libvirt will emit for
      journal log records.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      c6cae570
    • D
      Auto-generate the table of contents in logging doc · a9bcd60e
      Daniel P. Berrange 提交于
      The logging doc had a hand-written table of contents
      instead of using the automatic XSL generated one.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      a9bcd60e
    • D
      Fix heading level in logging docs · e86ee41b
      Daniel P. Berrange 提交于
      The logging docs went straight from <h1> to <h3> header level,
      skipping out <h2>.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      e86ee41b
    • D
      Fix journald PRIORITY values · 21d370f0
      Daniel P. Berrange 提交于
      The systemd journal expects log record PRIORITY values to
      be encoded using the syslog compatible numbering scheme,
      not libvirt's own native numbering scheme. We must therefore
      apply a conversion.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      21d370f0
    • D
      Send virLogMetadata fields onto the journal · 54209df3
      Daniel P. Berrange 提交于
      The systemd journal accepts arbitrary user specified log
      fields. These can be passed into virLogMessage via the
      virLogMetadata structure. Allow up to 5 custom fields to
      be reported by libvirt callers.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      54209df3
    • O
      qemu: Enable 'host-passthrough' cpu mode for arm · 97962616
      Oleg Strikov 提交于
      This patch allows libvirt user to specify 'host-passthrough'
      cpu mode while using qemu/kvm backend on arm (arm32).
      It uses 'host' as a CPU model name instead of some other stub
      (correct CPU detection is not implemented yet) to allow libvirt
      user to specify 'host-model' cpu mode as well.
      Signed-off-by: NOleg Strikov <oleg.strikov@canonical.com>
      97962616
  4. 28 2月, 2014 3 次提交
  5. 27 2月, 2014 4 次提交
    • J
      sanlock: Truncate domain names longer than SANLK_NAME_LEN · 8f10c1e7
      Jiri Denemark 提交于
      Libvirt uses a domain name to fill in owner_name in sanlock_options in
      virLockManagerSanlockAcquire. Unfortunately, owner_name is limited to
      SANLK_NAME_LEN characters (including trailing '\0'), which means domains
      with longer names fail to start when sanlock is enabled. However, we can
      truncate the name when setting owner_name as explained by sanlock's
      author:
      
      Setting sanlk_options or the owner_name is unnecessary, and has very
      little to no benefit.  If you do provide something in owner_name, it can
      be anything, sanlock doesn't care or use it.
      
      If you run the command "sanlock status", the output will display a list
      of clients connected to the sanlock daemon.  This client list is
      displayed as "pid owner_name" if the client has provided an owner_name
      via sanlk_options. This debugging output is the only usage of
      owner_name, so its only benefit is to potentially provide a more human
      friendly output for debugging purposes.
      8f10c1e7
    • E
      build: skip virportallocatortest on cygwin · b88606ec
      Eric Blake 提交于
      Cygwin supports <dlfcn.h> and even has limited LD_PRELOAD
      capabilities; but because it does not use ELF binaries it
      cannot support RTLD_NEXT lookups.
      
        CC       libvirportallocatormock_la-virportallocatortest.lo
      virportallocatortest.c: In function 'init_syms':
      virportallocatortest.c:47:24: error: 'RTLD_NEXT' undeclared (first use in this function)
           realsocket = dlsym(RTLD_NEXT, "socket");
      
      * tests/virportallocatortest.c: Also require RTLD_NEXT.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      b88606ec
    • E
      build: ignore cygwin toolchain droppings · 028dd2b8
      Eric Blake 提交于
      The cygwin compiler automatically creates a '*.exe.manifest'
      companion file for any .exe file that contains a substring
      that would otherwise cause newer Windows to pester users about
      needing admin rights (such as "update", "instal", "setup"...).
      This means that compilation on cygwin left behind
      tests/networkxml2xmlupdatetest.exe.manifest.
      
      * .gitignore: Ignore manifest files.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      028dd2b8
    • Y
      maint: Fix minor typo (unkown) · 0e55eb04
      Yuri Chornoivan 提交于
      Signed-off-by: NEric Blake <eblake@redhat.com>
      0e55eb04
  6. 26 2月, 2014 15 次提交
    • I
      libxl: Recognise ARM architectures · bf5dbce6
      Ian Campbell 提交于
      Only tested on v7 but the v8 equivalent seems pretty obvious.
      
      XEN_CAP_REGEX already accepts more than it should (e.g. x86_64p or x86_32be)
      but I have stuck with the existing pattern.
      
      With this I can create a guest from:
        <domain type='xen'>
          <name>libvirt-test</name>
          <uuid>6343998e-9eda-11e3-98f6-77252a7d02f3</uuid>
          <memory>393216</memory>
          <currentMemory>393216</currentMemory>
          <vcpu>1</vcpu>
          <os>
            <type arch='armv7l' machine='xenpv'>linux</type>
            <kernel>/boot/vmlinuz-arm-native</kernel>
            <cmdline>console=hvc0 earlyprintk debug root=/dev/xvda1</cmdline>
          </os>
          <clock offset='utc'/>
          <on_poweroff>destroy</on_poweroff>
          <on_reboot>restart</on_reboot>
          <on_crash>destroy</on_crash>
          <devices>
            <disk type='block' device='disk'>
              <source dev='/dev/marilith-n0/debian-disk'/>
              <target dev='xvda1'/>
            </disk>
            <interface type='bridge'>
              <mac address='8e:a7:8e:3c:f4:f6'/>
              <source bridge='xenbr0'/>
            </interface>
          </devices>
        </domain>
      
      Using virsh create and I can destroy it too.
      
      Currently virsh console fails with:
        Connected to domain libvirt-test
        Escape character is ^]
        error: internal error: cannot find character device <null>
      
      I haven't investigated yet.
      Signed-off-by: NIan Campbell <ian.campbell@citrix.com>
      Signed-off-by: NEric Blake <eblake@redhat.com>
      bf5dbce6
    • P
      spec: Fix braces around macros · 16009667
      Peter Krempa 提交于
      In commit 72f7658b I've added a few
      macros with bad bracing. Although they work as expected fix them so that
      we use uniform syntax.
      16009667
    • M
      virsh: Honour -q in domblklist, vcpupin and emulatorpin · e53b0624
      Michal Privoznik 提交于
      If user wants to grep some info from domain, e.g. disk paths:
      
          # virsh -q domblklist win7 | awk '{print $2}'
          Source
      
          /var/lib/libvirt/images/windows.qcow2
          /home/zippy/work/tmp/en_windows_7_professional_x64_dvd_X15-65805.iso
      
      while with my change:
      
          # virsh -q domblklist win7 | awk '{print $2}'
          /var/lib/libvirt/images/windows.qcow2
          /home/zippy/work/tmp/en_windows_7_professional_x64_dvd_X15-65805.iso
      
      We don't print table header in other commands, like list.
      Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
      e53b0624
    • E
      spec: make systemd_daemon usage configurable · dea81f40
      Eric Blake 提交于
      On Fedora 20, I added this to my '~/.rpmmacros':
      
      %_without_udev 1
      %_without_storage_mpath 1
      %_without_storage_disk 1
      
      and uninstalled systemd-devel (which also removed device-mapper-devel).
      Then I ran 'make rpm', and inspected the results:
      
      $ ldd ~/rpmbuild/BUILD/libvirt-1.2.2/daemon/.libs/libvirtd | grep syst
      $
      
      Then I reinstalled systemd-devel, where I now see:
      
      $ ldd ~/rpmbuild/BUILD/libvirt-1.2.2/daemon/.libs/libvirtd | grep syst
        libsystemd-daemon.so.0 => /lib64/libsystemd-daemon.so.0 (0x00007ffb858ba000)
      $
      
      Oops - the build is non-deterministic, where the final binary
      depends on my build environment.  The fix is to require
      systemd-devel in all situations where the code base uses it.
      Now ~/.rpmmacros can contain "%define _without_systemd_daemon 1"
      to explicitly disable use of the library, but the library is now
      a strict build requirement for normal builds; if systemd-devel
      is not installed, the user now gets an up-front warning:
      
      $ rpmbuild -ta libvirt-1.2.2.tar.gz
      error: Failed build dependencies:
             systemd-devel is needed by libvirt-1.2.2-1.fc20.x86_64
      
      * libvirt.spec.in (with_systemd_daemon): New variable.
      (BuildRequires): Require systemd-devel for more than just udev.
      (%configure): Make choice of systemd_daemon explicit.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      dea81f40
    • E
      spec: require device-mapper-devel for storage-disk · 7cac3afa
      Eric Blake 提交于
      On Fedora 20, with the following in my ~/.rpmmacros:
      
      %_without_udev 1
      %_without_storage_mpath 1
      
      and with device-mapper-devel uninstalled, 'make rpm' fails with:
      
      checking for libdevmapper.h... no
      configure: error: You must install device-mapper-devel/libdevmapper >= 1.0.0 to compile libvirt
      error: Bad exit status from /var/tmp/rpm-tmp.Wo9pOG (%build)
      
      This is a rather late point to be issuing an error; better is
      to flag missing packages up front.  The fix is to match the logic
      in configure.ac on when devmapper is required (for both mpath and
      storage).  While at it, rbd storage is not dependent on mpath.
      With this patch applied, I now get:
      
      $ rpmbuild -ta libvirt-1.2.2.tar.gz
      error: Failed build dependencies:
             device-mapper-devel is needed by libvirt-1.2.2-1.fc20.x86_64
      
      until either installing the package or further modifying
      ~/.rpmmacros to add "%_without_storage_disk 1".
      
      * libvirt.spec.in (BuildRequires): Fix build when mpath is
      disabled.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      7cac3afa
    • E
      spec: explicitly avoid bhyve on Linux · fa293998
      Eric Blake 提交于
      Generally, we try to make the spec file tweakable via user
      variables, so that they can select a different subset of sub-rpms
      to build.  We also try to explicitly list all driver config
      options, rather than leaving the chance that the rpm build may be
      non-deterministic based on what the user had installed locally.
      But in the case of the recent bhyve hypervisor driver, there is
      no port of bhyve to Linux, so it is easier to just blindly
      disable it for now.  If someone ever does try to port bhyve to
      Fedora, we can make the spec file conditional at that point.
      
      * libvirt.spec.in (%configure): Don't try to build bhyve.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      fa293998
    • E
      build: use --with-systemd-daemon as configure option · 25034b3c
      Eric Blake 提交于
      Commit 68954fb2 added a configure option --with-systemd_daemon,
      which violates the conventions of configure files preferring
      dash in all option names.  This fixes it, before we hit a
      release where the tarball is baked with an awkward name.
      
      * m4/virt-lib.m4 (LIBVIRT_CHECK_LIB, LIBVIRT_CHECK_LIB_ALT)
      (LIBVIRT_CHECK_PKG): Favor - over _ in configure option names.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      25034b3c
    • P
      spec: Use correct versions of libgfapi in RHEL builds · 72f7658b
      Peter Krempa 提交于
      RHEL still uses the 3.4.0 package of libgfapi and the package is built
      only for x86_64.
      72f7658b
    • L
      network: unplug bandwidth and call networkRunHook only when appropriate · eed46d4c
      Laine Stump 提交于
      According to commit b4e0299d if networkAllocateActualDevice() was
      successful, it will *always* allocate an iface->data.network.actual,
      so we can use this during networkReleaseActualDevice() to know if
      there is really anything to undo. We were properly using this
      information to only decrement the network connections counter if it
      had previously been incremented, but we were unconditionally
      unplugging bandwidth and calling the "unplugged" network hook for
      *all* interfaces (during qemuProcessStop()) whether they had been
      previously plugged or not. This caused problems if a domain failed to
      start at some time prior to all interfaces being allocated. (I
      encountered this when an interface had a bandwidth floor set but no
      inbound QoS).
      
      This patch changes both the call to networkUnplugBandwidth() and the
      call to networkRunHook() to only be called if there was a previous
      call to "plug" for the same interface.
      eed46d4c
    • L
      network: don't even call networkRunHook if there is no network · 0700a3da
      Laine Stump 提交于
      networkAllocateActualDevice() is called for *all* interfaces, not just
      those with type='network'. In that case, it will jump down to its
      validate: label immediately, without allocating anything. After
      validation is done, two counters are potentially updated (one for the
      network, and one for any particular physical device that is chosen),
      and then networkRunHook() is called.
      
      This patch refactors that code a slight bit so that networkRunHook()
      doesn't get called if netdef is NULL (i.e. type != network) and to
      place the conditional increment of dev->connections inside the "if
      (netdef)" as well - dev can never be non-null if netdef is null
      (because "dev" is the pointer to a device in a network's pool of
      devices), so this doesn't have any functional effect, it just makes
      the code clearer.
      0700a3da
    • N
      Fix memory leak in virSCSIDeviceListDel() · 969493f9
      Nehal J Wani 提交于
      While running virscsitest, it was found that valgrind pointed out the following
      memory leak:
      
      ==320== 5 bytes in 1 blocks are definitely lost in loss record 4 of 37
      ==320==    at 0x4A069EE: malloc (vg_replace_malloc.c:270)
      ==320==    by 0x3E6CE81171: strdup (strdup.c:43)
      ==320==    by 0x4CB28DF: virStrdup (virstring.c:554)
      ==320==    by 0x4CAC987: virSCSIDeviceSetUsedBy (virscsi.c:289)
      ==320==    by 0x402321: test2 (virscsitest.c:100)
      ==320==    by 0x403231: virtTestRun (testutils.c:199)
      ==320==    by 0x402121: mymain (virscsitest.c:180)
      ==320==    by 0x4039AD: virtTestMain (testutils.c:782)
      ==320==    by 0x3E6CE1ED1C: (below main) (libc-start.c:226)
      ==320==
      
      Introduced by commit fd243fc4.
      Signed-off-by: NJán Tomko <jtomko@redhat.com>
      969493f9
    • M
      virNetDevVethCreate: Serialize callers · c0d162c6
      Michal Privoznik 提交于
      Consider dozen of LXC domains, each of them having this type of interface:
      
          <interface type='network'>
            <mac address='52:54:00:a7:05:4b'/>
            <source network='default'/>
          </interface>
      
      When starting these domain in parallel, all workers may meet in
      virNetDevVethCreate() where a race starts. Race over allocating veth
      pairs because allocation requires two steps:
      
        1) find first nonexistent '/sys/class/net/vnet%d/'
        2) run 'ip link add ...' command
      
      Now consider two threads. Both of them find N as the first unused veth
      index but only one of them succeeds allocating it. The other one fails.
      For such cases, we are running the allocation in a loop with 10 rounds.
      However this is very flaky synchronization. It should be rather used
      when libvirt is competing with other process than when libvirt threads
      fight each other. Therefore, internally we should use mutex to serialize
      callers, and do the allocation in loop (just in case we are competing
      with a different process). By the way we have something similar already
      since 1cf97c87.
      Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
      c0d162c6
    • E
      build: avoid ld_preload tests on mingw · f2dc1f67
      Eric Blake 提交于
      Running ./autobuild.sh complained during the mingw cross-compile:
      
        CC       libvirportallocatormock_la-virportallocatortest.lo
      ../../tests/virportallocatortest.c:32:20: fatal error: dlfcn.h: No such file or directory
       # include <dlfcn.h>
                          ^
      compilation terminated.  With that fixed, the next failure was:
      
        CCLD     qemuxml2argvmock.la
      libtool: link: libtool library `qemuxml2argvmock.la' must begin with `lib'
      libtool: link: Try `libtool --help --mode=link' for more information.
      
      While we don't need to limit all LD_PRELOAD tests to just Linux, we
      do need to limit them to platforms that actually support loading;
      we also need to avoid building qemu tests when qemu is not enabled.
      
      * tests/virportallocatortest.c: Make conditional on <dlfcn.h>.
      * tests/Makefile.am (test_libraries): Only build qemu mock library
      when building qemu tests.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      f2dc1f67
    • E
      build: fix cgroups on non-Linux · fa2e4dbf
      Eric Blake 提交于
      Running ./autobuild.sh detected a mingw failure:
      
        CCLD     libvirt.la
      Cannot export virCgroupGetPercpuStats: symbol not defined
      Cannot export virCgroupSetOwner: symbol not defined
      
      * src/util/vircgroup.c (virCgroupGetPercpuStats)
      (virCgroupSetOwner): Implement stubs.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      fa2e4dbf
    • J
      libxl: queue domain event earlier in shutdown handler · 4d975ded
      Jim Fehlig 提交于
      The shutdown handler may restart a domain when handling a reboot
      event or when <on_*> is set to 'restart'.  Restarting consists of
      calling libxlVmCleanup followed by libxlVmStart.  libxlVmStart will
      emit a VIR_DOMAIN_EVENT_STARTED event, but the SHUTDOWN event is
      not emitted until exiting the shutdown handler, after the STARTED
      event.
      
      This patch changes the logic a bit to queue the event at the start
      of the shutdown action, ensuring it is queued before any subsequent
      events that may be generated while executing the shutdown action.
      Signed-off-by: NJim Fehlig <jfehlig@suse.com>
      4d975ded
  7. 25 2月, 2014 2 次提交
    • L
      network: include plugged interface XML in "plugged" network hook · 2122cf39
      Laine Stump 提交于
      The network hook script gets called whenever an interface is plugged
      into or unplugged from a network, but even though the full XML of both
      the network and the domain is included, there is no reasonable way to
      determine what exact resources the plugged interface is using:
      
      1) Prior to a recent patch which modified the status XML of interfaces
      to include the information about actual hardware resources used, it
      would be possible to scan through the domain XML output sent to the
      hook, and from there find the correct interface, but that interface
      definition would not include any runtime info (e.g. bandwidth or vlan
      taken from a portgroup, or which physdev was used in case of a macvtap
      network).
      
      2) After the patch modifying the status XML of interfaces, the network
      name would no longer be included in the domain XML, so it would be
      completely impossible to determine which interface was the one being
      plugged.
      
      To solve that problem, this patch includes a single <interface>
      element at the beginning of the XML sent to the network hook for
      "plugged" and "unplugged" (just inside <hookData>) that is the status
      XML of the interface being plugged. This XML will include all info
      gathered from the chosen network and portgroup.
      
      NB: due to hardcoded spaces in all of the device *Format() functions,
      the <interface> element inside the <hookData> will be indented by 6
      spaces rather than 2. I had intended to fix this, but it turns out
      that to make virDomainNetDefFormat() indentation relative, I would
      have to do the same to virDomainDeviceInfoFormat(), and that function
      is called from 19 places - making that a prerequisite of this patch
      would cause too many merge difficulties if we needed to backport
      network hooks, so I chose to ignore the problem here and fix the
      problem for *all* devices in a followup later.
      2122cf39
    • L
      conf: output actual netdev status in <interface> XML · 7d5bf484
      Laine Stump 提交于
      Until now, the "live" XML status of an <interface type='network'>
      device would always show the network information, rather than the
      exact hardware device that was used. It would also show the name of
      any portgroup the interface belonged to, rather than providing the
      configuration that was derived from that portgroup. As an example,
      given the following network definition:
      
      [A]
        <network>
          <name>testnet</name>
          <forward type='bridge' dev='p4p1_0'>
            <interface dev='p4p1_0'/>
            <interface dev='p4p1_1'/>
            <interface dev='p4p1_2'/>
            <interface dev='p4p1_3'/>
          </forward>
          <portgroup name='admin'>
            <bandwidth>
                <inbound average='1000' peak='5000' burst='1024'/>
                <outbound average='128' peak='256' burst='256'/>
            </bandwidth>
          </portgroup>
        </network>
      
      and the following domain <interface>:
      
      [B]
        <interface type='network'>
          <source network='testnet' portgroup='admin'/>
        </interface>
      
      the output of "virsh dumpxml $domain" while the domain was running
      would yield something like this:
      
      [C]
        <interface type='network'>
          <source network='testnet' portgroup='admin'/>
          <target dev='macvtap0'/>
          <alias name='net0'/>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
        </interface>
      
      In order to learn the exact bandwidth information of the interface, a
      management application would need to retrieve the XML for testnet,
      then search for the portgroup named "admin". Even worse, there was no
      simple and standard way to learn which host physdev the macvtap0
      device is attached to.
      
      Internally, libvirt has always kept this information in the
      virDomainDef that is held in memory, as well as storing it in the
      (libvirt-internal-only) domain status XML (in
      /var/run/libvirt/qemu/$domain.xml). In order to not confuse the runtime
      "actual state" with the config of the device, it's internally stored
      like this:
      
      [D]
        <interface type='network'>
          <source network='testnet' portgroup='admin'/>
          <actual type='direct'>
            <source dev='p4p1_0' mode='bridge'/>
            <bandwidth>
                <inbound average='1000' peak='5000' burst='1024'/>
                <outbound average='128' peak='256' burst='256'/>
            </bandwidth>
          </actual>
          <target dev='macvtap0'/>
          <alias name='net0'/>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
        </interface>
      
      This was never exposed outside of libvirt though, because I thought it
      would be too awkward for a management application to need to look in
      two places for the same information, but I also wasn't sure that it
      would be okay to overwrite the config info (in this case "<source
      network='testnet' portgroup='admin'/>") with the actual runtime info
      (everything inside <actual> above).
      
      Now we have a need for this information to be made available to
      management applications (in particular, so that a network "plugged"
      hook will have full information about the device that is being plugged
      in), so it's time to take the leap and decide that it is acceptable
      for the config info to be replaced with actual runtime state (but
      *only* when reporting domain live status, *not* when saving state in
      /var/run/libvirt/qemu/$domain.xml - that remains the same so that
      there is no loss of information). That is what this patch does - once
      applied, the output of "virsh dumpxml $domain" when the domain is
      running will contain something like this:
      
      [E]
        <interface type='direct'>
          <source dev='p4p1_0' mode='bridge'/>
          <bandwidth>
              <inbound average='1000' peak='5000' burst='1024'/>
              <outbound average='128' peak='256' burst='256'/>
          </bandwidth>
          <target dev='macvtap0'/>
          <alias name='net0'/>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
        </interface>
      
      In effect, everything that is internally stored within <actual> is
      moved up a level to where a management application will expect
      it. This means that the management application will only look in a
      single place to learn - the type of interface in use, the name of the
      physdev (if relevant), the <bandwidth>, <vlan>, and <virtualport>
      settings in use.
      
      The potential downside is that a management app looking at this output
      will not see that the physdev 'p4p1_0' was actually allocated from the
      network named 'testnet', or that the bandwidth numbers were taken from
      the portgroup 'admin'. However, if they are interested in that info,
      they can always get the "inactive" XML for the domain.
      
      An example of where this could cause problems is in virt-manager's
      network device display, which shows the status of the device, but
      allows you to edit that status info and save it as the new
      config. Previously virt-manager would always display the information
      in example [C] above, and allow editing that. With this patch, it will
      instead display what is in [E] and allow editing it directly, which
      could lead to some confusion. I would suggest that virt-manager have
      an "edit" button which would change the display from the "live" xml to
      the "inactive" xml, so that editing would be done on that; such a
      change would both handle the new situation, and also be compatible
      with older releases.
      7d5bf484