Commit b248a415 authored by Chris Mason's avatar Chris Mason

Btrfs: A few updates for 2.6.18 and versions older than 2.6.25

This includes fixing a missing spinlock init call that caused oops on mount
for most kernels other than 2.6.25.
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 98d20f67
...@@ -850,7 +850,9 @@ void btrfs_unplug_io_fn(struct backing_dev_info *bdi, struct page *page) ...@@ -850,7 +850,9 @@ void btrfs_unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi) static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi)
{ {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
bdi_init(bdi); bdi_init(bdi);
#endif
bdi->ra_pages = default_backing_dev_info.ra_pages * 4; bdi->ra_pages = default_backing_dev_info.ra_pages * 4;
bdi->state = 0; bdi->state = 0;
bdi->capabilities = default_backing_dev_info.capabilities; bdi->capabilities = default_backing_dev_info.capabilities;
...@@ -950,7 +952,7 @@ void btrfs_end_io_csum(struct work_struct *work) ...@@ -950,7 +952,7 @@ void btrfs_end_io_csum(struct work_struct *work)
bio->bi_end_io = end_io_wq->end_io; bio->bi_end_io = end_io_wq->end_io;
kfree(end_io_wq); kfree(end_io_wq);
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,23) #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,23)
bio_endio(bio, bio->bi_size, err); bio_endio(bio, bio->bi_size, error);
#else #else
bio_endio(bio, error); bio_endio(bio, error);
#endif #endif
...@@ -1037,10 +1039,11 @@ struct btrfs_root *open_ctree(struct super_block *sb, ...@@ -1037,10 +1039,11 @@ struct btrfs_root *open_ctree(struct super_block *sb,
fs_info->btree_inode->i_mapping, GFP_NOFS); fs_info->btree_inode->i_mapping, GFP_NOFS);
fs_info->do_barriers = 1; fs_info->do_barriers = 1;
INIT_WORK(&fs_info->end_io_work, btrfs_end_io_csum);
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18) #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
INIT_WORK(&fs_info->end_io_work, btrfs_end_io_csum, fs_info);
INIT_WORK(&fs_info->trans_work, btrfs_transaction_cleaner, fs_info); INIT_WORK(&fs_info->trans_work, btrfs_transaction_cleaner, fs_info);
#else #else
INIT_WORK(&fs_info->end_io_work, btrfs_end_io_csum);
INIT_DELAYED_WORK(&fs_info->trans_work, btrfs_transaction_cleaner); INIT_DELAYED_WORK(&fs_info->trans_work, btrfs_transaction_cleaner);
#endif #endif
BTRFS_I(fs_info->btree_inode)->root = tree_root; BTRFS_I(fs_info->btree_inode)->root = tree_root;
...@@ -1173,7 +1176,9 @@ struct btrfs_root *open_ctree(struct super_block *sb, ...@@ -1173,7 +1176,9 @@ struct btrfs_root *open_ctree(struct super_block *sb,
close_all_devices(fs_info); close_all_devices(fs_info);
kfree(extent_root); kfree(extent_root);
kfree(tree_root); kfree(tree_root);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
bdi_destroy(&fs_info->bdi); bdi_destroy(&fs_info->bdi);
#endif
kfree(fs_info); kfree(fs_info);
return ERR_PTR(err); return ERR_PTR(err);
} }
...@@ -1407,7 +1412,10 @@ int close_ctree(struct btrfs_root *root) ...@@ -1407,7 +1412,10 @@ int close_ctree(struct btrfs_root *root)
#endif #endif
close_all_devices(fs_info); close_all_devices(fs_info);
btrfs_mapping_tree_free(&fs_info->mapping_tree); btrfs_mapping_tree_free(&fs_info->mapping_tree);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
bdi_destroy(&fs_info->bdi); bdi_destroy(&fs_info->bdi);
#endif
kfree(fs_info->extent_root); kfree(fs_info->extent_root);
kfree(fs_info->tree_root); kfree(fs_info->tree_root);
......
...@@ -908,11 +908,17 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf, ...@@ -908,11 +908,17 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf,
if (err < 0) if (err < 0)
num_written = err; num_written = err;
} else if (num_written > 0 && (file->f_flags & O_DIRECT)) { } else if (num_written > 0 && (file->f_flags & O_DIRECT)) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
do_sync_file_range(file, start_pos,
start_pos + num_written - 1,
SYNC_FILE_RANGE_WRITE |
SYNC_FILE_RANGE_WAIT_AFTER);
#else
do_sync_mapping_range(inode->i_mapping, start_pos, do_sync_mapping_range(inode->i_mapping, start_pos,
start_pos + num_written - 1, start_pos + num_written - 1,
SYNC_FILE_RANGE_WRITE | SYNC_FILE_RANGE_WRITE |
SYNC_FILE_RANGE_WAIT_AFTER); SYNC_FILE_RANGE_WAIT_AFTER);
#endif
invalidate_mapping_pages(inode->i_mapping, invalidate_mapping_pages(inode->i_mapping,
start_pos >> PAGE_CACHE_SHIFT, start_pos >> PAGE_CACHE_SHIFT,
(start_pos + num_written - 1) >> PAGE_CACHE_SHIFT); (start_pos + num_written - 1) >> PAGE_CACHE_SHIFT);
......
...@@ -126,6 +126,7 @@ static int device_list_add(const char *path, ...@@ -126,6 +126,7 @@ static int device_list_add(const char *path,
} }
device->devid = devid; device->devid = devid;
device->barriers = 1; device->barriers = 1;
spin_lock_init(&device->io_lock);
device->name = kstrdup(path, GFP_NOFS); device->name = kstrdup(path, GFP_NOFS);
if (!device->name) { if (!device->name) {
kfree(device); kfree(device);
...@@ -759,8 +760,8 @@ printk("alloc chunk start %Lu size %Lu from dev %Lu type %Lu\n", key.objectid, c ...@@ -759,8 +760,8 @@ printk("alloc chunk start %Lu size %Lu from dev %Lu type %Lu\n", key.objectid, c
em_tree = &extent_root->fs_info->mapping_tree.map_tree; em_tree = &extent_root->fs_info->mapping_tree.map_tree;
spin_lock(&em_tree->lock); spin_lock(&em_tree->lock);
ret = add_extent_mapping(em_tree, em); ret = add_extent_mapping(em_tree, em);
BUG_ON(ret);
spin_unlock(&em_tree->lock); spin_unlock(&em_tree->lock);
BUG_ON(ret);
free_extent_map(em); free_extent_map(em);
return ret; return ret;
} }
...@@ -799,6 +800,7 @@ int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len) ...@@ -799,6 +800,7 @@ int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len)
spin_lock(&em_tree->lock); spin_lock(&em_tree->lock);
em = lookup_extent_mapping(em_tree, logical, len); em = lookup_extent_mapping(em_tree, logical, len);
spin_unlock(&em_tree->lock);
BUG_ON(!em); BUG_ON(!em);
BUG_ON(em->start > logical || em->start + em->len < logical); BUG_ON(em->start > logical || em->start + em->len < logical);
...@@ -808,7 +810,6 @@ int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len) ...@@ -808,7 +810,6 @@ int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len)
else else
ret = 1; ret = 1;
free_extent_map(em); free_extent_map(em);
spin_unlock(&em_tree->lock);
return ret; return ret;
} }
...@@ -840,6 +841,7 @@ int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, ...@@ -840,6 +841,7 @@ int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
spin_lock(&em_tree->lock); spin_lock(&em_tree->lock);
em = lookup_extent_mapping(em_tree, logical, *length); em = lookup_extent_mapping(em_tree, logical, *length);
spin_unlock(&em_tree->lock);
BUG_ON(!em); BUG_ON(!em);
BUG_ON(em->start > logical || em->start + em->len < logical); BUG_ON(em->start > logical || em->start + em->len < logical);
...@@ -855,7 +857,6 @@ int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, ...@@ -855,7 +857,6 @@ int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
((map->type & BTRFS_BLOCK_GROUP_RAID1) || ((map->type & BTRFS_BLOCK_GROUP_RAID1) ||
(map->type & BTRFS_BLOCK_GROUP_DUP))) { (map->type & BTRFS_BLOCK_GROUP_DUP))) {
stripes_allocated = map->num_stripes; stripes_allocated = map->num_stripes;
spin_unlock(&em_tree->lock);
free_extent_map(em); free_extent_map(em);
kfree(multi); kfree(multi);
goto again; goto again;
...@@ -932,7 +933,6 @@ int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, ...@@ -932,7 +933,6 @@ int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
*multi_ret = multi; *multi_ret = multi;
out: out:
free_extent_map(em); free_extent_map(em);
spin_unlock(&em_tree->lock);
return 0; return 0;
} }
...@@ -1060,16 +1060,15 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key, ...@@ -1060,16 +1060,15 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
length = key->offset; length = key->offset;
spin_lock(&map_tree->map_tree.lock); spin_lock(&map_tree->map_tree.lock);
em = lookup_extent_mapping(&map_tree->map_tree, logical, 1); em = lookup_extent_mapping(&map_tree->map_tree, logical, 1);
spin_unlock(&map_tree->map_tree.lock);
/* already mapped? */ /* already mapped? */
if (em && em->start <= logical && em->start + em->len > logical) { if (em && em->start <= logical && em->start + em->len > logical) {
free_extent_map(em); free_extent_map(em);
spin_unlock(&map_tree->map_tree.lock);
return 0; return 0;
} else if (em) { } else if (em) {
free_extent_map(em); free_extent_map(em);
} }
spin_unlock(&map_tree->map_tree.lock);
map = kzalloc(sizeof(*map), GFP_NOFS); map = kzalloc(sizeof(*map), GFP_NOFS);
if (!map) if (!map)
...@@ -1110,8 +1109,8 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key, ...@@ -1110,8 +1109,8 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
spin_lock(&map_tree->map_tree.lock); spin_lock(&map_tree->map_tree.lock);
ret = add_extent_mapping(&map_tree->map_tree, em); ret = add_extent_mapping(&map_tree->map_tree, em);
BUG_ON(ret);
spin_unlock(&map_tree->map_tree.lock); spin_unlock(&map_tree->map_tree.lock);
BUG_ON(ret);
free_extent_map(em); free_extent_map(em);
return 0; return 0;
...@@ -1154,7 +1153,7 @@ static int read_one_dev(struct btrfs_root *root, ...@@ -1154,7 +1153,7 @@ static int read_one_dev(struct btrfs_root *root,
return -ENOMEM; return -ENOMEM;
list_add(&device->dev_list, list_add(&device->dev_list,
&root->fs_info->fs_devices->devices); &root->fs_info->fs_devices->devices);
device->total_ios = 0; device->barriers = 1;
spin_lock_init(&device->io_lock); spin_lock_init(&device->io_lock);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment