Received: by 10.213.65.68 with SMTP id h4csp1452317imn; Thu, 29 Mar 2018 05:07:50 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/ck1TcPil3F0Y5GCZOA1ksUSmmtKM6/ZpmWT4DyoEqggwm+Pengs9DjTEBETRirdlvZ4ER X-Received: by 2002:a17:902:8bc2:: with SMTP id r2-v6mr8002773plo.169.1522325270421; Thu, 29 Mar 2018 05:07:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522325270; cv=none; d=google.com; s=arc-20160816; b=Ql1RTgqQHPgXQDA8s8QA9BrLA8auJ3OyjtqST48J9B8hR3mlnyFVTG9WOwjchQkS5e NBxRP8aXODcTpYWkf2cNCXOlXo5lndxHr6wvCUcjgqp3Wq5/MiBOj6Eu6P7iOsVt6qwZ qysT2ImMcY9bJGjYooVyzWtD/wOH32h7lZNbHmhqiLrYYpfJ3Mn1KWj9E8ZrQYQz8W8P wY3GiLyG86VL+oMgOH9gvRtcpSJrAqtyyW8LB6lyXUDd7SQJsXwPbePXQRmFmisPHsqL fB7bjT6KUA77rL3XL2/s5wIZpCiFJpi8IoIlNTN3WIBan2RL+rW6nZDv+O99ogcVEp0i G4Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=h/PBZv0LhubFVR7HJfy2g0TjwrzaA3OLE4OumxqmORo=; b=xn8KHptWfONzSbCNj6BktIXAACyt30Rjb3GQLNkIUsgF+WQBC6sVoAgcchQSJUWBIk WM7FGdbKRcy3sE8SABHU3KbAsDP3Fp47ONt2FbnpEPSYlz0xm03cwIEhuWBsGQSUrbVb gGJWB5BIMlem6Rp2M/ORKXN+4kH5tTLzd9Q4aOg3ymbfvy6M/97JOis8m92JcZIvNbD2 DfEXBPjIi/Jmq9vbay2JFEid6iYcsa27M4nYnbCCWfH3u23/jmYI44HVXfetsjQPwgdu NuMm7//S9kgPLaCnEYZBUSiQdnWSXuYz1nZOfKqmyaiVlbe9iG84rZxd3cAYVYk0YYN5 Grjw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 61-v6si5840424plz.630.2018.03.29.05.07.36; Thu, 29 Mar 2018 05:07:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752846AbeC2MGW (ORCPT + 99 others); Thu, 29 Mar 2018 08:06:22 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52744 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752300AbeC2MGU (ORCPT ); Thu, 29 Mar 2018 08:06:20 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 16499406E8A4; Thu, 29 Mar 2018 12:06:20 +0000 (UTC) Received: from max.home.com (ovpn-117-14.ams2.redhat.com [10.36.117.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE3A3215CDC5; Thu, 29 Mar 2018 12:06:18 +0000 (UTC) From: Andreas Gruenbacher To: cluster-devel@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, NeilBrown , Thomas Graf , Herbert Xu , Tom Herbert , Andreas Gruenbacher Subject: [PATCH v2 1/2] lockref: Add lockref_put_not_zero Date: Thu, 29 Mar 2018 14:06:11 +0200 Message-Id: <20180329120612.6104-2-agruenba@redhat.com> In-Reply-To: <20180329120612.6104-1-agruenba@redhat.com> References: <20180329120612.6104-1-agruenba@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 29 Mar 2018 12:06:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 29 Mar 2018 12:06:20 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'agruenba@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Put a lockref unless the lockref is dead or its count would become zero. This is the same as lockref_put_or_lock except that the lock is never left held. Signed-off-by: Andreas Gruenbacher --- include/linux/lockref.h | 1 + lib/lockref.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/linux/lockref.h b/include/linux/lockref.h index 2eac32095113..99f17cc8e163 100644 --- a/include/linux/lockref.h +++ b/include/linux/lockref.h @@ -37,6 +37,7 @@ struct lockref { extern void lockref_get(struct lockref *); extern int lockref_put_return(struct lockref *); extern int lockref_get_not_zero(struct lockref *); +extern int lockref_put_not_zero(struct lockref *); extern int lockref_get_or_lock(struct lockref *); extern int lockref_put_or_lock(struct lockref *); diff --git a/lib/lockref.c b/lib/lockref.c index 47169ed7e964..3d468b53d4c9 100644 --- a/lib/lockref.c +++ b/lib/lockref.c @@ -80,6 +80,34 @@ int lockref_get_not_zero(struct lockref *lockref) } EXPORT_SYMBOL(lockref_get_not_zero); +/** + * lockref_put_not_zero - Decrements count unless count <= 1 before decrement + * @lockref: pointer to lockref structure + * Return: 1 if count updated successfully or 0 if count would become zero + */ +int lockref_put_not_zero(struct lockref *lockref) +{ + int retval; + + CMPXCHG_LOOP( + new.count--; + if (old.count <= 1) + return 0; + , + return 1; + ); + + spin_lock(&lockref->lock); + retval = 0; + if (lockref->count > 1) { + lockref->count--; + retval = 1; + } + spin_unlock(&lockref->lock); + return retval; +} +EXPORT_SYMBOL(lockref_put_not_zero); + /** * lockref_get_or_lock - Increments count unless the count is 0 or dead * @lockref: pointer to lockref structure -- 2.14.3