Skip to contentSkip to conversation

drbd: part 5 of adding multiple volume support to drbd

RFC New Philipp Reisner 1 participant 17 messages Sep 2, 2011

Subsystems (2)
lore
Share & tools
lore

Philipp Reisner

author maintainer
#0 lore raw

cover drbd: part 5 of adding multiple volume support to drbd

This the first request for review of drbd-8.4. The complete set has 492 patches. This is the fifth installment containing 16 patches.

The whole set is available here:
git://git.drbd.org/linux-2.6-drbd.git for-jens

and is jens_for-3.2_drivers...for-jens
and this part is c807047...668659d

The most noticeable change is the support for multiple replicated volumes in a single DRBD connection. Write-ordering is obeyed among all writes in all volumes in a single connection. This feature is really important for users who use DRBD for mirroring over longer distances. (Protocol A).

author maintainer
#1 lore raw

PATCH 1/16 drbd: process_done_ee() has to handle unconfigured devices now

Took the chance and converted tconn_process_done_ee() to use idr_for_each_entry()

---
 drivers/block/drbd/drbd_receiver.c |   44 ++++++++++++++---------------------
 1 files changed, 18 insertions(+), 26 deletions(-)
drivers/block/drbd/drbd_receiver.c +18 -26
index c57ef9f..956a0e2 100644
@@ -404,7 +404,7 @@ static int drbd_process_done_ee(struct drbd_conf *mdev)
 	LIST_HEAD(work_list);
 	LIST_HEAD(reclaimed);
 	struct drbd_peer_request *peer_req, *t;
-	int ok = (mdev->state.conn >= C_WF_REPORT_PARAMS);
+	int ok = 1;
 
 	spin_lock_irq(&mdev->tconn->req_lock);
 	reclaim_net_ee(mdev, &reclaimed);
@@ -4670,37 +4670,27 @@ static int got_skip(struct drbd_conf *mdev, enum drbd_packet cmd)
 	return true;
 }
 
-static int _drbd_process_done_ee(int vnr, void *p, void *data)
-{
-	struct drbd_conf *mdev = (struct drbd_conf *)p;
-	return !drbd_process_done_ee(mdev);
-}
-
-static int _check_ee_empty(int vnr, void *p, void *data)
-{
-	struct drbd_conf *mdev = (struct drbd_conf *)p;
-	struct drbd_tconn *tconn = mdev->tconn;
-	int not_empty;
-
-	spin_lock_irq(&tconn->req_lock);
-	not_empty = !list_empty(&mdev->done_ee);
-	spin_unlock_irq(&tconn->req_lock);
-
-	return not_empty;
-}
-
 static int tconn_process_done_ee(struct drbd_tconn *tconn)
 {
-	int not_empty, err;
+	struct drbd_conf *mdev;
+	int i, not_empty = 0;
 
 	do {
 		clear_bit(SIGNAL_ASENDER, &tconn->flags);
 		flush_signals(current);
-		err = idr_for_each(&tconn->volumes, _drbd_process_done_ee, NULL);
-		if (err)
-			return err;
+		idr_for_each_entry(&tconn->volumes, mdev, i) {
+			if (!drbd_process_done_ee(mdev))
+				return 1; /* error */
+		}
 		set_bit(SIGNAL_ASENDER, &tconn->flags);
-		not_empty = idr_for_each(&tconn->volumes, _check_ee_empty, NULL);
+
+		spin_lock_irq(&tconn->req_lock);
+		idr_for_each_entry(&tconn->volumes, mdev, i) {
+			not_empty = !list_empty(&mdev->done_ee);
+			if (not_empty)
+				break;
+		}
+		spin_unlock_irq(&tconn->req_lock);
 	} while (not_empty);
 
 	return 0;
@@ -4762,8 +4752,10 @@ int drbd_asender(struct drbd_thread *thi)
 		   much to send */
 		if (!tconn->net_conf->no_cork)
 			drbd_tcp_cork(tconn->meta.socket);
-		if (tconn_process_done_ee(tconn))
+		if (tconn_process_done_ee(tconn)) {
+			conn_err(tconn, "tconn_process_done_ee() failed\n");
 			goto reconnect;
+		}
 		/* but unconditionally uncork unless disabled */
 		if (!tconn->net_conf->no_cork)
 			drbd_tcp_uncork(tconn->meta.socket);
Signature · 1 line
1.7.4.1
author maintainer
#2 lore raw

PATCH 2/16 drbd: New minors have to intherit the connection state form their connection

In reply to Philipp Reisner
---
 drivers/block/drbd/drbd_int.h      |    1 +
 drivers/block/drbd/drbd_main.c     |    5 +++++
 drivers/block/drbd/drbd_receiver.c |    5 +++--
 drivers/block/drbd/drbd_state.c    |    4 ++--
 4 files changed, 11 insertions(+), 4 deletions(-)
drivers/block/drbd/drbd_int.h +1 -0
index d84a073..05bb9fd 100644
@@ -1595,6 +1595,7 @@ extern void _drbd_wait_ee_list_empty(struct drbd_conf *mdev,
 extern void drbd_set_recv_tcq(struct drbd_conf *mdev, int tcq_enabled);
 extern void _drbd_clear_done_ee(struct drbd_conf *mdev, struct list_head *to_be_freed);
 extern void conn_flush_workqueue(struct drbd_tconn *tconn);
+extern int drbd_connected(int vnr, void *p, void *data);
 static inline void drbd_flush_workqueue(struct drbd_conf *mdev)
 {
 	conn_flush_workqueue(mdev->tconn);
drivers/block/drbd/drbd_main.c +5 -0
index de49c8d..4bfffe9 100644
@@ -2410,6 +2410,11 @@ enum drbd_ret_code conn_new_minor(struct drbd_tconn *tconn, unsigned int minor,
 	}
 	add_disk(disk);
 
+	/* inherit the connection state */
+	mdev->state.conn = tconn->cstate;
+	if (mdev->state.conn == C_WF_REPORT_PARAMS)
+		drbd_connected(vnr, mdev, tconn);
+
 	return NO_ERROR;
 
 out_idr_remove_vol:
drivers/block/drbd/drbd_receiver.c +3 -2
index 956a0e2..1c83a12 100644
@@ -744,8 +744,9 @@ static int drbd_socket_okay(struct socket **sock)
 		return false;
 	}
 }
-
-static int drbd_connected(int vnr, void *p, void *data)
+/* Gets called if a connection is established, or if a new minor gets created
+   in a connection */
+int drbd_connected(int vnr, void *p, void *data)
 {
 	struct drbd_conf *mdev = (struct drbd_conf *)p;
 	int ok = 1;
drivers/block/drbd/drbd_state.c +2 -2
index 3ca535e..37b52d7 100644
@@ -433,8 +433,8 @@ is_valid_soft_transition(union drbd_state os, union drbd_state ns)
 	if (ns.conn == C_DISCONNECTING && os.conn == C_UNCONNECTED)
 		rv = SS_IN_TRANSIENT_STATE;
 
-	if (ns.conn == os.conn && ns.conn == C_WF_REPORT_PARAMS)
-		rv = SS_IN_TRANSIENT_STATE;
+	/* if (ns.conn == os.conn && ns.conn == C_WF_REPORT_PARAMS)
+	   rv = SS_IN_TRANSIENT_STATE; */
 
 	if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) && os.conn < C_CONNECTED)
 		rv = SS_NEED_CONNECTION;
Signature · 1 line
1.7.4.1
author maintainer
#3 lore raw

PATCH 3/16 drbd: Allow two diskless minors to be connected

In reply to Philipp Reisner

In the context of drbd-8.4 it no longer makes sense to dissalow that.

---
 drivers/block/drbd/drbd_receiver.c |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)
drivers/block/drbd/drbd_receiver.c +0 -6
index 1c83a12..4eeba8f 100644
@@ -3133,12 +3133,6 @@ static int receive_sizes(struct drbd_conf *mdev, enum drbd_packet cmd,
 	p_size = be64_to_cpu(p->d_size);
 	p_usize = be64_to_cpu(p->u_size);
 
-	if (p_size == 0 && mdev->state.disk == D_DISKLESS) {
-		dev_err(DEV, "some backing storage is needed\n");
-		drbd_force_state(mdev, NS(conn, C_DISCONNECTING));
-		return false;
-	}
-
 	/* just store the peer's disk size for now.
 	 * we still need to figure out whether we accept that. */
 	mdev->p_size = p_size;
Signature · 1 line
1.7.4.1
author maintainer
#4 lore raw

PATCH 4/16 drbd: Do not modify the connection state with something else that conn_request_state()

In reply to Philipp Reisner
---
 drivers/block/drbd/drbd_actlog.c   |    2 +-
 drivers/block/drbd/drbd_receiver.c |   16 ++++++++--------
 drivers/block/drbd/drbd_worker.c   |   10 ++--------
 3 files changed, 11 insertions(+), 17 deletions(-)
drivers/block/drbd/drbd_actlog.c +1 -1
index 6d1e892..92a16ea 100644
@@ -759,7 +759,7 @@ static void drbd_try_clear_on_disk_bm(struct drbd_conf *mdev, sector_t sector,
 				dump_stack();
 
 				lc_put(mdev->resync, &ext->lce);
-				drbd_force_state(mdev, NS(conn, C_DISCONNECTING));
+				conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD);
 				return;
 			}
 		} else {
drivers/block/drbd/drbd_receiver.c +8 -8
index 4eeba8f..f239902 100644
@@ -2925,7 +2925,7 @@ static int receive_protocol(struct drbd_conf *mdev, enum drbd_packet cmd,
 	return true;
 
 disconnect:
-	drbd_force_state(mdev, NS(conn, C_DISCONNECTING));
+	conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD);
 	return false;
 }
 
@@ -3104,7 +3104,7 @@ disconnect:
 	crypto_free_hash(csums_tfm);
 	/* but free the verify_tfm again, if csums_tfm did not work out */
 	crypto_free_hash(verify_tfm);
-	drbd_force_state(mdev, NS(conn, C_DISCONNECTING));
+	conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD);
 	return false;
 }
 
@@ -3164,7 +3164,7 @@ static int receive_sizes(struct drbd_conf *mdev, enum drbd_packet cmd,
 		   mdev->state.disk >= D_OUTDATED &&
 		   mdev->state.conn < C_CONNECTED) {
 			dev_err(DEV, "The peer's disk size is too small!\n");
-			drbd_force_state(mdev, NS(conn, C_DISCONNECTING));
+			conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD);
 			mdev->ldev->dc.disk_size = my_usize;
 			put_ldev(mdev);
 			return false;
@@ -3240,7 +3240,7 @@ static int receive_uuids(struct drbd_conf *mdev, enum drbd_packet cmd,
 	    (mdev->ed_uuid & ~((u64)1)) != (p_uuid[UI_CURRENT] & ~((u64)1))) {
 		dev_err(DEV, "Can only connect to data with current UUID=%016llX\n",
 		    (unsigned long long)mdev->ed_uuid);
-		drbd_force_state(mdev, NS(conn, C_DISCONNECTING));
+		conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD);
 		return false;
 	}
 
@@ -3445,7 +3445,7 @@ static int receive_state(struct drbd_conf *mdev, enum drbd_packet cmd,
 				if (test_and_clear_bit(CONN_DRY_RUN, &mdev->flags))
 					return false;
 				D_ASSERT(os.conn == C_WF_REPORT_PARAMS);
-				drbd_force_state(mdev, NS(conn, C_DISCONNECTING));
+				conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD);
 				return false;
 			}
 		}
@@ -3470,7 +3470,7 @@ static int receive_state(struct drbd_conf *mdev, enum drbd_packet cmd,
 		tl_clear(mdev->tconn);
 		drbd_uuid_new_current(mdev);
 		clear_bit(NEW_CUR_UUID, &mdev->flags);
-		drbd_force_state(mdev, NS2(conn, C_PROTOCOL_ERROR, susp, 0));
+		conn_request_state(mdev->tconn, NS2(conn, C_PROTOCOL_ERROR, susp, 0), CS_HARD);
 		return false;
 	}
 	rv = _drbd_set_state(mdev, ns, cs_flags, NULL);
@@ -3478,7 +3478,7 @@ static int receive_state(struct drbd_conf *mdev, enum drbd_packet cmd,
 	spin_unlock_irq(&mdev->tconn->req_lock);
 
 	if (rv < SS_SUCCESS) {
-		drbd_force_state(mdev, NS(conn, C_DISCONNECTING));
+		conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD);
 		return false;
 	}
 
@@ -3651,7 +3651,7 @@ decode_bitmap_c(struct drbd_conf *mdev,
 	 * during all our tests. */
 
 	dev_err(DEV, "receive_bitmap_c: unknown encoding %u\n", p->encoding);
-	drbd_force_state(mdev, NS(conn, C_PROTOCOL_ERROR));
+	conn_request_state(mdev->tconn, NS(conn, C_PROTOCOL_ERROR), CS_HARD);
 	return -EIO;
 }
 
drivers/block/drbd/drbd_worker.c +2 -8
index e459cb2..a730520 100644
@@ -1290,12 +1290,6 @@ int w_send_read_req(struct drbd_work *w, int cancel)
 	ok = drbd_send_drequest(mdev, P_DATA_REQUEST, req->i.sector, req->i.size,
 				(unsigned long)req);
 
-	if (!ok) {
-		/* ?? we set C_TIMEOUT or C_BROKEN_PIPE in drbd_send();
-		 * so this is probably redundant */
-		if (mdev->state.conn >= C_CONNECTED)
-			drbd_force_state(mdev, NS(conn, C_NETWORK_FAILURE));
-	}
 	req_mod(req, ok ? HANDED_OVER_TO_NETWORK : SEND_FAILED);
 
 	return ok;
@@ -1510,7 +1504,7 @@ void drbd_start_resync(struct drbd_conf *mdev, enum drbd_conns side)
 			if (r > 0) {
 				dev_info(DEV, "before-resync-target handler returned %d, "
 					 "dropping connection.\n", r);
-				drbd_force_state(mdev, NS(conn, C_DISCONNECTING));
+				conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD);
 				return;
 			}
 		} else /* C_SYNC_SOURCE */ {
@@ -1523,7 +1517,7 @@ void drbd_start_resync(struct drbd_conf *mdev, enum drbd_conns side)
 				} else {
 					dev_info(DEV, "before-resync-source handler returned %d, "
 						 "dropping connection.\n", r);
-					drbd_force_state(mdev, NS(conn, C_DISCONNECTING));
+					conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD);
 					return;
 				}
 			}
Signature · 1 line
1.7.4.1
author maintainer
#5 lore raw

PATCH 5/16 drbd: Moved CONN_DRY_RUN to the per connection (tconn) flags

In reply to Philipp Reisner
---
 drivers/block/drbd/drbd_int.h      |    2 +-
 drivers/block/drbd/drbd_receiver.c |    8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/block/drbd/drbd_int.h +1 -1
index 05bb9fd..99b34f9 100644
@@ -791,7 +791,6 @@ enum {
 	RESYNC_AFTER_NEG,       /* Resync after online grow after the attach&negotiate finished. */
 	RESIZE_PENDING,		/* Size change detected locally, waiting for the response from
 				 * the peer, if it changed there as well. */
-	CONN_DRY_RUN,		/* Expect disconnect after resync handshake. */
 	NEW_CUR_UUID,		/* Create new current UUID when thawing IO */
 	AL_SUSPENDED,		/* Activity logging is currently suspended. */
 	AHEAD_TO_SYNC_SOURCE,   /* Ahead -> SyncSource queued */
@@ -915,6 +914,7 @@ enum {
 				 * but worker thread is still handling the cleanup.
 				 * reconfiguring (nl_disk_conf, nl_net_conf) is dissalowed,
 				 * while this is set. */
+	CONN_DRY_RUN,		/* Expect disconnect after resync handshake. */
 };
 
 struct drbd_tconn {			/* is a resource from the config file */
drivers/block/drbd/drbd_receiver.c +4 -4
index f239902..7bb5e5c 100644
@@ -2803,7 +2803,7 @@ static enum drbd_conns drbd_sync_handshake(struct drbd_conf *mdev, enum drbd_rol
 		}
 	}
 
-	if (mdev->tconn->net_conf->dry_run || test_bit(CONN_DRY_RUN, &mdev->flags)) {
+	if (mdev->tconn->net_conf->dry_run || test_bit(CONN_DRY_RUN, &mdev->tconn->flags)) {
 		if (hg == 0)
 			dev_info(DEV, "dry-run connect: No resync, would become Connected immediately.\n");
 		else
@@ -2872,10 +2872,10 @@ static int receive_protocol(struct drbd_conf *mdev, enum drbd_packet cmd,
 	cf		= be32_to_cpu(p->conn_flags);
 	p_want_lose = cf & CF_WANT_LOSE;
 
-	clear_bit(CONN_DRY_RUN, &mdev->flags);
+	clear_bit(CONN_DRY_RUN, &mdev->tconn->flags);
 
 	if (cf & CF_DRY_RUN)
-		set_bit(CONN_DRY_RUN, &mdev->flags);
+		set_bit(CONN_DRY_RUN, &mdev->tconn->flags);
 
 	if (p_proto != mdev->tconn->net_conf->wire_protocol) {
 		dev_err(DEV, "incompatible communication protocols\n");
@@ -3442,7 +3442,7 @@ static int receive_state(struct drbd_conf *mdev, enum drbd_packet cmd,
 				peer_state.disk = D_DISKLESS;
 				real_peer_disk = D_DISKLESS;
 			} else {
-				if (test_and_clear_bit(CONN_DRY_RUN, &mdev->flags))
+				if (test_and_clear_bit(CONN_DRY_RUN, &mdev->tconn->flags))
 					return false;
 				D_ASSERT(os.conn == C_WF_REPORT_PARAMS);
 				conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD);
Signature · 1 line
1.7.4.1
author maintainer
#6 lore raw

PATCH 6/16 drbd: Allow packet handler functions that take a connection

In reply to Philipp Reisner

That is necessary in case a connection does not have a volume 0

---
 drivers/block/drbd/drbd_receiver.c |   75 ++++++++++++++++++++----------------
 1 files changed, 42 insertions(+), 33 deletions(-)
drivers/block/drbd/drbd_receiver.c +42 -33
index 7bb5e5c..1301ba1 100644
@@ -3856,39 +3856,45 @@ static int receive_out_of_sync(struct drbd_conf *mdev, enum drbd_packet cmd,
 	return true;
 }
 
-typedef int (*drbd_cmd_handler_f)(struct drbd_conf *, enum drbd_packet cmd,
-				  unsigned int to_receive);
-
 struct data_cmd {
 	int expect_payload;
 	size_t pkt_size;
-	drbd_cmd_handler_f function;
+	enum {
+		MDEV,
+		CONN,
+	} type;
+	union {
+		int (*mdev_fn)(struct drbd_conf *, enum drbd_packet cmd,
+				  unsigned int to_receive);
+		int (*conn_fn)(struct drbd_tconn *, enum drbd_packet cmd,
+				  unsigned int to_receive);
+	};
 };
 
 static struct data_cmd drbd_cmd_handler[] = {
-	[P_DATA]	    = { 1, sizeof(struct p_data), receive_Data },
-	[P_DATA_REPLY]	    = { 1, sizeof(struct p_data), receive_DataReply },
-	[P_RS_DATA_REPLY]   = { 1, sizeof(struct p_data), receive_RSDataReply } ,
-	[P_BARRIER]	    = { 0, sizeof(struct p_barrier), receive_Barrier } ,
-	[P_BITMAP]	    = { 1, sizeof(struct p_header), receive_bitmap } ,
-	[P_COMPRESSED_BITMAP] = { 1, sizeof(struct p_header), receive_bitmap } ,
-	[P_UNPLUG_REMOTE]   = { 0, sizeof(struct p_header), receive_UnplugRemote },
-	[P_DATA_REQUEST]    = { 0, sizeof(struct p_block_req), receive_DataRequest },
-	[P_RS_DATA_REQUEST] = { 0, sizeof(struct p_block_req), receive_DataRequest },
-	[P_SYNC_PARAM]	    = { 1, sizeof(struct p_header), receive_SyncParam },
-	[P_SYNC_PARAM89]    = { 1, sizeof(struct p_header), receive_SyncParam },
-	[P_PROTOCOL]        = { 1, sizeof(struct p_protocol), receive_protocol },
-	[P_UUIDS]	    = { 0, sizeof(struct p_uuids), receive_uuids },
-	[P_SIZES]	    = { 0, sizeof(struct p_sizes), receive_sizes },
-	[P_STATE]	    = { 0, sizeof(struct p_state), receive_state },
-	[P_STATE_CHG_REQ]   = { 0, sizeof(struct p_req_state), receive_req_state },
-	[P_SYNC_UUID]       = { 0, sizeof(struct p_rs_uuid), receive_sync_uuid },
-	[P_OV_REQUEST]      = { 0, sizeof(struct p_block_req), receive_DataRequest },
-	[P_OV_REPLY]        = { 1, sizeof(struct p_block_req), receive_DataRequest },
-	[P_CSUM_RS_REQUEST] = { 1, sizeof(struct p_block_req), receive_DataRequest },
-	[P_DELAY_PROBE]     = { 0, sizeof(struct p_delay_probe93), receive_skip },
-	[P_OUT_OF_SYNC]     = { 0, sizeof(struct p_block_desc), receive_out_of_sync },
-	[P_CONN_ST_CHG_REQ] = { 0, sizeof(struct p_req_state), receive_req_state },
+	[P_DATA]	    = { 1, sizeof(struct p_data), MDEV, { receive_Data } },
+	[P_DATA_REPLY]	    = { 1, sizeof(struct p_data), MDEV, { receive_DataReply } },
+	[P_RS_DATA_REPLY]   = { 1, sizeof(struct p_data), MDEV, { receive_RSDataReply } } ,
+	[P_BARRIER]	    = { 0, sizeof(struct p_barrier), MDEV, { receive_Barrier } } ,
+	[P_BITMAP]	    = { 1, sizeof(struct p_header), MDEV, { receive_bitmap } } ,
+	[P_COMPRESSED_BITMAP] = { 1, sizeof(struct p_header), MDEV, { receive_bitmap } } ,
+	[P_UNPLUG_REMOTE]   = { 0, sizeof(struct p_header), MDEV, { receive_UnplugRemote } },
+	[P_DATA_REQUEST]    = { 0, sizeof(struct p_block_req), MDEV, { receive_DataRequest } },
+	[P_RS_DATA_REQUEST] = { 0, sizeof(struct p_block_req), MDEV, { receive_DataRequest } },
+	[P_SYNC_PARAM]	    = { 1, sizeof(struct p_header), MDEV, { receive_SyncParam } },
+	[P_SYNC_PARAM89]    = { 1, sizeof(struct p_header), MDEV, { receive_SyncParam } },
+	[P_PROTOCOL]        = { 1, sizeof(struct p_protocol), MDEV, { receive_protocol } },
+	[P_UUIDS]	    = { 0, sizeof(struct p_uuids), MDEV, { receive_uuids } },
+	[P_SIZES]	    = { 0, sizeof(struct p_sizes), MDEV, { receive_sizes } },
+	[P_STATE]	    = { 0, sizeof(struct p_state), MDEV, { receive_state } },
+	[P_STATE_CHG_REQ]   = { 0, sizeof(struct p_req_state), MDEV, { receive_req_state } },
+	[P_SYNC_UUID]       = { 0, sizeof(struct p_rs_uuid), MDEV, { receive_sync_uuid } },
+	[P_OV_REQUEST]      = { 0, sizeof(struct p_block_req), MDEV, { receive_DataRequest } },
+	[P_OV_REPLY]        = { 1, sizeof(struct p_block_req), MDEV, { receive_DataRequest } },
+	[P_CSUM_RS_REQUEST] = { 1, sizeof(struct p_block_req), MDEV, { receive_DataRequest } },
+	[P_DELAY_PROBE]     = { 0, sizeof(struct p_delay_probe93), MDEV, { receive_skip } },
+	[P_OUT_OF_SYNC]     = { 0, sizeof(struct p_block_desc), MDEV, { receive_out_of_sync } },
+	[P_CONN_ST_CHG_REQ] = { 0, sizeof(struct p_req_state), MDEV, { receive_req_state } },
 };
 
 /* All handler functions that expect a sub-header get that sub-heder in
@@ -3901,7 +3907,6 @@ static struct data_cmd drbd_cmd_handler[] = {
 static void drbdd(struct drbd_tconn *tconn)
 {
 	struct p_header *header = &tconn->data.rbuf.header;
-	struct drbd_conf *mdev;
 	struct packet_info pi;
 	size_t shs; /* sub header size */
 	int rv;
@@ -3912,7 +3917,7 @@ static void drbdd(struct drbd_tconn *tconn)
 			goto err_out;
 
 		if (unlikely(pi.cmd >= ARRAY_SIZE(drbd_cmd_handler) ||
-		    !drbd_cmd_handler[pi.cmd].function)) {
+		    !drbd_cmd_handler[pi.cmd].mdev_fn)) {
 			conn_err(tconn, "unknown packet type %d, l: %d!\n", pi.cmd, pi.size);
 			goto err_out;
 		}
@@ -3932,10 +3937,14 @@ static void drbdd(struct drbd_tconn *tconn)
 			}
 		}
 
-		mdev = vnr_to_mdev(tconn, pi.vnr);
-		rv = mdev ?
-			drbd_cmd_handler[pi.cmd].function(mdev, pi.cmd, pi.size - shs) :
-			tconn_receive_skip(tconn, pi.cmd, pi.size - shs);
+		if (drbd_cmd_handler[pi.cmd].type == CONN) {
+			rv = drbd_cmd_handler[pi.cmd].conn_fn(tconn, pi.cmd, pi.size - shs);
+		} else {
+			struct drbd_conf *mdev = vnr_to_mdev(tconn, pi.vnr);
+			rv = mdev ?
+				drbd_cmd_handler[pi.cmd].mdev_fn(mdev, pi.cmd, pi.size - shs) :
+				tconn_receive_skip(tconn, pi.cmd, pi.size - shs);
+		}
 
 		if (unlikely(!rv)) {
 			conn_err(tconn, "error receiving %s, l: %d!\n",
Signature · 1 line
1.7.4.1
author maintainer
#7 lore raw

PATCH 7/16 drbd: Converted receive_protocol() from mdev to tconn

In reply to Philipp Reisner
---
 drivers/block/drbd/drbd_receiver.c |   46 ++++++++++++++++++------------------
 1 files changed, 23 insertions(+), 23 deletions(-)
drivers/block/drbd/drbd_receiver.c +23 -23
index 1301ba1..17904f7 100644
@@ -2856,10 +2856,10 @@ static int cmp_after_sb(enum drbd_after_sb_p peer, enum drbd_after_sb_p self)
 	return 1;
 }
 
-static int receive_protocol(struct drbd_conf *mdev, enum drbd_packet cmd,
+static int receive_protocol(struct drbd_tconn *tconn, enum drbd_packet cmd,
 			    unsigned int data_size)
 {
-	struct p_protocol *p = &mdev->tconn->data.rbuf.protocol;
+	struct p_protocol *p = &tconn->data.rbuf.protocol;
 	int p_proto, p_after_sb_0p, p_after_sb_1p, p_after_sb_2p;
 	int p_want_lose, p_two_primaries, cf;
 	char p_integrity_alg[SHARED_SECRET_MAX] = "";
@@ -2872,60 +2872,60 @@ static int receive_protocol(struct drbd_conf *mdev, enum drbd_packet cmd,
 	cf		= be32_to_cpu(p->conn_flags);
 	p_want_lose = cf & CF_WANT_LOSE;
 
-	clear_bit(CONN_DRY_RUN, &mdev->tconn->flags);
+	clear_bit(CONN_DRY_RUN, &tconn->flags);
 
 	if (cf & CF_DRY_RUN)
-		set_bit(CONN_DRY_RUN, &mdev->tconn->flags);
+		set_bit(CONN_DRY_RUN, &tconn->flags);
 
-	if (p_proto != mdev->tconn->net_conf->wire_protocol) {
-		dev_err(DEV, "incompatible communication protocols\n");
+	if (p_proto != tconn->net_conf->wire_protocol) {
+		conn_err(tconn, "incompatible communication protocols\n");
 		goto disconnect;
 	}
 
-	if (cmp_after_sb(p_after_sb_0p, mdev->tconn->net_conf->after_sb_0p)) {
-		dev_err(DEV, "incompatible after-sb-0pri settings\n");
+	if (cmp_after_sb(p_after_sb_0p, tconn->net_conf->after_sb_0p)) {
+		conn_err(tconn, "incompatible after-sb-0pri settings\n");
 		goto disconnect;
 	}
 
-	if (cmp_after_sb(p_after_sb_1p, mdev->tconn->net_conf->after_sb_1p)) {
-		dev_err(DEV, "incompatible after-sb-1pri settings\n");
+	if (cmp_after_sb(p_after_sb_1p, tconn->net_conf->after_sb_1p)) {
+		conn_err(tconn, "incompatible after-sb-1pri settings\n");
 		goto disconnect;
 	}
 
-	if (cmp_after_sb(p_after_sb_2p, mdev->tconn->net_conf->after_sb_2p)) {
-		dev_err(DEV, "incompatible after-sb-2pri settings\n");
+	if (cmp_after_sb(p_after_sb_2p, tconn->net_conf->after_sb_2p)) {
+		conn_err(tconn, "incompatible after-sb-2pri settings\n");
 		goto disconnect;
 	}
 
-	if (p_want_lose && mdev->tconn->net_conf->want_lose) {
-		dev_err(DEV, "both sides have the 'want_lose' flag set\n");
+	if (p_want_lose && tconn->net_conf->want_lose) {
+		conn_err(tconn, "both sides have the 'want_lose' flag set\n");
 		goto disconnect;
 	}
 
-	if (p_two_primaries != mdev->tconn->net_conf->two_primaries) {
-		dev_err(DEV, "incompatible setting of the two-primaries options\n");
+	if (p_two_primaries != tconn->net_conf->two_primaries) {
+		conn_err(tconn, "incompatible setting of the two-primaries options\n");
 		goto disconnect;
 	}
 
-	if (mdev->tconn->agreed_pro_version >= 87) {
-		unsigned char *my_alg = mdev->tconn->net_conf->integrity_alg;
+	if (tconn->agreed_pro_version >= 87) {
+		unsigned char *my_alg = tconn->net_conf->integrity_alg;
 
-		if (drbd_recv(mdev->tconn, p_integrity_alg, data_size) != data_size)
+		if (drbd_recv(tconn, p_integrity_alg, data_size) != data_size)
 			return false;
 
 		p_integrity_alg[SHARED_SECRET_MAX-1] = 0;
 		if (strcmp(p_integrity_alg, my_alg)) {
-			dev_err(DEV, "incompatible setting of the data-integrity-alg\n");
+			conn_err(tconn, "incompatible setting of the data-integrity-alg\n");
 			goto disconnect;
 		}
-		dev_info(DEV, "data-integrity-alg: %s\n",
+		conn_info(tconn, "data-integrity-alg: %s\n",
 		     my_alg[0] ? my_alg : (unsigned char *)"<not-used>");
 	}
 
 	return true;
 
 disconnect:
-	conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD);
+	conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_HARD);
 	return false;
 }
 
@@ -3883,7 +3883,7 @@ static struct data_cmd drbd_cmd_handler[] = {
 	[P_RS_DATA_REQUEST] = { 0, sizeof(struct p_block_req), MDEV, { receive_DataRequest } },
 	[P_SYNC_PARAM]	    = { 1, sizeof(struct p_header), MDEV, { receive_SyncParam } },
 	[P_SYNC_PARAM89]    = { 1, sizeof(struct p_header), MDEV, { receive_SyncParam } },
-	[P_PROTOCOL]        = { 1, sizeof(struct p_protocol), MDEV, { receive_protocol } },
+	[P_PROTOCOL]        = { 1, sizeof(struct p_protocol), CONN, { .conn_fn = receive_protocol } },
 	[P_UUIDS]	    = { 0, sizeof(struct p_uuids), MDEV, { receive_uuids } },
 	[P_SIZES]	    = { 0, sizeof(struct p_sizes), MDEV, { receive_sizes } },
 	[P_STATE]	    = { 0, sizeof(struct p_state), MDEV, { receive_state } },
Signature · 1 line
1.7.4.1
author maintainer
#8 lore raw

PATCH 8/16 drbd: Separate connection state changes from minor dev state changes #1

In reply to Philipp Reisner
---
 drivers/block/drbd/drbd_receiver.c |   36 ++++++++++++++++++++++++++++--------
 1 files changed, 28 insertions(+), 8 deletions(-)
drivers/block/drbd/drbd_receiver.c +28 -8
index 17904f7..7e25a80 100644
@@ -3334,19 +3334,39 @@ static int receive_req_state(struct drbd_conf *mdev, enum drbd_packet cmd,
 	mask = convert_state(mask);
 	val = convert_state(val);
 
-	if (cmd == P_CONN_ST_CHG_REQ) {
-		rv = conn_request_state(mdev->tconn, mask, val, CS_VERBOSE | CS_LOCAL_ONLY);
-		conn_send_sr_reply(mdev->tconn, rv);
-	} else {
-		rv = drbd_change_state(mdev, CS_VERBOSE, mask, val);
-		drbd_send_sr_reply(mdev, rv);
-	}
+	rv = drbd_change_state(mdev, CS_VERBOSE, mask, val);
+	drbd_send_sr_reply(mdev, rv);
 
 	drbd_md_sync(mdev);
 
 	return true;
 }
 
+static int receive_req_conn_state(struct drbd_tconn *tconn, enum drbd_packet cmd,
+				  unsigned int data_size)
+{
+	struct p_req_state *p = &tconn->data.rbuf.req_state;
+	union drbd_state mask, val;
+	enum drbd_state_rv rv;
+
+	mask.i = be32_to_cpu(p->mask);
+	val.i = be32_to_cpu(p->val);
+
+	if (test_bit(DISCARD_CONCURRENT, &tconn->flags) &&
+	    mutex_is_locked(&tconn->cstate_mutex)) {
+		conn_send_sr_reply(tconn, SS_CONCURRENT_ST_CHG);
+		return true;
+	}
+
+	mask = convert_state(mask);
+	val = convert_state(val);
+
+	rv = conn_request_state(tconn, mask, val, CS_VERBOSE | CS_LOCAL_ONLY);
+	conn_send_sr_reply(tconn, rv);
+
+	return true;
+}
+
 static int receive_state(struct drbd_conf *mdev, enum drbd_packet cmd,
 			 unsigned int data_size)
 {
@@ -3894,7 +3914,7 @@ static struct data_cmd drbd_cmd_handler[] = {
 	[P_CSUM_RS_REQUEST] = { 1, sizeof(struct p_block_req), MDEV, { receive_DataRequest } },
 	[P_DELAY_PROBE]     = { 0, sizeof(struct p_delay_probe93), MDEV, { receive_skip } },
 	[P_OUT_OF_SYNC]     = { 0, sizeof(struct p_block_desc), MDEV, { receive_out_of_sync } },
-	[P_CONN_ST_CHG_REQ] = { 0, sizeof(struct p_req_state), MDEV, { receive_req_state } },
+	[P_CONN_ST_CHG_REQ] = { 0, sizeof(struct p_req_state), CONN, { .conn_fn = receive_req_conn_state } },
 };
 
 /* All handler functions that expect a sub-header get that sub-heder in
Signature · 1 line
1.7.4.1
author maintainer
#9 lore raw

PATCH 9/16 drbd: Allow packet handler functions that take a connection (meta connection)

In reply to Philipp Reisner
---
 drivers/block/drbd/drbd_receiver.c |   66 ++++++++++++++++++++++-------------
 1 files changed, 41 insertions(+), 25 deletions(-)
drivers/block/drbd/drbd_receiver.c +41 -25
index 7e25a80..0117dcd 100644
@@ -60,6 +60,11 @@ enum finish_epoch {
 	FE_RECYCLED,
 };
 
+enum mdev_or_conn {
+	MDEV,
+	CONN,
+};
+
 static int drbd_do_handshake(struct drbd_tconn *tconn);
 static int drbd_do_auth(struct drbd_tconn *tconn);
 static int drbd_disconnected(int vnr, void *p, void *data);
@@ -3879,10 +3884,7 @@ static int receive_out_of_sync(struct drbd_conf *mdev, enum drbd_packet cmd,
 struct data_cmd {
 	int expect_payload;
 	size_t pkt_size;
-	enum {
-		MDEV,
-		CONN,
-	} type;
+	enum mdev_or_conn fa_type; /* first argument's type */
 	union {
 		int (*mdev_fn)(struct drbd_conf *, enum drbd_packet cmd,
 				  unsigned int to_receive);
@@ -3957,7 +3959,7 @@ static void drbdd(struct drbd_tconn *tconn)
 			}
 		}
 
-		if (drbd_cmd_handler[pi.cmd].type == CONN) {
+		if (drbd_cmd_handler[pi.cmd].fa_type == CONN) {
 			rv = drbd_cmd_handler[pi.cmd].conn_fn(tconn, pi.cmd, pi.size - shs);
 		} else {
 			struct drbd_conf *mdev = vnr_to_mdev(tconn, pi.vnr);
@@ -4722,27 +4724,31 @@ static int tconn_process_done_ee(struct drbd_tconn *tconn)
 
 struct asender_cmd {
 	size_t pkt_size;
-	int (*process)(struct drbd_conf *, enum drbd_packet);
+	enum mdev_or_conn fa_type; /* first argument's type */
+	union {
+		int (*mdev_fn)(struct drbd_conf *mdev, enum drbd_packet cmd);
+		int (*conn_fn)(struct drbd_tconn *tconn, enum drbd_packet cmd);
+	};
 };
 
 static struct asender_cmd asender_tbl[] = {
-	[P_PING]	    = { sizeof(struct p_header), got_Ping },
-	[P_PING_ACK]	    = { sizeof(struct p_header), got_PingAck },
-	[P_RECV_ACK]	    = { sizeof(struct p_block_ack), got_BlockAck },
-	[P_WRITE_ACK]	    = { sizeof(struct p_block_ack), got_BlockAck },
-	[P_RS_WRITE_ACK]    = { sizeof(struct p_block_ack), got_BlockAck },
-	[P_DISCARD_WRITE]   = { sizeof(struct p_block_ack), got_BlockAck },
-	[P_NEG_ACK]	    = { sizeof(struct p_block_ack), got_NegAck },
-	[P_NEG_DREPLY]	    = { sizeof(struct p_block_ack), got_NegDReply },
-	[P_NEG_RS_DREPLY]   = { sizeof(struct p_block_ack), got_NegRSDReply},
-	[P_OV_RESULT]	    = { sizeof(struct p_block_ack), got_OVResult },
-	[P_BARRIER_ACK]	    = { sizeof(struct p_barrier_ack), got_BarrierAck },
-	[P_STATE_CHG_REPLY] = { sizeof(struct p_req_state_reply), got_RqSReply },
-	[P_RS_IS_IN_SYNC]   = { sizeof(struct p_block_ack), got_IsInSync },
-	[P_DELAY_PROBE]     = { sizeof(struct p_delay_probe93), got_skip },
-	[P_RS_CANCEL]       = { sizeof(struct p_block_ack), got_NegRSDReply},
-	[P_CONN_ST_CHG_REPLY]={ sizeof(struct p_req_state_reply), got_RqSReply },
-	[P_RETRY_WRITE]	    = { sizeof(struct p_block_ack), got_BlockAck },
+	[P_PING]	    = { sizeof(struct p_header), MDEV, { got_Ping } },
+	[P_PING_ACK]	    = { sizeof(struct p_header), MDEV, { got_PingAck } },
+	[P_RECV_ACK]	    = { sizeof(struct p_block_ack), MDEV, { got_BlockAck } },
+	[P_WRITE_ACK]	    = { sizeof(struct p_block_ack), MDEV, { got_BlockAck } },
+	[P_RS_WRITE_ACK]    = { sizeof(struct p_block_ack), MDEV, { got_BlockAck } },
+	[P_DISCARD_WRITE]   = { sizeof(struct p_block_ack), MDEV, { got_BlockAck } },
+	[P_NEG_ACK]	    = { sizeof(struct p_block_ack), MDEV, { got_NegAck } },
+	[P_NEG_DREPLY]	    = { sizeof(struct p_block_ack), MDEV, { got_NegDReply } },
+	[P_NEG_RS_DREPLY]   = { sizeof(struct p_block_ack), MDEV, { got_NegRSDReply } },
+	[P_OV_RESULT]	    = { sizeof(struct p_block_ack), MDEV, { got_OVResult } },
+	[P_BARRIER_ACK]	    = { sizeof(struct p_barrier_ack), MDEV, { got_BarrierAck } },
+	[P_STATE_CHG_REPLY] = { sizeof(struct p_req_state_reply), MDEV, { got_RqSReply } },
+	[P_RS_IS_IN_SYNC]   = { sizeof(struct p_block_ack), MDEV, { got_IsInSync } },
+	[P_DELAY_PROBE]     = { sizeof(struct p_delay_probe93), MDEV, { got_skip } },
+	[P_RS_CANCEL]       = { sizeof(struct p_block_ack), MDEV, { got_NegRSDReply } },
+	[P_CONN_ST_CHG_REPLY]={ sizeof(struct p_req_state_reply), MDEV, { got_RqSReply } },
+	[P_RETRY_WRITE]	    = { sizeof(struct p_block_ack), MDEV, { got_BlockAck } },
 };
 
 int drbd_asender(struct drbd_thread *thi)
@@ -4845,10 +4851,20 @@ int drbd_asender(struct drbd_thread *thi)
 			}
 		}
 		if (received == expect) {
-			tconn->last_received = jiffies;
-			if (!cmd->process(vnr_to_mdev(tconn, pi.vnr), pi.cmd))
+			bool rv;
+
+			if (cmd->fa_type == CONN) {
+				rv = cmd->conn_fn(tconn, pi.cmd);
+			} else {
+				struct drbd_conf *mdev = vnr_to_mdev(tconn, pi.vnr);
+				rv = cmd->mdev_fn(mdev, pi.cmd);
+			}
+
+			if (!rv)
 				goto reconnect;
 
+			tconn->last_received = jiffies;
+
 			/* the idle_timeout (ping-int)
 			 * has been restored in got_PingAck() */
 			if (cmd == &asender_tbl[P_PING_ACK])
Signature · 1 line
1.7.4.1
author maintainer
#10 lore raw

PATCH 10/16 drbd: Converted got_Ping() and got_PingAck() from mdev to tconn

In reply to Philipp Reisner
---
 drivers/block/drbd/drbd_receiver.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)
drivers/block/drbd/drbd_receiver.c +5 -6
index 0117dcd..e28f194 100644
@@ -4444,15 +4444,14 @@ static int got_RqSReply(struct drbd_conf *mdev, enum drbd_packet cmd)
 	return true;
 }
 
-static int got_Ping(struct drbd_conf *mdev, enum drbd_packet cmd)
+static int got_Ping(struct drbd_tconn *tconn, enum drbd_packet cmd)
 {
-	return drbd_send_ping_ack(mdev->tconn);
+	return drbd_send_ping_ack(tconn);
 
 }
 
-static int got_PingAck(struct drbd_conf *mdev, enum drbd_packet cmd)
+static int got_PingAck(struct drbd_tconn *tconn, enum drbd_packet cmd)
 {
-	struct drbd_tconn *tconn = mdev->tconn;
 	/* restore idle timeout */
 	tconn->meta.socket->sk->sk_rcvtimeo = tconn->net_conf->ping_int*HZ;
 	if (!test_and_set_bit(GOT_PING_ACK, &tconn->flags))
@@ -4732,8 +4731,8 @@ struct asender_cmd {
 };
 
 static struct asender_cmd asender_tbl[] = {
-	[P_PING]	    = { sizeof(struct p_header), MDEV, { got_Ping } },
-	[P_PING_ACK]	    = { sizeof(struct p_header), MDEV, { got_PingAck } },
+	[P_PING]	    = { sizeof(struct p_header), CONN, { .conn_fn = got_Ping } },
+	[P_PING_ACK]	    = { sizeof(struct p_header), CONN, { .conn_fn = got_PingAck } },
 	[P_RECV_ACK]	    = { sizeof(struct p_block_ack), MDEV, { got_BlockAck } },
 	[P_WRITE_ACK]	    = { sizeof(struct p_block_ack), MDEV, { got_BlockAck } },
 	[P_RS_WRITE_ACK]    = { sizeof(struct p_block_ack), MDEV, { got_BlockAck } },
Signature · 1 line
1.7.4.1
author maintainer
#11 lore raw

PATCH 11/16 drbd: Separate connection state changes from minor dev state changes #2

In reply to Philipp Reisner

New function got_conn_RqSReply()

---
 drivers/block/drbd/drbd_receiver.c |   47 ++++++++++++++++++++----------------
 1 files changed, 26 insertions(+), 21 deletions(-)
drivers/block/drbd/drbd_receiver.c +26 -21
index e28f194..5fd78f4 100644
@@ -4415,32 +4415,37 @@ int drbdd_init(struct drbd_thread *thi)
 
 /* ********* acknowledge sender ******** */
 
+static int got_conn_RqSReply(struct drbd_tconn *tconn, enum drbd_packet cmd)
+{
+	struct p_req_state_reply *p = &tconn->meta.rbuf.req_state_reply;
+	int retcode = be32_to_cpu(p->retcode);
+
+	if (retcode >= SS_SUCCESS) {
+		set_bit(CONN_WD_ST_CHG_OKAY, &tconn->flags);
+	} else {
+		set_bit(CONN_WD_ST_CHG_FAIL, &tconn->flags);
+		conn_err(tconn, "Requested state change failed by peer: %s (%d)\n",
+			 drbd_set_st_err_str(retcode), retcode);
+	}
+	wake_up(&tconn->ping_wait);
+
+	return true;
+}
+
 static int got_RqSReply(struct drbd_conf *mdev, enum drbd_packet cmd)
 {
 	struct p_req_state_reply *p = &mdev->tconn->meta.rbuf.req_state_reply;
-	struct drbd_tconn *tconn = mdev->tconn;
-
 	int retcode = be32_to_cpu(p->retcode);
 
-	if (cmd == P_STATE_CHG_REPLY) {
-		if (retcode >= SS_SUCCESS) {
-			set_bit(CL_ST_CHG_SUCCESS, &mdev->flags);
-		} else {
-			set_bit(CL_ST_CHG_FAIL, &mdev->flags);
-			dev_err(DEV, "Requested state change failed by peer: %s (%d)\n",
-				drbd_set_st_err_str(retcode), retcode);
-		}
-		wake_up(&mdev->state_wait);
-	} else /* conn == P_CONN_ST_CHG_REPLY */ {
-		if (retcode >= SS_SUCCESS) {
-			set_bit(CONN_WD_ST_CHG_OKAY, &tconn->flags);
-		} else {
-			set_bit(CONN_WD_ST_CHG_FAIL, &tconn->flags);
-			conn_err(tconn, "Requested state change failed by peer: %s (%d)\n",
-				 drbd_set_st_err_str(retcode), retcode);
-		}
-		wake_up(&tconn->ping_wait);
+	if (retcode >= SS_SUCCESS) {
+		set_bit(CL_ST_CHG_SUCCESS, &mdev->flags);
+	} else {
+		set_bit(CL_ST_CHG_FAIL, &mdev->flags);
+		dev_err(DEV, "Requested state change failed by peer: %s (%d)\n",
+			drbd_set_st_err_str(retcode), retcode);
 	}
+	wake_up(&mdev->state_wait);
+
 	return true;
 }
 
@@ -4746,7 +4751,7 @@ static struct asender_cmd asender_tbl[] = {
 	[P_RS_IS_IN_SYNC]   = { sizeof(struct p_block_ack), MDEV, { got_IsInSync } },
 	[P_DELAY_PROBE]     = { sizeof(struct p_delay_probe93), MDEV, { got_skip } },
 	[P_RS_CANCEL]       = { sizeof(struct p_block_ack), MDEV, { got_NegRSDReply } },
-	[P_CONN_ST_CHG_REPLY]={ sizeof(struct p_req_state_reply), MDEV, { got_RqSReply } },
+	[P_CONN_ST_CHG_REPLY]={ sizeof(struct p_req_state_reply), CONN, {.conn_fn = got_conn_RqSReply}},
 	[P_RETRY_WRITE]	    = { sizeof(struct p_block_ack), MDEV, { got_BlockAck } },
 };
 
Signature · 1 line
1.7.4.1
author maintainer
#12 lore raw

PATCH 12/16 drbd: fix conn_reconfig_start without conn_reconfig_done in drbd_adm_attach

In reply to Philipp Reisner

From: Lars Ellenberg <[email protected]>

If drbd_adm_attach failed early, it left the CONFIG_PENDING bit on, blocking any further conn_reconfig_start on that connection.

---
 drivers/block/drbd/drbd_nl.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/block/drbd/drbd_nl.c +3 -2
index 2970f45..7389e37 100644
@@ -1074,7 +1074,7 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info)
 	if (!adm_ctx.reply_skb)
 		return retcode;
 	if (retcode != NO_ERROR)
-		goto fail;
+		goto finish;
 
 	mdev = adm_ctx.mdev;
 	conn_reconfig_start(mdev->tconn);
@@ -1433,8 +1433,8 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info)
  force_diskless:
 	drbd_force_state(mdev, NS(disk, D_FAILED));
 	drbd_md_sync(mdev);
-	conn_reconfig_done(mdev->tconn);
  fail:
+	conn_reconfig_done(mdev->tconn);
 	if (nbc) {
 		if (nbc->backing_bdev)
 			blkdev_put(nbc->backing_bdev,
@@ -1446,6 +1446,7 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info)
 	}
 	lc_destroy(resync_lru);
 
+ finish:
 	drbd_adm_finish(info, retcode);
 	return 0;
 }
Signature · 1 line
1.7.4.1
author maintainer
#13 lore raw

PATCH 13/16 drbd: Allow volumes to become primary only on one side

In reply to Philipp Reisner
---
 drivers/block/drbd/drbd_state.c   |   21 ++++++++++++++++++---
 drivers/block/drbd/drbd_strings.c |    1 +
 include/linux/drbd.h              |    3 ++-
 3 files changed, 21 insertions(+), 4 deletions(-)
drivers/block/drbd/drbd_state.c +18 -3
index 37b52d7..e2686b3 100644
@@ -330,6 +330,18 @@ static void print_state_change(struct drbd_conf *mdev, union drbd_state os, unio
 		dev_info(DEV, "%s\n", pb);
 }
 
+static bool vol_has_primary_peer(struct drbd_tconn *tconn)
+{
+	struct drbd_conf *mdev;
+	int minor;
+
+	idr_for_each_entry(&tconn->volumes, mdev, minor) {
+		if (mdev->state.peer == R_PRIMARY)
+			return true;
+	}
+	return false;
+}
+
 /**
  * is_valid_state() - Returns an SS_ error code if ns is not valid
  * @mdev:	DRBD device.
@@ -350,9 +362,12 @@ is_valid_state(struct drbd_conf *mdev, union drbd_state ns)
 	}
 
 	if (get_net_conf(mdev->tconn)) {
-		if (!mdev->tconn->net_conf->two_primaries &&
-		    ns.role == R_PRIMARY && ns.peer == R_PRIMARY)
-			rv = SS_TWO_PRIMARIES;
+		if (!mdev->tconn->net_conf->two_primaries && ns.role == R_PRIMARY) {
+			if (ns.peer == R_PRIMARY)
+				rv = SS_TWO_PRIMARIES;
+			else if (vol_has_primary_peer(mdev->tconn))
+				rv = SS_O_VOL_PEER_PRI;
+			}
 		put_net_conf(mdev->tconn);
 	}
 
drivers/block/drbd/drbd_strings.c +1 -0
index c44a2a6..9a664bd 100644
@@ -89,6 +89,7 @@ static const char *drbd_state_sw_errors[] = {
 	[-SS_LOWER_THAN_OUTDATED] = "Disk state is lower than outdated",
 	[-SS_IN_TRANSIENT_STATE] = "In transient state, retry after next state change",
 	[-SS_CONCURRENT_ST_CHG] = "Concurrent state changes detected and aborted",
+	[-SS_O_VOL_PEER_PRI] = "Other vol primary on peer not allowed by config",
 };
 
 const char *drbd_conn_str(enum drbd_conns s)
include/linux/drbd.h +2 -1
index d28fdd8..9cdb888 100644
@@ -300,7 +300,8 @@ enum drbd_state_rv {
 	SS_NOT_SUPPORTED = -17,      /* drbd-8.2 only */
 	SS_IN_TRANSIENT_STATE = -18,  /* Retry after the next state change */
 	SS_CONCURRENT_ST_CHG = -19,   /* Concurrent cluster side state change! */
-	SS_AFTER_LAST_ERROR = -20,    /* Keep this at bottom */
+	SS_O_VOL_PEER_PRI = -20,
+	SS_AFTER_LAST_ERROR = -21,    /* Keep this at bottom */
 };
 
 /* from drbd_strings.c */
Signature · 1 line
1.7.4.1
author maintainer
#14 lore raw

PATCH 14/16 drbd: conn_khelper() for user mode callbacks for connections

In reply to Philipp Reisner
---
 drivers/block/drbd/drbd_nl.c |   87 ++++++++++++++++++++++++++++++++---------
 1 files changed, 68 insertions(+), 19 deletions(-)
drivers/block/drbd/drbd_nl.c +68 -19
index 7389e37..8f427a1 100644
@@ -285,43 +285,49 @@ static int drbd_adm_finish(struct genl_info *info, int retcode)
 	return 0;
 }
 
-int drbd_khelper(struct drbd_conf *mdev, char *cmd)
+static void setup_khelper_env(struct drbd_tconn *tconn, char **envp)
 {
-	char *envp[] = { "HOME=/",
-			"TERM=linux",
-			"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
-			NULL, /* Will be set to address family */
-			NULL, /* Will be set to address */
-			NULL };
-	char mb[12], af[20], ad[60], *afs;
-	char *argv[] = {usermode_helper, cmd, mb, NULL };
-	struct sib_info sib;
-	int ret;
+	char af[20], ad[60], *afs;
 
-	snprintf(mb, 12, "minor-%d", mdev_to_minor(mdev));
-
-	if (get_net_conf(mdev->tconn)) {
-		switch (((struct sockaddr *)mdev->tconn->net_conf->peer_addr)->sa_family) {
+	if (get_net_conf(tconn)) {
+		switch (((struct sockaddr *)tconn->net_conf->peer_addr)->sa_family) {
 		case AF_INET6:
 			afs = "ipv6";
 			snprintf(ad, 60, "DRBD_PEER_ADDRESS=%pI6",
-				 &((struct sockaddr_in6 *)mdev->tconn->net_conf->peer_addr)->sin6_addr);
+				 &((struct sockaddr_in6 *)tconn->net_conf->peer_addr)->sin6_addr);
 			break;
 		case AF_INET:
 			afs = "ipv4";
 			snprintf(ad, 60, "DRBD_PEER_ADDRESS=%pI4",
-				 &((struct sockaddr_in *)mdev->tconn->net_conf->peer_addr)->sin_addr);
+				 &((struct sockaddr_in *)tconn->net_conf->peer_addr)->sin_addr);
 			break;
 		default:
 			afs = "ssocks";
 			snprintf(ad, 60, "DRBD_PEER_ADDRESS=%pI4",
-				 &((struct sockaddr_in *)mdev->tconn->net_conf->peer_addr)->sin_addr);
+				 &((struct sockaddr_in *)tconn->net_conf->peer_addr)->sin_addr);
 		}
 		snprintf(af, 20, "DRBD_PEER_AF=%s", afs);
 		envp[3]=af;
 		envp[4]=ad;
-		put_net_conf(mdev->tconn);
+		put_net_conf(tconn);
 	}
+}
+
+int drbd_khelper(struct drbd_conf *mdev, char *cmd)
+{
+	char *envp[] = { "HOME=/",
+			"TERM=linux",
+			"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
+			NULL, /* Will be set to address family */
+			NULL, /* Will be set to address */
+			NULL };
+	char mb[12];
+	char *argv[] = {usermode_helper, cmd, mb, NULL };
+	struct sib_info sib;
+	int ret;
+
+	snprintf(mb, 12, "minor-%d", mdev_to_minor(mdev));
+	setup_khelper_env(mdev->tconn, envp);
 
 	/* The helper may take some time.
 	 * write out any unsynced meta data changes now */
@@ -350,6 +356,49 @@ int drbd_khelper(struct drbd_conf *mdev, char *cmd)
 	return ret;
 }
 
+static void conn_md_sync(struct drbd_tconn *tconn)
+{
+	struct drbd_conf *mdev;
+	int minor;
+
+	idr_for_each_entry(&tconn->volumes, mdev, minor)
+		drbd_md_sync(mdev);
+}
+
+int conn_khelper(struct drbd_tconn *tconn, char *cmd)
+{
+	char *envp[] = { "HOME=/",
+			"TERM=linux",
+			"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
+			NULL, /* Will be set to address family */
+			NULL, /* Will be set to address */
+			NULL };
+	char *argv[] = {usermode_helper, cmd, tconn->name, NULL };
+	int ret;
+
+	setup_khelper_env(tconn, envp);
+	conn_md_sync(tconn);
+
+	conn_info(tconn, "helper command: %s %s %s\n", usermode_helper, cmd, tconn->name);
+	/* TODO: conn_bcast_event() ?? */
+
+	ret = call_usermodehelper(usermode_helper, argv, envp, 1);
+	if (ret)
+		conn_warn(tconn, "helper command: %s %s %s exit code %u (0x%x)\n",
+			  usermode_helper, cmd, tconn->name,
+			  (ret >> 8) & 0xff, ret);
+	else
+		conn_info(tconn, "helper command: %s %s %s exit code %u (0x%x)\n",
+			  usermode_helper, cmd, tconn->name,
+			  (ret >> 8) & 0xff, ret);
+	/* TODO: conn_bcast_event() ?? */
+
+	if (ret < 0) /* Ignore any ERRNOs we got. */
+		ret = 0;
+
+	return ret;
+}
+
 enum drbd_disk_state drbd_try_outdate_peer(struct drbd_conf *mdev)
 {
 	char *ex_to_string;
Signature · 1 line
1.7.4.1
author maintainer
#15 lore raw

PATCH 15/16 drbd: distribute former syncer_conf settings to disk, connection, and resource level

In reply to Philipp Reisner

From: Lars Ellenberg <[email protected]>

This commit breaks the API again.

Move per-volume former syncer options into disk_conf. Move per-connection former syncer options into net_conf. Renamed the remainign sync_conf to res_opts

Syncer settings have been changeable at runtime, so we need to prepare for these settings to be runtime-changeable in their new home as well.

Introduce new configuration operations, and share the netlink attribute between "attach" (create new disk) and "disk-opts" (change options). Same for "connect" and "net-opts".

Some fields cannot be changed at runtime, however.
Introduce a new flag GENLA_F_INVARIANT to be able to trigger on that in the generated validation and assignment functions.

---
 drivers/block/drbd/drbd_int.h      |   10 +-
 drivers/block/drbd/drbd_main.c     |   70 +++---
 drivers/block/drbd/drbd_nl.c       |  477 +++++++++++++++++++++++-------------
 drivers/block/drbd/drbd_receiver.c |   44 ++--
 drivers/block/drbd/drbd_state.c    |    4 +-
 drivers/block/drbd/drbd_worker.c   |   50 ++--
 include/linux/drbd_genl.h          |  133 ++++++-----
 include/linux/drbd_limits.h        |    2 +
 include/linux/genl_magic_func.h    |   41 ++--
 include/linux/genl_magic_struct.h  |   18 +-
 10 files changed, 512 insertions(+), 337 deletions(-)
drivers/block/drbd/drbd_int.h +5 -5
index 99b34f9..a9138ff 100644
@@ -860,7 +860,7 @@ struct drbd_md {
 	s32 bm_offset;	/* signed relative sector offset to bitmap */
 
 	/* u32 al_nr_extents;	   important for restoring the AL
-	 * is stored into  sync_conf.al_extents, which in turn
+	 * is stored into  ldev->dc.al_extents, which in turn
 	 * gets applied to act_log->nr_elements
 	 */
 };
@@ -929,6 +929,7 @@ struct drbd_tconn {			/* is a resource from the config file */
 	atomic_t net_cnt;		/* Users of net_conf */
 	wait_queue_head_t net_cnt_wait;
 	wait_queue_head_t ping_wait;		/* Woken upon reception of a ping, and a state change */
+	struct res_opts res_opts;
 
 	struct drbd_socket data;	/* data/barrier/cstate/parameter packets */
 	struct drbd_socket meta;	/* ping/ack (metadata) packets */
@@ -945,6 +946,8 @@ struct drbd_tconn {			/* is a resource from the config file */
 	struct crypto_hash *cram_hmac_tfm;
 	struct crypto_hash *integrity_w_tfm; /* to be used by the worker thread */
 	struct crypto_hash *integrity_r_tfm; /* to be used by the receiver thread */
+	struct crypto_hash *csums_tfm;
+	struct crypto_hash *verify_tfm;
 	void *int_dig_out;
 	void *int_dig_in;
 	void *int_dig_vv;
@@ -963,7 +966,6 @@ struct drbd_conf {
 	unsigned long flags;
 
 	/* configured by drbdsetup */
-	struct syncer_conf sync_conf;
 	struct drbd_backing_dev *ldev __protected_by(local);
 
 	sector_t p_size;     /* partner's disk size */
@@ -1037,8 +1039,6 @@ struct drbd_conf {
 	/* size of out-of-sync range in sectors. */
 	sector_t ov_last_oos_size;
 	unsigned long ov_left; /* in bits */
-	struct crypto_hash *csums_tfm;
-	struct crypto_hash *verify_tfm;
 
 	struct drbd_bitmap *bitmap;
 	unsigned long bm_resync_fo; /* bit offset for drbd_bm_find_next */
@@ -1188,7 +1188,7 @@ extern int conn_send_cmd2(struct drbd_tconn *tconn, enum drbd_packet cmd,
 			  char *data, size_t size);
 #define USE_DATA_SOCKET 1
 #define USE_META_SOCKET 0
-extern int drbd_send_sync_param(struct drbd_conf *mdev, struct syncer_conf *sc);
+extern int drbd_send_sync_param(struct drbd_conf *mdev);
 extern int drbd_send_b_ack(struct drbd_conf *mdev, u32 barrier_nr,
 			u32 set_size);
 extern int drbd_send_ack(struct drbd_conf *, enum drbd_packet,
drivers/block/drbd/drbd_main.c +32 -38

133 lines not on this page · raw message

drivers/block/drbd/drbd_nl.c +310 -167

629 lines not on this page · raw message

drivers/block/drbd/drbd_receiver.c +22 -22

100 lines not on this page · raw message

drivers/block/drbd/drbd_state.c +2 -2
index e2686b3..c4a0710 100644
@@ -403,7 +403,7 @@ is_valid_state(struct drbd_conf *mdev, union drbd_state ns)
 		rv = SS_CONNECTED_OUTDATES;
 
 	else if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) &&
-		 (mdev->sync_conf.verify_alg[0] == 0))
+		 (mdev->tconn->net_conf->verify_alg[0] == 0))
 		rv = SS_NO_VERIFY_ALG;
 
 	else if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) &&
@@ -669,7 +669,7 @@ static union drbd_state sanitize_state(struct drbd_conf *mdev, union drbd_state
 	    (ns.role == R_PRIMARY && ns.conn < C_CONNECTED && ns.pdsk > D_OUTDATED))
 		ns.susp_fen = 1; /* Suspend IO while fence-peer handler runs (peer lost) */
 
-	if (mdev->sync_conf.on_no_data == OND_SUSPEND_IO &&
+	if (mdev->tconn->res_opts.on_no_data == OND_SUSPEND_IO &&
 	    (ns.role == R_PRIMARY && ns.disk < D_UP_TO_DATE && ns.pdsk < D_UP_TO_DATE))
 		ns.susp_nod = 1; /* Suspend IO while no data available (no accessible data available) */
 
drivers/block/drbd/drbd_worker.c +25 -25

160 lines not on this page · raw message

include/linux/drbd_genl.h +75 -58

175 lines not on this page · raw message

include/linux/drbd_limits.h +2 -0
index 22920a8..659a8eb 100644
@@ -166,5 +166,7 @@
 #define DRBD_CONG_EXTENTS_MAX	DRBD_AL_EXTENTS_MAX
 #define DRBD_CONG_EXTENTS_DEF	DRBD_AL_EXTENTS_DEF
 
+#define DRBD_PROTOCOL_DEF DRBD_PROT_C
+
 #undef RANGE
 #endif
include/linux/genl_magic_func.h +26 -15

70 lines not on this page · raw message

include/linux/genl_magic_struct.h +13 -5
index 745ebfd..9a605b9 100644
@@ -59,12 +59,20 @@ enum {
 	GENLA_F_MANDATORY	= 1 << 14,
 	GENLA_F_REQUIRED	= 1 << 15,
 
-	/* This will not be present in the __u16 .nla_type, but can be
-	 * triggered on in <struct>_to_skb, to exclude "sensitive"
-	 * information from broadcasts, or on unpriviledged get requests.
-	 * This is useful because genetlink multicast groups can be listened in
-	 * on by anyone.  */
+	/* Below will not be present in the __u16 .nla_type, but can be
+	 * triggered on in <struct>_to_skb resp. <struct>_from_attrs */
+
+	/* To exclude "sensitive" information from broadcasts, or on
+	 * unpriviledged get requests.  This is useful because genetlink
+	 * multicast groups can be listened in on by anyone.  */
 	GENLA_F_SENSITIVE	= 1 << 16,
+
+	/* INVARIAN options cannot be changed at runtime.
+	 * Useful to share an attribute policy and struct definition,
+	 * between some "create" and "change" commands,
+	 * but disallow certain fields to be changed online.
+	 */
+	GENLA_F_INVARIANT	= 1 << 17,
 };
 
 #define __nla_type(x)	((__u16)((__u16)(x) & (__u16)NLA_TYPE_MASK))
Signature · 1 line
1.7.4.1
author maintainer
#16 lore raw

PATCH 16/16 drbd: Fixed conn_lowest_minor

In reply to Philipp Reisner

It actually returned the lowest volume number. While doing that renamed a few wrongly named variables.

---
 drivers/block/drbd/drbd_main.c  |   12 +++++++-----
 drivers/block/drbd/drbd_nl.c    |    4 ++--
 drivers/block/drbd/drbd_state.c |    8 ++++----
 3 files changed, 13 insertions(+), 11 deletions(-)
drivers/block/drbd/drbd_main.c +7 -5
index b1de7e8..4d6207a 100644
@@ -434,7 +434,7 @@ void tl_clear(struct drbd_tconn *tconn)
 	struct drbd_conf *mdev;
 	struct list_head *le, *tle;
 	struct drbd_request *r;
-	int minor;
+	int vnr;
 
 	spin_lock_irq(&tconn->req_lock);
 
@@ -453,7 +453,7 @@ void tl_clear(struct drbd_tconn *tconn)
 	}
 
 	/* ensure bit indicating barrier is required is clear */
-	idr_for_each_entry(&tconn->volumes, mdev, minor)
+	idr_for_each_entry(&tconn->volumes, mdev, vnr)
 		clear_bit(CREATE_BARRIER, &mdev->flags);
 
 	spin_unlock_irq(&tconn->req_lock);
@@ -634,11 +634,13 @@ char *drbd_task_to_thread_name(struct drbd_tconn *tconn, struct task_struct *tas
 
 int conn_lowest_minor(struct drbd_tconn *tconn)
 {
-	int minor = 0;
+	int vnr = 0;
+	struct drbd_conf *mdev;
 
-	if (!idr_get_next(&tconn->volumes, &minor))
+	mdev = idr_get_next(&tconn->volumes, &vnr);
+	if (!mdev)
 		return -1;
-	return minor;
+	return mdev_to_minor(mdev);
 }
 
 #ifdef CONFIG_SMP
drivers/block/drbd/drbd_nl.c +2 -2
index ab22019..fe4b106 100644
@@ -361,9 +361,9 @@ int drbd_khelper(struct drbd_conf *mdev, char *cmd)
 static void conn_md_sync(struct drbd_tconn *tconn)
 {
 	struct drbd_conf *mdev;
-	int minor;
+	int vnr;
 
-	idr_for_each_entry(&tconn->volumes, mdev, minor)
+	idr_for_each_entry(&tconn->volumes, mdev, vnr)
 		drbd_md_sync(mdev);
 }
 
drivers/block/drbd/drbd_state.c +4 -4
index c4a0710..42a94cd 100644
@@ -51,9 +51,9 @@ static union drbd_state sanitize_state(struct drbd_conf *mdev, union drbd_state
 bool conn_all_vols_unconf(struct drbd_tconn *tconn)
 {
 	struct drbd_conf *mdev;
-	int minor;
+	int vnr;
 
-	idr_for_each_entry(&tconn->volumes, mdev, minor) {
+	idr_for_each_entry(&tconn->volumes, mdev, vnr) {
 		if (mdev->state.disk != D_DISKLESS ||
 		    mdev->state.conn != C_STANDALONE ||
 		    mdev->state.role != R_SECONDARY)
@@ -333,9 +333,9 @@ static void print_state_change(struct drbd_conf *mdev, union drbd_state os, unio
 static bool vol_has_primary_peer(struct drbd_tconn *tconn)
 {
 	struct drbd_conf *mdev;
-	int minor;
+	int vnr;
 
-	idr_for_each_entry(&tconn->volumes, mdev, minor) {
+	idr_for_each_entry(&tconn->volumes, mdev, vnr) {
 		if (mdev->state.peer == R_PRIMARY)
 			return true;
 	}
Signature · 1 line
1.7.4.1