From owner-freebsd-drivers@FreeBSD.ORG Wed Jul 29 19:39:07 2009 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3A99710657ED for ; Wed, 29 Jul 2009 19:39:07 +0000 (UTC) (envelope-from cjharrer@comcast.net) Received: from QMTA02.westchester.pa.mail.comcast.net (qmta02.westchester.pa.mail.comcast.net [76.96.62.24]) by mx1.freebsd.org (Postfix) with ESMTP id CF15E8FC16 for ; Wed, 29 Jul 2009 19:39:06 +0000 (UTC) (envelope-from cjharrer@comcast.net) Received: from OMTA24.westchester.pa.mail.comcast.net ([76.96.62.76]) by QMTA02.westchester.pa.mail.comcast.net with comcast id MnN71c0041ei1Bg52vf7oQ; Wed, 29 Jul 2009 19:39:07 +0000 Received: from record ([69.253.164.177]) by OMTA24.westchester.pa.mail.comcast.net with comcast id Mvhg1c0063py3KZ3kvhgcM; Wed, 29 Jul 2009 19:41:40 +0000 From: "Chris Harrer" To: "'Chris Harrer'" , "'John Baldwin'" References: <002801ca06f0$b1d42af0$157c80d0$@net> <20090725035643.GT49724@elvis.mu.org> <000c01ca1071$54991d70$fdcb5850$@net> <200907291356.51702.jhb@freebsd.org> In-Reply-To: Date: Wed, 29 Jul 2009 15:39:05 -0400 Message-ID: <000f01ca1084$3c20caf0$b46260d0$@net> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-index: AcoQdfiCG9t44+1bSKSxSEicpj0saQAAHWVQAAGBFBAAAe3ikA== Content-Language: en-us Cc: freebsd-drivers@freebsd.org Subject: RE: Driver development question X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Jul 2009 19:39:08 -0000 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