Skip to contentSkip to conversation

libxl: FreeBSD related fixes

PATCH New Roger Pau Monne 3 participants 5 messages Jan 14, 2016 – Jan 15, 2016

lore
Share & tools
lore
#1 lore raw

PATCH v2 1/2 libxl: fix _SC_GETPW_R_SIZE_MAX usage

If sysconf(_SC_GETPW_R_SIZE_MAX) fails for any reason just use an initial buffer size of 2048. This is not a critical failure, and the code that makes use of this buffer is able to expand it later if required.

---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- Use a default buffer size if sysconf(_SC_GETPW_R_SIZE_MAX) fails for any reason, this should not be a critical failure.

---
 tools/libxl/libxl_dm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/libxl/libxl_dm.c +4 -3
index 0aaefd9..a088d71 100644
@@ -730,9 +730,10 @@ static int libxl__dm_runas_helper(libxl__gc *gc, const char *username)
 
     buf_size = sysconf(_SC_GETPW_R_SIZE_MAX);
     if (buf_size < 0) {
-        LOGE(ERROR, "sysconf(_SC_GETPW_R_SIZE_MAX) returned error %ld",
-                buf_size);
-        return ERROR_FAIL;
+        buf_size = 2048;
+        LOG(DEBUG,
+"sysconf(_SC_GETPW_R_SIZE_MAX) failed, setting the initial buffer size to %ld",
+            buf_size);
     }
 
     while (1) {
Signature · 7 lines
1.9.5 (Apple Git-50.3)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] libxl: fix _SC_GETPW_R_SIZE_MAX usage

Quoted 27 lines · Roger Pau Monne

If sysconf(_SC_GETPW_R_SIZE_MAX) fails for any reason just use an initial buffer size of 2048. This is not a critical failure, and the code that makes use of this buffer is able to expand it later if required.

---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- Use a default buffer size if sysconf(_SC_GETPW_R_SIZE_MAX) fails for any reason, this should not be a critical failure.

---
 tools/libxl/libxl_dm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/libxl/libxl_dm.c +0 -0
index 0aaefd9..a088d71 100644
@@ -730,9 +730,10 @@ static int libxl__dm_runas_helper(libxl__gc *gc, const char *username)
 
     buf_size = sysconf(_SC_GETPW_R_SIZE_MAX);
     if (buf_size < 0) {

tools/libxl/libxl_dm.c static int libxl__dm_runas_helper(libxl__gc *gc, const char *username) · line 739

Quoted 10 lines
tools/libxl/libxl_dm.c +4 -3
-        LOGE(ERROR, "sysconf(_SC_GETPW_R_SIZE_MAX) returned error %ld",
-                buf_size);
-        return ERROR_FAIL;
+        buf_size = 2048;
+        LOG(DEBUG,
+"sysconf(_SC_GETPW_R_SIZE_MAX) failed, setting the initial buffer size to %ld",
+            buf_size);
     }
 
     while (1) {

Looks sane to me.

Signature · 1 line
Doug Goldstein

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by on v2 1/2 Applied
#3 lore raw

Re: [PATCH v2 1/2] libxl: fix _SC_GETPW_R_SIZE_MAX usage

In reply to Roger Pau Monne
Quoted 10 lines · Roger Pau Monne

If sysconf(_SC_GETPW_R_SIZE_MAX) fails for any reason just use an initial buffer size of 2048. This is not a critical failure, and the code that makes use of this buffer is able to expand it later if required.

---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>

Well done on your prescience on fixing all my comments on v1 before you'd even seen them!

Applied.

Quoted 21 lines

---
Changes since v1:
 - Use a default buffer size if sysconf(_SC_GETPW_R_SIZE_MAX) fails for any
   reason, this should not be a critical failure.
---
 tools/libxl/libxl_dm.c | 7 ++++---

 1 file changed, 4 insertions(+), 3 deletions(-)
tools/libxl/libxl_dm.c +0 -0
index 0aaefd9..a088d71 100644
@@ -730,9 +730,10 @@ static int libxl__dm_runas_helper(libxl__gc *gc,
 const char *username)


     buf_size = sysconf(_SC_GETPW_R_SIZE_MAX);
     if (buf_size < 0) {
-        LOGE(ERROR, "sysconf(_SC_GETPW_R_SIZE_MAX) returned error %ld", -                buf_size);
-        return ERROR_FAIL;

Quoted 8 lines

+        buf_size = 2048;
+        LOG(DEBUG,
+"sysconf(_SC_GETPW_R_SIZE_MAX) failed, setting the initial buffer size to %ld",
+            buf_size);
     }

     while (1) {

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#4 lore raw

PATCH v2 2/2 libxl: fix UUID usage on FreeBSD

In reply to Roger Pau Monne

libxl makes the assumtion that libxl_uuid == uuid_t, and that uuid_t can be freely used as a byte array. This is not true on FreeBSD (and NetBSD too, not sure about other BSD UUID implementations), where the internals of uuid don't match what libxl expects as a byte array because of endianness issues.

Fix this by converting the libxl_uuid type to a struct with an internal uuid_t field and a byte-array. Also introduce a new function that should be used in order to load a byte array into a uuid_t struct.

---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>

---
 tools/libxl/libxl.c      |  2 +-
 tools/libxl/libxl.h      |  9 +++++++++
 tools/libxl/libxl_uuid.c | 22 +++++++++++++++++++---
 tools/libxl/libxl_uuid.h |  3 ++-
 4 files changed, 31 insertions(+), 5 deletions(-)
tools/libxl/libxl.c +1 -1
index 9207621..ae08b2f 100644
@@ -616,7 +616,7 @@ static void xcinfo2xlinfo(libxl_ctx *ctx,
 {
     size_t size;
 
-    memcpy(&(xlinfo->uuid), xcinfo->handle, sizeof(xen_domain_handle_t));
+    libxl_uuid_from_bytearray(&xlinfo->uuid, xcinfo->handle);
     xlinfo->domid = xcinfo->domain;
     xlinfo->ssidref = xcinfo->ssidref;
     if (libxl_flask_sid_to_context(ctx, xlinfo->ssidref,
tools/libxl/libxl.h +9 -0
index 05606a7..876fca8 100644
@@ -867,6 +867,15 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src);
  */
 #define LIBXL_HAVE_DEVICE_MODEL_VERSION_NONE 1
 
+/*
+ * LIBXL_HAVE_UUID_FROM_BYTEARRAY
+ *
+ * In the case that LIBXL_HAVE_UUID_FROM_BYTEARRAY is set libxl
+ * provides a function (libxl_uuid_from_bytearray) to convert an
+ * octet stream into a UUID.
+ */
+#define LIBXL_HAVE_UUID_FROM_BYTEARRAY 1
+
 typedef char **libxl_string_list;
 void libxl_string_list_dispose(libxl_string_list *sl);
 int libxl_string_list_length(const libxl_string_list *sl);
tools/libxl/libxl_uuid.c +19 -3
index 7d4a032..f566f50 100644
@@ -33,6 +33,12 @@ int libxl_uuid_from_string(libxl_uuid *uuid, const char *in)
      return uuid_parse(in, uuid->uuid);
 }
 
+int libxl_uuid_from_bytearray(libxl_uuid *uuid, const uint8_t *raw)
+{
+    memcpy(uuid, raw, sizeof(*uuid));
+    return 0;
+}
+
 void libxl_uuid_copy(libxl_ctx *ctx_opt, libxl_uuid *dst,
                      const libxl_uuid *src)
 {
@@ -72,9 +78,9 @@ void libxl_uuid_generate(libxl_uuid *uuid)
 {
     uint32_t status;
 
-    BUILD_BUG_ON(sizeof(libxl_uuid) != sizeof(uuid_t));
     uuid_create(&uuid->uuid, &status);
     assert(status == uuid_s_ok);
+    uuid_enc_be(uuid->uuid_raw, &uuid->uuid);
 }
 
 #ifdef __FreeBSD__
@@ -85,6 +91,8 @@ int libxl_uuid_from_string(libxl_uuid *uuid, const char *in)
     uuid_from_string(in, &uuid->uuid, &status);
     if (status != uuid_s_ok)
         return -1;
+    uuid_enc_be(uuid->uuid_raw, &uuid->uuid);
+
     return 0;
 }
 #else
@@ -101,15 +109,23 @@ int libxl_uuid_from_string(libxl_uuid *uuid, const char *in)
 #undef LIBXL__UUID_PTRS
 #endif
 
+int libxl_uuid_from_bytearray(libxl_uuid *uuid, const uint8_t *raw)
+{
+    uuid_dec_le(raw, &uuid->uuid);
+    uuid_enc_be(uuid->uuid_raw, &uuid->uuid);
+
+    return 0;
+}
+
 void libxl_uuid_copy(libxl_ctx *ctx_opt, libxl_uuid *dst,
                      const libxl_uuid *src)
 {
-    memcpy(&dst->uuid, &src->uuid, sizeof(dst->uuid));
+    memcpy(dst, src, sizeof(*dst));
 }
 
 void libxl_uuid_clear(libxl_uuid *uuid)
 {
-    memset(&uuid->uuid, 0, sizeof(uuid->uuid));
+    memset(uuid, 0, sizeof(*uuid));
 }
 
 #ifdef __FreeBSD__
tools/libxl/libxl_uuid.h +2 -1
index c5041c7..d84e3d1 100644
@@ -42,7 +42,7 @@ typedef struct {
 #include <stdio.h>
 #include <assert.h>
 
-typedef union {
+typedef struct {
     uuid_t uuid;
     uint8_t uuid_raw[16];
 } libxl_uuid;
@@ -73,6 +73,7 @@ void libxl_uuid_clear(libxl_uuid *uuid);
 int libxl_uuid_compare(const libxl_uuid *uuid1, const libxl_uuid *uuid2);
 const uint8_t *libxl_uuid_bytearray_const(const libxl_uuid *uuid);
 uint8_t *libxl_uuid_bytearray(libxl_uuid *uuid);
+int libxl_uuid_from_bytearray(libxl_uuid *uuid, const uint8_t *raw);
 
 #endif /* __LIBXL_UUID_H__ */
 
Signature · 7 lines
1.9.5 (Apple Git-50.3)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel