Whamcloud - gitweb
LU-5405 llog: add newly opened llog at tail of handle list
[fs/lustre-release.git] / lustre / obdclass / llog_cat.c
index b34d5d3..181fbf5 100644 (file)
@@ -48,9 +48,6 @@
 
 #define DEBUG_SUBSYSTEM S_LOG
 
-#ifndef __KERNEL__
-#include <liblustre.h>
-#endif
 
 #include <obd_class.h>
 
@@ -173,7 +170,7 @@ int llog_cat_id2handle(const struct lu_env *env, struct llog_handle *cathandle,
        }
 
        down_write(&cathandle->lgh_lock);
-       list_add(&loghandle->u.phd.phd_entry, &cathandle->u.chd.chd_head);
+       list_add_tail(&loghandle->u.phd.phd_entry, &cathandle->u.chd.chd_head);
        up_write(&cathandle->lgh_lock);
 
        loghandle->u.phd.phd_cat_handle = cathandle;
@@ -535,6 +532,17 @@ int llog_cat_process_cb(const struct lu_env *env, struct llog_handle *cat_llh,
                CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
                       cat_llh->lgh_ctxt->loc_obd->obd_name,
                       POSTID(&lir->lid_id.lgl_oi), rc);
+               if (rc == -ENOENT || rc == -ESTALE) {
+                       /* After a server crash, a stub of index
+                        * record in catlog could be kept, because
+                        * plain log destroy + catlog index record
+                        * deletion are not atomic. So we end up with
+                        * an index but no actual record. Destroy the
+                        * index and move on. */
+                       rc = llog_cat_cleanup(env, cat_llh, NULL,
+                                             rec->lrh_index);
+               }
+
                RETURN(rc);
        }
 
@@ -650,6 +658,17 @@ static int llog_cat_reverse_process_cb(const struct lu_env *env,
                CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
                       cat_llh->lgh_ctxt->loc_obd->obd_name,
                       POSTID(&lir->lid_id.lgl_oi), rc);
+               if (rc == -ENOENT || rc == -ESTALE) {
+                       /* After a server crash, a stub of index
+                        * record in catlog could be kept, because
+                        * plain log destroy + catlog index record
+                        * deletion are not atomic. So we end up with
+                        * an index but no actual record. Destroy the
+                        * index and move on. */
+                       rc = llog_cat_cleanup(env, cat_llh, NULL,
+                                             rec->lrh_index);
+               }
+
                RETURN(rc);
        }