Print this page
5552 libsun_sas leaks devids
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Jean McCormack <jean.mccormack@nexenta.com>
Reviewed by: Marcel Telka <marcel.telka@nexenta.com>


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.

  25  */
  26 
  27 #include        <sun_sas.h>
  28 #include        <sys/types.h>
  29 #include        <netinet/in.h>
  30 #include        <inttypes.h>
  31 #include        <ctype.h>
  32 #include        <sys/scsi/scsi_address.h>
  33 #include        <libdevid.h>
  34 
  35 /*
  36  * Get the preferred minor node for the given path.
  37  * ":n" for tapes, ":c,raw" for disks,
  38  * and ":0" for enclosures.
  39  */
  40 static void
  41 get_minor(char *devpath, char *minor)
  42 {
  43         const char      ROUTINE[] = "get_minor";
  44         char    fullpath[MAXPATHLEN];


 570         /* get ScsiBusNumber */
 571         mapping_ptr->entry.ScsiId.ScsiBusNumber = port_ptr->cntlNumber;
 572 
 573         (void) memcpy(mapping_ptr->entry.PortLun.PortWWN.wwn,
 574             SASAddress.wwn, 8);
 575 
 576         /* Store the devices path for now.  We'll convert to /dev later */
 577         get_minor(devpath, minorname);
 578         (void) snprintf(mapping_ptr->entry.ScsiId.OSDeviceName,
 579             sizeof (mapping_ptr->entry.ScsiId.OSDeviceName),
 580             "%s%s%s", DEVICES_DIR, devpath, minorname);
 581 
 582         /* reset errno to 0 */
 583         errno = 0;
 584         if (di_prop_lookup_strings(DDI_DEV_T_ANY, node, "devid",
 585             &propStringData) != -1) {
 586                 if (devid_str_decode(propStringData, &devid, NULL) != -1) {
 587                         guidStr = devid_to_guid(devid);
 588                         if (guidStr != NULL) {
 589                                 (void) strlcpy(mapping_ptr->entry.LUID.buffer,
 590                                     guidStr, 256);

 591                                 devid_free_guid(guidStr);
 592                         } else {
 593                                 /*
 594                                  * Note:
 595                                  * if logical unit associated page 83 id
 596                                  * descriptor is not avaialble for the device
 597                                  * devid_to_guid returns NULl with errno 0.
 598                                  */
 599                                 log(LOG_DEBUG, ROUTINE,
 600                                     "failed to get devid guid on (%s) : %s",
 601                                     devpath, strerror(errno));
 602                         }


 603                 } else {
 604                         /*
 605                          * device may not support proper page 83 id descriptor.
 606                          * leave LUID attribute to NULL and continue.
 607                          */
 608                         log(LOG_DEBUG, ROUTINE,
 609                             "failed to decode devid prop on (%s) : %s",
 610                             devpath, strerror(errno));
 611                 }
 612         } else {
 613                 /* leave LUID attribute to NULL and continue. */
 614                 log(LOG_DEBUG, ROUTINE,
 615                     "failed to get devid prop on (%s) : %s",
 616                     devpath, strerror(errno));
 617         }
 618 
 619         if (disco_port_ptr->scsiInfo == NULL) {
 620                 disco_port_ptr->scsiInfo = mapping_ptr;
 621         } else {
 622                 mapping_ptr->next = disco_port_ptr->scsiInfo;


 988         (void) snprintf(mapping_ptr->entry.ScsiId.OSDeviceName,
 989             sizeof (mapping_ptr->entry.ScsiId.OSDeviceName),
 990             "%s%s%s", DEVICES_DIR, clientdevpath, minorname);
 991 
 992         /* get luid. */
 993         errno = 0; /* reset errno to 0 */
 994         if (di_prop_lookup_strings(DDI_DEV_T_ANY, clientnode, "devid",
 995             &propStringData) != -1) {
 996                 if (devid_str_decode(propStringData, &devid, NULL) != -1) {
 997                         guidStr = devid_to_guid(devid);
 998                         if (guidStr != NULL) {
 999                                 (void) strlcpy(mapping_ptr->entry.LUID.buffer,
1000                                     guidStr,
1001                                     sizeof (mapping_ptr->entry.LUID.buffer));
1002                                 devid_free_guid(guidStr);
1003                         } else {
1004                                 /*
1005                                  * Note:
1006                                  * if logical unit associated page 83 id
1007                                  * descriptor is not avaialble for the device
1008                                  * devid_to_guid returns NULl with errno 0.
1009                                  */
1010                                 log(LOG_DEBUG, ROUTINE,
1011                                     "failed to get devid guid on (%s)",
1012                                     " associated with path(%s) : %s",
1013                                     clientdevpath,
1014                                     pathdevpath ?  pathdevpath :
1015                                     "(missing device path)",
1016                                     strerror(errno));
1017                         }


1018                 } else {
1019                         /*
1020                          * device may not support proper page 83 id descriptor.
1021                          * leave LUID attribute to NULL and continue.
1022                          */
1023                         log(LOG_DEBUG, ROUTINE,
1024                             "failed to decode devid prop on (%s)",
1025                             " associated with path(%s) : %s",
1026                             clientdevpath,
1027                             pathdevpath ?  pathdevpath :
1028                             "(missing device path)",
1029                             strerror(errno));
1030                 }
1031         } else {
1032                 /* leave LUID attribute to NULL and continue. */
1033                 log(LOG_DEBUG, ROUTINE, "Failed to get devid on %s"
1034                     " associated with path(%s) : %s", clientdevpath,
1035                     pathdevpath ?  pathdevpath : "(missing device path)",
1036                     strerror(errno));
1037         }




   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  26  */
  27 
  28 #include        <sun_sas.h>
  29 #include        <sys/types.h>
  30 #include        <netinet/in.h>
  31 #include        <inttypes.h>
  32 #include        <ctype.h>
  33 #include        <sys/scsi/scsi_address.h>
  34 #include        <libdevid.h>
  35 
  36 /*
  37  * Get the preferred minor node for the given path.
  38  * ":n" for tapes, ":c,raw" for disks,
  39  * and ":0" for enclosures.
  40  */
  41 static void
  42 get_minor(char *devpath, char *minor)
  43 {
  44         const char      ROUTINE[] = "get_minor";
  45         char    fullpath[MAXPATHLEN];


 571         /* get ScsiBusNumber */
 572         mapping_ptr->entry.ScsiId.ScsiBusNumber = port_ptr->cntlNumber;
 573 
 574         (void) memcpy(mapping_ptr->entry.PortLun.PortWWN.wwn,
 575             SASAddress.wwn, 8);
 576 
 577         /* Store the devices path for now.  We'll convert to /dev later */
 578         get_minor(devpath, minorname);
 579         (void) snprintf(mapping_ptr->entry.ScsiId.OSDeviceName,
 580             sizeof (mapping_ptr->entry.ScsiId.OSDeviceName),
 581             "%s%s%s", DEVICES_DIR, devpath, minorname);
 582 
 583         /* reset errno to 0 */
 584         errno = 0;
 585         if (di_prop_lookup_strings(DDI_DEV_T_ANY, node, "devid",
 586             &propStringData) != -1) {
 587                 if (devid_str_decode(propStringData, &devid, NULL) != -1) {
 588                         guidStr = devid_to_guid(devid);
 589                         if (guidStr != NULL) {
 590                                 (void) strlcpy(mapping_ptr->entry.LUID.buffer,
 591                                     guidStr,
 592                                     sizeof (mapping_ptr->entry.LUID.buffer));
 593                                 devid_free_guid(guidStr);
 594                         } else {
 595                                 /*
 596                                  * Note:
 597                                  * if logical unit associated page 83 id
 598                                  * descriptor is not avaialble for the device
 599                                  * devid_to_guid returns NULL with errno 0.
 600                                  */
 601                                 log(LOG_DEBUG, ROUTINE,
 602                                     "failed to get devid guid on (%s) : %s",
 603                                     devpath, strerror(errno));
 604                         }
 605 
 606                         devid_free(devid);
 607                 } else {
 608                         /*
 609                          * device may not support proper page 83 id descriptor.
 610                          * leave LUID attribute to NULL and continue.
 611                          */
 612                         log(LOG_DEBUG, ROUTINE,
 613                             "failed to decode devid prop on (%s) : %s",
 614                             devpath, strerror(errno));
 615                 }
 616         } else {
 617                 /* leave LUID attribute to NULL and continue. */
 618                 log(LOG_DEBUG, ROUTINE,
 619                     "failed to get devid prop on (%s) : %s",
 620                     devpath, strerror(errno));
 621         }
 622 
 623         if (disco_port_ptr->scsiInfo == NULL) {
 624                 disco_port_ptr->scsiInfo = mapping_ptr;
 625         } else {
 626                 mapping_ptr->next = disco_port_ptr->scsiInfo;


 992         (void) snprintf(mapping_ptr->entry.ScsiId.OSDeviceName,
 993             sizeof (mapping_ptr->entry.ScsiId.OSDeviceName),
 994             "%s%s%s", DEVICES_DIR, clientdevpath, minorname);
 995 
 996         /* get luid. */
 997         errno = 0; /* reset errno to 0 */
 998         if (di_prop_lookup_strings(DDI_DEV_T_ANY, clientnode, "devid",
 999             &propStringData) != -1) {
1000                 if (devid_str_decode(propStringData, &devid, NULL) != -1) {
1001                         guidStr = devid_to_guid(devid);
1002                         if (guidStr != NULL) {
1003                                 (void) strlcpy(mapping_ptr->entry.LUID.buffer,
1004                                     guidStr,
1005                                     sizeof (mapping_ptr->entry.LUID.buffer));
1006                                 devid_free_guid(guidStr);
1007                         } else {
1008                                 /*
1009                                  * Note:
1010                                  * if logical unit associated page 83 id
1011                                  * descriptor is not avaialble for the device
1012                                  * devid_to_guid returns NULL with errno 0.
1013                                  */
1014                                 log(LOG_DEBUG, ROUTINE,
1015                                     "failed to get devid guid on (%s)",
1016                                     " associated with path(%s) : %s",
1017                                     clientdevpath,
1018                                     pathdevpath ?  pathdevpath :
1019                                     "(missing device path)",
1020                                     strerror(errno));
1021                         }
1022 
1023                         devid_free(devid);
1024                 } else {
1025                         /*
1026                          * device may not support proper page 83 id descriptor.
1027                          * leave LUID attribute to NULL and continue.
1028                          */
1029                         log(LOG_DEBUG, ROUTINE,
1030                             "failed to decode devid prop on (%s)",
1031                             " associated with path(%s) : %s",
1032                             clientdevpath,
1033                             pathdevpath ?  pathdevpath :
1034                             "(missing device path)",
1035                             strerror(errno));
1036                 }
1037         } else {
1038                 /* leave LUID attribute to NULL and continue. */
1039                 log(LOG_DEBUG, ROUTINE, "Failed to get devid on %s"
1040                     " associated with path(%s) : %s", clientdevpath,
1041                     pathdevpath ?  pathdevpath : "(missing device path)",
1042                     strerror(errno));
1043         }