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+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * btnode.c - NILFS B-tree node cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Originally written by Seiji Kihara.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Fully revised by Ryusuke Konishi for stabilization and simplification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/types.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/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/backing-dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "nilfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "mdt.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "dat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "page.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "btnode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) void nilfs_btnode_cache_clear(struct address_space *btnc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	invalidate_mapping_pages(btnc, 0, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	truncate_inode_pages(btnc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) struct buffer_head *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) nilfs_btnode_create_block(struct address_space *btnc, __u64 blocknr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct inode *inode = NILFS_BTNC_I(btnc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	bh = nilfs_grab_buffer(inode, btnc, blocknr, BIT(BH_NILFS_Node));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	if (unlikely(!bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (unlikely(buffer_mapped(bh) || buffer_uptodate(bh) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		     buffer_dirty(bh))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	memset(bh->b_data, 0, i_blocksize(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	bh->b_bdev = inode->i_sb->s_bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	bh->b_blocknr = blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	set_buffer_mapped(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	set_buffer_uptodate(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	unlock_page(bh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	put_page(bh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	return bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) int nilfs_btnode_submit_block(struct address_space *btnc, __u64 blocknr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			      sector_t pblocknr, int mode, int mode_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			      struct buffer_head **pbh, sector_t *submit_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct inode *inode = NILFS_BTNC_I(btnc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	bh = nilfs_grab_buffer(inode, btnc, blocknr, BIT(BH_NILFS_Node));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (unlikely(!bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	err = -EEXIST; /* internal code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	page = bh->b_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (buffer_uptodate(bh) || buffer_dirty(bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (pblocknr == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		pblocknr = blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		if (inode->i_ino != NILFS_DAT_INO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			/* blocknr is a virtual block number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			err = nilfs_dat_translate(nilfs->ns_dat, blocknr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 						  &pblocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			if (unlikely(err)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 				brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 				goto out_locked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (mode_flags & REQ_RAHEAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		if (pblocknr != *submit_ptr + 1 || !trylock_buffer(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			err = -EBUSY; /* internal code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			goto out_locked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	} else { /* mode == READ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		lock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (buffer_uptodate(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		err = -EEXIST; /* internal code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	set_buffer_mapped(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	bh->b_bdev = inode->i_sb->s_bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	bh->b_blocknr = pblocknr; /* set block address for read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	bh->b_end_io = end_buffer_read_sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	get_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	submit_bh(mode, mode_flags, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	bh->b_blocknr = blocknr; /* set back to the given block address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	*submit_ptr = pblocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	*pbh = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) out_locked:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * nilfs_btnode_delete - delete B-tree node buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * @bh: buffer to be deleted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * nilfs_btnode_delete() invalidates the specified buffer and delete the page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * including the buffer if the page gets unbusy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) void nilfs_btnode_delete(struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	struct address_space *mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	struct page *page = bh->b_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	pgoff_t index = page_index(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	int still_dirty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	get_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	lock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	wait_on_page_writeback(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	nilfs_forget_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	still_dirty = PageDirty(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	mapping = page->mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (!still_dirty && mapping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		invalidate_inode_pages2_range(mapping, index, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  * nilfs_btnode_prepare_change_key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  *  prepare to move contents of the block for old key to one of new key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  *  the old buffer will not be removed, but might be reused for new buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  *  it might return -ENOMEM because of memory allocation errors,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  *  and might return -EIO because of disk read errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) int nilfs_btnode_prepare_change_key(struct address_space *btnc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 				    struct nilfs_btnode_chkey_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	struct buffer_head *obh, *nbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct inode *inode = NILFS_BTNC_I(btnc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	__u64 oldkey = ctxt->oldkey, newkey = ctxt->newkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (oldkey == newkey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	obh = ctxt->bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	ctxt->newbh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (inode->i_blkbits == PAGE_SHIFT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		struct page *opage = obh->b_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		lock_page(opage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		/* BUG_ON(oldkey != obh->b_page->index); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		if (unlikely(oldkey != opage->index))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			NILFS_PAGE_BUG(opage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 				       "invalid oldkey %lld (newkey=%lld)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 				       (unsigned long long)oldkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 				       (unsigned long long)newkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		xa_lock_irq(&btnc->i_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		err = __xa_insert(&btnc->i_pages, newkey, opage, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		xa_unlock_irq(&btnc->i_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		 * Note: page->index will not change to newkey until
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		 * nilfs_btnode_commit_change_key() will be called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		 * To protect the page in intermediate state, the page lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		 * is held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		else if (err != -EBUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			goto failed_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		err = invalidate_inode_pages2_range(btnc, newkey, newkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		/* fallback to copy mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		unlock_page(opage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	nbh = nilfs_btnode_create_block(btnc, newkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (!nbh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	BUG_ON(nbh == obh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	ctxt->newbh = nbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  failed_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	unlock_page(obh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  * nilfs_btnode_commit_change_key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  *  commit the change_key operation prepared by prepare_change_key().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) void nilfs_btnode_commit_change_key(struct address_space *btnc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 				    struct nilfs_btnode_chkey_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct buffer_head *obh = ctxt->bh, *nbh = ctxt->newbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	__u64 oldkey = ctxt->oldkey, newkey = ctxt->newkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	struct page *opage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (oldkey == newkey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (nbh == NULL) {	/* blocksize == pagesize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		opage = obh->b_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		if (unlikely(oldkey != opage->index))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			NILFS_PAGE_BUG(opage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 				       "invalid oldkey %lld (newkey=%lld)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 				       (unsigned long long)oldkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 				       (unsigned long long)newkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		mark_buffer_dirty(obh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		xa_lock_irq(&btnc->i_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		__xa_erase(&btnc->i_pages, oldkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		__xa_set_mark(&btnc->i_pages, newkey, PAGECACHE_TAG_DIRTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		xa_unlock_irq(&btnc->i_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		opage->index = obh->b_blocknr = newkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		unlock_page(opage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		nilfs_copy_buffer(nbh, obh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		mark_buffer_dirty(nbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		nbh->b_blocknr = newkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		ctxt->bh = nbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		nilfs_btnode_delete(obh); /* will decrement bh->b_count */
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  * nilfs_btnode_abort_change_key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  *  abort the change_key operation prepared by prepare_change_key().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) void nilfs_btnode_abort_change_key(struct address_space *btnc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 				   struct nilfs_btnode_chkey_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	struct buffer_head *nbh = ctxt->newbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	__u64 oldkey = ctxt->oldkey, newkey = ctxt->newkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (oldkey == newkey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (nbh == NULL) {	/* blocksize == pagesize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		xa_erase_irq(&btnc->i_pages, newkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		unlock_page(ctxt->bh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		brelse(nbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }