Daniel,
As we discussed, here is the program I was using for testing different
topology strings.
--
Elizabeth Kon (Beth)
IBM Linux Technology Center
Open Hypervisor Team
email: eak@xxxxxxxxxx
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
#include <stdlib.h>
int
getNumber (char * pointer, int * result) {
int i = 0, ret;
while (isdigit(*(pointer + i)))
i++;
if (i == 0)
return -1;
*(result) = atoi(pointer);
return (i);
}
main(){
char string1[1024] = "node0:0-3,7,9-10\n node1:11-14\n";
// char string1[1024] = "node0:4,7\n";
// char string1[1024] = "node0:8-9,11\n";
// char string1[1024] = "node0:0,3,7,9\n node21:11,14\n";
// char string1[1024] = "node0:9\n node21:11\n node33:12-14\n";
// char string1[1024] = "node0:0\n";
// char string1[1024] = "node0:0-3\n node1:4,5-9\n";
// char string1[1024] = "node0:0-3\n \n";
// char string1[1024] = "node0:0\n node1:4,6-9\n";
// char string1[1024] = "node0:Easeirasde1:4,6-9\n";
// char string1[1024] = "node0:0-3-7,9-10\n node1:11-14\n";
// char string1[1024] = "node0:0\n node1:1";
const char *nodeToCpu;
char *offset, *xml_str, *tempStr = NULL, *reallocP;
size_t len, dash, comma, newline;
int cellNum, numCells = 2, numCpus = 15, cellCpuCount = 0, start, finish, r;
int i = 0, *cpuNumsP = NULL, *iCpuNumsP;
int c, numSize, cpuNum, next;
offset = &(string1[0]);
cpuNumsP = iCpuNumsP = malloc(numCpus * sizeof(int));
while ((offset = strstr(offset, "node")) != NULL) {
cpuNumsP = iCpuNumsP;
cellCpuCount = 0;
offset +=4;
if ((numSize = getNumber(offset, &cellNum)) < 0) {
printf ("no digits after node!!\n");
return -1;
}
offset += numSize;
if (*(offset) != ':') {
printf ("no : after nodenumber!!\n");
return -1;
}
offset++;
/* get cpu numbers */
while (1) {
if ((numSize = getNumber(offset, &cpuNum)) < 0) {
printf ("no digits after :!!\n");
return -1;
}
offset += numSize;
next = *(offset);
if (next == '-') {
offset++;
start = cpuNum;
if ((numSize = getNumber(offset, &finish)) < 0) {
printf ("no digits after -!!\n");
return -1;
}
if (start > finish) {
printf ("error, start > finish!!\n");
return -1;
}
for (i=start; i<=finish && cellCpuCount<numCpus; i++) {
*(cpuNumsP++) = i;
cellCpuCount++;
}
if (cellCpuCount >= numCpus) {
return -1;
}
offset += numSize;
next = *(offset);
offset++;
if (next == ',') {
continue;
} else if (next == '\n') {
break;
} else {
printf ("badly formed !!\n");
return -1;
}
} else {
/* add the single number */
if (cellCpuCount >= numCpus) {
printf ("cellCpuCount %d > numCpus %d\n!!!!!!", cellCpuCount, numCpus);
return -1;
}
*(cpuNumsP) = cpuNum;
cpuNumsP++;
cellCpuCount++;
if (next == ',') {
offset++;
continue;
} else if (next == '\n') {
break;
} else {
printf ("badly formed\n");
return -1;
}
}
}
printf ("\n");
printf ("cell_id = %d\n",cellNum);
printf ("cell cpu count = %d\n",cellCpuCount);
for (i = 0; i < cellCpuCount; i++) {
printf ("cpu id = %d\n", *(iCpuNumsP + i));
}
}
}
--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list