Whamcloud - gitweb
LU-14688 mdt: changelog purge deletes plain llog
[fs/lustre-release.git] / lustre / mdd / mdd_device.c
index de4c04b..e7923f1 100644 (file)
@@ -27,7 +27,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * lustre/mdd/mdd_device.c
  *
@@ -307,10 +306,8 @@ static int llog_changelog_cancel_cb(const struct lu_env *env,
                                    struct llog_rec_hdr *hdr, void *data)
 {
        struct llog_changelog_rec *rec = (struct llog_changelog_rec *)hdr;
-       struct llog_cookie       cookie;
        struct changelog_cancel_cookie *cl_cookie =
                (struct changelog_cancel_cookie *)data;
-       int                      rc;
 
        ENTRY;
 
@@ -340,15 +337,40 @@ static int llog_changelog_cancel_cb(const struct lu_env *env,
                /* records are in order, so we're done */
                RETURN(LLOG_PROC_BREAK);
 
-       cookie.lgc_lgl = llh->lgh_id;
-       cookie.lgc_index = hdr->lrh_index;
+       if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_CHANGELOG_RACE))) {
+               if (cfs_fail_val == 0)
+                       cfs_fail_val = hdr->lrh_index;
+               if (cfs_fail_val == hdr->lrh_index)
+                       OBD_RACE(OBD_FAIL_MDS_CHANGELOG_RACE);
+       }
+
+       /* Records folow one by one, cr_index++. We could calculate the
+        * last cr_index at this plain llog. And if it less then cookie endrec
+        * cancel the whole file.
+        */
+       if ((LLOG_HDR_BITMAP_SIZE(llh->lgh_hdr) - hdr->lrh_index +
+            rec->cr.cr_index) < cl_cookie->endrec) {
+               int rc;
+
+               if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_CHANGELOG_DEL))) {
+                       if (cfs_fail_val == 0) {
+                               cfs_fail_val = (unsigned long)llh & 0xFFFFFFFF;
+                               OBD_RACE(OBD_FAIL_MDS_CHANGELOG_DEL);
+                       }
+               }
+               rc = llog_destroy(env, llh);
+               if (!rc) {
+                       CDEBUG(D_HA, "Changelog destroyed plain "DFID"\n",
+                              PFID(&llh->lgh_id.lgl_oi.oi_fid));
+                       RETURN(LLOG_DEL_PLAIN);
+               }
+       }
 
        /* cancel them one at a time.  I suppose we could store up the cookies
         * and cancel them all at once; probably more efficient, but this is
         * done as a user call, so who cares... */
-       rc = llog_cat_cancel_records(env, llh->u.phd.phd_cat_handle, 1,
-                                    &cookie);
-       RETURN(rc < 0 ? rc : 0);
+
+       RETURN(LLOG_DEL_RECORD);
 }
 
 static int llog_changelog_cancel(const struct lu_env *env,
@@ -725,7 +747,7 @@ int mdd_changelog_write_header(const struct lu_env *env,
        }
 
        reclen = llog_data_len(sizeof(*rec) + len);
-       buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_big_buf, reclen);
+       buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_chlg_buf, reclen);
        if (buf->lb_buf == NULL)
                RETURN(-ENOMEM);
        rec = buf->lb_buf;
@@ -1817,7 +1839,11 @@ static int mdd_changelog_clear(const struct lu_env *env,
                              mdd_changelog_clear_cb, (void *)&mcuc,
                              0, 0);
 
-       if (rc < 0) {
+       if (rc == -EINVAL) {
+               CDEBUG(D_IOCTL, "%s: No changelog recnum <= %llu to clear\n",
+                      mdd2obd_dev(mdd)->obd_name, (unsigned long long) endrec);
+               RETURN(-EINVAL);
+       } else if (rc < 0) {
                CWARN("%s: Failure to clear the changelog for user %d: %d\n",
                      mdd2obd_dev(mdd)->obd_name, id, rc);
        } else if (mcuc.mcuc_flush) {
@@ -1832,7 +1858,7 @@ static int mdd_changelog_clear(const struct lu_env *env,
                                                      mcuc.mcuc_minrec);
                }
        } else {
-               CWARN("%s: No entry for user %d\n",
+               CDEBUG(D_IOCTL, "%s: No entry for user %d\n",
                      mdd2obd_dev(mdd)->obd_name, id);
                rc = -ENOENT;
        }
@@ -1943,17 +1969,17 @@ static const struct md_device_operations mdd_ops = {
        .mdo_dtconf_get     = mdd_dtconf_get,
 };
 
-static struct lu_device_type_operations mdd_device_type_ops = {
-        .ldto_init = mdd_type_init,
-        .ldto_fini = mdd_type_fini,
+static const struct lu_device_type_operations mdd_device_type_ops = {
+       .ldto_init              = mdd_type_init,
+       .ldto_fini              = mdd_type_fini,
 
-        .ldto_start = mdd_type_start,
-        .ldto_stop  = mdd_type_stop,
+       .ldto_start             = mdd_type_start,
+       .ldto_stop              = mdd_type_stop,
 
-        .ldto_device_alloc = mdd_device_alloc,
-        .ldto_device_free  = mdd_device_free,
+       .ldto_device_alloc      = mdd_device_alloc,
+       .ldto_device_free       = mdd_device_free,
 
-        .ldto_device_fini    = mdd_device_fini
+       .ldto_device_fini       = mdd_device_fini
 };
 
 static struct lu_device_type mdd_device_type = {
@@ -1974,6 +2000,7 @@ static void mdd_key_fini(const struct lu_context *ctx,
        lu_buf_free(&info->mti_big_buf);
        lu_buf_free(&info->mti_link_buf);
        lu_buf_free(&info->mti_xattr_buf);
+       lu_buf_free(&info->mti_chlg_buf);
 
        OBD_FREE_PTR(info);
 }