Print this page
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
NEX-799 past last file mark returned NDMP_IO_ERR, should be NDMP_EOM_ERR (V4+)
NEX-812 NDMP backup terminate after hit the EOM in Netbackup backup
NEX-355 NDMP backup, EOF position remains on BOT side of filemark
NEX-249 NS ndmp can't write to a brand new tape with IO error (fix cstyle)
SUP-484 NDMP backup jobs error out when reaching the end of media (EOM)
NEX-249 NS ndmp can't write to a brand new tape with IO error

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/ndmpd/ndmp/ndmpd_tape.c
          +++ new/usr/src/cmd/ndmpd/ndmp/ndmpd_tape.c
↓ 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/param.h>
       43 +#include <syslog.h>
  43   44  #include <fcntl.h>
  44   45  #include <sys/mtio.h>
  45   46  #include <errno.h>
  46   47  #include <stdio.h>
  47   48  #include <string.h>
  48   49  #include <unistd.h>
  49   50  #include "ndmpd_common.h"
  50   51  #include "ndmpd.h"
  51   52  
  52   53  static void tape_open_send_reply(ndmp_connection_t *connection, int err);
↓ open down ↓ 55 lines elided ↑ open up ↑
 108  109  void
 109  110  ndmpd_tape_open_v2(ndmp_connection_t *connection, void *body)
 110  111  {
 111  112          ndmp_tape_open_request_v2 *request = (ndmp_tape_open_request_v2 *) body;
 112  113          ndmpd_session_t *session = ndmp_get_client_data(connection);
 113  114          char adptnm[SCSI_MAX_NAME];
 114  115          int mode;
 115  116          int sid, lun;
 116  117          int err;
 117  118          scsi_adapter_t *sa;
 118      -        int devid;
      119 +        int devid = -1;
 119  120  
 120  121          err = NDMP_NO_ERR;
 121  122  
 122  123          if (session->ns_tape.td_fd != -1 || session->ns_scsi.sd_is_open != -1) {
 123      -                NDMP_LOG(LOG_INFO,
      124 +                syslog(LOG_INFO,
 124  125                      "Connection already has a tape or scsi device open");
 125  126                  err = NDMP_DEVICE_OPENED_ERR;
 126  127          } else if (request->mode != NDMP_TAPE_READ_MODE &&
 127  128              request->mode != NDMP_TAPE_WRITE_MODE &&
 128  129              request->mode != NDMP_TAPE_RAW1_MODE) {
 129  130                  err = NDMP_ILLEGAL_ARGS_ERR;
 130  131          }
 131  132  
 132  133          if ((sa = scsi_get_adapter(0)) != NULL) {
 133      -                NDMP_LOG(LOG_DEBUG,
 134      -                    "Adapter device opened: %s", request->device.name);
 135  134                  (void) strlcpy(adptnm, request->device.name, SCSI_MAX_NAME-2);
 136  135                  adptnm[SCSI_MAX_NAME-1] = '\0';
 137  136                  sid = lun = -1;
 138  137          }
 139  138          /* try to get the scsi id etc.... */
 140  139          if (sa) {
 141  140                  scsi_find_sid_lun(sa, request->device.name, &sid, &lun);
 142  141                  if (ndmp_open_list_find(request->device.name, sid, lun) == 0 &&
 143  142                      (devid = tape_open(request->device.name,
 144  143                      O_RDWR | O_NDELAY)) < 0) {
 145      -                        NDMP_LOG(LOG_ERR, "Failed to open device %s: %m.",
      144 +                        syslog(LOG_ERR, "Failed to open device %s: %m.",
 146  145                              request->device.name);
 147  146                          err = NDMP_NO_DEVICE_ERR;
 148  147                  }
 149  148                  else
 150  149                          (void) close(devid);
 151  150          } else {
 152      -                NDMP_LOG(LOG_ERR, "%s: No such tape device.",
      151 +                syslog(LOG_ERR, "%s: No such tape device.",
 153  152                      request->device.name);
 154  153                  err = NDMP_NO_DEVICE_ERR;
 155  154          }
 156  155          if (err != NDMP_NO_ERR) {
 157  156                  tape_open_send_reply(connection, err);
 158  157                  return;
 159  158          }
 160  159  
 161  160          switch (ndmp_open_list_add(connection, adptnm, sid, lun, devid)) {
 162  161          case 0:
↓ open down ↓ 22 lines elided ↑ open up ↑
 185  184          if (request->mode != NDMP_TAPE_RAW1_MODE &&
 186  185              !is_tape_unit_ready(adptnm, 0)) {
 187  186                  (void) ndmp_open_list_del(adptnm, sid, lun);
 188  187                  tape_open_send_reply(connection, NDMP_NO_TAPE_LOADED_ERR);
 189  188                  return;
 190  189          }
 191  190  
 192  191          mode = (request->mode == NDMP_TAPE_READ_MODE) ? O_RDONLY : O_RDWR;
 193  192          mode |= O_NDELAY;
 194  193          if ((session->ns_tape.td_fd = open(request->device.name, mode)) < 0) {
 195      -                        NDMP_LOG(LOG_ERR, "Failed to open tape device %s: %m.",
      194 +                        syslog(LOG_ERR, "Failed to open tape device %s: %m.",
 196  195                              request->device.name);
 197  196                          switch (errno) {
 198  197                          case EACCES:
 199  198                                  err = NDMP_WRITE_PROTECT_ERR;
 200  199                                  break;
 201  200                          case ENXIO:
 202  201                          case ENOENT:
 203  202                                  err = NDMP_NO_DEVICE_ERR;
 204  203                                  break;
 205  204                          case EBUSY:
↓ open down ↓ 7 lines elided ↑ open up ↑
 213  212                          tape_open_send_reply(connection, err);
 214  213                          return;
 215  214                  }
 216  215  
 217  216          session->ns_tape.td_mode = request->mode;
 218  217          session->ns_tape.td_sid = sid;
 219  218          session->ns_tape.td_lun = lun;
 220  219          (void) strlcpy(session->ns_tape.td_adapter_name, adptnm, SCSI_MAX_NAME);
 221  220          session->ns_tape.td_record_count = 0;
 222  221  
 223      -        NDMP_LOG(LOG_DEBUG, "Tape is opened fd: %d", session->ns_tape.td_fd);
 224      -
 225  222          tape_open_send_reply(connection, NDMP_NO_ERR);
 226  223  }
 227  224  
 228  225  
 229  226  /*
 230  227   * ndmpd_tape_close_v2
 231  228   *
 232  229   * This handler closes the currently open tape device.
 233  230   *
 234  231   * Parameters:
↓ open down ↓ 4 lines elided ↑ open up ↑
 239  236   *   void
 240  237   */
 241  238  /*ARGSUSED*/
 242  239  void
 243  240  ndmpd_tape_close_v2(ndmp_connection_t *connection, void *body)
 244  241  {
 245  242          ndmp_tape_close_reply reply;
 246  243          ndmpd_session_t *session = ndmp_get_client_data(connection);
 247  244  
 248  245          if (session->ns_tape.td_fd == -1) {
 249      -                NDMP_LOG(LOG_ERR, "Tape device is not open.");
      246 +                syslog(LOG_ERR, "Tape device is not open.");
 250  247                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
 251  248                  ndmp_send_reply(connection, (void *) &reply,
 252  249                      "sending tape_close reply");
 253  250                  return;
 254  251          }
 255  252          common_tape_close(connection);
 256  253  
 257  254  }
 258  255  
 259  256  /*
↓ open down ↓ 14 lines elided ↑ open up ↑
 274  271  ndmpd_tape_get_state_v2(ndmp_connection_t *connection, void *body)
 275  272  
 276  273  {
 277  274          ndmp_tape_get_state_reply_v2 reply;
 278  275          ndmpd_session_t *session = ndmp_get_client_data(connection);
 279  276          struct mtget mtstatus;
 280  277          struct mtdrivetype_request dtpr;
 281  278          struct mtdrivetype dtp;
 282  279  
 283  280          if (session->ns_tape.td_fd == -1) {
 284      -                NDMP_LOG(LOG_ERR, "Tape device is not open.");
      281 +                syslog(LOG_ERR, "Tape device is not open.");
 285  282                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
 286  283                  ndmp_send_reply(connection, (void *) &reply,
 287  284                      "sending tape_get_state reply");
 288  285                  return;
 289  286          }
 290  287  
 291  288          if (ioctl(session->ns_tape.td_fd, MTIOCGET, &mtstatus) < 0) {
 292      -                NDMP_LOG(LOG_ERR, "Failed to get status from tape: %m.");
 293      -                NDMP_LOG(LOG_DEBUG, "ioctl(MTIOCGET) error: %m.");
      289 +                syslog(LOG_ERR, "Failed to get status from tape: %m.");
 294  290                  reply.error = NDMP_IO_ERR;
 295  291                  ndmp_send_reply(connection, (void *)&reply,
 296  292                      "sending tape_get_state reply");
 297  293                  return;
 298  294          }
 299  295  
 300  296          dtpr.size = sizeof (struct mtdrivetype);
 301  297          dtpr.mtdtp = &dtp;
 302  298          if (ioctl(session->ns_tape.td_fd, MTIOCGETDRIVETYPE, &dtpr) == -1) {
 303      -                NDMP_LOG(LOG_ERR,
      299 +                syslog(LOG_ERR,
 304  300                      "Failed to get drive type information from tape: %m.");
 305      -                NDMP_LOG(LOG_DEBUG, "ioctl(MTIOCGETDRIVETYPE) error: %m.");
 306  301                  reply.error = NDMP_IO_ERR;
 307  302                  ndmp_send_reply(connection, (void *)&reply,
 308  303                      "sending tape_get_state reply");
 309  304                  return;
 310  305          }
 311  306  
 312  307          reply.flags = 0;
 313  308  
 314  309          reply.file_num = mtstatus.mt_fileno;
 315  310          reply.soft_errors = 0;
↓ open down ↓ 1 lines elided ↑ open up ↑
 317  312          if (dtp.bsize == 0)
 318  313                  reply.blockno = mtstatus.mt_blkno;
 319  314          else
 320  315                  reply.blockno = mtstatus.mt_blkno *
 321  316                      (session->ns_mover.md_record_size / dtp.bsize);
 322  317  
 323  318          reply.soft_errors = 0;
 324  319          reply.total_space = long_long_to_quad(0);       /* not supported */
 325  320          reply.space_remain = long_long_to_quad(0);      /* not supported */
 326  321  
 327      -        NDMP_LOG(LOG_DEBUG,
 328      -            "flags: 0x%x, file_num: %d, block_size: %d, blockno: %d",
 329      -            reply.flags, reply.file_num, reply.block_size, reply.blockno);
 330      -
 331  322          reply.error = NDMP_NO_ERR;
 332  323          ndmp_send_reply(connection, (void *) &reply,
 333  324              "sending tape_get_state reply");
 334  325  }
 335  326  
 336  327  
 337  328  /*
 338  329   * ndmpd_tape_mtio_v2
 339  330   *
 340  331   * This handler handles tape_mtio requests.
↓ open down ↓ 13 lines elided ↑ open up ↑
 354  345          ndmpd_session_t *session = ndmp_get_client_data(connection);
 355  346  
 356  347          struct mtop tapeop;
 357  348          struct mtget mtstatus;
 358  349          int retry = 0;
 359  350          int rc;
 360  351  
 361  352          reply.resid_count = 0;
 362  353  
 363  354          if (session->ns_tape.td_fd == -1) {
 364      -                NDMP_LOG(LOG_ERR, "Tape device is not open.");
      355 +                syslog(LOG_ERR, "Tape device is not open.");
 365  356                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
 366  357                  ndmp_send_reply(connection, (void *) &reply,
 367  358                      "sending tape_mtio reply");
 368  359                  return;
 369  360          }
 370  361  
 371  362          reply.error = NDMP_NO_ERR;
 372  363          switch (request->tape_op) {
 373  364          case NDMP_MTIO_FSF:
 374  365                  tapeop.mt_op = MTFSF;
↓ open down ↓ 32 lines elided ↑ open up ↑
 407  398          }
 408  399  
 409  400          if (reply.error == NDMP_NO_ERR && request->tape_op != NDMP_MTIO_TUR) {
 410  401                  tapeop.mt_count = request->count;
 411  402  
 412  403                  do {
 413  404                          NS_UPD(twait, trun);
 414  405                          errno = 0;
 415  406                          rc = ioctl(session->ns_tape.td_fd, MTIOCTOP, &tapeop);
 416  407                          NS_UPD(trun, twait);
 417      -                        NDMP_LOG(LOG_DEBUG,
 418      -                            "ioctl MTIO rc:%d, cmd:%d, retry:%d, error: %d",
 419      -                            rc, tapeop.mt_op, retry, errno);
 420  408                  } while (rc < 0 && errno == EIO &&
 421  409                      retry++ < 5);
 422  410  
 423  411                  /*
 424  412                   * Ignore I/O errors since these usually are the result of
 425  413                   * attempting to position past the beginning or end of the tape.
 426  414                   * The residual count will be returned and can be used to
 427  415                   * determine that the call was not completely successful.
 428  416                   */
 429  417                  if (rc < 0) {
 430      -                        NDMP_LOG(LOG_ERR,
      418 +                        syslog(LOG_ERR,
 431  419                              "Failed to send command to tape: %m.");
 432      -                        NDMP_LOG(LOG_DEBUG, "ioctl(MTIOCTOP) error: %m.");
 433  420  
 434  421                          /* MTWEOF doesnt have residual count */
 435  422                          if (tapeop.mt_op == MTWEOF)
 436  423                                  reply.error = NDMP_IO_ERR;
 437  424                          else
 438  425                                  reply.error = NDMP_NO_ERR;
 439  426                          reply.resid_count = tapeop.mt_count;
 440  427                          ndmp_send_reply(connection, (void *)&reply,
 441  428                              "sending tape_mtio reply");
 442  429                          return;
 443  430                  }
 444  431  
 445  432                  if (request->tape_op != NDMP_MTIO_REW &&
 446  433                      request->tape_op != NDMP_MTIO_OFF) {
 447  434                          if (ioctl(session->ns_tape.td_fd, MTIOCGET,
 448  435                              &mtstatus) < 0) {
 449      -                                NDMP_LOG(LOG_ERR,
      436 +                                syslog(LOG_ERR,
 450  437                                      "Failed to send command to tape: %m.");
 451      -                                NDMP_LOG(LOG_DEBUG,
 452      -                                    "ioctl(MTIOCGET) error: %m.");
 453  438                                  reply.error = NDMP_IO_ERR;
 454  439                                  ndmp_send_reply(connection, (void *)&reply,
 455  440                                      "sending tape_mtio reply");
 456  441  
 457  442                                  return;
 458  443                          }
 459  444  
 460  445                          reply.resid_count = labs(mtstatus.mt_resid);
 461  446                  }
 462  447          }
 463  448  
 464      -        NDMP_LOG(LOG_DEBUG, "resid_count: %d",
 465      -            reply.resid_count);
 466  449          ndmp_send_reply(connection, (void *) &reply, "sending tape_mtio reply");
 467  450  }
 468  451  
 469  452  
 470  453  /*
 471  454   * ndmpd_tape_read_v2
 472  455   *
 473  456   * This handler handles tape_read requests.
 474  457   * This interface is a non-buffered interface. Each read request
 475  458   * maps directly to a read to the tape device. It is the responsibility
↓ open down ↓ 16 lines elided ↑ open up ↑
 492  475  ndmpd_tape_read_v2(ndmp_connection_t *connection, void *body)
 493  476  {
 494  477          ndmp_tape_read_request *request = (ndmp_tape_read_request *) body;
 495  478          ndmp_tape_read_reply reply;
 496  479          ndmpd_session_t *session = ndmp_get_client_data(connection);
 497  480          char *buf;
 498  481  
 499  482          reply.data_in.data_in_len = 0;
 500  483  
 501  484          if (session->ns_tape.td_fd == -1) {
 502      -                NDMP_LOG(LOG_ERR, "Tape device is not open.");
      485 +                syslog(LOG_ERR, "Tape device is not open.");
 503  486                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
 504  487                  ndmp_send_reply(connection, (void *)&reply,
 505  488                      "sending tape_read reply");
 506  489                  return;
 507  490          }
 508  491          if (request->count == 0) {
 509  492                  reply.error = NDMP_NO_ERR;
 510  493                  ndmp_send_reply(connection, (void *)&reply,
 511  494                      "sending tape_read reply");
 512  495                  return;
↓ open down ↓ 29 lines elided ↑ open up ↑
 542  525  {
 543  526          ndmp_tape_execute_cdb_request *request;
 544  527          ndmp_tape_execute_cdb_reply reply;
 545  528          ndmpd_session_t *session = ndmp_get_client_data(connection);
 546  529  
 547  530          request = (ndmp_tape_execute_cdb_request *) body;
 548  531  
 549  532          if (session->ns_tape.td_fd == -1) {
 550  533                  (void) memset((void *) &reply, 0, sizeof (reply));
 551  534  
 552      -                NDMP_LOG(LOG_ERR, "Tape device is not open.");
      535 +                syslog(LOG_ERR, "Tape device is not open.");
 553  536                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
 554  537                  ndmp_send_reply(connection, (void *) &reply,
 555  538                      "sending tape_execute_cdb reply");
 556  539          } else {
 557  540                  ndmp_execute_cdb(session, session->ns_tape.td_adapter_name,
 558  541                      session->ns_tape.td_sid, session->ns_tape.td_lun,
 559  542                      (ndmp_execute_cdb_request *)request);
 560  543          }
 561  544  }
 562  545  
↓ open down ↓ 42 lines elided ↑ open up ↑
 605  588  void
 606  589  ndmpd_tape_get_state_v3(ndmp_connection_t *connection, void *body)
 607  590  {
 608  591          ndmp_tape_get_state_reply_v3 reply;
 609  592          ndmpd_session_t *session = ndmp_get_client_data(connection);
 610  593          struct mtdrivetype_request dtpr;
 611  594          struct mtdrivetype dtp;
 612  595          struct mtget mtstatus;
 613  596  
 614  597          if (session->ns_tape.td_fd == -1) {
 615      -                NDMP_LOG(LOG_ERR, "Tape device is not open.");
      598 +                syslog(LOG_ERR, "Tape device is not open.");
 616  599                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
 617  600                  ndmp_send_reply(connection, (void *) &reply,
 618  601                      "sending tape_get_state reply");
 619  602                  return;
 620  603          }
 621  604  
 622  605          if (ioctl(session->ns_tape.td_fd, MTIOCGET, &mtstatus) == -1) {
 623      -                NDMP_LOG(LOG_ERR, "Failed to get status from tape: %m.");
 624      -                NDMP_LOG(LOG_DEBUG, "ioctl(MTIOCGET) error: %m.");
      606 +                syslog(LOG_ERR, "Failed to get status from tape: %m.");
 625  607  
 626  608                  reply.error = NDMP_IO_ERR;
 627  609                  ndmp_send_reply(connection, (void *)&reply,
 628  610                      "sending tape_get_state reply");
 629  611                  return;
 630  612          }
 631  613  
 632  614          dtpr.size = sizeof (struct mtdrivetype);
 633  615          dtpr.mtdtp = &dtp;
 634  616          if (ioctl(session->ns_tape.td_fd, MTIOCGETDRIVETYPE, &dtpr) == -1) {
 635      -                NDMP_LOG(LOG_ERR,
      617 +                syslog(LOG_ERR,
 636  618                      "Failed to get drive type information from tape: %m.");
 637      -                NDMP_LOG(LOG_DEBUG, "ioctl(MTIOCGETDRIVETYPE) error: %m.");
 638  619  
 639  620                  reply.error = NDMP_IO_ERR;
 640  621                  ndmp_send_reply(connection, (void *)&reply,
 641  622                      "sending tape_get_state reply");
 642  623                  return;
 643  624          }
 644  625  
 645  626          reply.flags = 0;
 646  627  
 647  628          reply.file_num = mtstatus.mt_fileno;
↓ open down ↓ 10 lines elided ↑ open up ↑
 658  639  
 659  640          reply.soft_errors = 0;
 660  641          reply.total_space = long_long_to_quad(0LL);
 661  642          reply.space_remain = long_long_to_quad(0LL);
 662  643  
 663  644          reply.invalid = NDMP_TAPE_STATE_SOFT_ERRORS_INVALID |
 664  645              NDMP_TAPE_STATE_TOTAL_SPACE_INVALID |
 665  646              NDMP_TAPE_STATE_SPACE_REMAIN_INVALID |
 666  647              NDMP_TAPE_STATE_PARTITION_INVALID;
 667  648  
 668      -
 669      -        NDMP_LOG(LOG_DEBUG, "f 0x%x, fnum %d, bsize %d, bno: %d",
 670      -            reply.flags, reply.file_num, reply.block_size, reply.blockno);
 671      -
 672  649          reply.error = NDMP_NO_ERR;
 673  650          ndmp_send_reply(connection, (void *) &reply,
 674  651              "sending tape_get_state reply");
 675  652  }
 676  653  
 677  654  /*
 678  655   * tape_is_at_bot
 679  656   *
 680  657   * Returns 1 if tape is at BOT, 0 on error or not at BOT.
 681  658   *
↓ open down ↓ 75 lines elided ↑ open up ↑
 757  734   *   body       (input) - request message body.
 758  735   */
 759  736  void ndmpd_tape_write_v3(ndmp_connection_t *connection, void *body) {
 760  737          ndmp_tape_write_request *request = (ndmp_tape_write_request *)body;
 761  738          ndmp_tape_write_reply reply; ndmpd_session_t *session =
 762  739                  ndmp_get_client_data(connection); ssize_t n;
 763  740  
 764  741          reply.count = 0;
 765  742  
 766  743          if (session->ns_tape.td_fd == -1) {
 767      -                NDMP_LOG(LOG_ERR, "Tape device is not open.");
      744 +                syslog(LOG_ERR, "Tape device is not open.");
 768  745                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
 769  746                  ndmp_send_reply(connection, (void *) &reply,
 770  747                      "sending tape_write reply");
 771  748                  return;
 772  749          }
 773  750          if (session->ns_tape.td_mode == NDMP_TAPE_READ_MODE) {
 774      -                NDMP_LOG(LOG_INFO, "Tape device opened in read-only mode");
      751 +                syslog(LOG_INFO, "Tape device opened in read-only mode");
 775  752                  reply.error = NDMP_PERMISSION_ERR;
 776  753                  ndmp_send_reply(connection, (void *) &reply,
 777  754                      "sending tape_write reply");
 778  755                  return;
 779  756          }
 780  757          if (request->data_out.data_out_len == 0) {
 781  758                  reply.error = NDMP_NO_ERR;
 782  759                  ndmp_send_reply(connection, (void *) &reply,
 783  760                      "sending tape_write reply");
 784  761                  return;
↓ open down ↓ 10 lines elided ↑ open up ↑
 795  772                  reply.error = NDMP_DEVICE_BUSY_ERR;
 796  773                  ndmp_send_reply(connection, (void *) &reply,
 797  774                      "sending tape_write reply");
 798  775                  return;
 799  776          }
 800  777  
 801  778          n = write(session->ns_tape.td_fd, request->data_out.data_out_val,
 802  779              request->data_out.data_out_len);
 803  780  
 804  781          if (n < 0) {
 805      -                NDMP_LOG(LOG_ERR, "Tape write error: %m.");
      782 +                syslog(LOG_ERR, "Tape write error: %m.");
 806  783                  reply.error = NDMP_IO_ERR;
 807  784          } else if (n == 0) {
 808      -                NDMP_LOG(LOG_INFO, "EOM detected");
      785 +                syslog(LOG_INFO, "EOM detected");
 809  786                  reply.error = NDMP_EOM_ERR;
 810  787          } else {
 811  788                  NS_ADD(wtape, n);
 812  789                  reply.count = n;
 813  790                  reply.error = NDMP_NO_ERR;
 814  791  
 815  792                  if (n < request->data_out.data_out_len)
 816      -                        NDMP_LOG(LOG_DEBUG,
      793 +                        syslog(LOG_DEBUG,
 817  794                                  "EOM is coming (partial write of %d bytes)", n);
 818  795          }
 819  796  
 820  797          ndmp_send_reply(connection, (void *) &reply,
 821  798              "sending tape_write reply");
 822  799  }
 823  800  
 824  801  /*
 825  802   * ndmpd_tape_read_v3
 826  803   *
↓ open down ↓ 19 lines elided ↑ open up ↑
 846  823  {
 847  824          ndmp_tape_read_request *request = (ndmp_tape_read_request *) body;
 848  825          ndmp_tape_read_reply reply;
 849  826          ndmpd_session_t *session = ndmp_get_client_data(connection);
 850  827          char *buf;
 851  828          int n;
 852  829  
 853  830          reply.data_in.data_in_len = 0;
 854  831  
 855  832          if (session->ns_tape.td_fd == -1) {
 856      -                NDMP_LOG(LOG_ERR, "Tape device is not open.");
      833 +                syslog(LOG_ERR, "Tape device is not open.");
 857  834                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
 858  835                  ndmp_send_reply(connection, (void *) &reply,
 859  836                      "sending tape_read reply");
 860  837                  return;
 861  838          }
 862  839          if (request->count == 0) {
 863  840                  reply.error = NDMP_NO_ERR;
 864  841                  ndmp_send_reply(connection, (void *) &reply,
 865  842                      "sending tape_read reply");
 866  843                  return;
↓ open down ↓ 27 lines elided ↑ open up ↑
 894  871                   * of spanned data between the tapes.
 895  872                   */
 896  873                  if (errno == ENOSPC) {
 897  874                          reply.error = NDMP_EOF_ERR;
 898  875                  }
 899  876                  /*
 900  877                   * If at beginning of file and read fails with EIO, then it's
 901  878                   * repeated attempt to read at EOT.
 902  879                   */
 903  880                  else if (errno == EIO && tape_is_at_bof(session)) {
 904      -                        NDMP_LOG(LOG_DEBUG, "Repeated read at EOT");
      881 +                        syslog(LOG_DEBUG, "Repeated read at EOT");
 905  882                          reply.error = NDMP_EOM_ERR;
 906  883                  }
 907  884                  /*
 908  885                   * According to NDMPv4 spec preferred error code when
 909  886                   * trying to read from blank tape is NDMP_EOM_ERR.
 910  887                   */
 911  888                  else if (errno == EIO && tape_is_at_bot(session)) {
 912      -                        NDMP_LOG(LOG_ERR, "Blank tape detected, returning EOM");
      889 +                        syslog(LOG_ERR, "Blank tape detected, returning EOM");
 913  890                          reply.error = NDMP_EOM_ERR;
 914  891                  } else {
 915      -                        NDMP_LOG(LOG_ERR, "Tape read error: %m.");
      892 +                        syslog(LOG_ERR, "Tape read error: %m.");
 916  893                          reply.error = NDMP_IO_ERR;
 917  894                  }
 918  895          } else if (n == 0) {
 919  896                  if (tape_is_at_bof(session)) {
 920      -                        NDMP_LOG(LOG_DEBUG, "EOT detected");
      897 +                        syslog(LOG_DEBUG, "EOT detected");
 921  898                          reply.error = NDMP_EOM_ERR;
 922  899                  } else {
 923  900                          /* reposition the tape to BOT side of FM */
 924  901                          fm_dance(session);
 925      -                        NDMP_LOG(LOG_DEBUG, "EOF detected");
      902 +                        syslog(LOG_DEBUG, "EOF detected");
 926  903                          reply.error = NDMP_EOF_ERR;
 927  904                  }
 928  905          } else {
 929  906                  session->ns_tape.td_pos += n;
 930  907                  reply.data_in.data_in_len = n;
 931  908                  reply.data_in.data_in_val = buf;
 932  909                  reply.error = NDMP_NO_ERR;
 933  910                  NS_ADD(rtape, n);
 934  911          }
 935  912  
↓ open down ↓ 25 lines elided ↑ open up ↑
 961  938  void
 962  939  ndmpd_tape_get_state_v4(ndmp_connection_t *connection, void *body)
 963  940  {
 964  941          ndmp_tape_get_state_reply_v4 reply;
 965  942          ndmpd_session_t *session = ndmp_get_client_data(connection);
 966  943          struct mtget mtstatus;
 967  944          struct mtdrivetype_request dtpr;
 968  945          struct mtdrivetype dtp;
 969  946  
 970  947          if (session->ns_tape.td_fd == -1) {
 971      -                NDMP_LOG(LOG_ERR, "Tape device is not open.");
      948 +                syslog(LOG_ERR, "Tape device is not open.");
 972  949                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
 973  950                  ndmp_send_reply(connection, (void *) &reply,
 974  951                      "sending tape_get_state reply");
 975  952                  return;
 976  953          }
 977  954  
 978  955          /*
 979  956           * Need code to detect NDMP_TAPE_STATE_NOREWIND
 980  957           */
 981  958  
 982  959          if (ioctl(session->ns_tape.td_fd, MTIOCGET, &mtstatus) == -1) {
 983      -                NDMP_LOG(LOG_ERR,
      960 +                syslog(LOG_ERR,
 984  961                      "Failed to get status information from tape: %m.");
 985      -                NDMP_LOG(LOG_DEBUG, "ioctl(MTIOCGET) error: %m.");
 986  962  
 987  963                  reply.error = NDMP_IO_ERR;
 988  964                  ndmp_send_reply(connection, (void *)&reply,
 989  965                      "sending tape_get_state reply");
 990  966                  return;
 991  967          }
 992  968  
 993  969          dtpr.size = sizeof (struct mtdrivetype);
 994  970          dtpr.mtdtp = &dtp;
 995  971          if (ioctl(session->ns_tape.td_fd, MTIOCGETDRIVETYPE, &dtpr) == -1) {
 996      -                NDMP_LOG(LOG_ERR,
      972 +                syslog(LOG_ERR,
 997  973                      "Failed to get drive type information from tape: %m.");
 998      -                NDMP_LOG(LOG_DEBUG, "ioctl(MTIOCGETDRIVETYPE) error: %m.");
 999  974  
1000  975                  reply.error = NDMP_IO_ERR;
1001  976                  ndmp_send_reply(connection, (void *)&reply,
1002  977                      "sending tape_get_state reply");
1003  978                  return;
1004  979          }
1005  980  
1006  981          reply.flags = NDMP_TAPE_NOREWIND;
1007  982  
1008  983          reply.file_num = mtstatus.mt_fileno;
↓ open down ↓ 7 lines elided ↑ open up ↑
1016  991                      (session->ns_mover.md_record_size / dtp.bsize);
1017  992  
1018  993          reply.total_space = long_long_to_quad(0LL); /* not supported */
1019  994          reply.space_remain = long_long_to_quad(0LL); /* not supported */
1020  995          reply.soft_errors = 0;
1021  996          reply.unsupported = NDMP_TAPE_STATE_SOFT_ERRORS_INVALID |
1022  997              NDMP_TAPE_STATE_TOTAL_SPACE_INVALID |
1023  998              NDMP_TAPE_STATE_SPACE_REMAIN_INVALID |
1024  999              NDMP_TAPE_STATE_PARTITION_INVALID;
1025 1000  
1026      -        NDMP_LOG(LOG_DEBUG, "f 0x%x, fnum %d, bsize %d, bno: %d",
1027      -            reply.flags, reply.file_num, reply.block_size, reply.blockno);
1028      -
1029 1001          reply.error = NDMP_NO_ERR;
1030 1002          ndmp_send_reply(connection, (void *) &reply,
1031 1003              "sending tape_get_state reply");
1032 1004  }
1033 1005  /*
1034 1006   * ndmpd_tape_close_v4
1035 1007   *
1036 1008   * This handler (v4) closes the currently open tape device.
1037 1009   *
1038 1010   * Parameters:
↓ open down ↓ 4 lines elided ↑ open up ↑
1043 1015   *   void
1044 1016   */
1045 1017  /*ARGSUSED*/
1046 1018  void
1047 1019  ndmpd_tape_close_v4(ndmp_connection_t *connection, void *body)
1048 1020  {
1049 1021          ndmp_tape_close_reply reply;
1050 1022          ndmpd_session_t *session = ndmp_get_client_data(connection);
1051 1023  
1052 1024          if (session->ns_tape.td_fd == -1) {
1053      -                NDMP_LOG(LOG_ERR, "Tape device is not open.");
     1025 +                syslog(LOG_ERR, "Tape device is not open.");
1054 1026                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
1055 1027                  ndmp_send_reply(connection, (void *) &reply,
1056 1028                      "sending tape_close reply");
1057 1029                  return;
1058 1030          }
1059 1031  
1060 1032          /*
1061 1033           * V4 suggests that this should not be accepted
1062 1034           * when mover is in listen or active state
1063 1035           */
↓ open down ↓ 58 lines elided ↑ open up ↑
1122 1094  
1123 1095          n = read(session->ns_tape.td_fd, buf, wanted);
1124 1096          if (n < 0) {
1125 1097                  /*
1126 1098                   * This fix is for Symantec during importing
1127 1099                   * of spanned data between the tapes.
1128 1100                   */
1129 1101                  if (errno == ENOSPC) {
1130 1102                          reply->error = NDMP_EOF_ERR;
1131 1103                  } else {
1132      -                        NDMP_LOG(LOG_ERR, "Tape read error: %m.");
     1104 +                        syslog(LOG_ERR, "Tape read error: %m.");
1133 1105                          reply->error = NDMP_IO_ERR;
1134 1106                  }
1135 1107          } else if (n == 0) {
1136      -                NDMP_LOG(LOG_DEBUG, "NDMP_EOF_ERR");
1137      -
1138 1108                  reply->error = NDMP_EOF_ERR;
1139 1109  
1140 1110                  (void) ndmp_mtioctl(session->ns_tape.td_fd, MTFSF, 1);
1141 1111  
1142 1112                  len = strlen(NDMP_EOM_MAGIC);
1143 1113                  (void) memset(buf, 0, len);
1144 1114                  n = read(session->ns_tape.td_fd, buf, len);
1145 1115                  buf[len] = '\0';
1146 1116  
1147      -                NDMP_LOG(LOG_DEBUG, "Checking EOM: nread %d [%s]", n, buf);
1148      -
1149 1117                  (void) ndmp_mtioctl(session->ns_tape.td_fd, MTBSF, 1);
1150 1118  
1151 1119                  if (strncmp(buf, NDMP_EOM_MAGIC, len) != 0)
1152 1120                          (void) ndmp_mtioctl(session->ns_tape.td_fd, MTFSF, 1);
1153 1121          } else {
1154 1122                  session->ns_tape.td_pos += n;
1155 1123                  reply->data_in.data_in_len = n;
1156 1124                  reply->data_in.data_in_val = buf;
1157 1125                  reply->error = NDMP_NO_ERR;
1158 1126                  NS_ADD(rtape, n);
↓ open down ↓ 41 lines elided ↑ open up ↑
1200 1168   */
1201 1169  static void
1202 1170  common_tape_open(ndmp_connection_t *connection, char *devname, int ndmpmode)
1203 1171  {
1204 1172          ndmpd_session_t *session = ndmp_get_client_data(connection);
1205 1173          char adptnm[SCSI_MAX_NAME];
1206 1174          int err;
1207 1175          int mode;
1208 1176          int sid, lun;
1209 1177          scsi_adapter_t *sa;
1210      -        int devid;
     1178 +        int devid = -1;
1211 1179  
1212 1180          err = NDMP_NO_ERR;
1213 1181  
1214 1182          if (session->ns_tape.td_fd != -1 || session->ns_scsi.sd_is_open != -1) {
1215      -                NDMP_LOG(LOG_INFO,
     1183 +                syslog(LOG_INFO,
1216 1184                      "Connection already has a tape or scsi device open");
1217 1185                  err = NDMP_DEVICE_OPENED_ERR;
1218 1186          } else if (!validmode(ndmpmode))
1219 1187                  err = NDMP_ILLEGAL_ARGS_ERR;
1220 1188          if ((sa = scsi_get_adapter(0)) != NULL) {
1221      -                NDMP_LOG(LOG_DEBUG, "Adapter device opened: %s", devname);
1222 1189                  (void) strlcpy(adptnm, devname, SCSI_MAX_NAME-2);
1223 1190                  adptnm[SCSI_MAX_NAME-1] = '\0';
1224 1191                  sid = lun = -1;
1225 1192          }
1226 1193          if (sa) {
1227 1194                  scsi_find_sid_lun(sa, devname, &sid, &lun);
1228 1195                  if (ndmp_open_list_find(devname, sid, lun) == 0 &&
1229 1196                      (devid = open(devname, O_RDWR | O_NDELAY)) < 0) {
1230      -                        NDMP_LOG(LOG_ERR,
     1197 +                        syslog(LOG_ERR,
1231 1198                              "Failed to open device %s: %m.", devname);
1232 1199                          err = NDMP_NO_DEVICE_ERR;
1233 1200                  } else {
1234 1201                          (void) close(devid);
1235 1202                  }
1236 1203          } else {
1237      -                NDMP_LOG(LOG_ERR, "%s: No such tape device.", devname);
     1204 +                syslog(LOG_ERR, "%s: No such tape device.", devname);
1238 1205                  err = NDMP_NO_DEVICE_ERR;
1239 1206          }
1240 1207  
1241 1208          if (err != NDMP_NO_ERR) {
1242 1209                  tape_open_send_reply(connection, err);
1243 1210                  return;
1244 1211          }
1245 1212  
1246 1213          /*
1247 1214           * If tape is not opened in raw mode and tape is not loaded
↓ open down ↓ 14 lines elided ↑ open up ↑
1262 1229              ndmpmode == NDMP_TAPE_RAW_MODE && errno == EACCES) {
1263 1230                  /*
1264 1231                   * V4 suggests that if the tape is open in raw mode
1265 1232                   * and could not be opened with write access, it should
1266 1233                   * be opened read only instead.
1267 1234                   */
1268 1235                  ndmpmode = NDMP_TAPE_READ_MODE;
1269 1236                  session->ns_tape.td_fd = open(devname, O_RDONLY);
1270 1237          }
1271 1238          if (session->ns_tape.td_fd < 0) {
1272      -                NDMP_LOG(LOG_ERR, "Failed to open tape device %s: %m.",
     1239 +                syslog(LOG_ERR, "Failed to open tape device %s: %m.",
1273 1240                      devname);
1274 1241                  switch (errno) {
1275 1242                  case EACCES:
1276 1243                          err = NDMP_WRITE_PROTECT_ERR;
1277 1244                          break;
1278 1245                  case ENOENT:
1279 1246                          err = NDMP_NO_DEVICE_ERR;
1280 1247                          break;
1281 1248                  case EBUSY:
1282 1249                          err = NDMP_DEVICE_BUSY_ERR;
↓ open down ↓ 27 lines elided ↑ open up ↑
1310 1277                  tape_open_send_reply(connection, err);
1311 1278                  return;
1312 1279          }
1313 1280  
1314 1281          session->ns_tape.td_mode = ndmpmode;
1315 1282          session->ns_tape.td_sid = sid;
1316 1283          session->ns_tape.td_lun = lun;
1317 1284          (void) strlcpy(session->ns_tape.td_adapter_name, adptnm, SCSI_MAX_NAME);
1318 1285          session->ns_tape.td_record_count = 0;
1319 1286  
1320      -        NDMP_LOG(LOG_DEBUG, "Tape is opened fd: %d", session->ns_tape.td_fd);
1321      -
1322 1287          tape_open_send_reply(connection, NDMP_NO_ERR);
1323 1288  }
1324 1289  
1325 1290  
1326 1291  /*
1327 1292   * common_tape_close
1328 1293   *
1329 1294   * Generic function for closing the tape
1330 1295   *
1331 1296   * Parameters:
↓ open down ↓ 46 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX