root / drivers / log.h @ abdb293f
History | View | Annotate | Download (3.7 kB)
1 |
/*
|
---|---|
2 |
* Copyright (c) 2008, XenSource Inc.
|
3 |
* All rights reserved.
|
4 |
*
|
5 |
* Redistribution and use in source and binary forms, with or without
|
6 |
* modification, are permitted provided that the following conditions are met:
|
7 |
* * Redistributions of source code must retain the above copyright
|
8 |
* notice, this list of conditions and the following disclaimer.
|
9 |
* * Redistributions in binary form must reproduce the above copyright
|
10 |
* notice, this list of conditions and the following disclaimer in the
|
11 |
* documentation and/or other materials provided with the distribution.
|
12 |
* * Neither the name of XenSource Inc. nor the names of its contributors
|
13 |
* may be used to endorse or promote products derived from this software
|
14 |
* without specific prior written permission.
|
15 |
*
|
16 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
20 |
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
21 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
22 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
23 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
24 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
*/
|
28 |
|
29 |
/* log.h: API for writelog communication */
|
30 |
|
31 |
#ifndef __LOG_H__
|
32 |
#define __LOG_H__ 1 |
33 |
|
34 |
#include <inttypes.h> |
35 |
|
36 |
#define LOGCMD_SHMP "shmp" |
37 |
#define LOGCMD_PEEK "peek" |
38 |
#define LOGCMD_CLEAR "clrw" |
39 |
#define LOGCMD_GET "getw" |
40 |
#define LOGCMD_KICK "kick" |
41 |
|
42 |
#define CTLRSPLEN_SHMP 256 |
43 |
#define CTLRSPLEN_PEEK 4 |
44 |
#define CTLRSPLEN_CLEAR 4 |
45 |
#define CTLRSPLEN_GET 4 |
46 |
#define CTLRSPLEN_KICK 0 |
47 |
|
48 |
/* shmregion is arbitrarily capped at 8 megs for a minimum of
|
49 |
* 64 MB of data per read (if there are no contiguous regions)
|
50 |
* In the off-chance that there is more dirty data, multiple
|
51 |
* reads must be done */
|
52 |
#define SHMSIZE (8 * 1024 * 1024) |
53 |
#define SRINGSIZE 4096 |
54 |
|
55 |
/* The shared memory region is split up into 3 subregions:
|
56 |
* The first half is reserved for the dirty bitmap log.
|
57 |
* The second half begins with 1 page for read request descriptors,
|
58 |
* followed by a big area for supplying read data.
|
59 |
*/
|
60 |
static inline void* bmstart(void* shm) |
61 |
{ |
62 |
return shm;
|
63 |
} |
64 |
|
65 |
static inline void* bmend(void* shm) |
66 |
{ |
67 |
return shm + SHMSIZE/2; |
68 |
} |
69 |
|
70 |
static inline void* sringstart(void* shm) |
71 |
{ |
72 |
return bmend(shm);
|
73 |
} |
74 |
|
75 |
static inline void* sdatastart(void* shm) |
76 |
{ |
77 |
return sringstart(shm) + SRINGSIZE;
|
78 |
} |
79 |
|
80 |
static inline void* sdataend(void* shm) |
81 |
{ |
82 |
return shm + SHMSIZE;
|
83 |
} |
84 |
|
85 |
/* format for messages between log client and server */
|
86 |
struct log_ctlmsg {
|
87 |
char msg[4]; |
88 |
char params[16]; |
89 |
}; |
90 |
|
91 |
/* extent descriptor */
|
92 |
struct disk_range {
|
93 |
uint64_t sector; |
94 |
uint32_t count; |
95 |
}; |
96 |
|
97 |
/* dirty write logging space. This is an extent ring at the front,
|
98 |
* full of disk_ranges plus a pointer into the data area */
|
99 |
/* I think I'd rather have the header in front of each data section to
|
100 |
* avoid having two separate spaces that can run out, but then I'd either
|
101 |
* lose page alignment on the data blocks or spend an entire page on the
|
102 |
* header */
|
103 |
|
104 |
struct log_extent {
|
105 |
uint64_t sector; |
106 |
uint32_t count; |
107 |
uint32_t offset; /* offset from start of data area to start of extent */
|
108 |
}; |
109 |
|
110 |
/* struct above should be 16 bytes, or 256 extents/page */
|
111 |
|
112 |
typedef struct log_extent log_request_t; |
113 |
typedef struct log_extent log_response_t; |
114 |
|
115 |
DEFINE_RING_TYPES(log, log_request_t, log_response_t); |
116 |
|
117 |
#define LOG_HEADER_PAGES 4 |
118 |
|
119 |
#endif
|