70 #include <linux/export.h>
74 #include <linux/slab.h>
86 static struct lbuf *log_redrive_list;
93 #define LOG_LOCK_INIT(log) mutex_init(&(log)->loglock)
94 #define LOG_LOCK(log) mutex_lock(&((log)->loglock))
95 #define LOG_UNLOCK(log) mutex_unlock(&((log)->loglock))
102 #define LOGGC_LOCK_INIT(log) spin_lock_init(&(log)->gclock)
103 #define LOGGC_LOCK(log) spin_lock_irq(&(log)->gclock)
104 #define LOGGC_UNLOCK(log) spin_unlock_irq(&(log)->gclock)
105 #define LOGGC_WAKEUP(tblk) wake_up_all(&(tblk)->gcwait)
110 #define LOGSYNC_DELTA(logsize) min((logsize)/8, 128*LOGPSIZE)
111 #define LOGSYNC_BARRIER(logsize) ((logsize)/4)
123 #define LCACHE_LOCK(flags) spin_lock_irqsave(&jfsLCacheLock, flags)
124 #define LCACHE_UNLOCK(flags) spin_unlock_irqrestore(&jfsLCacheLock, flags)
129 #define LCACHE_SLEEP_COND(wq, cond, flags) \
133 __SLEEP_COND(wq, cond, LCACHE_LOCK(flags), LCACHE_UNLOCK(flags)); \
136 #define LCACHE_WAKEUP(event) wake_up(event)
143 #define lbmREAD 0x0001
144 #define lbmWRITE 0x0002
147 #define lbmRELEASE 0x0004
152 #define lbmSYNC 0x0008
155 #define lbmFREE 0x0010
159 #define lbmDONE 0x0020
160 #define lbmERROR 0x0040
164 #define lbmDIRECT 0x0100
186 static void lbmLogShutdown(
struct jfs_log *
log);
188 static void lbmFree(
struct lbuf * bp);
189 static void lbmfree(
struct lbuf * bp);
191 static void lbmWrite(
struct jfs_log *
log,
struct lbuf * bp,
int flag,
int cant_block);
193 static int lbmIOWait(
struct lbuf * bp,
int flag);
194 static bio_end_io_t lbmIODone;
195 static void lbmStartIO(
struct lbuf * bp);
196 static void lmGCwrite(
struct jfs_log *
log,
int cant_block);
197 static int lmLogSync(
struct jfs_log *
log,
int hard_sync);
204 #ifdef CONFIG_JFS_STATISTICS
205 static struct lmStat {
214 static void write_special_inodes(
struct jfs_log *
log,
246 jfs_info(
"lmLog: log:0x%p tblk:0x%p, lrd:0x%p tlck:0x%p",
247 log, tblk, lrd, tlck);
297 if (tblk->
lsn == 0) {
327 lsn = lmWriteRecord(log, tblk, lrd, tlck);
334 lsn = lmLogSync(log, 0);
380 bp = (
struct lbuf *) log->
bp;
382 dstoffset = log->
eor;
394 linelock = (
struct linelock *) & tlck->
lock;
399 p = (
caddr_t) &JFS_IP(tlck->
ip)->i_dtroot;
401 p = (
caddr_t) &JFS_IP(tlck->
ip)->i_xtroot;
402 linelock = (
struct linelock *) & tlck->
lock;
407 inlinelock = (
struct inlinelock *) & tlck;
408 p = (
caddr_t) & inlinelock->pxd;
409 linelock = (
struct linelock *) & tlck;
413 jfs_err(
"lmWriteRecord: UFO tlck:0x%p", tlck);
422 for (i = 0; i < linelock->
index; i++, lv++) {
439 src = (
u8 *) p + (lv->
offset << l2linesize);
440 srclen = lv->
length << l2linesize;
444 nbytes =
min(freespace, srclen);
445 dst = (
caddr_t) lp + dstoffset;
456 bp = (
struct lbuf *) log->
bp;
468 lvd = (
struct lvd *) ((
caddr_t) lp + dstoffset);
472 jfs_info(
"lmWriteRecord: lv offset:%d length:%d",
476 if ((i = linelock->
next)) {
492 nbytes =
min(freespace, srclen);
493 dst = (
caddr_t) lp + dstoffset;
508 log->
eor = dstoffset;
509 bp->
l_eor = dstoffset;
541 jfs_info(
"lmWriteRecord: lrd:0x%04x bp:0x%p pn:%d eor:0x%x",
552 bp = (
struct lbuf *) log->
bp;
573 static int lmNextPage(
struct jfs_log * log)
594 if (list_empty(&log->
cqueue))
609 if (tblk && tblk->
pn == pn) {
621 lbmWrite(log, bp, 0, 0);
647 log->
page = (pn == log->
size - 1) ? 2 : pn + 1;
651 nextbp = lbmAllocate(log, log->
page);
693 jfs_info(
"lmGroup Commit: tblk = 0x%p, gcrtc = %d", tblk, log->
gcrtc);
758 static void lmGCwrite(
struct jfs_log * log,
int cant_write)
776 if (tblk->
pn != gcpn)
789 bp = (
struct lbuf *) tblk->
bp;
823 static void lmPostGC(
struct lbuf * bp)
859 jfs_info(
"lmPostGC: tblk = 0x%p, flag = 0x%x", tblk,
890 jfs_info(
"lmPostGC: calling lbmWrite");
904 if ((!list_empty(&log->
cqueue)) &&
905 ((log->
gcrtc > 0) || (tblk->
bp->l_wqnext !=
NULL) ||
921 spin_unlock_irqrestore(&log->
gclock, flags);
942 static int lmLogSync(
struct jfs_log * log,
int hard_sync)
990 lsn = lmWriteRecord(log,
NULL, &lrd,
NULL);
1002 free = logsize - written;
1004 more =
min(free / 2, delta);
1006 jfs_warn(
"\n ... Log Wrap ... Log Wrap ... Log Wrap ...\n");
1040 jfs_info(
"log barrier on: lsn=0x%x syncpt=0x%x", lsn,
1061 lmLogSync(log, hard_sync);
1086 return open_dummy_log(sb);
1089 return open_inline_log(sb);
1095 sizeof(log->
uuid))) {
1096 jfs_warn(
"wrong uuid on JFS journal\n");
1103 if ((rc = lmLogFileSystem(log, sbi, 1))) {
1115 INIT_LIST_HEAD(&log->
sb_list);
1145 if ((rc = lmLogFileSystem(log, sbi, 1)))
1162 lbmLogShutdown(log);
1171 jfs_warn(
"lmLogOpen: exit(%d)", rc);
1182 INIT_LIST_HEAD(&log->
sb_list);
1198 jfs_warn(
"lmLogOpen: exit(%d)", rc);
1202 list_add(&JFS_SBI(sb)->log_list, &log->
sb_list);
1203 JFS_SBI(sb)->log =
log;
1219 INIT_LIST_HEAD(&dummy_log->
sb_list);
1223 dummy_log->
base = 0;
1224 dummy_log->
size = 1024;
1235 list_add(&JFS_SBI(sb)->log_list, &dummy_log->
sb_list);
1236 JFS_SBI(sb)->log = dummy_log;
1266 struct lbuf *bpsuper;
1271 jfs_info(
"lmLogInit: log:0x%p", log);
1283 INIT_LIST_HEAD(&log->
cqueue);
1291 if ((rc = lbmLogInit(log)))
1304 bp = lbmAllocate(log , 0);
1311 if ((rc = lbmRead(log, 1, &bpsuper)))
1314 logsuper = (
struct logsuper *) bpsuper->
l_ldata;
1317 jfs_warn(
"*** Log Format Error ! ***");
1324 jfs_warn(
"*** Log Is Dirty ! ***");
1335 jfs_info(
"lmLogInit: inline log:0x%p base:0x%Lx "
1337 (
unsigned long long) log->
base, log->
size);
1340 jfs_warn(
"wrong uuid on JFS log device");
1345 jfs_info(
"lmLogInit: external log:0x%p base:0x%Lx "
1347 (
unsigned long long) log->
base, log->
size);
1357 if ((rc = lbmRead(log, log->
page, &bp)))
1362 jfs_info(
"lmLogInit: lsn:0x%x page:%d eor:%d:%d",
1389 lsn = lmWriteRecord(log,
NULL, &lrd,
NULL);
1395 if ((rc = lbmIOWait(bp, 0)))
1405 if ((rc = lbmIOWait(bpsuper,
lbmFREE)))
1416 jfs_info(
"lmLogInit: lsn:0x%x syncpt:0x%x sync:0x%x",
1438 lbmLogShutdown(log);
1440 jfs_warn(
"lmLogInit: exit(%d)", rc);
1464 jfs_info(
"lmLogClose: log:0x%p", log);
1488 lmLogFileSystem(log, sbi, 0);
1490 if (!list_empty(&log->
sb_list))
1516 jfs_info(
"lmLogClose: exit(%d)", rc);
1540 jfs_info(
"jfs_flush_journal: log:0x%p wait=%d", log, wait);
1544 if (!list_empty(&log->
cqueue)) {
1602 if ((!list_empty(&log->
cqueue)) || !list_empty(&log->
synclist)) {
1603 for (i = 0; i < 200; i++) {
1606 if (list_empty(&log->
cqueue) &&
1613 #ifdef CONFIG_JFS_DEBUG
1621 print_hex_dump(
KERN_ERR,
"metapage: ",
1626 sizeof(
long), mp->
page,
1627 sizeof(
struct page), 0);
1629 print_hex_dump(
KERN_ERR,
"tblock:",
1631 lp,
sizeof(
struct tblock), 0);
1660 struct lbuf *bpsuper;
1664 jfs_info(
"lmLogShutdown: log:0x%p", log);
1678 lsn = lmWriteRecord(log,
NULL, &lrd,
NULL);
1691 if ((rc = lbmRead(log, 1, &bpsuper)))
1694 logsuper = (
struct logsuper *) bpsuper->
l_ldata;
1698 rc = lbmIOWait(bpsuper,
lbmFREE);
1700 jfs_info(
"lmLogShutdown: lsn:0x%x page:%d eor:%d",
1707 lbmLogShutdown(log);
1710 jfs_warn(
"lmLogShutdown: exit(%d)", rc);
1736 struct lbuf *bpsuper;
1742 if ((rc = lbmRead(log, 1, &bpsuper)))
1745 logsuper = (
struct logsuper *) bpsuper->
l_ldata;
1753 if (i == MAX_ACTIVE) {
1754 jfs_warn(
"Too many file systems sharing journal!");
1764 if (i == MAX_ACTIVE) {
1765 jfs_warn(
"Somebody stomped on the journal!");
1784 rc = lbmIOWait(bpsuper,
lbmFREE);
1809 static int lbmLogInit(
struct jfs_log * log)
1814 jfs_info(
"lbmLogInit: log:0x%p", log);
1868 lbmLogShutdown(log);
1878 static void lbmLogShutdown(
struct jfs_log * log)
1882 jfs_info(
"lbmLogShutdown: log:0x%p", log);
1899 static struct lbuf *lbmAllocate(
struct jfs_log * log,
int pn)
1902 unsigned long flags;
1930 static void lbmFree(
struct lbuf * bp)
1932 unsigned long flags;
1941 static void lbmfree(
struct lbuf * bp)
1969 static inline void lbmRedrive(
struct lbuf *bp)
1971 unsigned long flags;
1974 bp->l_redrive_next = log_redrive_list;
1975 log_redrive_list =
bp;
1976 spin_unlock_irqrestore(&log_redrive_lock, flags);
1985 static int lbmRead(
struct jfs_log * log,
int pn,
struct lbuf **
bpp)
1993 *bpp = bp = lbmAllocate(log, pn);
1994 jfs_info(
"lbmRead: bp:0x%p pn:0x%x", bp, pn);
2001 bio->bi_bdev = log->
bdev;
2002 bio->bi_io_vec[0].bv_page = bp->
l_page;
2003 bio->bi_io_vec[0].bv_len =
LOGPSIZE;
2004 bio->bi_io_vec[0].bv_offset = bp->
l_offset;
2010 bio->bi_end_io = lbmIODone;
2011 bio->bi_private = bp;
2035 static void lbmWrite(
struct jfs_log * log,
struct lbuf * bp,
int flag,
2039 unsigned long flags;
2041 jfs_info(
"lbmWrite: bp:0x%p flag:0x%x pn:0x%x", bp, flag, bp->
l_pn);
2103 static void lbmDirectWrite(
struct jfs_log * log,
struct lbuf * bp,
int flag)
2105 jfs_info(
"lbmDirectWrite: bp:0x%p flag:0x%x pn:0x%x",
2106 bp, flag, bp->
l_pn);
2133 static void lbmStartIO(
struct lbuf * bp)
2142 bio->bi_bdev = log->
bdev;
2143 bio->bi_io_vec[0].bv_page = bp->
l_page;
2144 bio->bi_io_vec[0].bv_len =
LOGPSIZE;
2145 bio->bi_io_vec[0].bv_offset = bp->
l_offset;
2151 bio->bi_end_io = lbmIODone;
2152 bio->bi_private =
bp;
2168 static int lbmIOWait(
struct lbuf * bp,
int flag)
2170 unsigned long flags;
2173 jfs_info(
"lbmIOWait1: bp:0x%p flag:0x%x:0x%x", bp, bp->
l_flag, flag);
2186 jfs_info(
"lbmIOWait2: bp:0x%p flag:0x%x:0x%x", bp, bp->
l_flag, flag);
2195 static void lbmIODone(
struct bio *bio,
int error)
2197 struct lbuf *bp = bio->bi_private;
2198 struct lbuf *nextbp, *
tail;
2200 unsigned long flags;
2211 if (!
test_bit(BIO_UPTODATE, &bio->bi_flags)) {
2214 jfs_err(
"lbmIODone: I/O error in JFS log");
2289 if (nextbp->
l_flag & lbmWRITE) {
2341 spin_lock_irq(&log_redrive_lock);
2342 while ((bp = log_redrive_list)) {
2343 log_redrive_list = bp->l_redrive_next;
2344 bp->l_redrive_next =
NULL;
2345 spin_unlock_irq(&log_redrive_lock);
2347 spin_lock_irq(&log_redrive_lock);
2351 spin_unlock_irq(&log_redrive_lock);
2355 spin_unlock_irq(&log_redrive_lock);
2361 jfs_info(
"jfsIOWait being killed!");
2385 struct logsuper *logsuper;
2388 struct lrd *lrd_ptr;
2392 jfs_info(
"lmLogFormat: logAddress:%Ld logSize:%d",
2393 (
long long)logAddress, logSize);
2398 bp = lbmAllocate(log, 1);
2414 logsuper = (
struct logsuper *) bp->
l_ldata;
2428 if ((rc = lbmIOWait(bp, 0)))
2461 lrd_ptr = (
struct lrd *) &lp->
data;
2471 if ((rc = lbmIOWait(bp, 0)))
2477 for (lspn = 0; lspn < npages - 3; lspn++) {
2484 if ((rc = lbmIOWait(bp, 0)))
2499 #ifdef CONFIG_JFS_STATISTICS
2500 static int jfs_lmstats_proc_show(
struct seq_file *
m,
void *
v)
2503 "JFS Logmgr stats\n"
2504 "================\n"
2506 "writes submitted = %d\n"
2507 "writes completed = %d\n"
2508 "full pages submitted = %d\n"
2509 "partial pages submitted = %d\n",
2514 lmStat.partial_page);
2525 .open = jfs_lmstats_proc_open,