Whamcloud - gitweb
LU-7156 mdd: add changelog_size to procfs 16/16416/11
authorAlexander Boyko <alexander.boyko@seagate.com>
Mon, 14 Sep 2015 19:32:46 +0000 (22:32 +0300)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 6 Apr 2016 01:39:50 +0000 (01:39 +0000)
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 <alexander.boyko@seagate.com>
Seagate-bug-id: MRP-2383
Change-Id: Ia2905bbf965256b18708fb79c9e5e07b4ffd2b10
Reviewed-on: http://review.whamcloud.com/16416
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Jenkins
Reviewed-by: Nathaniel Clark <nathaniel.l.clark@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
lustre/include/lustre_log.h
lustre/mdd/mdd_lproc.c
lustre/obdclass/llog.c
lustre/obdclass/llog_cat.c
lustre/tests/sanity.sh

index 8a237b2..d31a1d1 100644 (file)
@@ -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);
index 1329852..1990ae1 100644 (file)
@@ -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",
index 0fdd8fe..68ee8fa 100644 (file)
@@ -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);
+
index 46fbd36..5fdee1f 100644 (file)
@@ -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)
index 8ec8111..f4cf582 100755 (executable)
@@ -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