From d79d498fd0dc06694a7903a7715b9179d4ce100c Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 18 Jul 2024 09:16:29 +0200 Subject: [PATCH] mkfs: move more code into create_sb_metadata_file Move more boilerplate for creating the two possible files into create_sb_metadata_file, and turn the actual bitmap/summary specific code into callbacks. Signed-off-by: Christoph Hellwig --- mkfs/proto.c | 117 +++++++++++++++++++++------------------------------ 1 file changed, 47 insertions(+), 70 deletions(-) diff --git a/mkfs/proto.c b/mkfs/proto.c index 2cbe4c9ab..9f41e73f0 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -799,99 +799,76 @@ out_rele: return error; } -static int -create_sb_metadata_file( - struct xfs_trans **tpp, - mode_t mode, - struct xfs_inode **ipp) -{ - struct xfs_icreate_args args = { - .mode = mode, - .flags = XFS_ICREATE_UNLINKABLE, - }; - struct xfs_mount *mp = (*tpp)->t_mountp; - xfs_ino_t ino; - int error; - - /* - * Call the space management code to pick the on-disk inode to be - * allocated. - */ - error = -libxfs_dialloc(tpp, &args, &ino); - if (error) - return error; - - error = -libxfs_icreate(*tpp, ino, &args, ipp); - if (error) - return error; - - if (xfs_has_metadir(mp)) - libxfs_imeta_set_iflag(*tpp, *ipp); - - return 0; -} - /* Create the realtime bitmap inode. */ static void rtbitmap_create( - struct xfs_mount *mp) + struct xfs_inode *ip) { - struct xfs_trans *tp; - struct xfs_inode *rbmip; - int error; - - /* Create the realtime bitmap inode. */ - error = -libxfs_trans_alloc_rollable(mp, MKFS_BLOCKRES_INODE, &tp); - if (error) - res_failed(error); - - error = create_sb_metadata_file(&tp, S_IFREG, &rbmip); - if (error) - fail(_("Realtime bitmap inode allocation failed"), error); + struct xfs_mount *mp = ip->i_mount; - mp->m_sb.sb_rbmino = rbmip->i_ino; - rbmip->i_disk_size = mp->m_sb.sb_rbmblocks * mp->m_sb.sb_blocksize; - rbmip->i_diflags |= XFS_DIFLAG_NEWRTBM; + ip->i_disk_size = mp->m_sb.sb_rbmblocks * mp->m_sb.sb_blocksize; + ip->i_diflags |= XFS_DIFLAG_NEWRTBM; if (!xfs_has_rtgroups(mp)) - inode_set_atime(VFS_I(rbmip), 0, 0); - libxfs_trans_log_inode(tp, rbmip, XFS_ILOG_CORE); - libxfs_log_sb(tp); + inode_set_atime(VFS_I(ip), 0, 0); - error = -libxfs_trans_commit(tp); - if (error) - fail(_("Completion of the realtime bitmap inode failed"), - error); - mp->m_rbmip = rbmip; + mp->m_sb.sb_rbmino = ip->i_ino; + mp->m_rbmip = ip; } /* Create the realtime summary inode. */ static void rtsummary_create( - struct xfs_mount *mp) + struct xfs_inode *ip) { - struct xfs_trans *tp; - struct xfs_inode *rsumip; + struct xfs_mount *mp = ip->i_mount; + + ip->i_disk_size = mp->m_rsumsize; + + mp->m_sb.sb_rsumino = ip->i_ino; + mp->m_rsumip = ip; +} + +static void +create_sb_metadata_file( + struct xfs_mount *mp, + void (*create)(struct xfs_inode *ip)) +{ + struct xfs_icreate_args args = { + .mode = S_IFREG, + .flags = XFS_ICREATE_UNLINKABLE, + }; + xfs_ino_t ino; int error; + struct xfs_trans *tp; + struct xfs_inode *ip; error = -libxfs_trans_alloc_rollable(mp, MKFS_BLOCKRES_INODE, &tp); if (error) res_failed(error); - /* Create the realtime summary inode. */ - error = create_sb_metadata_file(&tp, S_IFREG, &rsumip); + error = -libxfs_dialloc(&tp, &args, &ino); if (error) - fail(_("Realtime summary inode allocation failed"), error); + goto fail; - mp->m_sb.sb_rsumino = rsumip->i_ino; - rsumip->i_disk_size = mp->m_rsumsize; - libxfs_trans_log_inode(tp, rsumip, XFS_ILOG_CORE); + error = -libxfs_icreate(tp, ino, &args, &ip); + if (error) + goto fail; + + if (xfs_has_metadir(mp)) + libxfs_imeta_set_iflag(tp, ip); + + create(ip); + + libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); libxfs_log_sb(tp); error = -libxfs_trans_commit(tp); if (error) - fail(_("Completion of the realtime summary inode failed"), - error); - mp->m_rsumip = rsumip; + goto fail; + return; +fail: + if (error) + fail(_("Realtime inode allocation failed"), error); } /* Zero the realtime bitmap/summary file. */ @@ -980,8 +957,8 @@ rtinit( xfs_rgnumber_t rgno; int i; - rtbitmap_create(mp); - rtsummary_create(mp); + create_sb_metadata_file(mp, rtbitmap_create); + create_sb_metadata_file(mp, rtsummary_create); if (xfs_has_rtgroups(mp)) { int error; -- 2.50.1