From patchwork Wed May 11 10:35:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 9067781 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 38DF99F372 for ; Wed, 11 May 2016 10:42:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4153E20154 for ; Wed, 11 May 2016 10:42:28 +0000 (UTC) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3FDE7200F2 for ; Wed, 11 May 2016 10:42:27 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u4BAaLbh010662; Wed, 11 May 2016 06:36:22 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u4BAZk9k009037 for ; Wed, 11 May 2016 06:35:46 -0400 Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4BAZkqR018083 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 11 May 2016 06:35:46 -0400 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 D664A37EEB; Wed, 11 May 2016 10:35:44 +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 9E77BABF7; Wed, 11 May 2016 10:35:42 +0000 (UTC) From: Hannes Reinecke To: Christophe Varoqui Date: Wed, 11 May 2016 12:35:41 +0200 Message-Id: <1462962941-9429-1-git-send-email-hare@suse.de> X-Greylist: Sender IP whitelisted by DNSRBL, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 11 May 2016 10:35:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 11 May 2016 10:35:45 +0000 (UTC) for IP:'195.135.220.15' DOMAIN:'mx2.suse.de' HELO:'mx2.suse.de' FROM:'hare@suse.de' RCPT:'' X-RedHat-Spam-Score: -3.317 (BAYES_50, DCC_REPUT_00_12, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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.26 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-loop: dm-devel@redhat.com Cc: Hannes Reinecke , dm-devel@redhat.com Subject: [dm-devel] multipathd: move 'filter_devnode' under vector lock 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-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Ben Marzinski pointed out that filter_devnode() is used without any lock or configuration settings in uev_trigger(), and hence might be invalid when processing events during reconfiguration. So move it into the individual functions and handle it with the vector lock held. Signed-off-by: Hannes Reinecke --- multipathd/main.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 58e8854..2c7486d 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -580,6 +580,11 @@ uev_add_path (struct uevent *uev, struct vectors * vecs) pthread_cleanup_push(cleanup_lock, &vecs->lock); lock(vecs->lock); pthread_testcancel(); + if (filter_devnode(conf->blist_devnode, conf->elist_devnode, + uev->kernel) > 0) { + ret = 0; + goto out_unlock; + } pp = find_path_by_dev(vecs->pathvec, uev->kernel); if (pp) { int r; @@ -637,6 +642,7 @@ uev_add_path (struct uevent *uev, struct vectors * vecs) free_path(pp); ret = 1; } +out_unlock: lock_cleanup_pop(vecs->lock); return ret; } @@ -780,22 +786,23 @@ fail: static int uev_remove_path (struct uevent *uev, struct vectors * vecs) { - struct path *pp; - int ret; + struct path *pp = NULL; + int ret = 0; condlog(2, "%s: remove path (uevent)", uev->kernel); pthread_cleanup_push(cleanup_lock, &vecs->lock); lock(vecs->lock); pthread_testcancel(); - pp = find_path_by_dev(vecs->pathvec, uev->kernel); - if (pp) - ret = ev_remove_path(pp, vecs); - lock_cleanup_pop(vecs->lock); - if (!pp) { - /* Not an error; path might have been purged earlier */ - condlog(0, "%s: path already removed", uev->kernel); - return 0; + if (filter_devnode(conf->blist_devnode, conf->elist_devnode, + uev->kernel) == 0) { + pp = find_path_by_dev(vecs->pathvec, uev->kernel); + if (pp) + ret = ev_remove_path(pp, vecs); + else + /* Not an error; path might have been purged earlier */ + condlog(0, "%s: path already removed", uev->kernel); } + lock_cleanup_pop(vecs->lock); return ret; } @@ -905,7 +912,7 @@ uev_update_path (struct uevent *uev, struct vectors * vecs) ro = uevent_get_disk_ro(uev); if (ro >= 0) { - struct path * pp; + struct path * pp = NULL; struct multipath *mpp = NULL; condlog(2, "%s: update path write_protect to '%d' (uevent)", @@ -918,6 +925,10 @@ uev_update_path (struct uevent *uev, struct vectors * vecs) * need to be at the same indentation level, hence * this slightly convoluted codepath. */ + if (filter_devnode(conf->blist_devnode, conf->elist_devnode, + uev->kernel) > 0) { + goto out_unlock; + } pp = find_path_by_dev(vecs->pathvec, uev->kernel); if (pp) { if (pp->initialized == INIT_REQUESTED_UDEV) { @@ -937,11 +948,13 @@ uev_update_path (struct uevent *uev, struct vectors * vecs) uev->kernel, mpp->alias, retval); } } + out_unlock: lock_cleanup_pop(vecs->lock); if (!pp) { - condlog(0, "%s: spurious uevent, path not found", - uev->kernel); - return 1; + if (retval) + condlog(0, "%s: spurious uevent, path not found", + uev->kernel); + return retval; } if (retval == 2) return uev_add_path(uev, vecs); @@ -1059,10 +1072,6 @@ uev_trigger (struct uevent * uev, void * trigger_data) /* * path add/remove event */ - if (filter_devnode(conf->blist_devnode, conf->elist_devnode, - uev->kernel) > 0) - goto out; - if (!strncmp(uev->action, "add", 3)) { r = uev_add_path(uev, vecs); goto out;