[PATCH] resize: slightly alter signature

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Our existing virDomainBlockResize takes an unsigned long long
argument; if that command is later taught a DELTA and SHRINK flag,
we cannot change its type without breaking API (but at least such
a change would be ABI compatible).  Meanwhile, the only time a
negative size makes sense is if both DELTA and SHRINK are used
together, but if we keep the argument unsigned, applications can
pass the positive delta amount by which they would like to shrink
the system, and have the flags imply the negative value.  So,
since this API has not yet been released, and in the interest of
consistency with existing API, we swap virStorageVolResize to
always pass an unsigned value.

* include/libvirt/libvirt.h.in (virStorageVolResize): Use unsigned
argument.
* src/libvirt.c (virStorageVolResize): Likewise.
* src/driver.h (virDrvStorageVolUpload): Adjust clients.
* src/remote/remote_protocol.x (remote_storage_vol_resize_args):
Likewise.
* src/remote_protocol-structs: Regenerate.
Suggested by Daniel P. Berrange.
---
 include/libvirt/libvirt.h.in |    2 +-
 src/driver.h                 |    2 +-
 src/libvirt.c                |   17 +++++++++--------
 src/remote/remote_protocol.x |    2 +-
 src/remote_protocol-structs  |    2 +-
 5 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 0a7b324..d9b9b95 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2415,7 +2415,7 @@ typedef enum {
 } virStorageVolResizeFlags;

 int                     virStorageVolResize             (virStorageVolPtr vol,
-                                                         long long capacity,
+                                                         unsigned long long capacity,
                                                          unsigned int flags);


diff --git a/src/driver.h b/src/driver.h
index ba7dbc4..2e2042e 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1277,7 +1277,7 @@ typedef int
                                unsigned int flags);
 typedef int
         (*virDrvStorageVolResize) (virStorageVolPtr vol,
-                                   long long capacity,
+                                   unsigned long long capacity,
                                    unsigned int flags);

 typedef int
diff --git a/src/libvirt.c b/src/libvirt.c
index e702a34..c609202 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -13014,16 +13014,20 @@ error:
  * Normally, this operation should only be used to enlarge capacity;
  * but if @flags contains VIR_STORAGE_RESIZE_SHRINK, it is possible to
  * attempt a reduction in capacity even though it might cause data loss.
+ * If VIR_STORAGE_RESIZE_DELTA is also present, then @capacity is
+ * subtracted from the current size; without it, @capacity represents
+ * the absolute new size regardless of whether it is larger or smaller
+ * than the current size.
  *
  * Returns 0 on success, or -1 on error.
  */
 int
 virStorageVolResize(virStorageVolPtr vol,
-                    long long capacity,
+                    unsigned long long capacity,
                     unsigned int flags)
 {
     virConnectPtr conn;
-    VIR_DEBUG("vol=%p capacity=%lld flags=%x", vol, capacity, flags);
+    VIR_DEBUG("vol=%p capacity=%llu flags=%x", vol, capacity, flags);

     virResetLastError();

@@ -13040,12 +13044,9 @@ virStorageVolResize(virStorageVolPtr vol,
        goto error;
     }

-    /* Negative capacity is valid only with both delta and shrink;
-     * zero capacity is valid with either delta or shrink.  */
-    if ((capacity < 0 && !(flags & VIR_STORAGE_VOL_RESIZE_DELTA) &&
-         !(flags & VIR_STORAGE_VOL_RESIZE_SHRINK)) ||
-        (capacity == 0 && !((flags & VIR_STORAGE_VOL_RESIZE_DELTA) ||
-                            (flags & VIR_STORAGE_VOL_RESIZE_SHRINK)))) {
+    /* Zero capacity is only valid with either delta or shrink.  */
+    if (capacity == 0 && !((flags & VIR_STORAGE_VOL_RESIZE_DELTA) ||
+                           (flags & VIR_STORAGE_VOL_RESIZE_SHRINK))) {
         virLibStorageVolError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         goto error;
     }
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index b58925a..b2c8426 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -1709,7 +1709,7 @@ struct remote_storage_vol_get_path_ret {

 struct remote_storage_vol_resize_args {
     remote_nonnull_storage_vol vol;
-    hyper capacity;
+    unsigned hyper capacity;
     unsigned int flags;
 };

diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 5eac9bf..e9137a9 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -1282,7 +1282,7 @@ struct remote_storage_vol_get_path_ret {
 };
 struct remote_storage_vol_resize_args {
         remote_nonnull_storage_vol vol;
-        int64_t                    capacity;
+        uint64_t                   capacity;
         u_int                      flags;
 };
 struct remote_node_num_of_devices_args {
-- 
1.7.7.6

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


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]