Skip to contentSkip to conversation

: libxenlight, checks before device deletion and addition

PATCH In review Andres Lagar-Cavilla 2 participants 3 messages Nov 30, 2009 – Dec 1, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 14/14 : libxenlight, checks before device deletion and addition

Proper existential checks before adding or deleting a device, i.e. return error if:

- Adding a device to a non-existent domain
- Adding a device twice
- Deleting a non-existent device
- Deleting a device from a non-existent domain

# HG changeset patch
# User Andres Lagar-Cavilla <[email protected]> # Date 1259606866 18000
# Node ID 7a2b9d53941757142b408d09020099990b725467 # Parent bf82205e60f45e98ab637c68d5c305dcb3e167cd Proper existential checks before adding or deleting a device, i.e. return error if:

- Adding a device to a non-existent domain
- Adding a device twice
- Deleting a non-existent device
- Deleting a device from a non-existent domain

libxl.c +11 -7
diff -r bf82205e60f4 -r 7a2b9d539417 libxl.c
@@ -1008,6 +1008,7 @@ int libxl_device_disk_add(struct libxl_c
     int devid;
     libxl_device device;
     int major, minor;
+    int rc;
 
     front = flexarray_make(16, 1);
     if (!front)
@@ -1126,12 +1127,12 @@ int libxl_device_disk_add(struct libxl_c
         flexarray_set(front, foffset++, "x86_32-abi"); /* hardcoded ! */
     }
 
-    libxl_device_generic_add(ctx, &device,
+    rc = libxl_device_generic_add(ctx, &device,
                              libxl_xs_kvs_of_flexarray(ctx, back, boffset),
                              libxl_xs_kvs_of_flexarray(ctx, front, foffset));
     flexarray_free(back);
     flexarray_free(front);
-    return 0;
+    return rc;
 }
 
 int libxl_device_disk_del(struct libxl_ctx *ctx, 
@@ -1169,6 +1170,7 @@ int libxl_device_nic_add(struct libxl_ct
     unsigned int boffset = 0;
     unsigned int foffset = 0;
     libxl_device device;
+    int rc;
 
     front = flexarray_make(16, 1);
     if (!front)
@@ -1214,14 +1216,14 @@ int libxl_device_nic_add(struct libxl_ct
         flexarray_set(front, foffset++, "x86_32-abi"); /* hardcoded ! */
     }
 
-    libxl_device_generic_add(ctx, &device,
+    rc = libxl_device_generic_add(ctx, &device,
                              libxl_xs_kvs_of_flexarray(ctx, back, boffset),
                              libxl_xs_kvs_of_flexarray(ctx, front, foffset));
 
     /* FIXME: wait for plug */
     flexarray_free(back);
     flexarray_free(front);
-    return 0;
+    return rc;
 }
 
 int libxl_device_nic_del(struct libxl_ctx *ctx, 
@@ -1257,6 +1259,7 @@ int libxl_device_console_add(struct libx
     unsigned int boffset = 0;
     unsigned int foffset = 0;
     libxl_device device;
+    int rc;
 
     if (console->build_state) {
         xs_transaction_t t;
@@ -1319,13 +1322,13 @@ retry_transaction:
     else
         flexarray_set(front, foffset++, "ioemu");
 
-    libxl_device_generic_add(ctx, &device,
+    rc = libxl_device_generic_add(ctx, &device,
                              libxl_xs_kvs_of_flexarray(ctx, back, boffset),
                              libxl_xs_kvs_of_flexarray(ctx, front, foffset));
     flexarray_free(back);
     flexarray_free(front);
 
-    return 0;
+    return rc;
 }
 
 /******************************************************************************/
@@ -1336,6 +1339,7 @@ int libxl_device_vkb_add(struct libxl_ct
     unsigned int boffset = 0;
     unsigned int foffset = 0;
     libxl_device device;
+    int rc;
 
     front = flexarray_make(16, 1);
     if (!front)
@@ -1371,7 +1375,7 @@ int libxl_device_vkb_add(struct libxl_ct
     flexarray_free(back);
     flexarray_free(front);
 
-    return 0;
+    return rc;
 }
 
 int libxl_device_vkb_clean_shutdown(struct libxl_ctx *ctx, uint32_t domid)
libxl_device.c +43 -3

70 lines not on this page · raw message

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

#1 lore raw
Quoted 9 lines · Andres Lagar-Cavilla

Proper existential checks before adding or deleting a device, i.e. return error if:

- Adding a device to a non-existent domain
- Adding a device twice
- Deleting a non-existent device
- Deleting a device from a non-existent domain

you should not check the non-existency of a domain. this is pointless since just after you check the domain might have gone away. also you might think of a mode where you populate the xenstore tree before creating the domain .. nobody does that, but I don't think there's any major stopper to do that or that it would be a bad idea either.

Same reason that should it not check for device existency outside of the transaction, otherwise someome might have added it in the meantime.

PS: please don't call libxl_free, that's really unnecessary at this stage, until we sort memory handling completly. (there's a "GC" for now)

Signature · 1 line
Vincent
#2 lore raw

Agreed in that it is a weak check being non-transactional. But some check should be there, shouldn't it? Just throwing it out there. The other checks are kosher I assume? Andres

Quoted 27 lines · Vincent Hanquez
Quoted 10 lines · Andres Lagar-Cavilla

Proper existential checks before adding or deleting a device, i.e. return error if:

- Adding a device to a non-existent domain
- Adding a device twice
- Deleting a non-existent device
- Deleting a device from a non-existent domain

you should not check the non-existency of a domain. this is pointless since just after you check the domain might have gone away. also you might think of a mode where you populate the xenstore tree before creating the domain .. nobody does that, but I don't think there's any major stopper to do that or that it would be a bad idea either.

Same reason that should it not check for device existency outside of the transaction, otherwise someome might have added it in the meantime.

PS: please don't call libxl_free, that's really unnecessary at this stage, until we sort memory handling completly. (there's a "GC" for now)