Whamcloud - gitweb
LU-6471 obdclass: fix llog_cat_cleanup() usage on Client
[fs/lustre-release.git] / lustre / obdclass / llog_cat.c
index 181fbf5..c8c2da3 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2013, Intel Corporation.
+ * Copyright (c) 2012, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -125,6 +125,7 @@ int llog_cat_id2handle(const struct lu_env *env, struct llog_handle *cathandle,
                       struct llog_handle **res, struct llog_logid *logid)
 {
        struct llog_handle      *loghandle;
+       enum llog_flag           fmt;
        int                      rc = 0;
 
        ENTRY;
@@ -132,6 +133,7 @@ int llog_cat_id2handle(const struct lu_env *env, struct llog_handle *cathandle,
        if (cathandle == NULL)
                RETURN(-EBADF);
 
+       fmt = cathandle->lgh_hdr->llh_flags & LLOG_F_EXT_MASK;
        down_write(&cathandle->lgh_lock);
        list_for_each_entry(loghandle, &cathandle->u.chd.chd_head,
                            u.phd.phd_entry) {
@@ -162,7 +164,7 @@ int llog_cat_id2handle(const struct lu_env *env, struct llog_handle *cathandle,
                RETURN(rc);
        }
 
-       rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN, NULL);
+       rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN | fmt, NULL);
        if (rc < 0) {
                llog_close(env, loghandle);
                loghandle = NULL;
@@ -509,8 +511,9 @@ int llog_cat_cancel_records(const struct lu_env *env,
 }
 EXPORT_SYMBOL(llog_cat_cancel_records);
 
-int llog_cat_process_cb(const struct lu_env *env, struct llog_handle *cat_llh,
-                       struct llog_rec_hdr *rec, void *data)
+static int llog_cat_process_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;
@@ -547,9 +550,10 @@ int llog_cat_process_cb(const struct lu_env *env, struct llog_handle *cat_llh,
        }
 
        /* clean old empty llogs, do not consider current llog in use */
+       /* ignore remote (lgh_obj=NULL) llogs */
        hdr = llh->lgh_hdr;
        if ((hdr->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
-           hdr->llh_count == 1 &&
+           hdr->llh_count == 1 && cat_llh->lgh_obj != NULL &&
            llh != cat_llh->u.chd.chd_current_log) {
                rc = llog_destroy(env, llh);
                if (rc)
@@ -625,7 +629,6 @@ int llog_cat_process_or_fork(const struct lu_env *env,
 
         RETURN(rc);
 }
-EXPORT_SYMBOL(llog_cat_process_or_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)
@@ -737,7 +740,7 @@ int llog_cat_reverse_process(const struct lu_env *env,
 }
 EXPORT_SYMBOL(llog_cat_reverse_process);
 
-int llog_cat_set_first_idx(struct llog_handle *cathandle, int index)
+static int llog_cat_set_first_idx(struct llog_handle *cathandle, int index)
 {
         struct llog_log_hdr *llh = cathandle->lgh_hdr;
         int i, bitmap_size, idx;
@@ -788,6 +791,11 @@ int llog_cat_cleanup(const struct lu_env *env, struct llog_handle *cathandle,
                /* llog was opened and keep in a list, close it now */
                llog_close(env, loghandle);
        }
+
+       /* do not attempt to cleanup on-disk llog if on client side */
+       if (cathandle->lgh_obj == NULL)
+               return 0;
+
        /* remove plain llog entry from catalog by index */
        llog_cat_set_first_idx(cathandle, index);
        rc = llog_cancel_rec(env, cathandle, index);
@@ -798,54 +806,6 @@ int llog_cat_cleanup(const struct lu_env *env, struct llog_handle *cathandle,
        return rc;
 }
 
-int cat_cancel_cb(const struct lu_env *env, struct llog_handle *cathandle,
-                 struct llog_rec_hdr *rec, void *data)
-{
-       struct llog_logid_rec   *lir = (struct llog_logid_rec *)rec;
-       struct llog_handle      *loghandle;
-       struct llog_log_hdr     *llh;
-       int                      rc;
-
-       ENTRY;
-
-       if (rec->lrh_type != LLOG_LOGID_MAGIC) {
-               CERROR("invalid record in catalog\n");
-               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(&cathandle->lgh_id.lgl_oi));
-
-       rc = llog_cat_id2handle(env, cathandle, &loghandle, &lir->lid_id);
-       if (rc) {
-               CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
-                      cathandle->lgh_ctxt->loc_obd->obd_name,
-                      POSTID(&lir->lid_id.lgl_oi), rc);
-               if (rc == -ENOENT || rc == -ESTALE) {
-                       /* remove index from catalog */
-                       llog_cat_cleanup(env, cathandle, NULL, rec->lrh_index);
-               }
-               RETURN(rc);
-       }
-
-       llh = loghandle->lgh_hdr;
-       if ((llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
-           (llh->llh_count == 1)) {
-               rc = llog_destroy(env, loghandle);
-               if (rc)
-                       CERROR("%s: fail to destroy empty log: rc = %d\n",
-                              loghandle->lgh_ctxt->loc_obd->obd_name, rc);
-
-               llog_cat_cleanup(env, cathandle, loghandle,
-                                loghandle->u.phd.phd_cookie.lgc_index);
-       }
-       llog_handle_put(loghandle);
-
-       RETURN(rc);
-}
-EXPORT_SYMBOL(cat_cancel_cb);
-
 /* helper to initialize catalog llog and process it to cancel */
 int llog_cat_init_and_process(const struct lu_env *env,
                              struct llog_handle *llh)
@@ -859,4 +819,3 @@ int llog_cat_init_and_process(const struct lu_env *env,
        RETURN(0);
 }
 EXPORT_SYMBOL(llog_cat_init_and_process);
-