1 /*
2  * Copyright (c) 1998,1999,2000
3  *	Traakan, Inc., Los Altos, CA
4  *	All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice unmodified, this list of conditions, and the following
11  *    disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 /*
30  * Project:  NDMJOB
31  * Ident:    $Id: $
32  *
33  * Description:
34  *
35  */
36 
37 
38 #include "ndmagents.h"
39 
40 
41 #ifndef NDMOS_OPTION_NO_DATA_AGENT
42 
43 
44 /*
45  * DATA Agent originated calls
46  ****************************************************************
47  */
48 
49 int
ndma_notify_data_halted(struct ndm_session * sess)50 ndma_notify_data_halted (struct ndm_session *sess)
51 {
52 	struct ndmconn *	conn = sess->plumb.control;
53 	struct ndm_data_agent *	da = &sess->data_acb;
54 
55 	assert (da->data_state.state == NDMP9_DATA_STATE_HALTED);
56 	assert (da->data_state.halt_reason != NDMP9_DATA_HALT_NA);
57 
58 	NDMC_WITH_NO_REPLY(ndmp9_notify_data_halted, NDMP9VER)
59 		request->reason = da->data_state.halt_reason;
60 		ndma_send_to_control (sess, xa, sess->plumb.data);
61 	NDMC_ENDWITH
62 
63 	return 0;
64 }
65 
66 int
ndma_notify_data_read(struct ndm_session * sess,unsigned long long offset,unsigned long long length)67 ndma_notify_data_read (struct ndm_session *sess,
68   unsigned long long offset, unsigned long long length)
69 {
70 	struct ndmconn *	conn = sess->plumb.control;
71 
72 	NDMC_WITH_NO_REPLY(ndmp9_notify_data_read, NDMP9VER)
73 		request->offset = offset;
74 		request->length = length;
75 		ndma_send_to_control (sess, xa, sess->plumb.data);
76 	NDMC_ENDWITH
77 
78 	return 0;
79 }
80 
81 #endif /* !NDMOS_OPTION_NO_DATA_AGENT */
82 
83 
84 #ifndef NDMOS_OPTION_NO_TAPE_AGENT
85 
86 int
ndma_notify_mover_halted(struct ndm_session * sess)87 ndma_notify_mover_halted (struct ndm_session *sess)
88 {
89 	struct ndmconn *	conn = sess->plumb.control;
90 	struct ndm_tape_agent *	ta = &sess->tape_acb;
91 
92 	assert (ta->mover_state.state == NDMP9_MOVER_STATE_HALTED);
93 	assert (ta->mover_state.halt_reason != NDMP9_MOVER_HALT_NA);
94 
95 	NDMC_WITH_NO_REPLY(ndmp9_notify_mover_halted, NDMP9VER)
96 		request->reason = ta->mover_state.halt_reason;
97 		ndma_send_to_control (sess, xa, sess->plumb.tape);
98 	NDMC_ENDWITH
99 
100 	return 0;
101 }
102 
103 int
ndma_notify_mover_paused(struct ndm_session * sess)104 ndma_notify_mover_paused (struct ndm_session *sess)
105 {
106 	struct ndmconn *	conn = sess->plumb.control;
107 	struct ndm_tape_agent *	ta = &sess->tape_acb;
108 
109 	assert (ta->mover_state.state == NDMP9_MOVER_STATE_PAUSED);
110 	assert (ta->mover_state.pause_reason != NDMP9_MOVER_PAUSE_NA);
111 
112 	NDMC_WITH_NO_REPLY(ndmp9_notify_mover_paused, NDMP9VER)
113 		request->reason = ta->mover_state.pause_reason;
114 		request->seek_position = ta->mover_want_pos;
115 		ndma_send_to_control (sess, xa, sess->plumb.tape);
116 	NDMC_ENDWITH
117 
118 	return 0;
119 }
120 
121 #endif /* !NDMOS_OPTION_NO_TAPE_AGENT */
122 
123 
124 #ifndef NDMOS_EFFECT_NO_SERVER_AGENTS
125 
126 void
ndma_send_logmsg(struct ndm_session * sess,ndmp9_log_type ltype,struct ndmconn * from_conn,char * fmt,...)127 ndma_send_logmsg (struct ndm_session *sess, ndmp9_log_type ltype,
128   struct ndmconn *from_conn,
129   char *fmt, ...)
130 {
131 	struct ndmconn *	conn = from_conn;
132 	char			buf[4096];
133 	va_list			ap;
134 
135 	va_start (ap, fmt);
136 	vsnprintf (buf, sizeof(buf), fmt, ap);
137 	va_end (ap);
138 
139 	if (!from_conn) return;
140 
141 	switch (from_conn->protocol_version) {
142 #ifndef NDMOS_OPTION_NO_NDMP2
143 	case NDMP2VER:
144 		switch (ltype) {
145 		default:
146 		case NDMP9_LOG_NORMAL:
147 		case NDMP9_LOG_ERROR:
148 		case NDMP9_LOG_WARNING:
149 		    NDMC_WITH_NO_REPLY(ndmp2_log_log, NDMP2VER)
150 			request->entry = buf;
151 			ndma_send_to_control (sess, xa, from_conn);
152 		    NDMC_ENDWITH
153 		    break;
154 
155 		case NDMP9_LOG_DEBUG:
156 		    NDMC_WITH_NO_REPLY(ndmp2_log_debug, NDMP2VER)
157 			request->level = NDMP2_DBG_USER_INFO;
158 			request->message = buf;
159 			ndma_send_to_control (sess, xa, from_conn);
160 		    NDMC_ENDWITH
161 		    break;
162 		}
163 	    break;
164 #endif /* !NDMOS_OPTION_NO_NDMP2 */
165 #ifndef NDMOS_OPTION_NO_NDMP3
166 	case NDMP3VER:
167 	    NDMC_WITH_NO_REPLY(ndmp3_log_message, NDMP3VER)
168 		switch (ltype) {
169 		default:
170 		case NDMP9_LOG_NORMAL:
171 			request->log_type = NDMP3_LOG_NORMAL;
172 			break;
173 
174 		case NDMP9_LOG_DEBUG:
175 			request->log_type = NDMP3_LOG_DEBUG;
176 			break;
177 
178 		case NDMP9_LOG_ERROR:
179 			request->log_type = NDMP3_LOG_ERROR;
180 			break;
181 
182 		case NDMP9_LOG_WARNING:
183 			request->log_type = NDMP3_LOG_WARNING;
184 			break;
185 		}
186 		request->message_id = time(0);
187 		request->entry = buf;
188 		ndma_send_to_control (sess, xa, from_conn);
189 	    NDMC_ENDWITH
190 	    break;
191 #endif /* !NDMOS_OPTION_NO_NDMP3 */
192 #ifndef NDMOS_OPTION_NO_NDMP4
193 	case NDMP4VER:
194 	    NDMC_WITH_POST(ndmp4_log_message, NDMP4VER)
195 		switch (ltype) {
196 		default:
197 		case NDMP9_LOG_NORMAL:
198 			request->log_type = NDMP4_LOG_NORMAL;
199 			break;
200 
201 		case NDMP9_LOG_DEBUG:
202 			request->log_type = NDMP4_LOG_DEBUG;
203 			break;
204 
205 		case NDMP9_LOG_ERROR:
206 			request->log_type = NDMP4_LOG_ERROR;
207 			break;
208 
209 		case NDMP9_LOG_WARNING:
210 			request->log_type = NDMP4_LOG_WARNING;
211 			break;
212 		}
213 		request->message_id = time(0);
214 		request->entry = buf;
215 		ndma_send_to_control (sess, xa, from_conn);
216 	    NDMC_ENDWITH
217 	    break;
218 #endif /* !NDMOS_OPTION_NO_NDMP4 */
219 
220 	default:
221 		/* BOGUS */
222 		break;
223 	}
224 }
225 
226 #endif /* !NDMOS_EFFECT_NO_SERVER_AGENTS */
227