Skip to content

Commit ab5bd5c

Browse files
Andre Nollneilbrown
authored andcommitted
md: Convert remaining 1k representations in linear.c to sectors.
This patch renames hash_spacing and preshift to spacing and sector_shift respectively with the following change of semantics: Case 1: (sizeof(sector_t) <= sizeof(u32)). ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In this case, we have sector_shift = preshift = 0 and spacing = 2 * hash_spacing. Hence, the index for the hash table which is computed by the new code in which_dev() as sector / spacing equals the old value which was (sector/2) / hash_spacing. Note also that the value of nb_zone stays the same because both sz and base double. Case 2: (sizeof(sector_t) > sizeof(u32)). ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (aka the shifting dance case). Here we have sector_shift = preshift + 1 and spacing = 2 * hash_spacing during the computation of nb_zone and curr_sector, but spacing = hash_spacing in which_dev() because in the last hunk of the patch for linear.c we shift down conf->spacing (= 2 * hash_spacing) by one more bit than in the old code. Hence in the computation of nb_zone, sz and base have the same value as before, so nb_zone is not affected. Also curr_sector in the next hunk stays the same. In which_dev() the hash table index is computed as (sector >> sector_shift) / spacing In view of sector_shift = preshift + 1 and spacing = hash_spacing, this equals ((sector/2) >> preshift) / hash_spacing which is the value computed by the old code. Signed-off-by: Andre Noll <maan@systemlinux.org> Signed-off-by: NeilBrown <neilb@suse.de>
1 parent 23242fb commit ab5bd5c

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

drivers/md/linear.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ static inline dev_info_t *which_dev(mddev_t *mddev, sector_t sector)
3333
{
3434
dev_info_t *hash;
3535
linear_conf_t *conf = mddev_to_conf(mddev);
36-
sector_t block = sector >> 1;
3736

3837
/*
3938
* sector_div(a,b) returns the remainer and sets a to a/b
4039
*/
41-
block >>= conf->preshift;
42-
(void)sector_div(block, conf->hash_spacing);
43-
hash = conf->hash_table[block];
40+
sector >>= conf->sector_shift;
41+
(void)sector_div(sector, conf->spacing);
42+
hash = conf->hash_table[sector];
4443

4544
while (sector >= hash->num_sectors + hash->start_sector)
4645
hash++;
@@ -164,25 +163,25 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
164163
* that is larger than min_sectors and use the size of that as
165164
* the actual spacing
166165
*/
167-
conf->hash_spacing = conf->array_sectors / 2;
166+
conf->spacing = conf->array_sectors;
168167
for (i=0; i < cnt-1 ; i++) {
169168
sector_t tmp = 0;
170169
int j;
171170
for (j = i; j < cnt - 1 && tmp < min_sectors; j++)
172171
tmp += conf->disks[j].num_sectors;
173-
if (tmp >= min_sectors && tmp < conf->hash_spacing * 2)
174-
conf->hash_spacing = tmp / 2;
172+
if (tmp >= min_sectors && tmp < conf->spacing)
173+
conf->spacing = tmp;
175174
}
176175

177-
/* hash_spacing may be too large for sector_div to work with,
176+
/* spacing may be too large for sector_div to work with,
178177
* so we might need to pre-shift
179178
*/
180-
conf->preshift = 0;
179+
conf->sector_shift = 0;
181180
if (sizeof(sector_t) > sizeof(u32)) {
182-
sector_t space = conf->hash_spacing;
181+
sector_t space = conf->spacing;
183182
while (space > (sector_t)(~(u32)0)) {
184183
space >>= 1;
185-
conf->preshift++;
184+
conf->sector_shift++;
186185
}
187186
}
188187
/*
@@ -194,9 +193,9 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
194193
unsigned round;
195194
unsigned long base;
196195

197-
sz = conf->array_sectors >> (conf->preshift + 1);
196+
sz = conf->array_sectors >> conf->sector_shift;
198197
sz += 1; /* force round-up */
199-
base = conf->hash_spacing >> conf->preshift;
198+
base = conf->spacing >> conf->sector_shift;
200199
round = sector_div(sz, base);
201200
nb_zone = sz + (round ? 1 : 0);
202201
}
@@ -221,7 +220,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
221220
i = 0;
222221
for (curr_sector = 0;
223222
curr_sector < conf->array_sectors;
224-
curr_sector += conf->hash_spacing * 2) {
223+
curr_sector += conf->spacing) {
225224

226225
while (i < raid_disks-1 &&
227226
curr_sector >= conf->disks[i+1].start_sector)
@@ -230,12 +229,12 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
230229
*table ++ = conf->disks + i;
231230
}
232231

233-
if (conf->preshift) {
234-
conf->hash_spacing >>= conf->preshift;
235-
/* round hash_spacing up so that when we divide by it,
232+
if (conf->sector_shift) {
233+
conf->spacing >>= conf->sector_shift;
234+
/* round spacing up so that when we divide by it,
236235
* we err on the side of "too-low", which is safest.
237236
*/
238-
conf->hash_spacing++;
237+
conf->spacing++;
239238
}
240239

241240
BUG_ON(table - conf->hash_table > nb_zone);

include/linux/raid/linear.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ struct linear_private_data
1515
{
1616
struct linear_private_data *prev; /* earlier version */
1717
dev_info_t **hash_table;
18-
sector_t hash_spacing;
18+
sector_t spacing;
1919
sector_t array_sectors;
20-
int preshift; /* shift before dividing by hash_spacing */
20+
int sector_shift; /* shift before dividing
21+
* by spacing
22+
*/
2123
dev_info_t disks[0];
2224
};
2325

0 commit comments

Comments
 (0)