aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/dir.c
diff options
context:
space:
mode:
authorSteven Whitehouse <swhiteho@redhat.com>2006-03-20 12:30:04 -0500
committerSteven Whitehouse <swhiteho@redhat.com>2006-03-20 12:30:04 -0500
commitc752666c17f870fa8ae9f16804dd457e9e6daaec (patch)
treec3c48383f386a24edbdf3c6292f25b587e6d9368 /fs/gfs2/dir.c
parent419c93e0b6b9eef0bf26b8ad415f2a5bf4300119 (diff)
[GFS2] Fix bug in directory code and tidy up
Due to a typo, the dir leaf split operation was (for the first split in a directory) writing the new hash vaules at the wrong offset. This is now fixed. Also some other tidy ups are included: - We use GFS2's hash function for dentries (see ops_dentry.c) so that we don't have to keep recalculating the hash values. - A lot of common code is eliminated between the various directory lookup routines. - Better error checking on directory lookup (previously different routines checked for different errors) - The leaf split operation has a couple of redundant operations removed from it, so it should be faster. There is still further scope for further clean ups in the directory code, and readdir in particular could do with slimming down a bit. Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/gfs2/dir.c')
-rw-r--r--fs/gfs2/dir.c1360
1 files changed, 519 insertions, 841 deletions
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
index 37f70ca558cc..f31f163da1a1 100644
--- a/fs/gfs2/dir.c
+++ b/fs/gfs2/dir.c
@@ -130,7 +130,7 @@ static int gfs2_dir_write_stuffed(struct gfs2_inode *ip, const char *buf,
130 return error; 130 return error;
131 131
132 gfs2_trans_add_bh(ip->i_gl, dibh, 1); 132 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
133 memcpy(dibh->b_data + offset + sizeof(struct gfs2_inode), buf, size); 133 memcpy(dibh->b_data + offset + sizeof(struct gfs2_dinode), buf, size);
134 if (ip->i_di.di_size < offset + size) 134 if (ip->i_di.di_size < offset + size)
135 ip->i_di.di_size = offset + size; 135 ip->i_di.di_size = offset + size;
136 ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); 136 ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds();
@@ -177,7 +177,7 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf,
177 if (gfs2_is_stuffed(ip)) { 177 if (gfs2_is_stuffed(ip)) {
178 error = gfs2_unstuff_dinode(ip, NULL, NULL); 178 error = gfs2_unstuff_dinode(ip, NULL, NULL);
179 if (error) 179 if (error)
180 return error; 180 return error;
181 } 181 }
182 182
183 lblock = offset; 183 lblock = offset;
@@ -244,7 +244,7 @@ fail:
244} 244}
245 245
246static int gfs2_dir_read_stuffed(struct gfs2_inode *ip, char *buf, 246static int gfs2_dir_read_stuffed(struct gfs2_inode *ip, char *buf,
247 unsigned int offset, unsigned int size) 247 unsigned int offset, unsigned int size)
248{ 248{
249 struct buffer_head *dibh; 249 struct buffer_head *dibh;
250 int error; 250 int error;
@@ -343,26 +343,159 @@ fail:
343 return (copied) ? copied : error; 343 return (copied) ? copied : error;
344} 344}
345 345
346/** 346typedef int (*gfs2_dscan_t)(const struct gfs2_dirent *dent,
347 * int gfs2_filecmp - Compare two filenames 347 const struct qstr *name);
348 * @file1: The first filename 348
349 * @file2: The second filename 349static inline int __gfs2_dirent_find(const struct gfs2_dirent *dent,
350 * @len_of_file2: The length of the second file 350 const struct qstr *name, int ret)
351 * 351{
352 * This routine compares two filenames and returns 1 if they are equal. 352 if (dent->de_inum.no_addr != 0 &&
353 * 353 be32_to_cpu(dent->de_hash) == name->hash &&
354 * Returns: 1 if the files are the same, otherwise 0. 354 be16_to_cpu(dent->de_name_len) == name->len &&
355 memcmp((char *)(dent+1), name->name, name->len) == 0)
356 return ret;
357 return 0;
358}
359
360static int gfs2_dirent_find(const struct gfs2_dirent *dent,
361 const struct qstr *name)
362{
363 return __gfs2_dirent_find(dent, name, 1);
364}
365
366static int gfs2_dirent_prev(const struct gfs2_dirent *dent,
367 const struct qstr *name)
368{
369 return __gfs2_dirent_find(dent, name, 2);
370}
371
372/*
373 * name->name holds ptr to start of block.
374 * name->len holds size of block.
355 */ 375 */
376static int gfs2_dirent_last(const struct gfs2_dirent *dent,
377 const struct qstr *name)
378{
379 const char *start = name->name;
380 const char *end = (const char *)dent + be16_to_cpu(dent->de_rec_len);
381 if (name->len == (end - start))
382 return 1;
383 return 0;
384}
356 385
357int gfs2_filecmp(struct qstr *file1, char *file2, int len_of_file2) 386static int gfs2_dirent_find_space(const struct gfs2_dirent *dent,
387 const struct qstr *name)
358{ 388{
359 if (file1->len != len_of_file2) 389 unsigned required = GFS2_DIRENT_SIZE(name->len);
360 return 0; 390 unsigned actual = GFS2_DIRENT_SIZE(be16_to_cpu(dent->de_name_len));
361 if (memcmp(file1->name, file2, file1->len)) 391 unsigned totlen = be16_to_cpu(dent->de_rec_len);
362 return 0; 392
363 return 1; 393 if ((totlen - actual) >= required)
394 return 1;
395 return 0;
364} 396}
365 397
398/*
399 * Other possible things to check:
400 * - Inode located within filesystem size (and on valid block)
401 * - Valid directory entry type
402 * Not sure how heavy-weight we want to make this... could also check
403 * hash is correct for example, but that would take a lot of extra time.
404 * For now the most important thing is to check that the various sizes
405 * are correct.
406 */
407static int gfs2_check_dirent(struct gfs2_dirent *dent, unsigned int offset,
408 unsigned int size, unsigned int len, int first)
409{
410 const char *msg = "gfs2_dirent too small";
411 if (unlikely(size < sizeof(struct gfs2_dirent)))
412 goto error;
413 msg = "gfs2_dirent misaligned";
414 if (unlikely(offset & 0x7))
415 goto error;
416 msg = "gfs2_dirent points beyond end of block";
417 if (unlikely(offset + size > len))
418 goto error;
419 msg = "zero inode number";
420 if (unlikely(!first && !dent->de_inum.no_addr))
421 goto error;
422 msg = "name length is greater than space in dirent";
423 if (dent->de_inum.no_addr &&
424 unlikely(sizeof(struct gfs2_dirent)+be16_to_cpu(dent->de_name_len) >
425 size))
426 goto error;
427 return 0;
428error:
429 printk(KERN_WARNING "gfs2_check_dirent: %s (%s)\n", msg,
430 first ? "first in block" : "not first in block");
431 return -EIO;
432}
433
434static struct gfs2_dirent *gfs2_dirent_scan(struct inode *inode,
435 void *buf,
436 unsigned int len, gfs2_dscan_t scan,
437 const struct qstr *name)
438{
439 struct gfs2_meta_header *h = buf;
440 struct gfs2_dirent *dent, *prev;
441 unsigned offset;
442 unsigned size;
443 int ret = 0;
444
445 BUG_ON(buf == NULL);
446 BUG_ON(name == NULL);
447
448 switch(be16_to_cpu(h->mh_type)) {
449 case GFS2_METATYPE_LF:
450 offset = sizeof(struct gfs2_leaf);
451 break;
452 case GFS2_METATYPE_DI:
453 offset = sizeof(struct gfs2_dinode);
454 break;
455 default:
456 goto wrong_type;
457 }
458
459 prev = NULL;
460 dent = (struct gfs2_dirent *)(buf + offset);
461 size = be16_to_cpu(dent->de_rec_len);
462 if (gfs2_check_dirent(dent, offset, size, len, 1))
463 goto consist_inode;
464 do {
465 ret = scan(dent, name);
466 if (ret)
467 break;
468 offset += size;
469 if (offset == len)
470 break;
471 prev = dent;
472 dent = (struct gfs2_dirent *)(buf + offset);
473 size = be16_to_cpu(dent->de_rec_len);
474 if (gfs2_check_dirent(dent, offset, size, len, 0))
475 goto consist_inode;
476 } while(1);
477
478 switch(ret) {
479 case 0:
480 return NULL;
481 case 1:
482 return dent;
483 case 2:
484 return prev ? prev : dent;
485 default:
486 BUG_ON(ret > 0);
487 return ERR_PTR(ret);
488 }
489
490wrong_type:
491 printk(KERN_WARNING "gfs2_scan_dirent: %p wrong block type %u\n", scan,
492 be16_to_cpu(h->mh_type));
493consist_inode:
494 gfs2_consist_inode(inode->u.generic_ip);
495 return ERR_PTR(-EIO);
496}
497
498
366/** 499/**
367 * dirent_first - Return the first dirent 500 * dirent_first - Return the first dirent
368 * @dip: the directory 501 * @dip: the directory
@@ -489,180 +622,39 @@ static void dirent_del(struct gfs2_inode *dip, struct buffer_head *bh,
489 prev->de_rec_len = cpu_to_be16(prev_rec_len); 622 prev->de_rec_len = cpu_to_be16(prev_rec_len);
490} 623}
491 624
492/** 625/*
493 * gfs2_dirent_alloc - Allocate a directory entry 626 * Takes a dent from which to grab space as an argument. Returns the
494 * @dip: The GFS2 inode 627 * newly created dent.
495 * @bh: The buffer
496 * @name_len: The length of the name
497 * @dent_out: Pointer to list of dirents
498 *
499 * Returns: 0 on success, error code otherwise
500 */ 628 */
501 629struct gfs2_dirent *gfs2_init_dirent(struct inode *inode,
502int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh, 630 struct gfs2_dirent *dent,
503 int name_len, struct gfs2_dirent **dent_out) 631 const struct qstr *name,
632 struct buffer_head *bh)
504{ 633{
505 struct gfs2_dirent *dent, *new; 634 struct gfs2_inode *ip = inode->u.generic_ip;
506 unsigned int rec_len = GFS2_DIRENT_SIZE(name_len); 635 struct gfs2_dirent *ndent;
507 unsigned int entries = 0, offset = 0; 636 unsigned offset = 0, totlen;
508 int type; 637
509 638 if (dent->de_inum.no_addr)
510 type = dirent_first(dip, bh, &dent); 639 offset = GFS2_DIRENT_SIZE(be16_to_cpu(dent->de_name_len));
511 if (type < 0) 640 totlen = be16_to_cpu(dent->de_rec_len);
512 return type; 641 BUG_ON(offset + name->len > totlen);
513 642 gfs2_trans_add_bh(ip->i_gl, bh, 1);
514 if (type == IS_LEAF) { 643 ndent = (struct gfs2_dirent *)((char *)dent + offset);
515 struct gfs2_leaf *leaf = (struct gfs2_leaf *)bh->b_data; 644 dent->de_rec_len = cpu_to_be16(offset);
516 entries = be16_to_cpu(leaf->lf_entries); 645 gfs2_qstr2dirent(name, totlen - offset, ndent);
517 offset = sizeof(struct gfs2_leaf); 646 return ndent;
518 } else {
519 struct gfs2_dinode *dinode = (struct gfs2_dinode *)bh->b_data;
520 entries = be32_to_cpu(dinode->di_entries);
521 offset = sizeof(struct gfs2_dinode);
522 }
523
524 if (!entries) {
525 if (dent->de_inum.no_addr) {
526 gfs2_consist_inode(dip);
527 return -EIO;
528 }
529
530 gfs2_trans_add_bh(dip->i_gl, bh, 1);
531
532 dent->de_rec_len = cpu_to_be16(bh->b_size - offset);
533 dent->de_name_len = cpu_to_be16(name_len);
534
535 *dent_out = dent;
536 return 0;
537 }
538
539 do {
540 uint16_t cur_rec_len;
541 uint16_t cur_name_len;
542
543 cur_rec_len = be16_to_cpu(dent->de_rec_len);
544 cur_name_len = be16_to_cpu(dent->de_name_len);
545
546 if ((!dent->de_inum.no_addr && cur_rec_len >= rec_len) ||
547 (cur_rec_len >= GFS2_DIRENT_SIZE(cur_name_len) + rec_len)) {
548 gfs2_trans_add_bh(dip->i_gl, bh, 1);
549
550 if (dent->de_inum.no_addr) {
551 new = (struct gfs2_dirent *)((char *)dent +
552 GFS2_DIRENT_SIZE(cur_name_len));
553 memset(new, 0, sizeof(struct gfs2_dirent));
554
555 new->de_rec_len = cpu_to_be16(cur_rec_len -
556 GFS2_DIRENT_SIZE(cur_name_len));
557 new->de_name_len = cpu_to_be16(name_len);
558
559 dent->de_rec_len = cpu_to_be16(cur_rec_len -
560 be16_to_cpu(new->de_rec_len));
561
562 *dent_out = new;
563 return 0;
564 }
565
566 dent->de_name_len = cpu_to_be16(name_len);
567
568 *dent_out = dent;
569 return 0;
570 }
571 } while (dirent_next(dip, bh, &dent) == 0);
572
573 return -ENOSPC;
574} 647}
575 648
576/** 649static struct gfs2_dirent *gfs2_dirent_alloc(struct inode *inode,
577 * dirent_fits - See if we can fit a entry in this buffer 650 struct buffer_head *bh,
578 * @dip: The GFS2 inode 651 const struct qstr *name)
579 * @bh: The buffer
580 * @name_len: The length of the name
581 *
582 * Returns: 1 if it can fit, 0 otherwise
583 */
584
585static int dirent_fits(struct gfs2_inode *dip, struct buffer_head *bh,
586 int name_len)
587{ 652{
588 struct gfs2_dirent *dent; 653 struct gfs2_dirent *dent;
589 unsigned int rec_len = GFS2_DIRENT_SIZE(name_len); 654 dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, gfs2_dirent_find_space, name);
590 unsigned int entries = 0; 655 if (!dent || IS_ERR(dent))
591 int type; 656 return dent;
592 657 return gfs2_init_dirent(inode, dent, name, bh);
593 type = dirent_first(dip, bh, &dent);
594 if (type < 0)
595 return type;
596
597 if (type == IS_LEAF) {
598 struct gfs2_leaf *leaf = (struct gfs2_leaf *)bh->b_data;
599 entries = be16_to_cpu(leaf->lf_entries);
600 } else {
601 struct gfs2_dinode *dinode = (struct gfs2_dinode *)bh->b_data;
602 entries = be32_to_cpu(dinode->di_entries);
603 }
604
605 if (!entries)
606 return 1;
607
608 do {
609 uint16_t cur_rec_len;
610 uint32_t cur_name_len;
611
612 cur_rec_len = be16_to_cpu(dent->de_rec_len);
613 cur_name_len = be16_to_cpu(dent->de_name_len);
614
615 if ((!dent->de_inum.no_addr && cur_rec_len >= rec_len) ||
616 (cur_rec_len >= GFS2_DIRENT_SIZE(cur_name_len) + rec_len))
617 return 1;
618 } while (dirent_next(dip, bh, &dent) == 0);
619
620 return 0;
621}
622
623static int leaf_search(struct gfs2_inode *dip, struct buffer_head *bh,
624 struct qstr *filename, struct gfs2_dirent **dent_out,
625 struct gfs2_dirent **dent_prev)
626{
627 uint32_t hash;
628 struct gfs2_dirent *dent, *prev = NULL;
629 unsigned int entries = 0;
630 int type;
631
632 type = dirent_first(dip, bh, &dent);
633 if (type < 0)
634 return type;
635
636 if (type == IS_LEAF) {
637 struct gfs2_leaf *leaf = (struct gfs2_leaf *)bh->b_data;
638 entries = be16_to_cpu(leaf->lf_entries);
639 } else if (type == IS_DINODE) {
640 struct gfs2_dinode *dinode = (struct gfs2_dinode *)bh->b_data;
641 entries = be32_to_cpu(dinode->di_entries);
642 }
643
644 hash = gfs2_disk_hash(filename->name, filename->len);
645
646 do {
647 if (!dent->de_inum.no_addr) {
648 prev = dent;
649 continue;
650 }
651
652 if (be32_to_cpu(dent->de_hash) == hash &&
653 gfs2_filecmp(filename, (char *)(dent + 1),
654 be16_to_cpu(dent->de_name_len))) {
655 *dent_out = dent;
656 if (dent_prev)
657 *dent_prev = prev;
658
659 return 0;
660 }
661
662 prev = dent;
663 } while (dirent_next(dip, bh, &dent) == 0);
664
665 return -ENOENT;
666} 658}
667 659
668static int get_leaf(struct gfs2_inode *dip, uint64_t leaf_no, 660static int get_leaf(struct gfs2_inode *dip, uint64_t leaf_no,
@@ -716,75 +708,81 @@ static int get_first_leaf(struct gfs2_inode *dip, uint32_t index,
716 return error; 708 return error;
717} 709}
718 710
719static int get_next_leaf(struct gfs2_inode *dip, struct buffer_head *bh_in, 711static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode,
720 struct buffer_head **bh_out) 712 const struct qstr *name,
713 gfs2_dscan_t scan,
714 struct buffer_head **pbh)
721{ 715{
722 struct gfs2_leaf *leaf; 716 struct buffer_head *bh;
723 int error; 717 struct gfs2_dirent *dent;
724 718 struct gfs2_inode *ip = inode->u.generic_ip;
725 leaf = (struct gfs2_leaf *)bh_in->b_data;
726
727 if (!leaf->lf_next)
728 error = -ENOENT;
729 else
730 error = get_leaf(dip, be64_to_cpu(leaf->lf_next), bh_out);
731
732 return error;
733}
734
735static int linked_leaf_search(struct gfs2_inode *dip, struct qstr *filename,
736 struct gfs2_dirent **dent_out,
737 struct gfs2_dirent **dent_prev,
738 struct buffer_head **bh_out)
739{
740 struct buffer_head *bh = NULL, *bh_next;
741 uint32_t hsize, index;
742 uint32_t hash;
743 int error; 719 int error;
744 720
745 hsize = 1 << dip->i_di.di_depth; 721 if (ip->i_di.di_flags & GFS2_DIF_EXHASH) {
746 if (hsize * sizeof(uint64_t) != dip->i_di.di_size) { 722 struct gfs2_leaf *leaf;
747 gfs2_consist_inode(dip); 723 unsigned hsize = 1 << ip->i_di.di_depth;
748 return -EIO; 724 unsigned index;
749 } 725 u64 ln;
750 726 if (hsize * sizeof(u64) != ip->i_di.di_size) {
751 /* Figure out the address of the leaf node. */ 727 gfs2_consist_inode(ip);
752 728 return ERR_PTR(-EIO);
753 hash = gfs2_disk_hash(filename->name, filename->len); 729 }
754 index = hash >> (32 - dip->i_di.di_depth);
755
756 error = get_first_leaf(dip, index, &bh_next);
757 if (error)
758 return error;
759
760 /* Find the entry */
761
762 do {
763 brelse(bh);
764
765 bh = bh_next;
766
767 error = leaf_search(dip, bh, filename, dent_out, dent_prev);
768 switch (error) {
769 case 0:
770 *bh_out = bh;
771 return 0;
772
773 case -ENOENT:
774 break;
775 730
776 default: 731 index = name->hash >> (32 - ip->i_di.di_depth);
732 error = get_first_leaf(ip, index, &bh);
733 if (error)
734 return ERR_PTR(error);
735 do {
736 dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size,
737 scan, name);
738 if (dent)
739 goto got_dent;
740 leaf = (struct gfs2_leaf *)bh->b_data;
741 ln = be64_to_cpu(leaf->lf_next);
777 brelse(bh); 742 brelse(bh);
778 return error; 743 if (!ln)
779 } 744 break;
745 error = get_leaf(ip, ln, &bh);
746 } while(!error);
780 747
781 error = get_next_leaf(dip, bh, &bh_next); 748 return error ? ERR_PTR(error) : NULL;
782 } 749 }
783 while (!error);
784 750
785 brelse(bh); 751 error = gfs2_meta_inode_buffer(ip, &bh);
752 if (error)
753 return ERR_PTR(error);
754 dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, scan, name);
755got_dent:
756 *pbh = bh;
757 return dent;
758}
786 759
787 return error; 760static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh, u16 depth)
761{
762 struct gfs2_inode *ip = inode->u.generic_ip;
763 u64 bn = gfs2_alloc_meta(ip);
764 struct buffer_head *bh = gfs2_meta_new(ip->i_gl, bn);
765 struct gfs2_leaf *leaf;
766 struct gfs2_dirent *dent;
767 if (!bh)
768 return NULL;
769 gfs2_trans_add_bh(ip->i_gl, bh, 1);
770 gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF);
771 leaf = (struct gfs2_leaf *)bh->b_data;
772 leaf->lf_depth = cpu_to_be16(depth);
773 leaf->lf_entries = cpu_to_be16(0);
774 leaf->lf_dirent_format = cpu_to_be16(GFS2_FORMAT_DE);
775 leaf->lf_next = cpu_to_be64(0);
776 memset(leaf->lf_reserved, 0, sizeof(leaf->lf_reserved));
777 dent = (struct gfs2_dirent *)(leaf+1);
778 dent->de_inum.no_formal_ino = cpu_to_be64(0);
779 dent->de_inum.no_addr = cpu_to_be64(0);
780 dent->de_hash = cpu_to_be32(0);
781 dent->de_rec_len = cpu_to_be16(bh->b_size - sizeof(struct gfs2_leaf));
782 dent->de_name_len = cpu_to_be16(0);
783 dent->de_type = cpu_to_be16(0);
784 *pbh = bh;
785 return leaf;
788} 786}
789 787
790/** 788/**
@@ -794,10 +792,12 @@ static int linked_leaf_search(struct gfs2_inode *dip, struct qstr *filename,
794 * Returns: 0 on success, error code otherwise 792 * Returns: 0 on success, error code otherwise
795 */ 793 */
796 794
797static int dir_make_exhash(struct gfs2_inode *dip) 795static int dir_make_exhash(struct inode *inode)
798{ 796{
797 struct gfs2_inode *dip = inode->u.generic_ip;
799 struct gfs2_sbd *sdp = dip->i_sbd; 798 struct gfs2_sbd *sdp = dip->i_sbd;
800 struct gfs2_dirent *dent; 799 struct gfs2_dirent *dent;
800 struct qstr args;
801 struct buffer_head *bh, *dibh; 801 struct buffer_head *bh, *dibh;
802 struct gfs2_leaf *leaf; 802 struct gfs2_leaf *leaf;
803 int y; 803 int y;
@@ -809,24 +809,14 @@ static int dir_make_exhash(struct gfs2_inode *dip)
809 if (error) 809 if (error)
810 return error; 810 return error;
811 811
812 /* Allocate a new block for the first leaf node */
813
814 bn = gfs2_alloc_meta(dip);
815
816 /* Turn over a new leaf */ 812 /* Turn over a new leaf */
817 813
818 bh = gfs2_meta_new(dip->i_gl, bn); 814 leaf = new_leaf(inode, &bh, 0);
819 gfs2_trans_add_bh(dip->i_gl, bh, 1); 815 if (!leaf)
820 gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); 816 return -ENOSPC;
821 gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); 817 bn = bh->b_blocknr;
822
823 /* Fill in the leaf structure */
824
825 leaf = (struct gfs2_leaf *)bh->b_data;
826 818
827 gfs2_assert(sdp, dip->i_di.di_entries < (1 << 16)); 819 gfs2_assert(sdp, dip->i_di.di_entries < (1 << 16));
828
829 leaf->lf_dirent_format = cpu_to_be32(GFS2_FORMAT_DE);
830 leaf->lf_entries = cpu_to_be16(dip->i_di.di_entries); 820 leaf->lf_entries = cpu_to_be16(dip->i_di.di_entries);
831 821
832 /* Copy dirents */ 822 /* Copy dirents */
@@ -837,15 +827,21 @@ static int dir_make_exhash(struct gfs2_inode *dip)
837 /* Find last entry */ 827 /* Find last entry */
838 828
839 x = 0; 829 x = 0;
840 dirent_first(dip, bh, &dent); 830 args.len = bh->b_size - sizeof(struct gfs2_dinode) +
841 831 sizeof(struct gfs2_leaf);
842 do { 832 args.name = bh->b_data;
843 if (!dent->de_inum.no_addr) 833 dent = gfs2_dirent_scan(dip->i_vnode, bh->b_data, bh->b_size,
844 continue; 834 gfs2_dirent_last, &args);
845 if (++x == dip->i_di.di_entries) 835 if (!dent) {
846 break; 836 brelse(bh);
837 brelse(dibh);
838 return -EIO;
839 }
840 if (IS_ERR(dent)) {
841 brelse(bh);
842 brelse(dibh);
843 return PTR_ERR(dent);
847 } 844 }
848 while (dirent_next(dip, bh, &dent) == 0);
849 845
850 /* Adjust the last dirent's record length 846 /* Adjust the last dirent's record length
851 (Remember that dent still points to the last entry.) */ 847 (Remember that dent still points to the last entry.) */
@@ -891,45 +887,39 @@ static int dir_make_exhash(struct gfs2_inode *dip)
891 * Returns: 0 on success, error code on failure 887 * Returns: 0 on success, error code on failure
892 */ 888 */
893 889
894static int dir_split_leaf(struct gfs2_inode *dip, uint32_t index, 890static int dir_split_leaf(struct inode *inode, const struct qstr *name)
895 uint64_t leaf_no)
896{ 891{
892 struct gfs2_inode *dip = inode->u.generic_ip;
897 struct buffer_head *nbh, *obh, *dibh; 893 struct buffer_head *nbh, *obh, *dibh;
898 struct gfs2_leaf *nleaf, *oleaf; 894 struct gfs2_leaf *nleaf, *oleaf;
899 struct gfs2_dirent *dent, *prev = NULL, *next = NULL, *new; 895 struct gfs2_dirent *dent, *prev = NULL, *next = NULL, *new;
900 uint32_t start, len, half_len, divider; 896 uint32_t start, len, half_len, divider;
901 uint64_t bn, *lp; 897 uint64_t bn, *lp, leaf_no;
902 uint32_t name_len; 898 uint32_t index;
903 int x, moved = 0; 899 int x, moved = 0;
904 int error; 900 int error;
905 901
906 /* Allocate the new leaf block */ 902 index = name->hash >> (32 - dip->i_di.di_depth);
907 903 error = get_leaf_nr(dip, index, &leaf_no);
908 bn = gfs2_alloc_meta(dip); 904 if (error)
909 905 return error;
910 /* Get the new leaf block */
911
912 nbh = gfs2_meta_new(dip->i_gl, bn);
913 gfs2_trans_add_bh(dip->i_gl, nbh, 1);
914 gfs2_metatype_set(nbh, GFS2_METATYPE_LF, GFS2_FORMAT_LF);
915 gfs2_buffer_clear_tail(nbh, sizeof(struct gfs2_meta_header));
916
917 nleaf = (struct gfs2_leaf *)nbh->b_data;
918
919 nleaf->lf_dirent_format = cpu_to_be32(GFS2_FORMAT_DE);
920 906
921 /* Get the old leaf block */ 907 /* Get the old leaf block */
922
923 error = get_leaf(dip, leaf_no, &obh); 908 error = get_leaf(dip, leaf_no, &obh);
924 if (error) 909 if (error)
925 goto fail; 910 goto fail;
926 911
927 gfs2_trans_add_bh(dip->i_gl, obh, 1); 912 gfs2_trans_add_bh(dip->i_gl, obh, 1);
928
929 oleaf = (struct gfs2_leaf *)obh->b_data; 913 oleaf = (struct gfs2_leaf *)obh->b_data;
930 914
931 /* Compute the start and len of leaf pointers in the hash table. */ 915 nleaf = new_leaf(inode, &nbh, be16_to_cpu(oleaf->lf_depth) + 1);
916 if (!nleaf) {
917 brelse(obh);
918 return -ENOSPC;
919 }
920 bn = nbh->b_blocknr;
932 921
922 /* Compute the start and len of leaf pointers in the hash table. */
933 len = 1 << (dip->i_di.di_depth - be16_to_cpu(oleaf->lf_depth)); 923 len = 1 << (dip->i_di.di_depth - be16_to_cpu(oleaf->lf_depth));
934 half_len = len >> 1; 924 half_len = len >> 1;
935 if (!half_len) { 925 if (!half_len) {
@@ -943,19 +933,8 @@ static int dir_split_leaf(struct gfs2_inode *dip, uint32_t index,
943 /* Change the pointers. 933 /* Change the pointers.
944 Don't bother distinguishing stuffed from non-stuffed. 934 Don't bother distinguishing stuffed from non-stuffed.
945 This code is complicated enough already. */ 935 This code is complicated enough already. */
946 936 lp = kmalloc(half_len * sizeof(uint64_t), GFP_NOFS | __GFP_NOFAIL);
947 lp = kcalloc(half_len, sizeof(uint64_t), GFP_KERNEL | __GFP_NOFAIL);
948
949 error = gfs2_dir_read_data(dip, (char *)lp, start * sizeof(uint64_t),
950 half_len * sizeof(uint64_t));
951 if (error != half_len * sizeof(uint64_t)) {
952 if (error >= 0)
953 error = -EIO;
954 goto fail_lpfree;
955 }
956
957 /* Change the pointers */ 937 /* Change the pointers */
958
959 for (x = 0; x < half_len; x++) 938 for (x = 0; x < half_len; x++)
960 lp[x] = cpu_to_be64(bn); 939 lp[x] = cpu_to_be64(bn);
961 940
@@ -970,11 +949,9 @@ static int dir_split_leaf(struct gfs2_inode *dip, uint32_t index,
970 kfree(lp); 949 kfree(lp);
971 950
972 /* Compute the divider */ 951 /* Compute the divider */
973
974 divider = (start + half_len) << (32 - dip->i_di.di_depth); 952 divider = (start + half_len) << (32 - dip->i_di.di_depth);
975 953
976 /* Copy the entries */ 954 /* Copy the entries */
977
978 dirent_first(dip, obh, &dent); 955 dirent_first(dip, obh, &dent);
979 956
980 do { 957 do {
@@ -984,48 +961,37 @@ static int dir_split_leaf(struct gfs2_inode *dip, uint32_t index,
984 961
985 if (dent->de_inum.no_addr && 962 if (dent->de_inum.no_addr &&
986 be32_to_cpu(dent->de_hash) < divider) { 963 be32_to_cpu(dent->de_hash) < divider) {
987 name_len = be16_to_cpu(dent->de_name_len); 964 struct qstr str;
988 965 str.name = (char*)(dent+1);
989 gfs2_dirent_alloc(dip, nbh, name_len, &new); 966 str.len = be16_to_cpu(dent->de_name_len);
967 str.hash = be32_to_cpu(dent->de_hash);
968 new = gfs2_dirent_alloc(dip->i_vnode, nbh, &str);
969 if (IS_ERR(new)) {
970 error = PTR_ERR(new);
971 break;
972 }
990 973
991 new->de_inum = dent->de_inum; /* No endian worries */ 974 new->de_inum = dent->de_inum; /* No endian worries */
992 new->de_hash = dent->de_hash; /* No endian worries */
993 new->de_type = dent->de_type; /* No endian worries */ 975 new->de_type = dent->de_type; /* No endian worries */
994 memcpy((char *)(new + 1), (char *)(dent + 1), 976 nleaf->lf_entries = cpu_to_be16(be16_to_cpu(nleaf->lf_entries)+1);
995 name_len);
996
997 nleaf->lf_entries = be16_to_cpu(nleaf->lf_entries)+1;
998 nleaf->lf_entries = cpu_to_be16(nleaf->lf_entries);
999 977
1000 dirent_del(dip, obh, prev, dent); 978 dirent_del(dip, obh, prev, dent);
1001 979
1002 if (!oleaf->lf_entries) 980 if (!oleaf->lf_entries)
1003 gfs2_consist_inode(dip); 981 gfs2_consist_inode(dip);
1004 oleaf->lf_entries = be16_to_cpu(oleaf->lf_entries)-1; 982 oleaf->lf_entries = cpu_to_be16(be16_to_cpu(oleaf->lf_entries)-1);
1005 oleaf->lf_entries = cpu_to_be16(oleaf->lf_entries);
1006 983
1007 if (!prev) 984 if (!prev)
1008 prev = dent; 985 prev = dent;
1009 986
1010 moved = 1; 987 moved = 1;
1011 } else 988 } else {
1012 prev = dent; 989 prev = dent;
1013 990 }
1014 dent = next; 991 dent = next;
1015 } 992 } while (dent);
1016 while (dent);
1017
1018 /* If none of the entries got moved into the new leaf,
1019 artificially fill in the first entry. */
1020 993
1021 if (!moved) { 994 oleaf->lf_depth = nleaf->lf_depth;
1022 gfs2_dirent_alloc(dip, nbh, 0, &new);
1023 new->de_inum.no_addr = 0;
1024 }
1025
1026 oleaf->lf_depth = be16_to_cpu(oleaf->lf_depth) + 1;
1027 oleaf->lf_depth = cpu_to_be16(oleaf->lf_depth);
1028 nleaf->lf_depth = oleaf->lf_depth;
1029 995
1030 error = gfs2_meta_inode_buffer(dip, &dibh); 996 error = gfs2_meta_inode_buffer(dip, &dibh);
1031 if (!gfs2_assert_withdraw(dip->i_sbd, !error)) { 997 if (!gfs2_assert_withdraw(dip->i_sbd, !error)) {
@@ -1142,12 +1108,10 @@ static int compare_dents(const void *a, const void *b)
1142 int ret = 0; 1108 int ret = 0;
1143 1109
1144 dent_a = *(struct gfs2_dirent **)a; 1110 dent_a = *(struct gfs2_dirent **)a;
1145 hash_a = dent_a->de_hash; 1111 hash_a = be32_to_cpu(dent_a->de_hash);
1146 hash_a = be32_to_cpu(hash_a);
1147 1112
1148 dent_b = *(struct gfs2_dirent **)b; 1113 dent_b = *(struct gfs2_dirent **)b;
1149 hash_b = dent_b->de_hash; 1114 hash_b = be32_to_cpu(dent_b->de_hash);
1150 hash_b = be32_to_cpu(hash_b);
1151 1115
1152 if (hash_a > hash_b) 1116 if (hash_a > hash_b)
1153 ret = 1; 1117 ret = 1;
@@ -1292,8 +1256,7 @@ static int do_filldir_single(struct gfs2_inode *dip, uint64_t *offset,
1292 goto out; 1256 goto out;
1293 } 1257 }
1294 darr[e++] = de; 1258 darr[e++] = de;
1295 } 1259 } while (dirent_next(dip, bh, &de) == 0);
1296 while (dirent_next(dip, bh, &de) == 0);
1297 1260
1298 if (e != entries) { 1261 if (e != entries) {
1299 gfs2_consist_inode(dip); 1262 gfs2_consist_inode(dip);
@@ -1341,11 +1304,9 @@ static int do_filldir_multi(struct gfs2_inode *dip, uint64_t *offset,
1341 1304
1342 leaf = (struct gfs2_leaf *)bh->b_data; 1305 leaf = (struct gfs2_leaf *)bh->b_data;
1343 entries = be16_to_cpu(leaf->lf_entries); 1306 entries = be16_to_cpu(leaf->lf_entries);
1344 ln = leaf->lf_next; 1307 ln = be64_to_cpu(leaf->lf_next);
1345 1308
1346 while (ln) { 1309 while (ln) {
1347 ln = be64_to_cpu(ln);
1348
1349 error = get_leaf(dip, ln, &tmp_bh); 1310 error = get_leaf(dip, ln, &tmp_bh);
1350 if (error) 1311 if (error)
1351 return error; 1312 return error;
@@ -1355,7 +1316,7 @@ static int do_filldir_multi(struct gfs2_inode *dip, uint64_t *offset,
1355 entries += be16_to_cpu(leaf->lf_entries); 1316 entries += be16_to_cpu(leaf->lf_entries);
1356 leaves++; 1317 leaves++;
1357 } 1318 }
1358 ln = leaf->lf_next; 1319 ln = be64_to_cpu(leaf->lf_next);
1359 1320
1360 brelse(tmp_bh); 1321 brelse(tmp_bh);
1361 } 1322 }
@@ -1387,14 +1348,11 @@ static int do_filldir_multi(struct gfs2_inode *dip, uint64_t *offset,
1387 goto out; 1348 goto out;
1388 } 1349 }
1389 darr[e++] = de; 1350 darr[e++] = de;
1390 } 1351 } while (dirent_next(dip, bh, &de) == 0);
1391 while (dirent_next(dip, bh, &de) == 0);
1392 } 1352 }
1393 ln = leaf->lf_next; 1353 ln = be64_to_cpu(leaf->lf_next);
1394 1354
1395 while (ln) { 1355 while (ln) {
1396 ln = be64_to_cpu(ln);
1397
1398 error = get_leaf(dip, ln, &tmp_bh); 1356 error = get_leaf(dip, ln, &tmp_bh);
1399 if (error) 1357 if (error)
1400 goto out; 1358 goto out;
@@ -1411,14 +1369,13 @@ static int do_filldir_multi(struct gfs2_inode *dip, uint64_t *offset,
1411 goto out; 1369 goto out;
1412 } 1370 }
1413 darr[e++] = de; 1371 darr[e++] = de;
1414 } 1372 } while (dirent_next(dip, tmp_bh, &de) == 0);
1415 while (dirent_next(dip, tmp_bh, &de) == 0);
1416 1373
1417 larr[l++] = tmp_bh; 1374 larr[l++] = tmp_bh;
1418 1375
1419 ln = leaf->lf_next; 1376 ln = be64_to_cpu(leaf->lf_next);
1420 } else { 1377 } else {
1421 ln = leaf->lf_next; 1378 ln = be64_to_cpu(leaf->lf_next);
1422 brelse(tmp_bh); 1379 brelse(tmp_bh);
1423 } 1380 }
1424 } 1381 }
@@ -1446,207 +1403,6 @@ static int do_filldir_multi(struct gfs2_inode *dip, uint64_t *offset,
1446} 1403}
1447 1404
1448/** 1405/**
1449 * dir_e_search - Search exhash (leaf) dir for inode matching name
1450 * @dip: The GFS2 inode
1451 * @filename: Filename string
1452 * @inode: If non-NULL, function fills with formal inode # and block address
1453 * @type: If non-NULL, function fills with DT_... dinode type
1454 *
1455 * Returns:
1456 */
1457
1458static int dir_e_search(struct gfs2_inode *dip, struct qstr *filename,
1459 struct gfs2_inum *inum, unsigned int *type)
1460{
1461 struct buffer_head *bh;
1462 struct gfs2_dirent *dent;
1463 int error;
1464
1465 error = linked_leaf_search(dip, filename, &dent, NULL, &bh);
1466 if (error)
1467 return error;
1468
1469 if (inum)
1470 gfs2_inum_in(inum, (char *)&dent->de_inum);
1471 if (type)
1472 *type = be16_to_cpu(dent->de_type);
1473
1474 brelse(bh);
1475
1476 return 0;
1477}
1478
1479static int dir_e_add(struct gfs2_inode *dip, struct qstr *filename,
1480 struct gfs2_inum *inum, unsigned int type)
1481{
1482 struct buffer_head *bh, *nbh, *dibh;
1483 struct gfs2_leaf *leaf, *nleaf;
1484 struct gfs2_dirent *dent;
1485 uint32_t hsize, index;
1486 uint32_t hash;
1487 uint64_t leaf_no, bn;
1488 int error;
1489
1490 restart:
1491 hsize = 1 << dip->i_di.di_depth;
1492 if (hsize * sizeof(uint64_t) != dip->i_di.di_size) {
1493 gfs2_consist_inode(dip);
1494 return -EIO;
1495 }
1496
1497 /* Figure out the address of the leaf node. */
1498
1499 hash = gfs2_disk_hash(filename->name, filename->len);
1500 index = hash >> (32 - dip->i_di.di_depth);
1501
1502 error = get_leaf_nr(dip, index, &leaf_no);
1503 if (error)
1504 return error;
1505
1506 /* Add entry to the leaf */
1507
1508 for (;;) {
1509 error = get_leaf(dip, leaf_no, &bh);
1510 if (error)
1511 return error;
1512
1513 leaf = (struct gfs2_leaf *)bh->b_data;
1514
1515 if (gfs2_dirent_alloc(dip, bh, filename->len, &dent)) {
1516
1517 if (be16_to_cpu(leaf->lf_depth) < dip->i_di.di_depth) {
1518 /* Can we split the leaf? */
1519
1520 brelse(bh);
1521
1522 error = dir_split_leaf(dip, index, leaf_no);
1523 if (error)
1524 return error;
1525
1526 goto restart;
1527
1528 } else if (dip->i_di.di_depth < GFS2_DIR_MAX_DEPTH) {
1529 /* Can we double the hash table? */
1530
1531 brelse(bh);
1532
1533 error = dir_double_exhash(dip);
1534 if (error)
1535 return error;
1536
1537 goto restart;
1538
1539 } else if (leaf->lf_next) {
1540 /* Can we try the next leaf in the list? */
1541 leaf_no = be64_to_cpu(leaf->lf_next);
1542 brelse(bh);
1543 continue;
1544
1545 } else {
1546 /* Create a new leaf and add it to the list. */
1547
1548 bn = gfs2_alloc_meta(dip);
1549
1550 nbh = gfs2_meta_new(dip->i_gl, bn);
1551 gfs2_trans_add_bh(dip->i_gl, nbh, 1);
1552 gfs2_metatype_set(nbh,
1553 GFS2_METATYPE_LF,
1554 GFS2_FORMAT_LF);
1555 gfs2_buffer_clear_tail(nbh,
1556 sizeof(struct gfs2_meta_header));
1557
1558 gfs2_trans_add_bh(dip->i_gl, bh, 1);
1559 leaf->lf_next = cpu_to_be64(bn);
1560
1561 nleaf = (struct gfs2_leaf *)nbh->b_data;
1562 nleaf->lf_depth = leaf->lf_depth;
1563 nleaf->lf_dirent_format = cpu_to_be32(GFS2_FORMAT_DE);
1564
1565 gfs2_dirent_alloc(dip, nbh, filename->len,
1566 &dent);
1567
1568 dip->i_di.di_blocks++;
1569
1570 brelse(bh);
1571
1572 bh = nbh;
1573 leaf = nleaf;
1574 }
1575 }
1576
1577 /* If the gfs2_dirent_alloc() succeeded, it pinned the "bh" */
1578
1579 gfs2_inum_out(inum, (char *)&dent->de_inum);
1580 dent->de_hash = cpu_to_be32(hash);
1581 dent->de_type = cpu_to_be16(type);
1582 memcpy((char *)(dent + 1), filename->name, filename->len);
1583
1584 leaf->lf_entries = be16_to_cpu(leaf->lf_entries) + 1;
1585 leaf->lf_entries = cpu_to_be16(leaf->lf_entries);
1586
1587 brelse(bh);
1588
1589 error = gfs2_meta_inode_buffer(dip, &dibh);
1590 if (error)
1591 return error;
1592
1593 dip->i_di.di_entries++;
1594 dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds();
1595
1596 gfs2_trans_add_bh(dip->i_gl, dibh, 1);
1597 gfs2_dinode_out(&dip->i_di, dibh->b_data);
1598 brelse(dibh);
1599
1600 return 0;
1601 }
1602
1603 return -ENOENT;
1604}
1605
1606static int dir_e_del(struct gfs2_inode *dip, struct qstr *filename)
1607{
1608 struct buffer_head *bh, *dibh;
1609 struct gfs2_dirent *dent, *prev;
1610 struct gfs2_leaf *leaf;
1611 unsigned int entries;
1612 int error;
1613
1614 error = linked_leaf_search(dip, filename, &dent, &prev, &bh);
1615 if (error == -ENOENT) {
1616 gfs2_consist_inode(dip);
1617 return -EIO;
1618 }
1619 if (error)
1620 return error;
1621
1622 dirent_del(dip, bh, prev, dent); /* Pins bh */
1623
1624 leaf = (struct gfs2_leaf *)bh->b_data;
1625 entries = be16_to_cpu(leaf->lf_entries);
1626 if (!entries)
1627 gfs2_consist_inode(dip);
1628 entries--;
1629 leaf->lf_entries = cpu_to_be16(entries);
1630
1631 brelse(bh);
1632
1633 error = gfs2_meta_inode_buffer(dip, &dibh);
1634 if (error)
1635 return error;
1636
1637 if (!dip->i_di.di_entries)
1638 gfs2_consist_inode(dip);
1639 dip->i_di.di_entries--;
1640 dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds();
1641
1642 gfs2_trans_add_bh(dip->i_gl, dibh, 1);
1643 gfs2_dinode_out(&dip->i_di, dibh->b_data);
1644 brelse(dibh);
1645
1646 return 0;
1647}
1648
1649/**
1650 * dir_e_read - Reads the entries from a directory into a filldir buffer 1406 * dir_e_read - Reads the entries from a directory into a filldir buffer
1651 * @dip: dinode pointer 1407 * @dip: dinode pointer
1652 * @offset: the hash of the last entry read shifted to the right once 1408 * @offset: the hash of the last entry read shifted to the right once
@@ -1661,7 +1417,7 @@ static int dir_e_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque,
1661{ 1417{
1662 struct gfs2_sbd *sdp = dip->i_sbd; 1418 struct gfs2_sbd *sdp = dip->i_sbd;
1663 struct buffer_head *bh; 1419 struct buffer_head *bh;
1664 struct gfs2_leaf leaf; 1420 struct gfs2_leaf *leaf;
1665 uint32_t hsize, len; 1421 uint32_t hsize, len;
1666 uint32_t ht_offset, lp_offset, ht_offset_cur = -1; 1422 uint32_t ht_offset, lp_offset, ht_offset_cur = -1;
1667 uint32_t hash, index; 1423 uint32_t hash, index;
@@ -1702,14 +1458,15 @@ static int dir_e_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque,
1702 if (error) 1458 if (error)
1703 goto out; 1459 goto out;
1704 1460
1705 gfs2_leaf_in(&leaf, bh->b_data); 1461 leaf = (struct gfs2_leaf *)bh->b_data;
1706 1462 if (leaf->lf_next)
1707 if (leaf.lf_next)
1708 error = do_filldir_multi(dip, offset, opaque, filldir, 1463 error = do_filldir_multi(dip, offset, opaque, filldir,
1709 bh, &copied); 1464 bh, &copied);
1710 else 1465 else
1711 error = do_filldir_single(dip, offset, opaque, filldir, 1466 error = do_filldir_single(dip, offset, opaque, filldir,
1712 bh, leaf.lf_entries, &copied); 1467 bh,
1468 be16_to_cpu(leaf->lf_entries),
1469 &copied);
1713 1470
1714 brelse(bh); 1471 brelse(bh);
1715 1472
@@ -1719,7 +1476,7 @@ static int dir_e_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque,
1719 goto out; 1476 goto out;
1720 } 1477 }
1721 1478
1722 len = 1 << (dip->i_di.di_depth - leaf.lf_depth); 1479 len = 1 << (dip->i_di.di_depth - be16_to_cpu(leaf->lf_depth));
1723 index = (index & ~(len - 1)) + len; 1480 index = (index & ~(len - 1)) + len;
1724 } 1481 }
1725 1482
@@ -1729,165 +1486,6 @@ static int dir_e_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque,
1729 return error; 1486 return error;
1730} 1487}
1731 1488
1732static int dir_e_mvino(struct gfs2_inode *dip, struct qstr *filename,
1733 struct gfs2_inum *inum, unsigned int new_type)
1734{
1735 struct buffer_head *bh, *dibh;
1736 struct gfs2_dirent *dent;
1737 int error;
1738
1739 error = linked_leaf_search(dip, filename, &dent, NULL, &bh);
1740 if (error == -ENOENT) {
1741 gfs2_consist_inode(dip);
1742 return -EIO;
1743 }
1744 if (error)
1745 return error;
1746
1747 gfs2_trans_add_bh(dip->i_gl, bh, 1);
1748
1749 gfs2_inum_out(inum, (char *)&dent->de_inum);
1750 dent->de_type = cpu_to_be16(new_type);
1751
1752 brelse(bh);
1753
1754 error = gfs2_meta_inode_buffer(dip, &dibh);
1755 if (error)
1756 return error;
1757
1758 dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds();
1759
1760 gfs2_trans_add_bh(dip->i_gl, dibh, 1);
1761 gfs2_dinode_out(&dip->i_di, dibh->b_data);
1762 brelse(dibh);
1763
1764 return 0;
1765}
1766
1767/**
1768 * dir_l_search - Search linear (stuffed dinode) dir for inode matching name
1769 * @dip: The GFS2 inode
1770 * @filename: Filename string
1771 * @inode: If non-NULL, function fills with formal inode # and block address
1772 * @type: If non-NULL, function fills with DT_... dinode type
1773 *
1774 * Returns:
1775 */
1776
1777static int dir_l_search(struct gfs2_inode *dip, struct qstr *filename,
1778 struct gfs2_inum *inum, unsigned int *type)
1779{
1780 struct buffer_head *dibh;
1781 struct gfs2_dirent *dent;
1782 int error;
1783
1784 if (!gfs2_is_stuffed(dip)) {
1785 gfs2_consist_inode(dip);
1786 return -EIO;
1787 }
1788
1789 error = gfs2_meta_inode_buffer(dip, &dibh);
1790 if (error)
1791 return error;
1792
1793 error = leaf_search(dip, dibh, filename, &dent, NULL);
1794 if (!error) {
1795 if (inum)
1796 gfs2_inum_in(inum, (char *)&dent->de_inum);
1797 if (type)
1798 *type = be16_to_cpu(dent->de_type);
1799 }
1800
1801 brelse(dibh);
1802
1803 return error;
1804}
1805
1806static int dir_l_add(struct gfs2_inode *dip, struct qstr *filename,
1807 struct gfs2_inum *inum, unsigned int type)
1808{
1809 struct buffer_head *dibh;
1810 struct gfs2_dirent *dent;
1811 int error;
1812
1813 if (!gfs2_is_stuffed(dip)) {
1814 gfs2_consist_inode(dip);
1815 return -EIO;
1816 }
1817
1818 error = gfs2_meta_inode_buffer(dip, &dibh);
1819 if (error)
1820 return error;
1821
1822 if (gfs2_dirent_alloc(dip, dibh, filename->len, &dent)) {
1823 brelse(dibh);
1824
1825 error = dir_make_exhash(dip);
1826 if (!error)
1827 error = dir_e_add(dip, filename, inum, type);
1828
1829 return error;
1830 }
1831
1832 /* gfs2_dirent_alloc() pins */
1833
1834 gfs2_inum_out(inum, (char *)&dent->de_inum);
1835 dent->de_hash = gfs2_disk_hash(filename->name, filename->len);
1836 dent->de_hash = cpu_to_be32(dent->de_hash);
1837 dent->de_type = cpu_to_be16(type);
1838 memcpy((char *)(dent + 1), filename->name, filename->len);
1839
1840 dip->i_di.di_entries++;
1841 dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds();
1842
1843 gfs2_dinode_out(&dip->i_di, dibh->b_data);
1844 brelse(dibh);
1845
1846 return 0;
1847}
1848
1849static int dir_l_del(struct gfs2_inode *dip, struct qstr *filename)
1850{
1851 struct buffer_head *dibh;
1852 struct gfs2_dirent *dent, *prev;
1853 int error;
1854
1855 if (!gfs2_is_stuffed(dip)) {
1856 gfs2_consist_inode(dip);
1857 return -EIO;
1858 }
1859
1860 error = gfs2_meta_inode_buffer(dip, &dibh);
1861 if (error)
1862 return error;
1863
1864 error = leaf_search(dip, dibh, filename, &dent, &prev);
1865 if (error == -ENOENT) {
1866 gfs2_consist_inode(dip);
1867 error = -EIO;
1868 goto out;
1869 }
1870 if (error)
1871 goto out;
1872
1873 dirent_del(dip, dibh, prev, dent);
1874
1875 /* dirent_del() pins */
1876
1877 if (!dip->i_di.di_entries)
1878 gfs2_consist_inode(dip);
1879 dip->i_di.di_entries--;
1880
1881 dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds();
1882
1883 gfs2_dinode_out(&dip->i_di, dibh->b_data);
1884
1885 out:
1886 brelse(dibh);
1887
1888 return error;
1889}
1890
1891static int dir_l_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque, 1489static int dir_l_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque,
1892 gfs2_filldir_t filldir) 1490 gfs2_filldir_t filldir)
1893{ 1491{
@@ -1919,46 +1517,6 @@ static int dir_l_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque,
1919 return error; 1517 return error;
1920} 1518}
1921 1519
1922static int dir_l_mvino(struct gfs2_inode *dip, struct qstr *filename,
1923 struct gfs2_inum *inum, unsigned int new_type)
1924{
1925 struct buffer_head *dibh;
1926 struct gfs2_dirent *dent;
1927 int error;
1928
1929 if (!gfs2_is_stuffed(dip)) {
1930 gfs2_consist_inode(dip);
1931 return -EIO;
1932 }
1933
1934 error = gfs2_meta_inode_buffer(dip, &dibh);
1935 if (error)
1936 return error;
1937
1938 error = leaf_search(dip, dibh, filename, &dent, NULL);
1939 if (error == -ENOENT) {
1940 gfs2_consist_inode(dip);
1941 error = -EIO;
1942 goto out;
1943 }
1944 if (error)
1945 goto out;
1946
1947 gfs2_trans_add_bh(dip->i_gl, dibh, 1);
1948
1949 gfs2_inum_out(inum, (char *)&dent->de_inum);
1950 dent->de_type = cpu_to_be16(new_type);
1951
1952 dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds();
1953
1954 gfs2_dinode_out(&dip->i_di, dibh->b_data);
1955
1956 out:
1957 brelse(dibh);
1958
1959 return error;
1960}
1961
1962/** 1520/**
1963 * gfs2_dir_search - Search a directory 1521 * gfs2_dir_search - Search a directory
1964 * @dip: The GFS2 inode 1522 * @dip: The GFS2 inode
@@ -1971,17 +1529,69 @@ static int dir_l_mvino(struct gfs2_inode *dip, struct qstr *filename,
1971 * Returns: errno 1529 * Returns: errno
1972 */ 1530 */
1973 1531
1974int gfs2_dir_search(struct gfs2_inode *dip, struct qstr *filename, 1532int gfs2_dir_search(struct inode *dir, const struct qstr *name,
1975 struct gfs2_inum *inum, unsigned int *type) 1533 struct gfs2_inum *inum, unsigned int *type)
1976{ 1534{
1535 struct buffer_head *bh;
1536 struct gfs2_dirent *dent;
1537
1538 dent = gfs2_dirent_search(dir, name, gfs2_dirent_find, &bh);
1539 if (dent) {
1540 if (IS_ERR(dent))
1541 return PTR_ERR(dent);
1542 if (inum)
1543 gfs2_inum_in(inum, (char *)&dent->de_inum);
1544 if (type)
1545 *type = be16_to_cpu(dent->de_type);
1546 brelse(bh);
1547 return 0;
1548 }
1549 return -ENOENT;
1550}
1551
1552static int dir_new_leaf(struct inode *inode, const struct qstr *name)
1553{
1554 struct buffer_head *bh, *obh;
1555 struct gfs2_inode *ip = inode->u.generic_ip;
1556 struct gfs2_leaf *leaf, *oleaf;
1977 int error; 1557 int error;
1558 u32 index;
1559 u64 bn;
1978 1560
1979 if (dip->i_di.di_flags & GFS2_DIF_EXHASH) 1561 index = name->hash >> (32 - ip->i_di.di_depth);
1980 error = dir_e_search(dip, filename, inum, type); 1562 error = get_first_leaf(ip, index, &obh);
1981 else 1563 if (error)
1982 error = dir_l_search(dip, filename, inum, type); 1564 return error;
1565 do {
1566 oleaf = (struct gfs2_leaf *)obh->b_data;
1567 bn = be64_to_cpu(oleaf->lf_next);
1568 if (!bn)
1569 break;
1570 brelse(obh);
1571 error = get_leaf(ip, bn, &obh);
1572 if (error)
1573 return error;
1574 } while(1);
1983 1575
1984 return error; 1576 gfs2_trans_add_bh(ip->i_gl, obh, 1);
1577
1578 leaf = new_leaf(inode, &bh, be16_to_cpu(oleaf->lf_depth));
1579 if (!leaf) {
1580 brelse(obh);
1581 return -ENOSPC;
1582 }
1583 oleaf->lf_next = cpu_to_be64(bn);
1584 brelse(bh);
1585 brelse(obh);
1586
1587 error = gfs2_meta_inode_buffer(ip, &bh);
1588 if (error)
1589 return error;
1590 gfs2_trans_add_bh(ip->i_gl, bh, 1);
1591 ip->i_di.di_blocks++;
1592 gfs2_dinode_out(&ip->i_di, bh->b_data);
1593 brelse(bh);
1594 return 0;
1985} 1595}
1986 1596
1987/** 1597/**
@@ -1994,19 +1604,70 @@ int gfs2_dir_search(struct gfs2_inode *dip, struct qstr *filename,
1994 * Returns: 0 on success, error code on failure 1604 * Returns: 0 on success, error code on failure
1995 */ 1605 */
1996 1606
1997int gfs2_dir_add(struct gfs2_inode *dip, struct qstr *filename, 1607int gfs2_dir_add(struct inode *inode, const struct qstr *name,
1998 struct gfs2_inum *inum, unsigned int type) 1608 const struct gfs2_inum *inum, unsigned type)
1999{ 1609{
1610 struct gfs2_inode *ip = inode->u.generic_ip;
1611 struct buffer_head *bh;
1612 struct gfs2_dirent *dent;
1613 struct gfs2_leaf *leaf;
2000 int error; 1614 int error;
2001 1615
2002 if (dip->i_di.di_flags & GFS2_DIF_EXHASH) 1616 while(1) {
2003 error = dir_e_add(dip, filename, inum, type); 1617 dent = gfs2_dirent_search(inode, name, gfs2_dirent_find_space,
2004 else 1618 &bh);
2005 error = dir_l_add(dip, filename, inum, type); 1619 if (dent) {
2006 1620 if (IS_ERR(dent))
1621 return PTR_ERR(dent);
1622 dent = gfs2_init_dirent(inode, dent, name, bh);
1623 gfs2_inum_out(inum, (char *)&dent->de_inum);
1624 dent->de_type = cpu_to_be16(type);
1625 if (ip->i_di.di_flags & GFS2_DIF_EXHASH) {
1626 leaf = (struct gfs2_leaf *)bh->b_data;
1627 leaf->lf_entries = cpu_to_be16(be16_to_cpu(leaf->lf_entries) + 1);
1628 }
1629 brelse(bh);
1630 error = gfs2_meta_inode_buffer(ip, &bh);
1631 if (error)
1632 break;
1633 gfs2_trans_add_bh(ip->i_gl, bh, 1);
1634 ip->i_di.di_entries++;
1635 ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds();
1636 gfs2_dinode_out(&ip->i_di, bh->b_data);
1637 brelse(bh);
1638 error = 0;
1639 break;
1640 }
1641 if (!(ip->i_di.di_flags & GFS2_DIF_EXHASH)) {
1642 error = dir_make_exhash(inode);
1643 if (error)
1644 break;
1645 continue;
1646 }
1647 error = dir_split_leaf(inode, name);
1648 if (error == 0)
1649 continue;
1650 if (error != -ENOSPC)
1651 break;
1652 if (ip->i_di.di_depth < GFS2_DIR_MAX_DEPTH) {
1653 error = dir_double_exhash(ip);
1654 if (error)
1655 break;
1656 error = dir_split_leaf(inode, name);
1657 if (error)
1658 break;
1659 continue;
1660 }
1661 error = dir_new_leaf(inode, name);
1662 if (!error)
1663 continue;
1664 error = -ENOSPC;
1665 break;
1666 }
2007 return error; 1667 return error;
2008} 1668}
2009 1669
1670
2010/** 1671/**
2011 * gfs2_dir_del - Delete a directory entry 1672 * gfs2_dir_del - Delete a directory entry
2012 * @dip: The GFS2 inode 1673 * @dip: The GFS2 inode
@@ -2015,14 +1676,50 @@ int gfs2_dir_add(struct gfs2_inode *dip, struct qstr *filename,
2015 * Returns: 0 on success, error code on failure 1676 * Returns: 0 on success, error code on failure
2016 */ 1677 */
2017 1678
2018int gfs2_dir_del(struct gfs2_inode *dip, struct qstr *filename) 1679int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *name)
2019{ 1680{
1681 struct gfs2_dirent *dent, *prev = NULL;
1682 struct buffer_head *bh;
2020 int error; 1683 int error;
2021 1684
2022 if (dip->i_di.di_flags & GFS2_DIF_EXHASH) 1685 /* Returns _either_ the entry (if its first in block) or the
2023 error = dir_e_del(dip, filename); 1686 previous entry otherwise */
2024 else 1687 dent = gfs2_dirent_search(dip->i_vnode, name, gfs2_dirent_prev, &bh);
2025 error = dir_l_del(dip, filename); 1688 if (!dent) {
1689 gfs2_consist_inode(dip);
1690 return -EIO;
1691 }
1692 if (IS_ERR(dent)) {
1693 gfs2_consist_inode(dip);
1694 return PTR_ERR(dent);
1695 }
1696 /* If not first in block, adjust pointers accordingly */
1697 if (gfs2_dirent_find(dent, name) == 0) {
1698 prev = dent;
1699 dent = (struct gfs2_dirent *)((char *)dent + be16_to_cpu(prev->de_rec_len));
1700 }
1701
1702 dirent_del(dip, bh, prev, dent);
1703 if (dip->i_di.di_flags & GFS2_DIF_EXHASH) {
1704 struct gfs2_leaf *leaf = (struct gfs2_leaf *)bh->b_data;
1705 u16 entries = be16_to_cpu(leaf->lf_entries);
1706 if (!entries)
1707 gfs2_consist_inode(dip);
1708 leaf->lf_entries = cpu_to_be16(--entries);
1709 brelse(bh);
1710 }
1711
1712 error = gfs2_meta_inode_buffer(dip, &bh);
1713 if (error)
1714 return error;
1715
1716 if (!dip->i_di.di_entries)
1717 gfs2_consist_inode(dip);
1718 gfs2_trans_add_bh(dip->i_gl, bh, 1);
1719 dip->i_di.di_entries--;
1720 dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds();
1721 gfs2_dinode_out(&dip->i_di, bh->b_data);
1722 brelse(bh);
2026 1723
2027 return error; 1724 return error;
2028} 1725}
@@ -2053,17 +1750,37 @@ int gfs2_dir_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque,
2053 * Returns: errno 1750 * Returns: errno
2054 */ 1751 */
2055 1752
2056int gfs2_dir_mvino(struct gfs2_inode *dip, struct qstr *filename, 1753int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename,
2057 struct gfs2_inum *inum, unsigned int new_type) 1754 struct gfs2_inum *inum, unsigned int new_type)
2058{ 1755{
1756 struct buffer_head *bh;
1757 struct gfs2_dirent *dent;
2059 int error; 1758 int error;
2060 1759
2061 if (dip->i_di.di_flags & GFS2_DIF_EXHASH) 1760 dent = gfs2_dirent_search(dip->i_vnode, filename, gfs2_dirent_find, &bh);
2062 error = dir_e_mvino(dip, filename, inum, new_type); 1761 if (!dent) {
2063 else 1762 gfs2_consist_inode(dip);
2064 error = dir_l_mvino(dip, filename, inum, new_type); 1763 return -EIO;
1764 }
1765 if (IS_ERR(dent))
1766 return PTR_ERR(dent);
2065 1767
2066 return error; 1768 gfs2_trans_add_bh(dip->i_gl, bh, 1);
1769 gfs2_inum_out(inum, (char *)&dent->de_inum);
1770 dent->de_type = cpu_to_be16(new_type);
1771
1772 if (dip->i_di.di_flags & GFS2_DIF_EXHASH) {
1773 brelse(bh);
1774 error = gfs2_meta_inode_buffer(dip, &bh);
1775 if (error)
1776 return error;
1777 gfs2_trans_add_bh(dip->i_gl, bh, 1);
1778 }
1779
1780 dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds();
1781 gfs2_dinode_out(&dip->i_di, bh->b_data);
1782 brelse(bh);
1783 return 0;
2067} 1784}
2068 1785
2069/** 1786/**
@@ -2079,7 +1796,7 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data)
2079{ 1796{
2080 struct gfs2_sbd *sdp = dip->i_sbd; 1797 struct gfs2_sbd *sdp = dip->i_sbd;
2081 struct buffer_head *bh; 1798 struct buffer_head *bh;
2082 struct gfs2_leaf leaf; 1799 struct gfs2_leaf *leaf;
2083 uint32_t hsize, len; 1800 uint32_t hsize, len;
2084 uint32_t ht_offset, lp_offset, ht_offset_cur = -1; 1801 uint32_t ht_offset, lp_offset, ht_offset_cur = -1;
2085 uint32_t index = 0; 1802 uint32_t index = 0;
@@ -2118,10 +1835,10 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data)
2118 error = get_leaf(dip, leaf_no, &bh); 1835 error = get_leaf(dip, leaf_no, &bh);
2119 if (error) 1836 if (error)
2120 goto out; 1837 goto out;
2121 gfs2_leaf_in(&leaf, bh->b_data); 1838 leaf = (struct gfs2_leaf *)bh->b_data;
2122 brelse(bh); 1839 brelse(bh);
2123 1840
2124 len = 1 << (dip->i_di.di_depth - leaf.lf_depth); 1841 len = 1 << (dip->i_di.di_depth - be16_to_cpu(leaf->lf_depth));
2125 1842
2126 error = lc(dip, index, len, leaf_no, data); 1843 error = lc(dip, index, len, leaf_no, data);
2127 if (error) 1844 if (error)
@@ -2158,10 +1875,10 @@ static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len,
2158 uint64_t leaf_no, void *data) 1875 uint64_t leaf_no, void *data)
2159{ 1876{
2160 struct gfs2_sbd *sdp = dip->i_sbd; 1877 struct gfs2_sbd *sdp = dip->i_sbd;
2161 struct gfs2_leaf tmp_leaf; 1878 struct gfs2_leaf *tmp_leaf;
2162 struct gfs2_rgrp_list rlist; 1879 struct gfs2_rgrp_list rlist;
2163 struct buffer_head *bh, *dibh; 1880 struct buffer_head *bh, *dibh;
2164 uint64_t blk; 1881 uint64_t blk, nblk;
2165 unsigned int rg_blocks = 0, l_blocks = 0; 1882 unsigned int rg_blocks = 0, l_blocks = 0;
2166 char *ht; 1883 char *ht;
2167 unsigned int x, size = len * sizeof(uint64_t); 1884 unsigned int x, size = len * sizeof(uint64_t);
@@ -2185,11 +1902,12 @@ static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len,
2185 1902
2186 /* Count the number of leaves */ 1903 /* Count the number of leaves */
2187 1904
2188 for (blk = leaf_no; blk; blk = tmp_leaf.lf_next) { 1905 for (blk = leaf_no; blk; blk = nblk) {
2189 error = get_leaf(dip, blk, &bh); 1906 error = get_leaf(dip, blk, &bh);
2190 if (error) 1907 if (error)
2191 goto out_rlist; 1908 goto out_rlist;
2192 gfs2_leaf_in(&tmp_leaf, (bh)->b_data); 1909 tmp_leaf = (struct gfs2_leaf *)bh->b_data;
1910 nblk = be64_to_cpu(tmp_leaf->lf_next);
2193 brelse(bh); 1911 brelse(bh);
2194 1912
2195 gfs2_rlist_add(sdp, &rlist, blk); 1913 gfs2_rlist_add(sdp, &rlist, blk);
@@ -2214,11 +1932,12 @@ static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len,
2214 if (error) 1932 if (error)
2215 goto out_rg_gunlock; 1933 goto out_rg_gunlock;
2216 1934
2217 for (blk = leaf_no; blk; blk = tmp_leaf.lf_next) { 1935 for (blk = leaf_no; blk; blk = nblk) {
2218 error = get_leaf(dip, blk, &bh); 1936 error = get_leaf(dip, blk, &bh);
2219 if (error) 1937 if (error)
2220 goto out_end_trans; 1938 goto out_end_trans;
2221 gfs2_leaf_in(&tmp_leaf, bh->b_data); 1939 tmp_leaf = (struct gfs2_leaf *)bh->b_data;
1940 nblk = be64_to_cpu(tmp_leaf->lf_next);
2222 brelse(bh); 1941 brelse(bh);
2223 1942
2224 gfs2_free_meta(dip, blk, 1); 1943 gfs2_free_meta(dip, blk, 1);
@@ -2308,63 +2027,22 @@ int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip)
2308 * gfs2_diradd_alloc_required - find if adding entry will require an allocation 2027 * gfs2_diradd_alloc_required - find if adding entry will require an allocation
2309 * @ip: the file being written to 2028 * @ip: the file being written to
2310 * @filname: the filename that's going to be added 2029 * @filname: the filename that's going to be added
2311 * @alloc_required: set to 1 if an alloc is required, 0 otherwise
2312 * 2030 *
2313 * Returns: errno 2031 * Returns: 1 if alloc required, 0 if not, -ve on error
2314 */ 2032 */
2315 2033
2316int gfs2_diradd_alloc_required(struct gfs2_inode *dip, struct qstr *filename, 2034int gfs2_diradd_alloc_required(struct inode *inode,
2317 int *alloc_required) 2035 const struct qstr *name)
2318{ 2036{
2319 struct buffer_head *bh = NULL, *bh_next; 2037 struct gfs2_dirent *dent;
2320 uint32_t hsize, hash, index; 2038 struct buffer_head *bh;
2321 int error = 0;
2322
2323 *alloc_required = 0;
2324
2325 if (dip->i_di.di_flags & GFS2_DIF_EXHASH) {
2326 hsize = 1 << dip->i_di.di_depth;
2327 if (hsize * sizeof(uint64_t) != dip->i_di.di_size) {
2328 gfs2_consist_inode(dip);
2329 return -EIO;
2330 }
2331
2332 hash = gfs2_disk_hash(filename->name, filename->len);
2333 index = hash >> (32 - dip->i_di.di_depth);
2334
2335 error = get_first_leaf(dip, index, &bh_next);
2336 if (error)
2337 return error;
2338
2339 do {
2340 brelse(bh);
2341
2342 bh = bh_next;
2343
2344 if (dirent_fits(dip, bh, filename->len))
2345 break;
2346
2347 error = get_next_leaf(dip, bh, &bh_next);
2348 if (error == -ENOENT) {
2349 *alloc_required = 1;
2350 error = 0;
2351 break;
2352 }
2353 }
2354 while (!error);
2355
2356 brelse(bh);
2357 } else {
2358 error = gfs2_meta_inode_buffer(dip, &bh);
2359 if (error)
2360 return error;
2361
2362 if (!dirent_fits(dip, bh, filename->len))
2363 *alloc_required = 1;
2364
2365 brelse(bh);
2366 }
2367 2039
2368 return error; 2040 dent = gfs2_dirent_search(inode, name, gfs2_dirent_find_space, &bh);
2041 if (!dent)
2042 return 1;
2043 if (IS_ERR(dent))
2044 return PTR_ERR(dent);
2045 brelse(bh);
2046 return 0;
2369} 2047}
2370 2048