Skip to content

Commit

Permalink
VFS: Convert sb->s_flags & MS_RDONLY to sb_rdonly(sb)
Browse files Browse the repository at this point in the history
Firstly by applying the following with coccinelle's spatch:

	@@ expression SB; @@
	-SB->s_flags & MS_RDONLY
	+sb_rdonly(SB)

to effect the conversion to sb_rdonly(sb), then by applying:

	@@ expression A, SB; @@
	(
	-(!sb_rdonly(SB)) && A
	+!sb_rdonly(SB) && A
	|
	-A != (sb_rdonly(SB))
	+A != sb_rdonly(SB)
	|
	-A == (sb_rdonly(SB))
	+A == sb_rdonly(SB)
	|
	-!(sb_rdonly(SB))
	+!sb_rdonly(SB)
	|
	-A && (sb_rdonly(SB))
	+A && sb_rdonly(SB)
	|
	-A || (sb_rdonly(SB))
	+A || sb_rdonly(SB)
	|
	-(sb_rdonly(SB)) != A
	+sb_rdonly(SB) != A
	|
	-(sb_rdonly(SB)) == A
	+sb_rdonly(SB) == A
	|
	-(sb_rdonly(SB)) && A
	+sb_rdonly(SB) && A
	|
	-(sb_rdonly(SB)) || A
	+sb_rdonly(SB) || A
	)

	@@ expression A, B, SB; @@
	(
	-(sb_rdonly(SB)) ? 1 : 0
	+sb_rdonly(SB)
	|
	-(sb_rdonly(SB)) ? A : B
	+sb_rdonly(SB) ? A : B
	)

to remove left over excess bracketage and finally by applying:

	@@ expression A, SB; @@
	(
	-(A & MS_RDONLY) != sb_rdonly(SB)
	+(bool)(A & MS_RDONLY) != sb_rdonly(SB)
	|
	-(A & MS_RDONLY) == sb_rdonly(SB)
	+(bool)(A & MS_RDONLY) == sb_rdonly(SB)
	)

to make comparisons against the result of sb_rdonly() (which is a bool)
work correctly.

Signed-off-by: David Howells <dhowells@redhat.com>
  • Loading branch information
dhowells committed Jul 17, 2017
1 parent 94e92e7 commit bc98a42
Show file tree
Hide file tree
Showing 74 changed files with 210 additions and 226 deletions.
4 changes: 2 additions & 2 deletions drivers/staging/lustre/lustre/llite/llite_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
data->ocd_ibits_known = MDS_INODELOCK_FULL;
data->ocd_version = LUSTRE_VERSION_CODE;

if (sb->s_flags & MS_RDONLY)
if (sb_rdonly(sb))
data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
if (sbi->ll_flags & LL_SBI_USER_XATTR)
data->ocd_connect_flags |= OBD_CONNECT_XATTR;
Expand Down Expand Up @@ -2033,7 +2033,7 @@ int ll_remount_fs(struct super_block *sb, int *flags, char *data)
int err;
__u32 read_only;

if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
if ((bool)(*flags & MS_RDONLY) != sb_rdonly(sb)) {
read_only = *flags & MS_RDONLY;
err = obd_set_info_async(NULL, sbi->ll_md_exp,
sizeof(KEY_READ_ONLY),
Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/lustre/lustre/llite/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,7 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
}
}

if (it->it_op & IT_OPEN && it->it_flags & FMODE_WRITE &&
dentry->d_sb->s_flags & MS_RDONLY)
if (it->it_op & IT_OPEN && it->it_flags & FMODE_WRITE && sb_rdonly(dentry->d_sb))
return ERR_PTR(-EROFS);

if (it->it_op & IT_CREAT)
Expand Down
2 changes: 1 addition & 1 deletion fs/affs/amigaffs.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ affs_error(struct super_block *sb, const char *function, const char *fmt, ...)
vaf.fmt = fmt;
vaf.va = &args;
pr_crit("error (device %s): %s(): %pV\n", sb->s_id, function, &vaf);
if (!(sb->s_flags & MS_RDONLY))
if (!sb_rdonly(sb))
pr_warn("Remounting filesystem read-only\n");
sb->s_flags |= MS_RDONLY;
va_end(args);
Expand Down
2 changes: 1 addition & 1 deletion fs/affs/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ affs_count_free_blocks(struct super_block *sb)

pr_debug("%s()\n", __func__);

if (sb->s_flags & MS_RDONLY)
if (sb_rdonly(sb))
return 0;

mutex_lock(&AFFS_SB(sb)->s_bmlock);
Expand Down
6 changes: 3 additions & 3 deletions fs/affs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void affs_mark_sb_dirty(struct super_block *sb)
struct affs_sb_info *sbi = AFFS_SB(sb);
unsigned long delay;

if (sb->s_flags & MS_RDONLY)
if (sb_rdonly(sb))
return;

spin_lock(&sbi->work_lock);
Expand Down Expand Up @@ -464,7 +464,7 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
* not recommended.
*/
if ((chksum == FS_DCFFS || chksum == MUFS_DCFFS || chksum == FS_DCOFS
|| chksum == MUFS_DCOFS) && !(sb->s_flags & MS_RDONLY)) {
|| chksum == MUFS_DCOFS) && !sb_rdonly(sb)) {
pr_notice("Dircache FS - mounting %s read only\n", sb->s_id);
sb->s_flags |= MS_RDONLY;
}
Expand Down Expand Up @@ -596,7 +596,7 @@ affs_remount(struct super_block *sb, int *flags, char *data)
memcpy(sbi->s_volume, volume, 32);
spin_unlock(&sbi->symlink_lock);

if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
if ((bool)(*flags & MS_RDONLY) == sb_rdonly(sb))
return 0;

if (*flags & MS_RDONLY)
Expand Down
2 changes: 1 addition & 1 deletion fs/befs/linuxvfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ befs_fill_super(struct super_block *sb, void *data, int silent)

befs_debug(sb, "---> %s", __func__);

if (!(sb->s_flags & MS_RDONLY)) {
if (!sb_rdonly(sb)) {
befs_warning(sb,
"No write support. Marking filesystem read-only");
sb->s_flags |= MS_RDONLY;
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/dev-replace.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ static u64 __btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
u64 result;
int ret;

if (fs_info->sb->s_flags & MS_RDONLY)
if (sb_rdonly(fs_info->sb))
return -EROFS;

mutex_lock(&dev_replace->lock_finishing_cancel_unmount);
Expand Down
12 changes: 6 additions & 6 deletions fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2478,7 +2478,7 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
return ret;
}

if (fs_info->sb->s_flags & MS_RDONLY) {
if (sb_rdonly(fs_info->sb)) {
ret = btrfs_commit_super(fs_info);
if (ret)
return ret;
Expand Down Expand Up @@ -2874,7 +2874,7 @@ int open_ctree(struct super_block *sb,

features = btrfs_super_compat_ro_flags(disk_super) &
~BTRFS_FEATURE_COMPAT_RO_SUPP;
if (!(sb->s_flags & MS_RDONLY) && features) {
if (!sb_rdonly(sb) && features) {
btrfs_err(fs_info,
"cannot mount read-write because of unsupported optional features (%llx)",
features);
Expand Down Expand Up @@ -3039,7 +3039,7 @@ int open_ctree(struct super_block *sb,
btrfs_calc_num_tolerated_disk_barrier_failures(fs_info);
if (fs_info->fs_devices->missing_devices >
fs_info->num_tolerated_disk_barrier_failures &&
!(sb->s_flags & MS_RDONLY)) {
!sb_rdonly(sb)) {
btrfs_warn(fs_info,
"missing devices (%llu) exceeds the limit (%d), writeable mount is not allowed",
fs_info->fs_devices->missing_devices,
Expand Down Expand Up @@ -3102,7 +3102,7 @@ int open_ctree(struct super_block *sb,
if (ret)
goto fail_qgroup;

if (!(sb->s_flags & MS_RDONLY)) {
if (!sb_rdonly(sb)) {
ret = btrfs_cleanup_fs_roots(fs_info);
if (ret)
goto fail_qgroup;
Expand All @@ -3128,7 +3128,7 @@ int open_ctree(struct super_block *sb,
goto fail_qgroup;
}

if (sb->s_flags & MS_RDONLY)
if (sb_rdonly(sb))
return 0;

if (btrfs_test_opt(fs_info, CLEAR_CACHE) &&
Expand Down Expand Up @@ -3928,7 +3928,7 @@ void close_ctree(struct btrfs_fs_info *fs_info)

cancel_work_sync(&fs_info->async_reclaim_work);

if (!(fs_info->sb->s_flags & MS_RDONLY)) {
if (!sb_rdonly(fs_info->sb)) {
/*
* If the cleaner thread is stopped and there are
* block groups queued for removal, the deletion will be
Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/extent_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,7 @@ int repair_eb_io_failure(struct btrfs_fs_info *fs_info,
unsigned long i, num_pages = num_extent_pages(eb->start, eb->len);
int ret = 0;

if (fs_info->sb->s_flags & MS_RDONLY)
if (sb_rdonly(fs_info->sb))
return -EROFS;

for (i = 0; i < num_pages; i++) {
Expand Down Expand Up @@ -2111,7 +2111,7 @@ int clean_io_failure(struct btrfs_fs_info *fs_info,
failrec->start);
goto out;
}
if (fs_info->sb->s_flags & MS_RDONLY)
if (sb_rdonly(fs_info->sb))
goto out;

spin_lock(&io_tree->lock);
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -5817,7 +5817,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)

if (!IS_ERR(inode) && root != sub_root) {
down_read(&fs_info->cleanup_work_sem);
if (!(inode->i_sb->s_flags & MS_RDONLY))
if (!sb_rdonly(inode->i_sb))
ret = btrfs_orphan_cleanup(sub_root);
up_read(&fs_info->cleanup_work_sem);
if (ret) {
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4438,7 +4438,7 @@ static long btrfs_ioctl_dev_replace(struct btrfs_fs_info *fs_info,

switch (p->cmd) {
case BTRFS_IOCTL_DEV_REPLACE_CMD_START:
if (fs_info->sb->s_flags & MS_RDONLY) {
if (sb_rdonly(fs_info->sb)) {
ret = -EROFS;
goto out;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/root-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
int ret;
bool can_recover = true;

if (fs_info->sb->s_flags & MS_RDONLY)
if (sb_rdonly(fs_info->sb))
can_recover = false;

path = btrfs_alloc_path();
Expand Down
11 changes: 5 additions & 6 deletions fs/btrfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static void btrfs_handle_error(struct btrfs_fs_info *fs_info)
{
struct super_block *sb = fs_info->sb;

if (sb->s_flags & MS_RDONLY)
if (sb_rdonly(sb))
return;

if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
Expand Down Expand Up @@ -138,7 +138,7 @@ void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function
* Special case: if the error is EROFS, and we're already
* under MS_RDONLY, then it is safe here.
*/
if (errno == -EROFS && (sb->s_flags & MS_RDONLY))
if (errno == -EROFS && sb_rdonly(sb))
return;

#ifdef CONFIG_PRINTK
Expand Down Expand Up @@ -1687,8 +1687,7 @@ static inline void btrfs_remount_cleanup(struct btrfs_fs_info *fs_info,
* close or the filesystem is read only.
*/
if (btrfs_raw_test_opt(old_opts, AUTO_DEFRAG) &&
(!btrfs_raw_test_opt(fs_info->mount_opt, AUTO_DEFRAG) ||
(fs_info->sb->s_flags & MS_RDONLY))) {
(!btrfs_raw_test_opt(fs_info->mount_opt, AUTO_DEFRAG) || sb_rdonly(fs_info->sb))) {
btrfs_cleanup_defrag_inodes(fs_info);
}

Expand Down Expand Up @@ -1735,7 +1734,7 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
btrfs_resize_thread_pool(fs_info,
fs_info->thread_pool_size, old_thread_pool_size);

if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
if ((bool)(*flags & MS_RDONLY) == sb_rdonly(sb))
goto out;

if (*flags & MS_RDONLY) {
Expand Down Expand Up @@ -1835,7 +1834,7 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)

restore:
/* We've hit an error - don't reset MS_RDONLY */
if (sb->s_flags & MS_RDONLY)
if (sb_rdonly(sb))
old_flags |= MS_RDONLY;
sb->s_flags = old_flags;
fs_info->mount_opt = old_opts;
Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static ssize_t btrfs_feature_attr_store(struct kobject *kobj,
if (!fs_info)
return -EPERM;

if (fs_info->sb->s_flags & MS_RDONLY)
if (sb_rdonly(fs_info->sb))
return -EROFS;

ret = kstrtoul(skip_spaces(buf), 0, &val);
Expand Down Expand Up @@ -388,7 +388,7 @@ static ssize_t btrfs_label_store(struct kobject *kobj,
if (!fs_info)
return -EPERM;

if (fs_info->sb->s_flags & MS_RDONLY)
if (sb_rdonly(fs_info->sb))
return -EROFS;

/*
Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/volumes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2337,7 +2337,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
int seeding_dev = 0;
int ret = 0;

if ((sb->s_flags & MS_RDONLY) && !fs_info->fs_devices->seeding)
if (sb_rdonly(sb) && !fs_info->fs_devices->seeding)
return -EROFS;

bdev = blkdev_get_by_path(device_path, FMODE_WRITE | FMODE_EXCL,
Expand Down Expand Up @@ -4085,7 +4085,7 @@ int btrfs_pause_balance(struct btrfs_fs_info *fs_info)

int btrfs_cancel_balance(struct btrfs_fs_info *fs_info)
{
if (fs_info->sb->s_flags & MS_RDONLY)
if (sb_rdonly(fs_info->sb))
return -EROFS;

mutex_lock(&fs_info->balance_mutex);
Expand Down
2 changes: 1 addition & 1 deletion fs/cachefiles/bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static int cachefiles_daemon_add_cache(struct cachefiles_cache *cache)
goto error_unsupported;

ret = -EROFS;
if (root->d_sb->s_flags & MS_RDONLY)
if (sb_rdonly(root->d_sb))
goto error_unsupported;

/* determine the security of the on-disk cache as this governs
Expand Down
3 changes: 1 addition & 2 deletions fs/ecryptfs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,7 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
* 1) The lower mount is ro
* 2) The ecryptfs_encrypted_view mount option is specified
*/
if (path.dentry->d_sb->s_flags & MS_RDONLY ||
mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED)
if (sb_rdonly(path.dentry->d_sb) || mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED)
s->s_flags |= MS_RDONLY;

s->s_maxbytes = path.dentry->d_sb->s_maxbytes;
Expand Down
2 changes: 1 addition & 1 deletion fs/efs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ static int efs_fill_super(struct super_block *s, void *d, int silent)
}
brelse(bh);

if (!(s->s_flags & MS_RDONLY)) {
if (!sb_rdonly(s)) {
#ifdef DEBUG
pr_info("forcing read-only mode\n");
#endif
Expand Down
13 changes: 6 additions & 7 deletions fs/ext2/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void ext2_error(struct super_block *sb, const char *function,
struct ext2_sb_info *sbi = EXT2_SB(sb);
struct ext2_super_block *es = sbi->s_es;

if (!(sb->s_flags & MS_RDONLY)) {
if (!sb_rdonly(sb)) {
spin_lock(&sbi->s_lock);
sbi->s_mount_state |= EXT2_ERROR_FS;
es->s_state |= cpu_to_le16(EXT2_ERROR_FS);
Expand Down Expand Up @@ -151,7 +151,7 @@ static void ext2_put_super (struct super_block * sb)
ext2_xattr_destroy_cache(sbi->s_ea_block_cache);
sbi->s_ea_block_cache = NULL;
}
if (!(sb->s_flags & MS_RDONLY)) {
if (!sb_rdonly(sb)) {
struct ext2_super_block *es = sbi->s_es;

spin_lock(&sbi->s_lock);
Expand Down Expand Up @@ -940,8 +940,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
le32_to_cpu(features));
goto failed_mount;
}
if (!(sb->s_flags & MS_RDONLY) &&
(features = EXT2_HAS_RO_COMPAT_FEATURE(sb, ~EXT2_FEATURE_RO_COMPAT_SUPP))){
if (!sb_rdonly(sb) && (features = EXT2_HAS_RO_COMPAT_FEATURE(sb, ~EXT2_FEATURE_RO_COMPAT_SUPP))){
ext2_msg(sb, KERN_ERR, "error: couldn't mount RDWR because of "
"unsupported optional features (%x)",
le32_to_cpu(features));
Expand Down Expand Up @@ -1170,7 +1169,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
if (EXT2_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL))
ext2_msg(sb, KERN_WARNING,
"warning: mounting ext3 filesystem as ext2");
if (ext2_setup_super (sb, es, sb->s_flags & MS_RDONLY))
if (ext2_setup_super (sb, es, sb_rdonly(sb)))
sb->s_flags |= MS_RDONLY;
ext2_write_super(sb);
return 0;
Expand Down Expand Up @@ -1301,7 +1300,7 @@ static int ext2_unfreeze(struct super_block *sb)

static void ext2_write_super(struct super_block *sb)
{
if (!(sb->s_flags & MS_RDONLY))
if (!sb_rdonly(sb))
ext2_sync_fs(sb, 1);
}

Expand Down Expand Up @@ -1339,7 +1338,7 @@ static int ext2_remount (struct super_block * sb, int * flags, char * data)
"dax flag with busy inodes while remounting");
sbi->s_mount_opt ^= EXT2_MOUNT_DAX;
}
if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) {
if ((bool)(*flags & MS_RDONLY) == sb_rdonly(sb)) {
spin_unlock(&sbi->s_lock);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/ext4/ext4_jbd2.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static int ext4_journal_check_start(struct super_block *sb)
if (unlikely(ext4_forced_shutdown(EXT4_SB(sb))))
return -EIO;

if (sb->s_flags & MS_RDONLY)
if (sb_rdonly(sb))
return -EROFS;
WARN_ON(sb->s_writers.frozen == SB_FREEZE_COMPLETE);
journal = EXT4_SB(sb)->s_journal;
Expand Down
2 changes: 1 addition & 1 deletion fs/ext4/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
return -EIO;

if (unlikely(!(sbi->s_mount_flags & EXT4_MF_MNTDIR_SAMPLED) &&
!(sb->s_flags & MS_RDONLY))) {
!sb_rdonly(sb))) {
sbi->s_mount_flags |= EXT4_MF_MNTDIR_SAMPLED;
/*
* Sample where the filesystem has been mounted and
Expand Down
2 changes: 1 addition & 1 deletion fs/ext4/fsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync)

trace_ext4_sync_file_enter(file, datasync);

if (inode->i_sb->s_flags & MS_RDONLY) {
if (sb_rdonly(inode->i_sb)) {
/* Make sure that we read updated s_mount_flags value */
smp_rmb();
if (EXT4_SB(inode->i_sb)->s_mount_flags & EXT4_MF_FS_ABORTED)
Expand Down
2 changes: 1 addition & 1 deletion fs/ext4/ialloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ int ext4_init_inode_table(struct super_block *sb, ext4_group_t group,
int num, ret = 0, used_blks = 0;

/* This should not happen, but just to be sure check this */
if (sb->s_flags & MS_RDONLY) {
if (sb_rdonly(sb)) {
ret = 1;
goto out;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/ext4/mmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ static int kmmpd(void *data)
goto exit_thread;
}

if (sb->s_flags & MS_RDONLY) {
if (sb_rdonly(sb)) {
ext4_warning(sb, "kmmpd being stopped since filesystem "
"has been remounted as readonly.");
goto exit_thread;
Expand Down
Loading

0 comments on commit bc98a42

Please sign in to comment.