All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe De Muyter <phdm@macqel.be>
To: Karel Zak <kzak@redhat.com>
Cc: linux-kernel@vger.kernel.org, Jens Axboe <axboe@kernel.dk>
Subject: Re: [PATCH 2/5] Add aix lvm partitions support files
Date: Mon, 29 Apr 2013 13:40:41 +0200	[thread overview]
Message-ID: <20130429114041.GA10884@frolo.macqel> (raw)
In-Reply-To: <20130429093756.GB12317@x2.net.home>

On Mon, Apr 29, 2013 at 11:37:56AM +0200, Karel Zak wrote:
> On Thu, Apr 25, 2013 at 11:10:26PM +0200, Philippe De Muyter wrote:

Thanks for the interest and the quick reply.

> > +int aix_partition(struct parsed_partitions *state)
> > +{
> > +	int ret = 0;
> > +	Sector sect;
> > +	unsigned char *d;
> > +	u32 pp_bytes_size;
> > +	u32 pp_blocks_size = 0;
> > +	u32 vgda_sector = 0;
> > +	u32 vgda_len = 0;
> > +	int numlvs = 0;
> > +	struct pvd *pvd;
> > +	unsigned short pps_per_lv[16];
> > +	unsigned short pps_found[16];
> > +	unsigned char lv_is_contiguous[16];
> > +	struct lvname *n = NULL;
> > +
> > +	d = read_part_sector(state, 7, &sect);
> > +	if (d) {
> > +		struct lvm_rec *p = (struct lvm_rec *)d;
> > +		u16 lvm_version = be16_to_cpu(p->version);
> > +		char tmp[64];
> > +
> > +		if (lvm_version == 1) {
> > +			int pp_size_log2 = be16_to_cpu(p->pp_size);
> > +
> > +			pp_bytes_size = 1 << pp_size_log2;
> > +			pp_blocks_size = pp_bytes_size / 512;
> > +			snprintf(tmp, sizeof(tmp), " AIX LVM header version %u found\n", lvm_version);
> 
> 'tmp' is nowhere used, maybe you want to use strlcat(state->pp_buf, tmp, PAGE_SIZE); too.

Oops, of course :)
> 
> > +			vgda_len = be32_to_cpu(p->vgda_len);
> > +			vgda_sector = be32_to_cpu(p->vgda_psn[0]);
> > +		} else {
> > +			snprintf(tmp, sizeof(tmp), " unsupported AIX LVM version %d found\n",
> > +				lvm_version);
> > +			strlcat(state->pp_buf, tmp, PAGE_SIZE);
> > +		}
> > +		put_dev_sector(sect);
> > +	}
> > +	if (vgda_sector && (d = read_part_sector(state, vgda_sector, &sect))) {
> > +		struct vgda *p = (struct vgda *)d;
> > +
> > +		numlvs = be16_to_cpu(p->numlvs);
> > +		put_dev_sector(sect);
> > +	}
> > +	if (numlvs && (d = read_part_sector(state, vgda_sector + 1, &sect))) {
> > +		struct lvd *p = (struct lvd *)d;
> > +		int i;
> > +
> > +		n = alloc_lvn(state, vgda_sector + vgda_len - 33);
> > +		if (n) {
> > +			int j = 0;
> > +
> > +			memset(lv_is_contiguous, 0, 16);
> > +			for (i = 0; i < 16; i += 1)
> > +				pps_found[i] = 0;
> 
> why not memset(pps_found, ....)? I also see magical constant 16

Actually 16 is the maximum partition count allowed in a disk by linux,
or should it be 15 ?  Is there already a constant for that ?
The AIX disk I tested with had only :) 11 partitions.

> everywhere, maybe you can use sizeof() and ARRAY_SIZE().

Will do.
> 
> > +			for (i = 0; j < numlvs && i < 16; i += 1) {
> > +				pps_per_lv[i] = be16_to_cpu(p[i].num_lps);
> > +				if (pps_per_lv[i])
> > +					j += 1;
> > +			}
> 
> hmm, what's wrong with j++ and i++, "j += 1" seems like old Python :-)
> 

What's wrong with "j += 1" ?
I only use ++ for side effects; I personaly find "j += 1" more readable :)
But I should rename 'j' to be more explicit.


> > +			while (i < 16)
> > +				pps_per_lv[i++] = 0;
> > +		}
> > +		put_dev_sector(sect);
> > +	}
> > +	pvd = alloc_pvd(state, vgda_sector + 17);
> > +	if (pvd) {
> > +		int numpps = be16_to_cpu(pvd->pp_count);
> > +		int psn_part1 = be32_to_cpu(pvd->psn_part1);
> > +		int i;
> > +		int cur_lv_ix = -1;
> > +		int next_lp_ix = 1;
> > +		int lp_ix;
> > +
> > +		for (i = 0; i < numpps; i += 1) {
> > +			struct ppe *p = pvd->ppe + i;
> > +			int lv_ix;
> > +
> > +			lp_ix = be16_to_cpu(p->lp_ix);
> > +			if (!lp_ix) {
> > +				next_lp_ix = 1;
> > +				continue;
> > +			}
> > +			lv_ix = be16_to_cpu(p->lv_ix) - 1;
> > +			pps_found[lv_ix] += 1;
> 
>  Would be better to be a little paranoid when you read the data from
>  disk and check that lv_ix is in range 0..16 ?

Of course.

> 
> > +			if (lp_ix != next_lp_ix)
> > +				continue;
> > +			if (lp_ix == 1)
> > +				cur_lv_ix = lv_ix;
> > +			else if (lv_ix != cur_lv_ix)
> > +				next_lp_ix = 1;
> > +			if (lp_ix == pps_per_lv[lv_ix]) {
> > +				char tmp[70];
> > +
> > +				put_partition(state, lv_ix + 1,
> > +					(i + 1 - lp_ix) * pp_blocks_size + psn_part1,
> > +					pps_per_lv[lv_ix] * pp_blocks_size);
> > +				snprintf(tmp, sizeof(tmp), " <%s>\n", n[lv_ix].name);
> > +				strlcat(state->pp_buf, tmp, PAGE_SIZE);
> > +				lv_is_contiguous[lv_ix] = 1;
> > +				ret = 1;
> > +				next_lp_ix = 1;
> > +			} else
> > +				next_lp_ix += 1;
> > +		}
> > +		for (i = 0; i < 16; i += 1)
> > +			if (pps_found[i] && !lv_is_contiguous[i])
> > +				printk("partition %s (%d pp's found) is not contiguous\n", n[i].name, pps_found[i]);
> > +		kfree(pvd);
> > +	}
> > +	if (n)
> > +		kfree(n);
> > +	return ret;
> > +}
> 
> Philippe, do you have any disk image with AIX LVM? It would be nice to
> have a way how to test the code. I'd like to add support for AIX to
> libblkid too.

Of course.  But that's not a couple of blocks.  I'll try to cut the
slice that you need.

Philippe

-- 
Philippe De Muyter +32 2 6101532 Macq SA rue de l'Aeronef 2 B-1140 Bruxelles

  reply	other threads:[~2013-04-29 11:40 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-25 21:10 [RFC PATCH 0/5] Add aix lvm partitions support Philippe De Muyter
2013-04-25 21:10 ` [PATCH 1/5] partitions/msdos.c: end-of-line whitespace and semicolon cleanup Philippe De Muyter
2013-04-25 21:10 ` [PATCH 2/5] Add aix lvm partitions support files Philippe De Muyter
2013-04-29  9:37   ` Karel Zak
2013-04-29 11:40     ` Philippe De Muyter [this message]
2013-04-29 12:36       ` Karel Zak
2013-04-29 15:34         ` Philippe De Muyter
2013-04-30  6:41           ` Jens Axboe
2013-04-30  6:45             ` Philippe De Muyter
2013-04-29 21:50       ` Philippe De Muyter
2013-04-30  7:08         ` Philippe De Muyter
2013-04-30  7:18           ` Philippe De Muyter
2013-05-01  5:35             ` Philippe De Muyter
2013-04-25 21:10 ` [PATCH 3/5] partitions/msdos: enumerate also AIX LVM partitions Philippe De Muyter
2013-04-25 21:10 ` [PATCH 4/5] partitions/Makefile: compile aix.c if configured Philippe De Muyter
2013-04-25 21:10 ` [PATCH 5/5] partitions/Kconfig: add the AIX_PARTITION entry Philippe De Muyter
  -- strict thread matches above, loose matches on Subject: below --
2013-04-29 21:18 [PATCH v2 0/5] partitions: add AIX LVM support Philippe De Muyter
2013-04-29 21:18 ` [PATCH 2/5] Add aix lvm partitions support files Philippe De Muyter
2013-05-20 23:39   ` Andrew Morton
2013-05-21  7:27     ` Philippe De Muyter
2013-05-24 10:04       ` Christoph Hellwig
2013-05-24 10:58         ` Philippe De Muyter
2013-08-12 11:52           ` Christoph Hellwig
2013-08-12 12:21             ` Alasdair G Kergon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130429114041.GA10884@frolo.macqel \
    --to=phdm@macqel.be \
    --cc=axboe@kernel.dk \
    --cc=kzak@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.