char *name, char *backup);
int llog_read_header(const struct lu_env *env, struct llog_handle *handle,
const struct obd_uuid *uuid);
+__u64 llog_size(const struct lu_env *env, struct llog_handle *llh);
/* llog_process flags */
#define LLOG_FLAG_NODEAMON 0x0001
struct llog_handle *cathandle, int count,
struct llog_cookie *cookies);
int llog_cat_process_or_fork(const struct lu_env *env,
- struct llog_handle *cat_llh, llog_cb_t cb,
- void *data, int startcat, int startidx, bool fork);
+ struct llog_handle *cat_llh, llog_cb_t cat_cb,
+ llog_cb_t cb, void *data, int startcat,
+ int startidx, bool fork);
int llog_cat_process(const struct lu_env *env, struct llog_handle *cat_llh,
llog_cb_t cb, void *data, int startcat, int startidx);
+__u64 llog_cat_size(const struct lu_env *env, struct llog_handle *cat_llh);
int llog_cat_reverse_process(const struct lu_env *env,
struct llog_handle *cat_llh, llog_cb_t cb,
void *data);
}
LPROC_SEQ_FOPS_RO(mdd_changelog_users);
+static int mdd_changelog_size_ctxt(const struct lu_env *env,
+ struct mdd_device *mdd,
+ int index, __u64 *val)
+{
+ struct llog_ctxt *ctxt;
+
+ ctxt = llog_get_context(mdd2obd_dev(mdd),
+ index);
+ if (ctxt == NULL)
+ return -ENXIO;
+
+ if (!(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) {
+ CERROR("%s: ChangeLog has wrong flags: rc = %d\n",
+ ctxt->loc_obd->obd_name, -EINVAL);
+ llog_ctxt_put(ctxt);
+ return -EINVAL;
+ }
+
+ *val += llog_cat_size(env, ctxt->loc_handle);
+
+ llog_ctxt_put(ctxt);
+
+ return 0;
+}
+
+static int mdd_changelog_size_seq_show(struct seq_file *m, void *data)
+{
+ struct lu_env env;
+ struct mdd_device *mdd = m->private;
+ __u64 tmp = 0;
+ int rc;
+
+ rc = lu_env_init(&env, LCT_LOCAL);
+ if (rc)
+ return rc;
+
+ rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_ORIG_CTXT, &tmp);
+ if (rc) {
+ lu_env_fini(&env);
+ return rc;
+ }
+
+ rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_USER_ORIG_CTXT,
+ &tmp);
+
+ seq_printf(m, LPU64"\n", tmp);
+ lu_env_fini(&env);
+ return rc;
+}
+LPROC_SEQ_FOPS_RO(mdd_changelog_size);
+
static int mdd_sync_perm_seq_show(struct seq_file *m, void *data)
{
struct mdd_device *mdd = m->private;
.fops = &mdd_changelog_mask_fops },
{ .name = "changelog_users",
.fops = &mdd_changelog_users_fops },
+ { .name = "changelog_size",
+ .fops = &mdd_changelog_size_fops },
{ .name = "sync_permission",
.fops = &mdd_sync_perm_fops },
{ .name = "lfsck_speed_limit",
RETURN(rc);
}
EXPORT_SYMBOL(llog_backup);
+
+/* Get size of llog */
+__u64 llog_size(const struct lu_env *env, struct llog_handle *llh)
+{
+ int rc;
+ struct lu_attr la;
+
+ rc = llh->lgh_obj->do_ops->do_attr_get(env, llh->lgh_obj, &la);
+ if (rc) {
+ CERROR("%s: attr_get failed, rc = %d\n",
+ llh->lgh_ctxt->loc_obd->obd_name, rc);
+ return 0;
+ }
+
+ return la.la_size;
+}
+EXPORT_SYMBOL(llog_size);
+
}
int llog_cat_process_or_fork(const struct lu_env *env,
- struct llog_handle *cat_llh,
+ struct llog_handle *cat_llh, llog_cb_t cat_cb,
llog_cb_t cb, void *data, int startcat,
int startidx, bool fork)
{
cd.lpcd_first_idx = llh->llh_cat_idx;
cd.lpcd_last_idx = 0;
- rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
+ rc = llog_process_or_fork(env, cat_llh, cat_cb,
&d, &cd, fork);
if (rc != 0)
RETURN(rc);
cd.lpcd_first_idx = 0;
cd.lpcd_last_idx = cat_llh->lgh_last_idx;
- rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
+ rc = llog_process_or_fork(env, cat_llh, cat_cb,
&d, &cd, fork);
} else {
- rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
+ rc = llog_process_or_fork(env, cat_llh, cat_cb,
&d, NULL, fork);
}
int llog_cat_process(const struct lu_env *env, struct llog_handle *cat_llh,
llog_cb_t cb, void *data, int startcat, int startidx)
{
- return llog_cat_process_or_fork(env, cat_llh, cb, data, startcat,
- startidx, false);
+ return llog_cat_process_or_fork(env, cat_llh, llog_cat_process_cb,
+ cb, data, startcat, startidx, false);
}
EXPORT_SYMBOL(llog_cat_process);
+static int llog_cat_size_cb(const struct lu_env *env,
+ struct llog_handle *cat_llh,
+ struct llog_rec_hdr *rec, void *data)
+{
+ struct llog_process_data *d = data;
+ struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
+ struct llog_handle *llh;
+ int rc;
+ __u64 *cum_size = d->lpd_data;
+ __u64 size;
+
+ ENTRY;
+ if (rec->lrh_type != LLOG_LOGID_MAGIC) {
+ CERROR("%s: invalid record in catalog, rc = %d\n",
+ cat_llh->lgh_ctxt->loc_obd->obd_name, -EINVAL);
+ RETURN(-EINVAL);
+ }
+ CDEBUG(D_HA, "processing log "DOSTID":%x at index %u of catalog "
+ DOSTID"\n", POSTID(&lir->lid_id.lgl_oi), lir->lid_id.lgl_ogen,
+ rec->lrh_index, POSTID(&cat_llh->lgh_id.lgl_oi));
+
+ rc = llog_cat_id2handle(env, cat_llh, &llh, &lir->lid_id);
+ if (rc) {
+ CWARN("%s: cannot find handle for llog "DOSTID": rc = %d\n",
+ cat_llh->lgh_ctxt->loc_obd->obd_name,
+ POSTID(&lir->lid_id.lgl_oi), rc);
+ RETURN(0);
+ }
+ size = llog_size(env, llh);
+ *cum_size += size;
+
+ CDEBUG(D_INFO, "Add llog entry "DOSTID" size "LPU64"\n",
+ POSTID(&llh->lgh_id.lgl_oi), size);
+
+ llog_handle_put(llh);
+
+ RETURN(0);
+
+}
+
+__u64 llog_cat_size(const struct lu_env *env, struct llog_handle *cat_llh)
+{
+ __u64 size = llog_size(env, cat_llh);
+
+ llog_cat_process_or_fork(env, cat_llh, llog_cat_size_cb,
+ NULL, &size, 0, 0, false);
+
+ return size;
+}
+EXPORT_SYMBOL(llog_cat_size);
+
static int llog_cat_reverse_process_cb(const struct lu_env *env,
struct llog_handle *cat_llh,
struct llog_rec_hdr *rec, void *data)
}
run_test 252 "check lr_reader tool"
+test_254() {
+ local cl_user
+
+ [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+ remote_mds_nodsh && skip "remote MDS with nodsh" && return
+ do_facet mds1 $LCTL get_param -n mdd.$MDT0.changelog_size ||
+ { skip "MDS does not support changelog_size" && return; }
+
+ cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
+ echo "Registered as changelog user $cl_user"
+
+ $LFS changelog_clear $MDT0 $cl_user 0
+
+ local size1=$(do_facet mds1 \
+ $LCTL get_param -n mdd.$MDT0.changelog_size)
+ echo "Changelog size $size1"
+
+ rm -rf $DIR/$tdir
+ $LFS mkdir -i 0 $DIR/$tdir
+ # change something
+ mkdir -p $DIR/$tdir/pics/2008/zachy
+ touch $DIR/$tdir/pics/2008/zachy/timestamp
+ cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
+ mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
+ ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
+ ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
+ rm $DIR/$tdir/pics/desktop.jpg
+
+ local size2=$(do_facet mds1 \
+ $LCTL get_param -n mdd.$MDT0.changelog_size)
+ echo "Changelog size after work $size2"
+
+ do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
+
+ if (( size2 <= size1 )); then
+ error "Changelog size after work should be greater than original"
+ fi
+ return 0
+}
+run_test 254 "Check changelog size"
+
test_256() {
local cl_user
local cat_sl