Beispiel #1
0
static int
dmtz_mod_handler(module_t mod, int type, void *unused)
{
	dm_target_t *dmt = NULL;
	int err = 0;

	switch(type) {
	case MOD_LOAD:
		if ((dmt = dm_target_lookup("zero")) != NULL) {
			dm_target_unbusy(dmt);
			return EEXIST;
		}
		dmt = dm_target_alloc("zero");
		dmt->version[0] = 1;
		dmt->version[1] = 0;
		dmt->version[2] = 0;
		dmt->strategy = &dm_target_zero_strategy;

		err = dm_target_insert(dmt);
		if (err == 0)
			kprintf("dm_target_zero: Successfully initialized\n");
		break;

	case MOD_UNLOAD:
		err = dm_target_remove("zero");
		if (err == 0)
			kprintf("dm_target_zero: unloaded\n");
		break;
	}

	return err;
}
Beispiel #2
0
static int
dmte_mod_handler(module_t mod, int type, void *unused)
{
	dm_target_t *dmt = NULL;
	int err = 0;

	switch(type) {
	case MOD_LOAD:
		if ((dmt = dm_target_lookup("error")) != NULL) {
			dm_target_unbusy(dmt);
			return EEXIST;
		}
		dmt = dm_target_alloc("error");
		dmt->version[0] = 1;
		dmt->version[1] = 0;
		dmt->version[2] = 0;
		strlcpy(dmt->name, "error", DM_MAX_TYPE_NAME);
		dmt->init = &dm_target_error_init;
		dmt->status = &dm_target_error_status;
		dmt->strategy = &dm_target_error_strategy;
		dmt->deps = &dm_target_error_deps;
		dmt->destroy = &dm_target_error_destroy;
		dmt->upcall = &dm_target_error_upcall;
		dmt->dump = NULL;

		err = dm_target_insert(dmt);
		if (err == 0)
			kprintf("dm_target_error: Successfully initialized\n");
		break;

	case MOD_UNLOAD:
		err = dm_target_rem("error");
		if (err == 0)
			kprintf("dm_target_error: unloaded\n");
		break;

	default:
		break;
	}

	return err;
}
static int
dm_target_snapshot_modcmd(modcmd_t cmd, void *arg)
{
	dm_target_t *dmt, *dmt1;
	int r;

	dmt = NULL;
	dmt1 = NULL;

	switch (cmd) {
	case MODULE_CMD_INIT:
		if (((dmt = dm_target_lookup("snapshot")) != NULL)) {
			dm_target_unbusy(dmt);
			return EEXIST;
		}
		if (((dmt = dm_target_lookup("snapshot-origin")) != NULL)) {
			dm_target_unbusy(dmt);
			return EEXIST;
		}
		dmt = dm_target_alloc("snapshot");
		dmt1 = dm_target_alloc("snapshot-origin");

		dmt->version[0] = 1;
		dmt->version[1] = 0;
		dmt->version[2] = 5;
		strlcpy(dmt->name, "snapshot", DM_MAX_TYPE_NAME);
		dmt->init = &dm_target_snapshot_init;
		dmt->status = &dm_target_snapshot_status;
		dmt->strategy = &dm_target_snapshot_strategy;
		dmt->deps = &dm_target_snapshot_deps;
		dmt->destroy = &dm_target_snapshot_destroy;
		dmt->upcall = &dm_target_snapshot_upcall;

		r = dm_target_insert(dmt);

		dmt1->version[0] = 1;
		dmt1->version[1] = 0;
		dmt1->version[2] = 5;
		strlcpy(dmt1->name, "snapshot-origin", DM_MAX_TYPE_NAME);
		dmt1->init = &dm_target_snapshot_orig_init;
		dmt1->status = &dm_target_snapshot_orig_status;
		dmt1->strategy = &dm_target_snapshot_orig_strategy;
		dmt1->sync = &dm_target_snapshot_orig_sync;
		dmt1->deps = &dm_target_snapshot_orig_deps;
		dmt1->destroy = &dm_target_snapshot_orig_destroy;
		dmt1->upcall = &dm_target_snapshot_orig_upcall;

		r = dm_target_insert(dmt1);
		break;

	case MODULE_CMD_FINI:
		/*
		 * Try to remove snapshot target if it works remove snap-origin
		 * it is not possible to remove snapshot and do not remove
		 * snap-origin because they are used together.
		 */
		if ((r = dm_target_rem("snapshot")) == 0)
			r = dm_target_rem("snapshot-origin");

		break;

	case MODULE_CMD_STAT:
		return ENOTTY;

	default:
		return ENOTTY;
	}

	return r;
}