]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_scrub: fix background-mode sleep throttling
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 6 Jun 2019 13:58:55 +0000 (08:58 -0500)
committerEric Sandeen <sandeen@redhat.com>
Thu, 6 Jun 2019 13:58:55 +0000 (08:58 -0500)
The comment preceding background_sleep() is wrong -- the function sleeps
100us, not 100ms, for every '-b' passed in after the first one.  This is
really not obvious from the magic numbers, so fix the comment and use
symbolic constants for easier reading.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
scrub/common.c

index c877c7c8f00e1d059bfe181fba40c7990c860058..1cd2b7ba6d034dcb9dfe261a825f6f2897d21e5a 100644 (file)
@@ -253,21 +253,23 @@ scrub_nproc_workqueue(
 }
 
 /*
- * Sleep for 100ms * however many -b we got past the initial one.
+ * Sleep for 100us * however many -b we got past the initial one.
  * This is an (albeit clumsy) way to throttle scrub activity.
  */
+#define NSEC_PER_SEC   1000000000ULL
+#define NSEC_PER_USEC  1000ULL
 void
 background_sleep(void)
 {
-       unsigned long long      time;
+       unsigned long long      time_ns;
        struct timespec         tv;
 
        if (bg_mode < 2)
                return;
 
-       time = 100000ULL * (bg_mode - 1);
-       tv.tv_sec = time / 1000000;
-       tv.tv_nsec = time % 1000000;
+       time_ns =  100 * NSEC_PER_USEC * (bg_mode - 1);
+       tv.tv_sec = time_ns / NSEC_PER_SEC;
+       tv.tv_nsec = time_ns % NSEC_PER_SEC;
        nanosleep(&tv, NULL);
 }