*/
/*
* This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
*
* lustre/mdd/mdd_trans.c
*
th = mdd_child_ops(mdd)->dt_trans_create(env, mdd->mdd_child);
if (!IS_ERR(th) && uc)
- th->th_ignore_quota = !!md_capable(uc, CFS_CAP_SYS_RESOURCE);
+ th->th_ignore_quota = !!cap_raised(uc->uc_cap, CAP_SYS_RESOURCE);
return th;
}
struct mdd_changelog_gc {
struct mdd_device *mcgc_mdd;
__u32 mcgc_id;
- __u32 mcgc_maxtime;
- __u64 mcgc_maxindexes;
- bool mcgc_found;
+ __u32 mcgc_mintime;
+ __u64 mcgc_minrec;
+ char mcgc_name[CHANGELOG_USER_NAMELEN_FULL];
};
/* return first registered ChangeLog user idle since too long
struct llog_handle *llh,
struct llog_rec_hdr *hdr, void *data)
{
- struct llog_changelog_user_rec *rec;
- struct mdd_changelog_gc *mcgc = (struct mdd_changelog_gc *)data;
+ struct llog_changelog_user_rec2 *rec;
+ struct mdd_changelog_gc *mcgc = data;
struct mdd_device *mdd = mcgc->mcgc_mdd;
+
ENTRY;
if ((llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN) == 0)
RETURN(-ENXIO);
- rec = container_of(hdr, struct llog_changelog_user_rec,
- cur_hdr);
-
- /* find oldest idle user, based on last record update/cancel time (new
- * behavior), or for old user records, last record index vs current
- * ChangeLog index. Late users with old record format will be treated
- * first as we assume they could be idle since longer
- */
- if (rec->cur_time != 0) {
- __u32 time_now = (__u32)ktime_get_real_seconds();
- __u32 time_out = rec->cur_time +
- mdd->mdd_changelog_max_idle_time;
- __u32 idle_time = time_now - rec->cur_time;
-
- /* treat oldest idle user first, and if no old format user
- * has been already selected
- */
- if (time_after32(time_now, time_out) &&
- idle_time > mcgc->mcgc_maxtime &&
- mcgc->mcgc_maxindexes == 0) {
- mcgc->mcgc_maxtime = idle_time;
- mcgc->mcgc_id = rec->cur_id;
- mcgc->mcgc_found = true;
- }
- } else {
- /* old user record with no idle time stamp, so use empirical
- * method based on its current index/position
- */
- __u64 idle_indexes;
-
- idle_indexes = mdd->mdd_cl.mc_index - rec->cur_endrec;
-
- /* treat user with the oldest/smallest current index first */
- if (idle_indexes >= mdd->mdd_changelog_max_idle_indexes &&
- idle_indexes > mcgc->mcgc_maxindexes) {
- mcgc->mcgc_maxindexes = idle_indexes;
- mcgc->mcgc_id = rec->cur_id;
- mcgc->mcgc_found = true;
- }
+ rec = container_of(hdr, typeof(*rec), cur_hdr);
+ if (rec->cur_endrec < mcgc->mcgc_minrec &&
+ (mdd->mdd_changelog_emrg_gc ||
+ mdd_changelog_is_too_idle(mdd, rec->cur_endrec, rec->cur_time))) {
+ mcgc->mcgc_mintime = rec->cur_time;
+ mcgc->mcgc_minrec = rec->cur_endrec;
+ mcgc->mcgc_id = rec->cur_id;
+ mdd_chlg_username(rec, mcgc->mcgc_name,
+ sizeof(mcgc->mcgc_name));
}
RETURN(0);
}
/* recover space from long-term inactive ChangeLog users */
static int mdd_chlg_garbage_collect(void *data)
{
- struct mdd_device *mdd = (struct mdd_device *)data;
- struct lu_env *env = NULL;
- int rc;
+ struct mdd_device *mdd = data;
+ struct lu_env *env = NULL;
+ int rc;
struct llog_ctxt *ctxt;
- struct mdd_changelog_gc mcgc = {
- .mcgc_mdd = mdd,
- .mcgc_found = false,
- .mcgc_maxtime = 0,
- .mcgc_maxindexes = 0,
- };
+
ENTRY;
mdd->mdd_cl.mc_gc_task = current;
mdd2obd_dev(mdd)->obd_name, current->pid);
OBD_ALLOC_PTR(env);
- if (env == NULL)
+ if (!env)
GOTO(out, rc = -ENOMEM);
rc = lu_env_init(env, LCT_MD_THREAD);
if (rc)
- GOTO(out, rc);
+ GOTO(out_free, rc);
+
+ ctxt = llog_get_context(mdd2obd_dev(mdd),
+ LLOG_CHANGELOG_USER_ORIG_CTXT);
+ if (!ctxt)
+ GOTO(out_env, rc = -ENXIO);
+ if (!(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT))
+ GOTO(out_ctxt, rc = -ENXIO);
for (;;) {
- ctxt = llog_get_context(mdd2obd_dev(mdd),
- LLOG_CHANGELOG_USER_ORIG_CTXT);
- if (ctxt == NULL ||
- (ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT) == 0)
- GOTO(out_ctxt, rc = -ENXIO);
+ __u32 time_now = (__u32)ktime_get_real_seconds();
+ struct mdd_changelog_gc mcgc = {
+ .mcgc_mdd = mdd,
+ .mcgc_minrec = mdd->mdd_cl.mc_index,
+ .mcgc_name = { 0 },
+ };
rc = llog_cat_process(env, ctxt->loc_handle,
mdd_changelog_gc_cb, &mcgc, 0, 0);
- if (rc != 0 || mcgc.mcgc_found == false)
+ if (rc)
+ GOTO(out_ctxt, rc);
+
+ if (!mcgc.mcgc_name[0])
break;
- llog_ctxt_put(ctxt);
-
- if (mcgc.mcgc_maxindexes != 0)
- CWARN("%s: Force deregister of ChangeLog user cl%d "
- "idle with more than %llu unprocessed records\n",
- mdd2obd_dev(mdd)->obd_name, mcgc.mcgc_id,
- mcgc.mcgc_maxindexes);
- else
- CWARN("%s: Force deregister of ChangeLog user cl%d "
- "idle since more than %us\n",
- mdd2obd_dev(mdd)->obd_name, mcgc.mcgc_id,
- mcgc.mcgc_maxtime);
+
+ CWARN("%s: force deregister of changelog user %s idle for %us with %llu unprocessed records\n",
+ mdd2obd_dev(mdd)->obd_name, mcgc.mcgc_name,
+ time_now - mcgc.mcgc_mintime,
+ mdd->mdd_cl.mc_index - mcgc.mcgc_minrec);
mdd_changelog_user_purge(env, mdd, mcgc.mcgc_id);
- if (kthread_should_stop())
- GOTO(out_env, rc = 0);
+ if (mdd->mdd_changelog_emrg_gc &&
+ mdd_changelog_is_space_safe(env, mdd, ctxt->loc_handle, 0))
+ mdd->mdd_changelog_emrg_gc = false;
- /* try again to search for another candidate */
- mcgc.mcgc_found = false;
- mcgc.mcgc_maxtime = 0;
- mcgc.mcgc_maxindexes = 0;
+ if (kthread_should_stop())
+ GOTO(out_ctxt, rc = 0);
}
-
+ EXIT;
out_ctxt:
- if (ctxt != NULL)
- llog_ctxt_put(ctxt);
-
+ llog_ctxt_put(ctxt);
out_env:
lu_env_fini(env);
- GOTO(out, rc);
+out_free:
+ OBD_FREE_PTR(env);
out:
- if (env)
- OBD_FREE_PTR(env);
-
spin_lock(&mdd->mdd_cl.mc_lock);
mdd->mdd_cl.mc_gc_task = MDD_CHLG_GC_NONE;
spin_unlock(&mdd->mdd_cl.mc_lock);