ia64/xen-unstable

view tools/blktap/parallax/blockstore.h @ 6432:b54144915ae6

merge?
author cl349@firebug.cl.cam.ac.uk
date Thu Aug 25 16:26:30 2005 +0000 (2005-08-25)
parents 3428d58a85e1 6e899a3840b2
children 0610add7c3fe
line source
1 /**************************************************************************
2 *
3 * blockstore.h
4 *
5 * Simple block store interface
6 *
7 */
9 #ifndef __BLOCKSTORE_H__
10 #define __BLOCKSTORE_H__
12 #include <netinet/in.h>
13 #include <xenctrl.h>
15 #define BLOCK_SIZE 4096
16 #define BLOCK_SHIFT 12
17 #define BLOCK_MASK 0xfffffffffffff000LL
19 /* XXX SMH: where is the below supposed to be defined???? */
20 #ifndef SECTOR_SHIFT
21 #define SECTOR_SHIFT 9
22 #endif
24 #define FREEBLOCK_SIZE (BLOCK_SIZE / sizeof(u64)) - (3 * sizeof(u64))
25 #define FREEBLOCK_MAGIC 0x0fee0fee0fee0feeULL
27 typedef struct {
28 u64 magic;
29 u64 next;
30 u64 count;
31 u64 list[FREEBLOCK_SIZE];
32 } freeblock_t;
34 #define BLOCKSTORE_MAGIC 0xaaaaaaa00aaaaaaaULL
35 #define BLOCKSTORE_SUPER 1ULL
37 typedef struct {
38 u64 magic;
39 u64 freelist_full;
40 u64 freelist_current;
41 } blockstore_super_t;
43 extern void *newblock();
44 extern void *readblock(u64 id);
45 extern u64 allocblock(void *block);
46 extern u64 allocblock_hint(void *block, u64 hint);
47 extern int writeblock(u64 id, void *block);
49 /* Add this blockid to a freelist, to be recycled by the allocator. */
50 extern void releaseblock(u64 id);
52 /* this is a memory free() operation for block-sized allocations */
53 extern void freeblock(void *block);
54 extern int __init_blockstore(void);
56 /* debug for freelist. */
57 void freelist_count(int print_each);
58 #define ALLOCFAIL (((u64)(-1)))
60 /* Distribution
61 */
62 #define BLOCKSTORED_PORT 9346
64 struct bshdr_t_struct {
65 u32 operation;
66 u32 flags;
67 u64 id;
68 u64 luid;
69 } __attribute__ ((packed));
70 typedef struct bshdr_t_struct bshdr_t;
72 struct bsmsg_t_struct {
73 bshdr_t hdr;
74 unsigned char block[BLOCK_SIZE];
75 } __attribute__ ((packed));
77 typedef struct bsmsg_t_struct bsmsg_t;
79 #define MSGBUFSIZE_OP sizeof(u32)
80 #define MSGBUFSIZE_FLAGS (sizeof(u32) + sizeof(u32))
81 #define MSGBUFSIZE_ID (sizeof(u32) + sizeof(u32) + sizeof(u64) + sizeof(u64))
82 #define MSGBUFSIZE_BLOCK sizeof(bsmsg_t)
84 #define BSOP_READBLOCK 0x01
85 #define BSOP_WRITEBLOCK 0x02
86 #define BSOP_ALLOCBLOCK 0x03
87 #define BSOP_FREEBLOCK 0x04
89 #define BSOP_FLAG_ERROR 0x01
91 #define BS_ALLOC_SKIP 10
92 #define BS_ALLOC_HACK
94 /* Remote hosts and cluster map - XXX need to generalise
95 */
97 /*
99 Interim ID format is
101 63 60 59 40 39 20 19 0
102 +----+--------------------+--------------------+--------------------+
103 |map | replica 2 | replica 1 | replica 0 |
104 +----+--------------------+--------------------+--------------------+
106 The map is an index into a table detailing which machines form the
107 cluster.
109 */
111 #define BSID_REPLICA0(_id) ((_id)&0xfffffULL)
112 #define BSID_REPLICA1(_id) (((_id)>>20)&0xfffffULL)
113 #define BSID_REPLICA2(_id) (((_id)>>40)&0xfffffULL)
114 #define BSID_MAP(_id) (((_id)>>60)&0xfULL)
116 #define BSID(_map, _rep0, _rep1, _rep2) ((((u64)(_map))<<60) | \
117 (((u64)(_rep2))<<40) | \
118 (((u64)(_rep1))<<20) | ((u64)(_rep0)))
120 typedef struct bsserver_t_struct {
121 char *hostname;
122 struct sockaddr_in sin;
123 } bsserver_t;
125 #define MAX_SERVERS 16
127 #define CLUSTER_MAX_REPLICAS 3
128 typedef struct bscluster_t_struct {
129 int servers[CLUSTER_MAX_REPLICAS];
130 } bscluster_t;
132 #define MAX_CLUSTERS 16
134 #endif /* __BLOCKSTORE_H__ */