+
+/**** changelogs ****/
+static int lprocfs_rd_changelog_mask(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
+{
+ struct mdd_device *mdd = data;
+ int i = 0, rc = 0;
+
+ *eof = 1;
+ while (i < CL_LAST) {
+ if (mdd->mdd_cl.mc_mask & (1 << i))
+ rc += snprintf(page + rc, count - rc, "%s ",
+ changelog_type2str(i));
+ i++;
+ }
+ return rc;
+}
+
+static int lprocfs_wr_changelog_mask(struct file *file, const char *buffer,
+ unsigned long count, void *data)
+{
+ struct mdd_device *mdd = data;
+ char *kernbuf;
+ int rc;
+ ENTRY;
+
+ if (count >= CFS_PAGE_SIZE)
+ RETURN(-EINVAL);
+ OBD_ALLOC(kernbuf, CFS_PAGE_SIZE);
+ if (kernbuf == NULL)
+ RETURN(-ENOMEM);
+ if (cfs_copy_from_user(kernbuf, buffer, count))
+ GOTO(out, rc = -EFAULT);
+ kernbuf[count] = 0;
+
+ rc = cfs_str2mask(kernbuf, changelog_type2str, &mdd->mdd_cl.mc_mask,
+ CHANGELOG_MINMASK, CHANGELOG_ALLMASK);
+ if (rc == 0)
+ rc = count;
+out:
+ OBD_FREE(kernbuf, CFS_PAGE_SIZE);
+ return rc;
+}
+
+struct cucb_data {
+ char *page;
+ int count;
+ int idx;
+};
+
+static int lprocfs_changelog_users_cb(const struct lu_env *env,
+ struct llog_handle *llh,
+ struct llog_rec_hdr *hdr, void *data)
+{
+ struct llog_changelog_user_rec *rec;
+ struct cucb_data *cucb = (struct cucb_data *)data;
+
+ LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
+
+ rec = (struct llog_changelog_user_rec *)hdr;
+
+ cucb->idx += snprintf(cucb->page + cucb->idx, cucb->count - cucb->idx,
+ CHANGELOG_USER_PREFIX"%-3d "LPU64"\n",
+ rec->cur_id, rec->cur_endrec);
+ if (cucb->idx >= cucb->count)
+ return -ENOSPC;
+
+ return 0;
+}
+
+static int lprocfs_rd_changelog_users(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
+{
+ struct lu_env env;
+ struct mdd_device *mdd = data;
+ struct llog_ctxt *ctxt;
+ struct cucb_data cucb;
+ __u64 cur;
+ int rc;
+
+ *eof = 1;
+
+ ctxt = llog_get_context(mdd2obd_dev(mdd),
+ LLOG_CHANGELOG_USER_ORIG_CTXT);
+ if (ctxt == NULL)
+ return -ENXIO;
+ LASSERT(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT);
+
+ rc = lu_env_init(&env, LCT_LOCAL);
+ if (rc) {
+ llog_ctxt_put(ctxt);
+ return rc;
+ }
+
+ spin_lock(&mdd->mdd_cl.mc_lock);
+ cur = mdd->mdd_cl.mc_index;
+ spin_unlock(&mdd->mdd_cl.mc_lock);
+
+ cucb.count = count;
+ cucb.page = page;
+ cucb.idx = 0;
+
+ cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx,
+ "current index: "LPU64"\n", cur);
+
+ cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx,
+ "%-5s %s\n", "ID", "index");
+
+ llog_cat_process(&env, ctxt->loc_handle, lprocfs_changelog_users_cb,
+ &cucb, 0, 0);
+
+ lu_env_fini(&env);
+ llog_ctxt_put(ctxt);
+ return cucb.idx;
+}
+
+static int lprocfs_rd_sync_perm(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
+{
+ struct mdd_device *mdd = data;
+
+ LASSERT(mdd != NULL);
+ return snprintf(page, count, "%d\n", mdd->mdd_sync_permission);
+}
+
+static int lprocfs_wr_sync_perm(struct file *file, const char *buffer,
+ unsigned long count, void *data)
+{
+ struct mdd_device *mdd = data;
+ int val, rc;
+
+ LASSERT(mdd != NULL);
+ rc = lprocfs_write_helper(buffer, count, &val);
+ if (rc)
+ return rc;
+
+ mdd->mdd_sync_permission = !!val;
+ return count;
+}
+
+static int lprocfs_rd_lfsck_speed_limit(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
+{
+ struct mdd_device *mdd = data;
+
+ LASSERT(mdd != NULL);
+ *eof = 1;
+ return snprintf(page, count, "%u\n", mdd->mdd_lfsck.ml_speed_limit);
+}
+
+static int lprocfs_wr_lfsck_speed_limit(struct file *file, const char *buffer,
+ unsigned long count, void *data)
+{
+ struct mdd_device *mdd = data;
+ struct md_lfsck *lfsck;
+ __u32 val;
+ int rc;
+
+ LASSERT(mdd != NULL);
+ rc = lprocfs_write_helper(buffer, count, &val);
+ if (rc)
+ return rc;
+
+ lfsck = &mdd->mdd_lfsck;
+ if (val != lfsck->ml_speed_limit)
+ mdd_lfsck_set_speed(lfsck, val);
+ return count;
+}
+