Commit 159ec1fc authored by Cheng Renquan's avatar Cheng Renquan Committed by NeilBrown

md: use list_for_each_entry macro directly

The rdev_for_each macro defined in <linux/raid/md_k.h> is identical to
list_for_each_entry_safe, from <linux/list.h>, it should be defined to
use list_for_each_entry_safe, instead of reinventing the wheel.

But some calls to each_entry_safe don't really need a safe version,
just a direct list_for_each_entry is enough, this could save a temp
variable (tmp) in every function that used rdev_for_each.

In this patch, most rdev_for_each loops are replaced by list_for_each_entry,
totally save many tmp vars; and only in the other situations that will call
list_del to delete an entry, the safe version is used.
Signed-off-by: default avatarCheng Renquan <crquan@gmail.com>
Signed-off-by: default avatarNeilBrown <neilb@suse.de>
parent ccacc7d2
...@@ -215,7 +215,6 @@ static struct page *read_sb_page(mddev_t *mddev, long offset, ...@@ -215,7 +215,6 @@ static struct page *read_sb_page(mddev_t *mddev, long offset,
/* choose a good rdev and read the page from there */ /* choose a good rdev and read the page from there */
mdk_rdev_t *rdev; mdk_rdev_t *rdev;
struct list_head *tmp;
sector_t target; sector_t target;
if (!page) if (!page)
...@@ -223,7 +222,7 @@ static struct page *read_sb_page(mddev_t *mddev, long offset, ...@@ -223,7 +222,7 @@ static struct page *read_sb_page(mddev_t *mddev, long offset,
if (!page) if (!page)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
rdev_for_each(rdev, tmp, mddev) { list_for_each_entry(rdev, &mddev->disks, same_set) {
if (! test_bit(In_sync, &rdev->flags) if (! test_bit(In_sync, &rdev->flags)
|| test_bit(Faulty, &rdev->flags)) || test_bit(Faulty, &rdev->flags))
continue; continue;
......
...@@ -283,7 +283,6 @@ static int reconfig(mddev_t *mddev, int layout, int chunk_size) ...@@ -283,7 +283,6 @@ static int reconfig(mddev_t *mddev, int layout, int chunk_size)
static int run(mddev_t *mddev) static int run(mddev_t *mddev)
{ {
mdk_rdev_t *rdev; mdk_rdev_t *rdev;
struct list_head *tmp;
int i; int i;
conf_t *conf = kmalloc(sizeof(*conf), GFP_KERNEL); conf_t *conf = kmalloc(sizeof(*conf), GFP_KERNEL);
...@@ -296,7 +295,7 @@ static int run(mddev_t *mddev) ...@@ -296,7 +295,7 @@ static int run(mddev_t *mddev)
} }
conf->nfaults = 0; conf->nfaults = 0;
rdev_for_each(rdev, tmp, mddev) list_for_each_entry(rdev, &mddev->disks, same_set)
conf->rdev = rdev; conf->rdev = rdev;
mddev->array_sectors = mddev->size * 2; mddev->array_sectors = mddev->size * 2;
......
...@@ -105,7 +105,6 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks) ...@@ -105,7 +105,6 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
int i, nb_zone, cnt; int i, nb_zone, cnt;
sector_t min_sectors; sector_t min_sectors;
sector_t curr_sector; sector_t curr_sector;
struct list_head *tmp;
conf = kzalloc (sizeof (*conf) + raid_disks*sizeof(dev_info_t), conf = kzalloc (sizeof (*conf) + raid_disks*sizeof(dev_info_t),
GFP_KERNEL); GFP_KERNEL);
...@@ -115,7 +114,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks) ...@@ -115,7 +114,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
cnt = 0; cnt = 0;
conf->array_sectors = 0; conf->array_sectors = 0;
rdev_for_each(rdev, tmp, mddev) { list_for_each_entry(rdev, &mddev->disks, same_set) {
int j = rdev->raid_disk; int j = rdev->raid_disk;
dev_info_t *disk = conf->disks + j; dev_info_t *disk = conf->disks + j;
......
This diff is collapsed.
...@@ -408,7 +408,6 @@ static int multipath_run (mddev_t *mddev) ...@@ -408,7 +408,6 @@ static int multipath_run (mddev_t *mddev)
int disk_idx; int disk_idx;
struct multipath_info *disk; struct multipath_info *disk;
mdk_rdev_t *rdev; mdk_rdev_t *rdev;
struct list_head *tmp;
if (mddev->level != LEVEL_MULTIPATH) { if (mddev->level != LEVEL_MULTIPATH) {
printk("multipath: %s: raid level not set to multipath IO (%d)\n", printk("multipath: %s: raid level not set to multipath IO (%d)\n",
...@@ -441,7 +440,7 @@ static int multipath_run (mddev_t *mddev) ...@@ -441,7 +440,7 @@ static int multipath_run (mddev_t *mddev)
} }
conf->working_disks = 0; conf->working_disks = 0;
rdev_for_each(rdev, tmp, mddev) { list_for_each_entry(rdev, &mddev->disks, same_set) {
disk_idx = rdev->raid_disk; disk_idx = rdev->raid_disk;
if (disk_idx < 0 || if (disk_idx < 0 ||
disk_idx >= mddev->raid_disks) disk_idx >= mddev->raid_disks)
......
...@@ -57,7 +57,6 @@ static int create_strip_zones (mddev_t *mddev) ...@@ -57,7 +57,6 @@ static int create_strip_zones (mddev_t *mddev)
sector_t min_spacing; sector_t min_spacing;
raid0_conf_t *conf = mddev_to_conf(mddev); raid0_conf_t *conf = mddev_to_conf(mddev);
mdk_rdev_t *smallest, *rdev1, *rdev2, *rdev; mdk_rdev_t *smallest, *rdev1, *rdev2, *rdev;
struct list_head *tmp1, *tmp2;
struct strip_zone *zone; struct strip_zone *zone;
int cnt; int cnt;
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
...@@ -67,11 +66,11 @@ static int create_strip_zones (mddev_t *mddev) ...@@ -67,11 +66,11 @@ static int create_strip_zones (mddev_t *mddev)
*/ */
conf->nr_strip_zones = 0; conf->nr_strip_zones = 0;
rdev_for_each(rdev1, tmp1, mddev) { list_for_each_entry(rdev1, &mddev->disks, same_set) {
printk(KERN_INFO "raid0: looking at %s\n", printk(KERN_INFO "raid0: looking at %s\n",
bdevname(rdev1->bdev,b)); bdevname(rdev1->bdev,b));
c = 0; c = 0;
rdev_for_each(rdev2, tmp2, mddev) { list_for_each_entry(rdev2, &mddev->disks, same_set) {
printk(KERN_INFO "raid0: comparing %s(%llu)", printk(KERN_INFO "raid0: comparing %s(%llu)",
bdevname(rdev1->bdev,b), bdevname(rdev1->bdev,b),
(unsigned long long)rdev1->size); (unsigned long long)rdev1->size);
...@@ -120,7 +119,7 @@ static int create_strip_zones (mddev_t *mddev) ...@@ -120,7 +119,7 @@ static int create_strip_zones (mddev_t *mddev)
cnt = 0; cnt = 0;
smallest = NULL; smallest = NULL;
zone->dev = conf->devlist; zone->dev = conf->devlist;
rdev_for_each(rdev1, tmp1, mddev) { list_for_each_entry(rdev1, &mddev->disks, same_set) {
int j = rdev1->raid_disk; int j = rdev1->raid_disk;
if (j < 0 || j >= mddev->raid_disks) { if (j < 0 || j >= mddev->raid_disks) {
...@@ -268,7 +267,6 @@ static int raid0_run (mddev_t *mddev) ...@@ -268,7 +267,6 @@ static int raid0_run (mddev_t *mddev)
s64 sectors; s64 sectors;
raid0_conf_t *conf; raid0_conf_t *conf;
mdk_rdev_t *rdev; mdk_rdev_t *rdev;
struct list_head *tmp;
if (mddev->chunk_size == 0) { if (mddev->chunk_size == 0) {
printk(KERN_ERR "md/raid0: non-zero chunk size required.\n"); printk(KERN_ERR "md/raid0: non-zero chunk size required.\n");
...@@ -294,7 +292,7 @@ static int raid0_run (mddev_t *mddev) ...@@ -294,7 +292,7 @@ static int raid0_run (mddev_t *mddev)
/* calculate array device size */ /* calculate array device size */
mddev->array_sectors = 0; mddev->array_sectors = 0;
rdev_for_each(rdev, tmp, mddev) list_for_each_entry(rdev, &mddev->disks, same_set)
mddev->array_sectors += rdev->size * 2; mddev->array_sectors += rdev->size * 2;
printk(KERN_INFO "raid0 : md_size is %llu sectors.\n", printk(KERN_INFO "raid0 : md_size is %llu sectors.\n",
......
...@@ -1919,7 +1919,6 @@ static int run(mddev_t *mddev) ...@@ -1919,7 +1919,6 @@ static int run(mddev_t *mddev)
int i, j, disk_idx; int i, j, disk_idx;
mirror_info_t *disk; mirror_info_t *disk;
mdk_rdev_t *rdev; mdk_rdev_t *rdev;
struct list_head *tmp;
if (mddev->level != 1) { if (mddev->level != 1) {
printk("raid1: %s: raid level not set to mirroring (%d)\n", printk("raid1: %s: raid level not set to mirroring (%d)\n",
...@@ -1964,7 +1963,7 @@ static int run(mddev_t *mddev) ...@@ -1964,7 +1963,7 @@ static int run(mddev_t *mddev)
spin_lock_init(&conf->device_lock); spin_lock_init(&conf->device_lock);
mddev->queue->queue_lock = &conf->device_lock; mddev->queue->queue_lock = &conf->device_lock;
rdev_for_each(rdev, tmp, mddev) { list_for_each_entry(rdev, &mddev->disks, same_set) {
disk_idx = rdev->raid_disk; disk_idx = rdev->raid_disk;
if (disk_idx >= mddev->raid_disks if (disk_idx >= mddev->raid_disks
|| disk_idx < 0) || disk_idx < 0)
......
...@@ -2025,7 +2025,6 @@ static int run(mddev_t *mddev) ...@@ -2025,7 +2025,6 @@ static int run(mddev_t *mddev)
int i, disk_idx; int i, disk_idx;
mirror_info_t *disk; mirror_info_t *disk;
mdk_rdev_t *rdev; mdk_rdev_t *rdev;
struct list_head *tmp;
int nc, fc, fo; int nc, fc, fo;
sector_t stride, size; sector_t stride, size;
...@@ -2108,7 +2107,7 @@ static int run(mddev_t *mddev) ...@@ -2108,7 +2107,7 @@ static int run(mddev_t *mddev)
spin_lock_init(&conf->device_lock); spin_lock_init(&conf->device_lock);
mddev->queue->queue_lock = &conf->device_lock; mddev->queue->queue_lock = &conf->device_lock;
rdev_for_each(rdev, tmp, mddev) { list_for_each_entry(rdev, &mddev->disks, same_set) {
disk_idx = rdev->raid_disk; disk_idx = rdev->raid_disk;
if (disk_idx >= mddev->raid_disks if (disk_idx >= mddev->raid_disks
|| disk_idx < 0) || disk_idx < 0)
......
...@@ -3998,7 +3998,6 @@ static int run(mddev_t *mddev) ...@@ -3998,7 +3998,6 @@ static int run(mddev_t *mddev)
int raid_disk, memory; int raid_disk, memory;
mdk_rdev_t *rdev; mdk_rdev_t *rdev;
struct disk_info *disk; struct disk_info *disk;
struct list_head *tmp;
int working_disks = 0; int working_disks = 0;
if (mddev->level != 5 && mddev->level != 4 && mddev->level != 6) { if (mddev->level != 5 && mddev->level != 4 && mddev->level != 6) {
...@@ -4108,7 +4107,7 @@ static int run(mddev_t *mddev) ...@@ -4108,7 +4107,7 @@ static int run(mddev_t *mddev)
pr_debug("raid5: run(%s) called.\n", mdname(mddev)); pr_debug("raid5: run(%s) called.\n", mdname(mddev));
rdev_for_each(rdev, tmp, mddev) { list_for_each_entry(rdev, &mddev->disks, same_set) {
raid_disk = rdev->raid_disk; raid_disk = rdev->raid_disk;
if (raid_disk >= conf->raid_disks if (raid_disk >= conf->raid_disks
|| raid_disk < 0) || raid_disk < 0)
...@@ -4533,7 +4532,6 @@ static int raid5_start_reshape(mddev_t *mddev) ...@@ -4533,7 +4532,6 @@ static int raid5_start_reshape(mddev_t *mddev)
{ {
raid5_conf_t *conf = mddev_to_conf(mddev); raid5_conf_t *conf = mddev_to_conf(mddev);
mdk_rdev_t *rdev; mdk_rdev_t *rdev;
struct list_head *rtmp;
int spares = 0; int spares = 0;
int added_devices = 0; int added_devices = 0;
unsigned long flags; unsigned long flags;
...@@ -4541,7 +4539,7 @@ static int raid5_start_reshape(mddev_t *mddev) ...@@ -4541,7 +4539,7 @@ static int raid5_start_reshape(mddev_t *mddev)
if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
return -EBUSY; return -EBUSY;
rdev_for_each(rdev, rtmp, mddev) list_for_each_entry(rdev, &mddev->disks, same_set)
if (rdev->raid_disk < 0 && if (rdev->raid_disk < 0 &&
!test_bit(Faulty, &rdev->flags)) !test_bit(Faulty, &rdev->flags))
spares++; spares++;
...@@ -4563,7 +4561,7 @@ static int raid5_start_reshape(mddev_t *mddev) ...@@ -4563,7 +4561,7 @@ static int raid5_start_reshape(mddev_t *mddev)
/* Add some new drives, as many as will fit. /* Add some new drives, as many as will fit.
* We know there are enough to make the newly sized array work. * We know there are enough to make the newly sized array work.
*/ */
rdev_for_each(rdev, rtmp, mddev) list_for_each_entry(rdev, &mddev->disks, same_set)
if (rdev->raid_disk < 0 && if (rdev->raid_disk < 0 &&
!test_bit(Faulty, &rdev->flags)) { !test_bit(Faulty, &rdev->flags)) {
if (raid5_add_disk(mddev, rdev) == 0) { if (raid5_add_disk(mddev, rdev) == 0) {
......
...@@ -335,17 +335,14 @@ static inline char * mdname (mddev_t * mddev) ...@@ -335,17 +335,14 @@ static inline char * mdname (mddev_t * mddev)
* iterates through some rdev ringlist. It's safe to remove the * iterates through some rdev ringlist. It's safe to remove the
* current 'rdev'. Dont touch 'tmp' though. * current 'rdev'. Dont touch 'tmp' though.
*/ */
#define rdev_for_each_list(rdev, tmp, list) \ #define rdev_for_each_list(rdev, tmp, head) \
\ list_for_each_entry_safe(rdev, tmp, head, same_set)
for ((tmp) = (list).next; \
(rdev) = (list_entry((tmp), mdk_rdev_t, same_set)), \
(tmp) = (tmp)->next, (tmp)->prev != &(list) \
; )
/* /*
* iterates through the 'same array disks' ringlist * iterates through the 'same array disks' ringlist
*/ */
#define rdev_for_each(rdev, tmp, mddev) \ #define rdev_for_each(rdev, tmp, mddev) \
rdev_for_each_list(rdev, tmp, (mddev)->disks) list_for_each_entry_safe(rdev, tmp, &((mddev)->disks), same_set)
#define rdev_for_each_rcu(rdev, mddev) \ #define rdev_for_each_rcu(rdev, mddev) \
list_for_each_entry_rcu(rdev, &((mddev)->disks), same_set) list_for_each_entry_rcu(rdev, &((mddev)->disks), same_set)
......
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