xref: /illumos-gate/usr/src/lib/mpapi/libmpscsi_vhci/common/MP_DisablePath.c (revision 89b2a9fbeabf42fa54594df0e5927bcc50a07cc9)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <syslog.h>
27 #include <errno.h>
28 #include <unistd.h>
29 #include <stropts.h>
30 
31 #include "mp_utils.h"
32 
33 
34 /*
35  *	Called by the common layer to request to disable a path
36  */
37 
38 MP_STATUS
39 MP_DisablePath(MP_OID oid)
40 {
41 	mp_iocdata_t mp_ioctl;
42 
43 	int ioctlStatus = 0;
44 
45 	MP_STATUS mpStatus = MP_STATUS_SUCCESS;
46 
47 
48 
49 	log(LOG_INFO, "MP_DisablePath()", " - enter");
50 
51 
52 	log(LOG_INFO, "MP_DisablePath()",
53 		"oid.objectSequenceNumber = %llx",
54 		oid.objectSequenceNumber);
55 
56 	if (g_scsi_vhci_fd < 0) {
57 		log(LOG_INFO, "MP_DisablePath()",
58 		    "invalid driver file handle");
59 		log(LOG_INFO, "MP_DisablePath()", " - error exit");
60 		return (MP_STATUS_FAILED);
61 	}
62 
63 	(void) memset(&mp_ioctl, 0, sizeof (mp_iocdata_t));
64 
65 	mp_ioctl.mp_cmd  = MP_DISABLE_PATH;
66 	mp_ioctl.mp_ibuf = (caddr_t)&oid.objectSequenceNumber;
67 	mp_ioctl.mp_ilen = sizeof (oid.objectSequenceNumber);
68 	mp_ioctl.mp_xfer =  MP_XFER_WRITE;
69 
70 	log(LOG_INFO, "MP_DisablePath()",
71 		"mp_ioctl.mp_cmd (MP_DISABLE_PATH) : %d",
72 		mp_ioctl.mp_cmd);
73 
74 	ioctlStatus = ioctl(g_scsi_vhci_fd, MP_CMD, &mp_ioctl);
75 
76 	log(LOG_INFO, "MP_DisablePath()",
77 		" IOCTL call returned: %d", ioctlStatus);
78 
79 	if (ioctlStatus < 0) {
80 		ioctlStatus = errno;
81 	}
82 
83 	if (ioctlStatus != 0) {
84 		log(LOG_INFO, "MP_DisablePath()",
85 		    "IOCTL call failed.  IOCTL error is: %d",
86 			ioctlStatus);
87 		log(LOG_INFO, "MP_DisablePath()",
88 		    "IOCTL call failed.  IOCTL error is: %s",
89 			strerror(ioctlStatus));
90 		log(LOG_INFO, "MP_DisablePath()",
91 		    "IOCTL call failed.  mp_ioctl.mp_errno: %x",
92 			mp_ioctl.mp_errno);
93 
94 		if (ENOTSUP == ioctlStatus) {
95 			mpStatus = MP_STATUS_UNSUPPORTED;
96 		} else if (0 == mp_ioctl.mp_errno) {
97 			mpStatus = MP_STATUS_FAILED;
98 		} else {
99 			mpStatus = getStatus4ErrorCode(mp_ioctl.mp_errno);
100 		}
101 
102 		log(LOG_INFO, "MP_DisablePath()",
103 			" - error exit");
104 
105 		return (mpStatus);
106 	}
107 
108 
109 	log(LOG_INFO, "MP_DisablePath()", " - exit");
110 
111 	return (MP_STATUS_SUCCESS);
112 }
113