* [PATCH v2 0/29] block: Make blkdev_get_by_*() return handle
@ 2023-08-11 11:04 Jan Kara
2023-08-11 11:04 ` [PATCH 27/29] reiserfs: Convert to bdev_open_by_dev/path() Jan Kara
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Jan Kara @ 2023-08-11 11:04 UTC (permalink / raw)
To: linux-fsdevel-u79uwXL29TY76Z2rM5mHXA
Cc: Dave Kleikamp, jfs-discussion-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
Jan Kara, Darrick J. Wong,
linux-nvme-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Joseph Qi,
dm-devel-H+wXaHxf7aLQT0dZR+AlfA,
target-devel-u79uwXL29TY76Z2rM5mHXA,
linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Jack Wang,
Alasdair Kergon, drbd-dev-cunTk1MwBs8qoQakbn7OcQ,
linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-nilfs-u79uwXL29TY76Z2rM5mHXA,
linux-scsi-u79uwXL29TY76Z2rM5mHXA, Sergey Senozhatsky,
Christoph Hellwig, xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b,
Gao Xiang, Christian Borntraeger, Kent Overstreet, Sven Schnelle,
linux-pm-u79uwXL29TY76Z2rM5mHXA, Mike Snitzer, Chao Yu,
Joern Engel, re
Hello,
this is a v2 of the patch series which implements the idea of blkdev_get_by_*()
calls returning bdev_handle which is then passed to blkdev_put() [1]. This
makes the get and put calls for bdevs more obviously matching and allows us to
propagate context from get to put without having to modify all the users
(again!). In particular I need to propagate used open flags to blkdev_put() to
be able count writeable opens and add support for blocking writes to mounted
block devices. I'll send that series separately.
The series is based on Christian's vfs tree as of yesterday as there is quite
some overlap. Patches have passed some reasonable testing - I've tested block
changes, md, dm, bcache, xfs, btrfs, ext4, swap. This obviously doesn't cover
everything so I'd like to ask respective maintainers to review / test their
changes. Thanks! I've pushed out the full branch to:
git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git bdev_handle
to ease review / testing.
Changes since v1:
* Rebased on top of current vfs tree
* Renamed final functions to bdev_open_by_*() and bdev_release()
* Fixed detection of exclusive open in blkdev_ioctl() and blkdev_fallocate()
* Fixed swap conversion to properly reinitialize swap_info->bdev_handle
* Fixed xfs conversion to not oops with rtdev without logdev
* Couple other minor fixups
Honza
[1] https://lore.kernel.org/all/ZJGNsVDhZx0Xgs2H-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org
CC: Alasdair Kergon <agk-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
CC: Andrew Morton <akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
CC: Anna Schumaker <anna-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
CC: Chao Yu <chao-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
CC: Christian Borntraeger <borntraeger-tEXmvtCZX7AybS5Ee8rs3A@public.gmane.org>
CC: Coly Li <colyli-l3A5Bk7waGM@public.gmane.org
CC: "Darrick J. Wong" <djwong-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
CC: Dave Kleikamp <shaggy-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
CC: David Sterba <dsterba-IBi9RG/b67k@public.gmane.org>
CC: dm-devel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
CC: drbd-dev-cunTk1MwBs8qoQakbn7OcQ@public.gmane.org
CC: Gao Xiang <xiang-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
CC: Jack Wang <jinpu.wang-vEVw2sk9H7kAvxtiuMwx3w@public.gmane.org>
CC: Jaegeuk Kim <jaegeuk-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
CC: jfs-discussion-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
CC: Joern Engel <joern-o6zPIXG8fmPj4SYmN/TMmA@public.gmane.org>
CC: Joseph Qi <joseph.qi-KPsoFbNs7GizrGE5bRqYAgC/G2K4zDHf@public.gmane.org>
CC: Kent Overstreet <kent.overstreet-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
CC: linux-bcache-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
CC: linux-btrfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
CC: linux-erofs-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
CC: <linux-ext4-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
CC: linux-f2fs-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
CC: linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org
CC: linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
CC: linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
CC: linux-nilfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
CC: linux-nvme-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
CC: linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
CC: linux-raid-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
CC: linux-s390-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
CC: linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
CC: linux-xfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
CC: "Md. Haris Iqbal" <haris.iqbal-vEVw2sk9H7kAvxtiuMwx3w@public.gmane.org>
CC: Mike Snitzer <snitzer-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
CC: Minchan Kim <minchan-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
CC: ocfs2-devel-N0ozoZBvEnrZJqsBc5GL+g@public.gmane.org
CC: reiserfs-devel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
CC: Sergey Senozhatsky <senozhatsky-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
CC: Song Liu <song-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
CC: Sven Schnelle <svens-tEXmvtCZX7AybS5Ee8rs3A@public.gmane.org>
CC: target-devel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
CC: Ted Tso <tytso-3s7WtUTddSA@public.gmane.org>
CC: Trond Myklebust <trond.myklebust-F/q8l9xzQnoyLce1RVWEUA@public.gmane.org>
CC: xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b@public.gmane.org
Previous versions:
Link: http://lore.kernel.org/r/20230629165206.383-1-jack-AlSwsSmVLrQ@public.gmane.org # v1
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 27/29] reiserfs: Convert to bdev_open_by_dev/path() 2023-08-11 11:04 [PATCH v2 0/29] block: Make blkdev_get_by_*() return handle Jan Kara @ 2023-08-11 11:04 ` Jan Kara 2023-08-11 12:27 ` [PATCH v2 0/29] block: Make blkdev_get_by_*() return handle Christoph Hellwig 2023-08-25 1:58 ` Al Viro 2 siblings, 0 replies; 9+ messages in thread From: Jan Kara @ 2023-08-11 11:04 UTC (permalink / raw) To: linux-fsdevel; +Cc: linux-block, Christoph Hellwig, Jan Kara, reiserfs-devel Convert reiserfs to use bdev_open_by_dev/path() and pass the handle around. CC: reiserfs-devel@vger.kernel.org Signed-off-by: Jan Kara <jack@suse.cz> --- fs/reiserfs/journal.c | 56 +++++++++++++++++++----------------------- fs/reiserfs/procfs.c | 2 +- fs/reiserfs/reiserfs.h | 11 ++++++--- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c index 015bfe4e4524..171c912af50f 100644 --- a/fs/reiserfs/journal.c +++ b/fs/reiserfs/journal.c @@ -90,8 +90,7 @@ static int flush_commit_list(struct super_block *s, static int can_dirty(struct reiserfs_journal_cnode *cn); static int journal_join(struct reiserfs_transaction_handle *th, struct super_block *sb); -static void release_journal_dev(struct super_block *super, - struct reiserfs_journal *journal); +static void release_journal_dev(struct reiserfs_journal *journal); static void dirty_one_transaction(struct super_block *s, struct reiserfs_journal_list *jl); static void flush_async_commits(struct work_struct *work); @@ -1893,7 +1892,7 @@ static void free_journal_ram(struct super_block *sb) * j_header_bh is on the journal dev, make sure * not to release the journal dev until we brelse j_header_bh */ - release_journal_dev(sb, journal); + release_journal_dev(journal); vfree(journal); } @@ -2387,7 +2386,7 @@ static int journal_read(struct super_block *sb) cur_dblock = SB_ONDISK_JOURNAL_1st_BLOCK(sb); reiserfs_info(sb, "checking transaction log (%pg)\n", - journal->j_dev_bd); + journal->j_bdev_handle->bdev); start = ktime_get_seconds(); /* @@ -2448,7 +2447,7 @@ static int journal_read(struct super_block *sb) * device and journal device to be the same */ d_bh = - reiserfs_breada(journal->j_dev_bd, cur_dblock, + reiserfs_breada(journal->j_bdev_handle->bdev, cur_dblock, sb->s_blocksize, SB_ONDISK_JOURNAL_1st_BLOCK(sb) + SB_ONDISK_JOURNAL_SIZE(sb)); @@ -2587,17 +2586,11 @@ static void journal_list_init(struct super_block *sb) SB_JOURNAL(sb)->j_current_jl = alloc_journal_list(sb); } -static void release_journal_dev(struct super_block *super, - struct reiserfs_journal *journal) +static void release_journal_dev(struct reiserfs_journal *journal) { - if (journal->j_dev_bd != NULL) { - void *holder = NULL; - - if (journal->j_dev_bd->bd_dev != super->s_dev) - holder = journal; - - blkdev_put(journal->j_dev_bd, holder); - journal->j_dev_bd = NULL; + if (journal->j_bdev_handle) { + bdev_release(journal->j_bdev_handle); + journal->j_bdev_handle = NULL; } } @@ -2612,7 +2605,7 @@ static int journal_init_dev(struct super_block *super, result = 0; - journal->j_dev_bd = NULL; + journal->j_bdev_handle = NULL; jdev = SB_ONDISK_JOURNAL_DEVICE(super) ? new_decode_dev(SB_ONDISK_JOURNAL_DEVICE(super)) : super->s_dev; @@ -2623,36 +2616,37 @@ static int journal_init_dev(struct super_block *super, if ((!jdev_name || !jdev_name[0])) { if (jdev == super->s_dev) holder = NULL; - journal->j_dev_bd = blkdev_get_by_dev(jdev, blkdev_mode, holder, - NULL); - if (IS_ERR(journal->j_dev_bd)) { - result = PTR_ERR(journal->j_dev_bd); - journal->j_dev_bd = NULL; + journal->j_bdev_handle = bdev_open_by_dev(jdev, blkdev_mode, + holder, NULL); + if (IS_ERR(journal->j_bdev_handle)) { + result = PTR_ERR(journal->j_bdev_handle); + journal->j_bdev_handle = NULL; reiserfs_warning(super, "sh-458", "cannot init journal device unknown-block(%u,%u): %i", MAJOR(jdev), MINOR(jdev), result); return result; } else if (jdev != super->s_dev) - set_blocksize(journal->j_dev_bd, super->s_blocksize); + set_blocksize(journal->j_bdev_handle->bdev, + super->s_blocksize); return 0; } - journal->j_dev_bd = blkdev_get_by_path(jdev_name, blkdev_mode, holder, - NULL); - if (IS_ERR(journal->j_dev_bd)) { - result = PTR_ERR(journal->j_dev_bd); - journal->j_dev_bd = NULL; + journal->j_bdev_handle = bdev_open_by_path(jdev_name, blkdev_mode, + holder, NULL); + if (IS_ERR(journal->j_bdev_handle)) { + result = PTR_ERR(journal->j_bdev_handle); + journal->j_bdev_handle = NULL; reiserfs_warning(super, "sh-457", "journal_init_dev: Cannot open '%s': %i", jdev_name, result); return result; } - set_blocksize(journal->j_dev_bd, super->s_blocksize); + set_blocksize(journal->j_bdev_handle->bdev, super->s_blocksize); reiserfs_info(super, "journal_init_dev: journal device: %pg\n", - journal->j_dev_bd); + journal->j_bdev_handle->bdev); return 0; } @@ -2810,7 +2804,7 @@ int journal_init(struct super_block *sb, const char *j_dev_name, "journal header magic %x (device %pg) does " "not match to magic found in super block %x", jh->jh_journal.jp_journal_magic, - journal->j_dev_bd, + journal->j_bdev_handle->bdev, sb_jp_journal_magic(rs)); brelse(bhjh); goto free_and_return; @@ -2834,7 +2828,7 @@ int journal_init(struct super_block *sb, const char *j_dev_name, reiserfs_info(sb, "journal params: device %pg, size %u, " "journal first block %u, max trans len %u, max batch %u, " "max commit age %u, max trans age %u\n", - journal->j_dev_bd, + journal->j_bdev_handle->bdev, SB_ONDISK_JOURNAL_SIZE(sb), SB_ONDISK_JOURNAL_1st_BLOCK(sb), journal->j_trans_max, diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c index 3dba8acf4e83..83cb9402e0f9 100644 --- a/fs/reiserfs/procfs.c +++ b/fs/reiserfs/procfs.c @@ -354,7 +354,7 @@ static int show_journal(struct seq_file *m, void *unused) "prepare: \t%12lu\n" "prepare_retry: \t%12lu\n", DJP(jp_journal_1st_block), - SB_JOURNAL(sb)->j_dev_bd, + SB_JOURNAL(sb)->j_bdev_handle->bdev, DJP(jp_journal_dev), DJP(jp_journal_size), DJP(jp_journal_trans_max), diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h index 55e85256aae8..8e426392b5c2 100644 --- a/fs/reiserfs/reiserfs.h +++ b/fs/reiserfs/reiserfs.h @@ -299,7 +299,7 @@ struct reiserfs_journal { /* oldest journal block. start here for traverse */ struct reiserfs_journal_cnode *j_first; - struct block_device *j_dev_bd; + struct bdev_handle *j_bdev_handle; /* first block on s_dev of reserved area journal */ int j_1st_reserved_block; @@ -2809,9 +2809,12 @@ struct reiserfs_journal_header { #define journal_hash(t,sb,block) ((t)[_jhashfn((sb),(block)) & JBH_HASH_MASK]) /* We need these to make journal.c code more readable */ -#define journal_find_get_block(s, block) __find_get_block(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize) -#define journal_getblk(s, block) __getblk(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize) -#define journal_bread(s, block) __bread(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize) +#define journal_find_get_block(s, block) __find_get_block(\ + SB_JOURNAL(s)->j_bdev_handle->bdev, block, s->s_blocksize) +#define journal_getblk(s, block) __getblk(SB_JOURNAL(s)->j_bdev_handle->bdev,\ + block, s->s_blocksize) +#define journal_bread(s, block) __bread(SB_JOURNAL(s)->j_bdev_handle->bdev,\ + block, s->s_blocksize) enum reiserfs_bh_state_bits { BH_JDirty = BH_PrivateStart, /* buffer is in current transaction */ -- 2.35.3 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/29] block: Make blkdev_get_by_*() return handle 2023-08-11 11:04 [PATCH v2 0/29] block: Make blkdev_get_by_*() return handle Jan Kara 2023-08-11 11:04 ` [PATCH 27/29] reiserfs: Convert to bdev_open_by_dev/path() Jan Kara @ 2023-08-11 12:27 ` Christoph Hellwig 2023-08-25 1:58 ` Al Viro 2 siblings, 0 replies; 9+ messages in thread From: Christoph Hellwig @ 2023-08-11 12:27 UTC (permalink / raw) To: Jan Kara Cc: linux-fsdevel, linux-block, Christoph Hellwig, Alasdair Kergon, Andrew Morton, Anna Schumaker, Chao Yu, Christian Borntraeger, Darrick J. Wong, Dave Kleikamp, David Sterba, dm-devel, drbd-dev, Gao Xiang, Jack Wang, Jaegeuk Kim, jfs-discussion, Joern Engel, Joseph Qi, Kent Overstreet, linux-bcache, linux-btrfs Except for a mostly cosmetic nitpick this looks good to me: Acked-by: Christoph Hellwig <hch@lst.de> That's not eactly the deep review I'd like to do, but as I'm about to head out for vacation that's probably as good as it gets. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/29] block: Make blkdev_get_by_*() return handle 2023-08-11 11:04 [PATCH v2 0/29] block: Make blkdev_get_by_*() return handle Jan Kara 2023-08-11 11:04 ` [PATCH 27/29] reiserfs: Convert to bdev_open_by_dev/path() Jan Kara 2023-08-11 12:27 ` [PATCH v2 0/29] block: Make blkdev_get_by_*() return handle Christoph Hellwig @ 2023-08-25 1:58 ` Al Viro 2023-08-25 13:47 ` Jan Kara 2 siblings, 1 reply; 9+ messages in thread From: Al Viro @ 2023-08-25 1:58 UTC (permalink / raw) To: Jan Kara Cc: linux-fsdevel, linux-block, Christoph Hellwig, Alasdair Kergon, Andrew Morton, Anna Schumaker, Chao Yu, Christian Borntraeger, Darrick J. Wong, Dave Kleikamp, David Sterba, dm-devel, drbd-dev, Gao Xiang, Jack Wang, Jaegeuk Kim, jfs-discussion, Joern Engel, Joseph Qi, Kent Overstreet, linux-bcache, linux-btrfs On Fri, Aug 11, 2023 at 01:04:31PM +0200, Jan Kara wrote: > Hello, > > this is a v2 of the patch series which implements the idea of blkdev_get_by_*() > calls returning bdev_handle which is then passed to blkdev_put() [1]. This > makes the get and put calls for bdevs more obviously matching and allows us to > propagate context from get to put without having to modify all the users > (again!). In particular I need to propagate used open flags to blkdev_put() to > be able count writeable opens and add support for blocking writes to mounted > block devices. I'll send that series separately. > > The series is based on Christian's vfs tree as of yesterday as there is quite > some overlap. Patches have passed some reasonable testing - I've tested block > changes, md, dm, bcache, xfs, btrfs, ext4, swap. This obviously doesn't cover > everything so I'd like to ask respective maintainers to review / test their > changes. Thanks! I've pushed out the full branch to: > > git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git bdev_handle > > to ease review / testing. Hmm... Completely Insane Idea(tm): how about turning that thing inside out and having your bdev_open_by... return an actual opened struct file? After all, we do that for sockets and pipes just fine and that's a whole lot hotter area. Suppose we leave blkdev_open()/blkdev_release() as-is. No need to mess with what we have for normal opened files for block devices. And have block_open_by_dev() that would find bdev, etc., same yours does and shove it into anon file. Paired with plain fput() - no need to bother with new primitives for closing. With a helper returning I_BDEV(bdev_file_inode(file)) to get from those to bdev. NOTE: I'm not suggesting replacing ->s_bdev with struct file * if we do that - we want that value cached, obviously. Just store both... Not saying it's a good idea, but... might be interesting to look into. Comments? ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/29] block: Make blkdev_get_by_*() return handle 2023-08-25 1:58 ` Al Viro @ 2023-08-25 13:47 ` Jan Kara 2023-08-26 2:28 ` Al Viro ` (2 more replies) 0 siblings, 3 replies; 9+ messages in thread From: Jan Kara @ 2023-08-25 13:47 UTC (permalink / raw) To: Al Viro Cc: Dave Kleikamp, jfs-discussion-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Jan Kara, Darrick J. Wong, linux-nvme-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Joseph Qi, dm-devel-H+wXaHxf7aLQT0dZR+AlfA, target-devel-u79uwXL29TY76Z2rM5mHXA, linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Jack Wang, Alasdair Kergon, drbd-dev-cunTk1MwBs8qoQakbn7OcQ, linux-s390-u79uwXL29TY76Z2rM5mHXA, linux-nilfs-u79uwXL29TY76Z2rM5mHXA, linux-scsi-u79uwXL29TY76Z2rM5mHXA, Sergey Senozhatsky, Christoph Hellwig, xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b, Gao Xiang, Christian Borntraeger, Kent Overstreet, Sven Schnelle, linux-pm-u79uwXL29TY76Z2rM5mHXA, Mike Snitzer, Chao Yu, Joern Engel, re On Fri 25-08-23 02:58:43, Al Viro wrote: > On Fri, Aug 11, 2023 at 01:04:31PM +0200, Jan Kara wrote: > > Hello, > > > > this is a v2 of the patch series which implements the idea of blkdev_get_by_*() > > calls returning bdev_handle which is then passed to blkdev_put() [1]. This > > makes the get and put calls for bdevs more obviously matching and allows us to > > propagate context from get to put without having to modify all the users > > (again!). In particular I need to propagate used open flags to blkdev_put() to > > be able count writeable opens and add support for blocking writes to mounted > > block devices. I'll send that series separately. > > > > The series is based on Christian's vfs tree as of yesterday as there is quite > > some overlap. Patches have passed some reasonable testing - I've tested block > > changes, md, dm, bcache, xfs, btrfs, ext4, swap. This obviously doesn't cover > > everything so I'd like to ask respective maintainers to review / test their > > changes. Thanks! I've pushed out the full branch to: > > > > git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git bdev_handle > > > > to ease review / testing. > > Hmm... Completely Insane Idea(tm): how about turning that thing inside out and > having your bdev_open_by... return an actual opened struct file? > > After all, we do that for sockets and pipes just fine and that's a whole lot > hotter area. > > Suppose we leave blkdev_open()/blkdev_release() as-is. No need to mess with > what we have for normal opened files for block devices. And have block_open_by_dev() > that would find bdev, etc., same yours does and shove it into anon file. > > Paired with plain fput() - no need to bother with new primitives for closing. > With a helper returning I_BDEV(bdev_file_inode(file)) to get from those to bdev. > > NOTE: I'm not suggesting replacing ->s_bdev with struct file * if we do that - > we want that value cached, obviously. Just store both... > > Not saying it's a good idea, but... might be interesting to look into. > Comments? I can see the appeal of not having to introduce the new bdev_handle type and just using struct file which unifies in-kernel and userspace block device opens. But I can see downsides too - the last fput() happening from task work makes me a bit nervous whether it will not break something somewhere with exclusive bdev opens. Getting from struct file to bdev is somewhat harder but I guess a helper like F_BDEV() would solve that just fine. So besides my last fput() worry about I think this could work and would be probably a bit nicer than what I have. But before going and redoing the whole series let me gather some more feedback so that we don't go back and forth. Christoph, Christian, Jens, any opinion? Honza -- Jan Kara <jack-IBi9RG/b67k@public.gmane.org> SUSE Labs, CR ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/29] block: Make blkdev_get_by_*() return handle 2023-08-25 13:47 ` Jan Kara @ 2023-08-26 2:28 ` Al Viro 2023-08-28 14:27 ` Christoph Hellwig 2023-08-28 13:20 ` Christian Brauner 2023-08-28 14:22 ` Christoph Hellwig 2 siblings, 1 reply; 9+ messages in thread From: Al Viro @ 2023-08-26 2:28 UTC (permalink / raw) To: Jan Kara Cc: Dave Kleikamp, jfs-discussion-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Darrick J. Wong, linux-nvme-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Joseph Qi, dm-devel-H+wXaHxf7aLQT0dZR+AlfA, target-devel-u79uwXL29TY76Z2rM5mHXA, linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Jack Wang, Alasdair Kergon, drbd-dev-cunTk1MwBs8qoQakbn7OcQ, linux-s390-u79uwXL29TY76Z2rM5mHXA, linux-nilfs-u79uwXL29TY76Z2rM5mHXA, linux-scsi-u79uwXL29TY76Z2rM5mHXA, Sergey Senozhatsky, Christoph Hellwig, xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b, Gao Xiang, Christian Borntraeger, Kent Overstreet, Sven Schnelle, linux-pm-u79uwXL29TY76Z2rM5mHXA, Mike Snitzer, Chao Yu, Joern Engel, reiserfs-devel-u79uwXL29TbrhsbdSgBK9A On Fri, Aug 25, 2023 at 03:47:56PM +0200, Jan Kara wrote: > I can see the appeal of not having to introduce the new bdev_handle type > and just using struct file which unifies in-kernel and userspace block > device opens. But I can see downsides too - the last fput() happening from > task work makes me a bit nervous whether it will not break something > somewhere with exclusive bdev opens. Getting from struct file to bdev is > somewhat harder but I guess a helper like F_BDEV() would solve that just > fine. > > So besides my last fput() worry about I think this could work and would be > probably a bit nicer than what I have. But before going and redoing the whole > series let me gather some more feedback so that we don't go back and forth. > Christoph, Christian, Jens, any opinion? Redoing is not an issue - it can be done on top of your series just as well. Async behaviour of fput() might be, but... need to look through the actual users; for a lot of them it's perfectly fine. FWIW, from a cursory look there appears to be a missing primitive: take an opened bdev (or bdev_handle, with your variant, or opened file if we go that way eventually) and claim it. I mean, look at claim_swapfile() for example: p->bdev = blkdev_get_by_dev(inode->i_rdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL, p); if (IS_ERR(p->bdev)) { error = PTR_ERR(p->bdev); p->bdev = NULL; return error; } p->old_block_size = block_size(p->bdev); error = set_blocksize(p->bdev, PAGE_SIZE); if (error < 0) return error; we already have the file opened, and we keep it opened all the way until the swapoff(2); here we have noticed that it's a block device and we * open the fucker again (by device number), this time claiming it with our swap_info_struct as holder, to be closed at swapoff(2) time (just before we close the file) * flip the block size to PAGE_SIZE, to be reverted at swapoff(2) time That really looks like it ought to be * take the opened file, see that it's a block device * try to claim it with that holder * on success, flip the block size with close_filp() in the swapoff(2) (or failure exit path in swapon(2)) doing what it would've done for an O_EXCL opened block device. The only difference from O_EXCL userland open is that here we would end up with holder pointing not to struct file in question, but to our swap_info_struct. It will do the right thing. This extra open is entirely due to "well, we need to claim it and the primitive that does that happens to be tied to opening"; feels rather counter-intuitive. For that matter, we could add an explicit "unclaim" primitive - might be easier to follow. That would add another example where that could be used - in blkdev_bszset() we have an opened block device (it's an ioctl, after all), we want to change block size and we *really* don't want to have that happen under a mounted filesystem. So if it's not opened exclusive, we do a temporary exclusive open of own and act on that instead. Might as well go for a temporary claim... BTW, what happens if two threads call ioctl(fd, BLKBSZSET, &n) for the same descriptor that happens to have been opened O_EXCL? Without O_EXCL they would've been unable to claim the sucker at the same time - the holder we are using is the address of a function argument, i.e. something that points to kernel stack of the caller. Those would conflict and we either get set_blocksize() calls fully serialized, or one of the callers would eat -EBUSY. Not so in "opened with O_EXCL" case - they can very well overlap and IIRC set_blocksize() does *not* expect that kind of crap... It's all under CAP_SYS_ADMIN, so it's not as if it was a meaningful security hole anyway, but it does look fishy. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/29] block: Make blkdev_get_by_*() return handle 2023-08-26 2:28 ` Al Viro @ 2023-08-28 14:27 ` Christoph Hellwig 0 siblings, 0 replies; 9+ messages in thread From: Christoph Hellwig @ 2023-08-28 14:27 UTC (permalink / raw) To: Al Viro Cc: Dave Kleikamp, jfs-discussion-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Jan Kara, Darrick J. Wong, linux-nvme-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Joseph Qi, dm-devel-H+wXaHxf7aLQT0dZR+AlfA, target-devel-u79uwXL29TY76Z2rM5mHXA, linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Jack Wang, Alasdair Kergon, drbd-dev-cunTk1MwBs8qoQakbn7OcQ, linux-s390-u79uwXL29TY76Z2rM5mHXA, linux-nilfs-u79uwXL29TY76Z2rM5mHXA, linux-scsi-u79uwXL29TY76Z2rM5mHXA, Sergey Senozhatsky, Christoph Hellwig, xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b, Gao Xiang, Christian Borntraeger, Kent Overstreet, Sven Schnelle, linux-pm-u79uwXL29TY76Z2rM5mHXA, Mike Snitzer, Chao Yu, Joern Engel, re On Sat, Aug 26, 2023 at 03:28:52AM +0100, Al Viro wrote: > I mean, look at claim_swapfile() for example: > p->bdev = blkdev_get_by_dev(inode->i_rdev, > FMODE_READ | FMODE_WRITE | FMODE_EXCL, p); > if (IS_ERR(p->bdev)) { > error = PTR_ERR(p->bdev); > p->bdev = NULL; > return error; > } > p->old_block_size = block_size(p->bdev); > error = set_blocksize(p->bdev, PAGE_SIZE); > if (error < 0) > return error; > we already have the file opened, and we keep it opened all the way until > the swapoff(2); here we have noticed that it's a block device and we > * open the fucker again (by device number), this time claiming > it with our swap_info_struct as holder, to be closed at swapoff(2) time > (just before we close the file) Note that some drivers look at FMODE_EXCL/BLK_OPEN_EXCL in ->open. These are probably bogus and maybe we want to kill them, but that will need an audit first. > BTW, what happens if two threads call ioctl(fd, BLKBSZSET, &n) > for the same descriptor that happens to have been opened O_EXCL? > Without O_EXCL they would've been unable to claim the sucker at the same > time - the holder we are using is the address of a function argument, > i.e. something that points to kernel stack of the caller. Those would > conflict and we either get set_blocksize() calls fully serialized, or > one of the callers would eat -EBUSY. Not so in "opened with O_EXCL" > case - they can very well overlap and IIRC set_blocksize() does *not* > expect that kind of crap... It's all under CAP_SYS_ADMIN, so it's not > as if it was a meaningful security hole anyway, but it does look fishy. The user get to keep the pieces.. BLKBSZSET is kinda bogus anyway as the soft blocksize only matters for buffer_head-like I/O, and there only for file systems. Not idea why anyone would set it manually. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/29] block: Make blkdev_get_by_*() return handle 2023-08-25 13:47 ` Jan Kara 2023-08-26 2:28 ` Al Viro @ 2023-08-28 13:20 ` Christian Brauner 2023-08-28 14:22 ` Christoph Hellwig 2 siblings, 0 replies; 9+ messages in thread From: Christian Brauner @ 2023-08-28 13:20 UTC (permalink / raw) To: Jan Kara Cc: Dave Kleikamp, jfs-discussion-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Darrick J. Wong, linux-nvme-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Joseph Qi, dm-devel-H+wXaHxf7aLQT0dZR+AlfA, target-devel-u79uwXL29TY76Z2rM5mHXA, linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Jack Wang, Alasdair Kergon, drbd-dev-cunTk1MwBs8qoQakbn7OcQ, linux-s390-u79uwXL29TY76Z2rM5mHXA, linux-nilfs-u79uwXL29TY76Z2rM5mHXA, linux-scsi-u79uwXL29TY76Z2rM5mHXA, Sergey Senozhatsky, Christoph Hellwig, xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b, Gao Xiang, Christian Borntraeger, Kent Overstreet, Sven Schnelle, linux-pm-u79uwXL29TY76Z2rM5mHXA, Mike Snitzer, Chao Yu, Joern Engel, reiserfs-devel-u79uwXL29TbrhsbdSgBK9A > So besides my last fput() worry about I think this could work and would be > probably a bit nicer than what I have. But before going and redoing the whole > series let me gather some more feedback so that we don't go back and forth. > Christoph, Christian, Jens, any opinion? I'll be a bit under water for the next few days, I expect but I'll get back to this. I think not making you redo this whole thing from scratch is what I'd prefer unless there's really clear advantages. But I don't want to offer a haphazard opinion in the middle of the merge window. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/29] block: Make blkdev_get_by_*() return handle 2023-08-25 13:47 ` Jan Kara 2023-08-26 2:28 ` Al Viro 2023-08-28 13:20 ` Christian Brauner @ 2023-08-28 14:22 ` Christoph Hellwig 2 siblings, 0 replies; 9+ messages in thread From: Christoph Hellwig @ 2023-08-28 14:22 UTC (permalink / raw) To: Jan Kara Cc: Dave Kleikamp, jfs-discussion-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Darrick J. Wong, linux-nvme-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Joseph Qi, dm-devel-H+wXaHxf7aLQT0dZR+AlfA, target-devel-u79uwXL29TY76Z2rM5mHXA, linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Jack Wang, Alasdair Kergon, drbd-dev-cunTk1MwBs8qoQakbn7OcQ, linux-s390-u79uwXL29TY76Z2rM5mHXA, linux-nilfs-u79uwXL29TY76Z2rM5mHXA, linux-scsi-u79uwXL29TY76Z2rM5mHXA, Sergey Senozhatsky, Christoph Hellwig, xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b, Gao Xiang, Christian Borntraeger, Kent Overstreet, Sven Schnelle, Christian Brauner, linux-pm-u79uwXL29TY76Z2rM5mHXA, Mike Snitzer, Chao Yu, Joern Engel On Fri, Aug 25, 2023 at 03:47:56PM +0200, Jan Kara wrote: > I can see the appeal of not having to introduce the new bdev_handle type > and just using struct file which unifies in-kernel and userspace block > device opens. But I can see downsides too - the last fput() happening from > task work makes me a bit nervous whether it will not break something > somewhere with exclusive bdev opens. Getting from struct file to bdev is > somewhat harder but I guess a helper like F_BDEV() would solve that just > fine. > > So besides my last fput() worry about I think this could work and would be > probably a bit nicer than what I have. But before going and redoing the whole > series let me gather some more feedback so that we don't go back and forth. > Christoph, Christian, Jens, any opinion? I did think about the file a bit. The fact that we'd need something like an anon_file for the by_dev open was always a huge turn off for me, but maybe my concern is overblown. Having a struct file would actually be really useful for a bunch of users. ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-08-28 14:27 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-08-11 11:04 [PATCH v2 0/29] block: Make blkdev_get_by_*() return handle Jan Kara 2023-08-11 11:04 ` [PATCH 27/29] reiserfs: Convert to bdev_open_by_dev/path() Jan Kara 2023-08-11 12:27 ` [PATCH v2 0/29] block: Make blkdev_get_by_*() return handle Christoph Hellwig 2023-08-25 1:58 ` Al Viro 2023-08-25 13:47 ` Jan Kara 2023-08-26 2:28 ` Al Viro 2023-08-28 14:27 ` Christoph Hellwig 2023-08-28 13:20 ` Christian Brauner 2023-08-28 14:22 ` Christoph Hellwig
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).