Skip to contentSkip to conversation

Only call stat() when adding a disk if we expect a device to exist.

PATCH Superseded David Scott 2 participants 3 messages Apr 23, 2013

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Only call stat() when adding a disk if we expect a device to exist.

We consider calling stat() a helpful error check in the following circumstances only:
1. the disk backend type must be PHYsical
2. the disk backend domain must be the same as the running libxl code (assumed to be 0)
3. there must not be a hotplug script because this would imply that the device won't be created until after the hotplug script has run.

With this fix, it is possible to use qemu's built-in block drivers such as ceph, with a xl config disk spec like this:

disk=[ 'backendtype=qdisk,format=raw,vdev=hda,access=rw,target=rbd:rbd/ubuntu1204.img' ]

---
 tools/libxl/libxl_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/libxl_device.c +1 -1
index eeea9d9..ec0fec2 100644
@@ -236,7 +236,7 @@ int libxl__device_disk_set_backend(libxl__gc *gc, libxl_device_disk *disk) {
             return ERROR_INVAL;
         }
         memset(&a.stab, 0, sizeof(a.stab));
-    } else if (!disk->script) {
+    } else if (disk->backend == LIBXL_DISK_BACKEND_PHY && disk->backend_domid == 0 && !disk->script) {
         if (stat(disk->pdev_path, &a.stab)) {
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Disk vdev=%s "
                              "failed to stat: %s",
Signature · 1 line
1.8.1.2
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · David Scott

We consider calling stat() a helpful error check in the following circumstances only:
1. the disk backend type must be PHYsical
2. the disk backend domain must be the same as the running libxl code (assumed to be 0)

AKA LIBXL_TOOLSTACK_DOMID. That line could also do with wrapping but I can do that as I commit if you like.

Quoted 10 lines

3. there must not be a hotplug script because this would imply that the device won't be created until after the hotplug script has run.

With this fix, it is possible to use qemu's built-in block drivers such as ceph, with a xl config disk spec like this:

disk=[ 'backendtype=qdisk,format=raw,vdev=hda,access=rw,target=rbd:rbd/ubuntu1204.img' ]

With the above changes:

Quoted 17 lines
---
 tools/libxl/libxl_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/libxl_device.c +1 -1
index eeea9d9..ec0fec2 100644
@@ -236,7 +236,7 @@ int libxl__device_disk_set_backend(libxl__gc *gc, libxl_device_disk *disk) {
             return ERROR_INVAL;
         }
         memset(&a.stab, 0, sizeof(a.stab));
-    } else if (!disk->script) {
+    } else if (disk->backend == LIBXL_DISK_BACKEND_PHY && disk->backend_domid == 0 && !disk->script) {
         if (stat(disk->pdev_path, &a.stab)) {
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Disk vdev=%s "
                              "failed to stat: %s",
#2 lore raw
Quoted 8 lines · Ian Campbell
Quoted 5 lines · David Scott
Quoted 5 lines

We consider calling stat() a helpful error check in the following circumstances only:
1. the disk backend type must be PHYsical
2. the disk backend domain must be the same as the running libxl code (assumed to be 0)

AKA LIBXL_TOOLSTACK_DOMID. That line could also do with wrapping but I can do that as I commit if you like.

Ah, I grepped around for stuff like "DOMID_SELF" but missed that one :-)

I'll resend...

Cheers,
Dave