Whamcloud - gitweb
LU-12268 osd: BUG_ON for IAM corruption
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_iam.c
index a699f02..c8a06d8 100644 (file)
@@ -27,7 +27,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * iam.c
  * Top-level entry points into iam module
 
 #include <ldiskfs/acl.h>
 
-/*
- * List of all registered formats.
- *
- * No locking. Callers synchronize.
- */
-static LIST_HEAD(iam_formats);
-
-void iam_format_register(struct iam_format *fmt)
-{
-       list_add(&fmt->if_linkage, &iam_formats);
-}
-
 static struct buffer_head *
 iam_load_idle_blocks(struct iam_container *c, iam_ptr_t blk)
 {
@@ -178,7 +165,7 @@ iam_load_idle_blocks(struct iam_container *c, iam_ptr_t blk)
 
        bh = __ldiskfs_bread(NULL, inode, blk, 0);
        if (IS_ERR_OR_NULL(bh)) {
-               CERROR("%s: cannot load idle blocks, blk = %u, err = %ld\n",
+               CERROR("%s: cannot load idle blocks, blk = %u: rc = %ld\n",
                       osd_ino2name(inode), blk, bh ? PTR_ERR(bh) : -EIO);
                c->ic_idle_failed = 1;
                if (bh == NULL)
@@ -188,11 +175,14 @@ iam_load_idle_blocks(struct iam_container *c, iam_ptr_t blk)
 
        head = (struct iam_idle_head *)(bh->b_data);
        if (le16_to_cpu(head->iih_magic) != IAM_IDLE_HEADER_MAGIC) {
-               CERROR("%s: invalid idle block head, blk = %u, magic = %d\n",
-                      osd_ino2name(inode), blk, le16_to_cpu(head->iih_magic));
+               int rc = -EBADF;
+
+               CERROR("%s: invalid idle block head, blk = %u, magic = %x: rc = %d\n",
+                      osd_ino2name(inode), blk, le16_to_cpu(head->iih_magic),
+                      rc);
                brelse(bh);
                c->ic_idle_failed = 1;
-               return ERR_PTR(-EBADF);
+               return ERR_PTR(rc);
        }
 
        return bh;
@@ -205,27 +195,10 @@ iam_load_idle_blocks(struct iam_container *c, iam_ptr_t blk)
 static int iam_format_guess(struct iam_container *c)
 {
        int result;
-       struct iam_format *fmt;
-
-       /*
-        * XXX temporary initialization hook.
-        */
-       {
-               static int initialized = 0;
 
-               if (!initialized) {
-                       iam_lvar_format_init();
-                       iam_lfix_format_init();
-                       initialized = 1;
-               }
-       }
-
-       result = -ENOENT;
-       list_for_each_entry(fmt, &iam_formats, if_linkage) {
-               result = fmt->if_guess(c);
-               if (result == 0)
-                       break;
-       }
+       result = iam_lvar_guess(c);
+       if (result)
+               result = iam_lfix_guess(c);
 
        if (result == 0) {
                struct buffer_head *bh;
@@ -806,12 +779,18 @@ void iam_insert_key(struct iam_path *path, struct iam_frame *frame,
        assert_corr(count < dx_get_limit(entries));
        assert_corr(frame->at < iam_entry_shift(path, entries, count));
        assert_inv(dx_node_check(path, frame));
+       /* Prevent memory corruption outside of buffer_head */
+       BUG_ON(count >= dx_get_limit(entries));
+       BUG_ON((char *)iam_entry_shift(path, entries, count + 1) >
+              (frame->bh->b_data + frame->bh->b_size));
 
        memmove(iam_entry_shift(path, new, 1), new,
                (char *)iam_entry_shift(path, entries, count) - (char *)new);
        dx_set_ikey(path, new, key);
        dx_set_block(path, new, ptr);
        dx_set_count(entries, count + 1);
+
+       BUG_ON(count > dx_get_limit(entries));
        assert_inv(dx_node_check(path, frame));
 }