int obd_alloc_fail(const void *ptr, const char *name, const char *type, size_t size, const char *file, int line) { if (ptr == NULL || (cfs_rand() & OBD_ALLOC_FAIL_MASK) < obd_alloc_fail_rate) { CERROR("%s%salloc of %s ("LPU64" bytes) failed at %s:%d\n", ptr ? "force " :"", type, name, (__u64)size, file, line); CERROR(LPU64" total bytes and "LPU64" total pages " "("LPU64" bytes) allocated by Lustre, " "%d total bytes by LNET\n", obd_memory_sum(), obd_pages_sum() << CFS_PAGE_SHIFT, obd_pages_sum(), cfs_atomic_read(&libcfs_kmemory)); return 1; } return 0; }
static int llog_test_setup(struct obd_device *obd, struct lustre_cfg *lcfg) { struct lprocfs_static_vars lvars; struct obd_device *tgt; int rc; ENTRY; if (lcfg->lcfg_bufcount < 2) { CERROR("requires a TARGET OBD name\n"); RETURN(-EINVAL); } if (lcfg->lcfg_buflens[1] < 1) { CERROR("requires a TARGET OBD name\n"); RETURN(-EINVAL); } /* disk obd */ tgt = class_name2obd(lustre_cfg_string(lcfg, 1)); if (!tgt || !tgt->obd_attached || !tgt->obd_set_up) { CERROR("target device not attached or not set up (%s)\n", lustre_cfg_string(lcfg, 1)); RETURN(-EINVAL); } rc = obd_llog_init(obd, NULL, tgt, NULL); if (rc) RETURN(rc); llog_test_rand = cfs_rand(); rc = llog_run_tests(obd); if (rc) llog_test_cleanup(obd); lprocfs_llog_test_init_vars(&lvars); lprocfs_obd_setup(obd, lvars.obd_vars); RETURN(rc); }
static int llog_test_setup(struct obd_device *obd, struct lustre_cfg *lcfg) { struct obd_device *tgt; struct llog_ctxt *ctxt; struct dt_object *o; struct lu_env env; struct lu_context test_session; int rc; if (lcfg->lcfg_bufcount < 2) { CERROR("requires a TARGET OBD name\n"); return -EINVAL; } if (lcfg->lcfg_buflens[1] < 1) { CERROR("requires a TARGET OBD name\n"); return -EINVAL; } /* disk obd */ tgt = class_name2obd(lustre_cfg_string(lcfg, 1)); if (!tgt || !tgt->obd_attached || !tgt->obd_set_up) { CERROR("target device not attached or not set up (%s)\n", lustre_cfg_string(lcfg, 1)); return -EINVAL; } rc = lu_env_init(&env, LCT_LOCAL | LCT_MG_THREAD); if (rc) return rc; rc = lu_context_init(&test_session, LCT_SESSION); if (rc) GOTO(cleanup_env, rc); test_session.lc_thread = (struct ptlrpc_thread *)current; lu_context_enter(&test_session); env.le_ses = &test_session; CWARN("Setup llog-test device over %s device\n", lustre_cfg_string(lcfg, 1)); OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt); obd->obd_lvfs_ctxt.dt = lu2dt_dev(tgt->obd_lu_dev); rc = llog_setup(&env, tgt, &tgt->obd_olg, LLOG_TEST_ORIG_CTXT, tgt, &llog_osd_ops); if (rc) GOTO(cleanup_session, rc); /* use MGS llog dir for tests */ ctxt = llog_get_context(tgt, LLOG_CONFIG_ORIG_CTXT); LASSERT(ctxt); o = ctxt->loc_dir; llog_ctxt_put(ctxt); ctxt = llog_get_context(tgt, LLOG_TEST_ORIG_CTXT); LASSERT(ctxt); ctxt->loc_dir = o; llog_ctxt_put(ctxt); llog_test_rand = cfs_rand(); rc = llog_run_tests(&env, tgt); if (rc) llog_test_cleanup(obd); cleanup_session: lu_context_exit(&test_session); lu_context_fini(&test_session); cleanup_env: lu_env_fini(&env); return rc; }
int __obd_fail_check_set(__u32 id, __u32 value, int set) { static cfs_atomic_t obd_fail_count = CFS_ATOMIC_INIT(0); LASSERT(!(id & OBD_FAIL_ONCE)); if ((obd_fail_loc & (OBD_FAILED | OBD_FAIL_ONCE)) == (OBD_FAILED | OBD_FAIL_ONCE)) { cfs_atomic_set(&obd_fail_count, 0); /* paranoia */ return 0; } /* Fail 1/obd_fail_val times */ if (obd_fail_loc & OBD_FAIL_RAND) { if (obd_fail_val < 2 || cfs_rand() % obd_fail_val > 0) return 0; } /* Skip the first obd_fail_val, then fail */ if (obd_fail_loc & OBD_FAIL_SKIP) { if (cfs_atomic_inc_return(&obd_fail_count) <= obd_fail_val) return 0; } /* Fail obd_fail_val times, overridden by FAIL_ONCE */ if (obd_fail_loc & OBD_FAIL_SOME && (!(obd_fail_loc & OBD_FAIL_ONCE) || obd_fail_val <= 1)) { int count = cfs_atomic_inc_return(&obd_fail_count); if (count >= obd_fail_val) { cfs_set_bit(OBD_FAIL_ONCE_BIT, &obd_fail_loc); cfs_atomic_set(&obd_fail_count, 0); /* we are lost race to increase obd_fail_count */ if (count > obd_fail_val) return 0; } } if ((set == OBD_FAIL_LOC_ORSET || set == OBD_FAIL_LOC_RESET) && (value & OBD_FAIL_ONCE)) cfs_set_bit(OBD_FAIL_ONCE_BIT, &obd_fail_loc); /* Lost race to set OBD_FAILED_BIT. */ if (cfs_test_and_set_bit(OBD_FAILED_BIT, &obd_fail_loc)) { /* If OBD_FAIL_ONCE is valid, only one process can fail, * otherwise multi-process can fail at the same time. */ if (obd_fail_loc & OBD_FAIL_ONCE) return 0; } switch (set) { case OBD_FAIL_LOC_NOSET: break; case OBD_FAIL_LOC_ORSET: obd_fail_loc |= value & ~(OBD_FAILED | OBD_FAIL_ONCE); break; case OBD_FAIL_LOC_RESET: obd_fail_loc = value; break; default: LASSERTF(0, "called with bad set %u\n", set); break; } return 1; }
int __cfs_fail_check_set(__u32 id, __u32 value, int set) { static cfs_atomic_t cfs_fail_count = CFS_ATOMIC_INIT(0); LASSERT(!(id & CFS_FAIL_ONCE)); if ((cfs_fail_loc & (CFS_FAILED | CFS_FAIL_ONCE)) == (CFS_FAILED | CFS_FAIL_ONCE)) { cfs_atomic_set(&cfs_fail_count, 0); /* paranoia */ return 0; } /* Fail 1/cfs_fail_val times */ if (cfs_fail_loc & CFS_FAIL_RAND) { if (cfs_fail_val < 2 || cfs_rand() % cfs_fail_val > 0) return 0; } /* Skip the first cfs_fail_val, then fail */ if (cfs_fail_loc & CFS_FAIL_SKIP) { if (cfs_atomic_inc_return(&cfs_fail_count) <= cfs_fail_val) return 0; } /* check cfs_fail_val... */ if (set == CFS_FAIL_LOC_VALUE) { if (cfs_fail_val != -1 && cfs_fail_val != value) return 0; } /* Fail cfs_fail_val times, overridden by FAIL_ONCE */ if (cfs_fail_loc & CFS_FAIL_SOME && (!(cfs_fail_loc & CFS_FAIL_ONCE) || cfs_fail_val <= 1)) { int count = cfs_atomic_inc_return(&cfs_fail_count); if (count >= cfs_fail_val) { set_bit(CFS_FAIL_ONCE_BIT, &cfs_fail_loc); cfs_atomic_set(&cfs_fail_count, 0); /* we are lost race to increase */ if (count > cfs_fail_val) return 0; } } if ((set == CFS_FAIL_LOC_ORSET || set == CFS_FAIL_LOC_RESET) && (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. */ 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; } return 1; }