Commit cc087349 authored by Daniel P. Berrange's avatar Daniel P. Berrange

Split QEMU code into a separate file for conditional build

Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
parent 4665fecf
......@@ -9,6 +9,11 @@ Make sure to have `libvirt-dev` package (or the development files otherwise some
The libvirt go package provides API coverage for libvirt versions
from 1.2.0 onwards, through conditional compilation of newer APIs.
By default the binding will support APIs in libvirt.so, libvirt-qemu.so
and libvirt-lxc.so. Coverage for the latter two libraries can be dropped
from the build using build tags 'without_qemu' or 'without_lxc'
respectively.
## Development status
The Go API is considered to be production ready and aims to be kept
......
......@@ -28,11 +28,7 @@ package libvirt
/*
#cgo pkg-config: libvirt
// Can't rely on pkg-config for libvirt-qemu since it was not
// installed until 2.6.0 onwards
#cgo LDFLAGS: -lvirt-qemu
#include <libvirt/libvirt.h>
#include <libvirt/libvirt-qemu.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
#include "domain_compat.h"
......@@ -437,34 +433,6 @@ const (
DOMAIN_EVENT_TRAY_CHANGE_CLOSE = ConnectDomainEventTrayChangeReason(C.VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE)
)
/*
* QMP has two different kinds of ways to talk to QEMU. One is legacy (HMP,
* or 'human' monitor protocol. The default is QMP, which is all-JSON.
*
* QMP json commands are of the format:
* {"execute" : "query-cpus"}
*
* whereas the same command in 'HMP' would be:
* 'info cpus'
*/
type DomainQemuMonitorCommandFlags int
const (
DOMAIN_QEMU_MONITOR_COMMAND_DEFAULT = DomainQemuMonitorCommandFlags(C.VIR_DOMAIN_QEMU_MONITOR_COMMAND_DEFAULT)
DOMAIN_QEMU_MONITOR_COMMAND_HMP = DomainQemuMonitorCommandFlags(C.VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP)
)
type DomainQemuAgentCommandTimeout int
const (
DOMAIN_QEMU_AGENT_COMMAND_MIN = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_MIN)
DOMAIN_QEMU_AGENT_COMMAND_BLOCK = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK)
DOMAIN_QEMU_AGENT_COMMAND_DEFAULT = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT)
DOMAIN_QEMU_AGENT_COMMAND_NOWAIT = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT)
DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN)
)
type DomainProcessSignal int
const (
......@@ -1739,35 +1707,6 @@ func (d *Domain) GetVcpusFlags(flags DomainVcpuFlags) (int32, error) {
return int32(result), nil
}
func (d *Domain) QemuMonitorCommand(command string, flags DomainQemuMonitorCommandFlags) (string, error) {
var cResult *C.char
cCommand := C.CString(command)
defer C.free(unsafe.Pointer(cCommand))
result := C.virDomainQemuMonitorCommand(d.ptr, cCommand, &cResult, C.uint(flags))
if result != 0 {
return "", GetLastError()
}
rstring := C.GoString(cResult)
C.free(unsafe.Pointer(cResult))
return rstring, nil
}
func (d *Domain) QemuAgentCommand(command string, timeout DomainQemuAgentCommandTimeout, flags uint32) (string, error) {
cCommand := C.CString(command)
defer C.free(unsafe.Pointer(cCommand))
result := C.virDomainQemuAgentCommand(d.ptr, cCommand, C.int(timeout), C.uint(flags))
if result == nil {
return "", GetLastError()
}
rstring := C.GoString(result)
C.free(unsafe.Pointer(result))
return rstring, nil
}
func (d *Domain) PinVcpu(vcpu uint, cpuMap []bool) error {
maplen := (len(cpuMap) + 7) / 8
ccpumap := make([]C.uchar, maplen)
......
......@@ -483,10 +483,6 @@ int virDomainPinIOThreadCompat(virDomainPtr domain,
#define VIR_DOMAIN_EVENT_ID_DEVICE_ADDED 19
#endif
#ifndef VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN
#define VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN 60
#endif
int virDomainAddIOThreadCompat(virDomainPtr domain,
unsigned int iothread_id,
unsigned int flags);
......
// +build !without_qemu
/*
* This file is part of the libvirt-go project
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Copyright (c) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
// Can't rely on pkg-config for libvirt-qemu since it was not
// installed until 2.6.0 onwards
#cgo LDFLAGS: -lvirt-qemu
#include <libvirt/libvirt.h>
#include <libvirt/libvirt-qemu.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
#include "qemu_compat.h"
*/
import "C"
import (
"unsafe"
)
/*
* QMP has two different kinds of ways to talk to QEMU. One is legacy (HMP,
* or 'human' monitor protocol. The default is QMP, which is all-JSON.
*
* QMP json commands are of the format:
* {"execute" : "query-cpus"}
*
* whereas the same command in 'HMP' would be:
* 'info cpus'
*/
type DomainQemuMonitorCommandFlags int
const (
DOMAIN_QEMU_MONITOR_COMMAND_DEFAULT = DomainQemuMonitorCommandFlags(C.VIR_DOMAIN_QEMU_MONITOR_COMMAND_DEFAULT)
DOMAIN_QEMU_MONITOR_COMMAND_HMP = DomainQemuMonitorCommandFlags(C.VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP)
)
type DomainQemuAgentCommandTimeout int
const (
DOMAIN_QEMU_AGENT_COMMAND_MIN = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_MIN)
DOMAIN_QEMU_AGENT_COMMAND_BLOCK = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK)
DOMAIN_QEMU_AGENT_COMMAND_DEFAULT = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT)
DOMAIN_QEMU_AGENT_COMMAND_NOWAIT = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT)
DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN)
)
func (d *Domain) QemuMonitorCommand(command string, flags DomainQemuMonitorCommandFlags) (string, error) {
var cResult *C.char
cCommand := C.CString(command)
defer C.free(unsafe.Pointer(cCommand))
result := C.virDomainQemuMonitorCommand(d.ptr, cCommand, &cResult, C.uint(flags))
if result != 0 {
return "", GetLastError()
}
rstring := C.GoString(cResult)
C.free(unsafe.Pointer(cResult))
return rstring, nil
}
func (d *Domain) QemuAgentCommand(command string, timeout DomainQemuAgentCommandTimeout, flags uint32) (string, error) {
cCommand := C.CString(command)
defer C.free(unsafe.Pointer(cCommand))
result := C.virDomainQemuAgentCommand(d.ptr, cCommand, C.int(timeout), C.uint(flags))
if result == nil {
return "", GetLastError()
}
rstring := C.GoString(result)
C.free(unsafe.Pointer(result))
return rstring, nil
}
/*
* This file is part of the libvirt-go project
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Copyright (c) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_QEMU_COMPAT_H__
#define LIBVIRT_GO_QEMU_COMPAT_H__
/* 1.2.15 */
#ifndef VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN
#define VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN 60
#endif
#endif /* LIBVIRT_GO_QEMU_COMPAT_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment