stackglue.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * stackglue.c
  5. *
  6. * Code which implements an OCFS2 specific interface to underlying
  7. * cluster stacks.
  8. *
  9. * Copyright (C) 2007 Oracle. All rights reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public
  13. * License as published by the Free Software Foundation, version 2.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. */
  20. #include "stackglue.h"
  21. static struct ocfs2_locking_protocol *lproto;
  22. /* These should be identical */
  23. #if (DLM_LOCK_IV != LKM_IVMODE)
  24. # error Lock modes do not match
  25. #endif
  26. #if (DLM_LOCK_NL != LKM_NLMODE)
  27. # error Lock modes do not match
  28. #endif
  29. #if (DLM_LOCK_CR != LKM_CRMODE)
  30. # error Lock modes do not match
  31. #endif
  32. #if (DLM_LOCK_CW != LKM_CWMODE)
  33. # error Lock modes do not match
  34. #endif
  35. #if (DLM_LOCK_PR != LKM_PRMODE)
  36. # error Lock modes do not match
  37. #endif
  38. #if (DLM_LOCK_PW != LKM_PWMODE)
  39. # error Lock modes do not match
  40. #endif
  41. #if (DLM_LOCK_EX != LKM_EXMODE)
  42. # error Lock modes do not match
  43. #endif
  44. static inline int mode_to_o2dlm(int mode)
  45. {
  46. BUG_ON(mode > LKM_MAXMODE);
  47. return mode;
  48. }
  49. #define map_flag(_generic, _o2dlm) \
  50. if (flags & (_generic)) { \
  51. flags &= ~(_generic); \
  52. o2dlm_flags |= (_o2dlm); \
  53. }
  54. static int flags_to_o2dlm(u32 flags)
  55. {
  56. int o2dlm_flags = 0;
  57. map_flag(DLM_LKF_NOQUEUE, LKM_NOQUEUE);
  58. map_flag(DLM_LKF_CANCEL, LKM_CANCEL);
  59. map_flag(DLM_LKF_CONVERT, LKM_CONVERT);
  60. map_flag(DLM_LKF_VALBLK, LKM_VALBLK);
  61. map_flag(DLM_LKF_IVVALBLK, LKM_INVVALBLK);
  62. map_flag(DLM_LKF_ORPHAN, LKM_ORPHAN);
  63. map_flag(DLM_LKF_FORCEUNLOCK, LKM_FORCE);
  64. map_flag(DLM_LKF_TIMEOUT, LKM_TIMEOUT);
  65. map_flag(DLM_LKF_LOCAL, LKM_LOCAL);
  66. /* map_flag() should have cleared every flag passed in */
  67. BUG_ON(flags != 0);
  68. return o2dlm_flags;
  69. }
  70. #undef map_flag
  71. enum dlm_status ocfs2_dlm_lock(struct dlm_ctxt *dlm,
  72. int mode,
  73. struct dlm_lockstatus *lksb,
  74. u32 flags,
  75. void *name,
  76. unsigned int namelen,
  77. void *astarg)
  78. {
  79. int o2dlm_mode = mode_to_o2dlm(mode);
  80. int o2dlm_flags = flags_to_o2dlm(flags);
  81. BUG_ON(lproto == NULL);
  82. return dlmlock(dlm, o2dlm_mode, lksb, o2dlm_flags, name, namelen,
  83. lproto->lp_lock_ast, astarg,
  84. lproto->lp_blocking_ast);
  85. }
  86. enum dlm_status ocfs2_dlm_unlock(struct dlm_ctxt *dlm,
  87. struct dlm_lockstatus *lksb,
  88. u32 flags,
  89. void *astarg)
  90. {
  91. int o2dlm_flags = flags_to_o2dlm(flags);
  92. BUG_ON(lproto == NULL);
  93. return dlmunlock(dlm, lksb, o2dlm_flags,
  94. lproto->lp_unlock_ast, astarg);
  95. }
  96. void o2cb_get_stack(struct ocfs2_locking_protocol *proto)
  97. {
  98. BUG_ON(proto == NULL);
  99. lproto = proto;
  100. }
  101. void o2cb_put_stack(void)
  102. {
  103. lproto = NULL;
  104. }