forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 958e46acc8e900e8569dd467c1af9b8d2d019394
kernel/fs/nilfs2/segment.c
....@@ -158,7 +158,7 @@
158158 * it is saved and will be restored on
159159 * nilfs_transaction_commit().
160160 */
161
- nilfs_msg(sb, KERN_WARNING, "journal info from a different FS");
161
+ nilfs_warn(sb, "journal info from a different FS");
162162 save = current->journal_info;
163163 }
164164 if (!ti) {
....@@ -322,7 +322,7 @@
322322 struct the_nilfs *nilfs = sb->s_fs_info;
323323 struct nilfs_sc_info *sci = nilfs->ns_writer;
324324
325
- if (!sci || !sci->sc_flush_request)
325
+ if (sb_rdonly(sb) || unlikely(!sci) || !sci->sc_flush_request)
326326 return;
327327
328328 set_bit(NILFS_SC_PRIOR_FLUSH, &sci->sc_flags);
....@@ -738,15 +738,18 @@
738738 struct list_head *listp)
739739 {
740740 struct nilfs_inode_info *ii = NILFS_I(inode);
741
- struct address_space *mapping = &ii->i_btnode_cache;
741
+ struct inode *btnc_inode = ii->i_assoc_inode;
742742 struct pagevec pvec;
743743 struct buffer_head *bh, *head;
744744 unsigned int i;
745745 pgoff_t index = 0;
746746
747
+ if (!btnc_inode)
748
+ return;
749
+
747750 pagevec_init(&pvec);
748751
749
- while (pagevec_lookup_tag(&pvec, mapping, &index,
752
+ while (pagevec_lookup_tag(&pvec, btnc_inode->i_mapping, &index,
750753 PAGECACHE_TAG_DIRTY)) {
751754 for (i = 0; i < pagevec_count(&pvec); i++) {
752755 bh = head = page_buffers(pvec.pages[i]);
....@@ -877,9 +880,11 @@
877880 nilfs_mdt_mark_dirty(nilfs->ns_cpfile);
878881 nilfs_cpfile_put_checkpoint(
879882 nilfs->ns_cpfile, nilfs->ns_cno, bh_cp);
880
- } else
881
- WARN_ON(err == -EINVAL || err == -ENOENT);
882
-
883
+ } else if (err == -EINVAL || err == -ENOENT) {
884
+ nilfs_error(sci->sc_super,
885
+ "checkpoint creation failed due to metadata corruption.");
886
+ err = -EIO;
887
+ }
883888 return err;
884889 }
885890
....@@ -893,7 +898,11 @@
893898 err = nilfs_cpfile_get_checkpoint(nilfs->ns_cpfile, nilfs->ns_cno, 0,
894899 &raw_cp, &bh_cp);
895900 if (unlikely(err)) {
896
- WARN_ON(err == -EINVAL || err == -ENOENT);
901
+ if (err == -EINVAL || err == -ENOENT) {
902
+ nilfs_error(sci->sc_super,
903
+ "checkpoint finalization failed due to metadata corruption.");
904
+ err = -EIO;
905
+ }
897906 goto failed_ibh;
898907 }
899908 raw_cp->cp_snapshot_list.ssl_next = 0;
....@@ -1138,7 +1147,8 @@
11381147 nilfs_sc_cstage_set(sci, NILFS_ST_DAT);
11391148 goto dat_stage;
11401149 }
1141
- nilfs_sc_cstage_inc(sci); /* Fall through */
1150
+ nilfs_sc_cstage_inc(sci);
1151
+ fallthrough;
11421152 case NILFS_ST_GC:
11431153 if (nilfs_doing_gc()) {
11441154 head = &sci->sc_gc_inodes;
....@@ -1159,7 +1169,8 @@
11591169 }
11601170 sci->sc_stage.gc_inode_ptr = NULL;
11611171 }
1162
- nilfs_sc_cstage_inc(sci); /* Fall through */
1172
+ nilfs_sc_cstage_inc(sci);
1173
+ fallthrough;
11631174 case NILFS_ST_FILE:
11641175 head = &sci->sc_dirty_files;
11651176 ii = list_prepare_entry(sci->sc_stage.dirty_file_ptr, head,
....@@ -1186,7 +1197,7 @@
11861197 }
11871198 nilfs_sc_cstage_inc(sci);
11881199 sci->sc_stage.flags |= NILFS_CF_IFILE_STARTED;
1189
- /* Fall through */
1200
+ fallthrough;
11901201 case NILFS_ST_IFILE:
11911202 err = nilfs_segctor_scan_file(sci, sci->sc_root->ifile,
11921203 &nilfs_sc_file_ops);
....@@ -1197,13 +1208,14 @@
11971208 err = nilfs_segctor_create_checkpoint(sci);
11981209 if (unlikely(err))
11991210 break;
1200
- /* Fall through */
1211
+ fallthrough;
12011212 case NILFS_ST_CPFILE:
12021213 err = nilfs_segctor_scan_file(sci, nilfs->ns_cpfile,
12031214 &nilfs_sc_file_ops);
12041215 if (unlikely(err))
12051216 break;
1206
- nilfs_sc_cstage_inc(sci); /* Fall through */
1217
+ nilfs_sc_cstage_inc(sci);
1218
+ fallthrough;
12071219 case NILFS_ST_SUFILE:
12081220 err = nilfs_sufile_freev(nilfs->ns_sufile, sci->sc_freesegs,
12091221 sci->sc_nfreesegs, &ndone);
....@@ -1219,7 +1231,8 @@
12191231 &nilfs_sc_file_ops);
12201232 if (unlikely(err))
12211233 break;
1222
- nilfs_sc_cstage_inc(sci); /* Fall through */
1234
+ nilfs_sc_cstage_inc(sci);
1235
+ fallthrough;
12231236 case NILFS_ST_DAT:
12241237 dat_stage:
12251238 err = nilfs_segctor_scan_file(sci, nilfs->ns_dat,
....@@ -1230,7 +1243,8 @@
12301243 nilfs_sc_cstage_set(sci, NILFS_ST_DONE);
12311244 return 0;
12321245 }
1233
- nilfs_sc_cstage_inc(sci); /* Fall through */
1246
+ nilfs_sc_cstage_inc(sci);
1247
+ fallthrough;
12341248 case NILFS_ST_SR:
12351249 if (mode == SC_LSEG_SR) {
12361250 /* Appending a super root */
....@@ -1940,9 +1954,9 @@
19401954 err = nilfs_ifile_get_inode_block(
19411955 ifile, ii->vfs_inode.i_ino, &ibh);
19421956 if (unlikely(err)) {
1943
- nilfs_msg(sci->sc_super, KERN_WARNING,
1944
- "log writer: error %d getting inode block (ino=%lu)",
1945
- err, ii->vfs_inode.i_ino);
1957
+ nilfs_warn(sci->sc_super,
1958
+ "log writer: error %d getting inode block (ino=%lu)",
1959
+ err, ii->vfs_inode.i_ino);
19461960 return err;
19471961 }
19481962 spin_lock(&nilfs->ns_inode_lock);
....@@ -2234,7 +2248,7 @@
22342248 struct nilfs_transaction_info *ti;
22352249 int err;
22362250
2237
- if (!sci)
2251
+ if (sb_rdonly(sb) || unlikely(!sci))
22382252 return -EROFS;
22392253
22402254 /* A call inside transactions causes a deadlock. */
....@@ -2273,7 +2287,7 @@
22732287 struct nilfs_transaction_info ti;
22742288 int err = 0;
22752289
2276
- if (!sci)
2290
+ if (sb_rdonly(sb) || unlikely(!sci))
22772291 return -EROFS;
22782292
22792293 nilfs_transaction_lock(sb, &ti, 0);
....@@ -2410,7 +2424,7 @@
24102424 continue;
24112425 list_del_init(&ii->i_dirty);
24122426 truncate_inode_pages(&ii->vfs_inode.i_data, 0);
2413
- nilfs_btnode_cache_clear(&ii->i_btnode_cache);
2427
+ nilfs_btnode_cache_clear(ii->i_assoc_inode->i_mapping);
24142428 iput(&ii->vfs_inode);
24152429 }
24162430 }
....@@ -2449,7 +2463,7 @@
24492463 if (likely(!err))
24502464 break;
24512465
2452
- nilfs_msg(sb, KERN_WARNING, "error %d cleaning segments", err);
2466
+ nilfs_warn(sb, "error %d cleaning segments", err);
24532467 set_current_state(TASK_INTERRUPTIBLE);
24542468 schedule_timeout(sci->sc_interval);
24552469 }
....@@ -2457,9 +2471,9 @@
24572471 int ret = nilfs_discard_segments(nilfs, sci->sc_freesegs,
24582472 sci->sc_nfreesegs);
24592473 if (ret) {
2460
- nilfs_msg(sb, KERN_WARNING,
2461
- "error %d on discard request, turning discards off for the device",
2462
- ret);
2474
+ nilfs_warn(sb,
2475
+ "error %d on discard request, turning discards off for the device",
2476
+ ret);
24632477 nilfs_clear_opt(nilfs, DISCARD);
24642478 }
24652479 }
....@@ -2540,9 +2554,9 @@
25402554 /* start sync. */
25412555 sci->sc_task = current;
25422556 wake_up(&sci->sc_wait_task); /* for nilfs_segctor_start_thread() */
2543
- nilfs_msg(sci->sc_super, KERN_INFO,
2544
- "segctord starting. Construction interval = %lu seconds, CP frequency < %lu seconds",
2545
- sci->sc_interval / HZ, sci->sc_mjcp_freq / HZ);
2557
+ nilfs_info(sci->sc_super,
2558
+ "segctord starting. Construction interval = %lu seconds, CP frequency < %lu seconds",
2559
+ sci->sc_interval / HZ, sci->sc_mjcp_freq / HZ);
25462560
25472561 spin_lock(&sci->sc_state_lock);
25482562 loop:
....@@ -2616,8 +2630,8 @@
26162630 if (IS_ERR(t)) {
26172631 int err = PTR_ERR(t);
26182632
2619
- nilfs_msg(sci->sc_super, KERN_ERR,
2620
- "error %d creating segctord thread", err);
2633
+ nilfs_err(sci->sc_super, "error %d creating segctord thread",
2634
+ err);
26212635 return err;
26222636 }
26232637 wait_event(sci->sc_wait_task, sci->sc_task != NULL);
....@@ -2727,14 +2741,14 @@
27272741 nilfs_segctor_write_out(sci);
27282742
27292743 if (!list_empty(&sci->sc_dirty_files)) {
2730
- nilfs_msg(sci->sc_super, KERN_WARNING,
2731
- "disposed unprocessed dirty file(s) when stopping log writer");
2744
+ nilfs_warn(sci->sc_super,
2745
+ "disposed unprocessed dirty file(s) when stopping log writer");
27322746 nilfs_dispose_list(nilfs, &sci->sc_dirty_files, 1);
27332747 }
27342748
27352749 if (!list_empty(&sci->sc_iput_queue)) {
2736
- nilfs_msg(sci->sc_super, KERN_WARNING,
2737
- "disposed unprocessed inode(s) in iput queue when stopping log writer");
2750
+ nilfs_warn(sci->sc_super,
2751
+ "disposed unprocessed inode(s) in iput queue when stopping log writer");
27382752 nilfs_dispose_list(nilfs, &sci->sc_iput_queue, 1);
27392753 }
27402754
....@@ -2769,11 +2783,12 @@
27692783
27702784 if (nilfs->ns_writer) {
27712785 /*
2772
- * This happens if the filesystem was remounted
2773
- * read/write after nilfs_error degenerated it into a
2774
- * read-only mount.
2786
+ * This happens if the filesystem is made read-only by
2787
+ * __nilfs_error or nilfs_remount and then remounted
2788
+ * read/write. In these cases, reuse the existing
2789
+ * writer.
27752790 */
2776
- nilfs_detach_log_writer(sb);
2791
+ return 0;
27772792 }
27782793
27792794 nilfs->ns_writer = nilfs_segctor_new(sb, root);
....@@ -2783,10 +2798,9 @@
27832798 inode_attach_wb(nilfs->ns_bdev->bd_inode, NULL);
27842799
27852800 err = nilfs_segctor_start_thread(nilfs->ns_writer);
2786
- if (err) {
2787
- kfree(nilfs->ns_writer);
2788
- nilfs->ns_writer = NULL;
2789
- }
2801
+ if (unlikely(err))
2802
+ nilfs_detach_log_writer(sb);
2803
+
27902804 return err;
27912805 }
27922806
....@@ -2812,8 +2826,8 @@
28122826 spin_lock(&nilfs->ns_inode_lock);
28132827 if (!list_empty(&nilfs->ns_dirty_files)) {
28142828 list_splice_init(&nilfs->ns_dirty_files, &garbage_list);
2815
- nilfs_msg(sb, KERN_WARNING,
2816
- "disposed unprocessed dirty file(s) when detaching log writer");
2829
+ nilfs_warn(sb,
2830
+ "disposed unprocessed dirty file(s) when detaching log writer");
28172831 }
28182832 spin_unlock(&nilfs->ns_inode_lock);
28192833 up_write(&nilfs->ns_segctor_sem);