g_mirror.c (139054) | g_mirror.c (139140) |
---|---|
1/*- 2 * Copyright (c) 2004 Pawel Jakub Dawidek <pjd@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) 2004 Pawel Jakub Dawidek <pjd@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/mirror/g_mirror.c 139054 2004-12-19 23:55:49Z pjd $"); | 28__FBSDID("$FreeBSD: head/sys/geom/mirror/g_mirror.c 139140 2004-12-21 18:42:51Z pjd $"); |
29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/kernel.h> 33#include <sys/module.h> 34#include <sys/limits.h> 35#include <sys/lock.h> 36#include <sys/mutex.h> --- 172 unchanged lines hidden (view full) --- 209 210static struct g_mirror_event * 211g_mirror_event_get(struct g_mirror_softc *sc) 212{ 213 struct g_mirror_event *ep; 214 215 mtx_lock(&sc->sc_events_mtx); 216 ep = TAILQ_FIRST(&sc->sc_events); | 29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/kernel.h> 33#include <sys/module.h> 34#include <sys/limits.h> 35#include <sys/lock.h> 36#include <sys/mutex.h> --- 172 unchanged lines hidden (view full) --- 209 210static struct g_mirror_event * 211g_mirror_event_get(struct g_mirror_softc *sc) 212{ 213 struct g_mirror_event *ep; 214 215 mtx_lock(&sc->sc_events_mtx); 216 ep = TAILQ_FIRST(&sc->sc_events); |
217 if (ep != NULL) 218 TAILQ_REMOVE(&sc->sc_events, ep, e_next); | |
219 mtx_unlock(&sc->sc_events_mtx); 220 return (ep); 221} 222 | 217 mtx_unlock(&sc->sc_events_mtx); 218 return (ep); 219} 220 |
221 |
|
223static void | 222static void |
223g_mirror_event_remove(struct g_mirror_softc *sc, struct g_mirror_event *ep) 224{ 225 226 mtx_lock(&sc->sc_events_mtx); 227 TAILQ_REMOVE(&sc->sc_events, ep, e_next); 228 mtx_unlock(&sc->sc_events_mtx); 229} 230 231static void |
|
224g_mirror_event_cancel(struct g_mirror_disk *disk) 225{ 226 struct g_mirror_softc *sc; 227 struct g_mirror_event *ep, *tmpep; 228 229 g_topology_assert(); 230 231 sc = disk->d_softc; --- 263 unchanged lines hidden (view full) --- 495 g_mirror_destroy_provider(sc); 496 for (disk = LIST_FIRST(&sc->sc_disks); disk != NULL; 497 disk = LIST_FIRST(&sc->sc_disks)) { 498 disk->d_flags &= ~G_MIRROR_DISK_FLAG_DIRTY; 499 g_mirror_update_metadata(disk); 500 g_mirror_destroy_disk(disk); 501 } 502 while ((ep = g_mirror_event_get(sc)) != NULL) { | 232g_mirror_event_cancel(struct g_mirror_disk *disk) 233{ 234 struct g_mirror_softc *sc; 235 struct g_mirror_event *ep, *tmpep; 236 237 g_topology_assert(); 238 239 sc = disk->d_softc; --- 263 unchanged lines hidden (view full) --- 503 g_mirror_destroy_provider(sc); 504 for (disk = LIST_FIRST(&sc->sc_disks); disk != NULL; 505 disk = LIST_FIRST(&sc->sc_disks)) { 506 disk->d_flags &= ~G_MIRROR_DISK_FLAG_DIRTY; 507 g_mirror_update_metadata(disk); 508 g_mirror_destroy_disk(disk); 509 } 510 while ((ep = g_mirror_event_get(sc)) != NULL) { |
511 g_mirror_event_remove(sc, ep); |
|
503 if ((ep->e_flags & G_MIRROR_EVENT_DONTWAIT) != 0) 504 g_mirror_event_free(ep); 505 else { 506 ep->e_error = ECANCELED; 507 ep->e_flags |= G_MIRROR_EVENT_DONE; 508 G_MIRROR_DEBUG(4, "%s: Waking up %p.", __func__, ep); 509 mtx_lock(&sc->sc_events_mtx); 510 wakeup(ep); --- 945 unchanged lines hidden (view full) --- 1456 nreqs = 0; 1457 for (;;) { 1458 G_MIRROR_DEBUG(5, "%s: Let's see...", __func__); 1459 /* 1460 * First take a look at events. 1461 * This is important to handle events before any I/O requests. 1462 */ 1463 ep = g_mirror_event_get(sc); | 512 if ((ep->e_flags & G_MIRROR_EVENT_DONTWAIT) != 0) 513 g_mirror_event_free(ep); 514 else { 515 ep->e_error = ECANCELED; 516 ep->e_flags |= G_MIRROR_EVENT_DONE; 517 G_MIRROR_DEBUG(4, "%s: Waking up %p.", __func__, ep); 518 mtx_lock(&sc->sc_events_mtx); 519 wakeup(ep); --- 945 unchanged lines hidden (view full) --- 1465 nreqs = 0; 1466 for (;;) { 1467 G_MIRROR_DEBUG(5, "%s: Let's see...", __func__); 1468 /* 1469 * First take a look at events. 1470 * This is important to handle events before any I/O requests. 1471 */ 1472 ep = g_mirror_event_get(sc); |
1464 if (ep != NULL) { 1465 g_topology_lock(); | 1473 if (ep != NULL && g_topology_try_lock()) { 1474 g_mirror_event_remove(sc, ep); |
1466 if ((ep->e_flags & G_MIRROR_EVENT_DEVICE) != 0) { 1467 /* Update only device status. */ 1468 G_MIRROR_DEBUG(3, 1469 "Running event for device %s.", 1470 sc->sc_name); 1471 ep->e_error = 0; 1472 g_mirror_update_device(sc, 1); 1473 } else { --- 28 unchanged lines hidden (view full) --- 1502 } 1503 /* 1504 * Now I/O requests. 1505 */ 1506 /* Get first request from the queue. */ 1507 mtx_lock(&sc->sc_queue_mtx); 1508 bp = bioq_first(&sc->sc_queue); 1509 if (bp == NULL) { | 1475 if ((ep->e_flags & G_MIRROR_EVENT_DEVICE) != 0) { 1476 /* Update only device status. */ 1477 G_MIRROR_DEBUG(3, 1478 "Running event for device %s.", 1479 sc->sc_name); 1480 ep->e_error = 0; 1481 g_mirror_update_device(sc, 1); 1482 } else { --- 28 unchanged lines hidden (view full) --- 1511 } 1512 /* 1513 * Now I/O requests. 1514 */ 1515 /* Get first request from the queue. */ 1516 mtx_lock(&sc->sc_queue_mtx); 1517 bp = bioq_first(&sc->sc_queue); 1518 if (bp == NULL) { |
1519 if (ep != NULL) { 1520 /* 1521 * No I/O requests and topology lock was 1522 * already held? Try again. 1523 */ 1524 mtx_unlock(&sc->sc_queue_mtx); 1525 continue; 1526 } |
|
1510 if ((sc->sc_flags & 1511 G_MIRROR_DEVICE_FLAG_DESTROY) != 0) { 1512 mtx_unlock(&sc->sc_queue_mtx); 1513 if (g_mirror_try_destroy(sc)) 1514 kthread_exit(0); 1515 mtx_lock(&sc->sc_queue_mtx); 1516 } 1517 } --- 63 unchanged lines hidden (view full) --- 1581 1582 g_mirror_sync_request(bp); 1583sleep: 1584 sps = g_mirror_syncs_per_sec; 1585 if (sps == 0) { 1586 G_MIRROR_DEBUG(5, "%s: I'm here 6.", __func__); 1587 continue; 1588 } | 1527 if ((sc->sc_flags & 1528 G_MIRROR_DEVICE_FLAG_DESTROY) != 0) { 1529 mtx_unlock(&sc->sc_queue_mtx); 1530 if (g_mirror_try_destroy(sc)) 1531 kthread_exit(0); 1532 mtx_lock(&sc->sc_queue_mtx); 1533 } 1534 } --- 63 unchanged lines hidden (view full) --- 1598 1599 g_mirror_sync_request(bp); 1600sleep: 1601 sps = g_mirror_syncs_per_sec; 1602 if (sps == 0) { 1603 G_MIRROR_DEBUG(5, "%s: I'm here 6.", __func__); 1604 continue; 1605 } |
1606 if (ep != NULL) { 1607 /* 1608 * We have some pending events, don't sleep now. 1609 */ 1610 G_MIRROR_DEBUG(5, "%s: I'm here 7.", __func__); 1611 continue; 1612 } |
|
1589 mtx_lock(&sc->sc_queue_mtx); 1590 if (bioq_first(&sc->sc_queue) != NULL) { 1591 mtx_unlock(&sc->sc_queue_mtx); | 1613 mtx_lock(&sc->sc_queue_mtx); 1614 if (bioq_first(&sc->sc_queue) != NULL) { 1615 mtx_unlock(&sc->sc_queue_mtx); |
1592 G_MIRROR_DEBUG(5, "%s: I'm here 7.", __func__); | 1616 G_MIRROR_DEBUG(5, "%s: I'm here 8.", __func__); |
1593 continue; 1594 } 1595 timeout = hz / sps; 1596 if (timeout == 0) 1597 timeout = 1; 1598 MSLEEP(sc, &sc->sc_queue_mtx, PRIBIO | PDROP, "m:w3", 1599 timeout); 1600 } else { 1601 g_mirror_register_request(bp); 1602 } | 1617 continue; 1618 } 1619 timeout = hz / sps; 1620 if (timeout == 0) 1621 timeout = 1; 1622 MSLEEP(sc, &sc->sc_queue_mtx, PRIBIO | PDROP, "m:w3", 1623 timeout); 1624 } else { 1625 g_mirror_register_request(bp); 1626 } |
1603 G_MIRROR_DEBUG(5, "%s: I'm here 8.", __func__); | 1627 G_MIRROR_DEBUG(5, "%s: I'm here 9.", __func__); |
1604 } 1605} 1606 1607/* 1608 * Open disk's consumer if needed. 1609 */ 1610static void 1611g_mirror_update_access(struct g_mirror_disk *disk) --- 1224 unchanged lines hidden --- | 1628 } 1629} 1630 1631/* 1632 * Open disk's consumer if needed. 1633 */ 1634static void 1635g_mirror_update_access(struct g_mirror_disk *disk) --- 1224 unchanged lines hidden --- |