Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_BLOCKGROUP_LOCK_H
0003 #define _LINUX_BLOCKGROUP_LOCK_H
0004 /*
0005  * Per-blockgroup locking for ext2 and ext3.
0006  *
0007  * Simple hashed spinlocking.
0008  */
0009 
0010 #include <linux/spinlock.h>
0011 #include <linux/cache.h>
0012 
0013 #ifdef CONFIG_SMP
0014 #define NR_BG_LOCKS (4 << ilog2(NR_CPUS < 32 ? NR_CPUS : 32))
0015 #else
0016 #define NR_BG_LOCKS 1
0017 #endif
0018 
0019 struct bgl_lock {
0020     spinlock_t lock;
0021 } ____cacheline_aligned_in_smp;
0022 
0023 struct blockgroup_lock {
0024     struct bgl_lock locks[NR_BG_LOCKS];
0025 };
0026 
0027 static inline void bgl_lock_init(struct blockgroup_lock *bgl)
0028 {
0029     int i;
0030 
0031     for (i = 0; i < NR_BG_LOCKS; i++)
0032         spin_lock_init(&bgl->locks[i].lock);
0033 }
0034 
0035 static inline spinlock_t *
0036 bgl_lock_ptr(struct blockgroup_lock *bgl, unsigned int block_group)
0037 {
0038     return &bgl->locks[block_group & (NR_BG_LOCKS-1)].lock;
0039 }
0040 
0041 #endif