drm/radeon: fix PM on non-vram cards.
[safe/jmp/linux-2.6] / fs / ceph / auth_x.c
index 8d8a849..83d4d27 100644 (file)
@@ -4,6 +4,7 @@
 #include <linux/err.h>
 #include <linux/module.h>
 #include <linux/random.h>
+#include <linux/slab.h>
 
 #include "auth_x.h"
 #include "auth_x_protocol.h"
@@ -11,8 +12,6 @@
 #include "auth.h"
 #include "decode.h"
 
-struct kmem_cache *ceph_x_ticketbuf_cachep;
-
 #define TEMP_TICKET_BUF_LEN    256
 
 static void ceph_x_validate_tickets(struct ceph_auth_client *ac, int *pneed);
@@ -28,6 +27,17 @@ static int ceph_x_is_authenticated(struct ceph_auth_client *ac)
        return (ac->want_keys & xi->have_keys) == ac->want_keys;
 }
 
+static int ceph_x_should_authenticate(struct ceph_auth_client *ac)
+{
+       struct ceph_x_info *xi = ac->private;
+       int need;
+
+       ceph_x_validate_tickets(ac, &need);
+       dout("ceph_x_should_authenticate want=%d need=%d have=%d\n",
+            ac->want_keys, need, xi->have_keys);
+       return need != 0;
+}
+
 static int ceph_x_encrypt_buflen(int ilen)
 {
        return sizeof(struct ceph_x_encrypt_header) + ilen + 16 +
@@ -128,27 +138,26 @@ static int ceph_x_proc_ticket_reply(struct ceph_auth_client *ac,
        int ret;
        char *dbuf;
        char *ticket_buf;
-       u8 struct_v;
+       u8 reply_struct_v;
 
-       dbuf = kmem_cache_alloc(ceph_x_ticketbuf_cachep, GFP_NOFS | GFP_ATOMIC);
+       dbuf = kmalloc(TEMP_TICKET_BUF_LEN, GFP_NOFS);
        if (!dbuf)
                return -ENOMEM;
 
        ret = -ENOMEM;
-       ticket_buf = kmem_cache_alloc(ceph_x_ticketbuf_cachep,
-                                     GFP_NOFS | GFP_ATOMIC);
+       ticket_buf = kmalloc(TEMP_TICKET_BUF_LEN, GFP_NOFS);
        if (!ticket_buf)
                goto out_dbuf;
 
        ceph_decode_need(&p, end, 1 + sizeof(u32), bad);
-       struct_v = ceph_decode_8(&p);
-       if (struct_v != 1)
+       reply_struct_v = ceph_decode_8(&p);
+       if (reply_struct_v != 1)
                goto bad;
        num = ceph_decode_32(&p);
        dout("%d tickets\n", num);
        while (num--) {
                int type;
-               u8 struct_v;
+               u8 tkt_struct_v, blob_struct_v;
                struct ceph_x_ticket_handler *th;
                void *dp, *dend;
                int dlen;
@@ -167,8 +176,8 @@ static int ceph_x_proc_ticket_reply(struct ceph_auth_client *ac,
                type = ceph_decode_32(&p);
                dout(" ticket type %d %s\n", type, ceph_entity_type_name(type));
 
-               struct_v = ceph_decode_8(&p);
-               if (struct_v != 1)
+               tkt_struct_v = ceph_decode_8(&p);
+               if (tkt_struct_v != 1)
                        goto bad;
 
                th = get_ticket_handler(ac, type);
@@ -188,8 +197,8 @@ static int ceph_x_proc_ticket_reply(struct ceph_auth_client *ac,
                dend = dbuf + dlen;
                dp = dbuf;
 
-               struct_v = ceph_decode_8(&dp);
-               if (struct_v != 1)
+               tkt_struct_v = ceph_decode_8(&dp);
+               if (tkt_struct_v != 1)
                        goto bad;
 
                memcpy(&old_key, &th->session_key, sizeof(old_key));
@@ -226,7 +235,7 @@ static int ceph_x_proc_ticket_reply(struct ceph_auth_client *ac,
                tpend = tp + dlen;
                dout(" ticket blob is %d bytes\n", dlen);
                ceph_decode_need(&tp, tpend, 1 + sizeof(u64), bad);
-               struct_v = ceph_decode_8(&tp);
+               blob_struct_v = ceph_decode_8(&tp);
                new_secret_id = ceph_decode_64(&tp);
                ret = ceph_decode_buffer(&new_ticket_blob, &tp, tpend);
                if (ret)
@@ -250,9 +259,9 @@ static int ceph_x_proc_ticket_reply(struct ceph_auth_client *ac,
 
        ret = 0;
 out:
-       kmem_cache_free(ceph_x_ticketbuf_cachep, ticket_buf);
+       kfree(ticket_buf);
 out_dbuf:
-       kmem_cache_free(ceph_x_ticketbuf_cachep, dbuf);
+       kfree(dbuf);
        return ret;
 
 bad:
@@ -604,8 +613,6 @@ static void ceph_x_destroy(struct ceph_auth_client *ac)
                remove_ticket_handler(ac, th);
        }
 
-       kmem_cache_destroy(ceph_x_ticketbuf_cachep);
-
        kfree(ac->private);
        ac->private = NULL;
 }
@@ -622,7 +629,9 @@ static void ceph_x_invalidate_authorizer(struct ceph_auth_client *ac,
 
 
 static const struct ceph_auth_client_ops ceph_x_ops = {
+       .name = "x",
        .is_authenticated = ceph_x_is_authenticated,
+       .should_authenticate = ceph_x_should_authenticate,
        .build_request = ceph_x_build_request,
        .handle_reply = ceph_x_handle_reply,
        .create_authorizer = ceph_x_create_authorizer,
@@ -640,26 +649,20 @@ int ceph_x_init(struct ceph_auth_client *ac)
        int ret;
 
        dout("ceph_x_init %p\n", ac);
+       ret = -ENOMEM;
        xi = kzalloc(sizeof(*xi), GFP_NOFS);
        if (!xi)
-               return -ENOMEM;
+               goto out;
 
-       ret = -ENOMEM;
-       ceph_x_ticketbuf_cachep = kmem_cache_create("ceph_x_ticketbuf",
-                                     TEMP_TICKET_BUF_LEN, 8,
-                                     (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
-                                     NULL);
-       if (!ceph_x_ticketbuf_cachep)
-               goto done_nomem;
        ret = -EINVAL;
        if (!ac->secret) {
                pr_err("no secret set (for auth_x protocol)\n");
-               goto done_nomem;
+               goto out_nomem;
        }
 
        ret = ceph_crypto_key_unarmor(&xi->secret, ac->secret);
        if (ret)
-               goto done_nomem;
+               goto out_nomem;
 
        xi->starting = true;
        xi->ticket_handlers = RB_ROOT;
@@ -669,10 +672,9 @@ int ceph_x_init(struct ceph_auth_client *ac)
        ac->ops = &ceph_x_ops;
        return 0;
 
-done_nomem:
+out_nomem:
        kfree(xi);
-       if (ceph_x_ticketbuf_cachep)
-               kmem_cache_destroy(ceph_x_ticketbuf_cachep);
+out:
        return ret;
 }