blob: 29135def468e97ab240ddf11d0c51c2555dbb5dc [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);
20void btrfs_set_lock_blocking_rw(struct extent_buffer *eb, int rw);
21void btrfs_clear_lock_blocking_rw(struct extent_buffer *eb, int rw);
Chris Masonb9447ef82009-03-09 11:45:38 -040022void btrfs_assert_tree_locked(struct extent_buffer *eb);
Chris Masonbd681512011-07-16 15:23:14 -040023int btrfs_try_tree_read_lock(struct extent_buffer *eb);
24int btrfs_try_tree_write_lock(struct extent_buffer *eb);
Chris Masonf82c4582014-11-19 10:25:09 -080025int btrfs_tree_read_lock_atomic(struct extent_buffer *eb);
26
Chris Masonbd681512011-07-16 15:23:14 -040027
28static inline void btrfs_tree_unlock_rw(struct extent_buffer *eb, int rw)
29{
30 if (rw == BTRFS_WRITE_LOCK || rw == BTRFS_WRITE_LOCK_BLOCKING)
31 btrfs_tree_unlock(eb);
32 else if (rw == BTRFS_READ_LOCK_BLOCKING)
33 btrfs_tree_read_unlock_blocking(eb);
34 else if (rw == BTRFS_READ_LOCK)
35 btrfs_tree_read_unlock(eb);
36 else
37 BUG();
38}
39
40static inline void btrfs_set_lock_blocking(struct extent_buffer *eb)
41{
42 btrfs_set_lock_blocking_rw(eb, BTRFS_WRITE_LOCK);
43}
44
45static inline void btrfs_clear_lock_blocking(struct extent_buffer *eb)
46{
47 btrfs_clear_lock_blocking_rw(eb, BTRFS_WRITE_LOCK_BLOCKING);
48}
Chris Mason925baed2008-06-25 16:01:30 -040049#endif