aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_attr.c
diff options
context:
space:
mode:
authorDave Chinner <dchinner@redhat.com>2012-11-12 06:54:16 -0500
committerBen Myers <bpm@sgi.com>2012-11-15 22:34:52 -0500
commitad14c33ac862601c4c22755ed3b59f1906b134e5 (patch)
tree80d2fe31b0db8c0f763080ca69902cf903764da9 /fs/xfs/xfs_attr.c
parente6f7667c4eef42b6f5bc6cdeb31d0bab62fe5f79 (diff)
xfs: factor and verify attr leaf reads
Some reads are not converted yet because it isn't obvious ahead of time what the format of the block is going to be. Need to determine how to tell if the first block in the tree is a node or leaf format block. That will be done in later patches. Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Phil White <pwhite@sgi.com> Signed-off-by: Ben Myers <bpm@sgi.com>
Diffstat (limited to 'fs/xfs/xfs_attr.c')
-rw-r--r--fs/xfs/xfs_attr.c70
1 files changed, 18 insertions, 52 deletions
diff --git a/fs/xfs/xfs_attr.c b/fs/xfs/xfs_attr.c
index cd5a9cd0ded0..d644915367e3 100644
--- a/fs/xfs/xfs_attr.c
+++ b/fs/xfs/xfs_attr.c
@@ -903,11 +903,9 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
903 */ 903 */
904 dp = args->dp; 904 dp = args->dp;
905 args->blkno = 0; 905 args->blkno = 0;
906 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp, 906 error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
907 XFS_ATTR_FORK, NULL);
908 if (error) 907 if (error)
909 return(error); 908 return error;
910 ASSERT(bp != NULL);
911 909
912 /* 910 /*
913 * Look up the given attribute in the leaf block. Figure out if 911 * Look up the given attribute in the leaf block. Figure out if
@@ -1031,12 +1029,12 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
1031 * Read in the block containing the "old" attr, then 1029 * Read in the block containing the "old" attr, then
1032 * remove the "old" attr from that block (neat, huh!) 1030 * remove the "old" attr from that block (neat, huh!)
1033 */ 1031 */
1034 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, 1032 error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno,
1035 &bp, XFS_ATTR_FORK, NULL); 1033 -1, &bp);
1036 if (error) 1034 if (error)
1037 return(error); 1035 return error;
1038 ASSERT(bp != NULL); 1036
1039 (void)xfs_attr_leaf_remove(bp, args); 1037 xfs_attr_leaf_remove(bp, args);
1040 1038
1041 /* 1039 /*
1042 * If the result is small enough, shrink it all into the inode. 1040 * If the result is small enough, shrink it all into the inode.
@@ -1100,20 +1098,17 @@ xfs_attr_leaf_removename(xfs_da_args_t *args)
1100 */ 1098 */
1101 dp = args->dp; 1099 dp = args->dp;
1102 args->blkno = 0; 1100 args->blkno = 0;
1103 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp, 1101 error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
1104 XFS_ATTR_FORK, NULL); 1102 if (error)
1105 if (error) { 1103 return error;
1106 return(error);
1107 }
1108 1104
1109 ASSERT(bp != NULL);
1110 error = xfs_attr_leaf_lookup_int(bp, args); 1105 error = xfs_attr_leaf_lookup_int(bp, args);
1111 if (error == ENOATTR) { 1106 if (error == ENOATTR) {
1112 xfs_trans_brelse(args->trans, bp); 1107 xfs_trans_brelse(args->trans, bp);
1113 return(error); 1108 return(error);
1114 } 1109 }
1115 1110
1116 (void)xfs_attr_leaf_remove(bp, args); 1111 xfs_attr_leaf_remove(bp, args);
1117 1112
1118 /* 1113 /*
1119 * If the result is small enough, shrink it all into the inode. 1114 * If the result is small enough, shrink it all into the inode.
@@ -1158,11 +1153,9 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
1158 trace_xfs_attr_leaf_get(args); 1153 trace_xfs_attr_leaf_get(args);
1159 1154
1160 args->blkno = 0; 1155 args->blkno = 0;
1161 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp, 1156 error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
1162 XFS_ATTR_FORK, NULL);
1163 if (error) 1157 if (error)
1164 return(error); 1158 return error;
1165 ASSERT(bp != NULL);
1166 1159
1167 error = xfs_attr_leaf_lookup_int(bp, args); 1160 error = xfs_attr_leaf_lookup_int(bp, args);
1168 if (error != EEXIST) { 1161 if (error != EEXIST) {
@@ -1183,25 +1176,15 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
1183STATIC int 1176STATIC int
1184xfs_attr_leaf_list(xfs_attr_list_context_t *context) 1177xfs_attr_leaf_list(xfs_attr_list_context_t *context)
1185{ 1178{
1186 xfs_attr_leafblock_t *leaf;
1187 int error; 1179 int error;
1188 struct xfs_buf *bp; 1180 struct xfs_buf *bp;
1189 1181
1190 trace_xfs_attr_leaf_list(context); 1182 trace_xfs_attr_leaf_list(context);
1191 1183
1192 context->cursor->blkno = 0; 1184 context->cursor->blkno = 0;
1193 error = xfs_da_read_buf(NULL, context->dp, 0, -1, &bp, XFS_ATTR_FORK, 1185 error = xfs_attr_leaf_read(NULL, context->dp, 0, -1, &bp);
1194 NULL);
1195 if (error) 1186 if (error)
1196 return XFS_ERROR(error); 1187 return XFS_ERROR(error);
1197 ASSERT(bp != NULL);
1198 leaf = bp->b_addr;
1199 if (unlikely(leaf->hdr.info.magic != cpu_to_be16(XFS_ATTR_LEAF_MAGIC))) {
1200 XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW,
1201 context->dp->i_mount, leaf);
1202 xfs_trans_brelse(NULL, bp);
1203 return XFS_ERROR(EFSCORRUPTED);
1204 }
1205 1188
1206 error = xfs_attr_leaf_list_int(bp, context); 1189 error = xfs_attr_leaf_list_int(bp, context);
1207 xfs_trans_brelse(NULL, bp); 1190 xfs_trans_brelse(NULL, bp);
@@ -1605,12 +1588,9 @@ xfs_attr_node_removename(xfs_da_args_t *args)
1605 ASSERT(state->path.blk[0].bp); 1588 ASSERT(state->path.blk[0].bp);
1606 state->path.blk[0].bp = NULL; 1589 state->path.blk[0].bp = NULL;
1607 1590
1608 error = xfs_da_read_buf(args->trans, args->dp, 0, -1, &bp, 1591 error = xfs_attr_leaf_read(args->trans, args->dp, 0, -1, &bp);
1609 XFS_ATTR_FORK, NULL);
1610 if (error) 1592 if (error)
1611 goto out; 1593 goto out;
1612 ASSERT((((xfs_attr_leafblock_t *)bp->b_addr)->hdr.info.magic) ==
1613 cpu_to_be16(XFS_ATTR_LEAF_MAGIC));
1614 1594
1615 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) { 1595 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1616 xfs_bmap_init(args->flist, args->firstblock); 1596 xfs_bmap_init(args->flist, args->firstblock);
@@ -1920,14 +1900,6 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
1920 */ 1900 */
1921 for (;;) { 1901 for (;;) {
1922 leaf = bp->b_addr; 1902 leaf = bp->b_addr;
1923 if (unlikely(leaf->hdr.info.magic !=
1924 cpu_to_be16(XFS_ATTR_LEAF_MAGIC))) {
1925 XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
1926 XFS_ERRLEVEL_LOW,
1927 context->dp->i_mount, leaf);
1928 xfs_trans_brelse(NULL, bp);
1929 return(XFS_ERROR(EFSCORRUPTED));
1930 }
1931 error = xfs_attr_leaf_list_int(bp, context); 1903 error = xfs_attr_leaf_list_int(bp, context);
1932 if (error) { 1904 if (error) {
1933 xfs_trans_brelse(NULL, bp); 1905 xfs_trans_brelse(NULL, bp);
@@ -1937,16 +1909,10 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
1937 break; 1909 break;
1938 cursor->blkno = be32_to_cpu(leaf->hdr.info.forw); 1910 cursor->blkno = be32_to_cpu(leaf->hdr.info.forw);
1939 xfs_trans_brelse(NULL, bp); 1911 xfs_trans_brelse(NULL, bp);
1940 error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1, 1912 error = xfs_attr_leaf_read(NULL, context->dp, cursor->blkno, -1,
1941 &bp, XFS_ATTR_FORK, NULL); 1913 &bp);
1942 if (error) 1914 if (error)
1943 return(error); 1915 return error;
1944 if (unlikely((bp == NULL))) {
1945 XFS_ERROR_REPORT("xfs_attr_node_list(5)",
1946 XFS_ERRLEVEL_LOW,
1947 context->dp->i_mount);
1948 return(XFS_ERROR(EFSCORRUPTED));
1949 }
1950 } 1916 }
1951 xfs_trans_brelse(NULL, bp); 1917 xfs_trans_brelse(NULL, bp);
1952 return(0); 1918 return(0);