ocfs2: add online file check feature
cover ocfs2: add online file check feature
When there are errors in the ocfs2 filesystem,
they are usually accompanied by the inode number which caused the error. This inode number would be the input to fixing the file.
One of these options could be considered:
A file in the sys filesytem which would accept inode numbers. This could be used to communication back what has to be fixed or is fixed. You could write:
$# echo "CHECK <inode>" > /sys/fs/ocfs2/devname/filecheck
or
$# echo "FIX <inode>" > /sys/fs/ocfs2/devname/filecheck
Gang He (4):
ocfs2: export ocfs2_kset for online file check
ocfs2: sysfile interfaces for online file check
ocfs2: create/remove sysfile for online file check
ocfs2: check/fix inode block for online file check
fs/ocfs2/Makefile | 3 +- fs/ocfs2/filecheck.c | 569 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/ocfs2/filecheck.h | 48 +++++ fs/ocfs2/inode.c | 196 ++++++++++++++++- fs/ocfs2/inode.h | 3 + fs/ocfs2/ocfs2_trace.h | 2 + fs/ocfs2/stackglue.c | 3 +- fs/ocfs2/stackglue.h | 2 + fs/ocfs2/super.c | 5 + 9 files changed, 823 insertions(+), 8 deletions(-) create mode 100644 fs/ocfs2/filecheck.c create mode 100644 fs/ocfs2/filecheck.h
Signature · 1 line
2.1.2
PATCH 1/4 ocfs2: export ocfs2_kset for online file check
Export ocfs2_kset object from ocfs2_stackglue kernel module, then online file check code will create the related sysfiles under ocfs2_kset object.
--- fs/ocfs2/stackglue.c | 3 ++- fs/ocfs2/stackglue.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-)
fs/ocfs2/stackglue.c +2 -1
@@ -629,7 +629,8 @@ static struct attribute_group ocfs2_attr_group = { .attrs = ocfs2_attrs, }; -static struct kset *ocfs2_kset; +struct kset *ocfs2_kset; +EXPORT_SYMBOL_GPL (ocfs2_kset);static void ocfs2_sysfs_exit (void ) {
fs/ocfs2/stackglue.h +2 -0
@@ -298,4 +298,6 @@ void ocfs2_stack_glue_set_max_proto_version(struct ocfs2_protocol_version *max_pint ocfs2_stack_glue_register (struct ocfs2_stack_plugin *plugin);void ocfs2_stack_glue_unregister (struct ocfs2_stack_plugin *plugin); +extern struct kset *ocfs2_kset; +#endif /* STACKGLUE_H */
Signature · 1 line
2.1.2
PATCH 2/4 ocfs2: sysfile interfaces for online file check
In reply to Gang HeImplement online file check sysfile interfaces, e.g. how to create the related sysfile according to device name, how to display/handle file check request from the sysfile.
--- fs/ocfs2/Makefile | 3 +- fs/ocfs2/filecheck.c | 569 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/ocfs2/filecheck.h | 48 +++++ fs/ocfs2/inode.h | 3 + 4 files changed, 622 insertions(+), 1 deletion(-) create mode 100644 fs/ocfs2/filecheck.c create mode 100644 fs/ocfs2/filecheck.h
fs/ocfs2/Makefile +2 -1
@@ -41,7 +41,8 @@ ocfs2-objs := \ quota_local.o \ quota_global.o \ xattr.o \ - acl.o + acl.o \ + filecheck.o ocfs2_stackglue-objs := stackglue.o ocfs2_stack_o2cb-objs := stack_o2cb.o
fs/ocfs2/filecheck.c new file +569 -0
569 lines not on this page · raw message
fs/ocfs2/filecheck.h new file +48 -0
48 lines not on this page · raw message
fs/ocfs2/inode.h +3 -0
@@ -139,6 +139,9 @@ int ocfs2_drop_inode(struct inode *inode);/* Flags for ocfs2_iget() */ #define OCFS2_FI_FLAG_SYSFILE 0x1#define OCFS2_FI_FLAG_ORPHAN_RECOVERY 0x2 +#define OCFS2_FI_FLAG_FILECHECK_CHK 0x4 +#define OCFS2_FI_FLAG_FILECHECK_FIX 0x8 +struct inode *ocfs2_ilookup (struct super_block *sb,u64 feoff);struct inode *ocfs2_iget (struct ocfs2_super *osb,u64 feoff,unsigned flags,int sysfile_type);
Signature · 1 line
2.1.2
PATCH 3/4 ocfs2: create/remove sysfile for online file check
In reply to Gang HeCreate online file check sysfile when ocfs2 mount, remove the related sysfile when ocfs2 umount.
--- fs/ocfs2/super.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/ocfs2/super.c +5 -0
@@ -74,6 +74,7 @@#include "suballoc.h" #include "buffer_head_io.h" +#include "filecheck.h" static struct kmem_cache *ocfs2_inode_cachep;struct kmem_cache *ocfs2_dquot_cachep;
@@ -1202,6 +1203,9 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)/* Start this when the mount is almost sure of being successful */ ocfs2_orphan_scan_start (osb); +/* Create filecheck sysfile /sys/fs/ocfs2/<devname>/filecheck */ +ocfs2_filecheck_create_sysfs (sb); +return status; read_super_error:
@@ -1658,6 +1662,7 @@ static void ocfs2_put_super(struct super_block *sb)ocfs2_sync_blockdev (sb);ocfs2_dismount_volume (sb,0 ); +ocfs2_filecheck_remove_sysfs (sb); }static int ocfs2_statfs (struct dentry *dentry,struct kstatfs *buf)
Signature · 1 line
2.1.2
PATCH 4/4 ocfs2: check/fix inode block for online file check
In reply to Gang HeImplement online check or fix inode block during
reading a inode block to memory.
--- fs/ocfs2/inode.c | 196 +++++++++++++++++++++++++++++++++++++++++++++++-- fs/ocfs2/ocfs2_trace.h | 2 + 2 files changed, 192 insertions(+), 6 deletions(-)
fs/ocfs2/inode.c +190 -6
@@ -53,6 +53,7 @@#include "xattr.h" #include "refcounttree.h" #include "ocfs2_trace.h" +#include "filecheck.h" #include "buffer_head_io.h"
@@ -74,6 +75,13 @@ static int ocfs2_truncate_for_delete(struct ocfs2_super *osb,struct inode *inode, struct buffer_head *fe_bh); +static int ocfs2_filecheck_read_inode_block_full (struct inode *inode, +struct buffer_head **bh,int flags,int type); +static int ocfs2_filecheck_validate_inode_block (struct super_block *sb, +struct buffer_head *bh); +static int ocfs2_filecheck_repair_inode_block (struct super_block *sb, +struct buffer_head *bh); +void ocfs2_set_inode_flags (struct inode *inode) {unsigned int flags =OCFS2_I (inode)->ip_attr;
@@ -127,6 +135,7 @@ struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)struct inode *ocfs2_iget (struct ocfs2_super *osb,u64 blkno,unsigned flags,int sysfile_type) { +int rc =0 ;struct inode *inode =NULL ;struct super_block *sb = osb->sb;struct ocfs2_find_inode_args args;
@@ -161,12 +170,17 @@ struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned flags, }trace_ocfs2_iget5_locked (inode->i_state);if (inode->i_state &I_NEW ) { -ocfs2_read_locked_inode (inode, &args); + rc =ocfs2_read_locked_inode (inode, &args);unlock_new_inode (inode); }if (is_bad_inode (inode)) {iput (inode); - inode =ERR_PTR (-ESTALE ); +if ((flags &OCFS2_FI_FLAG_FILECHECK_CHK ) || + (flags &OCFS2_FI_FLAG_FILECHECK_FIX )) +/* Return OCFS2_FILECHECK_ERR_XXX related errno */ + inode =ERR_PTR (rc); +else + inode =ERR_PTR (-ESTALE ); goto bail; }
@@ -494,16 +508,32 @@ static int ocfs2_read_locked_inode(struct inode *inode, }if (can_lock) { - status =ocfs2_read_inode_block_full (inode, &bh, -OCFS2_BH_IGNORE_CACHE ); +if (args->fi_flags &OCFS2_FI_FLAG_FILECHECK_CHK ) + status =ocfs2_filecheck_read_inode_block_full (inode, + &bh,OCFS2_BH_IGNORE_CACHE ,0 ); +else if (args->fi_flags &OCFS2_FI_FLAG_FILECHECK_FIX ) + status =ocfs2_filecheck_read_inode_block_full (inode, + &bh,OCFS2_BH_IGNORE_CACHE ,1 ); +else + status =ocfs2_read_inode_block_full (inode, + &bh,OCFS2_BH_IGNORE_CACHE ); }else { status =ocfs2_read_blocks_sync (osb, args->fi_blkno,1 , &bh);/* * If buffer is in jbd, then its checksum may not have been * computed as yet. */ -if (!status && !buffer_jbd (bh)) - status =ocfs2_validate_inode_block (osb->sb, bh); +if (!status && !buffer_jbd (bh)) { +if (args->fi_flags &OCFS2_FI_FLAG_FILECHECK_CHK ) + status =ocfs2_filecheck_validate_inode_block ( + osb->sb, bh); +else if (args->fi_flags &OCFS2_FI_FLAG_FILECHECK_FIX ) + status =ocfs2_filecheck_repair_inode_block ( + osb->sb, bh); +else + status =ocfs2_validate_inode_block ( + osb->sb, bh); + } }if (status <0 ) {mlog_errno (status);
@@ -531,6 +561,14 @@ static int ocfs2_read_locked_inode(struct inode *inode,BUG_ON (args->fi_blkno !=le64_to_cpu (fe->i_blkno)); +if (buffer_dirty (bh)) { + status =ocfs2_write_block (osb, bh,INODE_CACHE (inode)); +if (status <0 ) { +mlog_errno (status); + goto bail; + } + } + status =0 ; bail:
@@ -1385,6 +1423,152 @@ bail:return rc; } +static int ocfs2_filecheck_validate_inode_block (struct super_block *sb, +struct buffer_head *bh) +{ +int rc =0 ; +struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data; + +trace_ocfs2_filecheck_validate_inode_block ( + (unsigned long long )bh->b_blocknr); + +BUG_ON (!buffer_uptodate (bh)); + +if (!OCFS2_IS_VALID_DINODE (di)) { +mlog (ML_ERROR , +"Filecheck: invalid dinode #%llu: signature = %.*s\n" , + (unsigned long long )bh->b_blocknr,7 , di->i_signature); + rc = -OCFS2_FILECHECK_ERR_INVALIDINO ; + goto bail; + } + + rc =ocfs2_validate_meta_ecc (sb, bh->b_data, &di->i_check); +if (rc) { +mlog (ML_ERROR , +"Filecheck: checksum failed for dinode %llu\n" , + (unsigned long long )bh->b_blocknr); + rc = -OCFS2_FILECHECK_ERR_BLOCKECC ; + goto bail; + } + +if (le64_to_cpu (di->i_blkno) != bh->b_blocknr) { +mlog (ML_ERROR , +"Filecheck: invalid dinode #%llu: i_blkno is %llu\n" , + (unsigned long long )bh->b_blocknr, + (unsigned long long )le64_to_cpu (di->i_blkno)); + rc = -OCFS2_FILECHECK_ERR_BLOCKNO ; + goto bail; + } + +if (!(di->i_flags &cpu_to_le32 (OCFS2_VALID_FL ))) { +mlog (ML_ERROR , +"Filecheck: invalid dinode #%llu: OCFS2_VALID_FL not set\n" , + (unsigned long long )bh->b_blocknr); + rc = -OCFS2_FILECHECK_ERR_VALIDFLAG ; + goto bail; + } + +if (le32_to_cpu (di->i_fs_generation) != +OCFS2_SB (sb)->fs_generation) { +mlog (ML_ERROR , +"Filecheck: invalid dinode #%llu: fs_generation is %u\n" , + (unsigned long long )bh->b_blocknr, +le32_to_cpu (di->i_fs_generation)); + rc = -OCFS2_FILECHECK_ERR_GENERATION ; + goto bail; + } + +bail: +return rc; +} + +static int ocfs2_filecheck_repair_inode_block (struct super_block *sb, +struct buffer_head *bh) +{ +int rc; +int changed =0 ; +struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data; + + rc =ocfs2_filecheck_validate_inode_block (sb, bh); +/* Can't fix invalid inode block */ +if (!rc || rc == -OCFS2_FILECHECK_ERR_INVALIDINO ) +return rc; + +trace_ocfs2_filecheck_repair_inode_block ( + (unsigned long long )bh->b_blocknr); + +if (ocfs2_is_hard_readonly (OCFS2_SB (sb)) || +ocfs2_is_soft_readonly (OCFS2_SB (sb))) { +mlog (ML_ERROR , +"Filecheck: try to repair dinode #%llu on readonly filesystem\n" , + (unsigned long long )bh->b_blocknr); +return -OCFS2_FILECHECK_ERR_READONLY ; + } + +if (le64_to_cpu (di->i_blkno) != bh->b_blocknr) { + di->i_blkno =cpu_to_le64 (bh->b_blocknr); + changed =1 ; +mlog (ML_ERROR , +"Filecheck: reset dinode #%llu: i_blkno to %llu\n" , + (unsigned long long )bh->b_blocknr, + (unsigned long long )le64_to_cpu (di->i_blkno)); + } + +if (!(di->i_flags &cpu_to_le32 (OCFS2_VALID_FL ))) { + di->i_flags |=cpu_to_le32 (OCFS2_VALID_FL ); + changed =1 ; +mlog (ML_ERROR , +"Filecheck: reset dinode #%llu: OCFS2_VALID_FL is set\n" , + (unsigned long long )bh->b_blocknr); + } + +if (le32_to_cpu (di->i_fs_generation) != +OCFS2_SB (sb)->fs_generation) { + di->i_fs_generation =cpu_to_le32 (OCFS2_SB (sb)->fs_generation); + changed =1 ; +mlog (ML_ERROR , +"Filecheck: reset dinode #%llu: fs_generation to %u\n" , + (unsigned long long )bh->b_blocknr, +le32_to_cpu (di->i_fs_generation)); + } + +if (changed || +ocfs2_validate_meta_ecc (sb, bh->b_data, &di->i_check)) { +ocfs2_compute_meta_ecc (sb, bh->b_data, &di->i_check); +mark_buffer_dirty (bh); +mlog (ML_ERROR , +"Filecheck: reset dinode #%llu: compute meta ecc\n" , + (unsigned long long )bh->b_blocknr); + } + +return 0 ; +} + +static int +ocfs2_filecheck_read_inode_block_full (struct inode *inode, +struct buffer_head **bh,int flags,int type) +{ +int rc; +struct buffer_head *tmp = *bh; + +if (!type)/* Check inode block */ + rc =ocfs2_read_blocks (INODE_CACHE (inode), +OCFS2_I (inode)->ip_blkno, +1 , &tmp, flags, + ocfs2_filecheck_validate_inode_block); +else /* Repair inode block */ + rc =ocfs2_read_blocks (INODE_CACHE (inode), +OCFS2_I (inode)->ip_blkno, +1 , &tmp, flags, + ocfs2_filecheck_repair_inode_block); + +/* If ocfs2_read_blocks() got us a new bh, pass it up. */ +if (!rc && !*bh) + *bh = tmp; + +return rc; +} +int ocfs2_read_inode_block_full (struct inode *inode,struct buffer_head **bh,int flags) {
fs/ocfs2/ocfs2_trace.h +2 -0
@@ -1540,6 +1540,8 @@ DEFINE_OCFS2_ULL_INT_EVENT(ocfs2_read_locked_inode);DEFINE_OCFS2_INT_INT_EVENT (ocfs2_check_orphan_recovery_state);DEFINE_OCFS2_ULL_EVENT (ocfs2_validate_inode_block); +DEFINE_OCFS2_ULL_EVENT (ocfs2_filecheck_validate_inode_block); +DEFINE_OCFS2_ULL_EVENT (ocfs2_filecheck_repair_inode_block); TRACE_EVENT(ocfs2_inode_is_valid_to_delete, TP_PROTO(void *task, void *dc_task, unsigned long long ino,
Signature · 1 line
2.1.2
Hi Gang,
Thank you and Goldwyn for posting this feature as well as its framework. This patch set tries to fix inode related errors such as block no, valid flag, generation, metaecc, etc. I think it may fit some cases but not all. For example, valid flag not set readonly may be caused by an inode with two entries, so I think it is not right to just reset it. Moreover, in our environment, most readonly cases we have encountered are related gd and entent tree/block. So do you have any consideration about these cases?
For more details about gd and entent tree/block readonly cases, please refer the previous mails:
https://oss.oracle.com/pipermail/ocfs2-devel/2015-April/010768.html
https://oss.oracle.com/pipermail/ocfs2-devel/2015-June/010873.html
Thanks,
Joseph
Quoted 30 lines · Gang He
When there are errors in the ocfs2 filesystem,
they are usually accompanied by the inode number which caused the error. This inode number would be the input to fixing the file.
One of these options could be considered:
A file in the sys filesytem which would accept inode numbers. This could be used to communication back what has to be fixed or is fixed. You could write:
$# echo "CHECK <inode>" >/sys/fs/ocfs2/devname/filecheck
or
$# echo "FIX <inode>" >/sys/fs/ocfs2/devname/filecheckGang He (4):
ocfs2: exportocfs2_ksetfor online file check
ocfs2: sysfile interfaces for online file check
ocfs2: create/remove sysfile for online file check
ocfs2: check/fix inode block for online file checkfs/ocfs2/Makefile | 3 +- fs/ocfs2/filecheck.c | 569 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/ocfs2/filecheck.h | 48 +++++ fs/ocfs2/inode.c | 196 ++++++++++++++++- fs/ocfs2/inode.h | 3 + fs/ocfs2/ocfs2_trace.h | 2 + fs/ocfs2/stackglue.c | 3 +- fs/ocfs2/stackglue.h | 2 + fs/ocfs2/super.c | 5 + 9 files changed, 823 insertions(+), 8 deletions(-) create mode 100644 fs/ocfs2/filecheck.c create mode 100644 fs/ocfs2/filecheck.h
Hi Joseph,
Thank for your reviewing.
Online file check feature will try to check/fix some independent block corruption problems.
Since these operations are under online file system, the features are limited, otherwise, we have
to use FSCK tools after file system is unmounted (e.g. some inconsistent meta-data problem).
This online file check will be implemented by some stages.
First, we give a online file check framework and inode block check.
Second, we will add other kinds of block check/fix, e.g.
Add checks/fixes for directory blocks.
Add checks/fixes for extent_block errors/corruption
Add checks/fixes directory indexing. fsck currently abandons the tree and rebuilds a new index, we can do the same. Add checks/fixes for xattr blocks
Add checks/fixes for refcount blocks
Finally, add system file checks (journal, local_alloc etc).
Anyway, this feature only can address some independent problems, since we cannot block other file access when file check is running. For more serious problem, have to stop file system and run FSCK to chech/fix step by step.
Thanks
Gang
Quoted 50 lines
Quoted 1 line
Quoted 1 line
Hi Gang,
Thank you and Goldwyn for posting this feature as well as its framework. This patch set tries to fix inode related errors such as block no, valid flag, generation, metaecc, etc. I think it may fit some cases but not all. For example, valid flag not set readonly may be caused by an inode with two entries, so I think it is not right to just reset it. Moreover, in our environment, most readonly cases we have encountered are related gd and entent tree/block. So do you have any consideration about these cases?
For more details about gd and entent tree/block readonly cases, please refer the previous mails:
https://oss.oracle.com/pipermail/ocfs2-devel/2015-April/010768.html
https://oss.oracle.com/pipermail/ocfs2-devel/2015-June/010873.htmlThanks,
JosephQuoted 11 lines · Gang He
When there are errors in the ocfs2 filesystem,
they are usually accompanied by the inode number which caused the error. This inode number would be the input to fixing the file.
One of these options could be considered:
A file in the sys filesytem which would accept inode numbers. This could be used to communication back what has to be fixed or is fixed. You could write:
$# echo "CHECK <inode>" >/sys/fs/ocfs2/devname/filecheck
or
$# echo "FIX <inode>" >/sys/fs/ocfs2/devname/filecheckQuoted 8 lines
Gang He (4):
ocfs2: exportocfs2_ksetfor online file check
ocfs2: sysfile interfaces for online file check
ocfs2: create/remove sysfile for online file check
ocfs2: check/fix inode block for online file checkfs/ocfs2/Makefile | 3 +- fs/ocfs2/filecheck.c | 569+++++++++++++++++++++++++++++++++++++++++++++++++
Quoted 11 lines
fs/ocfs2/filecheck.h | 48 +++++ fs/ocfs2/inode.c | 196 ++++++++++++++++- fs/ocfs2/inode.h | 3 + fs/ocfs2/ocfs2_trace.h | 2 + fs/ocfs2/stackglue.c | 3 +- fs/ocfs2/stackglue.h | 2 + fs/ocfs2/super.c | 5 + 9 files changed, 823 insertions(+), 8 deletions(-) create mode 100644 fs/ocfs2/filecheck.c create mode 100644 fs/ocfs2/filecheck.h
Quoted 10 lines · On Wed, 24 Jun 2015 13:24:17 +0800 Gang He <[email protected]> wrote:
When there are errors in the ocfs2 filesystem,
they are usually accompanied by the inode number which caused the error. This inode number would be the input to fixing the file.
One of these options could be considered:
A file in the sys filesytem which would accept inode numbers. This could be used to communication back what has to be fixed or is fixed. You could write:
$# echo "CHECK <inode>" >/sys/fs/ocfs2/devname/filecheck
or
$# echo "FIX <inode>" >/sys/fs/ocfs2/devname/filecheck
This is a userspace feature so it should have user documentation. Documentation/filesystems/ocfs2.txt is presumably the appropriate place.
And the availability of the complete user documentation will make the review of this patchset more productive.
Hi Andrew,
Thank for your suggestions.
I will sort out a document for ocfs2 online file check feature.
Thanks
Gang
Quoted 20 lines
Quoted 1 line
Quoted 1 line
Quoted 10 lines · On Wed, 24 Jun 2015 13:24:17 +0800 Gang He <[email protected]> wrote:
When there are errors in the ocfs2 filesystem,
they are usually accompanied by the inode number which caused the error. This inode number would be the input to fixing the file.
One of these options could be considered:
A file in the sys filesytem which would accept inode numbers. This could be used to communication back what has to be fixed or is fixed. You could write:
$# echo "CHECK <inode>" >/sys/fs/ocfs2/devname/filecheck
or
$# echo "FIX <inode>" >/sys/fs/ocfs2/devname/filecheckThis is a userspace feature so it should have user documentation.
Documentation/filesystems/ocfs2.txtis presumably the appropriate place.And the availability of the complete user documentation will make the review of this patchset more productive.