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-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-2690 NDMP V4 required to have Record size is persistent between mover connections and state transitions
NEX-2911 NDMP logging should use syslog and is too chatty
NEX-727 Netbackup Catalog verification hangs waiting for NDMP server
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-559 NDMP cannot backup/restore a file which spans multiple tapes
SUP-484 NDMP backup jobs error out when reaching the end of media (EOM)

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/ndmpd/ndmp/ndmpd_mover.c
          +++ new/usr/src/cmd/ndmpd/ndmp/ndmpd_mover.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/ioctl.h>
  43   43  #include <sys/types.h>
  44   44  #include <sys/socket.h>
  45   45  #include <sys/socketvar.h>
       46 +#include <syslog.h>
  46   47  #include <netinet/in.h>
  47   48  #include <arpa/inet.h>
  48   49  #include <net/if.h>
  49   50  #include <errno.h>
  50   51  #include <fcntl.h>
  51   52  #include <netdb.h>
  52   53  #include <stdlib.h>
  53   54  #include <unistd.h>
  54   55  #include <string.h>
  55   56  #include "ndmpd_common.h"
↓ open down ↓ 123 lines elided ↑ open up ↑
 179  180          ndmp_mover_listen_request_v2 *request;
 180  181          ndmp_mover_listen_reply_v2 reply;
 181  182          ndmpd_session_t *session = ndmp_get_client_data(connection);
 182  183          ulong_t addr;
 183  184          ushort_t port;
 184  185  
 185  186          request = (ndmp_mover_listen_request_v2 *)body;
 186  187  
 187  188          if (session->ns_mover.md_state != NDMP_MOVER_STATE_IDLE ||
 188  189              session->ns_data.dd_state != NDMP_DATA_STATE_IDLE) {
 189      -                NDMP_LOG(LOG_DEBUG, "Invalid state");
 190  190                  reply.error = NDMP_ILLEGAL_STATE_ERR;
 191  191                  ndmp_send_reply(connection, (void *) &reply,
 192  192                      "sending mover_listen reply");
 193  193                  return;
 194  194          }
 195  195          session->ns_mover.md_mode = request->mode;
 196  196  
 197  197          if (request->addr_type == NDMP_ADDR_LOCAL) {
 198  198                  reply.mover.addr_type = NDMP_ADDR_LOCAL;
 199  199          } else {
↓ open down ↓ 38 lines elided ↑ open up ↑
 238  238   *   void
 239  239   */
 240  240  /*ARGSUSED*/
 241  241  void
 242  242  ndmpd_mover_continue_v2(ndmp_connection_t *connection, void *body)
 243  243  {
 244  244          ndmp_mover_continue_reply reply;
 245  245          ndmpd_session_t *session = ndmp_get_client_data(connection);
 246  246  
 247  247          if (session->ns_mover.md_state != NDMP_MOVER_STATE_PAUSED) {
 248      -                NDMP_LOG(LOG_DEBUG, "Invalid state");
 249  248  
 250  249                  reply.error = NDMP_ILLEGAL_STATE_ERR;
 251  250                  ndmp_send_reply(connection, (void *) &reply,
 252  251                      "sending mover_continue reply");
 253  252                  return;
 254  253          }
 255  254          session->ns_mover.md_state = NDMP_MOVER_STATE_ACTIVE;
 256  255          reply.error = NDMP_NO_ERR;
 257  256          ndmp_send_reply(connection, (void *) &reply,
 258  257              "sending mover_continue reply");
↓ open down ↓ 14 lines elided ↑ open up ↑
 273  272   */
 274  273  /*ARGSUSED*/
 275  274  void
 276  275  ndmpd_mover_abort_v2(ndmp_connection_t *connection, void *body)
 277  276  {
 278  277          ndmp_mover_abort_reply reply;
 279  278          ndmpd_session_t *session = ndmp_get_client_data(connection);
 280  279  
 281  280          if (session->ns_mover.md_state == NDMP_MOVER_STATE_IDLE ||
 282  281              session->ns_mover.md_state == NDMP_MOVER_STATE_HALTED) {
 283      -                NDMP_LOG(LOG_DEBUG, "Invalid state");
 284  282  
 285  283                  reply.error = NDMP_ILLEGAL_STATE_ERR;
 286  284                  ndmp_send_reply(connection, (void *) &reply,
 287  285                      "sending mover_abort reply");
 288  286                  return;
 289  287          }
 290  288  
 291  289          reply.error = NDMP_NO_ERR;
 292  290          ndmp_send_reply(connection, (void *) &reply,
 293  291              "sending mover_abort reply");
↓ open down ↓ 16 lines elided ↑ open up ↑
 310  308   *   void
 311  309   */
 312  310  /*ARGSUSED*/
 313  311  void
 314  312  ndmpd_mover_stop_v2(ndmp_connection_t *connection, void *body)
 315  313  {
 316  314          ndmp_mover_stop_reply reply;
 317  315          ndmpd_session_t *session = ndmp_get_client_data(connection);
 318  316  
 319  317          if (session->ns_mover.md_state != NDMP_MOVER_STATE_HALTED) {
 320      -                NDMP_LOG(LOG_DEBUG, "Invalid state");
 321  318  
 322  319                  reply.error = NDMP_ILLEGAL_STATE_ERR;
 323  320                  ndmp_send_reply(connection, (void *) &reply,
 324  321                      "sending mover_stop reply");
 325  322                  return;
 326  323          }
 327  324  
 328  325          ndmp_waitfor_op(session);
 329  326          reply.error = NDMP_NO_ERR;
 330  327          ndmp_send_reply(connection, (void *) &reply,
↓ open down ↓ 32 lines elided ↑ open up ↑
 363  360           * The NDMPv2 specification states that "a window can be set only
 364  361           * when in the listen or paused state."
 365  362           *
 366  363           * See the comment in ndmpd_mover_set_window_v3 regarding the reason for
 367  364           * allowing it in the idle state as well.
 368  365           */
 369  366          if (session->ns_mover.md_state != NDMP_MOVER_STATE_IDLE &&
 370  367              session->ns_mover.md_state != NDMP_MOVER_STATE_PAUSED &&
 371  368              session->ns_mover.md_state != NDMP_MOVER_STATE_LISTEN) {
 372  369                  reply.error = NDMP_ILLEGAL_STATE_ERR;
 373      -                NDMP_LOG(LOG_DEBUG, "Invalid state %d",
 374      -                    session->ns_mover.md_state);
 375  370          } else {
 376  371                  if (quad_to_long_long(request->length) == 0) {
 377  372                          reply.error = NDMP_ILLEGAL_ARGS_ERR;
 378      -                        NDMP_LOG(LOG_DEBUG, "Invalid window size %d",
      373 +                        syslog(LOG_ERR, "Illegal window size %d",
 379  374                              quad_to_long_long(request->length));
 380  375                  } else {
 381  376                          reply.error = NDMP_NO_ERR;
 382  377                          session->ns_mover.md_window_offset =
 383  378                              quad_to_long_long(request->offset);
 384  379                          session->ns_mover.md_window_length =
 385  380                              quad_to_long_long(request->length);
 386  381                          session->ns_mover.md_position =
 387  382                              session->ns_mover.md_window_offset;
 388  383                  }
↓ open down ↓ 26 lines elided ↑ open up ↑
 415  410  ndmpd_mover_read_v2(ndmp_connection_t *connection, void *body)
 416  411  {
 417  412          ndmp_mover_read_request *request = (ndmp_mover_read_request *) body;
 418  413          ndmp_mover_read_reply reply;
 419  414          ndmpd_session_t *session = ndmp_get_client_data(connection);
 420  415          int err;
 421  416  
 422  417          if (session->ns_mover.md_state != NDMP_MOVER_STATE_ACTIVE ||
 423  418              session->ns_mover.md_bytes_left_to_read != 0 ||
 424  419              session->ns_mover.md_mode != NDMP_MOVER_MODE_WRITE) {
 425      -                NDMP_LOG(LOG_DEBUG, "Invalid state");
 426  420                  reply.error = NDMP_ILLEGAL_STATE_ERR;
 427  421                  ndmp_send_reply(connection, &reply,
 428  422                      "sending mover_read reply");
 429  423                  return;
 430  424          }
 431  425          if (session->ns_tape.td_fd == -1) {
 432      -                NDMP_LOG(LOG_DEBUG, "Tape device is not open");
      426 +                syslog(LOG_ERR, "Tape device is not open");
 433  427                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
 434  428                  ndmp_send_reply(connection, &reply,
 435  429                      "sending mover_read reply");
 436  430                  return;
 437  431          }
 438  432  
 439  433          reply.error = NDMP_NO_ERR;
 440  434          ndmp_send_reply(connection, &reply, "sending mover_read reply");
 441  435  
 442  436          err = ndmpd_mover_seek(session, quad_to_long_long(request->offset),
↓ open down ↓ 30 lines elided ↑ open up ↑
 473  467   *   void
 474  468   */
 475  469  /*ARGSUSED*/
 476  470  void
 477  471  ndmpd_mover_close_v2(ndmp_connection_t *connection, void *body)
 478  472  {
 479  473          ndmp_mover_close_reply reply;
 480  474          ndmpd_session_t *session = ndmp_get_client_data(connection);
 481  475  
 482  476          if (session->ns_mover.md_state != NDMP_MOVER_STATE_PAUSED) {
 483      -                NDMP_LOG(LOG_DEBUG, "Invalid state");
 484  477  
 485  478                  reply.error = NDMP_ILLEGAL_STATE_ERR;
 486  479                  ndmp_send_reply(connection, &reply,
 487  480                      "sending mover_close reply");
 488  481                  return;
 489  482          }
 490  483          free(session->ns_mover.md_data_addr_v4.tcp_addr_v4);
 491  484  
 492  485          reply.error = NDMP_NO_ERR;
 493  486          ndmp_send_reply(connection, &reply, "sending mover_close reply");
↓ open down ↓ 12 lines elided ↑ open up ↑
 506  499   *   body       (input) - request message body.
 507  500   *
 508  501   * Returns:
 509  502   *   void
 510  503   */
 511  504  void
 512  505  ndmpd_mover_set_record_size_v2(ndmp_connection_t *connection, void *body)
 513  506  {
 514  507          ndmp_mover_set_record_size_request *request;
 515  508          ndmp_mover_set_record_size_reply reply;
      509 +
 516  510          ndmpd_session_t *session = ndmp_get_client_data(connection);
 517  511  
 518  512          request = (ndmp_mover_set_record_size_request *) body;
 519  513  
 520  514          session->ns_mover.md_record_size = request->len;
 521  515          session->ns_mover.md_buf = realloc(session->ns_mover.md_buf,
 522  516              request->len);
 523  517  
 524  518          reply.error = NDMP_NO_ERR;
 525  519          ndmp_send_reply(connection, &reply,
↓ open down ↓ 79 lines elided ↑ open up ↑
 605  599          ushort_t port;
 606  600  
 607  601          request = (ndmp_mover_listen_request_v3 *)body;
 608  602  
 609  603          (void) memset((void*)&reply, 0, sizeof (reply));
 610  604          reply.error = NDMP_NO_ERR;
 611  605  
 612  606          if (request->mode != NDMP_MOVER_MODE_READ &&
 613  607              request->mode != NDMP_MOVER_MODE_WRITE) {
 614  608                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
 615      -                NDMP_LOG(LOG_DEBUG, "Invalid mode %d", request->mode);
 616  609          } else if (!ndmp_valid_v3addr_type(request->addr_type)) {
 617  610                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
 618      -                NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
 619      -                    request->addr_type);
 620  611          } else if (session->ns_mover.md_state != NDMP_MOVER_STATE_IDLE) {
 621  612                  reply.error = NDMP_ILLEGAL_STATE_ERR;
 622      -                NDMP_LOG(LOG_DEBUG,
 623      -                    "Invalid mover state to process listen request");
 624  613          } else if (session->ns_data.dd_state != NDMP_DATA_STATE_IDLE) {
 625  614                  reply.error = NDMP_ILLEGAL_STATE_ERR;
 626      -                NDMP_LOG(LOG_DEBUG,
 627      -                    "Invalid data state to process listen request");
 628  615          } else if (session->ns_tape.td_fd == -1) {
 629  616                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
 630      -                NDMP_LOG(LOG_DEBUG, "No tape device open");
      617 +                syslog(LOG_ERR, "No tape device open");
 631  618          } else if (request->mode == NDMP_MOVER_MODE_READ &&
 632  619              session->ns_tape.td_mode == NDMP_TAPE_READ_MODE) {
 633  620                  reply.error = NDMP_PERMISSION_ERR;
 634      -                NDMP_LOG(LOG_ERR, "Write protected device.");
      621 +                syslog(LOG_ERR, "Write protected device.");
 635  622          }
 636  623  
 637  624          if (reply.error != NDMP_NO_ERR) {
 638  625                  ndmp_send_reply(connection, &reply,
 639  626                      "error sending ndmp_mover_listen reply");
 640  627                  return;
 641  628          }
 642  629  
 643  630          switch (request->addr_type) {
 644  631          case NDMP_ADDR_LOCAL:
↓ open down ↓ 6 lines elided ↑ open up ↑
 651  638                          reply.error = NDMP_IO_ERR;
 652  639                          break;
 653  640                  }
 654  641                  reply.error = NDMP_NO_ERR;
 655  642                  reply.data_connection_addr.addr_type = NDMP_ADDR_TCP;
 656  643                  reply.data_connection_addr.tcp_ip_v3 = htonl(addr);
 657  644                  reply.data_connection_addr.tcp_port_v3 = htons(port);
 658  645                  session->ns_mover.md_data_addr.addr_type = NDMP_ADDR_TCP;
 659  646                  session->ns_mover.md_data_addr.tcp_ip_v3 = addr;
 660  647                  session->ns_mover.md_data_addr.tcp_port_v3 = ntohs(port);
 661      -                NDMP_LOG(LOG_DEBUG, "listen_socket: %d",
      648 +                syslog(LOG_DEBUG, "listen_socket: %d",
 662  649                      session->ns_mover.md_listen_sock);
 663  650                  break;
 664  651          default:
 665  652                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
 666      -                NDMP_LOG(LOG_DEBUG, "Invalid address type: %d",
 667      -                    request->addr_type);
 668  653          }
 669  654  
 670  655          if (reply.error == NDMP_NO_ERR) {
 671  656                  session->ns_mover.md_mode = request->mode;
 672  657                  session->ns_mover.md_state = NDMP_MOVER_STATE_LISTEN;
 673  658          }
 674  659  
 675  660          ndmp_send_reply(connection, &reply,
 676  661              "error sending ndmp_mover_listen reply");
 677  662  }
↓ open down ↓ 16 lines elided ↑ open up ↑
 694  679  ndmpd_mover_continue_v3(ndmp_connection_t *connection, void *body)
 695  680  {
 696  681          ndmp_mover_continue_reply reply;
 697  682          ndmpd_session_t *session = ndmp_get_client_data(connection);
 698  683          ndmp_lbr_params_t *nlp = ndmp_get_nlp(session);
 699  684          int ret;
 700  685  
 701  686          (void) memset((void*)&reply, 0, sizeof (reply));
 702  687  
 703  688          if (session->ns_mover.md_state != NDMP_MOVER_STATE_PAUSED) {
 704      -                NDMP_LOG(LOG_DEBUG, "Invalid state");
 705  689                  reply.error = NDMP_ILLEGAL_STATE_ERR;
 706  690                  ndmp_send_reply(connection, (void *) &reply,
 707  691                      "sending mover_continue reply");
 708  692                  return;
 709  693          }
 710  694  
 711  695          if (session->ns_protocol_version == NDMPV4 &&
 712  696              !session->ns_mover.md_pre_cond) {
 713      -                NDMP_LOG(LOG_DEBUG, "Precondition check");
      697 +                syslog(LOG_DEBUG, "Precondition check");
 714  698                  reply.error = NDMP_PRECONDITION_ERR;
 715  699                  ndmp_send_reply(connection, (void *) &reply,
 716  700                      "sending mover_continue reply");
 717  701                  return;
 718  702          }
 719  703          /*
 720  704           * Restore the file handler if the mover is remote to the data
 721  705           * server and the handler was removed pending the continuation of a
 722  706           * seek request. The handler is removed in mover_data_write().
 723  707           */
↓ open down ↓ 22 lines elided ↑ open up ↑
 746  730                              session->ns_mover.md_sock, NDMPD_SELECT_MODE_WRITE,
 747  731                              HC_MOVER, mover_data_write_v3) < 0)
 748  732                                  ndmpd_mover_error(session,
 749  733                                      NDMP_MOVER_HALT_INTERNAL_ERROR);
 750  734                  } else {
 751  735                          /*
 752  736                           * This should not happen because we should be in the
 753  737                           * right window. This means that DMA does not follow
 754  738                           * the V3 spec.
 755  739                           */
 756      -                        NDMP_LOG(LOG_DEBUG, "DMA Error.");
 757  740                          ndmpd_mover_error(session,
 758  741                              NDMP_MOVER_HALT_INTERNAL_ERROR);
 759  742                          return;
 760  743                  }
 761  744          }
 762  745  
 763  746          (void) mutex_lock(&nlp->nlp_mtx);
 764  747          session->ns_mover.md_state = NDMP_MOVER_STATE_ACTIVE;
 765  748          session->ns_mover.md_pause_reason = NDMP_MOVER_PAUSE_NA;
 766  749          /* The tape has been likely exchanged, reset tape block counter */
↓ open down ↓ 21 lines elided ↑ open up ↑
 788  771   */
 789  772  /*ARGSUSED*/
 790  773  void
 791  774  ndmpd_mover_abort_v3(ndmp_connection_t *connection, void *body)
 792  775  {
 793  776          ndmp_mover_abort_reply reply;
 794  777          ndmpd_session_t *session = ndmp_get_client_data(connection);
 795  778  
 796  779          if (session->ns_mover.md_state == NDMP_MOVER_STATE_IDLE ||
 797  780              session->ns_mover.md_state == NDMP_MOVER_STATE_HALTED) {
 798      -                NDMP_LOG(LOG_DEBUG, "Invalid state");
 799  781  
 800  782                  reply.error = NDMP_ILLEGAL_STATE_ERR;
 801  783                  ndmp_send_reply(connection, (void *) &reply,
 802  784                      "sending mover_abort reply");
 803  785                  return;
 804  786          }
 805  787  
 806  788          reply.error = NDMP_NO_ERR;
 807  789          ndmp_send_reply(connection, (void *) &reply,
 808  790              "sending mover_abort reply");
↓ open down ↓ 27 lines elided ↑ open up ↑
 836  818          /*
 837  819           * Note: The spec says that the window can be set only in the listen
 838  820           * and paused states.  We let this happen when mover is in the idle
 839  821           * state as well.  I can't rememebr which NDMP client (net_backup 4.5
 840  822           * or net_worker 6.1.1) forced us to do this!
 841  823           */
 842  824          if (session->ns_mover.md_state != NDMP_MOVER_STATE_IDLE &&
 843  825              session->ns_mover.md_state != NDMP_MOVER_STATE_LISTEN &&
 844  826              session->ns_mover.md_state != NDMP_MOVER_STATE_PAUSED) {
 845  827                  reply.error = NDMP_ILLEGAL_STATE_ERR;
 846      -                NDMP_LOG(LOG_DEBUG, "Invalid state %d",
 847      -                    session->ns_mover.md_state);
 848  828          } else if (session->ns_mover.md_record_size == 0) {
 849  829                  if (session->ns_protocol_version == NDMPV4)
 850  830                          reply.error = NDMP_PRECONDITION_ERR;
 851  831                  else
 852  832                          reply.error = NDMP_ILLEGAL_ARGS_ERR;
 853      -                NDMP_LOG(LOG_DEBUG, "Invalid record size 0");
 854  833          } else
 855  834                  reply.error = NDMP_NO_ERR;
 856  835  
 857  836          if (quad_to_long_long(request->length) == 0) {
 858  837                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
 859      -                NDMP_LOG(LOG_DEBUG, "Invalid window size %d",
 860      -                    quad_to_long_long(request->length));
 861  838          }
 862  839  
 863  840          if (reply.error != NDMP_NO_ERR) {
 864  841                  ndmp_send_reply(connection, (void *) &reply,
 865  842                      "sending mover_set_window_v3 reply");
 866  843                  return;
 867  844          }
 868  845  
 869  846          session->ns_mover.md_pre_cond = TRUE;
 870  847          session->ns_mover.md_window_offset = quad_to_long_long(request->offset);
↓ open down ↓ 46 lines elided ↑ open up ↑
 917  894          ndmp_mover_read_request *request = (ndmp_mover_read_request *)body;
 918  895          ndmp_mover_read_reply reply;
 919  896          ndmpd_session_t *session = ndmp_get_client_data(connection);
 920  897          int err;
 921  898  
 922  899          (void) memset((void*)&reply, 0, sizeof (reply));
 923  900  
 924  901          if (session->ns_mover.md_state != NDMP_MOVER_STATE_ACTIVE ||
 925  902              session->ns_mover.md_mode != NDMP_MOVER_MODE_WRITE) {
 926  903                  reply.error = NDMP_ILLEGAL_STATE_ERR;
 927      -                NDMP_LOG(LOG_DEBUG, "Invalid state");
 928  904          } else if (session->ns_mover.md_bytes_left_to_read != 0) {
 929  905                  reply.error = NDMP_READ_IN_PROGRESS_ERR;
 930      -                NDMP_LOG(LOG_DEBUG, "In progress");
 931  906          } else if (session->ns_tape.td_fd == -1) {
 932  907                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
 933      -                NDMP_LOG(LOG_DEBUG, "Tape device is not open");
      908 +                syslog(LOG_ERR, "Tape device is not open");
 934  909          } else if (quad_to_long_long(request->length) == 0 ||
 935  910              (quad_to_long_long(request->length) == MAX_WINDOW_SIZE &&
 936  911              quad_to_long_long(request->offset) != 0)) {
 937  912                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
 938      -                NDMP_LOG(LOG_DEBUG, "Illegal args");
 939  913          } else {
 940  914                  reply.error = NDMP_NO_ERR;
 941  915          }
 942  916  
 943  917          ndmp_send_reply(connection, (void *) &reply,
 944  918              "sending ndmp_mover_read_reply");
 945  919          if (reply.error != NDMP_NO_ERR)
 946  920                  return;
 947  921  
 948  922          err = ndmpd_mover_seek(session, quad_to_long_long(request->offset),
↓ open down ↓ 39 lines elided ↑ open up ↑
 988  962  {
 989  963          ndmp_mover_set_record_size_request *request;
 990  964          ndmp_mover_set_record_size_reply reply;
 991  965          ndmpd_session_t *session = ndmp_get_client_data(connection);
 992  966          char *cp;
 993  967  
 994  968          request = (ndmp_mover_set_record_size_request *) body;
 995  969  
 996  970          if (session->ns_mover.md_state != NDMP_MOVER_STATE_IDLE) {
 997  971                  reply.error = NDMP_ILLEGAL_STATE_ERR;
 998      -                NDMP_LOG(LOG_DEBUG, "Invalid mover state %d",
 999      -                    session->ns_mover.md_state);
1000  972          } else if (request->len > (unsigned int)ndmp_max_mover_recsize) {
1001  973                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
1002      -                NDMP_LOG(LOG_DEBUG,
1003      -                    "Invalid argument %d, should be > 0 and <= %d",
1004      -                    request->len, ndmp_max_mover_recsize);
1005      -        } else if (request->len == session->ns_mover.md_record_size)
      974 +        } else if (request->len == session->ns_mover.md_record_size) {
1006  975                  reply.error = NDMP_NO_ERR;
1007      -        else if (!(cp = realloc(session->ns_mover.md_buf, request->len))) {
      976 +                session->ns_mover.md_pre_cond = TRUE;
      977 +        } else if (!(cp = realloc(session->ns_mover.md_buf, request->len))) {
1008  978                  reply.error = NDMP_NO_MEM_ERR;
1009  979          } else {
1010  980                  reply.error = NDMP_NO_ERR;
1011  981                  session->ns_mover.md_buf = cp;
1012  982                  session->ns_mover.md_record_size = request->len;
1013  983                  session->ns_mover.md_window_offset = 0;
1014  984                  session->ns_mover.md_window_length = 0;
1015  985          }
1016  986  
1017  987          ndmp_send_reply(connection, (void *) &reply,
↓ open down ↓ 20 lines elided ↑ open up ↑
1038 1008          ndmp_mover_connect_reply_v3 reply;
1039 1009          ndmpd_session_t *session = ndmp_get_client_data(connection);
1040 1010  
1041 1011          request = (ndmp_mover_connect_request_v3*)body;
1042 1012  
1043 1013          (void) memset((void*)&reply, 0, sizeof (reply));
1044 1014  
1045 1015          if (request->mode != NDMP_MOVER_MODE_READ &&
1046 1016              request->mode != NDMP_MOVER_MODE_WRITE) {
1047 1017                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
1048      -                NDMP_LOG(LOG_DEBUG, "Invalid mode %d", request->mode);
1049 1018          } else if (!ndmp_valid_v3addr_type(request->addr.addr_type)) {
1050 1019                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
1051      -                NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
1052      -                    request->addr.addr_type);
1053 1020          } else if (session->ns_mover.md_state != NDMP_MOVER_STATE_IDLE) {
1054 1021                  reply.error = NDMP_ILLEGAL_STATE_ERR;
1055      -                NDMP_LOG(LOG_DEBUG, "Invalid state %d: mover is not idle",
1056      -                    session->ns_mover.md_state);
1057 1022          } else if (session->ns_tape.td_fd == -1) {
1058 1023                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
1059      -                NDMP_LOG(LOG_DEBUG, "No tape device open");
     1024 +                syslog(LOG_ERR, "No tape device open");
1060 1025          } else if (request->mode == NDMP_MOVER_MODE_READ &&
1061 1026              session->ns_tape.td_mode == NDMP_TAPE_READ_MODE) {
1062 1027                  reply.error = NDMP_WRITE_PROTECT_ERR;
1063      -                NDMP_LOG(LOG_ERR, "Write protected device.");
     1028 +                syslog(LOG_ERR, "Write protected device.");
1064 1029          } else
1065 1030                  reply.error = NDMP_NO_ERR;
1066 1031  
1067 1032          if (reply.error != NDMP_NO_ERR) {
1068 1033                  ndmp_send_reply(connection, (void *) &reply,
1069 1034                      "sending ndmp_mover_connect reply");
1070 1035                  return;
1071 1036          }
1072 1037  
1073 1038          switch (request->addr.addr_type) {
1074 1039          case NDMP_ADDR_LOCAL:
1075 1040                  /*
1076 1041                   * Verify that the data server is listening for a
1077 1042                   * local connection.
1078 1043                   */
1079 1044                  if (session->ns_data.dd_state != NDMP_DATA_STATE_LISTEN ||
1080 1045                      session->ns_data.dd_listen_sock != -1) {
1081      -                        NDMP_LOG(LOG_DEBUG,
1082      -                            "Data server is not in local listen state");
1083 1046                          reply.error = NDMP_ILLEGAL_STATE_ERR;
1084 1047                  } else
1085 1048                          session->ns_data.dd_state = NDMP_DATA_STATE_CONNECTED;
1086 1049                  break;
1087 1050  
1088 1051          case NDMP_ADDR_TCP:
1089 1052                  reply.error = mover_connect_sock(session, request->mode,
1090 1053                      request->addr.tcp_ip_v3, request->addr.tcp_port_v3);
1091 1054                  break;
1092 1055  
1093 1056          default:
1094 1057                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
1095      -                NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
1096      -                    request->addr.addr_type);
1097 1058          }
1098 1059  
1099 1060          if (reply.error == NDMP_NO_ERR) {
1100 1061                  session->ns_mover.md_data_addr.addr_type =
1101 1062                      request->addr.addr_type;
1102 1063                  session->ns_mover.md_state = NDMP_MOVER_STATE_ACTIVE;
1103 1064                  session->ns_mover.md_mode = request->mode;
1104 1065          }
1105 1066  
1106 1067          ndmp_send_reply(connection, (void *) &reply,
↓ open down ↓ 82 lines elided ↑ open up ↑
1189 1150          ushort_t port;
1190 1151  
1191 1152          request = (ndmp_mover_listen_request_v4 *)body;
1192 1153  
1193 1154          (void) memset((void*)&reply, 0, sizeof (reply));
1194 1155          reply.error = NDMP_NO_ERR;
1195 1156  
1196 1157          if (request->mode != NDMP_MOVER_MODE_READ &&
1197 1158              request->mode != NDMP_MOVER_MODE_WRITE) {
1198 1159                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
1199      -                NDMP_LOG(LOG_DEBUG, "Invalid mode %d", request->mode);
1200 1160          } else if (!ndmp_valid_v3addr_type(request->addr_type)) {
1201 1161                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
1202      -                NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
1203      -                    request->addr_type);
1204 1162          } else if (session->ns_mover.md_state != NDMP_MOVER_STATE_IDLE) {
1205 1163                  reply.error = NDMP_ILLEGAL_STATE_ERR;
1206      -                NDMP_LOG(LOG_DEBUG,
1207      -                    "Invalid mover state to process listen request");
1208 1164          } else if (session->ns_data.dd_state != NDMP_DATA_STATE_IDLE) {
1209 1165                  reply.error = NDMP_ILLEGAL_STATE_ERR;
1210      -                NDMP_LOG(LOG_DEBUG,
1211      -                    "Invalid data state to process listen request");
1212 1166          } else if (session->ns_tape.td_fd == -1) {
1213 1167                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
1214      -                NDMP_LOG(LOG_DEBUG, "No tape device open");
     1168 +                syslog(LOG_ERR, "No tape device open");
1215 1169          } else if (session->ns_mover.md_record_size == 0) {
1216 1170                  reply.error = NDMP_PRECONDITION_ERR;
1217      -                NDMP_LOG(LOG_DEBUG, "Invalid record size 0");
1218 1171          } else if (request->mode == NDMP_MOVER_MODE_READ &&
1219 1172              session->ns_tape.td_mode == NDMP_TAPE_READ_MODE) {
1220 1173                  reply.error = NDMP_PERMISSION_ERR;
1221      -                NDMP_LOG(LOG_ERR, "Write protected device.");
     1174 +                syslog(LOG_ERR, "Write protected device.");
1222 1175          }
1223 1176  
1224 1177          if (reply.error != NDMP_NO_ERR) {
1225 1178                  ndmp_send_reply(connection, (void *) &reply,
1226 1179                      "error sending ndmp_mover_listen reply");
1227 1180                  return;
1228 1181          }
1229 1182  
1230 1183          switch (request->addr_type) {
1231 1184          case NDMP_ADDR_LOCAL:
↓ open down ↓ 16 lines elided ↑ open up ↑
1248 1201                  session->ns_mover.md_data_addr_v4.tcp_ip_v4(0) = addr;
1249 1202                  session->ns_mover.md_data_addr_v4.tcp_port_v4(0) = ntohs(port);
1250 1203  
1251 1204                  ndmp_copy_addr_v4(&reply.connect_addr,
1252 1205                      &session->ns_mover.md_data_addr_v4);
1253 1206  
1254 1207                  /* For compatibility with V3 */
1255 1208                  session->ns_mover.md_data_addr.addr_type = NDMP_ADDR_TCP;
1256 1209                  session->ns_mover.md_data_addr.tcp_ip_v3 = addr;
1257 1210                  session->ns_mover.md_data_addr.tcp_port_v3 = ntohs(port);
1258      -                NDMP_LOG(LOG_DEBUG, "listen_socket: %d",
     1211 +                syslog(LOG_DEBUG, "listen_socket: %d",
1259 1212                      session->ns_mover.md_listen_sock);
1260 1213                  break;
1261 1214          default:
1262 1215                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
1263      -                NDMP_LOG(LOG_DEBUG, "Invalid address type: %d",
1264      -                    request->addr_type);
1265 1216          }
1266 1217  
1267 1218          if (reply.error == NDMP_NO_ERR) {
1268 1219                  session->ns_mover.md_mode = request->mode;
1269 1220                  session->ns_mover.md_state = NDMP_MOVER_STATE_LISTEN;
1270 1221          }
1271 1222  
1272 1223          ndmp_send_reply(connection, (void *) &reply,
1273 1224              "error sending ndmp_mover_listen reply");
1274 1225          free(reply.connect_addr.tcp_addr_v4);
↓ open down ↓ 17 lines elided ↑ open up ↑
1292 1243          ndmp_mover_connect_request_v4 *request;
1293 1244          ndmp_mover_connect_reply_v4 reply;
1294 1245          ndmpd_session_t *session = ndmp_get_client_data(connection);
1295 1246  
1296 1247          request = (ndmp_mover_connect_request_v4 *)body;
1297 1248          (void) memset((void*)&reply, 0, sizeof (reply));
1298 1249  
1299 1250          if (request->mode != NDMP_MOVER_MODE_READ &&
1300 1251              request->mode != NDMP_MOVER_MODE_WRITE) {
1301 1252                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
1302      -                NDMP_LOG(LOG_DEBUG, "Invalid mode %d", request->mode);
1303 1253          } else if (!ndmp_valid_v3addr_type(request->addr.addr_type)) {
1304 1254                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
1305      -                NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
1306      -                    request->addr.addr_type);
1307 1255          } else if (session->ns_mover.md_state != NDMP_MOVER_STATE_IDLE) {
1308 1256                  reply.error = NDMP_ILLEGAL_STATE_ERR;
1309      -                NDMP_LOG(LOG_DEBUG, "Invalid state %d: mover is not idle",
1310      -                    session->ns_mover.md_state);
1311 1257          } else if (session->ns_tape.td_fd == -1) {
1312 1258                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
1313      -                NDMP_LOG(LOG_DEBUG, "No tape device open");
     1259 +                syslog(LOG_ERR, "No tape device open");
1314 1260          } else if (request->mode == NDMP_MOVER_MODE_READ &&
1315 1261              session->ns_tape.td_mode == NDMP_TAPE_READ_MODE) {
1316 1262                  reply.error = NDMP_PERMISSION_ERR;
1317      -                NDMP_LOG(LOG_ERR, "Write protected device.");
     1263 +                syslog(LOG_ERR, "Write protected device.");
1318 1264          } else if (session->ns_mover.md_record_size == 0) {
1319 1265                  reply.error = NDMP_PRECONDITION_ERR;
1320      -                NDMP_LOG(LOG_DEBUG, "Invalid record size 0");
1321 1266          } else
1322 1267                  reply.error = NDMP_NO_ERR;
1323 1268  
1324 1269          if (reply.error != NDMP_NO_ERR) {
1325 1270                  ndmp_send_reply(connection, (void *) &reply,
1326 1271                      "sending ndmp_mover_connect reply");
1327 1272                  return;
1328 1273          }
1329 1274  
1330 1275          switch (request->addr.addr_type) {
1331 1276          case NDMP_ADDR_LOCAL:
1332 1277                  /*
1333 1278                   * Verify that the data server is listening for a
1334 1279                   * local connection.
1335 1280                   */
1336 1281                  if (session->ns_data.dd_state != NDMP_DATA_STATE_LISTEN ||
1337 1282                      session->ns_data.dd_listen_sock != -1) {
1338      -                        NDMP_LOG(LOG_DEBUG,
1339      -                            "Data server is not in local listen state");
1340 1283                          reply.error = NDMP_ILLEGAL_STATE_ERR;
1341 1284                  } else
1342 1285                          session->ns_data.dd_state = NDMP_DATA_STATE_CONNECTED;
1343 1286                  break;
1344 1287  
1345 1288          case NDMP_ADDR_TCP:
1346 1289                  reply.error = mover_connect_sock(session, request->mode,
1347 1290                      request->addr.tcp_ip_v4(0), request->addr.tcp_port_v4(0));
1348 1291                  break;
1349 1292  
1350 1293          default:
1351 1294                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
1352      -                NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
1353      -                    request->addr.addr_type);
1354 1295          }
1355 1296  
1356 1297          if (reply.error == NDMP_NO_ERR) {
1357 1298                  session->ns_mover.md_data_addr.addr_type =
1358 1299                      request->addr.addr_type;
1359 1300                  session->ns_mover.md_state = NDMP_MOVER_STATE_ACTIVE;
1360 1301                  session->ns_mover.md_mode = request->mode;
1361 1302          }
1362 1303  
1363 1304          ndmp_send_reply(connection, (void *) &reply,
↓ open down ↓ 140 lines elided ↑ open up ↑
1504 1445          ssize_t n;
1505 1446          ulong_t count = 0;
1506 1447  
1507 1448          while (count < length) {
1508 1449                  if (session->ns_eof == TRUE ||
1509 1450                      session->ns_data.dd_abort == TRUE)
1510 1451                          return (-1);
1511 1452  
1512 1453                  if ((n = write(session->ns_data.dd_sock, &data[count],
1513 1454                      length - count)) < 0) {
1514      -                        NDMP_LOG(LOG_ERR, "Socket write error: %m.");
     1455 +                        syslog(LOG_ERR, "Socket write error: %m.");
1515 1456                          return (-1);
1516 1457                  }
1517 1458                  count += n;
1518 1459          }
1519 1460  
1520 1461          return (0);
1521 1462  }
1522 1463  
1523 1464  /*
1524 1465   * ndmpd_local_read
↓ open down ↓ 54 lines elided ↑ open up ↑
1579 1520                          session->ns_mover.md_state = NDMP_MOVER_STATE_PAUSED;
1580 1521                          session->ns_mover.md_pause_reason =
1581 1522                              NDMP_MOVER_PAUSE_SEEK;
1582 1523                          pause_request.reason = NDMP_MOVER_PAUSE_SEEK;
1583 1524                          pause_request.seek_position =
1584 1525                              long_long_to_quad(session->ns_mover.md_position);
1585 1526  
1586 1527                          if (ndmp_send_request(session->ns_connection,
1587 1528                              NDMP_NOTIFY_MOVER_PAUSED, NDMP_NO_ERR,
1588 1529                              (void *) &pause_request, 0) < 0) {
1589      -                                NDMP_LOG(LOG_DEBUG,
1590      -                                    "Sending notify_mover_paused request");
1591 1530                                  ndmpd_mover_error(session,
1592 1531                                      NDMP_MOVER_HALT_INTERNAL_ERROR);
1593 1532                                  return (-1);
1594 1533                          }
1595 1534                          /*
1596 1535                           * Wait until the state is changed by
1597 1536                           * an abort or continue request.
1598 1537                           */
1599 1538                          if (ndmp_wait_for_mover(session) != 0)
1600 1539                                  return (1);
↓ open down ↓ 65 lines elided ↑ open up ↑
1666 1605                                  return (1);
1667 1606  
1668 1607                          ndmpd_mover_error(session,
1669 1608                              (n == 0 ? NDMP_MOVER_HALT_ABORTED :
1670 1609                              NDMP_MOVER_HALT_INTERNAL_ERROR));
1671 1610                          return (n == 0) ? (1) : (-1);
1672 1611                  }
1673 1612                  session->ns_mover.md_w_index = n;
1674 1613                  session->ns_mover.md_r_index = 0;
1675 1614  
1676      -                NDMP_LOG(LOG_DEBUG, "n: %d", n);
1677      -
1678 1615                  /*
1679 1616                   * Discard data if the current data stream position is
1680 1617                   * prior to the seek position. This is necessary if a seek
1681 1618                   * request set the seek pointer to a position that is not a
1682 1619                   * record boundary. The seek request handler can only position
1683 1620                   * to the start of a record.
1684 1621                   */
1685 1622                  if (session->ns_mover.md_position <
1686 1623                      session->ns_mover.md_seek_position) {
1687 1624                          session->ns_mover.md_r_index =
↓ open down ↓ 58 lines elided ↑ open up ↑
1746 1683                          }
1747 1684  
1748 1685                          request.offset =
1749 1686                              long_long_to_quad(session->ns_data.dd_read_offset);
1750 1687                          request.length =
1751 1688                              long_long_to_quad(session->ns_data.dd_read_length);
1752 1689  
1753 1690                          if (ndmp_send_request_lock(session->ns_connection,
1754 1691                              NDMP_NOTIFY_DATA_READ, NDMP_NO_ERR,
1755 1692                              (void *) &request, 0) < 0) {
1756      -                                NDMP_LOG(LOG_DEBUG,
1757      -                                    "Sending notify_data_read request");
1758 1693                                  return (-1);
1759 1694                          }
1760 1695                  }
1761 1696                  if (session->ns_eof == TRUE ||
1762 1697                      session->ns_data.dd_abort == TRUE)
1763 1698                          return (1);
1764 1699  
1765 1700                  /*
1766 1701                   * If the module called ndmpd_seek() prior to reading all of the
1767 1702                   * data that the remote mover was requested to send, then the
↓ open down ↓ 6 lines elided ↑ open up ↑
1774 1709                                  return (-1);
1775 1710                          session->ns_mover.md_discard_length -= n;
1776 1711                          continue;
1777 1712                  }
1778 1713                  /*
1779 1714                   * Don't attempt to read more data than the remote is sending.
1780 1715                   */
1781 1716                  if (len > session->ns_mover.md_bytes_left_to_read)
1782 1717                          len = session->ns_mover.md_bytes_left_to_read;
1783 1718  
1784      -                NDMP_LOG(LOG_DEBUG, "len: %u", len);
1785      -
1786 1719                  if ((n = read(session->ns_data.dd_sock, &data[count],
1787 1720                      len)) < 0) {
1788      -                        NDMP_LOG(LOG_ERR, "Socket read error: %m.");
     1721 +                        syslog(LOG_ERR, "Socket read error: %m.");
1789 1722                          return (-1);
1790 1723                  }
1791 1724                  /* read returns 0 if the connection was closed */
1792 1725                  if (n == 0)
1793 1726                          return (-1);
1794 1727  
1795 1728                  count += n;
1796 1729                  session->ns_mover.md_bytes_left_to_read -= n;
1797 1730                  session->ns_mover.md_position += n;
1798 1731          }
↓ open down ↓ 65 lines elided ↑ open up ↑
1864 1797  void
1865 1798  ndmpd_mover_shut_down(ndmpd_session_t *session)
1866 1799  {
1867 1800          ndmp_lbr_params_t *nlp;
1868 1801  
1869 1802          if ((nlp = ndmp_get_nlp(session)) == NULL)
1870 1803                  return;
1871 1804  
1872 1805          (void) mutex_lock(&nlp->nlp_mtx);
1873 1806          if (session->ns_mover.md_listen_sock != -1) {
1874      -                NDMP_LOG(LOG_DEBUG, "mover.listen_sock: %d",
1875      -                    session->ns_mover.md_listen_sock);
1876 1807                  (void) ndmpd_remove_file_handler(session,
1877 1808                      session->ns_mover.md_listen_sock);
1878 1809                  (void) close(session->ns_mover.md_listen_sock);
1879 1810                  session->ns_mover.md_listen_sock = -1;
1880 1811          }
1881 1812          if (session->ns_mover.md_sock != -1) {
1882      -                NDMP_LOG(LOG_DEBUG, "mover.sock: %d",
1883      -                    session->ns_mover.md_sock);
1884 1813                  (void) ndmpd_remove_file_handler(session,
1885 1814                      session->ns_mover.md_sock);
1886 1815                  (void) close(session->ns_mover.md_sock);
1887 1816                  session->ns_mover.md_sock = -1;
1888 1817          }
1889 1818          (void) cond_broadcast(&nlp->nlp_cv);
1890 1819          (void) mutex_unlock(&nlp->nlp_mtx);
1891 1820  }
1892 1821  
1893 1822  
↓ open down ↓ 47 lines elided ↑ open up ↑
1941 1870                           * The NDMPCopy client will send a zero address to
1942 1871                           * direct the server to use the mover socket as the
1943 1872                           * data socket to receive the recovery data.
1944 1873                           */
1945 1874                          if (sin.sin_addr.s_addr == 0 && sin.sin_port == 0) {
1946 1875                                  session->ns_data.dd_sock =
1947 1876                                      session->ns_mover.md_sock;
1948 1877                                  return (NDMP_NO_ERR);
1949 1878                          }
1950 1879  
1951      -                        NDMP_LOG(LOG_DEBUG, "addr: %u port: %u",
     1880 +                        syslog(LOG_DEBUG, "addr: %u port: %u",
1952 1881                              mover->ndmp_mover_addr_u.addr.ip_addr,
1953 1882                              (ulong_t)sin.sin_port);
1954 1883  
1955 1884                          if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
1956      -                                NDMP_LOG(LOG_DEBUG, "Socket error: %m");
     1885 +                                syslog(LOG_ERR, "Socket error: %m");
1957 1886                                  return (NDMP_IO_ERR);
1958 1887                          }
1959 1888                          if (connect(sock, (struct sockaddr *)&sin,
1960 1889                              sizeof (sin)) < 0) {
1961      -                                NDMP_LOG(LOG_DEBUG, "Connect error: %m");
     1890 +                                syslog(LOG_ERR, "Connect error: %m");
1962 1891                                  (void) close(sock);
1963 1892                                  return (NDMP_IO_ERR);
1964 1893                          }
1965 1894                          set_socket_options(sock);
1966 1895                  } else {
1967 1896                          if ((session->ns_mover.md_state !=
1968 1897                              NDMP_MOVER_STATE_ACTIVE) ||
1969 1898                              (session->ns_mover.md_sock == -1)) {
1970 1899  
1971      -                                NDMP_LOG(LOG_DEBUG,
     1900 +                                syslog(LOG_DEBUG,
1972 1901                                      "Not in active  state mover"
1973      -                                    "  state = %d or Invalid mover sock=%d",
     1902 +                                    "  state = %d or Illegal mover sock=%d",
1974 1903                                      session->ns_mover.md_state,
1975 1904                                      session->ns_mover.md_sock);
1976 1905                                  return (NDMP_ILLEGAL_STATE_ERR);
1977 1906                          }
1978 1907  
1979 1908                          sock = session->ns_mover.md_sock;
1980      -                        NDMP_LOG(LOG_DEBUG,
     1909 +                        syslog(LOG_DEBUG,
1981 1910                              "session: 0x%x setting data sock fd: %d to be"
1982 1911                              " same as listen_sock", session, sock);
1983 1912                  }
1984 1913  
1985      -                NDMP_LOG(LOG_DEBUG, "sock fd: %d", sock);
1986      -
1987 1914                  session->ns_data.dd_sock = sock;
1988 1915  
1989      -                NDMP_LOG(LOG_DEBUG, "data.mover_sock: %u", sock);
1990      -
1991 1916                  return (NDMP_NO_ERR);
1992 1917          }
1993 1918          /* Local mover connection. */
1994 1919  
1995 1920          if (session->ns_mover.md_state != NDMP_MOVER_STATE_LISTEN) {
1996      -                NDMP_LOG(LOG_DEBUG, "Mover is not in listen state");
1997 1921                  return (NDMP_ILLEGAL_STATE_ERR);
1998 1922          }
1999 1923          if (session->ns_tape.td_fd == -1) {
2000      -                NDMP_LOG(LOG_DEBUG, "Tape device not open");
     1924 +                syslog(LOG_ERR, "Tape device not open");
2001 1925                  return (NDMP_DEV_NOT_OPEN_ERR);
2002 1926          }
2003 1927          if (mover_mode == NDMP_MOVER_MODE_READ &&
2004 1928              session->ns_tape.td_mode == NDMP_TAPE_READ_MODE) {
2005      -                NDMP_LOG(LOG_ERR, "Write protected device.");
     1929 +                syslog(LOG_ERR, "Write protected device.");
2006 1930                  return (NDMP_WRITE_PROTECT_ERR);
2007 1931          }
2008 1932          session->ns_mover.md_state = NDMP_MOVER_STATE_ACTIVE;
2009 1933          session->ns_mover.md_mode = mover_mode;
2010 1934  
2011 1935          return (NDMP_NO_ERR);
2012 1936  }
2013 1937  
2014 1938  
2015 1939  
↓ open down ↓ 35 lines elided ↑ open up ↑
2051 1975  
2052 1976          /*
2053 1977           * If the requested position is outside of the window,
2054 1978           * notify the client that a seek is required.
2055 1979           */
2056 1980          if (session->ns_mover.md_seek_position <
2057 1981              session->ns_mover.md_window_offset ||
2058 1982              session->ns_mover.md_seek_position >=
2059 1983              session->ns_mover.md_window_offset +
2060 1984              session->ns_mover.md_window_length) {
2061      -                NDMP_LOG(LOG_DEBUG, "MOVER_PAUSE_SEEK(%llu)",
2062      -                    session->ns_mover.md_seek_position);
2063 1985  
2064 1986                  session->ns_mover.md_w_index = 0;
2065 1987                  session->ns_mover.md_r_index = 0;
2066 1988  
2067 1989                  session->ns_mover.md_state = NDMP_MOVER_STATE_PAUSED;
2068 1990                  session->ns_mover.md_pause_reason = NDMP_MOVER_PAUSE_SEEK;
2069 1991                  pause_request.reason = NDMP_MOVER_PAUSE_SEEK;
2070 1992                  pause_request.seek_position = long_long_to_quad(offset);
2071 1993  
2072 1994                  if (ndmp_send_request(session->ns_connection,
2073 1995                      NDMP_NOTIFY_MOVER_PAUSED, NDMP_NO_ERR,
2074 1996                      (void *) &pause_request, 0) < 0) {
2075      -                        NDMP_LOG(LOG_DEBUG,
2076      -                            "Sending notify_mover_paused request");
2077 1997                          return (-1);
2078 1998                  }
2079 1999                  return (1);
2080 2000          }
2081 2001          /*
2082 2002           * Determine the data stream position of the first byte in the
2083 2003           * data buffer.
2084 2004           */
2085 2005          buf_position = session->ns_mover.md_position -
2086 2006              (session->ns_mover.md_position % session->ns_mover.md_record_size);
↓ open down ↓ 7 lines elided ↑ open up ↑
2094 2014                  tape_position += session->ns_mover.md_record_size;
2095 2015  
2096 2016          /*
2097 2017           * Check if requested position is for data that has been read and is
2098 2018           * in the buffer.
2099 2019           */
2100 2020          if (offset >= buf_position && offset < tape_position) {
2101 2021                  session->ns_mover.md_position = offset;
2102 2022                  session->ns_mover.md_r_index = session->ns_mover.md_position -
2103 2023                      buf_position;
2104      -
2105      -                NDMP_LOG(LOG_DEBUG, "pos %llu r_index %u",
2106      -                    session->ns_mover.md_position,
2107      -                    session->ns_mover.md_r_index);
2108      -
2109 2024                  return (0);
2110 2025          }
2111 2026  
2112 2027          ctlcmd = 0;
2113 2028          if (tape_position > session->ns_mover.md_seek_position) {
2114 2029                  /* Need to seek backward. */
2115 2030                  ctlcmd = MTBSR;
2116 2031                  ctlcnt = (int)((tape_position - offset - 1)
2117 2032                      / session->ns_mover.md_record_size) + 1;
2118 2033                  tape_position -= ((u_longlong_t)(((tape_position - offset - 1) /
↓ open down ↓ 4 lines elided ↑ open up ↑
2123 2038                  /* Need to seek forward. */
2124 2039                  ctlcmd = MTFSR;
2125 2040                  ctlcnt = (int)((offset - tape_position)
2126 2041                      / session->ns_mover.md_record_size);
2127 2042                  tape_position += ((u_longlong_t)(((offset - tape_position) /
2128 2043                      session->ns_mover.md_record_size)) *
2129 2044                      (u_longlong_t)session->ns_mover.md_record_size);
2130 2045          }
2131 2046          /* Reposition the tape if necessary. */
2132 2047          if (ctlcmd) {
2133      -                NDMP_LOG(LOG_DEBUG, "cmd %d count %d",
2134      -                    ctlcmd, ctlcnt);
2135 2048                  (void) ndmp_mtioctl(session->ns_tape.td_fd, ctlcmd, ctlcnt);
2136 2049          }
2137 2050  
2138 2051          session->ns_mover.md_position = tape_position;
2139 2052          session->ns_mover.md_r_index = 0;
2140 2053          session->ns_mover.md_w_index = 0;
2141 2054  
2142      -        NDMP_LOG(LOG_DEBUG, "pos %llu", session->ns_mover.md_position);
2143      -
2144 2055          return (0);
2145 2056  }
2146 2057  
2147 2058  
2148 2059  /* ** static functions ************************************************** */
2149 2060  
2150 2061  /*
2151 2062   * create_listen_socket_v2
2152 2063   *
2153 2064   * Creates a socket for listening for accepting data connections.
↓ open down ↓ 20 lines elided ↑ open up ↑
2174 2085           * connection is ready to be accepted.
2175 2086           */
2176 2087          if (ndmpd_add_file_handler(session, (void *) session,
2177 2088              session->ns_mover.md_listen_sock, NDMPD_SELECT_MODE_READ, HC_MOVER,
2178 2089              accept_connection) < 0) {
2179 2090                  (void) close(session->ns_mover.md_listen_sock);
2180 2091                  session->ns_mover.md_listen_sock = -1;
2181 2092                  return (-1);
2182 2093          }
2183 2094  
2184      -        NDMP_LOG(LOG_DEBUG, "addr: 0x%x, port: %d", *addr, *port);
2185 2095          return (0);
2186 2096  }
2187 2097  
2188 2098  /*
2189 2099   * accept_connection
2190 2100   *
2191 2101   * Accept a data connection from a data server.
2192 2102   * Called by ndmpd_select when a connection is pending on
2193 2103   * the mover listen socket.
2194 2104   *
↓ open down ↓ 15 lines elided ↑ open up ↑
2210 2120  
2211 2121          from_len = sizeof (from);
2212 2122          session->ns_mover.md_sock = accept(fd, (struct sockaddr *)&from,
2213 2123              &from_len);
2214 2124  
2215 2125          (void) ndmpd_remove_file_handler(session, fd);
2216 2126          (void) close(session->ns_mover.md_listen_sock);
2217 2127          session->ns_mover.md_listen_sock = -1;
2218 2128  
2219 2129          if (session->ns_mover.md_sock < 0) {
2220      -                NDMP_LOG(LOG_DEBUG, "Accept error: %m");
     2130 +                syslog(LOG_ERR, "Accept error: %m");
2221 2131                  ndmpd_mover_error(session, NDMP_MOVER_HALT_CONNECT_ERROR);
2222 2132                  return;
2223 2133          }
2224 2134          set_socket_options(session->ns_mover.md_sock);
2225 2135  
2226      -        NDMP_LOG(LOG_DEBUG, "sock fd: %d", session->ns_mover.md_sock);
2227      -
2228 2136          if (session->ns_mover.md_mode == NDMP_MOVER_MODE_READ) {
2229 2137                  if (start_mover_for_backup(session) < 0) {
2230 2138                          ndmpd_mover_error(session,
2231 2139                              NDMP_MOVER_HALT_INTERNAL_ERROR);
2232 2140                          return;
2233 2141                  }
2234      -                NDMP_LOG(LOG_DEBUG, "Backup connection established by %s:%d",
     2142 +                syslog(LOG_DEBUG, "Backup connection established by %s:%d",
2235 2143                      inet_ntoa(IN_ADDR(from.sin_addr.s_addr)),
2236 2144                      ntohs(from.sin_port));
2237 2145          } else {
2238      -                NDMP_LOG(LOG_DEBUG, "Restore connection established by %s:%d",
     2146 +                syslog(LOG_DEBUG, "Restore connection established by %s:%d",
2239 2147                      inet_ntoa(IN_ADDR(from.sin_addr.s_addr)),
2240 2148                      ntohs(from.sin_port));
2241 2149          }
2242 2150  
2243      -        NDMP_LOG(LOG_DEBUG, "Received connection");
2244      -
2245 2151          session->ns_mover.md_state = NDMP_MOVER_STATE_ACTIVE;
2246 2152  }
2247 2153  
2248 2154  /*
2249 2155   * tape_read
2250 2156   *
2251 2157   * Reads a data record from tape. Detects and handles EOT conditions.
2252 2158   *
2253 2159   * Parameters:
2254 2160   *   session (input) - session pointer.
↓ open down ↓ 7 lines elided ↑ open up ↑
2262 2168  static int
2263 2169  tape_read(ndmpd_session_t *session, char *data)
2264 2170  {
2265 2171          ssize_t n;
2266 2172          int err;
2267 2173          int count = session->ns_mover.md_record_size;
2268 2174  
2269 2175          for (; ; ) {
2270 2176                  n = read(session->ns_tape.td_fd, data, count);
2271 2177                  if (n < 0) {
2272      -                        NDMP_LOG(LOG_ERR, "Tape read error: %m.");
     2178 +                        syslog(LOG_ERR, "Tape read error: %m.");
2273 2179                          return (TAPE_READ_ERR);
2274 2180                  }
2275 2181                  NS_ADD(rtape, n);
2276 2182  
2277 2183                  if (n == 0) {
2278 2184                          if (!is_writer_running(session))
2279 2185                                  return (TAPE_NO_WRITER_ERR);
2280 2186  
2281 2187                          /*
2282 2188                           * End of media reached.
2283 2189                           * Notify client and wait for the client to
2284 2190                           * either abort the data operation or continue the
2285 2191                           * operation after changing the tape.
2286 2192                           */
2287 2193                          NDMP_APILOG((void*)session, NDMP_LOG_NORMAL,
2288 2194                              ++ndmp_log_msg_id,
2289 2195                              "End of tape reached. Load next tape");
2290 2196  
2291      -                        NDMP_LOG(LOG_DEBUG,
     2197 +                        syslog(LOG_DEBUG,
2292 2198                              "End of tape reached. Load next tape");
2293 2199  
2294 2200                          err = change_tape(session);
2295 2201  
2296 2202                          /* Operation aborted or connection terminated? */
2297 2203                          if (err < 0) {
2298 2204                                  /*
2299 2205                                   * K.L. Go back one record if it is read
2300 2206                                   * but not used.
2301 2207                                   */
↓ open down ↓ 44 lines elided ↑ open up ↑
2346 2252          session->ns_mover.md_state = NDMP_MOVER_STATE_PAUSED;
2347 2253  
2348 2254          if (session->ns_mover.md_mode == NDMP_MOVER_MODE_READ)
2349 2255                  session->ns_mover.md_pause_reason = NDMP_MOVER_PAUSE_EOM;
2350 2256          else
2351 2257                  session->ns_mover.md_pause_reason = NDMP_MOVER_PAUSE_EOF;
2352 2258  
2353 2259          request.reason = session->ns_mover.md_pause_reason;
2354 2260          request.seek_position = long_long_to_quad(0LL);
2355 2261  
2356      -        NDMP_LOG(LOG_DEBUG, "ndmp_send_request: MOVER_PAUSED, reason: %d",
     2262 +        syslog(LOG_DEBUG, "ndmp_send_request: MOVER_PAUSED, reason: %d",
2357 2263              session->ns_mover.md_pause_reason);
2358 2264  
2359 2265          if (ndmp_send_request(session->ns_connection,
2360 2266              NDMP_NOTIFY_MOVER_PAUSED, NDMP_NO_ERR,
2361 2267              (void *) &request, 0) < 0) {
2362      -                NDMP_LOG(LOG_DEBUG,
2363      -                    "Sending notify_mover_paused request");
2364 2268                  return (-1);
2365 2269          }
2366 2270          /*
2367 2271           * Wait for until the state is changed by
2368 2272           * an abort or continue request.
2369 2273           */
2370 2274          return (ndmp_wait_for_mover(session));
2371 2275  }
2372 2276  
2373 2277  
↓ open down ↓ 16 lines elided ↑ open up ↑
2390 2294  {
2391 2295          int n;
2392 2296          char *addr;
2393 2297  
2394 2298          if ((addr = ndmp_malloc(length)) == NULL)
2395 2299                  return (-1);
2396 2300  
2397 2301          /* Read and discard the data. */
2398 2302          n = read(session->ns_mover.md_sock, addr, length);
2399 2303          if (n < 0) {
2400      -                NDMP_LOG(LOG_ERR, "Socket read error: %m.");
     2304 +                syslog(LOG_ERR, "Socket read error: %m.");
2401 2305                  free(addr);
2402 2306                  return (-1);
2403 2307          }
2404 2308  
2405 2309          free(addr);
2406 2310          return (n);
2407 2311  }
2408 2312  
2409 2313  
2410 2314  /*
↓ open down ↓ 22 lines elided ↑ open up ↑
2433 2337           * Remove the file handler to prevent this function from
2434 2338           * being called. The handler will be reinstalled in
2435 2339           * ndmpd_mover_continue.
2436 2340           */
2437 2341  
2438 2342          if (session->ns_mover.md_position >=
2439 2343              session->ns_mover.md_window_offset +
2440 2344              session->ns_mover.md_window_length) {
2441 2345                  ndmp_notify_mover_paused_request pause_request;
2442 2346  
2443      -                NDMP_LOG(LOG_DEBUG, "end of mover window");
2444      -
2445 2347                  session->ns_mover.md_state = NDMP_MOVER_STATE_PAUSED;
2446 2348                  session->ns_mover.md_pause_reason = NDMP_MOVER_PAUSE_SEEK;
2447 2349                  pause_request.reason = NDMP_MOVER_PAUSE_SEEK;
2448 2350                  pause_request.seek_position =
2449 2351                      long_long_to_quad(session->ns_mover.md_position);
2450 2352  
2451 2353                  if (ndmp_send_request(session->ns_connection,
2452 2354                      NDMP_NOTIFY_MOVER_PAUSED, NDMP_NO_ERR,
2453 2355                      (void *) &pause_request, 0) < 0) {
2454      -                        NDMP_LOG(LOG_DEBUG,
2455      -                            "Sending notify_mover_paused request");
2456 2356                          ndmpd_mover_error(session,
2457 2357                              NDMP_MOVER_HALT_INTERNAL_ERROR);
2458 2358                  }
2459 2359                  buf->tb_errno = EIO;
2460 2360                  return (TAPE_READ_ERR);
2461 2361          }
2462 2362  
2463 2363          n = tape_read(session, buf->tb_buffer_data);
2464 2364  
2465      -        NDMP_LOG(LOG_DEBUG, "read %d bytes from tape", n);
2466      -
2467 2365          if (n <= 0) {
2468 2366                  if (n < 0)
2469 2367                          ndmpd_mover_error(session,
2470 2368                              (n == 0 ? NDMP_MOVER_HALT_ABORTED :
2471 2369                              NDMP_MOVER_HALT_INTERNAL_ERROR));
2472 2370                  return (TAPE_READ_ERR);
2473 2371          }
2474 2372  
2475 2373          buf->tb_full = TRUE;
2476 2374          buf->tb_buffer_size = session->ns_mover.md_record_size;
↓ open down ↓ 31 lines elided ↑ open up ↑
2508 2406  {
2509 2407          int bidx;       /* buffer index */
2510 2408          int rv;
2511 2409          ndmp_lbr_params_t *nlp;
2512 2410          tlm_buffer_t *buf;
2513 2411          tlm_buffers_t *bufs;
2514 2412          tlm_cmd_t *lcmd;        /* Local command */
2515 2413          tlm_commands_t *cmds;   /* Commands structure */
2516 2414  
2517 2415          if ((nlp = ndmp_get_nlp(session)) == NULL) {
2518      -                NDMP_LOG(LOG_DEBUG, "nlp == NULL");
2519 2416                  return (-1);
2520 2417          }
2521 2418  
2522 2419          cmds = &nlp->nlp_cmds;
2523 2420          lcmd = cmds->tcs_command;
2524 2421          bufs = lcmd->tc_buffers;
2525 2422  
2526 2423          lcmd->tc_ref++;
2527 2424          cmds->tcs_reader_count++;
2528 2425  
↓ open down ↓ 1 lines elided ↑ open up ↑
2530 2427           * Let our parent thread know that we are running.
2531 2428           */
2532 2429          tlm_cmd_signal(cmds->tcs_command, TLM_TAPE_READER);
2533 2430  
2534 2431          buf = tlm_buffer_in_buf(bufs, &bidx);
2535 2432          while (cmds->tcs_reader == TLM_RESTORE_RUN &&
2536 2433              lcmd->tc_reader == TLM_RESTORE_RUN) {
2537 2434                  buf = tlm_buffer_in_buf(bufs, NULL);
2538 2435  
2539 2436                  if (buf->tb_full) {
2540      -                        NDMP_LOG(LOG_DEBUG, "R%d", bidx);
     2437 +                        syslog(LOG_DEBUG, "R%d", bidx);
2541 2438                          /*
2542 2439                           * The buffer is still full, wait for the consumer
2543 2440                           * thread to use it.
2544 2441                           */
2545 2442                          tlm_buffer_out_buf_timed_wait(bufs, 100);
2546 2443  
2547 2444                  } else {
2548      -                        NDMP_LOG(LOG_DEBUG, "r%d", bidx);
     2445 +                        syslog(LOG_DEBUG, "r%d", bidx);
2549 2446  
2550 2447                          rv = mover_tape_read_one_buf(session, buf);
2551 2448                          /*
2552 2449                           * If there was an error while reading, such as
2553 2450                           * end of stream.
2554 2451                           */
2555 2452                          if (rv < 0) {
2556      -                                NDMP_LOG(LOG_DEBUG, "Exiting, rv: %d", rv);
     2453 +                                syslog(LOG_DEBUG, "Exiting, rv: %d", rv);
2557 2454                                  break;
2558 2455                          }
2559 2456  
2560 2457                          /*
2561 2458                           * Can we do more buffering?
2562 2459                           */
2563 2460                          if (is_buffer_erroneous(buf)) {
2564      -                                NDMP_LOG(LOG_DEBUG,
     2461 +                                syslog(LOG_DEBUG,
2565 2462                                      "Exiting, errno: %d, eot: %d, eof: %d",
2566 2463                                      buf->tb_errno, buf->tb_eot, buf->tb_eof);
2567 2464                                  break;
2568 2465                          }
2569 2466  
2570 2467                          (void) tlm_buffer_advance_in_idx(bufs);
2571 2468                          tlm_buffer_release_in_buf(bufs);
2572 2469                          bidx = bufs->tbs_buffer_in;
2573 2470                  }
2574 2471          }
↓ open down ↓ 27 lines elided ↑ open up ↑
2602 2499  static int
2603 2500  mover_socket_write_one_buf(ndmpd_session_t *session, tlm_buffer_t *buf)
2604 2501  {
2605 2502          int n;
2606 2503  
2607 2504          /* Write the data to the data connection. */
2608 2505          errno = 0;
2609 2506          n = write(session->ns_mover.md_sock, buf->tb_buffer_data,
2610 2507              buf->tb_buffer_size);
2611 2508  
2612      -        NDMP_LOG(LOG_DEBUG, "n: %d, len: %d", n, buf->tb_buffer_size);
2613      -
2614 2509          if (n < 0) {
2615      -                NDMP_LOG(LOG_DEBUG, "n: %d, errno: %m", n);
2616 2510                  ndmpd_mover_error(session, NDMP_MOVER_HALT_CONNECT_CLOSED);
2617 2511                  return (-1);
2618 2512          }
2619 2513  
2620 2514          session->ns_mover.md_position += n;
2621 2515          session->ns_mover.md_bytes_left_to_read -= n;
2622 2516          tlm_buffer_mark_empty(buf);
2623 2517  
2624 2518          /*
2625 2519           * If the read limit has been reached,
2626 2520           * then remove the file handler to prevent this
2627 2521           * function from getting called. The next mover_read request
2628 2522           * will reinstall the handler.
2629 2523           */
2630 2524          if (session->ns_mover.md_bytes_left_to_read == 0) {
2631      -                NDMP_LOG(LOG_DEBUG, "bytes_left_to_read == 0");
2632 2525                  (void) ndmpd_remove_file_handler(session,
2633 2526                      session->ns_mover.md_sock);
2634 2527                  return (-1);
2635 2528          }
2636 2529  
2637 2530          return (0);
2638 2531  }
2639 2532  
2640 2533  
2641 2534  
↓ open down ↓ 14 lines elided ↑ open up ↑
2656 2549  mover_socket_writer(ndmpd_session_t *session)
2657 2550  {
2658 2551          int bidx;       /* buffer index */
2659 2552          ndmp_lbr_params_t *nlp;
2660 2553          tlm_buffer_t *buf;
2661 2554          tlm_buffers_t *bufs;
2662 2555          tlm_cmd_t *lcmd;        /* Local command */
2663 2556          tlm_commands_t *cmds;   /* Commands structure */
2664 2557  
2665 2558          if ((nlp = ndmp_get_nlp(session)) == NULL) {
2666      -                NDMP_LOG(LOG_DEBUG, "nlp == NULL");
2667 2559                  return (-1);
2668 2560          }
2669 2561  
2670 2562          cmds = &nlp->nlp_cmds;
2671 2563          lcmd = cmds->tcs_command;
2672 2564          bufs = lcmd->tc_buffers;
2673 2565  
2674 2566          lcmd->tc_ref++;
2675 2567          cmds->tcs_writer_count++;
2676 2568  
↓ open down ↓ 1 lines elided ↑ open up ↑
2678 2570           * Let our parent thread know that we are running.
2679 2571           */
2680 2572          tlm_cmd_signal(cmds->tcs_command, TLM_SOCK_WRITER);
2681 2573  
2682 2574          bidx = bufs->tbs_buffer_out;
2683 2575          while (cmds->tcs_writer != (int)TLM_ABORT &&
2684 2576              lcmd->tc_writer != (int)TLM_ABORT) {
2685 2577                  buf = &bufs->tbs_buffer[bidx];
2686 2578  
2687 2579                  if (buf->tb_full) {
2688      -                        NDMP_LOG(LOG_DEBUG, "w%d", bidx);
     2580 +                        syslog(LOG_DEBUG, "w%d", bidx);
2689 2581  
2690 2582                          if (mover_socket_write_one_buf(session, buf) < 0) {
2691      -                                NDMP_LOG(LOG_DEBUG,
2692      -                                    "mover_socket_write_one_buf() < 0");
2693 2583                                  break;
2694 2584                          }
2695 2585  
2696 2586                          (void) tlm_buffer_advance_out_idx(bufs);
2697 2587                          tlm_buffer_release_out_buf(bufs);
2698 2588                          bidx = bufs->tbs_buffer_out;
2699 2589                  } else {
2700 2590                          if (lcmd->tc_writer != TLM_RESTORE_RUN) {
2701 2591                                  /* No more data is coming, time to exit */
2702      -                                NDMP_LOG(LOG_DEBUG, "Time to exit");
2703 2592                                  break;
2704 2593                          }
2705      -                        NDMP_LOG(LOG_DEBUG, "W%d", bidx);
     2594 +                        syslog(LOG_DEBUG, "W%d", bidx);
2706 2595                          /*
2707 2596                           * The buffer is not full, wait for the producer
2708 2597                           * thread to fill it.
2709 2598                           */
2710 2599                          tlm_buffer_in_buf_timed_wait(bufs, 100);
2711 2600                  }
2712 2601          }
2713 2602  
2714 2603          if (cmds->tcs_writer == (int)TLM_ABORT)
2715      -                NDMP_LOG(LOG_DEBUG, "cmds->tcs_writer == (int)TLM_ABORT");
     2604 +                syslog(LOG_DEBUG, "cmds->tcs_writer == (int)TLM_ABORT");
2716 2605          if (lcmd->tc_writer == (int)TLM_ABORT)
2717      -                NDMP_LOG(LOG_DEBUG, "lcmd->tc_writer == TLM_ABORT");
     2606 +                syslog(LOG_DEBUG, "lcmd->tc_writer == TLM_ABORT");
2718 2607  
2719 2608          /* If the producer is waiting for us, wake it up. */
2720 2609          tlm_buffer_release_out_buf(bufs);
2721 2610  
2722 2611          /*
2723 2612           * Clean up.
2724 2613           */
2725 2614          cmds->tcs_writer_count--;
2726 2615          lcmd->tc_ref--;
2727 2616          lcmd->tc_reader = TLM_STOP;
↓ open down ↓ 16 lines elided ↑ open up ↑
2744 2633   */
2745 2634  static int
2746 2635  start_mover_for_restore(ndmpd_session_t *session)
2747 2636  {
2748 2637          ndmp_lbr_params_t *nlp;
2749 2638          tlm_commands_t *cmds;
2750 2639          long xfer_size;
2751 2640          int rc;
2752 2641  
2753 2642          if ((nlp = ndmp_get_nlp(session)) == NULL) {
2754      -                NDMP_LOG(LOG_DEBUG, "nlp == NULL");
2755 2643                  return (-1);
2756 2644          }
2757 2645  
2758 2646          cmds = &nlp->nlp_cmds;
2759 2647          (void) memset(cmds, 0, sizeof (*cmds));
2760 2648          cmds->tcs_reader = cmds->tcs_writer = TLM_RESTORE_RUN;
2761 2649          xfer_size = ndmp_buffer_get_size(session);
2762 2650          cmds->tcs_command = tlm_create_reader_writer_ipc(FALSE, xfer_size);
2763 2651          if (cmds->tcs_command == NULL)
2764 2652                  return (-1);
↓ open down ↓ 4 lines elided ↑ open up ↑
2769 2657          /*
2770 2658           * We intentionnally don't wait for the threads to start since the
2771 2659           * reply of the request (which resulted in calling this function)
2772 2660           * must be sent to the client before probable errors are sent
2773 2661           * to the client.
2774 2662           */
2775 2663          rc = pthread_create(NULL, NULL, (funct_t)mover_tape_reader, session);
2776 2664          if (rc == 0) {
2777 2665                  tlm_cmd_wait(cmds->tcs_command, TLM_TAPE_READER);
2778 2666          } else {
2779      -                NDMP_LOG(LOG_DEBUG, "Launch mover_tape_reader: %s",
2780      -                    strerror(rc));
2781 2667                  return (-1);
2782 2668          }
2783 2669  
2784 2670          rc = pthread_create(NULL, NULL, (funct_t)mover_socket_writer, session);
2785 2671          if (rc == 0) {
2786 2672                  tlm_cmd_wait(cmds->tcs_command, TLM_SOCK_WRITER);
2787 2673          } else {
2788      -                NDMP_LOG(LOG_DEBUG, "Launch mover_socket_writer: %s",
2789      -                    strerror(rc));
2790 2674                  return (-1);
2791 2675          }
2792 2676  
2793 2677          tlm_release_reader_writer_ipc(cmds->tcs_command);
2794 2678          return (0);
2795 2679  }
2796 2680  
2797 2681  
2798 2682  /*
2799 2683   * mover_socket_read_one_buf
↓ open down ↓ 13 lines elided ↑ open up ↑
2813 2697  static int
2814 2698  mover_socket_read_one_buf(ndmpd_session_t *session, tlm_buffer_t *buf,
2815 2699      long read_size)
2816 2700  {
2817 2701          int n, index;
2818 2702          long toread;
2819 2703  
2820 2704          tlm_buffer_mark_empty(buf);
2821 2705          for (index = 0, toread = read_size; toread > 0; ) {
2822 2706                  errno = 0;
2823      -                NDMP_LOG(LOG_DEBUG, "index: %d, toread: %d", index, toread);
2824      -
2825 2707                  n = read(session->ns_mover.md_sock, &buf->tb_buffer_data[index],
2826 2708                      toread);
2827 2709                  if (n == 0) {
2828      -                        NDMP_LOG(LOG_DEBUG, "n: %d", n);
2829 2710                          break;
2830 2711                  } else if (n > 0) {
2831      -                        NDMP_LOG(LOG_DEBUG, "n: %d", n);
2832 2712                          index += n;
2833 2713                          toread -= n;
2834 2714                  } else {
2835 2715                          buf->tb_eof = TRUE;
2836 2716                          buf->tb_errno = errno;
2837 2717                          buf->tb_buffer_size = 0;
2838      -                        NDMP_LOG(LOG_DEBUG, "n: %d, errno: %m", n);
2839 2718                          return (-1);
2840 2719                  }
2841 2720          }
2842 2721  
2843 2722          if (index > 0) {
2844 2723                  buf->tb_full = TRUE;
2845 2724                  buf->tb_buffer_size = read_size;
2846 2725                  if (read_size > 0)
2847 2726                          (void) memset(&buf->tb_buffer_data[index], 0,
2848 2727                              read_size - index);
2849 2728          } else {
2850 2729                  buf->tb_eof = TRUE;
2851 2730                  buf->tb_buffer_size = 0;
2852 2731          }
2853 2732  
2854      -        NDMP_LOG(LOG_DEBUG, "full: %d, eot: %d, eof: %d,"
     2733 +        syslog(LOG_DEBUG, "full: %d, eot: %d, eof: %d,"
2855 2734              " errno: %d, size: %d, data: 0x%x",
2856 2735              buf->tb_full, buf->tb_eot, buf->tb_eof, buf->tb_errno,
2857 2736              buf->tb_buffer_size, buf->tb_buffer_data);
2858 2737  
2859 2738          return (0);
2860 2739  }
2861 2740  
2862 2741  
2863 2742  
2864 2743  /*
↓ open down ↓ 14 lines elided ↑ open up ↑
2879 2758  {
2880 2759          int bidx;       /* buffer index */
2881 2760          ndmp_lbr_params_t *nlp;
2882 2761          tlm_buffer_t *buf;
2883 2762          tlm_buffers_t *bufs;
2884 2763          tlm_cmd_t *lcmd;        /* Local command */
2885 2764          tlm_commands_t *cmds;   /* Commands structure */
2886 2765          static int nr = 0;
2887 2766  
2888 2767          if ((nlp = ndmp_get_nlp(session)) == NULL) {
2889      -                NDMP_LOG(LOG_DEBUG, "nlp == NULL");
2890 2768                  return (-1);
2891 2769          }
2892 2770  
2893 2771          cmds = &nlp->nlp_cmds;
2894 2772          lcmd = cmds->tcs_command;
2895 2773          bufs = lcmd->tc_buffers;
2896 2774  
2897 2775          lcmd->tc_ref++;
2898 2776          cmds->tcs_reader_count++;
2899 2777  
↓ open down ↓ 1 lines elided ↑ open up ↑
2901 2779           * Let our parent thread know that we are running.
2902 2780           */
2903 2781          tlm_cmd_signal(cmds->tcs_command, TLM_SOCK_READER);
2904 2782  
2905 2783          bidx = bufs->tbs_buffer_in;
2906 2784          while (cmds->tcs_reader == TLM_BACKUP_RUN &&
2907 2785              lcmd->tc_reader == TLM_BACKUP_RUN) {
2908 2786                  buf = &bufs->tbs_buffer[bidx];
2909 2787  
2910 2788                  if (buf->tb_full) {
2911      -                        NDMP_LOG(LOG_DEBUG, "R%d", bidx);
     2789 +                        syslog(LOG_DEBUG, "R%d", bidx);
2912 2790                          /*
2913 2791                           * The buffer is still full, wait for the consumer
2914 2792                           * thread to use it.
2915 2793                           */
2916 2794                          tlm_buffer_out_buf_timed_wait(bufs, 100);
2917 2795                  } else {
2918      -                        NDMP_LOG(LOG_DEBUG, "r%d, nr: %d", bidx, ++nr);
     2796 +                        syslog(LOG_DEBUG, "r%d, nr: %d", bidx, ++nr);
2919 2797  
2920 2798                          (void) mover_socket_read_one_buf(session, buf,
2921 2799                              bufs->tbs_data_transfer_size);
2922 2800  
2923 2801                          /*
2924 2802                           * Can we do more buffering?
2925 2803                           */
2926 2804                          if (is_buffer_erroneous(buf)) {
2927      -                                NDMP_LOG(LOG_DEBUG,
     2805 +                                syslog(LOG_DEBUG,
2928 2806                                      "Exiting, errno: %d, eot: %d, eof: %d",
2929 2807                                      buf->tb_errno, buf->tb_eot, buf->tb_eof);
2930 2808                                  break;
2931 2809                          }
2932 2810  
2933 2811                          (void) tlm_buffer_advance_in_idx(bufs);
2934 2812                          tlm_buffer_release_in_buf(bufs);
2935 2813                          bidx = bufs->tbs_buffer_in;
2936 2814                  }
2937 2815          }
2938 2816  
2939 2817          if (cmds->tcs_reader != TLM_BACKUP_RUN)
2940      -                NDMP_LOG(LOG_DEBUG, "cmds->tcs_reader != TLM_BACKUP_RUN");
     2818 +                syslog(LOG_DEBUG, "cmds->tcs_reader != TLM_BACKUP_RUN");
2941 2819          if (lcmd->tc_reader != TLM_BACKUP_RUN)
2942      -                NDMP_LOG(LOG_DEBUG, "lcmd->tc_reader != TLM_BACKUP_RUN");
2943      -        NDMP_LOG(LOG_DEBUG, "nr: %d", nr);
     2820 +                syslog(LOG_DEBUG, "lcmd->tc_reader != TLM_BACKUP_RUN");
     2821 +        syslog(LOG_DEBUG, "nr: %d", nr);
2944 2822  
2945 2823          /* If the consumer is waiting for us, wake it up. */
2946 2824          tlm_buffer_release_in_buf(bufs);
2947 2825  
2948 2826          /*
2949 2827           * Clean up.
2950 2828           */
2951 2829          cmds->tcs_reader_count--;
2952 2830          lcmd->tc_ref--;
2953 2831          lcmd->tc_writer = TLM_STOP;
↓ open down ↓ 13 lines elided ↑ open up ↑
2967 2845   *
2968 2846   * Returns:
2969 2847   *   0: on success
2970 2848   *  -1: otherwise
2971 2849   */
2972 2850  static int
2973 2851  mover_tape_write_one_buf(ndmpd_session_t *session, tlm_buffer_t *buf)
2974 2852  {
2975 2853          int n;
2976 2854  
2977      -        NDMP_LOG(LOG_DEBUG, "full: %d, eot: %d, eof: %d,"
     2855 +        syslog(LOG_DEBUG, "full: %d, eot: %d, eof: %d,"
2978 2856              " errno: %d, size: %d, data: 0x%x",
2979 2857              buf->tb_full, buf->tb_eot, buf->tb_eof, buf->tb_errno,
2980 2858              buf->tb_buffer_size, buf->tb_buffer_data);
2981 2859  
2982 2860          n = mover_tape_write_v3(session, buf->tb_buffer_data,
2983 2861              buf->tb_buffer_size);
2984 2862  
2985      -        NDMP_LOG(LOG_DEBUG, "n: %d", n);
2986      -
2987 2863          if (n <= 0) {
2988 2864                  ndmpd_mover_error(session, (n == 0 ? NDMP_MOVER_HALT_ABORTED
2989 2865                      : NDMP_MOVER_HALT_INTERNAL_ERROR));
2990 2866                  return (-1);
2991 2867          }
2992 2868          session->ns_mover.md_position += n;
2993 2869          session->ns_mover.md_data_written += n;
2994 2870          session->ns_mover.md_record_num++;
2995 2871  
2996      -        NDMP_LOG(LOG_DEBUG, "Calling tlm_buffer_mark_empty(buf)");
2997 2872          tlm_buffer_mark_empty(buf);
2998 2873  
2999 2874          return (0);
3000 2875  }
3001 2876  
3002 2877  
3003 2878  /*
3004 2879   * mover_tape_writer
3005 2880   *
3006 2881   * Mover tape writer thread. This is used for performing remote backups
↓ open down ↓ 12 lines elided ↑ open up ↑
3019 2894  {
3020 2895          int bidx;
3021 2896          ndmp_lbr_params_t *nlp;
3022 2897          tlm_buffer_t *buf;
3023 2898          tlm_buffers_t *bufs;
3024 2899          tlm_cmd_t *lcmd;
3025 2900          tlm_commands_t *cmds;
3026 2901          static int nw = 0;
3027 2902  
3028 2903          if ((nlp = ndmp_get_nlp(session)) == NULL) {
3029      -                NDMP_LOG(LOG_DEBUG, "nlp == NULL");
3030 2904                  return (-1);
3031 2905          }
3032 2906  
3033 2907          cmds = &nlp->nlp_cmds;
3034 2908          lcmd = cmds->tcs_command;
3035 2909          bufs = lcmd->tc_buffers;
3036 2910  
3037 2911          lcmd->tc_ref++;
3038 2912          cmds->tcs_writer_count++;
3039 2913  
3040 2914          /*
3041 2915           * Let our parent thread know that we are running.
3042 2916           */
3043 2917          tlm_cmd_signal(cmds->tcs_command, TLM_TAPE_WRITER);
3044 2918  
3045 2919          bidx = bufs->tbs_buffer_out;
3046 2920          buf = &bufs->tbs_buffer[bidx];
3047 2921          while (cmds->tcs_writer != (int)TLM_ABORT &&
3048 2922              lcmd->tc_writer != (int)TLM_ABORT) {
3049 2923                  if (buf->tb_full) {
3050      -                        NDMP_LOG(LOG_DEBUG, "w%d, nw: %d", bidx, ++nw);
     2924 +                        syslog(LOG_DEBUG, "w%d, nw: %d", bidx, ++nw);
3051 2925  
3052 2926                          if (mover_tape_write_one_buf(session, buf) < 0) {
3053      -                                NDMP_LOG(LOG_DEBUG,
     2927 +                                syslog(LOG_DEBUG,
3054 2928                                      "mover_tape_write_one_buf() failed");
3055 2929                                  break;
3056 2930                          }
3057 2931  
3058 2932                          (void) tlm_buffer_advance_out_idx(bufs);
3059 2933                          tlm_buffer_release_out_buf(bufs);
3060 2934                          bidx = bufs->tbs_buffer_out;
3061 2935                          buf = &bufs->tbs_buffer[bidx];
3062 2936                  } else {
3063 2937                          if (lcmd->tc_writer != TLM_BACKUP_RUN) {
3064 2938                                  /* No more data is coming, time to exit */
3065      -                                NDMP_LOG(LOG_DEBUG, "Time to exit");
3066 2939                                  break;
3067 2940                          }
3068      -                        NDMP_LOG(LOG_DEBUG, "W%d", bidx);
     2941 +                        syslog(LOG_DEBUG, "W%d", bidx);
3069 2942                          /*
3070 2943                           * The buffer is not full, wait for the producer
3071 2944                           * thread to fill it.
3072 2945                           */
3073 2946                          tlm_buffer_in_buf_timed_wait(bufs, 100);
3074 2947                  }
3075 2948          }
3076 2949  
3077 2950          if (cmds->tcs_writer == (int)TLM_ABORT)
3078      -                NDMP_LOG(LOG_DEBUG, "cmds->tcs_writer == TLM_ABORT");
     2951 +                syslog(LOG_DEBUG, "cmds->tcs_writer == TLM_ABORT");
3079 2952          if (lcmd->tc_writer == (int)TLM_ABORT)
3080      -                NDMP_LOG(LOG_DEBUG, "lcmd->tc_writer == TLM_ABORT");
3081      -        NDMP_LOG(LOG_DEBUG, "nw: %d", nw);
     2953 +                syslog(LOG_DEBUG, "lcmd->tc_writer == TLM_ABORT");
3082 2954  
3083 2955          if (buf->tb_errno == 0) {
3084 2956                  ndmpd_mover_error(session, NDMP_MOVER_HALT_CONNECT_CLOSED);
3085 2957          } else {
3086      -                NDMP_LOG(LOG_DEBUG, "buf->tb_errno: %d", buf->tb_errno);
3087 2958                  ndmpd_mover_error(session, NDMP_MOVER_HALT_INTERNAL_ERROR);
3088 2959          }
3089 2960  
3090 2961          /* If the producer is waiting for us, wake it up. */
3091 2962          tlm_buffer_release_out_buf(bufs);
3092 2963  
3093 2964          /*
3094 2965           * Clean up.
3095 2966           */
3096 2967          cmds->tcs_writer_count--;
↓ open down ↓ 18 lines elided ↑ open up ↑
3115 2986   *  -1: otherwise
3116 2987   */
3117 2988  static int
3118 2989  start_mover_for_backup(ndmpd_session_t *session)
3119 2990  {
3120 2991          ndmp_lbr_params_t *nlp;
3121 2992          tlm_commands_t *cmds;
3122 2993          int rc;
3123 2994  
3124 2995          if ((nlp = ndmp_get_nlp(session)) == NULL) {
3125      -                NDMP_LOG(LOG_DEBUG, "nlp == NULL");
3126 2996                  return (-1);
3127 2997          }
3128 2998  
3129 2999          cmds = &nlp->nlp_cmds;
3130 3000          (void) memset(cmds, 0, sizeof (*cmds));
3131 3001          cmds->tcs_reader = cmds->tcs_writer = TLM_BACKUP_RUN;
3132 3002          cmds->tcs_command = tlm_create_reader_writer_ipc(TRUE,
3133 3003              session->ns_mover.md_record_size);
3134 3004          if (cmds->tcs_command == NULL)
3135 3005                  return (-1);
↓ open down ↓ 4 lines elided ↑ open up ↑
3140 3010          /*
3141 3011           * We intentionally don't wait for the threads to start since the
3142 3012           * reply of the request (which resulted in calling this function)
3143 3013           * must be sent to the client before probable errors are sent
3144 3014           * to the client.
3145 3015           */
3146 3016          rc = pthread_create(NULL, NULL, (funct_t)mover_socket_reader, session);
3147 3017          if (rc == 0) {
3148 3018                  tlm_cmd_wait(cmds->tcs_command, TLM_SOCK_READER);
3149 3019          } else {
3150      -                NDMP_LOG(LOG_DEBUG, "Launch mover_socket_reader: %s",
3151      -                    strerror(rc));
3152 3020                  return (-1);
3153 3021          }
3154 3022  
3155 3023          rc = pthread_create(NULL, NULL, (funct_t)mover_tape_writer, session);
3156 3024          if (rc == 0) {
3157 3025                  tlm_cmd_wait(cmds->tcs_command, TLM_TAPE_WRITER);
3158 3026          } else {
3159      -                NDMP_LOG(LOG_DEBUG, "Launch mover_tape_writer: %s",
3160      -                    strerror(rc));
3161 3027                  return (-1);
3162 3028          }
3163 3029  
3164 3030          tlm_release_reader_writer_ipc(cmds->tcs_command);
3165 3031          return (0);
3166 3032  }
3167 3033  
3168 3034  
3169 3035  /*
3170 3036   * is_writer_running
↓ open down ↓ 138 lines elided ↑ open up ↑
3309 3175  {
3310 3176          ndmp_lbr_params_t *nlp = ndmp_get_nlp(session);
3311 3177  
3312 3178          if (session->ns_mover.md_state == NDMP_MOVER_STATE_HALTED ||
3313 3179              (session->ns_protocol_version > NDMPV2 &&
3314 3180              session->ns_mover.md_state == NDMP_MOVER_STATE_IDLE))
3315 3181                  return;
3316 3182  
3317 3183          if (session->ns_protocol_version == NDMPV4) {
3318 3184                  if (ndmpd_mover_error_send_v4(session, reason) < 0)
3319      -                        NDMP_LOG(LOG_DEBUG,
     3185 +                        syslog(LOG_ERR,
3320 3186                              "Error sending notify_mover_halted request");
3321 3187          } else {
3322 3188                  /* No media error in V3 */
3323 3189                  if (reason == NDMP_MOVER_HALT_MEDIA_ERROR)
3324 3190                          reason = NDMP_MOVER_HALT_INTERNAL_ERROR;
3325 3191                  if (ndmpd_mover_error_send(session, reason) < 0)
3326      -                        NDMP_LOG(LOG_DEBUG,
     3192 +                        syslog(LOG_ERR,
3327 3193                              "Error sending notify_mover_halted request");
3328 3194          }
3329 3195  
3330 3196          (void) mutex_lock(&nlp->nlp_mtx);
3331 3197          if (session->ns_mover.md_listen_sock != -1) {
3332 3198                  (void) ndmpd_remove_file_handler(session,
3333 3199                      session->ns_mover.md_listen_sock);
3334 3200                  (void) close(session->ns_mover.md_listen_sock);
3335 3201                  session->ns_mover.md_listen_sock = -1;
3336 3202          }
↓ open down ↓ 37 lines elided ↑ open up ↑
3374 3240          session->ns_mover.md_state = NDMP_MOVER_STATE_PAUSED;
3375 3241          session->ns_mover.md_pause_reason = reason;
3376 3242          session->ns_mover.md_pre_cond = FALSE;
3377 3243  
3378 3244          request.reason = session->ns_mover.md_pause_reason;
3379 3245          request.seek_position =
3380 3246              long_long_to_quad(session->ns_mover.md_position);
3381 3247  
3382 3248          if (ndmp_send_request(session->ns_connection, NDMP_NOTIFY_MOVER_PAUSED,
3383 3249              NDMP_NO_ERR, (void *)&request, 0) < 0) {
3384      -                NDMP_LOG(LOG_DEBUG,
     3250 +                syslog(LOG_ERR,
3385 3251                      "Error sending notify_mover_paused_request");
3386 3252                  return (-1);
3387 3253          }
3388 3254  
3389 3255          /*
3390 3256           * 3-way operations are single-thread.  The same thread
3391 3257           * should process the messages.
3392 3258           *
3393 3259           * 2-way operations are multi-thread.  The main thread
3394 3260           * processes the messages.  We just need to wait and
↓ open down ↓ 22 lines elided ↑ open up ↑
3417 3283                          default:
3418 3284                                  return (-1);
3419 3285                          }
3420 3286                  }
3421 3287  
3422 3288          } else {
3423 3289                  if (session->ns_mover.md_data_addr.addr_type ==
3424 3290                      NDMP_ADDR_LOCAL) {
3425 3291                          rv = ndmp_wait_for_mover(session);
3426 3292                  } else {
3427      -                        NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
3428      -                            session->ns_mover.md_data_addr.addr_type);
3429 3293                          rv = -1;
3430 3294                  }
3431 3295          }
3432 3296  
3433 3297          return (rv);
3434 3298  }
3435 3299  
3436 3300  
3437 3301  /*
3438 3302   * mover_tape_write_v3
↓ open down ↓ 16 lines elided ↑ open up ↑
3455 3319          ssize_t n;
3456 3320          ssize_t count = length;
3457 3321  
3458 3322          while (count > 0) {
3459 3323                  /*
3460 3324                   * Enforce mover window on write.
3461 3325                   */
3462 3326                  if (session->ns_mover.md_position >=
3463 3327                      session->ns_mover.md_window_offset +
3464 3328                      session->ns_mover.md_window_length) {
3465      -                        NDMP_LOG(LOG_DEBUG, "MOVER_PAUSE_EOW");
     3329 +                        syslog(LOG_DEBUG, "MOVER_PAUSE_EOW");
3466 3330  
3467 3331                          if (mover_pause_v3(session, NDMP_MOVER_PAUSE_EOW) < 0)
3468 3332                                  /* Operation aborted or connection terminated */
3469 3333                                  return (-1);
3470 3334  
3471 3335                  }
3472 3336  
3473 3337                  n = write(session->ns_tape.td_fd, data, count);
3474 3338                  if (n < 0) {
3475      -                        NDMP_LOG(LOG_ERR, "Tape write error: %m.");
     3339 +                        syslog(LOG_ERR, "Tape write error: %m.");
3476 3340                          return (-1);
3477 3341                  } else if (n > 0) {
3478 3342                          NS_ADD(wtape, n);
3479 3343                          count -= n;
3480 3344                          data += n;
3481 3345                          session->ns_tape.td_record_count++;
3482 3346                  }
3483 3347  
3484 3348                  /* EOM handling */
3485 3349                  if (count > 0) {
3486 3350                          struct mtget mtstatus;
3487 3351  
3488 3352                          (void) ioctl(session->ns_tape.td_fd, MTIOCGET,
3489 3353                              &mtstatus);
3490      -                        NDMP_LOG(LOG_DEBUG, "EOM detected (%d written bytes, "
     3354 +                        syslog(LOG_DEBUG, "EOM detected (%d written bytes, "
3491 3355                              "mover record %d, file #%d, block #%d)", n,
3492 3356                              session->ns_tape.td_record_count,
3493 3357                              mtstatus.mt_fileno, mtstatus.mt_blkno);
3494 3358  
3495 3359                          /*
3496 3360                           * Notify the client to either abort the operation
3497 3361                           * or change the tape.
3498 3362                           */
3499 3363                          NDMP_APILOG((void*)session, NDMP_LOG_NORMAL,
3500 3364                              ++ndmp_log_msg_id,
↓ open down ↓ 32 lines elided ↑ open up ↑
3533 3397          if (session->ns_mover.md_w_index == 0)
3534 3398                  return (0);
3535 3399  
3536 3400          (void) memset((void*)&session->ns_mover.md_buf[session->
3537 3401              ns_mover.md_w_index], 0,
3538 3402              session->ns_mover.md_record_size - session->ns_mover.md_w_index);
3539 3403  
3540 3404          n = mover_tape_write_v3(session, session->ns_mover.md_buf,
3541 3405              session->ns_mover.md_record_size);
3542 3406          if (n < 0) {
3543      -                NDMP_LOG(LOG_ERR, "Tape write error: %m.");
     3407 +                syslog(LOG_ERR, "Tape write error: %m.");
3544 3408                  return (-1);
3545 3409          }
3546 3410  
3547 3411          session->ns_mover.md_w_index = 0;
3548 3412          session->ns_mover.md_position += n;
3549 3413          return (n);
3550 3414  }
3551 3415  
3552 3416  
3553 3417  /*
↓ open down ↓ 14 lines elided ↑ open up ↑
3568 3432  int
3569 3433  ndmpd_local_write_v3(ndmpd_session_t *session, char *data, ulong_t length)
3570 3434  {
3571 3435          ulong_t count = 0;
3572 3436          ssize_t n;
3573 3437          ulong_t len;
3574 3438  
3575 3439          if (session->ns_mover.md_state == NDMP_MOVER_STATE_IDLE ||
3576 3440              session->ns_mover.md_state == NDMP_MOVER_STATE_LISTEN ||
3577 3441              session->ns_mover.md_state == NDMP_MOVER_STATE_HALTED) {
3578      -                NDMP_LOG(LOG_DEBUG, "Invalid mover state to write data");
3579 3442                  return (-1);
3580 3443          }
3581 3444  
3582 3445          /*
3583 3446           * A length of 0 indicates that any buffered data should be
3584 3447           * flushed to tape.
3585 3448           */
3586 3449          if (length == 0) {
3587 3450                  if (session->ns_mover.md_w_index == 0)
3588 3451                          return (0);
↓ open down ↓ 107 lines elided ↑ open up ↑
3696 3559          n = read(fd, &session->ns_mover.md_buf[session->ns_mover.md_w_index],
3697 3560              session->ns_mover.md_record_size - session->ns_mover.md_w_index);
3698 3561  
3699 3562          /*
3700 3563           * Since this function is only called when select believes data
3701 3564           * is available to be read, a return of zero indicates the
3702 3565           * connection has been closed.
3703 3566           */
3704 3567          if (n <= 0) {
3705 3568                  if (n == 0) {
3706      -                        NDMP_LOG(LOG_DEBUG, "Data connection closed");
     3569 +                        syslog(LOG_DEBUG, "Data connection closed");
3707 3570                          ndmpd_mover_error(session,
3708 3571                              NDMP_MOVER_HALT_CONNECT_CLOSED);
3709 3572                  } else {
3710 3573                          /* Socket is non-blocking, perhaps there are no data */
3711 3574                          if (errno == EAGAIN) {
3712      -                                NDMP_LOG(LOG_ERR, "No data to read");
     3575 +                                syslog(LOG_DEBUG, "No data to read");
3713 3576                                  return;
3714 3577                          }
3715 3578  
3716      -                        NDMP_LOG(LOG_ERR, "Failed to read from socket: %m");
     3579 +                        syslog(LOG_ERR,
     3580 +                            "Failed to read from socket %d: %m", fd);
3717 3581                          ndmpd_mover_error(session,
3718 3582                              NDMP_MOVER_HALT_INTERNAL_ERROR);
3719 3583                  }
3720 3584  
3721 3585                  /* Save the index since mover_tape_flush_v3 resets it. */
3722 3586                  index = session->ns_mover.md_w_index;
3723 3587  
3724 3588                  /* Flush any buffered data to tape. */
3725 3589                  if (mover_tape_flush_v3(session) > 0) {
3726 3590                          session->ns_mover.md_data_written += index;
3727 3591                          session->ns_mover.md_record_num++;
3728 3592                  }
3729 3593  
3730 3594                  return;
3731 3595          }
3732 3596  
3733      -        NDMP_LOG(LOG_DEBUG, "n %d", n);
3734      -
3735 3597          session->ns_mover.md_w_index += n;
3736 3598  
3737 3599          if (session->ns_mover.md_w_index == session->ns_mover.md_record_size) {
3738 3600                  n = mover_tape_write_v3(session, session->ns_mover.md_buf,
3739 3601                      session->ns_mover.md_record_size);
3740 3602                  if (n <= 0) {
3741 3603                          ndmpd_mover_error(session,
3742 3604                              (n == 0 ? NDMP_MOVER_HALT_ABORTED :
3743 3605                              NDMP_MOVER_HALT_MEDIA_ERROR));
3744 3606                          return;
↓ open down ↓ 33 lines elided ↑ open up ↑
3778 3640          while (count > 0) {
3779 3641                  pause_reason = NDMP_MOVER_PAUSE_NA;
3780 3642  
3781 3643                  n = read(session->ns_tape.td_fd, data, count);
3782 3644                  if (n < 0) {
3783 3645                          /*
3784 3646                           * If at beginning of file and read fails with EIO,
3785 3647                           * then it's repeated attempt to read at EOT.
3786 3648                           */
3787 3649                          if (errno == EIO && tape_is_at_bof(session)) {
3788      -                                NDMP_LOG(LOG_DEBUG, "Repeated read at EOT");
3789 3650                                  pause_reason = NDMP_MOVER_PAUSE_EOM;
3790 3651                                  NDMP_APILOG((void*)session, NDMP_LOG_NORMAL,
3791 3652                                      ++ndmp_log_msg_id,
3792 3653                                      "End of tape reached. Load next tape");
3793 3654                          }
3794 3655                          /*
3795 3656                           * According to NDMPv4 spec preferred error code when
3796 3657                           * trying to read from blank tape is NDMP_EOM_ERR.
3797 3658                           */
3798 3659                          else if (errno == EIO && tape_is_at_bot(session)) {
3799      -                                NDMP_LOG(LOG_ERR,
     3660 +                                syslog(LOG_ERR,
3800 3661                                      "Blank tape detected, returning EOM");
3801 3662                                  NDMP_APILOG((void*)session, NDMP_LOG_NORMAL,
3802 3663                                      ++ndmp_log_msg_id,
3803 3664                                      "Blank tape. Load another tape");
3804 3665                                  pause_reason = NDMP_MOVER_PAUSE_EOM;
3805 3666                          } else {
3806      -                                NDMP_LOG(LOG_ERR, "Tape read error: %m.");
     3667 +                                syslog(LOG_ERR, "Tape read error: %m.");
3807 3668                                  return (TAPE_READ_ERR);
3808 3669                          }
3809 3670                  } else if (n > 0) {
3810 3671                          NS_ADD(rtape, n);
3811 3672                          data += n;
3812 3673                          count -= n;
3813 3674                          session->ns_tape.td_record_count++;
3814 3675                  } else {
3815 3676                          if (!is_writer_running_v3(session))
3816 3677                                  return (TAPE_NO_WRITER_ERR);
3817 3678  
3818 3679                          /*
3819 3680                           * End of file or media reached. Notify client and
3820 3681                           * wait for the client to either abort the data
3821 3682                           * operation or continue the operation after changing
3822 3683                           * the tape.
3823 3684                           */
3824 3685                          if (tape_is_at_bof(session)) {
3825      -                                NDMP_LOG(LOG_DEBUG, "EOT detected");
     3686 +                                syslog(LOG_DEBUG, "EOT detected");
3826 3687                                  pause_reason = NDMP_MOVER_PAUSE_EOM;
3827 3688                                  NDMP_APILOG((void*)session, NDMP_LOG_NORMAL,
3828 3689                                      ++ndmp_log_msg_id, "End of medium reached");
3829 3690                          } else {
3830      -                                NDMP_LOG(LOG_DEBUG, "EOF detected");
     3691 +                                syslog(LOG_DEBUG, "EOF detected");
3831 3692                                  /* reposition the tape to BOT side of FM */
3832 3693                                  fm_dance(session);
3833 3694                                  pause_reason = NDMP_MOVER_PAUSE_EOF;
3834 3695                                  NDMP_APILOG((void*)session, NDMP_LOG_NORMAL,
3835 3696                                      ++ndmp_log_msg_id, "End of file reached.");
3836 3697                          }
3837 3698                  }
3838 3699  
3839 3700                  if (pause_reason != NDMP_MOVER_PAUSE_NA) {
3840 3701                          err = mover_pause_v3(session, pause_reason);
↓ open down ↓ 37 lines elided ↑ open up ↑
3878 3739  
3879 3740          /*
3880 3741           * If the end of the mover window has been reached,
3881 3742           * then notify the client that a seek is needed.
3882 3743           * Remove the file handler to prevent this function from
3883 3744           * being called. The handler will be reinstalled in
3884 3745           * ndmpd_mover_continue.
3885 3746           */
3886 3747          if (session->ns_mover.md_position >= session->ns_mover.md_window_offset
3887 3748              + session->ns_mover.md_window_length) {
3888      -                NDMP_LOG(LOG_DEBUG,
     3749 +                syslog(LOG_DEBUG,
3889 3750                      "MOVER_PAUSE_SEEK(%llu)", session->ns_mover.md_position);
3890 3751  
3891 3752                  session->ns_mover.md_w_index = 0;
3892 3753                  session->ns_mover.md_r_index = 0;
3893 3754  
3894 3755                  session->ns_mover.md_state = NDMP_MOVER_STATE_PAUSED;
3895 3756                  session->ns_mover.md_pause_reason = NDMP_MOVER_PAUSE_SEEK;
3896 3757                  pause_request.reason = NDMP_MOVER_PAUSE_SEEK;
3897 3758                  pause_request.seek_position =
3898 3759                      long_long_to_quad(session->ns_mover.md_position);
3899 3760                  session->ns_mover.md_seek_position =
3900 3761                      session->ns_mover.md_position;
3901 3762  
3902 3763                  (void) ndmpd_remove_file_handler(session, fd);
3903 3764  
3904 3765                  if (ndmp_send_request(session->ns_connection,
3905 3766                      NDMP_NOTIFY_MOVER_PAUSED, NDMP_NO_ERR,
3906 3767                      (void *)&pause_request, 0) < 0) {
3907      -                        NDMP_LOG(LOG_DEBUG,
     3768 +                        syslog(LOG_DEBUG,
3908 3769                              "Sending notify_mover_paused request");
3909 3770                          ndmpd_mover_error(session,
3910 3771                              NDMP_MOVER_HALT_INTERNAL_ERROR);
3911 3772                  }
3912 3773                  return;
3913 3774          }
3914 3775  
3915 3776          /*
3916 3777           * Read more data into the tape buffer if the buffer is empty.
3917 3778           */
3918 3779          if (session->ns_mover.md_w_index == 0) {
3919 3780                  n = mover_tape_read_v3(session, session->ns_mover.md_buf);
3920 3781  
3921      -                NDMP_LOG(LOG_DEBUG,
     3782 +                syslog(LOG_DEBUG,
3922 3783                      "read %u bytes from tape", n);
3923 3784  
3924 3785                  if (n <= 0) {
3925 3786                          ndmpd_mover_error(session, (n == 0 ?
3926 3787                              NDMP_MOVER_HALT_ABORTED
3927 3788                              : NDMP_MOVER_HALT_MEDIA_ERROR));
3928 3789                          return;
3929 3790                  }
3930 3791  
3931 3792                  /*
↓ open down ↓ 27 lines elided ↑ open up ↑
3959 3820          if (session->ns_mover.md_position +
3960 3821              session->ns_mover.md_bytes_left_to_read >
3961 3822              session->ns_mover.md_window_offset +
3962 3823              session->ns_mover.md_window_length)
3963 3824                  wlen = session->ns_mover.md_window_offset +
3964 3825                      session->ns_mover.md_window_length -
3965 3826                      session->ns_mover.md_position;
3966 3827          else
3967 3828                  wlen = session->ns_mover.md_bytes_left_to_read;
3968 3829  
3969      -        NDMP_LOG(LOG_DEBUG, "wlen window restrictions: %llu", wlen);
3970      -
3971 3830          /*
3972 3831           * Now limit the length to the amount of data in the buffer.
3973 3832           */
3974 3833          if (wlen > session->ns_mover.md_w_index - session->ns_mover.md_r_index)
3975 3834                  wlen = session->ns_mover.md_w_index -
3976 3835                      session->ns_mover.md_r_index;
3977 3836  
3978 3837          len = wlen & 0xffffffff;
3979      -        NDMP_LOG(LOG_DEBUG,
3980      -            "buffer restrictions: wlen %llu len %u", wlen, len);
3981 3838  
3982 3839          /*
3983 3840           * Write the data to the data connection.
3984 3841           */
3985 3842          n = write(session->ns_mover.md_sock,
3986 3843              &session->ns_mover.md_buf[session->ns_mover.md_r_index], len);
3987 3844  
3988 3845          if (n < 0) {
3989 3846                  /* Socket is non-blocking, perhaps the write queue is full */
3990 3847                  if (errno == EAGAIN) {
3991      -                        NDMP_LOG(LOG_ERR, "Cannot write to socket");
     3848 +                        syslog(LOG_ERR, "Cannot write to socket");
3992 3849                          return;
3993 3850                  }
3994      -                NDMP_LOG(LOG_ERR, "Failed to write to socket: %m");
     3851 +                syslog(LOG_ERR, "Failed to write to socket: %m");
3995 3852                  ndmpd_mover_error(session, NDMP_MOVER_HALT_CONNECT_CLOSED);
3996 3853                  return;
3997 3854          }
3998 3855  
3999      -        NDMP_LOG(LOG_DEBUG,
4000      -            "wrote %u of %u bytes to data connection position %llu r_index %lu",
     3856 +        syslog(LOG_DEBUG,
     3857 +            "wrote %u of %u bytes to data connection position %lu r_index %lu",
4001 3858              n, len, session->ns_mover.md_position,
4002 3859              session->ns_mover.md_r_index);
4003 3860  
4004 3861          session->ns_mover.md_r_index += n;
4005 3862          session->ns_mover.md_position += n;
4006 3863          session->ns_mover.md_bytes_left_to_read -= n;
4007 3864  
4008 3865          /*
4009 3866           * If all data in the buffer has been written,
4010 3867           * zero the buffer indices. The next call to this function
↓ open down ↓ 35 lines elided ↑ open up ↑
4046 3903  accept_connection_v3(void *cookie, int fd, ulong_t mode)
4047 3904  {
4048 3905          ndmpd_session_t *session = (ndmpd_session_t *)cookie;
4049 3906          int from_len;
4050 3907          struct sockaddr_in from;
4051 3908  
4052 3909          from_len = sizeof (from);
4053 3910          session->ns_mover.md_sock = accept(fd, (struct sockaddr *)&from,
4054 3911              &from_len);
4055 3912  
4056      -        NDMP_LOG(LOG_DEBUG, "sin: port %d addr %s", ntohs(from.sin_port),
     3913 +        syslog(LOG_DEBUG, "sin: port %d addr %s", ntohs(from.sin_port),
4057 3914              inet_ntoa(IN_ADDR(from.sin_addr.s_addr)));
4058 3915  
4059 3916          (void) ndmpd_remove_file_handler(session, fd);
4060 3917          (void) close(session->ns_mover.md_listen_sock);
4061 3918          session->ns_mover.md_listen_sock = -1;
4062 3919  
4063 3920          if (session->ns_mover.md_sock < 0) {
4064      -                NDMP_LOG(LOG_DEBUG, "Accept error: %m");
     3921 +                syslog(LOG_DEBUG, "Accept error: %m");
4065 3922                  ndmpd_mover_error(session, NDMP_MOVER_HALT_CONNECT_ERROR);
4066 3923                  return;
4067 3924          }
4068 3925  
4069 3926          /*
4070 3927           * Save the peer address.
4071 3928           */
4072 3929          session->ns_mover.md_data_addr.tcp_ip_v3 = from.sin_addr.s_addr;
4073 3930          session->ns_mover.md_data_addr.tcp_port_v3 = ntohs(from.sin_port);
4074 3931  
4075 3932          /* Set the parameter of the new socket */
4076 3933          set_socket_options(session->ns_mover.md_sock);
4077 3934  
4078 3935          /*
4079 3936           * Backup/restore is handled by a callback called from main event loop,
4080 3937           * which reads/writes data to md_sock socket. IO on socket must be
4081 3938           * non-blocking, otherwise ndmpd would be unable to process other
4082 3939           * incoming requests.
4083 3940           */
4084 3941          if (!set_socket_nonblock(session->ns_mover.md_sock)) {
4085      -                NDMP_LOG(LOG_ERR, "Could not set non-blocking mode "
     3942 +                syslog(LOG_ERR, "Could not set non-blocking mode "
4086 3943                      "on socket: %m");
4087 3944                  ndmpd_mover_error(session, NDMP_MOVER_HALT_INTERNAL_ERROR);
4088 3945                  return;
4089 3946          }
4090 3947  
4091      -        NDMP_LOG(LOG_DEBUG, "sock fd: %d", session->ns_mover.md_sock);
     3948 +        syslog(LOG_DEBUG, "sock fd: %d", session->ns_mover.md_sock);
4092 3949  
4093 3950          if (session->ns_mover.md_mode == NDMP_MOVER_MODE_READ) {
4094 3951                  if (ndmpd_add_file_handler(session, (void*)session,
4095 3952                      session->ns_mover.md_sock, NDMPD_SELECT_MODE_READ,
4096 3953                      HC_MOVER, mover_data_read_v3) < 0) {
4097 3954                          ndmpd_mover_error(session,
4098 3955                              NDMP_MOVER_HALT_INTERNAL_ERROR);
4099 3956                          return;
4100 3957                  }
4101      -                NDMP_LOG(LOG_DEBUG, "Backup connection established by %s:%d",
     3958 +                syslog(LOG_DEBUG, "Backup connection established by %s:%d",
4102 3959                      inet_ntoa(IN_ADDR(from.sin_addr.s_addr)),
4103 3960                      ntohs(from.sin_port));
4104 3961          } else {
4105      -                NDMP_LOG(LOG_DEBUG, "Restore connection established by %s:%d",
     3962 +                syslog(LOG_DEBUG, "Restore connection established by %s:%d",
4106 3963                      inet_ntoa(IN_ADDR(from.sin_addr.s_addr)),
4107 3964                      ntohs(from.sin_port));
4108 3965          }
4109 3966  
4110 3967          session->ns_mover.md_state = NDMP_MOVER_STATE_ACTIVE;
4111 3968  }
4112 3969  
4113 3970  
4114 3971  /*
4115 3972   * create_listen_socket_v3
↓ open down ↓ 21 lines elided ↑ open up ↑
4137 3994           * ndmpd_select will call accept_connection when a
4138 3995           * connection is ready to be accepted.
4139 3996           */
4140 3997          if (ndmpd_add_file_handler(session, (void *) session,
4141 3998              session->ns_mover.md_listen_sock, NDMPD_SELECT_MODE_READ, HC_MOVER,
4142 3999              accept_connection_v3) < 0) {
4143 4000                  (void) close(session->ns_mover.md_listen_sock);
4144 4001                  session->ns_mover.md_listen_sock = -1;
4145 4002                  return (-1);
4146 4003          }
4147      -        NDMP_LOG(LOG_DEBUG, "IP %s port %d",
     4004 +        syslog(LOG_DEBUG, "IP %s port %d",
4148 4005              inet_ntoa(*(struct in_addr *)addr), ntohs(*port));
4149 4006          return (0);
4150 4007  }
4151 4008  
4152 4009  
4153 4010  /*
4154 4011   * mover_connect_sock
4155 4012   *
4156 4013   * Connect the mover to the specified address
4157 4014   *
↓ open down ↓ 16 lines elided ↑ open up ↑
4174 4031          if (sock < 0)
4175 4032                  return (NDMP_CONNECT_ERR);
4176 4033  
4177 4034          /*
4178 4035           * Backup/restore is handled by a callback called from main event loop,
4179 4036           * which reads/writes data to md_sock socket. IO on socket must be
4180 4037           * non-blocking, otherwise ndmpd would be unable to process other
4181 4038           * incoming requests.
4182 4039           */
4183 4040          if (!set_socket_nonblock(sock)) {
4184      -                NDMP_LOG(LOG_ERR, "Could not set non-blocking mode "
     4041 +                syslog(LOG_ERR, "Could not set non-blocking mode "
4185 4042                      "on socket: %m");
4186 4043                  (void) close(sock);
4187 4044                  return (NDMP_CONNECT_ERR);
4188 4045          }
4189 4046  
4190 4047          if (mode == NDMP_MOVER_MODE_READ) {
4191 4048                  if (ndmpd_add_file_handler(session, (void*)session, sock,
4192 4049                      NDMPD_SELECT_MODE_READ, HC_MOVER, mover_data_read_v3) < 0) {
4193 4050                          (void) close(sock);
4194 4051                          return (NDMP_CONNECT_ERR);
↓ open down ↓ 27 lines elided ↑ open up ↑
4222 4079  ndmpd_local_read_v3(ndmpd_session_t *session, char *data, ulong_t length)
4223 4080  {
4224 4081          ulong_t count;
4225 4082          ulong_t len;
4226 4083          ssize_t n;
4227 4084  
4228 4085          count = 0;
4229 4086          if (session->ns_mover.md_state == NDMP_MOVER_STATE_IDLE ||
4230 4087              session->ns_mover.md_state == NDMP_MOVER_STATE_LISTEN ||
4231 4088              session->ns_mover.md_state == NDMP_MOVER_STATE_HALTED) {
4232      -                NDMP_LOG(LOG_DEBUG, "Invalid mover state to read data");
4233 4089                  return (-1);
4234 4090          }
4235 4091  
4236 4092          /*
4237 4093           * Automatically increase the seek window if necessary.
4238 4094           * This is needed in the event the module attempts to read
4239 4095           * past a seek window set via a prior call to ndmpd_seek() or
4240 4096           * the module has not issued a seek. If no seek was issued then
4241 4097           * pretend that a seek was issued to read the entire tape.
4242 4098           */
↓ open down ↓ 102 lines elided ↑ open up ↑
4345 4201                          ndmpd_mover_error(session,
4346 4202                              (n == 0 ? NDMP_MOVER_HALT_ABORTED :
4347 4203                              NDMP_MOVER_HALT_MEDIA_ERROR));
4348 4204                          return ((n == 0) ? 1 : -1);
4349 4205                  }
4350 4206  
4351 4207                  session->ns_mover.md_w_index = n;
4352 4208                  session->ns_mover.md_r_index = 0;
4353 4209                  session->ns_mover.md_record_num++;
4354 4210  
4355      -                NDMP_LOG(LOG_DEBUG, "n: %d", n);
4356      -
4357 4211                  /*
4358 4212                   * Discard data if the current data stream position is
4359 4213                   * prior to the seek position. This is necessary if a seek
4360 4214                   * request set the seek pointer to a position that is not a
4361 4215                   * record boundary. The seek request handler can only position
4362 4216                   * to the start of a record.
4363 4217                   */
4364 4218                  if (session->ns_mover.md_position <
4365 4219                      session->ns_mover.md_seek_position) {
4366 4220                          session->ns_mover.md_r_index =
4367 4221                              session->ns_mover.md_seek_position -
4368 4222                              session->ns_mover.md_position;
4369 4223                          session->ns_mover.md_position =
4370 4224                              session->ns_mover.md_seek_position;
4371 4225                  }
4372 4226          }
4373 4227  
4374 4228          return (0);
4375 4229  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX