[PATCH] DVB: misc. updates to the dvb-core
[linux-2.6/history.git] / fs / jfs / jfs_txnmgr.c
blob12e9ccffb49bfe7d6fcb8f6bc47cff8facc9b0c0
1 /*
2 * Copyright (C) International Business Machines Corp., 2000-2004
3 * Portions Copyright (C) Christoph Hellwig, 2001-2002
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * jfs_txnmgr.c: transaction manager
23 * notes:
24 * transaction starts with txBegin() and ends with txCommit()
25 * or txAbort().
27 * tlock is acquired at the time of update;
28 * (obviate scan at commit time for xtree and dtree)
29 * tlock and mp points to each other;
30 * (no hashlist for mp -> tlock).
32 * special cases:
33 * tlock on in-memory inode:
34 * in-place tlock in the in-memory inode itself;
35 * converted to page lock by iWrite() at commit time.
37 * tlock during write()/mmap() under anonymous transaction (tid = 0):
38 * transferred (?) to transaction at commit time.
40 * use the page itself to update allocation maps
41 * (obviate intermediate replication of allocation/deallocation data)
42 * hold on to mp+lock thru update of maps
46 #include <linux/fs.h>
47 #include <linux/vmalloc.h>
48 #include <linux/smp_lock.h>
49 #include <linux/completion.h>
50 #include <linux/suspend.h>
51 #include <linux/module.h>
52 #include <linux/moduleparam.h>
53 #include "jfs_incore.h"
54 #include "jfs_filsys.h"
55 #include "jfs_metapage.h"
56 #include "jfs_dinode.h"
57 #include "jfs_imap.h"
58 #include "jfs_dmap.h"
59 #include "jfs_superblock.h"
60 #include "jfs_debug.h"
63 * transaction management structures
65 static struct {
66 int freetid; /* index of a free tid structure */
67 int freelock; /* index first free lock word */
68 wait_queue_head_t freewait; /* eventlist of free tblock */
69 wait_queue_head_t freelockwait; /* eventlist of free tlock */
70 wait_queue_head_t lowlockwait; /* eventlist of ample tlocks */
71 int tlocksInUse; /* Number of tlocks in use */
72 spinlock_t LazyLock; /* synchronize sync_queue & unlock_queue */
73 /* struct tblock *sync_queue; * Transactions waiting for data sync */
74 struct list_head unlock_queue; /* Txns waiting to be released */
75 struct list_head anon_list; /* inodes having anonymous txns */
76 struct list_head anon_list2; /* inodes having anonymous txns
77 that couldn't be sync'ed */
78 } TxAnchor;
80 int jfs_tlocks_low; /* Indicates low number of available tlocks */
82 #ifdef CONFIG_JFS_STATISTICS
83 struct {
84 uint txBegin;
85 uint txBegin_barrier;
86 uint txBegin_lockslow;
87 uint txBegin_freetid;
88 uint txBeginAnon;
89 uint txBeginAnon_barrier;
90 uint txBeginAnon_lockslow;
91 uint txLockAlloc;
92 uint txLockAlloc_freelock;
93 } TxStat;
94 #endif
96 static int nTxBlock = 512; /* number of transaction blocks */
97 module_param(nTxBlock, int, 0);
98 MODULE_PARM_DESC(nTxBlock,
99 "Number of transaction blocks (default:512, max:65536)");
101 static int nTxLock = 4096; /* number of transaction locks */
102 module_param(nTxLock, int, 0);
103 MODULE_PARM_DESC(nTxLock,
104 "Number of transaction locks (default:4096, max:65536)");
106 struct tblock *TxBlock; /* transaction block table */
107 static int TxLockLWM; /* Low water mark for number of txLocks used */
108 static int TxLockHWM; /* High water mark for number of txLocks used */
109 static int TxLockVHWM; /* Very High water mark */
110 struct tlock *TxLock; /* transaction lock table */
114 * transaction management lock
116 static spinlock_t jfsTxnLock = SPIN_LOCK_UNLOCKED;
118 #define TXN_LOCK() spin_lock(&jfsTxnLock)
119 #define TXN_UNLOCK() spin_unlock(&jfsTxnLock)
121 #define LAZY_LOCK_INIT() spin_lock_init(&TxAnchor.LazyLock);
122 #define LAZY_LOCK(flags) spin_lock_irqsave(&TxAnchor.LazyLock, flags)
123 #define LAZY_UNLOCK(flags) spin_unlock_irqrestore(&TxAnchor.LazyLock, flags)
125 DECLARE_WAIT_QUEUE_HEAD(jfs_sync_thread_wait);
126 DECLARE_WAIT_QUEUE_HEAD(jfs_commit_thread_wait);
129 * Retry logic exist outside these macros to protect from spurrious wakeups.
131 static inline void TXN_SLEEP_DROP_LOCK(wait_queue_head_t * event)
133 DECLARE_WAITQUEUE(wait, current);
135 add_wait_queue(event, &wait);
136 set_current_state(TASK_UNINTERRUPTIBLE);
137 TXN_UNLOCK();
138 schedule();
139 current->state = TASK_RUNNING;
140 remove_wait_queue(event, &wait);
143 #define TXN_SLEEP(event)\
145 TXN_SLEEP_DROP_LOCK(event);\
146 TXN_LOCK();\
149 #define TXN_WAKEUP(event) wake_up_all(event)
153 * statistics
155 struct {
156 tid_t maxtid; /* 4: biggest tid ever used */
157 lid_t maxlid; /* 4: biggest lid ever used */
158 int ntid; /* 4: # of transactions performed */
159 int nlid; /* 4: # of tlocks acquired */
160 int waitlock; /* 4: # of tlock wait */
161 } stattx;
165 * external references
167 extern int lmGroupCommit(struct jfs_log *, struct tblock *);
168 extern int jfs_commit_inode(struct inode *, int);
169 extern int jfs_stop_threads;
171 extern struct completion jfsIOwait;
174 * forward references
176 static int diLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
177 struct tlock * tlck, struct commit * cd);
178 static int dataLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
179 struct tlock * tlck);
180 static void dtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
181 struct tlock * tlck);
182 static void mapLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
183 struct tlock * tlck);
184 static void txAllocPMap(struct inode *ip, struct maplock * maplock,
185 struct tblock * tblk);
186 static void txForce(struct tblock * tblk);
187 static int txLog(struct jfs_log * log, struct tblock * tblk,
188 struct commit * cd);
189 static void txUpdateMap(struct tblock * tblk);
190 static void txRelease(struct tblock * tblk);
191 static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
192 struct tlock * tlck);
193 static void LogSyncRelease(struct metapage * mp);
196 * transaction block/lock management
197 * ---------------------------------
201 * Get a transaction lock from the free list. If the number in use is
202 * greater than the high water mark, wake up the sync daemon. This should
203 * free some anonymous transaction locks. (TXN_LOCK must be held.)
205 static lid_t txLockAlloc(void)
207 lid_t lid;
209 INCREMENT(TxStat.txLockAlloc);
210 if (!TxAnchor.freelock) {
211 INCREMENT(TxStat.txLockAlloc_freelock);
214 while (!(lid = TxAnchor.freelock))
215 TXN_SLEEP(&TxAnchor.freelockwait);
216 TxAnchor.freelock = TxLock[lid].next;
217 HIGHWATERMARK(stattx.maxlid, lid);
218 if ((++TxAnchor.tlocksInUse > TxLockHWM) && (jfs_tlocks_low == 0)) {
219 jfs_info("txLockAlloc tlocks low");
220 jfs_tlocks_low = 1;
221 wake_up(&jfs_sync_thread_wait);
224 return lid;
227 static void txLockFree(lid_t lid)
229 TxLock[lid].next = TxAnchor.freelock;
230 TxAnchor.freelock = lid;
231 TxAnchor.tlocksInUse--;
232 if (jfs_tlocks_low && (TxAnchor.tlocksInUse < TxLockLWM)) {
233 jfs_info("txLockFree jfs_tlocks_low no more");
234 jfs_tlocks_low = 0;
235 TXN_WAKEUP(&TxAnchor.lowlockwait);
237 TXN_WAKEUP(&TxAnchor.freelockwait);
241 * NAME: txInit()
243 * FUNCTION: initialize transaction management structures
245 * RETURN:
247 * serialization: single thread at jfs_init()
249 int txInit(void)
251 int k, size;
253 /* Verify tunable parameters */
254 if (nTxBlock < 16)
255 nTxBlock = 16; /* No one should set it this low */
256 if (nTxBlock > 65536)
257 nTxBlock = 65536;
258 if (nTxLock < 256)
259 nTxLock = 256; /* No one should set it this low */
260 if (nTxLock > 65536)
261 nTxLock = 65536;
263 * initialize transaction block (tblock) table
265 * transaction id (tid) = tblock index
266 * tid = 0 is reserved.
268 TxLockLWM = (nTxLock * 4) / 10;
269 TxLockHWM = (nTxLock * 8) / 10;
270 TxLockVHWM = (nTxLock * 9) / 10;
272 size = sizeof(struct tblock) * nTxBlock;
273 TxBlock = (struct tblock *) vmalloc(size);
274 if (TxBlock == NULL)
275 return -ENOMEM;
277 for (k = 1; k < nTxBlock - 1; k++) {
278 TxBlock[k].next = k + 1;
279 init_waitqueue_head(&TxBlock[k].gcwait);
280 init_waitqueue_head(&TxBlock[k].waitor);
282 TxBlock[k].next = 0;
283 init_waitqueue_head(&TxBlock[k].gcwait);
284 init_waitqueue_head(&TxBlock[k].waitor);
286 TxAnchor.freetid = 1;
287 init_waitqueue_head(&TxAnchor.freewait);
289 stattx.maxtid = 1; /* statistics */
292 * initialize transaction lock (tlock) table
294 * transaction lock id = tlock index
295 * tlock id = 0 is reserved.
297 size = sizeof(struct tlock) * nTxLock;
298 TxLock = (struct tlock *) vmalloc(size);
299 if (TxLock == NULL) {
300 vfree(TxBlock);
301 return -ENOMEM;
304 /* initialize tlock table */
305 for (k = 1; k < nTxLock - 1; k++)
306 TxLock[k].next = k + 1;
307 TxLock[k].next = 0;
308 init_waitqueue_head(&TxAnchor.freelockwait);
309 init_waitqueue_head(&TxAnchor.lowlockwait);
311 TxAnchor.freelock = 1;
312 TxAnchor.tlocksInUse = 0;
313 INIT_LIST_HEAD(&TxAnchor.anon_list);
314 INIT_LIST_HEAD(&TxAnchor.anon_list2);
316 LAZY_LOCK_INIT();
317 INIT_LIST_HEAD(&TxAnchor.unlock_queue);
319 stattx.maxlid = 1; /* statistics */
321 return 0;
325 * NAME: txExit()
327 * FUNCTION: clean up when module is unloaded
329 void txExit(void)
331 vfree(TxLock);
332 TxLock = NULL;
333 vfree(TxBlock);
334 TxBlock = NULL;
339 * NAME: txBegin()
341 * FUNCTION: start a transaction.
343 * PARAMETER: sb - superblock
344 * flag - force for nested tx;
346 * RETURN: tid - transaction id
348 * note: flag force allows to start tx for nested tx
349 * to prevent deadlock on logsync barrier;
351 tid_t txBegin(struct super_block *sb, int flag)
353 tid_t t;
354 struct tblock *tblk;
355 struct jfs_log *log;
357 jfs_info("txBegin: flag = 0x%x", flag);
358 log = JFS_SBI(sb)->log;
360 TXN_LOCK();
362 INCREMENT(TxStat.txBegin);
364 retry:
365 if (!(flag & COMMIT_FORCE)) {
367 * synchronize with logsync barrier
369 if (test_bit(log_SYNCBARRIER, &log->flag) ||
370 test_bit(log_QUIESCE, &log->flag)) {
371 INCREMENT(TxStat.txBegin_barrier);
372 TXN_SLEEP(&log->syncwait);
373 goto retry;
376 if (flag == 0) {
378 * Don't begin transaction if we're getting starved for tlocks
379 * unless COMMIT_FORCE or COMMIT_INODE (which may ultimately
380 * free tlocks)
382 if (TxAnchor.tlocksInUse > TxLockVHWM) {
383 INCREMENT(TxStat.txBegin_lockslow);
384 TXN_SLEEP(&TxAnchor.lowlockwait);
385 goto retry;
390 * allocate transaction id/block
392 if ((t = TxAnchor.freetid) == 0) {
393 jfs_info("txBegin: waiting for free tid");
394 INCREMENT(TxStat.txBegin_freetid);
395 TXN_SLEEP(&TxAnchor.freewait);
396 goto retry;
399 tblk = tid_to_tblock(t);
401 if ((tblk->next == 0) && !(flag & COMMIT_FORCE)) {
402 /* Don't let a non-forced transaction take the last tblk */
403 jfs_info("txBegin: waiting for free tid");
404 INCREMENT(TxStat.txBegin_freetid);
405 TXN_SLEEP(&TxAnchor.freewait);
406 goto retry;
409 TxAnchor.freetid = tblk->next;
412 * initialize transaction
416 * We can't zero the whole thing or we screw up another thread being
417 * awakened after sleeping on tblk->waitor
419 * memset(tblk, 0, sizeof(struct tblock));
421 tblk->next = tblk->last = tblk->xflag = tblk->flag = tblk->lsn = 0;
423 tblk->sb = sb;
424 ++log->logtid;
425 tblk->logtid = log->logtid;
427 ++log->active;
429 HIGHWATERMARK(stattx.maxtid, t); /* statistics */
430 INCREMENT(stattx.ntid); /* statistics */
432 TXN_UNLOCK();
434 jfs_info("txBegin: returning tid = %d", t);
436 return t;
441 * NAME: txBeginAnon()
443 * FUNCTION: start an anonymous transaction.
444 * Blocks if logsync or available tlocks are low to prevent
445 * anonymous tlocks from depleting supply.
447 * PARAMETER: sb - superblock
449 * RETURN: none
451 void txBeginAnon(struct super_block *sb)
453 struct jfs_log *log;
455 log = JFS_SBI(sb)->log;
457 TXN_LOCK();
458 INCREMENT(TxStat.txBeginAnon);
460 retry:
462 * synchronize with logsync barrier
464 if (test_bit(log_SYNCBARRIER, &log->flag) ||
465 test_bit(log_QUIESCE, &log->flag)) {
466 INCREMENT(TxStat.txBeginAnon_barrier);
467 TXN_SLEEP(&log->syncwait);
468 goto retry;
472 * Don't begin transaction if we're getting starved for tlocks
474 if (TxAnchor.tlocksInUse > TxLockVHWM) {
475 INCREMENT(TxStat.txBeginAnon_lockslow);
476 TXN_SLEEP(&TxAnchor.lowlockwait);
477 goto retry;
479 TXN_UNLOCK();
484 * txEnd()
486 * function: free specified transaction block.
488 * logsync barrier processing:
490 * serialization:
492 void txEnd(tid_t tid)
494 struct tblock *tblk = tid_to_tblock(tid);
495 struct jfs_log *log;
497 jfs_info("txEnd: tid = %d", tid);
498 TXN_LOCK();
501 * wakeup transactions waiting on the page locked
502 * by the current transaction
504 TXN_WAKEUP(&tblk->waitor);
506 log = JFS_SBI(tblk->sb)->log;
509 * Lazy commit thread can't free this guy until we mark it UNLOCKED,
510 * otherwise, we would be left with a transaction that may have been
511 * reused.
513 * Lazy commit thread will turn off tblkGC_LAZY before calling this
514 * routine.
516 if (tblk->flag & tblkGC_LAZY) {
517 jfs_info("txEnd called w/lazy tid: %d, tblk = 0x%p", tid, tblk);
518 TXN_UNLOCK();
520 spin_lock_irq(&log->gclock); // LOGGC_LOCK
521 tblk->flag |= tblkGC_UNLOCKED;
522 spin_unlock_irq(&log->gclock); // LOGGC_UNLOCK
523 return;
526 jfs_info("txEnd: tid: %d, tblk = 0x%p", tid, tblk);
528 assert(tblk->next == 0);
531 * insert tblock back on freelist
533 tblk->next = TxAnchor.freetid;
534 TxAnchor.freetid = tid;
537 * mark the tblock not active
539 if (--log->active == 0) {
540 clear_bit(log_FLUSH, &log->flag);
543 * synchronize with logsync barrier
545 if (test_bit(log_SYNCBARRIER, &log->flag)) {
546 /* forward log syncpt */
547 /* lmSync(log); */
549 jfs_info("log barrier off: 0x%x", log->lsn);
551 /* enable new transactions start */
552 clear_bit(log_SYNCBARRIER, &log->flag);
554 /* wakeup all waitors for logsync barrier */
555 TXN_WAKEUP(&log->syncwait);
560 * wakeup all waitors for a free tblock
562 TXN_WAKEUP(&TxAnchor.freewait);
564 TXN_UNLOCK();
569 * txLock()
571 * function: acquire a transaction lock on the specified <mp>
573 * parameter:
575 * return: transaction lock id
577 * serialization:
579 struct tlock *txLock(tid_t tid, struct inode *ip, struct metapage * mp,
580 int type)
582 struct jfs_inode_info *jfs_ip = JFS_IP(ip);
583 int dir_xtree = 0;
584 lid_t lid;
585 tid_t xtid;
586 struct tlock *tlck;
587 struct xtlock *xtlck;
588 struct linelock *linelock;
589 xtpage_t *p;
590 struct tblock *tblk;
592 TXN_LOCK();
594 if (S_ISDIR(ip->i_mode) && (type & tlckXTREE) &&
595 !(mp->xflag & COMMIT_PAGE)) {
597 * Directory inode is special. It can have both an xtree tlock
598 * and a dtree tlock associated with it.
600 dir_xtree = 1;
601 lid = jfs_ip->xtlid;
602 } else
603 lid = mp->lid;
605 /* is page not locked by a transaction ? */
606 if (lid == 0)
607 goto allocateLock;
609 jfs_info("txLock: tid:%d ip:0x%p mp:0x%p lid:%d", tid, ip, mp, lid);
611 /* is page locked by the requester transaction ? */
612 tlck = lid_to_tlock(lid);
613 if ((xtid = tlck->tid) == tid)
614 goto grantLock;
617 * is page locked by anonymous transaction/lock ?
619 * (page update without transaction (i.e., file write) is
620 * locked under anonymous transaction tid = 0:
621 * anonymous tlocks maintained on anonymous tlock list of
622 * the inode of the page and available to all anonymous
623 * transactions until txCommit() time at which point
624 * they are transferred to the transaction tlock list of
625 * the commiting transaction of the inode)
627 if (xtid == 0) {
628 tlck->tid = tid;
629 tblk = tid_to_tblock(tid);
631 * The order of the tlocks in the transaction is important
632 * (during truncate, child xtree pages must be freed before
633 * parent's tlocks change the working map).
634 * Take tlock off anonymous list and add to tail of
635 * transaction list
637 * Note: We really need to get rid of the tid & lid and
638 * use list_head's. This code is getting UGLY!
640 if (jfs_ip->atlhead == lid) {
641 if (jfs_ip->atltail == lid) {
642 /* only anonymous txn.
643 * Remove from anon_list
645 list_del_init(&jfs_ip->anon_inode_list);
647 jfs_ip->atlhead = tlck->next;
648 } else {
649 lid_t last;
650 for (last = jfs_ip->atlhead;
651 lid_to_tlock(last)->next != lid;
652 last = lid_to_tlock(last)->next) {
653 assert(last);
655 lid_to_tlock(last)->next = tlck->next;
656 if (jfs_ip->atltail == lid)
657 jfs_ip->atltail = last;
660 /* insert the tlock at tail of transaction tlock list */
662 if (tblk->next)
663 lid_to_tlock(tblk->last)->next = lid;
664 else
665 tblk->next = lid;
666 tlck->next = 0;
667 tblk->last = lid;
669 goto grantLock;
672 goto waitLock;
675 * allocate a tlock
677 allocateLock:
678 lid = txLockAlloc();
679 tlck = lid_to_tlock(lid);
682 * initialize tlock
684 tlck->tid = tid;
686 /* mark tlock for meta-data page */
687 if (mp->xflag & COMMIT_PAGE) {
689 tlck->flag = tlckPAGELOCK;
691 /* mark the page dirty and nohomeok */
692 mark_metapage_dirty(mp);
693 atomic_inc(&mp->nohomeok);
695 jfs_info("locking mp = 0x%p, nohomeok = %d tid = %d tlck = 0x%p",
696 mp, atomic_read(&mp->nohomeok), tid, tlck);
698 /* if anonymous transaction, and buffer is on the group
699 * commit synclist, mark inode to show this. This will
700 * prevent the buffer from being marked nohomeok for too
701 * long a time.
703 if ((tid == 0) && mp->lsn)
704 set_cflag(COMMIT_Synclist, ip);
706 /* mark tlock for in-memory inode */
707 else
708 tlck->flag = tlckINODELOCK;
710 tlck->type = 0;
712 /* bind the tlock and the page */
713 tlck->ip = ip;
714 tlck->mp = mp;
715 if (dir_xtree)
716 jfs_ip->xtlid = lid;
717 else
718 mp->lid = lid;
721 * enqueue transaction lock to transaction/inode
723 /* insert the tlock at tail of transaction tlock list */
724 if (tid) {
725 tblk = tid_to_tblock(tid);
726 if (tblk->next)
727 lid_to_tlock(tblk->last)->next = lid;
728 else
729 tblk->next = lid;
730 tlck->next = 0;
731 tblk->last = lid;
733 /* anonymous transaction:
734 * insert the tlock at head of inode anonymous tlock list
736 else {
737 tlck->next = jfs_ip->atlhead;
738 jfs_ip->atlhead = lid;
739 if (tlck->next == 0) {
740 /* This inode's first anonymous transaction */
741 jfs_ip->atltail = lid;
742 list_add_tail(&jfs_ip->anon_inode_list,
743 &TxAnchor.anon_list);
747 /* initialize type dependent area for linelock */
748 linelock = (struct linelock *) & tlck->lock;
749 linelock->next = 0;
750 linelock->flag = tlckLINELOCK;
751 linelock->maxcnt = TLOCKSHORT;
752 linelock->index = 0;
754 switch (type & tlckTYPE) {
755 case tlckDTREE:
756 linelock->l2linesize = L2DTSLOTSIZE;
757 break;
759 case tlckXTREE:
760 linelock->l2linesize = L2XTSLOTSIZE;
762 xtlck = (struct xtlock *) linelock;
763 xtlck->header.offset = 0;
764 xtlck->header.length = 2;
766 if (type & tlckNEW) {
767 xtlck->lwm.offset = XTENTRYSTART;
768 } else {
769 if (mp->xflag & COMMIT_PAGE)
770 p = (xtpage_t *) mp->data;
771 else
772 p = &jfs_ip->i_xtroot;
773 xtlck->lwm.offset =
774 le16_to_cpu(p->header.nextindex);
776 xtlck->lwm.length = 0; /* ! */
777 xtlck->twm.offset = 0;
778 xtlck->hwm.offset = 0;
780 xtlck->index = 2;
781 break;
783 case tlckINODE:
784 linelock->l2linesize = L2INODESLOTSIZE;
785 break;
787 case tlckDATA:
788 linelock->l2linesize = L2DATASLOTSIZE;
789 break;
791 default:
792 jfs_err("UFO tlock:0x%p", tlck);
796 * update tlock vector
798 grantLock:
799 tlck->type |= type;
801 TXN_UNLOCK();
803 return tlck;
806 * page is being locked by another transaction:
808 waitLock:
809 /* Only locks on ipimap or ipaimap should reach here */
810 /* assert(jfs_ip->fileset == AGGREGATE_I); */
811 if (jfs_ip->fileset != AGGREGATE_I) {
812 jfs_err("txLock: trying to lock locked page!");
813 dump_mem("ip", ip, sizeof(struct inode));
814 dump_mem("mp", mp, sizeof(struct metapage));
815 dump_mem("Locker's tblk", tid_to_tblock(tid),
816 sizeof(struct tblock));
817 dump_mem("Tlock", tlck, sizeof(struct tlock));
818 BUG();
820 INCREMENT(stattx.waitlock); /* statistics */
821 release_metapage(mp);
823 jfs_info("txLock: in waitLock, tid = %d, xtid = %d, lid = %d",
824 tid, xtid, lid);
825 TXN_SLEEP_DROP_LOCK(&tid_to_tblock(xtid)->waitor);
826 jfs_info("txLock: awakened tid = %d, lid = %d", tid, lid);
828 return NULL;
833 * NAME: txRelease()
835 * FUNCTION: Release buffers associated with transaction locks, but don't
836 * mark homeok yet. The allows other transactions to modify
837 * buffers, but won't let them go to disk until commit record
838 * actually gets written.
840 * PARAMETER:
841 * tblk -
843 * RETURN: Errors from subroutines.
845 static void txRelease(struct tblock * tblk)
847 struct metapage *mp;
848 lid_t lid;
849 struct tlock *tlck;
851 TXN_LOCK();
853 for (lid = tblk->next; lid; lid = tlck->next) {
854 tlck = lid_to_tlock(lid);
855 if ((mp = tlck->mp) != NULL &&
856 (tlck->type & tlckBTROOT) == 0) {
857 assert(mp->xflag & COMMIT_PAGE);
858 mp->lid = 0;
863 * wakeup transactions waiting on a page locked
864 * by the current transaction
866 TXN_WAKEUP(&tblk->waitor);
868 TXN_UNLOCK();
873 * NAME: txUnlock()
875 * FUNCTION: Initiates pageout of pages modified by tid in journalled
876 * objects and frees their lockwords.
878 static void txUnlock(struct tblock * tblk)
880 struct tlock *tlck;
881 struct linelock *linelock;
882 lid_t lid, next, llid, k;
883 struct metapage *mp;
884 struct jfs_log *log;
885 int difft, diffp;
887 jfs_info("txUnlock: tblk = 0x%p", tblk);
888 log = JFS_SBI(tblk->sb)->log;
891 * mark page under tlock homeok (its log has been written):
893 for (lid = tblk->next; lid; lid = next) {
894 tlck = lid_to_tlock(lid);
895 next = tlck->next;
897 jfs_info("unlocking lid = %d, tlck = 0x%p", lid, tlck);
899 /* unbind page from tlock */
900 if ((mp = tlck->mp) != NULL &&
901 (tlck->type & tlckBTROOT) == 0) {
902 assert(mp->xflag & COMMIT_PAGE);
904 /* hold buffer
906 * It's possible that someone else has the metapage.
907 * The only things were changing are nohomeok, which
908 * is handled atomically, and clsn which is protected
909 * by the LOGSYNC_LOCK.
911 hold_metapage(mp, 1);
913 assert(atomic_read(&mp->nohomeok) > 0);
914 atomic_dec(&mp->nohomeok);
916 /* inherit younger/larger clsn */
917 LOGSYNC_LOCK(log);
918 if (mp->clsn) {
919 logdiff(difft, tblk->clsn, log);
920 logdiff(diffp, mp->clsn, log);
921 if (difft > diffp)
922 mp->clsn = tblk->clsn;
923 } else
924 mp->clsn = tblk->clsn;
925 LOGSYNC_UNLOCK(log);
927 assert(!(tlck->flag & tlckFREEPAGE));
929 if (tlck->flag & tlckWRITEPAGE) {
930 write_metapage(mp);
931 } else {
932 /* release page which has been forced */
933 release_metapage(mp);
937 /* insert tlock, and linelock(s) of the tlock if any,
938 * at head of freelist
940 TXN_LOCK();
942 llid = ((struct linelock *) & tlck->lock)->next;
943 while (llid) {
944 linelock = (struct linelock *) lid_to_tlock(llid);
945 k = linelock->next;
946 txLockFree(llid);
947 llid = k;
949 txLockFree(lid);
951 TXN_UNLOCK();
953 tblk->next = tblk->last = 0;
956 * remove tblock from logsynclist
957 * (allocation map pages inherited lsn of tblk and
958 * has been inserted in logsync list at txUpdateMap())
960 if (tblk->lsn) {
961 LOGSYNC_LOCK(log);
962 log->count--;
963 list_del(&tblk->synclist);
964 LOGSYNC_UNLOCK(log);
970 * txMaplock()
972 * function: allocate a transaction lock for freed page/entry;
973 * for freed page, maplock is used as xtlock/dtlock type;
975 struct tlock *txMaplock(tid_t tid, struct inode *ip, int type)
977 struct jfs_inode_info *jfs_ip = JFS_IP(ip);
978 lid_t lid;
979 struct tblock *tblk;
980 struct tlock *tlck;
981 struct maplock *maplock;
983 TXN_LOCK();
986 * allocate a tlock
988 lid = txLockAlloc();
989 tlck = lid_to_tlock(lid);
992 * initialize tlock
994 tlck->tid = tid;
996 /* bind the tlock and the object */
997 tlck->flag = tlckINODELOCK;
998 tlck->ip = ip;
999 tlck->mp = NULL;
1001 tlck->type = type;
1004 * enqueue transaction lock to transaction/inode
1006 /* insert the tlock at tail of transaction tlock list */
1007 if (tid) {
1008 tblk = tid_to_tblock(tid);
1009 if (tblk->next)
1010 lid_to_tlock(tblk->last)->next = lid;
1011 else
1012 tblk->next = lid;
1013 tlck->next = 0;
1014 tblk->last = lid;
1016 /* anonymous transaction:
1017 * insert the tlock at head of inode anonymous tlock list
1019 else {
1020 tlck->next = jfs_ip->atlhead;
1021 jfs_ip->atlhead = lid;
1022 if (tlck->next == 0) {
1023 /* This inode's first anonymous transaction */
1024 jfs_ip->atltail = lid;
1025 list_add_tail(&jfs_ip->anon_inode_list,
1026 &TxAnchor.anon_list);
1030 TXN_UNLOCK();
1032 /* initialize type dependent area for maplock */
1033 maplock = (struct maplock *) & tlck->lock;
1034 maplock->next = 0;
1035 maplock->maxcnt = 0;
1036 maplock->index = 0;
1038 return tlck;
1043 * txLinelock()
1045 * function: allocate a transaction lock for log vector list
1047 struct linelock *txLinelock(struct linelock * tlock)
1049 lid_t lid;
1050 struct tlock *tlck;
1051 struct linelock *linelock;
1053 TXN_LOCK();
1055 /* allocate a TxLock structure */
1056 lid = txLockAlloc();
1057 tlck = lid_to_tlock(lid);
1059 TXN_UNLOCK();
1061 /* initialize linelock */
1062 linelock = (struct linelock *) tlck;
1063 linelock->next = 0;
1064 linelock->flag = tlckLINELOCK;
1065 linelock->maxcnt = TLOCKLONG;
1066 linelock->index = 0;
1068 /* append linelock after tlock */
1069 linelock->next = tlock->next;
1070 tlock->next = lid;
1072 return linelock;
1078 * transaction commit management
1079 * -----------------------------
1083 * NAME: txCommit()
1085 * FUNCTION: commit the changes to the objects specified in
1086 * clist. For journalled segments only the
1087 * changes of the caller are committed, ie by tid.
1088 * for non-journalled segments the data are flushed to
1089 * disk and then the change to the disk inode and indirect
1090 * blocks committed (so blocks newly allocated to the
1091 * segment will be made a part of the segment atomically).
1093 * all of the segments specified in clist must be in
1094 * one file system. no more than 6 segments are needed
1095 * to handle all unix svcs.
1097 * if the i_nlink field (i.e. disk inode link count)
1098 * is zero, and the type of inode is a regular file or
1099 * directory, or symbolic link , the inode is truncated
1100 * to zero length. the truncation is committed but the
1101 * VM resources are unaffected until it is closed (see
1102 * iput and iclose).
1104 * PARAMETER:
1106 * RETURN:
1108 * serialization:
1109 * on entry the inode lock on each segment is assumed
1110 * to be held.
1112 * i/o error:
1114 int txCommit(tid_t tid, /* transaction identifier */
1115 int nip, /* number of inodes to commit */
1116 struct inode **iplist, /* list of inode to commit */
1117 int flag)
1119 int rc = 0;
1120 struct commit cd;
1121 struct jfs_log *log;
1122 struct tblock *tblk;
1123 struct lrd *lrd;
1124 int lsn;
1125 struct inode *ip;
1126 struct jfs_inode_info *jfs_ip;
1127 int k, n;
1128 ino_t top;
1129 struct super_block *sb;
1131 jfs_info("txCommit, tid = %d, flag = %d", tid, flag);
1132 /* is read-only file system ? */
1133 if (isReadOnly(iplist[0])) {
1134 rc = -EROFS;
1135 goto TheEnd;
1138 sb = cd.sb = iplist[0]->i_sb;
1139 cd.tid = tid;
1141 if (tid == 0)
1142 tid = txBegin(sb, 0);
1143 tblk = tid_to_tblock(tid);
1146 * initialize commit structure
1148 log = JFS_SBI(sb)->log;
1149 cd.log = log;
1151 /* initialize log record descriptor in commit */
1152 lrd = &cd.lrd;
1153 lrd->logtid = cpu_to_le32(tblk->logtid);
1154 lrd->backchain = 0;
1156 tblk->xflag |= flag;
1158 if ((flag & (COMMIT_FORCE | COMMIT_SYNC)) == 0)
1159 tblk->xflag |= COMMIT_LAZY;
1161 * prepare non-journaled objects for commit
1163 * flush data pages of non-journaled file
1164 * to prevent the file getting non-initialized disk blocks
1165 * in case of crash.
1166 * (new blocks - )
1168 cd.iplist = iplist;
1169 cd.nip = nip;
1172 * acquire transaction lock on (on-disk) inodes
1174 * update on-disk inode from in-memory inode
1175 * acquiring transaction locks for AFTER records
1176 * on the on-disk inode of file object
1178 * sort the inodes array by inode number in descending order
1179 * to prevent deadlock when acquiring transaction lock
1180 * of on-disk inodes on multiple on-disk inode pages by
1181 * multiple concurrent transactions
1183 for (k = 0; k < cd.nip; k++) {
1184 top = (cd.iplist[k])->i_ino;
1185 for (n = k + 1; n < cd.nip; n++) {
1186 ip = cd.iplist[n];
1187 if (ip->i_ino > top) {
1188 top = ip->i_ino;
1189 cd.iplist[n] = cd.iplist[k];
1190 cd.iplist[k] = ip;
1194 ip = cd.iplist[k];
1195 jfs_ip = JFS_IP(ip);
1198 * BUGBUG - This code has temporarily been removed. The
1199 * intent is to ensure that any file data is written before
1200 * the metadata is committed to the journal. This prevents
1201 * uninitialized data from appearing in a file after the
1202 * journal has been replayed. (The uninitialized data
1203 * could be sensitive data removed by another user.)
1205 * The problem now is that we are holding the IWRITELOCK
1206 * on the inode, and calling filemap_fdatawrite on an
1207 * unmapped page will cause a deadlock in jfs_get_block.
1209 * The long term solution is to pare down the use of
1210 * IWRITELOCK. We are currently holding it too long.
1211 * We could also be smarter about which data pages need
1212 * to be written before the transaction is committed and
1213 * when we don't need to worry about it at all.
1215 * if ((!S_ISDIR(ip->i_mode))
1216 * && (tblk->flag & COMMIT_DELETE) == 0) {
1217 * filemap_fdatawrite(ip->i_mapping);
1218 * filemap_fdatawait(ip->i_mapping);
1223 * Mark inode as not dirty. It will still be on the dirty
1224 * inode list, but we'll know not to commit it again unless
1225 * it gets marked dirty again
1227 clear_cflag(COMMIT_Dirty, ip);
1229 /* inherit anonymous tlock(s) of inode */
1230 if (jfs_ip->atlhead) {
1231 lid_to_tlock(jfs_ip->atltail)->next = tblk->next;
1232 tblk->next = jfs_ip->atlhead;
1233 if (!tblk->last)
1234 tblk->last = jfs_ip->atltail;
1235 jfs_ip->atlhead = jfs_ip->atltail = 0;
1236 TXN_LOCK();
1237 list_del_init(&jfs_ip->anon_inode_list);
1238 TXN_UNLOCK();
1242 * acquire transaction lock on on-disk inode page
1243 * (become first tlock of the tblk's tlock list)
1245 if (((rc = diWrite(tid, ip))))
1246 goto out;
1250 * write log records from transaction locks
1252 * txUpdateMap() resets XAD_NEW in XAD.
1254 if ((rc = txLog(log, tblk, &cd)))
1255 goto TheEnd;
1258 * Ensure that inode isn't reused before
1259 * lazy commit thread finishes processing
1261 if (tblk->xflag & COMMIT_DELETE) {
1262 atomic_inc(&tblk->u.ip->i_count);
1264 * Avoid a rare deadlock
1266 * If the inode is locked, we may be blocked in
1267 * jfs_commit_inode. If so, we don't want the
1268 * lazy_commit thread doing the last iput() on the inode
1269 * since that may block on the locked inode. Instead,
1270 * commit the transaction synchronously, so the last iput
1271 * will be done by the calling thread (or later)
1273 if (tblk->u.ip->i_state & I_LOCK)
1274 tblk->xflag &= ~COMMIT_LAZY;
1277 ASSERT((!(tblk->xflag & COMMIT_DELETE)) ||
1278 ((tblk->u.ip->i_nlink == 0) &&
1279 !test_cflag(COMMIT_Nolink, tblk->u.ip)));
1282 * write COMMIT log record
1284 lrd->type = cpu_to_le16(LOG_COMMIT);
1285 lrd->length = 0;
1286 lsn = lmLog(log, tblk, lrd, NULL);
1288 lmGroupCommit(log, tblk);
1291 * - transaction is now committed -
1295 * force pages in careful update
1296 * (imap addressing structure update)
1298 if (flag & COMMIT_FORCE)
1299 txForce(tblk);
1302 * update allocation map.
1304 * update inode allocation map and inode:
1305 * free pager lock on memory object of inode if any.
1306 * update block allocation map.
1308 * txUpdateMap() resets XAD_NEW in XAD.
1310 if (tblk->xflag & COMMIT_FORCE)
1311 txUpdateMap(tblk);
1314 * free transaction locks and pageout/free pages
1316 txRelease(tblk);
1318 if ((tblk->flag & tblkGC_LAZY) == 0)
1319 txUnlock(tblk);
1323 * reset in-memory object state
1325 for (k = 0; k < cd.nip; k++) {
1326 ip = cd.iplist[k];
1327 jfs_ip = JFS_IP(ip);
1330 * reset in-memory inode state
1332 jfs_ip->bxflag = 0;
1333 jfs_ip->blid = 0;
1336 out:
1337 if (rc != 0)
1338 txAbort(tid, 1);
1340 TheEnd:
1341 jfs_info("txCommit: tid = %d, returning %d", tid, rc);
1342 return rc;
1347 * NAME: txLog()
1349 * FUNCTION: Writes AFTER log records for all lines modified
1350 * by tid for segments specified by inodes in comdata.
1351 * Code assumes only WRITELOCKS are recorded in lockwords.
1353 * PARAMETERS:
1355 * RETURN :
1357 static int txLog(struct jfs_log * log, struct tblock * tblk, struct commit * cd)
1359 int rc = 0;
1360 struct inode *ip;
1361 lid_t lid;
1362 struct tlock *tlck;
1363 struct lrd *lrd = &cd->lrd;
1366 * write log record(s) for each tlock of transaction,
1368 for (lid = tblk->next; lid; lid = tlck->next) {
1369 tlck = lid_to_tlock(lid);
1371 tlck->flag |= tlckLOG;
1373 /* initialize lrd common */
1374 ip = tlck->ip;
1375 lrd->aggregate = cpu_to_le32(JFS_SBI(ip->i_sb)->aggregate);
1376 lrd->log.redopage.fileset = cpu_to_le32(JFS_IP(ip)->fileset);
1377 lrd->log.redopage.inode = cpu_to_le32(ip->i_ino);
1379 /* write log record of page from the tlock */
1380 switch (tlck->type & tlckTYPE) {
1381 case tlckXTREE:
1382 xtLog(log, tblk, lrd, tlck);
1383 break;
1385 case tlckDTREE:
1386 dtLog(log, tblk, lrd, tlck);
1387 break;
1389 case tlckINODE:
1390 diLog(log, tblk, lrd, tlck, cd);
1391 break;
1393 case tlckMAP:
1394 mapLog(log, tblk, lrd, tlck);
1395 break;
1397 case tlckDATA:
1398 dataLog(log, tblk, lrd, tlck);
1399 break;
1401 default:
1402 jfs_err("UFO tlock:0x%p", tlck);
1406 return rc;
1411 * diLog()
1413 * function: log inode tlock and format maplock to update bmap;
1415 static int diLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
1416 struct tlock * tlck, struct commit * cd)
1418 int rc = 0;
1419 struct metapage *mp;
1420 pxd_t *pxd;
1421 struct pxd_lock *pxdlock;
1423 mp = tlck->mp;
1425 /* initialize as REDOPAGE record format */
1426 lrd->log.redopage.type = cpu_to_le16(LOG_INODE);
1427 lrd->log.redopage.l2linesize = cpu_to_le16(L2INODESLOTSIZE);
1429 pxd = &lrd->log.redopage.pxd;
1432 * inode after image
1434 if (tlck->type & tlckENTRY) {
1435 /* log after-image for logredo(): */
1436 lrd->type = cpu_to_le16(LOG_REDOPAGE);
1437 // *pxd = mp->cm_pxd;
1438 PXDaddress(pxd, mp->index);
1439 PXDlength(pxd,
1440 mp->logical_size >> tblk->sb->s_blocksize_bits);
1441 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1443 /* mark page as homeward bound */
1444 tlck->flag |= tlckWRITEPAGE;
1445 } else if (tlck->type & tlckFREE) {
1447 * free inode extent
1449 * (pages of the freed inode extent have been invalidated and
1450 * a maplock for free of the extent has been formatted at
1451 * txLock() time);
1453 * the tlock had been acquired on the inode allocation map page
1454 * (iag) that specifies the freed extent, even though the map
1455 * page is not itself logged, to prevent pageout of the map
1456 * page before the log;
1459 /* log LOG_NOREDOINOEXT of the freed inode extent for
1460 * logredo() to start NoRedoPage filters, and to update
1461 * imap and bmap for free of the extent;
1463 lrd->type = cpu_to_le16(LOG_NOREDOINOEXT);
1465 * For the LOG_NOREDOINOEXT record, we need
1466 * to pass the IAG number and inode extent
1467 * index (within that IAG) from which the
1468 * the extent being released. These have been
1469 * passed to us in the iplist[1] and iplist[2].
1471 lrd->log.noredoinoext.iagnum =
1472 cpu_to_le32((u32) (size_t) cd->iplist[1]);
1473 lrd->log.noredoinoext.inoext_idx =
1474 cpu_to_le32((u32) (size_t) cd->iplist[2]);
1476 pxdlock = (struct pxd_lock *) & tlck->lock;
1477 *pxd = pxdlock->pxd;
1478 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
1480 /* update bmap */
1481 tlck->flag |= tlckUPDATEMAP;
1483 /* mark page as homeward bound */
1484 tlck->flag |= tlckWRITEPAGE;
1485 } else
1486 jfs_err("diLog: UFO type tlck:0x%p", tlck);
1487 #ifdef _JFS_WIP
1489 * alloc/free external EA extent
1491 * a maplock for txUpdateMap() to update bPWMAP for alloc/free
1492 * of the extent has been formatted at txLock() time;
1494 else {
1495 assert(tlck->type & tlckEA);
1497 /* log LOG_UPDATEMAP for logredo() to update bmap for
1498 * alloc of new (and free of old) external EA extent;
1500 lrd->type = cpu_to_le16(LOG_UPDATEMAP);
1501 pxdlock = (struct pxd_lock *) & tlck->lock;
1502 nlock = pxdlock->index;
1503 for (i = 0; i < nlock; i++, pxdlock++) {
1504 if (pxdlock->flag & mlckALLOCPXD)
1505 lrd->log.updatemap.type =
1506 cpu_to_le16(LOG_ALLOCPXD);
1507 else
1508 lrd->log.updatemap.type =
1509 cpu_to_le16(LOG_FREEPXD);
1510 lrd->log.updatemap.nxd = cpu_to_le16(1);
1511 lrd->log.updatemap.pxd = pxdlock->pxd;
1512 lrd->backchain =
1513 cpu_to_le32(lmLog(log, tblk, lrd, NULL));
1516 /* update bmap */
1517 tlck->flag |= tlckUPDATEMAP;
1519 #endif /* _JFS_WIP */
1521 return rc;
1526 * dataLog()
1528 * function: log data tlock
1530 static int dataLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
1531 struct tlock * tlck)
1533 struct metapage *mp;
1534 pxd_t *pxd;
1536 mp = tlck->mp;
1538 /* initialize as REDOPAGE record format */
1539 lrd->log.redopage.type = cpu_to_le16(LOG_DATA);
1540 lrd->log.redopage.l2linesize = cpu_to_le16(L2DATASLOTSIZE);
1542 pxd = &lrd->log.redopage.pxd;
1544 /* log after-image for logredo(): */
1545 lrd->type = cpu_to_le16(LOG_REDOPAGE);
1547 if (JFS_IP(tlck->ip)->next_index < MAX_INLINE_DIRTABLE_ENTRY) {
1549 * The table has been truncated, we've must have deleted
1550 * the last entry, so don't bother logging this
1552 mp->lid = 0;
1553 hold_metapage(mp, 0);
1554 atomic_dec(&mp->nohomeok);
1555 discard_metapage(mp);
1556 tlck->mp = NULL;
1557 return 0;
1560 PXDaddress(pxd, mp->index);
1561 PXDlength(pxd, mp->logical_size >> tblk->sb->s_blocksize_bits);
1563 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1565 /* mark page as homeward bound */
1566 tlck->flag |= tlckWRITEPAGE;
1568 return 0;
1573 * dtLog()
1575 * function: log dtree tlock and format maplock to update bmap;
1577 static void dtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
1578 struct tlock * tlck)
1580 struct metapage *mp;
1581 struct pxd_lock *pxdlock;
1582 pxd_t *pxd;
1584 mp = tlck->mp;
1586 /* initialize as REDOPAGE/NOREDOPAGE record format */
1587 lrd->log.redopage.type = cpu_to_le16(LOG_DTREE);
1588 lrd->log.redopage.l2linesize = cpu_to_le16(L2DTSLOTSIZE);
1590 pxd = &lrd->log.redopage.pxd;
1592 if (tlck->type & tlckBTROOT)
1593 lrd->log.redopage.type |= cpu_to_le16(LOG_BTROOT);
1596 * page extension via relocation: entry insertion;
1597 * page extension in-place: entry insertion;
1598 * new right page from page split, reinitialized in-line
1599 * root from root page split: entry insertion;
1601 if (tlck->type & (tlckNEW | tlckEXTEND)) {
1602 /* log after-image of the new page for logredo():
1603 * mark log (LOG_NEW) for logredo() to initialize
1604 * freelist and update bmap for alloc of the new page;
1606 lrd->type = cpu_to_le16(LOG_REDOPAGE);
1607 if (tlck->type & tlckEXTEND)
1608 lrd->log.redopage.type |= cpu_to_le16(LOG_EXTEND);
1609 else
1610 lrd->log.redopage.type |= cpu_to_le16(LOG_NEW);
1611 // *pxd = mp->cm_pxd;
1612 PXDaddress(pxd, mp->index);
1613 PXDlength(pxd,
1614 mp->logical_size >> tblk->sb->s_blocksize_bits);
1615 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1617 /* format a maplock for txUpdateMap() to update bPMAP for
1618 * alloc of the new page;
1620 if (tlck->type & tlckBTROOT)
1621 return;
1622 tlck->flag |= tlckUPDATEMAP;
1623 pxdlock = (struct pxd_lock *) & tlck->lock;
1624 pxdlock->flag = mlckALLOCPXD;
1625 pxdlock->pxd = *pxd;
1627 pxdlock->index = 1;
1629 /* mark page as homeward bound */
1630 tlck->flag |= tlckWRITEPAGE;
1631 return;
1635 * entry insertion/deletion,
1636 * sibling page link update (old right page before split);
1638 if (tlck->type & (tlckENTRY | tlckRELINK)) {
1639 /* log after-image for logredo(): */
1640 lrd->type = cpu_to_le16(LOG_REDOPAGE);
1641 PXDaddress(pxd, mp->index);
1642 PXDlength(pxd,
1643 mp->logical_size >> tblk->sb->s_blocksize_bits);
1644 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1646 /* mark page as homeward bound */
1647 tlck->flag |= tlckWRITEPAGE;
1648 return;
1652 * page deletion: page has been invalidated
1653 * page relocation: source extent
1655 * a maplock for free of the page has been formatted
1656 * at txLock() time);
1658 if (tlck->type & (tlckFREE | tlckRELOCATE)) {
1659 /* log LOG_NOREDOPAGE of the deleted page for logredo()
1660 * to start NoRedoPage filter and to update bmap for free
1661 * of the deletd page
1663 lrd->type = cpu_to_le16(LOG_NOREDOPAGE);
1664 pxdlock = (struct pxd_lock *) & tlck->lock;
1665 *pxd = pxdlock->pxd;
1666 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
1668 /* a maplock for txUpdateMap() for free of the page
1669 * has been formatted at txLock() time;
1671 tlck->flag |= tlckUPDATEMAP;
1673 return;
1678 * xtLog()
1680 * function: log xtree tlock and format maplock to update bmap;
1682 static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
1683 struct tlock * tlck)
1685 struct inode *ip;
1686 struct metapage *mp;
1687 xtpage_t *p;
1688 struct xtlock *xtlck;
1689 struct maplock *maplock;
1690 struct xdlistlock *xadlock;
1691 struct pxd_lock *pxdlock;
1692 pxd_t *pxd;
1693 int next, lwm, hwm;
1695 ip = tlck->ip;
1696 mp = tlck->mp;
1698 /* initialize as REDOPAGE/NOREDOPAGE record format */
1699 lrd->log.redopage.type = cpu_to_le16(LOG_XTREE);
1700 lrd->log.redopage.l2linesize = cpu_to_le16(L2XTSLOTSIZE);
1702 pxd = &lrd->log.redopage.pxd;
1704 if (tlck->type & tlckBTROOT) {
1705 lrd->log.redopage.type |= cpu_to_le16(LOG_BTROOT);
1706 p = &JFS_IP(ip)->i_xtroot;
1707 if (S_ISDIR(ip->i_mode))
1708 lrd->log.redopage.type |=
1709 cpu_to_le16(LOG_DIR_XTREE);
1710 } else
1711 p = (xtpage_t *) mp->data;
1712 next = le16_to_cpu(p->header.nextindex);
1714 xtlck = (struct xtlock *) & tlck->lock;
1716 maplock = (struct maplock *) & tlck->lock;
1717 xadlock = (struct xdlistlock *) maplock;
1720 * entry insertion/extension;
1721 * sibling page link update (old right page before split);
1723 if (tlck->type & (tlckNEW | tlckGROW | tlckRELINK)) {
1724 /* log after-image for logredo():
1725 * logredo() will update bmap for alloc of new/extended
1726 * extents (XAD_NEW|XAD_EXTEND) of XAD[lwm:next) from
1727 * after-image of XADlist;
1728 * logredo() resets (XAD_NEW|XAD_EXTEND) flag when
1729 * applying the after-image to the meta-data page.
1731 lrd->type = cpu_to_le16(LOG_REDOPAGE);
1732 // *pxd = mp->cm_pxd;
1733 PXDaddress(pxd, mp->index);
1734 PXDlength(pxd,
1735 mp->logical_size >> tblk->sb->s_blocksize_bits);
1736 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1738 /* format a maplock for txUpdateMap() to update bPMAP
1739 * for alloc of new/extended extents of XAD[lwm:next)
1740 * from the page itself;
1741 * txUpdateMap() resets (XAD_NEW|XAD_EXTEND) flag.
1743 lwm = xtlck->lwm.offset;
1744 if (lwm == 0)
1745 lwm = XTPAGEMAXSLOT;
1747 if (lwm == next)
1748 goto out;
1749 if (lwm > next) {
1750 jfs_err("xtLog: lwm > next\n");
1751 goto out;
1753 tlck->flag |= tlckUPDATEMAP;
1754 xadlock->flag = mlckALLOCXADLIST;
1755 xadlock->count = next - lwm;
1756 if ((xadlock->count <= 2) && (tblk->xflag & COMMIT_LAZY)) {
1757 int i;
1759 * Lazy commit may allow xtree to be modified before
1760 * txUpdateMap runs. Copy xad into linelock to
1761 * preserve correct data.
1763 xadlock->xdlist = &xtlck->pxdlock;
1764 memcpy(xadlock->xdlist, &p->xad[lwm],
1765 sizeof(xad_t) * xadlock->count);
1767 for (i = 0; i < xadlock->count; i++)
1768 p->xad[lwm + i].flag &=
1769 ~(XAD_NEW | XAD_EXTENDED);
1770 } else {
1772 * xdlist will point to into inode's xtree, ensure
1773 * that transaction is not committed lazily.
1775 xadlock->xdlist = &p->xad[lwm];
1776 tblk->xflag &= ~COMMIT_LAZY;
1778 jfs_info("xtLog: alloc ip:0x%p mp:0x%p tlck:0x%p lwm:%d "
1779 "count:%d", tlck->ip, mp, tlck, lwm, xadlock->count);
1781 maplock->index = 1;
1783 out:
1784 /* mark page as homeward bound */
1785 tlck->flag |= tlckWRITEPAGE;
1787 return;
1791 * page deletion: file deletion/truncation (ref. xtTruncate())
1793 * (page will be invalidated after log is written and bmap
1794 * is updated from the page);
1796 if (tlck->type & tlckFREE) {
1797 /* LOG_NOREDOPAGE log for NoRedoPage filter:
1798 * if page free from file delete, NoRedoFile filter from
1799 * inode image of zero link count will subsume NoRedoPage
1800 * filters for each page;
1801 * if page free from file truncattion, write NoRedoPage
1802 * filter;
1804 * upadte of block allocation map for the page itself:
1805 * if page free from deletion and truncation, LOG_UPDATEMAP
1806 * log for the page itself is generated from processing
1807 * its parent page xad entries;
1809 /* if page free from file truncation, log LOG_NOREDOPAGE
1810 * of the deleted page for logredo() to start NoRedoPage
1811 * filter for the page;
1813 if (tblk->xflag & COMMIT_TRUNCATE) {
1814 /* write NOREDOPAGE for the page */
1815 lrd->type = cpu_to_le16(LOG_NOREDOPAGE);
1816 PXDaddress(pxd, mp->index);
1817 PXDlength(pxd,
1818 mp->logical_size >> tblk->sb->
1819 s_blocksize_bits);
1820 lrd->backchain =
1821 cpu_to_le32(lmLog(log, tblk, lrd, NULL));
1823 if (tlck->type & tlckBTROOT) {
1824 /* Empty xtree must be logged */
1825 lrd->type = cpu_to_le16(LOG_REDOPAGE);
1826 lrd->backchain =
1827 cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1831 /* init LOG_UPDATEMAP of the freed extents
1832 * XAD[XTENTRYSTART:hwm) from the deleted page itself
1833 * for logredo() to update bmap;
1835 lrd->type = cpu_to_le16(LOG_UPDATEMAP);
1836 lrd->log.updatemap.type = cpu_to_le16(LOG_FREEXADLIST);
1837 xtlck = (struct xtlock *) & tlck->lock;
1838 hwm = xtlck->hwm.offset;
1839 lrd->log.updatemap.nxd =
1840 cpu_to_le16(hwm - XTENTRYSTART + 1);
1841 /* reformat linelock for lmLog() */
1842 xtlck->header.offset = XTENTRYSTART;
1843 xtlck->header.length = hwm - XTENTRYSTART + 1;
1844 xtlck->index = 1;
1845 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1847 /* format a maplock for txUpdateMap() to update bmap
1848 * to free extents of XAD[XTENTRYSTART:hwm) from the
1849 * deleted page itself;
1851 tlck->flag |= tlckUPDATEMAP;
1852 xadlock->flag = mlckFREEXADLIST;
1853 xadlock->count = hwm - XTENTRYSTART + 1;
1854 if ((xadlock->count <= 2) && (tblk->xflag & COMMIT_LAZY)) {
1856 * Lazy commit may allow xtree to be modified before
1857 * txUpdateMap runs. Copy xad into linelock to
1858 * preserve correct data.
1860 xadlock->xdlist = &xtlck->pxdlock;
1861 memcpy(xadlock->xdlist, &p->xad[XTENTRYSTART],
1862 sizeof(xad_t) * xadlock->count);
1863 } else {
1865 * xdlist will point to into inode's xtree, ensure
1866 * that transaction is not committed lazily.
1868 xadlock->xdlist = &p->xad[XTENTRYSTART];
1869 tblk->xflag &= ~COMMIT_LAZY;
1871 jfs_info("xtLog: free ip:0x%p mp:0x%p count:%d lwm:2",
1872 tlck->ip, mp, xadlock->count);
1874 maplock->index = 1;
1876 /* mark page as invalid */
1877 if (((tblk->xflag & COMMIT_PWMAP) || S_ISDIR(ip->i_mode))
1878 && !(tlck->type & tlckBTROOT))
1879 tlck->flag |= tlckFREEPAGE;
1881 else (tblk->xflag & COMMIT_PMAP)
1882 ? release the page;
1884 return;
1888 * page/entry truncation: file truncation (ref. xtTruncate())
1890 * |----------+------+------+---------------|
1891 * | | |
1892 * | | hwm - hwm before truncation
1893 * | next - truncation point
1894 * lwm - lwm before truncation
1895 * header ?
1897 if (tlck->type & tlckTRUNCATE) {
1898 pxd_t tpxd; /* truncated extent of xad */
1899 int twm;
1902 * For truncation the entire linelock may be used, so it would
1903 * be difficult to store xad list in linelock itself.
1904 * Therefore, we'll just force transaction to be committed
1905 * synchronously, so that xtree pages won't be changed before
1906 * txUpdateMap runs.
1908 tblk->xflag &= ~COMMIT_LAZY;
1909 lwm = xtlck->lwm.offset;
1910 if (lwm == 0)
1911 lwm = XTPAGEMAXSLOT;
1912 hwm = xtlck->hwm.offset;
1913 twm = xtlck->twm.offset;
1916 * write log records
1918 /* log after-image for logredo():
1920 * logredo() will update bmap for alloc of new/extended
1921 * extents (XAD_NEW|XAD_EXTEND) of XAD[lwm:next) from
1922 * after-image of XADlist;
1923 * logredo() resets (XAD_NEW|XAD_EXTEND) flag when
1924 * applying the after-image to the meta-data page.
1926 lrd->type = cpu_to_le16(LOG_REDOPAGE);
1927 PXDaddress(pxd, mp->index);
1928 PXDlength(pxd, mp->logical_size >> tblk->sb->s_blocksize_bits);
1929 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1932 * truncate entry XAD[twm == next - 1]:
1934 if (twm == next - 1) {
1935 /* init LOG_UPDATEMAP for logredo() to update bmap for
1936 * free of truncated delta extent of the truncated
1937 * entry XAD[next - 1]:
1938 * (xtlck->pxdlock = truncated delta extent);
1940 pxdlock = (struct pxd_lock *) & xtlck->pxdlock;
1941 /* assert(pxdlock->type & tlckTRUNCATE); */
1942 lrd->type = cpu_to_le16(LOG_UPDATEMAP);
1943 lrd->log.updatemap.type = cpu_to_le16(LOG_FREEPXD);
1944 lrd->log.updatemap.nxd = cpu_to_le16(1);
1945 lrd->log.updatemap.pxd = pxdlock->pxd;
1946 tpxd = pxdlock->pxd; /* save to format maplock */
1947 lrd->backchain =
1948 cpu_to_le32(lmLog(log, tblk, lrd, NULL));
1952 * free entries XAD[next:hwm]:
1954 if (hwm >= next) {
1955 /* init LOG_UPDATEMAP of the freed extents
1956 * XAD[next:hwm] from the deleted page itself
1957 * for logredo() to update bmap;
1959 lrd->type = cpu_to_le16(LOG_UPDATEMAP);
1960 lrd->log.updatemap.type =
1961 cpu_to_le16(LOG_FREEXADLIST);
1962 xtlck = (struct xtlock *) & tlck->lock;
1963 hwm = xtlck->hwm.offset;
1964 lrd->log.updatemap.nxd =
1965 cpu_to_le16(hwm - next + 1);
1966 /* reformat linelock for lmLog() */
1967 xtlck->header.offset = next;
1968 xtlck->header.length = hwm - next + 1;
1969 xtlck->index = 1;
1970 lrd->backchain =
1971 cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1975 * format maplock(s) for txUpdateMap() to update bmap
1977 maplock->index = 0;
1980 * allocate entries XAD[lwm:next):
1982 if (lwm < next) {
1983 /* format a maplock for txUpdateMap() to update bPMAP
1984 * for alloc of new/extended extents of XAD[lwm:next)
1985 * from the page itself;
1986 * txUpdateMap() resets (XAD_NEW|XAD_EXTEND) flag.
1988 tlck->flag |= tlckUPDATEMAP;
1989 xadlock->flag = mlckALLOCXADLIST;
1990 xadlock->count = next - lwm;
1991 xadlock->xdlist = &p->xad[lwm];
1993 jfs_info("xtLog: alloc ip:0x%p mp:0x%p count:%d "
1994 "lwm:%d next:%d",
1995 tlck->ip, mp, xadlock->count, lwm, next);
1996 maplock->index++;
1997 xadlock++;
2001 * truncate entry XAD[twm == next - 1]:
2003 if (twm == next - 1) {
2004 struct pxd_lock *pxdlock;
2006 /* format a maplock for txUpdateMap() to update bmap
2007 * to free truncated delta extent of the truncated
2008 * entry XAD[next - 1];
2009 * (xtlck->pxdlock = truncated delta extent);
2011 tlck->flag |= tlckUPDATEMAP;
2012 pxdlock = (struct pxd_lock *) xadlock;
2013 pxdlock->flag = mlckFREEPXD;
2014 pxdlock->count = 1;
2015 pxdlock->pxd = tpxd;
2017 jfs_info("xtLog: truncate ip:0x%p mp:0x%p count:%d "
2018 "hwm:%d", ip, mp, pxdlock->count, hwm);
2019 maplock->index++;
2020 xadlock++;
2024 * free entries XAD[next:hwm]:
2026 if (hwm >= next) {
2027 /* format a maplock for txUpdateMap() to update bmap
2028 * to free extents of XAD[next:hwm] from thedeleted
2029 * page itself;
2031 tlck->flag |= tlckUPDATEMAP;
2032 xadlock->flag = mlckFREEXADLIST;
2033 xadlock->count = hwm - next + 1;
2034 xadlock->xdlist = &p->xad[next];
2036 jfs_info("xtLog: free ip:0x%p mp:0x%p count:%d "
2037 "next:%d hwm:%d",
2038 tlck->ip, mp, xadlock->count, next, hwm);
2039 maplock->index++;
2042 /* mark page as homeward bound */
2043 tlck->flag |= tlckWRITEPAGE;
2045 return;
2050 * mapLog()
2052 * function: log from maplock of freed data extents;
2054 void mapLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
2055 struct tlock * tlck)
2057 struct pxd_lock *pxdlock;
2058 int i, nlock;
2059 pxd_t *pxd;
2062 * page relocation: free the source page extent
2064 * a maplock for txUpdateMap() for free of the page
2065 * has been formatted at txLock() time saving the src
2066 * relocated page address;
2068 if (tlck->type & tlckRELOCATE) {
2069 /* log LOG_NOREDOPAGE of the old relocated page
2070 * for logredo() to start NoRedoPage filter;
2072 lrd->type = cpu_to_le16(LOG_NOREDOPAGE);
2073 pxdlock = (struct pxd_lock *) & tlck->lock;
2074 pxd = &lrd->log.redopage.pxd;
2075 *pxd = pxdlock->pxd;
2076 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
2078 /* (N.B. currently, logredo() does NOT update bmap
2079 * for free of the page itself for (LOG_XTREE|LOG_NOREDOPAGE);
2080 * if page free from relocation, LOG_UPDATEMAP log is
2081 * specifically generated now for logredo()
2082 * to update bmap for free of src relocated page;
2083 * (new flag LOG_RELOCATE may be introduced which will
2084 * inform logredo() to start NORedoPage filter and also
2085 * update block allocation map at the same time, thus
2086 * avoiding an extra log write);
2088 lrd->type = cpu_to_le16(LOG_UPDATEMAP);
2089 lrd->log.updatemap.type = cpu_to_le16(LOG_FREEPXD);
2090 lrd->log.updatemap.nxd = cpu_to_le16(1);
2091 lrd->log.updatemap.pxd = pxdlock->pxd;
2092 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
2094 /* a maplock for txUpdateMap() for free of the page
2095 * has been formatted at txLock() time;
2097 tlck->flag |= tlckUPDATEMAP;
2098 return;
2102 * Otherwise it's not a relocate request
2105 else {
2106 /* log LOG_UPDATEMAP for logredo() to update bmap for
2107 * free of truncated/relocated delta extent of the data;
2108 * e.g.: external EA extent, relocated/truncated extent
2109 * from xtTailgate();
2111 lrd->type = cpu_to_le16(LOG_UPDATEMAP);
2112 pxdlock = (struct pxd_lock *) & tlck->lock;
2113 nlock = pxdlock->index;
2114 for (i = 0; i < nlock; i++, pxdlock++) {
2115 if (pxdlock->flag & mlckALLOCPXD)
2116 lrd->log.updatemap.type =
2117 cpu_to_le16(LOG_ALLOCPXD);
2118 else
2119 lrd->log.updatemap.type =
2120 cpu_to_le16(LOG_FREEPXD);
2121 lrd->log.updatemap.nxd = cpu_to_le16(1);
2122 lrd->log.updatemap.pxd = pxdlock->pxd;
2123 lrd->backchain =
2124 cpu_to_le32(lmLog(log, tblk, lrd, NULL));
2125 jfs_info("mapLog: xaddr:0x%lx xlen:0x%x",
2126 (ulong) addressPXD(&pxdlock->pxd),
2127 lengthPXD(&pxdlock->pxd));
2130 /* update bmap */
2131 tlck->flag |= tlckUPDATEMAP;
2137 * txEA()
2139 * function: acquire maplock for EA/ACL extents or
2140 * set COMMIT_INLINE flag;
2142 void txEA(tid_t tid, struct inode *ip, dxd_t * oldea, dxd_t * newea)
2144 struct tlock *tlck = NULL;
2145 struct pxd_lock *maplock = NULL, *pxdlock = NULL;
2148 * format maplock for alloc of new EA extent
2150 if (newea) {
2151 /* Since the newea could be a completely zeroed entry we need to
2152 * check for the two flags which indicate we should actually
2153 * commit new EA data
2155 if (newea->flag & DXD_EXTENT) {
2156 tlck = txMaplock(tid, ip, tlckMAP);
2157 maplock = (struct pxd_lock *) & tlck->lock;
2158 pxdlock = (struct pxd_lock *) maplock;
2159 pxdlock->flag = mlckALLOCPXD;
2160 PXDaddress(&pxdlock->pxd, addressDXD(newea));
2161 PXDlength(&pxdlock->pxd, lengthDXD(newea));
2162 pxdlock++;
2163 maplock->index = 1;
2164 } else if (newea->flag & DXD_INLINE) {
2165 tlck = NULL;
2167 set_cflag(COMMIT_Inlineea, ip);
2172 * format maplock for free of old EA extent
2174 if (!test_cflag(COMMIT_Nolink, ip) && oldea->flag & DXD_EXTENT) {
2175 if (tlck == NULL) {
2176 tlck = txMaplock(tid, ip, tlckMAP);
2177 maplock = (struct pxd_lock *) & tlck->lock;
2178 pxdlock = (struct pxd_lock *) maplock;
2179 maplock->index = 0;
2181 pxdlock->flag = mlckFREEPXD;
2182 PXDaddress(&pxdlock->pxd, addressDXD(oldea));
2183 PXDlength(&pxdlock->pxd, lengthDXD(oldea));
2184 maplock->index++;
2190 * txForce()
2192 * function: synchronously write pages locked by transaction
2193 * after txLog() but before txUpdateMap();
2195 void txForce(struct tblock * tblk)
2197 struct tlock *tlck;
2198 lid_t lid, next;
2199 struct metapage *mp;
2202 * reverse the order of transaction tlocks in
2203 * careful update order of address index pages
2204 * (right to left, bottom up)
2206 tlck = lid_to_tlock(tblk->next);
2207 lid = tlck->next;
2208 tlck->next = 0;
2209 while (lid) {
2210 tlck = lid_to_tlock(lid);
2211 next = tlck->next;
2212 tlck->next = tblk->next;
2213 tblk->next = lid;
2214 lid = next;
2218 * synchronously write the page, and
2219 * hold the page for txUpdateMap();
2221 for (lid = tblk->next; lid; lid = next) {
2222 tlck = lid_to_tlock(lid);
2223 next = tlck->next;
2225 if ((mp = tlck->mp) != NULL &&
2226 (tlck->type & tlckBTROOT) == 0) {
2227 assert(mp->xflag & COMMIT_PAGE);
2229 if (tlck->flag & tlckWRITEPAGE) {
2230 tlck->flag &= ~tlckWRITEPAGE;
2232 /* do not release page to freelist */
2235 * The "right" thing to do here is to
2236 * synchronously write the metadata.
2237 * With the current implementation this
2238 * is hard since write_metapage requires
2239 * us to kunmap & remap the page. If we
2240 * have tlocks pointing into the metadata
2241 * pages, we don't want to do this. I think
2242 * we can get by with synchronously writing
2243 * the pages when they are released.
2245 assert(atomic_read(&mp->nohomeok));
2246 set_bit(META_dirty, &mp->flag);
2247 set_bit(META_sync, &mp->flag);
2255 * txUpdateMap()
2257 * function: update persistent allocation map (and working map
2258 * if appropriate);
2260 * parameter:
2262 static void txUpdateMap(struct tblock * tblk)
2264 struct inode *ip;
2265 struct inode *ipimap;
2266 lid_t lid;
2267 struct tlock *tlck;
2268 struct maplock *maplock;
2269 struct pxd_lock pxdlock;
2270 int maptype;
2271 int k, nlock;
2272 struct metapage *mp = NULL;
2274 ipimap = JFS_SBI(tblk->sb)->ipimap;
2276 maptype = (tblk->xflag & COMMIT_PMAP) ? COMMIT_PMAP : COMMIT_PWMAP;
2280 * update block allocation map
2282 * update allocation state in pmap (and wmap) and
2283 * update lsn of the pmap page;
2286 * scan each tlock/page of transaction for block allocation/free:
2288 * for each tlock/page of transaction, update map.
2289 * ? are there tlock for pmap and pwmap at the same time ?
2291 for (lid = tblk->next; lid; lid = tlck->next) {
2292 tlck = lid_to_tlock(lid);
2294 if ((tlck->flag & tlckUPDATEMAP) == 0)
2295 continue;
2297 if (tlck->flag & tlckFREEPAGE) {
2299 * Another thread may attempt to reuse freed space
2300 * immediately, so we want to get rid of the metapage
2301 * before anyone else has a chance to get it.
2302 * Lock metapage, update maps, then invalidate
2303 * the metapage.
2305 mp = tlck->mp;
2306 ASSERT(mp->xflag & COMMIT_PAGE);
2307 hold_metapage(mp, 0);
2311 * extent list:
2312 * . in-line PXD list:
2313 * . out-of-line XAD list:
2315 maplock = (struct maplock *) & tlck->lock;
2316 nlock = maplock->index;
2318 for (k = 0; k < nlock; k++, maplock++) {
2320 * allocate blocks in persistent map:
2322 * blocks have been allocated from wmap at alloc time;
2324 if (maplock->flag & mlckALLOC) {
2325 txAllocPMap(ipimap, maplock, tblk);
2328 * free blocks in persistent and working map:
2329 * blocks will be freed in pmap and then in wmap;
2331 * ? tblock specifies the PMAP/PWMAP based upon
2332 * transaction
2334 * free blocks in persistent map:
2335 * blocks will be freed from wmap at last reference
2336 * release of the object for regular files;
2338 * Alway free blocks from both persistent & working
2339 * maps for directories
2341 else { /* (maplock->flag & mlckFREE) */
2343 if (S_ISDIR(tlck->ip->i_mode))
2344 txFreeMap(ipimap, maplock,
2345 tblk, COMMIT_PWMAP);
2346 else
2347 txFreeMap(ipimap, maplock,
2348 tblk, maptype);
2351 if (tlck->flag & tlckFREEPAGE) {
2352 if (!(tblk->flag & tblkGC_LAZY)) {
2353 /* This is equivalent to txRelease */
2354 ASSERT(mp->lid == lid);
2355 tlck->mp->lid = 0;
2357 assert(atomic_read(&mp->nohomeok) == 1);
2358 atomic_dec(&mp->nohomeok);
2359 discard_metapage(mp);
2360 tlck->mp = NULL;
2364 * update inode allocation map
2366 * update allocation state in pmap and
2367 * update lsn of the pmap page;
2368 * update in-memory inode flag/state
2370 * unlock mapper/write lock
2372 if (tblk->xflag & COMMIT_CREATE) {
2373 diUpdatePMap(ipimap, tblk->ino, FALSE, tblk);
2374 ipimap->i_state |= I_DIRTY;
2375 /* update persistent block allocation map
2376 * for the allocation of inode extent;
2378 pxdlock.flag = mlckALLOCPXD;
2379 pxdlock.pxd = tblk->u.ixpxd;
2380 pxdlock.index = 1;
2381 txAllocPMap(ipimap, (struct maplock *) & pxdlock, tblk);
2382 } else if (tblk->xflag & COMMIT_DELETE) {
2383 ip = tblk->u.ip;
2384 diUpdatePMap(ipimap, ip->i_ino, TRUE, tblk);
2385 ipimap->i_state |= I_DIRTY;
2386 iput(ip);
2392 * txAllocPMap()
2394 * function: allocate from persistent map;
2396 * parameter:
2397 * ipbmap -
2398 * malock -
2399 * xad list:
2400 * pxd:
2402 * maptype -
2403 * allocate from persistent map;
2404 * free from persistent map;
2405 * (e.g., tmp file - free from working map at releae
2406 * of last reference);
2407 * free from persistent and working map;
2409 * lsn - log sequence number;
2411 static void txAllocPMap(struct inode *ip, struct maplock * maplock,
2412 struct tblock * tblk)
2414 struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap;
2415 struct xdlistlock *xadlistlock;
2416 xad_t *xad;
2417 s64 xaddr;
2418 int xlen;
2419 struct pxd_lock *pxdlock;
2420 struct xdlistlock *pxdlistlock;
2421 pxd_t *pxd;
2422 int n;
2425 * allocate from persistent map;
2427 if (maplock->flag & mlckALLOCXADLIST) {
2428 xadlistlock = (struct xdlistlock *) maplock;
2429 xad = xadlistlock->xdlist;
2430 for (n = 0; n < xadlistlock->count; n++, xad++) {
2431 if (xad->flag & (XAD_NEW | XAD_EXTENDED)) {
2432 xaddr = addressXAD(xad);
2433 xlen = lengthXAD(xad);
2434 dbUpdatePMap(ipbmap, FALSE, xaddr,
2435 (s64) xlen, tblk);
2436 xad->flag &= ~(XAD_NEW | XAD_EXTENDED);
2437 jfs_info("allocPMap: xaddr:0x%lx xlen:%d",
2438 (ulong) xaddr, xlen);
2441 } else if (maplock->flag & mlckALLOCPXD) {
2442 pxdlock = (struct pxd_lock *) maplock;
2443 xaddr = addressPXD(&pxdlock->pxd);
2444 xlen = lengthPXD(&pxdlock->pxd);
2445 dbUpdatePMap(ipbmap, FALSE, xaddr, (s64) xlen, tblk);
2446 jfs_info("allocPMap: xaddr:0x%lx xlen:%d", (ulong) xaddr, xlen);
2447 } else { /* (maplock->flag & mlckALLOCPXDLIST) */
2449 pxdlistlock = (struct xdlistlock *) maplock;
2450 pxd = pxdlistlock->xdlist;
2451 for (n = 0; n < pxdlistlock->count; n++, pxd++) {
2452 xaddr = addressPXD(pxd);
2453 xlen = lengthPXD(pxd);
2454 dbUpdatePMap(ipbmap, FALSE, xaddr, (s64) xlen,
2455 tblk);
2456 jfs_info("allocPMap: xaddr:0x%lx xlen:%d",
2457 (ulong) xaddr, xlen);
2464 * txFreeMap()
2466 * function: free from persistent and/or working map;
2468 * todo: optimization
2470 void txFreeMap(struct inode *ip,
2471 struct maplock * maplock, struct tblock * tblk, int maptype)
2473 struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap;
2474 struct xdlistlock *xadlistlock;
2475 xad_t *xad;
2476 s64 xaddr;
2477 int xlen;
2478 struct pxd_lock *pxdlock;
2479 struct xdlistlock *pxdlistlock;
2480 pxd_t *pxd;
2481 int n;
2483 jfs_info("txFreeMap: tblk:0x%p maplock:0x%p maptype:0x%x",
2484 tblk, maplock, maptype);
2487 * free from persistent map;
2489 if (maptype == COMMIT_PMAP || maptype == COMMIT_PWMAP) {
2490 if (maplock->flag & mlckFREEXADLIST) {
2491 xadlistlock = (struct xdlistlock *) maplock;
2492 xad = xadlistlock->xdlist;
2493 for (n = 0; n < xadlistlock->count; n++, xad++) {
2494 if (!(xad->flag & XAD_NEW)) {
2495 xaddr = addressXAD(xad);
2496 xlen = lengthXAD(xad);
2497 dbUpdatePMap(ipbmap, TRUE, xaddr,
2498 (s64) xlen, tblk);
2499 jfs_info("freePMap: xaddr:0x%lx "
2500 "xlen:%d",
2501 (ulong) xaddr, xlen);
2504 } else if (maplock->flag & mlckFREEPXD) {
2505 pxdlock = (struct pxd_lock *) maplock;
2506 xaddr = addressPXD(&pxdlock->pxd);
2507 xlen = lengthPXD(&pxdlock->pxd);
2508 dbUpdatePMap(ipbmap, TRUE, xaddr, (s64) xlen,
2509 tblk);
2510 jfs_info("freePMap: xaddr:0x%lx xlen:%d",
2511 (ulong) xaddr, xlen);
2512 } else { /* (maplock->flag & mlckALLOCPXDLIST) */
2514 pxdlistlock = (struct xdlistlock *) maplock;
2515 pxd = pxdlistlock->xdlist;
2516 for (n = 0; n < pxdlistlock->count; n++, pxd++) {
2517 xaddr = addressPXD(pxd);
2518 xlen = lengthPXD(pxd);
2519 dbUpdatePMap(ipbmap, TRUE, xaddr,
2520 (s64) xlen, tblk);
2521 jfs_info("freePMap: xaddr:0x%lx xlen:%d",
2522 (ulong) xaddr, xlen);
2528 * free from working map;
2530 if (maptype == COMMIT_PWMAP || maptype == COMMIT_WMAP) {
2531 if (maplock->flag & mlckFREEXADLIST) {
2532 xadlistlock = (struct xdlistlock *) maplock;
2533 xad = xadlistlock->xdlist;
2534 for (n = 0; n < xadlistlock->count; n++, xad++) {
2535 xaddr = addressXAD(xad);
2536 xlen = lengthXAD(xad);
2537 dbFree(ip, xaddr, (s64) xlen);
2538 xad->flag = 0;
2539 jfs_info("freeWMap: xaddr:0x%lx xlen:%d",
2540 (ulong) xaddr, xlen);
2542 } else if (maplock->flag & mlckFREEPXD) {
2543 pxdlock = (struct pxd_lock *) maplock;
2544 xaddr = addressPXD(&pxdlock->pxd);
2545 xlen = lengthPXD(&pxdlock->pxd);
2546 dbFree(ip, xaddr, (s64) xlen);
2547 jfs_info("freeWMap: xaddr:0x%lx xlen:%d",
2548 (ulong) xaddr, xlen);
2549 } else { /* (maplock->flag & mlckFREEPXDLIST) */
2551 pxdlistlock = (struct xdlistlock *) maplock;
2552 pxd = pxdlistlock->xdlist;
2553 for (n = 0; n < pxdlistlock->count; n++, pxd++) {
2554 xaddr = addressPXD(pxd);
2555 xlen = lengthPXD(pxd);
2556 dbFree(ip, xaddr, (s64) xlen);
2557 jfs_info("freeWMap: xaddr:0x%lx xlen:%d",
2558 (ulong) xaddr, xlen);
2566 * txFreelock()
2568 * function: remove tlock from inode anonymous locklist
2570 void txFreelock(struct inode *ip)
2572 struct jfs_inode_info *jfs_ip = JFS_IP(ip);
2573 struct tlock *xtlck, *tlck;
2574 lid_t xlid = 0, lid;
2576 if (!jfs_ip->atlhead)
2577 return;
2579 TXN_LOCK();
2580 xtlck = (struct tlock *) &jfs_ip->atlhead;
2582 while ((lid = xtlck->next) != 0) {
2583 tlck = lid_to_tlock(lid);
2584 if (tlck->flag & tlckFREELOCK) {
2585 xtlck->next = tlck->next;
2586 txLockFree(lid);
2587 } else {
2588 xtlck = tlck;
2589 xlid = lid;
2593 if (jfs_ip->atlhead)
2594 jfs_ip->atltail = xlid;
2595 else {
2596 jfs_ip->atltail = 0;
2598 * If inode was on anon_list, remove it
2600 list_del_init(&jfs_ip->anon_inode_list);
2602 TXN_UNLOCK();
2607 * txAbort()
2609 * function: abort tx before commit;
2611 * frees line-locks and segment locks for all
2612 * segments in comdata structure.
2613 * Optionally sets state of file-system to FM_DIRTY in super-block.
2614 * log age of page-frames in memory for which caller has
2615 * are reset to 0 (to avoid logwarap).
2617 void txAbort(tid_t tid, int dirty)
2619 lid_t lid, next;
2620 struct metapage *mp;
2621 struct tblock *tblk = tid_to_tblock(tid);
2622 struct tlock *tlck;
2625 * free tlocks of the transaction
2627 for (lid = tblk->next; lid; lid = next) {
2628 tlck = lid_to_tlock(lid);
2629 next = tlck->next;
2630 mp = tlck->mp;
2631 JFS_IP(tlck->ip)->xtlid = 0;
2633 if (mp) {
2634 mp->lid = 0;
2637 * reset lsn of page to avoid logwarap:
2639 * (page may have been previously committed by another
2640 * transaction(s) but has not been paged, i.e.,
2641 * it may be on logsync list even though it has not
2642 * been logged for the current tx.)
2644 if (mp->xflag & COMMIT_PAGE && mp->lsn)
2645 LogSyncRelease(mp);
2647 /* insert tlock at head of freelist */
2648 TXN_LOCK();
2649 txLockFree(lid);
2650 TXN_UNLOCK();
2653 /* caller will free the transaction block */
2655 tblk->next = tblk->last = 0;
2658 * mark filesystem dirty
2660 if (dirty)
2661 jfs_error(tblk->sb, "txAbort");
2663 return;
2667 * txLazyCommit(void)
2669 * All transactions except those changing ipimap (COMMIT_FORCE) are
2670 * processed by this routine. This insures that the inode and block
2671 * allocation maps are updated in order. For synchronous transactions,
2672 * let the user thread finish processing after txUpdateMap() is called.
2674 static void txLazyCommit(struct tblock * tblk)
2676 struct jfs_log *log;
2678 while (((tblk->flag & tblkGC_READY) == 0) &&
2679 ((tblk->flag & tblkGC_UNLOCKED) == 0)) {
2680 /* We must have gotten ahead of the user thread
2682 jfs_info("jfs_lazycommit: tblk 0x%p not unlocked", tblk);
2683 yield();
2686 jfs_info("txLazyCommit: processing tblk 0x%p", tblk);
2688 txUpdateMap(tblk);
2690 log = (struct jfs_log *) JFS_SBI(tblk->sb)->log;
2692 spin_lock_irq(&log->gclock); // LOGGC_LOCK
2694 tblk->flag |= tblkGC_COMMITTED;
2696 if (tblk->flag & tblkGC_READY)
2697 log->gcrtc--;
2699 wake_up_all(&tblk->gcwait); // LOGGC_WAKEUP
2702 * Can't release log->gclock until we've tested tblk->flag
2704 if (tblk->flag & tblkGC_LAZY) {
2705 spin_unlock_irq(&log->gclock); // LOGGC_UNLOCK
2706 txUnlock(tblk);
2707 tblk->flag &= ~tblkGC_LAZY;
2708 txEnd(tblk - TxBlock); /* Convert back to tid */
2709 } else
2710 spin_unlock_irq(&log->gclock); // LOGGC_UNLOCK
2712 jfs_info("txLazyCommit: done: tblk = 0x%p", tblk);
2716 * jfs_lazycommit(void)
2718 * To be run as a kernel daemon. If lbmIODone is called in an interrupt
2719 * context, or where blocking is not wanted, this routine will process
2720 * committed transactions from the unlock queue.
2722 int jfs_lazycommit(void *arg)
2724 int WorkDone;
2725 struct tblock *tblk;
2726 unsigned long flags;
2727 struct jfs_sb_info *sbi;
2729 daemonize("jfsCommit");
2731 complete(&jfsIOwait);
2733 do {
2734 LAZY_LOCK(flags);
2735 while (!list_empty(&TxAnchor.unlock_queue)) {
2736 WorkDone = 0;
2737 list_for_each_entry(tblk, &TxAnchor.unlock_queue,
2738 cqueue) {
2740 sbi = JFS_SBI(tblk->sb);
2742 * For each volume, the transactions must be
2743 * handled in order. If another commit thread
2744 * is handling a tblk for this superblock,
2745 * skip it
2747 if (sbi->commit_state & IN_LAZYCOMMIT)
2748 continue;
2750 sbi->commit_state |= IN_LAZYCOMMIT;
2751 WorkDone = 1;
2754 * Remove transaction from queue
2756 list_del(&tblk->cqueue);
2758 LAZY_UNLOCK(flags);
2759 txLazyCommit(tblk);
2760 LAZY_LOCK(flags);
2762 sbi->commit_state &= ~IN_LAZYCOMMIT;
2764 * Don't continue in the for loop. (We can't
2765 * anyway, it's unsafe!) We want to go back to
2766 * the beginning of the list.
2768 break;
2771 /* If there was nothing to do, don't continue */
2772 if (!WorkDone)
2773 break;
2776 if (current->flags & PF_FREEZE) {
2777 LAZY_UNLOCK(flags);
2778 refrigerator(PF_FREEZE);
2779 } else {
2780 DECLARE_WAITQUEUE(wq, current);
2782 add_wait_queue(&jfs_commit_thread_wait, &wq);
2783 set_current_state(TASK_INTERRUPTIBLE);
2784 LAZY_UNLOCK(flags);
2785 schedule();
2786 current->state = TASK_RUNNING;
2787 remove_wait_queue(&jfs_commit_thread_wait, &wq);
2789 } while (!jfs_stop_threads);
2791 if (!list_empty(&TxAnchor.unlock_queue))
2792 jfs_err("jfs_lazycommit being killed w/pending transactions!");
2793 else
2794 jfs_info("jfs_lazycommit being killed\n");
2795 complete_and_exit(&jfsIOwait, 0);
2798 void txLazyUnlock(struct tblock * tblk)
2800 unsigned long flags;
2802 LAZY_LOCK(flags);
2804 list_add_tail(&tblk->cqueue, &TxAnchor.unlock_queue);
2806 * Don't wake up a commit thread if there is already one servicing
2807 * this superblock.
2809 if (!(JFS_SBI(tblk->sb)->commit_state & IN_LAZYCOMMIT))
2810 wake_up(&jfs_commit_thread_wait);
2811 LAZY_UNLOCK(flags);
2814 static void LogSyncRelease(struct metapage * mp)
2816 struct jfs_log *log = mp->log;
2818 assert(atomic_read(&mp->nohomeok));
2819 assert(log);
2820 atomic_dec(&mp->nohomeok);
2822 if (atomic_read(&mp->nohomeok))
2823 return;
2825 hold_metapage(mp, 0);
2827 LOGSYNC_LOCK(log);
2828 mp->log = NULL;
2829 mp->lsn = 0;
2830 mp->clsn = 0;
2831 log->count--;
2832 list_del_init(&mp->synclist);
2833 LOGSYNC_UNLOCK(log);
2835 release_metapage(mp);
2839 * txQuiesce
2841 * Block all new transactions and push anonymous transactions to
2842 * completion
2844 * This does almost the same thing as jfs_sync below. We don't
2845 * worry about deadlocking when jfs_tlocks_low is set, since we would
2846 * expect jfs_sync to get us out of that jam.
2848 void txQuiesce(struct super_block *sb)
2850 struct inode *ip;
2851 struct jfs_inode_info *jfs_ip;
2852 struct jfs_log *log = JFS_SBI(sb)->log;
2853 tid_t tid;
2855 set_bit(log_QUIESCE, &log->flag);
2857 TXN_LOCK();
2858 restart:
2859 while (!list_empty(&TxAnchor.anon_list)) {
2860 jfs_ip = list_entry(TxAnchor.anon_list.next,
2861 struct jfs_inode_info,
2862 anon_inode_list);
2863 ip = &jfs_ip->vfs_inode;
2866 * inode will be removed from anonymous list
2867 * when it is committed
2869 TXN_UNLOCK();
2870 tid = txBegin(ip->i_sb, COMMIT_INODE | COMMIT_FORCE);
2871 down(&jfs_ip->commit_sem);
2872 txCommit(tid, 1, &ip, 0);
2873 txEnd(tid);
2874 up(&jfs_ip->commit_sem);
2876 * Just to be safe. I don't know how
2877 * long we can run without blocking
2879 cond_resched();
2880 TXN_LOCK();
2884 * If jfs_sync is running in parallel, there could be some inodes
2885 * on anon_list2. Let's check.
2887 if (!list_empty(&TxAnchor.anon_list2)) {
2888 list_splice(&TxAnchor.anon_list2, &TxAnchor.anon_list);
2889 INIT_LIST_HEAD(&TxAnchor.anon_list2);
2890 goto restart;
2892 TXN_UNLOCK();
2895 * We may need to kick off the group commit
2897 jfs_flush_journal(log, 0);
2901 * txResume()
2903 * Allows transactions to start again following txQuiesce
2905 void txResume(struct super_block *sb)
2907 struct jfs_log *log = JFS_SBI(sb)->log;
2909 clear_bit(log_QUIESCE, &log->flag);
2910 TXN_WAKEUP(&log->syncwait);
2914 * jfs_sync(void)
2916 * To be run as a kernel daemon. This is awakened when tlocks run low.
2917 * We write any inodes that have anonymous tlocks so they will become
2918 * available.
2920 int jfs_sync(void *arg)
2922 struct inode *ip;
2923 struct jfs_inode_info *jfs_ip;
2924 int rc;
2925 tid_t tid;
2927 daemonize("jfsSync");
2929 complete(&jfsIOwait);
2931 do {
2933 * write each inode on the anonymous inode list
2935 TXN_LOCK();
2936 while (jfs_tlocks_low && !list_empty(&TxAnchor.anon_list)) {
2937 jfs_ip = list_entry(TxAnchor.anon_list.next,
2938 struct jfs_inode_info,
2939 anon_inode_list);
2940 ip = &jfs_ip->vfs_inode;
2942 if (! igrab(ip)) {
2944 * Inode is being freed
2946 list_del_init(&jfs_ip->anon_inode_list);
2947 } else if (! down_trylock(&jfs_ip->commit_sem)) {
2949 * inode will be removed from anonymous list
2950 * when it is committed
2952 TXN_UNLOCK();
2953 tid = txBegin(ip->i_sb, COMMIT_INODE);
2954 rc = txCommit(tid, 1, &ip, 0);
2955 txEnd(tid);
2956 up(&jfs_ip->commit_sem);
2958 iput(ip);
2960 * Just to be safe. I don't know how
2961 * long we can run without blocking
2963 cond_resched();
2964 TXN_LOCK();
2965 } else {
2966 /* We can't get the commit semaphore. It may
2967 * be held by a thread waiting for tlock's
2968 * so let's not block here. Save it to
2969 * put back on the anon_list.
2972 /* Take off anon_list */
2973 list_del(&jfs_ip->anon_inode_list);
2975 /* Put on anon_list2 */
2976 list_add(&jfs_ip->anon_inode_list,
2977 &TxAnchor.anon_list2);
2979 TXN_UNLOCK();
2980 iput(ip);
2981 TXN_LOCK();
2984 /* Add anon_list2 back to anon_list */
2985 list_splice_init(&TxAnchor.anon_list2, &TxAnchor.anon_list);
2987 if (current->flags & PF_FREEZE) {
2988 TXN_UNLOCK();
2989 refrigerator(PF_FREEZE);
2990 } else {
2991 DECLARE_WAITQUEUE(wq, current);
2993 add_wait_queue(&jfs_sync_thread_wait, &wq);
2994 set_current_state(TASK_INTERRUPTIBLE);
2995 TXN_UNLOCK();
2996 schedule();
2997 current->state = TASK_RUNNING;
2998 remove_wait_queue(&jfs_sync_thread_wait, &wq);
3000 } while (!jfs_stop_threads);
3002 jfs_info("jfs_sync being killed");
3003 complete_and_exit(&jfsIOwait, 0);
3006 #if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_DEBUG)
3007 int jfs_txanchor_read(char *buffer, char **start, off_t offset, int length,
3008 int *eof, void *data)
3010 int len = 0;
3011 off_t begin;
3012 char *freewait;
3013 char *freelockwait;
3014 char *lowlockwait;
3016 freewait =
3017 waitqueue_active(&TxAnchor.freewait) ? "active" : "empty";
3018 freelockwait =
3019 waitqueue_active(&TxAnchor.freelockwait) ? "active" : "empty";
3020 lowlockwait =
3021 waitqueue_active(&TxAnchor.lowlockwait) ? "active" : "empty";
3023 len += sprintf(buffer,
3024 "JFS TxAnchor\n"
3025 "============\n"
3026 "freetid = %d\n"
3027 "freewait = %s\n"
3028 "freelock = %d\n"
3029 "freelockwait = %s\n"
3030 "lowlockwait = %s\n"
3031 "tlocksInUse = %d\n"
3032 "jfs_tlocks_low = %d\n"
3033 "unlock_queue is %sempty\n",
3034 TxAnchor.freetid,
3035 freewait,
3036 TxAnchor.freelock,
3037 freelockwait,
3038 lowlockwait,
3039 TxAnchor.tlocksInUse,
3040 jfs_tlocks_low,
3041 list_empty(&TxAnchor.unlock_queue) ? "" : "not ");
3043 begin = offset;
3044 *start = buffer + begin;
3045 len -= begin;
3047 if (len > length)
3048 len = length;
3049 else
3050 *eof = 1;
3052 if (len < 0)
3053 len = 0;
3055 return len;
3057 #endif
3059 #if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_STATISTICS)
3060 int jfs_txstats_read(char *buffer, char **start, off_t offset, int length,
3061 int *eof, void *data)
3063 int len = 0;
3064 off_t begin;
3066 len += sprintf(buffer,
3067 "JFS TxStats\n"
3068 "===========\n"
3069 "calls to txBegin = %d\n"
3070 "txBegin blocked by sync barrier = %d\n"
3071 "txBegin blocked by tlocks low = %d\n"
3072 "txBegin blocked by no free tid = %d\n"
3073 "calls to txBeginAnon = %d\n"
3074 "txBeginAnon blocked by sync barrier = %d\n"
3075 "txBeginAnon blocked by tlocks low = %d\n"
3076 "calls to txLockAlloc = %d\n"
3077 "tLockAlloc blocked by no free lock = %d\n",
3078 TxStat.txBegin,
3079 TxStat.txBegin_barrier,
3080 TxStat.txBegin_lockslow,
3081 TxStat.txBegin_freetid,
3082 TxStat.txBeginAnon,
3083 TxStat.txBeginAnon_barrier,
3084 TxStat.txBeginAnon_lockslow,
3085 TxStat.txLockAlloc,
3086 TxStat.txLockAlloc_freelock);
3088 begin = offset;
3089 *start = buffer + begin;
3090 len -= begin;
3092 if (len > length)
3093 len = length;
3094 else
3095 *eof = 1;
3097 if (len < 0)
3098 len = 0;
3100 return len;
3102 #endif