Whamcloud - gitweb
LU-13090 utils: fix lfs_migrate -p for file with pool
[fs/lustre-release.git] / libcfs / libcfs / fail.c
index 0cd8a4a..304faae 100644 (file)
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see http://www.gnu.org/licenses
  *
- * Please contact Oracle Corporation, Inc., 500 Oracle Parkway, Redwood Shores,
- * CA 94065 USA or visit www.oracle.com if you need additional information or
- * have any questions.
- *
  * GPL HEADER END
  */
 /*
@@ -33,6 +29,7 @@
  * Lustre is a trademark of Oracle Corporation, Inc.
  */
 
+#include <linux/random.h>
 #include <libcfs/libcfs.h>
 
 unsigned long cfs_fail_loc = 0;
@@ -61,7 +58,7 @@ int __cfs_fail_check_set(__u32 id, __u32 value, int set)
 
        /* Fail 1/cfs_fail_val times */
        if (cfs_fail_loc & CFS_FAIL_RAND) {
-               if (cfs_fail_val < 2 || cfs_rand() % cfs_fail_val > 0)
+               if (cfs_fail_val < 2 || prandom_u32_max(cfs_fail_val) > 0)
                        return 0;
        }
 
@@ -125,16 +122,23 @@ EXPORT_SYMBOL(__cfs_fail_check_set);
 
 int __cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set)
 {
+       ktime_t till = ktime_add_ms(ktime_get(), ms);
        int ret = 0;
 
        ret = __cfs_fail_check_set(id, value, set);
        if (ret && likely(ms > 0)) {
-               CERROR("cfs_fail_timeout id %x sleeping for %dms\n",
-                      id, ms);
-               set_current_state(TASK_UNINTERRUPTIBLE);
-               schedule_timeout(cfs_time_seconds(ms) / 1000);
-               set_current_state(TASK_RUNNING);
-               CERROR("cfs_fail_timeout id %x awake\n", id);
+               CERROR("cfs_fail_timeout id %x sleeping for %dms\n", id, ms);
+               while (ktime_before(ktime_get(), till)) {
+                       set_current_state(TASK_UNINTERRUPTIBLE);
+                       schedule_timeout(cfs_time_seconds(1) / 10);
+                       set_current_state(TASK_RUNNING);
+                       if (!cfs_fail_loc) {
+                               CERROR("cfs_fail_timeout interrupted\n");
+                               break;
+                       }
+               }
+               if (cfs_fail_loc)
+                       CERROR("cfs_fail_timeout id %x awake\n", id);
        }
        return ret;
 }