Re: [PATCH 2/5] Add aix lvm partitions support files

2013-08-12 Thread Alasdair G Kergon
On Mon, Aug 12, 2013 at 04:52:34AM -0700, Christoph Hellwig wrote:
> lvm is mostly about the Linux specific formats.  If you want to create
> a separate userspace consumer for device mapper that's probably also
> fine, but if you need support for complex layours device mapper is the
> way to go, and the partitioning layer isn't getting you anywhere.
 
If you can map the AIX volume manager objects onto the linux ones, you
can write a 'format' module for lvm2 to handle them.

Alasdair

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-08-12 Thread Christoph Hellwig
On Fri, May 24, 2013 at 12:58:52PM +0200, Philippe De Muyter wrote:
> > This very much screams like it should be implemented in the lvm2
> > userspace package using the dm kernel driver.
> 
> Is lvm2 a generic tool for discovering foreign partition layouts, or it is
> about one linux-specific lvm implementation ?

lvm is mostly about the Linux specific formats.  If you want to create
a separate userspace consumer for device mapper that's probably also
fine, but if you need support for complex layours device mapper is the
way to go, and the partitioning layer isn't getting you anywhere.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-08-12 Thread Christoph Hellwig
On Fri, May 24, 2013 at 12:58:52PM +0200, Philippe De Muyter wrote:
  This very much screams like it should be implemented in the lvm2
  userspace package using the dm kernel driver.
 
 Is lvm2 a generic tool for discovering foreign partition layouts, or it is
 about one linux-specific lvm implementation ?

lvm is mostly about the Linux specific formats.  If you want to create
a separate userspace consumer for device mapper that's probably also
fine, but if you need support for complex layours device mapper is the
way to go, and the partitioning layer isn't getting you anywhere.

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-08-12 Thread Alasdair G Kergon
On Mon, Aug 12, 2013 at 04:52:34AM -0700, Christoph Hellwig wrote:
 lvm is mostly about the Linux specific formats.  If you want to create
 a separate userspace consumer for device mapper that's probably also
 fine, but if you need support for complex layours device mapper is the
 way to go, and the partitioning layer isn't getting you anywhere.
 
If you can map the AIX volume manager objects onto the linux ones, you
can write a 'format' module for lvm2 to handle them.

Alasdair

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-05-24 Thread Philippe De Muyter
On Fri, May 24, 2013 at 06:04:52AM -0400, Christoph Hellwig wrote:
> On Tue, May 21, 2013 at 09:27:54AM +0200, Philippe De Muyter wrote:
> > AIX LVM permits to make "logical volumes" which are made of multiple slices
> > of multiple disks.  The new code allows only access to the "logical volumes"
> > which are made of one slice on the probed disk, a slice being a contiguous
> > disk area.  The code also detects "logical volumes" made of multiple slices
> > on the probed disk, but can not describe them to the partition layer, 
> > because
> > the partition layer generic code does not support that.  When such
> > non-contiguous "logical volumes" are detected, a diagnostic message is
> > printed.
> 
> This very much screams like it should be implemented in the lvm2
> userspace package using the dm kernel driver.

Is lvm2 a generic tool for discovering foreign partition layouts, or it is
about one linux-specific lvm implementation ?

Philippe
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-05-24 Thread Christoph Hellwig
On Tue, May 21, 2013 at 09:27:54AM +0200, Philippe De Muyter wrote:
> AIX LVM permits to make "logical volumes" which are made of multiple slices
> of multiple disks.  The new code allows only access to the "logical volumes"
> which are made of one slice on the probed disk, a slice being a contiguous
> disk area.  The code also detects "logical volumes" made of multiple slices
> on the probed disk, but can not describe them to the partition layer, because
> the partition layer generic code does not support that.  When such
> non-contiguous "logical volumes" are detected, a diagnostic message is
> printed.

This very much screams like it should be implemented in the lvm2
userspace package using the dm kernel driver.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-05-24 Thread Christoph Hellwig
On Tue, May 21, 2013 at 09:27:54AM +0200, Philippe De Muyter wrote:
 AIX LVM permits to make logical volumes which are made of multiple slices
 of multiple disks.  The new code allows only access to the logical volumes
 which are made of one slice on the probed disk, a slice being a contiguous
 disk area.  The code also detects logical volumes made of multiple slices
 on the probed disk, but can not describe them to the partition layer, because
 the partition layer generic code does not support that.  When such
 non-contiguous logical volumes are detected, a diagnostic message is
 printed.

This very much screams like it should be implemented in the lvm2
userspace package using the dm kernel driver.

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-05-24 Thread Philippe De Muyter
On Fri, May 24, 2013 at 06:04:52AM -0400, Christoph Hellwig wrote:
 On Tue, May 21, 2013 at 09:27:54AM +0200, Philippe De Muyter wrote:
  AIX LVM permits to make logical volumes which are made of multiple slices
  of multiple disks.  The new code allows only access to the logical volumes
  which are made of one slice on the probed disk, a slice being a contiguous
  disk area.  The code also detects logical volumes made of multiple slices
  on the probed disk, but can not describe them to the partition layer, 
  because
  the partition layer generic code does not support that.  When such
  non-contiguous logical volumes are detected, a diagnostic message is
  printed.
 
 This very much screams like it should be implemented in the lvm2
 userspace package using the dm kernel driver.

Is lvm2 a generic tool for discovering foreign partition layouts, or it is
about one linux-specific lvm implementation ?

Philippe
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-05-21 Thread Philippe De Muyter
Hi Andrew,

On Mon, May 20, 2013 at 04:39:27PM -0700, Andrew Morton wrote:
> On Mon, 29 Apr 2013 23:18:30 +0200 Philippe De Muyter  wrote:
> 
> > adding partitions/aix.h and partitions/aix.c
> > 
> > Partitions (called Logical Volumes in AIX) can be non-contiguous or
> > even split on more than one disk.  Altough we detect such partitions,
> > we cannot describe them to the Linux partitions layer, so we simply
> > discard them and issue a diagnose message.
> 
> This description is rather hard to follow.
> 
> It appears that the new code permits Linux to access some types of AIX
> partitions, but not other types, correct?  If so, can we please provide
> a more explicit description of which typesw are and are not supported?
> 

AIX LVM permits to make "logical volumes" which are made of multiple slices
of multiple disks.  The new code allows only access to the "logical volumes"
which are made of one slice on the probed disk, a slice being a contiguous
disk area.  The code also detects "logical volumes" made of multiple slices
on the probed disk, but can not describe them to the partition layer, because
the partition layer generic code does not support that.  When such
non-contiguous "logical volumes" are detected, a diagnostic message is
printed.

Philippe

-- 
Philippe De Muyter +32 2 6101532 Macq SA rue de l'Aeronef 2 B-1140 Bruxelles
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-05-21 Thread Philippe De Muyter
Hi Andrew,

On Mon, May 20, 2013 at 04:39:27PM -0700, Andrew Morton wrote:
 On Mon, 29 Apr 2013 23:18:30 +0200 Philippe De Muyter p...@macqel.be wrote:
 
  adding partitions/aix.h and partitions/aix.c
  
  Partitions (called Logical Volumes in AIX) can be non-contiguous or
  even split on more than one disk.  Altough we detect such partitions,
  we cannot describe them to the Linux partitions layer, so we simply
  discard them and issue a diagnose message.
 
 This description is rather hard to follow.
 
 It appears that the new code permits Linux to access some types of AIX
 partitions, but not other types, correct?  If so, can we please provide
 a more explicit description of which typesw are and are not supported?
 

AIX LVM permits to make logical volumes which are made of multiple slices
of multiple disks.  The new code allows only access to the logical volumes
which are made of one slice on the probed disk, a slice being a contiguous
disk area.  The code also detects logical volumes made of multiple slices
on the probed disk, but can not describe them to the partition layer, because
the partition layer generic code does not support that.  When such
non-contiguous logical volumes are detected, a diagnostic message is
printed.

Philippe

-- 
Philippe De Muyter +32 2 6101532 Macq SA rue de l'Aeronef 2 B-1140 Bruxelles
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-05-20 Thread Andrew Morton
On Mon, 29 Apr 2013 23:18:30 +0200 Philippe De Muyter  wrote:

> adding partitions/aix.h and partitions/aix.c
> 
> Partitions (called Logical Volumes in AIX) can be non-contiguous or
> even split on more than one disk.  Altough we detect such partitions,
> we cannot describe them to the Linux partitions layer, so we simply
> discard them and issue a diagnose message.

This description is rather hard to follow.

It appears that the new code permits Linux to access some types of AIX
partitions, but not other types, correct?  If so, can we please provide
a more explicit description of which typesw are and are not supported?


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-05-20 Thread Andrew Morton
On Mon, 29 Apr 2013 23:18:30 +0200 Philippe De Muyter p...@macqel.be wrote:

 adding partitions/aix.h and partitions/aix.c
 
 Partitions (called Logical Volumes in AIX) can be non-contiguous or
 even split on more than one disk.  Altough we detect such partitions,
 we cannot describe them to the Linux partitions layer, so we simply
 discard them and issue a diagnose message.

This description is rather hard to follow.

It appears that the new code permits Linux to access some types of AIX
partitions, but not other types, correct?  If so, can we please provide
a more explicit description of which typesw are and are not supported?


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-30 Thread Philippe De Muyter
On Tue, Apr 30, 2013 at 09:18:40AM +0200, Philippe De Muyter wrote:
> On Tue, Apr 30, 2013 at 09:08:40AM +0200, Philippe De Muyter wrote:
> > On Mon, Apr 29, 2013 at 11:50:51PM +0200, Philippe De Muyter wrote:
> > > On Mon, Apr 29, 2013 at 01:40:41PM +0200, Philippe De Muyter wrote:
> > > > On Mon, Apr 29, 2013 at 11:37:56AM +0200, Karel Zak wrote:
> > > > > 
> > > > > 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.
> > > 
> > > Here is one example.  I'll try to send another one tomorrow.
> > 
> > Here is the other example.
> 
> And here is a third one

And now a fourth one, this one with partitions that are not contiguous.

Philippe

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


aixlvmhdr-136g.bz2
Description: application/bzip


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-30 Thread Philippe De Muyter
On Tue, Apr 30, 2013 at 09:08:40AM +0200, Philippe De Muyter wrote:
> On Mon, Apr 29, 2013 at 11:50:51PM +0200, Philippe De Muyter wrote:
> > On Mon, Apr 29, 2013 at 01:40:41PM +0200, Philippe De Muyter wrote:
> > > On Mon, Apr 29, 2013 at 11:37:56AM +0200, Karel Zak wrote:
> > > > 
> > > > 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.
> > 
> > Here is one example.  I'll try to send another one tomorrow.
> 
> Here is the other example.

And here is a third one

Philippe

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


aixlvmhdr-jori.bz2
Description: application/bzip


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-30 Thread Philippe De Muyter
On Mon, Apr 29, 2013 at 11:50:51PM +0200, Philippe De Muyter wrote:
> On Mon, Apr 29, 2013 at 01:40:41PM +0200, Philippe De Muyter wrote:
> > On Mon, Apr 29, 2013 at 11:37:56AM +0200, Karel Zak wrote:
> > > 
> > > 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.
> 
> Here is one example.  I'll try to send another one tomorrow.

Here is the other example.

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


aixlvmhdr-goofy.bz2
Description: application/bzip


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-30 Thread Philippe De Muyter
On Tue, Apr 30, 2013 at 08:41:52AM +0200, Jens Axboe wrote:
> On Mon, Apr 29 2013, Philippe De Muyter wrote:
> > 
> > so sda is 8,0 and sdb is 8,16
> > 
> > and if, while discovering partitions of /dev/sda, I try to make a
> > partition 16 or higher, it is silently discarded by 'put_partition'.
> > 
> > Is that changed ?
> 
> That's a set limitation of sd, it does not apply to other devices. The
> legacy IDE code used 64 for max partitions, for instance. So Karel is
> right, you should not make any assumptions about the max number of
> partitions, it is driver dependent.

I replaced that by state->limit in the v2 series.

Philippe
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-30 Thread Jens Axboe
On Mon, Apr 29 2013, Philippe De Muyter wrote:
> Hi Karel
> 
> On Mon, Apr 29, 2013 at 02:36:51PM +0200, Karel Zak wrote:
> > On Mon, Apr 29, 2013 at 01:40:41PM +0200, Philippe De Muyter wrote:
> > > > 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.
> > 
> > I don't think it's correct to expect any hardcoded limit. 
> >  
> > The struct parsed_partitions->parts is allocated according to
> > disk_max_parts() where the limit depends on number of minor numbers or
> > it's DISK_MAX_PARTS (=256).
> > 
> > There is no problem to create disk with many partitions:
> > 
> >  # modprobe scsi_debug dev_size_mb=300
> >  # (echo -e 'g\n'; for i in {1..100}; do echo -e "n\n\n\n+1M"; done; \
> > echo -e 'w\nq\n') | fdisk /dev/sdb
> > 
> >  # lsblk -n /dev/sdb | wc -l
> >  101
> 
> how are they named then ?
> 
> on my system (a 2.6.24 kernel which is the last one that support my
> powerpc PReP machine because PReP support got removed with the merge
> of /arch/ppc and /arch/powerpc :( ), I get :
> 
> root:~# ls -l /dev/sd[ab]*
> brw-r- 1 root disk 8,  0 Apr 25 22:22 /dev/sda
> brw-r- 1 root disk 8, 10 Apr 25 22:22 /dev/sda10
> brw-r- 1 root disk 8, 11 Apr 25 22:22 /dev/sda11
> brw-r- 1 root disk 8,  3 Apr 25 22:22 /dev/sda3
> brw-r- 1 root disk 8,  4 Apr 25 22:22 /dev/sda4
> brw-r- 1 root disk 8,  5 Apr 25 22:22 /dev/sda5
> brw-r- 1 root disk 8,  6 Apr 25 22:22 /dev/sda6
> brw-r- 1 root disk 8,  7 Apr 25 22:22 /dev/sda7
> brw-r- 1 root disk 8,  8 Apr 25 22:22 /dev/sda8
> brw-r- 1 root disk 8,  9 Apr 25 22:22 /dev/sda9
> brw-r- 1 root disk 8, 16 Apr 25 22:22 /dev/sdb
> brw-r- 1 root disk 8, 26 Apr 25 22:22 /dev/sdb10
> brw-r- 1 root disk 8, 27 Apr 25 22:22 /dev/sdb11
> brw-r- 1 root disk 8, 19 Apr 25 22:22 /dev/sdb3
> brw-r- 1 root disk 8, 20 Apr 25 22:22 /dev/sdb4
> brw-r- 1 root disk 8, 21 Apr 25 22:22 /dev/sdb5
> brw-r- 1 root disk 8, 22 Apr 25 22:22 /dev/sdb6
> brw-r- 1 root disk 8, 23 Apr 25 22:22 /dev/sdb7
> brw-r- 1 root disk 8, 24 Apr 25 22:22 /dev/sdb8
> brw-r- 1 root disk 8, 25 Apr 25 22:22 /dev/sdb9
> root:~#
> 
> so sda is 8,0 and sdb is 8,16
> 
> and if, while discovering partitions of /dev/sda, I try to make a
> partition 16 or higher, it is silently discarded by 'put_partition'.
> 
> Is that changed ?

That's a set limitation of sd, it does not apply to other devices. The
legacy IDE code used 64 for max partitions, for instance. So Karel is
right, you should not make any assumptions about the max number of
partitions, it is driver dependent.

-- 
Jens Axboe

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-30 Thread Jens Axboe
On Mon, Apr 29 2013, Philippe De Muyter wrote:
 Hi Karel
 
 On Mon, Apr 29, 2013 at 02:36:51PM +0200, Karel Zak wrote:
  On Mon, Apr 29, 2013 at 01:40:41PM +0200, Philippe De Muyter wrote:
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.
  
  I don't think it's correct to expect any hardcoded limit. 
   
  The struct parsed_partitions-parts is allocated according to
  disk_max_parts() where the limit depends on number of minor numbers or
  it's DISK_MAX_PARTS (=256).
  
  There is no problem to create disk with many partitions:
  
   # modprobe scsi_debug dev_size_mb=300
   # (echo -e 'g\n'; for i in {1..100}; do echo -e n\n\n\n+1M; done; \
  echo -e 'w\nq\n') | fdisk /dev/sdb
  
   # lsblk -n /dev/sdb | wc -l
   101
 
 how are they named then ?
 
 on my system (a 2.6.24 kernel which is the last one that support my
 powerpc PReP machine because PReP support got removed with the merge
 of /arch/ppc and /arch/powerpc :( ), I get :
 
 root:~# ls -l /dev/sd[ab]*
 brw-r- 1 root disk 8,  0 Apr 25 22:22 /dev/sda
 brw-r- 1 root disk 8, 10 Apr 25 22:22 /dev/sda10
 brw-r- 1 root disk 8, 11 Apr 25 22:22 /dev/sda11
 brw-r- 1 root disk 8,  3 Apr 25 22:22 /dev/sda3
 brw-r- 1 root disk 8,  4 Apr 25 22:22 /dev/sda4
 brw-r- 1 root disk 8,  5 Apr 25 22:22 /dev/sda5
 brw-r- 1 root disk 8,  6 Apr 25 22:22 /dev/sda6
 brw-r- 1 root disk 8,  7 Apr 25 22:22 /dev/sda7
 brw-r- 1 root disk 8,  8 Apr 25 22:22 /dev/sda8
 brw-r- 1 root disk 8,  9 Apr 25 22:22 /dev/sda9
 brw-r- 1 root disk 8, 16 Apr 25 22:22 /dev/sdb
 brw-r- 1 root disk 8, 26 Apr 25 22:22 /dev/sdb10
 brw-r- 1 root disk 8, 27 Apr 25 22:22 /dev/sdb11
 brw-r- 1 root disk 8, 19 Apr 25 22:22 /dev/sdb3
 brw-r- 1 root disk 8, 20 Apr 25 22:22 /dev/sdb4
 brw-r- 1 root disk 8, 21 Apr 25 22:22 /dev/sdb5
 brw-r- 1 root disk 8, 22 Apr 25 22:22 /dev/sdb6
 brw-r- 1 root disk 8, 23 Apr 25 22:22 /dev/sdb7
 brw-r- 1 root disk 8, 24 Apr 25 22:22 /dev/sdb8
 brw-r- 1 root disk 8, 25 Apr 25 22:22 /dev/sdb9
 root:~#
 
 so sda is 8,0 and sdb is 8,16
 
 and if, while discovering partitions of /dev/sda, I try to make a
 partition 16 or higher, it is silently discarded by 'put_partition'.
 
 Is that changed ?

That's a set limitation of sd, it does not apply to other devices. The
legacy IDE code used 64 for max partitions, for instance. So Karel is
right, you should not make any assumptions about the max number of
partitions, it is driver dependent.

-- 
Jens Axboe

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-30 Thread Philippe De Muyter
On Tue, Apr 30, 2013 at 08:41:52AM +0200, Jens Axboe wrote:
 On Mon, Apr 29 2013, Philippe De Muyter wrote:
  
  so sda is 8,0 and sdb is 8,16
  
  and if, while discovering partitions of /dev/sda, I try to make a
  partition 16 or higher, it is silently discarded by 'put_partition'.
  
  Is that changed ?
 
 That's a set limitation of sd, it does not apply to other devices. The
 legacy IDE code used 64 for max partitions, for instance. So Karel is
 right, you should not make any assumptions about the max number of
 partitions, it is driver dependent.

I replaced that by state-limit in the v2 series.

Philippe
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-30 Thread Philippe De Muyter
On Mon, Apr 29, 2013 at 11:50:51PM +0200, Philippe De Muyter wrote:
 On Mon, Apr 29, 2013 at 01:40:41PM +0200, Philippe De Muyter wrote:
  On Mon, Apr 29, 2013 at 11:37:56AM +0200, Karel Zak wrote:
   
   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.
 
 Here is one example.  I'll try to send another one tomorrow.

Here is the other example.

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


aixlvmhdr-goofy.bz2
Description: application/bzip


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-30 Thread Philippe De Muyter
On Tue, Apr 30, 2013 at 09:08:40AM +0200, Philippe De Muyter wrote:
 On Mon, Apr 29, 2013 at 11:50:51PM +0200, Philippe De Muyter wrote:
  On Mon, Apr 29, 2013 at 01:40:41PM +0200, Philippe De Muyter wrote:
   On Mon, Apr 29, 2013 at 11:37:56AM +0200, Karel Zak wrote:

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.
  
  Here is one example.  I'll try to send another one tomorrow.
 
 Here is the other example.

And here is a third one

Philippe

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


aixlvmhdr-jori.bz2
Description: application/bzip


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-30 Thread Philippe De Muyter
On Tue, Apr 30, 2013 at 09:18:40AM +0200, Philippe De Muyter wrote:
 On Tue, Apr 30, 2013 at 09:08:40AM +0200, Philippe De Muyter wrote:
  On Mon, Apr 29, 2013 at 11:50:51PM +0200, Philippe De Muyter wrote:
   On Mon, Apr 29, 2013 at 01:40:41PM +0200, Philippe De Muyter wrote:
On Mon, Apr 29, 2013 at 11:37:56AM +0200, Karel Zak wrote:
 
 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.
   
   Here is one example.  I'll try to send another one tomorrow.
  
  Here is the other example.
 
 And here is a third one

And now a fourth one, this one with partitions that are not contiguous.

Philippe

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


aixlvmhdr-136g.bz2
Description: application/bzip


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-29 Thread Philippe De Muyter
On Mon, Apr 29, 2013 at 01:40:41PM +0200, Philippe De Muyter wrote:
> On Mon, Apr 29, 2013 at 11:37:56AM +0200, Karel Zak wrote:
> > 
> > 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.

Here is one example.  I'll try to send another one tomorrow.

Philippe


aixlvmhdr-128g.bz2
Description: application/bzip


[PATCH 2/5] Add aix lvm partitions support files

2013-04-29 Thread Philippe De Muyter
adding partitions/aix.h and partitions/aix.c

Partitions (called Logical Volumes in AIX) can be non-contiguous or
even split on more than one disk.  Altough we detect such partitions,
we cannot describe them to the Linux partitions layer, so we simply
discard them and issue a diagnose message.

Signed-off-by: Philippe De Muyter 
Cc: Karel Zak 
Cc: Jens Axboe 
Cc: Andrew Morton 
---
 block/partitions/aix.c |  290 
 block/partitions/aix.h |1 +
 2 files changed, 291 insertions(+), 0 deletions(-)
 create mode 100644 block/partitions/aix.c
 create mode 100644 block/partitions/aix.h

diff --git a/block/partitions/aix.c b/block/partitions/aix.c
new file mode 100644
index 000..b3288d2
--- /dev/null
+++ b/block/partitions/aix.c
@@ -0,0 +1,290 @@
+/*
+ *  fs/partitions/aix.c
+ *
+ *  Copyright (C) 2012-2013 Philippe De Muyter 
+ */
+
+#include "check.h"
+#include "aix.h"
+
+struct lvm_rec {
+   char lvm_id[4]; /* "_LVM" */
+   char reserved4[16];
+   __be32 lvmarea_len;
+   __be32 vgda_len;
+   __be32 vgda_psn[2];
+   char reserved36[10];
+   __be16 pp_size; /* log2(pp_size) */
+   char reserved46[12];
+   __be16 version;
+   };
+
+struct vgda {
+   __be32 secs;
+   __be32 usec;
+   char reserved8[16];
+   __be16 numlvs;
+   __be16 maxlvs;
+   __be16 pp_size;
+   __be16 numpvs;
+   __be16 total_vgdas;
+   __be16 vgda_size;
+   };
+
+struct lvd {
+   __be16 lv_ix;
+   __be16 res2;
+   __be16 res4;
+   __be16 maxsize;
+   __be16 lv_state;
+   __be16 mirror;
+   __be16 mirror_policy;
+   __be16 num_lps;
+   __be16 res10[8];
+   };
+
+struct lvname {
+   char name[64];
+   };
+
+struct ppe {
+   __be16 lv_ix;
+   unsigned short res2;
+   unsigned short res4;
+   __be16 lp_ix;
+   unsigned short res8[12];
+   };
+
+struct pvd {
+   char reserved0[16];
+   __be16 pp_count;
+   char reserved18[2];
+   __be32 psn_part1;
+   char reserved24[8];
+   struct ppe ppe[1016];
+   };
+
+#define LVM_MAXLVS 256
+
+/**
+ * last_lba(): return number of last logical block of device
+ * @bdev: block device
+ *
+ * Description: Returns last LBA value on success, 0 on error.
+ * This is stored (by sd and ide-geometry) in
+ *  the part[0] entry for this disk, and is the number of
+ *  physical sectors available on the disk.
+ */
+static u64 last_lba(struct block_device *bdev)
+{
+   if (!bdev || !bdev->bd_inode)
+   return 0;
+   return (bdev->bd_inode->i_size >> 9) - 1ULL;
+}
+
+/**
+ * read_lba(): Read bytes from disk, starting at given LBA
+ * @state
+ * @lba
+ * @buffer
+ * @count
+ *
+ * Description:  Reads @count bytes from @state->bdev into @buffer.
+ * Returns number of bytes read on success, 0 on error.
+ */
+static size_t read_lba(struct parsed_partitions *state, u64 lba, u8 * buffer, 
size_t count)
+{
+   size_t totalreadcount = 0;
+
+   if (!buffer || lba + count / 512 > last_lba(state->bdev))
+return 0;
+
+   while (count) {
+   int copied = 512;
+   Sector sect;
+   unsigned char *data = read_part_sector(state, lba++, );
+   if (!data)
+   break;
+   if (copied > count)
+   copied = count;
+   memcpy(buffer, data, copied);
+   put_dev_sector(sect);
+   buffer += copied;
+   totalreadcount +=copied;
+   count -= copied;
+   }
+   return totalreadcount;
+}
+
+/**
+ * alloc_pvd(): reads physical volume descriptor
+ * @state
+ * @lba
+ *
+ * Description: Returns pvd on success,  NULL on error.
+ * Allocates space for pvd and fill it with disk blocks at @lba
+ * Notes: remember to free pvd when you're done!
+ */
+static struct pvd *alloc_pvd(struct parsed_partitions *state, u32 lba)
+{
+   size_t count = sizeof(struct pvd);
+   struct pvd *p;
+
+   p = kmalloc(count, GFP_KERNEL);
+   if (!p)
+   return NULL;
+
+   if (read_lba(state, lba, (u8 *) p, count) < count) {
+   kfree(p);
+   return NULL;
+   }
+   return p;
+}
+
+/**
+ * alloc_lvn(): reads logical volume names
+ * @state
+ * @lba
+ *
+ * Description: Returns lvn on success,  NULL on error.
+ * Allocates space for lvn and fill it with disk blocks at @lba
+ * Notes: remember to free lvn when you're done!
+ */
+static struct lvname *alloc_lvn(struct parsed_partitions *state, u32 lba)
+{
+   size_t count = sizeof(struct lvname) * LVM_MAXLVS;
+   struct lvname *p;
+
+   p = kmalloc(count, GFP_KERNEL);
+   if (!p)
+   return NULL;
+
+   if (read_lba(state, lba, (u8 *) p, count) < count) {
+   kfree(p);
+   return NULL;
+   }
+   return p;
+}
+
+int aix_partition(struct parsed_partitions *state)
+{
+   int 

Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-29 Thread Philippe De Muyter
Hi Karel

On Mon, Apr 29, 2013 at 02:36:51PM +0200, Karel Zak wrote:
> On Mon, Apr 29, 2013 at 01:40:41PM +0200, Philippe De Muyter wrote:
> > > 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.
> 
> I don't think it's correct to expect any hardcoded limit. 
>  
> The struct parsed_partitions->parts is allocated according to
> disk_max_parts() where the limit depends on number of minor numbers or
> it's DISK_MAX_PARTS (=256).
> 
> There is no problem to create disk with many partitions:
> 
>  # modprobe scsi_debug dev_size_mb=300
>  # (echo -e 'g\n'; for i in {1..100}; do echo -e "n\n\n\n+1M"; done; \
> echo -e 'w\nq\n') | fdisk /dev/sdb
> 
>  # lsblk -n /dev/sdb | wc -l
>  101

how are they named then ?

on my system (a 2.6.24 kernel which is the last one that support my
powerpc PReP machine because PReP support got removed with the merge
of /arch/ppc and /arch/powerpc :( ), I get :

root:~# ls -l /dev/sd[ab]*
brw-r- 1 root disk 8,  0 Apr 25 22:22 /dev/sda
brw-r- 1 root disk 8, 10 Apr 25 22:22 /dev/sda10
brw-r- 1 root disk 8, 11 Apr 25 22:22 /dev/sda11
brw-r- 1 root disk 8,  3 Apr 25 22:22 /dev/sda3
brw-r- 1 root disk 8,  4 Apr 25 22:22 /dev/sda4
brw-r- 1 root disk 8,  5 Apr 25 22:22 /dev/sda5
brw-r- 1 root disk 8,  6 Apr 25 22:22 /dev/sda6
brw-r- 1 root disk 8,  7 Apr 25 22:22 /dev/sda7
brw-r- 1 root disk 8,  8 Apr 25 22:22 /dev/sda8
brw-r- 1 root disk 8,  9 Apr 25 22:22 /dev/sda9
brw-r- 1 root disk 8, 16 Apr 25 22:22 /dev/sdb
brw-r- 1 root disk 8, 26 Apr 25 22:22 /dev/sdb10
brw-r- 1 root disk 8, 27 Apr 25 22:22 /dev/sdb11
brw-r- 1 root disk 8, 19 Apr 25 22:22 /dev/sdb3
brw-r- 1 root disk 8, 20 Apr 25 22:22 /dev/sdb4
brw-r- 1 root disk 8, 21 Apr 25 22:22 /dev/sdb5
brw-r- 1 root disk 8, 22 Apr 25 22:22 /dev/sdb6
brw-r- 1 root disk 8, 23 Apr 25 22:22 /dev/sdb7
brw-r- 1 root disk 8, 24 Apr 25 22:22 /dev/sdb8
brw-r- 1 root disk 8, 25 Apr 25 22:22 /dev/sdb9
root:~#

so sda is 8,0 and sdb is 8,16

and if, while discovering partitions of /dev/sda, I try to make a
partition 16 or higher, it is silently discarded by 'put_partition'.

Is that changed ?

Philippe

-- 
Philippe De Muyter +32 2 6101532 Macq SA rue de l'Aeronef 2 B-1140 Bruxelles
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-29 Thread Karel Zak
On Mon, Apr 29, 2013 at 01:40:41PM +0200, Philippe De Muyter wrote:
> > 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.

I don't think it's correct to expect any hardcoded limit. 
 
The struct parsed_partitions->parts is allocated according to
disk_max_parts() where the limit depends on number of minor numbers or
it's DISK_MAX_PARTS (=256).

There is no problem to create disk with many partitions:

 # modprobe scsi_debug dev_size_mb=300
 # (echo -e 'g\n'; for i in {1..100}; do echo -e "n\n\n\n+1M"; done; \
echo -e 'w\nq\n') | fdisk /dev/sdb

 # lsblk -n /dev/sdb | wc -l
 101

 Note it's fdisk with GPT support.

> > 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.

 Cool!

Karel

-- 
 Karel Zak  
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-29 Thread Philippe De Muyter
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, );
> > +   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, ))) {
> > +   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

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), " 

Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-29 Thread Karel Zak
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", 

Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-29 Thread Karel Zak
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, 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.

 + 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
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 

Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-29 Thread Philippe De Muyter
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;
  +  

Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-29 Thread Karel Zak
On Mon, Apr 29, 2013 at 01:40:41PM +0200, Philippe De Muyter wrote:
  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.

I don't think it's correct to expect any hardcoded limit. 
 
The struct parsed_partitions-parts is allocated according to
disk_max_parts() where the limit depends on number of minor numbers or
it's DISK_MAX_PARTS (=256).

There is no problem to create disk with many partitions:

 # modprobe scsi_debug dev_size_mb=300
 # (echo -e 'g\n'; for i in {1..100}; do echo -e n\n\n\n+1M; done; \
echo -e 'w\nq\n') | fdisk /dev/sdb

 # lsblk -n /dev/sdb | wc -l
 101

 Note it's fdisk with GPT support.

  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.

 Cool!

Karel

-- 
 Karel Zak  k...@redhat.com
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-29 Thread Philippe De Muyter
Hi Karel

On Mon, Apr 29, 2013 at 02:36:51PM +0200, Karel Zak wrote:
 On Mon, Apr 29, 2013 at 01:40:41PM +0200, Philippe De Muyter wrote:
   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.
 
 I don't think it's correct to expect any hardcoded limit. 
  
 The struct parsed_partitions-parts is allocated according to
 disk_max_parts() where the limit depends on number of minor numbers or
 it's DISK_MAX_PARTS (=256).
 
 There is no problem to create disk with many partitions:
 
  # modprobe scsi_debug dev_size_mb=300
  # (echo -e 'g\n'; for i in {1..100}; do echo -e n\n\n\n+1M; done; \
 echo -e 'w\nq\n') | fdisk /dev/sdb
 
  # lsblk -n /dev/sdb | wc -l
  101

how are they named then ?

on my system (a 2.6.24 kernel which is the last one that support my
powerpc PReP machine because PReP support got removed with the merge
of /arch/ppc and /arch/powerpc :( ), I get :

root:~# ls -l /dev/sd[ab]*
brw-r- 1 root disk 8,  0 Apr 25 22:22 /dev/sda
brw-r- 1 root disk 8, 10 Apr 25 22:22 /dev/sda10
brw-r- 1 root disk 8, 11 Apr 25 22:22 /dev/sda11
brw-r- 1 root disk 8,  3 Apr 25 22:22 /dev/sda3
brw-r- 1 root disk 8,  4 Apr 25 22:22 /dev/sda4
brw-r- 1 root disk 8,  5 Apr 25 22:22 /dev/sda5
brw-r- 1 root disk 8,  6 Apr 25 22:22 /dev/sda6
brw-r- 1 root disk 8,  7 Apr 25 22:22 /dev/sda7
brw-r- 1 root disk 8,  8 Apr 25 22:22 /dev/sda8
brw-r- 1 root disk 8,  9 Apr 25 22:22 /dev/sda9
brw-r- 1 root disk 8, 16 Apr 25 22:22 /dev/sdb
brw-r- 1 root disk 8, 26 Apr 25 22:22 /dev/sdb10
brw-r- 1 root disk 8, 27 Apr 25 22:22 /dev/sdb11
brw-r- 1 root disk 8, 19 Apr 25 22:22 /dev/sdb3
brw-r- 1 root disk 8, 20 Apr 25 22:22 /dev/sdb4
brw-r- 1 root disk 8, 21 Apr 25 22:22 /dev/sdb5
brw-r- 1 root disk 8, 22 Apr 25 22:22 /dev/sdb6
brw-r- 1 root disk 8, 23 Apr 25 22:22 /dev/sdb7
brw-r- 1 root disk 8, 24 Apr 25 22:22 /dev/sdb8
brw-r- 1 root disk 8, 25 Apr 25 22:22 /dev/sdb9
root:~#

so sda is 8,0 and sdb is 8,16

and if, while discovering partitions of /dev/sda, I try to make a
partition 16 or higher, it is silently discarded by 'put_partition'.

Is that changed ?

Philippe

-- 
Philippe De Muyter +32 2 6101532 Macq SA rue de l'Aeronef 2 B-1140 Bruxelles
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/5] Add aix lvm partitions support files

2013-04-29 Thread Philippe De Muyter
adding partitions/aix.h and partitions/aix.c

Partitions (called Logical Volumes in AIX) can be non-contiguous or
even split on more than one disk.  Altough we detect such partitions,
we cannot describe them to the Linux partitions layer, so we simply
discard them and issue a diagnose message.

Signed-off-by: Philippe De Muyter p...@macqel.be
Cc: Karel Zak k...@redhat.com
Cc: Jens Axboe ax...@kernel.dk
Cc: Andrew Morton a...@linux-foundation.org
---
 block/partitions/aix.c |  290 
 block/partitions/aix.h |1 +
 2 files changed, 291 insertions(+), 0 deletions(-)
 create mode 100644 block/partitions/aix.c
 create mode 100644 block/partitions/aix.h

diff --git a/block/partitions/aix.c b/block/partitions/aix.c
new file mode 100644
index 000..b3288d2
--- /dev/null
+++ b/block/partitions/aix.c
@@ -0,0 +1,290 @@
+/*
+ *  fs/partitions/aix.c
+ *
+ *  Copyright (C) 2012-2013 Philippe De Muyter p...@macqel.be
+ */
+
+#include check.h
+#include aix.h
+
+struct lvm_rec {
+   char lvm_id[4]; /* _LVM */
+   char reserved4[16];
+   __be32 lvmarea_len;
+   __be32 vgda_len;
+   __be32 vgda_psn[2];
+   char reserved36[10];
+   __be16 pp_size; /* log2(pp_size) */
+   char reserved46[12];
+   __be16 version;
+   };
+
+struct vgda {
+   __be32 secs;
+   __be32 usec;
+   char reserved8[16];
+   __be16 numlvs;
+   __be16 maxlvs;
+   __be16 pp_size;
+   __be16 numpvs;
+   __be16 total_vgdas;
+   __be16 vgda_size;
+   };
+
+struct lvd {
+   __be16 lv_ix;
+   __be16 res2;
+   __be16 res4;
+   __be16 maxsize;
+   __be16 lv_state;
+   __be16 mirror;
+   __be16 mirror_policy;
+   __be16 num_lps;
+   __be16 res10[8];
+   };
+
+struct lvname {
+   char name[64];
+   };
+
+struct ppe {
+   __be16 lv_ix;
+   unsigned short res2;
+   unsigned short res4;
+   __be16 lp_ix;
+   unsigned short res8[12];
+   };
+
+struct pvd {
+   char reserved0[16];
+   __be16 pp_count;
+   char reserved18[2];
+   __be32 psn_part1;
+   char reserved24[8];
+   struct ppe ppe[1016];
+   };
+
+#define LVM_MAXLVS 256
+
+/**
+ * last_lba(): return number of last logical block of device
+ * @bdev: block device
+ *
+ * Description: Returns last LBA value on success, 0 on error.
+ * This is stored (by sd and ide-geometry) in
+ *  the part[0] entry for this disk, and is the number of
+ *  physical sectors available on the disk.
+ */
+static u64 last_lba(struct block_device *bdev)
+{
+   if (!bdev || !bdev-bd_inode)
+   return 0;
+   return (bdev-bd_inode-i_size  9) - 1ULL;
+}
+
+/**
+ * read_lba(): Read bytes from disk, starting at given LBA
+ * @state
+ * @lba
+ * @buffer
+ * @count
+ *
+ * Description:  Reads @count bytes from @state-bdev into @buffer.
+ * Returns number of bytes read on success, 0 on error.
+ */
+static size_t read_lba(struct parsed_partitions *state, u64 lba, u8 * buffer, 
size_t count)
+{
+   size_t totalreadcount = 0;
+
+   if (!buffer || lba + count / 512  last_lba(state-bdev))
+return 0;
+
+   while (count) {
+   int copied = 512;
+   Sector sect;
+   unsigned char *data = read_part_sector(state, lba++, sect);
+   if (!data)
+   break;
+   if (copied  count)
+   copied = count;
+   memcpy(buffer, data, copied);
+   put_dev_sector(sect);
+   buffer += copied;
+   totalreadcount +=copied;
+   count -= copied;
+   }
+   return totalreadcount;
+}
+
+/**
+ * alloc_pvd(): reads physical volume descriptor
+ * @state
+ * @lba
+ *
+ * Description: Returns pvd on success,  NULL on error.
+ * Allocates space for pvd and fill it with disk blocks at @lba
+ * Notes: remember to free pvd when you're done!
+ */
+static struct pvd *alloc_pvd(struct parsed_partitions *state, u32 lba)
+{
+   size_t count = sizeof(struct pvd);
+   struct pvd *p;
+
+   p = kmalloc(count, GFP_KERNEL);
+   if (!p)
+   return NULL;
+
+   if (read_lba(state, lba, (u8 *) p, count)  count) {
+   kfree(p);
+   return NULL;
+   }
+   return p;
+}
+
+/**
+ * alloc_lvn(): reads logical volume names
+ * @state
+ * @lba
+ *
+ * Description: Returns lvn on success,  NULL on error.
+ * Allocates space for lvn and fill it with disk blocks at @lba
+ * Notes: remember to free lvn when you're done!
+ */
+static struct lvname *alloc_lvn(struct parsed_partitions *state, u32 lba)
+{
+   size_t count = sizeof(struct lvname) * LVM_MAXLVS;
+   struct lvname *p;
+
+   p = kmalloc(count, GFP_KERNEL);
+   if (!p)
+   return NULL;
+
+   if (read_lba(state, lba, (u8 *) p, count)  count) {
+   kfree(p);
+   return NULL;
+   }
+   return p;

Re: [PATCH 2/5] Add aix lvm partitions support files

2013-04-29 Thread Philippe De Muyter
On Mon, Apr 29, 2013 at 01:40:41PM +0200, Philippe De Muyter wrote:
 On Mon, Apr 29, 2013 at 11:37:56AM +0200, Karel Zak wrote:
  
  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.

Here is one example.  I'll try to send another one tomorrow.

Philippe


aixlvmhdr-128g.bz2
Description: application/bzip


[PATCH 2/5] Add aix lvm partitions support files

2013-04-25 Thread Philippe De Muyter
adding partitions/aix.h and partitions/aix.c

Partitions (called Logical Volumes in AIX) can be non-contiguous or
even split on more than one disk.  Altough we detect such partitions,
we cannot describe them to the Linux partitions layer, so we simply
discard them and issue a diagnose message.

Signed-off-by: Philippe De Muyter 
Cc: Jens Axboe 
---
 block/partitions/aix.c |  279 
 block/partitions/aix.h |1 +
 2 files changed, 280 insertions(+), 0 deletions(-)
 create mode 100644 block/partitions/aix.c
 create mode 100644 block/partitions/aix.h

diff --git a/block/partitions/aix.c b/block/partitions/aix.c
new file mode 100644
index 000..c4c72ed
--- /dev/null
+++ b/block/partitions/aix.c
@@ -0,0 +1,279 @@
+/*
+ *  fs/partitions/aix.c
+ *
+ *  Copyright (C) 2012-2013 Philippe De Muyter 
+ */
+
+#include "check.h"
+#include "aix.h"
+
+struct lvm_rec {
+   char lvm_id[4]; /* "_LVM" */
+   char reserved4[16];
+   __be32 lvmarea_len;
+   __be32 vgda_len;
+   __be32 vgda_psn[2];
+   char reserved36[10];
+   __be16 pp_size; /* log2(pp_size) */
+   char reserved46[12];
+   __be16 version;
+   };
+
+struct vgda {
+   __be32 secs;
+   __be32 usec;
+   char reserved8[16];
+   __be16 numlvs;
+   __be16 maxlvs;
+   __be16 pp_size;
+   __be16 numpvs;
+   __be16 total_vgdas;
+   __be16 vgda_size;
+   };
+
+struct lvd {
+   __be16 lv_ix;
+   __be16 res2;
+   __be16 res4;
+   __be16 maxsize;
+   __be16 lv_state;
+   __be16 mirror;
+   __be16 mirror_policy;
+   __be16 num_lps;
+   __be16 res10[8];
+   };
+
+struct lvname {
+   char name[64];
+   };
+
+struct ppe {
+   __be16 lv_ix;
+   unsigned short res2;
+   unsigned short res4;
+   __be16 lp_ix;
+   unsigned short res8[12];
+   };
+
+struct pvd {
+   char reserved0[16];
+   __be16 pp_count;
+   char reserved18[2];
+   __be32 psn_part1;
+   char reserved24[8];
+   struct ppe ppe[1016];
+   };
+
+/**
+ * last_lba(): return number of last logical block of device
+ * @bdev: block device
+ *
+ * Description: Returns last LBA value on success, 0 on error.
+ * This is stored (by sd and ide-geometry) in
+ *  the part[0] entry for this disk, and is the number of
+ *  physical sectors available on the disk.
+ */
+static u64 last_lba(struct block_device *bdev)
+{
+   if (!bdev || !bdev->bd_inode)
+   return 0;
+   return (bdev->bd_inode->i_size >> 9) - 1ULL;
+}
+
+/**
+ * read_lba(): Read bytes from disk, starting at given LBA
+ * @state
+ * @lba
+ * @buffer
+ * @count
+ *
+ * Description:  Reads @count bytes from @state->bdev into @buffer.
+ * Returns number of bytes read on success, 0 on error.
+ */
+static size_t read_lba(struct parsed_partitions *state, u64 lba, u8 * buffer, 
size_t count)
+{
+   size_t totalreadcount = 0;
+
+   if (!buffer || lba + count / 512 > last_lba(state->bdev))
+return 0;
+
+   while (count) {
+   int copied = 512;
+   Sector sect;
+   unsigned char *data = read_part_sector(state, lba++, );
+   if (!data)
+   break;
+   if (copied > count)
+   copied = count;
+   memcpy(buffer, data, copied);
+   put_dev_sector(sect);
+   buffer += copied;
+   totalreadcount +=copied;
+   count -= copied;
+   }
+   return totalreadcount;
+}
+
+/**
+ * alloc_pvd(): reads physical volume descriptor
+ * @state
+ * @lba
+ *
+ * Description: Returns pvd on success,  NULL on error.
+ * Allocates space for pvd and fill it with disk blocks at @lba
+ * Notes: remember to free pvd when you're done!
+ */
+static struct pvd *alloc_pvd(struct parsed_partitions *state, u32 lba)
+{
+   size_t count = sizeof(struct pvd);
+   struct pvd *p;
+
+   p = kzalloc(count, GFP_KERNEL);
+   if (!p)
+   return NULL;
+
+   if (read_lba(state, lba, (u8 *) p, count) < count) {
+   kfree(p);
+   return NULL;
+   }
+   return p;
+}
+
+/**
+ * alloc_lvn(): reads logical volume names
+ * @state
+ * @lba
+ *
+ * Description: Returns lvn on success,  NULL on error.
+ * Allocates space for lvn and fill it with disk blocks at @lba
+ * Notes: remember to free lvn when you're done!
+ */
+static struct lvname *alloc_lvn(struct parsed_partitions *state, u32 lba)
+{
+   size_t count = sizeof(struct lvname) * 256;
+   struct lvname *p;
+
+   p = kzalloc(count, GFP_KERNEL);
+   if (!p)
+   return NULL;
+
+   if (read_lba(state, lba, (u8 *) p, count) < count) {
+   kfree(p);
+   return NULL;
+   }
+   return p;
+}
+
+int aix_partition(struct parsed_partitions *state)
+{
+   int ret = 0;
+   Sector sect;
+   unsigned char *d;
+   

[PATCH 2/5] Add aix lvm partitions support files

2013-04-25 Thread Philippe De Muyter
adding partitions/aix.h and partitions/aix.c

Partitions (called Logical Volumes in AIX) can be non-contiguous or
even split on more than one disk.  Altough we detect such partitions,
we cannot describe them to the Linux partitions layer, so we simply
discard them and issue a diagnose message.

Signed-off-by: Philippe De Muyter p...@macqel.be
Cc: Jens Axboe ax...@kernel.dk
---
 block/partitions/aix.c |  279 
 block/partitions/aix.h |1 +
 2 files changed, 280 insertions(+), 0 deletions(-)
 create mode 100644 block/partitions/aix.c
 create mode 100644 block/partitions/aix.h

diff --git a/block/partitions/aix.c b/block/partitions/aix.c
new file mode 100644
index 000..c4c72ed
--- /dev/null
+++ b/block/partitions/aix.c
@@ -0,0 +1,279 @@
+/*
+ *  fs/partitions/aix.c
+ *
+ *  Copyright (C) 2012-2013 Philippe De Muyter p...@macqel.be
+ */
+
+#include check.h
+#include aix.h
+
+struct lvm_rec {
+   char lvm_id[4]; /* _LVM */
+   char reserved4[16];
+   __be32 lvmarea_len;
+   __be32 vgda_len;
+   __be32 vgda_psn[2];
+   char reserved36[10];
+   __be16 pp_size; /* log2(pp_size) */
+   char reserved46[12];
+   __be16 version;
+   };
+
+struct vgda {
+   __be32 secs;
+   __be32 usec;
+   char reserved8[16];
+   __be16 numlvs;
+   __be16 maxlvs;
+   __be16 pp_size;
+   __be16 numpvs;
+   __be16 total_vgdas;
+   __be16 vgda_size;
+   };
+
+struct lvd {
+   __be16 lv_ix;
+   __be16 res2;
+   __be16 res4;
+   __be16 maxsize;
+   __be16 lv_state;
+   __be16 mirror;
+   __be16 mirror_policy;
+   __be16 num_lps;
+   __be16 res10[8];
+   };
+
+struct lvname {
+   char name[64];
+   };
+
+struct ppe {
+   __be16 lv_ix;
+   unsigned short res2;
+   unsigned short res4;
+   __be16 lp_ix;
+   unsigned short res8[12];
+   };
+
+struct pvd {
+   char reserved0[16];
+   __be16 pp_count;
+   char reserved18[2];
+   __be32 psn_part1;
+   char reserved24[8];
+   struct ppe ppe[1016];
+   };
+
+/**
+ * last_lba(): return number of last logical block of device
+ * @bdev: block device
+ *
+ * Description: Returns last LBA value on success, 0 on error.
+ * This is stored (by sd and ide-geometry) in
+ *  the part[0] entry for this disk, and is the number of
+ *  physical sectors available on the disk.
+ */
+static u64 last_lba(struct block_device *bdev)
+{
+   if (!bdev || !bdev-bd_inode)
+   return 0;
+   return (bdev-bd_inode-i_size  9) - 1ULL;
+}
+
+/**
+ * read_lba(): Read bytes from disk, starting at given LBA
+ * @state
+ * @lba
+ * @buffer
+ * @count
+ *
+ * Description:  Reads @count bytes from @state-bdev into @buffer.
+ * Returns number of bytes read on success, 0 on error.
+ */
+static size_t read_lba(struct parsed_partitions *state, u64 lba, u8 * buffer, 
size_t count)
+{
+   size_t totalreadcount = 0;
+
+   if (!buffer || lba + count / 512  last_lba(state-bdev))
+return 0;
+
+   while (count) {
+   int copied = 512;
+   Sector sect;
+   unsigned char *data = read_part_sector(state, lba++, sect);
+   if (!data)
+   break;
+   if (copied  count)
+   copied = count;
+   memcpy(buffer, data, copied);
+   put_dev_sector(sect);
+   buffer += copied;
+   totalreadcount +=copied;
+   count -= copied;
+   }
+   return totalreadcount;
+}
+
+/**
+ * alloc_pvd(): reads physical volume descriptor
+ * @state
+ * @lba
+ *
+ * Description: Returns pvd on success,  NULL on error.
+ * Allocates space for pvd and fill it with disk blocks at @lba
+ * Notes: remember to free pvd when you're done!
+ */
+static struct pvd *alloc_pvd(struct parsed_partitions *state, u32 lba)
+{
+   size_t count = sizeof(struct pvd);
+   struct pvd *p;
+
+   p = kzalloc(count, GFP_KERNEL);
+   if (!p)
+   return NULL;
+
+   if (read_lba(state, lba, (u8 *) p, count)  count) {
+   kfree(p);
+   return NULL;
+   }
+   return p;
+}
+
+/**
+ * alloc_lvn(): reads logical volume names
+ * @state
+ * @lba
+ *
+ * Description: Returns lvn on success,  NULL on error.
+ * Allocates space for lvn and fill it with disk blocks at @lba
+ * Notes: remember to free lvn when you're done!
+ */
+static struct lvname *alloc_lvn(struct parsed_partitions *state, u32 lba)
+{
+   size_t count = sizeof(struct lvname) * 256;
+   struct lvname *p;
+
+   p = kzalloc(count, GFP_KERNEL);
+   if (!p)
+   return NULL;
+
+   if (read_lba(state, lba, (u8 *) p, count)  count) {
+   kfree(p);
+   return NULL;
+   }
+   return p;
+}
+
+int aix_partition(struct parsed_partitions *state)
+{
+   int ret = 0;
+   Sector sect;
+