2 * Copyright (c) 2009-2012 Zmanda, Inc. All Rights Reserved.
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.
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
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
18 * Contact information: Zmanda Inc., 465 N Mathlida Ave, Suite 300
19 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
22 /* An interface for devices that support direct-tcp access to a the device */
29 #include "directtcp.h"
30 #include <glib-object.h>
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)
39 * Parent class for connections
42 typedef struct NDMPConnection {
45 /* the ndmconn - interface to ndmlib */
48 /* integer to identify this connection */
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
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;
60 /* log state, if using verbose logging (private) */
68 typedef struct NDMPConnectionClass_ {
69 GObjectClass __parent__;
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;
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.
83 * @returns: error code
85 ndmp4_error ndmp_connection_err_code(
86 NDMPConnection *self);
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
93 * @returns: heap-allocated error message
95 gchar *ndmp_connection_err_msg(
96 NDMPConnection *self);
98 /* Set the verbose flag for this connection
100 * @param self: object
101 * @param verbose: TRUE for verbose logging
103 void ndmp_connection_set_verbose(
104 NDMPConnection *self,
108 * basic NDMP protocol operations
110 * All of these functions return TRUE on success.
113 gboolean ndmp_connection_scsi_open(
114 NDMPConnection *self,
117 gboolean ndmp_connection_scsi_close(
118 NDMPConnection *self);
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 */
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 */
138 gboolean ndmp_connection_tape_open(
139 NDMPConnection *self,
141 ndmp9_tape_open_mode mode);
143 gboolean ndmp_connection_tape_close(
144 NDMPConnection *self);
146 gboolean ndmp_connection_tape_mtio(
147 NDMPConnection *self,
148 ndmp9_tape_mtio_op tape_op,
152 gboolean ndmp_connection_tape_write(
153 NDMPConnection *self,
156 guint64 *count); /* output */
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 */
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) */
171 gboolean ndmp_connection_mover_set_record_size(
172 NDMPConnection *self,
173 guint32 record_size);
175 gboolean ndmp_connection_mover_set_window(
176 NDMPConnection *self,
180 gboolean ndmp_connection_mover_read(
181 NDMPConnection *self,
185 gboolean ndmp_connection_mover_continue(
186 NDMPConnection *self);
188 gboolean ndmp_connection_mover_listen(
189 NDMPConnection *self,
190 ndmp9_mover_mode mode,
191 ndmp9_addr_type addr_type,
192 DirectTCPAddr **addrs);
194 gboolean ndmp_connection_mover_connect(
195 NDMPConnection *self,
196 ndmp9_mover_mode mode,
197 DirectTCPAddr *addrs);
199 gboolean ndmp_connection_mover_abort(
200 NDMPConnection *self);
202 gboolean ndmp_connection_mover_stop(
203 NDMPConnection *self);
205 gboolean ndmp_connection_mover_close(
206 NDMPConnection *self);
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) */
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);
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,
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.
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