ceph: use new D_COMPLETE dentry flag
[linux-2.6.git] / fs / ceph / mdsmap.c
index 15913cb..73b7d44 100644 (file)
@@ -1,4 +1,4 @@
-#include "ceph_debug.h"
+#include <linux/ceph/ceph_debug.h>
 
 #include <linux/bug.h>
 #include <linux/err.h>
@@ -6,9 +6,9 @@
 #include <linux/slab.h>
 #include <linux/types.h>
 
-#include "mdsmap.h"
-#include "messenger.h"
-#include "decode.h"
+#include <linux/ceph/mdsmap.h>
+#include <linux/ceph/messenger.h>
+#include <linux/ceph/decode.h>
 
 #include "super.h"
 
@@ -49,6 +49,7 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m)
 struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
 {
        struct ceph_mdsmap *m;
+       const void *start = *p;
        int i, j, n;
        int err = -EINVAL;
        u16 version;
@@ -60,22 +61,23 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
        ceph_decode_16_safe(p, end, version, bad);
 
        ceph_decode_need(p, end, 8*sizeof(u32) + sizeof(u64), bad);
-       ceph_decode_32(p, m->m_epoch);
-       ceph_decode_32(p, m->m_client_epoch);
-       ceph_decode_32(p, m->m_last_failure);
-       ceph_decode_32(p, m->m_root);
-       ceph_decode_32(p, m->m_session_timeout);
-       ceph_decode_32(p, m->m_session_autoclose);
-       ceph_decode_64(p, m->m_max_file_size);
-       ceph_decode_32(p, m->m_max_mds);
+       m->m_epoch = ceph_decode_32(p);
+       m->m_client_epoch = ceph_decode_32(p);
+       m->m_last_failure = ceph_decode_32(p);
+       m->m_root = ceph_decode_32(p);
+       m->m_session_timeout = ceph_decode_32(p);
+       m->m_session_autoclose = ceph_decode_32(p);
+       m->m_max_file_size = ceph_decode_64(p);
+       m->m_max_mds = ceph_decode_32(p);
 
        m->m_info = kcalloc(m->m_max_mds, sizeof(*m->m_info), GFP_NOFS);
        if (m->m_info == NULL)
                goto badmem;
 
        /* pick out active nodes from mds_info (state > 0) */
-       ceph_decode_32(p, n);
+       n = ceph_decode_32(p);
        for (i = 0; i < n; i++) {
+               u64 global_id;
                u32 namelen;
                s32 mds, inc, state;
                u64 state_seq;
@@ -83,48 +85,56 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
                struct ceph_entity_addr addr;
                u32 num_export_targets;
                void *pexport_targets = NULL;
+               struct ceph_timespec laggy_since;
 
-               ceph_decode_need(p, end, sizeof(addr) + 1 + sizeof(u32), bad);
-               *p += sizeof(addr);          /* skip addr key */
-               ceph_decode_8(p, infoversion);
-               ceph_decode_32(p, namelen);  /* skip mds name */
+               ceph_decode_need(p, end, sizeof(u64)*2 + 1 + sizeof(u32), bad);
+               global_id = ceph_decode_64(p);
+               infoversion = ceph_decode_8(p);
+               *p += sizeof(u64);
+               namelen = ceph_decode_32(p);  /* skip mds name */
                *p += namelen;
 
                ceph_decode_need(p, end,
-                                5*sizeof(u32) + sizeof(u64) +
+                                4*sizeof(u32) + sizeof(u64) +
                                 sizeof(addr) + sizeof(struct ceph_timespec),
                                 bad);
-               ceph_decode_32(p, mds);
-               ceph_decode_32(p, inc);
-               ceph_decode_32(p, state);
-               ceph_decode_64(p, state_seq);
+               mds = ceph_decode_32(p);
+               inc = ceph_decode_32(p);
+               state = ceph_decode_32(p);
+               state_seq = ceph_decode_64(p);
                ceph_decode_copy(p, &addr, sizeof(addr));
-               *p += sizeof(struct ceph_timespec);
+               ceph_decode_addr(&addr);
+               ceph_decode_copy(p, &laggy_since, sizeof(laggy_since));
                *p += sizeof(u32);
                ceph_decode_32_safe(p, end, namelen, bad);
-               *p += sizeof(namelen);
+               *p += namelen;
                if (infoversion >= 2) {
                        ceph_decode_32_safe(p, end, num_export_targets, bad);
                        pexport_targets = *p;
-                       *p += sizeof(num_export_targets * sizeof(u32));
+                       *p += num_export_targets * sizeof(u32);
                } else {
                        num_export_targets = 0;
                }
 
-               dout("mdsmap_decode %d/%d mds%d.%d %s %s\n",
-                    i+1, n, mds, inc, pr_addr(&addr.in_addr),
+               dout("mdsmap_decode %d/%d %lld mds%d.%d %s %s\n",
+                    i+1, n, global_id, mds, inc,
+                    ceph_pr_addr(&addr.in_addr),
                     ceph_mds_state_name(state));
                if (mds >= 0 && mds < m->m_max_mds && state > 0) {
+                       m->m_info[mds].global_id = global_id;
                        m->m_info[mds].state = state;
                        m->m_info[mds].addr = addr;
+                       m->m_info[mds].laggy =
+                               (laggy_since.tv_sec != 0 ||
+                                laggy_since.tv_nsec != 0);
                        m->m_info[mds].num_export_targets = num_export_targets;
                        if (num_export_targets) {
                                m->m_info[mds].export_targets =
                                        kcalloc(num_export_targets, sizeof(u32),
                                                GFP_NOFS);
                                for (j = 0; j < num_export_targets; j++)
-                                       ceph_decode_32(&pexport_targets,
-                                             m->m_info[mds].export_targets[j]);
+                                       m->m_info[mds].export_targets[j] =
+                                              ceph_decode_32(&pexport_targets);
                        } else {
                                m->m_info[mds].export_targets = NULL;
                        }
@@ -139,8 +149,8 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
                goto badmem;
        ceph_decode_need(p, end, sizeof(u32)*(n+1), bad);
        for (i = 0; i < n; i++)
-               ceph_decode_32(p, m->m_data_pg_pools[i]);
-       ceph_decode_32(p, m->m_cas_pg_pool);
+               m->m_data_pg_pools[i] = ceph_decode_32(p);
+       m->m_cas_pg_pool = ceph_decode_32(p);
 
        /* ok, we don't care about the rest. */
        dout("mdsmap_decode success epoch %u\n", m->m_epoch);
@@ -150,6 +160,9 @@ badmem:
        err = -ENOMEM;
 bad:
        pr_err("corrupt mdsmap\n");
+       print_hex_dump(KERN_DEBUG, "mdsmap: ",
+                      DUMP_PREFIX_OFFSET, 16, 1,
+                      start, end - start, true);
        ceph_mdsmap_destroy(m);
        return ERR_PTR(-EINVAL);
 }