[PATCH 4/11] arch/x86/kvm: Correct NULL test

2010-02-06 Thread Julia Lawall
From: Julia Lawall ju...@diku.dk

msr was tested above, so the second test is not needed.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// smpl
@r@
expression *x;
expression e;
identifier l;
@@

if (x == NULL || ...) {
... when forall
return ...; }
... when != goto l;
when != x = e
when != x
*x == NULL
// /smpl

Signed-off-by: Julia Lawall ju...@diku.dk

---
 arch/x86/kvm/vmx.c  |2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 7375ae1..422bfc8 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -1609,8 +1609,6 @@ static void vmx_set_efer(struct kvm_vcpu *vcpu, u64 efer)
 */
vmx_load_host_state(to_vmx(vcpu));
vcpu-arch.shadow_efer = efer;
-   if (!msr)
-   return;
if (efer  EFER_LMA) {
vmcs_write32(VM_ENTRY_CONTROLS,
 vmcs_read32(VM_ENTRY_CONTROLS) |
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: How to edit *.qcow2

2010-02-06 Thread Liang Guo
在 星期五 05 二月 2010 14:54:57,sati...@pacific.net.hk 写道:
 Hi Liang,
 
 
 Thanks for your advice and link.
 
 Host - Debian 5.0
 KVM
 libvirt
 
  run  kvm-nbd  VM/vm30.qcow2, modprobe nbd
  nbd-client localhost 1024 /dev/nbd0
 
  then you can use /dev/nbd0 as a block device like /dev/sda
 
  I've write a little essay on how to install Debian on kvm image, FYI:
 
  http://blog.chinaunix.net/u/7667/showart_2112267.html
 
 I can't find kvm-nbd and nbd-client.  I have nbd installed already.
 
 
 $ yum list nbd
 Loaded plugins: presto, refresh-packagekit
 Available Packages
 nbd.x86_642.9.13-1.fc12   fedora
 
 
 $ which kvm-nbd
 /usr/bin/which: no kvm-nbd in
 (/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:
 /usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/satimis/bin)
 
 
 $ which qemu-nbd
 /usr/bin/qemu-nbd
 
 
 $ which nbd-client
 /usr/bin/which: no nbd-client in
 (/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:
 /usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/satimis/bin)
 
 
 I suppose qemu-nbd = kvm-nbd ?  Where is nbd-client ?
In debian stable, kvm-nbd command is from pacakge kvm, please see 
http://packages.debian.org/lenny/amd64/kvm/filelist

If you are using Debian SID, you should use qemu-kvm instead of kvm. 

nbd-client command is from package nbd-client, please see:
http://packages.debian.org/lenny/amd64/nbd-client/filelist, It is in /sbin 
directory, so you should use root to run it.

qemu-nbd is from package qemu-utils, I have not use it, but I think it should 
do the same thing as kvm-nbd. 

I don't know fedora exactly, but I think fedora should have relevant package.

Best Wishes. 

-- 
Liang Guo
http://bluestone.cublog.cn
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Add assignment operation to config file parser..

2010-02-06 Thread john cooper
This patch reworks support for both assignment and
append in the config file parser.  It was motivated
by comments received on the cpu model config file
format.

Commit dc9ca4ba27be4fe6a0284061b8f056c4364fb0d9
changed the behavior of = from assign to append.
This patch preserves the ability to append to an
option (however now via +=), reverts = to its
previous behavior, and allows both to interoperate.

Signed-off-by: john cooper john.coo...@redhat.com
---

diff --git a/qemu-config.c b/qemu-config.c
index 246fae6..4e53250 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -429,6 +429,7 @@ int qemu_config_parse(FILE *fp)
 char line[1024], group[64], id[64], arg[64], value[1024];
 QemuOptsList *list = NULL;
 QemuOpts *opts = NULL;
+char append;
 
 while (fgets(line, sizeof(line), fp) != NULL) {
 if (line[0] == '\n') {
@@ -455,13 +456,16 @@ int qemu_config_parse(FILE *fp)
 opts = qemu_opts_create(list, NULL, 0);
 continue;
 }
-if (sscanf(line,  %63s = \%1023[^\]\, arg, value) == 2) {
-/* arg = value */
+append = 0;
+if (sscanf(line,  %63s = \%1023[^\]\, arg, value) == 2 ||
+(sscanf(line,  %63s += \%1023[^\]\, arg, value) == 2 ?
+append = 1 : 0)) {
+/* arg = value, arg += value */
 if (opts == NULL) {
 fprintf(stderr, no group defined\n);
 return -1;
 }
-if (qemu_opt_set(opts, arg, value) != 0) {
+if (_qemu_opt_set(opts, arg, value, append) != 0) {
 fprintf(stderr, failed to set \%s\ for %s\n,
 arg, group);
 return -1;
diff --git a/qemu-option.c b/qemu-option.c
index a52a4c4..7c0faed 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -562,7 +562,11 @@ static void qemu_opt_del(QemuOpt *opt)
 qemu_free(opt);
 }
 
-int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
+/* add option *name,*value to group *opts.  if append add to tail of option
+ * list, else set as sole element (overwrite any existing entries of *name).
+ */
+int _qemu_opt_set(QemuOpts *opts, const char *name, const char *value,
+  char append)
 {
 QemuOpt *opt;
 QemuOptDesc *desc = opts-list-desc;
@@ -582,13 +586,27 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const 
char *value)
 return -1;
 }
 }
-
-opt = qemu_mallocz(sizeof(*opt));
-opt-name = qemu_strdup(name);
-opt-opts = opts;
-QTAILQ_INSERT_TAIL(opts-head, opt, next);
-if (desc[i].name != NULL) {
-opt-desc = desc+i;
+if (append || !(opt = qemu_opt_find(opts, name))) {
+opt = qemu_mallocz(sizeof(*opt));
+opt-name = qemu_strdup(name);
+opt-opts = opts;
+QTAILQ_INSERT_TAIL(opts-head, opt, next);
+if (desc[i].name != NULL) {
+opt-desc = desc+i;
+}
+} else if (!append) {
+QemuOpt *p, *next;
+
+/* assign to reclaimed *opt, remove all other *name defs */
+QTAILQ_FOREACH_SAFE(p, opts-head, next, next) {
+if (p != opt  !strcmp(name, p-name)) {
+qemu_free((char *)p-str);
+QTAILQ_REMOVE(opts-head, p, next);
+qemu_free((char *)p);
+}
+}
+qemu_free((char *)opt-str);
+opt-str = NULL;
 }
 if (value) {
 opt-str = qemu_strdup(value);
diff --git a/qemu-option.h b/qemu-option.h
index 666b666..2385b1a 100644
--- a/qemu-option.h
+++ b/qemu-option.h
@@ -104,7 +104,14 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name);
 int qemu_opt_get_bool(QemuOpts *opts, const char *name, int defval);
 uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t 
defval);
 uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval);
-int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
+int _qemu_opt_set(QemuOpts *opts, const char *name, const char *value,
+  char append);
+static inline int qemu_opt_set(QemuOpts *opts, const char *name,
+   const char *value)
+{
+return (_qemu_opt_set(opts, name, value, 0));
+}
+
 typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void 
*opaque);
 int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
  int abort_on_failure);
-- 
john.coo...@redhat.com
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html