~ubuntu-branches/ubuntu/natty/libvirt/natty-proposed

« back to all changes in this revision

Viewing changes to src/node_device/node_device_udev.c

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Léonard
  • Date: 2010-07-06 12:14:33 UTC
  • mto: (3.4.17 sid) (1.2.6 upstream) (0.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 93.
  • Revision ID: james.westby@ubuntu.com-20100706121433-94utbax9zjvmkcsj
Tags: upstream-0.8.2
Import upstream version 0.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
 
58
58
    ret = virStrToLong_ull(s, end_ptr, base, result);
59
59
    if (ret != 0) {
60
 
        VIR_ERROR("Failed to convert '%s' to unsigned long long", s);
 
60
        VIR_ERROR(_("Failed to convert '%s' to unsigned long long"), s);
61
61
    } else {
62
62
        VIR_DEBUG("Converted '%s' to unsigned long %llu", s, *result);
63
63
    }
75
75
 
76
76
    ret = virStrToLong_ui(s, end_ptr, base, result);
77
77
    if (ret != 0) {
78
 
        VIR_ERROR("Failed to convert '%s' to unsigned int", s);
 
78
        VIR_ERROR(_("Failed to convert '%s' to unsigned int"), s);
79
79
    } else {
80
80
        VIR_DEBUG("Converted '%s' to unsigned int %u", s, *result);
81
81
    }
92
92
 
93
93
    ret = virStrToLong_i(s, end_ptr, base, result);
94
94
    if (ret != 0) {
95
 
        VIR_ERROR("Failed to convert '%s' to int", s);
 
95
        VIR_ERROR(_("Failed to convert '%s' to int"), s);
96
96
    } else {
97
97
        VIR_DEBUG("Converted '%s' to int %u", s, *result);
98
98
    }
122
122
     * of the function must also be changed. */
123
123
    *property_value = strdup(udev_value);
124
124
    if (*property_value == NULL) {
125
 
        VIR_ERROR("Failed to allocate memory for property value for "
126
 
                  "property key '%s' on device with sysname '%s'",
 
125
        VIR_ERROR(_("Failed to allocate memory for property value for "
 
126
                    "property key '%s' on device with sysname '%s'"),
127
127
                  property_key, udev_device_get_sysname(udev_device));
128
128
        virReportOOMError();
129
129
        ret = PROPERTY_ERROR;
211
211
     * of the function must also be changed. */
212
212
    *attr_value = strdup(udev_value);
213
213
    if (*attr_value == NULL) {
214
 
        VIR_ERROR("Failed to allocate memory for sysfs attribute value for "
215
 
                  "sysfs attribute '%s' on device with sysname '%s'",
 
214
        VIR_ERROR(_("Failed to allocate memory for sysfs attribute value for "
 
215
                    "sysfs attribute '%s' on device with sysname '%s'"),
216
216
                  attr_name, udev_device_get_sysname(udev_device));
217
217
        virReportOOMError();
218
218
        ret = PROPERTY_ERROR;
329
329
 
330
330
    if (virBufferError(&buf)) {
331
331
        virBufferFreeAndReset(&buf);
332
 
        VIR_ERROR("Buffer error when generating device name for device "
333
 
                  "with sysname '%s'", udev_device_get_sysname(device));
 
332
        VIR_ERROR(_("Buffer error when generating device name for device "
 
333
                    "with sysname '%s'"), udev_device_get_sysname(device));
334
334
        ret = -1;
335
335
    }
336
336
 
363
363
                               char **vendor_string,
364
364
                               char **product_string)
365
365
{
366
 
    int ret = -1;
 
366
    int ret = -1, pciret;
367
367
    struct pci_id_match m;
368
368
    const char *vendor_name = NULL, *device_name = NULL;
369
369
 
370
 
    if (pci_system_init() != 0) {
371
 
        VIR_ERROR0("Failed to initialize libpciaccess");
 
370
    if ((pciret = pci_system_init()) != 0) {
 
371
        char ebuf[256];
 
372
        VIR_INFO("Failed to initialize libpciaccess: %s",
 
373
                 virStrerror(pciret, ebuf, sizeof ebuf));
 
374
        ret = 0;
372
375
        goto out;
373
376
    }
374
377
 
382
385
 
383
386
    /* pci_get_strings returns void */
384
387
    pci_get_strings(&m,
 
388
                    &device_name,
385
389
                    &vendor_name,
386
 
                    &device_name,
387
390
                    NULL,
388
391
                    NULL);
389
392
 
597
600
                                       virNodeDeviceDefPtr def)
598
601
{
599
602
    int ret = -1;
 
603
    const char *devtype = udev_device_get_devtype(device);
600
604
    union _virNodeDevCapData *data = &def->caps->data;
601
605
 
 
606
    if (devtype && STREQ(devtype, "wlan")) {
 
607
        data->net.subtype = VIR_NODE_DEV_CAP_NET_80211;
 
608
    } else {
 
609
        data->net.subtype = VIR_NODE_DEV_CAP_NET_80203;
 
610
    }
 
611
 
602
612
    if (udevGetStringProperty(device,
603
613
                              "INTERFACE",
604
614
                              &data->net.ifname) == PROPERTY_ERROR) {
639
649
    filename = basename(def->sysfs_path);
640
650
 
641
651
    if (!STRPREFIX(filename, "host")) {
642
 
        VIR_ERROR("SCSI host found, but its udev name '%s' does "
643
 
                  "not begin with 'host'", filename);
 
652
        VIR_ERROR(_("SCSI host found, but its udev name '%s' does "
 
653
                    "not begin with 'host'"), filename);
644
654
        goto out;
645
655
    }
646
656
 
737
747
            ret = -1;
738
748
            virReportOOMError();
739
749
        } else {
740
 
            VIR_ERROR("Failed to find SCSI device type %d", type);
 
750
            VIR_ERROR(_("Failed to find SCSI device type %d"), type);
741
751
        }
742
752
    }
743
753
 
802
812
 
803
813
out:
804
814
    if (ret != 0) {
805
 
        VIR_ERROR("Failed to process SCSI device with sysfs path '%s'",
 
815
        VIR_ERROR(_("Failed to process SCSI device with sysfs path '%s'"),
806
816
                  def->sysfs_path);
807
817
    }
808
818
    return ret;
1074
1084
    int ret = 0;
1075
1085
 
1076
1086
    devtype = udev_device_get_devtype(device);
 
1087
    VIR_DEBUG("Found device type '%s' for device '%s'",
 
1088
              NULLSTR(devtype), udev_device_get_sysname(device));
1077
1089
 
1078
1090
    if (devtype != NULL && STREQ(devtype, "usb_device")) {
1079
1091
        *type = VIR_NODE_DEV_CAP_USB_DEV;
1105
1117
        goto out;
1106
1118
    }
1107
1119
 
 
1120
    if (devtype != NULL && STREQ(devtype, "wlan")) {
 
1121
        *type = VIR_NODE_DEV_CAP_NET;
 
1122
        goto out;
 
1123
    }
 
1124
 
1108
1125
    if (udevGetUintProperty(device, "PCI_CLASS", &tmp, 16) == PROPERTY_FOUND) {
1109
1126
        *type = VIR_NODE_DEV_CAP_PCI_DEV;
1110
1127
        goto out;
1111
1128
    }
1112
1129
 
1113
 
    /* It does not appear that network interfaces set the device type
1114
 
     * property. */
 
1130
    /* It does not appear that wired network interfaces set the
 
1131
     * DEVTYPE property.  USB devices also have an INTERFACE property,
 
1132
     * but they do set DEVTYPE, so if devtype is NULL and the
 
1133
     * INTERFACE property exists, we have a network device. */
1115
1134
    if (devtype == NULL &&
1116
1135
        udevGetStringProperty(device,
1117
1136
                              "INTERFACE",
1165
1184
        ret = udevProcessStorage(device, def);
1166
1185
        break;
1167
1186
    default:
1168
 
        VIR_ERROR("Unknown device type %d", def->caps->type);
 
1187
        VIR_ERROR(_("Unknown device type %d"), def->caps->type);
1169
1188
        ret = -1;
1170
1189
        break;
1171
1190
    }
1207
1226
    virNodeDeviceObjPtr dev = NULL;
1208
1227
    int ret = -1;
1209
1228
 
1210
 
    parent_device = udev_device_get_parent(device);
1211
 
    if (parent_device == NULL) {
1212
 
        VIR_INFO("Could not find udev parent for device with sysfs path '%s'",
1213
 
                 udev_device_get_syspath(device));
1214
 
    }
1215
 
 
1216
 
    parent_sysfs_path = udev_device_get_syspath(parent_device);
1217
 
    if (parent_sysfs_path == NULL) {
1218
 
        VIR_INFO("Could not get syspath for parent of '%s'",
1219
 
                 udev_device_get_syspath(device));
1220
 
        parent_sysfs_path = "";
1221
 
    }
1222
 
 
1223
 
    def->parent_sysfs_path = strdup(parent_sysfs_path);
1224
 
    if (def->parent_sysfs_path == NULL) {
1225
 
        virReportOOMError();
1226
 
        goto out;
1227
 
    }
1228
 
 
1229
 
    dev = virNodeDeviceFindBySysfsPath(&driverState->devs, parent_sysfs_path);
1230
 
    if (dev == NULL) {
 
1229
    parent_device = device;
 
1230
    do {
 
1231
 
 
1232
        parent_device = udev_device_get_parent(parent_device);
 
1233
        if (parent_device == NULL) {
 
1234
            break;
 
1235
        }
 
1236
 
 
1237
        parent_sysfs_path = udev_device_get_syspath(parent_device);
 
1238
        if (parent_sysfs_path == NULL) {
 
1239
            VIR_INFO("Could not get syspath for parent of '%s'",
 
1240
                     udev_device_get_syspath(parent_device));
 
1241
        }
 
1242
 
 
1243
        dev = virNodeDeviceFindBySysfsPath(&driverState->devs,
 
1244
                                           parent_sysfs_path);
 
1245
        if (dev != NULL) {
 
1246
            def->parent = strdup(dev->def->name);
 
1247
            virNodeDeviceObjUnlock(dev);
 
1248
 
 
1249
            if (def->parent == NULL) {
 
1250
                virReportOOMError();
 
1251
                goto out;
 
1252
            }
 
1253
 
 
1254
            def->parent_sysfs_path = strdup(parent_sysfs_path);
 
1255
            if (def->parent_sysfs_path == NULL) {
 
1256
                virReportOOMError();
 
1257
                goto out;
 
1258
            }
 
1259
 
 
1260
        }
 
1261
 
 
1262
    } while (def->parent == NULL && parent_device != NULL);
 
1263
 
 
1264
    if (def->parent == NULL) {
1231
1265
        def->parent = strdup("computer");
1232
 
    } else {
1233
 
        def->parent = strdup(dev->def->name);
1234
 
        virNodeDeviceObjUnlock(dev);
1235
1266
    }
1236
1267
 
1237
1268
    if (def->parent == NULL) {
1281
1312
        goto out;
1282
1313
    }
1283
1314
 
 
1315
    /* If this is a device change, the old definition will be freed
 
1316
     * and the current definition will take its place. */
1284
1317
    nodeDeviceLock(driverState);
1285
1318
    dev = virNodeDeviceAssignDef(&driverState->devs, def);
1286
1319
    nodeDeviceUnlock(driverState);
1287
1320
 
1288
1321
    if (dev == NULL) {
1289
 
        VIR_ERROR("Failed to create device for '%s'", def->name);
1290
 
        virNodeDeviceDefFree(def);
 
1322
        VIR_ERROR(_("Failed to create device for '%s'"), def->name);
1291
1323
        goto out;
1292
1324
    }
1293
1325
 
1296
1328
    ret = 0;
1297
1329
 
1298
1330
out:
 
1331
    if (ret != 0) {
 
1332
        virNodeDeviceDefFree(def);
 
1333
    }
 
1334
 
1299
1335
    return ret;
1300
1336
}
1301
1337
 
1310
1346
    name = udev_list_entry_get_name(list_entry);
1311
1347
 
1312
1348
    device = udev_device_new_from_syspath(udev, name);
 
1349
 
1313
1350
    if (device != NULL) {
1314
1351
        if (udevAddOneDevice(device) != 0) {
1315
1352
            VIR_INFO("Failed to create node device for udev device '%s'",
1316
1353
                     name);
1317
1354
        }
1318
 
        udev_device_unref(device);
1319
1355
        ret = 0;
1320
1356
    }
1321
1357
 
 
1358
    udev_device_unref(device);
 
1359
 
1322
1360
    return ret;
1323
1361
}
1324
1362
 
1333
1371
 
1334
1372
    ret = udev_enumerate_scan_devices(udev_enumerate);
1335
1373
    if (0 != ret) {
1336
 
        VIR_ERROR("udev scan devices returned %d", ret);
 
1374
        VIR_ERROR(_("udev scan devices returned %d"), ret);
1337
1375
        goto out;
1338
1376
    }
1339
1377
 
1401
1439
 
1402
1440
    udev_fd = udev_monitor_get_fd(udev_monitor);
1403
1441
    if (fd != udev_fd) {
1404
 
        VIR_ERROR("File descriptor returned by udev %d does not "
1405
 
                  "match node device file descriptor %d", fd, udev_fd);
 
1442
        VIR_ERROR(_("File descriptor returned by udev %d does not "
 
1443
                    "match node device file descriptor %d"), fd, udev_fd);
1406
1444
        goto out;
1407
1445
    }
1408
1446
 
1409
1447
    device = udev_monitor_receive_device(udev_monitor);
1410
1448
    if (device == NULL) {
1411
 
        VIR_ERROR0("udev_monitor_receive_device returned NULL");
 
1449
        VIR_ERROR0(_("udev_monitor_receive_device returned NULL"));
1412
1450
        goto out;
1413
1451
    }
1414
1452
 
1426
1464
    }
1427
1465
 
1428
1466
out:
 
1467
    udev_device_unref(device);
1429
1468
    return;
1430
1469
}
1431
1470
 
1443
1482
    if (device == NULL) {
1444
1483
        device = udev_device_new_from_syspath(udev, DMI_DEVPATH_FALLBACK);
1445
1484
        if (device == NULL) {
1446
 
            VIR_ERROR("Failed to get udev device for syspath '%s' or '%s'",
 
1485
            VIR_ERROR(_("Failed to get udev device for syspath '%s' or '%s'"),
1447
1486
                      DMI_DEVPATH, DMI_DEVPATH_FALLBACK);
1448
1487
            goto out;
1449
1488
        }
1473
1512
        goto out;
1474
1513
    }
1475
1514
 
1476
 
    if (udevGetStringSysfsAttr(device,
1477
 
                               "product_uuid",
1478
 
                               &tmp) == PROPERTY_ERROR) {
 
1515
    if (virGetHostUUID(data->system.hardware.uuid))
1479
1516
        goto out;
1480
 
    }
1481
 
    virUUIDParse(tmp, data->system.hardware.uuid);
1482
1517
 
1483
1518
    if (udevGetStringSysfsAttr(device,
1484
1519
                               "bios_vendor",
1534
1569
 
1535
1570
    dev = virNodeDeviceAssignDef(&driverState->devs, def);
1536
1571
    if (dev == NULL) {
1537
 
        VIR_ERROR("Failed to create device for '%s'", def->name);
 
1572
        VIR_ERROR(_("Failed to create device for '%s'"), def->name);
1538
1573
        goto out;
1539
1574
    }
1540
1575
 
1572
1607
    }
1573
1608
 
1574
1609
    if (virMutexInit(&driverState->lock) < 0) {
1575
 
        VIR_ERROR0("Failed to initialize mutex for driverState");
 
1610
        VIR_ERROR0(_("Failed to initialize mutex for driverState"));
1576
1611
        VIR_FREE(priv);
1577
1612
        VIR_FREE(driverState);
1578
1613
        ret = -1;
1594
1629
    if (priv->udev_monitor == NULL) {
1595
1630
        VIR_FREE(priv);
1596
1631
        nodeDeviceUnlock(driverState);
1597
 
        VIR_ERROR0("udev_monitor_new_from_netlink returned NULL");
 
1632
        VIR_ERROR0(_("udev_monitor_new_from_netlink returned NULL"));
1598
1633
        ret = -1;
1599
1634
        goto out;
1600
1635
    }