Message ID | 20230704122224.16257-3-jack@suse.cz (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | block: Make blkdev_get_by_*() return handle | expand |
On Tue, Jul 04, 2023 at 02:21:30PM +0200, Jan Kara wrote: >Convert blkdev_open() to use blkdev_get_handle_by_dev(). > >Signed-off-by: Jan Kara <jack@suse.cz> >--- > block/fops.c | 17 +++++++++-------- > 1 file changed, 9 insertions(+), 8 deletions(-) > >diff --git a/block/fops.c b/block/fops.c >index b6aa470c09ae..d7f3b6e67a2f 100644 >--- a/block/fops.c >+++ b/block/fops.c >@@ -496,7 +496,7 @@ blk_mode_t file_to_blk_mode(struct file *file) > > static int blkdev_open(struct inode *inode, struct file *filp) > { >- struct block_device *bdev; >+ struct bdev_handle *handle; > blk_mode_t mode; > > /* >@@ -509,24 +509,25 @@ static int blkdev_open(struct inode *inode, struct file *filp) > filp->f_mode |= FMODE_BUF_RASYNC; > > mode = file_to_blk_mode(filp); >- bdev = blkdev_get_by_dev(inode->i_rdev, mode, >- mode & BLK_OPEN_EXCL ? filp : NULL, NULL); >- if (IS_ERR(bdev)) >- return PTR_ERR(bdev); >+ handle = blkdev_get_handle_by_dev(inode->i_rdev, mode, >+ mode & BLK_OPEN_EXCL ? filp : NULL, NULL); >+ if (IS_ERR(handle)) >+ return PTR_ERR(handle); > > if (mode & BLK_OPEN_EXCL) > filp->private_data = filp; Is this needed? This is getting overwritten after a couple of lines below. >- if (bdev_nowait(bdev)) >+ if (bdev_nowait(handle->bdev)) > filp->f_mode |= FMODE_NOWAIT; > >- filp->f_mapping = bdev->bd_inode->i_mapping; >+ filp->f_mapping = handle->bdev->bd_inode->i_mapping; > filp->f_wb_err = filemap_sample_wb_err(filp->f_mapping); >+ filp->private_data = handle; Here.
On Wed 05-07-23 10:35:10, Kanchan Joshi wrote: > On Tue, Jul 04, 2023 at 02:21:30PM +0200, Jan Kara wrote: > > Convert blkdev_open() to use blkdev_get_handle_by_dev(). > > > > Signed-off-by: Jan Kara <jack@suse.cz> > > --- > > block/fops.c | 17 +++++++++-------- > > 1 file changed, 9 insertions(+), 8 deletions(-) > > > > diff --git a/block/fops.c b/block/fops.c > > index b6aa470c09ae..d7f3b6e67a2f 100644 > > --- a/block/fops.c > > +++ b/block/fops.c > > @@ -496,7 +496,7 @@ blk_mode_t file_to_blk_mode(struct file *file) > > > > static int blkdev_open(struct inode *inode, struct file *filp) > > { > > - struct block_device *bdev; > > + struct bdev_handle *handle; > > blk_mode_t mode; > > > > /* > > @@ -509,24 +509,25 @@ static int blkdev_open(struct inode *inode, struct file *filp) > > filp->f_mode |= FMODE_BUF_RASYNC; > > > > mode = file_to_blk_mode(filp); > > - bdev = blkdev_get_by_dev(inode->i_rdev, mode, > > - mode & BLK_OPEN_EXCL ? filp : NULL, NULL); > > - if (IS_ERR(bdev)) > > - return PTR_ERR(bdev); > > + handle = blkdev_get_handle_by_dev(inode->i_rdev, mode, > > + mode & BLK_OPEN_EXCL ? filp : NULL, NULL); > > + if (IS_ERR(handle)) > > + return PTR_ERR(handle); > > > > if (mode & BLK_OPEN_EXCL) > > filp->private_data = filp; > > Is this needed? > This is getting overwritten after a couple of lines below. > > > - if (bdev_nowait(bdev)) > > + if (bdev_nowait(handle->bdev)) > > filp->f_mode |= FMODE_NOWAIT; > > > > - filp->f_mapping = bdev->bd_inode->i_mapping; > > + filp->f_mapping = handle->bdev->bd_inode->i_mapping; > > filp->f_wb_err = filemap_sample_wb_err(filp->f_mapping); > > + filp->private_data = handle; > > Here. Good point, I'll fix that for the next version. Thanks for review! Honza
diff --git a/block/fops.c b/block/fops.c index b6aa470c09ae..d7f3b6e67a2f 100644 --- a/block/fops.c +++ b/block/fops.c @@ -496,7 +496,7 @@ blk_mode_t file_to_blk_mode(struct file *file) static int blkdev_open(struct inode *inode, struct file *filp) { - struct block_device *bdev; + struct bdev_handle *handle; blk_mode_t mode; /* @@ -509,24 +509,25 @@ static int blkdev_open(struct inode *inode, struct file *filp) filp->f_mode |= FMODE_BUF_RASYNC; mode = file_to_blk_mode(filp); - bdev = blkdev_get_by_dev(inode->i_rdev, mode, - mode & BLK_OPEN_EXCL ? filp : NULL, NULL); - if (IS_ERR(bdev)) - return PTR_ERR(bdev); + handle = blkdev_get_handle_by_dev(inode->i_rdev, mode, + mode & BLK_OPEN_EXCL ? filp : NULL, NULL); + if (IS_ERR(handle)) + return PTR_ERR(handle); if (mode & BLK_OPEN_EXCL) filp->private_data = filp; - if (bdev_nowait(bdev)) + if (bdev_nowait(handle->bdev)) filp->f_mode |= FMODE_NOWAIT; - filp->f_mapping = bdev->bd_inode->i_mapping; + filp->f_mapping = handle->bdev->bd_inode->i_mapping; filp->f_wb_err = filemap_sample_wb_err(filp->f_mapping); + filp->private_data = handle; return 0; } static int blkdev_release(struct inode *inode, struct file *filp) { - blkdev_put(I_BDEV(filp->f_mapping->host), filp->private_data); + blkdev_handle_put(filp->private_data); return 0; }
Convert blkdev_open() to use blkdev_get_handle_by_dev(). Signed-off-by: Jan Kara <jack@suse.cz> --- block/fops.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)