Skip to contentSkip to conversation

tools: some fixes for the hypervisor file system

PATCH In review Juergen Gross 3 participants 5 messages Jun 2, 2020

lore
Share & tools
lore
#0 lore raw

cover tools: some fixes for the hypervisor file system

Juergen Gross (2):
tools: check return value of asprintf() in xenhypfs
tools: make libxenhypfs interface more future proof

 tools/libs/hypfs/core.c             |  2 +-
 tools/libs/hypfs/include/xenhypfs.h | 31 +++++++++++++++++------------
 tools/misc/xenhypfs.c               | 10 ++++++++--
 3 files changed, 27 insertions(+), 16 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/2 tools: check return value of asprintf() in xenhypfs

asprintf() can fail, so check its return value. Additionally fix a memory leak in xenhypfs.

---
 tools/misc/xenhypfs.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/misc/xenhypfs.c +6 -1
index 158b901f42..5145b8969f 100644
@@ -148,9 +148,14 @@ static int xenhypfs_tree_sub(char *path, unsigned int depth)
         printf("%*s%s%s\n", depth * 2, "", ent[i].name,
                ent[i].type == xenhypfs_type_dir ? "/" : "");
         if (ent[i].type == xenhypfs_type_dir) {
-            asprintf(&p, "%s%s%s", path, (depth == 1) ? "" : "/", ent[i].name);
+            if (asprintf(&p, "%s%s%s", path, (depth == 1) ? "" : "/",
+                         ent[i].name) < 0) {
+                ret = 2;
+                break;
+            }
             if (xenhypfs_tree_sub(p, depth + 1))
                 ret = 2;
+            free(p);
         }
     }
 
Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/2 tools: make libxenhypfs interface more future proof

In reply to Juergen Gross

As compilers are free to choose the width of an enum they should be avoided in stable interfaces when declaring a variable. So the struct xenhypfs_dirent definition should be modified to have explicitly sized members for type and encoding and the related enums should be defined separately.

Additionally it is better to have a larger flags member in that struct with the "writable" indicator occupying only a single bit. This will make future additions easier.

---
 tools/libs/hypfs/core.c             |  2 +-
 tools/libs/hypfs/include/xenhypfs.h | 31 +++++++++++++++++------------
 tools/misc/xenhypfs.c               |  3 ++-
 3 files changed, 21 insertions(+), 15 deletions(-)
tools/libs/hypfs/core.c +1 -1
index d4309b5ae2..c91e165705 100644
@@ -204,7 +204,7 @@ static void xenhypfs_set_attrs(struct xen_hypfs_direntry *entry,
         dirent->type = xenhypfs_type_blob;
     }
 
-    dirent->is_writable = entry->max_write_len;
+    dirent->flags = entry->max_write_len ? XENHYPFS_FLAG_WRITABLE : 0;
 }
 
 void *xenhypfs_read_raw(xenhypfs_handle *fshdl, const char *path,
tools/libs/hypfs/include/xenhypfs.h +18 -13
index ab157edceb..25432d2a16 100644
@@ -26,22 +26,27 @@ struct xentoollog_logger;
 
 typedef struct xenhypfs_handle xenhypfs_handle;
 
+enum xenhypfs_type {
+    xenhypfs_type_dir,
+    xenhypfs_type_blob,
+    xenhypfs_type_string,
+    xenhypfs_type_uint,
+    xenhypfs_type_int,
+    xenhypfs_type_bool,
+};
+
+enum xenhypfs_encoding {
+    xenhypfs_enc_plain,
+    xenhypfs_enc_gzip
+};
+
 struct xenhypfs_dirent {
     char *name;
     size_t size;
-    enum {
-        xenhypfs_type_dir,
-        xenhypfs_type_blob,
-        xenhypfs_type_string,
-        xenhypfs_type_uint,
-        xenhypfs_type_int,
-        xenhypfs_type_bool
-    } type;
-    enum {
-        xenhypfs_enc_plain,
-        xenhypfs_enc_gzip
-    } encoding;
-    bool is_writable;
+    unsigned short type;
+    unsigned short encoding;
+    unsigned int flags;
+#define XENHYPFS_FLAG_WRITABLE  0x00000001
 };
 
 xenhypfs_handle *xenhypfs_open(struct xentoollog_logger *logger,
tools/misc/xenhypfs.c +2 -1
index 5145b8969f..5da24aed90 100644
@@ -125,7 +125,8 @@ static int xenhypfs_ls(char *path)
     } else {
         for (i = 0; i < n; i++)
             printf("%s r%c %s\n", xenhypfs_type(ent + i),
-                   ent[i].is_writable ? 'w' : '-', ent[i].name);
+                   (ent[i].flags & XENHYPFS_FLAG_WRITABLE) ? 'w' : '-',
+                   ent[i].name);
 
         free(ent);
     }
Signature · 1 line
2.26.2
#3 lore raw
In reply to Juergen Gross
Quoted 7 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Juergen Gross
Sent: 02 June 2020 07:00
To: [email protected]
Cc: Juergen Gross <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>
Subject: [PATCH-for-4.14 0/2] tools: some fixes for the hypervisor file system

Quoted 8 lines

Juergen Gross (2):
tools: check return value of asprintf() in xenhypfs
tools: make libxenhypfs interface more future proof

 tools/libs/hypfs/core.c             |  2 +-
 tools/libs/hypfs/include/xenhypfs.h | 31 +++++++++++++++++------------
 tools/misc/xenhypfs.c               | 10 ++++++++--
 3 files changed, 27 insertions(+), 16 deletions(-)
Quoted 4 lines

--
2.26.2

Acked-by on the v1 series
#4 lore raw
In reply to Juergen Gross
Quoted 7 lines · Juergen Gross

Juergen Gross (2):
tools: check return value of asprintf() in xenhypfs
tools: make libxenhypfs interface more future proof

 tools/libs/hypfs/core.c             |  2 +-
 tools/libs/hypfs/include/xenhypfs.h | 31 +++++++++++++++++------------
 tools/misc/xenhypfs.c               | 10 ++++++++--

Good improvements.

Quoted 5 lines
 3 files changed, 27 insertions(+), 16 deletions(-)
Signature · 1 line
2.26.2