xref: /titanic_44/usr/src/cmd/vscan/vscand/vs_door.c (revision 49b225e1cfa7bbf7738d4df0a03f18e3283426eb)
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 
29 /*
30  * vscand door server
31  */
32 
33 #include <door.h>
34 #include <errno.h>
35 #include <syslog.h>
36 #include <unistd.h>
37 #include <varargs.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <synch.h>
42 #include <fcntl.h>
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <sys/param.h>
46 #include <pthread.h>
47 #include "vs_incl.h"
48 
49 #define	VS_DOOR_VERSION	1
50 static int vs_door_cookie;
51 
52 /* function prototype */
53 static void vs_door_scan_req(void *, char *, size_t, door_desc_t *, uint_t);
54 
55 /* local data */
56 static int vs_door_fd = -1;
57 static pthread_mutex_t vs_door_mutex = PTHREAD_MUTEX_INITIALIZER;
58 
59 
60 /*
61  * vs_door_init
62  *
63  * Start the vscand door service.
64  * Returns 0 on success. Otherwise, -1.
65  */
66 int
67 vs_door_init(void)
68 {
69 	(void) pthread_mutex_lock(&vs_door_mutex);
70 
71 	if ((vs_door_fd = door_create(vs_door_scan_req,
72 	    &vs_door_cookie, (DOOR_UNREF | DOOR_REFUSE_DESC))) < 0) {
73 		syslog(LOG_ERR, "vscand: door create%s", strerror(errno));
74 		vs_door_fd = -1;
75 	}
76 
77 	(void) pthread_mutex_unlock(&vs_door_mutex);
78 	return (vs_door_fd);
79 }
80 
81 
82 /*
83  * vscan_door_fini
84  *
85  * Stop the vscand door service.
86  */
87 void
88 vs_door_fini(void)
89 {
90 	(void) pthread_mutex_lock(&vs_door_mutex);
91 
92 	if (vs_door_fd >= 0) {
93 		if (door_revoke(vs_door_fd) < 0)
94 			syslog(LOG_ERR, "vscand: door revoke %s",
95 			    strerror(errno));
96 	}
97 
98 	vs_door_fd = -1;
99 
100 	(void) pthread_mutex_unlock(&vs_door_mutex);
101 }
102 
103 
104 /*
105  * vs_door_scan_req
106  *
107  * Invoke the vscand door service.
108  */
109 /* ARGSUSED */
110 static void
111 vs_door_scan_req(void *cookie, char *ptr, size_t size, door_desc_t *dp,
112     uint_t n_desc)
113 {
114 	vs_scan_req_t *scan_req;
115 	uint32_t result = VS_STATUS_ERROR;
116 
117 	if (ptr != NULL) {
118 		/* LINTED E_BAD_PTR_CAST_ALIGN - to be fixed with encoding */
119 		scan_req = (vs_scan_req_t *)ptr;
120 		result = vs_svc_queue_scan_req(scan_req);
121 	}
122 
123 	(void) door_return((char *)&result, sizeof (uint32_t), NULL, 0);
124 }
125