]> git.karo-electronics.de Git - linux-beck.git/commitdiff
pnfsblock: merge rw extents
authorFred Isaman <iisaman@citi.umich.edu>
Sun, 31 Jul 2011 00:52:50 +0000 (20:52 -0400)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Sun, 31 Jul 2011 16:18:17 +0000 (12:18 -0400)
Signed-off-by: Fred Isaman <iisaman@citi.umich.edu>
Signed-off-by: Benny Halevy <bhalevy@panasas.com>
Signed-off-by: Benny Halevy <bhalevy@tonian.com>
Signed-off-by: Jim Rees <rees@umich.edu>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
fs/nfs/blocklayout/extents.c

index 473faee9cdef0b35cffacc6a6340770a1b7685aa..292aadfd4d461c8224692888786b81f34c1a0c5d 100644 (file)
@@ -493,3 +493,50 @@ bl_find_get_extent(struct pnfs_block_layout *bl, sector_t isect,
        print_bl_extent(ret);
        return ret;
 }
+
+/* Helper function to set_to_rw that initialize a new extent */
+static void
+_prep_new_extent(struct pnfs_block_extent *new,
+                struct pnfs_block_extent *orig,
+                sector_t offset, sector_t length, int state)
+{
+       kref_init(&new->be_refcnt);
+       /* don't need to INIT_LIST_HEAD(&new->be_node) */
+       memcpy(&new->be_devid, &orig->be_devid, sizeof(struct nfs4_deviceid));
+       new->be_mdev = orig->be_mdev;
+       new->be_f_offset = offset;
+       new->be_length = length;
+       new->be_v_offset = orig->be_v_offset - orig->be_f_offset + offset;
+       new->be_state = state;
+       new->be_inval = orig->be_inval;
+}
+
+/* Tries to merge be with extent in front of it in list.
+ * Frees storage if not used.
+ */
+static struct pnfs_block_extent *
+_front_merge(struct pnfs_block_extent *be, struct list_head *head,
+            struct pnfs_block_extent *storage)
+{
+       struct pnfs_block_extent *prev;
+
+       if (!storage)
+               goto no_merge;
+       if (&be->be_node == head || be->be_node.prev == head)
+               goto no_merge;
+       prev = list_entry(be->be_node.prev, struct pnfs_block_extent, be_node);
+       if ((prev->be_f_offset + prev->be_length != be->be_f_offset) ||
+           !extents_consistent(prev, be))
+               goto no_merge;
+       _prep_new_extent(storage, prev, prev->be_f_offset,
+                        prev->be_length + be->be_length, prev->be_state);
+       list_replace(&prev->be_node, &storage->be_node);
+       bl_put_extent(prev);
+       list_del(&be->be_node);
+       bl_put_extent(be);
+       return storage;
+
+ no_merge:
+       kfree(storage);
+       return be;
+}