root/branches/Orange-Elaine-Distr-Dir-Branch/src/proto/pvfs2-attr.h @ 8386

Revision 8386, 13.2 KB (checked in by elaine, 3 years ago)

Preliminary work for distributed directories - making client aware of DIR_ENT_KEY.

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 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_DIRENT_FILES         (1 << 21)
59#define PVFS_ATTR_DIR_ALL \
60(PVFS_ATTR_DIR_DIRENT_COUNT | PVFS_ATTR_DIR_HINT | PVFS_ATTR_DIR_DIRENT_FILES)
61
62/* attributes that do not change once set */
63#define PVFS_STATIC_ATTR_MASK \
64(PVFS_ATTR_COMMON_TYPE|PVFS_ATTR_META_DIST|PVFS_ATTR_META_DFILES|PVFS_ATTR_META_MIRROR_DFILES|PVFS_ATTR_META_UNSTUFFED)
65
66/* extended hint attributes for a metafile object */
67struct PVFS_metafile_hint_s
68{
69    PVFS_flags flags;
70};
71typedef struct PVFS_metafile_hint_s PVFS_metafile_hint;
72#ifdef __PINT_REQPROTO_ENCODE_FUNCS_C
73endecode_fields_1(PVFS_metafile_hint,
74        PVFS_flags, flags)
75#endif
76
77/* attributes specific to metadata objects */
78struct PVFS_metafile_attr_s
79{
80    /* distribution */
81    PINT_dist *dist;
82    uint32_t dist_size;  /* not sent across wire, each side may be diff */
83
84    /* list of datafiles */
85    PVFS_handle *dfile_array;
86    uint32_t dfile_count;
87
88    /* list of mirrored datafiles */
89    PVFS_handle *mirror_dfile_array;
90    uint32_t mirror_copies_count;
91
92    int32_t stuffed_size;
93
94    PVFS_metafile_hint hint;
95};
96typedef struct PVFS_metafile_attr_s PVFS_metafile_attr;
97#ifdef __PINT_REQPROTO_ENCODE_FUNCS_C
98#define encode_PVFS_metafile_attr_dist(pptr,x) do { \
99    encode_PINT_dist(pptr, &(x)->dist); \
100} while (0)
101#define decode_PVFS_metafile_attr_dist(pptr,x) do { \
102    decode_PINT_dist(pptr, &(x)->dist); \
103    (x)->dist_size = PINT_DIST_PACK_SIZE((x)->dist); \
104} while (0)
105#define encode_PVFS_metafile_attr_mirror_dfiles(pptr,x) do {            \
106  int dfiles_i, copy_i, handle_i;                                       \
107  encode_uint32_t(pptr, &(x)->mirror_copies_count);                     \
108  encode_skip4(pptr,);                                                  \
109  for (copy_i=0; copy_i<(x)->mirror_copies_count; copy_i++)             \
110    for (dfiles_i=0; dfiles_i<(x)->dfile_count; dfiles_i++)             \
111    {                                                                   \
112       handle_i = (copy_i * (x)->dfile_count) + dfiles_i;               \
113       encode_PVFS_handle(pptr, &(x)->mirror_dfile_array[handle_i]);    \
114    }                                                                   \
115} while (0)
116#define decode_PVFS_metafile_attr_mirror_dfiles(pptr,x) do {            \
117  int dfiles_i, copy_i, handle_i;                                       \
118  decode_uint32_t(pptr, &(x)->mirror_copies_count);                     \
119  decode_skip4(pptr,);                                                  \
120  (x)->mirror_dfile_array = decode_malloc((x)->dfile_count         *    \
121                                          (x)->mirror_copies_count *    \
122                                          sizeof(PVFS_handle));         \
123  for (copy_i=0; copy_i<(x)->mirror_copies_count; copy_i++)             \
124    for (dfiles_i=0; dfiles_i<(x)->dfile_count; dfiles_i++)             \
125    {                                                                   \
126       handle_i = (copy_i * (x)->dfile_count) + dfiles_i;               \
127       decode_PVFS_handle(pptr, &(x)->mirror_dfile_array[handle_i]);    \
128    }                                                                   \
129} while (0)
130#define encode_PVFS_metafile_attr_dfiles(pptr,x) do {                   \
131    int dfiles_i;                                                       \
132    encode_uint32_t(pptr, &(x)->dfile_count);                           \
133    encode_skip4(pptr,);                                                \
134    for (dfiles_i=0; dfiles_i<(x)->dfile_count; dfiles_i++)             \
135        encode_PVFS_handle(pptr, &(x)->dfile_array[dfiles_i]);          \
136    encode_PVFS_metafile_hint(pptr, &(x)->hint);                        \
137} while (0)
138#define decode_PVFS_metafile_attr_dfiles(pptr,x) do {                     \
139    int dfiles_i;                                                         \
140    decode_uint32_t(pptr, &(x)->dfile_count);                             \
141    decode_skip4(pptr,);                                                  \
142    (x)->dfile_array = decode_malloc((x)->dfile_count                     \
143      * sizeof(*(x)->dfile_array));                                       \
144    for (dfiles_i=0; dfiles_i<(x)->dfile_count; dfiles_i++)               \
145        decode_PVFS_handle(pptr, &(x)->dfile_array[dfiles_i]);            \
146    decode_PVFS_metafile_hint(pptr, &(x)->hint);                          \
147} while (0)
148#endif
149
150/* attributes specific to datafile objects */
151struct PVFS_datafile_attr_s
152{
153    PVFS_size size;
154};
155typedef struct PVFS_datafile_attr_s PVFS_datafile_attr;
156endecode_fields_1(PVFS_datafile_attr, PVFS_size, size)
157
158/* extended hint attributes for a directory object */
159struct PVFS_directory_hint_s
160{
161    uint32_t  dist_name_len;
162    /* what is the distribution name? */
163    char     *dist_name;
164    /* what are the distribution parameters? */
165    uint32_t  dist_params_len;
166    char     *dist_params;
167    /* how many dfiles ought to be used */
168    uint32_t dfile_count;
169};
170typedef struct PVFS_directory_hint_s PVFS_directory_hint;
171
172#ifdef __PINT_REQPROTO_ENCODE_FUNCS_C
173endecode_fields_7(PVFS_directory_hint,
174        uint32_t, dist_name_len,
175        skip4,,
176        string, dist_name,
177        uint32_t, dist_params_len,
178        skip4,,
179        string, dist_params,
180        uint32_t, dfile_count)
181#endif
182
183/* attributes specific to directory objects */
184struct PVFS_directory_attr_s
185{
186    /* list of files to hold directory entries */
187    PVFS_handle dirent_handle;
188    uint32_t dirent_file_count;
189    PVFS_size dirent_count;
190    PVFS_directory_hint hint;
191};
192typedef struct PVFS_directory_attr_s PVFS_directory_attr;
193
194#ifdef __PINT_REQPROTO_ENCODE_FUNCS_C
195#define encode_PVFS_directory_attr(pptr, x) do { \
196    encode_uint32_t(pptr, &(x)->dirent_file_count);\
197    encode_skip4(pptr,);\
198    encode_PVFS_handle(pptr, &(x)->dirent_handle);\
199    encode_PVFS_size(pptr, &(x)->dirent_count);\
200    encode_PVFS_directory_hint(pptr, &(x)->hint);\
201} while(0)
202
203#if 0
204    int dirent_files_i;\
205    for (dirent_files_i=0; dirent_files_i<(x)->dirent_file_count; dirent_files_i++)\
206        encode_PVFS_handle(pptr, &(x)->dirent_file_array[dirent_files_i]);\
207
208#endif
209
210#define decode_PVFS_directory_attr(pptr, x) do { \
211    decode_uint32_t(pptr, &(x)->dirent_file_count);\
212    decode_skip4(pptr,);\
213    decode_PVFS_handle(pptr, &(x)->dirent_handle);\
214    decode_PVFS_size(pptr, &(x)->dirent_count);\
215    decode_PVFS_directory_hint(pptr, &(x)->hint);\
216} while(0)
217#endif
218
219#if 0
220    int dirent_files_i;\
221    (x)->dirent_file_array = decode_malloc((x)->dirent_file_count \
222      * sizeof(*(x)->dirent_file_array));\
223    for (dirent_files_i=0; dirent_files_i<(x)->dirent_file_count; dirent_files_i++)\
224    { \
225        decode_PVFS_handle(pptr, &(x)->dirent_file_array[dirent_files_i]);\
226    } \
227
228#endif
229
230/* attributes specific to symlinks */
231struct PVFS_symlink_attr_s
232{
233    uint32_t target_path_len;
234    char *target_path;
235};
236typedef struct PVFS_symlink_attr_s PVFS_symlink_attr;
237endecode_fields_3(
238  PVFS_symlink_attr,
239  uint32_t, target_path_len,
240  skip4,,
241  string, target_path)
242
243/* generic attributes; applies to all objects */
244struct PVFS_object_attr
245{
246    PVFS_uid owner;
247    PVFS_gid group;
248    PVFS_permissions perms;
249    PVFS_time atime;
250    PVFS_time mtime;
251    PVFS_time ctime;
252    uint32_t mask;     /* indicates which fields are currently valid */
253    PVFS_ds_type objtype; /* defined in pvfs2-types.h */
254    union
255    {
256        PVFS_metafile_attr meta;
257        PVFS_datafile_attr data;
258        PVFS_directory_attr dir;
259        PVFS_symlink_attr sym;
260    }
261    u;
262};
263typedef struct PVFS_object_attr PVFS_object_attr;
264#ifdef __PINT_REQPROTO_ENCODE_FUNCS_C
265#define encode_PVFS_object_attr(pptr,x) do { \
266    encode_PVFS_uid(pptr, &(x)->owner); \
267    encode_PVFS_gid(pptr, &(x)->group); \
268    encode_PVFS_permissions(pptr, &(x)->perms); \
269    encode_skip4(pptr,); \
270    encode_PVFS_time(pptr, &(x)->atime); \
271    encode_PVFS_time(pptr, &(x)->mtime); \
272    encode_PVFS_time(pptr, &(x)->ctime); \
273    encode_uint32_t(pptr, &(x)->mask); \
274    encode_PVFS_ds_type(pptr, &(x)->objtype); \
275    if ((x)->objtype == PVFS_TYPE_METAFILE && \
276        (!((x)->mask & PVFS_ATTR_META_UNSTUFFED))) \
277    { \
278        encode_int32_t(pptr, &(x)->u.meta.stuffed_size); \
279        encode_skip4(pptr,); \
280    } \
281    if ((x)->mask & PVFS_ATTR_META_DIST) \
282        encode_PVFS_metafile_attr_dist(pptr, &(x)->u.meta); \
283    if ((x)->mask & PVFS_ATTR_META_DFILES) \
284        encode_PVFS_metafile_attr_dfiles(pptr, &(x)->u.meta); \
285    if ((x)->mask & PVFS_ATTR_META_MIRROR_DFILES) \
286        encode_PVFS_metafile_attr_mirror_dfiles(pptr, &(x)->u.meta); \
287    if ((x)->mask & PVFS_ATTR_DATA_SIZE) \
288        encode_PVFS_datafile_attr(pptr, &(x)->u.data); \
289    if ((x)->mask & PVFS_ATTR_SYMLNK_TARGET) \
290        encode_PVFS_symlink_attr(pptr, &(x)->u.sym); \
291    if (((x)->mask & PVFS_ATTR_DIR_DIRENT_COUNT) || \
292        ((x)->mask & PVFS_ATTR_DIR_DIRENT_FILES) || \
293        ((x)->mask & PVFS_ATTR_DIR_HINT)) \
294        encode_PVFS_directory_attr(pptr, &(x)->u.dir); \
295} while (0)
296#define decode_PVFS_object_attr(pptr,x) do { \
297    decode_PVFS_uid(pptr, &(x)->owner); \
298    decode_PVFS_gid(pptr, &(x)->group); \
299    decode_PVFS_permissions(pptr, &(x)->perms); \
300    decode_skip4(pptr,); \
301    decode_PVFS_time(pptr, &(x)->atime); \
302    decode_PVFS_time(pptr, &(x)->mtime); \
303    decode_PVFS_time(pptr, &(x)->ctime); \
304    decode_uint32_t(pptr, &(x)->mask); \
305    decode_PVFS_ds_type(pptr, &(x)->objtype); \
306    if ((x)->objtype == PVFS_TYPE_METAFILE && \
307        (!((x)->mask & PVFS_ATTR_META_UNSTUFFED))) \
308    { \
309        decode_int32_t(pptr, &(x)->u.meta.stuffed_size); \
310        decode_skip4(pptr,); \
311    } \
312    if ((x)->mask & PVFS_ATTR_META_DIST) \
313        decode_PVFS_metafile_attr_dist(pptr, &(x)->u.meta); \
314    if ((x)->mask & PVFS_ATTR_META_DFILES) \
315        decode_PVFS_metafile_attr_dfiles(pptr, &(x)->u.meta); \
316    if ((x)->mask & PVFS_ATTR_META_MIRROR_DFILES) \
317        decode_PVFS_metafile_attr_mirror_dfiles(pptr, &(x)->u.meta); \
318    if ((x)->mask & PVFS_ATTR_DATA_SIZE) \
319        decode_PVFS_datafile_attr(pptr, &(x)->u.data); \
320    if ((x)->mask & PVFS_ATTR_SYMLNK_TARGET) \
321        decode_PVFS_symlink_attr(pptr, &(x)->u.sym); \
322    if (((x)->mask & PVFS_ATTR_DIR_DIRENT_COUNT) || \
323        ((x)->mask & PVFS_ATTR_DIR_DIRENT_FILES) || \
324        ((x)->mask & PVFS_ATTR_DIR_HINT)) \
325        decode_PVFS_directory_attr(pptr, &(x)->u.dir); \
326} while (0)
327#endif
328/* attr buffer needs room for larger of symlink path, meta fields or
329 * dir hints: an attrib structure can never hold information for not more
330 * than a symlink or a metafile or a dir object
331*/
332#define extra_size_PVFS_object_attr_dir  (PVFS_REQ_LIMIT_DIST_BYTES + \
333  PVFS_REQ_LIMIT_DIST_NAME + roundup8(sizeof(PVFS_directory_attr)) + \
334  PVFS_REQ_LIMIT_HANDLES_COUNT * sizeof(PVFS_handle))
335/*TODO: PVFS_REQ_LIMIT_HANDLES_COUNT really needs to change to something
336        indicating the max number of servers */
337
338/* room for distribution, stuffed_size, dfile array, and mirror_dfile_array */
339#define extra_size_PVFS_object_attr_meta (PVFS_REQ_LIMIT_DIST_BYTES + \
340  sizeof(int32_t) +                                                   \
341  (PVFS_REQ_LIMIT_DFILE_COUNT * sizeof(PVFS_handle)) +                \
342  (PVFS_REQ_LIMIT_MIRROR_DFILE_COUNT * sizeof(PVFS_handle)))
343
344#define extra_size_PVFS_object_attr_symlink (PVFS_REQ_LIMIT_PATH_NAME_BYTES)
345
346#define extra_size_PVFS_object_attr \
347        max(max(extra_size_PVFS_object_attr_meta, extra_size_PVFS_object_attr_symlink), extra_size_PVFS_object_attr_dir)
348
349#endif /* __PVFS2_ATTR_H */
350
351/*
352 * Local variables:
353 *  c-indent-level: 4
354 *  c-basic-offset: 4
355 * End:
356 *
357 * vim: ts=8 sts=4 sw=4 expandtab
358 */
Note: See TracBrowser for help on using the browser.