Print this page
NEX-9532 NDMP: readdir errors when file/directory has special characters
Reviewed by: Peer Dampmann <peer.dampmann@nexenta.com>
Reviewed by: Alexander Eremin <alexander.eremin@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
NEX-5801 Snapshots left over after failed backups
Reviewed by: Rick Mesta <rick.mesta@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Revert "NEX-5801 Snapshots left over after failed backups"
This reverts commit f182fb95f09036db71fbfc6f0a6b90469b761f21.
NEX-5801 Snapshots left over after failed backups
Reviewed by: Rick Mesta <rick.mesta@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-2911 NDMP logging should use syslog and is too chatty
NEX-799 past last file mark returned NDMP_IO_ERR, should be NDMP_EOM_ERR (V4+)
NEX-812 NDMP backup terminate after hit the EOM in Netbackup backup
NEX-355 NDMP backup, EOF position remains on BOT side of filemark
NEX-249 NS ndmp can't write to a brand new tape with IO error (fix cstyle)
SUP-484 NDMP backup jobs error out when reaching the end of media (EOM)
NEX-249 NS ndmp can't write to a brand new tape with IO error
@@ -35,13 +35,14 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* 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/param.h>
+#include <syslog.h>
#include <fcntl.h>
#include <sys/mtio.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
@@ -113,27 +114,25 @@
char adptnm[SCSI_MAX_NAME];
int mode;
int sid, lun;
int err;
scsi_adapter_t *sa;
- int devid;
+ int devid = -1;
err = NDMP_NO_ERR;
if (session->ns_tape.td_fd != -1 || session->ns_scsi.sd_is_open != -1) {
- NDMP_LOG(LOG_INFO,
+ syslog(LOG_INFO,
"Connection already has a tape or scsi device open");
err = NDMP_DEVICE_OPENED_ERR;
} else if (request->mode != NDMP_TAPE_READ_MODE &&
request->mode != NDMP_TAPE_WRITE_MODE &&
request->mode != NDMP_TAPE_RAW1_MODE) {
err = NDMP_ILLEGAL_ARGS_ERR;
}
if ((sa = scsi_get_adapter(0)) != NULL) {
- NDMP_LOG(LOG_DEBUG,
- "Adapter device opened: %s", request->device.name);
(void) strlcpy(adptnm, request->device.name, SCSI_MAX_NAME-2);
adptnm[SCSI_MAX_NAME-1] = '\0';
sid = lun = -1;
}
/* try to get the scsi id etc.... */
@@ -140,18 +139,18 @@
if (sa) {
scsi_find_sid_lun(sa, request->device.name, &sid, &lun);
if (ndmp_open_list_find(request->device.name, sid, lun) == 0 &&
(devid = tape_open(request->device.name,
O_RDWR | O_NDELAY)) < 0) {
- NDMP_LOG(LOG_ERR, "Failed to open device %s: %m.",
+ syslog(LOG_ERR, "Failed to open device %s: %m.",
request->device.name);
err = NDMP_NO_DEVICE_ERR;
}
else
(void) close(devid);
} else {
- NDMP_LOG(LOG_ERR, "%s: No such tape device.",
+ syslog(LOG_ERR, "%s: No such tape device.",
request->device.name);
err = NDMP_NO_DEVICE_ERR;
}
if (err != NDMP_NO_ERR) {
tape_open_send_reply(connection, err);
@@ -190,11 +189,11 @@
}
mode = (request->mode == NDMP_TAPE_READ_MODE) ? O_RDONLY : O_RDWR;
mode |= O_NDELAY;
if ((session->ns_tape.td_fd = open(request->device.name, mode)) < 0) {
- NDMP_LOG(LOG_ERR, "Failed to open tape device %s: %m.",
+ syslog(LOG_ERR, "Failed to open tape device %s: %m.",
request->device.name);
switch (errno) {
case EACCES:
err = NDMP_WRITE_PROTECT_ERR;
break;
@@ -218,12 +217,10 @@
session->ns_tape.td_sid = sid;
session->ns_tape.td_lun = lun;
(void) strlcpy(session->ns_tape.td_adapter_name, adptnm, SCSI_MAX_NAME);
session->ns_tape.td_record_count = 0;
- NDMP_LOG(LOG_DEBUG, "Tape is opened fd: %d", session->ns_tape.td_fd);
-
tape_open_send_reply(connection, NDMP_NO_ERR);
}
/*
@@ -244,11 +241,11 @@
{
ndmp_tape_close_reply reply;
ndmpd_session_t *session = ndmp_get_client_data(connection);
if (session->ns_tape.td_fd == -1) {
- NDMP_LOG(LOG_ERR, "Tape device is not open.");
+ syslog(LOG_ERR, "Tape device is not open.");
reply.error = NDMP_DEV_NOT_OPEN_ERR;
ndmp_send_reply(connection, (void *) &reply,
"sending tape_close reply");
return;
}
@@ -279,32 +276,30 @@
struct mtget mtstatus;
struct mtdrivetype_request dtpr;
struct mtdrivetype dtp;
if (session->ns_tape.td_fd == -1) {
- NDMP_LOG(LOG_ERR, "Tape device is not open.");
+ syslog(LOG_ERR, "Tape device is not open.");
reply.error = NDMP_DEV_NOT_OPEN_ERR;
ndmp_send_reply(connection, (void *) &reply,
"sending tape_get_state reply");
return;
}
if (ioctl(session->ns_tape.td_fd, MTIOCGET, &mtstatus) < 0) {
- NDMP_LOG(LOG_ERR, "Failed to get status from tape: %m.");
- NDMP_LOG(LOG_DEBUG, "ioctl(MTIOCGET) error: %m.");
+ syslog(LOG_ERR, "Failed to get status from tape: %m.");
reply.error = NDMP_IO_ERR;
ndmp_send_reply(connection, (void *)&reply,
"sending tape_get_state reply");
return;
}
dtpr.size = sizeof (struct mtdrivetype);
dtpr.mtdtp = &dtp;
if (ioctl(session->ns_tape.td_fd, MTIOCGETDRIVETYPE, &dtpr) == -1) {
- NDMP_LOG(LOG_ERR,
+ syslog(LOG_ERR,
"Failed to get drive type information from tape: %m.");
- NDMP_LOG(LOG_DEBUG, "ioctl(MTIOCGETDRIVETYPE) error: %m.");
reply.error = NDMP_IO_ERR;
ndmp_send_reply(connection, (void *)&reply,
"sending tape_get_state reply");
return;
}
@@ -322,14 +317,10 @@
reply.soft_errors = 0;
reply.total_space = long_long_to_quad(0); /* not supported */
reply.space_remain = long_long_to_quad(0); /* not supported */
- NDMP_LOG(LOG_DEBUG,
- "flags: 0x%x, file_num: %d, block_size: %d, blockno: %d",
- reply.flags, reply.file_num, reply.block_size, reply.blockno);
-
reply.error = NDMP_NO_ERR;
ndmp_send_reply(connection, (void *) &reply,
"sending tape_get_state reply");
}
@@ -359,11 +350,11 @@
int rc;
reply.resid_count = 0;
if (session->ns_tape.td_fd == -1) {
- NDMP_LOG(LOG_ERR, "Tape device is not open.");
+ syslog(LOG_ERR, "Tape device is not open.");
reply.error = NDMP_DEV_NOT_OPEN_ERR;
ndmp_send_reply(connection, (void *) &reply,
"sending tape_mtio reply");
return;
}
@@ -412,13 +403,10 @@
do {
NS_UPD(twait, trun);
errno = 0;
rc = ioctl(session->ns_tape.td_fd, MTIOCTOP, &tapeop);
NS_UPD(trun, twait);
- NDMP_LOG(LOG_DEBUG,
- "ioctl MTIO rc:%d, cmd:%d, retry:%d, error: %d",
- rc, tapeop.mt_op, retry, errno);
} while (rc < 0 && errno == EIO &&
retry++ < 5);
/*
* Ignore I/O errors since these usually are the result of
@@ -425,13 +413,12 @@
* attempting to position past the beginning or end of the tape.
* The residual count will be returned and can be used to
* determine that the call was not completely successful.
*/
if (rc < 0) {
- NDMP_LOG(LOG_ERR,
+ syslog(LOG_ERR,
"Failed to send command to tape: %m.");
- NDMP_LOG(LOG_DEBUG, "ioctl(MTIOCTOP) error: %m.");
/* MTWEOF doesnt have residual count */
if (tapeop.mt_op == MTWEOF)
reply.error = NDMP_IO_ERR;
else
@@ -444,14 +431,12 @@
if (request->tape_op != NDMP_MTIO_REW &&
request->tape_op != NDMP_MTIO_OFF) {
if (ioctl(session->ns_tape.td_fd, MTIOCGET,
&mtstatus) < 0) {
- NDMP_LOG(LOG_ERR,
+ syslog(LOG_ERR,
"Failed to send command to tape: %m.");
- NDMP_LOG(LOG_DEBUG,
- "ioctl(MTIOCGET) error: %m.");
reply.error = NDMP_IO_ERR;
ndmp_send_reply(connection, (void *)&reply,
"sending tape_mtio reply");
return;
@@ -459,12 +444,10 @@
reply.resid_count = labs(mtstatus.mt_resid);
}
}
- NDMP_LOG(LOG_DEBUG, "resid_count: %d",
- reply.resid_count);
ndmp_send_reply(connection, (void *) &reply, "sending tape_mtio reply");
}
/*
@@ -497,11 +480,11 @@
char *buf;
reply.data_in.data_in_len = 0;
if (session->ns_tape.td_fd == -1) {
- NDMP_LOG(LOG_ERR, "Tape device is not open.");
+ syslog(LOG_ERR, "Tape device is not open.");
reply.error = NDMP_DEV_NOT_OPEN_ERR;
ndmp_send_reply(connection, (void *)&reply,
"sending tape_read reply");
return;
}
@@ -547,11 +530,11 @@
request = (ndmp_tape_execute_cdb_request *) body;
if (session->ns_tape.td_fd == -1) {
(void) memset((void *) &reply, 0, sizeof (reply));
- NDMP_LOG(LOG_ERR, "Tape device is not open.");
+ syslog(LOG_ERR, "Tape device is not open.");
reply.error = NDMP_DEV_NOT_OPEN_ERR;
ndmp_send_reply(connection, (void *) &reply,
"sending tape_execute_cdb reply");
} else {
ndmp_execute_cdb(session, session->ns_tape.td_adapter_name,
@@ -610,20 +593,19 @@
struct mtdrivetype_request dtpr;
struct mtdrivetype dtp;
struct mtget mtstatus;
if (session->ns_tape.td_fd == -1) {
- NDMP_LOG(LOG_ERR, "Tape device is not open.");
+ syslog(LOG_ERR, "Tape device is not open.");
reply.error = NDMP_DEV_NOT_OPEN_ERR;
ndmp_send_reply(connection, (void *) &reply,
"sending tape_get_state reply");
return;
}
if (ioctl(session->ns_tape.td_fd, MTIOCGET, &mtstatus) == -1) {
- NDMP_LOG(LOG_ERR, "Failed to get status from tape: %m.");
- NDMP_LOG(LOG_DEBUG, "ioctl(MTIOCGET) error: %m.");
+ syslog(LOG_ERR, "Failed to get status from tape: %m.");
reply.error = NDMP_IO_ERR;
ndmp_send_reply(connection, (void *)&reply,
"sending tape_get_state reply");
return;
@@ -630,13 +612,12 @@
}
dtpr.size = sizeof (struct mtdrivetype);
dtpr.mtdtp = &dtp;
if (ioctl(session->ns_tape.td_fd, MTIOCGETDRIVETYPE, &dtpr) == -1) {
- NDMP_LOG(LOG_ERR,
+ syslog(LOG_ERR,
"Failed to get drive type information from tape: %m.");
- NDMP_LOG(LOG_DEBUG, "ioctl(MTIOCGETDRIVETYPE) error: %m.");
reply.error = NDMP_IO_ERR;
ndmp_send_reply(connection, (void *)&reply,
"sending tape_get_state reply");
return;
@@ -663,14 +644,10 @@
reply.invalid = NDMP_TAPE_STATE_SOFT_ERRORS_INVALID |
NDMP_TAPE_STATE_TOTAL_SPACE_INVALID |
NDMP_TAPE_STATE_SPACE_REMAIN_INVALID |
NDMP_TAPE_STATE_PARTITION_INVALID;
-
- NDMP_LOG(LOG_DEBUG, "f 0x%x, fnum %d, bsize %d, bno: %d",
- reply.flags, reply.file_num, reply.block_size, reply.blockno);
-
reply.error = NDMP_NO_ERR;
ndmp_send_reply(connection, (void *) &reply,
"sending tape_get_state reply");
}
@@ -762,18 +739,18 @@
ndmp_get_client_data(connection); ssize_t n;
reply.count = 0;
if (session->ns_tape.td_fd == -1) {
- NDMP_LOG(LOG_ERR, "Tape device is not open.");
+ syslog(LOG_ERR, "Tape device is not open.");
reply.error = NDMP_DEV_NOT_OPEN_ERR;
ndmp_send_reply(connection, (void *) &reply,
"sending tape_write reply");
return;
}
if (session->ns_tape.td_mode == NDMP_TAPE_READ_MODE) {
- NDMP_LOG(LOG_INFO, "Tape device opened in read-only mode");
+ syslog(LOG_INFO, "Tape device opened in read-only mode");
reply.error = NDMP_PERMISSION_ERR;
ndmp_send_reply(connection, (void *) &reply,
"sending tape_write reply");
return;
}
@@ -800,22 +777,22 @@
n = write(session->ns_tape.td_fd, request->data_out.data_out_val,
request->data_out.data_out_len);
if (n < 0) {
- NDMP_LOG(LOG_ERR, "Tape write error: %m.");
+ syslog(LOG_ERR, "Tape write error: %m.");
reply.error = NDMP_IO_ERR;
} else if (n == 0) {
- NDMP_LOG(LOG_INFO, "EOM detected");
+ syslog(LOG_INFO, "EOM detected");
reply.error = NDMP_EOM_ERR;
} else {
NS_ADD(wtape, n);
reply.count = n;
reply.error = NDMP_NO_ERR;
if (n < request->data_out.data_out_len)
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"EOM is coming (partial write of %d bytes)", n);
}
ndmp_send_reply(connection, (void *) &reply,
"sending tape_write reply");
@@ -851,11 +828,11 @@
int n;
reply.data_in.data_in_len = 0;
if (session->ns_tape.td_fd == -1) {
- NDMP_LOG(LOG_ERR, "Tape device is not open.");
+ syslog(LOG_ERR, "Tape device is not open.");
reply.error = NDMP_DEV_NOT_OPEN_ERR;
ndmp_send_reply(connection, (void *) &reply,
"sending tape_read reply");
return;
}
@@ -899,32 +876,32 @@
/*
* If at beginning of file and read fails with EIO, then it's
* repeated attempt to read at EOT.
*/
else if (errno == EIO && tape_is_at_bof(session)) {
- NDMP_LOG(LOG_DEBUG, "Repeated read at EOT");
+ syslog(LOG_DEBUG, "Repeated read at EOT");
reply.error = NDMP_EOM_ERR;
}
/*
* According to NDMPv4 spec preferred error code when
* trying to read from blank tape is NDMP_EOM_ERR.
*/
else if (errno == EIO && tape_is_at_bot(session)) {
- NDMP_LOG(LOG_ERR, "Blank tape detected, returning EOM");
+ syslog(LOG_ERR, "Blank tape detected, returning EOM");
reply.error = NDMP_EOM_ERR;
} else {
- NDMP_LOG(LOG_ERR, "Tape read error: %m.");
+ syslog(LOG_ERR, "Tape read error: %m.");
reply.error = NDMP_IO_ERR;
}
} else if (n == 0) {
if (tape_is_at_bof(session)) {
- NDMP_LOG(LOG_DEBUG, "EOT detected");
+ syslog(LOG_DEBUG, "EOT detected");
reply.error = NDMP_EOM_ERR;
} else {
/* reposition the tape to BOT side of FM */
fm_dance(session);
- NDMP_LOG(LOG_DEBUG, "EOF detected");
+ syslog(LOG_DEBUG, "EOF detected");
reply.error = NDMP_EOF_ERR;
}
} else {
session->ns_tape.td_pos += n;
reply.data_in.data_in_len = n;
@@ -966,11 +943,11 @@
struct mtget mtstatus;
struct mtdrivetype_request dtpr;
struct mtdrivetype dtp;
if (session->ns_tape.td_fd == -1) {
- NDMP_LOG(LOG_ERR, "Tape device is not open.");
+ syslog(LOG_ERR, "Tape device is not open.");
reply.error = NDMP_DEV_NOT_OPEN_ERR;
ndmp_send_reply(connection, (void *) &reply,
"sending tape_get_state reply");
return;
}
@@ -978,13 +955,12 @@
/*
* Need code to detect NDMP_TAPE_STATE_NOREWIND
*/
if (ioctl(session->ns_tape.td_fd, MTIOCGET, &mtstatus) == -1) {
- NDMP_LOG(LOG_ERR,
+ syslog(LOG_ERR,
"Failed to get status information from tape: %m.");
- NDMP_LOG(LOG_DEBUG, "ioctl(MTIOCGET) error: %m.");
reply.error = NDMP_IO_ERR;
ndmp_send_reply(connection, (void *)&reply,
"sending tape_get_state reply");
return;
@@ -991,13 +967,12 @@
}
dtpr.size = sizeof (struct mtdrivetype);
dtpr.mtdtp = &dtp;
if (ioctl(session->ns_tape.td_fd, MTIOCGETDRIVETYPE, &dtpr) == -1) {
- NDMP_LOG(LOG_ERR,
+ syslog(LOG_ERR,
"Failed to get drive type information from tape: %m.");
- NDMP_LOG(LOG_DEBUG, "ioctl(MTIOCGETDRIVETYPE) error: %m.");
reply.error = NDMP_IO_ERR;
ndmp_send_reply(connection, (void *)&reply,
"sending tape_get_state reply");
return;
@@ -1021,13 +996,10 @@
reply.unsupported = NDMP_TAPE_STATE_SOFT_ERRORS_INVALID |
NDMP_TAPE_STATE_TOTAL_SPACE_INVALID |
NDMP_TAPE_STATE_SPACE_REMAIN_INVALID |
NDMP_TAPE_STATE_PARTITION_INVALID;
- NDMP_LOG(LOG_DEBUG, "f 0x%x, fnum %d, bsize %d, bno: %d",
- reply.flags, reply.file_num, reply.block_size, reply.blockno);
-
reply.error = NDMP_NO_ERR;
ndmp_send_reply(connection, (void *) &reply,
"sending tape_get_state reply");
}
/*
@@ -1048,11 +1020,11 @@
{
ndmp_tape_close_reply reply;
ndmpd_session_t *session = ndmp_get_client_data(connection);
if (session->ns_tape.td_fd == -1) {
- NDMP_LOG(LOG_ERR, "Tape device is not open.");
+ syslog(LOG_ERR, "Tape device is not open.");
reply.error = NDMP_DEV_NOT_OPEN_ERR;
ndmp_send_reply(connection, (void *) &reply,
"sending tape_close reply");
return;
}
@@ -1127,27 +1099,23 @@
* of spanned data between the tapes.
*/
if (errno == ENOSPC) {
reply->error = NDMP_EOF_ERR;
} else {
- NDMP_LOG(LOG_ERR, "Tape read error: %m.");
+ syslog(LOG_ERR, "Tape read error: %m.");
reply->error = NDMP_IO_ERR;
}
} else if (n == 0) {
- NDMP_LOG(LOG_DEBUG, "NDMP_EOF_ERR");
-
reply->error = NDMP_EOF_ERR;
(void) ndmp_mtioctl(session->ns_tape.td_fd, MTFSF, 1);
len = strlen(NDMP_EOM_MAGIC);
(void) memset(buf, 0, len);
n = read(session->ns_tape.td_fd, buf, len);
buf[len] = '\0';
- NDMP_LOG(LOG_DEBUG, "Checking EOM: nread %d [%s]", n, buf);
-
(void) ndmp_mtioctl(session->ns_tape.td_fd, MTBSF, 1);
if (strncmp(buf, NDMP_EOM_MAGIC, len) != 0)
(void) ndmp_mtioctl(session->ns_tape.td_fd, MTFSF, 1);
} else {
@@ -1205,38 +1173,37 @@
char adptnm[SCSI_MAX_NAME];
int err;
int mode;
int sid, lun;
scsi_adapter_t *sa;
- int devid;
+ int devid = -1;
err = NDMP_NO_ERR;
if (session->ns_tape.td_fd != -1 || session->ns_scsi.sd_is_open != -1) {
- NDMP_LOG(LOG_INFO,
+ syslog(LOG_INFO,
"Connection already has a tape or scsi device open");
err = NDMP_DEVICE_OPENED_ERR;
} else if (!validmode(ndmpmode))
err = NDMP_ILLEGAL_ARGS_ERR;
if ((sa = scsi_get_adapter(0)) != NULL) {
- NDMP_LOG(LOG_DEBUG, "Adapter device opened: %s", devname);
(void) strlcpy(adptnm, devname, SCSI_MAX_NAME-2);
adptnm[SCSI_MAX_NAME-1] = '\0';
sid = lun = -1;
}
if (sa) {
scsi_find_sid_lun(sa, devname, &sid, &lun);
if (ndmp_open_list_find(devname, sid, lun) == 0 &&
(devid = open(devname, O_RDWR | O_NDELAY)) < 0) {
- NDMP_LOG(LOG_ERR,
+ syslog(LOG_ERR,
"Failed to open device %s: %m.", devname);
err = NDMP_NO_DEVICE_ERR;
} else {
(void) close(devid);
}
} else {
- NDMP_LOG(LOG_ERR, "%s: No such tape device.", devname);
+ syslog(LOG_ERR, "%s: No such tape device.", devname);
err = NDMP_NO_DEVICE_ERR;
}
if (err != NDMP_NO_ERR) {
tape_open_send_reply(connection, err);
@@ -1267,11 +1234,11 @@
*/
ndmpmode = NDMP_TAPE_READ_MODE;
session->ns_tape.td_fd = open(devname, O_RDONLY);
}
if (session->ns_tape.td_fd < 0) {
- NDMP_LOG(LOG_ERR, "Failed to open tape device %s: %m.",
+ syslog(LOG_ERR, "Failed to open tape device %s: %m.",
devname);
switch (errno) {
case EACCES:
err = NDMP_WRITE_PROTECT_ERR;
break;
@@ -1315,12 +1282,10 @@
session->ns_tape.td_sid = sid;
session->ns_tape.td_lun = lun;
(void) strlcpy(session->ns_tape.td_adapter_name, adptnm, SCSI_MAX_NAME);
session->ns_tape.td_record_count = 0;
- NDMP_LOG(LOG_DEBUG, "Tape is opened fd: %d", session->ns_tape.td_fd);
-
tape_open_send_reply(connection, NDMP_NO_ERR);
}
/*