1. 26 2月, 2015 2 次提交
    • L
      conf: error out on invalid host id · 719cd218
      Luyao Huang 提交于
      https://bugzilla.redhat.com/show_bug.cgi?id=1196503
      
      We already check whether the host id is valid or not, add a jump
      to forbid invalid host id.
      Signed-off-by: NLuyao Huang <lhuang@redhat.com>
      Signed-off-by: NJán Tomko <jtomko@redhat.com>
      719cd218
    • L
      network: only clear bandwidth if it has been set · 118b2408
      Laine Stump 提交于
      libvirt was unconditionally calling virNetDevBandwidthClear() for
      every interface (and network bridge) of a type that supported
      bandwidth, whether it actually had anything set or not. This doesn't
      hurt anything (unless ifname == NULL!), but is wasteful.
      
      This patch makes sure that all calls to virNetDevBandwidthClear() are
      qualified by checking that the interface really had some bandwidth
      setup done, and checks for a null ifname inside
      virNetDevBandwidthClear(), silently returning success if it is null
      (as well as removing the ATTRIBUTE_NONNULL from that function's
      prototype, since we can't guarantee that it is never null,
      e.g. sometimes a type='ethernet' interface has no ifname as it is
      provided on the fly by qemu).
      118b2408
  2. 25 2月, 2015 2 次提交
  3. 24 2月, 2015 1 次提交
    • M
      network_conf: Forbid commas in DNS TXT · 39df9d2f
      Michal Privoznik 提交于
      https://bugzilla.redhat.com/show_bug.cgi?id=1151942
      
      While the restriction doesn't have origin in any RFC, it matters
      to us while constructing the dnsmasq config file (or command line
      previously). For better picture, this is how the corresponding
      part of network XML look like:
      
        <dns>
          <forwarder addr='8.8.4.4'/>
          <txt name='example' value='example value'/>
        </dns>
      
      And this is how the config file looks like then:
      
        server=8.8.4.4
        txt-record=example,example value
      
      Now we can see why there can't be any commas in the TXT name.
      They are used by dnsmasq to separate @name and @value.
      
      Funny, we have it in the documentation, but the code (which was
      pushed back in 2011) didn't reflect that.
      Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
      39df9d2f
  4. 21 2月, 2015 27 次提交
    • M
      conf: support backend domain name in disk and network devices · c374353c
      Marek Marczykowski 提交于
      At least Xen supports backend drivers in another domain (aka "driver
      domain"). This patch introduces an XML config option for specifying the
      backend domain name for <disk> and <interface> devices.  E.g.
      
        <disk>
          <backenddomain name='diskvm'/>
          ...
        </disk>
        <interface type='bridge'>
          <backenddomain name='netvm'/>
          ...
        </interface>
      
      In the future, same option will be needed for USB devices (hostdev
      objects), but for now libxl doesn't have support for PVUSB.
      Signed-off-by: NMarek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
      c374353c
    • L
      network: allow <pf> together with <interface>/<address> in network status · 8f8e581a
      Laine Stump 提交于
      The function that parses the <forward> subelement of a network used to
      fail/log an error if the network definition contained both a <pf>
      element as well as at least one <interface> or <address> element. That
      check was present because the configuration of a network should have
      either one <pf>, one or more <interface>, or one or more <address>,
      but never combinations of multiple kinds.
      
      This caused a problem when libvirtd was restarted with a network
      already active - when a network with a <pf> element is started, the
      referenced PF (Physical Function of an SRIOV-capable network card) is
      checked for VFs (Virtual Functions), and the <forward> is filled in
      with a list of all VFs for that PF either in the form of their PCI
      addresses (a list of <address>) or their netdev names (a list of
      <interface>); the <pf> element is not removed though. When libvirtd is
      restarted, it parses the network status and finds both the original
      <pf> from the config, as well as the list of either <address> or
      <interface>, fails the parse, and the network is not added to the
      active list. This failure is often obscured because the network is
      marked as autostart so libvirt immediately restarts it.
      
      It seems odd to me that <interface> and <address> are stored in the
      same array rather than keeping two separate arrays, and having
      separate arrays would have made the check much simpler. However,
      changing to use two separate arrays would have required changes in
      more places, potentially creating more conflicts and (more
      importantly) more possible regressions in the event of a backport, so
      I chose to keep the existing data structure in order to localize the
      change.
      
      It appears that this problem has been in the code ever since support
      for <pf> was added (0.9.10), but until commit
      34cc3b2f (first in libvirt 1.2.4)
      networks with interface pools were not properly marked as active on
      restart anyway, so there is no point in backporting this patch any
      further than that.
      8f8e581a
    • P
      conf: Hoist validation of memory size into the post parse callback · e5c7864c
      Peter Krempa 提交于
      Later patches will need to access the full definition to do check the
      memory size and thus the checking needs to be done after the whole
      definition including devices is known.
      e5c7864c
    • P
      conf: numa: Check ABI stability of NUMA configuration · b98596a7
      Peter Krempa 提交于
      Add helper to compare initial sizes of indivitual NUMA nodes and the map
      of belonging vCPUs. Other configuration is not ABI.
      b98596a7
    • P
      conf: ABI: Hugepage backing definition is not guest ABI · e431c3c0
      Peter Krempa 提交于
      The backing of the vm's memory isn't influencing the guest ABI thus
      shouldn't be checked.
      e431c3c0
    • P
      conf: Move all NUMA configuration to virDomainNuma · 181742d4
      Peter Krempa 提交于
      For historical reasons data regarding NUMA configuration were split
      between the CPU definition and numatune. We cannot do anything about the
      XML still being split, but we certainly can at least store the relevant
      data in one place.
      
      This patch moves the NUMA stuff to the right place.
      181742d4
    • P
      conf: numa: Add setter/getter for NUMA node memory size · b9ddb258
      Peter Krempa 提交于
      Add the helpers and refactor places where the value is accessed without
      them.
      b9ddb258
    • P
      7800d473
    • P
      conf: numa: Add accessor for the NUMA node cpu mask · d9a779a3
      Peter Krempa 提交于
      Add virDomainNumaGetNodeCpumask() and refactor a few places that would
      get the cpu mask without the helper.
      d9a779a3
    • P
      conf: numa: Add helper to get guest NUMA node count and refactor users · be22d073
      Peter Krempa 提交于
      Add an accessor so that a later refactor is simpler.
      be22d073
    • P
      conf: numa: Don't pass double pointer to virDomainNumatuneParseXML · b83543c5
      Peter Krempa 提交于
      virDomainNumatuneParseXML now doesn't allocate the def->numa object any
      longer so we don't need to pass a double pointer.
      b83543c5
    • P
      numa: conf: Tweak parameters of virDomainNumatuneSet · fa993072
      Peter Krempa 提交于
      As virDomainNumatuneSet now doesn't allocate the virDomainNuma object
      any longer it's not necessary to pass the pointer to a pointer to store
      the object as it will not change any longer.
      
      While touching the parameter definitions I've also changed the name of
      the parameter to "numa".
      fa993072
    • P
      conf: numa: Always allocate the NUMA config · 21008c01
      Peter Krempa 提交于
      Since our formatter now handles well if the config is allocated and not
      filled we can safely always-allocate the NUMA config and remove the
      ad-hoc allocation code.
      
      This will help in later patches as the parser will be refactored to just
      fill the data.
      21008c01
    • P
      conf: Allocate domain definition with the new helper · c0341119
      Peter Krempa 提交于
      Use the virDomainDefNew() helper to allocate the definition instead of
      doing it via VIR_ALLOC.
      c0341119
    • P
      conf: Separate helper for creating domain objects · 61e43ce9
      Peter Krempa 提交于
      Move the existing virDomainDefNew to virDomainDefNewFull as it's setting
      a few things in the conf and re-introduce virDomainDefNew as a function
      without parameters for common use.
      61e43ce9
    • P
      conf: numa: Format <numatune> XML only if necessary · 121cde47
      Peter Krempa 提交于
      Do a content-aware check if formatting of the <numatune> element is
      necessary. Later on the def->numa structure will be always present so we
      cannot decide only on the basis whether it's allocated.
      121cde47
    • P
      conf: numa: Refactor logic in virDomainNumatuneParseXML · 638e3d27
      Peter Krempa 提交于
      Shuffling around the logic will allow to simplify the code quite a bit.
      As an additional bonus the change in the logic now reports an error if
      automatic placement is selected and individual placement is configured.
      638e3d27
    • P
      conf: numa: Reformat virDomainNumatuneParseXML · 67bd807c
      Peter Krempa 提交于
      Collapse few of the conditions so that the program flow is more clear.
      67bd807c
    • P
      conf: numa: Improve error message in case a numa node doesn't have cpus · 60a2ce49
      Peter Krempa 提交于
      Currently the code would exit without reporting an error as
      virBitmapParse reports one only if it fails to parse the bitmap, whereas
      the code was jumping to the error label even in case 0 cpus were
      correctly parsed in the map.
      60a2ce49
    • P
      conf: numa: Recalculate rather than remember total NUMA cpu count · 6b616632
      Peter Krempa 提交于
      It's easier to recalculate the number in the one place it's used as
      having a separate variable to track it. It will also help with moving
      the NUMA code to the separate module.
      6b616632
    • P
      conf: Move enum virMemAccess to the NUMA code and rename it · a3673b22
      Peter Krempa 提交于
      Name it virNumaMemAccess and add it to conf/numa_conf.[ch]
      
      Note that to avoid a circular dependency the type of the NUMA cell
      memAccess variable was changed to int. It will be turned back later
      after the circular dependency will not exist.
      a3673b22
    • P
      conf: numa: Rename virDomainNumatune to virDomainNuma · 6bc80fa8
      Peter Krempa 提交于
      The structure will gradually become the only place for NUMA related
      config, thus rename it appropriately.
      6bc80fa8
    • P
      conf: Move NUMA cell formatter to numa_conf · 456268d4
      Peter Krempa 提交于
      Move the code that formats the /domain/cpu/numa element to numa_conf as
      it belongs there.
      456268d4
    • P
      conf: numa: Don't duplicate NUMA cell cpumask · 2562141f
      Peter Krempa 提交于
      The mask was stored both as a bitmap and as a string. The string is used
      for XML output only. Remove the string, as it can be reconstructed from
      the bitmap.
      
      The test change is necessary as the bitmap formatter doesn't "optimize"
      using the '^' operator.
      2562141f
    • P
      conf: Refactor virDomainNumaDefCPUParseXML · 34a1dd73
      Peter Krempa 提交于
      Rewrite the function to save a few local variables and reorder the code
      to make more sense.
      
      Additionally the ncells_max member of the virCPUDef structure is used
      only for tracking allocation when parsing the numa definition, which can
      be avoided by switching to VIR_ALLOC_N as the array is not resized
      after initial allocation.
      34a1dd73
    • P
      conf: Move NUMA cell parsing code from cpu conf to numa conf · 5bba61fd
      Peter Krempa 提交于
      For weird historical reasons NUMA cells are added as a subelement of
      <cpu> while the actual configuration is done in <numatune>.
      
      This patch splits out the cell parser code from cpu config to NUMA
      config. Note that the changes to the code are minimal just to make it
      work and the function will be refactored in the next patch.
      5bba61fd
    • P
      conf: Move numatune_conf to numa_conf · fcee64e7
      Peter Krempa 提交于
      For a while now there are two places that gather information about NUMA
      related guest configuration. While the XML can't be changed we can at
      least store the data in one place in the definition.
      
      Rename the numatune_conf.[ch] files to numa_conf as later patches will
      move the rest of the definitions from the cpu definition to this one.
      fcee64e7
  5. 19 2月, 2015 1 次提交
    • J
      Search for schemas and cpu_map.xml in source tree · bc6e2063
      Jiri Denemark 提交于
      Not all files we want to find using virFileFindResource{,Full} are
      generated when libvirt is built, some of them (such as RNG schemas) are
      distributed with sources. The current API was not able to find source
      files if libvirt was built in VPATH.
      
      Both RNG schemas and cpu_map.xml are distributed in source tarball.
      Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
      bc6e2063
  6. 17 2月, 2015 1 次提交
  7. 13 2月, 2015 1 次提交
  8. 12 2月, 2015 4 次提交
    • M
      docs, schema, conf: Add support for setting scheduler parameters of guest threads · 8680ea97
      Martin Kletzander 提交于
      In order for QEMU vCPU (and other) threads to run with RT scheduler,
      libvirt needs to take care of that so QEMU doesn't have to run privileged.
      
      Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1178986Signed-off-by: NMartin Kletzander <mkletzan@redhat.com>
      8680ea97
    • L
      domain: include portgroup in interface status xml · 89d26890
      Laine Stump 提交于
      Prior to commit 7d5bf484 (first appearing in libvirt 1.2.2), the
      status XML of a domain's interface was missing a lot of important
      information; mainly it just output the config of the interface, plus
      the name of the tap device and qemu device alias. Commit 7d5bf484
      changed the status XML to include many important bits of information
      that were required to make network "hook" scripts useful - bandwidth
      information, vlan tag, the name of the bridge (or physical device in
      the case of macvtap) that the tap/macvtap device was attached to - the
      commit log for 7d5bf484 has a very detailed explanation of the
      change. For quick reference - in the example given there, prior to the
      change, status XML looked like figure [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>
      
      and after the change, it looked like figure [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>
      
      You'll notice that bandwidth info, physdev, and macvtap mode have been
      added, but the network and portgroup names are now missing - I didn't
      think that this information was of any use once the needed
      bandwidth/vlan/etc config had been pulled from the network/portgroup.
      
      I was wrong.
      
      A few months after that change a user on IRC asked what happened to
      portgroup in the status XML and described how he used it (more or less
      as a tag to decide what external information to use in a hook script
      that was run at startup/migration time - see
      http://wiki.libvirt.org/page/OVS_and_PVLANS ). At that time I planned
      to make a patch to re-add portgroup, but life intervened as that was
      just prior to a transatlantic move involving several weeks of
      "vacation". During this time I somehow forgot to make the patch, and
      also mistakenly remembered that I *had* made it.
      
      Subsequent to this, as a part of mprivozn's work to add support for
      network-specific hooks, I did re-add the output of the network name in
      status XML, but once again completely forgot about portgroup. This was
      in commit a3609121 (first appearing in libvirt 1.2.11). This made the
      status XML from the above example look like this:
      
            <interface type='direct'>
              <source network='testnet' 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>
      
      *This* patch just adds the portgroup back to the status XML, so the
       same example interface will look like this:
      
            <interface type='direct'>
              <source network='testnet' portgroup='admin'
                      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>
      
      The result is that the status XML now contains all information about
      how the interface is setup (bandwidth, physical device, tap device,
      etc), in addition to pointers to its origin (the network and
      portgroup).
      89d26890
    • L
      domain: avoid potential memory leak in virDomainGraphicsListenSet*() · 6d1194ff
      Laine Stump 提交于
      virDomainGraphicsListenSetAddress() and
      virDomainGraphicsListenSetNetwork() both set their respective char* to
      NULL directly when asked to set it to NULL, which is okay as long as
      it's already set to NULL. If these functions are ever called to clear
      a listen object that has a valid string in address or network, it will
      end up leaking the old value. Currently that doesn't happen, so this
      is just a preemptive strike.
      6d1194ff
    • L
      domain: backfill listen address to parent <graphics> listen attribute · 69929941
      Laine Stump 提交于
      Prior to 0.9.4, libvirt only supported a single listen, and it had to
      be an IP address:
      
         <graphics listen='1.2.3.4' ..../>
      
      Starting with 0.9.4, a graphics element could have a <listen>
      subelement (actually the grammar supports multiples, but all of the
      drivers only support a single <listen> per <graphics>), and that
      listen element can be of type='address' or type='network'. For
      type='address', <listen> also has an attribute called 'address' which
      contains the IP address for listening:
      
          <graphics ....>
            <listen type='address' address='1.2.3.4' .../>
          </graphics>
      
      type can also be "network", and in that case listen will have a
      "network" attribute which will contain the name of a libvirt
      network:
      
          <graphics ....>
            <listen type='network' network='testnet' .../>
          </graphics>
      
      At domain start (or migrate) time, libvirt will attempt to
      find an IP address associated with that network (e.g. the IP address
      of the bridge device used by the network, or the physical device
      listed in <forward dev='physdev'/>) and fill in that address in the
      status XML:
      
          <graphics ....>
            <listen type='network' network='testnet' address='1.2.3.4' .../>
          </graphics>
      
      In the case that a <graphics> element has a <listen> subelement of
      type='address', that listen subelement's "address" attribute is
      backfilled into the parent graphics element's "listen" *attribute* for
      backward compatibility (so that a management application unaware of
      the separate <listen> element can still learn the listen
      address). This backfill should be done with the IP learned from
      type='network' as well, and that's what this patch does:
      
          <graphics listen='1.2.3.4' ....>
            <listen type='network' network='testnet' address='1.2.3.4' .../>
          </graphics>
      
      This is a continuation of the fix for:
      
         https://bugzilla.redhat.com/show_bug.cgi?id=1191016
      69929941
  9. 11 2月, 2015 1 次提交
    • Z
      conf: Fix libvirtd crash and memory leak caused by virDomainVcpuPinDel() · 2d27dcb0
      Zhang Bo 提交于
      The function virDomainVcpuPinDel() used vcpupin_list to stand for
      def->cputune.vcpupin, which made the codes more readable.
      However, in this function, it will realloc vcpupin_list later.
      As the definition of realloc(), it may free vcpupin_list and then
      points it to a new-realloced address, but def->cputune.vcpupin doesn't
      point to the new address(it's freed however).
      Thus,
      1) When we refer to the def->cputune.vcpupin afterwards, which was freed
      by realloc(), an INVALID READ occurs, and libvirtd may crash.
      2) As no one will use vcpupin_list any more, and no one frees it(it's just
      alloced by realloc()), memory leak occurs.
      
      Part of the valgrind logs are shown as below:
      ==1837== Thread 15:
      ==1837== Invalid read of size 8
      ==1837==    at 0x5367337: virDomainDefFormatInternal (domain_conf.c:18392)
              which is : virBufferAsprintf(buf, "<vcpupin vcpu='%u' ",
                                def->cputune.vcpupin[i]->vcpuid);
      ==1837==    by 0x536966C: virDomainObjFormat (domain_conf.c:18970)
      ==1837==    by 0x5369743: virDomainSaveStatus (domain_conf.c:19166)
      ==1837==    by 0x117B26DC: qemuDomainPinVcpuFlags (qemu_driver.c:4586)
      ==1837==    by 0x53EA313: virDomainPinVcpuFlags (libvirt.c:9803)
      ==1837==    by 0x14CB7D: remoteDispatchDomainPinVcpuFlags (remote_dispatch.h:6762)
      ==1837==    by 0x14CC81: remoteDispatchDomainPinVcpuFlagsHelper (remote_dispatch.h:6740)
      ==1837==    by 0x5464C30: virNetServerProgramDispatchCall (virnetserverprogram.c:437)
      ==1837==    by 0x546507A: virNetServerProgramDispatch (virnetserverprogram.c:307)
      ==1837==    by 0x171B83: virNetServerProcessMsg (virnetserver.c:172)
      ==1837==    by 0x171E6E: virNetServerHandleJob (virnetserver.c:193)
      ==1837==    by 0x5318E78: virThreadPoolWorker (virthreadpool.c:145)
      ==1837==  Address 0x12ea2870 is 0 bytes inside a block of size 16 free'd
      ==1837==    at 0x4C291AC: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
      ==1837==    by 0x52A3D14: virReallocN (viralloc.c:245)
      ==1837==    by 0x52A3DFB: virShrinkN (viralloc.c:372)
      ==1837==    by 0x52A3F57: virDeleteElementsN (viralloc.c:503)
      ==1837==    by 0x533939E: virDomainVcpuPinDel (domain_conf.c:15405)  //doReset为true时才会进到。
      ==1837==    by 0x117B2642: qemuDomainPinVcpuFlags (qemu_driver.c:4573)
      ==1837==    by 0x53EA313: virDomainPinVcpuFlags (libvirt.c:9803)
      ==1837==    by 0x14CB7D: remoteDispatchDomainPinVcpuFlags (remote_dispatch.h:6762)
      ==1837==    by 0x14CC81: remoteDispatchDomainPinVcpuFlagsHelper (remote_dispatch.h:6740)
      ==1837==    by 0x5464C30: virNetServerProgramDispatchCall (virnetserverprogram.c:437)
      ==1837==    by 0x546507A: virNetServerProgramDispatch (virnetserverprogram.c:307)
      ==1837==    by 0x171B83: virNetServerProcessMsg (virnetserver.c:172)
      
      Steps to reproduce the problem:
      1) use virDomainPinVcpuFlags() to pin a guest's vcpu to all the pcpus
      of the host.
      
      This patch uses def->cputune.vcpupin instead of vcpupin_list to do the
      realloc() job, to avoid invalid read or memory leaking.
      Signed-off-by: NZhang Bo <oscar.zhangbo@huawei.com>
      Signed-off-by: Yue Wenyuan <yuewenyuan@huawei.com@huawei.com>
      2d27dcb0