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 15/26] drbd: Replace conn_get_by_name() with drbd_find_resource()
Date: Fri, 20 Dec 2013 13:29:12 +0100 [thread overview]
Message-ID: <1387542563-6833-16-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>
So far, connections and resources always come in pairs, but in the future with
multiple connections per resource, the names will stick with the resources.
Signed-off-by: Andreas Gruenbacher <agruen@linbit.com>
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
---
drivers/block/drbd/drbd_int.h | 2 +-
drivers/block/drbd/drbd_main.c | 10 ++++------
drivers/block/drbd/drbd_nl.c | 38 +++++++++++++++++++++++++-------------
3 files changed, 30 insertions(+), 20 deletions(-)
diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
index 8b57e0b..1a1dd41 100644
--- a/drivers/block/drbd/drbd_int.h
+++ b/drivers/block/drbd/drbd_int.h
@@ -1206,9 +1206,9 @@ extern void drbd_free_resource(struct drbd_resource *resource);
extern int set_resource_options(struct drbd_connection *connection, struct res_opts *res_opts);
extern struct drbd_connection *conn_create(const char *name, struct res_opts *res_opts);
extern void drbd_destroy_connection(struct kref *kref);
-struct drbd_connection *conn_get_by_name(const char *name);
extern struct drbd_connection *conn_get_by_addrs(void *my_addr, int my_addr_len,
void *peer_addr, int peer_addr_len);
+extern struct drbd_resource *drbd_find_resource(const char *name);
extern void drbd_destroy_resource(struct kref *kref);
extern void conn_free_crypto(struct drbd_connection *connection);
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
index fe16e6d..dd9fe7a 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -2407,9 +2407,8 @@ static void drbd_init_workqueue(struct drbd_work_queue* wq)
init_waitqueue_head(&wq->q_wait);
}
-struct drbd_connection *conn_get_by_name(const char *name)
+struct drbd_resource *drbd_find_resource(const char *name)
{
- struct drbd_connection *connection;
struct drbd_resource *resource;
if (!name || !name[0])
@@ -2418,15 +2417,14 @@ struct drbd_connection *conn_get_by_name(const char *name)
rcu_read_lock();
for_each_resource_rcu(resource, &drbd_resources) {
if (!strcmp(resource->name, name)) {
- connection = first_connection(resource);
- kref_get(&connection->kref);
+ kref_get(&resource->kref);
goto found;
}
}
- connection = NULL;
+ resource = NULL;
found:
rcu_read_unlock();
- return connection;
+ return resource;
}
struct drbd_connection *conn_get_by_addrs(void *my_addr, int my_addr_len,
diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
index 6b0aa47..d7c7c24 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -104,6 +104,7 @@ static struct drbd_config_context {
struct drbd_genlmsghdr *reply_dh;
/* resolved from attributes, if possible */
struct drbd_device *device;
+ struct drbd_resource *resource;
struct drbd_connection *connection;
} adm_ctx;
@@ -213,13 +214,19 @@ static int drbd_adm_prepare(struct sk_buff *skb, struct genl_info *info,
adm_ctx.minor = d_in->minor;
adm_ctx.device = minor_to_device(d_in->minor);
- adm_ctx.connection = conn_get_by_name(adm_ctx.resource_name);
+ if (adm_ctx.resource_name) {
+ adm_ctx.resource = drbd_find_resource(adm_ctx.resource_name);
+ if (adm_ctx.resource) {
+ adm_ctx.connection = first_connection(adm_ctx.resource);
+ kref_get(&adm_ctx.connection->kref);
+ }
+ }
if (!adm_ctx.device && (flags & DRBD_ADM_NEED_MINOR)) {
drbd_msg_put_info("unknown minor");
return ERR_MINOR_INVALID;
}
- if (!adm_ctx.connection && (flags & DRBD_ADM_NEED_RESOURCE)) {
+ if (!adm_ctx.resource && (flags & DRBD_ADM_NEED_RESOURCE)) {
drbd_msg_put_info("unknown resource");
if (adm_ctx.resource_name)
return ERR_RES_NOT_KNOWN;
@@ -247,10 +254,10 @@ static int drbd_adm_prepare(struct sk_buff *skb, struct genl_info *info,
}
/* some more paranoia, if the request was over-determined */
- if (adm_ctx.device && adm_ctx.connection &&
- first_peer_device(adm_ctx.device)->connection != adm_ctx.connection) {
- pr_warning("request: minor=%u, resource=%s; but that minor belongs to connection %s\n",
- adm_ctx.minor, adm_ctx.resource_name,
+ if (adm_ctx.device && adm_ctx.resource &&
+ adm_ctx.device->resource != adm_ctx.resource) {
+ pr_warning("request: minor=%u, resource=%s; but that minor belongs to resource %s\n",
+ adm_ctx.minor, adm_ctx.resource->name,
adm_ctx.device->resource->name);
drbd_msg_put_info("minor exists in different resource");
return ERR_INVALID_REQUEST;
@@ -280,6 +287,10 @@ static int drbd_adm_finish(struct genl_info *info, int retcode)
kref_put(&adm_ctx.connection->kref, drbd_destroy_connection);
adm_ctx.connection = NULL;
}
+ if (adm_ctx.resource) {
+ kref_put(&adm_ctx.resource->kref, drbd_destroy_resource);
+ adm_ctx.resource = NULL;
+ }
if (!adm_ctx.reply_skb)
return -ENOMEM;
@@ -3034,7 +3045,7 @@ int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb)
const unsigned hdrlen = GENL_HDRLEN + GENL_MAGIC_FAMILY_HDRSZ;
struct nlattr *nla;
const char *resource_name;
- struct drbd_connection *connection;
+ struct drbd_resource *resource;
int maxtype;
/* Is this a followup call? */
@@ -3063,18 +3074,19 @@ int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb)
if (!nla)
return -EINVAL;
resource_name = nla_data(nla);
- connection = conn_get_by_name(resource_name);
-
- if (!connection)
+ if (!*resource_name)
+ return -ENODEV;
+ resource = drbd_find_resource(resource_name);
+ if (!resource)
return -ENODEV;
- kref_put(&connection->kref, drbd_destroy_connection); /* get_one_status() (re)validates connection by itself */
+ kref_put(&resource->kref, drbd_destroy_resource); /* get_one_status() revalidates the resource */
/* prime iterators, and set "filter" mode mark:
* only dump this connection. */
- cb->args[0] = (long)connection;
+ cb->args[0] = (long)resource;
/* cb->args[1] = 0; passed in this way. */
- cb->args[2] = (long)connection;
+ cb->args[2] = (long)resource;
dump:
return get_one_status(skb, cb);
--
1.7.9.5
next prev parent reply other threads:[~2013-12-20 12:41 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 ` Philipp Reisner [this message]
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 ` [PATCH 24/26] drbd: get_one_status(): Iterate over resource->devices instead of connection->peer_devices Philipp Reisner
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-16-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®