error_conversion.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Copyright (c) 2008 Allied Telesis Labs.
  3. * Copyright (c) 2012 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Angus Salkeld (asalkeld@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <corosync/corotypes.h>
  36. cs_error_t qb_to_cs_error (int result)
  37. {
  38. int32_t res;
  39. cs_error_t err = CS_ERR_LIBRARY;
  40. if (result >= 0) {
  41. return CS_OK;
  42. }
  43. res = -result;
  44. switch (res) {
  45. case EBADF:
  46. err = CS_ERR_BAD_HANDLE;
  47. break;
  48. case ENOMEM:
  49. err = CS_ERR_NO_MEMORY;
  50. break;
  51. case ENOMSG:
  52. case ENOBUFS:
  53. case ETIMEDOUT:
  54. case EAGAIN:
  55. err = CS_ERR_TRY_AGAIN;
  56. break;
  57. case EBADE:
  58. err = CS_ERR_FAILED_OPERATION;
  59. break;
  60. case ETIME:
  61. err = CS_ERR_TIMEOUT;
  62. break;
  63. case EINVAL:
  64. err = CS_ERR_INVALID_PARAM;
  65. break;
  66. case EBUSY:
  67. err = CS_ERR_BUSY;
  68. break;
  69. case EACCES:
  70. err = CS_ERR_ACCESS;
  71. break;
  72. case EOVERFLOW:
  73. err = CS_ERR_NAME_TOO_LONG;
  74. break;
  75. case EEXIST:
  76. err = CS_ERR_EXIST;
  77. break;
  78. case ENOSPC:
  79. err = CS_ERR_NO_SPACE;
  80. break;
  81. case EINTR:
  82. err = CS_ERR_INTERRUPT;
  83. break;
  84. case ENOENT:
  85. case ENODEV:
  86. err = CS_ERR_NOT_EXIST;
  87. break;
  88. case ENOSYS:
  89. case ENOTSUP:
  90. err = CS_ERR_NOT_SUPPORTED;
  91. break;
  92. case EBADMSG:
  93. err = CS_ERR_MESSAGE_ERROR;
  94. break;
  95. case EMSGSIZE:
  96. case E2BIG:
  97. err = CS_ERR_TOO_BIG;
  98. break;
  99. case ECONNREFUSED:
  100. case ENOTCONN:
  101. default:
  102. err = CS_ERR_LIBRARY;
  103. break;
  104. }
  105. return err;
  106. }
  107. cs_error_t hdb_error_to_cs (int res)
  108. {
  109. if (res == 0) {
  110. return (CS_OK);
  111. } else {
  112. if (res == -EBADF) {
  113. return (CS_ERR_BAD_HANDLE);
  114. } else if (res == -ENOMEM) {
  115. return (CS_ERR_NO_MEMORY);
  116. } else if (res == -EMFILE) {
  117. return (CS_ERR_NO_RESOURCES);
  118. } else if (res == -EACCES) {
  119. return (CS_ERR_ACCESS);
  120. }
  121. return (CS_ERR_LIBRARY);
  122. }
  123. }
  124. const char * cs_strerror(cs_error_t err)
  125. {
  126. switch (err) {
  127. case CS_OK:
  128. return "success";
  129. case CS_ERR_LIBRARY:
  130. return "CS_ERR_LIBRARY";
  131. case CS_ERR_VERSION:
  132. return "CS_ERR_VERSION";
  133. case CS_ERR_INIT:
  134. return "CS_ERR_INIT";
  135. case CS_ERR_NO_MEMORY:
  136. return "CS_ERR_NO_MEMORY";
  137. case CS_ERR_NAME_TOO_LONG :
  138. return "CS_ERR_NAME_TOO_LONG ";
  139. case CS_ERR_TIMEOUT:
  140. return "CS_ERR_TIMEOUT";
  141. case CS_ERR_TRY_AGAIN:
  142. return "CS_ERR_TRY_AGAIN";
  143. case CS_ERR_INVALID_PARAM:
  144. return "CS_ERR_INVALID_PARAM";
  145. case CS_ERR_BAD_HANDLE:
  146. return "CS_ERR_BAD_HANDLE";
  147. case CS_ERR_BUSY :
  148. return "CS_ERR_BUSY ";
  149. case CS_ERR_ACCESS :
  150. return "CS_ERR_ACCESS ";
  151. case CS_ERR_NOT_EXIST :
  152. return "CS_ERR_NOT_EXIST ";
  153. case CS_ERR_EXIST :
  154. return "CS_ERR_EXIST ";
  155. case CS_ERR_NO_SPACE :
  156. return "CS_ERR_NO_SPACE ";
  157. case CS_ERR_INTERRUPT :
  158. return "CS_ERR_INTERRUPT ";
  159. case CS_ERR_NAME_NOT_FOUND :
  160. return "CS_ERR_NAME_NOT_FOUND ";
  161. case CS_ERR_NO_RESOURCES :
  162. return "CS_ERR_NO_RESOURCES ";
  163. case CS_ERR_NOT_SUPPORTED :
  164. return "CS_ERR_NOT_SUPPORTED ";
  165. case CS_ERR_BAD_OPERATION :
  166. return "CS_ERR_BAD_OPERATION ";
  167. case CS_ERR_FAILED_OPERATION :
  168. return "CS_ERR_FAILED_OPERATION ";
  169. case CS_ERR_MESSAGE_ERROR :
  170. return "CS_ERR_MESSAGE_ERROR ";
  171. case CS_ERR_QUEUE_FULL :
  172. return "CS_ERR_QUEUE_FULL ";
  173. case CS_ERR_QUEUE_NOT_AVAILABLE :
  174. return "CS_ERR_QUEUE_NOT_AVAILABLE ";
  175. case CS_ERR_BAD_FLAGS :
  176. return "CS_ERR_BAD_FLAGS ";
  177. case CS_ERR_TOO_BIG :
  178. return "CS_ERR_TOO_BIG ";
  179. case CS_ERR_NO_SECTIONS :
  180. return "CS_ERR_NO_SECTIONS ";
  181. case CS_ERR_CONTEXT_NOT_FOUND :
  182. return "CS_ERR_CONTEXT_NOT_FOUND ";
  183. case CS_ERR_TOO_MANY_GROUPS :
  184. return "CS_ERR_TOO_MANY_GROUPS ";
  185. case CS_ERR_SECURITY :
  186. return "CS_ERR_SECURITY ";
  187. default:
  188. return "unknown error";
  189. }
  190. }