Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1493bf21 authored by Tejun Heo's avatar Tejun Heo Committed by Jens Axboe
Browse files

block: use struct parsed_partitions *state universally in partition check 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: default avatarTejun Heo <tj@kernel.org>
Cc: Ben Hutchings <ben@decadent.org.uk>
Acked-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent c3e33e04
Loading
Loading
Loading
Loading
+32 −36
Original line number Diff line number Diff line
@@ -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;

@@ -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;
@@ -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;

@@ -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;
@@ -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;

@@ -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);
@@ -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;
@@ -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;

@@ -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;
		}
	}
@@ -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) {
@@ -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;
@@ -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;

@@ -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;
			}
@@ -446,8 +444,7 @@ 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;
@@ -455,7 +452,7 @@ adfspart_check_POWERTEC(struct parsed_partitions *state, struct block_device *bd
	int slot = 1;
	int i;

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

@@ -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;
@@ -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;

@@ -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");
	}
+5 −5
Original line number Diff line number Diff line
@@ -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);
+6 −7
Original line number Diff line number Diff line
@@ -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;
@@ -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;
		}
@@ -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 */
@@ -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;
		}
+1 −1
Original line number Diff line number Diff line
@@ -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);
+4 −4
Original line number Diff line number Diff line
@@ -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;
@@ -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) &&
@@ -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);
Loading