From patchwork Wed Oct 12 08:54:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Wang X-Patchwork-Id: 9372253 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 B2B2360839 for ; Wed, 12 Oct 2016 08:56:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A141929366 for ; Wed, 12 Oct 2016 08:56:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95E4B29372; Wed, 12 Oct 2016 08:56:48 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID 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 D79BF29366 for ; Wed, 12 Oct 2016 08:56:47 +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 u9C8sNAJ022292; Wed, 12 Oct 2016 04:54:24 -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 u9C8s9fr011169 for ; Wed, 12 Oct 2016 04:54:09 -0400 Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9C8s9jQ020689 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 12 Oct 2016 04:54:09 -0400 Received: from mail-wm0-f54.google.com (mail-wm0-f54.google.com [74.125.82.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 991387F6A4 for ; Wed, 12 Oct 2016 08:54:07 +0000 (UTC) Received: by mail-wm0-f54.google.com with SMTP id c78so18475022wme.1 for ; Wed, 12 Oct 2016 01:54:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profitbricks-com.20150623.gappssmtp.com; s=20150623; h=to:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=6B7YVEptSYjOkVPFDR2EAN3Vgn4RtU+Uw6mqaa4B1P8=; b=wjiO7J8GTEbLKy0BpouONZjqvy3ICx/88oniP+QiEKPThg3FvkeaUQwek1TVqIc8i/ XD51mC02HlRonWBSdXTJeHtixcBNwQHHKbsR6k/IYnGxXg527FpbOD/hfsZLt3bqioP7 EeDo6/a/Gqn5EDAvpZryfgb7AgS8YxEUYSdacJg83P+xwqvdLgEuAFM3ZmMUvGUDNoB+ yV6zvXjNei+lXKhOk7B8wD5NjPd3tsMxWUrjDR01+X/IUADbvEzehIovG6ouKxEePEq1 UoEwC5pHLdZpI4xubK22XOFCcdbRe/Tf3kuI5mCi73s3hes73pCj3hElrFq9o+re53Db cF+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=6B7YVEptSYjOkVPFDR2EAN3Vgn4RtU+Uw6mqaa4B1P8=; b=jlaFg4ebJobzN53wfhNQyIScyqsjfCVNtpljnVF8AVSaUsDAUyIpWI9MkW6pIkOSIl 0XclEjiNoiUY+X/AdWarKmL0aMC/3xpTDQfvPUmIP5GS/FB32egQhWcbw03FgqLLBUR4 g0QN/Iu4LQ8PzLOCu8s2FvtRVN05KQ+6URyaJ6Z7ZezBLfI3cyydOGNIRf1yG2Bki1JH /6jzwEcf8JSbZVF/C9H3BNxRapDduomRNs8GkHurFmhWexMjYBshQawhKUKVBnE6R2S1 TkWBnTjaek33EYNw8oJfT7RB1JPwHi8IjsiIhDGbXZtoqOmaE0SSCgx+SsxCNJDdYDVl WDKg== X-Gm-Message-State: AA6/9RkWO6IHZvBSF3hGGRGR+81xn01IB7Slc5rZJIQ83PBufQuoiW8rD03ZUWq2EzGOH/il X-Received: by 10.194.75.165 with SMTP id d5mr7408wjw.190.1476262446342; Wed, 12 Oct 2016 01:54:06 -0700 (PDT) Received: from [192.168.71.52] ([62.217.45.26]) by smtp.googlemail.com with ESMTPSA id w131sm1730295wmf.15.2016.10.12.01.54.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Oct 2016 01:54:05 -0700 (PDT) To: dm-devel@redhat.com, christophe.varoqui@opensvc.com, tang.junhui@zte.com.cn From: Michael Wang Message-ID: Date: Wed, 12 Oct 2016 10:54:05 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 12 Oct 2016 08:54:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 12 Oct 2016 08:54:07 +0000 (UTC) for IP:'74.125.82.54' DOMAIN:'mail-wm0-f54.google.com' HELO:'mail-wm0-f54.google.com' FROM:'yun.wang@profitbricks.com' RCPT:'' X-RedHat-Spam-Score: 0.869 (BAYES_50, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 74.125.82.54 mail-wm0-f54.google.com 74.125.82.54 mail-wm0-f54.google.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.25 X-loop: dm-devel@redhat.com Subject: [dm-devel] [PATCH] multipath-tools: release lock on handler failure 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Virus-Scanned: ClamAV using ClamSMTP Inside parse_cmd() the pthread_cleanup_pop() rely on '!r' as the indicator of locked or not, while this will be overwritten if the handler return failed, and the unlock will be missing. This will lead into the situation that all the following operation will trying to hold a lock which will never be released. This patch using a separate flag to record the status of locking to make sure the unlock and lock are in pairs. Signed-off-by: Michael Wang --- multipathd/cli.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/multipathd/cli.c b/multipathd/cli.c index e8a9384..50161be 100644 --- a/multipathd/cli.c +++ b/multipathd/cli.c @@ -481,6 +481,7 @@ parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout ) tmo.tv_sec = 0; } if (h->locked) { + int locked = 0; struct vectors * vecs = (struct vectors *)data; pthread_cleanup_push(cleanup_lock, &vecs->lock); @@ -491,10 +492,11 @@ parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout ) r = 0; } if (r == 0) { + locked = 1; pthread_testcancel(); r = h->fn(cmdvec, reply, len, data); } - pthread_cleanup_pop(!r); + pthread_cleanup_pop(locked); } else r = h->fn(cmdvec, reply, len, data); free_keys(cmdvec);