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 <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"
59 #include "jfs_superblock.h"
60 #include "jfs_debug.h"
63 * transaction management structures
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 */
80 int jfs_tlocks_low
; /* Indicates low number of available tlocks */
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 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
);
139 current
->state
= TASK_RUNNING
;
140 remove_wait_queue(event
, &wait
);
143 #define TXN_SLEEP(event)\
145 TXN_SLEEP_DROP_LOCK(event);\
149 #define TXN_WAKEUP(event) wake_up_all(event)
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 */
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
;
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
,
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)
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");
221 wake_up(&jfs_sync_thread_wait
);
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");
235 TXN_WAKEUP(&TxAnchor
.lowlockwait
);
237 TXN_WAKEUP(&TxAnchor
.freelockwait
);
243 * FUNCTION: initialize transaction management structures
247 * serialization: single thread at jfs_init()
253 /* Verify tunable parameters */
255 nTxBlock
= 16; /* No one should set it this low */
256 if (nTxBlock
> 65536)
259 nTxLock
= 256; /* No one should set it this low */
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
);
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
);
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
) {
304 /* initialize tlock table */
305 for (k
= 1; k
< nTxLock
- 1; k
++)
306 TxLock
[k
].next
= k
+ 1;
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
);
317 INIT_LIST_HEAD(&TxAnchor
.unlock_queue
);
319 stattx
.maxlid
= 1; /* statistics */
327 * FUNCTION: clean up when module is unloaded
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
)
357 jfs_info("txBegin: flag = 0x%x", flag
);
358 log
= JFS_SBI(sb
)->log
;
362 INCREMENT(TxStat
.txBegin
);
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
);
378 * Don't begin transaction if we're getting starved for tlocks
379 * unless COMMIT_FORCE or COMMIT_INODE (which may ultimately
382 if (TxAnchor
.tlocksInUse
> TxLockVHWM
) {
383 INCREMENT(TxStat
.txBegin_lockslow
);
384 TXN_SLEEP(&TxAnchor
.lowlockwait
);
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
);
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
);
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;
425 tblk
->logtid
= log
->logtid
;
429 HIGHWATERMARK(stattx
.maxtid
, t
); /* statistics */
430 INCREMENT(stattx
.ntid
); /* statistics */
434 jfs_info("txBegin: returning tid = %d", 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
451 void txBeginAnon(struct super_block
*sb
)
455 log
= JFS_SBI(sb
)->log
;
458 INCREMENT(TxStat
.txBeginAnon
);
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
);
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
);
486 * function: free specified transaction block.
488 * logsync barrier processing:
492 void txEnd(tid_t tid
)
494 struct tblock
*tblk
= tid_to_tblock(tid
);
497 jfs_info("txEnd: tid = %d", tid
);
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
513 * Lazy commit thread will turn off tblkGC_LAZY before calling this
516 if (tblk
->flag
& tblkGC_LAZY
) {
517 jfs_info("txEnd called w/lazy tid: %d, tblk = 0x%p", tid
, tblk
);
520 spin_lock_irq(&log
->gclock
); // LOGGC_LOCK
521 tblk
->flag
|= tblkGC_UNLOCKED
;
522 spin_unlock_irq(&log
->gclock
); // LOGGC_UNLOCK
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 */
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
);
571 * function: acquire a transaction lock on the specified <mp>
575 * return: transaction lock id
579 struct tlock
*txLock(tid_t tid
, struct inode
*ip
, struct metapage
* mp
,
582 struct jfs_inode_info
*jfs_ip
= JFS_IP(ip
);
587 struct xtlock
*xtlck
;
588 struct linelock
*linelock
;
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.
605 /* is page not locked by a transaction ? */
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
)
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)
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
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
;
650 for (last
= jfs_ip
->atlhead
;
651 lid_to_tlock(last
)->next
!= lid
;
652 last
= lid_to_tlock(last
)->next
) {
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 */
663 lid_to_tlock(tblk
->last
)->next
= lid
;
679 tlck
= lid_to_tlock(lid
);
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
703 if ((tid
== 0) && mp
->lsn
)
704 set_cflag(COMMIT_Synclist
, ip
);
706 /* mark tlock for in-memory inode */
708 tlck
->flag
= tlckINODELOCK
;
712 /* bind the tlock and the page */
721 * enqueue transaction lock to transaction/inode
723 /* insert the tlock at tail of transaction tlock list */
725 tblk
= tid_to_tblock(tid
);
727 lid_to_tlock(tblk
->last
)->next
= lid
;
733 /* anonymous transaction:
734 * insert the tlock at head of inode anonymous tlock list
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
;
750 linelock
->flag
= tlckLINELOCK
;
751 linelock
->maxcnt
= TLOCKSHORT
;
754 switch (type
& tlckTYPE
) {
756 linelock
->l2linesize
= L2DTSLOTSIZE
;
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
;
769 if (mp
->xflag
& COMMIT_PAGE
)
770 p
= (xtpage_t
*) mp
->data
;
772 p
= &jfs_ip
->i_xtroot
;
774 le16_to_cpu(p
->header
.nextindex
);
776 xtlck
->lwm
.length
= 0; /* ! */
777 xtlck
->twm
.offset
= 0;
778 xtlck
->hwm
.offset
= 0;
784 linelock
->l2linesize
= L2INODESLOTSIZE
;
788 linelock
->l2linesize
= L2DATASLOTSIZE
;
792 jfs_err("UFO tlock:0x%p", tlck
);
796 * update tlock vector
806 * page is being locked by another transaction:
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
));
820 INCREMENT(stattx
.waitlock
); /* statistics */
821 release_metapage(mp
);
823 jfs_info("txLock: in waitLock, tid = %d, xtid = %d, lid = %d",
825 TXN_SLEEP_DROP_LOCK(&tid_to_tblock(xtid
)->waitor
);
826 jfs_info("txLock: awakened tid = %d, lid = %d", tid
, lid
);
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.
843 * RETURN: Errors from subroutines.
845 static void txRelease(struct tblock
* tblk
)
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
);
863 * wakeup transactions waiting on a page locked
864 * by the current transaction
866 TXN_WAKEUP(&tblk
->waitor
);
875 * FUNCTION: Initiates pageout of pages modified by tid in journalled
876 * objects and frees their lockwords.
878 static void txUnlock(struct tblock
* tblk
)
881 struct linelock
*linelock
;
882 lid_t lid
, next
, llid
, k
;
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
);
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
);
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 */
919 logdiff(difft
, tblk
->clsn
, log
);
920 logdiff(diffp
, mp
->clsn
, log
);
922 mp
->clsn
= tblk
->clsn
;
924 mp
->clsn
= tblk
->clsn
;
927 assert(!(tlck
->flag
& tlckFREEPAGE
));
929 if (tlck
->flag
& tlckWRITEPAGE
) {
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
942 llid
= ((struct linelock
*) & tlck
->lock
)->next
;
944 linelock
= (struct linelock
*) lid_to_tlock(llid
);
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())
963 list_del(&tblk
->synclist
);
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
);
981 struct maplock
*maplock
;
989 tlck
= lid_to_tlock(lid
);
996 /* bind the tlock and the object */
997 tlck
->flag
= tlckINODELOCK
;
1004 * enqueue transaction lock to transaction/inode
1006 /* insert the tlock at tail of transaction tlock list */
1008 tblk
= tid_to_tblock(tid
);
1010 lid_to_tlock(tblk
->last
)->next
= lid
;
1016 /* anonymous transaction:
1017 * insert the tlock at head of inode anonymous tlock list
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
);
1032 /* initialize type dependent area for maplock */
1033 maplock
= (struct maplock
*) & tlck
->lock
;
1035 maplock
->maxcnt
= 0;
1045 * function: allocate a transaction lock for log vector list
1047 struct linelock
*txLinelock(struct linelock
* tlock
)
1051 struct linelock
*linelock
;
1055 /* allocate a TxLock structure */
1056 lid
= txLockAlloc();
1057 tlck
= lid_to_tlock(lid
);
1061 /* initialize linelock */
1062 linelock
= (struct linelock
*) tlck
;
1064 linelock
->flag
= tlckLINELOCK
;
1065 linelock
->maxcnt
= TLOCKLONG
;
1066 linelock
->index
= 0;
1068 /* append linelock after tlock */
1069 linelock
->next
= tlock
->next
;
1078 * transaction commit management
1079 * -----------------------------
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
1109 * on entry the inode lock on each segment is assumed
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 */
1121 struct jfs_log
*log
;
1122 struct tblock
*tblk
;
1126 struct jfs_inode_info
*jfs_ip
;
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])) {
1138 sb
= cd
.sb
= iplist
[0]->i_sb
;
1142 tid
= txBegin(sb
, 0);
1143 tblk
= tid_to_tblock(tid
);
1146 * initialize commit structure
1148 log
= JFS_SBI(sb
)->log
;
1151 /* initialize log record descriptor in commit */
1153 lrd
->logtid
= cpu_to_le32(tblk
->logtid
);
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
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
++) {
1187 if (ip
->i_ino
> top
) {
1189 cd
.iplist
[n
] = 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
;
1234 tblk
->last
= jfs_ip
->atltail
;
1235 jfs_ip
->atlhead
= jfs_ip
->atltail
= 0;
1237 list_del_init(&jfs_ip
->anon_inode_list
);
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
))))
1250 * write log records from transaction locks
1252 * txUpdateMap() resets XAD_NEW in XAD.
1254 if ((rc
= txLog(log
, tblk
, &cd
)))
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
);
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
)
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
)
1314 * free transaction locks and pageout/free pages
1318 if ((tblk
->flag
& tblkGC_LAZY
) == 0)
1323 * reset in-memory object state
1325 for (k
= 0; k
< cd
.nip
; k
++) {
1327 jfs_ip
= JFS_IP(ip
);
1330 * reset in-memory inode state
1341 jfs_info("txCommit: tid = %d, returning %d", tid
, rc
);
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.
1357 static int txLog(struct jfs_log
* log
, struct tblock
* tblk
, struct commit
* cd
)
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 */
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
) {
1382 xtLog(log
, tblk
, lrd
, tlck
);
1386 dtLog(log
, tblk
, lrd
, tlck
);
1390 diLog(log
, tblk
, lrd
, tlck
, cd
);
1394 mapLog(log
, tblk
, lrd
, tlck
);
1398 dataLog(log
, tblk
, lrd
, tlck
);
1402 jfs_err("UFO tlock:0x%p", tlck
);
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
)
1419 struct metapage
*mp
;
1421 struct pxd_lock
*pxdlock
;
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
;
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
);
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
) {
1449 * (pages of the freed inode extent have been invalidated and
1450 * a maplock for free of the extent has been formatted at
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
));
1481 tlck
->flag
|= tlckUPDATEMAP
;
1483 /* mark page as homeward bound */
1484 tlck
->flag
|= tlckWRITEPAGE
;
1486 jfs_err("diLog: UFO type tlck:0x%p", tlck
);
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;
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
);
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
;
1513 cpu_to_le32(lmLog(log
, tblk
, lrd
, NULL
));
1517 tlck
->flag
|= tlckUPDATEMAP
;
1519 #endif /* _JFS_WIP */
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
;
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
1553 hold_metapage(mp
, 0);
1554 atomic_dec(&mp
->nohomeok
);
1555 discard_metapage(mp
);
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
;
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
;
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
);
1610 lrd
->log
.redopage
.type
|= cpu_to_le16(LOG_NEW
);
1611 // *pxd = mp->cm_pxd;
1612 PXDaddress(pxd
, mp
->index
);
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
)
1622 tlck
->flag
|= tlckUPDATEMAP
;
1623 pxdlock
= (struct pxd_lock
*) & tlck
->lock
;
1624 pxdlock
->flag
= mlckALLOCPXD
;
1625 pxdlock
->pxd
= *pxd
;
1629 /* mark page as homeward bound */
1630 tlck
->flag
|= tlckWRITEPAGE
;
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
);
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
;
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
;
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
)
1686 struct metapage
*mp
;
1688 struct xtlock
*xtlck
;
1689 struct maplock
*maplock
;
1690 struct xdlistlock
*xadlock
;
1691 struct pxd_lock
*pxdlock
;
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
);
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
);
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
;
1745 lwm
= XTPAGEMAXSLOT
;
1750 jfs_err("xtLog: lwm > next\n");
1753 tlck
->flag
|= tlckUPDATEMAP
;
1754 xadlock
->flag
= mlckALLOCXADLIST
;
1755 xadlock
->count
= next
- lwm
;
1756 if ((xadlock
->count
<= 2) && (tblk
->xflag
& COMMIT_LAZY
)) {
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
);
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
);
1784 /* mark page as homeward bound */
1785 tlck
->flag
|= tlckWRITEPAGE
;
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
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
);
1818 mp
->logical_size
>> tblk
->sb
->
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
);
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;
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
);
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
);
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)
1888 * page/entry truncation: file truncation (ref. xtTruncate())
1890 * |----------+------+------+---------------|
1892 * | | hwm - hwm before truncation
1893 * | next - truncation point
1894 * lwm - lwm before truncation
1897 if (tlck
->type
& tlckTRUNCATE
) {
1898 pxd_t tpxd
; /* truncated extent of xad */
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
1908 tblk
->xflag
&= ~COMMIT_LAZY
;
1909 lwm
= xtlck
->lwm
.offset
;
1911 lwm
= XTPAGEMAXSLOT
;
1912 hwm
= xtlck
->hwm
.offset
;
1913 twm
= xtlck
->twm
.offset
;
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 */
1948 cpu_to_le32(lmLog(log
, tblk
, lrd
, NULL
));
1952 * free entries XAD[next:hwm]:
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;
1971 cpu_to_le32(lmLog(log
, tblk
, lrd
, tlck
));
1975 * format maplock(s) for txUpdateMap() to update bmap
1980 * allocate entries XAD[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 "
1995 tlck
->ip
, mp
, xadlock
->count
, lwm
, next
);
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
;
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
);
2024 * free entries XAD[next:hwm]:
2027 /* format a maplock for txUpdateMap() to update bmap
2028 * to free extents of XAD[next:hwm] from thedeleted
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 "
2038 tlck
->ip
, mp
, xadlock
->count
, next
, hwm
);
2042 /* mark page as homeward bound */
2043 tlck
->flag
|= tlckWRITEPAGE
;
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
;
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
;
2102 * Otherwise it's not a relocate request
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
);
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
;
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
));
2131 tlck
->flag
|= tlckUPDATEMAP
;
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
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
));
2164 } else if (newea
->flag
& DXD_INLINE
) {
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
) {
2176 tlck
= txMaplock(tid
, ip
, tlckMAP
);
2177 maplock
= (struct pxd_lock
*) & tlck
->lock
;
2178 pxdlock
= (struct pxd_lock
*) maplock
;
2181 pxdlock
->flag
= mlckFREEPXD
;
2182 PXDaddress(&pxdlock
->pxd
, addressDXD(oldea
));
2183 PXDlength(&pxdlock
->pxd
, lengthDXD(oldea
));
2192 * function: synchronously write pages locked by transaction
2193 * after txLog() but before txUpdateMap();
2195 void txForce(struct tblock
* tblk
)
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
);
2210 tlck
= lid_to_tlock(lid
);
2212 tlck
->next
= tblk
->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
);
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
);
2257 * function: update persistent allocation map (and working map
2262 static void txUpdateMap(struct tblock
* tblk
)
2265 struct inode
*ipimap
;
2268 struct maplock
*maplock
;
2269 struct pxd_lock pxdlock
;
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)
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
2306 ASSERT(mp
->xflag
& COMMIT_PAGE
);
2307 hold_metapage(mp
, 0);
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
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
);
2347 txFreeMap(ipimap
, maplock
,
2351 if (tlck
->flag
& tlckFREEPAGE
) {
2352 if (!(tblk
->flag
& tblkGC_LAZY
)) {
2353 /* This is equivalent to txRelease */
2354 ASSERT(mp
->lid
== lid
);
2357 assert(atomic_read(&mp
->nohomeok
) == 1);
2358 atomic_dec(&mp
->nohomeok
);
2359 discard_metapage(mp
);
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
;
2381 txAllocPMap(ipimap
, (struct maplock
*) & pxdlock
, tblk
);
2382 } else if (tblk
->xflag
& COMMIT_DELETE
) {
2384 diUpdatePMap(ipimap
, ip
->i_ino
, TRUE
, tblk
);
2385 ipimap
->i_state
|= I_DIRTY
;
2394 * function: allocate from persistent map;
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
;
2419 struct pxd_lock
*pxdlock
;
2420 struct xdlistlock
*pxdlistlock
;
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
,
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
,
2456 jfs_info("allocPMap: xaddr:0x%lx xlen:%d",
2457 (ulong
) xaddr
, xlen
);
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
;
2478 struct pxd_lock
*pxdlock
;
2479 struct xdlistlock
*pxdlistlock
;
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
,
2499 jfs_info("freePMap: xaddr:0x%lx "
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
,
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
,
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
);
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
);
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
)
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
;
2593 if (jfs_ip
->atlhead
)
2594 jfs_ip
->atltail
= xlid
;
2596 jfs_ip
->atltail
= 0;
2598 * If inode was on anon_list, remove it
2600 list_del_init(&jfs_ip
->anon_inode_list
);
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
)
2620 struct metapage
*mp
;
2621 struct tblock
*tblk
= tid_to_tblock(tid
);
2625 * free tlocks of the transaction
2627 for (lid
= tblk
->next
; lid
; lid
= next
) {
2628 tlck
= lid_to_tlock(lid
);
2631 JFS_IP(tlck
->ip
)->xtlid
= 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
)
2647 /* insert tlock at head of freelist */
2653 /* caller will free the transaction block */
2655 tblk
->next
= tblk
->last
= 0;
2658 * mark filesystem dirty
2661 jfs_error(tblk
->sb
, "txAbort");
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
);
2686 jfs_info("txLazyCommit: processing tblk 0x%p", 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
)
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
2707 tblk
->flag
&= ~tblkGC_LAZY
;
2708 txEnd(tblk
- TxBlock
); /* Convert back to tid */
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
)
2725 struct tblock
*tblk
;
2726 unsigned long flags
;
2727 struct jfs_sb_info
*sbi
;
2729 daemonize("jfsCommit");
2731 complete(&jfsIOwait
);
2735 while (!list_empty(&TxAnchor
.unlock_queue
)) {
2737 list_for_each_entry(tblk
, &TxAnchor
.unlock_queue
,
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,
2747 if (sbi
->commit_state
& IN_LAZYCOMMIT
)
2750 sbi
->commit_state
|= IN_LAZYCOMMIT
;
2754 * Remove transaction from queue
2756 list_del(&tblk
->cqueue
);
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.
2771 /* If there was nothing to do, don't continue */
2776 if (current
->flags
& PF_FREEZE
) {
2778 refrigerator(PF_FREEZE
);
2780 DECLARE_WAITQUEUE(wq
, current
);
2782 add_wait_queue(&jfs_commit_thread_wait
, &wq
);
2783 set_current_state(TASK_INTERRUPTIBLE
);
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!");
2794 jfs_info("jfs_lazycommit being killed\n");
2795 complete_and_exit(&jfsIOwait
, 0);
2798 void txLazyUnlock(struct tblock
* tblk
)
2800 unsigned long flags
;
2804 list_add_tail(&tblk
->cqueue
, &TxAnchor
.unlock_queue
);
2806 * Don't wake up a commit thread if there is already one servicing
2809 if (!(JFS_SBI(tblk
->sb
)->commit_state
& IN_LAZYCOMMIT
))
2810 wake_up(&jfs_commit_thread_wait
);
2814 static void LogSyncRelease(struct metapage
* mp
)
2816 struct jfs_log
*log
= mp
->log
;
2818 assert(atomic_read(&mp
->nohomeok
));
2820 atomic_dec(&mp
->nohomeok
);
2822 if (atomic_read(&mp
->nohomeok
))
2825 hold_metapage(mp
, 0);
2832 list_del_init(&mp
->synclist
);
2833 LOGSYNC_UNLOCK(log
);
2835 release_metapage(mp
);
2841 * Block all new transactions and push anonymous transactions to
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
)
2851 struct jfs_inode_info
*jfs_ip
;
2852 struct jfs_log
*log
= JFS_SBI(sb
)->log
;
2855 set_bit(log_QUIESCE
, &log
->flag
);
2859 while (!list_empty(&TxAnchor
.anon_list
)) {
2860 jfs_ip
= list_entry(TxAnchor
.anon_list
.next
,
2861 struct jfs_inode_info
,
2863 ip
= &jfs_ip
->vfs_inode
;
2866 * inode will be removed from anonymous list
2867 * when it is committed
2870 tid
= txBegin(ip
->i_sb
, COMMIT_INODE
| COMMIT_FORCE
);
2871 down(&jfs_ip
->commit_sem
);
2872 txCommit(tid
, 1, &ip
, 0);
2874 up(&jfs_ip
->commit_sem
);
2876 * Just to be safe. I don't know how
2877 * long we can run without blocking
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
);
2895 * We may need to kick off the group commit
2897 jfs_flush_journal(log
, 0);
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
);
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
2920 int jfs_sync(void *arg
)
2923 struct jfs_inode_info
*jfs_ip
;
2927 daemonize("jfsSync");
2929 complete(&jfsIOwait
);
2933 * write each inode on the anonymous inode list
2936 while (jfs_tlocks_low
&& !list_empty(&TxAnchor
.anon_list
)) {
2937 jfs_ip
= list_entry(TxAnchor
.anon_list
.next
,
2938 struct jfs_inode_info
,
2940 ip
= &jfs_ip
->vfs_inode
;
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
2953 tid
= txBegin(ip
->i_sb
, COMMIT_INODE
);
2954 rc
= txCommit(tid
, 1, &ip
, 0);
2956 up(&jfs_ip
->commit_sem
);
2960 * Just to be safe. I don't know how
2961 * long we can run without blocking
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
);
2984 /* Add anon_list2 back to anon_list */
2985 list_splice_init(&TxAnchor
.anon_list2
, &TxAnchor
.anon_list
);
2987 if (current
->flags
& PF_FREEZE
) {
2989 refrigerator(PF_FREEZE
);
2991 DECLARE_WAITQUEUE(wq
, current
);
2993 add_wait_queue(&jfs_sync_thread_wait
, &wq
);
2994 set_current_state(TASK_INTERRUPTIBLE
);
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
)
3017 waitqueue_active(&TxAnchor
.freewait
) ? "active" : "empty";
3019 waitqueue_active(&TxAnchor
.freelockwait
) ? "active" : "empty";
3021 waitqueue_active(&TxAnchor
.lowlockwait
) ? "active" : "empty";
3023 len
+= sprintf(buffer
,
3029 "freelockwait = %s\n"
3030 "lowlockwait = %s\n"
3031 "tlocksInUse = %d\n"
3032 "jfs_tlocks_low = %d\n"
3033 "unlock_queue is %sempty\n",
3039 TxAnchor
.tlocksInUse
,
3041 list_empty(&TxAnchor
.unlock_queue
) ? "" : "not ");
3044 *start
= buffer
+ begin
;
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
)
3066 len
+= sprintf(buffer
,
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",
3079 TxStat
.txBegin_barrier
,
3080 TxStat
.txBegin_lockslow
,
3081 TxStat
.txBegin_freetid
,
3083 TxStat
.txBeginAnon_barrier
,
3084 TxStat
.txBeginAnon_lockslow
,
3086 TxStat
.txLockAlloc_freelock
);
3089 *start
= buffer
+ begin
;