xref: /illumos-gate/usr/src/cmd/devfsadm/i386/xen_link.c (revision 843e19887f64dde75055cf8842fc4db2171eff45)
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 2007 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 
43 static devfsadm_create_t xen_cbt[] = {
44 	{ "xendev", DDI_PSEUDO, "xenbus",
45 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, devxen,
46 	},
47 	{ "xendev", DDI_PSEUDO, PRIVCMD_DRIVER_NAME,
48 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, devxen,
49 	},
50 	{ "xendev", DDI_PSEUDO, "evtchn",
51 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, devxen,
52 	},
53 	{ "xendev", DDI_PSEUDO, DOMCAPS_DRIVER_NAME,
54 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, devxen,
55 	},
56 	{ "xendev", DDI_PSEUDO, BALLOON_DRIVER_NAME,
57 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, devxen,
58 	},
59 };
60 
61 DEVFSADM_CREATE_INIT_V0(xen_cbt);
62 
63 static devfsadm_remove_t xen_remove_cbt[] = {
64 	{ "xendev", "^" "xen/xenbus" "$", RM_ALWAYS | RM_PRE | RM_HOT,
65 	    ILEVEL_0, devfsadm_rm_all
66 	},
67 	{ "xendev", "^" PRIVCMD_PATHNAME "$", RM_ALWAYS | RM_PRE | RM_HOT,
68 	    ILEVEL_0, devfsadm_rm_all
69 	},
70 	{ "xendev", "^" "xen/evtchn" "$", RM_ALWAYS | RM_PRE | RM_HOT,
71 	    ILEVEL_0, devfsadm_rm_all
72 	},
73 	{ "xendev", "^" DOMCAPS_PATHNAME "$", RM_ALWAYS | RM_PRE | RM_HOT,
74 	    ILEVEL_0, devfsadm_rm_all
75 	},
76 	{ "xendev", "^" BALLOON_PATHNAME "$", RM_ALWAYS | RM_PRE | RM_HOT,
77 	    ILEVEL_0, devfsadm_rm_all
78 	},
79 };
80 
81 DEVFSADM_REMOVE_INIT_V0(xen_remove_cbt);
82 
83 /*
84  * /dev/xen/<foo>	->	/devices/xendev/<whatever>:<foo>
85  */
86 static int
87 devxen(di_minor_t minor, di_node_t node)
88 {
89 	char buf[256];
90 
91 	(void) snprintf(buf, sizeof (buf), "xen/%s", di_minor_name(minor));
92 	(void) devfsadm_mklink(buf, node, minor, 0);
93 
94 	return (DEVFSADM_CONTINUE);
95 }
96