[libvirt] [PATCH v2] virsh: Emit error for VSH_OT_DATA without VSH_OFLAG_REQ

2014-12-10 Thread Hao Liu
Commit 6b9964 enforces checking invalid use of VSH_OT_STRING with
VSH_OFLAG_REQ. This commit tries to do the same thing to stop using
VSH_OT_DATA without VSH_OFLAG_REQ and also fix existing misuse.

Signed-off-by: Hao Liu 
---
V2:
Add missing fix of dommemstat --period option.

 tools/virsh-domain-monitor.c |  4 +--
 tools/virsh-domain.c | 68 ++--
 tools/virsh-network.c|  6 ++--
 tools/virsh-pool.c   | 18 ++--
 tools/virsh-snapshot.c   | 20 ++---
 tools/virsh.c| 13 +++--
 6 files changed, 68 insertions(+), 61 deletions(-)

diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 259400f..ace2c4a 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -271,7 +271,7 @@ static const vshCmdOptDef opts_dommemstat[] = {
  .help = N_("domain name, id or uuid")
 },
 {.name = "period",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .flags = VSH_OFLAG_REQ_OPT,
  .help = N_("period in seconds to set collection")
 },
@@ -845,7 +845,7 @@ static const vshCmdOptDef opts_domblkstat[] = {
  .help = N_("domain name, id or uuid")
 },
 {.name = "device",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .flags = VSH_OFLAG_EMPTY_OK,
  .help = N_("block device")
 },
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 750411b..6733cfa 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -755,27 +755,27 @@ static const vshCmdOptDef opts_attach_interface[] = {
  .help = N_("source of network interface")
 },
 {.name = "target",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("target network name")
 },
 {.name = "mac",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("MAC address")
 },
 {.name = "script",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("script used to bridge network interface")
 },
 {.name = "model",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("model type")
 },
 {.name = "inbound",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("control domain's incoming traffics")
 },
 {.name = "outbound",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("control domain's outgoing traffics")
 },
 {.name = "persistent",
@@ -1749,7 +1749,7 @@ static const vshCmdOptDef opts_block_commit[] = {
  .help = N_("bandwidth limit in MiB/s")
 },
 {.name = "base",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("path of base file to commit into (default bottom of chain)")
 },
 {.name = "shallow",
@@ -1757,7 +1757,7 @@ static const vshCmdOptDef opts_block_commit[] = {
  .help = N_("use backing file of top as base")
 },
 {.name = "top",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("path of top file to commit from (default top of chain)")
 },
 {.name = "active",
@@ -1977,7 +1977,7 @@ static const vshCmdOptDef opts_block_copy[] = {
  .help = N_("fully-qualified path of source disk")
 },
 {.name = "dest",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("path of the copy to create")
 },
 {.name = "bandwidth",
@@ -2025,11 +2025,11 @@ static const vshCmdOptDef opts_block_copy[] = {
  .help = N_("with --wait, don't wait for cancel to finish")
 },
 {.name = "xml",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("filename containing XML description of the copy destination")
 },
 {.name = "format",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("format of the destination file")
 },
 {.name = "granularity",
@@ -2519,7 +2519,7 @@ static const vshCmdOptDef opts_block_pull[] = {
  .help = N_("bandwidth limit in MiB/s")
 },
 {.name = "base",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("path of backing file in chain for a partial pull")
 },
 {.name = "wait",
@@ -3046,11 +3046,11 @@ static const vshCmdOptDef opts_domiftune[] = {
  .help = N_("interface device (MAC Address)")
 },
 {.name = "inbound",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("control domain's incoming traffics")
 },
 {.name = "outbound",
- .typ

[libvirt] [PATCH] virsh: Emit error for VSH_OT_DATA without VSH_OFLAG_REQ

2014-12-10 Thread Hao Liu
Commit 6b9964 enforces checking invalid use of VSH_OT_STRING with
VSH_OFLAG_REQ. This commit tries to do the same thing to stop using
VSH_OT_DATA without VSH_OFLAG_REQ and also fix existing misuse.

Signed-off-by: Hao Liu 
---
 tools/virsh-domain-monitor.c |  2 +-
 tools/virsh-domain.c | 68 ++--
 tools/virsh-network.c|  6 ++--
 tools/virsh-pool.c   | 18 ++--
 tools/virsh-snapshot.c   | 20 ++---
 tools/virsh.c| 13 +++--
 6 files changed, 67 insertions(+), 60 deletions(-)

diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 259400f..442adfb 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -845,7 +845,7 @@ static const vshCmdOptDef opts_domblkstat[] = {
  .help = N_("domain name, id or uuid")
 },
 {.name = "device",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .flags = VSH_OFLAG_EMPTY_OK,
  .help = N_("block device")
 },
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 750411b..6733cfa 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -755,27 +755,27 @@ static const vshCmdOptDef opts_attach_interface[] = {
  .help = N_("source of network interface")
 },
 {.name = "target",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("target network name")
 },
 {.name = "mac",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("MAC address")
 },
 {.name = "script",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("script used to bridge network interface")
 },
 {.name = "model",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("model type")
 },
 {.name = "inbound",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("control domain's incoming traffics")
 },
 {.name = "outbound",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("control domain's outgoing traffics")
 },
 {.name = "persistent",
@@ -1749,7 +1749,7 @@ static const vshCmdOptDef opts_block_commit[] = {
  .help = N_("bandwidth limit in MiB/s")
 },
 {.name = "base",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("path of base file to commit into (default bottom of chain)")
 },
 {.name = "shallow",
@@ -1757,7 +1757,7 @@ static const vshCmdOptDef opts_block_commit[] = {
  .help = N_("use backing file of top as base")
 },
 {.name = "top",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("path of top file to commit from (default top of chain)")
 },
 {.name = "active",
@@ -1977,7 +1977,7 @@ static const vshCmdOptDef opts_block_copy[] = {
  .help = N_("fully-qualified path of source disk")
 },
 {.name = "dest",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("path of the copy to create")
 },
 {.name = "bandwidth",
@@ -2025,11 +2025,11 @@ static const vshCmdOptDef opts_block_copy[] = {
  .help = N_("with --wait, don't wait for cancel to finish")
 },
 {.name = "xml",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("filename containing XML description of the copy destination")
 },
 {.name = "format",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("format of the destination file")
 },
 {.name = "granularity",
@@ -2519,7 +2519,7 @@ static const vshCmdOptDef opts_block_pull[] = {
  .help = N_("bandwidth limit in MiB/s")
 },
 {.name = "base",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("path of backing file in chain for a partial pull")
 },
 {.name = "wait",
@@ -3046,11 +3046,11 @@ static const vshCmdOptDef opts_domiftune[] = {
  .help = N_("interface device (MAC Address)")
 },
 {.name = "inbound",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("control domain's incoming traffics")
 },
 {.name = "outbound",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  .help = N_("control domain's outgoing traffics")
 },
 {.name = "config",
@@ -3425,7 +3425,7 @@ static const vshCmdOptDef opts_undefine[] = {
  .help = N_("remove domain managed state file")
 },
 {.name = "storage",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_STRING,
  

[libvirt] [PATCH v2] docs: Fix missing curly braces

2014-12-10 Thread Hao Liu
Signed-off-by: Hao Liu 
---
 docs/hacking.html.in | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/docs/hacking.html.in b/docs/hacking.html.in
index a73b1e0..53786b7 100644
--- a/docs/hacking.html.in
+++ b/docs/hacking.html.in
@@ -481,8 +481,9 @@
 
 
   while (expr1 &&
- expr2)   // multi-line, at same indentation, {} required
+ expr2) { // multi-line, at same indentation, {} required
   single_line_stmt();
+  }
 
 
 
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] docs: Fix missing curly braces

2014-12-09 Thread Hao Liu
Signed-off-by: Hao Liu 
---
 HACKING | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/HACKING b/HACKING
index 884e78c..94d9d2c 100644
--- a/HACKING
+++ b/HACKING
@@ -383,8 +383,9 @@ single-'statement' loop: each has only one 'line' in its 
body.
   single_line_stmt(); // {} is optional (not enforced either way)
 
   while (expr1 &&
- expr2)   // multi-line, at same indentation, {} required
+ expr2) { // multi-line, at same indentation, {} required
   single_line_stmt();
+  }
 
 However, the moment your loop/if/else body extends on to a second line, for
 whatever reason (even if it's just an added comment), then you should add
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2] storage: Check stderr when matching parted output

2014-12-09 Thread Hao Liu
In old version of parted like parted-2.1-25, error message is shown in
stdout when printing a disk info without disk label.

Error: /dev/sda: unrecognised disk label

This line has been moved to stderr in newer version of parted. So we
should check both stdout and stderr when locating this message.

This should fix bug:
https://bugzilla.redhat.com/show_bug.cgi?id=1172468

Signed-off-by: Hao Liu 
---
V2: (Courtesy of Luyang Huang)
Fixed memory leak;
Fixed curly brace style;

 src/storage/storage_backend_disk.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/storage/storage_backend_disk.c 
b/src/storage/storage_backend_disk.c
index 4b05e8c..3f97fd9 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -370,21 +370,26 @@ virStorageBackendDiskFindLabel(const char* device)
 };
 virCommandPtr cmd = virCommandNew(PARTED);
 char *output = NULL;
+char *error = NULL;
 int ret = -1;
 
 virCommandAddArgSet(cmd, args);
 virCommandAddEnvString(cmd, "LC_ALL=C");
 virCommandSetOutputBuffer(cmd, &output);
+virCommandSetErrorBuffer(cmd, &error);
 
 /* if parted succeeds we have a valid partition table */
 ret = virCommandRun(cmd, NULL);
 if (ret < 0) {
-if (strstr(output, "unrecognised disk label"))
+if (strstr(output, "unrecognised disk label") ||
+strstr(error, "unrecognised disk label")) {
 ret = 1;
+}
 }
 
 virCommandFree(cmd);
 VIR_FREE(output);
+VIR_FREE(error);
 return ret;
 }
 
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] storage: Check stderr when matching parted output

2014-12-09 Thread Hao Liu
In old version of parted like parted-2.1-25, error message is shown in
stdout when printing a disk info without disk label.

Error: /dev/sda: unrecognised disk label

This line has been moved to stderr in newer version of parted. So we
should check both stdout and stderr when locating this message.

This should fix bug:
https://bugzilla.redhat.com/show_bug.cgi?id=1172468

Signed-off-by: Hao Liu 
---
 src/storage/storage_backend_disk.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/storage/storage_backend_disk.c 
b/src/storage/storage_backend_disk.c
index 4b05e8c..d57b67d 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -370,16 +370,19 @@ virStorageBackendDiskFindLabel(const char* device)
 };
 virCommandPtr cmd = virCommandNew(PARTED);
 char *output = NULL;
+char *error = NULL;
 int ret = -1;
 
 virCommandAddArgSet(cmd, args);
 virCommandAddEnvString(cmd, "LC_ALL=C");
 virCommandSetOutputBuffer(cmd, &output);
+virCommandSetErrorBuffer(cmd, &error);
 
 /* if parted succeeds we have a valid partition table */
 ret = virCommandRun(cmd, NULL);
 if (ret < 0) {
-if (strstr(output, "unrecognised disk label"))
+if (strstr(output, "unrecognised disk label") ||
+strstr(error, "unrecognised disk label"))
 ret = 1;
 }
 
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [perl-Sys-Virt][PATCH] Fix memory corruption when calling migrate_to_uri

2014-12-08 Thread Hao Liu
The variable `nparams` didn't change accordingly when adding a new
parameter in commit b2cecf73.

This patch fixes https://bugzilla.redhat.com/show_bug.cgi?id=1171938

Signed-off-by: Hao Liu 
---
 Virt.xs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Virt.xs b/Virt.xs
index 763a117..688b0d7 100644
--- a/Virt.xs
+++ b/Virt.xs
@@ -4342,7 +4342,7 @@ _migrate_to_uri(dom, desturi, newparams, flags=0)
  virTypedParameter *params;
  int nparams;
   PPCODE:
- nparams = 5;
+ nparams = 6;
  Newx(params, nparams, virTypedParameter);
 
  strncpy(params[0].field, VIR_MIGRATE_PARAM_URI,
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] Fix invalid log, misused option types and a typo

2014-11-10 Thread Hao Liu
This patch fixes the following issues.

1)  When an invalid wwn is introduced, libvirt reports
"Malformed wwn: %s". The template won't be replaced.

2)  "target" option for dompmsuspend and "xml" option for
save-image-define are required options and should use
VSH_OT_DATA instead of VSH_OT_STRING as an option type.

3)  A typo.

Signed-off-by: Hao Liu 
---
 src/util/virutil.c   | 4 ++--
 tools/virsh-domain.c | 4 ++--
 tools/virsh-host.c   | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/util/virutil.c b/src/util/virutil.c
index 1116fda..c178515 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -1549,8 +1549,8 @@ virValidateWWN(const char *wwn)
 }
 
 if (i != 16 || p[i]) {
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Malformed wwn: %s"));
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("Malformed wwn: %s"), wwn);
 return false;
 }
 
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 13a904f..8e743f1 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -3228,7 +3228,7 @@ static const vshCmdOptDef opts_dom_pm_suspend[] = {
  .help = N_("duration in seconds")
 },
 {.name = "target",
- .type = VSH_OT_STRING,
+ .type = VSH_OT_DATA,
  .flags = VSH_OFLAG_REQ,
  .help = N_("mem(Suspend-to-RAM), "
 "disk(Suspend-to-Disk), "
@@ -4268,7 +4268,7 @@ static const vshCmdOptDef opts_save_image_define[] = {
  .help = N_("saved state file to modify")
 },
 {.name = "xml",
- .type = VSH_OT_STRING,
+ .type = VSH_OT_DATA,
  .flags = VSH_OFLAG_REQ,
  .help = N_("filename containing updated XML for the target")
 },
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index 4a3ff28..28b160d 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -497,7 +497,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd)
 pageSizes[0] = VIR_DIV_UP(tmp, 1024);
 
 if (vshCommandOptULongLong(cmd, "pagecount", &pageCounts[0]) < 0) {
-vshError(ctl, "%s", _("pagecount hat to be a number"));
+vshError(ctl, "%s", _("pagecount has to be a number"));
 return false;
 }
 
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] virsh: Fix types for option bandwidth in block*

2014-11-06 Thread Hao Liu
Bandwidth options in blockcommit, blockcopy, blockjob and blockpull
are parsed by vshCommandOptULWrap() and should be shown as a number
type option.

And a typo is fixed.

Signed-off-by: Hao Liu 
---
 tools/virsh-domain.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index dfc3a8c..bd5f404 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -1616,7 +1616,7 @@ static const vshCmdOptDef opts_block_commit[] = {
  .help = N_("fully-qualified path of disk")
 },
 {.name = "bandwidth",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_INT,
  .help = N_("bandwidth limit in MiB/s")
 },
 {.name = "base",
@@ -1834,7 +1834,7 @@ static const vshCmdOptDef opts_block_copy[] = {
  .help = N_("path of the copy to create")
 },
 {.name = "bandwidth",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_INT,
  .help = N_("bandwidth limit in MiB/s")
 },
 {.name = "shallow",
@@ -2190,8 +2190,8 @@ static const vshCmdOptDef opts_block_job[] = {
  .help = N_("implies --info; output details rather than human summary")
 },
 {.name = "bandwidth",
- .type = VSH_OT_DATA,
- .help = N_("set the Bandwidth limit in MiB/s")
+ .type = VSH_OT_INT,
+ .help = N_("set the bandwidth limit in MiB/s")
 },
 {.name = NULL}
 };
@@ -2349,7 +2349,7 @@ static const vshCmdOptDef opts_block_pull[] = {
  .help = N_("fully-qualified path of disk")
 },
 {.name = "bandwidth",
- .type = VSH_OT_DATA,
+ .type = VSH_OT_INT,
  .help = N_("bandwidth limit in MiB/s")
 },
 {.name = "base",
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list