Date: Thu, 23 Sep 2010 10:42:33 -0700 From: "Ricky Charlet" <RCharlet@adaranet.com> To: John Baldwin <jhb@freebsd.org>, "freebsd-drivers@freebsd.org" <freebsd-drivers@freebsd.org> Subject: RE: newbie trouble with destroy_dev Message-ID: <32AB5C9615CC494997D9ABB1DB12783C024C950492@SJ-EXCH-1.adaranet.com> In-Reply-To: <201009230949.12884.jhb@freebsd.org> References: <32AB5C9615CC494997D9ABB1DB12783C024C95033B@SJ-EXCH-1.adaranet.com> <201009230949.12884.jhb@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Thanks. That totally worked. Lesson learned =3D destroy_dev sooner than des= troy cv's and mutexes's and internal state. One question though... I did not find any "DYING" flag in relation = to cv's or mutexes. So I just skipped that step in your advice. I only foun= d the string "DYING" in relation to jails, sound-drivers, some network stuf= f and ipsec. Will you give me a little more specific pointer to what "DYING= " flag you were referring to? FYI, my userland program sitting in the read loop exited cleanly an= d got errno=3DENXIO, which is beautiful. Thanks again. --- Ricky Charlet Adara Networks USA 408-433-4942 -----Original Message----- From: John Baldwin [mailto:jhb@freebsd.org] Sent: Thursday, September 23, 2010 6:49 AM To: freebsd-drivers@freebsd.org Cc: Ricky Charlet Subject: Re: newbie trouble with destroy_dev On Wednesday, September 22, 2010 3:11:10 pm Ricky Charlet wrote: > Howdy, > > My goal is to destroy a character device which is current= ly open for read. Is that allowable? I'm hoping the userland program doing the reading will simply get a read error back (possibly with no data or truncat= ed data). > > My experience so far is that I crash the box. > > I'm using BSD 8.0. My program with the driver is a kerne= l module. Upon using the `kldunload` utility, the d_close() method is called.= I have tried these logic flows: > > Test 1 > --------------------- > Unhook my packet-filter-hooks > cv_broadcast; > cv_destory > mMtx_destroy > destroy_dev > free associated buffers > > Test 2 > -------------------- > Unhook my packet-filter-hooks > cv_broadcast; > cv_destory > mMtx_destroy > destroy_dev_sched_cb > free associated buffers > > Test 3 > ---------------------- > Unhook my packet-filter-hooks > cv_broadcast; > cv_destory > mMtx_destroy > free associated buffers > > > In all cases I get a kernel crash and the system reboots. Note that the userland program has the associated charater device open and = is in a for-ever loop reading the fd. > > I'm a newbie and have not yet attached a debugger. I'll g= o start reading about that and trying it out while I hopefully await replies. Call destroy_dev() earlier, before you destroy any state. Your cdevsw routines can be invoked right up until destroy_dev() returns, so if you destroy the mutex before destroy_dev() you might destroy it before a cdevsw routine tries to use it. I suspect you might need something like: unhook_packet_filters set DYING flag (for listeners to the cv to know to exit, etc.) cv_broadcast() destroy_dev() free buffers cv_destroy() mtx_destroy() -- John Baldwin
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?32AB5C9615CC494997D9ABB1DB12783C024C950492>