~serge-hallyn/ubuntu/raring/libvirt/libvirt-hugepages

« back to all changes in this revision

Viewing changes to src/util/sysinfo.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-07-11 12:37:49 UTC
  • mfrom: (1.2.14)
  • Revision ID: package-import@ubuntu.com-20120711123749-gt314clvb7840c6p
Tags: 0.9.13-0ubuntu1
* New upstream version: 
* debian/rules: Remove .la files
* debian/control: Dropped debian vcs info.
* Dropped:
  - debian/paches/9022-pass-the-virt-driver-name-into-security-drivers:
    Already applied upstream.
  - debian/patches/9023-dont-enable-apparmor-driver-with-lxc
    Already applied upstream.
  - debian/patches/9024-initialize-random-generator-in-lxc:
    Already applied upstream.
* Re-diffed:
  - debian/patches/9002-better_default_uri_virsh.patch
* Added:
  - debian/patches/add-libvirt-highbank-support.patch: Add highbank 
    CPU detection support.
  - debian/patches/fix-lxc-container-unmounting.patch: Fix container
    mounting.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
                         __FUNCTION__, __LINE__, __VA_ARGS__)
45
45
 
46
46
#define SYSINFO_SMBIOS_DECODER "dmidecode"
 
47
#define SYSINFO "/proc/sysinfo"
47
48
#define CPUINFO "/proc/cpuinfo"
48
49
 
49
50
VIR_ENUM_IMPL(virSysinfo, VIR_SYSINFO_LAST,
241
242
    return NULL;
242
243
}
243
244
 
 
245
#elif defined(__s390__) || defined(__s390x__)
 
246
 
 
247
static int
 
248
virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret)
 
249
{
 
250
    char *cur, *eol = NULL;
 
251
    const char *property;
 
252
 
 
253
    /* Return if Manufacturer field is not found */
 
254
    if ((cur = strstr(base, "Manufacturer")) == NULL)
 
255
        return 0;
 
256
 
 
257
    base = cur;
 
258
    if ((cur = strstr(base, "Manufacturer")) != NULL) {
 
259
        cur = strchr(cur, ':') + 1;
 
260
        eol = strchr(cur, '\n');
 
261
        virSkipSpacesBackwards(cur, &eol);
 
262
        if ((eol) && ((property = strndup(cur, eol - cur)) == NULL))
 
263
            goto no_memory;
 
264
        virSkipSpaces(&property);
 
265
        ret->system_manufacturer = (char *) property;
 
266
    }
 
267
    if ((cur = strstr(base, "Type")) != NULL) {
 
268
        cur = strchr(cur, ':') + 1;
 
269
        eol = strchr(cur, '\n');
 
270
        virSkipSpacesBackwards(cur, &eol);
 
271
        if ((eol) && ((property = strndup(cur, eol - cur)) == NULL))
 
272
            goto no_memory;
 
273
        virSkipSpaces(&property);
 
274
        ret->system_family = (char *) property;
 
275
    }
 
276
    if ((cur = strstr(base, "Sequence Code")) != NULL) {
 
277
        cur = strchr(cur, ':') + 1;
 
278
        eol = strchr(cur, '\n');
 
279
        virSkipSpacesBackwards(cur, &eol);
 
280
        if ((eol) && ((property = strndup(cur, eol - cur)) == NULL))
 
281
            goto no_memory;
 
282
        virSkipSpaces(&property);
 
283
        ret->system_serial = (char *) property;
 
284
    }
 
285
 
 
286
    return 0;
 
287
 
 
288
no_memory:
 
289
    return -1;
 
290
}
 
291
 
 
292
static int
 
293
virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret)
 
294
{
 
295
    char *cur, *eol, *tmp_base;
 
296
    char *manufacturer;
 
297
    const char *tmp;
 
298
    virSysinfoProcessorDefPtr processor;
 
299
 
 
300
    if ((cur = strstr(base, "vendor_id")) != NULL) {
 
301
        cur = strchr(cur, ':') + 1;
 
302
        eol = strchr(cur, '\n');
 
303
        virSkipSpacesBackwards(cur, &eol);
 
304
        if ((eol) && ((tmp = strndup(cur, eol - cur)) == NULL))
 
305
            goto no_memory;
 
306
        virSkipSpaces(&tmp);
 
307
        manufacturer = (char *) tmp;
 
308
    }
 
309
 
 
310
    /* Find processor N: line and gather the processor manufacturer, version,
 
311
     * serial number, and family */
 
312
    while ((tmp_base = strstr(base, "processor ")) != NULL) {
 
313
        base = tmp_base;
 
314
        eol = strchr(base, '\n');
 
315
        cur = strchr(base, ':') + 1;
 
316
 
 
317
        if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) {
 
318
            goto no_memory;
 
319
        }
 
320
 
 
321
        processor = &ret->processor[ret->nprocessor - 1];
 
322
 
 
323
        /* Set the processor manufacturer */
 
324
        processor->processor_manufacturer = manufacturer;
 
325
 
 
326
        if ((cur = strstr(base, "version =")) != NULL) {
 
327
            cur += sizeof("version =");
 
328
            eol = strchr(cur, ',');
 
329
            if ((eol) &&
 
330
                ((processor->processor_version = strndup(cur, eol - cur)) == NULL))
 
331
                goto no_memory;
 
332
        }
 
333
        if ((cur = strstr(base, "identification =")) != NULL) {
 
334
            cur += sizeof("identification =");
 
335
            eol = strchr(cur, ',');
 
336
            if ((eol) &&
 
337
                ((processor->processor_serial_number = strndup(cur, eol - cur)) == NULL))
 
338
                goto no_memory;
 
339
        }
 
340
        if ((cur = strstr(base, "machine =")) != NULL) {
 
341
            cur += sizeof("machine =");
 
342
            eol = strchr(cur, '\n');
 
343
            if ((eol) &&
 
344
                ((processor->processor_family = strndup(cur, eol - cur)) == NULL))
 
345
                goto no_memory;
 
346
        }
 
347
 
 
348
        base = cur;
 
349
    }
 
350
 
 
351
    return 0;
 
352
 
 
353
no_memory:
 
354
    return -1;
 
355
}
 
356
 
 
357
/* virSysinfoRead for s390x
 
358
 * Gathers sysinfo data from /proc/sysinfo and /proc/cpuinfo */
 
359
virSysinfoDefPtr
 
360
virSysinfoRead(void) {
 
361
    virSysinfoDefPtr ret = NULL;
 
362
    char *outbuf = NULL;
 
363
 
 
364
    if (VIR_ALLOC(ret) < 0)
 
365
        goto no_memory;
 
366
 
 
367
    /* Gather info from /proc/cpuinfo */
 
368
    if (virFileReadAll(CPUINFO, 2048, &outbuf) < 0) {
 
369
        virSmbiosReportError(VIR_ERR_INTERNAL_ERROR,
 
370
                             _("Failed to open %s"), CPUINFO);
 
371
        return NULL;
 
372
    }
 
373
 
 
374
    ret->nprocessor = 0;
 
375
    ret->processor = NULL;
 
376
    if (virSysinfoParseProcessor(outbuf, ret) < 0)
 
377
        goto no_memory;
 
378
 
 
379
    /* Free buffer before reading next file */
 
380
    VIR_FREE(outbuf);
 
381
 
 
382
    /* Gather info from /proc/sysinfo */
 
383
    if (virFileReadAll(SYSINFO, 4096, &outbuf) < 0) {
 
384
        virSmbiosReportError(VIR_ERR_INTERNAL_ERROR,
 
385
                             _("Failed to open %s"), SYSINFO);
 
386
        return NULL;
 
387
    }
 
388
 
 
389
    if (virSysinfoParseSystem(outbuf, ret) < 0)
 
390
        goto no_memory;
 
391
 
 
392
    return ret;
 
393
 
 
394
no_memory:
 
395
    VIR_FREE(outbuf);
 
396
    return NULL;
 
397
}
 
398
 
244
399
#elif defined(WIN32) || \
245
400
    !(defined(__x86_64__) || \
246
401
      defined(__i386__) ||   \