blob: 511ab123a8223493f8c15ee5dbc683f2ca747dd2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _LINUX_BLOCKGROUP_LOCK_H
3#define _LINUX_BLOCKGROUP_LOCK_H
4/*
5 * Per-blockgroup locking for ext2 and ext3.
6 *
7 * Simple hashed spinlocking.
8 */
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/spinlock.h>
11#include <linux/cache.h>
12
13#ifdef CONFIG_SMP
Eric Biggers7c5f6b32016-09-15 18:29:06 -040014#define NR_BG_LOCKS (4 << ilog2(NR_CPUS < 32 ? NR_CPUS : 32))
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#define NR_BG_LOCKS 1
Eric Biggers7c5f6b32016-09-15 18:29:06 -040017#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19struct bgl_lock {
20 spinlock_t lock;
21} ____cacheline_aligned_in_smp;
22
23struct blockgroup_lock {
24 struct bgl_lock locks[NR_BG_LOCKS];
25};
26
27static inline void bgl_lock_init(struct blockgroup_lock *bgl)
28{
29 int i;
30
31 for (i = 0; i < NR_BG_LOCKS; i++)
32 spin_lock_init(&bgl->locks[i].lock);
33}
34
Pekka Enbergc644f0e2009-01-04 12:00:48 -080035static inline spinlock_t *
36bgl_lock_ptr(struct blockgroup_lock *bgl, unsigned int block_group)
37{
Eric Biggers9e5ab852016-09-15 18:25:07 -040038 return &bgl->locks[block_group & (NR_BG_LOCKS-1)].lock;
Pekka Enbergc644f0e2009-01-04 12:00:48 -080039}
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41#endif