From owner-freebsd-fs@FreeBSD.ORG Tue Oct 4 00:22:17 2011 Return-Path: Delivered-To: fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0CC9C106566C; Tue, 4 Oct 2011 00:22:17 +0000 (UTC) (envelope-from lstewart@freebsd.org) Received: from lauren.room52.net (lauren.room52.net [210.50.193.198]) by mx1.freebsd.org (Postfix) with ESMTP id C2F558FC0C; Tue, 4 Oct 2011 00:22:16 +0000 (UTC) Received: from lstewart1.loshell.room52.net (ppp59-167-184-191.static.internode.on.net [59.167.184.191]) by lauren.room52.net (Postfix) with ESMTPSA id 162E27E896; Tue, 4 Oct 2011 11:22:15 +1100 (EST) Message-ID: <4E8A51B6.8090108@freebsd.org> Date: Tue, 04 Oct 2011 11:22:14 +1100 From: Lawrence Stewart User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:6.0.2) Gecko/20110914 Thunderbird/6.0.2 MIME-Version: 1.0 To: Kostik Belousov References: <1258376930.20111002193223@serebryakov.spb.ru> <228926402.20111002231459@serebryakov.spb.ru> <349860851.20111003113417@serebryakov.spb.ru> <4E8986F0.3050007@freebsd.org> <1223820108.20111003161859@serebryakov.spb.ru> <20111003160145.GP1511@deviant.kiev.zoral.com.ua> In-Reply-To: <20111003160145.GP1511@deviant.kiev.zoral.com.ua> Content-Type: text/plain; charset=KOI8-R; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.0 required=5.0 tests=UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on lauren.room52.net Cc: fs@freebsd.org Subject: Re: code in GEOM thread could not use vnode API (Was: alq_open_flags() panics in _mtx_lock_flags()) X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 00:22:17 -0000 On 10/04/11 03:01, Kostik Belousov wrote: > On Mon, Oct 03, 2011 at 04:18:59PM +0400, Lev Serebryakov wrote: >> Hello, Lawrence. >> You wrote 3 октября 2011 г., 13:57:04: >> >>> I know nothing about VFS, but wonder if it's something to do with the >>> credentials you pass in? >> They looks Ok. Not NULL, at least :) I'm passing >> "curtrhead->td_ucred". >> >>> Lev, are you able to share your code with us? >> Yes, of course. Minimal code, which trigger this error, attached. >> Build, load module and PANIC! >> >> This is geom_zero module, which try to create ALQ with name >> "/var/log/zero.alq.log" on it load (not creation! So, you don't need >> even create such GEOM!). Please note, that "init" callback of GEOM >> class is called in g_event GEOM thread. >> >> Code is for 9.0/10.0 >> >> My code is rewritten with usage of working thread already, and it >> works without any panic. But worker thread looks like overkill for >> simple case "write 24 bytes record to ALQ for each BIO" to me. >> >> So I could prove, that this code PANIC because alq_open_flags() is >> called from one of three GEOM threads. > Look at the body of e.g. g_io_schedule_down(), the > THREAD_NO_SLEEPING(); > call right before the call to geom start method. Thanks Kostik, that's the context I was missing. > Basically, you cannot use any kernel subsystem in the context of > the up/down threads that could sleep. This includes VFS, VM and > everything that is layered on top of it. > > The decision is deliberate. Up and down shall only schedule the processing, > or perform the fast processing. > > BTW, it must be obvious that trying to perform any VFS operation from geom > up or down causes deadlock. So Lev, I believe what you can do is alq_open_flags() in a separate context (module init routine or a sysctl handler are good places) and then you should be able to use it in the sleep sensitive context, as ALQ is designed to work in such places if you pass the ALQ_NOWAIT flag to the other API calls. If you want an example, have a look at sys/netinet/siftr.c. The packet fast path is non-sleepable, so I create the ALQ when the enable sysctl is called (siftr_sysctl_enabled_handler -> siftr_manage_ops -> alq_open), although I defer the pkt processing work to a separate thread which does the alq_writes. You should be able to do the writes in the geom fast path without a separate thread if you prefer. Cheers, Lawrence