PATCH] scsi_debug: Fix endianess in partition table

2013-04-26 Thread Martin Peschke
James,
could you pick up this fix, preferably for 3.10, please?

I am not the only one you has run into the issue:
https://nazar.karan.org/blob/distro!
parted.git/8780c767126938173f49dfbcd4360813932f7756/SOURCES!
disable-t9020.patch

Thanks,
Martin




Both start_sect and nr_sects in struct partition are __le32 and
require cpu_to_le32() on assignment.

Without this fix tools like fdisk show an invalid partition table
for SCSI devices emulated by scsi_debug on big-endian architectures,
like s390x. Besides a kernel message like this was emitted:

sda: p1 start 536870912 is beyond EOD, enabling native capacity
sda: p1 start 536870912 is beyond EOD, truncated

For verification 'xxd -l 512 /dev/sda' has been used to make sure
that this fix makes scsi_debug generated partition tables on s390x
look like the ones generated on my laptop.

Signed-off-by: Martin Peschke mpesc...@linux.vnet.ibm.com
Reviewed-by: Steffen Maier ma...@linux.vnet.ibm.com
Acked-by: Douglas Gilbert dgilb...@interlog.com

---
 drivers/scsi/scsi_debug.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -2662,8 +2662,8 @@ static void __init sdebug_build_parts(un
   / sdebug_sectors_per;
pp-end_sector = (end_sec % sdebug_sectors_per) + 1;
 
-   pp-start_sect = start_sec;
-   pp-nr_sects = end_sec - start_sec + 1;
+   pp-start_sect = cpu_to_le32(start_sec);
+   pp-nr_sects = cpu_to_le32(end_sec - start_sec + 1);
pp-sys_ind = 0x83; /* plain Linux partition */
}
 }


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


[PATCH] scsi_debug: Fix endianess in partition table

2013-02-15 Thread Martin Peschke
James,
could you pick up this fix, please?

Btw., it looks like others where bitten by this one:
https://nazar.karan.org/blob/distro!
parted.git/8780c767126938173f49dfbcd4360813932f7756/SOURCES!
disable-t9020.patch

Thanks,
Martin





Both start_sect and nr_sects in struct partition are __le32 and
require cpu_to_le32() on assignment.

Without this fix tools like fdisk show an invalid partition table
for SCSI devices emulated by scsi_debug on big-endian architectures,
like s390x. Besides a kernel message like this was emitted:

sda: p1 start 536870912 is beyond EOD, enabling native capacity
sda: p1 start 536870912 is beyond EOD, truncated

For verification 'xxd -l 512 /dev/sda' has been used to make sure
that this fix makes scsi_debug generated partition tables on s390x
look like the ones generated on my laptop.

Signed-off-by: Martin Peschke mpesc...@linux.vnet.ibm.com
Reviewed-by: Steffen Maier ma...@linux.vnet.ibm.com
Acked-by: Douglas Gilbert dgilb...@interlog.com

---
 drivers/scsi/scsi_debug.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -2662,8 +2662,8 @@ static void __init sdebug_build_parts(un
   / sdebug_sectors_per;
pp-end_sector = (end_sec % sdebug_sectors_per) + 1;
 
-   pp-start_sect = start_sec;
-   pp-nr_sects = end_sec - start_sec + 1;
+   pp-start_sect = cpu_to_le32(start_sec);
+   pp-nr_sects = cpu_to_le32(end_sec - start_sec + 1);
pp-sys_ind = 0x83; /* plain Linux partition */
}
 }


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


Re: [PATCH] scsi_debug: Fix endianess in partition table

2013-02-13 Thread Martin Peschke
On Tue, 2013-02-12 at 09:45 -0500, Douglas Gilbert wrote:
 However since SCSI is big endian and you are introducing
 some le code then a line or so of explanation (comments)
 in your revised patch might be helpful.

I would argue that the definition of struct partition itself should be
sufficient explanation. Only scsi_debug failed to assign values in a
correct manner. 

 BTW Finding a big endian architecture to test this patch on is
 not easy.

No big deal ;-) I can help out with test data from my System z (aka
s390x).


Without fix:

[root@ ~]# xxd -l 512 /dev/sda
snip
1b0:        0001  
1c0: 0100 8307 203f  0020  3fe0    ?... ..?...
1d0:          
1e0:          
1f0:        55aa  ..U.


With fix:

[root@ ~]# xxd -l 512 /dev/sda
snip
1b0:        0001  
1c0: 0100 8307 203f 2000  e03f     ? ?
1d0:          
1e0:          
1f0:        55aa  ..U.


Which makes it exactly look like the table seen on my laptop:

root@:~# xxd -l 512 /dev/sdb
snip
1b0:        0001  
1c0: 0100 8307 203f 2000  e03f     ? ?
1d0:          
1e0:          
1f0:        55aa  ..U.


Assuming:
modprobe scsi_debug physblk_exp=3 lowest_aligned=7 num_parts=1

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


Re: [PATCH] scsi_debug: Fix endianess in partition table

2013-02-13 Thread Douglas Gilbert

On 13-02-11 12:34 PM, Martin Peschke wrote:

Both start_sect and nr_sects in struct partition are __le32 and
require cpu_to_le32() on assignment.

Without this fix tools like fdisk show an invalid partition table
for SCSI devices emulated by scsi_debug on big-endian architectures,
like s390x. Besides a kernel message like this was emitted:

sda: p1 start 536870912 is beyond EOD, enabling native capacity
sda: p1 start 536870912 is beyond EOD, truncated

For verification 'xxd -l 512 /dev/sda' has been used to make sure
that this fix makes scsi_debug generated partition tables on s390x
look like the ones generated on my laptop.

Signed-off-by: Martin Peschke mpesc...@linux.vnet.ibm.com
Reviewed-by: Steffen Maier ma...@linux.vnet.ibm.com


Acked-by: Douglas Gilbert dgilb...@interlog.com

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


Re: [PATCH] scsi_debug: Fix endianess in partition table

2013-02-12 Thread Martin Peschke
On Mon, 2013-02-11 at 18:34 +0100, Martin Peschke wrote:
 Both start_sect and nr_sects in struct partition are __le32 and
 require cpu_to_le32() on assignment.

Steffen Maier has pointed me at:

block/partitions/msdos.c:   return
(sector_t)get_unaligned_le32(p-start_sect);

Unfortunately, both get_unaligned_le32() and le32_to_cpu() appear to be
in use for start_sect and nr_sects.

Any one who would argue for changing my patch from cpu_to_le32 to
put_unaligned_le32()?

Thanks,
Martin



 
 Without this fix tools like fdisk show an invalid partition table
 for SCSI devices emulated by scsi_debug on big-endian architectures,
 like s390x. Besides a kernel message like this was emitted:
 
 sda: p1 start 536870912 is beyond EOD, enabling native capacity
 sda: p1 start 536870912 is beyond EOD, truncated
 
 For verification 'xxd -l 512 /dev/sda' has been used to make sure
 that this fix makes scsi_debug generated partition tables on s390x
 look like the ones generated on my laptop.
 
 Signed-off-by: Martin Peschke mpesc...@linux.vnet.ibm.com
 Reviewed-by: Steffen Maier ma...@linux.vnet.ibm.com
 
 ---
  drivers/scsi/scsi_debug.c |4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
 
 --- a/drivers/scsi/scsi_debug.c
 +++ b/drivers/scsi/scsi_debug.c
 @@ -2662,8 +2662,8 @@ static void __init sdebug_build_parts(un
  / sdebug_sectors_per;
   pp-end_sector = (end_sec % sdebug_sectors_per) + 1;
 
 - pp-start_sect = start_sec;
 - pp-nr_sects = end_sec - start_sec + 1;
 + pp-start_sect = cpu_to_le32(start_sec);
 + pp-nr_sects = cpu_to_le32(end_sec - start_sec + 1);
   pp-sys_ind = 0x83; /* plain Linux partition */
   }
  }
 
 
 --
 To unsubscribe from this list: send the line unsubscribe linux-scsi in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
 


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


Re: [PATCH] scsi_debug: Fix endianess in partition table

2013-02-12 Thread Douglas Gilbert

On 13-02-12 04:03 AM, Martin Peschke wrote:

On Mon, 2013-02-11 at 18:34 +0100, Martin Peschke wrote:

Both start_sect and nr_sects in struct partition are __le32 and
require cpu_to_le32() on assignment.


Steffen Maier has pointed me at:

block/partitions/msdos.c:   return
(sector_t)get_unaligned_le32(p-start_sect);

Unfortunately, both get_unaligned_le32() and le32_to_cpu() appear to be
in use for start_sect and nr_sects.

Any one who would argue for changing my patch from cpu_to_le32 to
put_unaligned_le32()?


No (because I don't know). However since SCSI is big
endian and you are introducing some le code then a line
or so of explanation (comments) in your revised patch might
be helpful.


BTW Finding a big endian architecture to test this patch on is
not easy. The openwrt in my router is big endian (MIPS) but
openwrt don't distribute the scsi_debug module :-(

Doug Gilbert


Without this fix tools like fdisk show an invalid partition table
for SCSI devices emulated by scsi_debug on big-endian architectures,
like s390x. Besides a kernel message like this was emitted:

sda: p1 start 536870912 is beyond EOD, enabling native capacity
sda: p1 start 536870912 is beyond EOD, truncated

For verification 'xxd -l 512 /dev/sda' has been used to make sure
that this fix makes scsi_debug generated partition tables on s390x
look like the ones generated on my laptop.

Signed-off-by: Martin Peschke mpesc...@linux.vnet.ibm.com
Reviewed-by: Steffen Maier ma...@linux.vnet.ibm.com

---
  drivers/scsi/scsi_debug.c |4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -2662,8 +2662,8 @@ static void __init sdebug_build_parts(un
   / sdebug_sectors_per;
pp-end_sector = (end_sec % sdebug_sectors_per) + 1;

-   pp-start_sect = start_sec;
-   pp-nr_sects = end_sec - start_sec + 1;
+   pp-start_sect = cpu_to_le32(start_sec);
+   pp-nr_sects = cpu_to_le32(end_sec - start_sec + 1);
pp-sys_ind = 0x83;  /* plain Linux partition */
}
  }


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




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



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


[PATCH] scsi_debug: Fix endianess in partition table

2013-02-11 Thread Martin Peschke
Both start_sect and nr_sects in struct partition are __le32 and
require cpu_to_le32() on assignment.

Without this fix tools like fdisk show an invalid partition table
for SCSI devices emulated by scsi_debug on big-endian architectures,
like s390x. Besides a kernel message like this was emitted:

sda: p1 start 536870912 is beyond EOD, enabling native capacity
sda: p1 start 536870912 is beyond EOD, truncated

For verification 'xxd -l 512 /dev/sda' has been used to make sure
that this fix makes scsi_debug generated partition tables on s390x
look like the ones generated on my laptop.

Signed-off-by: Martin Peschke mpesc...@linux.vnet.ibm.com
Reviewed-by: Steffen Maier ma...@linux.vnet.ibm.com

---
 drivers/scsi/scsi_debug.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -2662,8 +2662,8 @@ static void __init sdebug_build_parts(un
   / sdebug_sectors_per;
pp-end_sector = (end_sec % sdebug_sectors_per) + 1;
 
-   pp-start_sect = start_sec;
-   pp-nr_sects = end_sec - start_sec + 1;
+   pp-start_sect = cpu_to_le32(start_sec);
+   pp-nr_sects = cpu_to_le32(end_sec - start_sec + 1);
pp-sys_ind = 0x83; /* plain Linux partition */
}
 }


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