root/branches/cu-security-branch/include/pvfs2-types.h @ 8397

Revision 8397, 34.9 KB (checked in by nlmills, 3 years ago)

initial merge with Orange-Branch. much will be broken

Line 
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. */
66typedef uint8_t PVFS_boolean;
67typedef int32_t PVFS_error;
68typedef int64_t PVFS_offset;
69typedef int64_t PVFS_size;
70typedef int64_t PVFS_id_gen_t;
71
72/** Opaque value representing a destination address. */
73typedef int64_t PVFS_BMI_addr_t;
74
75inline void encode_PVFS_BMI_addr_t(char **pptr, const PVFS_BMI_addr_t *x);
76inline int encode_PVFS_BMI_addr_t_size_check(const PVFS_BMI_addr_t *x);
77inline 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. */
89typedef int32_t PVFS_msg_tag_t;
90typedef PVFS_id_gen_t PVFS_context_id;
91
92enum 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 */
101enum 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 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. */
124typedef 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 */
130typedef int32_t PVFS_fs_id;
131typedef uint64_t PVFS_ds_position;
132typedef 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. */
143typedef uint32_t PVFS_uid;
144typedef uint32_t PVFS_gid;
145typedef uint64_t PVFS_time;
146typedef uint32_t PVFS_permissions;
147typedef 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 */
160typedef struct
161{
162    PVFS_handle first;
163    PVFS_handle last;
164} PVFS_handle_extent;
165endecode_fields_2(
166    PVFS_handle_extent,
167    PVFS_handle, first,
168    PVFS_handle, last);
169
170/* an array of contiguous ranges of handles */
171typedef struct
172{
173    uint32_t extent_count;
174    PVFS_handle_extent *extent_array;
175} PVFS_handle_extent_array;
176endecode_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 */
185enum 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 */
205struct 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 */
216typedef 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
228inline void encode_PVFS_sys_layout(char **pptr, const struct PVFS_sys_layout_s *x);
229inline 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. */
275typedef enum
276{
277    PVFS_TYPE_NONE =              0,
278    PVFS_TYPE_METAFILE =    (1 << 0),
279    PVFS_TYPE_DATAFILE =    (1 << 1),
280    PVFS_TYPE_DIRECTORY =   (1 << 2),
281    PVFS_TYPE_SYMLINK =     (1 << 3),
282    PVFS_TYPE_DIRDATA =     (1 << 4),
283    PVFS_TYPE_INTERNAL =    (1 << 5)   /* for the server's private use */
284} PVFS_ds_type;
285
286#define decode_PVFS_ds_type decode_enum
287#define encode_PVFS_ds_type encode_enum
288
289#ifdef __KERNEL__
290#include <linux/fs.h>
291#endif
292
293
294/*The value for PVFS_MIRROR_FL will not conflict with the FS values.*/
295#if defined(FS_IMMUTABLE_FL)
296
297#define PVFS_IMMUTABLE_FL FS_IMMUTABLE_FL
298#define PVFS_APPEND_FL    FS_APPEND_FL
299#define PVFS_NOATIME_FL   FS_NOATIME_FL
300#define PVFS_MIRROR_FL    0x01000000ULL
301
302#else
303
304/* PVFS Object Flags (PVFS_flags); Add more as we implement them */
305#define PVFS_IMMUTABLE_FL 0x10ULL
306#define PVFS_APPEND_FL    0x20ULL
307#define PVFS_NOATIME_FL   0x80ULL
308#define PVFS_MIRROR_FL    0x01000000ULL
309
310#endif
311
312/* Key/Value Pairs */
313/* Extended attributes are stored on objects with */
314/* a Key/Value pair.  A key or a value is simply */
315/* a byte string of some length.  Keys are normally */
316/* strings, and thus are printable ASCII and NULL */
317/* terminated.  Values are any sequence of bytes */
318/* and are user interpreted.  This struct represents */
319/* EITHER a key or a value.  This struct is IDENTICAL */
320/* to a TROVE_keyval_s defined in src/io/trove/trove-types.h */
321/* but is duplicated here to maintain separation between */
322/* the Trove implementation and PVFS2.  This struct should */
323/* be used everywhere but within Trove. WBL 6/2005*/
324typedef struct PVFS_ds_keyval_s
325{
326        void *buffer;      /* points to actual key or value */
327        int32_t buffer_sz; /* the size of the area pointed to by buffer */
328        int32_t read_sz;   /* when reading, the actual number of bytes read */
329                           /* only valid after a read */
330} PVFS_ds_keyval;
331
332typedef struct
333{
334    uint32_t count;
335} PVFS_ds_keyval_handle_info;
336
337/* attribute masks used by system interface callers */
338#define PVFS_ATTR_SYS_SIZE                  (1 << 20)
339#define PVFS_ATTR_SYS_LNK_TARGET            (1 << 24)
340#define PVFS_ATTR_SYS_DFILE_COUNT           (1 << 25)
341#define PVFS_ATTR_SYS_DIRENT_COUNT          (1 << 26)
342#define PVFS_ATTR_SYS_DIR_HINT              (1 << 27)
343#define PVFS_ATTR_SYS_BLKSIZE               (1 << 28)
344#define PVFS_ATTR_SYS_MIRROR_COPIES_COUNT   (1 << 29)
345#define PVFS_ATTR_SYS_CAPABILITY            (1 << 30)
346#define PVFS_ATTR_SYS_UID                   (1 << 0)
347#define PVFS_ATTR_SYS_GID                   (1 << 1)
348#define PVFS_ATTR_SYS_PERM                  (1 << 2)
349#define PVFS_ATTR_SYS_ATIME                 (1 << 3)
350#define PVFS_ATTR_SYS_CTIME                 (1 << 4)
351#define PVFS_ATTR_SYS_MTIME                 (1 << 5)
352#define PVFS_ATTR_SYS_TYPE                  (1 << 6)
353#define PVFS_ATTR_SYS_ATIME_SET             (1 << 7)
354#define PVFS_ATTR_SYS_MTIME_SET             (1 << 8)
355#define PVFS_ATTR_SYS_COMMON_ALL \
356(PVFS_ATTR_SYS_UID   | PVFS_ATTR_SYS_GID   | \
357 PVFS_ATTR_SYS_PERM  | PVFS_ATTR_SYS_ATIME | \
358 PVFS_ATTR_SYS_CTIME | PVFS_ATTR_SYS_MTIME | \
359 PVFS_ATTR_SYS_TYPE)
360
361#define PVFS_ATTR_SYS_ALL                    \
362(PVFS_ATTR_SYS_COMMON_ALL | PVFS_ATTR_SYS_SIZE | \
363 PVFS_ATTR_SYS_LNK_TARGET | PVFS_ATTR_SYS_DFILE_COUNT | \
364 PVFS_ATTR_SYS_MIRROR_COPIES_COUNT | \
365 PVFS_ATTR_SYS_DIRENT_COUNT | PVFS_ATTR_SYS_DIR_HINT | PVFS_ATTR_SYS_BLKSIZE)
366#define PVFS_ATTR_SYS_ALL_NOHINT                \
367(PVFS_ATTR_SYS_COMMON_ALL | PVFS_ATTR_SYS_SIZE | \
368 PVFS_ATTR_SYS_LNK_TARGET | PVFS_ATTR_SYS_DFILE_COUNT | \
369 PVFS_ATTR_SYS_MIRROR_COPIES_COUNT | \
370 PVFS_ATTR_SYS_DIRENT_COUNT | PVFS_ATTR_SYS_BLKSIZE)
371#define PVFS_ATTR_SYS_ALL_NOSIZE                   \
372(PVFS_ATTR_SYS_COMMON_ALL | PVFS_ATTR_SYS_LNK_TARGET | \
373 PVFS_ATTR_SYS_DFILE_COUNT | PVFS_ATTR_SYS_DIRENT_COUNT | \
374 PVFS_ATTR_SYS_MIRROR_COPIES_COUNT | \
375 PVFS_ATTR_SYS_DIR_HINT | PVFS_ATTR_SYS_BLKSIZE)
376#define PVFS_ATTR_SYS_ALL_SETABLE \
377(PVFS_ATTR_SYS_COMMON_ALL-PVFS_ATTR_SYS_TYPE)
378#define PVFS_ATTR_SYS_ALL_TIMES \
379((PVFS_ATTR_SYS_COMMON_ALL-PVFS_ATTR_SYS_TYPE) | PVFS_ATTR_SYS_ATIME_SET | PVFS_ATTR_SYS_MTIME_SET)
380
381/* Extended attribute flags */
382#define PVFS_XATTR_CREATE  0x1
383#define PVFS_XATTR_REPLACE 0x2
384
385/** statfs and misc. server statistic information. */
386typedef struct
387{
388    PVFS_fs_id fs_id;
389    PVFS_size bytes_available;
390    PVFS_size bytes_total;
391    uint64_t ram_total_bytes;
392    uint64_t ram_free_bytes;
393    uint64_t load_1;
394    uint64_t load_5;
395    uint64_t load_15;
396    uint64_t uptime_seconds;
397    uint64_t handles_available_count;
398    uint64_t handles_total_count;
399} PVFS_statfs;
400endecode_fields_12(
401    PVFS_statfs,
402    skip4,,
403    PVFS_fs_id, fs_id,
404    PVFS_size, bytes_available,
405    PVFS_size, bytes_total,
406    uint64_t, ram_total_bytes,
407    uint64_t, ram_free_bytes,
408    uint64_t, load_1,
409    uint64_t, load_5,
410    uint64_t, load_15,
411    uint64_t, uptime_seconds,
412    uint64_t, handles_available_count,
413    uint64_t, handles_total_count);
414
415/** object reference (uniquely refers to a single file, directory, or
416    symlink).
417*/
418typedef struct
419{
420    PVFS_handle handle;
421    PVFS_fs_id fs_id;
422    int32_t    __pad1;
423} PVFS_object_ref;
424
425/* max length of BMI style URI's for identifying servers */
426#define PVFS_MAX_SERVER_ADDR_LEN 256
427/* max length of PVFS filename */
428#define PVFS_NAME_MAX            256
429/* max len of individual path element */
430#define PVFS_SEGMENT_MAX         PVFS_NAME_MAX
431
432/* max extended attribute name len as imposed by the VFS and exploited for the
433 * upcall request types.
434 * NOTE: Please retain them as multiples of 8 even if you wish to change them
435 * This is *NECESSARY* for supporting 32 bit user-space binaries on a 64-bit kernel.
436 */
437#define PVFS_MAX_XATTR_NAMELEN   256 /* Not the same as XATTR_NAME_MAX defined
438                                        by <linux/xattr.h> */
439#define PVFS_MAX_XATTR_VALUELEN  8192 /* Not the same as XATTR_SIZE_MAX defined
440                                        by <linux/xattr.h> */
441#define PVFS_MAX_XATTR_LISTLEN   8  /* Not the same as XATTR_LIST_MAX
442                                          defined by <linux/xattr.h> */
443
444/* This structure is used by the VFS-client interaction alone */
445typedef struct {
446    char key[PVFS_MAX_XATTR_NAMELEN];
447    int32_t  key_sz; /* int32_t for portable, fixed-size structures */
448    int32_t  val_sz;
449    char val[PVFS_MAX_XATTR_VALUELEN];
450} PVFS_keyval_pair;
451
452/** Directory entry contents. */
453typedef struct
454{
455    char d_name[PVFS_NAME_MAX + 1];
456    PVFS_handle handle;
457} PVFS_dirent;
458endecode_fields_2(
459    PVFS_dirent,
460    here_string, d_name,
461    PVFS_handle, handle);
462
463/** Predefined server parameters that can be manipulated at run-time
464 *  through the mgmt interface.
465 */
466enum PVFS_server_param
467{
468    PVFS_SERV_PARAM_INVALID = 0,
469    PVFS_SERV_PARAM_GOSSIP_MASK = 1, /* gossip debugging on or off */
470    PVFS_SERV_PARAM_FSID_CHECK = 2,  /* verify that an fsid is ok */
471    PVFS_SERV_PARAM_ROOT_CHECK = 3,  /* verify existance of root handle */
472    PVFS_SERV_PARAM_MODE = 4,        /* change the current server mode */
473    PVFS_SERV_PARAM_EVENT_ENABLE = 5,    /* event enable */
474    PVFS_SERV_PARAM_EVENT_DISABLE = 6, /* event disable */
475    PVFS_SERV_PARAM_SYNC_META = 7,   /* metadata sync flags */
476    PVFS_SERV_PARAM_SYNC_DATA = 8,   /* file data sync flags */
477    PVFS_SERV_PARAM_DROP_CACHES = 9
478};
479
480enum PVFS_mgmt_param_type
481{
482    PVFS_MGMT_PARAM_TYPE_UINT64,
483    PVFS_MGMT_PARAM_TYPE_STRING
484} ;
485
486struct PVFS_mgmt_setparam_value
487{
488    enum PVFS_mgmt_param_type type;
489    union
490    {
491        uint64_t value;
492        char *string_value;
493    } u;
494};
495
496encode_enum_union_2_struct(
497    PVFS_mgmt_setparam_value,
498    type, u,
499    uint64_t, value,        PVFS_MGMT_PARAM_TYPE_UINT64,
500    string,   string_value, PVFS_MGMT_PARAM_TYPE_STRING);
501
502enum PVFS_server_mode
503{
504    PVFS_SERVER_NORMAL_MODE = 1,      /* default server operating mode */
505    PVFS_SERVER_ADMIN_MODE = 2        /* administrative mode */
506};
507
508/* PVFS2 ACL structures */
509typedef struct {
510    int32_t  p_tag;
511    uint32_t p_perm;
512    uint32_t p_id;
513} pvfs2_acl_entry;
514
515/* These defines match that of the POSIX defines */
516#define PVFS2_ACL_UNDEFINED_ID   (-1)
517
518/* p_tag entry in struct posix_acl_entry */
519#define PVFS2_ACL_USER_OBJ    (0x01)
520#define PVFS2_ACL_USER        (0x02)
521#define PVFS2_ACL_GROUP_OBJ   (0x04)
522#define PVFS2_ACL_GROUP       (0x08)
523#define PVFS2_ACL_MASK        (0x10)
524#define PVFS2_ACL_OTHER       (0x20)
525
526/* permissions in the p_perm field */
527#define PVFS2_ACL_READ       (0x04)
528#define PVFS2_ACL_WRITE      (0x02)
529#define PVFS2_ACL_EXECUTE    (0x01)
530
531/* PVFS2 errors
532 *
533 * Errors are made up of a code to indicate the error type and a class
534 * that indicates where the error came from.  These are |'d together.
535 */
536int PVFS_strerror_r(int errnum, char *buf, int n);
537void PVFS_perror(const char *text, int retcode);
538void PVFS_perror_gossip(const char* text, int retcode);
539PVFS_error PVFS_get_errno_mapping(PVFS_error error);
540PVFS_error PVFS_errno_to_error(int err);
541
542/* special bits used to differentiate PVFS error codes from system
543 * errno values
544 */
545#define PVFS_ERROR_BIT           (1 << 30)
546#define PVFS_NON_ERRNO_ERROR_BIT (1 << 29)
547#define IS_PVFS_ERROR(__error)            \
548((__error)&(PVFS_ERROR_BIT))
549#define IS_PVFS_NON_ERRNO_ERROR(__error)  \
550(((__error)&(PVFS_NON_ERRNO_ERROR_BIT)) && IS_PVFS_ERROR(__error))
551
552/* 7 bits are used for the errno mapped error codes */
553#define PVFS_ERROR_CODE(__error) \
554((__error) & (PVFS_error)(0x7f|PVFS_ERROR_BIT))
555#define PVFS_ERROR_CLASS(__error) \
556((__error) & ~((PVFS_error)(0x7f|PVFS_ERROR_BIT|PVFS_NON_ERRNO_ERROR_BIT)))
557#define PVFS_NON_ERRNO_ERROR_CODE(__error) \
558((__error) & (PVFS_error)(127|PVFS_ERROR_BIT|PVFS_NON_ERRNO_ERROR_BIT))
559
560#define PVFS_ERROR_BMI    (1 << 7) /* BMI-specific error */
561#define PVFS_ERROR_TROVE  (2 << 7) /* Trove-specific error */
562#define PVFS_ERROR_FLOW   (3 << 7)
563#define PVFS_ERROR_SM     (4 << 7) /* state machine specific error */
564#define PVFS_ERROR_SCHED  (5 << 7)
565#define PVFS_ERROR_CLIENT (6 << 7)
566#define PVFS_ERROR_DEV    (7 << 7) /* device file interaction */
567
568#define PVFS_ERROR_CLASS_BITS                                          \
569(PVFS_ERROR_BMI | PVFS_ERROR_TROVE | PVFS_ERROR_FLOW | PVFS_ERROR_SM | \
570 PVFS_ERROR_SCHED | PVFS_ERROR_CLIENT | PVFS_ERROR_DEV)
571
572/* a shorthand to make the error code definitions more readable */
573#define E(num) (num|PVFS_ERROR_BIT)
574
575/* PVFS2 error codes, compliments of asm/errno.h */
576#define PVFS_EPERM            E(1) /* Operation not permitted */
577#define PVFS_ENOENT           E(2) /* No such file or directory */
578#define PVFS_EINTR            E(3) /* Interrupted system call */
579#define PVFS_EIO              E(4) /* I/O error */
580#define PVFS_ENXIO            E(5) /* No such device or address */
581#define PVFS_EBADF            E(6) /* Bad file number */
582#define PVFS_EAGAIN           E(7) /* Try again */
583#define PVFS_ENOMEM           E(8) /* Out of memory */
584#define PVFS_EFAULT           E(9) /* Bad address */
585#define PVFS_EBUSY           E(10) /* Device or resource busy */
586#define PVFS_EEXIST          E(11) /* File exists */
587#define PVFS_ENODEV          E(12) /* No such device */
588#define PVFS_ENOTDIR         E(13) /* Not a directory */
589#define PVFS_EISDIR          E(14) /* Is a directory */
590#define PVFS_EINVAL          E(15) /* Invalid argument */
591#define PVFS_EMFILE          E(16) /* Too many open files */
592#define PVFS_EFBIG           E(17) /* File too large */
593#define PVFS_ENOSPC          E(18) /* No space left on device */
594#define PVFS_EROFS           E(19) /* Read-only file system */
595#define PVFS_EMLINK          E(20) /* Too many links */
596#define PVFS_EPIPE           E(21) /* Broken pipe */
597#define PVFS_EDEADLK         E(22) /* Resource deadlock would occur */
598#define PVFS_ENAMETOOLONG    E(23) /* File name too long */
599#define PVFS_ENOLCK          E(24) /* No record locks available */
600#define PVFS_ENOSYS          E(25) /* Function not implemented */
601#define PVFS_ENOTEMPTY       E(26) /* Directory not empty */
602#define PVFS_ELOOP           E(27) /* Too many symbolic links encountered */
603#define PVFS_EWOULDBLOCK     E(28) /* Operation would block */
604#define PVFS_ENOMSG          E(29) /* No message of desired type */
605#define PVFS_EUNATCH         E(30) /* Protocol driver not attached */
606#define PVFS_EBADR           E(31) /* Invalid request descriptor */
607#define PVFS_EDEADLOCK       E(32)
608#define PVFS_ENODATA         E(33) /* No data available */
609#define PVFS_ETIME           E(34) /* Timer expired */
610#define PVFS_ENONET          E(35) /* Machine is not on the network */
611#define PVFS_EREMOTE         E(36) /* Object is remote */
612#define PVFS_ECOMM           E(37) /* Communication error on send */
613#define PVFS_EPROTO          E(38) /* Protocol error */
614#define PVFS_EBADMSG         E(39) /* Not a data message */
615#define PVFS_EOVERFLOW       E(40) /* Value too large for defined data type */
616#define PVFS_ERESTART        E(41) /* Interrupted system call should be restarted */
617#define PVFS_EMSGSIZE        E(42) /* Message too long */
618#define PVFS_EPROTOTYPE      E(43) /* Protocol wrong type for socket */
619#define PVFS_ENOPROTOOPT     E(44) /* Protocol not available */
620#define PVFS_EPROTONOSUPPORT E(45) /* Protocol not supported */
621#define PVFS_EOPNOTSUPP      E(46) /* Operation not supported on transport endpoint */
622#define PVFS_EADDRINUSE      E(47) /* Address already in use */
623#define PVFS_EADDRNOTAVAIL   E(48) /* Cannot assign requested address */
624#define PVFS_ENETDOWN        E(49) /* Network is down */
625#define PVFS_ENETUNREACH     E(50) /* Network is unreachable */
626#define PVFS_ENETRESET       E(51) /* Network dropped connection because of reset */
627#define PVFS_ENOBUFS         E(52) /* No buffer space available */
628#define PVFS_ETIMEDOUT       E(53) /* Connection timed out */
629#define PVFS_ECONNREFUSED    E(54) /* Connection refused */
630#define PVFS_EHOSTDOWN       E(55) /* Host is down */
631#define PVFS_EHOSTUNREACH    E(56) /* No route to host */
632#define PVFS_EALREADY        E(57) /* Operation already in progress */
633#define PVFS_EACCES          E(58) /* Access not allowed */
634#define PVFS_ECONNRESET      E(59) /* Connection reset by peer */
635
636/***************** non-errno/pvfs2 specific error codes *****************/
637#define PVFS_ECANCEL    (1|(PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT))
638#define PVFS_EDEVINIT   (2|(PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT))
639#define PVFS_EDETAIL    (3|(PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT))
640#define PVFS_EHOSTNTFD  (4|(PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT))
641#define PVFS_EADDRNTFD  (5|(PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT))
642#define PVFS_ENORECVR   (6|(PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT))
643#define PVFS_ETRYAGAIN  (7|(PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT))
644
645/* NOTE: PLEASE DO NOT ARBITRARILY ADD NEW ERRNO ERROR CODES!
646 *
647 * IF YOU CHOOSE TO ADD A NEW ERROR CODE (DESPITE OUR PLEA), YOU ALSO
648 * NEED TO INCREMENT PVFS_ERRNO MAX (BELOW) AND ADD A MAPPING TO A
649 * UNIX ERRNO VALUE IN THE MACROS BELOW (USED IN
650 * src/common/misc/errno-mapping.c and the kernel module)
651 */
652#define PVFS_ERRNO_MAX          60
653
654/*
655 * If system headers do not define these, assign them, with arbitrary
656 * numbers.  These values must be unique with respect to defined errors
657 * and each other to avoid collisions in case statements elsewhere.
658 */
659#ifndef EUNATCH
660#define EUNATCH -6060842
661#endif
662
663#ifndef EBADR
664#define EBADR -6060843
665#endif
666
667#ifndef EDEADLOCK
668#define EDEADLOCK -6060844
669#endif
670
671#ifndef ENONET
672#define ENONET -6060845
673#endif
674
675#ifndef ECOMM
676#define ECOMM -6060846
677#endif
678
679#ifndef ERESTART
680#define ERESTART -6060847
681#endif
682
683#ifndef ETIME
684#define ETIME -6060848
685#endif
686
687#ifndef EBADMSG
688#define EBADMSG -6060849
689#endif
690
691#define DECLARE_ERRNO_MAPPING()                       \
692PVFS_error PINT_errno_mapping[PVFS_ERRNO_MAX + 1] = { \
693    0,     /* leave this one empty */                 \
694    EPERM, /* 1 */                                    \
695    ENOENT,                                           \
696    EINTR,                                            \
697    EIO,                                              \
698    ENXIO,                                            \
699    EBADF,                                            \
700    EAGAIN,                                           \
701    ENOMEM,                                           \
702    EFAULT,                                           \
703    EBUSY, /* 10 */                                   \
704    EEXIST,                                           \
705    ENODEV,                                           \
706    ENOTDIR,                                          \
707    EISDIR,                                           \
708    EINVAL,                                           \
709    EMFILE,                                           \
710    EFBIG,                                            \
711    ENOSPC,                                           \
712    EROFS,                                            \
713    EMLINK, /* 20 */                                  \
714    EPIPE,                                            \
715    EDEADLK,                                          \
716    ENAMETOOLONG,                                     \
717    ENOLCK,                                           \
718    ENOSYS,                                           \
719    ENOTEMPTY,                                        \
720    ELOOP,                                            \
721    EWOULDBLOCK,                                      \
722    ENOMSG,                                           \
723    EUNATCH, /* 30 */                                 \
724    EBADR,                                            \
725    EDEADLOCK,                                        \
726    ENODATA,                                          \
727    ETIME,                                            \
728    ENONET,                                           \
729    EREMOTE,                                          \
730    ECOMM,                                            \
731    EPROTO,                                           \
732    EBADMSG,                                          \
733    EOVERFLOW, /* 40 */                               \
734    ERESTART,                                         \
735    EMSGSIZE,                                         \
736    EPROTOTYPE,                                       \
737    ENOPROTOOPT,                                      \
738    EPROTONOSUPPORT,                                  \
739    EOPNOTSUPP,                                       \
740    EADDRINUSE,                                       \
741    EADDRNOTAVAIL,                                    \
742    ENETDOWN,                                         \
743    ENETUNREACH, /* 50 */                             \
744    ENETRESET,                                        \
745    ENOBUFS,                                          \
746    ETIMEDOUT,                                        \
747    ECONNREFUSED,                                     \
748    EHOSTDOWN,                                        \
749    EHOSTUNREACH,                                     \
750    EALREADY,                                         \
751    EACCES,                                           \
752    ECONNRESET,   /* 59 */                            \
753    0         /* PVFS_ERRNO_MAX */                    \
754};                                                    \
755const char *PINT_non_errno_strerror_mapping[] = {     \
756    "Success", /* 0 */                                \
757    "Operation cancelled (possibly due to timeout)",  \
758    "Device initialization failed",                   \
759    "Detailed per-server errors are available",       \
760    "Unknown host",                                   \
761    "No address associated with name",                \
762    "Unknown server error",                           \
763    "Host name lookup failure",                       \
764};                                                    \
765PVFS_error PINT_non_errno_mapping[] = {               \
766    0,     /* leave this one empty */                 \
767    PVFS_ECANCEL,   /* 1 */                           \
768    PVFS_EDEVINIT,  /* 2 */                           \
769    PVFS_EDETAIL,   /* 3 */                           \
770    PVFS_EHOSTNTFD, /* 4 */                           \
771    PVFS_EADDRNTFD, /* 5 */                           \
772    PVFS_ENORECVR,  /* 6 */                           \
773    PVFS_ETRYAGAIN, /* 7 */                           \
774}
775
776/*
777  NOTE: PVFS_get_errno_mapping will convert a PVFS_ERROR_CODE to an
778  errno value.  If the error code is a pvfs2 specific error code
779  (i.e. a PVFS_NON_ERRNO_ERROR_CODE), PVFS_get_errno_mapping will
780  return an index into the PINT_non_errno_strerror_mapping array which
781  can be used for getting the pvfs2 specific strerror message given
782  the error code.  if the value is not a recognized error code, the
783  passed in value will be returned unchanged.
784*/
785#define DECLARE_ERRNO_MAPPING_AND_FN()                     \
786extern PVFS_error PINT_errno_mapping[];                    \
787extern PVFS_error PINT_non_errno_mapping[];                \
788extern const char *PINT_non_errno_strerror_mapping[];      \
789PVFS_error PVFS_get_errno_mapping(PVFS_error error)        \
790{                                                          \
791    PVFS_error ret = error, mask = 0;                      \
792    int32_t positive = ((error > -1) ? 1 : 0);             \
793    if (IS_PVFS_NON_ERRNO_ERROR((positive? error: -error)))\
794    {                                                      \
795    mask = (PVFS_NON_ERRNO_ERROR_BIT | PVFS_ERROR_BIT |    \
796            PVFS_ERROR_CLASS_BITS);                        \
797    ret = PVFS_NON_ERRNO_ERROR_CODE(                       \
798          ((positive ? error : abs(error))) & ~mask);      \
799    }                                                      \
800    else if (IS_PVFS_ERROR((positive? error: -error)))     \
801    {                                                      \
802    mask = (PVFS_ERROR_BIT | PVFS_ERROR_CLASS_BITS);       \
803    ret = PINT_errno_mapping[                              \
804        PVFS_ERROR_CODE(((positive ? error :               \
805                             abs(error))) & ~mask)];       \
806    }                                                      \
807    return ret;                                            \
808}                                                          \
809PVFS_error PVFS_errno_to_error(int err)                    \
810{                                                          \
811    PVFS_error e = 0;                                      \
812    \
813    for(; e < PVFS_ERRNO_MAX; ++e)                         \
814    {                                                      \
815        if(PINT_errno_mapping[e] == err)                   \
816        {                                                  \
817            return e;                                      \
818        }                                                  \
819    }                                                      \
820    return 0;                                              \
821}                                                          \
822DECLARE_ERRNO_MAPPING()
823#define PVFS_ERROR_TO_ERRNO(__error) PVFS_get_errno_mapping(__error)
824
825/** These structures/calls are used when returning detailed lists of
826 *  errors from a particular call.  This is done to report on specific,
827 *  per-server failures.
828 */
829typedef struct
830{
831    PVFS_error error;
832    PVFS_BMI_addr_t addr;
833} PVFS_error_server;
834
835typedef struct
836{
837    int count_allocated;
838    int count_used;
839    int count_exceeded; /* set if we ran out of space for errors */
840    /* structure is alloc'd larger for more errors */
841    PVFS_error_server error[1];
842} PVFS_error_details;
843
844PVFS_error_details *PVFS_error_details_new(int count);
845void PVFS_error_details_free(PVFS_error_details *details);
846
847/** PVFS I/O operation types, used in both system and server interfaces.
848 */
849enum PVFS_io_type
850{
851    PVFS_IO_READ  = 1,
852    PVFS_IO_WRITE = 2
853};
854
855/*
856 * Filesystem "magic" number unique to PVFS2 kernel interface.  Used by
857 * ROMIO to auto-detect access method given a mounted path.
858 */
859#define PVFS2_SUPER_MAGIC 0x20030528
860
861/* flag value that can be used with mgmt_iterate_handles to retrieve
862 * reserved handle values
863 */
864#define PVFS_MGMT_RESERVED 1
865
866/*
867 * Structure and macros for timing things for profile-like output.
868 *
869 */
870struct profiler
871{
872    struct  timeval  start;
873    struct  timeval  finish;
874    uint64_t  save_timing;
875};
876
877#define INIT_PROFILER(prof_struct) prof_struct.cumulative_diff = 0;
878
879#define START_PROFILER(prof_struct) \
880    gettimeofday(&prof_struct.start, NULL);
881
882#define FINISH_PROFILER(label, prof_struct, print_timing) \
883{ \
884    double t_start, t_finish; \
885    gettimeofday(&prof_struct.finish, NULL); \
886    t_start = prof_struct.start.tv_sec + (prof_struct.start.tv_usec/1000000.0); \
887    t_finish = prof_struct.finish.tv_sec + (prof_struct.finish.tv_usec/1000000.0); \
888    prof_struct.save_timing = t_finish - t_start * 1000000.0; \
889    if (print_timing) { \
890      gossip_err("PROFILING %s: %f\n", label, t_finish - t_start); \
891    } \
892}
893
894#define PRINT_PROFILER(label, prof_struct) \
895      gossip_err("PROFILING %s: %f\n", label, prof_struct.save_timing / 1000000.0);
896
897
898
899
900/*
901 * New types for robust security implementation.
902 */
903typedef unsigned char *PVFS_signature;
904
905typedef struct PVFS_capability PVFS_capability;
906struct PVFS_capability
907{
908    char *issuer;              /* alias of the issuing server */
909    PVFS_fs_id fsid;           /* fsid for which this capability is valid */
910    uint32_t sig_size;         /* length of the signature in bytes */
911    PVFS_signature signature;  /* digital signature */
912    PVFS_time timeout;         /* seconds after epoch to time out */
913    uint32_t op_mask;          /* allowed operations mask */
914    uint32_t num_handles;      /* number of elements in the handle array */
915    PVFS_handle *handle_array; /* handles in this capability */
916};
917endecode_fields_3a2a_struct (
918    PVFS_capability,
919    string, issuer,
920    PVFS_fs_id, fsid,
921    skip4,,
922    uint32_t, sig_size,
923    PVFS_signature, signature,
924    PVFS_time, timeout,
925    uint32_t, op_mask,
926    uint32_t, num_handles,
927    PVFS_handle, handle_array)
928#define extra_size_PVFS_capability (PVFS_REQ_LIMIT_HANDLES_COUNT * \
929                                    sizeof(PVFS_handle)          + \
930                                    PVFS_REQ_LIMIT_ISSUER        + \
931                                    PVFS_REQ_LIMIT_SIGNATURE)
932
933typedef struct PVFS_credential PVFS_credential;
934struct PVFS_credential
935{
936    PVFS_uid userid;           /* user id */
937    uint32_t num_groups;       /* length of group_array */
938    PVFS_gid *group_array;     /* groups for which the user is a member */
939    char *issuer;              /* alias of the issuing server */
940    PVFS_time timeout;         /* seconds after epoch to time out */
941    uint32_t sig_size;         /* length of the signature in bytes */
942    PVFS_signature signature;  /* digital signature */
943};
944endecode_fields_3a2a_struct (
945    PVFS_credential,
946    skip4,,
947    skip4,,
948    PVFS_uid, userid,
949    uint32_t, num_groups,
950    PVFS_gid, group_array,
951    string, issuer,
952    PVFS_time, timeout,
953    uint32_t, sig_size,
954    PVFS_signature, signature)
955#define extra_size_PVFS_credential (PVFS_REQ_LIMIT_GROUPS    * \
956                                    sizeof(PVFS_gid)         + \
957                                    PVFS_REQ_LIMIT_ISSUER    + \
958                                    PVFS_REQ_LIMIT_SIGNATURE)
959
960#endif /* __PVFS2_TYPES_H */
961
962/*
963 * Local variables:
964 *  c-indent-level: 4
965 *  c-basic-offset: 4
966 * End:
967 *
968 * vim: ts=8 sts=4 sw=4 expandtab
969 */
Note: See TracBrowser for help on using the browser.