Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Feb 2006 18:35:26 +0100
From:      Pawel Jakub Dawidek <pjd@FreeBSD.org>
To:        Dag-Erling Sm?rgrav <des@des.no>
Cc:        cvs-src@FreeBSD.org, src-committers@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/lib/libutil Makefile kld.3 kld.c libutil.h
Message-ID:  <20060218173526.GC849@garage.freebsd.pl>
In-Reply-To: <8664ncr2zz.fsf@xps.des.no>
References:  <200602181125.k1IBPSBu021102@repoman.freebsd.org> <20060218114331.GA849@garage.freebsd.pl> <86accor6wh.fsf@xps.des.no> <20060218172241.GB849@garage.freebsd.pl> <8664ncr2zz.fsf@xps.des.no>

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

--w7PDEPdKQumQfZlR
Content-Type: text/plain; charset=iso-8859-2
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Feb 18, 2006 at 06:27:44PM +0100, Dag-Erling Sm?rgrav wrote:
+> Pawel Jakub Dawidek <pjd@FreeBSD.org> writes:
+> > It doesn't change your API, just extends it. With this change I'll be
+> > able to use this functions in geom(8) without wrappers around them.
+> > And this is the whole point of having them, right?
+>=20
+> Please tell me what semantics you want instead of expecting me to read
+> your mind.

There are some cases where you cannot decide which module to load,
because it is provided at run-time.

In geom(8) I've something like this currently:

static void
load_module(void)
{
	char name1[64], name2[64];
=20
	snprintf(name1, sizeof(name1), "g_%s", class_name);
	snprintf(name2, sizeof(name2), "geom_%s", class_name);
	if (modfind(name1) < 0) {
		/* Not present in kernel, try loading it. */
		if (kldload(name2) < 0 || modfind(name1) < 0) {
			if (errno !=3D EEXIST) {
				errx(EXIT_FAILURE,
				    "%s module not available!", name2);
			}
		}
	}
}

Changing it to the version below doesn't really buy me anything:

static void
load_module(void)
{
	char name1[64], name2[64];
=20
	snprintf(name1, sizeof(name1), "g_%s", class_name);
	snprintf(name2, sizeof(name2), "geom_%s", class_name);
	if (!kld_isloaded(name1) && kld_load(name2) =3D=3D -1)
		err(1, "failed to load %s module", name2);
}

But changing it to the code below, or removing load_module entirely looks
like improvement:

static void
load_module(void)
{

	if (!kld_isloaded("g_%s", class_name) &&
	    kld_load("geom_%s", class_name) =3D=3D -1) {
		err(1, "failed to load geom_%s module", class_name);
	}
}

Yet another option is to reimplement kld_load(3) to:

	kld_load(const char *modname, const char *kldname);

(and eventually remove kld_isloaded(3)).

--=20
Pawel Jakub Dawidek                       http://www.wheel.pl
pjd@FreeBSD.org                           http://www.FreeBSD.org
FreeBSD committer                         Am I Evil? Yes, I Am!

--w7PDEPdKQumQfZlR
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (FreeBSD)

iD8DBQFD91reForvXbEpPzQRAhjKAJ0dGx17niyMFqZ1OXs/2BzhC/bnHwCgnAyP
7bbTsePqM0P2+POsYYp3Odc=
=xVtF
-----END PGP SIGNATURE-----

--w7PDEPdKQumQfZlR--



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