[libvirt] [PATCH4/3] qemu: add cpu feature check for host-passthrough
by Luyao Huang
Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
---
I forgot this place.
src/qemu/qemu_process.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 79f763e..5f418a9 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4070,11 +4070,6 @@ qemuProcessVerifyGuestCPU(virQEMUDriverPtr driver,
bool ret = false;
size_t i;
- /* no features are passed to QEMU with -cpu host
- * so it makes no sense to verify them */
- if (def->cpu && def->cpu->mode == VIR_CPU_MODE_HOST_PASSTHROUGH)
- return true;
-
switch (arch) {
case VIR_ARCH_I686:
case VIR_ARCH_X86_64:
--
1.8.3.1
9 years, 6 months
[libvirt] [PATCH 0/3] fix some issue around host-passthough cpu model
by Luyao Huang
We support add feature in host-passthough cpu model, but there are
some place need fix.
Luyao Huang (3):
cpu:x86: fix cannot keep cpu feature after migrate/restore
qemu: add a check for non-migratable cpu flags
docs: fix a small xml error in docs
docs/formatdomain.html.in | 2 +-
src/cpu/cpu_x86.c | 9 ++++-----
src/qemu/qemu_migration.c | 2 +-
3 files changed, 6 insertions(+), 7 deletions(-)
--
1.8.3.1
9 years, 6 months
[libvirt] [PATCHv3] conf: Add the cpu duplicate use check for vm numa settings
by Luyao Huang
https://bugzilla.redhat.com/show_bug.cgi?id=1176020
We had a check for the vcpu count total number in <numa>
before, however this check is not good enough. There are
some examples:
1. one of cpu id is out of maxvcpus, can set success(cpu count = 5 < 10):
<vcpu placement='static'>10</vcpu>
<cell id='0' cpus='0-3,100' memory='512000' unit='KiB'/>
2. use the same cpu in 2 cell, can set success(cpu count = 8 < 10):
<vcpu placement='static'>10</vcpu>
<cell id='0' cpus='0-3' memory='512000' unit='KiB'/>
<cell id='1' cpus='0-3' memory='512000' unit='KiB'/>
3. use the same cpu in 2 cell, cannot set success(cpu count = 11 > 10):
<vcpu placement='static'>10</vcpu>
<cell id='0' cpus='0-6' memory='512000' unit='KiB'/>
<cell id='1' cpus='0-3' memory='512000' unit='KiB'/>
Add a check for numa cpus, check if duplicate use one cpu in more
than one cell.
Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
---
v3: remove the max vcpu check, just add a check when
parse the numa settings, and change the subject.
src/conf/numa_conf.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
index 7ad3f66..e25d7a8 100644
--- a/src/conf/numa_conf.c
+++ b/src/conf/numa_conf.c
@@ -738,6 +738,15 @@ virDomainNumaDefCPUParseXML(virDomainNumaPtr def,
}
VIR_FREE(tmp);
+ for (j = 0; j < i; j++) {
+ if (virBitmapOverlaps(def->mem_nodes[j].cpumask,
+ def->mem_nodes[i].cpumask)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("NUMA cells %zu and %zu have overlapping vCPU ids"), i, j);
+ goto cleanup;
+ }
+ }
+
ctxt->node = nodes[i];
if (virDomainParseMemory("./@memory", "./@unit", ctxt,
&def->mem_nodes[cur_cell].mem, true, false) < 0)
--
1.8.3.1
9 years, 6 months
[libvirt] [PATCH 0/8] Resolve new Coverity issues
by John Ferlan
Installed a new Coverity checker (7.6.1) and naturally new issues
were found, plus a set of false positives which for now I'll just
have to ignore since it seems they may be a bug in Coverity, but
that's still to be determined
John Ferlan (8):
libxl: Resolve Coverity RESOURCE_LEAK
vbox: Resolve Coverity RESOURCE_LEAK
qemu: Resolve Coverity IDENTICAL_BRANCHES
qemu: Resolve Coverity FORWARD_NULL
xen: Resolve Coverity FORWARD_NULL
qemu: Resolve Coverity FORWARD_NULL
qemu: Resolve Coverity FORWARD_NULL
qemu: Resolve Coverity FORWARD_NULL
src/libxl/libxl_migration.c | 1 +
src/qemu/qemu_capabilities.c | 4 +++-
src/qemu/qemu_command.c | 4 +++-
src/qemu/qemu_driver.c | 5 +++--
src/qemu/qemu_hotplug.c | 11 +++--------
src/vbox/vbox_common.c | 21 +++++++--------------
src/xen/xm_internal.c | 3 +++
7 files changed, 23 insertions(+), 26 deletions(-)
--
2.1.0
9 years, 6 months
[libvirt] [PATCH v1] [libvirt-php] add stream support and upload/resize/download for volume
by Vasiliy Tolstov
This patch add to libvirt php binding libvirt stream support
Also provide resize/upload/download for libvirt volume
Signed-off-by: Vasiliy Tolstov <v.tolstov(a)selfip.ru>
---
configure.ac | 3 +-
src/libvirt-php.c | 382 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
src/libvirt-php.h | 17 +++
3 files changed, 395 insertions(+), 7 deletions(-)
diff --git a/configure.ac b/configure.ac
index b854153..7099f9d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,7 +1,6 @@
AC_INIT([libvirt-php], [0.5.0], [http://libvirt.org])
-AM_INIT_AUTOMAKE([-Wall -Werror])
+AM_INIT_AUTOMAKE([-Wall -Werror -Wno-portability])
AC_CONFIG_FILES([Makefile tools/Makefile src/Makefile tests/Makefile docs/Makefile])
-AM_INIT_AUTOMAKE([-Wno-portability])
AM_MAINTAINER_MODE([enable])
dnl Checks for programs.
diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index 6d6fa81..0adc4be 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -61,6 +61,7 @@ int le_libvirt_storagepool;
int le_libvirt_volume;
int le_libvirt_network;
int le_libvirt_nodedev;
+int le_libvirt_stream;
#if LIBVIR_VERSION_NUMBER>=8000
int le_libvirt_snapshot;
#endif
@@ -90,6 +91,13 @@ static zend_function_entry libvirt_functions[] = {
PHP_FE(libvirt_connect_get_maxvcpus, NULL)
PHP_FE(libvirt_connect_get_encrypted, NULL)
PHP_FE(libvirt_connect_get_secure, NULL)
+ /* Stream functions */
+ PHP_FE(libvirt_stream_create, NULL)
+ PHP_FE(libvirt_stream_close, NULL)
+ PHP_FE(libvirt_stream_abort, NULL)
+ PHP_FE(libvirt_stream_finish, NULL)
+ PHP_FE(libvirt_stream_send, NULL)
+ PHP_FE(libvirt_stream_recv, NULL)
/* Domain functions */
PHP_FE(libvirt_domain_new, NULL)
PHP_FE(libvirt_domain_new_get_vnc, NULL)
@@ -148,7 +156,7 @@ static zend_function_entry libvirt_functions[] = {
PHP_FE(libvirt_domain_get_screen_dimensions, NULL)
PHP_FE(libvirt_domain_send_keys, NULL)
PHP_FE(libvirt_domain_send_pointer_event, NULL)
- PHP_FE(libvirt_domain_update_device, NULL)
+ PHP_FE(libvirt_domain_update_device, NULL)
/* Domain snapshot functions */
PHP_FE(libvirt_domain_has_current_snapshot, NULL)
PHP_FE(libvirt_domain_snapshot_create, NULL)
@@ -169,6 +177,9 @@ static zend_function_entry libvirt_functions[] = {
PHP_FE(libvirt_storagevolume_create_xml,NULL)
PHP_FE(libvirt_storagevolume_create_xml_from,NULL)
PHP_FE(libvirt_storagevolume_delete,NULL)
+ PHP_FE(libvirt_storagevolume_download,NULL)
+ PHP_FE(libvirt_storagevolume_upload,NULL)
+ PHP_FE(libvirt_storagevolume_resize,NULL)
PHP_FE(libvirt_storagepool_get_uuid_string, NULL)
PHP_FE(libvirt_storagepool_get_name, NULL)
PHP_FE(libvirt_storagepool_lookup_by_uuid_string, NULL)
@@ -370,6 +381,8 @@ char *translate_counter_type(int type)
break;
case INT_RESOURCE_DOMAIN: return "domain";
break;
+ case INT_RESOURCE_STREAM: return "stream";
+ break;
case INT_RESOURCE_NETWORK: return "network";
break;
case INT_RESOURCE_NODEDEV: return "node device";
@@ -444,7 +457,7 @@ void free_tokens(tTokenizer t)
Private function name: resource_change_counter
Since version: 0.4.2
Description: Function to increment (inc = 1) / decrement (inc = 0) the resource pointers count including the memory location
- Arguments: @type [int]: type of resource (INT_RESOURCE_x defines where x can be { CONNECTION | DOMAIN | NETWORK | NODEDEV | STORAGEPOOL | VOLUME | SNAPSHOT })
+ Arguments: @type [int]: type of resource (INT_RESOURCE_x defines where x can be { CONNECTION | DOMAIN | NETWORK | NODEDEV | STORAGEPOOL | VOLUME | SNAPSHOT | STREAM })
@conn [virConnectPtr]: libvirt connection pointer associated with the resource, NULL for libvirt connection objects
@mem [pointer]: Pointer to memory location for the resource. Will be converted to appropriate uint for the arch.
@inc [int/bool]: Increment the counter (1 = add memory location) or decrement the counter (0 = remove memory location) from entries.
@@ -724,6 +737,18 @@ void free_resource(int type, arch_uint mem TSRMLS_DC)
}
}
+ if (type == INT_RESOURCE_STREAM) {
+ rv = virStreamFree( (virStreamPtr)mem );
+ if (rv != 0) {
+ DPRINTF("%s: virStreamFree(%p) returned %d (%s)\n", __FUNCTION__, (virStreamPtr)mem, rv, LIBVIRT_G (last_error));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,"virStreamFree failed with %i on destructor: %s", rv, LIBVIRT_G (last_error));
+ }
+ else {
+ DPRINTF("%s: virStreamFree(%p) completed successfully\n", __FUNCTION__, (virStreamPtr)mem);
+ resource_change_counter(INT_RESOURCE_STREAM, NULL, (virStreamPtr)mem, 0 TSRMLS_CC);
+ }
+ }
+
if (type == INT_RESOURCE_NETWORK) {
rv = virNetworkFree( (virNetworkPtr)mem );
if (rv != 0) {
@@ -986,6 +1011,36 @@ static void php_libvirt_domain_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
}
}
+/* Destructor for stream resource */
+static void php_libvirt_stream_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+{
+ php_libvirt_stream *stream = (php_libvirt_stream*)rsrc->ptr;
+ int rv = 0;
+
+ if (stream != NULL)
+ {
+ if (stream->stream != NULL)
+ {
+ if (!check_resource_allocation(NULL, INT_RESOURCE_STREAM, stream->stream TSRMLS_CC)) {
+ stream->stream=NULL;
+ efree (stream);
+ return;
+ }
+ rv = virStreamFree(stream->stream);
+ if (rv != 0) {
+ DPRINTF("%s: virStreamFree(%p) returned %d (%s)\n", __FUNCTION__, stream->stream, rv, LIBVIRT_G (last_error));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,"virStreamFree failed with %i on destructor: %s", rv, LIBVIRT_G (last_error));
+ }
+ else {
+ DPRINTF("%s: virStreamFree(%p) completed successfully\n", __FUNCTION__, stream->stream);
+ resource_change_counter(INT_RESOURCE_STREAM, NULL, stream->stream, 0 TSRMLS_CC);
+ }
+ stream->stream=NULL;
+ }
+ efree (stream);
+ }
+}
+
/* Destructor for storagepool resource */
static void php_libvirt_storagepool_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
@@ -1144,6 +1199,7 @@ PHP_MINIT_FUNCTION(libvirt)
/* register resource types and their descriptors */
le_libvirt_connection = zend_register_list_destructors_ex(php_libvirt_connection_dtor, NULL, PHP_LIBVIRT_CONNECTION_RES_NAME, module_number);
le_libvirt_domain = zend_register_list_destructors_ex(php_libvirt_domain_dtor, NULL, PHP_LIBVIRT_DOMAIN_RES_NAME, module_number);
+ le_libvirt_stream = zend_register_list_destructors_ex(php_libvirt_stream_dtor, NULL, PHP_LIBVIRT_STREAM_RES_NAME, module_number);
le_libvirt_storagepool = zend_register_list_destructors_ex(php_libvirt_storagepool_dtor, NULL, PHP_LIBVIRT_STORAGEPOOL_RES_NAME, module_number);
le_libvirt_volume = zend_register_list_destructors_ex(php_libvirt_volume_dtor, NULL, PHP_LIBVIRT_VOLUME_RES_NAME, module_number);
le_libvirt_network = zend_register_list_destructors_ex(php_libvirt_network_dtor, NULL, PHP_LIBVIRT_NETWORK_RES_NAME, module_number);
@@ -1171,6 +1227,11 @@ PHP_MINIT_FUNCTION(libvirt)
REGISTER_LONG_CONSTANT("VIR_DOMAIN_SHUTOFF", 5, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("VIR_DOMAIN_CRASHED", 6, CONST_CS | CONST_PERSISTENT);
+ /* Volume constants */
+ REGISTER_LONG_CONSTANT("VIR_STORAGE_VOL_RESIZE_ALLOCATE", 1, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("VIR_STORAGE_VOL_RESIZE_DELTA", 2, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("VIR_STORAGE_VOL_RESIZE_SHRINK", 4, CONST_CS | CONST_PERSISTENT);
+
/* Domain vCPU flags */
REGISTER_LONG_CONSTANT("VIR_DOMAIN_VCPU_CONFIG", VIR_DOMAIN_VCPU_CONFIG, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("VIR_DOMAIN_VCPU_CURRENT", VIR_DOMAIN_VCPU_CURRENT, CONST_CS | CONST_PERSISTENT);
@@ -3456,6 +3517,207 @@ PHP_FUNCTION(libvirt_domain_lookup_by_uuid_string)
}
/*
+ Function name: libvirt_stream_create
+ Since version: 0.5.0
+ Description: Function is used to create new stream from libvirt conn
+ Arguments: @res [resource]: libvirt connection resource from libvirt_connect()
+ Returns: resource libvirt stream resource
+*/
+PHP_FUNCTION(libvirt_stream_create)
+{
+ php_libvirt_connection *conn=NULL;
+ zval *zconn;
+ virStreamPtr stream = NULL;
+ php_libvirt_stream *res_stream;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zconn) == FAILURE) {
+ RETURN_FALSE;
+ }
+ ZEND_FETCH_RESOURCE (conn, php_libvirt_connection*, &zconn, -1, PHP_LIBVIRT_CONNECTION_RES_NAME, le_libvirt_connection);
+ if ((conn==NULL)||(conn->conn==NULL))RETURN_FALSE;
+
+ stream = virStreamNew(conn->conn, 0);
+ if (stream==NULL) {
+ set_error("Cannot create new stream" TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
+ res_stream = (php_libvirt_stream *)emalloc(sizeof(php_libvirt_stream));
+ res_stream->stream = stream;
+ res_stream->conn = conn;
+
+ resource_change_counter(INT_RESOURCE_STREAM, conn->conn, res_stream->stream, 1 TSRMLS_CC);
+ ZEND_REGISTER_RESOURCE(return_value, res_stream, le_libvirt_stream);
+}
+
+/*
+ Function name: libvirt_stream_close
+ Since version: 0.5.0
+ Description: Function is used to close stream
+ Arguments: @res [resource]: libvirt stream resource from libvirt_stream_create()
+ Returns: int
+*/
+PHP_FUNCTION(libvirt_stream_close)
+{
+ zval *zstream;
+ php_libvirt_stream *stream=NULL;
+ int retval = -1;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream) == FAILURE) {
+ RETURN_LONG(retval);
+ }
+ ZEND_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, -1, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream);
+ if ((stream==NULL)||(stream->stream==NULL))RETURN_LONG(retval);
+
+ retval = virStreamFree(stream->stream);
+ if (retval != 0) {
+ set_error("Cannot free stream" TSRMLS_CC);
+ RETURN_LONG(retval);
+ }
+
+ resource_change_counter(INT_RESOURCE_STREAM, stream->conn, stream->stream, 0 TSRMLS_CC);
+ RETURN_LONG(retval);
+}
+
+/*
+ Function name: libvirt_stream_abort
+ Since version: 0.5.0
+ Description: Function is used to abort transfer
+ Arguments: @res [resource]: libvirt stream resource from libvirt_stream_create()
+ Returns: int
+*/
+PHP_FUNCTION(libvirt_stream_abort)
+{
+ zval *zstream;
+ php_libvirt_stream *stream=NULL;
+ int retval = -1;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream) == FAILURE) {
+ RETURN_LONG(retval);
+ }
+ ZEND_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, -1, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream);
+ if ((stream==NULL)||(stream->stream==NULL))RETURN_LONG(retval);
+
+ retval = virStreamAbort(stream->stream);
+ if (retval != 0) {
+ set_error("Cannot abort stream" TSRMLS_CC);
+ RETURN_LONG(retval);
+ }
+ RETURN_LONG(retval);
+}
+
+/*
+ Function name: libvirt_stream_finish
+ Since version: 0.5.0
+ Description: Function is used to finish transfer
+ Arguments: @res [resource]: libvirt stream resource from libvirt_stream_create()
+ Returns: int
+*/
+PHP_FUNCTION(libvirt_stream_finish)
+{
+ zval *zstream;
+ php_libvirt_stream *stream=NULL;
+ int retval = -1;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream) == FAILURE) {
+ RETURN_LONG(retval);
+ }
+ ZEND_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, -1, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream);
+ if ((stream==NULL)||(stream->stream==NULL))RETURN_LONG(retval);
+
+ retval = virStreamFinish(stream->stream);
+ if (retval != 0) {
+ set_error("Cannot finish stream" TSRMLS_CC);
+ RETURN_LONG(retval);
+ }
+ RETURN_LONG(retval);
+}
+
+/*
+ Function name: libvirt_stream_recv
+ Since version: 0.5.0
+ Description: Function is used to close stream from libvirt conn
+ Arguments: @res [resource]: libvirt stream resource from libvirt_stream_create()
+ @data [string]: buffer
+ @len [int]: amout of data to recieve
+ Returns: int
+*/
+PHP_FUNCTION(libvirt_stream_recv)
+{
+ zval *zstream, *zbuf;
+ char *recv_buf;
+ php_libvirt_stream *stream=NULL;
+ int retval = -1;
+ long length = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|l", &zstream, &zbuf, &length) == FAILURE) {
+ RETURN_LONG(retval);
+ }
+ ZEND_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, -1, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream);
+ if ((stream==NULL)||(stream->stream==NULL))RETURN_LONG(retval);
+
+ recv_buf = emalloc(length + 1);
+ memset(recv_buf, 0, length + 1);
+
+ retval = virStreamRecv(stream->stream, recv_buf, length);
+ if (retval < 0) {
+ efree(recv_buf);
+ zval_dtor(zbuf);
+ Z_TYPE_P(zbuf) = IS_NULL;
+ } else {
+ recv_buf[retval] = '\0';
+ /* Rebuild buffer zval */
+ zval_dtor(zbuf);
+ Z_STRVAL_P(zbuf) = recv_buf;
+ Z_STRLEN_P(zbuf) = retval;
+ Z_TYPE_P(zbuf) = IS_STRING;
+ }
+
+ if (retval == -1) {
+ set_error("Cannot recv from stream" TSRMLS_CC);
+ RETURN_LONG(retval);
+ }
+
+ RETURN_LONG(retval);
+}
+
+/*
+ Function name: libvirt_stream_send
+ Since version: 0.5.0
+ Description: Function is used to close stream from libvirt conn
+ Arguments: @res [resource]: libvirt stream resource from libvirt_stream_create()
+ @data [string]: buffer
+ @length [int]: amout of data to send
+ Returns: int
+*/
+PHP_FUNCTION(libvirt_stream_send)
+{
+ zval *zstream, *zbuf;
+ php_libvirt_stream *stream=NULL;
+ int retval = -1;
+ long length = 0;
+ char *cstr;
+ //int cstrlen;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|l", &zstream, &zbuf, &length) == FAILURE) {
+ RETURN_LONG(retval);
+ }
+ ZEND_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, -1, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream);
+ if ((stream==NULL)||(stream->stream==NULL))RETURN_LONG(retval);
+
+ cstr = Z_STRVAL_P(zbuf);
+ //cstrlen = Z_STRLEN_P(zbuf);
+
+ retval = virStreamSend(stream->stream, cstr, length);
+ if (retval == -1) {
+ set_error("Cannot send to stream" TSRMLS_CC);
+ RETURN_LONG(retval);
+ }
+
+ RETURN_LONG(retval);
+}
+
+/*
Function name: libvirt_domain_lookup_by_id
Since version: 0.4.1(-1)
Description: Function is used to get domain by it's ID, applicable only to running guests
@@ -3544,13 +3806,12 @@ PHP_FUNCTION(libvirt_domain_get_uuid_string)
@opaque [void *]: used for file descriptor
Returns: write() error code as it's calling write
*/
-
static int streamSink(virStreamPtr st ATTRIBUTE_UNUSED,
const char *bytes, size_t nbytes, void *opaque)
{
- int *fd = (int *)opaque;
+ int *fd = (int *)opaque;
- return write(*fd, bytes, nbytes);
+ return write(*fd, bytes, nbytes);
}
/*
@@ -6782,6 +7043,117 @@ PHP_FUNCTION(libvirt_storagevolume_delete)
}
/*
+ Function name: libvirt_storagevolume_resize
+ Since version: 0.5.0
+ Description: Function is used to resize volume identified by it's resource
+ Arguments: @res [resource]: libvirt storagevolume resource
+ @capacity [int]: capacity for the storage volume
+ @flags [int]: optional flags for the storage volume resize for virStorageVolResize()
+ Returns: int
+*/
+PHP_FUNCTION(libvirt_storagevolume_resize)
+{
+ php_libvirt_volume *volume=NULL;
+ zval *zvolume;
+ long flags = 0;
+ long capacity = 0;
+ int retval = -1;
+
+ GET_VOLUME_FROM_ARGS("rl|l", &zvolume, &capacity, &flags);
+
+ retval = virStorageVolResize(volume->volume, capacity, flags);
+ DPRINTF("%s: virStorageVolResize(%p, %d, %d) returned %d\n", PHPFUNC, volume->volume, (int) capacity, (int) flags, retval);
+ if (retval != 0) {
+ set_error_if_unset("Cannot resize storage volume" TSRMLS_CC);
+ RETURN_LONG(retval);
+ }
+
+ RETURN_LONG(retval);
+}
+
+/*
+ Function name: libvirt_storagevolume_download
+ Since version: 0.5.0
+ Description: Function is used to download volume identified by it's resource
+ Arguments: @res [resource]: libvirt storagevolume resource
+ @stream [resource]: stream to use as output
+ @offset [int]: position to start reading from
+ @length [int] : limit on amount of data to download
+ @flags [int]: optional flags for the storage volume download for virStorageVolDownload()
+ Returns: int
+*/
+PHP_FUNCTION(libvirt_storagevolume_download)
+{
+ php_libvirt_volume *volume=NULL;
+ php_libvirt_stream *stream=NULL;
+ zval *zvolume;
+ zval *zstream;
+ long flags = 0;
+ long offset = 0;
+ long length = 0;
+ int retval = -1;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l|l|l", &zvolume, &zstream, &offset, &length, &flags) == FAILURE) {
+ RETURN_LONG(retval);
+ }
+ ZEND_FETCH_RESOURCE (volume, php_libvirt_volume*, &zvolume, -1, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume);
+ if ((volume==NULL)||(volume->volume==NULL))RETURN_LONG(retval);
+ ZEND_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, -1, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream);
+ if ((stream==NULL)||(stream->stream==NULL))RETURN_LONG(retval);
+
+ retval = virStorageVolDownload(volume->volume, stream->stream, offset, length, flags);
+ DPRINTF("%s: virStorageVolDownload(%p, %p, %d, %d, %d) returned %d\n", PHPFUNC, volume->volume, stream->stream, (int) offset, (int) length, (int) flags, retval);
+
+ if (retval == -1) {
+ set_error("Cannot download from stream" TSRMLS_CC);
+ RETURN_LONG(retval);
+ }
+
+ RETURN_LONG(retval);
+}
+
+/*
+ Function name: libvirt_storagevolume_upload
+ Since version: 0.5.0
+ Description: Function is used to upload volume identified by it's resource
+ Arguments: @res [resource]: libvirt storagevolume resource
+ @stream [resource]: stream to use as input
+ @offset [int]: position to start writing to
+ @length [int] : limit on amount of data to upload
+ @flags [int]: optional flags for the storage volume upload for virStorageVolUpload()
+ Returns: int
+*/
+PHP_FUNCTION(libvirt_storagevolume_upload)
+{
+ php_libvirt_volume *volume=NULL;
+ php_libvirt_stream *stream=NULL;
+ zval *zvolume;
+ zval *zstream;
+ long flags = 0;
+ long offset = 0;
+ long length = 0;
+ int retval = -1;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l|l|l", &zvolume, &zstream, &offset, &length, &flags) == FAILURE) {
+ RETURN_LONG(retval);
+ }
+ ZEND_FETCH_RESOURCE (volume, php_libvirt_volume*, &zvolume, -1, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume);
+ if ((volume==NULL)||(volume->volume==NULL))RETURN_LONG(retval);
+ ZEND_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, -1, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream);
+ if ((stream==NULL)||(stream->stream==NULL))RETURN_LONG(retval);
+
+ retval = virStorageVolUpload(volume->volume, stream->stream, offset, length, flags);
+ DPRINTF("%s: virStorageVolUpload(%p, %p, %d, %d, %d) returned %d\n", PHPFUNC, volume->volume, stream->stream, (int) offset, (int) length, (int) flags, retval);
+
+ if (retval == -1) {
+ set_error_if_unset("Cannot upload storage volume" TSRMLS_CC);
+ RETURN_LONG(retval);
+ }
+
+ RETURN_LONG(retval);
+}
+
+/*
Function name: libvirt_storagepool_get_uuid_string
Since version: 0.4.1(-1)
Description: Function is used to get storage pool by UUID string
diff --git a/src/libvirt-php.h b/src/libvirt-php.h
index 450fbea..3bcc682 100644
--- a/src/libvirt-php.h
+++ b/src/libvirt-php.h
@@ -214,6 +214,7 @@ ZEND_END_MODULE_GLOBALS(libvirt)
#define INT_RESOURCE_STORAGEPOOL 0x10
#define INT_RESOURCE_VOLUME 0x20
#define INT_RESOURCE_SNAPSHOT 0x40
+#define INT_RESOURCE_STREAM 0x50
typedef struct tVMDisk {
char *path;
@@ -257,6 +258,11 @@ typedef struct _php_libvirt_connection {
long resource_id;
} php_libvirt_connection;
+typedef struct _php_libvirt_stream {
+ virStreamPtr stream;
+ php_libvirt_connection* conn;
+} php_libvirt_stream;
+
typedef struct _php_libvirt_domain {
virDomainPtr domain;
php_libvirt_connection* conn;
@@ -311,6 +317,7 @@ int gdebug;
#define PHP_LIBVIRT_CONNECTION_RES_NAME "Libvirt connection"
#define PHP_LIBVIRT_DOMAIN_RES_NAME "Libvirt domain"
+#define PHP_LIBVIRT_STREAM_RES_NAME "Libvirt stream"
#define PHP_LIBVIRT_STORAGEPOOL_RES_NAME "Libvirt storagepool"
#define PHP_LIBVIRT_VOLUME_RES_NAME "Libvirt volume"
#define PHP_LIBVIRT_NETWORK_RES_NAME "Libvirt virtual network"
@@ -347,6 +354,13 @@ PHP_FUNCTION(libvirt_node_get_info);
PHP_FUNCTION(libvirt_node_get_cpu_stats);
PHP_FUNCTION(libvirt_node_get_cpu_stats_for_each_cpu);
PHP_FUNCTION(libvirt_node_get_mem_stats);
+/* Stream functions */
+PHP_FUNCTION(libvirt_stream_create);
+PHP_FUNCTION(libvirt_stream_close);
+PHP_FUNCTION(libvirt_stream_abort);
+PHP_FUNCTION(libvirt_stream_finish);
+PHP_FUNCTION(libvirt_stream_recv);
+PHP_FUNCTION(libvirt_stream_send);
/* Domain functions */
PHP_FUNCTION(libvirt_domain_new);
PHP_FUNCTION(libvirt_domain_new_get_vnc);
@@ -427,6 +441,9 @@ PHP_FUNCTION(libvirt_storagevolume_get_xml_desc);
PHP_FUNCTION(libvirt_storagevolume_create_xml);
PHP_FUNCTION(libvirt_storagevolume_create_xml_from);
PHP_FUNCTION(libvirt_storagevolume_delete);
+PHP_FUNCTION(libvirt_storagevolume_download);
+PHP_FUNCTION(libvirt_storagevolume_upload);
+PHP_FUNCTION(libvirt_storagevolume_resize);
PHP_FUNCTION(libvirt_storagepool_get_uuid_string);
PHP_FUNCTION(libvirt_storagepool_get_name);
PHP_FUNCTION(libvirt_storagepool_lookup_by_uuid_string);
--
2.3.3
9 years, 6 months
Re: [libvirt] add a rbd disk by virsh attach-device , the operation fails
by 饶俊明
The problem has been resolved,.
qemu-kvm is required to support the Ceph RBD versions, and restart the virtual machine;
---------------------------------------------------------------------------
-----邮件原件-----
发件人: Martin Kletzander [mailto:mkletzan@redhat.com]
发送时间: 2015年5月5日 14:15
收件人: 饶俊明
抄送: libvir-list(a)redhat.com
主题: Re: [libvirt] add a rbd disk by virsh attach-device , the operation fails
On Tue, May 05, 2015 at 03:25:39AM +0000, 饶俊明 wrote:
>Hello:
> add a rbd disk by virsh attach-device ,the operation fails; libvirt
>version: libvirt-0.10.2-46.el6.x86_64 operated virsh pool-info, pool-edit, attach-device domain_id /tmp/rbddisk.xml command:
>
Hi there,
this list is for upstream discussions and as I can see, the version of libvirt you are using is a little old and it's downstream. Try whether this problem persist with e.g. the now released version 1.2.15 or feel free to contact your support specialist in case you are using RHEL.
>virsh # pool-info 0a081d22-070b-3f58-a883-78e29012b052
>Name: 0a081d22-070b-3f58-a883-78e29012b052
>UUID: 0a081d22-070b-3f58-a883-78e29012b052
>State: running
>Persistent: no
>Autostart: no
>Capacity: 305.50 TiB
>Allocation: 173.06 GiB
>Available: 304.98 TiB
>
>virsh # pool-edit 0a081d22-070b-3f58-a883-78e29012b052
><pool type='rbd'>
> <name>0a081d22-070b-3f58-a883-78e29012b052</name>
> <uuid>0a081d22-070b-3f58-a883-78e29012b052</uuid>
> <capacity unit='bytes'>335898508001280</capacity>
> <allocation unit='bytes'>185824236409</allocation>
> <available unit='bytes'>335327800442880</available>
> <source>
> <host name='szebs01.app.paic.com.cn' port='6789'/>
> <name>ebs_sz_01_01</name>
> <auth username='szbcs' type='ceph'>
> <secret uuid='0a081d22-070b-3f58-a883-78e29012b052'/>
> </auth>
> </source>
></pool>
>
>virsh # attach-device 52 /tmp/rbddisk.xml
>error: Failed to attach device from /tmp/rbddisk.xml
>error: internal error unable to execute QEMU command
>'__com.redhat_drive_add': Device 'drive-virtio-disk1' could not be
>initialized
>
This error comes from qemu, but it doesn't say much.
Does the domain fail to start with the disk already in the XML or is this a problem just with hot-plugging?
>This context of /tmp/rbddisk.xml :
> <disk type='network' device='disk'>
> <driver name='qemu' type='raw' cache='none'/>
> <auth username='szbcs'>
> <secret type='ceph' uuid='0a081d22-070b-3f58-a883-78e29012b052'/>
> </auth>
> <source protocol='rbd' name='ebs_sz_01_01/5eba8a02-f251-4674-88b8-e368a07d50c5'>
> <host name='szebs01.app.paic.com.cn' port='6789'/>
> </source>
> <target dev='vdb' bus='virtio'/>
> <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
> </disk>
>
>This error information in libvirtd log file:
>2015-05-05 02:51:52.005+0000: 32082: error :
>qemuMonitorJSONCheckError:359 : internal error unable to execute QEMU
>command '__com.redhat_drive_add': Device 'drive-virtio-disk1' could not
>be initialized
>
This is only one line and it doesn't say anything more than the error from virsh. Try looking at more context, or rather in the domain's log file where qemu might've said more about the error.
********************************************************************************************************************************
The information in this email is confidential and may be legally privileged. If you have received this email in error or are not the intended recipient, please immediately notify the sender and delete this message from your computer. Any use, distribution, or copying of this email other than by the intended recipient is strictly prohibited. All messages sent to and from us may be monitored to ensure compliance with internal policies and to protect our business.
Emails are not secure and cannot be guaranteed to be error free as they can be intercepted, amended, lost or destroyed, or contain viruses. Anyone who communicates with us by email is taken to accept these risks.
收发邮件者请注意:
本邮件含保密信息,若误收本邮件,请务必通知发送人并直接删去,不得使用、传播或复制本邮件。
进出邮件均受到本公司合规监控。邮件可能发生被截留、被修改、丢失、被破坏或包含计算机病毒等不安全情况。
********************************************************************************************************************************
9 years, 6 months
[libvirt] [PATCH] Ignore bridge template names with multiple printf conversions
by Ján Tomko
For some reason, we allow a bridge name with %d in it, which we replace
with an unsigned integer to form a bridge name that does not yet exist
on the host.
Do not blindly pass it to virAsprintf if it's not the only conversion,
to prevent crashing on input like:
<network>
<name>test</name>
<forward mode='none'/>
<bridge name='virbr%d%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s'/>
</network>
Ignore any template strings that do not have exactly one %d conversion,
like we do in various drivers before calling virNetDevTapCreateInBridgePort.
---
This was added by commit 4c3f3b4
http://libvirt.org/git/?p=libvirt.git;a=commitdiff;h=4c3f3b4
https://www.redhat.com/archives/libvir-list/2009-April/msg00394.html
claiming it worked some time before that
src/network/bridge_driver.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 3b879cd..1c5613a 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -2775,7 +2775,13 @@ networkFindUnusedBridgeName(virNetworkObjListPtr nets,
int ret = -1, id = 0;
char *newname = NULL;
- const char *templ = def->bridge ? def->bridge : "virbr%d";
+ const char *templ = "virbr%d";
+ const char *p;
+
+ if (def->bridge &&
+ (p = strchr(def->bridge, '%')) == strrchr(def->bridge, '%') &&
+ strstr(def->bridge, "%d"))
+ templ = def->bridge;
do {
if (virAsprintf(&newname, templ, id) < 0)
@@ -2809,7 +2815,7 @@ networkFindUnusedBridgeName(virNetworkObjListPtr nets,
/*
* networkValidateBridgeName() - if no bridge name is set, or if the
- * bridge name contains a %d (indicating that this is a template for
+ * bridge name contains a % (indicating that this is a template for
* the actual name) try to set an appropriate bridge name. If a
* bridge name *is* set, make sure it doesn't conflict with any other
* network's bridge name.
@@ -2820,7 +2826,7 @@ networkBridgeNameValidate(virNetworkObjListPtr nets,
{
int ret = -1;
- if (def->bridge && !strstr(def->bridge, "%d")) {
+ if (def->bridge && !strchr(def->bridge, '%')) {
if (virNetworkBridgeInUse(nets, def->bridge, def->name)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("bridge name '%s' already in use."),
--
2.0.5
9 years, 6 months
[libvirt] [PATCH] qemu: Properly rename persistent def after migration
by Jiri Denemark
When migrating a domain while changing its name and using
VIR_MIGRATE_PERSIST_DEST flag, libvirt would fail to properly change the
name in the persistent definition. The inconsistency results in weird
behavior when dumping domain XML, destroying the domain, restarting
libvirtd and likely in several other situations.
Since the new name is already stored in vm->def->name, we just need to
make sure the persistent definition uses this new name too.
https://bugzilla.redhat.com/show_bug.cgi?id=1076354
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/qemu/qemu_migration.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 20c2193..c1af704 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1392,6 +1392,14 @@ qemuMigrationEatCookie(virQEMUDriverPtr driver,
flags) < 0)
goto error;
+ if (flags & QEMU_MIGRATION_COOKIE_PERSISTENT &&
+ mig->persistent &&
+ STRNEQ(dom->def->name, mig->persistent->name)) {
+ VIR_FREE(mig->persistent->name);
+ if (VIR_STRDUP(mig->persistent->name, dom->def->name) < 0)
+ goto error;
+ }
+
if (mig->flags & QEMU_MIGRATION_COOKIE_LOCKSTATE) {
if (!mig->lockDriver) {
if (virLockManagerPluginUsesState(driver->lockManager)) {
--
2.4.0
9 years, 6 months
[libvirt] add a rbd disk by virsh attach-device , the operation fails
by 饶俊明
Hello:
add a rbd disk by virsh attach-device ,the operation fails; libvirt version: libvirt-0.10.2-46.el6.x86_64
operated virsh pool-info, pool-edit, attach-device domain_id /tmp/rbddisk.xml command:
virsh # pool-info 0a081d22-070b-3f58-a883-78e29012b052
Name: 0a081d22-070b-3f58-a883-78e29012b052
UUID: 0a081d22-070b-3f58-a883-78e29012b052
State: running
Persistent: no
Autostart: no
Capacity: 305.50 TiB
Allocation: 173.06 GiB
Available: 304.98 TiB
virsh # pool-edit 0a081d22-070b-3f58-a883-78e29012b052
<pool type='rbd'>
<name>0a081d22-070b-3f58-a883-78e29012b052</name>
<uuid>0a081d22-070b-3f58-a883-78e29012b052</uuid>
<capacity unit='bytes'>335898508001280</capacity>
<allocation unit='bytes'>185824236409</allocation>
<available unit='bytes'>335327800442880</available>
<source>
<host name='szebs01.app.paic.com.cn' port='6789'/>
<name>ebs_sz_01_01</name>
<auth username='szbcs' type='ceph'>
<secret uuid='0a081d22-070b-3f58-a883-78e29012b052'/>
</auth>
</source>
</pool>
virsh # attach-device 52 /tmp/rbddisk.xml
error: Failed to attach device from /tmp/rbddisk.xml
error: internal error unable to execute QEMU command '__com.redhat_drive_add': Device 'drive-virtio-disk1' could not be initialized
This context of /tmp/rbddisk.xml :
<disk type='network' device='disk'>
<driver name='qemu' type='raw' cache='none'/>
<auth username='szbcs'>
<secret type='ceph' uuid='0a081d22-070b-3f58-a883-78e29012b052'/>
</auth>
<source protocol='rbd' name='ebs_sz_01_01/5eba8a02-f251-4674-88b8-e368a07d50c5'>
<host name='szebs01.app.paic.com.cn' port='6789'/>
</source>
<target dev='vdb' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</disk>
This error information in libvirtd log file:
2015-05-05 02:51:52.005+0000: 32082: error : qemuMonitorJSONCheckError:359 : internal error unable to execute QEMU command '__com.redhat_drive_add': Device 'drive-virtio-disk1' could not be initialized
Thanks!!
********************************************************************************************************************************
The information in this email is confidential and may be legally privileged. If you have received this email in error or are not the intended recipient, please immediately notify the sender and delete this message from your computer. Any use, distribution, or copying of this email other than by the intended recipient is strictly prohibited. All messages sent to and from us may be monitored to ensure compliance with internal policies and to protect our business.
Emails are not secure and cannot be guaranteed to be error free as they can be intercepted, amended, lost or destroyed, or contain viruses. Anyone who communicates with us by email is taken to accept these risks.
�跺���欢���娉ㄦ�锛����浠跺�淇��淇℃�锛��璇�����浠讹�璇峰�蹇���ュ���汉骞剁��ュ��伙�涓��浣跨�������澶�����浠躲�
杩����欢����版�������������浠跺��藉����������淇����涪澶便�琚��������璁$��虹�姣��涓���ㄦ��点�
********************************************************************************************************************************
9 years, 6 months
[libvirt] [libvirt-test-api][PATCH] Add a new test case for getMemoryParameters
by Luyao Huang
Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
---
cases/test_connection.conf | 4 ++
repos/virconn/connection_getMemoryParameters.py | 61 +++++++++++++++++++++++++
2 files changed, 65 insertions(+)
create mode 100644 repos/virconn/connection_getMemoryParameters.py
diff --git a/cases/test_connection.conf b/cases/test_connection.conf
index 914acac..3c08a95 100644
--- a/cases/test_connection.conf
+++ b/cases/test_connection.conf
@@ -69,3 +69,7 @@ storage:pool_uuid
virconn:connection_getCellsFreeMemory
conn
qemu:///system
+
+virconn:connection_getMemoryParameters
+ conn
+ qemu:///system
diff --git a/repos/virconn/connection_getMemoryParameters.py b/repos/virconn/connection_getMemoryParameters.py
new file mode 100644
index 0000000..9b88fc3
--- /dev/null
+++ b/repos/virconn/connection_getMemoryParameters.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+
+import libvirt
+from libvirt import libvirtError
+from utils import utils
+
+required_params = ()
+optional_params = {'conn': ''}
+node_memory = ['full_scans',
+ 'merge_across_nodes',
+ 'pages_shared',
+ 'pages_sharing',
+ 'pages_to_scan',
+ 'pages_unshared',
+ 'pages_volatile',
+ 'sleep_millisecs']
+
+SYSFS_MEMORY_SHARED_PATH = '/sys/kernel/mm/ksm/'
+LIBVIRT_API_PATH = '/usr/share/libvirt/api/libvirt-api.xml'
+flags=0
+
+def check_memory_parameter(libvirt_dict, parameter_name):
+ a = libvirt_dict.get('shm_%s' % parameter_name)
+ try:
+ b = long(open('%s%s' % (SYSFS_MEMORY_SHARED_PATH, parameter_name)).read())
+ except IOError:
+ logger.info("Cannot get file in path %s%s" \
+ % (SYSFS_MEMORY_SHARED_PATH, parameter_name))
+ return 1
+ logger.info("equal %s : libvirt get %u and we get %u"\
+ % (parameter_name, a, b))
+ if a == b:
+ return 0
+ else:
+ return 1
+
+def connection_getMemoryParameters(params):
+ """
+ test API for getMemoryParameters in class virConnect
+ """
+ global logger
+ logger = params['logger']
+ fail=0
+
+ try:
+ conn=libvirt.open(params['conn'])
+
+ logger.info("get connection to libvirtd")
+
+ if utils.check_flags('getMemoryParameters', LIBVIRT_API_PATH) == 1:
+ return 1
+
+ param_dict=conn.getMemoryParameters()
+
+ for n in node_memory:
+ fail=check_memory_parameter(param_dict, n)
+
+ except libvirtError, e:
+ logger.error("API error message: %s" % e.message)
+ fail=1
+ return fail
--
1.8.3.1
9 years, 6 months