diff options
author | Qinghuang Feng <qhfeng.kernel@gmail.com> | 2009-01-21 10:59:08 -0500 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2009-01-21 10:59:08 -0500 |
commit | c6e308713a47527f88a277ee95b7c5d1db80f77b (patch) | |
tree | 0a890bb3ac2ae1bb8733cf8679d1441e1b85eb81 /fs/btrfs/volumes.c | |
parent | 57506d50ed6db7b0e7ddc9845e86e81f140983d5 (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/volumes.c')
-rw-r--r-- | fs/btrfs/volumes.c | 35 |
1 files changed, 9 insertions, 26 deletions
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 | ||
118 | static noinline struct btrfs_fs_devices *find_fsid(u8 *fsid) | 116 | static 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 | ||
345 | int btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices) | 341 | int 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); |
352 | again: | 346 | again: |
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 | ||
383 | static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices) | 376 | static 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) | |||
1703 | int btrfs_balance(struct btrfs_root *dev_root) | 1688 | int 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); |