Strip xseg stuff
[archipelago] / xseg / mapper-versions.h
1 /*
2  * Copyright 2013 GRNET S.A. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or
5  * without modification, are permitted provided that the following
6  * conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above
9  *      copyright notice, this list of conditions and the following
10  *      disclaimer.
11  *   2. Redistributions in binary form must reproduce the above
12  *      copyright notice, this list of conditions and the following
13  *      disclaimer in the documentation and/or other materials
14  *      provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * The views and conclusions contained in the software and
30  * documentation are those of the authors and should not be
31  * interpreted as representing official policies, either expressed
32  * or implied, of GRNET S.A.
33  */
34
35 #ifndef MAPPERVERSIONS_H
36
37 #define MAPPERVERSIONS_H
38
39 #include <mapper.h>
40 #include <xseg/protocol.h>
41 #include <mapper-version0.h>
42 #include <mapper-version1.h>
43 #include <mapper-version2.h>
44
45 #define MAP_LATEST_VERSION 2
46 /* These come straight from the struct map fields that need to be kept in
47  * permament storage.
48  *
49  * version
50  * size
51  * blocksize
52  * epoch
53  * flags
54  */
55 #define MAX_MAPHEADER_SIZE (sizeof(uint32_t) \
56                           + sizeof(uint64_t) \
57                           + sizeof(uint32_t) \
58                           + sizeof(uint64_t) \
59                           + sizeof(uint32_t) \
60                            )
61
62 /* should always be the maximum objectlen of all versions */
63 //#define MAX_OBJECT_LEN v2_max_objectlen
64
65 /* since object names are cacluclated from the volume names, the limit of the
66  * maximum volume len is calculated from the maximum object len, statically for
67  * all map versions.
68  *
69  * How the object name is calculated is reflected in this formula:
70  *
71  * volume-index-epoch
72  */
73 //#define MAX_VOLUME_LEN (MAX_OBJECT_LEN - HEXLIFIED_INDEX - HEXLIFIED_EPOCH - 2)
74
75 /* Some compile time checks */
76 #if MAX_OBJECT_LEN < v2_max_objectlen
77 #error "MAX_OBJECT_LEN is smaller than v2_max_objectlen"
78 #endif
79
80 #if MAX_OBJECT_LEN < v1_max_objectlen
81 #error "MAX_OBJECT_LEN is smaller than v1_max_objectlen"
82 #endif
83
84 #if MAX_OBJECT_LEN < v0_max_objectlen
85 #error "MAX_OBJECT_LEN is smaller than v0_max_objectlen"
86 #endif
87
88
89 /*
90  * map read/write functions
91  *
92  * version 0 -> pithos map
93  * version 1 -> archipelago version 1
94  * version 2 -> archipelago version 2
95  *
96  */
97
98 struct map_functions {
99         void (*object_to_map)(unsigned char *buf, struct map_node *mn);
100         int (*read_object)(struct map_node *mn, unsigned char *buf);
101         struct xseg_request * (*prepare_write_object)(struct peer_req *pr,
102                         struct map *map, struct map_node *mn);
103 //      int (*read_map)(struct map *map, unsigned char * data);
104 //      int (*write_map)(struct peer_req *pr, struct map *map);
105         int (*read_map_metadata)(struct map *map, unsigned char *metadata,
106                         uint32_t metadata_len);
107         int (*load_map_data)(struct peer_req *pr, struct map *map);
108         int (*write_map_metadata)(struct peer_req *pr, struct map *map);
109         int (*write_map_data)(struct peer_req *pr, struct map *map);
110 };
111
112 extern struct map_functions map_functions[];
113
114 #endif /* end MAPPERVERSIONS_H */