Date: Sat, 24 Feb 2001 00:46:54 +0900 From: "Daniel C. Sobral" <dcs@newsguy.com> To: dcs@FreeBSD.org Cc: freebsd-bugs@FreeBSD.org, David Xu <davidx@viasoft.com.cn> Subject: Re: kern/25130: kernel crash with kldload/kldunload md.ko Message-ID: <3A9685EE.CCF85BAE@newsguy.com> References: <200102220941.f1M9fbm50374@freefall.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. --------------6F6CA58BE66EC1938BC65A35 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit dcs@FreeBSD.org wrote: > > Synopsis: kernel crash with kldload/kldunload md.ko > > Responsible-Changed-From-To: freebsd-bugs->dcs > Responsible-Changed-By: dcs > Responsible-Changed-When: Thu Feb 22 01:41:01 PST 2001 > Responsible-Changed-Why: > I'm working on it right now. > > http://www.freebsd.org/cgi/query-pr.cgi?pr=25130 See attached md.diff. While you are at it, attached mdconfig.diff automatically loads the md.ko if the module is not present. -- Daniel C. Sobral (8-DCS) dcs@newsguy.com dcs@freebsd.org capo@kzinti.bsdconspiracy.net Acabou o hipismo-arte. Mas a desculpa brasileira mais ouvida em Sydney e' que nao tem mais cavalo bobo por ai'. --------------6F6CA58BE66EC1938BC65A35 Content-Type: text/plain; charset=us-ascii; name="md.diff" Content-Disposition: inline; filename="md.diff" Content-Transfer-Encoding: 7bit Index: md.c =================================================================== RCS file: /home/ncvs/src/sys/dev/md/md.c,v retrieving revision 1.23 diff -u -p -r1.23 md.c --- md.c 2001/01/28 20:55:55 1.23 +++ md.c 2001/02/22 10:27:35 @@ -85,6 +85,8 @@ #include <vm/vm_zone.h> #include <vm/swap_pager.h> +#define MD_MODVER 1 + #ifndef MD_NSECT #define MD_NSECT (10000 * 2) #endif @@ -110,9 +112,11 @@ SYSCTL_INT(_debug, OID_AUTO, mddebug, CT static u_char mfs_root[MD_ROOT_SIZE*1024] = "MFS Filesystem goes here"; static u_char end_mfs_root[] __unused = "MFS Filesystem had better STOP here"; #endif + +static int mdrootready; +static int mdunits; +static dev_t status_dev = 0; -static int mdrootready; -static int mdunits; #define CDEV_MAJOR 95 @@ -883,10 +887,37 @@ md_drvinit(void *unused) mdunits, name, len, ptr); md_preloaded(ptr, len); } - make_dev(&mdctl_cdevsw, 0xffff00ff, UID_ROOT, GID_WHEEL, 0600, "mdctl"); + status_dev = make_dev(&mdctl_cdevsw, 0xffff00ff, UID_ROOT, GID_WHEEL, 0600, "mdctl"); } + +static int +md_modevent(module_t mod, int type, void *data) +{ + switch (type) { + case MOD_LOAD: + md_drvinit(NULL); + break; + case MOD_UNLOAD: + if (!LIST_EMPTY(&md_softc_list)) + return EBUSY; + if (status_dev) + destroy_dev(status_dev); + status_dev = 0; + break; + default: + break; + } + return 0; +} + +static moduledata_t md_mod = { + "md", + md_modevent, + NULL +}; +DECLARE_MODULE(md, md_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+CDEV_MAJOR); +MODULE_VERSION(md, MD_MODVER); -SYSINIT(mddev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR, md_drvinit,NULL) #ifdef MD_ROOT static void --------------6F6CA58BE66EC1938BC65A35 Content-Type: text/plain; charset=us-ascii; name="mdconfig.diff" Content-Disposition: inline; filename="mdconfig.diff" Content-Transfer-Encoding: 7bit Index: mdconfig.c =================================================================== RCS file: /home/ncvs/src/sbin/mdconfig/mdconfig.c,v retrieving revision 1.6 diff -u -p -r1.6 mdconfig.c --- mdconfig.c 2001/01/31 08:41:18 1.6 +++ mdconfig.c 2001/02/22 07:53:19 @@ -18,12 +18,16 @@ #include <err.h> #include <sys/ioctl.h> #include <sys/param.h> +#include <sys/module.h> +#include <sys/linker.h> #include <sys/mdioctl.h> struct md_ioctl mdio; enum {UNSET, ATTACH, DETACH} action = UNSET; +void mdmaybeload(void); + void usage() { @@ -139,6 +143,7 @@ main(int argc, char **argv) } } + mdmaybeload(); fd = open("/dev/mdctl", O_RDWR, 0); if (fd < 0) err(1, "open(/dev/mdctl)"); @@ -154,5 +159,36 @@ main(int argc, char **argv) if (mdio.md_options & MD_AUTOUNIT) printf("md%d\n", mdio.md_unit); return (0); +} + +void +mdmaybeload(void) +{ + struct module_stat mstat; + int fileid, modid; + char *name = "md"; + char *cp; + + /* scan files in kernel */ + mstat.version = sizeof(struct module_stat); + for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) { + /* scan modules in file */ + for (modid = kldfirstmod(fileid); modid > 0; + modid = modfnext(modid)) { + if (modstat(modid, &mstat) < 0) + continue; + /* strip bus name if present */ + if ((cp = strchr(mstat.name, '/')) != NULL) { + cp++; + } else { + cp = mstat.name; + } + /* already loaded? */ + if (!strcmp(name, cp)) + return; + } + } + /* not present, we should try to load it */ + kldload(name); } --------------6F6CA58BE66EC1938BC65A35-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3A9685EE.CCF85BAE>