Skip to content

Commit ae897e0

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: support creating per-RTG files in growfs
To support adding new RT groups in growfs, we need to be able to create the per-RT group files. Add a new xfs_rtginode_create helper to create a given per-RTG file. Most of the code for that is shared, but the details of the actual file are abstracted out using a new create method in struct xfs_rtginode_ops. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent e3088ae commit ae897e0

File tree

5 files changed

+137
-0
lines changed

5 files changed

+137
-0
lines changed

fs/xfs/libxfs/xfs_rtbitmap.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,3 +1297,35 @@ xfs_rtfile_initialize_blocks(
12971297

12981298
return 0;
12991299
}
1300+
1301+
int
1302+
xfs_rtbitmap_create(
1303+
struct xfs_rtgroup *rtg,
1304+
struct xfs_inode *ip,
1305+
struct xfs_trans *tp,
1306+
bool init)
1307+
{
1308+
struct xfs_mount *mp = rtg_mount(rtg);
1309+
1310+
ip->i_disk_size = mp->m_sb.sb_rbmblocks * mp->m_sb.sb_blocksize;
1311+
if (init && !xfs_has_rtgroups(mp)) {
1312+
ip->i_diflags |= XFS_DIFLAG_NEWRTBM;
1313+
inode_set_atime(VFS_I(ip), 0, 0);
1314+
}
1315+
xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1316+
return 0;
1317+
}
1318+
1319+
int
1320+
xfs_rtsummary_create(
1321+
struct xfs_rtgroup *rtg,
1322+
struct xfs_inode *ip,
1323+
struct xfs_trans *tp,
1324+
bool init)
1325+
{
1326+
struct xfs_mount *mp = rtg_mount(rtg);
1327+
1328+
ip->i_disk_size = mp->m_rsumblocks * mp->m_sb.sb_blocksize;
1329+
xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1330+
return 0;
1331+
}

fs/xfs/libxfs/xfs_rtbitmap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ xfs_filblks_t xfs_rtsummary_blockcount(struct xfs_mount *mp,
315315
int xfs_rtfile_initialize_blocks(struct xfs_rtgroup *rtg,
316316
enum xfs_rtg_inodes type, xfs_fileoff_t offset_fsb,
317317
xfs_fileoff_t end_fsb, void *data);
318+
int xfs_rtbitmap_create(struct xfs_rtgroup *rtg, struct xfs_inode *ip,
319+
struct xfs_trans *tp, bool init);
320+
int xfs_rtsummary_create(struct xfs_rtgroup *rtg, struct xfs_inode *ip,
321+
struct xfs_trans *tp, bool init);
318322

319323
#else /* CONFIG_XFS_RT */
320324
# define xfs_rtfree_extent(t,b,l) (-ENOSYS)

fs/xfs/libxfs/xfs_rtgroup.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,24 @@ struct xfs_rtginode_ops {
272272

273273
/* Does the fs have this feature? */
274274
bool (*enabled)(struct xfs_mount *mp);
275+
276+
/* Create this rtgroup metadata inode and initialize it. */
277+
int (*create)(struct xfs_rtgroup *rtg,
278+
struct xfs_inode *ip,
279+
struct xfs_trans *tp,
280+
bool init);
275281
};
276282

277283
static const struct xfs_rtginode_ops xfs_rtginode_ops[XFS_RTGI_MAX] = {
278284
[XFS_RTGI_BITMAP] = {
279285
.name = "bitmap",
280286
.metafile_type = XFS_METAFILE_RTBITMAP,
287+
.create = xfs_rtbitmap_create,
281288
},
282289
[XFS_RTGI_SUMMARY] = {
283290
.name = "summary",
284291
.metafile_type = XFS_METAFILE_RTSUMMARY,
292+
.create = xfs_rtsummary_create,
285293
},
286294
};
287295

@@ -389,6 +397,67 @@ xfs_rtginode_irele(
389397
*ipp = NULL;
390398
}
391399

400+
/* Add a metadata inode for a realtime rmap btree. */
401+
int
402+
xfs_rtginode_create(
403+
struct xfs_rtgroup *rtg,
404+
enum xfs_rtg_inodes type,
405+
bool init)
406+
{
407+
const struct xfs_rtginode_ops *ops = &xfs_rtginode_ops[type];
408+
struct xfs_mount *mp = rtg_mount(rtg);
409+
struct xfs_metadir_update upd = {
410+
.dp = mp->m_rtdirip,
411+
.metafile_type = ops->metafile_type,
412+
};
413+
int error;
414+
415+
if (!xfs_rtginode_enabled(rtg, type))
416+
return 0;
417+
418+
if (!mp->m_rtdirip)
419+
return -EFSCORRUPTED;
420+
421+
upd.path = xfs_rtginode_path(rtg_rgno(rtg), type);
422+
if (!upd.path)
423+
return -ENOMEM;
424+
425+
error = xfs_metadir_start_create(&upd);
426+
if (error)
427+
goto out_path;
428+
429+
error = xfs_metadir_create(&upd, S_IFREG);
430+
if (error)
431+
return error;
432+
433+
xfs_rtginode_lockdep_setup(upd.ip, rtg_rgno(rtg), type);
434+
435+
upd.ip->i_projid = rtg_rgno(rtg);
436+
error = ops->create(rtg, upd.ip, upd.tp, init);
437+
if (error)
438+
goto out_cancel;
439+
440+
error = xfs_metadir_commit(&upd);
441+
if (error)
442+
goto out_path;
443+
444+
kfree(upd.path);
445+
xfs_finish_inode_setup(upd.ip);
446+
rtg->rtg_inodes[type] = upd.ip;
447+
return 0;
448+
449+
out_cancel:
450+
xfs_metadir_cancel(&upd, error);
451+
/* Have to finish setting up the inode to ensure it's deleted. */
452+
if (upd.ip) {
453+
xfs_finish_inode_setup(upd.ip);
454+
xfs_irele(upd.ip);
455+
}
456+
out_path:
457+
kfree(upd.path);
458+
return error;
459+
}
460+
392461
/* Create the parent directory for all rtgroup inodes and load it. */
393462
int
394463
xfs_rtginode_mkdir_parent(

fs/xfs/libxfs/xfs_rtgroup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ enum xfs_metafile_type xfs_rtginode_metafile_type(enum xfs_rtg_inodes type);
242242
bool xfs_rtginode_enabled(struct xfs_rtgroup *rtg, enum xfs_rtg_inodes type);
243243
int xfs_rtginode_load(struct xfs_rtgroup *rtg, enum xfs_rtg_inodes type,
244244
struct xfs_trans *tp);
245+
int xfs_rtginode_create(struct xfs_rtgroup *rtg, enum xfs_rtg_inodes type,
246+
bool init);
245247
void xfs_rtginode_irele(struct xfs_inode **ipp);
246248

247249
static inline const char *xfs_rtginode_path(xfs_rgnumber_t rgno,

fs/xfs/xfs_rtalloc.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,29 @@ xfs_growfs_rt_fixup_extsize(
711711
return error;
712712
}
713713

714+
/* Ensure that the rtgroup metadata inode is loaded, creating it if neeeded. */
715+
static int
716+
xfs_rtginode_ensure(
717+
struct xfs_rtgroup *rtg,
718+
enum xfs_rtg_inodes type)
719+
{
720+
struct xfs_trans *tp;
721+
int error;
722+
723+
if (rtg->rtg_inodes[type])
724+
return 0;
725+
726+
error = xfs_trans_alloc_empty(rtg_mount(rtg), &tp);
727+
if (error)
728+
return error;
729+
error = xfs_rtginode_load(rtg, type, tp);
730+
xfs_trans_cancel(tp);
731+
732+
if (error != -ENOENT)
733+
return 0;
734+
return xfs_rtginode_create(rtg, type, true);
735+
}
736+
714737
static int
715738
xfs_growfs_rt_bmblock(
716739
struct xfs_rtgroup *rtg,
@@ -927,12 +950,19 @@ xfs_growfs_rtg(
927950
xfs_extlen_t bmblocks;
928951
xfs_fileoff_t bmbno;
929952
struct xfs_rtgroup *rtg;
953+
unsigned int i;
930954
int error;
931955

932956
rtg = xfs_rtgroup_grab(mp, 0);
933957
if (!rtg)
934958
return -EINVAL;
935959

960+
for (i = 0; i < XFS_RTGI_MAX; i++) {
961+
error = xfs_rtginode_ensure(rtg, i);
962+
if (error)
963+
goto out_rele;
964+
}
965+
936966
error = xfs_growfs_rt_alloc_blocks(rtg, nrblocks, rextsize, &bmblocks);
937967
if (error)
938968
goto out_rele;

0 commit comments

Comments
 (0)