xref: /titanic_41/usr/src/cmd/vscan/vscand/vs_door.c (revision bfc848c632c9eacb2a640246d96e198f1b185c03)
1911106dfSjm199354 /*
2911106dfSjm199354  * CDDL HEADER START
3911106dfSjm199354  *
4911106dfSjm199354  * The contents of this file are subject to the terms of the
5911106dfSjm199354  * Common Development and Distribution License (the "License").
6911106dfSjm199354  * You may not use this file except in compliance with the License.
7911106dfSjm199354  *
8911106dfSjm199354  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9911106dfSjm199354  * or http://www.opensolaris.org/os/licensing.
10911106dfSjm199354  * See the License for the specific language governing permissions
11911106dfSjm199354  * and limitations under the License.
12911106dfSjm199354  *
13911106dfSjm199354  * When distributing Covered Code, include this CDDL HEADER in each
14911106dfSjm199354  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15911106dfSjm199354  * If applicable, add the following below this CDDL HEADER, with the
16911106dfSjm199354  * fields enclosed by brackets "[]" replaced with your own identifying
17911106dfSjm199354  * information: Portions Copyright [yyyy] [name of copyright owner]
18911106dfSjm199354  *
19911106dfSjm199354  * CDDL HEADER END
20911106dfSjm199354  */
21911106dfSjm199354 /*
2253c11029Sjm199354  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23911106dfSjm199354  * Use is subject to license terms.
24911106dfSjm199354  */
25911106dfSjm199354 
26911106dfSjm199354 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27911106dfSjm199354 
28911106dfSjm199354 
29911106dfSjm199354 /*
30911106dfSjm199354  * vscand door server
31911106dfSjm199354  */
32911106dfSjm199354 
33911106dfSjm199354 #include <door.h>
34911106dfSjm199354 #include <errno.h>
35911106dfSjm199354 #include <syslog.h>
36911106dfSjm199354 #include <unistd.h>
37911106dfSjm199354 #include <varargs.h>
38911106dfSjm199354 #include <stdio.h>
39911106dfSjm199354 #include <stdlib.h>
40911106dfSjm199354 #include <string.h>
41911106dfSjm199354 #include <synch.h>
42911106dfSjm199354 #include <fcntl.h>
43911106dfSjm199354 #include <sys/types.h>
44911106dfSjm199354 #include <sys/stat.h>
45911106dfSjm199354 #include <sys/param.h>
46911106dfSjm199354 #include <pthread.h>
47911106dfSjm199354 #include "vs_incl.h"
48911106dfSjm199354 
49911106dfSjm199354 #define	VS_DOOR_VERSION	1
50911106dfSjm199354 static int vs_door_cookie;
51911106dfSjm199354 
52911106dfSjm199354 /* function prototype */
53911106dfSjm199354 static void vs_door_scan_req(void *, char *, size_t, door_desc_t *, uint_t);
54911106dfSjm199354 
55911106dfSjm199354 /* local data */
56911106dfSjm199354 static int vs_door_fd = -1;
57911106dfSjm199354 static pthread_mutex_t vs_door_mutex = PTHREAD_MUTEX_INITIALIZER;
58911106dfSjm199354 
59911106dfSjm199354 
60911106dfSjm199354 /*
61911106dfSjm199354  * vs_door_init
62911106dfSjm199354  *
63911106dfSjm199354  * Start the vscand door service.
64911106dfSjm199354  * Returns 0 on success. Otherwise, -1.
65911106dfSjm199354  */
66911106dfSjm199354 int
vs_door_init(void)67911106dfSjm199354 vs_door_init(void)
68911106dfSjm199354 {
69911106dfSjm199354 	(void) pthread_mutex_lock(&vs_door_mutex);
70911106dfSjm199354 
71911106dfSjm199354 	if ((vs_door_fd = door_create(vs_door_scan_req,
72911106dfSjm199354 	    &vs_door_cookie, (DOOR_UNREF | DOOR_REFUSE_DESC))) < 0) {
73911106dfSjm199354 		syslog(LOG_ERR, "vscand: door create%s", strerror(errno));
74911106dfSjm199354 		vs_door_fd = -1;
75911106dfSjm199354 	}
76911106dfSjm199354 
77911106dfSjm199354 	(void) pthread_mutex_unlock(&vs_door_mutex);
78911106dfSjm199354 	return (vs_door_fd);
79911106dfSjm199354 }
80911106dfSjm199354 
81911106dfSjm199354 
82911106dfSjm199354 /*
83911106dfSjm199354  * vscan_door_fini
84911106dfSjm199354  *
85911106dfSjm199354  * Stop the vscand door service.
86911106dfSjm199354  */
87911106dfSjm199354 void
vs_door_fini(void)88911106dfSjm199354 vs_door_fini(void)
89911106dfSjm199354 {
90911106dfSjm199354 	(void) pthread_mutex_lock(&vs_door_mutex);
91911106dfSjm199354 
92911106dfSjm199354 	if (vs_door_fd >= 0) {
93911106dfSjm199354 		if (door_revoke(vs_door_fd) < 0)
94911106dfSjm199354 			syslog(LOG_ERR, "vscand: door revoke %s",
95911106dfSjm199354 			    strerror(errno));
96911106dfSjm199354 	}
97911106dfSjm199354 
98911106dfSjm199354 	vs_door_fd = -1;
99911106dfSjm199354 
100911106dfSjm199354 	(void) pthread_mutex_unlock(&vs_door_mutex);
101911106dfSjm199354 }
102911106dfSjm199354 
103911106dfSjm199354 
104911106dfSjm199354 /*
105911106dfSjm199354  * vs_door_scan_req
106911106dfSjm199354  *
107911106dfSjm199354  * Invoke the vscand door service.
108911106dfSjm199354  */
109911106dfSjm199354 /* ARGSUSED */
110911106dfSjm199354 static void
vs_door_scan_req(void * cookie,char * ptr,size_t size,door_desc_t * dp,uint_t n_desc)111911106dfSjm199354 vs_door_scan_req(void *cookie, char *ptr, size_t size, door_desc_t *dp,
112911106dfSjm199354     uint_t n_desc)
113911106dfSjm199354 {
11453c11029Sjm199354 	vs_scan_req_t *scan_req;
115*bfc848c6Sjm199354 	uint32_t result = VS_STATUS_ERROR;
116911106dfSjm199354 
117*bfc848c6Sjm199354 	if (ptr != NULL) {
11853c11029Sjm199354 		/* LINTED E_BAD_PTR_CAST_ALIGN - to be fixed with encoding */
11953c11029Sjm199354 		scan_req = (vs_scan_req_t *)ptr;
120*bfc848c6Sjm199354 		result = vs_svc_queue_scan_req(scan_req);
12153c11029Sjm199354 	}
122911106dfSjm199354 
123*bfc848c6Sjm199354 	(void) door_return((char *)&result, sizeof (uint32_t), NULL, 0);
124911106dfSjm199354 }
125