1. 09 3月, 2012 12 次提交
    • L
      util: consolidate duplicated error messages in pci.c · b8e47850
      Laine Stump 提交于
      This is nearly identical to an earlier patch for virnetlink.c.
      
      There are special stub versions of all public functions in this file
      that are compiled when the platform isn't linux. Each of these
      functions had an almost identical message, differing only in the
      function name included in the message. Since log messages already
      contain the function name, we can just define a const char* with the
      common part of the string, and use that same string for all the log
      messages.
      
      If nothing else, this at least makes for less strings that need
      translating...
      b8e47850
    • L
      qemu: eliminate memory leak in qemuDomainUpdateDeviceConfig · 7a23ba09
      Laine Stump 提交于
      This function was freeing a virDomainNetDef with
      VIR_FREE(). virDomainNetDef is a complex structure with many pointers
      to other dynamically allocated data; to properly free it
      virDomainNetDefFree() must be called instead, otherwise several
      strings (and potentially other things) will be leaked.
      7a23ba09
    • L
      qemu: support persistent hotplug of <hostdev> devices · edb6fc3a
      Laine Stump 提交于
      For some reason, although live hotplug of <hostdev> devices is
      supported, persistent hotplug is not. This patch adds the proper
      VIR_DOMAIN_DEVICE_HOSTDEV cases to the switches in
      qemuDomainAttachDeviceConfig and qemuDomainDetachDeviceConfig.
      edb6fc3a
    • L
      util: standardize return from functions calling virNetlinkCommand · 0208face
      Laine Stump 提交于
      There are several functions that call virNetlinkCommand, and they all
      follow a common pattern, with three exit labels: err_exit (or
      cleanup), malformed_resp, and buffer_too_small. All three of these
      labels do their own cleanup and have their own return. However, the
      malformed_resp label usually frees the same items as the
      cleanup/err_exit label, and the buffer_too_small label just doesn't
      free recvbuf (because it's known to always be NULL at the time we goto
      buffer_too_small.
      
      In order to simplify and standardize the code, I've made the following
      changes to all of these functions:
      
      1) err_exit is replaced with the more libvirt-ish "cleanup", which
         makes sense because in all cases this code is also executed in the
         case of success, so labelling it err_exit may be confusing.
      
      2) rc is initialized to -1, and set to 0 just before the cleanup
         label. Any code that currently sets rc = -1 is made to instead goto
         cleanup.
      
      3) malformed_resp and buffer_too_small just log their error and goto
         cleanup. This gives us a single return path, and a single place to
         free up resources.
      
      4) In one instance, rather then logging an error immediately, a char*
         msg was pointed to an error string, then goto cleanup (and cleanup
         would log an error if msg != NULL). It takes no more lines of code
         to just log the message as we encounter it.
      
      This patch should have 0 functional effects.
      0208face
    • L
      util: eliminate device object leaks related to virDomain*Remove*() · f985773d
      Laine Stump 提交于
      There are several functions in domain_conf.c that remove a device
      object from the domain's list of that object type, but don't free the
      object or return it to the caller to free. In many cases this isn't a
      problem because the caller already had a pointer to the object and
      frees it afterward, but in several cases the removed object was just
      left floating around with no references to it.
      
      In particular, the function qemuDomainDetachDeviceConfig() calls
      functions to locate and remove net (virDomainNetRemoveByMac), disk
      (virDomainDiskRemoveByName()), and lease (virDomainLeaseRemove())
      devices, but neither it nor its caller qemuDomainModifyDeviceConfig()
      ever obtain a pointer to the device being removed, much less free it.
      
      This patch modifies the following "remove" functions to return a
      pointer to the device object being removed from the domain device
      arrays, to give the caller the option of freeing the device object
      using that pointer if needed. In places where the object was
      previously leaked, it is now freed:
      
        virDomainDiskRemove
        virDomainDiskRemoveByName
        virDomainNetRemove
        virDomainNetRemoveByMac
        virDomainHostdevRemove
        virDomainLeaseRemove
        virDomainLeaseRemoveAt
      
      The functions that had been leaking:
      
        libxlDomainDetachConfig - leaked a virDomainDiskDef
        qemuDomainDetachDeviceConfig - could leak a virDomainDiskDef,
                                  a virDomainNetDef, or a
                                  virDomainLeaseDef
        qemuDomainDetachLease   - leaked a virDomainLeaseDef
      f985773d
    • L
      qemu: don't 'remove' hostdev objects from domain if operation fails · b59e5984
      Laine Stump 提交于
      There were certain paths through the hostdev detach code that could
      lead to the lower level function failing (and not removing the object
      from the domain's hostdevs list), but the higher level function
      free'ing the hostdev object anyway. This would leave a stale
      hostdevdef pointer in the list, which would surely cause a problem
      eventually.
      
      This patch relocates virDomainHostdevRemove from the lower level
      functions qemuDomainDetachThisHostDevice and
      qemuDomainDetachHostPciDevice, to their caller
      qemuDomainDetachThisHostDevice, placing it just before the call to
      virDomainHostdevDefFree. This makes it easy to verify that either both
      operations are done, or neither.
      
      NB: The "dangling pointer" part of this problem was introduced in
      commit 13d5a6, so it is not present in libvirt versions prior to
      0.9.9. Earlier versions would return failure in certain cases even
      though the the device object was removed/deleted, but the removal and
      deletion operations would always both happen or neither.
      b59e5984
    • L
      util: make virDomainLeaseDefFree global · 8845d293
      Laine Stump 提交于
      It will be used in a different file in an upcoming patch.
      8845d293
    • L
      util: consolidate duplicated error messages in virnetlink.c · 879bcee0
      Laine Stump 提交于
      There are special stub versions of all public functions in this file
      that are compiled when either libnl isn't available or the platform
      isn't linux. Each of these functions had two almost identical message,
      differing only in the function name included in the message. Since log
      messages already contain the function name, we can just define a const
      char* with the common part of the string, and use that same string for
      all the log messages.
      
      Also, rather than doing #if defined ... #else ... #endif *inside the
      error log macro invocation*, this patch does #if defined ... just
      once, using it to decide which single string to define. This turns the
      error log in each function from 6 lines, to 1 line.
      879bcee0
    • L
      util: log error on OOM in virNetDevOpenvswitchAddPort · d403b84c
      Laine Stump 提交于
      OOM conditions silently returned failure.
      d403b84c
    • A
      Attach vm-id to Open vSwitch interfaces. · ac8bbdbd
      Ansis Atteka 提交于
      This patch will allow OpenFlow controllers to identify which interface
      belongs to a particular VM by using the Domain UUID.
      
      ovs-vsctl get Interface vnet0 external_ids
      {attached-mac="52:54:00:8C:55:2C", iface-id="83ce45d6-3639-096e-ab3c-21f66a05f7fa", iface-status=active, vm-id="142a90a7-0acc-ab92-511c-586f12da8851"}
      
      V2 changes:
      Replaced vm-uuid with vm-id. There was a discussion in Open vSwitch
      mailinglist that we should stick with the same DB key postfixes for the
      sake of consistency (e.g iface-id, vm-id ...).
      ac8bbdbd
    • L
      util: whitespace change to virNetDevOpenvswitchAddPort · 38e56abb
      Laine Stump 提交于
      The indentation on the final lines of the function was off by four
      spaces, making me wonder for a second if there was something
      missing. (There wasn't.)
      38e56abb
    • L
      util: add stub pciConfigAddressToSysfsFile for non-linux platforms · 09d22af1
      Laine Stump 提交于
      Absence of this stub function caused a build failure on mingw32.
      09d22af1
  2. 08 3月, 2012 16 次提交
    • E
      rpc: generalize solution for VPATH builds · 4d2e8355
      Eric Blake 提交于
      Commit 5d4b0c4c tried to fix certain classes of VPATH builds,
      but was too limited.  In particular, Guannan Ren reported:
      
      >    For example: The libvirt source code resides in /home/testuser,
      >                 I make dist in /tmp/buildvpath, the XDR routine .c file will
      >                 include full path of the header file like:
      >
      >                 #include "/home/testuser/src/rpc/virnetprotocol.h"
      >                 #include "internal.h"
      >                 #include <arpa/inet.h>
      >
      >    If we distribute the tarball to another machine to compile,
      >    it will report error as follows:
      >
      >    rpc/virnetprotocol.c:7:59: fatal error:
      >    /home/testuser/src/rpc/virnetprotocol.h: No such file or directory
      
      * src/rpc/genprotocol.pl: Fix more include lines.
      4d2e8355
    • M
      util: Don't overflow on errno in virFileAccessibleAs · f05fb6c5
      Michal Privoznik 提交于
      If we need to virFork() to check assess() under different
      UID+GID we need to translate returned status via WEXITSTATUS().
      Otherwise, we may return values greater than 255 which is
      obviously wrong.
      f05fb6c5
    • P
      sanlock: Use STREQ_NULLABLE instead of STREQ on strings that may be null · 96b41f63
      Peter Krempa 提交于
      The function sanlock_inquire can return NULL in the state string if the
      message consists only of a header. The return value is arbitrary and
      sent by the server. We should proceed carefully while touching such
      pointers.
      96b41f63
    • P
      sanlock: Fix condition left crippled while debugging · 3bf5f042
      Peter Krempa 提交于
      3bf5f042
    • M
      qemu: Don't parse device twice in attach/detach · 1e0534a7
      Michal Privoznik 提交于
      Some members are generated during XML parse (e.g. MAC address of
      an interface); However, with current implementation, if we
      are plugging a device both to persistent and live config,
      we parse given XML twice: first time for live, second for config.
      This is wrong then as the second time we are not guaranteed
      to generate same values as we did for the first time.
      To prevent that we need to create a copy of DeviceDefPtr;
      This is done through format/parse process instead of writing
      functions for deep copy as it is easier to maintain:
      adding new field to any virDomain*DefPtr doesn't require change
      of copying function.
      1e0534a7
    • M
      qemu: Fix startupPolicy for snapshot-revert · b819b3b7
      Michal Privoznik 提交于
      Currently, startupPolicy='requisite' was determining cold boot
      by migrateFrom != NULL. That means, if domain was started up
      with migrateFrom set we didn't require disk source path and allowed
      it to be dropped. However, on snapshot-revert domain wasn't migrated
      but according to documentation, requisite should drop disk source
      as well.
      b819b3b7
    • E
      xml: allow scaled memory on input · 2e22f23b
      Eric Blake 提交于
      Output is still in kibibytes, but input can now be in different
      scales for ease of typing.
      
      * src/conf/domain_conf.c (virDomainParseMemory): New helper.
      (virDomainDefParseXML): Use it when parsing.
      * docs/schemas/domaincommon.rng: Expand XML; rename memoryKBElement
      to memoryElement and update callers.
      * docs/formatdomain.html.in (elementsMemoryAllocation): Document
      scaling.
      * tests/qemuxml2argvdata/qemuxml2argv-memtune.xml: Adjust test.
      * tests/qemuxml2xmltest.c: Likewise.
      * tests/qemuxml2xmloutdata/qemuxml2xmlout-memtune.xml: New file.
      2e22f23b
    • E
      xml: use better types for memory values · 4888f0fb
      Eric Blake 提交于
      Using 'unsigned long' for memory values is risky on 32-bit platforms,
      as a PAE guest can have more than 4GiB memory.  Our API is
      (unfortunately) locked at 'unsigned long' and a scale of 1024, but
      the rest of our system should consistently use 64-bit values,
      especially since the previous patch centralized overflow checking.
      
      * src/conf/domain_conf.h (_virDomainDef): Always use 64-bit values
      for memory.  Change hugepage_backed to a bool.
      * src/conf/domain_conf.c (virDomainDefParseXML)
      (virDomainDefCheckABIStability, virDomainDefFormatInternal): Fix
      clients.
      * src/vmx/vmx.c (virVMXFormatConfig): Likewise.
      * src/xenxs/xen_sxpr.c (xenParseSxpr, xenFormatSxpr): Likewise.
      * src/xenxs/xen_xm.c (xenXMConfigGetULongLong): New function.
      (xenXMConfigGetULong, xenXMConfigSetInt): Avoid truncation.
      (xenParseXM, xenFormatXM): Fix clients.
      * src/phyp/phyp_driver.c (phypBuildLpar): Likewise.
      * src/openvz/openvz_driver.c (openvzDomainSetMemoryInternal):
      Likewise.
      * src/vbox/vbox_tmpl.c (vboxDomainDefineXML): Likewise.
      * src/qemu/qemu_command.c (qemuBuildCommandLine): Likewise.
      * src/qemu/qemu_process.c (qemuProcessStart): Likewise.
      * src/qemu/qemu_monitor.h (qemuMonitorGetBalloonInfo): Likewise.
      * src/qemu/qemu_monitor_text.h (qemuMonitorTextGetBalloonInfo):
      Likewise.
      * src/qemu/qemu_monitor_text.c (qemuMonitorTextGetBalloonInfo):
      Likewise.
      * src/qemu/qemu_monitor_json.h (qemuMonitorJSONGetBalloonInfo):
      Likewise.
      * src/qemu/qemu_monitor_json.c (qemuMonitorJSONGetBalloonInfo):
      Likewise.
      * src/qemu/qemu_driver.c (qemudDomainGetInfo)
      (qemuDomainGetXMLDesc): Likewise.
      * src/uml/uml_conf.c (umlBuildCommandLine): Likewise.
      4888f0fb
    • E
      xml: use long long internally, to centralize overflow checks · 73b99771
      Eric Blake 提交于
      On 64-bit platforms, unsigned long and unsigned long long are
      identical, so we don't have to worry about overflow checks.
      On 32-bit platforms, anywhere we narrow unsigned long long back
      to unsigned long, we have to worry about overflow; it's easier
      to do this in one place by having most of the code use the same
      or wider types, and only doing the narrowing at the last minute.
      Therefore, the memory set commands remain unsigned long, and
      the memory get command now centralizes the overflow check into
      libvirt.c, so that drivers don't have to repeat the work.
      
      This also fixes a bug where xen returned the wrong value on
      failure (most APIs return -1 on failure, but getMaxMemory
      must return 0 on failure).
      
      * src/driver.h (virDrvDomainGetMaxMemory): Use long long.
      * src/libvirt.c (virDomainGetMaxMemory): Raise overflow.
      * src/test/test_driver.c (testGetMaxMemory): Fix driver.
      * src/rpc/gendispatch.pl (name_to_ProcName): Likewise.
      * src/xen/xen_hypervisor.c (xenHypervisorGetMaxMemory): Likewise.
      * src/xen/xen_driver.c (xenUnifiedDomainGetMaxMemory): Likewise.
      * src/xen/xend_internal.c (xenDaemonDomainGetMaxMemory):
      Likewise.
      * src/xen/xend_internal.h (xenDaemonDomainGetMaxMemory):
      Likewise.
      * src/xen/xm_internal.c (xenXMDomainGetMaxMemory): Likewise.
      * src/xen/xm_internal.h (xenXMDomainGetMaxMemory): Likewise.
      * src/xen/xs_internal.c (xenStoreDomainGetMaxMemory): Likewise.
      * src/xen/xs_internal.h (xenStoreDomainGetMaxMemory): Likewise.
      * src/xenapi/xenapi_driver.c (xenapiDomainGetMaxMemory):
      Likewise.
      * src/esx/esx_driver.c (esxDomainGetMaxMemory): Likewise.
      * src/libxl/libxl_driver.c (libxlDomainGetMaxMemory): Likewise.
      * src/qemu/qemu_driver.c (qemudDomainGetMaxMemory): Likewise.
      * src/lxc/lxc_driver.c (lxcDomainGetMaxMemory): Likewise.
      * src/uml/uml_driver.c (umlDomainGetMaxMemory): Likewise.
      73b99771
    • E
      xml: drop unenforced minimum memory limit from RNG · 1b1402b9
      Eric Blake 提交于
      The test domain allows <memory>0</memory>, but the RNG was stating
      that memory had to be at least 4096000 bytes.  Hypervisors should
      enforce their own limits, rather than complicating the RNG.
      
      Meanwhile, some copy and paste had introduced some fishy constructs
      in various unit tests.
      
      * docs/schemas/domaincommon.rng (memoryKB, memoryKBElement): Drop
      limit that isn't enforced in code.
      * src/conf/domain_conf.c (virDomainDefParseXML): Require current
      <= maximum.
      * tests/qemuxml2argvdata/*.xml: Fix offenders.
      1b1402b9
    • E
      storage: support more scaling suffixes · 2e148612
      Eric Blake 提交于
      Disk manufacturers are fond of quoting sizes in powers of 10,
      rather than powers of 2 (after all, 2.1 GB sounds larger than
      2.0 GiB, even though the exact opposite is true).  So, we might
      as well follow coreutils' lead in supporting three types of
      suffix: single letter ${u} (which we already had) and ${u}iB
      for the power of 2, and ${u}B for power of 10.
      
      Additionally, it is impossible to create a file with more than
      2**63 bytes, since off_t is signed (if you have enough storage
      to even create one 8EiB file, I'm jealous).  This now reports
      failure up front rather than down the road when the kernel
      finally refuses an impossible size.
      
      * docs/schemas/basictypes.rng (unit): Add suffixes.
      * src/conf/storage_conf.c (virStorageSize): Use new function.
      * docs/formatstorage.html.in: Document it.
      * tests/storagevolxml2xmlin/vol-file-backing.xml: Test it.
      * tests/storagevolxml2xmlin/vol-file.xml: Likewise.
      2e148612
    • E
      xml: output memory unit for clarity · 26545784
      Eric Blake 提交于
      Make it obvious to 'dumpxml' readers what unit we are using,
      since our default of KiB for memory (1024) differs from qemu's
      default of MiB; and differs from our use of bytes for storage.
      
      Tests were updated via:
      
      $ find tests/*data tests/*out -name '*.xml' | \
        xargs sed -i 's/<\(memory\|currentMemory\|hard_limit\|soft_limit\|min_guarantee\|swap_hard_limit\)>/<\1 unit='"'KiB'>/"
      $ find tests/*data tests/*out -name '*.xml' | \
        xargs sed -i 's/<\(capacity\|allocation\|available\)>/<\1 unit='"'bytes'>/"
      
      followed by a few fixes for the stragglers.
      
      Note that with this patch, the RNG for <memory> still forbids
      validation of anything except unit='KiB', since the code silently
      ignores the attribute; a later patch will expand <memory> to allow
      scaled input in the code and update the RNG to match.
      
      * docs/schemas/basictypes.rng (unit): Add 'bytes'.
      (scaledInteger): New define.
      * docs/schemas/storagevol.rng (sizing): Use it.
      * docs/schemas/storagepool.rng (sizing): Likewise.
      * docs/schemas/domaincommon.rng (memoryKBElement): New define; use
      for memory elements.
      * src/conf/storage_conf.c (virStoragePoolDefFormat)
      (virStorageVolDefFormat): Likewise.
      * src/conf/domain_conf.h (_virDomainDef): Document unit used
      internally.
      * src/conf/storage_conf.h (_virStoragePoolDef, _virStorageVolDef):
      Likewise.
      * tests/*data/*.xml: Update all tests.
      * tests/*out/*.xml: Likewise.
      * tests/define-dev-segfault: Likewise.
      * tests/openvzutilstest.c (testReadNetworkConf): Likewise.
      * tests/qemuargv2xmltest.c (blankProblemElements): Likewise.
      26545784
    • E
      util: new function for scaling numbers · 0d90823e
      Eric Blake 提交于
      Scaling an integer based on a suffix is something we plan on reusing
      in several contexts: XML parsing, virsh CLI parsing, and possibly
      elsewhere.  Make it easy to reuse, as well as adding in support for
      powers of 1000.
      
      * src/util/util.h (virScaleInteger): New function.
      * src/util/util.c (virScaleInteger): Implement it.
      * src/libvirt_private.syms (util.h): Export it.
      0d90823e
    • E
      api: add overflow error · 239fb8c4
      Eric Blake 提交于
      Overflow can be user-induced, so it deserves more than being called
      an internal error.  Note that in general, 32-bit platforms have
      far more places to trigger this error (anywhere the public API
      used 'unsigned long' but the other side of the connection is a
      64-bit server); but some are possible on 64-bit platforms (where
      the public API computes the product of two numbers).
      
      * include/libvirt/virterror.h (VIR_ERR_OVERFLOW): New error.
      * src/util/virterror.c (virErrorMsg): Translate it.
      * src/libvirt.c (virDomainSetVcpusFlags, virDomainGetVcpuPinInfo)
      (virDomainGetVcpus, virDomainGetCPUStats): Use it.
      * daemon/remote.c (HYPER_TO_TYPE): Likewise.
      * src/qemu/qemu_driver.c (qemuDomainBlockResize): Likewise.
      239fb8c4
    • E
      docs: use correct terminology for 1024 bytes · 9dfdeadc
      Eric Blake 提交于
      Yes, I like kilobytes better than kibibytes (when I say kilobytes,
      I generally mean 1024).  But since the term is ambiguous, it can't
      hurt to say what we mean, by using both the correct name and
      calling out the numeric equivalent.
      
      * src/libvirt.c (virDomainGetMaxMemory, virDomainSetMaxMemory)
      (virDomainSetMemory, virDomainSetMemoryFlags)
      (virNodeGetFreeMemory): Tweak wording.
      * docs/formatdomain.html.in: Likewise.
      * docs/formatstorage.html.in: Likewise.
      9dfdeadc
    • L
      util: fix build mingw (and all non-linux) build failure · 861707b9
      Laine Stump 提交于
      ATTRIBUTE_UNUSED was accidentally forgotten on one arg of a stub
      function for functionality that's not present on non-linux
      platforms. This causes a non-linux build with
      --enable-compile-warnings=error to fail.
      861707b9
  3. 07 3月, 2012 6 次提交
  4. 06 3月, 2012 6 次提交
    • R
      qemu: install port profile and mac address on netdev hostdevs · ce43483c
      Roopa Prabhu 提交于
      These changes are applied only if the hostdev has a parent net device
      (i.e. if it was defined as "<interface type='hostdev'>" rather than
      just "<hostdev>").  If the parent netdevice has virtual port
      information, the original virtualport associate functions are called
      (these set and restore both mac and port profile on an
      interface). Otherwise, only mac address is set on the device.
      
      Note that This is only supported for SR-IOV Virtual Functions (not for
      standard PCI or USB netdevs), and virtualport association is only
      supported for 802.1Qbh. For all other types of cards and types of
      virtualport, a "Config Unsupported" error is returned and the
      operation fails.
      Signed-off-by: NRoopa Prabhu <roprabhu@cisco.com>
      ce43483c
    • R
      util: Changes to support portprofiles for hostdevs · 15bbfd83
      Roopa Prabhu 提交于
      This patch includes the following changes to virnetdevmacvlan.c and
      virnetdevvportprofile.c:
      
       - removes some netlink functions which are now available in
         virnetdev.c
      
       - Adds a vf argument to all port profile functions.
      
      For 802.1Qbh devices, the port profile calls can use a vf argument if
      passed by the caller. If the vf argument is -1 it will try to derive the vf
      if the device passed is a virtual function.
      
      For 802.1Qbg devices, This patch introduces a null check for the device
      argument because during port profile assignment on a hostdev, this argument
      can be null.
      Signed-off-by: NRoopa Prabhu <roprabhu@cisco.com>
      15bbfd83
    • R
      util: support functions for mac/portprofile associations on hostdev · 5095bf06
      Roopa Prabhu 提交于
      This patch adds the following:
      
      - functions to set and get vf configs
      - Functions to replace and store vf configs (Only mac address is handled today.
        But the functions can be easily extended for vlans and other vf configs)
      - function to dump link dev info (This is moved from virnetdevvportprofile.c)
      Signed-off-by: NRoopa Prabhu <roprabhu@cisco.com>
      5095bf06
    • R
      util: two new pci util functions · b8b70273
      Roopa Prabhu 提交于
      pciDeviceGetVirtualFunctionInfo returns pf netdevice name and virtual
      function index for a given vf. This is just a wrapper around existing functions
      to return vf's pf and vf_index with one api call
      
      pciConfigAddressToSysfsfile returns the sysfile pci device link
      from a 'struct pci_config_address'
      Signed-off-by: NRoopa Prabhu <roprabhu@cisco.com>
      b8b70273
    • L
      qemu: support type=hostdev network device live hotplug attach/detach · cf90342b
      Laine Stump 提交于
      qemuDomainAttachNetDevice
      
        - re-ordered some things at start of function because
          networkAllocateActualDevice should always be run and a slot
          in def->nets always allocated, but host_net_add isn't needed
          if the actual type is hostdev.
      
        - if actual type is hostdev, defer to
          qemuDomainAttachHostDevice (which will reach up to the NetDef
          for things like MAC address when necessary). After return
          from qemuDomainAttachHostDevice, slip directly to cleanup,
          since the rest of the function is specific to emulated net
          devices.
      
        - put assignment of new NetDef into expanded def->nets down
          below cleanup: (but only on success) since it is also needed
          for emulated and hostdev net devices.
      
      qemuDomainDetachHostDevice
      
        - after locating the exact device to detach, check if it's a
          network device and, if so, use toplevel
          qemuDomainDetachNetDevice instead so that the def->nets list
          is properly updated, and 'actual device' properly returned to
          network pool if appropriate. Otherwise, for normal hostdevs,
          call the lower level qemuDomainDetachThisDevice.
      
      qemuDomainDetachNetDevice
      
        - This is where it gets a bit tricky. After locating the device
          on the def->nets list, if the network device type == hostdev,
          call the *lower level* qemuDomainDetachThisDevice (which will
          reach back up to the parent net device for MAC address /
          virtualport when appropriate, then clear the device out of
          def->hostdevs) before skipping past all the emulated
          net-device-specific code to cleanup:, where the network
          device is removed from def->nets, and the network device
          object is freed.
      
      In short, any time a hostdev-type network device is detached, we must
      go through the toplevel virDomaineDetachNetDevice function first and
      last, to make sure 1) the def->nnets list is properly managed, and 2)
      any device allocated with networkAllocateActualDevice is properly
      freed. At the same time, in the middle we need to go through the
      lower-level vidDomainDetach*This*HostDevice to be sure that 1) the
      def->hostdevs list is properly managed, 2) the PCI device is properly
      detached from the guest and reattached to the host (if appropriate),
      and 3) any higher level teardown is called at the appropriate time, by
      reaching back up to the NetDef config (part (3) will be covered in a
      separate patch).
      cf90342b
    • L
      qemu: use virDomainNetRemove instead of inline code · 16520d65
      Laine Stump 提交于
      The code being replaced is exactly identical to the newly global
      function, right down to the comment.
      16520d65