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>
Revert "NEX-5801 Snapshots left over after failed backups"
This reverts commit f182fb95f09036db71fbfc6f0a6b90469b761f21.
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>
NEX-2990 ndmpd dumping core when used with ndmpcopy
NEX-2911 NDMP logging should use syslog and is too chatty
NEX-559 NDMP cannot backup/restore a file which spans multiple tapes
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/cmd/ndmpd/ndmp/ndmpd_tar.c
+++ new/usr/src/cmd/ndmpd/ndmp/ndmpd_tar.c
1 1 /*
2 2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
3 + * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
3 4 */
4 5
5 6 /*
6 7 * BSD 3 Clause License
7 8 *
8 9 * Copyright (c) 2007, The Storage Networking Industry Association.
9 10 *
10 11 * Redistribution and use in source and binary forms, with or without
11 12 * modification, are permitted provided that the following conditions
12 13 * are met:
13 14 * - Redistributions of source code must retain the above copyright
14 15 * notice, this list of conditions and the following disclaimer.
15 16 *
16 17 * - Redistributions in binary form must reproduce the above copyright
17 18 * notice, this list of conditions and the following disclaimer in
18 19 * the documentation and/or other materials provided with the
19 20 * distribution.
20 21 *
21 22 * - Neither the name of The Storage Networking Industry Association (SNIA)
22 23 * nor the names of its contributors may be used to endorse or promote
23 24 * products derived from this software without specific prior written
24 25 * permission.
25 26 *
26 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
30 31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 37 * POSSIBILITY OF SUCH DAMAGE.
37 38 */
38 39 /* Copyright (c) 2007, The Storage Networking Industry Association. */
39 40 /* Copyright (c) 1996, 1997 PDC, Network Appliance. All Rights Reserved */
40 -/* Copyright 2014 Nexenta Systems, Inc. All rights reserved. */
41 +/* Copyright 2017 Nexenta Systems, Inc. All rights reserved. */
41 42
42 43 #include <sys/stat.h>
43 44 #include <sys/types.h>
44 45 #include <sys/socket.h>
46 +#include <syslog.h>
45 47 #include <errno.h>
46 48 #include <stdio.h>
47 49 #include <string.h>
48 50 #include <unistd.h>
49 51 #include <time.h>
50 52 #include <cstack.h>
51 53 #include <dirent.h>
52 54 #include <traverse.h>
53 55 #include "bitmap.h"
54 56 #include "ndmpd.h"
55 57 #include "tlm_buffers.h"
56 58
57 59
58 60 typedef struct ndmp_run_args {
59 61 char *nr_chkp_nm;
60 62 char *nr_unchkp_nm;
61 63 char **nr_excls;
62 64 } ndmp_run_args_t;
63 65
64 66
65 67 /*
66 68 * backup_create_structs
67 69 *
68 70 * Allocate the structures before performing backup
69 71 *
70 72 * Parameters:
71 73 * sesison (input) - session handle
72 74 * jname (input) - backup job name
73 75 *
74 76 * Returns:
75 77 * 0: on success
76 78 * -1: otherwise
|
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
77 79 */
78 80 static int
79 81 backup_create_structs(ndmpd_session_t *session, char *jname)
80 82 {
81 83 int n;
82 84 long xfer_size;
83 85 ndmp_lbr_params_t *nlp;
84 86 tlm_commands_t *cmds;
85 87
86 88 if ((nlp = ndmp_get_nlp(session)) == NULL) {
87 - NDMP_LOG(LOG_DEBUG, "nlp == NULL");
88 89 return (-1);
89 90 }
90 91
91 92 if ((nlp->nlp_jstat = tlm_new_job_stats(jname)) == NULL) {
92 - NDMP_LOG(LOG_DEBUG, "Creating job stats");
93 93 return (-1);
94 94 }
95 95
96 96 cmds = &nlp->nlp_cmds;
97 97 (void) memset(cmds, 0, sizeof (*cmds));
98 98
99 99 xfer_size = ndmp_buffer_get_size(session);
100 100 if (xfer_size < 512*KILOBYTE) {
101 101 /*
102 102 * Read multiple of mover_record_size near to 512K. This
103 103 * will prevent the data being copied in the mover buffer
104 104 * when we write the data.
105 105 */
106 106 if ((n = (512 * KILOBYTE/xfer_size)) <= 0)
107 107 n = 1;
108 108 xfer_size *= n;
109 - NDMP_LOG(LOG_DEBUG, "Adjusted read size: %d", xfer_size);
109 + syslog(LOG_DEBUG, "Adjusted read size: %d", xfer_size);
110 110 }
111 111
112 112 cmds->tcs_command = tlm_create_reader_writer_ipc(TRUE, xfer_size);
113 113 if (cmds->tcs_command == NULL) {
114 - NDMP_LOG(LOG_DEBUG, "Error creating ipc buffers");
114 + syslog(LOG_ERR, "Error creating ipc buffers");
115 115 tlm_un_ref_job_stats(jname);
116 116 return (-1);
117 117 }
118 118
119 119 nlp->nlp_logcallbacks = lbrlog_callbacks_init(session,
120 120 ndmpd_file_history_path,
121 121 ndmpd_file_history_dir,
122 122 ndmpd_file_history_node);
123 123 if (nlp->nlp_logcallbacks == NULL) {
124 124 tlm_release_reader_writer_ipc(cmds->tcs_command);
125 125 tlm_un_ref_job_stats(jname);
126 126 return (-1);
127 127 }
128 128 nlp->nlp_jstat->js_callbacks = (void *)(nlp->nlp_logcallbacks);
129 129
130 130 return (0);
131 131 }
132 132
133 133
134 134 /*
135 135 * restore_create_structs
136 136 *
137 137 * Allocate structures for performing a restore
138 138 *
139 139 * Parameters:
140 140 * sesison (input) - session handle
141 141 * jname (input) - backup job name
142 142 *
143 143 * Returns:
144 144 * 0: on success
145 145 * -1: otherwise
|
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
146 146 */
147 147 static int
148 148 restore_create_structs(ndmpd_session_t *session, char *jname)
149 149 {
150 150 int i;
151 151 long xfer_size;
152 152 ndmp_lbr_params_t *nlp;
153 153 tlm_commands_t *cmds;
154 154
155 155 if ((nlp = ndmp_get_nlp(session)) == NULL) {
156 - NDMP_LOG(LOG_DEBUG, "nlp == NULL");
157 156 return (-1);
158 157 }
159 158 if ((nlp->nlp_jstat = tlm_new_job_stats(jname)) == NULL) {
160 - NDMP_LOG(LOG_DEBUG, "Creating job stats");
161 159 return (-1);
162 160 }
163 161
164 162 cmds = &nlp->nlp_cmds;
165 163 (void) memset(cmds, 0, sizeof (*cmds));
166 164
167 165 xfer_size = ndmp_buffer_get_size(session);
168 166 cmds->tcs_command = tlm_create_reader_writer_ipc(FALSE, xfer_size);
169 167 if (cmds->tcs_command == NULL) {
170 - NDMP_LOG(LOG_DEBUG, "Error creating ipc buffers");
168 + syslog(LOG_ERR, "Error creating ipc buffers");
171 169 tlm_un_ref_job_stats(jname);
172 170 return (-1);
173 171 }
174 172
175 173 nlp->nlp_logcallbacks = lbrlog_callbacks_init(session,
176 174 ndmpd_path_restored, NULL, NULL);
177 175 if (nlp->nlp_logcallbacks == NULL) {
178 176 tlm_release_reader_writer_ipc(cmds->tcs_command);
179 177 tlm_un_ref_job_stats(jname);
180 178 return (-1);
181 179 }
182 180 nlp->nlp_jstat->js_callbacks = (void *)(nlp->nlp_logcallbacks);
183 181
184 182 nlp->nlp_restored = ndmp_malloc(sizeof (boolean_t) * nlp->nlp_nfiles);
185 183 if (nlp->nlp_restored == NULL) {
186 184 lbrlog_callbacks_done(nlp->nlp_logcallbacks);
187 185 tlm_release_reader_writer_ipc(cmds->tcs_command);
188 186 tlm_un_ref_job_stats(jname);
189 187 return (-1);
190 188 }
191 189 for (i = 0; i < (int)nlp->nlp_nfiles; i++)
192 190 nlp->nlp_restored[i] = FALSE;
193 191
194 192 return (0);
195 193 }
196 194
197 195
198 196 /*
199 197 * send_unrecovered_list
200 198 *
201 199 * Creates a list of restored files
202 200 *
203 201 * Parameters:
204 202 * params (input) - NDMP parameters
205 203 * nlp (input) - NDMP/LBR parameters
206 204 *
207 205 * Returns:
|
↓ open down ↓ |
27 lines elided |
↑ open up ↑ |
208 206 * 0: on success
209 207 * -1: otherwise
210 208 */
211 209 static int
212 210 send_unrecovered_list(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp)
213 211 {
214 212 int i, rv;
215 213 ndmp_name *ent;
216 214
217 215 if (params == NULL) {
218 - NDMP_LOG(LOG_DEBUG, "params == NULL");
219 216 return (-1);
220 217 }
221 218 if (nlp == NULL) {
222 - NDMP_LOG(LOG_DEBUG, "nlp == NULL");
223 219 return (-1);
224 220 }
225 221
226 222 rv = 0;
227 223 for (i = 0; i < (int)nlp->nlp_nfiles; i++) {
228 - NDMP_LOG(LOG_DEBUG, "nlp->nlp_restored[%d]: %s", i,
224 + syslog(LOG_DEBUG, "nlp->nlp_restored[%d]: %s", i,
229 225 nlp->nlp_restored[i] ? "TRUE" : "FALSE");
230 226
231 227 if (!nlp->nlp_restored[i]) {
232 228 ent = (ndmp_name *)MOD_GETNAME(params, i);
233 229 if (ent == NULL) {
234 - NDMP_LOG(LOG_DEBUG, "ent == NULL");
235 230 rv = -1;
236 231 break;
237 232 }
238 233 if (ent->name == NULL) {
239 - NDMP_LOG(LOG_DEBUG, "ent->name == NULL");
240 234 rv = -1;
241 235 break;
242 236 }
243 237
244 - NDMP_LOG(LOG_DEBUG, "ent.name: \"%s\"", ent->name);
238 + syslog(LOG_DEBUG, "ent.name: \"%s\"", ent->name);
245 239
246 240 rv = MOD_FILERECOVERD(params, ent->name, ENOENT);
247 241 if (rv < 0)
248 242 break;
249 243 }
250 244 }
251 245
252 246 return (rv);
253 247 }
254 248
255 249
256 250 /*
257 251 * backup_release_structs
258 252 *
259 253 * Deallocated the NDMP/LBR specific parameters
260 254 *
261 255 * Parameters:
262 256 * session (input) - session handle
263 257 *
264 258 * Returns:
|
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
265 259 * void
266 260 */
267 261 /*ARGSUSED*/
268 262 static void
269 263 backup_release_structs(ndmpd_session_t *session)
270 264 {
271 265 ndmp_lbr_params_t *nlp;
272 266 tlm_commands_t *cmds;
273 267
274 268 if ((nlp = ndmp_get_nlp(session)) == NULL) {
275 - NDMP_LOG(LOG_DEBUG, "nlp == NULL");
276 269 return;
277 270 }
278 271 cmds = &nlp->nlp_cmds;
279 272 if (cmds == NULL) {
280 - NDMP_LOG(LOG_DEBUG, "cmds == NULL");
281 273 return;
282 274 }
283 275
284 276 if (nlp->nlp_logcallbacks != NULL) {
285 277 lbrlog_callbacks_done(nlp->nlp_logcallbacks);
286 278 nlp->nlp_logcallbacks = NULL;
287 - } else {
288 - NDMP_LOG(LOG_DEBUG, "FH CALLBACKS == NULL");
289 279 }
290 280
291 281 if (cmds->tcs_command != NULL) {
292 282 if (cmds->tcs_command->tc_buffers != NULL)
293 283 tlm_release_reader_writer_ipc(cmds->tcs_command);
294 - else
295 - NDMP_LOG(LOG_DEBUG, "BUFFERS == NULL");
296 284 cmds->tcs_command = NULL;
297 - } else {
298 - NDMP_LOG(LOG_DEBUG, "COMMAND == NULL");
299 285 }
300 286
301 287 if (nlp->nlp_bkmap >= 0) {
302 288 (void) dbm_free(nlp->nlp_bkmap);
303 289 nlp->nlp_bkmap = -1;
304 290 }
305 291
306 292 if (session->ns_data.dd_operation == NDMP_DATA_OP_RECOVER &&
307 293 nlp->nlp_restored != NULL) {
308 294 free(nlp->nlp_restored);
309 295 nlp->nlp_restored = NULL;
310 - } else {
311 - NDMP_LOG(LOG_DEBUG, "nlp_restored == NULL");
312 296 }
313 297 }
314 298
315 299 /*
316 300 * ndmp_write_utf8magic
317 301 *
318 302 * Write a magic pattern to the tar header. This is used
319 303 * as a crest to indicate that tape belongs to us.
320 304 */
321 305 int
322 306 ndmp_write_utf8magic(tlm_cmd_t *cmd)
323 307 {
324 308 char *cp;
325 309 long actual_size;
326 310
327 311 if (cmd->tc_buffers == NULL) {
328 - NDMP_LOG(LOG_DEBUG, "cmd->tc_buffers == NULL");
329 312 return (-1);
330 313 }
331 314
332 315 cp = tlm_get_write_buffer(RECORDSIZE, &actual_size,
333 316 cmd->tc_buffers, TRUE);
334 317 if (actual_size < RECORDSIZE) {
335 - NDMP_LOG(LOG_DEBUG, "Couldn't get enough buffer");
336 318 return (-1);
337 319 }
338 320
339 321 (void) strlcpy(cp, NDMPUTF8MAGIC, RECORDSIZE);
340 322 return (0);
341 323 }
342 324
343 325
344 326 /*
345 327 * timecmp
346 328 *
347 329 * This callback function is used during backup. It checks
348 330 * if the object specified by the 'attr' should be backed
349 331 * up or not.
350 332 *
351 333 * Directories are backed up anyways for dump format.
352 334 * If this function is called, then the directory is
353 335 * marked in the bitmap vector, it shows that either the
354 336 * directory itself is modified or there is something below
355 337 * it that will be backed up.
356 338 *
357 339 * Directories for tar format are backed up if and only if
358 340 * they are modified.
359 341 *
360 342 * By setting ndmp_force_bk_dirs global variable to a non-zero
361 343 * value, directories are backed up anyways.
362 344 *
363 345 * Backing up the directories unconditionally, helps
364 346 * restoring the metadata of directories as well, when one
365 347 * of the objects below them are being restored.
366 348 *
367 349 * For non-directory objects, if the modification or change
368 350 * time of the object is after the date specified by the
369 351 * bk_selector_t, the the object must be backed up.
|
↓ open down ↓ |
24 lines elided |
↑ open up ↑ |
370 352 *
371 353 */
372 354 static boolean_t
373 355 timecmp(bk_selector_t *bksp,
374 356 struct stat64 *attr)
375 357 {
376 358 ndmp_lbr_params_t *nlp;
377 359
378 360 nlp = (ndmp_lbr_params_t *)bksp->bs_cookie;
379 361 if (S_ISDIR(attr->st_mode) && ndmp_force_bk_dirs) {
380 - NDMP_LOG(LOG_DEBUG, "d(%lu)",
381 - (uint_t)attr->st_ino);
382 362 return (TRUE);
383 363 }
384 364 if (S_ISDIR(attr->st_mode) &&
385 365 dbm_getone(nlp->nlp_bkmap, (u_longlong_t)attr->st_ino) &&
386 366 ((NLP_ISDUMP(nlp) && ndmp_dump_path_node) ||
387 367 (NLP_ISTAR(nlp) && ndmp_tar_path_node))) {
388 368 /*
389 369 * If the object is a directory and it leads to a modified
390 370 * object (that should be backed up) and for that type of
391 371 * backup the path nodes should be backed up, then return
392 372 * TRUE.
|
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
393 373 *
394 374 * This is required by some DMAs like Backup Express, which
395 375 * needs to receive ADD_NODE (for dump) or ADD_PATH (for tar)
396 376 * for the intermediate directories of a modified object.
397 377 * Other DMAs, like net_backup and net_worker, do not have such
398 378 * requirement. This requirement makes sense for dump format
399 379 * but for 'tar' format, it does not. In provision to the
400 380 * NDMP-v4 spec, for 'tar' format the intermediate directories
401 381 * need not to be reported.
402 382 */
403 - NDMP_LOG(LOG_DEBUG, "p(%lu)", (u_longlong_t)attr->st_ino);
383 + syslog(LOG_DEBUG, "p(%lu)", (u_longlong_t)attr->st_ino);
404 384 return (TRUE);
405 385 }
406 386 if (attr->st_mtime > bksp->bs_ldate) {
407 - NDMP_LOG(LOG_DEBUG, "m(%lu): %lu > %lu",
387 + syslog(LOG_DEBUG, "m(%lu): %lu > %lu",
408 388 (uint_t)attr->st_ino, (uint_t)attr->st_mtime,
409 389 (uint_t)bksp->bs_ldate);
410 390 return (TRUE);
411 391 }
412 392 if (attr->st_ctime > bksp->bs_ldate) {
413 393 if (NLP_IGNCTIME(nlp)) {
414 - NDMP_LOG(LOG_DEBUG, "ign c(%lu): %lu > %lu",
394 + syslog(LOG_DEBUG, "ign c(%lu): %lu > %lu",
415 395 (uint_t)attr->st_ino, (uint_t)attr->st_ctime,
416 396 (uint_t)bksp->bs_ldate);
417 397 return (FALSE);
418 398 }
419 - NDMP_LOG(LOG_DEBUG, "c(%lu): %lu > %lu",
399 + syslog(LOG_DEBUG, "c(%lu): %lu > %lu",
420 400 (uint_t)attr->st_ino, (uint_t)attr->st_ctime,
421 401 (uint_t)bksp->bs_ldate);
422 402 return (TRUE);
423 403 }
424 - NDMP_LOG(LOG_DEBUG, "mc(%lu): (%lu,%lu) < %lu",
404 + syslog(LOG_DEBUG, "mc(%lu): (%lu,%lu) < %lu",
425 405 (uint_t)attr->st_ino, (uint_t)attr->st_mtime,
426 406 (uint_t)attr->st_ctime, (uint_t)bksp->bs_ldate);
427 407 return (FALSE);
428 408 }
429 409
430 410
431 411 /*
432 412 * get_acl_info
433 413 *
434 414 * load up all the access and attribute info
435 415 */
436 416 static int
437 417 get_acl_info(char *name, tlm_acls_t *tlm_acls)
438 418 {
439 419 int erc;
440 420 acl_t *aclp = NULL;
441 421 char *acltp;
442 422
443 423 erc = lstat64(name, &tlm_acls->acl_attr);
444 424 if (erc != 0) {
445 - NDMP_LOG(LOG_ERR, "Could not find file %s.", name);
425 + syslog(LOG_ERR, "Could not find file %s.", name);
446 426 erc = TLM_NO_SOURCE_FILE;
447 427 return (erc);
448 428 }
449 429 erc = acl_get(name, ACL_NO_TRIVIAL, &aclp);
450 430 if (erc != 0) {
451 - NDMP_LOG(LOG_DEBUG,
431 + syslog(LOG_DEBUG,
452 432 "Could not read ACL for file [%s]", name);
453 433 erc = TLM_NO_SOURCE_FILE;
454 434 return (erc);
455 435 }
456 436 if (aclp && (acltp = acl_totext(aclp,
457 437 ACL_APPEND_ID | ACL_SID_FMT | ACL_COMPACT_FMT)) != NULL) {
458 438 (void) strlcpy(tlm_acls->acl_info.attr_info, acltp,
459 439 TLM_MAX_ACL_TXT);
460 440 acl_free(aclp);
461 441 free(acltp);
462 442 }
463 443 return (erc);
464 444 }
465 445 /*
466 446 * get_dir_acl_info
467 447 *
468 448 * load up all ACL and attr info about a directory
469 449 */
470 450 static int
471 451 get_dir_acl_info(char *dir, tlm_acls_t *tlm_acls, tlm_job_stats_t *js)
472 452 {
473 453 int erc;
474 454 char *checkpointed_dir;
475 455 char root_dir[TLM_VOLNAME_MAX_LENGTH];
476 456 char *spot;
477 457 char *fil;
478 458 acl_t *aclp = NULL;
479 459 char *acltp;
480 460
481 461 checkpointed_dir = ndmp_malloc(TLM_MAX_PATH_NAME);
|
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
482 462 if (checkpointed_dir == NULL)
483 463 return (-1);
484 464
485 465 if (tlm_acls->acl_checkpointed)
486 466 fil = tlm_build_snapshot_name(dir, checkpointed_dir,
487 467 js->js_job_name);
488 468 else
489 469 fil = dir;
490 470 erc = lstat64(fil, &tlm_acls->acl_attr);
491 471 if (erc != 0) {
492 - NDMP_LOG(LOG_ERR, "Could not find directory %s.", dir);
472 + syslog(LOG_ERR, "Could not find directory %s.", dir);
493 473 free(checkpointed_dir);
494 474 return (-1);
495 475 }
496 476
497 477 spot = strchr(&fil[1], '/');
498 478 if (spot == NULL) {
499 479 (void) strlcpy(root_dir, fil, TLM_VOLNAME_MAX_LENGTH);
500 480 } else {
501 481 *spot = 0;
502 482 (void) strlcpy(root_dir, fil, TLM_VOLNAME_MAX_LENGTH);
503 483 *spot = '/';
504 484 }
505 485 if (strcmp(root_dir, tlm_acls->acl_root_dir) != 0) {
506 486 struct stat64 attr;
507 487
508 488 erc = lstat64(root_dir, &attr);
509 489 if (erc != 0) {
510 - NDMP_LOG(LOG_ERR, "Cannot find root directory %s.",
490 + syslog(LOG_ERR, "Cannot find root directory %s.",
511 491 root_dir);
512 492 free(checkpointed_dir);
513 493 return (-1);
514 494 }
515 495 (void) strlcpy(tlm_acls->acl_root_dir, root_dir,
516 496 TLM_VOLNAME_MAX_LENGTH);
517 497 }
518 498 erc = acl_get(fil, ACL_NO_TRIVIAL, &aclp);
519 499 if (erc != 0) {
520 - NDMP_LOG(LOG_DEBUG,
500 + syslog(LOG_DEBUG,
521 501 "Could not read metadata for directory [%s]", dir);
522 502 free(checkpointed_dir);
523 503 return (-1);
524 504 }
525 505 if (aclp && (acltp = acl_totext(aclp,
526 506 ACL_APPEND_ID | ACL_SID_FMT | ACL_COMPACT_FMT)) != NULL) {
527 507 (void) strlcpy(tlm_acls->acl_info.attr_info, acltp,
528 508 TLM_MAX_ACL_TXT);
529 509 acl_free(aclp);
530 510 free(acltp);
531 511 }
532 512
533 513 free(checkpointed_dir);
534 514 return (0);
535 515 }
536 516
537 517 /*
538 518 * backup_dir
|
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
539 519 *
540 520 * Create a TAR entry record for a directory
541 521 */
542 522 static int
543 523 backup_dir(char *dir, tlm_acls_t *tlm_acls,
544 524 tlm_cmd_t *local_commands, tlm_job_stats_t *job_stats,
545 525 bk_selector_t *bksp)
546 526 {
547 527 int erc;
548 528
549 - NDMP_LOG(LOG_DEBUG, "\"%s\"", dir);
550 -
551 529 erc = get_dir_acl_info(dir, tlm_acls, job_stats);
552 530 if (erc != 0) {
553 - NDMP_LOG(LOG_DEBUG,
531 + syslog(LOG_ERR,
554 532 "Could not read directory info for %s", dir);
555 533 job_stats->js_errors++;
556 534 } else {
557 535 /*
558 536 * See if the directory must be backed up.
559 537 */
560 538 if (bksp && !(*bksp->bs_fn)(bksp, &tlm_acls->acl_attr)) {
561 - NDMP_LOG(LOG_DEBUG, "[%s] dir skipped", dir);
539 + syslog(LOG_DEBUG, "[%s] dir skipped", dir);
562 540 return (erc);
563 541 }
564 542
565 543 if (tm_tar_ops.tm_putdir != NULL)
566 544 (void) (tm_tar_ops.tm_putdir)(dir, tlm_acls,
567 545 local_commands, job_stats);
568 546 }
569 547
570 548 return (erc);
571 549 }
572 550
573 551
574 552 /*
575 553 * backup_file
576 554 *
|
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
577 555 * Create a TAR record entry for a file
578 556 */
579 557 static longlong_t
580 558 backup_file(char *dir, char *name, tlm_acls_t *tlm_acls,
581 559 tlm_commands_t *commands, tlm_cmd_t *local_commands,
582 560 tlm_job_stats_t *job_stats, bk_selector_t *bksp)
583 561 {
584 562
585 563 int erc;
586 564 char buf[TLM_MAX_PATH_NAME];
587 - longlong_t rv;
565 + longlong_t rv = -1;
588 566
589 - NDMP_LOG(LOG_DEBUG, "\"%s/%s\"", dir, name);
590 -
591 567 (void) strlcpy(buf, dir, sizeof (buf));
592 568 (void) strlcat(buf, "/", sizeof (buf));
593 569 (void) strlcat(buf, name, sizeof (buf));
594 570
595 571 /*
596 572 * get_acl_info extracts file handle, attributes and ACLs of the file.
597 573 * This is not efficient when the attributes and file handle of
598 574 * the file is already known.
599 575 */
600 576 erc = get_acl_info(buf, tlm_acls);
601 577 if (erc != TLM_NO_ERRORS) {
602 - NDMP_LOG(LOG_ERR, "Could not open file %s/%s.", dir, name);
578 + syslog(LOG_ERR, "Could not open file %s/%s.", dir, name);
603 579 return (-ENOENT);
604 580 }
605 581
606 582 /* Should the file be backed up? */
607 583 if (!bksp) {
608 - NDMP_LOG(LOG_DEBUG,
584 + syslog(LOG_DEBUG,
609 585 "[%s/%s] has no selection criteria", dir, name);
610 586
611 587 } else if (!((*bksp->bs_fn)(bksp, &tlm_acls->acl_attr))) {
612 - NDMP_LOG(LOG_DEBUG, "[%s/%s] file skipped", dir, name);
588 + syslog(LOG_DEBUG, "[%s/%s] file skipped", dir, name);
613 589 return (0);
614 590 }
615 591
616 592 /* Only the regular files and symbolic links can be backed up. */
617 593 if (!S_ISLNK(tlm_acls->acl_attr.st_mode) &&
618 594 !S_ISREG(tlm_acls->acl_attr.st_mode)) {
619 - NDMP_LOG(LOG_DEBUG,
595 + syslog(LOG_DEBUG,
620 596 "Warning: skip backing up [%s][%s]", dir, name);
621 597 return (-EINVAL);
622 598 }
623 599
624 600
625 601 if (tm_tar_ops.tm_putfile != NULL)
626 602 rv = (tm_tar_ops.tm_putfile)(dir, name, tlm_acls, commands,
627 603 local_commands, job_stats);
628 604
629 605 return (rv);
630 606 }
631 607
632 608
633 609
634 610 /*
635 611 * backup_work
636 612 *
637 613 * Start the NDMP backup (V2 only).
638 614 */
639 615 int
640 616 backup_work(char *bk_path, tlm_job_stats_t *job_stats,
641 617 ndmp_run_args_t *np, tlm_commands_t *commands,
642 618 ndmp_lbr_params_t *nlp)
643 619 {
644 620 struct full_dir_info dir_info; /* the blob to push/pop with cstack_t */
645 621 struct full_dir_info *t_dir_info, *p_dir_info;
646 622 struct stat64 ret_attr; /* attributes of current file name */
647 623 fs_fhandle_t ret_fh;
648 624 char *first_name; /* where the first name is located */
649 625 char *dname;
650 626 int erc;
|
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
651 627 int retval;
652 628 cstack_t *stk;
653 629 unsigned long fileid;
654 630 tlm_acls_t tlm_acls;
655 631 int dname_size;
656 632 longlong_t fsize;
657 633 bk_selector_t bks;
658 634 tlm_cmd_t *local_commands;
659 635 long dpos;
660 636
661 - NDMP_LOG(LOG_DEBUG, "nr_chkpnted %d nr_ldate: %u bk_path: \"%s\"",
637 + syslog(LOG_DEBUG, "nr_chkpnted %d nr_ldate: %u bk_path: \"%s\"",
662 638 NLP_ISCHKPNTED(nlp), nlp->nlp_ldate, bk_path);
663 639
664 640 /* Get every name in this directory */
665 641 dname = ndmp_malloc(TLM_MAX_PATH_NAME);
666 642 if (dname == NULL)
667 643 return (-ENOMEM);
668 644
669 645 local_commands = commands->tcs_command;
670 646 retval = 0;
671 647 (void) memset(&bks, 0, sizeof (bks));
672 648 bks.bs_cookie = (void *)nlp;
673 649 bks.bs_level = nlp->nlp_clevel;
674 650 bks.bs_ldate = nlp->nlp_ldate;
675 651 bks.bs_fn = timecmp;
676 652
677 653 /*
678 654 * should we skip the whole thing?
679 655 */
680 656 if (tlm_is_excluded("", bk_path, np->nr_excls)) {
681 - NDMP_LOG(LOG_DEBUG, "%s excluded", bk_path);
657 + syslog(LOG_DEBUG, "%s excluded", bk_path);
682 658 free(dname);
683 659 return (0);
684 660 }
685 661
686 662 /*
687 663 * Search for the top-level file-directory
688 664 */
689 665 if (NLP_ISCHKPNTED(nlp)) {
690 666 first_name = np->nr_chkp_nm;
691 667 (void) strlcpy(first_name, bk_path, TLM_MAX_PATH_NAME);
692 668 } else {
693 669 first_name = tlm_build_snapshot_name(bk_path, np->nr_chkp_nm,
694 670 nlp->nlp_jstat->js_job_name);
695 671 }
696 672
697 673 (void) memset(&ret_fh, 0, sizeof (ret_fh));
698 674 erc = fs_getstat(first_name, &ret_fh, &ret_attr);
699 675 if (erc != 0) {
700 - NDMP_LOG(LOG_ERR, "Path %s not found.", first_name);
676 + syslog(LOG_ERR, "Path %s not found.", first_name);
701 677 free(dname);
702 678 return (-EINVAL);
703 679 }
704 680
705 681 if ((stk = cstack_new()) == NULL) {
706 682 free(dname);
707 - NDMP_LOG(LOG_DEBUG, "cstack_new failed");
683 + syslog(LOG_DEBUG, "cstack_new failed");
708 684 return (-ENOMEM);
709 685 }
710 686 (void) strlcpy(dir_info.fd_dir_name, first_name, TLM_MAX_PATH_NAME);
711 687 (void) memcpy(&dir_info.fd_dir_fh, &ret_fh, sizeof (fs_fhandle_t));
712 688 p_dir_info = dup_dir_info(&dir_info);
713 689
714 690 /*
715 691 * Push the first name onto the stack so that we can pop it back
716 692 * off as part of the normal cycle
717 693 */
718 694 if (cstack_push(stk, p_dir_info, 0)) {
719 695 free(dname);
720 696 free(p_dir_info);
721 697 cstack_delete(stk);
722 - NDMP_LOG(LOG_DEBUG, "cstack_push failed");
698 + syslog(LOG_DEBUG, "cstack_push failed");
723 699 return (-ENOMEM);
724 700 }
725 701
726 702 (void) memset(&tlm_acls, 0, sizeof (tlm_acls));
727 703 /*
728 704 * Did NDMP create a checkpoint?
729 705 */
730 706 if (NLP_ISCHKPNTED(nlp) || fs_is_rdonly(bk_path)) {
731 707 tlm_acls.acl_checkpointed = FALSE;
732 708 } else {
733 709 /* Use the checkpoint created by NDMP */
734 710 tlm_acls.acl_checkpointed = TRUE;
735 711 }
736 712
737 713 /*
738 714 * This is level-backup. It never resets the archive bit.
739 715 */
740 716 tlm_acls.acl_clear_archive = FALSE;
741 717
742 - NDMP_LOG(LOG_DEBUG, "acls.chkpnt: %c acls.clear_arcbit: %c",
718 + syslog(LOG_DEBUG, "acls.chkpnt: %c acls.clear_arcbit: %c",
743 719 NDMP_YORN(tlm_acls.acl_checkpointed),
744 720 NDMP_YORN(tlm_acls.acl_clear_archive));
745 721
746 722 while (commands->tcs_reader == TLM_BACKUP_RUN &&
747 723 local_commands->tc_reader == TLM_BACKUP_RUN &&
748 724 cstack_pop(stk, (void **)&p_dir_info, 0) == 0) {
749 725
750 726 if (NLP_ISCHKPNTED(nlp))
751 727 (void) strlcpy(np->nr_unchkp_nm,
752 728 p_dir_info->fd_dir_name, TLM_MAX_PATH_NAME);
753 729 else
754 730 (void) tlm_remove_checkpoint(p_dir_info->fd_dir_name,
755 731 np->nr_unchkp_nm);
|
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
756 732
757 733 (void) backup_dir(np->nr_unchkp_nm, &tlm_acls, local_commands,
758 734 job_stats, &bks);
759 735
760 736
761 737 while (commands->tcs_reader == TLM_BACKUP_RUN &&
762 738 local_commands->tc_reader == TLM_BACKUP_RUN) {
763 739
764 740 dname_size = TLM_MAX_PATH_NAME - 1;
765 741
766 - NDMP_LOG(LOG_DEBUG,
742 + syslog(LOG_DEBUG,
767 743 "dir_name: %s", p_dir_info->fd_dir_name);
768 744
769 745 (void) memset(&ret_fh, 0, sizeof (ret_fh));
770 746 erc = fs_readdir(&p_dir_info->fd_dir_fh,
771 747 p_dir_info->fd_dir_name, &dpos,
772 748 dname, &dname_size, &ret_fh, &ret_attr);
773 749 if (erc == 0) {
774 750 fileid = ret_fh.fh_fid;
775 751 } else {
776 - NDMP_LOG(LOG_DEBUG,
752 + syslog(LOG_DEBUG,
777 753 "Filesystem readdir in [%s]",
778 754 p_dir_info->fd_dir_name);
779 755 retval = -ENOENT;
780 756 break;
781 757 }
782 758
783 759 /* an empty name size marks the end of the list */
784 760 if (dname_size == 0)
785 761 break;
786 762 dname[dname_size] = '\0';
787 763
788 - NDMP_LOG(LOG_DEBUG, "dname: \"%s\"", dname);
789 -
790 764 /*
791 765 * If name refers to a directory, push its file
792 766 * handle onto the stack (skip "." and "..").
793 767 */
794 768 if (rootfs_dot_or_dotdot(dname)) {
795 769 fileid = 0;
796 770 continue;
797 771 }
798 772
799 773 /*
800 774 * Skip the:
801 775 * non-dir entries which should not be backed up
802 776 * Or
803 777 * dir-type entries which have have nothing under
804 778 * their hierarchy to be backed up.
805 779 */
806 780 if (!dbm_getone(nlp->nlp_bkmap, (u_longlong_t)fileid)) {
807 - NDMP_LOG(LOG_DEBUG, "Skipping %s/%s",
781 + syslog(LOG_DEBUG, "Skipping %s/%s",
808 782 p_dir_info->fd_dir_name, dname);
809 783 fileid = 0;
810 784 continue;
811 785 }
812 786
813 787 if (tlm_is_excluded(np->nr_unchkp_nm, dname,
814 788 np->nr_excls)) {
815 789 fileid = 0;
816 790 continue;
817 791 }
818 792 if (S_ISDIR(ret_attr.st_mode)) {
819 793 /*
820 794 * only directories get pushed onto this stack,
821 795 * so we do not have to test for regular files.
822 796 */
823 797 t_dir_info = tlm_new_dir_info(&ret_fh,
824 798 p_dir_info->fd_dir_name, dname);
825 799 if (t_dir_info == NULL) {
826 - NDMP_LOG(LOG_DEBUG,
800 + syslog(LOG_DEBUG,
827 801 "While backing up [%s][%s]",
828 802 p_dir_info->fd_dir_name, dname);
829 803 } else if (cstack_push(stk, t_dir_info,
830 804 0) != 0) {
831 - NDMP_LOG(LOG_DEBUG,
805 + syslog(LOG_DEBUG,
832 806 "No enough memory stack_push");
833 807 retval = -ENOMEM;
834 808 break;
835 809 }
836 810 } else if (S_ISREG(ret_attr.st_mode) ||
837 811 S_ISLNK(ret_attr.st_mode)) {
838 812
839 813 fsize = backup_file(np->nr_unchkp_nm, dname,
840 814 &tlm_acls, commands, local_commands,
841 815 job_stats, &bks);
842 816
843 817 if (fsize >= 0) {
844 818 job_stats->js_files_so_far++;
845 819 job_stats->js_bytes_total += fsize;
846 820 } else
847 821 job_stats->js_errors++;
848 822 fileid = 0;
849 823 }
850 824 }
851 825 fileid = 0;
852 826 free(p_dir_info);
853 827 if (retval != 0)
854 828 break;
855 829 }
856 830
857 831 free(dname);
858 832
859 833 while (cstack_pop(stk, (void **)&p_dir_info, 0) == 0) {
860 834 free(p_dir_info);
861 835 }
862 836
863 837 cstack_delete(stk);
864 838 return (retval);
865 839 }
866 840
867 841
868 842 /*
869 843 * free_paths
870 844 *
871 845 * Free the path names
872 846 */
873 847 static void
874 848 free_paths(ndmp_run_args_t *np)
875 849 {
876 850 free(np->nr_chkp_nm);
877 851 free(np->nr_unchkp_nm);
878 852 free(np->nr_excls);
879 853 }
880 854
881 855
882 856 /*
883 857 * malloc_paths
884 858 *
885 859 * Allocate the path names (direct and checkpointed paths)
886 860 */
887 861 static boolean_t
888 862 malloc_paths(ndmp_run_args_t *np)
889 863 {
890 864 boolean_t rv;
891 865
892 866 rv = TRUE;
893 867 np->nr_chkp_nm = ndmp_malloc(TLM_MAX_PATH_NAME);
894 868 np->nr_unchkp_nm = ndmp_malloc(TLM_MAX_PATH_NAME);
895 869 if (!np->nr_chkp_nm || !np->nr_unchkp_nm) {
896 870 free_paths(np);
897 871 rv = FALSE;
898 872 } else if ((np->nr_excls = ndmpd_make_exc_list()) == NULL) {
899 873 free_paths(np);
900 874 rv = FALSE;
901 875 }
902 876 return (rv);
903 877 }
904 878
905 879
906 880 /*
907 881 * ndmp_backup_reader
908 882 *
909 883 * Backup reader thread which uses backup_work to read and TAR
910 884 * the files/dirs to be backed up (V2 only)
|
↓ open down ↓ |
69 lines elided |
↑ open up ↑ |
911 885 */
912 886 static int
913 887 ndmp_backup_reader(tlm_commands_t *commands, ndmp_lbr_params_t *nlp,
914 888 char *job_name)
915 889 {
916 890 int retval;
917 891 ndmp_run_args_t np;
918 892 tlm_job_stats_t *job_stats;
919 893 tlm_cmd_t *local_commands;
920 894
921 - NDMP_LOG(LOG_DEBUG, "bk_path: \"%s\"", nlp->nlp_backup_path);
895 + syslog(LOG_DEBUG, "bk_path: \"%s\"", nlp->nlp_backup_path);
922 896
923 897 local_commands = commands->tcs_command;
924 898 (void) memset(&np, 0, sizeof (np));
925 899 if (!malloc_paths(&np))
926 900 return (-1);
927 901 local_commands->tc_ref++;
928 902 commands->tcs_reader_count++;
929 903
930 904 job_stats = tlm_ref_job_stats(job_name);
931 905
932 906 retval = backup_work(nlp->nlp_backup_path, job_stats, &np,
933 907 commands, nlp);
934 908 write_tar_eof(local_commands);
935 909
936 910 commands->tcs_reader_count--;
937 911 local_commands->tc_writer = TLM_STOP;
938 912 tlm_release_reader_writer_ipc(local_commands);
939 913 tlm_un_ref_job_stats(job_name);
940 914
941 915 free_paths(&np);
942 916 return (retval);
943 917
944 918 }
945 919
946 920
947 921 /*
948 922 * ndmp_tar_writer
949 923 *
950 924 * The backup writer thread that writes the TAR records to the
951 925 * tape media (V2 only)
952 926 */
953 927 int
954 928 ndmp_tar_writer(ndmpd_session_t *session, ndmpd_module_params_t *mod_params,
|
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
955 929 tlm_commands_t *cmds)
956 930 {
957 931 int bidx, nw;
958 932 int err;
959 933 tlm_buffer_t *buf;
960 934 tlm_buffers_t *bufs;
961 935 tlm_cmd_t *lcmd; /* Local command */
962 936
963 937 err = 0;
964 938 if (session == NULL) {
965 - NDMP_LOG(LOG_DEBUG, "session == NULL");
966 939 err = -1;
967 940 } else if (mod_params == NULL) {
968 - NDMP_LOG(LOG_DEBUG, "mod_params == NULL");
969 941 err = -1;
970 942 } else if (cmds == NULL) {
971 - NDMP_LOG(LOG_DEBUG, "cmds == NULL");
972 943 err = -1;
973 944 }
974 945
975 946 if (err != 0)
976 947 return (err);
977 948
978 949 lcmd = cmds->tcs_command;
979 950 bufs = lcmd->tc_buffers;
980 951
981 952 lcmd->tc_ref++;
982 953 cmds->tcs_writer_count++;
983 954
984 955 nw = 0;
985 956 buf = tlm_buffer_out_buf(bufs, &bidx);
986 957 while (cmds->tcs_writer != (int)TLM_ABORT &&
987 958 lcmd->tc_writer != (int)TLM_ABORT) {
988 959 if (buf->tb_full) {
989 - NDMP_LOG(LOG_DEBUG, "w%d", bidx);
990 -
991 960 if (MOD_WRITE(mod_params, buf->tb_buffer_data,
992 961 buf->tb_buffer_size) != 0) {
993 - NDMP_LOG(LOG_DEBUG,
962 + syslog(LOG_DEBUG,
994 963 "Writing buffer %d, pos: %lld",
995 964 bidx, session->ns_mover.md_position);
996 965 err = -1;
997 966 break;
998 967 }
999 968
1000 969 tlm_buffer_mark_empty(buf);
1001 970 (void) tlm_buffer_advance_out_idx(bufs);
1002 971 buf = tlm_buffer_out_buf(bufs, &bidx);
1003 972 tlm_buffer_release_out_buf(bufs);
1004 973 nw++;
1005 974 } else {
1006 975 if (lcmd->tc_writer != TLM_BACKUP_RUN) {
1007 976 /* No more data is comming; time to exit. */
1008 - NDMP_LOG(LOG_DEBUG,
1009 - "tc_writer!=TLM_BACKUP_RUN; time to exit");
1010 977 break;
1011 978 } else {
1012 - NDMP_LOG(LOG_DEBUG, "W%d", bidx);
1013 979 tlm_buffer_in_buf_timed_wait(bufs, 100);
1014 980 }
1015 981 }
1016 982 }
1017 983
1018 - NDMP_LOG(LOG_DEBUG, "nw: %d", nw);
1019 - if (cmds->tcs_writer != (int)TLM_ABORT) {
1020 - NDMP_LOG(LOG_DEBUG, "tcs_writer != TLM_ABORT");
1021 - } else {
1022 - NDMP_LOG(LOG_DEBUG, "tcs_writer == TLM_ABORT");
1023 - }
1024 -
1025 - if (lcmd->tc_writer != (int)TLM_ABORT) {
1026 - NDMP_LOG(LOG_DEBUG, "tc_writer != TLM_ABORT");
1027 - } else {
1028 - NDMP_LOG(LOG_DEBUG, "tc_writer == TLM_ABORT");
1029 - }
1030 984 cmds->tcs_writer_count--;
1031 985 lcmd->tc_reader = TLM_STOP;
1032 986 lcmd->tc_ref--;
1033 987
1034 988 return (err);
1035 989 }
1036 990
1037 991
1038 992 /*
1039 993 * read_one_buf
1040 994 *
1041 995 * Read one buffer from the tape
1042 996 */
1043 997 static int
1044 998 read_one_buf(ndmpd_module_params_t *mod_params, tlm_buffers_t *bufs,
1045 999 tlm_buffer_t *buf)
1046 1000 {
1047 1001 int rv;
1048 1002
1049 1003 if ((rv = MOD_READ(mod_params, buf->tb_buffer_data,
1050 1004 bufs->tbs_data_transfer_size)) == 0) {
1051 1005 buf->tb_eof = buf->tb_eot = FALSE;
1052 1006 buf->tb_errno = 0;
1053 1007 buf->tb_buffer_size = bufs->tbs_data_transfer_size;
1054 1008 buf->tb_buffer_spot = 0;
1055 1009 buf->tb_full = TRUE;
1056 1010 (void) tlm_buffer_advance_in_idx(bufs);
1057 1011 }
1058 1012
1059 1013 return (rv);
1060 1014 }
1061 1015
1062 1016
1063 1017 /*
1064 1018 * ndmp_tar_reader
1065 1019 *
1066 1020 * NDMP Tar reader thread. This threads keep reading the tar
1067 1021 * file from the tape and wakes up the consumer thread to extract
1068 1022 * it on the disk
1069 1023 */
1070 1024 int
1071 1025 ndmp_tar_reader(ndmp_tar_reader_arg_t *argp)
1072 1026 {
1073 1027 int bidx;
1074 1028 int err;
1075 1029 tlm_buffer_t *buf;
1076 1030 tlm_buffers_t *bufs;
1077 1031 tlm_cmd_t *lcmd; /* Local command */
1078 1032 ndmpd_session_t *session;
1079 1033 ndmpd_module_params_t *mod_params;
1080 1034 tlm_commands_t *cmds;
|
↓ open down ↓ |
41 lines elided |
↑ open up ↑ |
1081 1035
1082 1036 if (!argp)
1083 1037 return (-1);
1084 1038
1085 1039 session = argp->tr_session;
1086 1040 mod_params = argp->tr_mod_params;
1087 1041 cmds = argp->tr_cmds;
1088 1042
1089 1043 err = 0;
1090 1044 if (session == NULL) {
1091 - NDMP_LOG(LOG_DEBUG, "session == NULL");
1092 1045 err = -1;
1093 1046 } else if (cmds == NULL) {
1094 - NDMP_LOG(LOG_DEBUG, "cmds == NULL");
1095 1047 err = -1;
1096 1048 }
1097 1049
1098 1050 if (err != 0) {
1099 1051 tlm_cmd_signal(cmds->tcs_command, TLM_TAR_READER);
1100 1052 return (err);
1101 1053 }
1102 1054
1103 1055 lcmd = cmds->tcs_command;
1104 1056 bufs = lcmd->tc_buffers;
1105 1057
1106 1058 lcmd->tc_ref++;
1107 1059 cmds->tcs_reader_count++;
1108 1060
|
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
1109 1061 /*
1110 1062 * Synchronize with our parent thread.
1111 1063 */
1112 1064 tlm_cmd_signal(cmds->tcs_command, TLM_TAR_READER);
1113 1065
1114 1066 buf = tlm_buffer_in_buf(bufs, &bidx);
1115 1067 while (cmds->tcs_reader == TLM_RESTORE_RUN &&
1116 1068 lcmd->tc_reader == TLM_RESTORE_RUN) {
1117 1069
1118 1070 if (buf->tb_full) {
1119 - NDMP_LOG(LOG_DEBUG, "R%d", bidx);
1120 1071 /*
1121 1072 * The buffer is still full, wait for the consumer
1122 1073 * thread to use it.
1123 1074 */
1124 1075 tlm_buffer_out_buf_timed_wait(bufs, 100);
1125 1076 buf = tlm_buffer_in_buf(bufs, NULL);
1126 1077 } else {
1127 - NDMP_LOG(LOG_DEBUG, "r%d", bidx);
1128 -
1129 1078 err = read_one_buf(mod_params, bufs, buf);
1130 1079 if (err < 0) {
1131 - NDMP_LOG(LOG_DEBUG,
1080 + syslog(LOG_DEBUG,
1132 1081 "Reading buffer %d, pos: %lld",
1133 1082 bidx, session->ns_mover.md_position);
1134 1083
1135 1084 /* Force the writer to stop. */
1136 1085 buf->tb_eot = buf->tb_eof = TRUE;
1137 1086 break;
1138 1087 } else if (err == 1) {
1139 - NDMP_LOG(LOG_DEBUG,
1088 + syslog(LOG_DEBUG,
1140 1089 "operation aborted or session terminated");
1141 1090 err = 0;
1142 1091 break;
1143 1092 }
1144 1093
1145 1094 buf = tlm_buffer_in_buf(bufs, &bidx);
1146 1095 tlm_buffer_release_in_buf(bufs);
1147 1096 }
1148 1097 }
1149 1098
1150 1099 /*
1151 1100 * If the consumer is waiting for us, wake it up so that it detects
1152 1101 * we're quiting.
1153 1102 */
1154 1103 lcmd->tc_writer = TLM_STOP;
1155 1104 tlm_buffer_release_in_buf(bufs);
1156 1105 (void) usleep(1000);
1157 1106
1158 1107 /*
1159 1108 * Clean up.
1160 1109 */
1161 1110 cmds->tcs_reader_count--;
1162 1111 lcmd->tc_ref--;
1163 1112 return (err);
1164 1113 }
1165 1114
1166 1115
1167 1116 /*
1168 1117 * ndmpd_tar_backup
1169 1118 *
1170 1119 * Check must have been done that backup work directory exists, before
1171 1120 * calling this function.
|
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
1172 1121 */
1173 1122 static int
1174 1123 ndmpd_tar_backup(ndmpd_session_t *session, ndmpd_module_params_t *mod_params,
1175 1124 ndmp_lbr_params_t *nlp)
1176 1125 {
1177 1126 char jname[TLM_MAX_BACKUP_JOB_NAME];
1178 1127 int err;
1179 1128 tlm_commands_t *cmds;
1180 1129
1181 1130 if (mod_params->mp_operation != NDMP_DATA_OP_BACKUP) {
1182 - NDMP_LOG(LOG_DEBUG,
1131 + syslog(LOG_DEBUG,
1183 1132 "mod_params->mp_operation != NDMP_DATA_OP_BACKUP");
1184 1133 err = -1;
1185 1134 } else {
1186 1135 if (ndmpd_mark_inodes_v2(session, nlp) != 0)
1187 1136 err = -1;
1188 1137 else if (ndmp_get_bk_dir_ino(nlp))
1189 1138 err = -1;
1190 1139 else
1191 1140 err = 0;
1192 1141 }
1193 1142
1194 1143 if (err != 0)
1195 1144 return (err);
1196 1145
1197 - (void) ndmp_new_job_name(jname);
1198 - if (backup_create_structs(session, jname) < 0)
1146 + if (ndmp_new_job_name(jname, sizeof (jname)) <= 0) {
1199 1147 return (-1);
1200 -
1148 + }
1149 + if (backup_create_structs(session, jname) < 0) {
1150 + return (-1);
1151 + }
1201 1152 nlp->nlp_jstat->js_start_ltime = time(NULL);
1202 1153 nlp->nlp_jstat->js_start_time = nlp->nlp_jstat->js_start_ltime;
1203 1154 nlp->nlp_jstat->js_chkpnt_time = nlp->nlp_cdate;
1204 1155
1205 1156 if (!session->ns_data.dd_abort) {
1206 1157
1207 1158 cmds = &nlp->nlp_cmds;
1208 1159 cmds->tcs_reader = cmds->tcs_writer = TLM_BACKUP_RUN;
1209 1160 cmds->tcs_command->tc_reader = TLM_BACKUP_RUN;
1210 1161 cmds->tcs_command->tc_writer = TLM_BACKUP_RUN;
1211 1162
1212 1163 if (ndmp_write_utf8magic(cmds->tcs_command) < 0) {
1213 1164 backup_release_structs(session);
1214 1165 return (-1);
1215 1166 }
1216 1167
1217 - NDMP_LOG(LOG_DEBUG, "Backing up \"%s\" started.",
1168 + syslog(LOG_DEBUG, "Backing up \"%s\" started.",
1218 1169 nlp->nlp_backup_path);
1219 1170
1220 1171 err = ndmp_backup_reader(cmds, nlp, jname);
1221 1172 if (err != 0) {
1222 1173 backup_release_structs(session);
1223 - NDMP_LOG(LOG_DEBUG, "Launch ndmp_backup_reader: %s",
1174 + syslog(LOG_DEBUG, "Launch ndmp_backup_reader: %s",
1224 1175 strerror(err));
1225 1176 return (-1);
1226 1177 }
1227 1178
1228 1179 /* Act as the writer thread. */
1229 1180 err = ndmp_tar_writer(session, mod_params, cmds);
1230 1181
1231 1182 nlp->nlp_jstat->js_stop_time = time(NULL);
1232 1183
1233 - NDMP_LOG(LOG_DEBUG,
1234 - "Runtime [%s] %llu bytes (%llu): %d seconds",
1184 + syslog(LOG_DEBUG,
1185 + "Runtime [%s] %lu bytes (%llu): %d seconds",
1235 1186 nlp->nlp_backup_path, session->ns_mover.md_data_written,
1236 1187 session->ns_mover.md_data_written,
1237 1188 nlp->nlp_jstat->js_stop_time -
1238 1189 nlp->nlp_jstat->js_start_ltime);
1239 1190 MOD_LOG(mod_params,
1240 - "Runtime [%s] %llu bytes (%llu): %d seconds",
1191 + "Runtime [%s] %lu bytes (%lu): %d seconds",
1241 1192 nlp->nlp_backup_path, session->ns_mover.md_data_written,
1242 1193 session->ns_mover.md_data_written,
1243 1194 nlp->nlp_jstat->js_stop_time -
1244 1195 nlp->nlp_jstat->js_start_ltime);
1245 1196
1246 1197 if (session->ns_data.dd_abort)
1247 1198 err = -1;
1248 1199
1249 - NDMP_LOG(LOG_DEBUG, "Backing up \"%s\" finished. (%d)",
1200 + syslog(LOG_DEBUG, "Backing up \"%s\" finished. (%d)",
1250 1201 nlp->nlp_backup_path, err);
1251 1202 } else {
1252 1203 nlp->nlp_jstat->js_stop_time = time(NULL);
1253 - NDMP_LOG(LOG_DEBUG, "Backing up \"%s\" aborted.",
1204 + syslog(LOG_DEBUG, "Backing up \"%s\" aborted.",
1254 1205 nlp->nlp_backup_path);
1255 1206 err = 0;
1256 1207 }
1257 1208
1258 1209 backup_release_structs(session);
1259 1210 return (err);
1260 1211 }
1261 1212
1262 1213
1263 1214 /*
1264 1215 * ndmpd_tar_restore
1265 1216 *
1266 1217 * Restore function that launches TAR reader thread to read from the
1267 1218 * tape and writes the extracted files/dirs to the filesystem
1268 1219 */
1269 1220 static int
1270 1221 ndmpd_tar_restore(ndmpd_session_t *session, ndmpd_module_params_t *mod_params,
1271 1222 ndmp_lbr_params_t *nlp)
1272 1223 {
1273 1224 char jname[TLM_MAX_BACKUP_JOB_NAME];
|
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
1274 1225 char *rspath;
1275 1226 int err;
1276 1227 tlm_commands_t *cmds;
1277 1228 ndmp_tar_reader_arg_t arg;
1278 1229 tlm_backup_restore_arg_t tlm_arg;
1279 1230 ndmp_name *ent;
1280 1231 pthread_t rdtp, wrtp;
1281 1232 int i;
1282 1233
1283 1234 if (mod_params->mp_operation != NDMP_DATA_OP_RECOVER) {
1284 - NDMP_LOG(LOG_DEBUG,
1285 - "mod_params->mp_operation != NDMP_DATA_OP_RECOVER");
1286 1235 return (-1);
1287 1236 }
1288 1237
1289 1238 if (nlp->nlp_restore_path[0] != '\0')
1290 1239 rspath = nlp->nlp_restore_path;
1291 1240 else if (nlp->nlp_restore_bk_path[0] != '\0')
1292 1241 rspath = nlp->nlp_restore_bk_path;
1293 1242 else
1294 1243 rspath = "";
1295 1244
1296 - (void) ndmp_new_job_name(jname);
1297 - if (restore_create_structs(session, jname) < 0)
1245 + if (ndmp_new_job_name(jname, sizeof (jname)) <= 0) {
1298 1246 return (-1);
1247 + }
1248 + if (restore_create_structs(session, jname) < 0) {
1249 + return (-1);
1250 + }
1299 1251
1300 1252 nlp->nlp_jstat->js_start_ltime = time(NULL);
1301 1253 nlp->nlp_jstat->js_start_time = time(NULL);
1302 1254
1303 1255 if (!session->ns_data.dd_abort) {
1304 1256 cmds = &nlp->nlp_cmds;
1305 1257 cmds->tcs_reader = cmds->tcs_writer = TLM_RESTORE_RUN;
1306 1258 cmds->tcs_command->tc_reader = TLM_RESTORE_RUN;
1307 1259 cmds->tcs_command->tc_writer = TLM_RESTORE_RUN;
1308 1260
1309 - NDMP_LOG(LOG_DEBUG, "Restoring to \"%s\" started.", rspath);
1310 - NDMP_LOG(LOG_DEBUG, "Restoring from %s tape(s).",
1261 + syslog(LOG_DEBUG, "Restoring to \"%s\" started.", rspath);
1262 + syslog(LOG_DEBUG, "Restoring from %s tape(s).",
1311 1263 ndmp_data_get_mover_mode(session));
1312 1264
1313 1265 arg.tr_session = session;
1314 1266 arg.tr_mod_params = mod_params;
1315 1267 arg.tr_cmds = cmds;
1316 1268
1317 1269 err = pthread_create(&rdtp, NULL, (funct_t)ndmp_tar_reader,
1318 1270 (void *)&arg);
1319 1271 if (err == 0) {
1320 1272 tlm_cmd_wait(cmds->tcs_command, TLM_TAR_READER);
1321 1273 } else {
1322 - NDMP_LOG(LOG_DEBUG, "Launch ndmp_tar_reader: %m");
1274 + syslog(LOG_DEBUG, "Launch ndmp_tar_reader: %m");
1323 1275 return (-1);
1324 1276 }
1325 1277
1326 1278 if (!ndmp_check_utf8magic(cmds->tcs_command)) {
1327 - NDMP_LOG(LOG_DEBUG, "UTF8Magic not found!");
1279 + syslog(LOG_DEBUG, "UTF8Magic not found!");
1328 1280 } else {
1329 - NDMP_LOG(LOG_DEBUG, "UTF8Magic found");
1281 + syslog(LOG_DEBUG, "UTF8Magic found");
1330 1282 }
1331 1283
1332 1284 (void) memset(&tlm_arg, 0, sizeof (tlm_backup_restore_arg_t));
1333 1285 (void) pthread_barrier_init(&tlm_arg.ba_barrier, 0, 2);
1334 1286
1335 1287 /*
1336 1288 * Set up restore parameters
1337 1289 */
1338 1290 tlm_arg.ba_commands = cmds;
1339 1291 tlm_arg.ba_cmd = cmds->tcs_command;
1340 1292 tlm_arg.ba_job = nlp->nlp_jstat->js_job_name;
1341 1293 tlm_arg.ba_dir = nlp->nlp_restore_path;
1342 1294 for (i = 0; i < nlp->nlp_nfiles; i++) {
1343 1295 ent = (ndmp_name *)MOD_GETNAME(mod_params, i);
1344 - tlm_arg.ba_sels[i] = ent->name;
1296 + tlm_arg.ba_sels[i] = strdup(ent->name);
1345 1297 }
1298 + tlm_arg.ba_count = i;
1346 1299
1347 -
1348 1300 if (tm_tar_ops.tm_getfile != NULL) {
1349 1301 err = pthread_create(&wrtp, NULL,
1350 1302 (funct_t)tm_tar_ops.tm_getfile, (void *)&tlm_arg);
1351 1303 } else {
1352 1304 (void) pthread_barrier_destroy(&tlm_arg.ba_barrier);
1353 - NDMP_LOG(LOG_DEBUG,
1305 + syslog(LOG_DEBUG,
1354 1306 "Thread create tm_getfile: ops NULL");
1355 1307 return (-1);
1356 1308 }
1357 1309 if (err == 0) {
1358 1310 (void) pthread_barrier_wait(&tlm_arg.ba_barrier);
1359 1311 } else {
1360 1312 (void) pthread_barrier_destroy(&tlm_arg.ba_barrier);
1361 - NDMP_LOG(LOG_DEBUG, "thread create tm_getfile: %m");
1313 + syslog(LOG_DEBUG, "thread create tm_getfile: %m");
1362 1314 return (-1);
1363 1315 }
1364 1316
1365 1317 (void) pthread_join(rdtp, NULL);
1366 1318 (void) pthread_join(wrtp, NULL);
1367 1319 (void) pthread_barrier_destroy(&tlm_arg.ba_barrier);
1368 1320
1369 1321 nlp->nlp_jstat->js_stop_time = time(NULL);
1370 1322
1371 1323 /* Send the list of un-recovered files/dirs to the client. */
1372 1324 (void) send_unrecovered_list(mod_params, nlp);
1373 1325
1374 1326 ndmp_stop_local_reader(session, cmds);
1375 1327 ndmp_wait_for_reader(cmds);
1376 1328 ndmp_stop_remote_reader(session);
1377 - NDMP_LOG(LOG_DEBUG, "Restoring to \"%s\" finished. (%d)",
1329 + syslog(LOG_DEBUG, "Restoring to \"%s\" finished. (%d)",
1378 1330 rspath, err);
1379 1331 } else {
1380 1332 nlp->nlp_jstat->js_stop_time = time(NULL);
1381 1333
1382 1334 /* nothing restored. */
1383 1335 (void) send_unrecovered_list(mod_params, nlp);
1384 - NDMP_LOG(LOG_DEBUG, "Restoring to \"%s\" aborted.",
1336 + syslog(LOG_DEBUG, "Restoring to \"%s\" aborted.",
1385 1337 rspath);
1386 1338 err = -1;
1387 1339 }
1388 1340
1389 1341 NDMP_FREE(nlp->nlp_restore_path);
1390 1342 backup_release_structs(session);
1391 1343
1392 1344 return (err);
1393 1345 }
1394 1346
1395 1347
1396 1348 /*
1397 1349 * prefixdir
1398 1350 *
1399 1351 * Extract the path for a given full path entry
1400 1352 */
1401 1353 static char *
1402 1354 prefixdir(char *dir, char *suffix)
1403 1355 {
1404 1356 static char tmp[TLM_MAX_PATH_NAME];
1405 1357 char *tend, *send; /* tmp and suffix end */
1406 1358
1407 1359 if (dir == NULL || suffix == NULL)
1408 1360 return (NULL);
1409 1361
1410 1362 if (*suffix == '\0')
1411 1363 return (dir);
1412 1364
1413 1365 if (*dir == '\0')
1414 1366 return (NULL);
1415 1367
1416 1368 (void) strlcpy(tmp, dir, TLM_MAX_PATH_NAME);
1417 1369 tend = &tmp[strlen(tmp)];
1418 1370 send = &suffix[strlen(suffix)];
1419 1371
1420 1372 /*
1421 1373 * Move backward as far as the last part of the dir and
1422 1374 * the suffix match.
1423 1375 */
1424 1376 while (tend >= tmp && send >= suffix)
1425 1377 if (*tend == *send)
1426 1378 tend--, send--;
1427 1379 else
1428 1380 break;
1429 1381
1430 1382 *++tend = '\0';
1431 1383 return (tmp);
1432 1384 }
1433 1385
1434 1386
1435 1387 /*
1436 1388 * get_nfiles
1437 1389 *
1438 1390 * Get the count of files to be restored
1439 1391 */
1440 1392 static int
1441 1393 get_nfiles(ndmpd_session_t *session, ndmpd_module_params_t *params)
1442 1394 {
1443 1395 if (session->ns_data.dd_nlist_len == 0) {
1444 1396 MOD_LOG(params, "Error: nothing specified to be restored.\n");
1445 1397 return (-1);
1446 1398 }
1447 1399
1448 1400 return (session->ns_data.dd_nlist_len);
1449 1401 }
1450 1402
1451 1403
1452 1404 /*
1453 1405 * get_restore_dest
1454 1406 *
1455 1407 * Get the full pathname of where the entries should be restored to.
1456 1408 */
1457 1409 static char *
1458 1410 get_restore_dest(ndmpd_module_params_t *params)
1459 1411 {
1460 1412 ndmp_name *ent;
1461 1413 char *cp;
1462 1414
1463 1415 /*
1464 1416 * Destination of restore:
1465 1417 * NetBackup of Veritas(C) sends the entries like this:
1466 1418 *
1467 1419 * ent[i].name: is the relative pathname of what is selected in
1468 1420 * the GUI.
1469 1421 * ent[i].dest: is the full pathname of where the dir/file must
1470 1422 * be restored to.
1471 1423 * ent[i].ssi: 0
1472 1424 * ent[i].fh_info: 0
1473 1425 *
1474 1426 */
1475 1427 ent = (ndmp_name *)MOD_GETNAME(params, 0);
1476 1428 cp = prefixdir(ent->dest, ent->name);
1477 1429 if (cp == NULL) {
1478 1430 MOD_LOG(params, "Error: empty restore path.\n");
1479 1431 return (NULL);
1480 1432 }
1481 1433
1482 1434 return (cp);
1483 1435 }
1484 1436
1485 1437
1486 1438 /*
1487 1439 * correct_ents
1488 1440 *
1489 1441 * Correct the entries in the restore list by appending the appropriate
1490 1442 * path to them
1491 1443 */
1492 1444 static int
1493 1445 correct_ents(ndmpd_module_params_t *params, int n, char *bkpath)
1494 1446 {
1495 1447 char *cp, *pathname;
1496 1448 int i, len, rv;
1497 1449 ndmp_name *ent;
1498 1450
|
↓ open down ↓ |
104 lines elided |
↑ open up ↑ |
1499 1451 if ((pathname = ndmp_malloc(TLM_MAX_PATH_NAME)) == NULL) {
1500 1452 MOD_LOG(params, "Error: insufficient memory.\n");
1501 1453 return (-1);
1502 1454 }
1503 1455
1504 1456 rv = 0;
1505 1457 /* Append the backup path to all the "ent[].name"s. */
1506 1458 for (i = 0; i < n; i++) {
1507 1459 ent = (ndmp_name *)MOD_GETNAME(params, i);
1508 1460
1509 - NDMP_LOG(LOG_DEBUG,
1461 + syslog(LOG_DEBUG,
1510 1462 "Old: ent[%d].name: \"%s\"", i, ent->name);
1511 - NDMP_LOG(LOG_DEBUG,
1463 + syslog(LOG_DEBUG,
1512 1464 "Old: ent[%d].dest: \"%s\"", i, ent->dest);
1513 1465
1514 1466 /* remove trailing slash */
1515 1467 len = strlen(ent->name);
1516 1468 if (ent->name[len - 1] == '/')
1517 1469 ent->name[len - 1] = '\0';
1518 1470
1519 1471 if (!tlm_cat_path(pathname, bkpath, ent->name)) {
1520 1472 MOD_LOG(params, "Error: path too long.\n");
1521 1473 rv = -1;
1522 1474 break;
1523 1475 }
1524 1476
|
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
1525 1477 /* Make a copy of the new string and save it in ent->name. */
1526 1478 cp = strdup(pathname);
1527 1479 if (cp == NULL) {
1528 1480 MOD_LOG(params, "Error: insufficient memory.\n");
1529 1481 rv = -1;
1530 1482 break;
1531 1483 }
1532 1484 free(ent->name);
1533 1485 ent->name = cp;
1534 1486
1535 - NDMP_LOG(LOG_DEBUG,
1487 + syslog(LOG_DEBUG,
1536 1488 "New: ent[%d].name: \"%s\"", i, ent->name);
1537 1489 }
1538 1490
1539 1491 free(pathname);
1540 1492 return (rv);
1541 1493 }
1542 1494
1543 1495
1544 1496 /*
1545 1497 * check_restore_paths
1546 1498 *
1547 1499 * Go through the restore list and check the validity of the
|
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
1548 1500 * restore path.
1549 1501 */
1550 1502 static int
1551 1503 check_restore_paths(ndmpd_module_params_t *params, int n, char *rspath)
1552 1504 {
1553 1505 int i, rv;
1554 1506 ndmp_name *ent;
1555 1507
1556 1508 rv = 0;
1557 1509 if (rspath != NULL && *rspath != '\0') {
1558 - NDMP_LOG(LOG_DEBUG, "rspath: \"%s\"", rspath);
1510 + syslog(LOG_DEBUG, "rspath: \"%s\"", rspath);
1559 1511 if (!fs_volexist(rspath)) {
1560 1512 MOD_LOG(params,
1561 1513 "Error: Invalid volume name for restore.");
1562 1514 rv = -1;
1563 1515 }
1564 1516 } else {
1565 1517 for (i = 0; i < n; i++) {
1566 1518 ent = (ndmp_name *)MOD_GETNAME(params, i);
1567 - NDMP_LOG(LOG_DEBUG,
1519 + syslog(LOG_DEBUG,
1568 1520 "ent[%d].name: \"%s\"", i, ent->name);
1569 1521
1570 1522 if (!fs_volexist(ent->name)) {
1571 1523 MOD_LOG(params,
1572 1524 "Error: Invalid volume name for restore.",
1573 1525 ent->name);
1574 1526 rv = -1;
1575 1527 break;
1576 1528 }
1577 1529 }
1578 1530 }
1579 1531
1580 1532 return (rv);
1581 1533 }
1582 1534
1583 1535
1584 1536 /*
1585 1537 * check_backup_dir_validity
1586 1538 *
1587 1539 * Check if the backup directory is valid. Make sure it exists and
1588 1540 * is writable. Check for snapshot and readonly cases.
1589 1541 */
1590 1542 static int
1591 1543 check_backup_dir_validity(ndmpd_module_params_t *params, char *bkpath)
1592 1544 {
1593 1545 char *msg;
1594 1546 int rv;
1595 1547 struct stat64 st;
1596 1548
1597 1549 rv = NDMP_NO_ERR;
1598 1550 if (stat64(bkpath, &st) < 0) {
1599 1551 msg = strerror(errno);
1600 1552 MOD_LOG(params, "Error: stat(%s): %s.\n", bkpath, msg);
1601 1553 rv = NDMP_ILLEGAL_ARGS_ERR;
1602 1554 } else if (!S_ISDIR(st.st_mode)) {
1603 1555 MOD_LOG(params, "Error: %s is not a directory.\n", bkpath);
1604 1556 rv = NDMP_ILLEGAL_ARGS_ERR;
1605 1557 } else if (fs_is_rdonly(bkpath) && !fs_is_chkpntvol(bkpath) &&
1606 1558 fs_is_chkpnt_enabled(bkpath)) {
1607 1559 MOD_LOG(params, "Error: %s is not a checkpointed path.\n",
1608 1560 bkpath);
1609 1561 rv = NDMP_BAD_FILE_ERR;
1610 1562 }
1611 1563
1612 1564 return (rv);
1613 1565 }
1614 1566
1615 1567
1616 1568 /*
1617 1569 * ndmp_backup_extract_params
1618 1570 *
1619 1571 * Go through the backup parameters and check the validity
1620 1572 * for each one. Then set the NLP flags according to the parameters.
1621 1573 */
1622 1574 int
1623 1575 ndmp_backup_extract_params(ndmpd_session_t *session,
1624 1576 ndmpd_module_params_t *params)
1625 1577 {
1626 1578 char *cp;
1627 1579 int rv;
1628 1580 ndmp_lbr_params_t *nlp;
1629 1581
1630 1582 /* Extract directory to be backed up from env variables */
1631 1583 if ((nlp = ndmp_get_nlp(session)) == NULL) {
1632 1584 MOD_LOG(params, "Error: Internal error: nlp == NULL.\n");
1633 1585 return (NDMP_ILLEGAL_ARGS_ERR);
|
↓ open down ↓ |
56 lines elided |
↑ open up ↑ |
1634 1586 }
1635 1587 if ((nlp->nlp_backup_path = get_backup_path_v2(params)) == NULL)
1636 1588 return (NDMP_FILE_NOT_FOUND_ERR);
1637 1589
1638 1590 if ((rv = check_backup_dir_validity(params,
1639 1591 nlp->nlp_backup_path)) != NDMP_NO_ERR)
1640 1592 return (rv);
1641 1593
1642 1594 /* Should the st_ctime be ignored when backing up? */
1643 1595 if (ndmp_ignore_ctime) {
1644 - NDMP_LOG(LOG_DEBUG, "ignoring st_ctime");
1596 + syslog(LOG_DEBUG, "ignoring st_ctime");
1645 1597 NLP_SET(nlp, NLPF_IGNCTIME);
1646 1598 } else
1647 1599 NLP_UNSET(nlp, NLPF_IGNCTIME);
1648 1600
1649 1601 /* Should the st_lmtime be ignored when backing up? */
1650 1602 if (ndmp_include_lmtime) {
1651 - NDMP_LOG(LOG_DEBUG, "including st_lmtime");
1603 + syslog(LOG_DEBUG, "including st_lmtime");
1652 1604 NLP_SET(nlp, NLPF_INCLMTIME);
1653 1605 } else
1654 1606 NLP_UNSET(nlp, NLPF_INCLMTIME);
1655 1607
1656 - NDMP_LOG(LOG_DEBUG, "flags %x", nlp->nlp_flags);
1608 + syslog(LOG_DEBUG, "flags %x", nlp->nlp_flags);
1657 1609
1658 1610 /* Is backup history requested? */
1659 1611 cp = MOD_GETENV(params, "HIST");
1660 1612 if (cp == NULL) {
1661 - NDMP_LOG(LOG_DEBUG, "env(HIST) not specified");
1613 + syslog(LOG_DEBUG, "env(HIST) not specified");
1662 1614 NLP_UNSET(nlp, NLPF_FH);
1663 1615 } else {
1664 - NDMP_LOG(LOG_DEBUG, "env(HIST): \"%s\"", cp);
1616 + syslog(LOG_DEBUG, "env(HIST): \"%s\"", cp);
1665 1617
1666 1618 if (strchr("t_ty_y", *cp))
1667 1619 NLP_SET(nlp, NLPF_FH);
1668 1620 else
1669 1621 NLP_UNSET(nlp, NLPF_FH);
1670 1622 }
1671 1623
1672 1624 nlp->nlp_clevel = 0;
1673 1625 /* Is it an incremental backup? */
1674 1626 cp = MOD_GETENV(params, "LEVEL");
1675 1627 if (cp == NULL) {
1676 - NDMP_LOG(LOG_DEBUG,
1628 + syslog(LOG_DEBUG,
1677 1629 "env(LEVEL) not specified, default to 0");
1678 1630 } else if (*cp < '0' || *cp > '9' || *(cp+1) != '\0') {
1679 - NDMP_LOG(LOG_DEBUG, "Invalid backup level '%s'", cp);
1631 + syslog(LOG_DEBUG, "Invalid backup level '%s'", cp);
1680 1632 return (NDMP_ILLEGAL_ARGS_ERR);
1681 1633 } else
1682 1634 nlp->nlp_clevel = *cp - '0';
1683 1635
1684 1636 /* Extract last backup time from the dumpdates file */
1685 1637 nlp->nlp_llevel = nlp->nlp_clevel;
1686 1638 nlp->nlp_ldate = 0;
1687 1639 if (ndmpd_get_dumptime(nlp->nlp_backup_path, &nlp->nlp_llevel,
1688 1640 &nlp->nlp_ldate) < 0) {
1689 1641 MOD_LOG(params, "Error: getting dumpdate for %s level %d\n",
1690 1642 nlp->nlp_backup_path, nlp->nlp_clevel);
1691 1643 return (NDMP_NO_MEM_ERR);
1692 1644 }
1693 1645
1694 - NDMP_LOG(LOG_DEBUG,
1646 + syslog(LOG_DEBUG,
1695 1647 "Date of this level %d on \"%s\": %s",
1696 1648 nlp->nlp_clevel, nlp->nlp_backup_path, cctime(&nlp->nlp_cdate));
1697 - NDMP_LOG(LOG_DEBUG,
1649 + syslog(LOG_DEBUG,
1698 1650 "Date of last level %d on \"%s\": %s",
1699 1651 nlp->nlp_llevel, nlp->nlp_backup_path, cctime(&nlp->nlp_ldate));
1700 1652
1701 1653 /* Should the dumpdate file be updated? */
1702 1654 cp = MOD_GETENV(params, "UPDATE");
1703 1655 if (cp == NULL) {
1704 - NDMP_LOG(LOG_DEBUG,
1656 + syslog(LOG_DEBUG,
1705 1657 "env(UPDATE) not specified, default to TRUE");
1706 1658 NLP_SET(nlp, NLPF_UPDATE);
1707 1659 } else {
1708 - NDMP_LOG(LOG_DEBUG, "env(UPDATE): \"%s\"", cp);
1660 + syslog(LOG_DEBUG, "env(UPDATE): \"%s\"", cp);
1709 1661 if (strchr("t_ty_y", *cp) != NULL)
1710 1662 NLP_SET(nlp, NLPF_UPDATE);
1711 1663 else
1712 1664 NLP_UNSET(nlp, NLPF_UPDATE);
1713 1665 }
1714 1666
1715 1667 return (NDMP_NO_ERR);
1716 1668 }
1717 1669
1718 1670
1719 1671
1720 1672 /*
1721 1673 * log_bk_params_v2
1722 1674 *
1723 1675 * Dump the value of the parameters in the log file for debugging.
1724 1676 */
1725 1677 void
1726 1678 log_bk_params_v2(ndmpd_session_t *session, ndmpd_module_params_t *params,
1727 1679 ndmp_lbr_params_t *nlp)
1728 1680 {
1729 1681 MOD_LOG(params, "Date of this level %d on \"%s\": %s\n",
1730 1682 nlp->nlp_clevel, nlp->nlp_backup_path, cctime(&nlp->nlp_cdate));
1731 1683 MOD_LOG(params, "Date of last level %d on \"%s\": %s\n",
1732 1684 nlp->nlp_llevel, nlp->nlp_backup_path, cctime(&nlp->nlp_ldate));
1733 1685
1734 1686 MOD_LOG(params, "Backing up: \"%s\".\n", nlp->nlp_backup_path);
1735 1687 MOD_LOG(params, "Record size: %d\n", session->ns_mover.md_record_size);
1736 1688 MOD_LOG(params, "File history: %c.\n",
1737 1689 NDMP_YORN(NLP_ISSET(nlp, NLPF_FH)));
1738 1690 MOD_LOG(params, "Update: %s\n",
1739 1691 NLP_ISSET(nlp, NLPF_UPDATE) ? "TRUE" : "FALSE");
1740 1692
1741 1693 }
1742 1694
1743 1695
1744 1696 /*
1745 1697 * same_path
1746 1698 *
1747 1699 * Find out if the paths are the same regardless of the ending slash
1748 1700 *
1749 1701 * Examples :
1750 1702 * /a/b/c == /a/b/c
1751 1703 * /a/b/c/ == /a/b/c
1752 1704 * /a/b/c == /a/b/c/
1753 1705 */
1754 1706 static boolean_t
1755 1707 same_path(char *s, char *t)
1756 1708 {
1757 1709 boolean_t rv;
1758 1710 int slen, tlen;
1759 1711
1760 1712 rv = FALSE;
1761 1713 slen = strlen(s);
1762 1714 tlen = strlen(t);
1763 1715 if (slen == tlen && strcmp(s, t) == 0) {
1764 1716 rv = TRUE;
|
↓ open down ↓ |
46 lines elided |
↑ open up ↑ |
1765 1717 } else {
1766 1718 if (slen == tlen - 1) {
1767 1719 if (strncmp(s, t, slen) == 0 && t[tlen - 1] == '/')
1768 1720 rv = TRUE;
1769 1721 } else if (tlen == slen -1) {
1770 1722 if (strncmp(s, t, tlen) == 0 && s[slen - 1] == '/')
1771 1723 rv = TRUE;
1772 1724 }
1773 1725 }
1774 1726
1775 - NDMP_LOG(LOG_DEBUG, "rv: %d", rv);
1727 + syslog(LOG_DEBUG, "rv: %d", rv);
1776 1728 return (rv);
1777 1729 }
1778 1730
1779 1731
1780 1732 /*
1781 1733 * ndmp_restore_extract_params
1782 1734 *
1783 1735 * Go through the restore parameters and check them and extract them
1784 1736 * by setting NLP flags and other values.
1785 1737 *
1786 1738 * Parameters:
1787 1739 *
1788 1740 * Returns:
1789 1741 * 0: on success
|
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
1790 1742 * -1: otherwise
1791 1743 */
1792 1744 int
1793 1745 ndmp_restore_extract_params(ndmpd_session_t *session,
1794 1746 ndmpd_module_params_t *params)
1795 1747 {
1796 1748 char *bkpath, *rspath;
1797 1749 ndmp_lbr_params_t *nlp;
1798 1750
1799 1751 if ((nlp = ndmp_get_nlp(session)) == NULL) {
1800 - NDMP_LOG(LOG_DEBUG, "nlp == NULL");
1801 1752 return (-1);
1802 1753 }
1803 1754
1804 1755 /* Extract directory from where the backup was made. */
1805 1756 if ((bkpath = get_backup_path_v2(params)) == NULL)
1806 1757 return (NDMP_ILLEGAL_ARGS_ERR);
1807 1758
1808 1759 nlp->nlp_restore_bk_path = bkpath;
1809 1760
1810 1761 /* The number of the selections. */
1811 1762 if ((nlp->nlp_nfiles = get_nfiles(session, params)) == 0)
1812 1763 return (NDMP_ILLEGAL_ARGS_ERR);
1813 1764
1814 - NDMP_LOG(LOG_DEBUG, "nfiles: %d", nlp->nlp_nfiles);
1765 + syslog(LOG_DEBUG, "nfiles: %d", nlp->nlp_nfiles);
1815 1766
1816 1767 if ((rspath = get_restore_dest(params)) == NULL)
1817 1768 return (NDMP_ILLEGAL_ARGS_ERR);
1818 1769
1819 1770 if (fs_is_rdonly(rspath)) {
1820 1771 MOD_LOG(params,
1821 1772 "Error: Can't restore to a read-only volume: \"%s\"\n",
1822 1773 rspath);
1823 1774 return (NDMP_ILLEGAL_ARGS_ERR);
1824 1775 }
1825 1776 if (fs_is_chkpntvol(rspath)) {
1826 1777 MOD_LOG(params,
1827 1778 "Error: Can't restore to a checkpoint: \"%s\"\n", rspath);
1828 1779 return (NDMP_ILLEGAL_ARGS_ERR);
1829 1780 }
1830 1781
1831 1782 if (same_path(bkpath, rspath))
1832 1783 rspath = "";
1833 1784
1834 1785 if ((nlp->nlp_restore_path = strdup(rspath)) == NULL)
1835 1786 return (NDMP_NO_MEM_ERR);
1836 1787
1837 1788 bkpath = trim_name(bkpath);
1838 1789 if (correct_ents(params, nlp->nlp_nfiles, bkpath) < 0) {
1839 1790 free(nlp->nlp_restore_path);
1840 1791 return (NDMP_ILLEGAL_ARGS_ERR);
1841 1792 }
1842 1793
1843 1794 if (check_restore_paths(params, nlp->nlp_nfiles, rspath) < 0) {
1844 1795 free(nlp->nlp_restore_path);
1845 1796 return (NDMP_ILLEGAL_ARGS_ERR);
1846 1797 }
1847 1798
1848 1799 MOD_LOG(params, "Restoring %d files.\n", nlp->nlp_nfiles);
1849 1800 MOD_LOG(params, "Restoring to: \"%s\".\n", nlp->nlp_restore_path);
1850 1801 MOD_LOG(params, "Record size: %d\n", session->ns_mover.md_record_size);
1851 1802
1852 1803 return (NDMP_NO_ERR);
1853 1804 }
1854 1805
1855 1806 /*
1856 1807 * ndmpd_tar_backup_starter (V2 only)
1857 1808 *
1858 1809 * The main backup starter function. It creates a snapshot if necessary
1859 1810 * and calls ndmp_tar_backup to perform the actual backup. It does the cleanup
1860 1811 * and release the snapshot at the end.
1861 1812 */
1862 1813 int
1863 1814 ndmpd_tar_backup_starter(void *arg)
1864 1815 {
1865 1816 ndmpd_module_params_t *mod_params = arg;
1866 1817 int err;
1867 1818 ndmpd_session_t *session;
1868 1819 ndmp_lbr_params_t *nlp;
1869 1820
1870 1821 session = (ndmpd_session_t *)(mod_params->mp_daemon_cookie);
|
↓ open down ↓ |
46 lines elided |
↑ open up ↑ |
1871 1822 *(mod_params->mp_module_cookie) = nlp = ndmp_get_nlp(session);
1872 1823 ndmp_session_ref(session);
1873 1824
1874 1825 err = 0;
1875 1826 if (fs_is_chkpntvol(nlp->nlp_backup_path) ||
1876 1827 fs_is_rdonly(nlp->nlp_backup_path) ||
1877 1828 !fs_is_chkpnt_enabled(nlp->nlp_backup_path))
1878 1829 NLP_SET(nlp, NLPF_CHKPNTED_PATH);
1879 1830 else {
1880 1831 NLP_UNSET(nlp, NLPF_CHKPNTED_PATH);
1881 - if (ndmp_create_snapshot(nlp->nlp_backup_path,
1882 - nlp->nlp_jstat->js_job_name) < 0) {
1832 + if (backup_dataset_create(nlp) < 0) {
1883 1833 MOD_LOG(mod_params,
1884 1834 "Error: creating checkpoint on %s\n",
1885 1835 nlp->nlp_backup_path);
1886 1836 /* -1 causes halt reason to become internal error. */
1887 1837 err = -1;
1888 1838 }
1889 1839 }
1890 1840
1891 - NDMP_LOG(LOG_DEBUG, "NLPF_CHKPNTED_PATH: %c",
1841 + syslog(LOG_DEBUG, "NLPF_CHKPNTED_PATH: %c",
1892 1842 NDMP_YORN(NLP_ISCHKPNTED(nlp)));
1893 - NDMP_LOG(LOG_DEBUG, "err: %d, update %c",
1843 + syslog(LOG_DEBUG, "err: %d, update %c",
1894 1844 err, NDMP_YORN(NLP_SHOULD_UPDATE(nlp)));
1895 1845
1896 1846 if (err == 0) {
1897 - err = ndmp_get_cur_bk_time(nlp, &nlp->nlp_cdate,
1898 - nlp->nlp_jstat->js_job_name);
1847 + err = ndmp_get_cur_bk_time(nlp, &nlp->nlp_cdate);
1899 1848 if (err != 0) {
1900 - NDMP_LOG(LOG_DEBUG, "err %d", err);
1849 + syslog(LOG_DEBUG, "err %d", err);
1901 1850 } else {
1902 1851 log_bk_params_v2(session, mod_params, nlp);
1903 1852 err = ndmpd_tar_backup(session, mod_params, nlp);
1904 1853 }
1905 1854 }
1906 1855
1907 1856 if (nlp->nlp_bkmap >= 0) {
1908 1857 (void) dbm_free(nlp->nlp_bkmap);
1909 1858 nlp->nlp_bkmap = -1;
1910 1859 }
1911 1860
1912 1861 if (!NLP_ISCHKPNTED(nlp))
1913 - (void) ndmp_remove_snapshot(nlp->nlp_backup_path,
1914 - nlp->nlp_jstat->js_job_name);
1862 + (void) backup_dataset_destroy(nlp);
1915 1863
1916 - NDMP_LOG(LOG_DEBUG, "err %d, update %c",
1864 + syslog(LOG_DEBUG, "err %d, update %c",
1917 1865 err, NDMP_YORN(NLP_SHOULD_UPDATE(nlp)));
1918 1866
1919 1867 if (err == 0 && NLP_SHOULD_UPDATE(nlp)) {
1920 1868 if (ndmpd_put_dumptime(nlp->nlp_backup_path, nlp->nlp_clevel,
1921 1869 nlp->nlp_cdate) < 0) {
1922 1870 err = EPERM;
1923 1871 MOD_LOG(mod_params,
1924 1872 "Error: updating the dumpdates file on %s\n",
1925 1873 nlp->nlp_backup_path);
1926 1874 }
1927 1875 }
1928 1876
1929 1877 MOD_DONE(mod_params, err);
1930 1878
1931 1879 /* nlp_params is allocated in start_backup() */
1932 1880 NDMP_FREE(nlp->nlp_params);
1933 1881
1934 1882 NS_DEC(nbk);
1935 1883 ndmp_session_unref(session);
1936 1884 return (err);
1937 1885 }
1938 1886
1939 1887
1940 1888 /*
1941 1889 * ndmpd_tar_backup_abort
1942 1890 *
1943 1891 * Abort the running backup by stopping the reader thread (V2 only)
1944 1892 */
1945 1893 int
1946 1894 ndmpd_tar_backup_abort(void *module_cookie)
1947 1895 {
1948 1896 ndmp_lbr_params_t *nlp;
1949 1897
1950 1898 nlp = (ndmp_lbr_params_t *)module_cookie;
1951 1899 if (nlp != NULL && nlp->nlp_session != NULL) {
1952 1900 if (nlp->nlp_session->ns_data.dd_mover.addr_type ==
1953 1901 NDMP_ADDR_TCP && nlp->nlp_session->ns_data.dd_sock != -1) {
1954 1902 (void) close(nlp->nlp_session->ns_data.dd_sock);
1955 1903 nlp->nlp_session->ns_data.dd_sock = -1;
1956 1904 }
1957 1905 ndmp_stop_reader_thread(nlp->nlp_session);
1958 1906 }
1959 1907
1960 1908 return (0);
1961 1909 }
1962 1910
1963 1911 /*
1964 1912 * ndmpd_tar_restore_starter
1965 1913 *
1966 1914 * Starts the restore by running ndmpd_tar_restore function (V2 only)
1967 1915 */
1968 1916
1969 1917 int
1970 1918 ndmpd_tar_restore_starter(void *arg)
1971 1919 {
1972 1920 ndmpd_module_params_t *mod_params = arg;
1973 1921 int err;
1974 1922 ndmpd_session_t *session;
1975 1923 ndmp_lbr_params_t *nlp;
1976 1924
1977 1925 session = (ndmpd_session_t *)(mod_params->mp_daemon_cookie);
1978 1926 *(mod_params->mp_module_cookie) = nlp = ndmp_get_nlp(session);
1979 1927 ndmp_session_ref(session);
1980 1928
1981 1929 err = ndmpd_tar_restore(session, mod_params, nlp);
1982 1930 MOD_DONE(mod_params, err);
1983 1931
1984 1932 /* nlp_params is allocated in start_recover() */
1985 1933 NDMP_FREE(nlp->nlp_params);
1986 1934
1987 1935 NS_DEC(nrs);
1988 1936 ndmp_session_unref(session);
1989 1937 return (err);
1990 1938 }
1991 1939
1992 1940
1993 1941 /*
1994 1942 * ndmpd_tar_restore_abort
1995 1943 *
1996 1944 * Aborts the restore operation by stopping the writer thread (V2 only)
1997 1945 */
1998 1946 int
1999 1947 ndmpd_tar_restore_abort(void *module_cookie)
2000 1948 {
2001 1949 ndmp_lbr_params_t *nlp;
2002 1950
2003 1951 nlp = (ndmp_lbr_params_t *)module_cookie;
2004 1952 if (nlp != NULL && nlp->nlp_session != NULL) {
2005 1953 (void) mutex_lock(&nlp->nlp_mtx);
2006 1954 if (nlp->nlp_session->ns_data.dd_mover.addr_type ==
2007 1955 NDMP_ADDR_TCP && nlp->nlp_session->ns_data.dd_sock != -1) {
2008 1956 (void) close(nlp->nlp_session->ns_data.dd_sock);
2009 1957 nlp->nlp_session->ns_data.dd_sock = -1;
2010 1958 }
2011 1959 (void) cond_broadcast(&nlp->nlp_cv);
2012 1960 (void) mutex_unlock(&nlp->nlp_mtx);
2013 1961 ndmp_stop_writer_thread(nlp->nlp_session);
2014 1962 }
2015 1963
2016 1964 return (0);
2017 1965 }
|
↓ open down ↓ |
91 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX