From 793ce5e6f570212f854eedda32277e7037079eaf Mon Sep 17 00:00:00 2001 From: Alexander Boyko Date: Mon, 14 Sep 2015 22:32:46 +0300 Subject: [PATCH 1/1] LU-7156 mdd: add changelog_size to procfs It is hard to get size of changelogs. This patch adds new procfs file changelog_size. It shows the current size of all changelog files. Signed-off-by: Alexander Boyko Seagate-bug-id: MRP-2383 Change-Id: Ia2905bbf965256b18708fb79c9e5e07b4ffd2b10 Reviewed-on: http://review.whamcloud.com/16416 Reviewed-by: Andreas Dilger Tested-by: Jenkins Reviewed-by: Nathaniel Clark Tested-by: Maloo --- lustre/include/lustre_log.h | 7 +++-- lustre/mdd/mdd_lproc.c | 53 ++++++++++++++++++++++++++++++++++++++ lustre/obdclass/llog.c | 18 +++++++++++++ lustre/obdclass/llog_cat.c | 63 ++++++++++++++++++++++++++++++++++++++++----- lustre/tests/sanity.sh | 41 +++++++++++++++++++++++++++++ 5 files changed, 174 insertions(+), 8 deletions(-) diff --git a/lustre/include/lustre_log.h b/lustre/include/lustre_log.h index 8a237b2..d31a1d1 100644 --- a/lustre/include/lustre_log.h +++ b/lustre/include/lustre_log.h @@ -106,6 +106,7 @@ int llog_backup(const struct lu_env *env, struct obd_device *obd, 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 @@ -153,10 +154,12 @@ int llog_cat_cancel_records(const struct lu_env *env, 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); diff --git a/lustre/mdd/mdd_lproc.c b/lustre/mdd/mdd_lproc.c index 1329852..1990ae1 100644 --- a/lustre/mdd/mdd_lproc.c +++ b/lustre/mdd/mdd_lproc.c @@ -178,6 +178,57 @@ static int mdd_changelog_users_seq_show(struct seq_file *m, 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; @@ -285,6 +336,8 @@ static struct lprocfs_vars lprocfs_mdd_obd_vars[] = { .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", diff --git a/lustre/obdclass/llog.c b/lustre/obdclass/llog.c index 0fdd8fe..68ee8fa 100644 --- a/lustre/obdclass/llog.c +++ b/lustre/obdclass/llog.c @@ -1244,3 +1244,21 @@ out_close: 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); + diff --git a/lustre/obdclass/llog_cat.c b/lustre/obdclass/llog_cat.c index 46fbd36..5fdee1f7 100644 --- a/lustre/obdclass/llog_cat.c +++ b/lustre/obdclass/llog_cat.c @@ -794,7 +794,7 @@ out: } 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) { @@ -818,17 +818,17 @@ int llog_cat_process_or_fork(const struct lu_env *env, 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); } @@ -838,11 +838,62 @@ int llog_cat_process_or_fork(const struct lu_env *env, 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) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 8ec8111..f4cf582 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -13570,6 +13570,47 @@ test_252() { } 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 -- 1.8.3.1