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,10 +34,13 @@
  * 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,11 +116,10 @@
 
         /*
          * 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,

@@ -255,11 +257,11 @@
 
         if (section_name == NULL)
                 return (-TLM_NO_SCRATCH_SPACE);
 
         if (fstat64(fd, attr) == -1) {
-                NDMP_LOG(LOG_DEBUG, "output_file_header stat failed.");
+                syslog(LOG_ERR, "output_file_header stat failed.");
                 free(section_name);
                 return (-TLM_OPEN_ERR);
         }
 
         /*

@@ -298,13 +300,10 @@
         (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) {

@@ -486,13 +485,10 @@
                     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,

@@ -528,12 +524,10 @@
                             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 ",

@@ -578,11 +572,11 @@
                  * 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]",
+                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,11 +636,10 @@
         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;

@@ -660,11 +653,11 @@
                 free(fullname);
                 return (-TLM_NO_SCRATCH_SPACE);
         }
 
         if (!tlm_cat_path(fullname, dir, name)) {
-                NDMP_LOG(LOG_DEBUG, "Path too long.");
+                syslog(LOG_ERR, "Path too long.");
                 free(fullname);
                 return (-TLM_NO_SCRATCH_SPACE);
         }
 
         if (pathconf(fullname, _PC_XATTR_EXISTS) != 1 &&

@@ -679,11 +672,11 @@
                 rv = -TLM_NO_SCRATCH_SPACE;
                 goto err_out;
         }
 
         if (!tlm_cat_path(snapname, chkdir, name)) {
-                NDMP_LOG(LOG_DEBUG, "Path too long.");
+                syslog(LOG_ERR, "Path too long.");
                 rv = -TLM_NO_SCRATCH_SPACE;
                 goto err_out;
         }
 
         fnamep = (tlm_acls->acl_checkpointed) ? snapname : fullname;

@@ -691,24 +684,21 @@
         /*
          * Open the file for reading.
          */
         fd = attropen(fnamep, ".", O_RDONLY);
         if (fd == -1) {
-                NDMP_LOG(LOG_DEBUG, "BACKUP> Can't open file [%s][%s]",
+                syslog(LOG_ERR, "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);
+                syslog(LOG_ERR, "BACKUP> Can't open file [%s]", fullname);
                 (void) close(fd);
                 rv = TLM_NO_SOURCE_FILE;
                 goto err_out;
         }
 

@@ -721,11 +711,11 @@
                 if (sysattr_rdonly(dtp->d_name))
                         continue;
 
                 afd = attropen(fnamep, dtp->d_name, O_RDONLY);
                 if (afd == -1) {
-                        NDMP_LOG(LOG_DEBUG,
+                        syslog(LOG_ERR,
                             "problem(%d) opening xattr file [%s][%s]", errno,
                             fullname, fnamep);
                         goto tear_down;
                 }
 

@@ -743,12 +733,12 @@
                 while (section_size > 0) {
                         char    *buf;
                         long    actual_size;
                         int     read_size;
                         int sysattr_read = 0;
-                        char *rec;
-                        int size;
+                        char *rec = NULL;
+                        int size = 0;
 
                         /*
                          * check for Abort commands
                          */
                         if (commands->tcs_reader != TLM_BACKUP_RUN) {

@@ -803,11 +793,11 @@
 
                         NS_ADD(rdisk, actual_size);
                         NS_INC(rfile);
 
                         if (actual_size == -1) {
-                                NDMP_LOG(LOG_DEBUG,
+                                syslog(LOG_ERR,
                                     "problem(%d) reading file [%s][%s]",
                                     errno, fullname, snapname);
                                 goto tear_down;
                         }
                         seek_spot += actual_size;

@@ -865,11 +855,11 @@
          * 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);
+                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,17 +868,16 @@
                 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.");
+                syslog(LOG_ERR, "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);

@@ -934,18 +923,18 @@
                 /*
                  * Open the file for reading.
                  */
                 fd = open(fnamep, O_RDONLY);
                 if (fd == -1) {
-                        NDMP_LOG(LOG_DEBUG,
+                        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 {
-                NDMP_LOG(LOG_DEBUG, "found hardlink, inode = %llu, pos = %llu ",
+                syslog(LOG_DEBUG, "found hardlink, inode = %llu, pos = %llu ",
                     tlm_acls->acl_attr.st_ino, hardlink_pos);
 
                 fd = -1;
         }
 

@@ -1045,11 +1034,11 @@
 
                         if (actual_size == 0)
                                 break;
 
                         if (actual_size == -1) {
-                                NDMP_LOG(LOG_DEBUG,
+                                syslog(LOG_ERR,
                                     "problem(%d) reading file [%s][%s]",
                                     errno, fullname, snapname);
                                 goto tear_down;
                         }
                         seek_spot += actual_size;

@@ -1064,21 +1053,21 @@
          * 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,
+                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) {
-                NDMP_LOG(LOG_DEBUG,
+                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);