From 82e9a11056a55289c880786da71d8b1125f357b2 Mon Sep 17 00:00:00 2001 From: Olaf Faaland Date: Wed, 11 Nov 2020 14:38:25 -0800 Subject: [PATCH] LU-14125 osc: prevent overflow of o_dropped In osc_announce_cached(), prevent o_dropped from overflowing. Necessary because o_dropped AKA o_misc is 32 bits, but cl_lost_grant is 64 bits. Add a CDEBUG call so we can tell whether this happened. Signed-off-by: Olaf Faaland Change-Id: Ia459934c789ae9609f851ae0a2581de583c6fc1c Reviewed-on: https://review.whamcloud.com/40659 Reviewed-by: Andreas Dilger Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons --- lustre/osc/osc_request.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lustre/osc/osc_request.c b/lustre/osc/osc_request.c index 0043b83..52503cc 100644 --- a/lustre/osc/osc_request.c +++ b/lustre/osc/osc_request.c @@ -747,11 +747,20 @@ static void osc_announce_cached(struct client_obd *cli, struct obdo *oa, ~(PTLRPC_MAX_BRW_SIZE * 4UL)); } oa->o_grant = cli->cl_avail_grant + cli->cl_reserved_grant; - oa->o_dropped = cli->cl_lost_grant; - cli->cl_lost_grant = 0; + /* o_dropped AKA o_misc is 32 bits, but cl_lost_grant is 64 bits */ + if (cli->cl_lost_grant > INT_MAX) { + CDEBUG(D_CACHE, + "%s: avoided o_dropped overflow: cl_lost_grant %lu\n", + cli_name(cli), cli->cl_lost_grant); + oa->o_dropped = INT_MAX; + } else { + oa->o_dropped = cli->cl_lost_grant; + } + cli->cl_lost_grant -= oa->o_dropped; spin_unlock(&cli->cl_loi_list_lock); - CDEBUG(D_CACHE, "dirty: %llu undirty: %u dropped %u grant: %llu\n", - oa->o_dirty, oa->o_undirty, oa->o_dropped, oa->o_grant); + CDEBUG(D_CACHE, "%s: dirty: %llu undirty: %u dropped %u grant: %llu" + " cl_lost_grant %lu\n", cli_name(cli), oa->o_dirty, + oa->o_undirty, oa->o_dropped, oa->o_grant, cli->cl_lost_grant); } void osc_update_next_shrink(struct client_obd *cli) -- 1.8.3.1