aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@linbit.com>2011-06-13 08:27:45 -0400
committerPhilipp Reisner <philipp.reisner@linbit.com>2014-02-17 10:44:57 -0500
commit4bc760488c1e9c65c9f6dea1ae8a7b94b9eaebe1 (patch)
tree3ce56e7e187fac5571d825a00df163572ed71f92
parent803ea1348e412a1e35cfbb891f4514b74e7af460 (diff)
drbd: Replace conn_get_by_name() with drbd_find_resource()
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>
-rw-r--r--drivers/block/drbd/drbd_int.h2
-rw-r--r--drivers/block/drbd/drbd_main.c10
-rw-r--r--drivers/block/drbd/drbd_nl.c38
3 files changed, 30 insertions, 20 deletions
diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
index 73a7a6e8f715..1bca8ec5f65b 100644
--- a/drivers/block/drbd/drbd_int.h
+++ b/drivers/block/drbd/drbd_int.h
@@ -1211,9 +1211,9 @@ extern void drbd_free_resource(struct drbd_resource *resource);
1211extern int set_resource_options(struct drbd_connection *connection, struct res_opts *res_opts); 1211extern int set_resource_options(struct drbd_connection *connection, struct res_opts *res_opts);
1212extern struct drbd_connection *conn_create(const char *name, struct res_opts *res_opts); 1212extern struct drbd_connection *conn_create(const char *name, struct res_opts *res_opts);
1213extern void drbd_destroy_connection(struct kref *kref); 1213extern void drbd_destroy_connection(struct kref *kref);
1214struct drbd_connection *conn_get_by_name(const char *name);
1215extern struct drbd_connection *conn_get_by_addrs(void *my_addr, int my_addr_len, 1214extern struct drbd_connection *conn_get_by_addrs(void *my_addr, int my_addr_len,
1216 void *peer_addr, int peer_addr_len); 1215 void *peer_addr, int peer_addr_len);
1216extern struct drbd_resource *drbd_find_resource(const char *name);
1217extern void drbd_destroy_resource(struct kref *kref); 1217extern void drbd_destroy_resource(struct kref *kref);
1218extern void conn_free_crypto(struct drbd_connection *connection); 1218extern void conn_free_crypto(struct drbd_connection *connection);
1219 1219
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
index 92479bdc3e78..2be5355dede2 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -2405,9 +2405,8 @@ static void drbd_init_workqueue(struct drbd_work_queue* wq)
2405 init_waitqueue_head(&wq->q_wait); 2405 init_waitqueue_head(&wq->q_wait);
2406} 2406}
2407 2407
2408struct drbd_connection *conn_get_by_name(const char *name) 2408struct drbd_resource *drbd_find_resource(const char *name)
2409{ 2409{
2410 struct drbd_connection *connection;
2411 struct drbd_resource *resource; 2410 struct drbd_resource *resource;
2412 2411
2413 if (!name || !name[0]) 2412 if (!name || !name[0])
@@ -2416,15 +2415,14 @@ struct drbd_connection *conn_get_by_name(const char *name)
2416 rcu_read_lock(); 2415 rcu_read_lock();
2417 for_each_resource_rcu(resource, &drbd_resources) { 2416 for_each_resource_rcu(resource, &drbd_resources) {
2418 if (!strcmp(resource->name, name)) { 2417 if (!strcmp(resource->name, name)) {
2419 connection = first_connection(resource); 2418 kref_get(&resource->kref);
2420 kref_get(&connection->kref);
2421 goto found; 2419 goto found;
2422 } 2420 }
2423 } 2421 }
2424 connection = NULL; 2422 resource = NULL;
2425found: 2423found:
2426 rcu_read_unlock(); 2424 rcu_read_unlock();
2427 return connection; 2425 return resource;
2428} 2426}
2429 2427
2430struct drbd_connection *conn_get_by_addrs(void *my_addr, int my_addr_len, 2428struct 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 bbd63e9f51d8..cbf745c7bc2f 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -104,6 +104,7 @@ static struct drbd_config_context {
104 struct drbd_genlmsghdr *reply_dh; 104 struct drbd_genlmsghdr *reply_dh;
105 /* resolved from attributes, if possible */ 105 /* resolved from attributes, if possible */
106 struct drbd_device *device; 106 struct drbd_device *device;
107 struct drbd_resource *resource;
107 struct drbd_connection *connection; 108 struct drbd_connection *connection;
108} adm_ctx; 109} adm_ctx;
109 110
@@ -213,13 +214,19 @@ static int drbd_adm_prepare(struct sk_buff *skb, struct genl_info *info,
213 214
214 adm_ctx.minor = d_in->minor; 215 adm_ctx.minor = d_in->minor;
215 adm_ctx.device = minor_to_device(d_in->minor); 216 adm_ctx.device = minor_to_device(d_in->minor);
216 adm_ctx.connection = conn_get_by_name(adm_ctx.resource_name); 217 if (adm_ctx.resource_name) {
218 adm_ctx.resource = drbd_find_resource(adm_ctx.resource_name);
219 if (adm_ctx.resource) {
220 adm_ctx.connection = first_connection(adm_ctx.resource);
221 kref_get(&adm_ctx.connection->kref);
222 }
223 }
217 224
218 if (!adm_ctx.device && (flags & DRBD_ADM_NEED_MINOR)) { 225 if (!adm_ctx.device && (flags & DRBD_ADM_NEED_MINOR)) {
219 drbd_msg_put_info("unknown minor"); 226 drbd_msg_put_info("unknown minor");
220 return ERR_MINOR_INVALID; 227 return ERR_MINOR_INVALID;
221 } 228 }
222 if (!adm_ctx.connection && (flags & DRBD_ADM_NEED_RESOURCE)) { 229 if (!adm_ctx.resource && (flags & DRBD_ADM_NEED_RESOURCE)) {
223 drbd_msg_put_info("unknown resource"); 230 drbd_msg_put_info("unknown resource");
224 if (adm_ctx.resource_name) 231 if (adm_ctx.resource_name)
225 return ERR_RES_NOT_KNOWN; 232 return ERR_RES_NOT_KNOWN;
@@ -247,10 +254,10 @@ static int drbd_adm_prepare(struct sk_buff *skb, struct genl_info *info,
247 } 254 }
248 255
249 /* some more paranoia, if the request was over-determined */ 256 /* some more paranoia, if the request was over-determined */
250 if (adm_ctx.device && adm_ctx.connection && 257 if (adm_ctx.device && adm_ctx.resource &&
251 first_peer_device(adm_ctx.device)->connection != adm_ctx.connection) { 258 adm_ctx.device->resource != adm_ctx.resource) {
252 pr_warning("request: minor=%u, resource=%s; but that minor belongs to connection %s\n", 259 pr_warning("request: minor=%u, resource=%s; but that minor belongs to resource %s\n",
253 adm_ctx.minor, adm_ctx.resource_name, 260 adm_ctx.minor, adm_ctx.resource->name,
254 adm_ctx.device->resource->name); 261 adm_ctx.device->resource->name);
255 drbd_msg_put_info("minor exists in different resource"); 262 drbd_msg_put_info("minor exists in different resource");
256 return ERR_INVALID_REQUEST; 263 return ERR_INVALID_REQUEST;
@@ -280,6 +287,10 @@ static int drbd_adm_finish(struct genl_info *info, int retcode)
280 kref_put(&adm_ctx.connection->kref, drbd_destroy_connection); 287 kref_put(&adm_ctx.connection->kref, drbd_destroy_connection);
281 adm_ctx.connection = NULL; 288 adm_ctx.connection = NULL;
282 } 289 }
290 if (adm_ctx.resource) {
291 kref_put(&adm_ctx.resource->kref, drbd_destroy_resource);
292 adm_ctx.resource = NULL;
293 }
283 294
284 if (!adm_ctx.reply_skb) 295 if (!adm_ctx.reply_skb)
285 return -ENOMEM; 296 return -ENOMEM;
@@ -3034,7 +3045,7 @@ int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb)
3034 const unsigned hdrlen = GENL_HDRLEN + GENL_MAGIC_FAMILY_HDRSZ; 3045 const unsigned hdrlen = GENL_HDRLEN + GENL_MAGIC_FAMILY_HDRSZ;
3035 struct nlattr *nla; 3046 struct nlattr *nla;
3036 const char *resource_name; 3047 const char *resource_name;
3037 struct drbd_connection *connection; 3048 struct drbd_resource *resource;
3038 int maxtype; 3049 int maxtype;
3039 3050
3040 /* Is this a followup call? */ 3051 /* Is this a followup call? */
@@ -3063,18 +3074,19 @@ int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb)
3063 if (!nla) 3074 if (!nla)
3064 return -EINVAL; 3075 return -EINVAL;
3065 resource_name = nla_data(nla); 3076 resource_name = nla_data(nla);
3066 connection = conn_get_by_name(resource_name); 3077 if (!*resource_name)
3067 3078 return -ENODEV;
3068 if (!connection) 3079 resource = drbd_find_resource(resource_name);
3080 if (!resource)
3069 return -ENODEV; 3081 return -ENODEV;
3070 3082
3071 kref_put(&connection->kref, drbd_destroy_connection); /* get_one_status() (re)validates connection by itself */ 3083 kref_put(&resource->kref, drbd_destroy_resource); /* get_one_status() revalidates the resource */
3072 3084
3073 /* prime iterators, and set "filter" mode mark: 3085 /* prime iterators, and set "filter" mode mark:
3074 * only dump this connection. */ 3086 * only dump this connection. */
3075 cb->args[0] = (long)connection; 3087 cb->args[0] = (long)resource;
3076 /* cb->args[1] = 0; passed in this way. */ 3088 /* cb->args[1] = 0; passed in this way. */
3077 cb->args[2] = (long)connection; 3089 cb->args[2] = (long)resource;
3078 3090
3079dump: 3091dump:
3080 return get_one_status(skb, cb); 3092 return get_one_status(skb, cb);