[PATCH] xfs_admin: open with O_EXCL if we will be writing

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

 



So, coreOS has a systemd unit which changes the UUID of a filesystem
on first boot, and they're currently racing that with mount.

This leads to corruption and mount failures.

If xfs_db is running as xfs_admin in a mode that can write to the
device, open that device exclusively.

This might still lead to mount failures if xfs_admin wins the open race,
but at least it won't corrupt the filesystem along the way.

Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
---

(this opens plain files O_EXCL is well, which is undefined without O_CREAT.
I'm not sure if we need to worry about that.)

diff --git a/db/init.c b/db/init.c
index eec65d0..f43be6e 100644
--- a/db/init.c
+++ b/db/init.c
@@ -97,6 +97,14 @@ init(
 	else
 		x.dname = fsdevice;
 
+	/*
+	 * If running as xfs_admin in RW mode, prevent concurrent
+	 * opens of a block device.
+ 	 */
+	if (!strcmp(progname, "xfs_admin") &&
+	    (x.isreadonly != LIBXFS_ISREADONLY))
+		x.isreadonly = LIBXFS_EXCLUSIVELY;
+
 	x.bcache_flags = CACHE_MISCOMPARE_PURGE;
 	if (!libxfs_init(&x)) {
 		fputs(_("\nfatal error -- couldn't initialize XFS library\n"),




[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux