hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/gfs2/meta_io.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
34 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
4
- *
5
- * This copyrighted material is made available to anyone wishing to use,
6
- * modify, copy, or redistribute it subject to the terms and conditions
7
- * of the GNU General Public License version 2.
85 */
96
107 #include <linux/sched.h>
....@@ -189,9 +186,9 @@
189186 static void gfs2_meta_read_endio(struct bio *bio)
190187 {
191188 struct bio_vec *bvec;
192
- int i;
189
+ struct bvec_iter_all iter_all;
193190
194
- bio_for_each_segment_all(bvec, bio, i) {
191
+ bio_for_each_segment_all(bvec, bio, iter_all) {
195192 struct page *page = bvec->bv_page;
196193 struct buffer_head *bh = page_buffers(page);
197194 unsigned int len = bvec->bv_len;
....@@ -254,7 +251,8 @@
254251 struct buffer_head *bh, *bhs[2];
255252 int num = 0;
256253
257
- if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) {
254
+ if (unlikely(gfs2_withdrawn(sdp)) &&
255
+ (!sdp->sd_jdesc || gl != sdp->sd_jinode_gl)) {
258256 *bhp = NULL;
259257 return -EIO;
260258 }
....@@ -312,7 +310,7 @@
312310
313311 int gfs2_meta_wait(struct gfs2_sbd *sdp, struct buffer_head *bh)
314312 {
315
- if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
313
+ if (unlikely(gfs2_withdrawn(sdp)))
316314 return -EIO;
317315
318316 wait_on_buffer(bh);
....@@ -323,7 +321,7 @@
323321 gfs2_io_error_bh_wd(sdp, bh);
324322 return -EIO;
325323 }
326
- if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
324
+ if (unlikely(gfs2_withdrawn(sdp)))
327325 return -EIO;
328326
329327 return 0;
....@@ -350,38 +348,109 @@
350348 brelse(bh);
351349 }
352350 if (bd) {
353
- spin_lock(&sdp->sd_ail_lock);
354351 if (bd->bd_tr) {
355352 gfs2_trans_add_revoke(sdp, bd);
356353 } else if (was_pinned) {
357354 bh->b_private = NULL;
358355 kmem_cache_free(gfs2_bufdata_cachep, bd);
356
+ } else if (!list_empty(&bd->bd_ail_st_list) &&
357
+ !list_empty(&bd->bd_ail_gl_list)) {
358
+ gfs2_remove_from_ail(bd);
359359 }
360
- spin_unlock(&sdp->sd_ail_lock);
361360 }
362361 clear_buffer_dirty(bh);
363362 clear_buffer_uptodate(bh);
364363 }
365364
366365 /**
367
- * gfs2_meta_wipe - make inode's buffers so they aren't dirty/pinned anymore
366
+ * gfs2_ail1_wipe - remove deleted/freed buffers from the ail1 list
367
+ * @sdp: superblock
368
+ * @bstart: starting block address of buffers to remove
369
+ * @blen: length of buffers to be removed
370
+ *
371
+ * This function is called from gfs2_journal wipe, whose job is to remove
372
+ * buffers, corresponding to deleted blocks, from the journal. If we find any
373
+ * bufdata elements on the system ail1 list, they haven't been written to
374
+ * the journal yet. So we remove them.
375
+ */
376
+static void gfs2_ail1_wipe(struct gfs2_sbd *sdp, u64 bstart, u32 blen)
377
+{
378
+ struct gfs2_trans *tr, *s;
379
+ struct gfs2_bufdata *bd, *bs;
380
+ struct buffer_head *bh;
381
+ u64 end = bstart + blen;
382
+
383
+ gfs2_log_lock(sdp);
384
+ spin_lock(&sdp->sd_ail_lock);
385
+ list_for_each_entry_safe(tr, s, &sdp->sd_ail1_list, tr_list) {
386
+ list_for_each_entry_safe(bd, bs, &tr->tr_ail1_list,
387
+ bd_ail_st_list) {
388
+ bh = bd->bd_bh;
389
+ if (bh->b_blocknr < bstart || bh->b_blocknr >= end)
390
+ continue;
391
+
392
+ gfs2_remove_from_journal(bh, REMOVE_JDATA);
393
+ }
394
+ }
395
+ spin_unlock(&sdp->sd_ail_lock);
396
+ gfs2_log_unlock(sdp);
397
+}
398
+
399
+static struct buffer_head *gfs2_getjdatabuf(struct gfs2_inode *ip, u64 blkno)
400
+{
401
+ struct address_space *mapping = ip->i_inode.i_mapping;
402
+ struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
403
+ struct page *page;
404
+ struct buffer_head *bh;
405
+ unsigned int shift = PAGE_SHIFT - sdp->sd_sb.sb_bsize_shift;
406
+ unsigned long index = blkno >> shift; /* convert block to page */
407
+ unsigned int bufnum = blkno - (index << shift);
408
+
409
+ page = find_get_page_flags(mapping, index, FGP_LOCK|FGP_ACCESSED);
410
+ if (!page)
411
+ return NULL;
412
+ if (!page_has_buffers(page)) {
413
+ unlock_page(page);
414
+ put_page(page);
415
+ return NULL;
416
+ }
417
+ /* Locate header for our buffer within our page */
418
+ for (bh = page_buffers(page); bufnum--; bh = bh->b_this_page)
419
+ /* Do nothing */;
420
+ get_bh(bh);
421
+ unlock_page(page);
422
+ put_page(page);
423
+ return bh;
424
+}
425
+
426
+/**
427
+ * gfs2_journal_wipe - make inode's buffers so they aren't dirty/pinned anymore
368428 * @ip: the inode who owns the buffers
369429 * @bstart: the first buffer in the run
370430 * @blen: the number of buffers in the run
371431 *
372432 */
373433
374
-void gfs2_meta_wipe(struct gfs2_inode *ip, u64 bstart, u32 blen)
434
+void gfs2_journal_wipe(struct gfs2_inode *ip, u64 bstart, u32 blen)
375435 {
376436 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
377437 struct buffer_head *bh;
438
+ int ty;
378439
440
+ gfs2_ail1_wipe(sdp, bstart, blen);
379441 while (blen) {
442
+ ty = REMOVE_META;
380443 bh = gfs2_getbuf(ip->i_gl, bstart, NO_CREATE);
444
+ if (!bh && gfs2_is_jdata(ip)) {
445
+ bh = gfs2_getjdatabuf(ip, bstart);
446
+ ty = REMOVE_JDATA;
447
+ }
381448 if (bh) {
382449 lock_buffer(bh);
383450 gfs2_log_lock(sdp);
384
- gfs2_remove_from_journal(bh, REMOVE_META);
451
+ spin_lock(&sdp->sd_ail_lock);
452
+ gfs2_remove_from_journal(bh, ty);
453
+ spin_unlock(&sdp->sd_ail_lock);
385454 gfs2_log_unlock(sdp);
386455 unlock_buffer(bh);
387456 brelse(bh);