Remove autoconf dependency on vfs and dk:

opendisk() -> kern/subr_disk_open.c
config_handle_wedges -> dev/dkwedge/dk.c
This commit is contained in:
pooka 2009-09-06 16:18:55 +00:00
parent d7f624cfd8
commit f926eb58c3
4 changed files with 155 additions and 111 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: files,v 1.953 2009/08/14 21:17:21 mbalmer Exp $
# $NetBSD: files,v 1.954 2009/09/06 16:18:56 pooka Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
version 20090313
@ -1466,6 +1466,7 @@ file kern/subr_callback.c
file kern/subr_debug.c debug
file kern/subr_devsw.c
file kern/subr_disk.c
file kern/subr_disk_open.c
file kern/subr_iostat.c
file kern/subr_evcnt.c
file kern/subr_exec_fd.c

View File

@ -1,4 +1,4 @@
/* $NetBSD: dk.c,v 1.48 2009/08/06 16:00:49 haad Exp $ */
/* $NetBSD: dk.c,v 1.49 2009/09/06 16:18:55 pooka Exp $ */
/*-
* Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.48 2009/08/06 16:00:49 haad Exp $");
__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.49 2009/09/06 16:18:55 pooka Exp $");
#include "opt_dkwedge.h"
@ -1426,3 +1426,70 @@ out:
return rv;
}
/*
* config glue
*/
int
config_handle_wedges(struct device *dv, int par)
{
struct dkwedge_list wl;
struct dkwedge_info *wi;
struct vnode *vn;
char diskname[16];
int i, error;
if ((vn = opendisk(dv)) == NULL)
return -1;
wl.dkwl_bufsize = sizeof(*wi) * 16;
wl.dkwl_buf = wi = malloc(wl.dkwl_bufsize, M_TEMP, M_WAITOK);
error = VOP_IOCTL(vn, DIOCLWEDGES, &wl, FREAD, NOCRED);
VOP_CLOSE(vn, FREAD, NOCRED);
vput(vn);
if (error) {
#ifdef DEBUG_WEDGE
printf("%s: List wedges returned %d\n",
device_xname(dv), error);
#endif
free(wi, M_TEMP);
return -1;
}
#ifdef DEBUG_WEDGE
printf("%s: Returned %u(%u) wedges\n", device_xname(dv),
wl.dkwl_nwedges, wl.dkwl_ncopied);
#endif
snprintf(diskname, sizeof(diskname), "%s%c", device_xname(dv),
par + 'a');
for (i = 0; i < wl.dkwl_ncopied; i++) {
#ifdef DEBUG_WEDGE
printf("%s: Looking for %s in %s\n",
device_xname(dv), diskname, wi[i].dkw_wname);
#endif
if (strcmp(wi[i].dkw_wname, diskname) == 0)
break;
}
if (i == wl.dkwl_ncopied) {
#ifdef DEBUG_WEDGE
printf("%s: Cannot find wedge with parent %s\n",
device_xname(dv), diskname);
#endif
free(wi, M_TEMP);
return -1;
}
#ifdef DEBUG_WEDGE
printf("%s: Setting boot wedge %s (%s) at %llu %llu\n",
device_xname(dv), wi[i].dkw_devname, wi[i].dkw_wname,
(unsigned long long)wi[i].dkw_offset,
(unsigned long long)wi[i].dkw_size);
#endif
dkwedge_set_bootwedge(dv, wi[i].dkw_offset, wi[i].dkw_size);
free(wi, M_TEMP);
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: subr_autoconf.c,v 1.180 2009/09/03 15:20:08 pooka Exp $ */
/* $NetBSD: subr_autoconf.c,v 1.181 2009/09/06 16:18:56 pooka Exp $ */
/*
* Copyright (c) 1996, 2000 Christopher G. Demetriou
@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.180 2009/09/03 15:20:08 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.181 2009/09/06 16:18:56 pooka Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@ -225,112 +225,6 @@ static int config_initialized; /* config_init() has been called. */
static int config_do_twiddle;
static callout_t config_twiddle_ch;
struct vnode *
opendisk(struct device *dv)
{
int bmajor, bminor;
struct vnode *tmpvn;
int error;
dev_t dev;
/*
* Lookup major number for disk block device.
*/
bmajor = devsw_name2blk(device_xname(dv), NULL, 0);
if (bmajor == -1)
return NULL;
bminor = minor(device_unit(dv));
/*
* Fake a temporary vnode for the disk, open it, and read
* and hash the sectors.
*/
dev = device_is_a(dv, "dk") ? makedev(bmajor, bminor) :
MAKEDISKDEV(bmajor, bminor, RAW_PART);
if (bdevvp(dev, &tmpvn))
panic("%s: can't alloc vnode for %s", __func__,
device_xname(dv));
error = VOP_OPEN(tmpvn, FREAD, NOCRED);
if (error) {
#ifndef DEBUG
/*
* Ignore errors caused by missing device, partition,
* or medium.
*/
if (error != ENXIO && error != ENODEV)
#endif
printf("%s: can't open dev %s (%d)\n",
__func__, device_xname(dv), error);
vput(tmpvn);
return NULL;
}
return tmpvn;
}
int
config_handle_wedges(struct device *dv, int par)
{
struct dkwedge_list wl;
struct dkwedge_info *wi;
struct vnode *vn;
char diskname[16];
int i, error;
if ((vn = opendisk(dv)) == NULL)
return -1;
wl.dkwl_bufsize = sizeof(*wi) * 16;
wl.dkwl_buf = wi = malloc(wl.dkwl_bufsize, M_TEMP, M_WAITOK);
error = VOP_IOCTL(vn, DIOCLWEDGES, &wl, FREAD, NOCRED);
VOP_CLOSE(vn, FREAD, NOCRED);
vput(vn);
if (error) {
#ifdef DEBUG_WEDGE
printf("%s: List wedges returned %d\n",
device_xname(dv), error);
#endif
free(wi, M_TEMP);
return -1;
}
#ifdef DEBUG_WEDGE
printf("%s: Returned %u(%u) wedges\n", device_xname(dv),
wl.dkwl_nwedges, wl.dkwl_ncopied);
#endif
snprintf(diskname, sizeof(diskname), "%s%c", device_xname(dv),
par + 'a');
for (i = 0; i < wl.dkwl_ncopied; i++) {
#ifdef DEBUG_WEDGE
printf("%s: Looking for %s in %s\n",
device_xname(dv), diskname, wi[i].dkw_wname);
#endif
if (strcmp(wi[i].dkw_wname, diskname) == 0)
break;
}
if (i == wl.dkwl_ncopied) {
#ifdef DEBUG_WEDGE
printf("%s: Cannot find wedge with parent %s\n",
device_xname(dv), diskname);
#endif
free(wi, M_TEMP);
return -1;
}
#ifdef DEBUG_WEDGE
printf("%s: Setting boot wedge %s (%s) at %llu %llu\n",
device_xname(dv), wi[i].dkw_devname, wi[i].dkw_wname,
(unsigned long long)wi[i].dkw_offset,
(unsigned long long)wi[i].dkw_size);
#endif
dkwedge_set_bootwedge(dv, wi[i].dkw_offset, wi[i].dkw_size);
free(wi, M_TEMP);
return 0;
}
/*
* Initialize the autoconfiguration data structures. Normally this
* is done by configure(), but some platforms need to do this very

82
sys/kern/subr_disk_open.c Normal file
View File

@ -0,0 +1,82 @@
/* $NetBSD: subr_disk_open.c,v 1.1 2009/09/06 16:18:56 pooka Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: subr_disk_open.c,v 1.1 2009/09/06 16:18:56 pooka Exp $");
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/disk.h>
#include <sys/disklabel.h>
#include <sys/fcntl.h>
#include <sys/kauth.h>
#include <sys/vnode.h>
struct vnode *
opendisk(struct device *dv)
{
int bmajor, bminor;
struct vnode *tmpvn;
int error;
dev_t dev;
/*
* Lookup major number for disk block device.
*/
bmajor = devsw_name2blk(device_xname(dv), NULL, 0);
if (bmajor == -1)
return NULL;
bminor = minor(device_unit(dv));
/*
* Fake a temporary vnode for the disk, open it, and read
* and hash the sectors.
*/
dev = device_is_a(dv, "dk") ? makedev(bmajor, bminor) :
MAKEDISKDEV(bmajor, bminor, RAW_PART);
if (bdevvp(dev, &tmpvn))
panic("%s: can't alloc vnode for %s", __func__,
device_xname(dv));
error = VOP_OPEN(tmpvn, FREAD, NOCRED);
if (error) {
#ifndef DEBUG
/*
* Ignore errors caused by missing device, partition,
* or medium.
*/
if (error != ENXIO && error != ENODEV)
#endif
printf("%s: can't open dev %s (%d)\n",
__func__, device_xname(dv), error);
vput(tmpvn);
return NULL;
}
return tmpvn;
}