g_mirror.c (137254) | g_mirror.c (137259) |
---|---|
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 137254 2004-11-05 12:35:21Z pjd $"); | 28__FBSDID("$FreeBSD: head/sys/geom/mirror/g_mirror.c 137259 2004-11-05 17:18:39Z 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> --- 712 unchanged lines hidden (view full) --- 749 G_MIRROR_DEBUG(1, "Disk %s (device %s) marked as dirty.", 750 g_mirror_get_diskname(disk), sc->sc_name); 751 disk->d_flags |= G_MIRROR_DISK_FLAG_DIRTY; 752 g_mirror_update_metadata(disk); 753 } 754 g_topology_unlock(); 755} 756 | 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> --- 712 unchanged lines hidden (view full) --- 749 G_MIRROR_DEBUG(1, "Disk %s (device %s) marked as dirty.", 750 g_mirror_get_diskname(disk), sc->sc_name); 751 disk->d_flags |= G_MIRROR_DISK_FLAG_DIRTY; 752 g_mirror_update_metadata(disk); 753 } 754 g_topology_unlock(); 755} 756 |
757/* 758 * Return 1 if we should check if mirror is idling. 759 */ 760static int 761g_mirror_check_idle(struct g_mirror_softc *sc) 762{ 763 struct g_mirror_disk *disk; 764 765 if (sc->sc_idle) 766 return (0); 767 if (sc->sc_provider != NULL && sc->sc_provider->acw == 0) 768 return (0); 769 /* 770 * Check if there are no in-flight requests. 771 */ 772 LIST_FOREACH(disk, &sc->sc_disks, d_next) { 773 if (disk->d_state != G_MIRROR_DISK_STATE_ACTIVE) 774 continue; 775 if (disk->d_consumer->index > 0) 776 return (0); 777 } 778 return (1); 779} 780 |
|
757static __inline int 758bintime_cmp(struct bintime *bt1, struct bintime *bt2) 759{ 760 761 if (bt1->sec < bt2->sec) 762 return (-1); 763 else if (bt1->sec > bt2->sec) 764 return (1); --- 736 unchanged lines hidden (view full) --- 1501 sync->ds_resync = -1; 1502 } 1503 g_mirror_sync_one(disk); 1504 } 1505 G_MIRROR_DEBUG(5, "%s: I'm here 2.", __func__); 1506 goto sleep; 1507 } 1508 if (bp == NULL) { | 781static __inline int 782bintime_cmp(struct bintime *bt1, struct bintime *bt2) 783{ 784 785 if (bt1->sec < bt2->sec) 786 return (-1); 787 else if (bt1->sec > bt2->sec) 788 return (1); --- 736 unchanged lines hidden (view full) --- 1525 sync->ds_resync = -1; 1526 } 1527 g_mirror_sync_one(disk); 1528 } 1529 G_MIRROR_DEBUG(5, "%s: I'm here 2.", __func__); 1530 goto sleep; 1531 } 1532 if (bp == NULL) { |
1509#define G_MIRROR_IS_IDLE(sc) ((sc)->sc_idle || \ 1510 ((sc)->sc_provider != NULL && \ 1511 (sc)->sc_provider->acw == 0)) 1512 if (G_MIRROR_IS_IDLE(sc)) { 1513 /* 1514 * If we're already in idle state, sleep without 1515 * a timeout. 1516 */ 1517 MSLEEP(sc, &sc->sc_queue_mtx, PRIBIO | PDROP, 1518 "m:w1", 0); 1519 G_MIRROR_DEBUG(5, "%s: I'm here 3.", __func__); 1520 } else { | 1533 if (g_mirror_check_idle(sc)) { |
1521 u_int idletime; 1522 1523 idletime = g_mirror_idletime; 1524 if (idletime == 0) 1525 idletime = 1; 1526 idletime *= hz; 1527 if (msleep(sc, &sc->sc_queue_mtx, PRIBIO | PDROP, | 1534 u_int idletime; 1535 1536 idletime = g_mirror_idletime; 1537 if (idletime == 0) 1538 idletime = 1; 1539 idletime *= hz; 1540 if (msleep(sc, &sc->sc_queue_mtx, PRIBIO | PDROP, |
1528 "m:w2", idletime) == EWOULDBLOCK) { 1529 G_MIRROR_DEBUG(5, "%s: I'm here 4.", | 1541 "m:w1", idletime) == EWOULDBLOCK) { 1542 G_MIRROR_DEBUG(5, "%s: I'm here 3.", |
1530 __func__); 1531 /* | 1543 __func__); 1544 /* |
1532 * No I/O requests in 5 seconds, so mark 1533 * components as clean. | 1545 * No I/O requests in 'idletime' seconds, 1546 * so mark components as clean. |
1534 */ 1535 g_mirror_idle(sc); 1536 } | 1547 */ 1548 g_mirror_idle(sc); 1549 } |
1550 G_MIRROR_DEBUG(5, "%s: I'm here 4.", __func__); 1551 } else { 1552 MSLEEP(sc, &sc->sc_queue_mtx, PRIBIO | PDROP, 1553 "m:w2", 0); |
|
1537 G_MIRROR_DEBUG(5, "%s: I'm here 5.", __func__); 1538 } 1539 continue; 1540 } 1541 nreqs++; 1542 bioq_remove(&sc->sc_queue, bp); 1543 mtx_unlock(&sc->sc_queue_mtx); 1544 --- 1326 unchanged lines hidden --- | 1554 G_MIRROR_DEBUG(5, "%s: I'm here 5.", __func__); 1555 } 1556 continue; 1557 } 1558 nreqs++; 1559 bioq_remove(&sc->sc_queue, bp); 1560 mtx_unlock(&sc->sc_queue_mtx); 1561 --- 1326 unchanged lines hidden --- |