f2fs-tools: support zoned ufs devices
PATCH 1/1 f2fs-tools: support zoned ufs devices
From: Daeho Jeong <[email protected]>
Support zoned ufs devices.
1. implemented out-place updates
2. keep roll forward recovery intact
3. open block device files with O_SYNC to comply with zoned device's write rules
Signed-off-by Daeho Jeong <[email protected]>
--- fsck/defrag.c | 2 +- fsck/dir.c | 47 +++++++++++---- fsck/f2fs.h | 3 +- fsck/fsck.c | 96 +++++++++++++++++++------------ fsck/fsck.h | 31 +++++++--- fsck/main.c | 3 + fsck/mount.c | 151 ++++++++++++++++++++++++++++++++++++++++--------- fsck/node.c | 30 ++++++++-- fsck/node.h | 1 + fsck/resize.c | 2 +- fsck/segment.c | 120 ++++++++++++++++++++++++++++++++++----- fsck/xattr.c | 7 ++- lib/libf2fs.c | 32 +++++++---- 13 files changed, 405 insertions(+), 120 deletions(-)
fsck/defrag.c +1 -1
@@ -49,7 +49,7 @@ static int migrate_block(struct f2fs_sb_info *sbi, u64 from, u64 to)/* if data block, read node and update node block */ if (IS_DATASEG (type))update_data_blkaddr (sbi,le32_to_cpu (sum.nid), -le16_to_cpu (sum.ofs_in_node), to); +le16_to_cpu (sum.ofs_in_node), to,NULL );else update_nat_blkaddr (sbi,0 ,le32_to_cpu (sum.nid), to);
fsck/dir.c +36 -11
143 lines not on this page · raw message
fsck/f2fs.h +2 -1
@@ -189,6 +189,7 @@ struct curseg_info {struct f2fs_sm_info {struct sit_info *sit_info;struct curseg_info *curseg_array; +struct curseg_info saved_curseg_warm_node;block_t seg0_blkaddr;block_t main_blkaddr;
@@ -238,7 +239,7 @@ struct dnode_of_data {unsigned int ofs_in_node;block_t data_blkaddr;block_t node_blkaddr; -int idirty, ndirty; +int idirty, ndirty, alloced; };struct hardlink_cache_entry {
fsck/fsck.c +60 -36
234 lines not on this page · raw message
fsck/fsck.h +24 -7
@@ -153,8 +153,7 @@ struct selabel_handle;static inline bool need_fsync_data_record (struct f2fs_sb_info *sbi) { -return !is_set_ckpt_flags (F2FS_CKPT (sbi),CP_UMOUNT_FLAG ) || - c.zoned_model ==F2FS_ZONED_HM ; +return !is_set_ckpt_flags (F2FS_CKPT (sbi),CP_UMOUNT_FLAG ); }extern int fsck_chk_orphan_node (struct f2fs_sb_info *);
@@ -181,9 +180,10 @@ extern int fsck_chk_didnode_blk(struct f2fs_sb_info *, struct f2fs_inode *, enum FILE_TYPE, struct f2fs_node *, u32 *, struct f2fs_compr_blk_cnt *, struct child_info *);extern int fsck_chk_data_blk (struct f2fs_sb_info *,int , -u32 ,struct child_info *,int ,enum FILE_TYPE ,u32 ,u16 ,u8 ,int ); +u32 ,struct child_info *,int ,enum FILE_TYPE ,u32 ,u16 ,u8 , +int ,struct f2fs_node *);extern int fsck_chk_dentry_blk (struct f2fs_sb_info *,int , -u32 ,struct child_info *,int ,int ); +u32 ,struct child_info *,int ,int ,struct f2fs_node *);int fsck_chk_inline_dentries (struct f2fs_sb_info *,struct f2fs_node *,struct child_info *);void fsck_chk_checkpoint (struct f2fs_sb_info *sbi);
@@ -209,7 +209,9 @@ extern void rewrite_sit_area_bitmap(struct f2fs_sb_info *);extern void build_nat_area_bitmap (struct f2fs_sb_info *);extern void build_sit_area_bitmap (struct f2fs_sb_info *);extern int f2fs_set_main_bitmap (struct f2fs_sb_info *,u32 ,int ); +extern int f2fs_clear_main_bitmap (struct f2fs_sb_info *,u32 );extern int f2fs_set_sit_bitmap (struct f2fs_sb_info *,u32 ); +extern int f2fs_clear_sit_bitmap (struct f2fs_sb_info *,u32 );extern void fsck_init (struct f2fs_sb_info *);extern int fsck_verify (struct f2fs_sb_info *);extern void fsck_free (struct f2fs_sb_info *);
@@ -225,13 +227,18 @@ extern void update_curseg_info(struct f2fs_sb_info *, int);extern void zero_journal_entries (struct f2fs_sb_info *);extern void flush_sit_entries (struct f2fs_sb_info *);extern void move_curseg_info (struct f2fs_sb_info *,u64 ,int ); +extern void move_one_curseg_info (struct f2fs_sb_info *sbi,u64 from,int left, +int i);extern void write_curseg_info (struct f2fs_sb_info *); +extern void save_curseg_warm_node_info (struct f2fs_sb_info *); +extern void restore_curseg_warm_node_info (struct f2fs_sb_info *);extern int find_next_free_block (struct f2fs_sb_info *,u64 *,int ,int ,bool );extern void duplicate_checkpoint (struct f2fs_sb_info *);extern void write_checkpoint (struct f2fs_sb_info *);extern void write_checkpoints (struct f2fs_sb_info *);extern void update_superblock (struct f2fs_super_block *,int ); -extern void update_data_blkaddr (struct f2fs_sb_info *,nid_t ,u16 ,block_t ); +extern void update_data_blkaddr (struct f2fs_sb_info *,nid_t ,u16 ,block_t , +struct f2fs_node *);extern void update_nat_blkaddr (struct f2fs_sb_info *,nid_t ,nid_t ,block_t );extern void print_raw_sb_info (struct f2fs_super_block *);
@@ -294,6 +301,8 @@ void set_data_blkaddr(struct dnode_of_data *);block_t new_node_block (struct f2fs_sb_info *,struct dnode_of_data *,unsigned int );int f2fs_rebuild_qf_inode (struct f2fs_sb_info *sbi,int qtype); +int update_block (struct f2fs_sb_info *sbi,void *buf,u32 *blkaddr, +struct f2fs_node *node_blk);/* segment.c */ struct quota_file ;
@@ -321,7 +330,7 @@ int inode_set_selinux(struct f2fs_sb_info *, u32, const char *);int f2fs_find_path (struct f2fs_sb_info *,char *,nid_t *);nid_t f2fs_lookup (struct f2fs_sb_info *,struct f2fs_node *,u8 *,int );int f2fs_add_link (struct f2fs_sb_info *,struct f2fs_node *, -const unsigned char *,int ,nid_t ,int ,block_t ,int ); +const unsigned char *,int ,nid_t ,int ,block_t *,int );struct hardlink_cache_entry *f2fs_search_hardlink (struct f2fs_sb_info *sbi,struct dentry *de);
@@ -332,6 +341,14 @@ void write_all_xattrs(struct f2fs_sb_info *sbi,/* dir.c */ int convert_inline_dentry (struct f2fs_sb_info *sbi,struct f2fs_node *node, -block_t p_blkaddr); +block_t *p_blkaddr); + +/* node.c */ +int update_inode (struct f2fs_sb_info *sbi,struct f2fs_node *inode, +u32 *blkaddr); + +/* mount.c */ +int flush_nat_journal_entries (struct f2fs_sb_info *sbi); +int flush_sit_journal_entries (struct f2fs_sb_info *sbi);#endif /* _FSCK_H_ */
fsck/main.c +3 -0
@@ -834,6 +834,9 @@ static int do_fsck(struct f2fs_sb_info *sbi)print_cp_state (flag); +if (c.roll_forward && c.zoned_model ==F2FS_ZONED_HM ) +save_curseg_warm_node_info (sbi); +fsck_chk_and_fix_write_pointers (sbi);fsck_chk_curseg_info (sbi);
fsck/mount.c +123 -28
265 lines not on this page · raw message
fsck/node.c +24 -6
@@ -69,6 +69,8 @@ int f2fs_rebuild_qf_inode(struct f2fs_sb_info *sbi, int qtype)F2FS_NODE_FOOTER (raw_node)->cp_ver =cpu_to_le64 (cp_ver);get_node_info (sbi, ino, &ni); +if (ni.ino != ino) + ni.version =0 ;set_summary (&sum, ino,0 , ni.version); ret =reserve_new_block (sbi, &blkaddr, &sum,CURSEG_HOT_NODE ,1 );if (ret) {
@@ -255,6 +257,7 @@ int get_dnode_of_data(struct f2fs_sb_info *sbi, struct dnode_of_data *dn,block_t nblk[4 ];struct node_info ni;int level, i; +bool parent_alloced = false;int ret; level =get_node_path (dn->inode_blk, index, offset, noffset);
@@ -274,6 +277,14 @@ int get_dnode_of_data(struct f2fs_sb_info *sbi, struct dnode_of_data *dn,f2fs_alloc_nid (sbi, &nids[i]); dn->nid = nids[i]; +set_nid (parent, offset[i -1 ], nids[i], i ==1 ); + +/* Parent node has changed */ +if (!parent_alloced) + ret =update_block (sbi, parent, &nblk[i -1 ],NULL ); +else + ret =dev_write_block (parent, nblk[i -1 ]); +ASSERT (ret >=0 );/* Function new_node_blk get a new f2fs_node blk and update*/ /* We should make sure that dn->node_blk == NULL*/
@@ -284,7 +295,9 @@ int get_dnode_of_data(struct f2fs_sb_info *sbi, struct dnode_of_data *dn,return -EINVAL ; } -set_nid (parent, offset[i -1 ], nids[i], i ==1 ); + parent_alloced = true; +if (i == level) + dn->alloced =1 ; }else {/* If Sparse file no read API, */ struct node_info ni;
@@ -299,11 +312,6 @@ int get_dnode_of_data(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, nblk[i] = ni.blk_addr; } -if (mode ==ALLOC_NODE ){ -/* Parent node may have changed */ - ret =dev_write_block (parent, nblk[i -1 ]); -ASSERT (ret >=0 ); - }if (i !=1 )free (parent);
@@ -319,3 +327,13 @@ int get_dnode_of_data(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, dn->node_blkaddr = nblk[level];return 0 ; } + +int update_inode (struct f2fs_sb_info *sbi,struct f2fs_node *inode, +u32 *blkaddr) +{ +if (c.feature &cpu_to_le32 (F2FS_FEATURE_INODE_CHKSUM )) + inode->i.i_inode_checksum = +cpu_to_le32 (f2fs_inode_chksum (inode)); +return update_block (sbi, inode, blkaddr,NULL ); +} +
fsck/node.h +1 -0
@@ -99,6 +99,7 @@ static inline void set_new_dnode(struct dnode_of_data *dn, dn->nid = nid; dn->idirty =0 ; dn->ndirty =0 ; + dn->alloced =0 ; }static inline void inc_inode_blocks (struct dnode_of_data *dn)
fsck/resize.c +1 -1
@@ -196,7 +196,7 @@ static void migrate_main(struct f2fs_sb_info *sbi, unsigned int offset)if (IS_DATASEG (se->type))update_data_blkaddr (sbi,le32_to_cpu (sum.nid), -le16_to_cpu (sum.ofs_in_node), to); +le16_to_cpu (sum.ofs_in_node), to,NULL );else update_nat_blkaddr (sbi,0 ,le32_to_cpu (sum.nid), to);
fsck/segment.c +105 -15
204 lines not on this page · raw message
fsck/xattr.c +5 -2
@@ -94,6 +94,7 @@ void write_all_xattrs(struct f2fs_sb_info *sbi,nid_t xnid =le32_to_cpu (inode->i.i_xattr_nid);u64 inline_size =inline_xattr_size (&inode->i);int ret; +bool xattrblk_alloced = false;memcpy (inline_xattr_addr (&inode->i), txattr_addr, inline_size);
@@ -109,6 +110,7 @@ void write_all_xattrs(struct f2fs_sb_info *sbi,ASSERT (dn.node_blk); xattr_node = dn.node_blk; inode->i.i_xattr_nid =cpu_to_le32 (new_nid); + xattrblk_alloced = true; }else {set_new_dnode (&dn, inode,NULL , xnid);get_node_info (sbi, xnid, &ni);
@@ -125,7 +127,8 @@ void write_all_xattrs(struct f2fs_sb_info *sbi,memcpy (xattr_addr, txattr_addr + inline_size,F2FS_BLKSIZE -sizeof (struct node_footer )); - ret =dev_write_block (xattr_node, blkaddr); + ret = xattrblk_alloced ?dev_write_block (xattr_node, blkaddr) : +update_block (sbi, xattr_node, &blkaddr,NULL ); free_xattr_node:free (xattr_node);
@@ -250,7 +253,7 @@ int f2fs_setxattr(struct f2fs_sb_info *sbi, nid_t ino, int index, const char *nawrite_all_xattrs (sbi, inode, new_hsize, base_addr);/* inode need update */ -ASSERT (write_inode (inode, ni.blk_addr) >=0 ); +ASSERT (update_inode (sbi, inode, &ni.blk_addr) >=0 ); exit:free (inode);free (base_addr);
lib/libf2fs.c +20 -12
@@ -919,6 +919,7 @@ int get_device_info(int i)unsigned char model_inq[6 ] = {MODELINQUIRY };#endif struct device_info *dev = c.devices + i; +int flags =O_RDWR ;if (c.sparse_mode) { fd =open (dev->path,O_RDWR |O_CREAT |O_BINARY ,0644 );
@@ -934,20 +935,33 @@ int get_device_info(int i) stat_buf =malloc (sizeof (struct stat ));ASSERT (stat_buf); -if (!c.sparse_mode) { -if (stat (dev->path, stat_buf) <0 ) { -MSG (0 ,"\tError: Failed to get the device stat!\n" ); +if (stat (dev->path, stat_buf) <0 ) { +MSG (0 ,"\tError: Failed to get the device stat!\n" ); +free (stat_buf); +return -1 ; + } + +#ifdef __linux__ +if (S_ISBLK (stat_buf->st_mode)) { +if (f2fs_get_zoned_model (i) <0 ) {free (stat_buf);return -1 ; } + } +#endif + +if (!c.sparse_mode) { +if (dev->zoned_model ==F2FS_ZONED_HM && c.func ==FSCK ) + flags |=O_DSYNC ;if (S_ISBLK (stat_buf->st_mode) && !c.force && c.func !=DUMP && !c.dry_run) { - fd =open (dev->path,O_RDWR |O_EXCL ); + flags |=O_EXCL ; + fd =open (dev->path, flags);if (fd <0 ) fd =open_check_fs (dev->path,O_EXCL ); }else { - fd =open (dev->path,O_RDWR ); + fd =open (dev->path, flags);if (fd <0 ) fd =open_check_fs (dev->path,0 ); }
@@ -1047,13 +1061,6 @@ int get_device_info(int i) }#ifdef __linux__ -if (S_ISBLK (stat_buf->st_mode)) { -if (f2fs_get_zoned_model (i) <0 ) { -free (stat_buf); -return -1 ; - } - } -if (dev->zoned_model !=F2FS_ZONED_NONE ) {/* Get the number of blocks per zones */
@@ -1104,6 +1111,7 @@ int get_device_info(int i) } }#endif +/* adjust wanted_total_sectors */ if (c.wanted_total_sectors !=-1 ) { MSG(0, "Info: wanted sectors = %"PRIu64" (in %"PRIu64" bytes)\n",
Signature · 8 lines
2.43.0.rc2.451.g8631bc7472-goog _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel