[PATCH] btrfs-progs: avoid ioctl for multipath-dev with its non-multipath path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We should avoid using non multi-path (mp) path for mp disks
As of now there is no good way (like api) to check that.
A workaround way is to check if the O_EXCL open is unsuccessful.
This is safe since otherwise the BTRFS_IOC_SCAN_DEV ioctl would
fail if the disk-path can not be opened with the flag O_EXCL set.

Signed-off-by: Anand Jain <anand.jain@xxxxxxxxxx>
---
 utils.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/utils.c b/utils.c
index 3308668..0231677 100644
--- a/utils.c
+++ b/utils.c
@@ -1105,6 +1105,13 @@ again:
 		if (!S_ISBLK(st.st_mode)) {
 			continue;
 		}
+
+		/* Do not test for O_EXCL here since btrfs when
+		* mounted will open with O_EXCL, and if we don't
+		* allow btrfs_scan_one_device pass thru 
+		* btrfs fi show will not show the btrfs fs which
+		* are mounted
+		*/
 		fd = open(fullpath, O_RDONLY);
 		if (fd < 0) {
 			/* ignore the following errors:
@@ -1122,10 +1129,18 @@ again:
 					    &num_devices,
 					    BTRFS_SUPER_INFO_OFFSET,
 					    0ull);
+		close(fd);
+
 		if (ret == 0 && flags & BTRFS_SCAN_REGISTER) {
+			/* Test if the dev is already opened with O_EXCL flag
+			*  if yes then no need to call ioctl since the
+			*  ioctl will anyway fail.
+			*/
+			fd = open(fullpath, O_RDONLY|O_EXCL);
+			if (fd < 0) continue; 
+			close(fd);
 			btrfs_register_one_device(fullpath);
 		}
-		close(fd);
 	}
 	if (!list_empty(&pending_list)) {
 		free(pending);
@@ -1444,6 +1459,12 @@ scan_again:
 			continue;
 		}
 
+		/* Do not test for O_EXCL here since btrfs when
+		* mounted will open with O_EXCL, and if we don't
+		* allow btrfs_scan_one_device pass thru 
+		* btrfs fi show will not show the btrfs fs which
+		* are mounted
+		*/
 		fd = open(fullpath, O_RDONLY);
 		if (fd < 0) {
 			fprintf(stderr, "failed to open %s: %s\n",
@@ -1455,6 +1476,13 @@ scan_again:
 					    BTRFS_SUPER_INFO_OFFSET,
 					    0ull);
 		if (ret == 0 && flags & BTRFS_SCAN_REGISTER) {
+			/* Test if the dev is already opened with O_EXCL flag
+			*  if yes then no need to call ioctl since the
+			*  ioctl will anyway fail.
+			*/
+			fd = open(fullpath, O_RDONLY|O_EXCL);
+			if (fd < 0) continue; 
+			close(fd);
 			btrfs_register_one_device(fullpath);
 		}
 		close(fd);
-- 
1.8.1.227.g44fe835

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




[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux