xref: /illumos-gate/usr/src/lib/librcm/librcm_impl.h (revision 1da57d55)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*25e8c5aaSvikram  * Common Development and Distribution License (the "License").
6*25e8c5aaSvikram  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*25e8c5aaSvikram  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _LIBRCM_IMPL_H
277c478bd9Sstevel@tonic-gate #define	_LIBRCM_IMPL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <assert.h>
347c478bd9Sstevel@tonic-gate #include <stdio.h>
357c478bd9Sstevel@tonic-gate #include <stdarg.h>
367c478bd9Sstevel@tonic-gate #include <dlfcn.h>
377c478bd9Sstevel@tonic-gate #include <errno.h>
387c478bd9Sstevel@tonic-gate #include <fcntl.h>
397c478bd9Sstevel@tonic-gate #include <poll.h>
407c478bd9Sstevel@tonic-gate #include <stdlib.h>
417c478bd9Sstevel@tonic-gate #include <string.h>
427c478bd9Sstevel@tonic-gate #include <strings.h>
437c478bd9Sstevel@tonic-gate #include <syslog.h>
447c478bd9Sstevel@tonic-gate #include <unistd.h>
457c478bd9Sstevel@tonic-gate #include <sys/mman.h>
467c478bd9Sstevel@tonic-gate #include <sys/wait.h>
477c478bd9Sstevel@tonic-gate #include <sys/types.h>
487c478bd9Sstevel@tonic-gate #include <sys/stat.h>
497c478bd9Sstevel@tonic-gate #include <sys/param.h>
507c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
517c478bd9Sstevel@tonic-gate #include <librcm.h>
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  * This file contains information private to librcm rcm_daemon.
557c478bd9Sstevel@tonic-gate  */
567c478bd9Sstevel@tonic-gate #define	RCM_DAEMON_START	"/usr/lib/rcm/rcm_daemon"
577c478bd9Sstevel@tonic-gate #define	RCM_SERVICE_DOOR	"/var/run/rcm_daemon_door"
587c478bd9Sstevel@tonic-gate #define	RCM_MODULE_SUFFIX	"_rcm.so"
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /*
617c478bd9Sstevel@tonic-gate  * flag fields supported by individual librcm interfaces
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate #define	RCM_ALLOC_HDL_MASK	(RCM_NOPID)
647c478bd9Sstevel@tonic-gate #define	RCM_GET_INFO_MASK	(RCM_INCLUDE_SUBTREE|RCM_INCLUDE_DEPENDENT|\
657c478bd9Sstevel@tonic-gate 				RCM_DR_OPERATION|RCM_MOD_INFO|RCM_FILESYS)
667c478bd9Sstevel@tonic-gate #define	RCM_REGISTER_MASK	(RCM_FILESYS|RCM_REGISTER_DR|\
677c478bd9Sstevel@tonic-gate 				RCM_REGISTER_EVENT|RCM_REGISTER_CAPACITY)
687c478bd9Sstevel@tonic-gate #define	RCM_REQUEST_MASK	(RCM_QUERY|RCM_SCOPE|RCM_FORCE|RCM_FILESYS|\
69*25e8c5aaSvikram 				RCM_QUERY_CANCEL|RCM_RETIRE_REQUEST)
70*25e8c5aaSvikram #define	RCM_NOTIFY_MASK		(RCM_FILESYS|RCM_RETIRE_NOTIFY)
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /* event data names */
737c478bd9Sstevel@tonic-gate #define	RCM_CMD			"rcm.cmd"
747c478bd9Sstevel@tonic-gate #define	RCM_RESULT		"rcm.result"
757c478bd9Sstevel@tonic-gate #define	RCM_RESULT_INFO		"rcm.result_info"
767c478bd9Sstevel@tonic-gate #define	RCM_RSRCNAMES		"rcm.rsrcnames"
777c478bd9Sstevel@tonic-gate #define	RCM_RSRCSTATE		"rcm.rsrcstate"
787c478bd9Sstevel@tonic-gate #define	RCM_CLIENT_ID		"rcm.client_id"
797c478bd9Sstevel@tonic-gate #define	RCM_CLIENT_INFO		"rcm.client_info"
807c478bd9Sstevel@tonic-gate #define	RCM_CLIENT_ERROR	"rcm.client_error"
817c478bd9Sstevel@tonic-gate #define	RCM_CLIENT_MODNAME	"rcm.client_modname"
827c478bd9Sstevel@tonic-gate #define	RCM_CLIENT_PROPERTIES	"rcm.client_properties"
837c478bd9Sstevel@tonic-gate #define	RCM_SEQ_NUM		"rcm.seq_num"
847c478bd9Sstevel@tonic-gate #define	RCM_REQUEST_FLAG	"rcm.request_flag"
857c478bd9Sstevel@tonic-gate #define	RCM_SUSPEND_INTERVAL	"rcm.suspend_interval"
867c478bd9Sstevel@tonic-gate #define	RCM_CHANGE_DATA		"rcm.change_data"
877c478bd9Sstevel@tonic-gate #define	RCM_EVENT_DATA		"rcm.event_data"
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /*
907c478bd9Sstevel@tonic-gate  * action commands shared by librcm and rcm_daemon
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate #define	CMD_KNOCK		0
937c478bd9Sstevel@tonic-gate #define	CMD_REGISTER		1
947c478bd9Sstevel@tonic-gate #define	CMD_UNREGISTER		2
957c478bd9Sstevel@tonic-gate #define	CMD_GETINFO		3
967c478bd9Sstevel@tonic-gate #define	CMD_SUSPEND		4
977c478bd9Sstevel@tonic-gate #define	CMD_RESUME		5
987c478bd9Sstevel@tonic-gate #define	CMD_OFFLINE		6
997c478bd9Sstevel@tonic-gate #define	CMD_ONLINE		7
1007c478bd9Sstevel@tonic-gate #define	CMD_REMOVE		8
1017c478bd9Sstevel@tonic-gate #define	CMD_EVENT		9
1027c478bd9Sstevel@tonic-gate #define	CMD_REQUEST_CHANGE	10
1037c478bd9Sstevel@tonic-gate #define	CMD_NOTIFY_CHANGE	11
1047c478bd9Sstevel@tonic-gate #define	CMD_GETSTATE		12
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * Ops vector for calling directly into daemon from RCM modules
1087c478bd9Sstevel@tonic-gate  */
1097c478bd9Sstevel@tonic-gate typedef struct {
1107c478bd9Sstevel@tonic-gate 	int	(*librcm_regis)();
1117c478bd9Sstevel@tonic-gate 	int	(*librcm_unregis)();
1127c478bd9Sstevel@tonic-gate 	int	(*librcm_getinfo)();
1137c478bd9Sstevel@tonic-gate 	int	(*librcm_suspend)();
1147c478bd9Sstevel@tonic-gate 	int	(*librcm_resume)();
1157c478bd9Sstevel@tonic-gate 	int	(*librcm_offline)();
1167c478bd9Sstevel@tonic-gate 	int	(*librcm_online)();
1177c478bd9Sstevel@tonic-gate 	int	(*librcm_remove)();
1187c478bd9Sstevel@tonic-gate 	int	(*librcm_request_change)();
1197c478bd9Sstevel@tonic-gate 	int	(*librcm_notify_change)();
1207c478bd9Sstevel@tonic-gate 	int	(*librcm_notify_event)();
1217c478bd9Sstevel@tonic-gate 	int	(*librcm_getstate)();
1227c478bd9Sstevel@tonic-gate } librcm_ops_t;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate /*
1257c478bd9Sstevel@tonic-gate  * rcm handle struture
1267c478bd9Sstevel@tonic-gate  */
1277c478bd9Sstevel@tonic-gate struct rcm_handle {
1287c478bd9Sstevel@tonic-gate 	char		*modname;
1297c478bd9Sstevel@tonic-gate 	pid_t		pid;
1307c478bd9Sstevel@tonic-gate 	int		seq_num;
1317c478bd9Sstevel@tonic-gate 	librcm_ops_t	*lrcm_ops;
1327c478bd9Sstevel@tonic-gate 	struct module	*module;
1337c478bd9Sstevel@tonic-gate };
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate struct rcm_info {
1367c478bd9Sstevel@tonic-gate 	nvlist_t *info;
1377c478bd9Sstevel@tonic-gate 	struct rcm_info	*next;
1387c478bd9Sstevel@tonic-gate };
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate /*
1417c478bd9Sstevel@tonic-gate  * module utility routines
1427c478bd9Sstevel@tonic-gate  */
1437c478bd9Sstevel@tonic-gate char *rcm_module_dir(uint_t);
1447c478bd9Sstevel@tonic-gate void *rcm_module_open(char *);
1457c478bd9Sstevel@tonic-gate void rcm_module_close(void *);
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate /*
1487c478bd9Sstevel@tonic-gate  * rcm scripting utility routines
1497c478bd9Sstevel@tonic-gate  */
1507c478bd9Sstevel@tonic-gate char *rcm_script_dir(uint_t dirnum);
1517c478bd9Sstevel@tonic-gate char *rcm_dir(uint_t dirnum, int *rcm_script);
1527c478bd9Sstevel@tonic-gate char *rcm_get_script_dir(char *script_name);
1537c478bd9Sstevel@tonic-gate int rcm_is_script(char *filename);
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate #endif
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate #endif /* _LIBRCM_IMPL_H */
161