Whamcloud - gitweb
LU-8040 mgc: Apply changelog defaults values in mdd_init0()
[fs/lustre-release.git] / lustre / mdd / mdd_device.c
index 74ab352..6129e11 100644 (file)
@@ -124,6 +124,10 @@ static int mdd_init0(const struct lu_env *env, struct mdd_device *mdd,
        const char *dev;
        ENTRY;
 
+       /* LU-8040 Set defaults here, before values configs */
+       mdd->mdd_cl.mc_flags = 0; /* off by default */
+       mdd->mdd_cl.mc_mask = CHANGELOG_DEFMASK;
+
        dev = lustre_cfg_string(lcfg, 0);
        if (dev == NULL)
                RETURN(rc);
@@ -266,7 +270,48 @@ static int llog_changelog_cancel(const struct lu_env *env,
 static struct llog_operations changelog_orig_logops;
 
 static int
-mdd_changelog_on(const struct lu_env *env, struct mdd_device *mdd, int on);
+mdd_changelog_write_header(const struct lu_env *env, struct mdd_device *mdd,
+                          int markerflags);
+
+static int
+mdd_changelog_on(const struct lu_env *env, struct mdd_device *mdd)
+{
+       int rc = 0;
+
+       if ((mdd->mdd_cl.mc_flags & CLM_ON) != 0)
+               return rc;
+
+       LCONSOLE_INFO("%s: changelog on\n", mdd2obd_dev(mdd)->obd_name);
+       if (mdd->mdd_cl.mc_flags & CLM_ERR) {
+               CERROR("Changelogs cannot be enabled due to error "
+                      "condition (see %s log).\n",
+                      mdd2obd_dev(mdd)->obd_name);
+               rc = -ESRCH;
+       } else {
+               spin_lock(&mdd->mdd_cl.mc_lock);
+               mdd->mdd_cl.mc_flags |= CLM_ON;
+               spin_unlock(&mdd->mdd_cl.mc_lock);
+               rc = mdd_changelog_write_header(env, mdd, CLM_START);
+       }
+       return rc;
+}
+
+static int
+mdd_changelog_off(const struct lu_env *env, struct mdd_device *mdd)
+{
+       int rc = 0;
+
+       if ((mdd->mdd_cl.mc_flags & CLM_ON) != CLM_ON)
+               return rc;
+
+       LCONSOLE_INFO("%s: changelog off\n", mdd2obd_dev(mdd)->obd_name);
+       rc = mdd_changelog_write_header(env, mdd, CLM_FINI);
+       spin_lock(&mdd->mdd_cl.mc_lock);
+       mdd->mdd_cl.mc_flags &= ~CLM_ON;
+       spin_unlock(&mdd->mdd_cl.mc_lock);
+
+       return rc;
+}
 
 static int mdd_changelog_llog_init(const struct lu_env *env,
                                   struct mdd_device *mdd)
@@ -299,7 +344,7 @@ static int mdd_changelog_llog_init(const struct lu_env *env,
        if (rc)
                GOTO(out_cleanup, rc);
 
-       rc = llog_cat_init_and_process(env, ctxt->loc_handle);
+       rc = llog_init_handle(env, ctxt->loc_handle, LLOG_F_IS_CAT, NULL);
        if (rc)
                GOTO(out_close, rc);
 
@@ -335,7 +380,7 @@ static int mdd_changelog_llog_init(const struct lu_env *env,
        uctxt->loc_handle->lgh_logops->lop_add = llog_cat_add_rec;
        uctxt->loc_handle->lgh_logops->lop_declare_add = llog_cat_declare_add_rec;
 
-       rc = llog_cat_init_and_process(env, uctxt->loc_handle);
+       rc = llog_init_handle(env, uctxt->loc_handle, LLOG_F_IS_CAT, NULL);
        if (rc)
                GOTO(out_uclose, rc);
 
@@ -349,7 +394,7 @@ static int mdd_changelog_llog_init(const struct lu_env *env,
 
        /* If we have registered users, assume we want changelogs on */
        if (mdd->mdd_cl.mc_lastuser > 0) {
-               rc = mdd_changelog_on(env, mdd, 1);
+               rc = mdd_changelog_on(env, mdd);
                if (rc < 0)
                        GOTO(out_uclose, rc);
        }
@@ -375,8 +420,6 @@ static int mdd_changelog_init(const struct lu_env *env, struct mdd_device *mdd)
        mdd->mdd_cl.mc_index = 0;
        spin_lock_init(&mdd->mdd_cl.mc_lock);
        mdd->mdd_cl.mc_starttime = cfs_time_current_64();
-       mdd->mdd_cl.mc_flags = 0; /* off by default */
-       mdd->mdd_cl.mc_mask = CHANGELOG_DEFMASK;
        spin_lock_init(&mdd->mdd_cl.mc_user_lock);
        mdd->mdd_cl.mc_lastuser = 0;
 
@@ -410,39 +453,6 @@ static void mdd_changelog_fini(const struct lu_env *env,
        }
 }
 
-static int
-mdd_changelog_write_header(const struct lu_env *env, struct mdd_device *mdd,
-                          int markerflags);
-
-/* Start / stop recording */
-static int
-mdd_changelog_on(const struct lu_env *env, struct mdd_device *mdd, int on)
-{
-        int rc = 0;
-
-        if ((on == 1) && ((mdd->mdd_cl.mc_flags & CLM_ON) == 0)) {
-                LCONSOLE_INFO("%s: changelog on\n", mdd2obd_dev(mdd)->obd_name);
-                if (mdd->mdd_cl.mc_flags & CLM_ERR) {
-                        CERROR("Changelogs cannot be enabled due to error "
-                               "condition (see %s log).\n",
-                               mdd2obd_dev(mdd)->obd_name);
-                        rc = -ESRCH;
-                } else {
-                       spin_lock(&mdd->mdd_cl.mc_lock);
-                       mdd->mdd_cl.mc_flags |= CLM_ON;
-                       spin_unlock(&mdd->mdd_cl.mc_lock);
-                       rc = mdd_changelog_write_header(env, mdd, CLM_START);
-               }
-       } else if ((on == 0) && ((mdd->mdd_cl.mc_flags & CLM_ON) == CLM_ON)) {
-               LCONSOLE_INFO("%s: changelog off\n",mdd2obd_dev(mdd)->obd_name);
-               rc = mdd_changelog_write_header(env, mdd, CLM_FINI);
-               spin_lock(&mdd->mdd_cl.mc_lock);
-               mdd->mdd_cl.mc_flags &= ~CLM_ON;
-               spin_unlock(&mdd->mdd_cl.mc_lock);
-       }
-       return rc;
-}
-
 /** Remove entries with indicies up to and including \a endrec from the
  *  changelog
  * \param mdd
@@ -828,7 +838,7 @@ static int mdd_hsm_actions_llog_init(const struct lu_env *env,
                GOTO(out_cleanup, rc);
        }
 
-       rc = llog_cat_init_and_process(env, ctxt->loc_handle);
+       rc = llog_init_handle(env, ctxt->loc_handle, LLOG_F_IS_CAT, NULL);
        if (rc)
                GOTO(out_close, rc);
 
@@ -1281,10 +1291,10 @@ static int mdd_changelog_user_register(const struct lu_env *env,
                 RETURN(-ENOMEM);
         }
 
-        /* Assume we want it on since somebody registered */
-        rc = mdd_changelog_on(env, mdd, 1);
-        if (rc)
-                GOTO(out, rc);
+       /* Assume we want it on since somebody registered */
+       rc = mdd_changelog_on(env, mdd);
+       if (rc)
+               GOTO(out, rc);
 
         rec->cur_hdr.lrh_len = sizeof(*rec);
         rec->cur_hdr.lrh_type = CHANGELOG_USER_REC;
@@ -1431,11 +1441,11 @@ static int mdd_changelog_user_purge(const struct lu_env *env,
                rc = -ENOENT;
         }
 
-        if (!rc && data.mcud_usercount == 0)
-                /* No more users; turn changelogs off */
-                rc = mdd_changelog_on(env, mdd, 0);
+       if (!rc && data.mcud_usercount == 0)
+               /* No more users; turn changelogs off */
+               rc = mdd_changelog_off(env, mdd);
 
-        RETURN (rc);
+       RETURN(rc);
 }
 
 /** mdd_iocontrol
@@ -1479,7 +1489,12 @@ static int mdd_iocontrol(const struct lu_env *env, struct md_device *m,
                                (struct lfsck_stop *)karg);
                RETURN(rc);
        }
-        }
+       case OBD_IOC_QUERY_LFSCK: {
+               rc = lfsck_query(env, mdd->mdd_bottom, NULL, NULL,
+                                (struct lfsck_query *)karg);
+               RETURN(rc);
+       }
+       }
 
         /* Below ioctls use obd_ioctl_data */
         if (len != sizeof(*data)) {