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 24/26] drbd: get_one_status(): Iterate over resource->devices instead of connection->peer_devices
Date: Fri, 20 Dec 2013 13:29:21 +0100	[thread overview]
Message-ID: <1387542563-6833-25-git-send-email-philipp.reisner@linbit.com> (raw)
In-Reply-To: <1387542563-6833-1-git-send-email-philipp.reisner@linbit.com>

From: Andreas Gruenbacher <agruen@linbit.com>

Signed-off-by: Andreas Gruenbacher <agruen@linbit.com>
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
---
 drivers/block/drbd/drbd_nl.c |   70 +++++++++++++++++++++++++++---------------
 1 file changed, 45 insertions(+), 25 deletions(-)

diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
index 12a65ce..f999e7c 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -2752,23 +2752,28 @@ int drbd_adm_outdate(struct sk_buff *skb, struct genl_info *info)
 	return drbd_adm_simple_request_state(skb, info, NS(disk, D_OUTDATED));
 }
 
-int nla_put_drbd_cfg_context(struct sk_buff *skb, struct drbd_connection *connection, unsigned vnr)
+static int nla_put_drbd_cfg_context(struct sk_buff *skb,
+				    struct drbd_resource *resource,
+				    struct drbd_connection *connection,
+				    struct drbd_device *device)
 {
 	struct nlattr *nla;
 	nla = nla_nest_start(skb, DRBD_NLA_CFG_CONTEXT);
 	if (!nla)
 		goto nla_put_failure;
-	if (vnr != VOLUME_UNSPECIFIED &&
-	    nla_put_u32(skb, T_ctx_volume, vnr))
+	if (device &&
+	    nla_put_u32(skb, T_ctx_volume, device->vnr))
 		goto nla_put_failure;
 	if (nla_put_string(skb, T_ctx_resource_name, connection->resource->name))
 		goto nla_put_failure;
-	if (connection->my_addr_len &&
-	    nla_put(skb, T_ctx_my_addr, connection->my_addr_len, &connection->my_addr))
-		goto nla_put_failure;
-	if (connection->peer_addr_len &&
-	    nla_put(skb, T_ctx_peer_addr, connection->peer_addr_len, &connection->peer_addr))
-		goto nla_put_failure;
+	if (connection) {
+		if (connection->my_addr_len &&
+		    nla_put(skb, T_ctx_my_addr, connection->my_addr_len, &connection->my_addr))
+			goto nla_put_failure;
+		if (connection->peer_addr_len &&
+		    nla_put(skb, T_ctx_peer_addr, connection->peer_addr_len, &connection->peer_addr))
+			goto nla_put_failure;
+	}
 	nla_nest_end(skb, nla);
 	return 0;
 
@@ -2778,9 +2783,22 @@ nla_put_failure:
 	return -EMSGSIZE;
 }
 
+/*
+ * Return the connection of @resource if @resource has exactly one connection.
+ */
+static struct drbd_connection *the_only_connection(struct drbd_resource *resource)
+{
+	struct list_head *connections = &resource->connections;
+
+	if (list_empty(connections) || connections->next->next != connections)
+		return NULL;
+	return list_first_entry(&resource->connections, struct drbd_connection, connections);
+}
+
 int nla_put_status_info(struct sk_buff *skb, struct drbd_device *device,
 		const struct sib_info *sib)
 {
+	struct drbd_resource *resource = device->resource;
 	struct state_info *si = NULL; /* for sizeof(si->member); */
 	struct nlattr *nla;
 	int got_ldev;
@@ -2804,7 +2822,7 @@ int nla_put_status_info(struct sk_buff *skb, struct drbd_device *device,
 
 	/* We need to add connection name and volume number information still.
 	 * Minor number is in drbd_genlmsghdr. */
-	if (nla_put_drbd_cfg_context(skb, first_peer_device(device)->connection, device->vnr))
+	if (nla_put_drbd_cfg_context(skb, resource, the_only_connection(resource), device))
 		goto nla_put_failure;
 
 	if (res_opts_to_skb(skb, &device->resource->res_opts, exclude_sensitive))
@@ -2922,19 +2940,17 @@ out:
 
 static int get_one_status(struct sk_buff *skb, struct netlink_callback *cb)
 {
-	struct drbd_peer_device *peer_device;
 	struct drbd_device *device;
 	struct drbd_genlmsghdr *dh;
 	struct drbd_resource *pos = (struct drbd_resource *)cb->args[0];
 	struct drbd_resource *resource = NULL;
-	struct drbd_connection *connection;
 	struct drbd_resource *tmp;
 	unsigned volume = cb->args[1];
 
 	/* Open coded, deferred, iteration:
 	 * for_each_resource_safe(resource, tmp, &drbd_resources) {
-	 *      connection = "first connection of resource";
-	 *	idr_for_each_entry(&connection->peer_devices, peer_device, i) {
+	 *      connection = "first connection of resource or undefined";
+	 *	idr_for_each_entry(&resource->devices, device, i) {
 	 *	  ...
 	 *	}
 	 * }
@@ -2969,9 +2985,8 @@ static int get_one_status(struct sk_buff *skb, struct netlink_callback *cb)
 	}
 	if (resource) {
 next_resource:
-		connection = first_connection(resource);
-		peer_device = idr_get_next(&connection->peer_devices, &volume);
-		if (!peer_device) {
+		device = idr_get_next(&resource->devices, &volume);
+		if (!device) {
 			/* No more volumes to dump on this resource.
 			 * Advance resource iterator. */
 			pos = list_entry_rcu(resource->resources.next,
@@ -2995,24 +3010,29 @@ next_resource:
 		if (!dh)
 			goto out;
 
-		if (!peer_device) {
+		if (!device) {
 			/* This is a connection without a single volume.
 			 * Suprisingly enough, it may have a network
 			 * configuration. */
-			struct net_conf *nc;
+			struct drbd_connection *connection;
+
 			dh->minor = -1U;
 			dh->ret_code = NO_ERROR;
-			if (nla_put_drbd_cfg_context(skb, connection, VOLUME_UNSPECIFIED))
-				goto cancel;
-			nc = rcu_dereference(connection->net_conf);
-			if (nc && net_conf_to_skb(skb, nc, 1) != 0)
+			connection = the_only_connection(resource);
+			if (nla_put_drbd_cfg_context(skb, resource, connection, NULL))
 				goto cancel;
+			if (connection) {
+				struct net_conf *nc;
+
+				nc = rcu_dereference(connection->net_conf);
+				if (nc && net_conf_to_skb(skb, nc, 1) != 0)
+					goto cancel;
+			}
 			goto done;
 		}
 
-		device = peer_device->device;
 		D_ASSERT(device, device->vnr == volume);
-		D_ASSERT(device, first_peer_device(device)->connection == connection);
+		D_ASSERT(device, device->resource == resource);
 
 		dh->minor = device_to_minor(device);
 		dh->ret_code = NO_ERROR;
-- 
1.7.9.5


  parent reply	other threads:[~2013-12-20 12:47 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-20 12:28 [PATCH 00/26] DRBD code reorganization Philipp Reisner
2013-12-20 12:28 ` [PATCH 01/26] drbd: Add missing error goto Philipp Reisner
2013-12-20 12:28 ` [PATCH 02/26] idr: Add new function idr_is_empty() Philipp Reisner
2013-12-20 12:29 ` [PATCH 03/26] drbd: Describe the future high-level structure of DRBD Philipp Reisner
2013-12-20 12:29 ` [PATCH 04/26] drbd: Split off on-the-wire protocol definitions Philipp Reisner
2013-12-20 12:29 ` [PATCH 05/26] drbd: Rename struct drbd_conf -> struct drbd_device Philipp Reisner
2013-12-20 12:29 ` [PATCH 06/26] drbd: Rename "mdev" to "device" Philipp Reisner
2013-12-20 12:29 ` [PATCH 07/26] drbd: Rename drbd_tconn -> drbd_connection Philipp Reisner
2013-12-20 12:29 ` [PATCH 08/26] drbd: Introduce "peer_device" object between "device" and "connection" Philipp Reisner
2013-12-20 12:29 ` [PATCH 09/26] drbd: Improve some function and variable naming Philipp Reisner
2013-12-20 12:29 ` [PATCH 10/26] drbd: Add struct drbd_resource Philipp Reisner
2013-12-20 12:29 ` [PATCH 11/26] drbd: drbd_adm_down(): Move valid resource name check to drbd_adm_prepare() Philipp Reisner
2013-12-20 12:29 ` [PATCH 12/26] drbd: Add struct drbd_device->resource Philipp Reisner
2013-12-20 12:29 ` [PATCH 13/26] drbd: Minor cleanup in conn_new_minor() Philipp Reisner
2013-12-20 12:29 ` [PATCH 14/26] drbd: Add struct drbd_resource->devices Philipp Reisner
2013-12-20 12:29 ` [PATCH 15/26] drbd: Replace conn_get_by_name() with drbd_find_resource() Philipp Reisner
2013-12-20 12:29 ` [PATCH 16/26] drbd: conn_try_disconnect(): Use parameter instead of the global variable Philipp Reisner
2013-12-20 12:29 ` [PATCH 17/26] drbd: Move resource options from connection to resource Philipp Reisner
2013-12-20 12:29 ` [PATCH 18/26] drbd: Turn connection->volumes into connection->peer_devices Philipp Reisner
2013-12-20 12:29 ` [PATCH 19/26] drbd: Remove the terrible DEV hack Philipp Reisner
2013-12-20 12:29 ` [PATCH 20/26] drbd: Turn drbd_printk() into a polymorphic macro Philipp Reisner
2013-12-20 12:29 ` [PATCH 21/26] drbd: Replace and remove the obsolete conn_() macros Philipp Reisner
2013-12-20 12:29 ` [PATCH 22/26] drbd: Add explicit device parameter to D_ASSERT Philipp Reisner
2013-12-20 12:29 ` [PATCH 23/26] drbd: Rename drbd_{create,delete}_minor -> drbd_{create,delete}_device Philipp Reisner
2013-12-20 12:29 ` Philipp Reisner [this message]
2013-12-20 12:29 ` [PATCH 25/26] drbd: drbd_adm_new_resource(): Check if resource exists, not if it has any connections Philipp Reisner
2013-12-20 12:29 ` [PATCH 26/26] drbd: drbd_create_device(): Take a resource instead of a connection argument 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=1387542563-6833-25-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®