Imported Upstream version 3.1.0
[debian/amanda] / ndmp-src / ndma_noti_calls.c
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
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
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
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
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
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         switch (from_conn->protocol_version) {
140 #ifndef NDMOS_OPTION_NO_NDMP2
141         case NDMP2VER:
142                 switch (ltype) {
143                 default:
144                 case NDMP9_LOG_NORMAL:
145                 case NDMP9_LOG_ERROR:
146                 case NDMP9_LOG_WARNING:
147                     NDMC_WITH_NO_REPLY(ndmp2_log_log, NDMP2VER)
148                         request->entry = buf;
149                         ndma_send_to_control (sess, xa, from_conn);
150                     NDMC_ENDWITH
151                     break;
152
153                 case NDMP9_LOG_DEBUG:
154                     NDMC_WITH_NO_REPLY(ndmp2_log_debug, NDMP2VER)
155                         request->level = NDMP2_DBG_USER_INFO;
156                         request->message = buf;
157                         ndma_send_to_control (sess, xa, from_conn);
158                     NDMC_ENDWITH
159                     break;
160                 }
161             break;
162 #endif /* !NDMOS_OPTION_NO_NDMP2 */
163 #ifndef NDMOS_OPTION_NO_NDMP3
164         case NDMP3VER:
165             NDMC_WITH_NO_REPLY(ndmp3_log_message, NDMP3VER)
166                 switch (ltype) {
167                 default:
168                 case NDMP9_LOG_NORMAL:
169                         request->log_type = NDMP3_LOG_NORMAL;
170                         break;
171
172                 case NDMP9_LOG_DEBUG:
173                         request->log_type = NDMP3_LOG_DEBUG;
174                         break;
175
176                 case NDMP9_LOG_ERROR:
177                         request->log_type = NDMP3_LOG_ERROR;
178                         break;
179
180                 case NDMP9_LOG_WARNING:
181                         request->log_type = NDMP3_LOG_WARNING;
182                         break;
183                 }
184                 request->message_id = time(0);
185                 request->entry = buf;
186                 ndma_send_to_control (sess, xa, from_conn);
187             NDMC_ENDWITH
188             break;
189 #endif /* !NDMOS_OPTION_NO_NDMP3 */
190 #ifndef NDMOS_OPTION_NO_NDMP4
191         case NDMP4VER:
192             NDMC_WITH_POST(ndmp4_log_message, NDMP4VER)
193                 switch (ltype) {
194                 default:
195                 case NDMP9_LOG_NORMAL:
196                         request->log_type = NDMP4_LOG_NORMAL;
197                         break;
198
199                 case NDMP9_LOG_DEBUG:
200                         request->log_type = NDMP4_LOG_DEBUG;
201                         break;
202
203                 case NDMP9_LOG_ERROR:
204                         request->log_type = NDMP4_LOG_ERROR;
205                         break;
206
207                 case NDMP9_LOG_WARNING:
208                         request->log_type = NDMP4_LOG_WARNING;
209                         break;
210                 }
211                 request->message_id = time(0);
212                 request->entry = buf;
213                 ndma_send_to_control (sess, xa, from_conn);
214             NDMC_ENDWITH
215             break;
216 #endif /* !NDMOS_OPTION_NO_NDMP4 */
217
218         default:
219                 /* BOGUS */
220                 break;
221         }
222 }
223
224 #endif /* !NDMOS_EFFECT_NO_SERVER_AGENTS */