@@ -258,7 +258,8 @@ __bch2_create(struct mnt_idmap *idmap,
258258retry :
259259 bch2_trans_begin (trans );
260260
261- ret = bch2_create_trans (trans ,
261+ ret = bch2_subvol_is_ro_trans (trans , dir -> ei_subvol ) ?:
262+ bch2_create_trans (trans ,
262263 inode_inum (dir ), & dir_u , & inode_u ,
263264 !(flags & BCH_CREATE_TMPFILE )
264265 ? & dentry -> d_name : NULL ,
@@ -430,7 +431,9 @@ static int bch2_link(struct dentry *old_dentry, struct inode *vdir,
430431
431432 lockdep_assert_held (& inode -> v .i_rwsem );
432433
433- ret = __bch2_link (c , inode , dir , dentry );
434+ ret = bch2_subvol_is_ro (c , dir -> ei_subvol ) ?:
435+ bch2_subvol_is_ro (c , inode -> ei_subvol ) ?:
436+ __bch2_link (c , inode , dir , dentry );
434437 if (unlikely (ret ))
435438 return ret ;
436439
@@ -481,7 +484,11 @@ int __bch2_unlink(struct inode *vdir, struct dentry *dentry,
481484
482485static int bch2_unlink (struct inode * vdir , struct dentry * dentry )
483486{
484- return __bch2_unlink (vdir , dentry , false);
487+ struct bch_inode_info * dir = to_bch_ei (vdir );
488+ struct bch_fs * c = dir -> v .i_sb -> s_fs_info ;
489+
490+ return bch2_subvol_is_ro (c , dir -> ei_subvol ) ?:
491+ __bch2_unlink (vdir , dentry , false);
485492}
486493
487494static int bch2_symlink (struct mnt_idmap * idmap ,
@@ -562,6 +569,11 @@ static int bch2_rename2(struct mnt_idmap *idmap,
562569 src_inode ,
563570 dst_inode );
564571
572+ ret = bch2_subvol_is_ro_trans (trans , src_dir -> ei_subvol ) ?:
573+ bch2_subvol_is_ro_trans (trans , dst_dir -> ei_subvol );
574+ if (ret )
575+ goto err ;
576+
565577 if (inode_attr_changing (dst_dir , src_inode , Inode_opt_project )) {
566578 ret = bch2_fs_quota_transfer (c , src_inode ,
567579 dst_dir -> ei_qid ,
@@ -783,11 +795,13 @@ static int bch2_setattr(struct mnt_idmap *idmap,
783795 struct dentry * dentry , struct iattr * iattr )
784796{
785797 struct bch_inode_info * inode = to_bch_ei (dentry -> d_inode );
798+ struct bch_fs * c = inode -> v .i_sb -> s_fs_info ;
786799 int ret ;
787800
788801 lockdep_assert_held (& inode -> v .i_rwsem );
789802
790- ret = setattr_prepare (idmap , dentry , iattr );
803+ ret = bch2_subvol_is_ro (c , inode -> ei_subvol ) ?:
804+ setattr_prepare (idmap , dentry , iattr );
791805 if (ret )
792806 return ret ;
793807
@@ -1010,12 +1024,26 @@ static int bch2_vfs_readdir(struct file *file, struct dir_context *ctx)
10101024 return bch2_err_class (ret );
10111025}
10121026
1027+ static int bch2_open (struct inode * vinode , struct file * file )
1028+ {
1029+ if (file -> f_flags & (O_WRONLY |O_RDWR )) {
1030+ struct bch_inode_info * inode = to_bch_ei (vinode );
1031+ struct bch_fs * c = inode -> v .i_sb -> s_fs_info ;
1032+
1033+ int ret = bch2_subvol_is_ro (c , inode -> ei_subvol );
1034+ if (ret )
1035+ return ret ;
1036+ }
1037+
1038+ return generic_file_open (vinode , file );
1039+ }
1040+
10131041static const struct file_operations bch_file_operations = {
1042+ .open = bch2_open ,
10141043 .llseek = bch2_llseek ,
10151044 .read_iter = bch2_read_iter ,
10161045 .write_iter = bch2_write_iter ,
10171046 .mmap = bch2_mmap ,
1018- .open = generic_file_open ,
10191047 .fsync = bch2_fsync ,
10201048 .splice_read = filemap_splice_read ,
10211049 .splice_write = iter_file_splice_write ,
0 commit comments