[05/30] storagefile: Check version to determine if qcow2 or not

Message ID 79f92e315686e90a7247bb40ef5dc2e50d5d3977.1570482718.git.crobinso@redhat.com
State Accepted
Commit 253f2cae4a3e42ec67d9ae6347cc5bafcf71a064
Headers show
Series
  • storagefile, security: qcow2 data_file support
Related show

Commit Message

Cole Robinson Oct. 7, 2019, 9:49 p.m.
Rather than require a boolean to be passed in

Signed-off-by: Cole Robinson <crobinso@redhat.com>

---
 src/util/virstoragefile.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

-- 
2.23.0

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

Comments

Daniel Henrique Barboza Oct. 9, 2019, 8:50 p.m. | #1
On 10/7/19 6:49 PM, Cole Robinson wrote:
> Rather than require a boolean to be passed in

>

> Signed-off-by: Cole Robinson <crobinso@redhat.com>

> ---


I was about to say 'why didn't you remove the isQCow2 boolean and
change the 2 callers of the function ' but then I saw that the next 2
patches does further code simplification here.


Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>





>   src/util/virstoragefile.c | 11 ++++++-----

>   1 file changed, 6 insertions(+), 5 deletions(-)

>

> diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c

> index 905e70b1a9..9bf4c1178b 100644

> --- a/src/util/virstoragefile.c

> +++ b/src/util/virstoragefile.c

> @@ -486,7 +486,7 @@ qcowXGetBackingStore(char **res,

>                        int *format,

>                        const char *buf,

>                        size_t buf_size,

> -                     bool isQCow2)

> +                     bool isQCow2 ATTRIBUTE_UNUSED)

>   {

>       unsigned long long offset;

>       unsigned int size;

> @@ -548,8 +548,11 @@ qcowXGetBackingStore(char **res,

>        * for qcow2 v3 images, the length of the header

>        * is stored at QCOW2v3_HDR_SIZE

>        */

> -    if (isQCow2) {

> -        version = virReadBufInt32BE(buf + QCOWX_HDR_VERSION);

> +

> +    version = virReadBufInt32BE(buf + QCOWX_HDR_VERSION);

> +    if (version >= 2) {

> +        /* QCow1 doesn't have the extensions capability

> +         * used to store backing format */

>           if (version == 2)

>               start = QCOW2_HDR_TOTAL_SIZE;

>           else

> @@ -569,8 +572,6 @@ qcow1GetBackingStore(char **res,

>                        const char *buf,

>                        size_t buf_size)

>   {

> -    /* QCow1 doesn't have the extensions capability

> -     * used to store backing format */

>       return qcowXGetBackingStore(res, format, buf, buf_size, false);

>   }

>   


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

Patch

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 905e70b1a9..9bf4c1178b 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -486,7 +486,7 @@  qcowXGetBackingStore(char **res,
                      int *format,
                      const char *buf,
                      size_t buf_size,
-                     bool isQCow2)
+                     bool isQCow2 ATTRIBUTE_UNUSED)
 {
     unsigned long long offset;
     unsigned int size;
@@ -548,8 +548,11 @@  qcowXGetBackingStore(char **res,
      * for qcow2 v3 images, the length of the header
      * is stored at QCOW2v3_HDR_SIZE
      */
-    if (isQCow2) {
-        version = virReadBufInt32BE(buf + QCOWX_HDR_VERSION);
+
+    version = virReadBufInt32BE(buf + QCOWX_HDR_VERSION);
+    if (version >= 2) {
+        /* QCow1 doesn't have the extensions capability
+         * used to store backing format */
         if (version == 2)
             start = QCOW2_HDR_TOTAL_SIZE;
         else
@@ -569,8 +572,6 @@  qcow1GetBackingStore(char **res,
                      const char *buf,
                      size_t buf_size)
 {
-    /* QCow1 doesn't have the extensions capability
-     * used to store backing format */
     return qcowXGetBackingStore(res, format, buf, buf_size, false);
 }