xref: /illumos-gate/usr/src/cmd/devfsadm/i386/xen_link.c (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
1 /*
2  * CDDL HEADER START
3  *
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.
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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <regex.h>
27 #include <devfsadm.h>
28 #include <stdio.h>
29 #include <strings.h>
30 #include <stdlib.h>
31 #include <limits.h>
32 #include <sys/privcmd_impl.h>
33 #include <sys/domcaps_impl.h>
34 #include <sys/balloon.h>
35 
36 /*
37  * Handle miscellaneous children of xendev
38  */
39 static int devxen(di_minor_t, di_node_t);
40 static int xdt(di_minor_t minor, di_node_t node);
41 
42 static devfsadm_create_t xen_cbt[] = {
43 	{ "xendev", DDI_PSEUDO, "xenbus",
44 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, devxen,
45 	},
46 	{ "xendev", DDI_PSEUDO, PRIVCMD_DRIVER_NAME,
47 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, devxen,
48 	},
49 	{ "xendev", DDI_PSEUDO, "evtchn",
50 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, devxen,
51 	},
52 	{ "xendev", DDI_PSEUDO, DOMCAPS_DRIVER_NAME,
53 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, devxen,
54 	},
55 	{ "xendev", DDI_PSEUDO, BALLOON_DRIVER_NAME,
56 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, devxen,
57 	},
58 	{ "pseudo", DDI_PSEUDO, "xdt",
59 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, xdt
60 	},
61 };
62 
63 DEVFSADM_CREATE_INIT_V0(xen_cbt);
64 
65 static devfsadm_remove_t xen_remove_cbt[] = {
66 	{ "xendev", "^" "xen/xenbus" "$", RM_ALWAYS | RM_PRE | RM_HOT,
67 	    ILEVEL_0, devfsadm_rm_all
68 	},
69 	{ "xendev", "^" PRIVCMD_PATHNAME "$", RM_ALWAYS | RM_PRE | RM_HOT,
70 	    ILEVEL_0, devfsadm_rm_all
71 	},
72 	{ "xendev", "^" "xen/evtchn" "$", RM_ALWAYS | RM_PRE | RM_HOT,
73 	    ILEVEL_0, devfsadm_rm_all
74 	},
75 	{ "xendev", "^" DOMCAPS_PATHNAME "$", RM_ALWAYS | RM_PRE | RM_HOT,
76 	    ILEVEL_0, devfsadm_rm_all
77 	},
78 	{ "xendev", "^" BALLOON_PATHNAME "$", RM_ALWAYS | RM_PRE | RM_HOT,
79 	    ILEVEL_0, devfsadm_rm_all
80 	},
81 };
82 
83 DEVFSADM_REMOVE_INIT_V0(xen_remove_cbt);
84 
85 /*
86  * /dev/xen/<foo>	->	/devices/xendev/<whatever>:<foo>
87  */
88 static int
devxen(di_minor_t minor,di_node_t node)89 devxen(di_minor_t minor, di_node_t node)
90 {
91 	char buf[256];
92 
93 	(void) snprintf(buf, sizeof (buf), "xen/%s", di_minor_name(minor));
94 	(void) devfsadm_mklink(buf, node, minor, 0);
95 
96 	return (DEVFSADM_CONTINUE);
97 }
98 
99 static int
xdt(di_minor_t minor,di_node_t node)100 xdt(di_minor_t minor, di_node_t node)
101 {
102 	char *mname = di_minor_name(minor);
103 	char path[MAXPATHLEN];
104 
105 	(void) snprintf(path, sizeof (path), "dtrace/provider/%s", mname);
106 	(void) devfsadm_mklink(path, node, minor, 0);
107 
108 	return (DEVFSADM_CONTINUE);
109 }
110