#include <linux/swap.h>
#include <linux/radix-tree.h>
#include <linux/writeback.h>
-#include <linux/buffer_head.h> // for block_sync_page
+#include <linux/buffer_head.h>
#include <linux/workqueue.h>
#include <linux/kthread.h>
#include <linux/freezer.h>
#include "ref-cache.h"
#include "tree-log.h"
-#if 0
-static int check_tree_block(struct btrfs_root *root, struct extent_buffer *buf)
-{
- if (extent_buffer_blocknr(buf) != btrfs_header_blocknr(buf)) {
- printk(KERN_CRIT "buf blocknr(buf) is %llu, header is %llu\n",
- (unsigned long long)extent_buffer_blocknr(buf),
- (unsigned long long)btrfs_header_blocknr(buf));
- return 1;
- }
- return 0;
-}
-#endif
-
static struct extent_io_ops btree_extent_io_ops;
static void end_workqueue_fn(struct btrfs_work *work);
u64 failed_start = em->start;
u64 failed_len = em->len;
- printk("failed to insert %Lu %Lu -> %Lu into tree\n",
- em->start, em->len, em->block_start);
free_extent_map(em);
em = lookup_extent_mapping(em_tree, start, len);
if (em) {
- printk("after failing, found %Lu %Lu %Lu\n",
- em->start, em->len, em->block_start);
ret = 0;
} else {
em = lookup_extent_mapping(em_tree, failed_start,
failed_len);
- if (em) {
- printk("double failure lookup gives us "
- "%Lu %Lu -> %Lu\n", em->start,
- em->len, em->block_start);
- free_extent_map(em);
- }
ret = -EIO;
}
} else if (ret) {
unsigned long inline_result;
len = buf->len - offset;
- while(len > 0) {
+ while (len > 0) {
err = map_private_extent_buffer(buf, offset, 32,
&map_token, &kaddr,
&map_start, &map_len, KM_USER0);
- if (err) {
- printk("failed to map extent buffer! %lu\n",
- offset);
+ if (err)
return 1;
- }
cur_len = min(len, map_len - (offset - map_start));
crc = btrfs_csum_data(root, kaddr + offset - map_start,
crc, cur_len);
btrfs_csum_final(crc, result);
if (verify) {
- /* FIXME, this is not good */
if (memcmp_extent_buffer(buf, result, 0, csum_size)) {
u32 val;
u32 found = 0;
memcpy(&found, result, csum_size);
read_extent_buffer(buf, &val, 0, csum_size);
- printk("btrfs: %s checksum verify failed on %llu "
- "wanted %X found %X level %d\n",
+ printk(KERN_INFO "btrfs: %s checksum verify failed "
+ "on %llu wanted %X found %X level %d\n",
root->fs_info->sb->s_id,
buf->start, val, found, btrfs_header_level(buf));
if (result != (char *)&inline_result)
if (!ret &&
!verify_parent_transid(io_tree, eb, parent_transid))
return ret;
-printk("read extent buffer pages failed with ret %d mirror no %d\n", ret, mirror_num);
+
num_copies = btrfs_num_copies(&root->fs_info->mapping_tree,
eb->start, eb->len);
if (num_copies == 1)
}
/*
- * checksum a dirty tree block before IO. This has extra checks to make
- * sure we only fill in the checksum field in the first page of a multi-page block
+ * checksum a dirty tree block before IO. This has extra checks to make sure
+ * we only fill in the checksum field in the first page of a multi-page block
*/
+
static int csum_dirty_buffer(struct btrfs_root *root, struct page *page)
{
struct extent_io_tree *tree;
if (!page->private)
goto out;
len = page->private >> 2;
- if (len == 0) {
- WARN_ON(1);
- }
+ WARN_ON(len == 0);
+
eb = alloc_extent_buffer(tree, start, len, page, GFP_NOFS);
ret = btree_read_extent_buffer_pages(root, eb, start + PAGE_CACHE_SIZE,
btrfs_header_generation(eb));
BUG_ON(ret);
found_start = btrfs_header_bytenr(eb);
if (found_start != start) {
- printk("warning: eb start incorrect %Lu buffer %Lu len %lu\n",
- start, found_start, len);
WARN_ON(1);
goto err;
}
if (eb->first_page != page) {
- printk("bad first page %lu %lu\n", eb->first_page->index,
- page->index);
WARN_ON(1);
goto err;
}
if (!PageUptodate(page)) {
- printk("csum not up to date page %lu\n", page->index);
WARN_ON(1);
goto err;
}
goto out;
if (!page->private)
goto out;
+
len = page->private >> 2;
- if (len == 0) {
- WARN_ON(1);
- }
+ WARN_ON(len == 0);
+
eb = alloc_extent_buffer(tree, start, len, page, GFP_NOFS);
found_start = btrfs_header_bytenr(eb);
if (found_start != start) {
- printk("bad tree block start %llu %llu\n",
+ printk(KERN_INFO "btrfs bad tree block start %llu %llu\n",
(unsigned long long)found_start,
(unsigned long long)eb->start);
ret = -EIO;
goto err;
}
if (eb->first_page != page) {
- printk("bad first page %lu %lu\n", eb->first_page->index,
- page->index);
+ printk(KERN_INFO "btrfs bad first page %lu %lu\n",
+ eb->first_page->index, page->index);
WARN_ON(1);
ret = -EIO;
goto err;
}
if (check_tree_block_fsid(root, eb)) {
- printk("bad fsid on block %Lu\n", eb->start);
+ printk(KERN_INFO "btrfs bad fsid on block %llu\n",
+ (unsigned long long)eb->start);
ret = -EIO;
goto err;
}
HZ/10);
}
#endif
- while(atomic_read(&fs_info->async_submit_draining) &&
+ while (atomic_read(&fs_info->async_submit_draining) &&
atomic_read(&fs_info->nr_async_submits)) {
wait_event(fs_info->async_submit_wait,
(atomic_read(&fs_info->nr_async_submits) == 0));
struct btrfs_root *root;
WARN_ON(bio->bi_vcnt <= 0);
- while(bio_index < bio->bi_vcnt) {
+ while (bio_index < bio->bi_vcnt) {
root = BTRFS_I(bvec->bv_page->mapping->host)->root;
csum_dirty_buffer(root, bvec->bv_page);
bio_index++;
num_dirty = count_range_bits(tree, &start, (u64)-1,
thresh, EXTENT_DIRTY);
- if (num_dirty < thresh) {
+ if (num_dirty < thresh)
return 0;
- }
}
return extent_writepages(tree, mapping, btree_get_extent, wbc);
}
int ret;
if (PageWriteback(page) || PageDirty(page))
- return 0;
+ return 0;
tree = &BTRFS_I(page->mapping->host)->io_tree;
map = &BTRFS_I(page->mapping->host)->extent_tree;
ret = try_release_extent_state(map, tree, page, gfp_flags);
- if (!ret) {
+ if (!ret)
return 0;
- }
ret = try_release_extent_buffer(tree, page);
if (ret == 1) {
extent_invalidatepage(tree, page, offset);
btree_releasepage(page, GFP_NOFS);
if (PagePrivate(page)) {
- printk("warning page private not zero on page %Lu\n",
- page_offset(page));
+ printk(KERN_WARNING "btrfs warning page private not zero "
+ "on page %llu\n", (unsigned long long)page_offset(page));
ClearPagePrivate(page);
set_page_private(page, 0);
page_cache_release(page);
int btrfs_wait_tree_block_writeback(struct extent_buffer *buf)
{
return btrfs_wait_on_page_writeback_range(buf->first_page->mapping,
- buf->start, buf->start + buf->len -1);
+ buf->start, buf->start + buf->len - 1);
}
struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,
ret = btree_read_extent_buffer_pages(root, buf, 0, parent_transid);
- if (ret == 0) {
+ if (ret == 0)
buf->flags |= EXTENT_UPTODATE;
- } else {
+ else
WARN_ON(1);
- }
return buf;
}
if (!log_root_tree)
return 0;
- while(1) {
+ while (1) {
ret = find_first_extent_bit(&log_root_tree->dirty_log_pages,
0, &start, &end, EXTENT_DIRTY);
if (ret)
root->in_sysfs = 1;
return root;
}
-#if 0
-static int add_hasher(struct btrfs_fs_info *info, char *type) {
- struct btrfs_hasher *hasher;
-
- hasher = kmalloc(sizeof(*hasher), GFP_NOFS);
- if (!hasher)
- return -ENOMEM;
- hasher->hash_tfm = crypto_alloc_hash(type, 0, CRYPTO_ALG_ASYNC);
- if (!hasher->hash_tfm) {
- kfree(hasher);
- return -EINVAL;
- }
- spin_lock(&info->hash_lock);
- list_add(&hasher->list, &info->hashers);
- spin_unlock(&info->hash_lock);
- return 0;
-}
-#endif
static int btrfs_congested_fn(void *congested_data, int bdi_bits)
{
continue;
bdi = blk_get_backing_dev_info(device->bdev);
- if (bdi->unplug_io_fn) {
+ if (bdi->unplug_io_fn)
bdi->unplug_io_fn(bdi, page);
- }
}
}
mutex_lock(&root->fs_info->transaction_kthread_mutex);
if (root->fs_info->total_ref_cache_size > 20 * 1024 * 1024) {
- printk("btrfs: total reference cache size %Lu\n",
- root->fs_info->total_ref_cache_size);
+ printk(KERN_INFO "btrfs: total reference cache "
+ "size %llu\n",
+ root->fs_info->total_ref_cache_size);
}
mutex_lock(&root->fs_info->trans_mutex);
fs_info->btree_inode->i_ino = 1;
fs_info->btree_inode->i_nlink = 1;
- fs_info->thread_pool_size = min(num_online_cpus() + 2, 8);
+ fs_info->thread_pool_size = min_t(unsigned long,
+ num_online_cpus() + 2, 8);
INIT_LIST_HEAD(&fs_info->ordered_extents);
spin_lock_init(&fs_info->ordered_extent_lock);
atomic_set(&fs_info->tree_log_writers, 0);
fs_info->tree_log_transid = 0;
-#if 0
- ret = add_hasher(fs_info, "crc32c");
- if (ret) {
- printk("btrfs: failed hash setup, modprobe cryptomgr?\n");
- err = -ENOMEM;
- goto fail_iput;
- }
-#endif
__setup_root(4096, 4096, 4096, 4096, tree_root,
fs_info, BTRFS_ROOT_TREE_OBJECTID);
goto fail_iput;
memcpy(&fs_info->super_copy, bh->b_data, sizeof(fs_info->super_copy));
+ memcpy(&fs_info->super_for_commit, &fs_info->super_copy,
+ sizeof(fs_info->super_for_commit));
brelse(bh);
memcpy(fs_info->fsid, fs_info->super_copy.fsid, BTRFS_FSID_SIZE);
if (strncmp((char *)(&disk_super->magic), BTRFS_MAGIC,
sizeof(disk_super->magic))) {
- printk("btrfs: valid FS not found on %s\n", sb->s_id);
+ printk(KERN_INFO "btrfs: valid FS not found on %s\n", sb->s_id);
goto fail_sb_buffer;
}
ret = btrfs_read_sys_array(tree_root);
mutex_unlock(&fs_info->chunk_mutex);
if (ret) {
- printk("btrfs: failed to read the system array on %s\n",
- sb->s_id);
+ printk(KERN_WARNING "btrfs: failed to read the system "
+ "array on %s\n", sb->s_id);
goto fail_sys_array;
}
BUG_ON(!chunk_root->node);
read_extent_buffer(chunk_root->node, fs_info->chunk_tree_uuid,
- (unsigned long)btrfs_header_chunk_tree_uuid(chunk_root->node),
- BTRFS_UUID_SIZE);
+ (unsigned long)btrfs_header_chunk_tree_uuid(chunk_root->node),
+ BTRFS_UUID_SIZE);
mutex_lock(&fs_info->chunk_mutex);
ret = btrfs_read_chunk_tree(chunk_root);
mutex_unlock(&fs_info->chunk_mutex);
if (ret) {
- printk("btrfs: failed to read chunk tree on %s\n", sb->s_id);
+ printk(KERN_WARNING "btrfs: failed to read chunk tree on %s\n",
+ sb->s_id);
goto fail_chunk_root;
}
btrfs_read_block_groups(extent_root);
- fs_info->generation = generation + 1;
+ fs_info->generation = generation;
fs_info->last_trans_committed = generation;
fs_info->data_alloc_profile = (u64)-1;
fs_info->metadata_alloc_profile = (u64)-1;
u64 bytenr = btrfs_super_log_root(disk_super);
if (fs_devices->rw_devices == 0) {
- printk("Btrfs log replay required on RO media\n");
+ printk(KERN_WARNING "Btrfs log replay required "
+ "on RO media\n");
err = -EIO;
goto fail_trans_kthread;
}
total_errors++;
}
if (total_errors > max_errors) {
- printk("btrfs: %d errors while writing supers\n", total_errors);
+ printk(KERN_ERR "btrfs: %d errors while writing supers\n",
+ total_errors);
BUG();
}
total_errors++;
}
if (total_errors > max_errors) {
- printk("btrfs: %d errors while writing supers\n", total_errors);
+ printk(KERN_ERR "btrfs: %d errors while writing supers\n",
+ total_errors);
BUG();
}
return 0;
down_write(&root->anon_super.s_umount);
kill_anon_super(&root->anon_super);
}
-#if 0
- if (root->in_sysfs)
- btrfs_sysfs_del_root(root);
-#endif
if (root->node)
free_extent_buffer(root->node);
if (root->commit_root)
free_extent_buffer(root->commit_root);
- if (root->name)
- kfree(root->name);
+ kfree(root->name);
kfree(root);
return 0;
}
struct btrfs_root *gang[8];
int i;
- while(1) {
+ while (1) {
ret = radix_tree_gang_lookup(&fs_info->fs_roots_radix,
(void **)gang, 0,
ARRAY_SIZE(gang));
if (!(fs_info->sb->s_flags & MS_RDONLY)) {
ret = btrfs_commit_super(root);
- if (ret) {
- printk("btrfs: commit super returns %d\n", ret);
- }
+ if (ret)
+ printk(KERN_ERR "btrfs: commit super ret %d\n", ret);
}
if (fs_info->delalloc_bytes) {
- printk("btrfs: at unmount delalloc count %Lu\n",
+ printk(KERN_INFO "btrfs: at unmount delalloc count %llu\n",
fs_info->delalloc_bytes);
}
if (fs_info->total_ref_cache_size) {
- printk("btrfs: at umount reference cache size %Lu\n",
- fs_info->total_ref_cache_size);
+ printk(KERN_INFO "btrfs: at umount reference cache size %llu\n",
+ (unsigned long long)fs_info->total_ref_cache_size);
}
if (fs_info->extent_root->node)
if (fs_info->tree_root->node)
free_extent_buffer(fs_info->tree_root->node);
- if (root->fs_info->chunk_root->node);
+ if (root->fs_info->chunk_root->node)
free_extent_buffer(root->fs_info->chunk_root->node);
- if (root->fs_info->dev_root->node);
+ if (root->fs_info->dev_root->node)
free_extent_buffer(root->fs_info->dev_root->node);
- if (root->fs_info->csum_root->node);
+ if (root->fs_info->csum_root->node)
free_extent_buffer(root->fs_info->csum_root->node);
btrfs_free_block_groups(root->fs_info);
btrfs_stop_workers(&fs_info->submit_workers);
#if 0
- while(!list_empty(&fs_info->hashers)) {
+ while (!list_empty(&fs_info->hashers)) {
struct btrfs_hasher *hasher;
hasher = list_entry(fs_info->hashers.next, struct btrfs_hasher,
hashers);
WARN_ON(!btrfs_tree_locked(buf));
if (transid != root->fs_info->generation) {
- printk(KERN_CRIT "transid mismatch buffer %llu, found %Lu running %Lu\n",
+ printk(KERN_CRIT "btrfs transid mismatch buffer %llu, "
+ "found %llu running %llu\n",
(unsigned long long)buf->start,
- transid, root->fs_info->generation);
+ (unsigned long long)transid,
+ (unsigned long long)root->fs_info->generation);
WARN_ON(1);
}
set_extent_buffer_dirty(&BTRFS_I(btree_inode)->io_tree, buf);
struct btrfs_root *root = BTRFS_I(buf->first_page->mapping->host)->root;
int ret;
ret = btree_read_extent_buffer_pages(root, buf, 0, parent_transid);
- if (ret == 0) {
+ if (ret == 0)
buf->flags |= EXTENT_UPTODATE;
- }
return ret;
}