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

[XFS] Add op_flags field and helpers to xfs_da_args

The end of the xfs_da_args structure has 4 unsigned char fields for
true/false information on directory and attr operations using the
xfs_da_args structure.

The following converts these 4 into a op_flags field that uses the first 4
bits for these fields and allows expansion for future operation
information (eg. case-insensitive lookup request).

SGI-PV: 981520
SGI-Modid: xfs-linux-melb:xfs-kern:31206a

Signed-off-by: Barry Naujok <bnaujok@sgi.com>
Signed-off-by: Christoph Hellwig <hch@infradead.org>

authored by

Barry Naujok and committed by
Niv Sardi
6a178100 5163f95a

+71 -58
+5 -6
fs/xfs/xfs_attr.c
··· 241 241 args.firstblock = &firstblock; 242 242 args.flist = &flist; 243 243 args.whichfork = XFS_ATTR_FORK; 244 - args.addname = 1; 245 - args.oknoent = 1; 244 + args.op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT; 246 245 247 246 /* 248 247 * Determine space new attribute will use, and if it would be ··· 973 974 xfs_da_brelse(args->trans, bp); 974 975 return(retval); 975 976 } 976 - args->rename = 1; /* an atomic rename */ 977 + args->op_flags |= XFS_DA_OP_RENAME; /* an atomic rename */ 977 978 args->blkno2 = args->blkno; /* set 2nd entry info*/ 978 979 args->index2 = args->index; 979 980 args->rmtblkno2 = args->rmtblkno; ··· 1053 1054 * so that one disappears and one appears atomically. Then we 1054 1055 * must remove the "old" attribute/value pair. 1055 1056 */ 1056 - if (args->rename) { 1057 + if (args->op_flags & XFS_DA_OP_RENAME) { 1057 1058 /* 1058 1059 * In a separate transaction, set the incomplete flag on the 1059 1060 * "old" attr and clear the incomplete flag on the "new" attr. ··· 1306 1307 } else if (retval == EEXIST) { 1307 1308 if (args->flags & ATTR_CREATE) 1308 1309 goto out; 1309 - args->rename = 1; /* atomic rename op */ 1310 + args->op_flags |= XFS_DA_OP_RENAME; /* atomic rename op */ 1310 1311 args->blkno2 = args->blkno; /* set 2nd entry info*/ 1311 1312 args->index2 = args->index; 1312 1313 args->rmtblkno2 = args->rmtblkno; ··· 1424 1425 * so that one disappears and one appears atomically. Then we 1425 1426 * must remove the "old" attribute/value pair. 1426 1427 */ 1427 - if (args->rename) { 1428 + if (args->op_flags & XFS_DA_OP_RENAME) { 1428 1429 /* 1429 1430 * In a separate transaction, set the incomplete flag on the 1430 1431 * "old" attr and clear the incomplete flag on the "new" attr.
+11 -9
fs/xfs/xfs_attr_leaf.c
··· 369 369 * Fix up the start offset of the attribute fork 370 370 */ 371 371 totsize -= size; 372 - if (totsize == sizeof(xfs_attr_sf_hdr_t) && !args->addname && 373 - (mp->m_flags & XFS_MOUNT_ATTR2) && 374 - (dp->i_d.di_format != XFS_DINODE_FMT_BTREE)) { 372 + if (totsize == sizeof(xfs_attr_sf_hdr_t) && 373 + !(args->op_flags & XFS_DA_OP_ADDNAME) && 374 + (mp->m_flags & XFS_MOUNT_ATTR2) && 375 + (dp->i_d.di_format != XFS_DINODE_FMT_BTREE)) { 375 376 /* 376 377 * Last attribute now removed, revert to original 377 378 * inode format making all literal area available ··· 390 389 xfs_idata_realloc(dp, -size, XFS_ATTR_FORK); 391 390 dp->i_d.di_forkoff = xfs_attr_shortform_bytesfit(dp, totsize); 392 391 ASSERT(dp->i_d.di_forkoff); 393 - ASSERT(totsize > sizeof(xfs_attr_sf_hdr_t) || args->addname || 394 - !(mp->m_flags & XFS_MOUNT_ATTR2) || 395 - dp->i_d.di_format == XFS_DINODE_FMT_BTREE); 392 + ASSERT(totsize > sizeof(xfs_attr_sf_hdr_t) || 393 + (args->op_flags & XFS_DA_OP_ADDNAME) || 394 + !(mp->m_flags & XFS_MOUNT_ATTR2) || 395 + dp->i_d.di_format == XFS_DINODE_FMT_BTREE); 396 396 dp->i_afp->if_ext_max = 397 397 XFS_IFORK_ASIZE(dp) / (uint)sizeof(xfs_bmbt_rec_t); 398 398 dp->i_df.if_ext_max = ··· 533 531 nargs.total = args->total; 534 532 nargs.whichfork = XFS_ATTR_FORK; 535 533 nargs.trans = args->trans; 536 - nargs.oknoent = 1; 534 + nargs.op_flags = XFS_DA_OP_OKNOENT; 537 535 538 536 sfe = &sf->list[0]; 539 537 for (i = 0; i < sf->hdr.count; i++) { ··· 855 853 nargs.total = args->total; 856 854 nargs.whichfork = XFS_ATTR_FORK; 857 855 nargs.trans = args->trans; 858 - nargs.oknoent = 1; 856 + nargs.op_flags = XFS_DA_OP_OKNOENT; 859 857 entry = &leaf->entries[0]; 860 858 for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) { 861 859 if (entry->flags & XFS_ATTR_INCOMPLETE) ··· 1157 1155 entry->hashval = cpu_to_be32(args->hashval); 1158 1156 entry->flags = tmp ? XFS_ATTR_LOCAL : 0; 1159 1157 entry->flags |= XFS_ATTR_NSP_ARGS_TO_ONDISK(args->flags); 1160 - if (args->rename) { 1158 + if (args->op_flags & XFS_DA_OP_RENAME) { 1161 1159 entry->flags |= XFS_ATTR_INCOMPLETE; 1162 1160 if ((args->blkno2 == args->blkno) && 1163 1161 (args->index2 <= args->index)) {
+1 -1
fs/xfs/xfs_da_btree.c
··· 1431 1431 } 1432 1432 if (level < 0) { 1433 1433 *result = XFS_ERROR(ENOENT); /* we're out of our tree */ 1434 - ASSERT(args->oknoent); 1434 + ASSERT(args->op_flags & XFS_DA_OP_OKNOENT); 1435 1435 return(0); 1436 1436 } 1437 1437
+9 -4
fs/xfs/xfs_da_btree.h
··· 132 132 int index2; /* index of 2nd attr in blk */ 133 133 xfs_dablk_t rmtblkno2; /* remote attr value starting blkno */ 134 134 int rmtblkcnt2; /* remote attr value block count */ 135 - unsigned char justcheck; /* T/F: check for ok with no space */ 136 - unsigned char rename; /* T/F: this is an atomic rename op */ 137 - unsigned char addname; /* T/F: this is an add operation */ 138 - unsigned char oknoent; /* T/F: ok to return ENOENT, else die */ 135 + int op_flags; /* operation flags */ 139 136 enum xfs_dacmp cmpresult; /* name compare result for lookups */ 140 137 } xfs_da_args_t; 138 + 139 + /* 140 + * Operation flags: 141 + */ 142 + #define XFS_DA_OP_JUSTCHECK 0x0001 /* check for ok with no space */ 143 + #define XFS_DA_OP_RENAME 0x0002 /* this is an atomic rename op */ 144 + #define XFS_DA_OP_ADDNAME 0x0004 /* this is an add operation */ 145 + #define XFS_DA_OP_OKNOENT 0x0008 /* lookup/add op, ENOENT ok, else die */ 141 146 142 147 /* 143 148 * Structure to describe buffer(s) for a block.
+8 -6
fs/xfs/xfs_dir2.c
··· 46 46 47 47 struct xfs_name xfs_name_dotdot = {"..", 2}; 48 48 49 + extern const struct xfs_nameops xfs_default_nameops; 50 + 49 51 void 50 52 xfs_dir_mount( 51 53 xfs_mount_t *mp) ··· 175 173 args.total = total; 176 174 args.whichfork = XFS_DATA_FORK; 177 175 args.trans = tp; 178 - args.justcheck = 0; 179 - args.addname = args.oknoent = 1; 176 + args.op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT; 180 177 181 178 if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) 182 179 rval = xfs_dir2_sf_addname(&args); ··· 216 215 args.dp = dp; 217 216 args.whichfork = XFS_DATA_FORK; 218 217 args.trans = tp; 219 - args.oknoent = 1; 218 + args.op_flags = XFS_DA_OP_OKNOENT; 220 219 args.cmpresult = XFS_CMP_DIFFERENT; 221 220 222 221 if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) ··· 268 267 args.total = total; 269 268 args.whichfork = XFS_DATA_FORK; 270 269 args.trans = tp; 271 - args.justcheck = args.addname = args.oknoent = 0; 270 + args.op_flags = 0; 272 271 273 272 if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) 274 273 rval = xfs_dir2_sf_removename(&args); ··· 351 350 args.total = total; 352 351 args.whichfork = XFS_DATA_FORK; 353 352 args.trans = tp; 354 - args.justcheck = args.addname = args.oknoent = 0; 353 + args.op_flags = 0; 355 354 356 355 if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) 357 356 rval = xfs_dir2_sf_replace(&args); ··· 395 394 args.dp = dp; 396 395 args.whichfork = XFS_DATA_FORK; 397 396 args.trans = tp; 398 - args.justcheck = args.addname = args.oknoent = 1; 397 + args.op_flags = XFS_DA_OP_JUSTCHECK | XFS_DA_OP_ADDNAME | 398 + XFS_DA_OP_OKNOENT; 399 399 400 400 if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) 401 401 rval = xfs_dir2_sf_addname(&args);
+5 -5
fs/xfs/xfs_dir2_block.c
··· 215 215 /* 216 216 * If this isn't a real add, we're done with the buffer. 217 217 */ 218 - if (args->justcheck) 218 + if (args->op_flags & XFS_DA_OP_JUSTCHECK) 219 219 xfs_da_brelse(tp, bp); 220 220 /* 221 221 * If we don't have space for the new entry & leaf ... ··· 225 225 * Not trying to actually do anything, or don't have 226 226 * a space reservation: return no-space. 227 227 */ 228 - if (args->justcheck || args->total == 0) 228 + if ((args->op_flags & XFS_DA_OP_JUSTCHECK) || args->total == 0) 229 229 return XFS_ERROR(ENOSPC); 230 230 /* 231 231 * Convert to the next larger format. ··· 240 240 /* 241 241 * Just checking, and it would work, so say so. 242 242 */ 243 - if (args->justcheck) 243 + if (args->op_flags & XFS_DA_OP_JUSTCHECK) 244 244 return 0; 245 245 needlog = needscan = 0; 246 246 /* ··· 674 674 else 675 675 high = mid - 1; 676 676 if (low > high) { 677 - ASSERT(args->oknoent); 677 + ASSERT(args->op_flags & XFS_DA_OP_OKNOENT); 678 678 xfs_da_brelse(tp, bp); 679 679 return XFS_ERROR(ENOENT); 680 680 } ··· 713 713 } while (++mid < be32_to_cpu(btp->count) && 714 714 be32_to_cpu(blp[mid].hashval) == hash); 715 715 716 - ASSERT(args->oknoent); 716 + ASSERT(args->op_flags & XFS_DA_OP_OKNOENT); 717 717 /* 718 718 * Here, we can only be doing a lookup (not a rename or replace). 719 719 * If a case-insensitive match was found earlier, return success.
+8 -7
fs/xfs/xfs_dir2_leaf.c
··· 263 263 * If we don't have enough free bytes but we can make enough 264 264 * by compacting out stale entries, we'll do that. 265 265 */ 266 - if ((char *)bestsp - (char *)&leaf->ents[be16_to_cpu(leaf->hdr.count)] < needbytes && 267 - be16_to_cpu(leaf->hdr.stale) > 1) { 266 + if ((char *)bestsp - (char *)&leaf->ents[be16_to_cpu(leaf->hdr.count)] < 267 + needbytes && be16_to_cpu(leaf->hdr.stale) > 1) { 268 268 compact = 1; 269 269 } 270 270 /* 271 271 * Otherwise if we don't have enough free bytes we need to 272 272 * convert to node form. 273 273 */ 274 - else if ((char *)bestsp - (char *)&leaf->ents[be16_to_cpu(leaf->hdr.count)] < 275 - needbytes) { 274 + else if ((char *)bestsp - (char *)&leaf->ents[be16_to_cpu( 275 + leaf->hdr.count)] < needbytes) { 276 276 /* 277 277 * Just checking or no space reservation, give up. 278 278 */ 279 - if (args->justcheck || args->total == 0) { 279 + if ((args->op_flags & XFS_DA_OP_JUSTCHECK) || 280 + args->total == 0) { 280 281 xfs_da_brelse(tp, lbp); 281 282 return XFS_ERROR(ENOSPC); 282 283 } ··· 302 301 * If just checking, then it will fit unless we needed to allocate 303 302 * a new data block. 304 303 */ 305 - if (args->justcheck) { 304 + if (args->op_flags & XFS_DA_OP_JUSTCHECK) { 306 305 xfs_da_brelse(tp, lbp); 307 306 return use_block == -1 ? XFS_ERROR(ENOSPC) : 0; 308 307 } ··· 1415 1414 cbp = dbp; 1416 1415 } 1417 1416 } 1418 - ASSERT(args->oknoent); 1417 + ASSERT(args->op_flags & XFS_DA_OP_OKNOENT); 1419 1418 /* 1420 1419 * Here, we can only be doing a lookup (not a rename or replace). 1421 1420 * If a case-insensitive match was found earlier, release the current
+9 -7
fs/xfs/xfs_dir2_node.c
··· 226 226 ASSERT(index == be16_to_cpu(leaf->hdr.count) || 227 227 be32_to_cpu(leaf->ents[index].hashval) >= args->hashval); 228 228 229 - if (args->justcheck) 229 + if (args->op_flags & XFS_DA_OP_JUSTCHECK) 230 230 return 0; 231 231 232 232 /* ··· 515 515 /* Didn't find any space */ 516 516 fi = -1; 517 517 out: 518 - ASSERT(args->oknoent); 518 + ASSERT(args->op_flags & XFS_DA_OP_OKNOENT); 519 519 if (curbp) { 520 520 /* Giving back a free block. */ 521 521 state->extravalid = 1; ··· 638 638 /* Didn't find an exact match. */ 639 639 error = ENOENT; 640 640 di = -1; 641 - ASSERT(index == be16_to_cpu(leaf->hdr.count) || args->oknoent); 641 + ASSERT(index == be16_to_cpu(leaf->hdr.count) || 642 + (args->op_flags & XFS_DA_OP_OKNOENT)); 642 643 out: 643 644 if (curbp) { 644 645 /* Giving back a data block. */ ··· 670 669 int *indexp, /* out: leaf entry index */ 671 670 xfs_da_state_t *state) /* state to fill in */ 672 671 { 673 - if (args->addname) 672 + if (args->op_flags & XFS_DA_OP_ADDNAME) 674 673 return xfs_dir2_leafn_lookup_for_addname(bp, args, indexp, 675 674 state); 676 675 return xfs_dir2_leafn_lookup_for_entry(bp, args, indexp, state); ··· 1384 1383 /* 1385 1384 * It worked, fix the hash values up the btree. 1386 1385 */ 1387 - if (!args->justcheck) 1386 + if (!(args->op_flags & XFS_DA_OP_JUSTCHECK)) 1388 1387 xfs_da_fixhashpath(state, &state->path); 1389 1388 } else { 1390 1389 /* ··· 1567 1566 /* 1568 1567 * Not allowed to allocate, return failure. 1569 1568 */ 1570 - if (args->justcheck || args->total == 0) { 1569 + if ((args->op_flags & XFS_DA_OP_JUSTCHECK) || 1570 + args->total == 0) { 1571 1571 /* 1572 1572 * Drop the freespace buffer unless it came from our 1573 1573 * caller. ··· 1714 1712 /* 1715 1713 * If just checking, we succeeded. 1716 1714 */ 1717 - if (args->justcheck) { 1715 + if (args->op_flags & XFS_DA_OP_JUSTCHECK) { 1718 1716 if ((fblk == NULL || fblk->bp == NULL) && fbp != NULL) 1719 1717 xfs_da_buf_done(fbp); 1720 1718 return 0;
+4 -4
fs/xfs/xfs_dir2_sf.c
··· 332 332 /* 333 333 * Just checking or no space reservation, it doesn't fit. 334 334 */ 335 - if (args->justcheck || args->total == 0) 335 + if ((args->op_flags & XFS_DA_OP_JUSTCHECK) || args->total == 0) 336 336 return XFS_ERROR(ENOSPC); 337 337 /* 338 338 * Convert to block form then add the name. ··· 345 345 /* 346 346 * Just checking, it fits. 347 347 */ 348 - if (args->justcheck) 348 + if (args->op_flags & XFS_DA_OP_JUSTCHECK) 349 349 return 0; 350 350 /* 351 351 * Do it the easy way - just add it at the end. ··· 869 869 return XFS_ERROR(EEXIST); 870 870 } 871 871 } 872 - ASSERT(args->oknoent); 872 + ASSERT(args->op_flags & XFS_DA_OP_OKNOENT); 873 873 /* 874 874 * Here, we can only be doing a lookup (not a rename or replace). 875 875 * If a case-insensitive match was found earlier, return "found". ··· 1071 1071 * Didn't find it. 1072 1072 */ 1073 1073 if (i == sfp->hdr.count) { 1074 - ASSERT(args->oknoent); 1074 + ASSERT(args->op_flags & XFS_DA_OP_OKNOENT); 1075 1075 #if XFS_BIG_INUMS 1076 1076 if (i8elevated) 1077 1077 xfs_dir2_sf_toino4(args);
+11 -9
fs/xfs/xfs_dir2_trace.c
··· 85 85 (void *)((unsigned long)(args->inumber >> 32)), 86 86 (void *)((unsigned long)(args->inumber & 0xFFFFFFFF)), 87 87 (void *)args->dp, (void *)args->trans, 88 - (void *)(unsigned long)args->justcheck, NULL, NULL); 88 + (void *)(unsigned long)(args->op_flags & XFS_DA_OP_JUSTCHECK), 89 + NULL, NULL); 89 90 } 90 91 91 92 void ··· 101 100 (void *)((unsigned long)(args->inumber >> 32)), 102 101 (void *)((unsigned long)(args->inumber & 0xFFFFFFFF)), 103 102 (void *)args->dp, (void *)args->trans, 104 - (void *)(unsigned long)args->justcheck, 103 + (void *)(unsigned long)(args->op_flags & XFS_DA_OP_JUSTCHECK), 105 104 (void *)(bp ? bp->bps[0] : NULL), NULL); 106 105 } 107 106 ··· 118 117 (void *)((unsigned long)(args->inumber >> 32)), 119 118 (void *)((unsigned long)(args->inumber & 0xFFFFFFFF)), 120 119 (void *)args->dp, (void *)args->trans, 121 - (void *)(unsigned long)args->justcheck, 120 + (void *)(unsigned long)(args->op_flags & XFS_DA_OP_JUSTCHECK), 122 121 (void *)(lbp ? lbp->bps[0] : NULL), 123 122 (void *)(dbp ? dbp->bps[0] : NULL)); 124 123 } ··· 158 157 (void *)((unsigned long)(args->inumber >> 32)), 159 158 (void *)((unsigned long)(args->inumber & 0xFFFFFFFF)), 160 159 (void *)args->dp, (void *)args->trans, 161 - (void *)(unsigned long)args->justcheck, (void *)(long)db, 162 - (void *)dbp); 160 + (void *)(unsigned long)(args->op_flags & XFS_DA_OP_JUSTCHECK), 161 + (void *)(long)db, (void *)dbp); 163 162 } 164 163 165 164 void ··· 174 173 (void *)((unsigned long)(args->inumber >> 32)), 175 174 (void *)((unsigned long)(args->inumber & 0xFFFFFFFF)), 176 175 (void *)args->dp, (void *)args->trans, 177 - (void *)(unsigned long)args->justcheck, 176 + (void *)(unsigned long)(args->op_flags & XFS_DA_OP_JUSTCHECK), 178 177 (void *)((unsigned long)(i >> 32)), 179 178 (void *)((unsigned long)(i & 0xFFFFFFFF))); 180 179 } ··· 191 190 (void *)((unsigned long)(args->inumber >> 32)), 192 191 (void *)((unsigned long)(args->inumber & 0xFFFFFFFF)), 193 192 (void *)args->dp, (void *)args->trans, 194 - (void *)(unsigned long)args->justcheck, (void *)(long)s, NULL); 193 + (void *)(unsigned long)(args->op_flags & XFS_DA_OP_JUSTCHECK), 194 + (void *)(long)s, NULL); 195 195 } 196 196 197 197 void ··· 210 208 (void *)((unsigned long)(args->inumber >> 32)), 211 209 (void *)((unsigned long)(args->inumber & 0xFFFFFFFF)), 212 210 (void *)args->dp, (void *)args->trans, 213 - (void *)(unsigned long)args->justcheck, (void *)(long)s, 214 - (void *)dbp); 211 + (void *)(unsigned long)(args->op_flags & XFS_DA_OP_JUSTCHECK), 212 + (void *)(long)s, (void *)dbp); 215 213 } 216 214 #endif /* XFS_DIR2_TRACE */