X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;ds=sidebyside;f=libcfs%2Flibcfs%2Ffail.c;h=00c4c2b7d727a60965683b61bcb080f1feb4afb9;hb=da1d93513fdff0a70257b13aa5649e478d4f70b6;hp=58a698e5b34e131579527ad2b493e01544f4dc93;hpb=2b294992edce5af7b79d4300ed3aa1ea6a8db850;p=fs%2Flustre-release.git diff --git a/libcfs/libcfs/fail.c b/libcfs/libcfs/fail.c index 58a698e..00c4c2b 100644 --- a/libcfs/libcfs/fail.c +++ b/libcfs/libcfs/fail.c @@ -16,38 +16,41 @@ * 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 */ /* * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, 2014, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ * Lustre is a trademark of Oracle Corporation, Inc. */ +#include +#include +#include +#include #include -unsigned long cfs_fail_loc = 0; -unsigned int cfs_fail_val = 0; -int cfs_fail_err; -wait_queue_head_t cfs_race_waitq; -int cfs_race_state; - +unsigned long cfs_fail_loc; EXPORT_SYMBOL(cfs_fail_loc); + +unsigned int cfs_fail_val; EXPORT_SYMBOL(cfs_fail_val); + +int cfs_fail_err; EXPORT_SYMBOL(cfs_fail_err); + +DECLARE_WAIT_QUEUE_HEAD(cfs_race_waitq); EXPORT_SYMBOL(cfs_race_waitq); + +int cfs_race_state; EXPORT_SYMBOL(cfs_race_state); -int __cfs_fail_check_set(__u32 id, __u32 value, int set) +int __cfs_fail_check_set(u32 id, u32 value, int set) { static atomic_t cfs_fail_count = ATOMIC_INIT(0); @@ -61,7 +64,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; } @@ -92,48 +95,58 @@ int __cfs_fail_check_set(__u32 id, __u32 value, int set) } /* Take into account the current call for FAIL_ONCE for ORSET only, - * as RESET is a new fail_loc, it does not change the current call */ + * as RESET is a new fail_loc, it does not change the current call + */ if ((set == CFS_FAIL_LOC_ORSET) && (value & CFS_FAIL_ONCE)) set_bit(CFS_FAIL_ONCE_BIT, &cfs_fail_loc); /* Lost race to set CFS_FAILED_BIT. */ if (test_and_set_bit(CFS_FAILED_BIT, &cfs_fail_loc)) { /* If CFS_FAIL_ONCE is valid, only one process can fail, - * otherwise multi-process can fail at the same time. */ + * otherwise multi-process can fail at the same time. + */ if (cfs_fail_loc & CFS_FAIL_ONCE) return 0; } switch (set) { - case CFS_FAIL_LOC_NOSET: - case CFS_FAIL_LOC_VALUE: - break; - case CFS_FAIL_LOC_ORSET: - cfs_fail_loc |= value & ~(CFS_FAILED | CFS_FAIL_ONCE); - break; - case CFS_FAIL_LOC_RESET: - cfs_fail_loc = value; - break; - default: - LASSERTF(0, "called with bad set %u\n", set); - break; + case CFS_FAIL_LOC_NOSET: + case CFS_FAIL_LOC_VALUE: + break; + case CFS_FAIL_LOC_ORSET: + cfs_fail_loc |= value & ~(CFS_FAILED | CFS_FAIL_ONCE); + break; + case CFS_FAIL_LOC_RESET: + cfs_fail_loc = value; + atomic_set(&cfs_fail_count, 0); + break; + default: + LASSERTF(0, "called with bad set %u\n", set); + break; } return 1; } EXPORT_SYMBOL(__cfs_fail_check_set); -int __cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set) +int __cfs_fail_timeout_set(u32 id, u32 value, int ms, int set) { - int ret = 0; + ktime_t till = ktime_add_ms(ktime_get(), ms); + int ret; ret = __cfs_fail_check_set(id, value, set); - if (ret) { - CERROR("cfs_fail_timeout id %x sleeping for %dms\n", - id, ms); - schedule_timeout_and_set_state(TASK_UNINTERRUPTIBLE, - cfs_time_seconds(ms) / 1000); - set_current_state(TASK_RUNNING); - CERROR("cfs_fail_timeout id %x awake\n", id); + if (ret && likely(ms > 0)) { + CERROR("cfs_fail_timeout id %x sleeping for %dms\n", id, ms); + while (ktime_before(ktime_get(), till)) { + schedule_timeout_uninterruptible(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; }