^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) International Business Machines Corp., 2000-2005
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Portions Copyright (C) Christoph Hellwig, 2001-2002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * jfs_txnmgr.c: transaction manager
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * notes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * transaction starts with txBegin() and ends with txCommit()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * or txAbort().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * tlock is acquired at the time of update;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * (obviate scan at commit time for xtree and dtree)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * tlock and mp points to each other;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * (no hashlist for mp -> tlock).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * special cases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * tlock on in-memory inode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * in-place tlock in the in-memory inode itself;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * converted to page lock by iWrite() at commit time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * tlock during write()/mmap() under anonymous transaction (tid = 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * transferred (?) to transaction at commit time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * use the page itself to update allocation maps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * (obviate intermediate replication of allocation/deallocation data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * hold on to mp+lock thru update of maps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/freezer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include "jfs_incore.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include "jfs_inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include "jfs_filsys.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include "jfs_metapage.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include "jfs_dinode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include "jfs_imap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include "jfs_dmap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include "jfs_superblock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include "jfs_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * transaction management structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int freetid; /* index of a free tid structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int freelock; /* index first free lock word */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) wait_queue_head_t freewait; /* eventlist of free tblock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) wait_queue_head_t freelockwait; /* eventlist of free tlock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) wait_queue_head_t lowlockwait; /* eventlist of ample tlocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) int tlocksInUse; /* Number of tlocks in use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) spinlock_t LazyLock; /* synchronize sync_queue & unlock_queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /* struct tblock *sync_queue; * Transactions waiting for data sync */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct list_head unlock_queue; /* Txns waiting to be released */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct list_head anon_list; /* inodes having anonymous txns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct list_head anon_list2; /* inodes having anonymous txns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) that couldn't be sync'ed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) } TxAnchor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int jfs_tlocks_low; /* Indicates low number of available tlocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #ifdef CONFIG_JFS_STATISTICS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) uint txBegin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) uint txBegin_barrier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) uint txBegin_lockslow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) uint txBegin_freetid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) uint txBeginAnon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) uint txBeginAnon_barrier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) uint txBeginAnon_lockslow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) uint txLockAlloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) uint txLockAlloc_freelock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) } TxStat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static int nTxBlock = -1; /* number of transaction blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) module_param(nTxBlock, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) MODULE_PARM_DESC(nTxBlock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) "Number of transaction blocks (max:65536)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static int nTxLock = -1; /* number of transaction locks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) module_param(nTxLock, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) MODULE_PARM_DESC(nTxLock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) "Number of transaction locks (max:65536)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct tblock *TxBlock; /* transaction block table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static int TxLockLWM; /* Low water mark for number of txLocks used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static int TxLockHWM; /* High water mark for number of txLocks used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static int TxLockVHWM; /* Very High water mark */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct tlock *TxLock; /* transaction lock table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * transaction management lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static DEFINE_SPINLOCK(jfsTxnLock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define TXN_LOCK() spin_lock(&jfsTxnLock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define TXN_UNLOCK() spin_unlock(&jfsTxnLock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define LAZY_LOCK_INIT() spin_lock_init(&TxAnchor.LazyLock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define LAZY_LOCK(flags) spin_lock_irqsave(&TxAnchor.LazyLock, flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define LAZY_UNLOCK(flags) spin_unlock_irqrestore(&TxAnchor.LazyLock, flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static DECLARE_WAIT_QUEUE_HEAD(jfs_commit_thread_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static int jfs_commit_thread_waking;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * Retry logic exist outside these macros to protect from spurrious wakeups.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static inline void TXN_SLEEP_DROP_LOCK(wait_queue_head_t * event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) DECLARE_WAITQUEUE(wait, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) add_wait_queue(event, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) set_current_state(TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) io_schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) remove_wait_queue(event, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #define TXN_SLEEP(event)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) TXN_SLEEP_DROP_LOCK(event);\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) TXN_LOCK();\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #define TXN_WAKEUP(event) wake_up_all(event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * statistics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) tid_t maxtid; /* 4: biggest tid ever used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) lid_t maxlid; /* 4: biggest lid ever used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) int ntid; /* 4: # of transactions performed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int nlid; /* 4: # of tlocks acquired */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int waitlock; /* 4: # of tlock wait */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) } stattx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * forward references
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static int diLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct tlock * tlck, struct commit * cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static int dataLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct tlock * tlck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static void dtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct tlock * tlck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static void mapLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct tlock * tlck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static void txAllocPMap(struct inode *ip, struct maplock * maplock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct tblock * tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static void txForce(struct tblock * tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static int txLog(struct jfs_log * log, struct tblock * tblk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct commit * cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static void txUpdateMap(struct tblock * tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static void txRelease(struct tblock * tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct tlock * tlck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static void LogSyncRelease(struct metapage * mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * transaction block/lock management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * ---------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * Get a transaction lock from the free list. If the number in use is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * greater than the high water mark, wake up the sync daemon. This should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * free some anonymous transaction locks. (TXN_LOCK must be held.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static lid_t txLockAlloc(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) lid_t lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) INCREMENT(TxStat.txLockAlloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (!TxAnchor.freelock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) INCREMENT(TxStat.txLockAlloc_freelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) while (!(lid = TxAnchor.freelock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) TXN_SLEEP(&TxAnchor.freelockwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) TxAnchor.freelock = TxLock[lid].next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) HIGHWATERMARK(stattx.maxlid, lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if ((++TxAnchor.tlocksInUse > TxLockHWM) && (jfs_tlocks_low == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) jfs_info("txLockAlloc tlocks low");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) jfs_tlocks_low = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) wake_up_process(jfsSyncThread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static void txLockFree(lid_t lid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) TxLock[lid].tid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) TxLock[lid].next = TxAnchor.freelock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) TxAnchor.freelock = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) TxAnchor.tlocksInUse--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (jfs_tlocks_low && (TxAnchor.tlocksInUse < TxLockLWM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) jfs_info("txLockFree jfs_tlocks_low no more");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) jfs_tlocks_low = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) TXN_WAKEUP(&TxAnchor.lowlockwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) TXN_WAKEUP(&TxAnchor.freelockwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * NAME: txInit()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * FUNCTION: initialize transaction management structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * RETURN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * serialization: single thread at jfs_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) int txInit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) int k, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) struct sysinfo si;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /* Set defaults for nTxLock and nTxBlock if unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (nTxLock == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (nTxBlock == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /* Base default on memory size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) si_meminfo(&si);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (si.totalram > (256 * 1024)) /* 1 GB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) nTxLock = 64 * 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) nTxLock = si.totalram >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) } else if (nTxBlock > (8 * 1024))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) nTxLock = 64 * 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) nTxLock = nTxBlock << 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (nTxBlock == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) nTxBlock = nTxLock >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /* Verify tunable parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (nTxBlock < 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) nTxBlock = 16; /* No one should set it this low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (nTxBlock > 65536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) nTxBlock = 65536;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (nTxLock < 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) nTxLock = 256; /* No one should set it this low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (nTxLock > 65536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) nTxLock = 65536;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) printk(KERN_INFO "JFS: nTxBlock = %d, nTxLock = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) nTxBlock, nTxLock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * initialize transaction block (tblock) table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * transaction id (tid) = tblock index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * tid = 0 is reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) TxLockLWM = (nTxLock * 4) / 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) TxLockHWM = (nTxLock * 7) / 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) TxLockVHWM = (nTxLock * 8) / 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) size = sizeof(struct tblock) * nTxBlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) TxBlock = vmalloc(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (TxBlock == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) for (k = 1; k < nTxBlock - 1; k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) TxBlock[k].next = k + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) init_waitqueue_head(&TxBlock[k].gcwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) init_waitqueue_head(&TxBlock[k].waitor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) TxBlock[k].next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) init_waitqueue_head(&TxBlock[k].gcwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) init_waitqueue_head(&TxBlock[k].waitor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) TxAnchor.freetid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) init_waitqueue_head(&TxAnchor.freewait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) stattx.maxtid = 1; /* statistics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) * initialize transaction lock (tlock) table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * transaction lock id = tlock index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) * tlock id = 0 is reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) size = sizeof(struct tlock) * nTxLock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) TxLock = vmalloc(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (TxLock == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) vfree(TxBlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /* initialize tlock table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) for (k = 1; k < nTxLock - 1; k++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) TxLock[k].next = k + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) TxLock[k].next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) init_waitqueue_head(&TxAnchor.freelockwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) init_waitqueue_head(&TxAnchor.lowlockwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) TxAnchor.freelock = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) TxAnchor.tlocksInUse = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) INIT_LIST_HEAD(&TxAnchor.anon_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) INIT_LIST_HEAD(&TxAnchor.anon_list2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) LAZY_LOCK_INIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) INIT_LIST_HEAD(&TxAnchor.unlock_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) stattx.maxlid = 1; /* statistics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * NAME: txExit()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * FUNCTION: clean up when module is unloaded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) void txExit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) vfree(TxLock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) TxLock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) vfree(TxBlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) TxBlock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * NAME: txBegin()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * FUNCTION: start a transaction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * PARAMETER: sb - superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) * flag - force for nested tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * RETURN: tid - transaction id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * note: flag force allows to start tx for nested tx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * to prevent deadlock on logsync barrier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) tid_t txBegin(struct super_block *sb, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) tid_t t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct tblock *tblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) struct jfs_log *log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) jfs_info("txBegin: flag = 0x%x", flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) log = JFS_SBI(sb)->log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) INCREMENT(TxStat.txBegin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (!(flag & COMMIT_FORCE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * synchronize with logsync barrier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (test_bit(log_SYNCBARRIER, &log->flag) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) test_bit(log_QUIESCE, &log->flag)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) INCREMENT(TxStat.txBegin_barrier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) TXN_SLEEP(&log->syncwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (flag == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) * Don't begin transaction if we're getting starved for tlocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) * unless COMMIT_FORCE or COMMIT_INODE (which may ultimately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * free tlocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (TxAnchor.tlocksInUse > TxLockVHWM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) INCREMENT(TxStat.txBegin_lockslow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) TXN_SLEEP(&TxAnchor.lowlockwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) * allocate transaction id/block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) if ((t = TxAnchor.freetid) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) jfs_info("txBegin: waiting for free tid");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) INCREMENT(TxStat.txBegin_freetid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) TXN_SLEEP(&TxAnchor.freewait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) tblk = tid_to_tblock(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if ((tblk->next == 0) && !(flag & COMMIT_FORCE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) /* Don't let a non-forced transaction take the last tblk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) jfs_info("txBegin: waiting for free tid");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) INCREMENT(TxStat.txBegin_freetid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) TXN_SLEEP(&TxAnchor.freewait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) TxAnchor.freetid = tblk->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) * initialize transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * We can't zero the whole thing or we screw up another thread being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * awakened after sleeping on tblk->waitor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) * memset(tblk, 0, sizeof(struct tblock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) tblk->next = tblk->last = tblk->xflag = tblk->flag = tblk->lsn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) tblk->sb = sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) ++log->logtid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) tblk->logtid = log->logtid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) ++log->active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) HIGHWATERMARK(stattx.maxtid, t); /* statistics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) INCREMENT(stattx.ntid); /* statistics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) jfs_info("txBegin: returning tid = %d", t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) * NAME: txBeginAnon()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * FUNCTION: start an anonymous transaction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * Blocks if logsync or available tlocks are low to prevent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) * anonymous tlocks from depleting supply.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) * PARAMETER: sb - superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) * RETURN: none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) void txBeginAnon(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) struct jfs_log *log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) log = JFS_SBI(sb)->log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) INCREMENT(TxStat.txBeginAnon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * synchronize with logsync barrier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (test_bit(log_SYNCBARRIER, &log->flag) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) test_bit(log_QUIESCE, &log->flag)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) INCREMENT(TxStat.txBeginAnon_barrier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) TXN_SLEEP(&log->syncwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * Don't begin transaction if we're getting starved for tlocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (TxAnchor.tlocksInUse > TxLockVHWM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) INCREMENT(TxStat.txBeginAnon_lockslow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) TXN_SLEEP(&TxAnchor.lowlockwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) * txEnd()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) * function: free specified transaction block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) * logsync barrier processing:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) * serialization:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) void txEnd(tid_t tid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) struct tblock *tblk = tid_to_tblock(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) struct jfs_log *log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) jfs_info("txEnd: tid = %d", tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * wakeup transactions waiting on the page locked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) * by the current transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) TXN_WAKEUP(&tblk->waitor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) log = JFS_SBI(tblk->sb)->log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) * Lazy commit thread can't free this guy until we mark it UNLOCKED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) * otherwise, we would be left with a transaction that may have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) * reused.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) * Lazy commit thread will turn off tblkGC_LAZY before calling this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) * routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (tblk->flag & tblkGC_LAZY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) jfs_info("txEnd called w/lazy tid: %d, tblk = 0x%p", tid, tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) spin_lock_irq(&log->gclock); // LOGGC_LOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) tblk->flag |= tblkGC_UNLOCKED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) spin_unlock_irq(&log->gclock); // LOGGC_UNLOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) jfs_info("txEnd: tid: %d, tblk = 0x%p", tid, tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) assert(tblk->next == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) * insert tblock back on freelist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) tblk->next = TxAnchor.freetid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) TxAnchor.freetid = tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) * mark the tblock not active
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (--log->active == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) clear_bit(log_FLUSH, &log->flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) * synchronize with logsync barrier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) if (test_bit(log_SYNCBARRIER, &log->flag)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) /* write dirty metadata & forward log syncpt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) jfs_syncpt(log, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) jfs_info("log barrier off: 0x%x", log->lsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) /* enable new transactions start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) clear_bit(log_SYNCBARRIER, &log->flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) /* wakeup all waitors for logsync barrier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) TXN_WAKEUP(&log->syncwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) goto wakeup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) wakeup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) * wakeup all waitors for a free tblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) TXN_WAKEUP(&TxAnchor.freewait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) * txLock()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) * function: acquire a transaction lock on the specified <mp>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) * parameter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) * return: transaction lock id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) * serialization:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) struct tlock *txLock(tid_t tid, struct inode *ip, struct metapage * mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) struct jfs_inode_info *jfs_ip = JFS_IP(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) int dir_xtree = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) lid_t lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) tid_t xtid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) struct xtlock *xtlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) struct linelock *linelock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) xtpage_t *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) struct tblock *tblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) if (S_ISDIR(ip->i_mode) && (type & tlckXTREE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) !(mp->xflag & COMMIT_PAGE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) * Directory inode is special. It can have both an xtree tlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) * and a dtree tlock associated with it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) dir_xtree = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) lid = jfs_ip->xtlid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) lid = mp->lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) /* is page not locked by a transaction ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) if (lid == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) goto allocateLock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) jfs_info("txLock: tid:%d ip:0x%p mp:0x%p lid:%d", tid, ip, mp, lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) /* is page locked by the requester transaction ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) tlck = lid_to_tlock(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) if ((xtid = tlck->tid) == tid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) goto grantLock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) * is page locked by anonymous transaction/lock ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) * (page update without transaction (i.e., file write) is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) * locked under anonymous transaction tid = 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) * anonymous tlocks maintained on anonymous tlock list of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) * the inode of the page and available to all anonymous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) * transactions until txCommit() time at which point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) * they are transferred to the transaction tlock list of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) * the committing transaction of the inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) if (xtid == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) tlck->tid = tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) tblk = tid_to_tblock(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) * The order of the tlocks in the transaction is important
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) * (during truncate, child xtree pages must be freed before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) * parent's tlocks change the working map).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) * Take tlock off anonymous list and add to tail of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) * transaction list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) * Note: We really need to get rid of the tid & lid and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) * use list_head's. This code is getting UGLY!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if (jfs_ip->atlhead == lid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) if (jfs_ip->atltail == lid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) /* only anonymous txn.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) * Remove from anon_list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) list_del_init(&jfs_ip->anon_inode_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) jfs_ip->atlhead = tlck->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) lid_t last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) for (last = jfs_ip->atlhead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) lid_to_tlock(last)->next != lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) last = lid_to_tlock(last)->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) assert(last);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) lid_to_tlock(last)->next = tlck->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) if (jfs_ip->atltail == lid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) jfs_ip->atltail = last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) /* insert the tlock at tail of transaction tlock list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) if (tblk->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) lid_to_tlock(tblk->last)->next = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) tblk->next = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) tlck->next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) tblk->last = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) goto grantLock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) goto waitLock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) * allocate a tlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) allocateLock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) lid = txLockAlloc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) tlck = lid_to_tlock(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) * initialize tlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) tlck->tid = tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) /* mark tlock for meta-data page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) if (mp->xflag & COMMIT_PAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) tlck->flag = tlckPAGELOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) /* mark the page dirty and nohomeok */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) metapage_nohomeok(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) jfs_info("locking mp = 0x%p, nohomeok = %d tid = %d tlck = 0x%p",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) mp, mp->nohomeok, tid, tlck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) /* if anonymous transaction, and buffer is on the group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) * commit synclist, mark inode to show this. This will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) * prevent the buffer from being marked nohomeok for too
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) * long a time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) if ((tid == 0) && mp->lsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) set_cflag(COMMIT_Synclist, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) /* mark tlock for in-memory inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) tlck->flag = tlckINODELOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) if (S_ISDIR(ip->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) tlck->flag |= tlckDIRECTORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) tlck->type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) /* bind the tlock and the page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) tlck->ip = ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) tlck->mp = mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) if (dir_xtree)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) jfs_ip->xtlid = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) mp->lid = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) * enqueue transaction lock to transaction/inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) /* insert the tlock at tail of transaction tlock list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) if (tid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) tblk = tid_to_tblock(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) if (tblk->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) lid_to_tlock(tblk->last)->next = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) tblk->next = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) tlck->next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) tblk->last = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) /* anonymous transaction:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) * insert the tlock at head of inode anonymous tlock list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) tlck->next = jfs_ip->atlhead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) jfs_ip->atlhead = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) if (tlck->next == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) /* This inode's first anonymous transaction */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) jfs_ip->atltail = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) list_add_tail(&jfs_ip->anon_inode_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) &TxAnchor.anon_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) /* initialize type dependent area for linelock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) linelock = (struct linelock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) linelock->next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) linelock->flag = tlckLINELOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) linelock->maxcnt = TLOCKSHORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) linelock->index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) switch (type & tlckTYPE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) case tlckDTREE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) linelock->l2linesize = L2DTSLOTSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) case tlckXTREE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) linelock->l2linesize = L2XTSLOTSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) xtlck = (struct xtlock *) linelock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) xtlck->header.offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) xtlck->header.length = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) if (type & tlckNEW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) xtlck->lwm.offset = XTENTRYSTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) if (mp->xflag & COMMIT_PAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) p = (xtpage_t *) mp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) p = &jfs_ip->i_xtroot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) xtlck->lwm.offset =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) le16_to_cpu(p->header.nextindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) xtlck->lwm.length = 0; /* ! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) xtlck->twm.offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) xtlck->hwm.offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) xtlck->index = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) case tlckINODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) linelock->l2linesize = L2INODESLOTSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) case tlckDATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) linelock->l2linesize = L2DATASLOTSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) jfs_err("UFO tlock:0x%p", tlck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) * update tlock vector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) grantLock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) tlck->type |= type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) return tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) * page is being locked by another transaction:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) waitLock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) /* Only locks on ipimap or ipaimap should reach here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) /* assert(jfs_ip->fileset == AGGREGATE_I); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) if (jfs_ip->fileset != AGGREGATE_I) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) printk(KERN_ERR "txLock: trying to lock locked page!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) print_hex_dump(KERN_ERR, "ip: ", DUMP_PREFIX_ADDRESS, 16, 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) ip, sizeof(*ip), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) print_hex_dump(KERN_ERR, "mp: ", DUMP_PREFIX_ADDRESS, 16, 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) mp, sizeof(*mp), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) print_hex_dump(KERN_ERR, "Locker's tblock: ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) DUMP_PREFIX_ADDRESS, 16, 4, tid_to_tblock(tid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) sizeof(struct tblock), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) print_hex_dump(KERN_ERR, "Tlock: ", DUMP_PREFIX_ADDRESS, 16, 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) tlck, sizeof(*tlck), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) INCREMENT(stattx.waitlock); /* statistics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) release_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) xtid = tlck->tid; /* reacquire after dropping TXN_LOCK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) jfs_info("txLock: in waitLock, tid = %d, xtid = %d, lid = %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) tid, xtid, lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) /* Recheck everything since dropping TXN_LOCK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) if (xtid && (tlck->mp == mp) && (mp->lid == lid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) TXN_SLEEP_DROP_LOCK(&tid_to_tblock(xtid)->waitor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) jfs_info("txLock: awakened tid = %d, lid = %d", tid, lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) * NAME: txRelease()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) * FUNCTION: Release buffers associated with transaction locks, but don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) * mark homeok yet. The allows other transactions to modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) * buffers, but won't let them go to disk until commit record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) * actually gets written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) * PARAMETER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) * tblk -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) * RETURN: Errors from subroutines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) static void txRelease(struct tblock * tblk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) lid_t lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) for (lid = tblk->next; lid; lid = tlck->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) tlck = lid_to_tlock(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) if ((mp = tlck->mp) != NULL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) (tlck->type & tlckBTROOT) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) assert(mp->xflag & COMMIT_PAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) mp->lid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) * wakeup transactions waiting on a page locked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) * by the current transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) TXN_WAKEUP(&tblk->waitor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) * NAME: txUnlock()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) * FUNCTION: Initiates pageout of pages modified by tid in journalled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) * objects and frees their lockwords.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) static void txUnlock(struct tblock * tblk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) struct linelock *linelock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) lid_t lid, next, llid, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) struct jfs_log *log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) int difft, diffp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) jfs_info("txUnlock: tblk = 0x%p", tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) log = JFS_SBI(tblk->sb)->log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) * mark page under tlock homeok (its log has been written):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) for (lid = tblk->next; lid; lid = next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) tlck = lid_to_tlock(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) next = tlck->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) jfs_info("unlocking lid = %d, tlck = 0x%p", lid, tlck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) /* unbind page from tlock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) if ((mp = tlck->mp) != NULL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) (tlck->type & tlckBTROOT) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) assert(mp->xflag & COMMIT_PAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) /* hold buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) hold_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) assert(mp->nohomeok > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) _metapage_homeok(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) /* inherit younger/larger clsn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) LOGSYNC_LOCK(log, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) if (mp->clsn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) logdiff(difft, tblk->clsn, log);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) logdiff(diffp, mp->clsn, log);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) if (difft > diffp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) mp->clsn = tblk->clsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) mp->clsn = tblk->clsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) LOGSYNC_UNLOCK(log, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) assert(!(tlck->flag & tlckFREEPAGE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) put_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) /* insert tlock, and linelock(s) of the tlock if any,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) * at head of freelist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) llid = ((struct linelock *) & tlck->lock)->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) while (llid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) linelock = (struct linelock *) lid_to_tlock(llid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) k = linelock->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) txLockFree(llid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) llid = k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) txLockFree(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) tblk->next = tblk->last = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) * remove tblock from logsynclist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) * (allocation map pages inherited lsn of tblk and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) * has been inserted in logsync list at txUpdateMap())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) if (tblk->lsn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) LOGSYNC_LOCK(log, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) log->count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) list_del(&tblk->synclist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) LOGSYNC_UNLOCK(log, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) * txMaplock()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) * function: allocate a transaction lock for freed page/entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) * for freed page, maplock is used as xtlock/dtlock type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) struct tlock *txMaplock(tid_t tid, struct inode *ip, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) struct jfs_inode_info *jfs_ip = JFS_IP(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) lid_t lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) struct tblock *tblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) struct maplock *maplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) * allocate a tlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) lid = txLockAlloc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) tlck = lid_to_tlock(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) * initialize tlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) tlck->tid = tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) /* bind the tlock and the object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) tlck->flag = tlckINODELOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) if (S_ISDIR(ip->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) tlck->flag |= tlckDIRECTORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) tlck->ip = ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) tlck->mp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) tlck->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) * enqueue transaction lock to transaction/inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) /* insert the tlock at tail of transaction tlock list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) if (tid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) tblk = tid_to_tblock(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) if (tblk->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) lid_to_tlock(tblk->last)->next = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) tblk->next = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) tlck->next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) tblk->last = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) /* anonymous transaction:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) * insert the tlock at head of inode anonymous tlock list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) tlck->next = jfs_ip->atlhead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) jfs_ip->atlhead = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) if (tlck->next == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) /* This inode's first anonymous transaction */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) jfs_ip->atltail = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) list_add_tail(&jfs_ip->anon_inode_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) &TxAnchor.anon_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) /* initialize type dependent area for maplock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) maplock = (struct maplock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) maplock->next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) maplock->maxcnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) maplock->index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) return tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) * txLinelock()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) * function: allocate a transaction lock for log vector list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) struct linelock *txLinelock(struct linelock * tlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) lid_t lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) struct linelock *linelock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) /* allocate a TxLock structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) lid = txLockAlloc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) tlck = lid_to_tlock(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) /* initialize linelock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) linelock = (struct linelock *) tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) linelock->next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) linelock->flag = tlckLINELOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) linelock->maxcnt = TLOCKLONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) linelock->index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) if (tlck->flag & tlckDIRECTORY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) linelock->flag |= tlckDIRECTORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) /* append linelock after tlock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) linelock->next = tlock->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) tlock->next = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) return linelock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) * transaction commit management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) * -----------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) * NAME: txCommit()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) * FUNCTION: commit the changes to the objects specified in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) * clist. For journalled segments only the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) * changes of the caller are committed, ie by tid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) * for non-journalled segments the data are flushed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) * disk and then the change to the disk inode and indirect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) * blocks committed (so blocks newly allocated to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) * segment will be made a part of the segment atomically).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) * all of the segments specified in clist must be in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) * one file system. no more than 6 segments are needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) * to handle all unix svcs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) * if the i_nlink field (i.e. disk inode link count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) * is zero, and the type of inode is a regular file or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) * directory, or symbolic link , the inode is truncated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) * to zero length. the truncation is committed but the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) * VM resources are unaffected until it is closed (see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) * iput and iclose).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) * PARAMETER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) * RETURN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) * serialization:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) * on entry the inode lock on each segment is assumed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) * to be held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) * i/o error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) int txCommit(tid_t tid, /* transaction identifier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) int nip, /* number of inodes to commit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) struct inode **iplist, /* list of inode to commit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) struct commit cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) struct jfs_log *log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) struct tblock *tblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) struct lrd *lrd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) struct inode *ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) struct jfs_inode_info *jfs_ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) int k, n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) ino_t top;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) struct super_block *sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) jfs_info("txCommit, tid = %d, flag = %d", tid, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) /* is read-only file system ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) if (isReadOnly(iplist[0])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) rc = -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) goto TheEnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) sb = cd.sb = iplist[0]->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) cd.tid = tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) if (tid == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) tid = txBegin(sb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) tblk = tid_to_tblock(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) * initialize commit structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) log = JFS_SBI(sb)->log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) cd.log = log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) /* initialize log record descriptor in commit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) lrd = &cd.lrd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) lrd->logtid = cpu_to_le32(tblk->logtid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) lrd->backchain = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) tblk->xflag |= flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) if ((flag & (COMMIT_FORCE | COMMIT_SYNC)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) tblk->xflag |= COMMIT_LAZY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) * prepare non-journaled objects for commit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) * flush data pages of non-journaled file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) * to prevent the file getting non-initialized disk blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) * in case of crash.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) * (new blocks - )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) cd.iplist = iplist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) cd.nip = nip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) * acquire transaction lock on (on-disk) inodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) * update on-disk inode from in-memory inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) * acquiring transaction locks for AFTER records
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) * on the on-disk inode of file object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) * sort the inodes array by inode number in descending order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) * to prevent deadlock when acquiring transaction lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) * of on-disk inodes on multiple on-disk inode pages by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) * multiple concurrent transactions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) for (k = 0; k < cd.nip; k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) top = (cd.iplist[k])->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) for (n = k + 1; n < cd.nip; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) ip = cd.iplist[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) if (ip->i_ino > top) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) top = ip->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) cd.iplist[n] = cd.iplist[k];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) cd.iplist[k] = ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) ip = cd.iplist[k];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) jfs_ip = JFS_IP(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) * BUGBUG - This code has temporarily been removed. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) * intent is to ensure that any file data is written before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) * the metadata is committed to the journal. This prevents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) * uninitialized data from appearing in a file after the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) * journal has been replayed. (The uninitialized data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) * could be sensitive data removed by another user.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) * The problem now is that we are holding the IWRITELOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) * on the inode, and calling filemap_fdatawrite on an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) * unmapped page will cause a deadlock in jfs_get_block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) * The long term solution is to pare down the use of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) * IWRITELOCK. We are currently holding it too long.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) * We could also be smarter about which data pages need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) * to be written before the transaction is committed and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) * when we don't need to worry about it at all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) * if ((!S_ISDIR(ip->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) * && (tblk->flag & COMMIT_DELETE) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) * filemap_write_and_wait(ip->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) * Mark inode as not dirty. It will still be on the dirty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) * inode list, but we'll know not to commit it again unless
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) * it gets marked dirty again
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) clear_cflag(COMMIT_Dirty, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) /* inherit anonymous tlock(s) of inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) if (jfs_ip->atlhead) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) lid_to_tlock(jfs_ip->atltail)->next = tblk->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) tblk->next = jfs_ip->atlhead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) if (!tblk->last)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) tblk->last = jfs_ip->atltail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) jfs_ip->atlhead = jfs_ip->atltail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) list_del_init(&jfs_ip->anon_inode_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) * acquire transaction lock on on-disk inode page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) * (become first tlock of the tblk's tlock list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) if (((rc = diWrite(tid, ip))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) * write log records from transaction locks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) * txUpdateMap() resets XAD_NEW in XAD.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) if ((rc = txLog(log, tblk, &cd)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) goto TheEnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) * Ensure that inode isn't reused before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) * lazy commit thread finishes processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) if (tblk->xflag & COMMIT_DELETE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) ihold(tblk->u.ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) * Avoid a rare deadlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) * If the inode is locked, we may be blocked in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) * jfs_commit_inode. If so, we don't want the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) * lazy_commit thread doing the last iput() on the inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) * since that may block on the locked inode. Instead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) * commit the transaction synchronously, so the last iput
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) * will be done by the calling thread (or later)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) * I believe this code is no longer needed. Splitting I_LOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) * into two bits, I_NEW and I_SYNC should prevent this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) * deadlock as well. But since I don't have a JFS testload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) * to verify this, only a trivial s/I_LOCK/I_SYNC/ was done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) * Joern
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) if (tblk->u.ip->i_state & I_SYNC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) tblk->xflag &= ~COMMIT_LAZY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) ASSERT((!(tblk->xflag & COMMIT_DELETE)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) ((tblk->u.ip->i_nlink == 0) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) !test_cflag(COMMIT_Nolink, tblk->u.ip)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) * write COMMIT log record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) lrd->type = cpu_to_le16(LOG_COMMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) lrd->length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) lmLog(log, tblk, lrd, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) lmGroupCommit(log, tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) * - transaction is now committed -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) * force pages in careful update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) * (imap addressing structure update)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) if (flag & COMMIT_FORCE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) txForce(tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) * update allocation map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) * update inode allocation map and inode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) * free pager lock on memory object of inode if any.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) * update block allocation map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) * txUpdateMap() resets XAD_NEW in XAD.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) if (tblk->xflag & COMMIT_FORCE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) txUpdateMap(tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) * free transaction locks and pageout/free pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) txRelease(tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) if ((tblk->flag & tblkGC_LAZY) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) txUnlock(tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) * reset in-memory object state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) for (k = 0; k < cd.nip; k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) ip = cd.iplist[k];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) jfs_ip = JFS_IP(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) * reset in-memory inode state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) jfs_ip->bxflag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) jfs_ip->blid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) txAbort(tid, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) TheEnd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) jfs_info("txCommit: tid = %d, returning %d", tid, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) * NAME: txLog()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) * FUNCTION: Writes AFTER log records for all lines modified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) * by tid for segments specified by inodes in comdata.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) * Code assumes only WRITELOCKS are recorded in lockwords.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) * PARAMETERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) * RETURN :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) static int txLog(struct jfs_log * log, struct tblock * tblk, struct commit * cd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) struct inode *ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) lid_t lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) struct lrd *lrd = &cd->lrd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) * write log record(s) for each tlock of transaction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) for (lid = tblk->next; lid; lid = tlck->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) tlck = lid_to_tlock(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) tlck->flag |= tlckLOG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) /* initialize lrd common */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) ip = tlck->ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) lrd->aggregate = cpu_to_le32(JFS_SBI(ip->i_sb)->aggregate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) lrd->log.redopage.fileset = cpu_to_le32(JFS_IP(ip)->fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) lrd->log.redopage.inode = cpu_to_le32(ip->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) /* write log record of page from the tlock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) switch (tlck->type & tlckTYPE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) case tlckXTREE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) xtLog(log, tblk, lrd, tlck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) case tlckDTREE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) dtLog(log, tblk, lrd, tlck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) case tlckINODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) diLog(log, tblk, lrd, tlck, cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) case tlckMAP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) mapLog(log, tblk, lrd, tlck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) case tlckDATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) dataLog(log, tblk, lrd, tlck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) jfs_err("UFO tlock:0x%p", tlck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) * diLog()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) * function: log inode tlock and format maplock to update bmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) static int diLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) struct tlock * tlck, struct commit * cd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) pxd_t *pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) struct pxd_lock *pxdlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) mp = tlck->mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) /* initialize as REDOPAGE record format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) lrd->log.redopage.type = cpu_to_le16(LOG_INODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) lrd->log.redopage.l2linesize = cpu_to_le16(L2INODESLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) pxd = &lrd->log.redopage.pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) * inode after image
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) if (tlck->type & tlckENTRY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) /* log after-image for logredo(): */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) lrd->type = cpu_to_le16(LOG_REDOPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) PXDaddress(pxd, mp->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) PXDlength(pxd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) mp->logical_size >> tblk->sb->s_blocksize_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) /* mark page as homeward bound */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) tlck->flag |= tlckWRITEPAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) } else if (tlck->type & tlckFREE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) * free inode extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) * (pages of the freed inode extent have been invalidated and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) * a maplock for free of the extent has been formatted at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) * txLock() time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) * the tlock had been acquired on the inode allocation map page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) * (iag) that specifies the freed extent, even though the map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) * page is not itself logged, to prevent pageout of the map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) * page before the log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) /* log LOG_NOREDOINOEXT of the freed inode extent for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) * logredo() to start NoRedoPage filters, and to update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) * imap and bmap for free of the extent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) lrd->type = cpu_to_le16(LOG_NOREDOINOEXT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) * For the LOG_NOREDOINOEXT record, we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) * to pass the IAG number and inode extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) * index (within that IAG) from which the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) * the extent being released. These have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) * passed to us in the iplist[1] and iplist[2].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) lrd->log.noredoinoext.iagnum =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) cpu_to_le32((u32) (size_t) cd->iplist[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) lrd->log.noredoinoext.inoext_idx =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) cpu_to_le32((u32) (size_t) cd->iplist[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) pxdlock = (struct pxd_lock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) *pxd = pxdlock->pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) /* update bmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) tlck->flag |= tlckUPDATEMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) /* mark page as homeward bound */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) tlck->flag |= tlckWRITEPAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) jfs_err("diLog: UFO type tlck:0x%p", tlck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) #ifdef _JFS_WIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) * alloc/free external EA extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) * a maplock for txUpdateMap() to update bPWMAP for alloc/free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) * of the extent has been formatted at txLock() time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) assert(tlck->type & tlckEA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) /* log LOG_UPDATEMAP for logredo() to update bmap for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) * alloc of new (and free of old) external EA extent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) lrd->type = cpu_to_le16(LOG_UPDATEMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) pxdlock = (struct pxd_lock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) nlock = pxdlock->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) for (i = 0; i < nlock; i++, pxdlock++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) if (pxdlock->flag & mlckALLOCPXD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) lrd->log.updatemap.type =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) cpu_to_le16(LOG_ALLOCPXD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) lrd->log.updatemap.type =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) cpu_to_le16(LOG_FREEPXD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) lrd->log.updatemap.nxd = cpu_to_le16(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) lrd->log.updatemap.pxd = pxdlock->pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) lrd->backchain =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) cpu_to_le32(lmLog(log, tblk, lrd, NULL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) /* update bmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) tlck->flag |= tlckUPDATEMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) #endif /* _JFS_WIP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) * dataLog()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) * function: log data tlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) static int dataLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) struct tlock * tlck)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) pxd_t *pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) mp = tlck->mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) /* initialize as REDOPAGE record format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) lrd->log.redopage.type = cpu_to_le16(LOG_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) lrd->log.redopage.l2linesize = cpu_to_le16(L2DATASLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) pxd = &lrd->log.redopage.pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) /* log after-image for logredo(): */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) lrd->type = cpu_to_le16(LOG_REDOPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) if (jfs_dirtable_inline(tlck->ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) * The table has been truncated, we've must have deleted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) * the last entry, so don't bother logging this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) mp->lid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) grab_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) metapage_homeok(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) discard_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) tlck->mp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) PXDaddress(pxd, mp->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) PXDlength(pxd, mp->logical_size >> tblk->sb->s_blocksize_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) /* mark page as homeward bound */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) tlck->flag |= tlckWRITEPAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) * dtLog()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) * function: log dtree tlock and format maplock to update bmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) static void dtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) struct tlock * tlck)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) struct pxd_lock *pxdlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) pxd_t *pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) mp = tlck->mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) /* initialize as REDOPAGE/NOREDOPAGE record format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) lrd->log.redopage.type = cpu_to_le16(LOG_DTREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) lrd->log.redopage.l2linesize = cpu_to_le16(L2DTSLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) pxd = &lrd->log.redopage.pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) if (tlck->type & tlckBTROOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) lrd->log.redopage.type |= cpu_to_le16(LOG_BTROOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) * page extension via relocation: entry insertion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) * page extension in-place: entry insertion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) * new right page from page split, reinitialized in-line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) * root from root page split: entry insertion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) if (tlck->type & (tlckNEW | tlckEXTEND)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) /* log after-image of the new page for logredo():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) * mark log (LOG_NEW) for logredo() to initialize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) * freelist and update bmap for alloc of the new page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) lrd->type = cpu_to_le16(LOG_REDOPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) if (tlck->type & tlckEXTEND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) lrd->log.redopage.type |= cpu_to_le16(LOG_EXTEND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) lrd->log.redopage.type |= cpu_to_le16(LOG_NEW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) PXDaddress(pxd, mp->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) PXDlength(pxd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) mp->logical_size >> tblk->sb->s_blocksize_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) /* format a maplock for txUpdateMap() to update bPMAP for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) * alloc of the new page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) if (tlck->type & tlckBTROOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) tlck->flag |= tlckUPDATEMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) pxdlock = (struct pxd_lock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) pxdlock->flag = mlckALLOCPXD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) pxdlock->pxd = *pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) pxdlock->index = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) /* mark page as homeward bound */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) tlck->flag |= tlckWRITEPAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) * entry insertion/deletion,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) * sibling page link update (old right page before split);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) if (tlck->type & (tlckENTRY | tlckRELINK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) /* log after-image for logredo(): */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) lrd->type = cpu_to_le16(LOG_REDOPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) PXDaddress(pxd, mp->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) PXDlength(pxd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) mp->logical_size >> tblk->sb->s_blocksize_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) /* mark page as homeward bound */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) tlck->flag |= tlckWRITEPAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) * page deletion: page has been invalidated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) * page relocation: source extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) * a maplock for free of the page has been formatted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) * at txLock() time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) if (tlck->type & (tlckFREE | tlckRELOCATE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) /* log LOG_NOREDOPAGE of the deleted page for logredo()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) * to start NoRedoPage filter and to update bmap for free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) * of the deletd page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) lrd->type = cpu_to_le16(LOG_NOREDOPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) pxdlock = (struct pxd_lock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) *pxd = pxdlock->pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) /* a maplock for txUpdateMap() for free of the page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) * has been formatted at txLock() time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) tlck->flag |= tlckUPDATEMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) * xtLog()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) * function: log xtree tlock and format maplock to update bmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) struct tlock * tlck)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) struct inode *ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) xtpage_t *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) struct xtlock *xtlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) struct maplock *maplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) struct xdlistlock *xadlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) struct pxd_lock *pxdlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) pxd_t *page_pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) int next, lwm, hwm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) ip = tlck->ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) mp = tlck->mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) /* initialize as REDOPAGE/NOREDOPAGE record format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) lrd->log.redopage.type = cpu_to_le16(LOG_XTREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) lrd->log.redopage.l2linesize = cpu_to_le16(L2XTSLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) page_pxd = &lrd->log.redopage.pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) if (tlck->type & tlckBTROOT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) lrd->log.redopage.type |= cpu_to_le16(LOG_BTROOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) p = &JFS_IP(ip)->i_xtroot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) if (S_ISDIR(ip->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) lrd->log.redopage.type |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) cpu_to_le16(LOG_DIR_XTREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) p = (xtpage_t *) mp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) next = le16_to_cpu(p->header.nextindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) maplock = (struct maplock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) xadlock = (struct xdlistlock *) maplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) * entry insertion/extension;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) * sibling page link update (old right page before split);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) if (tlck->type & (tlckNEW | tlckGROW | tlckRELINK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) /* log after-image for logredo():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) * logredo() will update bmap for alloc of new/extended
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) * extents (XAD_NEW|XAD_EXTEND) of XAD[lwm:next) from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) * after-image of XADlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) * logredo() resets (XAD_NEW|XAD_EXTEND) flag when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) * applying the after-image to the meta-data page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) lrd->type = cpu_to_le16(LOG_REDOPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) PXDaddress(page_pxd, mp->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) PXDlength(page_pxd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) mp->logical_size >> tblk->sb->s_blocksize_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) /* format a maplock for txUpdateMap() to update bPMAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) * for alloc of new/extended extents of XAD[lwm:next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) * from the page itself;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) * txUpdateMap() resets (XAD_NEW|XAD_EXTEND) flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) lwm = xtlck->lwm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) if (lwm == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) lwm = XTPAGEMAXSLOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) if (lwm == next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) if (lwm > next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) jfs_err("xtLog: lwm > next");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) tlck->flag |= tlckUPDATEMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) xadlock->flag = mlckALLOCXADLIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) xadlock->count = next - lwm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) if ((xadlock->count <= 4) && (tblk->xflag & COMMIT_LAZY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) pxd_t *pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) * Lazy commit may allow xtree to be modified before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) * txUpdateMap runs. Copy xad into linelock to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) * preserve correct data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) * We can fit twice as may pxd's as xads in the lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) xadlock->flag = mlckALLOCPXDLIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) pxd = xadlock->xdlist = &xtlck->pxdlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) for (i = 0; i < xadlock->count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) PXDaddress(pxd, addressXAD(&p->xad[lwm + i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) PXDlength(pxd, lengthXAD(&p->xad[lwm + i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) p->xad[lwm + i].flag &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) ~(XAD_NEW | XAD_EXTENDED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) pxd++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) * xdlist will point to into inode's xtree, ensure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) * that transaction is not committed lazily.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) xadlock->flag = mlckALLOCXADLIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) xadlock->xdlist = &p->xad[lwm];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) tblk->xflag &= ~COMMIT_LAZY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) jfs_info("xtLog: alloc ip:0x%p mp:0x%p tlck:0x%p lwm:%d count:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) tlck->ip, mp, tlck, lwm, xadlock->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) maplock->index = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) /* mark page as homeward bound */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) tlck->flag |= tlckWRITEPAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) * page deletion: file deletion/truncation (ref. xtTruncate())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) * (page will be invalidated after log is written and bmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) * is updated from the page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) if (tlck->type & tlckFREE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) /* LOG_NOREDOPAGE log for NoRedoPage filter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) * if page free from file delete, NoRedoFile filter from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) * inode image of zero link count will subsume NoRedoPage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) * filters for each page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) * if page free from file truncattion, write NoRedoPage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) * filter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) * upadte of block allocation map for the page itself:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) * if page free from deletion and truncation, LOG_UPDATEMAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) * log for the page itself is generated from processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) * its parent page xad entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) /* if page free from file truncation, log LOG_NOREDOPAGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) * of the deleted page for logredo() to start NoRedoPage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) * filter for the page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) if (tblk->xflag & COMMIT_TRUNCATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) /* write NOREDOPAGE for the page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) lrd->type = cpu_to_le16(LOG_NOREDOPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) PXDaddress(page_pxd, mp->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) PXDlength(page_pxd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) mp->logical_size >> tblk->sb->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) s_blocksize_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) lrd->backchain =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) cpu_to_le32(lmLog(log, tblk, lrd, NULL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) if (tlck->type & tlckBTROOT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) /* Empty xtree must be logged */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) lrd->type = cpu_to_le16(LOG_REDOPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) lrd->backchain =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) cpu_to_le32(lmLog(log, tblk, lrd, tlck));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) /* init LOG_UPDATEMAP of the freed extents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) * XAD[XTENTRYSTART:hwm) from the deleted page itself
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) * for logredo() to update bmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) lrd->type = cpu_to_le16(LOG_UPDATEMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) lrd->log.updatemap.type = cpu_to_le16(LOG_FREEXADLIST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) hwm = xtlck->hwm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) lrd->log.updatemap.nxd =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) cpu_to_le16(hwm - XTENTRYSTART + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) /* reformat linelock for lmLog() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) xtlck->header.offset = XTENTRYSTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) xtlck->header.length = hwm - XTENTRYSTART + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) xtlck->index = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) /* format a maplock for txUpdateMap() to update bmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) * to free extents of XAD[XTENTRYSTART:hwm) from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) * deleted page itself;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) tlck->flag |= tlckUPDATEMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) xadlock->count = hwm - XTENTRYSTART + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) if ((xadlock->count <= 4) && (tblk->xflag & COMMIT_LAZY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) pxd_t *pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) * Lazy commit may allow xtree to be modified before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) * txUpdateMap runs. Copy xad into linelock to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) * preserve correct data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) * We can fit twice as may pxd's as xads in the lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) xadlock->flag = mlckFREEPXDLIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) pxd = xadlock->xdlist = &xtlck->pxdlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) for (i = 0; i < xadlock->count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) PXDaddress(pxd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) addressXAD(&p->xad[XTENTRYSTART + i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) PXDlength(pxd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) lengthXAD(&p->xad[XTENTRYSTART + i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) pxd++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) * xdlist will point to into inode's xtree, ensure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) * that transaction is not committed lazily.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) xadlock->flag = mlckFREEXADLIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) xadlock->xdlist = &p->xad[XTENTRYSTART];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) tblk->xflag &= ~COMMIT_LAZY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) jfs_info("xtLog: free ip:0x%p mp:0x%p count:%d lwm:2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) tlck->ip, mp, xadlock->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) maplock->index = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) /* mark page as invalid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) if (((tblk->xflag & COMMIT_PWMAP) || S_ISDIR(ip->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) && !(tlck->type & tlckBTROOT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) tlck->flag |= tlckFREEPAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) else (tblk->xflag & COMMIT_PMAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) ? release the page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) * page/entry truncation: file truncation (ref. xtTruncate())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) * |----------+------+------+---------------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) * | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) * | | hwm - hwm before truncation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) * | next - truncation point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) * lwm - lwm before truncation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) * header ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) if (tlck->type & tlckTRUNCATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) pxd_t pxd; /* truncated extent of xad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) int twm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) * For truncation the entire linelock may be used, so it would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) * be difficult to store xad list in linelock itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) * Therefore, we'll just force transaction to be committed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) * synchronously, so that xtree pages won't be changed before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) * txUpdateMap runs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) tblk->xflag &= ~COMMIT_LAZY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) lwm = xtlck->lwm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) if (lwm == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) lwm = XTPAGEMAXSLOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) hwm = xtlck->hwm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) twm = xtlck->twm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) * write log records
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) /* log after-image for logredo():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) * logredo() will update bmap for alloc of new/extended
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) * extents (XAD_NEW|XAD_EXTEND) of XAD[lwm:next) from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) * after-image of XADlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) * logredo() resets (XAD_NEW|XAD_EXTEND) flag when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) * applying the after-image to the meta-data page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) lrd->type = cpu_to_le16(LOG_REDOPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) PXDaddress(page_pxd, mp->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) PXDlength(page_pxd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) mp->logical_size >> tblk->sb->s_blocksize_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) * truncate entry XAD[twm == next - 1]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) if (twm == next - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) /* init LOG_UPDATEMAP for logredo() to update bmap for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) * free of truncated delta extent of the truncated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) * entry XAD[next - 1]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) * (xtlck->pxdlock = truncated delta extent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) pxdlock = (struct pxd_lock *) & xtlck->pxdlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) /* assert(pxdlock->type & tlckTRUNCATE); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) lrd->type = cpu_to_le16(LOG_UPDATEMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) lrd->log.updatemap.type = cpu_to_le16(LOG_FREEPXD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) lrd->log.updatemap.nxd = cpu_to_le16(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) lrd->log.updatemap.pxd = pxdlock->pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) pxd = pxdlock->pxd; /* save to format maplock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) lrd->backchain =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) cpu_to_le32(lmLog(log, tblk, lrd, NULL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) * free entries XAD[next:hwm]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) if (hwm >= next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) /* init LOG_UPDATEMAP of the freed extents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) * XAD[next:hwm] from the deleted page itself
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) * for logredo() to update bmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) lrd->type = cpu_to_le16(LOG_UPDATEMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) lrd->log.updatemap.type =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) cpu_to_le16(LOG_FREEXADLIST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) hwm = xtlck->hwm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) lrd->log.updatemap.nxd =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) cpu_to_le16(hwm - next + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) /* reformat linelock for lmLog() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) xtlck->header.offset = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) xtlck->header.length = hwm - next + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) xtlck->index = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) lrd->backchain =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) cpu_to_le32(lmLog(log, tblk, lrd, tlck));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) * format maplock(s) for txUpdateMap() to update bmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) maplock->index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) * allocate entries XAD[lwm:next):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) if (lwm < next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) /* format a maplock for txUpdateMap() to update bPMAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) * for alloc of new/extended extents of XAD[lwm:next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) * from the page itself;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) * txUpdateMap() resets (XAD_NEW|XAD_EXTEND) flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) tlck->flag |= tlckUPDATEMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) xadlock->flag = mlckALLOCXADLIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) xadlock->count = next - lwm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) xadlock->xdlist = &p->xad[lwm];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) jfs_info("xtLog: alloc ip:0x%p mp:0x%p count:%d lwm:%d next:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) tlck->ip, mp, xadlock->count, lwm, next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) maplock->index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) xadlock++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) * truncate entry XAD[twm == next - 1]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) if (twm == next - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) /* format a maplock for txUpdateMap() to update bmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) * to free truncated delta extent of the truncated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) * entry XAD[next - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) * (xtlck->pxdlock = truncated delta extent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) tlck->flag |= tlckUPDATEMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) pxdlock = (struct pxd_lock *) xadlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) pxdlock->flag = mlckFREEPXD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) pxdlock->count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) pxdlock->pxd = pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) jfs_info("xtLog: truncate ip:0x%p mp:0x%p count:%d hwm:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) ip, mp, pxdlock->count, hwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) maplock->index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) xadlock++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) * free entries XAD[next:hwm]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) if (hwm >= next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) /* format a maplock for txUpdateMap() to update bmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) * to free extents of XAD[next:hwm] from thedeleted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) * page itself;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) tlck->flag |= tlckUPDATEMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) xadlock->flag = mlckFREEXADLIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) xadlock->count = hwm - next + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) xadlock->xdlist = &p->xad[next];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) jfs_info("xtLog: free ip:0x%p mp:0x%p count:%d next:%d hwm:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) tlck->ip, mp, xadlock->count, next, hwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) maplock->index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) /* mark page as homeward bound */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) tlck->flag |= tlckWRITEPAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) * mapLog()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) * function: log from maplock of freed data extents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) static void mapLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) struct tlock * tlck)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) struct pxd_lock *pxdlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) int i, nlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) pxd_t *pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) * page relocation: free the source page extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) * a maplock for txUpdateMap() for free of the page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) * has been formatted at txLock() time saving the src
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) * relocated page address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) if (tlck->type & tlckRELOCATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) /* log LOG_NOREDOPAGE of the old relocated page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) * for logredo() to start NoRedoPage filter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) lrd->type = cpu_to_le16(LOG_NOREDOPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) pxdlock = (struct pxd_lock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) pxd = &lrd->log.redopage.pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) *pxd = pxdlock->pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) /* (N.B. currently, logredo() does NOT update bmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) * for free of the page itself for (LOG_XTREE|LOG_NOREDOPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) * if page free from relocation, LOG_UPDATEMAP log is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) * specifically generated now for logredo()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) * to update bmap for free of src relocated page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) * (new flag LOG_RELOCATE may be introduced which will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) * inform logredo() to start NORedoPage filter and also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) * update block allocation map at the same time, thus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) * avoiding an extra log write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) lrd->type = cpu_to_le16(LOG_UPDATEMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) lrd->log.updatemap.type = cpu_to_le16(LOG_FREEPXD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) lrd->log.updatemap.nxd = cpu_to_le16(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) lrd->log.updatemap.pxd = pxdlock->pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) /* a maplock for txUpdateMap() for free of the page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) * has been formatted at txLock() time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) tlck->flag |= tlckUPDATEMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) * Otherwise it's not a relocate request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) /* log LOG_UPDATEMAP for logredo() to update bmap for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) * free of truncated/relocated delta extent of the data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) * e.g.: external EA extent, relocated/truncated extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) * from xtTailgate();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) lrd->type = cpu_to_le16(LOG_UPDATEMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) pxdlock = (struct pxd_lock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) nlock = pxdlock->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) for (i = 0; i < nlock; i++, pxdlock++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) if (pxdlock->flag & mlckALLOCPXD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) lrd->log.updatemap.type =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) cpu_to_le16(LOG_ALLOCPXD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) lrd->log.updatemap.type =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) cpu_to_le16(LOG_FREEPXD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) lrd->log.updatemap.nxd = cpu_to_le16(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) lrd->log.updatemap.pxd = pxdlock->pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) lrd->backchain =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) cpu_to_le32(lmLog(log, tblk, lrd, NULL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) jfs_info("mapLog: xaddr:0x%lx xlen:0x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) (ulong) addressPXD(&pxdlock->pxd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) lengthPXD(&pxdlock->pxd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) /* update bmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) tlck->flag |= tlckUPDATEMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) * txEA()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) * function: acquire maplock for EA/ACL extents or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) * set COMMIT_INLINE flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) void txEA(tid_t tid, struct inode *ip, dxd_t * oldea, dxd_t * newea)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) struct tlock *tlck = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) struct pxd_lock *maplock = NULL, *pxdlock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) * format maplock for alloc of new EA extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) if (newea) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) /* Since the newea could be a completely zeroed entry we need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) * check for the two flags which indicate we should actually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) * commit new EA data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) if (newea->flag & DXD_EXTENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) tlck = txMaplock(tid, ip, tlckMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) maplock = (struct pxd_lock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) pxdlock = (struct pxd_lock *) maplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) pxdlock->flag = mlckALLOCPXD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) PXDaddress(&pxdlock->pxd, addressDXD(newea));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) PXDlength(&pxdlock->pxd, lengthDXD(newea));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) pxdlock++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) maplock->index = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) } else if (newea->flag & DXD_INLINE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) tlck = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) set_cflag(COMMIT_Inlineea, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) * format maplock for free of old EA extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) if (!test_cflag(COMMIT_Nolink, ip) && oldea->flag & DXD_EXTENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) if (tlck == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) tlck = txMaplock(tid, ip, tlckMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) maplock = (struct pxd_lock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) pxdlock = (struct pxd_lock *) maplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) maplock->index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) pxdlock->flag = mlckFREEPXD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) PXDaddress(&pxdlock->pxd, addressDXD(oldea));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) PXDlength(&pxdlock->pxd, lengthDXD(oldea));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) maplock->index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) * txForce()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) * function: synchronously write pages locked by transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) * after txLog() but before txUpdateMap();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) static void txForce(struct tblock * tblk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) lid_t lid, next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) * reverse the order of transaction tlocks in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) * careful update order of address index pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) * (right to left, bottom up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) tlck = lid_to_tlock(tblk->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) lid = tlck->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) tlck->next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) while (lid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) tlck = lid_to_tlock(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) next = tlck->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) tlck->next = tblk->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) tblk->next = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) lid = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) * synchronously write the page, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) * hold the page for txUpdateMap();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) for (lid = tblk->next; lid; lid = next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) tlck = lid_to_tlock(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) next = tlck->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) if ((mp = tlck->mp) != NULL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) (tlck->type & tlckBTROOT) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) assert(mp->xflag & COMMIT_PAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) if (tlck->flag & tlckWRITEPAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) tlck->flag &= ~tlckWRITEPAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) /* do not release page to freelist */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) force_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) * The "right" thing to do here is to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) * synchronously write the metadata.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) * With the current implementation this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) * is hard since write_metapage requires
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) * us to kunmap & remap the page. If we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) * have tlocks pointing into the metadata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) * pages, we don't want to do this. I think
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) * we can get by with synchronously writing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) * the pages when they are released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) assert(mp->nohomeok);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) set_bit(META_dirty, &mp->flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) set_bit(META_sync, &mp->flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) * txUpdateMap()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) * function: update persistent allocation map (and working map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) * if appropriate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) * parameter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) static void txUpdateMap(struct tblock * tblk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) struct inode *ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) struct inode *ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) lid_t lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) struct maplock *maplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) struct pxd_lock pxdlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) int maptype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) int k, nlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) struct metapage *mp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) ipimap = JFS_SBI(tblk->sb)->ipimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) maptype = (tblk->xflag & COMMIT_PMAP) ? COMMIT_PMAP : COMMIT_PWMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) * update block allocation map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) * update allocation state in pmap (and wmap) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) * update lsn of the pmap page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) * scan each tlock/page of transaction for block allocation/free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) * for each tlock/page of transaction, update map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) * ? are there tlock for pmap and pwmap at the same time ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) for (lid = tblk->next; lid; lid = tlck->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) tlck = lid_to_tlock(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) if ((tlck->flag & tlckUPDATEMAP) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) if (tlck->flag & tlckFREEPAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) * Another thread may attempt to reuse freed space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) * immediately, so we want to get rid of the metapage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) * before anyone else has a chance to get it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) * Lock metapage, update maps, then invalidate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) * the metapage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) mp = tlck->mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) ASSERT(mp->xflag & COMMIT_PAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) grab_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) * extent list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) * . in-line PXD list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) * . out-of-line XAD list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) maplock = (struct maplock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) nlock = maplock->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) for (k = 0; k < nlock; k++, maplock++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) * allocate blocks in persistent map:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) * blocks have been allocated from wmap at alloc time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) if (maplock->flag & mlckALLOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) txAllocPMap(ipimap, maplock, tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) * free blocks in persistent and working map:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) * blocks will be freed in pmap and then in wmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) * ? tblock specifies the PMAP/PWMAP based upon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) * transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) * free blocks in persistent map:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) * blocks will be freed from wmap at last reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) * release of the object for regular files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) * Alway free blocks from both persistent & working
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) * maps for directories
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) else { /* (maplock->flag & mlckFREE) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) if (tlck->flag & tlckDIRECTORY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) txFreeMap(ipimap, maplock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) tblk, COMMIT_PWMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) txFreeMap(ipimap, maplock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) tblk, maptype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) if (tlck->flag & tlckFREEPAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) if (!(tblk->flag & tblkGC_LAZY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) /* This is equivalent to txRelease */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) ASSERT(mp->lid == lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) tlck->mp->lid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) assert(mp->nohomeok == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) metapage_homeok(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) discard_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) tlck->mp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) * update inode allocation map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) * update allocation state in pmap and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) * update lsn of the pmap page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) * update in-memory inode flag/state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) * unlock mapper/write lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) if (tblk->xflag & COMMIT_CREATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) diUpdatePMap(ipimap, tblk->ino, false, tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) /* update persistent block allocation map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) * for the allocation of inode extent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) pxdlock.flag = mlckALLOCPXD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) pxdlock.pxd = tblk->u.ixpxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) pxdlock.index = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) txAllocPMap(ipimap, (struct maplock *) & pxdlock, tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) } else if (tblk->xflag & COMMIT_DELETE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) ip = tblk->u.ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) diUpdatePMap(ipimap, ip->i_ino, true, tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) iput(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) * txAllocPMap()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) * function: allocate from persistent map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) * parameter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) * ipbmap -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) * malock -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) * xad list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) * pxd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) * maptype -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) * allocate from persistent map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) * free from persistent map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) * (e.g., tmp file - free from working map at releae
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) * of last reference);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) * free from persistent and working map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) * lsn - log sequence number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) static void txAllocPMap(struct inode *ip, struct maplock * maplock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) struct tblock * tblk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) struct xdlistlock *xadlistlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) xad_t *xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) s64 xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) int xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) struct pxd_lock *pxdlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) struct xdlistlock *pxdlistlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) pxd_t *pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) * allocate from persistent map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) if (maplock->flag & mlckALLOCXADLIST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) xadlistlock = (struct xdlistlock *) maplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) xad = xadlistlock->xdlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) for (n = 0; n < xadlistlock->count; n++, xad++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) if (xad->flag & (XAD_NEW | XAD_EXTENDED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) xaddr = addressXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) xlen = lengthXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) dbUpdatePMap(ipbmap, false, xaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) (s64) xlen, tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) xad->flag &= ~(XAD_NEW | XAD_EXTENDED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) jfs_info("allocPMap: xaddr:0x%lx xlen:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) (ulong) xaddr, xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) } else if (maplock->flag & mlckALLOCPXD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) pxdlock = (struct pxd_lock *) maplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) xaddr = addressPXD(&pxdlock->pxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) xlen = lengthPXD(&pxdlock->pxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) dbUpdatePMap(ipbmap, false, xaddr, (s64) xlen, tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) jfs_info("allocPMap: xaddr:0x%lx xlen:%d", (ulong) xaddr, xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) } else { /* (maplock->flag & mlckALLOCPXDLIST) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) pxdlistlock = (struct xdlistlock *) maplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) pxd = pxdlistlock->xdlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) for (n = 0; n < pxdlistlock->count; n++, pxd++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) xaddr = addressPXD(pxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) xlen = lengthPXD(pxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) dbUpdatePMap(ipbmap, false, xaddr, (s64) xlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) jfs_info("allocPMap: xaddr:0x%lx xlen:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) (ulong) xaddr, xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) * txFreeMap()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) * function: free from persistent and/or working map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) * todo: optimization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) void txFreeMap(struct inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) struct maplock * maplock, struct tblock * tblk, int maptype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) struct xdlistlock *xadlistlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) xad_t *xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) s64 xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) int xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) struct pxd_lock *pxdlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) struct xdlistlock *pxdlistlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) pxd_t *pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) jfs_info("txFreeMap: tblk:0x%p maplock:0x%p maptype:0x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) tblk, maplock, maptype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) * free from persistent map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) if (maptype == COMMIT_PMAP || maptype == COMMIT_PWMAP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) if (maplock->flag & mlckFREEXADLIST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) xadlistlock = (struct xdlistlock *) maplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) xad = xadlistlock->xdlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) for (n = 0; n < xadlistlock->count; n++, xad++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) if (!(xad->flag & XAD_NEW)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) xaddr = addressXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) xlen = lengthXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) dbUpdatePMap(ipbmap, true, xaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) (s64) xlen, tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) jfs_info("freePMap: xaddr:0x%lx xlen:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) (ulong) xaddr, xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) } else if (maplock->flag & mlckFREEPXD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) pxdlock = (struct pxd_lock *) maplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) xaddr = addressPXD(&pxdlock->pxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) xlen = lengthPXD(&pxdlock->pxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) dbUpdatePMap(ipbmap, true, xaddr, (s64) xlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) jfs_info("freePMap: xaddr:0x%lx xlen:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) (ulong) xaddr, xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) } else { /* (maplock->flag & mlckALLOCPXDLIST) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) pxdlistlock = (struct xdlistlock *) maplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) pxd = pxdlistlock->xdlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) for (n = 0; n < pxdlistlock->count; n++, pxd++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) xaddr = addressPXD(pxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) xlen = lengthPXD(pxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) dbUpdatePMap(ipbmap, true, xaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) (s64) xlen, tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) jfs_info("freePMap: xaddr:0x%lx xlen:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) (ulong) xaddr, xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) * free from working map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) if (maptype == COMMIT_PWMAP || maptype == COMMIT_WMAP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) if (maplock->flag & mlckFREEXADLIST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) xadlistlock = (struct xdlistlock *) maplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) xad = xadlistlock->xdlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) for (n = 0; n < xadlistlock->count; n++, xad++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) xaddr = addressXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) xlen = lengthXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) dbFree(ip, xaddr, (s64) xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) xad->flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) jfs_info("freeWMap: xaddr:0x%lx xlen:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) (ulong) xaddr, xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) } else if (maplock->flag & mlckFREEPXD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) pxdlock = (struct pxd_lock *) maplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) xaddr = addressPXD(&pxdlock->pxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) xlen = lengthPXD(&pxdlock->pxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) dbFree(ip, xaddr, (s64) xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) jfs_info("freeWMap: xaddr:0x%lx xlen:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) (ulong) xaddr, xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) } else { /* (maplock->flag & mlckFREEPXDLIST) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) pxdlistlock = (struct xdlistlock *) maplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) pxd = pxdlistlock->xdlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) for (n = 0; n < pxdlistlock->count; n++, pxd++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) xaddr = addressPXD(pxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) xlen = lengthPXD(pxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) dbFree(ip, xaddr, (s64) xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) jfs_info("freeWMap: xaddr:0x%lx xlen:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) (ulong) xaddr, xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) * txFreelock()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) * function: remove tlock from inode anonymous locklist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) void txFreelock(struct inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) struct jfs_inode_info *jfs_ip = JFS_IP(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) struct tlock *xtlck, *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) lid_t xlid = 0, lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) if (!jfs_ip->atlhead)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) xtlck = (struct tlock *) &jfs_ip->atlhead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) while ((lid = xtlck->next) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) tlck = lid_to_tlock(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) if (tlck->flag & tlckFREELOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) xtlck->next = tlck->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) txLockFree(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) xtlck = tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) xlid = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) if (jfs_ip->atlhead)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) jfs_ip->atltail = xlid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) jfs_ip->atltail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) * If inode was on anon_list, remove it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) list_del_init(&jfs_ip->anon_inode_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) * txAbort()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) * function: abort tx before commit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) * frees line-locks and segment locks for all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) * segments in comdata structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) * Optionally sets state of file-system to FM_DIRTY in super-block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) * log age of page-frames in memory for which caller has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) * are reset to 0 (to avoid logwarap).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) void txAbort(tid_t tid, int dirty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) lid_t lid, next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) struct tblock *tblk = tid_to_tblock(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) * free tlocks of the transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) for (lid = tblk->next; lid; lid = next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) tlck = lid_to_tlock(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) next = tlck->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) mp = tlck->mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) JFS_IP(tlck->ip)->xtlid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) if (mp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) mp->lid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) * reset lsn of page to avoid logwarap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) * (page may have been previously committed by another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) * transaction(s) but has not been paged, i.e.,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) * it may be on logsync list even though it has not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) * been logged for the current tx.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) if (mp->xflag & COMMIT_PAGE && mp->lsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) LogSyncRelease(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) /* insert tlock at head of freelist */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) txLockFree(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) /* caller will free the transaction block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) tblk->next = tblk->last = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) * mark filesystem dirty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) if (dirty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) jfs_error(tblk->sb, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) * txLazyCommit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) * All transactions except those changing ipimap (COMMIT_FORCE) are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) * processed by this routine. This insures that the inode and block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) * allocation maps are updated in order. For synchronous transactions,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) * let the user thread finish processing after txUpdateMap() is called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) static void txLazyCommit(struct tblock * tblk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) struct jfs_log *log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) while (((tblk->flag & tblkGC_READY) == 0) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) ((tblk->flag & tblkGC_UNLOCKED) == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) /* We must have gotten ahead of the user thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) jfs_info("jfs_lazycommit: tblk 0x%p not unlocked", tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) yield();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) jfs_info("txLazyCommit: processing tblk 0x%p", tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) txUpdateMap(tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) log = (struct jfs_log *) JFS_SBI(tblk->sb)->log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) spin_lock_irq(&log->gclock); // LOGGC_LOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) tblk->flag |= tblkGC_COMMITTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) if (tblk->flag & tblkGC_READY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) log->gcrtc--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) wake_up_all(&tblk->gcwait); // LOGGC_WAKEUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) * Can't release log->gclock until we've tested tblk->flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) if (tblk->flag & tblkGC_LAZY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) spin_unlock_irq(&log->gclock); // LOGGC_UNLOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) txUnlock(tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) tblk->flag &= ~tblkGC_LAZY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) txEnd(tblk - TxBlock); /* Convert back to tid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) spin_unlock_irq(&log->gclock); // LOGGC_UNLOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) jfs_info("txLazyCommit: done: tblk = 0x%p", tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) * jfs_lazycommit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) * To be run as a kernel daemon. If lbmIODone is called in an interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) * context, or where blocking is not wanted, this routine will process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) * committed transactions from the unlock queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) int jfs_lazycommit(void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) int WorkDone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) struct tblock *tblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) struct jfs_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) LAZY_LOCK(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) jfs_commit_thread_waking = 0; /* OK to wake another thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) while (!list_empty(&TxAnchor.unlock_queue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) WorkDone = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) list_for_each_entry(tblk, &TxAnchor.unlock_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) cqueue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) sbi = JFS_SBI(tblk->sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) * For each volume, the transactions must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) * handled in order. If another commit thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) * is handling a tblk for this superblock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) * skip it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) if (sbi->commit_state & IN_LAZYCOMMIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) sbi->commit_state |= IN_LAZYCOMMIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) WorkDone = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) * Remove transaction from queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) list_del(&tblk->cqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) LAZY_UNLOCK(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) txLazyCommit(tblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) LAZY_LOCK(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) sbi->commit_state &= ~IN_LAZYCOMMIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) * Don't continue in the for loop. (We can't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) * anyway, it's unsafe!) We want to go back to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) * the beginning of the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) /* If there was nothing to do, don't continue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) if (!WorkDone)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) /* In case a wakeup came while all threads were active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) jfs_commit_thread_waking = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) if (freezing(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) LAZY_UNLOCK(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) try_to_freeze();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) DECLARE_WAITQUEUE(wq, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) add_wait_queue(&jfs_commit_thread_wait, &wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) LAZY_UNLOCK(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) remove_wait_queue(&jfs_commit_thread_wait, &wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) } while (!kthread_should_stop());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) if (!list_empty(&TxAnchor.unlock_queue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) jfs_err("jfs_lazycommit being killed w/pending transactions!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) jfs_info("jfs_lazycommit being killed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) void txLazyUnlock(struct tblock * tblk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) LAZY_LOCK(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) list_add_tail(&tblk->cqueue, &TxAnchor.unlock_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) * Don't wake up a commit thread if there is already one servicing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) * this superblock, or if the last one we woke up hasn't started yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) if (!(JFS_SBI(tblk->sb)->commit_state & IN_LAZYCOMMIT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) !jfs_commit_thread_waking) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) jfs_commit_thread_waking = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) wake_up(&jfs_commit_thread_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) LAZY_UNLOCK(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) static void LogSyncRelease(struct metapage * mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) struct jfs_log *log = mp->log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) assert(mp->nohomeok);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) assert(log);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) metapage_homeok(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) * txQuiesce
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) * Block all new transactions and push anonymous transactions to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) * completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) * This does almost the same thing as jfs_sync below. We don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) * worry about deadlocking when jfs_tlocks_low is set, since we would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) * expect jfs_sync to get us out of that jam.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) void txQuiesce(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) struct inode *ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) struct jfs_inode_info *jfs_ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) struct jfs_log *log = JFS_SBI(sb)->log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) tid_t tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) set_bit(log_QUIESCE, &log->flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) restart:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) while (!list_empty(&TxAnchor.anon_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) jfs_ip = list_entry(TxAnchor.anon_list.next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) struct jfs_inode_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) anon_inode_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) ip = &jfs_ip->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) * inode will be removed from anonymous list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) * when it is committed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) tid = txBegin(ip->i_sb, COMMIT_INODE | COMMIT_FORCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) mutex_lock(&jfs_ip->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) txCommit(tid, 1, &ip, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) txEnd(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) mutex_unlock(&jfs_ip->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) * Just to be safe. I don't know how
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) * long we can run without blocking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) * If jfs_sync is running in parallel, there could be some inodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) * on anon_list2. Let's check.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) if (!list_empty(&TxAnchor.anon_list2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) list_splice_init(&TxAnchor.anon_list2, &TxAnchor.anon_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) goto restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) * We may need to kick off the group commit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) jfs_flush_journal(log, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) * txResume()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) * Allows transactions to start again following txQuiesce
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) void txResume(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) struct jfs_log *log = JFS_SBI(sb)->log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) clear_bit(log_QUIESCE, &log->flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) TXN_WAKEUP(&log->syncwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) * jfs_sync(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) * To be run as a kernel daemon. This is awakened when tlocks run low.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) * We write any inodes that have anonymous tlocks so they will become
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) * available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) int jfs_sync(void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) struct inode *ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) struct jfs_inode_info *jfs_ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) tid_t tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) * write each inode on the anonymous inode list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) while (jfs_tlocks_low && !list_empty(&TxAnchor.anon_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) jfs_ip = list_entry(TxAnchor.anon_list.next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) struct jfs_inode_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) anon_inode_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) ip = &jfs_ip->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) if (! igrab(ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) * Inode is being freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) list_del_init(&jfs_ip->anon_inode_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) } else if (mutex_trylock(&jfs_ip->commit_mutex)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) * inode will be removed from anonymous list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) * when it is committed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) tid = txBegin(ip->i_sb, COMMIT_INODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) txCommit(tid, 1, &ip, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) txEnd(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) mutex_unlock(&jfs_ip->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) iput(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) * Just to be safe. I don't know how
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) * long we can run without blocking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) /* We can't get the commit mutex. It may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) * be held by a thread waiting for tlock's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) * so let's not block here. Save it to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) * put back on the anon_list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) /* Move from anon_list to anon_list2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) list_move(&jfs_ip->anon_inode_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) &TxAnchor.anon_list2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) iput(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) TXN_LOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) /* Add anon_list2 back to anon_list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) list_splice_init(&TxAnchor.anon_list2, &TxAnchor.anon_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) if (freezing(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) try_to_freeze();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) TXN_UNLOCK();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) } while (!kthread_should_stop());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) jfs_info("jfs_sync being killed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) #if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_DEBUG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) int jfs_txanchor_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) char *freewait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) char *freelockwait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) char *lowlockwait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) freewait =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) waitqueue_active(&TxAnchor.freewait) ? "active" : "empty";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) freelockwait =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) waitqueue_active(&TxAnchor.freelockwait) ? "active" : "empty";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) lowlockwait =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) waitqueue_active(&TxAnchor.lowlockwait) ? "active" : "empty";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) seq_printf(m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) "JFS TxAnchor\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) "============\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) "freetid = %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) "freewait = %s\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) "freelock = %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) "freelockwait = %s\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) "lowlockwait = %s\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) "tlocksInUse = %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) "jfs_tlocks_low = %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) "unlock_queue is %sempty\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) TxAnchor.freetid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) freewait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) TxAnchor.freelock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) freelockwait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) lowlockwait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) TxAnchor.tlocksInUse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) jfs_tlocks_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) list_empty(&TxAnchor.unlock_queue) ? "" : "not ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) #if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_STATISTICS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) int jfs_txstats_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) seq_printf(m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) "JFS TxStats\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) "===========\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) "calls to txBegin = %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) "txBegin blocked by sync barrier = %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) "txBegin blocked by tlocks low = %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) "txBegin blocked by no free tid = %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) "calls to txBeginAnon = %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) "txBeginAnon blocked by sync barrier = %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) "txBeginAnon blocked by tlocks low = %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) "calls to txLockAlloc = %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) "tLockAlloc blocked by no free lock = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) TxStat.txBegin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) TxStat.txBegin_barrier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) TxStat.txBegin_lockslow,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) TxStat.txBegin_freetid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) TxStat.txBeginAnon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) TxStat.txBeginAnon_barrier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) TxStat.txBeginAnon_lockslow,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) TxStat.txLockAlloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) TxStat.txLockAlloc_freelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) #endif