From patchwork Thu Mar 2 12:54:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_B=C3=B6hmwalder?= X-Patchwork-Id: 63411 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp4221416wrd; Thu, 2 Mar 2023 05:03:35 -0800 (PST) X-Google-Smtp-Source: AK7set9MvwQi++khqpK3RuAcKqRMEeZGaoho34jJWL1YBAElbV5/nDBzWgmOkdiE/sbt2naj8uu4 X-Received: by 2002:a17:903:70c:b0:19c:92f5:69b0 with SMTP id kk12-20020a170903070c00b0019c92f569b0mr8742454plb.40.1677762215649; Thu, 02 Mar 2023 05:03:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677762215; cv=none; d=google.com; s=arc-20160816; b=eC4DvrsIdbMxS61odbegH/EapfPID2RQGK6IGQ0fBmLSRu0isGM0x/VY3w3f1xtsIu P8KEU0SUBzMI/dn0UK2huTZwRXosTEClOGnf9oDjpYznocftXPy+ducO9V2ihM8IOyWD ITnn47kY0xh0jr7UhWYRIZc5bxircaFxH7vtGsIhmcXLWhSvhq15EL8in9kSY2KFZaqx wBkhyhsAhQdHxR8f9CgjACpVZlJ1/GNmCH8AKYeHR1+1z+m66GvVy7uE0GXLMdBjCWOd 6yuqpvia72vowGSCsasRyciaVkRvVQhoFGGAOzuGo6WtwfiAl9QvTBtYgum8OMbOTKr2 J33w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4P+RPLywpWRpuXMP+b0VdhJHn8q4YXA5NPmEVVhViGs=; b=xMiKxZO2BNMV4bfmR5mL/PQRzh+qrgBcjpsuHl6i+1vDTjFumt0n2BaQdbuLb45Vb2 ThV/Z63l7P+bYHKRF3sYkvWulleJ7yP4lgFJWv0UxIXxmyCNfC4m41eNaDgBtT5QxSqF xNPhUUS9EJgspxiMZGYOBYr8eERsQ9ECdlpPjiSHtzxDk2g5RerY5QRSqRGSBbw5GGsZ BkiRvnOgUROWooP8Dmjn8uiUaPWu+YbVdRTVZ+63N083DVDiZwVkccrh4pntDFWN8RQs GJTxacQ03WnnbYRKPXzj+LjPVnMIg4wiF6Hqq92RS3/nBKCfKe22aZlQiJ0yrcpk9XKE tbzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linbit-com.20210112.gappssmtp.com header.s=20210112 header.b=xsbXLGVM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p5-20020a63fe05000000b004fbcfd0788esi1017578pgh.308.2023.03.02.05.03.20; Thu, 02 Mar 2023 05:03:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linbit-com.20210112.gappssmtp.com header.s=20210112 header.b=xsbXLGVM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229948AbjCBMzd (ORCPT + 99 others); Thu, 2 Mar 2023 07:55:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229751AbjCBMza (ORCPT ); Thu, 2 Mar 2023 07:55:30 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 227EEAD34 for ; Thu, 2 Mar 2023 04:55:28 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id o12so67112075edb.9 for ; Thu, 02 Mar 2023 04:55:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linbit-com.20210112.gappssmtp.com; s=20210112; t=1677761726; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4P+RPLywpWRpuXMP+b0VdhJHn8q4YXA5NPmEVVhViGs=; b=xsbXLGVMB0BEySbmuZ4OPbz54jIQrq9L8n+vgdNwdHVZChDW1eXmofRZ2XwzaUaDes Fe6ThvsEHdUip+LQxNazRFqukSssQRL2GDL4p4Gs3PzGLXtttvg5UC5cUj4dQfblsn+0 AhUsqK/EZP7w8hKhMxwj4L4LTeQ6vhwpguMpWc49rpHZNvTptUZRRYk7WZEiaYVBs3aO GXOujLfVO0z5FhPSbeyIsAgyTX9E7t05/+9jdjBZSXWFQ4IF2bpl638GSsA1WqdrpSRi IHgaDSorhNPpMGp2hK3GqLZcNboSRr3S5UV2DrCmn4XtZ+RifH66LMMMgIwc0LFh7GMm dgRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677761726; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4P+RPLywpWRpuXMP+b0VdhJHn8q4YXA5NPmEVVhViGs=; b=RtESvVvznk7H+KsDehgffCCvgUw8Rf2D+9hvsIBpFMZ4vDBYIOk02f0RxFBraHle0/ oBxlm3jN+eahHqx0MVyTxrlWSCDm9g3uN766pDocTtTbeQDiICQweCfGMa2RvBS+Q3uU UmMwlYPH0FrDTysaw3sd000iYVbUEzu/amfvvggSaNljV8Pxqa0piXEhGh9APDBI8TXN m4cJo8szZbfWwN0Pf7A0uJcNlELlpAHGbtlhEcU+nnslitVwRHIublPbV0OBOPzkjAtJ 2nH//eLwri6IzenVsYfkN1N3kvGsBhb2ETYD9Rx2P/tZgLGYs7GsaxDIK8OTN8mKDK0X pC1w== X-Gm-Message-State: AO0yUKWwYvmlJzmSaUzM5wrajMt7n99mR2B6YQ7nAMVvAB/pe1bmjdiK 03KVpwLkpkfGYTmU5K6yxJ2Aag== X-Received: by 2002:aa7:d612:0:b0:4c0:9bd7:54cc with SMTP id c18-20020aa7d612000000b004c09bd754ccmr1244162edr.11.1677761726641; Thu, 02 Mar 2023 04:55:26 -0800 (PST) Received: from localhost.localdomain (h082218028181.host.wavenet.at. [82.218.28.181]) by smtp.gmail.com with ESMTPSA id a98-20020a509eeb000000b004ad601533a3sm6955034edf.55.2023.03.02.04.55.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 04:55:26 -0800 (PST) From: =?utf-8?q?Christoph_B=C3=B6hmwalder?= To: Jens Axboe Cc: drbd-dev@lists.linbit.com, linux-kernel@vger.kernel.org, Lars Ellenberg , Philipp Reisner , linux-block@vger.kernel.org, Andreas Gruenbacher , =?utf-8?q?Christoph_B=C3=B6hmwalde?= =?utf-8?q?r?= Subject: [PATCH v2 2/7] drbd: Rip out the ERR_IF_CNT_IS_NEGATIVE macro Date: Thu, 2 Mar 2023 13:54:40 +0100 Message-Id: <20230302125445.2653493-3-christoph.boehmwalder@linbit.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230302125445.2653493-1-christoph.boehmwalder@linbit.com> References: <20230302125445.2653493-1-christoph.boehmwalder@linbit.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759261192969802651?= X-GMAIL-MSGID: =?utf-8?q?1759261192969802651?= From: Andreas Gruenbacher Signed-off-by: Andreas Gruenbacher Signed-off-by: Christoph Böhmwalder --- drivers/block/drbd/drbd_int.h | 37 ++++++++++++++--------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h index d89b7d03d4c8..772023ace749 100644 --- a/drivers/block/drbd/drbd_int.h +++ b/drivers/block/drbd/drbd_int.h @@ -1918,18 +1918,14 @@ static inline void inc_ap_pending(struct drbd_device *device) atomic_inc(&device->ap_pending_cnt); } -#define ERR_IF_CNT_IS_NEGATIVE(which, func, line) \ - if (atomic_read(&device->which) < 0) \ - drbd_err(device, "in %s:%d: " #which " = %d < 0 !\n", \ - func, line, \ - atomic_read(&device->which)) - -#define dec_ap_pending(device) _dec_ap_pending(device, __func__, __LINE__) -static inline void _dec_ap_pending(struct drbd_device *device, const char *func, int line) +#define dec_ap_pending(device) ((void)expect((device), __dec_ap_pending(device) >= 0)) +static inline int __dec_ap_pending(struct drbd_device *device) { - if (atomic_dec_and_test(&device->ap_pending_cnt)) + int ap_pending_cnt = atomic_dec_return(&device->ap_pending_cnt); + + if (ap_pending_cnt == 0) wake_up(&device->misc_wait); - ERR_IF_CNT_IS_NEGATIVE(ap_pending_cnt, func, line); + return ap_pending_cnt; } /* counts how many resync-related answers we still expect from the peer @@ -1943,11 +1939,10 @@ static inline void inc_rs_pending(struct drbd_device *device) atomic_inc(&device->rs_pending_cnt); } -#define dec_rs_pending(device) _dec_rs_pending(device, __func__, __LINE__) -static inline void _dec_rs_pending(struct drbd_device *device, const char *func, int line) +#define dec_rs_pending(device) ((void)expect((device), __dec_rs_pending(device) >= 0)) +static inline int __dec_rs_pending(struct drbd_device *device) { - atomic_dec(&device->rs_pending_cnt); - ERR_IF_CNT_IS_NEGATIVE(rs_pending_cnt, func, line); + return atomic_dec_return(&device->rs_pending_cnt); } /* counts how many answers we still need to send to the peer. @@ -1964,18 +1959,16 @@ static inline void inc_unacked(struct drbd_device *device) atomic_inc(&device->unacked_cnt); } -#define dec_unacked(device) _dec_unacked(device, __func__, __LINE__) -static inline void _dec_unacked(struct drbd_device *device, const char *func, int line) +#define dec_unacked(device) ((void)expect(device, __dec_unacked(device) >= 0)) +static inline int __dec_unacked(struct drbd_device *device) { - atomic_dec(&device->unacked_cnt); - ERR_IF_CNT_IS_NEGATIVE(unacked_cnt, func, line); + return atomic_dec_return(&device->unacked_cnt); } -#define sub_unacked(device, n) _sub_unacked(device, n, __func__, __LINE__) -static inline void _sub_unacked(struct drbd_device *device, int n, const char *func, int line) +#define sub_unacked(device, n) ((void)expect(device, __sub_unacked(device) >= 0)) +static inline int __sub_unacked(struct drbd_device *device, int n) { - atomic_sub(n, &device->unacked_cnt); - ERR_IF_CNT_IS_NEGATIVE(unacked_cnt, func, line); + return atomic_sub_return(n, &device->unacked_cnt); } static inline bool is_sync_target_state(enum drbd_conns connection_state)