2 * Copyright (c) 2009, 2010 Zmanda, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * Contact information: Zmanda Inc., 465 N Mathlida Ave, Suite 300
18 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
21 /* An interface for devices that support direct-tcp access to a the device */
28 #include "directtcp.h"
29 #include <glib-object.h>
31 GType ndmp_connection_get_type (void);
32 #define TYPE_NDMP_CONNECTION (ndmp_connection_get_type())
33 #define NDMP_CONNECTION(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), ndmp_connection_get_type(), NDMPConnection)
34 #define IS_NDMP_CONNECTION(obj) G_TYPE_CHECK_INSTANCE_TYPE((obj), ndmp_connection_get_type ())
35 #define NDMP_CONNECTION_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), ndmp_connection_get_type(), NDMPConnectionClass)
38 * Parent class for connections
41 typedef struct NDMPConnection_ {
44 /* the ndmconn - interface to ndmlib */
47 /* integer to identify this connection */
50 /* received notifications; note that this does not include all possible
51 * notifications, and that only one "queued" version of each notification
52 * is possible. Each reason is 0 if no such notification has been
54 ndmp9_data_halt_reason data_halt_reason;
55 ndmp9_mover_halt_reason mover_halt_reason;
56 ndmp9_mover_pause_reason mover_pause_reason;
57 guint64 mover_pause_seek_position;
59 /* log state, if using verbose logging (private) */
67 typedef struct NDMPConnectionClass_ {
68 GObjectClass __parent__;
70 /* NOTE: this class is not subclassed, so its "methods" are not
71 * implemented via the usual GObject function-pointer mechanism,
72 * but are simple C functions. */
73 } NDMPConnectionClass;
77 /* Get the last NDMP error on this connection; returns NDMP4_NO_ERR (0)
78 * if no error occurred, or if there was a communications error. This
79 * will also detect errors from the constructor.
82 * @returns: error code
84 ndmp4_error ndmp_connection_err_code(
85 NDMPConnection *self);
87 /* Get the error message describing the most recent error on this object.
88 * This will always return a non-NULL string. The result must be freed
92 * @returns: heap-allocated error message
94 gchar *ndmp_connection_err_msg(
95 NDMPConnection *self);
97 /* Set the verbose flag for this connection
100 * @param verbose: TRUE for verbose logging
102 void ndmp_connection_set_verbose(
103 NDMPConnection *self,
107 * basic NDMP protocol operations
109 * All of these functions return TRUE on success.
112 gboolean ndmp_connection_scsi_open(
113 NDMPConnection *self,
116 gboolean ndmp_connection_scsi_close(
117 NDMPConnection *self);
119 gboolean ndmp_connection_scsi_execute_cdb(
120 NDMPConnection *self,
121 guint32 flags, /* bitmask: NDMP9_SCSI_DATA_DIR_{IN,OUT}; OUT = to device */
122 guint32 timeout, /* in ms */
127 gsize *actual_dataout_len, /* output */
128 gpointer datain, /* output */
129 gsize datain_max_len, /* output buffer size */
130 gsize *actual_datain_len, /* output */
131 guint8 *status, /* output */
132 gpointer ext_sense, /* output */
133 gsize ext_sense_max_len, /* output buffer size */
134 gsize *actual_ext_sense_len /* output */
137 gboolean ndmp_connection_tape_open(
138 NDMPConnection *self,
140 ndmp9_tape_open_mode mode);
142 gboolean ndmp_connection_tape_close(
143 NDMPConnection *self);
145 gboolean ndmp_connection_tape_mtio(
146 NDMPConnection *self,
147 ndmp9_tape_mtio_op tape_op,
151 gboolean ndmp_connection_tape_write(
152 NDMPConnection *self,
155 guint64 *count); /* output */
157 gboolean ndmp_connection_tape_read(
158 NDMPConnection *self,
159 gpointer buf, /* output */
160 guint64 count, /* buffer size/requested read size */
161 guint64 *out_count); /* bytes read */
163 gboolean ndmp_connection_tape_get_state(
164 NDMPConnection *self,
165 guint64 *blocksize, /* 0 if not supported */
166 guint64 *file_num, /* all 1's if not supported */
167 guint64 *blockno); /* all 1's if not supported */
168 /* (other state variables should be added as needed) */
170 gboolean ndmp_connection_mover_set_record_size(
171 NDMPConnection *self,
172 guint32 record_size);
174 gboolean ndmp_connection_mover_set_window(
175 NDMPConnection *self,
179 gboolean ndmp_connection_mover_read(
180 NDMPConnection *self,
184 gboolean ndmp_connection_mover_continue(
185 NDMPConnection *self);
187 gboolean ndmp_connection_mover_listen(
188 NDMPConnection *self,
189 ndmp9_mover_mode mode,
190 ndmp9_addr_type addr_type,
191 DirectTCPAddr **addrs);
193 gboolean ndmp_connection_mover_connect(
194 NDMPConnection *self,
195 ndmp9_mover_mode mode,
196 DirectTCPAddr *addrs);
198 gboolean ndmp_connection_mover_abort(
199 NDMPConnection *self);
201 gboolean ndmp_connection_mover_stop(
202 NDMPConnection *self);
204 gboolean ndmp_connection_mover_close(
205 NDMPConnection *self);
207 gboolean ndmp_connection_mover_get_state(
208 NDMPConnection *self,
209 ndmp9_mover_state *state,
210 guint64 *bytes_moved,
211 guint64 *window_offset,
212 guint64 *window_length);
213 /* (other state variables should be added as needed) */
215 /* Synchronous notification interface. This handles all types of notification,
216 * returning the result in the appropriate output parameter. */
217 gboolean ndmp_connection_wait_for_notify(
218 NDMPConnection *self,
219 /* NDMP_NOTIFY_DATA_HALTED */
220 ndmp9_data_halt_reason *data_halt_reason,
221 /* NDMP_NOTIFY_MOVER_HALTED */
222 ndmp9_mover_halt_reason *mover_halt_reason,
223 /* NDMP_NOTIFY_MOVER_PAUSED */
224 ndmp9_mover_pause_reason *mover_pause_reason,
225 guint64 *mover_pause_seek_position);
231 /* Get a new NDMP connection. If an error occurs, this returns an empty object
232 * with its err_msg and err_code set appropriately.
234 * @param hostname: hostname to connect to
235 * @param port: port to connect on
236 * @param username: username to login with
237 * @param password: password to login with
238 * @param auth: authentication method to use ("MD5", "TEXT", "NONE", or "VOID")
239 * @returns: NDMPConnection object