提交 4bc76048 编写于 作者: A Andreas Gruenbacher 提交者: Philipp Reisner

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: NAndreas Gruenbacher <agruen@linbit.com>
Signed-off-by: NPhilipp Reisner <philipp.reisner@linbit.com>
上级 803ea134
...@@ -1211,9 +1211,9 @@ extern void drbd_free_resource(struct drbd_resource *resource); ...@@ -1211,9 +1211,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 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 struct drbd_connection *conn_create(const char *name, struct res_opts *res_opts);
extern void drbd_destroy_connection(struct kref *kref); 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, extern struct drbd_connection *conn_get_by_addrs(void *my_addr, int my_addr_len,
void *peer_addr, int peer_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 drbd_destroy_resource(struct kref *kref);
extern void conn_free_crypto(struct drbd_connection *connection); extern void conn_free_crypto(struct drbd_connection *connection);
......
...@@ -2405,9 +2405,8 @@ static void drbd_init_workqueue(struct drbd_work_queue* wq) ...@@ -2405,9 +2405,8 @@ static void drbd_init_workqueue(struct drbd_work_queue* wq)
init_waitqueue_head(&wq->q_wait); 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; struct drbd_resource *resource;
if (!name || !name[0]) if (!name || !name[0])
...@@ -2416,15 +2415,14 @@ struct drbd_connection *conn_get_by_name(const char *name) ...@@ -2416,15 +2415,14 @@ struct drbd_connection *conn_get_by_name(const char *name)
rcu_read_lock(); rcu_read_lock();
for_each_resource_rcu(resource, &drbd_resources) { for_each_resource_rcu(resource, &drbd_resources) {
if (!strcmp(resource->name, name)) { if (!strcmp(resource->name, name)) {
connection = first_connection(resource); kref_get(&resource->kref);
kref_get(&connection->kref);
goto found; goto found;
} }
} }
connection = NULL; resource = NULL;
found: found:
rcu_read_unlock(); rcu_read_unlock();
return connection; return resource;
} }
struct drbd_connection *conn_get_by_addrs(void *my_addr, int my_addr_len, struct drbd_connection *conn_get_by_addrs(void *my_addr, int my_addr_len,
......
...@@ -104,6 +104,7 @@ static struct drbd_config_context { ...@@ -104,6 +104,7 @@ static struct drbd_config_context {
struct drbd_genlmsghdr *reply_dh; struct drbd_genlmsghdr *reply_dh;
/* resolved from attributes, if possible */ /* resolved from attributes, if possible */
struct drbd_device *device; struct drbd_device *device;
struct drbd_resource *resource;
struct drbd_connection *connection; struct drbd_connection *connection;
} adm_ctx; } adm_ctx;
...@@ -213,13 +214,19 @@ static int drbd_adm_prepare(struct sk_buff *skb, struct genl_info *info, ...@@ -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.minor = d_in->minor;
adm_ctx.device = minor_to_device(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)) { if (!adm_ctx.device && (flags & DRBD_ADM_NEED_MINOR)) {
drbd_msg_put_info("unknown minor"); drbd_msg_put_info("unknown minor");
return ERR_MINOR_INVALID; 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"); drbd_msg_put_info("unknown resource");
if (adm_ctx.resource_name) if (adm_ctx.resource_name)
return ERR_RES_NOT_KNOWN; return ERR_RES_NOT_KNOWN;
...@@ -247,10 +254,10 @@ static int drbd_adm_prepare(struct sk_buff *skb, struct genl_info *info, ...@@ -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 */ /* some more paranoia, if the request was over-determined */
if (adm_ctx.device && adm_ctx.connection && if (adm_ctx.device && adm_ctx.resource &&
first_peer_device(adm_ctx.device)->connection != adm_ctx.connection) { adm_ctx.device->resource != adm_ctx.resource) {
pr_warning("request: minor=%u, resource=%s; but that minor belongs to connection %s\n", pr_warning("request: minor=%u, resource=%s; but that minor belongs to resource %s\n",
adm_ctx.minor, adm_ctx.resource_name, adm_ctx.minor, adm_ctx.resource->name,
adm_ctx.device->resource->name); adm_ctx.device->resource->name);
drbd_msg_put_info("minor exists in different resource"); drbd_msg_put_info("minor exists in different resource");
return ERR_INVALID_REQUEST; return ERR_INVALID_REQUEST;
...@@ -280,6 +287,10 @@ static int drbd_adm_finish(struct genl_info *info, int retcode) ...@@ -280,6 +287,10 @@ static int drbd_adm_finish(struct genl_info *info, int retcode)
kref_put(&adm_ctx.connection->kref, drbd_destroy_connection); kref_put(&adm_ctx.connection->kref, drbd_destroy_connection);
adm_ctx.connection = NULL; 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) if (!adm_ctx.reply_skb)
return -ENOMEM; return -ENOMEM;
...@@ -3034,7 +3045,7 @@ int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -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; const unsigned hdrlen = GENL_HDRLEN + GENL_MAGIC_FAMILY_HDRSZ;
struct nlattr *nla; struct nlattr *nla;
const char *resource_name; const char *resource_name;
struct drbd_connection *connection; struct drbd_resource *resource;
int maxtype; int maxtype;
/* Is this a followup call? */ /* Is this a followup call? */
...@@ -3063,18 +3074,19 @@ int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -3063,18 +3074,19 @@ int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb)
if (!nla) if (!nla)
return -EINVAL; return -EINVAL;
resource_name = nla_data(nla); resource_name = nla_data(nla);
connection = conn_get_by_name(resource_name); if (!*resource_name)
return -ENODEV;
if (!connection) resource = drbd_find_resource(resource_name);
if (!resource)
return -ENODEV; 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: /* prime iterators, and set "filter" mode mark:
* only dump this connection. */ * only dump this connection. */
cb->args[0] = (long)connection; cb->args[0] = (long)resource;
/* cb->args[1] = 0; passed in this way. */ /* cb->args[1] = 0; passed in this way. */
cb->args[2] = (long)connection; cb->args[2] = (long)resource;
dump: dump:
return get_one_status(skb, cb); return get_one_status(skb, cb);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册