]> git.lizzy.rs Git - plan9front.git/blob - sys/man/6/venti
iostats: dup 9p pipe to both fd 0 and fd 1 for exportfs
[plan9front.git] / sys / man / 6 / venti
1 .TH VENTI 6
2 .SH NAME
3 venti \- archival storage server
4 .SH DESCRIPTION
5 Venti is a block storage server intended for archival data.
6 In a Venti server, the SHA1 hash of a block's contents acts
7 as the block identifier for read and write operations.
8 This approach enforces a write-once policy, preventing
9 accidental or malicious destruction of data.  In addition,
10 duplicate copies of a block are coalesced, reducing the
11 consumption of storage and simplifying the implementation
12 of clients.
13 .PP
14 This manual page documents the basic concepts of
15 block storage using Venti as well as the Venti network protocol.
16 .PP
17 .IR Venti (1)
18 documents some simple clients.
19 .IR Vac (1)
20 and
21 .IR vacfs (4)
22 are more complex clients.
23 .PP
24 .IR Venti (2)
25 describes a C library interface for accessing
26 Venti servers and manipulating Venti data structures.
27 .PP
28 .IR Venti (8)
29 describes the programs used to run a Venti server.
30 .PP
31 .SS "Scores
32 The SHA1 hash that identifies a block is called its
33 .IR score .
34 The score of the zero-length block is called the
35 .IR "zero score" .
36 .PP
37 Scores may have an optional 
38 .IB label :
39 prefix, typically used to
40 describe the format of the data.
41 For example, 
42 .IR vac (1)
43 uses a
44 .B vac:
45 prefix, while vbackup uses prefixes corresponding to the file system
46 types: 
47 .BR ext2: ,
48 .BR ffs: ,
49 and so on.
50 .SS "Files and Directories
51 Venti accepts blocks up to 56 kilobytes in size.  
52 By convention, Venti clients use hash trees of blocks to
53 represent arbitrary-size data
54 .IR files .
55 The data to be stored is split into fixed-size
56 blocks and written to the server, producing a list
57 of scores.
58 The resulting list of scores is split into fixed-size pointer
59 blocks (using only an integral number of scores per block)
60 and written to the server, producing a smaller list
61 of scores.
62 The process continues, eventually ending with the
63 score for the hash tree's top-most block.
64 Each file stored this way is summarized by
65 a
66 .B VtEntry
67 structure recording the top-most score, the depth
68 of the tree, the data block size, and the pointer block size.
69 One or more 
70 .B VtEntry
71 structures can be concatenated
72 and stored as a special file called a
73 .IR directory .
74 In this
75 manner, arbitrary trees of files can be constructed
76 and stored.
77 .PP
78 Scores passed between programs conventionally refer
79 to
80 .B VtRoot
81 blocks, which contain descriptive information
82 as well as the score of a directory block containing a small number
83 of directory entries.
84 .PP
85 Conventionally, programs do not mix data and directory entries
86 in the same file.  Instead, they keep two separate files, one with
87 directory entries and one with metadata referencing those
88 entries by position.
89 Keeping this parallel representation is a minor annoyance
90 but makes it possible for general programs like
91 .I venti/copy
92 (see
93 .IR venti (1))
94 to traverse the block tree without knowing the specific details
95 of any particular program's data.
96 .SS "Block Types
97 To allow programs to traverse these structures without
98 needing to understand their higher-level meanings,
99 Venti tags each block with a type.  The types are:
100 .PP
101 .nf
102 .ft L
103     VtDataType     000  \f1data\fL
104     VtDataType+1   001  \fRscores of \fPVtDataType\fR blocks\fL
105     VtDataType+2   002  \fRscores of \fPVtDataType+1\fR blocks\fL
106     \fR\&...\fL
107     VtDirType      010  VtEntry\fR structures\fL
108     VtDirType+1    011  \fRscores of \fLVtDirType\fR blocks\fL
109     VtDirType+2    012  \fRscores of \fLVtDirType+1\fR blocks\fL
110     \fR\&...\fL
111     VtRootType     020  VtRoot\fR structure\fL
112 .fi
113 .PP
114 The octal numbers listed are the type numbers used
115 by the commands below.
116 (For historical reasons, the type numbers used on
117 disk and on the wire are different from the above.
118 They do not distinguish
119 .BI VtDataType+ n
120 blocks from
121 .BI VtDirType+ n
122 blocks.)
123 .SS "Zero Truncation
124 To avoid storing the same short data blocks padded with
125 differing numbers of zeros, Venti clients working with fixed-size
126 blocks conventionally
127 `zero truncate' the blocks before writing them to the server.
128 For example, if a 1024-byte data block contains the 
129 11-byte string 
130 .RB ` hello " " world '
131 followed by 1013 zero bytes,
132 a client would store only the 11-byte block.
133 When the client later read the block from the server,
134 it would append zero bytes to the end as necessary to
135 reach the expected size.
136 .PP
137 When truncating pointer blocks
138 .RB ( VtDataType+ \fIn
139 and
140 .BI VtDirType+ n
141 blocks),
142 trailing zero scores are removed
143 instead of trailing zero bytes.
144 .PP
145 Because of the truncation convention,
146 any file consisting entirely of zero bytes,
147 no matter what its length, will be represented by the zero score:
148 the data blocks contain all zeros and are thus truncated
149 to the empty block, and the pointer blocks contain all zero scores
150 and are thus also truncated to the empty block, 
151 and so on up the hash tree.
152 .SS Network Protocol
153 A Venti session begins when a
154 .I client
155 connects to the network address served by a Venti
156 .IR server ;
157 the conventional address is 
158 .BI tcp! server !venti
159 (the
160 .B venti
161 port is 17034).
162 Both client and server begin by sending a version
163 string of the form
164 .BI venti- versions - comment \en \fR.
165 The
166 .I versions
167 field is a list of acceptable versions separated by
168 colons.
169 The protocol described here is version
170 .BR 02 .
171 The client is responsible for choosing a common
172 version and sending it in the
173 .B VtThello
174 message, described below.
175 .PP
176 After the initial version exchange, the client transmits
177 .I requests
178 .RI ( T-messages )
179 to the server, which subsequently returns
180 .I replies
181 .RI ( R-messages )
182 to the client.
183 The combined act of transmitting (receiving) a request
184 of a particular type, and receiving (transmitting) its reply
185 is called a
186 .I transaction
187 of that type.
188 .PP
189 Each message consists of a sequence of bytes.
190 Two-byte fields hold unsigned integers represented
191 in big-endian order (most significant byte first).
192 Data items of variable lengths are represented by
193 a one-byte field specifying a count,
194 .IR n ,
195 followed by
196 .I n
197 bytes of data.
198 Text strings are represented similarly,
199 using a two-byte count with
200 the text itself stored as a UTF-encoded sequence
201 of Unicode characters (see
202 .IR utf (6)).
203 Text strings are not
204 .SM NUL\c
205 -terminated:
206 .I n
207 counts the bytes of UTF data, which include no final
208 zero byte.
209 The
210 .SM NUL
211 character is illegal in text strings in the Venti protocol.
212 The maximum string length in Venti is 1024 bytes.
213 .PP
214 Each Venti message begins with a two-byte size field 
215 specifying the length in bytes of the message,
216 not including the length field itself.
217 The next byte is the message type, one of the constants
218 in the enumeration in the include file
219 .BR <venti.h> .
220 The next byte is an identifying
221 .IR tag ,
222 used to match responses to requests.
223 The remaining bytes are parameters of different sizes.
224 In the message descriptions, the number of bytes in a field
225 is given in brackets after the field name.
226 The notation
227 .IR parameter [ n ]
228 where
229 .I n
230 is not a constant represents a variable-length parameter:
231 .IR n [1]
232 followed by
233 .I n
234 bytes of data forming the
235 .IR parameter .
236 The notation
237 .IR string [ s ]
238 (using a literal
239 .I s
240 character)
241 is shorthand for
242 .IR s [2]
243 followed by
244 .I s
245 bytes of UTF-8 text.
246 The notation
247 .IR parameter []
248 where 
249 .I parameter
250 is the last field in the message represents a 
251 variable-length field that comprises all remaining
252 bytes in the message.
253 .PP
254 All Venti RPC messages are prefixed with a field
255 .IR size [2]
256 giving the length of the message that follows
257 (not including the
258 .I size
259 field itself).
260 The message bodies are:
261 .ta \w'\fLVtTgoodbye 'u
262 .IP
263 .ne 2v
264 .B VtThello
265 .IR tag [1]
266 .IR version [ s ]
267 .IR uid [ s ]
268 .IR strength [1]
269 .IR crypto [ n ]
270 .IR codec [ n ]
271 .br
272 .B VtRhello
273 .IR tag [1]
274 .IR sid [ s ] 
275 .IR rcrypto [1]
276 .IR rcodec [1]
277 .IP
278 .ne 2v
279 .B VtTping
280 .IR tag [1]
281 .br
282 .B VtRping
283 .IR tag [1]
284 .IP
285 .ne 2v
286 .B VtTread
287 .IR tag [1]
288 .IR score [20]
289 .IR type [1]
290 .IR pad [1]
291 .IR count [2]
292 .br
293 .B VtRead
294 .IR tag [1]
295 .IR data []
296 .IP
297 .ne 2v
298 .B VtTwrite
299 .IR tag [1]
300 .IR type [1]
301 .IR pad [3]
302 .IR data []
303 .br
304 .B VtRwrite
305 .IR tag [1]
306 .IR score [20]
307 .IP
308 .ne 2v
309 .B VtTsync
310 .IR tag [1]
311 .br
312 .B VtRsync
313 .IR tag [1]
314 .IP
315 .ne 2v
316 .B VtRerror
317 .IR tag [1]
318 .IR error [ s ]
319 .IP
320 .ne 2v
321 .B VtTgoodbye
322 .IR tag [1]
323 .PP
324 Each T-message has a one-byte
325 .I tag
326 field, chosen and used by the client to identify the message.
327 The server will echo the request's
328 .I tag
329 field in the reply.
330 Clients should arrange that no two outstanding
331 messages have the same tag field so that responses
332 can be distinguished.
333 .PP
334 The type of an R-message will either be one greater than
335 the type of the corresponding T-message or
336 .BR Rerror ,
337 indicating that the request failed.
338 In the latter case, the
339 .I error
340 field contains a string describing the reason for failure.
341 .PP
342 Venti connections must begin with a 
343 .B hello
344 transaction.
345 The
346 .B VtThello
347 message contains the protocol
348 .I version
349 that the client has chosen to use.
350 The fields
351 .IR strength ,
352 .IR crypto ,
353 and
354 .IR codec
355 could be used to add authentication, encryption,
356 and compression to the Venti session
357 but are currently ignored.
358 The 
359 .IR rcrypto ,
360 and
361 .I rcodec
362 fields in the 
363 .B VtRhello
364 response are similarly ignored.
365 The
366 .IR uid 
367 and
368 .IR sid
369 fields are intended to be the identity
370 of the client and server but, given the lack of
371 authentication, should be treated only as advisory.
372 The initial
373 .B hello
374 should be the only
375 .B hello
376 transaction during the session.
377 .PP
378 The
379 .B ping
380 message has no effect and 
381 is used mainly for debugging.
382 Servers should respond immediately to pings.
383 .PP
384 The
385 .B read
386 message requests a block with the given
387 .I score
388 and
389 .IR type .
390 Use
391 .I vttodisktype
392 and
393 .I vtfromdisktype
394 (see
395 .IR venti (2))
396 to convert a block type enumeration value
397 .RB ( VtDataType ,
398 etc.)
399 to the 
400 .I type
401 used on disk and in the protocol.
402 The
403 .I count
404 field specifies the maximum expected size
405 of the block.
406 The
407 .I data
408 in the reply is the block's contents.
409 .PP
410 The
411 .B write
412 message writes a new block of the given
413 .I type
414 with contents
415 .I data
416 to the server.
417 The response includes the
418 .I score
419 to use to read the block,
420 which should be the SHA1 hash of 
421 .IR data .
422 .PP
423 The Venti server may buffer written blocks in memory,
424 waiting until after responding to the
425 .B write
426 message before writing them to
427 permanent storage.
428 The server will delay the response to a
429 .B sync
430 message until after all blocks in earlier
431 .B write
432 messages have been written to permanent storage.
433 .PP
434 The
435 .B goodbye
436 message ends a session.  There is no
437 .BR VtRgoodbye :
438 upon receiving the
439 .BR VtTgoodbye
440 message, the server terminates up the connection.
441 .SH SEE ALSO
442 .IR venti (1),
443 .IR venti (2),
444 .IR venti (8)
445 .br
446 Sean Quinlan and Sean Dorward,
447 ``Venti: a new approach to archival storage'',
448 .I "Usenix Conference on File and Storage Technologies" ,
449 2002.