Skip to contentSkip to conversation

xen-blkfront: don't call talk_to_blkback when already connected to blkback

PATCH In review Bob Liu 3 participants 19 messages May 31, 2016 – Jun 15, 2016

Subsystems (3)
lore
Share & tools
lore

Bob Liu

author
#0 lore raw

PATCH 1/2 xen-blkfront: don't call talk_to_blkback when already connected to blkback

Sometimes blkfont may receive twice blkback_changed() notification after migration, then talk_to_blkback() will be called twice too and confused xen-blkback.

---
 drivers/block/xen-blkfront.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/xen-blkfront.c +2 -1
index ca13df8..01aa460 100644
@@ -2485,7 +2485,8 @@ static void blkback_changed(struct xenbus_device *dev,
 		break;
 
 	case XenbusStateConnected:
-		if (dev->state != XenbusStateInitialised) {
+		if ((dev->state != XenbusStateInitialised) &&
+			(dev->state != XenbusStateConnected)) {
 			if (talk_to_blkback(dev, info))
 				break;
 		}
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 2/2 xen-blkfront: fix resume issues

After migrate to another host, the number of rings(block hardware queues) may be changed and the ring info structure will also be reallocated.

This patch fix two related place:
* call blk_mq_update_nr_hw_queues() to make blk-core knows the number
of hardware queues have been changed.
* Don't store rinfo pointer to hctx->driver_data, because rinfo may be
* reallocated so using hctx->queue_num to get the rinfo structure instead.

---
 drivers/block/xen-blkfront.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/block/xen-blkfront.c +8 -12
index 01aa460..83e36c5 100644
@@ -874,8 +874,12 @@ static int blkif_queue_rq(struct blk_mq_hw_ctx *hctx,
 			  const struct blk_mq_queue_data *qd)
 {
 	unsigned long flags;
-	struct blkfront_ring_info *rinfo = (struct blkfront_ring_info *)hctx->driver_data;
+	int qid = hctx->queue_num;
+	struct blkfront_info *info = hctx->queue->queuedata;
+	struct blkfront_ring_info *rinfo = NULL;
 
+	BUG_ON(info->nr_rings <= qid);
+	rinfo = &info->rinfo[qid];
 	blk_mq_start_request(qd->rq);
 	spin_lock_irqsave(&rinfo->ring_lock, flags);
 	if (RING_FULL(&rinfo->ring))
@@ -901,20 +905,9 @@ out_busy:
 	return BLK_MQ_RQ_QUEUE_BUSY;
 }
 
-static int blk_mq_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
-			    unsigned int index)
-{
-	struct blkfront_info *info = (struct blkfront_info *)data;
-
-	BUG_ON(info->nr_rings <= index);
-	hctx->driver_data = &info->rinfo[index];
-	return 0;
-}
-
 static struct blk_mq_ops blkfront_mq_ops = {
 	.queue_rq = blkif_queue_rq,
 	.map_queue = blk_mq_map_queue,
-	.init_hctx = blk_mq_init_hctx,
 };
 
 static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size,
@@ -950,6 +943,7 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size,
 		return PTR_ERR(rq);
 	}
 
+	rq->queuedata = info;
 	queue_flag_set_unlocked(QUEUE_FLAG_VIRT, rq);
 
 	if (info->feature_discard) {
@@ -2149,6 +2143,8 @@ static int blkfront_resume(struct xenbus_device *dev)
 		return err;
 
 	err = talk_to_blkback(dev, info);
+	if (!err)
+		blk_mq_update_nr_hw_queues(&info->tag_set, info->nr_rings);
 
 	/*
 	 * We have to wait for the backend to switch to
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#2 lore raw

PATCH 2/2 xen-blkfront: fix resume issues

In reply to Bob Liu

After migrate to another host, the number of rings(block hardware queues) may be changed and the ring info structure will also be reallocated.

This patch fix two related place:
* call blk_mq_update_nr_hw_queues() to make blk-core knows the number
of hardware queues have been changed.
* Don't store rinfo pointer to hctx->driver_data, because rinfo may be
* reallocated so using hctx->queue_num to get the rinfo structure instead.

---
 drivers/block/xen-blkfront.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/block/xen-blkfront.c +8 -12
index 01aa460..83e36c5 100644
@@ -874,8 +874,12 @@ static int blkif_queue_rq(struct blk_mq_hw_ctx *hctx,
 			  const struct blk_mq_queue_data *qd)
 {
 	unsigned long flags;
-	struct blkfront_ring_info *rinfo = (struct blkfront_ring_info *)hctx->driver_data;
+	int qid = hctx->queue_num;
+	struct blkfront_info *info = hctx->queue->queuedata;
+	struct blkfront_ring_info *rinfo = NULL;
 
+	BUG_ON(info->nr_rings <= qid);
+	rinfo = &info->rinfo[qid];
 	blk_mq_start_request(qd->rq);
 	spin_lock_irqsave(&rinfo->ring_lock, flags);
 	if (RING_FULL(&rinfo->ring))
@@ -901,20 +905,9 @@ out_busy:
 	return BLK_MQ_RQ_QUEUE_BUSY;
 }
 
-static int blk_mq_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
-			    unsigned int index)
-{
-	struct blkfront_info *info = (struct blkfront_info *)data;
-
-	BUG_ON(info->nr_rings <= index);
-	hctx->driver_data = &info->rinfo[index];
-	return 0;
-}
-
 static struct blk_mq_ops blkfront_mq_ops = {
 	.queue_rq = blkif_queue_rq,
 	.map_queue = blk_mq_map_queue,
-	.init_hctx = blk_mq_init_hctx,
 };
 
 static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size,
@@ -950,6 +943,7 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size,
 		return PTR_ERR(rq);
 	}
 
+	rq->queuedata = info;
 	queue_flag_set_unlocked(QUEUE_FLAG_VIRT, rq);
 
 	if (info->feature_discard) {
@@ -2149,6 +2143,8 @@ static int blkfront_resume(struct xenbus_device *dev)
 		return err;
 
 	err = talk_to_blkback(dev, info);
+	if (!err)
+		blk_mq_update_nr_hw_queues(&info->tag_set, info->nr_rings);
 
 	/*
 	 * We have to wait for the backend to switch to
Signature · 1 line
2.7.4
#3 lore raw
In reply to Bob Liu
Quoted 3 lines · Bob Liu

Sometimes blkfont may receive twice blkback_changed() notification after migration, then talk_to_blkback() will be called twice too and confused xen-blkback.

Could you enlighten the patch description by having some form of state transition here? I am curious how you got the frontend to get in XenbusStateConnected (via blkif_recover right) and then the backend triggering the update once more?

Or is just a simple race - the backend moves from XenbusStateConnected-> XenbusStateConnected - which retriggers the frontend to hit in blkback_changed the XenbusStateConnected state and go in there? (That would be in conenct_ring changing the state). But I don't see how the frontend_changed code get there as we have:

770 /*

 771                  * Ensure we connect even when two watches fire in
 772                  * close succession and we miss the intermediate value
 773                  * of frontend_state.
 774                  */

775 if (dev->state == XenbusStateConnected)
776 break;
777

?

Now what about 'blkfront_connect' being called on the second time?

Ah, info->connected is probably by then in BLKIF_STATE_CONNECTED (as blkif_recover changed) and we just reread the size of the disk.

Is that how about the flow goes?

Quoted 23 lines
---
 drivers/block/xen-blkfront.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/xen-blkfront.c +2 -1
index ca13df8..01aa460 100644
@@ -2485,7 +2485,8 @@ static void blkback_changed(struct xenbus_device *dev,
 		break;
 
 	case XenbusStateConnected:
-		if (dev->state != XenbusStateInitialised) {
+		if ((dev->state != XenbusStateInitialised) &&
+			(dev->state != XenbusStateConnected)) {
 			if (talk_to_blkback(dev, info))
 				break;
 		}
Signature · 1 line
2.7.4

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

#4 lore raw
In reply to Bob Liu
Quoted 3 lines · Bob Liu

Sometimes blkfont may receive twice blkback_changed() notification after migration, then talk_to_blkback() will be called twice too and confused xen-blkback.

Could you enlighten the patch description by having some form of state transition here? I am curious how you got the frontend to get in XenbusStateConnected (via blkif_recover right) and then the backend triggering the update once more?

Or is just a simple race - the backend moves from XenbusStateConnected-> XenbusStateConnected - which retriggers the frontend to hit in blkback_changed the XenbusStateConnected state and go in there? (That would be in conenct_ring changing the state). But I don't see how the frontend_changed code get there as we have:

770 /*

 771                  * Ensure we connect even when two watches fire in
 772                  * close succession and we miss the intermediate value
 773                  * of frontend_state.
 774                  */

775 if (dev->state == XenbusStateConnected)
776 break;
777

?

Now what about 'blkfront_connect' being called on the second time?

Ah, info->connected is probably by then in BLKIF_STATE_CONNECTED (as blkif_recover changed) and we just reread the size of the disk.

Is that how about the flow goes?

Quoted 23 lines
---
 drivers/block/xen-blkfront.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/xen-blkfront.c +2 -1
index ca13df8..01aa460 100644
@@ -2485,7 +2485,8 @@ static void blkback_changed(struct xenbus_device *dev,
 		break;
 
 	case XenbusStateConnected:
-		if (dev->state != XenbusStateInitialised) {
+		if ((dev->state != XenbusStateInitialised) &&
+			(dev->state != XenbusStateConnected)) {
 			if (talk_to_blkback(dev, info))
 				break;
 		}
Signature · 1 line
2.7.4
author
#5 lore raw
Quoted 25 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Bob Liu

Sometimes blkfont may receive twice blkback_changed() notification after migration, then talk_to_blkback() will be called twice too and confused xen-blkback.

Could you enlighten the patch description by having some form of state transition here? I am curious how you got the frontend to get in XenbusStateConnected (via blkif_recover right) and then the backend triggering the update once more?

Or is just a simple race - the backend moves from XenbusStateConnected-> XenbusStateConnected - which retriggers the frontend to hit in blkback_changed the XenbusStateConnected state and go in there? (That would be in conenct_ring changing the state). But I don't see how the frontend_changed code get there as we have:

770 /*

 771                  * Ensure we connect even when two watches fire in
 772                  * close succession and we miss the intermediate value
 773                  * of frontend_state.
 774                  */

775 if (dev->state == XenbusStateConnected)
776 break;
777

Quoted 8 lines

?

Now what about 'blkfront_connect' being called on the second time?

Ah, info->connected is probably by then in BLKIF_STATE_CONNECTED (as blkif_recover changed) and we just reread the size of the disk.

Is that how about the flow goes?

blkfront blkback
blkfront_resume()

Quoted 2 lines

talk_to_blkback()
Set blkfront to XenbusStateInitialised

Front changed()
> Connect()
> Set blkback to XenbusStateConnected

blkback_changed()

Quoted 1 line

Skip talk_to_blkback()

because frontstate == XenbusStateInitialised

Quoted 2 lines

blkfront_connect()
Set blkfront to XenbusStateConnected

------------------------------------------------------------------
But sometimes blkfront receives
blkback_changed() event more than once!
Not sure why.

blkback_changed()

Quoted 1 line

because now frontstate != XenbusStateInitialised

talk_to_blkback() is also called again

Quoted 1 line

blkfront state changed from

XenbusStateConnected to XenbusStateInitialised (Which is not correct!)

Front_changed():
> Do nothing because blkback
already in XenbusStateConnected

Now blkback is XenbusStateConnected but blkfront still XenbusStateInitialised.

Quoted 13 lines
Quoted 13 lines
---
 drivers/block/xen-blkfront.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/xen-blkfront.c +0 -0
index ca13df8..01aa460 100644
@@ -2485,7 +2485,8 @@ static void blkback_changed(struct xenbus_device *dev,
 		break;
 
Quoted 10 lines
Quoted 10 lines
drivers/block/xen-blkfront.c +2 -1
 	case XenbusStateConnected:
-		if (dev->state != XenbusStateInitialised) {
+		if ((dev->state != XenbusStateInitialised) &&
+			(dev->state != XenbusStateConnected)) {
 			if (talk_to_blkback(dev, info))
 				break;
 		}
Signature · 1 line
2.7.4

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

author
#6 lore raw
In reply to Konrad Rzeszutek Wilk
Quoted 25 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Bob Liu

Sometimes blkfont may receive twice blkback_changed() notification after migration, then talk_to_blkback() will be called twice too and confused xen-blkback.

Could you enlighten the patch description by having some form of state transition here? I am curious how you got the frontend to get in XenbusStateConnected (via blkif_recover right) and then the backend triggering the update once more?

Or is just a simple race - the backend moves from XenbusStateConnected-> XenbusStateConnected - which retriggers the frontend to hit in blkback_changed the XenbusStateConnected state and go in there? (That would be in conenct_ring changing the state). But I don't see how the frontend_changed code get there as we have:

770 /*

 771                  * Ensure we connect even when two watches fire in
 772                  * close succession and we miss the intermediate value
 773                  * of frontend_state.
 774                  */

775 if (dev->state == XenbusStateConnected)
776 break;
777

Quoted 8 lines

?

Now what about 'blkfront_connect' being called on the second time?

Ah, info->connected is probably by then in BLKIF_STATE_CONNECTED (as blkif_recover changed) and we just reread the size of the disk.

Is that how about the flow goes?

blkfront blkback
blkfront_resume()

Quoted 2 lines

talk_to_blkback()
Set blkfront to XenbusStateInitialised

Front changed()
> Connect()
> Set blkback to XenbusStateConnected

blkback_changed()

Quoted 1 line

Skip talk_to_blkback()

because frontstate == XenbusStateInitialised

Quoted 2 lines

blkfront_connect()
Set blkfront to XenbusStateConnected

------------------------------------------------------------------
But sometimes blkfront receives
blkback_changed() event more than once!
Not sure why.

blkback_changed()

Quoted 1 line

because now frontstate != XenbusStateInitialised

talk_to_blkback() is also called again

Quoted 1 line

blkfront state changed from

XenbusStateConnected to XenbusStateInitialised (Which is not correct!)

Front_changed():
> Do nothing because blkback
already in XenbusStateConnected

Now blkback is XenbusStateConnected but blkfront still XenbusStateInitialised.

Quoted 23 lines
Quoted 23 lines
---
 drivers/block/xen-blkfront.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/xen-blkfront.c +2 -1
index ca13df8..01aa460 100644
@@ -2485,7 +2485,8 @@ static void blkback_changed(struct xenbus_device *dev,
 		break;
 
 	case XenbusStateConnected:
-		if (dev->state != XenbusStateInitialised) {
+		if ((dev->state != XenbusStateInitialised) &&
+			(dev->state != XenbusStateConnected)) {
 			if (talk_to_blkback(dev, info))
 				break;
 		}
Signature · 1 line
2.7.4
#7 lore raw
Quoted 46 lines · Bob Liu
Quoted 25 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Bob Liu

Sometimes blkfont may receive twice blkback_changed() notification after migration, then talk_to_blkback() will be called twice too and confused xen-blkback.

Could you enlighten the patch description by having some form of state transition here? I am curious how you got the frontend to get in XenbusStateConnected (via blkif_recover right) and then the backend triggering the update once more?

Or is just a simple race - the backend moves from XenbusStateConnected-> XenbusStateConnected - which retriggers the frontend to hit in blkback_changed the XenbusStateConnected state and go in there? (That would be in conenct_ring changing the state). But I don't see how the frontend_changed code get there as we have:

770 /*

 771                  * Ensure we connect even when two watches fire in
 772                  * close succession and we miss the intermediate value
 773                  * of frontend_state.
 774                  */

775 if (dev->state == XenbusStateConnected)
776 break;
777

Quoted 8 lines

?

Now what about 'blkfront_connect' being called on the second time?

Ah, info->connected is probably by then in BLKIF_STATE_CONNECTED (as blkif_recover changed) and we just reread the size of the disk.

Is that how about the flow goes?

blkfront blkback
blkfront_resume()

Quoted 2 lines

talk_to_blkback()
Set blkfront to XenbusStateInitialised

Front changed()
> Connect()
> Set blkback to XenbusStateConnected

blkback_changed()

Quoted 1 line

Skip talk_to_blkback()

Quoted 8 lines

because frontstate == XenbusStateInitialised

Quoted 2 lines

blkfront_connect()
Set blkfront to XenbusStateConnected

------------------------------------------------------------------
But sometimes blkfront receives
blkback_changed() event more than once!

Could the control stack (xend) be doing this?

Quoted 10 lines

Not sure why.

blkback_changed()

Quoted 1 line

because now frontstate != XenbusStateInitialised

talk_to_blkback() is also called again

Quoted 1 line

blkfront state changed from

XenbusStateConnected to XenbusStateInitialised (Which is not correct!)

Quoted 6 lines

Front_changed():
> Do nothing because blkback
already in XenbusStateConnected

Now blkback is XenbusStateConnected but blkfront still XenbusStateInitialised.

Ah!

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
---
 drivers/block/xen-blkfront.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/xen-blkfront.c +0 -0
index ca13df8..01aa460 100644
@@ -2485,7 +2485,8 @@ static void blkback_changed(struct xenbus_device *dev,
 		break;
 
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/block/xen-blkfront.c +2 -1
 	case XenbusStateConnected:
-		if (dev->state != XenbusStateInitialised) {
+		if ((dev->state != XenbusStateInitialised) &&
+			(dev->state != XenbusStateConnected)) {
 			if (talk_to_blkback(dev, info))
 				break;
 		}
Signature · 1 line
2.7.4

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

#8 lore raw
In reply to Bob Liu
Quoted 46 lines · Bob Liu
Quoted 25 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Bob Liu

Sometimes blkfont may receive twice blkback_changed() notification after migration, then talk_to_blkback() will be called twice too and confused xen-blkback.

Could you enlighten the patch description by having some form of state transition here? I am curious how you got the frontend to get in XenbusStateConnected (via blkif_recover right) and then the backend triggering the update once more?

Or is just a simple race - the backend moves from XenbusStateConnected-> XenbusStateConnected - which retriggers the frontend to hit in blkback_changed the XenbusStateConnected state and go in there? (That would be in conenct_ring changing the state). But I don't see how the frontend_changed code get there as we have:

770 /*

 771                  * Ensure we connect even when two watches fire in
 772                  * close succession and we miss the intermediate value
 773                  * of frontend_state.
 774                  */

775 if (dev->state == XenbusStateConnected)
776 break;
777

Quoted 8 lines

?

Now what about 'blkfront_connect' being called on the second time?

Ah, info->connected is probably by then in BLKIF_STATE_CONNECTED (as blkif_recover changed) and we just reread the size of the disk.

Is that how about the flow goes?

blkfront blkback
blkfront_resume()

Quoted 2 lines

talk_to_blkback()
Set blkfront to XenbusStateInitialised

Front changed()
> Connect()
> Set blkback to XenbusStateConnected

blkback_changed()

Quoted 1 line

Skip talk_to_blkback()

Quoted 8 lines

because frontstate == XenbusStateInitialised

Quoted 2 lines

blkfront_connect()
Set blkfront to XenbusStateConnected

------------------------------------------------------------------
But sometimes blkfront receives
blkback_changed() event more than once!

Could the control stack (xend) be doing this?

Quoted 10 lines

Not sure why.

blkback_changed()

Quoted 1 line

because now frontstate != XenbusStateInitialised

talk_to_blkback() is also called again

Quoted 1 line

blkfront state changed from

XenbusStateConnected to XenbusStateInitialised (Which is not correct!)

Quoted 6 lines

Front_changed():
> Do nothing because blkback
already in XenbusStateConnected

Now blkback is XenbusStateConnected but blkfront still XenbusStateInitialised.

Ah!

Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
---
 drivers/block/xen-blkfront.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/xen-blkfront.c +2 -1
index ca13df8..01aa460 100644
@@ -2485,7 +2485,8 @@ static void blkback_changed(struct xenbus_device *dev,
 		break;
 
 	case XenbusStateConnected:
-		if (dev->state != XenbusStateInitialised) {
+		if ((dev->state != XenbusStateInitialised) &&
+			(dev->state != XenbusStateConnected)) {
 			if (talk_to_blkback(dev, info))
 				break;
 		}
Signature · 1 line
2.7.4
#9 lore raw
In reply to Bob Liu
Quoted 46 lines · Bob Liu
Quoted 25 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Bob Liu

Sometimes blkfont may receive twice blkback_changed() notification after migration, then talk_to_blkback() will be called twice too and confused xen-blkback.

Could you enlighten the patch description by having some form of state transition here? I am curious how you got the frontend to get in XenbusStateConnected (via blkif_recover right) and then the backend triggering the update once more?

Or is just a simple race - the backend moves from XenbusStateConnected-> XenbusStateConnected - which retriggers the frontend to hit in blkback_changed the XenbusStateConnected state and go in there? (That would be in conenct_ring changing the state). But I don't see how the frontend_changed code get there as we have:

770 /*

 771                  * Ensure we connect even when two watches fire in
 772                  * close succession and we miss the intermediate value
 773                  * of frontend_state.
 774                  */

775 if (dev->state == XenbusStateConnected)
776 break;
777

Quoted 8 lines

?

Now what about 'blkfront_connect' being called on the second time?

Ah, info->connected is probably by then in BLKIF_STATE_CONNECTED (as blkif_recover changed) and we just reread the size of the disk.

Is that how about the flow goes?

blkfront blkback
blkfront_resume()

Quoted 2 lines

talk_to_blkback()
Set blkfront to XenbusStateInitialised

Front changed()
> Connect()
> Set blkback to XenbusStateConnected

blkback_changed()

Quoted 1 line

Skip talk_to_blkback()

Quoted 8 lines

because frontstate == XenbusStateInitialised

Quoted 2 lines

blkfront_connect()
Set blkfront to XenbusStateConnected

------------------------------------------------------------------
But sometimes blkfront receives
blkback_changed() event more than once!

I think I know why. The udev scripts that get invoked when when we attach a disk are a bit custom. As such I think they just revalidate the size leading to this.

And this 'poke-at-XenbusStateConnected' state multiple times is allowed. It is used to signal disk changes (or just to revalidate). Hence it does not matter why really - we need to deal with this.

I modified your patch a bit and are testing it:

From e49dc9fc65eda4923b41d903ac51a7ddee182bcd Mon Sep 17 00:00:00 2001
From: Bob Liu <[email protected]>
Date: Tue, 7 Jun 2016 10:43:15 -0400
Subject: [PATCH] xen-blkfront: don't call talk_to_blkback when already
connected to blkback

Sometimes blkfront may twice receive blkback_changed() notification (XenbusStateConnected) after migration, which will cause talk_to_blkback() to be called twice too and confuse xen-blkback.

The flow is as follow:
blkfront blkback
blkfront_resume()

Quoted 2 lines

talk_to_blkback()
Set blkfront to XenbusStateInitialised

front changed()
> Connect()
> Set blkback to XenbusStateConnected

blkback_changed()

Quoted 1 line

Skip talk_to_blkback()

because frontstate == XenbusStateInitialised

Quoted 2 lines

blkfront_connect()
Set blkfront to XenbusStateConnected

-----
And here we get another XenbusStateConnected notification leading to:
-----
blkback_changed()

Quoted 1 line

because now frontstate != XenbusStateInitialised

talk_to_blkback() is also called again

Quoted 1 line

blkfront state changed from

XenbusStateConnected to XenbusStateInitialised
(Which is not correct!)

front_changed():
> Do nothing because blkback
already in XenbusStateConnected

Now blkback is in XenbusStateConnected but blkfront is still in XenbusStateInitialised - leading to no disks.

Poking of the XenbusStateConnected state is allowed (to deal with block disk change) and has to be dealt with. The most likely cause of this bug are custom udev scripts hooking up the disks and then validating the size.

---
 drivers/block/xen-blkfront.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/block/xen-blkfront.c +14 -1
index b4b8fbd..7765ad5 100644
@@ -2484,10 +2484,23 @@ static void blkback_changed(struct xenbus_device *dev,
 		break;
 
 	case XenbusStateConnected:
-		if (dev->state != XenbusStateInitialised) {
+		/*
+		 * talk_to_blkback sets state to XenbusStateInitialised
+		 * and blkfront_connect sets it to XenbusStateConnected
+		 * (if connection went OK).
+		 *
+		 * If the backend (or toolstack) decides to poke at backend
+		 * state (and re-trigger the watch by setting the state repeatedly
+		 * to XenbusStateConnected (4)) we need to deal with this.
+		 * This is allowed as this is used to communicate to the guest
+		 * that the size of disk has changed!
+		 */
+		if ((dev->state != XenbusStateInitialised) &&
+		    (dev->state != XenbusStateConnected)) {
 			if (talk_to_blkback(dev, info))
 				break;
 		}
+
 		blkfront_connect(info);
 		break;
 
Signature · 7 lines
2.4.11


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#10 lore raw
In reply to Bob Liu
Quoted 46 lines · Bob Liu
Quoted 25 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Bob Liu

Sometimes blkfont may receive twice blkback_changed() notification after migration, then talk_to_blkback() will be called twice too and confused xen-blkback.

Could you enlighten the patch description by having some form of state transition here? I am curious how you got the frontend to get in XenbusStateConnected (via blkif_recover right) and then the backend triggering the update once more?

Or is just a simple race - the backend moves from XenbusStateConnected-> XenbusStateConnected - which retriggers the frontend to hit in blkback_changed the XenbusStateConnected state and go in there? (That would be in conenct_ring changing the state). But I don't see how the frontend_changed code get there as we have:

770 /*

 771                  * Ensure we connect even when two watches fire in
 772                  * close succession and we miss the intermediate value
 773                  * of frontend_state.
 774                  */

775 if (dev->state == XenbusStateConnected)
776 break;
777

Quoted 8 lines

?

Now what about 'blkfront_connect' being called on the second time?

Ah, info->connected is probably by then in BLKIF_STATE_CONNECTED (as blkif_recover changed) and we just reread the size of the disk.

Is that how about the flow goes?

blkfront blkback
blkfront_resume()

Quoted 2 lines

talk_to_blkback()
Set blkfront to XenbusStateInitialised

Front changed()
> Connect()
> Set blkback to XenbusStateConnected

blkback_changed()

Quoted 1 line

Skip talk_to_blkback()

Quoted 8 lines

because frontstate == XenbusStateInitialised

Quoted 2 lines

blkfront_connect()
Set blkfront to XenbusStateConnected

------------------------------------------------------------------
But sometimes blkfront receives
blkback_changed() event more than once!

I think I know why. The udev scripts that get invoked when when we attach a disk are a bit custom. As such I think they just revalidate the size leading to this.

And this 'poke-at-XenbusStateConnected' state multiple times is allowed. It is used to signal disk changes (or just to revalidate). Hence it does not matter why really - we need to deal with this.

I modified your patch a bit and are testing it:

Quoted 1 line

From e49dc9fc65eda4923b41d903ac51a7ddee182bcd Mon Sep 17 00:00:00 2001

From: Bob Liu <[email protected]>
Date: Tue, 7 Jun 2016 10:43:15 -0400
Subject: [PATCH] xen-blkfront: don't call talk_to_blkback when already
connected to blkback

Sometimes blkfront may twice receive blkback_changed() notification (XenbusStateConnected) after migration, which will cause talk_to_blkback() to be called twice too and confuse xen-blkback.

The flow is as follow:
blkfront blkback
blkfront_resume()

Quoted 2 lines

talk_to_blkback()
Set blkfront to XenbusStateInitialised

front changed()
> Connect()
> Set blkback to XenbusStateConnected

blkback_changed()

Quoted 1 line

Skip talk_to_blkback()

because frontstate == XenbusStateInitialised

Quoted 2 lines

blkfront_connect()
Set blkfront to XenbusStateConnected

-----
And here we get another XenbusStateConnected notification leading to:
-----
blkback_changed()

Quoted 1 line

because now frontstate != XenbusStateInitialised

talk_to_blkback() is also called again

Quoted 1 line

blkfront state changed from

XenbusStateConnected to XenbusStateInitialised
(Which is not correct!)

front_changed():
> Do nothing because blkback
already in XenbusStateConnected

Now blkback is in XenbusStateConnected but blkfront is still in XenbusStateInitialised - leading to no disks.

Poking of the XenbusStateConnected state is allowed (to deal with block disk change) and has to be dealt with. The most likely cause of this bug are custom udev scripts hooking up the disks and then validating the size.

---
 drivers/block/xen-blkfront.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/block/xen-blkfront.c +14 -1
index b4b8fbd..7765ad5 100644
@@ -2484,10 +2484,23 @@ static void blkback_changed(struct xenbus_device *dev,
 		break;
 
 	case XenbusStateConnected:
-		if (dev->state != XenbusStateInitialised) {
+		/*
+		 * talk_to_blkback sets state to XenbusStateInitialised
+		 * and blkfront_connect sets it to XenbusStateConnected
+		 * (if connection went OK).
+		 *
+		 * If the backend (or toolstack) decides to poke at backend
+		 * state (and re-trigger the watch by setting the state repeatedly
+		 * to XenbusStateConnected (4)) we need to deal with this.
+		 * This is allowed as this is used to communicate to the guest
+		 * that the size of disk has changed!
+		 */
+		if ((dev->state != XenbusStateInitialised) &&
+		    (dev->state != XenbusStateConnected)) {
 			if (talk_to_blkback(dev, info))
 				break;
 		}
+
 		blkfront_connect(info);
 		break;
 
Signature · 1 line
2.4.11
author
#11 lore raw
Quoted 60 lines · Konrad Rzeszutek Wilk
Quoted 46 lines · Bob Liu
Quoted 25 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Bob Liu

Sometimes blkfont may receive twice blkback_changed() notification after migration, then talk_to_blkback() will be called twice too and confused xen-blkback.

Could you enlighten the patch description by having some form of state transition here? I am curious how you got the frontend to get in XenbusStateConnected (via blkif_recover right) and then the backend triggering the update once more?

Or is just a simple race - the backend moves from XenbusStateConnected-> XenbusStateConnected - which retriggers the frontend to hit in blkback_changed the XenbusStateConnected state and go in there? (That would be in conenct_ring changing the state). But I don't see how the frontend_changed code get there as we have:

770 /*

 771                  * Ensure we connect even when two watches fire in
 772                  * close succession and we miss the intermediate value
 773                  * of frontend_state.
 774                  */

775 if (dev->state == XenbusStateConnected)
776 break;
777

Quoted 8 lines

?

Now what about 'blkfront_connect' being called on the second time?

Ah, info->connected is probably by then in BLKIF_STATE_CONNECTED (as blkif_recover changed) and we just reread the size of the disk.

Is that how about the flow goes?

blkfront blkback
blkfront_resume()

Quoted 2 lines

talk_to_blkback()
Set blkfront to XenbusStateInitialised

Front changed()
> Connect()
> Set blkback to XenbusStateConnected

blkback_changed()

Quoted 1 line

Skip talk_to_blkback()

Quoted 8 lines

because frontstate == XenbusStateInitialised

Quoted 2 lines

blkfront_connect()
Set blkfront to XenbusStateConnected

------------------------------------------------------------------
But sometimes blkfront receives
blkback_changed() event more than once!

I think I know why. The udev scripts that get invoked when when we attach a disk are a bit custom. As such I think they just revalidate the size leading to this.

Quoted 6 lines

And this 'poke-at-XenbusStateConnected' state multiple times is allowed. It is used to signal disk changes (or just to revalidate). Hence it does not matter why really - we need to deal with this.

I modified your patch a bit and are testing it:

Looks much better, thank you very much!

Bob

Quoted 84 lines

From e49dc9fc65eda4923b41d903ac51a7ddee182bcd Mon Sep 17 00:00:00 2001
From: Bob Liu <[email protected]>
Date: Tue, 7 Jun 2016 10:43:15 -0400
Subject: [PATCH] xen-blkfront: don't call talk_to_blkback when already
connected to blkback

Sometimes blkfront may twice receive blkback_changed() notification (XenbusStateConnected) after migration, which will cause talk_to_blkback() to be called twice too and confuse xen-blkback.

The flow is as follow:
blkfront blkback
blkfront_resume()

Quoted 2 lines

talk_to_blkback()
Set blkfront to XenbusStateInitialised

front changed()
> Connect()
> Set blkback to XenbusStateConnected

blkback_changed()

Quoted 1 line

Skip talk_to_blkback()

because frontstate == XenbusStateInitialised

Quoted 2 lines

blkfront_connect()
Set blkfront to XenbusStateConnected

-----
And here we get another XenbusStateConnected notification leading to:
-----
blkback_changed()

Quoted 1 line

because now frontstate != XenbusStateInitialised

talk_to_blkback() is also called again

Quoted 1 line

blkfront state changed from

XenbusStateConnected to XenbusStateInitialised
(Which is not correct!)

front_changed():
> Do nothing because blkback
already in XenbusStateConnected

Now blkback is in XenbusStateConnected but blkfront is still in XenbusStateInitialised - leading to no disks.

Poking of the XenbusStateConnected state is allowed (to deal with block disk change) and has to be dealt with. The most likely cause of this bug are custom udev scripts hooking up the disks and then validating the size.

---
 drivers/block/xen-blkfront.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/block/xen-blkfront.c +14 -1
index b4b8fbd..7765ad5 100644
@@ -2484,10 +2484,23 @@ static void blkback_changed(struct xenbus_device *dev,
 		break;
 
 	case XenbusStateConnected:
-		if (dev->state != XenbusStateInitialised) {
+		/*
+		 * talk_to_blkback sets state to XenbusStateInitialised
+		 * and blkfront_connect sets it to XenbusStateConnected
+		 * (if connection went OK).
+		 *
+		 * If the backend (or toolstack) decides to poke at backend
+		 * state (and re-trigger the watch by setting the state repeatedly
+		 * to XenbusStateConnected (4)) we need to deal with this.
+		 * This is allowed as this is used to communicate to the guest
+		 * that the size of disk has changed!
+		 */
+		if ((dev->state != XenbusStateInitialised) &&
+		    (dev->state != XenbusStateConnected)) {
 			if (talk_to_blkback(dev, info))
 				break;
 		}
+
 		blkfront_connect(info);
 		break;
 
#12 lore raw
Quoted 62 lines · Bob Liu
Quoted 60 lines · Konrad Rzeszutek Wilk
Quoted 46 lines · Bob Liu
Quoted 25 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Bob Liu

Sometimes blkfont may receive twice blkback_changed() notification after migration, then talk_to_blkback() will be called twice too and confused xen-blkback.

Could you enlighten the patch description by having some form of state transition here? I am curious how you got the frontend to get in XenbusStateConnected (via blkif_recover right) and then the backend triggering the update once more?

Or is just a simple race - the backend moves from XenbusStateConnected-> XenbusStateConnected - which retriggers the frontend to hit in blkback_changed the XenbusStateConnected state and go in there? (That would be in conenct_ring changing the state). But I don't see how the frontend_changed code get there as we have:

770 /*

 771                  * Ensure we connect even when two watches fire in
 772                  * close succession and we miss the intermediate value
 773                  * of frontend_state.
 774                  */

775 if (dev->state == XenbusStateConnected)
776 break;
777

Quoted 8 lines

?

Now what about 'blkfront_connect' being called on the second time?

Ah, info->connected is probably by then in BLKIF_STATE_CONNECTED (as blkif_recover changed) and we just reread the size of the disk.

Is that how about the flow goes?

blkfront blkback
blkfront_resume()

Quoted 2 lines

talk_to_blkback()
Set blkfront to XenbusStateInitialised

Front changed()
> Connect()
> Set blkback to XenbusStateConnected

blkback_changed()

Quoted 1 line

Skip talk_to_blkback()

Quoted 8 lines

because frontstate == XenbusStateInitialised

Quoted 2 lines

blkfront_connect()
Set blkfront to XenbusStateConnected

------------------------------------------------------------------
But sometimes blkfront receives
blkback_changed() event more than once!

I think I know why. The udev scripts that get invoked when when we attach a disk are a bit custom. As such I think they just revalidate the size leading to this.

Quoted 8 lines
Quoted 6 lines

And this 'poke-at-XenbusStateConnected' state multiple times is allowed. It is used to signal disk changes (or just to revalidate). Hence it does not matter why really - we need to deal with this.

I modified your patch a bit and are testing it:

Looks much better, thank you very much!

Great! I also had it tested overnight and there was no hitch will send it out soon.

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

#13 lore raw
In reply to Bob Liu
Quoted 62 lines · Bob Liu
Quoted 60 lines · Konrad Rzeszutek Wilk
Quoted 46 lines · Bob Liu
Quoted 25 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Bob Liu

Sometimes blkfont may receive twice blkback_changed() notification after migration, then talk_to_blkback() will be called twice too and confused xen-blkback.

Could you enlighten the patch description by having some form of state transition here? I am curious how you got the frontend to get in XenbusStateConnected (via blkif_recover right) and then the backend triggering the update once more?

Or is just a simple race - the backend moves from XenbusStateConnected-> XenbusStateConnected - which retriggers the frontend to hit in blkback_changed the XenbusStateConnected state and go in there? (That would be in conenct_ring changing the state). But I don't see how the frontend_changed code get there as we have:

770 /*

 771                  * Ensure we connect even when two watches fire in
 772                  * close succession and we miss the intermediate value
 773                  * of frontend_state.
 774                  */

775 if (dev->state == XenbusStateConnected)
776 break;
777

Quoted 8 lines

?

Now what about 'blkfront_connect' being called on the second time?

Ah, info->connected is probably by then in BLKIF_STATE_CONNECTED (as blkif_recover changed) and we just reread the size of the disk.

Is that how about the flow goes?

blkfront blkback
blkfront_resume()

Quoted 2 lines

talk_to_blkback()
Set blkfront to XenbusStateInitialised

Front changed()
> Connect()
> Set blkback to XenbusStateConnected

blkback_changed()

Quoted 1 line

Skip talk_to_blkback()

Quoted 8 lines

because frontstate == XenbusStateInitialised

Quoted 2 lines

blkfront_connect()
Set blkfront to XenbusStateConnected

------------------------------------------------------------------
But sometimes blkfront receives
blkback_changed() event more than once!

I think I know why. The udev scripts that get invoked when when we attach a disk are a bit custom. As such I think they just revalidate the size leading to this.

Quoted 8 lines
Quoted 6 lines

And this 'poke-at-XenbusStateConnected' state multiple times is allowed. It is used to signal disk changes (or just to revalidate). Hence it does not matter why really - we need to deal with this.

I modified your patch a bit and are testing it:

Looks much better, thank you very much!

Great! I also had it tested overnight and there was no hitch will send it out soon.

#14 lore raw
Quoted 11 lines · Konrad Rzeszutek Wilk
Quoted 10 lines · Bob Liu
Quoted 8 lines · Konrad Rzeszutek Wilk
Quoted 7 lines · Bob Liu
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Bob Liu

Sometimes blkfont may receive twice blkback_changed() notification after migration, then talk_to_blkback() will be called twice too and confused xen-blkback.

... snip

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 2 lines

But sometimes blkfront receives
blkback_changed() event more than once!

I think I know why. The udev scripts that get invoked when when we attach a disk are a bit custom. As such I think they just revalidate the size leading to this.

And this 'poke-at-XenbusStateConnected' state multiple times is allowed. It is used to signal disk changes (or just to revalidate). Hence it does not matter why really - we need to deal with this.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

I modified your patch a bit and are testing it:

Looks much better, thank you very much!

Great! I also had it tested overnight and there was no hitch will send it out soon.

I'd like to request that this patch is backported to Linux 4.5 and both of the patches in this series are backported to Linux 4.6. This is affecting Debian Testing (using Linux 4.6). It fails to recover its disk when resuming or migrating.

Thanks,

Signature · 1 line
Ross Lagerwall
#15 lore raw
Quoted 29 lines · Ross Lagerwall
Quoted 11 lines · Konrad Rzeszutek Wilk
Quoted 10 lines · Bob Liu
Quoted 8 lines · Konrad Rzeszutek Wilk
Quoted 7 lines · Bob Liu
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Bob Liu

Sometimes blkfont may receive twice blkback_changed() notification after migration, then talk_to_blkback() will be called twice too and confused xen-blkback.

... snip

Quoted 16 lines
Quoted 15 lines
Quoted 7 lines
Quoted 2 lines

But sometimes blkfront receives
blkback_changed() event more than once!

I think I know why. The udev scripts that get invoked when when we attach a disk are a bit custom. As such I think they just revalidate the size leading to this.

Quoted 6 lines

And this 'poke-at-XenbusStateConnected' state multiple times is allowed. It is used to signal disk changes (or just to revalidate). Hence it does not matter why really - we need to deal with this.

I modified your patch a bit and are testing it:

Looks much better, thank you very much!

Quoted 8 lines
Quoted 3 lines

Great! I also had it tested overnight and there was no hitch will send it out soon.

I'd like to request that this patch is backported to Linux 4.5 and both of the patches in this series are backported to Linux 4.6. This is affecting Debian Testing (using Linux 4.6). It fails to recover its disk when resuming or migrating.

Good idea. Done.

Quoted 4 lines

Thanks,

Signature · 1 line
Ross Lagerwall

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

#16 lore raw
In reply to Ross Lagerwall
Quoted 29 lines · Ross Lagerwall
Quoted 11 lines · Konrad Rzeszutek Wilk
Quoted 10 lines · Bob Liu
Quoted 8 lines · Konrad Rzeszutek Wilk
Quoted 7 lines · Bob Liu
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Bob Liu

Sometimes blkfont may receive twice blkback_changed() notification after migration, then talk_to_blkback() will be called twice too and confused xen-blkback.

... snip

Quoted 16 lines
Quoted 15 lines
Quoted 7 lines
Quoted 2 lines

But sometimes blkfront receives
blkback_changed() event more than once!

I think I know why. The udev scripts that get invoked when when we attach a disk are a bit custom. As such I think they just revalidate the size leading to this.

Quoted 6 lines

And this 'poke-at-XenbusStateConnected' state multiple times is allowed. It is used to signal disk changes (or just to revalidate). Hence it does not matter why really - we need to deal with this.

I modified your patch a bit and are testing it:

Looks much better, thank you very much!

Quoted 8 lines
Quoted 3 lines

Great! I also had it tested overnight and there was no hitch will send it out soon.

I'd like to request that this patch is backported to Linux 4.5 and both of the patches in this series are backported to Linux 4.6. This is affecting Debian Testing (using Linux 4.6). It fails to recover its disk when resuming or migrating.

Good idea. Done.

Quoted 4 lines

Thanks,

Signature · 1 line
Ross Lagerwall
#17 lore raw
In reply to Konrad Rzeszutek Wilk
Quoted 11 lines · Konrad Rzeszutek Wilk
Quoted 10 lines · Bob Liu
Quoted 8 lines · Konrad Rzeszutek Wilk
Quoted 7 lines · Bob Liu
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Bob Liu

Sometimes blkfont may receive twice blkback_changed() notification after migration, then talk_to_blkback() will be called twice too and confused xen-blkback.

... snip

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 2 lines

But sometimes blkfront receives
blkback_changed() event more than once!

I think I know why. The udev scripts that get invoked when when we attach a disk are a bit custom. As such I think they just revalidate the size leading to this.

And this 'poke-at-XenbusStateConnected' state multiple times is allowed. It is used to signal disk changes (or just to revalidate). Hence it does not matter why really - we need to deal with this.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

I modified your patch a bit and are testing it:

Looks much better, thank you very much!

Great! I also had it tested overnight and there was no hitch will send it out soon.

I'd like to request that this patch is backported to Linux 4.5 and both of the patches in this series are backported to Linux 4.6. This is affecting Debian Testing (using Linux 4.6). It fails to recover its disk when resuming or migrating.

Thanks,

Signature · 6 lines
Ross Lagerwall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#18 lore raw
In reply to Konrad Rzeszutek Wilk
Quoted 60 lines · Konrad Rzeszutek Wilk
Quoted 46 lines · Bob Liu
Quoted 25 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Bob Liu

Sometimes blkfont may receive twice blkback_changed() notification after migration, then talk_to_blkback() will be called twice too and confused xen-blkback.

Could you enlighten the patch description by having some form of state transition here? I am curious how you got the frontend to get in XenbusStateConnected (via blkif_recover right) and then the backend triggering the update once more?

Or is just a simple race - the backend moves from XenbusStateConnected-> XenbusStateConnected - which retriggers the frontend to hit in blkback_changed the XenbusStateConnected state and go in there? (That would be in conenct_ring changing the state). But I don't see how the frontend_changed code get there as we have:

770 /*

 771                  * Ensure we connect even when two watches fire in
 772                  * close succession and we miss the intermediate value
 773                  * of frontend_state.
 774                  */

775 if (dev->state == XenbusStateConnected)
776 break;
777

Quoted 8 lines

?

Now what about 'blkfront_connect' being called on the second time?

Ah, info->connected is probably by then in BLKIF_STATE_CONNECTED (as blkif_recover changed) and we just reread the size of the disk.

Is that how about the flow goes?

blkfront blkback
blkfront_resume()

Quoted 2 lines

talk_to_blkback()
Set blkfront to XenbusStateInitialised

Front changed()
> Connect()
> Set blkback to XenbusStateConnected

blkback_changed()

Quoted 1 line

Skip talk_to_blkback()

Quoted 8 lines

because frontstate == XenbusStateInitialised

Quoted 2 lines

blkfront_connect()
Set blkfront to XenbusStateConnected

------------------------------------------------------------------
But sometimes blkfront receives
blkback_changed() event more than once!

I think I know why. The udev scripts that get invoked when when we attach a disk are a bit custom. As such I think they just revalidate the size leading to this.

Quoted 6 lines

And this 'poke-at-XenbusStateConnected' state multiple times is allowed. It is used to signal disk changes (or just to revalidate). Hence it does not matter why really - we need to deal with this.

I modified your patch a bit and are testing it:

Looks much better, thank you very much!

Bob

Quoted 74 lines

From e49dc9fc65eda4923b41d903ac51a7ddee182bcd Mon Sep 17 00:00:00 2001
From: Bob Liu <[email protected]>
Date: Tue, 7 Jun 2016 10:43:15 -0400
Subject: [PATCH] xen-blkfront: don't call talk_to_blkback when already
connected to blkback

Sometimes blkfront may twice receive blkback_changed() notification (XenbusStateConnected) after migration, which will cause talk_to_blkback() to be called twice too and confuse xen-blkback.

The flow is as follow:
blkfront blkback
blkfront_resume()

Quoted 2 lines

talk_to_blkback()
Set blkfront to XenbusStateInitialised

front changed()
> Connect()
> Set blkback to XenbusStateConnected

blkback_changed()

Quoted 1 line

Skip talk_to_blkback()

because frontstate == XenbusStateInitialised

Quoted 2 lines

blkfront_connect()
Set blkfront to XenbusStateConnected

-----
And here we get another XenbusStateConnected notification leading to:
-----
blkback_changed()

Quoted 1 line

because now frontstate != XenbusStateInitialised

talk_to_blkback() is also called again

Quoted 1 line

blkfront state changed from

XenbusStateConnected to XenbusStateInitialised
(Which is not correct!)

front_changed():
> Do nothing because blkback
already in XenbusStateConnected

Now blkback is in XenbusStateConnected but blkfront is still in XenbusStateInitialised - leading to no disks.

Poking of the XenbusStateConnected state is allowed (to deal with block disk change) and has to be dealt with. The most likely cause of this bug are custom udev scripts hooking up the disks and then validating the size.

---
 drivers/block/xen-blkfront.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/block/xen-blkfront.c +10 -1
index b4b8fbd..7765ad5 100644
@@ -2484,10 +2484,23 @@ static void blkback_changed(struct xenbus_device *dev,
 		break;
 
 	case XenbusStateConnected:
-		if (dev->state != XenbusStateInitialised) {
+		/*
+		 * talk_to_blkback sets state to XenbusStateInitialised
+		 * and blkfront_connect sets it to XenbusStateConnected
+		 * (if connection went OK).
+		 *
+		 * If the backend (or toolstack) decides to poke at backend
+		 * state (and re-trigger the watch by setting the state repeatedly
+		 * to XenbusStateConnected (4)) we need to deal with this.
+		 * This is allowed as this is used to communicate to the guest
+		 * that the size of disk has changed!

drivers/block/xen-blkfront.c static void blkback_changed(struct xenbus_device *dev, · line 2506

Quoted 10 lines
drivers/block/xen-blkfront.c +4 -0
+		 */
+		if ((dev->state != XenbusStateInitialised) &&
+		    (dev->state != XenbusStateConnected)) {
 			if (talk_to_blkback(dev, info))
 				break;
 		}
+
 		blkfront_connect(info);
 		break;
 

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