diff options
author | 2011-09-19 14:55:10 +0000 | |
---|---|---|
committer | 2011-09-19 14:55:10 +0000 | |
commit | 6a6db795059de06d38ff2b3facfb2a86277d3745 (patch) | |
tree | 7865ccce1e06711e23b6d754d74ec4d91bcc0106 /sys/dev/softraid.c | |
parent | clean up buffer cache statistics somewhat to (diff) | |
download | wireguard-openbsd-6a6db795059de06d38ff2b3facfb2a86277d3745.tar.xz wireguard-openbsd-6a6db795059de06d38ff2b3facfb2a86277d3745.zip |
Cleanup sr_ioctl_createraid(). There are three clear cases - (1) corrupt
or invalid metadata; (2) a new volume with no existing metadata; and (3)
an existing volume with metadata. This removes duplicated code and
simplifies the code path.
Also ensure that we only process the optional metadata once per volume
and not once per chunk. Move the optional metadata handler calls into
sr_ioctl_createraid().
Diffstat (limited to 'sys/dev/softraid.c')
-rw-r--r-- | sys/dev/softraid.c | 67 |
1 files changed, 27 insertions, 40 deletions
diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c index 33654c730bf..931037d94be 100644 --- a/sys/dev/softraid.c +++ b/sys/dev/softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid.c,v 1.248 2011/09/18 19:40:49 jsing Exp $ */ +/* $OpenBSD: softraid.c,v 1.249 2011/09/19 14:55:10 jsing Exp $ */ /* * Copyright (c) 2007, 2008, 2009 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org> @@ -297,7 +297,6 @@ sr_meta_probe(struct sr_discipline *sd, dev_t *dt, int no_chunk) if (no_chunk == 0) goto unwind; - cl = &sd->sd_vol.sv_chunk_list; for (d = 0, prevf = SR_META_F_INVALID; d < no_chunk; d++) { @@ -742,7 +741,6 @@ sr_meta_read(struct sr_discipline *sd) struct sr_chunk *ch_entry; struct sr_meta_chunk *cp; struct sr_meta_driver *s; - struct sr_meta_opt_item *omi; void *fm = NULL; int no_disk = 0, got_meta = 0; @@ -788,21 +786,15 @@ sr_meta_read(struct sr_discipline *sd) /* assume first chunk contains metadata */ if (got_meta == 0) { + sr_meta_opt_load(sc, sm, &sd->sd_meta_opt); bcopy(sm, sd->sd_meta, sizeof(*sd->sd_meta)); got_meta = 1; } bcopy(cp, &ch_entry->src_meta, sizeof(ch_entry->src_meta)); - /* Load and process optional metadata. */ - sr_meta_opt_load(sc, sm, &sd->sd_meta_opt); - SLIST_FOREACH(omi, &sd->sd_meta_opt, omi_link) - if (sd->sd_meta_opt_handler == NULL || - sd->sd_meta_opt_handler(sd, omi->omi_som) != 0) - sr_meta_opt_handler(sd, omi->omi_som); - - cp++; no_disk++; + cp++; } free(sm, M_DEVBUF); @@ -829,8 +821,8 @@ sr_meta_opt_load(struct sr_softc *sc, struct sr_metadata *sm, sizeof(struct sr_meta_chunk) * sm->ssdi.ssd_chunk_no); for (i = 0; i < sm->ssdi.ssd_opt_no; i++) { - omi = malloc(sizeof(struct sr_meta_opt_item), - M_DEVBUF, M_WAITOK | M_ZERO); + omi = malloc(sizeof(struct sr_meta_opt_item), M_DEVBUF, + M_WAITOK | M_ZERO); SLIST_INSERT_HEAD(som, omi, omi_link); if (omh->som_length == 0) { @@ -2945,15 +2937,16 @@ sr_roam_chunks(struct sr_discipline *sd) int sr_ioctl_createraid(struct sr_softc *sc, struct bioc_createraid *bc, int user) { - dev_t *dt; - int i, no_chunk, rv = EINVAL, target, vol; - int no_meta, updatemeta = 0; + struct sr_meta_opt_item *omi; struct sr_chunk_head *cl; struct sr_discipline *sd = NULL; struct sr_chunk *ch_entry; struct scsi_link *link; struct device *dev; char devname[32]; + dev_t *dt; + int i, no_chunk, rv = EINVAL, target, vol; + int no_meta, updatemeta = 0; DNPRINTF(SR_D_IOCTL, "%s: sr_ioctl_createraid(%d)\n", DEVNAME(sc), user); @@ -3027,7 +3020,12 @@ sr_ioctl_createraid(struct sr_softc *sc, struct bioc_createraid *bc, int user) } } - if ((no_meta = sr_meta_read(sd)) == 0) { + no_meta = sr_meta_read(sd); + if (no_meta == -1) { + printf("%s: one of the chunks has corrupt metadata; aborting " + "assembly\n", DEVNAME(sc)); + goto unwind; + } else if (no_meta == 0) { /* fill out all chunk metadata */ sr_meta_chunks_create(sc, cl); ch_entry = SLIST_FIRST(cl); @@ -3064,15 +3062,21 @@ sr_ioctl_createraid(struct sr_softc *sc, struct bioc_createraid *bc, int user) sd->sd_meta_flags = bc->bc_flags & BIOC_SCNOAUTOASSEMBLE; updatemeta = 1; - } else if (no_meta == no_chunk) { + } else { + if (no_meta != no_chunk) + printf("%s: trying to bring up %s degraded\n", + DEVNAME(sc), sd->sd_meta->ssd_devname); + if (sd->sd_meta->ssd_meta_flags & SR_META_DIRTY) printf("%s: %s was not shutdown properly\n", DEVNAME(sc), sd->sd_meta->ssd_devname); + if (user == 0 && sd->sd_meta_flags & BIOC_SCNOAUTOASSEMBLE) { DNPRINTF(SR_D_META, "%s: disk not auto assembled from " "metadata\n", DEVNAME(sc)); goto unwind; } + if (sr_already_assembled(sd)) { printf("%s: disk ", DEVNAME(sc)); sr_uuid_print(&sd->sd_meta->ssdi.ssd_uuid, 0); @@ -3080,6 +3084,11 @@ sr_ioctl_createraid(struct sr_softc *sc, struct bioc_createraid *bc, int user) goto unwind; } + SLIST_FOREACH(omi, &sd->sd_meta_opt, omi_link) + if (sd->sd_meta_opt_handler == NULL || + sd->sd_meta_opt_handler(sd, omi->omi_som) != 0) + sr_meta_opt_handler(sd, omi->omi_som); + if (sd->sd_assemble) { if ((i = sd->sd_assemble(sd, bc, no_chunk))) { rv = i; @@ -3090,28 +3099,6 @@ sr_ioctl_createraid(struct sr_softc *sc, struct bioc_createraid *bc, int user) DNPRINTF(SR_D_META, "%s: disk assembled from metadata\n", DEVNAME(sc)); updatemeta = 0; - } else if (no_meta == -1) { - printf("%s: one of the chunks has corrupt metadata; aborting " - "assembly\n", DEVNAME(sc)); - goto unwind; - } else { - if (sr_already_assembled(sd)) { - printf("%s: disk ", DEVNAME(sc)); - sr_uuid_print(&sd->sd_meta->ssdi.ssd_uuid, 0); - printf(" already assembled; will not partial " - "assemble it\n"); - goto unwind; - } - - if (sd->sd_assemble) { - if ((i = sd->sd_assemble(sd, bc, no_chunk))) { - rv = i; - goto unwind; - } - } - - printf("%s: trying to bring up %s degraded\n", DEVNAME(sc), - sd->sd_meta->ssd_devname); } /* metadata SHALL be fully filled in at this point */ |