Skip to contentSkip to conversation

btrfs: log, when replace, is canceled by the user

PATCH Superseded Anand Jain 4 participants 8 messages Feb 12, 2018 – Feb 13, 2018 Btrfs file system

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

PATCH 1/1 btrfs: log, when replace, is canceled by the user

For forensic investigations of issues, we would want to know if and when the user cancels the replace.

---
 fs/btrfs/dev-replace.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/btrfs/dev-replace.c +7 -0
index 197be3fe307b..83eb2d32b477 100644
@@ -711,6 +711,7 @@ static u64 __btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 {
 	struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
 	struct btrfs_device *tgt_device = NULL;
+	struct btrfs_device *src_device = NULL;
 	struct btrfs_trans_handle *trans;
 	struct btrfs_root *root = fs_info->tree_root;
 	u64 result;
@@ -732,6 +733,7 @@ static u64 __btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 	case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
 		result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR;
 		tgt_device = dev_replace->tgtdev;
+		src_device = dev_replace->srcdev;
 		dev_replace->tgtdev = NULL;
 		dev_replace->srcdev = NULL;
 		break;
@@ -749,6 +751,11 @@ static u64 __btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 	}
 	ret = btrfs_commit_transaction(trans);
 	WARN_ON(ret);
+
+	btrfs_info(fs_info, "dev_replace from %s (devid %llu) to %s canceled",
+		   btrfs_dev_name(src_device), src_device->devid,
+		   rcu_str_deref(tgt_device->name));
+
 	if (tgt_device)
 		btrfs_destroy_dev_replace_tgtdev(fs_info, tgt_device);
 
Signature · 1 line
2.15.0
#1 lore raw
Quoted 29 lines · Anand Jain

For forensic investigations of issues, we would want to know if and when the user cancels the replace.

---
 fs/btrfs/dev-replace.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/btrfs/dev-replace.c +2 -0
index 197be3fe307b..83eb2d32b477 100644
@@ -711,6 +711,7 @@ static u64 __btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 {
 	struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
 	struct btrfs_device *tgt_device = NULL;
+	struct btrfs_device *src_device = NULL;
 	struct btrfs_trans_handle *trans;
 	struct btrfs_root *root = fs_info->tree_root;
 	u64 result;
@@ -732,6 +733,7 @@ static u64 __btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 	case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
 		result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR;
 		tgt_device = dev_replace->tgtdev;
+		src_device = dev_replace->srcdev;
 		dev_replace->tgtdev = NULL;
 		dev_replace->srcdev = NULL;
 		break;

fs/btrfs/dev-replace.c static u64 __btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info) · line 757

Quoted 7 lines
fs/btrfs/dev-replace.c +4 -0
@@ -749,6 +751,11 @@ static u64 __btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 	}
 	ret = btrfs_commit_transaction(trans);
 	WARN_ON(ret);
+
+	btrfs_info(fs_info, "dev_replace from %s (devid %llu) to %s canceled",
+		   btrfs_dev_name(src_device), src_device->devid,
+		   rcu_str_deref(tgt_device->name));

The behavior is quite good.

Although I'm wondering why for @src_device we use btrfs_dev_name() but rcu_str_deref() for @tgt_device?

Thanks,
Qu

Quoted 5 lines
fs/btrfs/dev-replace.c +1 -0
+
 	if (tgt_device)
 		btrfs_destroy_dev_replace_tgtdev(fs_info, tgt_device);
 
author
#2 lore raw
Quoted 11 lines

fs/btrfs/dev-replace.c static u64 __btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info) · line 757

Quoted 6 lines
fs/btrfs/dev-replace.c +4 -0
+
+	btrfs_info(fs_info, "dev_replace from %s (devid %llu) to %s canceled",
+		   btrfs_dev_name(src_device), src_device->devid,
+		   rcu_str_deref(tgt_device->name));

The behavior is quite good.

Although I'm wondering why for @src_device we use btrfs_dev_name() but rcu_str_deref() for @tgt_device?

Thanks for the comments.
My bad. In fact, I must use btrfs_dev_name() for tgt_device since the tgt_device can be missing (-o degraded) when the user decides to cancel.

Thanks, Anand

author
#3 lore raw

PATCH v2 1/1 btrfs: log, when replace, is canceled by the user

In reply to Anand Jain

For forensic investigations of issues, we would want to know if and when the user cancels the replace.

---
v1->v2: use btrfs_dev_name() instead of rcu_str_deref()
as btrfs_dev_name() also provides "missing" string, if needed.

 fs/btrfs/dev-replace.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/btrfs/dev-replace.c +7 -0
index dd717e204b5e..3b0760f7ec8a 100644
@@ -703,6 +703,7 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 {
 	struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
 	struct btrfs_device *tgt_device = NULL;
+	struct btrfs_device *src_device = NULL;
 	struct btrfs_trans_handle *trans;
 	struct btrfs_root *root = fs_info->tree_root;
 	int result;
@@ -724,6 +725,7 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 	case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
 		result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR;
 		tgt_device = dev_replace->tgtdev;
+		src_device = dev_replace->srcdev;
 		dev_replace->tgtdev = NULL;
 		dev_replace->srcdev = NULL;
 		break;
@@ -741,6 +743,11 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 	}
 	ret = btrfs_commit_transaction(trans);
 	WARN_ON(ret);
+
+	btrfs_info(fs_info, "dev_replace from %s (devid %llu) to %s canceled",
+		   btrfs_dev_name(src_device), src_device->devid,
+		   btrfs_dev_name(tgt_device));
+
 	if (tgt_device)
 		btrfs_destroy_dev_replace_tgtdev(fs_info, tgt_device);
 
Signature · 1 line
2.15.0
#4 lore raw
Quoted 7 lines · Anand Jain

For forensic investigations of issues, we would want to know if and when the user cancels the replace.

v1->v2: use btrfs_dev_name() instead of rcu_str_deref()
as btrfs_dev_name() also provides "missing" string, if needed.

Would you please provide the branch you're using?

As I couldn't find the function or macro of btrfs_dev_name()

Thanks,
Qu

Quoted 37 lines
 fs/btrfs/dev-replace.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/btrfs/dev-replace.c +7 -0
index dd717e204b5e..3b0760f7ec8a 100644
@@ -703,6 +703,7 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 {
 	struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
 	struct btrfs_device *tgt_device = NULL;
+	struct btrfs_device *src_device = NULL;
 	struct btrfs_trans_handle *trans;
 	struct btrfs_root *root = fs_info->tree_root;
 	int result;
@@ -724,6 +725,7 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 	case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
 		result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR;
 		tgt_device = dev_replace->tgtdev;
+		src_device = dev_replace->srcdev;
 		dev_replace->tgtdev = NULL;
 		dev_replace->srcdev = NULL;
 		break;
@@ -741,6 +743,11 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 	}
 	ret = btrfs_commit_transaction(trans);
 	WARN_ON(ret);
+
+	btrfs_info(fs_info, "dev_replace from %s (devid %llu) to %s canceled",
+		   btrfs_dev_name(src_device), src_device->devid,
+		   btrfs_dev_name(tgt_device));
+
 	if (tgt_device)
 		btrfs_destroy_dev_replace_tgtdev(fs_info, tgt_device);
 
#5 lore raw
Quoted 6 lines · Qu Wenruo
Quoted 3 lines · Anand Jain

For forensic investigations of issues, we would want to know if and when the user cancels the replace.

Quoted 8 lines
Quoted 4 lines

v1->v2: use btrfs_dev_name() instead of rcu_str_deref()
as btrfs_dev_name() also provides "missing" string, if needed.

Would you please provide the branch you're using?

As I couldn't find the function or macro of btrfs_dev_name()

I have it in my misc-next checkout. I got introduced by 3c958bd23b60 ("btrfs: add helper for device path or missing")

which is in 4.16-rc1 so pretty recent.

Quoted 42 lines

Thanks,
Qu

Quoted 37 lines
 fs/btrfs/dev-replace.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/btrfs/dev-replace.c +7 -0
index dd717e204b5e..3b0760f7ec8a 100644
@@ -703,6 +703,7 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 {
 	struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
 	struct btrfs_device *tgt_device = NULL;
+	struct btrfs_device *src_device = NULL;
 	struct btrfs_trans_handle *trans;
 	struct btrfs_root *root = fs_info->tree_root;
 	int result;
@@ -724,6 +725,7 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 	case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
 		result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR;
 		tgt_device = dev_replace->tgtdev;
+		src_device = dev_replace->srcdev;
 		dev_replace->tgtdev = NULL;
 		dev_replace->srcdev = NULL;
 		break;
@@ -741,6 +743,11 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 	}
 	ret = btrfs_commit_transaction(trans);
 	WARN_ON(ret);
+
+	btrfs_info(fs_info, "dev_replace from %s (devid %llu) to %s canceled",
+		   btrfs_dev_name(src_device), src_device->devid,
+		   btrfs_dev_name(tgt_device));
+
 	if (tgt_device)
 		btrfs_destroy_dev_replace_tgtdev(fs_info, tgt_device);
 
#6 lore raw
Quoted 16 lines · Nikolay Borisov
Quoted 13 lines · Qu Wenruo
Quoted 7 lines · Anand Jain

For forensic investigations of issues, we would want to know if and when the user cancels the replace.

v1->v2: use btrfs_dev_name() instead of rcu_str_deref()
as btrfs_dev_name() also provides "missing" string, if needed.

Would you please provide the branch you're using?

Quoted 7 lines
Quoted 1 line

As I couldn't find the function or macro of btrfs_dev_name()

I have it in my misc-next checkout. I got introduced by 3c958bd23b60 ("btrfs: add helper for device path or missing")

which is in 4.16-rc1 so pretty recent.

I was on v4.15, no wonder no such function.

Thank you very much,
Qu

Quoted 49 lines
Quoted 35 lines

Thanks,
Qu

Quoted 29 lines
 fs/btrfs/dev-replace.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/btrfs/dev-replace.c +3 -0
index dd717e204b5e..3b0760f7ec8a 100644
@@ -703,6 +703,7 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 {
 	struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
 	struct btrfs_device *tgt_device = NULL;
+	struct btrfs_device *src_device = NULL;
 	struct btrfs_trans_handle *trans;
 	struct btrfs_root *root = fs_info->tree_root;
 	int result;
@@ -724,6 +725,7 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 	case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
 		result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR;
 		tgt_device = dev_replace->tgtdev;
+		src_device = dev_replace->srcdev;
 		dev_replace->tgtdev = NULL;
 		dev_replace->srcdev = NULL;
 		break;
@@ -741,6 +743,11 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 	}
 	ret = btrfs_commit_transaction(trans);
 	WARN_ON(ret);
+
Quoted 9 lines

fs/btrfs/dev-replace.c int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info) · line 753

Quoted 8 lines
fs/btrfs/dev-replace.c +4 -0
+	btrfs_info(fs_info, "dev_replace from %s (devid %llu) to %s canceled",
+		   btrfs_dev_name(src_device), src_device->devid,
+		   btrfs_dev_name(tgt_device));
+
 	if (tgt_device)
 		btrfs_destroy_dev_replace_tgtdev(fs_info, tgt_device);
 

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