From patchwork Wed Mar 1 17:22:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 9598847 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 122A7600CB for ; Wed, 1 Mar 2017 17:24:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF9DF2850F for ; Wed, 1 Mar 2017 17:24:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E455828518; Wed, 1 Mar 2017 17:24:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 33DB72850F for ; Wed, 1 Mar 2017 17:24:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v21HN1P6000894; Wed, 1 Mar 2017 12:23:02 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v21HN0TC008564 for ; Wed, 1 Mar 2017 12:23:00 -0500 Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v21HN0Z2014871 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 1 Mar 2017 12:23:00 -0500 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 916CD4E4C8 for ; Wed, 1 Mar 2017 17:22:59 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id EC962ABA2; Wed, 1 Mar 2017 17:22:54 +0000 (UTC) From: Martin Wilck To: tang.junhui@zte.com.cn, dm-devel@redhat.com Date: Wed, 1 Mar 2017 18:22:19 +0100 Message-Id: <20170301172219.9683-1-mwilck@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 202 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 01 Mar 2017 17:22:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 01 Mar 2017 17:22:59 +0000 (UTC) for IP:'195.135.220.15' DOMAIN:'mx2.suse.de' HELO:'mx2.suse.de' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -1.901 (BAYES_50, DCC_REPUT_00_12, RCVD_IN_DNSWL_MED, SPF_PASS) 195.135.220.15 mx2.suse.de 195.135.220.15 mx2.suse.de X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-loop: dm-devel@redhat.com Subject: [dm-devel] [PATCH] uevent_can_discard: optimize devpath check X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Virus-Scanned: ClamAV using ClamSMTP This uses roughly 10% cycles of the sscanf-based implementation. Improves: ee8888f0 "multipath-tools: improve processing efficiency..." Signed-off-by: Martin Wilck --- 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