hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/fs/nilfs2/inode.c
....@@ -921,6 +921,7 @@
921921 struct nilfs_transaction_info ti;
922922 struct super_block *sb = inode->i_sb;
923923 struct nilfs_inode_info *ii = NILFS_I(inode);
924
+ struct the_nilfs *nilfs;
924925 int ret;
925926
926927 if (inode->i_nlink || !ii->i_root || unlikely(is_bad_inode(inode))) {
....@@ -932,6 +933,23 @@
932933 nilfs_transaction_begin(sb, &ti, 0); /* never fails */
933934
934935 truncate_inode_pages_final(&inode->i_data);
936
+
937
+ nilfs = sb->s_fs_info;
938
+ if (unlikely(sb_rdonly(sb) || !nilfs->ns_writer)) {
939
+ /*
940
+ * If this inode is about to be disposed after the file system
941
+ * has been degraded to read-only due to file system corruption
942
+ * or after the writer has been detached, do not make any
943
+ * changes that cause writes, just clear it.
944
+ * Do this check after read-locking ns_segctor_sem by
945
+ * nilfs_transaction_begin() in order to avoid a race with
946
+ * the writer detach operation.
947
+ */
948
+ clear_inode(inode);
949
+ nilfs_clear_inode(inode);
950
+ nilfs_transaction_abort(sb);
951
+ return;
952
+ }
935953
936954 /* TODO: some of the following operations may fail. */
937955 nilfs_truncate_bmap(ii, 0);
....@@ -1009,7 +1027,7 @@
10091027 int err;
10101028
10111029 spin_lock(&nilfs->ns_inode_lock);
1012
- if (ii->i_bh == NULL) {
1030
+ if (ii->i_bh == NULL || unlikely(!buffer_uptodate(ii->i_bh))) {
10131031 spin_unlock(&nilfs->ns_inode_lock);
10141032 err = nilfs_ifile_get_inode_block(ii->i_root->ifile,
10151033 inode->i_ino, pbh);
....@@ -1018,7 +1036,10 @@
10181036 spin_lock(&nilfs->ns_inode_lock);
10191037 if (ii->i_bh == NULL)
10201038 ii->i_bh = *pbh;
1021
- else {
1039
+ else if (unlikely(!buffer_uptodate(ii->i_bh))) {
1040
+ __brelse(ii->i_bh);
1041
+ ii->i_bh = *pbh;
1042
+ } else {
10221043 brelse(*pbh);
10231044 *pbh = ii->i_bh;
10241045 }
....@@ -1085,9 +1106,17 @@
10851106
10861107 int __nilfs_mark_inode_dirty(struct inode *inode, int flags)
10871108 {
1109
+ struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
10881110 struct buffer_head *ibh;
10891111 int err;
10901112
1113
+ /*
1114
+ * Do not dirty inodes after the log writer has been detached
1115
+ * and its nilfs_root struct has been freed.
1116
+ */
1117
+ if (unlikely(nilfs_purging(nilfs)))
1118
+ return 0;
1119
+
10911120 err = nilfs_load_inode_block(inode, &ibh);
10921121 if (unlikely(err)) {
10931122 nilfs_warn(inode->i_sb,