Commit f8c76f6f authored by Yehuda Sadeh's avatar Yehuda Sadeh Committed by Sage Weil

ceph: make mon client statfs handling more generic

This is being done so that we could reuse the statfs
infrastructure with other requests that return values.
Signed-off-by: default avatarYehuda Sadeh <yehuda@hq.newdream.net>
Signed-off-by: default avatarSage Weil <sage@newdream.net>
parent dbad185d
...@@ -113,7 +113,7 @@ static int osdmap_show(struct seq_file *s, void *p) ...@@ -113,7 +113,7 @@ static int osdmap_show(struct seq_file *s, void *p)
static int monc_show(struct seq_file *s, void *p) static int monc_show(struct seq_file *s, void *p)
{ {
struct ceph_client *client = s->private; struct ceph_client *client = s->private;
struct ceph_mon_statfs_request *req; struct ceph_mon_generic_request *req;
struct ceph_mon_client *monc = &client->monc; struct ceph_mon_client *monc = &client->monc;
struct rb_node *rp; struct rb_node *rp;
...@@ -126,9 +126,14 @@ static int monc_show(struct seq_file *s, void *p) ...@@ -126,9 +126,14 @@ static int monc_show(struct seq_file *s, void *p)
if (monc->want_next_osdmap) if (monc->want_next_osdmap)
seq_printf(s, "want next osdmap\n"); seq_printf(s, "want next osdmap\n");
for (rp = rb_first(&monc->statfs_request_tree); rp; rp = rb_next(rp)) { for (rp = rb_first(&monc->generic_request_tree); rp; rp = rb_next(rp)) {
req = rb_entry(rp, struct ceph_mon_statfs_request, node); __u16 op;
req = rb_entry(rp, struct ceph_mon_generic_request, node);
op = le16_to_cpu(req->request->hdr.type);
if (op == CEPH_MSG_STATFS)
seq_printf(s, "%lld statfs\n", req->tid); seq_printf(s, "%lld statfs\n", req->tid);
else
seq_printf(s, "%lld unknown\n", req->tid);
} }
mutex_unlock(&monc->mutex); mutex_unlock(&monc->mutex);
......
...@@ -353,14 +353,14 @@ static void ceph_monc_handle_map(struct ceph_mon_client *monc, ...@@ -353,14 +353,14 @@ static void ceph_monc_handle_map(struct ceph_mon_client *monc,
/* /*
* statfs * statfs
*/ */
static struct ceph_mon_statfs_request *__lookup_statfs( static struct ceph_mon_generic_request *__lookup_generic_req(
struct ceph_mon_client *monc, u64 tid) struct ceph_mon_client *monc, u64 tid)
{ {
struct ceph_mon_statfs_request *req; struct ceph_mon_generic_request *req;
struct rb_node *n = monc->statfs_request_tree.rb_node; struct rb_node *n = monc->generic_request_tree.rb_node;
while (n) { while (n) {
req = rb_entry(n, struct ceph_mon_statfs_request, node); req = rb_entry(n, struct ceph_mon_generic_request, node);
if (tid < req->tid) if (tid < req->tid)
n = n->rb_left; n = n->rb_left;
else if (tid > req->tid) else if (tid > req->tid)
...@@ -371,16 +371,16 @@ static struct ceph_mon_statfs_request *__lookup_statfs( ...@@ -371,16 +371,16 @@ static struct ceph_mon_statfs_request *__lookup_statfs(
return NULL; return NULL;
} }
static void __insert_statfs(struct ceph_mon_client *monc, static void __insert_generic_request(struct ceph_mon_client *monc,
struct ceph_mon_statfs_request *new) struct ceph_mon_generic_request *new)
{ {
struct rb_node **p = &monc->statfs_request_tree.rb_node; struct rb_node **p = &monc->generic_request_tree.rb_node;
struct rb_node *parent = NULL; struct rb_node *parent = NULL;
struct ceph_mon_statfs_request *req = NULL; struct ceph_mon_generic_request *req = NULL;
while (*p) { while (*p) {
parent = *p; parent = *p;
req = rb_entry(parent, struct ceph_mon_statfs_request, node); req = rb_entry(parent, struct ceph_mon_generic_request, node);
if (new->tid < req->tid) if (new->tid < req->tid)
p = &(*p)->rb_left; p = &(*p)->rb_left;
else if (new->tid > req->tid) else if (new->tid > req->tid)
...@@ -390,13 +390,13 @@ static void __insert_statfs(struct ceph_mon_client *monc, ...@@ -390,13 +390,13 @@ static void __insert_statfs(struct ceph_mon_client *monc,
} }
rb_link_node(&new->node, parent, p); rb_link_node(&new->node, parent, p);
rb_insert_color(&new->node, &monc->statfs_request_tree); rb_insert_color(&new->node, &monc->generic_request_tree);
} }
static void release_statfs_request(struct kref *kref) static void release_generic_request(struct kref *kref)
{ {
struct ceph_mon_statfs_request *req = struct ceph_mon_generic_request *req =
container_of(kref, struct ceph_mon_statfs_request, kref); container_of(kref, struct ceph_mon_generic_request, kref);
if (req->reply) if (req->reply)
ceph_msg_put(req->reply); ceph_msg_put(req->reply);
...@@ -404,33 +404,33 @@ static void release_statfs_request(struct kref *kref) ...@@ -404,33 +404,33 @@ static void release_statfs_request(struct kref *kref)
ceph_msg_put(req->request); ceph_msg_put(req->request);
} }
static void put_statfs_request(struct ceph_mon_statfs_request *req) static void put_generic_request(struct ceph_mon_generic_request *req)
{ {
kref_put(&req->kref, release_statfs_request); kref_put(&req->kref, release_generic_request);
} }
static void get_statfs_request(struct ceph_mon_statfs_request *req) static void get_generic_request(struct ceph_mon_generic_request *req)
{ {
kref_get(&req->kref); kref_get(&req->kref);
} }
static struct ceph_msg *get_statfs_reply(struct ceph_connection *con, static struct ceph_msg *get_generic_reply(struct ceph_connection *con,
struct ceph_msg_header *hdr, struct ceph_msg_header *hdr,
int *skip) int *skip)
{ {
struct ceph_mon_client *monc = con->private; struct ceph_mon_client *monc = con->private;
struct ceph_mon_statfs_request *req; struct ceph_mon_generic_request *req;
u64 tid = le64_to_cpu(hdr->tid); u64 tid = le64_to_cpu(hdr->tid);
struct ceph_msg *m; struct ceph_msg *m;
mutex_lock(&monc->mutex); mutex_lock(&monc->mutex);
req = __lookup_statfs(monc, tid); req = __lookup_generic_req(monc, tid);
if (!req) { if (!req) {
dout("get_statfs_reply %lld dne\n", tid); dout("get_generic_reply %lld dne\n", tid);
*skip = 1; *skip = 1;
m = NULL; m = NULL;
} else { } else {
dout("get_statfs_reply %lld got %p\n", tid, req->reply); dout("get_generic_reply %lld got %p\n", tid, req->reply);
m = ceph_msg_get(req->reply); m = ceph_msg_get(req->reply);
/* /*
* we don't need to track the connection reading into * we don't need to track the connection reading into
...@@ -445,7 +445,7 @@ static struct ceph_msg *get_statfs_reply(struct ceph_connection *con, ...@@ -445,7 +445,7 @@ static struct ceph_msg *get_statfs_reply(struct ceph_connection *con,
static void handle_statfs_reply(struct ceph_mon_client *monc, static void handle_statfs_reply(struct ceph_mon_client *monc,
struct ceph_msg *msg) struct ceph_msg *msg)
{ {
struct ceph_mon_statfs_request *req; struct ceph_mon_generic_request *req;
struct ceph_mon_statfs_reply *reply = msg->front.iov_base; struct ceph_mon_statfs_reply *reply = msg->front.iov_base;
u64 tid = le64_to_cpu(msg->hdr.tid); u64 tid = le64_to_cpu(msg->hdr.tid);
...@@ -454,21 +454,21 @@ static void handle_statfs_reply(struct ceph_mon_client *monc, ...@@ -454,21 +454,21 @@ static void handle_statfs_reply(struct ceph_mon_client *monc,
dout("handle_statfs_reply %p tid %llu\n", msg, tid); dout("handle_statfs_reply %p tid %llu\n", msg, tid);
mutex_lock(&monc->mutex); mutex_lock(&monc->mutex);
req = __lookup_statfs(monc, tid); req = __lookup_generic_req(monc, tid);
if (req) { if (req) {
*req->buf = reply->st; *(struct ceph_statfs *)req->buf = reply->st;
req->result = 0; req->result = 0;
get_statfs_request(req); get_generic_request(req);
} }
mutex_unlock(&monc->mutex); mutex_unlock(&monc->mutex);
if (req) { if (req) {
complete(&req->completion); complete(&req->completion);
put_statfs_request(req); put_generic_request(req);
} }
return; return;
bad: bad:
pr_err("corrupt statfs reply, no tid\n"); pr_err("corrupt generic reply, no tid\n");
ceph_msg_dump(msg); ceph_msg_dump(msg);
} }
...@@ -477,7 +477,7 @@ static void handle_statfs_reply(struct ceph_mon_client *monc, ...@@ -477,7 +477,7 @@ static void handle_statfs_reply(struct ceph_mon_client *monc,
*/ */
int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf) int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
{ {
struct ceph_mon_statfs_request *req; struct ceph_mon_generic_request *req;
struct ceph_mon_statfs *h; struct ceph_mon_statfs *h;
int err; int err;
...@@ -509,8 +509,8 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf) ...@@ -509,8 +509,8 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
mutex_lock(&monc->mutex); mutex_lock(&monc->mutex);
req->tid = ++monc->last_tid; req->tid = ++monc->last_tid;
req->request->hdr.tid = cpu_to_le64(req->tid); req->request->hdr.tid = cpu_to_le64(req->tid);
__insert_statfs(monc, req); __insert_generic_request(monc, req);
monc->num_statfs_requests++; monc->num_generic_requests++;
mutex_unlock(&monc->mutex); mutex_unlock(&monc->mutex);
/* send request and wait */ /* send request and wait */
...@@ -518,28 +518,28 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf) ...@@ -518,28 +518,28 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
err = wait_for_completion_interruptible(&req->completion); err = wait_for_completion_interruptible(&req->completion);
mutex_lock(&monc->mutex); mutex_lock(&monc->mutex);
rb_erase(&req->node, &monc->statfs_request_tree); rb_erase(&req->node, &monc->generic_request_tree);
monc->num_statfs_requests--; monc->num_generic_requests--;
mutex_unlock(&monc->mutex); mutex_unlock(&monc->mutex);
if (!err) if (!err)
err = req->result; err = req->result;
out: out:
kref_put(&req->kref, release_statfs_request); kref_put(&req->kref, release_generic_request);
return err; return err;
} }
/* /*
* Resend pending statfs requests. * Resend pending statfs requests.
*/ */
static void __resend_statfs(struct ceph_mon_client *monc) static void __resend_generic_request(struct ceph_mon_client *monc)
{ {
struct ceph_mon_statfs_request *req; struct ceph_mon_generic_request *req;
struct rb_node *p; struct rb_node *p;
for (p = rb_first(&monc->statfs_request_tree); p; p = rb_next(p)) { for (p = rb_first(&monc->generic_request_tree); p; p = rb_next(p)) {
req = rb_entry(p, struct ceph_mon_statfs_request, node); req = rb_entry(p, struct ceph_mon_generic_request, node);
ceph_con_send(monc->con, ceph_msg_get(req->request)); ceph_con_send(monc->con, ceph_msg_get(req->request));
} }
} }
...@@ -652,8 +652,8 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl) ...@@ -652,8 +652,8 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
monc->sub_sent = 0; monc->sub_sent = 0;
INIT_DELAYED_WORK(&monc->delayed_work, delayed_work); INIT_DELAYED_WORK(&monc->delayed_work, delayed_work);
monc->statfs_request_tree = RB_ROOT; monc->generic_request_tree = RB_ROOT;
monc->num_statfs_requests = 0; monc->num_generic_requests = 0;
monc->last_tid = 0; monc->last_tid = 0;
monc->have_mdsmap = 0; monc->have_mdsmap = 0;
...@@ -717,7 +717,7 @@ static void handle_auth_reply(struct ceph_mon_client *monc, ...@@ -717,7 +717,7 @@ static void handle_auth_reply(struct ceph_mon_client *monc,
monc->client->msgr->inst.name.num = monc->auth->global_id; monc->client->msgr->inst.name.num = monc->auth->global_id;
__send_subscribe(monc); __send_subscribe(monc);
__resend_statfs(monc); __resend_generic_request(monc);
} }
mutex_unlock(&monc->mutex); mutex_unlock(&monc->mutex);
} }
...@@ -809,7 +809,7 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con, ...@@ -809,7 +809,7 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con,
m = ceph_msg_get(monc->m_subscribe_ack); m = ceph_msg_get(monc->m_subscribe_ack);
break; break;
case CEPH_MSG_STATFS_REPLY: case CEPH_MSG_STATFS_REPLY:
return get_statfs_reply(con, hdr, skip); return get_generic_reply(con, hdr, skip);
case CEPH_MSG_AUTH_REPLY: case CEPH_MSG_AUTH_REPLY:
m = ceph_msg_get(monc->m_auth_reply); m = ceph_msg_get(monc->m_auth_reply);
break; break;
......
...@@ -22,7 +22,7 @@ struct ceph_monmap { ...@@ -22,7 +22,7 @@ struct ceph_monmap {
}; };
struct ceph_mon_client; struct ceph_mon_client;
struct ceph_mon_statfs_request; struct ceph_mon_generic_request;
/* /*
...@@ -40,15 +40,16 @@ struct ceph_mon_request { ...@@ -40,15 +40,16 @@ struct ceph_mon_request {
}; };
/* /*
* statfs() is done a bit differently because we need to get data back * ceph_mon_generic_request is being used for the statfs and poolop requests
* which are bening done a bit differently because we need to get data back
* to the caller * to the caller
*/ */
struct ceph_mon_statfs_request { struct ceph_mon_generic_request {
struct kref kref; struct kref kref;
u64 tid; u64 tid;
struct rb_node node; struct rb_node node;
int result; int result;
struct ceph_statfs *buf; void *buf;
struct completion completion; struct completion completion;
struct ceph_msg *request; /* original request */ struct ceph_msg *request; /* original request */
struct ceph_msg *reply; /* and reply */ struct ceph_msg *reply; /* and reply */
...@@ -71,9 +72,9 @@ struct ceph_mon_client { ...@@ -71,9 +72,9 @@ struct ceph_mon_client {
struct ceph_connection *con; struct ceph_connection *con;
bool have_fsid; bool have_fsid;
/* pending statfs requests */ /* pending generic requests */
struct rb_root statfs_request_tree; struct rb_root generic_request_tree;
int num_statfs_requests; int num_generic_requests;
u64 last_tid; u64 last_tid;
/* mds/osd map */ /* mds/osd map */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment