Re: [libvirt] [PATCH 3/3] virsh: make negative values with vol-resize more convenient

2015-05-27 Thread John Ferlan


On 05/27/2015 11:08 AM, Ján Tomko wrote:
> When shrinking a volume by a certain size, instead of typing
>   vol-resize volume 1G --delta --shrink
> we allow the convience of specifying a negative value:
>   vol-resize volume -1G --delta --shrink
> getting the same results with one more character.
> 
> A negative value only makes sense as a delta. Imply the
> --delta parameter if the value is negative.
> 
> Still require --shrink, because the operation is potentially
> destructive.
> ---
>  tools/virsh-volume.c | 15 ---
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 

Should virsh.pod be updated as well to indicate that --shrink with
negative number implies --delta (not required, but the text in virsh.pod
around this is lacking...


ACK (seemingly safe too)

John

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


[libvirt] [PATCH 3/3] virsh: make negative values with vol-resize more convenient

2015-05-27 Thread Ján Tomko
When shrinking a volume by a certain size, instead of typing
  vol-resize volume 1G --delta --shrink
we allow the convience of specifying a negative value:
  vol-resize volume -1G --delta --shrink
getting the same results with one more character.

A negative value only makes sense as a delta. Imply the
--delta parameter if the value is negative.

Still require --shrink, because the operation is potentially
destructive.
---
 tools/virsh-volume.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
index 5d6cc6a..989ce87 100644
--- a/tools/virsh-volume.c
+++ b/tools/virsh-volume.c
@@ -1124,14 +1124,10 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
 unsigned long long capacity = 0;
 unsigned int flags = 0;
 bool ret = false;
-bool delta = false;
+bool delta = vshCommandOptBool(cmd, "delta");
 
 if (vshCommandOptBool(cmd, "allocate"))
 flags |= VIR_STORAGE_VOL_RESIZE_ALLOCATE;
-if (vshCommandOptBool(cmd, "delta")) {
-delta = true;
-flags |= VIR_STORAGE_VOL_RESIZE_DELTA;
-}
 if (vshCommandOptBool(cmd, "shrink"))
 flags |= VIR_STORAGE_VOL_RESIZE_SHRINK;
 
@@ -1144,14 +1140,19 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
 if (*capacityStr == '-') {
 /* The API always requires a positive value; but we allow a
  * negative value for convenience.  */
-if (delta && vshCommandOptBool(cmd, "shrink")) {
+if (vshCommandOptBool(cmd, "shrink")) {
 capacityStr++;
+delta = true;
 } else {
 vshError(ctl, "%s",
- _("negative size requires --delta and --shrink"));
+ _("negative size requires --shrink"));
 goto cleanup;
 }
 }
+
+if (delta)
+flags |= VIR_STORAGE_VOL_RESIZE_DELTA;
+
 if (vshVolSize(capacityStr, &capacity) < 0) {
 vshError(ctl, _("Malformed size %s"), capacityStr);
 goto cleanup;
-- 
2.3.6

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