From 9074815cd478613b8aaf756c5e21d4ee5f1e5b95 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Wed, 22 Jun 2016 09:32:40 +1000 Subject: [PATCH] xfs: better xfs_trans_alloc interface Source kernel commit 253f4911f297b83745938b7f2c5649b94730b002 Merge xfs_trans_reserve and xfs_trans_alloc into a single function call that returns a transaction with all the required log and block reservations, and which allows passing transaction flags directly to avoid the cumbersome _xfs_trans_alloc interface. While we're at it we also get rid of the transaction type argument that has been superflous since we stopped supporting the non-CIL logging mode. The guts of it will be removed in another patch. [dchinner: fixed transaction leak in error path in xfs_setattr_nonsize] Signed-off-by: Christoph Hellwig Reviewed-by: Dave Chinner Signed-off-by: Dave Chinner --- include/xfs_trans.h | 6 +-- libxfs/libxfs_api_defs.h | 1 - libxfs/libxfs_priv.h | 1 - libxfs/trans.c | 53 +++++++++++-------------- libxfs/util.c | 5 +-- libxfs/xfs_attr.c | 58 +++++++--------------------- libxfs/xfs_bmap.c | 22 +++++------ libxfs/xfs_sb.c | 8 ++-- libxfs/xfs_shared.h | 5 ++- mkfs/proto.c | 51 ++++++++++++------------ mkfs/xfs_mkfs.c | 9 +++-- repair/phase5.c | 8 ++-- repair/phase6.c | 83 ++++++++++++++-------------------------- repair/phase7.c | 4 +- 14 files changed, 119 insertions(+), 195 deletions(-) diff --git a/include/xfs_trans.h b/include/xfs_trans.h index 0c7a90adc..b4bd1eb4d 100644 --- a/include/xfs_trans.h +++ b/include/xfs_trans.h @@ -87,9 +87,9 @@ typedef struct xfs_trans { void xfs_trans_init(struct xfs_mount *); int xfs_trans_roll(struct xfs_trans **, struct xfs_inode *); -xfs_trans_t *libxfs_trans_alloc(struct xfs_mount *, int); -int libxfs_trans_reserve(struct xfs_trans *, struct xfs_trans_res *, - uint, uint); +int libxfs_trans_alloc(struct xfs_mount *mp, struct xfs_trans_res *resp, + uint blocks, uint rtextents, uint flags, + struct xfs_trans **tpp); int libxfs_trans_commit(struct xfs_trans *); void libxfs_trans_cancel(struct xfs_trans *); struct xfs_buf *libxfs_trans_getsb(struct xfs_trans *, struct xfs_mount *, int); diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 685c7a70d..290dc1d7d 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -55,7 +55,6 @@ #define xfs_trans_read_buf_map libxfs_trans_read_buf_map #define xfs_trans_roll libxfs_trans_roll #define xfs_trans_get_buf_map libxfs_trans_get_buf_map -#define xfs_trans_reserve libxfs_trans_reserve #define xfs_trans_resv_calc libxfs_trans_resv_calc #define xfs_attr_get libxfs_attr_get diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index c14faca00..608d5c379 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -361,7 +361,6 @@ roundup_64(__uint64_t x, __uint32_t y) #define XFS_MOUNT_RDONLY 0 /* ignored in userspace */ -#define _xfs_trans_alloc(mp, type, f) libxfs_trans_alloc(mp, type) #define xfs_trans_get_block_res(tp) 1 #define xfs_trans_set_sync(tp) ((void) 0) #define xfs_trans_ordered_buf(tp, bp) ((void) 0) diff --git a/libxfs/trans.c b/libxfs/trans.c index 03889502a..521a049be 100644 --- a/libxfs/trans.c +++ b/libxfs/trans.c @@ -119,7 +119,6 @@ libxfs_trans_roll( */ tres.tr_logres = trans->t_log_res; tres.tr_logcount = trans->t_log_count; - *tpp = libxfs_trans_alloc(trans->t_mountp, trans->t_type); /* * Commit the current transaction. @@ -132,7 +131,6 @@ libxfs_trans_roll( if (error) return error; - trans = *tpp; /* * Reserve space in the log for th next transaction. @@ -143,7 +141,8 @@ libxfs_trans_roll( * the prior and the next transactions. */ tres.tr_logflags = XFS_TRANS_PERM_LOG_RES; - error = xfs_trans_reserve(trans, &tres, 0, 0); + error = libxfs_trans_alloc(trans->t_mountp, &tres, 0, 0, 0, tpp); + trans = *tpp; /* * Ensure that the inode is in the new transaction and locked. */ @@ -155,12 +154,28 @@ libxfs_trans_roll( return 0; } -xfs_trans_t * +int libxfs_trans_alloc( - xfs_mount_t *mp, - int type) + struct xfs_mount *mp, + struct xfs_trans_res *resp, + unsigned int blocks, + unsigned int rtextents, + unsigned int flags, + struct xfs_trans **tpp) + { - xfs_trans_t *ptr; + struct xfs_sb *sb = &mp->m_sb; + struct xfs_trans *ptr; + + /* + * Attempt to reserve the needed disk blocks by decrementing + * the number needed from the number available. This will + * fail if the count would go below zero. + */ + if (blocks > 0) { + if (sb->sb_fdblocks < blocks) + return -ENOSPC; + } if ((ptr = calloc(sizeof(xfs_trans_t), 1)) == NULL) { fprintf(stderr, _("%s: xact calloc failed (%d bytes): %s\n"), @@ -168,33 +183,11 @@ libxfs_trans_alloc( exit(1); } ptr->t_mountp = mp; - ptr->t_type = type; INIT_LIST_HEAD(&ptr->t_items); #ifdef XACT_DEBUG fprintf(stderr, "allocated new transaction %p\n", ptr); #endif - return ptr; -} - -int -libxfs_trans_reserve( - struct xfs_trans *tp, - struct xfs_trans_res *resp, - uint blocks, - uint rtextents) -{ - xfs_sb_t *mpsb = &tp->t_mountp->m_sb; - - /* - * Attempt to reserve the needed disk blocks by decrementing - * the number needed from the number available. This will - * fail if the count would go below zero. - */ - if (blocks > 0) { - if (mpsb->sb_fdblocks < blocks) - return -ENOSPC; - } - /* user space, don't need log/RT stuff (preserve the API though) */ + *tpp = ptr; return 0; } diff --git a/libxfs/util.c b/libxfs/util.c index f3b989543..37941246e 100644 --- a/libxfs/util.c +++ b/libxfs/util.c @@ -541,10 +541,9 @@ libxfs_alloc_file_space( while (allocatesize_fsb && !error) { datablocks = allocatesize_fsb; - tp = xfs_trans_alloc(mp, XFS_TRANS_DIOSTRAT); resblks = (uint)XFS_DIOSTRAT_SPACE_RES(mp, datablocks); - error = xfs_trans_reserve(tp, &M_RES(mp)->tr_write, - resblks, 0); + error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, + 0, 0, &tp); /* * Check for running out of space */ diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index afe3dcb5c..ad340c412 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -235,37 +235,21 @@ xfs_attr_set( return error; } - /* - * Start our first transaction of the day. - * - * All future transactions during this code must be "chained" off - * this one via the trans_dup() call. All transactions will contain - * the inode, and the inode will always be marked with trans_ihold(). - * Since the inode will be locked in all transactions, we must log - * the inode in every transaction to let it float upward through - * the log. - */ - args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_SET); + tres.tr_logres = M_RES(mp)->tr_attrsetm.tr_logres + + M_RES(mp)->tr_attrsetrt.tr_logres * args.total; + tres.tr_logcount = XFS_ATTRSET_LOG_COUNT; + tres.tr_logflags = XFS_TRANS_PERM_LOG_RES; /* * Root fork attributes can use reserved data blocks for this * operation if necessary */ - - if (rsvd) - args.trans->t_flags |= XFS_TRANS_RESERVE; - - tres.tr_logres = M_RES(mp)->tr_attrsetm.tr_logres + - M_RES(mp)->tr_attrsetrt.tr_logres * args.total; - tres.tr_logcount = XFS_ATTRSET_LOG_COUNT; - tres.tr_logflags = XFS_TRANS_PERM_LOG_RES; - error = xfs_trans_reserve(args.trans, &tres, args.total, 0); - if (error) { - xfs_trans_cancel(args.trans); + error = xfs_trans_alloc(mp, &tres, args.total, 0, + rsvd ? XFS_TRANS_RESERVE : 0, &args.trans); + if (error) return error; - } - xfs_ilock(dp, XFS_ILOCK_EXCL); + xfs_ilock(dp, XFS_ILOCK_EXCL); error = xfs_trans_reserve_quota_nblks(args.trans, dp, args.total, 0, rsvd ? XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_FORCE_RES : XFS_QMOPT_RES_REGBLKS); @@ -421,32 +405,16 @@ xfs_attr_remove( if (error) return error; - /* - * Start our first transaction of the day. - * - * All future transactions during this code must be "chained" off - * this one via the trans_dup() call. All transactions will contain - * the inode, and the inode will always be marked with trans_ihold(). - * Since the inode will be locked in all transactions, we must log - * the inode in every transaction to let it float upward through - * the log. - */ - args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_RM); - /* * Root fork attributes can use reserved data blocks for this * operation if necessary */ - - if (flags & ATTR_ROOT) - args.trans->t_flags |= XFS_TRANS_RESERVE; - - error = xfs_trans_reserve(args.trans, &M_RES(mp)->tr_attrrm, - XFS_ATTRRM_SPACE_RES(mp), 0); - if (error) { - xfs_trans_cancel(args.trans); + error = xfs_trans_alloc(mp, &M_RES(mp)->tr_attrrm, + XFS_ATTRRM_SPACE_RES(mp), 0, + (flags & ATTR_ROOT) ? XFS_TRANS_RESERVE : 0, + &args.trans); + if (error) return error; - } xfs_ilock(dp, XFS_ILOCK_EXCL); /* diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index cbcfd72f7..c2a2c5332 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -1113,15 +1113,14 @@ xfs_bmap_add_attrfork( mp = ip->i_mount; ASSERT(!XFS_NOT_DQATTACHED(mp, ip)); - tp = xfs_trans_alloc(mp, XFS_TRANS_ADDAFORK); + blks = XFS_ADDAFORK_SPACE_RES(mp); - if (rsvd) - tp->t_flags |= XFS_TRANS_RESERVE; - error = xfs_trans_reserve(tp, &M_RES(mp)->tr_addafork, blks, 0); - if (error) { - xfs_trans_cancel(tp); + + error = xfs_trans_alloc(mp, &M_RES(mp)->tr_addafork, blks, 0, + rsvd ? XFS_TRANS_RESERVE : 0, &tp); + if (error) return error; - } + xfs_ilock(ip, XFS_ILOCK_EXCL); error = xfs_trans_reserve_quota_nblks(tp, ip, blks, 0, rsvd ? XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_FORCE_RES : @@ -6018,13 +6017,10 @@ xfs_bmap_split_extent( xfs_fsblock_t firstfsb; int error; - tp = xfs_trans_alloc(mp, XFS_TRANS_DIOSTRAT); - error = xfs_trans_reserve(tp, &M_RES(mp)->tr_write, - XFS_DIOSTRAT_SPACE_RES(mp, 0), 0); - if (error) { - xfs_trans_cancel(tp); + error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, + XFS_DIOSTRAT_SPACE_RES(mp, 0), 0, 0, &tp); + if (error) return error; - } xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index 78ad8895e..45db6ae8e 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -820,12 +820,10 @@ xfs_sync_sb( struct xfs_trans *tp; int error; - tp = _xfs_trans_alloc(mp, XFS_TRANS_SB_CHANGE, KM_SLEEP); - error = xfs_trans_reserve(tp, &M_RES(mp)->tr_sb, 0, 0); - if (error) { - xfs_trans_cancel(tp); + error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0, + XFS_TRANS_NO_WRITECOUNT, &tp); + if (error) return error; - } xfs_log_sb(tp); if (wait) diff --git a/libxfs/xfs_shared.h b/libxfs/xfs_shared.h index 81ac87083..7d4ab6439 100644 --- a/libxfs/xfs_shared.h +++ b/libxfs/xfs_shared.h @@ -181,8 +181,9 @@ int xfs_log_calc_minimum_size(struct xfs_mount *); #define XFS_TRANS_SYNC 0x08 /* make commit synchronous */ #define XFS_TRANS_DQ_DIRTY 0x10 /* at least one dquot in trx dirty */ #define XFS_TRANS_RESERVE 0x20 /* OK to use reserved data blocks */ -#define XFS_TRANS_FREEZE_PROT 0x40 /* Transaction has elevated writer - count in superblock */ +#define XFS_TRANS_NO_WRITECOUNT 0x40 /* do not elevate SB writecount */ +#define XFS_TRANS_NOFS 0x80 /* pass KM_NOFS to kmem_alloc */ + /* * Field values for xfs_trans_mod_sb. */ diff --git a/mkfs/proto.c b/mkfs/proto.c index 09a9439f0..5f7f0b40b 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -25,7 +25,7 @@ */ static char *getstr(char **pp); static void fail(char *msg, int i); -static void getres(xfs_trans_t *tp, uint blocks); +static struct xfs_trans * getres(struct xfs_mount *mp, uint blocks); static void rsvfile(xfs_mount_t *mp, xfs_inode_t *ip, long long len); static int newfile(xfs_trans_t *tp, xfs_inode_t *ip, xfs_bmap_free_t *flist, xfs_fsblock_t *first, int dolocal, int logit, char *buf, int len); @@ -125,25 +125,25 @@ res_failed( fail(_("cannot reserve space"), i); } -static void +static struct xfs_trans * getres( - xfs_trans_t *tp, + struct xfs_mount *mp, uint blocks) { + struct xfs_trans *tp; int i; - xfs_mount_t *mp; uint r; - mp = tp->t_mountp; for (i = 0, r = MKFS_BLOCKRES(blocks); r >= blocks; r--) { struct xfs_trans_res tres = {0}; - i = -libxfs_trans_reserve(tp, &tres, r, 0); + i = -libxfs_trans_alloc(mp, &tres, r, 0, 0, &tp); if (i == 0) - return; + return tp; } res_failed(i); /* NOTREACHED */ + return NULL; } static char * @@ -192,6 +192,7 @@ rsvfile( { int error; xfs_trans_t *tp; + struct xfs_trans_res tres = {0}; error = -libxfs_alloc_file_space(ip, 0, llen, 1, 0); @@ -203,8 +204,7 @@ rsvfile( /* * update the inode timestamp, mode, and prealloc flag bits */ - tp = libxfs_trans_alloc(mp, 0); - + libxfs_trans_alloc(mp, &tres, 0, 0, 0, &tp); libxfs_trans_ijoin(tp, ip, 0); VFS_I(ip)->i_mode &= ~S_ISUID; @@ -454,13 +454,12 @@ parseproto( xname.name = (unsigned char *)name; xname.len = name ? strlen(name) : 0; xname.type = 0; - tp = libxfs_trans_alloc(mp, 0); flags = XFS_ILOG_CORE; xfs_bmap_init(&flist, &first); switch (fmt) { case IF_REGULAR: buf = newregfile(pp, &len); - getres(tp, XFS_B_TO_FSB(mp, len)); + tp = getres(mp, XFS_B_TO_FSB(mp, len)); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFREG, 1, 0, &creds, fsxp, &ip); if (error) @@ -483,7 +482,7 @@ parseproto( progname, value, name); exit(1); } - getres(tp, XFS_B_TO_FSB(mp, llen)); + tp = getres(mp, XFS_B_TO_FSB(mp, llen)); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFREG, 1, 0, &creds, fsxp, &ip); @@ -505,7 +504,7 @@ parseproto( return; case IF_BLOCK: - getres(tp, 0); + tp = getres(mp, 0); majdev = getnum(getstr(pp), 0, 0, false); mindev = getnum(getstr(pp), 0, 0, false); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFBLK, 1, @@ -520,7 +519,7 @@ parseproto( break; case IF_CHAR: - getres(tp, 0); + tp = getres(mp, 0); majdev = getnum(getstr(pp), 0, 0, false); mindev = getnum(getstr(pp), 0, 0, false); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFCHR, 1, @@ -534,7 +533,7 @@ parseproto( break; case IF_FIFO: - getres(tp, 0); + tp = getres(mp, 0); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFIFO, 1, 0, &creds, fsxp, &ip); if (error) @@ -546,7 +545,7 @@ parseproto( case IF_SYMLINK: buf = getstr(pp); len = (int)strlen(buf); - getres(tp, XFS_B_TO_FSB(mp, len)); + tp = getres(mp, XFS_B_TO_FSB(mp, len)); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFLNK, 1, 0, &creds, fsxp, &ip); if (error) @@ -557,7 +556,7 @@ parseproto( newdirent(mp, tp, pip, &xname, ip->i_ino, &first, &flist); break; case IF_DIRECTORY: - getres(tp, 0); + tp = getres(mp, 0); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFDIR, 1, 0, &creds, fsxp, &ip); if (error) @@ -649,8 +648,7 @@ rtinit( /* * First, allocate the inodes. */ - tp = libxfs_trans_alloc(mp, 0); - i = -libxfs_trans_reserve(tp, &tres, MKFS_BLOCKRES_INODE, 0); + i = -libxfs_trans_alloc(mp, &tres, MKFS_BLOCKRES_INODE, 0, 0, &tp); if (i) res_failed(i); @@ -687,9 +685,9 @@ rtinit( /* * Next, give the bitmap file some zero-filled blocks. */ - tp = libxfs_trans_alloc(mp, 0); - i = -libxfs_trans_reserve(tp, &tres, mp->m_sb.sb_rbmblocks + - (XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1), 0); + i = -libxfs_trans_alloc(mp, &tres, + mp->m_sb.sb_rbmblocks + (XFS_BM_MAXLEVELS(mp,XFS_DATA_FORK) - 1), + 0, 0, &tp); if (i) res_failed(i); @@ -723,10 +721,10 @@ rtinit( /* * Give the summary file some zero-filled blocks. */ - tp = libxfs_trans_alloc(mp, 0); nsumblocks = mp->m_rsumsize >> mp->m_sb.sb_blocklog; - i = -libxfs_trans_reserve(tp, &tres, nsumblocks + - (XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1), 0); + i = -libxfs_trans_alloc(mp, &tres, + nsumblocks + (XFS_BM_MAXLEVELS(mp,XFS_DATA_FORK) - 1), + 0, 0, &tp); if (i) res_failed(i); libxfs_trans_ijoin(tp, rsumip, 0); @@ -760,8 +758,7 @@ rtinit( * Do one transaction per bitmap block. */ for (bno = 0; bno < mp->m_sb.sb_rextents; bno = ebno) { - tp = libxfs_trans_alloc(mp, 0); - i = -libxfs_trans_reserve(tp, &tres, 0, 0); + i = -libxfs_trans_alloc(mp, &tres, 0, 0, 0, &tp); if (i) res_failed(i); libxfs_trans_ijoin(tp, rbmip, 0); diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 82c9eaafa..8007dd0c6 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -3136,15 +3136,16 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), xfs_trans_t *tp; struct xfs_trans_res tres = {0}; + c = libxfs_trans_alloc(mp, &tres, worst_freelist, 0, 0, &tp); + if (c) + res_failed(c); + memset(&args, 0, sizeof(args)); - args.tp = tp = libxfs_trans_alloc(mp, 0); + args.tp = tp; args.mp = mp; args.agno = agno; args.alignment = 1; args.pag = xfs_perag_get(mp,agno); - c = -libxfs_trans_reserve(tp, &tres, worst_freelist, 0); - if (c) - res_failed(c); libxfs_alloc_fix_freelist(&args, 0); xfs_perag_put(args.pag); diff --git a/repair/phase5.c b/repair/phase5.c index 5d4884814..bc6f50366 100644 --- a/repair/phase5.c +++ b/repair/phase5.c @@ -1505,13 +1505,13 @@ build_agf_agfl(xfs_mount_t *mp, int error; memset(&args, 0, sizeof(args)); - args.tp = tp = libxfs_trans_alloc(mp, 0); + args.pag = xfs_perag_get(mp,agno); + libxfs_trans_alloc(mp, &tres, + xfs_alloc_min_freelist(mp, args.pag), 0, 0, &tp); + args.tp = tp; args.mp = mp; args.agno = agno; args.alignment = 1; - args.pag = xfs_perag_get(mp,agno); - libxfs_trans_reserve(tp, &tres, - xfs_alloc_min_freelist(mp, args.pag), 0); error = libxfs_alloc_fix_freelist(&args, 0); xfs_perag_put(args.pag); if (error) { diff --git a/repair/phase6.c b/repair/phase6.c index 774e2cd76..419eb8939 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -494,9 +494,7 @@ mk_rbmino(xfs_mount_t *mp) /* * first set up inode */ - tp = libxfs_trans_alloc(mp, 0); - - i = -libxfs_trans_reserve(tp, &tres, 10, 0); + i = -libxfs_trans_alloc(mp, &tres, 10, 0, 0, &tp); if (i) res_failed(i); @@ -544,9 +542,9 @@ mk_rbmino(xfs_mount_t *mp) * then allocate blocks for file and fill with zeroes (stolen * from mkfs) */ - tp = libxfs_trans_alloc(mp, 0); - error = -libxfs_trans_reserve(tp, &tres, mp->m_sb.sb_rbmblocks + - (XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1), 0); + error = -libxfs_trans_alloc(mp, &tres, + mp->m_sb.sb_rbmblocks + (XFS_BM_MAXLEVELS(mp,XFS_DATA_FORK) - 1), + 0, 0, &tp); if (error) res_failed(error); @@ -598,9 +596,7 @@ fill_rbmino(xfs_mount_t *mp) bmp = btmcompute; bno = 0; - tp = libxfs_trans_alloc(mp, 0); - - error = -libxfs_trans_reserve(tp, &tres, 10, 0); + error = -libxfs_trans_alloc(mp, &tres, 10, 0, 0, &tp); if (error) res_failed(error); @@ -671,9 +667,7 @@ fill_rsumino(xfs_mount_t *mp) bno = 0; end_bno = mp->m_rsumsize >> mp->m_sb.sb_blocklog; - tp = libxfs_trans_alloc(mp, 0); - - error = -libxfs_trans_reserve(tp, &tres, 10, 0); + error = -libxfs_trans_alloc(mp, &tres, 10, 0, 0, &tp); if (error) res_failed(error); @@ -747,9 +741,7 @@ mk_rsumino(xfs_mount_t *mp) /* * first set up inode */ - tp = libxfs_trans_alloc(mp, 0); - - i = -libxfs_trans_reserve(tp, &M_RES(mp)->tr_ichange, 10, 0); + i = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 10, 0, 0, &tp); if (i) res_failed(i); @@ -797,15 +789,15 @@ mk_rsumino(xfs_mount_t *mp) * then allocate blocks for file and fill with zeroes (stolen * from mkfs) */ - tp = libxfs_trans_alloc(mp, 0); xfs_bmap_init(&flist, &first); nsumblocks = mp->m_rsumsize >> mp->m_sb.sb_blocklog; tres.tr_logres = BBTOB(128); tres.tr_logcount = XFS_DEFAULT_PERM_LOG_COUNT; tres.tr_logflags = XFS_TRANS_PERM_LOG_RES; - error = -libxfs_trans_reserve(tp, &tres, mp->m_sb.sb_rbmblocks + - (XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1), 0); + error = -libxfs_trans_alloc(mp, &tres, + mp->m_sb.sb_rbmblocks + (XFS_BM_MAXLEVELS(mp,XFS_DATA_FORK) - 1), + 0, 0, &tp); if (error) res_failed(error); @@ -854,10 +846,8 @@ mk_root_dir(xfs_mount_t *mp) int vers; int times; - tp = libxfs_trans_alloc(mp, 0); ip = NULL; - - i = -libxfs_trans_reserve(tp, &M_RES(mp)->tr_ichange, 10, 0); + i = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 10, 0, 0, &tp); if (i) res_failed(i); @@ -953,12 +943,9 @@ mk_orphanage(xfs_mount_t *mp) /* * could not be found, create it */ - - tp = libxfs_trans_alloc(mp, 0); xfs_bmap_init(&flist, &first); - nres = XFS_MKDIR_SPACE_RES(mp, xname.len); - i = -libxfs_trans_reserve(tp, &M_RES(mp)->tr_mkdir, nres, 0); + i = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_mkdir, nres, 0, 0, &tp); if (i) res_failed(i); @@ -1092,8 +1079,6 @@ mv_orphanage( xname.len = snprintf((char *)fname, sizeof(fname), "%llu.%d", (unsigned long long)ino, ++incr); - tp = libxfs_trans_alloc(mp, 0); - if ((err = -libxfs_iget(mp, NULL, ino, 0, &ino_p, 0))) do_error(_("%d - couldn't iget disconnected inode\n"), err); @@ -1112,8 +1097,8 @@ mv_orphanage( if (err) { ASSERT(err == ENOENT); - err = -libxfs_trans_reserve(tp, &M_RES(mp)->tr_rename, - nres, 0); + err = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_rename, + nres, 0, 0, &tp); if (err) do_error( _("space reservation failed (%d), filesystem may be out of space\n"), @@ -1154,8 +1139,8 @@ mv_orphanage( libxfs_trans_commit(tp); } else { - err = -libxfs_trans_reserve(tp, &M_RES(mp)->tr_rename, - nres, 0); + err = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_rename, + nres, 0, 0, &tp); if (err) do_error( _("space reservation failed (%d), filesystem may be out of space\n"), @@ -1210,8 +1195,8 @@ mv_orphanage( * also accounted for in the create */ nres = XFS_DIRENTER_SPACE_RES(mp, xname.len); - err = -libxfs_trans_reserve(tp, &M_RES(mp)->tr_remove, - nres, 0); + err = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_remove, + nres, 0, 0, &tp); if (err) do_error( _("space reservation failed (%d), filesystem may be out of space\n"), @@ -1306,9 +1291,8 @@ longform_dir2_rebuild( xfs_bmap_init(&flist, &firstblock); - tp = libxfs_trans_alloc(mp, 0); nres = XFS_REMOVE_SPACE_RES(mp); - error = -libxfs_trans_reserve(tp, &M_RES(mp)->tr_remove, nres, 0); + error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_remove, nres, 0, 0, &tp); if (error) res_failed(error); libxfs_trans_ijoin(tp, ip, 0); @@ -1349,10 +1333,9 @@ longform_dir2_rebuild( p->name.name[1] == '.')))) continue; - tp = libxfs_trans_alloc(mp, 0); nres = XFS_CREATE_SPACE_RES(mp, p->name.len); - error = -libxfs_trans_reserve(tp, &M_RES(mp)->tr_create, - nres, 0); + error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_create, + nres, 0, 0, &tp); if (error) res_failed(error); @@ -1406,9 +1389,8 @@ dir2_kill_block( int nres; xfs_trans_t *tp; - tp = libxfs_trans_alloc(mp, 0); nres = XFS_REMOVE_SPACE_RES(mp); - error = -libxfs_trans_reserve(tp, &M_RES(mp)->tr_remove, nres, 0); + error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_remove, nres, 0, 0, &tp); if (error) res_failed(error); libxfs_trans_ijoin(tp, ip, 0); @@ -1598,8 +1580,7 @@ longform_dir2_entry_check_data( if (freetab->nents < db + 1) freetab->nents = db + 1; - tp = libxfs_trans_alloc(mp, 0); - error = -libxfs_trans_reserve(tp, &M_RES(mp)->tr_remove, 0, 0); + error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_remove, 0, 0, 0, &tp); if (error) res_failed(error); da.trans = tp; @@ -2902,7 +2883,6 @@ process_dir_inode( break; case XFS_DINODE_FMT_LOCAL: - tp = libxfs_trans_alloc(mp, 0); /* * using the remove reservation is overkill * since at most we'll only need to log the @@ -2910,8 +2890,8 @@ process_dir_inode( * new define in ourselves. */ nres = no_modify ? 0 : XFS_REMOVE_SPACE_RES(mp); - error = -libxfs_trans_reserve(tp, &M_RES(mp)->tr_remove, - nres, 0); + error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_remove, + nres, 0, 0, &tp); if (error) res_failed(error); @@ -2951,11 +2931,9 @@ process_dir_inode( do_warn(_("recreating root directory .. entry\n")); - tp = libxfs_trans_alloc(mp, 0); - ASSERT(tp != NULL); - nres = XFS_MKDIR_SPACE_RES(mp, 2); - error = -libxfs_trans_reserve(tp, &M_RES(mp)->tr_mkdir, nres, 0); + error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_mkdir, + nres, 0, 0, &tp); if (error) res_failed(error); @@ -3010,12 +2988,9 @@ process_dir_inode( do_warn( _("creating missing \".\" entry in dir ino %" PRIu64 "\n"), ino); - tp = libxfs_trans_alloc(mp, 0); - ASSERT(tp != NULL); - nres = XFS_MKDIR_SPACE_RES(mp, 1); - error = -libxfs_trans_reserve(tp, &M_RES(mp)->tr_mkdir, - nres, 0); + error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_mkdir, + nres, 0, 0, &tp); if (error) res_failed(error); diff --git a/repair/phase7.c b/repair/phase7.c index 3e234b980..8bce117d3 100644 --- a/repair/phase7.c +++ b/repair/phase7.c @@ -40,10 +40,8 @@ update_inode_nlinks( int dirty; int nres; - tp = libxfs_trans_alloc(mp, XFS_TRANS_REMOVE); - nres = no_modify ? 0 : 10; - error = -libxfs_trans_reserve(tp, &M_RES(mp)->tr_remove, nres, 0); + error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_remove, nres, 0, 0, &tp); ASSERT(error == 0); error = -libxfs_trans_iget(mp, tp, ino, 0, 0, &ip); -- 2.39.5