Print this page
NEX-15119 Commvault Certification fail incremental backup
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
NEX-15119 Commvault Certification fail incremental backup
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
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-2911 NDMP logging should use syslog and is too chatty
SUP-898 nscd is extremely slow when a local file is missing
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Josef Sipek <josef.sipek@nexenta.com>
NEX-2500 Conflict between NDMP backup job and 'zfs send' leads to NDMP job abort.
NEX-2492 mdb loops forever printing a stack backtrace
NEX-2430 ndmpd segfaults in get_backup_size+0x13b() lint fix
NEX-2430 ndmpd segfaults in get_backup_size+0x13b()
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_tar3.c
+++ new/usr/src/cmd/ndmpd/ndmp/ndmpd_tar3.c
1 1 /*
2 2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
3 3 */
4 4
5 5 /*
6 6 * BSD 3 Clause License
7 7 *
8 8 * Copyright (c) 2007, The Storage Networking Industry Association.
9 9 *
10 10 * Redistribution and use in source and binary forms, with or without
11 11 * modification, are permitted provided that the following conditions
12 12 * are met:
13 13 * - Redistributions of source code must retain the above copyright
14 14 * notice, this list of conditions and the following disclaimer.
15 15 *
16 16 * - Redistributions in binary form must reproduce the above copyright
17 17 * notice, this list of conditions and the following disclaimer in
18 18 * the documentation and/or other materials provided with the
19 19 * distribution.
20 20 *
21 21 * - Neither the name of The Storage Networking Industry Association (SNIA)
22 22 * nor the names of its contributors may be used to endorse or promote
23 23 * products derived from this software without specific prior written
24 24 * permission.
25 25 *
26 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
↓ open down ↓ |
29 lines elided |
↑ open up ↑ |
30 30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 36 * POSSIBILITY OF SUCH DAMAGE.
37 37 */
38 38 /* Copyright (c) 2007, The Storage Networking Industry Association. */
39 39 /* Copyright (c) 1996, 1997 PDC, Network Appliance. All Rights Reserved */
40 -/* Copyright 2014 Nexenta Systems, Inc. All rights reserved. */
40 +/* Copyright 2017 Nexenta Systems, Inc. All rights reserved. */
41 41
42 42 #include <sys/stat.h>
43 43 #include <sys/types.h>
44 44 #include <sys/time.h>
45 +#include <syslog.h>
45 46 #include <ctype.h>
46 47 #include <sys/socket.h>
47 48 #include <sys/acl.h>
48 49 #include <netinet/in.h>
49 50 #include <arpa/inet.h>
50 51 #include <errno.h>
51 52 #include <stdio.h>
52 53 #include <string.h>
53 54 #include <time.h>
54 55 #include <cstack.h>
55 56 #include "ndmp.h"
56 57 #include "ndmpd.h"
57 58 #include <bitmap.h>
58 59 #include <traverse.h>
59 60
60 61
61 62 /*
62 63 * Maximum length of the string-representation of u_longlong_t type.
63 64 */
64 65 #define QUAD_DECIMAL_LEN 20
65 66
66 67
67 68 /* Is Y=yes or T=true */
68 69 #define IS_YORT(c) (strchr("YT", toupper(c)))
69 70
70 71 /* Is F=file format (vs D=node-dir format) */
71 72 #define IS_F(c) (toupper(c) == 'F')
72 73
73 74 /*
74 75 * If path is defined.
75 76 */
76 77 #define ISDEFINED(cp) ((cp) && *(cp))
77 78 #define SHOULD_LBRBK(bpp) (!((bpp)->bp_opr & TLM_OP_CHOOSE_ARCHIVE))
78 79
79 80 /*
80 81 * Component boundary means end of path or on a '/'. At this
81 82 * point both paths should be on component boundary.
82 83 */
83 84 #define COMPBNDRY(p) (!*(p) || (*p) == '/')
84 85
85 86 typedef struct bk_param_v3 {
86 87 ndmpd_session_t *bp_session;
87 88 ndmp_lbr_params_t *bp_nlp;
88 89 tlm_job_stats_t *bp_js;
89 90 tlm_cmd_t *bp_lcmd;
90 91 tlm_commands_t *bp_cmds;
91 92 tlm_acls_t *bp_tlmacl;
92 93 int bp_opr;
93 94 char *bp_tmp;
94 95 char *bp_chkpnm;
95 96 char **bp_excls;
96 97 char *bp_unchkpnm;
97 98 } bk_param_v3_t;
98 99
99 100
100 101 /*
101 102 * Multiple destination restore mode
102 103 */
103 104 #define MULTIPLE_DEST_DIRS 128
104 105
105 106 int multiple_dest_restore = 0;
106 107
|
↓ open down ↓ |
52 lines elided |
↑ open up ↑ |
107 108 /*
108 109 * Plug-in module ops
109 110 */
110 111 ndmp_plugin_t *ndmp_pl;
111 112
112 113 /*
113 114 * NDMP exclusion list
114 115 */
115 116 char **ndmp_excl_list = NULL;
116 117
118 +extern boolean_t fs_is_checkpointed(ndmp_lbr_params_t *);
119 +
117 120 /*
118 121 * split_env
119 122 *
120 123 * Splits the string into list of sections separated by the
121 124 * sep character.
122 125 *
123 126 * Parameters:
124 127 * envp (input) - the environment variable that should be broken
125 128 * sep (input) - the separator character
126 129 *
127 130 * Returns:
128 131 * Array of character pointers: On success. The array is allocated
129 132 * as well as all its entries. They all should be freed by the
130 133 * caller.
131 134 * NULL: on error
132 135 */
133 136 static char **
134 137 split_env(char *envp, char sep)
135 138 {
136 139 char *bp, *cp, *ep;
137 140 char *save;
138 141 char **cpp;
139 142 int n;
140 143
141 144 if (!envp)
142 145 return (NULL);
143 146
144 147 while (isspace(*envp))
145 148 envp++;
146 149
147 150 if (!*envp)
148 151 return (NULL);
149 152
150 153 bp = save = strdup(envp);
151 154 if (!bp)
152 155 return (NULL);
153 156
154 157 /*
155 158 * Since the env variable is not empty, it contains at least one
156 159 * component
157 160 */
158 161 n = 1;
159 162 while ((cp = strchr(bp, sep))) {
160 163 if (cp > save && *(cp-1) != '\\')
161 164 n++;
162 165
163 166 bp = cp + 1;
164 167 }
165 168
166 169 n++; /* for the terminating NULL pointer */
167 170 cpp = ndmp_malloc(sizeof (char *) * n);
168 171 if (!cpp) {
169 172 free(save);
170 173 return (NULL);
171 174 }
172 175
173 176 (void) memset(cpp, 0, n * sizeof (char *));
174 177 n = 0;
175 178 cp = bp = ep = save;
176 179 while (*cp)
177 180 if (*cp == sep) {
178 181 *ep = '\0';
179 182 if (strlen(bp) > 0) {
180 183 cpp[n] = strdup(bp);
181 184 if (!cpp[n++]) {
182 185 tlm_release_list(cpp);
183 186 cpp = NULL;
184 187 break;
185 188 }
186 189 }
187 190 ep = bp = ++cp;
188 191 } else if (*cp == '\\') {
189 192 ++cp;
190 193 if (*cp == 'n') { /* "\n" */
191 194 *ep++ = '\n';
192 195 cp++;
193 196 } else if (*cp == 't') { /* "\t" */
194 197 *ep++ = '\t';
195 198 cp++;
196 199 } else
197 200 *ep++ = *cp++;
198 201 } else
199 202 *ep++ = *cp++;
200 203
201 204 *ep = '\0';
202 205 if (cpp) {
203 206 if (strlen(bp) > 0) {
204 207 cpp[n] = strdup(bp);
205 208 if (!cpp[n++]) {
206 209 tlm_release_list(cpp);
207 210 cpp = NULL;
208 211 } else
209 212 cpp[n] = NULL;
210 213 }
211 214
212 215 if (n == 0 && cpp != NULL) {
213 216 tlm_release_list(cpp);
214 217 cpp = NULL;
215 218 }
216 219 }
217 220
218 221 free(save);
219 222 return (cpp);
220 223 }
221 224
222 225
223 226 /*
224 227 * prl
225 228 *
226 229 * Print the array of character pointers passed to it. This is
227 230 * used for debugging purpose.
228 231 *
|
↓ open down ↓ |
102 lines elided |
↑ open up ↑ |
229 232 * Parameters:
230 233 * lpp (input) - pointer to the array of strings
231 234 *
232 235 * Returns:
233 236 * void
234 237 */
235 238 static void
236 239 prl(char **lpp)
237 240 {
238 241 if (!lpp) {
239 - NDMP_LOG(LOG_DEBUG, "empty");
242 + syslog(LOG_DEBUG, "empty");
240 243 return;
241 244 }
242 245
243 246 while (*lpp)
244 - NDMP_LOG(LOG_DEBUG, "\"%s\"", *lpp++);
247 + syslog(LOG_DEBUG, "\"%s\"", *lpp++);
245 248 }
246 249
247 250
248 251 /*
249 252 * inlist
250 253 *
251 254 * Looks through all the strings of the array to see if the ent
252 255 * matches any of the strings. The strings are patterns.
253 256 *
254 257 * Parameters:
255 258 * lpp (input) - pointer to the array of strings
|
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
256 259 * ent (input) - the entry to be matched
257 260 *
258 261 * Returns:
259 262 * TRUE: if there is a match
260 263 * FALSE: invalid argument or no match
261 264 */
262 265 static boolean_t
263 266 inlist(char **lpp, char *ent)
264 267 {
265 268 if (!lpp || !ent) {
266 - NDMP_LOG(LOG_DEBUG, "empty list");
269 + syslog(LOG_DEBUG, "empty list");
267 270 return (FALSE);
268 271 }
269 272
270 273 while (*lpp) {
271 274 /*
272 275 * Fixing the sync_sort NDMPV3 problem, it sends the inclusion
273 276 * like "./" which we should skip the "./"
274 277 */
275 278 char *pattern = *lpp;
276 279 if (strncmp(pattern, "./", 2) == 0)
277 280 pattern += 2;
278 281
279 - NDMP_LOG(LOG_DEBUG, "pattern %s, ent %s", pattern, ent);
282 + syslog(LOG_DEBUG, "pattern %s, ent %s", pattern, ent);
280 283
281 284 if (match(pattern, ent)) {
282 - NDMP_LOG(LOG_DEBUG, "match(%s,%s)", pattern, ent);
285 + syslog(LOG_DEBUG, "match(%s,%s)", pattern, ent);
283 286 return (TRUE);
284 287 }
285 288 lpp++;
286 289 }
287 290
288 - NDMP_LOG(LOG_DEBUG, "no match");
291 + syslog(LOG_DEBUG, "no match");
289 292 return (FALSE);
290 293 }
291 294
292 295
293 296 /*
294 297 * inexl
295 298 *
296 299 * Checks if the entry is in the list. This is used for exclusion
297 300 * list. If the exclusion list is empty, FALSE should be returned
298 301 * showing that nothing should be excluded by default.
299 302 *
300 303 * Parameters:
301 304 * lpp (input) - pointer to the array of strings
302 305 * ent (input) - the entry to be matched
303 306 *
304 307 * Returns:
305 308 * TRUE: if there is a match
306 309 * FALSE: invalid argument or no match
307 310 *
308 311 */
309 312 static boolean_t
310 313 inexl(char **lpp, char *ent)
311 314 {
312 315 if (!lpp || !ent)
313 316 return (FALSE);
314 317
315 318 return (inlist(lpp, ent));
316 319 }
317 320
318 321
319 322 /*
320 323 * ininc
321 324 *
322 325 * Checks if the entry is in the list. This is used for inclusion
323 326 * list. If the inclusion list is empty, TRUE should be returned
324 327 * showing that everything should be included by default.
325 328 *
326 329 * Parameters:
327 330 * lpp (input) - pointer to the array of strings
328 331 * ent (input) - the entry to be matched
329 332 *
330 333 * Returns:
331 334 * TRUE: if there is a match or the list is empty
332 335 * FALSE: no match
333 336 */
334 337 static boolean_t
335 338 ininc(char **lpp, char *ent)
336 339 {
337 340 if (!lpp || !ent || !*ent)
338 341 return (TRUE);
339 342
340 343 return (inlist(lpp, ent));
341 344 }
342 345
343 346
344 347 /*
345 348 * setupsels
346 349 *
347 350 * Set up the selection list for Local B/R functions. A new array of
348 351 * "char *" is created and the pointers point to the original paths of
349 352 * the Nlist.
350 353 *
351 354 * Parameters:
352 355 * session (input) - pointer to the session
353 356 * params (input) - pointer to the parameters structure
354 357 * nlp (input) - pointer to the nlp structure
355 358 * index(input) - If not zero is the DAR entry position
356 359 *
357 360 * Returns:
358 361 * list pointer: on success
359 362 * NULL: on error
360 363 */
361 364 /*ARGSUSED*/
362 365 char **
363 366 setupsels(ndmpd_session_t *session, ndmpd_module_params_t *params,
364 367 ndmp_lbr_params_t *nlp, int index)
365 368 {
366 369 char **lpp, **save;
367 370 int i, n;
368 371 int len;
369 372 int start, end;
370 373 mem_ndmp_name_v3_t *ep;
371 374
372 375 n = session->ns_data.dd_nlist_len;
373 376
374 377 save = lpp = ndmp_malloc(sizeof (char *) * (n + 1));
375 378 if (!lpp) {
376 379 MOD_LOGV3(params, NDMP_LOG_ERROR, "Insufficient memory.\n");
377 380 return (NULL);
378 381 }
379 382
380 383 if (index) { /* DAR, just one entry */
381 384 /*
382 385 * We have to setup a list of strings that will not match any
383 386 * file. One DAR entry will be added in the right position later
384 387 * in this function.
385 388 * When the match is called from tar_getdir the
386 389 * location of the selection that matches the entry is
387 390 * important
388 391 */
389 392 for (i = 0; i < n; ++i)
390 393 *(lpp+i) = " ";
391 394 n = 1;
392 395 start = index-1;
393 396 end = start+1;
394 397 lpp += start; /* Next selection entry will be in lpp[start] */
395 398 } else {
396 399 start = 0;
397 400 end = n;
398 401 }
399 402
400 403 for (i = start; i < end; i++) {
401 404 ep = (mem_ndmp_name_v3_t *)MOD_GETNAME(params, i);
402 405 if (!ep)
403 406 continue;
|
↓ open down ↓ |
105 lines elided |
↑ open up ↑ |
404 407
405 408 /*
406 409 * Check for clients that send original path as "."(like
407 410 * CA products). In this situation opath is something like
408 411 * "/v1/." and we should change it to "/v1/"
409 412 */
410 413 len = strlen(ep->nm3_opath);
411 414 if (len > 1 && ep->nm3_opath[len-2] == '/' &&
412 415 ep->nm3_opath[len-1] == '.') {
413 416 ep->nm3_opath[len-1] = '\0';
414 - NDMP_LOG(LOG_DEBUG,
417 + syslog(LOG_DEBUG,
415 418 "nm3_opath changed from %s. to %s",
416 419 ep->nm3_opath, ep->nm3_opath);
417 420 }
418 421 *lpp++ = ep->nm3_opath;
419 422 }
420 423
421 424 /* list termination indicator is a null pointer */
422 425 *lpp = NULL;
423 426
424 427 return (save);
425 428 }
426 429
427 430
428 431 /*
429 432 * mkrsp
430 433 *
431 434 * Make Restore Path.
432 435 * It gets a path, a selection (with which the path has matched) a new
433 436 * name and makes a new name for the path.
434 437 * All the components of the path and the selection are skipped as long
435 438 * as they are the same. If either of the path or selection are not on
436 439 * a component boundary, the match was reported falsefully and no new name
437 440 * is generated(Except the situation in which both path and selection
438 441 * end with trailing '/' and selection is the prefix of the path).
439 442 * Otherwise, the remaining of the path is appended to the
440 443 * new name. The result is saved in the buffer passed.
441 444 *
442 445 * Parameters:
443 446 * bp (output) - pointer to the result buffer
444 447 * pp (input) - pointer to the path
445 448 * sp (input) - pointer to the selection
446 449 * np (input) - pointer to the new name
447 450 *
448 451 * Returns:
449 452 * pointer to the bp: on success
450 453 * NULL: otherwise
451 454 */
452 455 char *
453 456 mkrsp(char *bp, char *pp, char *sp, char *np)
454 457 {
455 458 if (!bp || !pp)
456 459 return (NULL);
457 460
458 461
459 462 pp += strspn(pp, "/");
460 463 if (sp) {
461 464 sp += strspn(sp, "/");
462 465
463 466 /* skip as much as match */
464 467 while (*sp && *pp && *sp == *pp) {
465 468 sp++;
466 469 pp++;
467 470 }
468 471
469 472 if (!COMPBNDRY(pp) || !COMPBNDRY(sp))
470 473 /* An exception to the boundary rule */
471 474 /* (!(!*sp && (*(pp - 1)) == '/')) */
472 475 if (*sp || (*(pp - 1)) != '/')
473 476 return (NULL);
474 477
475 478 /* if pp shorter than sp, it should not be restored */
476 479 if (!*pp && *sp) {
477 480 sp += strspn(sp, "/");
478 481 if (strlen(sp) > 0)
|
↓ open down ↓ |
54 lines elided |
↑ open up ↑ |
479 482 return (NULL);
480 483 }
481 484 }
482 485
483 486 if (np)
484 487 np += strspn(np, "/");
485 488 else
486 489 np = "";
487 490
488 491 if (!tlm_cat_path(bp, np, pp)) {
489 - NDMP_LOG(LOG_ERR, "Restore path too long %s/%s.", np, pp);
492 + syslog(LOG_ERR, "Restore path too long %s/%s.", np, pp);
490 493 return (NULL);
491 494 }
492 495
493 496 return (bp);
494 497 }
495 498
496 499
497 500 /*
498 501 * mknewname
499 502 *
500 503 * This is used as callback for creating the restore path. This function
501 504 * can handle both single destination and multiple restore paths.
502 505 *
503 506 * Make up the restore destination path for a particular file/directory, path,
504 507 * based on nm3_opath and nm3_dpath. path should have matched nm3_opath
505 508 * in some way.
|
↓ open down ↓ |
6 lines elided |
↑ open up ↑ |
506 509 */
507 510 char *
508 511 mknewname(struct rs_name_maker *rnp, char *buf, int idx, char *path)
509 512 {
510 513 char *rv;
511 514 ndmp_lbr_params_t *nlp;
512 515 mem_ndmp_name_v3_t *ep;
513 516
514 517 rv = NULL;
515 518 if (!buf) {
516 - NDMP_LOG(LOG_DEBUG, "buf is NULL");
519 + syslog(LOG_DEBUG, "buf is NULL");
517 520 } else if (!path) {
518 - NDMP_LOG(LOG_DEBUG, "path is NULL");
521 + syslog(LOG_DEBUG, "path is NULL");
519 522 } else if ((nlp = rnp->rn_nlp) == 0) {
520 - NDMP_LOG(LOG_DEBUG, "rnp->rn_nlp is NULL");
523 + syslog(LOG_DEBUG, "rnp->rn_nlp is NULL");
521 524 } else if (!nlp->nlp_params) {
522 - NDMP_LOG(LOG_DEBUG, "nlp->nlp_params is NULL");
525 + syslog(LOG_DEBUG, "nlp->nlp_params is NULL");
523 526 } else
524 527 if (!ndmp_full_restore_path) {
525 528 if (idx < 0 || idx >= (int)nlp->nlp_nfiles) {
526 - NDMP_LOG(LOG_DEBUG,
529 + syslog(LOG_DEBUG,
527 530 "Invalid idx %d range (0, %d)",
528 531 idx, nlp->nlp_nfiles);
529 532 } else if (!(ep = (mem_ndmp_name_v3_t *)MOD_GETNAME(
530 533 nlp->nlp_params, idx))) {
531 - NDMP_LOG(LOG_DEBUG,
534 + syslog(LOG_DEBUG,
532 535 "nlist entry %d is NULL", idx);
533 536 } else {
534 537 rv = mkrsp(buf, path, ep->nm3_opath,
535 538 ep->nm3_dpath);
536 -
537 - NDMP_LOG(LOG_DEBUG,
538 - "idx %d org \"%s\" dst \"%s\"",
539 - idx, ep->nm3_opath, ep->nm3_dpath);
540 - if (rv) {
541 - NDMP_LOG(LOG_DEBUG,
542 - "path \"%s\": \"%s\"", path, rv);
543 - } else {
544 - NDMP_LOG(LOG_DEBUG,
545 - "path \"%s\": NULL", path);
546 - }
547 539 }
548 540 } else {
549 541 if (!tlm_cat_path(buf, nlp->nlp_restore_path, path)) {
550 - NDMP_LOG(LOG_ERR, "Path too long %s/%s.",
542 + syslog(LOG_ERR, "Path too long %s/%s.",
551 543 nlp->nlp_restore_path, path);
552 544 rv = NULL;
553 545 } else {
554 546 rv = buf;
555 - NDMP_LOG(LOG_DEBUG,
556 - "path \"%s\": \"%s\"", path, rv);
557 547 }
558 548 }
559 549
560 550 return (rv);
561 551 }
562 552
563 553
564 554 /*
565 555 * chopslash
566 556 *
567 557 * Remove the slash from the end of the given path
568 558 */
569 559 static void
570 560 chopslash(char *cp)
571 561 {
572 562 int ln;
573 563
574 564 if (!cp || !*cp)
575 565 return;
576 566
577 567 ln = strlen(cp);
578 568 cp += ln - 1; /* end of the string */
579 569 while (ln > 0 && *cp == '/') {
580 570 *cp-- = '\0';
581 571 ln--;
582 572 }
583 573 }
584 574
585 575
586 576 /*
587 577 * joinpath
588 578 *
589 579 * Join two given paths
590 580 */
591 581 static char *
592 582 joinpath(char *bp, char *pp, char *np)
593 583 {
594 584 if (pp && *pp) {
595 585 if (np && *np)
596 586 (void) tlm_cat_path(bp, pp, np);
597 587 else
598 588 (void) strlcpy(bp, pp, TLM_MAX_PATH_NAME);
599 589 } else {
600 590 if (np && *np)
601 591 (void) strlcpy(bp, np, TLM_MAX_PATH_NAME);
602 592 else
603 593 bp = NULL;
604 594 }
605 595
606 596 return (bp);
607 597 }
608 598
609 599
610 600 /*
611 601 * voliswr
612 602 *
613 603 * Is the volume writable?
|
↓ open down ↓ |
47 lines elided |
↑ open up ↑ |
614 604 */
615 605 static int
616 606 voliswr(char *path)
617 607 {
618 608 int rv;
619 609
620 610 if (!path)
621 611 return (0);
622 612
623 613 rv = !fs_is_rdonly(path) && !fs_is_chkpntvol(path);
624 - NDMP_LOG(LOG_DEBUG, "%d path \"%s\"", rv, path);
614 + syslog(LOG_DEBUG, "%d path \"%s\"", rv, path);
625 615 return (rv);
626 616
627 617 }
628 618
629 619
630 620 /*
631 621 * is_valid_backup_dir_v3
632 622 *
633 623 * Checks the validity of the backup path. Backup path should
634 624 * have the following characteristics to be valid:
635 625 * 1) It should be an absolute path.
636 626 * 2) It should be a directory.
637 627 * 3) It should not be checkpoint root directory
638 628 * 4) If the file system is read-only, the backup path
639 629 * should be a checkpointed path. Checkpoint cannot
640 630 * be created on a read-only file system.
641 631 *
642 632 * Parameters:
643 633 * params (input) - pointer to the parameters structure.
644 634 * bkpath (input) - the backup path
645 635 *
646 636 * Returns:
647 637 * TRUE: if everything's OK
648 638 * FALSE: otherwise.
649 639 */
650 640 static boolean_t
651 641 is_valid_backup_dir_v3(ndmpd_module_params_t *params, char *bkpath)
652 642 {
653 643 char *msg;
654 644 struct stat64 st;
655 645
656 646 if (*bkpath != '/') {
657 647 MOD_LOGV3(params, NDMP_LOG_ERROR,
658 648 "Relative backup path not allowed \"%s\".\n", bkpath);
659 649 return (FALSE);
660 650 }
661 651 if (stat64(bkpath, &st) < 0) {
662 652 msg = strerror(errno);
663 653 MOD_LOGV3(params, NDMP_LOG_ERROR, "\"%s\" %s.\n",
664 654 bkpath, msg);
665 655 return (FALSE);
666 656 }
667 657 if (!S_ISDIR(st.st_mode)) {
668 658 /* only directories can be specified as the backup path */
669 659 MOD_LOGV3(params, NDMP_LOG_ERROR,
670 660 "\"%s\" is not a directory.\n", bkpath);
671 661 return (FALSE);
672 662 }
673 663 if (fs_is_rdonly(bkpath) && !fs_is_chkpntvol(bkpath) &&
674 664 fs_is_chkpnt_enabled(bkpath)) {
675 665 /* it is not a chkpnted path */
676 666 MOD_LOGV3(params, NDMP_LOG_ERROR,
677 667 "\"%s\" is not a checkpointed path.\n", bkpath);
678 668 return (FALSE);
679 669 }
680 670
681 671 return (TRUE);
682 672 }
683 673
684 674
685 675 /*
686 676 * log_date_token_v3
687 677 *
688 678 * Log the token sequence number and also the date of the
689 679 * last backup for token-based backup in the system log
690 680 * and also send them as normal log to the client.
691 681 *
692 682 * Parameters:
693 683 * params (input) - pointer to the parameters structure
694 684 * nlp (input) - pointer to the nlp structure
695 685 *
696 686 * Returns:
697 687 * void
698 688 */
699 689 static void
700 690 log_date_token_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp)
701 691 {
702 692 MOD_LOGV3(params, NDMP_LOG_NORMAL, "Token sequence counter: %d.\n",
703 693 nlp->nlp_tokseq);
704 694
705 695 MOD_LOGV3(params, NDMP_LOG_NORMAL, "Date of the last backup: %s.\n",
706 696 cctime(&nlp->nlp_tokdate));
707 697
708 698 if (nlp->nlp_dmpnm) {
709 699 MOD_LOGV3(params, NDMP_LOG_NORMAL,
710 700 "Backup date log file name: \"%s\".\n", nlp->nlp_dmpnm);
711 701 }
712 702 }
713 703
714 704
715 705 /*
716 706 * log_lbr_bk_v3
717 707 *
718 708 * Log the backup level and data of the backup for LBR-type
719 709 * backup in the system log and also send them as normal log
720 710 * to the client.
721 711 *
722 712 * Parameters:
723 713 * params (input) - pointer to the parameters structure
724 714 * nlp (input) - pointer to the nlp structure
725 715 *
726 716 * Returns:
727 717 * void
728 718 */
729 719 static void
730 720 log_lbr_bk_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp)
731 721 {
732 722 MOD_LOGV3(params, NDMP_LOG_NORMAL,
733 723 "Date of this level '%c': %s.\n", nlp->nlp_clevel,
734 724 cctime(&nlp->nlp_cdate));
735 725
736 726 if (nlp->nlp_dmpnm) {
737 727 MOD_LOGV3(params, NDMP_LOG_NORMAL,
738 728 "Backup date log file name: \"%s\".\n", nlp->nlp_dmpnm);
739 729 }
740 730 }
741 731
742 732
743 733 /*
744 734 * log_level_v3
745 735 *
746 736 * Log the backup level and date of the last and the current
747 737 * backup for level-type backup in the system log and also
748 738 * send them as normal log to the client.
749 739 *
750 740 * Parameters:
751 741 * params (input) - pointer to the parameters structure
752 742 * nlp (input) - pointer to the nlp structure
753 743 *
754 744 * Returns:
755 745 * void
756 746 */
757 747 static void
758 748 log_level_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp)
759 749 {
760 750 MOD_LOGV3(params, NDMP_LOG_NORMAL,
761 751 "Date of the last level '%u': %s.\n", nlp->nlp_llevel,
762 752 cctime(&nlp->nlp_ldate));
763 753
764 754 MOD_LOGV3(params, NDMP_LOG_NORMAL,
765 755 "Date of this level '%u': %s.\n", nlp->nlp_clevel,
766 756 cctime(&nlp->nlp_cdate));
767 757
768 758 MOD_LOGV3(params, NDMP_LOG_NORMAL, "Update: %s.\n",
769 759 NDMP_TORF(NLP_ISSET(nlp, NLPF_UPDATE)));
770 760 }
771 761
772 762
773 763 /*
774 764 * log_bk_params_v3
775 765 *
776 766 * Dispatcher function which calls the appropriate function
777 767 * for logging the backup date and level in the system log
778 768 * and also send them as normal log message to the client.
779 769 *
780 770 * Parameters:
781 771 * session (input) - pointer to the session
782 772 * params (input) - pointer to the parameters structure
|
↓ open down ↓ |
148 lines elided |
↑ open up ↑ |
783 773 * nlp (input) - pointer to the nlp structure
784 774 *
785 775 * Returns:
786 776 * void
787 777 */
788 778 static void
789 779 log_bk_params_v3(ndmpd_session_t *session, ndmpd_module_params_t *params,
790 780 ndmp_lbr_params_t *nlp)
791 781 {
792 782 MOD_LOGV3(params, NDMP_LOG_NORMAL, "Backing up \"%s\".\n",
793 - nlp->nlp_backup_path);
783 + NLP_ISCHKPNTED(nlp) ? nlp->nlp_mountpoint : nlp->nlp_backup_path);
794 784
795 785 if (session->ns_mover.md_data_addr.addr_type == NDMP_ADDR_LOCAL)
796 786 MOD_LOGV3(params, NDMP_LOG_NORMAL,
797 787 "Tape record size: %d.\n",
798 788 session->ns_mover.md_record_size);
799 789
800 790 MOD_LOGV3(params, NDMP_LOG_NORMAL, "File history: %c.\n",
801 791 NDMP_YORN(NLP_ISSET(nlp, NLPF_FH)));
802 792
803 793 if (NLP_ISSET(nlp, NLPF_TOKENBK))
804 794 log_date_token_v3(params, nlp);
805 795 else if (NLP_ISSET(nlp, NLPF_LBRBK))
806 796 log_lbr_bk_v3(params, nlp);
807 797 else if (NLP_ISSET(nlp, NLPF_LEVELBK))
808 798 log_level_v3(params, nlp);
809 799 else {
810 800 MOD_LOGV3(params, NDMP_LOG_ERROR,
811 801 "Internal error: backup level not defined for \"%s\".\n",
812 802 nlp->nlp_backup_path);
813 803 }
814 804 }
815 805
816 806
817 807 /*
818 808 * get_update_env_v3
819 809 *
820 810 * Is the UPDATE environment variable specified? If it is
821 811 * the corresponding flag is set in the flags field of the
822 812 * nlp structure, otherwise the flag is cleared.
823 813 *
824 814 * Parameters:
825 815 * params (input) - pointer to the parameters structure
826 816 * nlp (input) - pointer to the nlp structure
827 817 *
828 818 * Returns:
|
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
829 819 * void
830 820 */
831 821 static void
832 822 get_update_env_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp)
833 823 {
834 824 char *envp;
835 825
836 826 envp = MOD_GETENV(params, "UPDATE");
837 827 if (!envp) {
838 828 NLP_SET(nlp, NLPF_UPDATE);
839 - NDMP_LOG(LOG_DEBUG,
829 + syslog(LOG_DEBUG,
840 830 "env(UPDATE) not defined, default to TRUE");
841 831 } else {
842 - NDMP_LOG(LOG_DEBUG, "env(UPDATE): \"%s\"", envp);
832 + syslog(LOG_DEBUG, "env(UPDATE): \"%s\"", envp);
843 833 if (IS_YORT(*envp))
844 834 NLP_SET(nlp, NLPF_UPDATE);
845 835 else
846 836 NLP_UNSET(nlp, NLPF_UPDATE);
847 837 }
848 838 }
849 839
850 840
851 841 /*
852 842 * get_hist_env_v3
853 843 *
854 844 * Is backup history requested? If it is, the corresponding
855 845 * flag is set in the flags field of the nlp structure, otherwise
856 846 * the flag is cleared.
857 847 *
858 848 * Parameters:
859 849 * params (input) - pointer to the parameters structure
860 850 * nlp (input) - pointer to the nlp structure
861 851 *
|
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
862 852 * Returns:
863 853 * void
864 854 */
865 855 static void
866 856 get_hist_env_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp)
867 857 {
868 858 char *envp;
869 859
870 860 envp = MOD_GETENV(params, "HIST");
871 861 if (!envp) {
872 - NDMP_LOG(LOG_DEBUG, "env(HIST) not defined");
862 + syslog(LOG_DEBUG, "env(HIST) not defined");
873 863 NLP_UNSET(nlp, NLPF_FH);
874 864 } else {
875 - NDMP_LOG(LOG_DEBUG, "env(HIST): \"%s\"", envp);
865 + syslog(LOG_DEBUG, "env(HIST): \"%s\"", envp);
876 866 if (IS_YORT(*envp) || IS_F(*envp))
877 867 NLP_SET(nlp, NLPF_FH);
878 868 else
879 869 NLP_UNSET(nlp, NLPF_FH);
880 870
881 871 /* Force file format if specified */
882 872 if (IS_F(*envp)) {
883 873 params->mp_file_history_path_func =
884 874 ndmpd_api_file_history_file_v3;
885 875 params->mp_file_history_dir_func = 0;
886 876 params->mp_file_history_node_func = 0;
887 877 }
888 878 }
889 879 }
890 880
891 881
892 882 /*
893 883 * get_exc_env_v3
894 884 *
895 885 * Gets the EXCLUDE environment variable and breaks it
896 886 * into strings. The separator of the EXCLUDE environment
897 887 * variable is the ',' character.
898 888 *
899 889 * Parameters:
900 890 * params (input) - pointer to the parameters structure
901 891 * nlp (input) - pointer to the nlp structure
902 892 *
|
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
903 893 * Returns:
904 894 * void
905 895 */
906 896 static void
907 897 get_exc_env_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp)
908 898 {
909 899 char *envp;
910 900
911 901 envp = MOD_GETENV(params, "EXCLUDE");
912 902 if (!envp) {
913 - NDMP_LOG(LOG_DEBUG, "env(EXCLUDE) not defined");
903 + syslog(LOG_DEBUG, "env(EXCLUDE) not defined");
914 904 nlp->nlp_exl = NULL;
915 905 } else {
916 - NDMP_LOG(LOG_DEBUG, "env(EXCLUDE): \"%s\"", envp);
906 + syslog(LOG_DEBUG, "env(EXCLUDE): \"%s\"", envp);
917 907 nlp->nlp_exl = split_env(envp, ',');
918 908 prl(nlp->nlp_exl);
919 909 }
920 910 }
921 911
922 912
923 913 /*
924 914 * get_inc_env_v3
925 915 *
926 916 * Gets the FILES environment variable that shows which files
927 917 * should be backed up, and breaks it into strings. The
928 918 * separator of the FILES environment variable is the space
929 919 * character.
930 920 *
931 921 * Parameters:
932 922 * params (input) - pointer to the parameters structure
933 923 * nlp (input) - pointer to the nlp structure
934 924 *
|
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
935 925 * Returns:
936 926 * void
937 927 */
938 928 static void
939 929 get_inc_env_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp)
940 930 {
941 931 char *envp;
942 932
943 933 envp = MOD_GETENV(params, "FILES");
944 934 if (!envp) {
945 - NDMP_LOG(LOG_DEBUG, "env(FILES) not defined");
935 + syslog(LOG_DEBUG, "env(FILES) not defined");
946 936 nlp->nlp_inc = NULL;
947 937 } else {
948 - NDMP_LOG(LOG_DEBUG, "env(FILES): \"%s\"", envp);
938 + syslog(LOG_DEBUG, "env(FILES): \"%s\"", envp);
949 939 nlp->nlp_inc = split_env(envp, ' ');
950 940 prl(nlp->nlp_inc);
951 941 }
952 942 }
953 943
954 944
955 945 /*
956 946 * get_direct_env_v3
957 947 *
958 948 * Gets the DIRECT environment variable that shows if the fh_info should
959 949 * be sent to the client or not.
960 950 *
961 951 * Parameters:
962 952 * params (input) - pointer to the parameters structure
963 953 * nlp (input) - pointer to the nlp structure
964 954 *
965 955 * Returns:
966 956 * void
967 957 */
968 958 static void
969 959 get_direct_env_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp)
|
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
970 960 {
971 961 char *envp;
972 962
973 963 /*
974 964 * We should send the fh_info to the DMA, unless it is specified
975 965 * in the request that we should not send fh_info.
976 966 * At the moment we do not support DAR on directories, so if the user
977 967 * needs to restore a directory they should disable the DAR.
978 968 */
979 969 if (params->mp_operation == NDMP_DATA_OP_RECOVER && !ndmp_dar_support) {
980 - NDMP_LOG(LOG_DEBUG, "Direct Access Restore Disabled");
970 + syslog(LOG_INFO, "Direct Access Restore Disabled");
981 971 NLP_UNSET(nlp, NLPF_DIRECT);
982 972 MOD_LOGV3(params, NDMP_LOG_NORMAL,
983 973 "DAR is disabled. Running Restore without DAR");
984 974 return;
985 975 }
986 976
987 977 /*
988 978 * Regardless of whether DIRECT is defined at backup time we send
989 979 * back the fh_info, for some clients do not use get_backup_attrs.
990 980 * If operation is restore we have to unset the DIRECT, for
991 981 * some clients do not set the MOVER window.
992 982 */
993 983 if (params->mp_operation == NDMP_DATA_OP_BACKUP) {
994 - NDMP_LOG(LOG_DEBUG, "backup default env(DIRECT): YES");
984 + syslog(LOG_DEBUG, "backup default env(DIRECT): YES");
995 985 NLP_SET(nlp, NLPF_DIRECT);
996 986 } else {
997 987
998 988 envp = MOD_GETENV(params, "DIRECT");
999 989 if (!envp) {
1000 - NDMP_LOG(LOG_DEBUG, "env(DIRECT) not defined");
990 + syslog(LOG_DEBUG, "env(DIRECT) not defined");
1001 991 NLP_UNSET(nlp, NLPF_DIRECT);
1002 992 } else {
1003 - NDMP_LOG(LOG_DEBUG, "env(DIRECT): \"%s\"", envp);
993 + syslog(LOG_DEBUG, "env(DIRECT): \"%s\"", envp);
1004 994 if (IS_YORT(*envp)) {
1005 995 NLP_SET(nlp, NLPF_DIRECT);
1006 - NDMP_LOG(LOG_DEBUG,
996 + syslog(LOG_DEBUG,
1007 997 "Direct Access Restore Enabled");
1008 998 } else {
1009 999 NLP_UNSET(nlp, NLPF_DIRECT);
1010 - NDMP_LOG(LOG_DEBUG,
1000 + syslog(LOG_DEBUG,
1011 1001 "Direct Access Restore Disabled");
1012 1002 }
1013 1003 }
1014 1004 }
1015 1005
1016 1006 if (NLP_ISSET(nlp, NLPF_DIRECT)) {
1017 1007 if (params->mp_operation == NDMP_DATA_OP_BACKUP)
1018 1008 MOD_LOGV3(params, NDMP_LOG_NORMAL,
1019 1009 "Direct Access Restore information is supported");
1020 1010 else
1021 1011 MOD_LOGV3(params, NDMP_LOG_NORMAL,
1022 1012 "Running Restore with Direct Access Restore");
1023 1013 } else {
1024 1014 if (params->mp_operation == NDMP_DATA_OP_BACKUP)
1025 1015 MOD_LOGV3(params, NDMP_LOG_NORMAL,
1026 1016 "Direct Access Restore is not supported");
1027 1017 else
1028 1018 MOD_LOGV3(params, NDMP_LOG_NORMAL,
1029 1019 "Running Restore without Direct Access Restore");
1030 1020 }
1031 1021 }
1032 1022
1033 1023
1034 1024 /*
1035 1025 * get_date_token_v3
1036 1026 *
1037 1027 * Parse the token passed as the argument. Evaluate it and
1038 1028 * issue any warning or error if needed. Save the date and
1039 1029 * token sequence in the nlp structure fields. The sequence
1040 1030 * number in the token should be less than hard-limit. If
1041 1031 * it's between soft and hard limit, a warning is issued.
1042 1032 * There is a configurable limit which should be less than
1043 1033 * the soft-limit saved in ndmp_max_tok_seq variable.
1044 1034 *
1045 1035 * The NLPF_TOKENBK flag is set in the nlp flags field to
1046 1036 * show that the backup type is token-based.
1047 1037 *
1048 1038 * Parameters:
1049 1039 * params (input) - pointer to the parameters structure
1050 1040 * nlp (input) - pointer to the nlp structure
1051 1041 * basedate (input) - the value of the BASE_DATE environment
1052 1042 * variable.
1053 1043 *
1054 1044 * Returns:
1055 1045 * NDMP_NO_ERR: on success
1056 1046 * != NDMP_NO_ERR: Otherwise
1057 1047 *
1058 1048 */
1059 1049 static ndmp_error
1060 1050 get_date_token_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp,
1061 1051 char *basedate)
1062 1052 {
1063 1053 char *endp;
1064 1054 uint_t seq;
1065 1055 ndmp_error rv;
1066 1056 time_t tstamp;
1067 1057 u_longlong_t tok;
1068 1058
1069 1059 if (!params || !nlp || !basedate || !*basedate)
1070 1060 return (NDMP_ILLEGAL_ARGS_ERR);
1071 1061
1072 1062 if (MOD_GETENV(params, "LEVEL")) {
1073 1063 MOD_LOGV3(params, NDMP_LOG_WARNING,
1074 1064 "Both BASE_DATE and LEVEL environment variables "
1075 1065 "defined.\n");
1076 1066 MOD_LOGCONTV3(params, NDMP_LOG_WARNING,
1077 1067 "BASE_DATE is being used for this backup.\n");
1078 1068 }
1079 1069
|
↓ open down ↓ |
59 lines elided |
↑ open up ↑ |
1080 1070 tok = strtoll(basedate, &endp, 10);
1081 1071 if (endp == basedate) {
1082 1072 MOD_LOGV3(params, NDMP_LOG_ERROR,
1083 1073 "Invalid BASE_DATE environment variable: \"%s\".\n",
1084 1074 basedate);
1085 1075 return (NDMP_ILLEGAL_ARGS_ERR);
1086 1076 }
1087 1077
1088 1078 tstamp = tok & 0xffffffff;
1089 1079 seq = (tok >> 32) & 0xffffffff;
1090 - NDMP_LOG(LOG_DEBUG, "basedate \"%s\" %lld seq %u tstamp %u",
1091 - basedate, tok, seq, tstamp);
1092 1080
1093 1081 if ((int)seq > ndmp_get_max_tok_seq()) {
1094 1082 rv = NDMP_ILLEGAL_ARGS_ERR;
1095 1083 MOD_LOGV3(params, NDMP_LOG_ERROR,
1096 1084 "The sequence counter of the token exceeds the "
1097 1085 "maximum permitted value.\n");
1098 1086 MOD_LOGCONTV3(params, NDMP_LOG_ERROR,
1099 1087 "Token sequence: %u, maxiumum value: %u.\n",
1100 1088 seq, ndmp_get_max_tok_seq());
1101 1089 } else if (seq >= NDMP_TOKSEQ_HLIMIT) {
1102 1090 rv = NDMP_ILLEGAL_ARGS_ERR;
1103 1091 MOD_LOGV3(params, NDMP_LOG_ERROR,
1104 1092 "The sequence counter the of token exceeds the "
1105 1093 "hard-limit.\n");
1106 1094 MOD_LOGCONTV3(params, NDMP_LOG_ERROR,
1107 1095 "Token sequence: %u, hard-limit: %u.\n",
1108 1096 seq, NDMP_TOKSEQ_HLIMIT);
1109 1097 } else {
1110 1098 rv = NDMP_NO_ERR;
1111 1099 /*
1112 1100 * Issue a warning if the seq is equal to the maximum
1113 1101 * permitted seq number or equal to the soft-limit.
1114 1102 */
1115 1103 if (seq == NDMP_TOKSEQ_SLIMIT) {
1116 1104 MOD_LOGV3(params, NDMP_LOG_WARNING,
1117 1105 "The sequence counter of the token has reached "
1118 1106 "the soft-limit.\n");
1119 1107 MOD_LOGCONTV3(params, NDMP_LOG_WARNING,
1120 1108 "Token sequence: %u, soft-limit: %u.\n",
1121 1109 seq, NDMP_TOKSEQ_SLIMIT);
1122 1110 } else if ((int)seq == ndmp_get_max_tok_seq()) {
1123 1111 MOD_LOGV3(params, NDMP_LOG_WARNING,
1124 1112 "The sequence counter of the token has reached "
1125 1113 "the maximum permitted value.\n");
1126 1114 MOD_LOGCONTV3(params, NDMP_LOG_WARNING,
1127 1115 "Token sequence: %u, maxiumum value: %u.\n",
1128 1116 seq, ndmp_get_max_tok_seq());
1129 1117 }
1130 1118
1131 1119 /*
1132 1120 * The current seq is equal to the seq field of the
1133 1121 * token. It will be increased after successful backup
1134 1122 * before setting the DUMP_DATE environment variable.
1135 1123 */
1136 1124 nlp->nlp_dmpnm = MOD_GETENV(params, "DMP_NAME");
1137 1125 NLP_SET(nlp, NLPF_TOKENBK);
1138 1126 NLP_UNSET(nlp, NLPF_LEVELBK);
1139 1127 NLP_UNSET(nlp, NLPF_LBRBK);
1140 1128 nlp->nlp_tokseq = seq;
1141 1129 nlp->nlp_tokdate = tstamp;
1142 1130 /*
1143 1131 * The value of nlp_cdate will be set to the checkpoint
1144 1132 * creation time after it is created.
1145 1133 */
1146 1134 }
1147 1135
1148 1136 return (rv);
1149 1137 }
1150 1138
1151 1139
1152 1140 /*
1153 1141 * get_lbr_bk_v3
1154 1142 *
1155 1143 * Sets the level fields of the nlp structures for
1156 1144 * LBR-type backup. The NLPF_LBRBK flag of the
1157 1145 * nlp flags is also set to show the backup type.
1158 1146 *
1159 1147 * Parameters:
1160 1148 * params (input) - pointer to the parameters structure
1161 1149 * nlp (input) - pointer to the nlp structure
1162 1150 * type (input) - the backup level: 'F', 'A', 'I', 'D' or
1163 1151 * their lower-case values.
1164 1152 *
1165 1153 * Returns:
1166 1154 * NDMP_NO_ERR: on success
1167 1155 * != NDMP_NO_ERR: Otherwise
1168 1156 */
1169 1157 static ndmp_error
1170 1158 get_lbr_bk_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp, char *type)
1171 1159 {
1172 1160 if (!params || !nlp || !type || !*type)
1173 1161 return (NDMP_ILLEGAL_ARGS_ERR);
1174 1162
1175 1163 NLP_SET(nlp, NLPF_LBRBK);
1176 1164 NLP_UNSET(nlp, NLPF_TOKENBK);
1177 1165 NLP_UNSET(nlp, NLPF_LEVELBK);
1178 1166 nlp->nlp_dmpnm = MOD_GETENV(params, "DMP_NAME");
1179 1167 nlp->nlp_llevel = toupper(*type);
1180 1168 nlp->nlp_ldate = (time_t)0;
1181 1169 nlp->nlp_clevel = nlp->nlp_llevel;
1182 1170 (void) time(&nlp->nlp_cdate);
1183 1171
1184 1172 return (NDMP_NO_ERR);
1185 1173 }
1186 1174
1187 1175
1188 1176 /*
1189 1177 * get_backup_level_v3
1190 1178 *
1191 1179 * Gets the backup level from the environment variables. If
1192 1180 * BASE_DATE is specified, it will be used, otherwise LEVEL
1193 1181 * will be used. If neither is specified, LEVEL = '0' is
1194 1182 * assumed.
1195 1183 *
1196 1184 * Parameters:
1197 1185 * params (input) - pointer to the parameters structure
1198 1186 * nlp (input) - pointer to the nlp structure
1199 1187 *
1200 1188 * Returns:
1201 1189 * NDMP_NO_ERR: on success
1202 1190 * != NDMP_NO_ERR: Otherwise
1203 1191 */
1204 1192 static ndmp_error
1205 1193 get_backup_level_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp)
1206 1194 {
1207 1195 char *envp;
1208 1196 ndmp_error rv;
1209 1197
1210 1198 /*
1211 1199 * If the BASE_DATE env variable is specified use it, otherwise
1212 1200 * look to see if LEVEL is specified. If LEVEL is not
1213 1201 * specified either, backup level '0' must be made. Level backup
1214 1202 * does not clear the archive bit.
1215 1203 *
1216 1204 * If LEVEL environment varaible is specified, values for
1217 1205 * 'F', 'D', 'I' and 'A' (for 'Full', 'Differential',
1218 1206 * 'Incremental', and 'Archive' is checked first. Then
1219 1207 * level '0' to '9' will be checked.
1220 1208 *
|
↓ open down ↓ |
119 lines elided |
↑ open up ↑ |
1221 1209 * LEVEL environment variable can hold only one character.
1222 1210 * If its length is longer than 1, an error is returned.
1223 1211 */
1224 1212 envp = MOD_GETENV(params, "BASE_DATE");
1225 1213 if (envp)
1226 1214 return (get_date_token_v3(params, nlp, envp));
1227 1215
1228 1216
1229 1217 envp = MOD_GETENV(params, "LEVEL");
1230 1218 if (!envp) {
1231 - NDMP_LOG(LOG_DEBUG, "env(LEVEL) not defined, default to 0");
1219 + syslog(LOG_DEBUG, "env(LEVEL) not defined, default to 0");
1232 1220 NLP_SET(nlp, NLPF_LEVELBK);
1233 1221 NLP_UNSET(nlp, NLPF_LBRBK);
1234 1222 NLP_UNSET(nlp, NLPF_TOKENBK);
1235 1223 nlp->nlp_llevel = 0;
1236 1224 nlp->nlp_ldate = 0;
1237 1225 nlp->nlp_clevel = 0;
1238 1226 /*
1239 1227 * The value of nlp_cdate will be set to the checkpoint
1240 1228 * creation time after it is created.
1241 1229 */
1242 1230 return (NDMP_NO_ERR);
1243 1231 }
1244 1232
1245 1233 if (*(envp+1) != '\0') {
1246 1234 MOD_LOGV3(params, NDMP_LOG_ERROR,
1247 1235 "Invalid backup level \"%s\".\n", envp);
1248 1236 return (NDMP_ILLEGAL_ARGS_ERR);
1249 1237 }
1250 1238
1251 1239 if (IS_LBR_BKTYPE(*envp))
1252 1240 return (get_lbr_bk_v3(params, nlp, envp));
1253 1241
1254 1242 if (!isdigit(*envp)) {
1255 1243 MOD_LOGV3(params, NDMP_LOG_ERROR,
1256 1244 "Invalid backup level \"%s\".\n", envp);
1257 1245 return (NDMP_ILLEGAL_ARGS_ERR);
1258 1246 }
1259 1247
1260 1248 NLP_SET(nlp, NLPF_LEVELBK);
1261 1249 NLP_UNSET(nlp, NLPF_LBRBK);
1262 1250 NLP_UNSET(nlp, NLPF_TOKENBK);
1263 1251 nlp->nlp_llevel = *envp - '0';
1264 1252 nlp->nlp_ldate = 0;
1265 1253 nlp->nlp_clevel = nlp->nlp_llevel;
1266 1254 /*
1267 1255 * The value of nlp_cdate will be set to the checkpoint
1268 1256 * creation time after it is created.
1269 1257 */
1270 1258 if (ndmpd_get_dumptime(nlp->nlp_backup_path, &nlp->nlp_llevel,
1271 1259 &nlp->nlp_ldate) < 0) {
1272 1260 MOD_LOGV3(params, NDMP_LOG_ERROR,
1273 1261 "Getting dumpdates for %s level '%c'.\n",
1274 1262 nlp->nlp_backup_path, *envp);
1275 1263 return (NDMP_NO_MEM_ERR);
1276 1264 } else {
1277 1265 get_update_env_v3(params, nlp);
1278 1266 rv = NDMP_NO_ERR;
1279 1267 }
1280 1268
1281 1269 return (rv);
1282 1270 }
1283 1271
1284 1272
1285 1273 /*
1286 1274 * save_date_token_v3
1287 1275 *
1288 1276 * Make the value of DUMP_DATE env variable and append the values
1289 1277 * of the current backup in the file specified with the DMP_NAME
1290 1278 * env variable if any file is specified. The file will be
1291 1279 * relative name in the backup directory path.
1292 1280 *
1293 1281 * Parameters:
1294 1282 * params (input) - pointer to the parameters structure
1295 1283 * nlp (input) - pointer to the nlp structure
1296 1284 *
1297 1285 * Returns:
1298 1286 * void
1299 1287 */
1300 1288 static void
1301 1289 save_date_token_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp)
1302 1290 {
|
↓ open down ↓ |
61 lines elided |
↑ open up ↑ |
1303 1291 char val[QUAD_DECIMAL_LEN];
1304 1292 u_longlong_t tok;
1305 1293
1306 1294 if (!params || !nlp)
1307 1295 return;
1308 1296
1309 1297 nlp->nlp_tokseq++;
1310 1298 tok = ((u_longlong_t)nlp->nlp_tokseq << 32) | nlp->nlp_cdate;
1311 1299 (void) snprintf(val, sizeof (val), "%llu", tok);
1312 1300
1313 - NDMP_LOG(LOG_DEBUG, "tok: %lld %s", tok, val);
1314 -
1315 1301 if (MOD_SETENV(params, "DUMP_DATE", val) != 0) {
1316 1302 MOD_LOGV3(params, NDMP_LOG_ERROR,
1317 1303 "Could not set DUMP_DATE to %s", val);
1318 1304 } else if (!nlp->nlp_dmpnm) {
1319 - NDMP_LOG(LOG_DEBUG, "No log file defined");
1305 + syslog(LOG_DEBUG, "No log file defined");
1320 1306 } else if (ndmpd_append_dumptime(nlp->nlp_dmpnm, nlp->nlp_backup_path,
1321 1307 nlp->nlp_tokseq, nlp->nlp_tokdate) < 0) {
1322 1308 MOD_LOGV3(params, NDMP_LOG_ERROR,
1323 1309 "Saving backup date for \"%s\" in \"%s\".\n",
1324 1310 nlp->nlp_backup_path, nlp->nlp_dmpnm);
1325 1311 }
1326 1312 }
1327 1313
1328 1314
1329 1315 /*
1330 1316 * save_lbr_bk_v3
1331 1317 *
1332 1318 * Append the backup type and date in the DMP_NAME file for
1333 1319 * LBR-type backup if any file is specified.
1334 1320 *
1335 1321 * Parameters:
1336 1322 * params (input) - pointer to the parameters structure
1337 1323 * nlp (input) - pointer to the nlp structure
1338 1324 *
|
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
1339 1325 * Returns:
1340 1326 * void
1341 1327 */
1342 1328 static void
1343 1329 save_lbr_bk_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp)
1344 1330 {
1345 1331 if (!params || !nlp)
1346 1332 return;
1347 1333
1348 1334 if (!nlp->nlp_dmpnm) {
1349 - NDMP_LOG(LOG_DEBUG, "No log file defined");
1335 + syslog(LOG_DEBUG, "No log file defined");
1350 1336 } else if (ndmpd_append_dumptime(nlp->nlp_dmpnm, nlp->nlp_backup_path,
1351 1337 nlp->nlp_clevel, nlp->nlp_cdate) < 0) {
1352 1338 MOD_LOGV3(params, NDMP_LOG_ERROR,
1353 1339 "Saving backup date for \"%s\" in \"%s\".\n",
1354 1340 nlp->nlp_backup_path, nlp->nlp_dmpnm);
1355 1341 }
1356 1342 }
1357 1343
1358 1344
1359 1345 /*
1360 1346 * save_level_v3
1361 1347 *
1362 1348 * Save the date and level of the current backup in the dumpdates
1363 1349 * file.
1364 1350 *
1365 1351 * Parameters:
1366 1352 * params (input) - pointer to the parameters structure
1367 1353 * nlp (input) - pointer to the nlp structure
1368 1354 *
|
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
1369 1355 * Returns:
1370 1356 * void
1371 1357 */
1372 1358 static void
1373 1359 save_level_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp)
1374 1360 {
1375 1361 if (!params || !nlp)
1376 1362 return;
1377 1363
1378 1364 if (!NLP_SHOULD_UPDATE(nlp)) {
1379 - NDMP_LOG(LOG_DEBUG, "update not requested");
1365 + syslog(LOG_DEBUG, "update not requested");
1380 1366 } else if (ndmpd_put_dumptime(nlp->nlp_backup_path, nlp->nlp_clevel,
1381 1367 nlp->nlp_cdate) < 0) {
1382 1368 MOD_LOGV3(params, NDMP_LOG_ERROR, "Logging backup date.\n");
1383 1369 }
1384 1370 }
1385 1371
1386 1372
1387 1373 /*
1388 1374 * save_backup_date_v3
1389 1375 *
1390 1376 * A dispatcher function to call the corresponding save function
1391 1377 * based on the backup type.
1392 1378 *
1393 1379 * Parameters:
1394 1380 * params (input) - pointer to the parameters structure
1395 1381 * nlp (input) - pointer to the nlp structure
1396 1382 *
1397 1383 * Returns:
1398 1384 * void
1399 1385 */
1400 1386 static void
1401 1387 save_backup_date_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp)
1402 1388 {
1403 1389 if (!params || !nlp)
1404 1390 return;
1405 1391
1406 1392 if (NLP_ISSET(nlp, NLPF_TOKENBK))
1407 1393 save_date_token_v3(params, nlp);
1408 1394 else if (NLP_ISSET(nlp, NLPF_LBRBK))
1409 1395 save_lbr_bk_v3(params, nlp);
1410 1396 else if (NLP_ISSET(nlp, NLPF_LEVELBK))
1411 1397 save_level_v3(params, nlp);
1412 1398 else {
1413 1399 MOD_LOGV3(params, NDMP_LOG_ERROR,
1414 1400 "Internal error: lost backup level type for \"%s\".\n",
1415 1401 nlp->nlp_backup_path);
1416 1402 }
1417 1403 }
1418 1404
1419 1405
|
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
1420 1406 /*
1421 1407 * backup_alloc_structs_v3
1422 1408 *
1423 1409 * Create the structures for V3 backup. This includes:
1424 1410 * Job stats
1425 1411 * Reader writer IPC
1426 1412 * File history callback structure
1427 1413 *
1428 1414 * Parameters:
1429 1415 * session (input) - pointer to the session
1430 - * jname (input) - name assigned to the current backup for
1431 - * job stats strucure
1432 1416 *
1433 1417 * Returns:
1434 1418 * 0: on success
1435 1419 * -1: otherwise
1436 1420 */
1437 1421 static int
1438 -backup_alloc_structs_v3(ndmpd_session_t *session, char *jname)
1422 +backup_alloc_structs_v3(ndmpd_session_t *session)
1439 1423 {
1440 1424 int n;
1441 1425 long xfer_size;
1442 1426 ndmp_lbr_params_t *nlp;
1443 1427 tlm_commands_t *cmds;
1444 1428
1445 1429 nlp = ndmp_get_nlp(session);
1446 1430 if (!nlp) {
1447 - NDMP_LOG(LOG_DEBUG, "nlp == NULL");
1431 + syslog(LOG_ERR, "nlp == NULL");
1448 1432 return (-1);
1449 1433 }
1450 1434
1451 - nlp->nlp_jstat = tlm_new_job_stats(jname);
1435 + nlp->nlp_jstat = tlm_new_job_stats(nlp->nlp_job_name);
1452 1436 if (!nlp->nlp_jstat) {
1453 - NDMP_LOG(LOG_DEBUG, "Creating job stats");
1437 + syslog(LOG_ERR, "Creating job stats failed");
1454 1438 return (-1);
1455 1439 }
1456 1440
1457 1441 cmds = &nlp->nlp_cmds;
1458 1442 (void) memset(cmds, 0, sizeof (*cmds));
1459 1443
1460 1444 xfer_size = ndmp_buffer_get_size(session);
1461 1445 if (xfer_size < 512*KILOBYTE) {
1462 1446 /*
1463 1447 * Read multiple of mover_record_size near to 512K. This
1464 1448 * will prevent the data being copied in the mover buffer
1465 1449 * when we write the data.
1466 1450 */
1467 1451 n = 512 * KILOBYTE / xfer_size;
1468 1452 if (n <= 0)
1469 1453 n = 1;
1470 1454 xfer_size *= n;
1471 - NDMP_LOG(LOG_DEBUG, "Adjusted read size: %d",
1455 + syslog(LOG_DEBUG, "Adjusted read size: %d",
1472 1456 xfer_size);
1473 1457 }
1474 1458
1475 1459 cmds->tcs_command = tlm_create_reader_writer_ipc(TRUE, xfer_size);
1476 1460 if (!cmds->tcs_command) {
1477 - tlm_un_ref_job_stats(jname);
1461 + tlm_un_ref_job_stats(nlp->nlp_job_name);
1478 1462 return (-1);
1479 1463 }
1480 1464
1481 1465 nlp->nlp_logcallbacks = lbrlog_callbacks_init(session,
1482 1466 ndmpd_fhpath_v3_cb, ndmpd_fhdir_v3_cb, ndmpd_fhnode_v3_cb);
1483 1467 if (!nlp->nlp_logcallbacks) {
1484 1468 tlm_release_reader_writer_ipc(cmds->tcs_command);
1485 - tlm_un_ref_job_stats(jname);
1469 + tlm_un_ref_job_stats(nlp->nlp_job_name);
1486 1470 return (-1);
1487 1471 }
1488 1472 nlp->nlp_jstat->js_callbacks = (void *)(nlp->nlp_logcallbacks);
1489 1473 nlp->nlp_restored = NULL;
1490 1474
1491 1475 return (0);
1492 1476 }
1493 1477
1494 1478
1495 1479 /*
1496 1480 * restore_alloc_structs_v3
1497 1481 *
1498 1482 * Create the structures for V3 Restore. This includes:
1499 1483 * Job stats
1500 1484 * Reader writer IPC
1501 1485 * File recovery callback structure
1502 1486 *
1503 1487 * Parameters:
1504 1488 * session (input) - pointer to the session
1505 - * jname (input) - name assigned to the current backup for
1506 - * job stats strucure
1507 1489 *
1508 1490 * Returns:
1509 1491 * 0: on success
1510 1492 * -1: otherwise
1511 1493 */
1512 1494 int
1513 -restore_alloc_structs_v3(ndmpd_session_t *session, char *jname)
1495 +restore_alloc_structs_v3(ndmpd_session_t *session)
1514 1496 {
1515 1497 long xfer_size;
1516 1498 ndmp_lbr_params_t *nlp;
1517 1499 tlm_commands_t *cmds;
1518 1500
1519 1501 nlp = ndmp_get_nlp(session);
1520 1502 if (!nlp) {
1521 - NDMP_LOG(LOG_DEBUG, "nlp == NULL");
1503 + syslog(LOG_ERR, "nlp == NULL");
1522 1504 return (-1);
1523 1505 }
1524 1506
1525 1507 /* this is used in ndmpd_path_restored_v3() */
1526 1508 nlp->nlp_lastidx = -1;
1527 1509
1528 - nlp->nlp_jstat = tlm_new_job_stats(jname);
1510 + nlp->nlp_jstat = tlm_new_job_stats(nlp->nlp_job_name);
1529 1511 if (!nlp->nlp_jstat) {
1530 - NDMP_LOG(LOG_DEBUG, "Creating job stats");
1512 + syslog(LOG_ERR, "Creating job stats failed");
1531 1513 return (-1);
1532 1514 }
1533 1515
1534 1516 cmds = &nlp->nlp_cmds;
1535 1517 (void) memset(cmds, 0, sizeof (*cmds));
1536 1518
1537 1519 xfer_size = ndmp_buffer_get_size(session);
1538 1520 cmds->tcs_command = tlm_create_reader_writer_ipc(FALSE, xfer_size);
1539 1521 if (!cmds->tcs_command) {
1540 - tlm_un_ref_job_stats(jname);
1522 + tlm_un_ref_job_stats(nlp->nlp_job_name);
1541 1523 return (-1);
1542 1524 }
1543 1525
1544 1526 nlp->nlp_logcallbacks = lbrlog_callbacks_init(session,
1545 1527 ndmpd_path_restored_v3, NULL, NULL);
1546 1528 if (!nlp->nlp_logcallbacks) {
1547 1529 tlm_release_reader_writer_ipc(cmds->tcs_command);
1548 - tlm_un_ref_job_stats(jname);
1530 + tlm_un_ref_job_stats(nlp->nlp_job_name);
1549 1531 return (-1);
1550 1532 }
1551 1533 nlp->nlp_jstat->js_callbacks = (void *)(nlp->nlp_logcallbacks);
1552 1534
1553 1535 nlp->nlp_rsbm = bm_alloc(nlp->nlp_nfiles, 0);
1554 1536 if (nlp->nlp_rsbm < 0) {
1555 - NDMP_LOG(LOG_ERR, "Out of memory.");
1537 + syslog(LOG_ERR, "Out of memory.");
1556 1538 lbrlog_callbacks_done(nlp->nlp_logcallbacks);
1557 1539 tlm_release_reader_writer_ipc(cmds->tcs_command);
1558 - tlm_un_ref_job_stats(jname);
1540 + tlm_un_ref_job_stats(nlp->nlp_job_name);
1559 1541 return (-1);
1560 1542 }
1561 1543
1562 1544 return (0);
1563 1545 }
1564 1546
1565 1547
1566 1548 /*
1567 1549 * free_structs_v3
1568 1550 *
1569 1551 * Release the resources allocated by backup_alloc_structs_v3
1570 1552 * function.
1571 1553 *
1572 1554 * Parameters:
1573 1555 * session (input) - pointer to the session
1574 - * jname (input) - name assigned to the current backup for
1575 - * job stats strucure
1576 1556 *
1577 1557 * Returns:
1578 1558 * void
1579 1559 */
1580 -/*ARGSUSED*/
1581 1560 static void
1582 -free_structs_v3(ndmpd_session_t *session, char *jname)
1561 +free_structs_v3(ndmpd_session_t *session)
1583 1562 {
1584 1563 ndmp_lbr_params_t *nlp;
1585 1564 tlm_commands_t *cmds;
1586 1565
1587 1566 nlp = ndmp_get_nlp(session);
1588 1567 if (!nlp) {
1589 - NDMP_LOG(LOG_DEBUG, "nlp == NULL");
1568 + syslog(LOG_DEBUG, "nlp == NULL");
1590 1569 return;
1591 1570 }
1592 1571 cmds = &nlp->nlp_cmds;
1593 1572 if (!cmds) {
1594 - NDMP_LOG(LOG_DEBUG, "cmds == NULL");
1573 + syslog(LOG_DEBUG, "cmds == NULL");
1595 1574 return;
1596 1575 }
1597 1576
1598 1577 if (nlp->nlp_logcallbacks) {
1599 1578 lbrlog_callbacks_done(nlp->nlp_logcallbacks);
1600 1579 nlp->nlp_logcallbacks = NULL;
1601 1580 } else
1602 - NDMP_LOG(LOG_DEBUG, "FH CALLBACKS == NULL");
1581 + syslog(LOG_DEBUG, "FH CALLBACKS == NULL");
1603 1582
1604 1583 if (cmds->tcs_command) {
1605 1584 if (cmds->tcs_command->tc_buffers != NULL)
1606 1585 tlm_release_reader_writer_ipc(cmds->tcs_command);
1607 1586 else
1608 - NDMP_LOG(LOG_DEBUG, "BUFFERS == NULL");
1587 + syslog(LOG_DEBUG, "BUFFERS == NULL");
1609 1588 cmds->tcs_command = NULL;
1610 1589 } else
1611 - NDMP_LOG(LOG_DEBUG, "COMMAND == NULL");
1590 + syslog(LOG_DEBUG, "COMMAND == NULL");
1612 1591
1613 1592 if (nlp->nlp_bkmap >= 0) {
1614 1593 (void) dbm_free(nlp->nlp_bkmap);
1615 1594 nlp->nlp_bkmap = -1;
1616 1595 }
1617 1596
1618 1597 if (session->ns_data.dd_operation == NDMP_DATA_OP_RECOVER) {
1619 1598 if (nlp->nlp_rsbm < 0) {
1620 - NDMP_LOG(LOG_DEBUG, "nlp_rsbm < 0 %d", nlp->nlp_rsbm);
1599 + syslog(LOG_DEBUG, "nlp_rsbm < 0 %d", nlp->nlp_rsbm);
1621 1600 } else {
1622 1601 (void) bm_free(nlp->nlp_rsbm);
1623 1602 nlp->nlp_rsbm = -1;
1624 1603 }
1625 1604 }
1626 1605 }
1627 1606
1628 1607
1629 1608 /*
1630 1609 * backup_dirv3
1631 1610 *
1632 1611 * Backup a directory and update the bytes processed field of the
1633 1612 * data server.
1634 1613 *
1635 1614 * Parameters:
1636 1615 * bpp (input) - pointer to the backup parameters structure
1637 1616 * pnp (input) - pointer to the path node
1638 1617 * enp (input) - pointer to the entry node
1639 1618 *
1640 1619 * Returns:
1641 1620 * 0: on success
1642 1621 * != 0: otherwise
1643 1622 */
1644 1623 static int
1645 1624 backup_dirv3(bk_param_v3_t *bpp, fst_node_t *pnp,
|
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
1646 1625 fst_node_t *enp)
1647 1626 {
1648 1627 longlong_t apos, bpos;
1649 1628 acl_t *aclp = NULL;
1650 1629 char *acltp;
1651 1630 struct stat64 st;
1652 1631 char fullpath[TLM_MAX_PATH_NAME];
1653 1632 char *p;
1654 1633
1655 1634 if (!bpp || !pnp || !enp) {
1656 - NDMP_LOG(LOG_DEBUG, "Invalid argument");
1635 + syslog(LOG_ERR, "Invalid argument in backup_dirv3");
1657 1636 return (-1);
1658 1637 }
1659 1638
1660 - NDMP_LOG(LOG_DEBUG, "d(%s)", bpp->bp_tmp);
1661 -
1662 1639 if (lstat64(bpp->bp_tmp, &st) != 0)
1663 1640 return (0);
1664 1641
1665 1642 if (acl_get(bpp->bp_tmp, ACL_NO_TRIVIAL, &aclp) != 0) {
1666 - NDMP_LOG(LOG_DEBUG, "acl_get error errno=%d", errno);
1643 + syslog(LOG_DEBUG, "acl_get error errno=%d", errno);
1667 1644 return (-1);
1668 1645 }
1669 1646 if (aclp && (acltp = acl_totext(aclp,
1670 1647 ACL_APPEND_ID | ACL_SID_FMT | ACL_COMPACT_FMT)) != NULL) {
1671 1648 (void) strlcpy(bpp->bp_tlmacl->acl_info.attr_info,
1672 1649 acltp, TLM_MAX_ACL_TXT);
1673 1650 acl_free(aclp);
1674 1651 free(acltp);
1675 1652 } else {
1676 1653 *bpp->bp_tlmacl->acl_info.attr_info = '\0';
1677 1654 }
1678 1655
1679 1656 bpos = tlm_get_data_offset(bpp->bp_lcmd);
1680 1657
1681 1658 p = bpp->bp_tmp + strlen(bpp->bp_chkpnm);
1682 1659 if (*p == '/')
1683 1660 (void) snprintf(fullpath, TLM_MAX_PATH_NAME, "%s%s",
1684 1661 bpp->bp_unchkpnm, p);
1685 1662 else
1686 1663 (void) snprintf(fullpath, TLM_MAX_PATH_NAME, "%s/%s",
1687 1664 bpp->bp_unchkpnm, p);
1688 1665
1689 1666 if (tm_tar_ops.tm_putdir != NULL)
1690 1667 (void) (tm_tar_ops.tm_putdir)(fullpath, bpp->bp_tlmacl,
1691 1668 bpp->bp_lcmd, bpp->bp_js);
1692 1669
1693 1670 apos = tlm_get_data_offset(bpp->bp_lcmd);
1694 1671 bpp->bp_session->ns_data.dd_module.dm_stats.ms_bytes_processed +=
1695 1672 apos - bpos;
1696 1673
1697 1674 return (0);
1698 1675 }
1699 1676
1700 1677
1701 1678 /*
1702 1679 * backup_filev3
1703 1680 *
1704 1681 * Backup a file and update the bytes processed field of the
1705 1682 * data server.
1706 1683 *
1707 1684 * Parameters:
1708 1685 * bpp (input) - pointer to the backup parameters structure
1709 1686 * pnp (input) - pointer to the path node
1710 1687 * enp (input) - pointer to the entry node
|
↓ open down ↓ |
34 lines elided |
↑ open up ↑ |
1711 1688 *
1712 1689 * Returns:
1713 1690 * 0: on success
1714 1691 * != 0: otherwise
1715 1692 */
1716 1693 static int
1717 1694 backup_filev3(bk_param_v3_t *bpp, fst_node_t *pnp,
1718 1695 fst_node_t *enp)
1719 1696 {
1720 1697 char *ent;
1721 - longlong_t rv;
1698 + int rv = -1;
1722 1699 longlong_t apos, bpos;
1723 1700 acl_t *aclp = NULL;
1724 1701 char *acltp;
1725 1702 struct stat64 st;
1726 1703 char fullpath[TLM_MAX_PATH_NAME];
1727 1704 char *p;
1728 1705
1729 1706 if (!bpp || !pnp || !enp) {
1730 - NDMP_LOG(LOG_DEBUG, "Invalid argument");
1707 + syslog(LOG_ERR, "Invalid argument in backup_filev3");
1731 1708 return (-1);
1732 1709 }
1733 1710
1734 - NDMP_LOG(LOG_DEBUG, "f(%s)", bpp->bp_tmp);
1735 -
1736 1711 if (lstat64(bpp->bp_tmp, &st) != 0)
1737 1712 return (0);
1738 1713
1739 1714 if (!S_ISLNK(bpp->bp_tlmacl->acl_attr.st_mode)) {
1740 1715 if (acl_get(bpp->bp_tmp, ACL_NO_TRIVIAL, &aclp) != 0) {
1741 - NDMP_LOG(LOG_DEBUG, "acl_get error");
1716 + syslog(LOG_DEBUG, "acl_get error");
1742 1717 return (-1);
1743 1718 }
1744 1719
1745 1720 if (aclp &&
1746 1721 (acltp = acl_totext(aclp,
1747 1722 ACL_APPEND_ID | ACL_SID_FMT | ACL_COMPACT_FMT)) != NULL) {
1748 1723 (void) strlcpy(bpp->bp_tlmacl->acl_info.attr_info,
1749 1724 acltp, TLM_MAX_ACL_TXT);
1750 1725 acl_free(aclp);
1751 1726 free(acltp);
1752 1727 } else {
1753 1728 *bpp->bp_tlmacl->acl_info.attr_info = '\0';
1754 1729 }
1755 1730 }
1756 1731
1757 1732 bpos = tlm_get_data_offset(bpp->bp_lcmd);
1758 1733 ent = enp->tn_path ? enp->tn_path : "";
1759 1734
1760 1735 p = pnp->tn_path + strlen(bpp->bp_chkpnm);
1761 1736 if (*p == '/')
1762 1737 (void) snprintf(fullpath, TLM_MAX_PATH_NAME, "%s%s",
1763 1738 bpp->bp_unchkpnm, p);
1764 1739 else
1765 1740 (void) snprintf(fullpath, TLM_MAX_PATH_NAME, "%s/%s",
1766 1741 bpp->bp_unchkpnm, p);
1767 1742
1768 1743 if (tm_tar_ops.tm_putfile != NULL)
1769 1744 rv = (tm_tar_ops.tm_putfile)(fullpath, ent, pnp->tn_path,
1770 1745 bpp->bp_tlmacl, bpp->bp_cmds, bpp->bp_lcmd, bpp->bp_js,
1771 1746 bpp->bp_session->hardlink_q);
1772 1747
1773 1748 apos = tlm_get_data_offset(bpp->bp_lcmd);
1774 1749 bpp->bp_session->ns_data.dd_module.dm_stats.ms_bytes_processed +=
1775 1750 apos - bpos;
1776 1751
1777 1752 return (rv < 0 ? rv : 0);
1778 1753 }
1779 1754
1780 1755
1781 1756 /*
1782 1757 * check_bk_args
1783 1758 *
1784 1759 * Check the argument of the bpp. This is shared function between
1785 1760 * timebk_v3 and lbrbk_v3 functions. The checks include:
1786 1761 * - The bpp itself.
1787 1762 * - If the session pointer of the bpp is valid.
1788 1763 * - If the session connection to the DMA is closed.
1789 1764 * - If the nlp pointer of the bpp is valid.
1790 1765 * - If the backup is aborted.
1791 1766 *
1792 1767 * Parameters:
1793 1768 * bpp (input) - pointer to the backup parameters structure
1794 1769 *
1795 1770 * Returns:
|
↓ open down ↓ |
44 lines elided |
↑ open up ↑ |
1796 1771 * 0: if everything's OK
1797 1772 * != 0: otherwise
1798 1773 */
1799 1774 static int
1800 1775 check_bk_args(bk_param_v3_t *bpp)
1801 1776 {
1802 1777 int rv;
1803 1778
1804 1779 if (!bpp) {
1805 1780 rv = -1;
1806 - NDMP_LOG(LOG_DEBUG, "Lost bpp");
1781 + syslog(LOG_DEBUG, "Lost bpp");
1807 1782 } else if (!bpp->bp_session) {
1808 1783 rv = -1;
1809 - NDMP_LOG(LOG_DEBUG, "Session is NULL");
1784 + syslog(LOG_DEBUG, "Session is NULL");
1810 1785 } else if (bpp->bp_session->ns_eof) {
1811 1786 rv = -1;
1812 - NDMP_LOG(LOG_INFO,
1787 + syslog(LOG_INFO,
1813 1788 "Connection client is closed for backup \"%s\"",
1814 1789 bpp->bp_nlp->nlp_backup_path);
1815 1790 } else if (!bpp->bp_nlp) {
1816 - NDMP_LOG(LOG_DEBUG, "Lost nlp");
1791 + syslog(LOG_DEBUG, "Lost nlp");
1817 1792 return (-1);
1818 1793 } else if (bpp->bp_session->ns_data.dd_abort) {
1819 1794 rv = -1;
1820 - NDMP_LOG(LOG_INFO, "Backup aborted \"%s\"",
1795 + syslog(LOG_INFO, "Backup aborted \"%s\"",
1821 1796 bpp->bp_nlp->nlp_backup_path);
1822 1797 } else
1823 1798 rv = 0;
1824 1799
1825 1800 return (rv);
1826 1801 }
1827 1802
1828 1803
1829 1804 /*
1830 1805 * shouldskip
1831 1806 *
1832 1807 * Determines if the current entry should be skipped or it
1833 1808 * should be backed up.
1834 1809 *
1835 1810 * Parameters:
1836 1811 * bpp (input) - pointer to the backup parameters structure
1837 1812 * pnp (input) - pointer to the path node
1838 1813 * enp (input) - pointer to the entry node
1839 1814 * errp (output) - pointer to the error value that should be
1840 1815 * returned by the caller
1841 1816 *
1842 1817 * Returns:
1843 1818 * TRUE: if the entry should not be backed up
1844 1819 * FALSE: otherwise
|
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
1845 1820 */
1846 1821 static boolean_t
1847 1822 shouldskip(bk_param_v3_t *bpp, fst_node_t *pnp,
1848 1823 fst_node_t *enp, int *errp)
1849 1824 {
1850 1825 char *ent;
1851 1826 boolean_t rv;
1852 1827 struct stat64 *estp;
1853 1828
1854 1829 if (!bpp || !pnp || !enp || !errp) {
1855 - NDMP_LOG(LOG_DEBUG, "Invalid argument");
1830 + syslog(LOG_DEBUG, "Invalid argument in shouldskip");
1856 1831 return (TRUE);
1857 1832 }
1858 1833
1859 1834 if (!enp->tn_path) {
1860 1835 ent = "";
1861 1836 estp = pnp->tn_st;
1862 1837 } else {
1863 1838 ent = enp->tn_path;
1864 1839 estp = enp->tn_st;
1865 1840 }
1866 1841
1867 1842 /*
1868 1843 * When excluding or skipping entries, FST_SKIP should be
1869 1844 * returned, otherwise, 0 should be returned to
1870 1845 * get other entries in the directory of this entry.
1871 1846 */
1872 1847 if (!dbm_getone(bpp->bp_nlp->nlp_bkmap, (u_longlong_t)estp->st_ino)) {
1873 1848 rv = TRUE;
1874 1849 *errp = S_ISDIR(estp->st_mode) ? FST_SKIP : 0;
1875 - NDMP_LOG(LOG_DEBUG, "Skipping %d %s/%s",
1876 - *errp, pnp->tn_path, ent);
1877 1850 } else if (tlm_is_excluded(pnp->tn_path, ent, bpp->bp_excls)) {
1878 1851 rv = TRUE;
1879 1852 *errp = S_ISDIR(estp->st_mode) ? FST_SKIP : 0;
1880 - NDMP_LOG(LOG_DEBUG, "excl %d \"%s/%s\"",
1881 - *errp, pnp->tn_path, ent);
1882 1853 } else if (inexl(bpp->bp_nlp->nlp_exl, ent)) {
1883 1854 rv = TRUE;
1884 1855 *errp = S_ISDIR(estp->st_mode) ? FST_SKIP : 0;
1885 - NDMP_LOG(LOG_DEBUG, "out %d \"%s/%s\"",
1886 - *errp, pnp->tn_path, ent);
1887 1856 } else if (!S_ISDIR(estp->st_mode) &&
1888 1857 !ininc(bpp->bp_nlp->nlp_inc, ent)) {
1889 1858 rv = TRUE;
1890 1859 *errp = 0;
1891 - NDMP_LOG(LOG_DEBUG, "!in \"%s/%s\"", pnp->tn_path, ent);
1892 1860 } else
1893 1861 rv = FALSE;
1894 1862
1895 1863 return (rv);
1896 1864 }
1897 1865
1898 1866
1899 1867 /*
1900 1868 * ischngd
1901 1869 *
1902 1870 * Check if the object specified should be backed up or not.
1903 1871 * If stp belongs to a directory and if it is marked in the
1904 1872 * bitmap vector, it shows that either the directory itself is
1905 1873 * modified or there is something below it that will be backed
1906 1874 * up.
1907 1875 *
1908 1876 * By setting ndmp_force_bk_dirs global variable to a non-zero
1909 1877 * value, directories are backed up anyways.
1910 1878 *
1911 1879 * Backing up the directories unconditionally helps
1912 1880 * restoring the metadata of directories as well, when one
1913 1881 * of the objects below them are being restored.
1914 1882 *
1915 1883 * For non-directory objects, if the modification or change
|
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
1916 1884 * time of the object is after the date specified by the
1917 1885 * bk_selector_t, the the object must be backed up.
1918 1886 */
1919 1887 static boolean_t
1920 1888 ischngd(struct stat64 *stp, time_t t, ndmp_lbr_params_t *nlp)
1921 1889 {
1922 1890 boolean_t rv;
1923 1891
1924 1892 if (!stp) {
1925 1893 rv = FALSE;
1926 - NDMP_LOG(LOG_DEBUG, "stp is NULL");
1894 + syslog(LOG_DEBUG, "stp is NULL");
1927 1895 } else if (!nlp) {
1928 1896 rv = FALSE;
1929 - NDMP_LOG(LOG_DEBUG, "nlp is NULL");
1897 + syslog(LOG_DEBUG, "nlp is NULL");
1930 1898 } else if (t == 0) {
1931 1899 /*
1932 1900 * if we are doing base backup then we do not need to
1933 1901 * check the time, for we should backup everything.
1934 1902 */
1935 1903 rv = TRUE;
1936 - NDMP_LOG(LOG_DEBUG, "Base Backup");
1937 1904 } else if (S_ISDIR(stp->st_mode) && ndmp_force_bk_dirs) {
1938 1905 rv = TRUE;
1939 - NDMP_LOG(LOG_DEBUG, "d(%lu)", (uint_t)stp->st_ino);
1940 1906 } else if (S_ISDIR(stp->st_mode) &&
1941 1907 dbm_getone(nlp->nlp_bkmap, (u_longlong_t)stp->st_ino) &&
1942 1908 ((NLP_ISDUMP(nlp) && ndmp_dump_path_node) ||
1943 1909 (NLP_ISTAR(nlp) && ndmp_tar_path_node))) {
1944 1910 /*
1945 1911 * If the object is a directory and it leads to a modified
1946 1912 * object (that should be backed up) and for that type of
1947 1913 * backup the path nodes should be backed up, then return
1948 1914 * TRUE.
1949 1915 *
1950 1916 * This is required by some DMAs like Backup Express, which
1951 1917 * needs to receive ADD_NODE (for dump) or ADD_PATH (for tar)
1952 1918 * for the intermediate directories of a modified object.
1953 1919 * Other DMAs, like net_backup and net_worker, do not have such
1954 1920 * requirement. This requirement makes sense for dump format
1955 1921 * but for 'tar' format, it does not. In provision to the
1956 1922 * NDMP-v4 spec, for 'tar' format the intermediate directories
1957 1923 * need not to be reported.
1958 1924 */
1959 1925 rv = TRUE;
1960 - NDMP_LOG(LOG_DEBUG, "p(%lu)", (u_longlong_t)stp->st_ino);
1961 1926 } else if (stp->st_mtime > t) {
1962 1927 rv = TRUE;
1963 - NDMP_LOG(LOG_DEBUG, "m(%lu): %lu > %lu",
1964 - (uint_t)stp->st_ino, (uint_t)stp->st_mtime, (uint_t)t);
1965 1928 } else if (stp->st_ctime > t) {
1966 1929 if (NLP_IGNCTIME(nlp)) {
1967 1930 rv = FALSE;
1968 - NDMP_LOG(LOG_DEBUG, "ign c(%lu): %lu > %lu",
1931 + syslog(LOG_DEBUG, "ign c(%lu): %lu > %lu",
1969 1932 (uint_t)stp->st_ino, (uint_t)stp->st_ctime,
1970 1933 (uint_t)t);
1971 1934 } else {
1972 1935 rv = TRUE;
1973 - NDMP_LOG(LOG_DEBUG, "c(%lu): %lu > %lu",
1936 + syslog(LOG_DEBUG, "c(%lu): %lu > %lu",
1974 1937 (uint_t)stp->st_ino, (uint_t)stp->st_ctime,
1975 1938 (uint_t)t);
1976 1939 }
1977 1940 } else {
1978 1941 rv = FALSE;
1979 - NDMP_LOG(LOG_DEBUG, "mc(%lu): (%lu,%lu) < %lu",
1942 + syslog(LOG_DEBUG, "mc(%lu): (%lu,%lu) < %lu",
1980 1943 (uint_t)stp->st_ino, (uint_t)stp->st_mtime,
1981 1944 (uint_t)stp->st_ctime, (uint_t)t);
1982 1945 }
1983 1946
1984 1947 return (rv);
1985 1948 }
1986 1949
1987 1950
1988 1951 /*
1989 1952 * iscreated
1990 1953 *
1991 1954 * This function is used to check last mtime (currently inside the ACL
1992 1955 * structure) instead of ctime for checking if the file is to be backed up
|
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
1993 1956 * or not. See option "inc.lmtime" for more details
1994 1957 */
1995 1958 /*ARGSUSED*/
1996 1959 int iscreated(ndmp_lbr_params_t *nlp, char *name, tlm_acls_t *tacl,
1997 1960 time_t t)
1998 1961 {
1999 1962 int ret;
2000 1963 acl_t *aclp = NULL;
2001 1964 char *acltp;
2002 1965
2003 - NDMP_LOG(LOG_DEBUG, "flags %x", nlp->nlp_flags);
1966 + syslog(LOG_DEBUG, "flags %x", nlp->nlp_flags);
2004 1967 if (NLP_INCLMTIME(nlp) == FALSE)
2005 1968 return (0);
2006 1969
2007 1970 ret = acl_get(name, ACL_NO_TRIVIAL, &aclp);
2008 1971 if (ret != 0) {
2009 - NDMP_LOG(LOG_DEBUG,
1972 + syslog(LOG_DEBUG,
2010 1973 "Error getting the acl information: err %d", ret);
2011 1974 return (0);
2012 1975 }
2013 1976 if (aclp && (acltp = acl_totext(aclp,
2014 1977 ACL_APPEND_ID | ACL_SID_FMT | ACL_COMPACT_FMT)) != NULL) {
2015 1978 (void) strlcpy(tacl->acl_info.attr_info, acltp,
2016 1979 TLM_MAX_ACL_TXT);
2017 1980 acl_free(aclp);
2018 1981 free(acltp);
2019 1982 }
2020 1983
2021 1984 /* Need to add support for last mtime */
2022 1985
2023 1986 return (0);
2024 1987 }
2025 1988
2026 1989 /*
2027 1990 * size_cb
2028 1991 *
2029 1992 * The callback function for calculating the size of
2030 1993 * the backup path. This is used to get an estimate
2031 1994 * of the progress of backup during NDMP backup
2032 1995 */
2033 1996 static int
2034 1997 size_cb(void *arg, fst_node_t *pnp, fst_node_t *enp)
2035 1998 {
2036 1999 struct stat64 *stp;
2037 2000
2038 2001 stp = enp->tn_path ? enp->tn_st : pnp->tn_st;
2039 2002 *((u_longlong_t *)arg) += stp->st_size;
2040 2003
2041 2004 return (0);
2042 2005 }
2043 2006
2044 2007 /*
2045 2008 * timebk_v3
2046 2009 *
2047 2010 * The callback function for backing up objects based on
2048 2011 * their time stamp. This is shared between token-based
2049 2012 * and level-based backup, which look at the time stamps
2050 2013 * of the objects to determine if they should be backed
2051 2014 * up.
2052 2015 *
2053 2016 * Parameters:
2054 2017 * arg (input) - pointer to the backup parameters structure
2055 2018 * pnp (input) - pointer to the path node
2056 2019 * enp (input) - pointer to the entry node
2057 2020 *
2058 2021 * Returns:
2059 2022 * 0: if backup should continue
2060 2023 * -1: if the backup should be stopped
2061 2024 * FST_SKIP: if backing up the current directory is enough
2062 2025 */
2063 2026 static int
2064 2027 timebk_v3(void *arg, fst_node_t *pnp, fst_node_t *enp)
2065 2028 {
2066 2029 char *ent;
2067 2030 int rv;
2068 2031 time_t t;
2069 2032 bk_param_v3_t *bpp;
2070 2033 struct stat64 *stp;
2071 2034 fs_fhandle_t *fhp;
2072 2035
2073 2036 bpp = (bk_param_v3_t *)arg;
2074 2037
2075 2038 rv = check_bk_args(bpp);
2076 2039 if (rv != 0)
2077 2040 return (rv);
2078 2041
2079 2042 stp = enp->tn_path ? enp->tn_st : pnp->tn_st;
2080 2043 if (shouldskip(bpp, pnp, enp, &rv))
2081 2044 return (rv);
2082 2045
2083 2046 if (enp->tn_path) {
2084 2047 ent = enp->tn_path;
|
↓ open down ↓ |
65 lines elided |
↑ open up ↑ |
2085 2048 stp = enp->tn_st;
2086 2049 fhp = enp->tn_fh;
2087 2050 } else {
2088 2051 ent = "";
2089 2052 stp = pnp->tn_st;
2090 2053 fhp = pnp->tn_fh;
2091 2054 }
2092 2055
2093 2056
2094 2057 if (!tlm_cat_path(bpp->bp_tmp, pnp->tn_path, ent)) {
2095 - NDMP_LOG(LOG_ERR, "Path too long %s/%s.", pnp->tn_path, ent);
2058 + syslog(LOG_ERR, "Path too long %s/%s.", pnp->tn_path, ent);
2096 2059 return (FST_SKIP);
2097 2060 }
2098 2061 if (NLP_ISSET(bpp->bp_nlp, NLPF_TOKENBK))
2099 2062 t = bpp->bp_nlp->nlp_tokdate;
2100 2063 else if (NLP_ISSET(bpp->bp_nlp, NLPF_LEVELBK)) {
2101 2064 t = bpp->bp_nlp->nlp_ldate;
2102 2065 } else {
2103 - NDMP_LOG(LOG_DEBUG, "Unknown backup type on \"%s/%s\"",
2066 + syslog(LOG_ERR, "Unknown backup type on \"%s/%s\"",
2104 2067 pnp->tn_path, ent);
2105 2068 return (-1);
2106 2069 }
2107 2070
2108 2071 if (S_ISDIR(stp->st_mode)) {
2109 2072 bpp->bp_tlmacl->acl_dir_fh = *fhp;
2110 2073 (void) ndmpd_fhdir_v3_cb(bpp->bp_nlp->nlp_logcallbacks,
2111 2074 bpp->bp_tmp, stp);
2112 2075
2113 2076 if (ischngd(stp, t, bpp->bp_nlp)) {
2114 2077 (void) memcpy(&bpp->bp_tlmacl->acl_attr, stp,
2115 2078 sizeof (struct stat64));
2116 2079 rv = backup_dirv3(bpp, pnp, enp);
2117 2080 }
2118 2081 } else {
2119 2082 if (ischngd(stp, t, bpp->bp_nlp) ||
2120 2083 iscreated(bpp->bp_nlp, bpp->bp_tmp, bpp->bp_tlmacl, t)) {
2121 2084 rv = 0;
2122 2085 (void) memcpy(&bpp->bp_tlmacl->acl_attr, stp,
2123 2086 sizeof (struct stat64));
2124 2087 bpp->bp_tlmacl->acl_fil_fh = *fhp;
2125 2088 (void) backup_filev3(bpp, pnp, enp);
2126 2089 }
2127 2090 }
2128 2091
2129 2092 return (rv);
2130 2093 }
2131 2094
2132 2095
2133 2096 /*
2134 2097 * lbrbk_v3
2135 2098 *
2136 2099 * The callback function for backing up objects based on
2137 2100 * their archive directory bit. This is used in LBR-type
2138 2101 * backup. In which the objects are backed up if their
2139 2102 * archive bit is set.
2140 2103 *
2141 2104 * Parameters:
2142 2105 * arg (input) - pointer to the backup parameters structure
2143 2106 * pnp (input) - pointer to the path node
2144 2107 * enp (input) - pointer to the entry node
2145 2108 *
2146 2109 * Returns:
2147 2110 * 0: if backup should continue
2148 2111 * -1: if the backup should be stopped
2149 2112 * FST_SKIP: if backing up the current directory is enough
2150 2113 */
2151 2114 static int
2152 2115 lbrbk_v3(void *arg, fst_node_t *pnp, fst_node_t *enp)
2153 2116 {
2154 2117 char *ent;
2155 2118 int rv;
2156 2119 bk_param_v3_t *bpp;
2157 2120 struct stat64 *stp;
2158 2121 fs_fhandle_t *fhp;
2159 2122
2160 2123 bpp = (bk_param_v3_t *)arg;
2161 2124 rv = check_bk_args(bpp);
2162 2125 if (rv != 0)
2163 2126 return (rv);
2164 2127
2165 2128 stp = enp->tn_path ? enp->tn_st : pnp->tn_st;
2166 2129 if (shouldskip(bpp, pnp, enp, &rv))
2167 2130 return (rv);
2168 2131
2169 2132 if (enp->tn_path) {
|
↓ open down ↓ |
56 lines elided |
↑ open up ↑ |
2170 2133 ent = enp->tn_path;
2171 2134 stp = enp->tn_st;
2172 2135 fhp = enp->tn_fh;
2173 2136 } else {
2174 2137 ent = "";
2175 2138 stp = pnp->tn_st;
2176 2139 fhp = pnp->tn_fh;
2177 2140 }
2178 2141
2179 2142 if (!tlm_cat_path(bpp->bp_tmp, pnp->tn_path, ent)) {
2180 - NDMP_LOG(LOG_ERR, "Path too long %s/%s.", pnp->tn_path, ent);
2143 + syslog(LOG_ERR, "Path too long %s/%s.", pnp->tn_path, ent);
2181 2144 return (FST_SKIP);
2182 2145 }
2183 2146 if (!NLP_ISSET(bpp->bp_nlp, NLPF_LBRBK)) {
2184 - NDMP_LOG(LOG_DEBUG, "!NLPF_LBRBK");
2147 + syslog(LOG_DEBUG, "!NLPF_LBRBK");
2185 2148 return (-1);
2186 2149 }
2187 2150
2188 2151 if (S_ISDIR(stp->st_mode)) {
2189 2152 bpp->bp_tlmacl->acl_dir_fh = *fhp;
2190 2153 (void) ndmpd_fhdir_v3_cb(bpp->bp_nlp->nlp_logcallbacks,
2191 2154 bpp->bp_tmp, stp);
2192 2155
2193 2156 if (SHOULD_LBRBK(bpp)) {
2194 2157 bpp->bp_tlmacl->acl_attr = *stp;
2195 2158 rv = backup_dirv3(bpp, pnp, enp);
2196 2159 }
2197 2160 } else if (SHOULD_LBRBK(bpp)) {
2198 2161 rv = 0;
2199 2162 bpp->bp_tlmacl->acl_attr = *stp;
2200 2163 bpp->bp_tlmacl->acl_fil_fh = *fhp;
2201 2164 (void) backup_filev3(bpp, pnp, enp);
2202 2165 }
2203 2166
2204 2167 return (rv);
2205 2168 }
|
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
2206 2169
2207 2170
2208 2171 /*
2209 2172 * backup_reader_v3
2210 2173 *
2211 2174 * The reader thread for the backup. It sets up the callback
2212 2175 * parameters and traverses the backup hierarchy in level-order
2213 2176 * way.
2214 2177 *
2215 2178 * Parameters:
2216 - * jname (input) - name assigned to the current backup for
2217 - * job stats strucure
2218 - * nlp (input) - pointer to the nlp structure
2219 - * cmds (input) - pointer to the tlm_commands_t structure
2179 + * argp (input) - backup reader argument
2220 2180 *
2221 2181 * Returns:
2222 2182 * 0: on success
2223 2183 * != 0: otherwise
2224 2184 */
2225 2185 static int
2226 2186 backup_reader_v3(backup_reader_arg_t *argp)
2227 2187 {
2228 2188 int rv;
2229 2189 tlm_cmd_t *lcmd;
2230 2190 tlm_acls_t tlm_acls;
2231 2191 longlong_t bpos, n;
2232 2192 bk_param_v3_t bp;
2233 2193 fs_traverse_t ft;
2234 - char *jname;
2235 2194 ndmp_lbr_params_t *nlp;
2236 2195 tlm_commands_t *cmds;
2196 + int rc;
2237 2197
2238 2198 if (!argp)
2239 2199 return (-1);
2240 2200
2241 - jname = argp->br_jname;
2242 2201 nlp = argp->br_nlp;
2243 2202 cmds = argp->br_cmds;
2244 2203
2245 2204 rv = 0;
2246 2205 lcmd = cmds->tcs_command;
2247 2206 lcmd->tc_ref++;
2248 2207 cmds->tcs_reader_count++;
2249 2208
2250 2209 (void) memset(&tlm_acls, 0, sizeof (tlm_acls));
2251 2210
2252 2211 /* NDMP parameters */
2253 2212 bp.bp_session = nlp->nlp_session;
2254 2213 bp.bp_nlp = nlp;
2255 2214
2256 2215 /* LBR-related parameters */
2257 - bp.bp_js = tlm_ref_job_stats(jname);
2216 + bp.bp_js = tlm_ref_job_stats(nlp->nlp_job_name);
2258 2217 bp.bp_cmds = cmds;
2259 2218 bp.bp_lcmd = lcmd;
2260 2219 bp.bp_tlmacl = &tlm_acls;
2261 2220 bp.bp_opr = 0;
2262 2221
2263 2222 /* release the parent thread, after referencing the job stats */
2264 - (void) pthread_barrier_wait(&argp->br_barrier);
2223 + rc = pthread_barrier_wait(&argp->br_barrier);
2224 + if (rc == PTHREAD_BARRIER_SERIAL_THREAD) {
2225 + (void) pthread_barrier_destroy(&argp->br_barrier);
2226 + }
2265 2227
2266 2228 bp.bp_tmp = ndmp_malloc(sizeof (char) * TLM_MAX_PATH_NAME);
2267 2229 if (!bp.bp_tmp)
2268 2230 return (-1);
2269 2231
2270 2232 /*
2271 2233 * Make the checkpointed paths for traversing the
2272 2234 * backup hierarchy, if we make the checkpoint.
2273 2235 */
2274 2236 bp.bp_unchkpnm = nlp->nlp_backup_path;
2275 2237 if (!NLP_ISCHKPNTED(nlp)) {
2276 - tlm_acls.acl_checkpointed = TRUE;
2238 + tlm_acls.acl_checkpointed = FALSE;
2277 2239 bp.bp_chkpnm = ndmp_malloc(sizeof (char) * TLM_MAX_PATH_NAME);
2278 2240 if (!bp.bp_chkpnm) {
2279 2241 NDMP_FREE(bp.bp_tmp);
2280 2242 return (-1);
2281 2243 }
2282 2244 (void) tlm_build_snapshot_name(nlp->nlp_backup_path,
2283 2245 bp.bp_chkpnm, nlp->nlp_jstat->js_job_name);
2284 2246 } else {
2285 - tlm_acls.acl_checkpointed = FALSE;
2286 - bp.bp_chkpnm = nlp->nlp_backup_path;
2247 + tlm_acls.acl_checkpointed = TRUE;
2248 + bp.bp_chkpnm = nlp->nlp_mountpoint;
2287 2249 }
2288 2250 bp.bp_excls = ndmpd_make_exc_list();
2289 2251
2290 2252 /* set traversing arguments */
2291 2253 ft.ft_path = nlp->nlp_backup_path;
2292 2254 ft.ft_lpath = bp.bp_chkpnm;
2293 2255
2294 - NDMP_LOG(LOG_DEBUG, "path %s lpath %s", ft.ft_path, ft.ft_lpath);
2295 2256 if (NLP_ISSET(nlp, NLPF_TOKENBK) || NLP_ISSET(nlp, NLPF_LEVELBK)) {
2296 2257 ft.ft_callbk = timebk_v3;
2297 2258 tlm_acls.acl_clear_archive = FALSE;
2298 2259 } else if (NLP_ISSET(nlp, NLPF_LBRBK)) {
2299 2260 ft.ft_callbk = lbrbk_v3;
2300 2261 tlm_acls.acl_clear_archive = FALSE;
2301 2262
2302 - NDMP_LOG(LOG_DEBUG, "bp_opr %x clr_arc %c",
2263 + syslog(LOG_DEBUG, "bp_opr %x clr_arc %c",
2303 2264 bp.bp_opr, NDMP_YORN(tlm_acls.acl_clear_archive));
2304 2265 } else {
2305 2266 rv = -1;
2306 2267 MOD_LOGV3(nlp->nlp_params, NDMP_LOG_ERROR,
2307 - "Unknow backup type.\n");
2268 + "Unknown backup type.\n");
2308 2269 }
2270 +
2309 2271 ft.ft_arg = &bp;
2310 - ft.ft_logfp = (ft_log_t)ndmp_log;
2272 + ft.ft_logfp = (ft_log_t)syslog;
2311 2273 ft.ft_flags = FST_VERBOSE | FST_STOP_ONERR;
2312 2274
2275 + syslog(LOG_DEBUG, "Traverse logical path [%s]", ft.ft_lpath);
2276 +
2313 2277 /* take into account the header written to the stream so far */
2314 2278 n = tlm_get_data_offset(lcmd);
2315 2279 nlp->nlp_session->ns_data.dd_module.dm_stats.ms_bytes_processed = n;
2316 2280
2317 2281 if (rv == 0) {
2318 2282 /* start traversing the hierarchy and actual backup */
2319 2283 rv = traverse_level(&ft);
2320 2284 if (rv == 0) {
2321 2285 /* write the trailer and update the bytes processed */
2322 2286 bpos = tlm_get_data_offset(lcmd);
2323 2287 (void) write_tar_eof(lcmd);
2324 2288 n = tlm_get_data_offset(lcmd) - bpos;
2325 2289 nlp->nlp_session->
2326 2290 ns_data.dd_module.dm_stats.ms_bytes_processed += n;
2327 2291 } else {
2328 2292 MOD_LOGV3(nlp->nlp_params, NDMP_LOG_ERROR,
2329 2293 "Filesystem traverse error.\n");
2330 2294 ndmpd_data_error(nlp->nlp_session,
2331 2295 NDMP_DATA_HALT_INTERNAL_ERROR);
2332 2296 }
|
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
2333 2297 }
2334 2298
2335 2299 if (!NLP_ISCHKPNTED(nlp))
2336 2300 NDMP_FREE(bp.bp_chkpnm);
2337 2301 NDMP_FREE(bp.bp_tmp);
2338 2302 NDMP_FREE(bp.bp_excls);
2339 2303
2340 2304 cmds->tcs_reader_count--;
2341 2305 lcmd->tc_writer = TLM_STOP;
2342 2306 tlm_release_reader_writer_ipc(lcmd);
2343 - tlm_un_ref_job_stats(jname);
2344 - return (rv);
2307 + tlm_un_ref_job_stats(nlp->nlp_job_name);
2345 2308
2309 + return (rv);
2346 2310 }
2347 2311
2348 2312
2349 2313 /*
2350 2314 * tar_backup_v3
2351 2315 *
2352 2316 * Traverse the backup hierarchy if needed and make the bitmap.
2353 2317 * Then launch reader and writer threads to do the actual backup.
2354 2318 *
2355 2319 * Parameters:
2356 2320 * session (input) - pointer to the session
2357 2321 * params (input) - pointer to the parameters structure
2358 2322 * nlp (input) - pointer to the nlp structure
2359 - * jname (input) - job name
2360 2323 *
2361 2324 * Returns:
2362 2325 * 0: on success
2363 2326 * != 0: otherwise
2364 2327 */
2365 2328 static int
2366 2329 tar_backup_v3(ndmpd_session_t *session, ndmpd_module_params_t *params,
2367 - ndmp_lbr_params_t *nlp, char *jname)
2330 + ndmp_lbr_params_t *nlp)
2368 2331 {
2369 2332 tlm_commands_t *cmds;
2370 2333 backup_reader_arg_t arg;
2371 2334 pthread_t rdtp;
2372 2335 char info[256];
2373 2336 int result;
2374 2337 ndmp_context_t nctx;
2375 2338 int err;
2339 + int rc;
2376 2340
2377 - if (ndmp_get_bk_dir_ino(nlp))
2341 + if (ndmp_get_bk_dir_ino(nlp)) {
2342 + syslog(LOG_ERR, "Couldn't get backup directory inode");
2378 2343 return (-1);
2344 + }
2379 2345
2380 2346 result = err = 0;
2381 2347
2382 2348 /* exit as if there was an internal error */
2383 - if (session->ns_eof)
2349 + if (session->ns_eof) {
2384 2350 return (-1);
2385 -
2351 + }
2386 2352 if (!session->ns_data.dd_abort) {
2387 - if (backup_alloc_structs_v3(session, jname) < 0) {
2353 + if (backup_alloc_structs_v3(session) < 0) {
2388 2354 nlp->nlp_bkmap = -1;
2389 2355 return (-1);
2390 2356 }
2391 2357
2392 2358 if (ndmpd_mark_inodes_v3(session, nlp) != 0) {
2393 2359 if (nlp->nlp_bkmap != -1) {
2394 2360 (void) dbm_free(nlp->nlp_bkmap);
2395 2361 nlp->nlp_bkmap = -1;
2396 2362 }
2397 - free_structs_v3(session, jname);
2363 + free_structs_v3(session);
2398 2364 return (-1);
2399 2365 }
2400 2366
2401 2367 nlp->nlp_jstat->js_start_ltime = time(NULL);
2402 2368 nlp->nlp_jstat->js_start_time = nlp->nlp_jstat->js_start_ltime;
2403 2369 nlp->nlp_jstat->js_chkpnt_time = nlp->nlp_cdate;
2404 2370
2405 2371 cmds = &nlp->nlp_cmds;
2406 2372 cmds->tcs_reader = cmds->tcs_writer = TLM_BACKUP_RUN;
2407 2373 cmds->tcs_command->tc_reader = TLM_BACKUP_RUN;
2408 2374 cmds->tcs_command->tc_writer = TLM_BACKUP_RUN;
2409 2375
2410 2376 if (ndmp_write_utf8magic(cmds->tcs_command) < 0) {
2411 - free_structs_v3(session, jname);
2377 + free_structs_v3(session);
2412 2378 return (-1);
2413 2379 }
2414 2380
2415 - NDMP_LOG(LOG_DEBUG,
2416 - "Backing up \"%s\" started.", nlp->nlp_backup_path);
2381 + syslog(LOG_DEBUG, "Backing up \"%s\" started.",
2382 + NLP_ISCHKPNTED(nlp)
2383 + ? nlp->nlp_mountpoint : nlp->nlp_backup_path);
2417 2384
2418 2385 /* Plug-in module */
2419 2386 if (ndmp_pl != NULL &&
2420 2387 ndmp_pl->np_pre_backup != NULL) {
2421 2388 (void) memset(&nctx, 0, sizeof (ndmp_context_t));
2422 2389 nctx.nc_plversion = ndmp_pl->np_plversion;
2423 2390 nctx.nc_plname = ndmpd_get_prop(NDMP_PLUGIN_PATH);
2424 2391 nctx.nc_cmds = cmds;
2425 2392 nctx.nc_params = params;
2426 2393 nctx.nc_ddata = (void *) session;
2427 2394 if ((err = ndmp_pl->np_pre_backup(ndmp_pl, &nctx,
2428 2395 nlp->nlp_backup_path)) != 0) {
2429 - NDMP_LOG(LOG_ERR, "Pre-backup plug-in: %m");
2396 + syslog(LOG_ERR, "Pre-backup plug-in: %m");
2430 2397 goto backup_out;
2431 2398 }
2432 2399 }
2433 2400
2434 2401 (void) memset(&arg, 0, sizeof (backup_reader_arg_t));
2435 - arg.br_jname = jname;
2436 2402 arg.br_nlp = nlp;
2437 2403 arg.br_cmds = cmds;
2438 2404
2439 2405 (void) pthread_barrier_init(&arg.br_barrier, 0, 2);
2440 2406
2441 2407 err = pthread_create(&rdtp, NULL, (funct_t)backup_reader_v3,
2442 2408 (void *)&arg);
2443 2409 if (err == 0) {
2444 - (void) pthread_barrier_wait(&arg.br_barrier);
2445 - (void) pthread_barrier_destroy(&arg.br_barrier);
2410 + rc = pthread_barrier_wait(&arg.br_barrier);
2411 + if (rc == PTHREAD_BARRIER_SERIAL_THREAD) {
2412 + (void) pthread_barrier_destroy(&arg.br_barrier);
2413 + }
2446 2414 } else {
2447 2415 (void) pthread_barrier_destroy(&arg.br_barrier);
2448 - free_structs_v3(session, jname);
2449 - NDMP_LOG(LOG_DEBUG, "Launch backup_reader_v3: %m");
2416 + free_structs_v3(session);
2417 + syslog(LOG_ERR, "Launch backup_reader_v3 failed on %s",
2418 + nlp->nlp_job_name);
2450 2419 return (-1);
2451 2420 }
2452 2421
2453 2422 if ((err = ndmp_tar_writer(session, params, cmds)) != 0)
2454 2423 result = EIO;
2455 2424
2456 2425 nlp->nlp_jstat->js_stop_time = time(NULL);
2457 2426
2458 2427 (void) snprintf(info, sizeof (info),
2459 - "Runtime [%s] %llu bytes (%llu): %d seconds\n",
2428 + "Runtime [%s] %lu bytes (%lu): %d seconds\n",
2460 2429 nlp->nlp_backup_path,
2461 2430 session->ns_data.dd_module.dm_stats.ms_bytes_processed,
2462 2431 session->ns_data.dd_module.dm_stats.ms_bytes_processed,
2463 2432 nlp->nlp_jstat->js_stop_time -
2464 2433 nlp->nlp_jstat->js_start_ltime);
2465 2434 MOD_LOGV3(params, NDMP_LOG_NORMAL, info);
2466 2435
2467 2436 ndmp_wait_for_reader(cmds);
2468 2437 (void) pthread_join(rdtp, NULL);
2469 -
2470 2438 /* exit as if there was an internal error */
2471 2439 if (session->ns_eof) {
2472 2440 result = EPIPE;
2473 2441 err = -1;
2474 2442 }
2475 2443 if (!session->ns_data.dd_abort) {
2476 2444 ndmpd_audit_backup(session->ns_connection,
2477 2445 nlp->nlp_backup_path,
2478 2446 session->ns_data.dd_data_addr.addr_type,
2479 2447 session->ns_tape.td_adapter_name, result);
2480 - NDMP_LOG(LOG_DEBUG, "Backing up \"%s\" Finished.",
2481 - nlp->nlp_backup_path);
2448 + syslog(LOG_DEBUG, "Backing up \"%s\" Finished.",
2449 + NLP_ISCHKPNTED(nlp) ?
2450 + nlp->nlp_mountpoint : nlp->nlp_backup_path);
2482 2451 }
2483 2452 }
2484 2453
2485 2454 if (session->ns_data.dd_abort) {
2486 2455 ndmpd_audit_backup(session->ns_connection,
2487 2456 nlp->nlp_backup_path,
2488 2457 session->ns_data.dd_data_addr.addr_type,
2489 2458 session->ns_tape.td_adapter_name, EINTR);
2490 - NDMP_LOG(LOG_DEBUG,
2491 - "Backing up \"%s\" aborted.", nlp->nlp_backup_path);
2459 + syslog(LOG_INFO, "Backing up \"%s\" aborted.",
2460 + NLP_ISCHKPNTED(nlp) ?
2461 + nlp->nlp_mountpoint : nlp->nlp_backup_path);
2492 2462 err = -1;
2493 2463 } else {
2494 2464
2495 2465 backup_out:
2496 2466 /* Plug-in module */
2497 2467 if (ndmp_pl != NULL &&
2498 2468 ndmp_pl->np_post_backup != NULL &&
2499 2469 ndmp_pl->np_post_backup(ndmp_pl, &nctx, err) == -1) {
2500 - NDMP_LOG(LOG_DEBUG, "Post-backup plug-in: %m");
2470 + syslog(LOG_ERR, "Post-backup plug-in: %m");
2501 2471 return (-1);
2502 2472 }
2503 2473 }
2504 2474
2505 - free_structs_v3(session, jname);
2475 + free_structs_v3(session);
2506 2476 return (err);
2507 2477 }
2508 2478
2509 2479 /*
2510 2480 * get_backup_size
2511 2481 *
2512 2482 * Find the estimate of backup size. This is used to get an estimate
2513 2483 * of the progress of backup during NDMP backup.
2514 2484 */
2515 2485 void
2516 -get_backup_size(ndmp_bkup_size_arg_t *sarg)
2486 +get_backup_size(ndmp_lbr_params_t *nlp)
2517 2487 {
2518 2488 fs_traverse_t ft;
2519 - u_longlong_t bk_size;
2489 + u_longlong_t bk_size = 0;
2490 + char buf[256];
2520 2491 char spath[PATH_MAX];
2521 2492 int rv;
2522 2493
2523 - bk_size = 0;
2524 - if (fs_is_chkpntvol(sarg->bs_path)) {
2525 - ft.ft_path = sarg->bs_path;
2494 + if (NLP_ISCHKPNTED(nlp)) {
2495 + ft.ft_path = nlp->nlp_mountpoint;
2526 2496 } else {
2527 - (void) tlm_build_snapshot_name(sarg->bs_path,
2528 - spath, sarg->bs_jname);
2497 + (void) tlm_build_snapshot_name(nlp->nlp_backup_path,
2498 + spath, nlp->nlp_job_name);
2529 2499 ft.ft_path = spath;
2530 2500 }
2531 2501
2532 2502 ft.ft_lpath = ft.ft_path;
2533 2503 ft.ft_callbk = size_cb;
2534 2504 ft.ft_arg = &bk_size;
2535 - ft.ft_logfp = (ft_log_t)ndmp_log;
2505 + ft.ft_logfp = (ft_log_t)syslog;
2536 2506 ft.ft_flags = FST_VERBOSE;
2537 2507
2538 2508 if ((rv = traverse_level(&ft)) != 0) {
2539 - NDMP_LOG(LOG_DEBUG, "bksize err=%d", rv);
2509 + syslog(LOG_DEBUG, "bksize err=%d", rv);
2510 + syslog(LOG_DEBUG, "[%s] backup will be reported as [0]\n",
2511 + nlp->nlp_job_name, buf);
2540 2512 bk_size = 0;
2541 2513 } else {
2542 - NDMP_LOG(LOG_DEBUG, "bksize %lld, %lldKB, %lldMB\n",
2543 - bk_size, bk_size / 1024, bk_size /(1024 * 1024));
2514 + (void) zfs_nicenum(bk_size, buf, sizeof (buf));
2515 + syslog(LOG_DEBUG, "[%s] backup size is [%s]\n",
2516 + nlp->nlp_job_name, buf);
2544 2517 }
2545 - sarg->bs_session->ns_data.dd_data_size = bk_size;
2518 +
2519 + nlp->nlp_session->ns_data.dd_data_size = bk_size;
2546 2520 }
2547 2521
2548 2522 /*
2549 2523 * get_rs_path_v3
2550 2524 *
2551 2525 * Find the restore path
2552 2526 */
2553 2527 ndmp_error
2554 2528 get_rs_path_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp)
2555 2529 {
2556 2530 char *dp;
2557 - ndmp_error rv;
2531 + ndmp_error rv = -1;
2558 2532 mem_ndmp_name_v3_t *ep;
2559 2533 int i, nm_cnt;
2560 2534 char *nm_dpath_list[MULTIPLE_DEST_DIRS];
2561 2535 static char mdest_buf[256];
2562 2536
2563 2537 *mdest_buf = 0;
2564 2538 *nm_dpath_list = "";
2565 2539 for (i = 0, nm_cnt = 0; i < (int)nlp->nlp_nfiles; i++) {
2566 2540 ep = (mem_ndmp_name_v3_t *)MOD_GETNAME(params, i);
2567 2541 if (!ep) {
2568 - NDMP_LOG(LOG_DEBUG, "Can't get Nlist[%d]", i);
2542 + syslog(LOG_ERR, "Can't get Nlist[%d]", i);
2569 2543 return (NDMP_ILLEGAL_ARGS_ERR);
2570 2544 }
2571 2545 if (strcmp(nm_dpath_list[nm_cnt], ep->nm3_dpath) != 0 &&
2572 2546 nm_cnt < MULTIPLE_DEST_DIRS - 1)
2573 2547 nm_dpath_list[++nm_cnt] = ep->nm3_dpath;
2574 2548 }
2575 2549
2576 2550 multiple_dest_restore = (nm_cnt > 1);
2577 2551 nlp->nlp_restore_path = mdest_buf;
2578 2552
2579 2553 for (i = 1; i < nm_cnt + 1; i++) {
2580 2554 if (ISDEFINED(nm_dpath_list[i]))
2581 2555 dp = nm_dpath_list[i];
2582 2556 else
2583 2557 /* the default destination path is backup directory */
2584 2558 dp = nlp->nlp_backup_path;
2585 2559
2586 2560 /* check the destination directory exists and is writable */
2587 2561 if (!fs_volexist(dp)) {
2588 2562 rv = NDMP_ILLEGAL_ARGS_ERR;
2589 2563 MOD_LOGV3(params, NDMP_LOG_ERROR,
|
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
2590 2564 "Invalid destination path volume \"%s\".\n", dp);
2591 2565 } else if (!voliswr(dp)) {
2592 2566 rv = NDMP_ILLEGAL_ARGS_ERR;
2593 2567 MOD_LOGV3(params, NDMP_LOG_ERROR,
2594 2568 "The destination path volume"
2595 2569 " is not writable \"%s\".\n", dp);
2596 2570 } else {
2597 2571 rv = NDMP_NO_ERR;
2598 2572 (void) strlcat(nlp->nlp_restore_path, dp,
2599 2573 sizeof (mdest_buf));
2600 - NDMP_LOG(LOG_DEBUG, "rspath: \"%s\"", dp);
2574 + syslog(LOG_DEBUG, "rspath: \"%s\"", dp);
2601 2575 }
2602 2576
2603 2577 /*
2604 2578 * Exit if there is an error or it is not a multiple
2605 2579 * destination restore mode
2606 2580 */
2607 2581 if (rv != NDMP_NO_ERR || !multiple_dest_restore)
2608 2582 break;
2609 2583
2610 2584 if (i < nm_cnt)
2611 2585 (void) strlcat(nlp->nlp_restore_path, ", ",
2612 2586 sizeof (mdest_buf));
2613 2587 }
2614 2588
2615 2589 return (rv);
2616 2590 }
2617 2591
2618 2592
2619 2593 /*
2620 2594 * fix_nlist_v3
2621 2595 *
2622 2596 * Check if the recovery list is valid and fix it if there are some
2623 2597 * unspecified entries in it. It checks for original, destination
2624 2598 * and new path for all NDMP names provided inside the list.
2625 2599 *
2626 2600 * V3: dpath is the destination directory. If newnm is not NULL, the
2627 2601 * destination path is dpath/newnm. Otherwise the destination path is
2628 2602 * dpath/opath_last_node, where opath_last_node is the last node in opath.
2629 2603 *
2630 2604 * V4: If newnm is not NULL, dpath is the destination directory, and
2631 2605 * dpath/newnm is the destination path. If newnm is NULL, dpath is
2632 2606 * the destination path (opath is not involved in forming destination path).
2633 2607 */
2634 2608 ndmp_error
2635 2609 fix_nlist_v3(ndmpd_session_t *session, ndmpd_module_params_t *params,
2636 2610 ndmp_lbr_params_t *nlp)
2637 2611 {
2638 2612 char *cp, *buf, *bp;
2639 2613 int i, n;
2640 2614 int iswrbk;
2641 2615 int bvexists;
2642 2616 ndmp_error rv;
2643 2617 mem_ndmp_name_v3_t *ep;
2644 2618 char *dp;
2645 2619 char *nm;
2646 2620 int existsvol;
2647 2621 int isrwdst;
2648 2622
2649 2623 buf = ndmp_malloc(TLM_MAX_PATH_NAME);
2650 2624 if (!buf) {
2651 2625 MOD_LOGV3(params, NDMP_LOG_ERROR, "Insufficient memory.\n");
2652 2626 return (NDMP_NO_MEM_ERR);
2653 2627 }
2654 2628
2655 2629 bvexists = fs_volexist(nlp->nlp_backup_path);
2656 2630 iswrbk = voliswr(nlp->nlp_backup_path);
2657 2631
2658 2632 rv = NDMP_NO_ERR;
2659 2633 n = session->ns_data.dd_nlist_len;
2660 2634 for (i = 0; i < n; i++) {
2661 2635 ep = (mem_ndmp_name_v3_t *)MOD_GETNAME(params, i);
2662 2636 if (!ep)
2663 2637 continue;
2664 2638
2665 2639 /* chop off the trailing slashes */
2666 2640 chopslash(ep->nm3_opath);
2667 2641
2668 2642 chopslash(ep->nm3_dpath);
2669 2643 chopslash(ep->nm3_newnm);
2670 2644
2671 2645 /* existing and non-empty destination path */
2672 2646 if (ISDEFINED(ep->nm3_dpath)) {
2673 2647 dp = ep->nm3_dpath;
2674 2648 existsvol = fs_volexist(dp);
2675 2649 isrwdst = voliswr(dp);
2676 2650 } else {
2677 2651 /* the default destination path is backup directory */
2678 2652 dp = nlp->nlp_backup_path;
2679 2653 existsvol = bvexists;
2680 2654 isrwdst = iswrbk;
2681 2655 }
2682 2656
2683 2657 /* check the destination directory exists and is writable */
2684 2658 if (!existsvol) {
2685 2659 rv = NDMP_ILLEGAL_ARGS_ERR;
2686 2660 MOD_LOGV3(params, NDMP_LOG_ERROR,
2687 2661 "Invalid destination path volume "
2688 2662 "\"%s\".\n", dp);
2689 2663 break;
2690 2664 }
2691 2665 if (!isrwdst) {
2692 2666 rv = NDMP_ILLEGAL_ARGS_ERR;
2693 2667 MOD_LOGV3(params, NDMP_LOG_ERROR,
2694 2668 "The destination path volume is not "
2695 2669 "writable \"%s\".\n", dp);
2696 2670 break;
2697 2671 }
2698 2672
2699 2673 /*
2700 2674 * If new name is not specified, the default new name is
2701 2675 * the last component of the original path, if any
2702 2676 * (except in V4).
2703 2677 */
2704 2678 if (ISDEFINED(ep->nm3_newnm)) {
2705 2679 nm = ep->nm3_newnm;
2706 2680 } else {
2707 2681 char *p, *q;
2708 2682
2709 2683 /*
2710 2684 * Find the last component of nm3_opath.
2711 2685 * nm3_opath has no trailing '/'.
2712 2686 */
2713 2687 p = strrchr(ep->nm3_opath, '/');
2714 2688 nm = p ? p + 1 : ep->nm3_opath;
2715 2689
2716 2690 /*
2717 2691 * In DDAR the last component could
2718 2692 * be repeated in nm3_dpath
2719 2693 */
2720 2694 q = strrchr(ep->nm3_dpath, '/');
2721 2695 q = q ? q + 1 : ep->nm3_dpath;
2722 2696 if (strcmp(nm, q) == 0)
2723 2697 nm = NULL;
2724 2698
2725 2699 }
2726 2700
2727 2701 bp = joinpath(buf, dp, nm);
2728 2702 if (!bp) {
2729 2703 /*
2730 2704 * Note: What should be done with this entry?
2731 2705 * We leave it untouched for now, hence no path in
2732 2706 * the backup image matches with this entry and will
2733 2707 * be reported as not found.
2734 2708 */
2735 2709 MOD_LOGV3(params, NDMP_LOG_ERROR,
2736 2710 "Destination path too long(%s/%s)", dp, nm);
2737 2711 continue;
2738 2712 }
2739 2713 cp = strdup(bp);
2740 2714 if (!cp) {
2741 2715 MOD_LOGV3(params, NDMP_LOG_ERROR,
2742 2716 "Insufficient memory.\n");
2743 2717 rv = NDMP_NO_MEM_ERR;
2744 2718 break;
2745 2719 }
2746 2720 free(ep->nm3_dpath);
2747 2721 ep->nm3_dpath = cp;
2748 2722 NDMP_FREE(ep->nm3_newnm);
2749 2723
2750 2724 bp = joinpath(buf, nlp->nlp_backup_path, ep->nm3_opath);
2751 2725 if (!bp) {
2752 2726 /*
2753 2727 * Note: The same problem of above with long path.
2754 2728 */
2755 2729 MOD_LOGV3(params, NDMP_LOG_ERROR,
2756 2730 "Path too long(%s/%s)",
2757 2731 nlp->nlp_backup_path, ep->nm3_opath);
2758 2732 continue;
2759 2733 }
|
↓ open down ↓ |
149 lines elided |
↑ open up ↑ |
2760 2734 cp = strdup(bp);
2761 2735 if (!cp) {
2762 2736 MOD_LOGV3(params, NDMP_LOG_ERROR,
2763 2737 "Insufficient memory.\n");
2764 2738 rv = NDMP_NO_MEM_ERR;
2765 2739 break;
2766 2740 }
2767 2741 NDMP_FREE(ep->nm3_opath);
2768 2742 ep->nm3_opath = cp;
2769 2743
2770 - NDMP_LOG(LOG_DEBUG, "orig[%d]: \"%s\"", i, ep->nm3_opath);
2744 + syslog(LOG_DEBUG, "orig[%d]: \"%s\"", i, ep->nm3_opath);
2771 2745 if (ep->nm3_dpath) {
2772 - NDMP_LOG(LOG_DEBUG,
2746 + syslog(LOG_DEBUG,
2773 2747 "dest[%d]: \"%s\"", i, ep->nm3_dpath);
2774 2748 } else {
2775 - NDMP_LOG(LOG_DEBUG, "dest[%d]: \"%s\"", i, "NULL");
2749 + syslog(LOG_INFO, "dest[%d]: \"%s\"", i, "NULL");
2776 2750 }
2777 2751 }
2778 2752
2779 2753 free(buf);
2780 2754
2781 2755 return (rv);
2782 2756 }
2783 2757
2784 2758
2785 2759 /*
2786 2760 * allvalidfh
2787 2761 *
2788 2762 * Run a sanity check on the file history info. The file history
2789 2763 * info is the offset of the record starting the entry on the tape
2790 2764 * and is used in DAR (direct access restore mode).
2791 2765 */
2792 2766 static boolean_t
2793 2767 allvalidfh(ndmpd_session_t *session, ndmpd_module_params_t *params)
2794 2768 {
2795 2769 int i, n;
2796 2770 boolean_t rv;
2797 2771 mem_ndmp_name_v3_t *ep;
2798 2772
2799 2773 rv = TRUE;
2800 2774 n = session->ns_data.dd_nlist_len;
2801 2775 for (i = 0; i < n; i++) {
2802 2776 ep = (mem_ndmp_name_v3_t *)MOD_GETNAME(params, i);
2803 2777 if (!ep)
2804 2778 continue;
2805 2779 /*
2806 2780 * The fh_info's sent from the client are multiples
2807 2781 * of RECORDSIZE which is 512 bytes.
2808 2782 *
2809 2783 * All our fh_info's are at the RECORDSIZE boundary. If there
2810 2784 * is any fh_info that is less than RECORDSIZE (this covers 0
2811 2785 * and -1 values too), then the result is that DAR cannot be
2812 2786 * done.
2813 2787 */
2814 2788 if (ep->nm3_fh_info < RECORDSIZE ||
2815 2789 ep->nm3_fh_info % RECORDSIZE != 0) {
2816 2790 rv = FALSE;
2817 2791 break;
2818 2792 }
2819 2793 }
2820 2794
2821 2795 return (rv);
2822 2796 }
2823 2797
2824 2798
2825 2799 /*
2826 2800 * log_rs_params_v3
2827 2801 *
2828 2802 * Log a copy of all values of the restore parameters
2829 2803 */
2830 2804 void
2831 2805 log_rs_params_v3(ndmpd_session_t *session, ndmpd_module_params_t *params,
2832 2806 ndmp_lbr_params_t *nlp)
2833 2807 {
2834 2808 MOD_LOGV3(params, NDMP_LOG_NORMAL, "Restoring to \"%s\".\n",
2835 2809 (nlp->nlp_restore_path) ? nlp->nlp_restore_path : "NULL");
2836 2810
2837 2811 if (session->ns_data.dd_data_addr.addr_type == NDMP_ADDR_LOCAL) {
2838 2812 MOD_LOGV3(params, NDMP_LOG_NORMAL, "Tape server: local.\n");
2839 2813 MOD_LOGV3(params, NDMP_LOG_NORMAL,
2840 2814 "Tape record size: %d.\n",
2841 2815 session->ns_mover.md_record_size);
2842 2816 } else if (session->ns_data.dd_data_addr.addr_type == NDMP_ADDR_TCP)
2843 2817 MOD_LOGV3(params, NDMP_LOG_NORMAL,
2844 2818 "Tape server: remote at %s:%d.\n",
2845 2819 inet_ntoa(IN_ADDR(session->ns_data.dd_data_addr.tcp_ip_v3)),
2846 2820 session->ns_data.dd_data_addr.tcp_port_v3);
2847 2821 else
2848 2822 MOD_LOGV3(params, NDMP_LOG_ERROR,
2849 2823 "Unknown tape server address type.\n");
2850 2824
2851 2825 if (NLP_ISSET(nlp, NLPF_DIRECT))
2852 2826 MOD_LOGV3(params, NDMP_LOG_NORMAL,
2853 2827 "Direct Access Restore.\n");
2854 2828 }
2855 2829
2856 2830
2857 2831 /*
2858 2832 * send_unrecovered_list_v3
2859 2833 *
|
↓ open down ↓ |
74 lines elided |
↑ open up ↑ |
2860 2834 * Create the list of files that were in restore list but
2861 2835 * not recovered due to some errors.
2862 2836 */
2863 2837 int
2864 2838 send_unrecovered_list_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp)
2865 2839 {
2866 2840 int i, rv;
2867 2841 int err;
2868 2842
2869 2843 if (!params) {
2870 - NDMP_LOG(LOG_DEBUG, "params == NULL");
2844 + syslog(LOG_ERR, "params == NULL");
2871 2845 return (-1);
2872 2846 }
2873 2847 if (!nlp) {
2874 - NDMP_LOG(LOG_DEBUG, "nlp == NULL");
2848 + syslog(LOG_ERR, "nlp == NULL");
2875 2849 return (-1);
2876 2850 }
2877 2851
2878 2852 if (nlp->nlp_lastidx != -1) {
2879 2853 if (!bm_getone(nlp->nlp_rsbm, (u_longlong_t)nlp->nlp_lastidx))
2880 2854 err = ENOENT;
2881 2855 else
2882 2856 err = 0;
2883 2857 (void) ndmp_send_recovery_stat_v3(params, nlp,
2884 2858 nlp->nlp_lastidx, err);
2885 2859 nlp->nlp_lastidx = -1;
2886 2860 }
2887 2861
2888 2862 rv = 0;
2889 2863 for (i = 0; i < (int)nlp->nlp_nfiles; i++) {
2890 2864 if (!bm_getone(nlp->nlp_rsbm, (u_longlong_t)i)) {
2891 2865 rv = ndmp_send_recovery_stat_v3(params, nlp, i, ENOENT);
2892 2866 if (rv < 0)
2893 2867 break;
2894 2868 }
2895 2869 }
2896 2870
2897 2871 return (rv);
2898 2872 }
2899 2873
2900 2874
|
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
2901 2875
2902 2876 /*
2903 2877 * restore_dar_alloc_structs_v3
2904 2878 *
2905 2879 * Allocates the necessary structures for running DAR restore.
2906 2880 * It just creates the reader writer IPC.
2907 2881 * This function is called for each entry in the restore entry list.
2908 2882 *
2909 2883 * Parameters:
2910 2884 * session (input) - pointer to the session
2911 - * jname (input) - Job name
2912 2885 *
2913 2886 * Returns:
2914 2887 * 0: on success
2915 2888 * -1: on error
2916 2889 */
2917 2890 int
2918 -restore_dar_alloc_structs_v3(ndmpd_session_t *session, char *jname)
2891 +restore_dar_alloc_structs_v3(ndmpd_session_t *session)
2919 2892 {
2920 2893 long xfer_size;
2921 2894 ndmp_lbr_params_t *nlp;
2922 2895 tlm_commands_t *cmds;
2923 2896
2924 2897 nlp = ndmp_get_nlp(session);
2925 2898 if (!nlp) {
2926 - NDMP_LOG(LOG_DEBUG, "nlp == NULL");
2899 + syslog(LOG_ERR, "nlp == NULL");
2927 2900 return (-1);
2928 2901 }
2929 2902
2930 2903 cmds = &nlp->nlp_cmds;
2931 2904 (void) memset(cmds, 0, sizeof (*cmds));
2932 2905
2933 2906 xfer_size = ndmp_buffer_get_size(session);
2934 2907 cmds->tcs_command = tlm_create_reader_writer_ipc(FALSE, xfer_size);
2935 2908 if (!cmds->tcs_command) {
2936 - tlm_un_ref_job_stats(jname);
2909 + tlm_un_ref_job_stats(nlp->nlp_job_name);
2937 2910 return (-1);
2938 2911 }
2939 2912
2940 2913 return (0);
2941 2914 }
2942 2915
2943 2916
2944 2917 /*
2945 2918 * free_dar_structs_v3
2946 2919 *
2947 2920 * To free the structures were created by restore_dar_alloc_structs_v3.
2948 2921 * This funnction is called for each entry in restore entry list.
2949 2922 *
2950 2923 * Parameters:
2951 2924 * session (input) - pointer to the session
2952 - * jname (input) - job name
2953 2925 *
2954 2926 * Returns:
2955 2927 * NONE
2956 2928 */
2957 2929 /*ARGSUSED*/
2958 2930 static void
2959 -free_dar_structs_v3(ndmpd_session_t *session, char *jname)
2931 +free_dar_structs_v3(ndmpd_session_t *session)
2960 2932 {
2961 2933 ndmp_lbr_params_t *nlp;
2962 2934 tlm_commands_t *cmds;
2963 2935
2964 2936 nlp = ndmp_get_nlp(session);
2965 2937 if (!nlp) {
2966 - NDMP_LOG(LOG_DEBUG, "nlp == NULL");
2938 + syslog(LOG_DEBUG, "nlp == NULL");
2967 2939 return;
2968 2940 }
2969 2941 cmds = &nlp->nlp_cmds;
2970 2942 if (!cmds) {
2971 - NDMP_LOG(LOG_DEBUG, "cmds == NULL");
2943 + syslog(LOG_DEBUG, "cmds == NULL");
2972 2944 return;
2973 2945 }
2974 2946
2975 2947 if (cmds->tcs_command) {
2976 2948 if (cmds->tcs_command->tc_buffers != NULL)
2977 2949 tlm_release_reader_writer_ipc(cmds->tcs_command);
2978 2950 else
2979 - NDMP_LOG(LOG_DEBUG, "BUFFERS == NULL");
2951 + syslog(LOG_DEBUG, "BUFFERS == NULL");
2980 2952 cmds->tcs_command = NULL;
2981 2953 } else
2982 - NDMP_LOG(LOG_DEBUG, "COMMAND == NULL");
2954 + syslog(LOG_DEBUG, "COMMAND == NULL");
2983 2955 }
2984 2956
2985 2957
2986 2958 /*
2987 2959 * ndmp_dar_tar_init_v3
2988 2960 *
2989 2961 * Constructor for the DAR restore. Creates job name, allocates structures
2990 2962 * needed for keeping the statistics, and reports the start of restore action.
2991 2963 * It is called once for each DAR restore request.
2992 2964 *
2993 2965 * Parameters:
2994 2966 * session (input) - pointer to the session
2995 2967 * nlp (input) - pointer to the nlp structure
2996 2968 *
2997 2969 * Returns:
2998 2970 * char pointer: on success
2999 2971 * NULL: on error
3000 2972 */
|
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
3001 2973 static char *ndmpd_dar_tar_init_v3(ndmpd_session_t *session,
3002 2974 ndmp_lbr_params_t *nlp)
3003 2975 {
3004 2976 char *jname;
3005 2977
3006 2978 jname = ndmp_malloc(TLM_MAX_BACKUP_JOB_NAME);
3007 2979
3008 2980 if (!jname)
3009 2981 return (NULL);
3010 2982
3011 - (void) ndmp_new_job_name(jname);
2983 + if (ndmp_new_job_name(jname, TLM_MAX_BACKUP_JOB_NAME) <= 0) {
2984 + free(jname);
2985 + return (NULL);
2986 + }
3012 2987
3013 2988 if (!nlp) {
3014 2989 free(jname);
3015 - NDMP_LOG(LOG_DEBUG, "nlp == NULL");
2990 + syslog(LOG_DEBUG, "nlp == NULL");
3016 2991 return (NULL);
3017 2992 }
3018 2993
3019 2994 nlp->nlp_jstat = tlm_new_job_stats(jname);
3020 2995 if (!nlp->nlp_jstat) {
3021 2996 free(jname);
3022 - NDMP_LOG(LOG_DEBUG, "Creating job stats");
2997 + syslog(LOG_DEBUG, "Creating job stats");
3023 2998 return (NULL);
3024 2999 }
3025 3000
3026 3001 nlp->nlp_jstat->js_start_ltime = time(NULL);
3027 3002 nlp->nlp_jstat->js_start_time = nlp->nlp_jstat->js_start_ltime;
3028 3003
3029 3004 nlp->nlp_logcallbacks = lbrlog_callbacks_init(session,
3030 3005 ndmpd_path_restored_v3, NULL, NULL);
3031 3006 if (!nlp->nlp_logcallbacks) {
3032 3007 tlm_un_ref_job_stats(jname);
3033 3008 free(jname);
3034 3009 return (NULL);
3035 3010 }
3036 3011 nlp->nlp_jstat->js_callbacks = (void *)(nlp->nlp_logcallbacks);
3037 3012
3038 3013 nlp->nlp_rsbm = bm_alloc(nlp->nlp_nfiles, 0);
3039 3014 if (nlp->nlp_rsbm < 0) {
3040 - NDMP_LOG(LOG_ERR, "Out of memory.");
3015 + syslog(LOG_ERR, "Out of memory.");
3041 3016 lbrlog_callbacks_done(nlp->nlp_logcallbacks);
3042 3017 tlm_un_ref_job_stats(jname);
3043 3018 free(jname);
3044 3019 return (NULL);
3045 3020 }
3046 3021
3047 3022 /* this is used in ndmpd_path_restored_v3() */
3048 3023 nlp->nlp_lastidx = -1;
3049 3024
3050 - NDMP_LOG(LOG_DEBUG, "Restoring from %s tape(s).",
3025 + syslog(LOG_DEBUG, "Restoring from %s tape(s).",
3051 3026 ndmp_data_get_mover_mode(session));
3052 3027
3053 3028 return (jname);
3054 3029 }
3055 3030
3056 3031 /*
3057 3032 * ndmpd_dar_tar_end_v3
3058 3033 *
3059 3034 * Deconstructor for the DAR restore. This function is called once per
3060 3035 * DAR request. It deallocates memories allocated by ndmpd_dar_tar_init_v3.
3061 3036 *
3062 3037 * Parameters:
3063 3038 * session (input) - pointer to the session
3064 3039 * params (input) - pointer to the parameters structure
3065 3040 * nlp (input) - pointer to the nlp structure
3066 3041 * jname(input) - job name
3067 3042 *
|
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
3068 3043 * Returns:
3069 3044 * 0: on success
3070 3045 * -1: on error
3071 3046 */
3072 3047 static int ndmpd_dar_tar_end_v3(ndmpd_session_t *session,
3073 3048 ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp, char *jname)
3074 3049 {
3075 3050 int err = 0;
3076 3051
3077 3052
3078 - NDMP_LOG(LOG_DEBUG, "lastidx %d", nlp->nlp_lastidx);
3053 + syslog(LOG_DEBUG, "lastidx %d", nlp->nlp_lastidx);
3079 3054
3080 3055 /* nothing restored. */
3081 3056 (void) send_unrecovered_list_v3(params, nlp);
3082 3057
3083 3058 if (nlp->nlp_jstat) {
3084 3059 nlp->nlp_bytes_total =
3085 3060 (u_longlong_t)nlp->nlp_jstat->js_bytes_total;
3086 3061 tlm_un_ref_job_stats(jname);
3087 3062 nlp->nlp_jstat = NULL;
3088 3063 } else {
3089 - NDMP_LOG(LOG_DEBUG, "JSTAT == NULL");
3064 + syslog(LOG_DEBUG, "JSTAT == NULL");
3090 3065 }
3091 3066
3092 3067 if (nlp->nlp_logcallbacks) {
3093 3068 lbrlog_callbacks_done(nlp->nlp_logcallbacks);
3094 3069 nlp->nlp_logcallbacks = NULL;
3095 3070 } else {
3096 - NDMP_LOG(LOG_DEBUG, "FH CALLBACKS == NULL");
3071 + syslog(LOG_DEBUG, "FH CALLBACKS == NULL");
3097 3072 }
3098 3073
3099 3074 if (session->ns_data.dd_abort) {
3100 - NDMP_LOG(LOG_DEBUG, "Restoring to \"%s\" aborted.",
3075 + syslog(LOG_DEBUG, "Restoring to \"%s\" aborted.",
3101 3076 (nlp->nlp_restore_path) ? nlp->nlp_restore_path : "NULL");
3102 3077 err = EINTR;
3103 3078 } else {
3104 - NDMP_LOG(LOG_DEBUG, "Restoring to \"%s\" finished. (%d)",
3079 + syslog(LOG_DEBUG, "Restoring to \"%s\" finished. (%d)",
3105 3080 (nlp->nlp_restore_path) ? nlp->nlp_restore_path :
3106 3081 "NULL", err);
3107 3082 }
3108 3083
3109 3084 if (session->ns_data.dd_operation == NDMP_DATA_OP_RECOVER) {
3110 3085 if (nlp->nlp_rsbm < 0) {
3111 - NDMP_LOG(LOG_DEBUG, "nlp_rsbm < 0 %d", nlp->nlp_rsbm);
3086 + syslog(LOG_DEBUG, "nlp_rsbm < 0 %d", nlp->nlp_rsbm);
3112 3087 } else {
3113 3088 (void) bm_free(nlp->nlp_rsbm);
3114 3089 nlp->nlp_rsbm = -1;
3115 3090 }
3116 3091 }
3117 3092
3118 3093 free(jname);
3119 3094
3120 3095 return (err);
3121 3096 }
3122 3097
3123 3098
3124 3099 /*
3125 3100 * ndmpd_dar_tar_v3
3126 3101 *
|
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
3127 3102 * This function is called for each entry in DAR entry list. The window
3128 3103 * is already located and we should be in the right position to read
3129 3104 * the data from the tape.
3130 3105 * For each entry we setup selection list; so that, if the file name from
3131 3106 * tape is not as the name client asked for, error be returned.
3132 3107 *
3133 3108 * Parameters:
3134 3109 * session (input) - pointer to the session
3135 3110 * params (input) - pointer to the parameters structure
3136 3111 * nlp (input) - pointer to the nlp structure
3137 - * jname (input) - job name
3138 3112 * dar_index(input) - Index of this entry in the restore list
3139 3113 *
3140 3114 * Returns:
3141 3115 * 0: on success
3142 3116 * -1: on error
3143 3117 */
3144 3118 static int
3145 3119 ndmpd_dar_tar_v3(ndmpd_session_t *session, ndmpd_module_params_t *params,
3146 - ndmp_lbr_params_t *nlp, char *jname, int dar_index)
3120 + ndmp_lbr_params_t *nlp, int dar_index)
3147 3121 {
3148 3122 char *excl;
3149 3123 char **sels;
3150 3124 int flags;
3151 3125 int err;
3152 3126 tlm_commands_t *cmds;
3153 3127 struct rs_name_maker rn;
3154 3128 int data_addr_type = session->ns_data.dd_data_addr.addr_type;
3155 3129 ndmp_tar_reader_arg_t arg;
3156 3130 pthread_t rdtp;
3157 3131 ndmp_context_t nctx;
3158 3132 mem_ndmp_name_v3_t *ep;
3159 3133
3160 3134 err = 0;
3161 3135
3162 3136 /*
3163 3137 * We have to allocate and deallocate buffers every time we
3164 3138 * run the restore, for we need to flush the buffers.
3165 3139 */
3166 - if (restore_dar_alloc_structs_v3(session, jname) < 0)
3140 + if (restore_dar_alloc_structs_v3(session) < 0)
3167 3141 return (-1);
3168 3142
3169 3143 sels = setupsels(session, params, nlp, dar_index);
3170 3144 if (!sels) {
3171 - free_dar_structs_v3(session, jname);
3145 + free_dar_structs_v3(session);
3172 3146 return (-1);
3173 3147 }
3174 3148 excl = NULL;
3175 3149 flags = RSFLG_OVR_ALWAYS;
3176 3150 rn.rn_nlp = nlp;
3177 3151 rn.rn_fp = mknewname;
3178 3152
3179 3153 if (!session->ns_data.dd_abort) {
3180 3154 cmds = &nlp->nlp_cmds;
3181 3155 cmds->tcs_reader = cmds->tcs_writer = TLM_RESTORE_RUN;
3182 3156 cmds->tcs_command->tc_reader = TLM_RESTORE_RUN;
3183 3157 cmds->tcs_command->tc_writer = TLM_RESTORE_RUN;
|
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
3184 3158
3185 3159 arg.tr_session = session;
3186 3160 arg.tr_mod_params = params;
3187 3161 arg.tr_cmds = cmds;
3188 3162
3189 3163 err = pthread_create(&rdtp, NULL, (funct_t)ndmp_tar_reader,
3190 3164 (void *)&arg);
3191 3165 if (err == 0) {
3192 3166 tlm_cmd_wait(cmds->tcs_command, TLM_TAR_READER);
3193 3167 } else {
3194 - NDMP_LOG(LOG_DEBUG, "launch ndmp_tar_reader: %m");
3168 + syslog(LOG_ERR, "launch ndmp_tar_reader failed");
3195 3169 return (-1);
3196 3170 }
3197 3171
3198 3172 cmds->tcs_command->tc_ref++;
3199 3173 cmds->tcs_writer_count++;
3200 3174
3201 3175 /* Plug-in module */
3202 3176 if (ndmp_pl != NULL &&
3203 3177 ndmp_pl->np_pre_restore != NULL) {
3204 3178 (void) memset(&nctx, 0, sizeof (ndmp_context_t));
3205 3179 nctx.nc_cmds = cmds;
3206 3180 nctx.nc_params = params;
3207 3181 nctx.nc_ddata = (void *) session;
3208 3182 ep = (mem_ndmp_name_v3_t *)MOD_GETNAME(params,
3209 3183 dar_index - 1);
3210 3184
3211 3185 if ((err = ndmp_pl->np_pre_restore(ndmp_pl, &nctx,
3212 3186 ep->nm3_opath, ep->nm3_dpath))
3213 3187 != 0) {
3214 - NDMP_LOG(LOG_ERR, "Pre-restore plug-in: %m");
3188 + syslog(LOG_ERR, "Pre-restore plug-in: %m");
3215 3189 ndmp_stop_local_reader(session, cmds);
3216 3190 ndmp_wait_for_reader(cmds);
3217 3191 (void) pthread_join(rdtp, NULL);
3218 3192 ndmp_stop_remote_reader(session);
3219 3193 goto restore_out;
3220 3194 }
3221 3195 }
3222 3196
3223 3197 if (tm_tar_ops.tm_getdir != NULL) {
3224 3198 char errbuf[256];
3225 3199
3226 3200 err = (tm_tar_ops.tm_getdir)(cmds, cmds->tcs_command,
3227 3201 nlp->nlp_jstat, &rn, 1, 1, sels, &excl, flags,
3228 - dar_index, nlp->nlp_backup_path,
3202 + dar_index, nlp->nlp_mountpoint,
3229 3203 session->hardlink_q);
3230 3204 /*
3231 3205 * If the fatal error from tm_getdir looks like an
3232 3206 * errno code, we send the error description to DMA.
3233 3207 */
3234 3208 if (err > 0 && strerror_r(err, errbuf,
3235 3209 sizeof (errbuf)) == 0) {
3236 3210 MOD_LOGV3(params, NDMP_LOG_ERROR,
3237 3211 "Fatal error during the restore: %s\n",
3238 3212 errbuf);
3239 3213 }
3240 3214 }
3241 3215
3242 3216 cmds->tcs_writer_count--;
3243 3217 cmds->tcs_command->tc_ref--;
3244 - NDMP_LOG(LOG_DEBUG, "stop local reader.");
3218 + syslog(LOG_DEBUG, "stop local reader.");
3245 3219 ndmp_stop_local_reader(session, cmds);
3246 3220
3247 3221 ndmp_wait_for_reader(cmds);
3248 3222 (void) pthread_join(rdtp, NULL);
3249 3223
3250 3224 /*
3251 3225 * If this is the last DAR entry and it is a three-way
3252 3226 * restore then we should close the connection.
3253 3227 */
3254 3228 if ((data_addr_type == NDMP_ADDR_TCP) &&
3255 3229 (dar_index == (int)session->ns_data.dd_nlist_len)) {
3256 - NDMP_LOG(LOG_DEBUG, "stop remote reader.");
3230 + syslog(LOG_DEBUG, "stop remote reader.");
3257 3231 ndmp_stop_remote_reader(session);
3258 3232 }
3259 3233
3260 3234 /* exit as if there was an internal error */
3261 3235 if (session->ns_eof)
3262 3236 err = -1;
3263 3237 restore_out:
3264 3238 /* Plug-in module */
3265 3239 if (ndmp_pl != NULL &&
3266 3240 ndmp_pl->np_post_restore != NULL &&
3267 3241 ndmp_pl->np_post_restore(ndmp_pl, &nctx, err) == -1) {
3268 - NDMP_LOG(LOG_DEBUG, "Post-restore plug-in: %m");
3242 + syslog(LOG_DEBUG, "Post-restore plug-in: %m");
3269 3243 err = -1;
3270 3244 }
3271 3245 }
3272 3246
3273 3247 NDMP_FREE(sels);
3274 3248
3275 - free_dar_structs_v3(session, jname);
3249 + free_dar_structs_v3(session);
3276 3250
3277 3251 return (err);
3278 3252 }
3279 3253
3280 3254 /*
3281 3255 * ndmpd_dar_locate_windwos_v3
3282 3256 *
3283 3257 * Locating the right window in which the requested file is backed up.
3284 3258 * We should go through windows to find the exact location, for the
3285 3259 * file can be located in for example 10th window after the current window.
3286 3260 *
3287 3261 * Parameters:
3288 3262 * session (input) - pointer to the session
3289 3263 * params (input) - pointer to the parameters structure
3290 3264 * fh_info (input) - index from the beginning of the backup stream
3291 3265 * len (input) - Length of the mover window
3292 3266 *
3293 3267 * Returns:
3294 3268 * 0: on success
3295 3269 * -1: on error
3296 3270 */
|
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
3297 3271 static int
3298 3272 ndmpd_dar_locate_window_v3(ndmpd_session_t *session,
3299 3273 ndmpd_module_params_t *params, u_longlong_t fh_info, u_longlong_t len)
3300 3274 {
3301 3275 int ret = 0;
3302 3276
3303 3277
3304 3278 for (; ; ) {
3305 3279 ret = (*params->mp_seek_func)(session, fh_info, len);
3306 3280
3307 - NDMP_LOG(LOG_DEBUG, "ret %d", ret);
3281 + syslog(LOG_DEBUG, "ret %d", ret);
3308 3282 if (ret == 0) /* Seek was done successfully */
3309 3283 break;
3310 3284 else if (ret < 0) {
3311 - NDMP_LOG(LOG_DEBUG, "Seek error");
3285 + syslog(LOG_ERR,
3286 + "Seek error in ndmpd_dar_locate_window_v3");
3312 3287 break;
3313 3288 }
3314 3289
3315 3290 /*
3316 3291 * DMA moved to a new window.
3317 3292 * If we are reading the remainig of the file from
3318 3293 * new window, seek is handled by ndmpd_local_read_v3.
3319 3294 * Here we should continue the seek inside the new
3320 3295 * window.
3321 3296 */
3322 3297 continue;
3323 3298 }
3324 3299 return (ret);
3325 3300 }
3326 3301
3327 3302 /*
3328 3303 * ndmpd_rs_dar_tar_v3
3329 3304 *
3330 3305 * Main DAR function. It calls the constructor, then for each entry it
3331 3306 * calls the locate_window_v3 to find the exact position of the file. Then
3332 3307 * it restores the file.
3333 3308 * When all restore requests are done it calls the deconstructor to clean
3334 3309 * everything up.
3335 3310 *
3336 3311 * Parameters:
3337 3312 * session (input) - pointer to the session
3338 3313 * params (input) - pointer to the parameters structure
3339 3314 * nlp (input) - pointer to the nlp structure
3340 3315 *
3341 3316 * Returns:
3342 3317 * 0: on success
3343 3318 * -1: on error
3344 3319 */
3345 3320 static int
3346 3321 ndmpd_rs_dar_tar_v3(ndmpd_session_t *session, ndmpd_module_params_t *params,
3347 3322 ndmp_lbr_params_t *nlp)
3348 3323 {
3349 3324 mem_ndmp_name_v3_t *ep;
3350 3325 u_longlong_t len;
3351 3326 char *jname;
3352 3327 int n = session->ns_data.dd_nlist_len;
3353 3328 int i, ret = 0;
3354 3329 int result = 0;
3355 3330
3356 3331 jname = ndmpd_dar_tar_init_v3(session, nlp);
3357 3332
3358 3333 if (!jname)
3359 3334 return (-1);
3360 3335
3361 3336 /*
|
↓ open down ↓ |
40 lines elided |
↑ open up ↑ |
3362 3337 * We set the length = sizeof (tlm_tar_hdr_t)
3363 3338 * This is important for three-way DAR restore, for we should
3364 3339 * read the header first (If we ask for more data then we have
3365 3340 * to read and discard the remaining data in the socket)
3366 3341 */
3367 3342 len = tlm_tarhdr_size();
3368 3343
3369 3344 for (i = 0; i < n; ++i) {
3370 3345 ep = (mem_ndmp_name_v3_t *)MOD_GETNAME(params, i);
3371 3346 if (!ep) {
3372 - NDMP_LOG(LOG_DEBUG, "ep NULL, i %d", i);
3347 + syslog(LOG_DEBUG, "ep NULL, i %d", i);
3373 3348 continue;
3374 3349 }
3375 - NDMP_LOG(LOG_DEBUG,
3350 + syslog(LOG_DEBUG,
3376 3351 "restoring opath %s, dpath %s, fh_info %lld",
3377 3352 ep->nm3_opath ? ep->nm3_opath : "NULL",
3378 3353 ep->nm3_dpath ? ep->nm3_dpath : "NULL",
3379 3354 ep->nm3_fh_info);
3380 3355
3381 3356 /*
3382 3357 * We should seek till finding the window in which file
3383 3358 * is located.
3384 3359 */
3385 3360 ret = ndmpd_dar_locate_window_v3(session, params,
3386 3361 ep->nm3_fh_info, len);
3387 3362
3388 3363 if (ret < 0) /* If seek fails, restore should be aborted */
3389 3364 break;
3390 3365 /*
3391 3366 * We are inside the target window.
3392 3367 * for each restore we will use one entry as selection list
3393 3368 */
3394 - if ((ret = ndmpd_dar_tar_v3(session, params, nlp, jname, i+1))
3369 + if ((ret = ndmpd_dar_tar_v3(session, params, nlp, i+1))
3395 3370 != 0)
3396 3371 result = EIO;
3397 3372 ndmpd_audit_restore(session->ns_connection,
3398 3373 ep->nm3_opath ? ep->nm3_opath : "NULL",
3399 3374 session->ns_data.dd_data_addr.addr_type,
3400 3375 session->ns_tape.td_adapter_name, result);
3401 3376 }
3402 3377
3403 - NDMP_LOG(LOG_DEBUG, "End of restore list");
3378 + syslog(LOG_DEBUG, "End of restore list");
3404 3379
3405 3380 (void) ndmpd_dar_tar_end_v3(session, params, nlp, jname);
3406 3381
3407 3382 return (ret);
3408 3383 }
3409 3384
3410 3385 /*
3411 3386 * ndmp_plugin_pre_restore
3412 3387 *
3413 3388 * Wrapper for pre-restore callback with multiple path
3414 3389 */
3415 3390 static int
3416 3391 ndmp_plugin_pre_restore(ndmp_context_t *ctxp, ndmpd_module_params_t *params,
3417 3392 int ncount)
3418 3393 {
3419 3394 mem_ndmp_name_v3_t *ep;
3420 3395 int err;
3421 3396 int i;
3422 3397
3423 3398 for (i = 0; i < ncount; i++) {
3424 3399 if (!(ep = (mem_ndmp_name_v3_t *)MOD_GETNAME(params, i)))
3425 3400 continue;
3426 3401 if ((err = ndmp_pl->np_pre_restore(ndmp_pl, ctxp,
3427 3402 ep->nm3_opath, ep->nm3_dpath)) != 0)
3428 3403 return (err);
3429 3404 }
3430 3405
3431 3406 return (0);
3432 3407 }
3433 3408
3434 3409 /*
3435 3410 * get_absolute_path
3436 3411 *
3437 3412 * Get resolved path name which does not involve ".", ".." or extra
3438 3413 * "/" or symbolic links.
3439 3414 *
3440 3415 * e.g.
3441 3416 *
3442 3417 * /backup/path/ -> /backup/path
3443 3418 * /backup/path/. -> /backup/path
3444 3419 * /backup/path/../path/ -> /backup/path
3445 3420 * /link-to-backup-path -> /backup/path
3446 3421 *
3447 3422 * Returns:
3448 3423 * Pointer to the new path (allocated)
3449 3424 * NULL if the path doesnt exist
3450 3425 */
|
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
3451 3426 static char *
3452 3427 get_absolute_path(const char *bkpath)
3453 3428 {
3454 3429 char *pbuf;
3455 3430 char *rv;
3456 3431
3457 3432 if (!(pbuf = ndmp_malloc(TLM_MAX_PATH_NAME)))
3458 3433 return (NULL);
3459 3434
3460 3435 if ((rv = realpath(bkpath, pbuf)) == NULL) {
3461 - NDMP_LOG(LOG_DEBUG, "Invalid path [%s] err=%d",
3436 + syslog(LOG_ERR, "Invalid path [%s] err=%d",
3462 3437 bkpath, errno);
3463 3438 }
3464 3439 return (rv);
3465 3440 }
3466 3441
3467 3442 /*
3468 3443 * Expands the format string and logs the resulting message to the
3469 3444 * remote DMA
3470 3445 */
3471 3446 void
3472 3447 ndmp_log_dma(ndmp_context_t *nctx, ndmp_log_dma_type_t lt, const char *fmt, ...)
3473 3448 {
3474 3449 va_list ap;
3475 3450 char buf[256];
3476 3451 ndmpd_module_params_t *params;
3477 3452
3478 3453 if (nctx == NULL ||
3479 3454 (params = (ndmpd_module_params_t *)nctx->nc_params) == NULL)
3480 3455 return;
3481 3456
3482 3457 va_start(ap, fmt);
3483 3458 (void) vsnprintf(buf, sizeof (buf), fmt, ap);
3484 3459 va_end(ap);
3485 3460
3486 3461 MOD_LOGV3(params, (ndmp_log_type)lt, "%s", buf);
3487 3462 }
3488 3463
3489 3464
3490 3465 /*
3491 3466 * ndmpd_rs_sar_tar_v3
3492 3467 *
3493 3468 * Main non-DAR restore function. It will try to restore all the entries
3494 3469 * that have been backed up.
3495 3470 *
3496 3471 * Parameters:
3497 3472 * session (input) - pointer to the session
3498 3473 * params (input) - pointer to the parameters structure
|
↓ open down ↓ |
27 lines elided |
↑ open up ↑ |
3499 3474 * nlp (input) - pointer to the nlp structure
3500 3475 *
3501 3476 * Returns:
3502 3477 * 0: on success
3503 3478 * -1: on error
3504 3479 */
3505 3480 static int
3506 3481 ndmpd_rs_sar_tar_v3(ndmpd_session_t *session, ndmpd_module_params_t *params,
3507 3482 ndmp_lbr_params_t *nlp)
3508 3483 {
3509 - char jname[TLM_MAX_BACKUP_JOB_NAME];
3510 3484 char *excl;
3511 3485 char **sels;
3512 3486 int flags;
3513 3487 int err;
3514 3488 tlm_commands_t *cmds;
3515 3489 struct rs_name_maker rn;
3516 3490 ndmp_tar_reader_arg_t arg;
3517 3491 pthread_t rdtp;
3518 3492 int result;
3519 3493 ndmp_context_t nctx;
3520 3494
3521 3495 result = err = 0;
3522 - (void) ndmp_new_job_name(jname);
3523 - if (restore_alloc_structs_v3(session, jname) < 0)
3524 - return (-1);
3525 3496
3497 + if (restore_alloc_structs_v3(session) < 0) {
3498 + return (-1);
3499 + }
3526 3500 sels = setupsels(session, params, nlp, 0);
3527 3501 if (!sels) {
3528 - free_structs_v3(session, jname);
3502 + free_structs_v3(session);
3529 3503 return (-1);
3530 3504 }
3531 3505 excl = NULL;
3532 3506 flags = RSFLG_OVR_ALWAYS;
3533 3507 rn.rn_nlp = nlp;
3534 3508 rn.rn_fp = mknewname;
3535 3509
3536 3510 nlp->nlp_jstat->js_start_ltime = time(NULL);
3537 3511 nlp->nlp_jstat->js_start_time = nlp->nlp_jstat->js_start_ltime;
3538 3512
3539 3513 if (!session->ns_data.dd_abort && !session->ns_data.dd_abort) {
3540 3514 cmds = &nlp->nlp_cmds;
3541 3515 cmds->tcs_reader = cmds->tcs_writer = TLM_RESTORE_RUN;
3542 3516 cmds->tcs_command->tc_reader = TLM_RESTORE_RUN;
3543 3517 cmds->tcs_command->tc_writer = TLM_RESTORE_RUN;
3544 3518
3545 - NDMP_LOG(LOG_DEBUG, "Restoring to \"%s\" started.",
3519 + syslog(LOG_DEBUG, "Restoring to \"%s\" started.",
3546 3520 (nlp->nlp_restore_path) ? nlp->nlp_restore_path : "NULL");
3547 3521
3548 3522 arg.tr_session = session;
3549 3523 arg.tr_mod_params = params;
3550 3524 arg.tr_cmds = cmds;
3551 3525 err = pthread_create(&rdtp, NULL, (funct_t)ndmp_tar_reader,
3552 3526 (void *)&arg);
3553 3527 if (err == 0) {
3554 3528 tlm_cmd_wait(cmds->tcs_command, TLM_TAR_READER);
3555 3529 } else {
3556 - NDMP_LOG(LOG_DEBUG, "Launch ndmp_tar_reader: %m");
3557 - free_structs_v3(session, jname);
3530 + syslog(LOG_ERR, "Launch ndmp_tar_reader failed");
3531 + free_structs_v3(session);
3558 3532 return (-1);
3559 3533 }
3560 3534
3561 3535 if (!ndmp_check_utf8magic(cmds->tcs_command)) {
3562 - NDMP_LOG(LOG_DEBUG, "UTF8Magic not found!");
3536 + syslog(LOG_DEBUG, "UTF8Magic not found!");
3563 3537 } else {
3564 - NDMP_LOG(LOG_DEBUG, "UTF8Magic found");
3538 + syslog(LOG_DEBUG, "UTF8Magic found");
3565 3539 }
3566 3540
3567 3541 /* Plug-in module */
3568 3542 if (ndmp_pl != NULL &&
3569 3543 ndmp_pl->np_pre_restore != NULL) {
3570 3544 (void) memset(&nctx, 0, sizeof (ndmp_context_t));
3571 3545 nctx.nc_cmds = cmds;
3572 3546 nctx.nc_params = params;
3573 3547 nctx.nc_ddata = (void *) session;
3574 3548 if ((err = ndmp_plugin_pre_restore(&nctx, params,
3575 3549 nlp->nlp_nfiles))
3576 3550 != 0) {
3577 - NDMP_LOG(LOG_ERR, "Pre-restore plug-in: %m");
3551 + syslog(LOG_ERR, "Pre-restore plug-in: %m");
3578 3552 ndmp_stop_local_reader(session, cmds);
3579 3553 ndmp_wait_for_reader(cmds);
3580 3554 (void) pthread_join(rdtp, NULL);
3581 3555 ndmp_stop_remote_reader(session);
3582 3556 goto restore_out;
3583 3557 }
3584 3558 }
3585 3559
3586 3560 cmds->tcs_command->tc_ref++;
3587 3561 cmds->tcs_writer_count++;
3588 3562
3589 3563 if (tm_tar_ops.tm_getdir != NULL) {
3590 3564 char errbuf[256];
3591 3565
3592 3566 err = (tm_tar_ops.tm_getdir)(cmds, cmds->tcs_command,
3593 3567 nlp->nlp_jstat, &rn, 1, 1, sels, &excl, flags, 0,
3594 - nlp->nlp_backup_path, session->hardlink_q);
3568 + nlp->nlp_mountpoint, session->hardlink_q);
3595 3569 /*
3596 3570 * If the fatal error from tm_getdir looks like an
3597 3571 * errno code, we send the error description to DMA.
3598 3572 */
3599 3573 if (err > 0 && strerror_r(err, errbuf,
3600 3574 sizeof (errbuf)) == 0) {
3601 3575 MOD_LOGV3(params, NDMP_LOG_ERROR,
3602 3576 "Fatal error during the restore: %s\n",
3603 3577 errbuf);
3604 3578 }
3605 3579 }
3606 3580
3607 3581 cmds->tcs_writer_count--;
3608 3582 cmds->tcs_command->tc_ref--;
3609 3583 nlp->nlp_jstat->js_stop_time = time(NULL);
3610 3584
3611 3585 /* Send the list of un-recovered files/dirs to the client. */
3612 3586 (void) send_unrecovered_list_v3(params, nlp);
3613 3587
3614 3588 ndmp_stop_local_reader(session, cmds);
3615 3589 ndmp_wait_for_reader(cmds);
3616 3590 (void) pthread_join(rdtp, NULL);
3617 3591
3618 3592 ndmp_stop_remote_reader(session);
|
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
3619 3593
3620 3594 /* exit as if there was an internal error */
3621 3595 if (session->ns_eof)
3622 3596 err = -1;
3623 3597 if (err == -1)
3624 3598 result = EIO;
3625 3599 }
3626 3600
3627 3601 (void) send_unrecovered_list_v3(params, nlp); /* nothing restored. */
3628 3602 if (session->ns_data.dd_abort) {
3629 - NDMP_LOG(LOG_DEBUG, "Restoring to \"%s\" aborted.",
3603 + syslog(LOG_DEBUG, "Restoring to \"%s\" aborted.",
3630 3604 (nlp->nlp_restore_path) ? nlp->nlp_restore_path : "NULL");
3631 3605 result = EINTR;
3632 3606 ndmpd_audit_restore(session->ns_connection,
3633 3607 nlp->nlp_restore_path,
3634 3608 session->ns_data.dd_data_addr.addr_type,
3635 3609 session->ns_tape.td_adapter_name, result);
3636 3610 err = -1;
3637 3611 } else {
3638 - NDMP_LOG(LOG_DEBUG, "Restoring to \"%s\" finished. (%d)",
3612 + syslog(LOG_DEBUG, "Restoring to \"%s\" finished. (%d)",
3639 3613 (nlp->nlp_restore_path) ? nlp->nlp_restore_path : "NULL",
3640 3614 err);
3641 3615 ndmpd_audit_restore(session->ns_connection,
3642 3616 nlp->nlp_restore_path,
3643 3617 session->ns_data.dd_data_addr.addr_type,
3644 3618 session->ns_tape.td_adapter_name, result);
3645 3619
3646 3620 restore_out:
3647 3621 /* Plug-in module */
3648 3622 if (ndmp_pl != NULL &&
3649 3623 ndmp_pl->np_post_restore != NULL &&
3650 3624 ndmp_pl->np_post_restore(ndmp_pl, &nctx, err) == -1) {
3651 - NDMP_LOG(LOG_DEBUG, "Post-restore plug-in: %m");
3625 + syslog(LOG_DEBUG, "Post-restore plug-in: %m");
3652 3626 err = -1;
3653 3627 }
3654 3628 }
3655 3629
3656 3630 NDMP_FREE(sels);
3657 - free_structs_v3(session, jname);
3631 + free_structs_v3(session);
3658 3632
3659 3633 return (err);
3660 3634 }
3661 3635
3662 3636
3663 3637 /*
3664 3638 * ndmp_backup_get_params_v3
3665 3639 *
3666 3640 * Get the backup parameters from the NDMP env variables
3667 3641 * and log them in the system log and as normal messages
3668 3642 * to the DMA.
3669 3643 *
3670 3644 * Parameters:
3671 3645 * session (input) - pointer to the session
3672 3646 * params (input) - pointer to the parameters structure
3673 3647 *
3674 3648 * Returns:
3675 3649 * NDMP_NO_ERR: on success
3676 3650 * != NDMP_NO_ERR: otherwise
3677 3651 */
3678 3652 ndmp_error
3679 3653 ndmp_backup_get_params_v3(ndmpd_session_t *session,
3680 3654 ndmpd_module_params_t *params)
3681 3655 {
3682 3656 ndmp_lbr_params_t *nlp;
3683 3657
3684 3658 if (!session || !params)
3685 3659 return (NDMP_ILLEGAL_ARGS_ERR);
3686 3660
|
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
3687 3661 nlp = ndmp_get_nlp(session);
3688 3662 if (!nlp) {
3689 3663 MOD_LOGV3(params, NDMP_LOG_ERROR,
3690 3664 "Internal error: NULL nlp.\n");
3691 3665 return (NDMP_ILLEGAL_ARGS_ERR);
3692 3666 } else {
3693 3667 if (!(nlp->nlp_backup_path = get_backup_path_v3(params)) ||
3694 3668 !is_valid_backup_dir_v3(params, nlp->nlp_backup_path))
3695 3669 return (NDMP_ILLEGAL_ARGS_ERR);
3696 3670 }
3697 -
3698 3671 nlp->nlp_backup_path = get_absolute_path(nlp->nlp_backup_path);
3699 3672 if (!nlp->nlp_backup_path)
3700 3673 return (NDMP_ILLEGAL_ARGS_ERR);
3701 3674
3702 - if (fs_is_chkpntvol(nlp->nlp_backup_path) ||
3703 - fs_is_rdonly(nlp->nlp_backup_path) ||
3704 - !fs_is_chkpnt_enabled(nlp->nlp_backup_path))
3675 + /*
3676 + * Assume volume is not checkpointed unless found to be below
3677 + */
3678 + NLP_UNSET(nlp, NLPF_CHKPNTED_PATH);
3679 +
3680 + /*
3681 + * Get the zfs volume name from the backup path and store in
3682 + * nlp_vol.
3683 + */
3684 + if (get_zfsvolname(nlp->nlp_vol,
3685 + sizeof (nlp->nlp_vol), nlp->nlp_backup_path) == -1) {
3686 + syslog(LOG_ERR,
3687 + "Cannot get volume from [%s] on create",
3688 + nlp->nlp_backup_path);
3689 + NDMP_FREE(nlp->nlp_params);
3690 + return (-1);
3691 + }
3692 +
3693 + /*
3694 + * Find out if this data is already checkpointed via. an AutoSync
3695 + * or HPR snapshot. If it is, set the flag, and extract the snapshot
3696 + * name to use as the nlp_job_name otherwise use the normal
3697 + * 'NdmpBackup-nnnn' format.
3698 + */
3699 + if (fs_is_checkpointed(nlp) &&
3700 + (ndmp_autosync_support || ndmp_hpr_support)) {
3705 3701 NLP_SET(nlp, NLPF_CHKPNTED_PATH);
3706 - else
3707 - NLP_UNSET(nlp, NLPF_CHKPNTED_PATH);
3702 + syslog(LOG_DEBUG, ">>>> Checkpointed dataset found <<<<");
3703 + }
3708 3704
3705 + (void) ndmp_new_job_name(nlp->nlp_job_name,
3706 + sizeof (nlp->nlp_job_name));
3707 +
3708 + syslog(LOG_DEBUG, "New backup job name [%s]",
3709 + nlp->nlp_job_name);
3710 +
3709 3711 /* Should the st_ctime be ignored when backing up? */
3710 3712 if (ndmp_ignore_ctime) {
3711 - NDMP_LOG(LOG_DEBUG, "ignoring st_ctime");
3713 + syslog(LOG_DEBUG, "ignoring st_ctime");
3712 3714 NLP_SET(nlp, NLPF_IGNCTIME);
3713 3715 } else {
3714 3716 NLP_UNSET(nlp, NLPF_IGNCTIME);
3715 3717 }
3716 3718
3717 3719 if (ndmp_include_lmtime == TRUE) {
3718 - NDMP_LOG(LOG_DEBUG, "including st_lmtime");
3720 + syslog(LOG_DEBUG, "including st_lmtime");
3719 3721 NLP_SET(nlp, NLPF_INCLMTIME);
3720 3722 } else {
3721 3723 NLP_UNSET(nlp, NLPF_INCLMTIME);
3722 3724 }
3723 3725
3724 - NDMP_LOG(LOG_DEBUG, "flags %x", nlp->nlp_flags);
3726 + syslog(LOG_DEBUG, "flags %x", nlp->nlp_flags);
3725 3727
3726 3728 get_hist_env_v3(params, nlp);
3727 3729 get_exc_env_v3(params, nlp);
3728 3730 get_inc_env_v3(params, nlp);
3729 3731 get_direct_env_v3(params, nlp);
3730 3732 return (get_backup_level_v3(params, nlp));
3731 3733 }
3732 3734
3733 3735
3734 3736 /*
3735 3737 * ndmpd_tar_backup_starter_v3
3736 3738 *
3737 3739 * Create the checkpoint for the backup and do the backup,
3738 3740 * then remove the backup checkpoint if we created it.
3739 3741 * Save the backup time information based on the backup
3740 3742 * type and stop the data server.
3741 3743 *
3742 3744 * Parameters:
3743 3745 * params (input) - pointer to the parameters structure
3744 3746 *
3745 3747 * Returns:
|
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
3746 3748 * 0: on success
3747 3749 * != 0: otherwise
3748 3750 */
3749 3751 int
3750 3752 ndmpd_tar_backup_starter_v3(void *arg)
3751 3753 {
3752 3754 ndmpd_module_params_t *params = arg;
3753 3755 int err;
3754 3756 ndmpd_session_t *session;
3755 3757 ndmp_lbr_params_t *nlp;
3756 - char jname[TLM_MAX_BACKUP_JOB_NAME];
3757 - ndmp_bkup_size_arg_t sarg;
3758 - pthread_t tid;
3759 3758
3760 3759 session = (ndmpd_session_t *)(params->mp_daemon_cookie);
3761 3760 *(params->mp_module_cookie) = nlp = ndmp_get_nlp(session);
3762 3761 ndmp_session_ref(session);
3763 - (void) ndmp_new_job_name(jname);
3764 3762
3763 + pthread_cleanup_push(backup_dataset_destroy, nlp);
3764 +
3765 3765 err = 0;
3766 - if (!NLP_ISCHKPNTED(nlp) &&
3767 - ndmp_create_snapshot(nlp->nlp_backup_path, jname) < 0) {
3766 + if (backup_dataset_create(nlp) < 0) {
3768 3767 MOD_LOGV3(params, NDMP_LOG_ERROR,
3769 3768 "Creating checkpoint on \"%s\".\n",
3770 3769 nlp->nlp_backup_path);
3771 3770 err = -1;
3772 3771 }
3773 3772
3774 - NDMP_LOG(LOG_DEBUG, "err %d, chkpnted %c",
3775 - err, NDMP_YORN(NLP_ISCHKPNTED(nlp)));
3773 + syslog(LOG_DEBUG, "BACKUP STARTED [%s]", nlp->nlp_snapname);
3776 3774
3777 3775 if (err == 0) {
3778 - sarg.bs_session = session;
3779 - sarg.bs_jname = jname;
3780 - sarg.bs_path = nlp->nlp_backup_path;
3781 -
3782 3776 /* Get an estimate of the data size */
3783 - if (pthread_create(&tid, NULL, (funct_t)get_backup_size,
3784 - (void *)&sarg) == 0)
3785 - (void) pthread_detach(tid);
3777 + (void) get_backup_size(nlp);
3786 3778
3787 - err = ndmp_get_cur_bk_time(nlp, &nlp->nlp_cdate, jname);
3779 + err = ndmp_get_cur_bk_time(nlp, &nlp->nlp_cdate);
3788 3780 if (err != 0) {
3789 - NDMP_LOG(LOG_DEBUG, "err %d", err);
3781 + syslog(LOG_ERR,
3782 + "Failed to get current backup time %d", err);
3790 3783 } else {
3791 3784 log_bk_params_v3(session, params, nlp);
3792 - err = tar_backup_v3(session, params, nlp, jname);
3785 + err = tar_backup_v3(session, params, nlp);
3793 3786 }
3794 3787 }
3795 3788
3796 - if (!NLP_ISCHKPNTED(nlp))
3797 - (void) ndmp_remove_snapshot(nlp->nlp_backup_path, jname);
3789 + pthread_cleanup_pop(B_TRUE);
3798 3790
3799 - NDMP_LOG(LOG_DEBUG, "err %d, update %c",
3800 - err, NDMP_YORN(NLP_SHOULD_UPDATE(nlp)));
3801 -
3802 3791 if (err == 0)
3803 3792 save_backup_date_v3(params, nlp);
3804 3793
3805 3794 MOD_DONE(params, err);
3806 3795
3807 3796 /* nlp_params is allocated in start_backup_v3() */
3808 3797 NDMP_FREE(nlp->nlp_params);
3809 3798 NDMP_FREE(nlp->nlp_backup_path);
3810 3799
3811 3800 NS_DEC(nbk);
3812 3801 ndmp_session_unref(session);
3802 + syslog(LOG_DEBUG, "BACKUP COMPLETE [%s] (as jobname %s)",
3803 + nlp->nlp_snapname, nlp->nlp_job_name);
3813 3804 return (err);
3814 -
3815 3805 }
3816 3806
3817 3807
3818 3808 /*
3819 3809 * ndmpd_tar_backup_abort_v3
3820 3810 *
3821 3811 * Abort the backup operation and stop the reader thread.
3822 3812 *
3823 3813 * Parameters:
3824 3814 * module_cookie (input) - pointer to the nlp structure
3825 3815 *
3826 3816 * Returns:
3827 3817 * 0: always
3828 3818 */
3829 3819 int
3830 3820 ndmpd_tar_backup_abort_v3(void *module_cookie)
3831 3821 {
3832 3822 ndmp_lbr_params_t *nlp;
3833 3823
3834 3824 nlp = (ndmp_lbr_params_t *)module_cookie;
3835 3825 if (nlp && nlp->nlp_session) {
3836 3826 if (nlp->nlp_session->ns_data.dd_data_addr.addr_type ==
3837 3827 NDMP_ADDR_TCP &&
3838 3828 nlp->nlp_session->ns_data.dd_sock != -1) {
3839 3829 (void) close(nlp->nlp_session->ns_data.dd_sock);
3840 3830 nlp->nlp_session->ns_data.dd_sock = -1;
3841 3831 }
3842 3832 ndmp_stop_reader_thread(nlp->nlp_session);
3843 3833 }
3844 3834
3845 3835 return (0);
3846 3836 }
3847 3837
3848 3838
3849 3839 /*
3850 3840 * ndmp_restore_get_params_v3
3851 3841 *
3852 3842 * Get the parameters specified for recovery such as restore path, type
3853 3843 * of restore (DAR, non-DAR) etc
3854 3844 *
3855 3845 * Parameters:
3856 3846 * session (input) - pointer to the session
3857 3847 * params (input) - pointer to the parameters structure
3858 3848 *
3859 3849 * Returns:
3860 3850 * NDMP_NO_ERR: on success
|
↓ open down ↓ |
36 lines elided |
↑ open up ↑ |
3861 3851 * != NDMP_NO_ERR: otherwise
3862 3852 */
3863 3853 ndmp_error
3864 3854 ndmp_restore_get_params_v3(ndmpd_session_t *session,
3865 3855 ndmpd_module_params_t *params)
3866 3856 {
3867 3857 ndmp_error rv;
3868 3858 ndmp_lbr_params_t *nlp;
3869 3859
3870 3860 if (!(nlp = ndmp_get_nlp(session))) {
3871 - NDMP_LOG(LOG_DEBUG, "nlp is NULL");
3861 + syslog(LOG_DEBUG, "nlp is NULL");
3872 3862 rv = NDMP_ILLEGAL_ARGS_ERR;
3873 3863 } else if (!(nlp->nlp_backup_path = get_backup_path_v3(params)))
3874 3864 rv = NDMP_ILLEGAL_ARGS_ERR;
3875 3865 else if ((nlp->nlp_nfiles = session->ns_data.dd_nlist_len) == 0) {
3876 - NDMP_LOG(LOG_DEBUG, "nfiles: %d", nlp->nlp_nfiles);
3866 + syslog(LOG_DEBUG, "nfiles: %d", nlp->nlp_nfiles);
3877 3867 rv = NDMP_ILLEGAL_ARGS_ERR;
3878 3868 } else if (get_rs_path_v3(params, nlp) != NDMP_NO_ERR) {
3879 3869 rv = NDMP_ILLEGAL_ARGS_ERR;
3880 3870 } else if ((rv = fix_nlist_v3(session, params, nlp)) != NDMP_NO_ERR) {
3881 - NDMP_LOG(LOG_DEBUG, "fix_nlist_v3: %d", rv);
3871 + syslog(LOG_DEBUG, "fix_nlist_v3: %d", rv);
3882 3872 } else {
3883 3873 rv = NDMP_NO_ERR;
3884 3874 get_direct_env_v3(params, nlp);
3885 3875 if (NLP_ISSET(nlp, NLPF_DIRECT)) {
3886 3876 if (NLP_ISSET(nlp, NLPF_RECURSIVE)) {
3887 3877 /* Currently we dont support DAR on directory */
3888 - NDMP_LOG(LOG_DEBUG,
3878 + syslog(LOG_DEBUG,
3889 3879 "Can't have RECURSIVE and DIRECT together");
3890 3880 rv = NDMP_ILLEGAL_ARGS_ERR;
3891 3881 return (rv);
3892 3882 }
3893 3883
3894 3884 /*
3895 3885 * DAR can be done if all the fh_info's are valid.
3896 3886 */
3897 3887 if (allvalidfh(session, params)) {
3898 3888 ndmp_sort_nlist_v3(session);
3899 3889 } else {
3900 3890 MOD_LOGV3(params, NDMP_LOG_WARNING,
3901 3891 "Cannot do direct access recovery. "
3902 3892 "Some 'fh_info'es are not valid.\n");
3903 3893 NLP_UNSET(nlp, NLPF_DIRECT);
3904 3894 }
3905 3895 }
3906 3896
3907 3897 log_rs_params_v3(session, params, nlp);
3908 3898 }
3909 3899
3910 3900 return (rv);
3911 3901 }
3912 3902
3913 3903
3914 3904 /*
3915 3905 * ndmpd_tar_restore_starter_v3
3916 3906 *
3917 3907 * The main restore starter function. It will start a DAR or
3918 3908 * non-DAR recovery based on the parameters. (V3 and V4 only)
3919 3909 *
3920 3910 * Parameters:
3921 3911 * params (input) - pointer to the parameters structure
3922 3912 *
3923 3913 * Returns:
3924 3914 * NDMP_NO_ERR: on success
3925 3915 * != NDMP_NO_ERR: otherwise
3926 3916 */
3927 3917 int
3928 3918 ndmpd_tar_restore_starter_v3(void *arg)
3929 3919 {
3930 3920 ndmpd_module_params_t *params = arg;
3931 3921 int err;
3932 3922 ndmpd_session_t *session;
3933 3923 ndmp_lbr_params_t *nlp;
3934 3924
3935 3925
3936 3926 session = (ndmpd_session_t *)(params->mp_daemon_cookie);
3937 3927 *(params->mp_module_cookie) = nlp = ndmp_get_nlp(session);
3938 3928 ndmp_session_ref(session);
3939 3929
3940 3930 if (NLP_ISSET(nlp, NLPF_DIRECT))
3941 3931 err = ndmpd_rs_dar_tar_v3(session, params, nlp);
3942 3932 else
3943 3933 err = ndmpd_rs_sar_tar_v3(session, params, nlp);
3944 3934
3945 3935 MOD_DONE(params, err);
3946 3936
3947 3937 NS_DEC(nrs);
3948 3938 /* nlp_params is allocated in start_recover() */
3949 3939 NDMP_FREE(nlp->nlp_params);
3950 3940 ndmp_session_unref(session);
3951 3941 return (err);
3952 3942
3953 3943 }
3954 3944
3955 3945 /*
3956 3946 * ndmp_tar_restore_abort_v3
3957 3947 *
3958 3948 * Restore abort function (V3 and V4 only)
3959 3949 *
3960 3950 * Parameters:
3961 3951 * module_cookie (input) - pointer to nlp
3962 3952 *
3963 3953 * Returns:
3964 3954 * 0
3965 3955 */
3966 3956 int
3967 3957 ndmpd_tar_restore_abort_v3(void *module_cookie)
3968 3958 {
3969 3959 ndmp_lbr_params_t *nlp;
3970 3960
3971 3961 nlp = (ndmp_lbr_params_t *)module_cookie;
3972 3962 if (nlp != NULL && nlp->nlp_session != NULL) {
3973 3963 if (nlp->nlp_session->ns_data.dd_mover.addr_type ==
3974 3964 NDMP_ADDR_TCP &&
3975 3965 nlp->nlp_session->ns_data.dd_sock != -1) {
3976 3966 (void) close(nlp->nlp_session->ns_data.dd_sock);
3977 3967 nlp->nlp_session->ns_data.dd_sock = -1;
3978 3968 }
3979 3969 ndmp_stop_writer_thread(nlp->nlp_session);
3980 3970 }
3981 3971
3982 3972 return (0);
3983 3973 }
|
↓ open down ↓ |
85 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX