int libxfs_zero_extent( struct xfs_inode *ip, xfs_fsblock_t start_fsb, xfs_off_t count_fsb) { xfs_daddr_t sector = xfs_fsb_to_db(ip, start_fsb); ssize_t size = XFS_FSB_TO_BB(ip->i_mount, count_fsb); return libxfs_device_zero(xfs_find_bdev_for_inode(ip), sector, size); }
/* * Allocate the realtime bitmap and summary inodes, and fill in data if any. */ static void rtinit( xfs_mount_t *mp) { xfs_dfiloff_t bno; int committed; xfs_dfiloff_t ebno; xfs_bmbt_irec_t *ep; int error; xfs_fsblock_t first; xfs_bmap_free_t flist; int i; xfs_bmbt_irec_t map[XFS_BMAP_MAX_NMAP]; xfs_extlen_t nsumblocks; int nmap; xfs_inode_t *rbmip; xfs_inode_t *rsumip; xfs_trans_t *tp; struct cred creds; struct fsxattr fsxattrs; /* * First, allocate the inodes. */ tp = libxfs_trans_alloc(mp, 0); if ((i = libxfs_trans_reserve(tp, MKFS_BLOCKRES_INODE, 0, 0, 0, 0))) res_failed(i); memset(&creds, 0, sizeof(creds)); memset(&fsxattrs, 0, sizeof(fsxattrs)); error = libxfs_inode_alloc(&tp, NULL, S_IFREG, 1, 0, &creds, &fsxattrs, &rbmip); if (error) { fail(_("Realtime bitmap inode allocation failed"), error); } /* * Do our thing with rbmip before allocating rsumip, * because the next call to ialloc() may * commit the transaction in which rbmip was allocated. */ mp->m_sb.sb_rbmino = rbmip->i_ino; rbmip->i_d.di_size = mp->m_sb.sb_rbmblocks * mp->m_sb.sb_blocksize; rbmip->i_d.di_flags = XFS_DIFLAG_NEWRTBM; *(__uint64_t *)&rbmip->i_d.di_atime = 0; libxfs_trans_log_inode(tp, rbmip, XFS_ILOG_CORE); libxfs_mod_sb(tp, XFS_SB_RBMINO); libxfs_trans_ihold(tp, rbmip); mp->m_rbmip = rbmip; error = libxfs_inode_alloc(&tp, NULL, S_IFREG, 1, 0, &creds, &fsxattrs, &rsumip); if (error) { fail(_("Realtime summary inode allocation failed"), error); } mp->m_sb.sb_rsumino = rsumip->i_ino; rsumip->i_d.di_size = mp->m_rsumsize; libxfs_trans_log_inode(tp, rsumip, XFS_ILOG_CORE); libxfs_mod_sb(tp, XFS_SB_RSUMINO); libxfs_trans_ihold(tp, rsumip); libxfs_trans_commit(tp, 0); mp->m_rsumip = rsumip; /* * Next, give the bitmap file some zero-filled blocks. */ tp = libxfs_trans_alloc(mp, 0); if ((i = libxfs_trans_reserve(tp, mp->m_sb.sb_rbmblocks + (XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1), 0, 0, 0, 0))) res_failed(i); libxfs_trans_ijoin(tp, rbmip, 0); libxfs_trans_ihold(tp, rbmip); bno = 0; xfs_bmap_init(&flist, &first); while (bno < mp->m_sb.sb_rbmblocks) { nmap = XFS_BMAP_MAX_NMAP; error = libxfs_bmapi(tp, rbmip, bno, (xfs_extlen_t)(mp->m_sb.sb_rbmblocks - bno), XFS_BMAPI_WRITE, &first, mp->m_sb.sb_rbmblocks, map, &nmap, &flist); if (error) { fail(_("Allocation of the realtime bitmap failed"), error); } for (i = 0, ep = map; i < nmap; i++, ep++) { libxfs_device_zero(mp->m_dev, XFS_FSB_TO_DADDR(mp, ep->br_startblock), XFS_FSB_TO_BB(mp, ep->br_blockcount)); bno += ep->br_blockcount; } } error = libxfs_bmap_finish(&tp, &flist, &committed); if (error) { fail(_("Completion of the realtime bitmap failed"), error); } libxfs_trans_commit(tp, 0); /* * Give the summary file some zero-filled blocks. */ tp = libxfs_trans_alloc(mp, 0); nsumblocks = mp->m_rsumsize >> mp->m_sb.sb_blocklog; if ((i = libxfs_trans_reserve(tp, nsumblocks + (XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1), 0, 0, 0, 0))) res_failed(i); libxfs_trans_ijoin(tp, rsumip, 0); libxfs_trans_ihold(tp, rsumip); bno = 0; xfs_bmap_init(&flist, &first); while (bno < nsumblocks) { nmap = XFS_BMAP_MAX_NMAP; error = libxfs_bmapi(tp, rsumip, bno, (xfs_extlen_t)(nsumblocks - bno), XFS_BMAPI_WRITE, &first, nsumblocks, map, &nmap, &flist); if (error) { fail(_("Allocation of the realtime summary failed"), error); } for (i = 0, ep = map; i < nmap; i++, ep++) { libxfs_device_zero(mp->m_dev, XFS_FSB_TO_DADDR(mp, ep->br_startblock), XFS_FSB_TO_BB(mp, ep->br_blockcount)); bno += ep->br_blockcount; } } error = libxfs_bmap_finish(&tp, &flist, &committed); if (error) { fail(_("Completion of the realtime summary failed"), error); } libxfs_trans_commit(tp, 0); /* * Free the whole area using transactions. * Do one transaction per bitmap block. */ for (bno = 0; bno < mp->m_sb.sb_rextents; bno = ebno) { tp = libxfs_trans_alloc(mp, 0); if ((i = libxfs_trans_reserve(tp, 0, 0, 0, 0, 0))) res_failed(i); xfs_bmap_init(&flist, &first); ebno = XFS_RTMIN(mp->m_sb.sb_rextents, bno + NBBY * mp->m_sb.sb_blocksize); error = libxfs_rtfree_extent(tp, bno, (xfs_extlen_t)(ebno-bno)); if (error) { fail(_("Error initializing the realtime space"), error); } error = libxfs_bmap_finish(&tp, &flist, &committed); if (error) { fail(_("Error completing the realtime space"), error); } libxfs_trans_commit(tp, 0); } }