misc patches
Benjamin Marzinski
maintainercover misc patches
This is a small collection of individual bug fix patches that apply on top of my previous patch set.
Benjamin Marzinski (4):
libmultipath: fix sysfs dev_loss_tmo parsing
kpartx: read devices with direct IO
kpartx: handle alternate bsd disklabel location
libmultipath: fix checker detection for nvme devices
kpartx/bsd.c | 16 ++++++++++++-- kpartx/dasd.c | 7 +++--- kpartx/gpt.c | 22 +++++++++---------- kpartx/kpartx.c | 46 ++++++++++++++++++++++++++++++---------- kpartx/kpartx.h | 2 ++ libmultipath/discovery.c | 15 +++++++++---- libmultipath/propsel.c | 4 +++- 7 files changed, 79 insertions(+), 33 deletions(-)
Signature · 1 line
2.17.2
Benjamin Marzinski
maintainerPATCH 1/4 libmultipath: fix sysfs dev_loss_tmo parsing
dev_loss_tmo is a u32 value. However the kernel sysfs code prints it as a signed integer. This means that if dev_loss_tmo is above INT_MAX, the sysfs value will be a negative number. Parsing this was causing sysfs_set_rport_tmo() to fail.
--- libmultipath/discovery.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
libmultipath/discovery.c +5 -4
@@ -583,7 +583,8 @@ sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp)struct udev_device *rport_dev =NULL ;char value[16 ], *eptr;char rport_id[32 ]; -unsigned long long tmo =0 ; +long long ll_tmo; +unsigned int tmo =0 ;int ret; sprintf(rport_id, "rport-%d:%d-%d",
@@ -607,13 +608,13 @@ sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp) "error %d", rport_id, -ret); goto out; } - tmo =strtoull (value, &eptr,0 ); -if (value == eptr || tmo ==ULLONG_MAX ) { + ll_tmo =strtoll (value, &eptr,0 ); +if (value == eptr || ll_tmo >UINT_MAX || ll_tmo <INT_MIN ) {condlog (0 ,"%s: Cannot parse dev_loss_tmo " "attribute '%s'" , rport_id, value); goto out; } - + tmo = (unsigned int )ll_tmo;/* * This is tricky. * dev_loss_tmo will be limited to 600 if fast_io_fail
Signature · 1 line
2.17.2
Re: [PATCH 1/4] libmultipath: fix sysfs dev_loss_tmo parsing
Quoted 8 lines · Benjamin Marzinski
dev_loss_tmois a u32 value. However the kernel sysfs code prints it as
a signed integer. This means that ifdev_loss_tmois aboveINT_MAX, the
sysfs value will be a negative number. Parsing this was causingsysfs_set_rport_tmo()to fail.Signed-off-by Benjamin Marzinski <[email protected]>
Thanks for catching this. I think it can be fixed simpler, because strtoul() parses negative values just fine. See below.
Regards,
Martin
From 16eca9b0f340a13fee0c28ae52dffa578193f015 Mon Sep 17 00:00:00 2001
From: Benjamin Marzinski <[email protected]>
Date: Wed, 1 Jul 2020 17:39:33 -0500
Subject: [PATCH] libmultipath: fix sysfs dev_loss_tmo parsing
dev_loss_tmo is a u32 value. However the kernel sysfs code prints it as a signed integer. This means that if dev_loss_tmo is above INT_MAX, the sysfs value will be a negative number. Parsing this was causing sysfs_set_rport_tmo() to fail.
--- libmultipath/discovery.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
libmultipath/discovery.c +3 -3
@@ -581,7 +581,7 @@ sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp)struct udev_device *rport_dev =NULL ;char value[16 ], *eptr;char rport_id[32 ]; -unsigned long long tmo =0 ; +unsigned int tmo;int ret; sprintf(rport_id, "rport-%d:%d-%d",
@@ -605,8 +605,8 @@ sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp) "error %d", rport_id, -ret); goto out; } - tmo =strtoull (value, &eptr,0 ); -if (value == eptr || tmo ==ULLONG_MAX ) { + tmo =strtoul (value, &eptr,0 ); +if (value == eptr) {condlog (0 ,"%s: Cannot parse dev_loss_tmo " "attribute '%s'" , rport_id, value); goto out;
Signature · 1 line
2.26.2
Benjamin Marzinski
maintainerRe: [PATCH 1/4] libmultipath: fix sysfs dev_loss_tmo parsing
Quoted 8 lines · Martin Wilck
Quoted 7 lines · Benjamin Marzinski
dev_loss_tmois a u32 value. However the kernel sysfs code prints it as
a signed integer. This means that ifdev_loss_tmois aboveINT_MAX, the
sysfs value will be a negative number. Parsing this was causingsysfs_set_rport_tmo()to fail.
Quoted 4 lines
Quoted 1 line
Signed-off-by Benjamin Marzinski <[email protected]>Thanks for catching this. I think it can be fixed simpler, because
strtoul()parses negative values just fine. See below.
Sure. Lets go with that.
-Ben
Quoted 46 lines
Regards,
MartinQuoted 1 line
From
16eca9b0f340a13fee0c28ae52dffa578193f015Mon Sep 17 00:00:00 2001From: Benjamin Marzinski <[email protected]>
Date: Wed, 1 Jul 2020 17:39:33 -0500
Subject: [PATCH] libmultipath: fix sysfsdev_loss_tmoparsing
dev_loss_tmois a u32 value. However the kernel sysfs code prints it as a signed integer. This means that ifdev_loss_tmois aboveINT_MAX, the sysfs value will be a negative number. Parsing this was causingsysfs_set_rport_tmo()to fail.Signed-off-by Benjamin Marzinski <[email protected]>Signed-off-by Martin Wilck <[email protected]>--- libmultipath/discovery.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)libmultipath/discovery.c +3
-3@@ -581,7 +581,7 @@ sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp)struct udev_device *rport_dev =NULL ;char value[16 ], *eptr;char rport_id[32 ]; -unsigned long long tmo =0 ; +unsigned int tmo;int ret; sprintf(rport_id, "rport-%d:%d-%d",@@ -605,8 +605,8 @@ sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp) "error %d", rport_id, -ret); goto out; } - tmo =strtoull (value, &eptr,0 ); -if (value == eptr || tmo ==ULLONG_MAX ) { + tmo =strtoul (value, &eptr,0 ); +if (value == eptr) {condlog (0 ,"%s: Cannot parse dev_loss_tmo " "attribute '%s'" , rport_id, value); goto out;Signature · 1 line
2.26.2
Benjamin Marzinski
maintainerPATCH 2/4 kpartx: read devices with direct IO
In reply to Benjamin MarzinskiIf kpartx is used on top of shared storage, and a device has its partition table changed on one machine, and then kpartx is run on another, it may not see the new data, because the cache still contains the old data, and there is nothing to tell the machine running kpartx to invalidate it. To solve this, kpartx should read the devices using direct io.
One issue with how this code has been updated is that the original code for getblock() always read 1024 bytes. The new code reads a logical sector size chunk of the device, and returns a pointer to the 512 byte sector that the caller asked for, within that (possibly larger) chunk. This means that if the logical sector size is 512, then the code is now only reading 512 bytes. Looking through the code for the various partition types, I can't see a case where more than 512 bytes is needed and getblock() is used. If anyone has a reason why this code should be reading 1024 bytes at minmum, I can certainly change this. But when I looked, I couldn't find a case where reading 512 bytes would cause a problem.
--- kpartx/dasd.c | 7 ++++--- kpartx/gpt.c | 22 ++++++++++------------ kpartx/kpartx.c | 46 +++++++++++++++++++++++++++++++++++----------- kpartx/kpartx.h | 2 ++ 4 files changed, 51 insertions(+), 26 deletions(-)
kpartx/dasd.c +4 -3
@@ -22,6 +22,7 @@* along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#define _GNU_SOURCE#include <stdio.h> #include <stdlib.h> #include <unistd.h>
@@ -117,13 +118,13 @@ read_dasd_pt(int fd, __attribute__((unused)) struct slice all,sprintf (pathname,"/dev/.kpartx-node-%u-%u" , (unsigned int )major (dev), (unsigned int )minor (dev)); -if ((fd_dasd =open (pathname,O_RDONLY )) ==-1 ) { +if ((fd_dasd =open (pathname,O_RDONLY |O_DIRECT )) ==-1 ) {/* Devicenode does not exist. Try to create one */ if (mknod (pathname,0600 |S_IFBLK , dev) ==-1 ) {/* Couldn't create a device node */ return -1 ; } - fd_dasd =open (pathname,O_RDONLY ); + fd_dasd =open (pathname,O_RDONLY |O_DIRECT );/* * The file will vanish when the last process (we) * has ceased to access it.
@@ -175,7 +176,7 @@ read_dasd_pt(int fd, __attribute__((unused)) struct slice all,* Get volume label, extract name and type. */ -if (!(data = (unsigned char *)malloc (blocksize))) +if (aligned_malloc ((void **)&data, blocksize,NULL )) goto out;
kpartx/gpt.c +10 -12
@@ -243,8 +243,7 @@ alloc_read_gpt_entries(int fd, gpt_header * gpt)if (!count)return NULL ; - pte = (gpt_entry *)malloc (count); -if (!pte) +if (aligned_malloc ((void **)&pte,get_sector_size (fd), &count))return NULL ;memset (pte,0 , count);
@@ -269,12 +268,11 @@ static gpt_header * alloc_read_gpt_header(int fd, uint64_t lba) {gpt_header *gpt; - gpt = (gpt_header *) -malloc (sizeof (gpt_header)); -if (!gpt) +size_t size =sizeof (gpt_header); +if (aligned_malloc ((void **)&gpt,get_sector_size (fd), &size))return NULL ; -memset (gpt,0 ,sizeof (*gpt)); -if (!read_lba (fd, lba, gpt,sizeof (gpt_header))) { +memset (gpt,0 , size); +if (!read_lba (fd, lba, gpt, size)) {free (gpt);return NULL ; }
@@ -498,6 +496,7 @@ find_valid_gpt(int fd, gpt_header ** gpt, gpt_entry ** ptes)gpt_header *pgpt =NULL , *agpt =NULL ;gpt_entry *pptes =NULL , *aptes =NULL ;legacy_mbr *legacymbr =NULL ; +size_t size =sizeof (legacy_mbr);uint64_t lastlba;if (!gpt || !ptes)return 0 ;
@@ -526,11 +525,10 @@ find_valid_gpt(int fd, gpt_header ** gpt, gpt_entry ** ptes) }/* This will be added to the EFI Spec. per Intel after v1.02. */ - legacymbr =malloc (sizeof (*legacymbr)); -if (legacymbr) { -memset (legacymbr,0 ,sizeof (*legacymbr)); -read_lba (fd,0 , (uint8_t *) legacymbr, -sizeof (*legacymbr)); +if (aligned_malloc ((void **)&legacymbr,get_sector_size (fd), + &size) ==0 ) { +memset (legacymbr,0 , size); +read_lba (fd,0 , (uint8_t *) legacymbr, size); good_pmbr =is_pmbr_valid (legacymbr);free (legacymbr); legacymbr=NULL ;
kpartx/kpartx.c +35 -11
100 lines not on this page · raw message
kpartx/kpartx.h +2 -0
@@ -1,6 +1,7 @@#ifndef _KPARTX_H#define _KPARTX_H +#include <stddef.h> #include <stdint.h> #include <sys/ioctl.h>
@@ -61,6 +62,7 @@ extern ptreader read_mac_pt;extern ptreader read_sun_pt;extern ptreader read_ps3_pt; +int aligned_malloc (void **mem_p,size_t align,size_t *size_p);char *getblock (int fd,unsigned int secnr); static inline unsigned int
Signature · 1 line
2.17.2
Re: [PATCH 2/4] kpartx: read devices with direct IO
Quoted 28 lines · Benjamin Marzinski
If kpartx is used on top of shared storage, and a device has its partition table changed on one machine, and then kpartx is run on another, it may not see the new data, because the cache still contains
the old data, and there is nothing to tell the machine running kpartx to
invalidate it. To solve this, kpartx should read the devices using direct io.One issue with how this code has been updated is that the original code
forgetblock()always read 1024 bytes. The new code reads a logical sector size chunk of the device, and returns a pointer to the 512 byte
sector that the caller asked for, within that (possibly larger) chunk.
This means that if the logical sector size is 512, then the code is now
only reading 512 bytes. Looking through the code for the various partition types, I can't see a case where more than 512 bytes is needed
andgetblock()is used. If anyone has a reason why this code should be
reading 1024 bytes at minmum, I can certainly change this. But when I
looked, I couldn't find a case where reading 512 bytes would cause a problem.
Quoted 1 line
Signed-off-by Benjamin Marzinski <[email protected]>
The value 1024 comes from first partx in util-linux, where Christophe pulled the first kpartx from:
http://ftp.be.debian.org/pub/linux/utils/util-linux/v2.10/util-linux-2.10m.tar.gz
I, too, see no reason for reading more than a single block.
Two nits below. Here's one more, I'd have preferred two separate patches for these two different issues. But never mind.
Regards,
Martin
Quoted 152 lines
--- kpartx/dasd.c | 7 ++++--- kpartx/gpt.c | 22 ++++++++++------------ kpartx/kpartx.c | 46 +++++++++++++++++++++++++++++++++++----------- kpartx/kpartx.h | 2 ++ 4 files changed, 51 insertions(+), 26 deletions(-)kpartx/dasd.c +0
-0@@ -22,6 +22,7 @@* along with this program. If not, see < http://www.gnu.org/licenses/>;.
*/kpartx/dasd.c +3
-3+#define _GNU_SOURCE#include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -117,13 +118,13 @@ read_dasd_pt(int fd, __attribute__((unused)) struct slice all, sprintf(pathname, "/dev/.kpartx-node-%u-%u", (unsigned int )major (dev), (unsigned int)minor(dev)); -if ((fd_dasd =open (pathname,O_RDONLY )) ==-1 ) { +if ((fd_dasd =open (pathname,O_RDONLY |O_DIRECT )) == -1) {/* Devicenode does not exist. Try to create one */ if (mknod(pathname, 0600 | S_IFBLK, dev) == -1) {/* Couldn't create a device node */ return -1 ; } - fd_dasd =open (pathname,O_RDONLY ); + fd_dasd =open (pathname,O_RDONLY |O_DIRECT );/* * The file will vanish when the last process (we)
kpartx/dasd.c +1
-1* has ceased to access it. @@ -175,7 +176,7 @@ read_dasd_pt(int fd, __attribute__((unused))struct slice all, * Get volume label, extract name and type. */ -if (!(data = (unsigned char *)malloc (blocksize))) +if (aligned_malloc ((void **)&data, blocksize,NULL )) goto out;kpartx/gpt.c +6
-7@@ -243,8 +243,7 @@ alloc_read_gpt_entries(int fd, gpt_header * gpt)if (!count)return NULL ; - pte = (gpt_entry *)malloc (count); -if (!pte) +if (aligned_malloc ((void **)&pte,get_sector_size (fd), &count))return NULL ;memset (pte,0 , count);@@ -269,12 +268,11 @@ static gpt_header * alloc_read_gpt_header(int fd, uint64_t lba) {gpt_header *gpt; - gpt = (gpt_header *) -malloc (sizeof (gpt_header)); -if (!gpt) +size_t size =sizeof (gpt_header); +if (aligned_malloc ((void **)&gpt,get_sector_size (fd), &size))return NULL ; -memset (gpt,0 ,sizeof (*gpt)); -if (!read_lba (fd, lba, gpt,sizeof (gpt_header))) { +memset (gpt,0 , size); +if (!read_lba (fd, lba, gpt, size)) {free (gpt);return NULL ; }@@ -498,6 +496,7 @@ find_valid_gpt(int fd, gpt_header ** gpt, gpt_entry ** ptes) gpt_header *pgpt = NULL, *agpt = NULL;gpt_entry *pptes =NULL , *aptes =NULL ;legacy_mbr *legacymbr =NULL ; +size_t size =sizeof (legacy_mbr);uint64_t lastlba;if (!gpt || !ptes)kpartx/gpt.c +4
-5return 0 ;@@ -526,11 +525,10 @@ find_valid_gpt(int fd, gpt_header ** gpt, gpt_entry ** ptes) }/* This will be added to the EFI Spec. per Intel after v1.02. */ - legacymbr =malloc (sizeof (*legacymbr)); -if (legacymbr) { -memset (legacymbr,0 ,sizeof (*legacymbr)); -read_lba (fd,0 , (uint8_t *) legacymbr, -sizeof (*legacymbr)); +if (aligned_malloc ((void **)&legacymbr,get_sector_size (fd), + &size) ==0 ) { +memset (legacymbr,0 , size); +read_lba (fd,0 , (uint8_t *) legacymbr, size); good_pmbr =is_pmbr_valid (legacymbr);kpartx/gpt.c +0
-0free (legacymbr); legacymbr=NULL ;kpartx/kpartx.c +4
-4@@ -19,6 +19,7 @@* cva, 2002-10-26 */ +#define _GNU_SOURCE#include <stdio.h> #include <fcntl.h> #include <errno.h> @@ -41,7 +42,6 @@#define SIZE (a) (sizeof(a)/sizeof((a)[0])) -#define READ_SIZE 1024#define MAXTYPES 64#define MAXSLICES 256#define DM_TARGET "linear"@@ -388,7 +388,7 @@ main(int argc, char **argv){set_delimiter (mapname, delim); } - fd =open (device,O_RDONLY ); + fd =open (device,O_RDONLY |O_DIRECT );if (fd ==-1 ) {perror (device);@@ -690,9 +690,9 @@ xmalloc (size_t size) {*/ static int -sseek (int fd,unsigned int secnr) { +sseek (int fd,unsigned int secnr,int secsz) {off64_t in, out; - in = ((off64_t ) secnr <<9 ); + in = ((off64_t ) secnr * secsz); out =1 ;if ((out =lseek64 (fd, in,SEEK_SET )) != in)
kpartx/kpartx.c sseek(int fd, unsigned int secnr) { · line 709
Quoted 7 lines
kpartx/kpartx.c +4
-0@@ -703,6 +703,21 @@ sseek(int fd, unsigned int secnr) {return 0 ; } +int +aligned_malloc (void **mem_p,size_t align,size_t *size_p) +{ +size_t pgsize =getpagesize ();
Nit: I'd use a static variable here and call getpagesize() only once.
kpartx/kpartx.c sseek(int fd, unsigned int secnr) {
Quoted 7 lines
kpartx/kpartx.c +6
-0+size_t size = pgsize; +if (!mem_p || !align || (size_p && !*size_p)) +return EINVAL ; + +if (size_p) + *size_p = size = ((*size_p + align -1 ) / align) * align;
It would be cleaner to set *size_p only after successful return from posix_memalign().
Quoted 79 lines
kpartx/kpartx.c +21
-7+ +return posix_memalign (mem_p, pgsize, size); +} + +/* always in sector size blocks */ static struct block { unsigned int secnr;@@ -710,30 +725,39 @@ struct block {struct block *next; } *blockhead; +/* blknr is always in 512 byte blocks */ char * -getblock (int fd,unsigned int secnr) { +getblock (int fd,unsigned int blknr) { +unsigned int secsz =get_sector_size (fd); +unsigned int blks_per_sec = secsz /512 ; +unsigned int secnr = blknr / blks_per_sec; +unsigned int blk_off = (blknr % blks_per_sec) *512 ;struct block *bp;for (bp = blockhead; bp; bp = bp->next)if (bp->secnr == secnr) -return bp->block; +return bp->block + blk_off; -if (sseek (fd, secnr)) +if (sseek (fd, secnr, secsz))return NULL ; bp =xmalloc (sizeof (struct block )); bp->secnr = secnr; bp->next = blockhead; blockhead = bp; - bp->block = (char *)xmalloc (READ_SIZE ); +if (aligned_malloc ((void **)&bp->block, secsz,NULL )) { +fprintf (stderr,"aligned_malloc failed\n" ); +exit (1 ); + } -if (read (fd, bp->block,READ_SIZE ) !=READ_SIZE ) { +if (read (fd, bp->block, secsz) != secsz) {fprintf (stderr,"read error, sector %d\n" , secnr); - bp->block =NULL ; + blockhead = bp->next; +return NULL ; } -return bp->block; +return bp->block + blk_off; }int kpartx/kpartx.h +2
-0@@ -1,6 +1,7 @@#ifndef _KPARTX_H#define _KPARTX_H +#include <stddef.h> #include <stdint.h> #include <sys/ioctl.h> @@ -61,6 +62,7 @@ extern ptreader read_mac_pt;extern ptreader read_sun_pt;extern ptreader read_ps3_pt; +int aligned_malloc (void **mem_p,size_t align,size_t *size_p);char *getblock (int fd,unsigned int secnr); static inline unsigned int
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerRe: [PATCH 2/4] kpartx: read devices with direct IO
Quoted 204 lines · Martin Wilck
Quoted 28 lines · Benjamin Marzinski
If kpartx is used on top of shared storage, and a device has its partition table changed on one machine, and then kpartx is run on another, it may not see the new data, because the cache still contains
the old data, and there is nothing to tell the machine running kpartx to
invalidate it. To solve this, kpartx should read the devices using direct io.One issue with how this code has been updated is that the original code
forgetblock()always read 1024 bytes. The new code reads a logical sector size chunk of the device, and returns a pointer to the 512 byte
sector that the caller asked for, within that (possibly larger) chunk.
This means that if the logical sector size is 512, then the code is now
only reading 512 bytes. Looking through the code for the various partition types, I can't see a case where more than 512 bytes is needed
andgetblock()is used. If anyone has a reason why this code should be
reading 1024 bytes at minmum, I can certainly change this. But when I
looked, I couldn't find a case where reading 512 bytes would cause a problem.Quoted 1 line
Signed-off-by Benjamin Marzinski <[email protected]>The value 1024 comes from first partx in util-linux, where Christophe pulled the first kpartx from:
http://ftp.be.debian.org/pub/linux/utils/util-linux/v2.10/util-linux-2.10m.tar.gz
I, too, see no reason for reading more than a single block.Two nits below. Here's one more, I'd have preferred two separate patches for these two different issues. But never mind.
Regards,
MartinQuoted 152 lines
--- kpartx/dasd.c | 7 ++++--- kpartx/gpt.c | 22 ++++++++++------------ kpartx/kpartx.c | 46 +++++++++++++++++++++++++++++++++++----------- kpartx/kpartx.h | 2 ++ 4 files changed, 51 insertions(+), 26 deletions(-)kpartx/dasd.c +0
-0@@ -22,6 +22,7 @@* along with this program. If not, see < http://www.gnu.org/licenses/>;.
*/kpartx/dasd.c +3
-3+#define _GNU_SOURCE#include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -117,13 +118,13 @@ read_dasd_pt(int fd, __attribute__((unused)) struct slice all, sprintf(pathname, "/dev/.kpartx-node-%u-%u", (unsigned int )major (dev), (unsigned int)minor(dev)); -if ((fd_dasd =open (pathname,O_RDONLY )) ==-1 ) { +if ((fd_dasd =open (pathname,O_RDONLY |O_DIRECT )) == -1) {/* Devicenode does not exist. Try to create one */ if (mknod(pathname, 0600 | S_IFBLK, dev) == -1) {/* Couldn't create a device node */ return -1 ; } - fd_dasd =open (pathname,O_RDONLY ); + fd_dasd =open (pathname,O_RDONLY |O_DIRECT );/* * The file will vanish when the last process (we)
kpartx/dasd.c +1
-1* has ceased to access it. @@ -175,7 +176,7 @@ read_dasd_pt(int fd, __attribute__((unused))struct slice all, * Get volume label, extract name and type. */ -if (!(data = (unsigned char *)malloc (blocksize))) +if (aligned_malloc ((void **)&data, blocksize,NULL )) goto out;kpartx/gpt.c +6
-7@@ -243,8 +243,7 @@ alloc_read_gpt_entries(int fd, gpt_header * gpt)if (!count)return NULL ; - pte = (gpt_entry *)malloc (count); -if (!pte) +if (aligned_malloc ((void **)&pte,get_sector_size (fd), &count))return NULL ;memset (pte,0 , count);@@ -269,12 +268,11 @@ static gpt_header * alloc_read_gpt_header(int fd, uint64_t lba) {gpt_header *gpt; - gpt = (gpt_header *) -malloc (sizeof (gpt_header)); -if (!gpt) +size_t size =sizeof (gpt_header); +if (aligned_malloc ((void **)&gpt,get_sector_size (fd), &size))return NULL ; -memset (gpt,0 ,sizeof (*gpt)); -if (!read_lba (fd, lba, gpt,sizeof (gpt_header))) { +memset (gpt,0 , size); +if (!read_lba (fd, lba, gpt, size)) {free (gpt);return NULL ; }@@ -498,6 +496,7 @@ find_valid_gpt(int fd, gpt_header ** gpt, gpt_entry ** ptes) gpt_header *pgpt = NULL, *agpt = NULL;gpt_entry *pptes =NULL , *aptes =NULL ;legacy_mbr *legacymbr =NULL ; +size_t size =sizeof (legacy_mbr);uint64_t lastlba;if (!gpt || !ptes)kpartx/gpt.c +4
-5return 0 ;@@ -526,11 +525,10 @@ find_valid_gpt(int fd, gpt_header ** gpt, gpt_entry ** ptes) }/* This will be added to the EFI Spec. per Intel after v1.02. */ - legacymbr =malloc (sizeof (*legacymbr)); -if (legacymbr) { -memset (legacymbr,0 ,sizeof (*legacymbr)); -read_lba (fd,0 , (uint8_t *) legacymbr, -sizeof (*legacymbr)); +if (aligned_malloc ((void **)&legacymbr,get_sector_size (fd), + &size) ==0 ) { +memset (legacymbr,0 , size); +read_lba (fd,0 , (uint8_t *) legacymbr, size); good_pmbr =is_pmbr_valid (legacymbr);kpartx/gpt.c +0
-0free (legacymbr); legacymbr=NULL ;kpartx/kpartx.c +4
-4@@ -19,6 +19,7 @@* cva, 2002-10-26 */ +#define _GNU_SOURCE#include <stdio.h> #include <fcntl.h> #include <errno.h> @@ -41,7 +42,6 @@#define SIZE (a) (sizeof(a)/sizeof((a)[0])) -#define READ_SIZE 1024#define MAXTYPES 64#define MAXSLICES 256#define DM_TARGET "linear"@@ -388,7 +388,7 @@ main(int argc, char **argv){set_delimiter (mapname, delim); } - fd =open (device,O_RDONLY ); + fd =open (device,O_RDONLY |O_DIRECT );if (fd ==-1 ) {perror (device);@@ -690,9 +690,9 @@ xmalloc (size_t size) {*/ static int -sseek (int fd,unsigned int secnr) { +sseek (int fd,unsigned int secnr,int secsz) {off64_t in, out; - in = ((off64_t ) secnr <<9 ); + in = ((off64_t ) secnr * secsz); out =1 ;if ((out =lseek64 (fd, in,SEEK_SET )) != in)kpartx/kpartx.c sseek(int fd, unsigned int secnr) { · line 709
Quoted 7 lines
kpartx/kpartx.c +4
-0@@ -703,6 +703,21 @@ sseek(int fd, unsigned int secnr) {return 0 ; } +int +aligned_malloc (void **mem_p,size_t align,size_t *size_p) +{ +size_t pgsize =getpagesize ();Nit: I'd use a static variable here and call
getpagesize()only once.
Quoted 10 lines
kpartx/kpartx.c sseek(int fd, unsigned int secnr) {
Quoted 7 lines
kpartx/kpartx.c +6
-0+size_t size = pgsize; +if (!mem_p || !align || (size_p && !*size_p)) +return EINVAL ; + +if (size_p) + *size_p = size = ((*size_p + align -1 ) / align) * align;It would be cleaner to set
*size_ponly after successful return fromposix_memalign().
Sure. I can change these.
-Ben
Quoted 86 lines
Quoted 79 lines
kpartx/kpartx.c +21
-7+ +return posix_memalign (mem_p, pgsize, size); +} + +/* always in sector size blocks */ static struct block { unsigned int secnr;@@ -710,30 +725,39 @@ struct block {struct block *next; } *blockhead; +/* blknr is always in 512 byte blocks */ char * -getblock (int fd,unsigned int secnr) { +getblock (int fd,unsigned int blknr) { +unsigned int secsz =get_sector_size (fd); +unsigned int blks_per_sec = secsz /512 ; +unsigned int secnr = blknr / blks_per_sec; +unsigned int blk_off = (blknr % blks_per_sec) *512 ;struct block *bp;for (bp = blockhead; bp; bp = bp->next)if (bp->secnr == secnr) -return bp->block; +return bp->block + blk_off; -if (sseek (fd, secnr)) +if (sseek (fd, secnr, secsz))return NULL ; bp =xmalloc (sizeof (struct block )); bp->secnr = secnr; bp->next = blockhead; blockhead = bp; - bp->block = (char *)xmalloc (READ_SIZE ); +if (aligned_malloc ((void **)&bp->block, secsz,NULL )) { +fprintf (stderr,"aligned_malloc failed\n" ); +exit (1 ); + } -if (read (fd, bp->block,READ_SIZE ) !=READ_SIZE ) { +if (read (fd, bp->block, secsz) != secsz) {fprintf (stderr,"read error, sector %d\n" , secnr); - bp->block =NULL ; + blockhead = bp->next; +return NULL ; } -return bp->block; +return bp->block + blk_off; }int kpartx/kpartx.h +2
-0@@ -1,6 +1,7 @@#ifndef _KPARTX_H#define _KPARTX_H +#include <stddef.h> #include <stdint.h> #include <sys/ioctl.h> @@ -61,6 +62,7 @@ extern ptreader read_mac_pt;extern ptreader read_sun_pt;extern ptreader read_ps3_pt; +int aligned_malloc (void **mem_p,size_t align,size_t *size_p);char *getblock (int fd,unsigned int secnr); static inline unsigned intSignature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerPATCH 3/4 kpartx: handle alternate bsd disklabel location
In reply to Benjamin Marzinskibsd disk labels can either be at the start of the second sector, or 64 bytes into the first sector, but kpartx only handled the first case. However the second case is what parted creates, and what the linux kernel partition code expects. kpartx should handle both cases.
--- kpartx/bsd.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
kpartx/bsd.c +14 -2
@@ -1,6 +1,7 @@#include "kpartx.h" #include <stdio.h> +#define BSD_LABEL_OFFSET 64#define BSD_DISKMAGIC (0x82564557UL)/* The disk magic number */ #define XBSD_MAXPARTITIONS 16#define BSD_FS_UNUSED 0
@@ -60,8 +61,19 @@ read_bsd_pt(int fd, struct slice all, struct slice *sp, unsigned int ns) {return -1 ; l = (struct bsd_disklabel *) bp; -if (l->d_magic !=BSD_DISKMAGIC ) -return -1 ; +if (l->d_magic !=BSD_DISKMAGIC ) { +/* +* BSD disklabels can also start 64 bytes offset from the +* start of the first sector +*/ + bp =getblock (fd, offset); +if (bp ==NULL ) +return -1 ; + + l = (struct bsd_disklabel *)(bp +64 ); +if (l->d_magic !=BSD_DISKMAGIC ) +return -1 ; + } max_partitions =16 ;if (l->d_npartitions < max_partitions)
Signature · 1 line
2.17.2
Re: [PATCH 3/4] kpartx: handle alternate bsd disklabel location
Quoted 7 lines · Benjamin Marzinski
bsd disk labels can either be at the start of the second sector, or 64
bytes into the first sector, but kpartx only handled the first case. However the second case is what parted creates, and what the linux kernel partition code expects. kpartx should handle both cases.Signed-off-by Benjamin Marzinski <[email protected]>
I can see that for parted, but not for the kernel
(https://elixir.bootlin.com/linux/latest/source/block/partitions/msdos.c#L368)
Anyway:
Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerRe: [PATCH 3/4] kpartx: handle alternate bsd disklabel location
Quoted 11 lines · Martin Wilck
Quoted 7 lines · Benjamin Marzinski
bsd disk labels can either be at the start of the second sector, or 64
bytes into the first sector, but kpartx only handled the first case. However the second case is what parted creates, and what the linux kernel partition code expects. kpartx should handle both cases.Signed-off-by Benjamin Marzinski <[email protected]>I can see that for parted, but not for the kernel
(https://elixir.bootlin.com/linux/latest/source/block/partitions/msdos.c#L368)
https://elixir.bootlin.com/linux/latest/source/block/partitions/osf.c
-Ben
Quoted 11 lines
Anyway:
Reviewed-by Martin Wilck <[email protected]>Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Software Solutions Germany GmbH HRB 36809, AG Nürnberg GF: Felix Imendörffer
Benjamin Marzinski
maintainerPATCH 4/4 libmultipath: fix checker detection for nvme devices
In reply to Benjamin MarzinskiIn order to fix hwhandler autodetection, commit 8794a776 made detect_alua() differentiate between failures to detect whether alua was supported, and successfully detecting that it was not supported. However, this causes nvme devices to get the TUR checker assigned to them. This is because there is nothing in detect_alua() to make it only work on scsi devices, and select_checker wasn't updated to handle detect_alua() failing without setting pp->tpgs to TPGS_NONE.
detect_alua() should automatically set pp->tpgs to TPGS_NONE and exit on non-scsi devices. Also, select_checker() should not assume that a devices is ALUA, simply because if failed to detect if alua was supported.
down"
--- libmultipath/discovery.c | 6 ++++++ libmultipath/propsel.c | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-)
libmultipath/discovery.c +6 -0
@@ -888,6 +888,12 @@ detect_alua(struct path * pp)int tpgs;unsigned int timeout; + +if (pp->bus !=SYSFS_BUS_SCSI ) { + pp->tpgs =TPGS_NONE ; +return ; + } +if (sysfs_get_timeout (pp, &timeout) <=0 ) timeout =DEF_TIMEOUT ;
libmultipath/propsel.c +3 -1
@@ -521,7 +521,9 @@ int select_checker(struct config *conf, struct path *pp)if (check_rdac (pp)) { ckr_name =RDAC ; goto out; - }else if (path_get_tpgs (pp) !=TPGS_NONE ) { + } +path_get_tpgs (pp); +if (pp->tpgs !=TPGS_NONE && pp->tpgs !=TPGS_UNDEF ) { ckr_name =TUR ; goto out; }
Signature · 1 line
2.17.2
Re: [PATCH 4/4] libmultipath: fix checker detection for nvme devices
Quoted 16 lines · Benjamin Marzinski
In order to fix hwhandler autodetection, commit
8794a776madedetect_alua()differentiate between failures to detect whether alua was
supported, and successfully detecting that it was not supported. However, this causes nvme devices to get the TUR checker assigned to them. This is because there is nothing indetect_alua()to make it only
work on scsi devices, andselect_checkerwasn't updated to handledetect_alua()failing without settingpp->tpgstoTPGS_NONE.
detect_alua()should automatically setpp->tpgstoTPGS_NONEand exit on
non-scsi devices. Also,select_checker()should not assume that a devices is ALUA, simply because if failed to detect if alua was supported.
Quoted 3 lines
Fixes 8794a776 "libmultipath: fix ALUA autodetection when paths aredown"
Signed-off-by Benjamin Marzinski <[email protected]>