Skip to contentSkip to conversation

btrfs-progs: Correct check_running_fs_exclop() return value

PATCH In review Goldwyn Rodrigues 3 participants 4 messages Apr 9, 2021 – Jun 4, 2021 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: Correct check_running_fs_exclop() return value

check_running_fs_exclop() can return 1 when exclop is changed to "none" The ret is set by the return value of the select() operation. Checking the exclusive op changes just the exclop variable while ret is still set to 1.

Set ret exclusively if exclop is set to BTRFS_EXCL_NONE.

---
 common/utils.c | 2 ++
 1 file changed, 2 insertions(+)
common/utils.c +2 -0
index 57e41432..2e5175c3 100644
@@ -2326,6 +2326,8 @@ int check_running_fs_exclop(int fd, enum exclusive_operation start, bool enqueue
 			tv.tv_sec /= 2;
 			ret = select(sysfs_fd + 1, NULL, NULL, &fds, &tv);
 			exclop = get_fs_exclop(fd);
+			if (exclop == BTRFS_EXCL_NONE)
+				ret = 0;
 			continue;
 		}
 	}
Signature · 1 line
2.30.2
#1 lore raw
Quoted 7 lines · Goldwyn Rodrigues

check_running_fs_exclop() can return 1 when exclop is changed to "none" The ret is set by the return value of the select() operation. Checking the exclusive op changes just the exclop variable while ret is still set to 1.

Set ret exclusively if exclop is set to BTRFS_EXCL_NONE.
---

SOB missing.

Quoted 9 lines
  common/utils.c | 2 ++
  1 file changed, 2 insertions(+)
common/utils.c +0 -0
index 57e41432..2e5175c3 100644

common/utils.c int check_running_fs_exclop(int fd, enum exclusive_operation start, bool enqueue · line 2333

Quoted 8 lines
common/utils.c +2 -0
@@ -2326,6 +2326,8 @@ int check_running_fs_exclop(int fd, enum exclusive_operation start, bool enqueue
  			tv.tv_sec /= 2;
  			ret = select(sysfs_fd + 1, NULL, NULL, &fds, &tv);
  			exclop = get_fs_exclop(fd);
+			if (exclop == BTRFS_EXCL_NONE)
+				ret = 0;
  			continue;
  		}
  	}

This is bit inconsistent from what is done a few lines above:

        exclop = get_fs_exclop(fd);
        if (exclop <= 0) {
                ret = 0;
                goto out;
        }

We return 0 for both BTRFS_EXCLOP_NONE || BTRFS_EXCLOP_UNKNOWN.

Thanks, Anand

#2 lore raw
Quoted 10 lines · Anand Jain
Quoted 7 lines · Goldwyn Rodrigues

check_running_fs_exclop() can return 1 when exclop is changed to "none" The ret is set by the return value of the select() operation. Checking the exclusive op changes just the exclop variable while ret is still set to 1.

Set ret exclusively if exclop is set to BTRFS_EXCL_NONE.
---

SOB missing.

Yes, missed that.

Quoted 22 lines
Quoted 10 lines
  common/utils.c | 2 ++
  1 file changed, 2 insertions(+)
common/utils.c +0 -0
index 57e41432..2e5175c3 100644

common/utils.c int check_running_fs_exclop(int fd, enum exclusive_operation start, bool enqueue · line 2333

Quoted 8 lines
common/utils.c +2 -0
@@ -2326,6 +2326,8 @@ int check_running_fs_exclop(int fd, enum exclusive_operation start, bool enqueue
  			tv.tv_sec /= 2;
  			ret = select(sysfs_fd + 1, NULL, NULL, &fds, &tv);
  			exclop = get_fs_exclop(fd);
+			if (exclop == BTRFS_EXCL_NONE)
+				ret = 0;
  			continue;
  		}
  	}

This is bit inconsistent from what is done a few lines above:

Quoted 8 lines
        exclop = get_fs_exclop(fd);
        if (exclop <= 0) {
                ret = 0;
                goto out;
        }

We return 0 for both BTRFS_EXCLOP_NONE || BTRFS_EXCLOP_UNKNOWN.

I am not sure why we are translating the sysfs file value to enums. The only status we are concerned about is with "none", anything besides that is considered to be busy, for code flow purposes. For error display, we can print whatever the sysfs file contains. Was this done for i18n?

Of course, to maintain backward compatibility, we need to check on existence of the file.

Anyways, I will re-post this patch with what is done a few lines above.

Signature · 1 line
Goldwyn
#3 lore raw
Quoted 42 lines · Goldwyn Rodrigues
Quoted 10 lines · Anand Jain
Quoted 7 lines · Goldwyn Rodrigues

check_running_fs_exclop() can return 1 when exclop is changed to "none" The ret is set by the return value of the select() operation. Checking the exclusive op changes just the exclop variable while ret is still set to 1.

Set ret exclusively if exclop is set to BTRFS_EXCL_NONE.
---

SOB missing.

Yes, missed that.

Quoted 28 lines
Quoted 10 lines
  common/utils.c | 2 ++
  1 file changed, 2 insertions(+)
common/utils.c +0 -0
index 57e41432..2e5175c3 100644

common/utils.c int check_running_fs_exclop(int fd, enum exclusive_operation start, bool enqueue · line 2333

Quoted 8 lines
common/utils.c +2 -0
@@ -2326,6 +2326,8 @@ int check_running_fs_exclop(int fd, enum exclusive_operation start, bool enqueue
  			tv.tv_sec /= 2;
  			ret = select(sysfs_fd + 1, NULL, NULL, &fds, &tv);
  			exclop = get_fs_exclop(fd);
+			if (exclop == BTRFS_EXCL_NONE)
+				ret = 0;
  			continue;
  		}
  	}

This is bit inconsistent from what is done a few lines above:

        exclop = get_fs_exclop(fd);
        if (exclop <= 0) {
                ret = 0;
                goto out;
        }
Quoted 7 lines
Quoted 2 lines

We return 0 for both BTRFS_EXCLOP_NONE || BTRFS_EXCLOP_UNKNOWN.

I am not sure why we are translating the sysfs file value to enums. The only status we are concerned about is with "none", anything besides that is considered to be busy, for code flow purposes. For error display, we can print whatever the sysfs file contains. Was this done for i18n?

No, I changed it to string to enum because this is separating the actual input from sysfs to the internal representation of a valid state. The original patch read the sysfs file and compared string everywhere, this is not a good practice. i18n is not done anywhere in progs so that's not the reason.