Print this page
NEX-14898 Null message (cfga_msg: NULL msgp) printed for sata devices with cfgadm
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Cynthia Eastham <cynthia.eastham@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/cfgadm_plugins/sata/common/cfga_sata.c
          +++ new/usr/src/lib/cfgadm_plugins/sata/common/cfga_sata.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
       24 + * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
  24   25   * Use is subject to license terms.
  25   26   */
  26   27  
  27   28  #include <sys/param.h>
  28   29  #include <sys/stat.h>
  29   30  #include <errno.h>
  30   31  #include <string.h>
  31   32  #include <dirent.h>
  32   33  #include "cfga_sata.h"
  33   34  
↓ open down ↓ 673 lines elided ↑ open up ↑
 707  708  
 708  709                  if (!sata_confirm(confp, msg)) {
 709  710                          free(msg);
 710  711                          rv = CFGA_SATA_NACK;
 711  712                          break;
 712  713                  }
 713  714                  free(msg);
 714  715  
 715  716                  devpath = sata_get_devicepath(ap_id);
 716  717                  if (devpath == NULL) {
 717      -                        (void) printf(
      718 +                        DPRINTF(
 718  719                              "cfga_change_state: get device path failed\n");
 719  720                          rv = CFGA_SATA_DEV_UNCONFIGURE;
 720  721                          break;
 721  722                  }
 722  723  
 723  724                  if ((rv = sata_rcm_offline(ap_id, errstring, devpath, flags))
 724  725                      != CFGA_SATA_OK) {
 725  726                          break;
 726  727                  }
 727  728  
↓ open down ↓ 36 lines elided ↑ open up ↑
 764  765                  /*
 765  766                   * If the port originally with device attached and was
 766  767                   * unconfigured already, the devicepath for the sd will be
 767  768                   * removed. sata_get_devicepath in this case is not necessary.
 768  769                   */
 769  770                  /* only call rcm_offline if the state was CONFIGURED */
 770  771                  if (ostate == AP_OSTATE_CONFIGURED &&
 771  772                      pmult == B_FALSE) {
 772  773                          devpath = sata_get_devicepath(ap_id);
 773  774                          if (devpath == NULL) {
 774      -                                (void) printf(
      775 +                                DPRINTF(
 775  776                                      "cfga_change_state: get path failed\n");
 776  777                                  rv = CFGA_SATA_DEV_UNCONFIGURE;
 777  778                                  break;
 778  779                          }
 779  780  
 780  781                          len = strlen(SATA_CONFIRM_DEVICE) +
 781  782                              strlen(SATA_CONFIRM_DEVICE_SUSPEND) +
 782  783                              strlen("Disconnect") + strlen(ap_id);
 783  784                          if ((msg = (char *)calloc(len +3, 1)) != NULL) {
 784  785                                  (void) snprintf(msg, len + 3,
↓ open down ↓ 154 lines elided ↑ open up ↑
 939  940          /*
 940  941           * All subcommands which can change state of device require
 941  942           * root privileges.
 942  943           */
 943  944          if (geteuid() != 0) {
 944  945                  rv = CFGA_SATA_PRIV;
 945  946                  goto bailout;
 946  947          }
 947  948  
 948  949          if (func == NULL) {
 949      -                (void) printf("No valid option specified\n");
      950 +                DPRINTF("No valid option specified\n");
 950  951                  rv = CFGA_SATA_OPTIONS;
 951  952                  goto bailout;
 952  953          }
 953  954  
 954  955          if ((rv = setup_for_devctl_cmd(ap_id, &hdl, &list, 0)) !=
 955  956              CFGA_SATA_OK) {
 956  957                  goto bailout;
 957  958          }
 958  959  
 959  960          /* We do not care here about dynamic AP name component */
↓ open down ↓ 290 lines elided ↑ open up ↑
1250 1251          char    *p;
1251 1252  
1252 1253          assert(dyncomp != NULL);
1253 1254  
1254 1255          /*
1255 1256           * Get target node path
1256 1257           */
1257 1258          devpath = sata_get_devicepath(ap_id);
1258 1259          if (devpath == NULL) {
1259 1260  
1260      -                (void) printf("cfga_list_ext: cannot locate target device\n");
     1261 +                DPRINTF("cfga_list_ext: cannot locate target device\n");
1261 1262                  return (CFGA_SATA_DYNAMIC_AP);
1262 1263  
1263 1264          } else {
1264 1265  
1265 1266                  cp = strrchr(devpath, *PATH_SEP);
1266 1267                  assert(cp != NULL);
1267 1268                  *cp = 0;        /* terminate path for opendir() */
1268 1269  
1269 1270                  (void) strncpy(name_part, cp + 1, MAXNAMELEN);
1270 1271  
↓ open down ↓ 295 lines elided ↑ open up ↑
1566 1567          if ((*ap_id_list)->ap_r_state == CFGA_STAT_CONNECTED) {
1567 1568                  char *str_p;
1568 1569                  int skip, i;
1569 1570  
1570 1571                  /*
1571 1572                   * Fill in the 'Information' field for the -v option
1572 1573                   * Model (MOD:)
1573 1574                   */
1574 1575                  if ((rv = do_control_ioctl(ap_id, SATA_CFGA_GET_MODEL_INFO,
1575 1576                      NULL, (void **)&str_p, &size)) != CFGA_SATA_OK) {
1576      -                        (void) printf(
     1577 +                        DPRINTF(
1577 1578                              "SATA_CFGA_GET_MODULE_INFO ioctl failed\n");
1578 1579                          goto bailout;
1579 1580                  }
1580 1581                  /* drop leading and trailing spaces */
1581 1582                  skip = strspn(str_p, " ");
1582 1583                  for (i = size - 1; i >= 0; i--) {
1583 1584                          if (str_p[i] == '\040')
1584 1585                                  str_p[i] = '\0';
1585 1586                          else if (str_p[i] != '\0')
1586 1587                                  break;
↓ open down ↓ 6 lines elided ↑ open up ↑
1593 1594  
1594 1595                  free(str_p);
1595 1596  
1596 1597                  /*
1597 1598                   * Fill in the 'Information' field for the -v option
1598 1599                   * Firmware revision (FREV:)
1599 1600                   */
1600 1601                  if ((rv = do_control_ioctl(ap_id,
1601 1602                      SATA_CFGA_GET_REVFIRMWARE_INFO,
1602 1603                      NULL, (void **)&str_p, &size)) != CFGA_SATA_OK) {
1603      -                        (void) printf(
     1604 +                        DPRINTF(
1604 1605                              "SATA_CFGA_GET_REVFIRMWARE_INFO ioctl failed\n");
1605 1606                          goto bailout;
1606 1607                  }
1607 1608                  /* drop leading and trailing spaces */
1608 1609                  skip = strspn(str_p, " ");
1609 1610                  for (i = size - 1; i >= 0; i--) {
1610 1611                          if (str_p[i] == '\040')
1611 1612                                  str_p[i] = '\0';
1612 1613                          else if (str_p[i] != '\0')
1613 1614                                  break;
↓ open down ↓ 6 lines elided ↑ open up ↑
1620 1621                  free(str_p);
1621 1622  
1622 1623  
1623 1624                  /*
1624 1625                   * Fill in the 'Information' field for the -v option
1625 1626                   * Serial Number (SN:)
1626 1627                   */
1627 1628                  if ((rv = do_control_ioctl(ap_id,
1628 1629                      SATA_CFGA_GET_SERIALNUMBER_INFO,
1629 1630                      NULL, (void **)&str_p, &size)) != CFGA_SATA_OK) {
1630      -                        (void) printf(
     1631 +                        DPRINTF(
1631 1632                              "SATA_CFGA_GET_SERIALNUMBER_INFO ioctl failed\n");
1632 1633                          goto bailout;
1633 1634                  }
1634 1635                  /* drop leading and trailing spaces */
1635 1636                  skip = strspn(str_p, " ");
1636 1637                  for (i = size - 1; i >= 0; i--) {
1637 1638                          if (str_p[i] == '\040')
1638 1639                                  str_p[i] = '\0';
1639 1640                          else if (str_p[i] != '\0')
1640 1641                                  break;
↓ open down ↓ 4 lines elided ↑ open up ↑
1645 1646                      sizeof ((*ap_id_list)->ap_info));
1646 1647  
1647 1648                  free(str_p);
1648 1649  
1649 1650  
1650 1651  
1651 1652                  /* Fill in ap_type which is collected from HBA driver */
1652 1653                  /* call do_control_ioctl TBD */
1653 1654                  if ((rv = do_control_ioctl(ap_id, SATA_CFGA_GET_AP_TYPE, NULL,
1654 1655                      (void **)&str_p, &size)) != CFGA_SATA_OK) {
1655      -                        (void) printf(
     1656 +                        DPRINTF(
1656 1657                              "SATA_CFGA_GET_AP_TYPE ioctl failed\n");
1657 1658                          goto bailout;
1658 1659                  }
1659 1660  
1660 1661                  (void) strlcpy((*ap_id_list)->ap_type, str_p,
1661 1662                      sizeof ((*ap_id_list)->ap_type));
1662 1663  
1663 1664                  free(str_p);
1664 1665  
1665 1666                  /*
↓ open down ↓ 58 lines elided ↑ open up ↑
1724 1725   * This routine accepts a string adn prints it using
1725 1726   * the message print routine argument.
1726 1727   */
1727 1728  static void
1728 1729  cfga_msg(struct cfga_msg *msgp, const char *str)
1729 1730  {
1730 1731          int len;
1731 1732          char *q;
1732 1733  
1733 1734          if (msgp == NULL || msgp->message_routine == NULL) {
1734      -                (void) printf("cfga_msg: NULL msgp\n");
     1735 +                DPRINTF("cfga_msg: msg\n");
1735 1736                  return;
1736 1737          }
1737 1738  
1738 1739          if ((len = strlen(str)) == 0) {
1739      -                (void) printf("cfga_msg: null str\n");
     1740 +                DPRINTF("cfga_msg: null str\n");
1740 1741                  return;
1741 1742          }
1742 1743  
1743 1744          if ((q = (char *)calloc(len + 1, 1)) == NULL) {
1744      -                perror("cfga_msg");
     1745 +                DPRINTF("cfga_msg: null q\n");
1745 1746                  return;
1746 1747          }
1747 1748  
1748 1749          (void) strcpy(q, str);
1749 1750          (*msgp->message_routine)(msgp->appdata_ptr, q);
1750 1751  
1751 1752          free(q);
1752 1753  }
1753 1754  
1754 1755  /* cfgadm entry point */
↓ open down ↓ 62 lines elided ↑ open up ↑
1817 1818      char **errstring)
1818 1819  {
1819 1820          char *pdyn, *lap_id;
1820 1821          int rv;
1821 1822  
1822 1823          if (errstring != NULL) {
1823 1824                  *errstring = NULL;
1824 1825          }
1825 1826  
1826 1827          if (options != NULL) {
     1828 +                DPRINTF("verify_params: hardware-specific options not "
     1829 +                    "supported.\n");
1827 1830                  return (CFGA_SATA_OPTIONS);
1828 1831          }
1829 1832  
1830 1833          /* Strip dynamic AP name component if it is present. */
1831 1834          lap_id = strdup(ap_id);
1832 1835          if (lap_id == NULL) {
1833 1836                  return (CFGA_SATA_ALLOC_FAIL);
1834 1837          }
1835 1838          if ((pdyn = GET_DYN(lap_id)) != NULL) {
1836 1839                  *pdyn = '\0';
1837 1840          }
1838 1841  
1839 1842          if (verify_valid_apid(lap_id) != 0) {
     1843 +                DPRINTF("verify_params: not a SATA ap_id.\n");
1840 1844                  rv = CFGA_SATA_AP;
1841 1845          } else {
1842 1846                  rv = CFGA_SATA_OK;
1843 1847          }
1844 1848          free(lap_id);
1845 1849  
1846 1850          return (rv);
1847 1851  }
1848 1852  
1849 1853  /*
↓ open down ↓ 69 lines elided ↑ open up ↑
1919 1923                      "setup_for_devctl_cmd: devctl_ap_acquire failed: %s\n",
1920 1924                      strerror(errno));
1921 1925                  rv = CFGA_SATA_DEVCTL;
1922 1926                  goto bailout;
1923 1927          }
1924 1928  
1925 1929          /* Set up nvlist to pass the port number down to the driver */
1926 1930          if (nvlist_alloc(user_nvlistp, NV_UNIQUE_NAME_TYPE, NULL) != 0) {
1927 1931                  *user_nvlistp = NULL;
1928 1932                  rv = CFGA_SATA_NVLIST;
1929      -                (void) printf("nvlist_alloc failed\n");
     1933 +                DPRINTF("nvlist_alloc failed\n");
1930 1934                  goto bailout;
1931 1935          }
1932 1936  
1933 1937          /*
1934 1938           * Get port id, for Port Multiplier port, things could be a little bit
1935 1939           * complicated because of "port.port" format in ap_id, thus for
1936 1940           * port multiplier port, port number should be coded as 32bit int
1937 1941           * with the sig 16 bit as sata channel number, least 16 bit as
1938 1942           * the port number of sata port multiplier port.
1939 1943           */
1940 1944          if ((rv = get_port_num(lap_id, &port)) != CFGA_SATA_OK) {
1941      -                (void) printf(
     1945 +                DPRINTF(
1942 1946                      "setup_for_devctl_cmd: get_port_num, errno: %d\n",
1943 1947                      errno);
1944 1948                  goto bailout;
1945 1949          }
1946 1950  
1947 1951          /* Creates an int32_t entry */
1948 1952          if (nvlist_add_int32(*user_nvlistp, PORT, port) == -1) {
1949      -                (void) printf("nvlist_add_int32 failed\n");
     1953 +                DPRINTF("nvlist_add_int32 failed\n");
1950 1954                  rv = CFGA_SATA_NVLIST;
1951 1955                  goto bailout;
1952 1956          }
1953 1957  
1954 1958          free(lap_id);
1955 1959          return (rv);
1956 1960  
1957 1961  bailout:
1958 1962          free(lap_id);
1959 1963          (void) cleanup_after_devctl_cmd(*devctl_hdl, *user_nvlistp);
↓ open down ↓ 2 lines elided ↑ open up ↑
1962 1966  }
1963 1967  
1964 1968  
1965 1969  static cfga_sata_ret_t
1966 1970  port_state(devctl_hdl_t hdl, nvlist_t *list,
1967 1971      ap_rstate_t *rstate, ap_ostate_t *ostate)
1968 1972  {
1969 1973          devctl_ap_state_t       devctl_ap_state;
1970 1974  
1971 1975          if (devctl_ap_getstate(hdl, list, &devctl_ap_state) == -1) {
1972      -                (void) printf("devctl_ap_getstate failed, errno: %d\n", errno);
     1976 +                DPRINTF("devctl_ap_getstate failed, errno: %d\n", errno);
1973 1977                  return (CFGA_SATA_IOCTL);
1974 1978          }
1975 1979          *rstate = devctl_ap_state.ap_rstate;
1976 1980          *ostate =  devctl_ap_state.ap_ostate;
1977 1981          return (CFGA_SATA_OK);
1978 1982  }
1979 1983  
1980 1984  
1981 1985  /*
1982 1986   * Given a subcommand to the DEVCTL_AP_CONTROL ioctl, rquest the size of
↓ open down ↓ 15 lines elided ↑ open up ↑
1998 2002  
1999 2003          assert(descrp != NULL);
2000 2004          *descrp = NULL;
2001 2005          assert(sizep != NULL);
2002 2006  
2003 2007          if ((rv = get_port_num(ap_id, &port)) != CFGA_SATA_OK) {
2004 2008                  goto bailout;
2005 2009          }
2006 2010  
2007 2011          if ((fd = open(ap_id, O_RDONLY)) == -1) {
2008      -                (void) printf("do_control_ioctl: open failed: errno:%d\n",
     2012 +                DPRINTF("do_control_ioctl: open failed: errno:%d\n",
2009 2013                      errno);
2010 2014                  rv = CFGA_SATA_OPEN;
2011 2015                  if (errno == EBUSY) {
2012 2016                          rv = CFGA_SATA_BUSY;
2013 2017                  }
2014 2018                  goto bailout;
2015 2019          }
2016 2020  
2017 2021          ioctl_data.cmd = subcommand;
2018 2022          ioctl_data.port = port;
↓ open down ↓ 14 lines elided ↑ open up ↑
2033 2037                  ioctl_data.bufsiz = sizeof (local_size);
2034 2038  
2035 2039                  if (ioctl(fd, DEVCTL_AP_CONTROL, &ioctl_data) != 0) {
2036 2040                          perror("ioctl failed (size)");
2037 2041                          rv = CFGA_SATA_IOCTL;
2038 2042                          goto bailout;
2039 2043                  }
2040 2044                  *sizep = local_size;
2041 2045  
2042 2046                  if (local_size == 0) {
2043      -                        (void) printf("zero length data\n");
     2047 +                        DPRINTF("zero length data\n");
2044 2048                          rv = CFGA_SATA_ZEROLEN;
2045 2049                          goto bailout;
2046 2050                  }
2047 2051                  if ((*descrp = malloc(*sizep)) == NULL) {
2048      -                        (void) printf("do_control_ioctl: malloc failed\n");
     2052 +                        DPRINTF("do_control_ioctl: malloc failed\n");
2049 2053                          rv = CFGA_SATA_ALLOC_FAIL;
2050 2054                          goto bailout;
2051 2055                  }
2052 2056          } else {
2053 2057                  *sizep = 0;
2054 2058          }
2055 2059          ioctl_data.get_size = B_FALSE;
2056 2060          ioctl_data.buf = *descrp;
2057 2061          ioctl_data.bufsiz = *sizep;
2058 2062  
↓ open down ↓ 59 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX