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.
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
24 * transaction starts with txBegin() and ends with txCommit()
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).
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
47 #include <linux/vmalloc.h>
48 #include <linux/smp_lock.h>
49 #include <linux/completion.h>
50 #include "jfs_incore.h"
51 #include "jfs_filsys.h"
52 #include "jfs_metapage.h"
53 #include "jfs_dinode.h"
56 #include "jfs_superblock.h"
57 #include "jfs_debug.h"
60 * transaction management structures
64 int freetid; /* index of a free tid structure */
65 wait_queue_head_t freewait; /* eventlist of free tblock */
68 int freelock; /* index first free lock word */
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 int TlocksLow; /* Indicates low number of available tlocks */
73 spinlock_t LazyLock; /* synchronize sync_queue & unlock_queue */
74 /* struct tblock *sync_queue; * Transactions waiting for data sync */
75 struct tblock *unlock_queue; /* Txns waiting to be released */
76 struct tblock *unlock_tail; /* Tail of unlock_queue */
77 struct list_head anon_list; /* inodes having anonymous txns */
78 struct list_head anon_list2; /* inodes having anonymous txns
79 that couldn't be sync'ed */
82 #ifdef CONFIG_JFS_STATISTICS
86 uint txBegin_lockslow;
89 uint txBeginAnon_barrier;
90 uint txBeginAnon_lockslow;
92 uint txLockAlloc_freelock;
96 static int nTxBlock = 512; /* number of transaction blocks */
97 struct tblock *TxBlock; /* transaction block table */
99 static int nTxLock = 4096; /* number of transaction locks */
100 static int TxLockLWM = 4096*.4; /* Low water mark for number of txLocks used */
101 static int TxLockHWM = 4096*.8; /* High water mark for number of txLocks used */
102 struct tlock *TxLock; /* transaction lock table */
106 * transaction management lock
108 static spinlock_t jfsTxnLock = SPIN_LOCK_UNLOCKED;
110 #define TXN_LOCK() spin_lock(&jfsTxnLock)
111 #define TXN_UNLOCK() spin_unlock(&jfsTxnLock)
113 #define LAZY_LOCK_INIT() spin_lock_init(&TxAnchor.LazyLock);
114 #define LAZY_LOCK(flags) spin_lock_irqsave(&TxAnchor.LazyLock, flags)
115 #define LAZY_UNLOCK(flags) spin_unlock_irqrestore(&TxAnchor.LazyLock, flags)
117 DECLARE_WAIT_QUEUE_HEAD(jfs_sync_thread_wait);
118 DECLARE_WAIT_QUEUE_HEAD(jfs_commit_thread_wait);
121 * Retry logic exist outside these macros to protect from spurrious wakeups.
123 static inline void TXN_SLEEP_DROP_LOCK(wait_queue_head_t * event)
125 DECLARE_WAITQUEUE(wait, current);
127 add_wait_queue(event, &wait);
128 set_current_state(TASK_UNINTERRUPTIBLE);
131 current->state = TASK_RUNNING;
132 remove_wait_queue(event, &wait);
135 #define TXN_SLEEP(event)\
137 TXN_SLEEP_DROP_LOCK(event);\
141 #define TXN_WAKEUP(event) wake_up_all(event)
148 tid_t maxtid; /* 4: biggest tid ever used */
149 lid_t maxlid; /* 4: biggest lid ever used */
150 int ntid; /* 4: # of transactions performed */
151 int nlid; /* 4: # of tlocks acquired */
152 int waitlock; /* 4: # of tlock wait */
157 * external references
159 extern int lmGroupCommit(struct jfs_log *, struct tblock *);
160 extern void lmSync(struct jfs_log *);
161 extern int jfs_commit_inode(struct inode *, int);
162 extern int jfs_stop_threads;
164 struct task_struct *jfsCommitTask;
165 extern struct completion jfsIOwait;
170 static int diLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
171 struct tlock * tlck, struct commit * cd);
172 static int dataLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
173 struct tlock * tlck);
174 static void dtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
175 struct tlock * tlck);
176 static void mapLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
177 struct tlock * tlck);
178 static void txAllocPMap(struct inode *ip, struct maplock * maplock,
179 struct tblock * tblk);
180 static void txForce(struct tblock * tblk);
181 static int txLog(struct jfs_log * log, struct tblock * tblk,
183 static void txUpdateMap(struct tblock * tblk);
184 static void txRelease(struct tblock * tblk);
185 static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
186 struct tlock * tlck);
187 static void LogSyncRelease(struct metapage * mp);
190 * transaction block/lock management
191 * ---------------------------------
195 * Get a transaction lock from the free list. If the number in use is
196 * greater than the high water mark, wake up the sync daemon. This should
197 * free some anonymous transaction locks. (TXN_LOCK must be held.)
199 static lid_t txLockAlloc(void)
203 INCREMENT(TxStat.txLockAlloc);
204 if (!TxAnchor.freelock) {
205 INCREMENT(TxStat.txLockAlloc_freelock);
208 while (!(lid = TxAnchor.freelock))
209 TXN_SLEEP(&TxAnchor.freelockwait);
210 TxAnchor.freelock = TxLock[lid].next;
211 HIGHWATERMARK(stattx.maxlid, lid);
212 if ((++TxAnchor.tlocksInUse > TxLockHWM) && (TxAnchor.TlocksLow == 0)) {
213 jfs_info("txLockAlloc TlocksLow");
214 TxAnchor.TlocksLow = 1;
215 wake_up(&jfs_sync_thread_wait);
221 static void txLockFree(lid_t lid)
223 TxLock[lid].next = TxAnchor.freelock;
224 TxAnchor.freelock = lid;
225 TxAnchor.tlocksInUse--;
226 if (TxAnchor.TlocksLow && (TxAnchor.tlocksInUse < TxLockLWM)) {
227 jfs_info("txLockFree TlocksLow no more");
228 TxAnchor.TlocksLow = 0;
229 TXN_WAKEUP(&TxAnchor.lowlockwait);
231 TXN_WAKEUP(&TxAnchor.freelockwait);
237 * FUNCTION: initialize transaction management structures
241 * serialization: single thread at jfs_init()
248 * initialize transaction block (tblock) table
250 * transaction id (tid) = tblock index
251 * tid = 0 is reserved.
253 size = sizeof(struct tblock) * nTxBlock;
254 TxBlock = (struct tblock *) vmalloc(size);
258 for (k = 1; k < nTxBlock - 1; k++) {
259 TxBlock[k].next = k + 1;
260 init_waitqueue_head(&TxBlock[k].gcwait);
261 init_waitqueue_head(&TxBlock[k].waitor);
264 init_waitqueue_head(&TxBlock[k].gcwait);
265 init_waitqueue_head(&TxBlock[k].waitor);
267 TxAnchor.freetid = 1;
268 init_waitqueue_head(&TxAnchor.freewait);
270 stattx.maxtid = 1; /* statistics */
273 * initialize transaction lock (tlock) table
275 * transaction lock id = tlock index
276 * tlock id = 0 is reserved.
278 size = sizeof(struct tlock) * nTxLock;
279 TxLock = (struct tlock *) vmalloc(size);
280 if (TxLock == NULL) {
285 /* initialize tlock table */
286 for (k = 1; k < nTxLock - 1; k++)
287 TxLock[k].next = k + 1;
289 init_waitqueue_head(&TxAnchor.freelockwait);
290 init_waitqueue_head(&TxAnchor.lowlockwait);
292 TxAnchor.freelock = 1;
293 TxAnchor.tlocksInUse = 0;
294 INIT_LIST_HEAD(&TxAnchor.anon_list);
295 INIT_LIST_HEAD(&TxAnchor.anon_list2);
297 stattx.maxlid = 1; /* statistics */
305 * FUNCTION: clean up when module is unloaded
319 * FUNCTION: start a transaction.
321 * PARAMETER: sb - superblock
322 * flag - force for nested tx;
324 * RETURN: tid - transaction id
326 * note: flag force allows to start tx for nested tx
327 * to prevent deadlock on logsync barrier;
329 tid_t txBegin(struct super_block *sb, int flag)
335 jfs_info("txBegin: flag = 0x%x", flag);
336 log = JFS_SBI(sb)->log;
340 INCREMENT(TxStat.txBegin);
343 if (!(flag & COMMIT_FORCE)) {
345 * synchronize with logsync barrier
347 if (test_bit(log_SYNCBARRIER, &log->flag) ||
348 test_bit(log_QUIESCE, &log->flag)) {
349 INCREMENT(TxStat.txBegin_barrier);
350 TXN_SLEEP(&log->syncwait);
356 * Don't begin transaction if we're getting starved for tlocks
357 * unless COMMIT_FORCE or COMMIT_INODE (which may ultimately
360 if (TxAnchor.TlocksLow) {
361 INCREMENT(TxStat.txBegin_lockslow);
362 TXN_SLEEP(&TxAnchor.lowlockwait);
368 * allocate transaction id/block
370 if ((t = TxAnchor.freetid) == 0) {
371 jfs_info("txBegin: waiting for free tid");
372 INCREMENT(TxStat.txBegin_freetid);
373 TXN_SLEEP(&TxAnchor.freewait);
377 tblk = tid_to_tblock(t);
379 if ((tblk->next == 0) && !(flag & COMMIT_FORCE)) {
380 /* Don't let a non-forced transaction take the last tblk */
381 jfs_info("txBegin: waiting for free tid");
382 INCREMENT(TxStat.txBegin_freetid);
383 TXN_SLEEP(&TxAnchor.freewait);
387 TxAnchor.freetid = tblk->next;
390 * initialize transaction
394 * We can't zero the whole thing or we screw up another thread being
395 * awakened after sleeping on tblk->waitor
397 * memset(tblk, 0, sizeof(struct tblock));
399 tblk->next = tblk->last = tblk->xflag = tblk->flag = tblk->lsn = 0;
403 tblk->logtid = log->logtid;
407 HIGHWATERMARK(stattx.maxtid, t); /* statistics */
408 INCREMENT(stattx.ntid); /* statistics */
412 jfs_info("txBegin: returning tid = %d", t);
419 * NAME: txBeginAnon()
421 * FUNCTION: start an anonymous transaction.
422 * Blocks if logsync or available tlocks are low to prevent
423 * anonymous tlocks from depleting supply.
425 * PARAMETER: sb - superblock
429 void txBeginAnon(struct super_block *sb)
433 log = JFS_SBI(sb)->log;
436 INCREMENT(TxStat.txBeginAnon);
440 * synchronize with logsync barrier
442 if (test_bit(log_SYNCBARRIER, &log->flag) ||
443 test_bit(log_QUIESCE, &log->flag)) {
444 INCREMENT(TxStat.txBeginAnon_barrier);
445 TXN_SLEEP(&log->syncwait);
450 * Don't begin transaction if we're getting starved for tlocks
452 if (TxAnchor.TlocksLow) {
453 INCREMENT(TxStat.txBeginAnon_lockslow);
454 TXN_SLEEP(&TxAnchor.lowlockwait);
464 * function: free specified transaction block.
466 * logsync barrier processing:
470 void txEnd(tid_t tid)
472 struct tblock *tblk = tid_to_tblock(tid);
475 jfs_info("txEnd: tid = %d", tid);
479 * wakeup transactions waiting on the page locked
480 * by the current transaction
482 TXN_WAKEUP(&tblk->waitor);
484 log = JFS_SBI(tblk->sb)->log;
487 * Lazy commit thread can't free this guy until we mark it UNLOCKED,
488 * otherwise, we would be left with a transaction that may have been
491 * Lazy commit thread will turn off tblkGC_LAZY before calling this
494 if (tblk->flag & tblkGC_LAZY) {
495 jfs_info("txEnd called w/lazy tid: %d, tblk = 0x%p", tid, tblk);
498 spin_lock_irq(&log->gclock); // LOGGC_LOCK
499 tblk->flag |= tblkGC_UNLOCKED;
500 spin_unlock_irq(&log->gclock); // LOGGC_UNLOCK
504 jfs_info("txEnd: tid: %d, tblk = 0x%p", tid, tblk);
506 assert(tblk->next == 0);
509 * insert tblock back on freelist
511 tblk->next = TxAnchor.freetid;
512 TxAnchor.freetid = tid;
515 * mark the tblock not active
517 if (--log->active == 0) {
518 clear_bit(log_FLUSH, &log->flag);
521 * synchronize with logsync barrier
523 if (test_bit(log_SYNCBARRIER, &log->flag)) {
524 /* forward log syncpt */
527 jfs_info("log barrier off: 0x%x", log->lsn);
529 /* enable new transactions start */
530 clear_bit(log_SYNCBARRIER, &log->flag);
532 /* wakeup all waitors for logsync barrier */
533 TXN_WAKEUP(&log->syncwait);
538 * wakeup all waitors for a free tblock
540 TXN_WAKEUP(&TxAnchor.freewait);
549 * function: acquire a transaction lock on the specified <mp>
553 * return: transaction lock id
557 struct tlock *txLock(tid_t tid, struct inode *ip, struct metapage * mp,
560 struct jfs_inode_info *jfs_ip = JFS_IP(ip);
565 struct xtlock *xtlck;
566 struct linelock *linelock;
570 assert(!test_cflag(COMMIT_Nolink, ip));
574 if (S_ISDIR(ip->i_mode) && (type & tlckXTREE) &&
575 !(mp->xflag & COMMIT_PAGE)) {
577 * Directory inode is special. It can have both an xtree tlock
578 * and a dtree tlock associated with it.
585 /* is page not locked by a transaction ? */
589 jfs_info("txLock: tid:%d ip:0x%p mp:0x%p lid:%d", tid, ip, mp, lid);
591 /* is page locked by the requester transaction ? */
592 tlck = lid_to_tlock(lid);
593 if ((xtid = tlck->tid) == tid)
597 * is page locked by anonymous transaction/lock ?
599 * (page update without transaction (i.e., file write) is
600 * locked under anonymous transaction tid = 0:
601 * anonymous tlocks maintained on anonymous tlock list of
602 * the inode of the page and available to all anonymous
603 * transactions until txCommit() time at which point
604 * they are transferred to the transaction tlock list of
605 * the commiting transaction of the inode)
609 tblk = tid_to_tblock(tid);
611 * The order of the tlocks in the transaction is important
612 * (during truncate, child xtree pages must be freed before
613 * parent's tlocks change the working map).
614 * Take tlock off anonymous list and add to tail of
617 * Note: We really need to get rid of the tid & lid and
618 * use list_head's. This code is getting UGLY!
620 if (jfs_ip->atlhead == lid) {
621 if (jfs_ip->atltail == lid) {
622 /* only anonymous txn.
623 * Remove from anon_list
625 list_del_init(&jfs_ip->anon_inode_list);
627 jfs_ip->atlhead = tlck->next;
630 for (last = jfs_ip->atlhead;
631 lid_to_tlock(last)->next != lid;
632 last = lid_to_tlock(last)->next) {
635 lid_to_tlock(last)->next = tlck->next;
636 if (jfs_ip->atltail == lid)
637 jfs_ip->atltail = last;
640 /* insert the tlock at tail of transaction tlock list */
643 lid_to_tlock(tblk->last)->next = lid;
659 tlck = lid_to_tlock(lid);
666 /* mark tlock for meta-data page */
667 if (mp->xflag & COMMIT_PAGE) {
669 tlck->flag = tlckPAGELOCK;
671 /* mark the page dirty and nohomeok */
672 mark_metapage_dirty(mp);
673 atomic_inc(&mp->nohomeok);
675 jfs_info("locking mp = 0x%p, nohomeok = %d tid = %d tlck = 0x%p",
676 mp, atomic_read(&mp->nohomeok), tid, tlck);
678 /* if anonymous transaction, and buffer is on the group
679 * commit synclist, mark inode to show this. This will
680 * prevent the buffer from being marked nohomeok for too
683 if ((tid == 0) && mp->lsn)
684 set_cflag(COMMIT_Synclist, ip);
686 /* mark tlock for in-memory inode */
688 tlck->flag = tlckINODELOCK;
692 /* bind the tlock and the page */
701 * enqueue transaction lock to transaction/inode
703 /* insert the tlock at tail of transaction tlock list */
705 tblk = tid_to_tblock(tid);
707 lid_to_tlock(tblk->last)->next = lid;
713 /* anonymous transaction:
714 * insert the tlock at head of inode anonymous tlock list
717 tlck->next = jfs_ip->atlhead;
718 jfs_ip->atlhead = lid;
719 if (tlck->next == 0) {
720 /* This inode's first anonymous transaction */
721 jfs_ip->atltail = lid;
722 list_add_tail(&jfs_ip->anon_inode_list,
723 &TxAnchor.anon_list);
727 /* initialize type dependent area for linelock */
728 linelock = (struct linelock *) & tlck->lock;
730 linelock->flag = tlckLINELOCK;
731 linelock->maxcnt = TLOCKSHORT;
734 switch (type & tlckTYPE) {
736 linelock->l2linesize = L2DTSLOTSIZE;
740 linelock->l2linesize = L2XTSLOTSIZE;
742 xtlck = (struct xtlock *) linelock;
743 xtlck->header.offset = 0;
744 xtlck->header.length = 2;
746 if (type & tlckNEW) {
747 xtlck->lwm.offset = XTENTRYSTART;
749 if (mp->xflag & COMMIT_PAGE)
750 p = (xtpage_t *) mp->data;
752 p = &jfs_ip->i_xtroot;
754 le16_to_cpu(p->header.nextindex);
756 xtlck->lwm.length = 0; /* ! */
757 xtlck->twm.offset = 0;
758 xtlck->hwm.offset = 0;
764 linelock->l2linesize = L2INODESLOTSIZE;
768 linelock->l2linesize = L2DATASLOTSIZE;
772 jfs_err("UFO tlock:0x%p", tlck);
776 * update tlock vector
786 * page is being locked by another transaction:
789 /* Only locks on ipimap or ipaimap should reach here */
790 /* assert(jfs_ip->fileset == AGGREGATE_I); */
791 if (jfs_ip->fileset != AGGREGATE_I) {
792 jfs_err("txLock: trying to lock locked page!");
793 dump_mem("ip", ip, sizeof(struct inode));
794 dump_mem("mp", mp, sizeof(struct metapage));
795 dump_mem("Locker's tblk", tid_to_tblock(tid),
796 sizeof(struct tblock));
797 dump_mem("Tlock", tlck, sizeof(struct tlock));
800 INCREMENT(stattx.waitlock); /* statistics */
801 release_metapage(mp);
803 jfs_info("txLock: in waitLock, tid = %d, xtid = %d, lid = %d",
805 TXN_SLEEP_DROP_LOCK(&tid_to_tblock(xtid)->waitor);
806 jfs_info("txLock: awakened tid = %d, lid = %d", tid, lid);
815 * FUNCTION: Release buffers associated with transaction locks, but don't
816 * mark homeok yet. The allows other transactions to modify
817 * buffers, but won't let them go to disk until commit record
818 * actually gets written.
823 * RETURN: Errors from subroutines.
825 static void txRelease(struct tblock * tblk)
833 for (lid = tblk->next; lid; lid = tlck->next) {
834 tlck = lid_to_tlock(lid);
835 if ((mp = tlck->mp) != NULL &&
836 (tlck->type & tlckBTROOT) == 0) {
837 assert(mp->xflag & COMMIT_PAGE);
843 * wakeup transactions waiting on a page locked
844 * by the current transaction
846 TXN_WAKEUP(&tblk->waitor);
855 * FUNCTION: Initiates pageout of pages modified by tid in journalled
856 * objects and frees their lockwords.
858 static void txUnlock(struct tblock * tblk)
861 struct linelock *linelock;
862 lid_t lid, next, llid, k;
867 jfs_info("txUnlock: tblk = 0x%p", tblk);
868 log = JFS_SBI(tblk->sb)->log;
871 * mark page under tlock homeok (its log has been written):
873 for (lid = tblk->next; lid; lid = next) {
874 tlck = lid_to_tlock(lid);
877 jfs_info("unlocking lid = %d, tlck = 0x%p", lid, tlck);
879 /* unbind page from tlock */
880 if ((mp = tlck->mp) != NULL &&
881 (tlck->type & tlckBTROOT) == 0) {
882 assert(mp->xflag & COMMIT_PAGE);
886 * It's possible that someone else has the metapage.
887 * The only things were changing are nohomeok, which
888 * is handled atomically, and clsn which is protected
889 * by the LOGSYNC_LOCK.
891 hold_metapage(mp, 1);
893 assert(atomic_read(&mp->nohomeok) > 0);
894 atomic_dec(&mp->nohomeok);
896 /* inherit younger/larger clsn */
899 logdiff(difft, tblk->clsn, log);
900 logdiff(diffp, mp->clsn, log);
902 mp->clsn = tblk->clsn;
904 mp->clsn = tblk->clsn;
907 assert(!(tlck->flag & tlckFREEPAGE));
909 if (tlck->flag & tlckWRITEPAGE) {
912 /* release page which has been forced */
913 release_metapage(mp);
917 /* insert tlock, and linelock(s) of the tlock if any,
918 * at head of freelist
922 llid = ((struct linelock *) & tlck->lock)->next;
924 linelock = (struct linelock *) lid_to_tlock(llid);
933 tblk->next = tblk->last = 0;
936 * remove tblock from logsynclist
937 * (allocation map pages inherited lsn of tblk and
938 * has been inserted in logsync list at txUpdateMap())
943 list_del(&tblk->synclist);
952 * function: allocate a transaction lock for freed page/entry;
953 * for freed page, maplock is used as xtlock/dtlock type;
955 struct tlock *txMaplock(tid_t tid, struct inode *ip, int type)
957 struct jfs_inode_info *jfs_ip = JFS_IP(ip);
961 struct maplock *maplock;
969 tlck = lid_to_tlock(lid);
976 /* bind the tlock and the object */
977 tlck->flag = tlckINODELOCK;
984 * enqueue transaction lock to transaction/inode
986 /* insert the tlock at tail of transaction tlock list */
988 tblk = tid_to_tblock(tid);
990 lid_to_tlock(tblk->last)->next = lid;
996 /* anonymous transaction:
997 * insert the tlock at head of inode anonymous tlock list
1000 tlck->next = jfs_ip->atlhead;
1001 jfs_ip->atlhead = lid;
1002 if (tlck->next == 0) {
1003 /* This inode's first anonymous transaction */
1004 jfs_ip->atltail = lid;
1005 list_add_tail(&jfs_ip->anon_inode_list,
1006 &TxAnchor.anon_list);
1012 /* initialize type dependent area for maplock */
1013 maplock = (struct maplock *) & tlck->lock;
1015 maplock->maxcnt = 0;
1025 * function: allocate a transaction lock for log vector list
1027 struct linelock *txLinelock(struct linelock * tlock)
1031 struct linelock *linelock;
1035 /* allocate a TxLock structure */
1036 lid = txLockAlloc();
1037 tlck = lid_to_tlock(lid);
1041 /* initialize linelock */
1042 linelock = (struct linelock *) tlck;
1044 linelock->flag = tlckLINELOCK;
1045 linelock->maxcnt = TLOCKLONG;
1046 linelock->index = 0;
1048 /* append linelock after tlock */
1049 linelock->next = tlock->next;
1058 * transaction commit management
1059 * -----------------------------
1065 * FUNCTION: commit the changes to the objects specified in
1066 * clist. For journalled segments only the
1067 * changes of the caller are committed, ie by tid.
1068 * for non-journalled segments the data are flushed to
1069 * disk and then the change to the disk inode and indirect
1070 * blocks committed (so blocks newly allocated to the
1071 * segment will be made a part of the segment atomically).
1073 * all of the segments specified in clist must be in
1074 * one file system. no more than 6 segments are needed
1075 * to handle all unix svcs.
1077 * if the i_nlink field (i.e. disk inode link count)
1078 * is zero, and the type of inode is a regular file or
1079 * directory, or symbolic link , the inode is truncated
1080 * to zero length. the truncation is committed but the
1081 * VM resources are unaffected until it is closed (see
1089 * on entry the inode lock on each segment is assumed
1094 int txCommit(tid_t tid, /* transaction identifier */
1095 int nip, /* number of inodes to commit */
1096 struct inode **iplist, /* list of inode to commit */
1101 struct jfs_log *log;
1102 struct tblock *tblk;
1106 struct jfs_inode_info *jfs_ip;
1109 struct super_block *sb;
1111 jfs_info("txCommit, tid = %d, flag = %d", tid, flag);
1112 /* is read-only file system ? */
1113 if (isReadOnly(iplist[0])) {
1118 sb = cd.sb = iplist[0]->i_sb;
1122 tid = txBegin(sb, 0);
1123 tblk = tid_to_tblock(tid);
1126 * initialize commit structure
1128 log = JFS_SBI(sb)->log;
1131 /* initialize log record descriptor in commit */
1133 lrd->logtid = cpu_to_le32(tblk->logtid);
1136 tblk->xflag |= flag;
1138 if ((flag & (COMMIT_FORCE | COMMIT_SYNC)) == 0)
1139 tblk->xflag |= COMMIT_LAZY;
1141 * prepare non-journaled objects for commit
1143 * flush data pages of non-journaled file
1144 * to prevent the file getting non-initialized disk blocks
1152 * acquire transaction lock on (on-disk) inodes
1154 * update on-disk inode from in-memory inode
1155 * acquiring transaction locks for AFTER records
1156 * on the on-disk inode of file object
1158 * sort the inodes array by inode number in descending order
1159 * to prevent deadlock when acquiring transaction lock
1160 * of on-disk inodes on multiple on-disk inode pages by
1161 * multiple concurrent transactions
1163 for (k = 0; k < cd.nip; k++) {
1164 top = (cd.iplist[k])->i_ino;
1165 for (n = k + 1; n < cd.nip; n++) {
1167 if (ip->i_ino > top) {
1169 cd.iplist[n] = cd.iplist[k];
1175 jfs_ip = JFS_IP(ip);
1177 if (test_and_clear_cflag(COMMIT_Syncdata, ip) &&
1178 ((tblk->flag & COMMIT_DELETE) == 0))
1179 fsync_inode_data_buffers(ip);
1182 * Mark inode as not dirty. It will still be on the dirty
1183 * inode list, but we'll know not to commit it again unless
1184 * it gets marked dirty again
1186 clear_cflag(COMMIT_Dirty, ip);
1188 /* inherit anonymous tlock(s) of inode */
1189 if (jfs_ip->atlhead) {
1190 lid_to_tlock(jfs_ip->atltail)->next = tblk->next;
1191 tblk->next = jfs_ip->atlhead;
1193 tblk->last = jfs_ip->atltail;
1194 jfs_ip->atlhead = jfs_ip->atltail = 0;
1196 list_del_init(&jfs_ip->anon_inode_list);
1201 * acquire transaction lock on on-disk inode page
1202 * (become first tlock of the tblk's tlock list)
1204 if (((rc = diWrite(tid, ip))))
1209 * write log records from transaction locks
1211 * txUpdateMap() resets XAD_NEW in XAD.
1213 if ((rc = txLog(log, tblk, &cd)))
1217 * Ensure that inode isn't reused before
1218 * lazy commit thread finishes processing
1220 if (tblk->xflag & (COMMIT_CREATE | COMMIT_DELETE)) {
1221 atomic_inc(&tblk->ip->i_count);
1223 * Avoid a rare deadlock
1225 * If the inode is locked, we may be blocked in
1226 * jfs_commit_inode. If so, we don't want the
1227 * lazy_commit thread doing the last iput() on the inode
1228 * since that may block on the locked inode. Instead,
1229 * commit the transaction synchronously, so the last iput
1230 * will be done by the calling thread (or later)
1232 if (tblk->ip->i_state & I_LOCK)
1233 tblk->xflag &= ~COMMIT_LAZY;
1236 ASSERT((!(tblk->xflag & COMMIT_DELETE)) ||
1237 ((tblk->ip->i_nlink == 0) &&
1238 !test_cflag(COMMIT_Nolink, tblk->ip)));
1241 * write COMMIT log record
1243 lrd->type = cpu_to_le16(LOG_COMMIT);
1245 lsn = lmLog(log, tblk, lrd, NULL);
1247 lmGroupCommit(log, tblk);
1250 * - transaction is now committed -
1254 * force pages in careful update
1255 * (imap addressing structure update)
1257 if (flag & COMMIT_FORCE)
1261 * update allocation map.
1263 * update inode allocation map and inode:
1264 * free pager lock on memory object of inode if any.
1265 * update block allocation map.
1267 * txUpdateMap() resets XAD_NEW in XAD.
1269 if (tblk->xflag & COMMIT_FORCE)
1273 * free transaction locks and pageout/free pages
1277 if ((tblk->flag & tblkGC_LAZY) == 0)
1282 * reset in-memory object state
1284 for (k = 0; k < cd.nip; k++) {
1286 jfs_ip = JFS_IP(ip);
1289 * reset in-memory inode state
1300 jfs_info("txCommit: tid = %d, returning %d", tid, rc);
1308 * FUNCTION: Writes AFTER log records for all lines modified
1309 * by tid for segments specified by inodes in comdata.
1310 * Code assumes only WRITELOCKS are recorded in lockwords.
1316 static int txLog(struct jfs_log * log, struct tblock * tblk, struct commit * cd)
1322 struct lrd *lrd = &cd->lrd;
1325 * write log record(s) for each tlock of transaction,
1327 for (lid = tblk->next; lid; lid = tlck->next) {
1328 tlck = lid_to_tlock(lid);
1330 tlck->flag |= tlckLOG;
1332 /* initialize lrd common */
1334 lrd->aggregate = cpu_to_le32(kdev_t_to_nr(ip->i_dev));
1335 lrd->log.redopage.fileset = cpu_to_le32(JFS_IP(ip)->fileset);
1336 lrd->log.redopage.inode = cpu_to_le32(ip->i_ino);
1338 /* write log record of page from the tlock */
1339 switch (tlck->type & tlckTYPE) {
1341 xtLog(log, tblk, lrd, tlck);
1345 dtLog(log, tblk, lrd, tlck);
1349 diLog(log, tblk, lrd, tlck, cd);
1353 mapLog(log, tblk, lrd, tlck);
1357 dataLog(log, tblk, lrd, tlck);
1361 jfs_err("UFO tlock:0x%p", tlck);
1372 * function: log inode tlock and format maplock to update bmap;
1374 static int diLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
1375 struct tlock * tlck, struct commit * cd)
1378 struct metapage *mp;
1380 struct pxd_lock *pxdlock;
1384 /* initialize as REDOPAGE record format */
1385 lrd->log.redopage.type = cpu_to_le16(LOG_INODE);
1386 lrd->log.redopage.l2linesize = cpu_to_le16(L2INODESLOTSIZE);
1388 pxd = &lrd->log.redopage.pxd;
1393 if (tlck->type & tlckENTRY) {
1394 /* log after-image for logredo(): */
1395 lrd->type = cpu_to_le16(LOG_REDOPAGE);
1396 // *pxd = mp->cm_pxd;
1397 PXDaddress(pxd, mp->index);
1399 mp->logical_size >> tblk->sb->s_blocksize_bits);
1400 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1402 /* mark page as homeward bound */
1403 tlck->flag |= tlckWRITEPAGE;
1404 } else if (tlck->type & tlckFREE) {
1408 * (pages of the freed inode extent have been invalidated and
1409 * a maplock for free of the extent has been formatted at
1412 * the tlock had been acquired on the inode allocation map page
1413 * (iag) that specifies the freed extent, even though the map
1414 * page is not itself logged, to prevent pageout of the map
1415 * page before the log;
1418 /* log LOG_NOREDOINOEXT of the freed inode extent for
1419 * logredo() to start NoRedoPage filters, and to update
1420 * imap and bmap for free of the extent;
1422 lrd->type = cpu_to_le16(LOG_NOREDOINOEXT);
1424 * For the LOG_NOREDOINOEXT record, we need
1425 * to pass the IAG number and inode extent
1426 * index (within that IAG) from which the
1427 * the extent being released. These have been
1428 * passed to us in the iplist[1] and iplist[2].
1430 lrd->log.noredoinoext.iagnum =
1431 cpu_to_le32((u32) (size_t) cd->iplist[1]);
1432 lrd->log.noredoinoext.inoext_idx =
1433 cpu_to_le32((u32) (size_t) cd->iplist[2]);
1435 pxdlock = (struct pxd_lock *) & tlck->lock;
1436 *pxd = pxdlock->pxd;
1437 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
1440 tlck->flag |= tlckUPDATEMAP;
1442 /* mark page as homeward bound */
1443 tlck->flag |= tlckWRITEPAGE;
1445 jfs_err("diLog: UFO type tlck:0x%p", tlck);
1448 * alloc/free external EA extent
1450 * a maplock for txUpdateMap() to update bPWMAP for alloc/free
1451 * of the extent has been formatted at txLock() time;
1454 assert(tlck->type & tlckEA);
1456 /* log LOG_UPDATEMAP for logredo() to update bmap for
1457 * alloc of new (and free of old) external EA extent;
1459 lrd->type = cpu_to_le16(LOG_UPDATEMAP);
1460 pxdlock = (struct pxd_lock *) & tlck->lock;
1461 nlock = pxdlock->index;
1462 for (i = 0; i < nlock; i++, pxdlock++) {
1463 if (pxdlock->flag & mlckALLOCPXD)
1464 lrd->log.updatemap.type =
1465 cpu_to_le16(LOG_ALLOCPXD);
1467 lrd->log.updatemap.type =
1468 cpu_to_le16(LOG_FREEPXD);
1469 lrd->log.updatemap.nxd = cpu_to_le16(1);
1470 lrd->log.updatemap.pxd = pxdlock->pxd;
1472 cpu_to_le32(lmLog(log, tblk, lrd, NULL));
1476 tlck->flag |= tlckUPDATEMAP;
1478 #endif /* _JFS_WIP */
1487 * function: log data tlock
1489 static int dataLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
1490 struct tlock * tlck)
1492 struct metapage *mp;
1497 /* initialize as REDOPAGE record format */
1498 lrd->log.redopage.type = cpu_to_le16(LOG_DATA);
1499 lrd->log.redopage.l2linesize = cpu_to_le16(L2DATASLOTSIZE);
1501 pxd = &lrd->log.redopage.pxd;
1503 /* log after-image for logredo(): */
1504 lrd->type = cpu_to_le16(LOG_REDOPAGE);
1506 if (JFS_IP(tlck->ip)->next_index < MAX_INLINE_DIRTABLE_ENTRY) {
1508 * The table has been truncated, we've must have deleted
1509 * the last entry, so don't bother logging this
1512 hold_metapage(mp, 0);
1513 atomic_dec(&mp->nohomeok);
1514 discard_metapage(mp);
1519 PXDaddress(pxd, mp->index);
1520 PXDlength(pxd, mp->logical_size >> tblk->sb->s_blocksize_bits);
1522 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1524 /* mark page as homeward bound */
1525 tlck->flag |= tlckWRITEPAGE;
1534 * function: log dtree tlock and format maplock to update bmap;
1536 static void dtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
1537 struct tlock * tlck)
1539 struct metapage *mp;
1540 struct pxd_lock *pxdlock;
1545 /* initialize as REDOPAGE/NOREDOPAGE record format */
1546 lrd->log.redopage.type = cpu_to_le16(LOG_DTREE);
1547 lrd->log.redopage.l2linesize = cpu_to_le16(L2DTSLOTSIZE);
1549 pxd = &lrd->log.redopage.pxd;
1551 if (tlck->type & tlckBTROOT)
1552 lrd->log.redopage.type |= cpu_to_le16(LOG_BTROOT);
1555 * page extension via relocation: entry insertion;
1556 * page extension in-place: entry insertion;
1557 * new right page from page split, reinitialized in-line
1558 * root from root page split: entry insertion;
1560 if (tlck->type & (tlckNEW | tlckEXTEND)) {
1561 /* log after-image of the new page for logredo():
1562 * mark log (LOG_NEW) for logredo() to initialize
1563 * freelist and update bmap for alloc of the new page;
1565 lrd->type = cpu_to_le16(LOG_REDOPAGE);
1566 if (tlck->type & tlckEXTEND)
1567 lrd->log.redopage.type |= cpu_to_le16(LOG_EXTEND);
1569 lrd->log.redopage.type |= cpu_to_le16(LOG_NEW);
1570 // *pxd = mp->cm_pxd;
1571 PXDaddress(pxd, mp->index);
1573 mp->logical_size >> tblk->sb->s_blocksize_bits);
1574 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1576 /* format a maplock for txUpdateMap() to update bPMAP for
1577 * alloc of the new page;
1579 if (tlck->type & tlckBTROOT)
1581 tlck->flag |= tlckUPDATEMAP;
1582 pxdlock = (struct pxd_lock *) & tlck->lock;
1583 pxdlock->flag = mlckALLOCPXD;
1584 pxdlock->pxd = *pxd;
1588 /* mark page as homeward bound */
1589 tlck->flag |= tlckWRITEPAGE;
1594 * entry insertion/deletion,
1595 * sibling page link update (old right page before split);
1597 if (tlck->type & (tlckENTRY | tlckRELINK)) {
1598 /* log after-image for logredo(): */
1599 lrd->type = cpu_to_le16(LOG_REDOPAGE);
1600 PXDaddress(pxd, mp->index);
1602 mp->logical_size >> tblk->sb->s_blocksize_bits);
1603 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1605 /* mark page as homeward bound */
1606 tlck->flag |= tlckWRITEPAGE;
1611 * page deletion: page has been invalidated
1612 * page relocation: source extent
1614 * a maplock for free of the page has been formatted
1615 * at txLock() time);
1617 if (tlck->type & (tlckFREE | tlckRELOCATE)) {
1618 /* log LOG_NOREDOPAGE of the deleted page for logredo()
1619 * to start NoRedoPage filter and to update bmap for free
1620 * of the deletd page
1622 lrd->type = cpu_to_le16(LOG_NOREDOPAGE);
1623 pxdlock = (struct pxd_lock *) & tlck->lock;
1624 *pxd = pxdlock->pxd;
1625 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
1627 /* a maplock for txUpdateMap() for free of the page
1628 * has been formatted at txLock() time;
1630 tlck->flag |= tlckUPDATEMAP;
1639 * function: log xtree tlock and format maplock to update bmap;
1641 static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
1642 struct tlock * tlck)
1645 struct metapage *mp;
1647 struct xtlock *xtlck;
1648 struct maplock *maplock;
1649 struct xdlistlock *xadlock;
1650 struct pxd_lock *pxdlock;
1657 /* initialize as REDOPAGE/NOREDOPAGE record format */
1658 lrd->log.redopage.type = cpu_to_le16(LOG_XTREE);
1659 lrd->log.redopage.l2linesize = cpu_to_le16(L2XTSLOTSIZE);
1661 pxd = &lrd->log.redopage.pxd;
1663 if (tlck->type & tlckBTROOT) {
1664 lrd->log.redopage.type |= cpu_to_le16(LOG_BTROOT);
1665 p = &JFS_IP(ip)->i_xtroot;
1666 if (S_ISDIR(ip->i_mode))
1667 lrd->log.redopage.type |=
1668 cpu_to_le16(LOG_DIR_XTREE);
1670 p = (xtpage_t *) mp->data;
1671 next = le16_to_cpu(p->header.nextindex);
1673 xtlck = (struct xtlock *) & tlck->lock;
1675 maplock = (struct maplock *) & tlck->lock;
1676 xadlock = (struct xdlistlock *) maplock;
1679 * entry insertion/extension;
1680 * sibling page link update (old right page before split);
1682 if (tlck->type & (tlckNEW | tlckGROW | tlckRELINK)) {
1683 /* log after-image for logredo():
1684 * logredo() will update bmap for alloc of new/extended
1685 * extents (XAD_NEW|XAD_EXTEND) of XAD[lwm:next) from
1686 * after-image of XADlist;
1687 * logredo() resets (XAD_NEW|XAD_EXTEND) flag when
1688 * applying the after-image to the meta-data page.
1690 lrd->type = cpu_to_le16(LOG_REDOPAGE);
1691 // *pxd = mp->cm_pxd;
1692 PXDaddress(pxd, mp->index);
1694 mp->logical_size >> tblk->sb->s_blocksize_bits);
1695 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1697 /* format a maplock for txUpdateMap() to update bPMAP
1698 * for alloc of new/extended extents of XAD[lwm:next)
1699 * from the page itself;
1700 * txUpdateMap() resets (XAD_NEW|XAD_EXTEND) flag.
1702 lwm = xtlck->lwm.offset;
1704 lwm = XTPAGEMAXSLOT;
1709 jfs_err("xtLog: lwm > next\n");
1712 tlck->flag |= tlckUPDATEMAP;
1713 xadlock->flag = mlckALLOCXADLIST;
1714 xadlock->count = next - lwm;
1715 if ((xadlock->count <= 2) && (tblk->xflag & COMMIT_LAZY)) {
1718 * Lazy commit may allow xtree to be modified before
1719 * txUpdateMap runs. Copy xad into linelock to
1720 * preserve correct data.
1722 xadlock->xdlist = &xtlck->pxdlock;
1723 memcpy(xadlock->xdlist, &p->xad[lwm],
1724 sizeof(xad_t) * xadlock->count);
1726 for (i = 0; i < xadlock->count; i++)
1727 p->xad[lwm + i].flag &=
1728 ~(XAD_NEW | XAD_EXTENDED);
1731 * xdlist will point to into inode's xtree, ensure
1732 * that transaction is not committed lazily.
1734 xadlock->xdlist = &p->xad[lwm];
1735 tblk->xflag &= ~COMMIT_LAZY;
1737 jfs_info("xtLog: alloc ip:0x%p mp:0x%p tlck:0x%p lwm:%d "
1738 "count:%d", tlck->ip, mp, tlck, lwm, xadlock->count);
1743 /* mark page as homeward bound */
1744 tlck->flag |= tlckWRITEPAGE;
1750 * page deletion: file deletion/truncation (ref. xtTruncate())
1752 * (page will be invalidated after log is written and bmap
1753 * is updated from the page);
1755 if (tlck->type & tlckFREE) {
1756 /* LOG_NOREDOPAGE log for NoRedoPage filter:
1757 * if page free from file delete, NoRedoFile filter from
1758 * inode image of zero link count will subsume NoRedoPage
1759 * filters for each page;
1760 * if page free from file truncattion, write NoRedoPage
1763 * upadte of block allocation map for the page itself:
1764 * if page free from deletion and truncation, LOG_UPDATEMAP
1765 * log for the page itself is generated from processing
1766 * its parent page xad entries;
1768 /* if page free from file truncation, log LOG_NOREDOPAGE
1769 * of the deleted page for logredo() to start NoRedoPage
1770 * filter for the page;
1772 if (tblk->xflag & COMMIT_TRUNCATE) {
1773 /* write NOREDOPAGE for the page */
1774 lrd->type = cpu_to_le16(LOG_NOREDOPAGE);
1775 PXDaddress(pxd, mp->index);
1777 mp->logical_size >> tblk->sb->
1780 cpu_to_le32(lmLog(log, tblk, lrd, NULL));
1782 if (tlck->type & tlckBTROOT) {
1783 /* Empty xtree must be logged */
1784 lrd->type = cpu_to_le16(LOG_REDOPAGE);
1786 cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1790 /* init LOG_UPDATEMAP of the freed extents
1791 * XAD[XTENTRYSTART:hwm) from the deleted page itself
1792 * for logredo() to update bmap;
1794 lrd->type = cpu_to_le16(LOG_UPDATEMAP);
1795 lrd->log.updatemap.type = cpu_to_le16(LOG_FREEXADLIST);
1796 xtlck = (struct xtlock *) & tlck->lock;
1797 hwm = xtlck->hwm.offset;
1798 lrd->log.updatemap.nxd =
1799 cpu_to_le16(hwm - XTENTRYSTART + 1);
1800 /* reformat linelock for lmLog() */
1801 xtlck->header.offset = XTENTRYSTART;
1802 xtlck->header.length = hwm - XTENTRYSTART + 1;
1804 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1806 /* format a maplock for txUpdateMap() to update bmap
1807 * to free extents of XAD[XTENTRYSTART:hwm) from the
1808 * deleted page itself;
1810 tlck->flag |= tlckUPDATEMAP;
1811 xadlock->flag = mlckFREEXADLIST;
1812 xadlock->count = hwm - XTENTRYSTART + 1;
1813 if ((xadlock->count <= 2) && (tblk->xflag & COMMIT_LAZY)) {
1815 * Lazy commit may allow xtree to be modified before
1816 * txUpdateMap runs. Copy xad into linelock to
1817 * preserve correct data.
1819 xadlock->xdlist = &xtlck->pxdlock;
1820 memcpy(xadlock->xdlist, &p->xad[XTENTRYSTART],
1821 sizeof(xad_t) * xadlock->count);
1824 * xdlist will point to into inode's xtree, ensure
1825 * that transaction is not committed lazily.
1827 xadlock->xdlist = &p->xad[XTENTRYSTART];
1828 tblk->xflag &= ~COMMIT_LAZY;
1830 jfs_info("xtLog: free ip:0x%p mp:0x%p count:%d lwm:2",
1831 tlck->ip, mp, xadlock->count);
1835 /* mark page as invalid */
1836 if (((tblk->xflag & COMMIT_PWMAP) || S_ISDIR(ip->i_mode))
1837 && !(tlck->type & tlckBTROOT))
1838 tlck->flag |= tlckFREEPAGE;
1840 else (tblk->xflag & COMMIT_PMAP)
1847 * page/entry truncation: file truncation (ref. xtTruncate())
1849 * |----------+------+------+---------------|
1851 * | | hwm - hwm before truncation
1852 * | next - truncation point
1853 * lwm - lwm before truncation
1856 if (tlck->type & tlckTRUNCATE) {
1857 pxd_t tpxd; /* truncated extent of xad */
1861 * For truncation the entire linelock may be used, so it would
1862 * be difficult to store xad list in linelock itself.
1863 * Therefore, we'll just force transaction to be committed
1864 * synchronously, so that xtree pages won't be changed before
1867 tblk->xflag &= ~COMMIT_LAZY;
1868 lwm = xtlck->lwm.offset;
1870 lwm = XTPAGEMAXSLOT;
1871 hwm = xtlck->hwm.offset;
1872 twm = xtlck->twm.offset;
1877 /* log after-image for logredo():
1879 * logredo() will update bmap for alloc of new/extended
1880 * extents (XAD_NEW|XAD_EXTEND) of XAD[lwm:next) from
1881 * after-image of XADlist;
1882 * logredo() resets (XAD_NEW|XAD_EXTEND) flag when
1883 * applying the after-image to the meta-data page.
1885 lrd->type = cpu_to_le16(LOG_REDOPAGE);
1886 PXDaddress(pxd, mp->index);
1887 PXDlength(pxd, mp->logical_size >> tblk->sb->s_blocksize_bits);
1888 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1891 * truncate entry XAD[twm == next - 1]:
1893 if (twm == next - 1) {
1894 /* init LOG_UPDATEMAP for logredo() to update bmap for
1895 * free of truncated delta extent of the truncated
1896 * entry XAD[next - 1]:
1897 * (xtlck->pxdlock = truncated delta extent);
1899 pxdlock = (struct pxd_lock *) & xtlck->pxdlock;
1900 /* assert(pxdlock->type & tlckTRUNCATE); */
1901 lrd->type = cpu_to_le16(LOG_UPDATEMAP);
1902 lrd->log.updatemap.type = cpu_to_le16(LOG_FREEPXD);
1903 lrd->log.updatemap.nxd = cpu_to_le16(1);
1904 lrd->log.updatemap.pxd = pxdlock->pxd;
1905 tpxd = pxdlock->pxd; /* save to format maplock */
1907 cpu_to_le32(lmLog(log, tblk, lrd, NULL));
1911 * free entries XAD[next:hwm]:
1914 /* init LOG_UPDATEMAP of the freed extents
1915 * XAD[next:hwm] from the deleted page itself
1916 * for logredo() to update bmap;
1918 lrd->type = cpu_to_le16(LOG_UPDATEMAP);
1919 lrd->log.updatemap.type =
1920 cpu_to_le16(LOG_FREEXADLIST);
1921 xtlck = (struct xtlock *) & tlck->lock;
1922 hwm = xtlck->hwm.offset;
1923 lrd->log.updatemap.nxd =
1924 cpu_to_le16(hwm - next + 1);
1925 /* reformat linelock for lmLog() */
1926 xtlck->header.offset = next;
1927 xtlck->header.length = hwm - next + 1;
1930 cpu_to_le32(lmLog(log, tblk, lrd, tlck));
1934 * format maplock(s) for txUpdateMap() to update bmap
1939 * allocate entries XAD[lwm:next):
1942 /* format a maplock for txUpdateMap() to update bPMAP
1943 * for alloc of new/extended extents of XAD[lwm:next)
1944 * from the page itself;
1945 * txUpdateMap() resets (XAD_NEW|XAD_EXTEND) flag.
1947 tlck->flag |= tlckUPDATEMAP;
1948 xadlock->flag = mlckALLOCXADLIST;
1949 xadlock->count = next - lwm;
1950 xadlock->xdlist = &p->xad[lwm];
1952 jfs_info("xtLog: alloc ip:0x%p mp:0x%p count:%d "
1954 tlck->ip, mp, xadlock->count, lwm, next);
1960 * truncate entry XAD[twm == next - 1]:
1962 if (twm == next - 1) {
1963 struct pxd_lock *pxdlock;
1965 /* format a maplock for txUpdateMap() to update bmap
1966 * to free truncated delta extent of the truncated
1967 * entry XAD[next - 1];
1968 * (xtlck->pxdlock = truncated delta extent);
1970 tlck->flag |= tlckUPDATEMAP;
1971 pxdlock = (struct pxd_lock *) xadlock;
1972 pxdlock->flag = mlckFREEPXD;
1974 pxdlock->pxd = tpxd;
1976 jfs_info("xtLog: truncate ip:0x%p mp:0x%p count:%d "
1977 "hwm:%d", ip, mp, pxdlock->count, hwm);
1983 * free entries XAD[next:hwm]:
1986 /* format a maplock for txUpdateMap() to update bmap
1987 * to free extents of XAD[next:hwm] from thedeleted
1990 tlck->flag |= tlckUPDATEMAP;
1991 xadlock->flag = mlckFREEXADLIST;
1992 xadlock->count = hwm - next + 1;
1993 xadlock->xdlist = &p->xad[next];
1995 jfs_info("xtLog: free ip:0x%p mp:0x%p count:%d "
1997 tlck->ip, mp, xadlock->count, next, hwm);
2001 /* mark page as homeward bound */
2002 tlck->flag |= tlckWRITEPAGE;
2011 * function: log from maplock of freed data extents;
2013 void mapLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
2014 struct tlock * tlck)
2016 struct pxd_lock *pxdlock;
2021 * page relocation: free the source page extent
2023 * a maplock for txUpdateMap() for free of the page
2024 * has been formatted at txLock() time saving the src
2025 * relocated page address;
2027 if (tlck->type & tlckRELOCATE) {
2028 /* log LOG_NOREDOPAGE of the old relocated page
2029 * for logredo() to start NoRedoPage filter;
2031 lrd->type = cpu_to_le16(LOG_NOREDOPAGE);
2032 pxdlock = (struct pxd_lock *) & tlck->lock;
2033 pxd = &lrd->log.redopage.pxd;
2034 *pxd = pxdlock->pxd;
2035 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
2037 /* (N.B. currently, logredo() does NOT update bmap
2038 * for free of the page itself for (LOG_XTREE|LOG_NOREDOPAGE);
2039 * if page free from relocation, LOG_UPDATEMAP log is
2040 * specifically generated now for logredo()
2041 * to update bmap for free of src relocated page;
2042 * (new flag LOG_RELOCATE may be introduced which will
2043 * inform logredo() to start NORedoPage filter and also
2044 * update block allocation map at the same time, thus
2045 * avoiding an extra log write);
2047 lrd->type = cpu_to_le16(LOG_UPDATEMAP);
2048 lrd->log.updatemap.type = cpu_to_le16(LOG_FREEPXD);
2049 lrd->log.updatemap.nxd = cpu_to_le16(1);
2050 lrd->log.updatemap.pxd = pxdlock->pxd;
2051 lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
2053 /* a maplock for txUpdateMap() for free of the page
2054 * has been formatted at txLock() time;
2056 tlck->flag |= tlckUPDATEMAP;
2061 * Otherwise it's not a relocate request
2065 /* log LOG_UPDATEMAP for logredo() to update bmap for
2066 * free of truncated/relocated delta extent of the data;
2067 * e.g.: external EA extent, relocated/truncated extent
2068 * from xtTailgate();
2070 lrd->type = cpu_to_le16(LOG_UPDATEMAP);
2071 pxdlock = (struct pxd_lock *) & tlck->lock;
2072 nlock = pxdlock->index;
2073 for (i = 0; i < nlock; i++, pxdlock++) {
2074 if (pxdlock->flag & mlckALLOCPXD)
2075 lrd->log.updatemap.type =
2076 cpu_to_le16(LOG_ALLOCPXD);
2078 lrd->log.updatemap.type =
2079 cpu_to_le16(LOG_FREEPXD);
2080 lrd->log.updatemap.nxd = cpu_to_le16(1);
2081 lrd->log.updatemap.pxd = pxdlock->pxd;
2083 cpu_to_le32(lmLog(log, tblk, lrd, NULL));
2084 jfs_info("mapLog: xaddr:0x%lx xlen:0x%x",
2085 (ulong) addressPXD(&pxdlock->pxd),
2086 lengthPXD(&pxdlock->pxd));
2090 tlck->flag |= tlckUPDATEMAP;
2098 * function: acquire maplock for EA/ACL extents or
2099 * set COMMIT_INLINE flag;
2101 void txEA(tid_t tid, struct inode *ip, dxd_t * oldea, dxd_t * newea)
2103 struct tlock *tlck = NULL;
2104 struct pxd_lock *maplock = NULL, *pxdlock = NULL;
2107 * format maplock for alloc of new EA extent
2110 /* Since the newea could be a completely zeroed entry we need to
2111 * check for the two flags which indicate we should actually
2112 * commit new EA data
2114 if (newea->flag & DXD_EXTENT) {
2115 tlck = txMaplock(tid, ip, tlckMAP);
2116 maplock = (struct pxd_lock *) & tlck->lock;
2117 pxdlock = (struct pxd_lock *) maplock;
2118 pxdlock->flag = mlckALLOCPXD;
2119 PXDaddress(&pxdlock->pxd, addressDXD(newea));
2120 PXDlength(&pxdlock->pxd, lengthDXD(newea));
2123 } else if (newea->flag & DXD_INLINE) {
2126 set_cflag(COMMIT_Inlineea, ip);
2131 * format maplock for free of old EA extent
2133 if (!test_cflag(COMMIT_Nolink, ip) && oldea->flag & DXD_EXTENT) {
2135 tlck = txMaplock(tid, ip, tlckMAP);
2136 maplock = (struct pxd_lock *) & tlck->lock;
2137 pxdlock = (struct pxd_lock *) maplock;
2140 pxdlock->flag = mlckFREEPXD;
2141 PXDaddress(&pxdlock->pxd, addressDXD(oldea));
2142 PXDlength(&pxdlock->pxd, lengthDXD(oldea));
2151 * function: synchronously write pages locked by transaction
2152 * after txLog() but before txUpdateMap();
2154 void txForce(struct tblock * tblk)
2158 struct metapage *mp;
2161 * reverse the order of transaction tlocks in
2162 * careful update order of address index pages
2163 * (right to left, bottom up)
2165 tlck = lid_to_tlock(tblk->next);
2169 tlck = lid_to_tlock(lid);
2171 tlck->next = tblk->next;
2177 * synchronously write the page, and
2178 * hold the page for txUpdateMap();
2180 for (lid = tblk->next; lid; lid = next) {
2181 tlck = lid_to_tlock(lid);
2184 if ((mp = tlck->mp) != NULL &&
2185 (tlck->type & tlckBTROOT) == 0) {
2186 assert(mp->xflag & COMMIT_PAGE);
2188 if (tlck->flag & tlckWRITEPAGE) {
2189 tlck->flag &= ~tlckWRITEPAGE;
2191 /* do not release page to freelist */
2194 * The "right" thing to do here is to
2195 * synchronously write the metadata.
2196 * With the current implementation this
2197 * is hard since write_metapage requires
2198 * us to kunmap & remap the page. If we
2199 * have tlocks pointing into the metadata
2200 * pages, we don't want to do this. I think
2201 * we can get by with synchronously writing
2202 * the pages when they are released.
2204 assert(atomic_read(&mp->nohomeok));
2205 set_bit(META_dirty, &mp->flag);
2206 set_bit(META_sync, &mp->flag);
2216 * function: update persistent allocation map (and working map
2221 static void txUpdateMap(struct tblock * tblk)
2224 struct inode *ipimap;
2227 struct maplock *maplock;
2228 struct pxd_lock pxdlock;
2231 struct metapage *mp = 0;
2233 ipimap = JFS_SBI(tblk->sb)->ipimap;
2235 maptype = (tblk->xflag & COMMIT_PMAP) ? COMMIT_PMAP : COMMIT_PWMAP;
2239 * update block allocation map
2241 * update allocation state in pmap (and wmap) and
2242 * update lsn of the pmap page;
2245 * scan each tlock/page of transaction for block allocation/free:
2247 * for each tlock/page of transaction, update map.
2248 * ? are there tlock for pmap and pwmap at the same time ?
2250 for (lid = tblk->next; lid; lid = tlck->next) {
2251 tlck = lid_to_tlock(lid);
2253 if ((tlck->flag & tlckUPDATEMAP) == 0)
2256 if (tlck->flag & tlckFREEPAGE) {
2258 * Another thread may attempt to reuse freed space
2259 * immediately, so we want to get rid of the metapage
2260 * before anyone else has a chance to get it.
2261 * Lock metapage, update maps, then invalidate
2265 ASSERT(mp->xflag & COMMIT_PAGE);
2266 hold_metapage(mp, 0);
2271 * . in-line PXD list:
2272 * . out-of-line XAD list:
2274 maplock = (struct maplock *) & tlck->lock;
2275 nlock = maplock->index;
2277 for (k = 0; k < nlock; k++, maplock++) {
2279 * allocate blocks in persistent map:
2281 * blocks have been allocated from wmap at alloc time;
2283 if (maplock->flag & mlckALLOC) {
2284 txAllocPMap(ipimap, maplock, tblk);
2287 * free blocks in persistent and working map:
2288 * blocks will be freed in pmap and then in wmap;
2290 * ? tblock specifies the PMAP/PWMAP based upon
2293 * free blocks in persistent map:
2294 * blocks will be freed from wmap at last reference
2295 * release of the object for regular files;
2297 * Alway free blocks from both persistent & working
2298 * maps for directories
2300 else { /* (maplock->flag & mlckFREE) */
2302 if (S_ISDIR(tlck->ip->i_mode))
2303 txFreeMap(ipimap, maplock,
2304 tblk, COMMIT_PWMAP);
2306 txFreeMap(ipimap, maplock,
2310 if (tlck->flag & tlckFREEPAGE) {
2311 if (!(tblk->flag & tblkGC_LAZY)) {
2312 /* This is equivalent to txRelease */
2313 ASSERT(mp->lid == lid);
2316 assert(atomic_read(&mp->nohomeok) == 1);
2317 atomic_dec(&mp->nohomeok);
2318 discard_metapage(mp);
2323 * update inode allocation map
2325 * update allocation state in pmap and
2326 * update lsn of the pmap page;
2327 * update in-memory inode flag/state
2329 * unlock mapper/write lock
2331 if (tblk->xflag & COMMIT_CREATE) {
2334 ASSERT(test_cflag(COMMIT_New, ip));
2335 clear_cflag(COMMIT_New, ip);
2337 diUpdatePMap(ipimap, ip->i_ino, FALSE, tblk);
2338 ipimap->i_state |= I_DIRTY;
2339 /* update persistent block allocation map
2340 * for the allocation of inode extent;
2342 pxdlock.flag = mlckALLOCPXD;
2343 pxdlock.pxd = JFS_IP(ip)->ixpxd;
2345 txAllocPMap(ip, (struct maplock *) & pxdlock, tblk);
2347 } else if (tblk->xflag & COMMIT_DELETE) {
2349 diUpdatePMap(ipimap, ip->i_ino, TRUE, tblk);
2350 ipimap->i_state |= I_DIRTY;
2359 * function: allocate from persistent map;
2368 * allocate from persistent map;
2369 * free from persistent map;
2370 * (e.g., tmp file - free from working map at releae
2371 * of last reference);
2372 * free from persistent and working map;
2374 * lsn - log sequence number;
2376 static void txAllocPMap(struct inode *ip, struct maplock * maplock,
2377 struct tblock * tblk)
2379 struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap;
2380 struct xdlistlock *xadlistlock;
2384 struct pxd_lock *pxdlock;
2385 struct xdlistlock *pxdlistlock;
2390 * allocate from persistent map;
2392 if (maplock->flag & mlckALLOCXADLIST) {
2393 xadlistlock = (struct xdlistlock *) maplock;
2394 xad = xadlistlock->xdlist;
2395 for (n = 0; n < xadlistlock->count; n++, xad++) {
2396 if (xad->flag & (XAD_NEW | XAD_EXTENDED)) {
2397 xaddr = addressXAD(xad);
2398 xlen = lengthXAD(xad);
2399 dbUpdatePMap(ipbmap, FALSE, xaddr,
2401 xad->flag &= ~(XAD_NEW | XAD_EXTENDED);
2402 jfs_info("allocPMap: xaddr:0x%lx xlen:%d",
2403 (ulong) xaddr, xlen);
2406 } else if (maplock->flag & mlckALLOCPXD) {
2407 pxdlock = (struct pxd_lock *) maplock;
2408 xaddr = addressPXD(&pxdlock->pxd);
2409 xlen = lengthPXD(&pxdlock->pxd);
2410 dbUpdatePMap(ipbmap, FALSE, xaddr, (s64) xlen, tblk);
2411 jfs_info("allocPMap: xaddr:0x%lx xlen:%d", (ulong) xaddr, xlen);
2412 } else { /* (maplock->flag & mlckALLOCPXDLIST) */
2414 pxdlistlock = (struct xdlistlock *) maplock;
2415 pxd = pxdlistlock->xdlist;
2416 for (n = 0; n < pxdlistlock->count; n++, pxd++) {
2417 xaddr = addressPXD(pxd);
2418 xlen = lengthPXD(pxd);
2419 dbUpdatePMap(ipbmap, FALSE, xaddr, (s64) xlen,
2421 jfs_info("allocPMap: xaddr:0x%lx xlen:%d",
2422 (ulong) xaddr, xlen);
2431 * function: free from persistent and/or working map;
2433 * todo: optimization
2435 void txFreeMap(struct inode *ip,
2436 struct maplock * maplock, struct tblock * tblk, int maptype)
2438 struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap;
2439 struct xdlistlock *xadlistlock;
2443 struct pxd_lock *pxdlock;
2444 struct xdlistlock *pxdlistlock;
2448 jfs_info("txFreeMap: tblk:0x%p maplock:0x%p maptype:0x%x",
2449 tblk, maplock, maptype);
2452 * free from persistent map;
2454 if (maptype == COMMIT_PMAP || maptype == COMMIT_PWMAP) {
2455 if (maplock->flag & mlckFREEXADLIST) {
2456 xadlistlock = (struct xdlistlock *) maplock;
2457 xad = xadlistlock->xdlist;
2458 for (n = 0; n < xadlistlock->count; n++, xad++) {
2459 if (!(xad->flag & XAD_NEW)) {
2460 xaddr = addressXAD(xad);
2461 xlen = lengthXAD(xad);
2462 dbUpdatePMap(ipbmap, TRUE, xaddr,
2464 jfs_info("freePMap: xaddr:0x%lx "
2466 (ulong) xaddr, xlen);
2469 } else if (maplock->flag & mlckFREEPXD) {
2470 pxdlock = (struct pxd_lock *) maplock;
2471 xaddr = addressPXD(&pxdlock->pxd);
2472 xlen = lengthPXD(&pxdlock->pxd);
2473 dbUpdatePMap(ipbmap, TRUE, xaddr, (s64) xlen,
2475 jfs_info("freePMap: xaddr:0x%lx xlen:%d",
2476 (ulong) xaddr, xlen);
2477 } else { /* (maplock->flag & mlckALLOCPXDLIST) */
2479 pxdlistlock = (struct xdlistlock *) maplock;
2480 pxd = pxdlistlock->xdlist;
2481 for (n = 0; n < pxdlistlock->count; n++, pxd++) {
2482 xaddr = addressPXD(pxd);
2483 xlen = lengthPXD(pxd);
2484 dbUpdatePMap(ipbmap, TRUE, xaddr,
2486 jfs_info("freePMap: xaddr:0x%lx xlen:%d",
2487 (ulong) xaddr, xlen);
2493 * free from working map;
2495 if (maptype == COMMIT_PWMAP || maptype == COMMIT_WMAP) {
2496 if (maplock->flag & mlckFREEXADLIST) {
2497 xadlistlock = (struct xdlistlock *) maplock;
2498 xad = xadlistlock->xdlist;
2499 for (n = 0; n < xadlistlock->count; n++, xad++) {
2500 xaddr = addressXAD(xad);
2501 xlen = lengthXAD(xad);
2502 dbFree(ip, xaddr, (s64) xlen);
2504 jfs_info("freeWMap: xaddr:0x%lx xlen:%d",
2505 (ulong) xaddr, xlen);
2507 } else if (maplock->flag & mlckFREEPXD) {
2508 pxdlock = (struct pxd_lock *) maplock;
2509 xaddr = addressPXD(&pxdlock->pxd);
2510 xlen = lengthPXD(&pxdlock->pxd);
2511 dbFree(ip, xaddr, (s64) xlen);
2512 jfs_info("freeWMap: xaddr:0x%lx xlen:%d",
2513 (ulong) xaddr, xlen);
2514 } else { /* (maplock->flag & mlckFREEPXDLIST) */
2516 pxdlistlock = (struct xdlistlock *) maplock;
2517 pxd = pxdlistlock->xdlist;
2518 for (n = 0; n < pxdlistlock->count; n++, pxd++) {
2519 xaddr = addressPXD(pxd);
2520 xlen = lengthPXD(pxd);
2521 dbFree(ip, xaddr, (s64) xlen);
2522 jfs_info("freeWMap: xaddr:0x%lx xlen:%d",
2523 (ulong) xaddr, xlen);
2533 * function: remove tlock from inode anonymous locklist
2535 void txFreelock(struct inode *ip)
2537 struct jfs_inode_info *jfs_ip = JFS_IP(ip);
2538 struct tlock *xtlck, *tlck;
2539 lid_t xlid = 0, lid;
2541 if (!jfs_ip->atlhead)
2544 xtlck = (struct tlock *) &jfs_ip->atlhead;
2546 while ((lid = xtlck->next)) {
2547 tlck = lid_to_tlock(lid);
2548 if (tlck->flag & tlckFREELOCK) {
2549 xtlck->next = tlck->next;
2557 if (jfs_ip->atlhead)
2558 jfs_ip->atltail = xlid;
2560 jfs_ip->atltail = 0;
2562 * If inode was on anon_list, remove it
2565 list_del_init(&jfs_ip->anon_inode_list);
2574 * function: abort tx before commit;
2576 * frees line-locks and segment locks for all
2577 * segments in comdata structure.
2578 * Optionally sets state of file-system to FM_DIRTY in super-block.
2579 * log age of page-frames in memory for which caller has
2580 * are reset to 0 (to avoid logwarap).
2582 void txAbort(tid_t tid, int dirty)
2585 struct metapage *mp;
2586 struct tblock *tblk = tid_to_tblock(tid);
2589 jfs_warn("txAbort: tid:%d dirty:0x%x", tid, dirty);
2592 * free tlocks of the transaction
2594 for (lid = tblk->next; lid; lid = next) {
2595 tlck = lid_to_tlock(lid);
2598 JFS_IP(tlck->ip)->xtlid = 0;
2604 * reset lsn of page to avoid logwarap:
2606 * (page may have been previously committed by another
2607 * transaction(s) but has not been paged, i.e.,
2608 * it may be on logsync list even though it has not
2609 * been logged for the current tx.)
2611 if (mp->xflag & COMMIT_PAGE && mp->lsn)
2614 /* insert tlock at head of freelist */
2620 /* caller will free the transaction block */
2622 tblk->next = tblk->last = 0;
2625 * mark filesystem dirty
2628 jfs_error(tblk->sb, "txAbort");
2634 * txLazyCommit(void)
2636 * All transactions except those changing ipimap (COMMIT_FORCE) are
2637 * processed by this routine. This insures that the inode and block
2638 * allocation maps are updated in order. For synchronous transactions,
2639 * let the user thread finish processing after txUpdateMap() is called.
2641 static void txLazyCommit(struct tblock * tblk)
2643 struct jfs_log *log;
2645 while (((tblk->flag & tblkGC_READY) == 0) &&
2646 ((tblk->flag & tblkGC_UNLOCKED) == 0)) {
2647 /* We must have gotten ahead of the user thread
2649 jfs_info("txLazyCommit: tblk 0x%p not unlocked", tblk);
2653 jfs_info("txLazyCommit: processing tblk 0x%p", tblk);
2657 log = (struct jfs_log *) JFS_SBI(tblk->sb)->log;
2659 spin_lock_irq(&log->gclock); // LOGGC_LOCK
2661 tblk->flag |= tblkGC_COMMITTED;
2663 if (tblk->flag & tblkGC_READY)
2666 wake_up_all(&tblk->gcwait); // LOGGC_WAKEUP
2669 * Can't release log->gclock until we've tested tblk->flag
2671 if (tblk->flag & tblkGC_LAZY) {
2672 spin_unlock_irq(&log->gclock); // LOGGC_UNLOCK
2674 tblk->flag &= ~tblkGC_LAZY;
2675 txEnd(tblk - TxBlock); /* Convert back to tid */
2677 spin_unlock_irq(&log->gclock); // LOGGC_UNLOCK
2679 jfs_info("txLazyCommit: done: tblk = 0x%p", tblk);
2683 * jfs_lazycommit(void)
2685 * To be run as a kernel daemon. If lbmIODone is called in an interrupt
2686 * context, or where blocking is not wanted, this routine will process
2687 * committed transactions from the unlock queue.
2689 int jfs_lazycommit(void *arg)
2692 struct tblock *tblk;
2693 unsigned long flags;
2698 current->tty = NULL;
2699 strcpy(current->comm, "jfsCommit");
2703 jfsCommitTask = current;
2705 spin_lock_irq(¤t->sigmask_lock);
2706 sigfillset(¤t->blocked);
2707 recalc_sigpending(current);
2708 spin_unlock_irq(¤t->sigmask_lock);
2711 TxAnchor.unlock_queue = TxAnchor.unlock_tail = 0;
2713 complete(&jfsIOwait);
2716 DECLARE_WAITQUEUE(wq, current);
2721 while ((tblk = TxAnchor.unlock_queue)) {
2723 * We can't get ahead of user thread. Spinning is
2724 * simpler than blocking/waking. We shouldn't spin
2725 * very long, since user thread shouldn't be blocking
2726 * between lmGroupCommit & txEnd.
2731 * Remove first transaction from queue
2733 TxAnchor.unlock_queue = tblk->cqnext;
2735 if (TxAnchor.unlock_tail == tblk)
2736 TxAnchor.unlock_tail = 0;
2742 * We can be running indefinately if other processors
2743 * are adding transactions to this list
2752 add_wait_queue(&jfs_commit_thread_wait, &wq);
2753 set_current_state(TASK_INTERRUPTIBLE);
2756 current->state = TASK_RUNNING;
2757 remove_wait_queue(&jfs_commit_thread_wait, &wq);
2758 } while (!jfs_stop_threads);
2760 if (TxAnchor.unlock_queue)
2761 jfs_err("jfs_lazycommit being killed w/pending transactions!");
2763 jfs_info("jfs_lazycommit being killed\n");
2764 complete_and_exit(&jfsIOwait, 0);
2767 void txLazyUnlock(struct tblock * tblk)
2769 unsigned long flags;
2773 if (TxAnchor.unlock_tail)
2774 TxAnchor.unlock_tail->cqnext = tblk;
2776 TxAnchor.unlock_queue = tblk;
2777 TxAnchor.unlock_tail = tblk;
2780 wake_up(&jfs_commit_thread_wait);
2783 static void LogSyncRelease(struct metapage * mp)
2785 struct jfs_log *log = mp->log;
2787 assert(atomic_read(&mp->nohomeok));
2789 atomic_dec(&mp->nohomeok);
2791 if (atomic_read(&mp->nohomeok))
2794 hold_metapage(mp, 0);
2801 list_del_init(&mp->synclist);
2802 LOGSYNC_UNLOCK(log);
2804 release_metapage(mp);
2810 * Block all new transactions and push anonymous transactions to
2813 * This does almost the same thing as jfs_sync below. We don't
2814 * worry about deadlocking when TlocksLow is set, since we would
2815 * expect jfs_sync to get us out of that jam.
2817 void txQuiesce(struct super_block *sb)
2820 struct jfs_inode_info *jfs_ip;
2821 struct jfs_log *log = JFS_SBI(sb)->log;
2824 set_bit(log_QUIESCE, &log->flag);
2828 while (!list_empty(&TxAnchor.anon_list)) {
2829 jfs_ip = list_entry(TxAnchor.anon_list.next,
2830 struct jfs_inode_info,
2835 * inode will be removed from anonymous list
2836 * when it is committed
2839 tid = txBegin(ip->i_sb, COMMIT_INODE | COMMIT_FORCE);
2840 down(&jfs_ip->commit_sem);
2841 txCommit(tid, 1, &ip, 0);
2843 up(&jfs_ip->commit_sem);
2845 * Just to be safe. I don't know how
2846 * long we can run without blocking
2853 * If jfs_sync is running in parallel, there could be some inodes
2854 * on anon_list2. Let's check.
2856 if (!list_empty(&TxAnchor.anon_list2)) {
2857 list_splice(&TxAnchor.anon_list2, &TxAnchor.anon_list);
2858 INIT_LIST_HEAD(&TxAnchor.anon_list2);
2864 * We may need to kick off the group commit
2866 jfs_flush_journal(log, 0);
2872 * Allows transactions to start again following txQuiesce
2874 void txResume(struct super_block *sb)
2876 struct jfs_log *log = JFS_SBI(sb)->log;
2878 clear_bit(log_QUIESCE, &log->flag);
2879 TXN_WAKEUP(&log->syncwait);
2885 * To be run as a kernel daemon. This is awakened when tlocks run low.
2886 * We write any inodes that have anonymous tlocks so they will become
2889 int jfs_sync(void *arg)
2892 struct jfs_inode_info *jfs_ip;
2899 current->tty = NULL;
2900 strcpy(current->comm, "jfsSync");
2904 spin_lock_irq(¤t->sigmask_lock);
2905 sigfillset(¤t->blocked);
2906 recalc_sigpending(current);
2907 spin_unlock_irq(¤t->sigmask_lock);
2909 complete(&jfsIOwait);
2912 DECLARE_WAITQUEUE(wq, current);
2914 * write each inode on the anonymous inode list
2917 while (TxAnchor.TlocksLow && !list_empty(&TxAnchor.anon_list)) {
2918 jfs_ip = list_entry(TxAnchor.anon_list.next,
2919 struct jfs_inode_info,
2925 * Inode is being freed
2927 list_del_init(&jfs_ip->anon_inode_list);
2928 } else if (! down_trylock(&jfs_ip->commit_sem)) {
2930 * inode will be removed from anonymous list
2931 * when it is committed
2934 tid = txBegin(ip->i_sb, COMMIT_INODE);
2935 rc = txCommit(tid, 1, &ip, 0);
2937 up(&jfs_ip->commit_sem);
2941 * Just to be safe. I don't know how
2942 * long we can run without blocking
2947 /* We can't get the commit semaphore. It may
2948 * be held by a thread waiting for tlock's
2949 * so let's not block here. Save it to
2950 * put back on the anon_list.
2953 /* Take off anon_list */
2954 list_del(&jfs_ip->anon_inode_list);
2956 /* Put on anon_list2 */
2957 list_add(&jfs_ip->anon_inode_list,
2958 &TxAnchor.anon_list2);
2965 /* Add anon_list2 back to anon_list */
2966 if (!list_empty(&TxAnchor.anon_list2)) {
2967 list_splice(&TxAnchor.anon_list2, &TxAnchor.anon_list);
2968 INIT_LIST_HEAD(&TxAnchor.anon_list2);
2970 add_wait_queue(&jfs_sync_thread_wait, &wq);
2971 set_current_state(TASK_INTERRUPTIBLE);
2974 current->state = TASK_RUNNING;
2975 remove_wait_queue(&jfs_sync_thread_wait, &wq);
2976 } while (!jfs_stop_threads);
2978 jfs_info("jfs_sync being killed");
2979 complete_and_exit(&jfsIOwait, 0);
2982 #if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_DEBUG)
2983 int jfs_txanchor_read(char *buffer, char **start, off_t offset, int length,
2984 int *eof, void *data)
2993 waitqueue_active(&TxAnchor.freewait) ? "active" : "empty";
2995 waitqueue_active(&TxAnchor.freelockwait) ? "active" : "empty";
2997 waitqueue_active(&TxAnchor.lowlockwait) ? "active" : "empty";
2999 len += sprintf(buffer,
3005 "freelockwait = %s\n"
3006 "lowlockwait = %s\n"
3007 "tlocksInUse = %d\n"
3009 "unlock_queue = 0x%p\n"
3010 "unlock_tail = 0x%p\n",
3016 TxAnchor.tlocksInUse,
3018 TxAnchor.unlock_queue,
3019 TxAnchor.unlock_tail);
3022 *start = buffer + begin;
3037 #if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_STATISTICS)
3038 int jfs_txstats_read(char *buffer, char **start, off_t offset, int length,
3039 int *eof, void *data)
3044 len += sprintf(buffer,
3047 "calls to txBegin = %d\n"
3048 "txBegin blocked by sync barrier = %d\n"
3049 "txBegin blocked by tlocks low = %d\n"
3050 "txBegin blocked by no free tid = %d\n"
3051 "calls to txBeginAnon = %d\n"
3052 "txBeginAnon blocked by sync barrier = %d\n"
3053 "txBeginAnon blocked by tlocks low = %d\n"
3054 "calls to txLockAlloc = %d\n"
3055 "tLockAlloc blocked by no free lock = %d\n",
3057 TxStat.txBegin_barrier,
3058 TxStat.txBegin_lockslow,
3059 TxStat.txBegin_freetid,
3061 TxStat.txBeginAnon_barrier,
3062 TxStat.txBeginAnon_lockslow,
3064 TxStat.txLockAlloc_freelock);
3067 *start = buffer + begin;