[PATCH v2 2/4] libceph: get a full osdmap after failing to apply an incremental

From: Xiubo Li via B4 Relay

Date: Thu Dec 03 2026 - 08:25:10 EST


From: Xiubo Li <xiubo.li@xxxxxxxxx>

osdmap_apply_incremental() updates the map in place and advances its
epoch before it decodes new_pools, new_pg_temp, new_pg_upmap_items and
the like, each of which can fail, with -ENOMEM in particular. On
failure the map is left half updated at the new epoch. Any repeat of
that epoch is then ignored, the next incrementals are applied on top
of it, and whatever was missed stays missed until a full map happens
to replace it, while requests are routed with it. This has been so
since incremental maps were first applied in place.

Instead, mark the map invalid when an incremental fails to apply, for
any error, also one hit before the map was changed. While it is
invalid, pause new requests as for an epoch barrier, ignore
incrementals, and ask the monitor for its latest full map
(subscribing from epoch 0), taking it even if it is not newer than
the invalid one. Once it arrives, recalculate all requests as after
a gap in the maps. If the full map cannot be decoded either, ask
again from the periodic timeout work, once per osd_keepalive_timeout,
so that a map that keeps failing does not turn into a request loop.

Tested by injecting -ENOMEM into the decoding of a new
pg_upmap_primary entry (the next patch adds that decoder), then
reading the 31 objects of the PG from a krbd device:

+-------------------------------------+--------------+---------+
| | before | after |
+-------------------------------------+--------------+---------+
| pg_upmap_primary in the kernel map | missing | present |
| ... after a later incremental | missing | present |
| reads completed | 0/31 | 31/31 |
| OSD log | misdirected | clean |
+-------------------------------------+--------------+---------+

Before, the reads went to the old primary, which dropped them as
misdirected, and they completed only after that OSD was marked down.
With every full map failing to decode as well, the client asked for
one every 5 seconds (3 failed full maps in 10 seconds), and took the
next one once the injection stopped.

Reported-by: Alex Markuze <amarkuze@xxxxxxxxxx>
Link: https://lore.kernel.org/all/20261202131101.582425-1-amarkuze@xxxxxxxxxx/
Signed-off-by: Xiubo Li <xiubo.li@xxxxxxxxx>
---
include/linux/ceph/osd_client.h | 1 +
net/ceph/debugfs.c | 5 ++--
net/ceph/osd_client.c | 60 ++++++++++++++++++++++++++++++++---------
3 files changed, 51 insertions(+), 15 deletions(-)

diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h
index ba4618ac38b0..4e4091f6e68f 100644
--- a/include/linux/ceph/osd_client.h
+++ b/include/linux/ceph/osd_client.h
@@ -411,6 +411,7 @@ struct ceph_osd_client {
struct list_head osd_lru; /* idle osds */
spinlock_t osd_lru_lock;
u32 epoch_barrier;
+ bool osdmap_invalid; /* need a full map */
struct ceph_osd homeless_osd;
atomic64_t last_tid; /* tid of last request */
u64 last_linger_id;
diff --git a/net/ceph/debugfs.c b/net/ceph/debugfs.c
index 20674e5d2711..79c9714cfda9 100644
--- a/net/ceph/debugfs.c
+++ b/net/ceph/debugfs.c
@@ -71,8 +71,9 @@ static int osdmap_show(struct seq_file *s, void *p)
if (map == NULL)
goto out_unlock;

- seq_printf(s, "epoch %u barrier %u flags 0x%x\n", map->epoch,
- osdc->epoch_barrier, map->flags);
+ seq_printf(s, "epoch %u barrier %u flags 0x%x%s\n", map->epoch,
+ osdc->epoch_barrier, map->flags,
+ osdc->osdmap_invalid ? " invalid" : "");

for (n = rb_first(&map->pg_pools); n; n = rb_next(n)) {
struct ceph_pg_pool_info *pi =
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 81da34869d5a..1827d1f2719e 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -1534,7 +1534,8 @@ static bool target_should_be_paused(struct ceph_osd_client *osdc,
WARN_ON(pi->id != t->target_oloc.pool);
return ((t->flags & CEPH_OSD_FLAG_READ) && pauserd) ||
((t->flags & CEPH_OSD_FLAG_WRITE) && pausewr) ||
- (osdc->osdmap->epoch < osdc->epoch_barrier);
+ (osdc->osdmap->epoch < osdc->epoch_barrier) ||
+ osdc->osdmap_invalid;
}

static int pick_random_replica(const struct ceph_osds *acting)
@@ -2370,6 +2371,7 @@ static void send_request(struct ceph_osd_request *req)
static void maybe_request_map(struct ceph_osd_client *osdc)
{
bool continuous = false;
+ u32 epoch;

verify_osdc_locked(osdc);
WARN_ON(!osdc->osdmap->epoch);
@@ -2383,8 +2385,10 @@ static void maybe_request_map(struct ceph_osd_client *osdc)
dout("%s osdc %p onetime\n", __func__, osdc);
}

- if (ceph_monc_want_map(&osdc->client->monc, CEPH_SUB_OSDMAP,
- osdc->osdmap->epoch + 1, continuous))
+ /* epoch 0 asks for the latest full map */
+ epoch = osdc->osdmap_invalid ? 0 : osdc->osdmap->epoch + 1;
+ if (ceph_monc_want_map(&osdc->client->monc, CEPH_SUB_OSDMAP, epoch,
+ continuous))
ceph_monc_renew_subs(&osdc->client->monc);
}

@@ -2417,9 +2421,11 @@ static void __submit_request(struct ceph_osd_request *req, bool wrlocked)
if (osdc->abort_err) {
dout("req %p abort_err %d\n", req, osdc->abort_err);
err = osdc->abort_err;
- } else if (osdc->osdmap->epoch < osdc->epoch_barrier) {
- dout("req %p epoch %u barrier %u\n", req, osdc->osdmap->epoch,
- osdc->epoch_barrier);
+ } else if (osdc->osdmap->epoch < osdc->epoch_barrier ||
+ osdc->osdmap_invalid) {
+ dout("req %p epoch %u barrier %u invalid %d\n", req,
+ osdc->osdmap->epoch, osdc->epoch_barrier,
+ osdc->osdmap_invalid);
req->r_t.paused = true;
maybe_request_map(osdc);
} else if ((req->r_flags & CEPH_OSD_FLAG_WRITE) &&
@@ -3534,6 +3540,16 @@ static void handle_timeout(struct work_struct *work)
if (atomic_read(&osdc->num_homeless) || !list_empty(&slow_osds))
maybe_request_map(osdc);

+ /*
+ * Ask for the full map again if the last one could not be
+ * decoded either, once per tick rather than right away, so a
+ * map that keeps failing does not turn into a request loop.
+ */
+ if (osdc->osdmap_invalid) {
+ maybe_request_map(osdc);
+ ceph_monc_renew_subs(&osdc->client->monc);
+ }
+
while (!list_empty(&slow_osds)) {
struct ceph_osd *osd = list_first_entry(&slow_osds,
struct ceph_osd,
@@ -4092,14 +4108,16 @@ static int handle_one_map(struct ceph_osd_client *osdc,
WARN_ON(pi->was_full);
}

- if (osdc->osdmap->epoch &&
- osdc->osdmap->epoch + 1 < newmap->epoch) {
+ if ((osdc->osdmap->epoch &&
+ osdc->osdmap->epoch + 1 < newmap->epoch) ||
+ osdc->osdmap_invalid) {
WARN_ON(incremental);
skipped_map = true;
}

ceph_osdmap_destroy(osdc->osdmap);
osdc->osdmap = newmap;
+ osdc->osdmap_invalid = false;
}

was_full &= !ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL);
@@ -4216,14 +4234,27 @@ void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
epoch = ceph_decode_32(&p);
maplen = ceph_decode_32(&p);
ceph_decode_need(&p, end, maplen, bad);
- if (osdc->osdmap->epoch &&
+ if (osdc->osdmap->epoch && !osdc->osdmap_invalid &&
osdc->osdmap->epoch + 1 == epoch) {
dout("applying incremental map %u len %d\n",
epoch, maplen);
err = handle_one_map(osdc, p, p + maplen, true,
&need_resend, &need_resend_linger);
- if (err)
+ if (err) {
+ /*
+ * The map may have been changed in part,
+ * and a repeat of this epoch would not be
+ * applied: stop routing requests with it
+ * until a full map replaces it. This is
+ * done for any error, also for one hit
+ * before the map was changed.
+ */
+ pr_err("osdc failed to apply incremental map %u, requesting a full map\n",
+ epoch);
+ osdc->osdmap_invalid = true;
+ maybe_request_map(osdc);
goto bad;
+ }
handled_incremental = true;
} else {
dout("ignoring incremental map %u len %d\n",
@@ -4246,7 +4277,8 @@ void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
if (nr_maps > 1) {
dout("skipping non-latest full map %u len %d\n",
epoch, maplen);
- } else if (osdc->osdmap->epoch >= epoch) {
+ } else if (osdc->osdmap->epoch >= epoch &&
+ !osdc->osdmap_invalid) {
dout("skipping full map %u len %d, "
"older than our %u\n", epoch, maplen,
osdc->osdmap->epoch);
@@ -4278,8 +4310,10 @@ void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
kick_requests(osdc, &need_resend, &need_resend_linger);

ceph_osdc_abort_on_full(osdc);
- ceph_monc_got_map(&osdc->client->monc, CEPH_SUB_OSDMAP,
- osdc->osdmap->epoch);
+ /* keep asking for the full map while the current one is invalid */
+ if (!osdc->osdmap_invalid)
+ ceph_monc_got_map(&osdc->client->monc, CEPH_SUB_OSDMAP,
+ osdc->osdmap->epoch);
up_write(&osdc->lock);
wake_up_all(&osdc->client->auth_wq);
return;

--
2.53.0