~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-05-13 15:44:12 UTC
  • mfrom: (1.2.13)
  • Revision ID: package-import@ubuntu.com-20120513154412-fgmn5sxqdzgnzlx3
Tags: 0.9.12-0ubuntu1
* New upstream version:
  * Synchronize with debian packaging:
    - debian/control: Update build depends.
    - debian/libvirt-bin.postrm: Cleanup /var/log/libvirt
      on purge.
    - Bump standards verson (no changes).
    - debian/patches/Don-t-fail-if-we-can-t-setup-avahi.patch: Added
  * Dropped patches:
    - debian/patches/Debianize-libvirt-guests.patch
    - debian/patches/rewrite-lxc-controller-eof-handling-yet-again
    - debian/patches/ubuntu/libnl13.patch
    - debian/patches/ubuntu/fix-lxc-startup-error.patch
    - debian/patches/ubuntu/fix-bridge-fd.patch
    - debian/patches/ubuntu/skip-labelling-network-disks.patch
    - debian/patches/ubuntu/xen-xend-shutdown-detection.patch
    - debian/patches/ubuntu/xen-config-no-vfb-for-hvm.patch
    - debian/patches/debian/Disable-daemon-start-test.patch
    - debian/patches/debian/Disable-gnulib-s-test-nonplocking-pipe.sh.patch
    - debian/patches/ubuntu/9006-default-config-test-case.patch
    - debian/patches/fix-block-migration.patch
    - debian/patches/ubuntu/9022-qemu-unescape-HMP-commands-before-converting-them-to.patch
    - debian/patches/ubuntu/9023-qemu-change-rbd-auth_supported-separation-character-.patch
    - debian/patches/ubuntu/9024-qemu-allow-snapshotting-of-sheepdog-and-rbd-disks.patch
    - debian/patches/9025-qemu-change-rbd-auth_supported-separation-character-.patch
    - debian/patches/ubuntu/arm-gcc-workaround.patch
  * Rediffed:
    - debian/patches/Allow-libvirt-group-to-access-the-socket.patch
    - debian/patches/Disable-failing-virnetsockettest.patch
    - debian/patches/dnsmasq-as-priv-user
    - debian/patches/9002-better_default_uri_virsh.patch
  * debian/control: Add libnl-route-3-dev ass a build depends.
  * debian/patches/libnl3-build-fix.patch: Fix build with libnl3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * sysinfo.c: get SMBIOS/sysinfo information from the host
3
3
 *
4
 
 * Copyright (C) 2010-2011 Red Hat, Inc.
 
4
 * Copyright (C) 2010-2012 Red Hat, Inc.
5
5
 * Copyright (C) 2010 Daniel Veillard
6
6
 *
7
7
 * This library is free software; you can redistribute it and/or
44
44
                         __FUNCTION__, __LINE__, __VA_ARGS__)
45
45
 
46
46
#define SYSINFO_SMBIOS_DECODER "dmidecode"
 
47
#define CPUINFO "/proc/cpuinfo"
47
48
 
48
49
VIR_ENUM_IMPL(virSysinfo, VIR_SYSINFO_LAST,
49
50
              "smbios");
113
114
 *
114
115
 * Returns: a filled up sysinfo structure or NULL in case of error
115
116
 */
116
 
#if defined(WIN32) || \
 
117
 
 
118
#if defined(__powerpc__)
 
119
static int
 
120
virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret)
 
121
{
 
122
    char *eol = NULL;
 
123
    const char *cur;
 
124
 
 
125
    if ((cur = strstr(base, "platform")) == NULL)
 
126
        return 0;
 
127
 
 
128
    base = cur;
 
129
    /* Account for format 'platform    : XXXX'*/
 
130
    cur = strchr(cur, ':') + 1;
 
131
    eol = strchr(cur, '\n');
 
132
    virSkipSpaces(&cur);
 
133
    if (eol &&
 
134
       ((ret->system_family = strndup(cur, eol - cur)) == NULL))
 
135
         goto no_memory;
 
136
 
 
137
    if ((cur = strstr(base, "model")) != NULL) {
 
138
        cur = strchr(cur, ':') + 1;
 
139
        eol = strchr(cur, '\n');
 
140
        virSkipSpaces(&cur);
 
141
        if (eol && ((ret->system_serial = strndup(cur, eol - cur))
 
142
                                                           == NULL))
 
143
            goto no_memory;
 
144
    }
 
145
 
 
146
    if ((cur = strstr(base, "machine")) != NULL) {
 
147
        cur = strchr(cur, ':') + 1;
 
148
        eol = strchr(cur, '\n');
 
149
        virSkipSpaces(&cur);
 
150
        if (eol && ((ret->system_version = strndup(cur, eol - cur))
 
151
                                                            == NULL))
 
152
            goto no_memory;
 
153
    }
 
154
 
 
155
    return 0;
 
156
 
 
157
no_memory:
 
158
    return -1;
 
159
}
 
160
 
 
161
static int
 
162
virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret)
 
163
{
 
164
    const char *cur;
 
165
    char *eol, *tmp_base;
 
166
    virSysinfoProcessorDefPtr processor;
 
167
 
 
168
    while((tmp_base = strstr(base, "processor")) != NULL) {
 
169
        base = tmp_base;
 
170
        eol = strchr(base, '\n');
 
171
        cur = strchr(base, ':') + 1;
 
172
 
 
173
        if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) {
 
174
            goto no_memory;
 
175
        }
 
176
        processor = &ret->processor[ret->nprocessor - 1];
 
177
 
 
178
        virSkipSpaces(&cur);
 
179
        if (eol &&
 
180
            ((processor->processor_socket_destination = strndup
 
181
                                     (cur, eol - cur)) == NULL))
 
182
            goto no_memory;
 
183
 
 
184
        if ((cur = strstr(base, "cpu")) != NULL) {
 
185
            cur = strchr(cur, ':') + 1;
 
186
            eol = strchr(cur, '\n');
 
187
            virSkipSpaces(&cur);
 
188
            if (eol &&
 
189
               ((processor->processor_type = strndup(cur, eol - cur))
 
190
                                                             == NULL))
 
191
                goto no_memory;
 
192
        }
 
193
 
 
194
        if ((cur = strstr(base, "revision")) != NULL) {
 
195
            cur = strchr(cur, ':') + 1;
 
196
            eol = strchr(cur, '\n');
 
197
            virSkipSpaces(&cur);
 
198
            if (eol &&
 
199
               ((processor->processor_version = strndup(cur, eol - cur))
 
200
                                                                == NULL))
 
201
                goto no_memory;
 
202
        }
 
203
 
 
204
        base = cur;
 
205
    }
 
206
 
 
207
    return 0;
 
208
 
 
209
no_memory:
 
210
    return -1;
 
211
}
 
212
 
 
213
/* virSysinfoRead for PowerPC
 
214
 * Gathers sysinfo data from /proc/cpuinfo */
 
215
virSysinfoDefPtr
 
216
virSysinfoRead(void) {
 
217
    virSysinfoDefPtr ret = NULL;
 
218
    char *outbuf = NULL;
 
219
 
 
220
    if (VIR_ALLOC(ret) < 0)
 
221
        goto no_memory;
 
222
 
 
223
    if(virFileReadAll(CPUINFO, 2048, &outbuf) < 0) {
 
224
        virSmbiosReportError(VIR_ERR_INTERNAL_ERROR,
 
225
                             _("Failed to open %s"), CPUINFO);
 
226
        return NULL;
 
227
    }
 
228
 
 
229
    ret->nprocessor = 0;
 
230
    ret->processor = NULL;
 
231
    if (virSysinfoParseProcessor(outbuf, ret) < 0)
 
232
        goto no_memory;
 
233
 
 
234
    if (virSysinfoParseSystem(outbuf, ret) < 0)
 
235
        goto no_memory;
 
236
 
 
237
    return ret;
 
238
 
 
239
no_memory:
 
240
    VIR_FREE(outbuf);
 
241
    return NULL;
 
242
}
 
243
 
 
244
#elif defined(WIN32) || \
117
245
    !(defined(__x86_64__) || \
118
246
      defined(__i386__) ||   \
119
 
      defined(__amd64__))
 
247
      defined(__amd64__) || \
 
248
      defined(__powerpc__))
120
249
virSysinfoDefPtr
121
250
virSysinfoRead(void) {
122
251
    /*
130
259
 
131
260
#else /* !WIN32 && x86 */
132
261
 
133
 
static char *
134
 
virSysinfoParseBIOS(char *base, virSysinfoDefPtr ret)
 
262
static int
 
263
virSysinfoParseBIOS(const char *base, virSysinfoDefPtr ret)
135
264
{
136
 
    char *cur, *eol = NULL;
 
265
    const char *cur, *eol = NULL;
137
266
 
138
267
    if ((cur = strstr(base, "BIOS Information")) == NULL)
139
 
        return base;
 
268
        return 0;
140
269
 
141
270
    base = cur;
142
271
    if ((cur = strstr(base, "Vendor: ")) != NULL) {
164
293
            goto no_memory;
165
294
    }
166
295
 
167
 
    return base + strlen("BIOS Information");
 
296
    return 0;
168
297
 
169
298
no_memory:
170
 
    return NULL;
 
299
    return -1;
171
300
}
172
301
 
173
 
static char *
174
 
virSysinfoParseSystem(char *base, virSysinfoDefPtr ret)
 
302
static int
 
303
virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret)
175
304
{
176
 
    char *cur, *eol = NULL;
 
305
    const char *cur, *eol = NULL;
177
306
 
178
307
    if ((cur = strstr(base, "System Information")) == NULL)
179
 
        return base;
 
308
        return 0;
180
309
 
181
310
    base = cur;
182
311
    if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
223
352
            goto no_memory;
224
353
    }
225
354
 
226
 
    return base + strlen("System Information");
 
355
    return 0;
227
356
 
228
357
no_memory:
229
 
    return NULL;
 
358
    return -1;
230
359
}
231
360
 
232
 
static char *
233
 
virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret)
 
361
static int
 
362
virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret)
234
363
{
235
 
    char *cur, *eol, *tmp_base;
 
364
    const char *cur, *tmp_base;
 
365
    char *eol;
236
366
    virSysinfoProcessorDefPtr processor;
237
367
 
238
368
    while((tmp_base = strstr(base, "Processor Information")) != NULL) {
249
379
            eol = strchr(cur, '\n');
250
380
            virSkipSpacesBackwards(cur, &eol);
251
381
            if ((eol) &&
252
 
                ((processor->processor_socket_destination = strndup(cur, eol - cur)) == NULL))
 
382
                ((processor->processor_socket_destination
 
383
                  = strndup(cur, eol - cur)) == NULL))
253
384
                goto no_memory;
254
385
        }
255
386
        if ((cur = strstr(base, "Type: ")) != NULL) {
265
396
            eol = strchr(cur, '\n');
266
397
            virSkipSpacesBackwards(cur, &eol);
267
398
            if ((eol) &&
268
 
                ((processor->processor_family = strndup(cur, eol - cur)) == NULL))
 
399
                ((processor->processor_family = strndup(cur,
 
400
                                                        eol - cur)) == NULL))
269
401
                goto no_memory;
270
402
        }
271
403
        if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
273
405
            eol = strchr(cur, '\n');
274
406
            virSkipSpacesBackwards(cur, &eol);
275
407
            if ((eol) &&
276
 
                ((processor->processor_manufacturer = strndup(cur, eol - cur)) == NULL))
 
408
                ((processor->processor_manufacturer
 
409
                  = strndup(cur, eol - cur)) == NULL))
277
410
                goto no_memory;
278
411
        }
279
412
        if ((cur = strstr(base, "Signature: ")) != NULL) {
281
414
            eol = strchr(cur, '\n');
282
415
            virSkipSpacesBackwards(cur, &eol);
283
416
            if ((eol) &&
284
 
                ((processor->processor_signature = strndup(cur, eol - cur)) == NULL))
 
417
                ((processor->processor_signature
 
418
                  = strndup(cur, eol - cur)) == NULL))
285
419
                goto no_memory;
286
420
        }
287
421
        if ((cur = strstr(base, "Version: ")) != NULL) {
289
423
            eol = strchr(cur, '\n');
290
424
            virSkipSpacesBackwards(cur, &eol);
291
425
            if ((eol) &&
292
 
                ((processor->processor_version = strndup(cur, eol - cur)) == NULL))
 
426
                ((processor->processor_version = strndup(cur,
 
427
                                                         eol - cur)) == NULL))
293
428
                goto no_memory;
294
429
        }
295
430
        if ((cur = strstr(base, "External Clock: ")) != NULL) {
297
432
            eol = strchr(cur, '\n');
298
433
            virSkipSpacesBackwards(cur, &eol);
299
434
            if ((eol) &&
300
 
                ((processor->processor_external_clock = strndup(cur, eol - cur)) == NULL))
 
435
                ((processor->processor_external_clock
 
436
                  = strndup(cur, eol - cur)) == NULL))
301
437
                goto no_memory;
302
438
        }
303
439
        if ((cur = strstr(base, "Max Speed: ")) != NULL) {
305
441
            eol = strchr(cur, '\n');
306
442
            virSkipSpacesBackwards(cur, &eol);
307
443
            if ((eol) &&
308
 
                ((processor->processor_max_speed = strndup(cur, eol - cur)) == NULL))
 
444
                ((processor->processor_max_speed
 
445
                  = strndup(cur, eol - cur)) == NULL))
309
446
                goto no_memory;
310
447
        }
311
448
        if ((cur = strstr(base, "Status: ")) != NULL) {
313
450
            eol = strchr(cur, '\n');
314
451
            virSkipSpacesBackwards(cur, &eol);
315
452
            if ((eol) &&
316
 
                ((processor->processor_status = strndup(cur, eol - cur)) == NULL))
 
453
                ((processor->processor_status = strndup(cur,
 
454
                                                        eol - cur)) == NULL))
317
455
                goto no_memory;
318
456
        }
319
457
        if ((cur = strstr(base, "Serial Number: ")) != NULL) {
321
459
            eol = strchr(cur, '\n');
322
460
            virSkipSpacesBackwards(cur, &eol);
323
461
            if ((eol) &&
324
 
                ((processor->processor_serial_number = strndup(cur, eol - cur)) == NULL))
 
462
                ((processor->processor_serial_number
 
463
                  = strndup(cur, eol - cur)) == NULL))
325
464
                goto no_memory;
326
465
        }
327
466
        if ((cur = strstr(base, "Part Number: ")) != NULL) {
329
468
            eol = strchr(cur, '\n');
330
469
            virSkipSpacesBackwards(cur, &eol);
331
470
            if ((eol) &&
332
 
                ((processor->processor_part_number = strndup(cur, eol - cur)) == NULL))
 
471
                ((processor->processor_part_number
 
472
                  = strndup(cur, eol - cur)) == NULL))
333
473
                goto no_memory;
334
474
        }
335
475
 
336
476
        base += strlen("Processor Information");
337
477
    }
338
478
 
339
 
    return base;
 
479
    return 0;
340
480
 
341
481
no_memory:
342
 
    return NULL;
 
482
    return -1;
343
483
}
344
484
 
345
 
static char *
346
 
virSysinfoParseMemory(char *base, virSysinfoDefPtr ret)
 
485
static int
 
486
virSysinfoParseMemory(const char *base, virSysinfoDefPtr ret)
347
487
{
348
 
    char *cur, *eol, *tmp_base;
 
488
    const char *cur, *tmp_base;
 
489
    char *eol;
349
490
    virSysinfoMemoryDefPtr memory;
350
491
 
351
492
    while ((tmp_base = strstr(base, "Memory Device")) != NULL) {
373
514
            eol = strchr(cur, '\n');
374
515
            virSkipSpacesBackwards(cur, &eol);
375
516
            if ((eol) &&
376
 
                ((memory->memory_form_factor = strndup(cur, eol - cur)) == NULL))
 
517
                ((memory->memory_form_factor = strndup(cur,
 
518
                                                       eol - cur)) == NULL))
377
519
                goto no_memory;
378
520
        }
379
521
        if ((cur = strstr(base, "Locator: ")) != NULL) {
389
531
            eol = strchr(cur, '\n');
390
532
            virSkipSpacesBackwards(cur, &eol);
391
533
            if ((eol) &&
392
 
                ((memory->memory_bank_locator = strndup(cur, eol - cur)) == NULL))
 
534
                ((memory->memory_bank_locator = strndup(cur,
 
535
                                                        eol - cur)) == NULL))
393
536
                goto no_memory;
394
537
        }
395
538
        if ((cur = strstr(base, "Type: ")) != NULL) {
405
548
            eol = strchr(cur, '\n');
406
549
            virSkipSpacesBackwards(cur, &eol);
407
550
            if ((eol) &&
408
 
                ((memory->memory_type_detail = strndup(cur, eol - cur)) == NULL))
 
551
                ((memory->memory_type_detail = strndup(cur,
 
552
                                                       eol - cur)) == NULL))
409
553
                goto no_memory;
410
554
        }
411
555
        if ((cur = strstr(base, "Speed: ")) != NULL) {
421
565
            eol = strchr(cur, '\n');
422
566
            virSkipSpacesBackwards(cur, &eol);
423
567
            if ((eol) &&
424
 
                ((memory->memory_manufacturer = strndup(cur, eol - cur)) == NULL))
 
568
                ((memory->memory_manufacturer = strndup(cur,
 
569
                                                        eol - cur)) == NULL))
425
570
                goto no_memory;
426
571
        }
427
572
        if ((cur = strstr(base, "Serial Number: ")) != NULL) {
429
574
            eol = strchr(cur, '\n');
430
575
            virSkipSpacesBackwards(cur, &eol);
431
576
            if ((eol) &&
432
 
                ((memory->memory_serial_number = strndup(cur, eol - cur)) == NULL))
 
577
                ((memory->memory_serial_number = strndup(cur,
 
578
                                                         eol - cur)) == NULL))
433
579
                goto no_memory;
434
580
        }
435
581
        if ((cur = strstr(base, "Part Number: ")) != NULL) {
437
583
            eol = strchr(cur, '\n');
438
584
            virSkipSpacesBackwards(cur, &eol);
439
585
            if ((eol) &&
440
 
                ((memory->memory_part_number = strndup(cur, eol - cur)) == NULL))
 
586
                ((memory->memory_part_number = strndup(cur,
 
587
                                                       eol - cur)) == NULL))
441
588
                goto no_memory;
442
589
        }
443
590
 
445
592
        base += strlen("Memory Device");
446
593
    }
447
594
 
448
 
    return base;
 
595
    return 0;
449
596
 
450
597
no_memory:
451
 
    return NULL;
 
598
    return -1;
452
599
}
453
600
 
454
601
virSysinfoDefPtr
455
602
virSysinfoRead(void) {
456
 
    char *path, *base;
 
603
    char *path;
457
604
    virSysinfoDefPtr ret = NULL;
458
605
    char *outbuf = NULL;
459
606
    virCommandPtr cmd;
481
628
 
482
629
    ret->type = VIR_SYSINFO_SMBIOS;
483
630
 
484
 
    base = outbuf;
485
 
 
486
 
    if ((base = virSysinfoParseBIOS(base, ret)) == NULL)
 
631
    if (virSysinfoParseBIOS(outbuf, ret) < 0)
487
632
        goto no_memory;
488
633
 
489
 
    if ((base = virSysinfoParseSystem(base, ret)) == NULL)
 
634
    if (virSysinfoParseSystem(outbuf, ret) < 0)
490
635
        goto no_memory;
491
636
 
492
637
    ret->nprocessor = 0;
493
638
    ret->processor = NULL;
494
 
    if ((base = virSysinfoParseProcessor(base, ret)) == NULL)
 
639
    if (virSysinfoParseProcessor(outbuf, ret) < 0)
495
640
        goto no_memory;
496
641
 
497
642
    ret->nmemory = 0;
498
643
    ret->memory = NULL;
499
 
    if (virSysinfoParseMemory(base, ret) == NULL)
 
644
    if (virSysinfoParseMemory(outbuf, ret) < 0)
500
645
        goto no_memory;
501
646
 
502
647
cleanup: