Skip to content

Commit 5e19a99

Browse files
committed
nilfs2: separate initializer of metadata file inode
This separates a part of initialization code of metadata file inode, and makes it available from the nilfs iget function that a later patch will add to. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
1 parent 0e14a35 commit 5e19a99

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

fs/nilfs2/gcinode.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,14 @@ static struct inode *alloc_gcinode(struct the_nilfs *nilfs, ino_t ino,
225225
struct inode *inode;
226226
struct nilfs_inode_info *ii;
227227

228-
inode = nilfs_mdt_new_common(nilfs, NULL, ino, GFP_NOFS, 0);
228+
inode = nilfs_mdt_new_common(nilfs, NULL, ino);
229229
if (!inode)
230230
return NULL;
231231

232+
if (nilfs_mdt_init(inode, nilfs, GFP_NOFS, 0) < 0) {
233+
nilfs_destroy_inode(inode);
234+
return NULL;
235+
}
232236
inode->i_op = NULL;
233237
inode->i_fop = NULL;
234238
inode->i_mapping->a_ops = &def_gcinode_aops;

fs/nilfs2/mdt.c

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,27 @@ static const struct address_space_operations def_mdt_aops = {
439439
static const struct inode_operations def_mdt_iops;
440440
static const struct file_operations def_mdt_fops;
441441

442+
443+
int nilfs_mdt_init(struct inode *inode, struct the_nilfs *nilfs,
444+
gfp_t gfp_mask, size_t objsz)
445+
{
446+
struct nilfs_mdt_info *mi;
447+
448+
mi = kzalloc(max(sizeof(*mi), objsz), GFP_NOFS);
449+
if (!mi)
450+
return -ENOMEM;
451+
452+
mi->mi_nilfs = nilfs;
453+
init_rwsem(&mi->mi_sem);
454+
inode->i_private = mi;
455+
456+
inode->i_mode = S_IFREG;
457+
mapping_set_gfp_mask(inode->i_mapping, gfp_mask);
458+
inode->i_mapping->backing_dev_info = nilfs->ns_bdi;
459+
460+
return 0;
461+
}
462+
442463
/*
443464
* NILFS2 uses pseudo inodes for meta data files such as DAT, cpfile, sufile,
444465
* ifile, or gcinodes. This allows the B-tree code and segment constructor
@@ -454,37 +475,24 @@ static const struct file_operations def_mdt_fops;
454475
* @nilfs: nilfs object
455476
* @sb: super block instance the metadata file belongs to
456477
* @ino: inode number
457-
* @gfp_mask: gfp mask for data pages
458-
* @objsz: size of the private object attached to inode->i_private
459478
*/
460479
struct inode *
461480
nilfs_mdt_new_common(struct the_nilfs *nilfs, struct super_block *sb,
462-
ino_t ino, gfp_t gfp_mask, size_t objsz)
481+
ino_t ino)
463482
{
464483
struct inode *inode = nilfs_alloc_inode_common(nilfs);
465484

466485
if (!inode)
467486
return NULL;
468487
else {
469488
struct address_space * const mapping = &inode->i_data;
470-
struct nilfs_mdt_info *mi;
471-
472-
mi = kzalloc(max(sizeof(*mi), objsz), GFP_NOFS);
473-
if (!mi) {
474-
nilfs_destroy_inode(inode);
475-
return NULL;
476-
}
477-
mi->mi_nilfs = nilfs;
478-
init_rwsem(&mi->mi_sem);
479489

480490
inode->i_sb = sb; /* sb may be NULL for some meta data files */
481491
inode->i_blkbits = nilfs->ns_blocksize_bits;
482492
inode->i_flags = 0;
483493
atomic_set(&inode->i_count, 1);
484494
inode->i_nlink = 1;
485495
inode->i_ino = ino;
486-
inode->i_mode = S_IFREG;
487-
inode->i_private = mi;
488496

489497
#ifdef INIT_UNUSED_INODE_FIELDS
490498
atomic_set(&inode->i_writecount, 0);
@@ -515,9 +523,7 @@ nilfs_mdt_new_common(struct the_nilfs *nilfs, struct super_block *sb,
515523

516524
mapping->host = NULL; /* instead of inode */
517525
mapping->flags = 0;
518-
mapping_set_gfp_mask(mapping, gfp_mask);
519526
mapping->assoc_mapping = NULL;
520-
mapping->backing_dev_info = nilfs->ns_bdi;
521527

522528
inode->i_mapping = mapping;
523529
}
@@ -530,10 +536,14 @@ struct inode *nilfs_mdt_new(struct the_nilfs *nilfs, struct super_block *sb,
530536
{
531537
struct inode *inode;
532538

533-
inode = nilfs_mdt_new_common(nilfs, sb, ino, NILFS_MDT_GFP, objsz);
539+
inode = nilfs_mdt_new_common(nilfs, sb, ino);
534540
if (!inode)
535541
return NULL;
536542

543+
if (nilfs_mdt_init(inode, nilfs, NILFS_MDT_GFP, objsz) < 0) {
544+
nilfs_destroy_inode(inode);
545+
return NULL;
546+
}
537547
inode->i_op = &def_mdt_iops;
538548
inode->i_fop = &def_mdt_fops;
539549
inode->i_mapping->a_ops = &def_mdt_aops;

fs/nilfs2/mdt.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ int nilfs_mdt_forget_block(struct inode *, unsigned long);
7676
int nilfs_mdt_mark_block_dirty(struct inode *, unsigned long);
7777
int nilfs_mdt_fetch_dirty(struct inode *);
7878

79+
int nilfs_mdt_init(struct inode *inode, struct the_nilfs *nilfs,
80+
gfp_t gfp_mask, size_t objsz);
7981
struct inode *nilfs_mdt_new(struct the_nilfs *, struct super_block *, ino_t,
8082
size_t);
8183
struct inode *nilfs_mdt_new_common(struct the_nilfs *, struct super_block *,
82-
ino_t, gfp_t, size_t);
84+
ino_t);
8385
void nilfs_mdt_destroy(struct inode *);
8486
void nilfs_mdt_set_entry_size(struct inode *, unsigned, unsigned);
8587
void nilfs_mdt_set_shadow(struct inode *, struct inode *);

0 commit comments

Comments
 (0)