Skip to contentSkip to conversation

Basic blktap2 functionality issues.

DISCUSSION [email protected] 4 participants 6 messages Mar 29, 2012 – Apr 2, 2012

lore
Share & tools
lore
#0 lore raw

Hi, hope the day is going well for everyone.

I had posted a note about this issue two weeks ago and didn't get any response. I don't know if that indicates that people are not using blktap or if the question stumped everyone.

First of all there is a documentable issue with blktap in 4.1.2 and xl. Anyone trying to use it to export files to a guest will be affected. Using xl to do 'block-attach' and 'block-detach' in dom0 also doesn't work in stock 4.1.2 so I suspect there are generic issues with blktap and xl.

In stock 4.1.2 using xl results in the tapdisk2 server process being orphaned. There is a patch floating around from Ian Campbell which fixes this problem and either creates or uncovers what may be a more fundamental problem.

With Ian's patch applied the tapdisk2 process terminates but the tapdisk device is not released resulting in a steady accumulation of orphan minor numbers. The underlying cause of this appears to be a resource deadlock between xl requesting a detach of the VBD and the tapdisk2 process.

Ian actually acknowledges the phenomenon in one of his posts saying there appeared to be a 'hang' when the VBD is released with his patches. The 'hang' is actually a livelock where the entire kernel blocks until the select call from xl to the tapdisk2 process times out and rescues things. The error return from the select call is what causes the xl code to not complete the release of the tapdisk minor.

I'm still hunting through the code maze trying to find the underlying problem. The tapdisk2 process is hanging on the munmap of the ring buffers. It 'feels' as if the problem may be secondary to xl still holding a reference to some resource which blocks the unmap of the ring buffers.

I will continue to hunt but if anyone has any pointers send them my way. It takes a bit of time to come up to speed on all the code paths.

In a broader context I think the XEN community needs to take a reasoned look at how to handle the file issue. It appears as if Dan Stodden has disappeared so I get the sense the entire blktap2 architecture is a bit rudderless (no judgement just observation). I'm trying to put my money where my mouth is and actually hunt for the problems which are there.

I've seen rumbles on LKML about discussions with regards to modifications to loop in order to deal with the page cache issues which hinder the reliability of delivering virtual block devices over loop. I don't know how far out that is or even if it will eventuate. I've also heard rumbles about a mythical 'blktap3' which runs completely in userspace. If that is the direction things are going I would certainly be willing to hammer on that rather then put more time into blktap2 if there is 'blktap3' code someplace.

I will look forward to any comments or suggestions people may have.

Have a good weekend.

As always,

Dr. G.W. Wettstein, Ph.D.   Enjellic Systems Development, LLC.
4206 N. 19th Ave.           Specializing in information infra-structure
Fargo, ND  58102            development.

PH: 701-281-1686
FAX: 701-281-3949 EMAIL: [email protected]
------------------------------------------------------------------------------
"My thoughts on trusting Open-Source? A quote I once saw said it
best: 'Remember, Amateurs built the ark. Professionals built the Titanic.' Perhaps most significantly the ark was one guy, there were no doubt committees involved with the Titanic project."
-- Dr. G.W. Wettstein
Resurrection

#1 lore raw
Quoted 56 lines · On Thu, 29 Mar 2012, [email protected] wrote:

Hi, hope the day is going well for everyone.

I had posted a note about this issue two weeks ago and didn't get any response. I don't know if that indicates that people are not using blktap or if the question stumped everyone.

First of all there is a documentable issue with blktap in 4.1.2 and xl. Anyone trying to use it to export files to a guest will be affected. Using xl to do 'block-attach' and 'block-detach' in dom0 also doesn't work in stock 4.1.2 so I suspect there are generic issues with blktap and xl.

In stock 4.1.2 using xl results in the tapdisk2 server process being orphaned. There is a patch floating around from Ian Campbell which fixes this problem and either creates or uncovers what may be a more fundamental problem.

With Ian's patch applied the tapdisk2 process terminates but the tapdisk device is not released resulting in a steady accumulation of orphan minor numbers. The underlying cause of this appears to be a resource deadlock between xl requesting a detach of the VBD and the tapdisk2 process.

Ian actually acknowledges the phenomenon in one of his posts saying there appeared to be a 'hang' when the VBD is released with his patches. The 'hang' is actually a livelock where the entire kernel blocks until the select call from xl to the tapdisk2 process times out and rescues things. The error return from the select call is what causes the xl code to not complete the release of the tapdisk minor.

I'm still hunting through the code maze trying to find the underlying problem. The tapdisk2 process is hanging on the munmap of the ring buffers. It 'feels' as if the problem may be secondary to xl still holding a reference to some resource which blocks the unmap of the ring buffers.

I will continue to hunt but if anyone has any pointers send them my way. It takes a bit of time to come up to speed on all the code paths.

In a broader context I think the XEN community needs to take a reasoned look at how to handle the file issue. It appears as if Dan Stodden has disappeared so I get the sense the entire blktap2 architecture is a bit rudderless (no judgement just observation). I'm trying to put my money where my mouth is and actually hunt for the problems which are there.

I've seen rumbles on LKML about discussions with regards to modifications to loop in order to deal with the page cache issues which hinder the reliability of delivering virtual block devices over loop. I don't know how far out that is or even if it will eventuate. I've also heard rumbles about a mythical 'blktap3' which runs completely in userspace. If that is the direction things are going I would certainly be willing to hammer on that rather then put more time into blktap2 if there is 'blktap3' code someplace.

Quoted 1 line

I will look forward to any comments or suggestions people may have.

A completely userspace blktap version is indeed in the work, but it is not clear yet when it is going to be ready.

Alternatively if you don't need VHD format support, you can use QCOW or QCOW2 with upstream QEMU in xen-unstable, that leads to very good performances and still provides copy on write support.

#2 lore raw
Quoted 57 lines · Stefano Stabellini
Quoted 56 lines · On Thu, 29 Mar 2012, [email protected] wrote:

Hi, hope the day is going well for everyone.

I had posted a note about this issue two weeks ago and didn't get any response. I don't know if that indicates that people are not using blktap or if the question stumped everyone.

First of all there is a documentable issue with blktap in 4.1.2 and xl. Anyone trying to use it to export files to a guest will be affected. Using xl to do 'block-attach' and 'block-detach' in dom0 also doesn't work in stock 4.1.2 so I suspect there are generic issues with blktap and xl.

In stock 4.1.2 using xl results in the tapdisk2 server process being orphaned. There is a patch floating around from Ian Campbell which fixes this problem and either creates or uncovers what may be a more fundamental problem.

With Ian's patch applied the tapdisk2 process terminates but the tapdisk device is not released resulting in a steady accumulation of orphan minor numbers. The underlying cause of this appears to be a resource deadlock between xl requesting a detach of the VBD and the tapdisk2 process.

Ian actually acknowledges the phenomenon in one of his posts saying there appeared to be a 'hang' when the VBD is released with his patches. The 'hang' is actually a livelock where the entire kernel blocks until the select call from xl to the tapdisk2 process times out and rescues things. The error return from the select call is what causes the xl code to not complete the release of the tapdisk minor.

I'm still hunting through the code maze trying to find the underlying problem. The tapdisk2 process is hanging on the munmap of the ring buffers. It 'feels' as if the problem may be secondary to xl still holding a reference to some resource which blocks the unmap of the ring buffers.

I will continue to hunt but if anyone has any pointers send them my way. It takes a bit of time to come up to speed on all the code paths.

In a broader context I think the XEN community needs to take a reasoned look at how to handle the file issue. It appears as if Dan Stodden has disappeared so I get the sense the entire blktap2 architecture is a bit rudderless (no judgement just observation). I'm trying to put my money where my mouth is and actually hunt for the problems which are there.

I've seen rumbles on LKML about discussions with regards to modifications to loop in order to deal with the page cache issues which hinder the reliability of delivering virtual block devices over loop. I don't know how far out that is or even if it will eventuate. I've also heard rumbles about a mythical 'blktap3' which runs completely in userspace. If that is the direction things are going I would certainly be willing to hammer on that rather then put more time into blktap2 if there is 'blktap3' code someplace.

Quoted 9 lines
Quoted 1 line

I will look forward to any comments or suggestions people may have.

A completely userspace blktap version is indeed in the work, but it is not clear yet when it is going to be ready.

Alternatively if you don't need VHD format support, you can use QCOW or QCOW2 with upstream QEMU in xen-unstable, that leads to very good performances and still provides copy on write support.

We should still support blktap2 in the 4.2 for people who have a kernel with the necessary driver included therefore I still think the bug which Greg reports needs investigating and hopefully fixing.

Ian.

#3 lore raw
In reply to [email protected]
Quoted 9 lines · On Thu, 2012-03-29 at 15:39 +0100, [email protected] wrote:

Hi, hope the day is going well for everyone.

I had posted a note about this issue two weeks ago and didn't get any response. I don't know if that indicates that people are not using blktap or if the question stumped everyone.

First of all there is a documentable issue with blktap in 4.1.2 and xl. Anyone trying to use it to export files to a guest will be affected.

The issue you refer to here is the deadlock describe below right? The block device is actually functional while the guest is up and running?

Quoted 3 lines

Using xl to do 'block-attach' and 'block-detach' in dom0
also doesn't work in stock 4.1.2 so I suspect there are generic issues with blktap and xl.

Stefano was looking at block-attach to dom0 more generally in xen-unstable too.

Quoted 4 lines

In stock 4.1.2 using xl results in the tapdisk2 server process being orphaned. There is a patch floating around from Ian Campbell which fixes this problem and either creates or uncovers what may be a more fundamental problem.

That patch has been applied to xen-unstable -- does this hang occur for you there? (I'm in the process of installing a suitable system to try and reproduce).

Quoted 5 lines

With Ian's patch applied the tapdisk2 process terminates but the tapdisk device is not released resulting in a steady accumulation of orphan minor numbers. The underlying cause of this appears to be a resource deadlock between xl requesting a detach of the VBD and the tapdisk2 process.

When you say "the tapdisk2 process terminates" I guess you mean "tries to terminate but gets blocked" rather than actually quits, since otherwise I don't think there would be a deadlock?

I think an approach worth trying would be to have tapdisk_control_detach_vbd respond to TAPDISK_MESSAGE_DETACH before doing the actual detach. i.e. it would respond with "Yes, I will do that" rather than "Yes, I have done that". My speculation is that this will allow libxl to continue and hopefully avoid the deadlock.

A similar alternative would be to have tap_ctl_detach not wait for a response at all.

In both cases I think it could be argued that if the TAPDISK_MESSAGE_DETACH message does not result in tapdisk2 shutting down there isn't much that libxl could do about it anyway so it might as well get on with its life.

The other approach would be to figure out what libxl is doing after its call (or perhaps just not doing) to tap_ctl_detach which actually has to be done first e..g perhaps destroying the xenstore backend directory?

Quoted 4 lines

I've also heard rumbles about a mythical 'blktap3' which runs completely in userspace. If that is the direction things are going I would certainly be willing to hammer on that rather then put more time into blktap2 if there is 'blktap3' code someplace.

I expect that a lot of the control-plane stuff will be the same between blktap2 and 3 so any issues fixed in 2 will likely help 3 too.

It is also worth fixing issues in blktap2 simply for the sake of fixing them since there will still be people who are using it in 4.2.

Ian.

#4 lore raw
Quoted 5 lines · Ian Campbell

I think an approach worth trying would be to have tapdisk_control_detach_vbd respond to TAPDISK_MESSAGE_DETACH before doing the actual detach. i.e. it would respond with "Yes, I will do that" rather than "Yes, I have done that". My speculation is that this will allow libxl to continue and hopefully avoid the deadlock.

This seems to be the case as the following fixes things for me. Thanks very much for your analysis which lead me to this solution...

Ian.

8<--------------------------------

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1333106445 -3600
# Node ID 79e3dbe4b659e78408a9eea76c51a601bd4a383a
# Parent 947e095a6d29b5e90a01b7c06b298d4c91dcf3ac
tapdisk: respond to destroy request before tearing down the commuication channel

This avoids a deadlock while sending the response which leads to a 5s timeout and leaked tapdisk processes. Instead send the response after getting the VBD which appears to be the only step wich can fail (or at least the only one which returns an error code).

Also call libxl__device_destroy_tapdisk before removing the backend directory in xenstore since we need the tapdisk-params value.

tools/blktap2/drivers/tapdisk-control.c +12 -14
diff -r 947e095a6d29 -r 79e3dbe4b659 tools/blktap2/drivers/tapdisk-control.c
@@ -379,10 +379,18 @@ tapdisk_control_detach_vbd(struct tapdis
 	int err;
 
 	vbd = tapdisk_server_get_vbd(request->cookie);
-	if (!vbd) {
-		err = -EINVAL;
-		goto out;
-	}
+	err = !vbd ? -EINVAL : 0;
+
+	memset(&response, 0, sizeof(response));
+	response.type = TAPDISK_MESSAGE_DETACH_RSP;
+	response.cookie = request->cookie;
+	response.u.response.error = -err;
+
+	tapdisk_control_write_message(connection->socket, &response, 2);
+	tapdisk_control_close_connection(connection);
+
+	if (err)
+		return;
 
 	tapdisk_vbd_detach(vbd);
 
@@ -390,16 +398,6 @@ tapdisk_control_detach_vbd(struct tapdis
 		tapdisk_server_remove_vbd(vbd);
 		free(vbd);
 	}
-
-	err = 0;
-out:
-	memset(&response, 0, sizeof(response));
-	response.type = TAPDISK_MESSAGE_DETACH_RSP;
-	response.cookie = request->cookie;
-	response.u.response.error = -err;
-
-	tapdisk_control_write_message(connection->socket, &response, 2);
-	tapdisk_control_close_connection(connection);
 }
 
 static void
tools/libxl/libxl_device.c +2 -2
diff -r 947e095a6d29 -r 79e3dbe4b659 tools/libxl/libxl_device.c
@@ -432,11 +432,11 @@ int libxl__device_destroy(libxl__gc *gc,
     char *be_path = libxl__device_backend_path(gc, dev);
     char *fe_path = libxl__device_frontend_path(gc, dev);
 
+    libxl__device_destroy_tapdisk(gc, be_path);
+
     xs_rm(ctx->xsh, XBT_NULL, be_path);
     xs_rm(ctx->xsh, XBT_NULL, fe_path);
 
-    libxl__device_destroy_tapdisk(gc, be_path);
-
     return 0;
 }
#5 lore raw

Ian Campbell writes ("Re: [Xen-devel] Basic blktap2 functionality issues."):

Quoted 9 lines · Ian Campbell
Quoted 5 lines

I think an approach worth trying would be to have tapdisk_control_detach_vbd respond to TAPDISK_MESSAGE_DETACH before doing the actual detach. i.e. it would respond with "Yes, I will do that" rather than "Yes, I have done that". My speculation is that this will allow libxl to continue and hopefully avoid the deadlock.

This seems to be the case as the following fixes things for me. Thanks very much for your analysis which lead me to this solution...

Greg, can you confirm whether this works for you ?

Ian.