Skip to content

Commit

Permalink
block: use struct parsed_partitions *state universally in partition c…
Browse files Browse the repository at this point in the history
…heck code

Make the following changes to partition check code.

* Add ->bdev to struct parsed_partitions.

* Introduce read_part_sector() which is a simple wrapper around
  read_dev_sector() which takes struct parsed_partitions *state
  instead of @bdev.

* For functions which used to take @State and @bdev, drop @bdev.  For
  functions which used to take @bdev, replace it with @State.

* While updating, drop superflous checks on NULL state/bdev in ldm.c.

This cleans up the API a bit and enables better handling of IO errors
during partition check as the generic partition check code now has
much better visibility into what went wrong in the low level code
paths.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Ben Hutchings <ben@decadent.org.uk>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
  • Loading branch information
htejun authored and Jens Axboe committed May 21, 2010
1 parent c3e33e0 commit 1493bf2
Show file tree
Hide file tree
Showing 30 changed files with 225 additions and 239 deletions.
68 changes: 32 additions & 36 deletions fs/partitions/acorn.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ struct riscix_record {

#if defined(CONFIG_ACORN_PARTITION_CUMANA) || \
defined(CONFIG_ACORN_PARTITION_ADFS)
static int
riscix_partition(struct parsed_partitions *state, struct block_device *bdev,
unsigned long first_sect, int slot, unsigned long nr_sects)
static int riscix_partition(struct parsed_partitions *state,
unsigned long first_sect, int slot,
unsigned long nr_sects)
{
Sector sect;
struct riscix_record *rr;

rr = (struct riscix_record *)read_dev_sector(bdev, first_sect, &sect);
rr = read_part_sector(state, first_sect, &sect);
if (!rr)
return -1;

Expand Down Expand Up @@ -123,9 +123,9 @@ struct linux_part {

#if defined(CONFIG_ACORN_PARTITION_CUMANA) || \
defined(CONFIG_ACORN_PARTITION_ADFS)
static int
linux_partition(struct parsed_partitions *state, struct block_device *bdev,
unsigned long first_sect, int slot, unsigned long nr_sects)
static int linux_partition(struct parsed_partitions *state,
unsigned long first_sect, int slot,
unsigned long nr_sects)
{
Sector sect;
struct linux_part *linuxp;
Expand All @@ -135,7 +135,7 @@ linux_partition(struct parsed_partitions *state, struct block_device *bdev,

put_partition(state, slot++, first_sect, size);

linuxp = (struct linux_part *)read_dev_sector(bdev, first_sect, &sect);
linuxp = read_part_sector(state, first_sect, &sect);
if (!linuxp)
return -1;

Expand All @@ -157,8 +157,7 @@ linux_partition(struct parsed_partitions *state, struct block_device *bdev,
#endif

#ifdef CONFIG_ACORN_PARTITION_CUMANA
int
adfspart_check_CUMANA(struct parsed_partitions *state, struct block_device *bdev)
int adfspart_check_CUMANA(struct parsed_partitions *state)
{
unsigned long first_sector = 0;
unsigned int start_blk = 0;
Expand All @@ -185,7 +184,7 @@ adfspart_check_CUMANA(struct parsed_partitions *state, struct block_device *bdev
struct adfs_discrecord *dr;
unsigned int nr_sects;

data = read_dev_sector(bdev, start_blk * 2 + 6, &sect);
data = read_part_sector(state, start_blk * 2 + 6, &sect);
if (!data)
return -1;

Expand Down Expand Up @@ -217,14 +216,14 @@ adfspart_check_CUMANA(struct parsed_partitions *state, struct block_device *bdev
#ifdef CONFIG_ACORN_PARTITION_RISCIX
case PARTITION_RISCIX_SCSI:
/* RISCiX - we don't know how to find the next one. */
slot = riscix_partition(state, bdev, first_sector,
slot, nr_sects);
slot = riscix_partition(state, first_sector, slot,
nr_sects);
break;
#endif

case PARTITION_LINUX:
slot = linux_partition(state, bdev, first_sector,
slot, nr_sects);
slot = linux_partition(state, first_sector, slot,
nr_sects);
break;
}
put_dev_sector(sect);
Expand All @@ -249,8 +248,7 @@ adfspart_check_CUMANA(struct parsed_partitions *state, struct block_device *bdev
* hda1 = ADFS partition on first drive.
* hda2 = non-ADFS partition.
*/
int
adfspart_check_ADFS(struct parsed_partitions *state, struct block_device *bdev)
int adfspart_check_ADFS(struct parsed_partitions *state)
{
unsigned long start_sect, nr_sects, sectscyl, heads;
Sector sect;
Expand All @@ -259,7 +257,7 @@ adfspart_check_ADFS(struct parsed_partitions *state, struct block_device *bdev)
unsigned char id;
int slot = 1;

data = read_dev_sector(bdev, 6, &sect);
data = read_part_sector(state, 6, &sect);
if (!data)
return -1;

Expand All @@ -278,21 +276,21 @@ adfspart_check_ADFS(struct parsed_partitions *state, struct block_device *bdev)
/*
* Work out start of non-adfs partition.
*/
nr_sects = (bdev->bd_inode->i_size >> 9) - start_sect;
nr_sects = (state->bdev->bd_inode->i_size >> 9) - start_sect;

if (start_sect) {
switch (id) {
#ifdef CONFIG_ACORN_PARTITION_RISCIX
case PARTITION_RISCIX_SCSI:
case PARTITION_RISCIX_MFM:
slot = riscix_partition(state, bdev, start_sect,
slot, nr_sects);
slot = riscix_partition(state, start_sect, slot,
nr_sects);
break;
#endif

case PARTITION_LINUX:
slot = linux_partition(state, bdev, start_sect,
slot, nr_sects);
slot = linux_partition(state, start_sect, slot,
nr_sects);
break;
}
}
Expand All @@ -308,10 +306,11 @@ struct ics_part {
__le32 size;
};

static int adfspart_check_ICSLinux(struct block_device *bdev, unsigned long block)
static int adfspart_check_ICSLinux(struct parsed_partitions *state,
unsigned long block)
{
Sector sect;
unsigned char *data = read_dev_sector(bdev, block, &sect);
unsigned char *data = read_part_sector(state, block, &sect);
int result = 0;

if (data) {
Expand Down Expand Up @@ -349,8 +348,7 @@ static inline int valid_ics_sector(const unsigned char *data)
* hda2 = ADFS partition 1 on first drive.
* ..etc..
*/
int
adfspart_check_ICS(struct parsed_partitions *state, struct block_device *bdev)
int adfspart_check_ICS(struct parsed_partitions *state)
{
const unsigned char *data;
const struct ics_part *p;
Expand All @@ -360,7 +358,7 @@ adfspart_check_ICS(struct parsed_partitions *state, struct block_device *bdev)
/*
* Try ICS style partitions - sector 0 contains partition info.
*/
data = read_dev_sector(bdev, 0, &sect);
data = read_part_sector(state, 0, &sect);
if (!data)
return -1;

Expand Down Expand Up @@ -392,7 +390,7 @@ adfspart_check_ICS(struct parsed_partitions *state, struct block_device *bdev)
* partition is. We must not make this visible
* to the filesystem.
*/
if (size > 1 && adfspart_check_ICSLinux(bdev, start)) {
if (size > 1 && adfspart_check_ICSLinux(state, start)) {
start += 1;
size -= 1;
}
Expand Down Expand Up @@ -446,16 +444,15 @@ static inline int valid_ptec_sector(const unsigned char *data)
* hda2 = ADFS partition 1 on first drive.
* ..etc..
*/
int
adfspart_check_POWERTEC(struct parsed_partitions *state, struct block_device *bdev)
int adfspart_check_POWERTEC(struct parsed_partitions *state)
{
Sector sect;
const unsigned char *data;
const struct ptec_part *p;
int slot = 1;
int i;

data = read_dev_sector(bdev, 0, &sect);
data = read_part_sector(state, 0, &sect);
if (!data)
return -1;

Expand Down Expand Up @@ -508,8 +505,7 @@ static const char eesox_name[] = {
* 1. The individual ADFS boot block entries that are placed on the disk.
* 2. The start address of the next entry.
*/
int
adfspart_check_EESOX(struct parsed_partitions *state, struct block_device *bdev)
int adfspart_check_EESOX(struct parsed_partitions *state)
{
Sector sect;
const unsigned char *data;
Expand All @@ -518,7 +514,7 @@ adfspart_check_EESOX(struct parsed_partitions *state, struct block_device *bdev)
sector_t start = 0;
int i, slot = 1;

data = read_dev_sector(bdev, 7, &sect);
data = read_part_sector(state, 7, &sect);
if (!data)
return -1;

Expand All @@ -545,7 +541,7 @@ adfspart_check_EESOX(struct parsed_partitions *state, struct block_device *bdev)
if (i != 0) {
sector_t size;

size = get_capacity(bdev->bd_disk);
size = get_capacity(state->bdev->bd_disk);
put_partition(state, slot++, start, size - start);
printk("\n");
}
Expand Down
10 changes: 5 additions & 5 deletions fs/partitions/acorn.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* format, and everyone stick to it?
*/

int adfspart_check_CUMANA(struct parsed_partitions *state, struct block_device *bdev);
int adfspart_check_ADFS(struct parsed_partitions *state, struct block_device *bdev);
int adfspart_check_ICS(struct parsed_partitions *state, struct block_device *bdev);
int adfspart_check_POWERTEC(struct parsed_partitions *state, struct block_device *bdev);
int adfspart_check_EESOX(struct parsed_partitions *state, struct block_device *bdev);
int adfspart_check_CUMANA(struct parsed_partitions *state);
int adfspart_check_ADFS(struct parsed_partitions *state);
int adfspart_check_ICS(struct parsed_partitions *state);
int adfspart_check_POWERTEC(struct parsed_partitions *state);
int adfspart_check_EESOX(struct parsed_partitions *state);
13 changes: 6 additions & 7 deletions fs/partitions/amiga.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ checksum_block(__be32 *m, int size)
return sum;
}

int
amiga_partition(struct parsed_partitions *state, struct block_device *bdev)
int amiga_partition(struct parsed_partitions *state)
{
Sector sect;
unsigned char *data;
Expand All @@ -38,11 +37,11 @@ amiga_partition(struct parsed_partitions *state, struct block_device *bdev)
for (blk = 0; ; blk++, put_dev_sector(sect)) {
if (blk == RDB_ALLOCATION_LIMIT)
goto rdb_done;
data = read_dev_sector(bdev, blk, &sect);
data = read_part_sector(state, blk, &sect);
if (!data) {
if (warn_no_part)
printk("Dev %s: unable to read RDB block %d\n",
bdevname(bdev, b), blk);
bdevname(state->bdev, b), blk);
res = -1;
goto rdb_done;
}
Expand All @@ -64,7 +63,7 @@ amiga_partition(struct parsed_partitions *state, struct block_device *bdev)
}

printk("Dev %s: RDB in block %d has bad checksum\n",
bdevname(bdev, b), blk);
bdevname(state->bdev, b), blk);
}

/* blksize is blocks per 512 byte standard block */
Expand All @@ -75,11 +74,11 @@ amiga_partition(struct parsed_partitions *state, struct block_device *bdev)
put_dev_sector(sect);
for (part = 1; blk>0 && part<=16; part++, put_dev_sector(sect)) {
blk *= blksize; /* Read in terms partition table understands */
data = read_dev_sector(bdev, blk, &sect);
data = read_part_sector(state, blk, &sect);
if (!data) {
if (warn_no_part)
printk("Dev %s: unable to read partition block %d\n",
bdevname(bdev, b), blk);
bdevname(state->bdev, b), blk);
res = -1;
goto rdb_done;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/partitions/amiga.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
* fs/partitions/amiga.h
*/

int amiga_partition(struct parsed_partitions *state, struct block_device *bdev);
int amiga_partition(struct parsed_partitions *state);

8 changes: 4 additions & 4 deletions fs/partitions/atari.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static inline int OK_id(char *s)
memcmp (s, "RAW", 3) == 0 ;
}

int atari_partition(struct parsed_partitions *state, struct block_device *bdev)
int atari_partition(struct parsed_partitions *state)
{
Sector sect;
struct rootsector *rs;
Expand All @@ -42,12 +42,12 @@ int atari_partition(struct parsed_partitions *state, struct block_device *bdev)
int part_fmt = 0; /* 0:unknown, 1:AHDI, 2:ICD/Supra */
#endif

rs = (struct rootsector *) read_dev_sector(bdev, 0, &sect);
rs = read_part_sector(state, 0, &sect);
if (!rs)
return -1;

/* Verify this is an Atari rootsector: */
hd_size = bdev->bd_inode->i_size >> 9;
hd_size = state->bdev->bd_inode->i_size >> 9;
if (!VALID_PARTITION(&rs->part[0], hd_size) &&
!VALID_PARTITION(&rs->part[1], hd_size) &&
!VALID_PARTITION(&rs->part[2], hd_size) &&
Expand Down Expand Up @@ -84,7 +84,7 @@ int atari_partition(struct parsed_partitions *state, struct block_device *bdev)
printk(" XGM<");
partsect = extensect = be32_to_cpu(pi->st);
while (1) {
xrs = (struct rootsector *)read_dev_sector(bdev, partsect, &sect2);
xrs = read_part_sector(state, partsect, &sect2);
if (!xrs) {
printk (" block %ld read failed\n", partsect);
put_dev_sector(sect);
Expand Down
2 changes: 1 addition & 1 deletion fs/partitions/atari.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ struct rootsector
u16 checksum; /* checksum for bootable disks */
} __attribute__((__packed__));

int atari_partition(struct parsed_partitions *state, struct block_device *bdev);
int atari_partition(struct parsed_partitions *state);
5 changes: 3 additions & 2 deletions fs/partitions/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extern void md_autodetect_dev(dev_t dev);

int warn_no_part = 1; /*This is ugly: should make genhd removable media aware*/

static int (*check_part[])(struct parsed_partitions *, struct block_device *) = {
static int (*check_part[])(struct parsed_partitions *) = {
/*
* Probe partition formats with tables at disk address 0
* that also have an ADFS boot block at 0xdc0.
Expand Down Expand Up @@ -165,6 +165,7 @@ check_partition(struct gendisk *hd, struct block_device *bdev)
if (!state)
return NULL;

state->bdev = bdev;
disk_name(hd, 0, state->name);
printk(KERN_INFO " %s:", state->name);
if (isdigit(state->name[strlen(state->name)-1]))
Expand All @@ -174,7 +175,7 @@ check_partition(struct gendisk *hd, struct block_device *bdev)
i = res = err = 0;
while (!res && check_part[i]) {
memset(&state->parts, 0, sizeof(state->parts));
res = check_part[i++](state, bdev);
res = check_part[i++](state);
if (res < 0) {
/* We have hit an I/O error which we don't report now.
* But record it, and let the others do their job.
Expand Down
7 changes: 7 additions & 0 deletions fs/partitions/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* description.
*/
struct parsed_partitions {
struct block_device *bdev;
char name[BDEVNAME_SIZE];
struct {
sector_t from;
Expand All @@ -16,6 +17,12 @@ struct parsed_partitions {
int limit;
};

static inline void *read_part_sector(struct parsed_partitions *state,
sector_t n, Sector *p)
{
return read_dev_sector(state->bdev, n, p);
}

static inline void
put_partition(struct parsed_partitions *p, int n, sector_t from, sector_t size)
{
Expand Down
Loading

0 comments on commit 1493bf2

Please sign in to comment.