Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2004-2008 Red Hat, Inc.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/writeback.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/swap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/bio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/gfs2_ondisk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "gfs2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "incore.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "glock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "glops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include "log.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include "lops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include "meta_io.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include "rgrp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include "trans.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include "util.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include "trace_gfs2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static int gfs2_aspace_writepage(struct page *page, struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct buffer_head *bh, *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	int nr_underway = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int write_flags = REQ_META | REQ_PRIO | wbc_to_write_flags(wbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	BUG_ON(!PageLocked(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	BUG_ON(!page_has_buffers(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	head = page_buffers(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	bh = head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		if (!buffer_mapped(bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		 * If it's a fully non-blocking write attempt and we cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		 * lock the buffer then redirty the page.  Note that this can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		 * potentially cause a busy-wait loop from flusher thread and kswapd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		 * activity, but those code paths have their own higher-level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		 * throttling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		if (wbc->sync_mode != WB_SYNC_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			lock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		} else if (!trylock_buffer(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			redirty_page_for_writepage(wbc, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		if (test_clear_buffer_dirty(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			mark_buffer_async_write(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	} while ((bh = bh->b_this_page) != head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	 * The page and its buffers are protected by PageWriteback(), so we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	 * drop the bh refcounts early.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	BUG_ON(PageWriteback(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	set_page_writeback(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		struct buffer_head *next = bh->b_this_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		if (buffer_async_write(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			submit_bh(REQ_OP_WRITE, write_flags, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			nr_underway++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		bh = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	} while (bh != head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (nr_underway == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		end_page_writeback(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) const struct address_space_operations gfs2_meta_aops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	.writepage = gfs2_aspace_writepage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	.releasepage = gfs2_releasepage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) const struct address_space_operations gfs2_rgrp_aops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	.writepage = gfs2_aspace_writepage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	.releasepage = gfs2_releasepage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * gfs2_getbuf - Get a buffer with a given address space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * @gl: the glock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * @blkno: the block number (filesystem scope)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  * @create: 1 if the buffer should be created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * Returns: the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct buffer_head *gfs2_getbuf(struct gfs2_glock *gl, u64 blkno, int create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct address_space *mapping = gfs2_glock2aspace(gl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	unsigned int shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	unsigned long index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	unsigned int bufnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (mapping == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		mapping = &sdp->sd_aspace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	shift = PAGE_SHIFT - sdp->sd_sb.sb_bsize_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	index = blkno >> shift;             /* convert block to page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	bufnum = blkno - (index << shift);  /* block buf index within page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (create) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			page = grab_cache_page(mapping, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			if (page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			yield();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		page = find_get_page_flags(mapping, index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 						FGP_LOCK|FGP_ACCESSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		if (!page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (!page_has_buffers(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		create_empty_buffers(page, sdp->sd_sb.sb_bsize, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	/* Locate header for our buffer within our page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	for (bh = page_buffers(page); bufnum--; bh = bh->b_this_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		/* Do nothing */;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	get_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (!buffer_mapped(bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		map_bh(bh, sdp->sd_vfs, blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static void meta_prep_new(struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	lock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	clear_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	set_buffer_uptodate(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	mh->mh_magic = cpu_to_be32(GFS2_MAGIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)  * gfs2_meta_new - Get a block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  * @gl: The glock associated with this block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  * @blkno: The block number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  * Returns: The buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, u64 blkno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	bh = gfs2_getbuf(gl, blkno, CREATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	meta_prep_new(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	return bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static void gfs2_meta_read_endio(struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	struct bio_vec *bvec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct bvec_iter_all iter_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	bio_for_each_segment_all(bvec, bio, iter_all) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		struct page *page = bvec->bv_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		struct buffer_head *bh = page_buffers(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		unsigned int len = bvec->bv_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		while (bh_offset(bh) < bvec->bv_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			bh = bh->b_this_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			struct buffer_head *next = bh->b_this_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			len -= bh->b_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			bh->b_end_io(bh, !bio->bi_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			bh = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		} while (bh && len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	bio_put(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  * Submit several consecutive buffer head I/O requests as a single bio I/O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  * request.  (See submit_bh_wbc.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static void gfs2_submit_bhs(int op, int op_flags, struct buffer_head *bhs[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			    int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	while (num > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		struct buffer_head *bh = *bhs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		bio = bio_alloc(GFP_NOIO, num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		bio_set_dev(bio, bh->b_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		while (num > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			bh = *bhs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			if (!bio_add_page(bio, bh->b_page, bh->b_size, bh_offset(bh))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 				BUG_ON(bio->bi_iter.bi_size == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			bhs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			num--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		bio->bi_end_io = gfs2_meta_read_endio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		bio_set_op_attrs(bio, op, op_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		submit_bio(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * gfs2_meta_read - Read a block from disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  * @gl: The glock covering the block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  * @blkno: The block number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  * @flags: flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)  * @bhp: the place where the buffer is returned (NULL on failure)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)  * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		   int rahead, struct buffer_head **bhp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	struct buffer_head *bh, *bhs[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	int num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (unlikely(gfs2_withdrawn(sdp)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	    (!sdp->sd_jdesc || gl != sdp->sd_jinode_gl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		*bhp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	*bhp = bh = gfs2_getbuf(gl, blkno, CREATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	lock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	if (buffer_uptodate(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		flags &= ~DIO_WAIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		bh->b_end_io = end_buffer_read_sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		get_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		bhs[num++] = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (rahead) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		bh = gfs2_getbuf(gl, blkno + 1, CREATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		lock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		if (buffer_uptodate(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			bh->b_end_io = end_buffer_read_sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			bhs[num++] = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	gfs2_submit_bhs(REQ_OP_READ, REQ_META | REQ_PRIO, bhs, num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	if (!(flags & DIO_WAIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	bh = *bhp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	wait_on_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (unlikely(!buffer_uptodate(bh))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		struct gfs2_trans *tr = current->journal_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		if (tr && test_bit(TR_TOUCHED, &tr->tr_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			gfs2_io_error_bh_wd(sdp, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		*bhp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  * gfs2_meta_wait - Reread a block from disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  * @sdp: the filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  * @bh: The block to wait for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) int gfs2_meta_wait(struct gfs2_sbd *sdp, struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	if (unlikely(gfs2_withdrawn(sdp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	wait_on_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	if (!buffer_uptodate(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		struct gfs2_trans *tr = current->journal_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		if (tr && test_bit(TR_TOUCHED, &tr->tr_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			gfs2_io_error_bh_wd(sdp, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	if (unlikely(gfs2_withdrawn(sdp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) void gfs2_remove_from_journal(struct buffer_head *bh, int meta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	struct address_space *mapping = bh->b_page->mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	struct gfs2_sbd *sdp = gfs2_mapping2sbd(mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	struct gfs2_bufdata *bd = bh->b_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	struct gfs2_trans *tr = current->journal_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	int was_pinned = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	if (test_clear_buffer_pinned(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		trace_gfs2_pin(bd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		atomic_dec(&sdp->sd_log_pinned);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		list_del_init(&bd->bd_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		if (meta == REMOVE_META)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			tr->tr_num_buf_rm++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			tr->tr_num_databuf_rm++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		set_bit(TR_TOUCHED, &tr->tr_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		was_pinned = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	if (bd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		if (bd->bd_tr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			gfs2_trans_add_revoke(sdp, bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		} else if (was_pinned) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			bh->b_private = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 			kmem_cache_free(gfs2_bufdata_cachep, bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		} else if (!list_empty(&bd->bd_ail_st_list) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 					!list_empty(&bd->bd_ail_gl_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			gfs2_remove_from_ail(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	clear_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	clear_buffer_uptodate(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)  * gfs2_ail1_wipe - remove deleted/freed buffers from the ail1 list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)  * @sdp: superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)  * @bstart: starting block address of buffers to remove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)  * @blen: length of buffers to be removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)  * This function is called from gfs2_journal wipe, whose job is to remove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)  * buffers, corresponding to deleted blocks, from the journal. If we find any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)  * bufdata elements on the system ail1 list, they haven't been written to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)  * the journal yet. So we remove them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) static void gfs2_ail1_wipe(struct gfs2_sbd *sdp, u64 bstart, u32 blen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	struct gfs2_trans *tr, *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	struct gfs2_bufdata *bd, *bs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	u64 end = bstart + blen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	gfs2_log_lock(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	spin_lock(&sdp->sd_ail_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	list_for_each_entry_safe(tr, s, &sdp->sd_ail1_list, tr_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		list_for_each_entry_safe(bd, bs, &tr->tr_ail1_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 					 bd_ail_st_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			bh = bd->bd_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 			if (bh->b_blocknr < bstart || bh->b_blocknr >= end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 			gfs2_remove_from_journal(bh, REMOVE_JDATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	spin_unlock(&sdp->sd_ail_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	gfs2_log_unlock(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) static struct buffer_head *gfs2_getjdatabuf(struct gfs2_inode *ip, u64 blkno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	struct address_space *mapping = ip->i_inode.i_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	unsigned int shift = PAGE_SHIFT - sdp->sd_sb.sb_bsize_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	unsigned long index = blkno >> shift; /* convert block to page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	unsigned int bufnum = blkno - (index << shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	page = find_get_page_flags(mapping, index, FGP_LOCK|FGP_ACCESSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	if (!page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	if (!page_has_buffers(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	/* Locate header for our buffer within our page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	for (bh = page_buffers(page); bufnum--; bh = bh->b_this_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		/* Do nothing */;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	get_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	return bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)  * gfs2_journal_wipe - make inode's buffers so they aren't dirty/pinned anymore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)  * @ip: the inode who owns the buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)  * @bstart: the first buffer in the run
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)  * @blen: the number of buffers in the run
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) void gfs2_journal_wipe(struct gfs2_inode *ip, u64 bstart, u32 blen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	int ty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	gfs2_ail1_wipe(sdp, bstart, blen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	while (blen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		ty = REMOVE_META;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		bh = gfs2_getbuf(ip->i_gl, bstart, NO_CREATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		if (!bh && gfs2_is_jdata(ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 			bh = gfs2_getjdatabuf(ip, bstart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 			ty = REMOVE_JDATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		if (bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 			lock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 			gfs2_log_lock(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 			spin_lock(&sdp->sd_ail_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 			gfs2_remove_from_journal(bh, ty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 			spin_unlock(&sdp->sd_ail_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 			gfs2_log_unlock(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 			unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 			brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		bstart++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		blen--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)  * gfs2_meta_indirect_buffer - Get a metadata buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)  * @ip: The GFS2 inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)  * @height: The level of this buf in the metadata (indir addr) tree (if any)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)  * @num: The block number (device relative) of the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)  * @bhp: the buffer is returned here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)  * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, u64 num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 			      struct buffer_head **bhp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	struct gfs2_glock *gl = ip->i_gl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	u32 mtype = height ? GFS2_METATYPE_IN : GFS2_METATYPE_DI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	int rahead = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	if (num == ip->i_no_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		rahead = ip->i_rahead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	ret = gfs2_meta_read(gl, num, DIO_WAIT, rahead, &bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	if (ret == 0 && gfs2_metatype_check(sdp, bh, mtype)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		*bhp = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)  * gfs2_meta_ra - start readahead on an extent of a file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)  * @gl: the glock the blocks belong to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)  * @dblock: the starting disk block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)  * @extlen: the number of blocks in the extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)  * returns: the first buffer in the extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct buffer_head *gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	struct buffer_head *first_bh, *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	u32 max_ra = gfs2_tune_get(sdp, gt_max_readahead) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 			  sdp->sd_sb.sb_bsize_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	BUG_ON(!extlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	if (max_ra < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		max_ra = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	if (extlen > max_ra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		extlen = max_ra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	first_bh = gfs2_getbuf(gl, dblock, CREATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	if (buffer_uptodate(first_bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	if (!buffer_locked(first_bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 		ll_rw_block(REQ_OP_READ, REQ_META | REQ_PRIO, 1, &first_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	dblock++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	extlen--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	while (extlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		bh = gfs2_getbuf(gl, dblock, CREATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		if (!buffer_uptodate(bh) && !buffer_locked(bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 			ll_rw_block(REQ_OP_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 				    REQ_RAHEAD | REQ_META | REQ_PRIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 				    1, &bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		dblock++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		extlen--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		if (!buffer_locked(first_bh) && buffer_uptodate(first_bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	wait_on_buffer(first_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	return first_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)