2009-10-06 12:31:11 -06:00
|
|
|
#include "ceph_debug.h"
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2009-10-06 12:31:11 -06:00
|
|
|
#include <linux/random.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
|
|
|
|
#include "mon_client.h"
|
|
|
|
#include "super.h"
|
2009-11-18 17:19:57 -07:00
|
|
|
#include "auth.h"
|
2009-10-06 12:31:11 -06:00
|
|
|
#include "decode.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interact with Ceph monitor cluster. Handle requests for new map
|
|
|
|
* versions, and periodically resend as needed. Also implement
|
|
|
|
* statfs() and umount().
|
|
|
|
*
|
|
|
|
* A small cluster of Ceph "monitors" are responsible for managing critical
|
|
|
|
* cluster configuration and state information. An odd number (e.g., 3, 5)
|
|
|
|
* of cmon daemons use a modified version of the Paxos part-time parliament
|
|
|
|
* algorithm to manage the MDS map (mds cluster membership), OSD map, and
|
|
|
|
* list of clients who have mounted the file system.
|
|
|
|
*
|
|
|
|
* We maintain an open, active session with a monitor at all times in order to
|
|
|
|
* receive timely MDSMap updates. We periodically send a keepalive byte on the
|
|
|
|
* TCP socket to ensure we detect a failure. If the connection does break, we
|
|
|
|
* randomly hunt for a new monitor. Once the connection is reestablished, we
|
|
|
|
* resend any outstanding requests.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const static struct ceph_connection_operations mon_con_ops;
|
|
|
|
|
2010-02-02 17:21:06 -07:00
|
|
|
static int __validate_auth(struct ceph_mon_client *monc);
|
|
|
|
|
2009-10-06 12:31:11 -06:00
|
|
|
/*
|
|
|
|
* Decode a monmap blob (e.g., during mount).
|
|
|
|
*/
|
|
|
|
struct ceph_monmap *ceph_monmap_decode(void *p, void *end)
|
|
|
|
{
|
|
|
|
struct ceph_monmap *m = NULL;
|
|
|
|
int i, err = -EINVAL;
|
|
|
|
struct ceph_fsid fsid;
|
|
|
|
u32 epoch, num_mon;
|
|
|
|
u16 version;
|
2009-11-18 17:19:57 -07:00
|
|
|
u32 len;
|
|
|
|
|
|
|
|
ceph_decode_32_safe(&p, end, len, bad);
|
|
|
|
ceph_decode_need(&p, end, len, bad);
|
2009-10-06 12:31:11 -06:00
|
|
|
|
|
|
|
dout("monmap_decode %p %p len %d\n", p, end, (int)(end-p));
|
|
|
|
|
|
|
|
ceph_decode_16_safe(&p, end, version, bad);
|
|
|
|
|
|
|
|
ceph_decode_need(&p, end, sizeof(fsid) + 2*sizeof(u32), bad);
|
|
|
|
ceph_decode_copy(&p, &fsid, sizeof(fsid));
|
2009-10-14 10:59:09 -06:00
|
|
|
epoch = ceph_decode_32(&p);
|
2009-10-06 12:31:11 -06:00
|
|
|
|
2009-10-14 10:59:09 -06:00
|
|
|
num_mon = ceph_decode_32(&p);
|
2009-10-06 12:31:11 -06:00
|
|
|
ceph_decode_need(&p, end, num_mon*sizeof(m->mon_inst[0]), bad);
|
|
|
|
|
|
|
|
if (num_mon >= CEPH_MAX_MON)
|
|
|
|
goto bad;
|
|
|
|
m = kmalloc(sizeof(*m) + sizeof(m->mon_inst[0])*num_mon, GFP_NOFS);
|
|
|
|
if (m == NULL)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
m->fsid = fsid;
|
|
|
|
m->epoch = epoch;
|
|
|
|
m->num_mon = num_mon;
|
|
|
|
ceph_decode_copy(&p, m->mon_inst, num_mon*sizeof(m->mon_inst[0]));
|
2009-11-03 16:17:56 -07:00
|
|
|
for (i = 0; i < num_mon; i++)
|
|
|
|
ceph_decode_addr(&m->mon_inst[i].addr);
|
2009-10-06 12:31:11 -06:00
|
|
|
|
|
|
|
dout("monmap_decode epoch %d, num_mon %d\n", m->epoch,
|
|
|
|
m->num_mon);
|
|
|
|
for (i = 0; i < m->num_mon; i++)
|
|
|
|
dout("monmap_decode mon%d is %s\n", i,
|
|
|
|
pr_addr(&m->mon_inst[i].addr.in_addr));
|
|
|
|
return m;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
dout("monmap_decode failed with %d\n", err);
|
|
|
|
kfree(m);
|
|
|
|
return ERR_PTR(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* return true if *addr is included in the monmap.
|
|
|
|
*/
|
|
|
|
int ceph_monmap_contains(struct ceph_monmap *m, struct ceph_entity_addr *addr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < m->num_mon; i++)
|
2010-01-07 17:12:36 -07:00
|
|
|
if (memcmp(addr, &m->mon_inst[i].addr, sizeof(*addr)) == 0)
|
2009-10-06 12:31:11 -06:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-15 17:22:28 -07:00
|
|
|
/*
|
|
|
|
* Send an auth request.
|
|
|
|
*/
|
|
|
|
static void __send_prepared_auth_request(struct ceph_mon_client *monc, int len)
|
|
|
|
{
|
|
|
|
monc->pending_auth = 1;
|
|
|
|
monc->m_auth->front.iov_len = len;
|
|
|
|
monc->m_auth->hdr.front_len = cpu_to_le32(len);
|
|
|
|
ceph_msg_get(monc->m_auth); /* keep our ref */
|
|
|
|
ceph_con_send(monc->con, monc->m_auth);
|
|
|
|
}
|
|
|
|
|
2009-10-06 12:31:11 -06:00
|
|
|
/*
|
|
|
|
* Close monitor session, if any.
|
|
|
|
*/
|
|
|
|
static void __close_session(struct ceph_mon_client *monc)
|
|
|
|
{
|
|
|
|
if (monc->con) {
|
|
|
|
dout("__close_session closing mon%d\n", monc->cur_mon);
|
2009-11-18 17:19:57 -07:00
|
|
|
ceph_con_revoke(monc->con, monc->m_auth);
|
2009-10-06 12:31:11 -06:00
|
|
|
ceph_con_close(monc->con);
|
|
|
|
monc->cur_mon = -1;
|
2010-02-02 17:21:06 -07:00
|
|
|
monc->pending_auth = 0;
|
2009-11-18 17:19:57 -07:00
|
|
|
ceph_auth_reset(monc->auth);
|
2009-10-06 12:31:11 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open a session with a (new) monitor.
|
|
|
|
*/
|
|
|
|
static int __open_session(struct ceph_mon_client *monc)
|
|
|
|
{
|
|
|
|
char r;
|
2009-11-18 17:19:57 -07:00
|
|
|
int ret;
|
2009-10-06 12:31:11 -06:00
|
|
|
|
|
|
|
if (monc->cur_mon < 0) {
|
|
|
|
get_random_bytes(&r, 1);
|
|
|
|
monc->cur_mon = r % monc->monmap->num_mon;
|
|
|
|
dout("open_session num=%d r=%d -> mon%d\n",
|
|
|
|
monc->monmap->num_mon, r, monc->cur_mon);
|
|
|
|
monc->sub_sent = 0;
|
|
|
|
monc->sub_renew_after = jiffies; /* i.e., expired */
|
|
|
|
monc->want_next_osdmap = !!monc->want_next_osdmap;
|
|
|
|
|
|
|
|
dout("open_session mon%d opening\n", monc->cur_mon);
|
|
|
|
monc->con->peer_name.type = CEPH_ENTITY_TYPE_MON;
|
|
|
|
monc->con->peer_name.num = cpu_to_le64(monc->cur_mon);
|
|
|
|
ceph_con_open(monc->con,
|
|
|
|
&monc->monmap->mon_inst[monc->cur_mon].addr);
|
2009-11-18 17:19:57 -07:00
|
|
|
|
|
|
|
/* initiatiate authentication handshake */
|
|
|
|
ret = ceph_auth_build_hello(monc->auth,
|
|
|
|
monc->m_auth->front.iov_base,
|
|
|
|
monc->m_auth->front_max);
|
2010-02-15 17:22:28 -07:00
|
|
|
__send_prepared_auth_request(monc, ret);
|
2009-10-06 12:31:11 -06:00
|
|
|
} else {
|
|
|
|
dout("open_session mon%d already open\n", monc->cur_mon);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool __sub_expired(struct ceph_mon_client *monc)
|
|
|
|
{
|
|
|
|
return time_after_eq(jiffies, monc->sub_renew_after);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reschedule delayed work timer.
|
|
|
|
*/
|
|
|
|
static void __schedule_delayed(struct ceph_mon_client *monc)
|
|
|
|
{
|
|
|
|
unsigned delay;
|
|
|
|
|
2009-11-18 17:19:57 -07:00
|
|
|
if (monc->cur_mon < 0 || __sub_expired(monc))
|
2009-10-06 12:31:11 -06:00
|
|
|
delay = 10 * HZ;
|
|
|
|
else
|
|
|
|
delay = 20 * HZ;
|
|
|
|
dout("__schedule_delayed after %u\n", delay);
|
|
|
|
schedule_delayed_work(&monc->delayed_work, delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send subscribe request for mdsmap and/or osdmap.
|
|
|
|
*/
|
|
|
|
static void __send_subscribe(struct ceph_mon_client *monc)
|
|
|
|
{
|
|
|
|
dout("__send_subscribe sub_sent=%u exp=%u want_osd=%d\n",
|
|
|
|
(unsigned)monc->sub_sent, __sub_expired(monc),
|
|
|
|
monc->want_next_osdmap);
|
|
|
|
if ((__sub_expired(monc) && !monc->sub_sent) ||
|
|
|
|
monc->want_next_osdmap == 1) {
|
|
|
|
struct ceph_msg *msg;
|
|
|
|
struct ceph_mon_subscribe_item *i;
|
|
|
|
void *p, *end;
|
|
|
|
|
2010-04-01 17:07:23 -06:00
|
|
|
msg = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 96);
|
2009-10-06 12:31:11 -06:00
|
|
|
if (!msg)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p = msg->front.iov_base;
|
|
|
|
end = p + msg->front.iov_len;
|
|
|
|
|
|
|
|
dout("__send_subscribe to 'mdsmap' %u+\n",
|
|
|
|
(unsigned)monc->have_mdsmap);
|
|
|
|
if (monc->want_next_osdmap) {
|
|
|
|
dout("__send_subscribe to 'osdmap' %u\n",
|
|
|
|
(unsigned)monc->have_osdmap);
|
2009-11-18 17:19:57 -07:00
|
|
|
ceph_encode_32(&p, 3);
|
2009-10-06 12:31:11 -06:00
|
|
|
ceph_encode_string(&p, end, "osdmap", 6);
|
|
|
|
i = p;
|
|
|
|
i->have = cpu_to_le64(monc->have_osdmap);
|
|
|
|
i->onetime = 1;
|
|
|
|
p += sizeof(*i);
|
|
|
|
monc->want_next_osdmap = 2; /* requested */
|
|
|
|
} else {
|
2009-11-18 17:19:57 -07:00
|
|
|
ceph_encode_32(&p, 2);
|
2009-10-06 12:31:11 -06:00
|
|
|
}
|
|
|
|
ceph_encode_string(&p, end, "mdsmap", 6);
|
|
|
|
i = p;
|
|
|
|
i->have = cpu_to_le64(monc->have_mdsmap);
|
|
|
|
i->onetime = 0;
|
|
|
|
p += sizeof(*i);
|
2009-11-18 17:19:57 -07:00
|
|
|
ceph_encode_string(&p, end, "monmap", 6);
|
|
|
|
i = p;
|
|
|
|
i->have = 0;
|
|
|
|
i->onetime = 0;
|
|
|
|
p += sizeof(*i);
|
2009-10-06 12:31:11 -06:00
|
|
|
|
|
|
|
msg->front.iov_len = p - msg->front.iov_base;
|
|
|
|
msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
|
|
|
|
ceph_con_send(monc->con, msg);
|
|
|
|
|
|
|
|
monc->sub_sent = jiffies | 1; /* never 0 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_subscribe_ack(struct ceph_mon_client *monc,
|
|
|
|
struct ceph_msg *msg)
|
|
|
|
{
|
|
|
|
unsigned seconds;
|
2009-10-14 18:26:40 -06:00
|
|
|
struct ceph_mon_subscribe_ack *h = msg->front.iov_base;
|
|
|
|
|
|
|
|
if (msg->front.iov_len < sizeof(*h))
|
|
|
|
goto bad;
|
|
|
|
seconds = le32_to_cpu(h->duration);
|
2009-10-06 12:31:11 -06:00
|
|
|
|
|
|
|
mutex_lock(&monc->mutex);
|
|
|
|
if (monc->hunting) {
|
|
|
|
pr_info("mon%d %s session established\n",
|
|
|
|
monc->cur_mon, pr_addr(&monc->con->peer_addr.in_addr));
|
|
|
|
monc->hunting = false;
|
|
|
|
}
|
|
|
|
dout("handle_subscribe_ack after %d seconds\n", seconds);
|
2009-10-08 11:25:46 -06:00
|
|
|
monc->sub_renew_after = monc->sub_sent + (seconds >> 1)*HZ - 1;
|
2009-10-06 12:31:11 -06:00
|
|
|
monc->sub_sent = 0;
|
|
|
|
mutex_unlock(&monc->mutex);
|
|
|
|
return;
|
|
|
|
bad:
|
|
|
|
pr_err("got corrupt subscribe-ack msg\n");
|
2009-12-14 16:13:47 -07:00
|
|
|
ceph_msg_dump(msg);
|
2009-10-06 12:31:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keep track of which maps we have
|
|
|
|
*/
|
|
|
|
int ceph_monc_got_mdsmap(struct ceph_mon_client *monc, u32 got)
|
|
|
|
{
|
|
|
|
mutex_lock(&monc->mutex);
|
|
|
|
monc->have_mdsmap = got;
|
|
|
|
mutex_unlock(&monc->mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ceph_monc_got_osdmap(struct ceph_mon_client *monc, u32 got)
|
|
|
|
{
|
|
|
|
mutex_lock(&monc->mutex);
|
|
|
|
monc->have_osdmap = got;
|
|
|
|
monc->want_next_osdmap = 0;
|
|
|
|
mutex_unlock(&monc->mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register interest in the next osdmap
|
|
|
|
*/
|
|
|
|
void ceph_monc_request_next_osdmap(struct ceph_mon_client *monc)
|
|
|
|
{
|
|
|
|
dout("request_next_osdmap have %u\n", monc->have_osdmap);
|
|
|
|
mutex_lock(&monc->mutex);
|
|
|
|
if (!monc->want_next_osdmap)
|
|
|
|
monc->want_next_osdmap = 1;
|
|
|
|
if (monc->want_next_osdmap < 2)
|
|
|
|
__send_subscribe(monc);
|
|
|
|
mutex_unlock(&monc->mutex);
|
|
|
|
}
|
|
|
|
|
2009-11-18 17:19:57 -07:00
|
|
|
/*
|
2009-12-01 15:12:07 -07:00
|
|
|
*
|
2009-11-18 17:19:57 -07:00
|
|
|
*/
|
|
|
|
int ceph_monc_open_session(struct ceph_mon_client *monc)
|
2009-10-06 12:31:11 -06:00
|
|
|
{
|
|
|
|
if (!monc->con) {
|
|
|
|
monc->con = kmalloc(sizeof(*monc->con), GFP_KERNEL);
|
|
|
|
if (!monc->con)
|
|
|
|
return -ENOMEM;
|
|
|
|
ceph_con_init(monc->client->msgr, monc->con);
|
|
|
|
monc->con->private = monc;
|
|
|
|
monc->con->ops = &mon_con_ops;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_lock(&monc->mutex);
|
2009-11-18 17:19:57 -07:00
|
|
|
__open_session(monc);
|
2009-10-06 12:31:11 -06:00
|
|
|
__schedule_delayed(monc);
|
|
|
|
mutex_unlock(&monc->mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-18 17:19:57 -07:00
|
|
|
/*
|
|
|
|
* The monitor responds with mount ack indicate mount success. The
|
|
|
|
* included client ticket allows the client to talk to MDSs and OSDs.
|
|
|
|
*/
|
2009-11-18 17:50:41 -07:00
|
|
|
static void ceph_monc_handle_map(struct ceph_mon_client *monc,
|
|
|
|
struct ceph_msg *msg)
|
2009-11-18 17:19:57 -07:00
|
|
|
{
|
|
|
|
struct ceph_client *client = monc->client;
|
|
|
|
struct ceph_monmap *monmap = NULL, *old = monc->monmap;
|
|
|
|
void *p, *end;
|
|
|
|
|
|
|
|
mutex_lock(&monc->mutex);
|
|
|
|
|
|
|
|
dout("handle_monmap\n");
|
|
|
|
p = msg->front.iov_base;
|
|
|
|
end = p + msg->front.iov_len;
|
|
|
|
|
|
|
|
monmap = ceph_monmap_decode(p, end);
|
|
|
|
if (IS_ERR(monmap)) {
|
|
|
|
pr_err("problem decoding monmap, %d\n",
|
|
|
|
(int)PTR_ERR(monmap));
|
2009-12-11 09:55:23 -07:00
|
|
|
goto out;
|
2009-11-18 17:19:57 -07:00
|
|
|
}
|
2009-11-18 17:50:41 -07:00
|
|
|
|
|
|
|
if (ceph_check_fsid(monc->client, &monmap->fsid) < 0) {
|
2009-11-18 17:19:57 -07:00
|
|
|
kfree(monmap);
|
2009-12-11 09:55:23 -07:00
|
|
|
goto out;
|
2009-11-18 17:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
client->monc.monmap = monmap;
|
|
|
|
kfree(old);
|
|
|
|
|
2009-12-11 09:55:23 -07:00
|
|
|
out:
|
2009-11-18 17:19:57 -07:00
|
|
|
mutex_unlock(&monc->mutex);
|
2010-02-02 17:21:06 -07:00
|
|
|
wake_up(&client->auth_wq);
|
2009-11-18 17:19:57 -07:00
|
|
|
}
|
|
|
|
|
2009-10-06 12:31:11 -06:00
|
|
|
/*
|
|
|
|
* statfs
|
|
|
|
*/
|
2010-02-15 15:47:28 -07:00
|
|
|
static struct ceph_mon_statfs_request *__lookup_statfs(
|
|
|
|
struct ceph_mon_client *monc, u64 tid)
|
|
|
|
{
|
|
|
|
struct ceph_mon_statfs_request *req;
|
|
|
|
struct rb_node *n = monc->statfs_request_tree.rb_node;
|
|
|
|
|
|
|
|
while (n) {
|
|
|
|
req = rb_entry(n, struct ceph_mon_statfs_request, node);
|
|
|
|
if (tid < req->tid)
|
|
|
|
n = n->rb_left;
|
|
|
|
else if (tid > req->tid)
|
|
|
|
n = n->rb_right;
|
|
|
|
else
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __insert_statfs(struct ceph_mon_client *monc,
|
|
|
|
struct ceph_mon_statfs_request *new)
|
|
|
|
{
|
|
|
|
struct rb_node **p = &monc->statfs_request_tree.rb_node;
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct ceph_mon_statfs_request *req = NULL;
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
parent = *p;
|
|
|
|
req = rb_entry(parent, struct ceph_mon_statfs_request, node);
|
|
|
|
if (new->tid < req->tid)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else if (new->tid > req->tid)
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
else
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_link_node(&new->node, parent, p);
|
|
|
|
rb_insert_color(&new->node, &monc->statfs_request_tree);
|
|
|
|
}
|
|
|
|
|
2010-03-24 22:43:33 -06:00
|
|
|
static void release_statfs_request(struct kref *kref)
|
|
|
|
{
|
|
|
|
struct ceph_mon_statfs_request *req =
|
|
|
|
container_of(kref, struct ceph_mon_statfs_request, kref);
|
|
|
|
|
|
|
|
if (req->reply)
|
|
|
|
ceph_msg_put(req->reply);
|
|
|
|
if (req->request)
|
|
|
|
ceph_msg_put(req->request);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void put_statfs_request(struct ceph_mon_statfs_request *req)
|
|
|
|
{
|
|
|
|
kref_put(&req->kref, release_statfs_request);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_statfs_request(struct ceph_mon_statfs_request *req)
|
|
|
|
{
|
|
|
|
kref_get(&req->kref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ceph_msg *get_statfs_reply(struct ceph_connection *con,
|
|
|
|
struct ceph_msg_header *hdr,
|
|
|
|
int *skip)
|
|
|
|
{
|
|
|
|
struct ceph_mon_client *monc = con->private;
|
|
|
|
struct ceph_mon_statfs_request *req;
|
|
|
|
u64 tid = le64_to_cpu(hdr->tid);
|
|
|
|
struct ceph_msg *m;
|
|
|
|
|
|
|
|
mutex_lock(&monc->mutex);
|
|
|
|
req = __lookup_statfs(monc, tid);
|
|
|
|
if (!req) {
|
|
|
|
dout("get_statfs_reply %lld dne\n", tid);
|
|
|
|
*skip = 1;
|
|
|
|
m = NULL;
|
|
|
|
} else {
|
|
|
|
dout("get_statfs_reply %lld got %p\n", tid, req->reply);
|
|
|
|
m = ceph_msg_get(req->reply);
|
|
|
|
/*
|
|
|
|
* we don't need to track the connection reading into
|
|
|
|
* this reply because we only have one open connection
|
|
|
|
* at a time, ever.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
mutex_unlock(&monc->mutex);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2009-10-06 12:31:11 -06:00
|
|
|
static void handle_statfs_reply(struct ceph_mon_client *monc,
|
|
|
|
struct ceph_msg *msg)
|
|
|
|
{
|
|
|
|
struct ceph_mon_statfs_request *req;
|
|
|
|
struct ceph_mon_statfs_reply *reply = msg->front.iov_base;
|
2010-03-24 22:43:33 -06:00
|
|
|
u64 tid = le64_to_cpu(msg->hdr.tid);
|
2009-10-06 12:31:11 -06:00
|
|
|
|
|
|
|
if (msg->front.iov_len != sizeof(*reply))
|
|
|
|
goto bad;
|
|
|
|
dout("handle_statfs_reply %p tid %llu\n", msg, tid);
|
|
|
|
|
|
|
|
mutex_lock(&monc->mutex);
|
2010-02-15 15:47:28 -07:00
|
|
|
req = __lookup_statfs(monc, tid);
|
2009-10-06 12:31:11 -06:00
|
|
|
if (req) {
|
|
|
|
*req->buf = reply->st;
|
|
|
|
req->result = 0;
|
2010-03-24 22:43:33 -06:00
|
|
|
get_statfs_request(req);
|
2009-10-06 12:31:11 -06:00
|
|
|
}
|
|
|
|
mutex_unlock(&monc->mutex);
|
2010-03-24 22:43:33 -06:00
|
|
|
if (req) {
|
2009-10-06 12:31:11 -06:00
|
|
|
complete(&req->completion);
|
2010-03-24 22:43:33 -06:00
|
|
|
put_statfs_request(req);
|
|
|
|
}
|
2009-10-06 12:31:11 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
pr_err("corrupt statfs reply, no tid\n");
|
2009-12-14 16:13:47 -07:00
|
|
|
ceph_msg_dump(msg);
|
2009-10-06 12:31:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-03-24 22:43:33 -06:00
|
|
|
* Do a synchronous statfs().
|
2009-10-06 12:31:11 -06:00
|
|
|
*/
|
2010-03-24 22:43:33 -06:00
|
|
|
int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
|
2009-10-06 12:31:11 -06:00
|
|
|
{
|
2010-03-24 22:43:33 -06:00
|
|
|
struct ceph_mon_statfs_request *req;
|
2009-10-06 12:31:11 -06:00
|
|
|
struct ceph_mon_statfs *h;
|
2010-03-24 22:43:33 -06:00
|
|
|
int err;
|
|
|
|
|
|
|
|
req = kmalloc(sizeof(*req), GFP_NOFS);
|
|
|
|
if (!req)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
memset(req, 0, sizeof(*req));
|
|
|
|
kref_init(&req->kref);
|
|
|
|
req->buf = buf;
|
|
|
|
init_completion(&req->completion);
|
2009-10-06 12:31:11 -06:00
|
|
|
|
2010-04-01 17:06:19 -06:00
|
|
|
err = -ENOMEM;
|
2010-04-01 17:07:23 -06:00
|
|
|
req->request = ceph_msg_new(CEPH_MSG_STATFS, sizeof(*h));
|
2010-04-01 17:06:19 -06:00
|
|
|
if (!req->request)
|
2010-03-24 22:43:33 -06:00
|
|
|
goto out;
|
2010-04-01 17:07:23 -06:00
|
|
|
req->reply = ceph_msg_new(CEPH_MSG_STATFS_REPLY, 1024);
|
2010-04-01 17:06:19 -06:00
|
|
|
if (!req->reply)
|
2010-03-24 22:43:33 -06:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* fill out request */
|
|
|
|
h = req->request->front.iov_base;
|
2009-10-09 17:36:34 -06:00
|
|
|
h->monhdr.have_version = 0;
|
|
|
|
h->monhdr.session_mon = cpu_to_le16(-1);
|
|
|
|
h->monhdr.session_mon_tid = 0;
|
2009-10-06 12:31:11 -06:00
|
|
|
h->fsid = monc->monmap->fsid;
|
|
|
|
|
|
|
|
/* register request */
|
|
|
|
mutex_lock(&monc->mutex);
|
2010-03-24 22:43:33 -06:00
|
|
|
req->tid = ++monc->last_tid;
|
|
|
|
req->request->hdr.tid = cpu_to_le64(req->tid);
|
|
|
|
__insert_statfs(monc, req);
|
2009-10-06 12:31:11 -06:00
|
|
|
monc->num_statfs_requests++;
|
|
|
|
mutex_unlock(&monc->mutex);
|
|
|
|
|
|
|
|
/* send request and wait */
|
2010-03-24 22:43:33 -06:00
|
|
|
ceph_con_send(monc->con, ceph_msg_get(req->request));
|
|
|
|
err = wait_for_completion_interruptible(&req->completion);
|
2009-10-06 12:31:11 -06:00
|
|
|
|
|
|
|
mutex_lock(&monc->mutex);
|
2010-03-24 22:43:33 -06:00
|
|
|
rb_erase(&req->node, &monc->statfs_request_tree);
|
2009-10-06 12:31:11 -06:00
|
|
|
monc->num_statfs_requests--;
|
|
|
|
mutex_unlock(&monc->mutex);
|
|
|
|
|
|
|
|
if (!err)
|
2010-03-24 22:43:33 -06:00
|
|
|
err = req->result;
|
|
|
|
|
|
|
|
out:
|
|
|
|
kref_put(&req->kref, release_statfs_request);
|
2009-10-06 12:31:11 -06:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Resend pending statfs requests.
|
|
|
|
*/
|
|
|
|
static void __resend_statfs(struct ceph_mon_client *monc)
|
|
|
|
{
|
|
|
|
struct ceph_mon_statfs_request *req;
|
2010-02-15 15:47:28 -07:00
|
|
|
struct rb_node *p;
|
2009-10-06 12:31:11 -06:00
|
|
|
|
2010-02-15 15:47:28 -07:00
|
|
|
for (p = rb_first(&monc->statfs_request_tree); p; p = rb_next(p)) {
|
|
|
|
req = rb_entry(p, struct ceph_mon_statfs_request, node);
|
2010-03-24 22:43:33 -06:00
|
|
|
ceph_con_send(monc->con, ceph_msg_get(req->request));
|
2009-10-06 12:31:11 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delayed work. If we haven't mounted yet, retry. Otherwise,
|
|
|
|
* renew/retry subscription as needed (in case it is timing out, or we
|
|
|
|
* got an ENOMEM). And keep the monitor connection alive.
|
|
|
|
*/
|
|
|
|
static void delayed_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct ceph_mon_client *monc =
|
|
|
|
container_of(work, struct ceph_mon_client, delayed_work.work);
|
|
|
|
|
|
|
|
dout("monc delayed_work\n");
|
|
|
|
mutex_lock(&monc->mutex);
|
2009-11-18 17:19:57 -07:00
|
|
|
if (monc->hunting) {
|
|
|
|
__close_session(monc);
|
|
|
|
__open_session(monc); /* continue hunting */
|
2009-10-06 12:31:11 -06:00
|
|
|
} else {
|
2009-11-18 17:19:57 -07:00
|
|
|
ceph_con_keepalive(monc->con);
|
2010-02-02 17:21:06 -07:00
|
|
|
|
|
|
|
__validate_auth(monc);
|
|
|
|
|
2009-11-18 17:19:57 -07:00
|
|
|
if (monc->auth->ops->is_authenticated(monc->auth))
|
|
|
|
__send_subscribe(monc);
|
2009-10-06 12:31:11 -06:00
|
|
|
}
|
|
|
|
__schedule_delayed(monc);
|
|
|
|
mutex_unlock(&monc->mutex);
|
|
|
|
}
|
|
|
|
|
2009-10-27 12:50:50 -06:00
|
|
|
/*
|
|
|
|
* On startup, we build a temporary monmap populated with the IPs
|
|
|
|
* provided by mount(2).
|
|
|
|
*/
|
|
|
|
static int build_initial_monmap(struct ceph_mon_client *monc)
|
|
|
|
{
|
|
|
|
struct ceph_mount_args *args = monc->client->mount_args;
|
|
|
|
struct ceph_entity_addr *mon_addr = args->mon_addr;
|
|
|
|
int num_mon = args->num_mon;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* build initial monmap */
|
|
|
|
monc->monmap = kzalloc(sizeof(*monc->monmap) +
|
|
|
|
num_mon*sizeof(monc->monmap->mon_inst[0]),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!monc->monmap)
|
|
|
|
return -ENOMEM;
|
|
|
|
for (i = 0; i < num_mon; i++) {
|
|
|
|
monc->monmap->mon_inst[i].addr = mon_addr[i];
|
|
|
|
monc->monmap->mon_inst[i].addr.nonce = 0;
|
|
|
|
monc->monmap->mon_inst[i].name.type =
|
|
|
|
CEPH_ENTITY_TYPE_MON;
|
|
|
|
monc->monmap->mon_inst[i].name.num = cpu_to_le64(i);
|
|
|
|
}
|
|
|
|
monc->monmap->num_mon = num_mon;
|
2009-11-18 17:19:57 -07:00
|
|
|
monc->have_fsid = false;
|
2009-10-27 12:50:50 -06:00
|
|
|
|
|
|
|
/* release addr memory */
|
|
|
|
kfree(args->mon_addr);
|
|
|
|
args->mon_addr = NULL;
|
|
|
|
args->num_mon = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-06 12:31:11 -06:00
|
|
|
int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
dout("init\n");
|
|
|
|
memset(monc, 0, sizeof(*monc));
|
|
|
|
monc->client = cl;
|
|
|
|
monc->monmap = NULL;
|
|
|
|
mutex_init(&monc->mutex);
|
|
|
|
|
2009-10-27 12:50:50 -06:00
|
|
|
err = build_initial_monmap(monc);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
2009-10-06 12:31:11 -06:00
|
|
|
monc->con = NULL;
|
|
|
|
|
2009-11-18 17:19:57 -07:00
|
|
|
/* authentication */
|
|
|
|
monc->auth = ceph_auth_init(cl->mount_args->name,
|
|
|
|
cl->mount_args->secret);
|
|
|
|
if (IS_ERR(monc->auth))
|
|
|
|
return PTR_ERR(monc->auth);
|
|
|
|
monc->auth->want_keys =
|
|
|
|
CEPH_ENTITY_TYPE_AUTH | CEPH_ENTITY_TYPE_MON |
|
|
|
|
CEPH_ENTITY_TYPE_OSD | CEPH_ENTITY_TYPE_MDS;
|
|
|
|
|
2009-10-06 12:31:11 -06:00
|
|
|
/* msg pools */
|
2010-04-01 17:06:19 -06:00
|
|
|
err = -ENOMEM;
|
2010-03-24 22:52:30 -06:00
|
|
|
monc->m_subscribe_ack = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE_ACK,
|
2010-04-01 17:07:23 -06:00
|
|
|
sizeof(struct ceph_mon_subscribe_ack));
|
2010-04-01 17:06:19 -06:00
|
|
|
if (!monc->m_subscribe_ack)
|
2009-11-18 17:19:57 -07:00
|
|
|
goto out_monmap;
|
2010-03-24 22:48:05 -06:00
|
|
|
|
2010-04-01 17:07:23 -06:00
|
|
|
monc->m_auth_reply = ceph_msg_new(CEPH_MSG_AUTH_REPLY, 4096);
|
2010-04-01 17:06:19 -06:00
|
|
|
if (!monc->m_auth_reply)
|
2010-03-24 22:52:30 -06:00
|
|
|
goto out_subscribe_ack;
|
2009-11-18 17:19:57 -07:00
|
|
|
|
2010-04-01 17:07:23 -06:00
|
|
|
monc->m_auth = ceph_msg_new(CEPH_MSG_AUTH, 4096);
|
2010-02-02 17:21:06 -07:00
|
|
|
monc->pending_auth = 0;
|
2010-04-01 17:06:19 -06:00
|
|
|
if (!monc->m_auth)
|
2010-03-24 22:48:05 -06:00
|
|
|
goto out_auth_reply;
|
2009-10-06 12:31:11 -06:00
|
|
|
|
|
|
|
monc->cur_mon = -1;
|
2009-11-18 17:19:57 -07:00
|
|
|
monc->hunting = true;
|
2009-10-06 12:31:11 -06:00
|
|
|
monc->sub_renew_after = jiffies;
|
|
|
|
monc->sub_sent = 0;
|
|
|
|
|
|
|
|
INIT_DELAYED_WORK(&monc->delayed_work, delayed_work);
|
2010-02-15 15:47:28 -07:00
|
|
|
monc->statfs_request_tree = RB_ROOT;
|
2009-10-06 12:31:11 -06:00
|
|
|
monc->num_statfs_requests = 0;
|
|
|
|
monc->last_tid = 0;
|
|
|
|
|
|
|
|
monc->have_mdsmap = 0;
|
|
|
|
monc->have_osdmap = 0;
|
|
|
|
monc->want_next_osdmap = 1;
|
2009-11-18 17:19:57 -07:00
|
|
|
return 0;
|
|
|
|
|
2010-03-24 22:48:05 -06:00
|
|
|
out_auth_reply:
|
|
|
|
ceph_msg_put(monc->m_auth_reply);
|
2010-03-24 22:52:30 -06:00
|
|
|
out_subscribe_ack:
|
|
|
|
ceph_msg_put(monc->m_subscribe_ack);
|
2009-11-18 17:19:57 -07:00
|
|
|
out_monmap:
|
|
|
|
kfree(monc->monmap);
|
2009-10-06 12:31:11 -06:00
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ceph_monc_stop(struct ceph_mon_client *monc)
|
|
|
|
{
|
|
|
|
dout("stop\n");
|
|
|
|
cancel_delayed_work_sync(&monc->delayed_work);
|
|
|
|
|
|
|
|
mutex_lock(&monc->mutex);
|
|
|
|
__close_session(monc);
|
|
|
|
if (monc->con) {
|
|
|
|
monc->con->private = NULL;
|
|
|
|
monc->con->ops->put(monc->con);
|
|
|
|
monc->con = NULL;
|
|
|
|
}
|
|
|
|
mutex_unlock(&monc->mutex);
|
|
|
|
|
2009-11-18 17:19:57 -07:00
|
|
|
ceph_auth_destroy(monc->auth);
|
|
|
|
|
|
|
|
ceph_msg_put(monc->m_auth);
|
2010-03-24 22:48:05 -06:00
|
|
|
ceph_msg_put(monc->m_auth_reply);
|
2010-03-24 22:52:30 -06:00
|
|
|
ceph_msg_put(monc->m_subscribe_ack);
|
2009-10-06 12:31:11 -06:00
|
|
|
|
|
|
|
kfree(monc->monmap);
|
|
|
|
}
|
|
|
|
|
2009-11-18 17:19:57 -07:00
|
|
|
static void handle_auth_reply(struct ceph_mon_client *monc,
|
|
|
|
struct ceph_msg *msg)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&monc->mutex);
|
2010-02-02 17:21:06 -07:00
|
|
|
monc->pending_auth = 0;
|
2009-11-18 17:19:57 -07:00
|
|
|
ret = ceph_handle_auth_reply(monc->auth, msg->front.iov_base,
|
|
|
|
msg->front.iov_len,
|
|
|
|
monc->m_auth->front.iov_base,
|
|
|
|
monc->m_auth->front_max);
|
|
|
|
if (ret < 0) {
|
2010-02-02 17:21:06 -07:00
|
|
|
monc->client->auth_err = ret;
|
|
|
|
wake_up(&monc->client->auth_wq);
|
2009-11-18 17:19:57 -07:00
|
|
|
} else if (ret > 0) {
|
2010-02-02 17:21:06 -07:00
|
|
|
__send_prepared_auth_request(monc, ret);
|
2009-11-18 17:19:57 -07:00
|
|
|
} else if (monc->auth->ops->is_authenticated(monc->auth)) {
|
|
|
|
dout("authenticated, starting session\n");
|
2009-11-18 17:50:41 -07:00
|
|
|
|
|
|
|
monc->client->msgr->inst.name.type = CEPH_ENTITY_TYPE_CLIENT;
|
|
|
|
monc->client->msgr->inst.name.num = monc->auth->global_id;
|
|
|
|
|
2009-11-18 17:19:57 -07:00
|
|
|
__send_subscribe(monc);
|
|
|
|
__resend_statfs(monc);
|
|
|
|
}
|
|
|
|
mutex_unlock(&monc->mutex);
|
|
|
|
}
|
|
|
|
|
2010-02-02 17:21:06 -07:00
|
|
|
static int __validate_auth(struct ceph_mon_client *monc)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (monc->pending_auth)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = ceph_build_auth(monc->auth, monc->m_auth->front.iov_base,
|
|
|
|
monc->m_auth->front_max);
|
|
|
|
if (ret <= 0)
|
|
|
|
return ret; /* either an error, or no need to authenticate */
|
|
|
|
__send_prepared_auth_request(monc, ret);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ceph_monc_validate_auth(struct ceph_mon_client *monc)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&monc->mutex);
|
|
|
|
ret = __validate_auth(monc);
|
|
|
|
mutex_unlock(&monc->mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-10-06 12:31:11 -06:00
|
|
|
/*
|
|
|
|
* handle incoming message
|
|
|
|
*/
|
|
|
|
static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
|
|
|
|
{
|
|
|
|
struct ceph_mon_client *monc = con->private;
|
|
|
|
int type = le16_to_cpu(msg->hdr.type);
|
|
|
|
|
|
|
|
if (!monc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (type) {
|
2009-11-18 17:19:57 -07:00
|
|
|
case CEPH_MSG_AUTH_REPLY:
|
|
|
|
handle_auth_reply(monc, msg);
|
2009-10-06 12:31:11 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CEPH_MSG_MON_SUBSCRIBE_ACK:
|
|
|
|
handle_subscribe_ack(monc, msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CEPH_MSG_STATFS_REPLY:
|
|
|
|
handle_statfs_reply(monc, msg);
|
|
|
|
break;
|
|
|
|
|
2009-11-18 17:19:57 -07:00
|
|
|
case CEPH_MSG_MON_MAP:
|
|
|
|
ceph_monc_handle_map(monc, msg);
|
|
|
|
break;
|
|
|
|
|
2009-10-06 12:31:11 -06:00
|
|
|
case CEPH_MSG_MDS_MAP:
|
|
|
|
ceph_mdsc_handle_map(&monc->client->mdsc, msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CEPH_MSG_OSD_MAP:
|
|
|
|
ceph_osdc_handle_map(&monc->client->osdc, msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
pr_err("received unknown message type %d %s\n", type,
|
|
|
|
ceph_msg_type_name(type));
|
|
|
|
}
|
|
|
|
ceph_msg_put(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate memory for incoming message
|
|
|
|
*/
|
|
|
|
static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con,
|
2010-01-08 14:58:34 -07:00
|
|
|
struct ceph_msg_header *hdr,
|
|
|
|
int *skip)
|
2009-10-06 12:31:11 -06:00
|
|
|
{
|
|
|
|
struct ceph_mon_client *monc = con->private;
|
|
|
|
int type = le16_to_cpu(hdr->type);
|
2010-01-08 14:58:34 -07:00
|
|
|
int front_len = le32_to_cpu(hdr->front_len);
|
2010-02-19 22:43:23 -07:00
|
|
|
struct ceph_msg *m = NULL;
|
2009-10-06 12:31:11 -06:00
|
|
|
|
2010-01-08 14:58:34 -07:00
|
|
|
*skip = 0;
|
2010-01-11 15:47:13 -07:00
|
|
|
|
2009-10-06 12:31:11 -06:00
|
|
|
switch (type) {
|
|
|
|
case CEPH_MSG_MON_SUBSCRIBE_ACK:
|
2010-03-24 22:52:30 -06:00
|
|
|
m = ceph_msg_get(monc->m_subscribe_ack);
|
2010-01-08 14:58:34 -07:00
|
|
|
break;
|
2009-10-06 12:31:11 -06:00
|
|
|
case CEPH_MSG_STATFS_REPLY:
|
2010-03-24 22:43:33 -06:00
|
|
|
return get_statfs_reply(con, hdr, skip);
|
2009-11-18 17:19:57 -07:00
|
|
|
case CEPH_MSG_AUTH_REPLY:
|
2010-03-24 22:48:05 -06:00
|
|
|
m = ceph_msg_get(monc->m_auth_reply);
|
2010-01-08 14:58:34 -07:00
|
|
|
break;
|
2010-02-19 22:43:23 -07:00
|
|
|
case CEPH_MSG_MON_MAP:
|
|
|
|
case CEPH_MSG_MDS_MAP:
|
|
|
|
case CEPH_MSG_OSD_MAP:
|
2010-04-01 17:07:23 -06:00
|
|
|
m = ceph_msg_new(type, front_len);
|
2010-02-19 22:43:23 -07:00
|
|
|
break;
|
2009-10-06 12:31:11 -06:00
|
|
|
}
|
2010-01-08 14:58:34 -07:00
|
|
|
|
2010-02-19 22:43:23 -07:00
|
|
|
if (!m) {
|
|
|
|
pr_info("alloc_msg unknown type %d\n", type);
|
2010-01-08 14:58:34 -07:00
|
|
|
*skip = 1;
|
2010-02-19 22:43:23 -07:00
|
|
|
}
|
2010-01-08 14:58:34 -07:00
|
|
|
return m;
|
2009-10-06 12:31:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the monitor connection resets, pick a new monitor and resubmit
|
|
|
|
* any pending requests.
|
|
|
|
*/
|
|
|
|
static void mon_fault(struct ceph_connection *con)
|
|
|
|
{
|
|
|
|
struct ceph_mon_client *monc = con->private;
|
|
|
|
|
|
|
|
if (!monc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dout("mon_fault\n");
|
|
|
|
mutex_lock(&monc->mutex);
|
|
|
|
if (!con->private)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (monc->con && !monc->hunting)
|
|
|
|
pr_info("mon%d %s session lost, "
|
|
|
|
"hunting for new mon\n", monc->cur_mon,
|
|
|
|
pr_addr(&monc->con->peer_addr.in_addr));
|
|
|
|
|
|
|
|
__close_session(monc);
|
|
|
|
if (!monc->hunting) {
|
|
|
|
/* start hunting */
|
|
|
|
monc->hunting = true;
|
2009-11-18 17:19:57 -07:00
|
|
|
__open_session(monc);
|
2009-10-06 12:31:11 -06:00
|
|
|
} else {
|
|
|
|
/* already hunting, let's wait a bit */
|
|
|
|
__schedule_delayed(monc);
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
mutex_unlock(&monc->mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
const static struct ceph_connection_operations mon_con_ops = {
|
|
|
|
.get = ceph_con_get,
|
|
|
|
.put = ceph_con_put,
|
|
|
|
.dispatch = dispatch,
|
|
|
|
.fault = mon_fault,
|
|
|
|
.alloc_msg = mon_alloc_msg,
|
|
|
|
};
|