mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Philipp Reisner <philipp.reisner@linbit.com>
To: linux-kernel@vger.kernel.org, Jens Axboe <axboe@kernel.dk>
Cc: drbd-dev@lists.linbit.com
Subject: [PATCH 01/16] drbd: Use the idr_for_each_entry() iterator instead of idr_for_each()
Date: Thu,  8 Sep 2011 14:45:22 +0200	[thread overview]
Message-ID: <1315485937-18989-2-git-send-email-philipp.reisner@linbit.com> (raw)
In-Reply-To: <1315485937-18989-1-git-send-email-philipp.reisner@linbit.com>

Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
---
 drivers/block/drbd/drbd_state.c |  149 +++++++++++++++++++--------------------
 1 files changed, 74 insertions(+), 75 deletions(-)

diff --git a/drivers/block/drbd/drbd_state.c b/drivers/block/drbd/drbd_state.c
index 9159043..e712da7 100644
--- a/drivers/block/drbd/drbd_state.c
+++ b/drivers/block/drbd/drbd_state.c
@@ -1360,9 +1360,6 @@ static void print_conn_state_change(struct drbd_tconn *tconn, enum drbd_conns oc
 }
 
 struct _is_valid_itr_params {
-	enum chg_state_flags flags;
-	union drbd_state mask, val;
-	union drbd_state ms; /* maximal state, over all mdevs */
 	enum drbd_conns oc;
 	enum {
 		OC_UNINITIALIZED,
@@ -1371,69 +1368,85 @@ struct _is_valid_itr_params {
 	} oc_state;
 };
 
-static int _is_valid_itr_fn(int vnr, void *p, void *data)
+static enum drbd_state_rv
+conn_is_valid_transition(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state val,
+			 enum chg_state_flags flags, struct _is_valid_itr_params *params)
 {
-	struct drbd_conf *mdev = (struct drbd_conf *)p;
-	struct _is_valid_itr_params *params = (struct _is_valid_itr_params *)data;
-	enum chg_state_flags flags = params->flags;
+	enum drbd_state_rv rv = SS_SUCCESS;
 	union drbd_state ns, os;
-	enum drbd_state_rv rv;
-
-	os = mdev->state;
-	ns = apply_mask_val(os, params->mask, params->val);
-	ns = sanitize_state(mdev, ns, NULL);
-	rv = is_valid_state(mdev, ns);
+	struct drbd_conf *mdev;
+	int vnr;
 
-	if (rv < SS_SUCCESS) {
-		/* If the old state was illegal as well, then let this happen...*/
+	params->oc_state = OC_UNINITIALIZED;
+	idr_for_each_entry(&tconn->volumes, mdev, vnr) {
+		os = mdev->state;
+		ns = sanitize_state(mdev, apply_mask_val(os, mask, val), NULL);
+
+		switch (params->oc_state) {
+		case OC_UNINITIALIZED:
+			params->oc = os.conn;
+			params->oc_state = OC_CONSISTENT;
+			break;
+		case OC_CONSISTENT:
+			if (params->oc != os.conn)
+				params->oc_state = OC_INCONSISTENT;
+			break;
+		case OC_INCONSISTENT:
+			break;
+		}
 
-		if (is_valid_state(mdev, os) == rv)
-			rv = is_valid_soft_transition(os, ns);
-	} else
-		rv = is_valid_soft_transition(os, ns);
+		if (ns.i == os.i)
+			continue;
 
-	switch (params->oc_state) {
-	case OC_UNINITIALIZED:
-		params->oc = os.conn;
-		params->oc_state = OC_CONSISTENT;
-		break;
-	case OC_CONSISTENT:
-		if (params->oc != os.conn)
-			params->oc_state = OC_INCONSISTENT;
-		break;
-	case OC_INCONSISTENT:
-		break;
+		rv = is_valid_transition(os, ns);
+		if (rv < SS_SUCCESS)
+			break;
+
+		if (!(flags & CS_HARD)) {
+			rv = is_valid_state(mdev, ns);
+			if (rv < SS_SUCCESS) {
+				if (is_valid_state(mdev, os) == rv)
+					rv = is_valid_soft_transition(os, ns);
+			} else
+				rv = is_valid_soft_transition(os, ns);
+		}
+		if (rv < SS_SUCCESS)
+			break;
 	}
 
-	if (rv < SS_SUCCESS) {
-		if (flags & CS_VERBOSE)
-			print_st_err(mdev, os, ns, rv);
-		return rv;
-	} else
-		return 0;
+	if (rv < SS_SUCCESS && flags & CS_VERBOSE)
+		print_st_err(mdev, os, ns, rv);
+
+	return rv;
 }
 
-static int _set_state_itr_fn(int vnr, void *p, void *data)
+static union drbd_state
+conn_set_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state val,
+	       enum chg_state_flags flags)
 {
-	struct drbd_conf *mdev = (struct drbd_conf *)p;
-	struct _is_valid_itr_params *params = (struct _is_valid_itr_params *)data;
-	enum chg_state_flags flags = params->flags;
-	union drbd_state os, ns, ms = params->ms;
+	union drbd_state ns, os, ms = { };
+	struct drbd_conf *mdev;
 	enum drbd_state_rv rv;
+	int vnr;
 
-	os = mdev->state;
-	ns = apply_mask_val(os, params->mask, params->val);
-	ns = sanitize_state(mdev, ns, NULL);
+	tconn->cstate = val.conn;
 
-	rv = __drbd_set_state(mdev, ns, flags, NULL);
+	idr_for_each_entry(&tconn->volumes, mdev, vnr) {
+		os = mdev->state;
+		ns = apply_mask_val(os, mask, val);
+		ns = sanitize_state(mdev, ns, NULL);
 
-	ms.role = max_t(enum drbd_role, mdev->state.role, ms.role);
-	ms.peer = max_t(enum drbd_role, mdev->state.peer, ms.peer);
-	ms.disk = max_t(enum drbd_role, mdev->state.disk, ms.disk);
-	ms.pdsk = max_t(enum drbd_role, mdev->state.pdsk, ms.pdsk);
-	params->ms = ms;
+		rv = __drbd_set_state(mdev, ns, flags, NULL);
+		if (rv < SS_SUCCESS)
+			BUG();
 
-	return 0;
+		ms.role = max_t(enum drbd_role, mdev->state.role, ms.role);
+		ms.peer = max_t(enum drbd_role, mdev->state.peer, ms.peer);
+		ms.disk = max_t(enum drbd_disk_state, mdev->state.disk, ms.disk);
+		ms.pdsk = max_t(enum drbd_disk_state, mdev->state.pdsk, ms.pdsk);
+	}
+
+	return ms;
 }
 
 static enum drbd_state_rv
@@ -1449,18 +1462,14 @@ _conn_rq_cond(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state
 	if (test_and_clear_bit(CONN_WD_ST_CHG_FAIL, &tconn->flags))
 		return SS_CW_FAILED_BY_PEER;
 
-	params.flags = CS_NO_CSTATE_CHG; /* öö think */
-	params.mask = mask;
-	params.val = val;
-
 	spin_lock_irq(&tconn->req_lock);
 	rv = oc != C_WF_REPORT_PARAMS ? SS_CW_NO_NEED : SS_UNKNOWN_ERROR;
 
 	if (rv == SS_UNKNOWN_ERROR)
-		rv = idr_for_each(&tconn->volumes, _is_valid_itr_fn, &params);
+		rv = conn_is_valid_transition(tconn, mask, val, CS_NO_CSTATE_CHG, &params);
 
-	if (rv == 0)  /* idr_for_each semantics */
-		rv = SS_UNKNOWN_ERROR;  /* cont waiting, otherwise fail. */
+	if (rv == SS_SUCCESS)
+		rv = SS_UNKNOWN_ERROR; /* cont waiting, otherwise fail. */
 
 	spin_unlock_irq(&tconn->req_lock);
 
@@ -1500,22 +1509,13 @@ _conn_request_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_
 	struct _is_valid_itr_params params;
 	struct after_conn_state_chg_work *acscw;
 	enum drbd_conns oc = tconn->cstate;
+	union drbd_state ms;
 
 	rv = is_valid_conn_transition(oc, val.conn);
 	if (rv < SS_SUCCESS)
 		goto abort;
 
-	params.flags = flags;
-	params.mask = mask;
-	params.val = val;
-	params.oc_state = OC_UNINITIALIZED;
-
-	if (!(flags & CS_HARD))
-		rv = idr_for_each(&tconn->volumes, _is_valid_itr_fn, &params);
-
-	if (rv == 0)  /* idr_for_each semantics */
-		rv = SS_SUCCESS;
-
+	rv = conn_is_valid_transition(tconn, mask, val, flags, &params);
 	if (rv < SS_SUCCESS)
 		goto abort;
 
@@ -1528,17 +1528,16 @@ _conn_request_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_
 	if (params.oc_state == OC_CONSISTENT) {
 		oc = params.oc;
 		print_conn_state_change(tconn, oc, val.conn);
-		params.flags |= CS_NO_CSTATE_CHG;
+		flags |= CS_NO_CSTATE_CHG;
 	}
-	tconn->cstate = val.conn;
-	params.ms.i = 0;
-	params.ms.conn = val.conn;
-	idr_for_each(&tconn->volumes, _set_state_itr_fn, &params);
+
+	ms = conn_set_state(tconn, mask, val, flags);
+	ms.conn = val.conn;
 
 	acscw = kmalloc(sizeof(*acscw), GFP_ATOMIC);
 	if (acscw) {
 		acscw->oc = oc;
-		acscw->nms = params.ms;
+		acscw->nms = ms;
 		acscw->flags = flags;
 		acscw->w.cb = w_after_conn_state_ch;
 		acscw->w.tconn = tconn;
-- 
1.7.4.1


  reply	other threads:[~2011-09-08 12:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-08 12:45 [RFC 00/16] drbd: part 8 of adding multiple volume support to drbd Philipp Reisner
2011-09-08 12:45 ` Philipp Reisner [this message]
2011-09-08 12:45 ` [PATCH 02/16] drbd: Fixed logging of old connection state Philipp Reisner
2011-09-08 12:45 ` [PATCH 03/16] drbd: Print common state changes of all volumes as connection state changes Philipp Reisner
2011-09-08 12:45 ` [PATCH 04/16] drbd: Allow to disconnect if one volume is diskless Philipp Reisner
2011-09-08 12:45 ` [PATCH 05/16] drbd: Do not segfault if a sync dependency reaches a diskless device Philipp Reisner
2011-09-08 12:45 ` [PATCH 06/16] drbd: Pass struct packet_info down to the asender receive functions Philipp Reisner
2011-09-08 12:45 ` [PATCH 07/16] drbd: Map from (connection, volume number) to device in the asender handlers Philipp Reisner
2011-09-08 12:45 ` [PATCH 08/16] drbd: drbd_connect(): Initialize struct drbd_socket before sending anything Philipp Reisner
2011-09-08 12:45 ` [PATCH 09/16] drbd: _conn_send_cmd(), _drbd_send_cmd(): Pass a struct drbd_socket instead of a plain socket Philipp Reisner
2011-09-08 12:45 ` [PATCH 10/16] drbd: Change how the initial packets are called Philipp Reisner
2011-09-08 12:45 ` [PATCH 11/16] drbd: Change how the "handshake" " Philipp Reisner
2011-09-08 12:45 ` [PATCH 12/16] drbd: introduce the "initialized" activity log transaction type Philipp Reisner
2011-09-08 12:45 ` [PATCH 13/16] drbd: preparation commit, pass drbd_interval to drbd_al_begin/complete_io Philipp Reisner
2011-09-08 12:45 ` [PATCH 14/16] drbd: prepare to activate two activity log extents at once Philipp Reisner
2011-09-08 12:45 ` [PATCH 15/16] drbd: get rid of bio_split, allow bios of "arbitrary" size Philipp Reisner
2011-09-08 12:45 ` [PATCH 16/16] drbd: improvements to activate/deactivate multiple activity log extents Philipp Reisner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1315485937-18989-2-git-send-email-philipp.reisner@linbit.com \
    --to=philipp.reisner@linbit.com \
    --cc=axboe@kernel.dk \
    --cc=drbd-dev@lists.linbit.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®