File: nocow_locking.h

package info (click to toggle)
linux 6.17.9-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,734,892 kB
  • sloc: ansic: 26,684,085; asm: 271,195; sh: 147,401; python: 75,980; makefile: 57,306; perl: 36,943; xml: 19,562; cpp: 5,899; yacc: 4,909; lex: 2,943; awk: 1,556; sed: 29; ruby: 25
file content (50 lines) | stat: -rw-r--r-- 1,641 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _BCACHEFS_NOCOW_LOCKING_H
#define _BCACHEFS_NOCOW_LOCKING_H

#include "bcachefs.h"
#include "alloc_background.h"
#include "nocow_locking_types.h"

#include <linux/hash.h>

static inline struct nocow_lock_bucket *bucket_nocow_lock(struct bucket_nocow_lock_table *t,
							  u64 dev_bucket)
{
	unsigned h = hash_64(dev_bucket, BUCKET_NOCOW_LOCKS_BITS);

	return t->l + (h & (BUCKET_NOCOW_LOCKS - 1));
}

#define BUCKET_NOCOW_LOCK_UPDATE	(1 << 0)

bool bch2_bucket_nocow_is_locked(struct bucket_nocow_lock_table *, struct bpos);
void bch2_bucket_nocow_unlock(struct bucket_nocow_lock_table *, struct bpos, int);
bool __bch2_bucket_nocow_trylock(struct nocow_lock_bucket *, u64, int);
void __bch2_bucket_nocow_lock(struct bucket_nocow_lock_table *,
			      struct nocow_lock_bucket *, u64, int);

static inline void bch2_bucket_nocow_lock(struct bucket_nocow_lock_table *t,
					  struct bpos bucket, int flags)
{
	u64 dev_bucket = bucket_to_u64(bucket);
	struct nocow_lock_bucket *l = bucket_nocow_lock(t, dev_bucket);

	__bch2_bucket_nocow_lock(t, l, dev_bucket, flags);
}

static inline bool bch2_bucket_nocow_trylock(struct bucket_nocow_lock_table *t,
					  struct bpos bucket, int flags)
{
	u64 dev_bucket = bucket_to_u64(bucket);
	struct nocow_lock_bucket *l = bucket_nocow_lock(t, dev_bucket);

	return __bch2_bucket_nocow_trylock(l, dev_bucket, flags);
}

void bch2_nocow_locks_to_text(struct printbuf *, struct bucket_nocow_lock_table *);

void bch2_fs_nocow_locking_exit(struct bch_fs *);
void bch2_fs_nocow_locking_init_early(struct bch_fs *);

#endif /* _BCACHEFS_NOCOW_LOCKING_H */