2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
8 * Copyright (c) 2007, The Storage Networking Industry Association.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * - Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
21 * - Neither the name of The Storage Networking Industry Association (SNIA)
22 * nor the names of its contributors may be used to endorse or promote
23 * products derived from this software without specific prior written
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
38 /* Copyright (c) 2007, The Storage Networking Industry Association. */
39 /* Copyright (c) 1996, 1997 PDC, Network Appliance. All Rights Reserved */
41 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
44 #ifndef _NDMP_COMMON_H
45 #define _NDMP_COMMON_H
49 #include "ndmpd_log.h"
52 #include <sys/types.h>
57 #include <bsm/adt_event.h>
60 #define XDR_AND_SIZE(func) (bool_t(*)(XDR*, ...))xdr_##func, sizeof (func)
61 #define AUTH_REQUIRED TRUE
62 #define AUTH_NOT_REQUIRED FALSE
63 #define NDMP_EOM_MAGIC "PRCMEOM"
68 extern mutex_t ndmpd_zfs_fd_lock
;
70 /* Connection data structure. */
71 typedef struct msg_info
{
73 struct ndmp_msg_handler
*mi_handler
;
77 typedef struct ndmp_connection
{
80 ulong_t conn_my_sequence
;
81 boolean_t conn_authorized
;
83 msg_info_t conn_msginfo
; /* received request or reply message */
84 ushort_t conn_version
;
85 void *conn_client_data
;
87 adt_session_data_t
*conn_ah
;
90 typedef void (*ndmp_con_handler_func_t
) (struct ndmp_connection
*);
92 typedef void ndmp_msg_handler_func_t(struct ndmp_connection
*, void *);
95 typedef struct ndmp_msg_handler
{
96 ndmp_msg_handler_func_t
*mh_func
;
97 bool_t(*mh_xdr_request
) (XDR
*xdrs
, ...);
98 int mh_sizeof_request
;
99 bool_t(*mh_xdr_reply
) (XDR
*xdrs
, ...);
101 } ndmp_msg_handler_t
;
103 typedef struct ndmp_handler
{
106 ndmp_message hm_message
;
107 boolean_t hm_auth_required
;
108 ndmp_msg_handler_t hm_msg_v
[3];
109 } hd_msgs
[INT_MAXCMD
];
113 * Function prototypes.
115 extern ndmp_connection_t
*ndmp_create_connection(void);
117 extern void ndmp_destroy_connection(ndmp_connection_t
*);
119 extern void ndmp_close(ndmp_connection_t
*);
121 extern int ndmp_connect(ndmp_connection_t
*,
125 extern int ndmp_run(ulong_t
,
126 ndmp_con_handler_func_t
);
128 extern int ndmp_process_requests(ndmp_connection_t
*);
130 extern int ndmp_send_response(ndmp_connection_t
*,
134 extern int ndmp_send_request(ndmp_connection_t
*,
140 extern int ndmp_send_request_lock(ndmp_connection_t
*,
146 extern void ndmp_free_message(ndmp_connection_t
*);
148 extern int ndmp_get_fd(ndmp_connection_t
*);
150 extern void ndmp_set_client_data(ndmp_connection_t
*,
153 extern void *ndmp_get_client_data(ndmp_connection_t
*);
155 extern void ndmp_set_version(ndmp_connection_t
*,
158 extern ushort_t
ndmp_get_version(ndmp_connection_t
*);
160 extern void ndmp_set_authorized(ndmp_connection_t
*,
165 * NDMP daemon callback functions.
166 * Called by backup/recover modules.
168 typedef char *ndmpd_get_env_func_t(void *, char *);
169 typedef int ndmpd_add_env_func_t(void *, char *, char *);
170 typedef void *ndmpd_get_name_func_t(void *, ulong_t
);
171 typedef int ndmpd_dispatch_func_t(void *, boolean_t
);
172 typedef void ndmpd_done_func_t(void *, int);
173 typedef int ndmpd_log_func_t(void *, char *, ...);
175 typedef int ndmpd_log_func_v3_t(void *, ndmp_log_type
, ulong_t
,
179 #define NDMPD_SELECT_MODE_READ 1
180 #define NDMPD_SELECT_MODE_WRITE 2
181 #define NDMPD_SELECT_MODE_EXCEPTION 4
183 typedef void ndmpd_file_handler_func_t(void *, int, ulong_t
);
185 typedef int ndmpd_add_file_handler_func_t(void *, void *, int, ulong_t
,
186 ndmpd_file_handler_func_t
*);
188 typedef int ndmpd_remove_file_handler_func_t(void *, int);
190 typedef int ndmpd_write_func_t(void *, char *, ulong_t
);
192 typedef int ndmpd_file_history_path_func_t(void *, char *, struct stat64
*,
195 typedef int ndmpd_file_history_dir_func_t(void *, char *, ulong_t
,
198 typedef int ndmpd_file_history_node_func_t(void *, ulong_t
, struct stat64
*,
201 typedef int ndmpd_seek_func_t(void *, u_longlong_t
, u_longlong_t
);
203 typedef int ndmpd_read_func_t(void *, char *, ulong_t
);
205 typedef int ndmpd_file_recovered_func_t(void *, char *, int);
207 typedef struct ndmpd_module_stats
{
208 u_longlong_t ms_bytes_processed
;
209 u_longlong_t ms_est_bytes_remaining
;
210 ulong_t ms_est_time_remaining
;
211 } ndmpd_module_stats
;
214 * Parameter structure passed to module start function.
216 typedef struct ndmpd_module_params
{
217 void *mp_daemon_cookie
;
218 void **mp_module_cookie
;
219 ushort_t mp_protocol_version
;
220 ndmp_data_operation mp_operation
;
221 ndmpd_module_stats
*mp_stats
;
222 ndmpd_get_env_func_t
*mp_get_env_func
;
223 ndmpd_add_env_func_t
*mp_add_env_func
;
224 ndmpd_add_env_func_t
*mp_set_env_func
;
225 ndmpd_get_name_func_t
*mp_get_name_func
;
226 ndmpd_dispatch_func_t
*mp_dispatch_func
;
227 ndmpd_done_func_t
*mp_done_func
;
228 ndmpd_log_func_t
*mp_log_func
;
229 ndmpd_add_file_handler_func_t
*mp_add_file_handler_func
;
230 ndmpd_remove_file_handler_func_t
*mp_remove_file_handler_func
;
231 ndmpd_write_func_t
*mp_write_func
;
232 ndmpd_file_history_path_func_t
*mp_file_history_path_func
;
233 ndmpd_file_history_dir_func_t
*mp_file_history_dir_func
;
234 ndmpd_file_history_node_func_t
*mp_file_history_node_func
;
235 ndmpd_read_func_t
*mp_read_func
;
236 ndmpd_seek_func_t
*mp_seek_func
;
237 ndmpd_file_recovered_func_t
*mp_file_recovered_func
;
241 ndmpd_log_func_v3_t
*mp_log_func_v3
;
242 } ndmpd_module_params_t
;
244 #define MOD_ADDENV(m, n, v) \
245 (*(m)->mp_add_env_func)((m)->mp_daemon_cookie, n, v)
247 #define MOD_SETENV(m, n, v) \
248 (*(m)->mp_set_env_func)((m)->mp_daemon_cookie, n, v)
250 #define MOD_GETENV(m, e) \
251 (*(m)->mp_get_env_func)((m)->mp_daemon_cookie, e)
253 #define MOD_GETNAME(m, i) \
254 (*(m)->mp_get_name_func)((m)->mp_daemon_cookie, i)
256 #define MOD_LOG(m, ...) \
257 (*(m)->mp_log_func)((m)->mp_daemon_cookie, __VA_ARGS__)
259 #define MOD_READ(m, b, s) \
260 (*(m)->mp_read_func)((m)->mp_daemon_cookie, b, s)
262 #define MOD_WRITE(m, b, s) \
263 (*(m)->mp_write_func)((m)->mp_daemon_cookie, b, s)
265 #define MOD_DONE(m, e) \
266 (*(m)->mp_done_func)((m)->mp_daemon_cookie, e)
268 #define MOD_FILERECOVERD(m, n, e) \
269 (*(m)->mp_file_recovered_func)((m)->mp_daemon_cookie, n, e)
271 extern int ndmp_log_msg_id
;
273 #define MOD_LOGV3(m, t, ...) \
274 (*(m)->mp_log_func_v3)((m)->mp_daemon_cookie, (t), \
275 ++ndmp_log_msg_id, __VA_ARGS__)
277 #define MOD_LOGCONTV3(m, t, ...) \
278 (*(m)->mp_log_func_v3)((m)->mp_daemon_cookie, \
279 (t), ndmp_log_msg_id, __VA_ARGS__)
282 * Module function prototypes.
284 typedef int module_start_func_t(void *);
285 typedef int module_abort_func_t(void *);
286 #endif /* _NDMP_COMMON_H */