+ 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, rc = -ENXIO);
+
+ rc = llog_cat_process(env, ctxt->loc_handle,
+ mdd_changelog_user_purge_cb, &mcup,
+ 0, 0);
+
+ if ((rc == 0) && mcup.mcup_found) {
+ CDEBUG(D_IOCTL, "%s: Purging changelog entries for user %d "
+ "record=%llu\n",
+ mdd2obd_dev(mdd)->obd_name, id, mcup.mcup_minrec);
+ /* Cancelling record 0 destroys the entire changelog, make sure
+ we don't do that unless we mean it. */
+ if (mcup.mcup_minrec != 0 || mcup.mcup_usercount == 0) {
+ rc = mdd_changelog_llog_cancel(env, mdd,
+ mcup.mcup_minrec);
+ }
+ } else {
+ CWARN("%s: No changelog for user %u; rc=%d\n",
+ mdd2obd_dev(mdd)->obd_name, id, rc);
+ GOTO(out, rc = -ENOENT);
+ }
+
+ if ((rc == 0) && (mcup.mcup_usercount == 0)) {
+ /* No more users; turn changelogs off */
+ CDEBUG(D_IOCTL, "turning off changelogs\n");
+ rc = mdd_changelog_off(env, mdd);
+ }
+
+ EXIT;
+out:
+ if (ctxt != NULL)
+ llog_ctxt_put(ctxt);
+
+ return rc;
+}
+
+struct mdd_changelog_user_clear {
+ __u64 mcuc_endrec;
+ __u64 mcuc_minrec;
+ __u32 mcuc_id;
+ bool mcuc_flush;
+};
+
+/**
+ * changelog_clear callback
+ *
+ * Is called once per user.
+ *
+ * Check to see the user requested is available from rec.
+ * Check the oldest (smallest) record for boundary conditions.
+ * Truncate the changelog.
+ */
+static int mdd_changelog_clear_cb(const struct lu_env *env,
+ struct llog_handle *llh,
+ struct llog_rec_hdr *hdr,
+ void *data)
+{
+ struct llog_changelog_user_rec *rec;
+ struct mdd_changelog_user_clear *mcuc = data;
+ int rc;
+
+ 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);
+
+ /* Does the changelog id match the requested id? */
+ if (rec->cur_id != mcuc->mcuc_id) {
+ mcuc->mcuc_minrec = min(mcuc->mcuc_minrec,
+ rec->cur_endrec);
+ RETURN(0);
+ }
+
+ /* cur_endrec is the oldest purgeable record, make sure we're newer */
+ if (rec->cur_endrec > mcuc->mcuc_endrec) {
+ CDEBUG(D_IOCTL, "Request %llu out of range: %llu\n",
+ mcuc->mcuc_endrec, rec->cur_endrec);
+ RETURN(-EINVAL);
+ }
+
+ /* Flag that we've met all the range and user checks.
+ * We now know the record to flush.
+ */
+ rec->cur_endrec = mcuc->mcuc_endrec;
+ mcuc->mcuc_flush = true;