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