From patchwork Mon Apr 4 19:48:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: bmarzins@sourceware.org X-Patchwork-Id: 685351 Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p34JpTFU007083 for ; Mon, 4 Apr 2011 19:51:50 GMT 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 p34JmuGU007461; Mon, 4 Apr 2011 15:48:57 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p34JmutH008268 for ; Mon, 4 Apr 2011 15:48:56 -0400 Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.18]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p34Jmpj1031608 for ; Mon, 4 Apr 2011 15:48:51 -0400 Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by mx1.redhat.com (8.14.4/8.14.4) with SMTP id p34JmnH1027756 for ; Mon, 4 Apr 2011 15:48:49 -0400 Received: (qmail 3891 invoked by uid 9475); 4 Apr 2011 19:48:48 -0000 Date: 4 Apr 2011 19:48:48 -0000 Message-ID: <20110404194848.3889.qmail@sourceware.org> From: bmarzins@sourceware.org To: dm-cvs@sourceware.org, dm-devel@redhat.com X-RedHat-Spam-Score: -2.31 (RCVD_IN_DNSWL_MED,T_RP_MATCHES_RCVD) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.18 X-loop: dm-devel@redhat.com Subject: [dm-devel] multipath-tools libmultipath/lock.h libmultipa ... X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development 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-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 04 Apr 2011 19:52:08 +0000 (UTC) CVSROOT: /cvs/dm Module name: multipath-tools Branch: RHEL5_FC6 Changes by: bmarzins@sourceware.org 2011-04-04 19:48:47 Modified files: libmultipath : lock.h uevent.c multipathd : main.c Log message: Fix for bz #639429. It was possible for multipathd threads to access freed data during shutdown. Now the threads call pthread_testcancel() after acquiring the vecs->lock to make sure they immediately shutdown. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/multipath-tools/libmultipath/lock.h.diff?cvsroot=dm&only_with_tag=RHEL5_FC6&r1=1.1.2.1&r2=1.1.2.2 http://sourceware.org/cgi-bin/cvsweb.cgi/multipath-tools/libmultipath/uevent.c.diff?cvsroot=dm&only_with_tag=RHEL5_FC6&r1=1.4&r2=1.4.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/multipath-tools/multipathd/main.c.diff?cvsroot=dm&only_with_tag=RHEL5_FC6&r1=1.69.2.33&r2=1.69.2.34 --- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel --- multipath-tools/libmultipath/lock.h 2008/08/27 19:14:57 1.1.2.1 +++ multipath-tools/libmultipath/lock.h 2011/04/04 19:48:46 1.1.2.2 @@ -16,7 +16,7 @@ #else #define lock(a) pthread_mutex_lock(a) #define unlock(a) pthread_mutex_unlock(a) -#define lock_cleanup_pop(a) pthread_cleanup_pop(1); +#define lock_cleanup_pop(a) pthread_cleanup_pop(1) #endif void cleanup_lock (void * data); --- multipath-tools/libmultipath/uevent.c 2006/06/06 18:32:43 1.4 +++ multipath-tools/libmultipath/uevent.c 2011/04/04 19:48:46 1.4.2.1 @@ -100,6 +100,11 @@ } } +void cancel_thread(void * data) +{ + pthread_cancel((pthread_t)data); +} + int uevent_listen(int (*uev_trigger)(struct uevent *, void * trigger_data), void * trigger_data) { @@ -130,6 +135,7 @@ pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 64 * 1024); pthread_create(&uevq_thr, &attr, uevq_thread, NULL); + pthread_cleanup_push(cancel_thread, (void *)uevq_thr); memset(&snl, 0x00, sizeof(struct sockaddr_nl)); snl.nl_family = AF_NETLINK; @@ -255,7 +261,7 @@ close(sock); pthread_mutex_lock(uevq_lockp); - pthread_cancel(uevq_thr); + pthread_cleanup_pop(1); pthread_mutex_unlock(uevq_lockp); pthread_mutex_destroy(uevq_lockp); --- multipath-tools/multipathd/main.c 2011/03/07 05:19:38 1.69.2.33 +++ multipath-tools/multipathd/main.c 2011/04/04 19:48:46 1.69.2.34 @@ -82,6 +82,7 @@ pthread_cond_t exit_cond = PTHREAD_COND_INITIALIZER; pthread_mutex_t exit_mutex = PTHREAD_MUTEX_INITIALIZER; +int exitting = 0; /* * global copy of vecs for use in sig handlers */ @@ -648,6 +649,7 @@ pthread_cleanup_push(cleanup_lock, vecs->lock); lock(vecs->lock); + pthread_testcancel(); r = parse_cmd(str, reply, len, vecs); @@ -696,7 +698,9 @@ return 0; basenamecpy(uev->devpath, devname); + pthread_cleanup_push(cleanup_lock, vecs->lock); lock(vecs->lock); + pthread_testcancel(); /* * device map event @@ -736,6 +740,8 @@ out: unlock(vecs->lock); + lock_cleanup_pop(vecs->lock); +/* ; */ return r; } @@ -941,14 +947,15 @@ { int oldpriority; struct pathgroup * pgp; + struct path *pp1; int i, j, changed = 0; if (refresh_all) { vector_foreach_slot (pp->mpp->pg, pgp, i) { - vector_foreach_slot (pgp->paths, pp, j) { - oldpriority = pp->priority; - pathinfo(pp, conf->hwtable, DI_PRIO); - if (pp->priority != oldpriority) + vector_foreach_slot (pgp->paths, pp1, j) { + oldpriority = pp1->priority; + pathinfo(pp1, conf->hwtable, DI_PRIO); + if (pp1->priority != oldpriority) changed = 1; } } @@ -1012,6 +1019,7 @@ block_signal(SIGHUP, &old); pthread_cleanup_push(cleanup_lock, vecs->lock); lock(vecs->lock); + pthread_testcancel(); condlog(4, "tick"); vector_foreach_slot (vecs->pathvec, pp, i) { @@ -1497,7 +1505,8 @@ condlog(2, "reconfigure (SIGHUP)"); lock(gvecs->lock); - reconfigure(gvecs); + if (!exitting); + reconfigure(gvecs); unlock(gvecs->lock); #ifdef _DEBUG_ @@ -1698,6 +1707,7 @@ */ block_signal(SIGHUP, NULL); lock(vecs->lock); + exitting = 1; if (conf->queue_without_daemon == QUE_NO_DAEMON_OFF) vector_foreach_slot(vecs->mpvec, mpp, i) dm_queue_if_no_path(mpp->alias, 0);