cregit-Linux how code gets into the kernel

Release 4.18 fs/nilfs2/btnode.c

Directory: fs/nilfs2
/*
 * btnode.c - NILFS B-tree node cache
 *
 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Originally written by Seiji Kihara.
 * Fully revised by Ryusuke Konishi for stabilization and simplification.
 *
 */

#include <linux/types.h>
#include <linux/buffer_head.h>
#include <linux/mm.h>
#include <linux/backing-dev.h>
#include <linux/gfp.h>
#include "nilfs.h"
#include "mdt.h"
#include "dat.h"
#include "page.h"
#include "btnode.h"


void nilfs_btnode_cache_clear(struct address_space *btnc) { invalidate_mapping_pages(btnc, 0, -1); truncate_inode_pages(btnc, 0); }

Contributors

PersonTokensPropCommitsCommitProp
Ryusuke Konishi27100.00%1100.00%
Total27100.00%1100.00%


struct buffer_head * nilfs_btnode_create_block(struct address_space *btnc, __u64 blocknr) { struct inode *inode = NILFS_BTNC_I(btnc); struct buffer_head *bh; bh = nilfs_grab_buffer(inode, btnc, blocknr, BIT(BH_NILFS_Node)); if (unlikely(!bh)) return NULL; if (unlikely(buffer_mapped(bh) || buffer_uptodate(bh) || buffer_dirty(bh))) { brelse(bh); BUG(); } memset(bh->b_data, 0, i_blocksize(inode)); bh->b_bdev = inode->i_sb->s_bdev; bh->b_blocknr = blocknr; set_buffer_mapped(bh); set_buffer_uptodate(bh); unlock_page(bh->b_page); put_page(bh->b_page); return bh; }

Contributors

PersonTokensPropCommitsCommitProp
Ryusuke Konishi14097.22%360.00%
Fabian Frederick32.08%120.00%
Kirill A. Shutemov10.69%120.00%
Total144100.00%5100.00%


int nilfs_btnode_submit_block(struct address_space *btnc, __u64 blocknr, sector_t pblocknr, int mode, int mode_flags, struct buffer_head **pbh, sector_t *submit_ptr) { struct buffer_head *bh; struct inode *inode = NILFS_BTNC_I(btnc); struct page *page; int err; bh = nilfs_grab_buffer(inode, btnc, blocknr, BIT(BH_NILFS_Node)); if (unlikely(!bh)) return -ENOMEM; err = -EEXIST; /* internal code */ page = bh->b_page; if (buffer_uptodate(bh) || buffer_dirty(bh)) goto found; if (pblocknr == 0) { pblocknr = blocknr; if (inode->i_ino != NILFS_DAT_INO) { struct the_nilfs *nilfs = inode->i_sb->s_fs_info; /* blocknr is a virtual block number */ err = nilfs_dat_translate(nilfs->ns_dat, blocknr, &pblocknr); if (unlikely(err)) { brelse(bh); goto out_locked; } } } if (mode_flags & REQ_RAHEAD) { if (pblocknr != *submit_ptr + 1 || !trylock_buffer(bh)) { err = -EBUSY; /* internal code */ brelse(bh); goto out_locked; } } else { /* mode == READ */ lock_buffer(bh); } if (buffer_uptodate(bh)) { unlock_buffer(bh); err = -EEXIST; /* internal code */ goto found; } set_buffer_mapped(bh); bh->b_bdev = inode->i_sb->s_bdev; bh->b_blocknr = pblocknr; /* set block address for read */ bh->b_end_io = end_buffer_read_sync; get_bh(bh); submit_bh(mode, mode_flags, bh); bh->b_blocknr = blocknr; /* set back to the given block address */ *submit_ptr = pblocknr; err = 0; found: *pbh = bh; out_locked: unlock_page(page); put_page(page); return err; }

Contributors

PersonTokensPropCommitsCommitProp
Ryusuke Konishi31797.24%675.00%
Michael Christie82.45%112.50%
Kirill A. Shutemov10.31%112.50%
Total326100.00%8100.00%

/** * nilfs_btnode_delete - delete B-tree node buffer * @bh: buffer to be deleted * * nilfs_btnode_delete() invalidates the specified buffer and delete the page * including the buffer if the page gets unbusy. */
void nilfs_btnode_delete(struct buffer_head *bh) { struct address_space *mapping; struct page *page = bh->b_page; pgoff_t index = page_index(page); int still_dirty; get_page(page); lock_page(page); wait_on_page_writeback(page); nilfs_forget_buffer(bh); still_dirty = PageDirty(page); mapping = page->mapping; unlock_page(page); put_page(page); if (!still_dirty && mapping) invalidate_inode_pages2_range(mapping, index, index); }

Contributors

PersonTokensPropCommitsCommitProp
Ryusuke Konishi9297.87%150.00%
Kirill A. Shutemov22.13%150.00%
Total94100.00%2100.00%

/** * nilfs_btnode_prepare_change_key * prepare to move contents of the block for old key to one of new key. * the old buffer will not be removed, but might be reused for new buffer. * it might return -ENOMEM because of memory allocation errors, * and might return -EIO because of disk read errors. */
int nilfs_btnode_prepare_change_key(struct address_space *btnc, struct nilfs_btnode_chkey_ctxt *ctxt) { struct buffer_head *obh, *nbh; struct inode *inode = NILFS_BTNC_I(btnc); __u64 oldkey = ctxt->oldkey, newkey = ctxt->newkey; int err; if (oldkey == newkey) return 0; obh = ctxt->bh; ctxt->newbh = NULL; if (inode->i_blkbits == PAGE_SHIFT) { lock_page(obh->b_page); /* * We cannot call radix_tree_preload for the kernels older * than 2.6.23, because it is not exported for modules. */ retry: err = radix_tree_preload(GFP_NOFS & ~__GFP_HIGHMEM); if (err) goto failed_unlock; /* BUG_ON(oldkey != obh->b_page->index); */ if (unlikely(oldkey != obh->b_page->index)) NILFS_PAGE_BUG(obh->b_page, "invalid oldkey %lld (newkey=%lld)", (unsigned long long)oldkey, (unsigned long long)newkey); xa_lock_irq(&btnc->i_pages); err = radix_tree_insert(&btnc->i_pages, newkey, obh->b_page); xa_unlock_irq(&btnc->i_pages); /* * Note: page->index will not change to newkey until * nilfs_btnode_commit_change_key() will be called. * To protect the page in intermediate state, the page lock * is held. */ radix_tree_preload_end(); if (!err) return 0; else if (err != -EEXIST) goto failed_unlock; err = invalidate_inode_pages2_range(btnc, newkey, newkey); if (!err) goto retry; /* fallback to copy mode */ unlock_page(obh->b_page); } nbh = nilfs_btnode_create_block(btnc, newkey); if (!nbh) return -ENOMEM; BUG_ON(nbh == obh); ctxt->newbh = nbh; return 0; failed_unlock: unlock_page(obh->b_page); return err; }

Contributors

PersonTokensPropCommitsCommitProp
Ryusuke Konishi26697.79%360.00%
Matthew Wilcox51.84%120.00%
Kirill A. Shutemov10.37%120.00%
Total272100.00%5100.00%

/** * nilfs_btnode_commit_change_key * commit the change_key operation prepared by prepare_change_key(). */
void nilfs_btnode_commit_change_key(struct address_space *btnc, struct nilfs_btnode_chkey_ctxt *ctxt) { struct buffer_head *obh = ctxt->bh, *nbh = ctxt->newbh; __u64 oldkey = ctxt->oldkey, newkey = ctxt->newkey; struct page *opage; if (oldkey == newkey) return; if (nbh == NULL) { /* blocksize == pagesize */ opage = obh->b_page; if (unlikely(oldkey != opage->index)) NILFS_PAGE_BUG(opage, "invalid oldkey %lld (newkey=%lld)", (unsigned long long)oldkey, (unsigned long long)newkey); mark_buffer_dirty(obh); xa_lock_irq(&btnc->i_pages); radix_tree_delete(&btnc->i_pages, oldkey); radix_tree_tag_set(&btnc->i_pages, newkey, PAGECACHE_TAG_DIRTY); xa_unlock_irq(&btnc->i_pages); opage->index = obh->b_blocknr = newkey; unlock_page(opage); } else { nilfs_copy_buffer(nbh, obh); mark_buffer_dirty(nbh); nbh->b_blocknr = newkey; ctxt->bh = nbh; nilfs_btnode_delete(obh); /* will decrement bh->b_count */ } }

Contributors

PersonTokensPropCommitsCommitProp
Ryusuke Konishi18896.91%266.67%
Matthew Wilcox63.09%133.33%
Total194100.00%3100.00%

/** * nilfs_btnode_abort_change_key * abort the change_key operation prepared by prepare_change_key(). */
void nilfs_btnode_abort_change_key(struct address_space *btnc, struct nilfs_btnode_chkey_ctxt *ctxt) { struct buffer_head *nbh = ctxt->newbh; __u64 oldkey = ctxt->oldkey, newkey = ctxt->newkey; if (oldkey == newkey) return; if (nbh == NULL) { /* blocksize == pagesize */ xa_lock_irq(&btnc->i_pages); radix_tree_delete(&btnc->i_pages, newkey); xa_unlock_irq(&btnc->i_pages); unlock_page(ctxt->bh->b_page); } else brelse(nbh); }

Contributors

PersonTokensPropCommitsCommitProp
Ryusuke Konishi8994.68%150.00%
Matthew Wilcox55.32%150.00%
Total94100.00%2100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Ryusuke Konishi115197.05%1168.75%
Matthew Wilcox161.35%16.25%
Michael Christie80.67%16.25%
Kirill A. Shutemov50.42%16.25%
Fabian Frederick30.25%16.25%
Tejun Heo30.25%16.25%
Total1186100.00%16100.00%
Directory: fs/nilfs2
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.