1925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason/* 2925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason * Copyright (C) 2008 Oracle. All rights reserved. 3925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason * 4925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason * This program is free software; you can redistribute it and/or 5925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason * modify it under the terms of the GNU General Public 6925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason * License v2 as published by the Free Software Foundation. 7925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason * 8925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason * This program is distributed in the hope that it will be useful, 9925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason * but WITHOUT ANY WARRANTY; without even the implied warranty of 10925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason * General Public License for more details. 12925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason * 13925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason * You should have received a copy of the GNU General Public 14925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason * License along with this program; if not, write to the 15925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason * Boston, MA 021110-1307, USA. 17925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason */ 18925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason 19925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason#ifndef __BTRFS_LOCKING_ 20925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason#define __BTRFS_LOCKING_ 21925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason 22bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason#define BTRFS_WRITE_LOCK 1 23bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason#define BTRFS_READ_LOCK 2 24bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason#define BTRFS_WRITE_LOCK_BLOCKING 3 25bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason#define BTRFS_READ_LOCK_BLOCKING 4 26bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason 27143bede527b054a271053f41bfaca2b57baa9408Jeff Mahoneyvoid btrfs_tree_lock(struct extent_buffer *eb); 28143bede527b054a271053f41bfaca2b57baa9408Jeff Mahoneyvoid btrfs_tree_unlock(struct extent_buffer *eb); 29b4ce94de9b4d64e8ab3cf155d13653c666e22b9bChris Mason 30bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Masonvoid btrfs_tree_read_lock(struct extent_buffer *eb); 31bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Masonvoid btrfs_tree_read_unlock(struct extent_buffer *eb); 32bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Masonvoid btrfs_tree_read_unlock_blocking(struct extent_buffer *eb); 33bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Masonvoid btrfs_set_lock_blocking_rw(struct extent_buffer *eb, int rw); 34bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Masonvoid btrfs_clear_lock_blocking_rw(struct extent_buffer *eb, int rw); 35b9447ef80bd301b932ac4d85c9622e929de5fd62Chris Masonvoid btrfs_assert_tree_locked(struct extent_buffer *eb); 36bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Masonint btrfs_try_tree_read_lock(struct extent_buffer *eb); 37bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Masonint btrfs_try_tree_write_lock(struct extent_buffer *eb); 38f82c458a2c3ffb94b431fc6ad791a79df1b3713eChris Masonint btrfs_tree_read_lock_atomic(struct extent_buffer *eb); 39f82c458a2c3ffb94b431fc6ad791a79df1b3713eChris Mason 40bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason 41bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Masonstatic inline void btrfs_tree_unlock_rw(struct extent_buffer *eb, int rw) 42bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason{ 43bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason if (rw == BTRFS_WRITE_LOCK || rw == BTRFS_WRITE_LOCK_BLOCKING) 44bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason btrfs_tree_unlock(eb); 45bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason else if (rw == BTRFS_READ_LOCK_BLOCKING) 46bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason btrfs_tree_read_unlock_blocking(eb); 47bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason else if (rw == BTRFS_READ_LOCK) 48bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason btrfs_tree_read_unlock(eb); 49bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason else 50bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason BUG(); 51bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason} 52bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason 53bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Masonstatic inline void btrfs_set_lock_blocking(struct extent_buffer *eb) 54bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason{ 55bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason btrfs_set_lock_blocking_rw(eb, BTRFS_WRITE_LOCK); 56bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason} 57bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason 58bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Masonstatic inline void btrfs_clear_lock_blocking(struct extent_buffer *eb) 59bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason{ 60bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason btrfs_clear_lock_blocking_rw(eb, BTRFS_WRITE_LOCK_BLOCKING); 61bd681513fa6f2ff29aa391f01e413a2d1c59fd77Chris Mason} 62925baeddc5b0764a53f2214a1253251bab0e0324Chris Mason#endif 63