Multipath Follow-up patches
Benjamin Marzinski
maintainercover Multipath Follow-up patches
These patches resolve various minor issues that Martin had with my previous patch set.
Benjamin Marzinski (5):
multipath: fix issues found by compiling with gcc 10
libmultipath: turn pp->vpd_data into a pointer
libmultipath: change loading and resetting in directio
libmultipath: change directio get_events() timeout handling
libmultipath: cleanup old issues with directio checker
kpartx/dasd.c | 6 +- libmultipath/checkers.c | 26 ++--- libmultipath/checkers.h | 2 +- libmultipath/checkers/directio.c | 66 ++---------- libmultipath/discovery.c | 17 ++- libmultipath/print.c | 7 +- libmultipath/structs.c | 3 + libmultipath/structs.h | 2 +- multipath/main.c | 2 +- tests/directio.c | 178 ++++++++++++------------------- tests/vpd.c | 3 +- 11 files changed, 119 insertions(+), 193 deletions(-)
Signature · 1 line
2.17.2
Benjamin Marzinski
maintainerPATCH 1/5 multipath: fix issues found by compiling with gcc 10
--- kpartx/dasd.c | 6 +++--- libmultipath/print.c | 3 ++- multipath/main.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-)
kpartx/dasd.c +3 -3
@@ -186,7 +186,7 @@ read_dasd_pt(int fd, __attribute__((unused)) struct slice all, goto out; } -if ((!info.FBA_layout) && (!strcmp (info.type,"ECKD" ))) +if ((!info.FBA_layout) && (!strncmp (info.type,"ECKD" ,4 )))memcpy (&vlabel, data,sizeof (vlabel));else {bzero (&vlabel,4 );
@@ -216,7 +216,7 @@ read_dasd_pt(int fd, __attribute__((unused)) struct slice all, sp[0 ].size = size - sp[0 ].start; retval =1 ; }else if ((strncmp (type,"VOL1" ,4 ) ==0 ) && - (!info.FBA_layout) && (!strcmp (info.type,"ECKD" ))) { + (!info.FBA_layout) && (!strncmp (info.type,"ECKD" ,4 ))) {/* * New style VOL1 labeled disk */
@@ -265,7 +265,7 @@ read_dasd_pt(int fd, __attribute__((unused)) struct slice all,if (vlabel.ldl_version ==0xf2 ) { fmt_size =sectors512 (vlabel.formatted_blocks, blocksize); - }else if (!strcmp (info.type,"ECKD" )) { + }else if (!strncmp (info.type,"ECKD" ,4 )) {/* formatted w/o large volume support */ fmt_size = geo.cylinders * geo.heads * geo.sectors * (blocksize >>9 );
libmultipath/print.c +2 -1
@@ -29,6 +29,7 @@#include "uevent.h" #include "debug.h" #include "discovery.h" +#include "util.h" #define MAX (x,y) (((x) > (y)) ? (x) : (y))#define MIN (x,y) (((x) > (y)) ? (y) : (x))
@@ -2056,7 +2057,7 @@ int snprint_devices(struct config *conf, char * buff, int len, devptr = devpath +11 ; *devptr ='\0' ; -strncat (devptr, blkdev->d_name,PATH_MAX -12 ); +strlcpy (devptr, blkdev->d_name,PATH_MAX -11 );if (stat (devpath, &statbuf) <0 )continue ;
multipath/main.c +1 -1
@@ -1025,7 +1025,7 @@ main (int argc, char *argv[])if (!dev) goto out; -strncpy (dev, argv[optind],FILE_NAME_SIZE ); +strlcpy (dev, argv[optind],FILE_NAME_SIZE );if (dev_type !=DEV_UEVENT ) dev_type =get_dev_type (dev);if (dev_type ==DEV_NONE ) {
Signature · 1 line
2.17.2
Re: [PATCH 1/5] multipath: fix issues found by compiling with gcc 10
Quoted 6 lines · Benjamin Marzinski
Signed-off-by Benjamin Marzinski <[email protected]>--- kpartx/dasd.c | 6 +++--- libmultipath/print.c | 3 ++- multipath/main.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-)
I don't recall having raised issues about this, actually I haven't tested with gcc10 so far. But never mind :-)
kpartx/dasd.c read_dasd_pt(int fd, __attribute__((unused)) · line 191
Quoted 12 lines
kpartx/dasd.c +1
-1@@ -186,7 +186,7 @@ read_dasd_pt(int fd, __attribute__((unused))struct slice all, goto out; } -if ((!info.FBA_layout) && (!strcmp (info.type,"ECKD" ))) +if ((!info.FBA_layout) && (!strncmp (info.type,"ECKD" ,4 )))memcpy (&vlabel, data,sizeof (vlabel));
It looks to me as if this should actually be memcmp(), as info.type is not NUL-terminated.
Quoted 39 lines
kpartx/dasd.c +0
-0else {kpartx/dasd.c +1
-1bzero (&vlabel,4 );@@ -216,7 +216,7 @@ read_dasd_pt(int fd, __attribute__((unused))struct slice all, sp[0].size = size - sp[0].start; retval =1 ; }else if ((strncmp (type,"VOL1" ,4 ) ==0 ) && - (!info.FBA_layout) && (!strcmp (info.type,"ECKD" ))) { + (!info.FBA_layout) && (!strncmp (info.type,"ECKD" ,4 ))) {/* kpartx/dasd.c +1
-1* New style VOL1 labeled disk */ @@ -265,7 +265,7 @@ read_dasd_pt(int fd, __attribute__((unused))struct slice all, if (vlabel.ldl_version == 0xf2) { fmt_size =sectors512 (vlabel.formatted_blocks, blocksize); - } else if (!strcmp(info.type, "ECKD")) { + } else if (!strncmp(info.type, "ECKD",4)) {/* formatted w/o large volume support */
kpartx/dasd.c +0
-0fmt_size = geo.cylinders * geo.heads * geo.sectors * (blocksize >>9);
libmultipath/print.c +1
-0@@ -29,6 +29,7 @@#include "uevent.h" #include "debug.h" #include "discovery.h" +#include "util.h" #define MAX (x,y) (((x) > (y)) ? (x) : (y))#define MIN (x,y) (((x) > (y)) ? (y) : (x))
libmultipath/print.c int snprint_devices(struct config *conf, char * · line 2063
Quoted 8 lines
libmultipath/print.c +1
-1@@ -2056,7 +2057,7 @@ int snprint_devices(struct config *conf, char * buff, int len, devptr = devpath +11 ; *devptr ='\0' ; -strncat (devptr, blkdev->d_name,PATH_MAX -12 ); +strlcpy (devptr, blkdev->d_name,PATH_MAX -11 );if (stat (devpath, &statbuf) <0 )continue ;
If you use strlcpy(), you can delete the "*devptr = '\0'" statement (we can be certain that (PATH_MAX-11 > 0), thus strlcpy() is guaranteed to write a NUL byte).
Moreover, while you're at that, copying "/sys/block/" to devpath before the loop is an ugly pseudo-optimization (not your fault). Readability would be improved by ditching that and simply writing
if (safe_snprintf(devpath, sizeof(devpath),
"/sys/block/%s", devptr))
continue;inside the loop.
Martin
Benjamin Marzinski
maintainerRe: [PATCH 1/5] multipath: fix issues found by compiling with gcc 10
Quoted 10 lines · Martin Wilck
Quoted 6 lines · Benjamin Marzinski
Signed-off-by Benjamin Marzinski <[email protected]>--- kpartx/dasd.c | 6 +++--- libmultipath/print.c | 3 ++- multipath/main.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-)I don't recall having raised issues about this, actually I haven't tested with gcc10 so far. But never mind :-)
Actually, this is just because I happened to be working on these patches on a machine with gcc10 installed.
I'll fix these issues and resent.
-Ben
Quoted 82 lines
kpartx/dasd.c read_dasd_pt(int fd, __attribute__((unused)) · line 191
Quoted 13 lines
kpartx/dasd.c +1
-1@@ -186,7 +186,7 @@ read_dasd_pt(int fd, __attribute__((unused))struct slice all, goto out; } -if ((!info.FBA_layout) && (!strcmp (info.type,"ECKD" ))) +if ((!info.FBA_layout) && (!strncmp (info.type,"ECKD" ,4 )))memcpy (&vlabel, data,sizeof (vlabel));It looks to me as if this should actually be
memcmp(), as info.type is not NUL-terminated.Quoted 39 lines
kpartx/dasd.c +0
-0else {kpartx/dasd.c +1
-1bzero (&vlabel,4 );@@ -216,7 +216,7 @@ read_dasd_pt(int fd, __attribute__((unused))struct slice all, sp[0].size = size - sp[0].start; retval =1 ; }else if ((strncmp (type,"VOL1" ,4 ) ==0 ) && - (!info.FBA_layout) && (!strcmp (info.type,"ECKD" ))) { + (!info.FBA_layout) && (!strncmp (info.type,"ECKD" ,4 ))) {/* kpartx/dasd.c +1
-1* New style VOL1 labeled disk */ @@ -265,7 +265,7 @@ read_dasd_pt(int fd, __attribute__((unused))struct slice all, if (vlabel.ldl_version == 0xf2) { fmt_size =sectors512 (vlabel.formatted_blocks, blocksize); - } else if (!strcmp(info.type, "ECKD")) { + } else if (!strncmp(info.type, "ECKD",4)) {/* formatted w/o large volume support */
kpartx/dasd.c +0
-0fmt_size = geo.cylinders * geo.heads * geo.sectors * (blocksize >>9);
libmultipath/print.c +1
-0@@ -29,6 +29,7 @@#include "uevent.h" #include "debug.h" #include "discovery.h" +#include "util.h" #define MAX (x,y) (((x) > (y)) ? (x) : (y))#define MIN (x,y) (((x) > (y)) ? (y) : (x))libmultipath/print.c int snprint_devices(struct config *conf, char * · line 2063
Quoted 8 lines
libmultipath/print.c +1
-1@@ -2056,7 +2057,7 @@ int snprint_devices(struct config *conf, char * buff, int len, devptr = devpath +11 ; *devptr ='\0' ; -strncat (devptr, blkdev->d_name,PATH_MAX -12 ); +strlcpy (devptr, blkdev->d_name,PATH_MAX -11 );if (stat (devpath, &statbuf) <0 )continue ;If you use
strlcpy(), you can delete the "*devptr = '\0'" statement (we can be certain that (PATH_MAX-11 > 0), thusstrlcpy()is guaranteed to write a NUL byte).Moreover, while you're at that, copying "
/sys/block/" to devpath before the loop is an ugly pseudo-optimization (not your fault). Readability would be improved by ditching that and simply writingif (safe_snprintf(devpath, sizeof(devpath), "/sys/block/%s", devptr)) continue;inside the loop.
Martin
Benjamin Marzinski
maintainerPATCH 2/5 libmultipath: turn pp->vpd_data into a pointer
In reply to Benjamin MarzinskiInstead of always allocating space in the path structure for vpd_data, only allocte it when necessary.
Also, fix comments on vpd tests
--- libmultipath/discovery.c | 17 +++++++++++++++-- libmultipath/print.c | 4 ++-- libmultipath/structs.c | 3 +++ libmultipath/structs.h | 2 +- tests/vpd.c | 3 ++- 5 files changed, 23 insertions(+), 6 deletions(-)
libmultipath/discovery.c +15 -2
@@ -1649,8 +1649,21 @@ scsi_ioctl_pathinfo (struct path * pp, int mask)select_vpd_vendor_id (pp); vpd_id = pp->vpd_vendor_id; -if (vpd_id !=VPD_VP_UNDEF &&get_vpd_sgio (pp->fd, vpd_vendor_pages[vpd_id].pg, vpd_id, pp->vpd_data,sizeof (pp->vpd_data)) <0 ) -condlog (3 ,"%s: failed to get extra vpd data" , pp->dev); +if (vpd_id !=VPD_VP_UNDEF ) { +char vpd_data[VPD_DATA_SIZE ] = {0 }; + +if (get_vpd_sgio (pp->fd, vpd_vendor_pages[vpd_id].pg, vpd_id, + vpd_data,sizeof (vpd_data)) <0 ) +condlog (3 ,"%s: failed to get extra vpd data" , pp->dev); +else { + vpd_data[VPD_DATA_SIZE -1 ] ='\0' ; +if (pp->vpd_data) +free (pp->vpd_data); + pp->vpd_data =strdup (vpd_data); +if (!pp->vpd_data) +condlog (0 ,"%s: failed to allocate space for vpd data" , pp->dev); + } + } parent = pp->udev;while (parent) {
libmultipath/print.c +2 -2
@@ -371,7 +371,7 @@ snprint_multipath_vpd_data(char * buff, size_t len, vector_foreach_slot(mpp->pg, pgp, i) vector_foreach_slot(pgp->paths, pp, j) -if (strlen (pp->vpd_data)) +if (pp->vpd_data)return snprintf (buff, len,"%s" , pp->vpd_data);return snprintf (buff, len,"[undef]" ); }
@@ -710,7 +710,7 @@ snprint_path_marginal(char * buff, size_t len, const struct path * pp)static int snprint_path_vpd_data (char * buff,size_t len,const struct path * pp) { -if (strlen (pp->vpd_data) >0 ) +if (pp->vpd_data)return snprintf (buff, len,"%s" , pp->vpd_data);return snprintf (buff, len,"[undef]" ); }
libmultipath/structs.c +3 -0
@@ -131,6 +131,9 @@ free_path (struct path * pp)udev_device_unref (pp->udev); pp->udev =NULL ; } +if (pp->vpd_data) +free (pp->vpd_data); +vector_free (pp->hwe);FREE (pp);
libmultipath/structs.h +1 -1
@@ -269,7 +269,7 @@ struct path {char rev[PATH_REV_SIZE ];char serial[SERIAL_SIZE ];char tgt_node_name[NODE_NAME_SIZE ]; -char vpd_data[VPD_DATA_SIZE ]; +char *vpd_data;unsigned long long size;unsigned int checkint;unsigned int tick;
tests/vpd.c +2 -1
@@ -520,8 +520,9 @@ static void test_vpd_eui_ ## len ## _ ## wlen ## _ ## sml(void **state) \ n =create_vpd83 (vt->vpdbuf,sizeof (vt->vpdbuf), test_id, \2 ,0 , len); \if (sml) { \ -/* overwrite the page side to DEFAULT_SGIO_LEN + 1 */ \ +/* overwrite the page size to DEFAULT_SGIO_LEN + 1 */ \put_unaligned_be16 (255 , vt->vpdbuf +2 ); \ +/* this causes get_vpd_sgio to do a second ioctl */ \will_return (__wrap_ioctl, n); \will_return (__wrap_ioctl, vt->vpdbuf); \ } \
Signature · 1 line
2.17.2
Re: [PATCH 2/5] libmultipath: turn pp->vpd_data into a pointer
Quoted 6 lines · Benjamin Marzinski
Instead of always allocating space in the path structure for
vpd_data,
only allocte it when necessary.Also, fix comments on vpd tests
Quoted 8 lines
Signed-off-by Benjamin Marzinski <[email protected]>--- libmultipath/discovery.c | 17 +++++++++++++++-- libmultipath/print.c | 4 ++-- libmultipath/structs.c | 3 +++ libmultipath/structs.h | 2 +- tests/vpd.c | 3 ++- 5 files changed, 23 insertions(+), 6 deletions(-)
Benjamin Marzinski
maintainerPATCH 3/5 libmultipath: change loading and resetting in directio
In reply to Benjamin MarzinskiThe directio checker previously made sure to always keep an aio_group around after loading or resetting the checker. There is no need to do this, and removing this code simplifies the checker. With this change, there is no longer a need for a load or unload checker function, only a reset function which is run when the checker is reset or unloaded. Changing this broke a number of tests, so the unit tests have been updated as well.
--- libmultipath/checkers.c | 26 ++--- libmultipath/checkers.h | 2 +- libmultipath/checkers/directio.c | 43 +------- tests/directio.c | 177 +++++++++++++------------------ 4 files changed, 81 insertions(+), 167 deletions(-)
libmultipath/checkers.c +7 -19
@@ -18,9 +18,7 @@ struct checker_class {int (*init)(struct checker *);/* to allocate the context */ int (*mp_init)(struct checker *);/* to allocate the mpcontext */ void (*free)(struct checker *);/* to free the context */ -int (*load)(void );/* to allocate global variables */ -void (*unload)(void );/* to free global variables */ -int (*reset)(void );/* to reset the global variables */ +void (*reset)(void );/* to reset the global variables */ const char **msgtable;short msgtable_size; };
@@ -69,8 +67,8 @@ void free_checker_class(struct checker_class *c) }condlog (3 ,"unloading %s checker" , c->name);list_del (&c->node); -if (c->unload) - c->unload (); +if (c->reset) + c->reset ();if (c->handle) {if (dlclose (c->handle) !=0 ) { condlog(0, "Cannot unload checker %s: %s",
@@ -103,16 +101,14 @@ static struct checker_class *checker_class_lookup(const char *name)return NULL ; } -int reset_checker_classes (void ) +void reset_checker_classes (void ) { -int ret =0 ;struct checker_class *c;list_for_each_entry (c, &checkers, node) {if (c->reset) - ret = ret? ret : c->reset (); + c->reset (); } -return ret; } static struct checker_class *add_checker_class(const char *multipath_dir,
@@ -159,10 +155,8 @@ static struct checker_class *add_checker_class(const char *multipath_dir, goto out; c->mp_init = (int (*)(struct checker *))dlsym (c->handle,"libcheck_mp_init" ); - c->load = (int (*)(void ))dlsym (c->handle,"libcheck_load" ); - c->unload = (void (*)(void ))dlsym (c->handle,"libcheck_unload" ); - c->reset = (int (*)(void ))dlsym (c->handle,"libcheck_reset" ); -/* These 4 functions can be NULL. call dlerror() to clear out any + c->reset = (void (*)(void ))dlsym (c->handle,"libcheck_reset" ); +/* These 2 functions can be NULL. call dlerror() to clear out any * error string */ dlerror ();
@@ -189,12 +183,6 @@ static struct checker_class *add_checker_class(const char *multipath_dir,condlog (3 ,"checker %s: message table size = %d" , c->name, c->msgtable_size); -if (c->load && c->load () !=0 ) { -condlog (0 ,"%s: failed to load checker" , c->name); - c->unload =NULL ; - goto out; - } - done: c->sync =1 ;list_add (&c->node, &checkers);
libmultipath/checkers.h +1 -1
@@ -150,7 +150,7 @@ void checker_disable (struct checker *);int checker_check (struct checker *,int );int checker_is_sync (const struct checker *);const char *checker_name (const struct checker *); -int reset_checker_classes (void ); +void reset_checker_classes (void );/* * This returns a string that's best prepended with "$NAME checker", * where $NAME is the return value of checker_name().
libmultipath/checkers/directio.c +2 -41
58 lines not on this page · raw message
tests/directio.c +71 -106
377 lines not on this page · raw message
Signature · 1 line
2.17.2
Re: [PATCH 3/5] libmultipath: change loading and resetting in directio
Quoted 10 lines · Benjamin Marzinski
The directio checker previously made sure to always keep an
aio_grouparound after loading or resetting the checker. There is no need to do this, and removing this code simplifies the checker. With this change,
there is no longer a need for a load or unload checker function, only a
reset function which is run when the checker is reset or unloaded. Changing this broke a number of tests, so the unit tests have been updated as well.
Quoted 8 lines
Signed-off-by Benjamin Marzinski <[email protected]>--- libmultipath/checkers.c | 26 ++--- libmultipath/checkers.h | 2 +- libmultipath/checkers/directio.c | 43 +------- tests/directio.c | 177 +++++++++++++-------------- ---- 4 files changed, 81 insertions(+), 167 deletions(-)
Many thanks for making this change. I feared that the directio tests were tied quite closely to implementation details...
Benjamin Marzinski
maintainerRe: [PATCH 3/5] libmultipath: change loading and resetting in directio
Quoted 20 lines · Martin Wilck
Quoted 10 lines · Benjamin Marzinski
The directio checker previously made sure to always keep an
aio_grouparound after loading or resetting the checker. There is no need to do this, and removing this code simplifies the checker. With this change,
there is no longer a need for a load or unload checker function, only a
reset function which is run when the checker is reset or unloaded. Changing this broke a number of tests, so the unit tests have been updated as well.Quoted 8 lines
Signed-off-by Benjamin Marzinski <[email protected]>--- libmultipath/checkers.c | 26 ++--- libmultipath/checkers.h | 2 +- libmultipath/checkers/directio.c | 43 +------- tests/directio.c | 177 +++++++++++++-------------- ---- 4 files changed, 81 insertions(+), 167 deletions(-)
Quoted 2 lines
Many thanks for making this change. I feared that the directio tests were tied quite closely to implementation details...
I've always been looking at the unit tests as a way to make sure that we exercise code paths that are hard to hit with functional tests in a more real-world environment. As such, the idea is to write them specifically to match the code.
Quoted 3 lines
Reviewed-by Martin Wilck <[email protected]>
Benjamin Marzinski
maintainerPATCH 4/5 libmultipath: change directio get_events() timeout handling
In reply to Benjamin Marzinskiget_events() used a NULL or a zeroed timeout to mean "don't wait". io_getevents() uses a NULL timeout to mean "wait forever" and a zeroed timeout to mean "don't wait". Make get_events() work like io_getevents().
--- libmultipath/checkers/directio.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
libmultipath/checkers/directio.c +5 -5
@@ -262,7 +262,7 @@ get_events(struct aio_group *aio_grp, struct timespec *timeout)struct io_event events[128 ];int i, nr, got_events =0 ;struct timespec zero_timeout = {0 }; -struct timespec *timep = (timeout)? timeout : &zero_timeout; +struct timespec *timep = timeout; do { errno = 0;
@@ -303,7 +303,6 @@ check_state(int fd, struct directio_context *ct, int sync, int timeout_secs)int rc;long r;struct timespec currtime, endtime; -struct timespec *timep = &timeout;if (fstat (fd, &sb) ==0 ) {LOG (4 ,"called for %x" , (unsigned ) sb.st_rdev);
@@ -339,18 +338,19 @@ check_state(int fd, struct directio_context *ct, int sync, int timeout_secs) endtime.tv_nsec += timeout.tv_nsec;normalize_timespec (&endtime);while (1 ) { - r =get_events (ct->aio_grp, timep); + r =get_events (ct->aio_grp, &timeout);if (ct->req->state !=PATH_PENDING ) { ct->running =0 ;return ct->req->state; - }else if (r ==0 || !timep) + }else if (r ==0 || + (timeout.tv_sec ==0 && timeout.tv_nsec ==0 ))break ;get_monotonic_time (&currtime);timespecsub (&endtime, &currtime, &timeout);if (timeout.tv_sec <0 ) - timep =NULL ; + timeout.tv_sec = timeout.tv_nsec =0 ; }if (ct->running > timeout_secs || sync) {struct io_event event;
Signature · 1 line
2.17.2
Re: [PATCH 4/5] libmultipath: change directio get_events() timeout handling
Quoted 9 lines · Benjamin Marzinski
get_events()used a NULL or a zeroed timeout to mean "don't wait".io_getevents()uses a NULL timeout to mean "wait forever" and a zeroed timeout to mean "don't wait". Makeget_events()work likeio_getevents().Signed-off-by Benjamin Marzinski <[email protected]>--- libmultipath/checkers/directio.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Thank you.
Benjamin Marzinski
maintainerPATCH 5/5 libmultipath: cleanup old issues with directio checker
In reply to Benjamin MarzinskiThe directio checker manually aligns its directio buffer, instead of using posix_memalign(). It also defaults the block size for the read to 512, which may be too small for 4k devices, and it only waits for 5 ns for IO completion before giving up and setting the path to pending, which means that in will virtually always set the path to pending on the check when the IO is issued.
--- libmultipath/checkers/directio.c | 13 ++++--------- tests/directio.c | 1 - 2 files changed, 4 insertions(+), 10 deletions(-)
libmultipath/checkers/directio.c +4 -9
@@ -38,7 +38,6 @@ struct async_req {struct iocb io;unsigned int blksize;unsigned char * buf; -unsigned char * ptr;struct list_head node;int state;/* PATH_REMOVED means this is an orphan */ };
@@ -174,7 +173,7 @@ int libcheck_init (struct checker * c)if (ioctl (c->fd,BLKBSZGET , &req->blksize) <0 ) { c->msgid =MSG_DIRECTIO_BLOCKSIZE ; - req->blksize =512 ; + req->blksize =4096 ; }if (req->blksize >4096 ) {/*
@@ -185,8 +184,7 @@ int libcheck_init (struct checker * c)if (!req->blksize) goto out; - req->buf = (unsigned char *)malloc (req->blksize + pgsize); -if (!req->buf) +if (posix_memalign ((void **)&req->buf, pgsize, req->blksize) !=0 ) goto out; flags =fcntl (c->fd,F_GETFL );
@@ -199,9 +197,6 @@ int libcheck_init (struct checker * c) ct->reset_flags =1 ; } - req->ptr = (unsigned char *) (((unsigned long )req->buf + pgsize -1 ) & - (~(pgsize -1 ))); -/* Successfully initialized, return the context. */ ct->req = req; c->context = (void *) ct;
@@ -298,7 +293,7 @@ get_events(struct aio_group *aio_grp, struct timespec *timeout)static int check_state (int fd,struct directio_context *ct,int sync,int timeout_secs) { -struct timespec timeout = { .tv_nsec =5 }; +struct timespec timeout = { .tv_nsec =1000 };struct stat sb;int rc;long r;
@@ -323,7 +318,7 @@ check_state(int fd, struct directio_context *ct, int sync, int timeout_secs)LOG (3 ,"starting new request" );memset (&ct->req->io,0 ,sizeof (struct iocb )); -io_prep_pread (&ct->req->io, fd, ct->req->ptr, +io_prep_pread (&ct->req->io, fd, ct->req->buf, ct->req->blksize,0 ); ct->req->state =PATH_PENDING ;if (io_submit (ct->aio_grp->ioctx,1 , ios) !=1 ) {
tests/directio.c +0 -1
@@ -23,7 +23,6 @@#include <stddef.h> #include <setjmp.h> #include <stdlib.h> -#define UNIT_TESTING /* enable memory testing in directio.c */ #include <cmocka.h> #include "globals.c" #include "../libmultipath/checkers/directio.c"
Signature · 1 line
2.17.2
Re: [PATCH 5/5] libmultipath: cleanup old issues with directio checker
Quoted 10 lines · Benjamin Marzinski
The directio checker manually aligns its directio buffer, instead of using
posix_memalign(). It also defaults the block size for the read to
512, which may be too small for 4k devices, and it only waits for 5 ns
for IO completion before giving up and setting the path to pending, which means that in will virtually always set the path to pending on the
check when the IO is issued.
Quoted 6 lines
Signed-off-by Benjamin Marzinski <[email protected]>--- libmultipath/checkers/directio.c | 13 ++++--------- tests/directio.c | 1 - 2 files changed, 4 insertions(+), 10 deletions(-)