All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] 1 of 2 - When a partition is claimed, claim the whole device for partitioning.
@ 2003-08-11  2:35 NeilBrown
  2003-08-11  7:23 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: NeilBrown @ 2003-08-11  2:35 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel

### Comments for ChangeSet

Current devices can be 'claimed' by filesystems (when mounting) or
md/raid (when being included in an array) or 'raw' or ....
This stop concurrent access by these systems.

However it is still possible for one system to claim the whole device
and a second system to claim one partition, which is not good.

With this patch, when a partition is claimed, the whole device is 
claimed for partitioning.  So you cannot have a partition and the
whole devices claimed at the same time (except if the whole device
is claimed for partitioning).

 ----------- Diffstat output ------------
 ./fs/block_dev.c |   32 ++++++++++++++++++++++++++++----
 1 files changed, 28 insertions(+), 4 deletions(-)

diff ./fs/block_dev.c~current~ ./fs/block_dev.c
--- ./fs/block_dev.c~current~	2003-08-11 09:01:38.000000000 +1000
+++ ./fs/block_dev.c	2003-08-11 09:01:38.000000000 +1000
@@ -419,12 +419,34 @@ void bd_forget(struct inode *inode)
 
 int bd_claim(struct block_device *bdev, void *holder)
 {
-	int res = -EBUSY;
+	int res;
 	spin_lock(&bdev_lock);
-	if (!bdev->bd_holder || bdev->bd_holder == holder) {
-		bdev->bd_holder = holder;
+
+	/* first decide result */
+	if (bdev->bd_holder == holder)
+		res = 0;	 /* already a holder */
+	else if (bdev->bd_holder != NULL)
+		res = -EBUSY; 	 /* held by someone else */
+	else if (bdev->bd_contains == bdev)
+		res = 0;  	 /* is a whole device which isn't held */
+
+	else if (bdev->bd_contains->bd_holder == bd_claim)
+		res = 0; 	 /* is a partition of a device that is being partitioned */
+	else if (bdev->bd_contains->bd_holder != NULL)
+		res = -EBUSY;	 /* is a partition of a held device */
+	else
+		res = 0;	 /* is a partition of an un-held device */
+
+	/* now impose change */
+	if (res==0) {
+		/* note that for a whole device bd_holders
+		 * will be incremented twice, and bd_holder will
+		 * be set to bd_claim before being set to holder
+		 */
+		bdev->bd_contains->bd_holders ++;
+		bdev->bd_contains->bd_holder = bd_claim;
 		bdev->bd_holders++;
-		res = 0;
+		bdev->bd_holder = holder;
 	}
 	spin_unlock(&bdev_lock);
 	return res;
@@ -433,6 +455,8 @@ int bd_claim(struct block_device *bdev, 
 void bd_release(struct block_device *bdev)
 {
 	spin_lock(&bdev_lock);
+	if (!--bdev->bd_contains->bd_holders)
+		bdev->bd_contains->bd_holder = NULL;
 	if (!--bdev->bd_holders)
 		bdev->bd_holder = NULL;
 	spin_unlock(&bdev_lock);

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

* Re: [PATCH] 1 of 2 - When a partition is claimed, claim the whole device for partitioning.
  2003-08-11  2:35 [PATCH] 1 of 2 - When a partition is claimed, claim the whole device for partitioning NeilBrown
@ 2003-08-11  7:23 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2003-08-11  7:23 UTC (permalink / raw)
  To: NeilBrown; +Cc: Linus Torvalds, linux-kernel

On Mon, Aug 11, 2003 at 12:35:57PM +1000, NeilBrown wrote:
> ### Comments for ChangeSet
> 
> Current devices can be 'claimed' by filesystems (when mounting) or
> md/raid (when being included in an array) or 'raw' or ....
> This stop concurrent access by these systems.
> 
> However it is still possible for one system to claim the whole device
> and a second system to claim one partition, which is not good.
> 
> With this patch, when a partition is claimed, the whole device is 
> claimed for partitioning.  So you cannot have a partition and the
> whole devices claimed at the same time (except if the whole device
> is claimed for partitioning).

Ok, this answers my question in the first mail...


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

end of thread, other threads:[~2003-08-11  7:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-11  2:35 [PATCH] 1 of 2 - When a partition is claimed, claim the whole device for partitioning NeilBrown
2003-08-11  7:23 ` Christoph Hellwig

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.