aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nilfs2/dat.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nilfs2/dat.c')
-rw-r--r--fs/nilfs2/dat.c61
1 files changed, 35 insertions, 26 deletions
diff --git a/fs/nilfs2/dat.c b/fs/nilfs2/dat.c
index 7091c4e0f042..ab04a68f425d 100644
--- a/fs/nilfs2/dat.c
+++ b/fs/nilfs2/dat.c
@@ -463,39 +463,48 @@ ssize_t nilfs_dat_get_vinfo(struct inode *dat, void *buf, unsigned visz,
463} 463}
464 464
465/** 465/**
466 * nilfs_dat_read - read dat inode 466 * nilfs_dat_read - read or get dat inode
467 * @dat: dat inode 467 * @sb: super block instance
468 * @raw_inode: on-disk dat inode
469 */
470int nilfs_dat_read(struct inode *dat, struct nilfs_inode *raw_inode)
471{
472 return nilfs_read_inode_common(dat, raw_inode);
473}
474
475/**
476 * nilfs_dat_new - create dat file
477 * @nilfs: nilfs object
478 * @entry_size: size of a dat entry 468 * @entry_size: size of a dat entry
469 * @raw_inode: on-disk dat inode
470 * @inodep: buffer to store the inode
479 */ 471 */
480struct inode *nilfs_dat_new(struct the_nilfs *nilfs, size_t entry_size) 472int nilfs_dat_read(struct super_block *sb, size_t entry_size,
473 struct nilfs_inode *raw_inode, struct inode **inodep)
481{ 474{
482 static struct lock_class_key dat_lock_key; 475 static struct lock_class_key dat_lock_key;
483 struct inode *dat; 476 struct inode *dat;
484 struct nilfs_dat_info *di; 477 struct nilfs_dat_info *di;
485 int err; 478 int err;
486 479
487 dat = nilfs_mdt_new(nilfs, NULL, NILFS_DAT_INO, sizeof(*di)); 480 dat = nilfs_iget_locked(sb, NULL, NILFS_DAT_INO);
488 if (dat) { 481 if (unlikely(!dat))
489 err = nilfs_palloc_init_blockgroup(dat, entry_size); 482 return -ENOMEM;
490 if (unlikely(err)) { 483 if (!(dat->i_state & I_NEW))
491 nilfs_mdt_destroy(dat); 484 goto out;
492 return NULL;
493 }
494 485
495 di = NILFS_DAT_I(dat); 486 err = nilfs_mdt_init(dat, NILFS_MDT_GFP, sizeof(*di));
496 lockdep_set_class(&di->mi.mi_sem, &dat_lock_key); 487 if (err)
497 nilfs_palloc_setup_cache(dat, &di->palloc_cache); 488 goto failed;
498 nilfs_mdt_setup_shadow_map(dat, &di->shadow); 489
499 } 490 err = nilfs_palloc_init_blockgroup(dat, entry_size);
500 return dat; 491 if (err)
492 goto failed;
493
494 di = NILFS_DAT_I(dat);
495 lockdep_set_class(&di->mi.mi_sem, &dat_lock_key);
496 nilfs_palloc_setup_cache(dat, &di->palloc_cache);
497 nilfs_mdt_setup_shadow_map(dat, &di->shadow);
498
499 err = nilfs_read_inode_common(dat, raw_inode);
500 if (err)
501 goto failed;
502
503 unlock_new_inode(dat);
504 out:
505 *inodep = dat;
506 return 0;
507 failed:
508 iget_failed(dat);
509 return err;
501} 510}