Whamcloud - gitweb
b=3825
authoralex <alex>
Wed, 28 Jul 2004 21:22:30 +0000 (21:22 +0000)
committeralex <alex>
Wed, 28 Jul 2004 21:22:30 +0000 (21:22 +0000)
r=robert

  landed on HEAD

lustre/include/linux/lustre_idl.h
lustre/lvfs/llog_cat.c
lustre/lvfs/llog_lvfs.c

index 2e18afe..8f5bd37 100644 (file)
@@ -1042,6 +1042,10 @@ struct llog_log_hdr {
         struct llog_rec_tail    llh_tail;
 } __attribute__((packed));
 
+#define LLOG_BITMAP_SIZE(llh)  ((llh->llh_hdr.lrh_len -         \
+                                 llh->llh_bitmap_offset -       \
+                                 sizeof(llh->llh_tail)) * 8)
+
 /* log cookies are used to reference a specific log file and a record therein */
 struct llog_cookie {
         struct llog_logid       lgc_lgl;
index 3837b4d..901a4a2 100644 (file)
@@ -56,7 +56,7 @@ static struct llog_handle *llog_cat_new_log(struct llog_handle *cathandle,
         ENTRY;
 
         llh = cathandle->lgh_hdr;
-        bitmap_size = sizeof(llh->llh_bitmap) * 8;
+        bitmap_size = LLOG_BITMAP_SIZE(llh);
 
         index = (cathandle->lgh_last_idx + 1) % bitmap_size;
 
@@ -223,13 +223,15 @@ static struct llog_handle *llog_cat_current_log(struct llog_handle *cathandle,
         loghandle = cathandle->u.chd.chd_current_log;
         if (loghandle) {
                 struct llog_log_hdr *llh = loghandle->lgh_hdr;
-                if (loghandle->lgh_last_idx < (sizeof(llh->llh_bitmap)*8) - 1 &&
+                down_write(&loghandle->lgh_lock);
+                if (loghandle->lgh_last_idx < (LLOG_BITMAP_SIZE(llh) - 1) &&
                     (!logcookie ||
                      !(llog_cookie_get_flags(logcookie) & LLOG_COOKIE_REPLAY) ||
                      EQ_LOGID(loghandle->lgh_id, logcookie->lgc_lgl))) {
-                        down_write(&loghandle->lgh_lock);
                         up_read(&cathandle->lgh_lock);
                         RETURN(loghandle);
+                } else {
+                        up_write(&loghandle->lgh_lock);
                 }
         }
 
@@ -252,13 +254,15 @@ static struct llog_handle *llog_cat_current_log(struct llog_handle *cathandle,
         loghandle = cathandle->u.chd.chd_current_log;
         if (loghandle) {
                 struct llog_log_hdr *llh = loghandle->lgh_hdr;
-                if (loghandle->lgh_last_idx < (sizeof(llh->llh_bitmap)*8) - 1 &&
+                down_write(&loghandle->lgh_lock);
+                if (loghandle->lgh_last_idx < (LLOG_BITMAP_SIZE(llh) - 1) &&
                     (!logcookie ||
                      !(llog_cookie_get_flags(logcookie) & LLOG_COOKIE_REPLAY) ||
                      EQ_LOGID(loghandle->lgh_id, logcookie->lgc_lgl))) {
-                        down_write(&loghandle->lgh_lock);
                         up_write(&cathandle->lgh_lock);
                         RETURN(loghandle);
+                } else {
+                        down_write(&loghandle->lgh_lock);
                 }
         }
 
@@ -485,7 +489,7 @@ int llog_cat_set_first_idx(struct llog_handle *cathandle, int index)
         int i, bitmap_size, idx;
         ENTRY;
 
-        bitmap_size = sizeof(llh->llh_bitmap) * 8;
+        bitmap_size = LLOG_BITMAP_SIZE(llh);
         if (llh->llh_cat_idx == cpu_to_le32(index - 1)) {
                 idx = le32_to_cpu(llh->llh_cat_idx) + 1;
                 llh->llh_cat_idx = cpu_to_le32(idx);
index 5f57b64..3b1b548 100644 (file)
@@ -246,6 +246,9 @@ static int llog_lvfs_write_rec(struct llog_handle *loghandle,
                 rc = llog_lvfs_pad(ctxt, file, left, loghandle->lgh_last_idx);
                 if (rc)
                         RETURN(rc);
+                /* if it's the last idx in log file, then return -ENOSPC */
+                if (loghandle->lgh_last_idx == LLOG_BITMAP_SIZE(llh) - 1)
+                        RETURN(-ENOSPC);
         }
 
         loghandle->lgh_last_idx++;