Date: Wed, 29 Jul 2009 15:39:05 -0400 From: "Chris Harrer" <cjharrer@comcast.net> To: "'Chris Harrer'" <cjharrer@comcast.net>, "'John Baldwin'" <jhb@freebsd.org> Cc: freebsd-drivers@freebsd.org Subject: RE: Driver development question Message-ID: <000f01ca1084$3c20caf0$b46260d0$@net> References: <002801ca06f0$b1d42af0$157c80d0$@net> <20090725035643.GT49724@elvis.mu.org> <000c01ca1071$54991d70$fdcb5850$@net> <200907291356.51702.jhb@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Hi John, Sorry for top posting... I put a delay in my thread waiting for rootvnode to be set and I'm able to create a file now. Thanks! Chris -----Original Message----- From: Chris Harrer [mailto:cjharrer@comcast.net] Sent: Wednesday, July 29, 2009 2:51 PM To: 'Chris Harrer'; 'John Baldwin' Cc: 'Alfred Perlstein'; 'freebsd-drivers@freebsd.org' Subject: RE: Driver development question >The problem is that kernel threads do not have a valid file descriptor table, >hence fd_cdir is NULL. You could work around this if you create a dedicated >kproc and set fd_cdir to rootvnode (but vref() rootvnode when you do this). >You should also set fd_rdir and fd_jdir to rootvnode as well (also doing >appropriate vref() of rootvnode for each reference). Something like this: > > struct filedesc *fdp; > > fdp = curthread->td_proc->p_fd; > FILEDESC_XLOCK(fdp); > fd->fd_rdir = rootvnode; > vref(rootvnode); > fd->fd_jdir = rootvnode; > vref(rootvnode); > fd->fd_cdir = rootvnode; > vref(rootvnode); > FILEDESC_XUNLOCK(fdp); > >You should not do this from a callout routine or interrupt handler however. >You could do this via a TASK to a private taskqueue with a dedicated kernel >process however. (i.e. queue a task that does the above during after >creating the taskqueue and then queue a task to create the file later). > >-- >John Baldwin Hi John, I tried this and rootvnode = 0x0, so I am still getting a SIGSEGV. I create a thread in my "attach" routine via: status = kproc_create(sxg_dump_thread, adapter, &adapter->dumpproc, RFNOWAIT , 0, "sxgdump"); if (status) { SXG_DBG_MSG(adapter->dev, "%s[%p], Cannot create dump thread, status: %d\n", __func__, adapter, status); return (status); } Then my thread does: static void sxg_dump_thread(void * arg) { adapter_t *adapter = (adapter_t *)arg; struct filedesc *fdp; ulong32 index = 0; // Set up some file descriptor stuff so we can // actually open/create a dump file. Kernel // threads, by design, do not have a valid // file descriptor table. So, we're gonna // make this thread point to one! fdp = curthread->td_proc->p_fd; FILEDESC_XLOCK(fdp); fdp->fd_rdir = rootvnode; vref(rootvnode); <----- SIGSEGV on this line, rootvnode = 0x0 fdp->fd_jdir = rootvnode; vref(rootvnode); fdp->fd_cdir = rootvnode; vref(rootvnode); FILEDESC_XUNLOCK(fdp); for (;;){ ... Sorry if I'm doing something obviously wrong, I'm trying to come up to speed as quickly as I can. Cheers, Chris
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000f01ca1084$3c20caf0$b46260d0$>