Commit 64bf0b1a authored by NeilBrown's avatar NeilBrown Committed by Greg Kroah-Hartman
Browse files

staging: lustre: refactor libcfs initialization.



Many lustre modules depend on libcfs having initialized
properly, but do not explicit check that it did.
When lustre is built as discrete modules, this does not
cause a problem because if the libcfs module fails
initialization, the other modules don't even get loaded.

When lustre is compiled into the kernel, all module_init()
routines get run, so they need to check the required initialization
succeeded.

This patch splits out the initialization of libcfs into a new
libcfs_setup(), and has all modules call that.

The misc_register() call is kept separate as it does not allocate any
resources and if it fails, it fails hard - no point in retrying.
Other set-up allocates resources and so is best delayed until they
are needed, and can be worth retrying.

Ideally, the initialization would happen at mount time (or similar)
rather than at load time.  Doing this requires each module to
check dependencies when they are activated rather than when
they are loaded.  Achieving that is a much larger job that would
have to progress in stages.

For now, this change ensures that if some initialization in libcfs
fails, other modules will fail-safe.

Signed-off-by: default avatarNeilBrown <neilb@suse.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e67f133d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -137,6 +137,7 @@ struct libcfs_ioctl_handler {

int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
int libcfs_setup(void);

#define _LIBCFS_H

+6 −0
Original line number Diff line number Diff line
@@ -2928,6 +2928,8 @@ static void __exit ko2iblnd_exit(void)

static int __init ko2iblnd_init(void)
{
	int rc;

	BUILD_BUG_ON(sizeof(struct kib_msg) > IBLND_MSG_SIZE);
	BUILD_BUG_ON(offsetof(struct kib_msg,
			  ibm_u.get.ibgm_rd.rd_frags[IBLND_MAX_RDMA_FRAGS])
@@ -2938,6 +2940,10 @@ static int __init ko2iblnd_init(void)

	kiblnd_tunables_init();

	rc = libcfs_setup();
	if (rc)
		return rc;

	lnet_register_lnd(&the_o2iblnd);

	return 0;
+4 −0
Original line number Diff line number Diff line
@@ -2903,6 +2903,10 @@ static int __init ksocklnd_init(void)
	if (rc)
		return rc;

	rc = libcfs_setup();
	if (rc)
		return rc;

	lnet_register_lnd(&the_ksocklnd);

	return 0;
+4 −2
Original line number Diff line number Diff line
@@ -426,7 +426,8 @@ int cfs_crypto_register(void)
{
	request_module("crc32c");

	adler32 = cfs_crypto_adler32_register();
	if (cfs_crypto_adler32_register() == 0)
		adler32 = 1;

	/* check all algorithms and do performance test */
	cfs_crypto_test_hashes();
@@ -438,6 +439,7 @@ int cfs_crypto_register(void)
 */
void cfs_crypto_unregister(void)
{
	if (!adler32)
	if (adler32)
		cfs_crypto_adler32_unregister();
	adler32 = 0;
}
+42 −20
Original line number Diff line number Diff line
@@ -320,6 +320,8 @@ static struct miscdevice libcfs_dev = {
	.fops = &libcfs_fops,
};

static int libcfs_dev_registered;

int lprocfs_call_handler(void *data, int write, loff_t *ppos,
			 void __user *buffer, size_t *lenp,
			 int (*handler)(void *data, int write, loff_t pos,
@@ -687,49 +689,70 @@ static void lustre_remove_debugfs(void)
	lnet_debugfs_root = NULL;
}

static int libcfs_init(void)
static DEFINE_MUTEX(libcfs_startup);
static int libcfs_active;

int libcfs_setup(void)
{
	int rc;
	int rc = -EINVAL;

	mutex_lock(&libcfs_startup);
	if (libcfs_active)
		goto out;

	if (!libcfs_dev_registered)
		goto err;

	rc = libcfs_debug_init(5 * 1024 * 1024);
	if (rc < 0) {
		pr_err("LustreError: libcfs_debug_init: %d\n", rc);
		return rc;
		goto err;
	}

	rc = cfs_cpu_init();
	if (rc)
		goto cleanup_debug;

	rc = misc_register(&libcfs_dev);
	if (rc) {
		CERROR("misc_register: error %d\n", rc);
		goto cleanup_cpu;
	}
		goto err;

	cfs_rehash_wq = alloc_workqueue("cfs_rh", WQ_SYSFS, 4);
	if (!cfs_rehash_wq) {
		CERROR("Failed to start rehash workqueue.\n");
		rc = -ENOMEM;
		goto cleanup_deregister;
		goto err;
	}

	rc = cfs_crypto_register();
	if (rc) {
		CERROR("cfs_crypto_register: error %d\n", rc);
		goto cleanup_deregister;
		goto err;
	}

	lustre_insert_debugfs(lnet_table, lnet_debugfs_symlinks);

	CDEBUG(D_OTHER, "portals setup OK\n");
out:
	libcfs_active = 1;
	mutex_unlock(&libcfs_startup);
	return 0;
 cleanup_deregister:
	misc_deregister(&libcfs_dev);
cleanup_cpu:
err:
	cfs_crypto_unregister();
	if (cfs_rehash_wq)
		destroy_workqueue(cfs_rehash_wq);
	cfs_cpu_fini();
 cleanup_debug:
	libcfs_debug_cleanup();
	mutex_unlock(&libcfs_startup);
	return rc;
}
EXPORT_SYMBOL(libcfs_setup);

static int libcfs_init(void)
{
	int rc;

	rc = misc_register(&libcfs_dev);
	if (rc)
		CERROR("misc_register: error %d\n", rc);
	else
		libcfs_dev_registered = 1;
	return rc;
}

@@ -739,13 +762,12 @@ static void libcfs_exit(void)

	lustre_remove_debugfs();

	if (cfs_rehash_wq) {
	if (cfs_rehash_wq)
		destroy_workqueue(cfs_rehash_wq);
		cfs_rehash_wq = NULL;
	}

	cfs_crypto_unregister();

	if (libcfs_dev_registered)
		misc_deregister(&libcfs_dev);

	cfs_cpu_fini();
Loading