Whamcloud - gitweb
LU-1512 oi: reuse idle OI blocks
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_iam_lfix.c
index f676794..efea0b3 100644 (file)
@@ -511,6 +511,11 @@ static void iam_lfix_split(struct iam_leaf *l, struct buffer_head **bh,
         iam_insert_key_lock(path, path->ip_frame, pivot, new_blknr);
 }
 
         iam_insert_key_lock(path, path->ip_frame, pivot, new_blknr);
 }
 
+static int iam_lfix_leaf_empty(struct iam_leaf *leaf)
+{
+       return lentry_count_get(leaf) == 0;
+}
+
 static struct iam_leaf_operations iam_lfix_leaf_ops = {
         .init           = iam_lfix_init,
         .init_new       = iam_lfix_init_new,
 static struct iam_leaf_operations iam_lfix_leaf_ops = {
         .init           = iam_lfix_init,
         .init_new       = iam_lfix_init_new,
@@ -533,7 +538,8 @@ static struct iam_leaf_operations iam_lfix_leaf_ops = {
         .rec_add        = iam_lfix_rec_add,
         .rec_del        = iam_lfix_rec_del,
         .can_add        = iam_lfix_can_add,
         .rec_add        = iam_lfix_rec_add,
         .rec_del        = iam_lfix_rec_del,
         .can_add        = iam_lfix_can_add,
-        .split          = iam_lfix_split
+       .split          = iam_lfix_split,
+       .leaf_empty     = iam_lfix_leaf_empty,
 };
 
 /*
 };
 
 /*
@@ -695,11 +701,14 @@ static int iam_lfix_guess(struct iam_container *c)
                         descr->id_node_gap  = 0;
                         descr->id_ops       = &iam_lfix_ops;
                         descr->id_leaf_ops  = &iam_lfix_leaf_ops;
                         descr->id_node_gap  = 0;
                         descr->id_ops       = &iam_lfix_ops;
                         descr->id_leaf_ops  = &iam_lfix_leaf_ops;
-                } else
-                        result = -EBADF;
-                brelse(bh);
-        }
-        return result;
+
+                       c->ic_root_bh = bh;
+               } else {
+                       result = -EBADF;
+                       brelse(bh);
+               }
+       }
+       return result;
 }
 
 static struct iam_format iam_lfix_format = {
 }
 
 static struct iam_format iam_lfix_format = {
@@ -785,6 +794,18 @@ static void lfix_root(void *buf,
                                         blocksize, keysize + ptrsize)
         };
 
                                         blocksize, keysize + ptrsize)
         };
 
+       /* To guarantee that the padding "keysize + ptrsize"
+        * covers the "dx_countlimit" and the "idle_blocks". */
+       LASSERT((keysize + ptrsize) >=
+               (sizeof(struct dx_countlimit) + sizeof(__u32)));
+
+       entry = limit + 1;
+       /* Put "idle_blocks" just after the limit. There was padding after
+        * the limit, the "idle_blocks" re-uses part of the padding, so no
+        * compatibility issues with old layout.
+        */
+       *(__u32 *)entry = 0;
+
         entry = root + 1;
         /*
          * Skip over @limit.
         entry = root + 1;
         /*
          * Skip over @limit.
@@ -799,18 +820,20 @@ static void lfix_root(void *buf,
          * XXX: this key is hard-coded to be a sequence of 0's.
          */
 
          * XXX: this key is hard-coded to be a sequence of 0's.
          */
 
-        entry += keysize;
-        /* now @entry points to <ptr> */
-        if (ptrsize == 4)
-                STORE_UNALIGNED(cpu_to_le32(1), (u_int32_t *)entry);
-        else
-                STORE_UNALIGNED(cpu_to_le64(1), (u_int64_t *)entry);
+       memset(entry, 0, keysize);
+       entry += keysize;
+       /* now @entry points to <ptr> */
+       if (ptrsize == 4)
+               STORE_UNALIGNED(cpu_to_le32(1), (u_int32_t *)entry);
+       else
+               STORE_UNALIGNED(cpu_to_le64(1), (u_int64_t *)entry);
 }
 
 static void lfix_leaf(void *buf,
 }
 
 static void lfix_leaf(void *buf,
-                      int blocksize, int keysize, int ptrsize, int recsize)
+                     int blocksize, int keysize, int ptrsize, int recsize)
 {
 {
-        struct iam_leaf_head *head;
+       struct iam_leaf_head *head;
+       void *entry;
 
         /* form leaf */
         head = buf;
 
         /* form leaf */
         head = buf;
@@ -822,6 +845,9 @@ static void lfix_leaf(void *buf,
                  */
                 .ill_count = cpu_to_le16(1),
         };
                  */
                 .ill_count = cpu_to_le16(1),
         };
+
+       entry = (void *)(head + 1);
+       memset(entry, 0, keysize + recsize);
 }
 
 int iam_lfix_create(struct inode *obj,
 }
 
 int iam_lfix_create(struct inode *obj,