md_jmicron.c (220209) | md_jmicron.c (220210) |
---|---|
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> | 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 220209 2011-03-31 16:14:35Z mav $"); | 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; | 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 jmicron_raid_conf *meta; | |
583 struct g_raid_disk *disk; 584 struct task *task; 585 int update, na; 586 587 md = sc->sc_md; 588 mdi = (struct g_raid_md_jmicron_object *)md; | 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; |
589 meta = mdi->mdio_meta; | |
590 update = 0; 591 do { 592 /* Make sure we miss anything. */ 593 na = g_raid_ndisks(sc, G_RAID_DISK_S_ACTIVE); 594 if (na == mdi->mdio_total_disks) 595 break; 596 597 G_RAID_DEBUG1(1, md->mdo_softc, --- 17 unchanged lines hidden (view full) --- 615 update += g_raid_md_jmicron_start_disk(disk); 616 if (disk->d_state == G_RAID_DISK_S_ACTIVE) 617 break; 618 } 619 } 620 } while (disk != NULL); 621 622 /* Write new metadata if we changed something. */ | 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. */ |
623 if (update) { | 621 if (update) |
624 g_raid_md_write_jmicron(md, NULL, NULL, NULL); | 622 g_raid_md_write_jmicron(md, NULL, NULL, NULL); |
625 meta = mdi->mdio_meta; 626 } | |
627 628 /* Update status of our need for spare. */ 629 mdi->mdio_incomplete = (g_raid_ndisks(sc, G_RAID_DISK_S_ACTIVE) < 630 mdi->mdio_total_disks); 631 632 /* Request retaste hoping to find spare. */ 633 if (mdi->mdio_incomplete) { 634 task = malloc(sizeof(struct task), --- 195 unchanged lines hidden (view full) --- 830 uint16_t vendor; 831 832 G_RAID_DEBUG(1, "Tasting JMicron on %s", cp->provider->name); 833 mdi = (struct g_raid_md_jmicron_object *)md; 834 pp = cp->provider; 835 836 /* Read metadata from device. */ 837 meta = 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; |
838 spare = 0; | |
839 vendor = 0xffff; | 834 vendor = 0xffff; |
840 disk_pos = 0; | |
841 if (g_access(cp, 1, 0, 0) != 0) 842 return (G_RAID_MD_TASTE_FAIL); 843 g_topology_unlock(); 844 len = 2; 845 if (pp->geom->rank == 1) 846 g_io_getattr("GEOM::hba_vendor", cp, &len, &vendor); 847 meta = jmicron_meta_read(cp); 848 g_topology_lock(); --- 279 unchanged lines hidden (view full) --- 1128 if (size > pp->mediasize) 1129 size = pp->mediasize; 1130 if (sectorsize < pp->sectorsize) 1131 sectorsize = pp->sectorsize; 1132 } 1133 if (error != 0) 1134 return (error); 1135 | 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 |
|
1136 /* Reserve space for metadata. */ 1137 size -= sectorsize; 1138 1139 /* Handle size argument. */ 1140 len = sizeof(*sizearg); 1141 sizearg = gctl_get_param(req, "size", &len); 1142 if (sizearg != NULL && len == sizeof(*sizearg) && 1143 *sizearg > 0) { --- 215 unchanged lines hidden (view full) --- 1359 1360 pd = malloc(sizeof(*pd), M_MD_JMICRON, M_WAITOK | M_ZERO); 1361 pd->pd_disk_pos = -3; 1362 pd->pd_disk_id = arc4random() & JMICRON_DISK_MASK; 1363 pd->pd_disk_size = pp->mediasize; 1364 1365 disk = g_raid_create_disk(sc); 1366 disk->d_consumer = cp; | 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; |
1367 disk->d_consumer->private = disk; | |
1368 disk->d_md_data = (void *)pd; 1369 cp->private = disk; 1370 g_topology_unlock(); 1371 1372 /* Read kernel dumping information. */ 1373 disk->d_kd.offset = 0; 1374 disk->d_kd.length = OFF_MAX; 1375 len = sizeof(disk->d_kd); --- 89 unchanged lines hidden (view full) --- 1465 if (++spares >= 2) 1466 break; 1467 } 1468 1469 /* We are done. Print meta data and store them to disks. */ 1470 if (mdi->mdio_meta != NULL) 1471 free(mdi->mdio_meta, M_MD_JMICRON); 1472 mdi->mdio_meta = meta; | 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; |
1473 i = 0; | |
1474 TAILQ_FOREACH(disk, &sc->sc_disks, d_next) { 1475 pd = (struct g_raid_md_jmicron_perdisk *)disk->d_md_data; 1476 if (disk->d_state != G_RAID_DISK_S_ACTIVE && 1477 disk->d_state != G_RAID_DISK_S_SPARE) 1478 continue; 1479 if (pd->pd_meta != NULL) { 1480 free(pd->pd_meta, M_MD_JMICRON); 1481 pd->pd_meta = NULL; --- 20 unchanged lines hidden (view full) --- 1502 return (0); 1503} 1504 1505static int 1506g_raid_md_fail_disk_jmicron(struct g_raid_md_object *md, 1507 struct g_raid_subdisk *tsd, struct g_raid_disk *tdisk) 1508{ 1509 struct g_raid_softc *sc; | 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; |
1510 struct g_raid_md_jmicron_object *mdi; | |
1511 struct g_raid_md_jmicron_perdisk *pd; 1512 struct g_raid_subdisk *sd; 1513 1514 sc = md->mdo_softc; | 1507 struct g_raid_md_jmicron_perdisk *pd; 1508 struct g_raid_subdisk *sd; 1509 1510 sc = md->mdo_softc; |
1515 mdi = (struct g_raid_md_jmicron_object *)md; | |
1516 pd = (struct g_raid_md_jmicron_perdisk *)tdisk->d_md_data; 1517 1518 /* We can't fail disk that is not a part of array now. */ 1519 if (pd->pd_disk_pos < 0) 1520 return (-1); 1521 1522 if (tdisk->d_consumer) 1523 jmicron_meta_erase(tdisk->d_consumer); --- 60 unchanged lines hidden --- | 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 --- |