public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] floppy: remove floppy-specific O_EXCL handling
@ 2012-05-13  9:02 Jiri Kosina
  2012-05-14 16:25 ` Tejun Heo
  0 siblings, 1 reply; 8+ messages in thread
From: Jiri Kosina @ 2012-05-13  9:02 UTC (permalink / raw)
  To: Andrew Morton, Jens Axboe, NeilBrown, Tejun Heo; +Cc: linux-kernel

Block layer now handles O_EXCL in a generic way for block devices.

The semantics is however different for floppy and all other block devices,
as floppy driver contains its own O_EXCL handling.

The semantics for all-but-floppy bdevs is "there can be at most one O_EXCL 
open of this file", while for floppy bdev the semantics is "if someone has 
the bdev open with O_EXCL, noone else can open it".

Remove the floppy-specific handling and let the generic bdev code O_EXCL
handling take over.

Signed-off-by: Jiri Kosina <jkosina@suse.cz>
---
 drivers/block/floppy.c |    8 +-------
 1 files changed, 1 insertions(+), 7 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index b0b00d7..fe694f8 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -3650,13 +3650,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
 		set_bit(FD_VERIFY_BIT, &UDRS->flags);
 	}
 
-	if (UDRS->fd_ref == -1 || (UDRS->fd_ref && (mode & FMODE_EXCL)))
-		goto out2;
-
-	if (mode & FMODE_EXCL)
-		UDRS->fd_ref = -1;
-	else
-		UDRS->fd_ref++;
+	UDRS->fd_ref++;
 
 	opened_bdev[drive] = bdev;
 
-- 
Jiri Kosina
SUSE Labs

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

* Re: [PATCH] floppy: remove floppy-specific O_EXCL handling
  2012-05-13  9:02 [PATCH] floppy: remove floppy-specific O_EXCL handling Jiri Kosina
@ 2012-05-14 16:25 ` Tejun Heo
  2012-05-14 16:49   ` Joe Perches
  2012-05-14 20:42   ` Jiri Kosina
  0 siblings, 2 replies; 8+ messages in thread
From: Tejun Heo @ 2012-05-14 16:25 UTC (permalink / raw)
  To: Jiri Kosina; +Cc: Andrew Morton, Jens Axboe, NeilBrown, linux-kernel

Hello,

On Sun, May 13, 2012 at 11:02:07AM +0200, Jiri Kosina wrote:
> Block layer now handles O_EXCL in a generic way for block devices.
> 
> The semantics is however different for floppy and all other block devices,
> as floppy driver contains its own O_EXCL handling.
> 
> The semantics for all-but-floppy bdevs is "there can be at most one O_EXCL 
> open of this file", while for floppy bdev the semantics is "if someone has 
> the bdev open with O_EXCL, noone else can open it".
> 
> Remove the floppy-specific handling and let the generic bdev code O_EXCL
> handling take over.
> 
> Signed-off-by: Jiri Kosina <jkosina@suse.cz>

Patch looks good to me but why do we want to change this at this
point?

Thanks.

-- 
tejun

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

* Re: [PATCH] floppy: remove floppy-specific O_EXCL handling
  2012-05-14 16:25 ` Tejun Heo
@ 2012-05-14 16:49   ` Joe Perches
  2012-05-14 20:42   ` Jiri Kosina
  1 sibling, 0 replies; 8+ messages in thread
From: Joe Perches @ 2012-05-14 16:49 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Jiri Kosina, Andrew Morton, Jens Axboe, NeilBrown, linux-kernel

On Mon, 2012-05-14 at 09:25 -0700, Tejun Heo wrote:
> Hello,
> 
> On Sun, May 13, 2012 at 11:02:07AM +0200, Jiri Kosina wrote:
> > Block layer now handles O_EXCL in a generic way for block devices.
> > 
> > The semantics is however different for floppy and all other block devices,
> > as floppy driver contains its own O_EXCL handling.
> > 
> > The semantics for all-but-floppy bdevs is "there can be at most one O_EXCL 
> > open of this file", while for floppy bdev the semantics is "if someone has 
> > the bdev open with O_EXCL, noone else can open it".
> > 
> > Remove the floppy-specific handling and let the generic bdev code O_EXCL
> > handling take over.
> > 
> > Signed-off-by: Jiri Kosina <jkosina@suse.cz>
> 
> Patch looks good to me but why do we want to change this at this
> point?

Because the hobgoblins of consistency are as fun to hunt as the wumpus?



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

* Re: [PATCH] floppy: remove floppy-specific O_EXCL handling
  2012-05-14 16:25 ` Tejun Heo
  2012-05-14 16:49   ` Joe Perches
@ 2012-05-14 20:42   ` Jiri Kosina
  2012-05-14 21:19     ` Tejun Heo
  1 sibling, 1 reply; 8+ messages in thread
From: Jiri Kosina @ 2012-05-14 20:42 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Andrew Morton, Jens Axboe, NeilBrown, linux-kernel, Joe Perches

On Mon, 14 May 2012, Tejun Heo wrote:

> > Block layer now handles O_EXCL in a generic way for block devices.
> > 
> > The semantics is however different for floppy and all other block devices,
> > as floppy driver contains its own O_EXCL handling.
> > 
> > The semantics for all-but-floppy bdevs is "there can be at most one O_EXCL 
> > open of this file", while for floppy bdev the semantics is "if someone has 
> > the bdev open with O_EXCL, noone else can open it".
> > 
> > Remove the floppy-specific handling and let the generic bdev code O_EXCL
> > handling take over.
> > 
> > Signed-off-by: Jiri Kosina <jkosina@suse.cz>
> 
> Patch looks good to me 

Thanks.

> but why do we want to change this at this point?

Because since

	commit e525fd89d380c4a94c0d63913a1dd1a593ed25e7
	Author: Tejun Heo <tj@kernel.org>
	Date:   Sat Nov 13 11:55:17 2010 +0100

	    block: make blkdev_get/put() handle exclusive access

mount of /dev/fd0 actually causes the fd0 block device be claimed with 
_EXCL. Before this commit, you are able to mount /dev/fd0 and then open() 
it afterward. After this commit you can't any more, because mounting 
/dev/fd0 already passes O_EXCL to floppy_open(), and thus noone else can 
open(/dev/fd0) any more.

My commit brings things back into shape, i.e. you can, equally to other 
block devices, both mount it and open() it afterwards.

-- 
Jiri Kosina
SUSE Labs

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

* Re: [PATCH] floppy: remove floppy-specific O_EXCL handling
  2012-05-14 20:42   ` Jiri Kosina
@ 2012-05-14 21:19     ` Tejun Heo
  2012-05-14 21:38       ` Jiri Kosina
  0 siblings, 1 reply; 8+ messages in thread
From: Tejun Heo @ 2012-05-14 21:19 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: Andrew Morton, Jens Axboe, NeilBrown, linux-kernel, Joe Perches

Hello,

On Mon, May 14, 2012 at 10:42:58PM +0200, Jiri Kosina wrote:
> Because since
> 
> 	commit e525fd89d380c4a94c0d63913a1dd1a593ed25e7
> 	Author: Tejun Heo <tj@kernel.org>
> 	Date:   Sat Nov 13 11:55:17 2010 +0100
> 
> 	    block: make blkdev_get/put() handle exclusive access
> 
> mount of /dev/fd0 actually causes the fd0 block device be claimed with 
> _EXCL. Before this commit, you are able to mount /dev/fd0 and then open() 
> it afterward. After this commit you can't any more, because mounting 
> /dev/fd0 already passes O_EXCL to floppy_open(), and thus noone else can 
> open(/dev/fd0) any more.
> 
> My commit brings things back into shape, i.e. you can, equally to other 
> block devices, both mount it and open() it afterwards.

Ah, that makes sense.  Maybe it's a good idea to note why the change
is necessary in the commit message too?

 Acked-by: Tejun Heo <tj@kernel.org>

Thanks.

-- 
tejun

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

* Re: [PATCH] floppy: remove floppy-specific O_EXCL handling
  2012-05-14 21:19     ` Tejun Heo
@ 2012-05-14 21:38       ` Jiri Kosina
  2012-05-14 23:22         ` NeilBrown
  0 siblings, 1 reply; 8+ messages in thread
From: Jiri Kosina @ 2012-05-14 21:38 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Andrew Morton, Jens Axboe, NeilBrown, linux-kernel, Joe Perches

On Mon, 14 May 2012, Tejun Heo wrote:

> > Because since
> > 
> > 	commit e525fd89d380c4a94c0d63913a1dd1a593ed25e7
> > 	Author: Tejun Heo <tj@kernel.org>
> > 	Date:   Sat Nov 13 11:55:17 2010 +0100
> > 
> > 	    block: make blkdev_get/put() handle exclusive access
> > 
> > mount of /dev/fd0 actually causes the fd0 block device be claimed with 
> > _EXCL. Before this commit, you are able to mount /dev/fd0 and then open() 
> > it afterward. After this commit you can't any more, because mounting 
> > /dev/fd0 already passes O_EXCL to floppy_open(), and thus noone else can 
> > open(/dev/fd0) any more.
> > 
> > My commit brings things back into shape, i.e. you can, equally to other 
> > block devices, both mount it and open() it afterwards.
> 
> Ah, that makes sense.  Maybe it's a good idea to note why the change
> is necessary in the commit message too?

Makes sense. Please find the updated patch below. Andrew, Jens, are you 
going to pick it up, please?
Thanks.




From: Jiri Kosina <jkosina@suse.cz>
Subject: [PATCH] floppy: remove floppy-specific O_EXCL handling

Block layer now handles O_EXCL in a generic way for block devices.

The semantics is however different for floppy and all other block devices,
as floppy driver contains its own O_EXCL handling.

The semantics for all-but-floppy bdevs is "there can be at most one O_EXCL 
open of this file", while for floppy bdev the semantics is "if someone has 
the bdev open with O_EXCL, noone else can open it".

There is actual userspace-observable change in behavior because of this 
since commit e525fd89d380c ("block: make blkdev_get/put() handle exclusive 
access") -- on kernels containing this commit, mount of /dev/fd0 causes 
the fd0 block device be claimed with _EXCL, preventing subsequent 
open(/dev/fd0).

Bring things back into shape, i.e. make it possible, analogically to other 
block devices, to mount the floppy and open() it afterwards -- remove the 
floppy-specific handling and let the generic bdev code O_EXCL handling 
take over.

Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Acked-by: Tejun Heo <tj@kernel.org>
---
 drivers/block/floppy.c |    8 +-------
 1 files changed, 1 insertions(+), 7 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index b0b00d7..fe694f8 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -3650,13 +3650,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
 		set_bit(FD_VERIFY_BIT, &UDRS->flags);
 	}
 
-	if (UDRS->fd_ref == -1 || (UDRS->fd_ref && (mode & FMODE_EXCL)))
-		goto out2;
-
-	if (mode & FMODE_EXCL)
-		UDRS->fd_ref = -1;
-	else
-		UDRS->fd_ref++;
+	UDRS->fd_ref++;
 
 	opened_bdev[drive] = bdev;
 
-- 
Jiri Kosina
SUSE Labs

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

* Re: [PATCH] floppy: remove floppy-specific O_EXCL handling
  2012-05-14 21:38       ` Jiri Kosina
@ 2012-05-14 23:22         ` NeilBrown
  2012-05-15  6:15           ` Jiri Kosina
  0 siblings, 1 reply; 8+ messages in thread
From: NeilBrown @ 2012-05-14 23:22 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: Tejun Heo, Andrew Morton, Jens Axboe, linux-kernel, Joe Perches

[-- Attachment #1: Type: text/plain, Size: 3270 bytes --]

On Mon, 14 May 2012 23:38:27 +0200 (CEST) Jiri Kosina <jkosina@suse.cz> wrote:

> On Mon, 14 May 2012, Tejun Heo wrote:
> 
> > > Because since
> > > 
> > > 	commit e525fd89d380c4a94c0d63913a1dd1a593ed25e7
> > > 	Author: Tejun Heo <tj@kernel.org>
> > > 	Date:   Sat Nov 13 11:55:17 2010 +0100
> > > 
> > > 	    block: make blkdev_get/put() handle exclusive access
> > > 
> > > mount of /dev/fd0 actually causes the fd0 block device be claimed with 
> > > _EXCL. Before this commit, you are able to mount /dev/fd0 and then open() 
> > > it afterward. After this commit you can't any more, because mounting 
> > > /dev/fd0 already passes O_EXCL to floppy_open(), and thus noone else can 
> > > open(/dev/fd0) any more.
> > > 
> > > My commit brings things back into shape, i.e. you can, equally to other 
> > > block devices, both mount it and open() it afterwards.
> > 
> > Ah, that makes sense.  Maybe it's a good idea to note why the change
> > is necessary in the commit message too?
> 
> Makes sense. Please find the updated patch below. Andrew, Jens, are you 
> going to pick it up, please?
> Thanks.
> 
> 
> 
> 
> From: Jiri Kosina <jkosina@suse.cz>
> Subject: [PATCH] floppy: remove floppy-specific O_EXCL handling
> 
> Block layer now handles O_EXCL in a generic way for block devices.
> 
> The semantics is however different for floppy and all other block devices,
> as floppy driver contains its own O_EXCL handling.
> 
> The semantics for all-but-floppy bdevs is "there can be at most one O_EXCL 
> open of this file", while for floppy bdev the semantics is "if someone has 
> the bdev open with O_EXCL, noone else can open it".
> 
> There is actual userspace-observable change in behavior because of this 
> since commit e525fd89d380c ("block: make blkdev_get/put() handle exclusive 
> access") -- on kernels containing this commit, mount of /dev/fd0 causes 
> the fd0 block device be claimed with _EXCL, preventing subsequent 
> open(/dev/fd0).
> 
> Bring things back into shape, i.e. make it possible, analogically to other 
> block devices, to mount the floppy and open() it afterwards -- remove the 
> floppy-specific handling and let the generic bdev code O_EXCL handling 
> take over.
> 
> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
> Acked-by: Tejun Heo <tj@kernel.org>
> ---
>  drivers/block/floppy.c |    8 +-------
>  1 files changed, 1 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
> index b0b00d7..fe694f8 100644
> --- a/drivers/block/floppy.c
> +++ b/drivers/block/floppy.c
> @@ -3650,13 +3650,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
>  		set_bit(FD_VERIFY_BIT, &UDRS->flags);
>  	}
>  
> -	if (UDRS->fd_ref == -1 || (UDRS->fd_ref && (mode & FMODE_EXCL)))
> -		goto out2;
> -
> -	if (mode & FMODE_EXCL)
> -		UDRS->fd_ref = -1;
> -	else
> -		UDRS->fd_ref++;
> +	UDRS->fd_ref++;
>  
>  	opened_bdev[drive] = bdev;
>  


As we not longer set fd_ref to -1, you should also remove:

	if (UDRS->fd_ref < 0)
		UDRS->fd_ref = 0;
	else 

from floppy_release(), and the 'out:' section of floppy_open().

With those changes:
   Acked-by: NeilBrown <neilb@suse.de>

Thanks,
NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

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

* Re: [PATCH] floppy: remove floppy-specific O_EXCL handling
  2012-05-14 23:22         ` NeilBrown
@ 2012-05-15  6:15           ` Jiri Kosina
  0 siblings, 0 replies; 8+ messages in thread
From: Jiri Kosina @ 2012-05-15  6:15 UTC (permalink / raw)
  To: NeilBrown, Andrew Morton; +Cc: Tejun Heo, Jens Axboe, linux-kernel, Joe Perches

On Tue, 15 May 2012, NeilBrown wrote:

> > From: Jiri Kosina <jkosina@suse.cz>
> > Subject: [PATCH] floppy: remove floppy-specific O_EXCL handling
> > 
> > Block layer now handles O_EXCL in a generic way for block devices.
> > 
> > The semantics is however different for floppy and all other block devices,
> > as floppy driver contains its own O_EXCL handling.
> > 
> > The semantics for all-but-floppy bdevs is "there can be at most one O_EXCL 
> > open of this file", while for floppy bdev the semantics is "if someone has 
> > the bdev open with O_EXCL, noone else can open it".
> > 
> > There is actual userspace-observable change in behavior because of this 
> > since commit e525fd89d380c ("block: make blkdev_get/put() handle exclusive 
> > access") -- on kernels containing this commit, mount of /dev/fd0 causes 
> > the fd0 block device be claimed with _EXCL, preventing subsequent 
> > open(/dev/fd0).
> > 
> > Bring things back into shape, i.e. make it possible, analogically to other 
> > block devices, to mount the floppy and open() it afterwards -- remove the 
> > floppy-specific handling and let the generic bdev code O_EXCL handling 
> > take over.
> > 
> > Signed-off-by: Jiri Kosina <jkosina@suse.cz>
> > Acked-by: Tejun Heo <tj@kernel.org>
> > ---
> >  drivers/block/floppy.c |    8 +-------
> >  1 files changed, 1 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
> > index b0b00d7..fe694f8 100644
> > --- a/drivers/block/floppy.c
> > +++ b/drivers/block/floppy.c
> > @@ -3650,13 +3650,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
> >  		set_bit(FD_VERIFY_BIT, &UDRS->flags);
> >  	}
> >  
> > -	if (UDRS->fd_ref == -1 || (UDRS->fd_ref && (mode & FMODE_EXCL)))
> > -		goto out2;
> > -
> > -	if (mode & FMODE_EXCL)
> > -		UDRS->fd_ref = -1;
> > -	else
> > -		UDRS->fd_ref++;
> > +	UDRS->fd_ref++;
> >  
> >  	opened_bdev[drive] = bdev;
> >  
> 
> 
> As we not longer set fd_ref to -1, you should also remove:
> 
> 	if (UDRS->fd_ref < 0)
> 		UDRS->fd_ref = 0;
> 	else 
> 
> from floppy_release(), and the 'out:' section of floppy_open().
> 
> With those changes:
>    Acked-by: NeilBrown <neilb@suse.de>

Good point, thanks.

Andrew, could you please replace 
floppy-remove-floppy-specific-o_excl-handling.patch in your tree with the 
updated version below?

Thanks.



From: Jiri Kosina <jkosina@suse.cz>
Subject: [PATCH] floppy: remove floppy-specific O_EXCL handling

Block layer now handles O_EXCL in a generic way for block devices.

The semantics is however different for floppy and all other block devices,
as floppy driver contains its own O_EXCL handling.

The semantics for all-but-floppy bdevs is "there can be at most one O_EXCL
open of this file", while for floppy bdev the semantics is "if someone has
the bdev open with O_EXCL, noone else can open it".

There is actual userspace-observable change in behavior because of this
since commit e525fd89d380c ("block: make blkdev_get/put() handle exclusive
access") -- on kernels containing this commit, mount of /dev/fd0 causes
the fd0 block device be claimed with _EXCL, preventing subsequent
open(/dev/fd0).

Bring things back into shape, i.e.  make it possible, analogically to
other block devices, to mount the floppy and open() it afterwards --
remove the floppy-specific handling and let the generic bdev code O_EXCL
handling take over.

Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Acked-by: Tejun Heo <tj@kernel.org>
Acked-by: NeilBrown <neilb@suse.de>
Cc: Jens Axboe <axboe@kernel.dk>
---
 drivers/block/floppy.c |   18 ++++--------------
 1 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index b0b00d7..87c3a6e 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -3612,9 +3612,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
 
 	mutex_lock(&floppy_mutex);
 	mutex_lock(&open_lock);
-	if (UDRS->fd_ref < 0)
-		UDRS->fd_ref = 0;
-	else if (!UDRS->fd_ref--) {
+	if (!UDRS->fd_ref--) {
 		DPRINT("floppy_release with fd_ref == 0");
 		UDRS->fd_ref = 0;
 	}
@@ -3650,13 +3648,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
 		set_bit(FD_VERIFY_BIT, &UDRS->flags);
 	}
 
-	if (UDRS->fd_ref == -1 || (UDRS->fd_ref && (mode & FMODE_EXCL)))
-		goto out2;
-
-	if (mode & FMODE_EXCL)
-		UDRS->fd_ref = -1;
-	else
-		UDRS->fd_ref++;
+	UDRS->fd_ref++;
 
 	opened_bdev[drive] = bdev;
 
@@ -3719,10 +3711,8 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
 	mutex_unlock(&floppy_mutex);
 	return 0;
 out:
-	if (UDRS->fd_ref < 0)
-		UDRS->fd_ref = 0;
-	else
-		UDRS->fd_ref--;
+	UDRS->fd_ref--;
+
 	if (!UDRS->fd_ref)
 		opened_bdev[drive] = NULL;
 out2:


-- 
Jiri Kosina
SUSE Labs

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

end of thread, other threads:[~2012-05-15  6:16 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-13  9:02 [PATCH] floppy: remove floppy-specific O_EXCL handling Jiri Kosina
2012-05-14 16:25 ` Tejun Heo
2012-05-14 16:49   ` Joe Perches
2012-05-14 20:42   ` Jiri Kosina
2012-05-14 21:19     ` Tejun Heo
2012-05-14 21:38       ` Jiri Kosina
2012-05-14 23:22         ` NeilBrown
2012-05-15  6:15           ` Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox