···54475447 struct xfs_btree_cur *cur,54485448 int *logflags) /* output */54495449{54505450- struct xfs_ifork *ifp;54515450 struct xfs_bmbt_irec got;54525451 struct xfs_bmbt_irec left;54535452 xfs_filblks_t blockcount;54545453 int error, i;5455545454565456- ifp = XFS_IFORK_PTR(ip, whichfork);54575455 xfs_bmbt_get_all(gotp, &got);54585456 xfs_bmbt_get_all(leftp, &left);54595457 blockcount = left.br_blockcount + got.br_blockcount;···54845486 error = xfs_bmbt_lookup_eq(cur, got.br_startoff, got.br_startblock,54855487 got.br_blockcount, &i);54865488 if (error)54875487- goto out_error;54885488- XFS_WANT_CORRUPTED_GOTO(i == 1, out_error);54895489+ return error;54905490+ XFS_WANT_CORRUPTED_RETURN(i == 1);5489549154905492 error = xfs_btree_delete(cur, &i);54915493 if (error)54925492- goto out_error;54935493- XFS_WANT_CORRUPTED_GOTO(i == 1, out_error);54945494+ return error;54955495+ XFS_WANT_CORRUPTED_RETURN(i == 1);5494549654955497 /* lookup and update size of the previous extent */54965498 error = xfs_bmbt_lookup_eq(cur, left.br_startoff, left.br_startblock,54975499 left.br_blockcount, &i);54985500 if (error)54995499- goto out_error;55005500- XFS_WANT_CORRUPTED_GOTO(i == 1, out_error);55015501+ return error;55025502+ XFS_WANT_CORRUPTED_RETURN(i == 1);5501550355025504 left.br_blockcount = blockcount;5503550555045504- error = xfs_bmbt_update(cur, left.br_startoff, left.br_startblock,55055505- left.br_blockcount, left.br_state);55065506- if (error)55075507- goto out_error;55085508-55095509- return 0;55105510-55115511-out_error:55125512- return error;55065506+ return xfs_bmbt_update(cur, left.br_startoff, left.br_startblock,55075507+ left.br_blockcount, left.br_state);55135508}5514550955155510/*···55325541 startoff = got.br_startoff - offset_shift_fsb;5533554255345543 /* delalloc extents should be prevented by caller */55355535- XFS_WANT_CORRUPTED_GOTO(!isnullstartblock(got.br_startblock),55365536- out_error);55445544+ XFS_WANT_CORRUPTED_RETURN(!isnullstartblock(got.br_startblock));5537554555385546 /*55395539- * If this is the first extent in the file, make sure there's enough55405540- * room at the start of the file and jump right to the shift as there's55415541- * no left extent to merge.55475547+ * Check for merge if we've got an extent to the left, otherwise make55485548+ * sure there's enough room at the start of the file for the shift.55425549 */55435543- if (*current_ext == 0) {55445544- if (got.br_startoff < offset_shift_fsb)55505550+ if (*current_ext) {55515551+ /* grab the left extent and check for a large enough hole */55525552+ leftp = xfs_iext_get_ext(ifp, *current_ext - 1);55535553+ xfs_bmbt_get_all(leftp, &left);55545554+55555555+ if (startoff < left.br_startoff + left.br_blockcount)55455556 return -EINVAL;55465546- goto shift_extent;55475547- }5548555755495549- /* grab the left extent and check for a large enough hole */55505550- leftp = xfs_iext_get_ext(ifp, *current_ext - 1);55515551- xfs_bmbt_get_all(leftp, &left);55525552-55535553- if (startoff < left.br_startoff + left.br_blockcount)55585558+ /* check whether to merge the extent or shift it down */55595559+ if (xfs_bmse_can_merge(&left, &got, offset_shift_fsb)) {55605560+ return xfs_bmse_merge(ip, whichfork, offset_shift_fsb,55615561+ *current_ext, gotp, leftp, cur,55625562+ logflags);55635563+ }55645564+ } else if (got.br_startoff < offset_shift_fsb)55545565 return -EINVAL;5555556655565556- /* check whether to merge the extent or shift it down */55575557- if (!xfs_bmse_can_merge(&left, &got, offset_shift_fsb))55585558- goto shift_extent;55595559-55605560- return xfs_bmse_merge(ip, whichfork, offset_shift_fsb, *current_ext,55615561- gotp, leftp, cur, logflags);55625562-55635563-shift_extent:55645567 /*55655568 * Increment the extent index for the next iteration, update the start55665569 * offset of the in-core extent and update the btree if applicable.···55715586 got.br_blockcount, &i);55725587 if (error)55735588 return error;55745574- XFS_WANT_CORRUPTED_GOTO(i == 1, out_error);55895589+ XFS_WANT_CORRUPTED_RETURN(i == 1);5575559055765591 got.br_startoff = startoff;55775592 return xfs_bmbt_update(cur, got.br_startoff, got.br_startblock,55785593 got.br_blockcount, got.br_state);55795579-55805580-out_error:55815581- return error;55825594}5583559555845596/*
···34343535struct xfs_name xfs_name_dotdot = { (unsigned char *)"..", 2, XFS_DIR3_FT_DIR };36363737+/*3838+ * @mode, if set, indicates that the type field needs to be set up.3939+ * This uses the transformation from file mode to DT_* as defined in linux/fs.h4040+ * for file type specification. This will be propagated into the directory4141+ * structure if appropriate for the given operation and filesystem config.4242+ */4343+const unsigned char xfs_mode_to_ftype[S_IFMT >> S_SHIFT] = {4444+ [0] = XFS_DIR3_FT_UNKNOWN,4545+ [S_IFREG >> S_SHIFT] = XFS_DIR3_FT_REG_FILE,4646+ [S_IFDIR >> S_SHIFT] = XFS_DIR3_FT_DIR,4747+ [S_IFCHR >> S_SHIFT] = XFS_DIR3_FT_CHRDEV,4848+ [S_IFBLK >> S_SHIFT] = XFS_DIR3_FT_BLKDEV,4949+ [S_IFIFO >> S_SHIFT] = XFS_DIR3_FT_FIFO,5050+ [S_IFSOCK >> S_SHIFT] = XFS_DIR3_FT_SOCK,5151+ [S_IFLNK >> S_SHIFT] = XFS_DIR3_FT_SYMLINK,5252+};37533854/*3955 * ASCII case-insensitive (ie. A-Z) support for directories that was
+140
fs/xfs/libxfs/xfs_dir2.h
···3232extern struct xfs_name xfs_name_dotdot;33333434/*3535+ * directory filetype conversion tables.3636+ */3737+#define S_SHIFT 123838+extern const unsigned char xfs_mode_to_ftype[];3939+4040+/*3541 * directory operations vector for encode/decode routines3642 */3743struct xfs_dir_ops {···182176extern const struct xfs_buf_ops xfs_dir3_leaf1_buf_ops;183177extern const struct xfs_buf_ops xfs_dir3_free_buf_ops;184178extern const struct xfs_buf_ops xfs_dir3_data_buf_ops;179179+180180+/*181181+ * Directory offset/block conversion functions.182182+ *183183+ * DB blocks here are logical directory block numbers, not filesystem blocks.184184+ */185185+186186+/*187187+ * Convert dataptr to byte in file space188188+ */189189+static inline xfs_dir2_off_t190190+xfs_dir2_dataptr_to_byte(xfs_dir2_dataptr_t dp)191191+{192192+ return (xfs_dir2_off_t)dp << XFS_DIR2_DATA_ALIGN_LOG;193193+}194194+195195+/*196196+ * Convert byte in file space to dataptr. It had better be aligned.197197+ */198198+static inline xfs_dir2_dataptr_t199199+xfs_dir2_byte_to_dataptr(xfs_dir2_off_t by)200200+{201201+ return (xfs_dir2_dataptr_t)(by >> XFS_DIR2_DATA_ALIGN_LOG);202202+}203203+204204+/*205205+ * Convert byte in space to (DB) block206206+ */207207+static inline xfs_dir2_db_t208208+xfs_dir2_byte_to_db(struct xfs_da_geometry *geo, xfs_dir2_off_t by)209209+{210210+ return (xfs_dir2_db_t)(by >> geo->blklog);211211+}212212+213213+/*214214+ * Convert dataptr to a block number215215+ */216216+static inline xfs_dir2_db_t217217+xfs_dir2_dataptr_to_db(struct xfs_da_geometry *geo, xfs_dir2_dataptr_t dp)218218+{219219+ return xfs_dir2_byte_to_db(geo, xfs_dir2_dataptr_to_byte(dp));220220+}221221+222222+/*223223+ * Convert byte in space to offset in a block224224+ */225225+static inline xfs_dir2_data_aoff_t226226+xfs_dir2_byte_to_off(struct xfs_da_geometry *geo, xfs_dir2_off_t by)227227+{228228+ return (xfs_dir2_data_aoff_t)(by & (geo->blksize - 1));229229+}230230+231231+/*232232+ * Convert dataptr to a byte offset in a block233233+ */234234+static inline xfs_dir2_data_aoff_t235235+xfs_dir2_dataptr_to_off(struct xfs_da_geometry *geo, xfs_dir2_dataptr_t dp)236236+{237237+ return xfs_dir2_byte_to_off(geo, xfs_dir2_dataptr_to_byte(dp));238238+}239239+240240+/*241241+ * Convert block and offset to byte in space242242+ */243243+static inline xfs_dir2_off_t244244+xfs_dir2_db_off_to_byte(struct xfs_da_geometry *geo, xfs_dir2_db_t db,245245+ xfs_dir2_data_aoff_t o)246246+{247247+ return ((xfs_dir2_off_t)db << geo->blklog) + o;248248+}249249+250250+/*251251+ * Convert block (DB) to block (dablk)252252+ */253253+static inline xfs_dablk_t254254+xfs_dir2_db_to_da(struct xfs_da_geometry *geo, xfs_dir2_db_t db)255255+{256256+ return (xfs_dablk_t)(db << (geo->blklog - geo->fsblog));257257+}258258+259259+/*260260+ * Convert byte in space to (DA) block261261+ */262262+static inline xfs_dablk_t263263+xfs_dir2_byte_to_da(struct xfs_da_geometry *geo, xfs_dir2_off_t by)264264+{265265+ return xfs_dir2_db_to_da(geo, xfs_dir2_byte_to_db(geo, by));266266+}267267+268268+/*269269+ * Convert block and offset to dataptr270270+ */271271+static inline xfs_dir2_dataptr_t272272+xfs_dir2_db_off_to_dataptr(struct xfs_da_geometry *geo, xfs_dir2_db_t db,273273+ xfs_dir2_data_aoff_t o)274274+{275275+ return xfs_dir2_byte_to_dataptr(xfs_dir2_db_off_to_byte(geo, db, o));276276+}277277+278278+/*279279+ * Convert block (dablk) to block (DB)280280+ */281281+static inline xfs_dir2_db_t282282+xfs_dir2_da_to_db(struct xfs_da_geometry *geo, xfs_dablk_t da)283283+{284284+ return (xfs_dir2_db_t)(da >> (geo->blklog - geo->fsblog));285285+}286286+287287+/*288288+ * Convert block (dablk) to byte offset in space289289+ */290290+static inline xfs_dir2_off_t291291+xfs_dir2_da_to_byte(struct xfs_da_geometry *geo, xfs_dablk_t da)292292+{293293+ return xfs_dir2_db_off_to_byte(geo, xfs_dir2_da_to_db(geo, da), 0);294294+}295295+296296+/*297297+ * Directory tail pointer accessor functions. Based on block geometry.298298+ */299299+static inline struct xfs_dir2_block_tail *300300+xfs_dir2_block_tail_p(struct xfs_da_geometry *geo, struct xfs_dir2_data_hdr *hdr)301301+{302302+ return ((struct xfs_dir2_block_tail *)303303+ ((char *)hdr + geo->blksize)) - 1;304304+}305305+306306+static inline struct xfs_dir2_leaf_tail *307307+xfs_dir2_leaf_tail_p(struct xfs_da_geometry *geo, struct xfs_dir2_leaf *lp)308308+{309309+ return (struct xfs_dir2_leaf_tail *)310310+ ((char *)lp + geo->blksize -311311+ sizeof(struct xfs_dir2_leaf_tail));312312+}185313186314#endif /* __XFS_DIR2_H__ */
-8
fs/xfs/libxfs/xfs_dir2_block.c
···350350 int low; /* low index for binary srch */351351 int lowstale; /* low stale index */352352 int mid=0; /* midpoint for binary srch */353353- xfs_mount_t *mp; /* filesystem mount point */354353 int needlog; /* need to log header */355354 int needscan; /* need to rescan freespace */356355 __be16 *tagp; /* pointer to tag value */···359360360361 dp = args->dp;361362 tp = args->trans;362362- mp = dp->i_mount;363363364364 /* Read the (one and only) directory block into bp. */365365 error = xfs_dir3_block_read(tp, dp, &bp);···613615 xfs_inode_t *dp; /* incore inode */614616 int ent; /* entry index */615617 int error; /* error return value */616616- xfs_mount_t *mp; /* filesystem mount point */617618618619 trace_xfs_dir2_block_lookup(args);619620···623626 if ((error = xfs_dir2_block_lookup_int(args, &bp, &ent)))624627 return error;625628 dp = args->dp;626626- mp = dp->i_mount;627629 hdr = bp->b_addr;628630 xfs_dir3_data_check(dp, bp);629631 btp = xfs_dir2_block_tail_p(args->geo, hdr);···763767 xfs_inode_t *dp; /* incore inode */764768 int ent; /* block leaf entry index */765769 int error; /* error return value */766766- xfs_mount_t *mp; /* filesystem mount point */767770 int needlog; /* need to log block header */768771 int needscan; /* need to fixup bestfree */769772 xfs_dir2_sf_hdr_t sfh; /* shortform header */···780785 }781786 dp = args->dp;782787 tp = args->trans;783783- mp = dp->i_mount;784788 hdr = bp->b_addr;785789 btp = xfs_dir2_block_tail_p(args->geo, hdr);786790 blp = xfs_dir2_block_leaf_p(btp);···843849 xfs_inode_t *dp; /* incore inode */844850 int ent; /* leaf entry index */845851 int error; /* error return value */846846- xfs_mount_t *mp; /* filesystem mount point */847852848853 trace_xfs_dir2_block_replace(args);849854···854861 return error;855862 }856863 dp = args->dp;857857- mp = dp->i_mount;858864 hdr = bp->b_addr;859865 btp = xfs_dir2_block_tail_p(args->geo, hdr);860866 blp = xfs_dir2_block_leaf_p(btp);
-10
fs/xfs/libxfs/xfs_dir2_leaf.c
···382382 xfs_dir2_db_t ldb; /* leaf block's bno */383383 xfs_dir2_leaf_t *leaf; /* leaf structure */384384 xfs_dir2_leaf_tail_t *ltp; /* leaf's tail */385385- xfs_mount_t *mp; /* filesystem mount point */386385 int needlog; /* need to log block header */387386 int needscan; /* need to rescan bestfree */388387 xfs_trans_t *tp; /* transaction pointer */···392393 trace_xfs_dir2_block_to_leaf(args);393394394395 dp = args->dp;395395- mp = dp->i_mount;396396 tp = args->trans;397397 /*398398 * Add the leaf block to the inode.···622624 int lfloghigh; /* high leaf logging index */623625 int lowstale; /* index of prev stale leaf */624626 xfs_dir2_leaf_tail_t *ltp; /* leaf tail pointer */625625- xfs_mount_t *mp; /* filesystem mount point */626627 int needbytes; /* leaf block bytes needed */627628 int needlog; /* need to log data header */628629 int needscan; /* need to rescan data free */···636639637640 dp = args->dp;638641 tp = args->trans;639639- mp = dp->i_mount;640642641643 error = xfs_dir3_leaf_read(tp, dp, args->geo->leafblk, -1, &lbp);642644 if (error)···13501354 xfs_dir2_leaf_t *leaf; /* leaf structure */13511355 xfs_dir2_leaf_entry_t *lep; /* leaf entry */13521356 xfs_dir2_leaf_tail_t *ltp; /* leaf tail structure */13531353- xfs_mount_t *mp; /* filesystem mount point */13541357 int needlog; /* need to log data header */13551358 int needscan; /* need to rescan data frees */13561359 xfs_dir2_data_off_t oldbest; /* old value of best free */13571357- xfs_trans_t *tp; /* transaction pointer */13581360 struct xfs_dir2_data_free *bf; /* bestfree table */13591361 struct xfs_dir2_leaf_entry *ents;13601362 struct xfs_dir3_icleaf_hdr leafhdr;···13661372 return error;13671373 }13681374 dp = args->dp;13691369- tp = args->trans;13701370- mp = dp->i_mount;13711375 leaf = lbp->b_addr;13721376 hdr = dbp->b_addr;13731377 xfs_dir3_data_check(dp, dbp);···15971605 int error; /* error return value */15981606 xfs_dir2_leaf_t *leaf; /* leaf structure */15991607 xfs_dir2_leaf_tail_t *ltp; /* leaf tail structure */16001600- xfs_mount_t *mp; /* filesystem mount point */16011608 xfs_trans_t *tp; /* transaction pointer */1602160916031610 dp = args->dp;16041604- mp = dp->i_mount;16051611 tp = args->trans;16061612 /*16071613 * Read the offending data block. We need its buffer.
-12
fs/xfs/libxfs/xfs_dir2_node.c
···295295 int i; /* leaf freespace index */296296 xfs_dir2_leaf_t *leaf; /* leaf structure */297297 xfs_dir2_leaf_tail_t *ltp; /* leaf tail structure */298298- xfs_mount_t *mp; /* filesystem mount point */299298 int n; /* count of live freespc ents */300299 xfs_dir2_data_off_t off; /* freespace entry value */301300 __be16 *to; /* pointer to freespace entry */···304305 trace_xfs_dir2_leaf_to_node(args);305306306307 dp = args->dp;307307- mp = dp->i_mount;308308 tp = args->trans;309309 /*310310 * Add a freespace block to the directory.···383385 int lfloghigh; /* high leaf entry logging */384386 int lfloglow; /* low leaf entry logging */385387 int lowstale; /* previous stale entry */386386- xfs_mount_t *mp; /* filesystem mount point */387387- xfs_trans_t *tp; /* transaction pointer */388388 struct xfs_dir3_icleaf_hdr leafhdr;389389 struct xfs_dir2_leaf_entry *ents;390390391391 trace_xfs_dir2_leafn_add(args, index);392392393393 dp = args->dp;394394- mp = dp->i_mount;395395- tp = args->trans;396394 leaf = bp->b_addr;397395 dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);398396 ents = dp->d_ops->leaf_ents_p(leaf);···11621168 xfs_dir2_leaf_entry_t *lep; /* leaf entry */11631169 int longest; /* longest data free entry */11641170 int off; /* data block entry offset */11651165- xfs_mount_t *mp; /* filesystem mount point */11661171 int needlog; /* need to log data header */11671172 int needscan; /* need to rescan data frees */11681173 xfs_trans_t *tp; /* transaction pointer */···1173118011741181 dp = args->dp;11751182 tp = args->trans;11761176- mp = dp->i_mount;11771183 leaf = bp->b_addr;11781184 dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);11791185 ents = dp->d_ops->leaf_ents_p(leaf);···13131321 xfs_da_args_t *args; /* operation arguments */13141322 xfs_dablk_t blkno; /* new leaf block number */13151323 int error; /* error return value */13161316- xfs_mount_t *mp; /* filesystem mount point */13171324 struct xfs_inode *dp;1318132513191326 /*···13201329 */13211330 args = state->args;13221331 dp = args->dp;13231323- mp = dp->i_mount;13241332 ASSERT(oldblk->magic == XFS_DIR2_LEAFN_MAGIC);13251333 error = xfs_da_grow_inode(args, &blkno);13261334 if (error) {···22192229 xfs_inode_t *dp; /* incore directory inode */22202230 int error; /* error return code */22212231 xfs_dir2_free_t *free; /* freespace structure */22222222- xfs_mount_t *mp; /* filesystem mount point */22232232 xfs_trans_t *tp; /* transaction pointer */22242233 struct xfs_dir3_icfree_hdr freehdr;2225223422262235 dp = args->dp;22272227- mp = dp->i_mount;22282236 tp = args->trans;22292237 /*22302238 * Read the freespace block.
-140
fs/xfs/libxfs/xfs_dir2_priv.h
···20202121struct dir_context;22222323-/*2424- * Directory offset/block conversion functions.2525- *2626- * DB blocks here are logical directory block numbers, not filesystem blocks.2727- */2828-2929-/*3030- * Convert dataptr to byte in file space3131- */3232-static inline xfs_dir2_off_t3333-xfs_dir2_dataptr_to_byte(xfs_dir2_dataptr_t dp)3434-{3535- return (xfs_dir2_off_t)dp << XFS_DIR2_DATA_ALIGN_LOG;3636-}3737-3838-/*3939- * Convert byte in file space to dataptr. It had better be aligned.4040- */4141-static inline xfs_dir2_dataptr_t4242-xfs_dir2_byte_to_dataptr(xfs_dir2_off_t by)4343-{4444- return (xfs_dir2_dataptr_t)(by >> XFS_DIR2_DATA_ALIGN_LOG);4545-}4646-4747-/*4848- * Convert byte in space to (DB) block4949- */5050-static inline xfs_dir2_db_t5151-xfs_dir2_byte_to_db(struct xfs_da_geometry *geo, xfs_dir2_off_t by)5252-{5353- return (xfs_dir2_db_t)(by >> geo->blklog);5454-}5555-5656-/*5757- * Convert dataptr to a block number5858- */5959-static inline xfs_dir2_db_t6060-xfs_dir2_dataptr_to_db(struct xfs_da_geometry *geo, xfs_dir2_dataptr_t dp)6161-{6262- return xfs_dir2_byte_to_db(geo, xfs_dir2_dataptr_to_byte(dp));6363-}6464-6565-/*6666- * Convert byte in space to offset in a block6767- */6868-static inline xfs_dir2_data_aoff_t6969-xfs_dir2_byte_to_off(struct xfs_da_geometry *geo, xfs_dir2_off_t by)7070-{7171- return (xfs_dir2_data_aoff_t)(by & (geo->blksize - 1));7272-}7373-7474-/*7575- * Convert dataptr to a byte offset in a block7676- */7777-static inline xfs_dir2_data_aoff_t7878-xfs_dir2_dataptr_to_off(struct xfs_da_geometry *geo, xfs_dir2_dataptr_t dp)7979-{8080- return xfs_dir2_byte_to_off(geo, xfs_dir2_dataptr_to_byte(dp));8181-}8282-8383-/*8484- * Convert block and offset to byte in space8585- */8686-static inline xfs_dir2_off_t8787-xfs_dir2_db_off_to_byte(struct xfs_da_geometry *geo, xfs_dir2_db_t db,8888- xfs_dir2_data_aoff_t o)8989-{9090- return ((xfs_dir2_off_t)db << geo->blklog) + o;9191-}9292-9393-/*9494- * Convert block (DB) to block (dablk)9595- */9696-static inline xfs_dablk_t9797-xfs_dir2_db_to_da(struct xfs_da_geometry *geo, xfs_dir2_db_t db)9898-{9999- return (xfs_dablk_t)(db << (geo->blklog - geo->fsblog));100100-}101101-102102-/*103103- * Convert byte in space to (DA) block104104- */105105-static inline xfs_dablk_t106106-xfs_dir2_byte_to_da(struct xfs_da_geometry *geo, xfs_dir2_off_t by)107107-{108108- return xfs_dir2_db_to_da(geo, xfs_dir2_byte_to_db(geo, by));109109-}110110-111111-/*112112- * Convert block and offset to dataptr113113- */114114-static inline xfs_dir2_dataptr_t115115-xfs_dir2_db_off_to_dataptr(struct xfs_da_geometry *geo, xfs_dir2_db_t db,116116- xfs_dir2_data_aoff_t o)117117-{118118- return xfs_dir2_byte_to_dataptr(xfs_dir2_db_off_to_byte(geo, db, o));119119-}120120-121121-/*122122- * Convert block (dablk) to block (DB)123123- */124124-static inline xfs_dir2_db_t125125-xfs_dir2_da_to_db(struct xfs_da_geometry *geo, xfs_dablk_t da)126126-{127127- return (xfs_dir2_db_t)(da >> (geo->blklog - geo->fsblog));128128-}129129-130130-/*131131- * Convert block (dablk) to byte offset in space132132- */133133-static inline xfs_dir2_off_t134134-xfs_dir2_da_to_byte(struct xfs_da_geometry *geo, xfs_dablk_t da)135135-{136136- return xfs_dir2_db_off_to_byte(geo, xfs_dir2_da_to_db(geo, da), 0);137137-}138138-139139-/*140140- * Directory tail pointer accessor functions. Based on block geometry.141141- */142142-static inline struct xfs_dir2_block_tail *143143-xfs_dir2_block_tail_p(struct xfs_da_geometry *geo, struct xfs_dir2_data_hdr *hdr)144144-{145145- return ((struct xfs_dir2_block_tail *)146146- ((char *)hdr + geo->blksize)) - 1;147147-}148148-149149-static inline struct xfs_dir2_leaf_tail *150150-xfs_dir2_leaf_tail_p(struct xfs_da_geometry *geo, struct xfs_dir2_leaf *lp)151151-{152152- return (struct xfs_dir2_leaf_tail *)153153- ((char *)lp + geo->blksize -154154- sizeof(struct xfs_dir2_leaf_tail));155155-}156156-15723/* xfs_dir2.c */15824extern int xfs_dir_ino_validate(struct xfs_mount *mp, xfs_ino_t ino);15925extern int xfs_dir2_grow_inode(struct xfs_da_args *args, int space,16026 xfs_dir2_db_t *dbp);16127extern int xfs_dir_cilookup_result(struct xfs_da_args *args,16228 const unsigned char *name, int len);163163-164164-#define S_SHIFT 12165165-extern const unsigned char xfs_mode_to_ftype[];166166-167167-extern unsigned char xfs_dir3_get_dtype(struct xfs_mount *mp,168168- __uint8_t filetype);169291703017131/* xfs_dir2_block.c */
-10
fs/xfs/libxfs/xfs_dir2_sf.c
···452452 xfs_dir2_sf_hdr_t *oldsfp; /* original shortform dir */453453 xfs_dir2_sf_entry_t *sfep; /* entry in new dir */454454 xfs_dir2_sf_hdr_t *sfp; /* new shortform dir */455455- struct xfs_mount *mp;456455457456 /*458457 * Copy the old directory to the stack buffer.459458 */460459 dp = args->dp;461461- mp = dp->i_mount;462460463461 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;464462 old_isize = (int)dp->i_d.di_size;···537539 xfs_inode_t *dp; /* incore directory inode */538540 int holefit; /* found hole it will fit in */539541 int i; /* entry number */540540- xfs_mount_t *mp; /* filesystem mount point */541542 xfs_dir2_data_aoff_t offset; /* data block offset */542543 xfs_dir2_sf_entry_t *sfep; /* shortform entry */543544 xfs_dir2_sf_hdr_t *sfp; /* shortform structure */···544547 int used; /* data bytes used */545548546549 dp = args->dp;547547- mp = dp->i_mount;548550549551 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;550552 size = dp->d_ops->data_entsize(args->namelen);···609613 int offset; /* data offset */610614 xfs_dir2_sf_entry_t *sfep; /* shortform dir entry */611615 xfs_dir2_sf_hdr_t *sfp; /* shortform structure */612612- struct xfs_mount *mp;613616614617 dp = args->dp;615615- mp = dp->i_mount;616618617619 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;618620 offset = dp->d_ops->data_first_offset;···10071013 int oldsize; /* old inode size */10081014 xfs_dir2_sf_entry_t *sfep; /* new sf entry */10091015 xfs_dir2_sf_hdr_t *sfp; /* new sf directory */10101010- struct xfs_mount *mp;1011101610121017 trace_xfs_dir2_sf_toino4(args);1013101810141019 dp = args->dp;10151015- mp = dp->i_mount;1016102010171021 /*10181022 * Copy the old directory to the buffer.···10831091 int oldsize; /* old inode size */10841092 xfs_dir2_sf_entry_t *sfep; /* new sf entry */10851093 xfs_dir2_sf_hdr_t *sfp; /* new sf directory */10861086- struct xfs_mount *mp;1087109410881095 trace_xfs_dir2_sf_toino8(args);1089109610901097 dp = args->dp;10911091- mp = dp->i_mount;1092109810931099 /*10941100 * Copy the old directory to the buffer.
+24-10
fs/xfs/libxfs/xfs_ialloc.c
···4545 */4646static inline int4747xfs_ialloc_cluster_alignment(4848- xfs_alloc_arg_t *args)4848+ struct xfs_mount *mp)4949{5050- if (xfs_sb_version_hasalign(&args->mp->m_sb) &&5151- args->mp->m_sb.sb_inoalignmt >=5252- XFS_B_TO_FSBT(args->mp, args->mp->m_inode_cluster_size))5353- return args->mp->m_sb.sb_inoalignmt;5050+ if (xfs_sb_version_hasalign(&mp->m_sb) &&5151+ mp->m_sb.sb_inoalignmt >=5252+ XFS_B_TO_FSBT(mp, mp->m_inode_cluster_size))5353+ return mp->m_sb.sb_inoalignmt;5454 return 1;5555}5656···409409 * but not to use them in the actual exact allocation.410410 */411411 args.alignment = 1;412412- args.minalignslop = xfs_ialloc_cluster_alignment(&args) - 1;412412+ args.minalignslop = xfs_ialloc_cluster_alignment(args.mp) - 1;413413414414 /* Allow space for the inode btree to split. */415415 args.minleft = args.mp->m_in_maxlevels - 1;···445445 args.alignment = args.mp->m_dalign;446446 isaligned = 1;447447 } else448448- args.alignment = xfs_ialloc_cluster_alignment(&args);448448+ args.alignment = xfs_ialloc_cluster_alignment(args.mp);449449 /*450450 * Need to figure out where to allocate the inode blocks.451451 * Ideally they should be spaced out through the a.g.···474474 args.type = XFS_ALLOCTYPE_NEAR_BNO;475475 args.agbno = be32_to_cpu(agi->agi_root);476476 args.fsbno = XFS_AGB_TO_FSB(args.mp, agno, args.agbno);477477- args.alignment = xfs_ialloc_cluster_alignment(&args);477477+ args.alignment = xfs_ialloc_cluster_alignment(args.mp);478478 if ((error = xfs_alloc_vextent(&args)))479479 return error;480480 }···629629 }630630631631 /*632632- * Is there enough free space for the file plus a block of633633- * inodes? (if we need to allocate some)?632632+ * Check that there is enough free space for the file plus a633633+ * chunk of inodes if we need to allocate some. If this is the634634+ * first pass across the AGs, take into account the potential635635+ * space needed for alignment of inode chunks when checking the636636+ * longest contiguous free space in the AG - this prevents us637637+ * from getting ENOSPC because we have free space larger than638638+ * m_ialloc_blks but alignment constraints prevent us from using639639+ * it.640640+ *641641+ * If we can't find an AG with space for full alignment slack to642642+ * be taken into account, we must be near ENOSPC in all AGs.643643+ * Hence we don't include alignment for the second pass and so644644+ * if we fail allocation due to alignment issues then it is most645645+ * likely a real ENOSPC condition.634646 */635647 ineed = mp->m_ialloc_blks;648648+ if (flags && ineed > 1)649649+ ineed += xfs_ialloc_cluster_alignment(mp);636650 longest = pag->pagf_longest;637651 if (!longest)638652 longest = pag->pagf_flcount > 0;
+10-3
fs/xfs/xfs_buf.c
···10411041 struct work_struct *work)10421042{10431043 struct xfs_buf *bp =10441044- container_of(work, xfs_buf_t, b_iodone_work);10441044+ container_of(work, xfs_buf_t, b_ioend_work);1045104510461046 xfs_buf_ioend(bp);10471047}···10501050xfs_buf_ioend_async(10511051 struct xfs_buf *bp)10521052{10531053- INIT_WORK(&bp->b_iodone_work, xfs_buf_ioend_work);10541054- queue_work(bp->b_target->bt_mount->m_buf_workqueue, &bp->b_iodone_work);10531053+ INIT_WORK(&bp->b_ioend_work, xfs_buf_ioend_work);10541054+ queue_work(bp->b_ioend_wq, &bp->b_ioend_work);10551055}1056105610571057void···12191219 * left over from previous use of the buffer (e.g. failed readahead).12201220 */12211221 bp->b_error = 0;12221222+12231223+ /*12241224+ * Initialize the I/O completion workqueue if we haven't yet or the12251225+ * submitter has not opted to specify a custom one.12261226+ */12271227+ if (!bp->b_ioend_wq)12281228+ bp->b_ioend_wq = bp->b_target->bt_mount->m_buf_workqueue;1222122912231230 if (bp->b_flags & XBF_WRITE) {12241231 if (bp->b_flags & XBF_SYNCIO)
···4141 DT_FIFO, DT_SOCK, DT_LNK, DT_WHT,4242};43434444-unsigned char4444+static unsigned char4545xfs_dir3_get_dtype(4646 struct xfs_mount *mp,4747 __uint8_t filetype)···54545555 return xfs_dir3_filetype_table[filetype];5656}5757-/*5858- * @mode, if set, indicates that the type field needs to be set up.5959- * This uses the transformation from file mode to DT_* as defined in linux/fs.h6060- * for file type specification. This will be propagated into the directory6161- * structure if appropriate for the given operation and filesystem config.6262- */6363-const unsigned char xfs_mode_to_ftype[S_IFMT >> S_SHIFT] = {6464- [0] = XFS_DIR3_FT_UNKNOWN,6565- [S_IFREG >> S_SHIFT] = XFS_DIR3_FT_REG_FILE,6666- [S_IFDIR >> S_SHIFT] = XFS_DIR3_FT_DIR,6767- [S_IFCHR >> S_SHIFT] = XFS_DIR3_FT_CHRDEV,6868- [S_IFBLK >> S_SHIFT] = XFS_DIR3_FT_BLKDEV,6969- [S_IFIFO >> S_SHIFT] = XFS_DIR3_FT_FIFO,7070- [S_IFSOCK >> S_SHIFT] = XFS_DIR3_FT_SOCK,7171- [S_IFLNK >> S_SHIFT] = XFS_DIR3_FT_SYMLINK,7272-};73577458STATIC int7559xfs_dir2_sf_getdents(
···348348 int *done) /* 1 if there are more stats to get */349349{350350 xfs_buf_t *agbp; /* agi header buffer */351351- xfs_agi_t *agi; /* agi header data */352351 xfs_agino_t agino; /* inode # in allocation group */353352 xfs_agnumber_t agno; /* allocation group number */354353 xfs_btree_cur_t *cur; /* btree cursor for ialloc btree */···398399 error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp);399400 if (error)400401 break;401401- agi = XFS_BUF_TO_AGI(agbp);402402 /*403403 * Allocate and initialize a btree cursor for ialloc btree.404404 */
+4
fs/xfs/xfs_log.c
···18061806 XFS_BUF_ZEROFLAGS(bp);18071807 XFS_BUF_ASYNC(bp);18081808 bp->b_flags |= XBF_SYNCIO;18091809+ /* use high priority completion wq */18101810+ bp->b_ioend_wq = log->l_mp->m_log_workqueue;1809181118101812 if (log->l_mp->m_flags & XFS_MOUNT_BARRIER) {18111813 bp->b_flags |= XBF_FUA;···18561854 bp->b_flags |= XBF_SYNCIO;18571855 if (log->l_mp->m_flags & XFS_MOUNT_BARRIER)18581856 bp->b_flags |= XBF_FUA;18571857+ /* use high priority completion wq */18581858+ bp->b_ioend_wq = log->l_mp->m_log_workqueue;1859185918601860 ASSERT(XFS_BUF_ADDR(bp) <= log->l_logBBsize-1);18611861 ASSERT(XFS_BUF_ADDR(bp) + BTOBB(count) <= log->l_logBBsize);
···227227 return bp;228228}229229230230-#ifdef DEBUG231231-xfs_buftarg_t *xfs_error_target;232232-int xfs_do_error;233233-int xfs_req_num;234234-int xfs_error_mod = 33;235235-#endif236236-237230/*238231 * Get and lock the buffer for the caller if it is not already239232 * locked within the given transaction. If it has not yet been···248255 struct xfs_buf **bpp,249256 const struct xfs_buf_ops *ops)250257{251251- xfs_buf_t *bp;252252- xfs_buf_log_item_t *bip;258258+ struct xfs_buf *bp = NULL;259259+ struct xfs_buf_log_item *bip;253260 int error;254261255262 *bpp = NULL;256256- if (!tp) {257257- bp = xfs_buf_read_map(target, map, nmaps, flags, ops);258258- if (!bp)259259- return (flags & XBF_TRYLOCK) ?260260- -EAGAIN : -ENOMEM;261261-262262- if (bp->b_error) {263263- error = bp->b_error;264264- xfs_buf_ioerror_alert(bp, __func__);265265- XFS_BUF_UNDONE(bp);266266- xfs_buf_stale(bp);267267- xfs_buf_relse(bp);268268-269269- /* bad CRC means corrupted metadata */270270- if (error == -EFSBADCRC)271271- error = -EFSCORRUPTED;272272- return error;273273- }274274-#ifdef DEBUG275275- if (xfs_do_error) {276276- if (xfs_error_target == target) {277277- if (((xfs_req_num++) % xfs_error_mod) == 0) {278278- xfs_buf_relse(bp);279279- xfs_debug(mp, "Returning error!");280280- return -EIO;281281- }282282- }283283- }284284-#endif285285- if (XFS_FORCED_SHUTDOWN(mp))286286- goto shutdown_abort;287287- *bpp = bp;288288- return 0;289289- }290290-291263 /*292264 * If we find the buffer in the cache with this transaction293265 * pointer in its b_fsprivate2 field, then we know we already···261303 * If the buffer is not yet read in, then we read it in, increment262304 * the lock recursion count, and return it to the caller.263305 */264264- bp = xfs_trans_buf_item_match(tp, target, map, nmaps);265265- if (bp != NULL) {306306+ if (tp)307307+ bp = xfs_trans_buf_item_match(tp, target, map, nmaps);308308+ if (bp) {266309 ASSERT(xfs_buf_islocked(bp));267310 ASSERT(bp->b_transp == tp);268311 ASSERT(bp->b_fspriv != NULL);269312 ASSERT(!bp->b_error);270270- if (!(XFS_BUF_ISDONE(bp))) {271271- trace_xfs_trans_read_buf_io(bp, _RET_IP_);272272- ASSERT(!XFS_BUF_ISASYNC(bp));273273- ASSERT(bp->b_iodone == NULL);274274- XFS_BUF_READ(bp);275275- bp->b_ops = ops;313313+ ASSERT(bp->b_flags & XBF_DONE);276314277277- error = xfs_buf_submit_wait(bp);278278- if (error) {279279- if (!XFS_FORCED_SHUTDOWN(mp))280280- xfs_buf_ioerror_alert(bp, __func__);281281- xfs_buf_relse(bp);282282- /*283283- * We can gracefully recover from most read284284- * errors. Ones we can't are those that happen285285- * after the transaction's already dirty.286286- */287287- if (tp->t_flags & XFS_TRANS_DIRTY)288288- xfs_force_shutdown(tp->t_mountp,289289- SHUTDOWN_META_IO_ERROR);290290- /* bad CRC means corrupted metadata */291291- if (error == -EFSBADCRC)292292- error = -EFSCORRUPTED;293293- return error;294294- }295295- }296315 /*297316 * We never locked this buf ourselves, so we shouldn't298317 * brelse it either. Just get out.299318 */300319 if (XFS_FORCED_SHUTDOWN(mp)) {301320 trace_xfs_trans_read_buf_shut(bp, _RET_IP_);302302- *bpp = NULL;303321 return -EIO;304322 }305305-306323307324 bip = bp->b_fspriv;308325 bip->bli_recur++;···289356 }290357291358 bp = xfs_buf_read_map(target, map, nmaps, flags, ops);292292- if (bp == NULL) {293293- *bpp = NULL;294294- return (flags & XBF_TRYLOCK) ?295295- 0 : -ENOMEM;359359+ if (!bp) {360360+ if (!(flags & XBF_TRYLOCK))361361+ return -ENOMEM;362362+ return tp ? 0 : -EAGAIN;296363 }364364+365365+ /*366366+ * If we've had a read error, then the contents of the buffer are367367+ * invalid and should not be used. To ensure that a followup read tries368368+ * to pull the buffer from disk again, we clear the XBF_DONE flag and369369+ * mark the buffer stale. This ensures that anyone who has a current370370+ * reference to the buffer will interpret it's contents correctly and371371+ * future cache lookups will also treat it as an empty, uninitialised372372+ * buffer.373373+ */297374 if (bp->b_error) {298375 error = bp->b_error;376376+ if (!XFS_FORCED_SHUTDOWN(mp))377377+ xfs_buf_ioerror_alert(bp, __func__);378378+ bp->b_flags &= ~XBF_DONE;299379 xfs_buf_stale(bp);300300- XFS_BUF_DONE(bp);301301- xfs_buf_ioerror_alert(bp, __func__);302302- if (tp->t_flags & XFS_TRANS_DIRTY)380380+381381+ if (tp && (tp->t_flags & XFS_TRANS_DIRTY))303382 xfs_force_shutdown(tp->t_mountp, SHUTDOWN_META_IO_ERROR);304383 xfs_buf_relse(bp);305384···320375 error = -EFSCORRUPTED;321376 return error;322377 }323323-#ifdef DEBUG324324- if (xfs_do_error && !(tp->t_flags & XFS_TRANS_DIRTY)) {325325- if (xfs_error_target == target) {326326- if (((xfs_req_num++) % xfs_error_mod) == 0) {327327- xfs_force_shutdown(tp->t_mountp,328328- SHUTDOWN_META_IO_ERROR);329329- xfs_buf_relse(bp);330330- xfs_debug(mp, "Returning trans error!");331331- return -EIO;332332- }333333- }378378+379379+ if (XFS_FORCED_SHUTDOWN(mp)) {380380+ xfs_buf_relse(bp);381381+ trace_xfs_trans_read_buf_shut(bp, _RET_IP_);382382+ return -EIO;334383 }335335-#endif336336- if (XFS_FORCED_SHUTDOWN(mp))337337- goto shutdown_abort;338384339339- _xfs_trans_bjoin(tp, bp, 1);385385+ if (tp)386386+ _xfs_trans_bjoin(tp, bp, 1);340387 trace_xfs_trans_read_buf(bp->b_fspriv);341341-342388 *bpp = bp;343389 return 0;344390345345-shutdown_abort:346346- trace_xfs_trans_read_buf_shut(bp, _RET_IP_);347347- xfs_buf_relse(bp);348348- *bpp = NULL;349349- return -EIO;350391}351392352393/*