--- old/usr/src/cmd/ndmpd/ndmp/ndmpd_mover.c	Mon Aug  5 17:15:18 2019
+++ new/usr/src/cmd/ndmpd/ndmp/ndmpd_mover.c	Mon Aug  5 17:15:18 2019
@@ -37,12 +37,13 @@
  */
 /* Copyright (c) 2007, The Storage Networking Industry Association. */
 /* Copyright (c) 1996, 1997 PDC, Network Appliance. All Rights Reserved */
-/* Copyright 2014 Nexenta Systems, Inc.  All rights reserved. */
+/* Copyright 2017 Nexenta Systems, Inc.  All rights reserved. */
 
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
+#include <syslog.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <net/if.h>
@@ -186,7 +187,6 @@
 
 	if (session->ns_mover.md_state != NDMP_MOVER_STATE_IDLE ||
 	    session->ns_data.dd_state != NDMP_DATA_STATE_IDLE) {
-		NDMP_LOG(LOG_DEBUG, "Invalid state");
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
 		ndmp_send_reply(connection, (void *) &reply,
 		    "sending mover_listen reply");
@@ -245,7 +245,6 @@
 	ndmpd_session_t *session = ndmp_get_client_data(connection);
 
 	if (session->ns_mover.md_state != NDMP_MOVER_STATE_PAUSED) {
-		NDMP_LOG(LOG_DEBUG, "Invalid state");
 
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
 		ndmp_send_reply(connection, (void *) &reply,
@@ -280,7 +279,6 @@
 
 	if (session->ns_mover.md_state == NDMP_MOVER_STATE_IDLE ||
 	    session->ns_mover.md_state == NDMP_MOVER_STATE_HALTED) {
-		NDMP_LOG(LOG_DEBUG, "Invalid state");
 
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
 		ndmp_send_reply(connection, (void *) &reply,
@@ -317,7 +315,6 @@
 	ndmpd_session_t *session = ndmp_get_client_data(connection);
 
 	if (session->ns_mover.md_state != NDMP_MOVER_STATE_HALTED) {
-		NDMP_LOG(LOG_DEBUG, "Invalid state");
 
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
 		ndmp_send_reply(connection, (void *) &reply,
@@ -370,12 +367,10 @@
 	    session->ns_mover.md_state != NDMP_MOVER_STATE_PAUSED &&
 	    session->ns_mover.md_state != NDMP_MOVER_STATE_LISTEN) {
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid state %d",
-		    session->ns_mover.md_state);
 	} else {
 		if (quad_to_long_long(request->length) == 0) {
 			reply.error = NDMP_ILLEGAL_ARGS_ERR;
-			NDMP_LOG(LOG_DEBUG, "Invalid window size %d",
+			syslog(LOG_ERR, "Illegal window size %d",
 			    quad_to_long_long(request->length));
 		} else {
 			reply.error = NDMP_NO_ERR;
@@ -422,7 +417,6 @@
 	if (session->ns_mover.md_state != NDMP_MOVER_STATE_ACTIVE ||
 	    session->ns_mover.md_bytes_left_to_read != 0 ||
 	    session->ns_mover.md_mode != NDMP_MOVER_MODE_WRITE) {
-		NDMP_LOG(LOG_DEBUG, "Invalid state");
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
 		ndmp_send_reply(connection, &reply,
 		    "sending mover_read reply");
@@ -429,7 +423,7 @@
 		return;
 	}
 	if (session->ns_tape.td_fd == -1) {
-		NDMP_LOG(LOG_DEBUG, "Tape device is not open");
+		syslog(LOG_ERR, "Tape device is not open");
 		reply.error = NDMP_DEV_NOT_OPEN_ERR;
 		ndmp_send_reply(connection, &reply,
 		    "sending mover_read reply");
@@ -480,7 +474,6 @@
 	ndmpd_session_t *session = ndmp_get_client_data(connection);
 
 	if (session->ns_mover.md_state != NDMP_MOVER_STATE_PAUSED) {
-		NDMP_LOG(LOG_DEBUG, "Invalid state");
 
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
 		ndmp_send_reply(connection, &reply,
@@ -513,6 +506,7 @@
 {
 	ndmp_mover_set_record_size_request *request;
 	ndmp_mover_set_record_size_reply reply;
+
 	ndmpd_session_t *session = ndmp_get_client_data(connection);
 
 	request = (ndmp_mover_set_record_size_request *) body;
@@ -612,26 +606,19 @@
 	if (request->mode != NDMP_MOVER_MODE_READ &&
 	    request->mode != NDMP_MOVER_MODE_WRITE) {
 		reply.error = NDMP_ILLEGAL_ARGS_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid mode %d", request->mode);
 	} else if (!ndmp_valid_v3addr_type(request->addr_type)) {
 		reply.error = NDMP_ILLEGAL_ARGS_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
-		    request->addr_type);
 	} else if (session->ns_mover.md_state != NDMP_MOVER_STATE_IDLE) {
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
-		NDMP_LOG(LOG_DEBUG,
-		    "Invalid mover state to process listen request");
 	} else if (session->ns_data.dd_state != NDMP_DATA_STATE_IDLE) {
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
-		NDMP_LOG(LOG_DEBUG,
-		    "Invalid data state to process listen request");
 	} else if (session->ns_tape.td_fd == -1) {
 		reply.error = NDMP_DEV_NOT_OPEN_ERR;
-		NDMP_LOG(LOG_DEBUG, "No tape device open");
+		syslog(LOG_ERR, "No tape device open");
 	} else if (request->mode == NDMP_MOVER_MODE_READ &&
 	    session->ns_tape.td_mode == NDMP_TAPE_READ_MODE) {
 		reply.error = NDMP_PERMISSION_ERR;
-		NDMP_LOG(LOG_ERR, "Write protected device.");
+		syslog(LOG_ERR, "Write protected device.");
 	}
 
 	if (reply.error != NDMP_NO_ERR) {
@@ -658,13 +645,11 @@
 		session->ns_mover.md_data_addr.addr_type = NDMP_ADDR_TCP;
 		session->ns_mover.md_data_addr.tcp_ip_v3 = addr;
 		session->ns_mover.md_data_addr.tcp_port_v3 = ntohs(port);
-		NDMP_LOG(LOG_DEBUG, "listen_socket: %d",
+		syslog(LOG_DEBUG, "listen_socket: %d",
 		    session->ns_mover.md_listen_sock);
 		break;
 	default:
 		reply.error = NDMP_ILLEGAL_ARGS_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid address type: %d",
-		    request->addr_type);
 	}
 
 	if (reply.error == NDMP_NO_ERR) {
@@ -701,7 +686,6 @@
 	(void) memset((void*)&reply, 0, sizeof (reply));
 
 	if (session->ns_mover.md_state != NDMP_MOVER_STATE_PAUSED) {
-		NDMP_LOG(LOG_DEBUG, "Invalid state");
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
 		ndmp_send_reply(connection, (void *) &reply,
 		    "sending mover_continue reply");
@@ -710,7 +694,7 @@
 
 	if (session->ns_protocol_version == NDMPV4 &&
 	    !session->ns_mover.md_pre_cond) {
-		NDMP_LOG(LOG_DEBUG, "Precondition check");
+		syslog(LOG_DEBUG, "Precondition check");
 		reply.error = NDMP_PRECONDITION_ERR;
 		ndmp_send_reply(connection, (void *) &reply,
 		    "sending mover_continue reply");
@@ -753,7 +737,6 @@
 			 * right window. This means that DMA does not follow
 			 * the V3 spec.
 			 */
-			NDMP_LOG(LOG_DEBUG, "DMA Error.");
 			ndmpd_mover_error(session,
 			    NDMP_MOVER_HALT_INTERNAL_ERROR);
 			return;
@@ -795,7 +778,6 @@
 
 	if (session->ns_mover.md_state == NDMP_MOVER_STATE_IDLE ||
 	    session->ns_mover.md_state == NDMP_MOVER_STATE_HALTED) {
-		NDMP_LOG(LOG_DEBUG, "Invalid state");
 
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
 		ndmp_send_reply(connection, (void *) &reply,
@@ -843,21 +825,16 @@
 	    session->ns_mover.md_state != NDMP_MOVER_STATE_LISTEN &&
 	    session->ns_mover.md_state != NDMP_MOVER_STATE_PAUSED) {
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid state %d",
-		    session->ns_mover.md_state);
 	} else if (session->ns_mover.md_record_size == 0) {
 		if (session->ns_protocol_version == NDMPV4)
 			reply.error = NDMP_PRECONDITION_ERR;
 		else
 			reply.error = NDMP_ILLEGAL_ARGS_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid record size 0");
 	} else
 		reply.error = NDMP_NO_ERR;
 
 	if (quad_to_long_long(request->length) == 0) {
 		reply.error = NDMP_ILLEGAL_ARGS_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid window size %d",
-		    quad_to_long_long(request->length));
 	}
 
 	if (reply.error != NDMP_NO_ERR) {
@@ -924,18 +901,15 @@
 	if (session->ns_mover.md_state != NDMP_MOVER_STATE_ACTIVE ||
 	    session->ns_mover.md_mode != NDMP_MOVER_MODE_WRITE) {
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid state");
 	} else if (session->ns_mover.md_bytes_left_to_read != 0) {
 		reply.error = NDMP_READ_IN_PROGRESS_ERR;
-		NDMP_LOG(LOG_DEBUG, "In progress");
 	} else if (session->ns_tape.td_fd == -1) {
 		reply.error = NDMP_DEV_NOT_OPEN_ERR;
-		NDMP_LOG(LOG_DEBUG, "Tape device is not open");
+		syslog(LOG_ERR, "Tape device is not open");
 	} else if (quad_to_long_long(request->length) == 0 ||
 	    (quad_to_long_long(request->length) == MAX_WINDOW_SIZE &&
 	    quad_to_long_long(request->offset) != 0)) {
 		reply.error = NDMP_ILLEGAL_ARGS_ERR;
-		NDMP_LOG(LOG_DEBUG, "Illegal args");
 	} else {
 		reply.error = NDMP_NO_ERR;
 	}
@@ -995,16 +969,12 @@
 
 	if (session->ns_mover.md_state != NDMP_MOVER_STATE_IDLE) {
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid mover state %d",
-		    session->ns_mover.md_state);
 	} else if (request->len > (unsigned int)ndmp_max_mover_recsize) {
 		reply.error = NDMP_ILLEGAL_ARGS_ERR;
-		NDMP_LOG(LOG_DEBUG,
-		    "Invalid argument %d, should be > 0 and <= %d",
-		    request->len, ndmp_max_mover_recsize);
-	} else if (request->len == session->ns_mover.md_record_size)
+	} else if (request->len == session->ns_mover.md_record_size) {
 		reply.error = NDMP_NO_ERR;
-	else if (!(cp = realloc(session->ns_mover.md_buf, request->len))) {
+		session->ns_mover.md_pre_cond = TRUE;
+	} else if (!(cp = realloc(session->ns_mover.md_buf, request->len))) {
 		reply.error = NDMP_NO_MEM_ERR;
 	} else {
 		reply.error = NDMP_NO_ERR;
@@ -1045,22 +1015,17 @@
 	if (request->mode != NDMP_MOVER_MODE_READ &&
 	    request->mode != NDMP_MOVER_MODE_WRITE) {
 		reply.error = NDMP_ILLEGAL_ARGS_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid mode %d", request->mode);
 	} else if (!ndmp_valid_v3addr_type(request->addr.addr_type)) {
 		reply.error = NDMP_ILLEGAL_ARGS_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
-		    request->addr.addr_type);
 	} else if (session->ns_mover.md_state != NDMP_MOVER_STATE_IDLE) {
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid state %d: mover is not idle",
-		    session->ns_mover.md_state);
 	} else if (session->ns_tape.td_fd == -1) {
 		reply.error = NDMP_DEV_NOT_OPEN_ERR;
-		NDMP_LOG(LOG_DEBUG, "No tape device open");
+		syslog(LOG_ERR, "No tape device open");
 	} else if (request->mode == NDMP_MOVER_MODE_READ &&
 	    session->ns_tape.td_mode == NDMP_TAPE_READ_MODE) {
 		reply.error = NDMP_WRITE_PROTECT_ERR;
-		NDMP_LOG(LOG_ERR, "Write protected device.");
+		syslog(LOG_ERR, "Write protected device.");
 	} else
 		reply.error = NDMP_NO_ERR;
 
@@ -1078,8 +1043,6 @@
 		 */
 		if (session->ns_data.dd_state != NDMP_DATA_STATE_LISTEN ||
 		    session->ns_data.dd_listen_sock != -1) {
-			NDMP_LOG(LOG_DEBUG,
-			    "Data server is not in local listen state");
 			reply.error = NDMP_ILLEGAL_STATE_ERR;
 		} else
 			session->ns_data.dd_state = NDMP_DATA_STATE_CONNECTED;
@@ -1092,8 +1055,6 @@
 
 	default:
 		reply.error = NDMP_ILLEGAL_ARGS_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
-		    request->addr.addr_type);
 	}
 
 	if (reply.error == NDMP_NO_ERR) {
@@ -1196,29 +1157,21 @@
 	if (request->mode != NDMP_MOVER_MODE_READ &&
 	    request->mode != NDMP_MOVER_MODE_WRITE) {
 		reply.error = NDMP_ILLEGAL_ARGS_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid mode %d", request->mode);
 	} else if (!ndmp_valid_v3addr_type(request->addr_type)) {
 		reply.error = NDMP_ILLEGAL_ARGS_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
-		    request->addr_type);
 	} else if (session->ns_mover.md_state != NDMP_MOVER_STATE_IDLE) {
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
-		NDMP_LOG(LOG_DEBUG,
-		    "Invalid mover state to process listen request");
 	} else if (session->ns_data.dd_state != NDMP_DATA_STATE_IDLE) {
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
-		NDMP_LOG(LOG_DEBUG,
-		    "Invalid data state to process listen request");
 	} else if (session->ns_tape.td_fd == -1) {
 		reply.error = NDMP_DEV_NOT_OPEN_ERR;
-		NDMP_LOG(LOG_DEBUG, "No tape device open");
+		syslog(LOG_ERR, "No tape device open");
 	} else if (session->ns_mover.md_record_size == 0) {
 		reply.error = NDMP_PRECONDITION_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid record size 0");
 	} else if (request->mode == NDMP_MOVER_MODE_READ &&
 	    session->ns_tape.td_mode == NDMP_TAPE_READ_MODE) {
 		reply.error = NDMP_PERMISSION_ERR;
-		NDMP_LOG(LOG_ERR, "Write protected device.");
+		syslog(LOG_ERR, "Write protected device.");
 	}
 
 	if (reply.error != NDMP_NO_ERR) {
@@ -1255,13 +1208,11 @@
 		session->ns_mover.md_data_addr.addr_type = NDMP_ADDR_TCP;
 		session->ns_mover.md_data_addr.tcp_ip_v3 = addr;
 		session->ns_mover.md_data_addr.tcp_port_v3 = ntohs(port);
-		NDMP_LOG(LOG_DEBUG, "listen_socket: %d",
+		syslog(LOG_DEBUG, "listen_socket: %d",
 		    session->ns_mover.md_listen_sock);
 		break;
 	default:
 		reply.error = NDMP_ILLEGAL_ARGS_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid address type: %d",
-		    request->addr_type);
 	}
 
 	if (reply.error == NDMP_NO_ERR) {
@@ -1299,25 +1250,19 @@
 	if (request->mode != NDMP_MOVER_MODE_READ &&
 	    request->mode != NDMP_MOVER_MODE_WRITE) {
 		reply.error = NDMP_ILLEGAL_ARGS_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid mode %d", request->mode);
 	} else if (!ndmp_valid_v3addr_type(request->addr.addr_type)) {
 		reply.error = NDMP_ILLEGAL_ARGS_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
-		    request->addr.addr_type);
 	} else if (session->ns_mover.md_state != NDMP_MOVER_STATE_IDLE) {
 		reply.error = NDMP_ILLEGAL_STATE_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid state %d: mover is not idle",
-		    session->ns_mover.md_state);
 	} else if (session->ns_tape.td_fd == -1) {
 		reply.error = NDMP_DEV_NOT_OPEN_ERR;
-		NDMP_LOG(LOG_DEBUG, "No tape device open");
+		syslog(LOG_ERR, "No tape device open");
 	} else if (request->mode == NDMP_MOVER_MODE_READ &&
 	    session->ns_tape.td_mode == NDMP_TAPE_READ_MODE) {
 		reply.error = NDMP_PERMISSION_ERR;
-		NDMP_LOG(LOG_ERR, "Write protected device.");
+		syslog(LOG_ERR, "Write protected device.");
 	} else if (session->ns_mover.md_record_size == 0) {
 		reply.error = NDMP_PRECONDITION_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid record size 0");
 	} else
 		reply.error = NDMP_NO_ERR;
 
@@ -1335,8 +1280,6 @@
 		 */
 		if (session->ns_data.dd_state != NDMP_DATA_STATE_LISTEN ||
 		    session->ns_data.dd_listen_sock != -1) {
-			NDMP_LOG(LOG_DEBUG,
-			    "Data server is not in local listen state");
 			reply.error = NDMP_ILLEGAL_STATE_ERR;
 		} else
 			session->ns_data.dd_state = NDMP_DATA_STATE_CONNECTED;
@@ -1349,8 +1292,6 @@
 
 	default:
 		reply.error = NDMP_ILLEGAL_ARGS_ERR;
-		NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
-		    request->addr.addr_type);
 	}
 
 	if (reply.error == NDMP_NO_ERR) {
@@ -1511,7 +1452,7 @@
 
 		if ((n = write(session->ns_data.dd_sock, &data[count],
 		    length - count)) < 0) {
-			NDMP_LOG(LOG_ERR, "Socket write error: %m.");
+			syslog(LOG_ERR, "Socket write error: %m.");
 			return (-1);
 		}
 		count += n;
@@ -1586,8 +1527,6 @@
 			if (ndmp_send_request(session->ns_connection,
 			    NDMP_NOTIFY_MOVER_PAUSED, NDMP_NO_ERR,
 			    (void *) &pause_request, 0) < 0) {
-				NDMP_LOG(LOG_DEBUG,
-				    "Sending notify_mover_paused request");
 				ndmpd_mover_error(session,
 				    NDMP_MOVER_HALT_INTERNAL_ERROR);
 				return (-1);
@@ -1673,8 +1612,6 @@
 		session->ns_mover.md_w_index = n;
 		session->ns_mover.md_r_index = 0;
 
-		NDMP_LOG(LOG_DEBUG, "n: %d", n);
-
 		/*
 		 * Discard data if the current data stream position is
 		 * prior to the seek position. This is necessary if a seek
@@ -1753,8 +1690,6 @@
 			if (ndmp_send_request_lock(session->ns_connection,
 			    NDMP_NOTIFY_DATA_READ, NDMP_NO_ERR,
 			    (void *) &request, 0) < 0) {
-				NDMP_LOG(LOG_DEBUG,
-				    "Sending notify_data_read request");
 				return (-1);
 			}
 		}
@@ -1781,11 +1716,9 @@
 		if (len > session->ns_mover.md_bytes_left_to_read)
 			len = session->ns_mover.md_bytes_left_to_read;
 
-		NDMP_LOG(LOG_DEBUG, "len: %u", len);
-
 		if ((n = read(session->ns_data.dd_sock, &data[count],
 		    len)) < 0) {
-			NDMP_LOG(LOG_ERR, "Socket read error: %m.");
+			syslog(LOG_ERR, "Socket read error: %m.");
 			return (-1);
 		}
 		/* read returns 0 if the connection was closed */
@@ -1871,8 +1804,6 @@
 
 	(void) mutex_lock(&nlp->nlp_mtx);
 	if (session->ns_mover.md_listen_sock != -1) {
-		NDMP_LOG(LOG_DEBUG, "mover.listen_sock: %d",
-		    session->ns_mover.md_listen_sock);
 		(void) ndmpd_remove_file_handler(session,
 		    session->ns_mover.md_listen_sock);
 		(void) close(session->ns_mover.md_listen_sock);
@@ -1879,8 +1810,6 @@
 		session->ns_mover.md_listen_sock = -1;
 	}
 	if (session->ns_mover.md_sock != -1) {
-		NDMP_LOG(LOG_DEBUG, "mover.sock: %d",
-		    session->ns_mover.md_sock);
 		(void) ndmpd_remove_file_handler(session,
 		    session->ns_mover.md_sock);
 		(void) close(session->ns_mover.md_sock);
@@ -1948,17 +1877,17 @@
 				return (NDMP_NO_ERR);
 			}
 
-			NDMP_LOG(LOG_DEBUG, "addr: %u port: %u",
+			syslog(LOG_DEBUG, "addr: %u port: %u",
 			    mover->ndmp_mover_addr_u.addr.ip_addr,
 			    (ulong_t)sin.sin_port);
 
 			if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
-				NDMP_LOG(LOG_DEBUG, "Socket error: %m");
+				syslog(LOG_ERR, "Socket error: %m");
 				return (NDMP_IO_ERR);
 			}
 			if (connect(sock, (struct sockaddr *)&sin,
 			    sizeof (sin)) < 0) {
-				NDMP_LOG(LOG_DEBUG, "Connect error: %m");
+				syslog(LOG_ERR, "Connect error: %m");
 				(void) close(sock);
 				return (NDMP_IO_ERR);
 			}
@@ -1968,9 +1897,9 @@
 			    NDMP_MOVER_STATE_ACTIVE) ||
 			    (session->ns_mover.md_sock == -1)) {
 
-				NDMP_LOG(LOG_DEBUG,
+				syslog(LOG_DEBUG,
 				    "Not in active  state mover"
-				    "  state = %d or Invalid mover sock=%d",
+				    "  state = %d or Illegal mover sock=%d",
 				    session->ns_mover.md_state,
 				    session->ns_mover.md_sock);
 				return (NDMP_ILLEGAL_STATE_ERR);
@@ -1977,32 +1906,27 @@
 			}
 
 			sock = session->ns_mover.md_sock;
-			NDMP_LOG(LOG_DEBUG,
+			syslog(LOG_DEBUG,
 			    "session: 0x%x setting data sock fd: %d to be"
 			    " same as listen_sock", session, sock);
 		}
 
-		NDMP_LOG(LOG_DEBUG, "sock fd: %d", sock);
-
 		session->ns_data.dd_sock = sock;
 
-		NDMP_LOG(LOG_DEBUG, "data.mover_sock: %u", sock);
-
 		return (NDMP_NO_ERR);
 	}
 	/* Local mover connection. */
 
 	if (session->ns_mover.md_state != NDMP_MOVER_STATE_LISTEN) {
-		NDMP_LOG(LOG_DEBUG, "Mover is not in listen state");
 		return (NDMP_ILLEGAL_STATE_ERR);
 	}
 	if (session->ns_tape.td_fd == -1) {
-		NDMP_LOG(LOG_DEBUG, "Tape device not open");
+		syslog(LOG_ERR, "Tape device not open");
 		return (NDMP_DEV_NOT_OPEN_ERR);
 	}
 	if (mover_mode == NDMP_MOVER_MODE_READ &&
 	    session->ns_tape.td_mode == NDMP_TAPE_READ_MODE) {
-		NDMP_LOG(LOG_ERR, "Write protected device.");
+		syslog(LOG_ERR, "Write protected device.");
 		return (NDMP_WRITE_PROTECT_ERR);
 	}
 	session->ns_mover.md_state = NDMP_MOVER_STATE_ACTIVE;
@@ -2058,8 +1982,6 @@
 	    session->ns_mover.md_seek_position >=
 	    session->ns_mover.md_window_offset +
 	    session->ns_mover.md_window_length) {
-		NDMP_LOG(LOG_DEBUG, "MOVER_PAUSE_SEEK(%llu)",
-		    session->ns_mover.md_seek_position);
 
 		session->ns_mover.md_w_index = 0;
 		session->ns_mover.md_r_index = 0;
@@ -2072,8 +1994,6 @@
 		if (ndmp_send_request(session->ns_connection,
 		    NDMP_NOTIFY_MOVER_PAUSED, NDMP_NO_ERR,
 		    (void *) &pause_request, 0) < 0) {
-			NDMP_LOG(LOG_DEBUG,
-			    "Sending notify_mover_paused request");
 			return (-1);
 		}
 		return (1);
@@ -2101,11 +2021,6 @@
 		session->ns_mover.md_position = offset;
 		session->ns_mover.md_r_index = session->ns_mover.md_position -
 		    buf_position;
-
-		NDMP_LOG(LOG_DEBUG, "pos %llu r_index %u",
-		    session->ns_mover.md_position,
-		    session->ns_mover.md_r_index);
-
 		return (0);
 	}
 
@@ -2130,8 +2045,6 @@
 	}
 	/* Reposition the tape if necessary. */
 	if (ctlcmd) {
-		NDMP_LOG(LOG_DEBUG, "cmd %d count %d",
-		    ctlcmd, ctlcnt);
 		(void) ndmp_mtioctl(session->ns_tape.td_fd, ctlcmd, ctlcnt);
 	}
 
@@ -2139,8 +2052,6 @@
 	session->ns_mover.md_r_index = 0;
 	session->ns_mover.md_w_index = 0;
 
-	NDMP_LOG(LOG_DEBUG, "pos %llu", session->ns_mover.md_position);
-
 	return (0);
 }
 
@@ -2181,7 +2092,6 @@
 		return (-1);
 	}
 
-	NDMP_LOG(LOG_DEBUG, "addr: 0x%x, port: %d", *addr, *port);
 	return (0);
 }
 
@@ -2217,14 +2127,12 @@
 	session->ns_mover.md_listen_sock = -1;
 
 	if (session->ns_mover.md_sock < 0) {
-		NDMP_LOG(LOG_DEBUG, "Accept error: %m");
+		syslog(LOG_ERR, "Accept error: %m");
 		ndmpd_mover_error(session, NDMP_MOVER_HALT_CONNECT_ERROR);
 		return;
 	}
 	set_socket_options(session->ns_mover.md_sock);
 
-	NDMP_LOG(LOG_DEBUG, "sock fd: %d", session->ns_mover.md_sock);
-
 	if (session->ns_mover.md_mode == NDMP_MOVER_MODE_READ) {
 		if (start_mover_for_backup(session) < 0) {
 			ndmpd_mover_error(session,
@@ -2231,17 +2139,15 @@
 			    NDMP_MOVER_HALT_INTERNAL_ERROR);
 			return;
 		}
-		NDMP_LOG(LOG_DEBUG, "Backup connection established by %s:%d",
+		syslog(LOG_DEBUG, "Backup connection established by %s:%d",
 		    inet_ntoa(IN_ADDR(from.sin_addr.s_addr)),
 		    ntohs(from.sin_port));
 	} else {
-		NDMP_LOG(LOG_DEBUG, "Restore connection established by %s:%d",
+		syslog(LOG_DEBUG, "Restore connection established by %s:%d",
 		    inet_ntoa(IN_ADDR(from.sin_addr.s_addr)),
 		    ntohs(from.sin_port));
 	}
 
-	NDMP_LOG(LOG_DEBUG, "Received connection");
-
 	session->ns_mover.md_state = NDMP_MOVER_STATE_ACTIVE;
 }
 
@@ -2269,7 +2175,7 @@
 	for (; ; ) {
 		n = read(session->ns_tape.td_fd, data, count);
 		if (n < 0) {
-			NDMP_LOG(LOG_ERR, "Tape read error: %m.");
+			syslog(LOG_ERR, "Tape read error: %m.");
 			return (TAPE_READ_ERR);
 		}
 		NS_ADD(rtape, n);
@@ -2288,7 +2194,7 @@
 			    ++ndmp_log_msg_id,
 			    "End of tape reached. Load next tape");
 
-			NDMP_LOG(LOG_DEBUG,
+			syslog(LOG_DEBUG,
 			    "End of tape reached. Load next tape");
 
 			err = change_tape(session);
@@ -2353,14 +2259,12 @@
 	request.reason = session->ns_mover.md_pause_reason;
 	request.seek_position = long_long_to_quad(0LL);
 
-	NDMP_LOG(LOG_DEBUG, "ndmp_send_request: MOVER_PAUSED, reason: %d",
+	syslog(LOG_DEBUG, "ndmp_send_request: MOVER_PAUSED, reason: %d",
 	    session->ns_mover.md_pause_reason);
 
 	if (ndmp_send_request(session->ns_connection,
 	    NDMP_NOTIFY_MOVER_PAUSED, NDMP_NO_ERR,
 	    (void *) &request, 0) < 0) {
-		NDMP_LOG(LOG_DEBUG,
-		    "Sending notify_mover_paused request");
 		return (-1);
 	}
 	/*
@@ -2397,7 +2301,7 @@
 	/* Read and discard the data. */
 	n = read(session->ns_mover.md_sock, addr, length);
 	if (n < 0) {
-		NDMP_LOG(LOG_ERR, "Socket read error: %m.");
+		syslog(LOG_ERR, "Socket read error: %m.");
 		free(addr);
 		return (-1);
 	}
@@ -2440,8 +2344,6 @@
 	    session->ns_mover.md_window_length) {
 		ndmp_notify_mover_paused_request pause_request;
 
-		NDMP_LOG(LOG_DEBUG, "end of mover window");
-
 		session->ns_mover.md_state = NDMP_MOVER_STATE_PAUSED;
 		session->ns_mover.md_pause_reason = NDMP_MOVER_PAUSE_SEEK;
 		pause_request.reason = NDMP_MOVER_PAUSE_SEEK;
@@ -2451,8 +2353,6 @@
 		if (ndmp_send_request(session->ns_connection,
 		    NDMP_NOTIFY_MOVER_PAUSED, NDMP_NO_ERR,
 		    (void *) &pause_request, 0) < 0) {
-			NDMP_LOG(LOG_DEBUG,
-			    "Sending notify_mover_paused request");
 			ndmpd_mover_error(session,
 			    NDMP_MOVER_HALT_INTERNAL_ERROR);
 		}
@@ -2462,8 +2362,6 @@
 
 	n = tape_read(session, buf->tb_buffer_data);
 
-	NDMP_LOG(LOG_DEBUG, "read %d bytes from tape", n);
-
 	if (n <= 0) {
 		if (n < 0)
 			ndmpd_mover_error(session,
@@ -2515,7 +2413,6 @@
 	tlm_commands_t *cmds;	/* Commands structure */
 
 	if ((nlp = ndmp_get_nlp(session)) == NULL) {
-		NDMP_LOG(LOG_DEBUG, "nlp == NULL");
 		return (-1);
 	}
 
@@ -2537,7 +2434,7 @@
 		buf = tlm_buffer_in_buf(bufs, NULL);
 
 		if (buf->tb_full) {
-			NDMP_LOG(LOG_DEBUG, "R%d", bidx);
+			syslog(LOG_DEBUG, "R%d", bidx);
 			/*
 			 * The buffer is still full, wait for the consumer
 			 * thread to use it.
@@ -2545,7 +2442,7 @@
 			tlm_buffer_out_buf_timed_wait(bufs, 100);
 
 		} else {
-			NDMP_LOG(LOG_DEBUG, "r%d", bidx);
+			syslog(LOG_DEBUG, "r%d", bidx);
 
 			rv = mover_tape_read_one_buf(session, buf);
 			/*
@@ -2553,7 +2450,7 @@
 			 * end of stream.
 			 */
 			if (rv < 0) {
-				NDMP_LOG(LOG_DEBUG, "Exiting, rv: %d", rv);
+				syslog(LOG_DEBUG, "Exiting, rv: %d", rv);
 				break;
 			}
 
@@ -2561,7 +2458,7 @@
 			 * Can we do more buffering?
 			 */
 			if (is_buffer_erroneous(buf)) {
-				NDMP_LOG(LOG_DEBUG,
+				syslog(LOG_DEBUG,
 				    "Exiting, errno: %d, eot: %d, eof: %d",
 				    buf->tb_errno, buf->tb_eot, buf->tb_eof);
 				break;
@@ -2609,10 +2506,7 @@
 	n = write(session->ns_mover.md_sock, buf->tb_buffer_data,
 	    buf->tb_buffer_size);
 
-	NDMP_LOG(LOG_DEBUG, "n: %d, len: %d", n, buf->tb_buffer_size);
-
 	if (n < 0) {
-		NDMP_LOG(LOG_DEBUG, "n: %d, errno: %m", n);
 		ndmpd_mover_error(session, NDMP_MOVER_HALT_CONNECT_CLOSED);
 		return (-1);
 	}
@@ -2628,7 +2522,6 @@
 	 * will reinstall the handler.
 	 */
 	if (session->ns_mover.md_bytes_left_to_read == 0) {
-		NDMP_LOG(LOG_DEBUG, "bytes_left_to_read == 0");
 		(void) ndmpd_remove_file_handler(session,
 		    session->ns_mover.md_sock);
 		return (-1);
@@ -2663,7 +2556,6 @@
 	tlm_commands_t *cmds;	/* Commands structure */
 
 	if ((nlp = ndmp_get_nlp(session)) == NULL) {
-		NDMP_LOG(LOG_DEBUG, "nlp == NULL");
 		return (-1);
 	}
 
@@ -2685,11 +2577,9 @@
 		buf = &bufs->tbs_buffer[bidx];
 
 		if (buf->tb_full) {
-			NDMP_LOG(LOG_DEBUG, "w%d", bidx);
+			syslog(LOG_DEBUG, "w%d", bidx);
 
 			if (mover_socket_write_one_buf(session, buf) < 0) {
-				NDMP_LOG(LOG_DEBUG,
-				    "mover_socket_write_one_buf() < 0");
 				break;
 			}
 
@@ -2699,10 +2589,9 @@
 		} else {
 			if (lcmd->tc_writer != TLM_RESTORE_RUN) {
 				/* No more data is coming, time to exit */
-				NDMP_LOG(LOG_DEBUG, "Time to exit");
 				break;
 			}
-			NDMP_LOG(LOG_DEBUG, "W%d", bidx);
+			syslog(LOG_DEBUG, "W%d", bidx);
 			/*
 			 * The buffer is not full, wait for the producer
 			 * thread to fill it.
@@ -2712,9 +2601,9 @@
 	}
 
 	if (cmds->tcs_writer == (int)TLM_ABORT)
-		NDMP_LOG(LOG_DEBUG, "cmds->tcs_writer == (int)TLM_ABORT");
+		syslog(LOG_DEBUG, "cmds->tcs_writer == (int)TLM_ABORT");
 	if (lcmd->tc_writer == (int)TLM_ABORT)
-		NDMP_LOG(LOG_DEBUG, "lcmd->tc_writer == TLM_ABORT");
+		syslog(LOG_DEBUG, "lcmd->tc_writer == TLM_ABORT");
 
 	/* If the producer is waiting for us, wake it up. */
 	tlm_buffer_release_out_buf(bufs);
@@ -2751,7 +2640,6 @@
 	int rc;
 
 	if ((nlp = ndmp_get_nlp(session)) == NULL) {
-		NDMP_LOG(LOG_DEBUG, "nlp == NULL");
 		return (-1);
 	}
 
@@ -2776,8 +2664,6 @@
 	if (rc == 0) {
 		tlm_cmd_wait(cmds->tcs_command, TLM_TAPE_READER);
 	} else {
-		NDMP_LOG(LOG_DEBUG, "Launch mover_tape_reader: %s",
-		    strerror(rc));
 		return (-1);
 	}
 
@@ -2785,8 +2671,6 @@
 	if (rc == 0) {
 		tlm_cmd_wait(cmds->tcs_command, TLM_SOCK_WRITER);
 	} else {
-		NDMP_LOG(LOG_DEBUG, "Launch mover_socket_writer: %s",
-		    strerror(rc));
 		return (-1);
 	}
 
@@ -2820,15 +2704,11 @@
 	tlm_buffer_mark_empty(buf);
 	for (index = 0, toread = read_size; toread > 0; ) {
 		errno = 0;
-		NDMP_LOG(LOG_DEBUG, "index: %d, toread: %d", index, toread);
-
 		n = read(session->ns_mover.md_sock, &buf->tb_buffer_data[index],
 		    toread);
 		if (n == 0) {
-			NDMP_LOG(LOG_DEBUG, "n: %d", n);
 			break;
 		} else if (n > 0) {
-			NDMP_LOG(LOG_DEBUG, "n: %d", n);
 			index += n;
 			toread -= n;
 		} else {
@@ -2835,7 +2715,6 @@
 			buf->tb_eof = TRUE;
 			buf->tb_errno = errno;
 			buf->tb_buffer_size = 0;
-			NDMP_LOG(LOG_DEBUG, "n: %d, errno: %m", n);
 			return (-1);
 		}
 	}
@@ -2851,7 +2730,7 @@
 		buf->tb_buffer_size = 0;
 	}
 
-	NDMP_LOG(LOG_DEBUG, "full: %d, eot: %d, eof: %d,"
+	syslog(LOG_DEBUG, "full: %d, eot: %d, eof: %d,"
 	    " errno: %d, size: %d, data: 0x%x",
 	    buf->tb_full, buf->tb_eot, buf->tb_eof, buf->tb_errno,
 	    buf->tb_buffer_size, buf->tb_buffer_data);
@@ -2886,7 +2765,6 @@
 	static int nr = 0;
 
 	if ((nlp = ndmp_get_nlp(session)) == NULL) {
-		NDMP_LOG(LOG_DEBUG, "nlp == NULL");
 		return (-1);
 	}
 
@@ -2908,7 +2786,7 @@
 		buf = &bufs->tbs_buffer[bidx];
 
 		if (buf->tb_full) {
-			NDMP_LOG(LOG_DEBUG, "R%d", bidx);
+			syslog(LOG_DEBUG, "R%d", bidx);
 			/*
 			 * The buffer is still full, wait for the consumer
 			 * thread to use it.
@@ -2915,7 +2793,7 @@
 			 */
 			tlm_buffer_out_buf_timed_wait(bufs, 100);
 		} else {
-			NDMP_LOG(LOG_DEBUG, "r%d, nr: %d", bidx, ++nr);
+			syslog(LOG_DEBUG, "r%d, nr: %d", bidx, ++nr);
 
 			(void) mover_socket_read_one_buf(session, buf,
 			    bufs->tbs_data_transfer_size);
@@ -2924,7 +2802,7 @@
 			 * Can we do more buffering?
 			 */
 			if (is_buffer_erroneous(buf)) {
-				NDMP_LOG(LOG_DEBUG,
+				syslog(LOG_DEBUG,
 				    "Exiting, errno: %d, eot: %d, eof: %d",
 				    buf->tb_errno, buf->tb_eot, buf->tb_eof);
 				break;
@@ -2937,10 +2815,10 @@
 	}
 
 	if (cmds->tcs_reader != TLM_BACKUP_RUN)
-		NDMP_LOG(LOG_DEBUG, "cmds->tcs_reader != TLM_BACKUP_RUN");
+		syslog(LOG_DEBUG, "cmds->tcs_reader != TLM_BACKUP_RUN");
 	if (lcmd->tc_reader != TLM_BACKUP_RUN)
-		NDMP_LOG(LOG_DEBUG, "lcmd->tc_reader != TLM_BACKUP_RUN");
-	NDMP_LOG(LOG_DEBUG, "nr: %d", nr);
+		syslog(LOG_DEBUG, "lcmd->tc_reader != TLM_BACKUP_RUN");
+	syslog(LOG_DEBUG, "nr: %d", nr);
 
 	/* If the consumer is waiting for us, wake it up. */
 	tlm_buffer_release_in_buf(bufs);
@@ -2974,7 +2852,7 @@
 {
 	int n;
 
-	NDMP_LOG(LOG_DEBUG, "full: %d, eot: %d, eof: %d,"
+	syslog(LOG_DEBUG, "full: %d, eot: %d, eof: %d,"
 	    " errno: %d, size: %d, data: 0x%x",
 	    buf->tb_full, buf->tb_eot, buf->tb_eof, buf->tb_errno,
 	    buf->tb_buffer_size, buf->tb_buffer_data);
@@ -2982,8 +2860,6 @@
 	n = mover_tape_write_v3(session, buf->tb_buffer_data,
 	    buf->tb_buffer_size);
 
-	NDMP_LOG(LOG_DEBUG, "n: %d", n);
-
 	if (n <= 0) {
 		ndmpd_mover_error(session, (n == 0 ? NDMP_MOVER_HALT_ABORTED
 		    : NDMP_MOVER_HALT_INTERNAL_ERROR));
@@ -2993,7 +2869,6 @@
 	session->ns_mover.md_data_written += n;
 	session->ns_mover.md_record_num++;
 
-	NDMP_LOG(LOG_DEBUG, "Calling tlm_buffer_mark_empty(buf)");
 	tlm_buffer_mark_empty(buf);
 
 	return (0);
@@ -3026,7 +2901,6 @@
 	static int nw = 0;
 
 	if ((nlp = ndmp_get_nlp(session)) == NULL) {
-		NDMP_LOG(LOG_DEBUG, "nlp == NULL");
 		return (-1);
 	}
 
@@ -3047,10 +2921,10 @@
 	while (cmds->tcs_writer != (int)TLM_ABORT &&
 	    lcmd->tc_writer != (int)TLM_ABORT) {
 		if (buf->tb_full) {
-			NDMP_LOG(LOG_DEBUG, "w%d, nw: %d", bidx, ++nw);
+			syslog(LOG_DEBUG, "w%d, nw: %d", bidx, ++nw);
 
 			if (mover_tape_write_one_buf(session, buf) < 0) {
-				NDMP_LOG(LOG_DEBUG,
+				syslog(LOG_DEBUG,
 				    "mover_tape_write_one_buf() failed");
 				break;
 			}
@@ -3062,10 +2936,9 @@
 		} else {
 			if (lcmd->tc_writer != TLM_BACKUP_RUN) {
 				/* No more data is coming, time to exit */
-				NDMP_LOG(LOG_DEBUG, "Time to exit");
 				break;
 			}
-			NDMP_LOG(LOG_DEBUG, "W%d", bidx);
+			syslog(LOG_DEBUG, "W%d", bidx);
 			/*
 			 * The buffer is not full, wait for the producer
 			 * thread to fill it.
@@ -3075,15 +2948,13 @@
 	}
 
 	if (cmds->tcs_writer == (int)TLM_ABORT)
-		NDMP_LOG(LOG_DEBUG, "cmds->tcs_writer == TLM_ABORT");
+		syslog(LOG_DEBUG, "cmds->tcs_writer == TLM_ABORT");
 	if (lcmd->tc_writer == (int)TLM_ABORT)
-		NDMP_LOG(LOG_DEBUG, "lcmd->tc_writer == TLM_ABORT");
-	NDMP_LOG(LOG_DEBUG, "nw: %d", nw);
+		syslog(LOG_DEBUG, "lcmd->tc_writer == TLM_ABORT");
 
 	if (buf->tb_errno == 0) {
 		ndmpd_mover_error(session, NDMP_MOVER_HALT_CONNECT_CLOSED);
 	} else {
-		NDMP_LOG(LOG_DEBUG, "buf->tb_errno: %d", buf->tb_errno);
 		ndmpd_mover_error(session, NDMP_MOVER_HALT_INTERNAL_ERROR);
 	}
 
@@ -3122,7 +2993,6 @@
 	int rc;
 
 	if ((nlp = ndmp_get_nlp(session)) == NULL) {
-		NDMP_LOG(LOG_DEBUG, "nlp == NULL");
 		return (-1);
 	}
 
@@ -3147,8 +3017,6 @@
 	if (rc == 0) {
 		tlm_cmd_wait(cmds->tcs_command, TLM_SOCK_READER);
 	} else {
-		NDMP_LOG(LOG_DEBUG, "Launch mover_socket_reader: %s",
-		    strerror(rc));
 		return (-1);
 	}
 
@@ -3156,8 +3024,6 @@
 	if (rc == 0) {
 		tlm_cmd_wait(cmds->tcs_command, TLM_TAPE_WRITER);
 	} else {
-		NDMP_LOG(LOG_DEBUG, "Launch mover_tape_writer: %s",
-		    strerror(rc));
 		return (-1);
 	}
 
@@ -3316,7 +3182,7 @@
 
 	if (session->ns_protocol_version == NDMPV4) {
 		if (ndmpd_mover_error_send_v4(session, reason) < 0)
-			NDMP_LOG(LOG_DEBUG,
+			syslog(LOG_ERR,
 			    "Error sending notify_mover_halted request");
 	} else {
 		/* No media error in V3 */
@@ -3323,7 +3189,7 @@
 		if (reason == NDMP_MOVER_HALT_MEDIA_ERROR)
 			reason = NDMP_MOVER_HALT_INTERNAL_ERROR;
 		if (ndmpd_mover_error_send(session, reason) < 0)
-			NDMP_LOG(LOG_DEBUG,
+			syslog(LOG_ERR,
 			    "Error sending notify_mover_halted request");
 	}
 
@@ -3381,7 +3247,7 @@
 
 	if (ndmp_send_request(session->ns_connection, NDMP_NOTIFY_MOVER_PAUSED,
 	    NDMP_NO_ERR, (void *)&request, 0) < 0) {
-		NDMP_LOG(LOG_DEBUG,
+		syslog(LOG_ERR,
 		    "Error sending notify_mover_paused_request");
 		return (-1);
 	}
@@ -3424,8 +3290,6 @@
 		    NDMP_ADDR_LOCAL) {
 			rv = ndmp_wait_for_mover(session);
 		} else {
-			NDMP_LOG(LOG_DEBUG, "Invalid address type %d",
-			    session->ns_mover.md_data_addr.addr_type);
 			rv = -1;
 		}
 	}
@@ -3462,7 +3326,7 @@
 		if (session->ns_mover.md_position >=
 		    session->ns_mover.md_window_offset +
 		    session->ns_mover.md_window_length) {
-			NDMP_LOG(LOG_DEBUG, "MOVER_PAUSE_EOW");
+			syslog(LOG_DEBUG, "MOVER_PAUSE_EOW");
 
 			if (mover_pause_v3(session, NDMP_MOVER_PAUSE_EOW) < 0)
 				/* Operation aborted or connection terminated */
@@ -3472,7 +3336,7 @@
 
 		n = write(session->ns_tape.td_fd, data, count);
 		if (n < 0) {
-			NDMP_LOG(LOG_ERR, "Tape write error: %m.");
+			syslog(LOG_ERR, "Tape write error: %m.");
 			return (-1);
 		} else if (n > 0) {
 			NS_ADD(wtape, n);
@@ -3487,7 +3351,7 @@
 
 			(void) ioctl(session->ns_tape.td_fd, MTIOCGET,
 			    &mtstatus);
-			NDMP_LOG(LOG_DEBUG, "EOM detected (%d written bytes, "
+			syslog(LOG_DEBUG, "EOM detected (%d written bytes, "
 			    "mover record %d, file #%d, block #%d)", n,
 			    session->ns_tape.td_record_count,
 			    mtstatus.mt_fileno, mtstatus.mt_blkno);
@@ -3540,7 +3404,7 @@
 	n = mover_tape_write_v3(session, session->ns_mover.md_buf,
 	    session->ns_mover.md_record_size);
 	if (n < 0) {
-		NDMP_LOG(LOG_ERR, "Tape write error: %m.");
+		syslog(LOG_ERR, "Tape write error: %m.");
 		return (-1);
 	}
 
@@ -3575,7 +3439,6 @@
 	if (session->ns_mover.md_state == NDMP_MOVER_STATE_IDLE ||
 	    session->ns_mover.md_state == NDMP_MOVER_STATE_LISTEN ||
 	    session->ns_mover.md_state == NDMP_MOVER_STATE_HALTED) {
-		NDMP_LOG(LOG_DEBUG, "Invalid mover state to write data");
 		return (-1);
 	}
 
@@ -3703,17 +3566,18 @@
 	 */
 	if (n <= 0) {
 		if (n == 0) {
-			NDMP_LOG(LOG_DEBUG, "Data connection closed");
+			syslog(LOG_DEBUG, "Data connection closed");
 			ndmpd_mover_error(session,
 			    NDMP_MOVER_HALT_CONNECT_CLOSED);
 		} else {
 			/* Socket is non-blocking, perhaps there are no data */
 			if (errno == EAGAIN) {
-				NDMP_LOG(LOG_ERR, "No data to read");
+				syslog(LOG_DEBUG, "No data to read");
 				return;
 			}
 
-			NDMP_LOG(LOG_ERR, "Failed to read from socket: %m");
+			syslog(LOG_ERR,
+			    "Failed to read from socket %d: %m", fd);
 			ndmpd_mover_error(session,
 			    NDMP_MOVER_HALT_INTERNAL_ERROR);
 		}
@@ -3730,8 +3594,6 @@
 		return;
 	}
 
-	NDMP_LOG(LOG_DEBUG, "n %d", n);
-
 	session->ns_mover.md_w_index += n;
 
 	if (session->ns_mover.md_w_index == session->ns_mover.md_record_size) {
@@ -3785,7 +3647,6 @@
 			 * then it's repeated attempt to read at EOT.
 			 */
 			if (errno == EIO && tape_is_at_bof(session)) {
-				NDMP_LOG(LOG_DEBUG, "Repeated read at EOT");
 				pause_reason = NDMP_MOVER_PAUSE_EOM;
 				NDMP_APILOG((void*)session, NDMP_LOG_NORMAL,
 				    ++ndmp_log_msg_id,
@@ -3796,7 +3657,7 @@
 			 * trying to read from blank tape is NDMP_EOM_ERR.
 			 */
 			else if (errno == EIO && tape_is_at_bot(session)) {
-				NDMP_LOG(LOG_ERR,
+				syslog(LOG_ERR,
 				    "Blank tape detected, returning EOM");
 				NDMP_APILOG((void*)session, NDMP_LOG_NORMAL,
 				    ++ndmp_log_msg_id,
@@ -3803,7 +3664,7 @@
 				    "Blank tape. Load another tape");
 				pause_reason = NDMP_MOVER_PAUSE_EOM;
 			} else {
-				NDMP_LOG(LOG_ERR, "Tape read error: %m.");
+				syslog(LOG_ERR, "Tape read error: %m.");
 				return (TAPE_READ_ERR);
 			}
 		} else if (n > 0) {
@@ -3822,12 +3683,12 @@
 			 * the tape.
 			 */
 			if (tape_is_at_bof(session)) {
-				NDMP_LOG(LOG_DEBUG, "EOT detected");
+				syslog(LOG_DEBUG, "EOT detected");
 				pause_reason = NDMP_MOVER_PAUSE_EOM;
 				NDMP_APILOG((void*)session, NDMP_LOG_NORMAL,
 				    ++ndmp_log_msg_id, "End of medium reached");
 			} else {
-				NDMP_LOG(LOG_DEBUG, "EOF detected");
+				syslog(LOG_DEBUG, "EOF detected");
 				/* reposition the tape to BOT side of FM */
 				fm_dance(session);
 				pause_reason = NDMP_MOVER_PAUSE_EOF;
@@ -3885,7 +3746,7 @@
 	 */
 	if (session->ns_mover.md_position >= session->ns_mover.md_window_offset
 	    + session->ns_mover.md_window_length) {
-		NDMP_LOG(LOG_DEBUG,
+		syslog(LOG_DEBUG,
 		    "MOVER_PAUSE_SEEK(%llu)", session->ns_mover.md_position);
 
 		session->ns_mover.md_w_index = 0;
@@ -3904,7 +3765,7 @@
 		if (ndmp_send_request(session->ns_connection,
 		    NDMP_NOTIFY_MOVER_PAUSED, NDMP_NO_ERR,
 		    (void *)&pause_request, 0) < 0) {
-			NDMP_LOG(LOG_DEBUG,
+			syslog(LOG_DEBUG,
 			    "Sending notify_mover_paused request");
 			ndmpd_mover_error(session,
 			    NDMP_MOVER_HALT_INTERNAL_ERROR);
@@ -3918,7 +3779,7 @@
 	if (session->ns_mover.md_w_index == 0) {
 		n = mover_tape_read_v3(session, session->ns_mover.md_buf);
 
-		NDMP_LOG(LOG_DEBUG,
+		syslog(LOG_DEBUG,
 		    "read %u bytes from tape", n);
 
 		if (n <= 0) {
@@ -3966,8 +3827,6 @@
 	else
 		wlen = session->ns_mover.md_bytes_left_to_read;
 
-	NDMP_LOG(LOG_DEBUG, "wlen window restrictions: %llu", wlen);
-
 	/*
 	 * Now limit the length to the amount of data in the buffer.
 	 */
@@ -3976,8 +3835,6 @@
 		    session->ns_mover.md_r_index;
 
 	len = wlen & 0xffffffff;
-	NDMP_LOG(LOG_DEBUG,
-	    "buffer restrictions: wlen %llu len %u", wlen, len);
 
 	/*
 	 * Write the data to the data connection.
@@ -3988,16 +3845,16 @@
 	if (n < 0) {
 		/* Socket is non-blocking, perhaps the write queue is full */
 		if (errno == EAGAIN) {
-			NDMP_LOG(LOG_ERR, "Cannot write to socket");
+			syslog(LOG_ERR, "Cannot write to socket");
 			return;
 		}
-		NDMP_LOG(LOG_ERR, "Failed to write to socket: %m");
+		syslog(LOG_ERR, "Failed to write to socket: %m");
 		ndmpd_mover_error(session, NDMP_MOVER_HALT_CONNECT_CLOSED);
 		return;
 	}
 
-	NDMP_LOG(LOG_DEBUG,
-	    "wrote %u of %u bytes to data connection position %llu r_index %lu",
+	syslog(LOG_DEBUG,
+	    "wrote %u of %u bytes to data connection position %lu r_index %lu",
 	    n, len, session->ns_mover.md_position,
 	    session->ns_mover.md_r_index);
 
@@ -4053,7 +3910,7 @@
 	session->ns_mover.md_sock = accept(fd, (struct sockaddr *)&from,
 	    &from_len);
 
-	NDMP_LOG(LOG_DEBUG, "sin: port %d addr %s", ntohs(from.sin_port),
+	syslog(LOG_DEBUG, "sin: port %d addr %s", ntohs(from.sin_port),
 	    inet_ntoa(IN_ADDR(from.sin_addr.s_addr)));
 
 	(void) ndmpd_remove_file_handler(session, fd);
@@ -4061,7 +3918,7 @@
 	session->ns_mover.md_listen_sock = -1;
 
 	if (session->ns_mover.md_sock < 0) {
-		NDMP_LOG(LOG_DEBUG, "Accept error: %m");
+		syslog(LOG_DEBUG, "Accept error: %m");
 		ndmpd_mover_error(session, NDMP_MOVER_HALT_CONNECT_ERROR);
 		return;
 	}
@@ -4082,13 +3939,13 @@
 	 * incoming requests.
 	 */
 	if (!set_socket_nonblock(session->ns_mover.md_sock)) {
-		NDMP_LOG(LOG_ERR, "Could not set non-blocking mode "
+		syslog(LOG_ERR, "Could not set non-blocking mode "
 		    "on socket: %m");
 		ndmpd_mover_error(session, NDMP_MOVER_HALT_INTERNAL_ERROR);
 		return;
 	}
 
-	NDMP_LOG(LOG_DEBUG, "sock fd: %d", session->ns_mover.md_sock);
+	syslog(LOG_DEBUG, "sock fd: %d", session->ns_mover.md_sock);
 
 	if (session->ns_mover.md_mode == NDMP_MOVER_MODE_READ) {
 		if (ndmpd_add_file_handler(session, (void*)session,
@@ -4098,11 +3955,11 @@
 			    NDMP_MOVER_HALT_INTERNAL_ERROR);
 			return;
 		}
-		NDMP_LOG(LOG_DEBUG, "Backup connection established by %s:%d",
+		syslog(LOG_DEBUG, "Backup connection established by %s:%d",
 		    inet_ntoa(IN_ADDR(from.sin_addr.s_addr)),
 		    ntohs(from.sin_port));
 	} else {
-		NDMP_LOG(LOG_DEBUG, "Restore connection established by %s:%d",
+		syslog(LOG_DEBUG, "Restore connection established by %s:%d",
 		    inet_ntoa(IN_ADDR(from.sin_addr.s_addr)),
 		    ntohs(from.sin_port));
 	}
@@ -4144,7 +4001,7 @@
 		session->ns_mover.md_listen_sock = -1;
 		return (-1);
 	}
-	NDMP_LOG(LOG_DEBUG, "IP %s port %d",
+	syslog(LOG_DEBUG, "IP %s port %d",
 	    inet_ntoa(*(struct in_addr *)addr), ntohs(*port));
 	return (0);
 }
@@ -4181,7 +4038,7 @@
 	 * incoming requests.
 	 */
 	if (!set_socket_nonblock(sock)) {
-		NDMP_LOG(LOG_ERR, "Could not set non-blocking mode "
+		syslog(LOG_ERR, "Could not set non-blocking mode "
 		    "on socket: %m");
 		(void) close(sock);
 		return (NDMP_CONNECT_ERR);
@@ -4229,7 +4086,6 @@
 	if (session->ns_mover.md_state == NDMP_MOVER_STATE_IDLE ||
 	    session->ns_mover.md_state == NDMP_MOVER_STATE_LISTEN ||
 	    session->ns_mover.md_state == NDMP_MOVER_STATE_HALTED) {
-		NDMP_LOG(LOG_DEBUG, "Invalid mover state to read data");
 		return (-1);
 	}
 
@@ -4352,8 +4208,6 @@
 		session->ns_mover.md_r_index = 0;
 		session->ns_mover.md_record_num++;
 
-		NDMP_LOG(LOG_DEBUG, "n: %d", n);
-
 		/*
 		 * Discard data if the current data stream position is
 		 * prior to the seek position. This is necessary if a seek
