From patchwork Thu Jan 12 05:52:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tang.junhui@zte.com.cn X-Patchwork-Id: 9512165 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 171E660710 for ; Thu, 12 Jan 2017 06:01:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 075F528631 for ; Thu, 12 Jan 2017 06:01:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F04DE28635; Thu, 12 Jan 2017 06:01:45 +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 57BFB28631 for ; Thu, 12 Jan 2017 06:01:44 +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 v0C60dq9057093; Thu, 12 Jan 2017 01:00:39 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v0C60T72010591 for ; Thu, 12 Jan 2017 01:00:29 -0500 Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0C60Tn8031243 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 12 Jan 2017 01:00:29 -0500 Received: from out1.zte.com.cn (out1.zte.com.cn [202.103.147.172]) by mx1.redhat.com (Postfix) with ESMTP id 431C981231 for ; Thu, 12 Jan 2017 06:00:26 +0000 (UTC) X-MAILFROM: X-RCPTTO: X-FROMIP: 10.30.3.20 X-SEG-Scaned: 1 X-Received: unknown,10.30.3.20,20170112134527 Received: from unknown (HELO mse01.zte.com.cn) (10.30.3.20) by localhost with (AES256-SHA encrypted) SMTP; 12 Jan 2017 05:45:27 -0000 Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id v0C5rW2E044882; Thu, 12 Jan 2017 13:53:32 +0800 (GMT-8) (envelope-from tang.junhui@zte.com.cn) Received: from localhost.localdomain ([10.118.202.203]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2017011213533765-1137464 ; Thu, 12 Jan 2017 13:53:37 +0800 From: tang.junhui@zte.com.cn To: christophe.varoqui@opensvc.com, bmarzins@redhat.com, hare@suse.de, mwilck@suse.com, bart.vanassche@sandisk.com Date: Thu, 12 Jan 2017 13:52:22 +0800 Message-Id: <1484200347-11188-7-git-send-email-tang.junhui@zte.com.cn> In-Reply-To: <1484200347-11188-1-git-send-email-tang.junhui@zte.com.cn> References: <1484200347-11188-1-git-send-email-tang.junhui@zte.com.cn> X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-01-12 13:53:37, Serialize by Router on notes_smtp/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-01-12 13:53:32, Serialize complete at 2017-01-12 13:53:32 X-MAIL: mse01.zte.com.cn v0C5rW2E044882 X-HQIP: 127.0.0.1 X-Greylist: Delayed for 00:06:44 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 12 Jan 2017 06:00:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 12 Jan 2017 06:00:28 +0000 (UTC) for IP:'202.103.147.172' DOMAIN:'out1.zte.com.cn' HELO:'out1.zte.com.cn' FROM:'tang.junhui@zte.com.cn' RCPT:'' X-RedHat-Spam-Score: -2.8 (BAYES_50, DCC_REPUT_00_12, RP_MATCHES_RCVD, SPF_PASS) 202.103.147.172 out1.zte.com.cn 202.103.147.172 out1.zte.com.cn X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.25 X-loop: dm-devel@redhat.com Cc: zhang.kai16@zte.com.cn, dm-devel@redhat.com, tang.junhui@zte.com.cn, tang.wenjun3@zte.com.cn Subject: [dm-devel] [PATCH 06/11] multipathd: move uev_discard() to uevent.c and change its name to uevent_can_discard() 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 From: tang.junhui This patch is mainly done to adjust the code for the preparation of uevents merging. Change-Id: Iaac159ffe3930e53c3325d1069c3ed497e440c0c Signed-off-by: tang.wenjun --- libmultipath/uevent.c | 40 ++++++++++++++++++++++++++++++++++++++++ multipathd/main.c | 25 ------------------------- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/libmultipath/uevent.c b/libmultipath/uevent.c index 9b6b1d1..d6c02a6 100644 --- a/libmultipath/uevent.c +++ b/libmultipath/uevent.c @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -80,6 +81,44 @@ struct uevent * alloc_uevent (void) return uev; } +bool +uevent_can_discard(struct uevent *uev) +{ + char *tmp; + char a[11], b[11]; + + /* + * keep only block devices, discard partitions + */ + tmp = strstr(uev->devpath, "/block/"); + if (tmp == NULL){ + condlog(4, "no /block/ in '%s'", 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; + } + + return false; +} + +void +uevent_discard(struct list_head *tmpq) +{ + struct uevent *uev, *tmp; + + list_for_each_entry_reverse_safe(uev, tmp, tmpq, node) { + if (uevent_can_discard(uev)) { + list_del_init(&uev->node); + if (uev->udev) + udev_device_unref(uev->udev); + FREE(uev); + } + } +} + void service_uevq(struct list_head *tmpq) { @@ -144,6 +183,7 @@ int uevent_dispatch(int (*uev_trigger)(struct uevent *, void * trigger_data), pthread_mutex_unlock(uevq_lockp); if (!my_uev_trigger) break; + uevent_discard(&uevq_tmp); service_uevq(&uevq_tmp); } condlog(3, "Terminating uev service queue"); diff --git a/multipathd/main.c b/multipathd/main.c index 718c5e7..66d5c3d 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -1115,28 +1115,6 @@ uxsock_trigger (char * str, char ** reply, int * len, void * trigger_data) return r; } -static int -uev_discard(char * devpath) -{ - char *tmp; - char a[11], b[11]; - - /* - * keep only block devices, discard partitions - */ - tmp = strstr(devpath, "/block/"); - if (tmp == NULL){ - condlog(4, "no /block/ in '%s'", devpath); - return 1; - } - if (sscanf(tmp, "/block/%10s", a) != 1 || - sscanf(tmp, "/block/%10[^/]/%10s", a, b) == 2) { - condlog(4, "discard event on %s", devpath); - return 1; - } - return 0; -} - int uev_trigger (struct uevent * uev, void * trigger_data) { @@ -1146,9 +1124,6 @@ uev_trigger (struct uevent * uev, void * trigger_data) vecs = (struct vectors *)trigger_data; - if (uev_discard(uev->devpath)) - return 0; - pthread_cleanup_push(config_cleanup, NULL); pthread_mutex_lock(&config_lock); if (running_state != DAEMON_IDLE &&