Whamcloud - gitweb
Branch: HEAD
[fs/lustre-release.git] / lustre / lvfs / llog.c
index 12da23b..99bb653 100644 (file)
@@ -100,17 +100,23 @@ int llog_cancel_rec(struct llog_handle *loghandle, int index)
             (le32_to_cpu(llh->llh_count) == 1) &&
             (loghandle->lgh_last_idx == (LLOG_BITMAP_BYTES * 8) - 1)) {
                 rc = llog_destroy(loghandle);
-                if (rc)
+                if (rc) {
                         CERROR("failure destroying log after last cancel: %d\n",
                                rc);
-                LASSERT(rc == 0);
-                RETURN(1);
+                        ext2_set_bit(index, llh->llh_bitmap);
+                        llh->llh_count++;
+                } else {
+                        rc = 1;
+                }
+                RETURN(rc);
         }
 
         rc = llog_write_rec(loghandle, &llh->llh_hdr, NULL, 0, NULL, 0);
-        if (rc)
+        if (rc) {
                 CERROR("failure re-writing header %d\n", rc);
-        LASSERT(rc == 0);
+                ext2_set_bit(index, llh->llh_bitmap);
+                llh->llh_count++;
+        }
         RETURN(rc);
 }
 EXPORT_SYMBOL(llog_cancel_rec);
@@ -182,7 +188,7 @@ int llog_close(struct llog_handle *loghandle)
         if (rc)
                 GOTO(out, rc);
         if (lop->lop_close == NULL)
-                GOTO(out, -EOPNOTSUPP);
+                GOTO(out, rc = -EOPNOTSUPP);
         rc = lop->lop_close(loghandle);
  out:
         llog_free_handle(loghandle);
@@ -243,7 +249,7 @@ int llog_process(struct llog_handle *loghandle, llog_cb_t cb,
                 /* process records in buffer, starting where we found one */
                 while ((void *)rec < buf + LLOG_CHUNK_SIZE) {
                         if (rec->lrh_index == 0)
-                                GOTO(out, 0); /* no more records */
+                                GOTO(out, rc = 0); /* no more records */
 
                         /* if set, process the callback on this record */
                         if (ext2_test_bit(index, llh->llh_bitmap)) {
@@ -254,11 +260,13 @@ int llog_process(struct llog_handle *loghandle, llog_cb_t cb,
                                               loghandle->lgh_id.lgl_oid,
                                               loghandle->lgh_id.lgl_ogen);
                                         GOTO(out, rc);
-                                }
+                                } else if (rc == LLOG_DEL_RECORD) {
+                                        llog_cancel_rec(loghandle, rec->lrh_index);
+                                        rc = 0;
+                                } 
                                 if (rc)
                                         GOTO(out, rc);
                         }
-
                         /* next record, still in buffer? */
                         ++index;
                         if (index > last_index)
@@ -345,6 +353,10 @@ int llog_reverse_process(struct llog_handle *loghandle, llog_cb_t cb,
                         --index;
                         if (index < first_index)
                                 GOTO(out, rc = 0);
+
+                        if ((void *)rec == buf)
+                                break;
+
                         tail = (void *)rec - sizeof(struct llog_rec_tail);
                         rec = ((void *)rec - le32_to_cpu(tail->lrt_len));
                 }