8fbc7a2c71339642a9088a6da78af31fa3072085
[debian/amanda] / device-src / xfer-device.h
1 /*
2  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3  * Copyright (c) 2009, 2010 Zmanda, Inc.  All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published
7  * by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17  *
18  * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
19  * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
20  */
21
22 #ifndef XFER_DEVICE_H
23 #define XFER_DEVICE_H
24
25 #include "amxfer.h"
26 #include "device.h"
27
28 /* A transfer source that reads from a Device. The device must be positioned
29  * at the start of a file before the transfer is started.  The transfer will
30  * continue until the end of the file.
31  *
32  * Implemented in xfer-source-device.c
33  *
34  * @param device: Device object to read from
35  * @return: new element
36  */
37 XferElement *xfer_source_device(
38     Device *device);
39
40 /* A transfer destination that writes bytes to a Device.  The device should have a
41  * file started, ready for a device_write_block call.  On completion of the transfer,
42  * the file will be finished.
43  *
44  * Implemented in xfer-dest-device.c
45  *
46  * @param device: the Device to write to, with a file started
47  * @param max_memory: total amount of memory to use for buffers, or zero
48  *                    for a reasonable default.
49  * @return: new element
50  */
51 XferElement *xfer_dest_device(
52     Device *device,
53     size_t max_memory);
54
55 /*
56  * class declaration for XferDestTaper (an abstract base class)
57  */
58
59 GType xfer_dest_taper_get_type(void);
60 #define XFER_DEST_TAPER_TYPE (xfer_dest_taper_get_type())
61 #define XFER_DEST_TAPER(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), xfer_dest_taper_get_type(), XferDestTaper)
62 #define XFER_DEST_TAPER_CONST(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), xfer_dest_taper_get_type(), XferDestTaper const)
63 #define XFER_DEST_TAPER_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), xfer_dest_taper_get_type(), XferDestTaperClass)
64 #define IS_XFER_DEST_TAPER(obj) G_TYPE_CHECK_INSTANCE_TYPE((obj), xfer_dest_taper_get_type ())
65 #define XFER_DEST_TAPER_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), xfer_dest_taper_get_type(), XferDestTaperClass)
66
67 typedef struct XferDestTaper_ {
68     XferElement __parent__;
69 } XferDestTaper;
70
71 typedef struct {
72     XferElementClass __parent__;
73
74     /* see xfer-device.h for details of these methods */
75     void (*start_part)(XferDestTaper *self, gboolean retry_part, dumpfile_t *header);
76     void (*use_device)(XferDestTaper *self, Device *device);
77     void (*cache_inform)(XferDestTaper *self, const char *filename, off_t offset,
78                          off_t length);
79     guint64 (*get_part_bytes_written)(XferDestTaper *self);
80 } XferDestTaperClass;
81
82 /* Start writing the next part to the given device.  The part will be written
83  * to the device given to use_device, which should be open and properly positioned.
84  * It should not have a file open yet.
85  *
86  * @param self: the XferDestTaper object
87  * @param retry_part: retry the previous (incomplete) part if true
88  * @param header: part header
89  */
90 void xfer_dest_taper_start_part(
91     XferElement *self,
92     gboolean retry_part,
93     dumpfile_t *header);
94
95 /* Prepare to write subsequent parts to the given device.  The device must
96  * not be started yet.  It is not necessary to call this method for the first
97  * device used in a transfer.
98  *
99  * @param self: the XferDestTaper object
100  * @param device: the device
101  */
102 void xfer_dest_taper_use_device(
103     XferElement *self,
104     Device *device);
105
106 /* Add a slice of data to the cache for the element.  This is used by the taper
107  * when reading from holding disk, to tell the element which holding disk files
108  * contain the data that might be needed when rewinding, but can be used in any
109  * situation where the part data is already on-disk.  The order of calls to this
110  * function dictates the order in whch the files will be read, and no gaps or
111  * overlaps are supported.  Note, too, that this must be called *before* any of
112  * the data in the new file is sent into the transfer.
113  *
114  * @param self: the XferDestTaper object
115  * @param filename: the fully qualified filename of the cache file
116  * @param offset: offset into the file at which data begins
117  * @param length: length of data in file
118  */
119 void xfer_dest_taper_cache_inform(
120     XferElement *self,
121     const char *filename,
122     off_t offset,
123     off_t length);
124
125 /* Return the number of bytes written for the current part.
126  *
127  * @param self: the XferDestTaper object
128  */
129 guint64 xfer_dest_taper_get_part_bytes_written(
130     XferElement *self);
131
132 /* Constructor for XferDestTaperSplitter, which writes data to devices block by
133  * block and handles caching and splitting parts.
134  *
135  * @param first_device: the first device that will be used with this xfer, used
136  *                      to calculate some internal parameters
137  * @param max_memory: total amount of memory to use for buffers, or zero
138  *                    for a reasonable default.
139  * @param part_size: the desired size of each part
140  * @param use_mem_cache: if true, use the memory cache
141  * @param disk_cache_dirname: if not NULL, this is the directory in which the disk
142  *                    cache should be created
143  * @return: new element
144  */
145 XferElement *
146 xfer_dest_taper_splitter(
147     Device *first_device,
148     size_t max_memory,
149     guint64 part_size,
150     gboolean use_mem_cache,
151     const char *disk_cache_dirname);
152
153 /* Constructor for XferDestTaperDirectTCP, which uses DirectTCP to transfer data
154  * to devices (which must support the feature).
155  *
156  * @param first_device: the first device that will be used with this xfer, used
157  *                      to calculate some internal parameters
158  * @param part_size: the desired size of each part
159  * @return: new element
160  */
161 XferElement *
162 xfer_dest_taper_directtcp(
163     Device *first_device,
164     guint64 part_size);
165
166 /*
167  * XferSourceRecovery
168  */
169
170 /* Create a new XferSourceRecovery object.  Like XferDestTaper instances, this object
171  * will not start transferring data until xfer_source_recovery_start_part is called to
172  * give the device from which the data should flow.
173  *
174  * @param first device: teh first device that will be used with this xfer
175  * @returns: new element
176  */
177 XferElement *
178 xfer_source_recovery(
179     Device *first_device);
180
181 /* Start an XferSourceRecovery reading from a particular, pre-positioned device
182  *
183  * @param self: XferSourceRecovery object
184  * @param device: device to read from
185  */
186 void
187 xfer_source_recovery_start_part(
188     XferElement *elt,
189     Device *device);
190
191 /* Prepare to read subsequent parts from the given device.  The device must
192  * not be started yet.  It is not necessary to call this method for the first
193  * device used in a transfer.
194  *
195  * @param self: the XferSourceRecovery object
196  * @param device: the device
197  */
198 void xfer_source_recovery_use_device(
199     XferElement *self,
200     Device *device);
201
202 #endif