Skip to contentSkip to conversation

xen-blkback: stop blkback thread of every queue in xen_blkif_disconnect

PATCH Superseded Annie Li 3 participants 13 messages Aug 17, 2017 – Aug 24, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Annie Li

author
#0 lore raw

PATCH 1/1 xen-blkback: stop blkback thread of every queue in xen_blkif_disconnect

If there is inflight I/O in any non-last queue, blkback returns -EBUSY directly, and never stops thread of remaining queue and processs them. When removing vbd device with lots of disk I/O load, some queues with inflight I/O still have blkback thread running even though the corresponding vbd device or guest is gone.
And this could cause some problems, for example, if the backend device type is file, some loop devices and blkback thread always lingers there forever after guest is destroyed, and this causes failure of umounting repositories unless rebooting the dom0. So stop all threads properly and return -EBUSY if any queue has inflight I/O.

---
 drivers/block/xen-blkback/xenbus.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/block/xen-blkback/xenbus.c +8 -2
index 792da68..2adb859 100644
@@ -244,6 +244,7 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
 {
 	struct pending_req *req, *n;
 	unsigned int j, r;
+	bool busy = false;
 
 	for (r = 0; r < blkif->nr_rings; r++) {
 		struct xen_blkif_ring *ring = &blkif->rings[r];
@@ -261,8 +262,10 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
 		 * don't have any discard_io or other_io requests. So, checking
 		 * for inflight IO is enough.
 		 */
-		if (atomic_read(&ring->inflight) > 0)
-			return -EBUSY;
+		if (atomic_read(&ring->inflight) > 0) {
+			busy = true;
+			continue;
+		}
 
 		if (ring->irq) {
 			unbind_from_irqhandler(ring->irq, ring);
@@ -300,6 +303,9 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
 		WARN_ON(i != (XEN_BLKIF_REQS_PER_PAGE * blkif->nr_ring_pages));
 		ring->active = false;
 	}
+	if (busy)
+		return -EBUSY;
+
 	blkif->nr_ring_pages = 0;
 	/*
 	 * blkif->rings was allocated in connect_ring, so we should free it in
Signature · 1 line
1.9.3
#1 lore raw
Quoted 32 lines · Annie Li

If there is inflight I/O in any non-last queue, blkback returns -EBUSY directly, and never stops thread of remaining queue and processs them. When removing vbd device with lots of disk I/O load, some queues with inflight I/O still have blkback thread running even though the corresponding vbd device or guest is gone.
And this could cause some problems, for example, if the backend device type is file, some loop devices and blkback thread always lingers there forever after guest is destroyed, and this causes failure of umounting repositories unless rebooting the dom0. So stop all threads properly and return -EBUSY if any queue has inflight I/O.

---
 drivers/block/xen-blkback/xenbus.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/block/xen-blkback/xenbus.c +1 -0
index 792da68..2adb859 100644
@@ -244,6 +244,7 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
 {
 	struct pending_req *req, *n;
 	unsigned int j, r;
+	bool busy = false;
 
 	for (r = 0; r < blkif->nr_rings; r++) {
 		struct xen_blkif_ring *ring = &blkif->rings[r];

drivers/block/xen-blkback/xenbus.c static int xen_blkif_disconnect(struct xen_blkif *blkif) · line 268

Quoted 9 lines
drivers/block/xen-blkback/xenbus.c +4 -2
@@ -261,8 +262,10 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
 		 * don't have any discard_io or other_io requests. So, checking
 		 * for inflight IO is enough.
 		 */
-		if (atomic_read(&ring->inflight) > 0)
-			return -EBUSY;
+		if (atomic_read(&ring->inflight) > 0) {
+			busy = true;
+			continue;
+		}

I guess I'm missing something, but I don't see how this is solving the problem described in the description.

If the problem is that xen_blkif_disconnect returns without cleaning all the queues, this patch keeps the current behavior, just that it will try to remove more queues before returning, as opposed to returning when finding the first busy queue.

Roger.

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

#2 lore raw
In reply to Annie Li
Quoted 32 lines · Annie Li

If there is inflight I/O in any non-last queue, blkback returns -EBUSY directly, and never stops thread of remaining queue and processs them. When removing vbd device with lots of disk I/O load, some queues with inflight I/O still have blkback thread running even though the corresponding vbd device or guest is gone.
And this could cause some problems, for example, if the backend device type is file, some loop devices and blkback thread always lingers there forever after guest is destroyed, and this causes failure of umounting repositories unless rebooting the dom0. So stop all threads properly and return -EBUSY if any queue has inflight I/O.

---
 drivers/block/xen-blkback/xenbus.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/block/xen-blkback/xenbus.c +1 -0
index 792da68..2adb859 100644
@@ -244,6 +244,7 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
 {
 	struct pending_req *req, *n;
 	unsigned int j, r;
+	bool busy = false;
 
 	for (r = 0; r < blkif->nr_rings; r++) {
 		struct xen_blkif_ring *ring = &blkif->rings[r];

drivers/block/xen-blkback/xenbus.c static int xen_blkif_disconnect(struct xen_blkif *blkif) · line 268

Quoted 9 lines
drivers/block/xen-blkback/xenbus.c +4 -2
@@ -261,8 +262,10 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
 		 * don't have any discard_io or other_io requests. So, checking
 		 * for inflight IO is enough.
 		 */
-		if (atomic_read(&ring->inflight) > 0)
-			return -EBUSY;
+		if (atomic_read(&ring->inflight) > 0) {
+			busy = true;
+			continue;
+		}

I guess I'm missing something, but I don't see how this is solving the problem described in the description.

If the problem is that xen_blkif_disconnect returns without cleaning all the queues, this patch keeps the current behavior, just that it will try to remove more queues before returning, as opposed to returning when finding the first busy queue.

Roger.

author
#3 lore raw
Quoted 45 lines · Roger Pau Monné
Quoted 32 lines · Annie Li

If there is inflight I/O in any non-last queue, blkback returns -EBUSY directly, and never stops thread of remaining queue and processs them. When removing vbd device with lots of disk I/O load, some queues with inflight I/O still have blkback thread running even though the corresponding vbd device or guest is gone.
And this could cause some problems, for example, if the backend device type is file, some loop devices and blkback thread always lingers there forever after guest is destroyed, and this causes failure of umounting repositories unless rebooting the dom0. So stop all threads properly and return -EBUSY if any queue has inflight I/O.

---
  drivers/block/xen-blkback/xenbus.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
drivers/block/xen-blkback/xenbus.c +1 -0
index 792da68..2adb859 100644
@@ -244,6 +244,7 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
  {
  	struct pending_req *req, *n;
  	unsigned int j, r;
+	bool busy = false;
 
  	for (r = 0; r < blkif->nr_rings; r++) {
  		struct xen_blkif_ring *ring = &blkif->rings[r];

drivers/block/xen-blkback/xenbus.c static int xen_blkif_disconnect(struct xen_blkif *blkif) · line 268

Quoted 9 lines
drivers/block/xen-blkback/xenbus.c +4 -2
@@ -261,8 +262,10 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
  		 * don't have any discard_io or other_io requests. So, checking
  		 * for inflight IO is enough.
  		 */
-		if (atomic_read(&ring->inflight) > 0)
-			return -EBUSY;
+		if (atomic_read(&ring->inflight) > 0) {
+			busy = true;
+			continue;
+		}

I guess I'm missing something, but I don't see how this is solving the problem described in the description.

Quoted 4 lines

If the problem is that xen_blkif_disconnect returns without cleaning all the queues, this patch keeps the current behavior, just that it will try to remove more queues before returning, as opposed to returning when finding the first busy queue.

Before checking inflight, following code stops the blkback thread,

                if (ring->xenblkd) {
                        kthread_stop(ring->xenblkd);
                        wake_up(&ring->shutdown_wq);
                }

This patch allows thread of every queue has the chance to get stopped. Otherwise, only thread of queue before(including) first busy one get stopped, threads of remaining queue will still run, and these blkthread and corresponding loop device will linger forever even after guest is destroyed.

Thanks
Annie

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

author
#4 lore raw
In reply to Roger Pau Monné
Quoted 45 lines · Roger Pau Monné
Quoted 32 lines · Annie Li

If there is inflight I/O in any non-last queue, blkback returns -EBUSY directly, and never stops thread of remaining queue and processs them. When removing vbd device with lots of disk I/O load, some queues with inflight I/O still have blkback thread running even though the corresponding vbd device or guest is gone.
And this could cause some problems, for example, if the backend device type is file, some loop devices and blkback thread always lingers there forever after guest is destroyed, and this causes failure of umounting repositories unless rebooting the dom0. So stop all threads properly and return -EBUSY if any queue has inflight I/O.

---
  drivers/block/xen-blkback/xenbus.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
drivers/block/xen-blkback/xenbus.c +1 -0
index 792da68..2adb859 100644
@@ -244,6 +244,7 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
  {
  	struct pending_req *req, *n;
  	unsigned int j, r;
+	bool busy = false;
 
  	for (r = 0; r < blkif->nr_rings; r++) {
  		struct xen_blkif_ring *ring = &blkif->rings[r];

drivers/block/xen-blkback/xenbus.c static int xen_blkif_disconnect(struct xen_blkif *blkif) · line 268

Quoted 9 lines
drivers/block/xen-blkback/xenbus.c +4 -2
@@ -261,8 +262,10 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
  		 * don't have any discard_io or other_io requests. So, checking
  		 * for inflight IO is enough.
  		 */
-		if (atomic_read(&ring->inflight) > 0)
-			return -EBUSY;
+		if (atomic_read(&ring->inflight) > 0) {
+			busy = true;
+			continue;
+		}

I guess I'm missing something, but I don't see how this is solving the problem described in the description.

Quoted 4 lines

If the problem is that xen_blkif_disconnect returns without cleaning all the queues, this patch keeps the current behavior, just that it will try to remove more queues before returning, as opposed to returning when finding the first busy queue.

Before checking inflight, following code stops the blkback thread,

                if (ring->xenblkd) {
                        kthread_stop(ring->xenblkd);
                        wake_up(&ring->shutdown_wq);
                }

This patch allows thread of every queue has the chance to get stopped. Otherwise, only thread of queue before(including) first busy one get stopped, threads of remaining queue will still run, and these blkthread and corresponding loop device will linger forever even after guest is destroyed.

Thanks
Annie

#5 lore raw
Quoted 51 lines · annie li
Quoted 44 lines · Roger Pau Monné
Quoted 31 lines · Annie Li

If there is inflight I/O in any non-last queue, blkback returns -EBUSY directly, and never stops thread of remaining queue and processs them. When removing vbd device with lots of disk I/O load, some queues with inflight I/O still have blkback thread running even though the corresponding vbd device or guest is gone.
And this could cause some problems, for example, if the backend device type is file, some loop devices and blkback thread always lingers there forever after guest is destroyed, and this causes failure of umounting repositories unless rebooting the dom0. So stop all threads properly and return -EBUSY if any queue has inflight I/O.

---
  drivers/block/xen-blkback/xenbus.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
drivers/block/xen-blkback/xenbus.c +1 -0
index 792da68..2adb859 100644
@@ -244,6 +244,7 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
  {
  	struct pending_req *req, *n;
  	unsigned int j, r;
+	bool busy = false;
  	for (r = 0; r < blkif->nr_rings; r++) {
  		struct xen_blkif_ring *ring = &blkif->rings[r];

drivers/block/xen-blkback/xenbus.c static int xen_blkif_disconnect(struct xen_blkif *blkif) · line 268

Quoted 9 lines
drivers/block/xen-blkback/xenbus.c +4 -2
@@ -261,8 +262,10 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
  		 * don't have any discard_io or other_io requests. So, checking
  		 * for inflight IO is enough.
  		 */
-		if (atomic_read(&ring->inflight) > 0)
-			return -EBUSY;
+		if (atomic_read(&ring->inflight) > 0) {
+			busy = true;
+			continue;
+		}

I guess I'm missing something, but I don't see how this is solving the problem described in the description.

Quoted 4 lines

If the problem is that xen_blkif_disconnect returns without cleaning all the queues, this patch keeps the current behavior, just that it will try to remove more queues before returning, as opposed to returning when finding the first busy queue.

Before checking inflight, following code stops the blkback thread,

Quoted 8 lines
                if (ring->xenblkd) {
                        kthread_stop(ring->xenblkd);
                        wake_up(&ring->shutdown_wq);
                }

This patch allows thread of every queue has the chance to get stopped. Otherwise, only thread of queue before(including) first busy one get stopped, threads of remaining queue will still run, and these blkthread and corresponding loop device will linger forever even after guest is destroyed.

Thanks for the explanation:

Roger.

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

#6 lore raw
In reply to annie li
Quoted 51 lines · annie li
Quoted 44 lines · Roger Pau Monné
Quoted 31 lines · Annie Li

If there is inflight I/O in any non-last queue, blkback returns -EBUSY directly, and never stops thread of remaining queue and processs them. When removing vbd device with lots of disk I/O load, some queues with inflight I/O still have blkback thread running even though the corresponding vbd device or guest is gone.
And this could cause some problems, for example, if the backend device type is file, some loop devices and blkback thread always lingers there forever after guest is destroyed, and this causes failure of umounting repositories unless rebooting the dom0. So stop all threads properly and return -EBUSY if any queue has inflight I/O.

---
  drivers/block/xen-blkback/xenbus.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
drivers/block/xen-blkback/xenbus.c +1 -0
index 792da68..2adb859 100644
@@ -244,6 +244,7 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
  {
  	struct pending_req *req, *n;
  	unsigned int j, r;
+	bool busy = false;
  	for (r = 0; r < blkif->nr_rings; r++) {
  		struct xen_blkif_ring *ring = &blkif->rings[r];

drivers/block/xen-blkback/xenbus.c static int xen_blkif_disconnect(struct xen_blkif *blkif) · line 268

Quoted 9 lines
drivers/block/xen-blkback/xenbus.c +4 -2
@@ -261,8 +262,10 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
  		 * don't have any discard_io or other_io requests. So, checking
  		 * for inflight IO is enough.
  		 */
-		if (atomic_read(&ring->inflight) > 0)
-			return -EBUSY;
+		if (atomic_read(&ring->inflight) > 0) {
+			busy = true;
+			continue;
+		}

I guess I'm missing something, but I don't see how this is solving the problem described in the description.

Quoted 4 lines

If the problem is that xen_blkif_disconnect returns without cleaning all the queues, this patch keeps the current behavior, just that it will try to remove more queues before returning, as opposed to returning when finding the first busy queue.

Before checking inflight, following code stops the blkback thread,

Quoted 8 lines
                if (ring->xenblkd) {
                        kthread_stop(ring->xenblkd);
                        wake_up(&ring->shutdown_wq);
                }

This patch allows thread of every queue has the chance to get stopped. Otherwise, only thread of queue before(including) first busy one get stopped, threads of remaining queue will still run, and these blkthread and corresponding loop device will linger forever even after guest is destroyed.

Thanks for the explanation:

Roger.

#7 lore raw
Quoted 61 lines · Roger Pau Monné
Quoted 51 lines · annie li
Quoted 44 lines · Roger Pau Monné
Quoted 31 lines · Annie Li

If there is inflight I/O in any non-last queue, blkback returns -EBUSY directly, and never stops thread of remaining queue and processs them. When removing vbd device with lots of disk I/O load, some queues with inflight I/O still have blkback thread running even though the corresponding vbd device or guest is gone.
And this could cause some problems, for example, if the backend device type is file, some loop devices and blkback thread always lingers there forever after guest is destroyed, and this causes failure of umounting repositories unless rebooting the dom0. So stop all threads properly and return -EBUSY if any queue has inflight I/O.

---
  drivers/block/xen-blkback/xenbus.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
drivers/block/xen-blkback/xenbus.c +1 -0
index 792da68..2adb859 100644
@@ -244,6 +244,7 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
  {
  	struct pending_req *req, *n;
  	unsigned int j, r;
+	bool busy = false;
  	for (r = 0; r < blkif->nr_rings; r++) {
  		struct xen_blkif_ring *ring = &blkif->rings[r];

drivers/block/xen-blkback/xenbus.c static int xen_blkif_disconnect(struct xen_blkif *blkif) · line 268

Quoted 9 lines
drivers/block/xen-blkback/xenbus.c +4 -2
@@ -261,8 +262,10 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
  		 * don't have any discard_io or other_io requests. So, checking
  		 * for inflight IO is enough.
  		 */
-		if (atomic_read(&ring->inflight) > 0)
-			return -EBUSY;
+		if (atomic_read(&ring->inflight) > 0) {
+			busy = true;
+			continue;
+		}

I guess I'm missing something, but I don't see how this is solving the problem described in the description.

Quoted 4 lines

If the problem is that xen_blkif_disconnect returns without cleaning all the queues, this patch keeps the current behavior, just that it will try to remove more queues before returning, as opposed to returning when finding the first busy queue.

Before checking inflight, following code stops the blkback thread,

Quoted 8 lines
                if (ring->xenblkd) {
                        kthread_stop(ring->xenblkd);
                        wake_up(&ring->shutdown_wq);
                }

This patch allows thread of every queue has the chance to get stopped. Otherwise, only thread of queue before(including) first busy one get stopped, threads of remaining queue will still run, and these blkthread and corresponding loop device will linger forever even after guest is destroyed.

Quoted 3 lines

Thanks for the explanation:

Forgot to add, this needs to be backported to stable branches, so:

Roger.

#12 lore raw
In reply to Roger Pau Monné
Quoted 61 lines · Roger Pau Monné
Quoted 51 lines · annie li
Quoted 44 lines · Roger Pau Monné
Quoted 31 lines · Annie Li

If there is inflight I/O in any non-last queue, blkback returns -EBUSY directly, and never stops thread of remaining queue and processs them. When removing vbd device with lots of disk I/O load, some queues with inflight I/O still have blkback thread running even though the corresponding vbd device or guest is gone.
And this could cause some problems, for example, if the backend device type is file, some loop devices and blkback thread always lingers there forever after guest is destroyed, and this causes failure of umounting repositories unless rebooting the dom0. So stop all threads properly and return -EBUSY if any queue has inflight I/O.

---
  drivers/block/xen-blkback/xenbus.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
drivers/block/xen-blkback/xenbus.c +1 -0
index 792da68..2adb859 100644
@@ -244,6 +244,7 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
  {
  	struct pending_req *req, *n;
  	unsigned int j, r;
+	bool busy = false;
  	for (r = 0; r < blkif->nr_rings; r++) {
  		struct xen_blkif_ring *ring = &blkif->rings[r];

drivers/block/xen-blkback/xenbus.c static int xen_blkif_disconnect(struct xen_blkif *blkif) · line 268

Quoted 9 lines
drivers/block/xen-blkback/xenbus.c +4 -2
@@ -261,8 +262,10 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
  		 * don't have any discard_io or other_io requests. So, checking
  		 * for inflight IO is enough.
  		 */
-		if (atomic_read(&ring->inflight) > 0)
-			return -EBUSY;
+		if (atomic_read(&ring->inflight) > 0) {
+			busy = true;
+			continue;
+		}

I guess I'm missing something, but I don't see how this is solving the problem described in the description.

Quoted 4 lines

If the problem is that xen_blkif_disconnect returns without cleaning all the queues, this patch keeps the current behavior, just that it will try to remove more queues before returning, as opposed to returning when finding the first busy queue.

Before checking inflight, following code stops the blkback thread,

Quoted 8 lines
                if (ring->xenblkd) {
                        kthread_stop(ring->xenblkd);
                        wake_up(&ring->shutdown_wq);
                }

This patch allows thread of every queue has the chance to get stopped. Otherwise, only thread of queue before(including) first busy one get stopped, threads of remaining queue will still run, and these blkthread and corresponding loop device will linger forever even after guest is destroyed.

Quoted 3 lines

Thanks for the explanation:

Forgot to add, this needs to be backported to stable branches, so:

Roger.

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

#11 lore raw
In reply to Roger Pau Monné

.snip..

Quoted 4 lines
Quoted 2 lines

Forgot to add, this needs to be backported to stable branches, so:

Annie, could you resend the patch with the tags and an update to the description to me please?

Quoted 9 lines

Roger.

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

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

author
#9 lore raw
In reply to Konrad Rzeszutek Wilk
Quoted 5 lines · Konrad Rzeszutek Wilk

..snip..

Quoted 2 lines
Quoted 1 line

Forgot to add, this needs to be backported to stable branches, so:

Annie, could you resend the patch with the tags and an update to the description to me please?

Done

Thanks
Annie

Quoted 8 lines
Quoted 8 lines

Roger.

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

author
#10 lore raw
In reply to Konrad Rzeszutek Wilk
Quoted 5 lines · Konrad Rzeszutek Wilk

..snip..

Quoted 2 lines
Quoted 1 line

Forgot to add, this needs to be backported to stable branches, so:

Annie, could you resend the patch with the tags and an update to the description to me please?

Done

Thanks
Annie

Quoted 8 lines
Quoted 8 lines

Roger.

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

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