blob: 595014f64830f822d6d9135641e528353fdfe4f3 [file] [log] [blame]
David Sterba9888c342018-04-03 19:16:55 +02001/* SPDX-License-Identifier: GPL-2.0 */
Chris Mason925baed2008-06-25 16:01:30 -04002/*
3 * Copyright (C) 2008 Oracle. All rights reserved.
Chris Mason925baed2008-06-25 16:01:30 -04004 */
5
David Sterba9888c342018-04-03 19:16:55 +02006#ifndef BTRFS_LOCKING_H
7#define BTRFS_LOCKING_H
Chris Mason925baed2008-06-25 16:01:30 -04008
Chris Masonbd681512011-07-16 15:23:14 -04009#define BTRFS_WRITE_LOCK 1
10#define BTRFS_READ_LOCK 2
11#define BTRFS_WRITE_LOCK_BLOCKING 3
12#define BTRFS_READ_LOCK_BLOCKING 4
13
Jeff Mahoney143bede2012-03-01 14:56:26 +010014void btrfs_tree_lock(struct extent_buffer *eb);
15void btrfs_tree_unlock(struct extent_buffer *eb);
Chris Masonb4ce94d2009-02-04 09:25:08 -050016
Chris Masonbd681512011-07-16 15:23:14 -040017void btrfs_tree_read_lock(struct extent_buffer *eb);
18void btrfs_tree_read_unlock(struct extent_buffer *eb);
19void btrfs_tree_read_unlock_blocking(struct extent_buffer *eb);
David Sterbab95be2d2018-04-04 01:43:05 +020020void btrfs_set_lock_blocking_read(struct extent_buffer *eb);
21void btrfs_set_lock_blocking_write(struct extent_buffer *eb);
David Sterbaaa12c022018-04-04 01:52:31 +020022void btrfs_clear_lock_blocking_read(struct extent_buffer *eb);
23void btrfs_clear_lock_blocking_write(struct extent_buffer *eb);
Chris Masonb9447ef82009-03-09 11:45:38 -040024void btrfs_assert_tree_locked(struct extent_buffer *eb);
Chris Masonbd681512011-07-16 15:23:14 -040025int btrfs_try_tree_read_lock(struct extent_buffer *eb);
26int btrfs_try_tree_write_lock(struct extent_buffer *eb);
Chris Masonf82c4582014-11-19 10:25:09 -080027int btrfs_tree_read_lock_atomic(struct extent_buffer *eb);
28
Chris Masonbd681512011-07-16 15:23:14 -040029
30static inline void btrfs_tree_unlock_rw(struct extent_buffer *eb, int rw)
31{
32 if (rw == BTRFS_WRITE_LOCK || rw == BTRFS_WRITE_LOCK_BLOCKING)
33 btrfs_tree_unlock(eb);
34 else if (rw == BTRFS_READ_LOCK_BLOCKING)
35 btrfs_tree_read_unlock_blocking(eb);
36 else if (rw == BTRFS_READ_LOCK)
37 btrfs_tree_read_unlock(eb);
38 else
39 BUG();
40}
41
Chris Mason925baed2008-06-25 16:01:30 -040042#endif