* [PATCH] 2 of 2 - Allow O_EXCL on a block device to claim exclusive use.
@ 2003-08-11 2:35 NeilBrown
2003-08-11 7:22 ` Christoph Hellwig
0 siblings, 1 reply; 5+ messages in thread
From: NeilBrown @ 2003-08-11 2:35 UTC (permalink / raw)
To: Linus Torvalds; +Cc: linux-kernel
### Comments for ChangeSet
the blockdev layer has a concept of 'claiming' a device,
so for example it can be claimed when a filesystem is
mounted or when it is included into a raid array.
Only one subsystem can claim it at a time.
This patch matches this functionality available to user-space
via the O_EXCL flag to open.
This allows user-space programs to easily test if a device
is currently mounted etc, and to prevent a device from being
mounted or otherwise claimed.
----------- Diffstat output ------------
./fs/block_dev.c | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletion(-)
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:41.000000000 +1000
@@ -643,6 +643,7 @@ int blkdev_get(struct block_device *bdev
int blkdev_open(struct inode * inode, struct file * filp)
{
struct block_device *bdev;
+ int res;
/*
* Preserve backwards compatibility and allow large file access
@@ -655,7 +656,18 @@ int blkdev_open(struct inode * inode, st
bd_acquire(inode);
bdev = inode->i_bdev;
- return do_open(bdev, inode, filp);
+ res = do_open(bdev, inode, filp);
+ if (res)
+ return res;
+
+ if (!(filp->f_flags & O_EXCL) )
+ return 0;
+
+ if (!(res = bd_claim(bdev, filp)))
+ return 0;
+
+ blkdev_put(bdev, BDEV_FILE);
+ return res;
}
int blkdev_put(struct block_device *bdev, int kind)
@@ -704,6 +716,8 @@ int blkdev_put(struct block_device *bdev
int blkdev_close(struct inode * inode, struct file * filp)
{
+ if (inode->i_bdev->bd_holder == filp)
+ bd_release(inode->i_bdev);
return blkdev_put(inode->i_bdev, BDEV_FILE);
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] 2 of 2 - Allow O_EXCL on a block device to claim exclusive use.
2003-08-11 2:35 [PATCH] 2 of 2 - Allow O_EXCL on a block device to claim exclusive use NeilBrown
@ 2003-08-11 7:22 ` Christoph Hellwig
2003-08-12 1:48 ` Neil Brown
0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2003-08-11 7:22 UTC (permalink / raw)
To: NeilBrown; +Cc: Linus Torvalds, linux-kernel
On Mon, Aug 11, 2003 at 12:35:57PM +1000, NeilBrown wrote:
> 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:41.000000000 +1000
> @@ -643,6 +643,7 @@ int blkdev_get(struct block_device *bdev
> int blkdev_open(struct inode * inode, struct file * filp)
> {
> struct block_device *bdev;
> + int res;
>
> /*
> * Preserve backwards compatibility and allow large file access
> @@ -655,7 +656,18 @@ int blkdev_open(struct inode * inode, st
> bd_acquire(inode);
> bdev = inode->i_bdev;
>
> - return do_open(bdev, inode, filp);
> + res = do_open(bdev, inode, filp);
> + if (res)
> + return res;
> +
> + if (!(filp->f_flags & O_EXCL) )
> + return 0;
> +
> + if (!(res = bd_claim(bdev, filp)))
> + return 0;
> +
> + blkdev_put(bdev, BDEV_FILE);
> + return res;
Shouldn't you claim it before opening. Also what is the desired
behaviour when opening partitions vs whole device with O_EXCL?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] 2 of 2 - Allow O_EXCL on a block device to claim exclusive use.
2003-08-11 7:22 ` Christoph Hellwig
@ 2003-08-12 1:48 ` Neil Brown
2003-08-12 2:56 ` Andries Brouwer
0 siblings, 1 reply; 5+ messages in thread
From: Neil Brown @ 2003-08-12 1:48 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Linus Torvalds, linux-kernel
On Monday August 11, hch@infradead.org wrote:
> On Mon, Aug 11, 2003 at 12:35:57PM +1000, NeilBrown wrote:
> > diff ./fs/block_dev.c~current~ ./fs/block_dev.c
> > - return do_open(bdev, inode, filp);
> > + res = do_open(bdev, inode, filp);
> > + if (res)
> > + return res;
> > +
> > + if (!(filp->f_flags & O_EXCL) )
> > + return 0;
> > +
> > + if (!(res = bd_claim(bdev, filp)))
> > + return 0;
> > +
> > + blkdev_put(bdev, BDEV_FILE);
> > + return res;
>
> Shouldn't you claim it before opening. Also what is the desired
> behaviour when opening partitions vs whole device with O_EXCL?
Good question.
My first attempt at this did claim before openning.
However that didn't work.
Some aspects of the bdev that are needed for claiming are not
initialised before it is first opened. In particular, bd_contains,
gets set up by do_open.
Also, other code uses this order.
e.g. open_bdev_excl called blkdev_get (which calls do_open) before
bd_claim.
NeilBrown
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] 2 of 2 - Allow O_EXCL on a block device to claim exclusive use.
2003-08-12 1:48 ` Neil Brown
@ 2003-08-12 2:56 ` Andries Brouwer
2003-08-12 3:06 ` viro
0 siblings, 1 reply; 5+ messages in thread
From: Andries Brouwer @ 2003-08-12 2:56 UTC (permalink / raw)
To: Neil Brown; +Cc: Christoph Hellwig, Linus Torvalds, linux-kernel
On Tue, Aug 12, 2003 at 11:48:28AM +1000, Neil Brown wrote:
> My first attempt at this did claim before openning.
> However that didn't work.
> Some aspects of the bdev that are needed for claiming are not
> initialised before it is first opened. In particular, bd_contains,
> gets set up by do_open.
Size and structure of partitions are entirely independent of whether
someone has opened them. Thus, the corresponding bookkeeping must
not be in struct block_device, which exists only when the device
is open, but in struct gendisk or so (and only there).
It is a design mistake to have such stuff in struct block device.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] 2 of 2 - Allow O_EXCL on a block device to claim exclusive use.
2003-08-12 2:56 ` Andries Brouwer
@ 2003-08-12 3:06 ` viro
0 siblings, 0 replies; 5+ messages in thread
From: viro @ 2003-08-12 3:06 UTC (permalink / raw)
To: Andries Brouwer
Cc: Neil Brown, Christoph Hellwig, Linus Torvalds, linux-kernel
On Tue, Aug 12, 2003 at 04:56:10AM +0200, Andries Brouwer wrote:
> On Tue, Aug 12, 2003 at 11:48:28AM +1000, Neil Brown wrote:
>
> > My first attempt at this did claim before openning.
> > However that didn't work.
> > Some aspects of the bdev that are needed for claiming are not
> > initialised before it is first opened. In particular, bd_contains,
> > gets set up by do_open.
>
> Size and structure of partitions are entirely independent of whether
> someone has opened them. Thus, the corresponding bookkeeping must
> not be in struct block_device, which exists only when the device
> is open, but in struct gendisk or so (and only there).
>
> It is a design mistake to have such stuff in struct block device.
WTF does it have to do with ->bd_contains? We *do* have the information
you (and nobody else in this thread) are talking about - in gendisk.
Exclusion upon open, OTOH, has something with opening these beast, won't
you agree?
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-08-12 3:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-11 2:35 [PATCH] 2 of 2 - Allow O_EXCL on a block device to claim exclusive use NeilBrown
2003-08-11 7:22 ` Christoph Hellwig
2003-08-12 1:48 ` Neil Brown
2003-08-12 2:56 ` Andries Brouwer
2003-08-12 3:06 ` viro
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.