Message ID | 20230606073950.225178-31-hch@lst.de |
---|---|
State | New |
Headers | show |
Series | [01/31] block: also call ->open for incremental partition opens | expand |
On Wed, Jun 07, 2023 at 11:24:55AM +0200, Christian Brauner wrote: > On Tue, Jun 06, 2023 at 09:39:49AM +0200, Christoph Hellwig wrote: > > Store the file struct used as the holder in file->private_data as an > > indicator that this file descriptor was opened exclusively to remove > > the last use of FMODE_EXCL. > > > > Signed-off-by: Christoph Hellwig <hch@lst.de> > > --- > > Feels a bit odd to store the object itself but anyway, > Acked-by: Christian Brauner <brauner@kernel.org> We could literally store anything we want. The only reason I picked the file is because: a) we have it around and b) that allows passing it to blkdev_put without a branch in blkdev_release. If you prefer something else I can change it.
On 6/6/23 09:39, Christoph Hellwig wrote: > Store the file struct used as the holder in file->private_data as an > indicator that this file descriptor was opened exclusively to remove > the last use of FMODE_EXCL. > > Signed-off-by: Christoph Hellwig <hch@lst.de> > --- > block/fops.c | 14 ++++++++------ > 1 file changed, 8 insertions(+), 6 deletions(-) > > diff --git a/block/fops.c b/block/fops.c > index c40b9f978e3bc7..915e0ef7560993 100644 > --- a/block/fops.c > +++ b/block/fops.c > @@ -478,7 +478,7 @@ blk_mode_t file_to_blk_mode(struct file *file) > mode |= BLK_OPEN_READ; > if (file->f_mode & FMODE_WRITE) > mode |= BLK_OPEN_WRITE; > - if (file->f_mode & FMODE_EXCL) > + if (file->private_data) > mode |= BLK_OPEN_EXCL; > if ((file->f_flags & O_ACCMODE) == 3) > mode |= BLK_OPEN_WRITE_IOCTL; > @@ -501,12 +501,15 @@ static int blkdev_open(struct inode *inode, struct file *filp) > filp->f_flags |= O_LARGEFILE; > filp->f_mode |= FMODE_NOWAIT | FMODE_BUF_RASYNC; > > + /* > + * Use the file private data to store the holder, file_to_blk_mode > + * relies on this. > + */ Can you update the comment to reflect that we're only use the ->private_data field for exclusive open? I know it's indicated by the condition, but we really should be clarify this usage. > if (filp->f_flags & O_EXCL) > - filp->f_mode |= FMODE_EXCL; > + filp->private_data = filp; > > bdev = blkdev_get_by_dev(inode->i_rdev, file_to_blk_mode(filp), > - (filp->f_mode & FMODE_EXCL) ? filp : NULL, > - NULL); > + filp->private_data, NULL); > if (IS_ERR(bdev)) > return PTR_ERR(bdev); > > @@ -517,8 +520,7 @@ static int blkdev_open(struct inode *inode, struct file *filp) > > static int blkdev_release(struct inode *inode, struct file *filp) > { > - blkdev_put(I_BDEV(filp->f_mapping->host), > - (filp->f_mode & FMODE_EXCL) ? filp : NULL); > + blkdev_put(I_BDEV(filp->f_mapping->host), filp->private_data); > return 0; > } > Other than that: Reviewed-by: Hannes Reinecke <hare@suse.de> Cheers, Hannes
diff --git a/block/fops.c b/block/fops.c index c40b9f978e3bc7..915e0ef7560993 100644 --- a/block/fops.c +++ b/block/fops.c @@ -478,7 +478,7 @@ blk_mode_t file_to_blk_mode(struct file *file) mode |= BLK_OPEN_READ; if (file->f_mode & FMODE_WRITE) mode |= BLK_OPEN_WRITE; - if (file->f_mode & FMODE_EXCL) + if (file->private_data) mode |= BLK_OPEN_EXCL; if ((file->f_flags & O_ACCMODE) == 3) mode |= BLK_OPEN_WRITE_IOCTL; @@ -501,12 +501,15 @@ static int blkdev_open(struct inode *inode, struct file *filp) filp->f_flags |= O_LARGEFILE; filp->f_mode |= FMODE_NOWAIT | FMODE_BUF_RASYNC; + /* + * Use the file private data to store the holder, file_to_blk_mode + * relies on this. + */ if (filp->f_flags & O_EXCL) - filp->f_mode |= FMODE_EXCL; + filp->private_data = filp; bdev = blkdev_get_by_dev(inode->i_rdev, file_to_blk_mode(filp), - (filp->f_mode & FMODE_EXCL) ? filp : NULL, - NULL); + filp->private_data, NULL); if (IS_ERR(bdev)) return PTR_ERR(bdev); @@ -517,8 +520,7 @@ static int blkdev_open(struct inode *inode, struct file *filp) static int blkdev_release(struct inode *inode, struct file *filp) { - blkdev_put(I_BDEV(filp->f_mapping->host), - (filp->f_mode & FMODE_EXCL) ? filp : NULL); + blkdev_put(I_BDEV(filp->f_mapping->host), filp->private_data); return 0; }
Store the file struct used as the holder in file->private_data as an indicator that this file descriptor was opened exclusively to remove the last use of FMODE_EXCL. Signed-off-by: Christoph Hellwig <hch@lst.de> --- block/fops.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)