Пример #1
0
void
fmd_dr_init(void)
{
	const char *subclass = ESC_DR_AP_STATE_CHANGE;

	if (geteuid() != 0)
		return; /* legacy sysevent mechanism is still root-only */

	if ((fmd.d_dr_hdl = sysevent_bind_handle(fmd_dr_event)) == NULL)
		fmd_error(EFMD_EXIT, "failed to bind handle for DR sysevent");

	if (sysevent_subscribe_event(fmd.d_dr_hdl, EC_DR, &subclass, 1) == -1)
		fmd_error(EFMD_EXIT, "failed to subscribe for DR sysevent");
}
Пример #2
0
/*
 * Search the list of devices under SVM for the specified device.
 */
int
inuse_svm(char *slice, nvlist_t *attrs, int *errp)
{
	struct svm_list	*listp;
	int		found = 0;

	*errp = 0;
	if (slice == NULL) {
	    return (found);
	}

	(void) mutex_lock(&init_lock);
	if (!initialized) {
		/* dynamically load libmeta */
		if (init_svm()) {
			/*
			 * need to initialize the cluster library to
			 * avoid seg faults
			 */
			(mdl_sdssc_bind_library)();

			/* load the SVM cache */
			*errp = load_svm();

			if (*errp == 0) {
				/* start a thread to monitor the svm config */
				sysevent_handle_t *shp;
				const char *subclass_list[1];
				/*
				 * Only start the svmevent thread if
				 * we are not doing an install
				 */

				if (getenv("_LIBDISKMGT_INSTALL") == NULL) {
					shp = sysevent_bind_handle(
					    event_handler);
					if (shp != NULL) {
						subclass_list[0] = EC_SUB_ALL;
						if (sysevent_subscribe_event(
						    shp, EC_SVM_CONFIG,
						    subclass_list, 1) != 0) {
							*errp = errno;
						}
					} else {
						*errp = errno;
					}
					if (*errp) {
						/*
						 * If the sysevent thread fails,
						 * log the error but continue
						 * on. This failing to start
						 * is not catastrophic in
						 * particular for short lived
						 * consumers of libdiskmgt.
						 */
						syslog(LOG_WARNING,
						    dgettext(TEXT_DOMAIN,
						    "libdiskmgt: sysevent "
						    "thread for SVM failed "
						    "to start\n"));
						*errp = 0;
					}
				}
			}
		}

		if (*errp == 0) {
			initialized = 1;
		}
	}
	(void) mutex_unlock(&init_lock);

	(void) rw_rdlock(&svm_lock);
	listp = svm_listp;
	while (listp != NULL) {
	    if (strcmp(slice, listp->slice) == 0) {
		libdiskmgt_add_str(attrs, DM_USED_BY, DM_USE_SVM, errp);
		if (strcmp(listp->type, "mdb") == 0 ||
		    strcmp(listp->type, "hs") == 0) {

		    libdiskmgt_add_str(attrs, DM_USED_NAME, listp->type, errp);
		} else {
		    char name[MAXPATHLEN];
		    (void) snprintf(name, MAXPATHLEN, "%s:%s", listp->type,
			listp->name);
		    libdiskmgt_add_str(attrs, DM_USED_NAME, name, errp);
		}
		found = 1;
		break;
	    }
	    listp = listp->next;
	}
	(void) rw_unlock(&svm_lock);

	return (found);
}
Пример #3
0
/* Registers the plugin to the sysevent framework */
MP_STATUS
init_sysevents(void) {

	const char *subclass_list[] = {

		ESC_SUN_MP_PLUGIN_CHANGE,

		ESC_SUN_MP_LU_CHANGE,
		ESC_SUN_MP_LU_ADD,
		ESC_SUN_MP_LU_REMOVE,

		ESC_SUN_MP_PATH_CHANGE,
		ESC_SUN_MP_PATH_ADD,
		ESC_SUN_MP_PATH_REMOVE,

		ESC_SUN_MP_INIT_PORT_CHANGE,

		ESC_SUN_MP_TPG_CHANGE,
		ESC_SUN_MP_TPG_ADD,
		ESC_SUN_MP_TPG_REMOVE,

		ESC_SUN_MP_TARGET_PORT_CHANGE,
		ESC_SUN_MP_TARGET_PORT_ADD,
		ESC_SUN_MP_TARGET_PORT_REMOVE,

		ESC_SUN_MP_DEV_PROD_CHANGE,
		ESC_SUN_MP_DEV_PROD_ADD,
		ESC_SUN_MP_DEV_PROD_REMOVE

	};

	const char *init_port_subclass_list[] = {

		ESC_DDI_INITIATOR_REGISTER,
		ESC_DDI_INITIATOR_UNREGISTER
	};



	log(LOG_INFO, "init_sysevents()", "- enter");


	g_SysEventHandle = sysevent_bind_handle(sysevent_handler);
	if (g_SysEventHandle == NULL) {

		log(LOG_INFO, "init_sysevents()",
		    "- sysevent_bind_handle() failed");

		log(LOG_INFO, "init_sysevents()", "- error exit");

		return (MP_STATUS_FAILED);
	}

	if (sysevent_subscribe_event(g_SysEventHandle, EC_SUN_MP,
	    subclass_list, sizeof (subclass_list) / sizeof (subclass_list[0]))
	    != 0) {


		log(LOG_INFO, "init_sysevents()",
		    "- sysevent_subscribe_event() failed for subclass_list");

		log(LOG_INFO, "init_sysevents()", "- error exit");

		sysevent_unbind_handle(g_SysEventHandle);

		return (MP_STATUS_FAILED);
	}

	if (sysevent_subscribe_event(g_SysEventHandle, EC_DDI,
	    init_port_subclass_list, sizeof (init_port_subclass_list) /
	    sizeof (init_port_subclass_list[0])) != 0) {


		log(LOG_INFO, "init_sysevents()",
		    "- sysevent_subscribe_event() failed "
		    "for init_port_subclass_list");

		log(LOG_INFO, "init_sysevents()", "- error exit");

		sysevent_unbind_handle(g_SysEventHandle);

		return (MP_STATUS_FAILED);
	}


	log(LOG_INFO, "init_sysevents()", "- exit");

	return (MP_STATUS_SUCCESS);
}