18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * - Neither the name of The Storage Networking Industry Association (SNIA)
22 * nor the names of its contributors may be used to endorse or promote
23 * products derived from this software without specific prior written
24 * permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38 #include <sys/errno.h>
39 #include <sys/types.h>
40 #include <stdlib.h>
41 #include <unistd.h>
42 #include <ctype.h>
43 #include <sys/byteorder.h>
44 #include <sys/scsi/impl/uscsi.h>
45 #include <sys/scsi/scsi.h>
46 #include <tlm.h>
47 #include <pthread.h>
48 #include "tlm_proto.h"
49
50 /*
51 * generic routine to read a SCSI page
52 */
53 int
54 read_scsi_page(scsi_link_t *slink, union scsi_cdb *cdb,
55 int command_size, caddr_t data, int size)
56 {
57 struct uscsi_cmd uscsi_cmd;
58 char *dname;
59 int dev;
64 (void) memset(&uscsi_cmd, 0, sizeof (uscsi_cmd));
65
66 /* Lun is in the 5th bit */
67 cdb->scc_lun = slink->sl_lun;
68 uscsi_cmd.uscsi_flags |= USCSI_READ | USCSI_ISOLATE;
69 uscsi_cmd.uscsi_bufaddr = data;
70 uscsi_cmd.uscsi_buflen = size;
71 uscsi_cmd.uscsi_timeout = 1000;
72 uscsi_cmd.uscsi_cdb = (char *)cdb;
73
74 if (cdb->scc_cmd == SCMD_READ_ELEMENT_STATUS) {
75 uscsi_cmd.uscsi_flags |= USCSI_RQENABLE;
76 uscsi_cmd.uscsi_rqbuf = data;
77 uscsi_cmd.uscsi_rqlen = size;
78 }
79 uscsi_cmd.uscsi_cdblen = command_size;
80
81 dname = sasd_slink_name(slink);
82 dev = open(dname, O_RDWR | O_NDELAY);
83 if (dev == -1) {
84 NDMP_LOG(LOG_DEBUG, "Open failed for %s err=%d",
85 dname, errno);
86 return (errno);
87 }
88 if (tlm_ioctl(dev, USCSICMD, &uscsi_cmd) < 0) {
89 NDMP_LOG(LOG_DEBUG, "SCSI cmd %d failed for %s err=%d",
90 cdb->scc_cmd, dname, errno);
91 (void) close(dev);
92 return (errno);
93 }
94 (void) close(dev);
95 return (uscsi_cmd.uscsi_status);
96 }
97
98 /*
99 * Read the Inquiry Page.
100 */
101 static int
102 read_inquiry_page(scsi_link_t *slink, struct scsi_inquiry *inq)
103 {
104 union scsi_cdb cdb;
105
106 (void) memset(&cdb, 0, sizeof (union scsi_cdb));
107 cdb.scc_cmd = SCMD_INQUIRY;
108 cdb.g0_count0 = sizeof (struct scsi_inquiry);
109
256 /*
257 * See if we found something.
258 * Memset above would leave wwnp not printable.
259 */
260 if (isprint(wwnp[0]))
261 return (0);
262 return (-1);
263 }
264
265 /*
266 * Add the tape library call back function (used while scanning the bus)
267 */
268 static int
269 add_lib(scsi_link_t *slink, struct scsi_inquiry *sd, void *arg)
270 {
271 int l;
272 int *nlp; /* pointer to library counter */
273 sasd_drive_t *ssd;
274
275 if (!slink || !sd) {
276 NDMP_LOG(LOG_DEBUG, "Invalid argument %x %x %x",
277 slink, sd, arg);
278 return (-TLM_INVALID);
279 }
280
281 if (sd->inq_dtype == DTYPE_CHANGER) {
282 /* This is a robot, which means this is also a library */
283 nlp = (int *)arg;
284 (*nlp)++;
285 l = tlm_insert_new_library(slink);
286 tlm_enable_barcode(l);
287
288 NDMP_LOG(LOG_DEBUG, "lib %d sid %d lun %d",
289 l, slink->sl_sid, slink->sl_lun);
290
291 if ((ssd = sasd_slink_drive(slink)) != NULL) {
292 (void) strlcpy(ssd->sd_vendor, sd->inq_vid,
293 sizeof (ssd->sd_vendor));
294 (void) strlcpy(ssd->sd_id, sd->inq_pid,
295 sizeof (ssd->sd_id));
296 (void) strlcpy(ssd->sd_rev, sd->inq_revision,
297 sizeof (ssd->sd_rev));
298 (void) read_serial_num_page(slink, ssd->sd_serial,
299 sizeof (ssd->sd_serial));
300 (void) read_device_wwn(slink, ssd->sd_wwn,
301 sizeof (ssd->sd_wwn));
302 }
303 }
304
305 return (TLM_NO_ERRORS);
306 }
307
308 /*
309 * Create some virutal slots
310 */
311 static int
312 make_virtual_slot(int l, tlm_drive_t *dp)
313 {
314 int s;
315 tlm_slot_t *sp;
316
317 if (l <= 0 || !dp) {
318 NDMP_LOG(LOG_DEBUG, "Invalid argument %d, %x", l, dp);
319 return (-TLM_INVALID);
320 }
321
322 if ((s = tlm_insert_new_slot(l)) <= 0)
323 return (-TLM_NO_MEMORY);
324
325 if (!(sp = tlm_slot(l, s))) {
326 NDMP_LOG(LOG_DEBUG, "Internal error: slot not found %d", s);
327 return (-TLM_ERROR_INTERNAL);
328 }
329 /*
330 * For virtual slots element number is 0 and they are always full.
331 */
332 sp->ts_element = 0;
333 sp->ts_status_full = TRUE;
334 return (TLM_NO_ERRORS);
335 }
336
337 /*
338 * Make the tape drive not part of a tape library (stand alone)
339 */
340 static int
341 make_stand_alone_drive(scsi_link_t *slink, int l)
342 {
343 int d;
344 tlm_drive_t *dp;
345
346 if (!slink || l <= 0) {
347 NDMP_LOG(LOG_DEBUG, "Invalid argument %x %d", slink, l);
348 return (-TLM_INVALID);
349 }
350
351 d = tlm_insert_new_drive(l);
352 if (!(dp = tlm_drive(l, d))) {
353 NDMP_LOG(LOG_DEBUG, "Internal error: drive not found %d", d);
354 return (-TLM_ERROR_INTERNAL);
355 }
356
357 /* For stand-alone drives, the element number is the drive number. */
358 dp->td_element = d;
359 dp->td_slink = slink;
360 dp->td_scsi_id = slink->sl_sid;
361 dp->td_lun = slink->sl_lun;
362 dp->td_exists = TRUE;
363
364 /*
365 * Note: There is no way to remove library elements. We cannot clean
366 * up if make_virtual_slot() fails.
367 */
368 (void) make_virtual_slot(l, dp);
369 return (d);
370 }
371
372 /*
373 * Find the LIBRARY structure that has control of this DRIVE.
394 }
395
396 /* Not part of any library, this is a newly found tape drive. */
397 return (0);
398 }
399
400
401 /*
402 * Add the tape library call back function (used while scanning the bus)
403 */
404 static int
405 add_drv(scsi_link_t *slink, struct scsi_inquiry *sd, void *arg)
406 {
407 int l, d;
408 int *vlp; /* pointer to virtual library number */
409 sasd_drive_t *ssd;
410 tlm_library_t *library;
411 tlm_drive_t *drive;
412
413 if (!slink || !sd) {
414 NDMP_LOG(LOG_DEBUG, "Invalid argument %x %x %x",
415 slink, sd, arg);
416 return (-TLM_INVALID);
417 }
418
419 if (sd->inq_dtype == DTYPE_SEQUENTIAL) {
420 vlp = (int *)arg;
421 d = new_drive(slink, &l);
422 if (d == 0) {
423 /* This tape drive was not found inside any robot. */
424 if (*vlp == 0) {
425 /*
426 * First, create a virtual library if it's not
427 * done yet.
428 */
429 *vlp = tlm_insert_new_library(slink);
430 if ((library = tlm_library(*vlp)) != NULL)
431 library->tl_capability_robot = FALSE;
432 }
433 if ((d = make_stand_alone_drive(slink, *vlp)) < 0) {
434 /* sorry, we can not clean up the vlib now * */
435 return (-TLM_INVALID);
436 }
437 l = *vlp;
438 NDMP_LOG(LOG_DEBUG, "vlib(%d, %d) sid %d lun %d",
439 l, d, slink->sl_sid, slink->sl_lun);
440 } else
441 NDMP_LOG(LOG_DEBUG, "(%d, %d) sid %d lun %d",
442 l, d, slink->sl_sid, slink->sl_lun);
443
444 if ((drive = tlm_drive(l, d)) != NULL) {
445 drive->td_exists = TRUE;
446 drive->td_slink = slink;
447 }
448 if ((ssd = sasd_slink_drive(slink)) != NULL) {
449 (void) strlcpy(ssd->sd_vendor,
450 sd->inq_vid, sizeof (ssd->sd_vendor));
451 (void) strlcpy(ssd->sd_id, sd->inq_pid,
452 sizeof (ssd->sd_id));
453 (void) strlcpy(ssd->sd_rev, sd->inq_revision,
454 sizeof (ssd->sd_rev));
455 (void) read_serial_num_page(slink, ssd->sd_serial,
456 sizeof (ssd->sd_serial));
457 (void) read_device_wwn(slink, ssd->sd_wwn,
458 sizeof (ssd->sd_wwn));
459 }
460 }
461
486 return (nerr);
487 }
488
489 /*
490 * Marks the library/slots inaccessible if there are not enough drives
491 * available on the library
492 */
493 static void
494 inaccbl_drv_warn(int start, int max)
495 {
496 char *dname;
497 int l, d;
498 tlm_library_t *lp;
499
500 for (l = start; l < max; l++) {
501 if (!(lp = tlm_library(l)))
502 continue;
503 if (lp->tl_drive_count <= 0)
504 continue;
505
506 NDMP_LOG(LOG_DEBUG,
507 "Warning: The following drives are not accessible:");
508 for (d = 1; d <= lp->tl_drive_count; d++)
509 if (!(dname = tlm_get_tape_name(l, d))) {
510 NDMP_LOG(LOG_DEBUG,
511 "Error getting drive(%d, %d)", l, d);
512 } else
513 NDMP_LOG(LOG_DEBUG, "%s", dname);
514
515 /*
516 * Note: Make the slots inaccessible to prevent running
517 * discovery on these libraries. The better idea is
518 * removing these libraries, but we don't have that
519 * feature available now.
520 */
521 lp->tl_slot_count = 0;
522 }
523 }
524
525 /*
526 * Initialize the tape library data structure, asks the libraries what
527 * equipments they have.
528 */
529 int
530 tlm_init(void)
531 {
532 static int nlibs; /* number of found libraries */
533 int i, nsa;
536 scsi_adapter_t *sa;
537 tlm_library_t *lp;
538 tlm_drive_t *dp;
539
540 /* Search through all SCSI adapters, look for tape robots. */
541 nlibs = 0;
542
543 /*
544 * We probe both changers and tape drives here
545 * but later on this needs to be removed as the
546 * probe will happen somewhere else.
547 */
548 if (probe_scsi() < 0)
549 return (-1);
550
551 nsa = scsi_get_adapter_count();
552 for (i = 0; i < nsa; i++)
553 if ((sa = scsi_get_adapter(i)))
554 (void) scan_bus(sa, add_lib, (void *)&nlibs);
555
556 NDMP_LOG(LOG_DEBUG, "nlibs %d", nlibs);
557
558 /* Search through all SCSI adapters, look for tape drives. */
559 vlibs = 0;
560 for (i = 0; i < nsa; i++)
561 if ((sa = scsi_get_adapter(i)))
562 (void) scan_bus(sa, add_drv, (void *)&vlibs);
563
564 NDMP_LOG(LOG_DEBUG, "vlibs %d", vlibs);
565
566 if (nlibs > 0 && vlibs > 0)
567 inaccbl_drv_warn(nlibs + 1, vlibs + nlibs + 1);
568
569 for (l = 1; l <= tlm_library_count(); l++) {
570 if (!(lp = tlm_library(l))) {
571 NDMP_LOG(LOG_DEBUG, "can't find lib %d", l);
572 continue;
573 }
574
575 /*
576 * Make sure all libraries have tape drives.
577 */
578 if (lp->tl_drive_count == 0)
579 continue;
580
581 /*
582 * Make sure all tape drives exist. A drive that is not
583 * linked into the SCSI chain will be seen by the library
584 * but we cannot talk to it.
585 */
586 for (d = 1; d <= lp->tl_drive_count; d++) {
587 dp = tlm_drive(l, d);
588 if (dp && !dp->td_exists) {
589 NDMP_LOG(LOG_DEBUG, "Ghost drive found %d.%d",
590 l, d);
591 lp->tl_ghost_drives = TRUE;
592 continue;
593 }
594 }
595 }
596
597 if (nlibs > 0)
598 rv = (vlibs > 0) ? 0 : nlibs;
599 else
600 rv = vlibs;
601
602 return (rv);
603 }
|
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * - Neither the name of The Storage Networking Industry Association (SNIA)
22 * nor the names of its contributors may be used to endorse or promote
23 * products derived from this software without specific prior written
24 * permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38 /* Copyright 2016 Nexenta Systems, Inc. All rights reserved. */
39
40 #include <sys/errno.h>
41 #include <sys/types.h>
42 #include <syslog.h>
43 #include <stdlib.h>
44 #include <unistd.h>
45 #include <ctype.h>
46 #include <sys/byteorder.h>
47 #include <sys/scsi/impl/uscsi.h>
48 #include <sys/scsi/scsi.h>
49 #include <tlm.h>
50 #include <pthread.h>
51 #include "tlm_proto.h"
52
53 /*
54 * generic routine to read a SCSI page
55 */
56 int
57 read_scsi_page(scsi_link_t *slink, union scsi_cdb *cdb,
58 int command_size, caddr_t data, int size)
59 {
60 struct uscsi_cmd uscsi_cmd;
61 char *dname;
62 int dev;
67 (void) memset(&uscsi_cmd, 0, sizeof (uscsi_cmd));
68
69 /* Lun is in the 5th bit */
70 cdb->scc_lun = slink->sl_lun;
71 uscsi_cmd.uscsi_flags |= USCSI_READ | USCSI_ISOLATE;
72 uscsi_cmd.uscsi_bufaddr = data;
73 uscsi_cmd.uscsi_buflen = size;
74 uscsi_cmd.uscsi_timeout = 1000;
75 uscsi_cmd.uscsi_cdb = (char *)cdb;
76
77 if (cdb->scc_cmd == SCMD_READ_ELEMENT_STATUS) {
78 uscsi_cmd.uscsi_flags |= USCSI_RQENABLE;
79 uscsi_cmd.uscsi_rqbuf = data;
80 uscsi_cmd.uscsi_rqlen = size;
81 }
82 uscsi_cmd.uscsi_cdblen = command_size;
83
84 dname = sasd_slink_name(slink);
85 dev = open(dname, O_RDWR | O_NDELAY);
86 if (dev == -1) {
87 syslog(LOG_DEBUG, "Open failed for %s err=%d",
88 dname, errno);
89 return (errno);
90 }
91 if (tlm_ioctl(dev, USCSICMD, &uscsi_cmd) < 0) {
92 syslog(LOG_DEBUG, "SCSI cmd %d failed for %s err=%d",
93 cdb->scc_cmd, dname, errno);
94 (void) close(dev);
95 return (errno);
96 }
97 (void) close(dev);
98 return (uscsi_cmd.uscsi_status);
99 }
100
101 /*
102 * Read the Inquiry Page.
103 */
104 static int
105 read_inquiry_page(scsi_link_t *slink, struct scsi_inquiry *inq)
106 {
107 union scsi_cdb cdb;
108
109 (void) memset(&cdb, 0, sizeof (union scsi_cdb));
110 cdb.scc_cmd = SCMD_INQUIRY;
111 cdb.g0_count0 = sizeof (struct scsi_inquiry);
112
259 /*
260 * See if we found something.
261 * Memset above would leave wwnp not printable.
262 */
263 if (isprint(wwnp[0]))
264 return (0);
265 return (-1);
266 }
267
268 /*
269 * Add the tape library call back function (used while scanning the bus)
270 */
271 static int
272 add_lib(scsi_link_t *slink, struct scsi_inquiry *sd, void *arg)
273 {
274 int l;
275 int *nlp; /* pointer to library counter */
276 sasd_drive_t *ssd;
277
278 if (!slink || !sd) {
279 syslog(LOG_DEBUG, "Invalid argument %x %x %x",
280 slink, sd, arg);
281 return (-TLM_INVALID);
282 }
283
284 if (sd->inq_dtype == DTYPE_CHANGER) {
285 /* This is a robot, which means this is also a library */
286 nlp = (int *)arg;
287 (*nlp)++;
288 l = tlm_insert_new_library(slink);
289 tlm_enable_barcode(l);
290
291 syslog(LOG_DEBUG, "lib %d sid %d lun %d",
292 l, slink->sl_sid, slink->sl_lun);
293
294 if ((ssd = sasd_slink_drive(slink)) != NULL) {
295 (void) strlcpy(ssd->sd_vendor, sd->inq_vid,
296 sizeof (ssd->sd_vendor));
297 (void) strlcpy(ssd->sd_id, sd->inq_pid,
298 sizeof (ssd->sd_id));
299 (void) strlcpy(ssd->sd_rev, sd->inq_revision,
300 sizeof (ssd->sd_rev));
301 (void) read_serial_num_page(slink, ssd->sd_serial,
302 sizeof (ssd->sd_serial));
303 (void) read_device_wwn(slink, ssd->sd_wwn,
304 sizeof (ssd->sd_wwn));
305 }
306 }
307
308 return (TLM_NO_ERRORS);
309 }
310
311 /*
312 * Create some virutal slots
313 */
314 static int
315 make_virtual_slot(int l, tlm_drive_t *dp)
316 {
317 int s;
318 tlm_slot_t *sp;
319
320 if (l <= 0 || !dp) {
321 syslog(LOG_DEBUG, "Invalid argument %d, %x", l, dp);
322 return (-TLM_INVALID);
323 }
324
325 if ((s = tlm_insert_new_slot(l)) <= 0)
326 return (-TLM_NO_MEMORY);
327
328 if (!(sp = tlm_slot(l, s))) {
329 syslog(LOG_DEBUG, "Internal error: slot not found %d", s);
330 return (-TLM_ERROR_INTERNAL);
331 }
332 /*
333 * For virtual slots element number is 0 and they are always full.
334 */
335 sp->ts_element = 0;
336 sp->ts_status_full = TRUE;
337 return (TLM_NO_ERRORS);
338 }
339
340 /*
341 * Make the tape drive not part of a tape library (stand alone)
342 */
343 static int
344 make_stand_alone_drive(scsi_link_t *slink, int l)
345 {
346 int d;
347 tlm_drive_t *dp;
348
349 if (!slink || l <= 0) {
350 syslog(LOG_DEBUG, "Invalid argument %x %d", slink, l);
351 return (-TLM_INVALID);
352 }
353
354 d = tlm_insert_new_drive(l);
355 if (!(dp = tlm_drive(l, d))) {
356 syslog(LOG_DEBUG, "Internal error: drive not found %d", d);
357 return (-TLM_ERROR_INTERNAL);
358 }
359
360 /* For stand-alone drives, the element number is the drive number. */
361 dp->td_element = d;
362 dp->td_slink = slink;
363 dp->td_scsi_id = slink->sl_sid;
364 dp->td_lun = slink->sl_lun;
365 dp->td_exists = TRUE;
366
367 /*
368 * Note: There is no way to remove library elements. We cannot clean
369 * up if make_virtual_slot() fails.
370 */
371 (void) make_virtual_slot(l, dp);
372 return (d);
373 }
374
375 /*
376 * Find the LIBRARY structure that has control of this DRIVE.
397 }
398
399 /* Not part of any library, this is a newly found tape drive. */
400 return (0);
401 }
402
403
404 /*
405 * Add the tape library call back function (used while scanning the bus)
406 */
407 static int
408 add_drv(scsi_link_t *slink, struct scsi_inquiry *sd, void *arg)
409 {
410 int l, d;
411 int *vlp; /* pointer to virtual library number */
412 sasd_drive_t *ssd;
413 tlm_library_t *library;
414 tlm_drive_t *drive;
415
416 if (!slink || !sd) {
417 syslog(LOG_DEBUG, "Invalid argument %x %x %x",
418 slink, sd, arg);
419 return (-TLM_INVALID);
420 }
421
422 if (sd->inq_dtype == DTYPE_SEQUENTIAL) {
423 vlp = (int *)arg;
424 d = new_drive(slink, &l);
425 if (d == 0) {
426 /* This tape drive was not found inside any robot. */
427 if (*vlp == 0) {
428 /*
429 * First, create a virtual library if it's not
430 * done yet.
431 */
432 *vlp = tlm_insert_new_library(slink);
433 if ((library = tlm_library(*vlp)) != NULL)
434 library->tl_capability_robot = FALSE;
435 }
436 if ((d = make_stand_alone_drive(slink, *vlp)) < 0) {
437 /* sorry, we can not clean up the vlib now * */
438 return (-TLM_INVALID);
439 }
440 l = *vlp;
441 syslog(LOG_DEBUG, "vlib(%d, %d) sid %d lun %d",
442 l, d, slink->sl_sid, slink->sl_lun);
443 } else
444 syslog(LOG_DEBUG, "(%d, %d) sid %d lun %d",
445 l, d, slink->sl_sid, slink->sl_lun);
446
447 if ((drive = tlm_drive(l, d)) != NULL) {
448 drive->td_exists = TRUE;
449 drive->td_slink = slink;
450 }
451 if ((ssd = sasd_slink_drive(slink)) != NULL) {
452 (void) strlcpy(ssd->sd_vendor,
453 sd->inq_vid, sizeof (ssd->sd_vendor));
454 (void) strlcpy(ssd->sd_id, sd->inq_pid,
455 sizeof (ssd->sd_id));
456 (void) strlcpy(ssd->sd_rev, sd->inq_revision,
457 sizeof (ssd->sd_rev));
458 (void) read_serial_num_page(slink, ssd->sd_serial,
459 sizeof (ssd->sd_serial));
460 (void) read_device_wwn(slink, ssd->sd_wwn,
461 sizeof (ssd->sd_wwn));
462 }
463 }
464
489 return (nerr);
490 }
491
492 /*
493 * Marks the library/slots inaccessible if there are not enough drives
494 * available on the library
495 */
496 static void
497 inaccbl_drv_warn(int start, int max)
498 {
499 char *dname;
500 int l, d;
501 tlm_library_t *lp;
502
503 for (l = start; l < max; l++) {
504 if (!(lp = tlm_library(l)))
505 continue;
506 if (lp->tl_drive_count <= 0)
507 continue;
508
509 syslog(LOG_DEBUG,
510 "Warning: The following drives are not accessible:");
511 for (d = 1; d <= lp->tl_drive_count; d++)
512 if (!(dname = tlm_get_tape_name(l, d))) {
513 syslog(LOG_DEBUG,
514 "Error getting drive(%d, %d)", l, d);
515 } else
516 syslog(LOG_DEBUG, "%s", dname);
517
518 /*
519 * Note: Make the slots inaccessible to prevent running
520 * discovery on these libraries. The better idea is
521 * removing these libraries, but we don't have that
522 * feature available now.
523 */
524 lp->tl_slot_count = 0;
525 }
526 }
527
528 /*
529 * Initialize the tape library data structure, asks the libraries what
530 * equipments they have.
531 */
532 int
533 tlm_init(void)
534 {
535 static int nlibs; /* number of found libraries */
536 int i, nsa;
539 scsi_adapter_t *sa;
540 tlm_library_t *lp;
541 tlm_drive_t *dp;
542
543 /* Search through all SCSI adapters, look for tape robots. */
544 nlibs = 0;
545
546 /*
547 * We probe both changers and tape drives here
548 * but later on this needs to be removed as the
549 * probe will happen somewhere else.
550 */
551 if (probe_scsi() < 0)
552 return (-1);
553
554 nsa = scsi_get_adapter_count();
555 for (i = 0; i < nsa; i++)
556 if ((sa = scsi_get_adapter(i)))
557 (void) scan_bus(sa, add_lib, (void *)&nlibs);
558
559 /* Search through all SCSI adapters, look for tape drives. */
560 vlibs = 0;
561 for (i = 0; i < nsa; i++)
562 if ((sa = scsi_get_adapter(i)))
563 (void) scan_bus(sa, add_drv, (void *)&vlibs);
564
565 if (nlibs > 0 && vlibs > 0)
566 inaccbl_drv_warn(nlibs + 1, vlibs + nlibs + 1);
567
568 for (l = 1; l <= tlm_library_count(); l++) {
569 if (!(lp = tlm_library(l))) {
570 syslog(LOG_DEBUG, "can't find lib %d", l);
571 continue;
572 }
573
574 /*
575 * Make sure all libraries have tape drives.
576 */
577 if (lp->tl_drive_count == 0)
578 continue;
579
580 /*
581 * Make sure all tape drives exist. A drive that is not
582 * linked into the SCSI chain will be seen by the library
583 * but we cannot talk to it.
584 */
585 for (d = 1; d <= lp->tl_drive_count; d++) {
586 dp = tlm_drive(l, d);
587 if (dp && !dp->td_exists) {
588 syslog(LOG_DEBUG, "Ghost drive found %d.%d",
589 l, d);
590 lp->tl_ghost_drives = TRUE;
591 continue;
592 }
593 }
594 }
595
596 if (nlibs > 0)
597 rv = (vlibs > 0) ? 0 : nlibs;
598 else
599 rv = vlibs;
600
601 return (rv);
602 }
|