Whamcloud - gitweb
LU-11288 osc: re-check target versus available grant 26/33226/10
authorAlex Zhuravlev <bzzz@whamcloud.com>
Tue, 25 Sep 2018 06:48:06 +0000 (09:48 +0300)
committerOleg Drokin <green@whamcloud.com>
Mon, 29 Oct 2018 15:58:30 +0000 (15:58 +0000)
- 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 <bzzz@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/33226
Tested-by: Jenkins
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Bobi Jam <bobijam@hotmail.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/osc/osc_request.c
lustre/target/tgt_grant.c

index ffa7912..5875149 100644 (file)
@@ -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);
 }
index 42b5a67..99373cf 100644 (file)
@@ -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;