Whamcloud - gitweb
LU-15481 llog: Add LLOG_SKIP_PLAIN to skip llog plain
[fs/lustre-release.git] / lustre / obdclass / llog_cat.c
index 27b9aad..4f5b0b1 100644 (file)
@@ -246,14 +246,16 @@ static int llog_cat_refresh(const struct lu_env *env,
                if (!llog_exist(loghandle))
                        continue;
 
+               down_write(&loghandle->lgh_lock);
                rc = llog_read_header(env, loghandle, NULL);
+               up_write(&loghandle->lgh_lock);
                if (rc)
                        goto unlock;
        }
 
        rc = llog_read_header(env, cathandle, NULL);
 unlock:
-       up_write(&loghandle->lgh_lock);
+       up_write(&cathandle->lgh_lock);
 
        return rc;
 }
@@ -834,7 +836,8 @@ static int llog_cat_process_common(const struct lu_env *env,
        hdr = (*llhp)->lgh_hdr;
        if ((hdr->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
            hdr->llh_count == 1 && cat_llh->lgh_obj != NULL &&
-           *llhp != cat_llh->u.chd.chd_current_log) {
+           *llhp != cat_llh->u.chd.chd_current_log &&
+           *llhp != cat_llh->u.chd.chd_next_log) {
                rc = llog_destroy(env, *llhp);
                if (rc)
                        CWARN("%s: can't destroy empty log "DFID": rc = %d\n",
@@ -865,6 +868,7 @@ static int llog_cat_process_cb(const struct lu_env *env,
        } else if (d->lpd_startidx > 0) {
                 struct llog_process_cat_data cd;
 
+                cd.lpcd_read_mode = LLOG_READ_MODE_NORMAL;
                 cd.lpcd_first_idx = d->lpd_startidx;
                 cd.lpcd_last_idx = 0;
                rc = llog_process_or_fork(env, llh, d->lpd_cb, d->lpd_data,
@@ -891,6 +895,9 @@ out:
        if (rc == LLOG_DEL_PLAIN || rc == LLOG_DEL_RECORD)
                /* clear wrong catalog entry */
                rc = llog_cat_cleanup(env, cat_llh, llh, rec->lrh_index);
+       else if (rc == LLOG_SKIP_PLAIN)
+               /* processing callback ask to skip the llog -> continue */
+               rc = 0;
 
        if (llh)
                llog_handle_put(env, llh);
@@ -917,7 +924,9 @@ int llog_cat_process_or_fork(const struct lu_env *env,
 
        if (llh->llh_cat_idx >= cat_llh->lgh_last_idx &&
            llh->llh_count > 1) {
-               struct llog_process_cat_data cd;
+               struct llog_process_cat_data cd = {
+                       .lpcd_read_mode = LLOG_READ_MODE_NORMAL
+               };
 
                CWARN("%s: catlog "DFID" crosses index zero\n",
                      loghandle2name(cat_llh),
@@ -1054,6 +1063,9 @@ static int llog_cat_reverse_process_cb(const struct lu_env *env,
        } else if (rc == LLOG_DEL_RECORD) {
                /* clear wrong catalog entry */
                rc = llog_cat_cleanup(env, cat_llh, NULL, rec->lrh_index);
+       } else if (rc == LLOG_SKIP_PLAIN) {
+               /* processing callback ask to skip the llog -> continue */
+               rc = 0;
        }
        if (rc)
                RETURN(rc);
@@ -1080,6 +1092,7 @@ int llog_cat_reverse_process(const struct lu_env *env,
         ENTRY;
 
         LASSERT(llh->llh_flags & LLOG_F_IS_CAT);
+       cd.lpcd_read_mode = LLOG_READ_MODE_NORMAL;
         d.lpd_data = data;
         d.lpd_cb = cb;