File: filed.c

package info (click to toggle)
lam 7.1.4-8
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 56,404 kB
  • sloc: ansic: 156,541; sh: 9,991; cpp: 7,699; makefile: 5,621; perl: 488; fortran: 260; asm: 83
file content (248 lines) | stat: -rw-r--r-- 5,899 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
 * Copyright (c) 2001-2003 The Trustees of Indiana University.  
 *                         All rights reserved.
 * Copyright (c) 1998-2001 University of Notre Dame. 
 *                         All rights reserved.
 * Copyright (c) 1994-1998 The Ohio State University.  
 *                         All rights reserved.
 * 
 * This file is part of the LAM/MPI software package.  For license
 * information, see the LICENSE file in the top level directory of the
 * LAM/MPI source distribution.
 * 
 * $HEADER$
 *
 *	$Id: filed.c,v 6.7 2003/06/30 05:19:30 brbarret Exp $
 * 
 *	Function:	- filed mainline 
 *			- remote daemon
 *			- a leaner, meaner fighting machine
 *			- You, too, can maintain this program.
 *
 *			- Filed is organized into four parts:
 *			  1) filed - the request/reply mainline
 *			  2) fq* - the guts of the requests
 *			  3) f* - data structure modules
 *			  4) fface - the native file interface
 *
 *			- Filed provides the standard Unix I/O
 *			  operations as a remote service to Trollius
 *			  clients.  Additional requests, specific to
 *			  Trollius, control and monitor filed functions.
 *
 *			- There are actually three types of file descriptors
 *			  in the filed world.  First, there is the user file
 *			  descriptor, ufd, which resides wholly in the client
 *			  and has the look and feel of a Unix file descriptor.
 *			  The ufd has a field which contains the Trollius
 *			  file descriptor handle.  It is passed to filed
 *			  from the client, so that filed can identify the
 *			  target Trollius file descritor, tfd.  Before an
 *			  operation is carried out on a file, the tfd must
 *			  have an associated native OS (eg, Unix) file
 *			  descriptor open, and this is referred to as the fd.
 *			  Thus, an active file has an associated open fd,
 *			  while an inactive file does not.
 *
 *			- The word handle means the identifying number of
 *			  the descriptor while the word descriptors refers
 *			  to the whole data structure associated with an open
 *			  file.
 *
 *			- Filed does not ensure that the client that called for
 *			  a file open is the same client that calls for later
 *			  operations.  Since the client does not manage the
 *			  tfd handle (he only sees the ufd), this should not
 *			  be a problem.
 */

#include <string.h>

#include <events.h>
#include "filed.h"
#include <freq.h>
#include <net.h>
#include <portable.h>
#include <preq.h>
#include <priority.h>
#include <terror.h>
#include <typical.h>


/*
 * external functions
 */
extern void		fqopen();
extern void		fqclose();
extern void		fqread();
extern void		fqwrite();
extern void		fqlseek();
extern void		fqstate();
extern void		fqchdir();
extern void		fqgetwd();
extern void		fqrmfd();
extern void		fqaccess();
extern void		fqstat();
extern void		fqfstat();
extern void		fqtrunc();
extern void		fqftrunc();
extern void		fqdup();
extern void		fqmkdir();
extern void		fqsystem();
extern void		fqrename(struct freq* fq);
extern void		fqrmdir();
extern void		fqunlink();
extern void		fqincr();
extern void		fqpathfind();
extern void		fqf77read();
extern void		fqf77back();
extern void		fqopenfd();
extern void		fdstdio();	/* set up 0, 1 and 2 */
extern int		fmyinit();	/* machine dependent initialization */


/*
 * local variables
 */
static struct nmsg	incoming;	/* incoming filed request */

static void		(*(fqfunc[FQMAX]))() = {
			fqopen,
			fqclose,
			fqread,
			fqwrite,
			fqlseek,
			fqstate,
			fqrmfd,
			fqincr,
			fqaccess,
			fqmkdir,
			fqunlink,
			fqsystem,
			fqchdir,
			fqrmdir,
			fqgetwd,
			fqstat,
			fqfstat,
			fqdup,
			fqtrunc,
			fqftrunc,
			fqopenfd,
			fqpathfind,
			fqrename,
			fqf77read,
			fqf77back,
			};
/*
 * global variables
 */
char			fbuf[MAXNMSGLEN];


/*
 * global functions
 */
void			(*(f_init()))();
void			(*(filed()))();


/*
 *	f_init
 *
 *	Function:	- filed initialization
 */
void 
(*(f_init()))()
{
        memset((void*) fbuf, -1, MAXNMSGLEN);
	if (fmyinit()) lampanic("filed (fmyinit)");
/*
 * Attach to kernel.
 */
	if (lpattach("filed")) lampanic("filed (lpattach)");
/*
 * Set up standard I/O descriptors.
 */
	fdstdio();
/*
 * Receive first request.
 */
	incoming.nh_event = EVFILED;
	incoming.nh_type = 0;
	incoming.nh_flags = 0;
	incoming.nh_msg = fbuf;
	incoming.nh_length = sizeof(fbuf);

	if (nrecv(&incoming)) lampanic("filed (nrecv)");

	return((void (*)()) filed);
}

/*
 *	filed
 *
 *	Function:	- server loop
 *			- replies message & receives next request
 */
void
(*(filed()))()
{
	struct freq	*fq;		/* filed request details */

	fq = (struct freq *) incoming.nh_data;
/*
 * Process the request.
 * Individual request functions handle replies, if any.
 */
	if ((fq->fq_req < FQMAX) && (fq->fq_req >= 0)) {
		(*(fqfunc[fq->fq_req]))(fq);
	}
/*
 * Receive next request.
 */
	incoming.nh_event = EVFILED;
	incoming.nh_flags = 0;
	incoming.nh_msg = fbuf;
	incoming.nh_type = 0;
	incoming.nh_length = sizeof(fbuf);

	if (nrecv(&incoming)) lampanic("filed (nrecv)");

	return((void (*)()) filed);
}


/*
 *	fsendr
 *
 *	Function:	- sends reply back to client
 *			- copies parameters into the outgoing (reply) message
 *			  descriptor and calls nsend()
 *
 *	Accepts:	- client node
 *			- client event
 *			- reply error number (will be set as client errno)
 *			- reply return value (will be return to client caller)
 *			- length of buffer to return
 *			- message flags
 */
void
fsendr(int4 node, int4 event, int err, int4 ret, int4 length, int4 flags)
{
	struct nmsg	outgoing;	/* outgoing filed reply */
	struct freply	*fr;		/* filed reply details */

	LAM_ZERO_ME(outgoing);
	outgoing.nh_node = node;
	outgoing.nh_event = event;
	outgoing.nh_type = 0;
	outgoing.nh_flags = flags;
	outgoing.nh_length = length;
	outgoing.nh_msg = fbuf;

	fr = (struct freply *) outgoing.nh_data;
	fr->fr_errno = (int4) err;
	fr->fr_ret = ret;

	if (nsend(&outgoing)) lampanic("filed (nsend)");
}