Skip to contentSkip to conversation

Add some msg for io error

PATCH New zhanchengbin 1 participant 3 messages Mar 30, 2023

lore
Share & tools
lore
#0 lore raw

v2 cover Add some msg for io error

If there is an EIO during the process of fsck, the user can be notified of it.

Diff v2 Vs v1:
1) Optimize printing information
2) Remove the interaction after fsync failed and return an error.
3) Rearrange the patch sets.

zhanchengbin (2):
lib/ext2fs: add error handle in unix_flush and unix_write_byte
e2fsck: add sync error handle to e2fsck.

 e2fsck/ehandler.c    | 22 ++++++++++++++++++++++
 lib/ext2fs/ext2_io.h |  2 ++
 lib/ext2fs/unix_io.c | 37 ++++++++++++++++++++++++++-----------
 3 files changed, 50 insertions(+), 11 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 1/2 lib/ext2fs: add error handle in unix_flush and unix_write_byte

As you can see, a new error handling has been added for fsync, and the error handling for unix_write_byte function has reused the error handling of write_blk.

---
 lib/ext2fs/ext2_io.h |  2 ++
 lib/ext2fs/unix_io.c | 37 ++++++++++++++++++++++++++-----------
 2 files changed, 28 insertions(+), 11 deletions(-)
lib/ext2fs/ext2_io.h +2 -0
index 679184e3..becd7078 100644
@@ -56,6 +56,8 @@ struct struct_io_channel {
 				       size_t size,
 				       int actual_bytes_written,
 				       errcode_t error);
+	errcode_t       (*sync_error)(io_channel channel,
+	                               errcode_t error);
 	int		refcount;
 	int		flags;
 	long		reserved[14];
lib/ext2fs/unix_io.c +26 -11
index 3171c736..283b4eb6 100644
@@ -1250,7 +1250,8 @@ static errcode_t unix_write_byte(io_channel channel, unsigned long offset,
 #ifdef ALIGN_DEBUG
 		printf("unix_write_byte: O_DIRECT fallback\n");
 #endif
-		return EXT2_ET_UNIMPLEMENTED;
+		retval = EXT2_ET_UNIMPLEMENTED;
+		goto error_out;
 	}
 
 #ifndef NO_IO_CACHE
@@ -1258,19 +1259,30 @@ static errcode_t unix_write_byte(io_channel channel, unsigned long offset,
 	 * Flush out the cache completely
 	 */
 	if ((retval = flush_cached_blocks(channel, data, FLUSH_INVALIDATE)))
-		return retval;
+		goto error_out;
 #endif
 
-	if (lseek(data->dev, offset + data->offset, SEEK_SET) < 0)
-		return errno;
+	if (lseek(data->dev, offset + data->offset, SEEK_SET) < 0) {
+		retval = errno;
+		goto error_out;
+	}
 
 	actual = write(data->dev, buf, size);
-	if (actual < 0)
-		return errno;
-	if (actual != size)
-		return EXT2_ET_SHORT_WRITE;
-
+	if (actual < 0) {
+		retval = errno;
+		goto error_out;
+	}
+	if (actual != size) {
+		retval = EXT2_ET_SHORT_WRITE;
+		goto error_out;
+	}
 	return 0;
+error_out:
+	if (channel->write_error)
+		retval = (channel->write_error)(channel,
+					offset / channel->block_size, 0, buf,
+					size, actual, retval);
+	return retval;
 }
 
 /*
@@ -1289,8 +1301,11 @@ static errcode_t unix_flush(io_channel channel)
 	retval = flush_cached_blocks(channel, data, 0);
 #endif
 #ifdef HAVE_FSYNC
-	if (!retval && fsync(data->dev) != 0)
-		return errno;
+	if (!retval && fsync(data->dev) != 0) {
+		if (channel->sync_error)
+			retval = (channel->sync_error)(channel, errno);
+		return retval;
+	}
 #endif
 	return retval;
 }
Signature · 1 line
2.31.1
#2 lore raw

PATCH v2 2/2 e2fsck: add sync error handle to e2fsck.

In reply to zhanchengbin

If fsync fails during fsck, it is silent and users will not perceive it, so a function to handle fsync failure should be added to fsck.

---
 e2fsck/ehandler.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
e2fsck/ehandler.c +22 -0
index 71ca301c..1d95a89d 100644
@@ -118,6 +118,27 @@ static errcode_t e2fsck_handle_write_error(io_channel channel,
 	return error;
 }
 
+static errcode_t e2fsck_handle_sync_error(io_channel channel,
+                                            errcode_t error)
+{
+	ext2_filsys fs = (ext2_filsys) channel->app_data;
+	e2fsck_t ctx;
+
+	ctx = (e2fsck_t) fs->priv_data;
+	if (ctx->flags & E2F_FLAG_EXITING)
+		return 0;
+
+	if (operation)
+		printf(_("Error during fsync of dirty metadata while %s: %s "),
+		       operation, error_message(error));
+	else
+		printf(_("Error during fsync of dirty metadata: %s "),
+		       error_message(error));
+	preenhalt(ctx);
+
+	return error;
+}
+
 const char *ehandler_operation(const char *op)
 {
 	const char *ret = operation;
@@ -130,4 +151,5 @@ void ehandler_init(io_channel channel)
 {
 	channel->read_error = e2fsck_handle_read_error;
 	channel->write_error = e2fsck_handle_write_error;
+	channel->sync_error = e2fsck_handle_sync_error;
 }
Signature · 1 line
2.31.1