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 / src / proto / pvfs2-attr.h < prev    next >
C/C++ Source or Header  |  2010-04-30  |  12KB  |  325 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 code contained in this file, please
  7.  * update the PVFS2_PROTO_VERSION in pvfs2-req-proto.h accordingly
  8.  */
  9.  
  10. #ifndef __PVFS2_ATTR_H
  11. #define __PVFS2_ATTR_H
  12.  
  13. #include "pvfs2-types.h"
  14. #include "pvfs2-storage.h"
  15. #include "pint-distribution.h"
  16.  
  17. #ifndef max
  18. #define max(a,b) ((a) < (b) ? (b) : (a))
  19. #endif
  20.  
  21. /* internal attribute masks, common to all obj types */
  22. #define PVFS_ATTR_COMMON_UID   (1 << 0)
  23. #define PVFS_ATTR_COMMON_GID   (1 << 1)
  24. #define PVFS_ATTR_COMMON_PERM  (1 << 2)
  25. #define PVFS_ATTR_COMMON_ATIME (1 << 3)
  26. #define PVFS_ATTR_COMMON_CTIME (1 << 4)
  27. #define PVFS_ATTR_COMMON_MTIME (1 << 5)
  28. #define PVFS_ATTR_COMMON_TYPE  (1 << 6)
  29. #define PVFS_ATTR_COMMON_ATIME_SET (1 << 7)
  30. #define PVFS_ATTR_COMMON_MTIME_SET (1 << 8)
  31. #define PVFS_ATTR_COMMON_ALL                       \
  32. (PVFS_ATTR_COMMON_UID   | PVFS_ATTR_COMMON_GID   | \
  33.  PVFS_ATTR_COMMON_PERM  | PVFS_ATTR_COMMON_ATIME | \
  34.  PVFS_ATTR_COMMON_CTIME | PVFS_ATTR_COMMON_MTIME | \
  35.  PVFS_ATTR_COMMON_TYPE)
  36.  
  37. /* internal attribute masks for metadata objects */
  38. #define PVFS_ATTR_META_DIST          (1 << 10)
  39. #define PVFS_ATTR_META_DFILES        (1 << 11)
  40. #define PVFS_ATTR_META_MIRROR_DFILES (1 << 13)
  41. #define PVFS_ATTR_META_ALL \
  42. (PVFS_ATTR_META_DIST | PVFS_ATTR_META_DFILES | PVFS_ATTR_META_MIRROR_DFILES)
  43.  
  44. #define PVFS_ATTR_META_UNSTUFFED (1 << 12)
  45.  
  46.  
  47. /* internal attribute masks for datafile objects */
  48. #define PVFS_ATTR_DATA_SIZE            (1 << 15)
  49. #define PVFS_ATTR_DATA_ALL   PVFS_ATTR_DATA_SIZE
  50.  
  51. /* internal attribute masks for symlink objects */
  52. #define PVFS_ATTR_SYMLNK_TARGET            (1 << 18)
  53. #define PVFS_ATTR_SYMLNK_ALL PVFS_ATTR_SYMLNK_TARGET
  54.  
  55. /* internal attribute masks for directory objects */
  56. #define PVFS_ATTR_DIR_DIRENT_COUNT         (1 << 19)
  57. #define PVFS_ATTR_DIR_HINT                  (1 << 20)
  58. #define PVFS_ATTR_DIR_ALL \
  59. (PVFS_ATTR_DIR_DIRENT_COUNT | PVFS_ATTR_DIR_HINT)
  60.  
  61. /* attributes that do not change once set */
  62. #define PVFS_STATIC_ATTR_MASK \
  63. (PVFS_ATTR_COMMON_TYPE|PVFS_ATTR_META_DIST|PVFS_ATTR_META_DFILES|PVFS_ATTR_META_MIRROR_DFILES|PVFS_ATTR_META_UNSTUFFED)
  64.  
  65. /* extended hint attributes for a metafile object */
  66. struct PVFS_metafile_hint_s
  67. {
  68.     PVFS_flags flags;
  69. };
  70. typedef struct PVFS_metafile_hint_s PVFS_metafile_hint;
  71. #ifdef __PINT_REQPROTO_ENCODE_FUNCS_C
  72. endecode_fields_1(PVFS_metafile_hint,
  73.         PVFS_flags, flags);
  74. #endif
  75.  
  76. /* attributes specific to metadata objects */
  77. struct PVFS_metafile_attr_s
  78. {
  79.     /* distribution */
  80.     PINT_dist *dist;
  81.     uint32_t dist_size;  /* not sent across wire, each side may be diff */
  82.  
  83.     /* list of datafiles */
  84.     PVFS_handle *dfile_array;
  85.     uint32_t dfile_count;
  86.  
  87.     /* list of mirrored datafiles */
  88.     PVFS_handle *mirror_dfile_array;
  89.     uint32_t mirror_copies_count;
  90.  
  91.     int32_t stuffed_size;
  92.  
  93.     PVFS_metafile_hint hint;
  94. };
  95. typedef struct PVFS_metafile_attr_s PVFS_metafile_attr;
  96. #ifdef __PINT_REQPROTO_ENCODE_FUNCS_C
  97. #define encode_PVFS_metafile_attr_dist(pptr,x) do { \
  98.     encode_PINT_dist(pptr, &(x)->dist); \
  99. } while (0)
  100. #define decode_PVFS_metafile_attr_dist(pptr,x) do { \
  101.     decode_PINT_dist(pptr, &(x)->dist); \
  102.     (x)->dist_size = PINT_DIST_PACK_SIZE((x)->dist); \
  103. } while (0)
  104. #define encode_PVFS_metafile_attr_mirror_dfiles(pptr,x) do {            \
  105.   int dfiles_i, copy_i, handle_i;                                       \
  106.   encode_uint32_t(pptr, &(x)->mirror_copies_count);                     \
  107.   encode_skip4(pptr,);                                                  \
  108.   for (copy_i=0; copy_i<(x)->mirror_copies_count; copy_i++)             \
  109.     for (dfiles_i=0; dfiles_i<(x)->dfile_count; dfiles_i++)             \
  110.     {                                                                   \
  111.        handle_i = (copy_i * (x)->dfile_count) + dfiles_i;               \
  112.        encode_PVFS_handle(pptr, &(x)->mirror_dfile_array[handle_i]);    \
  113.     }                                                                   \
  114. } while (0)
  115. #define decode_PVFS_metafile_attr_mirror_dfiles(pptr,x) do {            \
  116.   int dfiles_i, copy_i, handle_i;                                       \
  117.   decode_uint32_t(pptr, &(x)->mirror_copies_count);                     \
  118.   decode_skip4(pptr,);                                                  \
  119.   (x)->mirror_dfile_array = decode_malloc((x)->dfile_count         *    \
  120.                                           (x)->mirror_copies_count *    \
  121.                                           sizeof(PVFS_handle));         \
  122.   for (copy_i=0; copy_i<(x)->mirror_copies_count; copy_i++)             \
  123.     for (dfiles_i=0; dfiles_i<(x)->dfile_count; dfiles_i++)             \
  124.     {                                                                   \
  125.        handle_i = (copy_i * (x)->dfile_count) + dfiles_i;               \
  126.        decode_PVFS_handle(pptr, &(x)->mirror_dfile_array[handle_i]);    \
  127.     }                                                                   \
  128. } while (0)
  129. #define encode_PVFS_metafile_attr_dfiles(pptr,x) do {                   \
  130.     int dfiles_i;                                                       \
  131.     encode_uint32_t(pptr, &(x)->dfile_count);                           \
  132.     encode_skip4(pptr,);                                                \
  133.     for (dfiles_i=0; dfiles_i<(x)->dfile_count; dfiles_i++)             \
  134.     encode_PVFS_handle(pptr, &(x)->dfile_array[dfiles_i]);          \
  135.     encode_PVFS_metafile_hint(pptr, &(x)->hint);                        \
  136. } while (0)
  137. #define decode_PVFS_metafile_attr_dfiles(pptr,x) do {                     \
  138.     int dfiles_i;                                                         \
  139.     decode_uint32_t(pptr, &(x)->dfile_count);                             \
  140.     decode_skip4(pptr,);                                                  \
  141.     (x)->dfile_array = decode_malloc((x)->dfile_count                     \
  142.       * sizeof(*(x)->dfile_array));                                       \
  143.     for (dfiles_i=0; dfiles_i<(x)->dfile_count; dfiles_i++)               \
  144.     decode_PVFS_handle(pptr, &(x)->dfile_array[dfiles_i]);            \
  145.     decode_PVFS_metafile_hint(pptr, &(x)->hint);                          \
  146. } while (0)
  147. #endif
  148.  
  149. /* attributes specific to datafile objects */
  150. struct PVFS_datafile_attr_s
  151. {
  152.     PVFS_size size;
  153. };
  154. typedef struct PVFS_datafile_attr_s PVFS_datafile_attr;
  155. endecode_fields_1(PVFS_datafile_attr, PVFS_size, size);
  156.  
  157. /* extended hint attributes for a directory object */
  158. struct PVFS_directory_hint_s
  159. {
  160.     uint32_t  dist_name_len;
  161.     /* what is the distribution name? */
  162.     char     *dist_name;
  163.     /* what are the distribution parameters? */
  164.     uint32_t  dist_params_len;
  165.     char     *dist_params;
  166.     /* how many dfiles ought to be used */
  167.     uint32_t dfile_count;
  168. };
  169. typedef struct PVFS_directory_hint_s PVFS_directory_hint;
  170.  
  171. #ifdef __PINT_REQPROTO_ENCODE_FUNCS_C
  172. endecode_fields_7(PVFS_directory_hint,
  173.         uint32_t, dist_name_len,
  174.         skip4,,
  175.         string, dist_name,
  176.         uint32_t, dist_params_len,
  177.         skip4,,
  178.         string, dist_params,
  179.         uint32_t, dfile_count);
  180. #endif
  181.  
  182. /* attributes specific to directory objects */
  183. struct PVFS_directory_attr_s
  184. {
  185.     PVFS_size dirent_count;
  186.     PVFS_directory_hint hint;
  187. };
  188. typedef struct PVFS_directory_attr_s PVFS_directory_attr;
  189.  
  190. #ifdef __PINT_REQPROTO_ENCODE_FUNCS_C
  191. #define encode_PVFS_directory_attr(pptr, x) do { \
  192.     encode_PVFS_size(pptr, &(x)->dirent_count);\
  193.     encode_PVFS_directory_hint(pptr, &(x)->hint);\
  194. } while(0)
  195. #define decode_PVFS_directory_attr(pptr, x) do { \
  196.     decode_PVFS_size(pptr, &(x)->dirent_count);\
  197.     decode_PVFS_directory_hint(pptr, &(x)->hint);\
  198. } while(0)
  199. #endif
  200.  
  201. /* attributes specific to symlinks */
  202. struct PVFS_symlink_attr_s
  203. {
  204.     uint32_t target_path_len;
  205.     char *target_path;
  206. };
  207. typedef struct PVFS_symlink_attr_s PVFS_symlink_attr;
  208. endecode_fields_3(
  209.   PVFS_symlink_attr,
  210.   uint32_t, target_path_len,
  211.   skip4,,
  212.   string, target_path);
  213.  
  214. /* generic attributes; applies to all objects */
  215. struct PVFS_object_attr
  216. {
  217.     PVFS_uid owner;
  218.     PVFS_gid group;
  219.     PVFS_permissions perms;
  220.     PVFS_time atime;
  221.     PVFS_time mtime;
  222.     PVFS_time ctime;
  223.     uint32_t mask;     /* indicates which fields are currently valid */
  224.     PVFS_ds_type objtype; /* defined in pvfs2-types.h */
  225.     union
  226.     {
  227.     PVFS_metafile_attr meta;
  228.     PVFS_datafile_attr data;
  229.     PVFS_directory_attr dir;
  230.     PVFS_symlink_attr sym;
  231.     }
  232.     u;
  233. };
  234. typedef struct PVFS_object_attr PVFS_object_attr;
  235. #ifdef __PINT_REQPROTO_ENCODE_FUNCS_C
  236. #define encode_PVFS_object_attr(pptr,x) do { \
  237.     encode_PVFS_uid(pptr, &(x)->owner); \
  238.     encode_PVFS_gid(pptr, &(x)->group); \
  239.     encode_PVFS_permissions(pptr, &(x)->perms); \
  240.     encode_skip4(pptr,); \
  241.     encode_PVFS_time(pptr, &(x)->atime); \
  242.     encode_PVFS_time(pptr, &(x)->mtime); \
  243.     encode_PVFS_time(pptr, &(x)->ctime); \
  244.     encode_uint32_t(pptr, &(x)->mask); \
  245.     encode_PVFS_ds_type(pptr, &(x)->objtype); \
  246.     if ((x)->objtype == PVFS_TYPE_METAFILE && \
  247.         (!((x)->mask & PVFS_ATTR_META_UNSTUFFED))) \
  248.     { \
  249.         encode_int32_t(pptr, &(x)->u.meta.stuffed_size); \
  250.         encode_skip4(pptr,); \
  251.     } \
  252.     if ((x)->mask & PVFS_ATTR_META_DIST) \
  253.     encode_PVFS_metafile_attr_dist(pptr, &(x)->u.meta); \
  254.     if ((x)->mask & PVFS_ATTR_META_DFILES) \
  255.     encode_PVFS_metafile_attr_dfiles(pptr, &(x)->u.meta); \
  256.     if ((x)->mask & PVFS_ATTR_META_MIRROR_DFILES) \
  257.         encode_PVFS_metafile_attr_mirror_dfiles(pptr, &(x)->u.meta); \
  258.     if ((x)->mask & PVFS_ATTR_DATA_SIZE) \
  259.     encode_PVFS_datafile_attr(pptr, &(x)->u.data); \
  260.     if ((x)->mask & PVFS_ATTR_SYMLNK_TARGET) \
  261.     encode_PVFS_symlink_attr(pptr, &(x)->u.sym); \
  262.     if (((x)->mask & PVFS_ATTR_DIR_DIRENT_COUNT) || \
  263.         ((x)->mask & PVFS_ATTR_DIR_HINT)) \
  264.     encode_PVFS_directory_attr(pptr, &(x)->u.dir); \
  265. } while (0)
  266. #define decode_PVFS_object_attr(pptr,x) do { \
  267.     decode_PVFS_uid(pptr, &(x)->owner); \
  268.     decode_PVFS_gid(pptr, &(x)->group); \
  269.     decode_PVFS_permissions(pptr, &(x)->perms); \
  270.     decode_skip4(pptr,); \
  271.     decode_PVFS_time(pptr, &(x)->atime); \
  272.     decode_PVFS_time(pptr, &(x)->mtime); \
  273.     decode_PVFS_time(pptr, &(x)->ctime); \
  274.     decode_uint32_t(pptr, &(x)->mask); \
  275.     decode_PVFS_ds_type(pptr, &(x)->objtype); \
  276.     if ((x)->objtype == PVFS_TYPE_METAFILE && \
  277.         (!((x)->mask & PVFS_ATTR_META_UNSTUFFED))) \
  278.     { \
  279.         decode_int32_t(pptr, &(x)->u.meta.stuffed_size); \
  280.         decode_skip4(pptr,); \
  281.     } \
  282.     if ((x)->mask & PVFS_ATTR_META_DIST) \
  283.     decode_PVFS_metafile_attr_dist(pptr, &(x)->u.meta); \
  284.     if ((x)->mask & PVFS_ATTR_META_DFILES) \
  285.     decode_PVFS_metafile_attr_dfiles(pptr, &(x)->u.meta); \
  286.     if ((x)->mask & PVFS_ATTR_META_MIRROR_DFILES) \
  287.         decode_PVFS_metafile_attr_mirror_dfiles(pptr, &(x)->u.meta); \
  288.     if ((x)->mask & PVFS_ATTR_DATA_SIZE) \
  289.     decode_PVFS_datafile_attr(pptr, &(x)->u.data); \
  290.     if ((x)->mask & PVFS_ATTR_SYMLNK_TARGET) \
  291.     decode_PVFS_symlink_attr(pptr, &(x)->u.sym); \
  292.     if (((x)->mask & PVFS_ATTR_DIR_DIRENT_COUNT) || \
  293.         ((x)->mask & PVFS_ATTR_DIR_HINT)) \
  294.     decode_PVFS_directory_attr(pptr, &(x)->u.dir); \
  295. } while (0)
  296. #endif
  297. /* attr buffer needs room for larger of symlink path, meta fields or 
  298.  * dir hints: an attrib structure can never hold information for not more 
  299.  * than a symlink or a metafile or a dir object 
  300. */
  301. #define extra_size_PVFS_object_attr_dir  (PVFS_REQ_LIMIT_DIST_BYTES + \
  302.   PVFS_REQ_LIMIT_DIST_NAME + roundup8(sizeof(PVFS_directory_attr)))
  303.  
  304. /* room for distribution, stuffed_size, dfile array, and mirror_dfile_array */
  305. #define extra_size_PVFS_object_attr_meta (PVFS_REQ_LIMIT_DIST_BYTES + \
  306.   sizeof(int32_t) +                                                   \
  307.   (PVFS_REQ_LIMIT_DFILE_COUNT * sizeof(PVFS_handle)) +                \
  308.   (PVFS_REQ_LIMIT_MIRROR_DFILE_COUNT * sizeof(PVFS_handle))) 
  309.  
  310. #define extra_size_PVFS_object_attr_symlink (PVFS_REQ_LIMIT_PATH_NAME_BYTES)
  311.  
  312. #define extra_size_PVFS_object_attr \
  313.         max(max(extra_size_PVFS_object_attr_meta, extra_size_PVFS_object_attr_symlink), extra_size_PVFS_object_attr_dir)
  314.  
  315. #endif /* __PVFS2_ATTR_H */
  316.  
  317. /*
  318.  * Local variables:
  319.  *  c-indent-level: 4
  320.  *  c-basic-offset: 4
  321.  * End:
  322.  *
  323.  * vim: ts=8 sts=4 sw=4 expandtab
  324.  */
  325.