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-2911 NDMP logging should use syslog and is too chatty
*** 34,43 ****
--- 34,46 ----
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
+ /* Copyright 2017 Nexenta Systems, Inc. All rights reserved. */
+
+ #include <syslog.h>
#include <stdio.h>
#include <limits.h>
#include <time.h>
#include <sys/stat.h>
#include <unistd.h>
*** 113,123 ****
/*
* Send the node or path history of the directory itself.
*/
pos = tlm_get_data_offset(local_commands);
- NDMP_LOG(LOG_DEBUG, "pos: %10lld [%s]", pos, name);
(void) tlm_log_fhnode(job_stats, name, "", &tlm_acls->acl_attr, pos);
(void) tlm_log_fhpath_name(job_stats, name, &tlm_acls->acl_attr, pos);
/* fhdir_cb is handled in ndmpd_tar3.c */
(void) output_acl_header(&tlm_acls->acl_info,
--- 116,125 ----
*** 255,265 ****
if (section_name == NULL)
return (-TLM_NO_SCRATCH_SPACE);
if (fstat64(fd, attr) == -1) {
! NDMP_LOG(LOG_DEBUG, "output_file_header stat failed.");
free(section_name);
return (-TLM_OPEN_ERR);
}
/*
--- 257,267 ----
if (section_name == NULL)
return (-TLM_NO_SCRATCH_SPACE);
if (fstat64(fd, attr) == -1) {
! syslog(LOG_ERR, "output_file_header stat failed.");
free(section_name);
return (-TLM_OPEN_ERR);
}
/*
*** 298,310 ****
(void) snprintf(tar_hdr->th_mtime, sizeof (tar_hdr->th_mtime), "%011o ",
attr->st_mtime);
(void) strlcpy(tar_hdr->th_magic, TLM_MAGIC,
sizeof (tar_hdr->th_magic));
- NDMP_LOG(LOG_DEBUG, "xattr_hdr: %s size %d mode %06o uid %d gid %d",
- aname, hsize, attr->st_mode & 07777, attr->st_uid, attr->st_gid);
-
tlm_build_header_checksum(tar_hdr);
xhdr = (struct xattr_hdr *)get_write_buffer(RECORDSIZE,
&actual_size, TRUE, local_commands);
if (!xhdr) {
--- 300,309 ----
*** 486,498 ****
file_count++);
} else {
(void) strlcpy(tar_hdr->th_name, section_name, TLM_NAME_SIZE);
}
- NDMP_LOG(LOG_DEBUG, "long_link: %s [%s]", long_link ? "TRUE" : "FALSE",
- link);
-
if (long_link) {
(void) snprintf(tar_hdr->th_linkname,
sizeof (tar_hdr->th_name),
"%s%08qd.slk",
LONGNAME_PREFIX,
--- 485,494 ----
*** 528,539 ****
sizeof (tar_hdr->th_shared.th_hlink_ino),
"%011llo ", attr->st_ino);
} else {
tar_hdr->th_linkflag = *link == 0 ? LF_NORMAL :
LF_SYMLINK;
- NDMP_LOG(LOG_DEBUG, "linkflag: '%c'",
- tar_hdr->th_linkflag);
}
}
(void) snprintf(tar_hdr->th_size, sizeof (tar_hdr->th_size), "%011o ",
(long)attr->st_size);
(void) snprintf(tar_hdr->th_mode, sizeof (tar_hdr->th_mode), "%06o ",
--- 524,533 ----
*** 578,588 ****
* realink(2) doesn't null terminate the link name. We must
* do it here.
*/
buf[len] = '\0';
} else {
! NDMP_LOG(LOG_DEBUG, "Error %d reading softlink of [%s]",
errno, nm);
buf[0] = '\0';
/* Backup the link if the destination missing */
if (errno == ENOENT)
--- 572,582 ----
* realink(2) doesn't null terminate the link name. We must
* do it here.
*/
buf[len] = '\0';
} else {
! syslog(LOG_ERR, "Error %d reading softlink of [%s]",
errno, nm);
buf[0] = '\0';
/* Backup the link if the destination missing */
if (errno == ENOENT)
*** 642,652 ****
int section; /* section of a huge file */
int fd;
int afd = 0;
longlong_t seek_spot = 0; /* location in the file */
/* for Multi Volume record */
- u_longlong_t pos;
DIR *dp;
struct dirent *dtp;
char *attrname;
char *fnamep;
int rv = 0;
--- 636,645 ----
*** 660,670 ****
free(fullname);
return (-TLM_NO_SCRATCH_SPACE);
}
if (!tlm_cat_path(fullname, dir, name)) {
! NDMP_LOG(LOG_DEBUG, "Path too long.");
free(fullname);
return (-TLM_NO_SCRATCH_SPACE);
}
if (pathconf(fullname, _PC_XATTR_EXISTS) != 1 &&
--- 653,663 ----
free(fullname);
return (-TLM_NO_SCRATCH_SPACE);
}
if (!tlm_cat_path(fullname, dir, name)) {
! syslog(LOG_ERR, "Path too long.");
free(fullname);
return (-TLM_NO_SCRATCH_SPACE);
}
if (pathconf(fullname, _PC_XATTR_EXISTS) != 1 &&
*** 679,689 ****
rv = -TLM_NO_SCRATCH_SPACE;
goto err_out;
}
if (!tlm_cat_path(snapname, chkdir, name)) {
! NDMP_LOG(LOG_DEBUG, "Path too long.");
rv = -TLM_NO_SCRATCH_SPACE;
goto err_out;
}
fnamep = (tlm_acls->acl_checkpointed) ? snapname : fullname;
--- 672,682 ----
rv = -TLM_NO_SCRATCH_SPACE;
goto err_out;
}
if (!tlm_cat_path(snapname, chkdir, name)) {
! syslog(LOG_ERR, "Path too long.");
rv = -TLM_NO_SCRATCH_SPACE;
goto err_out;
}
fnamep = (tlm_acls->acl_checkpointed) ? snapname : fullname;
*** 691,714 ****
/*
* Open the file for reading.
*/
fd = attropen(fnamep, ".", O_RDONLY);
if (fd == -1) {
! NDMP_LOG(LOG_DEBUG, "BACKUP> Can't open file [%s][%s]",
fullname, fnamep);
rv = TLM_NO_SOURCE_FILE;
goto err_out;
}
- pos = tlm_get_data_offset(local_commands);
- NDMP_LOG(LOG_DEBUG, "pos: %10lld [%s]", pos, name);
-
section = 0;
dp = (DIR *)fdopendir(fd);
if (dp == NULL) {
! NDMP_LOG(LOG_DEBUG, "BACKUP> Can't open file [%s]", fullname);
(void) close(fd);
rv = TLM_NO_SOURCE_FILE;
goto err_out;
}
--- 684,704 ----
/*
* Open the file for reading.
*/
fd = attropen(fnamep, ".", O_RDONLY);
if (fd == -1) {
! syslog(LOG_ERR, "BACKUP> Can't open file [%s][%s]",
fullname, fnamep);
rv = TLM_NO_SOURCE_FILE;
goto err_out;
}
section = 0;
dp = (DIR *)fdopendir(fd);
if (dp == NULL) {
! syslog(LOG_ERR, "BACKUP> Can't open file [%s]", fullname);
(void) close(fd);
rv = TLM_NO_SOURCE_FILE;
goto err_out;
}
*** 721,731 ****
if (sysattr_rdonly(dtp->d_name))
continue;
afd = attropen(fnamep, dtp->d_name, O_RDONLY);
if (afd == -1) {
! NDMP_LOG(LOG_DEBUG,
"problem(%d) opening xattr file [%s][%s]", errno,
fullname, fnamep);
goto tear_down;
}
--- 711,721 ----
if (sysattr_rdonly(dtp->d_name))
continue;
afd = attropen(fnamep, dtp->d_name, O_RDONLY);
if (afd == -1) {
! syslog(LOG_ERR,
"problem(%d) opening xattr file [%s][%s]", errno,
fullname, fnamep);
goto tear_down;
}
*** 743,754 ****
while (section_size > 0) {
char *buf;
long actual_size;
int read_size;
int sysattr_read = 0;
! char *rec;
! int size;
/*
* check for Abort commands
*/
if (commands->tcs_reader != TLM_BACKUP_RUN) {
--- 733,744 ----
while (section_size > 0) {
char *buf;
long actual_size;
int read_size;
int sysattr_read = 0;
! char *rec = NULL;
! int size = 0;
/*
* check for Abort commands
*/
if (commands->tcs_reader != TLM_BACKUP_RUN) {
*** 803,813 ****
NS_ADD(rdisk, actual_size);
NS_INC(rfile);
if (actual_size == -1) {
! NDMP_LOG(LOG_DEBUG,
"problem(%d) reading file [%s][%s]",
errno, fullname, snapname);
goto tear_down;
}
seek_spot += actual_size;
--- 793,803 ----
NS_ADD(rdisk, actual_size);
NS_INC(rfile);
if (actual_size == -1) {
! syslog(LOG_ERR,
"problem(%d) reading file [%s][%s]",
errno, fullname, snapname);
goto tear_down;
}
seek_spot += actual_size;
*** 865,875 ****
* the tape offset of the data record.
*/
u_longlong_t hardlink_pos = 0;
if (tlm_is_too_long(tlm_acls->acl_checkpointed, dir, name)) {
! NDMP_LOG(LOG_DEBUG, "Path too long [%s][%s]", dir, name);
return (-TLM_NO_SCRATCH_SPACE);
}
fullname = ndmp_malloc(TLM_MAX_PATH_NAME);
linkname = ndmp_malloc(TLM_MAX_PATH_NAME);
--- 855,865 ----
* the tape offset of the data record.
*/
u_longlong_t hardlink_pos = 0;
if (tlm_is_too_long(tlm_acls->acl_checkpointed, dir, name)) {
! syslog(LOG_ERR, "Path too long [%s][%s]", dir, name);
return (-TLM_NO_SCRATCH_SPACE);
}
fullname = ndmp_malloc(TLM_MAX_PATH_NAME);
linkname = ndmp_malloc(TLM_MAX_PATH_NAME);
*** 878,894 ****
real_size = -TLM_NO_SCRATCH_SPACE;
goto err_out;
}
if (!tlm_cat_path(fullname, dir, name) ||
!tlm_cat_path(snapname, chkdir, name)) {
! NDMP_LOG(LOG_DEBUG, "Path too long.");
real_size = -TLM_NO_SCRATCH_SPACE;
goto err_out;
}
pos = tlm_get_data_offset(local_commands);
- NDMP_LOG(LOG_DEBUG, "pos: %10lld [%s]", pos, name);
if (S_ISPECIAL(tlm_acls->acl_attr.st_mode)) {
if (S_ISLNK(tlm_acls->acl_attr.st_mode)) {
file_size = tlm_readlink(fullname, snapname, linkname,
TLM_MAX_PATH_NAME-1);
--- 868,883 ----
real_size = -TLM_NO_SCRATCH_SPACE;
goto err_out;
}
if (!tlm_cat_path(fullname, dir, name) ||
!tlm_cat_path(snapname, chkdir, name)) {
! syslog(LOG_ERR, "Path too long.");
real_size = -TLM_NO_SCRATCH_SPACE;
goto err_out;
}
pos = tlm_get_data_offset(local_commands);
if (S_ISPECIAL(tlm_acls->acl_attr.st_mode)) {
if (S_ISLNK(tlm_acls->acl_attr.st_mode)) {
file_size = tlm_readlink(fullname, snapname, linkname,
TLM_MAX_PATH_NAME-1);
*** 934,951 ****
/*
* Open the file for reading.
*/
fd = open(fnamep, O_RDONLY);
if (fd == -1) {
! NDMP_LOG(LOG_DEBUG,
"BACKUP> Can't open file [%s][%s] err(%d)",
fullname, fnamep, errno);
real_size = -TLM_NO_SOURCE_FILE;
goto err_out;
}
} else {
! NDMP_LOG(LOG_DEBUG, "found hardlink, inode = %llu, pos = %llu ",
tlm_acls->acl_attr.st_ino, hardlink_pos);
fd = -1;
}
--- 923,940 ----
/*
* Open the file for reading.
*/
fd = open(fnamep, O_RDONLY);
if (fd == -1) {
! syslog(LOG_ERR,
"BACKUP> Can't open file [%s][%s] err(%d)",
fullname, fnamep, errno);
real_size = -TLM_NO_SOURCE_FILE;
goto err_out;
}
} else {
! syslog(LOG_DEBUG, "found hardlink, inode = %llu, pos = %llu ",
tlm_acls->acl_attr.st_ino, hardlink_pos);
fd = -1;
}
*** 1045,1055 ****
if (actual_size == 0)
break;
if (actual_size == -1) {
! NDMP_LOG(LOG_DEBUG,
"problem(%d) reading file [%s][%s]",
errno, fullname, snapname);
goto tear_down;
}
seek_spot += actual_size;
--- 1034,1044 ----
if (actual_size == 0)
break;
if (actual_size == -1) {
! syslog(LOG_ERR,
"problem(%d) reading file [%s][%s]",
errno, fullname, snapname);
goto tear_down;
}
seek_spot += actual_size;
*** 1064,1084 ****
* to hardlink queue.
*/
if (tlm_acls->acl_attr.st_nlink > 1 && !hardlink_done) {
(void) hardlink_q_add(hardlink_q, tlm_acls->acl_attr.st_ino,
pos, NULL, 0);
! NDMP_LOG(LOG_DEBUG,
"backed up hardlink file %s, inode = %llu, pos = %llu ",
fullname, tlm_acls->acl_attr.st_ino, pos);
}
/*
* For hardlink, if other link belonging to the same inode has been
* backed up, no add_node entry should be sent for this link.
*/
if (hardlink_done) {
! NDMP_LOG(LOG_DEBUG,
"backed up hardlink link %s, inode = %llu, pos = %llu ",
fullname, tlm_acls->acl_attr.st_ino, hardlink_pos);
} else {
(void) tlm_log_fhnode(job_stats, dir, name,
&tlm_acls->acl_attr, pos);
--- 1053,1073 ----
* to hardlink queue.
*/
if (tlm_acls->acl_attr.st_nlink > 1 && !hardlink_done) {
(void) hardlink_q_add(hardlink_q, tlm_acls->acl_attr.st_ino,
pos, NULL, 0);
! syslog(LOG_DEBUG,
"backed up hardlink file %s, inode = %llu, pos = %llu ",
fullname, tlm_acls->acl_attr.st_ino, pos);
}
/*
* For hardlink, if other link belonging to the same inode has been
* backed up, no add_node entry should be sent for this link.
*/
if (hardlink_done) {
! syslog(LOG_DEBUG,
"backed up hardlink link %s, inode = %llu, pos = %llu ",
fullname, tlm_acls->acl_attr.st_ino, hardlink_pos);
} else {
(void) tlm_log_fhnode(job_stats, dir, name,
&tlm_acls->acl_attr, pos);