Print this page
NEX-13374 NDMP should be able to backup unmounted ZFS filesystems
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-9532 NDMP: readdir errors when file/directory has special characters
Reviewed by: Peer Dampmann <peer.dampmann@nexenta.com>
Reviewed by: Alexander Eremin <alexander.eremin@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
NEX-5801 Snapshots left over after failed backups
Reviewed by: Rick Mesta <rick.mesta@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
NEX-2911 NDMP logging should use syslog and is too chatty
NEX-2110 NDMP leaving zombie restore and backup threads around which hold up resources
NEX-727 Netbackup Catalog verification hangs waiting for NDMP server
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/cmd/ndmpd/ndmp/ndmpd_data.c
+++ new/usr/src/cmd/ndmpd/ndmp/ndmpd_data.c
1 1 /*
2 2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
3 - * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
3 + * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
4 4 */
5 5
6 6 /*
7 7 * BSD 3 Clause License
8 8 *
9 9 * Copyright (c) 2007, The Storage Networking Industry Association.
10 10 *
11 11 * Redistribution and use in source and binary forms, with or without
12 12 * modification, are permitted provided that the following conditions
13 13 * are met:
14 14 * - Redistributions of source code must retain the above copyright
15 15 * notice, this list of conditions and the following disclaimer.
16 16 *
17 17 * - Redistributions in binary form must reproduce the above copyright
18 18 * notice, this list of conditions and the following disclaimer in
19 19 * the documentation and/or other materials provided with the
20 20 * distribution.
21 21 *
22 22 * - Neither the name of The Storage Networking Industry Association (SNIA)
23 23 * nor the names of its contributors may be used to endorse or promote
24 24 * products derived from this software without specific prior written
25 25 * permission.
26 26 *
27 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
34 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 37 * POSSIBILITY OF SUCH DAMAGE.
38 38 */
39 39 /* Copyright (c) 2007, The Storage Networking Industry Association. */
40 40 /* Copyright (c) 1996, 1997 PDC, Network Appliance. All Rights Reserved */
41 41 #include <sys/types.h>
42 42 #include <sys/param.h>
43 43 #include <sys/socket.h>
44 +#include <syslog.h>
44 45 #include <netinet/in.h>
45 46 #include <errno.h>
46 47 #include <arpa/inet.h>
47 48 #include <stdlib.h>
48 49 #include <string.h>
49 50 #include "ndmpd_common.h"
50 51 #include "ndmpd.h"
51 52
52 53 static int ndmpd_data_error_send_v4(ndmpd_session_t *session,
53 54 ndmp_data_halt_reason reason);
54 55 static int ndmpd_data_error_send(ndmpd_session_t *session,
55 56 ndmp_data_halt_reason reason);
56 57 static void data_accept_connection_v3(void *cookie, int fd, ulong_t mode);
57 58 static int create_listen_socket_v3(ndmpd_session_t *session, ulong_t *addr,
58 59 ushort_t *port);
59 60 static ndmp_error data_connect_sock_v3(ndmpd_session_t *session, ulong_t addr,
60 61 ushort_t port);
61 62 static int discard_data_v3(ndmpd_session_t *session, ulong_t length);
62 63 static void nlp_release_job_stat(ndmpd_session_t *session);
63 64 static u_longlong_t ndmpd_data_get_info(ndmpd_session_t *session);
|
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
64 65
65 66 static ndmp_error ndmpd_tar_start_backup_v2(ndmpd_session_t *, char *,
66 67 ndmp_pval *, ulong_t);
67 68 static ndmp_error ndmpd_tar_start_recover_v2(ndmpd_session_t *, char *,
68 69 ndmp_pval *, ulong_t, ndmp_name *, ulong_t);
69 70 static ndmp_error ndmpd_tar_start_backup_v3(ndmpd_session_t *, char *,
70 71 ndmp_pval *, ulong_t);
71 72 static ndmp_error ndmpd_tar_start_recover_v3(ndmpd_session_t *,
72 73 ndmp_pval *, ulong_t, ndmp_name_v3 *, ulong_t);
73 74
74 -static ndmp_error ndmpd_zfs_start_op(ndmpd_session_t *,
75 - ndmp_pval *, ulong_t, ndmp_name_v3 *, ulong_t, enum ndmp_data_operation);
76 -
77 -
78 75 /*
79 76 * ************************************************************************
80 77 * NDMP V2 HANDLERS
81 78 * ************************************************************************
82 79 */
83 80
84 81 /*
85 82 * ndmpd_data_get_state_v2
86 83 *
87 84 * Request handler. Returns current data state.
88 85 *
89 86 * Parameters:
90 87 * connection (input) - connection handle.
91 88 * body (input) - request message body.
92 89 *
93 90 * Returns:
94 91 * void
95 92 */
96 93 /*ARGSUSED*/
97 94 void
98 95 ndmpd_data_get_state_v2(ndmp_connection_t *connection, void *body)
99 96 {
100 97 ndmp_data_get_state_reply_v2 reply;
101 98 ndmpd_session_t *session = ndmp_get_client_data(connection);
102 99
103 100 reply.error = NDMP_NO_ERR;
104 101 reply.operation = session->ns_data.dd_operation;
105 102 reply.state = session->ns_data.dd_state;
106 103 reply.halt_reason = session->ns_data.dd_halt_reason;
107 104
108 105 reply.est_time_remain =
109 106 session->ns_data.dd_module.dm_stats.ms_est_time_remaining;
110 107 reply.est_bytes_remain =
111 108 long_long_to_quad(
112 109 session->ns_data.dd_module.dm_stats.ms_est_bytes_remaining);
113 110
114 111 reply.bytes_processed =
115 112 long_long_to_quad(ndmpd_data_get_info(session));
116 113
117 114 reply.mover = session->ns_data.dd_mover;
118 115 reply.read_offset = long_long_to_quad(session->ns_data.dd_read_offset);
119 116 reply.read_length = long_long_to_quad(session->ns_data.dd_read_length);
120 117
121 118 ndmp_send_reply(connection, &reply,
122 119 "sending data_get_state reply");
123 120 }
124 121
125 122
126 123 /*
127 124 * ndmpd_data_start_backup_v2
128 125 *
129 126 * Request handler. Starts a backup.
130 127 *
131 128 * Parameters:
132 129 * connection (input) - connection handle.
133 130 * body (input) - request message body.
134 131 *
135 132 * Returns:
136 133 * void
137 134 */
138 135 void
139 136 ndmpd_data_start_backup_v2(ndmp_connection_t *connection, void *body)
140 137 {
141 138 ndmp_data_start_backup_request_v2 *request;
142 139 ndmp_data_start_backup_reply_v2 reply;
143 140 ndmpd_session_t *session = ndmp_get_client_data(connection);
144 141 ndmp_error err;
145 142
146 143 request = (ndmp_data_start_backup_request_v2 *)body;
147 144
148 145 reply.error = NDMP_NO_ERR;
|
↓ open down ↓ |
61 lines elided |
↑ open up ↑ |
149 146 session->ns_data.dd_mover = request->mover;
150 147
151 148 err = ndmpd_tar_start_backup_v2(session, request->bu_type,
152 149 request->env.env_val, request->env.env_len);
153 150
154 151 /*
155 152 * start_backup sends the reply if the backup is successfully started.
156 153 * Otherwise, send the reply containing the error here.
157 154 */
158 155 if (err != NDMP_NO_ERR) {
159 - NDMP_LOG(LOG_DEBUG, "err: %d", err);
156 + syslog(LOG_ERR, "err: %d", err);
160 157 reply.error = err;
161 158 ndmp_send_reply(connection, &reply,
162 159 "sending data_start_backup reply");
163 160 ndmpd_data_cleanup(session);
164 161 }
165 162 }
166 163
167 164 /*
168 165 * ndmpd_data_start_recover_v2
169 166 *
170 167 * Request handler. Starts a restore.
171 168 *
172 169 * Parameters:
173 170 * connection (input) - connection handle.
174 171 * body (input) - request message body.
175 172 *
176 173 * Returns:
177 174 * void
178 175 */
179 176 void
180 177 ndmpd_data_start_recover_v2(ndmp_connection_t *connection, void *body)
181 178 {
182 179 ndmp_data_start_recover_request_v2 *request;
183 180 ndmp_data_start_recover_reply_v2 reply;
184 181 ndmpd_session_t *session = ndmp_get_client_data(connection);
185 182 ndmp_error err;
186 183
187 184 request = (ndmp_data_start_recover_request_v2 *) body;
188 185 session->ns_data.dd_mover = request->mover;
189 186
190 187 err = ndmpd_tar_start_recover_v2(session, request->bu_type,
191 188 request->env.env_val, request->env.env_len,
192 189 request->nlist.nlist_val, request->nlist.nlist_len);
193 190
194 191 /*
195 192 * start_recover sends the reply if the recover is successfully started.
196 193 * Otherwise, send the reply containing the error here.
197 194 */
198 195 if (err != NDMP_NO_ERR) {
199 196 reply.error = err;
200 197 ndmp_send_reply(connection, &reply,
201 198 "sending ndmp_data_start_recover_request_v2 reply");
202 199 ndmpd_data_cleanup(session);
203 200 }
204 201 }
205 202
206 203 /*
207 204 * ndmpd_data_get_env_v2
208 205 *
209 206 * Request handler. Returns the environment variable array sent
210 207 * with the backup request. This request may only be sent with
211 208 * a backup operation is in progress.
212 209 *
213 210 * Parameters:
214 211 * connection (input) - connection handle.
215 212 * body (input) - request message body.
216 213 *
217 214 * Returns:
218 215 * void
|
↓ open down ↓ |
49 lines elided |
↑ open up ↑ |
219 216 */
220 217 /*ARGSUSED*/
221 218 void
222 219 ndmpd_data_get_env_v2(ndmp_connection_t *connection, void *body)
223 220 {
224 221 ndmp_data_get_env_reply reply;
225 222 ndmpd_session_t *session = ndmp_get_client_data(connection);
226 223
227 224 (void) memset((void*)&reply, 0, sizeof (reply));
228 225 if (session->ns_data.dd_operation != NDMP_DATA_OP_BACKUP) {
229 - NDMP_LOG(LOG_ERR, "Backup operation not active.");
226 + syslog(LOG_ERR, "Backup operation not active.");
230 227 reply.error = NDMP_ILLEGAL_STATE_ERR;
231 228 reply.env.env_len = 0;
232 229 } else {
233 230 reply.error = NDMP_NO_ERR;
234 231 reply.env.env_len = session->ns_data.dd_env_len;
235 232 reply.env.env_val = session->ns_data.dd_env;
236 233 }
237 234
238 235 ndmp_send_reply(connection, &reply, "sending data_get_env reply");
239 236 }
240 237
241 238
242 239 /*
243 240 * ndmpd_data_stop_v2
244 241 *
245 242 * Request handler. Stops the current data operation.
246 243 *
247 244 * Parameters:
248 245 * connection (input) - connection handle.
249 246 * body (input) - request message body.
250 247 *
251 248 * Returns:
|
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
252 249 * void
253 250 */
254 251 /*ARGSUSED*/
255 252 void
256 253 ndmpd_data_stop_v2(ndmp_connection_t *connection, void *body)
257 254 {
258 255 ndmp_data_stop_reply reply;
259 256 ndmpd_session_t *session = ndmp_get_client_data(connection);
260 257
261 258 if (session->ns_data.dd_state != NDMP_DATA_STATE_HALTED) {
262 - NDMP_LOG(LOG_ERR, "Invalid state to process stop request.");
263 259 reply.error = NDMP_ILLEGAL_STATE_ERR;
264 260 ndmp_send_reply(connection, &reply,
265 261 "sending data_stop reply");
266 262 return;
267 263 }
268 264 ndmp_waitfor_op(session);
269 265 ndmpd_data_cleanup(session);
270 266 ndmpd_file_history_cleanup(session, FALSE);
271 267
272 268 nlp_release_job_stat(session);
273 269
274 270 /* prepare for another data operation */
275 271 (void) ndmpd_data_init(session);
276 272 ndmpd_file_history_init(session);
277 273
278 274 reply.error = NDMP_NO_ERR;
279 275 ndmp_send_reply(connection, &reply, "sending data_stop reply");
280 276 }
281 277
282 278
283 279 /*
284 280 * ndmpd_data_abort_v2
285 281 *
286 282 * Request handler. Aborts the current backup/restore. The operation
287 283 * state is not changed to the halted state until after the operation
288 284 * has actually been aborted and the notify_halt request has been sent.
289 285 *
290 286 * Parameters:
291 287 * connection (input) - connection handle.
292 288 * body (input) - request message body.
293 289 *
294 290 * Returns:
295 291 * void
|
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
296 292 */
297 293 /*ARGSUSED*/
298 294 void
299 295 ndmpd_data_abort_v2(ndmp_connection_t *connection, void *body)
300 296 {
301 297 ndmp_data_abort_reply reply;
302 298 ndmpd_session_t *session = ndmp_get_client_data(connection);
303 299
304 300 if (session->ns_data.dd_state == NDMP_DATA_STATE_IDLE ||
305 301 session->ns_data.dd_state == NDMP_DATA_STATE_HALTED) {
306 - NDMP_LOG(LOG_ERR, "Invalid state to process abort request.");
307 302 reply.error = NDMP_ILLEGAL_STATE_ERR;
308 303 ndmp_send_reply(connection, &reply,
309 304 "sending data_abort reply");
310 305 return;
311 306 }
312 307 /*
313 308 * Don't go to HALTED state yet. Need to wait for data operation to
314 309 * abort. When this happens, ndmpd_done will get called and will
315 310 * perform the halt processing.
316 311 */
317 312 session->ns_data.dd_abort = TRUE;
318 313 (*session->ns_data.dd_module.dm_abort_func)(
319 314 session->ns_data.dd_module.dm_module_cookie);
320 315
321 316 reply.error = NDMP_NO_ERR;
322 317 ndmp_send_reply(connection, &reply, "sending data_abort reply");
323 318 }
324 319
325 320 /*
326 321 * ************************************************************************
327 322 * NDMP V3 HANDLERS
328 323 * ************************************************************************
329 324 */
330 325
331 326 /*
332 327 * ndmpd_data_get_state_v3
333 328 *
334 329 * Request handler. Returns current data state.
335 330 *
336 331 * Parameters:
337 332 * connection (input) - connection handle.
338 333 * body (input) - request message body.
339 334 *
340 335 * Returns:
341 336 * void
342 337 */
343 338 /*ARGSUSED*/
344 339 void
345 340 ndmpd_data_get_state_v3(ndmp_connection_t *connection, void *body)
346 341 {
347 342 ndmp_data_get_state_reply_v3 reply;
348 343 ndmpd_session_t *session = ndmp_get_client_data(connection);
349 344
350 345 (void) memset((void*)&reply, 0, sizeof (reply));
351 346
352 347 reply.error = NDMP_NO_ERR;
353 348 reply.invalid = NDMP_DATA_STATE_EST_BYTES_REMAIN_INVALID
354 349 | NDMP_DATA_STATE_EST_TIME_REMAIN_INVALID;
355 350 reply.operation = session->ns_data.dd_operation;
356 351 reply.state = session->ns_data.dd_state;
357 352 reply.halt_reason = session->ns_data.dd_halt_reason;
358 353
359 354 if (reply.operation == NDMP_DATA_OP_BACKUP)
360 355 reply.bytes_processed =
361 356 long_long_to_quad(
362 357 session->ns_data.dd_module.dm_stats.ms_bytes_processed);
363 358 else
364 359 reply.bytes_processed =
365 360 long_long_to_quad(ndmpd_data_get_info(session));
366 361
367 362 reply.est_bytes_remain = long_long_to_quad(0LL);
368 363 reply.est_time_remain = 0;
369 364 if (session->ns_data.dd_state != NDMP_DATA_STATE_IDLE)
370 365 ndmp_copy_addr_v3(&reply.data_connection_addr,
371 366 &session->ns_data.dd_data_addr);
372 367 reply.read_offset = long_long_to_quad(session->ns_data.dd_read_offset);
373 368 reply.read_length = long_long_to_quad(session->ns_data.dd_read_length);
374 369
375 370 ndmp_send_reply(connection, &reply,
376 371 "sending ndmp_data_get_state_v3 reply");
377 372 }
378 373
379 374
380 375 /*
381 376 * ndmpd_data_start_backup_v3
382 377 *
383 378 * Request handler. Starts a backup.
384 379 *
385 380 * Parameters:
386 381 * connection (input) - connection handle.
387 382 * body (input) - request message body.
388 383 *
389 384 * Returns:
390 385 * void
391 386 */
392 387 void
393 388 ndmpd_data_start_backup_v3(ndmp_connection_t *connection, void *body)
|
↓ open down ↓ |
77 lines elided |
↑ open up ↑ |
394 389 {
395 390 ndmp_data_start_backup_request_v3 *request;
396 391 ndmp_data_start_backup_reply_v3 reply;
397 392 ndmpd_session_t *session = ndmp_get_client_data(connection);
398 393
399 394 request = (ndmp_data_start_backup_request_v3 *)body;
400 395
401 396 (void) memset((void*)&reply, 0, sizeof (reply));
402 397
403 398 if (session->ns_data.dd_state != NDMP_DATA_STATE_CONNECTED) {
404 - NDMP_LOG(LOG_ERR,
405 - "Can't start new backup in current state.");
406 - NDMP_LOG(LOG_ERR,
407 - "Connection to the mover is not established.");
399 + syslog(LOG_ERR,
400 + "Can't start new backup in NOT CONNECTED state.");
408 401 reply.error = NDMP_ILLEGAL_STATE_ERR;
409 402 goto _error;
410 403 }
411 404
412 405 if (session->ns_data.dd_data_addr.addr_type == NDMP_ADDR_LOCAL) {
413 406 if (session->ns_tape.td_mode == NDMP_TAPE_READ_MODE) {
414 - NDMP_LOG(LOG_ERR, "Write protected device.");
407 + syslog(LOG_ERR, "Write protected device.");
415 408 reply.error = NDMP_WRITE_PROTECT_ERR;
416 409 goto _error;
417 410 }
418 411 }
419 412
420 413 if (strcasecmp(request->bu_type, NDMP_TAR_TYPE) == 0) {
421 414 session->ns_butype = NDMP_BUTYPE_TAR;
422 415 } else if (strcasecmp(request->bu_type, NDMP_DUMP_TYPE) == 0) {
423 416 session->ns_butype = NDMP_BUTYPE_DUMP;
424 417 } else if (strcasecmp(request->bu_type, NDMP_ZFS_TYPE) == 0) {
425 418 session->ns_butype = NDMP_BUTYPE_ZFS;
426 419 } else {
427 420 char msg_invalid[32];
428 421 char msg_types[32];
429 422
430 423 (void) snprintf(msg_invalid, 32, "Invalid backup type: %s.",
431 424 request->bu_type);
432 425 (void) snprintf(msg_types, 32,
433 - "Supported backup types are tar, dump, and zfs.");
426 + "Supported backup types are tar, dump.");
434 427
435 428 NDMP_APILOG((void *) session, NDMP_LOG_ERROR, ++ndmp_log_msg_id,
436 429 msg_invalid);
437 430 NDMP_APILOG((void *) session, NDMP_LOG_ERROR, ++ndmp_log_msg_id,
438 431 msg_types);
439 - NDMP_LOG(LOG_ERR, msg_invalid);
440 - NDMP_LOG(LOG_ERR, msg_types);
432 + syslog(LOG_ERR, "Invalid backup type: %s.",
433 + request->bu_type);
434 + syslog(LOG_ERR,
435 + "Supported backup types are tar, dump.");
441 436
442 437 reply.error = NDMP_ILLEGAL_ARGS_ERR;
443 438 goto _error;
444 439 }
445 440
446 - if (session->ns_butype == NDMP_BUTYPE_ZFS) {
447 - reply.error = ndmpd_zfs_start_op(session, request->env.env_val,
448 - request->env.env_len, NULL, 0, NDMP_DATA_OP_BACKUP);
449 - } else {
450 - reply.error = ndmpd_tar_start_backup_v3(session,
451 - request->bu_type, request->env.env_val,
452 - request->env.env_len);
453 - }
441 + reply.error = ndmpd_tar_start_backup_v3(session,
442 + request->bu_type, request->env.env_val,
443 + request->env.env_len);
454 444
455 445 /*
456 446 * *_start_backup* sends the reply if the backup is
457 447 * successfully started. Otherwise, send the reply
458 448 * containing the error here.
459 449 */
460 450
461 451 _error:
462 452
463 453 if (reply.error != NDMP_NO_ERR) {
464 454 ndmp_send_reply(connection, &reply,
465 455 "sending data_start_backup_v3 reply");
466 456 ndmpd_data_cleanup(session);
467 457 }
468 458 }
469 459
470 460 /*
471 461 * ndmpd_data_start_recover_v3
472 462 *
473 463 * Request handler. Starts a restore.
474 464 *
475 465 * Parameters:
476 466 * connection (input) - connection handle.
477 467 * body (input) - request message body.
478 468 *
479 469 * Returns:
480 470 * void
481 471 */
482 472 void
483 473 ndmpd_data_start_recover_v3(ndmp_connection_t *connection, void *body)
|
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
484 474 {
485 475 ndmp_data_start_recover_request_v3 *request;
486 476 ndmp_data_start_recover_reply_v3 reply;
487 477 ndmpd_session_t *session = ndmp_get_client_data(connection);
488 478
489 479 request = (ndmp_data_start_recover_request_v3 *)body;
490 480
491 481 (void) memset((void*)&reply, 0, sizeof (reply));
492 482
493 483 if (session->ns_data.dd_state != NDMP_DATA_STATE_CONNECTED) {
494 - NDMP_LOG(LOG_ERR, "Can't start new recover in current state.");
484 + syslog(LOG_ERR, "Can't start new recover in current state.");
495 485 reply.error = NDMP_ILLEGAL_STATE_ERR;
496 486 goto _error;
497 487 }
498 488
499 489 if (strcasecmp(request->bu_type, NDMP_TAR_TYPE) == 0) {
500 490 session->ns_butype = NDMP_BUTYPE_TAR;
501 491 } else if (strcasecmp(request->bu_type, NDMP_DUMP_TYPE) == 0) {
502 492 session->ns_butype = NDMP_BUTYPE_DUMP;
503 493 } else if (strcasecmp(request->bu_type, NDMP_ZFS_TYPE) == 0) {
504 494 session->ns_butype = NDMP_BUTYPE_ZFS;
505 495 } else {
506 496 char msg_invalid[32];
507 497 char msg_types[32];
508 498
509 499 (void) snprintf(msg_invalid, 32, "Invalid backup type: %s.",
510 500 request->bu_type);
511 501 (void) snprintf(msg_types, 32,
512 - "Supported backup types are tar, dump, and zfs.");
502 + "Supported backup types are tar, dump.");
513 503
514 504 NDMP_APILOG((void *) session, NDMP_LOG_ERROR, ++ndmp_log_msg_id,
515 505 msg_invalid);
516 506 NDMP_APILOG((void *) session, NDMP_LOG_ERROR, ++ndmp_log_msg_id,
517 507 msg_types);
518 - NDMP_LOG(LOG_ERR, msg_invalid);
519 - NDMP_LOG(LOG_ERR, msg_types);
508 + syslog(LOG_ERR, "Invalid backup type: %s.",
509 + request->bu_type);
510 + syslog(LOG_ERR,
511 + "Supported backup types are tar, dump.");
520 512
521 513 reply.error = NDMP_ILLEGAL_ARGS_ERR;
522 514 goto _error;
523 515 }
524 516
525 - if (session->ns_butype == NDMP_BUTYPE_ZFS) {
526 - reply.error = ndmpd_zfs_start_op(session, request->env.env_val,
527 - request->env.env_len, request->nlist.nlist_val,
528 - request->nlist.nlist_len, NDMP_DATA_OP_RECOVER);
529 - } else {
530 - reply.error = ndmpd_tar_start_recover_v3(session,
531 - request->env.env_val, request->env.env_len,
532 - request->nlist.nlist_val, request->nlist.nlist_len);
533 - }
517 + reply.error = ndmpd_tar_start_recover_v3(session,
518 + request->env.env_val, request->env.env_len,
519 + request->nlist.nlist_val, request->nlist.nlist_len);
534 520
535 521 /*
536 522 * *_start_recover* sends the reply if the recover is
537 523 * successfully started. Otherwise, send the reply
538 524 * containing the error here.
539 525 */
540 526
541 527 _error:
542 528
543 529 if (reply.error != NDMP_NO_ERR) {
544 530 ndmp_send_reply(connection, &reply,
545 531 "sending data_start_recover_v3 reply");
546 532 ndmpd_data_error(session, NDMP_DATA_HALT_INTERNAL_ERROR);
547 533 ndmpd_data_cleanup(session);
548 534 }
549 535 }
550 536
551 537 /*
552 538 * ndmpd_data_abort_v3
553 539 *
554 540 * Request handler. Aborts the current backup/restore. The operation
555 541 * state is not changed to the halted state until after the operation
556 542 * has actually been aborted and the notify_halt request has been sent.
557 543 *
558 544 * Parameters:
559 545 * connection (input) - connection handle.
560 546 * body (input) - request message body.
561 547 *
562 548 * Returns:
563 549 * void
564 550 */
|
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
565 551 /*ARGSUSED*/
566 552 void
567 553 ndmpd_data_abort_v3(ndmp_connection_t *connection, void *body)
568 554 {
569 555 ndmp_data_abort_reply reply;
570 556 ndmpd_session_t *session = ndmp_get_client_data(connection);
571 557
572 558 switch (session->ns_data.dd_state) {
573 559 case NDMP_DATA_STATE_IDLE:
574 560 reply.error = NDMP_ILLEGAL_STATE_ERR;
575 - NDMP_LOG(LOG_ERR, "Invalid state to process abort request.");
576 561 break;
577 562
578 563 case NDMP_DATA_STATE_ACTIVE:
579 564 /*
580 565 * Don't go to HALTED state yet. Need to wait for data
581 566 * operation to abort. When this happens, ndmpd_done_v3
582 567 * will get called and will perform the halt processing.
583 568 */
584 569 reply.error = NDMP_NO_ERR;
585 570 session->ns_data.dd_abort = TRUE;
586 571 if (session->ns_data.dd_module.dm_abort_func)
587 572 (*session->ns_data.dd_module.dm_abort_func)(
588 573 session->ns_data.dd_module.dm_module_cookie);
589 574 break;
|
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
590 575
591 576 case NDMP_DATA_STATE_HALTED:
592 577 case NDMP_DATA_STATE_LISTEN:
593 578 case NDMP_DATA_STATE_CONNECTED:
594 579 reply.error = NDMP_NO_ERR;
595 580 session->ns_data.dd_abort = TRUE;
596 581 ndmpd_data_error(session, NDMP_DATA_HALT_ABORTED);
597 582 break;
598 583 default:
599 584 reply.error = NDMP_ILLEGAL_STATE_ERR;
600 - NDMP_LOG(LOG_DEBUG, "Unknown data V3 state %d",
585 + syslog(LOG_ERR, "Unknown data V3 state %d",
601 586 session->ns_data.dd_state);
602 587 }
603 588
604 589 ndmp_send_reply(connection, &reply,
605 590 "sending data_abort_v3 reply");
606 591 }
607 592
608 593
609 594 /*
610 595 * ndmpd_data_stop_v3
611 596 *
612 597 * Request handler. Stops the current data operation.
613 598 *
614 599 * Parameters:
615 600 * connection (input) - connection handle.
616 601 * body (input) - request message body.
617 602 *
618 603 * Returns:
|
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
619 604 * void
620 605 */
621 606 /*ARGSUSED*/
622 607 void
623 608 ndmpd_data_stop_v3(ndmp_connection_t *connection, void *body)
624 609 {
625 610 ndmp_data_stop_reply reply;
626 611 ndmpd_session_t *session = ndmp_get_client_data(connection);
627 612
628 613 if (session->ns_data.dd_state != NDMP_DATA_STATE_HALTED) {
629 - NDMP_LOG(LOG_ERR, "Invalid state to process stop request.");
630 614 reply.error = NDMP_ILLEGAL_STATE_ERR;
631 615 ndmp_send_reply(connection, &reply,
632 616 "sending data_stop_v3 reply");
633 617 return;
634 618 }
635 619 ndmp_waitfor_op(session);
636 620 ndmpd_data_cleanup(session);
637 621 ndmpd_file_history_cleanup(session, FALSE);
638 622
639 623 /* prepare for another data operation */
640 624 (void) ndmpd_data_init(session);
641 625 ndmpd_file_history_init(session);
642 626
643 627 reply.error = NDMP_NO_ERR;
644 628 ndmp_send_reply(connection, &reply,
645 629 "sending data_stop_v3 reply");
646 630 }
647 631
648 632
649 633 /*
650 634 * ndmpd_data_listen_v3
651 635 *
652 636 * Request handler. Configures the server to listen for a connection
653 637 * from a remote mover.
654 638 *
655 639 * Parameters:
656 640 * connection (input) - connection handle.
657 641 * body (input) - request message body.
658 642 *
659 643 * Returns:
660 644 * void
661 645 */
662 646 void
663 647 ndmpd_data_listen_v3(ndmp_connection_t *connection, void *body)
664 648 {
665 649 ndmp_data_listen_request_v3 *request;
666 650 ndmp_data_listen_reply_v3 reply;
|
↓ open down ↓ |
27 lines elided |
↑ open up ↑ |
667 651 ndmpd_session_t *session = ndmp_get_client_data(connection);
668 652 ulong_t addr;
669 653 ushort_t port;
670 654
671 655 request = (ndmp_data_listen_request_v3 *)body;
672 656
673 657 (void) memset((void*)&reply, 0, sizeof (reply));
674 658
675 659 if (session->ns_data.dd_state != NDMP_DATA_STATE_IDLE) {
676 660 reply.error = NDMP_ILLEGAL_STATE_ERR;
677 - NDMP_LOG(LOG_ERR,
661 + syslog(LOG_ERR,
678 662 "Invalid internal data state to process listen request.");
679 663 } else if (session->ns_mover.md_state != NDMP_MOVER_STATE_IDLE) {
680 664 reply.error = NDMP_ILLEGAL_STATE_ERR;
681 - NDMP_LOG(LOG_ERR,
665 + syslog(LOG_ERR,
682 666 "Invalid mover state to process listen request.");
683 667 } else {
684 668 reply.error = NDMP_NO_ERR;
685 669 }
686 670
687 671 if (reply.error != NDMP_NO_ERR) {
688 672 ndmp_send_reply(connection, &reply,
689 673 "ndmp_data_listen_request_v3 reply");
690 674 return;
691 675 }
692 676
693 677 switch (request->addr_type) {
694 678 case NDMP_ADDR_LOCAL:
695 679 reply.data_connection_addr.addr_type = request->addr_type;
696 680 session->ns_data.dd_data_addr.addr_type = NDMP_ADDR_LOCAL;
697 681 break;
698 682 case NDMP_ADDR_TCP:
699 683 if (create_listen_socket_v3(session, &addr, &port) < 0) {
700 684 reply.error = NDMP_IO_ERR;
|
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
701 685 break;
702 686 }
703 687
704 688 reply.error = NDMP_NO_ERR;
705 689 reply.data_connection_addr.addr_type = request->addr_type;
706 690 reply.data_connection_addr.tcp_ip_v3 = htonl(addr);
707 691 reply.data_connection_addr.tcp_port_v3 = htons(port);
708 692 session->ns_data.dd_data_addr.addr_type = NDMP_ADDR_TCP;
709 693 session->ns_data.dd_data_addr.tcp_ip_v3 = addr;
710 694 session->ns_data.dd_data_addr.tcp_port_v3 = ntohs(port);
711 - NDMP_LOG(LOG_DEBUG, "listen_socket: %d",
695 + syslog(LOG_DEBUG, "listen_socket: %d",
712 696 session->ns_data.dd_listen_sock);
713 697 break;
714 698
715 699 default:
716 - NDMP_LOG(LOG_DEBUG, "Invalid address type: %d",
700 + syslog(LOG_ERR, "Invalid address type: %d",
717 701 request->addr_type);
718 702 reply.error = NDMP_ILLEGAL_ARGS_ERR;
719 703 break;
720 704 }
721 705
722 706 if (reply.error == NDMP_NO_ERR)
723 707 session->ns_data.dd_state = NDMP_DATA_STATE_LISTEN;
724 708
725 709 ndmp_send_reply(connection, &reply,
726 710 "ndmp_data_listen_request_v3 reply");
727 711 }
728 712
729 713
730 714 /*
731 715 * ndmpd_data_connect_v3
732 716 *
733 717 * Request handler. Connects the data server to either a local
734 718 * or remote mover.
735 719 *
736 720 * Parameters:
737 721 * connection (input) - connection handle.
738 722 * body (input) - request message body.
739 723 *
740 724 * Returns:
741 725 * void
742 726 */
743 727 void
744 728 ndmpd_data_connect_v3(ndmp_connection_t *connection, void *body)
745 729 {
|
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
746 730 ndmp_data_connect_request_v3 *request;
747 731 ndmp_data_connect_reply_v3 reply;
748 732 ndmpd_session_t *session = ndmp_get_client_data(connection);
749 733
750 734 request = (ndmp_data_connect_request_v3 *)body;
751 735
752 736 (void) memset((void*)&reply, 0, sizeof (reply));
753 737
754 738 if (!ndmp_valid_v3addr_type(request->addr.addr_type)) {
755 739 reply.error = NDMP_ILLEGAL_ARGS_ERR;
756 - NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
740 + syslog(LOG_ERR, "Invalid address type %d",
757 741 request->addr.addr_type);
758 742 } else if (session->ns_data.dd_state != NDMP_DATA_STATE_IDLE) {
759 743 reply.error = NDMP_ILLEGAL_STATE_ERR;
760 - NDMP_LOG(LOG_ERR, "Invalid state to process connect request.");
761 744 } else {
762 745 reply.error = NDMP_NO_ERR;
763 746 }
764 747
765 748 if (reply.error != NDMP_NO_ERR) {
766 749 ndmp_send_reply(connection, &reply,
767 750 "sending ndmp_data_connect_v3 reply");
768 751 return;
769 752 }
770 753
771 754 switch (request->addr.addr_type) {
772 755 case NDMP_ADDR_LOCAL:
773 756 /*
774 757 * Verify that the mover is listening for a
775 758 * local connection
776 759 */
777 760 if (session->ns_mover.md_state != NDMP_MOVER_STATE_LISTEN ||
778 761 session->ns_mover.md_listen_sock != -1) {
779 762 reply.error = NDMP_ILLEGAL_STATE_ERR;
780 - NDMP_LOG(LOG_ERR,
763 + syslog(LOG_ERR,
781 764 "Mover is not in local listen state.");
782 765 } else {
783 766 session->ns_mover.md_state = NDMP_MOVER_STATE_ACTIVE;
784 767 }
785 768 break;
786 769
787 770 case NDMP_ADDR_TCP:
788 771 reply.error = data_connect_sock_v3(session,
789 772 request->addr.tcp_ip_v3, request->addr.tcp_port_v3);
790 773 break;
791 774
792 775 default:
793 776 reply.error = NDMP_ILLEGAL_ARGS_ERR;
794 - NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
777 + syslog(LOG_ERR, "Invalid address type %d",
795 778 request->addr.addr_type);
796 779 }
797 780
798 781 if (reply.error == NDMP_NO_ERR)
799 782 session->ns_data.dd_state = NDMP_DATA_STATE_CONNECTED;
800 783
801 784 ndmp_send_reply(connection, &reply,
802 785 "sending ndmp_data_connect_v3 reply");
803 786 }
804 787
805 788
806 789 /*
807 790 * ************************************************************************
808 791 * NDMP V4 HANDLERS
809 792 * ************************************************************************
810 793 */
811 794
812 795 /*
813 796 * ndmpd_data_get_env_v4
814 797 *
815 798 * Request handler. Returns the environment variable array sent
816 799 * with the backup request. This request may only be sent with
817 800 * a backup operation is in progress.
818 801 *
819 802 * Parameters:
820 803 * connection (input) - connection handle.
821 804 * body (input) - request message body.
822 805 *
823 806 * Returns:
824 807 * void
825 808 */
826 809 /*ARGSUSED*/
|
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
827 810 void
828 811 ndmpd_data_get_env_v4(ndmp_connection_t *connection, void *body)
829 812 {
830 813 ndmp_data_get_env_reply reply;
831 814 ndmpd_session_t *session = ndmp_get_client_data(connection);
832 815
833 816 (void) memset((void*)&reply, 0, sizeof (reply));
834 817
835 818 if (session->ns_data.dd_state != NDMP_DATA_STATE_ACTIVE &&
836 819 session->ns_data.dd_state != NDMP_DATA_STATE_HALTED) {
837 - NDMP_LOG(LOG_ERR, "Invalid state for the data server.");
838 820 reply.error = NDMP_ILLEGAL_STATE_ERR;
839 821 reply.env.env_len = 0;
840 822 } else if (session->ns_data.dd_operation != NDMP_DATA_OP_BACKUP) {
841 - NDMP_LOG(LOG_ERR, "Backup operation not active.");
823 + syslog(LOG_ERR, "Backup operation not active.");
842 824 reply.error = NDMP_ILLEGAL_STATE_ERR;
843 825 reply.env.env_len = 0;
844 826 } else {
845 827 reply.error = NDMP_NO_ERR;
846 828 reply.env.env_len = session->ns_data.dd_env_len;
847 829 reply.env.env_val = session->ns_data.dd_env;
848 830 }
849 831
850 832 ndmp_send_reply(connection, &reply, "sending data_get_env reply");
851 833 }
852 834
853 835 /*
854 836 * ndmpd_data_get_state_v4
855 837 *
856 838 * Request handler. Returns current data state.
857 839 *
858 840 * Parameters:
859 841 * connection (input) - connection handle.
860 842 * body (input) - request message body.
861 843 *
862 844 * Returns:
863 845 * void
864 846 */
865 847 /*ARGSUSED*/
866 848 void
867 849 ndmpd_data_get_state_v4(ndmp_connection_t *connection, void *body)
868 850 {
869 851 ndmp_data_get_state_reply_v4 reply;
870 852 ndmpd_session_t *session = ndmp_get_client_data(connection);
871 853
872 854 (void) memset((void*)&reply, 0, sizeof (reply));
873 855
874 856 reply.error = NDMP_NO_ERR;
875 857 reply.unsupported = NDMP_DATA_STATE_EST_BYTES_REMAIN_INVALID
876 858 | NDMP_DATA_STATE_EST_TIME_REMAIN_INVALID;
877 859 reply.operation = session->ns_data.dd_operation;
878 860 reply.state = session->ns_data.dd_state;
879 861 reply.halt_reason = session->ns_data.dd_halt_reason;
880 862
881 863 if (reply.operation == NDMP_DATA_OP_BACKUP)
882 864 reply.bytes_processed = long_long_to_quad(
883 865 session->ns_data.dd_module.dm_stats.ms_bytes_processed);
884 866 else
885 867 reply.bytes_processed =
886 868 long_long_to_quad(ndmpd_data_get_info(session));
887 869
888 870 reply.est_bytes_remain = long_long_to_quad(0LL);
889 871 reply.est_time_remain = 0;
890 872 if (session->ns_data.dd_state != NDMP_DATA_STATE_IDLE)
891 873 ndmp_copy_addr_v4(&reply.data_connection_addr,
892 874 &session->ns_data.dd_data_addr_v4);
893 875
894 876 reply.read_offset = long_long_to_quad(session->ns_data.dd_read_offset);
895 877 reply.read_length = long_long_to_quad(session->ns_data.dd_read_length);
896 878
897 879 ndmp_send_reply(connection, &reply,
898 880 "sending ndmp_data_get_state_v4 reply");
899 881 free(reply.data_connection_addr.tcp_addr_v4);
900 882 }
901 883
902 884
903 885 /*
904 886 * ndmpd_data_connect_v4
905 887 *
906 888 * Request handler. Connects the data server to either a local
907 889 * or remote mover.
908 890 *
909 891 * Parameters:
910 892 * connection (input) - connection handle.
911 893 * body (input) - request message body.
912 894 *
913 895 * Returns:
914 896 * void
915 897 */
916 898 void
917 899 ndmpd_data_connect_v4(ndmp_connection_t *connection, void *body)
918 900 {
|
↓ open down ↓ |
67 lines elided |
↑ open up ↑ |
919 901 ndmp_data_connect_request_v4 *request;
920 902 ndmp_data_connect_reply_v4 reply;
921 903 ndmpd_session_t *session = ndmp_get_client_data(connection);
922 904
923 905 request = (ndmp_data_connect_request_v4 *)body;
924 906
925 907 (void) memset((void*)&reply, 0, sizeof (reply));
926 908
927 909 if (!ndmp_valid_v3addr_type(request->addr.addr_type)) {
928 910 reply.error = NDMP_ILLEGAL_ARGS_ERR;
929 - NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
911 + syslog(LOG_ERR, "Invalid address type %d",
930 912 request->addr.addr_type);
931 913 } else if (session->ns_data.dd_state != NDMP_DATA_STATE_IDLE) {
932 914 reply.error = NDMP_ILLEGAL_STATE_ERR;
933 - NDMP_LOG(LOG_ERR, "Invalid state to process connect request.");
934 915 } else {
935 916 reply.error = NDMP_NO_ERR;
936 917 }
937 918
938 919 if (reply.error != NDMP_NO_ERR) {
939 920 ndmp_send_reply(connection, &reply,
940 921 "sending ndmp_data_connect_v4 reply");
941 922 return;
942 923 }
943 924
944 925 switch (request->addr.addr_type) {
945 926 case NDMP_ADDR_LOCAL:
946 927 /*
947 928 * Verify that the mover is listening for a
948 929 * local connection
949 930 */
950 931 if (session->ns_mover.md_state != NDMP_MOVER_STATE_LISTEN ||
951 932 session->ns_mover.md_listen_sock != -1) {
952 933 reply.error = NDMP_ILLEGAL_STATE_ERR;
953 - NDMP_LOG(LOG_ERR,
934 + syslog(LOG_ERR,
954 935 "Mover is not in local listen state.");
955 936 } else {
956 937 session->ns_mover.md_state = NDMP_MOVER_STATE_ACTIVE;
957 938 }
958 939 break;
959 940
960 941 case NDMP_ADDR_TCP:
961 942 reply.error = data_connect_sock_v3(session,
962 943 request->addr.tcp_ip_v4(0), request->addr.tcp_port_v4(0));
963 944 break;
964 945
965 946 default:
966 947 reply.error = NDMP_ILLEGAL_ARGS_ERR;
967 - NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
948 + syslog(LOG_ERR, "Invalid address type %d",
968 949 request->addr.addr_type);
969 950 }
970 951
971 952 if (reply.error == NDMP_NO_ERR)
972 953 session->ns_data.dd_state = NDMP_DATA_STATE_CONNECTED;
973 954
974 955 ndmp_send_reply(connection, &reply,
975 956 "sending ndmp_data_connect_v4 reply");
976 957 }
977 958
978 959 /*
979 960 * ndmpd_data_listen_v4
980 961 *
981 962 * Request handler. Configures the server to listen for a connection
982 963 * from a remote mover.
983 964 *
984 965 * Parameters:
985 966 * connection (input) - connection handle.
986 967 * body (input) - request message body.
987 968 *
988 969 * Returns:
989 970 * void
990 971 */
991 972 void
992 973 ndmpd_data_listen_v4(ndmp_connection_t *connection, void *body)
993 974 {
994 975 ndmp_data_listen_request_v4 *request;
995 976 ndmp_data_listen_reply_v4 reply;
|
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
996 977 ndmpd_session_t *session = ndmp_get_client_data(connection);
997 978 ulong_t addr;
998 979 ushort_t port;
999 980
1000 981 request = (ndmp_data_listen_request_v4 *)body;
1001 982
1002 983 (void) memset((void*)&reply, 0, sizeof (reply));
1003 984
1004 985 if (session->ns_data.dd_state != NDMP_DATA_STATE_IDLE) {
1005 986 reply.error = NDMP_ILLEGAL_STATE_ERR;
1006 - NDMP_LOG(LOG_ERR,
987 + syslog(LOG_ERR,
1007 988 "Invalid internal data state to process listen request.");
1008 989 } else if (session->ns_mover.md_state != NDMP_MOVER_STATE_IDLE) {
1009 990 reply.error = NDMP_ILLEGAL_STATE_ERR;
1010 - NDMP_LOG(LOG_ERR,
991 + syslog(LOG_ERR,
1011 992 "Invalid mover state to process listen request.");
1012 993 } else {
1013 994 reply.error = NDMP_NO_ERR;
1014 995 }
1015 996
1016 997 if (reply.error != NDMP_NO_ERR) {
1017 998 ndmp_send_reply(connection, &reply,
1018 999 "ndmp_data_listen_request_v4 reply");
1019 1000 return;
1020 1001 }
1021 1002
1022 1003 switch (request->addr_type) {
1023 1004 case NDMP_ADDR_LOCAL:
1024 1005 reply.connect_addr.addr_type = request->addr_type;
1025 1006 session->ns_data.dd_data_addr.addr_type = NDMP_ADDR_LOCAL;
1026 1007 break;
1027 1008 case NDMP_ADDR_TCP:
1028 1009 if (create_listen_socket_v3(session, &addr, &port) < 0) {
1029 1010 reply.error = NDMP_IO_ERR;
1030 1011 break;
1031 1012 }
1032 1013
1033 1014 reply.error = NDMP_NO_ERR;
1034 1015 reply.connect_addr.addr_type = request->addr_type;
1035 1016 reply.connect_addr.tcp_addr_v4 =
1036 1017 ndmp_malloc(sizeof (ndmp_tcp_addr_v4));
1037 1018
1038 1019 reply.connect_addr.tcp_ip_v4(0) = htonl(addr);
1039 1020 reply.connect_addr.tcp_port_v4(0) = htons(port);
1040 1021 reply.connect_addr.tcp_len_v4 = 1;
1041 1022
1042 1023 session->ns_data.dd_data_addr_v4.addr_type = NDMP_ADDR_TCP;
1043 1024 session->ns_data.dd_data_addr_v4.tcp_addr_v4 =
|
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
1044 1025 ndmp_malloc(sizeof (ndmp_tcp_addr_v4));
1045 1026
1046 1027 session->ns_data.dd_data_addr_v4.tcp_ip_v4(0) = addr;
1047 1028 session->ns_data.dd_data_addr_v4.tcp_port_v4(0) = ntohs(port);
1048 1029 session->ns_data.dd_data_addr_v4.tcp_len_v4 = 1;
1049 1030
1050 1031 /* Copy that to data_addr for compatibility */
1051 1032 session->ns_data.dd_data_addr.addr_type = NDMP_ADDR_TCP;
1052 1033 session->ns_data.dd_data_addr.tcp_ip_v3 = addr;
1053 1034 session->ns_data.dd_data_addr.tcp_port_v3 = ntohs(port);
1054 - NDMP_LOG(LOG_DEBUG, "listen_socket: %d",
1035 + syslog(LOG_DEBUG, "listen_socket: %d",
1055 1036 session->ns_data.dd_listen_sock);
1056 1037 break;
1057 1038
1058 1039 default:
1059 - NDMP_LOG(LOG_DEBUG, "Invalid address type: %d",
1040 + syslog(LOG_ERR, "Invalid address type: %d",
1060 1041 request->addr_type);
1061 1042 reply.error = NDMP_ILLEGAL_ARGS_ERR;
1062 1043 break;
1063 1044 }
1064 1045
1065 1046 if (reply.error == NDMP_NO_ERR)
1066 1047 session->ns_data.dd_state = NDMP_DATA_STATE_LISTEN;
1067 1048
1068 1049 ndmp_send_reply(connection, &reply,
1069 1050 "ndmp_data_listen_request_v4 reply");
1070 1051 }
1071 1052
1072 1053
1073 1054 /*
1074 1055 * ndmpd_data_start_recover_filehist_v4
1075 1056 *
1076 1057 * Request handler. Recovers the file history (not supported yet)
1077 1058 * This command has an optional support in V4.
1078 1059 *
1079 1060 * Parameters:
1080 1061 * connection (input) - connection handle.
1081 1062 * body (input) - request message body.
|
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
1082 1063 *
1083 1064 * Returns:
1084 1065 * void
1085 1066 */
1086 1067 /*ARGSUSED*/
1087 1068 void
1088 1069 ndmpd_data_start_recover_filehist_v4(ndmp_connection_t *connection, void *body)
1089 1070 {
1090 1071 ndmp_data_start_recover_filehist_reply_v4 reply;
1091 1072
1092 - NDMP_LOG(LOG_DEBUG, "Request not supported");
1073 + syslog(LOG_DEBUG, "Request not supported");
1093 1074 reply.error = NDMP_NOT_SUPPORTED_ERR;
1094 1075
1095 1076 ndmp_send_reply(connection, &reply,
1096 1077 "sending ndmp_data_start_recover_filehist_reply_v4 reply");
1097 1078 }
1098 1079
1099 1080 /*
1100 1081 * ************************************************************************
1101 1082 * LOCALS
1102 1083 * ************************************************************************
1103 1084 */
1104 1085
1105 1086 /*
1106 1087 * ndmpd_data_error_send
1107 1088 *
1108 1089 * This function sends the notify message to the client.
1109 1090 *
1110 1091 * Parameters:
1111 1092 * session (input) - session pointer.
1112 1093 * reason (input) - halt reason.
1113 1094 *
1114 1095 * Returns:
1115 1096 * Error code
1116 1097 */
1117 1098 /*ARGSUSED*/
1118 1099 static int
1119 1100 ndmpd_data_error_send(ndmpd_session_t *session, ndmp_data_halt_reason reason)
1120 1101 {
1121 1102 ndmp_notify_data_halted_request req;
1122 1103
1123 1104 req.reason = session->ns_data.dd_halt_reason;
1124 1105 req.text_reason = "";
1125 1106
1126 1107 return (ndmp_send_request(session->ns_connection,
1127 1108 NDMP_NOTIFY_DATA_HALTED, NDMP_NO_ERR, &req, 0));
1128 1109 }
1129 1110
1130 1111
1131 1112 /*
1132 1113 * ndmpd_data_error_send_v4
1133 1114 *
1134 1115 * This function sends the notify message to the client.
1135 1116 *
1136 1117 * Parameters:
1137 1118 * session (input) - session pointer.
1138 1119 * reason (input) - halt reason.
1139 1120 *
1140 1121 * Returns:
1141 1122 * Error code
1142 1123 */
1143 1124 /*ARGSUSED*/
1144 1125 static int
1145 1126 ndmpd_data_error_send_v4(ndmpd_session_t *session, ndmp_data_halt_reason reason)
1146 1127 {
1147 1128 ndmp_notify_data_halted_request_v4 req;
1148 1129
1149 1130 req.reason = session->ns_data.dd_halt_reason;
1150 1131
1151 1132 return ndmp_send_request(session->ns_connection,
1152 1133 NDMP_NOTIFY_DATA_HALTED, NDMP_NO_ERR, &req, 0);
1153 1134 }
1154 1135
1155 1136
1156 1137 /*
1157 1138 * ndmpd_data_error
1158 1139 *
1159 1140 * This function is called when a data error has been detected.
1160 1141 * A notify message is sent to the client and the data server is
1161 1142 * placed into the halted state.
1162 1143 *
1163 1144 * Parameters:
1164 1145 * session (input) - session pointer.
1165 1146 * reason (input) - halt reason.
1166 1147 *
1167 1148 * Returns:
1168 1149 * void
1169 1150 */
1170 1151 void
1171 1152 ndmpd_data_error(ndmpd_session_t *session, ndmp_data_halt_reason reason)
1172 1153 {
1173 1154 if (session->ns_data.dd_state == NDMP_DATA_STATE_IDLE ||
1174 1155 session->ns_data.dd_state == NDMP_DATA_STATE_HALTED)
1175 1156 return;
1176 1157
1177 1158 if (session->ns_data.dd_operation == NDMP_DATA_OP_BACKUP) {
1178 1159 /*
1179 1160 * Send/discard any buffered file history data.
1180 1161 */
1181 1162 ndmpd_file_history_cleanup(session,
1182 1163 (reason == NDMP_DATA_HALT_SUCCESSFUL ? TRUE : FALSE));
1183 1164
1184 1165 /*
1185 1166 * If mover local and successful backup, write any
1186 1167 * remaining buffered data to tape.
1187 1168 */
|
↓ open down ↓ |
85 lines elided |
↑ open up ↑ |
1188 1169 if (session->ns_data.dd_data_addr.addr_type
1189 1170 == NDMP_ADDR_LOCAL && reason == NDMP_DATA_HALT_SUCCESSFUL)
1190 1171 (void) ndmpd_local_write_v3(session, 0, 0);
1191 1172 }
1192 1173
1193 1174 session->ns_data.dd_state = NDMP_DATA_STATE_HALTED;
1194 1175 session->ns_data.dd_halt_reason = reason;
1195 1176
1196 1177 if (session->ns_protocol_version == NDMPV4) {
1197 1178 if (ndmpd_data_error_send_v4(session, reason) < 0)
1198 - NDMP_LOG(LOG_DEBUG,
1179 + syslog(LOG_ERR,
1199 1180 "Error sending notify_data_halted request");
1200 1181 } else {
1201 1182 if (ndmpd_data_error_send(session, reason) < 0)
1202 - NDMP_LOG(LOG_DEBUG,
1183 + syslog(LOG_ERR,
1203 1184 "Error sending notify_data_halted request");
1204 1185 }
1205 1186
1206 1187 if (session->ns_data.dd_data_addr.addr_type == NDMP_ADDR_TCP) {
1207 1188 if (session->ns_data.dd_sock != -1) {
1208 1189 (void) ndmpd_remove_file_handler(session,
1209 1190 session->ns_data.dd_sock);
1210 1191 /*
1211 1192 * ndmpcopy: we use the same socket for the mover,
1212 1193 * so expect to close when mover is done!
1213 1194 */
1214 1195 if (session->ns_data.dd_sock !=
1215 1196 session->ns_mover.md_sock)
1216 1197 (void) close(session->ns_data.dd_sock);
1217 1198
1218 1199 session->ns_data.dd_sock = -1;
1219 1200 }
1220 1201 if (session->ns_data.dd_listen_sock != -1) {
1221 1202 (void) ndmpd_remove_file_handler(session,
1222 1203 session->ns_data.dd_listen_sock);
1223 1204
1224 1205 (void) close(session->ns_data.dd_listen_sock);
1225 1206 session->ns_data.dd_listen_sock = -1;
1226 1207 }
1227 1208 } else {
1228 1209 ndmpd_mover_error(session, NDMP_MOVER_HALT_CONNECT_CLOSED);
1229 1210 }
1230 1211 }
1231 1212
1232 1213
1233 1214 /*
1234 1215 * data_accept_connection_v3
1235 1216 *
1236 1217 * Accept a data connection from a remote mover.
1237 1218 * Called by ndmpd_select when a connection is pending on
1238 1219 * the data listen socket.
1239 1220 *
1240 1221 * Parameters:
1241 1222 * cookie (input) - session pointer.
1242 1223 * fd (input) - file descriptor.
1243 1224 * mode (input) - select mode.
1244 1225 *
1245 1226 * Returns:
1246 1227 * void
1247 1228 */
1248 1229 /*ARGSUSED*/
1249 1230 static void
|
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
1250 1231 data_accept_connection_v3(void *cookie, int fd, ulong_t mode)
1251 1232 {
1252 1233 ndmpd_session_t *session = (ndmpd_session_t *)cookie;
1253 1234 int from_len;
1254 1235 struct sockaddr_in from;
1255 1236
1256 1237 from_len = sizeof (from);
1257 1238 session->ns_data.dd_sock = accept(fd, (struct sockaddr *)&from,
1258 1239 &from_len);
1259 1240
1260 - NDMP_LOG(LOG_DEBUG, "sock fd: %d",
1241 + syslog(LOG_DEBUG, "sock fd: %d",
1261 1242 session->ns_data.dd_sock);
1262 - NDMP_LOG(LOG_DEBUG, "sin: port %d addr %s",
1243 + syslog(LOG_DEBUG, "sin: port %d addr %s",
1263 1244 ntohs(from.sin_port),
1264 1245 inet_ntoa(IN_ADDR(from.sin_addr.s_addr)));
1265 1246
1266 1247 (void) ndmpd_remove_file_handler(session, fd);
1267 1248 (void) close(session->ns_data.dd_listen_sock);
1268 1249 session->ns_data.dd_listen_sock = -1;
1269 1250
1270 1251 if (session->ns_data.dd_sock < 0) {
1271 - NDMP_LOG(LOG_DEBUG, "Accept error: %m");
1252 + syslog(LOG_ERR, "Accept error: %m");
1272 1253 ndmpd_data_error(session, NDMP_DATA_HALT_CONNECT_ERROR);
1273 1254 return;
1274 1255 }
1275 1256
1276 1257 /*
1277 1258 * Save the peer address.
1278 1259 */
1279 1260 session->ns_data.dd_data_addr.tcp_ip_v3 = from.sin_addr.s_addr;
1280 1261 session->ns_data.dd_data_addr.tcp_port_v3 = ntohs(from.sin_port);
1281 1262
1282 1263 /* Set the parameter of the new socket */
1283 1264 set_socket_options(session->ns_data.dd_sock);
1284 1265
1285 1266 session->ns_data.dd_state = NDMP_DATA_STATE_CONNECTED;
1286 1267 }
1287 1268
1288 1269
1289 1270 /*
1290 1271 * create_listen_socket_v3
1291 1272 *
1292 1273 * Creates the data sockets for listening for a remote mover/data
1293 1274 * incoming connections.
1294 1275 */
1295 1276 static int
1296 1277 create_listen_socket_v3(ndmpd_session_t *session, ulong_t *addr, ushort_t *port)
1297 1278 {
1298 1279 session->ns_data.dd_listen_sock = ndmp_create_socket(addr, port);
1299 1280 if (session->ns_data.dd_listen_sock < 0)
1300 1281 return (-1);
1301 1282
1302 1283 /*
1303 1284 * Add a file handler for the listen socket.
|
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
1304 1285 * ndmpd_select will call data_accept_connection when a
1305 1286 * connection is ready to be accepted.
1306 1287 */
1307 1288 if (ndmpd_add_file_handler(session, (void*)session,
1308 1289 session->ns_data.dd_listen_sock, NDMPD_SELECT_MODE_READ, HC_MOVER,
1309 1290 data_accept_connection_v3) < 0) {
1310 1291 (void) close(session->ns_data.dd_listen_sock);
1311 1292 session->ns_data.dd_listen_sock = -1;
1312 1293 return (-1);
1313 1294 }
1314 - NDMP_LOG(LOG_DEBUG, "addr: %s:%d",
1295 + syslog(LOG_DEBUG, "addr: %s:%d",
1315 1296 inet_ntoa(IN_ADDR(*addr)), ntohs(*port));
1316 1297
1317 1298 return (0);
1318 1299 }
1319 1300
1320 1301
1321 1302 /*
1322 1303 * data_connect_sock_v3
1323 1304 *
1324 1305 * Connect the data interface socket to the specified ip/port
1325 1306 *
1326 1307 * Parameters:
1327 1308 * session (input) - session pointer.
1328 1309 * addr (input) - IP address
1329 1310 * port (input) - port number
1330 1311 *
1331 1312 * Returns:
1332 1313 * NDMP_NO_ERR - backup successfully started.
1333 1314 * otherwise - error code of backup start error.
1334 1315 */
1335 1316 static ndmp_error
1336 1317 data_connect_sock_v3(ndmpd_session_t *session, ulong_t addr, ushort_t port)
1337 1318 {
1338 1319 int sock;
1339 1320
1340 1321 sock = ndmp_connect_sock_v3(addr, port);
1341 1322 if (sock < 0)
1342 1323 return (NDMP_CONNECT_ERR);
1343 1324
1344 1325 session->ns_data.dd_sock = sock;
1345 1326 session->ns_data.dd_data_addr.addr_type = NDMP_ADDR_TCP;
1346 1327 session->ns_data.dd_data_addr.tcp_ip_v3 = ntohl(addr);
1347 1328 session->ns_data.dd_data_addr.tcp_port_v3 = port;
1348 1329
1349 1330 return (NDMP_NO_ERR);
1350 1331 }
1351 1332
1352 1333
1353 1334 /*
1354 1335 * ndmpd_tar_start_backup_v3
1355 1336 *
1356 1337 * Start the backup work
1357 1338 *
1358 1339 * Parameters:
1359 1340 * session (input) - session pointer.
1360 1341 * bu_type (input) - backup type.
1361 1342 * env_val (input) - environment variable array.
1362 1343 * env_len (input) - length of env_val.
1363 1344 *
1364 1345 * Returns:
1365 1346 * NDMP_NO_ERR - backup successfully started.
|
↓ open down ↓ |
41 lines elided |
↑ open up ↑ |
1366 1347 * otherwise - error code of backup start error.
1367 1348 */
1368 1349 static ndmp_error
1369 1350 ndmpd_tar_start_backup_v3(ndmpd_session_t *session, char *bu_type,
1370 1351 ndmp_pval *env_val, ulong_t env_len)
1371 1352 {
1372 1353 int err;
1373 1354 ndmp_lbr_params_t *nlp;
1374 1355 ndmpd_module_params_t *params;
1375 1356 ndmp_data_start_backup_reply_v3 reply;
1357 + pthread_t tid;
1376 1358
1377 1359 (void) memset((void*)&reply, 0, sizeof (reply));
1378 1360
1379 1361 err = ndmpd_save_env(session, env_val, env_len);
1380 1362 if (err != NDMP_NO_ERR)
1381 1363 return (err);
1382 1364
1383 1365 nlp = ndmp_get_nlp(session);
1384 1366 NDMP_FREE(nlp->nlp_params);
1385 1367 params = nlp->nlp_params = ndmp_malloc(sizeof (ndmpd_module_params_t));
1386 1368 if (!params)
1387 1369 return (NDMP_NO_MEM_ERR);
1388 1370
1389 1371 params->mp_daemon_cookie = (void *)session;
1390 1372 params->mp_module_cookie = &session->ns_data.dd_module.dm_module_cookie;
1391 1373 params->mp_protocol_version = session->ns_protocol_version;
1392 1374 params->mp_operation = NDMP_DATA_OP_BACKUP;
1393 1375 params->mp_get_env_func = ndmpd_api_get_env;
1394 1376 params->mp_add_env_func = ndmpd_api_add_env;
1395 1377 params->mp_set_env_func = ndmpd_api_set_env;
1396 1378 params->mp_get_name_func = 0;
1397 1379 params->mp_dispatch_func = ndmpd_api_dispatch;
1398 1380 params->mp_done_func = ndmpd_api_done_v3;
1399 1381 if (session->ns_protocol_version == NDMPV4)
1400 1382 params->mp_log_func_v3 = ndmpd_api_log_v4;
1401 1383 else
1402 1384 params->mp_log_func_v3 = ndmpd_api_log_v3;
1403 1385
1404 1386 params->mp_add_file_handler_func = ndmpd_api_add_file_handler;
1405 1387 params->mp_remove_file_handler_func = ndmpd_api_remove_file_handler;
1406 1388 params->mp_write_func = ndmpd_api_write_v3;
1407 1389 params->mp_read_func = 0;
1408 1390 params->mp_file_recovered_func = 0;
1409 1391 params->mp_stats = &session->ns_data.dd_module.dm_stats;
1410 1392 session->ns_data.dd_module.dm_module_cookie = 0;
1411 1393
1412 1394 if (strcmp(bu_type, NDMP_DUMP_TYPE) == 0) {
1413 1395 NLP_SET(nlp, NLPF_DUMP);
1414 1396 params->mp_file_history_path_func = 0;
1415 1397 params->mp_file_history_dir_func =
1416 1398 ndmpd_api_file_history_dir_v3;
1417 1399 params->mp_file_history_node_func =
1418 1400 ndmpd_api_file_history_node_v3;
1419 1401 } else if (strcmp(bu_type, NDMP_TAR_TYPE) == 0) {
1420 1402 NLP_SET(nlp, NLPF_TAR);
1421 1403 params->mp_file_history_path_func =
1422 1404 ndmpd_api_file_history_file_v3;
1423 1405 params->mp_file_history_dir_func = 0;
1424 1406 params->mp_file_history_node_func = 0;
1425 1407 } else {
1426 1408 NLP_UNSET(nlp, NLPF_DUMP);
1427 1409 NLP_UNSET(nlp, NLPF_TAR);
1428 1410 }
1429 1411
1430 1412 session->ns_data.dd_module.dm_start_func = ndmpd_tar_backup_starter_v3;
1431 1413 session->ns_data.dd_module.dm_abort_func = ndmpd_tar_backup_abort_v3;
1432 1414
1433 1415 session->ns_data.dd_module.dm_stats.ms_est_bytes_remaining = 0;
1434 1416 session->ns_data.dd_module.dm_stats.ms_est_time_remaining = 0;
|
↓ open down ↓ |
49 lines elided |
↑ open up ↑ |
1435 1417 session->ns_data.dd_nlist_v3 = 0;
1436 1418 session->ns_data.dd_nlist_len = 0;
1437 1419 session->ns_data.dd_bytes_left_to_read = 0;
1438 1420 session->ns_data.dd_position = 0;
1439 1421 session->ns_data.dd_discard_length = 0;
1440 1422 session->ns_data.dd_read_offset = 0;
1441 1423 session->ns_data.dd_read_length = 0;
1442 1424
1443 1425 reply.error = ndmp_backup_get_params_v3(session, params);
1444 1426 if (reply.error != NDMP_NO_ERR) {
1445 - NDMP_LOG(LOG_DEBUG, "err: %d", err);
1427 + syslog(LOG_ERR, "err: %d", err);
1446 1428 NDMP_FREE(nlp->nlp_params);
1447 1429 return (reply.error);
1448 1430 }
1449 1431
1450 1432 reply.error = NDMP_NO_ERR;
1451 1433 if (ndmp_send_response(session->ns_connection, NDMP_NO_ERR,
1452 1434 &reply) < 0) {
1453 - NDMP_LOG(LOG_DEBUG, "Sending data_start_backup_v3 reply");
1435 + syslog(LOG_DEBUG, "Sending data_start_backup_v3 reply");
1454 1436 return (NDMP_NO_ERR);
1455 1437 }
1456 1438
1457 1439 NS_INC(nbk);
1458 1440 session->ns_data.dd_state = NDMP_DATA_STATE_ACTIVE;
1459 1441 session->ns_data.dd_operation = NDMP_DATA_OP_BACKUP;
1460 1442 session->ns_data.dd_abort = FALSE;
1461 1443
1462 1444 /*
1463 1445 * perform the backup
1464 1446 *
1465 1447 * Cannot wait for the thread to exit as we are replying to the
1466 1448 * client request here.
1467 1449 */
1468 - err = pthread_create(NULL, NULL,
1450 + err = pthread_create(&tid, NULL,
1469 1451 (funct_t)session->ns_data.dd_module.dm_start_func,
1470 1452 params);
1453 +
1471 1454 if (err != 0) {
1472 - NDMP_LOG(LOG_ERR, "Can't start backup session.");
1455 + syslog(LOG_ERR, "Can't start V3 backup session.");
1473 1456 return (NDMP_ILLEGAL_ARGS_ERR);
1474 1457 }
1475 1458
1459 + (void) pthread_detach(tid);
1460 +
1476 1461 return (NDMP_NO_ERR);
1477 1462 }
1478 1463
1479 1464 /*
1480 1465 * ndmpd_tar_start_recover_v3
1481 1466 *
1482 1467 * Start the restore work
1483 1468 *
1484 1469 * Parameters:
1485 1470 * session (input) - session pointer.
1486 1471 * bu_type (input) - backup type.
1487 1472 * env_val (input) - environment variable array.
1488 1473 * env_len (input) - length of env_val.
1489 1474 * nlist_val (input) - list of files.
1490 1475 * nlist_len (input) - length of nlist_val.
1491 1476 *
1492 1477 * Returns:
1493 1478 * NDMP_NO_ERR - recover successfully started.
|
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
1494 1479 * otherwise - error code of recover start error.
1495 1480 */
1496 1481 static ndmp_error
1497 1482 ndmpd_tar_start_recover_v3(ndmpd_session_t *session,
1498 1483 ndmp_pval *env_val, ulong_t env_len, ndmp_name_v3 *nlist_val,
1499 1484 ulong_t nlist_len)
1500 1485 {
1501 1486 ndmp_data_start_recover_reply_v3 reply;
1502 1487 ndmpd_module_params_t *params;
1503 1488 ndmp_lbr_params_t *nlp;
1489 + pthread_t tid;
1504 1490 int err;
1505 1491
1506 1492 (void) memset((void*)&reply, 0, sizeof (reply));
1507 1493
1508 1494 nlp = ndmp_get_nlp(session);
1509 1495 NDMP_FREE(nlp->nlp_params);
1510 1496 params = nlp->nlp_params = ndmp_malloc(sizeof (ndmpd_module_params_t));
1511 1497 if (!params) {
1512 1498 return (NDMP_NO_MEM_ERR);
1513 1499 }
1514 1500
1515 1501 reply.error = ndmpd_save_env(session, env_val, env_len);
1516 1502 if (reply.error != NDMP_NO_ERR) {
1517 1503 NDMP_FREE(nlp->nlp_params);
1518 1504 return (NDMP_NO_MEM_ERR);
1519 1505 }
1520 1506
1521 1507 reply.error = ndmpd_save_nlist_v3(session, nlist_val, nlist_len);
1522 1508 if (reply.error != NDMP_NO_ERR) {
1523 1509 NDMP_FREE(nlp->nlp_params);
1524 1510 return (NDMP_NO_MEM_ERR);
1525 1511 }
1526 1512
1527 1513 /*
1528 1514 * Setup restore parameters.
1529 1515 */
1530 1516 params->mp_daemon_cookie = (void *)session;
1531 1517 params->mp_module_cookie = &session->ns_data.dd_module.dm_module_cookie;
1532 1518 params->mp_protocol_version = session->ns_protocol_version;
1533 1519 params->mp_operation = NDMP_DATA_OP_RECOVER;
1534 1520 params->mp_get_env_func = ndmpd_api_get_env;
1535 1521 params->mp_add_env_func = ndmpd_api_add_env;
1536 1522 params->mp_set_env_func = ndmpd_api_set_env;
1537 1523 params->mp_get_name_func = ndmpd_api_get_name_v3;
1538 1524 params->mp_dispatch_func = ndmpd_api_dispatch;
1539 1525 params->mp_done_func = ndmpd_api_done_v3;
1540 1526 if (session->ns_protocol_version == NDMPV4) {
1541 1527 params->mp_log_func_v3 = ndmpd_api_log_v4;
1542 1528 params->mp_file_recovered_func = ndmpd_api_file_recovered_v4;
1543 1529 } else {
1544 1530 params->mp_log_func_v3 = ndmpd_api_log_v3;
1545 1531 params->mp_file_recovered_func = ndmpd_api_file_recovered_v3;
1546 1532 }
1547 1533
1548 1534 params->mp_add_file_handler_func = ndmpd_api_add_file_handler;
1549 1535 params->mp_remove_file_handler_func = ndmpd_api_remove_file_handler;
1550 1536 params->mp_write_func = 0;
1551 1537 params->mp_file_history_path_func = 0;
1552 1538 params->mp_file_history_dir_func = 0;
1553 1539 params->mp_file_history_node_func = 0;
1554 1540 params->mp_read_func = ndmpd_api_read_v3;
1555 1541 params->mp_seek_func = ndmpd_api_seek_v3;
1556 1542 params->mp_stats = &session->ns_data.dd_module.dm_stats;
1557 1543
1558 1544 session->ns_data.dd_module.dm_module_cookie = 0;
1559 1545 session->ns_data.dd_module.dm_start_func = ndmpd_tar_restore_starter_v3;
1560 1546 session->ns_data.dd_module.dm_abort_func = ndmpd_tar_restore_abort_v3;
1561 1547 session->ns_data.dd_module.dm_stats.ms_est_bytes_remaining = 0;
1562 1548 session->ns_data.dd_module.dm_stats.ms_est_time_remaining = 0;
1563 1549 session->ns_data.dd_bytes_left_to_read = 0;
1564 1550 session->ns_data.dd_position = 0;
1565 1551 session->ns_data.dd_discard_length = 0;
1566 1552 session->ns_data.dd_read_offset = 0;
1567 1553 session->ns_data.dd_read_length = 0;
1568 1554
1569 1555 err = ndmp_restore_get_params_v3(session, params);
|
↓ open down ↓ |
56 lines elided |
↑ open up ↑ |
1570 1556 if (err != NDMP_NO_ERR) {
1571 1557 NDMP_FREE(nlp->nlp_params);
1572 1558 return (err);
1573 1559 }
1574 1560
1575 1561 reply.error = NDMP_NO_ERR;
1576 1562 if (ndmp_send_response(session->ns_connection, NDMP_NO_ERR,
1577 1563 &reply) < 0) {
1578 1564 NDMP_FREE(nlp->nlp_params);
1579 1565 ndmpd_free_nlist_v3(session);
1580 - NDMP_LOG(LOG_DEBUG,
1566 + syslog(LOG_ERR,
1581 1567 "Error sending ndmp_data_start_recover_reply");
1582 1568 ndmpd_data_error(session, NDMP_DATA_HALT_CONNECT_ERROR);
1583 1569 return (NDMP_NO_ERR);
1584 1570 }
1585 1571
1586 1572 NS_INC(nrs);
1587 1573 session->ns_data.dd_state = NDMP_DATA_STATE_ACTIVE;
1588 1574 session->ns_data.dd_operation = NDMP_DATA_OP_RECOVER;
1589 1575 session->ns_data.dd_abort = FALSE;
1590 1576
1591 1577 /*
1592 1578 * perform the restore
1593 1579 *
1594 1580 * Cannot wait for the thread to exit as we are replying to the
1595 1581 * client request here.
1596 1582 */
1597 - err = pthread_create(NULL, NULL,
1583 + err = pthread_create(&tid, NULL,
1598 1584 (funct_t)session->ns_data.dd_module.dm_start_func,
1599 1585 params);
1600 1586
1601 1587 if (err != 0) {
1602 - NDMP_LOG(LOG_ERR, "Can't start recover session.");
1588 + syslog(LOG_ERR, "Can't start V3 recover session.");
1603 1589 return (NDMP_ILLEGAL_ARGS_ERR);
1604 1590 }
1605 - return (NDMP_NO_ERR);
1606 -}
1607 1591
1608 -static ndmp_error
1609 -ndmpd_zfs_start_op(ndmpd_session_t *session, ndmp_pval *env_val,
1610 - ulong_t env_len, ndmp_name_v3 *nlist_val, ulong_t nlist_len,
1611 - enum ndmp_data_operation op)
1612 -{
1613 - ndmpd_zfs_args_t *ndmpd_zfs_args = &session->ns_ndmpd_zfs_args;
1614 - ndmp_data_start_backup_reply_v3 backup_reply;
1615 - ndmp_data_start_recover_reply_v3 recover_reply;
1616 - pthread_t tid;
1617 - void *reply;
1618 - char str[8];
1619 - int err;
1620 -
1621 - if (ndmpd_zfs_init(session) != 0)
1622 - return (NDMP_UNDEFINED_ERR);
1623 -
1624 - err = ndmpd_save_env(session, env_val, env_len);
1625 - if (err != NDMP_NO_ERR) {
1626 - ndmpd_zfs_fini(ndmpd_zfs_args);
1627 - return (err);
1628 - }
1629 -
1630 - switch (op) {
1631 - case NDMP_DATA_OP_BACKUP:
1632 - if (!ndmpd_zfs_backup_parms_valid(ndmpd_zfs_args)) {
1633 - ndmpd_zfs_fini(ndmpd_zfs_args);
1634 - return (NDMP_ILLEGAL_ARGS_ERR);
1635 - }
1636 -
1637 - if (ndmpd_zfs_pre_backup(ndmpd_zfs_args)) {
1638 - NDMP_LOG(LOG_ERR, "pre_backup error");
1639 - return (NDMP_ILLEGAL_ARGS_ERR);
1640 - }
1641 -
1642 - session->ns_data.dd_module.dm_start_func =
1643 - ndmpd_zfs_backup_starter;
1644 - (void) strlcpy(str, "backup", 8);
1645 - break;
1646 - case NDMP_DATA_OP_RECOVER:
1647 - err = ndmpd_save_nlist_v3(session, nlist_val, nlist_len);
1648 - if (err != NDMP_NO_ERR) {
1649 - ndmpd_zfs_fini(ndmpd_zfs_args);
1650 - return (NDMP_NO_MEM_ERR);
1651 - }
1652 -
1653 - if (!ndmpd_zfs_restore_parms_valid(ndmpd_zfs_args)) {
1654 - ndmpd_zfs_fini(ndmpd_zfs_args);
1655 - return (NDMP_ILLEGAL_ARGS_ERR);
1656 - }
1657 -
1658 - if (ndmpd_zfs_pre_restore(ndmpd_zfs_args)) {
1659 - NDMP_LOG(LOG_ERR, "pre_restore error");
1660 - (void) ndmpd_zfs_post_restore(ndmpd_zfs_args);
1661 - return (NDMP_ILLEGAL_ARGS_ERR);
1662 - }
1663 - session->ns_data.dd_module.dm_start_func =
1664 - ndmpd_zfs_restore_starter;
1665 - (void) strlcpy(str, "recover", 8);
1666 - break;
1667 - }
1668 -
1669 - ndmpd_zfs_params->mp_operation = op;
1670 - session->ns_data.dd_operation = op;
1671 - session->ns_data.dd_module.dm_abort_func = ndmpd_zfs_abort;
1672 - session->ns_data.dd_state = NDMP_DATA_STATE_ACTIVE;
1673 - session->ns_data.dd_abort = FALSE;
1674 -
1675 - if (op == NDMP_DATA_OP_BACKUP) {
1676 - (void) memset((void*)&backup_reply, 0, sizeof (backup_reply));
1677 - backup_reply.error = NDMP_NO_ERR;
1678 - reply = &backup_reply;
1679 - } else {
1680 - (void) memset((void*)&recover_reply, 0, sizeof (recover_reply));
1681 - recover_reply.error = NDMP_NO_ERR;
1682 - reply = &recover_reply;
1683 - }
1684 -
1685 - if (ndmp_send_response(session->ns_connection, NDMP_NO_ERR,
1686 - reply) < 0) {
1687 - NDMP_LOG(LOG_DEBUG, "Sending data_start_%s_v3 reply", str);
1688 - if (op == NDMP_DATA_OP_RECOVER)
1689 - ndmpd_data_error(session, NDMP_DATA_HALT_CONNECT_ERROR);
1690 - ndmpd_zfs_fini(ndmpd_zfs_args);
1691 - return (NDMP_NO_ERR);
1692 - }
1693 -
1694 - err = pthread_create(&tid, NULL,
1695 - (funct_t)session->ns_data.dd_module.dm_start_func, ndmpd_zfs_args);
1696 -
1697 - if (err) {
1698 - NDMP_LOG(LOG_ERR, "Can't start %s session (errno %d)",
1699 - str, err);
1700 - ndmpd_zfs_fini(ndmpd_zfs_args);
1701 - MOD_DONE(ndmpd_zfs_params, -1);
1702 - return (NDMP_NO_ERR);
1703 - }
1704 -
1705 1592 (void) pthread_detach(tid);
1706 1593
1707 - if (op == NDMP_DATA_OP_BACKUP)
1708 - NS_INC(nbk);
1709 - else
1710 - NS_INC(nrs);
1711 -
1712 - ndmpd_zfs_dma_log(ndmpd_zfs_args, NDMP_LOG_NORMAL,
1713 - "'zfs' %s starting\n", str);
1714 -
1715 1594 return (NDMP_NO_ERR);
1716 1595 }
1717 1596
1718 1597 /*
1719 1598 * discard_data_v3
1720 1599 *
1721 1600 * Read and discard data from the data connection.
1722 1601 * Called when a module has called ndmpd_seek() prior to
1723 1602 * reading all of the data from the previous seek.
1724 1603 *
1725 1604 * Parameters:
1726 1605 * session (input) - session pointer.
1727 1606 *
1728 1607 * Returns:
1729 1608 * number of bytes read and discarded.
1730 1609 * -1 - error.
1731 1610 */
1732 1611 static int
1733 1612 discard_data_v3(ndmpd_session_t *session, ulong_t length)
|
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
1734 1613 {
1735 1614 static char buf[MAX_RECORD_SIZE];
1736 1615 int n, toread;
1737 1616
1738 1617 toread = (length < MAX_RECORD_SIZE) ? length :
1739 1618 MAX_RECORD_SIZE;
1740 1619
1741 1620 /* Read and discard the data. */
1742 1621 n = read(session->ns_data.dd_sock, buf, toread);
1743 1622 if (n < 0) {
1744 - NDMP_LOG(LOG_ERR, "Socket read error: %m.");
1623 + syslog(LOG_ERR, "Socket read error: %m.");
1745 1624 n = -1;
1746 1625 }
1747 1626
1748 1627 return (n);
1749 1628 }
1750 1629
1751 1630
1752 1631 /*
1753 1632 * ndmpd_remote_read_v3
1754 1633 *
1755 1634 * Reads data from the remote mover.
1756 1635 *
1757 1636 * Parameters:
1758 1637 * session (input) - session pointer.
1759 1638 * data (input) - data to be written.
1760 1639 * length (input) - data length.
1761 1640 *
1762 1641 * Returns:
1763 1642 * 0 - data successfully read.
1764 1643 * -1 - error.
1765 1644 */
|
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
1766 1645 int
1767 1646 ndmpd_remote_read_v3(ndmpd_session_t *session, char *data, ulong_t length)
1768 1647 {
1769 1648 ulong_t count;
1770 1649 ulong_t len;
1771 1650 ssize_t n;
1772 1651 ndmp_notify_data_read_request request;
1773 1652 tlm_job_stats_t *jstat;
1774 1653 longlong_t fsize;
1775 1654
1776 - NDMP_LOG(LOG_DEBUG, "ns_data.dd_xx: [%llu, %llu, %llu, %llu, %llu]",
1777 - session->ns_data.dd_bytes_left_to_read,
1778 - session->ns_data.dd_read_offset,
1779 - session->ns_data.dd_read_length,
1780 - session->ns_data.dd_position,
1781 - session->ns_data.dd_discard_length);
1782 -
1783 1655 count = 0;
1784 1656 while (count < length) {
1785 1657 len = length - count;
1786 1658
1787 1659 /*
1788 1660 * If the end of the seek window has been reached then
1789 1661 * send an ndmp_read request to the client.
1790 1662 * The NDMP client will then send a mover_data_read request to
1791 1663 * the remote mover and the mover will send more data.
1792 1664 * This condition can occur if the module attempts to read past
1793 1665 * a seek window set via a prior call to ndmpd_seek() or
1794 1666 * the module has not issued a seek. If no seek was issued then
1795 1667 * pretend that a seek was issued to read the entire tape.
1796 1668 */
1797 1669 if (session->ns_data.dd_bytes_left_to_read == 0) {
1798 1670 /* ndmpd_seek() never called? */
1799 1671 if (session->ns_data.dd_read_length == 0) {
1800 1672 session->ns_data.dd_bytes_left_to_read = ~0LL;
1801 1673 session->ns_data.dd_read_offset = 0LL;
1802 1674 session->ns_data.dd_read_length = ~0LL;
|
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
1803 1675 } else {
1804 1676 /*
1805 1677 * While restoring a file, restoreFile()
1806 1678 * records the number of bytes still need to
1807 1679 * be restored. We use this as a guidance
1808 1680 * when asking for data from the tape.
1809 1681 */
1810 1682 jstat = session->ns_ndmp_lbr_params->nlp_jstat;
1811 1683 fsize = jstat->js_bytes_in_file;
1812 1684
1813 - NDMP_LOG(LOG_DEBUG, "bytes_left [%llu / %u]",
1814 - fsize, len);
1815 -
1816 1685 /*
1817 1686 * Fall back to the old way if fsize if too
1818 1687 * small.
1819 1688 */
1820 1689 if (fsize < len)
1821 1690 fsize = len;
1822 1691
1823 1692 session->ns_data.dd_bytes_left_to_read = fsize;
1824 1693 session->ns_data.dd_read_offset =
1825 1694 session->ns_data.dd_position;
1826 1695 session->ns_data.dd_read_length = fsize;
1827 1696 }
1828 1697
1829 1698 request.offset =
1830 1699 long_long_to_quad(session->ns_data.dd_read_offset);
1831 1700 request.length =
1832 1701 long_long_to_quad(session->ns_data.dd_read_length);
1833 1702
1834 - NDMP_LOG(LOG_DEBUG, "to NOTIFY_DATA_READ [%llu, %llu]",
1703 + syslog(LOG_DEBUG, "to NOTIFY_DATA_READ [%lu, %lu]",
1835 1704 session->ns_data.dd_read_offset,
1836 1705 session->ns_data.dd_read_length);
1837 1706
1838 1707 if (ndmp_send_request_lock(session->ns_connection,
1839 1708 NDMP_NOTIFY_DATA_READ, NDMP_NO_ERR,
1840 1709 &request, 0) < 0) {
1841 - NDMP_LOG(LOG_DEBUG,
1710 + syslog(LOG_ERR,
1842 1711 "Sending notify_data_read request");
1843 1712 return (-1);
1844 1713 }
1845 1714 }
1846 1715
1847 1716 /*
1848 1717 * If the module called ndmpd_seek() prior to reading all of the
1849 1718 * data that the remote mover was requested to send, then the
1850 1719 * excess data from the seek has to be discarded.
1851 1720 */
1852 1721 if (session->ns_data.dd_discard_length != 0) {
1853 1722 n = discard_data_v3(session,
1854 1723 (ulong_t)session->ns_data.dd_discard_length);
1855 1724 if (n < 0)
1856 1725 return (-1);
1857 1726
1858 1727 session->ns_data.dd_discard_length -= n;
1859 1728 continue;
|
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
1860 1729 }
1861 1730
1862 1731 /*
1863 1732 * Don't attempt to read more data than the remote is sending.
1864 1733 */
1865 1734 if (len > session->ns_data.dd_bytes_left_to_read)
1866 1735 len = session->ns_data.dd_bytes_left_to_read;
1867 1736
1868 1737 if ((n = read(session->ns_data.dd_sock, &data[count],
1869 1738 len)) < 0) {
1870 - NDMP_LOG(LOG_ERR, "Socket read error: %m.");
1739 + syslog(LOG_ERR, "Socket read error: %m.");
1871 1740 return (-1);
1872 1741 }
1873 1742
1874 1743 /* read returns 0 if the connection was closed */
1875 1744 if (n == 0) {
1876 - NDMP_LOG(LOG_DEBUG, "n 0 errno %d",
1745 + syslog(LOG_ERR, "n 0 errno %d",
1877 1746 errno);
1878 1747 return (-1);
1879 1748 }
1880 1749
1881 1750 count += n;
1882 1751 session->ns_data.dd_bytes_left_to_read -= n;
1883 1752 session->ns_data.dd_position += n;
1884 1753 }
1885 1754 return (0);
1886 1755 }
1887 1756
1888 1757 /*
1889 1758 * nlp_release_job_stat
1890 1759 *
1891 1760 * Unreference the job statistics
1892 1761 *
1893 1762 * Parameters:
1894 1763 * session (input) - session pointer.
|
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
1895 1764 *
1896 1765 * Returns:
1897 1766 * void
1898 1767 */
1899 1768 static void
1900 1769 nlp_release_job_stat(ndmpd_session_t *session)
1901 1770 {
1902 1771 ndmp_lbr_params_t *nlp;
1903 1772
1904 1773 if ((nlp = ndmp_get_nlp(session)) == NULL) {
1905 - NDMP_LOG(LOG_DEBUG, "nlp == NULL");
1906 1774 return;
1907 1775 }
1908 1776 if (nlp->nlp_jstat != NULL) {
1909 1777 nlp->nlp_bytes_total =
1910 1778 (u_longlong_t)nlp->nlp_jstat->js_bytes_total;
1911 1779 tlm_un_ref_job_stats(nlp->nlp_jstat->js_job_name);
1912 1780 nlp->nlp_jstat = NULL;
1913 - } else
1914 - NDMP_LOG(LOG_DEBUG, "JSTAT == NULL");
1781 + }
1915 1782 }
1916 1783
1917 1784
1918 1785 /* *** ndmpd global internal functions *********************************** */
1919 1786
1920 1787 /*
1921 1788 * ndmpd_data_init
1922 1789 *
1923 1790 * Initializes data specific session variables.
1924 1791 *
1925 1792 * Parameters:
1926 1793 * session (input) - session pointer.
1927 1794 *
1928 1795 * Returns:
1929 1796 * void
1930 1797 */
1931 1798 int
1932 1799 ndmpd_data_init(ndmpd_session_t *session)
1933 1800 {
1934 1801 session->ns_data.dd_operation = NDMP_DATA_OP_NOACTION;
1935 1802 session->ns_data.dd_state = NDMP_DATA_STATE_IDLE;
1936 1803 session->ns_data.dd_halt_reason = NDMP_DATA_HALT_NA;
1937 1804 session->ns_data.dd_abort = FALSE;
1938 1805 session->ns_data.dd_env = 0;
1939 1806 session->ns_data.dd_env_len = 0;
1940 1807 session->ns_data.dd_nlist = 0;
1941 1808 session->ns_data.dd_nlist_len = 0;
1942 1809 session->ns_data.dd_mover.addr_type = NDMP_ADDR_LOCAL;
1943 1810 session->ns_data.dd_sock = -1;
1944 1811 session->ns_data.dd_read_offset = 0;
1945 1812 session->ns_data.dd_read_length = 0;
1946 1813 session->ns_data.dd_module.dm_stats.ms_est_bytes_remaining = 0;
1947 1814 session->ns_data.dd_module.dm_stats.ms_est_time_remaining = 0;
1948 1815 /*
1949 1816 * NDMP V3
1950 1817 */
1951 1818 session->ns_data.dd_state = NDMP_DATA_STATE_IDLE;
1952 1819 session->ns_data.dd_nlist_v3 = 0;
1953 1820 session->ns_data.dd_data_addr.addr_type = NDMP_ADDR_LOCAL;
1954 1821 session->ns_data.dd_listen_sock = -1;
1955 1822 session->ns_data.dd_bytes_left_to_read = 0LL;
1956 1823 session->ns_data.dd_position = 0LL;
1957 1824 session->ns_data.dd_discard_length = 0LL;
1958 1825 return (0);
1959 1826 }
1960 1827
1961 1828
1962 1829
1963 1830 /*
1964 1831 * ndmpd_data_cleanup
1965 1832 *
1966 1833 * Releases resources allocated during a data operation.
1967 1834 *
|
↓ open down ↓ |
43 lines elided |
↑ open up ↑ |
1968 1835 * Parameters:
1969 1836 * session (input) - session pointer.
1970 1837 *
1971 1838 * Returns:
1972 1839 * void
1973 1840 */
1974 1841 void
1975 1842 ndmpd_data_cleanup(ndmpd_session_t *session)
1976 1843 {
1977 1844 if (session->ns_data.dd_listen_sock != -1) {
1978 - NDMP_LOG(LOG_DEBUG, "data.listen_sock: %d",
1845 + syslog(LOG_DEBUG, "data.listen_sock: %d",
1979 1846 session->ns_data.dd_listen_sock);
1980 1847 (void) ndmpd_remove_file_handler(session,
1981 1848 session->ns_data.dd_listen_sock);
1982 1849 (void) close(session->ns_data.dd_listen_sock);
1983 1850 session->ns_data.dd_listen_sock = -1;
1984 1851 }
1985 1852 if (session->ns_data.dd_sock != -1) {
1986 - NDMP_LOG(LOG_DEBUG, "data.sock: %d",
1853 + syslog(LOG_ERR, "data.sock: %d",
1987 1854 session->ns_data.dd_sock);
1988 1855
1989 1856 /*
1990 1857 * ndmpcopy: we use the same socket for the mover,
1991 1858 * so expect to close when mover is done!
1992 1859 */
1993 1860 if (session->ns_data.dd_sock != session->ns_mover.md_sock)
1994 1861 (void) close(session->ns_data.dd_sock);
1995 1862
1996 1863 session->ns_data.dd_sock = -1;
1997 1864 }
1998 1865
1999 1866 ndmpd_free_env(session);
2000 1867 ndmpd_free_nlist(session);
2001 1868 }
2002 1869
2003 1870
2004 1871 /*
2005 1872 * ndmp_data_get_mover_mode
2006 1873 *
2007 1874 * Return the mover mode
2008 1875 *
2009 1876 * Parameters:
2010 1877 * session (input) - session pointer.
2011 1878 *
2012 1879 * Returns:
2013 1880 * remote - remote backup
2014 1881 * local - local backup
2015 1882 */
2016 1883 char *
2017 1884 ndmp_data_get_mover_mode(ndmpd_session_t *session)
2018 1885 {
2019 1886 char *rv;
2020 1887
2021 1888 switch (session->ns_protocol_version) {
2022 1889 case NDMPV2:
2023 1890 rv = ((session->ns_data.dd_mover.addr_type == NDMP_ADDR_TCP)
2024 1891 ? "remote" : "local");
2025 1892 break;
2026 1893 case NDMPV3:
2027 1894 rv = ((session->ns_data.dd_data_addr.addr_type == NDMP_ADDR_TCP)
|
↓ open down ↓ |
31 lines elided |
↑ open up ↑ |
2028 1895 ? "remote" : "local");
2029 1896 break;
2030 1897 case NDMPV4:
2031 1898 rv = ((session->ns_data.dd_data_addr.addr_type ==
2032 1899 NDMP_ADDR_TCP ||
2033 1900 (session->ns_data.dd_data_addr_v4.addr_type ==
2034 1901 NDMP_ADDR_TCP)) ? "remote" : "local");
2035 1902 break;
2036 1903 default:
2037 1904 rv = "Unknown";
2038 - NDMP_LOG(LOG_ERR, "Invalid protocol version %d.",
1905 + syslog(LOG_ERR, "Invalid protocol version %d.",
2039 1906 session->ns_protocol_version);
2040 1907 }
2041 1908
2042 1909 return (rv);
2043 1910 }
2044 1911
2045 1912 /* *** static functions ******************************************** */
2046 1913
2047 1914 /*
2048 1915 * ndmpd_tar_start_backup_v2
2049 1916 *
2050 1917 * Request handling code common to version 1 and
2051 1918 * version 2 data_start_backup request handlers.
2052 1919 *
2053 1920 * Parameters:
2054 1921 * session (input) - session pointer.
2055 1922 * bu_type (input) - backup type.
2056 1923 * env_val (input) - environment variable array.
2057 1924 * env_len (input) - length of env_val.
2058 1925 *
2059 1926 * Returns:
|
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
2060 1927 * NDMP_NO_ERR - backup successfully started.
2061 1928 * otherwise - error code of backup start error.
2062 1929 */
2063 1930 static ndmp_error
2064 1931 ndmpd_tar_start_backup_v2(ndmpd_session_t *session, char *bu_type,
2065 1932 ndmp_pval *env_val, ulong_t env_len)
2066 1933 {
2067 1934 ndmp_data_start_backup_reply reply;
2068 1935 ndmpd_module_params_t *params;
2069 1936 ndmp_lbr_params_t *nlp;
1937 + pthread_t tid;
2070 1938 int err;
2071 1939
2072 1940 if (session->ns_data.dd_state != NDMP_DATA_STATE_IDLE) {
2073 - NDMP_LOG(LOG_ERR, "Can't start new backup in current state.");
1941 + syslog(LOG_ERR, "Can't start new backup in current state.");
2074 1942 return (NDMP_ILLEGAL_STATE_ERR);
2075 1943 }
2076 1944 if (strcmp(bu_type, NDMP_DUMP_TYPE) != 0 &&
2077 1945 strcmp(bu_type, NDMP_TAR_TYPE) != 0) {
2078 - NDMP_LOG(LOG_ERR, "Invalid backup type: %s.", bu_type);
2079 - NDMP_LOG(LOG_ERR, "Supported backup types are tar and dump.");
1946 + syslog(LOG_ERR, "Invalid backup type: %s.", bu_type);
1947 + syslog(LOG_ERR, "Supported backup types are tar and dump.");
2080 1948 return (NDMP_ILLEGAL_ARGS_ERR);
2081 1949 }
2082 1950 if ((err = ndmpd_save_env(session, env_val, env_len)) != NDMP_NO_ERR)
2083 1951 return (err);
2084 1952
2085 1953 nlp = ndmp_get_nlp(session);
2086 1954 NDMP_FREE(nlp->nlp_params);
2087 1955 params = nlp->nlp_params = ndmp_malloc(sizeof (ndmpd_module_params_t));
2088 1956 if (params == NULL)
2089 1957 return (NDMP_NO_MEM_ERR);
2090 1958
2091 1959 params->mp_daemon_cookie = (void *)session;
2092 1960 params->mp_module_cookie = &session->ns_data.dd_module.dm_module_cookie;
2093 1961 params->mp_protocol_version = session->ns_protocol_version;
2094 1962 params->mp_operation = NDMP_DATA_OP_BACKUP;
2095 1963 params->mp_get_env_func = ndmpd_api_get_env;
2096 1964 params->mp_add_env_func = ndmpd_api_add_env;
2097 1965 params->mp_get_name_func = ndmpd_api_get_name;
2098 1966 params->mp_dispatch_func = ndmpd_api_dispatch;
2099 1967 params->mp_done_func = ndmpd_api_done_v2;
2100 1968 params->mp_log_func = ndmpd_api_log_v2;
2101 1969 params->mp_add_file_handler_func = ndmpd_api_add_file_handler;
2102 1970 params->mp_remove_file_handler_func = ndmpd_api_remove_file_handler;
2103 1971 params->mp_write_func = ndmpd_api_write_v2;
2104 1972 params->mp_read_func = 0;
2105 1973 params->mp_file_recovered_func = 0;
2106 1974 params->mp_stats = &session->ns_data.dd_module.dm_stats;
2107 1975
2108 1976 session->ns_data.dd_module.dm_module_cookie = 0;
2109 1977 if (strcmp(bu_type, NDMP_DUMP_TYPE) == 0) {
2110 1978 NLP_SET(nlp, NLPF_DUMP);
2111 1979 params->mp_file_history_path_func = 0;
2112 1980 params->mp_file_history_dir_func =
2113 1981 ndmpd_api_file_history_dir_v2;
2114 1982 params->mp_file_history_node_func =
2115 1983 ndmpd_api_file_history_node_v2;
2116 1984 } else if (strcmp(bu_type, NDMP_TAR_TYPE) == 0) {
2117 1985 /* backup type == NDMP_TAR_TYPE */
2118 1986 NLP_SET(nlp, NLPF_TAR);
2119 1987 params->mp_file_history_path_func =
2120 1988 ndmpd_api_file_history_path_v2;
2121 1989 params->mp_file_history_dir_func = 0;
2122 1990 params->mp_file_history_node_func = 0;
2123 1991 } else {
2124 1992 NLP_UNSET(nlp, NLPF_DUMP);
2125 1993 NLP_UNSET(nlp, NLPF_TAR);
2126 1994 }
2127 1995
2128 1996 session->ns_data.dd_module.dm_start_func = ndmpd_tar_backup_starter;
2129 1997 session->ns_data.dd_module.dm_abort_func = ndmpd_tar_backup_abort;
|
↓ open down ↓ |
40 lines elided |
↑ open up ↑ |
2130 1998
2131 1999 session->ns_data.dd_module.dm_stats.ms_est_bytes_remaining = 0;
2132 2000 session->ns_data.dd_module.dm_stats.ms_est_time_remaining = 0;
2133 2001 session->ns_data.dd_nlist = 0;
2134 2002 session->ns_data.dd_nlist_len = 0;
2135 2003 session->ns_data.dd_read_offset = 0;
2136 2004 session->ns_data.dd_read_length = 0;
2137 2005
2138 2006 if ((err = ndmp_backup_extract_params(session,
2139 2007 params)) != NDMP_NO_ERR) {
2140 - NDMP_LOG(LOG_DEBUG, "err: %d", err);
2008 + syslog(LOG_ERR, "err: %d", err);
2141 2009 NDMP_FREE(nlp->nlp_params);
2142 2010 return (err);
2143 2011 }
2144 2012
2145 2013 err = ndmpd_mover_connect(session, NDMP_MOVER_MODE_READ);
2146 2014 if (err != NDMP_NO_ERR) {
2147 - NDMP_LOG(LOG_DEBUG,
2015 + syslog(LOG_ERR,
2148 2016 "mover connect err: %d", err);
2149 2017 NDMP_FREE(nlp->nlp_params);
2150 2018 return (err);
2151 2019 }
2152 2020
2153 2021 session->ns_data.dd_state = NDMP_DATA_STATE_ACTIVE;
2154 2022
2155 2023 session->ns_data.dd_operation = NDMP_DATA_OP_BACKUP;
2156 2024 session->ns_data.dd_abort = FALSE;
2157 2025
2158 - NDMP_LOG(LOG_DEBUG, "starting backup");
2026 + syslog(LOG_DEBUG, "starting backup");
2159 2027
2160 2028 reply.error = NDMP_NO_ERR;
2161 2029 if (ndmp_send_response(session->ns_connection, NDMP_NO_ERR,
2162 2030 &reply) < 0) {
2163 - NDMP_LOG(LOG_DEBUG, "Sending data_start_backup reply");
2031 + syslog(LOG_DEBUG, "Sending data_start_backup reply");
2164 2032 NDMP_FREE(nlp->nlp_params);
2165 2033 if (session->ns_data.dd_mover.addr_type == NDMP_ADDR_TCP) {
2166 2034 /*
2167 2035 * ndmpcopy: we use the same socket for the mover,
2168 2036 * so expect to close when mover is done!
2169 2037 */
2170 2038 if (session->ns_data.dd_sock !=
2171 2039 session->ns_mover.md_sock)
2172 2040 (void) close(session->ns_data.dd_sock);
2173 2041
2174 2042 session->ns_data.dd_sock = -1;
2175 2043 } else
2176 2044 ndmpd_mover_error(session,
|
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
2177 2045 NDMP_MOVER_HALT_CONNECT_CLOSED);
2178 2046 return (NDMP_NO_ERR);
2179 2047 }
2180 2048
2181 2049 /*
2182 2050 * perform the backup
2183 2051 *
2184 2052 * Cannot wait for the thread to exit as we are replying to the
2185 2053 * client request here.
2186 2054 */
2187 - (void) pthread_create(NULL, NULL,
2055 + (void) pthread_create(&tid, NULL,
2188 2056 (funct_t)session->ns_data.dd_module.dm_start_func,
2189 2057 params);
2190 2058
2059 + if (err) {
2060 + syslog(LOG_ERR, "Can't start V2 backup session.");
2061 + return (NDMP_ILLEGAL_ARGS_ERR);
2062 + }
2063 +
2064 + (void) pthread_detach(tid);
2065 +
2191 2066 return (NDMP_NO_ERR);
2192 2067 }
2193 2068
2194 2069 /*
2195 2070 * ndmpd_tar_start_recover_v2
2196 2071 *
2197 2072 * The main recover/restore function
2198 2073 *
2199 2074 * Parameters:
2200 2075 * session (input) - session pointer.
2201 2076 * bu_type (input) - backup type.
2202 2077 * env_val (input) - environment variable array.
2203 2078 * env_len (input) - length of env_val.
2204 2079 * nlist_val (input) - list of files.
2205 2080 * nlist_len (input) - length of nlist_val.
2206 2081 *
2207 2082 * Returns:
2208 2083 * NDMP_NO_ERR - recover successfully started.
|
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
2209 2084 * otherwise - error code of backup start error.
2210 2085 */
2211 2086 static ndmp_error
2212 2087 ndmpd_tar_start_recover_v2(ndmpd_session_t *session, char *bu_type,
2213 2088 ndmp_pval *env_val, ulong_t env_len, ndmp_name *nlist_val,
2214 2089 ulong_t nlist_len)
2215 2090 {
2216 2091 ndmp_data_start_recover_reply_v2 reply;
2217 2092 ndmpd_module_params_t *params;
2218 2093 ndmp_lbr_params_t *nlp;
2094 + pthread_t tid;
2219 2095 int err;
2220 2096
2221 2097 if (session->ns_data.dd_state != NDMP_DATA_STATE_IDLE) {
2222 - NDMP_LOG(LOG_ERR, "Can't start new recover in current state.");
2098 + syslog(LOG_ERR, "Can't start new recover in current state.");
2223 2099 return (NDMP_ILLEGAL_STATE_ERR);
2224 2100 }
2225 2101
2226 2102 if (strcmp(bu_type, NDMP_DUMP_TYPE) != 0 &&
2227 2103 strcmp(bu_type, NDMP_TAR_TYPE) != 0) {
2228 - NDMP_LOG(LOG_ERR, "Invalid backup type: %s.", bu_type);
2229 - NDMP_LOG(LOG_ERR, "Supported backup types are tar and dump.");
2104 + syslog(LOG_ERR, "Invalid backup type: %s.", bu_type);
2105 + syslog(LOG_ERR, "Supported backup types are tar and dump.");
2230 2106 return (NDMP_ILLEGAL_ARGS_ERR);
2231 2107 }
2232 2108
2233 2109 reply.error = ndmpd_save_env(session, env_val, env_len);
2234 2110 if (reply.error != NDMP_NO_ERR)
2235 2111 return (NDMP_NO_MEM_ERR);
2236 2112
2237 2113 reply.error = ndmpd_save_nlist_v2(session, nlist_val, nlist_len);
2238 2114 if (reply.error != NDMP_NO_ERR)
2239 2115 return (NDMP_NO_MEM_ERR);
2240 2116
2241 2117 nlp = ndmp_get_nlp(session);
2242 2118 NDMP_FREE(nlp->nlp_params);
2243 2119 params = nlp->nlp_params = ndmp_malloc(sizeof (ndmpd_module_params_t));
2244 2120 if (params == NULL)
2245 2121 return (NDMP_NO_MEM_ERR);
2246 2122
2247 2123 /*
2248 2124 * Setup restore parameters.
2249 2125 */
2250 2126 params->mp_daemon_cookie = (void *)session;
2251 2127 params->mp_module_cookie = &session->ns_data.dd_module.dm_module_cookie;
2252 2128 params->mp_protocol_version = session->ns_protocol_version;
2253 2129 params->mp_operation = NDMP_DATA_OP_RECOVER;
2254 2130 params->mp_get_env_func = ndmpd_api_get_env;
2255 2131 params->mp_add_env_func = ndmpd_api_add_env;
2256 2132 params->mp_get_name_func = ndmpd_api_get_name;
2257 2133 params->mp_dispatch_func = ndmpd_api_dispatch;
2258 2134 params->mp_done_func = ndmpd_api_done_v2;
2259 2135 params->mp_log_func = ndmpd_api_log_v2;
2260 2136 params->mp_add_file_handler_func = ndmpd_api_add_file_handler;
2261 2137 params->mp_remove_file_handler_func = ndmpd_api_remove_file_handler;
2262 2138 params->mp_write_func = 0;
2263 2139 params->mp_file_history_path_func = 0;
2264 2140 params->mp_file_history_dir_func = 0;
2265 2141 params->mp_file_history_node_func = 0;
2266 2142 params->mp_read_func = ndmpd_api_read_v2;
2267 2143 params->mp_seek_func = ndmpd_api_seek_v2;
2268 2144 params->mp_file_recovered_func = ndmpd_api_file_recovered_v2;
2269 2145 params->mp_stats = &session->ns_data.dd_module.dm_stats;
2270 2146
2271 2147 session->ns_data.dd_module.dm_module_cookie = 0;
2272 2148 session->ns_data.dd_module.dm_start_func = ndmpd_tar_restore_starter;
2273 2149 session->ns_data.dd_module.dm_abort_func = ndmpd_tar_restore_abort;
2274 2150 session->ns_data.dd_module.dm_stats.ms_est_bytes_remaining = 0;
2275 2151 session->ns_data.dd_module.dm_stats.ms_est_time_remaining = 0;
2276 2152 session->ns_data.dd_read_offset = 0;
2277 2153 session->ns_data.dd_read_length = 0;
2278 2154
2279 2155 if ((err = ndmp_restore_extract_params(session,
2280 2156 params)) != NDMP_NO_ERR) {
2281 2157 NDMP_FREE(nlp->nlp_params);
2282 2158 return (err);
2283 2159 }
2284 2160
2285 2161 err = ndmpd_mover_connect(session, NDMP_MOVER_MODE_WRITE);
2286 2162 if (err != NDMP_NO_ERR) {
2287 2163 NDMP_FREE(nlp->nlp_params);
|
↓ open down ↓ |
48 lines elided |
↑ open up ↑ |
2288 2164 return (err);
2289 2165 }
2290 2166
2291 2167 session->ns_data.dd_state = NDMP_DATA_STATE_ACTIVE;
2292 2168 session->ns_data.dd_operation = NDMP_DATA_OP_RECOVER;
2293 2169 session->ns_data.dd_abort = FALSE;
2294 2170
2295 2171 reply.error = NDMP_NO_ERR;
2296 2172 if (ndmp_send_response(session->ns_connection, NDMP_NO_ERR,
2297 2173 &reply) < 0) {
2298 - NDMP_LOG(LOG_DEBUG, "Sending data_start_recover reply");
2174 + syslog(LOG_DEBUG, "Sending data_start_recover reply");
2299 2175 NDMP_FREE(nlp->nlp_params);
2300 2176 if (session->ns_data.dd_mover.addr_type == NDMP_ADDR_TCP) {
2301 2177 /*
2302 2178 * ndmpcopy: we use the same socket for the mover,
2303 2179 * so expect to close when mover is done!
2304 2180 */
2305 2181 if (session->ns_data.dd_sock !=
2306 2182 session->ns_mover.md_sock)
2307 2183 (void) close(session->ns_data.dd_sock);
2308 2184
2309 2185 session->ns_data.dd_sock = -1;
2310 2186 } else {
2311 2187 ndmpd_mover_error(session,
2312 2188 NDMP_MOVER_HALT_CONNECT_CLOSED);
2313 2189 }
|
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
2314 2190 return (NDMP_NO_ERR);
2315 2191 }
2316 2192
2317 2193
2318 2194 /*
2319 2195 * perform the restore
2320 2196 *
2321 2197 * Cannot wait for the thread to exit as we are replying to the
2322 2198 * client request here.
2323 2199 */
2324 - (void) pthread_create(NULL, NULL,
2200 + (void) pthread_create(&tid, NULL,
2325 2201 (funct_t)session->ns_data.dd_module.dm_start_func,
2326 2202 params);
2327 2203
2204 + if (err != 0) {
2205 + syslog(LOG_ERR, "Can't start V2 recover session.");
2206 + return (NDMP_ILLEGAL_ARGS_ERR);
2207 + }
2208 +
2209 + (void) pthread_detach(tid);
2210 +
2328 2211 return (NDMP_NO_ERR);
2329 2212 }
2330 2213
2331 2214 /*
2332 2215 * ndmpd_data_get_info
2333 2216 *
2334 2217 * Return the total number of bytes processed
2335 2218 *
2336 2219 * Parameters:
2337 2220 * session (input) - session pointer.
2338 2221 *
2339 2222 * Returns:
2340 2223 * the number of bytes processed
2341 2224 */
2342 2225 static u_longlong_t
2343 2226 ndmpd_data_get_info(ndmpd_session_t *session)
2344 2227 {
2345 2228 ndmp_lbr_params_t *nlp;
2346 2229
2347 2230 nlp = ndmp_get_nlp(session);
2348 2231 if (nlp == NULL)
2349 2232 return ((u_longlong_t)0);
2350 2233
2351 2234 if (nlp->nlp_jstat == NULL)
2352 2235 return (nlp->nlp_bytes_total);
2353 2236
2354 2237 return ((u_longlong_t)nlp->nlp_jstat->js_bytes_total);
2355 2238 }
|
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX