diff options
author | Dave Chinner <dchinner@redhat.com> | 2013-10-29 07:11:52 -0400 |
---|---|---|
committer | Ben Myers <bpm@sgi.com> | 2013-10-30 14:47:22 -0400 |
commit | 01ba43b873d9e91ba2e0341fe8cb7e89eaa41661 (patch) | |
tree | 34b0f2ae40956eaf3a2dc1a693f29ff4200eb845 /fs/xfs/xfs_da_format.c | |
parent | 4bceb18f1551c8c047eeb54d48cda9f5453dc12f (diff) |
xfs: vectorise encoding/decoding directory headers
Conversion from on-disk structures to in-core header structures
currently relies on magic number checks. If the magic number is
wrong, but one of the supported values, we do the wrong thing with
the encode/decode operation. Split these functions so that there are
discrete operations for the specific directory format we are
handling.
In doing this, move all the header encode/decode functions to
xfs_da_format.c as they are directly manipulating the on-disk
format. It should be noted that all the growth in binary size is
from xfs_da_format.c - the rest of the code actaully shrinks.
text data bss dec hex filename
794490 96802 1096 892388 d9de4 fs/xfs/xfs.o.orig
792986 96802 1096 890884 d9804 fs/xfs/xfs.o.p1
792350 96802 1096 890248 d9588 fs/xfs/xfs.o.p2
789293 96802 1096 887191 d8997 fs/xfs/xfs.o.p3
789005 96802 1096 886903 d8997 fs/xfs/xfs.o.p4
789061 96802 1096 886959 d88af fs/xfs/xfs.o.p5
789733 96802 1096 887631 d8b4f fs/xfs/xfs.o.p6
791421 96802 1096 889319 d91e7 fs/xfs/xfs.o.p7
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Ben Myers <bpm@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
Diffstat (limited to 'fs/xfs/xfs_da_format.c')
-rw-r--r-- | fs/xfs/xfs_da_format.c | 209 |
1 files changed, 207 insertions, 2 deletions
diff --git a/fs/xfs/xfs_da_format.c b/fs/xfs/xfs_da_format.c index 72b48b5ec69a..b232c275791d 100644 --- a/fs/xfs/xfs_da_format.c +++ b/fs/xfs/xfs_da_format.c | |||
@@ -464,19 +464,84 @@ xfs_dir3_leaf_hdr_size(void) | |||
464 | return sizeof(struct xfs_dir3_leaf_hdr); | 464 | return sizeof(struct xfs_dir3_leaf_hdr); |
465 | } | 465 | } |
466 | 466 | ||
467 | static inline int | 467 | static int |
468 | xfs_dir3_max_leaf_ents(struct xfs_mount *mp) | 468 | xfs_dir3_max_leaf_ents(struct xfs_mount *mp) |
469 | { | 469 | { |
470 | return (mp->m_dirblksize - xfs_dir3_leaf_hdr_size()) / | 470 | return (mp->m_dirblksize - xfs_dir3_leaf_hdr_size()) / |
471 | (uint)sizeof(struct xfs_dir2_leaf_entry); | 471 | (uint)sizeof(struct xfs_dir2_leaf_entry); |
472 | } | 472 | } |
473 | 473 | ||
474 | static inline struct xfs_dir2_leaf_entry * | 474 | static struct xfs_dir2_leaf_entry * |
475 | xfs_dir3_leaf_ents_p(struct xfs_dir2_leaf *lp) | 475 | xfs_dir3_leaf_ents_p(struct xfs_dir2_leaf *lp) |
476 | { | 476 | { |
477 | return ((struct xfs_dir3_leaf *)lp)->__ents; | 477 | return ((struct xfs_dir3_leaf *)lp)->__ents; |
478 | } | 478 | } |
479 | 479 | ||
480 | static void | ||
481 | xfs_dir2_leaf_hdr_from_disk( | ||
482 | struct xfs_dir3_icleaf_hdr *to, | ||
483 | struct xfs_dir2_leaf *from) | ||
484 | { | ||
485 | to->forw = be32_to_cpu(from->hdr.info.forw); | ||
486 | to->back = be32_to_cpu(from->hdr.info.back); | ||
487 | to->magic = be16_to_cpu(from->hdr.info.magic); | ||
488 | to->count = be16_to_cpu(from->hdr.count); | ||
489 | to->stale = be16_to_cpu(from->hdr.stale); | ||
490 | |||
491 | ASSERT(to->magic == XFS_DIR2_LEAF1_MAGIC || | ||
492 | to->magic == XFS_DIR2_LEAFN_MAGIC); | ||
493 | } | ||
494 | |||
495 | static void | ||
496 | xfs_dir2_leaf_hdr_to_disk( | ||
497 | struct xfs_dir2_leaf *to, | ||
498 | struct xfs_dir3_icleaf_hdr *from) | ||
499 | { | ||
500 | ASSERT(from->magic == XFS_DIR2_LEAF1_MAGIC || | ||
501 | from->magic == XFS_DIR2_LEAFN_MAGIC); | ||
502 | |||
503 | to->hdr.info.forw = cpu_to_be32(from->forw); | ||
504 | to->hdr.info.back = cpu_to_be32(from->back); | ||
505 | to->hdr.info.magic = cpu_to_be16(from->magic); | ||
506 | to->hdr.count = cpu_to_be16(from->count); | ||
507 | to->hdr.stale = cpu_to_be16(from->stale); | ||
508 | } | ||
509 | |||
510 | static void | ||
511 | xfs_dir3_leaf_hdr_from_disk( | ||
512 | struct xfs_dir3_icleaf_hdr *to, | ||
513 | struct xfs_dir2_leaf *from) | ||
514 | { | ||
515 | struct xfs_dir3_leaf_hdr *hdr3 = (struct xfs_dir3_leaf_hdr *)from; | ||
516 | |||
517 | to->forw = be32_to_cpu(hdr3->info.hdr.forw); | ||
518 | to->back = be32_to_cpu(hdr3->info.hdr.back); | ||
519 | to->magic = be16_to_cpu(hdr3->info.hdr.magic); | ||
520 | to->count = be16_to_cpu(hdr3->count); | ||
521 | to->stale = be16_to_cpu(hdr3->stale); | ||
522 | |||
523 | ASSERT(to->magic == XFS_DIR3_LEAF1_MAGIC || | ||
524 | to->magic == XFS_DIR3_LEAFN_MAGIC); | ||
525 | } | ||
526 | |||
527 | static void | ||
528 | xfs_dir3_leaf_hdr_to_disk( | ||
529 | struct xfs_dir2_leaf *to, | ||
530 | struct xfs_dir3_icleaf_hdr *from) | ||
531 | { | ||
532 | struct xfs_dir3_leaf_hdr *hdr3 = (struct xfs_dir3_leaf_hdr *)to; | ||
533 | |||
534 | ASSERT(from->magic == XFS_DIR3_LEAF1_MAGIC || | ||
535 | from->magic == XFS_DIR3_LEAFN_MAGIC); | ||
536 | |||
537 | hdr3->info.hdr.forw = cpu_to_be32(from->forw); | ||
538 | hdr3->info.hdr.back = cpu_to_be32(from->back); | ||
539 | hdr3->info.hdr.magic = cpu_to_be16(from->magic); | ||
540 | hdr3->count = cpu_to_be16(from->count); | ||
541 | hdr3->stale = cpu_to_be16(from->stale); | ||
542 | } | ||
543 | |||
544 | |||
480 | /* | 545 | /* |
481 | * Directory/Attribute Node block operations | 546 | * Directory/Attribute Node block operations |
482 | */ | 547 | */ |
@@ -504,6 +569,121 @@ xfs_da3_node_tree_p(struct xfs_da_intnode *dap) | |||
504 | return ((struct xfs_da3_intnode *)dap)->__btree; | 569 | return ((struct xfs_da3_intnode *)dap)->__btree; |
505 | } | 570 | } |
506 | 571 | ||
572 | static void | ||
573 | xfs_da2_node_hdr_from_disk( | ||
574 | struct xfs_da3_icnode_hdr *to, | ||
575 | struct xfs_da_intnode *from) | ||
576 | { | ||
577 | ASSERT(from->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); | ||
578 | to->forw = be32_to_cpu(from->hdr.info.forw); | ||
579 | to->back = be32_to_cpu(from->hdr.info.back); | ||
580 | to->magic = be16_to_cpu(from->hdr.info.magic); | ||
581 | to->count = be16_to_cpu(from->hdr.__count); | ||
582 | to->level = be16_to_cpu(from->hdr.__level); | ||
583 | } | ||
584 | |||
585 | static void | ||
586 | xfs_da2_node_hdr_to_disk( | ||
587 | struct xfs_da_intnode *to, | ||
588 | struct xfs_da3_icnode_hdr *from) | ||
589 | { | ||
590 | ASSERT(from->magic == XFS_DA_NODE_MAGIC); | ||
591 | to->hdr.info.forw = cpu_to_be32(from->forw); | ||
592 | to->hdr.info.back = cpu_to_be32(from->back); | ||
593 | to->hdr.info.magic = cpu_to_be16(from->magic); | ||
594 | to->hdr.__count = cpu_to_be16(from->count); | ||
595 | to->hdr.__level = cpu_to_be16(from->level); | ||
596 | } | ||
597 | |||
598 | static void | ||
599 | xfs_da3_node_hdr_from_disk( | ||
600 | struct xfs_da3_icnode_hdr *to, | ||
601 | struct xfs_da_intnode *from) | ||
602 | { | ||
603 | struct xfs_da3_node_hdr *hdr3 = (struct xfs_da3_node_hdr *)from; | ||
604 | |||
605 | ASSERT(from->hdr.info.magic == cpu_to_be16(XFS_DA3_NODE_MAGIC)); | ||
606 | to->forw = be32_to_cpu(hdr3->info.hdr.forw); | ||
607 | to->back = be32_to_cpu(hdr3->info.hdr.back); | ||
608 | to->magic = be16_to_cpu(hdr3->info.hdr.magic); | ||
609 | to->count = be16_to_cpu(hdr3->__count); | ||
610 | to->level = be16_to_cpu(hdr3->__level); | ||
611 | } | ||
612 | |||
613 | static void | ||
614 | xfs_da3_node_hdr_to_disk( | ||
615 | struct xfs_da_intnode *to, | ||
616 | struct xfs_da3_icnode_hdr *from) | ||
617 | { | ||
618 | struct xfs_da3_node_hdr *hdr3 = (struct xfs_da3_node_hdr *)to; | ||
619 | |||
620 | ASSERT(from->magic == XFS_DA3_NODE_MAGIC); | ||
621 | hdr3->info.hdr.forw = cpu_to_be32(from->forw); | ||
622 | hdr3->info.hdr.back = cpu_to_be32(from->back); | ||
623 | hdr3->info.hdr.magic = cpu_to_be16(from->magic); | ||
624 | hdr3->__count = cpu_to_be16(from->count); | ||
625 | hdr3->__level = cpu_to_be16(from->level); | ||
626 | } | ||
627 | |||
628 | |||
629 | /* | ||
630 | * Directory free space block operations | ||
631 | */ | ||
632 | static void | ||
633 | xfs_dir2_free_hdr_from_disk( | ||
634 | struct xfs_dir3_icfree_hdr *to, | ||
635 | struct xfs_dir2_free *from) | ||
636 | { | ||
637 | to->magic = be32_to_cpu(from->hdr.magic); | ||
638 | to->firstdb = be32_to_cpu(from->hdr.firstdb); | ||
639 | to->nvalid = be32_to_cpu(from->hdr.nvalid); | ||
640 | to->nused = be32_to_cpu(from->hdr.nused); | ||
641 | ASSERT(to->magic == XFS_DIR2_FREE_MAGIC); | ||
642 | } | ||
643 | |||
644 | static void | ||
645 | xfs_dir2_free_hdr_to_disk( | ||
646 | struct xfs_dir2_free *to, | ||
647 | struct xfs_dir3_icfree_hdr *from) | ||
648 | { | ||
649 | ASSERT(from->magic == XFS_DIR2_FREE_MAGIC); | ||
650 | |||
651 | to->hdr.magic = cpu_to_be32(from->magic); | ||
652 | to->hdr.firstdb = cpu_to_be32(from->firstdb); | ||
653 | to->hdr.nvalid = cpu_to_be32(from->nvalid); | ||
654 | to->hdr.nused = cpu_to_be32(from->nused); | ||
655 | } | ||
656 | |||
657 | static void | ||
658 | xfs_dir3_free_hdr_from_disk( | ||
659 | struct xfs_dir3_icfree_hdr *to, | ||
660 | struct xfs_dir2_free *from) | ||
661 | { | ||
662 | struct xfs_dir3_free_hdr *hdr3 = (struct xfs_dir3_free_hdr *)from; | ||
663 | |||
664 | to->magic = be32_to_cpu(hdr3->hdr.magic); | ||
665 | to->firstdb = be32_to_cpu(hdr3->firstdb); | ||
666 | to->nvalid = be32_to_cpu(hdr3->nvalid); | ||
667 | to->nused = be32_to_cpu(hdr3->nused); | ||
668 | |||
669 | ASSERT(to->magic == XFS_DIR3_FREE_MAGIC); | ||
670 | } | ||
671 | |||
672 | static void | ||
673 | xfs_dir3_free_hdr_to_disk( | ||
674 | struct xfs_dir2_free *to, | ||
675 | struct xfs_dir3_icfree_hdr *from) | ||
676 | { | ||
677 | struct xfs_dir3_free_hdr *hdr3 = (struct xfs_dir3_free_hdr *)to; | ||
678 | |||
679 | ASSERT(from->magic == XFS_DIR3_FREE_MAGIC); | ||
680 | |||
681 | hdr3->hdr.magic = cpu_to_be32(from->magic); | ||
682 | hdr3->firstdb = cpu_to_be32(from->firstdb); | ||
683 | hdr3->nvalid = cpu_to_be32(from->nvalid); | ||
684 | hdr3->nused = cpu_to_be32(from->nused); | ||
685 | } | ||
686 | |||
507 | const struct xfs_dir_ops xfs_dir2_ops = { | 687 | const struct xfs_dir_ops xfs_dir2_ops = { |
508 | .sf_entsize = xfs_dir2_sf_entsize, | 688 | .sf_entsize = xfs_dir2_sf_entsize, |
509 | .sf_nextentry = xfs_dir2_sf_nextentry, | 689 | .sf_nextentry = xfs_dir2_sf_nextentry, |
@@ -532,11 +712,18 @@ const struct xfs_dir_ops xfs_dir2_ops = { | |||
532 | .data_unused_p = xfs_dir2_data_unused_p, | 712 | .data_unused_p = xfs_dir2_data_unused_p, |
533 | 713 | ||
534 | .leaf_hdr_size = xfs_dir2_leaf_hdr_size, | 714 | .leaf_hdr_size = xfs_dir2_leaf_hdr_size, |
715 | .leaf_hdr_to_disk = xfs_dir2_leaf_hdr_to_disk, | ||
716 | .leaf_hdr_from_disk = xfs_dir2_leaf_hdr_from_disk, | ||
535 | .leaf_max_ents = xfs_dir2_max_leaf_ents, | 717 | .leaf_max_ents = xfs_dir2_max_leaf_ents, |
536 | .leaf_ents_p = xfs_dir2_leaf_ents_p, | 718 | .leaf_ents_p = xfs_dir2_leaf_ents_p, |
537 | 719 | ||
538 | .node_hdr_size = xfs_da2_node_hdr_size, | 720 | .node_hdr_size = xfs_da2_node_hdr_size, |
721 | .node_hdr_to_disk = xfs_da2_node_hdr_to_disk, | ||
722 | .node_hdr_from_disk = xfs_da2_node_hdr_from_disk, | ||
539 | .node_tree_p = xfs_da2_node_tree_p, | 723 | .node_tree_p = xfs_da2_node_tree_p, |
724 | |||
725 | .free_hdr_to_disk = xfs_dir2_free_hdr_to_disk, | ||
726 | .free_hdr_from_disk = xfs_dir2_free_hdr_from_disk, | ||
540 | }; | 727 | }; |
541 | 728 | ||
542 | const struct xfs_dir_ops xfs_dir2_ftype_ops = { | 729 | const struct xfs_dir_ops xfs_dir2_ftype_ops = { |
@@ -567,11 +754,18 @@ const struct xfs_dir_ops xfs_dir2_ftype_ops = { | |||
567 | .data_unused_p = xfs_dir2_data_unused_p, | 754 | .data_unused_p = xfs_dir2_data_unused_p, |
568 | 755 | ||
569 | .leaf_hdr_size = xfs_dir2_leaf_hdr_size, | 756 | .leaf_hdr_size = xfs_dir2_leaf_hdr_size, |
757 | .leaf_hdr_to_disk = xfs_dir2_leaf_hdr_to_disk, | ||
758 | .leaf_hdr_from_disk = xfs_dir2_leaf_hdr_from_disk, | ||
570 | .leaf_max_ents = xfs_dir2_max_leaf_ents, | 759 | .leaf_max_ents = xfs_dir2_max_leaf_ents, |
571 | .leaf_ents_p = xfs_dir2_leaf_ents_p, | 760 | .leaf_ents_p = xfs_dir2_leaf_ents_p, |
572 | 761 | ||
573 | .node_hdr_size = xfs_da2_node_hdr_size, | 762 | .node_hdr_size = xfs_da2_node_hdr_size, |
763 | .node_hdr_to_disk = xfs_da2_node_hdr_to_disk, | ||
764 | .node_hdr_from_disk = xfs_da2_node_hdr_from_disk, | ||
574 | .node_tree_p = xfs_da2_node_tree_p, | 765 | .node_tree_p = xfs_da2_node_tree_p, |
766 | |||
767 | .free_hdr_to_disk = xfs_dir2_free_hdr_to_disk, | ||
768 | .free_hdr_from_disk = xfs_dir2_free_hdr_from_disk, | ||
575 | }; | 769 | }; |
576 | 770 | ||
577 | const struct xfs_dir_ops xfs_dir3_ops = { | 771 | const struct xfs_dir_ops xfs_dir3_ops = { |
@@ -602,20 +796,31 @@ const struct xfs_dir_ops xfs_dir3_ops = { | |||
602 | .data_unused_p = xfs_dir3_data_unused_p, | 796 | .data_unused_p = xfs_dir3_data_unused_p, |
603 | 797 | ||
604 | .leaf_hdr_size = xfs_dir3_leaf_hdr_size, | 798 | .leaf_hdr_size = xfs_dir3_leaf_hdr_size, |
799 | .leaf_hdr_to_disk = xfs_dir3_leaf_hdr_to_disk, | ||
800 | .leaf_hdr_from_disk = xfs_dir3_leaf_hdr_from_disk, | ||
605 | .leaf_max_ents = xfs_dir3_max_leaf_ents, | 801 | .leaf_max_ents = xfs_dir3_max_leaf_ents, |
606 | .leaf_ents_p = xfs_dir3_leaf_ents_p, | 802 | .leaf_ents_p = xfs_dir3_leaf_ents_p, |
607 | 803 | ||
608 | .node_hdr_size = xfs_da3_node_hdr_size, | 804 | .node_hdr_size = xfs_da3_node_hdr_size, |
805 | .node_hdr_to_disk = xfs_da3_node_hdr_to_disk, | ||
806 | .node_hdr_from_disk = xfs_da3_node_hdr_from_disk, | ||
609 | .node_tree_p = xfs_da3_node_tree_p, | 807 | .node_tree_p = xfs_da3_node_tree_p, |
808 | |||
809 | .free_hdr_to_disk = xfs_dir3_free_hdr_to_disk, | ||
810 | .free_hdr_from_disk = xfs_dir3_free_hdr_from_disk, | ||
610 | }; | 811 | }; |
611 | 812 | ||
612 | const struct xfs_dir_ops xfs_dir2_nondir_ops = { | 813 | const struct xfs_dir_ops xfs_dir2_nondir_ops = { |
613 | .node_hdr_size = xfs_da2_node_hdr_size, | 814 | .node_hdr_size = xfs_da2_node_hdr_size, |
815 | .node_hdr_to_disk = xfs_da2_node_hdr_to_disk, | ||
816 | .node_hdr_from_disk = xfs_da2_node_hdr_from_disk, | ||
614 | .node_tree_p = xfs_da2_node_tree_p, | 817 | .node_tree_p = xfs_da2_node_tree_p, |
615 | }; | 818 | }; |
616 | 819 | ||
617 | const struct xfs_dir_ops xfs_dir3_nondir_ops = { | 820 | const struct xfs_dir_ops xfs_dir3_nondir_ops = { |
618 | .node_hdr_size = xfs_da3_node_hdr_size, | 821 | .node_hdr_size = xfs_da3_node_hdr_size, |
822 | .node_hdr_to_disk = xfs_da3_node_hdr_to_disk, | ||
823 | .node_hdr_from_disk = xfs_da3_node_hdr_from_disk, | ||
619 | .node_tree_p = xfs_da3_node_tree_p, | 824 | .node_tree_p = xfs_da3_node_tree_p, |
620 | }; | 825 | }; |
621 | 826 | ||