From 440a3476992cbd1a3a4bbf4cd01a3e28ee7615d1 Mon Sep 17 00:00:00 2001 From: Ryusuke Konishi Date: Tue, 3 Oct 2023 21:45:31 +0900 Subject: [PATCH] Support blk_mode_t type and sb_open_mode() helper introduction 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 --- fs/nilfs2/kern_feature.h | 17 +++++++++++++++++ fs/nilfs2/super.c | 5 +---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/fs/nilfs2/kern_feature.h b/fs/nilfs2/kern_feature.h index 4951370..13ca607 100644 --- a/fs/nilfs2/kern_feature.h +++ b/fs/nilfs2/kern_feature.h @@ -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 @@ -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 @@ -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 */ @@ -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 */ diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c index 6ebb563..77cb821 100644 --- a/fs/nilfs2/super.c +++ b/fs/nilfs2/super.c @@ -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);