1. 02 5月, 2014 3 次提交
    • E
      util: new stricter unsigned int parsing · 7b045c8c
      Eric Blake 提交于
      strtoul() is required to parse negative numbers as their
      twos-complement positive counterpart.  But sometimes we want
      to reject negative numbers.  Add new functions to do this.
      The 'p' suffix is a mnemonic for 'positive' (technically it
      also parses 0, but 'non-negative' doesn't lend itself to a
      nice one-letter suffix).
      
      * src/util/virstring.h (virStrToLong_uip, virStrToLong_ulp)
      (virStrToLong_ullp): New prototypes.
      * src/util/virstring.c (virStrToLong_uip, virStrToLong_ulp)
      (virStrToLong_ullp): New functions.
      * src/libvirt_private.syms (virstring.h): Export them.
      * tests/virstringtest.c (testStringToLong): Test them.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      7b045c8c
    • E
      util: fix uint parsing on 64-bit platforms · f18c02ec
      Eric Blake 提交于
      Commit f22b7899 called to light a long-standing latent bug: the
      behavior of virStrToLong_ui was different on 32-bit platforms
      than on 64-bit platforms.  Curse you, C type promotion and
      narrowing rules, and strtoul specification.  POSIX says that for
      a 32-bit long, strtol handles only 2^32 values [LONG_MIN to
      LONG_MAX] while strtoul handles 2^33 - 1 values [-ULONG_MAX to
      ULONG_MAX] with twos-complement wraparound for negatives.  Thus,
      parsing -1 as unsigned long produces ULONG_MAX, rather than a
      range error.  We WANT[1] this same shortcut for turning -1 into
      UINT_MAX when parsing to int; and get it for free with 32-bit
      long.  But with 64-bit long, ULONG_MAX is outside the range
      of int and we were rejecting it as invalid; meanwhile, we were
      silently treating -18446744073709551615 as 1 even though it
      textually exceeds INT_MIN.  Too bad there's not a strtoui() in
      libc that does guaranteed parsing to int, regardless of the size
      of long.
      
      The bug has been latent since 2007, introduced by Jim Meyering
      in commit 5d254191 in the attempt to eradicate unsafe use of
      strto[u]l when parsing ints and longs.  How embarrassing that we
      are only discovering it now - so I'm adding a testsuite to ensure
      that it covers all the corner cases we care about.
      
      [1] Ideally, we really want the caller to be able to choose whether
      to allow negative numbers to wrap around to their 2s-complement
      counterpart, as in strtoul, or to force a stricter input range
      of [0 to UINT_MAX] by rejecting negative signs; this will be added
      in a later patch for all three int types.
      
      This patch is tested on both 32- and 64-bit; the enhanced
      virstringtest passes on both platforms, while virstoragetest now
      reliably fails on both platforms instead of just 32-bit platforms.
      That test will be fixed later.
      
      * src/util/virstring.c (virStrToLong_ui): Ensure same behavior
      regardless of platform long size.
      * tests/virstringtest.c (testStringToLong): New function.
      (mymain): Comprehensively test string to long parsing.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      f18c02ec
    • D
      Misc error reporting bugs in QEMU cli builder · dca027a9
      Daniel P. Berrange 提交于
      A couple of places in the QEMU XML -> ARGV conversion code
      raised an error but then forgot to return an error status
      due to missing gotos. While fixing this also tweak style
      of a couple of other error reports
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      dca027a9
  2. 01 5月, 2014 4 次提交
  3. 30 4月, 2014 6 次提交
  4. 29 4月, 2014 17 次提交
  5. 28 4月, 2014 5 次提交
  6. 27 4月, 2014 5 次提交
    • L
      network: centralize check for active network during interface attach · 34cc3b2f
      Laine Stump 提交于
      The check for a network being active during interface attach was being
      done individually in several places (by both the lxc driver and the
      qemu driver), but those places were too specific, leading to it *not*
      being checked when allocating a connection/device from a macvtap or
      hostdev network.
      
      This patch puts a single check in networkAllocateActualDevice(), which
      is always called before the any network interface is attached to any
      type of domain. It also removes all the other now-redundant checks
      from the lxc and qemu drivers.
      
      NB: the following patches are prerequisites for this patch, in the
      case that it is backported to any branch:
      
        440beeb7 network: fix virNetworkObjAssignDef and persistence
        8aaa5b68 network: create statedir during driver initialization
        b9e95491 network: change location of network state xml files
        411c5486 network: set macvtap/hostdev networks active if their state
                file exists
      
      This fixes:
      
        https://bugzilla.redhat.com/show_bug.cgi?id=880483
      34cc3b2f
    • L
      network: set macvtap/hostdev networks active if their state file exists · 411c5486
      Laine Stump 提交于
      libvirt attempts to determine at startup time which networks are
      already active, and set their active flags. Previously it has done
      this by assuming that all networks are inactive, then setting the
      active flag if the network has a bridge device associated with it and
      that bridge device exists. This is not useful for macvtap and hostdev
      based networks, since they do not use a bridge device.
      
      Of course the reason that such a check had to be done was that the
      presence of a status file in the network "stateDir" couldn't be
      trusted as an indicator of whether or not a network was active. This
      was due to the network driver mistakenly using
      /var/lib/libvirt/network to store the status files, rather than
      /var/run/libvirt/network (similar to what is done by every other
      libvirt driver that stores status xml for its objects). The difference
      is that /var/run is cleared out when the host reboots, so you can be
      assured that the state file you are seeing isn't just left over from a
      previous boot of the host.
      
      Now that the network driver has been switched to using
      /var/run/libvirt/network for status, we can also modify it to assume
      that any network with an existing status file is by definition active
      - we do this when reading the status file. To fine tune the results,
      networkFindActiveConfigs() is changed to networkUpdateAllState(),
      and only sets active = 0 if the conditions for particular network
      types are *not* met.
      
      The result is that during the first run of libvirtd after the host
      boots, there are no status files, so no networks are active. Any time
      libvirtd is restarted, any network with a status file will be marked
      as active (unless the network uses a bridge device and that device for
      some reason doesn't exist).
      411c5486
    • L
      network: change location of network state xml files · b9e95491
      Laine Stump 提交于
      For some reason these have been stored in /var/lib, although other
      drivers (e.g. qemu and lxc) store their state files in /var/run.
      
      It's much nicer to store state files in /var/run because it is
      automatically cleared out when the system reboots. We can then use
      existence of the state file as a convenient indicator of whether or
      not a particular network is active.
      
      Since changing the location of the state files by itself will cause
      problems in the case of a *live* upgrade from an older libvirt that
      uses /var/lib (because current status of active networks will be
      lost), the network driver initialization has been modified to migrate
      any network state files from /var/lib to /var/run.
      
      This will not help those trying to *downgrade*, but in practice this
      will only be problematic in two cases
      
      1) If there are networks with network-wide bandwidth limits configured
         *and in use* by a guest during a downgrade to "old" libvirt. In this
         case, the class ID's used for that network's tc rules, as well as
         the currently in-use bandwidth "floor" will be forgotten.
      
      2) If someone does this: 1) upgrade libvirt, 2) downgrade libvirt, 3)
         modify running state of network (e.g. add a static dhcp host, etc),
         4) upgrade. In this case, the modifications to the running network
         will be lost (but not any persistent changes to the network's
         config).
      b9e95491
    • L
      network: create statedir during driver initialization · 8aaa5b68
      Laine Stump 提交于
      This directory should be created when the network driver is first
      started up, not just when a dhcp daemon is run. This hasn't posed a
      problem in the past, because the directory has always been
      pre-existing.
      8aaa5b68
    • L
      network: fix virNetworkObjAssignDef and persistence · 440beeb7
      Laine Stump 提交于
      Experimentation showed that if virNetworkCreateXML() was called for a
      network that was already defined, and then the network was
      subsequently shutdown, the network would continue to be persistent
      after the shutdown (expected/desired), but the original config would
      be lost in favor of the transient config sent in with
      virNetworkCreateXML() (which would then be the new persistent config)
      (obviously unexpected/not desired).
      
      To fix this, virNetworkObjAssignDef() has been changed to
      
      1) properly save/free network->def and network->newDef for all the
      various combinations of live/active/persistent, including some
      combinations that were previously considered to be an error but didn't
      need to be (e.g. setting a "live" config for a network that isn't yet
      active but soon will be - that was previously considered an error,
      even though in practice it can be very useful).
      
      2) automatically set the persistent flag whenever a new non-live
      config is assigned to the network (and clear it when the non-live
      config is set to NULL). the libvirt network driver no longer directly
      manipulates network->persistent, but instead relies entirely on
      virNetworkObjAssignDef() to do the right thing automatically.
      
      After this patch, the following sequence will behave as expected:
      
      virNetworkDefineXML(X)
      virNetworkCreateXML(X') (same name but some config different)
      virNetworkDestroy(X)
      
      At the end of these calls, the network config will remain as it was
      after the initial virNetworkDefine(), whereas previously it would take
      on the changes given during virNetworkCreateXML().
      
      Another effect of this tighter coupling between a) setting a !live def
      and b) setting/clearing the "persistent" flag, is that future patches
      which change the details of network lifecycle management
      (e.g. upcoming patches to fix detection of "active" networks when
      libvirtd is restarted) will find it much more difficult to break
      persistence functionality.
      440beeb7