blockgroup_lock.h 771 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef _LINUX_BLOCKGROUP_LOCK_H
  2. #define _LINUX_BLOCKGROUP_LOCK_H
  3. /*
  4. * Per-blockgroup locking for ext2 and ext3.
  5. *
  6. * Simple hashed spinlocking.
  7. */
  8. #include <linux/spinlock.h>
  9. #include <linux/cache.h>
  10. #ifdef CONFIG_SMP
  11. #define NR_BG_LOCKS (4 << ilog2(NR_CPUS < 32 ? NR_CPUS : 32))
  12. #else
  13. #define NR_BG_LOCKS 1
  14. #endif
  15. struct bgl_lock {
  16. spinlock_t lock;
  17. } ____cacheline_aligned_in_smp;
  18. struct blockgroup_lock {
  19. struct bgl_lock locks[NR_BG_LOCKS];
  20. };
  21. static inline void bgl_lock_init(struct blockgroup_lock *bgl)
  22. {
  23. int i;
  24. for (i = 0; i < NR_BG_LOCKS; i++)
  25. spin_lock_init(&bgl->locks[i].lock);
  26. }
  27. static inline spinlock_t *
  28. bgl_lock_ptr(struct blockgroup_lock *bgl, unsigned int block_group)
  29. {
  30. return &bgl->locks[block_group & (NR_BG_LOCKS-1)].lock;
  31. }
  32. #endif