summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorKlemens Nanni <kn@cvs.openbsd.org>2022-12-21 09:54:24 +0000
committerKlemens Nanni <kn@cvs.openbsd.org>2022-12-21 09:54:24 +0000
commit1223e9cc529087842ad4f3de58c88e6d722e63dd (patch)
treecf1f7eca33747cc83c9ca911a302d07a0c748f67 /sys
parent9a7f4084cc063c0622497dc92d18d0202f1fcd93 (diff)
Move duplicate code to new sr_find_discipline() helper
OK miod
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/softraid.c54
1 files changed, 23 insertions, 31 deletions
diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c
index ac027fb5714..decea16cb24 100644
--- a/sys/dev/softraid.c
+++ b/sys/dev/softraid.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraid.c,v 1.428 2022/12/18 13:10:08 kn Exp $ */
+/* $OpenBSD: softraid.c,v 1.429 2022/12/21 09:54:23 kn Exp $ */
/*
* Copyright (c) 2007, 2008, 2009 Marco Peereboom <marco@peereboom.us>
* Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org>
@@ -141,6 +141,7 @@ int sr_chunk_in_use(struct sr_softc *, dev_t);
int sr_rw(struct sr_softc *, dev_t, char *, size_t,
daddr_t, long);
void sr_wu_done_callback(void *);
+struct sr_discipline *sr_find_discipline(struct sr_softc *sc, const char *);
/* don't include these on RAMDISK */
#ifndef SMALL_KERNEL
@@ -3610,16 +3611,9 @@ sr_ioctl_deleteraid(struct sr_softc *sc, struct sr_discipline *sd,
DNPRINTF(SR_D_IOCTL, "%s: sr_ioctl_deleteraid %s\n",
DEVNAME(sc), bd->bd_dev);
- if (sd == NULL) {
- TAILQ_FOREACH(sd, &sc->sc_dis_list, sd_link) {
- if (!strncmp(sd->sd_meta->ssd_devname, bd->bd_dev,
- sizeof(sd->sd_meta->ssd_devname)))
- break;
- }
- if (sd == NULL) {
- sr_error(sc, "volume %s not found", bd->bd_dev);
- goto bad;
- }
+ if (sd == NULL && (sd = sr_find_discipline(sc, bd->bd_dev)) == NULL) {
+ sr_error(sc, "volume %s not found", bd->bd_dev);
+ goto bad;
}
/*
@@ -3652,16 +3646,9 @@ sr_ioctl_discipline(struct sr_softc *sc, struct sr_discipline *sd,
DNPRINTF(SR_D_IOCTL, "%s: sr_ioctl_discipline %s\n", DEVNAME(sc),
bd->bd_dev);
- if (sd == NULL) {
- TAILQ_FOREACH(sd, &sc->sc_dis_list, sd_link) {
- if (!strncmp(sd->sd_meta->ssd_devname, bd->bd_dev,
- sizeof(sd->sd_meta->ssd_devname)))
- break;
- }
- if (sd == NULL) {
- sr_error(sc, "volume %s not found", bd->bd_dev);
- goto bad;
- }
+ if (sd == NULL && (sd = sr_find_discipline(sc, bd->bd_dev)) == NULL) {
+ sr_error(sc, "volume %s not found", bd->bd_dev);
+ goto bad;
}
if (sd->sd_ioctl_handler)
@@ -3688,16 +3675,9 @@ sr_ioctl_installboot(struct sr_softc *sc, struct sr_discipline *sd,
DNPRINTF(SR_D_IOCTL, "%s: sr_ioctl_installboot %s\n", DEVNAME(sc),
bb->bb_dev);
- if (sd == NULL) {
- TAILQ_FOREACH(sd, &sc->sc_dis_list, sd_link) {
- if (!strncmp(sd->sd_meta->ssd_devname, bb->bb_dev,
- sizeof(sd->sd_meta->ssd_devname)))
- break;
- }
- if (sd == NULL) {
- sr_error(sc, "volume %s not found", bb->bb_dev);
- goto done;
- }
+ if (sd == NULL && (sd = sr_find_discipline(sc, bb->bb_dev)) == NULL) {
+ sr_error(sc, "volume %s not found", bb->bb_dev);
+ goto done;
}
TAILQ_FOREACH(dk, &disklist, dk_link)
@@ -4840,6 +4820,18 @@ fail:
dma_free(buf, SR_REBUILD_IO_SIZE << DEV_BSHIFT);
}
+struct sr_discipline *
+sr_find_discipline(struct sr_softc *sc, const char *devname)
+{
+ struct sr_discipline *sd;
+
+ TAILQ_FOREACH(sd, &sc->sc_dis_list, sd_link)
+ if (!strncmp(sd->sd_meta->ssd_devname, devname,
+ sizeof(sd->sd_meta->ssd_devname)))
+ break;
+ return sd;
+}
+
#ifndef SMALL_KERNEL
int
sr_sensors_create(struct sr_discipline *sd)