From: Karel Zak <kzak@redhat.com>
To: Philippe De Muyter <phdm@macqel.be>
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 11:37:56 +0200 [thread overview]
Message-ID: <20130429093756.GB12317@x2.net.home> (raw)
In-Reply-To: <1366924229-21569-3-git-send-email-phdm@macqel.be>
On Thu, Apr 25, 2013 at 11:10:26PM +0200, Philippe De Muyter wrote:
> +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, §);
> + 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.
> + 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, §))) {
> + 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, §))) {
> + 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
everywhere, maybe you can use sizeof() and ARRAY_SIZE().
> + 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 :-)
> + 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 ?
> + 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.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
next prev parent reply other threads:[~2013-04-29 9:38 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 [this message]
2013-04-29 11:40 ` Philippe De Muyter
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
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=20130429093756.GB12317@x2.net.home \
--to=kzak@redhat.com \
--cc=axboe@kernel.dk \
--cc=linux-kernel@vger.kernel.org \
--cc=phdm@macqel.be \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®