Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp807715lqt; Thu, 6 Jun 2024 21:32:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVDxhfVRz43llX7BPQff3c6ZLJ9YsypElIvYlBZD8UWoMUNL5O6nZYILoaNPHZ+TDzr/paD7Zwu35crz6alZj+/DWAQo4bDbIjv1wzhuw== X-Google-Smtp-Source: AGHT+IF6aoYlkvDLKmpmg3T351O2OGyvet1yxBlMT/fA6qs0Wdfc4wIG1U+QWEA/EnFHJ9OmyRZj X-Received: by 2002:a05:6358:5917:b0:18a:6074:90d1 with SMTP id e5c5f4694b2df-19f1fee1cb9mr197432155d.19.1717734744556; Thu, 06 Jun 2024 21:32:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717734744; cv=pass; d=google.com; s=arc-20160816; b=eV1eCYf8SM6qFSl+vkf7XN/onjrFZCXM3Au41NQvSj8t3n5thIw31sZduCOPXDCU7b uiZBQWQbmeFQootTmdh9pV6UZGl5H1GS7rmtz5BDQPra2g3Fm1kA2mPed8Xfkbo3xRH5 gmwuNbqEBOMs2JdZwycLqkxTsPMvsIqyIVzJPV9mwAtZ/o2BoYBEjbbtGa+t9ojr9ffx E5yXQvqCY8grhpXS8cflrE50kPtVAsbgw4xhXd/uAF9nZ9WVLBGbgiy63gOLiz+nOTCZ NiW0q18zBSy/byquyQIAmEQrZITCf9aHIjMB82LmFrUPSawHJTD1Db8Rzceu4OFobzWU ep1A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=ajUxmoKCoUKocGGpNkzlCxxaZ7aLu882boufzecZrxI=; fh=yXYChwFvQA/NaaLzCC0IJdkW11OhjXgO4DHXzVmnGFw=; b=XBEW3VhuXZCl1E6EYIuj8N7Pc2UuLsBxK6Xqg40LAEuz9VFQ2w6OpHKYcI94AW/N+/ H1oqjpllg+8VKM87GVnIz4kNEyzmcuOYKwCvNvoLy2eG++NK5F5ZXcTrg/rKDmbvwKr9 knW7HYu8rdLOz1JURQxcsyqb6vLnQ/ij7QHAqgU5bUJXJ0c7XCs6GX7o5BF3LqeL9cy9 gNk0yj0+v66rYu+9aeDHa7+Vv54TlrePY59vgG68nLcH8gBkpEz+0sZzF1atr+Sh0wZP irizyhAHnHZwQIttyIE1nkxRAd52aLNfJXHITbx95AoGVrylV1BYn2xhNKt0FUC3eaI4 O7rg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-205309-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205309-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de21978fb3si520496a12.242.2024.06.06.21.32.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 21:32:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205309-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-205309-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205309-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1398E28AD89 for ; Fri, 7 Jun 2024 04:32:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 49B91154424; Fri, 7 Jun 2024 04:27:00 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CA2114D2BF for ; Fri, 7 Jun 2024 04:26:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717734419; cv=none; b=J33THrkvl0EKJYbAcqjMKZlrL85znAH8fYRnM44F9UA0a04WQxxs1Syn1z2fwFjQcAM8+53uWWgQ0DVOaB0Ofp53xqMa5w/tMZEcRliebrDbnj8vdl/RTuITBg2060Xzd4voVimkQn/xpHkAjkYFsf0rO2vGzrH/4GkR0luKYRE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717734419; c=relaxed/simple; bh=7VGYZQAFbnQuW8kB3hWIlpOvu4pLHWIi6PlbOkdfPTY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=K0AkAG6QNIEV0KQFucaodcG5sFeDEo/JV97p7E1rE1JcMUnOnmYxuodqsFwI3yHgq4OgEn+UUKPDs2ELCPhl3cG5R1UQ+INjxuxAjzdRl0Mxh3HuGNkYSMTS/26fB13R+9/dkEsFD1w6/l6RnVp1TEpEej9gumSHtL+BF/N0IFE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4VwShm0VlHzmYTL; Fri, 7 Jun 2024 12:22:16 +0800 (CST) Received: from kwepemm600013.china.huawei.com (unknown [7.193.23.68]) by mail.maildlp.com (Postfix) with ESMTPS id DE10A14038F; Fri, 7 Jun 2024 12:26:51 +0800 (CST) Received: from huawei.com (10.175.104.67) by kwepemm600013.china.huawei.com (7.193.23.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 7 Jun 2024 12:26:46 +0800 From: Zhihao Cheng To: , , , , , CC: , Subject: [RFC PATCH mtd-utils 027/110] ubifs-utils: Add rwsem implementations Date: Fri, 7 Jun 2024 12:24:52 +0800 Message-ID: <20240607042615.2069840-28-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240607042615.2069840-1-chengzhihao1@huawei.com> References: <20240607042615.2069840-1-chengzhihao1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600013.china.huawei.com (7.193.23.68) Add rwsem implementations, because there are some rwsems (eg. c->commit_sem) used in UBIFS linux kernel libs. The rwsem is implementated based on pthread mutex. This is a preparation for replacing implementation of UBIFS utils with linux kernel libs. Signed-off-by: Zhihao Cheng --- ubifs-utils/Makemodule.am | 1 + ubifs-utils/common/rwsem.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 ubifs-utils/common/rwsem.h diff --git a/ubifs-utils/Makemodule.am b/ubifs-utils/Makemodule.am index 9f33f0db..ece8a6e9 100644 --- a/ubifs-utils/Makemodule.am +++ b/ubifs-utils/Makemodule.am @@ -7,6 +7,7 @@ common_SOURCES = \ ubifs-utils/common/bitops.c \ ubifs-utils/common/spinlock.h \ ubifs-utils/common/mutex.h \ + ubifs-utils/common/rwsem.h \ ubifs-utils/common/kmem.h \ ubifs-utils/common/kmem.c \ ubifs-utils/common/defs.h \ diff --git a/ubifs-utils/common/rwsem.h b/ubifs-utils/common/rwsem.h new file mode 100644 index 00000000..3761724b --- /dev/null +++ b/ubifs-utils/common/rwsem.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_RWSEM_H_ +#define __LINUX_RWSEM_H_ + +#include + +struct rw_semaphore { + pthread_mutex_t lock; +}; + +#define init_rwsem(x) pthread_mutex_init(&(x)->lock, NULL) + +#define down_read(x) pthread_mutex_lock(&(x)->lock) +#define down_write(x) pthread_mutex_lock(&(x)->lock) +#define up_read(x) pthread_mutex_unlock(&(x)->lock) +#define up_write(x) pthread_mutex_unlock(&(x)->lock) +#define down_write_trylock(x) (pthread_mutex_trylock(&(x)->lock) == 0) + +#endif -- 2.13.6