Imported Upstream version 3.3.3
[debian/amanda] / ndmp-src / ndmpconnobj.h
1 /*
2  * Copyright (c) 2009-2012 Zmanda, Inc.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
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 N Mathlida Ave, Suite 300
19  * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
20  */
21
22 /* An interface for devices that support direct-tcp access to a the device */
23
24 #ifndef NDMCONNOBJ_H
25 #define NDMCONNOBJ_H
26
27 #include "amanda.h"
28 #include "ndmlib.h"
29 #include "directtcp.h"
30 #include <glib-object.h>
31
32 GType   ndmp_connection_get_type        (void);
33 #define TYPE_NDMP_CONNECTION    (ndmp_connection_get_type())
34 #define NDMP_CONNECTION(obj)    G_TYPE_CHECK_INSTANCE_CAST((obj), ndmp_connection_get_type(), NDMPConnection)
35 #define IS_NDMP_CONNECTION(obj) G_TYPE_CHECK_INSTANCE_TYPE((obj), ndmp_connection_get_type ())
36 #define NDMP_CONNECTION_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), ndmp_connection_get_type(), NDMPConnectionClass)
37
38 /*
39  * Parent class for connections
40  */
41
42 typedef struct NDMPConnection {
43     GObject __parent__;
44
45     /* the ndmconn - interface to ndmlib */
46     struct ndmconn *conn;
47
48     /* integer to identify this connection */
49     int connid;
50
51     /* received notifications; note that this does not include all possible
52      * notifications, and that only one "queued" version of each notification
53      * is possible.  Each reason is 0 if no such notification has been
54      * received.  */
55     ndmp9_data_halt_reason data_halt_reason;
56     ndmp9_mover_halt_reason mover_halt_reason;
57     ndmp9_mover_pause_reason mover_pause_reason;
58     guint64 mover_pause_seek_position;
59
60     /* log state, if using verbose logging (private) */
61     gpointer log_state;
62
63     /* error info */
64     int last_rc;
65     gchar *startup_err;
66 } NDMPConnection;
67
68 typedef struct NDMPConnectionClass_ {
69     GObjectClass __parent__;
70
71     /* NOTE: this class is not subclassed, so its "methods" are not
72      * implemented via the usual GObject function-pointer mechanism,
73      * but are simple C functions. */
74 } NDMPConnectionClass;
75
76 /* Error handling */
77
78 /* Get the last NDMP error on this connection; returns NDMP4_NO_ERR (0)
79  * if no error occurred, or if there was a communications error.  This
80  * will also detect errors from the constructor.
81  *
82  * @param self: object
83  * @returns: error code
84  */
85 ndmp4_error ndmp_connection_err_code(
86     NDMPConnection *self);
87
88 /* Get the error message describing the most recent error on this object.
89  * This will always return a non-NULL string.  The result must be freed
90  * by the caller.
91  *
92  * @param self: object
93  * @returns: heap-allocated error message
94  */
95 gchar *ndmp_connection_err_msg(
96     NDMPConnection *self);
97
98 /* Set the verbose flag for this connection
99  *
100  * @param self: object
101  * @param verbose: TRUE for verbose logging
102  */
103 void ndmp_connection_set_verbose(
104     NDMPConnection *self,
105     gboolean verbose);
106
107 /*
108  * basic NDMP protocol operations
109  *
110  * All of these functions return TRUE on success.
111  */
112
113 gboolean ndmp_connection_scsi_open(
114         NDMPConnection *self,
115         gchar *device);
116
117 gboolean ndmp_connection_scsi_close(
118         NDMPConnection *self);
119
120 gboolean ndmp_connection_scsi_execute_cdb(
121         NDMPConnection *self,
122         guint32 flags, /* bitmask: NDMP9_SCSI_DATA_DIR_{IN,OUT}; OUT = to device */
123         guint32 timeout, /* in ms */
124         gpointer cdb,
125         gsize cdb_len,
126         gpointer dataout,
127         gsize dataout_len,
128         gsize *actual_dataout_len, /* output */
129         gpointer datain, /* output */
130         gsize datain_max_len, /* output buffer size */
131         gsize *actual_datain_len, /* output */
132         guint8 *status, /* output */
133         gpointer ext_sense, /* output */
134         gsize ext_sense_max_len, /* output buffer size */
135         gsize *actual_ext_sense_len /* output */
136         );
137
138 gboolean ndmp_connection_tape_open(
139         NDMPConnection *self,
140         gchar *device,
141         ndmp9_tape_open_mode mode);
142
143 gboolean ndmp_connection_tape_close(
144         NDMPConnection *self);
145
146 gboolean ndmp_connection_tape_mtio(
147         NDMPConnection *self,
148         ndmp9_tape_mtio_op tape_op,
149         gint count,
150         guint *resid_count);
151
152 gboolean ndmp_connection_tape_write(
153         NDMPConnection *self,
154         gpointer buf,
155         guint64 len,
156         guint64 *count); /* output */
157
158 gboolean ndmp_connection_tape_read(
159         NDMPConnection *self,
160         gpointer buf, /* output */
161         guint64 count, /* buffer size/requested read size */
162         guint64 *out_count); /* bytes read */
163
164 gboolean ndmp_connection_tape_get_state(
165         NDMPConnection *self,
166         guint64 *blocksize, /* 0 if not supported */
167         guint64 *file_num, /* all 1's if not supported */
168         guint64 *blockno); /* all 1's if not supported */
169         /* (other state variables should be added as needed) */
170
171 gboolean ndmp_connection_mover_set_record_size(
172         NDMPConnection *self,
173         guint32 record_size);
174
175 gboolean ndmp_connection_mover_set_window(
176         NDMPConnection *self,
177         guint64 offset,
178         guint64 length);
179
180 gboolean ndmp_connection_mover_read(
181         NDMPConnection *self,
182         guint64 offset,
183         guint64 length);
184
185 gboolean ndmp_connection_mover_continue(
186         NDMPConnection *self);
187
188 gboolean ndmp_connection_mover_listen(
189         NDMPConnection *self,
190         ndmp9_mover_mode mode,
191         ndmp9_addr_type addr_type,
192         DirectTCPAddr **addrs);
193
194 gboolean ndmp_connection_mover_connect(
195         NDMPConnection *self,
196         ndmp9_mover_mode mode,
197         DirectTCPAddr *addrs);
198
199 gboolean ndmp_connection_mover_abort(
200         NDMPConnection *self);
201
202 gboolean ndmp_connection_mover_stop(
203         NDMPConnection *self);
204
205 gboolean ndmp_connection_mover_close(
206         NDMPConnection *self);
207
208 gboolean ndmp_connection_mover_get_state(
209         NDMPConnection *self,
210         ndmp9_mover_state *state,
211         guint64 *bytes_moved,
212         guint64 *window_offset,
213         guint64 *window_length);
214         /* (other state variables should be added as needed) */
215
216 /* Synchronous notification interface.  This handles all types of notification,
217  * returning the result in the appropriate output parameter. */
218 gboolean ndmp_connection_wait_for_notify(
219         NDMPConnection *self,
220         /* NDMP_NOTIFY_DATA_HALTED */
221         ndmp9_data_halt_reason *data_halt_reason,
222         /* NDMP_NOTIFY_MOVER_HALTED */
223         ndmp9_mover_halt_reason *mover_halt_reason,
224         /* NDMP_NOTIFY_MOVER_PAUSED */
225         ndmp9_mover_pause_reason *mover_pause_reason,
226         guint64 *mover_pause_seek_position);
227
228 /* Synchronous notification interface.  This handles all types of notification,
229  * returning the result in the appropriate output parameter. */
230 int ndmp_connection_wait_for_notify_with_cond(
231         NDMPConnection *self,
232         /* NDMP_NOTIFY_DATA_HALTED */
233         ndmp9_data_halt_reason *data_halt_reason,
234         /* NDMP_NOTIFY_MOVER_HALTED */
235         ndmp9_mover_halt_reason *mover_halt_reason,
236         /* NDMP_NOTIFY_MOVER_PAUSED */
237         ndmp9_mover_pause_reason *mover_pause_reason,
238         guint64 *mover_pause_seek_position,
239         int    *cancelled,
240         GMutex *abort_mutex,
241         GCond *abort_cond);
242
243 /*
244  * Constructor
245  */
246
247 /* Get a new NDMP connection. If an error occurs, this returns an empty object
248  * with its err_msg and err_code set appropriately.
249  *
250  * @param hostname: hostname to connect to
251  * @param port: port to connect on
252  * @param username: username to login with
253  * @param password: password to login with
254  * @param auth: authentication method to use ("MD5", "TEXT", "NONE", or "VOID")
255  * @returns: NDMPConnection object
256  */
257 NDMPConnection *
258 ndmp_connection_new(
259     gchar *hostname,
260     gint port,
261     gchar *username,
262     gchar *password,
263     gchar *auth);
264
265 #endif