Skip to contentSkip to conversation

More for the 3.18 merge window

PATCH Applied Philipp Reisner 2 participants 4 messages Sep 18, 2014

Subsystems (2)
lore
Share & tools
lore

Philipp Reisner

author maintainer
#0 lore raw

cover More for the 3.18 merge window

Hi Jens,

please put these two patches into your for-3.18/drivers branch. They fix the safety code for concurrent overlapping write detection in a DRBD dual primary setup.

The first of those two should also go to the stable kernels, I marked it with CC: [email protected]

Lai Jiangshan (2):
drbd: compute the end before rb_insert_augmented()
drbd: use RB_DECLARE_CALLBACKS() to define augment callbacks

 drivers/block/drbd/drbd_interval.c | 40 ++++++--------------------------------
 1 file changed, 6 insertions(+), 34 deletions(-)
Signature · 1 line
1.9.1
author maintainer
#1 lore raw

PATCH 1/2 drbd: compute the end before rb_insert_augmented()

From: Lai Jiangshan <[email protected]>

Commit 98683650 "Merge branch 'drbd-8.4_ed6' into for-3.8-drivers-drbd-8.4_ed6" switches to the new augment API, but the new API requires that the tree is augmented before rb_insert_augmented() is called, which is missing.

So we add the augment-code to drbd_insert_interval() when it travels the tree up to down before rb_insert_augmented(). See the example in include/linux/interval_tree_generic.h or Documentation/rbtree.txt.

drbd_insert_interval() may cancel the insertion when traveling, in this case, the just added augment-code does nothing before cancel since the @this node is already in the subtrees in this case.

---
 drivers/block/drbd/drbd_interval.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/block/drbd/drbd_interval.c +4 -0
index 89c497c..04a14e0 100644
@@ -79,6 +79,7 @@ bool
 drbd_insert_interval(struct rb_root *root, struct drbd_interval *this)
 {
 	struct rb_node **new = &root->rb_node, *parent = NULL;
+	sector_t this_end = this->sector + (this->size >> 9);
 
 	BUG_ON(!IS_ALIGNED(this->size, 512));
 
@@ -87,6 +88,8 @@ drbd_insert_interval(struct rb_root *root, struct drbd_interval *this)
 			rb_entry(*new, struct drbd_interval, rb);
 
 		parent = *new;
+		if (here->end < this_end)
+			here->end = this_end;
 		if (this->sector < here->sector)
 			new = &(*new)->rb_left;
 		else if (this->sector > here->sector)
@@ -99,6 +102,7 @@ drbd_insert_interval(struct rb_root *root, struct drbd_interval *this)
 			return false;
 	}
 
+	this->end = this_end;
 	rb_link_node(&this->rb, parent, new);
 	rb_insert_augmented(&this->rb, root, &augment_callbacks);
 	return true;
Signature · 1 line
1.9.1
author maintainer
#2 lore raw

PATCH 2/2 drbd: use RB_DECLARE_CALLBACKS() to define augment callbacks

In reply to Philipp Reisner

From: Lai Jiangshan <[email protected]>

The original code are the same as RB_DECLARE_CALLBACKS().

---
 drivers/block/drbd/drbd_interval.c | 36 ++----------------------------------
 1 file changed, 2 insertions(+), 34 deletions(-)
drivers/block/drbd/drbd_interval.c +2 -34
index 04a14e0..51b25ad 100644
@@ -37,40 +37,8 @@ compute_subtree_last(struct drbd_interval *node)
 	return max;
 }
 
-static void augment_propagate(struct rb_node *rb, struct rb_node *stop)
-{
-	while (rb != stop) {
-		struct drbd_interval *node = rb_entry(rb, struct drbd_interval, rb);
-		sector_t subtree_last = compute_subtree_last(node);
-		if (node->end == subtree_last)
-			break;
-		node->end = subtree_last;
-		rb = rb_parent(&node->rb);
-	}
-}
-
-static void augment_copy(struct rb_node *rb_old, struct rb_node *rb_new)
-{
-	struct drbd_interval *old = rb_entry(rb_old, struct drbd_interval, rb);
-	struct drbd_interval *new = rb_entry(rb_new, struct drbd_interval, rb);
-
-	new->end = old->end;
-}
-
-static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
-{
-	struct drbd_interval *old = rb_entry(rb_old, struct drbd_interval, rb);
-	struct drbd_interval *new = rb_entry(rb_new, struct drbd_interval, rb);
-
-	new->end = old->end;
-	old->end = compute_subtree_last(old);
-}
-
-static const struct rb_augment_callbacks augment_callbacks = {
-	augment_propagate,
-	augment_copy,
-	augment_rotate,
-};
+RB_DECLARE_CALLBACKS(static, augment_callbacks, struct drbd_interval, rb,
+		     sector_t, end, compute_subtree_last);
 
 /**
  * drbd_insert_interval  -  insert a new interval into a tree
Signature · 1 line
1.9.1
maintainer Applied
#3 lore raw
In reply to Philipp Reisner
Quoted 8 lines · Philipp Reisner

Hi Jens,

please put these two patches into your for-3.18/drivers branch. They fix the safety code for concurrent overlapping write detection in a DRBD dual primary setup.

The first of those two should also go to the stable kernels, I marked it with CC: [email protected]

Applied, thanks.

Signature · 1 line
Jens Axboe