cvs commit: src/lib/libutil Makefile kld.3 kld.c libutil.h

Pawel Jakub Dawidek pjd at FreeBSD.org
Sat Feb 18 09:35:46 PST 2006


On Sat, Feb 18, 2006 at 06:27:44PM +0100, Dag-Erling Sm?rgrav wrote:
+> Pawel Jakub Dawidek <pjd at 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?
+> 
+> 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];
 
	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 != 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];
 
	snprintf(name1, sizeof(name1), "g_%s", class_name);
	snprintf(name2, sizeof(name2), "geom_%s", class_name);
	if (!kld_isloaded(name1) && kld_load(name2) == -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) == -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)).

-- 
Pawel Jakub Dawidek                       http://www.wheel.pl
pjd at FreeBSD.org                           http://www.FreeBSD.org
FreeBSD committer                         Am I Evil? Yes, I Am!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/cvs-all/attachments/20060218/b409337a/attachment.bin


More information about the cvs-all mailing list