Skip to contentSkip to conversation

libxl: added libxl compatibility with physical backend file for NetBSD

PATCH In review Roger Pau Monne 3 participants 5 messages Jul 22, 2011 – Jul 29, 2011

lore
Share & tools
lore
#1 lore raw
In reply to Roger Pau Monne

tools/libxl/libxl_device.c int libxl__devices_destroy(libxl__gc *gc · line 469

Quoted 11 lines · Roger Pau Monne
tools/libxl/libxl_device.c +4 -0
@@ -455,6 +460,10 @@ int libxl__devices_destroy(libxl__gc *gc
             fe_path = libxl__sprintf(gc, "/local/domain/%d/device/%s/%s", domid, l1[i], l2[j]);
             be_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/backend", fe_path));
             if (be_path != NULL) {
+#ifdef DONT_REMOVE_VBD_FROM_STORE
+                if (!strcmp(l1[i], "vbd"))
+                    continue;
+#endif
                 if (libxl__device_destroy(gc, be_path, force) > 0)
                     n_watches++;
             } else { 

Most of this patch looks good but I'm still not convinced by this bit.

It misses the libxl_device_disk_del case which goes via libxl__device_destroy path not libxl__devices_destroy, as well as (maybe?) breaking the forced-destroy case (where the toolstack is responsible for actually nuking everything without exceptions) but really it's just that this special casing doesn't really pass the sniff test and makes me suspect it is just papering over a more fundamental issue somewhere else.

The Linux hotplug scripts also consults and then removes the backend dir and it doesn't seem to cause visible issues, so what is it about xenbackendd and/or the NetBSD scripts which doesn't like libxl's behaviour I wonder? If there's a race there then perhaps Linux also has the issue but in a benign form -- in which case it should be worth putting a generic fix in instead of special casing NetBSD. If this really is correct NetBSD specific behaviour then I think it needs a lot more rationale in the changelog etc.

The libxl device teardown stuff is pretty convoluted and I'm reasonably sure it is wrong in several respects, I've been meaning to untangle it, perhaps I should get to that sooner rather than later and maybe fix this issue as a side effect.

Ian.

#2 lore raw

2011/7/22 Ian Campbell <[email protected]>:

Quoted 23 lines · Roger Pau Monne

tools/libxl/libxl_device.c int libxl__devices_destroy(libxl__gc *gc · line 469

Quoted 11 lines
tools/libxl/libxl_device.c +4 -0
@@ -455,6 +460,10 @@ int libxl__devices_destroy(libxl__gc *gc
              fe_path = libxl__sprintf(gc, "/local/domain/%d/device/%s/%s", domid, l1[i], l2[j]);
              be_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/backend", fe_path));
              if (be_path != NULL) {
+#ifdef DONT_REMOVE_VBD_FROM_STORE
+                if (!strcmp(l1[i], "vbd"))
+                    continue;
+#endif
                  if (libxl__device_destroy(gc, be_path, force) > 0)
                      n_watches++;
              } else {

Most of this patch looks good but I'm still not convinced by this bit.

It misses the libxl_device_disk_del case which goes via libxl__device_destroy path not libxl__devices_destroy, as well as (maybe?) breaking the forced-destroy case (where the toolstack is responsible for actually nuking everything without exceptions) but really it's just that this special casing doesn't really pass the sniff test and makes me suspect it is just papering over a more fundamental issue somewhere else.

Quoted 8 lines

The Linux hotplug scripts also consults and then removes the backend dir and it doesn't seem to cause visible issues, so what is it about xenbackendd and/or the NetBSD scripts which doesn't like libxl's behaviour I wonder? If there's a race there then perhaps Linux also has the issue but in a benign form -- in which case it should be worth putting a generic fix in instead of special casing NetBSD. If this really is correct NetBSD specific behaviour then I think it needs a lot more rationale in the changelog etc.

I don't like doing it this way either. How are Linux hotplug scripts called? I've been looking arround, and there seems to be a set of udev rules that call the scripts based on changes regarding devfs, the problem is that NetBSD doesn't have devfs, and we have to watch the xenstore for changes in the status of the devices to trigger the correct scripts. I also see that Linux hotplug scripts also remove entries from xenstore after detaching (xen-hotplug-cleanup), isn't it wrong if the entries are deleted in libxl?

The basic problem with this (if I got it right) is synchronization, entries should be deleted after the corresponding hotplug scripts are done. This happens sometimes in NetBSD, but it is not guaranted, since there's no rendezvous point to tell libxl that all is fine and xenstore can be cleaned. I think it would be good to set some kind of indication, that hotplug scripts have finished execution before libxl deletes the entries in xenstore, and possibly set a timeout, so libxl is not waiting forever if something goes wrong.

Also with xend hotplug scripts where in charge of removing entries from xenstore, but in libxl Linux has no support for block-hotplug using the loop device (only 'phy' which doesn't involve any read from xenstore to unplug), that's why I think this problem has not appeared before.

Quoted 6 lines

The libxl device teardown stuff is pretty convoluted and I'm reasonably sure it is wrong in several respects, I've been meaning to untangle it, perhaps I should get to that sooner rather than later and maybe fix this issue as a side effect.

That would be great, I would like to give a hand if I can.

Quoted 3 lines

Ian.

Regards, Roger.

#0 lore raw

PATCH 1/1 libxl: added libxl compatibility with physical backend file for NetBSD

# HG changeset patch
# User royger
# Date 1311355770 -7200
# Node ID c3d4cad0fc2d34c8346c8a1c4d493a429939249d
# Parent bb2568713604f2eef45326c271132b06a0bff1cc
libxl: added libxl compatibility with physical backend file for NetBSD

This patch allows running PV machines on NetBSD using the libxenlight toolstack.
Added option for PHY backend to handle regular files and disable auto-remove of vbd xenstore entries. Updated xenbackend to detect if vbd is a regular file or a block partition and pass the correct parameter to 'block' script.

tools/hotplug/NetBSD/block +1 -1
diff -r bb2568713604 -r c3d4cad0fc2d tools/hotplug/NetBSD/block
@@ -19,7 +19,7 @@ error() {
 
 xpath=$1
 xstatus=$2
-xtype=$(xenstore-read "$xpath/type")
+xtype=$3
 xparams=$(xenstore-read "$xpath/params")
 
 case $xstatus in
tools/libxl/libxl_device.c +18 -9
diff -r bb2568713604 -r c3d4cad0fc2d tools/libxl/libxl_device.c
@@ -136,15 +136,20 @@ static int disk_try_backend(disk_try_bac
               a->disk->format == LIBXL_DISK_FORMAT_EMPTY)) {
             goto bad_format;
         }
-        if (a->disk->format != LIBXL_DISK_FORMAT_EMPTY &&
-            !S_ISBLK(a->stab.st_mode)) {
-            LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Disk vdev=%s, backend phy"
-                       " unsuitable as phys path not a block device",
-                       a->disk->vdev);
-            return 0;
-        }
-
-        return backend;
+        if (S_ISBLK(a->stab.st_mode))
+                return backend;
+#ifdef HAVE_PHY_BACKEND_FILE_SUPPORT
+        if (S_ISREG(a->stab.st_mode))
+            return backend;
+        LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Disk vdev=%s, backend phy"
+                   " unsuitable as phys path not a block device or"
+                   " raw image", a->disk->vdev);
+#else
+        LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Disk vdev=%s, backend phy"
+                   " unsuitable as phys path not a block device",
+                   a->disk->vdev);
+#endif
+        return 0;
 
     case LIBXL_DISK_BACKEND_TAP:
         if (!libxl__blktap_enabled(a->gc)) {
@@ -455,6 +460,10 @@ int libxl__devices_destroy(libxl__gc *gc
             fe_path = libxl__sprintf(gc, "/local/domain/%d/device/%s/%s", domid, l1[i], l2[j]);
             be_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/backend", fe_path));
             if (be_path != NULL) {
+#ifdef DONT_REMOVE_VBD_FROM_STORE
+                if (!strcmp(l1[i], "vbd"))
+                    continue;
+#endif
                 if (libxl__device_destroy(gc, be_path, force) > 0)
                     n_watches++;
             } else {
tools/libxl/libxl_osdeps.h +2 -0
diff -r bb2568713604 -r c3d4cad0fc2d tools/libxl/libxl_osdeps.h
@@ -25,6 +25,8 @@
 
 #if defined(__NetBSD__) || defined(__OpenBSD__)
 #include <util.h>
+#define HAVE_PHY_BACKEND_FILE_SUPPORT
+#define DONT_REMOVE_VBD_FROM_STORE
 #elif defined(__linux__)
 #include <pty.h>
 #elif defined(__sun__)
tools/xenbackendd/xenbackendd.c +36 -6

80 lines not on this page · raw message

#3 lore raw
In reply to Roger Pau Monné
Quoted 8 lines · Roger Pau Monné

2011/7/22 Ian Campbell <[email protected]>:

Quoted 1 line · Roger Pau Monne

I don't like doing it this way either. How are Linux hotplug scripts called? I've been looking arround, and there seems to be a set of udev rules that call the scripts based on changes regarding devfs, the problem is that NetBSD doesn't have devfs, and we have to watch the xenstore for changes in the status of the devices to trigger the correct scripts.

The hotplugs scripts are called from a udev rule but the event is triggered (asynchronously) by the backend driver based upon the changing state node, so ultimately they are triggered from the same xenstore watch.

It's certainly possible that the sequencing is different between Linux and NetBSD or that in the Linux case there is some interlock (deliberate or otherwise) between the kernel side and the hotplug script side which saves our bacon.

Who is responsible for driving the backend xenstore state machine under NetBSD? It doesn't look like xenbackendd (which just reacts to state changes).

Quoted 3 lines

I also see that Linux hotplug scripts also remove
entries from xenstore after detaching (xen-hotplug-cleanup), isn't it wrong if the entries are deleted in libxl?

It may be redundant but I don't think it is wrong, it should be harmless for both to remove the backend but if it isn't then I think it should be the toolstack's responsibility rather than the hotplug script.

Quoted 9 lines

The basic problem with this (if I got it right) is synchronization, entries should be deleted after the corresponding hotplug scripts are done. This happens sometimes in NetBSD, but it is not guaranted, since there's no rendezvous point to tell libxl that all is fine and xenstore can be cleaned. I think it would be good to set some kind of indication, that hotplug scripts have finished execution before libxl deletes the entries in xenstore, and possibly set a timeout, so libxl is not waiting forever if something goes wrong.

Quoted 5 lines

Also with xend hotplug scripts where in charge of removing entries from xenstore, but in libxl Linux has no support for block-hotplug using the loop device (only 'phy' which doesn't involve any read from xenstore to unplug), that's why I think this problem has not appeared before.

Ah, that may well be it. I had thought that vnd was all in kernel but now I see that it is setup and torn down in the hotplug script, much like for loopback on Linux with xend.

On Linux we were able to make the simplifying assumption of not handling this for phy devices because we had blktap to fall back on. NetBSD doesn't currently have that option.

I think part of the problem is that the vbd lifecycle and the backing device's lifecycle (vnd in this case, but could also be an iscsi login for example) are somewhat entwined via the hotplug scripts etc when really they should be layered and somewhat independent.

Ian Jackson has the best handle on this stuff and I know he has plans to move the block script callout stuff forward to better support various more complex block device types, integrate better with the toolstack and generally rationalise the existing interfaces etc so I'd like to hear what he thinks before I suggesting any particular avenue of attack to this problem. He's travelling right now but may be online intermittently next week (we're both going to be at the Debian conference in Banja Luka), I think he's back properly the week after that though.

Quoted 7 lines
Quoted 5 lines

The libxl device teardown stuff is pretty convoluted and I'm reasonably sure it is wrong in several respects, I've been meaning to untangle it, perhaps I should get to that sooner rather than later and maybe fix this issue as a side effect.

That would be great, I would like to give a hand if I can.

Thanks.

I'm travelling next week and on vacation the week after. But I need to get onto this soon so it is done for Xen 4.2, since it will an API incompatible change to libxl and we are hoping to declare the API stable at that point.

Have you considered coming to the Munich Xen.org hackathon in September?
http://wiki.xen.org/xenwiki/MUC_2011_hackathon. That would be a great opportunity to work through some of these issues and ensure that the future direction of libxl's handling of this stuff works for NetBSD as well as Linux.

Ian.

#4 lore raw
Quoted 5 lines

The hotplugs scripts are called from a udev rule but the event is triggered (asynchronously) by the backend driver based upon the changing state node, so ultimately they are triggered from the same xenstore watch.

Quoted 8 lines

It's certainly possible that the sequencing is different between Linux and NetBSD or that in the Linux case there is some interlock (deliberate or otherwise) between the kernel side and the hotplug script side which saves our bacon.

Who is responsible for driving the backend xenstore state machine under NetBSD? It doesn't look like xenbackendd (which just reacts to state changes).

xbdback is responsible for changing the state of xenstore, it performs the state change and attaches devices to guests. It is pretty similar to xenbackendd, but runs in the kernel space.

Quoted 3 lines

Ah, that may well be it. I had thought that vnd was all in kernel but now I see that it is setup and torn down in the hotplug script, much like for loopback on Linux with xend.

It's basically the same strategy as the one used on Linux with loopback devices

Quoted 3 lines

On Linux we were able to make the simplifying assumption of not handling this for phy devices because we had blktap to fall back on. NetBSD doesn't currently have that option.

Well, I'm trying to implement something similar to blktap2 in NetBSD, but all in user space, using pud, a driver that enables the implementation of block and character device drivers as userspace daemons (something similar to nbd in Linux I think), I've also looked into FUSE, but it required the use of vnd/loop device for the image to be presented as a block device.

Quoted 14 lines

I think part of the problem is that the vbd lifecycle and the backing device's lifecycle (vnd in this case, but could also be an iscsi login for example) are somewhat entwined via the hotplug scripts etc when really they should be layered and somewhat independent.

Ian Jackson has the best handle on this stuff and I know he has plans to move the block script callout stuff forward to better support various more complex block device types, integrate better with the toolstack and generally rationalise the existing interfaces etc so I'd like to hear what he thinks before I suggesting any particular avenue of attack to this problem. He's travelling right now but may be online intermittently next week (we're both going to be at the Debian conference in Banja Luka), I think he's back properly the week after that though.

Quoted 4 lines

I'm travelling next week and on vacation the week after. But I need to get onto this soon so it is done for Xen 4.2, since it will an API incompatible change to libxl and we are hoping to declare the API stable at that point.

Well, I hope you had a good trip, I will be off next week, and won't be back until the 10th of August, so we will have to leave this on a hold until then, but I'm not going to let it die.

Quoted 5 lines

Have you considered coming to the Munich Xen.org hackathon in September?
http://wiki.xen.org/xenwiki/MUC_2011_hackathon. That would be a great opportunity to work through some of these issues and ensure that the future direction of libxl's handling of this stuff works for NetBSD as well as Linux.

Thanks for the offer, I would really like to come, but I have some other stuff I also have to attend, so I don't think I will be able to come (it took me so long to answer this email because I was trying to come to the hackathon). Anyway, I hope I can come to future meetings/hackathons! I don't know if Christoph will we able to attend, if so he may be able to clarify some of the doubts about NetBSD device handling.

Thanks and regards, Roger.