49
49
50
50
#define XT_PAGE (IP , MP ) BT_PAGE(IP, MP, xtpage_t, i_xtroot)
51
51
52
- /* get page buffer for specified block address */
53
- /* ToDo: Replace this ugly macro with a function */
54
- #define XT_GETPAGE (IP , BN , MP , SIZE , P , RC ) \
55
- do { \
56
- BT_GETPAGE(IP, BN, MP, xtpage_t, SIZE, P, RC, i_xtroot); \
57
- if (!(RC)) { \
58
- if ((le16_to_cpu((P)->header.nextindex) < XTENTRYSTART) || \
59
- (le16_to_cpu((P)->header.nextindex) > \
60
- le16_to_cpu((P)->header.maxentry)) || \
61
- (le16_to_cpu((P)->header.maxentry) > \
62
- (((BN) == 0) ? XTROOTMAXSLOT : PSIZE >> L2XTSLOTSIZE))) { \
63
- jfs_error((IP)->i_sb, \
64
- "XT_GETPAGE: xtree page corrupt\n"); \
65
- BT_PUTPAGE(MP); \
66
- MP = NULL; \
67
- RC = -EIO; \
68
- } \
69
- } \
70
- } while (0)
71
-
72
52
/* for consistency */
73
53
#define XT_PUTPAGE (MP ) BT_PUTPAGE(MP)
74
54
@@ -114,6 +94,42 @@ static int xtSplitPage(tid_t tid, struct inode *ip, struct xtsplit * split,
114
94
static int xtSplitRoot (tid_t tid , struct inode * ip ,
115
95
struct xtsplit * split , struct metapage * * rmpp );
116
96
97
+ /*
98
+ * xt_getpage()
99
+ *
100
+ * function: get the page buffer for a specified block address.
101
+ *
102
+ * parameters:
103
+ * ip - pointer to the inode
104
+ * bn - block number (s64) of the xtree page to be retrieved;
105
+ * mp - pointer to a metapage pointer where the page buffer is returned;
106
+ *
107
+ * returns:
108
+ * A pointer to the xtree page (xtpage_t) on success, -EIO on error.
109
+ */
110
+
111
+ static inline xtpage_t * xt_getpage (struct inode * ip , s64 bn , struct metapage * * mp )
112
+ {
113
+ xtpage_t * p ;
114
+ int rc ;
115
+
116
+ BT_GETPAGE (ip , bn , * mp , xtpage_t , PSIZE , p , rc , i_xtroot );
117
+
118
+ if (rc )
119
+ return ERR_PTR (rc );
120
+ if ((le16_to_cpu (p -> header .nextindex ) < XTENTRYSTART ) ||
121
+ (le16_to_cpu (p -> header .nextindex ) >
122
+ le16_to_cpu (p -> header .maxentry )) ||
123
+ (le16_to_cpu (p -> header .maxentry ) >
124
+ ((bn == 0 ) ? XTROOTMAXSLOT : PSIZE >> L2XTSLOTSIZE ))) {
125
+ jfs_error (ip -> i_sb , "xt_getpage: xtree page corrupt\n" );
126
+ BT_PUTPAGE (* mp );
127
+ * mp = NULL ;
128
+ return ERR_PTR (- EIO );
129
+ }
130
+ return p ;
131
+ }
132
+
117
133
/*
118
134
* xtLookup()
119
135
*
@@ -216,7 +232,6 @@ static int xtSearch(struct inode *ip, s64 xoff, s64 *nextp,
216
232
int * cmpp , struct btstack * btstack , int flag )
217
233
{
218
234
struct jfs_inode_info * jfs_ip = JFS_IP (ip );
219
- int rc = 0 ;
220
235
int cmp = 1 ; /* init for empty page */
221
236
s64 bn ; /* block number */
222
237
struct metapage * mp ; /* page buffer */
@@ -252,9 +267,9 @@ static int xtSearch(struct inode *ip, s64 xoff, s64 *nextp,
252
267
*/
253
268
for (bn = 0 ;;) {
254
269
/* get/pin the page to search */
255
- XT_GETPAGE (ip , bn , mp , PSIZE , p , rc );
256
- if (rc )
257
- return rc ;
270
+ p = xt_getpage (ip , bn , & mp );
271
+ if (IS_ERR ( p ) )
272
+ return PTR_ERR ( p ) ;
258
273
259
274
/* try sequential access heuristics with the previous
260
275
* access entry in target leaf page:
@@ -807,10 +822,10 @@ xtSplitUp(tid_t tid,
807
822
* insert router entry in parent for new right child page <rp>
808
823
*/
809
824
/* get/pin the parent page <sp> */
810
- XT_GETPAGE (ip , parent -> bn , smp , PSIZE , sp , rc );
811
- if (rc ) {
825
+ sp = xt_getpage (ip , parent -> bn , & smp );
826
+ if (IS_ERR ( sp ) ) {
812
827
XT_PUTPAGE (rcmp );
813
- return rc ;
828
+ return PTR_ERR ( sp ) ;
814
829
}
815
830
816
831
/*
@@ -1062,10 +1077,10 @@ xtSplitPage(tid_t tid, struct inode *ip,
1062
1077
* update previous pointer of old next/right page of <sp>
1063
1078
*/
1064
1079
if (nextbn != 0 ) {
1065
- XT_GETPAGE (ip , nextbn , mp , PSIZE , p , rc );
1066
- if (rc ) {
1080
+ p = xt_getpage (ip , nextbn , & mp );
1081
+ if (IS_ERR ( p ) ) {
1067
1082
XT_PUTPAGE (rmp );
1068
- goto clean_up ;
1083
+ return PTR_ERR ( p ) ;
1069
1084
}
1070
1085
1071
1086
BT_MARK_DIRTY (mp , ip );
@@ -1417,9 +1432,9 @@ int xtExtend(tid_t tid, /* transaction id */
1417
1432
return rc ;
1418
1433
1419
1434
/* get back old page */
1420
- XT_GETPAGE (ip , bn , mp , PSIZE , p , rc );
1421
- if (rc )
1422
- return rc ;
1435
+ p = xt_getpage (ip , bn , & mp );
1436
+ if (IS_ERR ( p ) )
1437
+ return PTR_ERR ( p ) ;
1423
1438
/*
1424
1439
* if leaf root has been split, original root has been
1425
1440
* copied to new child page, i.e., original entry now
@@ -1433,9 +1448,9 @@ int xtExtend(tid_t tid, /* transaction id */
1433
1448
XT_PUTPAGE (mp );
1434
1449
1435
1450
/* get new child page */
1436
- XT_GETPAGE (ip , bn , mp , PSIZE , p , rc );
1437
- if (rc )
1438
- return rc ;
1451
+ p = xt_getpage (ip , bn , & mp );
1452
+ if (IS_ERR ( p ) )
1453
+ return PTR_ERR ( p ) ;
1439
1454
1440
1455
BT_MARK_DIRTY (mp , ip );
1441
1456
if (!test_cflag (COMMIT_Nolink , ip )) {
@@ -1711,9 +1726,9 @@ int xtUpdate(tid_t tid, struct inode *ip, xad_t * nxad)
1711
1726
return rc ;
1712
1727
1713
1728
/* get back old page */
1714
- XT_GETPAGE (ip , bn , mp , PSIZE , p , rc );
1715
- if (rc )
1716
- return rc ;
1729
+ p = xt_getpage (ip , bn , & mp );
1730
+ if (IS_ERR ( p ) )
1731
+ return PTR_ERR ( p ) ;
1717
1732
/*
1718
1733
* if leaf root has been split, original root has been
1719
1734
* copied to new child page, i.e., original entry now
@@ -1727,9 +1742,9 @@ int xtUpdate(tid_t tid, struct inode *ip, xad_t * nxad)
1727
1742
XT_PUTPAGE (mp );
1728
1743
1729
1744
/* get new child page */
1730
- XT_GETPAGE (ip , bn , mp , PSIZE , p , rc );
1731
- if (rc )
1732
- return rc ;
1745
+ p = xt_getpage (ip , bn , & mp );
1746
+ if (IS_ERR ( p ) )
1747
+ return PTR_ERR ( p ) ;
1733
1748
1734
1749
BT_MARK_DIRTY (mp , ip );
1735
1750
if (!test_cflag (COMMIT_Nolink , ip )) {
@@ -1788,9 +1803,9 @@ int xtUpdate(tid_t tid, struct inode *ip, xad_t * nxad)
1788
1803
XT_PUTPAGE (mp );
1789
1804
1790
1805
/* get new right page */
1791
- XT_GETPAGE (ip , bn , mp , PSIZE , p , rc );
1792
- if (rc )
1793
- return rc ;
1806
+ p = xt_getpage (ip , bn , & mp );
1807
+ if (IS_ERR ( p ) )
1808
+ return PTR_ERR ( p ) ;
1794
1809
1795
1810
BT_MARK_DIRTY (mp , ip );
1796
1811
if (!test_cflag (COMMIT_Nolink , ip )) {
@@ -1864,9 +1879,9 @@ printf("xtUpdate.updateLeft.split p:0x%p\n", p);
1864
1879
return rc ;
1865
1880
1866
1881
/* get back old page */
1867
- XT_GETPAGE (ip , bn , mp , PSIZE , p , rc );
1868
- if (rc )
1869
- return rc ;
1882
+ p = xt_getpage (ip , bn , & mp );
1883
+ if (IS_ERR ( p ) )
1884
+ return PTR_ERR ( p ) ;
1870
1885
1871
1886
/*
1872
1887
* if leaf root has been split, original root has been
@@ -1881,9 +1896,9 @@ printf("xtUpdate.updateLeft.split p:0x%p\n", p);
1881
1896
XT_PUTPAGE (mp );
1882
1897
1883
1898
/* get new child page */
1884
- XT_GETPAGE (ip , bn , mp , PSIZE , p , rc );
1885
- if (rc )
1886
- return rc ;
1899
+ p = xt_getpage (ip , bn , & mp );
1900
+ if (IS_ERR ( p ) )
1901
+ return PTR_ERR ( p ) ;
1887
1902
1888
1903
BT_MARK_DIRTY (mp , ip );
1889
1904
if (!test_cflag (COMMIT_Nolink , ip )) {
@@ -2187,7 +2202,6 @@ void xtInitRoot(tid_t tid, struct inode *ip)
2187
2202
*/
2188
2203
s64 xtTruncate (tid_t tid , struct inode * ip , s64 newsize , int flag )
2189
2204
{
2190
- int rc = 0 ;
2191
2205
s64 teof ;
2192
2206
struct metapage * mp ;
2193
2207
xtpage_t * p ;
@@ -2268,9 +2282,9 @@ s64 xtTruncate(tid_t tid, struct inode *ip, s64 newsize, int flag)
2268
2282
* first access of each page:
2269
2283
*/
2270
2284
getPage :
2271
- XT_GETPAGE (ip , bn , mp , PSIZE , p , rc );
2272
- if (rc )
2273
- return rc ;
2285
+ p = xt_getpage (ip , bn , & mp );
2286
+ if (IS_ERR ( p ) )
2287
+ return PTR_ERR ( p ) ;
2274
2288
2275
2289
/* process entries backward from last index */
2276
2290
index = le16_to_cpu (p -> header .nextindex ) - 1 ;
@@ -2506,9 +2520,9 @@ s64 xtTruncate(tid_t tid, struct inode *ip, s64 newsize, int flag)
2506
2520
2507
2521
/* get back the parent page */
2508
2522
bn = parent -> bn ;
2509
- XT_GETPAGE (ip , bn , mp , PSIZE , p , rc );
2510
- if (rc )
2511
- return rc ;
2523
+ p = xt_getpage (ip , bn , & mp );
2524
+ if (IS_ERR ( p ) )
2525
+ return PTR_ERR ( p ) ;
2512
2526
2513
2527
index = parent -> index ;
2514
2528
@@ -2791,9 +2805,9 @@ s64 xtTruncate_pmap(tid_t tid, struct inode *ip, s64 committed_size)
2791
2805
* first access of each page:
2792
2806
*/
2793
2807
getPage :
2794
- XT_GETPAGE (ip , bn , mp , PSIZE , p , rc );
2795
- if (rc )
2796
- return rc ;
2808
+ p = xt_getpage (ip , bn , & mp );
2809
+ if (IS_ERR ( p ) )
2810
+ return PTR_ERR ( p ) ;
2797
2811
2798
2812
/* process entries backward from last index */
2799
2813
index = le16_to_cpu (p -> header .nextindex ) - 1 ;
@@ -2836,9 +2850,9 @@ s64 xtTruncate_pmap(tid_t tid, struct inode *ip, s64 committed_size)
2836
2850
2837
2851
/* get back the parent page */
2838
2852
bn = parent -> bn ;
2839
- XT_GETPAGE (ip , bn , mp , PSIZE , p , rc );
2840
- if (rc )
2841
- return rc ;
2853
+ p = xt_getpage (ip , bn , & mp );
2854
+ if (IS_ERR ( p ) )
2855
+ return PTR_ERR ( p ) ;
2842
2856
2843
2857
index = parent -> index ;
2844
2858
0 commit comments