Skip to content

Commit

Permalink
Merge branch 'for-linus' of git://neil.brown.name/md
Browse files Browse the repository at this point in the history
* 'for-linus' of git://neil.brown.name/md:
  md: fix input truncation in safe_delay_store()
  md: check for memory allocation failure in faulty personality
  md: build failure due to missing delay.h
  md: Relax minimum size restrictions on chunk_size.
  md: remove space after function name in declaration and call.
  md: Remove unnecessary #includes, #defines, and function declarations.
  md: Convert remaining 1k representations in linear.c to sectors.
  md: linear.c: Make two local variables sector-based.
  md: linear: Represent dev_info->size and dev_info->offset in sectors.
  md: linear.c: Remove broken debug code.
  md: linear.c: Remove pointless initialization of curr_offset.
  md: linear.c: Fix typo in comment.
  md: Don't try to set an array to 'read-auto' if it is already in that state.
  md: Allow metadata_version to be updated for externally managed metadata.
  md: Fix rdev_size_store with size == 0
  • Loading branch information
torvalds committed Oct 16, 2008
2 parents 36ac1d2 + 97ce0a7 commit c472273
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 205 deletions.
2 changes: 2 additions & 0 deletions drivers/md/faulty.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ static int run(mddev_t *mddev)
int i;

conf_t *conf = kmalloc(sizeof(*conf), GFP_KERNEL);
if (!conf)
return -ENOMEM;

for (i=0; i<Modes; i++) {
atomic_set(&conf->counters[i], 0);
Expand Down
133 changes: 52 additions & 81 deletions drivers/md/linear.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,24 @@
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <linux/module.h>

#include <linux/raid/md.h>
#include <linux/slab.h>
#include <linux/raid/linear.h>

#define MAJOR_NR MD_MAJOR
#define MD_DRIVER
#define MD_PERSONALITY

/*
* find which device holds a particular offset
*/
static inline dev_info_t *which_dev(mddev_t *mddev, sector_t sector)
{
dev_info_t *hash;
linear_conf_t *conf = mddev_to_conf(mddev);
sector_t block = sector >> 1;

/*
* sector_div(a,b) returns the remainer and sets a to a/b
*/
block >>= conf->preshift;
(void)sector_div(block, conf->hash_spacing);
hash = conf->hash_table[block];
sector >>= conf->sector_shift;
(void)sector_div(sector, conf->spacing);
hash = conf->hash_table[sector];

while ((sector>>1) >= (hash->size + hash->offset))
while (sector >= hash->num_sectors + hash->start_sector)
hash++;
return hash;
}
Expand All @@ -65,7 +56,7 @@ static int linear_mergeable_bvec(struct request_queue *q,
sector_t sector = bvm->bi_sector + get_start_sect(bvm->bi_bdev);

dev0 = which_dev(mddev, sector);
maxsectors = (dev0->size << 1) - (sector - (dev0->offset<<1));
maxsectors = dev0->num_sectors - (sector - dev0->start_sector);

if (maxsectors < bio_sectors)
maxsectors = 0;
Expand Down Expand Up @@ -112,8 +103,8 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
dev_info_t **table;
mdk_rdev_t *rdev;
int i, nb_zone, cnt;
sector_t min_spacing;
sector_t curr_offset;
sector_t min_sectors;
sector_t curr_sector;
struct list_head *tmp;

conf = kzalloc (sizeof (*conf) + raid_disks*sizeof(dev_info_t),
Expand Down Expand Up @@ -145,7 +136,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
mddev->queue->max_sectors > (PAGE_SIZE>>9))
blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);

disk->size = rdev->size;
disk->num_sectors = rdev->size * 2;
conf->array_sectors += rdev->size * 2;

cnt++;
Expand All @@ -155,34 +146,34 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
goto out;
}

min_spacing = conf->array_sectors / 2;
sector_div(min_spacing, PAGE_SIZE/sizeof(struct dev_info *));
min_sectors = conf->array_sectors;
sector_div(min_sectors, PAGE_SIZE/sizeof(struct dev_info *));

/* min_spacing is the minimum spacing that will fit the hash
/* min_sectors is the minimum spacing that will fit the hash
* table in one PAGE. This may be much smaller than needed.
* We find the smallest non-terminal set of consecutive devices
* that is larger than min_spacing as use the size of that as
* that is larger than min_sectors and use the size of that as
* the actual spacing
*/
conf->hash_spacing = conf->array_sectors / 2;
conf->spacing = conf->array_sectors;
for (i=0; i < cnt-1 ; i++) {
sector_t sz = 0;
sector_t tmp = 0;
int j;
for (j = i; j < cnt - 1 && sz < min_spacing; j++)
sz += conf->disks[j].size;
if (sz >= min_spacing && sz < conf->hash_spacing)
conf->hash_spacing = sz;
for (j = i; j < cnt - 1 && tmp < min_sectors; j++)
tmp += conf->disks[j].num_sectors;
if (tmp >= min_sectors && tmp < conf->spacing)
conf->spacing = tmp;
}

/* hash_spacing may be too large for sector_div to work with,
/* spacing may be too large for sector_div to work with,
* so we might need to pre-shift
*/
conf->preshift = 0;
conf->sector_shift = 0;
if (sizeof(sector_t) > sizeof(u32)) {
sector_t space = conf->hash_spacing;
sector_t space = conf->spacing;
while (space > (sector_t)(~(u32)0)) {
space >>= 1;
conf->preshift++;
conf->sector_shift++;
}
}
/*
Expand All @@ -194,9 +185,9 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
unsigned round;
unsigned long base;

sz = conf->array_sectors >> (conf->preshift + 1);
sz = conf->array_sectors >> conf->sector_shift;
sz += 1; /* force round-up */
base = conf->hash_spacing >> conf->preshift;
base = conf->spacing >> conf->sector_shift;
round = sector_div(sz, base);
nb_zone = sz + (round ? 1 : 0);
}
Expand All @@ -211,32 +202,31 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
* Here we generate the linear hash table
* First calculate the device offsets.
*/
conf->disks[0].offset = 0;
conf->disks[0].start_sector = 0;
for (i = 1; i < raid_disks; i++)
conf->disks[i].offset =
conf->disks[i-1].offset +
conf->disks[i-1].size;
conf->disks[i].start_sector =
conf->disks[i-1].start_sector +
conf->disks[i-1].num_sectors;

table = conf->hash_table;
curr_offset = 0;
i = 0;
for (curr_offset = 0;
curr_offset < conf->array_sectors / 2;
curr_offset += conf->hash_spacing) {
for (curr_sector = 0;
curr_sector < conf->array_sectors;
curr_sector += conf->spacing) {

while (i < raid_disks-1 &&
curr_offset >= conf->disks[i+1].offset)
curr_sector >= conf->disks[i+1].start_sector)
i++;

*table ++ = conf->disks + i;
}

if (conf->preshift) {
conf->hash_spacing >>= conf->preshift;
/* round hash_spacing up so that when we divide by it,
if (conf->sector_shift) {
conf->spacing >>= conf->sector_shift;
/* round spacing up so that when we divide by it,
* we err on the side of "too-low", which is safest.
*/
conf->hash_spacing++;
conf->spacing++;
}

BUG_ON(table - conf->hash_table > nb_zone);
Expand Down Expand Up @@ -317,7 +307,6 @@ static int linear_make_request (struct request_queue *q, struct bio *bio)
const int rw = bio_data_dir(bio);
mddev_t *mddev = q->queuedata;
dev_info_t *tmp_dev;
sector_t block;
int cpu;

if (unlikely(bio_barrier(bio))) {
Expand All @@ -332,29 +321,33 @@ static int linear_make_request (struct request_queue *q, struct bio *bio)
part_stat_unlock();

tmp_dev = which_dev(mddev, bio->bi_sector);
block = bio->bi_sector >> 1;

if (unlikely(block >= (tmp_dev->size + tmp_dev->offset)
|| block < tmp_dev->offset)) {
if (unlikely(bio->bi_sector >= (tmp_dev->num_sectors +
tmp_dev->start_sector)
|| (bio->bi_sector <
tmp_dev->start_sector))) {
char b[BDEVNAME_SIZE];

printk("linear_make_request: Block %llu out of bounds on "
"dev %s size %llu offset %llu\n",
(unsigned long long)block,
printk("linear_make_request: Sector %llu out of bounds on "
"dev %s: %llu sectors, offset %llu\n",
(unsigned long long)bio->bi_sector,
bdevname(tmp_dev->rdev->bdev, b),
(unsigned long long)tmp_dev->size,
(unsigned long long)tmp_dev->offset);
(unsigned long long)tmp_dev->num_sectors,
(unsigned long long)tmp_dev->start_sector);
bio_io_error(bio);
return 0;
}
if (unlikely(bio->bi_sector + (bio->bi_size >> 9) >
(tmp_dev->offset + tmp_dev->size)<<1)) {
tmp_dev->start_sector + tmp_dev->num_sectors)) {
/* This bio crosses a device boundary, so we have to
* split it.
*/
struct bio_pair *bp;

bp = bio_split(bio,
((tmp_dev->offset + tmp_dev->size)<<1) - bio->bi_sector);
tmp_dev->start_sector + tmp_dev->num_sectors
- bio->bi_sector);

if (linear_make_request(q, &bp->bio1))
generic_make_request(&bp->bio1);
if (linear_make_request(q, &bp->bio2))
Expand All @@ -364,37 +357,15 @@ static int linear_make_request (struct request_queue *q, struct bio *bio)
}

bio->bi_bdev = tmp_dev->rdev->bdev;
bio->bi_sector = bio->bi_sector - (tmp_dev->offset << 1) + tmp_dev->rdev->data_offset;
bio->bi_sector = bio->bi_sector - tmp_dev->start_sector
+ tmp_dev->rdev->data_offset;

return 1;
}

static void linear_status (struct seq_file *seq, mddev_t *mddev)
{

#undef MD_DEBUG
#ifdef MD_DEBUG
int j;
linear_conf_t *conf = mddev_to_conf(mddev);
sector_t s = 0;

seq_printf(seq, " ");
for (j = 0; j < mddev->raid_disks; j++)
{
char b[BDEVNAME_SIZE];
s += conf->smallest_size;
seq_printf(seq, "[%s",
bdevname(conf->hash_table[j][0].rdev->bdev,b));

while (s > conf->hash_table[j][0].offset +
conf->hash_table[j][0].size)
seq_printf(seq, "/%s] ",
bdevname(conf->hash_table[j][1].rdev->bdev,b));
else
seq_printf(seq, "] ");
}
seq_printf(seq, "\n");
#endif
seq_printf(seq, " %dk rounding", mddev->chunk_size/1024);
}

Expand Down
Loading

0 comments on commit c472273

Please sign in to comment.