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;
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;
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);
}
}
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);
}
}
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);
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++;