blockgroup_lock.h 810 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #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. #include <linux/spinlock.h>
  10. #include <linux/cache.h>
  11. #ifdef CONFIG_SMP
  12. #define NR_BG_LOCKS (4 << ilog2(NR_CPUS < 32 ? NR_CPUS : 32))
  13. #else
  14. #define NR_BG_LOCKS 1
  15. #endif
  16. struct bgl_lock {
  17. spinlock_t lock;
  18. } ____cacheline_aligned_in_smp;
  19. struct blockgroup_lock {
  20. struct bgl_lock locks[NR_BG_LOCKS];
  21. };
  22. static inline void bgl_lock_init(struct blockgroup_lock *bgl)
  23. {
  24. int i;
  25. for (i = 0; i < NR_BG_LOCKS; i++)
  26. spin_lock_init(&bgl->locks[i].lock);
  27. }
  28. static inline spinlock_t *
  29. bgl_lock_ptr(struct blockgroup_lock *bgl, unsigned int block_group)
  30. {
  31. return &bgl->locks[block_group & (NR_BG_LOCKS-1)].lock;
  32. }
  33. #endif