Btrfs: simplify iteration codes

Merge list_for_each* and list_entry to list_for_each_entry*

Signed-off-by: Qinghuang Feng <qhfeng.kernel@gmail.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
This commit is contained in:
Qinghuang Feng 2009-01-21 10:59:08 -05:00 committed by Chris Mason
parent 57506d50ed
commit c6e308713a
6 changed files with 19 additions and 52 deletions

View file

@ -1135,7 +1135,6 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits)
{ {
struct btrfs_fs_info *info = (struct btrfs_fs_info *)congested_data; struct btrfs_fs_info *info = (struct btrfs_fs_info *)congested_data;
int ret = 0; int ret = 0;
struct list_head *cur;
struct btrfs_device *device; struct btrfs_device *device;
struct backing_dev_info *bdi; struct backing_dev_info *bdi;
#if 0 #if 0
@ -1143,8 +1142,7 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits)
btrfs_congested_async(info, 0)) btrfs_congested_async(info, 0))
return 1; return 1;
#endif #endif
list_for_each(cur, &info->fs_devices->devices) { list_for_each_entry(device, &info->fs_devices->devices, dev_list) {
device = list_entry(cur, struct btrfs_device, dev_list);
if (!device->bdev) if (!device->bdev)
continue; continue;
bdi = blk_get_backing_dev_info(device->bdev); bdi = blk_get_backing_dev_info(device->bdev);
@ -1162,13 +1160,11 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits)
*/ */
static void __unplug_io_fn(struct backing_dev_info *bdi, struct page *page) static void __unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
{ {
struct list_head *cur;
struct btrfs_device *device; struct btrfs_device *device;
struct btrfs_fs_info *info; struct btrfs_fs_info *info;
info = (struct btrfs_fs_info *)bdi->unplug_io_data; info = (struct btrfs_fs_info *)bdi->unplug_io_data;
list_for_each(cur, &info->fs_devices->devices) { list_for_each_entry(device, &info->fs_devices->devices, dev_list) {
device = list_entry(cur, struct btrfs_device, dev_list);
if (!device->bdev) if (!device->bdev)
continue; continue;
@ -1994,7 +1990,6 @@ static int write_dev_supers(struct btrfs_device *device,
int write_all_supers(struct btrfs_root *root, int max_mirrors) int write_all_supers(struct btrfs_root *root, int max_mirrors)
{ {
struct list_head *cur;
struct list_head *head = &root->fs_info->fs_devices->devices; struct list_head *head = &root->fs_info->fs_devices->devices;
struct btrfs_device *dev; struct btrfs_device *dev;
struct btrfs_super_block *sb; struct btrfs_super_block *sb;
@ -2010,8 +2005,7 @@ int write_all_supers(struct btrfs_root *root, int max_mirrors)
sb = &root->fs_info->super_for_commit; sb = &root->fs_info->super_for_commit;
dev_item = &sb->dev_item; dev_item = &sb->dev_item;
list_for_each(cur, head) { list_for_each_entry(dev, head, dev_list) {
dev = list_entry(cur, struct btrfs_device, dev_list);
if (!dev->bdev) { if (!dev->bdev) {
total_errors++; total_errors++;
continue; continue;
@ -2044,8 +2038,7 @@ int write_all_supers(struct btrfs_root *root, int max_mirrors)
} }
total_errors = 0; total_errors = 0;
list_for_each(cur, head) { list_for_each_entry(dev, head, dev_list) {
dev = list_entry(cur, struct btrfs_device, dev_list);
if (!dev->bdev) if (!dev->bdev)
continue; continue;
if (!dev->in_fs_metadata || !dev->writeable) if (!dev->in_fs_metadata || !dev->writeable)

View file

@ -325,10 +325,8 @@ static struct btrfs_space_info *__find_space_info(struct btrfs_fs_info *info,
u64 flags) u64 flags)
{ {
struct list_head *head = &info->space_info; struct list_head *head = &info->space_info;
struct list_head *cur;
struct btrfs_space_info *found; struct btrfs_space_info *found;
list_for_each(cur, head) { list_for_each_entry(found, head, list) {
found = list_entry(cur, struct btrfs_space_info, list);
if (found->flags == flags) if (found->flags == flags)
return found; return found;
} }
@ -3013,7 +3011,6 @@ loop_check:
static void dump_space_info(struct btrfs_space_info *info, u64 bytes) static void dump_space_info(struct btrfs_space_info *info, u64 bytes)
{ {
struct btrfs_block_group_cache *cache; struct btrfs_block_group_cache *cache;
struct list_head *l;
printk(KERN_INFO "space_info has %llu free, is %sfull\n", printk(KERN_INFO "space_info has %llu free, is %sfull\n",
(unsigned long long)(info->total_bytes - info->bytes_used - (unsigned long long)(info->total_bytes - info->bytes_used -
@ -3021,8 +3018,7 @@ static void dump_space_info(struct btrfs_space_info *info, u64 bytes)
(info->full) ? "" : "not "); (info->full) ? "" : "not ");
down_read(&info->groups_sem); down_read(&info->groups_sem);
list_for_each(l, &info->block_groups) { list_for_each_entry(cache, &info->block_groups, list) {
cache = list_entry(l, struct btrfs_block_group_cache, list);
spin_lock(&cache->lock); spin_lock(&cache->lock);
printk(KERN_INFO "block group %llu has %llu bytes, %llu used " printk(KERN_INFO "block group %llu has %llu bytes, %llu used "
"%llu pinned %llu reserved\n", "%llu pinned %llu reserved\n",

View file

@ -1323,12 +1323,11 @@ static noinline int add_pending_csums(struct btrfs_trans_handle *trans,
struct inode *inode, u64 file_offset, struct inode *inode, u64 file_offset,
struct list_head *list) struct list_head *list)
{ {
struct list_head *cur;
struct btrfs_ordered_sum *sum; struct btrfs_ordered_sum *sum;
btrfs_set_trans_block_group(trans, inode); btrfs_set_trans_block_group(trans, inode);
list_for_each(cur, list) {
sum = list_entry(cur, struct btrfs_ordered_sum, list); list_for_each_entry(sum, list, list) {
btrfs_csum_file_blocks(trans, btrfs_csum_file_blocks(trans,
BTRFS_I(inode)->root->fs_info->csum_root, sum); BTRFS_I(inode)->root->fs_info->csum_root, sum);
} }

View file

@ -613,7 +613,6 @@ int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr,
struct btrfs_sector_sum *sector_sums; struct btrfs_sector_sum *sector_sums;
struct btrfs_ordered_extent *ordered; struct btrfs_ordered_extent *ordered;
struct btrfs_ordered_inode_tree *tree = &BTRFS_I(inode)->ordered_tree; struct btrfs_ordered_inode_tree *tree = &BTRFS_I(inode)->ordered_tree;
struct list_head *cur;
unsigned long num_sectors; unsigned long num_sectors;
unsigned long i; unsigned long i;
u32 sectorsize = BTRFS_I(inode)->root->sectorsize; u32 sectorsize = BTRFS_I(inode)->root->sectorsize;
@ -624,8 +623,7 @@ int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr,
return 1; return 1;
mutex_lock(&tree->mutex); mutex_lock(&tree->mutex);
list_for_each_prev(cur, &ordered->list) { list_for_each_entry_reverse(ordered_sum, &ordered->list, list) {
ordered_sum = list_entry(cur, struct btrfs_ordered_sum, list);
if (disk_bytenr >= ordered_sum->bytenr) { if (disk_bytenr >= ordered_sum->bytenr) {
num_sectors = ordered_sum->len / sectorsize; num_sectors = ordered_sum->len / sectorsize;
sector_sums = ordered_sum->sums; sector_sums = ordered_sum->sums;

View file

@ -852,11 +852,9 @@ static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans,
{ {
struct btrfs_pending_snapshot *pending; struct btrfs_pending_snapshot *pending;
struct list_head *head = &trans->transaction->pending_snapshots; struct list_head *head = &trans->transaction->pending_snapshots;
struct list_head *cur;
int ret; int ret;
list_for_each(cur, head) { list_for_each_entry(pending, head, list) {
pending = list_entry(cur, struct btrfs_pending_snapshot, list);
ret = create_pending_snapshot(trans, fs_info, pending); ret = create_pending_snapshot(trans, fs_info, pending);
BUG_ON(ret); BUG_ON(ret);
} }

View file

@ -103,10 +103,8 @@ static noinline struct btrfs_device *__find_device(struct list_head *head,
u64 devid, u8 *uuid) u64 devid, u8 *uuid)
{ {
struct btrfs_device *dev; struct btrfs_device *dev;
struct list_head *cur;
list_for_each(cur, head) { list_for_each_entry(dev, head, dev_list) {
dev = list_entry(cur, struct btrfs_device, dev_list);
if (dev->devid == devid && if (dev->devid == devid &&
(!uuid || !memcmp(dev->uuid, uuid, BTRFS_UUID_SIZE))) { (!uuid || !memcmp(dev->uuid, uuid, BTRFS_UUID_SIZE))) {
return dev; return dev;
@ -117,11 +115,9 @@ static noinline struct btrfs_device *__find_device(struct list_head *head,
static noinline struct btrfs_fs_devices *find_fsid(u8 *fsid) static noinline struct btrfs_fs_devices *find_fsid(u8 *fsid)
{ {
struct list_head *cur;
struct btrfs_fs_devices *fs_devices; struct btrfs_fs_devices *fs_devices;
list_for_each(cur, &fs_uuids) { list_for_each_entry(fs_devices, &fs_uuids, list) {
fs_devices = list_entry(cur, struct btrfs_fs_devices, list);
if (memcmp(fsid, fs_devices->fsid, BTRFS_FSID_SIZE) == 0) if (memcmp(fsid, fs_devices->fsid, BTRFS_FSID_SIZE) == 0)
return fs_devices; return fs_devices;
} }
@ -344,14 +340,11 @@ error:
int btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices) int btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices)
{ {
struct list_head *tmp; struct btrfs_device *device, *next;
struct list_head *cur;
struct btrfs_device *device;
mutex_lock(&uuid_mutex); mutex_lock(&uuid_mutex);
again: again:
list_for_each_safe(cur, tmp, &fs_devices->devices) { list_for_each_entry_safe(device, next, &fs_devices->devices, dev_list) {
device = list_entry(cur, struct btrfs_device, dev_list);
if (device->in_fs_metadata) if (device->in_fs_metadata)
continue; continue;
@ -382,14 +375,12 @@ again:
static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices) static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
{ {
struct list_head *cur;
struct btrfs_device *device; struct btrfs_device *device;
if (--fs_devices->opened > 0) if (--fs_devices->opened > 0)
return 0; return 0;
list_for_each(cur, &fs_devices->devices) { list_for_each_entry(device, &fs_devices->devices, dev_list) {
device = list_entry(cur, struct btrfs_device, dev_list);
if (device->bdev) { if (device->bdev) {
close_bdev_exclusive(device->bdev, device->mode); close_bdev_exclusive(device->bdev, device->mode);
fs_devices->open_devices--; fs_devices->open_devices--;
@ -438,7 +429,6 @@ static int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
{ {
struct block_device *bdev; struct block_device *bdev;
struct list_head *head = &fs_devices->devices; struct list_head *head = &fs_devices->devices;
struct list_head *cur;
struct btrfs_device *device; struct btrfs_device *device;
struct block_device *latest_bdev = NULL; struct block_device *latest_bdev = NULL;
struct buffer_head *bh; struct buffer_head *bh;
@ -449,8 +439,7 @@ static int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
int seeding = 1; int seeding = 1;
int ret = 0; int ret = 0;
list_for_each(cur, head) { list_for_each_entry(device, head, dev_list) {
device = list_entry(cur, struct btrfs_device, dev_list);
if (device->bdev) if (device->bdev)
continue; continue;
if (!device->name) if (!device->name)
@ -1016,14 +1005,12 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
} }
if (strcmp(device_path, "missing") == 0) { if (strcmp(device_path, "missing") == 0) {
struct list_head *cur;
struct list_head *devices; struct list_head *devices;
struct btrfs_device *tmp; struct btrfs_device *tmp;
device = NULL; device = NULL;
devices = &root->fs_info->fs_devices->devices; devices = &root->fs_info->fs_devices->devices;
list_for_each(cur, devices) { list_for_each_entry(tmp, devices, dev_list) {
tmp = list_entry(cur, struct btrfs_device, dev_list);
if (tmp->in_fs_metadata && !tmp->bdev) { if (tmp->in_fs_metadata && !tmp->bdev) {
device = tmp; device = tmp;
break; break;
@ -1279,7 +1266,6 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
struct btrfs_device *device; struct btrfs_device *device;
struct block_device *bdev; struct block_device *bdev;
struct list_head *cur;
struct list_head *devices; struct list_head *devices;
struct super_block *sb = root->fs_info->sb; struct super_block *sb = root->fs_info->sb;
u64 total_bytes; u64 total_bytes;
@ -1303,8 +1289,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
mutex_lock(&root->fs_info->volume_mutex); mutex_lock(&root->fs_info->volume_mutex);
devices = &root->fs_info->fs_devices->devices; devices = &root->fs_info->fs_devices->devices;
list_for_each(cur, devices) { list_for_each_entry(device, devices, dev_list) {
device = list_entry(cur, struct btrfs_device, dev_list);
if (device->bdev == bdev) { if (device->bdev == bdev) {
ret = -EEXIST; ret = -EEXIST;
goto error; goto error;
@ -1703,7 +1688,6 @@ static u64 div_factor(u64 num, int factor)
int btrfs_balance(struct btrfs_root *dev_root) int btrfs_balance(struct btrfs_root *dev_root)
{ {
int ret; int ret;
struct list_head *cur;
struct list_head *devices = &dev_root->fs_info->fs_devices->devices; struct list_head *devices = &dev_root->fs_info->fs_devices->devices;
struct btrfs_device *device; struct btrfs_device *device;
u64 old_size; u64 old_size;
@ -1722,8 +1706,7 @@ int btrfs_balance(struct btrfs_root *dev_root)
dev_root = dev_root->fs_info->dev_root; dev_root = dev_root->fs_info->dev_root;
/* step one make some room on all the devices */ /* step one make some room on all the devices */
list_for_each(cur, devices) { list_for_each_entry(device, devices, dev_list) {
device = list_entry(cur, struct btrfs_device, dev_list);
old_size = device->total_bytes; old_size = device->total_bytes;
size_to_free = div_factor(old_size, 1); size_to_free = div_factor(old_size, 1);
size_to_free = min(size_to_free, (u64)1 * 1024 * 1024); size_to_free = min(size_to_free, (u64)1 * 1024 * 1024);