From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F3E53BED6A for ; Mon, 6 Jul 2026 07:38:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783323507; cv=none; b=Fc21cz3pHS9Vx88ZHAf6FJKum0BzTwbR2wsxwK+pMssk0JkTfdsuiUufvOHEYJ7G9mrwVUR+Pv3IDvWLCfi+CJo5Wcp8ITRC2mEzg1qC1yQ2pv9EVIC0ak+BlVHB+MyljAIHPTb7nhL6B2AqEfwCt6jGcaeqQxh1jQJLkXHXByk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783323507; c=relaxed/simple; bh=0q66rVPiB6wYvH6QGLn599GshpRlA1a1mXX41mVOwAY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QdB6eT8j7TVUwX6PXGdyrCBzQXEBT5yrPRapyPcAuUhmqf4PbF7lO+Jb+V2yd2W7y7Mgmtv+BcP6lmDB2nklD79XUTBpvp0Xte1sRZ/vtJP8FN23oMY1BVnPi40ptVQx5IbyWNxOdA9ITWSBaUJ7rilBlEw51RL0ZF5HdQuelzQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ionos.com; spf=pass smtp.mailfrom=ionos.com; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b=Dodfy68w; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ionos.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ionos.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b="Dodfy68w" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-476a130c138so2769210f8f.0 for ; Mon, 06 Jul 2026 00:38:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1783323499; x=1783928299; darn=vger.kernel.org; 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:content-type; bh=m5NAfX7bUPbqWXx47VHAOQDAdfI+leEUeKDSWi7QVvw=; b=Dodfy68ww6nEE0ffGLJPvNDN1CXfnLIlmQxrRqHd3qXpBmrh9S/St8393wYh3u6Hyc c2lTPcdwNAceTJlK2QBGHXaZ0ViGUffTwiqLumUq46L48Y3SFITvQI14IZes8KeUJ/v8 91CheODdteQTngMT6TF5BY6zz56V1vl6n6mfestDXthsjxiHyu/s5apBsDJO5GRDl6M3 IjQnECa/5tyGJVnUCMl4Fz5bnW3KjY+5/3CSqOtdchXfsmsJUFfIg2L3R89Bp3RD4wTP /EPAp1wb/IX3qhNUh9YacwaWEz1S/7GqFHrM2BLrzeZvontNqyoCwLrCD3RIVrgdBL1U KxGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783323499; x=1783928299; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=m5NAfX7bUPbqWXx47VHAOQDAdfI+leEUeKDSWi7QVvw=; b=ke4PKKGrt8irt8qo9N0zwOQkEZXEaqeWu61nbErn8fQpRvlPUKiaFnZ5g5f7Fa0t3s /HoOSBUcCHO16h2su0vf0LcQu1l+NlCjIH7v7sHu653O9rSxxin7hpUaaG75iJHHBI0P Wannhc6mEYbUPy6twE53g3SAkh6wb85b4UlCfSjP764Si8DUshS/ylMjwdvEPhNug6RA nxKlntlzZcuPt3KCFCkgWTVHnDuuEIs7TbecsPV4G8ZEDhAvVNFMfrFzeQFdy/yjZr04 jp922+U3WGLaKcDel6IEAPsM9pPi8YF/O0DPPpl5hL2ZVTbH+OV2Gwunbh8T+8npAtLG PSIg== X-Forwarded-Encrypted: i=1; AHgh+RpMMLI72QN+WnK8VIbrBzb4k6OP7xnXeLcK7AUHmy/HoCaE3tcCggekXO4BvWv+NGu8sJTG1OR+KmMS+aI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz923qI91BC3rDxggIMWnOpMpy051kKcu26yxt1XC3NVR/IBnfw CbTqRYZaZtihcEySSNJIOuNFCM/X0Xhu5HfbrZFspSyfYmt9UQAX2sAYvkt0b3d7tGs= X-Gm-Gg: AfdE7ckbjIqrmo03bVQvVBYLsc7RyHbQhifxk2HjotGmxAyilXFklrN+NhUODdv3LBD qIiMYFSHEsBGkbU8KHADyu54JnVBv4qMsp9jZLBW1JQDopUqYmTFOTjiXlXggwTQIZTFLGEjxUE TItrXNyE93KRCZdhNzK8PIFIWT+L5SAmO/IaYErviMdXG3/ZvohSieBkopHQFjZybiY8vIQrN36 BQNxw1bZ5d0Wjl/LB80ohljczgsw7EUTgbhixbdmKUDURhYm+R1Puro8WW1PtZksN0qRu6K8iEf 8zaOl2YH9wcTRnw5mx6HvZ3ivhqLlJcRZOl5HD4B8eugKJELylAZWp9L+AzfctKZ8p28ckOvKDi pMOxhJhwsZFMZSLnFo//DV8fzROYAmTbLmMOAhDfNLyhQZj2oloV1TpSZvVDoQK65/Iq4YDqz8V z/ikQJVM7ZO6h8HJzYzbqi4McPjhIo/9NLW+EX5oEQW9cDnc8a2i9cYtVd7N95uaZ1kS6ooOHO4 W6qcWTnqT8O49SA X-Received: by 2002:a05:6000:46ca:b0:475:f100:35fe with SMTP id ffacd0b85a97d-47aae69c8c6mr6580259f8f.59.1783323498778; Mon, 06 Jul 2026 00:38:18 -0700 (PDT) Received: from raven.intern.cm-ag (p200300dc6f45eb00023064fffe740809.dip0.t-ipconnect.de. [2003:dc:6f45:eb00:230:64ff:fe74:809]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47a9de1d8f1sm22248585f8f.3.2026.07.06.00.38.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 00:38:18 -0700 (PDT) From: Max Kellermann To: idryomov@gmail.com, amarkuze@redhat.com, ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Max Kellermann Subject: [PATCH v2 3/4] fs/ceph/caps: mark cap remove with RB_CLEAR_NODE() instead of ci=NULL Date: Mon, 6 Jul 2026 09:38:11 +0200 Message-ID: <20260706073812.3922732-3-max.kellermann@ionos.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260706073812.3922732-1-max.kellermann@ionos.com> References: <20260706073812.3922732-1-max.kellermann@ionos.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 __ceph_remove_cap() erases the ceph_cap object from the RB tree, thus it seems natural to use RB_CLEAR_NODE() / RB_EMPTY_NODE() for the removal check. Signed-off-by: Max Kellermann --- v1->v2: - move code to new patch "add helper function ceph_cap_is_removed()" - add locking documentation to ceph_cap.ci_node - fix data race by calling RB_CLEAR_NODE() under s_cap_lock Signed-off-by: Max Kellermann --- fs/ceph/caps.c | 7 +++++-- fs/ceph/super.h | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index f6f3e817b712..a6a59bc91b79 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -1157,8 +1157,11 @@ static void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release) cap->session = NULL; removed = 1; } - /* protect backpointer with s_cap_lock: see iterate_session_caps */ - cap->ci = NULL; + + /* protect removal marker with both i_ceph_lock and + s_cap_lock, so either one can be used to check for + removal */ + RB_CLEAR_NODE(&cap->ci_node); /* * s_cap_reconnect is protected by s_cap_lock. no one changes diff --git a/fs/ceph/super.h b/fs/ceph/super.h index 628d153601a5..509839c1db0b 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h @@ -203,7 +203,19 @@ struct ceph_fs_client { */ struct ceph_cap { struct ceph_inode_info *ci; - struct rb_node ci_node; /* per-ci cap tree */ + + /** + * Per-ci cap tree. Protected with + * `ceph_inode_info.i_ceph_lock`. + * + * Clearing this field with RB_CLEAR_NODE() requires holding + * both `ceph_inode_info.i_ceph_lock` and + * `ceph_mds_session->s_cap_lock`. Calling RB_EMPTY_NODE() + * (via ceph_cap_is_removed()) requires holding at least one + * of these. + */ + struct rb_node ci_node; + struct ceph_mds_session *session; struct list_head session_caps; /* per-session caplist */ u64 cap_id; /* unique cap id (mds provided) */ @@ -1280,7 +1292,7 @@ extern void ceph_add_cap(struct inode *inode, */ static inline bool ceph_cap_is_removed(const struct ceph_cap *cap) { - return !cap->ci; + return RB_EMPTY_NODE(&cap->ci_node); } extern void ceph_remove_cap(struct ceph_mds_client *mdsc, struct ceph_cap *cap, -- 2.47.3