~ubuntu-branches/ubuntu/oneiric/libvirt/oneiric-updates

« back to all changes in this revision

Viewing changes to src/node_device/node_device_udev.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2011-05-11 12:29:51 UTC
  • mfrom: (1.2.10) (3.4.30 sid)
  • Revision ID: package-import@ubuntu.com-20110511122951-ku5fk1tv37o5aymm
Tags: 0.9.1-1ubuntu1
* Resynchronize and merge from Debian unstable (LP: #794378). Remaining
  changes:
  - debian/control:
    * set X-Python-Version to 2.7, as 2.6 is not in oneiric.
    * set ubuntu maintainer
    * Build-Depends:
      - remove [linux-any] from all dependencies
      - remove [!linux-any] deps
      - swap libxen to libxen3, qemu to qemu-kvm, and open-iscsi to
        open-iscsi-utils in Build-Depends
      - remove virtualbox-ose Build-Depends
      - add parted and libapparmor-dev Build-Depends
    * convert Vcs-Git to Xs-Debian-Vcs-Git
    * libvirt-bin Depends: move netcat-openbsd, bridge-utils, dnsmasq-base
      (>= 2.46-1), and iptables from Recommends to Depends
    * libvirt-bin Recommends: move qemu to Suggests
    * libvirt-bin Suggests: add apparmor
    * libvirt0 Recommands: move lvm2 to Suggests
  - keep debian/libvirt-bin.apport
  - keep debian/libvirt-bin.cron.daily
  - debian/libvirt-bin.dirs:
    * add apparmor, cron.daily, and apport dirs
  - debian/libvirt-bin.examples:
    * add debian/libvirt-suspendonreboot
  - debian/libvirt-bin.install:
    * add /etc/apparmor.d files
    * add apport hook
  - debian/libvirt-bin.manpages:
    * add debian/libvirt-migrate-qemu-disks.1
  - debian/libvirt-bin.postinst:
    * replace libvirt groupname with libvirtd
    * add each admin user to libvirtd group
    * call apparmor_parser on usr.sbin.libvirtd and
      usr.lib.libvirt.virt-aa-helper
    * call 'libvirt-migrate-qemu-disks -a' after
      libvirt-bin has started if migrating from
      older than 0.8.3-1ubuntu1
  - debian/libvirt-bin.postrm:
    * replace libvirt groupname with libvirtd
    * remove usr.sbin.libvirtd and
      usr.lib.libvirt.virt-aa-helper
  - keep added files under debian/:
    * libvirt-bin.upstart
    * libvirt-migrate-qemu-disks
    * libvirt-migrate-qemu-disks.1
    * libvirt-suspendonreboot
    * apparmor profiles
  - debian/README.Debian:
    * add 'Apparmor Profile' section
    * add 'Disk migration' section
  - debian/rules:
    * move include of debhelper.mk to top of file so DEB_HOST_ARCH_OS
      is defined.
    * don't build with vbox since virtualbox-ose is in universe
      - remove WITH_VBOX, add explicit --without-vbox
    * add --with-apparmor to DEB_CONFIGURE_EXTRA_FLAGS
    * set DEB_DH_INSTALLINIT_ARGS to '--upstart-only'
    * remove unneeded binary-install/libvirt-bin:: and clean::
      sections (they only deal with sysvinit stuff)
    * add build/libvirt-bin:: section to install
      - apparmor files
      - apport hooks
      - libvirt-migrate-qemu-disks
* debian/patches/series:
  - don't apply Disable-CHECKSUM-rule.patch: our iptables can do this
  - don't apply Debian-specific Debianize-libvirt-guests.patch (sysvinit only)
  - don't apply Disable qemu-disable-network.diff.patch
* debian/patches:
  - drop 9007-fix-daemon-conf-ftbfs.patch (looks like it may be fixed)
  - drop patches applied upstream:
    * 9022-drop-booton-when-kernel-specified.patch
    * 9023-fix-lxc-console-hangup.patch
    * 9024-fix-broken-commandtest.patch
    * 9025-Pass-virSecurityManagerPtr-to-virSecurityDAC-Set-Res.patch
    * 9026-security-avoid-memory-leak.patch
    * 9027-CVE-2011-1146.patch
  - keep patches:
    * 9000-delayed_iff_up_bridge.patch
    * 9001-dont_clobber_existing_bridges.patch
    * 9002-better_default_uri_virsh.patch
    * 9003-better-default-arch.patch
    * 9004-libvirtd-group-name.patch
    * 9005-increase-unix-socket-timeout.patch
    * 9006-default-config-test-case.patch
    * 9011-move-ebtables-script.patch (refreshed)
    * 9014-skip-nodeinfotest.patch (modified to make it apply)
    * 9020-lp545795.patch (modified to make it still apply)
    * 9021-fix-uint64_t.patch
    * 9022-allows-lxc-containers-with-lxcguest.patch (renamed, modified
      to make it still apply, and added DEP-3 tags).
  - new patches:
    * 9023-disable-test-poll.patch - don't run broken test-poll

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * node_device_udev.c: node device enumeration - libudev implementation
3
3
 *
4
 
 * Copyright (C) 2009-2010 Red Hat, Inc.
 
4
 * Copyright (C) 2009-2011 Red Hat, Inc.
5
5
 *
6
6
 * This library is free software; you can redistribute it and/or
7
7
 * modify it under the terms of the GNU Lesser General Public
415
415
    const char *syspath = NULL;
416
416
    union _virNodeDevCapData *data = &def->caps->data;
417
417
    int ret = -1;
 
418
    char *p;
418
419
 
419
420
    syspath = udev_device_get_syspath(device);
420
421
 
425
426
        goto out;
426
427
    }
427
428
 
428
 
    char *p = strrchr(syspath, '/');
 
429
    p = strrchr(syspath, '/');
429
430
 
430
431
    if ((p == NULL) || (udevStrToLong_ui(p+1,
431
432
                                         &p,
1201
1202
    int ret = 0;
1202
1203
 
1203
1204
    name = udev_device_get_syspath(device);
1204
 
    nodeDeviceLock(driverState);
1205
1205
    dev = virNodeDeviceFindBySysfsPath(&driverState->devs, name);
1206
1206
 
1207
1207
    if (dev != NULL) {
1213
1213
                  name);
1214
1214
        ret = -1;
1215
1215
    }
1216
 
    nodeDeviceUnlock(driverState);
1217
1216
 
1218
1217
    return ret;
1219
1218
}
1315
1314
 
1316
1315
    /* If this is a device change, the old definition will be freed
1317
1316
     * and the current definition will take its place. */
1318
 
    nodeDeviceLock(driverState);
1319
1317
    dev = virNodeDeviceAssignDef(&driverState->devs, def);
1320
 
    nodeDeviceUnlock(driverState);
1321
1318
 
1322
1319
    if (dev == NULL) {
1323
1320
        VIR_ERROR(_("Failed to create device for '%s'"), def->name);
1424
1421
        ret = -1;
1425
1422
    }
1426
1423
 
 
1424
#if defined __s390__ || defined __s390x_
 
1425
    /* Nothing was initialized, nothing needs to be cleaned up */
 
1426
#else
1427
1427
    /* pci_system_cleanup returns void */
1428
1428
    pci_system_cleanup();
 
1429
#endif
1429
1430
 
1430
1431
    return ret;
1431
1432
}
1441
1442
    const char *action = NULL;
1442
1443
    int udev_fd = -1;
1443
1444
 
 
1445
    nodeDeviceLock(driverState);
1444
1446
    udev_fd = udev_monitor_get_fd(udev_monitor);
1445
1447
    if (fd != udev_fd) {
1446
1448
        VIR_ERROR(_("File descriptor returned by udev %d does not "
1469
1471
 
1470
1472
out:
1471
1473
    udev_device_unref(device);
 
1474
    nodeDeviceUnlock(driverState);
1472
1475
    return;
1473
1476
}
1474
1477
 
1589
1592
    return ret;
1590
1593
}
1591
1594
 
1592
 
static int udevDeviceMonitorStartup(int privileged ATTRIBUTE_UNUSED)
 
1595
static int udevDeviceMonitorStartup(int privileged)
1593
1596
{
1594
1597
    udevPrivate *priv = NULL;
1595
1598
    struct udev *udev = NULL;
1596
1599
    int ret = 0;
 
1600
 
 
1601
#if defined __s390__ || defined __s390x_
 
1602
    /* On s390(x) system there is no PCI bus.
 
1603
     * Therefore there is nothing to initialize here. */
 
1604
#else
1597
1605
    int pciret;
1598
1606
 
1599
1607
    if ((pciret = pci_system_init()) != 0) {
1600
 
        char ebuf[256];
1601
 
        VIR_ERROR(_("Failed to initialize libpciaccess: %s"),
1602
 
                  virStrerror(pciret, ebuf, sizeof ebuf));
1603
 
        ret = -1;
1604
 
        goto out;
 
1608
        /* Ignore failure as non-root; udev is not as helpful in that
 
1609
         * situation, but a non-privileged user won't benefit much
 
1610
         * from udev in the first place.  */
 
1611
        if (privileged || errno != EACCES) {
 
1612
            char ebuf[256];
 
1613
            VIR_ERROR(_("Failed to initialize libpciaccess: %s"),
 
1614
                      virStrerror(pciret, ebuf, sizeof ebuf));
 
1615
            ret = -1;
 
1616
            goto out;
 
1617
        }
1605
1618
    }
 
1619
#endif
1606
1620
 
1607
1621
    if (VIR_ALLOC(priv) < 0) {
1608
1622
        virReportOOMError();
1641
1655
    priv->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
1642
1656
    if (priv->udev_monitor == NULL) {
1643
1657
        VIR_FREE(priv);
1644
 
        nodeDeviceUnlock(driverState);
1645
1658
        VIR_ERROR0(_("udev_monitor_new_from_netlink returned NULL"));
1646
1659
        ret = -1;
1647
 
        goto out;
 
1660
        goto out_unlock;
1648
1661
    }
1649
1662
 
1650
1663
    udev_monitor_enable_receiving(priv->udev_monitor);
1664
1677
                                    VIR_EVENT_HANDLE_READABLE,
1665
1678
                                    udevEventHandleCallback, NULL, NULL);
1666
1679
    if (priv->watch == -1) {
1667
 
        nodeDeviceUnlock(driverState);
1668
1680
        ret = -1;
1669
 
        goto out;
 
1681
        goto out_unlock;
1670
1682
    }
1671
1683
 
1672
 
    nodeDeviceUnlock(driverState);
1673
 
 
1674
1684
    /* Create a fictional 'computer' device to root the device tree. */
1675
1685
    if (udevSetupSystemDev() != 0) {
1676
1686
        ret = -1;
1677
 
        goto out;
 
1687
        goto out_unlock;
1678
1688
    }
1679
1689
 
1680
1690
    /* Populate with known devices */
1681
1691
 
1682
1692
    if (udevEnumerateDevices(udev) != 0) {
1683
1693
        ret = -1;
1684
 
        goto out;
 
1694
        goto out_unlock;
1685
1695
    }
1686
1696
 
 
1697
out_unlock:
 
1698
    nodeDeviceUnlock(driverState);
 
1699
 
1687
1700
out:
1688
1701
    if (ret == -1) {
1689
1702
        udevDeviceMonitorShutdown();