6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2017 Nexenta Systems, Inc.
26 */
27
28 #include <sys/types.h>
29 #include <sys/inttypes.h>
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/user.h>
33 #include <sys/disp.h>
34 #include <sys/conf.h>
35 #include <sys/bootconf.h>
36 #include <sys/sysconf.h>
37 #include <sys/sunddi.h>
38 #include <sys/esunddi.h>
39 #include <sys/ddi_impldefs.h>
40 #include <sys/kmem.h>
41 #include <sys/vmem.h>
42 #include <sys/fs/ufs_fsdir.h>
43 #include <sys/hwconf.h>
44 #include <sys/modctl.h>
45 #include <sys/cmn_err.h>
50 #include <sys/autoconf.h>
51 #include <sys/callb.h>
52 #include <sys/sysmacros.h>
53 #include <sys/dacf.h>
54 #include <vm/seg_kmem.h>
55
56 struct hwc_class *hcl_head; /* head of list of classes */
57 static kmutex_t hcl_lock; /* for accessing list of classes */
58
59 #define DAFILE "/etc/driver_aliases"
60 #define CLASSFILE "/etc/driver_classes"
61 #define DACFFILE "/etc/dacf.conf"
62
63 static char class_file[] = CLASSFILE;
64 static char dafile[] = DAFILE;
65 static char dacffile[] = DACFFILE;
66
67 char *self_assembly = "/etc/system.d/.self-assembly";
68 char *systemfile = "/etc/system"; /* name of ascii system file */
69
70 static struct sysparam *sysparam_hd; /* head of parameters list */
71 static struct sysparam *sysparam_tl; /* tail of parameters list */
72 static vmem_t *mod_sysfile_arena; /* parser memory */
73
74 char obp_bootpath[BO_MAXOBJNAME]; /* bootpath from obp */
75
76 #if defined(_PSM_MODULES)
77
78 struct psm_mach {
79 struct psm_mach *m_next;
80 char *m_machname;
81 };
82
83 static struct psm_mach *pmach_head; /* head of list of classes */
84
85 #define MACHFILE "/etc/mach"
86 static char mach_file[] = MACHFILE;
87
88 #endif /* _PSM_MODULES */
89
794 sp->sys_next = NULL;
795 sysparam_tl->sys_next = sp;
796 sysparam_tl = sp;
797 }
798 last_tok = NAME;
799 break;
800 default:
801 kobj_file_err(CE_WARN,
802 file, tok_err, tokval);
803 kobj_find_eol(file);
804 break;
805 }
806 }
807 kobj_close_file(file);
808 }
809 }
810
811 void
812 mod_read_system_file(int ask)
813 {
814 mod_sysfile_arena = vmem_create("mod_sysfile", NULL, 0, 8,
815 segkmem_alloc, segkmem_free, heap_arena, 0, VM_SLEEP);
816
817 if (ask)
818 mod_askparams();
819
820 /*
821 * Read the user self-assembly file first
822 * to preserve existing system settings.
823 */
824 if (self_assembly != NULL)
825 read_system_file(self_assembly);
826
827 if (systemfile != NULL)
828 read_system_file(systemfile);
829
830 /*
831 * Sanity check of /etc/system.
832 */
833 check_system_file();
834
835 param_preset();
836 (void) mod_sysctl(SYS_SET_KVAR, NULL);
837 param_check();
838
839 if (ask == 0)
840 setparams();
841 }
842
843 /*
844 * Search for a specific module variable assignment in /etc/system. If
845 * successful, 1 is returned and the value is stored in '*value'.
846 * Otherwise 0 is returned and '*value' isn't modified. If 'module' is
847 * NULL we look for global definitions.
848 *
849 * This is useful if the value of an assignment is needed before a
850 * module is loaded (e.g. to obtain a default privileged rctl limit).
851 */
852 int
853 mod_sysvar(const char *module, const char *name, u_longlong_t *value)
854 {
855 struct sysparam *sysp;
856 int cnt = 0; /* dummy */
857
858 ASSERT(name != NULL);
859 ASSERT(value != NULL);
860 for (sysp = sysparam_hd; sysp != NULL; sysp = sysp->sys_next) {
|
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2017 Nexenta Systems, Inc.
26 * Copyright 2019 Joyent, Inc.
27 */
28
29 #include <sys/types.h>
30 #include <sys/inttypes.h>
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/user.h>
34 #include <sys/disp.h>
35 #include <sys/conf.h>
36 #include <sys/bootconf.h>
37 #include <sys/sysconf.h>
38 #include <sys/sunddi.h>
39 #include <sys/esunddi.h>
40 #include <sys/ddi_impldefs.h>
41 #include <sys/kmem.h>
42 #include <sys/vmem.h>
43 #include <sys/fs/ufs_fsdir.h>
44 #include <sys/hwconf.h>
45 #include <sys/modctl.h>
46 #include <sys/cmn_err.h>
51 #include <sys/autoconf.h>
52 #include <sys/callb.h>
53 #include <sys/sysmacros.h>
54 #include <sys/dacf.h>
55 #include <vm/seg_kmem.h>
56
57 struct hwc_class *hcl_head; /* head of list of classes */
58 static kmutex_t hcl_lock; /* for accessing list of classes */
59
60 #define DAFILE "/etc/driver_aliases"
61 #define CLASSFILE "/etc/driver_classes"
62 #define DACFFILE "/etc/dacf.conf"
63
64 static char class_file[] = CLASSFILE;
65 static char dafile[] = DAFILE;
66 static char dacffile[] = DACFFILE;
67
68 char *self_assembly = "/etc/system.d/.self-assembly";
69 char *systemfile = "/etc/system"; /* name of ascii system file */
70
71 #define BUILDVERSION_LEN (4096)
72
73 char *versionfile = "/etc/versions/build";
74 char buildversion[BUILDVERSION_LEN];
75
76 static struct sysparam *sysparam_hd; /* head of parameters list */
77 static struct sysparam *sysparam_tl; /* tail of parameters list */
78 static vmem_t *mod_sysfile_arena; /* parser memory */
79
80 char obp_bootpath[BO_MAXOBJNAME]; /* bootpath from obp */
81
82 #if defined(_PSM_MODULES)
83
84 struct psm_mach {
85 struct psm_mach *m_next;
86 char *m_machname;
87 };
88
89 static struct psm_mach *pmach_head; /* head of list of classes */
90
91 #define MACHFILE "/etc/mach"
92 static char mach_file[] = MACHFILE;
93
94 #endif /* _PSM_MODULES */
95
800 sp->sys_next = NULL;
801 sysparam_tl->sys_next = sp;
802 sysparam_tl = sp;
803 }
804 last_tok = NAME;
805 break;
806 default:
807 kobj_file_err(CE_WARN,
808 file, tok_err, tokval);
809 kobj_find_eol(file);
810 break;
811 }
812 }
813 kobj_close_file(file);
814 }
815 }
816
817 void
818 mod_read_system_file(int ask)
819 {
820 struct _buf *file;
821
822 mod_sysfile_arena = vmem_create("mod_sysfile", NULL, 0, 8,
823 segkmem_alloc, segkmem_free, heap_arena, 0, VM_SLEEP);
824
825 if (ask)
826 mod_askparams();
827
828 /*
829 * Read the user self-assembly file first
830 * to preserve existing system settings.
831 */
832 if (self_assembly != NULL)
833 read_system_file(self_assembly);
834
835 if (systemfile != NULL)
836 read_system_file(systemfile);
837
838 /*
839 * Sanity check of /etc/system.
840 */
841 check_system_file();
842
843 param_preset();
844 (void) mod_sysctl(SYS_SET_KVAR, NULL);
845 param_check();
846
847 if (ask == 0)
848 setparams();
849
850 /*
851 * A convenient place to read in our build version string.
852 */
853
854 if ((file = kobj_open_file(versionfile)) != (struct _buf *)-1) {
855 if (kobj_read_file(file, buildversion,
856 sizeof (buildversion) - 1, 0) == -1) {
857 cmn_err(CE_WARN, "failed to read %s\n", versionfile);
858 }
859 kobj_close_file(file);
860 }
861 }
862
863 /*
864 * Search for a specific module variable assignment in /etc/system. If
865 * successful, 1 is returned and the value is stored in '*value'.
866 * Otherwise 0 is returned and '*value' isn't modified. If 'module' is
867 * NULL we look for global definitions.
868 *
869 * This is useful if the value of an assignment is needed before a
870 * module is loaded (e.g. to obtain a default privileged rctl limit).
871 */
872 int
873 mod_sysvar(const char *module, const char *name, u_longlong_t *value)
874 {
875 struct sysparam *sysp;
876 int cnt = 0; /* dummy */
877
878 ASSERT(name != NULL);
879 ASSERT(value != NULL);
880 for (sysp = sysparam_hd; sysp != NULL; sysp = sysp->sys_next) {
|