home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / pvfs2 / orangefs-2.8.3-20110323.tar.gz / orangefs-2.8.3-20110323.tar / orangefs / include / pvfs2-types.h < prev    next >
C/C++ Source or Header  |  2011-02-25  |  36KB  |  967 lines

  1. /*
  2.  * (C) 2001 Clemson University and The University of Chicago
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6. /* NOTE: if you make any changes to the encoding definitions in this file, 
  7.  * please update the PVFS2_PROTO_VERSION in pvfs2-req-proto.h accordingly
  8.  */
  9. /** \file
  10.  *
  11.  *  Definitions of types used throughout PVFS2.
  12.  */
  13. #ifndef __PVFS2_TYPES_H
  14. #define __PVFS2_TYPES_H
  15.  
  16. #ifdef __KERNEL__
  17. #include <linux/types.h>
  18. #else
  19. #include <stdint.h>
  20. #include <sys/stat.h>
  21. #include <sys/time.h>
  22. #include <limits.h>
  23. #include <errno.h>
  24. #endif
  25.  
  26. #ifndef INT32_MAX
  27. /* definition taken from stdint.h */
  28. #define INT32_MAX (2147483647)
  29. #endif
  30.  
  31. #ifndef NAME_MAX
  32. #define NAME_MAX 255
  33. #endif
  34.  
  35. /* figure out the size of a pointer */
  36. #if defined(__WORDSIZE)
  37.   #define PVFS2_SIZEOF_VOIDP __WORDSIZE
  38. #elif defined(BITS_PER_LONG)
  39.   #define PVFS2_SIZEOF_VOIDP BITS_PER_LONG
  40. #elif defined(INTPTR_MIN)
  41.   #if   INTPTR_MIN == INT32_MIN
  42.     #define PVFS2_SIZEOF_VOIDP 32
  43.   #elif INTPTR_MIN == INT64_MIN
  44.     #define PVFS2_SIZEOF_VOIDP 64
  45.   #endif
  46. #else
  47.   #error "Unhandled size of void pointer"
  48. #endif
  49.  
  50. /* we need to align some variables in 32bit case to match alignment
  51.  * in 64bit case
  52.  */
  53. #if PVFS2_SIZEOF_VOIDP == 32
  54. #define PVFS2_ALIGN_VAR(_type, _name) \
  55.     _type _name; \
  56.     int32_t __pad##_name
  57. #else
  58. #define PVFS2_ALIGN_VAR(_type, _name) _type _name
  59. #endif
  60.  
  61. /* empty stubs to turn off encoding definition generation */
  62. #include "pvfs2-encode-stubs.h"
  63. #include "pvfs2-hint.h"
  64.  
  65. /* Basic types used throughout the code. */
  66. typedef uint8_t PVFS_boolean;
  67. typedef int32_t PVFS_error;
  68. typedef int64_t PVFS_offset;
  69. typedef int64_t PVFS_size;
  70. typedef int64_t PVFS_id_gen_t;
  71.  
  72. /** Opaque value representing a destination address. */
  73. typedef int64_t PVFS_BMI_addr_t;
  74.  
  75. inline void encode_PVFS_BMI_addr_t(char **pptr, const PVFS_BMI_addr_t *x);
  76. inline int encode_PVFS_BMI_addr_t_size_check(const PVFS_BMI_addr_t *x);
  77. inline void decode_PVFS_BMI_addr_t(char **pptr, PVFS_BMI_addr_t *x);
  78.  
  79. #define encode_PVFS_error encode_int32_t
  80. #define decode_PVFS_error decode_int32_t
  81. #define encode_PVFS_offset encode_int64_t
  82. #define decode_PVFS_offset decode_int64_t
  83. #define encode_PVFS_size encode_int64_t
  84. #define decode_PVFS_size decode_int64_t
  85. #define encode_PVFS_id_gen_t encode_int64_t
  86. #define decode_PVFS_id_gen_t decode_int64_t
  87.  
  88. /* Basic types used by communication subsystems. */
  89. typedef int32_t PVFS_msg_tag_t;
  90. typedef PVFS_id_gen_t PVFS_context_id;
  91.  
  92. enum PVFS_flowproto_type
  93. {
  94.     FLOWPROTO_DUMP_OFFSETS = 1,
  95.     FLOWPROTO_BMI_CACHE = 2,
  96.     FLOWPROTO_MULTIQUEUE = 3
  97. };
  98. #define FLOWPROTO_DEFAULT FLOWPROTO_MULTIQUEUE
  99.  
  100. /* supported wire encoding types */
  101. enum PVFS_encoding_type
  102. {
  103.     ENCODING_DIRECT = 1,
  104.     ENCODING_LE_BFIELD = 2,
  105.     ENCODING_XDR = 3
  106. };
  107.  
  108. /* these values must correspond to the defined encoding types above */
  109. #define ENCODING_INVALID_MIN                    0
  110. #define ENCODING_INVALID_MAX                    4
  111. #define ENCODING_SUPPORTED_MIN ENCODING_LE_BFIELD
  112. #define ENCODING_SUPPORTED_MAX ENCODING_LE_BFIELD
  113. #define ENCODING_IS_VALID(enc_type)      \
  114. ((enc_type > ENCODING_INVALID_MIN) &&    \
  115.  (enc_type < ENCODING_INVALID_MAX))
  116. #define ENCODING_IS_SUPPORTED(enc_type)  \
  117. ((enc_type >= ENCODING_SUPPORTED_MIN) && \
  118.  (enc_type <= ENCODING_SUPPORTED_MAX))
  119. #define PVFS2_ENCODING_DEFAULT ENCODING_LE_BFIELD
  120.  
  121. /* basic types used by storage subsystem */
  122.  
  123. /** Unique identifier for an object on a PVFS2 file system. */
  124. typedef uint64_t PVFS_handle;
  125.  
  126. /** Identifier for a specific PVFS2 file system; administrator
  127.  *  must guarantee that these are unique in the context of all
  128.  *  PVFS2 file systems reachable by a given client.
  129.  */
  130. typedef int32_t PVFS_fs_id;
  131. typedef uint64_t PVFS_ds_position;
  132. typedef int32_t PVFS_ds_flags;
  133.  
  134.  
  135. #define encode_PVFS_handle encode_uint64_t
  136. #define decode_PVFS_handle decode_uint64_t
  137. #define encode_PVFS_fs_id encode_int32_t
  138. #define decode_PVFS_fs_id decode_int32_t
  139. #define decode_PVFS_ds_position decode_uint64_t
  140. #define encode_PVFS_ds_position encode_uint64_t
  141.  
  142. /* Basic types used within metadata. */
  143. typedef uint32_t PVFS_uid;
  144. typedef uint32_t PVFS_gid;
  145. typedef uint64_t PVFS_time;
  146. typedef uint32_t PVFS_permissions;
  147. typedef uint64_t PVFS_flags;
  148. #define encode_PVFS_uid encode_uint32_t
  149. #define decode_PVFS_uid decode_uint32_t
  150. #define encode_PVFS_gid encode_uint32_t
  151. #define decode_PVFS_gid decode_uint32_t
  152. #define encode_PVFS_time encode_int64_t
  153. #define decode_PVFS_time decode_int64_t
  154. #define encode_PVFS_permissions encode_uint32_t
  155. #define decode_PVFS_permissions decode_uint32_t
  156. #define encode_PVFS_flags encode_uint64_t
  157. #define decode_PVFS_flags decode_uint64_t
  158.  
  159. /* contiguous range of handles */
  160. typedef struct
  161. {
  162.     PVFS_handle first;
  163.     PVFS_handle last;
  164. } PVFS_handle_extent;
  165. endecode_fields_2(
  166.     PVFS_handle_extent,
  167.     PVFS_handle, first,
  168.     PVFS_handle, last);
  169.  
  170. /* an array of contiguous ranges of handles */
  171. typedef struct
  172. {
  173.     uint32_t extent_count;
  174.     PVFS_handle_extent *extent_array;
  175. } PVFS_handle_extent_array;
  176. endecode_fields_1a(
  177.     PVFS_handle_extent_array,
  178.     skip4,,
  179.     uint32_t, extent_count,
  180.     PVFS_handle_extent, extent_array);
  181.  
  182. /* Layout algorithm for converting from server lists in the config
  183.  * to a list of servers to use to store datafiles for a file.
  184.  */
  185. enum PVFS_sys_layout_algorithm
  186. {
  187.     /* order the datafiles according to the server list */
  188.     PVFS_SYS_LAYOUT_NONE = 1,
  189.  
  190.     /* choose the first datafile randomly, and then round-robin in-order */
  191.     PVFS_SYS_LAYOUT_ROUND_ROBIN = 2,
  192.  
  193.     /* choose each datafile randomly */
  194.     PVFS_SYS_LAYOUT_RANDOM = 3,
  195.  
  196.     /* order the datafiles based on the list specified */
  197.     PVFS_SYS_LAYOUT_LIST = 4
  198. };
  199. #define PVFS_SYS_LAYOUT_DEFAULT NULL
  200.  
  201. /* The list of datafile servers that can be passed into PVFS_sys_create
  202.  * to specify the exact layout of a file.  The count parameter will override
  203.  * the num_dfiles field in the attribute.
  204.  */
  205. struct PVFS_sys_server_list
  206. {
  207.     int32_t count;
  208.     PVFS_BMI_addr_t *servers;
  209. };
  210.  
  211. /* The server laout struct passed to PVFS_sys_create.  The algorithm
  212.  * specifies how the servers are chosen to layout the file.  If the
  213.  * algorithm is set to PVFS_SYS_LAYOUT_LIST, the server_list parameter
  214.  * is used to determine the layout.
  215.  */
  216. typedef struct PVFS_sys_layout_s
  217. {
  218.     /* The algorithm to use to layout the file */
  219.     enum PVFS_sys_layout_algorithm algorithm;
  220.  
  221.     /* The server list specified if the
  222.      * PVFS_SYS_LAYOUT_LIST algorithm is chosen.
  223.      */
  224.     struct PVFS_sys_server_list server_list;
  225. } PVFS_sys_layout;
  226. #define extra_size_PVFS_sys_layout PVFS_REQ_LIMIT_LAYOUT
  227.  
  228. inline void encode_PVFS_sys_layout(char **pptr, const struct PVFS_sys_layout_s *x);
  229. inline void decode_PVFS_sys_layout(char **pptr, struct PVFS_sys_layout_s *x);
  230.  
  231. /* predefined special values for types */
  232. #define PVFS_CONTEXT_NULL    ((PVFS_context_id)-1)
  233. #define PVFS_HANDLE_NULL     ((PVFS_handle)0)
  234. #define PVFS_FS_ID_NULL       ((PVFS_fs_id)0)
  235. #define PVFS_OP_NULL         ((PVFS_id_gen_t)0)
  236. #define PVFS_BMI_ADDR_NULL ((PVFS_BMI_addr_t)0)
  237. #define PVFS_ITERATE_START    (INT32_MAX - 1)
  238. #define PVFS_ITERATE_END      (INT32_MAX - 2)
  239. #define PVFS_READDIR_START PVFS_ITERATE_START
  240. #define PVFS_READDIR_END   PVFS_ITERATE_END
  241.  
  242. #ifndef O_LARGEFILE
  243. #define O_LARGEFILE 0
  244. #endif
  245.  
  246. /* permission bits */
  247. #define PVFS_O_EXECUTE (1 << 0)
  248. #define PVFS_O_WRITE   (1 << 1)
  249. #define PVFS_O_READ    (1 << 2)
  250. #define PVFS_G_EXECUTE (1 << 3)
  251. #define PVFS_G_WRITE   (1 << 4)
  252. #define PVFS_G_READ    (1 << 5)
  253. #define PVFS_U_EXECUTE (1 << 6)
  254. #define PVFS_U_WRITE   (1 << 7)
  255. #define PVFS_U_READ    (1 << 8)
  256. /* no PVFS_U_VTX (sticky bit) */
  257. #define PVFS_G_SGID    (1 << 10)
  258. #define PVFS_U_SUID    (1 << 11)
  259.  
  260. /* valid permission mask */
  261. #define PVFS_PERM_VALID \
  262. (PVFS_O_EXECUTE | PVFS_O_WRITE | PVFS_O_READ | PVFS_G_EXECUTE | \
  263.  PVFS_G_WRITE | PVFS_G_READ | PVFS_U_EXECUTE | PVFS_U_WRITE | \
  264.  PVFS_U_READ | PVFS_G_SGID | PVFS_U_SUID)
  265.  
  266. #define PVFS_USER_ALL  (PVFS_U_EXECUTE|PVFS_U_WRITE|PVFS_U_READ)
  267. #define PVFS_GROUP_ALL (PVFS_G_EXECUTE|PVFS_G_WRITE|PVFS_G_READ)
  268. #define PVFS_OTHER_ALL (PVFS_O_EXECUTE|PVFS_O_WRITE|PVFS_O_READ)
  269.  
  270. #define PVFS_ALL_EXECUTE (PVFS_U_EXECUTE|PVFS_G_EXECUTE|PVFS_O_EXECUTE)
  271. #define PVFS_ALL_WRITE   (PVFS_U_WRITE|PVFS_G_WRITE|PVFS_O_WRITE)
  272. #define PVFS_ALL_READ    (PVFS_U_READ|PVFS_G_READ|PVFS_O_READ)
  273.  
  274. /** Object and attribute types. */
  275. /* If this enum is modified the server parameters related to the precreate pool
  276.  * batch and low threshold sizes may need to be modified  to reflect this 
  277.  * change. Also, the PVFS_DS_TYPE_COUNT #define below must be updated */
  278. typedef enum
  279. {
  280.     PVFS_TYPE_NONE =              0,
  281.     PVFS_TYPE_METAFILE =    (1 << 0),
  282.     PVFS_TYPE_DATAFILE =    (1 << 1),
  283.     PVFS_TYPE_DIRECTORY =   (1 << 2),
  284.     PVFS_TYPE_SYMLINK =     (1 << 3),
  285.     PVFS_TYPE_DIRDATA =     (1 << 4),
  286.     PVFS_TYPE_INTERNAL =    (1 << 5)   /* for the server's private use */
  287. } PVFS_ds_type;
  288.  
  289. #define decode_PVFS_ds_type decode_enum
  290. #define encode_PVFS_ds_type encode_enum
  291. #define PVFS_DS_TYPE_COUNT      7      /* total number of DS types defined in
  292.                                         * the PVFS_ds_type enum */
  293.                                             
  294.  
  295. /* helper to translate bit-shifted enum types to array index number in the 
  296.  * range (0-(PVFS_DS_TYPE_COUNT-1)) */
  297. #define PVFS_ds_type_to_int(__type, __intp)         \
  298. do {                                                \
  299.     uint32_t r = 0;                                 \
  300.     PVFS_ds_type t = __type;                        \
  301.     if( t == 0 )                                    \
  302.     {                                               \
  303.         *((uint32_t *)__intp) = 0;                  \
  304.     }                                               \
  305.     else                                            \
  306.     {                                               \
  307.         while( t >>=1 )                             \
  308.         {                                           \
  309.             r++;                                    \
  310.         }                                           \
  311.         *((uint32_t *)__intp) = r+1;                \
  312.     }                                               \
  313. } while( 0 )
  314.  
  315. /* helper to translate array index int to a proper PVFS_ds_type bit-shifted
  316.  * value */
  317. #define int_to_PVFS_ds_type(__i, __typep)           \
  318. do {                                                \
  319.     if( __i == 0 )                                  \
  320.     {                                               \
  321.         *((PVFS_ds_type *)__typep) = 0;             \
  322.     }                                               \
  323.     else                                            \
  324.     {                                               \
  325.         *((PVFS_ds_type *)__typep) = 1 << (__i - 1);\
  326.     }                                               \
  327. } while(0)
  328.  
  329. #ifdef __KERNEL__
  330. #include <linux/fs.h>
  331. #endif
  332.  
  333.  
  334. /*The value for PVFS_MIRROR_FL will not conflict with the FS values.*/
  335. #if defined(FS_IMMUTABLE_FL)
  336.  
  337. #define PVFS_IMMUTABLE_FL FS_IMMUTABLE_FL
  338. #define PVFS_APPEND_FL    FS_APPEND_FL
  339. #define PVFS_NOATIME_FL   FS_NOATIME_FL
  340. #define PVFS_MIRROR_FL    0x01000000ULL
  341.  
  342. #else
  343.  
  344. /* PVFS Object Flags (PVFS_flags); Add more as we implement them */
  345. #define PVFS_IMMUTABLE_FL 0x10ULL
  346. #define PVFS_APPEND_FL    0x20ULL
  347. #define PVFS_NOATIME_FL   0x80ULL
  348. #define PVFS_MIRROR_FL    0x01000000ULL
  349.  
  350. #endif
  351.  
  352. #define ALL_FS_META_HINT_FLAGS \
  353.    (PVFS_IMMUTABLE_FL |        \
  354.     PVFS_APPEND_FL    |        \
  355.     PVFS_NOATIME_FL )
  356.  
  357. /* Key/Value Pairs */
  358. /* Extended attributes are stored on objects with */
  359. /* a Key/Value pair.  A key or a value is simply */
  360. /* a byte string of some length.  Keys are normally */
  361. /* strings, and thus are printable ASCII and NULL */
  362. /* terminated.  Values are any sequence of bytes */
  363. /* and are user interpreted.  This struct represents */
  364. /* EITHER a key or a value.  This struct is IDENTICAL */
  365. /* to a TROVE_keyval_s defined in src/io/trove/trove-types.h */
  366. /* but is duplicated here to maintain separation between */
  367. /* the Trove implementation and PVFS2.  This struct should */
  368. /* be used everywhere but within Trove. WBL 6/2005*/
  369. typedef struct PVFS_ds_keyval_s
  370. {
  371.         void *buffer;      /* points to actual key or value */
  372.         int32_t buffer_sz; /* the size of the area pointed to by buffer */
  373.         int32_t read_sz;   /* when reading, the actual number of bytes read */
  374.                            /* only valid after a read */
  375. } PVFS_ds_keyval;
  376.  
  377. typedef struct
  378. {
  379.     uint32_t count;
  380. } PVFS_ds_keyval_handle_info;
  381.  
  382. /* attribute masks used by system interface callers */
  383. #define PVFS_ATTR_SYS_SIZE                  (1 << 20)
  384. #define PVFS_ATTR_SYS_LNK_TARGET            (1 << 24)
  385. #define PVFS_ATTR_SYS_DFILE_COUNT           (1 << 25)
  386. #define PVFS_ATTR_SYS_DIRENT_COUNT          (1 << 26)
  387. #define PVFS_ATTR_SYS_DIR_HINT              (1 << 27)
  388. #define PVFS_ATTR_SYS_BLKSIZE               (1 << 28)
  389. #define PVFS_ATTR_SYS_MIRROR_COPIES_COUNT   (1 << 29)
  390. #define PVFS_ATTR_SYS_UID                   (1 << 0)
  391. #define PVFS_ATTR_SYS_GID                   (1 << 1)
  392. #define PVFS_ATTR_SYS_PERM                  (1 << 2)
  393. #define PVFS_ATTR_SYS_ATIME                 (1 << 3)
  394. #define PVFS_ATTR_SYS_CTIME                 (1 << 4)
  395. #define PVFS_ATTR_SYS_MTIME                 (1 << 5)
  396. #define PVFS_ATTR_SYS_TYPE                  (1 << 6)
  397. #define PVFS_ATTR_SYS_ATIME_SET             (1 << 7)
  398. #define PVFS_ATTR_SYS_MTIME_SET             (1 << 8)
  399. #define PVFS_ATTR_SYS_COMMON_ALL \
  400. (PVFS_ATTR_SYS_UID   | PVFS_ATTR_SYS_GID   | \
  401.  PVFS_ATTR_SYS_PERM  | PVFS_ATTR_SYS_ATIME | \
  402.  PVFS_ATTR_SYS_CTIME | PVFS_ATTR_SYS_MTIME | \
  403.  PVFS_ATTR_SYS_TYPE)
  404.  
  405. #define PVFS_ATTR_SYS_ALL                    \
  406. (PVFS_ATTR_SYS_COMMON_ALL | PVFS_ATTR_SYS_SIZE | \
  407.  PVFS_ATTR_SYS_LNK_TARGET | PVFS_ATTR_SYS_DFILE_COUNT | \
  408.  PVFS_ATTR_SYS_MIRROR_COPIES_COUNT | \
  409.  PVFS_ATTR_SYS_DIRENT_COUNT | PVFS_ATTR_SYS_DIR_HINT | PVFS_ATTR_SYS_BLKSIZE)
  410. #define PVFS_ATTR_SYS_ALL_NOHINT                \
  411. (PVFS_ATTR_SYS_COMMON_ALL | PVFS_ATTR_SYS_SIZE | \
  412.  PVFS_ATTR_SYS_LNK_TARGET | PVFS_ATTR_SYS_DFILE_COUNT | \
  413.  PVFS_ATTR_SYS_MIRROR_COPIES_COUNT | \
  414.  PVFS_ATTR_SYS_DIRENT_COUNT | PVFS_ATTR_SYS_BLKSIZE)
  415. #define PVFS_ATTR_SYS_ALL_NOSIZE                   \
  416. (PVFS_ATTR_SYS_COMMON_ALL | PVFS_ATTR_SYS_LNK_TARGET | \
  417.  PVFS_ATTR_SYS_DFILE_COUNT | PVFS_ATTR_SYS_DIRENT_COUNT | \
  418.  PVFS_ATTR_SYS_MIRROR_COPIES_COUNT | \
  419.  PVFS_ATTR_SYS_DIR_HINT | PVFS_ATTR_SYS_BLKSIZE)
  420. #define PVFS_ATTR_SYS_ALL_SETABLE \
  421. (PVFS_ATTR_SYS_COMMON_ALL-PVFS_ATTR_SYS_TYPE) 
  422. #define PVFS_ATTR_SYS_ALL_TIMES \
  423. ((PVFS_ATTR_SYS_COMMON_ALL-PVFS_ATTR_SYS_TYPE) | PVFS_ATTR_SYS_ATIME_SET | PVFS_ATTR_SYS_MTIME_SET)
  424.  
  425. /* Extended attribute flags */
  426. #define PVFS_XATTR_CREATE  0x1
  427. #define PVFS_XATTR_REPLACE 0x2
  428.  
  429. /** statfs and misc. server statistic information. */
  430. typedef struct
  431. {
  432.     PVFS_fs_id fs_id;
  433.     PVFS_size bytes_available;
  434.     PVFS_size bytes_total;
  435.     uint64_t ram_total_bytes;
  436.     uint64_t ram_free_bytes;
  437.     uint64_t load_1;
  438.     uint64_t load_5;
  439.     uint64_t load_15;
  440.     uint64_t uptime_seconds;
  441.     uint64_t handles_available_count;
  442.     uint64_t handles_total_count;
  443. } PVFS_statfs;
  444. endecode_fields_12(
  445.     PVFS_statfs,
  446.     skip4,,
  447.     PVFS_fs_id, fs_id,
  448.     PVFS_size, bytes_available,
  449.     PVFS_size, bytes_total,
  450.     uint64_t, ram_total_bytes,
  451.     uint64_t, ram_free_bytes,
  452.     uint64_t, load_1,
  453.     uint64_t, load_5,
  454.     uint64_t, load_15,
  455.     uint64_t, uptime_seconds,
  456.     uint64_t, handles_available_count,
  457.     uint64_t, handles_total_count);
  458.  
  459. /** object reference (uniquely refers to a single file, directory, or
  460.     symlink).
  461. */
  462. typedef struct
  463. {
  464.     PVFS_handle handle;
  465.     PVFS_fs_id fs_id;
  466.     int32_t    __pad1;
  467. } PVFS_object_ref;
  468.  
  469. /** Credentials (stubbed for future authentication methods). */
  470. typedef struct
  471. {
  472.     PVFS_uid uid;
  473.     PVFS_gid gid;
  474. } PVFS_credentials;
  475. endecode_fields_2(
  476.     PVFS_credentials,
  477.     PVFS_uid, uid,
  478.     PVFS_gid, gid);
  479.  
  480. /* max length of BMI style URI's for identifying servers */
  481. #define PVFS_MAX_SERVER_ADDR_LEN 256
  482. /* max length of PVFS filename */
  483. #define PVFS_NAME_MAX            256
  484. /* max len of individual path element */
  485. #define PVFS_SEGMENT_MAX         PVFS_NAME_MAX
  486.  
  487. /* max extended attribute name len as imposed by the VFS and exploited for the
  488.  * upcall request types.
  489.  * NOTE: Please retain them as multiples of 8 even if you wish to change them
  490.  * This is *NECESSARY* for supporting 32 bit user-space binaries on a 64-bit kernel.
  491.  * Due to implementation within DBPF, this really needs to be PVFS_NAME_MAX,
  492.  * which it was the same value as, but no reason to let it break if that
  493.  * changes in the future.
  494.  */
  495. #define PVFS_MAX_XATTR_NAMELEN   PVFS_NAME_MAX /* Not the same as 
  496.                                                   XATTR_NAME_MAX defined
  497.                                                   by <linux/xattr.h> */
  498. #define PVFS_MAX_XATTR_VALUELEN  8192 /* Not the same as XATTR_SIZE_MAX defined
  499.                                         by <linux/xattr.h> */ 
  500. #define PVFS_MAX_XATTR_LISTLEN   8  /* Not the same as XATTR_LIST_MAX
  501.                                           defined by <linux/xattr.h> */
  502.  
  503. /* This structure is used by the VFS-client interaction alone */
  504. typedef struct {
  505.     char key[PVFS_MAX_XATTR_NAMELEN];
  506.     int32_t  key_sz; /* int32_t for portable, fixed-size structures */
  507.     int32_t  val_sz;
  508.     char val[PVFS_MAX_XATTR_VALUELEN];
  509. } PVFS_keyval_pair;
  510.  
  511. /** Directory entry contents. */
  512. typedef struct
  513. {
  514.     char d_name[PVFS_NAME_MAX + 1];
  515.     PVFS_handle handle;
  516. } PVFS_dirent;
  517. endecode_fields_2(
  518.     PVFS_dirent,
  519.     here_string, d_name,
  520.     PVFS_handle, handle);
  521.  
  522. /** Predefined server parameters that can be manipulated at run-time
  523.  *  through the mgmt interface.
  524.  */
  525. enum PVFS_server_param
  526. {
  527.     PVFS_SERV_PARAM_INVALID = 0,
  528.     PVFS_SERV_PARAM_GOSSIP_MASK = 1, /* gossip debugging on or off */
  529.     PVFS_SERV_PARAM_FSID_CHECK = 2,  /* verify that an fsid is ok */
  530.     PVFS_SERV_PARAM_ROOT_CHECK = 3,  /* verify existance of root handle */
  531.     PVFS_SERV_PARAM_MODE = 4,        /* change the current server mode */
  532.     PVFS_SERV_PARAM_EVENT_ENABLE = 5,    /* event enable */
  533.     PVFS_SERV_PARAM_EVENT_DISABLE = 6, /* event disable */
  534.     PVFS_SERV_PARAM_SYNC_META = 7,   /* metadata sync flags */
  535.     PVFS_SERV_PARAM_SYNC_DATA = 8,   /* file data sync flags */
  536.     PVFS_SERV_PARAM_DROP_CACHES = 9
  537. };
  538.  
  539. enum PVFS_mgmt_param_type
  540. {
  541.     PVFS_MGMT_PARAM_TYPE_UINT64,
  542.     PVFS_MGMT_PARAM_TYPE_STRING
  543. } ;
  544.  
  545. struct PVFS_mgmt_setparam_value
  546. {
  547.     enum PVFS_mgmt_param_type type;
  548.     union
  549.     {
  550.         uint64_t value;
  551.         char *string_value;
  552.     } u;
  553. };
  554.  
  555. encode_enum_union_2_struct(
  556.     PVFS_mgmt_setparam_value,
  557.     type, u,
  558.     uint64_t, value,        PVFS_MGMT_PARAM_TYPE_UINT64,
  559.     string,   string_value, PVFS_MGMT_PARAM_TYPE_STRING);
  560.  
  561. enum PVFS_server_mode
  562. {
  563.     PVFS_SERVER_NORMAL_MODE = 1,      /* default server operating mode */
  564.     PVFS_SERVER_ADMIN_MODE = 2        /* administrative mode */
  565. };
  566.  
  567. /* PVFS2 ACL structures */
  568. typedef struct {
  569.     int32_t  p_tag;
  570.     uint32_t p_perm;
  571.     uint32_t p_id;
  572. } pvfs2_acl_entry;
  573.  
  574. /* These defines match that of the POSIX defines */
  575. #define PVFS2_ACL_UNDEFINED_ID   (-1)
  576.  
  577. /* p_tag entry in struct posix_acl_entry */
  578. #define PVFS2_ACL_USER_OBJ    (0x01)
  579. #define PVFS2_ACL_USER        (0x02)
  580. #define PVFS2_ACL_GROUP_OBJ   (0x04)
  581. #define PVFS2_ACL_GROUP       (0x08)
  582. #define PVFS2_ACL_MASK        (0x10)
  583. #define PVFS2_ACL_OTHER       (0x20)
  584.  
  585. /* permissions in the p_perm field */
  586. #define PVFS2_ACL_READ       (0x04)
  587. #define PVFS2_ACL_WRITE      (0x02)
  588. #define PVFS2_ACL_EXECUTE    (0x01)
  589.  
  590. /* PVFS2 errors
  591.  *
  592.  * Errors are made up of a code to indicate the error type and a class
  593.  * that indicates where the error came from.  These are |'d together.
  594.  */
  595. int PVFS_strerror_r(int errnum, char *buf, int n);
  596. void PVFS_perror(const char *text, int retcode);
  597. void PVFS_perror_gossip(const char* text, int retcode);
  598. PVFS_error PVFS_get_errno_mapping(PVFS_error error);
  599. PVFS_error PVFS_errno_to_error(int err);
  600.  
  601. /* special bits used to differentiate PVFS error codes from system
  602.  * errno values
  603.  */
  604. #define PVFS_ERROR_BIT           (1 << 30)
  605. #define PVFS_NON_ERRNO_ERROR_BIT (1 << 29)
  606. #define IS_PVFS_ERROR(__error)            \
  607. ((__error)&(PVFS_ERROR_BIT))
  608. #define IS_PVFS_NON_ERRNO_ERROR(__error)  \
  609. (((__error)&(PVFS_NON_ERRNO_ERROR_BIT)) && IS_PVFS_ERROR(__error))
  610.  
  611. /* 7 bits are used for the errno mapped error codes */
  612. #define PVFS_ERROR_CODE(__error) \
  613. ((__error) & (PVFS_error)(0x7f|PVFS_ERROR_BIT))
  614. #define PVFS_ERROR_CLASS(__error) \
  615. ((__error) & ~((PVFS_error)(0x7f|PVFS_ERROR_BIT|PVFS_NON_ERRNO_ERROR_BIT)))
  616. #define PVFS_NON_ERRNO_ERROR_CODE(__error) \
  617. ((__error) & (PVFS_error)(127|PVFS_ERROR_BIT|PVFS_NON_ERRNO_ERROR_BIT))
  618.  
  619. #define PVFS_ERROR_BMI    (1 << 7) /* BMI-specific error */
  620. #define PVFS_ERROR_TROVE  (2 << 7) /* Trove-specific error */
  621. #define PVFS_ERROR_FLOW   (3 << 7)
  622. #define PVFS_ERROR_SM     (4 << 7) /* state machine specific error */
  623. #define PVFS_ERROR_SCHED  (5 << 7)
  624. #define PVFS_ERROR_CLIENT (6 << 7)
  625. #define PVFS_ERROR_DEV    (7 << 7) /* device file interaction */
  626.  
  627. #define PVFS_ERROR_CLASS_BITS                                          \
  628. (PVFS_ERROR_BMI | PVFS_ERROR_TROVE | PVFS_ERROR_FLOW | PVFS_ERROR_SM | \
  629.  PVFS_ERROR_SCHED | PVFS_ERROR_CLIENT | PVFS_ERROR_DEV)
  630.  
  631. /* a shorthand to make the error code definitions more readable */
  632. #define E(num) (num|PVFS_ERROR_BIT)
  633.  
  634. /* PVFS2 error codes, compliments of asm/errno.h */
  635. #define PVFS_EPERM            E(1) /* Operation not permitted */
  636. #define PVFS_ENOENT           E(2) /* No such file or directory */
  637. #define PVFS_EINTR            E(3) /* Interrupted system call */
  638. #define PVFS_EIO              E(4) /* I/O error */
  639. #define PVFS_ENXIO            E(5) /* No such device or address */
  640. #define PVFS_EBADF            E(6) /* Bad file number */
  641. #define PVFS_EAGAIN           E(7) /* Try again */
  642. #define PVFS_ENOMEM           E(8) /* Out of memory */
  643. #define PVFS_EFAULT           E(9) /* Bad address */
  644. #define PVFS_EBUSY           E(10) /* Device or resource busy */
  645. #define PVFS_EEXIST          E(11) /* File exists */
  646. #define PVFS_ENODEV          E(12) /* No such device */
  647. #define PVFS_ENOTDIR         E(13) /* Not a directory */
  648. #define PVFS_EISDIR          E(14) /* Is a directory */
  649. #define PVFS_EINVAL          E(15) /* Invalid argument */
  650. #define PVFS_EMFILE          E(16) /* Too many open files */
  651. #define PVFS_EFBIG           E(17) /* File too large */
  652. #define PVFS_ENOSPC          E(18) /* No space left on device */
  653. #define PVFS_EROFS           E(19) /* Read-only file system */
  654. #define PVFS_EMLINK          E(20) /* Too many links */
  655. #define PVFS_EPIPE           E(21) /* Broken pipe */
  656. #define PVFS_EDEADLK         E(22) /* Resource deadlock would occur */
  657. #define PVFS_ENAMETOOLONG    E(23) /* File name too long */
  658. #define PVFS_ENOLCK          E(24) /* No record locks available */
  659. #define PVFS_ENOSYS          E(25) /* Function not implemented */
  660. #define PVFS_ENOTEMPTY       E(26) /* Directory not empty */
  661. #define PVFS_ELOOP           E(27) /* Too many symbolic links encountered */
  662. #define PVFS_EWOULDBLOCK     E(28) /* Operation would block */
  663. #define PVFS_ENOMSG          E(29) /* No message of desired type */
  664. #define PVFS_EUNATCH         E(30) /* Protocol driver not attached */
  665. #define PVFS_EBADR           E(31) /* Invalid request descriptor */
  666. #define PVFS_EDEADLOCK       E(32)
  667. #define PVFS_ENODATA         E(33) /* No data available */
  668. #define PVFS_ETIME           E(34) /* Timer expired */
  669. #define PVFS_ENONET          E(35) /* Machine is not on the network */
  670. #define PVFS_EREMOTE         E(36) /* Object is remote */
  671. #define PVFS_ECOMM           E(37) /* Communication error on send */
  672. #define PVFS_EPROTO          E(38) /* Protocol error */
  673. #define PVFS_EBADMSG         E(39) /* Not a data message */
  674. #define PVFS_EOVERFLOW       E(40) /* Value too large for defined data type */
  675. #define PVFS_ERESTART        E(41) /* Interrupted system call should be restarted */
  676. #define PVFS_EMSGSIZE        E(42) /* Message too long */
  677. #define PVFS_EPROTOTYPE      E(43) /* Protocol wrong type for socket */
  678. #define PVFS_ENOPROTOOPT     E(44) /* Protocol not available */
  679. #define PVFS_EPROTONOSUPPORT E(45) /* Protocol not supported */
  680. #define PVFS_EOPNOTSUPP      E(46) /* Operation not supported on transport endpoint */
  681. #define PVFS_EADDRINUSE      E(47) /* Address already in use */
  682. #define PVFS_EADDRNOTAVAIL   E(48) /* Cannot assign requested address */
  683. #define PVFS_ENETDOWN        E(49) /* Network is down */
  684. #define PVFS_ENETUNREACH     E(50) /* Network is unreachable */
  685. #define PVFS_ENETRESET       E(51) /* Network dropped connection because of reset */
  686. #define PVFS_ENOBUFS         E(52) /* No buffer space available */
  687. #define PVFS_ETIMEDOUT       E(53) /* Connection timed out */
  688. #define PVFS_ECONNREFUSED    E(54) /* Connection refused */
  689. #define PVFS_EHOSTDOWN       E(55) /* Host is down */
  690. #define PVFS_EHOSTUNREACH    E(56) /* No route to host */
  691. #define PVFS_EALREADY        E(57) /* Operation already in progress */
  692. #define PVFS_EACCES          E(58) /* Access not allowed */
  693. #define PVFS_ECONNRESET      E(59) /* Connection reset by peer */
  694.  
  695. /***************** non-errno/pvfs2 specific error codes *****************/
  696. #define PVFS_ECANCEL    (1|(PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT))
  697. #define PVFS_EDEVINIT   (2|(PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT))
  698. #define PVFS_EDETAIL    (3|(PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT))
  699. #define PVFS_EHOSTNTFD  (4|(PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT))
  700. #define PVFS_EADDRNTFD  (5|(PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT))
  701. #define PVFS_ENORECVR   (6|(PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT))
  702. #define PVFS_ETRYAGAIN  (7|(PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT))
  703.  
  704. /* NOTE: PLEASE DO NOT ARBITRARILY ADD NEW ERRNO ERROR CODES!
  705.  *
  706.  * IF YOU CHOOSE TO ADD A NEW ERROR CODE (DESPITE OUR PLEA), YOU ALSO
  707.  * NEED TO INCREMENT PVFS_ERRNO MAX (BELOW) AND ADD A MAPPING TO A
  708.  * UNIX ERRNO VALUE IN THE MACROS BELOW (USED IN
  709.  * src/common/misc/errno-mapping.c and the kernel module)
  710.  */
  711. #define PVFS_ERRNO_MAX          60
  712.  
  713. /*
  714.  * If system headers do not define these, assign them, with arbitrary
  715.  * numbers.  These values must be unique with respect to defined errors
  716.  * and each other to avoid collisions in case statements elsewhere.
  717.  */
  718. #ifndef EUNATCH
  719. #define EUNATCH -6060842
  720. #endif
  721.  
  722. #ifndef EBADR
  723. #define EBADR -6060843
  724. #endif
  725.  
  726. #ifndef EDEADLOCK
  727. #define EDEADLOCK -6060844
  728. #endif
  729.  
  730. #ifndef ENONET
  731. #define ENONET -6060845
  732. #endif
  733.  
  734. #ifndef ECOMM
  735. #define ECOMM -6060846
  736. #endif
  737.  
  738. #ifndef ERESTART
  739. #define ERESTART -6060847
  740. #endif
  741.  
  742. #ifndef ETIME
  743. #define ETIME -6060848
  744. #endif
  745.  
  746. #ifndef EBADMSG
  747. #define EBADMSG -6060849
  748. #endif
  749.  
  750. #define DECLARE_ERRNO_MAPPING()                       \
  751. PVFS_error PINT_errno_mapping[PVFS_ERRNO_MAX + 1] = { \
  752.     0,     /* leave this one empty */                 \
  753.     EPERM, /* 1 */                                    \
  754.     ENOENT,                                           \
  755.     EINTR,                                            \
  756.     EIO,                                              \
  757.     ENXIO,                                            \
  758.     EBADF,                                            \
  759.     EAGAIN,                                           \
  760.     ENOMEM,                                           \
  761.     EFAULT,                                           \
  762.     EBUSY, /* 10 */                                   \
  763.     EEXIST,                                           \
  764.     ENODEV,                                           \
  765.     ENOTDIR,                                          \
  766.     EISDIR,                                           \
  767.     EINVAL,                                           \
  768.     EMFILE,                                           \
  769.     EFBIG,                                            \
  770.     ENOSPC,                                           \
  771.     EROFS,                                            \
  772.     EMLINK, /* 20 */                                  \
  773.     EPIPE,                                            \
  774.     EDEADLK,                                          \
  775.     ENAMETOOLONG,                                     \
  776.     ENOLCK,                                           \
  777.     ENOSYS,                                           \
  778.     ENOTEMPTY,                                        \
  779.     ELOOP,                                            \
  780.     EWOULDBLOCK,                                      \
  781.     ENOMSG,                                           \
  782.     EUNATCH, /* 30 */                                 \
  783.     EBADR,                                            \
  784.     EDEADLOCK,                                        \
  785.     ENODATA,                                          \
  786.     ETIME,                                            \
  787.     ENONET,                                           \
  788.     EREMOTE,                                          \
  789.     ECOMM,                                            \
  790.     EPROTO,                                           \
  791.     EBADMSG,                                          \
  792.     EOVERFLOW, /* 40 */                               \
  793.     ERESTART,                                         \
  794.     EMSGSIZE,                                         \
  795.     EPROTOTYPE,                                       \
  796.     ENOPROTOOPT,                                      \
  797.     EPROTONOSUPPORT,                                  \
  798.     EOPNOTSUPP,                                       \
  799.     EADDRINUSE,                                       \
  800.     EADDRNOTAVAIL,                                    \
  801.     ENETDOWN,                                         \
  802.     ENETUNREACH, /* 50 */                             \
  803.     ENETRESET,                                        \
  804.     ENOBUFS,                                          \
  805.     ETIMEDOUT,                                        \
  806.     ECONNREFUSED,                                     \
  807.     EHOSTDOWN,                                        \
  808.     EHOSTUNREACH,                                     \
  809.     EALREADY,                                         \
  810.     EACCES,                                           \
  811.     ECONNRESET,   /* 59 */                            \
  812.     0         /* PVFS_ERRNO_MAX */                    \
  813. };                                                    \
  814. const char *PINT_non_errno_strerror_mapping[] = {     \
  815.     "Success", /* 0 */                                \
  816.     "Operation cancelled (possibly due to timeout)",  \
  817.     "Device initialization failed",                   \
  818.     "Detailed per-server errors are available",       \
  819.     "Unknown host",                                   \
  820.     "No address associated with name",                \
  821.     "Unknown server error",                           \
  822.     "Host name lookup failure",                       \
  823. };                                                    \
  824. PVFS_error PINT_non_errno_mapping[] = {               \
  825.     0,     /* leave this one empty */                 \
  826.     PVFS_ECANCEL,   /* 1 */                           \
  827.     PVFS_EDEVINIT,  /* 2 */                           \
  828.     PVFS_EDETAIL,   /* 3 */                           \
  829.     PVFS_EHOSTNTFD, /* 4 */                           \
  830.     PVFS_EADDRNTFD, /* 5 */                           \
  831.     PVFS_ENORECVR,  /* 6 */                           \
  832.     PVFS_ETRYAGAIN, /* 7 */                           \
  833. }
  834.  
  835. /*
  836.   NOTE: PVFS_get_errno_mapping will convert a PVFS_ERROR_CODE to an
  837.   errno value.  If the error code is a pvfs2 specific error code
  838.   (i.e. a PVFS_NON_ERRNO_ERROR_CODE), PVFS_get_errno_mapping will
  839.   return an index into the PINT_non_errno_strerror_mapping array which
  840.   can be used for getting the pvfs2 specific strerror message given
  841.   the error code.  if the value is not a recognized error code, the
  842.   passed in value will be returned unchanged.
  843. */
  844. #define DECLARE_ERRNO_MAPPING_AND_FN()                     \
  845. extern PVFS_error PINT_errno_mapping[];                    \
  846. extern PVFS_error PINT_non_errno_mapping[];                \
  847. extern const char *PINT_non_errno_strerror_mapping[];      \
  848. PVFS_error PVFS_get_errno_mapping(PVFS_error error)        \
  849. {                                                          \
  850.     PVFS_error ret = error, mask = 0;                      \
  851.     int32_t positive = ((error > -1) ? 1 : 0);             \
  852.     if (IS_PVFS_NON_ERRNO_ERROR((positive? error: -error)))\
  853.     {                                                      \
  854.     mask = (PVFS_NON_ERRNO_ERROR_BIT | PVFS_ERROR_BIT |    \
  855.             PVFS_ERROR_CLASS_BITS);                        \
  856.     ret = PVFS_NON_ERRNO_ERROR_CODE(                       \
  857.           ((positive ? error : abs(error))) & ~mask);      \
  858.     }                                                      \
  859.     else if (IS_PVFS_ERROR((positive? error: -error)))     \
  860.     {                                                      \
  861.     mask = (PVFS_ERROR_BIT | PVFS_ERROR_CLASS_BITS);       \
  862.     ret = PINT_errno_mapping[                              \
  863.         PVFS_ERROR_CODE(((positive ? error :               \
  864.                              abs(error))) & ~mask)];       \
  865.     }                                                      \
  866.     return ret;                                       \
  867. }                                                          \
  868. PVFS_error PVFS_errno_to_error(int err)                    \
  869. {                                                          \
  870.     PVFS_error e = 0;                                      \
  871.     \
  872.     for(; e < PVFS_ERRNO_MAX; ++e)                         \
  873.     {                                                      \
  874.         if(PINT_errno_mapping[e] == err)                   \
  875.         {                                                  \
  876.             return e;                                      \
  877.         }                                                  \
  878.     }                                                      \
  879.     return 0;                                              \
  880. }                                                          \
  881. DECLARE_ERRNO_MAPPING()
  882. #define PVFS_ERROR_TO_ERRNO(__error) PVFS_get_errno_mapping(__error)
  883.  
  884. /** These structures/calls are used when returning detailed lists of
  885.  *  errors from a particular call.  This is done to report on specific,
  886.  *  per-server failures.
  887.  */
  888. typedef struct
  889. {
  890.     PVFS_error error;
  891.     PVFS_BMI_addr_t addr;
  892. } PVFS_error_server;
  893.  
  894. typedef struct
  895. {
  896.     int count_allocated;
  897.     int count_used;
  898.     int count_exceeded; /* set if we ran out of space for errors */
  899.     /* structure is alloc'd larger for more errors */
  900.     PVFS_error_server error[1];
  901. } PVFS_error_details;
  902.  
  903. PVFS_error_details *PVFS_error_details_new(int count);
  904. void PVFS_error_details_free(PVFS_error_details *details);
  905.  
  906. /** PVFS I/O operation types, used in both system and server interfaces.
  907.  */
  908. enum PVFS_io_type
  909. {
  910.     PVFS_IO_READ  = 1,
  911.     PVFS_IO_WRITE = 2
  912. };
  913.  
  914. /*
  915.  * Filesystem "magic" number unique to PVFS2 kernel interface.  Used by
  916.  * ROMIO to auto-detect access method given a mounted path.
  917.  */
  918. #define PVFS2_SUPER_MAGIC 0x20030528
  919.  
  920. /* flag value that can be used with mgmt_iterate_handles to retrieve
  921.  * reserved handle values
  922.  */
  923. #define PVFS_MGMT_RESERVED 1
  924.  
  925. /*
  926.  * Structure and macros for timing things for profile-like output.
  927.  *
  928.  */
  929. struct profiler
  930. {
  931.     struct  timeval  start;
  932.     struct  timeval  finish;
  933.     uint64_t  save_timing;
  934. };
  935.  
  936. #define INIT_PROFILER(prof_struct) prof_struct.cumulative_diff = 0;
  937.  
  938. #define START_PROFILER(prof_struct) \
  939.     gettimeofday(&prof_struct.start, NULL);
  940.  
  941. #define FINISH_PROFILER(label, prof_struct, print_timing) \
  942. { \
  943.     double t_start, t_finish; \
  944.     gettimeofday(&prof_struct.finish, NULL); \
  945.     t_start = prof_struct.start.tv_sec + (prof_struct.start.tv_usec/1000000.0); \
  946.     t_finish = prof_struct.finish.tv_sec + (prof_struct.finish.tv_usec/1000000.0); \
  947.     prof_struct.save_timing = t_finish - t_start * 1000000.0; \
  948.     if (print_timing) { \
  949.       gossip_err("PROFILING %s: %f\n", label, t_finish - t_start); \
  950.     } \
  951. }
  952.  
  953. #define PRINT_PROFILER(label, prof_struct) \
  954.       gossip_err("PROFILING %s: %f\n", label, prof_struct.save_timing / 1000000.0);
  955.  
  956.  
  957. #endif /* __PVFS2_TYPES_H */
  958.  
  959. /*
  960.  * Local variables:
  961.  *  c-indent-level: 4
  962.  *  c-basic-offset: 4
  963.  * End:
  964.  *
  965.  * vim: ts=8 sts=4 sw=4 expandtab
  966.  */
  967.