[lustre-devel] [PATCH 08/39] lustre: osc: prevent overflow of o_dropped

James Simmons jsimmons at infradead.org
Thu Jan 21 09:16:31 PST 2021


From: Olaf Faaland <faaland1 at llnl.gov>

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.

WC-bug-id: https://jira.whamcloud.com/browse/LU-14125
Lustre-commit: 82e9a11056a552 ("LU-14125 osc: prevent overflow of o_dropped")
Signed-off-by: Olaf Faaland <faaland1 at llnl.gov>
Reviewed-on: https://review.whamcloud.com/40659
Reviewed-by: Andreas Dilger <adilger at whamcloud.com>
Reviewed-by: James Simmons <jsimmons at infradead.org>
Signed-off-by: James Simmons <jsimmons at infradead.org>
---
 fs/lustre/osc/osc_request.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/fs/lustre/osc/osc_request.c b/fs/lustre/osc/osc_request.c
index f225ccd..4a4b5ef 100644
--- a/fs/lustre/osc/osc_request.c
+++ b/fs/lustre/osc/osc_request.c
@@ -754,11 +754,21 @@ 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



More information about the lustre-devel mailing list