All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] btrfs-progs: btrfsck operations should be exclusive
@ 2014-01-13 13:14 Anand Jain
  2014-01-14 16:47 ` David Sterba
  2014-01-15  4:15 ` [PATCH v2] " Anand Jain
  0 siblings, 2 replies; 3+ messages in thread
From: Anand Jain @ 2014-01-13 13:14 UTC (permalink / raw)
  To: linux-btrfs

From: Anand Jain <Anand.Jain@oracle.com>

this patch will make btrfsck operations to open disk in exclusive mode,
so that mount will fail when btrfsck is running

Signed-off-by: Anand Jain <Anand.Jain@oracle.com>
---
 cmds-check.c |  3 ++-
 disk-io.c    | 10 ++++++++--
 disk-io.h    |  1 +
 volumes.c    |  2 +-
 4 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index 1569d6f..ac456bb 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -6382,7 +6382,8 @@ int cmd_check(int argc, char **argv)
 	int option_index = 0;
 	int init_csum_tree = 0;
 	int init_extent_tree = 0;
-	enum btrfs_open_ctree_flags ctree_flags = OPEN_CTREE_PARTIAL;
+	enum btrfs_open_ctree_flags ctree_flags =
+				OPEN_CTREE_PARTIAL|OPEN_CTREE_O_EXCL;
 
 	while(1) {
 		int c;
diff --git a/disk-io.c b/disk-io.c
index bd90417..44d6f6f 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1062,6 +1062,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
 	struct btrfs_fs_devices *fs_devices = NULL;
 	struct extent_buffer *eb;
 	int ret;
+	int oflags;
 
 	if (sb_bytenr == 0)
 		sb_bytenr = BTRFS_SUPER_INFO_OFFSET;
@@ -1085,9 +1086,14 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
 
 	fs_info->fs_devices = fs_devices;
 	if (flags & OPEN_CTREE_WRITES)
-		ret = btrfs_open_devices(fs_devices, O_RDWR);
+		oflags = O_RDWR;
 	else
-		ret = btrfs_open_devices(fs_devices, O_RDONLY);
+		oflags = O_RDONLY;
+
+	if (flags & OPEN_CTREE_O_EXCL)
+		oflags |= O_EXCL;
+
+	ret = btrfs_open_devices(fs_devices, oflags);
 	if (ret)
 		goto out_devices;
 
diff --git a/disk-io.h b/disk-io.h
index ca6af2d..594deba 100644
--- a/disk-io.h
+++ b/disk-io.h
@@ -32,6 +32,7 @@ enum btrfs_open_ctree_flags {
 	OPEN_CTREE_RECOVER_SUPER	= 8,
 	OPEN_CTREE_RESTORE		= 16,
 	OPEN_CTREE_NO_BLOCK_GROUPS	= 32,
+	OPEN_CTREE_O_EXCL		= 64,
 };
 
 static inline u64 btrfs_sb_offset(int mirror)
diff --git a/volumes.c b/volumes.c
index 65be5f0..8c45851 100644
--- a/volumes.c
+++ b/volumes.c
@@ -214,7 +214,7 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, int flags)
 		if (device->devid == fs_devices->lowest_devid)
 			fs_devices->lowest_bdev = fd;
 		device->fd = fd;
-		if (flags == O_RDWR)
+		if (flags & O_RDWR)
 			device->writeable = 1;
 	}
 	return 0;
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH] btrfs-progs: btrfsck operations should be exclusive
  2014-01-13 13:14 [RFC PATCH] btrfs-progs: btrfsck operations should be exclusive Anand Jain
@ 2014-01-14 16:47 ` David Sterba
  2014-01-15  4:15 ` [PATCH v2] " Anand Jain
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2014-01-14 16:47 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs

On Mon, Jan 13, 2014 at 09:14:55PM +0800, Anand Jain wrote:
> From: Anand Jain <Anand.Jain@oracle.com>
> 
> this patch will make btrfsck operations to open disk in exclusive mode,
> so that mount will fail when btrfsck is running

Makes sense, especially if fsck is in the repair mode, mounting such fs
would be bad.

> --- a/disk-io.h
> +++ b/disk-io.h
> @@ -32,6 +32,7 @@ enum btrfs_open_ctree_flags {
>  	OPEN_CTREE_RECOVER_SUPER	= 8,
>  	OPEN_CTREE_RESTORE		= 16,
>  	OPEN_CTREE_NO_BLOCK_GROUPS	= 32,
> +	OPEN_CTREE_O_EXCL		= 64,

I'd rather pick a more descriptive name, matching to the others, eg.
OPEN_CTREE_EXCLUSIVE, which would translate to the O_EXCL open mode.

As you've implemented it, the exclusive mode applies to both read-only
and write/repair modes, which is imho right and should prevent
accidental errors, ie. a safe default.


david

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2] btrfs-progs: btrfsck operations should be exclusive
  2014-01-13 13:14 [RFC PATCH] btrfs-progs: btrfsck operations should be exclusive Anand Jain
  2014-01-14 16:47 ` David Sterba
@ 2014-01-15  4:15 ` Anand Jain
  1 sibling, 0 replies; 3+ messages in thread
From: Anand Jain @ 2014-01-15  4:15 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba, Anand Jain

this patch will make the btrfsck and btrfsck --repair
to work in exclusive mode, by opening the device
with the O_EXCL flag

Signed-off-by: Anand Jain <Anand.Jain@oracle.com>
---
 v2: renamed OPEN_CTREE_O_EXCL to OPEN_CTREE_EXCLUSIVE, thanks David

 cmds-check.c |  3 ++-
 disk-io.c    | 10 ++++++++--
 disk-io.h    |  1 +
 volumes.c    |  2 +-
 4 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index 1569d6f..6c4a951 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -6382,7 +6382,8 @@ int cmd_check(int argc, char **argv)
 	int option_index = 0;
 	int init_csum_tree = 0;
 	int init_extent_tree = 0;
-	enum btrfs_open_ctree_flags ctree_flags = OPEN_CTREE_PARTIAL;
+	enum btrfs_open_ctree_flags ctree_flags =
+				OPEN_CTREE_PARTIAL|OPEN_CTREE_EXCLUSIVE;
 
 	while(1) {
 		int c;
diff --git a/disk-io.c b/disk-io.c
index bd90417..fc7c645 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1062,6 +1062,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
 	struct btrfs_fs_devices *fs_devices = NULL;
 	struct extent_buffer *eb;
 	int ret;
+	int oflags;
 
 	if (sb_bytenr == 0)
 		sb_bytenr = BTRFS_SUPER_INFO_OFFSET;
@@ -1085,9 +1086,14 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
 
 	fs_info->fs_devices = fs_devices;
 	if (flags & OPEN_CTREE_WRITES)
-		ret = btrfs_open_devices(fs_devices, O_RDWR);
+		oflags = O_RDWR;
 	else
-		ret = btrfs_open_devices(fs_devices, O_RDONLY);
+		oflags = O_RDONLY;
+
+	if (flags & OPEN_CTREE_EXCLUSIVE)
+		oflags |= O_EXCL;
+
+	ret = btrfs_open_devices(fs_devices, oflags);
 	if (ret)
 		goto out_devices;
 
diff --git a/disk-io.h b/disk-io.h
index ca6af2d..941a3da 100644
--- a/disk-io.h
+++ b/disk-io.h
@@ -32,6 +32,7 @@ enum btrfs_open_ctree_flags {
 	OPEN_CTREE_RECOVER_SUPER	= 8,
 	OPEN_CTREE_RESTORE		= 16,
 	OPEN_CTREE_NO_BLOCK_GROUPS	= 32,
+	OPEN_CTREE_EXCLUSIVE		= 64,
 };
 
 static inline u64 btrfs_sb_offset(int mirror)
diff --git a/volumes.c b/volumes.c
index 65be5f0..8c45851 100644
--- a/volumes.c
+++ b/volumes.c
@@ -214,7 +214,7 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, int flags)
 		if (device->devid == fs_devices->lowest_devid)
 			fs_devices->lowest_bdev = fd;
 		device->fd = fd;
-		if (flags == O_RDWR)
+		if (flags & O_RDWR)
 			device->writeable = 1;
 	}
 	return 0;
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-01-15  4:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-13 13:14 [RFC PATCH] btrfs-progs: btrfsck operations should be exclusive Anand Jain
2014-01-14 16:47 ` David Sterba
2014-01-15  4:15 ` [PATCH v2] " Anand Jain

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.