2009-11-19 07:19:57 +07:00
|
|
|
#include "ceph_debug.h"
|
|
|
|
|
|
|
|
#include <linux/module.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 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2009-11-19 07:19:57 +07:00
|
|
|
#include <linux/err.h>
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include "auth_none.h"
|
2010-02-03 07:25:35 +07:00
|
|
|
#include "auth_x.h"
|
2009-11-19 07:19:57 +07:00
|
|
|
#include "decode.h"
|
|
|
|
#include "super.h"
|
|
|
|
|
|
|
|
#include "messenger.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get protocol handler
|
|
|
|
*/
|
|
|
|
static u32 supported_protocols[] = {
|
2010-02-03 07:25:35 +07:00
|
|
|
CEPH_AUTH_NONE,
|
|
|
|
CEPH_AUTH_CEPHX
|
2009-11-19 07:19:57 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
int ceph_auth_init_protocol(struct ceph_auth_client *ac, int protocol)
|
|
|
|
{
|
|
|
|
switch (protocol) {
|
|
|
|
case CEPH_AUTH_NONE:
|
|
|
|
return ceph_auth_none_init(ac);
|
2010-02-03 07:25:35 +07:00
|
|
|
case CEPH_AUTH_CEPHX:
|
|
|
|
return ceph_x_init(ac);
|
2009-11-19 07:19:57 +07:00
|
|
|
default:
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* setup, teardown.
|
|
|
|
*/
|
|
|
|
struct ceph_auth_client *ceph_auth_init(const char *name, const char *secret)
|
|
|
|
{
|
|
|
|
struct ceph_auth_client *ac;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dout("auth_init name '%s' secret '%s'\n", name, secret);
|
|
|
|
|
|
|
|
ret = -ENOMEM;
|
|
|
|
ac = kzalloc(sizeof(*ac), GFP_NOFS);
|
|
|
|
if (!ac)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ac->negotiating = true;
|
|
|
|
if (name)
|
|
|
|
ac->name = name;
|
|
|
|
else
|
|
|
|
ac->name = CEPH_AUTH_NAME_DEFAULT;
|
|
|
|
dout("auth_init name %s secret %s\n", ac->name, secret);
|
|
|
|
ac->secret = secret;
|
|
|
|
return ac;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ceph_auth_destroy(struct ceph_auth_client *ac)
|
|
|
|
{
|
|
|
|
dout("auth_destroy %p\n", ac);
|
|
|
|
if (ac->ops)
|
|
|
|
ac->ops->destroy(ac);
|
|
|
|
kfree(ac);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset occurs when reconnecting to the monitor.
|
|
|
|
*/
|
|
|
|
void ceph_auth_reset(struct ceph_auth_client *ac)
|
|
|
|
{
|
|
|
|
dout("auth_reset %p\n", ac);
|
|
|
|
if (ac->ops && !ac->negotiating)
|
|
|
|
ac->ops->reset(ac);
|
|
|
|
ac->negotiating = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ceph_entity_name_encode(const char *name, void **p, void *end)
|
|
|
|
{
|
|
|
|
int len = strlen(name);
|
|
|
|
|
|
|
|
if (*p + 2*sizeof(u32) + len > end)
|
|
|
|
return -ERANGE;
|
|
|
|
ceph_encode_32(p, CEPH_ENTITY_TYPE_CLIENT);
|
|
|
|
ceph_encode_32(p, len);
|
|
|
|
ceph_encode_copy(p, name, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initiate protocol negotiation with monitor. Include entity name
|
|
|
|
* and list supported protocols.
|
|
|
|
*/
|
|
|
|
int ceph_auth_build_hello(struct ceph_auth_client *ac, void *buf, size_t len)
|
|
|
|
{
|
|
|
|
struct ceph_mon_request_header *monhdr = buf;
|
|
|
|
void *p = monhdr + 1, *end = buf + len, *lenp;
|
|
|
|
int i, num;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dout("auth_build_hello\n");
|
|
|
|
monhdr->have_version = 0;
|
|
|
|
monhdr->session_mon = cpu_to_le16(-1);
|
|
|
|
monhdr->session_mon_tid = 0;
|
|
|
|
|
|
|
|
ceph_encode_32(&p, 0); /* no protocol, yet */
|
|
|
|
|
|
|
|
lenp = p;
|
|
|
|
p += sizeof(u32);
|
|
|
|
|
2010-02-05 00:42:20 +07:00
|
|
|
ceph_decode_need(&p, end, 1 + sizeof(u32), bad);
|
|
|
|
ceph_encode_8(&p, 1);
|
2009-11-19 07:19:57 +07:00
|
|
|
num = ARRAY_SIZE(supported_protocols);
|
|
|
|
ceph_encode_32(&p, num);
|
2010-02-05 00:42:20 +07:00
|
|
|
ceph_decode_need(&p, end, num * sizeof(u32), bad);
|
2009-11-19 07:19:57 +07:00
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
ceph_encode_32(&p, supported_protocols[i]);
|
|
|
|
|
|
|
|
ret = ceph_entity_name_encode(ac->name, &p, end);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
ceph_decode_need(&p, end, sizeof(u64), bad);
|
|
|
|
ceph_encode_64(&p, ac->global_id);
|
|
|
|
|
|
|
|
ceph_encode_32(&lenp, p - lenp - sizeof(u32));
|
|
|
|
return p - buf;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
return -ERANGE;
|
|
|
|
}
|
|
|
|
|
2010-02-03 07:21:06 +07:00
|
|
|
int ceph_build_auth_request(struct ceph_auth_client *ac,
|
|
|
|
void *msg_buf, size_t msg_len)
|
|
|
|
{
|
|
|
|
struct ceph_mon_request_header *monhdr = msg_buf;
|
|
|
|
void *p = monhdr + 1;
|
|
|
|
void *end = msg_buf + msg_len;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
monhdr->have_version = 0;
|
|
|
|
monhdr->session_mon = cpu_to_le16(-1);
|
|
|
|
monhdr->session_mon_tid = 0;
|
|
|
|
|
|
|
|
ceph_encode_32(&p, ac->protocol);
|
|
|
|
|
|
|
|
ret = ac->ops->build_request(ac, p + sizeof(u32), end);
|
|
|
|
if (ret < 0) {
|
|
|
|
pr_err("error %d building request\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
dout(" built request %d bytes\n", ret);
|
|
|
|
ceph_encode_32(&p, ret);
|
|
|
|
return p + ret - msg_buf;
|
|
|
|
}
|
|
|
|
|
2009-11-19 07:19:57 +07:00
|
|
|
/*
|
|
|
|
* Handle auth message from monitor.
|
|
|
|
*/
|
|
|
|
int ceph_handle_auth_reply(struct ceph_auth_client *ac,
|
|
|
|
void *buf, size_t len,
|
|
|
|
void *reply_buf, size_t reply_len)
|
|
|
|
{
|
|
|
|
void *p = buf;
|
|
|
|
void *end = buf + len;
|
|
|
|
int protocol;
|
|
|
|
s32 result;
|
|
|
|
u64 global_id;
|
|
|
|
void *payload, *payload_end;
|
|
|
|
int payload_len;
|
|
|
|
char *result_msg;
|
|
|
|
int result_msg_len;
|
|
|
|
int ret = -EINVAL;
|
|
|
|
|
|
|
|
dout("handle_auth_reply %p %p\n", p, end);
|
|
|
|
ceph_decode_need(&p, end, sizeof(u32) * 3 + sizeof(u64), bad);
|
|
|
|
protocol = ceph_decode_32(&p);
|
|
|
|
result = ceph_decode_32(&p);
|
|
|
|
global_id = ceph_decode_64(&p);
|
|
|
|
payload_len = ceph_decode_32(&p);
|
|
|
|
payload = p;
|
|
|
|
p += payload_len;
|
|
|
|
ceph_decode_need(&p, end, sizeof(u32), bad);
|
|
|
|
result_msg_len = ceph_decode_32(&p);
|
|
|
|
result_msg = p;
|
|
|
|
p += result_msg_len;
|
|
|
|
if (p != end)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
dout(" result %d '%.*s' gid %llu len %d\n", result, result_msg_len,
|
|
|
|
result_msg, global_id, payload_len);
|
|
|
|
|
|
|
|
payload_end = payload + payload_len;
|
|
|
|
|
|
|
|
if (global_id && ac->global_id != global_id) {
|
|
|
|
dout(" set global_id %lld -> %lld\n", ac->global_id, global_id);
|
|
|
|
ac->global_id = global_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ac->negotiating) {
|
2009-11-21 04:59:13 +07:00
|
|
|
/* server does not support our protocols? */
|
|
|
|
if (!protocol && result < 0) {
|
|
|
|
ret = result;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-11-19 07:19:57 +07:00
|
|
|
/* set up (new) protocol handler? */
|
|
|
|
if (ac->protocol && ac->protocol != protocol) {
|
|
|
|
ac->ops->destroy(ac);
|
|
|
|
ac->protocol = 0;
|
|
|
|
ac->ops = NULL;
|
|
|
|
}
|
|
|
|
if (ac->protocol != protocol) {
|
|
|
|
ret = ceph_auth_init_protocol(ac, protocol);
|
|
|
|
if (ret) {
|
|
|
|
pr_err("error %d on auth protocol %d init\n",
|
|
|
|
ret, protocol);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2010-02-03 07:21:06 +07:00
|
|
|
|
|
|
|
ac->negotiating = false;
|
2009-11-19 07:19:57 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = ac->ops->handle_reply(ac, result, payload, payload_end);
|
|
|
|
if (ret == -EAGAIN) {
|
2010-02-03 07:21:06 +07:00
|
|
|
return ceph_build_auth_request(ac, reply_buf, reply_len);
|
2009-11-19 07:19:57 +07:00
|
|
|
} else if (ret) {
|
|
|
|
pr_err("authentication error %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
pr_err("failed to decode auth msg\n");
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-02-03 07:21:06 +07:00
|
|
|
int ceph_build_auth(struct ceph_auth_client *ac,
|
|
|
|
void *msg_buf, size_t msg_len)
|
|
|
|
{
|
|
|
|
if (!ac->protocol)
|
|
|
|
return ceph_auth_build_hello(ac, msg_buf, msg_len);
|
|
|
|
BUG_ON(!ac->ops);
|
|
|
|
if (!ac->ops->is_authenticated(ac))
|
|
|
|
return ceph_build_auth_request(ac, msg_buf, msg_len);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-11-19 07:19:57 +07:00
|
|
|
|
2010-02-03 07:21:06 +07:00
|
|
|
int ceph_auth_is_authenticated(struct ceph_auth_client *ac)
|
|
|
|
{
|
|
|
|
if (!ac->ops)
|
|
|
|
return 0;
|
|
|
|
return ac->ops->is_authenticated(ac);
|
|
|
|
}
|