aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorQinghuang Feng <qhfeng.kernel@gmail.com>2009-01-21 10:59:08 -0500
committerChris Mason <chris.mason@oracle.com>2009-01-21 10:59:08 -0500
commitc6e308713a47527f88a277ee95b7c5d1db80f77b (patch)
tree0a890bb3ac2ae1bb8733cf8679d1441e1b85eb81 /fs/btrfs
parent57506d50ed6db7b0e7ddc9845e86e81f140983d5 (diff)
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>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/disk-io.c15
-rw-r--r--fs/btrfs/extent-tree.c8
-rw-r--r--fs/btrfs/inode.c5
-rw-r--r--fs/btrfs/ordered-data.c4
-rw-r--r--fs/btrfs/transaction.c4
-rw-r--r--fs/btrfs/volumes.c35
6 files changed, 19 insertions, 52 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 0d8ccd625ba2..26a18779e84b 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1135,7 +1135,6 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits)
1135{ 1135{
1136 struct btrfs_fs_info *info = (struct btrfs_fs_info *)congested_data; 1136 struct btrfs_fs_info *info = (struct btrfs_fs_info *)congested_data;
1137 int ret = 0; 1137 int ret = 0;
1138 struct list_head *cur;
1139 struct btrfs_device *device; 1138 struct btrfs_device *device;
1140 struct backing_dev_info *bdi; 1139 struct backing_dev_info *bdi;
1141#if 0 1140#if 0
@@ -1143,8 +1142,7 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits)
1143 btrfs_congested_async(info, 0)) 1142 btrfs_congested_async(info, 0))
1144 return 1; 1143 return 1;
1145#endif 1144#endif
1146 list_for_each(cur, &info->fs_devices->devices) { 1145 list_for_each_entry(device, &info->fs_devices->devices, dev_list) {
1147 device = list_entry(cur, struct btrfs_device, dev_list);
1148 if (!device->bdev) 1146 if (!device->bdev)
1149 continue; 1147 continue;
1150 bdi = blk_get_backing_dev_info(device->bdev); 1148 bdi = blk_get_backing_dev_info(device->bdev);
@@ -1162,13 +1160,11 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits)
1162 */ 1160 */
1163static void __unplug_io_fn(struct backing_dev_info *bdi, struct page *page) 1161static void __unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
1164{ 1162{
1165 struct list_head *cur;
1166 struct btrfs_device *device; 1163 struct btrfs_device *device;
1167 struct btrfs_fs_info *info; 1164 struct btrfs_fs_info *info;
1168 1165
1169 info = (struct btrfs_fs_info *)bdi->unplug_io_data; 1166 info = (struct btrfs_fs_info *)bdi->unplug_io_data;
1170 list_for_each(cur, &info->fs_devices->devices) { 1167 list_for_each_entry(device, &info->fs_devices->devices, dev_list) {
1171 device = list_entry(cur, struct btrfs_device, dev_list);
1172 if (!device->bdev) 1168 if (!device->bdev)
1173 continue; 1169 continue;
1174 1170
@@ -1994,7 +1990,6 @@ static int write_dev_supers(struct btrfs_device *device,
1994 1990
1995int write_all_supers(struct btrfs_root *root, int max_mirrors) 1991int write_all_supers(struct btrfs_root *root, int max_mirrors)
1996{ 1992{
1997 struct list_head *cur;
1998 struct list_head *head = &root->fs_info->fs_devices->devices; 1993 struct list_head *head = &root->fs_info->fs_devices->devices;
1999 struct btrfs_device *dev; 1994 struct btrfs_device *dev;
2000 struct btrfs_super_block *sb; 1995 struct btrfs_super_block *sb;
@@ -2010,8 +2005,7 @@ int write_all_supers(struct btrfs_root *root, int max_mirrors)
2010 2005
2011 sb = &root->fs_info->super_for_commit; 2006 sb = &root->fs_info->super_for_commit;
2012 dev_item = &sb->dev_item; 2007 dev_item = &sb->dev_item;
2013 list_for_each(cur, head) { 2008 list_for_each_entry(dev, head, dev_list) {
2014 dev = list_entry(cur, struct btrfs_device, dev_list);
2015 if (!dev->bdev) { 2009 if (!dev->bdev) {
2016 total_errors++; 2010 total_errors++;
2017 continue; 2011 continue;
@@ -2044,8 +2038,7 @@ int write_all_supers(struct btrfs_root *root, int max_mirrors)
2044 } 2038 }
2045 2039
2046 total_errors = 0; 2040 total_errors = 0;
2047 list_for_each(cur, head) { 2041 list_for_each_entry(dev, head, dev_list) {
2048 dev = list_entry(cur, struct btrfs_device, dev_list);
2049 if (!dev->bdev) 2042 if (!dev->bdev)
2050 continue; 2043 continue;
2051 if (!dev->in_fs_metadata || !dev->writeable) 2044 if (!dev->in_fs_metadata || !dev->writeable)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index cdc961e7556a..a4e36c38b81e 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -325,10 +325,8 @@ static struct btrfs_space_info *__find_space_info(struct btrfs_fs_info *info,
325 u64 flags) 325 u64 flags)
326{ 326{
327 struct list_head *head = &info->space_info; 327 struct list_head *head = &info->space_info;
328 struct list_head *cur;
329 struct btrfs_space_info *found; 328 struct btrfs_space_info *found;
330 list_for_each(cur, head) { 329 list_for_each_entry(found, head, list) {
331 found = list_entry(cur, struct btrfs_space_info, list);
332 if (found->flags == flags) 330 if (found->flags == flags)
333 return found; 331 return found;
334 } 332 }
@@ -3013,7 +3011,6 @@ loop_check:
3013static void dump_space_info(struct btrfs_space_info *info, u64 bytes) 3011static void dump_space_info(struct btrfs_space_info *info, u64 bytes)
3014{ 3012{
3015 struct btrfs_block_group_cache *cache; 3013 struct btrfs_block_group_cache *cache;
3016 struct list_head *l;
3017 3014
3018 printk(KERN_INFO "space_info has %llu free, is %sfull\n", 3015 printk(KERN_INFO "space_info has %llu free, is %sfull\n",
3019 (unsigned long long)(info->total_bytes - info->bytes_used - 3016 (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)
3021 (info->full) ? "" : "not "); 3018 (info->full) ? "" : "not ");
3022 3019
3023 down_read(&info->groups_sem); 3020 down_read(&info->groups_sem);
3024 list_for_each(l, &info->block_groups) { 3021 list_for_each_entry(cache, &info->block_groups, list) {
3025 cache = list_entry(l, struct btrfs_block_group_cache, list);
3026 spin_lock(&cache->lock); 3022 spin_lock(&cache->lock);
3027 printk(KERN_INFO "block group %llu has %llu bytes, %llu used " 3023 printk(KERN_INFO "block group %llu has %llu bytes, %llu used "
3028 "%llu pinned %llu reserved\n", 3024 "%llu pinned %llu reserved\n",
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 44dbd550c4bd..45cf03ee1bc2 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1323,12 +1323,11 @@ static noinline int add_pending_csums(struct btrfs_trans_handle *trans,
1323 struct inode *inode, u64 file_offset, 1323 struct inode *inode, u64 file_offset,
1324 struct list_head *list) 1324 struct list_head *list)
1325{ 1325{
1326 struct list_head *cur;
1327 struct btrfs_ordered_sum *sum; 1326 struct btrfs_ordered_sum *sum;
1328 1327
1329 btrfs_set_trans_block_group(trans, inode); 1328 btrfs_set_trans_block_group(trans, inode);
1330 list_for_each(cur, list) { 1329
1331 sum = list_entry(cur, struct btrfs_ordered_sum, list); 1330 list_for_each_entry(sum, list, list) {
1332 btrfs_csum_file_blocks(trans, 1331 btrfs_csum_file_blocks(trans,
1333 BTRFS_I(inode)->root->fs_info->csum_root, sum); 1332 BTRFS_I(inode)->root->fs_info->csum_root, sum);
1334 } 1333 }
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index a20940170274..77c2411a5f0f 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -613,7 +613,6 @@ int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr,
613 struct btrfs_sector_sum *sector_sums; 613 struct btrfs_sector_sum *sector_sums;
614 struct btrfs_ordered_extent *ordered; 614 struct btrfs_ordered_extent *ordered;
615 struct btrfs_ordered_inode_tree *tree = &BTRFS_I(inode)->ordered_tree; 615 struct btrfs_ordered_inode_tree *tree = &BTRFS_I(inode)->ordered_tree;
616 struct list_head *cur;
617 unsigned long num_sectors; 616 unsigned long num_sectors;
618 unsigned long i; 617 unsigned long i;
619 u32 sectorsize = BTRFS_I(inode)->root->sectorsize; 618 u32 sectorsize = BTRFS_I(inode)->root->sectorsize;
@@ -624,8 +623,7 @@ int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr,
624 return 1; 623 return 1;
625 624
626 mutex_lock(&tree->mutex); 625 mutex_lock(&tree->mutex);
627 list_for_each_prev(cur, &ordered->list) { 626 list_for_each_entry_reverse(ordered_sum, &ordered->list, list) {
628 ordered_sum = list_entry(cur, struct btrfs_ordered_sum, list);
629 if (disk_bytenr >= ordered_sum->bytenr) { 627 if (disk_bytenr >= ordered_sum->bytenr) {
630 num_sectors = ordered_sum->len / sectorsize; 628 num_sectors = ordered_sum->len / sectorsize;
631 sector_sums = ordered_sum->sums; 629 sector_sums = ordered_sum->sums;
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 8a08f9443340..919172de5c9a 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -852,11 +852,9 @@ static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans,
852{ 852{
853 struct btrfs_pending_snapshot *pending; 853 struct btrfs_pending_snapshot *pending;
854 struct list_head *head = &trans->transaction->pending_snapshots; 854 struct list_head *head = &trans->transaction->pending_snapshots;
855 struct list_head *cur;
856 int ret; 855 int ret;
857 856
858 list_for_each(cur, head) { 857 list_for_each_entry(pending, head, list) {
859 pending = list_entry(cur, struct btrfs_pending_snapshot, list);
860 ret = create_pending_snapshot(trans, fs_info, pending); 858 ret = create_pending_snapshot(trans, fs_info, pending);
861 BUG_ON(ret); 859 BUG_ON(ret);
862 } 860 }
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 397c8db1bc27..fd0bedb07a64 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -103,10 +103,8 @@ static noinline struct btrfs_device *__find_device(struct list_head *head,
103 u64 devid, u8 *uuid) 103 u64 devid, u8 *uuid)
104{ 104{
105 struct btrfs_device *dev; 105 struct btrfs_device *dev;
106 struct list_head *cur;
107 106
108 list_for_each(cur, head) { 107 list_for_each_entry(dev, head, dev_list) {
109 dev = list_entry(cur, struct btrfs_device, dev_list);
110 if (dev->devid == devid && 108 if (dev->devid == devid &&
111 (!uuid || !memcmp(dev->uuid, uuid, BTRFS_UUID_SIZE))) { 109 (!uuid || !memcmp(dev->uuid, uuid, BTRFS_UUID_SIZE))) {
112 return dev; 110 return dev;
@@ -117,11 +115,9 @@ static noinline struct btrfs_device *__find_device(struct list_head *head,
117 115
118static noinline struct btrfs_fs_devices *find_fsid(u8 *fsid) 116static noinline struct btrfs_fs_devices *find_fsid(u8 *fsid)
119{ 117{
120 struct list_head *cur;
121 struct btrfs_fs_devices *fs_devices; 118 struct btrfs_fs_devices *fs_devices;
122 119
123 list_for_each(cur, &fs_uuids) { 120 list_for_each_entry(fs_devices, &fs_uuids, list) {
124 fs_devices = list_entry(cur, struct btrfs_fs_devices, list);
125 if (memcmp(fsid, fs_devices->fsid, BTRFS_FSID_SIZE) == 0) 121 if (memcmp(fsid, fs_devices->fsid, BTRFS_FSID_SIZE) == 0)
126 return fs_devices; 122 return fs_devices;
127 } 123 }
@@ -344,14 +340,11 @@ error:
344 340
345int btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices) 341int btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices)
346{ 342{
347 struct list_head *tmp; 343 struct btrfs_device *device, *next;
348 struct list_head *cur;
349 struct btrfs_device *device;
350 344
351 mutex_lock(&uuid_mutex); 345 mutex_lock(&uuid_mutex);
352again: 346again:
353 list_for_each_safe(cur, tmp, &fs_devices->devices) { 347 list_for_each_entry_safe(device, next, &fs_devices->devices, dev_list) {
354 device = list_entry(cur, struct btrfs_device, dev_list);
355 if (device->in_fs_metadata) 348 if (device->in_fs_metadata)
356 continue; 349 continue;
357 350
@@ -382,14 +375,12 @@ again:
382 375
383static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices) 376static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
384{ 377{
385 struct list_head *cur;
386 struct btrfs_device *device; 378 struct btrfs_device *device;
387 379
388 if (--fs_devices->opened > 0) 380 if (--fs_devices->opened > 0)
389 return 0; 381 return 0;
390 382
391 list_for_each(cur, &fs_devices->devices) { 383 list_for_each_entry(device, &fs_devices->devices, dev_list) {
392 device = list_entry(cur, struct btrfs_device, dev_list);
393 if (device->bdev) { 384 if (device->bdev) {
394 close_bdev_exclusive(device->bdev, device->mode); 385 close_bdev_exclusive(device->bdev, device->mode);
395 fs_devices->open_devices--; 386 fs_devices->open_devices--;
@@ -438,7 +429,6 @@ static int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
438{ 429{
439 struct block_device *bdev; 430 struct block_device *bdev;
440 struct list_head *head = &fs_devices->devices; 431 struct list_head *head = &fs_devices->devices;
441 struct list_head *cur;
442 struct btrfs_device *device; 432 struct btrfs_device *device;
443 struct block_device *latest_bdev = NULL; 433 struct block_device *latest_bdev = NULL;
444 struct buffer_head *bh; 434 struct buffer_head *bh;
@@ -449,8 +439,7 @@ static int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
449 int seeding = 1; 439 int seeding = 1;
450 int ret = 0; 440 int ret = 0;
451 441
452 list_for_each(cur, head) { 442 list_for_each_entry(device, head, dev_list) {
453 device = list_entry(cur, struct btrfs_device, dev_list);
454 if (device->bdev) 443 if (device->bdev)
455 continue; 444 continue;
456 if (!device->name) 445 if (!device->name)
@@ -1016,14 +1005,12 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
1016 } 1005 }
1017 1006
1018 if (strcmp(device_path, "missing") == 0) { 1007 if (strcmp(device_path, "missing") == 0) {
1019 struct list_head *cur;
1020 struct list_head *devices; 1008 struct list_head *devices;
1021 struct btrfs_device *tmp; 1009 struct btrfs_device *tmp;
1022 1010
1023 device = NULL; 1011 device = NULL;
1024 devices = &root->fs_info->fs_devices->devices; 1012 devices = &root->fs_info->fs_devices->devices;
1025 list_for_each(cur, devices) { 1013 list_for_each_entry(tmp, devices, dev_list) {
1026 tmp = list_entry(cur, struct btrfs_device, dev_list);
1027 if (tmp->in_fs_metadata && !tmp->bdev) { 1014 if (tmp->in_fs_metadata && !tmp->bdev) {
1028 device = tmp; 1015 device = tmp;
1029 break; 1016 break;
@@ -1279,7 +1266,6 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
1279 struct btrfs_trans_handle *trans; 1266 struct btrfs_trans_handle *trans;
1280 struct btrfs_device *device; 1267 struct btrfs_device *device;
1281 struct block_device *bdev; 1268 struct block_device *bdev;
1282 struct list_head *cur;
1283 struct list_head *devices; 1269 struct list_head *devices;
1284 struct super_block *sb = root->fs_info->sb; 1270 struct super_block *sb = root->fs_info->sb;
1285 u64 total_bytes; 1271 u64 total_bytes;
@@ -1303,8 +1289,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
1303 mutex_lock(&root->fs_info->volume_mutex); 1289 mutex_lock(&root->fs_info->volume_mutex);
1304 1290
1305 devices = &root->fs_info->fs_devices->devices; 1291 devices = &root->fs_info->fs_devices->devices;
1306 list_for_each(cur, devices) { 1292 list_for_each_entry(device, devices, dev_list) {
1307 device = list_entry(cur, struct btrfs_device, dev_list);
1308 if (device->bdev == bdev) { 1293 if (device->bdev == bdev) {
1309 ret = -EEXIST; 1294 ret = -EEXIST;
1310 goto error; 1295 goto error;
@@ -1703,7 +1688,6 @@ static u64 div_factor(u64 num, int factor)
1703int btrfs_balance(struct btrfs_root *dev_root) 1688int btrfs_balance(struct btrfs_root *dev_root)
1704{ 1689{
1705 int ret; 1690 int ret;
1706 struct list_head *cur;
1707 struct list_head *devices = &dev_root->fs_info->fs_devices->devices; 1691 struct list_head *devices = &dev_root->fs_info->fs_devices->devices;
1708 struct btrfs_device *device; 1692 struct btrfs_device *device;
1709 u64 old_size; 1693 u64 old_size;
@@ -1722,8 +1706,7 @@ int btrfs_balance(struct btrfs_root *dev_root)
1722 dev_root = dev_root->fs_info->dev_root; 1706 dev_root = dev_root->fs_info->dev_root;
1723 1707
1724 /* step one make some room on all the devices */ 1708 /* step one make some room on all the devices */
1725 list_for_each(cur, devices) { 1709 list_for_each_entry(device, devices, dev_list) {
1726 device = list_entry(cur, struct btrfs_device, dev_list);
1727 old_size = device->total_bytes; 1710 old_size = device->total_bytes;
1728 size_to_free = div_factor(old_size, 1); 1711 size_to_free = div_factor(old_size, 1);
1729 size_to_free = min(size_to_free, (u64)1 * 1024 * 1024); 1712 size_to_free = min(size_to_free, (u64)1 * 1024 * 1024);