Commit Graph

82 Commits

Author SHA1 Message Date
Eric Blake
68ea80cfdd maint: rename virBufferVSprintf to virBufferAsprintf
We already have virAsprintf, so picking a similar name helps for
seeing a similar purpose.  Furthermore, the prefix V before printf
generally implies 'va_list', even though this variant was '...', and
the old name got in the way of adding a new va_list version.

global rename performed with:

$ git grep -l virBufferVSprintf \
  | xargs -L1 sed -i 's/virBufferVSprintf/virBufferAsprintf/g'

then revert the changes in ChangeLog-old.
2011-05-05 13:47:40 -06:00
Michal Privoznik
a2eab0033c Fix disability to run on systems with no PCI bus
The patch which moved libpciaccess initialization to one place caused
regression - we were not able to run on system with no PCI bus, like
s390(x).
2011-05-03 13:46:22 +02:00
Serge Hallyn
2879582847 Change locking for udev monitor and callbacks
We're seeing bugs apparently resulting from thread unsafety of
libpciaccess, such as
https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/726099
To prevent those, as suggested by danpb on irc, move the
nodeDeviceLock(driverState) higher into the callers.  In
particular:

  udevDeviceMonitorStartup should hold the lock while calling
  udevEnumerateDevices(), and udevEventHandleCallback should hold it
  over its entire execution.

It's not clear to me whether it is ok to hold the
nodeDeviceLock while taking the virNodeDeviceObjLock(dev) on a
device.  If not, then the lock will need to be dropped around
the calling of udevSetupSystemDev(), and udevAddOneDevice()
may not actually be safe to call from higher layers with the
driverstate lock held.

libvirt 0.8.8 with this patch on it seems to work fine for me.
Assuming it looks ok and I haven't done anything obviously dumb,
I'll ask the bug submitters to try this patch.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2011-04-06 10:20:47 -06:00
Eric Blake
0d166c6b7c build: detect potentential uninitialized variables
Even with -Wuninitialized (which is part of autobuild.sh
--enable-compile-warnings=error), gcc does NOT catch this
use of an uninitialized variable:

{
  if (cond)
    goto error;
  int a = 1;
error:
  printf("%d", a);
}

which prints 0 (supposing the stack started life wiped) if
cond was true.  Clang will catch it, but we don't use clang
as often.  Using gcc -Wjump-misses-init catches it, but also
gives false positives:

{
  if (cond)
    goto error;
  int a = 1;
  return a;
error:
  return 0;
}

Here, a was never used in the scope of the error block, so
declaring it after goto is technically fine (and clang agrees).
However, given that our HACKING already documents a preference
to C89 decl-before-statement, the false positive warning is
enough of a prod to comply with HACKING.

[Personally, I'd _really_ rather use C99 decl-after-statement
to minimize scope, but until gcc can efficiently and reliably
catch scoping and uninitialized usage bugs, I'll settle with
the compromise of enforcing a coding standard that happens to
reject false positives if it can also detect real bugs.]

* acinclude.m4 (LIBVIRT_COMPILE_WARNINGS): Add -Wjump-misses-init.
* src/util/util.c (__virExec): Adjust offenders.
* src/conf/domain_conf.c (virDomainTimerDefParseXML): Likewise.
* src/remote/remote_driver.c (doRemoteOpen): Likewise.
* src/phyp/phyp_driver.c (phypGetLparNAME, phypGetLparProfile)
(phypGetVIOSFreeSCSIAdapter, phypVolumeGetKey)
(phypGetStoragePoolDevice)
(phypVolumeGetPhysicalVolumeByStoragePool)
(phypVolumeGetPath): Likewise.
* src/vbox/vbox_tmpl.c (vboxNetworkUndefineDestroy)
(vboxNetworkCreate, vboxNetworkDumpXML)
(vboxNetworkDefineCreateXML): Likewise.
* src/xenapi/xenapi_driver.c (getCapsObject)
(xenapiDomainDumpXML): Likewise.
* src/xenapi/xenapi_utils.c (createVMRecordFromXml): Likewise.
* src/security/security_selinux.c (SELinuxGenNewContext):
Likewise.
* src/qemu/qemu_command.c (qemuBuildCommandLine): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia):
Likewise.
* src/qemu/qemu_process.c (qemuProcessWaitForMonitor): Likewise.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextGetPtyPaths):
Likewise.
* src/qemu/qemu_driver.c (qemudDomainShutdown)
(qemudDomainBlockStats, qemudDomainMemoryPeek): Likewise.
* src/storage/storage_backend_iscsi.c
(virStorageBackendCreateIfaceIQN): Likewise.
* src/node_device/node_device_udev.c (udevProcessPCI): Likewise.
2011-04-04 11:26:29 -06:00
Guido Günther
d0bd206a61 Make check_fc_host() and check_vport_capable() usable as rvalues
as needed on non linux ports using HAL.
2011-04-01 11:23:51 +02:00
Eric Blake
4c7508b4de udev: fix regression with qemu:///session
https://bugzilla.redhat.com/show_bug.cgi?id=684655 points out
a regression introduced in commit 2215050edd - non-root users
can't connect to qemu:///session because libvirtd dies when
it can't use pciaccess initialization.

* src/node_device/node_device_udev.c (udevDeviceMonitorStartup):
Don't abort udev driver (and libvirtd overall) if non-root user
can't use pciaccess.
2011-03-21 10:47:48 -06:00
Eric Blake
994e7567b6 maint: kill all remaining uses of old DEBUG macro
Done mechanically with:
$ git grep -l '\bDEBUG0\? *(' | xargs -L1 sed -i 's/\bDEBUG0\? *(/VIR_&/'

followed by manual deletion of qemudDebug in daemon/libvirtd.c, along
with a single 'make syntax-check' fallout in the same file, and the
actual deletion in src/util/logging.h.

* src/util/logging.h (DEBUG, DEBUG0): Delete.
* daemon/libvirtd.h (qemudDebug): Likewise.
* global: Change remaining clients over to VIR_DEBUG counterpart.
2011-02-21 08:46:52 -07:00
Daniel P. Berrange
7a4bc156c1 Adjust some log levels in udev driver
Most of te VIR_INFO calls in the udev driver are only relevant
to developers so can switch to VIR_DEBUG. Failure to initialize
libpciaccess though is a fatal error

* src/node_device/node_device_udev.c: Adjust log levels
2011-02-09 17:23:21 +00:00
Daniel P. Berrange
cd782cc391 Support SCSI RAID type & lower log level for unknown types
The Linux kernel headers don't have a value for SCSI type 12,
but HAL source code shows this to be a 'raid'. Add workaround
for this type. Lower log level for unknown types since
this is not a fatal error condition. Include the device sysfs
path in the log output to allow identification of which device
has problems.

* src/node_device/node_device_udev.c: Add SCSI RAID type
2011-02-09 16:20:38 +00:00
Daniel P. Berrange
2215050edd Only initialize/cleanup libpciaccess once
libpciaccess has many bugs in its pci_system_init/cleanup
functions that makes calling them multiple times unwise.
eg it will double close() FDs, and leak other FDs.

* src/node_device/node_device_udev.c: Only initialize
  libpciaccess once
2011-02-09 16:20:27 +00:00
Chris Wright
51798a5d1c node_device: udev driver does not handle SR-IOV devices
The udev driver does not update a PCI device with its SR-IOV capabilities,
when applicable, the way the hal driver does.  As a result, dumping the
device's XML will not include the relevant physical or virtual function
information.

With this patch, the XML is correct:

# virsh nodedev-dumpxml pci_0000_09_00_0
<device>
  <name>pci_0000_09_00_0</name>
  <parent>pci_0000_00_1c_0</parent>
  <driver>
    <name>vxge</name>
  </driver>
  <capability type='pci'>
    <domain>0</domain>
    <bus>9</bus>
    <slot>0</slot>
    <function>0</function>
    <product id='0x5833'>X3100 Series 10 Gigabit Ethernet PCIe</product>
    <vendor id='0x17d5'>Neterion Inc.</vendor>
    <capability type='virt_functions'>
      <address domain='0x0000' bus='0x0a' slot='0x00' function='0x1'/>
      <address domain='0x0000' bus='0x0a' slot='0x00' function='0x2'/>
      <address domain='0x0000' bus='0x0a' slot='0x00' function='0x3'/>
    </capability>
  </capability>
</device>

# virsh nodedev-dumpxml pci_0000_0a_00_1
<device>
  <name>pci_0000_0a_00_1</name>
  <parent>pci_0000_00_1c_0</parent>
  <driver>
    <name>vxge</name>
  </driver>
  <capability type='pci'>
    <domain>0</domain>
    <bus>10</bus>
    <slot>0</slot>
    <function>1</function>
    <product id='0x5833'>X3100 Series 10 Gigabit Ethernet PCIe</product>
    <vendor id='0x17d5'>Neterion Inc.</vendor>
    <capability type='phys_function'>
      <address domain='0x0000' bus='0x09' slot='0x00' function='0x0'/>
    </capability>
  </capability>
</device>

Cc: Dave Allan <dallan@redhat.com>
Signed-off-by: Chris Wright <chrisw@redhat.com>
2011-01-03 09:05:10 -07:00
Jean-Baptiste Rouault
966a1bfe22 Create file in virFileWriteStr() if it doesn't exist
This patch adds a mode_t parameter to virFileWriteStr().
If mode is different from 0, virFileWriteStr() will try
to create the file if it doesn't exist.

* src/util/util.h (virFileWriteStr): Alter signature.
* src/util/util.c (virFileWriteStr): Allow file creation.
* src/network/bridge_driver.c (networkEnableIpForwarding)
(networkDisableIPV6): Adjust clients.
* src/node_device/node_device_driver.c
(nodeDeviceVportCreateDelete): Likewise.
* src/util/cgroup.c (virCgroupSetValueStr): Likewise.
* src/util/pci.c (pciBindDeviceToStub, pciUnBindDeviceFromStub):
Likewise.
2010-12-03 08:08:22 -07:00
Stefan Berger
60ae1c34ad bye to close(), welcome to VIR_(FORCE_)CLOSE()
Using automated replacement with sed and editing I have now replaced all
occurrences of close() with VIR_(FORCE_)CLOSE() except for one, of
course. Some replacements were straight forward, others I needed to pay
attention. I hope I payed attention in all the right places... Please
have a look. This should have at least solved one more double-close
error.
2010-11-09 15:48:48 -05:00
Guido Günther
94f232bb9b Don't fail on missing D-Bus
We don't fail when we can't contact HAL so we shouldn't fail if we can't
contact D-Bus either.
2010-10-13 14:47:19 +02:00
Eric Blake
9ba934c640 build: fix compiler warning
node_device/node_device_driver.c: In function 'nodeDeviceVportCreateDelete':
node_device/node_device_driver.c:423: error: implicit declaration of function 'stat' [-Wimplicit-function-declaration]

* src/node_device/node_device_driver.c (includes): Add <sys/stat.h>.
2010-08-18 13:46:09 -06:00
Dave Allan
b31ef77313 nodedev: Fix sysfs paths for vport operations
Some kernels, such as the one used in RHEL-5, have vport_create and
vport_delete operation files in /sys/class/scsi_host/hostN directory
instead of /sys/class/fc_host/hostN. Let's check both paths for
compatibility reasons.

This also removes unnecessary '/' characters from sysfs paths containing
LINUX_SYSFS_FC_HOST_PREFIX.
2010-08-18 17:32:31 +02:00
Cole Robinson
ed005221ff udev: Parse PCI devices even if libpciaccess fails
We only use libpciaccess for resolving device product/vendor. If
initializing the library fails (say if using qemu:///session), don't
warn so loudly, and carry on as usual.
2010-07-02 10:30:29 -04:00
David Allan
e7f3bad46e Fix leaks in udev device add/remove v3
* This patch is a modification of a patch submitted by Nigel Jones.
  It fixes several memory leaks on device addition/removal:

1. Free the virNodeDeviceDefPtr in udevAddOneDevice if the return
   value is non-zero

2. Always release the node device reference after the device has been
   processed.

* Refactored for better readability per the suggestion of clalance
2010-06-08 14:46:29 -04:00
Daniel P. Berrange
345ff369e5 Prefer UDEV to HAL drivers if both a compiled
HAL is deprecated and UDEV is the future. Thus if both
options are compiled, we should prefer use of UDEV over
HAL

* src/node_device/node_device_driver.c: Switch init
  order to try UDEV first, then HAL
2010-06-08 15:15:02 +01:00
David Allan
2874a683e9 Update nodedev scsi_host data before use
* It appears that the udev event for HBA creation arrives before the
  associated sysfs data is fully populated, resulting in bogus data
  for the nodedev entry until the entry is refreshed.  This problem is
  particularly troublesome when creating NPIV vHBAs because it results
  in libvirt failing to find the newly created adapter and waiting for
  the full timeout period before erroneously failing the create
  operation.  This patch forces an update before any attempt to use
  any scsi_host nodedev entry.
2010-06-03 10:54:39 -04:00
David Allan
d3e43bad98 Fix device destroy return value
* Set return value in error cases
* Clarify error message when parent device is not vport capable
2010-06-03 10:54:29 -04:00
David Allan
8b46a7bbdb Improve nodedev parent/child relationships
* If a nodedev has a parent that we don't want to display, we should
  continue walking up the udev device tree to see if any of its
  earlier ancestors are devices that we display.  It makes the tree
  much nicer looking than having a whole lot of devices hanging off
  the root node.
2010-05-28 12:48:45 -04:00
David Allan
07f6c3a95f v2 of Cole's wlan support
* Incorporated Jim's feedback (v1 & v2)

* Moved case of DEVTYPE == "wlan" up as it's definitive that we have a network interface.

* Made comment more detailed about the wired case to explain better
  how it differentiates between wired network interfaces and USB
  devices.
2010-05-27 13:20:04 -04:00
Daniel P. Berrange
60881161ea Expose a host UUID in the capabilities XML
Allow for a host UUID in the capabilities XML. Local drivers
will initialize this from the SMBIOS data. If a sanity check
shows SMBIOS uuid is invalid, allow an override from the
libvirtd.conf configuration file

* daemon/libvirtd.c, daemon/libvirtd.conf: Support a host_uuid
  configuration option
* docs/schemas/capability.rng: Add optional host uuid field
* src/conf/capabilities.c, src/conf/capabilities.h: Include
  host UUID in XML
* src/libvirt_private.syms: Export new uuid.h functions
* src/lxc/lxc_conf.c, src/qemu/qemu_driver.c,
  src/uml/uml_conf.c: Set host UUID in capabilities
* src/util/uuid.c, src/util/uuid.h: Support for host UUIDs
* src/node_device/node_device_udev.c: Use the host UUID functions
* tests/confdata/libvirtd.conf, tests/confdata/libvirtd.out: Add
  new host_uuid config option to test
2010-05-25 17:09:18 +01:00
Jim Meyering
d6f9cf4222 maint: don't mark VIR_DEBUG or VIR_DEBUG0 diagnostics for translation
Run this command:
  git grep -l VIR_DEBUG|xargs perl -pi -e \
    's/(VIR_DEBUG0?)\s*\(_\((".*?")\)/$1($2/'
2010-05-20 21:36:26 +02:00
Jim Meyering
82a3c81d8c maint: VIR_ERROR/VIR_ERROR0: mark up the remaining ones manually
Handle concatenated strings manually.
2010-05-20 21:36:25 +02:00
Jim Meyering
2d3208029b maint: mark translatable string args of VIR_ERROR
Run this:
  git grep -l 'VIR_ERROR\s*("'|xargs perl -pi -e \
    's/(VIR_ERROR)\s*\((".*?"),/$1(_($2),/'
2010-05-20 21:36:25 +02:00
Jim Meyering
8d63d82e5c maint: mark translatable string args of VIR_ERROR0
Run this:
  git grep -l 'VIR_ERROR0\s*("'|xargs perl -pi -e \
    's/(VIR_ERROR0)\s*\((".*?")\)/$1(_($2))/'
2010-05-20 21:36:25 +02:00
Jim Meyering
a986892e61 maint: add more free-like functions to the list and deal with fallout
* cfg.mk (useless_free_options): Add many vir*Free* function names,
and then remove the useless if-before-free tests exposed by running
make syntax-check.
* src/conf/interface_conf.c (virInterfaceDefFree): Remove useless "if".
(virInterfaceAssignDef): Likewise.
* src/conf/network_conf.c (virNetworkAssignDef): Likewise.
* src/conf/storage_conf.c (virStoragePoolObjAssignDef): Likewise.
* src/node_device/node_device_hal.c (dev_create): Likewise.
* src/security/virt-aa-helper.c (vahDeinit): Likewise.
* src/test/test_driver.c (testNodeDeviceCreateXML): Likewise.
* src/util/conf.c (virConfSetValue): Likewise.
2010-05-18 07:53:42 +02:00
Cole Robinson
74c7a3463d node_device: udev: Fix PCI product/vendor swappage
Product and vendor values were swapped in the XML, which made virt-manager
PCI device listing kinda useless.
2010-05-11 16:55:56 -04:00
Chris Lalancette
18b3096c40 Fix a memory leak in the node_device_udev code
We were over-writing a pointer without freeing it in
case of a disk device, leading to a memory leak.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
2010-04-29 09:15:54 -04:00
Klaus Ethgen
75d88455f5 The base used for conversion of USB values should be 16 not 10.
Signed-off-by: Guido Günther <agx@sigxcpu.org>
2010-04-27 19:47:54 +02:00
Matthias Bolte
051df19e0e Replace printf with logging macros 2010-04-17 15:02:28 +02:00
Matthias Bolte
49411f029a Remove unnecessary trailing \n in log messages 2010-04-06 01:41:58 +02:00
Eric Blake
0a33633579 maint: make Red Hat copyright notices consistent
Spell out 'Red Hat, Inc.':
 git grep -i 'Copyright.*Red Hat' | grep -v Inc

Include (C) consistently:
 git grep -i 'Copyright [^(].*Red Hat'

* src/lxc/lxc_container.c: Update copyright formatting.
* src/node_device/node_device_udev.c: Likewise.
* src/node_device/node_device_udev.h: Likewise.
* src/xen/xend_internal.h: Likewise.
* src/xen/xm_internal.c: Likewise.
* src/xen/xm_internal.h: Likewise.
* tests/xmconfigtest.c: Likewise.
* tests/object-locking.ml: Likewise.
* tools/virt-pki-validate.in: Likewise.
* tools/virt-xml-validate.in: Likewise.
2010-03-18 16:48:05 +01:00
Ed Swierk
e29439bd14 Allow devices without a parent
* Allow devices without parent links to be created and set their parent to the root "computer" node
2010-03-10 17:25:54 -05:00
David Allan
b978f31a93 Free resources on error in udev startup
* The udev driver didn't properly free resources that it allocates when setting up the 'computer' device in the error case.
2010-03-10 11:38:37 -05:00
Eric Blake
36d8e7d8d7 build: consistently indent preprocessor directives
* global: patch created by running:
for f in $(git ls-files '*.[ch]') ; do
    cppi $f > $f.t && mv $f.t $f
done
2010-03-09 19:22:28 +01:00
Eric Blake
84ef5aecca build: silence coverity warning in node_device
All other uses of get_str_prop in this file that ignored
failure explicitly cast to void.

* src/node_device/node_device_hal.c (dev_create): Silence coverity
warning.
2010-03-02 16:12:48 +01:00
Jim Meyering
a3301b71f6 udevEnumerateDevices: remove dead code
* src/node_device/node_device_udev.c (udevEnumerateDevices): Remove
unnecessary call to udev_list_entry_get_name.
2010-03-01 16:29:42 +01:00
Jim Meyering
081fd746f0 get_virtual_functions_linux: would mistakenly always return zero
* src/node_device/node_device_linux_sysfs.c(get_virtual_functions_linux):
Return "ret", rather than always returning 0.
2010-02-18 16:22:53 +01:00
Daniel P. Berrange
99edc443e9 Remove virConnectPtr from all node device XML APIs
The virConnectPtr is no longer required for error reporting since
that is recorded in a thread local. Remove use of virConnectPtr
from all APIs in node_device_conf.{h,c} and update all callers to
match
2010-02-10 13:32:01 +00:00
Matthias Bolte
f972dc2d5c Remove conn parameter from util functions
It was used for error reporting only.
2010-02-09 01:04:54 +01:00
Matthias Bolte
a5ab900d26 Remove conn parameter from virReportSystemError 2010-02-09 01:04:54 +01:00
Matthias Bolte
8ce5e2c1ab Remove conn parameter from virReportOOMError 2010-02-09 01:04:54 +01:00
David Allan
8d42b9b4e8 Fix locking for udev device add/remove
The original udev node device backend neglected to lock the driverState
struct containing the device list when adding and removing devices
* src/node_device/node_device_udev.c: add necessary locks in
  udevRemoveOneDevice() and udevAddOneDevice()
2010-02-03 16:56:33 +01:00
Matthias Bolte
33e25a3984 udev: Don't let strtoul parse USB busnum and devnum as octal
udevGetUintProperty was called with base set to 0 for busnum and devnum.
With base 0 strtoul parses the number as octal if it start with a 0. But
busnum and devnum are decimal and udev returns them padded with leading
zeros. So strtoul parses them as octal. This works for certain decimal
values like 001-007, but fails for values like 008.

Change udevProcessUSBDevice to use base 10 for busnum and devnum.
2010-02-02 09:54:29 +01:00
Jim Meyering
b74aadb3e5 portability to non-glibc: don't use realpath(..., NULL)
it causes a NULL-dereference on some systems like Solaris 10.
* src/node_device/node_device_linux_sysfs.c. Include <stdlib.h>.
(get_sriov_function): Use canonicalize_file_name, not realpath.
* bootstrap (modules): Add canonicalize-lgpl.
2010-01-27 13:39:46 +01:00
Matthias Bolte
227f26afdb udev: Set the state driver name 2010-01-26 21:23:18 +01:00
Matthias Bolte
d115ed59e0 udev: Remove event handle on shutdown
This fixes a segfault when the event handler is called after shutdown
when the global driver state is NULL again.

Also fix a locking issue in an error path.
2010-01-26 21:23:18 +01:00