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-2006 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) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/kallsyms.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/gfs2_ondisk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "gfs2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "incore.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "glock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "log.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "lops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "meta_io.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "trans.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include "util.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include "trace_gfs2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static void gfs2_print_trans(struct gfs2_sbd *sdp, const struct gfs2_trans *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	fs_warn(sdp, "Transaction created at: %pSR\n", (void *)tr->tr_ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	fs_warn(sdp, "blocks=%u revokes=%u reserved=%u touched=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		tr->tr_blocks, tr->tr_revokes, tr->tr_reserved,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		test_bit(TR_TOUCHED, &tr->tr_flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	fs_warn(sdp, "Buf %u/%u Databuf %u/%u Revoke %u/%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		tr->tr_num_buf_new, tr->tr_num_buf_rm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		tr->tr_num_databuf_new, tr->tr_num_databuf_rm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		tr->tr_num_revoke, tr->tr_num_revoke_rm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) int gfs2_trans_begin(struct gfs2_sbd *sdp, unsigned int blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		     unsigned int revokes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	struct gfs2_trans *tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	if (current->journal_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		gfs2_print_trans(sdp, current->journal_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	BUG_ON(blocks == 0 && revokes == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		return -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	tr = kmem_cache_zalloc(gfs2_trans_cachep, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (!tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	tr->tr_ip = _RET_IP_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	tr->tr_blocks = blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	tr->tr_revokes = revokes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	tr->tr_reserved = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	set_bit(TR_ALLOCED, &tr->tr_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		tr->tr_reserved += 6 + blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (revokes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		tr->tr_reserved += gfs2_struct2blk(sdp, revokes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	INIT_LIST_HEAD(&tr->tr_databuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	INIT_LIST_HEAD(&tr->tr_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	INIT_LIST_HEAD(&tr->tr_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	INIT_LIST_HEAD(&tr->tr_ail1_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	INIT_LIST_HEAD(&tr->tr_ail2_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	sb_start_intwrite(sdp->sd_vfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	error = gfs2_log_reserve(sdp, tr->tr_reserved);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	current->journal_info = tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	sb_end_intwrite(sdp->sd_vfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	kmem_cache_free(gfs2_trans_cachep, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return error;
^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) void gfs2_trans_end(struct gfs2_sbd *sdp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct gfs2_trans *tr = current->journal_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	s64 nbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	int alloced = test_bit(TR_ALLOCED, &tr->tr_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	current->journal_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (!test_bit(TR_TOUCHED, &tr->tr_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		gfs2_log_release(sdp, tr->tr_reserved);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		if (alloced) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			gfs2_trans_free(sdp, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			sb_end_intwrite(sdp->sd_vfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	nbuf = tr->tr_num_buf_new + tr->tr_num_databuf_new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	nbuf -= tr->tr_num_buf_rm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	nbuf -= tr->tr_num_databuf_rm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (gfs2_assert_withdraw(sdp, (nbuf <= tr->tr_blocks) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 				       (tr->tr_num_revoke <= tr->tr_revokes)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		gfs2_print_trans(sdp, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	gfs2_log_commit(sdp, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (alloced && !test_bit(TR_ATTACHED, &tr->tr_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		gfs2_trans_free(sdp, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	up_read(&sdp->sd_log_flush_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (sdp->sd_vfs->s_flags & SB_SYNCHRONOUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			       GFS2_LFC_TRANS_END);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (alloced)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		sb_end_intwrite(sdp->sd_vfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static struct gfs2_bufdata *gfs2_alloc_bufdata(struct gfs2_glock *gl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 					       struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	struct gfs2_bufdata *bd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	bd = kmem_cache_zalloc(gfs2_bufdata_cachep, GFP_NOFS | __GFP_NOFAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	bd->bd_bh = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	bd->bd_gl = gl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	INIT_LIST_HEAD(&bd->bd_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	INIT_LIST_HEAD(&bd->bd_ail_st_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	INIT_LIST_HEAD(&bd->bd_ail_gl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	bh->b_private = bd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	return bd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * gfs2_trans_add_data - Add a databuf to the transaction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * @gl: The inode glock associated with the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * @bh: The buffer to add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  * This is used in journaled data mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  * We need to journal the data block in the same way as metadata in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  * the functions above. The difference is that here we have a tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  * which is two __be64's being the block number (as per meta data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  * and a flag which says whether the data block needs escaping or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  * not. This means we need a new log entry for each 251 or so data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  * blocks, which isn't an enormous overhead but twice as much as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  * for normal metadata blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) void gfs2_trans_add_data(struct gfs2_glock *gl, struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	struct gfs2_trans *tr = current->journal_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct gfs2_bufdata *bd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	lock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (buffer_pinned(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		set_bit(TR_TOUCHED, &tr->tr_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	gfs2_log_lock(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	bd = bh->b_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (bd == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		gfs2_log_unlock(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		if (bh->b_private == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			bd = gfs2_alloc_bufdata(gl, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			bd = bh->b_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		lock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		gfs2_log_lock(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	gfs2_assert(sdp, bd->bd_gl == gl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	set_bit(TR_TOUCHED, &tr->tr_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (list_empty(&bd->bd_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		set_bit(GLF_LFLUSH, &bd->bd_gl->gl_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		set_bit(GLF_DIRTY, &bd->bd_gl->gl_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		gfs2_pin(sdp, bd->bd_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		tr->tr_num_databuf_new++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		list_add_tail(&bd->bd_list, &tr->tr_databuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	gfs2_log_unlock(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) void gfs2_trans_add_meta(struct gfs2_glock *gl, struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	struct gfs2_bufdata *bd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	struct gfs2_meta_header *mh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	struct gfs2_trans *tr = current->journal_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	enum gfs2_freeze_state state = atomic_read(&sdp->sd_freeze_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	lock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (buffer_pinned(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		set_bit(TR_TOUCHED, &tr->tr_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	gfs2_log_lock(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	bd = bh->b_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (bd == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		gfs2_log_unlock(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		lock_page(bh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		if (bh->b_private == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			bd = gfs2_alloc_bufdata(gl, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			bd = bh->b_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		unlock_page(bh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		lock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		gfs2_log_lock(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	gfs2_assert(sdp, bd->bd_gl == gl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	set_bit(TR_TOUCHED, &tr->tr_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	if (!list_empty(&bd->bd_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	set_bit(GLF_LFLUSH, &bd->bd_gl->gl_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	set_bit(GLF_DIRTY, &bd->bd_gl->gl_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	mh = (struct gfs2_meta_header *)bd->bd_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (unlikely(mh->mh_magic != cpu_to_be32(GFS2_MAGIC))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		fs_err(sdp, "Attempting to add uninitialised block to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		       "journal (inplace block=%lld)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		       (unsigned long long)bd->bd_bh->b_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if (unlikely(state == SFS_FROZEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		fs_info(sdp, "GFS2:adding buf while frozen\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		gfs2_assert_withdraw(sdp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	if (unlikely(gfs2_withdrawn(sdp))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		fs_info(sdp, "GFS2:adding buf while withdrawn! 0x%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			(unsigned long long)bd->bd_bh->b_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	gfs2_pin(sdp, bd->bd_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	mh->__pad0 = cpu_to_be64(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	mh->mh_jid = cpu_to_be32(sdp->sd_jdesc->jd_jid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	list_add(&bd->bd_list, &tr->tr_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	tr->tr_num_buf_new++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	gfs2_log_unlock(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	struct gfs2_trans *tr = current->journal_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	BUG_ON(!list_empty(&bd->bd_list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	gfs2_add_revoke(sdp, bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	set_bit(TR_TOUCHED, &tr->tr_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	tr->tr_num_revoke++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) void gfs2_trans_remove_revoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	struct gfs2_bufdata *bd, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	struct gfs2_trans *tr = current->journal_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	unsigned int n = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	gfs2_log_lock(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	list_for_each_entry_safe(bd, tmp, &sdp->sd_log_revokes, bd_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		if ((bd->bd_blkno >= blkno) && (bd->bd_blkno < (blkno + len))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			list_del_init(&bd->bd_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			gfs2_assert_withdraw(sdp, sdp->sd_log_num_revoke);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			sdp->sd_log_num_revoke--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			if (bd->bd_gl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 				gfs2_glock_remove_revoke(bd->bd_gl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			kmem_cache_free(gfs2_bufdata_cachep, bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			tr->tr_num_revoke_rm++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			if (--n == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 				break;
^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) 	gfs2_log_unlock(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) void gfs2_trans_free(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (tr == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	gfs2_assert_warn(sdp, list_empty(&tr->tr_ail1_list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	gfs2_assert_warn(sdp, list_empty(&tr->tr_ail2_list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	gfs2_assert_warn(sdp, list_empty(&tr->tr_databuf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	gfs2_assert_warn(sdp, list_empty(&tr->tr_buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	kmem_cache_free(gfs2_trans_cachep, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }