static LIST_HEAD(buffers);
static LIST_HEAD(states);
-#define LEAK_DEBUG 1
+#define LEAK_DEBUG 0
#ifdef LEAK_DEBUG
-static spinlock_t leak_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(leak_lock);
#endif
#define BUFFER_LRU_MAX 64
while (!list_empty(&states)) {
state = list_entry(states.next, struct extent_state, leak_list);
- printk("state leak: start %Lu end %Lu state %lu in tree %p refs %d\n", state->start, state->end, state->state, state->tree, atomic_read(&state->refs));
+ printk(KERN_ERR "btrfs state leak: start %llu end %llu "
+ "state %lu in tree %p refs %d\n",
+ (unsigned long long)state->start,
+ (unsigned long long)state->end,
+ state->state, state->tree, atomic_read(&state->refs));
list_del(&state->leak_list);
kmem_cache_free(extent_state_cache, state);
while (!list_empty(&buffers)) {
eb = list_entry(buffers.next, struct extent_buffer, leak_list);
- printk("buffer leak start %Lu len %lu refs %d\n", eb->start, eb->len, atomic_read(&eb->refs));
+ printk(KERN_ERR "btrfs buffer leak start %llu len %lu "
+ "refs %d\n", (unsigned long long)eb->start,
+ eb->len, atomic_read(&eb->refs));
list_del(&eb->leak_list);
kmem_cache_free(extent_buffer_cache, eb);
}
spin_lock_init(&tree->buffer_lock);
tree->mapping = mapping;
}
-EXPORT_SYMBOL(extent_io_tree_init);
-struct extent_state *alloc_extent_state(gfp_t mask)
+static struct extent_state *alloc_extent_state(gfp_t mask)
{
struct extent_state *state;
#ifdef LEAK_DEBUG
init_waitqueue_head(&state->wq);
return state;
}
-EXPORT_SYMBOL(alloc_extent_state);
-void free_extent_state(struct extent_state *state)
+static void free_extent_state(struct extent_state *state)
{
if (!state)
return;
kmem_cache_free(extent_state_cache, state);
}
}
-EXPORT_SYMBOL(free_extent_state);
static struct rb_node *tree_insert(struct rb_root *root, u64 offset,
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 tree_entry *entry;
- while(*p) {
+ while (*p) {
parent = *p;
entry = rb_entry(parent, struct tree_entry, rb_node);
struct rb_node **next_ret)
{
struct rb_root *root = &tree->state;
- struct rb_node * n = root->rb_node;
+ struct rb_node *n = root->rb_node;
struct rb_node *prev = NULL;
struct rb_node *orig_prev = NULL;
struct tree_entry *entry;
struct tree_entry *prev_entry = NULL;
- while(n) {
+ while (n) {
entry = rb_entry(n, struct tree_entry, rb_node);
prev = n;
prev_entry = entry;
n = n->rb_left;
else if (offset > entry->end)
n = n->rb_right;
- else {
+ else
return n;
- }
}
if (prev_ret) {
orig_prev = prev;
- while(prev && offset > prev_entry->end) {
+ while (prev && offset > prev_entry->end) {
prev = rb_next(prev);
prev_entry = rb_entry(prev, struct tree_entry, rb_node);
}
if (next_ret) {
prev_entry = rb_entry(prev, struct tree_entry, rb_node);
- while(prev && offset < prev_entry->start) {
+ while (prev && offset < prev_entry->start) {
prev = rb_prev(prev);
prev_entry = rb_entry(prev, struct tree_entry, rb_node);
}
struct rb_node *ret;
ret = __etree_search(tree, offset, &prev, NULL);
- if (!ret) {
+ if (!ret)
return prev;
- }
return ret;
}
u64 offset, struct rb_node *node)
{
struct rb_root *root = &tree->buffer;
- 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 extent_buffer *eb;
- while(*p) {
+ while (*p) {
parent = *p;
eb = rb_entry(parent, struct extent_buffer, rb_node);
u64 offset)
{
struct rb_root *root = &tree->buffer;
- struct rb_node * n = root->rb_node;
+ struct rb_node *n = root->rb_node;
struct extent_buffer *eb;
- while(n) {
+ while (n) {
eb = rb_entry(n, struct extent_buffer, rb_node);
if (offset < eb->start)
n = n->rb_left;
struct extent_state *state,
unsigned long bits)
{
- if (tree->ops && tree->ops->set_bit_hook) {
+ if (tree->ops && tree->ops->clear_bit_hook) {
tree->ops->clear_bit_hook(tree->mapping->host, state->start,
state->end, state->state, bits);
}
struct rb_node *node;
if (end < start) {
- printk("end < start %Lu %Lu\n", end, start);
+ printk(KERN_ERR "btrfs end < start %llu %llu\n",
+ (unsigned long long)end,
+ (unsigned long long)start);
WARN_ON(1);
}
if (bits & EXTENT_DIRTY)
if (node) {
struct extent_state *found;
found = rb_entry(node, struct extent_state, rb_node);
- printk("found node %Lu %Lu on insert of %Lu %Lu\n", found->start, found->end, start, end);
+ printk(KERN_ERR "btrfs found node %llu %llu on insert of "
+ "%llu %llu\n", (unsigned long long)found->start,
+ (unsigned long long)found->end,
+ (unsigned long long)start, (unsigned long long)end);
free_extent_state(state);
return -EEXIST;
}
if (node) {
struct extent_state *found;
found = rb_entry(node, struct extent_state, rb_node);
- printk("found node %Lu %Lu on insert of %Lu %Lu\n", found->start, found->end, prealloc->start, prealloc->end);
free_extent_state(prealloc);
return -EEXIST;
}
struct extent_state *state;
struct extent_state *prealloc = NULL;
struct rb_node *node;
- unsigned long flags;
int err;
int set = 0;
return -ENOMEM;
}
- spin_lock_irqsave(&tree->lock, flags);
+ spin_lock(&tree->lock);
/*
* this search will find the extents that end after
* our range starts
goto search_again;
out:
- spin_unlock_irqrestore(&tree->lock, flags);
+ spin_unlock(&tree->lock);
if (prealloc)
free_extent_state(prealloc);
search_again:
if (start > end)
goto out;
- spin_unlock_irqrestore(&tree->lock, flags);
+ spin_unlock(&tree->lock);
if (mask & __GFP_WAIT)
cond_resched();
goto again;
}
-EXPORT_SYMBOL(clear_extent_bit);
static int wait_on_state(struct extent_io_tree *tree,
struct extent_state *state)
+ __releases(tree->lock)
+ __acquires(tree->lock)
{
DEFINE_WAIT(wait);
prepare_to_wait(&state->wq, &wait, TASK_UNINTERRUPTIBLE);
- spin_unlock_irq(&tree->lock);
+ spin_unlock(&tree->lock);
schedule();
- spin_lock_irq(&tree->lock);
+ spin_lock(&tree->lock);
finish_wait(&state->wq, &wait);
return 0;
}
struct extent_state *state;
struct rb_node *node;
- spin_lock_irq(&tree->lock);
+ spin_lock(&tree->lock);
again:
while (1) {
/*
break;
if (need_resched()) {
- spin_unlock_irq(&tree->lock);
+ spin_unlock(&tree->lock);
cond_resched();
- spin_lock_irq(&tree->lock);
+ spin_lock(&tree->lock);
}
}
out:
- spin_unlock_irq(&tree->lock);
+ spin_unlock(&tree->lock);
return 0;
}
-EXPORT_SYMBOL(wait_extent_bit);
static void set_state_bits(struct extent_io_tree *tree,
struct extent_state *state,
* [start, end] is inclusive
* This takes the tree lock.
*/
-int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, int bits,
- int exclusive, u64 *failed_start, gfp_t mask)
+static int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
+ int bits, int exclusive, u64 *failed_start,
+ gfp_t mask)
{
struct extent_state *state;
struct extent_state *prealloc = NULL;
struct rb_node *node;
- unsigned long flags;
int err = 0;
int set;
u64 last_start;
return -ENOMEM;
}
- spin_lock_irqsave(&tree->lock, flags);
+ spin_lock(&tree->lock);
/*
* this search will find all the extents that end after
* our range starts.
if (end < last_start)
this_end = end;
else
- this_end = last_start -1;
+ this_end = last_start - 1;
err = insert_state(tree, prealloc, start, this_end,
bits);
prealloc = NULL;
goto search_again;
out:
- spin_unlock_irqrestore(&tree->lock, flags);
+ spin_unlock(&tree->lock);
if (prealloc)
free_extent_state(prealloc);
search_again:
if (start > end)
goto out;
- spin_unlock_irqrestore(&tree->lock, flags);
+ spin_unlock(&tree->lock);
if (mask & __GFP_WAIT)
cond_resched();
goto again;
}
-EXPORT_SYMBOL(set_extent_bit);
/* wrappers around set/clear extent bit */
int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
return set_extent_bit(tree, start, end, EXTENT_DIRTY, 0, NULL,
mask);
}
-EXPORT_SYMBOL(set_extent_dirty);
int set_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end,
gfp_t mask)
{
return set_extent_bit(tree, start, end, EXTENT_ORDERED, 0, NULL, mask);
}
-EXPORT_SYMBOL(set_extent_ordered);
int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
int bits, gfp_t mask)
return set_extent_bit(tree, start, end, bits, 0, NULL,
mask);
}
-EXPORT_SYMBOL(set_extent_bits);
int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
int bits, gfp_t mask)
{
return clear_extent_bit(tree, start, end, bits, 0, 0, mask);
}
-EXPORT_SYMBOL(clear_extent_bits);
int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end,
gfp_t mask)
EXTENT_DELALLOC | EXTENT_DIRTY,
0, NULL, mask);
}
-EXPORT_SYMBOL(set_extent_delalloc);
int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
gfp_t mask)
return clear_extent_bit(tree, start, end,
EXTENT_DIRTY | EXTENT_DELALLOC, 0, 0, mask);
}
-EXPORT_SYMBOL(clear_extent_dirty);
int clear_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end,
gfp_t mask)
{
return clear_extent_bit(tree, start, end, EXTENT_ORDERED, 1, 0, mask);
}
-EXPORT_SYMBOL(clear_extent_ordered);
int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
gfp_t mask)
return set_extent_bit(tree, start, end, EXTENT_NEW, 0, NULL,
mask);
}
-EXPORT_SYMBOL(set_extent_new);
-int clear_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
+static int clear_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
gfp_t mask)
{
return clear_extent_bit(tree, start, end, EXTENT_NEW, 0, 0, mask);
}
-EXPORT_SYMBOL(clear_extent_new);
int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
gfp_t mask)
return set_extent_bit(tree, start, end, EXTENT_UPTODATE, 0, NULL,
mask);
}
-EXPORT_SYMBOL(set_extent_uptodate);
-int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
- gfp_t mask)
+static int clear_extent_uptodate(struct extent_io_tree *tree, u64 start,
+ u64 end, gfp_t mask)
{
return clear_extent_bit(tree, start, end, EXTENT_UPTODATE, 0, 0, mask);
}
-EXPORT_SYMBOL(clear_extent_uptodate);
-int set_extent_writeback(struct extent_io_tree *tree, u64 start, u64 end,
+static int set_extent_writeback(struct extent_io_tree *tree, u64 start, u64 end,
gfp_t mask)
{
return set_extent_bit(tree, start, end, EXTENT_WRITEBACK,
0, NULL, mask);
}
-EXPORT_SYMBOL(set_extent_writeback);
-int clear_extent_writeback(struct extent_io_tree *tree, u64 start, u64 end,
- gfp_t mask)
+static int clear_extent_writeback(struct extent_io_tree *tree, u64 start,
+ u64 end, gfp_t mask)
{
return clear_extent_bit(tree, start, end, EXTENT_WRITEBACK, 1, 0, mask);
}
-EXPORT_SYMBOL(clear_extent_writeback);
int wait_on_extent_writeback(struct extent_io_tree *tree, u64 start, u64 end)
{
return wait_extent_bit(tree, start, end, EXTENT_WRITEBACK);
}
-EXPORT_SYMBOL(wait_on_extent_writeback);
/*
* either insert or lock state struct between start and end use mask to tell
}
return err;
}
-EXPORT_SYMBOL(lock_extent);
int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end,
gfp_t mask)
}
return 1;
}
-EXPORT_SYMBOL(try_lock_extent);
int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end,
gfp_t mask)
{
return clear_extent_bit(tree, start, end, EXTENT_LOCKED, 1, 0, mask);
}
-EXPORT_SYMBOL(unlock_extent);
/*
* helper function to set pages and extents in the tree dirty
set_extent_dirty(tree, start, end, GFP_NOFS);
return 0;
}
-EXPORT_SYMBOL(set_range_dirty);
/*
* helper function to set both pages and extents in the tree writeback
*/
-int set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end)
+static int set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end)
{
unsigned long index = start >> PAGE_CACHE_SHIFT;
unsigned long end_index = end >> PAGE_CACHE_SHIFT;
set_extent_writeback(tree, start, end, GFP_NOFS);
return 0;
}
-EXPORT_SYMBOL(set_range_writeback);
/*
* find the first offset in the io tree with 'bits' set. zero is
struct extent_state *state;
int ret = 1;
- spin_lock_irq(&tree->lock);
+ spin_lock(&tree->lock);
/*
* this search will find all the extents that end after
* our range starts.
*/
node = tree_search(tree, start);
- if (!node) {
+ if (!node)
goto out;
- }
- while(1) {
+ while (1) {
state = rb_entry(node, struct extent_state, rb_node);
if (state->end >= start && (state->state & bits)) {
*start_ret = state->start;
break;
}
out:
- spin_unlock_irq(&tree->lock);
+ spin_unlock(&tree->lock);
return ret;
}
-EXPORT_SYMBOL(find_first_extent_bit);
/* find the first state struct with 'bits' set after 'start', and
* return it. tree->lock must be held. NULL will returned if
* our range starts.
*/
node = tree_search(tree, start);
- if (!node) {
+ if (!node)
goto out;
- }
- while(1) {
+ while (1) {
state = rb_entry(node, struct extent_state, rb_node);
- if (state->end >= start && (state->state & bits)) {
+ if (state->end >= start && (state->state & bits))
return state;
- }
+
node = rb_next(node);
if (!node)
break;
out:
return NULL;
}
-EXPORT_SYMBOL(find_first_extent_bit_state);
/*
* find a contiguous range of bytes in the file marked as delalloc, not
u64 found = 0;
u64 total_bytes = 0;
- spin_lock_irq(&tree->lock);
+ spin_lock(&tree->lock);
/*
* this search will find all the extents that end after
goto out;
}
- while(1) {
+ while (1) {
state = rb_entry(node, struct extent_state, rb_node);
if (found && (state->start != cur_start ||
(state->state & EXTENT_BOUNDARY))) {
break;
}
out:
- spin_unlock_irq(&tree->lock);
+ spin_unlock(&tree->lock);
return found;
}
if (index == locked_page->index && end_index == index)
return 0;
- while(nr_pages > 0) {
+ while (nr_pages > 0) {
ret = find_get_pages_contig(inode->i_mapping, index,
- min(nr_pages, ARRAY_SIZE(pages)), pages);
+ min_t(unsigned long, nr_pages,
+ ARRAY_SIZE(pages)), pages);
for (i = 0; i < ret; i++) {
if (pages[i] != locked_page)
unlock_page(pages[i]);
/* skip the page at the start index */
nrpages = end_index - index + 1;
- while(nrpages > 0) {
+ while (nrpages > 0) {
ret = find_get_pages_contig(inode->i_mapping, index,
- min(nrpages, ARRAY_SIZE(pages)), pages);
+ min_t(unsigned long,
+ nrpages, ARRAY_SIZE(pages)), pages);
if (ret == 0) {
ret = -EAGAIN;
goto done;
*/
if (pages[i] != locked_page) {
lock_page(pages[i]);
- if (pages[i]->mapping != inode->i_mapping) {
+ if (!PageDirty(pages[i]) ||
+ pages[i]->mapping != inode->i_mapping) {
ret = -EAGAIN;
unlock_page(pages[i]);
page_cache_release(pages[i]);
* pages in order, so we can't process delalloc bytes before
* locked_page
*/
- if (delalloc_start < *start) {
+ if (delalloc_start < *start)
delalloc_start = *start;
- }
/*
* make sure to limit the number of pages we try to lock down
* if we're looping.
*/
- if (delalloc_end + 1 - delalloc_start > max_bytes && loops) {
+ if (delalloc_end + 1 - delalloc_start > max_bytes && loops)
delalloc_end = delalloc_start + PAGE_CACHE_SIZE - 1;
- }
+
/* step two, lock all the pages after the page that has start */
ret = lock_delalloc_pages(inode, locked_page,
delalloc_start, delalloc_end);
if (!(unlock_pages || clear_dirty || set_writeback || end_writeback))
return 0;
- while(nr_pages > 0) {
+ while (nr_pages > 0) {
ret = find_get_pages_contig(inode->i_mapping, index,
- min(nr_pages, ARRAY_SIZE(pages)), pages);
+ min_t(unsigned long,
+ nr_pages, ARRAY_SIZE(pages)), pages);
for (i = 0; i < ret; i++) {
if (pages[i] == locked_page) {
page_cache_release(pages[i]);
}
return 0;
}
-EXPORT_SYMBOL(extent_clear_unlock_delalloc);
/*
* count the number of bytes in the tree that have a given bit(s)
int found = 0;
if (search_end <= cur_start) {
- printk("search_end %Lu start %Lu\n", search_end, cur_start);
WARN_ON(1);
return 0;
}
- spin_lock_irq(&tree->lock);
+ spin_lock(&tree->lock);
if (cur_start == 0 && bits == EXTENT_DIRTY) {
total_bytes = tree->dirty_bytes;
goto out;
* our range starts.
*/
node = tree_search(tree, cur_start);
- if (!node) {
+ if (!node)
goto out;
- }
- while(1) {
+ while (1) {
state = rb_entry(node, struct extent_state, rb_node);
if (state->start > search_end)
break;
break;
}
out:
- spin_unlock_irq(&tree->lock);
+ spin_unlock(&tree->lock);
return total_bytes;
}
+
+#if 0
/*
* helper function to lock both pages and extents in the tree.
* pages must be locked first.
*/
-int lock_range(struct extent_io_tree *tree, u64 start, u64 end)
+static int lock_range(struct extent_io_tree *tree, u64 start, u64 end)
{
unsigned long index = start >> PAGE_CACHE_SHIFT;
unsigned long end_index = end >> PAGE_CACHE_SHIFT;
}
return err;
}
-EXPORT_SYMBOL(lock_range);
/*
* helper function to unlock both pages and extents in the tree.
*/
-int unlock_range(struct extent_io_tree *tree, u64 start, u64 end)
+static int unlock_range(struct extent_io_tree *tree, u64 start, u64 end)
{
unsigned long index = start >> PAGE_CACHE_SHIFT;
unsigned long end_index = end >> PAGE_CACHE_SHIFT;
unlock_extent(tree, start, end, GFP_NOFS);
return 0;
}
-EXPORT_SYMBOL(unlock_range);
+#endif
/*
* set the private field for a given byte offset in the tree. If there isn't
struct extent_state *state;
int ret = 0;
- spin_lock_irq(&tree->lock);
+ spin_lock(&tree->lock);
/*
* this search will find all the extents that end after
* our range starts.
}
state->private = private;
out:
- spin_unlock_irq(&tree->lock);
+ spin_unlock(&tree->lock);
return ret;
}
struct extent_state *state;
int ret = 0;
- spin_lock_irq(&tree->lock);
+ spin_lock(&tree->lock);
/*
* this search will find all the extents that end after
* our range starts.
}
*private = state->private;
out:
- spin_unlock_irq(&tree->lock);
+ spin_unlock(&tree->lock);
return ret;
}
struct extent_state *state = NULL;
struct rb_node *node;
int bitset = 0;
- unsigned long flags;
- spin_lock_irqsave(&tree->lock, flags);
+ spin_lock(&tree->lock);
node = tree_search(tree, start);
while (node && start <= end) {
state = rb_entry(node, struct extent_state, rb_node);
break;
}
}
- spin_unlock_irqrestore(&tree->lock, flags);
+ spin_unlock(&tree->lock);
return bitset;
}
-EXPORT_SYMBOL(test_range_bit);
/*
* helper function to set a given page up to date if all the
int whole_page;
int ret;
+ if (err)
+ uptodate = 0;
+
do {
struct page *page = bvec->bv_page;
tree = &BTRFS_I(page->mapping->host)->io_tree;
if (ret == 0) {
uptodate =
test_bit(BIO_UPTODATE, &bio->bi_flags);
+ if (err)
+ uptodate = 0;
continue;
}
}
int contig = 0;
int this_compressed = bio_flags & EXTENT_BIO_COMPRESSED;
int old_compressed = prev_bio_flags & EXTENT_BIO_COMPRESSED;
- size_t page_size = min(size, PAGE_CACHE_SIZE);
+ size_t page_size = min_t(size_t, size, PAGE_CACHE_SIZE);
if (bio_ret && *bio_ret) {
bio = *bio_ret;
nr = bio_get_nr_vecs(bdev);
bio = extent_bio_alloc(bdev, sector, nr, GFP_NOFS | __GFP_HIGH);
- if (!bio) {
- printk("failed to allocate bio nr %d\n", nr);
- }
bio_add_page(bio, page, page_size, offset);
bio->bi_end_io = end_io_func;
bio->bi_private = tree;
- if (bio_ret) {
+ if (bio_ret)
*bio_ret = bio;
- } else {
+ else
ret = submit_one_bio(rw, bio, mirror_num, bio_flags);
- }
return ret;
}
set_page_private(page, EXTENT_PAGE_PRIVATE);
}
}
-EXPORT_SYMBOL(set_page_extent_mapped);
-void set_page_extent_head(struct page *page, unsigned long len)
+static void set_page_extent_head(struct page *page, unsigned long len)
{
set_page_private(page, EXTENT_PAGE_PRIVATE_FIRST_PAGE | len << 2);
}
break;
}
extent_offset = cur - em->start;
- if (extent_map_end(em) <= cur) {
-printk("bad mapping em [%Lu %Lu] cur %Lu\n", em->start, extent_map_end(em), cur);
- }
BUG_ON(extent_map_end(em) <= cur);
- if (end < cur) {
-printk("2bad mapping end %Lu cur %Lu\n", end, cur);
- }
BUG_ON(end < cur);
if (test_bit(EXTENT_FLAG_COMPRESSED, &em->flags))
submit_one_bio(READ, bio, 0, bio_flags);
return ret;
}
-EXPORT_SYMBOL(extent_read_full_page);
/*
* the writepage semantics are similar to regular writepage. extent
pg_offset = i_size & (PAGE_CACHE_SIZE - 1);
if (page->index > end_index ||
(page->index == end_index && !pg_offset)) {
- if (epd->extent_locked) {
- if (tree->ops && tree->ops->writepage_end_io_hook)
- tree->ops->writepage_end_io_hook(page, start,
- page_end, NULL, 1);
- }
+ page->mapping->a_ops->invalidatepage(page, 0);
unlock_page(page);
return 0;
}
delalloc_end = 0;
page_started = 0;
if (!epd->extent_locked) {
- while(delalloc_end < page_end) {
+ while (delalloc_end < page_end) {
nr_delalloc = find_lock_delalloc_range(inode, tree,
page,
&delalloc_start,
nr_written++;
end = page_end;
- if (test_range_bit(tree, start, page_end, EXTENT_DELALLOC, 0)) {
- printk("found delalloc bits after lock_extent\n");
- }
+ if (test_range_bit(tree, start, page_end, EXTENT_DELALLOC, 0))
+ printk(KERN_ERR "btrfs delalloc bits after lock_extent\n");
if (last_byte <= start) {
clear_extent_dirty(tree, start, page_end, GFP_NOFS);
clear_extent_dirty(tree, cur,
cur + iosize - 1, GFP_NOFS);
- unlock_extent(tree, unlock_start, cur + iosize -1,
+ unlock_extent(tree, unlock_start, cur + iosize - 1,
GFP_NOFS);
/*
set_range_writeback(tree, cur, cur + iosize - 1);
if (!PageWriteback(page)) {
- printk("warning page %lu not writeback, "
- "cur %llu end %llu\n", page->index,
- (unsigned long long)cur,
+ printk(KERN_ERR "btrfs warning page %lu not "
+ "writeback, cur %llu end %llu\n",
+ page->index, (unsigned long long)cur,
(unsigned long long)end);
}
* WB_SYNC_ALL then we were called for data integrity and we must wait for
* existing IO to complete.
*/
-int extent_write_cache_pages(struct extent_io_tree *tree,
+static int extent_write_cache_pages(struct extent_io_tree *tree,
struct address_space *mapping,
struct writeback_control *wbc,
- writepage_t writepage, void *data)
+ writepage_t writepage, void *data,
+ void (*flush_fn)(void *))
{
struct backing_dev_info *bdi = mapping->backing_dev_info;
int ret = 0;
retry:
while (!done && (index <= end) &&
(nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
- PAGECACHE_TAG_DIRTY,
- min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1))) {
+ PAGECACHE_TAG_DIRTY, min(end - index,
+ (pgoff_t)PAGEVEC_SIZE-1) + 1))) {
unsigned i;
scanned = 1;
continue;
}
- if (wbc->sync_mode != WB_SYNC_NONE)
+ if (wbc->sync_mode != WB_SYNC_NONE) {
+ if (PageWriteback(page))
+ flush_fn(data);
wait_on_page_writeback(page);
+ }
if (PageWriteback(page) ||
!clear_page_dirty_for_io(page)) {
index = 0;
goto retry;
}
- if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
- mapping->writeback_index = index;
- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
- range_whole = 1;
-
- if (wbc->range_cont)
- wbc->range_start = index << PAGE_CACHE_SHIFT;
return ret;
}
-EXPORT_SYMBOL(extent_write_cache_pages);
+
+static noinline void flush_write_bio(void *data)
+{
+ struct extent_page_data *epd = data;
+ if (epd->bio) {
+ submit_one_bio(WRITE, epd->bio, 0, 0);
+ epd->bio = NULL;
+ }
+}
int extent_write_full_page(struct extent_io_tree *tree, struct page *page,
get_extent_t *get_extent,
ret = __extent_writepage(page, wbc, &epd);
extent_write_cache_pages(tree, mapping, &wbc_writepages,
- __extent_writepage, &epd);
- if (epd.bio) {
+ __extent_writepage, &epd, flush_write_bio);
+ if (epd.bio)
submit_one_bio(WRITE, epd.bio, 0, 0);
- }
return ret;
}
-EXPORT_SYMBOL(extent_write_full_page);
int extent_write_locked_range(struct extent_io_tree *tree, struct inode *inode,
u64 start, u64 end, get_extent_t *get_extent,
.range_end = end + 1,
};
- while(start <= end) {
+ while (start <= end) {
page = find_get_page(mapping, start >> PAGE_CACHE_SHIFT);
if (clear_page_dirty_for_io(page))
ret = __extent_writepage(page, &wbc_writepages, &epd);
submit_one_bio(WRITE, epd.bio, 0, 0);
return ret;
}
-EXPORT_SYMBOL(extent_write_locked_range);
-
int extent_writepages(struct extent_io_tree *tree,
struct address_space *mapping,
};
ret = extent_write_cache_pages(tree, mapping, wbc,
- __extent_writepage, &epd);
- if (epd.bio) {
+ __extent_writepage, &epd,
+ flush_write_bio);
+ if (epd.bio)
submit_one_bio(WRITE, epd.bio, 0, 0);
- }
return ret;
}
-EXPORT_SYMBOL(extent_writepages);
int extent_readpages(struct extent_io_tree *tree,
struct address_space *mapping,
/* open coding of lru_cache_add, also not exported */
page_cache_get(page);
if (!pagevec_add(&pvec, page))
- __pagevec_lru_add(&pvec);
+ __pagevec_lru_add_file(&pvec);
__extent_read_full_page(tree, page, get_extent,
&bio, 0, &bio_flags);
}
page_cache_release(page);
}
if (pagevec_count(&pvec))
- __pagevec_lru_add(&pvec);
+ __pagevec_lru_add_file(&pvec);
BUG_ON(!list_empty(pages));
if (bio)
submit_one_bio(READ, bio, 0, bio_flags);
return 0;
}
-EXPORT_SYMBOL(extent_readpages);
/*
* basic invalidatepage code, this waits on any locked or writeback
u64 end = start + PAGE_CACHE_SIZE - 1;
size_t blocksize = page->mapping->host->i_sb->s_blocksize;
- start += (offset + blocksize -1) & ~(blocksize - 1);
+ start += (offset + blocksize - 1) & ~(blocksize - 1);
if (start > end)
return 0;
1, 1, GFP_NOFS);
return 0;
}
-EXPORT_SYMBOL(extent_invalidatepage);
/*
* simple commit_write call, set_range_dirty is used to mark both
}
return 0;
}
-EXPORT_SYMBOL(extent_commit_write);
int extent_prepare_write(struct extent_io_tree *tree,
struct inode *inode, struct page *page,
orig_block_start = block_start;
lock_extent(tree, page_start, page_end, GFP_NOFS);
- while(block_start <= block_end) {
+ while (block_start <= block_end) {
em = get_extent(inode, page, page_offset, block_start,
block_end - block_start + 1, 1);
- if (IS_ERR(em) || !em) {
+ if (IS_ERR(em) || !em)
goto err;
- }
+
cur_end = min(block_end, extent_map_end(em) - 1);
block_off_start = block_start & (PAGE_CACHE_SIZE - 1);
block_off_end = block_off_start + blocksize;
/* FIXME, zero out newly allocated blocks on error */
return err;
}
-EXPORT_SYMBOL(extent_prepare_write);
/*
* a helper for releasepage, this tests for areas of the page that
}
return ret;
}
-EXPORT_SYMBOL(try_release_extent_state);
/*
* a helper for releasepage. As long as there are no locked extents
}
return try_release_extent_state(map, tree, page, mask);
}
-EXPORT_SYMBOL(try_release_extent_mapping);
sector_t extent_bmap(struct address_space *mapping, sector_t iblock,
get_extent_t *get_extent)
__free_extent_buffer(eb);
return exists;
}
-EXPORT_SYMBOL(alloc_extent_buffer);
struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
u64 start, unsigned long len,
return eb;
}
-EXPORT_SYMBOL(find_extent_buffer);
void free_extent_buffer(struct extent_buffer *eb)
{
WARN_ON(1);
}
-EXPORT_SYMBOL(free_extent_buffer);
int clear_extent_buffer_dirty(struct extent_io_tree *tree,
struct extent_buffer *eb)
for (i = 0; i < num_pages; i++) {
page = extent_buffer_page(eb, i);
+ if (!set && !PageDirty(page))
+ continue;
+
lock_page(page);
if (i == 0)
set_page_extent_head(page, eb->len);
}
return 0;
}
-EXPORT_SYMBOL(clear_extent_buffer_dirty);
int wait_on_extent_buffer_writeback(struct extent_io_tree *tree,
struct extent_buffer *eb)
return wait_on_extent_writeback(tree, eb->start,
eb->start + eb->len - 1);
}
-EXPORT_SYMBOL(wait_on_extent_buffer_writeback);
int set_extent_buffer_dirty(struct extent_io_tree *tree,
struct extent_buffer *eb)
}
__set_page_dirty_nobuffers(extent_buffer_page(eb, i));
set_extent_dirty(tree, page_offset(page),
- page_offset(page) + PAGE_CACHE_SIZE -1,
+ page_offset(page) + PAGE_CACHE_SIZE - 1,
GFP_NOFS);
unlock_page(page);
}
return 0;
}
-EXPORT_SYMBOL(set_extent_buffer_dirty);
int clear_extent_buffer_uptodate(struct extent_io_tree *tree,
struct extent_buffer *eb)
}
return 0;
}
-EXPORT_SYMBOL(set_extent_buffer_uptodate);
int extent_range_uptodate(struct extent_io_tree *tree,
u64 start, u64 end)
ret = test_range_bit(tree, start, end, EXTENT_UPTODATE, 1);
if (ret)
return 1;
- while(start <= end) {
+ while (start <= end) {
index = start >> PAGE_CACHE_SHIFT;
page = find_get_page(tree->mapping, index);
uptodate = PageUptodate(page);
}
return pg_uptodate;
}
-EXPORT_SYMBOL(extent_buffer_uptodate);
int read_extent_buffer_pages(struct extent_io_tree *tree,
struct extent_buffer *eb,
lock_page(page);
}
locked_pages++;
- if (!PageUptodate(page)) {
+ if (!PageUptodate(page))
all_uptodate = 0;
- }
}
if (all_uptodate) {
if (start_i == 0)
eb->flags |= EXTENT_UPTODATE;
- if (ret) {
- printk("all up to date but ret is %d\n", ret);
- }
goto unlock_exit;
}
err = __extent_read_full_page(tree, page,
get_extent, &bio,
mirror_num, &bio_flags);
- if (err) {
+ if (err)
ret = err;
- printk("err %d from __extent_read_full_page\n", ret);
- }
} else {
unlock_page(page);
}
if (bio)
submit_one_bio(READ, bio, mirror_num, bio_flags);
- if (ret || !wait) {
- if (ret)
- printk("ret %d wait %d returning\n", ret, wait);
+ if (ret || !wait)
return ret;
- }
+
for (i = start_i; i < num_pages; i++) {
page = extent_buffer_page(eb, i);
wait_on_page_locked(page);
- if (!PageUptodate(page)) {
- printk("page not uptodate after wait_on_page_locked\n");
+ if (!PageUptodate(page))
ret = -EIO;
- }
}
+
if (!ret)
eb->flags |= EXTENT_UPTODATE;
return ret;
unlock_exit:
i = start_i;
- while(locked_pages > 0) {
+ while (locked_pages > 0) {
page = extent_buffer_page(eb, i);
i++;
unlock_page(page);
}
return ret;
}
-EXPORT_SYMBOL(read_extent_buffer_pages);
void read_extent_buffer(struct extent_buffer *eb, void *dstv,
unsigned long start,
offset = (start_offset + start) & ((unsigned long)PAGE_CACHE_SIZE - 1);
- while(len > 0) {
+ while (len > 0) {
page = extent_buffer_page(eb, i);
cur = min(len, (PAGE_CACHE_SIZE - offset));
i++;
}
}
-EXPORT_SYMBOL(read_extent_buffer);
int map_private_extent_buffer(struct extent_buffer *eb, unsigned long start,
unsigned long min_len, char **token, char **map,
offset = 0;
*map_start = ((u64)i << PAGE_CACHE_SHIFT) - start_offset;
}
+
if (start + min_len > eb->len) {
-printk("bad mapping eb start %Lu len %lu, wanted %lu %lu\n", eb->start, eb->len, start, min_len);
+ printk(KERN_ERR "btrfs bad mapping eb start %llu len %lu, "
+ "wanted %lu %lu\n", (unsigned long long)eb->start,
+ eb->len, start, min_len);
WARN_ON(1);
}
*map_len = PAGE_CACHE_SIZE - offset;
return 0;
}
-EXPORT_SYMBOL(map_private_extent_buffer);
int map_extent_buffer(struct extent_buffer *eb, unsigned long start,
unsigned long min_len,
unmap_extent_buffer(eb, eb->map_token, km);
eb->map_token = NULL;
save = 1;
+ WARN_ON(!mutex_is_locked(&eb->mutex));
}
err = map_private_extent_buffer(eb, start, min_len, token, map,
map_start, map_len, km);
}
return err;
}
-EXPORT_SYMBOL(map_extent_buffer);
void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km)
{
kunmap_atomic(token, km);
}
-EXPORT_SYMBOL(unmap_extent_buffer);
int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv,
unsigned long start,
offset = (start_offset + start) & ((unsigned long)PAGE_CACHE_SIZE - 1);
- while(len > 0) {
+ while (len > 0) {
page = extent_buffer_page(eb, i);
cur = min(len, (PAGE_CACHE_SIZE - offset));
}
return ret;
}
-EXPORT_SYMBOL(memcmp_extent_buffer);
void write_extent_buffer(struct extent_buffer *eb, const void *srcv,
unsigned long start, unsigned long len)
offset = (start_offset + start) & ((unsigned long)PAGE_CACHE_SIZE - 1);
- while(len > 0) {
+ while (len > 0) {
page = extent_buffer_page(eb, i);
WARN_ON(!PageUptodate(page));
i++;
}
}
-EXPORT_SYMBOL(write_extent_buffer);
void memset_extent_buffer(struct extent_buffer *eb, char c,
unsigned long start, unsigned long len)
offset = (start_offset + start) & ((unsigned long)PAGE_CACHE_SIZE - 1);
- while(len > 0) {
+ while (len > 0) {
page = extent_buffer_page(eb, i);
WARN_ON(!PageUptodate(page));
i++;
}
}
-EXPORT_SYMBOL(memset_extent_buffer);
void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
unsigned long dst_offset, unsigned long src_offset,
offset = (start_offset + dst_offset) &
((unsigned long)PAGE_CACHE_SIZE - 1);
- while(len > 0) {
+ while (len > 0) {
page = extent_buffer_page(dst, i);
WARN_ON(!PageUptodate(page));
i++;
}
}
-EXPORT_SYMBOL(copy_extent_buffer);
static void move_pages(struct page *dst_page, struct page *src_page,
unsigned long dst_off, unsigned long src_off,
unsigned long src_i;
if (src_offset + len > dst->len) {
- printk("memmove bogus src_offset %lu move len %lu len %lu\n",
- src_offset, len, dst->len);
+ printk(KERN_ERR "btrfs memmove bogus src_offset %lu move "
+ "len %lu dst len %lu\n", src_offset, len, dst->len);
BUG_ON(1);
}
if (dst_offset + len > dst->len) {
- printk("memmove bogus dst_offset %lu move len %lu len %lu\n",
- dst_offset, len, dst->len);
+ printk(KERN_ERR "btrfs memmove bogus dst_offset %lu move "
+ "len %lu dst len %lu\n", dst_offset, len, dst->len);
BUG_ON(1);
}
- while(len > 0) {
+ while (len > 0) {
dst_off_in_page = (start_offset + dst_offset) &
((unsigned long)PAGE_CACHE_SIZE - 1);
src_off_in_page = (start_offset + src_offset) &
len -= cur;
}
}
-EXPORT_SYMBOL(memcpy_extent_buffer);
void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
unsigned long src_offset, unsigned long len)
unsigned long src_i;
if (src_offset + len > dst->len) {
- printk("memmove bogus src_offset %lu move len %lu len %lu\n",
- src_offset, len, dst->len);
+ printk(KERN_ERR "btrfs memmove bogus src_offset %lu move "
+ "len %lu len %lu\n", src_offset, len, dst->len);
BUG_ON(1);
}
if (dst_offset + len > dst->len) {
- printk("memmove bogus dst_offset %lu move len %lu len %lu\n",
- dst_offset, len, dst->len);
+ printk(KERN_ERR "btrfs memmove bogus dst_offset %lu move "
+ "len %lu len %lu\n", dst_offset, len, dst->len);
BUG_ON(1);
}
if (dst_offset < src_offset) {
memcpy_extent_buffer(dst, dst_offset, src_offset, len);
return;
}
- while(len > 0) {
+ while (len > 0) {
dst_i = (start_offset + dst_end) >> PAGE_CACHE_SHIFT;
src_i = (start_offset + src_end) >> PAGE_CACHE_SHIFT;
len -= cur;
}
}
-EXPORT_SYMBOL(memmove_extent_buffer);
int try_release_extent_buffer(struct extent_io_tree *tree, struct page *page)
{
spin_unlock(&tree->buffer_lock);
return ret;
}
-EXPORT_SYMBOL(try_release_extent_buffer);