1/*- 2 * Copyright (c) 2010 Alexander Motin <mav@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/geom/raid/md_jmicron.c 220210 2011-03-31 16:19:53Z mav $"); |
29 30#include <sys/param.h> 31#include <sys/bio.h> 32#include <sys/endian.h> 33#include <sys/kernel.h> 34#include <sys/kobj.h> 35#include <sys/limits.h> 36#include <sys/lock.h> --- 537 unchanged lines hidden (view full) --- 574 free(arg, M_MD_JMICRON); 575} 576 577static void 578g_raid_md_jmicron_refill(struct g_raid_softc *sc) 579{ 580 struct g_raid_md_object *md; 581 struct g_raid_md_jmicron_object *mdi; |
582 struct g_raid_disk *disk; 583 struct task *task; 584 int update, na; 585 586 md = sc->sc_md; 587 mdi = (struct g_raid_md_jmicron_object *)md; |
588 update = 0; 589 do { 590 /* Make sure we miss anything. */ 591 na = g_raid_ndisks(sc, G_RAID_DISK_S_ACTIVE); 592 if (na == mdi->mdio_total_disks) 593 break; 594 595 G_RAID_DEBUG1(1, md->mdo_softc, --- 17 unchanged lines hidden (view full) --- 613 update += g_raid_md_jmicron_start_disk(disk); 614 if (disk->d_state == G_RAID_DISK_S_ACTIVE) 615 break; 616 } 617 } 618 } while (disk != NULL); 619 620 /* Write new metadata if we changed something. */ |
621 if (update) |
622 g_raid_md_write_jmicron(md, NULL, NULL, NULL); |
623 624 /* Update status of our need for spare. */ 625 mdi->mdio_incomplete = (g_raid_ndisks(sc, G_RAID_DISK_S_ACTIVE) < 626 mdi->mdio_total_disks); 627 628 /* Request retaste hoping to find spare. */ 629 if (mdi->mdio_incomplete) { 630 task = malloc(sizeof(struct task), --- 195 unchanged lines hidden (view full) --- 826 uint16_t vendor; 827 828 G_RAID_DEBUG(1, "Tasting JMicron on %s", cp->provider->name); 829 mdi = (struct g_raid_md_jmicron_object *)md; 830 pp = cp->provider; 831 832 /* Read metadata from device. */ 833 meta = NULL; |
834 vendor = 0xffff; |
835 if (g_access(cp, 1, 0, 0) != 0) 836 return (G_RAID_MD_TASTE_FAIL); 837 g_topology_unlock(); 838 len = 2; 839 if (pp->geom->rank == 1) 840 g_io_getattr("GEOM::hba_vendor", cp, &len, &vendor); 841 meta = jmicron_meta_read(cp); 842 g_topology_lock(); --- 279 unchanged lines hidden (view full) --- 1122 if (size > pp->mediasize) 1123 size = pp->mediasize; 1124 if (sectorsize < pp->sectorsize) 1125 sectorsize = pp->sectorsize; 1126 } 1127 if (error != 0) 1128 return (error); 1129 |
1130 if (sectorsize <= 0) { 1131 gctl_error(req, "Can't get sector size."); 1132 return (-8); 1133 } 1134 |
1135 /* Reserve space for metadata. */ 1136 size -= sectorsize; 1137 1138 /* Handle size argument. */ 1139 len = sizeof(*sizearg); 1140 sizearg = gctl_get_param(req, "size", &len); 1141 if (sizearg != NULL && len == sizeof(*sizearg) && 1142 *sizearg > 0) { --- 215 unchanged lines hidden (view full) --- 1358 1359 pd = malloc(sizeof(*pd), M_MD_JMICRON, M_WAITOK | M_ZERO); 1360 pd->pd_disk_pos = -3; 1361 pd->pd_disk_id = arc4random() & JMICRON_DISK_MASK; 1362 pd->pd_disk_size = pp->mediasize; 1363 1364 disk = g_raid_create_disk(sc); 1365 disk->d_consumer = cp; |
1366 disk->d_md_data = (void *)pd; 1367 cp->private = disk; 1368 g_topology_unlock(); 1369 1370 /* Read kernel dumping information. */ 1371 disk->d_kd.offset = 0; 1372 disk->d_kd.length = OFF_MAX; 1373 len = sizeof(disk->d_kd); --- 89 unchanged lines hidden (view full) --- 1463 if (++spares >= 2) 1464 break; 1465 } 1466 1467 /* We are done. Print meta data and store them to disks. */ 1468 if (mdi->mdio_meta != NULL) 1469 free(mdi->mdio_meta, M_MD_JMICRON); 1470 mdi->mdio_meta = meta; |
1471 TAILQ_FOREACH(disk, &sc->sc_disks, d_next) { 1472 pd = (struct g_raid_md_jmicron_perdisk *)disk->d_md_data; 1473 if (disk->d_state != G_RAID_DISK_S_ACTIVE && 1474 disk->d_state != G_RAID_DISK_S_SPARE) 1475 continue; 1476 if (pd->pd_meta != NULL) { 1477 free(pd->pd_meta, M_MD_JMICRON); 1478 pd->pd_meta = NULL; --- 20 unchanged lines hidden (view full) --- 1499 return (0); 1500} 1501 1502static int 1503g_raid_md_fail_disk_jmicron(struct g_raid_md_object *md, 1504 struct g_raid_subdisk *tsd, struct g_raid_disk *tdisk) 1505{ 1506 struct g_raid_softc *sc; |
1507 struct g_raid_md_jmicron_perdisk *pd; 1508 struct g_raid_subdisk *sd; 1509 1510 sc = md->mdo_softc; |
1511 pd = (struct g_raid_md_jmicron_perdisk *)tdisk->d_md_data; 1512 1513 /* We can't fail disk that is not a part of array now. */ 1514 if (pd->pd_disk_pos < 0) 1515 return (-1); 1516 1517 if (tdisk->d_consumer) 1518 jmicron_meta_erase(tdisk->d_consumer); --- 60 unchanged lines hidden --- |