Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Oct 2011 16:18:59 +0400
From:      Lev Serebryakov <lev@FreeBSD.org>
To:        Lawrence Stewart <lstewart@freebsd.org>
Cc:        fs@freebsd.org
Subject:   Re: code in GEOM thread could not use vnode API (Was: alq_open_flags() panics in _mtx_lock_flags())
Message-ID:  <1223820108.20111003161859@serebryakov.spb.ru>
In-Reply-To: <4E8986F0.3050007@freebsd.org>
References:  <1258376930.20111002193223@serebryakov.spb.ru> <228926402.20111002231459@serebryakov.spb.ru> <349860851.20111003113417@serebryakov.spb.ru> <4E8986F0.3050007@freebsd.org>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
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.

-- 
// Black Lion AKA Lev Serebryakov <lev@FreeBSD.org>
[-- Attachment #2 --]
/*-
 * Copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include <sys/param.h>
#include <sys/bio.h>
#include <sys/kernel.h>
#include <sys/limits.h>
#include <sys/malloc.h>
#include <sys/queue.h>
#include <sys/sysctl.h>
#include <sys/systm.h>
#include <sys/alq.h>
#include <sys/proc.h>

#include <geom/geom.h>


#define	G_ZERO_CLASS_NAME	"ALQ-PANIC"

SYSCTL_DECL(_kern_geom);
SYSCTL_NODE(_kern_geom, OID_AUTO, zero, CTLFLAG_RW, 0, "GEOM_ALQ stuff");

static void
g_alq_start(struct bio *bp)
{
	int error = ENXIO;

	switch (bp->bio_cmd) {
	case BIO_READ:
	case BIO_DELETE:
	case BIO_WRITE:
		bp->bio_completed = bp->bio_length;
		error = 0;
		break;
	case BIO_GETATTR:
	default:
		error = EOPNOTSUPP;
		break;
	}
	g_io_deliver(bp, error);
}

static void
g_alq_init(struct g_class *mp)
{
	struct g_geom *gp;
	struct g_provider *pp;
	struct alq *alq;
	int error;

	g_topology_assert();
	gp = g_new_geomf(mp, "galq");
	gp->start = g_alq_start;
	gp->access = g_std_access;
	pp = g_new_providerf(gp, "%s", gp->name);
	pp->mediasize = 1152921504606846976LLU;
	pp->sectorsize = 512;
	g_error_provider(pp, 0);
	
	/* Trigger panic */
	error = alq_open_flags(&alq,  "/var/log/zero.alq.log",
	    curthread->td_ucred, ALQ_DEFAULT_CMODE,
	    16, ALQ_ORDERED);
	    
	if (!error)
		alq_close(alq);
}

static int
g_alq_destroy_geom(struct gctl_req *req __unused, struct g_class *mp __unused,
    struct g_geom *gp)
{
	struct g_provider *pp;

	g_topology_assert();
	if (gp == NULL)
		return (0);
	pp = LIST_FIRST(&gp->provider);
	if (pp == NULL)
		return (0);
	if (pp->acr > 0 || pp->acw > 0 || pp->ace > 0)
		return (EBUSY);
	g_wither_geom(gp, ENXIO);
	return (0);
}

static struct g_class g_alq_class = {
	.name = G_ZERO_CLASS_NAME,
	.version = G_VERSION,
	.init = g_alq_init,
	.destroy_geom = g_alq_destroy_geom
};

DECLARE_GEOM_CLASS(g_alq_class, g_alq);
MODULE_DEPEND(g_alq, alq, 1, 1, 1);

[-- Attachment #3 --]
CLASS=	alq

KERNBUILDROOT!=	make -C /usr/src/sys -V .OBJDIR
KERNNAME!=		uname -i
.if exists(${KERNBUILDROOT}/${KERNNAME}/opt_global.h) && !defined(KERNBUILDDIR)
KERNBUILDDIR:=${KERNBUILDROOT}/${KERNNAME}
.endif

KMODDIR?=	/boot/modules

KMOD=	geom_${CLASS}
SRCS=	g_${CLASS}.c

.include <bsd.kmod.mk>
help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1223820108.20111003161859>