Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

xfs: cleanup shortform directory inode number handling

Refactor the shortform directory helpers that deal with the 32-bit vs
64-bit wide inode numbers into more sensible helpers, and kill the
xfs_intino_t typedef that is now superflous.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Alex Elder <aelder@sgi.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>

+104 -75
+2 -3
fs/xfs/xfs_dir2_block.c
··· 1146 1146 */ 1147 1147 dep = (xfs_dir2_data_entry_t *) 1148 1148 ((char *)block + XFS_DIR2_DATA_DOTDOT_OFFSET); 1149 - dep->inumber = cpu_to_be64(xfs_dir2_sf_get_inumber(sfp, &sfp->hdr.parent)); 1149 + dep->inumber = cpu_to_be64(xfs_dir2_sf_get_parent_ino(sfp)); 1150 1150 dep->namelen = 2; 1151 1151 dep->name[0] = dep->name[1] = '.'; 1152 1152 tagp = xfs_dir2_data_entry_tag_p(dep); ··· 1195 1195 * Copy a real entry. 1196 1196 */ 1197 1197 dep = (xfs_dir2_data_entry_t *)((char *)block + newoffset); 1198 - dep->inumber = cpu_to_be64(xfs_dir2_sf_get_inumber(sfp, 1199 - xfs_dir2_sf_inumberp(sfep))); 1198 + dep->inumber = cpu_to_be64(xfs_dir2_sfe_get_ino(sfp, sfep)); 1200 1199 dep->namelen = sfep->namelen; 1201 1200 memcpy(dep->name, sfep->name, dep->namelen); 1202 1201 tagp = xfs_dir2_data_entry_tag_p(dep);
+99 -39
fs/xfs/xfs_dir2_sf.c
··· 59 59 static void xfs_dir2_sf_toino8(xfs_da_args_t *args); 60 60 #endif /* XFS_BIG_INUMS */ 61 61 62 + 63 + /* 64 + * Inode numbers in short-form directories can come in two versions, 65 + * either 4 bytes or 8 bytes wide. These helpers deal with the 66 + * two forms transparently by looking at the headers i8count field. 67 + */ 68 + static xfs_ino_t 69 + xfs_dir2_sf_get_ino( 70 + struct xfs_dir2_sf *sfp, 71 + xfs_dir2_inou_t *from) 72 + { 73 + if (sfp->hdr.i8count) 74 + return XFS_GET_DIR_INO8(from->i8); 75 + else 76 + return XFS_GET_DIR_INO4(from->i4); 77 + } 78 + 79 + static void 80 + xfs_dir2_sf_put_ino( 81 + struct xfs_dir2_sf *sfp, 82 + xfs_dir2_inou_t *to, 83 + xfs_ino_t ino) 84 + { 85 + if (sfp->hdr.i8count) 86 + XFS_PUT_DIR_INO8(ino, to->i8); 87 + else 88 + XFS_PUT_DIR_INO4(ino, to->i4); 89 + } 90 + 91 + xfs_ino_t 92 + xfs_dir2_sf_get_parent_ino( 93 + struct xfs_dir2_sf *sfp) 94 + { 95 + return xfs_dir2_sf_get_ino(sfp, &sfp->hdr.parent); 96 + } 97 + 98 + static void 99 + xfs_dir2_sf_put_parent_ino( 100 + struct xfs_dir2_sf *sfp, 101 + xfs_ino_t ino) 102 + { 103 + xfs_dir2_sf_put_ino(sfp, &sfp->hdr.parent, ino); 104 + } 105 + 106 + /* 107 + * In short-form directory entries the inode numbers are stored at variable 108 + * offset behind the entry name. The inode numbers may only be accessed 109 + * through the helpers below. 110 + */ 111 + static xfs_dir2_inou_t * 112 + xfs_dir2_sfe_inop( 113 + struct xfs_dir2_sf_entry *sfep) 114 + { 115 + return (xfs_dir2_inou_t *)&sfep->name[sfep->namelen]; 116 + } 117 + 118 + xfs_ino_t 119 + xfs_dir2_sfe_get_ino( 120 + struct xfs_dir2_sf *sfp, 121 + struct xfs_dir2_sf_entry *sfep) 122 + { 123 + return xfs_dir2_sf_get_ino(sfp, xfs_dir2_sfe_inop(sfep)); 124 + } 125 + 126 + static void 127 + xfs_dir2_sfe_put_ino( 128 + struct xfs_dir2_sf *sfp, 129 + struct xfs_dir2_sf_entry *sfep, 130 + xfs_ino_t ino) 131 + { 132 + xfs_dir2_sf_put_ino(sfp, xfs_dir2_sfe_inop(sfep), ino); 133 + } 134 + 62 135 /* 63 136 * Given a block directory (dp/block), calculate its size as a shortform (sf) 64 137 * directory and a header for the sf directory, if it will fit it the ··· 211 138 */ 212 139 sfhp->count = count; 213 140 sfhp->i8count = i8count; 214 - xfs_dir2_sf_put_inumber((xfs_dir2_sf_t *)sfhp, &parent, &sfhp->parent); 141 + xfs_dir2_sf_put_parent_ino((xfs_dir2_sf_t *)sfhp, parent); 215 142 return size; 216 143 } 217 144 ··· 238 165 char *ptr; /* current data pointer */ 239 166 xfs_dir2_sf_entry_t *sfep; /* shortform entry */ 240 167 xfs_dir2_sf_t *sfp; /* shortform structure */ 241 - xfs_ino_t temp; 242 168 243 169 trace_xfs_dir2_block_to_sf(args); 244 170 ··· 305 233 else if (dep->namelen == 2 && 306 234 dep->name[0] == '.' && dep->name[1] == '.') 307 235 ASSERT(be64_to_cpu(dep->inumber) == 308 - xfs_dir2_sf_get_inumber(sfp, &sfp->hdr.parent)); 236 + xfs_dir2_sf_get_parent_ino(sfp)); 309 237 /* 310 238 * Normal entry, copy it into shortform. 311 239 */ ··· 315 243 (xfs_dir2_data_aoff_t) 316 244 ((char *)dep - (char *)block)); 317 245 memcpy(sfep->name, dep->name, dep->namelen); 318 - temp = be64_to_cpu(dep->inumber); 319 - xfs_dir2_sf_put_inumber(sfp, &temp, 320 - xfs_dir2_sf_inumberp(sfep)); 246 + xfs_dir2_sfe_put_ino(sfp, sfep, 247 + be64_to_cpu(dep->inumber)); 248 + 321 249 sfep = xfs_dir2_sf_nextentry(sfp, sfep); 322 250 } 323 251 ptr += xfs_dir2_data_entsize(dep->namelen); ··· 478 406 sfep->namelen = args->namelen; 479 407 xfs_dir2_sf_put_offset(sfep, offset); 480 408 memcpy(sfep->name, args->name, sfep->namelen); 481 - xfs_dir2_sf_put_inumber(sfp, &args->inumber, 482 - xfs_dir2_sf_inumberp(sfep)); 409 + xfs_dir2_sfe_put_ino(sfp, sfep, args->inumber); 483 410 /* 484 411 * Update the header and inode. 485 412 */ ··· 569 498 sfep->namelen = args->namelen; 570 499 xfs_dir2_sf_put_offset(sfep, offset); 571 500 memcpy(sfep->name, args->name, sfep->namelen); 572 - xfs_dir2_sf_put_inumber(sfp, &args->inumber, 573 - xfs_dir2_sf_inumberp(sfep)); 501 + xfs_dir2_sfe_put_ino(sfp, sfep, args->inumber); 574 502 sfp->hdr.count++; 575 503 #if XFS_BIG_INUMS 576 504 if (args->inumber > XFS_DIR2_MAX_SHORT_INUM && !objchange) ··· 688 618 689 619 sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data; 690 620 offset = XFS_DIR2_DATA_FIRST_OFFSET; 691 - ino = xfs_dir2_sf_get_inumber(sfp, &sfp->hdr.parent); 621 + ino = xfs_dir2_sf_get_parent_ino(sfp); 692 622 i8count = ino > XFS_DIR2_MAX_SHORT_INUM; 693 623 694 624 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp); 695 625 i < sfp->hdr.count; 696 626 i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep)) { 697 627 ASSERT(xfs_dir2_sf_get_offset(sfep) >= offset); 698 - ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep)); 628 + ino = xfs_dir2_sfe_get_ino(sfp, sfep); 699 629 i8count += ino > XFS_DIR2_MAX_SHORT_INUM; 700 630 offset = 701 631 xfs_dir2_sf_get_offset(sfep) + ··· 756 686 /* 757 687 * Now can put in the inode number, since i8count is set. 758 688 */ 759 - xfs_dir2_sf_put_inumber(sfp, &pino, &sfp->hdr.parent); 689 + xfs_dir2_sf_put_parent_ino(sfp, pino); 760 690 sfp->hdr.count = 0; 761 691 dp->i_d.di_size = size; 762 692 xfs_dir2_sf_check(args); ··· 829 759 * Put .. entry unless we're starting past it. 830 760 */ 831 761 if (*offset <= dotdot_offset) { 832 - ino = xfs_dir2_sf_get_inumber(sfp, &sfp->hdr.parent); 762 + ino = xfs_dir2_sf_get_parent_ino(sfp); 833 763 if (filldir(dirent, "..", 2, dotdot_offset & 0x7fffffff, ino, DT_DIR)) { 834 764 *offset = dotdot_offset & 0x7fffffff; 835 765 return 0; ··· 849 779 continue; 850 780 } 851 781 852 - ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep)); 782 + ino = xfs_dir2_sfe_get_ino(sfp, sfep); 853 783 if (filldir(dirent, (char *)sfep->name, sfep->namelen, 854 784 off & 0x7fffffff, ino, DT_UNKNOWN)) { 855 785 *offset = off & 0x7fffffff; ··· 909 839 */ 910 840 if (args->namelen == 2 && 911 841 args->name[0] == '.' && args->name[1] == '.') { 912 - args->inumber = xfs_dir2_sf_get_inumber(sfp, &sfp->hdr.parent); 842 + args->inumber = xfs_dir2_sf_get_parent_ino(sfp); 913 843 args->cmpresult = XFS_CMP_EXACT; 914 844 return XFS_ERROR(EEXIST); 915 845 } ··· 928 858 sfep->namelen); 929 859 if (cmp != XFS_CMP_DIFFERENT && cmp != args->cmpresult) { 930 860 args->cmpresult = cmp; 931 - args->inumber = xfs_dir2_sf_get_inumber(sfp, 932 - xfs_dir2_sf_inumberp(sfep)); 861 + args->inumber = xfs_dir2_sfe_get_ino(sfp, sfep); 933 862 if (cmp == XFS_CMP_EXACT) 934 863 return XFS_ERROR(EEXIST); 935 864 ci_sfep = sfep; ··· 987 918 i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep)) { 988 919 if (xfs_da_compname(args, sfep->name, sfep->namelen) == 989 920 XFS_CMP_EXACT) { 990 - ASSERT(xfs_dir2_sf_get_inumber(sfp, 991 - xfs_dir2_sf_inumberp(sfep)) == 992 - args->inumber); 921 + ASSERT(xfs_dir2_sfe_get_ino(sfp, sfep) == 922 + args->inumber); 993 923 break; 994 924 } 995 925 } ··· 1108 1040 if (args->namelen == 2 && 1109 1041 args->name[0] == '.' && args->name[1] == '.') { 1110 1042 #if XFS_BIG_INUMS || defined(DEBUG) 1111 - ino = xfs_dir2_sf_get_inumber(sfp, &sfp->hdr.parent); 1043 + ino = xfs_dir2_sf_get_parent_ino(sfp); 1112 1044 ASSERT(args->inumber != ino); 1113 1045 #endif 1114 - xfs_dir2_sf_put_inumber(sfp, &args->inumber, &sfp->hdr.parent); 1046 + xfs_dir2_sf_put_parent_ino(sfp, args->inumber); 1115 1047 } 1116 1048 /* 1117 1049 * Normal entry, look for the name. ··· 1123 1055 if (xfs_da_compname(args, sfep->name, sfep->namelen) == 1124 1056 XFS_CMP_EXACT) { 1125 1057 #if XFS_BIG_INUMS || defined(DEBUG) 1126 - ino = xfs_dir2_sf_get_inumber(sfp, 1127 - xfs_dir2_sf_inumberp(sfep)); 1058 + ino = xfs_dir2_sfe_get_ino(sfp, sfep); 1128 1059 ASSERT(args->inumber != ino); 1129 1060 #endif 1130 - xfs_dir2_sf_put_inumber(sfp, &args->inumber, 1131 - xfs_dir2_sf_inumberp(sfep)); 1061 + xfs_dir2_sfe_put_ino(sfp, sfep, args->inumber); 1132 1062 break; 1133 1063 } 1134 1064 } ··· 1187 1121 char *buf; /* old dir's buffer */ 1188 1122 xfs_inode_t *dp; /* incore directory inode */ 1189 1123 int i; /* entry index */ 1190 - xfs_ino_t ino; /* entry inode number */ 1191 1124 int newsize; /* new inode size */ 1192 1125 xfs_dir2_sf_entry_t *oldsfep; /* old sf entry */ 1193 1126 xfs_dir2_sf_t *oldsfp; /* old sf directory */ ··· 1227 1162 */ 1228 1163 sfp->hdr.count = oldsfp->hdr.count; 1229 1164 sfp->hdr.i8count = 0; 1230 - ino = xfs_dir2_sf_get_inumber(oldsfp, &oldsfp->hdr.parent); 1231 - xfs_dir2_sf_put_inumber(sfp, &ino, &sfp->hdr.parent); 1165 + xfs_dir2_sf_put_parent_ino(sfp, xfs_dir2_sf_get_parent_ino(oldsfp)); 1232 1166 /* 1233 1167 * Copy the entries field by field. 1234 1168 */ ··· 1239 1175 sfep->namelen = oldsfep->namelen; 1240 1176 sfep->offset = oldsfep->offset; 1241 1177 memcpy(sfep->name, oldsfep->name, sfep->namelen); 1242 - ino = xfs_dir2_sf_get_inumber(oldsfp, 1243 - xfs_dir2_sf_inumberp(oldsfep)); 1244 - xfs_dir2_sf_put_inumber(sfp, &ino, xfs_dir2_sf_inumberp(sfep)); 1178 + xfs_dir2_sfe_put_ino(sfp, sfep, 1179 + xfs_dir2_sfe_get_ino(oldsfp, oldsfep)); 1245 1180 } 1246 1181 /* 1247 1182 * Clean up the inode. ··· 1262 1199 char *buf; /* old dir's buffer */ 1263 1200 xfs_inode_t *dp; /* incore directory inode */ 1264 1201 int i; /* entry index */ 1265 - xfs_ino_t ino; /* entry inode number */ 1266 1202 int newsize; /* new inode size */ 1267 1203 xfs_dir2_sf_entry_t *oldsfep; /* old sf entry */ 1268 1204 xfs_dir2_sf_t *oldsfp; /* old sf directory */ ··· 1302 1240 */ 1303 1241 sfp->hdr.count = oldsfp->hdr.count; 1304 1242 sfp->hdr.i8count = 1; 1305 - ino = xfs_dir2_sf_get_inumber(oldsfp, &oldsfp->hdr.parent); 1306 - xfs_dir2_sf_put_inumber(sfp, &ino, &sfp->hdr.parent); 1243 + xfs_dir2_sf_put_parent_ino(sfp, xfs_dir2_sf_get_parent_ino(oldsfp)); 1307 1244 /* 1308 1245 * Copy the entries field by field. 1309 1246 */ ··· 1314 1253 sfep->namelen = oldsfep->namelen; 1315 1254 sfep->offset = oldsfep->offset; 1316 1255 memcpy(sfep->name, oldsfep->name, sfep->namelen); 1317 - ino = xfs_dir2_sf_get_inumber(oldsfp, 1318 - xfs_dir2_sf_inumberp(oldsfep)); 1319 - xfs_dir2_sf_put_inumber(sfp, &ino, xfs_dir2_sf_inumberp(sfep)); 1256 + xfs_dir2_sfe_put_ino(sfp, sfep, 1257 + xfs_dir2_sfe_get_ino(oldsfp, oldsfep)); 1320 1258 } 1321 1259 /* 1322 1260 * Clean up the inode.
+3 -22
fs/xfs/xfs_dir2_sf.h
··· 90 90 ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t))); 91 91 } 92 92 93 - static inline xfs_dir2_inou_t *xfs_dir2_sf_inumberp(xfs_dir2_sf_entry_t *sfep) 94 - { 95 - return (xfs_dir2_inou_t *)&(sfep)->name[(sfep)->namelen]; 96 - } 97 - 98 - static inline xfs_intino_t 99 - xfs_dir2_sf_get_inumber(xfs_dir2_sf_t *sfp, xfs_dir2_inou_t *from) 100 - { 101 - return ((sfp)->hdr.i8count == 0 ? \ 102 - (xfs_intino_t)XFS_GET_DIR_INO4((from)->i4) : \ 103 - (xfs_intino_t)XFS_GET_DIR_INO8((from)->i8)); 104 - } 105 - 106 - static inline void xfs_dir2_sf_put_inumber(xfs_dir2_sf_t *sfp, xfs_ino_t *from, 107 - xfs_dir2_inou_t *to) 108 - { 109 - if ((sfp)->hdr.i8count == 0) 110 - XFS_PUT_DIR_INO4(*(from), (to)->i4); 111 - else 112 - XFS_PUT_DIR_INO8(*(from), (to)->i8); 113 - } 114 - 115 93 static inline xfs_dir2_data_aoff_t 116 94 xfs_dir2_sf_get_offset(xfs_dir2_sf_entry_t *sfep) 117 95 { ··· 133 155 /* 134 156 * Functions. 135 157 */ 158 + extern xfs_ino_t xfs_dir2_sf_get_parent_ino(struct xfs_dir2_sf *sfp); 159 + extern xfs_ino_t xfs_dir2_sfe_get_ino(struct xfs_dir2_sf *sfp, 160 + struct xfs_dir2_sf_entry *sfep); 136 161 extern int xfs_dir2_block_sfsize(struct xfs_inode *dp, 137 162 struct xfs_dir2_block *block, 138 163 xfs_dir2_sf_hdr_t *sfhp);
-11
fs/xfs/xfs_inum.h
··· 28 28 29 29 typedef __uint32_t xfs_agino_t; /* within allocation grp inode number */ 30 30 31 - /* 32 - * Useful inode bits for this kernel. 33 - * Used in some places where having 64-bits in the 32-bit kernels 34 - * costs too much. 35 - */ 36 - #if XFS_BIG_INUMS 37 - typedef xfs_ino_t xfs_intino_t; 38 - #else 39 - typedef __uint32_t xfs_intino_t; 40 - #endif 41 - 42 31 #define NULLFSINO ((xfs_ino_t)-1) 43 32 #define NULLAGINO ((xfs_agino_t)-1) 44 33