From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796304284; b=DyQ7sxW1nppGNFpqiFI85hVfCyx5vrm17QIWS2VtKt+HkEAoH2XJM3+iOucdnLtmzad2 PqqXg10cYMQpGikZjc/6nF9yUdeI5eNXYo5UdOsr4pbOnJB0o7Yc02UcbdS/IrHeYCM94 GUfDcT7inoRmdU5by9cS780ujB4jIv9Yvzs7MBWTYy2FH3szdDJO+cNoiADh/HE+rBbdc 11lTttGFliF+ZtdDoT2Q7sYMZznKSZ4w4LJTHxFZ4FDMnzISxDTJeNIafYHqri1m4WvHk VRBntk3xsiHAxWtRfqKC1UIYSy/GsMwIySbysy6D63EgEZJlaK/LU4JCKmWDd1rOKmg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796304284; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=yg19wJ/+fnxJuLYGoL5ZNep/DaqQjgcbu9MtuyY5VZM=; b=TXdwjWSsjONNukTa48Am7MVaGarsNizrIONeCc2ByHIgXnW3Qxir8FQBm9taeiDS3I3p vxyFjb9KUC+VrYjZhXDCNvKzbxgdC6xHI5kndd+sIP3bhvN2BHhflT+ilMDMHDWTNrF01 eatadTSVTUDT9KdpDUU7fU9rUe0yYWtU1k5J8wC5VTmFhvKvG8msWCzu/oG332gVG5Idi Kb52LyvXHTgGyF9G0R7L7csZFQFrSLnnp3ZzrI5ZJg1G7iIRjsNshz/DdlnRc2vllnWEe l8pOxkvD1xmb0+IJxTIw9z5a4K/roSjyOlea08LX1LXjgRyzx/h9Lb7I0SF7rpIwvfQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HTPLyrIr; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D34C7606A332; Thu, 3 Dec 2026 13:24:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HTPLyrIr Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796304284; b=Jw1PlmGoRS5iHviOEgiDVy9TUyv8z1BvGuEiEMKoUGZxj79HTSZd/HwcQyMRR1erANH5 s/9JYaSTlcDt07JHSF9i/BP8Pfebagb7kDzMgy0g5H7cSxoprg1b4qfTwaLSVxdK1en4e F4ZskPoarWzrqDnIvGRD48Dygs5zneumghaCi6TtWa0nN/II7KCrsUIiqRFqsSj5jW68A 12ijqVHnIYDDfKJd2Rqw6/oa2kudY/ZDoz92trsxq1foQi8YtVTsceNsuGVC8zfvey4YN /S9q5re/CQo3BtEJZ0jygabAzf3icoY71azJ8qMwuWh/AjYRNH0M4bj+IRr7IijIyNg== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796304284; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=yg19wJ/+fnxJuLYGoL5ZNep/DaqQjgcbu9MtuyY5VZM=; b=ubjarBiSdOGNplX/1KfaNqKCH02kKgYGyAI1F9Y95YjUHG6vIGEXMAEQV6AmnqLVhEjQ ZOi4KEQyYQ50ZeTgOzRusVU+RAMzeSkjNNyjPIEzCzXwoynscM8ZguoqtrtyfD4xdTmW3 xPvvOYy2o5B403sxmxrzUE0Kr0NwQ9SV1JwscoZPmGqP4H8agArH6Nb29IpH6I2G/Z1GK 3vpUFAdZ/YqR2qk2gwaCpJIjS4pyKJAL0tx3ptGa3jpBcOQ6rcTNCG7shdlShMAlqz5oX 4b1Z5jf6opVgfJX+WqAhGB09eUfSAQgAH3m/99CuHI4BoMbm8HDw4czwfOYX0+hE8DQ== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id BCB1B1F000C1; Thu, 3 Dec 2026 13:24:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796304284; bh=yg19wJ/+fnxJuLYGoL5ZNep/DaqQjgcbu9MtuyY5VZM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=HTPLyrIrr1uqIxygZ8svimUL76gks2Z6gAE6cLhZyEK6Q3rX9sU/4LDwClmhhgzCs WJ42/wBTbJhdTGKaeSgWVSjh/dyqXpGNYa6uVSdrEgrOKvVquKp4yTEV8WhcW5d8Eu s5z1k5gWIfsncmD9Hq4wP4hmz4mj1RwHzfygMQ6O2gJcMpC3aqnmKaqgvy1vQ24sHl w+tbTQ3g4aqh6J5jQdNS0k0HuIM0Wu/wrIecPWm9pfubGKezNvbUaUtQCwKYufK4gX fdY4xAj8vsdKGLnTf30bhqEx67tleKCVlIyPcxSVdIZBtugWHtpdTWnAIly2Absw0G l0yz9mHgVOS9A== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 45C3D4F9AF; Thu, 3 Dec 2026 13:24:43 +0000 (UTC) From: Xiubo Li via B4 Relay Date: Thu, 03 Dec 2026 14:24:22 +0100 Subject: [PATCH v2 3/4] libceph: decode and apply pg_upmap_primary mappings X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261203-b4-libceph-upmap-primary-v2-3-8a15d2fc7318@clyso.com> References: <20261203-b4-libceph-upmap-primary-v2-0-8a15d2fc7318@clyso.com> In-Reply-To: <20261203-b4-libceph-upmap-primary-v2-0-8a15d2fc7318@clyso.com> To: Ilya Dryomov , Alex Markuze , Viacheslav Dubeyko Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Xiubo Li X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796304272; l=6876; i=xiubo.li@clyso.com; s=20260625; h=from:subject:message-id; bh=CRio/b2XJ7Ni/kIafWnDgZeYfJKweKdadCqbGFvilqQ=; b=VQn26stD6YmK2IcXfdGdAAVg1leblLXNlufD5z5iKPYSlzdIZcF+oCwyB04gI1AdhUk+paT72 pi7q/xjy0etDOiV0heWyYI22HVUP/n5jN3+V/qdDsL3JUXZoOQmpYyZ X-Developer-Key: i=xiubo.li@clyso.com; a=ed25519; pk=V3NGr0AgAopiUhaLY51ipBkLN5LlcLhjOEfLEq1RoZ8= X-Endpoint-Received: by B4 Relay for xiubo.li@clyso.com/20260625 with auth_id=840 X-Original-From: Xiubo Li Reply-To: xiubo.li@clyso.com Content-Transfer-Encoding: 7bit From: Xiubo Li Since reef, the mgr read balancer and "ceph osd pg-upmap-primary" can choose the primary of a PG explicitly. The mapping is kept in the OSDMap as pg_upmap_primaries (client data v10 of a full map) and as new_pg_upmap_primary/old_pg_upmap_primary (client data v9 of an incremental), and the OSDs apply it after pg_upmap and pg_upmap_items: if the chosen OSD is in the raw set and not marked out, it is swapped into the first position. libceph stops decoding after pg_upmap_items, so for every such PG it computes a different primary than the OSDs do. Decode the mapping, skipping the crush_version, removed/purged snaps and last up/in change fields in front of it, apply it in apply_upmap() the same way OSDMap::_apply_upmap() does, and list it in the osdmap debugfs file. The monitors and OSDs send these encodings only to clients that have the SERVER_REEF feature, which the next patch advertises. Signed-off-by: Xiubo Li --- include/linux/ceph/osdmap.h | 4 ++ net/ceph/debugfs.c | 7 ++++ net/ceph/osdmap.c | 99 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 109 insertions(+), 1 deletion(-) diff --git a/include/linux/ceph/osdmap.h b/include/linux/ceph/osdmap.h index 5553019c3f07..0b36658cba56 100644 --- a/include/linux/ceph/osdmap.h +++ b/include/linux/ceph/osdmap.h @@ -164,6 +164,9 @@ struct ceph_pg_mapping { int len; int from_to[][2]; } pg_upmap_items; + struct { + int osd; + } pg_upmap_primary; }; }; @@ -185,6 +188,7 @@ struct ceph_osdmap { /* remap (post-CRUSH, pre-up) */ struct rb_root pg_upmap; /* PG := raw set */ struct rb_root pg_upmap_items; /* from -> to within raw set */ + struct rb_root pg_upmap_primaries; /* new primary within raw set */ u32 *osd_primary_affinity; diff --git a/net/ceph/debugfs.c b/net/ceph/debugfs.c index 79c9714cfda9..4039f8a5d001 100644 --- a/net/ceph/debugfs.c +++ b/net/ceph/debugfs.c @@ -139,6 +139,13 @@ static int osdmap_show(struct seq_file *s, void *p) pg->pg_upmap_items.from_to[i][1]); seq_printf(s, "]\n"); } + for (n = rb_first(&map->pg_upmap_primaries); n; n = rb_next(n)) { + struct ceph_pg_mapping *pg = + rb_entry(n, struct ceph_pg_mapping, node); + + seq_printf(s, "pg_upmap_primary %llu.%x %d\n", pg->pgid.pool, + pg->pgid.seed, pg->pg_upmap_primary.osd); + } out_unlock: up_read(&osdc->lock); diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c index a946724d4ef7..aedb8b15c972 100644 --- a/net/ceph/osdmap.c +++ b/net/ceph/osdmap.c @@ -1152,6 +1152,7 @@ struct ceph_osdmap *ceph_osdmap_alloc(void) map->primary_temp = RB_ROOT; map->pg_upmap = RB_ROOT; map->pg_upmap_items = RB_ROOT; + map->pg_upmap_primaries = RB_ROOT; init_workspace_manager(&map->crush_wsm); @@ -1194,6 +1195,13 @@ void ceph_osdmap_destroy(struct ceph_osdmap *map) rb_erase(&pg->node, &map->pg_upmap_items); kfree(pg); } + while (!RB_EMPTY_ROOT(&map->pg_upmap_primaries)) { + struct ceph_pg_mapping *pg = + rb_entry(rb_first(&map->pg_upmap_primaries), + struct ceph_pg_mapping, node); + rb_erase(&pg->node, &map->pg_upmap_primaries); + kfree(pg); + } while (!RB_EMPTY_ROOT(&map->pg_pools)) { struct ceph_pg_pool_info *pi = rb_entry(rb_first(&map->pg_pools), @@ -1678,6 +1686,44 @@ static int decode_old_pg_upmap_items(void **p, void *end, return decode_pg_mapping(p, end, &map->pg_upmap_items, NULL, true); } +static struct ceph_pg_mapping *__decode_pg_upmap_primary(void **p, void *end, + bool incremental) +{ + struct ceph_pg_mapping *pg; + u32 osd; + + ceph_decode_32_safe(p, end, osd, e_inval); + pg = alloc_pg_mapping(0); + if (!pg) + return ERR_PTR(-ENOMEM); + + pg->pg_upmap_primary.osd = osd; + return pg; + +e_inval: + return ERR_PTR(-EINVAL); +} + +static int decode_pg_upmap_primaries(void **p, void *end, + struct ceph_osdmap *map) +{ + return decode_pg_mapping(p, end, &map->pg_upmap_primaries, + __decode_pg_upmap_primary, false); +} + +static int decode_new_pg_upmap_primaries(void **p, void *end, + struct ceph_osdmap *map) +{ + return decode_pg_mapping(p, end, &map->pg_upmap_primaries, + __decode_pg_upmap_primary, true); +} + +static int decode_old_pg_upmap_primaries(void **p, void *end, + struct ceph_osdmap *map) +{ + return decode_pg_mapping(p, end, &map->pg_upmap_primaries, NULL, true); +} + /* * decode a full map. */ @@ -1812,6 +1858,23 @@ static int osdmap_decode(void **p, void *end, bool msgr2, WARN_ON(!RB_EMPTY_ROOT(&map->pg_upmap_items)); } + if (struct_v >= 10) { + /* crush_version */ + ceph_decode_skip_32(p, end, e_inval); + /* new_removed_snaps, new_purged_snaps */ + ceph_decode_skip_map_of_map(p, end, 64, 64, 64, e_inval); + ceph_decode_skip_map_of_map(p, end, 64, 64, 64, e_inval); + /* last_up_change, last_in_change */ + ceph_decode_skip_n(p, end, 2 * sizeof(struct ceph_timespec), + e_inval); + + err = decode_pg_upmap_primaries(p, end, map); + if (err) + goto bad; + } else { + WARN_ON(!RB_EMPTY_ROOT(&map->pg_upmap_primaries)); + } + /* ignore the rest */ *p = end; @@ -2127,6 +2190,23 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, bool msgr2, goto bad; } + if (struct_v >= 9) { + /* new_removed_snaps, new_purged_snaps */ + ceph_decode_skip_map_of_map(p, end, 64, 64, 64, e_inval); + ceph_decode_skip_map_of_map(p, end, 64, 64, 64, e_inval); + /* new_last_up_change, new_last_in_change */ + ceph_decode_skip_n(p, end, 2 * sizeof(struct ceph_timespec), + e_inval); + + err = decode_new_pg_upmap_primaries(p, end, map); + if (err) + goto bad; + + err = decode_old_pg_upmap_primaries(p, end, map); + if (err) + goto bad; + } + /* ignore the rest */ *p = end; @@ -2631,7 +2711,7 @@ static void pg_to_raw_osds(struct ceph_osdmap *osdmap, remove_nonexistent_osds(osdmap, pi, raw); } -/* apply pg_upmap[_items] mappings */ +/* apply pg_upmap[_items] and pg_upmap_primary mappings */ static void apply_upmap(struct ceph_osdmap *osdmap, const struct ceph_pg *pgid, struct ceph_osds *raw) @@ -2690,6 +2770,23 @@ static void apply_upmap(struct ceph_osdmap *osdmap, raw->osds[pos] = to; } } + + pg = lookup_pg_mapping(&osdmap->pg_upmap_primaries, pgid); + if (pg) { + int osd = pg->pg_upmap_primary.osd; + + /* ignore mapping if new primary is invalid or marked out */ + if (osd != CRUSH_ITEM_NONE && osd >= 0 && + osd < osdmap->max_osd && osdmap->osd_weight[osd] != 0) { + for (i = 1; i < raw->size; i++) { + if (raw->osds[i] == osd) { + raw->osds[i] = raw->osds[0]; + raw->osds[0] = osd; + break; + } + } + } + } } /* -- 2.53.0