uevent_can_discard: optimize devpath check
PATCH 1/1 uevent_can_discard: optimize devpath check
This uses roughly 10% cycles of the sscanf-based implementation.
Improves: ee8888f0 "multipath-tools: improve processing efficiency..."
--- libmultipath/uevent.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-)
libmultipath/uevent.c +23 -14
@@ -143,26 +143,35 @@ uevent_need_merge(void)return need_merge; } +static bool +uevent_can_discard_by_devpath (const char *devpath) +{ +static const char BLOCK [] ="/block/" ; +const char *tmp =strstr (devpath,BLOCK ); + +if (tmp ==NULL ) { +condlog (4 ,"no /block/ in '%s'" , devpath); +return true; + } + tmp +=sizeof (BLOCK ) -1 ; +if (*tmp =='\0' ) +/* just ".../block/" - discard */ +return true; +/* +* If there are more path elements after ".../block/xyz", +* it's a partition - discard it; but don't discard ".../block/sda/". +*/ + tmp =strchr (tmp,'/' ); +return tmp !=NULL && *(tmp +1 ) !='\0' ; +} +bool uevent_can_discard (struct uevent *uev) { -char *tmp; -char a[11 ], b[11 ];struct config * conf; -/* -* keep only block devices, discard partitions -*/ - tmp =strstr (uev->devpath,"/block/" ); -if (tmp ==NULL ){ -condlog (4 ,"no /block/ in '%s'" , uev->devpath); +if (uevent_can_discard_by_devpath (uev->devpath))return true; - } -if (sscanf (tmp,"/block/%10s" , a) !=1 || -sscanf (tmp,"/block/%10[^/]/%10s" , a, b) ==2 ) { -condlog (4 ,"discard event on %s" , uev->devpath); -return true; - }/* * do not filter dm devices by devnode
Signature · 1 line
2.12.0
It looks fine to me.
Regards,
Tang Junhui
> This uses roughly 10% cycles of the sscanf-based implementation.
>
> Improves: ee8888f0 "multipath-tools: improve processing efficiency..."
> Signed-off-by: Martin Wilck <[email protected]>
> ---
> libmultipath/uevent.c | 37 +++++++++++++++++++++++--------------
> 1 file changed, 23 insertions(+), 14 deletions(-)
>
> diff --git a/libmultipath/uevent.c b/libmultipath/uevent.c
> index 6e2527bd..367e129a 100644
> --- a/libmultipath/uevent.c
> +++ b/libmultipath/uevent.c
> @@ -143,26 +143,35 @@ uevent_need_merge(void)
> return need_merge
> }
>
> +static bool
> +uevent_can_discard_by_devpath(const char *devpath)
> +{
> + static const char BLOCK[] = "/block/"
> + const char *tmp = strstr(devpath, BLOCK)
> +
> + if (tmp == NULL) {
> + condlog(4, "no /block/ in '%s'", devpath)
> + return true
> + }
> + tmp += sizeof(BLOCK) - 1
> + if (*tmp == '\0')
> + /* just ".../block/" - discard */
> + return true
> + /*
> + * If there are more path elements after ".../block/xyz",
> + * it's a partition - discard it but don't discard ".../block/sda/".
> + */
> + tmp = strchr(tmp, '/')
> + return tmp != NULL && *(tmp + 1) != '\0'
> +}
> +
> bool
> uevent_can_discard(struct uevent *uev)
> {
> - char *tmp
> - char a[11], b[11]
> struct config * conf
>
> - /*
> - * keep only block devices, discard partitions
> - */
> - tmp = strstr(uev->devpath, "/block/")
> - if (tmp == NULL){
> - condlog(4, "no /block/ in '%s'", uev->devpath)
> + if (uevent_can_discard_by_devpath(uev->devpath))
> return true
> - }
> - if (sscanf(tmp, "/block/%10s", a) != 1 ||
> - sscanf(tmp, "/block/%10[^/]/%10s", a, b) == 2) {
> - condlog(4, "discard event on %s", uev->devpath)
> - return true
> - }
>
> /*
> * do not filter dm devices by devnode
> --
> 2.12.0
Christophe Varoqui
AppliedApplied.
Thanks.
Quoted 71 lines · Martin Wilck
This uses roughly 10% cycles of the sscanf-based implementation.
Improves:
ee8888f0"multipath-tools: improve processing efficiency..."Signed-off-by Martin Wilck <[email protected]>--- libmultipath/uevent.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-)libmultipath/uevent.c +17
-0@@ -143,26 +143,35 @@ uevent_need_merge(void)return need_merge; } +static bool +uevent_can_discard_by_devpath (const char *devpath) +{ +static const char BLOCK [] ="/block/" ; +const char *tmp =strstr (devpath,BLOCK ); + +if (tmp ==NULL ) { +condlog (4 ,"no /block/ in '%s'" , devpath); +return true; + } + tmp +=sizeof (BLOCK ) -1 ; +if (*tmp =='\0' ) +/* just ".../block/" - discard */ +return true; +/* +* If there are more path elements after ".../block/xyz", +* it's a partition - discard it; but don't discard ".../block/sda/".
libmultipath/uevent.c +6
-15+*/ + tmp =strchr (tmp,'/' ); +return tmp !=NULL && *(tmp +1 ) !='\0' ; +} +bool uevent_can_discard (struct uevent *uev) { -char *tmp; -char a[11 ], b[11 ];struct config * conf; -/* -* keep only block devices, discard partitions -*/ - tmp =strstr (uev->devpath,"/block/" ); -if (tmp ==NULL ){ -condlog (4 ,"no /block/ in '%s'" , uev->devpath); +if (uevent_can_discard_by_devpath (uev->devpath))return true; - } -if (sscanf (tmp,"/block/%10s" , a) !=1 || -sscanf (tmp,"/block/%10[^/]/%10s" , a, b) ==2 ) { -condlog (4 ,"discard event on %s" , uev->devpath); -return true; - }/* * do not filter dm devices by devnode -- 2.12.0
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel