#define _GNU_SOURCE #include #include #include #include #include #include #include #include #define NUM_THREADS 8 #define MAX_VMS 1000 const char *XML = "" " vm%06d" " 220160" " 60000" " 1" " " " hvm" " " " " " " " " " " " " " /bin/qemu-kvm" " " " " " " " " "
" " " " " " " " " " " " " " " " " ""; static pid_t gettid(void) { return syscall(SYS_gettid); } static void *one_thread(void *arg) { int i; virConnectPtr conn = arg; virConnectRef(conn); char *cmd; if (asprintf(&cmd, "qemu-img create -f qcow2 /home/berrange/VirtualMachines/vm%06d.qcow 1G", gettid()) < 0) abort(); if (system(cmd) != 0) abort(); char *xml; if (asprintf(&xml, XML, gettid(), gettid()) < 0) abort(); for (i = 0 ; i < MAX_VMS ; i++) { fprintf(stderr, "%d: %d of %d \n", gettid(), i, MAX_VMS); virDomainPtr dom = virDomainCreateXML(conn, xml, VIR_DOMAIN_START_AUTODESTROY); virDomainDestroy(dom); } free(xml); free(cmd); virConnectClose(conn); return NULL; } int main(int argc, char **argv) { virConnectPtr conn; int ret = -1; pthread_t threads[NUM_THREADS]; int i; if (!(conn = virConnectOpen("qemu:///session"))) goto error; for (i = 0 ; i < NUM_THREADS ; i++) { if (pthread_create(&threads[i], NULL, one_thread, conn) < 0) goto error; } for (i = 0 ; i < NUM_THREADS ; i++) { if (pthread_join(threads[i], NULL) < 0) goto error; } ret = 0; error: if (ret != 0) { virErrorPtr err = virGetLastError(); fprintf(stderr, "error: %s\n", err ? err->message : ""); } if (conn) virConnectClose(conn); exit(ret); }