Print this page
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-1123 NDMP commands can not uniquely identify Nexenta and the file server version (currently 4.0.1) and Sun Microsystems.
OS-49 Switch back to illumos' version of wcwidth()
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
NEX-426 ndmp_config_get_ext_list failed
NEX-250 Failed to open device /dev/rmt/0n because of too many files open

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/ndmpd/ndmp/ndmpd_config.c
          +++ new/usr/src/cmd/ndmpd/ndmp/ndmpd_config.c
↓ open down ↓ 29 lines elided ↑ open up ↑
  30   30   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31   31   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32   32   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33   33   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34   34   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35   35   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36   36   * POSSIBILITY OF SUCH DAMAGE.
  37   37   */
  38   38  /* Copyright (c) 2007, The Storage Networking Industry Association. */
  39   39  /* Copyright (c) 1996, 1997 PDC, Network Appliance. All Rights Reserved */
  40      -/* Copyright 2014 Nexenta Systems, Inc.  All rights reserved. */
       40 +/* Copyright 2016 Nexenta Systems, Inc.  All rights reserved. */
  41   41  
  42   42  #include <dirent.h>
  43   43  #include <errno.h>
  44   44  #include <stdio.h>
  45   45  #include <stdlib.h>
  46   46  #include <string.h>
       47 +#include <syslog.h>
  47   48  #include <sys/stat.h>
  48   49  #include <sys/mnttab.h>
  49   50  #include <sys/mntent.h>
  50   51  #include <sys/mntio.h>
  51   52  #include <sys/statvfs.h>
  52   53  #include <sys/utsname.h>
  53   54  #include <sys/scsi/scsi.h>
  54   55  #include <unistd.h>
  55   56  #include <sys/systeminfo.h>
  56   57  #include "ndmpd_common.h"
↓ open down ↓ 58 lines elided ↑ open up ↑
 115  116          (void) memset(buf, 0, sizeof (buf));
 116  117          (void) gethostname(buf, sizeof (buf));
 117  118  
 118  119          reply.error = NDMP_NO_ERR;
 119  120          reply.hostname = buf;
 120  121          (void) uname(&uts);
 121  122          reply.os_type = uts.sysname;
 122  123          reply.os_vers = uts.release;
 123  124  
 124  125          if (sysinfo(SI_HW_SERIAL, hostidstr, sizeof (hostidstr)) < 0) {
 125      -                NDMP_LOG(LOG_DEBUG, "sysinfo error: %m.");
      126 +                syslog(LOG_ERR, "sysinfo error: %m.");
 126  127                  reply.error = NDMP_UNDEFINED_ERR;
 127  128          }
 128  129  
 129  130          /*
 130  131           * Convert the hostid to hex. The returned string must match
 131  132           * the string returned by hostid(1).
 132  133           */
 133  134          hostid = strtoul(hostidstr, 0, 0);
 134  135          (void) snprintf(hostidstr, sizeof (hostidstr), "%lx", hostid);
 135  136          reply.hostid = hostidstr;
↓ open down ↓ 28 lines elided ↑ open up ↑
 164  165  
 165  166          request = (ndmp_config_get_butype_attr_request *)body;
 166  167  
 167  168          reply.error = NDMP_NO_ERR;
 168  169  
 169  170          if (strcmp(request->name, "dump") == 0) {
 170  171                  (void) simple_get_attrs(&reply.attrs);
 171  172          } else if (strcmp(request->name, "tar") == 0) {
 172  173                  reply.attrs = NDMP_NO_BACKUP_FILELIST;
 173  174          } else {
 174      -                NDMP_LOG(LOG_ERR, "Invalid backup type: %s.", request->name);
 175      -                NDMP_LOG(LOG_ERR,
      175 +                syslog(LOG_ERR, "Invalid backup type: %s.", request->name);
      176 +                syslog(LOG_ERR,
 176  177                      "Supported backup types are 'dump' and 'tar' only.");
 177  178                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
 178  179          }
 179  180  
 180  181          ndmp_send_reply(connection, (void *) &reply,
 181  182              "sending ndmp_config_get_butype_attr reply");
 182  183  }
 183  184  
 184  185  
 185  186  /*
↓ open down ↓ 59 lines elided ↑ open up ↑
 245  246                  break;
 246  247          case NDMP_AUTH_MD5:
 247  248                  /* Create a 64 byte random session challenge */
 248  249                  randomize(session->ns_challenge, MD5_CHALLENGE_SIZE);
 249  250                  (void) memcpy(reply.server_attr.ndmp_auth_attr_u.challenge,
 250  251                      session->ns_challenge, MD5_CHALLENGE_SIZE);
 251  252                  break;
 252  253          case NDMP_AUTH_NONE:
 253  254                  /* FALL THROUGH */
 254  255          default:
 255      -                NDMP_LOG(LOG_ERR, "Invalid authentication type: %d.",
      256 +                syslog(LOG_ERR, "Invalid authentication type: %d.",
 256  257                      request->auth_type);
 257      -                NDMP_LOG(LOG_ERR,
      258 +                syslog(LOG_ERR,
 258  259                      "Supported authentication types are md5 and cleartext.");
 259  260                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
 260  261                  break;
 261  262          }
 262  263  
 263  264          ndmp_send_reply(connection, (void *) &reply,
 264  265              "sending ndmp_config_get_auth_attr reply");
 265  266  }
 266  267  
 267  268  
↓ open down ↓ 32 lines elided ↑ open up ↑
 300  301  
 301  302  
 302  303          reply.error = NDMP_NO_ERR;
 303  304          reply.hostname = buf;
 304  305          (void) uname(&uts);
 305  306          reply.os_type = uts.sysname;
 306  307          reply.os_vers = uts.release;
 307  308  
 308  309          if (sysinfo(SI_HW_SERIAL, hostidstr, sizeof (hostidstr)) < 0) {
 309  310  
 310      -                NDMP_LOG(LOG_DEBUG, "sysinfo error: %m.");
      311 +                syslog(LOG_ERR, "sysinfo error: %m.");
 311  312                  reply.error = NDMP_UNDEFINED_ERR;
 312  313          }
 313  314  
 314  315          /*
 315  316           * Convert the hostid to hex. The returned string must match
 316  317           * the string returned by hostid(1).
 317  318           */
 318  319          hostid = strtoul(hostidstr, 0, 0);
 319  320          (void) snprintf(hostidstr, sizeof (hostidstr), "%lx", hostid);
 320  321          reply.hostid = hostidstr;
↓ open down ↓ 70 lines elided ↑ open up ↑
 391  392                  break;
 392  393          case NDMP_AUTH_MD5:
 393  394                  /* Create a 64 bytes random session challenge */
 394  395                  randomize(session->ns_challenge, MD5_CHALLENGE_SIZE);
 395  396                  (void) memcpy(reply.server_attr.ndmp_auth_attr_u.challenge,
 396  397                      session->ns_challenge, MD5_CHALLENGE_SIZE);
 397  398                  break;
 398  399          case NDMP_AUTH_NONE:
 399  400                  /* FALL THROUGH */
 400  401          default:
 401      -                NDMP_LOG(LOG_ERR, "Invalid authentication type: %d.",
      402 +                syslog(LOG_ERR, "Invalid authentication type: %d.",
 402  403                      request->auth_type);
 403      -                NDMP_LOG(LOG_ERR,
      404 +                syslog(LOG_ERR,
 404  405                      "Supported authentication types are md5 and cleartext.");
 405  406                  reply.error = NDMP_ILLEGAL_ARGS_ERR;
 406  407                  break;
 407  408          }
 408  409  
 409  410          ndmp_send_reply(connection, (void *) &reply,
 410  411              "sending ndmp_config_get_auth_attr_v3 reply");
 411  412  }
 412  413  
 413  414  
↓ open down ↓ 122 lines elided ↑ open up ↑
 536  537          int log_dev_len;
 537  538          FILE *fp = NULL;
 538  539          struct mnttab mt, *fs;
 539  540          struct statvfs64 stat_buf;
 540  541          ndmp_pval *envp, *save;
 541  542  
 542  543          (void) memset((void*)&reply, 0, sizeof (reply));
 543  544          reply.error = NDMP_NO_ERR;
 544  545  
 545  546          if ((fd = open(MNTTAB, O_RDONLY)) == -1) {
 546      -                NDMP_LOG(LOG_ERR, "File mnttab open error: %m.");
      547 +                syslog(LOG_ERR, "File mnttab open error: %m.");
 547  548                  reply.error = NDMP_UNDEFINED_ERR;
 548  549                  goto send_reply;
 549  550          }
 550  551  
 551  552          /* nothing was found, send an empty reply */
 552  553          if (ioctl(fd, MNTIOC_NMNTS, &nmnt) != 0 || nmnt <= 0) {
 553  554                  (void) close(fd);
 554      -                NDMP_LOG(LOG_ERR, "No file system found.");
      555 +                syslog(LOG_ERR, "No file system found.");
 555  556                  goto send_reply;
 556  557          }
 557  558  
 558  559          fp = fdopen(fd, "r");
 559  560          if (!fp) {
 560  561                  (void) close(fd);
 561      -                NDMP_LOG(LOG_ERR, "File mnttab open error: %m.");
      562 +                syslog(LOG_ERR, "File mnttab open error: %m.");
 562  563                  reply.error = NDMP_UNDEFINED_ERR;
 563  564                  goto send_reply;
 564  565          }
 565  566  
 566  567          fsip_save = fsip = ndmp_malloc(sizeof (ndmp_fs_info_v3) * nmnt);
 567  568          if (!fsip) {
 568  569                  (void) fclose(fp);
 569  570                  reply.error = NDMP_NO_MEM_ERR;
 570  571                  goto send_reply;
 571  572          }
↓ open down ↓ 18 lines elided ↑ open up ↑
 590  591                          reply.error = NDMP_NO_MEM_ERR;
 591  592                          break;
 592  593                  }
 593  594                  (void) snprintf(fsip->fs_type, MNTTYPE_LEN, "%s",
 594  595                      fs->mnt_fstype);
 595  596                  (void) snprintf(fsip->fs_logical_device, log_dev_len, "%s",
 596  597                      fs->mnt_mountp);
 597  598                  fsip->invalid = 0;
 598  599  
 599  600                  if (statvfs64(fs->mnt_mountp, &stat_buf) < 0) {
 600      -                        NDMP_LOG(LOG_DEBUG,
      601 +                        syslog(LOG_ERR,
 601  602                              "statvfs(%s) error.", fs->mnt_mountp);
 602  603                          fsip->fs_status =
 603  604                              "statvfs error: unable to determine filesystem"
 604  605                              " attributes";
 605  606                  } else {
 606  607                          fsip->invalid = 0;
 607  608                          fsip->total_size =
 608  609                              long_long_to_quad((u_longlong_t)stat_buf.f_frsize *
 609  610                              (u_longlong_t)stat_buf.f_blocks);
 610  611                          fsip->used_size =
↓ open down ↓ 103 lines elided ↑ open up ↑
 714  715                  if (!(sl = sasd_dev_slink(i)) || !(sd = sasd_drive(i)))
 715  716                          continue;
 716  717                  if (sl->sl_type != DTYPE_SEQUENTIAL)
 717  718                          continue;
 718  719                  /*
 719  720                   * Don't report dead links.
 720  721                   */
 721  722                  if ((access(sd->sd_name, F_OK) == -1) && (errno == ENOENT))
 722  723                          continue;
 723  724  
 724      -                NDMP_LOG(LOG_DEBUG,
      725 +                syslog(LOG_DEBUG,
 725  726                      "model \"%s\" dev \"%s\"", sd->sd_id, sd->sd_name);
 726  727  
 727  728                  envp_head = envp;
 728  729                  NDMP_SETENV(envp, "EXECUTE_CDB", "b");
 729  730                  NDMP_SETENV(envp, "SERIAL_NUMBER", sd->sd_serial);
 730  731                  NDMP_SETENV(envp, "WORLD_WIDE_NAME", sd->sd_wwn);
 731  732  
 732  733                  tip->model = sd->sd_id; /* like "DLT7000         " */
 733  734                  tip->caplist.caplist_len = 1;
 734  735                  tip->caplist.caplist_val = dcp;
 735  736                  dcp->device = sd->sd_name; /* like "isp1t060" */
 736  737                  dcp->attr = 0;
 737  738                  dcp->capability.capability_len = 3;
 738  739                  dcp->capability.capability_val = envp_head;
 739  740                  tip++;
 740  741                  dcp++;
 741  742                  n++;
 742  743          }
 743  744  
 744      -        NDMP_LOG(LOG_DEBUG, "n %d", n);
 745      -
 746  745          /*
 747  746           * We should not receive the get_tape_info when three-way backup is
 748  747           * running and we are acting as just data, but some clients try
 749  748           * to get the Tape information anyway.
 750  749           */
 751  750          if (n == 0 || max <= 0) {
 752  751                  reply.error = NDMP_NO_DEVICE_ERR;
 753  752                  ndmp_send_reply(connection, (void *)&reply,
 754  753                      "error sending ndmp_config_get_tape_info reply");
 755  754                  free(tip_save); free(dcp_save); free(envp_save);
↓ open down ↓ 60 lines elided ↑ open up ↑
 816  815                  if (!(sl = sasd_dev_slink(i)) || !(sd = sasd_drive(i)))
 817  816                          continue;
 818  817                  if (sl->sl_type != DTYPE_CHANGER)
 819  818                          continue;
 820  819                  /*
 821  820                   * Don't report dead links.
 822  821                   */
 823  822                  if ((access(sd->sd_name, F_OK) == -1) && (errno == ENOENT))
 824  823                          continue;
 825  824  
 826      -                NDMP_LOG(LOG_DEBUG,
      825 +                syslog(LOG_DEBUG,
 827  826                      "model \"%s\" dev \"%s\"", sd->sd_id, sd->sd_name);
 828  827  
 829  828                  envp_head = envp;
 830  829                  NDMP_SETENV(envp, "SERIAL_NUMBER", sd->sd_serial);
 831  830                  NDMP_SETENV(envp, "WORLD_WIDE_NAME", sd->sd_wwn);
 832  831  
 833  832                  sip->model = sd->sd_id; /* like "Powerstor L200  " */
 834  833                  sip->caplist.caplist_len = 1;
 835  834                  sip->caplist.caplist_val = dcp;
 836  835                  dcp->device = sd->sd_name; /* like "isp1m000" */
 837  836  
 838  837                  dcp->attr = 0;
 839  838                  dcp->capability.capability_len = 2;
 840  839                  dcp->capability.capability_val = envp_head;
 841  840                  sip++;
 842  841                  dcp++;
 843  842                  n++;
 844  843          }
 845  844  
 846      -        NDMP_LOG(LOG_DEBUG, "n %d", n);
 847      -
 848  845          reply.scsi_info.scsi_info_len = n;
 849  846          reply.scsi_info.scsi_info_val = sip_save;
 850  847  
 851  848          ndmp_send_reply(connection, (void *)&reply,
 852  849              "error sending ndmp_config_get_scsi_info reply");
 853  850  
 854  851          free(sip_save);
 855  852          free(dcp_save);
 856  853          free(envp_save);
 857  854  }
↓ open down ↓ 13 lines elided ↑ open up ↑
 871  868   *   void
 872  869   */
 873  870  /*ARGSUSED*/
 874  871  void
 875  872  ndmpd_config_get_server_info_v3(ndmp_connection_t *connection, void *body)
 876  873  {
 877  874          ndmp_config_get_server_info_reply_v3 reply;
 878  875          ndmp_auth_type auth_types[2];
 879  876          char rev_number[10];
 880  877          ndmpd_session_t *session = ndmp_get_client_data(connection);
      878 +        char *vendor;
      879 +        char *product;
 881  880  
 882  881          (void) memset((void*)&reply, 0, sizeof (reply));
 883  882          reply.error = NDMP_NO_ERR;
 884  883  
 885  884          if (connection->conn_authorized ||
 886  885              session->ns_protocol_version != NDMPV4) {
 887      -                reply.vendor_name = VENDOR_NAME;
 888      -                reply.product_name = PRODUCT_NAME;
      886 +                if ((vendor = ndmpd_get_prop(NDMP_VENDOR_NAME)) == NULL ||
      887 +                    *vendor == 0) {
      888 +                        reply.vendor_name = VENDOR_NAME;
      889 +                } else {
      890 +                        reply.vendor_name = vendor;
      891 +                }
      892 +                if ((product = ndmpd_get_prop(NDMP_PRODUCT_NAME)) == NULL ||
      893 +                    *product == 0) {
      894 +                        reply.product_name = PRODUCT_NAME;
      895 +                } else {
      896 +                        reply.product_name = product;
      897 +                }
 889  898                  (void) snprintf(rev_number, sizeof (rev_number), "%d",
 890  899                      ndmp_ver);
 891  900                  reply.revision_number = rev_number;
 892  901          } else {
 893  902                  reply.vendor_name = "\0";
 894  903                  reply.product_name = "\0";
 895  904                  reply.revision_number = "\0";
 896  905          }
 897  906  
 898      -        NDMP_LOG(LOG_DEBUG,
 899      -            "vendor \"%s\", product \"%s\" rev \"%s\"",
 900      -            reply.vendor_name, reply.product_name, reply.revision_number);
 901      -
 902  907          auth_types[0] = NDMP_AUTH_TEXT;
 903  908          auth_types[1] = NDMP_AUTH_MD5;
 904  909          reply.auth_type.auth_type_len = ARRAY_LEN(auth_types, ndmp_auth_type);
 905  910          reply.auth_type.auth_type_val = auth_types;
 906  911  
 907  912          ndmp_send_reply(connection, (void *)&reply,
 908  913              "error sending ndmp_config_get_server_info reply");
 909  914  }
 910  915  
 911  916  
↓ open down ↓ 136 lines elided ↑ open up ↑
1048 1053  {
1049 1054          ndmp_config_get_ext_list_reply_v4 reply;
1050 1055          ndmpd_session_t *session = ndmp_get_client_data(connection);
1051 1056  
1052 1057          (void) memset((void*)&reply, 0, sizeof (reply));
1053 1058  
1054 1059          if (session->ns_set_ext_list) {
1055 1060                  /*
1056 1061                   * Illegal request if extensions have already been selected.
1057 1062                   */
1058      -                NDMP_LOG(LOG_ERR, "Extensions have already been selected.");
     1063 +                syslog(LOG_ERR, "Extensions have already been selected.");
1059 1064                  reply.error = NDMP_EXT_DANDN_ILLEGAL_ERR;
1060 1065          } else {
1061 1066                  /*
1062 1067                   * Reply with an empty set of extensions.
1063 1068                   */
1064 1069                  session->ns_get_ext_list = B_TRUE;
1065 1070                  reply.error = NDMP_NO_ERR;
1066 1071          }
1067 1072  
1068 1073          reply.class_list.class_list_val = NULL;
↓ open down ↓ 24 lines elided ↑ open up ↑
1093 1098  
1094 1099          request = (ndmp_config_set_ext_list_request_v4 *)body;
1095 1100  
1096 1101          (void) memset((void*)&reply, 0, sizeof (reply));
1097 1102  
1098 1103          if (!session->ns_get_ext_list) {
1099 1104                  /*
1100 1105                   * The DMA is required to issue a NDMP_GET_EXT_LIST request
1101 1106                   * prior sending a NDMP_SET_EXT_LIST request.
1102 1107                   */
1103      -                NDMP_LOG(LOG_ERR, "No prior ndmp_config_get_ext_list issued.");
     1108 +                syslog(LOG_ERR, "No prior ndmp_config_get_ext_list issued.");
1104 1109                  reply.error = NDMP_PRECONDITION_ERR;
1105 1110          } else if (session->ns_set_ext_list) {
1106 1111                  /*
1107 1112                   * Illegal request if extensions have already been selected.
1108 1113                   */
1109      -                NDMP_LOG(LOG_ERR, "Extensions have already been selected.");
     1114 +                syslog(LOG_ERR, "Extensions have already been selected.");
1110 1115                  reply.error = NDMP_EXT_DANDN_ILLEGAL_ERR;
1111 1116          } else {
1112 1117                  /*
1113 1118                   * We currently do not support any extensions, but the DMA
1114 1119                   * may test NDMP_CONFIG_SET_EXT_LIST with an empty list.
1115 1120                   */
1116 1121                  if (request->ndmp_selected_ext.ndmp_selected_ext_len != 0) {
1117 1122                          reply.error = NDMP_CLASS_NOT_SUPPORTED_ERR;
1118 1123                  } else {
1119 1124                          session->ns_set_ext_list = B_TRUE;
↓ open down ↓ 32 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX