]> Pileus Git - ~andy/linux/blobdiff - fs/btrfs/ref-cache.c
Merge branch 'drm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/airlied...
[~andy/linux] / fs / btrfs / ref-cache.c
index 30fcb7aea5b5e709298fb813193f431738c811b1..d0cc62bccb948e776fb9845c7da1a8f2119788f6 100644 (file)
  */
 
 #include <linux/sched.h>
+#include <linux/sort.h>
 #include "ctree.h"
 #include "ref-cache.h"
 #include "transaction.h"
 
+/*
+ * leaf refs are used to cache the information about which extents
+ * a given leaf has references on.  This allows us to process that leaf
+ * in btrfs_drop_snapshot without needing to read it back from disk.
+ */
+
+/*
+ * kmalloc a leaf reference struct and update the counters for the
+ * total ref cache size
+ */
 struct btrfs_leaf_ref *btrfs_alloc_leaf_ref(struct btrfs_root *root,
                                            int nr_extents)
 {
@@ -40,6 +51,10 @@ struct btrfs_leaf_ref *btrfs_alloc_leaf_ref(struct btrfs_root *root,
        return ref;
 }
 
+/*
+ * free a leaf reference struct and update the counters for the
+ * total ref cache size
+ */
 void btrfs_free_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref)
 {
        if (!ref)
@@ -60,11 +75,11 @@ void btrfs_free_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref)
 static struct rb_node *tree_insert(struct rb_root *root, u64 bytenr,
                                   struct rb_node *node)
 {
-       struct rb_node ** p = &root->rb_node;
-       struct rb_node * parent = NULL;
+       struct rb_node **p = &root->rb_node;
+       struct rb_node *parent = NULL;
        struct btrfs_leaf_ref *entry;
 
-       while(*p) {
+       while (*p) {
                parent = *p;
                entry = rb_entry(parent, struct btrfs_leaf_ref, rb_node);
 
@@ -84,10 +99,10 @@ static struct rb_node *tree_insert(struct rb_root *root, u64 bytenr,
 
 static struct rb_node *tree_search(struct rb_root *root, u64 bytenr)
 {
-       struct rb_node * n = root->rb_node;
+       struct rb_node *n = root->rb_node;
        struct btrfs_leaf_ref *entry;
 
-       while(n) {
+       while (n) {
                entry = rb_entry(n, struct btrfs_leaf_ref, rb_node);
                WARN_ON(!entry->in_tree);
 
@@ -113,7 +128,7 @@ int btrfs_remove_leaf_refs(struct btrfs_root *root, u64 max_root_gen,
                return 0;
 
        spin_lock(&tree->lock);
-       while(!list_empty(&tree->list)) {
+       while (!list_empty(&tree->list)) {
                ref = list_entry(tree->list.next, struct btrfs_leaf_ref, list);
                BUG_ON(ref->tree != tree);
                if (ref->root_gen > max_root_gen)
@@ -135,6 +150,10 @@ int btrfs_remove_leaf_refs(struct btrfs_root *root, u64 max_root_gen,
        return 0;
 }
 
+/*
+ * find the leaf ref for a given extent.  This returns the ref struct with
+ * a usage reference incremented
+ */
 struct btrfs_leaf_ref *btrfs_lookup_leaf_ref(struct btrfs_root *root,
                                             u64 bytenr)
 {
@@ -160,6 +179,10 @@ again:
        return NULL;
 }
 
+/*
+ * add a fully filled in leaf ref struct
+ * remove all the refs older than a given root generation
+ */
 int btrfs_add_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref,
                       int shared)
 {
@@ -184,6 +207,10 @@ int btrfs_add_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref,
        return ret;
 }
 
+/*
+ * remove a single leaf ref from the tree.  This drops the ref held by the tree
+ * only
+ */
 int btrfs_remove_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref)
 {
        struct btrfs_leaf_ref_tree *tree;