Skip to content

Commit

Permalink
Support blk_mode_t type and sb_open_mode() helper introduction
Browse files Browse the repository at this point in the history
Kernel 6.5 replaced the fmode_t type with the blk_mode_t type in the
fs mount procedures, and introduced sb_open_helper() to simplify
calculating its value from mount flags.

These changes were backported to RHEL 9 (RHEL_RELEASE >= 370), so
support them switching their definitions depending on kernel versions.

Signed-off-by: Ryusuke Konishi <[email protected]>
  • Loading branch information
konis committed Oct 3, 2023
1 parent 9339101 commit 440a347
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
17 changes: 17 additions & 0 deletions fs/nilfs2/kern_feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
# if (RHEL_RELEASE_N >= 370)
# define HAVE_NEW_BLKDEV_GET_AND_PUT 1
# define HAVE_SB_S_MODE 0
# define HAVE_BLK_MODE_T 1
# endif
# else /* !defined(RHEL_RELEASE_N) */
# define HAVE_BD_BDI 0
Expand All @@ -72,6 +73,7 @@
# if (RHEL_MINOR > 3) /* RHEL_RELEASE_N >= 363 */
# define HAVE_NEW_BLKDEV_GET_AND_PUT 1
# define HAVE_SB_S_MODE 0
# define HAVE_BLK_MODE_T 1
# endif
# endif
#endif
Expand Down Expand Up @@ -210,6 +212,15 @@
# define HAVE_SB_S_MODE \
(LINUX_VERSION_CODE < KERNEL_VERSION(6, 5, 0))
#endif
/*
* In kernel 6.5, regarding block open flags, fmode_t has been replaced
* with block-specific type (BLK_OPEN_*) and sb_open_mode() helper has
* been added to simplify calculating its value from mount flags.
*/
#ifndef HAVE_BLK_MODE_T
# define HAVE_BLK_MODE_T \
(LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0))
#endif
#endif /* LINUX_VERSION_CODE */


Expand Down Expand Up @@ -291,4 +302,10 @@ compat_submit_bh(int mode, int mode_flags, struct buffer_head *bh)
blkdev_put(bdev, mode)
#endif

#if !HAVE_BLK_MODE_T
typedef fmode_t blk_mode_t;
#define sb_open_mode(flags) \
(FMODE_READ | FMODE_EXCL | (((flags) & SB_RDONLY) ? 0 : FMODE_WRITE))
#endif

#endif /* NILFS_KERN_FEATURE_H */
5 changes: 1 addition & 4 deletions fs/nilfs2/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -1306,13 +1306,10 @@ nilfs_mount(struct file_system_type *fs_type, int flags,
{
struct nilfs_super_data sd;
struct super_block *s;
fmode_t mode = FMODE_READ | FMODE_EXCL;
blk_mode_t mode = sb_open_mode(flags);
struct dentry *root_dentry;
int err, s_new = false;

if (!(flags & SB_RDONLY))
mode |= FMODE_WRITE;

sd.bdev = compat_blkdev_get_by_path(dev_name, mode, fs_type, NULL);
if (IS_ERR(sd.bdev))
return ERR_CAST(sd.bdev);
Expand Down

0 comments on commit 440a347

Please sign in to comment.