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 #ifndef NDMOS_OPTION_NO_DATA_AGENT
41
42
43 /*
44 * Initialization and Cleanup
45 ****************************************************************
46 */
47
48 /* Initialize -- Set data structure to know value, ignore current value */
49 int
ndmda_fh_initialize(struct ndm_session * sess)50 ndmda_fh_initialize (struct ndm_session *sess)
51 {
52 struct ndm_data_agent * da = &sess->data_acb;
53 struct ndmfhheap * fhh = &da->fhh;
54
55 ndmfhh_initialize (fhh);
56
57 return 0;
58 }
59
60 /* Commission -- Get agent ready. Entire session has been initialize()d */
61 int
ndmda_fh_commission(struct ndm_session * sess)62 ndmda_fh_commission (struct ndm_session *sess)
63 {
64 struct ndm_data_agent * da = &sess->data_acb;
65 struct ndmfhheap * fhh = &da->fhh;
66
67 ndmfhh_commission (fhh, &da->fhh_buf, sizeof da->fhh_buf);
68
69 return 0;
70 }
71
72 /* Decommission -- Discard agent */
73 int
ndmda_fh_decommission(struct ndm_session * sess)74 ndmda_fh_decommission (struct ndm_session *sess)
75 {
76 return 0;
77 }
78
79 /* Belay -- Cancel partially issued activation/start */
80 int
ndmda_fh_belay(struct ndm_session * sess)81 ndmda_fh_belay (struct ndm_session *sess)
82 {
83 return 0;
84 }
85
86
87
88
89 /*
90 * Semantic actions -- called from ndmda_XXX() butype formatters
91 ****************************************************************
92 */
93
94 void
ndmda_fh_add_file(struct ndm_session * sess,ndmp9_file_stat * filestat,char * name)95 ndmda_fh_add_file (struct ndm_session *sess,
96 ndmp9_file_stat *filestat, char *name)
97 {
98 struct ndm_data_agent * da = &sess->data_acb;
99 int nlen = strlen (name) + 1;
100 ndmp9_file * file9;
101 int rc;
102
103 rc = ndmda_fh_prepare (sess, NDMP9VER, NDMP9_FH_ADD_FILE,
104 sizeof (ndmp9_file), 1, nlen);
105
106 if (rc != NDMFHH_RET_OK)
107 return;
108
109 file9 = ndmfhh_add_entry (&da->fhh);
110 file9->fstat = *filestat;
111 file9->unix_path = ndmfhh_save_item (&da->fhh, name, nlen);
112 }
113
114 void
ndmda_fh_add_dir(struct ndm_session * sess,unsigned long long dir_fileno,char * name,unsigned long long fileno)115 ndmda_fh_add_dir (struct ndm_session *sess,
116 unsigned long long dir_fileno, char *name, unsigned long long fileno)
117 {
118 struct ndm_data_agent * da = &sess->data_acb;
119 int nlen = strlen (name) + 1;
120 ndmp9_dir * dir9;
121 int rc;
122
123 rc = ndmda_fh_prepare (sess, NDMP9VER, NDMP9_FH_ADD_DIR,
124 sizeof (ndmp9_dir), 1, nlen);
125
126 if (rc != NDMFHH_RET_OK)
127 return;
128
129 dir9 = ndmfhh_add_entry (&da->fhh);
130 dir9->unix_name = ndmfhh_save_item (&da->fhh, name, nlen);
131 dir9->parent = dir_fileno;
132 dir9->node = fileno;
133 }
134
135 void
ndmda_fh_add_node(struct ndm_session * sess,ndmp9_file_stat * filestat)136 ndmda_fh_add_node (struct ndm_session *sess, ndmp9_file_stat *filestat)
137 {
138 struct ndm_data_agent * da = &sess->data_acb;
139 ndmp9_node * node9;
140 int rc;
141
142 rc = ndmda_fh_prepare (sess, NDMP9VER, NDMP9_FH_ADD_NODE,
143 sizeof (ndmp9_node), 1, 0);
144
145 if (rc != NDMFHH_RET_OK)
146 return;
147
148 node9 = ndmfhh_add_entry (&da->fhh);
149 node9->fstat = *filestat;
150 }
151
152
153
154
155 /*
156 * Helpers -- prepare/flush
157 ****************************************************************
158 */
159
160 int
ndmda_fh_prepare(struct ndm_session * sess,int vers,int msg,int entry_size,unsigned n_item,unsigned total_size_of_items)161 ndmda_fh_prepare (struct ndm_session *sess,
162 int vers, int msg, int entry_size,
163 unsigned n_item, unsigned total_size_of_items)
164 {
165 struct ndm_data_agent * da = &sess->data_acb;
166 struct ndmfhheap * fhh = &da->fhh;
167 int fhtype = (vers<<16) + msg;
168 int rc;
169
170 rc = ndmfhh_prepare (fhh, fhtype, entry_size,
171 n_item, total_size_of_items);
172
173 if (rc == NDMFHH_RET_OK)
174 return NDMFHH_RET_OK;
175
176 ndmda_fh_flush (sess);
177
178 rc = ndmfhh_prepare (fhh, fhtype, entry_size,
179 n_item, total_size_of_items);
180
181 return rc;
182 }
183
184 void
ndmda_fh_flush(struct ndm_session * sess)185 ndmda_fh_flush (struct ndm_session *sess)
186 {
187 struct ndm_data_agent * da = &sess->data_acb;
188 struct ndmfhheap * fhh = &da->fhh;
189 int rc;
190 int fhtype;
191 void * table;
192 unsigned n_entry;
193
194 rc = ndmfhh_get_table (fhh, &fhtype, &table, &n_entry);
195 if (rc == NDMFHH_RET_OK && n_entry > 0) {
196 struct ndmp_xa_buf xa;
197 struct ndmfhh_generic_table *request;
198
199 request = (void *) &xa.request.body;
200 NDMOS_MACRO_ZEROFILL (&xa);
201
202 xa.request.protocol_version = fhtype >> 16;
203 xa.request.header.message = fhtype & 0xFFFF;
204
205 request->table_len = n_entry;
206 request->table_val = table;
207
208 ndma_send_to_control (sess, &xa, sess->plumb.data);
209 }
210
211 ndmfhh_reset (fhh);
212 }
213
214 #endif /* !NDMOS_OPTION_NO_DATA_AGENT */
215