Commit 15916de8 authored by Chris Mason's avatar Chris Mason

Btrfs: Fixes for 2.6.28-rc API changes

* open/close_bdev_excl -> open/close_bdev_exclusive
* blkdev_issue_discard takes a GFP mask now
* Fix blkdev_issue_discard usage now that it is enabled
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent ae20a6af
...@@ -21,4 +21,11 @@ static inline struct dentry *d_obtain_alias(struct inode *inode) ...@@ -21,4 +21,11 @@ static inline struct dentry *d_obtain_alias(struct inode *inode)
} }
#endif #endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
# define __pagevec_lru_add_file __pagevec_lru_add
# define open_bdev_exclusive open_bdev_excl
# define close_bdev_exclusive(bdev, mode) close_bdev_excl(bdev)
#endif
#endif /* _COMPAT_H_ */ #endif /* _COMPAT_H_ */
...@@ -419,7 +419,7 @@ static noinline int add_ra_bio_pages(struct inode *inode, ...@@ -419,7 +419,7 @@ static noinline int add_ra_bio_pages(struct inode *inode,
/* open coding of lru_cache_add, also not exported */ /* open coding of lru_cache_add, also not exported */
page_cache_get(page); page_cache_get(page);
if (!pagevec_add(&pvec, page)) if (!pagevec_add(&pvec, page))
__pagevec_lru_add(&pvec); __pagevec_lru_add_file(&pvec);
end = last_offset + PAGE_CACHE_SIZE - 1; end = last_offset + PAGE_CACHE_SIZE - 1;
/* /*
...@@ -475,7 +475,7 @@ static noinline int add_ra_bio_pages(struct inode *inode, ...@@ -475,7 +475,7 @@ static noinline int add_ra_bio_pages(struct inode *inode,
last_offset += PAGE_CACHE_SIZE; last_offset += PAGE_CACHE_SIZE;
} }
if (pagevec_count(&pvec)) if (pagevec_count(&pvec))
__pagevec_lru_add(&pvec); __pagevec_lru_add_file(&pvec);
return 0; return 0;
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "volumes.h" #include "volumes.h"
#include "locking.h" #include "locking.h"
#include "ref-cache.h" #include "ref-cache.h"
#include "compat.h"
#define PENDING_EXTENT_INSERT 0 #define PENDING_EXTENT_INSERT 0
#define PENDING_EXTENT_DELETE 1 #define PENDING_EXTENT_DELETE 1
...@@ -899,6 +900,17 @@ static int noinline remove_extent_backref(struct btrfs_trans_handle *trans, ...@@ -899,6 +900,17 @@ static int noinline remove_extent_backref(struct btrfs_trans_handle *trans,
return ret; return ret;
} }
static void btrfs_issue_discard(struct block_device *bdev,
u64 start, u64 len)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
blkdev_issue_discard(bdev, start >> 9, len >> 9, GFP_KERNEL);
#else
blkdev_issue_discard(bdev, start >> 9, len >> 9);
#endif
}
static int noinline free_extents(struct btrfs_trans_handle *trans, static int noinline free_extents(struct btrfs_trans_handle *trans,
struct btrfs_root *extent_root, struct btrfs_root *extent_root,
struct list_head *del_list) struct list_head *del_list)
...@@ -1108,6 +1120,7 @@ static int noinline free_extents(struct btrfs_trans_handle *trans, ...@@ -1108,6 +1120,7 @@ static int noinline free_extents(struct btrfs_trans_handle *trans,
BUG_ON(ret); BUG_ON(ret);
#ifdef BIO_RW_DISCARD #ifdef BIO_RW_DISCARD
map_length = tmp->num_bytes;
ret = btrfs_map_block(&info->mapping_tree, READ, ret = btrfs_map_block(&info->mapping_tree, READ,
tmp->bytenr, &map_length, &multi, tmp->bytenr, &map_length, &multi,
0); 0);
...@@ -1115,16 +1128,16 @@ static int noinline free_extents(struct btrfs_trans_handle *trans, ...@@ -1115,16 +1128,16 @@ static int noinline free_extents(struct btrfs_trans_handle *trans,
struct btrfs_bio_stripe *stripe; struct btrfs_bio_stripe *stripe;
int i; int i;
stripe = multi->stripe; stripe = multi->stripes;
if (map_length > tmp->num_bytes) if (map_length > tmp->num_bytes)
map_length = tmp->num_bytes; map_length = tmp->num_bytes;
for (i = 0; i < multi->num_stripes; for (i = 0; i < multi->num_stripes;
i++, stripe++) i++, stripe++)
blkdev_issue_discard(stripe->dev->bdev, btrfs_issue_discard(stripe->dev->bdev,
stripe->physical >> 9, stripe->physical,
map_length >> 9); map_length);
kfree(multi); kfree(multi);
} }
#endif #endif
...@@ -2498,9 +2511,9 @@ static int __free_extent(struct btrfs_trans_handle *trans, ...@@ -2498,9 +2511,9 @@ static int __free_extent(struct btrfs_trans_handle *trans,
map_length = num_bytes; map_length = num_bytes;
for (i = 0; i < multi->num_stripes; i++, stripe++) { for (i = 0; i < multi->num_stripes; i++, stripe++) {
blkdev_issue_discard(stripe->dev->bdev, btrfs_issue_discard(stripe->dev->bdev,
stripe->physical >> 9, stripe->physical,
map_length >> 9); map_length);
} }
kfree(multi); kfree(multi);
} }
......
...@@ -2639,14 +2639,14 @@ int extent_readpages(struct extent_io_tree *tree, ...@@ -2639,14 +2639,14 @@ int extent_readpages(struct extent_io_tree *tree,
/* open coding of lru_cache_add, also not exported */ /* open coding of lru_cache_add, also not exported */
page_cache_get(page); page_cache_get(page);
if (!pagevec_add(&pvec, page)) if (!pagevec_add(&pvec, page))
__pagevec_lru_add(&pvec); __pagevec_lru_add_file(&pvec);
__extent_read_full_page(tree, page, get_extent, __extent_read_full_page(tree, page, get_extent,
&bio, 0, &bio_flags); &bio, 0, &bio_flags);
} }
page_cache_release(page); page_cache_release(page);
} }
if (pagevec_count(&pvec)) if (pagevec_count(&pvec))
__pagevec_lru_add(&pvec); __pagevec_lru_add_file(&pvec);
BUG_ON(!list_empty(pages)); BUG_ON(!list_empty(pages));
if (bio) if (bio)
submit_one_bio(READ, bio, 0, bio_flags); submit_one_bio(READ, bio, 0, bio_flags);
......
...@@ -8,24 +8,24 @@ ...@@ -8,24 +8,24 @@
v="v0.16" v="v0.16"
which hg > /dev/null which git &> /dev/null
if [ -d .hg ] && [ $? == 0 ]; then if [ $? == 0 ]; then
last=$(hg tags | grep -m1 -o '^v[0-9.]\+') git branch >& /dev/null
if [ $? == 0 ]; then
# now check if the repo has commits since then... if head=`git rev-parse --verify HEAD 2>/dev/null`; then
if [[ $(hg id -t) == $last || \ if tag=`git describe --tags 2>/dev/null`; then
$(hg di -r "$last:." | awk '/^diff/{print $NF}' | sort -u) == .hgtags ]] v="$tag"
then fi
# check if it's dirty
if [[ $(hg id | cut -d' ' -f1) == *+ ]]; then # Are there uncommitted changes?
v=$last+ git update-index --refresh --unmerged > /dev/null
else if git diff-index --name-only HEAD | \
v=$last grep -v "^scripts/package" \
| read dummy; then
v="$v"-dirty
fi
fi fi
else fi
# includes dirty flag
v=$last+$(hg id -i)
fi
fi fi
echo "#ifndef __BUILD_VERSION" > .build-version.h echo "#ifndef __BUILD_VERSION" > .build-version.h
......
...@@ -85,7 +85,7 @@ int btrfs_cleanup_fs_uuids(void) ...@@ -85,7 +85,7 @@ int btrfs_cleanup_fs_uuids(void)
dev = list_entry(fs_devices->devices.next, dev = list_entry(fs_devices->devices.next,
struct btrfs_device, dev_list); struct btrfs_device, dev_list);
if (dev->bdev) { if (dev->bdev) {
close_bdev_excl(dev->bdev); close_bdev_exclusive(dev->bdev, dev->mode);
fs_devices->open_devices--; fs_devices->open_devices--;
} }
fs_devices->num_devices--; fs_devices->num_devices--;
...@@ -317,7 +317,7 @@ int btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices) ...@@ -317,7 +317,7 @@ int btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices)
continue; continue;
if (device->bdev) { if (device->bdev) {
close_bdev_excl(device->bdev); close_bdev_exclusive(device->bdev, device->mode);
device->bdev = NULL; device->bdev = NULL;
fs_devices->open_devices--; fs_devices->open_devices--;
} }
...@@ -356,7 +356,7 @@ static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices) ...@@ -356,7 +356,7 @@ static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
list_for_each(cur, &fs_devices->devices) { list_for_each(cur, &fs_devices->devices) {
device = list_entry(cur, struct btrfs_device, dev_list); device = list_entry(cur, struct btrfs_device, dev_list);
if (device->bdev) { if (device->bdev) {
close_bdev_excl(device->bdev); close_bdev_exclusive(device->bdev, device->mode);
fs_devices->open_devices--; fs_devices->open_devices--;
} }
if (device->writeable) { if (device->writeable) {
...@@ -391,7 +391,8 @@ int btrfs_close_devices(struct btrfs_fs_devices *fs_devices) ...@@ -391,7 +391,8 @@ int btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
return ret; return ret;
} }
int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices, void *holder) int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
int flags, void *holder)
{ {
struct block_device *bdev; struct block_device *bdev;
struct list_head *head = &fs_devices->devices; struct list_head *head = &fs_devices->devices;
...@@ -413,7 +414,7 @@ int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices, void *holder) ...@@ -413,7 +414,7 @@ int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices, void *holder)
if (!device->name) if (!device->name)
continue; continue;
bdev = open_bdev_excl(device->name, MS_RDONLY, holder); bdev = open_bdev_exclusive(device->name, flags, holder);
if (IS_ERR(bdev)) { if (IS_ERR(bdev)) {
printk("open %s failed\n", device->name); printk("open %s failed\n", device->name);
goto error; goto error;
...@@ -453,6 +454,8 @@ int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices, void *holder) ...@@ -453,6 +454,8 @@ int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices, void *holder)
device->bdev = bdev; device->bdev = bdev;
device->in_fs_metadata = 0; device->in_fs_metadata = 0;
device->mode = flags;
fs_devices->open_devices++; fs_devices->open_devices++;
if (device->writeable) { if (device->writeable) {
fs_devices->rw_devices++; fs_devices->rw_devices++;
...@@ -464,7 +467,7 @@ int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices, void *holder) ...@@ -464,7 +467,7 @@ int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices, void *holder)
error_brelse: error_brelse:
brelse(bh); brelse(bh);
error_close: error_close:
close_bdev_excl(bdev); close_bdev_exclusive(bdev, MS_RDONLY);
error: error:
continue; continue;
} }
...@@ -496,7 +499,7 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, ...@@ -496,7 +499,7 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
ret = 0; ret = 0;
} }
} else { } else {
ret = __btrfs_open_devices(fs_devices, holder); ret = __btrfs_open_devices(fs_devices, flags, holder);
} }
mutex_unlock(&uuid_mutex); mutex_unlock(&uuid_mutex);
return ret; return ret;
...@@ -514,7 +517,7 @@ int btrfs_scan_one_device(const char *path, int flags, void *holder, ...@@ -514,7 +517,7 @@ int btrfs_scan_one_device(const char *path, int flags, void *holder,
mutex_lock(&uuid_mutex); mutex_lock(&uuid_mutex);
bdev = open_bdev_excl(path, flags, holder); bdev = open_bdev_exclusive(path, flags, holder);
if (IS_ERR(bdev)) { if (IS_ERR(bdev)) {
ret = PTR_ERR(bdev); ret = PTR_ERR(bdev);
...@@ -551,7 +554,7 @@ int btrfs_scan_one_device(const char *path, int flags, void *holder, ...@@ -551,7 +554,7 @@ int btrfs_scan_one_device(const char *path, int flags, void *holder,
error_brelse: error_brelse:
brelse(bh); brelse(bh);
error_close: error_close:
close_bdev_excl(bdev); close_bdev_exclusive(bdev, flags);
error: error:
mutex_unlock(&uuid_mutex); mutex_unlock(&uuid_mutex);
return ret; return ret;
...@@ -1003,7 +1006,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) ...@@ -1003,7 +1006,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
goto out; goto out;
} }
} else { } else {
bdev = open_bdev_excl(device_path, MS_RDONLY, bdev = open_bdev_exclusive(device_path, MS_RDONLY,
root->fs_info->bdev_holder); root->fs_info->bdev_holder);
if (IS_ERR(bdev)) { if (IS_ERR(bdev)) {
ret = PTR_ERR(bdev); ret = PTR_ERR(bdev);
...@@ -1073,10 +1076,10 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) ...@@ -1073,10 +1076,10 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
BUG_ON(device->writeable); BUG_ON(device->writeable);
brelse(bh); brelse(bh);
if (bdev) if (bdev)
close_bdev_excl(bdev); close_bdev_exclusive(bdev, MS_RDONLY);
if (device->bdev) { if (device->bdev) {
close_bdev_excl(device->bdev); close_bdev_exclusive(device->bdev, device->mode);
device->bdev = NULL; device->bdev = NULL;
device->fs_devices->open_devices--; device->fs_devices->open_devices--;
} }
...@@ -1112,11 +1115,11 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) ...@@ -1112,11 +1115,11 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
if (device->bdev) { if (device->bdev) {
/* one close for the device struct or super_block */ /* one close for the device struct or super_block */
close_bdev_excl(device->bdev); close_bdev_exclusive(device->bdev, device->mode);
} }
if (bdev) { if (bdev) {
/* one close for us */ /* one close for us */
close_bdev_excl(bdev); close_bdev_exclusive(bdev, MS_RDONLY);
} }
kfree(device->name); kfree(device->name);
kfree(device); kfree(device);
...@@ -1127,7 +1130,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) ...@@ -1127,7 +1130,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
brelse(bh); brelse(bh);
error_close: error_close:
if (bdev) if (bdev)
close_bdev_excl(bdev); close_bdev_exclusive(bdev, MS_RDONLY);
out: out:
mutex_unlock(&root->fs_info->volume_mutex); mutex_unlock(&root->fs_info->volume_mutex);
mutex_unlock(&uuid_mutex); mutex_unlock(&uuid_mutex);
...@@ -1272,7 +1275,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) ...@@ -1272,7 +1275,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
if ((sb->s_flags & MS_RDONLY) && !root->fs_info->fs_devices->seeding) if ((sb->s_flags & MS_RDONLY) && !root->fs_info->fs_devices->seeding)
return -EINVAL; return -EINVAL;
bdev = open_bdev_excl(device_path, 0, root->fs_info->bdev_holder); bdev = open_bdev_exclusive(device_path, 0, root->fs_info->bdev_holder);
if (!bdev) { if (!bdev) {
return -EIO; return -EIO;
} }
...@@ -1331,6 +1334,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) ...@@ -1331,6 +1334,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
device->dev_root = root->fs_info->dev_root; device->dev_root = root->fs_info->dev_root;
device->bdev = bdev; device->bdev = bdev;
device->in_fs_metadata = 1; device->in_fs_metadata = 1;
device->mode = 0;
set_blocksize(device->bdev, 4096); set_blocksize(device->bdev, 4096);
if (seeding_dev) { if (seeding_dev) {
...@@ -1379,7 +1383,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) ...@@ -1379,7 +1383,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
mutex_unlock(&root->fs_info->volume_mutex); mutex_unlock(&root->fs_info->volume_mutex);
return ret; return ret;
error: error:
close_bdev_excl(bdev); close_bdev_exclusive(bdev, 0);
if (seeding_dev) { if (seeding_dev) {
mutex_unlock(&uuid_mutex); mutex_unlock(&uuid_mutex);
up_write(&sb->s_umount); up_write(&sb->s_umount);
...@@ -2907,7 +2911,8 @@ static int open_seed_devices(struct btrfs_root *root, u8 *fsid) ...@@ -2907,7 +2911,8 @@ static int open_seed_devices(struct btrfs_root *root, u8 *fsid)
goto out; goto out;
} }
ret = __btrfs_open_devices(fs_devices, root->fs_info->bdev_holder); ret = __btrfs_open_devices(fs_devices, MS_RDONLY,
root->fs_info->bdev_holder);
if (ret) if (ret)
goto out; goto out;
......
...@@ -42,6 +42,9 @@ struct btrfs_device { ...@@ -42,6 +42,9 @@ struct btrfs_device {
struct block_device *bdev; struct block_device *bdev;
/* the mode sent to open_bdev_exclusive */
fmode_t mode;
char *name; char *name;
/* the internal btrfs device id */ /* the internal btrfs device id */
......
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