mpt_cam.c (204090) | mpt_cam.c (215046) |
---|---|
1/*- 2 * Copyright (c) 2008 Yahoo!, Inc. 3 * All rights reserved. 4 * Written by: John Baldwin <jhb@FreeBSD.org> 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 15 unchanged lines hidden (view full) --- 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2008 Yahoo!, Inc. 3 * All rights reserved. 4 * Written by: John Baldwin <jhb@FreeBSD.org> 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 15 unchanged lines hidden (view full) --- 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31#include <sys/cdefs.h> |
32__RCSID("$FreeBSD: head/usr.sbin/mptutil/mpt_cam.c 204090 2010-02-19 15:16:00Z jhb $"); | 32__RCSID("$FreeBSD: head/usr.sbin/mptutil/mpt_cam.c 215046 2010-11-09 19:28:06Z jhb $"); |
33 34#include <sys/param.h> 35#include <err.h> 36#include <errno.h> 37#include <fcntl.h> 38#include <stdio.h> 39#include <stdlib.h> 40#include <string.h> --- 17 unchanged lines hidden (view full) --- 58 59/* Fetch the path id of bus 0 for the opened mpt controller. */ 60static int 61fetch_path_id(path_id_t *path_id) 62{ 63 struct bus_match_pattern *b; 64 union ccb ccb; 65 size_t bufsize; | 33 34#include <sys/param.h> 35#include <err.h> 36#include <errno.h> 37#include <fcntl.h> 38#include <stdio.h> 39#include <stdlib.h> 40#include <string.h> --- 17 unchanged lines hidden (view full) --- 58 59/* Fetch the path id of bus 0 for the opened mpt controller. */ 60static int 61fetch_path_id(path_id_t *path_id) 62{ 63 struct bus_match_pattern *b; 64 union ccb ccb; 65 size_t bufsize; |
66 int error; |
|
66 67 if (xpt_open() < 0) 68 return (ENXIO); 69 70 /* First, find the path id of bus 0 for this mpt controller. */ 71 bzero(&ccb, sizeof(ccb)); 72 73 ccb.ccb_h.func_code = XPT_DEV_MATCH; --- 12 unchanged lines hidden (view full) --- 86 ccb.cdm.patterns[0].type = DEV_MATCH_BUS; 87 b = &ccb.cdm.patterns[0].pattern.bus_pattern; 88 snprintf(b->dev_name, sizeof(b->dev_name), "mpt"); 89 b->unit_number = mpt_unit; 90 b->bus_id = 0; 91 b->flags = BUS_MATCH_NAME | BUS_MATCH_UNIT | BUS_MATCH_BUS_ID; 92 93 if (ioctl(xptfd, CAMIOCOMMAND, &ccb) < 0) { | 67 68 if (xpt_open() < 0) 69 return (ENXIO); 70 71 /* First, find the path id of bus 0 for this mpt controller. */ 72 bzero(&ccb, sizeof(ccb)); 73 74 ccb.ccb_h.func_code = XPT_DEV_MATCH; --- 12 unchanged lines hidden (view full) --- 87 ccb.cdm.patterns[0].type = DEV_MATCH_BUS; 88 b = &ccb.cdm.patterns[0].pattern.bus_pattern; 89 snprintf(b->dev_name, sizeof(b->dev_name), "mpt"); 90 b->unit_number = mpt_unit; 91 b->bus_id = 0; 92 b->flags = BUS_MATCH_NAME | BUS_MATCH_UNIT | BUS_MATCH_BUS_ID; 93 94 if (ioctl(xptfd, CAMIOCOMMAND, &ccb) < 0) { |
95 error = errno; |
|
94 free(ccb.cdm.matches); 95 free(ccb.cdm.patterns); | 96 free(ccb.cdm.matches); 97 free(ccb.cdm.patterns); |
96 return (errno); | 98 return (error); |
97 } 98 free(ccb.cdm.patterns); 99 100 if (((ccb.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) || 101 (ccb.cdm.status != CAM_DEV_MATCH_LAST)) { 102 warnx("fetch_path_id got CAM error %#x, CDM error %d\n", 103 ccb.ccb_h.status, ccb.cdm.status); 104 free(ccb.cdm.matches); --- 14 unchanged lines hidden (view full) --- 119int 120mpt_query_disk(U8 VolumeBus, U8 VolumeID, struct mpt_query_disk *qd) 121{ 122 struct periph_match_pattern *p; 123 struct periph_match_result *r; 124 union ccb ccb; 125 path_id_t path_id; 126 size_t bufsize; | 99 } 100 free(ccb.cdm.patterns); 101 102 if (((ccb.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) || 103 (ccb.cdm.status != CAM_DEV_MATCH_LAST)) { 104 warnx("fetch_path_id got CAM error %#x, CDM error %d\n", 105 ccb.ccb_h.status, ccb.cdm.status); 106 free(ccb.cdm.matches); --- 14 unchanged lines hidden (view full) --- 121int 122mpt_query_disk(U8 VolumeBus, U8 VolumeID, struct mpt_query_disk *qd) 123{ 124 struct periph_match_pattern *p; 125 struct periph_match_result *r; 126 union ccb ccb; 127 path_id_t path_id; 128 size_t bufsize; |
127 int error, i; | 129 int error; |
128 129 /* mpt(4) only handles devices on bus 0. */ 130 if (VolumeBus != 0) 131 return (ENXIO); 132 133 if (xpt_open() < 0) 134 return (ENXIO); 135 --- 23 unchanged lines hidden (view full) --- 159 ccb.cdm.patterns[0].type = DEV_MATCH_PERIPH; 160 p = &ccb.cdm.patterns[0].pattern.periph_pattern; 161 p->path_id = path_id; 162 snprintf(p->periph_name, sizeof(p->periph_name), "da"); 163 p->target_id = VolumeID; 164 p->flags = PERIPH_MATCH_PATH | PERIPH_MATCH_NAME | PERIPH_MATCH_TARGET; 165 166 if (ioctl(xptfd, CAMIOCOMMAND, &ccb) < 0) { | 130 131 /* mpt(4) only handles devices on bus 0. */ 132 if (VolumeBus != 0) 133 return (ENXIO); 134 135 if (xpt_open() < 0) 136 return (ENXIO); 137 --- 23 unchanged lines hidden (view full) --- 161 ccb.cdm.patterns[0].type = DEV_MATCH_PERIPH; 162 p = &ccb.cdm.patterns[0].pattern.periph_pattern; 163 p->path_id = path_id; 164 snprintf(p->periph_name, sizeof(p->periph_name), "da"); 165 p->target_id = VolumeID; 166 p->flags = PERIPH_MATCH_PATH | PERIPH_MATCH_NAME | PERIPH_MATCH_TARGET; 167 168 if (ioctl(xptfd, CAMIOCOMMAND, &ccb) < 0) { |
167 i = errno; | 169 error = errno; |
168 free(ccb.cdm.matches); 169 free(ccb.cdm.patterns); | 170 free(ccb.cdm.matches); 171 free(ccb.cdm.patterns); |
170 return (i); | 172 return (error); |
171 } 172 free(ccb.cdm.patterns); 173 174 if (((ccb.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) || 175 (ccb.cdm.status != CAM_DEV_MATCH_LAST)) { 176 warnx("mpt_query_disk got CAM error %#x, CDM error %d\n", 177 ccb.ccb_h.status, ccb.cdm.status); 178 free(ccb.cdm.matches); --- 213 unchanged lines hidden (view full) --- 392 CONFIG_PAGE_IOC_2 *ioc2; 393 struct mpt_standalone_disk *disks; 394 struct periph_match_pattern *p; 395 struct periph_match_result *r; 396 struct cam_device *dev; 397 union ccb ccb; 398 path_id_t path_id; 399 size_t bufsize; | 173 } 174 free(ccb.cdm.patterns); 175 176 if (((ccb.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) || 177 (ccb.cdm.status != CAM_DEV_MATCH_LAST)) { 178 warnx("mpt_query_disk got CAM error %#x, CDM error %d\n", 179 ccb.ccb_h.status, ccb.cdm.status); 180 free(ccb.cdm.matches); --- 213 unchanged lines hidden (view full) --- 394 CONFIG_PAGE_IOC_2 *ioc2; 395 struct mpt_standalone_disk *disks; 396 struct periph_match_pattern *p; 397 struct periph_match_result *r; 398 struct cam_device *dev; 399 union ccb ccb; 400 path_id_t path_id; 401 size_t bufsize; |
400 u_int i; | |
401 int count, error; | 402 int count, error; |
403 uint32_t i; |
|
402 403 if (xpt_open() < 0) 404 return (ENXIO); 405 406 error = fetch_path_id(&path_id); 407 if (error) 408 return (error); 409 --- 16 unchanged lines hidden (view full) --- 426 /* Match any "da" peripherals. */ 427 ccb.cdm.patterns[0].type = DEV_MATCH_PERIPH; 428 p = &ccb.cdm.patterns[0].pattern.periph_pattern; 429 p->path_id = path_id; 430 snprintf(p->periph_name, sizeof(p->periph_name), "da"); 431 p->flags = PERIPH_MATCH_PATH | PERIPH_MATCH_NAME; 432 433 if (ioctl(xptfd, CAMIOCOMMAND, &ccb) < 0) { | 404 405 if (xpt_open() < 0) 406 return (ENXIO); 407 408 error = fetch_path_id(&path_id); 409 if (error) 410 return (error); 411 --- 16 unchanged lines hidden (view full) --- 428 /* Match any "da" peripherals. */ 429 ccb.cdm.patterns[0].type = DEV_MATCH_PERIPH; 430 p = &ccb.cdm.patterns[0].pattern.periph_pattern; 431 p->path_id = path_id; 432 snprintf(p->periph_name, sizeof(p->periph_name), "da"); 433 p->flags = PERIPH_MATCH_PATH | PERIPH_MATCH_NAME; 434 435 if (ioctl(xptfd, CAMIOCOMMAND, &ccb) < 0) { |
434 i = errno; | 436 error = errno; |
435 free(ccb.cdm.matches); 436 free(ccb.cdm.patterns); | 437 free(ccb.cdm.matches); 438 free(ccb.cdm.patterns); |
437 return (i); | 439 return (error); |
438 } 439 free(ccb.cdm.patterns); 440 441 /* Check for CCB errors. */ 442 if ((ccb.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 443 free(ccb.cdm.matches); 444 return (EIO); 445 } --- 30 unchanged lines hidden (view full) --- 476 } 477 478 /* 479 * Some of the "da" peripherals may be for RAID volumes, so 480 * fetch the IOC 2 page (list of RAID volumes) so we can 481 * exclude them from the list. 482 */ 483 ioc2 = mpt_read_ioc_page(fd, 2, NULL); | 440 } 441 free(ccb.cdm.patterns); 442 443 /* Check for CCB errors. */ 444 if ((ccb.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 445 free(ccb.cdm.matches); 446 return (EIO); 447 } --- 30 unchanged lines hidden (view full) --- 478 } 479 480 /* 481 * Some of the "da" peripherals may be for RAID volumes, so 482 * fetch the IOC 2 page (list of RAID volumes) so we can 483 * exclude them from the list. 484 */ 485 ioc2 = mpt_read_ioc_page(fd, 2, NULL); |
486 if (ioc2 == NULL) 487 return (errno); |
|
484 disks = calloc(ccb.cdm.num_matches, sizeof(*disks)); 485 count = 0; 486 for (i = 0; i < ccb.cdm.num_matches; i++) { 487 r = &ccb.cdm.matches[i].result.periph_result; 488 if (periph_is_volume(ioc2, r)) 489 continue; 490 disks[count].bus = 0; 491 disks[count].target = r->target_id; --- 74 unchanged lines hidden --- | 488 disks = calloc(ccb.cdm.num_matches, sizeof(*disks)); 489 count = 0; 490 for (i = 0; i < ccb.cdm.num_matches; i++) { 491 r = &ccb.cdm.matches[i].result.periph_result; 492 if (periph_is_volume(ioc2, r)) 493 continue; 494 disks[count].bus = 0; 495 disks[count].target = r->target_id; --- 74 unchanged lines hidden --- |