Skip to contentSkip to conversation

btrfs-progs: subvolume: Add warning on deleting default subvolume

PATCH In review Sidong Yang 3 participants 6 messages Sep 28, 2020 – Sep 30, 2020 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: subvolume: Add warning on deleting default subvolume

This patch add warning messages when user try to delete default subvolume. When deleting default subvolume, kernel will not allow and make error message on syslog. but there is only message that permission denied on userspace. User can be noticed the reason by this warning message.

This patch implements github issue.
https://github.com/kdave/btrfs-progs/issues/274

---
 cmds/subvolume.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
cmds/subvolume.c +20 -0
index 2020e486..0cdf7a68 100644
@@ -264,6 +264,7 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd,
 	struct seen_fsid *seen_fsid_hash[SEEN_FSID_HASH_SIZE] = { NULL, };
 	enum { COMMIT_AFTER = 1, COMMIT_EACH = 2 };
 	enum btrfs_util_error err;
+	uint64_t default_subvol_id = 0, target_subvol_id = 0;
 
 	optind = 0;
 	while (1) {
@@ -360,6 +361,25 @@ again:
 		goto out;
 	}
 
+	err = btrfs_util_get_default_subvolume_fd(fd, &default_subvol_id);
+	if (fd < 0) {
+		ret = 1;
+		goto out;
+	}
+
+	if (subvolid > 0)
+		target_subvol_id = subvolid;
+	else {
+		err = btrfs_util_subvolume_id(path, &target_subvol_id);
+		if (fd < 0) {
+			ret = 1;
+			goto out;
+		}
+	}
+
+	if (target_subvol_id == default_subvol_id)
+		warning("trying to delete default subvolume.");
+
 	pr_verbose(MUST_LOG, "Delete subvolume (%s): ",
 		commit_mode == COMMIT_EACH ||
 		(commit_mode == COMMIT_AFTER && cnt + 1 == argc) ?
Signature · 1 line
2.25.1
#1 lore raw
Quoted 9 lines · Sidong Yang

This patch add warning messages when user try to delete default subvolume. When deleting default subvolume, kernel will not allow and make error message on syslog. but there is only message that permission denied on userspace. User can be noticed the reason by this warning message.

This patch implements github issue.
https://github.com/kdave/btrfs-progs/issues/274

Thanks.

Quoted 28 lines
---
 cmds/subvolume.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
cmds/subvolume.c +9 -0
index 2020e486..0cdf7a68 100644
@@ -264,6 +264,7 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd,
 	struct seen_fsid *seen_fsid_hash[SEEN_FSID_HASH_SIZE] = { NULL, };
 	enum { COMMIT_AFTER = 1, COMMIT_EACH = 2 };
 	enum btrfs_util_error err;
+	uint64_t default_subvol_id = 0, target_subvol_id = 0;
 
 	optind = 0;
 	while (1) {
@@ -360,6 +361,25 @@ again:
 		goto out;
 	}
 
+	err = btrfs_util_get_default_subvolume_fd(fd, &default_subvol_id);
+	if (fd < 0) {
+		ret = 1;
+		goto out;
+	}
+
+	if (subvolid > 0)
+		target_subvol_id = subvolid;

cmds/subvolume.c again: · line 381

Quoted 10 lines
cmds/subvolume.c +10 -0
+	else {
+		err = btrfs_util_subvolume_id(path, &target_subvol_id);
+		if (fd < 0) {
+			ret = 1;
+			goto out;
+		}
+	}
+
+	if (target_subvol_id == default_subvol_id)
+		warning("trying to delete default subvolume.");

I've changed that to skip the deletion and added id and path to the message, otherwise it's not clear which one it was. Also I've added a test.

#2 lore raw
In reply to Sidong Yang
Quoted 28 lines · Sidong Yang

This patch add warning messages when user try to delete default subvolume. When deleting default subvolume, kernel will not allow and make error message on syslog. but there is only message that permission denied on userspace. User can be noticed the reason by this warning message.

This patch implements github issue.
https://github.com/kdave/btrfs-progs/issues/274

---
 cmds/subvolume.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
cmds/subvolume.c +1 -0
index 2020e486..0cdf7a68 100644
@@ -264,6 +264,7 @@ static int cmd_subvol_delete(const struct 
 cmd_struct *cmd,
 	struct seen_fsid *seen_fsid_hash[SEEN_FSID_HASH_SIZE] = { 
 NULL, };
 	enum { COMMIT_AFTER = 1, COMMIT_EACH = 2 };
 	enum btrfs_util_error err;
+	uint64_t default_subvol_id = 0, target_subvol_id = 0;
 
cmds/subvolume.c +0 -0
 	optind = 0;
 	while (1) {

cmds/subvolume.c again: · line 367

Quoted 7 lines
cmds/subvolume.c +2 -0
@@ -360,6 +361,25 @@ again:
 		goto out;
 	}
 
+	err = btrfs_util_get_default_subvolume_fd(fd, 
 &default_subvol_id);
+	if (fd < 0) {
 

Should it be
" if (err) { |

        error_btrfs_util(err);
        ...

"?

cmds/subvolume.c again:

Quoted 10 lines
cmds/subvolume.c +9 -0
+		ret = 1;
+		goto out;
+	}
+
+	if (subvolid > 0)
+		target_subvol_id = subvolid;
+	else {
+		err = btrfs_util_subvolume_id(path, &target_subvol_id);
+		if (fd < 0) {
 

And here.

Quoted 11 lines
cmds/subvolume.c +8 -0
+			ret = 1;
+			goto out;
+		}
+	}
+
+	if (target_subvol_id == default_subvol_id)
+		warning("trying to delete default subvolume.");
+
cmds/subvolume.c +0 -0
 	pr_verbose(MUST_LOG, "Delete subvolume (%s): ",
 		commit_mode == COMMIT_EACH ||
 		(commit_mode == COMMIT_AFTER && cnt + 1 == argc) ?
#3 lore raw
Quoted 34 lines · Su Yue
Quoted 31 lines · Sidong Yang

This patch add warning messages when user try to delete default subvolume. When deleting default subvolume, kernel will not allow and make error message on syslog. but there is only message that permission denied on userspace. User can be noticed the reason by this warning message.

This patch implements github issue.
https://github.com/kdave/btrfs-progs/issues/274

---
 cmds/subvolume.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
cmds/subvolume.c +1 -0
index 2020e486..0cdf7a68 100644
@@ -264,6 +264,7 @@ static int cmd_subvol_delete(const struct cmd_struct
 *cmd,
 	struct seen_fsid *seen_fsid_hash[SEEN_FSID_HASH_SIZE] = {  NULL, };
 	enum { COMMIT_AFTER = 1, COMMIT_EACH = 2 };
 	enum btrfs_util_error err;
+	uint64_t default_subvol_id = 0, target_subvol_id = 0;
 
 	optind = 0;
cmds/subvolume.c +0 -0
 	while (1) {
@@ -360,6 +361,25 @@ again:
 		goto out;
 	}
 
Quoted 8 lines

cmds/subvolume.c again:

Quoted 3 lines
cmds/subvolume.c +2 -0
+	err = btrfs_util_get_default_subvolume_fd(fd, &default_subvol_id);
+	if (fd < 0) {
 

Should it be
" if (err) { |

        error_btrfs_util(err);
        ...

"?

Hi Su! Thanks for review!

Yeah, I think it's definitely wrong. My mistake.

Quoted 13 lines

cmds/subvolume.c again:

Quoted 11 lines
cmds/subvolume.c +9 -0
+		ret = 1;
+		goto out;
+	}
+
+	if (subvolid > 0)
+		target_subvol_id = subvolid;
+	else {
+		err = btrfs_util_subvolume_id(path, &target_subvol_id);
+		if (fd < 0) {
 

And here.

It's wrong too.

Dave, maybe this patch needs for Su's review.
Usually in this case, Could you fix it directly ?
or do I need to send a new patch?

Thanks,
Sidong

Quoted 12 lines
Quoted 11 lines
cmds/subvolume.c +8 -0
+			ret = 1;
+			goto out;
+		}
+	}
+
+	if (target_subvol_id == default_subvol_id)
+		warning("trying to delete default subvolume.");
+
 	pr_verbose(MUST_LOG, "Delete subvolume (%s): ",
cmds/subvolume.c +0 -0
 		commit_mode == COMMIT_EACH ||
 		(commit_mode == COMMIT_AFTER && cnt + 1 == argc) ?
#4 lore raw
Quoted 21 lines · Sidong Yang
Quoted 9 lines · Su Yue

Review

Quoted 3 lines · Sidong Yang
(quoted diff) +2 -0
+	err = btrfs_util_get_default_subvolume_fd(fd, &default_subvol_id);
+	if (fd < 0) {

Should it be
" if (err) { |

        error_btrfs_util(err);
        ...

"?

Hi Su! Thanks for review!

Yeah, I think it's definitely wrong. My mistake.

Quoted 5 lines

cmds/subvolume.c again: · line 374

Quoted 3 lines
cmds/subvolume.c +2 -0
+		err = btrfs_util_subvolume_id(path, &target_subvol_id);
+		if (fd < 0) {

And here.

Quoted 5 lines

It's wrong too.

Dave, maybe this patch needs for Su's review.
Usually in this case, Could you fix it directly ?
or do I need to send a new patch?

Yes I'll fix it in the commit, no need to resend.

#5 lore raw
In reply to Su Yue
Quoted 8 lines · Su Yue

On Mon 28 Sep 2020 at 23:07, Sidong Yang <[email protected]>

Review

Quoted 4 lines
(quoted diff) +1 -0
+	err = btrfs_util_get_default_subvolume_fd(fd, 

&default_subvol_id);

(quoted diff) +1 -0
+	if (fd < 0) {

Should it be
" if (err) {
|

Quoted 8 lines
         error_btrfs_util(err);
         ...

"?

cmds/subvolume.c again: · line 374

Quoted 3 lines
cmds/subvolume.c +2 -0
+		err = btrfs_util_subvolume_id(path, &target_subvol_id);
+		if (fd < 0) {

And here.

Thanks for catching it, I missed it too.