[14/30] storagefile: Parse qcow2 external data file

Message ID ffae0f056cb695c77476bbd81be71bb1c9d29776.1570482718.git.crobinso@redhat.com
State New
Headers show
Series
  • storagefile, security: qcow2 data_file support
Related show

Commit Message

Cole Robinson Oct. 7, 2019, 9:49 p.m.
This is tracked as a qcow2 extension, like backing store format

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

---
 src/util/virstoragefile.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 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, 9:47 p.m. | #1
On 10/7/19 6:49 PM, Cole Robinson wrote:
> This is tracked as a qcow2 extension, like backing store format

>

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

> ---


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



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

>   1 file changed, 20 insertions(+), 2 deletions(-)

>

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

> index 621cc56e87..7e32d7619e 100644

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

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

> @@ -202,6 +202,7 @@ qedGetBackingStore(char **, int *, const char *, size_t);

>   

>   #define QCOW2_HDR_EXTENSION_END 0

>   #define QCOW2_HDR_EXTENSION_BACKING_FORMAT 0xE2792ACA

> +#define QCOW2_HDR_EXTENSION_DATA_FILE 0x44415441

>   

>   #define QCOW2v3_HDR_FEATURES_INCOMPATIBLE (QCOW2_HDR_TOTAL_SIZE)

>   #define QCOW2v3_HDR_FEATURES_COMPATIBLE (QCOW2v3_HDR_FEATURES_INCOMPATIBLE+8)

> @@ -429,7 +430,8 @@ cowGetBackingStore(char **res,

>   static int

>   qcow2GetExtensions(const char *buf,

>                      size_t buf_size,

> -                   int *backingFormat)

> +                   int *backingFormat,

> +                   char **externalDataStoreRaw)

>   {

>       size_t offset;

>       size_t extension_start;

> @@ -508,6 +510,9 @@ qcow2GetExtensions(const char *buf,

>   

>           case QCOW2_HDR_EXTENSION_BACKING_FORMAT: {

>               VIR_AUTOFREE(char *) tmp = NULL;

> +            if (!backingFormat)

> +                break;

> +

>               if (VIR_ALLOC_N(tmp, len + 1) < 0)

>                   return -1;

>               memcpy(tmp, buf + offset, len);

> @@ -516,6 +521,19 @@ qcow2GetExtensions(const char *buf,

>               *backingFormat = virStorageFileFormatTypeFromString(tmp);

>               if (*backingFormat <= VIR_STORAGE_FILE_NONE)

>                   return -1;

> +            break;

> +        }

> +

> +        case QCOW2_HDR_EXTENSION_DATA_FILE: {

> +            if (!externalDataStoreRaw)

> +                break;

> +

> +            if (VIR_ALLOC_N(*externalDataStoreRaw, len + 1) < 0)

> +                return -1;

> +            memcpy(*externalDataStoreRaw, buf + offset, len);

> +            (*externalDataStoreRaw)[len] = '\0';

> +            VIR_DEBUG("parsed externalDataStoreRaw='%s'", *externalDataStoreRaw);

> +            break;

>           }

>           }

>   

> @@ -566,7 +584,7 @@ qcowXGetBackingStore(char **res,

>       memcpy(*res, buf + offset, size);

>       (*res)[size] = '\0';

>   

> -    if (qcow2GetExtensions(buf, buf_size, format) < 0)

> +    if (qcow2GetExtensions(buf, buf_size, format, NULL) < 0)

>           return BACKING_STORE_INVALID;

>   

>       return BACKING_STORE_OK;


--
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 621cc56e87..7e32d7619e 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -202,6 +202,7 @@  qedGetBackingStore(char **, int *, const char *, size_t);
 
 #define QCOW2_HDR_EXTENSION_END 0
 #define QCOW2_HDR_EXTENSION_BACKING_FORMAT 0xE2792ACA
+#define QCOW2_HDR_EXTENSION_DATA_FILE 0x44415441
 
 #define QCOW2v3_HDR_FEATURES_INCOMPATIBLE (QCOW2_HDR_TOTAL_SIZE)
 #define QCOW2v3_HDR_FEATURES_COMPATIBLE (QCOW2v3_HDR_FEATURES_INCOMPATIBLE+8)
@@ -429,7 +430,8 @@  cowGetBackingStore(char **res,
 static int
 qcow2GetExtensions(const char *buf,
                    size_t buf_size,
-                   int *backingFormat)
+                   int *backingFormat,
+                   char **externalDataStoreRaw)
 {
     size_t offset;
     size_t extension_start;
@@ -508,6 +510,9 @@  qcow2GetExtensions(const char *buf,
 
         case QCOW2_HDR_EXTENSION_BACKING_FORMAT: {
             VIR_AUTOFREE(char *) tmp = NULL;
+            if (!backingFormat)
+                break;
+
             if (VIR_ALLOC_N(tmp, len + 1) < 0)
                 return -1;
             memcpy(tmp, buf + offset, len);
@@ -516,6 +521,19 @@  qcow2GetExtensions(const char *buf,
             *backingFormat = virStorageFileFormatTypeFromString(tmp);
             if (*backingFormat <= VIR_STORAGE_FILE_NONE)
                 return -1;
+            break;
+        }
+
+        case QCOW2_HDR_EXTENSION_DATA_FILE: {
+            if (!externalDataStoreRaw)
+                break;
+
+            if (VIR_ALLOC_N(*externalDataStoreRaw, len + 1) < 0)
+                return -1;
+            memcpy(*externalDataStoreRaw, buf + offset, len);
+            (*externalDataStoreRaw)[len] = '\0';
+            VIR_DEBUG("parsed externalDataStoreRaw='%s'", *externalDataStoreRaw);
+            break;
         }
         }
 
@@ -566,7 +584,7 @@  qcowXGetBackingStore(char **res,
     memcpy(*res, buf + offset, size);
     (*res)[size] = '\0';
 
-    if (qcow2GetExtensions(buf, buf_size, format) < 0)
+    if (qcow2GetExtensions(buf, buf_size, format, NULL) < 0)
         return BACKING_STORE_INVALID;
 
     return BACKING_STORE_OK;