public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2.5.74-mm2] nbd: remove unneeded nbd_open/nbd_release and refcnt
@ 2003-07-06 21:15 Paul Clements
  2003-07-06 21:20 ` [PATCH 2.5.74-mm2] nbd: make nbd and block layer agree about device and block sizes Paul Clements
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Clements @ 2003-07-06 21:15 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel

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

Andrew,

per Jeff's comments, here's the revised patch for removing
nbd_open/release

--
Paul

[-- Attachment #2: nbd-remove_open_release-2.diff --]
[-- Type: text/x-diff, Size: 2653 bytes --]

--- linux-2.5.74-mm2/drivers/block/nbd.c.MINUS_LL	2003-07-06 11:31:51.000000000 -0400
+++ linux-2.5.74-mm2/drivers/block/nbd.c	2003-07-06 16:55:22.224389840 -0400
@@ -77,8 +77,6 @@
 #define dprintk(flags, fmt...) do { \
 	if (debugflags & (flags)) printk(KERN_DEBUG fmt); \
 } while (0)
-#define DBG_OPEN        0x0001
-#define DBG_RELEASE     0x0002
 #define DBG_IOCTL       0x0004
 #define DBG_INIT        0x0010
 #define DBG_EXIT        0x0020
@@ -521,33 +519,6 @@ static void do_nbd_request(request_queue
 	return;
 }
 
-static int nbd_open(struct inode *inode, struct file *file)
-{
-	struct nbd_device *lo = inode->i_bdev->bd_disk->private_data;
-
-	dprintk(DBG_OPEN, "%s: nbd_open refcnt=%d\n", lo->disk->disk_name,
-			lo->refcnt);
-	lo->refcnt++;
-	return 0;
-}
-
-static int nbd_release(struct inode *inode, struct file *file)
-{
-	struct nbd_device *lo = inode->i_bdev->bd_disk->private_data;
-
-#ifdef PARANOIA
-	if (lo->refcnt <= 0) {
-		printk(KERN_ALERT "%s: nbd_release: refcount(%d) <= 0\n",
-				lo->disk->disk_name, lo->refcnt);
-		BUG();
-	}
-#endif
-	lo->refcnt--;
-	dprintk(DBG_RELEASE, "%s: nbd_release: refcnt=%d\n",
-			lo->disk->disk_name, lo->refcnt);
-	return 0;
-}
-
 static int nbd_ioctl(struct inode *inode, struct file *file,
 		     unsigned int cmd, unsigned long arg)
 {
@@ -555,6 +526,8 @@ static int nbd_ioctl(struct inode *inode
 	int error;
 	struct request sreq ;
 
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
 #ifdef PARANOIA
 	BUG_ON(lo->magic != LO_MAGIC);
 #endif
@@ -562,8 +535,6 @@ static int nbd_ioctl(struct inode *inode
 	dprintk(DBG_IOCTL, "%s: nbd_ioctl cmd=%s(0x%x) arg=%lu\n",
 			lo->disk->disk_name, ioctl_cmd_to_ascii(cmd), cmd, arg);
 
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
 	switch (cmd) {
 	case NBD_DISCONNECT:
 	        printk(KERN_INFO "%s: NBD_DISCONNECT\n", lo->disk->disk_name);
@@ -678,8 +649,6 @@ static int nbd_ioctl(struct inode *inode
 static struct block_device_operations nbd_fops =
 {
 	.owner =	THIS_MODULE,
-	.open =		nbd_open,
-	.release =	nbd_release,
 	.ioctl =	nbd_ioctl,
 };
 
@@ -730,7 +699,6 @@ static int __init nbd_init(void)
 	devfs_mk_dir("nbd");
 	for (i = 0; i < MAX_NBD; i++) {
 		struct gendisk *disk = nbd_dev[i].disk;
-		nbd_dev[i].refcnt = 0;
 		nbd_dev[i].file = NULL;
 #ifdef PARANOIA
 		nbd_dev[i].magic = LO_MAGIC;
--- linux-2.5.74-mm2/include/linux/nbd.h.PRISTINE	2003-07-06 16:49:36.710915872 -0400
+++ linux-2.5.74-mm2/include/linux/nbd.h	2003-07-06 16:49:52.826465936 -0400
@@ -36,7 +36,6 @@
 #define PARANOIA
 
 struct nbd_device {
-	int refcnt;	
 	int flags;
 	int harderror;		/* Code of hard error			*/
 #define NBD_READ_ONLY 0x0001

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

* [PATCH 2.5.74-mm2] nbd: make nbd and block layer agree about device and  block sizes
  2003-07-06 21:15 [PATCH 2.5.74-mm2] nbd: remove unneeded nbd_open/nbd_release and refcnt Paul Clements
@ 2003-07-06 21:20 ` Paul Clements
  2003-07-06 21:38   ` Jeff Garzik
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Clements @ 2003-07-06 21:20 UTC (permalink / raw)
  To: akpm, linux-kernel

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

Andrew,

here's the revised patch for block and device size changes, using
set_blocksize() as Jeff suggested

Thanks,
Paul

[-- Attachment #2: nbd-block_layer_compat-2.diff --]
[-- Type: text/x-diff, Size: 1124 bytes --]

--- linux-2.5.74-mm2/drivers/block/nbd.c.MINUS_OPEN_RELEASE	2003-07-06 16:55:22.224389840 -0400
+++ linux-2.5.74-mm2/drivers/block/nbd.c	2003-07-06 16:50:46.287338648 -0400
@@ -588,18 +588,22 @@ static int nbd_ioctl(struct inode *inode
 		}
 		return error;
 	case NBD_SET_BLKSIZE:
-		if ((arg & (arg-1)) || (arg < 512) || (arg > PAGE_SIZE))
-			return -EINVAL;
 		lo->blksize = arg;
-		lo->bytesize &= ~(lo->blksize-1); 
+		lo->bytesize &= ~(lo->blksize-1);
+		inode->i_bdev->bd_inode->i_size = lo->bytesize;
+		set_blocksize(inode->i_bdev, lo->blksize);
 		set_capacity(lo->disk, lo->bytesize >> 9);
 		return 0;
 	case NBD_SET_SIZE:
-		lo->bytesize = arg & ~(lo->blksize-1); 
+		lo->bytesize = arg & ~(lo->blksize-1);
+		inode->i_bdev->bd_inode->i_size = lo->bytesize;
+		set_blocksize(inode->i_bdev, lo->blksize);
 		set_capacity(lo->disk, lo->bytesize >> 9);
 		return 0;
 	case NBD_SET_SIZE_BLOCKS:
 		lo->bytesize = ((u64) arg) * lo->blksize;
+		inode->i_bdev->bd_inode->i_size = lo->bytesize;
+		set_blocksize(inode->i_bdev, lo->blksize);
 		set_capacity(lo->disk, lo->bytesize >> 9);
 		return 0;
 	case NBD_DO_IT:

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

* Re: [PATCH 2.5.74-mm2] nbd: make nbd and block layer agree about device and  block sizes
  2003-07-06 21:20 ` [PATCH 2.5.74-mm2] nbd: make nbd and block layer agree about device and block sizes Paul Clements
@ 2003-07-06 21:38   ` Jeff Garzik
  2003-07-06 21:55     ` Paul Clements
  2003-07-06 22:03     ` Andrew Morton
  0 siblings, 2 replies; 6+ messages in thread
From: Jeff Garzik @ 2003-07-06 21:38 UTC (permalink / raw)
  To: Paul Clements; +Cc: akpm, linux-kernel, viro

Paul Clements wrote:
>  	case NBD_SET_BLKSIZE:
> -		if ((arg & (arg-1)) || (arg < 512) || (arg > PAGE_SIZE))
> -			return -EINVAL;
>  		lo->blksize = arg;
> -		lo->bytesize &= ~(lo->blksize-1); 
> +		lo->bytesize &= ~(lo->blksize-1);
> +		inode->i_bdev->bd_inode->i_size = lo->bytesize;
> +		set_blocksize(inode->i_bdev, lo->blksize);
>  		set_capacity(lo->disk, lo->bytesize >> 9);
>  		return 0;
>  	case NBD_SET_SIZE:
> -		lo->bytesize = arg & ~(lo->blksize-1); 
> +		lo->bytesize = arg & ~(lo->blksize-1);
> +		inode->i_bdev->bd_inode->i_size = lo->bytesize;
> +		set_blocksize(inode->i_bdev, lo->blksize);
>  		set_capacity(lo->disk, lo->bytesize >> 9);
>  		return 0;
>  	case NBD_SET_SIZE_BLOCKS:
>  		lo->bytesize = ((u64) arg) * lo->blksize;
> +		inode->i_bdev->bd_inode->i_size = lo->bytesize;
> +		set_blocksize(inode->i_bdev, lo->blksize);
>  		set_capacity(lo->disk, lo->bytesize >> 9);
>  		return 0;
>  	case NBD_DO_IT:


Thanks.  You forgot to check set_blocksize's return value for errors, 
though.

Also, I wonder if you found a bug/oversight in set_blocksize -- it sets 
bd_inode->i_blkbits but not bd_inode->i_size.  I think it should set 
i_size also.  Maybe Andrew or Al can confirm/refute this assertion.

	Jeff




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

* Re: [PATCH 2.5.74-mm2] nbd: make nbd and block layer agree about device and  block sizes
  2003-07-06 21:38   ` Jeff Garzik
@ 2003-07-06 21:55     ` Paul Clements
  2003-07-06 22:02       ` Jeff Garzik
  2003-07-06 22:03     ` Andrew Morton
  1 sibling, 1 reply; 6+ messages in thread
From: Paul Clements @ 2003-07-06 21:55 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Paul Clements, akpm, linux-kernel, viro

On Sun, 6 Jul 2003, Jeff Garzik wrote:

> Paul Clements wrote:
> >  	case NBD_SET_BLKSIZE:
> > -		if ((arg & (arg-1)) || (arg < 512) || (arg > PAGE_SIZE))
> > -			return -EINVAL;
> >  		lo->blksize = arg;
> > -		lo->bytesize &= ~(lo->blksize-1); 
> > +		lo->bytesize &= ~(lo->blksize-1);
> > +		inode->i_bdev->bd_inode->i_size = lo->bytesize;
> > +		set_blocksize(inode->i_bdev, lo->blksize);
> >  		set_capacity(lo->disk, lo->bytesize >> 9);
> >  		return 0;
> >  	case NBD_SET_SIZE:
> > -		lo->bytesize = arg & ~(lo->blksize-1); 
> > +		lo->bytesize = arg & ~(lo->blksize-1);
> > +		inode->i_bdev->bd_inode->i_size = lo->bytesize;
> > +		set_blocksize(inode->i_bdev, lo->blksize);
> >  		set_capacity(lo->disk, lo->bytesize >> 9);
> >  		return 0;
> >  	case NBD_SET_SIZE_BLOCKS:
> >  		lo->bytesize = ((u64) arg) * lo->blksize;
> > +		inode->i_bdev->bd_inode->i_size = lo->bytesize;
> > +		set_blocksize(inode->i_bdev, lo->blksize);
> >  		set_capacity(lo->disk, lo->bytesize >> 9);
> >  		return 0;
> >  	case NBD_DO_IT:
> 
> 
> Thanks.  You forgot to check set_blocksize's return value for errors, 
> though.
> 
> Also, I wonder if you found a bug/oversight in set_blocksize -- it sets 
> bd_inode->i_blkbits but not bd_inode->i_size.  I think it should set 
> i_size also.  Maybe Andrew or Al can confirm/refute this assertion.

OK, I'll wait for a response on this, and then redo the patch as appropriate...

--
Paul


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

* Re: [PATCH 2.5.74-mm2] nbd: make nbd and block layer agree about device and  block sizes
  2003-07-06 21:55     ` Paul Clements
@ 2003-07-06 22:02       ` Jeff Garzik
  0 siblings, 0 replies; 6+ messages in thread
From: Jeff Garzik @ 2003-07-06 22:02 UTC (permalink / raw)
  To: Paul.Clements; +Cc: akpm, linux-kernel, viro

Paul Clements wrote:
> On Sun, 6 Jul 2003, Jeff Garzik wrote:
>>Also, I wonder if you found a bug/oversight in set_blocksize -- it sets 
>>bd_inode->i_blkbits but not bd_inode->i_size.  I think it should set 
>>i_size also.  Maybe Andrew or Al can confirm/refute this assertion.
> 
> 
> OK, I'll wait for a response on this, and then redo the patch as appropriate...


No, nevermind.  What I was said dumb ;-)

The inode's size should not be the block size.

	Jeff




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

* Re: [PATCH 2.5.74-mm2] nbd: make nbd and block layer agree about device and  block sizes
  2003-07-06 21:38   ` Jeff Garzik
  2003-07-06 21:55     ` Paul Clements
@ 2003-07-06 22:03     ` Andrew Morton
  1 sibling, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2003-07-06 22:03 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Paul.Clements, akpm, linux-kernel, viro

Jeff Garzik <jgarzik@pobox.com> wrote:
>
> Also, I wonder if you found a bug/oversight in set_blocksize -- it sets 
>  bd_inode->i_blkbits but not bd_inode->i_size.  I think it should set 
>  i_size also.  Maybe Andrew or Al can confirm/refute this assertion.

set_blocksize() sets, err, the blocksize.

Lou was wanting to export bd_set_size() for setting i_size.  But
bd_set_size() goes and tries to set the blocksize too.

So the patch as-is will do I think, unless someone feels there's a need to
go and rework these things.


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

end of thread, other threads:[~2003-07-06 21:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-07-06 21:15 [PATCH 2.5.74-mm2] nbd: remove unneeded nbd_open/nbd_release and refcnt Paul Clements
2003-07-06 21:20 ` [PATCH 2.5.74-mm2] nbd: make nbd and block layer agree about device and block sizes Paul Clements
2003-07-06 21:38   ` Jeff Garzik
2003-07-06 21:55     ` Paul Clements
2003-07-06 22:02       ` Jeff Garzik
2003-07-06 22:03     ` Andrew Morton

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