[libvirt] [PATCHv6 0/6] Add virNodeGetCPUStats() API
by Minoru Usui
Hi,
This is v6 of virNodeGetCPUTimeParameters() API.
(This time, I rename it to virNodeGetCPUStats())
It returns cpu utilization or
cumulative cpu time of the node from /proc/stat since node boots up.
This patch only supports linux host.
Changes
v5->v6
- Rename API name to virNodeGetCPUStats()
- virsh nodecpustats subcommand returns raw/absolute cputime value by default,
and add --percent option for printing utilization.
v4->v5
- Rebase latest libvirt GIT tree.
v3->v4
- Rebase this patch like virDomainGetMemoryParameters() from v2 patches.
(drop v3 patches except virsh subcommand)
- Rename API name to virNodeGetCPUTimeParameters()
v2->v3
- Change user I/F. It is able to request what the user want by the @flags.
- Minor change of virsh nodecputime I/F.
v1->v2
- Change user I/F like virDomainGetMemoryStats()
- It can return either cpu utilization or cumulative cpu time of the node
depends on each driver.
Minoru Usui (6):
[v6] virNodeGetCPUStats: Expose new API
[v6] virNodeGetCPUStats: Define internal driver API
[v6] virNodeGetCPUStats: Implement public API
[v6] virNodeGetCPUStats: Implement remote protocol
[v6] virNodeGetCPUStats: Implement virsh support
[v6] virNodeGetCPUStats: Implement linux support
daemon/remote.c | 76 +++++++++++++++++++++++++
include/libvirt/libvirt.h.in | 65 +++++++++++++++++++++
src/driver.h | 8 +++
src/libvirt.c | 85 ++++++++++++++++++++++++++++
src/libvirt_private.syms | 1 +
src/libvirt_public.syms | 1 +
src/lxc/lxc_driver.c | 1 +
src/nodeinfo.c | 127 ++++++++++++++++++++++++++++++++++++++++++
src/nodeinfo.h | 5 +-
src/qemu/qemu_driver.c | 1 +
src/remote/remote_driver.c | 65 +++++++++++++++++++++
src/remote/remote_protocol.x | 21 +++++++-
src/uml/uml_driver.c | 1 +
tools/virsh.c | 127 ++++++++++++++++++++++++++++++++++++++++++
tools/virsh.pod | 6 ++
15 files changed, 588 insertions(+), 2 deletions(-)
--
Minoru Usui <usui(a)mxm.nes.nec.co.jp>
13 years, 5 months
[libvirt] [PATCH] security: plug regression introduced in disk probe logic
by Eric Blake
Regression introduced in commit d6623003 (v0.8.8) - using the
wrong sizeof operand meant that security manager private data
was overlaying the allowDiskFOrmatProbing member of struct
_virSecurityManager. This reopens disk probing, which was
supposed to be prevented by the solution to CVE-2010-2238.
* src/security/security_manager.c
(virSecurityManagerGetPrivateData): Use correct offset.
---
src/security/security_manager.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/security/security_manager.c b/src/security/security_manager.c
index 0246dd8..833c1a2 100644
--- a/src/security/security_manager.c
+++ b/src/security/security_manager.c
@@ -107,7 +107,7 @@ virSecurityManagerPtr virSecurityManagerNew(const char *name,
void *virSecurityManagerGetPrivateData(virSecurityManagerPtr mgr)
{
- return ((char*)mgr) + sizeof(mgr);
+ return ((char*)mgr) + sizeof(*mgr);
}
--
1.7.4.4
13 years, 5 months
[libvirt] [PATCH v2] screenshot: Expose the new API in virsh
by Michal Privoznik
* tools/virsh.c: Add screenshot command
* tools/virsh.pod: Document new command
* src/libvirt.c: Fix off-be-one error
---
diff to v1:
- make filename optional and generate filename when missing
src/libvirt.c | 2 +-
tools/virsh.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
tools/virsh.pod | 9 +++
3 files changed, 162 insertions(+), 1 deletions(-)
diff --git a/src/libvirt.c b/src/libvirt.c
index 5a5439d..cfb9e3b 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -2461,7 +2461,7 @@ error:
* The screen ID is the sequential number of screen. In case of multiple
* graphics cards, heads are enumerated before devices, e.g. having
* two graphics cards, both with four heads, screen ID 5 addresses
- * the first head on the second card.
+ * the second head on the second card.
*
* Returns a string representing the mime-type of the image format, or
* NULL upon error. The caller must free() the returned value.
diff --git a/tools/virsh.c b/tools/virsh.c
index e35637d..aad930e 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1879,6 +1879,157 @@ cmdDump(vshControl *ctl, const vshCmd *cmd)
return ret;
}
+static const vshCmdInfo info_screenshot[] = {
+ {"help", N_("take a screenshot of a current domain console and store it "
+ "into a file")},
+ {"desc", N_("screenshot of a current domain console")},
+ {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_screenshot[] = {
+ {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
+ {"file", VSH_OT_DATA, VSH_OFLAG_NONE, N_("where to store the screenshot")},
+ {"screen", VSH_OT_INT, VSH_OFLAG_NONE, N_("ID of a screen to take screenshot of")},
+ {NULL, 0, 0, NULL}
+};
+
+static int cmdScreenshotSink(virStreamPtr st ATTRIBUTE_UNUSED,
+ const char *bytes, size_t nbytes, void *opaque)
+{
+ int *fd = opaque;
+
+ return safewrite(*fd, bytes, nbytes);
+}
+
+/**
+ * Generate string: '<domain name>-<timestamp>>[<extension>]'
+ */
+static char *
+vshGenerFileName(vshControl *ctl, virDomainPtr dom) {
+ char timestr[100];
+ struct timeval cur_time;
+ struct tm time_info;
+ const char *ext = NULL;
+ const char *hypType = NULL;
+ char *ret = NULL;
+
+ /* We should be already connected, but doesn't
+ * hurt to check */
+ if (!vshConnectionUsability(ctl, ctl->conn))
+ return NULL;
+
+ if (!dom) {
+ vshError(ctl, "%s", _("Invalid domain supplied"));
+ return NULL;
+ }
+
+ if (!(hypType = virConnectGetType(ctl->conn))) {
+ vshError(ctl, "%s", _("Can't query hypervisor's type"));
+ return NULL;
+ }
+
+ if (STREQ(hypType, "QEMU"))
+ ext = ".ppm";
+ else if (STREQ(hypType, "VBOX"))
+ ext = ".png";
+ /* add hypervisors here */
+
+ gettimeofday(&cur_time, NULL);
+ localtime_r(&cur_time.tv_sec, &time_info);
+ strftime(timestr, sizeof(timestr), "%Y-%m-%d-%H:%M:%S", &time_info);
+
+ if (virAsprintf(&ret, "%s-%s%s", virDomainGetName(dom),
+ timestr, ext ? ext : "") < 0) {
+ vshError(ctl, "%s", _("Out of memory"));
+ return false;
+ }
+
+ return ret;
+}
+
+static bool
+cmdScreenshot(vshControl *ctl, const vshCmd *cmd) {
+ virDomainPtr dom;
+ const char *name = NULL;
+ char *file = NULL;
+ int fd = -1;
+ virStreamPtr st = NULL;
+ unsigned int screen = 0;
+ unsigned int flags = 0; /* currently unused */
+ int ret = false;
+ bool created = true;
+ bool generated = false;
+ char *mime = NULL;
+
+ if (!vshConnectionUsability(ctl, ctl->conn))
+ return false;
+
+ if (vshCommandOptString(cmd, "file", (const char **) &file) < 0) {
+ vshError(ctl, "%s", _("file must not be empty"));
+ return false;
+ }
+
+ if (vshCommandOptInt(cmd, "screen", (int*) &screen) < 0) {
+ vshError(ctl, "%s", _("invalid screen ID"));
+ return false;
+ }
+
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
+ return false;
+
+ if (!file) {
+ if (!(file=vshGenerFileName(ctl, dom)))
+ return false;
+ generated = true;
+ }
+
+ if ((fd = open(file, O_WRONLY|O_CREAT|O_EXCL, 0666)) < 0) {
+ created = false;
+ if (errno != EEXIST ||
+ (fd = open(file, O_WRONLY|O_TRUNC, 0666)) < 0) {
+ vshError(ctl, _("cannot create file %s"), file);
+ goto cleanup;
+ }
+ }
+
+ st = virStreamNew(ctl->conn, 0);
+
+ mime = virDomainScreenshot(dom, st, screen, flags);
+ if (mime == NULL) {
+ vshError(ctl, _("could not take a screenshot of %s"), name);
+ goto cleanup;
+ }
+
+ if (virStreamRecvAll(st, cmdScreenshotSink, &fd) < 0) {
+ vshError(ctl, _("could not receive data from domain %s"), name);
+ goto cleanup;
+ }
+
+ if (VIR_CLOSE(fd) < 0) {
+ vshError(ctl, _("cannot close file %s"), file);
+ goto cleanup;
+ }
+
+ if (virStreamFinish(st) < 0) {
+ vshError(ctl, _("cannot close stream on domain %s"), name);
+ goto cleanup;
+ }
+
+ vshPrint(ctl, _("Screenshot saved to %s it's type is %s"), file, mime);
+ ret = true;
+
+cleanup:
+ if (ret == false && created)
+ unlink(file);
+ if (generated)
+ VIR_FREE(file);
+ virDomainFree(dom);
+ if (st)
+ virStreamFree(st);
+ VIR_FORCE_CLOSE(fd);
+ return ret;
+}
+
/*
* "resume" command
*/
@@ -10750,6 +10901,7 @@ static const vshCmdDef domManagementCmds[] = {
{"resume", cmdResume, opts_resume, info_resume},
{"save", cmdSave, opts_save, info_save},
{"schedinfo", cmdSchedinfo, opts_schedinfo, info_schedinfo},
+ {"screenshot", cmdScreenshot, opts_screenshot, info_screenshot},
{"setmaxmem", cmdSetmaxmem, opts_setmaxmem, info_setmaxmem},
{"setmem", cmdSetmem, opts_setmem, info_setmem},
{"setvcpus", cmdSetvcpus, opts_setvcpus, info_setvcpus},
diff --git a/tools/virsh.pod b/tools/virsh.pod
index d11a0e3..5390f19 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -589,6 +589,15 @@ Therefore, -1 is a useful shorthand for 262144.
B<Note>: The weight and cap parameters are defined only for the
XEN_CREDIT scheduler and are now I<DEPRECATED>.
+=item B<screenshot> I<domain-id> I<imagefilepath> optional I<--screen> B<screenID>
+
+Takes a screenshot of a current domain console and stores it into a file.
+Optionally, if hypervisor supports more displays for a domain, I<screenID>
+allows to specify from which should be the screenshot taken. It is the
+sequential number of screen. In case of multiple graphics cards, heads
+are enumerated before devices, e.g. having two graphics cards, both with
+four heads, screen ID 5 addresses the second head on the second card.
+
=item B<setmem> I<domain-id> B<kilobytes> optional I<--config> I<--live>
I<--current>
--
1.7.5.rc3
13 years, 5 months
[libvirt] [PATCH] remote generator: Handle some virTypedParameterPtr using functions
by Matthias Bolte
This doesn't cover the getters that allow to query nparams yet.
---
This patch depends on
https://www.redhat.com/archives/libvir-list/2011-May/msg01856.html
daemon/remote.c | 182 -----------------------------------
daemon/remote_generator.pl | 58 +++++++++++-
src/remote/remote_driver.c | 215 ------------------------------------------
src/remote/remote_protocol.x | 20 ++--
4 files changed, 67 insertions(+), 408 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c
index e8db25b..1c26722 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -785,92 +785,6 @@ no_memory:
}
static int
-remoteDispatchDomainSetSchedulerParameters(struct qemud_server *server ATTRIBUTE_UNUSED,
- struct qemud_client *client ATTRIBUTE_UNUSED,
- virConnectPtr conn,
- remote_message_header *hdr ATTRIBUTE_UNUSED,
- remote_error *rerr,
- remote_domain_set_scheduler_parameters_args *args,
- void *ret ATTRIBUTE_UNUSED)
-{
- virDomainPtr dom = NULL;
- virTypedParameterPtr params = NULL;
- int nparams;
- int rv = -1;
-
- if (!conn) {
- virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
- goto cleanup;
- }
-
- nparams = args->params.params_len;
-
- if ((params = remoteDeserializeTypedParameters(args->params.params_val,
- args->params.params_len,
- REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX,
- &nparams)) == NULL)
- goto cleanup;
-
- if (!(dom = get_nonnull_domain(conn, args->dom)))
- goto cleanup;
-
- if (virDomainSetSchedulerParameters(dom, params, nparams) < 0)
- goto cleanup;
-
- rv = 0;
-
-cleanup:
- if (rv < 0)
- remoteDispatchError(rerr);
- if (dom)
- virDomainFree(dom);
- VIR_FREE(params);
- return rv;
-}
-
-static int
-remoteDispatchDomainSetSchedulerParametersFlags(struct qemud_server *server ATTRIBUTE_UNUSED,
- struct qemud_client *client ATTRIBUTE_UNUSED,
- virConnectPtr conn,
- remote_message_header *hdr ATTRIBUTE_UNUSED,
- remote_error *rerr,
- remote_domain_set_scheduler_parameters_flags_args *args,
- void *ret ATTRIBUTE_UNUSED)
-{
- virDomainPtr dom = NULL;
- virTypedParameterPtr params = NULL;
- int nparams;
- int rv = -1;
-
- if (!conn) {
- virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
- goto cleanup;
- }
-
- if ((params = remoteDeserializeTypedParameters(args->params.params_val,
- args->params.params_len,
- REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX,
- &nparams)) == NULL)
- goto cleanup;
-
- if (!(dom = get_nonnull_domain(conn, args->dom)))
- goto cleanup;
-
- if (virDomainSetSchedulerParametersFlags(dom, params, nparams, args->flags) < 0)
- goto cleanup;
-
- rv = 0;
-
-cleanup:
- if (rv < 0)
- remoteDispatchError(rerr);
- if (dom)
- virDomainFree(dom);
- VIR_FREE(params);
- return rv;
-}
-
-static int
remoteDispatchDomainMemoryStats(struct qemud_server *server ATTRIBUTE_UNUSED,
struct qemud_client *client ATTRIBUTE_UNUSED,
virConnectPtr conn,
@@ -1363,54 +1277,6 @@ cleanup:
}
static int
-remoteDispatchDomainSetMemoryParameters(struct qemud_server *server
- ATTRIBUTE_UNUSED,
- struct qemud_client *client
- ATTRIBUTE_UNUSED,
- virConnectPtr conn,
- remote_message_header *
- hdr ATTRIBUTE_UNUSED,
- remote_error * rerr,
- remote_domain_set_memory_parameters_args
- * args, void *ret ATTRIBUTE_UNUSED)
-{
- virDomainPtr dom = NULL;
- virTypedParameterPtr params = NULL;
- int nparams;
- unsigned int flags;
- int rv = -1;
-
- if (!conn) {
- virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
- goto cleanup;
- }
-
- flags = args->flags;
-
- if ((params = remoteDeserializeTypedParameters(args->params.params_val,
- args->params.params_len,
- REMOTE_DOMAIN_MEMORY_PARAMETERS_MAX,
- &nparams)) == NULL)
- goto cleanup;
-
- if (!(dom = get_nonnull_domain(conn, args->dom)))
- goto cleanup;
-
- if (virDomainSetMemoryParameters(dom, params, nparams, flags) < 0)
- goto cleanup;
-
- rv = 0;
-
-cleanup:
- if (rv < 0)
- remoteDispatchError(rerr);
- VIR_FREE(params);
- if (dom)
- virDomainFree(dom);
- return rv;
-}
-
-static int
remoteDispatchDomainGetMemoryParameters(struct qemud_server *server
ATTRIBUTE_UNUSED,
struct qemud_client *client
@@ -1478,54 +1344,6 @@ cleanup:
}
static int
-remoteDispatchDomainSetBlkioParameters(struct qemud_server *server
- ATTRIBUTE_UNUSED,
- struct qemud_client *client
- ATTRIBUTE_UNUSED,
- virConnectPtr conn,
- remote_message_header *
- hdr ATTRIBUTE_UNUSED,
- remote_error * rerr,
- remote_domain_set_blkio_parameters_args
- * args, void *ret ATTRIBUTE_UNUSED)
-{
- virDomainPtr dom = NULL;
- virTypedParameterPtr params = NULL;
- int nparams;
- unsigned int flags;
- int rv = -1;
-
- if (!conn) {
- virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
- goto cleanup;
- }
-
- flags = args->flags;
-
- if ((params = remoteDeserializeTypedParameters(args->params.params_val,
- args->params.params_len,
- REMOTE_DOMAIN_BLKIO_PARAMETERS_MAX,
- &nparams)) == NULL)
- goto cleanup;
-
- if (!(dom = get_nonnull_domain(conn, args->dom)))
- goto cleanup;
-
- if (virDomainSetBlkioParameters(dom, params, nparams, flags) < 0)
- goto cleanup;
-
- rv = 0;
-
-cleanup:
- if (rv < 0)
- remoteDispatchError(rerr);
- VIR_FREE(params);
- if (dom)
- virDomainFree(dom);
- return rv;
-}
-
-static int
remoteDispatchDomainGetBlkioParameters(struct qemud_server *server
ATTRIBUTE_UNUSED,
struct qemud_client *client
diff --git a/daemon/remote_generator.pl b/daemon/remote_generator.pl
index e901acd..5f4d8e4 100755
--- a/daemon/remote_generator.pl
+++ b/daemon/remote_generator.pl
@@ -407,6 +407,17 @@ elsif ($opt_b) {
}
push(@args_list, "args->$2.$2_len");
+ } elsif ($args_member =~ m/^remote_typed_param (\S+)<(\S+)>;/) {
+ push(@vars_list, "virTypedParameterPtr $1 = NULL");
+ push(@vars_list, "int n$1");
+ push(@args_list, "$1");
+ push(@args_list, "n$1");
+ push(@getters_list, " if (($1 = remoteDeserializeTypedParameters(args->$1.$1_val,\n" .
+ " args->$1.$1_len,\n" .
+ " $2,\n" .
+ " &n$1)) == NULL)\n" .
+ " goto cleanup;\n");
+ push(@free_list, " VIR_FREE(params);");
} elsif ($args_member =~ m/<\S+>;/ or $args_member =~ m/\[\S+\];/) {
# just make all other array types fail
die "unhandled type for argument value: $args_member";
@@ -893,6 +904,7 @@ elsif ($opt_k) {
my @vars_list = ();
my @args_check_list = ();
my @setters_list = ();
+ my @setters_list2 = ();
my $priv_src = "conn";
my $priv_name = "privateData";
my $call_args = "&args";
@@ -973,6 +985,19 @@ elsif ($opt_k) {
push(@setters_list, "args.$arg_name.${arg_name}_val = (char *)$arg_name;");
push(@setters_list, "args.$arg_name.${arg_name}_len = ${arg_name}len;");
push(@args_check_list, { name => "\"$arg_name\"", arg => "${arg_name}len", limit => $limit });
+ } elsif ($args_member =~ m/^remote_typed_param (\S+)<(\S+)>;/) {
+ push(@args_list, "virTypedParameterPtr $1");
+ push(@args_list, "int n$1");
+ push(@setters_list2, "if (remoteSerializeTypedParameters($1, n$1, &args.$1.$1_val, &args.$1.$1_len) < 0) {\n" .
+ " xdr_free((xdrproc_t)xdr_$call->{args}, (char *)&args);\n" .
+ " goto done;\n" .
+ " }");
+ } elsif ($args_member =~ m/^(unsigned )?int (\S+);\s*\/\*\s*call-by-reference\s*\*\//) {
+ my $type_name = $1; $type_name .= "int *";
+ my $arg_name = $2;
+
+ push(@args_list, "$type_name $arg_name");
+ push(@setters_list, "args.$arg_name = *$arg_name;");
} elsif ($args_member =~ m/^(unsigned )?int (\S+);/) {
my $type_name = $1; $type_name .= "int";
my $arg_name = $2;
@@ -1021,6 +1046,7 @@ elsif ($opt_k) {
# handle return values of the function
my @ret_list = ();
+ my @ret_list2 = ();
my $call_ret = "&ret";
my $single_ret_var = "int rv = -1";
my $single_ret_type = "int";
@@ -1029,6 +1055,7 @@ elsif ($opt_k) {
my $single_ret_list_name = "undefined";
my $single_ret_list_max_var = "undefined";
my $single_ret_list_max_define = "undefined";
+ my $single_ret_cleanup = 0;
my $multi_ret = 0;
if ($call->{ret} ne "void" and
@@ -1118,6 +1145,18 @@ elsif ($opt_k) {
$single_ret_var = "vir${type_name}Ptr rv = NULL";
$single_ret_type = "vir${type_name}Ptr";
}
+ } elsif ($ret_member =~ m/^remote_typed_param (\S+)<(\S+)>;\s*\/\*\s*insert@(\d+)\s*\*\//) {
+ splice(@args_list, int($3), 0, ("virTypedParameterPtr $1"));
+ push(@ret_list2, "if (remoteDeserializeTypedParameters(ret.$1.$1_val,\n" .
+ " ret.$1.$1_len,\n" .
+ " $2,\n" .
+ " $1,\n" .
+ " n$1) < 0)\n" .
+ " goto cleanup;\n");
+ $single_ret_cleanup = 1;
+ } elsif ($ret_member =~ m/^remote_typed_param (\S+)<\S+>;/) {
+ # error out on unannotated arrays
+ die "remote_typed_param array without insert@<offset> annotation: $ret_member";
} elsif ($ret_member =~ m/^int (\S+);/) {
my $arg_name = $1;
@@ -1257,6 +1296,17 @@ elsif ($opt_k) {
print "\n";
}
+ if (@setters_list2) {
+ print "\n";
+ print " ";
+ }
+
+ print join("\n ", @setters_list2);
+
+ if (@setters_list2) {
+ print "\n";
+ }
+
if ($call->{ret} ne "void") {
print "\n";
print " memset(&ret, 0, sizeof ret);\n";
@@ -1301,6 +1351,12 @@ elsif ($opt_k) {
print "\n";
}
+ if (@ret_list2) {
+ print " ";
+ print join("\n ", @ret_list2);
+ print "\n";
+ }
+
if (@ret_list) {
print " ";
print join("\n ", @ret_list);
@@ -1316,7 +1372,7 @@ elsif ($opt_k) {
print " rv = 0;\n";
}
- if ($single_ret_as_list) {
+ if ($single_ret_as_list or $single_ret_cleanup) {
print "\n";
print "cleanup:\n";
print " xdr_free((xdrproc_t)xdr_remote_$call->{name}_ret, (char *)&ret);\n";
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index ec290a0..5b3fbc9 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -1930,42 +1930,6 @@ cleanup:
}
static int
-remoteDomainSetMemoryParameters (virDomainPtr domain,
- virTypedParameterPtr params,
- int nparams,
- unsigned int flags)
-{
- int rv = -1;
- remote_domain_set_memory_parameters_args args;
- struct private_data *priv = domain->conn->privateData;
-
- remoteDriverLock(priv);
-
- make_nonnull_domain (&args.dom, domain);
-
- args.flags = flags;
-
- if (remoteSerializeTypedParameters(params, nparams,
- &args.params.params_val,
- &args.params.params_len) < 0) {
- xdr_free ((xdrproc_t) xdr_remote_domain_set_memory_parameters_args,
- (char *) &args);
- goto done;
- }
-
- if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_SET_MEMORY_PARAMETERS,
- (xdrproc_t) xdr_remote_domain_set_memory_parameters_args,
- (char *) &args, (xdrproc_t) xdr_void, (char *) NULL) == -1)
- goto done;
-
- rv = 0;
-
-done:
- remoteDriverUnlock(priv);
- return rv;
-}
-
-static int
remoteDomainGetMemoryParameters (virDomainPtr domain,
virTypedParameterPtr params, int *nparams,
unsigned int flags)
@@ -2014,42 +1978,6 @@ done:
}
static int
-remoteDomainSetBlkioParameters (virDomainPtr domain,
- virTypedParameterPtr params,
- int nparams,
- unsigned int flags)
-{
- int rv = -1;
- remote_domain_set_blkio_parameters_args args;
- struct private_data *priv = domain->conn->privateData;
-
- remoteDriverLock(priv);
-
- make_nonnull_domain (&args.dom, domain);
-
- args.flags = flags;
-
- if (remoteSerializeTypedParameters(params, nparams,
- &args.params.params_val,
- &args.params.params_len) < 0) {
- xdr_free ((xdrproc_t) xdr_remote_domain_set_blkio_parameters_args,
- (char *) &args);
- goto done;
- }
-
- if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_SET_BLKIO_PARAMETERS,
- (xdrproc_t) xdr_remote_domain_set_blkio_parameters_args,
- (char *) &args, (xdrproc_t) xdr_void, (char *) NULL) == -1)
- goto done;
-
- rv = 0;
-
-done:
- remoteDriverUnlock(priv);
- return rv;
-}
-
-static int
remoteDomainGetBlkioParameters (virDomainPtr domain,
virTypedParameterPtr params, int *nparams,
unsigned int flags)
@@ -2449,149 +2377,6 @@ done:
}
static int
-remoteDomainGetSchedulerParameters (virDomainPtr domain,
- virTypedParameterPtr params, int *nparams)
-{
- int rv = -1;
- remote_domain_get_scheduler_parameters_args args;
- remote_domain_get_scheduler_parameters_ret ret;
- struct private_data *priv = domain->conn->privateData;
-
- remoteDriverLock(priv);
-
- make_nonnull_domain (&args.dom, domain);
- args.nparams = *nparams;
-
- memset (&ret, 0, sizeof ret);
- if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_SCHEDULER_PARAMETERS,
- (xdrproc_t) xdr_remote_domain_get_scheduler_parameters_args, (char *) &args,
- (xdrproc_t) xdr_remote_domain_get_scheduler_parameters_ret, (char *) &ret) == -1)
- goto done;
-
- if (remoteDeserializeTypedParameters(ret.params.params_val,
- ret.params.params_len,
- REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX,
- params,
- nparams) < 0)
- goto cleanup;
-
- rv = 0;
-
-cleanup:
- xdr_free ((xdrproc_t) xdr_remote_domain_get_scheduler_parameters_ret, (char *) &ret);
-done:
- remoteDriverUnlock(priv);
- return rv;
-}
-
-static int
-remoteDomainGetSchedulerParametersFlags (virDomainPtr domain,
- virTypedParameterPtr params,
- int *nparams,
- unsigned int flags)
-{
- int rv = -1;
- remote_domain_get_scheduler_parameters_flags_args args;
- remote_domain_get_scheduler_parameters_flags_ret ret;
- struct private_data *priv = domain->conn->privateData;
-
- remoteDriverLock(priv);
-
- make_nonnull_domain (&args.dom, domain);
- args.nparams = *nparams;
- args.flags = flags;
-
- memset (&ret, 0, sizeof ret);
- if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_SCHEDULER_PARAMETERS_FLAGS,
- (xdrproc_t) xdr_remote_domain_get_scheduler_parameters_flags_args, (char *) &args,
- (xdrproc_t) xdr_remote_domain_get_scheduler_parameters_flags_ret, (char *) &ret) == -1)
- goto done;
-
- if (remoteDeserializeTypedParameters(ret.params.params_val,
- ret.params.params_len,
- REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX,
- params,
- nparams) < 0)
- goto cleanup;
-
- rv = 0;
-
-cleanup:
- xdr_free ((xdrproc_t) xdr_remote_domain_get_scheduler_parameters_flags_ret, (char *) &ret);
-done:
- remoteDriverUnlock(priv);
- return rv;
-}
-
-static int
-remoteDomainSetSchedulerParameters (virDomainPtr domain,
- virTypedParameterPtr params, int nparams)
-{
- int rv = -1;
- remote_domain_set_scheduler_parameters_args args;
- struct private_data *priv = domain->conn->privateData;
-
- remoteDriverLock(priv);
-
- make_nonnull_domain (&args.dom, domain);
-
- if (remoteSerializeTypedParameters(params, nparams,
- &args.params.params_val,
- &args.params.params_len) < 0) {
- xdr_free ((xdrproc_t) xdr_remote_domain_set_scheduler_parameters_args,
- (char *) &args);
- goto done;
- }
-
- if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_SET_SCHEDULER_PARAMETERS,
- (xdrproc_t) xdr_remote_domain_set_scheduler_parameters_args, (char *) &args,
- (xdrproc_t) xdr_void, (char *) NULL) == -1)
- goto done;
-
- rv = 0;
-
-done:
- remoteDriverUnlock(priv);
- return rv;
-}
-
-static int
-remoteDomainSetSchedulerParametersFlags(virDomainPtr domain,
- virTypedParameterPtr params,
- int nparams,
- unsigned int flags)
-{
- int rv = -1;
- remote_domain_set_scheduler_parameters_flags_args args;
- struct private_data *priv = domain->conn->privateData;
-
- remoteDriverLock(priv);
-
- make_nonnull_domain (&args.dom, domain);
-
- args.flags = flags;
-
- if (remoteSerializeTypedParameters(params, nparams,
- &args.params.params_val,
- &args.params.params_len) < 0) {
- xdr_free ((xdrproc_t) xdr_remote_domain_set_scheduler_parameters_flags_args,
- (char *) &args);
- goto done;
- }
-
- if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_SET_SCHEDULER_PARAMETERS_FLAGS,
- (xdrproc_t) xdr_remote_domain_set_scheduler_parameters_flags_args, (char *) &args,
- (xdrproc_t) xdr_void, (char *) NULL) == -1)
- goto done;
-
- rv = 0;
-
-done:
- remoteDriverUnlock(priv);
- return rv;
-}
-
-static int
remoteDomainMemoryStats (virDomainPtr domain,
struct _virDomainMemoryStat *stats,
unsigned int nr_stats)
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index 0602c27..c9b8cff 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -427,21 +427,21 @@ struct remote_domain_get_scheduler_type_ret {
struct remote_domain_get_scheduler_parameters_args {
remote_nonnull_domain dom;
- int nparams;
+ int nparams; /* call-by-reference */
};
struct remote_domain_get_scheduler_parameters_ret {
- remote_typed_param params<REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX>;
+ remote_typed_param params<REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX>; /* insert@1 */
};
struct remote_domain_get_scheduler_parameters_flags_args {
remote_nonnull_domain dom;
- int nparams;
+ int nparams; /* call-by-reference */
unsigned int flags;
};
struct remote_domain_get_scheduler_parameters_flags_ret {
- remote_typed_param params<REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX>;
+ remote_typed_param params<REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX>; /* insert@1 */
};
struct remote_domain_set_scheduler_parameters_args {
@@ -2113,8 +2113,8 @@ enum remote_procedure {
REMOTE_PROC_DOMAIN_RESTORE = 54, /* autogen autogen */
REMOTE_PROC_DOMAIN_SAVE = 55, /* autogen autogen */
REMOTE_PROC_DOMAIN_GET_SCHEDULER_TYPE = 56, /* skipgen skipgen */
- REMOTE_PROC_DOMAIN_GET_SCHEDULER_PARAMETERS = 57, /* skipgen skipgen */
- REMOTE_PROC_DOMAIN_SET_SCHEDULER_PARAMETERS = 58, /* skipgen skipgen */
+ REMOTE_PROC_DOMAIN_GET_SCHEDULER_PARAMETERS = 57, /* skipgen autogen */
+ REMOTE_PROC_DOMAIN_SET_SCHEDULER_PARAMETERS = 58, /* autogen autogen */
REMOTE_PROC_GET_HOSTNAME = 59, /* autogen autogen */
REMOTE_PROC_SUPPORTS_FEATURE = 60, /* autogen autogen */
@@ -2267,7 +2267,7 @@ enum remote_procedure {
REMOTE_PROC_DOMAIN_GET_BLOCK_INFO = 194, /* autogen autogen */
REMOTE_PROC_DOMAIN_EVENT_IO_ERROR_REASON = 195, /* autogen autogen */
REMOTE_PROC_DOMAIN_CREATE_WITH_FLAGS = 196, /* autogen autogen */
- REMOTE_PROC_DOMAIN_SET_MEMORY_PARAMETERS = 197, /* skipgen skipgen */
+ REMOTE_PROC_DOMAIN_SET_MEMORY_PARAMETERS = 197, /* autogen autogen */
REMOTE_PROC_DOMAIN_GET_MEMORY_PARAMETERS = 198, /* skipgen skipgen */
REMOTE_PROC_DOMAIN_SET_VCPUS_FLAGS = 199, /* autogen autogen */
REMOTE_PROC_DOMAIN_GET_VCPUS_FLAGS = 200, /* autogen autogen */
@@ -2276,7 +2276,7 @@ enum remote_procedure {
REMOTE_PROC_DOMAIN_IS_UPDATED = 202, /* autogen autogen */
REMOTE_PROC_GET_SYSINFO = 203, /* autogen autogen */
REMOTE_PROC_DOMAIN_SET_MEMORY_FLAGS = 204, /* autogen autogen */
- REMOTE_PROC_DOMAIN_SET_BLKIO_PARAMETERS = 205, /* skipgen skipgen */
+ REMOTE_PROC_DOMAIN_SET_BLKIO_PARAMETERS = 205, /* autogen autogen */
REMOTE_PROC_DOMAIN_GET_BLKIO_PARAMETERS = 206, /* skipgen skipgen */
REMOTE_PROC_DOMAIN_MIGRATE_SET_MAX_SPEED = 207, /* autogen autogen */
REMOTE_PROC_STORAGE_VOL_UPLOAD = 208, /* autogen autogen | writestream@1 */
@@ -2291,12 +2291,12 @@ enum remote_procedure {
REMOTE_PROC_DOMAIN_MIGRATE_PERFORM3 = 216, /* skipgen skipgen */
REMOTE_PROC_DOMAIN_MIGRATE_FINISH3 = 217, /* skipgen skipgen */
REMOTE_PROC_DOMAIN_MIGRATE_CONFIRM3 = 218, /* skipgen skipgen */
- REMOTE_PROC_DOMAIN_SET_SCHEDULER_PARAMETERS_FLAGS = 219, /* skipgen skipgen */
+ REMOTE_PROC_DOMAIN_SET_SCHEDULER_PARAMETERS_FLAGS = 219, /* autogen autogen */
REMOTE_PROC_INTERFACE_CHANGE_BEGIN = 220, /* autogen autogen */
REMOTE_PROC_INTERFACE_CHANGE_COMMIT = 221, /* autogen autogen */
REMOTE_PROC_INTERFACE_CHANGE_ROLLBACK = 222, /* autogen autogen */
- REMOTE_PROC_DOMAIN_GET_SCHEDULER_PARAMETERS_FLAGS = 223, /* skipgen skipgen */
+ REMOTE_PROC_DOMAIN_GET_SCHEDULER_PARAMETERS_FLAGS = 223, /* skipgen autogen */
REMOTE_PROC_DOMAIN_EVENT_CONTROL_ERROR = 224 /* skipgen skipgen */
/*
--
1.7.0.4
13 years, 5 months
[libvirt] remote generator: Legacy support for hyper to long mappings
by Matthias Bolte
This can be considered as a v2 for hyper annotation patch [1]. Dan
argued that hyper-to-long mapping is considered as legacy and hyper
should be mapped to long long for all new APIs. Therefore, he voted
against the longlong annotation, because this should be the default
anyway.
I removed the longlong annotations from the original patch. This
results in version-A of the attached patch 0001. But this optional
annotation makes the parser more complex. One of the reasons for
annotating things in the .x is to have single place to define a new
procedure. But as the long/longlong annotation only affect exiting
procedures and will not be added to new ones it's much simpler to
store this information in the generator itself. This information it is
fixed and will not change anymore. This is implemented in version-B of
the attached patch 0001. I favor version-B, what's your opinion on
this?
Attached patch 0002 extends the apibuild script to allow the usage of
long for the same fixed set as in the remote generator only. It
reports an error when new functions or structs use long instead of
longlong.
[1] https://www.redhat.com/archives/libvir-list/2011-May/msg01434.html
Matthias
13 years, 5 months
[libvirt] [PATCH] Use common parameter order for remote(De)SerializeTypedParameters
by Matthias Bolte
We commonly use "value, length" order, let's stick to this.
---
daemon/remote.c | 40 ++++++++++++++++++++--------------------
src/remote/remote_driver.c | 40 ++++++++++++++++++++--------------------
2 files changed, 40 insertions(+), 40 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c
index 5bcf202..e8db25b 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -546,8 +546,8 @@ cleanup:
static int
remoteSerializeTypedParameters(virTypedParameterPtr params,
int nparams,
- u_int *ret_params_len,
- remote_typed_param **ret_params_val)
+ remote_typed_param **ret_params_val,
+ u_int *ret_params_len)
{
int i;
int rv = -1;
@@ -608,8 +608,8 @@ cleanup:
/* Helper to deserialize typed parameters. */
static virTypedParameterPtr
-remoteDeserializeTypedParameters(u_int args_params_len,
- remote_typed_param *args_params_val,
+remoteDeserializeTypedParameters(remote_typed_param *args_params_val,
+ u_int args_params_len,
int limit,
int *nparams)
{
@@ -712,8 +712,8 @@ remoteDispatchDomainGetSchedulerParameters(struct qemud_server *server ATTRIBUTE
goto cleanup;
if (remoteSerializeTypedParameters(params, nparams,
- &ret->params.params_len,
- &ret->params.params_val) < 0)
+ &ret->params.params_val,
+ &ret->params.params_len) < 0)
goto cleanup;
rv = 0;
@@ -765,8 +765,8 @@ remoteDispatchDomainGetSchedulerParametersFlags(struct qemud_server *server ATTR
goto cleanup;
if (remoteSerializeTypedParameters(params, nparams,
- &ret->params.params_len,
- &ret->params.params_val) < 0)
+ &ret->params.params_val,
+ &ret->params.params_len) < 0)
goto cleanup;
rv = 0;
@@ -805,8 +805,8 @@ remoteDispatchDomainSetSchedulerParameters(struct qemud_server *server ATTRIBUTE
nparams = args->params.params_len;
- if ((params = remoteDeserializeTypedParameters(args->params.params_len,
- args->params.params_val,
+ if ((params = remoteDeserializeTypedParameters(args->params.params_val,
+ args->params.params_len,
REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX,
&nparams)) == NULL)
goto cleanup;
@@ -847,8 +847,8 @@ remoteDispatchDomainSetSchedulerParametersFlags(struct qemud_server *server ATTR
goto cleanup;
}
- if ((params = remoteDeserializeTypedParameters(args->params.params_len,
- args->params.params_val,
+ if ((params = remoteDeserializeTypedParameters(args->params.params_val,
+ args->params.params_len,
REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX,
&nparams)) == NULL)
goto cleanup;
@@ -1387,8 +1387,8 @@ remoteDispatchDomainSetMemoryParameters(struct qemud_server *server
flags = args->flags;
- if ((params = remoteDeserializeTypedParameters(args->params.params_len,
- args->params.params_val,
+ if ((params = remoteDeserializeTypedParameters(args->params.params_val,
+ args->params.params_len,
REMOTE_DOMAIN_MEMORY_PARAMETERS_MAX,
&nparams)) == NULL)
goto cleanup;
@@ -1461,8 +1461,8 @@ remoteDispatchDomainGetMemoryParameters(struct qemud_server *server
}
if (remoteSerializeTypedParameters(params, nparams,
- &ret->params.params_len,
- &ret->params.params_val) < 0)
+ &ret->params.params_val,
+ &ret->params.params_len) < 0)
goto cleanup;
success:
@@ -1502,8 +1502,8 @@ remoteDispatchDomainSetBlkioParameters(struct qemud_server *server
flags = args->flags;
- if ((params = remoteDeserializeTypedParameters(args->params.params_len,
- args->params.params_val,
+ if ((params = remoteDeserializeTypedParameters(args->params.params_val,
+ args->params.params_len,
REMOTE_DOMAIN_BLKIO_PARAMETERS_MAX,
&nparams)) == NULL)
goto cleanup;
@@ -1576,8 +1576,8 @@ remoteDispatchDomainGetBlkioParameters(struct qemud_server *server
}
if (remoteSerializeTypedParameters(params, nparams,
- &ret->params.params_len,
- &ret->params.params_val) < 0)
+ &ret->params.params_val,
+ &ret->params.params_len) < 0)
goto cleanup;
success:
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 75c7db3..ec290a0 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -1801,8 +1801,8 @@ done:
static int
remoteSerializeTypedParameters(virTypedParameterPtr params,
int nparams,
- u_int *args_params_len,
- remote_typed_param **args_params_val)
+ remote_typed_param **args_params_val,
+ u_int *args_params_len)
{
int i;
int rv = -1;
@@ -1863,8 +1863,8 @@ cleanup:
/* Helper to deserialize typed parameters. */
static int
-remoteDeserializeTypedParameters(u_int ret_params_len,
- remote_typed_param *ret_params_val,
+remoteDeserializeTypedParameters(remote_typed_param *ret_params_val,
+ u_int ret_params_len,
int limit,
virTypedParameterPtr params,
int *nparams)
@@ -1946,8 +1946,8 @@ remoteDomainSetMemoryParameters (virDomainPtr domain,
args.flags = flags;
if (remoteSerializeTypedParameters(params, nparams,
- &args.params.params_len,
- &args.params.params_val) < 0) {
+ &args.params.params_val,
+ &args.params.params_len) < 0) {
xdr_free ((xdrproc_t) xdr_remote_domain_set_memory_parameters_args,
(char *) &args);
goto done;
@@ -1996,8 +1996,8 @@ remoteDomainGetMemoryParameters (virDomainPtr domain,
goto cleanup;
}
- if (remoteDeserializeTypedParameters(ret.params.params_len,
- ret.params.params_val,
+ if (remoteDeserializeTypedParameters(ret.params.params_val,
+ ret.params.params_len,
REMOTE_DOMAIN_MEMORY_PARAMETERS_MAX,
params,
nparams) < 0)
@@ -2030,8 +2030,8 @@ remoteDomainSetBlkioParameters (virDomainPtr domain,
args.flags = flags;
if (remoteSerializeTypedParameters(params, nparams,
- &args.params.params_len,
- &args.params.params_val) < 0) {
+ &args.params.params_val,
+ &args.params.params_len) < 0) {
xdr_free ((xdrproc_t) xdr_remote_domain_set_blkio_parameters_args,
(char *) &args);
goto done;
@@ -2080,8 +2080,8 @@ remoteDomainGetBlkioParameters (virDomainPtr domain,
goto cleanup;
}
- if (remoteDeserializeTypedParameters(ret.params.params_len,
- ret.params.params_val,
+ if (remoteDeserializeTypedParameters(ret.params.params_val,
+ ret.params.params_len,
REMOTE_DOMAIN_BLKIO_PARAMETERS_MAX,
params,
nparams) < 0)
@@ -2468,8 +2468,8 @@ remoteDomainGetSchedulerParameters (virDomainPtr domain,
(xdrproc_t) xdr_remote_domain_get_scheduler_parameters_ret, (char *) &ret) == -1)
goto done;
- if (remoteDeserializeTypedParameters(ret.params.params_len,
- ret.params.params_val,
+ if (remoteDeserializeTypedParameters(ret.params.params_val,
+ ret.params.params_len,
REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX,
params,
nparams) < 0)
@@ -2507,8 +2507,8 @@ remoteDomainGetSchedulerParametersFlags (virDomainPtr domain,
(xdrproc_t) xdr_remote_domain_get_scheduler_parameters_flags_ret, (char *) &ret) == -1)
goto done;
- if (remoteDeserializeTypedParameters(ret.params.params_len,
- ret.params.params_val,
+ if (remoteDeserializeTypedParameters(ret.params.params_val,
+ ret.params.params_len,
REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX,
params,
nparams) < 0)
@@ -2536,8 +2536,8 @@ remoteDomainSetSchedulerParameters (virDomainPtr domain,
make_nonnull_domain (&args.dom, domain);
if (remoteSerializeTypedParameters(params, nparams,
- &args.params.params_len,
- &args.params.params_val) < 0) {
+ &args.params.params_val,
+ &args.params.params_len) < 0) {
xdr_free ((xdrproc_t) xdr_remote_domain_set_scheduler_parameters_args,
(char *) &args);
goto done;
@@ -2572,8 +2572,8 @@ remoteDomainSetSchedulerParametersFlags(virDomainPtr domain,
args.flags = flags;
if (remoteSerializeTypedParameters(params, nparams,
- &args.params.params_len,
- &args.params.params_val) < 0) {
+ &args.params.params_val,
+ &args.params.params_len) < 0) {
xdr_free ((xdrproc_t) xdr_remote_domain_set_scheduler_parameters_flags_args,
(char *) &args);
goto done;
--
1.7.0.4
13 years, 5 months
[libvirt] [PATCH] openvz: fix bridge devices parsing in openvzReadNetworkConf()
by Jean-Baptiste Rouault
strchrnul() was called on the wrong string so it returned
the same result for each iteration.
---
src/openvz/openvz_conf.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 5f33f75..6e32242 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -237,7 +237,7 @@ openvzReadNetworkConf(virDomainDefPtr def,
/*parse string*/
do {
- char *next = strchrnul (token, ',');
+ char *next = strchrnul (p, ',');
if (STRPREFIX(p, "ifname=")) {
/* skip in libvirt */
} else if (STRPREFIX(p, "host_ifname=")) {
--
1.7.1
13 years, 5 months
[libvirt] [PATCH] openvz: Add simple test for openvzReadNetworkConf
by Matthias Bolte
Convert openvzLocateConfFile to a replaceable callback to allow
testing the config file parsing without rewriting the whole OpenVZ
config parsing to a more testable structure.
Also ignore the openvzutilstest binary.
---
src/openvz/openvz_conf.c | 28 +++++++++++----
src/openvz/openvz_conf.h | 6 +++
tests/.gitignore | 1 +
tests/openvzutilstest.c | 78 ++++++++++++++++++++++++++++++++++++++++++++
tests/openvzutilstest.conf | 1 +
5 files changed, 106 insertions(+), 8 deletions(-)
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 6e32242..bba4e6f 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -60,6 +60,9 @@ static char *openvzLocateConfDir(void);
static int openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len);
static int openvzLocateConfFile(int vpsid, char **conffile, const char *ext);
static int openvzAssignUUIDs(void);
+static int openvzLocateConfFileDefault(int vpsid, char **conffile, const char *ext);
+
+openvzLocateConfFileFunc openvzLocateConfFileCallback = openvzLocateConfFileDefault;
int
strtoI(const char *str)
@@ -171,7 +174,7 @@ no_memory:
}
-static int
+int
openvzReadNetworkConf(virDomainDefPtr def,
int veid) {
int ret;
@@ -473,6 +476,8 @@ int openvzLoadDomains(struct openvz_driver *driver) {
if (VIR_ALLOC(dom->def) < 0)
goto no_memory;
+ dom->def->virtType = VIR_DOMAIN_VIRT_OPENVZ;
+
if (STREQ(status, "stopped")) {
virDomainObjSetState(dom, VIR_DOMAIN_SHUTOFF,
VIR_DOMAIN_SHUTOFF_UNKNOWN);
@@ -793,12 +798,9 @@ cleanup:
return ret;
}
-/* Locate config file of container
-* return -1 - error
-* 0 - OK
-*/
+
static int
-openvzLocateConfFile(int vpsid, char **conffile, const char *ext)
+openvzLocateConfFileDefault(int vpsid, char **conffile, const char *ext)
{
char * confdir;
int ret = 0;
@@ -817,8 +819,18 @@ openvzLocateConfFile(int vpsid, char **conffile, const char *ext)
return ret;
}
-static char
-*openvzLocateConfDir(void)
+/* Locate config file of container
+ * return -1 - error
+ * 0 - OK
+ */
+static int
+openvzLocateConfFile(int vpsid, char **conffile, const char *ext)
+{
+ return openvzLocateConfFileCallback(vpsid, conffile, ext);
+}
+
+static char *
+openvzLocateConfDir(void)
{
const char *conf_dir_list[] = {"/etc/vz/conf", "/usr/local/etc/conf", NULL};
int i=0;
diff --git a/src/openvz/openvz_conf.h b/src/openvz/openvz_conf.h
index d5a57a6..182ebae 100644
--- a/src/openvz/openvz_conf.h
+++ b/src/openvz/openvz_conf.h
@@ -53,6 +53,11 @@ struct openvz_driver {
int version;
};
+typedef int (*openvzLocateConfFileFunc)(int vpsid, char **conffile, const char *ext);
+
+/* this allows the testsuite to replace the conf file locator function */
+extern openvzLocateConfFileFunc openvzLocateConfFileCallback;
+
int openvz_readline(int fd, char *ptr, int maxlen);
int openvzExtractVersion(struct openvz_driver *driver);
int openvzReadVPSConfigParam(int vpsid, const char *param, char **value);
@@ -66,5 +71,6 @@ int strtoI(const char *str);
int openvzSetDefinedUUID(int vpsid, unsigned char *uuid);
unsigned int openvzGetNodeCPUs(void);
int openvzGetVEID(const char *name);
+int openvzReadNetworkConf(virDomainDefPtr def, int veid);
#endif /* OPENVZ_CONF_H */
diff --git a/tests/.gitignore b/tests/.gitignore
index e3906f0..749b5b9 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -16,6 +16,7 @@ object-locking
object-locking-files.txt
object-locking.cmi
object-locking.cmx
+openvzutilstest
qemuargv2xmltest
qemuhelptest
qemuxml2argvtest
diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c
index fe6a2ea..567131a 100644
--- a/tests/openvzutilstest.c
+++ b/tests/openvzutilstest.c
@@ -12,6 +12,13 @@
# include "util.h"
# include "openvz/openvz_conf.h"
+static int
+testLocateConfFile(int vpsid ATTRIBUTE_UNUSED, char **conffile,
+ const char *ext ATTRIBUTE_UNUSED)
+{
+ return virAsprintf(conffile, "%s/openvzutilstest.conf", abs_srcdir);
+}
+
struct testConfigParam {
const char *param;
const char *value;
@@ -62,10 +69,80 @@ cleanup:
}
static int
+testReadNetworkConf(const void *data ATTRIBUTE_UNUSED)
+{
+ int result = -1;
+ virDomainDefPtr def = NULL;
+ char *actual = NULL;
+ virErrorPtr err = NULL;
+ const char *expected =
+ "<domain type='openvz'>\n"
+ " <uuid>00000000-0000-0000-0000-000000000000</uuid>\n"
+ " <memory>0</memory>\n"
+ " <currentMemory>0</currentMemory>\n"
+ " <vcpu>0</vcpu>\n"
+ " <os>\n"
+ " <type>exe</type>\n"
+ " <init>/sbin/init</init>\n"
+ " </os>\n"
+ " <clock offset='utc'/>\n"
+ " <on_poweroff>destroy</on_poweroff>\n"
+ " <on_reboot>destroy</on_reboot>\n"
+ " <on_crash>destroy</on_crash>\n"
+ " <devices>\n"
+ " <interface type='ethernet'>\n"
+ " <mac address='00:00:00:00:00:00'/>\n"
+ " <ip address='194.44.18.88'/>\n"
+ " </interface>\n"
+ " <interface type='bridge'>\n"
+ " <mac address='00:18:51:c1:05:ee'/>\n"
+ " <target dev='veth105.10'/>\n"
+ " </interface>\n"
+ " </devices>\n"
+ "</domain>\n";
+
+ if (VIR_ALLOC(def) < 0 ||
+ !(def->os.type = strdup("exe")) ||
+ !(def->os.init = strdup("/sbin/init")))
+ goto cleanup;
+
+ def->virtType = VIR_DOMAIN_VIRT_OPENVZ;
+
+ if (openvzReadNetworkConf(def, 1) < 0) {
+ err = virGetLastError();
+ fprintf(stderr, "ERROR: %s\n", err != NULL ? err->message : "<unknown>");
+ goto cleanup;
+ }
+
+ actual = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE);
+
+ if (actual == NULL) {
+ err = virGetLastError();
+ fprintf(stderr, "ERROR: %s\n", err != NULL ? err->message : "<unknown>");
+ goto cleanup;
+ }
+
+ if (STRNEQ(expected, actual)) {
+ virtTestDifference(stderr, expected, actual);
+ goto cleanup;
+ }
+
+ result = 0;
+
+cleanup:
+ VIR_FREE(actual);
+ virDomainDefFree(def);
+
+ return result;
+}
+
+static int
mymain(void)
{
int result = 0;
+ openvzLocateConfFileCallback = testLocateConfFile;
+
# define DO_TEST(_name) \
do { \
if (virtTestRun("OpenVZ "#_name, 1, test##_name, \
@@ -75,6 +152,7 @@ mymain(void)
} while (0)
DO_TEST(ReadConfigParam);
+ DO_TEST(ReadNetworkConf);
return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/tests/openvzutilstest.conf b/tests/openvzutilstest.conf
index a1b93b7..c5d048c 100644
--- a/tests/openvzutilstest.conf
+++ b/tests/openvzutilstest.conf
@@ -39,3 +39,4 @@ QUOTATIME=""
DISK_QUOTA=no
OSTEMPLATE="rhel-5-lystor"
IP_ADDRESS="194.44.18.88"
+NETIF="ifname=eth10,mac=00:18:51:C1:05:EE,host_ifname=veth105.10,host_mac=00:18:51:8F:D9:F3
--
1.7.0.4
13 years, 5 months
[libvirt] virsh version problem with remote connection
by Matthias Bolte
virsh version does basically this
hvType = virConnectGetType(...)
virGetVersion(..., hvType, ...)
[...]
Assuming a remote connection virConnectGetType calls the remote driver
that returns the type of the underlying driver on the server side, for
example QEMU. Then virGetVersion compares hvType to a set of strings
that depend on configure options and returns LIBVIR_VERSION_NUMBER in
most cases. Now this fails in case libvirt on the client side is just
compiled with the remote driver enabled and the server side has the
actual driver such as the QEMU driver. It just happens to work when
the actual driver is compiled in on client and server side. But that's
not the case here.
freebsd# ./tools/virsh -c qemu+tcp://192.168.178.22/system version
Compiled against library: libvir 0.9.2
error: failed to get the library version
error: this function is not supported by the connection driver: virGetVersion
This is not FreeBSD specific, happens on Windows as well due to the
similar drivers configuration. The problem is that virConnectGetType
returns QEMU, but virGetVersion on the client side only accepts Remote
as hvType due to all other drivers being disabled on the client side.
I'm not sure how to fix this properly, does anyone have some idea?
Matthias
13 years, 5 months
[libvirt] [PATCH] util: Fix incorrect error in PCI functions.
by Osier Yang
Substitute VIR_ERR_NO_SUPPORT with VIR_ERR_INTERNAL_ERROR. Error
like following is not what user want to see.
error : pciDeviceIsAssignable:1487 : this function is not supported
by the connection driver: Device 0000:07:10.0 is behind a switch
lacking ACS and cannot be assigned
---
src/util/pci.c | 20 ++++++++++----------
1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/util/pci.c b/src/util/pci.c
index 9cc7b20..8baa3d8 100644
--- a/src/util/pci.c
+++ b/src/util/pci.c
@@ -614,7 +614,7 @@ pciTrySecondaryBusReset(pciDevice *dev,
* are not in use by the host or other guests.
*/
if ((conflict = pciBusContainsActiveDevices(dev, inactiveDevs))) {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Active %s devices on bus with %s, not doing bus reset"),
conflict->name, dev->name);
return -1;
@@ -624,7 +624,7 @@ pciTrySecondaryBusReset(pciDevice *dev,
if (pciGetParentDevice(dev, &parent) < 0)
return -1;
if (!parent) {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to find parent device for %s"),
dev->name);
return -1;
@@ -637,7 +637,7 @@ pciTrySecondaryBusReset(pciDevice *dev,
* are multiple devices/functions
*/
if (pciRead(dev, 0, config_space, PCI_CONF_LEN) < 0) {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to read PCI config space for %s"),
dev->name);
goto out;
@@ -657,7 +657,7 @@ pciTrySecondaryBusReset(pciDevice *dev,
usleep(200 * 1000); /* sleep 200ms */
if (pciWrite(dev, 0, config_space, PCI_CONF_LEN) < 0) {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to restore PCI config space for %s"),
dev->name);
goto out;
@@ -683,7 +683,7 @@ pciTryPowerManagementReset(pciDevice *dev)
/* Save and restore the device's config space. */
if (pciRead(dev, 0, &config_space[0], PCI_CONF_LEN) < 0) {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to read PCI config space for %s"),
dev->name);
return -1;
@@ -703,7 +703,7 @@ pciTryPowerManagementReset(pciDevice *dev)
usleep(10 * 1000); /* sleep 10ms */
if (pciWrite(dev, 0, &config_space[0], PCI_CONF_LEN) < 0) {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to restore PCI config space for %s"),
dev->name);
return -1;
@@ -770,7 +770,7 @@ pciResetDevice(pciDevice *dev,
if (ret < 0) {
virErrorPtr err = virGetLastError();
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to reset PCI device %s: %s"),
dev->name,
err ? err->message : _("no FLR, PM reset or bus reset available"));
@@ -1324,7 +1324,7 @@ pciGetDevice(unsigned domain,
product = pciReadDeviceID(dev, "device");
if (!vendor || !product) {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to read product/vendor ID for %s"),
dev->name);
VIR_FREE(product);
@@ -1588,7 +1588,7 @@ pciDeviceIsBehindSwitchLackingACS(pciDevice *dev)
if (dev->bus == 0)
return 0;
else {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to find parent device for %s"),
dev->name);
return -1;
@@ -1643,7 +1643,7 @@ int pciDeviceIsAssignable(pciDevice *dev,
VIR_DEBUG("%s %s: strict ACS check disabled; device assignment allowed",
dev->id, dev->name);
} else {
- pciReportError(VIR_ERR_NO_SUPPORT,
+ pciReportError(VIR_ERR_INTERNAL_ERROR,
_("Device %s is behind a switch lacking ACS and "
"cannot be assigned"),
dev->name);
--
1.7.4
13 years, 5 months