-
-
Save anonymous/01ac69ff3d5585052102 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.LibVirt | |
import Control.Monad | |
main = do | |
c <- openConnection "qemu:///system" | |
putStrLn "opened connection" | |
void $ defineDomainXML c xml | |
putStrLn "defined domain" | |
void $ closeConnection c | |
putStrLn "closed connection" | |
xml = "<domain type=\"qemu\">\ | |
\ <name>TEST-03</name>\ | |
\ <title>test from wiki</title>\ | |
\ <vcpu>1</vcpu>\ | |
\ <memory unit='KiB'>83886</memory>\ | |
\ <os>\ | |
\ <type arch=\"x86_64\">hvm</type>\ | |
\ </os>\ | |
\ <clock sync=\"localtime\"/>\ | |
\ <devices>\ | |
\ <emulator>/usr/bin/qemu-system-x86_64</emulator>\ | |
\ <disk type=\"file\" device=\"disk\">\ | |
\ <source file=\"/var/lib/vm-mon/domains/TEST-03/IMAGE\"/>\ | |
\ <target dev=\"hda\"/>\ | |
\ </disk>\ | |
\ </devices>\ | |
\</domain>" |
C - no errors:
#include <stdlib.h>
#include <stdio.h>
#include <libvirt/libvirt.h>
int main(int argc, char **argv) {
virConnectPtr conn = NULL;
conn = virConnectOpenAuth("qemu:///system", virConnectAuthPtrDefault, 0);
if (conn == NULL) {
fprintf(stderr, "Failed to connect to hypervisor\n");
goto error;
}
virDomainDefineXML(conn, "<domain type=\"kvm\">"
"<name>TEST-03</name>"
"<title>test from wiki</title>"
"<vcpu>1</vcpu>"
"<memory unit='KiB'>83886</memory>"
"<os>"
" <type arch=\"x86_64\">hvm</type>"
"</os>"
"<clock sync=\"localtime\"/>"
"<devices>"
" <emulator>/usr/bin/qemu-system-x86_64</emulator>"
" <disk type=\"file\" device=\"disk\">"
" <source file=\"/var/lib/vm-mon/files/hvmmuser/linux-0.2.img\"/>"
" <target dev=\"hda\"/>"
" </disk>"
"</devices>"
"</domain>");
error:
if (conn != NULL)
virConnectClose(conn);
return 0;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
strace:
stat("/usr/sbin/libvirtd", {st_mode=S_IFREG|0755, st_size=1211712, ...}) = 0 socket(PF_FILE, SOCK_STREAM, 0) = 4 connect(4, {sa_family=AF_FILE, path="/var/run/libvirt/libvirt-sock"}, 110) = 0 getsockname(4, {sa_family=AF_FILE, NULL}, [2]) = 0 gettid() = 1074 fcntl(4, F_GETFD) = 0 fcntl(4, F_SETFD, FD_CLOEXEC) = 0 fcntl(4, F_GETFL) = 0x2 (flags O_RDWR) fcntl(4, F_SETFL, O_RDWR|O_NONBLOCK) = 0 gettid() = 1074 pipe2([5, 6], O_CLOEXEC) = 0 mmap(NULL, 266240, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f88b3cec000 gettid() = 1074 gettid() = 1074 --- SIGVTALRM (Virtual timer expired) @ 0 (0) --- rt_sigreturn(0x1a) = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 mmap(NULL, 266240, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f88b3cab000 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 rt_sigprocmask(SIG_BLOCK, [PIPE CHLD WINCH], [], 8) = 0 poll([{fd=4, events=POLLOUT}, {fd=5, events=POLLIN}], 2, -1) = 1 ([{fd=4, revents=POLLOUT}]) rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 write(4, "\0\0\0\34 \0\200\206\0\0\0\1\0\0\0B\0\0\0\0\0\0\0\0\0\0\0\0", 28) = 28 rt_sigprocmask(SIG_BLOCK, [PIPE CHLD WINCH], [], 8) = 0 poll([{fd=4, events=POLLIN}, {fd=5, events=POLLIN}], 2, -1) = 1 ([{fd=4, revents=POLLIN}]) rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 read(4, "\0\0\0$", 4) = 4 gettid() = 1074 read(4, " \0\200\206\0\0\0\1\0\0\0B\0\0\0\1\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\0", 32) = 32 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 munmap(0x7f88b3cab000, 266240) = 0 gettid() = 1074 brk(0x101b000) = 0x101b000 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 rt_sigprocmask(SIG_BLOCK, [PIPE CHLD WINCH], [], 8) = 0 poll([{fd=4, events=POLLOUT}, {fd=5, events=POLLIN}], 2, -1) = 1 ([{fd=4, revents=POLLOUT}]) rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 write(4, "\0\0\0008 \0\200\206\0\0\0\1\0\0\0\1\0\0\0\0\0\0\0\1\0\0\0\0\0\0\0\1"..., 56) = 56 rt_sigprocmask(SIG_BLOCK, [PIPE CHLD WINCH], [], 8) = 0 poll([{fd=4, events=POLLIN}, {fd=5, events=POLLIN}], 2, -1) = 1 ([{fd=4, revents=POLLIN}]) rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 read(4, "\0\0\0\34", 4) = 4 gettid() = 1074 read(4, " \0\200\206\0\0\0\1\0\0\0\1\0\0\0\1\0\0\0\1\0\0\0\0", 24) = 24 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff0da61dc8) = -1 ENOTTY (Inappropriate ioctl for device) gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 --- SIGVTALRM (Virtual timer expired) @ 0 (0) --- rt_sigreturn(0x1a) = 1074 rt_sigprocmask(SIG_BLOCK, [PIPE CHLD WINCH], [], 8) = 0 poll([{fd=4, events=POLLOUT}, {fd=5, events=POLLIN}], 2, -1) = 1 ([{fd=4, revents=POLLOUT}]) rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 write(4, "\0\0\1\340 \0\200\206\0\0\0\1\0\0\0\v\0\0\0\0\0\0\0\2\0\0\0\0\0\0\1\275"..., 480) = 480 rt_sigprocmask(SIG_BLOCK, [PIPE CHLD WINCH], [], 8) = 0 poll([{fd=4, events=POLLIN}, {fd=5, events=POLLIN}], 2, -1) = ? ERESTART_RESTARTBLOCK (To be restarted) --- SIGVTALRM (Virtual timer expired) @ 0 (0) --- rt_sigreturn(0x1a) = -1 EINTR (Interrupted system call) rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 gettid() = 1074 write(2, "libvir: RPC error : poll on sock"..., 67libvir: RPC error : poll on socket failed: Interrupted system call ) = 67 select(2, [], [1], NULL, {0, 0}) = 1 (out [1], left {0, 0}) write(1, "opened connection\n", 18) = 18 write(2, "Test: ", 6Test: ) = 6 write(2, "Error {veCode = ErrSystemError, "..., 384Error {veCode = ErrSystemError, veDomain = FromRpc, veMessage = "poll on socket failed: Interrupted system call", veLevel = ErrError, veConnect = <Connection: 0x0000000000000000>, veDom = <Domain: 0x0000000000000000>, veStr1 = Just "%s", veStr2 = Just "poll on socket failed: Interrupted system call", veStr3 = Nothing, veInt1 = -1, veInt2 = -1, veNet = <Network: 0x0000000000000000>}) = 384 write(2, "\n", 1 ) = 1 clock_gettime(0x2 /* CLOCK_??? */, {0, 14507562}) = 0 rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0 clock_gettime(0x2 /* CLOCK_??? */, {0, 14520277}) = 0 clock_gettime(0x3 /* CLOCK_??? */, {0, 14524486}) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 timer_settime(0, 0, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0 timer_delete(0) = 0 rt_sigprocmask(SIG_BLOCK, [TTOU], [], 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 rt_sigaction(SIGINT, {SIG_DFL, [], SA_RESTORER, 0x7f88b28654a0}, NULL, 8) = 0 rt_sigaction(SIGPIPE, {SIG_DFL, [], SA_RESTORER, 0x7f88b28654a0}, NULL, 8) = 0 rt_sigaction(SIGTSTP, {SIG_DFL, [], SA_RESTORER, 0x7f88b28654a0}, NULL, 8) = 0 clock_gettime(0x2 /* CLOCK_??? */, {0, 14773417}) = 0 exit_group(1)