From fcbd8c981239dc2be4bcf55e9a3e40b72d939700 Mon Sep 17 00:00:00 2001 From: Alex Zhuravlev Date: Tue, 25 Sep 2018 09:48:06 +0300 Subject: [PATCH] LU-11288 osc: re-check target versus available grant - under the spinlock, otherwise it's possible that available grant has changed since target calculation and bytes to shrink go negative. - tgt_grant_alloc() should avoid negative grants Change-Id: I35613e4e840e172977c7b866fb429c40a7fefc8f Signed-off-by: Alex Zhuravlev Reviewed-on: https://review.whamcloud.com/33226 Tested-by: Jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Bobi Jam Reviewed-by: Oleg Drokin --- lustre/osc/osc_request.c | 6 ++++++ lustre/target/tgt_grant.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/lustre/osc/osc_request.c b/lustre/osc/osc_request.c index ffa7912..5875149 100644 --- a/lustre/osc/osc_request.c +++ b/lustre/osc/osc_request.c @@ -817,6 +817,11 @@ int osc_shrink_grant_to_target(struct client_obd *cli, __u64 target_bytes) osc_announce_cached(cli, &body->oa, 0); spin_lock(&cli->cl_loi_list_lock); + if (target_bytes >= cli->cl_avail_grant) { + /* available grant has changed since target calculation */ + spin_unlock(&cli->cl_loi_list_lock); + GOTO(out_free, rc = 0); + } body->oa.o_grant = cli->cl_avail_grant - target_bytes; cli->cl_avail_grant = target_bytes; spin_unlock(&cli->cl_loi_list_lock); @@ -832,6 +837,7 @@ int osc_shrink_grant_to_target(struct client_obd *cli, __u64 target_bytes) sizeof(*body), body, NULL); if (rc != 0) __osc_update_grant(cli, body->oa.o_grant); +out_free: OBD_FREE_PTR(body); RETURN(rc); } diff --git a/lustre/target/tgt_grant.c b/lustre/target/tgt_grant.c index 42b5a67..99373cf 100644 --- a/lustre/target/tgt_grant.c +++ b/lustre/target/tgt_grant.c @@ -937,6 +937,8 @@ static long tgt_grant_alloc(struct obd_export *exp, u64 curgrant, * client would like to have by more than grants for 2 full * RPCs */ + if (want + chunk <= ted->ted_grant) + RETURN(0); if (ted->ted_grant + grant > want + chunk) grant = want + chunk - ted->ted_grant; -- 1.8.3.1