- Add "prefer" balance algorithm. When used, only disk with the biggest

priority will be used for reading.
- Bump version number.
This commit is contained in:
Pawel Jakub Dawidek 2004-08-04 12:09:53 +00:00
parent e1efe7edcd
commit fe7c3780c8
2 changed files with 66 additions and 7 deletions

View File

@ -1012,6 +1012,43 @@ g_mirror_sync_request(struct bio *bp)
}
}
static void
g_mirror_request_prefer(struct g_mirror_softc *sc, struct bio *bp)
{
struct g_mirror_disk *disk;
struct g_consumer *cp;
struct bio *cbp;
LIST_FOREACH(disk, &sc->sc_disks, d_next) {
if (disk->d_state == G_MIRROR_DISK_STATE_ACTIVE)
break;
}
if (disk == NULL) {
if (bp->bio_error == 0)
bp->bio_error = ENXIO;
g_io_deliver(bp, bp->bio_error);
return;
}
cbp = g_clone_bio(bp);
if (cbp == NULL) {
if (bp->bio_error == 0)
bp->bio_error = ENOMEM;
g_io_deliver(bp, bp->bio_error);
return;
}
/*
* Fill in the component buf structure.
*/
cp = disk->d_consumer;
cbp->bio_done = g_mirror_done;
cbp->bio_to = cp->provider;
G_MIRROR_LOGREQ(3, cbp, "Sending request.");
KASSERT(cp->acr > 0 && cp->ace > 0,
("Consumer %s not opened (r%dw%de%d).", cp->provider->name, cp->acr,
cp->acw, cp->ace));
g_io_request(cbp, cp);
}
static void
g_mirror_request_round_robin(struct g_mirror_softc *sc, struct bio *bp)
{
@ -1171,12 +1208,15 @@ g_mirror_register_request(struct bio *bp)
switch (bp->bio_cmd) {
case BIO_READ:
switch (sc->sc_balance) {
case G_MIRROR_BALANCE_ROUND_ROBIN:
g_mirror_request_round_robin(sc, bp);
break;
case G_MIRROR_BALANCE_LOAD:
g_mirror_request_load(sc, bp);
break;
case G_MIRROR_BALANCE_PREFER:
g_mirror_request_prefer(sc, bp);
break;
case G_MIRROR_BALANCE_ROUND_ROBIN:
g_mirror_request_round_robin(sc, bp);
break;
case G_MIRROR_BALANCE_SPLIT:
g_mirror_request_split(sc, bp);
break;
@ -1909,7 +1949,23 @@ g_mirror_update_disk(struct g_mirror_disk *disk, u_int state)
DISK_STATE_CHANGED();
disk->d_state = state;
LIST_INSERT_HEAD(&sc->sc_disks, disk, d_next);
if (LIST_EMPTY(&sc->sc_disks))
LIST_INSERT_HEAD(&sc->sc_disks, disk, d_next);
else {
struct g_mirror_disk *dp;
LIST_FOREACH(dp, &sc->sc_disks, d_next) {
if (disk->d_priority >= dp->d_priority) {
LIST_INSERT_BEFORE(dp, disk, d_next);
dp = NULL;
break;
}
if (LIST_NEXT(dp, d_next) == NULL)
break;
}
if (dp != NULL)
LIST_INSERT_AFTER(dp, disk, d_next);
}
G_MIRROR_DEBUG(0, "Device %s: provider %s detected.",
sc->sc_name, g_mirror_get_diskname(disk));
if (sc->sc_state == G_MIRROR_DEVICE_STATE_STARTING)

View File

@ -35,14 +35,15 @@
#define G_MIRROR_CLASS_NAME "MIRROR"
#define G_MIRROR_MAGIC "GEOM::MIRROR"
#define G_MIRROR_VERSION 0
#define G_MIRROR_VERSION 1
#define G_MIRROR_BALANCE_NONE 0
#define G_MIRROR_BALANCE_ROUND_ROBIN 1
#define G_MIRROR_BALANCE_LOAD 2
#define G_MIRROR_BALANCE_SPLIT 3
#define G_MIRROR_BALANCE_PREFER 4
#define G_MIRROR_BALANCE_MIN G_MIRROR_BALANCE_NONE
#define G_MIRROR_BALANCE_MAX G_MIRROR_BALANCE_SPLIT
#define G_MIRROR_BALANCE_MAX G_MIRROR_BALANCE_PREFER
#define G_MIRROR_DISK_FLAG_DIRTY 0x0000000000000001ULL
#define G_MIRROR_DISK_FLAG_SYNCHRONIZING 0x0000000000000002ULL
@ -270,6 +271,7 @@ balance_name(u_int balance)
[G_MIRROR_BALANCE_ROUND_ROBIN] = "round-robin",
[G_MIRROR_BALANCE_LOAD] = "load",
[G_MIRROR_BALANCE_SPLIT] = "split",
[G_MIRROR_BALANCE_PREFER] = "prefer",
[G_MIRROR_BALANCE_MAX + 1] = "unknown"
};
@ -286,7 +288,8 @@ balance_id(const char *name)
[G_MIRROR_BALANCE_NONE] = "none",
[G_MIRROR_BALANCE_ROUND_ROBIN] = "round-robin",
[G_MIRROR_BALANCE_LOAD] = "load",
[G_MIRROR_BALANCE_SPLIT] = "split"
[G_MIRROR_BALANCE_SPLIT] = "split",
[G_MIRROR_BALANCE_PREFER] = "prefer"
};
int n;