This patch simplifies function gfs2_rgrp_used_recently. Now it uses
ktime functions to do its calculations. Also, it's called with the
rgrp rather than the reservation, and the constant HZ rather than
the hard-coded value 1000.

Signed-off-by: Bob Peterson <[email protected]>
---
 fs/gfs2/rgrp.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 6dea72f49316..4c9467bf9ab6 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -1900,21 +1900,18 @@ static bool gfs2_rgrp_congested(const struct gfs2_rgrpd 
*rgd, int loops)
 }
 
 /**
- * gfs2_rgrp_used_recently
- * @rs: The block reservation with the rgrp to test
+ * gfs2_rgrp_used_recently - check if a rgrp has been used recently
+ * @rgd: The rgrp to test
  * @msecs: The time limit in milliseconds
  *
  * Returns: True if the rgrp glock has been used within the time limit
  */
-static bool gfs2_rgrp_used_recently(const struct gfs2_blkreserv *rs,
-                                   u64 msecs)
+static inline bool gfs2_rgrp_used_recently(const struct gfs2_rgrpd *rgd,
+                                          u64 msecs)
 {
-       u64 tdiff;
-
-       tdiff = ktime_to_ns(ktime_sub(ktime_get_real(),
-                            rs->rs_rbm.rgd->rd_gl->gl_dstamp));
-
-       return tdiff > (msecs * 1000 * 1000);
+       return (ktime_before(ktime_get_real(),
+                            ktime_add(rgd->rd_gl->gl_dstamp,
+                                      ms_to_ktime(msecs))));
 }
 
 static u32 gfs2_orlov_skip(const struct gfs2_inode *ip)
@@ -2014,7 +2011,7 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, struct 
gfs2_alloc_parms *ap)
                                    !fast_to_acquire(rs->rs_rbm.rgd))
                                        goto next_rgrp;
                                if ((loops < 2) &&
-                                   gfs2_rgrp_used_recently(rs, 1000) &&
+                                   gfs2_rgrp_used_recently(rs->rs_rbm.rgd, HZ) 
&&
                                    gfs2_rgrp_congested(rs->rs_rbm.rgd, loops))
                                        goto next_rgrp;
                        }
-- 
2.14.3

Reply via email to