hc
2024-09-20 cf4ce59b3b70238352c7f1729f0f7223214828ad
kernel/fs/xfs/libxfs/xfs_dir2_node.c
....@@ -6,12 +6,11 @@
66 */
77 #include "xfs.h"
88 #include "xfs_fs.h"
9
+#include "xfs_shared.h"
910 #include "xfs_format.h"
1011 #include "xfs_log_format.h"
1112 #include "xfs_trans_resv.h"
1213 #include "xfs_mount.h"
13
-#include "xfs_da_format.h"
14
-#include "xfs_da_btree.h"
1514 #include "xfs_inode.h"
1615 #include "xfs_bmap.h"
1716 #include "xfs_dir2.h"
....@@ -20,7 +19,6 @@
2019 #include "xfs_trace.h"
2120 #include "xfs_trans.h"
2221 #include "xfs_buf_item.h"
23
-#include "xfs_cksum.h"
2422 #include "xfs_log.h"
2523
2624 /*
....@@ -34,8 +32,25 @@
3432 static int xfs_dir2_leafn_remove(xfs_da_args_t *args, struct xfs_buf *bp,
3533 int index, xfs_da_state_blk_t *dblk,
3634 int *rval);
37
-static int xfs_dir2_node_addname_int(xfs_da_args_t *args,
38
- xfs_da_state_blk_t *fblk);
35
+
36
+/*
37
+ * Convert data space db to the corresponding free db.
38
+ */
39
+static xfs_dir2_db_t
40
+xfs_dir2_db_to_fdb(struct xfs_da_geometry *geo, xfs_dir2_db_t db)
41
+{
42
+ return xfs_dir2_byte_to_db(geo, XFS_DIR2_FREE_OFFSET) +
43
+ (db / geo->free_max_bests);
44
+}
45
+
46
+/*
47
+ * Convert data space db to the corresponding index in a free db.
48
+ */
49
+static int
50
+xfs_dir2_db_to_fdindex(struct xfs_da_geometry *geo, xfs_dir2_db_t db)
51
+{
52
+ return db % geo->free_max_bests;
53
+}
3954
4055 /*
4156 * Check internal consistency of a leafn block.
....@@ -49,7 +64,7 @@
4964 struct xfs_dir2_leaf *leaf = bp->b_addr;
5065 struct xfs_dir3_icleaf_hdr leafhdr;
5166
52
- dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
67
+ xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &leafhdr, leaf);
5368
5469 if (leafhdr.magic == XFS_DIR3_LEAFN_MAGIC) {
5570 struct xfs_dir3_leaf_hdr *leaf3 = bp->b_addr;
....@@ -58,7 +73,7 @@
5873 } else if (leafhdr.magic != XFS_DIR2_LEAFN_MAGIC)
5974 return __this_address;
6075
61
- return xfs_dir3_leaf_check_int(dp->i_mount, dp, &leafhdr, leaf);
76
+ return xfs_dir3_leaf_check_int(dp->i_mount, &leafhdr, leaf);
6277 }
6378
6479 static inline void
....@@ -84,22 +99,20 @@
8499 xfs_dir3_free_verify(
85100 struct xfs_buf *bp)
86101 {
87
- struct xfs_mount *mp = bp->b_target->bt_mount;
102
+ struct xfs_mount *mp = bp->b_mount;
88103 struct xfs_dir2_free_hdr *hdr = bp->b_addr;
104
+
105
+ if (!xfs_verify_magic(bp, hdr->magic))
106
+ return __this_address;
89107
90108 if (xfs_sb_version_hascrc(&mp->m_sb)) {
91109 struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr;
92110
93
- if (hdr3->magic != cpu_to_be32(XFS_DIR3_FREE_MAGIC))
94
- return __this_address;
95111 if (!uuid_equal(&hdr3->uuid, &mp->m_sb.sb_meta_uuid))
96112 return __this_address;
97113 if (be64_to_cpu(hdr3->blkno) != bp->b_bn)
98114 return __this_address;
99115 if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->lsn)))
100
- return __this_address;
101
- } else {
102
- if (hdr->magic != cpu_to_be32(XFS_DIR2_FREE_MAGIC))
103116 return __this_address;
104117 }
105118
....@@ -112,7 +125,7 @@
112125 xfs_dir3_free_read_verify(
113126 struct xfs_buf *bp)
114127 {
115
- struct xfs_mount *mp = bp->b_target->bt_mount;
128
+ struct xfs_mount *mp = bp->b_mount;
116129 xfs_failaddr_t fa;
117130
118131 if (xfs_sb_version_hascrc(&mp->m_sb) &&
....@@ -129,7 +142,7 @@
129142 xfs_dir3_free_write_verify(
130143 struct xfs_buf *bp)
131144 {
132
- struct xfs_mount *mp = bp->b_target->bt_mount;
145
+ struct xfs_mount *mp = bp->b_mount;
133146 struct xfs_buf_log_item *bip = bp->b_log_item;
134147 struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr;
135148 xfs_failaddr_t fa;
....@@ -151,6 +164,8 @@
151164
152165 const struct xfs_buf_ops xfs_dir3_free_buf_ops = {
153166 .name = "xfs_dir3_free",
167
+ .magic = { cpu_to_be32(XFS_DIR2_FREE_MAGIC),
168
+ cpu_to_be32(XFS_DIR3_FREE_MAGIC) },
154169 .verify_read = xfs_dir3_free_read_verify,
155170 .verify_write = xfs_dir3_free_write_verify,
156171 .verify_struct = xfs_dir3_free_verify,
....@@ -164,10 +179,9 @@
164179 struct xfs_buf *bp)
165180 {
166181 struct xfs_mount *mp = dp->i_mount;
182
+ int maxbests = mp->m_dir_geo->free_max_bests;
167183 unsigned int firstdb;
168
- int maxbests;
169184
170
- maxbests = dp->d_ops->free_max_bests(mp->m_dir_geo);
171185 firstdb = (xfs_dir2_da_to_db(mp->m_dir_geo, fbno) -
172186 xfs_dir2_byte_to_db(mp->m_dir_geo, XFS_DIR2_FREE_OFFSET)) *
173187 maxbests;
....@@ -179,6 +193,8 @@
179193 if (be32_to_cpu(hdr3->nvalid) > maxbests)
180194 return __this_address;
181195 if (be32_to_cpu(hdr3->nvalid) < be32_to_cpu(hdr3->nused))
196
+ return __this_address;
197
+ if (be64_to_cpu(hdr3->hdr.owner) != dp->i_ino)
182198 return __this_address;
183199 } else {
184200 struct xfs_dir2_free_hdr *hdr = bp->b_addr;
....@@ -198,21 +214,21 @@
198214 struct xfs_trans *tp,
199215 struct xfs_inode *dp,
200216 xfs_dablk_t fbno,
201
- xfs_daddr_t mappedbno,
217
+ unsigned int flags,
202218 struct xfs_buf **bpp)
203219 {
204220 xfs_failaddr_t fa;
205221 int err;
206222
207
- err = xfs_da_read_buf(tp, dp, fbno, mappedbno, bpp,
208
- XFS_DATA_FORK, &xfs_dir3_free_buf_ops);
223
+ err = xfs_da_read_buf(tp, dp, fbno, flags, bpp, XFS_DATA_FORK,
224
+ &xfs_dir3_free_buf_ops);
209225 if (err || !*bpp)
210226 return err;
211227
212228 /* Check things that we can't do in the verifier. */
213229 fa = xfs_dir3_free_header_check(dp, fbno, *bpp);
214230 if (fa) {
215
- xfs_verifier_error(*bpp, -EFSCORRUPTED, fa);
231
+ __xfs_buf_mark_corrupt(*bpp, fa);
216232 xfs_trans_brelse(tp, *bpp);
217233 *bpp = NULL;
218234 return -EFSCORRUPTED;
....@@ -225,6 +241,58 @@
225241 return 0;
226242 }
227243
244
+void
245
+xfs_dir2_free_hdr_from_disk(
246
+ struct xfs_mount *mp,
247
+ struct xfs_dir3_icfree_hdr *to,
248
+ struct xfs_dir2_free *from)
249
+{
250
+ if (xfs_sb_version_hascrc(&mp->m_sb)) {
251
+ struct xfs_dir3_free *from3 = (struct xfs_dir3_free *)from;
252
+
253
+ to->magic = be32_to_cpu(from3->hdr.hdr.magic);
254
+ to->firstdb = be32_to_cpu(from3->hdr.firstdb);
255
+ to->nvalid = be32_to_cpu(from3->hdr.nvalid);
256
+ to->nused = be32_to_cpu(from3->hdr.nused);
257
+ to->bests = from3->bests;
258
+
259
+ ASSERT(to->magic == XFS_DIR3_FREE_MAGIC);
260
+ } else {
261
+ to->magic = be32_to_cpu(from->hdr.magic);
262
+ to->firstdb = be32_to_cpu(from->hdr.firstdb);
263
+ to->nvalid = be32_to_cpu(from->hdr.nvalid);
264
+ to->nused = be32_to_cpu(from->hdr.nused);
265
+ to->bests = from->bests;
266
+
267
+ ASSERT(to->magic == XFS_DIR2_FREE_MAGIC);
268
+ }
269
+}
270
+
271
+static void
272
+xfs_dir2_free_hdr_to_disk(
273
+ struct xfs_mount *mp,
274
+ struct xfs_dir2_free *to,
275
+ struct xfs_dir3_icfree_hdr *from)
276
+{
277
+ if (xfs_sb_version_hascrc(&mp->m_sb)) {
278
+ struct xfs_dir3_free *to3 = (struct xfs_dir3_free *)to;
279
+
280
+ ASSERT(from->magic == XFS_DIR3_FREE_MAGIC);
281
+
282
+ to3->hdr.hdr.magic = cpu_to_be32(from->magic);
283
+ to3->hdr.firstdb = cpu_to_be32(from->firstdb);
284
+ to3->hdr.nvalid = cpu_to_be32(from->nvalid);
285
+ to3->hdr.nused = cpu_to_be32(from->nused);
286
+ } else {
287
+ ASSERT(from->magic == XFS_DIR2_FREE_MAGIC);
288
+
289
+ to->hdr.magic = cpu_to_be32(from->magic);
290
+ to->hdr.firstdb = cpu_to_be32(from->firstdb);
291
+ to->hdr.nvalid = cpu_to_be32(from->nvalid);
292
+ to->hdr.nused = cpu_to_be32(from->nused);
293
+ }
294
+}
295
+
228296 int
229297 xfs_dir2_free_read(
230298 struct xfs_trans *tp,
....@@ -232,7 +300,7 @@
232300 xfs_dablk_t fbno,
233301 struct xfs_buf **bpp)
234302 {
235
- return __xfs_dir3_free_read(tp, dp, fbno, -1, bpp);
303
+ return __xfs_dir3_free_read(tp, dp, fbno, 0, bpp);
236304 }
237305
238306 static int
....@@ -242,7 +310,7 @@
242310 xfs_dablk_t fbno,
243311 struct xfs_buf **bpp)
244312 {
245
- return __xfs_dir3_free_read(tp, dp, fbno, -2, bpp);
313
+ return __xfs_dir3_free_read(tp, dp, fbno, XFS_DABUF_MAP_HOLE_OK, bpp);
246314 }
247315
248316 static int
....@@ -259,7 +327,7 @@
259327 struct xfs_dir3_icfree_hdr hdr;
260328
261329 error = xfs_da_get_buf(tp, dp, xfs_dir2_db_to_da(args->geo, fbno),
262
- -1, &bp, XFS_DATA_FORK);
330
+ &bp, XFS_DATA_FORK);
263331 if (error)
264332 return error;
265333
....@@ -283,7 +351,7 @@
283351 uuid_copy(&hdr3->hdr.uuid, &mp->m_sb.sb_meta_uuid);
284352 } else
285353 hdr.magic = XFS_DIR2_FREE_MAGIC;
286
- dp->d_ops->free_hdr_to_disk(bp->b_addr, &hdr);
354
+ xfs_dir2_free_hdr_to_disk(mp, bp->b_addr, &hdr);
287355 *bpp = bp;
288356 return 0;
289357 }
....@@ -294,21 +362,19 @@
294362 STATIC void
295363 xfs_dir2_free_log_bests(
296364 struct xfs_da_args *args,
365
+ struct xfs_dir3_icfree_hdr *hdr,
297366 struct xfs_buf *bp,
298367 int first, /* first entry to log */
299368 int last) /* last entry to log */
300369 {
301
- xfs_dir2_free_t *free; /* freespace structure */
302
- __be16 *bests;
370
+ struct xfs_dir2_free *free = bp->b_addr;
303371
304
- free = bp->b_addr;
305
- bests = args->dp->d_ops->free_bests_p(free);
306372 ASSERT(free->hdr.magic == cpu_to_be32(XFS_DIR2_FREE_MAGIC) ||
307373 free->hdr.magic == cpu_to_be32(XFS_DIR3_FREE_MAGIC));
308374 xfs_trans_log_buf(args->trans, bp,
309
- (uint)((char *)&bests[first] - (char *)free),
310
- (uint)((char *)&bests[last] - (char *)free +
311
- sizeof(bests[0]) - 1));
375
+ (char *)&hdr->bests[first] - (char *)free,
376
+ (char *)&hdr->bests[last] - (char *)free +
377
+ sizeof(hdr->bests[0]) - 1);
312378 }
313379
314380 /*
....@@ -327,7 +393,7 @@
327393 free->hdr.magic == cpu_to_be32(XFS_DIR3_FREE_MAGIC));
328394 #endif
329395 xfs_trans_log_buf(args->trans, bp, 0,
330
- args->dp->d_ops->free_hdr_size - 1);
396
+ args->geo->free_hdr_size - 1);
331397 }
332398
333399 /*
....@@ -344,14 +410,12 @@
344410 int error; /* error return value */
345411 struct xfs_buf *fbp; /* freespace buffer */
346412 xfs_dir2_db_t fdb; /* freespace block number */
347
- xfs_dir2_free_t *free; /* freespace structure */
348413 __be16 *from; /* pointer to freespace entry */
349414 int i; /* leaf freespace index */
350415 xfs_dir2_leaf_t *leaf; /* leaf structure */
351416 xfs_dir2_leaf_tail_t *ltp; /* leaf tail structure */
352417 int n; /* count of live freespc ents */
353418 xfs_dir2_data_off_t off; /* freespace entry value */
354
- __be16 *to; /* pointer to freespace entry */
355419 xfs_trans_t *tp; /* transaction pointer */
356420 struct xfs_dir3_icfree_hdr freehdr;
357421
....@@ -373,24 +437,25 @@
373437 if (error)
374438 return error;
375439
376
- free = fbp->b_addr;
377
- dp->d_ops->free_hdr_from_disk(&freehdr, free);
440
+ xfs_dir2_free_hdr_from_disk(dp->i_mount, &freehdr, fbp->b_addr);
378441 leaf = lbp->b_addr;
379442 ltp = xfs_dir2_leaf_tail_p(args->geo, leaf);
380443 if (be32_to_cpu(ltp->bestcount) >
381
- (uint)dp->i_d.di_size / args->geo->blksize)
444
+ (uint)dp->i_d.di_size / args->geo->blksize) {
445
+ xfs_buf_mark_corrupt(lbp);
382446 return -EFSCORRUPTED;
447
+ }
383448
384449 /*
385450 * Copy freespace entries from the leaf block to the new block.
386451 * Count active entries.
387452 */
388453 from = xfs_dir2_leaf_bests_p(ltp);
389
- to = dp->d_ops->free_bests_p(free);
390
- for (i = n = 0; i < be32_to_cpu(ltp->bestcount); i++, from++, to++) {
391
- if ((off = be16_to_cpu(*from)) != NULLDATAOFF)
454
+ for (i = n = 0; i < be32_to_cpu(ltp->bestcount); i++, from++) {
455
+ off = be16_to_cpu(*from);
456
+ if (off != NULLDATAOFF)
392457 n++;
393
- *to = cpu_to_be16(off);
458
+ freehdr.bests[i] = cpu_to_be16(off);
394459 }
395460
396461 /*
....@@ -399,8 +464,8 @@
399464 freehdr.nused = n;
400465 freehdr.nvalid = be32_to_cpu(ltp->bestcount);
401466
402
- dp->d_ops->free_hdr_to_disk(fbp->b_addr, &freehdr);
403
- xfs_dir2_free_log_bests(args, fbp, 0, freehdr.nvalid - 1);
467
+ xfs_dir2_free_hdr_to_disk(dp->i_mount, fbp->b_addr, &freehdr);
468
+ xfs_dir2_free_log_bests(args, &freehdr, fbp, 0, freehdr.nvalid - 1);
404469 xfs_dir2_free_log_header(args, fbp);
405470
406471 /*
....@@ -427,33 +492,33 @@
427492 static int /* error */
428493 xfs_dir2_leafn_add(
429494 struct xfs_buf *bp, /* leaf buffer */
430
- xfs_da_args_t *args, /* operation arguments */
495
+ struct xfs_da_args *args, /* operation arguments */
431496 int index) /* insertion pt for new entry */
432497 {
498
+ struct xfs_dir3_icleaf_hdr leafhdr;
499
+ struct xfs_inode *dp = args->dp;
500
+ struct xfs_dir2_leaf *leaf = bp->b_addr;
501
+ struct xfs_dir2_leaf_entry *lep;
502
+ struct xfs_dir2_leaf_entry *ents;
433503 int compact; /* compacting stale leaves */
434
- xfs_inode_t *dp; /* incore directory inode */
435
- int highstale; /* next stale entry */
436
- xfs_dir2_leaf_t *leaf; /* leaf structure */
437
- xfs_dir2_leaf_entry_t *lep; /* leaf entry */
504
+ int highstale = 0; /* next stale entry */
438505 int lfloghigh; /* high leaf entry logging */
439506 int lfloglow; /* low leaf entry logging */
440
- int lowstale; /* previous stale entry */
441
- struct xfs_dir3_icleaf_hdr leafhdr;
442
- struct xfs_dir2_leaf_entry *ents;
507
+ int lowstale = 0; /* previous stale entry */
443508
444509 trace_xfs_dir2_leafn_add(args, index);
445510
446
- dp = args->dp;
447
- leaf = bp->b_addr;
448
- dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
449
- ents = dp->d_ops->leaf_ents_p(leaf);
511
+ xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &leafhdr, leaf);
512
+ ents = leafhdr.ents;
450513
451514 /*
452515 * Quick check just to make sure we are not going to index
453516 * into other peoples memory
454517 */
455
- if (index < 0)
518
+ if (index < 0) {
519
+ xfs_buf_mark_corrupt(bp);
456520 return -EFSCORRUPTED;
521
+ }
457522
458523 /*
459524 * If there are already the maximum number of leaf entries in
....@@ -462,7 +527,7 @@
462527 * a compact.
463528 */
464529
465
- if (leafhdr.count == dp->d_ops->leaf_max_ents(args->geo)) {
530
+ if (leafhdr.count == args->geo->leaf_max_ents) {
466531 if (!leafhdr.stale)
467532 return -ENOSPC;
468533 compact = leafhdr.stale > 1;
....@@ -500,9 +565,9 @@
500565 lep->address = cpu_to_be32(xfs_dir2_db_off_to_dataptr(args->geo,
501566 args->blkno, args->index));
502567
503
- dp->d_ops->leaf_hdr_to_disk(leaf, &leafhdr);
568
+ xfs_dir2_leaf_hdr_to_disk(dp->i_mount, leaf, &leafhdr);
504569 xfs_dir3_leaf_log_header(args, bp);
505
- xfs_dir3_leaf_log_ents(args, bp, lfloglow, lfloghigh);
570
+ xfs_dir3_leaf_log_ents(args, &leafhdr, bp, lfloglow, lfloghigh);
506571 xfs_dir3_leaf_check(dp, bp);
507572 return 0;
508573 }
....@@ -516,10 +581,9 @@
516581 {
517582 struct xfs_dir3_icfree_hdr hdr;
518583
519
- dp->d_ops->free_hdr_from_disk(&hdr, bp->b_addr);
584
+ xfs_dir2_free_hdr_from_disk(dp->i_mount, &hdr, bp->b_addr);
520585
521
- ASSERT((hdr.firstdb %
522
- dp->d_ops->free_max_bests(dp->i_mount->m_dir_geo)) == 0);
586
+ ASSERT((hdr.firstdb % dp->i_mount->m_dir_geo->free_max_bests) == 0);
523587 ASSERT(hdr.firstdb <= db);
524588 ASSERT(db < hdr.firstdb + hdr.nvalid);
525589 }
....@@ -537,11 +601,9 @@
537601 struct xfs_buf *bp, /* leaf buffer */
538602 int *count) /* count of entries in leaf */
539603 {
540
- struct xfs_dir2_leaf *leaf = bp->b_addr;
541
- struct xfs_dir2_leaf_entry *ents;
542604 struct xfs_dir3_icleaf_hdr leafhdr;
543605
544
- dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
606
+ xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &leafhdr, bp->b_addr);
545607
546608 ASSERT(leafhdr.magic == XFS_DIR2_LEAFN_MAGIC ||
547609 leafhdr.magic == XFS_DIR3_LEAFN_MAGIC ||
....@@ -552,9 +614,7 @@
552614 *count = leafhdr.count;
553615 if (!leafhdr.count)
554616 return 0;
555
-
556
- ents = dp->d_ops->leaf_ents_p(leaf);
557
- return be32_to_cpu(ents[leafhdr.count - 1].hashval);
617
+ return be32_to_cpu(leafhdr.ents[leafhdr.count - 1].hashval);
558618 }
559619
560620 /*
....@@ -583,15 +643,13 @@
583643 xfs_dir2_db_t newdb; /* new data block number */
584644 xfs_dir2_db_t newfdb; /* new free block number */
585645 xfs_trans_t *tp; /* transaction pointer */
586
- struct xfs_dir2_leaf_entry *ents;
587646 struct xfs_dir3_icleaf_hdr leafhdr;
588647
589648 dp = args->dp;
590649 tp = args->trans;
591650 mp = dp->i_mount;
592651 leaf = bp->b_addr;
593
- dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
594
- ents = dp->d_ops->leaf_ents_p(leaf);
652
+ xfs_dir2_leaf_hdr_from_disk(mp, &leafhdr, leaf);
595653
596654 xfs_dir3_leaf_check(dp, bp);
597655 ASSERT(leafhdr.count > 0);
....@@ -611,11 +669,11 @@
611669 ASSERT(free->hdr.magic == cpu_to_be32(XFS_DIR2_FREE_MAGIC) ||
612670 free->hdr.magic == cpu_to_be32(XFS_DIR3_FREE_MAGIC));
613671 }
614
- length = dp->d_ops->data_entsize(args->namelen);
672
+ length = xfs_dir2_data_entsize(mp, args->namelen);
615673 /*
616674 * Loop over leaf entries with the right hash value.
617675 */
618
- for (lep = &ents[index];
676
+ for (lep = &leafhdr.ents[index];
619677 index < leafhdr.count && be32_to_cpu(lep->hashval) == args->hashval;
620678 lep++, index++) {
621679 /*
....@@ -637,14 +695,14 @@
637695 * in hand, take a look at it.
638696 */
639697 if (newdb != curdb) {
640
- __be16 *bests;
698
+ struct xfs_dir3_icfree_hdr freehdr;
641699
642700 curdb = newdb;
643701 /*
644702 * Convert the data block to the free block
645703 * holding its freespace information.
646704 */
647
- newfdb = dp->d_ops->db_to_fdb(args->geo, newdb);
705
+ newfdb = xfs_dir2_db_to_fdb(args->geo, newdb);
648706 /*
649707 * If it's not the one we have in hand, read it in.
650708 */
....@@ -668,20 +726,20 @@
668726 /*
669727 * Get the index for our entry.
670728 */
671
- fi = dp->d_ops->db_to_fdindex(args->geo, curdb);
729
+ fi = xfs_dir2_db_to_fdindex(args->geo, curdb);
672730 /*
673731 * If it has room, return it.
674732 */
675
- bests = dp->d_ops->free_bests_p(free);
676
- if (unlikely(bests[fi] == cpu_to_be16(NULLDATAOFF))) {
677
- XFS_ERROR_REPORT("xfs_dir2_leafn_lookup_int",
678
- XFS_ERRLEVEL_LOW, mp);
733
+ xfs_dir2_free_hdr_from_disk(mp, &freehdr, free);
734
+ if (XFS_IS_CORRUPT(mp,
735
+ freehdr.bests[fi] ==
736
+ cpu_to_be16(NULLDATAOFF))) {
679737 if (curfdb != newfdb)
680738 xfs_trans_brelse(tp, curbp);
681739 return -EFSCORRUPTED;
682740 }
683741 curfdb = newfdb;
684
- if (be16_to_cpu(bests[fi]) >= length)
742
+ if (be16_to_cpu(freehdr.bests[fi]) >= length)
685743 goto out;
686744 }
687745 }
....@@ -735,18 +793,19 @@
735793 xfs_dir2_db_t newdb; /* new data block number */
736794 xfs_trans_t *tp; /* transaction pointer */
737795 enum xfs_dacmp cmp; /* comparison result */
738
- struct xfs_dir2_leaf_entry *ents;
739796 struct xfs_dir3_icleaf_hdr leafhdr;
740797
741798 dp = args->dp;
742799 tp = args->trans;
743800 mp = dp->i_mount;
744801 leaf = bp->b_addr;
745
- dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
746
- ents = dp->d_ops->leaf_ents_p(leaf);
802
+ xfs_dir2_leaf_hdr_from_disk(mp, &leafhdr, leaf);
747803
748804 xfs_dir3_leaf_check(dp, bp);
749
- ASSERT(leafhdr.count > 0);
805
+ if (leafhdr.count <= 0) {
806
+ xfs_buf_mark_corrupt(bp);
807
+ return -EFSCORRUPTED;
808
+ }
750809
751810 /*
752811 * Look up the hash value in the leaf entries.
....@@ -762,7 +821,7 @@
762821 /*
763822 * Loop over leaf entries with the right hash value.
764823 */
765
- for (lep = &ents[index];
824
+ for (lep = &leafhdr.ents[index];
766825 index < leafhdr.count && be32_to_cpu(lep->hashval) == args->hashval;
767826 lep++, index++) {
768827 /*
....@@ -801,7 +860,7 @@
801860 error = xfs_dir3_data_read(tp, dp,
802861 xfs_dir2_db_to_da(args->geo,
803862 newdb),
804
- -1, &curbp);
863
+ 0, &curbp);
805864 if (error)
806865 return error;
807866 }
....@@ -819,7 +878,7 @@
819878 * EEXIST immediately. If it's the first case-insensitive
820879 * match, store the block & inode number and continue looking.
821880 */
822
- cmp = mp->m_dirnameops->compname(args, dep->name, dep->namelen);
881
+ cmp = xfs_dir2_compname(args, dep->name, dep->namelen);
823882 if (cmp != XFS_CMP_DIFFERENT && cmp != args->cmpresult) {
824883 /* If there is a CI match block, drop it */
825884 if (args->cmpresult != XFS_CMP_DIFFERENT &&
....@@ -827,7 +886,7 @@
827886 xfs_trans_brelse(tp, state->extrablk.bp);
828887 args->cmpresult = cmp;
829888 args->inumber = be64_to_cpu(dep->inumber);
830
- args->filetype = dp->d_ops->data_get_ftype(dep);
889
+ args->filetype = xfs_dir2_data_get_ftype(mp, dep);
831890 *indexp = index;
832891 state->extravalid = 1;
833892 state->extrablk.bp = curbp;
....@@ -917,7 +976,7 @@
917976 if (start_d < dhdr->count) {
918977 memmove(&dents[start_d + count], &dents[start_d],
919978 (dhdr->count - start_d) * sizeof(xfs_dir2_leaf_entry_t));
920
- xfs_dir3_leaf_log_ents(args, bp_d, start_d + count,
979
+ xfs_dir3_leaf_log_ents(args, dhdr, bp_d, start_d + count,
921980 count + dhdr->count - 1);
922981 }
923982 /*
....@@ -939,7 +998,7 @@
939998 */
940999 memcpy(&dents[start_d], &sents[start_s],
9411000 count * sizeof(xfs_dir2_leaf_entry_t));
942
- xfs_dir3_leaf_log_ents(args, bp_d, start_d, start_d + count - 1);
1001
+ xfs_dir3_leaf_log_ents(args, dhdr, bp_d, start_d, start_d + count - 1);
9431002
9441003 /*
9451004 * If there are source entries after the ones we copied,
....@@ -948,7 +1007,8 @@
9481007 if (start_s + count < shdr->count) {
9491008 memmove(&sents[start_s], &sents[start_s + count],
9501009 count * sizeof(xfs_dir2_leaf_entry_t));
951
- xfs_dir3_leaf_log_ents(args, bp_s, start_s, start_s + count - 1);
1010
+ xfs_dir3_leaf_log_ents(args, shdr, bp_s, start_s,
1011
+ start_s + count - 1);
9521012 }
9531013
9541014 /*
....@@ -977,10 +1037,10 @@
9771037 struct xfs_dir3_icleaf_hdr hdr1;
9781038 struct xfs_dir3_icleaf_hdr hdr2;
9791039
980
- dp->d_ops->leaf_hdr_from_disk(&hdr1, leaf1);
981
- dp->d_ops->leaf_hdr_from_disk(&hdr2, leaf2);
982
- ents1 = dp->d_ops->leaf_ents_p(leaf1);
983
- ents2 = dp->d_ops->leaf_ents_p(leaf2);
1040
+ xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &hdr1, leaf1);
1041
+ xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &hdr2, leaf2);
1042
+ ents1 = hdr1.ents;
1043
+ ents2 = hdr2.ents;
9841044
9851045 if (hdr1.count > 0 && hdr2.count > 0 &&
9861046 (be32_to_cpu(ents2[0].hashval) < be32_to_cpu(ents1[0].hashval) ||
....@@ -1030,10 +1090,10 @@
10301090
10311091 leaf1 = blk1->bp->b_addr;
10321092 leaf2 = blk2->bp->b_addr;
1033
- dp->d_ops->leaf_hdr_from_disk(&hdr1, leaf1);
1034
- dp->d_ops->leaf_hdr_from_disk(&hdr2, leaf2);
1035
- ents1 = dp->d_ops->leaf_ents_p(leaf1);
1036
- ents2 = dp->d_ops->leaf_ents_p(leaf2);
1093
+ xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &hdr1, leaf1);
1094
+ xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &hdr2, leaf2);
1095
+ ents1 = hdr1.ents;
1096
+ ents2 = hdr2.ents;
10371097
10381098 oldsum = hdr1.count + hdr2.count;
10391099 #if defined(DEBUG) || defined(XFS_WARN)
....@@ -1079,8 +1139,8 @@
10791139 ASSERT(hdr1.stale + hdr2.stale == oldstale);
10801140
10811141 /* log the changes made when moving the entries */
1082
- dp->d_ops->leaf_hdr_to_disk(leaf1, &hdr1);
1083
- dp->d_ops->leaf_hdr_to_disk(leaf2, &hdr2);
1142
+ xfs_dir2_leaf_hdr_to_disk(dp->i_mount, leaf1, &hdr1);
1143
+ xfs_dir2_leaf_hdr_to_disk(dp->i_mount, leaf2, &hdr2);
10841144 xfs_dir3_leaf_log_header(args, blk1->bp);
10851145 xfs_dir3_leaf_log_header(args, blk2->bp);
10861146
....@@ -1126,19 +1186,17 @@
11261186 int longest)
11271187 {
11281188 int logfree = 0;
1129
- __be16 *bests;
11301189 struct xfs_dir3_icfree_hdr freehdr;
11311190 struct xfs_inode *dp = args->dp;
11321191
1133
- dp->d_ops->free_hdr_from_disk(&freehdr, free);
1134
- bests = dp->d_ops->free_bests_p(free);
1192
+ xfs_dir2_free_hdr_from_disk(dp->i_mount, &freehdr, free);
11351193 if (hdr) {
11361194 /*
11371195 * Data block is not empty, just set the free entry to the new
11381196 * value.
11391197 */
1140
- bests[findex] = cpu_to_be16(longest);
1141
- xfs_dir2_free_log_bests(args, fbp, findex, findex);
1198
+ freehdr.bests[findex] = cpu_to_be16(longest);
1199
+ xfs_dir2_free_log_bests(args, &freehdr, fbp, findex, findex);
11421200 return 0;
11431201 }
11441202
....@@ -1154,18 +1212,18 @@
11541212 int i; /* free entry index */
11551213
11561214 for (i = findex - 1; i >= 0; i--) {
1157
- if (bests[i] != cpu_to_be16(NULLDATAOFF))
1215
+ if (freehdr.bests[i] != cpu_to_be16(NULLDATAOFF))
11581216 break;
11591217 }
11601218 freehdr.nvalid = i + 1;
11611219 logfree = 0;
11621220 } else {
11631221 /* Not the last entry, just punch it out. */
1164
- bests[findex] = cpu_to_be16(NULLDATAOFF);
1222
+ freehdr.bests[findex] = cpu_to_be16(NULLDATAOFF);
11651223 logfree = 1;
11661224 }
11671225
1168
- dp->d_ops->free_hdr_to_disk(free, &freehdr);
1226
+ xfs_dir2_free_hdr_to_disk(dp->i_mount, free, &freehdr);
11691227 xfs_dir2_free_log_header(args, fbp);
11701228
11711229 /*
....@@ -1190,7 +1248,7 @@
11901248
11911249 /* Log the free entry that changed, unless we got rid of it. */
11921250 if (logfree)
1193
- xfs_dir2_free_log_bests(args, fbp, findex, findex);
1251
+ xfs_dir2_free_log_bests(args, &freehdr, fbp, findex, findex);
11941252 return 0;
11951253 }
11961254
....@@ -1207,6 +1265,7 @@
12071265 xfs_da_state_blk_t *dblk, /* data block */
12081266 int *rval) /* resulting block needs join */
12091267 {
1268
+ struct xfs_da_geometry *geo = args->geo;
12101269 xfs_dir2_data_hdr_t *hdr; /* data block header */
12111270 xfs_dir2_db_t db; /* data block number */
12121271 struct xfs_buf *dbp; /* data block buffer */
....@@ -1221,27 +1280,25 @@
12211280 xfs_trans_t *tp; /* transaction pointer */
12221281 struct xfs_dir2_data_free *bf; /* bestfree table */
12231282 struct xfs_dir3_icleaf_hdr leafhdr;
1224
- struct xfs_dir2_leaf_entry *ents;
12251283
12261284 trace_xfs_dir2_leafn_remove(args, index);
12271285
12281286 dp = args->dp;
12291287 tp = args->trans;
12301288 leaf = bp->b_addr;
1231
- dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
1232
- ents = dp->d_ops->leaf_ents_p(leaf);
1289
+ xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &leafhdr, leaf);
12331290
12341291 /*
12351292 * Point to the entry we're removing.
12361293 */
1237
- lep = &ents[index];
1294
+ lep = &leafhdr.ents[index];
12381295
12391296 /*
12401297 * Extract the data block and offset from the entry.
12411298 */
1242
- db = xfs_dir2_dataptr_to_db(args->geo, be32_to_cpu(lep->address));
1299
+ db = xfs_dir2_dataptr_to_db(geo, be32_to_cpu(lep->address));
12431300 ASSERT(dblk->blkno == db);
1244
- off = xfs_dir2_dataptr_to_off(args->geo, be32_to_cpu(lep->address));
1301
+ off = xfs_dir2_dataptr_to_off(geo, be32_to_cpu(lep->address));
12451302 ASSERT(dblk->index == off);
12461303
12471304 /*
....@@ -1249,11 +1306,11 @@
12491306 * Log the leaf block changes.
12501307 */
12511308 leafhdr.stale++;
1252
- dp->d_ops->leaf_hdr_to_disk(leaf, &leafhdr);
1309
+ xfs_dir2_leaf_hdr_to_disk(dp->i_mount, leaf, &leafhdr);
12531310 xfs_dir3_leaf_log_header(args, bp);
12541311
12551312 lep->address = cpu_to_be32(XFS_DIR2_NULL_DATAPTR);
1256
- xfs_dir3_leaf_log_ents(args, bp, index, index);
1313
+ xfs_dir3_leaf_log_ents(args, &leafhdr, bp, index, index);
12571314
12581315 /*
12591316 * Make the data entry free. Keep track of the longest freespace
....@@ -1262,17 +1319,18 @@
12621319 dbp = dblk->bp;
12631320 hdr = dbp->b_addr;
12641321 dep = (xfs_dir2_data_entry_t *)((char *)hdr + off);
1265
- bf = dp->d_ops->data_bestfree_p(hdr);
1322
+ bf = xfs_dir2_data_bestfree_p(dp->i_mount, hdr);
12661323 longest = be16_to_cpu(bf[0].length);
12671324 needlog = needscan = 0;
12681325 xfs_dir2_data_make_free(args, dbp, off,
1269
- dp->d_ops->data_entsize(dep->namelen), &needlog, &needscan);
1326
+ xfs_dir2_data_entsize(dp->i_mount, dep->namelen), &needlog,
1327
+ &needscan);
12701328 /*
12711329 * Rescan the data block freespaces for bestfree.
12721330 * Log the data block header if needed.
12731331 */
12741332 if (needscan)
1275
- xfs_dir2_data_freescan(dp, hdr, &needlog);
1333
+ xfs_dir2_data_freescan(dp->i_mount, hdr, &needlog);
12761334 if (needlog)
12771335 xfs_dir2_data_log_header(args, dbp);
12781336 xfs_dir3_data_check(dp, dbp);
....@@ -1291,9 +1349,8 @@
12911349 * Convert the data block number to a free block,
12921350 * read in the free block.
12931351 */
1294
- fdb = dp->d_ops->db_to_fdb(args->geo, db);
1295
- error = xfs_dir2_free_read(tp, dp,
1296
- xfs_dir2_db_to_da(args->geo, fdb),
1352
+ fdb = xfs_dir2_db_to_fdb(geo, db);
1353
+ error = xfs_dir2_free_read(tp, dp, xfs_dir2_db_to_da(geo, fdb),
12971354 &fbp);
12981355 if (error)
12991356 return error;
....@@ -1301,23 +1358,22 @@
13011358 #ifdef DEBUG
13021359 {
13031360 struct xfs_dir3_icfree_hdr freehdr;
1304
- dp->d_ops->free_hdr_from_disk(&freehdr, free);
1305
- ASSERT(freehdr.firstdb == dp->d_ops->free_max_bests(args->geo) *
1306
- (fdb - xfs_dir2_byte_to_db(args->geo,
1307
- XFS_DIR2_FREE_OFFSET)));
1361
+
1362
+ xfs_dir2_free_hdr_from_disk(dp->i_mount, &freehdr, free);
1363
+ ASSERT(freehdr.firstdb == geo->free_max_bests *
1364
+ (fdb - xfs_dir2_byte_to_db(geo, XFS_DIR2_FREE_OFFSET)));
13081365 }
13091366 #endif
13101367 /*
13111368 * Calculate which entry we need to fix.
13121369 */
1313
- findex = dp->d_ops->db_to_fdindex(args->geo, db);
1370
+ findex = xfs_dir2_db_to_fdindex(geo, db);
13141371 longest = be16_to_cpu(bf[0].length);
13151372 /*
13161373 * If the data block is now empty we can get rid of it
13171374 * (usually).
13181375 */
1319
- if (longest == args->geo->blksize -
1320
- dp->d_ops->data_entry_offset) {
1376
+ if (longest == geo->blksize - geo->data_entry_offset) {
13211377 /*
13221378 * Try to punch out the data block.
13231379 */
....@@ -1349,9 +1405,9 @@
13491405 * Return indication of whether this leaf block is empty enough
13501406 * to justify trying to join it with a neighbor.
13511407 */
1352
- *rval = (dp->d_ops->leaf_hdr_size +
1353
- (uint)sizeof(ents[0]) * (leafhdr.count - leafhdr.stale)) <
1354
- args->geo->magicpct;
1408
+ *rval = (geo->leaf_hdr_size +
1409
+ (uint)sizeof(leafhdr.ents) * (leafhdr.count - leafhdr.stale)) <
1410
+ geo->magicpct;
13551411 return 0;
13561412 }
13571413
....@@ -1450,12 +1506,12 @@
14501506 */
14511507 blk = &state->path.blk[state->path.active - 1];
14521508 leaf = blk->bp->b_addr;
1453
- dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
1454
- ents = dp->d_ops->leaf_ents_p(leaf);
1509
+ xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &leafhdr, leaf);
1510
+ ents = leafhdr.ents;
14551511 xfs_dir3_leaf_check(dp, blk->bp);
14561512
14571513 count = leafhdr.count - leafhdr.stale;
1458
- bytes = dp->d_ops->leaf_hdr_size + count * sizeof(ents[0]);
1514
+ bytes = state->args->geo->leaf_hdr_size + count * sizeof(ents[0]);
14591515 if (bytes > (state->args->geo->blksize >> 1)) {
14601516 /*
14611517 * Blk over 50%, don't try to join.
....@@ -1500,8 +1556,7 @@
15001556 /*
15011557 * Read the sibling leaf block.
15021558 */
1503
- error = xfs_dir3_leafn_read(state->args->trans, dp,
1504
- blkno, -1, &bp);
1559
+ error = xfs_dir3_leafn_read(state->args->trans, dp, blkno, &bp);
15051560 if (error)
15061561 return error;
15071562
....@@ -1513,8 +1568,8 @@
15131568 (state->args->geo->blksize >> 2);
15141569
15151570 leaf = bp->b_addr;
1516
- dp->d_ops->leaf_hdr_from_disk(&hdr2, leaf);
1517
- ents = dp->d_ops->leaf_ents_p(leaf);
1571
+ xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &hdr2, leaf);
1572
+ ents = hdr2.ents;
15181573 count += hdr2.count - hdr2.stale;
15191574 bytes -= count * sizeof(ents[0]);
15201575
....@@ -1576,10 +1631,10 @@
15761631 drop_leaf = drop_blk->bp->b_addr;
15771632 save_leaf = save_blk->bp->b_addr;
15781633
1579
- dp->d_ops->leaf_hdr_from_disk(&savehdr, save_leaf);
1580
- dp->d_ops->leaf_hdr_from_disk(&drophdr, drop_leaf);
1581
- sents = dp->d_ops->leaf_ents_p(save_leaf);
1582
- dents = dp->d_ops->leaf_ents_p(drop_leaf);
1634
+ xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &savehdr, save_leaf);
1635
+ xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &drophdr, drop_leaf);
1636
+ sents = savehdr.ents;
1637
+ dents = drophdr.ents;
15831638
15841639 /*
15851640 * If there are any stale leaf entries, take this opportunity
....@@ -1605,13 +1660,342 @@
16051660 save_blk->hashval = be32_to_cpu(sents[savehdr.count - 1].hashval);
16061661
16071662 /* log the changes made when moving the entries */
1608
- dp->d_ops->leaf_hdr_to_disk(save_leaf, &savehdr);
1609
- dp->d_ops->leaf_hdr_to_disk(drop_leaf, &drophdr);
1663
+ xfs_dir2_leaf_hdr_to_disk(dp->i_mount, save_leaf, &savehdr);
1664
+ xfs_dir2_leaf_hdr_to_disk(dp->i_mount, drop_leaf, &drophdr);
16101665 xfs_dir3_leaf_log_header(args, save_blk->bp);
16111666 xfs_dir3_leaf_log_header(args, drop_blk->bp);
16121667
16131668 xfs_dir3_leaf_check(dp, save_blk->bp);
16141669 xfs_dir3_leaf_check(dp, drop_blk->bp);
1670
+}
1671
+
1672
+/*
1673
+ * Add a new data block to the directory at the free space index that the caller
1674
+ * has specified.
1675
+ */
1676
+static int
1677
+xfs_dir2_node_add_datablk(
1678
+ struct xfs_da_args *args,
1679
+ struct xfs_da_state_blk *fblk,
1680
+ xfs_dir2_db_t *dbno,
1681
+ struct xfs_buf **dbpp,
1682
+ struct xfs_buf **fbpp,
1683
+ struct xfs_dir3_icfree_hdr *hdr,
1684
+ int *findex)
1685
+{
1686
+ struct xfs_inode *dp = args->dp;
1687
+ struct xfs_trans *tp = args->trans;
1688
+ struct xfs_mount *mp = dp->i_mount;
1689
+ struct xfs_dir2_data_free *bf;
1690
+ xfs_dir2_db_t fbno;
1691
+ struct xfs_buf *fbp;
1692
+ struct xfs_buf *dbp;
1693
+ int error;
1694
+
1695
+ /* Not allowed to allocate, return failure. */
1696
+ if (args->total == 0)
1697
+ return -ENOSPC;
1698
+
1699
+ /* Allocate and initialize the new data block. */
1700
+ error = xfs_dir2_grow_inode(args, XFS_DIR2_DATA_SPACE, dbno);
1701
+ if (error)
1702
+ return error;
1703
+ error = xfs_dir3_data_init(args, *dbno, &dbp);
1704
+ if (error)
1705
+ return error;
1706
+
1707
+ /*
1708
+ * Get the freespace block corresponding to the data block
1709
+ * that was just allocated.
1710
+ */
1711
+ fbno = xfs_dir2_db_to_fdb(args->geo, *dbno);
1712
+ error = xfs_dir2_free_try_read(tp, dp,
1713
+ xfs_dir2_db_to_da(args->geo, fbno), &fbp);
1714
+ if (error)
1715
+ return error;
1716
+
1717
+ /*
1718
+ * If there wasn't a freespace block, the read will
1719
+ * return a NULL fbp. Allocate and initialize a new one.
1720
+ */
1721
+ if (!fbp) {
1722
+ error = xfs_dir2_grow_inode(args, XFS_DIR2_FREE_SPACE, &fbno);
1723
+ if (error)
1724
+ return error;
1725
+
1726
+ if (XFS_IS_CORRUPT(mp,
1727
+ xfs_dir2_db_to_fdb(args->geo, *dbno) !=
1728
+ fbno)) {
1729
+ xfs_alert(mp,
1730
+"%s: dir ino %llu needed freesp block %lld for data block %lld, got %lld",
1731
+ __func__, (unsigned long long)dp->i_ino,
1732
+ (long long)xfs_dir2_db_to_fdb(args->geo, *dbno),
1733
+ (long long)*dbno, (long long)fbno);
1734
+ if (fblk) {
1735
+ xfs_alert(mp,
1736
+ " fblk "PTR_FMT" blkno %llu index %d magic 0x%x",
1737
+ fblk, (unsigned long long)fblk->blkno,
1738
+ fblk->index, fblk->magic);
1739
+ } else {
1740
+ xfs_alert(mp, " ... fblk is NULL");
1741
+ }
1742
+ return -EFSCORRUPTED;
1743
+ }
1744
+
1745
+ /* Get a buffer for the new block. */
1746
+ error = xfs_dir3_free_get_buf(args, fbno, &fbp);
1747
+ if (error)
1748
+ return error;
1749
+ xfs_dir2_free_hdr_from_disk(mp, hdr, fbp->b_addr);
1750
+
1751
+ /* Remember the first slot as our empty slot. */
1752
+ hdr->firstdb = (fbno - xfs_dir2_byte_to_db(args->geo,
1753
+ XFS_DIR2_FREE_OFFSET)) *
1754
+ args->geo->free_max_bests;
1755
+ } else {
1756
+ xfs_dir2_free_hdr_from_disk(mp, hdr, fbp->b_addr);
1757
+ }
1758
+
1759
+ /* Set the freespace block index from the data block number. */
1760
+ *findex = xfs_dir2_db_to_fdindex(args->geo, *dbno);
1761
+
1762
+ /* Extend the freespace table if the new data block is off the end. */
1763
+ if (*findex >= hdr->nvalid) {
1764
+ ASSERT(*findex < args->geo->free_max_bests);
1765
+ hdr->nvalid = *findex + 1;
1766
+ hdr->bests[*findex] = cpu_to_be16(NULLDATAOFF);
1767
+ }
1768
+
1769
+ /*
1770
+ * If this entry was for an empty data block (this should always be
1771
+ * true) then update the header.
1772
+ */
1773
+ if (hdr->bests[*findex] == cpu_to_be16(NULLDATAOFF)) {
1774
+ hdr->nused++;
1775
+ xfs_dir2_free_hdr_to_disk(mp, fbp->b_addr, hdr);
1776
+ xfs_dir2_free_log_header(args, fbp);
1777
+ }
1778
+
1779
+ /* Update the freespace value for the new block in the table. */
1780
+ bf = xfs_dir2_data_bestfree_p(mp, dbp->b_addr);
1781
+ hdr->bests[*findex] = bf[0].length;
1782
+
1783
+ *dbpp = dbp;
1784
+ *fbpp = fbp;
1785
+ return 0;
1786
+}
1787
+
1788
+static int
1789
+xfs_dir2_node_find_freeblk(
1790
+ struct xfs_da_args *args,
1791
+ struct xfs_da_state_blk *fblk,
1792
+ xfs_dir2_db_t *dbnop,
1793
+ struct xfs_buf **fbpp,
1794
+ struct xfs_dir3_icfree_hdr *hdr,
1795
+ int *findexp,
1796
+ int length)
1797
+{
1798
+ struct xfs_inode *dp = args->dp;
1799
+ struct xfs_trans *tp = args->trans;
1800
+ struct xfs_buf *fbp = NULL;
1801
+ xfs_dir2_db_t firstfbno;
1802
+ xfs_dir2_db_t lastfbno;
1803
+ xfs_dir2_db_t ifbno = -1;
1804
+ xfs_dir2_db_t dbno = -1;
1805
+ xfs_dir2_db_t fbno;
1806
+ xfs_fileoff_t fo;
1807
+ int findex = 0;
1808
+ int error;
1809
+
1810
+ /*
1811
+ * If we came in with a freespace block that means that lookup
1812
+ * found an entry with our hash value. This is the freespace
1813
+ * block for that data entry.
1814
+ */
1815
+ if (fblk) {
1816
+ fbp = fblk->bp;
1817
+ findex = fblk->index;
1818
+ xfs_dir2_free_hdr_from_disk(dp->i_mount, hdr, fbp->b_addr);
1819
+ if (findex >= 0) {
1820
+ /* caller already found the freespace for us. */
1821
+ ASSERT(findex < hdr->nvalid);
1822
+ ASSERT(be16_to_cpu(hdr->bests[findex]) != NULLDATAOFF);
1823
+ ASSERT(be16_to_cpu(hdr->bests[findex]) >= length);
1824
+ dbno = hdr->firstdb + findex;
1825
+ goto found_block;
1826
+ }
1827
+
1828
+ /*
1829
+ * The data block looked at didn't have enough room.
1830
+ * We'll start at the beginning of the freespace entries.
1831
+ */
1832
+ ifbno = fblk->blkno;
1833
+ xfs_trans_brelse(tp, fbp);
1834
+ fbp = NULL;
1835
+ fblk->bp = NULL;
1836
+ }
1837
+
1838
+ /*
1839
+ * If we don't have a data block yet, we're going to scan the freespace
1840
+ * data for a data block with enough free space in it.
1841
+ */
1842
+ error = xfs_bmap_last_offset(dp, &fo, XFS_DATA_FORK);
1843
+ if (error)
1844
+ return error;
1845
+ lastfbno = xfs_dir2_da_to_db(args->geo, (xfs_dablk_t)fo);
1846
+ firstfbno = xfs_dir2_byte_to_db(args->geo, XFS_DIR2_FREE_OFFSET);
1847
+
1848
+ for (fbno = lastfbno - 1; fbno >= firstfbno; fbno--) {
1849
+ /* If it's ifbno we already looked at it. */
1850
+ if (fbno == ifbno)
1851
+ continue;
1852
+
1853
+ /*
1854
+ * Read the block. There can be holes in the freespace blocks,
1855
+ * so this might not succeed. This should be really rare, so
1856
+ * there's no reason to avoid it.
1857
+ */
1858
+ error = xfs_dir2_free_try_read(tp, dp,
1859
+ xfs_dir2_db_to_da(args->geo, fbno),
1860
+ &fbp);
1861
+ if (error)
1862
+ return error;
1863
+ if (!fbp)
1864
+ continue;
1865
+
1866
+ xfs_dir2_free_hdr_from_disk(dp->i_mount, hdr, fbp->b_addr);
1867
+
1868
+ /* Scan the free entry array for a large enough free space. */
1869
+ for (findex = hdr->nvalid - 1; findex >= 0; findex--) {
1870
+ if (be16_to_cpu(hdr->bests[findex]) != NULLDATAOFF &&
1871
+ be16_to_cpu(hdr->bests[findex]) >= length) {
1872
+ dbno = hdr->firstdb + findex;
1873
+ goto found_block;
1874
+ }
1875
+ }
1876
+
1877
+ /* Didn't find free space, go on to next free block */
1878
+ xfs_trans_brelse(tp, fbp);
1879
+ }
1880
+
1881
+found_block:
1882
+ *dbnop = dbno;
1883
+ *fbpp = fbp;
1884
+ *findexp = findex;
1885
+ return 0;
1886
+}
1887
+
1888
+/*
1889
+ * Add the data entry for a node-format directory name addition.
1890
+ * The leaf entry is added in xfs_dir2_leafn_add.
1891
+ * We may enter with a freespace block that the lookup found.
1892
+ */
1893
+static int
1894
+xfs_dir2_node_addname_int(
1895
+ struct xfs_da_args *args, /* operation arguments */
1896
+ struct xfs_da_state_blk *fblk) /* optional freespace block */
1897
+{
1898
+ struct xfs_dir2_data_unused *dup; /* data unused entry pointer */
1899
+ struct xfs_dir2_data_entry *dep; /* data entry pointer */
1900
+ struct xfs_dir2_data_hdr *hdr; /* data block header */
1901
+ struct xfs_dir2_data_free *bf;
1902
+ struct xfs_trans *tp = args->trans;
1903
+ struct xfs_inode *dp = args->dp;
1904
+ struct xfs_dir3_icfree_hdr freehdr;
1905
+ struct xfs_buf *dbp; /* data block buffer */
1906
+ struct xfs_buf *fbp; /* freespace buffer */
1907
+ xfs_dir2_data_aoff_t aoff;
1908
+ xfs_dir2_db_t dbno; /* data block number */
1909
+ int error; /* error return value */
1910
+ int findex; /* freespace entry index */
1911
+ int length; /* length of the new entry */
1912
+ int logfree = 0; /* need to log free entry */
1913
+ int needlog = 0; /* need to log data header */
1914
+ int needscan = 0; /* need to rescan data frees */
1915
+ __be16 *tagp; /* data entry tag pointer */
1916
+
1917
+ length = xfs_dir2_data_entsize(dp->i_mount, args->namelen);
1918
+ error = xfs_dir2_node_find_freeblk(args, fblk, &dbno, &fbp, &freehdr,
1919
+ &findex, length);
1920
+ if (error)
1921
+ return error;
1922
+
1923
+ /*
1924
+ * Now we know if we must allocate blocks, so if we are checking whether
1925
+ * we can insert without allocation then we can return now.
1926
+ */
1927
+ if (args->op_flags & XFS_DA_OP_JUSTCHECK) {
1928
+ if (dbno == -1)
1929
+ return -ENOSPC;
1930
+ return 0;
1931
+ }
1932
+
1933
+ /*
1934
+ * If we don't have a data block, we need to allocate one and make
1935
+ * the freespace entries refer to it.
1936
+ */
1937
+ if (dbno == -1) {
1938
+ /* we're going to have to log the free block index later */
1939
+ logfree = 1;
1940
+ error = xfs_dir2_node_add_datablk(args, fblk, &dbno, &dbp, &fbp,
1941
+ &freehdr, &findex);
1942
+ } else {
1943
+ /* Read the data block in. */
1944
+ error = xfs_dir3_data_read(tp, dp,
1945
+ xfs_dir2_db_to_da(args->geo, dbno),
1946
+ 0, &dbp);
1947
+ }
1948
+ if (error)
1949
+ return error;
1950
+
1951
+ /* setup for data block up now */
1952
+ hdr = dbp->b_addr;
1953
+ bf = xfs_dir2_data_bestfree_p(dp->i_mount, hdr);
1954
+ ASSERT(be16_to_cpu(bf[0].length) >= length);
1955
+
1956
+ /* Point to the existing unused space. */
1957
+ dup = (xfs_dir2_data_unused_t *)
1958
+ ((char *)hdr + be16_to_cpu(bf[0].offset));
1959
+
1960
+ /* Mark the first part of the unused space, inuse for us. */
1961
+ aoff = (xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr);
1962
+ error = xfs_dir2_data_use_free(args, dbp, dup, aoff, length,
1963
+ &needlog, &needscan);
1964
+ if (error) {
1965
+ xfs_trans_brelse(tp, dbp);
1966
+ return error;
1967
+ }
1968
+
1969
+ /* Fill in the new entry and log it. */
1970
+ dep = (xfs_dir2_data_entry_t *)dup;
1971
+ dep->inumber = cpu_to_be64(args->inumber);
1972
+ dep->namelen = args->namelen;
1973
+ memcpy(dep->name, args->name, dep->namelen);
1974
+ xfs_dir2_data_put_ftype(dp->i_mount, dep, args->filetype);
1975
+ tagp = xfs_dir2_data_entry_tag_p(dp->i_mount, dep);
1976
+ *tagp = cpu_to_be16((char *)dep - (char *)hdr);
1977
+ xfs_dir2_data_log_entry(args, dbp, dep);
1978
+
1979
+ /* Rescan the freespace and log the data block if needed. */
1980
+ if (needscan)
1981
+ xfs_dir2_data_freescan(dp->i_mount, hdr, &needlog);
1982
+ if (needlog)
1983
+ xfs_dir2_data_log_header(args, dbp);
1984
+
1985
+ /* If the freespace block entry is now wrong, update it. */
1986
+ if (freehdr.bests[findex] != bf[0].length) {
1987
+ freehdr.bests[findex] = bf[0].length;
1988
+ logfree = 1;
1989
+ }
1990
+
1991
+ /* Log the freespace entry if needed. */
1992
+ if (logfree)
1993
+ xfs_dir2_free_log_bests(args, &freehdr, fbp, findex, findex);
1994
+
1995
+ /* Return the data block and offset in args. */
1996
+ args->blkno = (xfs_dablk_t)dbno;
1997
+ args->index = be16_to_cpu(*tagp);
1998
+ return 0;
16151999 }
16162000
16172001 /*
....@@ -1631,9 +2015,7 @@
16312015 /*
16322016 * Allocate and initialize the state (btree cursor).
16332017 */
1634
- state = xfs_da_state_alloc();
1635
- state->args = args;
1636
- state->mp = args->dp->i_mount;
2018
+ state = xfs_da_state_alloc(args);
16372019 /*
16382020 * Look up the name. We're not supposed to find it, but
16392021 * this gives us the insertion point.
....@@ -1684,383 +2066,6 @@
16842066 }
16852067
16862068 /*
1687
- * Add the data entry for a node-format directory name addition.
1688
- * The leaf entry is added in xfs_dir2_leafn_add.
1689
- * We may enter with a freespace block that the lookup found.
1690
- */
1691
-static int /* error */
1692
-xfs_dir2_node_addname_int(
1693
- xfs_da_args_t *args, /* operation arguments */
1694
- xfs_da_state_blk_t *fblk) /* optional freespace block */
1695
-{
1696
- xfs_dir2_data_hdr_t *hdr; /* data block header */
1697
- xfs_dir2_db_t dbno; /* data block number */
1698
- struct xfs_buf *dbp; /* data block buffer */
1699
- xfs_dir2_data_entry_t *dep; /* data entry pointer */
1700
- xfs_inode_t *dp; /* incore directory inode */
1701
- xfs_dir2_data_unused_t *dup; /* data unused entry pointer */
1702
- int error; /* error return value */
1703
- xfs_dir2_db_t fbno; /* freespace block number */
1704
- struct xfs_buf *fbp; /* freespace buffer */
1705
- int findex; /* freespace entry index */
1706
- xfs_dir2_free_t *free=NULL; /* freespace block structure */
1707
- xfs_dir2_db_t ifbno; /* initial freespace block no */
1708
- xfs_dir2_db_t lastfbno=0; /* highest freespace block no */
1709
- int length; /* length of the new entry */
1710
- int logfree; /* need to log free entry */
1711
- xfs_mount_t *mp; /* filesystem mount point */
1712
- int needlog; /* need to log data header */
1713
- int needscan; /* need to rescan data frees */
1714
- __be16 *tagp; /* data entry tag pointer */
1715
- xfs_trans_t *tp; /* transaction pointer */
1716
- __be16 *bests;
1717
- struct xfs_dir3_icfree_hdr freehdr;
1718
- struct xfs_dir2_data_free *bf;
1719
- xfs_dir2_data_aoff_t aoff;
1720
-
1721
- dp = args->dp;
1722
- mp = dp->i_mount;
1723
- tp = args->trans;
1724
- length = dp->d_ops->data_entsize(args->namelen);
1725
- /*
1726
- * If we came in with a freespace block that means that lookup
1727
- * found an entry with our hash value. This is the freespace
1728
- * block for that data entry.
1729
- */
1730
- if (fblk) {
1731
- fbp = fblk->bp;
1732
- /*
1733
- * Remember initial freespace block number.
1734
- */
1735
- ifbno = fblk->blkno;
1736
- free = fbp->b_addr;
1737
- findex = fblk->index;
1738
- bests = dp->d_ops->free_bests_p(free);
1739
- dp->d_ops->free_hdr_from_disk(&freehdr, free);
1740
-
1741
- /*
1742
- * This means the free entry showed that the data block had
1743
- * space for our entry, so we remembered it.
1744
- * Use that data block.
1745
- */
1746
- if (findex >= 0) {
1747
- ASSERT(findex < freehdr.nvalid);
1748
- ASSERT(be16_to_cpu(bests[findex]) != NULLDATAOFF);
1749
- ASSERT(be16_to_cpu(bests[findex]) >= length);
1750
- dbno = freehdr.firstdb + findex;
1751
- } else {
1752
- /*
1753
- * The data block looked at didn't have enough room.
1754
- * We'll start at the beginning of the freespace entries.
1755
- */
1756
- dbno = -1;
1757
- findex = 0;
1758
- }
1759
- } else {
1760
- /*
1761
- * Didn't come in with a freespace block, so no data block.
1762
- */
1763
- ifbno = dbno = -1;
1764
- fbp = NULL;
1765
- findex = 0;
1766
- }
1767
-
1768
- /*
1769
- * If we don't have a data block yet, we're going to scan the
1770
- * freespace blocks looking for one. Figure out what the
1771
- * highest freespace block number is.
1772
- */
1773
- if (dbno == -1) {
1774
- xfs_fileoff_t fo; /* freespace block number */
1775
-
1776
- if ((error = xfs_bmap_last_offset(dp, &fo, XFS_DATA_FORK)))
1777
- return error;
1778
- lastfbno = xfs_dir2_da_to_db(args->geo, (xfs_dablk_t)fo);
1779
- fbno = ifbno;
1780
- }
1781
- /*
1782
- * While we haven't identified a data block, search the freeblock
1783
- * data for a good data block. If we find a null freeblock entry,
1784
- * indicating a hole in the data blocks, remember that.
1785
- */
1786
- while (dbno == -1) {
1787
- /*
1788
- * If we don't have a freeblock in hand, get the next one.
1789
- */
1790
- if (fbp == NULL) {
1791
- /*
1792
- * Happens the first time through unless lookup gave
1793
- * us a freespace block to start with.
1794
- */
1795
- if (++fbno == 0)
1796
- fbno = xfs_dir2_byte_to_db(args->geo,
1797
- XFS_DIR2_FREE_OFFSET);
1798
- /*
1799
- * If it's ifbno we already looked at it.
1800
- */
1801
- if (fbno == ifbno)
1802
- fbno++;
1803
- /*
1804
- * If it's off the end we're done.
1805
- */
1806
- if (fbno >= lastfbno)
1807
- break;
1808
- /*
1809
- * Read the block. There can be holes in the
1810
- * freespace blocks, so this might not succeed.
1811
- * This should be really rare, so there's no reason
1812
- * to avoid it.
1813
- */
1814
- error = xfs_dir2_free_try_read(tp, dp,
1815
- xfs_dir2_db_to_da(args->geo, fbno),
1816
- &fbp);
1817
- if (error)
1818
- return error;
1819
- if (!fbp)
1820
- continue;
1821
- free = fbp->b_addr;
1822
- findex = 0;
1823
- }
1824
- /*
1825
- * Look at the current free entry. Is it good enough?
1826
- *
1827
- * The bests initialisation should be where the bufer is read in
1828
- * the above branch. But gcc is too stupid to realise that bests
1829
- * and the freehdr are actually initialised if they are placed
1830
- * there, so we have to do it here to avoid warnings. Blech.
1831
- */
1832
- bests = dp->d_ops->free_bests_p(free);
1833
- dp->d_ops->free_hdr_from_disk(&freehdr, free);
1834
- if (be16_to_cpu(bests[findex]) != NULLDATAOFF &&
1835
- be16_to_cpu(bests[findex]) >= length)
1836
- dbno = freehdr.firstdb + findex;
1837
- else {
1838
- /*
1839
- * Are we done with the freeblock?
1840
- */
1841
- if (++findex == freehdr.nvalid) {
1842
- /*
1843
- * Drop the block.
1844
- */
1845
- xfs_trans_brelse(tp, fbp);
1846
- fbp = NULL;
1847
- if (fblk && fblk->bp)
1848
- fblk->bp = NULL;
1849
- }
1850
- }
1851
- }
1852
- /*
1853
- * If we don't have a data block, we need to allocate one and make
1854
- * the freespace entries refer to it.
1855
- */
1856
- if (unlikely(dbno == -1)) {
1857
- /*
1858
- * Not allowed to allocate, return failure.
1859
- */
1860
- if ((args->op_flags & XFS_DA_OP_JUSTCHECK) || args->total == 0)
1861
- return -ENOSPC;
1862
-
1863
- /*
1864
- * Allocate and initialize the new data block.
1865
- */
1866
- if (unlikely((error = xfs_dir2_grow_inode(args,
1867
- XFS_DIR2_DATA_SPACE,
1868
- &dbno)) ||
1869
- (error = xfs_dir3_data_init(args, dbno, &dbp))))
1870
- return error;
1871
-
1872
- /*
1873
- * If (somehow) we have a freespace block, get rid of it.
1874
- */
1875
- if (fbp)
1876
- xfs_trans_brelse(tp, fbp);
1877
- if (fblk && fblk->bp)
1878
- fblk->bp = NULL;
1879
-
1880
- /*
1881
- * Get the freespace block corresponding to the data block
1882
- * that was just allocated.
1883
- */
1884
- fbno = dp->d_ops->db_to_fdb(args->geo, dbno);
1885
- error = xfs_dir2_free_try_read(tp, dp,
1886
- xfs_dir2_db_to_da(args->geo, fbno),
1887
- &fbp);
1888
- if (error)
1889
- return error;
1890
-
1891
- /*
1892
- * If there wasn't a freespace block, the read will
1893
- * return a NULL fbp. Allocate and initialize a new one.
1894
- */
1895
- if (!fbp) {
1896
- error = xfs_dir2_grow_inode(args, XFS_DIR2_FREE_SPACE,
1897
- &fbno);
1898
- if (error)
1899
- return error;
1900
-
1901
- if (dp->d_ops->db_to_fdb(args->geo, dbno) != fbno) {
1902
- xfs_alert(mp,
1903
-"%s: dir ino %llu needed freesp block %lld for data block %lld, got %lld ifbno %llu lastfbno %d",
1904
- __func__, (unsigned long long)dp->i_ino,
1905
- (long long)dp->d_ops->db_to_fdb(
1906
- args->geo, dbno),
1907
- (long long)dbno, (long long)fbno,
1908
- (unsigned long long)ifbno, lastfbno);
1909
- if (fblk) {
1910
- xfs_alert(mp,
1911
- " fblk "PTR_FMT" blkno %llu index %d magic 0x%x",
1912
- fblk,
1913
- (unsigned long long)fblk->blkno,
1914
- fblk->index,
1915
- fblk->magic);
1916
- } else {
1917
- xfs_alert(mp, " ... fblk is NULL");
1918
- }
1919
- XFS_ERROR_REPORT("xfs_dir2_node_addname_int",
1920
- XFS_ERRLEVEL_LOW, mp);
1921
- return -EFSCORRUPTED;
1922
- }
1923
-
1924
- /*
1925
- * Get a buffer for the new block.
1926
- */
1927
- error = xfs_dir3_free_get_buf(args, fbno, &fbp);
1928
- if (error)
1929
- return error;
1930
- free = fbp->b_addr;
1931
- bests = dp->d_ops->free_bests_p(free);
1932
- dp->d_ops->free_hdr_from_disk(&freehdr, free);
1933
-
1934
- /*
1935
- * Remember the first slot as our empty slot.
1936
- */
1937
- freehdr.firstdb =
1938
- (fbno - xfs_dir2_byte_to_db(args->geo,
1939
- XFS_DIR2_FREE_OFFSET)) *
1940
- dp->d_ops->free_max_bests(args->geo);
1941
- } else {
1942
- free = fbp->b_addr;
1943
- bests = dp->d_ops->free_bests_p(free);
1944
- dp->d_ops->free_hdr_from_disk(&freehdr, free);
1945
- }
1946
-
1947
- /*
1948
- * Set the freespace block index from the data block number.
1949
- */
1950
- findex = dp->d_ops->db_to_fdindex(args->geo, dbno);
1951
- /*
1952
- * If it's after the end of the current entries in the
1953
- * freespace block, extend that table.
1954
- */
1955
- if (findex >= freehdr.nvalid) {
1956
- ASSERT(findex < dp->d_ops->free_max_bests(args->geo));
1957
- freehdr.nvalid = findex + 1;
1958
- /*
1959
- * Tag new entry so nused will go up.
1960
- */
1961
- bests[findex] = cpu_to_be16(NULLDATAOFF);
1962
- }
1963
- /*
1964
- * If this entry was for an empty data block
1965
- * (this should always be true) then update the header.
1966
- */
1967
- if (bests[findex] == cpu_to_be16(NULLDATAOFF)) {
1968
- freehdr.nused++;
1969
- dp->d_ops->free_hdr_to_disk(fbp->b_addr, &freehdr);
1970
- xfs_dir2_free_log_header(args, fbp);
1971
- }
1972
- /*
1973
- * Update the real value in the table.
1974
- * We haven't allocated the data entry yet so this will
1975
- * change again.
1976
- */
1977
- hdr = dbp->b_addr;
1978
- bf = dp->d_ops->data_bestfree_p(hdr);
1979
- bests[findex] = bf[0].length;
1980
- logfree = 1;
1981
- }
1982
- /*
1983
- * We had a data block so we don't have to make a new one.
1984
- */
1985
- else {
1986
- /*
1987
- * If just checking, we succeeded.
1988
- */
1989
- if (args->op_flags & XFS_DA_OP_JUSTCHECK)
1990
- return 0;
1991
-
1992
- /*
1993
- * Read the data block in.
1994
- */
1995
- error = xfs_dir3_data_read(tp, dp,
1996
- xfs_dir2_db_to_da(args->geo, dbno),
1997
- -1, &dbp);
1998
- if (error)
1999
- return error;
2000
- hdr = dbp->b_addr;
2001
- bf = dp->d_ops->data_bestfree_p(hdr);
2002
- logfree = 0;
2003
- }
2004
- ASSERT(be16_to_cpu(bf[0].length) >= length);
2005
- /*
2006
- * Point to the existing unused space.
2007
- */
2008
- dup = (xfs_dir2_data_unused_t *)
2009
- ((char *)hdr + be16_to_cpu(bf[0].offset));
2010
- needscan = needlog = 0;
2011
- /*
2012
- * Mark the first part of the unused space, inuse for us.
2013
- */
2014
- aoff = (xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr);
2015
- error = xfs_dir2_data_use_free(args, dbp, dup, aoff, length,
2016
- &needlog, &needscan);
2017
- if (error) {
2018
- xfs_trans_brelse(tp, dbp);
2019
- return error;
2020
- }
2021
- /*
2022
- * Fill in the new entry and log it.
2023
- */
2024
- dep = (xfs_dir2_data_entry_t *)dup;
2025
- dep->inumber = cpu_to_be64(args->inumber);
2026
- dep->namelen = args->namelen;
2027
- memcpy(dep->name, args->name, dep->namelen);
2028
- dp->d_ops->data_put_ftype(dep, args->filetype);
2029
- tagp = dp->d_ops->data_entry_tag_p(dep);
2030
- *tagp = cpu_to_be16((char *)dep - (char *)hdr);
2031
- xfs_dir2_data_log_entry(args, dbp, dep);
2032
- /*
2033
- * Rescan the block for bestfree if needed.
2034
- */
2035
- if (needscan)
2036
- xfs_dir2_data_freescan(dp, hdr, &needlog);
2037
- /*
2038
- * Log the data block header if needed.
2039
- */
2040
- if (needlog)
2041
- xfs_dir2_data_log_header(args, dbp);
2042
- /*
2043
- * If the freespace entry is now wrong, update it.
2044
- */
2045
- bests = dp->d_ops->free_bests_p(free); /* gcc is so stupid */
2046
- if (be16_to_cpu(bests[findex]) != be16_to_cpu(bf[0].length)) {
2047
- bests[findex] = bf[0].length;
2048
- logfree = 1;
2049
- }
2050
- /*
2051
- * Log the freespace entry if needed.
2052
- */
2053
- if (logfree)
2054
- xfs_dir2_free_log_bests(args, fbp, findex, findex);
2055
- /*
2056
- * Return the data block and offset in args, then drop the data block.
2057
- */
2058
- args->blkno = (xfs_dablk_t)dbno;
2059
- args->index = be16_to_cpu(*tagp);
2060
- return 0;
2061
-}
2062
-
2063
-/*
20642069 * Lookup an entry in a node-format directory.
20652070 * All the real work happens in xfs_da3_node_lookup_int.
20662071 * The only real output is the inode number of the entry.
....@@ -2079,9 +2084,8 @@
20792084 /*
20802085 * Allocate and initialize the btree cursor.
20812086 */
2082
- state = xfs_da_state_alloc();
2083
- state->args = args;
2084
- state->mp = args->dp->i_mount;
2087
+ state = xfs_da_state_alloc(args);
2088
+
20852089 /*
20862090 * Fill in the path to the entry in the cursor.
20872091 */
....@@ -2132,9 +2136,7 @@
21322136 /*
21332137 * Allocate and initialize the btree cursor.
21342138 */
2135
- state = xfs_da_state_alloc();
2136
- state->args = args;
2137
- state->mp = args->dp->i_mount;
2139
+ state = xfs_da_state_alloc(args);
21382140
21392141 /* Look up the entry we're deleting, set up the cursor. */
21402142 error = xfs_da3_node_lookup_int(state, &rval);
....@@ -2191,8 +2193,6 @@
21912193 int i; /* btree level */
21922194 xfs_ino_t inum; /* new inode number */
21932195 int ftype; /* new file type */
2194
- xfs_dir2_leaf_t *leaf; /* leaf structure */
2195
- xfs_dir2_leaf_entry_t *lep; /* leaf entry being changed */
21962196 int rval; /* internal return value */
21972197 xfs_da_state_t *state; /* btree cursor */
21982198
....@@ -2201,9 +2201,7 @@
22012201 /*
22022202 * Allocate and initialize the btree cursor.
22032203 */
2204
- state = xfs_da_state_alloc();
2205
- state->args = args;
2206
- state->mp = args->dp->i_mount;
2204
+ state = xfs_da_state_alloc(args);
22072205
22082206 /*
22092207 * We have to save new inode number and ftype since
....@@ -2224,16 +2222,17 @@
22242222 * and locked it. But paranoia is good.
22252223 */
22262224 if (rval == -EEXIST) {
2227
- struct xfs_dir2_leaf_entry *ents;
2225
+ struct xfs_dir3_icleaf_hdr leafhdr;
2226
+
22282227 /*
22292228 * Find the leaf entry.
22302229 */
22312230 blk = &state->path.blk[state->path.active - 1];
22322231 ASSERT(blk->magic == XFS_DIR2_LEAFN_MAGIC);
2233
- leaf = blk->bp->b_addr;
2234
- ents = args->dp->d_ops->leaf_ents_p(leaf);
2235
- lep = &ents[blk->index];
22362232 ASSERT(state->extravalid);
2233
+
2234
+ xfs_dir2_leaf_hdr_from_disk(state->mp, &leafhdr,
2235
+ blk->bp->b_addr);
22372236 /*
22382237 * Point to the data entry.
22392238 */
....@@ -2243,13 +2242,13 @@
22432242 dep = (xfs_dir2_data_entry_t *)
22442243 ((char *)hdr +
22452244 xfs_dir2_dataptr_to_off(args->geo,
2246
- be32_to_cpu(lep->address)));
2245
+ be32_to_cpu(leafhdr.ents[blk->index].address)));
22472246 ASSERT(inum != be64_to_cpu(dep->inumber));
22482247 /*
22492248 * Fill in the new inode number and log the entry.
22502249 */
22512250 dep->inumber = cpu_to_be64(inum);
2252
- args->dp->d_ops->data_put_ftype(dep, ftype);
2251
+ xfs_dir2_data_put_ftype(state->mp, dep, ftype);
22532252 xfs_dir2_data_log_entry(args, state->extrablk.bp, dep);
22542253 rval = 0;
22552254 }
....@@ -2306,7 +2305,7 @@
23062305 if (!bp)
23072306 return 0;
23082307 free = bp->b_addr;
2309
- dp->d_ops->free_hdr_from_disk(&freehdr, free);
2308
+ xfs_dir2_free_hdr_from_disk(dp->i_mount, &freehdr, free);
23102309
23112310 /*
23122311 * If there are used entries, there's nothing to do.