^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) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * jfs_xtree.c: extent allocation descriptor B+-tree manager
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/quotaops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "jfs_incore.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "jfs_filsys.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "jfs_metapage.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "jfs_dmap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "jfs_dinode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "jfs_superblock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "jfs_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * xtree local flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define XT_INSERT 0x00000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * xtree key/entry comparison: extent offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * -1: k < start of extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * 0: start_of_extent <= k <= end_of_extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * 1: k > end_of_extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define XT_CMP(CMP, K, X, OFFSET64)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) OFFSET64 = offsetXAD(X);\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) (CMP) = ((K) >= OFFSET64 + lengthXAD(X)) ? 1 :\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) ((K) < OFFSET64) ? -1 : 0;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* write a xad entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define XT_PUTENTRY(XAD, FLAG, OFF, LEN, ADDR)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) (XAD)->flag = (FLAG);\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) XADoffset((XAD), (OFF));\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) XADlength((XAD), (LEN));\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) XADaddress((XAD), (ADDR));\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define XT_PAGE(IP, MP) BT_PAGE(IP, MP, xtpage_t, i_xtroot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* get page buffer for specified block address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /* ToDo: Replace this ugly macro with a function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define XT_GETPAGE(IP, BN, MP, SIZE, P, RC) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) BT_GETPAGE(IP, BN, MP, xtpage_t, SIZE, P, RC, i_xtroot); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (!(RC)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if ((le16_to_cpu((P)->header.nextindex) < XTENTRYSTART) || \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) (le16_to_cpu((P)->header.nextindex) > \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) le16_to_cpu((P)->header.maxentry)) || \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) (le16_to_cpu((P)->header.maxentry) > \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) (((BN) == 0) ? XTROOTMAXSLOT : PSIZE >> L2XTSLOTSIZE))) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) jfs_error((IP)->i_sb, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) "XT_GETPAGE: xtree page corrupt\n"); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) BT_PUTPAGE(MP); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) MP = NULL; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) RC = -EIO; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* for consistency */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define XT_PUTPAGE(MP) BT_PUTPAGE(MP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define XT_GETSEARCH(IP, LEAF, BN, MP, P, INDEX) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) BT_GETSEARCH(IP, LEAF, BN, MP, xtpage_t, P, INDEX, i_xtroot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* xtree entry parameter descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct xtsplit {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) s16 index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) u8 flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) s64 off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) s64 addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct pxdlist *pxdlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * statistics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #ifdef CONFIG_JFS_STATISTICS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) uint search;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) uint fastSearch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) uint split;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) } xtStat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #endif
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * forward references
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static int xtSearch(struct inode *ip, s64 xoff, s64 *next, int *cmpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct btstack * btstack, int flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static int xtSplitUp(tid_t tid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct xtsplit * split, struct btstack * btstack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int xtSplitPage(tid_t tid, struct inode *ip, struct xtsplit * split,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct metapage ** rmpp, s64 * rbnp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static int xtSplitRoot(tid_t tid, struct inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct xtsplit * split, struct metapage ** rmpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #ifdef _STILL_TO_PORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static int xtDeleteUp(tid_t tid, struct inode *ip, struct metapage * fmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) xtpage_t * fp, struct btstack * btstack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static int xtSearchNode(struct inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) xad_t * xad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) int *cmpp, struct btstack * btstack, int flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static int xtRelink(tid_t tid, struct inode *ip, xtpage_t * fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #endif /* _STILL_TO_PORT */
^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) * xtLookup()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * function: map a single page into a physical extent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) int xtLookup(struct inode *ip, s64 lstart,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) s64 llen, int *pflag, s64 * paddr, s32 * plen, int no_check)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct btstack btstack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int cmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) s64 bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) xtpage_t *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) xad_t *xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) s64 next, size, xoff, xend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) s64 xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) *paddr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) *plen = llen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (!no_check) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /* is lookup offset beyond eof ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) size = ((u64) ip->i_size + (JFS_SBI(ip->i_sb)->bsize - 1)) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) JFS_SBI(ip->i_sb)->l2bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (lstart >= size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * search for the xad entry covering the logical extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) //search:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if ((rc = xtSearch(ip, lstart, &next, &cmp, &btstack, 0))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) jfs_err("xtLookup: xtSearch returned %d", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * compute the physical extent covering logical extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * N.B. search may have failed (e.g., hole in sparse file),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * and returned the index of the next entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /* retrieve search result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) XT_GETSEARCH(ip, btstack.top, bn, mp, p, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* is xad found covering start of logical extent ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * lstart is a page start address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * i.e., lstart cannot start in a hole;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (cmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) *plen = min(next - lstart, llen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * lxd covered by xad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) xad = &p->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) xoff = offsetXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) xlen = lengthXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) xend = xoff + xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) xaddr = addressXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /* initialize new pxd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) *pflag = xad->flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) *paddr = xaddr + (lstart - xoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* a page must be fully covered by an xad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) *plen = min(xend - lstart, llen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * xtSearch()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * function: search for the xad entry covering specified offset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * parameters:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * ip - file object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * xoff - extent offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * nextp - address of next extent (if any) for search miss
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * cmpp - comparison result:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * btstack - traverse stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * flag - search process flag (XT_INSERT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * btstack contains (bn, index) of search path traversed to the entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * *cmpp is set to result of comparison with the entry returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * the page containing the entry is pinned at exit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static int xtSearch(struct inode *ip, s64 xoff, s64 *nextp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) int *cmpp, struct btstack * btstack, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct jfs_inode_info *jfs_ip = JFS_IP(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) int cmp = 1; /* init for empty page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) s64 bn; /* block number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct metapage *mp; /* page buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) xtpage_t *p; /* page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) xad_t *xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) int base, index, lim, btindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct btframe *btsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) int nsplit = 0; /* number of pages to split */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) s64 t64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) s64 next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) INCREMENT(xtStat.search);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) BT_CLR(btstack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) btstack->nsplit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * search down tree from root:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * between two consecutive entries of <Ki, Pi> and <Kj, Pj> of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * internal page, child page Pi contains entry with k, Ki <= K < Kj.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * if entry with search key K is not found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * internal page search find the entry with largest key Ki
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * less than K which point to the child page to search;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * leaf page search find the entry with smallest key Kj
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * greater than K so that the returned index is the position of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * the entry to be shifted right for insertion of new entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * for empty tree, search key is greater than any key of the tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * by convention, root bn = 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) for (bn = 0;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) /* get/pin the page to search */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /* try sequential access heuristics with the previous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * access entry in target leaf page:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * once search narrowed down into the target leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * key must either match an entry in the leaf or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * key entry does not exist in the tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) //fastSearch:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if ((jfs_ip->btorder & BT_SEQUENTIAL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) (p->header.flag & BT_LEAF) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) (index = jfs_ip->btindex) <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) le16_to_cpu(p->header.nextindex)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) xad = &p->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) t64 = offsetXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (xoff < t64 + lengthXAD(xad)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (xoff >= t64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) *cmpp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /* stop sequential access heuristics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) goto binarySearch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) } else { /* (t64 + lengthXAD(xad)) <= xoff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /* try next sequential entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (index <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) le16_to_cpu(p->header.nextindex)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) xad++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) t64 = offsetXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if (xoff < t64 + lengthXAD(xad)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (xoff >= t64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) *cmpp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) /* miss: key falls between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * previous and this entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) *cmpp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) next = t64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) /* (xoff >= t64 + lengthXAD(xad));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * matching entry may be further out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * stop heuristic search
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /* stop sequential access heuristics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) goto binarySearch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) /* (index == p->header.nextindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) * miss: key entry does not exist in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * the target leaf/tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) *cmpp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * if hit, return index of the entry found, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * if miss, where new entry with search key is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * to be inserted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /* compute number of pages to split */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (flag & XT_INSERT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) if (p->header.nextindex == /* little-endian */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) p->header.maxentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) nsplit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) nsplit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) btstack->nsplit = nsplit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) /* save search result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) btsp = btstack->top;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) btsp->bn = bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) btsp->index = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) btsp->mp = mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /* update sequential access heuristics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) jfs_ip->btindex = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (nextp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) *nextp = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) INCREMENT(xtStat.fastSearch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /* well, ... full search now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) binarySearch:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) lim = le16_to_cpu(p->header.nextindex) - XTENTRYSTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * binary search with search key K on the current page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) for (base = XTENTRYSTART; lim; lim >>= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) index = base + (lim >> 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) XT_CMP(cmp, xoff, &p->xad[index], t64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (cmp == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) * search hit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) /* search hit - leaf page:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * return the entry found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (p->header.flag & BT_LEAF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) *cmpp = cmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) /* compute number of pages to split */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (flag & XT_INSERT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) if (p->header.nextindex ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) p->header.maxentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) nsplit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) nsplit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) btstack->nsplit = nsplit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /* save search result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) btsp = btstack->top;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) btsp->bn = bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) btsp->index = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) btsp->mp = mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) /* init sequential access heuristics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) btindex = jfs_ip->btindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) if (index == btindex ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) index == btindex + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) jfs_ip->btorder = BT_SEQUENTIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) jfs_ip->btorder = BT_RANDOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) jfs_ip->btindex = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) /* search hit - internal page:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) * descend/search its child page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if (index < le16_to_cpu(p->header.nextindex)-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) next = offsetXAD(&p->xad[index + 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) if (cmp > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) base = index + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) --lim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) * search miss
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) * base is the smallest index with key (Kj) greater than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) * search key (K) and may be zero or maxentry index.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) if (base < le16_to_cpu(p->header.nextindex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) next = offsetXAD(&p->xad[base]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) * search miss - leaf page:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) * return location of entry (base) where new entry with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) * search key K is to be inserted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (p->header.flag & BT_LEAF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) *cmpp = cmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /* compute number of pages to split */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (flag & XT_INSERT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (p->header.nextindex ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) p->header.maxentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) nsplit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) nsplit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) btstack->nsplit = nsplit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /* save search result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) btsp = btstack->top;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) btsp->bn = bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) btsp->index = base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) btsp->mp = mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) /* init sequential access heuristics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) btindex = jfs_ip->btindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if (base == btindex || base == btindex + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) jfs_ip->btorder = BT_SEQUENTIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) jfs_ip->btorder = BT_RANDOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) jfs_ip->btindex = base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) if (nextp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) *nextp = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * search miss - non-leaf page:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) * if base is non-zero, decrement base by one to get the parent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * entry of the child page to search.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) index = base ? base - 1 : base;
^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) * go down to child page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) /* update number of pages to split */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (p->header.nextindex == p->header.maxentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) nsplit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) nsplit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) /* push (bn, index) of the parent page/entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (BT_STACK_FULL(btstack)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) jfs_error(ip->i_sb, "stack overrun!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) BT_PUSH(btstack, bn, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) /* get the child page block number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) bn = addressXAD(&p->xad[index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) /* unpin the parent page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) * xtInsert()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) * function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) * parameter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) * tid - transaction id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) * ip - file object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) * xflag - extent flag (XAD_NOTRECORDED):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) * xoff - extent offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) * xlen - extent length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * xaddrp - extent address pointer (in/out):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) * if (*xaddrp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) * caller allocated data extent at *xaddrp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) * else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * allocate data extent and return its xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) * flag -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) * return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) int xtInsert(tid_t tid, /* transaction id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) struct inode *ip, int xflag, s64 xoff, s32 xlen, s64 * xaddrp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) s64 xaddr, hint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) struct metapage *mp; /* meta-page buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) xtpage_t *p; /* base B+-tree index page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) s64 bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) int index, nextindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) struct btstack btstack; /* traverse stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) struct xtsplit split; /* split information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) xad_t *xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) int cmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) s64 next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) struct xtlock *xtlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) jfs_info("xtInsert: nxoff:0x%lx nxlen:0x%x", (ulong) xoff, xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) * search for the entry location at which to insert:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * xtFastSearch() and xtSearch() both returns (leaf page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) * pinned, index at which to insert).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) * n.b. xtSearch() may return index of maxentry of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) * the full page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) if ((rc = xtSearch(ip, xoff, &next, &cmp, &btstack, XT_INSERT)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) /* retrieve search result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) XT_GETSEARCH(ip, btstack.top, bn, mp, p, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) /* This test must follow XT_GETSEARCH since mp must be valid if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) * we branch to out: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) if ((cmp == 0) || (next && (xlen > next - xoff))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) rc = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^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) * allocate data extent requested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) * allocation hint: last xad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if ((xaddr = *xaddrp) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) if (index > XTENTRYSTART) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) xad = &p->xad[index - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) hint = addressXAD(xad) + lengthXAD(xad) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) hint = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) if ((rc = dquot_alloc_block(ip, xlen)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) dquot_free_block(ip, xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) * insert entry for new extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) xflag |= XAD_NEW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) * if the leaf page is full, split the page and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) * propagate up the router entry for the new page from split
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) * The xtSplitUp() will insert the entry and unpin the leaf page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) nextindex = le16_to_cpu(p->header.nextindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) if (nextindex == le16_to_cpu(p->header.maxentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) split.mp = mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) split.index = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) split.flag = xflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) split.off = xoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) split.len = xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) split.addr = xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) split.pxdlist = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) if ((rc = xtSplitUp(tid, ip, &split, &btstack))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) /* undo data extent allocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) if (*xaddrp == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) dbFree(ip, xaddr, (s64) xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) dquot_free_block(ip, xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) *xaddrp = xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return 0;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) * insert the new entry into the leaf page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) * acquire a transaction lock on the leaf page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) * action: xad insertion/extension;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) /* if insert into middle, shift right remaining entries. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) if (index < nextindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) memmove(&p->xad[index + 1], &p->xad[index],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) (nextindex - index) * sizeof(xad_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) /* insert the new entry: mark the entry NEW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) xad = &p->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) XT_PUTENTRY(xad, xflag, xoff, xlen, xaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) /* advance next available entry index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) le16_add_cpu(&p->header.nextindex, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) /* Don't log it if there are no links to the file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) tlck = txLock(tid, ip, mp, tlckXTREE | tlckGROW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) xtlck->lwm.offset =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) (xtlck->lwm.offset) ? min(index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) (int)xtlck->lwm.offset) : index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) xtlck->lwm.length =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) le16_to_cpu(p->header.nextindex) - xtlck->lwm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) *xaddrp = xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) /* unpin the leaf page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) * xtSplitUp()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) * function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) * split full pages as propagating insertion up the tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) * parameter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) * tid - transaction id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) * ip - file object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) * split - entry parameter descriptor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) * btstack - traverse stack from xtSearch()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) * return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) xtSplitUp(tid_t tid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) struct inode *ip, struct xtsplit * split, struct btstack * btstack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) struct metapage *smp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) xtpage_t *sp; /* split page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) struct metapage *rmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) s64 rbn; /* new right page block number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) struct metapage *rcmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) xtpage_t *rcp; /* right child page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) s64 rcbn; /* right child page block number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) int skip; /* index of entry of insertion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) int nextindex; /* next available entry index of p */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) struct btframe *parent; /* parent page entry on traverse stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) xad_t *xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) s64 xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) int xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) int nsplit; /* number of pages split */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) struct pxdlist pxdlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) pxd_t *pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) struct xtlock *xtlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) smp = split->mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) sp = XT_PAGE(ip, smp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) /* is inode xtree root extension/inline EA area free ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) if ((sp->header.flag & BT_ROOT) && (!S_ISDIR(ip->i_mode)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) (le16_to_cpu(sp->header.maxentry) < XTROOTMAXSLOT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) (JFS_IP(ip)->mode2 & INLINEEA)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) sp->header.maxentry = cpu_to_le16(XTROOTMAXSLOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) JFS_IP(ip)->mode2 &= ~INLINEEA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) BT_MARK_DIRTY(smp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) * acquire a transaction lock on the leaf page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) * action: xad insertion/extension;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) /* if insert into middle, shift right remaining entries. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) skip = split->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) nextindex = le16_to_cpu(sp->header.nextindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) if (skip < nextindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) memmove(&sp->xad[skip + 1], &sp->xad[skip],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) (nextindex - skip) * sizeof(xad_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) /* insert the new entry: mark the entry NEW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) xad = &sp->xad[skip];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) XT_PUTENTRY(xad, split->flag, split->off, split->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) split->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) /* advance next available entry index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) le16_add_cpu(&sp->header.nextindex, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) /* Don't log it if there are no links to the file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) tlck = txLock(tid, ip, smp, tlckXTREE | tlckGROW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) xtlck->lwm.offset = (xtlck->lwm.offset) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) min(skip, (int)xtlck->lwm.offset) : skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) xtlck->lwm.length =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) le16_to_cpu(sp->header.nextindex) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) xtlck->lwm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) * allocate new index blocks to cover index page split(s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) * allocation hint: ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) if (split->pxdlist == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) nsplit = btstack->nsplit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) split->pxdlist = &pxdlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) pxdlist.maxnpxd = pxdlist.npxd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) pxd = &pxdlist.pxd[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) xlen = JFS_SBI(ip->i_sb)->nbperpage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) for (; nsplit > 0; nsplit--, pxd++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) if ((rc = dbAlloc(ip, (s64) 0, (s64) xlen, &xaddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) PXDaddress(pxd, xaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) PXDlength(pxd, xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) pxdlist.maxnpxd++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) /* undo allocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) XT_PUTPAGE(smp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) * Split leaf page <sp> into <sp> and a new right page <rp>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) * The split routines insert the new entry into the leaf page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) * and acquire txLock as appropriate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) * return <rp> pinned and its block number <rpbn>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) rc = (sp->header.flag & BT_ROOT) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) xtSplitRoot(tid, ip, split, &rmp) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) xtSplitPage(tid, ip, split, &rmp, &rbn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) XT_PUTPAGE(smp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) * propagate up the router entry for the leaf page just split
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) * insert a router entry for the new page into the parent page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) * propagate the insert/split up the tree by walking back the stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) * of (bn of parent page, index of child page entry in parent page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) * that were traversed during the search for the page that split.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) * the propagation of insert/split up the tree stops if the root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) * splits or the page inserted into doesn't have to split to hold
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) * the new entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) * the parent entry for the split page remains the same, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) * a new entry is inserted at its right with the first key and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) * block number of the new right page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) * There are a maximum of 3 pages pinned at any time:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) * right child, left parent and right parent (when the parent splits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) * to keep the child page pinned while working on the parent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) * make sure that all pins are released at exit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) while ((parent = BT_POP(btstack)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) /* parent page specified by stack frame <parent> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) /* keep current child pages <rcp> pinned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) rcmp = rmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) rcbn = rbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) rcp = XT_PAGE(ip, rcmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) * insert router entry in parent for new right child page <rp>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) /* get/pin the parent page <sp> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) XT_GETPAGE(ip, parent->bn, smp, PSIZE, sp, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) XT_PUTPAGE(rcmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) * The new key entry goes ONE AFTER the index of parent entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) * because the split was to the right.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) skip = parent->index + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) * split or shift right remaining entries of the parent page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) nextindex = le16_to_cpu(sp->header.nextindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) * parent page is full - split the parent page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) if (nextindex == le16_to_cpu(sp->header.maxentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) /* init for parent page split */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) split->mp = smp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) split->index = skip; /* index at insert */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) split->flag = XAD_NEW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) split->off = offsetXAD(&rcp->xad[XTENTRYSTART]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) split->len = JFS_SBI(ip->i_sb)->nbperpage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) split->addr = rcbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) /* unpin previous right child page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) XT_PUTPAGE(rcmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) /* The split routines insert the new entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) * and acquire txLock as appropriate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) * return <rp> pinned and its block number <rpbn>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) rc = (sp->header.flag & BT_ROOT) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) xtSplitRoot(tid, ip, split, &rmp) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) xtSplitPage(tid, ip, split, &rmp, &rbn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) XT_PUTPAGE(smp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) XT_PUTPAGE(smp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) /* keep new child page <rp> pinned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) * parent page is not full - insert in parent page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) * insert router entry in parent for the right child
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) * page from the first entry of the right child page:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) * acquire a transaction lock on the parent page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) * action: router xad insertion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) BT_MARK_DIRTY(smp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) * if insert into middle, shift right remaining entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) if (skip < nextindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) memmove(&sp->xad[skip + 1], &sp->xad[skip],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) (nextindex -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) skip) << L2XTSLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) /* insert the router entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) xad = &sp->xad[skip];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) XT_PUTENTRY(xad, XAD_NEW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) offsetXAD(&rcp->xad[XTENTRYSTART]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) JFS_SBI(ip->i_sb)->nbperpage, rcbn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) /* advance next available entry index. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) le16_add_cpu(&sp->header.nextindex, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) /* Don't log it if there are no links to the file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) tlck = txLock(tid, ip, smp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) tlckXTREE | tlckGROW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) xtlck->lwm.offset = (xtlck->lwm.offset) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) min(skip, (int)xtlck->lwm.offset) : skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) xtlck->lwm.length =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) le16_to_cpu(sp->header.nextindex) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) xtlck->lwm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) /* unpin parent page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) XT_PUTPAGE(smp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) /* exit propagate up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) /* unpin current right page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) XT_PUTPAGE(rmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) * xtSplitPage()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) * function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) * split a full non-root page into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) * original/split/left page and new right page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) * i.e., the original/split page remains as left page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) * parameter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) * int tid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) * struct inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) * struct xtsplit *split,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) * struct metapage **rmpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) * u64 *rbnp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) * return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) * Pointer to page in which to insert or NULL on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) xtSplitPage(tid_t tid, struct inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) struct xtsplit * split, struct metapage ** rmpp, s64 * rbnp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) struct metapage *smp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) xtpage_t *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) struct metapage *rmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) xtpage_t *rp; /* new right page allocated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) s64 rbn; /* new right page block number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) xtpage_t *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) s64 nextbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) int skip, maxentry, middle, righthalf, n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) xad_t *xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) struct pxdlist *pxdlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) pxd_t *pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) struct xtlock *sxtlck = NULL, *rxtlck = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) int quota_allocation = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) smp = split->mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) sp = XT_PAGE(ip, smp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) INCREMENT(xtStat.split);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) pxdlist = split->pxdlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) pxd = &pxdlist->pxd[pxdlist->npxd];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) pxdlist->npxd++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) rbn = addressPXD(pxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) /* Allocate blocks to quota. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) rc = dquot_alloc_block(ip, lengthPXD(pxd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) goto clean_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) quota_allocation += lengthPXD(pxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) * allocate the new right page for the split
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) rmp = get_metapage(ip, rbn, PSIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) if (rmp == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) goto clean_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) jfs_info("xtSplitPage: ip:0x%p smp:0x%p rmp:0x%p", ip, smp, rmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) BT_MARK_DIRTY(rmp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) * action: new page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) rp = (xtpage_t *) rmp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) rp->header.self = *pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) rp->header.flag = sp->header.flag & BT_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) rp->header.maxentry = sp->header.maxentry; /* little-endian */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) rp->header.nextindex = cpu_to_le16(XTENTRYSTART);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) BT_MARK_DIRTY(smp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) /* Don't log it if there are no links to the file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) * acquire a transaction lock on the new right page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) tlck = txLock(tid, ip, rmp, tlckXTREE | tlckNEW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) rxtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) rxtlck->lwm.offset = XTENTRYSTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) * acquire a transaction lock on the split page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) tlck = txLock(tid, ip, smp, tlckXTREE | tlckGROW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) sxtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) * initialize/update sibling pointers of <sp> and <rp>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) nextbn = le64_to_cpu(sp->header.next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) rp->header.next = cpu_to_le64(nextbn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) rp->header.prev = cpu_to_le64(addressPXD(&sp->header.self));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) sp->header.next = cpu_to_le64(rbn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) skip = split->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) * sequential append at tail (after last entry of last page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) * if splitting the last page on a level because of appending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) * a entry to it (skip is maxentry), it's likely that the access is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) * sequential. adding an empty page on the side of the level is less
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) * work and can push the fill factor much higher than normal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) * if we're wrong it's no big deal - we will do the split the right
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) * way next time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) * (it may look like it's equally easy to do a similar hack for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) * reverse sorted data, that is, split the tree left, but it's not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) * Be my guest.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) if (nextbn == 0 && skip == le16_to_cpu(sp->header.maxentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) * acquire a transaction lock on the new/right page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) * action: xad insertion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) /* insert entry at the first entry of the new right page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) xad = &rp->xad[XTENTRYSTART];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) XT_PUTENTRY(xad, split->flag, split->off, split->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) split->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) rp->header.nextindex = cpu_to_le16(XTENTRYSTART + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) /* rxtlck->lwm.offset = XTENTRYSTART; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) rxtlck->lwm.length = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) *rmpp = rmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) *rbnp = rbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) jfs_info("xtSplitPage: sp:0x%p rp:0x%p", sp, rp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) * non-sequential insert (at possibly middle page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) * update previous pointer of old next/right page of <sp>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) if (nextbn != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) XT_GETPAGE(ip, nextbn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) XT_PUTPAGE(rmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) goto clean_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) * acquire a transaction lock on the next page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) * action:sibling pointer update;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) if (!test_cflag(COMMIT_Nolink, ip))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) tlck = txLock(tid, ip, mp, tlckXTREE | tlckRELINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) p->header.prev = cpu_to_le64(rbn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) /* sibling page may have been updated previously, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) * it may be updated later;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) * split the data between the split and new/right pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) maxentry = le16_to_cpu(sp->header.maxentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) middle = maxentry >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) righthalf = maxentry - middle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) * skip index in old split/left page - insert into left page:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) if (skip <= middle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) /* move right half of split page to the new right page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) memmove(&rp->xad[XTENTRYSTART], &sp->xad[middle],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) righthalf << L2XTSLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) /* shift right tail of left half to make room for new entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) if (skip < middle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) memmove(&sp->xad[skip + 1], &sp->xad[skip],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) (middle - skip) << L2XTSLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) /* insert new entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) xad = &sp->xad[skip];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) XT_PUTENTRY(xad, split->flag, split->off, split->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) split->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) /* update page header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) sp->header.nextindex = cpu_to_le16(middle + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) sxtlck->lwm.offset = (sxtlck->lwm.offset) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) min(skip, (int)sxtlck->lwm.offset) : skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) rp->header.nextindex =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) cpu_to_le16(XTENTRYSTART + righthalf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) * skip index in new right page - insert into right page:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) /* move left head of right half to right page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) n = skip - middle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) memmove(&rp->xad[XTENTRYSTART], &sp->xad[middle],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) n << L2XTSLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) /* insert new entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) n += XTENTRYSTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) xad = &rp->xad[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) XT_PUTENTRY(xad, split->flag, split->off, split->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) split->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) /* move right tail of right half to right page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) if (skip < maxentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) memmove(&rp->xad[n + 1], &sp->xad[skip],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) (maxentry - skip) << L2XTSLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) /* update page header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) sp->header.nextindex = cpu_to_le16(middle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) sxtlck->lwm.offset = (sxtlck->lwm.offset) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) min(middle, (int)sxtlck->lwm.offset) : middle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) rp->header.nextindex = cpu_to_le16(XTENTRYSTART +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) righthalf + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) sxtlck->lwm.length = le16_to_cpu(sp->header.nextindex) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) sxtlck->lwm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) /* rxtlck->lwm.offset = XTENTRYSTART; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) rxtlck->lwm.length = le16_to_cpu(rp->header.nextindex) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) XTENTRYSTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) *rmpp = rmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) *rbnp = rbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) jfs_info("xtSplitPage: sp:0x%p rp:0x%p", sp, rp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) clean_up:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) /* Rollback quota allocation. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) if (quota_allocation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) dquot_free_block(ip, quota_allocation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) * xtSplitRoot()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) * function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) * split the full root page into original/root/split page and new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) * right page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) * i.e., root remains fixed in tree anchor (inode) and the root is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) * copied to a single new right child page since root page <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) * non-root page, and the split root page contains a single entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) * for the new right child page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) * parameter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) * int tid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) * struct inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) * struct xtsplit *split,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) * struct metapage **rmpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) * return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) * Pointer to page in which to insert or NULL on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) xtSplitRoot(tid_t tid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) struct inode *ip, struct xtsplit * split, struct metapage ** rmpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) xtpage_t *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) struct metapage *rmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) xtpage_t *rp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) s64 rbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) int skip, nextindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) xad_t *xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) pxd_t *pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) struct pxdlist *pxdlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) struct xtlock *xtlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) sp = &JFS_IP(ip)->i_xtroot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) INCREMENT(xtStat.split);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) * allocate a single (right) child page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) pxdlist = split->pxdlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) pxd = &pxdlist->pxd[pxdlist->npxd];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) pxdlist->npxd++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) rbn = addressPXD(pxd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) rmp = get_metapage(ip, rbn, PSIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) if (rmp == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) /* Allocate blocks to quota. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) rc = dquot_alloc_block(ip, lengthPXD(pxd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) release_metapage(rmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) jfs_info("xtSplitRoot: ip:0x%p rmp:0x%p", ip, rmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) * acquire a transaction lock on the new right page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) * action: new page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) BT_MARK_DIRTY(rmp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) rp = (xtpage_t *) rmp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) rp->header.flag =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) (sp->header.flag & BT_LEAF) ? BT_LEAF : BT_INTERNAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) rp->header.self = *pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) rp->header.nextindex = cpu_to_le16(XTENTRYSTART);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) rp->header.maxentry = cpu_to_le16(PSIZE >> L2XTSLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) /* initialize sibling pointers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) rp->header.next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) rp->header.prev = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) * copy the in-line root page into new right page extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) nextindex = le16_to_cpu(sp->header.maxentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) memmove(&rp->xad[XTENTRYSTART], &sp->xad[XTENTRYSTART],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) (nextindex - XTENTRYSTART) << L2XTSLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) * insert the new entry into the new right/child page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) * (skip index in the new right page will not change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) skip = split->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) /* if insert into middle, shift right remaining entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) if (skip != nextindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) memmove(&rp->xad[skip + 1], &rp->xad[skip],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) (nextindex - skip) * sizeof(xad_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) xad = &rp->xad[skip];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) XT_PUTENTRY(xad, split->flag, split->off, split->len, split->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) /* update page header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) rp->header.nextindex = cpu_to_le16(nextindex + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) tlck = txLock(tid, ip, rmp, tlckXTREE | tlckNEW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) xtlck->lwm.offset = XTENTRYSTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) xtlck->lwm.length = le16_to_cpu(rp->header.nextindex) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) XTENTRYSTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) * reset the root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) * init root with the single entry for the new right page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) * set the 1st entry offset to 0, which force the left-most key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) * at any level of the tree to be less than any search key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) * acquire a transaction lock on the root page (in-memory inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) * action: root split;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) BT_MARK_DIRTY(split->mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) xad = &sp->xad[XTENTRYSTART];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) XT_PUTENTRY(xad, XAD_NEW, 0, JFS_SBI(ip->i_sb)->nbperpage, rbn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) /* update page header of root */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) sp->header.flag &= ~BT_LEAF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) sp->header.flag |= BT_INTERNAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) sp->header.nextindex = cpu_to_le16(XTENTRYSTART + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) tlck = txLock(tid, ip, split->mp, tlckXTREE | tlckGROW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) xtlck->lwm.offset = XTENTRYSTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) xtlck->lwm.length = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) *rmpp = rmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) jfs_info("xtSplitRoot: sp:0x%p rp:0x%p", sp, rp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) * xtExtend()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) * function: extend in-place;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) * note: existing extent may or may not have been committed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) * caller is responsible for pager buffer cache update, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) * working block allocation map update;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) * update pmap: alloc whole extended extent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) int xtExtend(tid_t tid, /* transaction id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) struct inode *ip, s64 xoff, /* delta extent offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) s32 xlen, /* delta extent length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) int cmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) struct metapage *mp; /* meta-page buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) xtpage_t *p; /* base B+-tree index page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) s64 bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) int index, nextindex, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) struct btstack btstack; /* traverse stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) struct xtsplit split; /* split information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) xad_t *xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) s64 xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) struct xtlock *xtlck = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) jfs_info("xtExtend: nxoff:0x%lx nxlen:0x%x", (ulong) xoff, xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) /* there must exist extent to be extended */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) if ((rc = xtSearch(ip, xoff - 1, NULL, &cmp, &btstack, XT_INSERT)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) /* retrieve search result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) XT_GETSEARCH(ip, btstack.top, bn, mp, p, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) if (cmp != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) jfs_error(ip->i_sb, "xtSearch did not find extent\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) /* extension must be contiguous */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) xad = &p->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) if ((offsetXAD(xad) + lengthXAD(xad)) != xoff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) jfs_error(ip->i_sb, "extension is not contiguous\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) * acquire a transaction lock on the leaf page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) * action: xad insertion/extension;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) tlck = txLock(tid, ip, mp, tlckXTREE | tlckGROW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) /* extend will overflow extent ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) xlen = lengthXAD(xad) + xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) if ((len = xlen - MAXXLEN) <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) goto extendOld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) * extent overflow: insert entry for new extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) //insertNew:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) xoff = offsetXAD(xad) + MAXXLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) xaddr = addressXAD(xad) + MAXXLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) nextindex = le16_to_cpu(p->header.nextindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) * if the leaf page is full, insert the new entry and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) * propagate up the router entry for the new page from split
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) * The xtSplitUp() will insert the entry and unpin the leaf page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) if (nextindex == le16_to_cpu(p->header.maxentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) /* xtSpliUp() unpins leaf pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) split.mp = mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) split.index = index + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) split.flag = XAD_NEW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) split.off = xoff; /* split offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) split.len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) split.addr = xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) split.pxdlist = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) if ((rc = xtSplitUp(tid, ip, &split, &btstack)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) /* get back old page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) * if leaf root has been split, original root has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) * copied to new child page, i.e., original entry now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) * resides on the new child page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) if (p->header.flag & BT_INTERNAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) ASSERT(p->header.nextindex ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) cpu_to_le16(XTENTRYSTART + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) xad = &p->xad[XTENTRYSTART];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) bn = addressXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) /* get new child page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) tlck = txLock(tid, ip, mp, tlckXTREE|tlckGROW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) * insert the new entry into the leaf page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) /* insert the new entry: mark the entry NEW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) xad = &p->xad[index + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) XT_PUTENTRY(xad, XAD_NEW, xoff, len, xaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) /* advance next available entry index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) le16_add_cpu(&p->header.nextindex, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) /* get back old entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) xad = &p->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) xlen = MAXXLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) * extend old extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) extendOld:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) XADlength(xad, xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) if (!(xad->flag & XAD_NEW))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) xad->flag |= XAD_EXTENDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) xtlck->lwm.offset =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) (xtlck->lwm.offset) ? min(index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) (int)xtlck->lwm.offset) : index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) xtlck->lwm.length =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) le16_to_cpu(p->header.nextindex) - xtlck->lwm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) /* unpin the leaf page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) #ifdef _NOTYET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) * xtTailgate()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) * function: split existing 'tail' extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) * (split offset >= start offset of tail extent), and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) * relocate and extend the split tail half;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) * note: existing extent may or may not have been committed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) * caller is responsible for pager buffer cache update, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) * working block allocation map update;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) * update pmap: free old split tail extent, alloc new extent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) int xtTailgate(tid_t tid, /* transaction id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) struct inode *ip, s64 xoff, /* split/new extent offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) s32 xlen, /* new extent length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) s64 xaddr, /* new extent address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) int cmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) struct metapage *mp; /* meta-page buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) xtpage_t *p; /* base B+-tree index page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) s64 bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) int index, nextindex, llen, rlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) struct btstack btstack; /* traverse stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) struct xtsplit split; /* split information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) xad_t *xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) struct xtlock *xtlck = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) struct tlock *mtlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) struct maplock *pxdlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) printf("xtTailgate: nxoff:0x%lx nxlen:0x%x nxaddr:0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) (ulong)xoff, xlen, (ulong)xaddr);
^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) /* there must exist extent to be tailgated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) if ((rc = xtSearch(ip, xoff, NULL, &cmp, &btstack, XT_INSERT)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) /* retrieve search result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) XT_GETSEARCH(ip, btstack.top, bn, mp, p, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) if (cmp != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) jfs_error(ip->i_sb, "couldn't find extent\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) /* entry found must be last entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) nextindex = le16_to_cpu(p->header.nextindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) if (index != nextindex - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) jfs_error(ip->i_sb, "the entry found is not the last entry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) * acquire tlock of the leaf page containing original entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) tlck = txLock(tid, ip, mp, tlckXTREE | tlckGROW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) /* completely replace extent ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) xad = &p->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) printf("xtTailgate: xoff:0x%lx xlen:0x%x xaddr:0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) (ulong)offsetXAD(xad), lengthXAD(xad), (ulong)addressXAD(xad));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) if ((llen = xoff - offsetXAD(xad)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) goto updateOld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) * partially replace extent: insert entry for new extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) //insertNew:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) * if the leaf page is full, insert the new entry and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) * propagate up the router entry for the new page from split
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) * The xtSplitUp() will insert the entry and unpin the leaf page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) if (nextindex == le16_to_cpu(p->header.maxentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) /* xtSpliUp() unpins leaf pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) split.mp = mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) split.index = index + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) split.flag = XAD_NEW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) split.off = xoff; /* split offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) split.len = xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) split.addr = xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) split.pxdlist = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) if ((rc = xtSplitUp(tid, ip, &split, &btstack)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) /* get back old page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) * if leaf root has been split, original root has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) * copied to new child page, i.e., original entry now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) * resides on the new child page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) if (p->header.flag & BT_INTERNAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) ASSERT(p->header.nextindex ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) cpu_to_le16(XTENTRYSTART + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) xad = &p->xad[XTENTRYSTART];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) bn = addressXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) /* get new child page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) tlck = txLock(tid, ip, mp, tlckXTREE|tlckGROW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) * insert the new entry into the leaf page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) /* insert the new entry: mark the entry NEW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) xad = &p->xad[index + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) XT_PUTENTRY(xad, XAD_NEW, xoff, xlen, xaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) /* advance next available entry index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) le16_add_cpu(&p->header.nextindex, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) /* get back old XAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) xad = &p->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) * truncate/relocate old extent at split offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) updateOld:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) /* update dmap for old/committed/truncated extent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) rlen = lengthXAD(xad) - llen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) if (!(xad->flag & XAD_NEW)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) /* free from PWMAP at commit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) mtlck = txMaplock(tid, ip, tlckMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) pxdlock = (struct maplock *) & mtlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) pxdlock->flag = mlckFREEPXD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) PXDaddress(&pxdlock->pxd, addressXAD(xad) + llen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) PXDlength(&pxdlock->pxd, rlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) pxdlock->index = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) /* free from WMAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) dbFree(ip, addressXAD(xad) + llen, (s64) rlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) if (llen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) /* truncate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) XADlength(xad, llen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) /* replace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) XT_PUTENTRY(xad, XAD_NEW, xoff, xlen, xaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) xtlck->lwm.offset = (xtlck->lwm.offset) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) min(index, (int)xtlck->lwm.offset) : index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) xtlck->lwm.length = le16_to_cpu(p->header.nextindex) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) xtlck->lwm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) /* unpin the leaf page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) #endif /* _NOTYET */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) * xtUpdate()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) * function: update XAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) * update extent for allocated_but_not_recorded or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) * compressed extent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) * parameter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) * nxad - new XAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) * logical extent of the specified XAD must be completely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) * contained by an existing XAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) int xtUpdate(tid_t tid, struct inode *ip, xad_t * nxad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) { /* new XAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) int cmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) struct metapage *mp; /* meta-page buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) xtpage_t *p; /* base B+-tree index page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) s64 bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) int index0, index, newindex, nextindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) struct btstack btstack; /* traverse stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) struct xtsplit split; /* split information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) xad_t *xad, *lxad, *rxad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) int xflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) s64 nxoff, xoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) int nxlen, xlen, lxlen, rxlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) s64 nxaddr, xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) struct xtlock *xtlck = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) int newpage = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) /* there must exist extent to be tailgated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) nxoff = offsetXAD(nxad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) nxlen = lengthXAD(nxad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) nxaddr = addressXAD(nxad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) if ((rc = xtSearch(ip, nxoff, NULL, &cmp, &btstack, XT_INSERT)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) /* retrieve search result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) XT_GETSEARCH(ip, btstack.top, bn, mp, p, index0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) if (cmp != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) jfs_error(ip->i_sb, "Could not find extent\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) * acquire tlock of the leaf page containing original entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) tlck = txLock(tid, ip, mp, tlckXTREE | tlckGROW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) xad = &p->xad[index0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) xflag = xad->flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) xoff = offsetXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) xlen = lengthXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) xaddr = addressXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) /* nXAD must be completely contained within XAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) if ((xoff > nxoff) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) (nxoff + nxlen > xoff + xlen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) jfs_error(ip->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) "nXAD in not completely contained within XAD\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) index = index0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) newindex = index + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) nextindex = le16_to_cpu(p->header.nextindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) #ifdef _JFS_WIP_NOCOALESCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) if (xoff < nxoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) goto updateRight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) * replace XAD with nXAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) replace: /* (nxoff == xoff) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) if (nxlen == xlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) /* replace XAD with nXAD:recorded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) *xad = *nxad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) xad->flag = xflag & ~XAD_NOTRECORDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) } else /* (nxlen < xlen) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) goto updateLeft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) #endif /* _JFS_WIP_NOCOALESCE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) /* #ifdef _JFS_WIP_COALESCE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) if (xoff < nxoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) goto coalesceRight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) * coalesce with left XAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) //coalesceLeft: /* (xoff == nxoff) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) /* is XAD first entry of page ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) if (index == XTENTRYSTART)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) goto replace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) /* is nXAD logically and physically contiguous with lXAD ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) lxad = &p->xad[index - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) lxlen = lengthXAD(lxad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) if (!(lxad->flag & XAD_NOTRECORDED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) (nxoff == offsetXAD(lxad) + lxlen) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) (nxaddr == addressXAD(lxad) + lxlen) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) (lxlen + nxlen < MAXXLEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) /* extend right lXAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) index0 = index - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) XADlength(lxad, lxlen + nxlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) /* If we just merged two extents together, need to make sure the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) * right extent gets logged. If the left one is marked XAD_NEW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) * then we know it will be logged. Otherwise, mark as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) * XAD_EXTENDED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) if (!(lxad->flag & XAD_NEW))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) lxad->flag |= XAD_EXTENDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) if (xlen > nxlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) /* truncate XAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) XADoffset(xad, xoff + nxlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) XADlength(xad, xlen - nxlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) XADaddress(xad, xaddr + nxlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) } else { /* (xlen == nxlen) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) /* remove XAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) if (index < nextindex - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) memmove(&p->xad[index], &p->xad[index + 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) (nextindex - index -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 1) << L2XTSLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) p->header.nextindex =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) cpu_to_le16(le16_to_cpu(p->header.nextindex) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) index = index0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) newindex = index + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) nextindex = le16_to_cpu(p->header.nextindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) xoff = nxoff = offsetXAD(lxad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) xlen = nxlen = lxlen + nxlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) xaddr = nxaddr = addressXAD(lxad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) goto coalesceRight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) * replace XAD with nXAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) replace: /* (nxoff == xoff) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) if (nxlen == xlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) /* replace XAD with nXAD:recorded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) *xad = *nxad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) xad->flag = xflag & ~XAD_NOTRECORDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) goto coalesceRight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) } else /* (nxlen < xlen) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) goto updateLeft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) * coalesce with right XAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) coalesceRight: /* (xoff <= nxoff) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) /* is XAD last entry of page ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) if (newindex == nextindex) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) if (xoff == nxoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) goto updateRight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) /* is nXAD logically and physically contiguous with rXAD ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) rxad = &p->xad[index + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) rxlen = lengthXAD(rxad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) if (!(rxad->flag & XAD_NOTRECORDED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) (nxoff + nxlen == offsetXAD(rxad)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) (nxaddr + nxlen == addressXAD(rxad)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) (rxlen + nxlen < MAXXLEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) /* extend left rXAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) XADoffset(rxad, nxoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) XADlength(rxad, rxlen + nxlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) XADaddress(rxad, nxaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) /* If we just merged two extents together, need to make sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) * the left extent gets logged. If the right one is marked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) * XAD_NEW, then we know it will be logged. Otherwise, mark as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) * XAD_EXTENDED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) if (!(rxad->flag & XAD_NEW))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) rxad->flag |= XAD_EXTENDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) if (xlen > nxlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) /* truncate XAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) XADlength(xad, xlen - nxlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) else { /* (xlen == nxlen) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) /* remove XAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) memmove(&p->xad[index], &p->xad[index + 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) (nextindex - index - 1) << L2XTSLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) p->header.nextindex =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) cpu_to_le16(le16_to_cpu(p->header.nextindex) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) } else if (xoff == nxoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) if (xoff >= nxoff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) jfs_error(ip->i_sb, "xoff >= nxoff\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) /* #endif _JFS_WIP_COALESCE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) * split XAD into (lXAD, nXAD):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) * |---nXAD--->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) * --|----------XAD----------|--
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) * |-lXAD-|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) updateRight: /* (xoff < nxoff) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) /* truncate old XAD as lXAD:not_recorded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) xad = &p->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) XADlength(xad, nxoff - xoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) /* insert nXAD:recorded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) if (nextindex == le16_to_cpu(p->header.maxentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) /* xtSpliUp() unpins leaf pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) split.mp = mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) split.index = newindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) split.flag = xflag & ~XAD_NOTRECORDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) split.off = nxoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) split.len = nxlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) split.addr = nxaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) split.pxdlist = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) if ((rc = xtSplitUp(tid, ip, &split, &btstack)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) /* get back old page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) * if leaf root has been split, original root has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) * copied to new child page, i.e., original entry now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) * resides on the new child page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) if (p->header.flag & BT_INTERNAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) ASSERT(p->header.nextindex ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) cpu_to_le16(XTENTRYSTART + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) xad = &p->xad[XTENTRYSTART];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) bn = addressXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) /* get new child page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) tlck = txLock(tid, ip, mp, tlckXTREE|tlckGROW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) /* is nXAD on new page ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) if (newindex >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) (le16_to_cpu(p->header.maxentry) >> 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) newindex =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) newindex -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) le16_to_cpu(p->header.nextindex) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) XTENTRYSTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) newpage = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) /* if insert into middle, shift right remaining entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) if (newindex < nextindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) memmove(&p->xad[newindex + 1], &p->xad[newindex],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) (nextindex - newindex) << L2XTSLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) /* insert the entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) xad = &p->xad[newindex];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) *xad = *nxad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) xad->flag = xflag & ~XAD_NOTRECORDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) /* advance next available entry index. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) p->header.nextindex =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) cpu_to_le16(le16_to_cpu(p->header.nextindex) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) * does nXAD force 3-way split ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) * |---nXAD--->|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) * --|----------XAD-------------|--
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) * |-lXAD-| |-rXAD -|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) if (nxoff + nxlen == xoff + xlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) /* reorient nXAD as XAD for further split XAD into (nXAD, rXAD) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) if (newpage) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) /* close out old page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) xtlck->lwm.offset = (xtlck->lwm.offset) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) min(index0, (int)xtlck->lwm.offset) : index0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) xtlck->lwm.length =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) le16_to_cpu(p->header.nextindex) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) xtlck->lwm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) bn = le64_to_cpu(p->header.next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) /* get new right page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) tlck = txLock(tid, ip, mp, tlckXTREE | tlckGROW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) index0 = index = newindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) newindex = index + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) nextindex = le16_to_cpu(p->header.nextindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) xlen = xlen - (nxoff - xoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) xoff = nxoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) xaddr = nxaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) /* recompute split pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) if (nextindex == le16_to_cpu(p->header.maxentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) if ((rc = xtSearch(ip, nxoff, NULL, &cmp, &btstack, XT_INSERT)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) /* retrieve search result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) XT_GETSEARCH(ip, btstack.top, bn, mp, p, index0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) if (cmp != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) jfs_error(ip->i_sb, "xtSearch failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) return -EIO;
^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) if (index0 != index) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) jfs_error(ip->i_sb, "unexpected value of index\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) * split XAD into (nXAD, rXAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) * ---nXAD---|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) * --|----------XAD----------|--
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) * |-rXAD-|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) updateLeft: /* (nxoff == xoff) && (nxlen < xlen) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) /* update old XAD with nXAD:recorded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) xad = &p->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) *xad = *nxad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) xad->flag = xflag & ~XAD_NOTRECORDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) /* insert rXAD:not_recorded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) xoff = xoff + nxlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) xlen = xlen - nxlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) xaddr = xaddr + nxlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) if (nextindex == le16_to_cpu(p->header.maxentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) printf("xtUpdate.updateLeft.split p:0x%p\n", p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) /* xtSpliUp() unpins leaf pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) split.mp = mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) split.index = newindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) split.flag = xflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) split.off = xoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) split.len = xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) split.addr = xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) split.pxdlist = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) if ((rc = xtSplitUp(tid, ip, &split, &btstack)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) /* get back old page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) * if leaf root has been split, original root has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) * copied to new child page, i.e., original entry now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) * resides on the new child page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) if (p->header.flag & BT_INTERNAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) ASSERT(p->header.nextindex ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) cpu_to_le16(XTENTRYSTART + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) xad = &p->xad[XTENTRYSTART];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) bn = addressXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) /* get new child page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) tlck = txLock(tid, ip, mp, tlckXTREE|tlckGROW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) /* if insert into middle, shift right remaining entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) if (newindex < nextindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) memmove(&p->xad[newindex + 1], &p->xad[newindex],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) (nextindex - newindex) << L2XTSLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) /* insert the entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) xad = &p->xad[newindex];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) XT_PUTENTRY(xad, xflag, xoff, xlen, xaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) /* advance next available entry index. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) p->header.nextindex =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) cpu_to_le16(le16_to_cpu(p->header.nextindex) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) if (!test_cflag(COMMIT_Nolink, ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) xtlck->lwm.offset = (xtlck->lwm.offset) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) min(index0, (int)xtlck->lwm.offset) : index0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) xtlck->lwm.length = le16_to_cpu(p->header.nextindex) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) xtlck->lwm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) /* unpin the leaf page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) * xtAppend()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) * function: grow in append mode from contiguous region specified ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) * parameter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) * tid - transaction id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) * ip - file object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) * xflag - extent flag:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) * xoff - extent offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) * maxblocks - max extent length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) * xlen - extent length (in/out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) * xaddrp - extent address pointer (in/out):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) * flag -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) * return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) int xtAppend(tid_t tid, /* transaction id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) struct inode *ip, int xflag, s64 xoff, s32 maxblocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) s32 * xlenp, /* (in/out) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) s64 * xaddrp, /* (in/out) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) struct metapage *mp; /* meta-page buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) xtpage_t *p; /* base B+-tree index page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) s64 bn, xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) int index, nextindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) struct btstack btstack; /* traverse stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) struct xtsplit split; /* split information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) xad_t *xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) int cmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) struct xtlock *xtlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) int nsplit, nblocks, xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) struct pxdlist pxdlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) pxd_t *pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) s64 next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) xaddr = *xaddrp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) xlen = *xlenp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) jfs_info("xtAppend: xoff:0x%lx maxblocks:%d xlen:%d xaddr:0x%lx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) (ulong) xoff, maxblocks, xlen, (ulong) xaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) * search for the entry location at which to insert:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) * xtFastSearch() and xtSearch() both returns (leaf page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) * pinned, index at which to insert).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) * n.b. xtSearch() may return index of maxentry of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) * the full page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) if ((rc = xtSearch(ip, xoff, &next, &cmp, &btstack, XT_INSERT)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) /* retrieve search result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) XT_GETSEARCH(ip, btstack.top, bn, mp, p, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) if (cmp == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) rc = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) goto out;
^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) if (next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) xlen = min(xlen, (int)(next - xoff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) //insert:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) * insert entry for new extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) xflag |= XAD_NEW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) * if the leaf page is full, split the page and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) * propagate up the router entry for the new page from split
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) * The xtSplitUp() will insert the entry and unpin the leaf page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) nextindex = le16_to_cpu(p->header.nextindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) if (nextindex < le16_to_cpu(p->header.maxentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) goto insertLeaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) * allocate new index blocks to cover index page split(s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) nsplit = btstack.nsplit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) split.pxdlist = &pxdlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) pxdlist.maxnpxd = pxdlist.npxd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) pxd = &pxdlist.pxd[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) nblocks = JFS_SBI(ip->i_sb)->nbperpage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) for (; nsplit > 0; nsplit--, pxd++, xaddr += nblocks, maxblocks -= nblocks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) if ((rc = dbAllocBottomUp(ip, xaddr, (s64) nblocks)) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) PXDaddress(pxd, xaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) PXDlength(pxd, nblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) pxdlist.maxnpxd++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) /* undo allocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) xlen = min(xlen, maxblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) * allocate data extent requested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) if ((rc = dbAllocBottomUp(ip, xaddr, (s64) xlen)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) split.mp = mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) split.index = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) split.flag = xflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) split.off = xoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) split.len = xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) split.addr = xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) if ((rc = xtSplitUp(tid, ip, &split, &btstack))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) /* undo data extent allocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) dbFree(ip, *xaddrp, (s64) * xlenp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) *xaddrp = xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) *xlenp = xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) return 0;
^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) * insert the new entry into the leaf page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) insertLeaf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) * allocate data extent requested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) if ((rc = dbAllocBottomUp(ip, xaddr, (s64) xlen)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) * acquire a transaction lock on the leaf page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) * action: xad insertion/extension;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) tlck = txLock(tid, ip, mp, tlckXTREE | tlckGROW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) /* insert the new entry: mark the entry NEW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) xad = &p->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) XT_PUTENTRY(xad, xflag, xoff, xlen, xaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) /* advance next available entry index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) le16_add_cpu(&p->header.nextindex, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) xtlck->lwm.offset =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) (xtlck->lwm.offset) ? min(index,(int) xtlck->lwm.offset) : index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) xtlck->lwm.length = le16_to_cpu(p->header.nextindex) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) xtlck->lwm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) *xaddrp = xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) *xlenp = xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) /* unpin the leaf page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) #ifdef _STILL_TO_PORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) /* - TBD for defragmentaion/reorganization -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) * xtDelete()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) * function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) * delete the entry with the specified key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) * N.B.: whole extent of the entry is assumed to be deleted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) * parameter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) * return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) * ENOENT: if the entry is not found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) * exception:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) int xtDelete(tid_t tid, struct inode *ip, s64 xoff, s32 xlen, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) struct btstack btstack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) int cmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) s64 bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) xtpage_t *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) int index, nextindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) struct xtlock *xtlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) * find the matching entry; xtSearch() pins the page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) if ((rc = xtSearch(ip, xoff, NULL, &cmp, &btstack, 0)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) XT_GETSEARCH(ip, btstack.top, bn, mp, p, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) if (cmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) /* unpin the leaf page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) * delete the entry from the leaf page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) nextindex = le16_to_cpu(p->header.nextindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) le16_add_cpu(&p->header.nextindex, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) * if the leaf page bocome empty, free the page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) if (p->header.nextindex == cpu_to_le16(XTENTRYSTART))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) return (xtDeleteUp(tid, ip, mp, p, &btstack));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) * acquire a transaction lock on the leaf page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) * action:xad deletion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) tlck = txLock(tid, ip, mp, tlckXTREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) xtlck->lwm.offset =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) (xtlck->lwm.offset) ? min(index, xtlck->lwm.offset) : index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) /* if delete from middle, shift left/compact the remaining entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) if (index < nextindex - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) memmove(&p->xad[index], &p->xad[index + 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) (nextindex - index - 1) * sizeof(xad_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) /* - TBD for defragmentaion/reorganization -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) * xtDeleteUp()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) * function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) * free empty pages as propagating deletion up the tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) * parameter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) * return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) xtDeleteUp(tid_t tid, struct inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) struct metapage * fmp, xtpage_t * fp, struct btstack * btstack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) xtpage_t *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) int index, nextindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) s64 xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) int xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) struct btframe *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) struct xtlock *xtlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) * keep root leaf page which has become empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) if (fp->header.flag & BT_ROOT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) /* keep the root page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) fp->header.flag &= ~BT_INTERNAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) fp->header.flag |= BT_LEAF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) fp->header.nextindex = cpu_to_le16(XTENTRYSTART);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) /* XT_PUTPAGE(fmp); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) * free non-root leaf page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) if ((rc = xtRelink(tid, ip, fp))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) XT_PUTPAGE(fmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) xaddr = addressPXD(&fp->header.self);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) xlen = lengthPXD(&fp->header.self);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) /* free the page extent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) dbFree(ip, xaddr, (s64) xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) /* free the buffer page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) discard_metapage(fmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) * propagate page deletion up the index tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) * If the delete from the parent page makes it empty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) * continue all the way up the tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) * stop if the root page is reached (which is never deleted) or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) * if the entry deletion does not empty the page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) while ((parent = BT_POP(btstack)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) /* get/pin the parent page <sp> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) XT_GETPAGE(ip, parent->bn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) index = parent->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) /* delete the entry for the freed child page from parent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) nextindex = le16_to_cpu(p->header.nextindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) * the parent has the single entry being deleted:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) * free the parent page which has become empty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) if (nextindex == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) if (p->header.flag & BT_ROOT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) /* keep the root page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) p->header.flag &= ~BT_INTERNAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) p->header.flag |= BT_LEAF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) p->header.nextindex =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) cpu_to_le16(XTENTRYSTART);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) /* XT_PUTPAGE(mp); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) /* free the parent page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) if ((rc = xtRelink(tid, ip, p)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) xaddr = addressPXD(&p->header.self);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) /* free the page extent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) dbFree(ip, xaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) (s64) JFS_SBI(ip->i_sb)->nbperpage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) /* unpin/free the buffer page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) discard_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) /* propagate up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) * the parent has other entries remaining:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) * delete the router entry from the parent page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) * acquire a transaction lock on the leaf page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) * action:xad deletion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) tlck = txLock(tid, ip, mp, tlckXTREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) xtlck->lwm.offset =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) (xtlck->lwm.offset) ? min(index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) xtlck->lwm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) offset) : index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) /* if delete from middle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) * shift left/compact the remaining entries in the page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) if (index < nextindex - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) memmove(&p->xad[index], &p->xad[index + 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) (nextindex - index -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 1) << L2XTSLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) le16_add_cpu(&p->header.nextindex, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) jfs_info("xtDeleteUp(entry): 0x%lx[%d]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) (ulong) parent->bn, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) /* unpin the parent page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) /* exit propagation up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532)
^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) * NAME: xtRelocate()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) * FUNCTION: relocate xtpage or data extent of regular file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) * This function is mainly used by defragfs utility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) * NOTE: This routine does not have the logic to handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) * uncommitted allocated extent. The caller should call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) * txCommit() to commit all the allocation before call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) * this routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) xtRelocate(tid_t tid, struct inode * ip, xad_t * oxad, /* old XAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) s64 nxaddr, /* new xaddr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) int xtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) { /* extent type: XTPAGE or DATAEXT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) struct tblock *tblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) struct xtlock *xtlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) struct metapage *mp, *pmp, *lmp, *rmp; /* meta-page buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) xtpage_t *p, *pp, *rp, *lp; /* base B+-tree index page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) xad_t *xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) pxd_t *pxd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) s64 xoff, xsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) int xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) s64 oxaddr, sxaddr, dxaddr, nextbn, prevbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) cbuf_t *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) s64 offset, nbytes, nbrd, pno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) int nb, npages, nblks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) s64 bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) int cmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) struct pxd_lock *pxdlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) struct btstack btstack; /* traverse stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) xtype = xtype & EXTENT_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) xoff = offsetXAD(oxad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) oxaddr = addressXAD(oxad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) xlen = lengthXAD(oxad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) /* validate extent offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) offset = xoff << JFS_SBI(ip->i_sb)->l2bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) if (offset >= ip->i_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) return -ESTALE; /* stale extent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) jfs_info("xtRelocate: xtype:%d xoff:0x%lx xlen:0x%x xaddr:0x%lx:0x%lx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) xtype, (ulong) xoff, xlen, (ulong) oxaddr, (ulong) nxaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) * 1. get and validate the parent xtpage/xad entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) * covering the source extent to be relocated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) if (xtype == DATAEXT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) /* search in leaf entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) rc = xtSearch(ip, xoff, NULL, &cmp, &btstack, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) /* retrieve search result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) XT_GETSEARCH(ip, btstack.top, bn, pmp, pp, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) if (cmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) XT_PUTPAGE(pmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) return -ESTALE;
^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) /* validate for exact match with a single entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) xad = &pp->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) if (addressXAD(xad) != oxaddr || lengthXAD(xad) != xlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) XT_PUTPAGE(pmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) return -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) } else { /* (xtype == XTPAGE) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) /* search in internal entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) rc = xtSearchNode(ip, oxad, &cmp, &btstack, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) /* retrieve search result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) XT_GETSEARCH(ip, btstack.top, bn, pmp, pp, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) if (cmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) XT_PUTPAGE(pmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) return -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) /* xtSearchNode() validated for exact match with a single entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) xad = &pp->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) jfs_info("xtRelocate: parent xad entry validated.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) * 2. relocate the extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) if (xtype == DATAEXT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) /* if the extent is allocated-but-not-recorded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) * there is no real data to be moved in this extent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) if (xad->flag & XAD_NOTRECORDED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) /* release xtpage for cmRead()/xtLookup() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) XT_PUTPAGE(pmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) * cmRelocate()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) * copy target data pages to be relocated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) * data extent must start at page boundary and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) * multiple of page size (except the last data extent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) * read in each page of the source data extent into cbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) * update the cbuf extent descriptor of the page to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) * homeward bound to new dst data extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) * copy the data from the old extent to new extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) * copy is essential for compressed files to avoid problems
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) * that can arise if there was a change in compression
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) * algorithms.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) * it is a good strategy because it may disrupt cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) * policy to keep the pages in memory afterwards.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) offset = xoff << JFS_SBI(ip->i_sb)->l2bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) assert((offset & CM_OFFSET) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) nbytes = xlen << JFS_SBI(ip->i_sb)->l2bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) pno = offset >> CM_L2BSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) npages = (nbytes + (CM_BSIZE - 1)) >> CM_L2BSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) npages = ((offset + nbytes - 1) >> CM_L2BSIZE) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) (offset >> CM_L2BSIZE) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) sxaddr = oxaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) dxaddr = nxaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) /* process the request one cache buffer at a time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) for (nbrd = 0; nbrd < nbytes; nbrd += nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) offset += nb, pno++, npages--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) /* compute page size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) nb = min(nbytes - nbrd, CM_BSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) /* get the cache buffer of the page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) if (rc = cmRead(ip, offset, npages, &cp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) assert(addressPXD(&cp->cm_pxd) == sxaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) assert(!cp->cm_modified);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) /* bind buffer with the new extent address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) nblks = nb >> JFS_IP(ip->i_sb)->l2bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) cmSetXD(ip, cp, pno, dxaddr, nblks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) /* release the cbuf, mark it as modified */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) cmPut(cp, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) dxaddr += nblks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) sxaddr += nblks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) /* get back parent page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) if ((rc = xtSearch(ip, xoff, NULL, &cmp, &btstack, 0)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) XT_GETSEARCH(ip, btstack.top, bn, pmp, pp, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) jfs_info("xtRelocate: target data extent relocated.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) } else { /* (xtype == XTPAGE) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) * read in the target xtpage from the source extent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) XT_GETPAGE(ip, oxaddr, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) XT_PUTPAGE(pmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) * read in sibling pages if any to update sibling pointers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) rmp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) if (p->header.next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) nextbn = le64_to_cpu(p->header.next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) XT_GETPAGE(ip, nextbn, rmp, PSIZE, rp, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) XT_PUTPAGE(pmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) lmp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) if (p->header.prev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) prevbn = le64_to_cpu(p->header.prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) XT_GETPAGE(ip, prevbn, lmp, PSIZE, lp, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) XT_PUTPAGE(pmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) if (rmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) XT_PUTPAGE(rmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) return (rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) /* at this point, all xtpages to be updated are in memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) * update sibling pointers of sibling xtpages if any;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) if (lmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) BT_MARK_DIRTY(lmp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) tlck = txLock(tid, ip, lmp, tlckXTREE | tlckRELINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) lp->header.next = cpu_to_le64(nxaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) XT_PUTPAGE(lmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) if (rmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) BT_MARK_DIRTY(rmp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) tlck = txLock(tid, ip, rmp, tlckXTREE | tlckRELINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) rp->header.prev = cpu_to_le64(nxaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) XT_PUTPAGE(rmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) }
^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) * update the target xtpage to be relocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) * update the self address of the target page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) * and write to destination extent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) * redo image covers the whole xtpage since it is new page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) * to the destination extent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) * update of bmap for the free of source extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) * of the target xtpage itself:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) * update of bmap for the allocation of destination extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) * of the target xtpage itself:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) * update of bmap for the extents covered by xad entries in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) * the target xtpage is not necessary since they are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) * updated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) * if not committed before this relocation,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) * target page may contain XAD_NEW entries which must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) * be scanned for bmap update (logredo() always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) * scan xtpage REDOPAGE image for bmap update);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) * if committed before this relocation (tlckRELOCATE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) * scan may be skipped by commit() and logredo();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) /* tlckNEW init xtlck->lwm.offset = XTENTRYSTART; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) tlck = txLock(tid, ip, mp, tlckXTREE | tlckNEW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) /* update the self address in the xtpage header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) pxd = &p->header.self;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) PXDaddress(pxd, nxaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) /* linelock for the after image of the whole page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) xtlck->lwm.length =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) le16_to_cpu(p->header.nextindex) - xtlck->lwm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) /* update the buffer extent descriptor of target xtpage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) xsize = xlen << JFS_SBI(ip->i_sb)->l2bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) bmSetXD(mp, nxaddr, xsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) /* unpin the target page to new homeward bound */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) jfs_info("xtRelocate: target xtpage relocated.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) * 3. acquire maplock for the source extent to be freed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) * acquire a maplock saving the src relocated extent address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) * to free of the extent at commit time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) /* if DATAEXT relocation, write a LOG_UPDATEMAP record for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) * free PXD of the source data extent (logredo() will update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) * bmap for free of source data extent), and update bmap for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) * free of the source data extent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) if (xtype == DATAEXT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) tlck = txMaplock(tid, ip, tlckMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) /* if XTPAGE relocation, write a LOG_NOREDOPAGE record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) * for the source xtpage (logredo() will init NoRedoPage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) * filter and will also update bmap for free of the source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) * xtpage), and update bmap for free of the source xtpage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) * N.B. We use tlckMAP instead of tlkcXTREE because there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) * is no buffer associated with this lock since the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) * has been redirected to the target location.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) else /* (xtype == XTPAGE) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) tlck = txMaplock(tid, ip, tlckMAP | tlckRELOCATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) pxdlock = (struct pxd_lock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) pxdlock->flag = mlckFREEPXD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) PXDaddress(&pxdlock->pxd, oxaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) PXDlength(&pxdlock->pxd, xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) pxdlock->index = 1;
^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) * 4. update the parent xad entry for relocation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) * acquire tlck for the parent entry with XAD_NEW as entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) * update which will write LOG_REDOPAGE and update bmap for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) * allocation of XAD_NEW destination extent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) jfs_info("xtRelocate: update parent xad entry.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) BT_MARK_DIRTY(pmp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) tlck = txLock(tid, ip, pmp, tlckXTREE | tlckGROW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) /* update the XAD with the new destination extent; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) xad = &pp->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) xad->flag |= XAD_NEW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) XADaddress(xad, nxaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) xtlck->lwm.offset = min(index, xtlck->lwm.offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) xtlck->lwm.length = le16_to_cpu(pp->header.nextindex) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) xtlck->lwm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) /* unpin the parent xtpage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) XT_PUTPAGE(pmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) }
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) * xtSearchNode()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) * function: search for the internal xad entry covering specified extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) * This function is mainly used by defragfs utility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) * parameters:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) * ip - file object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) * xad - extent to find;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) * cmpp - comparison result:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) * btstack - traverse stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) * flag - search process flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) * returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) * btstack contains (bn, index) of search path traversed to the entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) * *cmpp is set to result of comparison with the entry returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) * the page containing the entry is pinned at exit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) static int xtSearchNode(struct inode *ip, xad_t * xad, /* required XAD entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) int *cmpp, struct btstack * btstack, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) s64 xoff, xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) int xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) int cmp = 1; /* init for empty page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) s64 bn; /* block number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) struct metapage *mp; /* meta-page buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) xtpage_t *p; /* page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) int base, index, lim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) struct btframe *btsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) s64 t64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) BT_CLR(btstack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) xoff = offsetXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) xlen = lengthXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) xaddr = addressXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) * search down tree from root:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) * between two consecutive entries of <Ki, Pi> and <Kj, Pj> of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) * internal page, child page Pi contains entry with k, Ki <= K < Kj.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) * if entry with search key K is not found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) * internal page search find the entry with largest key Ki
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) * less than K which point to the child page to search;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) * leaf page search find the entry with smallest key Kj
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) * greater than K so that the returned index is the position of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) * the entry to be shifted right for insertion of new entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) * for empty tree, search key is greater than any key of the tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) * by convention, root bn = 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) for (bn = 0;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) /* get/pin the page to search */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) if (p->header.flag & BT_LEAF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) return -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) lim = le16_to_cpu(p->header.nextindex) - XTENTRYSTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) * binary search with search key K on the current page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) for (base = XTENTRYSTART; lim; lim >>= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) index = base + (lim >> 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) XT_CMP(cmp, xoff, &p->xad[index], t64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) if (cmp == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) * search hit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) * verify for exact match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) if (xaddr == addressXAD(&p->xad[index]) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) xoff == offsetXAD(&p->xad[index])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) *cmpp = cmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) /* save search result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) btsp = btstack->top;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) btsp->bn = bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) btsp->index = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) btsp->mp = mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) /* descend/search its child page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) if (cmp > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) base = index + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) --lim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) * search miss - non-leaf page:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) * base is the smallest index with key (Kj) greater than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) * search key (K) and may be zero or maxentry index.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) * if base is non-zero, decrement base by one to get the parent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) * entry of the child page to search.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) index = base ? base - 1 : base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) * go down to child page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) /* get the child page block number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) bn = addressXAD(&p->xad[index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) /* unpin the parent page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983)
^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) * xtRelink()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) * function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) * link around a freed page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) * Parameter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) * int tid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) * struct inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) * xtpage_t *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) * returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) static int xtRelink(tid_t tid, struct inode *ip, xtpage_t * p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) s64 nextbn, prevbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) struct tlock *tlck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) nextbn = le64_to_cpu(p->header.next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) prevbn = le64_to_cpu(p->header.prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) /* update prev pointer of the next page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) if (nextbn != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) XT_GETPAGE(ip, nextbn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) * acquire a transaction lock on the page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) * action: update prev pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) tlck = txLock(tid, ip, mp, tlckXTREE | tlckRELINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) /* the page may already have been tlock'd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) p->header.prev = cpu_to_le64(prevbn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) /* update next pointer of the previous page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) if (prevbn != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) XT_GETPAGE(ip, prevbn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) * acquire a transaction lock on the page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) * action: update next pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) tlck = txLock(tid, ip, mp, tlckXTREE | tlckRELINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) /* the page may already have been tlock'd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) p->header.next = le64_to_cpu(nextbn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) #endif /* _STILL_TO_PORT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) * xtInitRoot()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) * initialize file root (inline in inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) void xtInitRoot(tid_t tid, struct inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) xtpage_t *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) * acquire a transaction lock on the root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) * action:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) txLock(tid, ip, (struct metapage *) &JFS_IP(ip)->bxflag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) tlckXTREE | tlckNEW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) p = &JFS_IP(ip)->i_xtroot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) p->header.flag = DXD_INDEX | BT_ROOT | BT_LEAF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) p->header.nextindex = cpu_to_le16(XTENTRYSTART);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) if (S_ISDIR(ip->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) p->header.maxentry = cpu_to_le16(XTROOTINITSLOT_DIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) p->header.maxentry = cpu_to_le16(XTROOTINITSLOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) ip->i_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) * We can run into a deadlock truncating a file with a large number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) * xtree pages (large fragmented file). A robust fix would entail a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) * reservation system where we would reserve a number of metadata pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) * and tlocks which we would be guaranteed without a deadlock. Without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) * this, a partial fix is to limit number of metadata pages we will lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) * in a single transaction. Currently we will truncate the file so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) * no more than 50 leaf pages will be locked. The caller of xtTruncate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) * will be responsible for ensuring that the current transaction gets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) * committed, and that subsequent transactions are created to truncate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) * the file further if needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) #define MAX_TRUNCATE_LEAVES 50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) * xtTruncate()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) * function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) * traverse for truncation logging backward bottom up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) * terminate at the last extent entry at the current subtree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) * root page covering new down size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) * truncation may occur within the last extent entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) * parameter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) * int tid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) * struct inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) * s64 newsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) * int type) {PWMAP, PMAP, WMAP; DELETE, TRUNCATE}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) * return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) * note:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) * PWMAP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) * 1. truncate (non-COMMIT_NOLINK file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) * by jfs_truncate() or jfs_open(O_TRUNC):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) * xtree is updated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) * 2. truncate index table of directory when last entry removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) * map update via tlock at commit time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) * PMAP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) * Call xtTruncate_pmap instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) * WMAP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) * 1. remove (free zero link count) on last reference release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) * (pmap has been freed at commit zero link count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) * 2. truncate (COMMIT_NOLINK file, i.e., tmp file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) * xtree is updated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) * map update directly at truncation time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) * if (DELETE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) * no LOG_NOREDOPAGE is required (NOREDOFILE is sufficient);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) * else if (TRUNCATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) * must write LOG_NOREDOPAGE for deleted index page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) * pages may already have been tlocked by anonymous transactions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) * during file growth (i.e., write) before truncation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) * except last truncated entry, deleted entries remains as is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) * in the page (nextindex is updated) for other use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) * (e.g., log/update allocation map): this avoid copying the page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) * info but delay free of pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) s64 xtTruncate(tid_t tid, struct inode *ip, s64 newsize, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) s64 teof;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) xtpage_t *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) s64 bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) int index, nextindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) xad_t *xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) s64 xoff, xaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) int xlen, len, freexlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) struct btstack btstack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) struct btframe *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) struct tblock *tblk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) struct tlock *tlck = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) struct xtlock *xtlck = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) struct xdlistlock xadlock; /* maplock for COMMIT_WMAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) struct pxd_lock *pxdlock; /* maplock for COMMIT_WMAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) s64 nfreed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) int freed, log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) int locked_leaves = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) /* save object truncation type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) if (tid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) tblk = tid_to_tblock(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) tblk->xflag |= flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) nfreed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) flag &= COMMIT_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) assert(flag != COMMIT_PMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) if (flag == COMMIT_PWMAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) log = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) log = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) xadlock.flag = mlckFREEXADLIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) xadlock.index = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) * if the newsize is not an integral number of pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) * the file between newsize and next page boundary will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) * be cleared.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) * if truncating into a file hole, it will cause
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) * a full block to be allocated for the logical block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) * release page blocks of truncated region <teof, eof>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) * free the data blocks from the leaf index blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) * delete the parent index entries corresponding to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) * the freed child data/index blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) * free the index blocks themselves which aren't needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) * in new sized file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) * index blocks are updated only if the blocks are to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) * retained in the new sized file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) * if type is PMAP, the data and index pages are NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) * freed, and the data and index blocks are NOT freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) * from working map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) * (this will allow continued access of data/index of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) * temporary file (zerolink count file truncated to zero-length)).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) teof = (newsize + (JFS_SBI(ip->i_sb)->bsize - 1)) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) JFS_SBI(ip->i_sb)->l2bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) /* clear stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) BT_CLR(&btstack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) * start with root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) * root resides in the inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) bn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) * first access of each page:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) getPage:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) /* process entries backward from last index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) index = le16_to_cpu(p->header.nextindex) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) /* Since this is the rightmost page at this level, and we may have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) * already freed a page that was formerly to the right, let's make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) * sure that the next pointer is zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) if (p->header.next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) if (log)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) * Make sure this change to the header is logged.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) * If we really truncate this leaf, the flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) * will be changed to tlckTRUNCATE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) tlck = txLock(tid, ip, mp, tlckXTREE|tlckGROW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) p->header.next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) if (p->header.flag & BT_INTERNAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) goto getChild;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) * leaf page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) freed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) /* does region covered by leaf page precede Teof ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) xad = &p->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) xoff = offsetXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) xlen = lengthXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) if (teof >= xoff + xlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) goto getParent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) /* (re)acquire tlock of the leaf page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) if (log) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) if (++locked_leaves > MAX_TRUNCATE_LEAVES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) * We need to limit the size of the transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) * to avoid exhausting pagecache & tlocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) newsize = (xoff + xlen) << JFS_SBI(ip->i_sb)->l2bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) goto getParent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) tlck = txLock(tid, ip, mp, tlckXTREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) tlck->type = tlckXTREE | tlckTRUNCATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) xtlck->hwm.offset = le16_to_cpu(p->header.nextindex) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) * scan backward leaf page entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) for (; index >= XTENTRYSTART; index--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) xad = &p->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) xoff = offsetXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) xlen = lengthXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) xaddr = addressXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) * The "data" for a directory is indexed by the block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) * device's address space. This metadata must be invalidated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) * here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) if (S_ISDIR(ip->i_mode) && (teof == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) invalidate_xad_metapages(ip, *xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) * entry beyond eof: continue scan of current page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) * xad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) * ---|---=======------->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) * eof
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) if (teof < xoff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) nfreed += xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) * (xoff <= teof): last entry to be deleted from page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) * If other entries remain in page: keep and update the page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) * eof == entry_start: delete the entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) * xad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) * -------|=======------->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) * eof
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) if (teof == xoff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) nfreed += xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) if (index == XTENTRYSTART)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) nextindex = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) * eof within the entry: truncate the entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) * xad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) * -------===|===------->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) * eof
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) else if (teof < xoff + xlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) /* update truncated entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) len = teof - xoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) freexlen = xlen - len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) XADlength(xad, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) /* save pxd of truncated extent in tlck */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) xaddr += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) if (log) { /* COMMIT_PWMAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) xtlck->lwm.offset = (xtlck->lwm.offset) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) min(index, (int)xtlck->lwm.offset) : index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) xtlck->lwm.length = index + 1 -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) xtlck->lwm.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) xtlck->twm.offset = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) pxdlock = (struct pxd_lock *) & xtlck->pxdlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) pxdlock->flag = mlckFREEPXD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) PXDaddress(&pxdlock->pxd, xaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) PXDlength(&pxdlock->pxd, freexlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) /* free truncated extent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) else { /* COMMIT_WMAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) pxdlock = (struct pxd_lock *) & xadlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) pxdlock->flag = mlckFREEPXD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) PXDaddress(&pxdlock->pxd, xaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) PXDlength(&pxdlock->pxd, freexlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) txFreeMap(ip, pxdlock, NULL, COMMIT_WMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) /* reset map lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) xadlock.flag = mlckFREEXADLIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) /* current entry is new last entry; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) nextindex = index + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) nfreed += freexlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) * eof beyond the entry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) * xad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) * -------=======---|--->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) * eof
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) else { /* (xoff + xlen < teof) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) nextindex = index + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) if (nextindex < le16_to_cpu(p->header.nextindex)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) if (!log) { /* COMMIT_WAMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) xadlock.xdlist = &p->xad[nextindex];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) xadlock.count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) le16_to_cpu(p->header.nextindex) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) nextindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) txFreeMap(ip, (struct maplock *) & xadlock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) NULL, COMMIT_WMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) p->header.nextindex = cpu_to_le16(nextindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) /* assert(freed == 0); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) goto getParent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) } /* end scan of leaf page entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) freed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) * leaf page become empty: free the page if type != PMAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) if (log) { /* COMMIT_PWMAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) /* txCommit() with tlckFREE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) * free data extents covered by leaf [XTENTRYSTART:hwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) * invalidate leaf if COMMIT_PWMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) * if (TRUNCATE), will write LOG_NOREDOPAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) tlck->type = tlckXTREE | tlckFREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) } else { /* COMMIT_WAMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) /* free data extents covered by leaf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) xadlock.xdlist = &p->xad[XTENTRYSTART];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) xadlock.count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) le16_to_cpu(p->header.nextindex) - XTENTRYSTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) txFreeMap(ip, (struct maplock *) & xadlock, NULL, COMMIT_WMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) if (p->header.flag & BT_ROOT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) p->header.flag &= ~BT_INTERNAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) p->header.flag |= BT_LEAF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) p->header.nextindex = cpu_to_le16(XTENTRYSTART);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) XT_PUTPAGE(mp); /* debug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) if (log) { /* COMMIT_PWMAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) /* page will be invalidated at tx completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) } else { /* COMMIT_WMAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) if (mp->lid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) lid_to_tlock(mp->lid)->flag |= tlckFREELOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) /* invalidate empty leaf page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) discard_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) * the leaf page become empty: delete the parent entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) * for the leaf page if the parent page is to be kept
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) * in the new sized file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) * go back up to the parent page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) getParent:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) /* pop/restore parent entry for the current child page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) if ((parent = BT_POP(&btstack)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) /* current page must have been root */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) /* get back the parent page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) bn = parent->bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) index = parent->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) * child page was not empty:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) if (freed == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) /* has any entry deleted from parent ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) if (index < le16_to_cpu(p->header.nextindex) - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) /* (re)acquire tlock on the parent page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) if (log) { /* COMMIT_PWMAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) /* txCommit() with tlckTRUNCATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) * free child extents covered by parent [);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) tlck = txLock(tid, ip, mp, tlckXTREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) if (!(tlck->type & tlckTRUNCATE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) xtlck->hwm.offset =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) le16_to_cpu(p->header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) nextindex) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) tlck->type =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) tlckXTREE | tlckTRUNCATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) } else { /* COMMIT_WMAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) /* free child extents covered by parent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) xadlock.xdlist = &p->xad[index + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) xadlock.count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) le16_to_cpu(p->header.nextindex) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) index - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) txFreeMap(ip, (struct maplock *) & xadlock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) NULL, COMMIT_WMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) p->header.nextindex = cpu_to_le16(index + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) goto getParent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) * child page was empty:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) nfreed += lengthXAD(&p->xad[index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) * During working map update, child page's tlock must be handled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) * before parent's. This is because the parent's tlock will cause
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) * the child's disk space to be marked available in the wmap, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) * it's important that the child page be released by that time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) * ToDo: tlocks should be on doubly-linked list, so we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) * quickly remove it and add it to the end.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) * Move parent page's tlock to the end of the tid's tlock list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) if (log && mp->lid && (tblk->last != mp->lid) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) lid_to_tlock(mp->lid)->tid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) lid_t lid = mp->lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) struct tlock *prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) tlck = lid_to_tlock(lid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) if (tblk->next == lid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) tblk->next = tlck->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) for (prev = lid_to_tlock(tblk->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) prev->next != lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) prev = lid_to_tlock(prev->next)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) assert(prev->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) prev->next = tlck->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) lid_to_tlock(tblk->last)->next = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) tlck->next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) tblk->last = lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) * parent page become empty: free the page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) if (index == XTENTRYSTART) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) if (log) { /* COMMIT_PWMAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) /* txCommit() with tlckFREE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) * free child extents covered by parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) * invalidate parent if COMMIT_PWMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) tlck = txLock(tid, ip, mp, tlckXTREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) xtlck->hwm.offset =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) le16_to_cpu(p->header.nextindex) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) tlck->type = tlckXTREE | tlckFREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) } else { /* COMMIT_WMAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) /* free child extents covered by parent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) xadlock.xdlist = &p->xad[XTENTRYSTART];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) xadlock.count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) le16_to_cpu(p->header.nextindex) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) XTENTRYSTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) txFreeMap(ip, (struct maplock *) & xadlock, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) COMMIT_WMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) BT_MARK_DIRTY(mp, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) if (p->header.flag & BT_ROOT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) p->header.flag &= ~BT_INTERNAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) p->header.flag |= BT_LEAF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) p->header.nextindex = cpu_to_le16(XTENTRYSTART);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) if (le16_to_cpu(p->header.maxentry) == XTROOTMAXSLOT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) * Shrink root down to allow inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) * EA (otherwise fsck complains)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) p->header.maxentry =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) cpu_to_le16(XTROOTINITSLOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) JFS_IP(ip)->mode2 |= INLINEEA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) XT_PUTPAGE(mp); /* debug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) if (log) { /* COMMIT_PWMAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) /* page will be invalidated at tx completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) } else { /* COMMIT_WMAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) if (mp->lid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) lid_to_tlock(mp->lid)->flag |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) tlckFREELOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) /* invalidate parent page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) discard_metapage(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) /* parent has become empty and freed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) * go back up to its parent page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) /* freed = 1; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) goto getParent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) * parent page still has entries for front region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) /* try truncate region covered by preceding entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) * (process backward)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) index--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) /* go back down to the child page corresponding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) * to the entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) goto getChild;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) * internal page: go down to child page of current entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) getChild:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) /* save current parent entry for the child page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) if (BT_STACK_FULL(&btstack)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) jfs_error(ip->i_sb, "stack overrun!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) BT_PUSH(&btstack, bn, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) /* get child page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) xad = &p->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) bn = addressXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) * first access of each internal entry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) /* release parent page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) /* process the child page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) goto getPage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) * update file resource stat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) /* set size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) if (S_ISDIR(ip->i_mode) && !newsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) ip->i_size = 1; /* fsck hates zero-length directories */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) ip->i_size = newsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) /* update quota allocation to reflect freed blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) dquot_free_block(ip, nfreed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) * free tlock of invalidated pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) if (flag == COMMIT_WMAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) txFreelock(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) return newsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) * xtTruncate_pmap()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) * function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) * Perform truncate to zero length for deleted file, leaving the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) * the xtree and working map untouched. This allows the file to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) * be accessed via open file handles, while the delete of the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) * is committed to disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) * parameter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) * tid_t tid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) * struct inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) * s64 committed_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) * return: new committed size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) * note:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) * To avoid deadlock by holding too many transaction locks, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) * truncation may be broken up into multiple transactions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) * The committed_size keeps track of part of the file has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) * freed from the pmaps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) s64 xtTruncate_pmap(tid_t tid, struct inode *ip, s64 committed_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) s64 bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) struct btstack btstack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) int cmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) int locked_leaves = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) struct metapage *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) xtpage_t *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) struct btframe *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) struct tblock *tblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) struct tlock *tlck = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) xad_t *xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) int xlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) s64 xoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) struct xtlock *xtlck = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) /* save object truncation type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) tblk = tid_to_tblock(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) tblk->xflag |= COMMIT_PMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) /* clear stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) BT_CLR(&btstack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) if (committed_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) xoff = (committed_size >> JFS_SBI(ip->i_sb)->l2bsize) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) rc = xtSearch(ip, xoff, NULL, &cmp, &btstack, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) XT_GETSEARCH(ip, btstack.top, bn, mp, p, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) if (cmp != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) jfs_error(ip->i_sb, "did not find extent\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) * start with root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) * root resides in the inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) bn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) * first access of each page:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) getPage:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) /* process entries backward from last index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) index = le16_to_cpu(p->header.nextindex) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) if (p->header.flag & BT_INTERNAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) goto getChild;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) * leaf page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) if (++locked_leaves > MAX_TRUNCATE_LEAVES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) * We need to limit the size of the transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) * to avoid exhausting pagecache & tlocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) xad = &p->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) xoff = offsetXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) xlen = lengthXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) return (xoff + xlen) << JFS_SBI(ip->i_sb)->l2bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) tlck = txLock(tid, ip, mp, tlckXTREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) tlck->type = tlckXTREE | tlckFREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) xtlck->hwm.offset = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790) * go back up to the parent page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) getParent:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) /* pop/restore parent entry for the current child page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) if ((parent = BT_POP(&btstack)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) /* current page must have been root */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) /* get back the parent page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) bn = parent->bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) index = parent->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) * parent page become empty: free the page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) if (index == XTENTRYSTART) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810) /* txCommit() with tlckFREE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) * free child extents covered by parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) * invalidate parent if COMMIT_PWMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814) tlck = txLock(tid, ip, mp, tlckXTREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) xtlck = (struct xtlock *) & tlck->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) xtlck->hwm.offset = le16_to_cpu(p->header.nextindex) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) tlck->type = tlckXTREE | tlckFREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) if (p->header.flag & BT_ROOT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) goto getParent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) * parent page still has entries for front region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832) index--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) * internal page: go down to child page of current entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) getChild:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) /* save current parent entry for the child page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) if (BT_STACK_FULL(&btstack)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) jfs_error(ip->i_sb, "stack overrun!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) BT_PUSH(&btstack, bn, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) /* get child page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) xad = &p->xad[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847) bn = addressXAD(xad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) * first access of each internal entry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) /* release parent page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853) XT_PUTPAGE(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) /* process the child page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) goto getPage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863) #ifdef CONFIG_JFS_STATISTICS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) int jfs_xtstat_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) seq_printf(m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) "JFS Xtree statistics\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) "====================\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) "searches = %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870) "fast searches = %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) "splits = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872) xtStat.search,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873) xtStat.fastSearch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) xtStat.split);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) #endif