4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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.
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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
32 #include <libnvpair.h>
33 #include <libdevinfo.h>
35 #include <sys/param.h>
38 #include <sys/systeminfo.h>
39 #include <sys/modctl.h>
40 #include <sys/fs/sdev_impl.h>
43 * Private interfaces for non-global /dev profile
47 * Allocate opaque data structure for passing profile to the kernel for
48 * the given mount point.
50 * Note that this interface returns an empty, initialized, profile.
51 * It does not return what may have been previously committed.
54 di_prof_init(const char *mountpt
, di_prof_t
*profp
)
58 if (nvlist_alloc(&nvl
, 0, 0))
61 if (nvlist_add_string(nvl
, SDEV_NVNAME_MOUNTPT
, mountpt
)) {
66 *profp
= (di_prof_t
)nvl
;
71 * Free space allocated by di_prof_init().
74 di_prof_fini(di_prof_t prof
)
76 nvlist_free((nvlist_t
*)prof
);
80 * Sends profile to the kernel.
83 di_prof_commit(di_prof_t prof
)
89 if (nvlist_pack((nvlist_t
*)prof
, &buf
, &buflen
, NV_ENCODE_NATIVE
, 0))
91 rv
= modctl(MODDEVNAME
, MODDEVNAME_PROFILE
, buf
, buflen
);
97 * Add a device or directory to profile's include list.
99 * Note that there is no arbitration between conflicting
100 * include and exclude profile entries, most recent
104 di_prof_add_dev(di_prof_t prof
, const char *dev
)
106 if (nvlist_add_string((nvlist_t
*)prof
, SDEV_NVNAME_INCLUDE
, dev
))
112 * Add a device or directory to profile's exclude list.
113 * This can effectively remove a previously committed device.
116 di_prof_add_exclude(di_prof_t prof
, const char *dev
)
118 if (nvlist_add_string((nvlist_t
*)prof
, SDEV_NVNAME_EXCLUDE
, dev
))
124 * Add a symlink to profile.
127 di_prof_add_symlink(di_prof_t prof
, const char *linkname
, const char *target
)
129 nvlist_t
*nvl
= (nvlist_t
*)prof
;
132 syml
[0] = (char *)linkname
; /* 1st entry must be the symlink */
133 syml
[1] = (char *)target
; /* 2nd entry must be the target */
134 if (nvlist_add_string_array(nvl
, SDEV_NVNAME_SYMLINK
, syml
, 2))
140 * Add a name mapping to profile.
143 di_prof_add_map(di_prof_t prof
, const char *source
, const char *target
)
145 nvlist_t
*nvl
= (nvlist_t
*)prof
;
148 map
[0] = (char *)source
; /* 1st entry must be the source */
149 map
[1] = (char *)target
; /* 2nd entry must be the target */
150 if (nvlist_add_string_array(nvl
, SDEV_NVNAME_MAP
, map
, 2))