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-894 Default location of NDMP log file should be under /var/log
NEX-727 Netbackup Catalog verification hangs waiting for NDMP server
@@ -1,8 +1,8 @@
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
/*
* BSD 3 Clause License
*
@@ -41,10 +41,11 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/uio.h>
+#include <syslog.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
@@ -82,10 +83,20 @@
* Do we support Direct Access Restore?
*/
int ndmp_dar_support = 0;
/*
+ * Is autosync enabled?
+ */
+int ndmp_autosync_support = 0;
+
+/*
+ * Is HPR snapshot enabled?
+ */
+int ndmp_hpr_support = 0;
+
+/*
* ndmp_connection_t handler function
*/
static ndmpd_file_handler_func_t connection_file_handler;
extern ndmp_handler_t ndmp_msghdl_tab[];
@@ -152,11 +163,11 @@
xdrrec_create(&connection->conn_xdrs, 0, 0, (caddr_t)connection,
ndmp_readit, ndmp_writeit);
if (connection->conn_xdrs.x_ops == 0) {
- NDMP_LOG(LOG_DEBUG, "xdrrec_create failed");
+ syslog(LOG_ERR, "xdrrec_create failed");
(void) mutex_destroy(&connection->conn_lock);
(void) close(connection->conn_sock);
free(connection);
return (0);
}
@@ -276,36 +287,35 @@
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(port);
if ((server_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- NDMP_LOG(LOG_DEBUG, "Socket error: %m");
+ syslog(LOG_ERR, "Socket error: %m");
return (-1);
}
on = 1;
(void) setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR,
(char *)&on, sizeof (on));
if (bind(server_socket, (struct sockaddr *)&sin, sizeof (sin)) < 0) {
- NDMP_LOG(LOG_DEBUG, "bind error: %m");
+ syslog(LOG_ERR, "bind error: %m");
(void) close(server_socket);
return (-1);
}
if (listen(server_socket, 5) < 0) {
- NDMP_LOG(LOG_DEBUG, "listen error: %m");
+ syslog(LOG_ERR, "listen error: %m");
(void) close(server_socket);
return (-1);
}
for (; ; ) {
if ((ns = tcp_accept(server_socket, &ipaddr)) < 0) {
- NDMP_LOG(LOG_DEBUG, "tcp_accept error: %m");
+ syslog(LOG_ERR, "tcp_accept error: %m");
continue;
}
- NDMP_LOG(LOG_DEBUG, "connection fd: %d", ns);
set_socket_options(ns);
if ((argp = ndmp_malloc(sizeof (ndmpd_worker_arg_t))) != NULL) {
argp->nw_sock = ns;
argp->nw_ipaddr = ipaddr;
@@ -420,11 +430,11 @@
int r;
struct timeval time;
/* Lookup info necessary for processing this request. */
if (!(handler = ndmp_get_handler(connection, message))) {
- NDMP_LOG(LOG_DEBUG, "Sending message 0x%x: not supported",
+ syslog(LOG_ERR, "Sending message 0x%x: not supported",
message);
return (-1);
}
(void) gettimeofday(&time, 0);
@@ -435,29 +445,28 @@
header.reply_sequence = 0;
header.error = err;
connection->conn_xdrs.x_op = XDR_ENCODE;
if (!xdr_ndmp_header(&connection->conn_xdrs, &header)) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"Sending message 0x%x: encoding request header", message);
(void) xdrrec_endofrecord(&connection->conn_xdrs, 1);
return (-1);
}
if (err == NDMP_NO_ERR && handler->mh_xdr_request && request_data) {
if (!(*handler->mh_xdr_request)(&connection->conn_xdrs,
request_data)) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"Sending message 0x%x: encoding request body",
message);
(void) xdrrec_endofrecord(&connection->conn_xdrs, 1);
return (-1);
}
}
(void) xdrrec_endofrecord(&connection->conn_xdrs, 1);
if (handler->mh_xdr_reply == 0) {
- NDMP_LOG(LOG_DEBUG, "handler->mh_xdr_reply == 0");
return (0);
}
/*
* Process messages until the reply to this request has been
@@ -476,11 +485,11 @@
/* reply received? */
if (r == 1) {
if (message !=
connection->conn_msginfo.mi_hdr.message) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"Received unexpected reply 0x%x",
connection->conn_msginfo.mi_hdr.message);
ndmp_free_message(connection_handle);
return (-1);
}
@@ -569,11 +578,11 @@
header.reply_sequence = connection->conn_msginfo.mi_hdr.sequence;
header.error = err;
connection->conn_xdrs.x_op = XDR_ENCODE;
if (!xdr_ndmp_header(&connection->conn_xdrs, &header)) {
- NDMP_LOG(LOG_DEBUG, "Sending message 0x%x: "
+ syslog(LOG_ERR, "Sending message 0x%x: "
"encoding reply header",
header.message);
(void) xdrrec_endofrecord(&connection->conn_xdrs, 1);
return (-1);
}
@@ -580,11 +589,11 @@
if (err == NDMP_NO_ERR &&
connection->conn_msginfo.mi_handler->mh_xdr_reply &&
reply) {
if (!(*connection->conn_msginfo.mi_handler->mh_xdr_reply)(
&connection->conn_xdrs, reply)) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"Sending message 0x%x: encoding reply body",
header.message);
(void) xdrrec_endofrecord(&connection->conn_xdrs, 1);
return (-1);
}
@@ -856,31 +865,29 @@
req.protocol_version = ndmp_ver;
req.text_reason = "";
if (ndmp_send_request_lock(connection, NDMP_NOTIFY_CONNECTION_STATUS,
NDMP_NO_ERR, (void *)&req, 0) < 0) {
- NDMP_LOG(LOG_DEBUG, "Connection terminated");
+ syslog(LOG_DEBUG, "Send CONNECTION STATUS failed");
return;
}
connection_fd = ndmp_get_fd(connection);
- NDMP_LOG(LOG_DEBUG, "connection_fd: %d", connection_fd);
-
/*
* Add the handler function for the connection to the DMA.
*/
if (ndmpd_add_file_handler(&session, (void *)&session, connection_fd,
NDMPD_SELECT_MODE_READ, HC_CLIENT, connection_file_handler) != 0) {
- NDMP_LOG(LOG_DEBUG, "Could not register session handler.");
+ syslog(LOG_ERR, "Could not register session handler.");
return;
}
/*
* Register the connection in the list of active connections.
*/
if (ndmp_connect_list_add(connection, &conn_id) != 0) {
- NDMP_LOG(LOG_ERR,
+ syslog(LOG_ERR,
"Could not register the session to the server.");
(void) ndmpd_remove_file_handler(&session, connection_fd);
return;
}
@@ -889,22 +896,20 @@
while (session.ns_eof == FALSE)
(void) ndmpd_select(&session, TRUE, HC_ALL);
hardlink_q_cleanup(session.hardlink_q);
- NDMP_LOG(LOG_DEBUG, "Connection terminated");
-
(void) ndmpd_remove_file_handler(&session, connection_fd);
if (session.ns_scsi.sd_is_open != -1) {
- NDMP_LOG(LOG_DEBUG, "scsi.is_open: %d",
+ syslog(LOG_ERR, "scsi.is_open: %d",
session.ns_scsi.sd_is_open);
(void) ndmp_open_list_del(session.ns_scsi.sd_adapter_name,
session.ns_scsi.sd_sid, session.ns_scsi.sd_lun);
}
if (session.ns_tape.td_fd != -1) {
- NDMP_LOG(LOG_DEBUG, "tape.fd: %d", session.ns_tape.td_fd);
+ syslog(LOG_ERR, "tape.fd: %d", session.ns_tape.td_fd);
(void) close(session.ns_tape.td_fd);
(void) ndmp_open_list_del(session.ns_tape.td_adapter_name,
session.ns_tape.td_sid, session.ns_tape.td_lun);
}
ndmpd_mover_shut_down(&session);
@@ -1032,11 +1037,11 @@
return (-1);
/* Lookup info necessary for processing this message. */
if ((connection->conn_msginfo.mi_handler = ndmp_get_handler(connection,
connection->conn_msginfo.mi_hdr.message)) == 0) {
- NDMP_LOG(LOG_DEBUG, "Message 0x%x not supported",
+ syslog(LOG_DEBUG, "Message 0x%x not supported",
connection->conn_msginfo.mi_hdr.message);
return (NDMP_NOT_SUPPORTED_ERR);
}
connection->conn_msginfo.mi_body = 0;
@@ -1047,21 +1052,21 @@
if (connection->conn_msginfo.mi_hdr.message_type ==
NDMP_MESSAGE_REQUEST) {
if (ndmp_check_auth_required(
connection->conn_msginfo.mi_hdr.message) &&
!connection->conn_authorized) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"Processing request 0x%x:connection not authorized",
connection->conn_msginfo.mi_hdr.message);
return (NDMP_NOT_AUTHORIZED_ERR);
}
if (connection->conn_msginfo.mi_handler->mh_sizeof_request >
0) {
xdr_func =
connection->conn_msginfo.mi_handler->mh_xdr_request;
if (xdr_func == NULL) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"Processing request 0x%x: no xdr function "
"in handler table",
connection->conn_msginfo.mi_hdr.message);
return (NDMP_NOT_SUPPORTED_ERR);
}
@@ -1078,11 +1083,11 @@
} else {
if (connection->conn_msginfo.mi_handler->mh_sizeof_reply > 0) {
xdr_func =
connection->conn_msginfo.mi_handler->mh_xdr_reply;
if (xdr_func == NULL) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"Processing reply 0x%x: no xdr function "
"in handler table",
connection->conn_msginfo.mi_hdr.message);
return (NDMP_NOT_SUPPORTED_ERR);
}
@@ -1100,12 +1105,16 @@
/* Decode message arguments if needed */
if (xdr_func) {
if (!(*xdr_func)(&connection->conn_xdrs,
connection->conn_msginfo.mi_body)) {
- NDMP_LOG(LOG_DEBUG,
- "Processing message 0x%x: error decoding arguments",
+ syslog(LOG_ERR,
+ "Processing %s message 0x%x: "
+ "error decoding arguments",
+ connection->conn_msginfo.mi_hdr.message_type ==
+ NDMP_MESSAGE_REQUEST ?
+ "Request" : "Reply",
connection->conn_msginfo.mi_hdr.message);
free(connection->conn_msginfo.mi_body);
connection->conn_msginfo.mi_body = 0;
return (NDMP_XDR_DECODE_ERR);
}
@@ -1166,26 +1175,22 @@
msg_info_t reply_msginfo;
boolean_t reply_read = FALSE;
boolean_t reply_error = FALSE;
int err;
- NDMP_LOG(LOG_DEBUG, "reply_expected: %s",
- reply_expected == TRUE ? "TRUE" : "FALSE");
-
(void) memset((void *)&reply_msginfo, 0, sizeof (msg_info_t));
do {
(void) memset((void *)&connection->conn_msginfo, 0,
sizeof (msg_info_t));
if ((err = ndmp_recv_msg(connection)) != NDMP_NO_ERR) {
if (connection->conn_eof) {
- NDMP_LOG(LOG_DEBUG, "detected eof");
return (NDMP_PROC_ERR);
}
if (err < 1) {
- NDMP_LOG(LOG_DEBUG, "error decoding header");
+ syslog(LOG_ERR, "error decoding header");
/*
* Error occurred decoding the header.
* Don't send a reply since we don't know
* the message or if the message was even
@@ -1202,16 +1207,16 @@
continue;
}
if (connection->conn_msginfo.mi_hdr.message_type
!= NDMP_MESSAGE_REQUEST) {
- NDMP_LOG(LOG_DEBUG, "received reply: 0x%x",
+ syslog(LOG_DEBUG, "received reply: 0x%x",
connection->conn_msginfo.mi_hdr.message);
if (reply_expected == FALSE ||
reply_read == TRUE)
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"Unexpected reply message: 0x%x",
connection->conn_msginfo.mi_hdr.
message);
ndmp_free_message((ndmp_connection_t *)
@@ -1221,25 +1226,23 @@
reply_read = TRUE;
reply_error = TRUE;
}
continue;
}
- NDMP_LOG(LOG_DEBUG, "received request: 0x%x",
- connection->conn_msginfo.mi_hdr.message);
(void) ndmp_send_response((ndmp_connection_t *)
connection, err, NULL);
ndmp_free_message((ndmp_connection_t *)connection);
continue;
}
if (connection->conn_msginfo.mi_hdr.message_type
!= NDMP_MESSAGE_REQUEST) {
- NDMP_LOG(LOG_DEBUG, "received reply: 0x%x",
+ syslog(LOG_DEBUG, "received reply: 0x%x",
connection->conn_msginfo.mi_hdr.message);
if (reply_expected == FALSE || reply_read == TRUE) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"Unexpected reply message: 0x%x",
connection->conn_msginfo.mi_hdr.message);
ndmp_free_message((ndmp_connection_t *)
connection);
continue;
@@ -1246,20 +1249,17 @@
}
reply_read = TRUE;
reply_msginfo = connection->conn_msginfo;
continue;
}
- NDMP_LOG(LOG_DEBUG, "received request: 0x%x",
- connection->conn_msginfo.mi_hdr.message);
-
/*
* The following is needed to catch an improperly constructed
* handler table or to deal with an NDMP client that is not
* conforming to the negotiated protocol version.
*/
if (connection->conn_msginfo.mi_handler->mh_func == NULL) {
- NDMP_LOG(LOG_DEBUG, "No handler for message 0x%x",
+ syslog(LOG_DEBUG, "No handler for message 0x%x",
connection->conn_msginfo.mi_hdr.message);
(void) ndmp_send_response((ndmp_connection_t *)
connection, NDMP_NOT_SUPPORTED_ERR, NULL);
ndmp_free_message((ndmp_connection_t *)connection);
@@ -1275,12 +1275,10 @@
ndmp_free_message((ndmp_connection_t *)connection);
} while (xdrrec_eof(&connection->conn_xdrs) == FALSE &&
connection->conn_eof == FALSE);
- NDMP_LOG(LOG_DEBUG, "no more messages in stream buffer");
-
if (connection->conn_eof == TRUE) {
if (reply_msginfo.mi_body)
free(reply_msginfo.mi_body);
return (NDMP_PROC_ERR);
}
@@ -1513,11 +1511,11 @@
char *path, int dest, char *local_path, int result)
{
adt_event_data_t *event;
if ((event = adt_alloc_event(conn->conn_ah, ADT_ndmp_backup)) == NULL) {
- NDMP_LOG(LOG_ERR, "Audit failure: %m.");
+ syslog(LOG_ERR, "Audit failure: %m.");
return;
}
event->adt_ndmp_backup.source = path;
if (dest == NDMP_ADDR_LOCAL) {
@@ -1526,14 +1524,14 @@
event->adt_ndmp_backup.remote_dest = conn->conn_sock;
}
if (result == 0) {
if (adt_put_event(event, ADT_SUCCESS, ADT_SUCCESS) != 0)
- NDMP_LOG(LOG_ERR, "Audit failure: %m.");
+ syslog(LOG_ERR, "Audit failure: %m.");
} else {
if (adt_put_event(event, ADT_FAILURE, result) != 0)
- NDMP_LOG(LOG_ERR, "Audit failure: %m.");
+ syslog(LOG_ERR, "Audit failure: %m.");
}
adt_free_event(event);
}
@@ -1550,11 +1548,11 @@
{
adt_event_data_t *event;
if ((event = adt_alloc_event(conn->conn_ah,
ADT_ndmp_restore)) == NULL) {
- NDMP_LOG(LOG_ERR, "Audit failure: %m.");
+ syslog(LOG_ERR, "Audit failure: %m.");
return;
}
event->adt_ndmp_restore.destination = path;
if (dest == NDMP_ADDR_LOCAL) {
@@ -1563,14 +1561,14 @@
event->adt_ndmp_restore.remote_source = conn->conn_sock;
}
if (result == 0) {
if (adt_put_event(event, ADT_SUCCESS, ADT_SUCCESS) != 0)
- NDMP_LOG(LOG_ERR, "Audit failure: %m.");
+ syslog(LOG_ERR, "Audit failure: %m.");
} else {
if (adt_put_event(event, ADT_FAILURE, result) != 0)
- NDMP_LOG(LOG_ERR, "Audit failure: %m.");
+ syslog(LOG_ERR, "Audit failure: %m.");
}
adt_free_event(event);
}
@@ -1586,34 +1584,34 @@
{
adt_event_data_t *event;
adt_termid_t *termid;
if (adt_load_termid(conn->conn_sock, &termid) != 0) {
- NDMP_LOG(LOG_ERR, "Audit failure: %m.");
+ syslog(LOG_ERR, "Audit failure: %m.");
return;
}
if (adt_set_user(conn->conn_ah, ADT_NO_ATTRIB, ADT_NO_ATTRIB,
ADT_NO_ATTRIB, ADT_NO_ATTRIB, termid, ADT_NEW) != 0) {
- NDMP_LOG(LOG_ERR, "Audit failure: %m.");
+ syslog(LOG_ERR, "Audit failure: %m.");
free(termid);
return;
}
free(termid);
if ((event = adt_alloc_event(conn->conn_ah,
ADT_ndmp_connect)) == NULL) {
- NDMP_LOG(LOG_ERR, "Audit failure: %m.");
+ syslog(LOG_ERR, "Audit failure: %m.");
return;
}
if (result == 0) {
if (adt_put_event(event, ADT_SUCCESS, ADT_SUCCESS) != 0)
- NDMP_LOG(LOG_ERR, "Audit failure: %m.");
+ syslog(LOG_ERR, "Audit failure: %m.");
} else {
if (adt_put_event(event, ADT_FAILURE, result) != 0)
- NDMP_LOG(LOG_ERR, "Audit failure: %m.");
+ syslog(LOG_ERR, "Audit failure: %m.");
}
adt_free_event(event);
}
@@ -1629,15 +1627,15 @@
{
adt_event_data_t *event;
if ((event = adt_alloc_event(conn->conn_ah,
ADT_ndmp_disconnect)) == NULL) {
- NDMP_LOG(LOG_ERR, "Audit failure: %m.");
+ syslog(LOG_ERR, "Audit failure: %m.");
return;
}
if (adt_put_event(event, ADT_SUCCESS, ADT_SUCCESS) != 0)
- NDMP_LOG(LOG_ERR, "Audit failure: %m.");
+ syslog(LOG_ERR, "Audit failure: %m.");
adt_free_event(event);
}
void *
@@ -1644,11 +1642,11 @@
ndmp_malloc(size_t size)
{
void *data;
if ((data = calloc(1, size)) == NULL) {
- NDMP_LOG(LOG_ERR, "Out of memory.");
+ syslog(LOG_ERR, "Out of memory.");
}
return (data);
}
@@ -1676,11 +1674,11 @@
if (!bkpath) {
MOD_LOGV3(params, NDMP_LOG_ERROR,
"Backup path not defined.\n");
} else {
- NDMP_LOG(LOG_DEBUG, "bkpath: \"%s\"", bkpath);
+ syslog(LOG_DEBUG, "bkpath: \"%s\"", bkpath);
}
return (bkpath);
}