Skip to contentSkip to conversation

Btrfs: deal with error on secondary log properly

PATCH In review Josef Bacik 3 participants 6 messages Aug 25, 2015 – Aug 28, 2015 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: deal with error on secondary log properly

If we have an fsync at the same time in two seperate subvolumes we could end up with the tree log pointing at invalid blocks. We need to notice if our writeout failed in anyway, if it did then we need to do a full transaction commit and return an error on the subvolume that gave us the io error. Thanks,

---
 fs/btrfs/file.c     | 4 ++++
 fs/btrfs/tree-log.c | 4 ++++
 2 files changed, 8 insertions(+)
fs/btrfs/file.c +4 -0
index b823fac..c8f49f5 100644
@@ -2054,6 +2054,10 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
 			if (!ret) {
 				ret = btrfs_end_transaction(trans, root);
 				goto out;
+			} else if (ctx.io_err) {
+				btrfs_end_transaction(trans, root);
+				ret = ctx.io_err;
+				goto out;
 			}
 		}
 		if (!full_sync) {
fs/btrfs/tree-log.c +4 -0
index 1bbaace..b4f15f5 100644
@@ -2857,6 +2857,10 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
 		ret = btrfs_wait_marked_extents(log, &log->dirty_log_pages,
 						mark);
 		btrfs_wait_logged_extents(trans, log, log_transid);
+		if (ret) {
+			btrfs_set_log_full_commit(root->fs_info, trans);
+			ctx->io_err = ret;
+		}
 		wait_log_commit(log_root_tree,
 				root_log_ctx.log_transid);
 		mutex_unlock(&log_root_tree->log_mutex);
Signature · 1 line
2.1.0
#1 lore raw
Quoted 2 lines · Josef Bacik

If we have an fsync at the same time in two seperate subvolumes we could end up with the tree log pointing at invalid blocks. We need to notice if our writeout

Mind to share more details of the problem?

Thanks,

-liubo

Quoted 46 lines

failed in anyway, if it did then we need to do a full transaction commit and return an error on the subvolume that gave us the io error. Thanks,

---
 fs/btrfs/file.c     | 4 ++++
 fs/btrfs/tree-log.c | 4 ++++
 2 files changed, 8 insertions(+)
fs/btrfs/file.c +4 -0
index b823fac..c8f49f5 100644
@@ -2054,6 +2054,10 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
 			if (!ret) {
 				ret = btrfs_end_transaction(trans, root);
 				goto out;
+			} else if (ctx.io_err) {
+				btrfs_end_transaction(trans, root);
+				ret = ctx.io_err;
+				goto out;
 			}
 		}
 		if (!full_sync) {
fs/btrfs/tree-log.c +4 -0
index 1bbaace..b4f15f5 100644
@@ -2857,6 +2857,10 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
 		ret = btrfs_wait_marked_extents(log, &log->dirty_log_pages,
 						mark);
 		btrfs_wait_logged_extents(trans, log, log_transid);
+		if (ret) {
+			btrfs_set_log_full_commit(root->fs_info, trans);
+			ctx->io_err = ret;
+		}
 		wait_log_commit(log_root_tree,
 				root_log_ctx.log_transid);
 		mutex_unlock(&log_root_tree->log_mutex);
Signature · 6 lines
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 6 lines · Liu Bo
Quoted 2 lines · Josef Bacik

If we have an fsync at the same time in two seperate subvolumes we could end up with the tree log pointing at invalid blocks. We need to notice if our writeout

Mind to share more details of the problem?

It's the problem Filipe was trying to solve. Say we fsync() on two different subvols, one of them will race in and be the one who commits the log root tree. So process A waits on process B to add its log to the log root tree and write out its log. If we get an IO error while writing out the log the log root tree will be pointing to invalid crap, and we also won't return an error back to userspace. We need to notice if there was an error, turn on the transaction commit stuff since we've already updated the the log root tree with our subvol log so we don't get garbage on the disk, and we need to return an error to process B. Thanks,

Josef

Reviewed-by on v1 1/1
#5 lore raw
In reply to Josef Bacik
Quoted 4 lines · Josef Bacik

If we have an fsync at the same time in two seperate subvolumes we could end up with the tree log pointing at invalid blocks. We need to notice if our writeout failed in anyway, if it did then we need to do a full transaction commit and return an error on the subvolume that gave us the io error. Thanks,

Thanks,

-liubo

Quoted 44 lines
---
 fs/btrfs/file.c     | 4 ++++
 fs/btrfs/tree-log.c | 4 ++++
 2 files changed, 8 insertions(+)
fs/btrfs/file.c +4 -0
index b823fac..c8f49f5 100644
@@ -2054,6 +2054,10 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
 			if (!ret) {
 				ret = btrfs_end_transaction(trans, root);
 				goto out;
+			} else if (ctx.io_err) {
+				btrfs_end_transaction(trans, root);
+				ret = ctx.io_err;
+				goto out;
 			}
 		}
 		if (!full_sync) {
fs/btrfs/tree-log.c +4 -0
index 1bbaace..b4f15f5 100644
@@ -2857,6 +2857,10 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
 		ret = btrfs_wait_marked_extents(log, &log->dirty_log_pages,
 						mark);
 		btrfs_wait_logged_extents(trans, log, log_transid);
+		if (ret) {
+			btrfs_set_log_full_commit(root->fs_info, trans);
+			ctx->io_err = ret;
+		}
 		wait_log_commit(log_root_tree,
 				root_log_ctx.log_transid);
 		mutex_unlock(&log_root_tree->log_mutex);
Signature · 6 lines
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
In reply to Josef Bacik
Quoted 13 lines · Josef Bacik
Quoted 11 lines · Liu Bo
Quoted 5 lines · Josef Bacik

If we have an fsync at the same time in two seperate subvolumes we could end up
with the tree log pointing at invalid blocks. We need to notice if our writeout

Mind to share more details of the problem?

Quoted 9 lines

It's the problem Filipe was trying to solve. Say we fsync() on two different subvols, one of them will race in and be the one who commits the log root tree. So process A waits on process B to add its log to the log root tree and write out its log. If we get an IO error while writing out the log the log root tree will be pointing to invalid crap, and we also won't return an error back to userspace. We need to notice if there was an error, turn on the transaction commit stuff since we've already updated the the log root tree with our subvol log so we don't get garbage on the disk, and we need to return an error to process B. Thanks,

Josef,

So the problem was that without forcing A to trigger a transaction commit if B gets an error when writing one or more log tree nodes/leafs, A could write a superblock pointing to a log root tree for which not all nodes/leafs were persisted. Then B would fall back to a transaction commit and everything would be ok - i.e. we would only have a "small" time window where a superblock points to an invalid log root tree.

So the fix here shouldn't be only to force A do a transaction commit (call btrfs_set_log_full_commit())? Why do we need to make B return an error to userspace and not fallback to a transaction commit too (as it was before this change)? After all this is the kind of failure for which we can fallback to a transaction commit without losing any inode metadata (links, owner, group, xattrs, etc) nor file data.

The change looks good, just puzzled why we need to return the error to userspace.

thanks

Quoted 8 lines

Josef

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 5 lines
Filipe David Manana,

"Reasonable men adapt themselves to the world.
 Unreasonable men adapt the world to themselves.
 That's why all progress depends on unreasonable men."
#4 lore raw
Quoted 41 lines · Filipe David Manana
Quoted 13 lines · Josef Bacik
Quoted 11 lines · Liu Bo
Quoted 5 lines · Josef Bacik

If we have an fsync at the same time in two seperate subvolumes we could end up
with the tree log pointing at invalid blocks. We need to notice if our writeout

Mind to share more details of the problem?

Quoted 9 lines

It's the problem Filipe was trying to solve. Say we fsync() on two different subvols, one of them will race in and be the one who commits the log root tree. So process A waits on process B to add its log to the log root tree and write out its log. If we get an IO error while writing out the log the log root tree will be pointing to invalid crap, and we also won't return an error back to userspace. We need to notice if there was an error, turn on the transaction commit stuff since we've already updated the the log root tree with our subvol log so we don't get garbage on the disk, and we need to return an error to process B. Thanks,

Josef,

So the problem was that without forcing A to trigger a transaction commit if B gets an error when writing one or more log tree nodes/leafs, A could write a superblock pointing to a log root tree for which not all nodes/leafs were persisted. Then B would fall back to a transaction commit and everything would be ok - i.e. we would only have a "small" time window where a superblock points to an invalid log root tree.

So the fix here shouldn't be only to force A do a transaction commit (call btrfs_set_log_full_commit())? Why do we need to make B return an error to userspace and not fallback to a transaction commit too (as it was before this change)? After all this is the kind of failure for which we can fallback to a transaction commit without losing any inode metadata (links, owner, group, xattrs, etc) nor file data.

Quoted 3 lines

The change looks good, just puzzled why we need to return the error to userspace.

Ah well there's a reason in upcoming patches! Basically I'm moving the wait on ordered extents back into the sync log stuff so I can have my go fast stripes back, and when I do that we'll want to return an error since it could be from wait_ordered_extents. But you are right, if we only error out writing the metadata we can just commit the transaction and not return an error. I can change this bit to not return an error if we want, or wait for my other patches which will fix it up. Thanks,

Josef