Print this page
NEX-13374 NDMP should be able to backup unmounted ZFS filesystems
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-9532 NDMP: readdir errors when file/directory has special characters
Reviewed by: Peer Dampmann <peer.dampmann@nexenta.com>
Reviewed by: Alexander Eremin <alexander.eremin@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
NEX-5801 Snapshots left over after failed backups
Reviewed by: Rick Mesta <rick.mesta@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Revert "NEX-5801 Snapshots left over after failed backups"
This reverts commit f182fb95f09036db71fbfc6f0a6b90469b761f21.
NEX-5801 Snapshots left over after failed backups
Reviewed by: Rick Mesta <rick.mesta@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-2990 ndmpd dumping core when used with ndmpcopy
NEX-2911 NDMP logging should use syslog and is too chatty
NEX-559 NDMP cannot backup/restore a file which spans multiple tapes

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