Skip to contentSkip to conversation

Add online file check feature

PATCH Superseded Gang He 3 participants 17 messages Dec 25, 2015 – Jan 14, 2016 OCFS2

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Gang He

author
#0 lore raw

v3 cover 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 "<inode>" > /sys/fs/ocfs2/devname/filecheck/check
or
$# echo "<inode>" > /sys/fs/ocfs2/devname/filecheck/fix

Compare with second version, I re-design filecheck sysfs interfaces, there are three sysfs files(check, fix and set) under filecheck directory(see above), sysfs will accept only one argument <inode>. Second, I adjust some code in ocfs2_filecheck_repair_inode_block() function according to upstream feedback, we cannot just add VALID_FL flag back as a inode block fix, then we will not fix this field corruption currently until having a complete solution. Compare with first version, I use strncasecmp instead of double strncmp functions. Second, update the source file contribution vendor.

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   | 605 +++++++++++++++++++++++++++++++++++++++++++++++++
 fs/ocfs2/filecheck.h   |  48 ++++
 fs/ocfs2/inode.c       | 200 +++++++++++++++-
 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, 863 insertions(+), 8 deletions(-)
 create mode 100644 fs/ocfs2/filecheck.c
 create mode 100644 fs/ocfs2/filecheck.h
Signature · 1 line
2.1.2
author
#1 lore raw

PATCH v3 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
index 5d965e8..13219ed 100644
@@ -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
index 66334a3..f2dce10 100644
@@ -298,4 +298,6 @@ void ocfs2_stack_glue_set_max_proto_version(struct ocfs2_protocol_version *max_p
 int 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
#2 lore raw

Re: [PATCH v3 1/4] ocfs2: export ocfs2_kset for online file check

Quoted 9 lines · On Fri, 25 Dec 2015 15:16:16 +0800 Gang He <[email protected]> wrote:

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 static struct attribute_group ocfs2_attr_group = { · line 633

Quoted 6 lines
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);

The EXPORT_SYMBOL is only needed if this symbol is to be referred to from a different module. That isn't the case here - everything which refers to ocfs2_kset is linked into ocfs2.ko, correct?

author
#3 lore raw

Re: [PATCH v3 1/4] ocfs2: export ocfs2_kset for online file check

Hello Andrew,

Quoted 15 lines
Quoted 1 line
Quoted 1 line
Quoted 12 lines · On Fri, 25 Dec 2015 15:16:16 +0800 Gang He <[email protected]> wrote:

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 +0 -0
@@ -629,7 +629,8 @@ static struct attribute_group ocfs2_attr_group = {
 	.attrs = ocfs2_attrs,
 };
 
Quoted 7 lines

fs/ocfs2/stackglue.c static struct attribute_group ocfs2_attr_group = { · line 633

Quoted 3 lines
fs/ocfs2/stackglue.c +2 -1
-static struct kset *ocfs2_kset;
+struct kset *ocfs2_kset;
+EXPORT_SYMBOL_GPL(ocfs2_kset);

The EXPORT_SYMBOL is only needed if this symbol is to be referred to from a different module. That isn't the case here - everything which refers to ocfs2_kset is linked into ocfs2.ko, correct?

There are some kernel modules (Not single KO file) for OCFS2 file system, the variable ocfs2_kset is located in ocfs2_stackglue.ko kernel module, if the main kernel module ocfs2.ko wants to refer to this variable, it looks to have to export this symbol?

Thanks
Gang

Reviewed-by on v3 1/4
#4 lore raw

Re: [PATCH v3 1/4] ocfs2: export ocfs2_kset for online file check

In reply to Gang He
Quoted 5 lines · Gang He

Export ocfs2_kset object from ocfs2_stackglue kernel module, then online file check code will create the related sysfiles under ocfs2_kset object.

This was easy to review, though you might consider adding a note that we're exporting this because it's built in ocfs2_stackglue.ko.

	--Mark
Quoted 38 lines
---
 fs/ocfs2/stackglue.c | 3 ++-
 fs/ocfs2/stackglue.h | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)
fs/ocfs2/stackglue.c +2 -1
index 5d965e8..13219ed 100644
@@ -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
index 66334a3..f2dce10 100644
@@ -298,4 +298,6 @@ void ocfs2_stack_glue_set_max_proto_version(struct ocfs2_protocol_version *max_p
 int 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 · 7 lines
2.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

--
Mark Fasheh

#5 lore raw

Re: [PATCH v3 1/4] ocfs2: export ocfs2_kset for online file check

Quoted 11 lines · On Wed, 13 Jan 2016 15:02:28 -0800 Mark Fasheh <[email protected]> wrote:
Quoted 5 lines · Gang He

Export ocfs2_kset object from ocfs2_stackglue kernel module, then online file check code will create the related sysfiles under ocfs2_kset object.

This was easy to review, though you might consider adding a note that we're exporting this because it's built in ocfs2_stackglue.ko.

I've updated the changelog to reflect that. (copy-n-paste is still in my skillset).

author
#6 lore raw

PATCH v3 2/4 ocfs2: sysfile interfaces for online file check

In reply to Gang He

Implement 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 | 605 +++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/ocfs2/filecheck.h |  48 ++++
 fs/ocfs2/inode.h     |   3 +
 4 files changed, 658 insertions(+), 1 deletion(-)
 create mode 100644 fs/ocfs2/filecheck.c
 create mode 100644 fs/ocfs2/filecheck.h
fs/ocfs2/Makefile +2 -1
index ce210d4..e27e652 100644
@@ -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 +605 -0

605 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
index aac8b86..01635e0 100644
@@ -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
#7 lore raw

Re: [PATCH v3 2/4] ocfs2: sysfile interfaces for online file check

Quoted 5 lines · Gang He

Implement 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.

Most of this looks good, I have two comments below. Also thank you for redoing the interface to be more sysfs friendly.

fs/ocfs2/filecheck.c line 7

Quoted 13 lines
fs/ocfs2/filecheck.c new file +7 -0
new file mode 100644
index 0000000..a83e4ba
@@ -0,0 +1,605 @@
+static DEFINE_SPINLOCK(ocfs2_filecheck_sysfs_lock);
+static LIST_HEAD(ocfs2_filecheck_sysfs_list);
+
+struct ocfs2_filecheck {
+	struct list_head fc_head;	/* File check entry list head */
+	spinlock_t fc_lock;
+	unsigned int fc_max;	/* Maximum number of entry in list */

What is the point of fc_max? Only root can initiate file check so we need not worry about a malicious user eating up our memory. That should let us drop a bunch of the code below that is concerned with setting/reporting it.

Quoted 19 lines
fs/ocfs2/filecheck.c new file +19 -0
+	unsigned int fc_size;	/* Current entry count in list */
+	unsigned int fc_done;	/* Finished entry count in list */
+};
+
+struct ocfs2_filecheck_sysfs_entry {	/* sysfs entry per mounting */
+	struct list_head fs_list;
+	atomic_t fs_count;
+	struct super_block *fs_sb;
+	struct kset *fs_devicekset;
+	struct kset *fs_fcheckkset;
+	struct ocfs2_filecheck *fs_fcheck;
+};
+
+#define OCFS2_FILECHECK_MAXSIZE		100
+#define OCFS2_FILECHECK_MINSIZE		10
+
+/* File check operation type */
+enum {
+	OCFS2_FILECHECK_TYPE_CHK = 0,	/* Check a file(inode) */

fs/ocfs2/filecheck.c line 90

Quoted 10 lines
fs/ocfs2/filecheck.c new file +10 -0
+	OCFS2_FILECHECK_TYPE_FIX,	/* Fix a file(inode) */
+	OCFS2_FILECHECK_TYPE_SET = 100	/* Set entry list maximum size */
+};
+
+struct ocfs2_filecheck_entry {
+	struct list_head fe_list;
+	unsigned long fe_ino;
+	unsigned int fe_type;
+	unsigned short fe_done:1;
+	unsigned short fe_status:15;

I don't see the need to use a short here (or bitfield) for fc_status. IMHO it is less error-prone if we just make it an int or unsigned int.

This is a bit off topic but I dream of the day when we can return errors which userspace undestands but are outside the tiny range of 0-255 :)

Thanks,

	--Mark

--
Mark Fasheh

author
#8 lore raw

Re: [PATCH v3 2/4] ocfs2: sysfile interfaces for online file check

Hello Mark,

Quoted 21 lines
Quoted 1 line
Quoted 1 line
Quoted 5 lines · Gang He

Implement 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.

Most of this looks good, I have two comments below. Also thank you for redoing the interface to be more sysfs friendly.

Quoted 9 lines
fs/ocfs2/filecheck.c new file +3 -0
new file mode 100644
index 0000000..a83e4ba
@@ -0,0 +1,605 @@
+static DEFINE_SPINLOCK(ocfs2_filecheck_sysfs_lock);
+static LIST_HEAD(ocfs2_filecheck_sysfs_list);
+
Quoted 8 lines

fs/ocfs2/filecheck.c line 61

Quoted 4 lines
fs/ocfs2/filecheck.c new file +4 -0
+struct ocfs2_filecheck {
+	struct list_head fc_head;	/* File check entry list head */
+	spinlock_t fc_lock;
+	unsigned int fc_max;	/* Maximum number of entry in list */

What is the point of fc_max? Only root can initiate file check so we need not worry about a malicious user eating up our memory. That should let us drop a bunch of the code below that is concerned with setting/reporting it.

the fc_max item is used to set the maximum number of file check entry (include doing and finished) in the list,
this means the kernel module will keep how many filecheck results (history records) at most when uses cat sysfile to inquire the filecheck results. the kernel module will not cache all finished filecheck results, I think we need a value to limit this size.

Quoted 26 lines
Quoted 26 lines
fs/ocfs2/filecheck.c new file +24 -0
+	unsigned int fc_size;	/* Current entry count in list */
+	unsigned int fc_done;	/* Finished entry count in list */
+};
+
+struct ocfs2_filecheck_sysfs_entry {	/* sysfs entry per mounting */
+	struct list_head fs_list;
+	atomic_t fs_count;
+	struct super_block *fs_sb;
+	struct kset *fs_devicekset;
+	struct kset *fs_fcheckkset;
+	struct ocfs2_filecheck *fs_fcheck;
+};
+
+#define OCFS2_FILECHECK_MAXSIZE		100
+#define OCFS2_FILECHECK_MINSIZE		10
+
+/* File check operation type */
+enum {
+	OCFS2_FILECHECK_TYPE_CHK = 0,	/* Check a file(inode) */
+	OCFS2_FILECHECK_TYPE_FIX,	/* Fix a file(inode) */
+	OCFS2_FILECHECK_TYPE_SET = 100	/* Set entry list maximum size */
+};
+
+struct ocfs2_filecheck_entry {
Quoted 8 lines

fs/ocfs2/filecheck.c line 90

Quoted 5 lines
fs/ocfs2/filecheck.c new file +5 -0
+	struct list_head fe_list;
+	unsigned long fe_ino;
+	unsigned int fe_type;
+	unsigned short fe_done:1;
+	unsigned short fe_status:15;

I don't see the need to use a short here (or bitfield) for fc_status. IMHO it is less error-prone if we just make it an int or unsigned int.

OK, I will make it an unsigned int type, but a bit field have to be used to indicate this file check entry is done, or under processing. Since we use this flag (fe_done) when we shrink the result records, we only can get rid of finished entries.

Quoted 4 lines

This is a bit off topic but I dream of the day when we can return errors which userspace undestands but are outside the tiny range of 0-255 :)

Yes, this is why we return a error string in the result, not a error number.
Second, these file check errors (most) are not generic, then we can not utilize system error numbers.

Quoted 6 lines

Thanks,

	--Mark

--
Mark Fasheh

author
#9 lore raw

PATCH v3 3/4 ocfs2: create/remove sysfile for online file check

In reply to Gang He

Create 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
index 2de4c8a..5ef88b8 100644
@@ -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;
@@ -1204,6 +1205,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:
@@ -1671,6 +1675,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
author
#11 lore raw

PATCH v3 4/4 ocfs2: check/fix inode block for online file check

In reply to Gang He

Implement online check or fix inode block during
reading a inode block to memory.

---
 fs/ocfs2/inode.c       | 200 +++++++++++++++++++++++++++++++++++++++++++++++--
 fs/ocfs2/ocfs2_trace.h |   2 +
 2 files changed, 196 insertions(+), 6 deletions(-)
fs/ocfs2/inode.c +194 -6
index 8f87e05..6ac2f19 100644
@@ -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,14 @@ 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 +136,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 +171,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 +509,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 +562,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:
@@ -1396,6 +1435,155 @@ 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));
+
+	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 (!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;
+	}
+
+	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 changed = 0;
+	struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
+
+	if (!ocfs2_filecheck_validate_inode_block(sb, bh))
+		return 0;
+
+	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: cannot repair dinode #%llu "
+		     "on readonly filesystem\n",
+		     (unsigned long long)bh->b_blocknr);
+		return -OCFS2_FILECHECK_ERR_READONLY;
+	}
+
+	if (!OCFS2_IS_VALID_DINODE(di)) {
+		/* Cannot fix invalid inode block */
+		return -OCFS2_FILECHECK_ERR_INVALIDINO;
+	}
+
+	if (!(di->i_flags & cpu_to_le32(OCFS2_VALID_FL))) {
+		/* Cannot just add VALID_FL flag back as a fix,
+		 * need more things to check here.
+		 */
+		return -OCFS2_FILECHECK_ERR_VALIDFLAG;
+	}
+
+	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 (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
index 6cb019b..d9205e0 100644
@@ -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
#12 lore raw

Re: [Ocfs2-devel] [PATCH v3 4/4] ocfs2: check/fix inode block for online file check

Quoted 102 lines · Gang He

Implement online check or fix inode block during
reading a inode block to memory.

---
 fs/ocfs2/inode.c       | 200 +++++++++++++++++++++++++++++++++++++++++++++++--
 fs/ocfs2/ocfs2_trace.h |   2 +
 2 files changed, 196 insertions(+), 6 deletions(-)
fs/ocfs2/inode.c +37 -6
index 8f87e05..6ac2f19 100644
@@ -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,14 @@ 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 +136,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 +171,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 +509,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);

fs/ocfs2/inode.c static int ocfs2_read_locked_inode(struct inode *inode, · line 571

Quoted 10 lines
fs/ocfs2/inode.c +7 -0
@@ -531,6 +562,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;
+		}
+	}

This reminds me, we should be checking for a readonly file system up top in the 'fix' helper.

Also, I'm concerned that the buffer in question might be journaled. In that case, writing it to disk like this could cause corruptions (if the buffer contains not-committed changes).

The answer might be to journal the changes we make but I'm not sure if that can deadlock with other iget() calls.

	--Mark

--
Mark Fasheh

author
#13 lore raw

Re: [Ocfs2-devel] [PATCH v3 4/4] ocfs2: check/fix inode block for online file check

Hello Mark,

Quoted 112 lines
Quoted 1 line
Quoted 1 line
Quoted 6 lines · Gang He

Implement online check or fix inode block during
reading a inode block to memory.

---
 fs/ocfs2/inode.c       | 200 

+++++++++++++++++++++++++++++++++++++++++++++++--

fs/ocfs2/inode.c static int ocfs2_truncate_for_delete(struct ocfs2_super

Quoted 16 lines
 fs/ocfs2/ocfs2_trace.h |   2 +
 2 files changed, 196 insertions(+), 6 deletions(-)
fs/ocfs2/inode.c +1 -0
index 8f87e05..6ac2f19 100644
@@ -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,14 @@ static int ocfs2_truncate_for_delete(struct ocfs2_super 

*osb,

fs/ocfs2/inode.c struct inode *ocfs2_ilookup(struct super_block *sb, u64

Quoted 15 lines
fs/ocfs2/inode.c +8 -0
 				    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 +136,7 @@ struct inode *ocfs2_ilookup(struct super_block *sb, u64 

blkno)

fs/ocfs2/inode.c struct inode *ocfs2_ilookup(struct super_block *sb, u64 · line 136

Quoted 1 line
fs/ocfs2/inode.c +0 -0
 struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned 

flags,

fs/ocfs2/inode.c struct inode *ocfs2_iget(struct ocfs2_super *osb, u64

Quoted 7 lines
fs/ocfs2/inode.c +1 -0
 			 int sysfile_type)
 {
+	int rc = 0;
 	struct inode *inode = NULL;
 	struct super_block *sb = osb->sb;
 	struct ocfs2_find_inode_args args;
@@ -161,12 +171,17 @@ struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 

blkno, unsigned flags,

Quoted 60 lines
fs/ocfs2/inode.c +27 -6
 	}
 	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 +509,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 +562,14 @@ static int ocfs2_read_locked_inode(struct inode *inode,
 
 	BUG_ON(args->fi_blkno != le64_to_cpu(fe->i_blkno));
 
Quoted 10 lines

fs/ocfs2/inode.c static int ocfs2_read_locked_inode(struct inode *inode, · line 571

Quoted 7 lines
fs/ocfs2/inode.c +7 -0
+	if (buffer_dirty(bh)) {
+		status = ocfs2_write_block(osb, bh, INODE_CACHE(inode));
+		if (status < 0) {
+			mlog_errno(status);
+			goto bail;
+		}
+	}

This reminds me, we should be checking for a readonly file system up top in the 'fix' helper.

When the file system becomes read-only, we still can check certain file via it's inode number and report the result (the inode block is integrated or not), but we cannot fix this file in file system read-only status, otherwise the subsequent logic will become too complex in case we modify/write a inode block under a read-only file system. Actually, online file check feature should be combined with "errors=continues" option for better using.

Quoted 4 lines

Also, I'm concerned that the buffer in question might be journaled. In that case, writing it to disk like this could cause corruptions (if the buffer contains not-committed changes).

I ever though of journaling this changed inode block in case file check fixing, but you know, we are being on inode block loading stage, the journal related structs are not prepared at this moment, then I write this block back to the disk synchronously within ocfs2_inode_lock, it looks a little tricky, but not bring any risk. in case the machine crashes when writing the inode block back to the disk, this will not affect file system integrity, since this inode block original is corrupted, the user can fix this inode block via file check again after the machine is recovered. Anyway, I just want to let all know what I think behind this part code, maybe it is not right, please give your feedback again.

Thanks
Gang

Quoted 7 lines

The answer might be to journal the changes we make but I'm not sure if that can deadlock with other iget() calls.

	--Mark

--
Mark Fasheh

#14 lore raw
In reply to Gang He
Quoted 11 lines · On Fri, 25 Dec 2015 15:16:15 +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 "<inode>" > /sys/fs/ocfs2/devname/filecheck/check
or
$# echo "<inode>" > /sys/fs/ocfs2/devname/filecheck/fix

Quoted 8 lines

Compare with second version, I re-design filecheck sysfs interfaces, there are three sysfs files(check, fix and set) under filecheck directory(see above), sysfs will accept only one argument <inode>. Second, I adjust some code in ocfs2_filecheck_repair_inode_block() function according to upstream feedback, we cannot just add VALID_FL flag back as a inode block fix, then we will not fix this field corruption currently until having a complete solution. Compare with first version, I use strncasecmp instead of double strncmp functions. Second, update the source file contribution vendor.

This feature should be documented, please. That means all pseudo-file locations, all inputs, all outputs, expected behaviour etc etc. Enough info so that our users can usefully and fully use this feature in the minimum time. Documentation/filesystems/ocfs2.txt is the place for that.

author
#15 lore raw

Hello Andrew and Mark,

Quoted 22 lines
Quoted 1 line
Quoted 1 line
Quoted 11 lines · On Fri, 25 Dec 2015 15:16:15 +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 "<inode>" > /sys/fs/ocfs2/devname/filecheck/check
or
$# echo "<inode>" > /sys/fs/ocfs2/devname/filecheck/fix

Quoted 2 lines

Compare with second version, I re-design filecheck sysfs interfaces, there are three sysfs files(check, fix and set) under filecheck directory(see

above),

Quoted 2 lines

sysfs will accept only one argument <inode>. Second, I adjust some code in ocfs2_filecheck_repair_inode_block() function according to upstream

feedback,

Quoted 1 line

we cannot just add VALID_FL flag back as a inode block fix, then we will not

Quoted 8 lines
Quoted 3 lines

fix this field corruption currently until having a complete solution. Compare with first version, I use strncasecmp instead of double strncmp functions. Second, update the source file contribution vendor.

This feature should be documented, please. That means all pseudo-file locations, all inputs, all outputs, expected behaviour etc etc. Enough info so that our users can usefully and fully use this feature in the minimum time. Documentation/filesystems/ocfs2.txt is the place for that.

I ever sent out a document which describes this feature, I will modify that document sightly since sysfs interfaces have been adjusted, then send out to the list as a separated patch. Is it OK for you?

Thanks
Gang

#16 lore raw
Quoted 6 lines · On Tue, 29 Dec 2015 20:00:08 -0700 "Gang He" <[email protected]> wrote:
Quoted 4 lines

This feature should be documented, please. That means all pseudo-file locations, all inputs, all outputs, expected behaviour etc etc. Enough info so that our users can usefully and fully use this feature in the minimum time. Documentation/filesystems/ocfs2.txt is the place for that.

I ever sent out a document which describes this feature, I will modify that document sightly since sysfs interfaces have been adjusted, then send out to the list as a separated patch. Is it OK for you?

Sounds good, thanks. The documentation is important because it permits reviewers to understand the proposed interfaces, which need to be nailed down before there's any point in looking at the implementation.