PadicoTM

Documentation

« back to PM2 home.
vnode_hfd.c
Go to the documentation of this file.
1/*
2 * Padico -- a High Performance Parallel and Distributed Computing Environment
3 * Copyright (c) 2002-2023 INRIA and the University of Rennes 1
4 * Alexandre DENIS <Alexandre.Denis@inria.fr>
5 * Christian PEREZ <Christian.Perez@inria.fr>
6 *
7 * The software has been registered at the Agency for the Protection of
8 * Programs (APP) under the number IDDN.FR.001.260013.000.S.P.2002.000.10000.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
30#include "VLink-internals.h"
31#include <Padico/Module.h>
32#include <Padico/SysIO.h>
33
35
36#define VLINK_SYSIO_DIRECT_SEND_THRESHOLD (4096)
37
38static int vnode_hfd_callback_reader(int fd, void*key);
39static int vnode_hfd_callback_writer(int fd, void*key);
42
43/* ********************************************************* */
44
48{
49 const int mode = flags & O_ACCMODE;
50 padico_out(50, "vnode=%p hfd=%d\n", vnode, fd);
52 vnode->hfd.fd = fd;
53 if((mode == O_RDONLY) || (mode == O_RDWR))
54 {
58 }
59 else
60 {
62 }
63 if((mode == O_WRONLY) || (mode == O_RDWR))
64 {
68 }
69 else
70 {
72 }
73}
74
76{
77 int again = 1;
78 vnode_check(vnode, hfd);
79 padico_out(50, "vnode=%p; hfd=%d; entering- activating io...\n", vnode, vnode->hfd.fd);
81 {
82 /* immediate read */
85 if(again)
86 {
87 /* re-arm polling */
91 }
92 }
94 {
98 padico_out(60, "io activated.\n");
99 if(!(vnode->rbox.read_done > 0))
100 {
101 int read_done = vnode->rbox.read_done ;
103 padico_out(60, "synchronizing.\n");
106 {
108 if(vnode->rbox.read_done == read_done)
110 }
111 else
113 padico_out(60, "synchronized.\n");
114 }
115 }
116 padico_out(60, "vnode=%p; hfd=%d; exit rlen=%ld\n", vnode, vnode->hfd.fd, puk_slong(vnode->rbox.read_done));
117}
118
120{
121 int again = 1;
122 vnode_check(vnode, hfd);
123 if(vnode->status.writable ||
125 {
126 /* try immediate write */
129 if(again)
130 {
131 /* re-arm polling */
135 }
136 }
138 {
142 if(!(vnode->wbox.write_done > 0))
143 {
148 }
149 }
150}
151
153{
154 int rc = -1;
155 padico_out(40,"vnode=%p hfd=%d\n", vnode, vnode->hfd.fd);
156 vnode->status.opened = 0;
157 if(vnode->content.hfd)
158 {
159 const padico_io_t io_read = vnode->hfd.io_read;
161 const padico_io_t io_write = vnode->hfd.io_write;
163 const int fd = vnode->hfd.fd;
164 vnode->hfd.fd = -1;
165 vnode->content.hfd = 0;
167 if(io_read)
168 {
169 padico_io_deactivate(io_read);
170 padico_io_unregister(io_read);
171 }
172 if(io_write)
173 {
174 padico_io_deactivate(io_write);
175 padico_io_unregister(io_write);
176 }
177 rc = PUK_ABI_FSYS_WRAP(close)(fd);
178 }
179 return rc;
180}
181
182
184{
185 padico_out(10, "hfd=%d; cmd=%d; arg=%p\n", vnode->hfd.fd, cmd, arg);
186 int rc = PUK_ABI_FSYS_WRAP(fcntl)(vnode->hfd.fd, cmd, arg);
188 padico_out(10, "hfd=%d; rc=%d; errno=%d\n", vnode->hfd.fd, rc, err);
190 return rc;
191}
192
193
194
195/* ********************************************************* */
196
205{
206 int again = 0;
207 assert(vnode->rbox.read_done >= 0);
208 const size_t todo = vnode->rbox.read_posted - vnode->rbox.read_done;
209 padico_out(50, "vnode=%p fd=%d read_done=%ld reading %ld bytes\n",
211 puk_ulong(todo));
214 int err = padico_sysio_errno();
215 /* update 'status.readable' & 'again' */
216 if(rc > 0)
217 {
218 /* received ok */
220 padico_out(50, "::read() received %d bytes (read_done=%ld/%ld)\n",
222 vnode->status.readable = 0;
224 /*
225 if(vnode->rbox.read_done < vnode->rbox.read_posted)
226 again = 1;
227 else
228 again = 0;
229 */
230 again = 1;
231 }
232 else if(rc == 0)
233 {
234 /* unexpected EOF detected */
235 padico_out(40, "::read()- rc = 0- detected EOF\n");
237 if(vnode->content.remote)
238 {
239 vnode->remote.can_recv = 0;
240 }
241 vnode->status.readable = 0;
243 again = 0;
244 }
245 else if(err == EINTR)
246 {
247 /* EINTR */
248 vnode->status.readable = 1;
249 again = 1;
250 }
251 else if(err == EAGAIN || err == EWOULDBLOCK)
252 {
253 /* EAGAIN */
254 padico_warning("read()- hfd not ready while marked 'readable'\n");
255 vnode->status.readable = 0;
256 again = 1;
257 }
258 else
259 {
260 /* error */
261 padico_warning("read()- hfd=%d rc=%d errno=%d (%s)\n",
262 vnode->hfd.fd, rc, err, strerror(err));
264 vnode->status.readable = 0;
265 again = 0;
266 }
267 padico_out(50, "vnode=%p fd=%d read_done=%ld exiting again=%d rc=%d\n",
269 return again;
270}
271
273{
274 int again = 0;
275 padico_out(40, "fd=%d writing %ld bytes (done=%ld; posted=%ld)\n",
276 vnode->hfd.fd,
282 int err = padico_sysio_errno();
283 if(rc > 0)
284 {
285 /* write ok */
286 padico_out(50, "::write() written %d bytes (done=%ld; posted=%ld)\n",
288 vnode->status.writable = 0;
290 again = 1;
292 }
293 else if(rc == -1 && err == EINTR)
294 {
295 /* EINTR */
296 again = 1;
297 vnode->status.writable = 1;
298 }
299 else if(rc == -1 && err == EAGAIN)
300 {
301 /* EAGAIN */
302 padico_warning("write()- hfd not ready while marked 'writable'\n");
303 again = 1;
304 vnode->status.writable = 0;
305 }
306 else if(rc == -1 && (err == EPIPE || err == ECONNRESET || err == EIO))
307 {
308 /* fatal errors: EPIPE, ECONNRESET, EIO */
309 again = 0;
310 vnode->remote.can_send = 0;
312 }
313 else
314 {
315 /* error */
316 padico_warning("write() unexpected error- rc=%d errno=%d (%s)\n",
317 rc, err, strerror(err));
318 again = 0;
320 }
321 return again;
322}
323
324static int vnode_hfd_callback_reader(int fd, void*key)
325{
326 int again = 0;
328 padico_out(20, "vnode=%p fd=%d entering\n", vnode, fd);
330 if(!vnode->content.hfd)
331 {
332 /* hfd is being closed */
333 again = 0;
334 }
335 else
336 {
337 vnode_check(vnode, hfd);
338 padico_out(40, "vnode=%p locked- hfd=%d (%d)\n", vnode, fd, vnode->hfd.fd);
339 assert(fd == vnode->hfd.fd);
341 {
343 }
344 else
345 {
346 padico_out(20, "no rbox -- fd=%d set status.readable and signaling observer\n", fd);
347 vnode->status.readable = 1;
349 again = 0; /* XXX */
350 }
351 /* check whether we are in a permitted state */
352 assert(again || /* operation in progress: callback re-posted */
353 vnode->status.end_of_file || /* we reached EOF */
354 vnode_get_error(vnode) != 0 || /* there is an error with the vnode */
355 (!vnode->content.rbox && vnode->status.readable ) || /* some data is buffered */
356 (vnode->content.rbox && (vnode->rbox.read_done == vnode->rbox.read_posted)) /* receive completed */
357 );
358 }
360 return again;
361}
362
363static int vnode_hfd_callback_writer(int fd, void*key)
364{
365 int again = 0;
367 padico_out(20, "vnode=%p fd=%d entering\n", vnode, fd);
369 if(!vnode->content.hfd)
370 {
371 /* hfd is being closed */
372 again = 0;
373 }
374 else
375 {
376 vnode_check(vnode, hfd);
378 {
380 }
381 else
382 {
383 padico_out(20, "no wbox -- fd=%d set status.writable and signaling observer\n", fd);
384 vnode->status.writable = 1;
386 again = 0;
387 }
388 /* check whether we are in a permitted state */
389 assert(again || /* operation in progress: re-post callback */
390 vnode->status.writable || /* ready to write */
391 !vnode->remote.can_send || /* link is shutdown */
392 vnode_get_error(vnode) != 0 || /* there is an error with the vnode */
393 (vnode->content.wbox && (vnode->wbox.write_done == vnode->wbox.write_posted)) /* write completed */
394 );
395 }
397 padico_out(20, "exit -- fd=%d; again=%d\n", fd, again);
398 return again;
399}
assert(slab_size > 0)
const const struct ns_rule_bucket_s * key
return NULL
Definition Shm.h:88
static int done
Definition console-mod.c:49
enum @14::@15::@16 mode
static int fd
Definition datacheck.c:32
void * arg
Definition PadicoTM.h:167
#define PUK_ABI_FSYS_WRAP(SYM)
Definition PadicoTM.h:88
padico_rc_t rc
Definition PadicoTM.h:146
#define __puk_abi_wrap__errno
Definition PadicoTM.h:101
#define PADICO_IO_EVENT_READ
the fildes is readable
Definition SysIO.h:62
int padico_sysio_errno(void)
Definition sysio.c:575
ssize_t padico_sysio_write(int fildes, const void *buf, ssize_t nbyte)
Definition sysio.c:699
int padico_sysio_refresh(padico_sysio_t io)
Waits until at least one polling/callback cycle has been performed on the I/O handle.
Definition sysio.c:262
void padico_io_activate(padico_sysio_t io)
Activates the I/O handle - when not activated, the callback is not triggered.
Definition sysio.c:278
void padico_io_unregister(padico_sysio_t io)
Unregister the I/O handle.
Definition sysio.c:298
padico_sysio_t padico_io_register(int fd, unsigned int what, padico_sysio_callback_t callback, void *key)
Registers a file descriptor for polling.
Definition sysio.c:205
ssize_t padico_sysio_read(int fildes, void *buf, ssize_t nbyte)
Definition sysio.c:620
#define PADICO_IO_EVENT_WRITE
the fildes is writable
Definition SysIO.h:63
#define padico_io_t
for backwards compatibility with legacy codes
Definition SysIO.h:53
void padico_io_deactivate(padico_sysio_t io)
Deactivate the I/O handle - should be used for temporarly deactivate callback trigger.
Definition sysio.c:288
virtual node descriptor, common to any file type
Definition VLink-API.h:383
struct vobs_attr_wbox_s wbox
Definition VLink-API.h:395
struct vobs_attr_remote_s remote
Definition VLink-API.h:399
struct padico_vnode_content_t content
Definition VLink-API.h:392
struct vnode_hfd_s hfd
Definition VLink-API.h:402
struct vobs_attr_rbox_s rbox
Definition VLink-API.h:394
volatile struct vobs_attr_status_s status
Definition VLink-API.h:393
int fd
associated file descriptor
Definition VLink-API.h:354
padico_sysio_t io_write
Definition VLink-API.h:356
padico_sysio_t io_read
Definition VLink-API.h:355
ssize_t read_posted
Definition VLink-API.h:243
unsigned end_of_file
we reached end-of-file
Definition VLink-API.h:159
unsigned writable
immediate 'write' will not block
Definition VLink-API.h:156
unsigned readable
immediate 'read' will not block
Definition VLink-API.h:155
unsigned opened
this vnode is currently opened
Definition VLink-API.h:157
ssize_t write_done
Definition VLink-API.h:257
ssize_t write_posted
Definition VLink-API.h:256
void * write_buffer
Definition VLink-API.h:258
struct vlink_statistics_s vlink_stat
Definition vio-stat.c:45
static int vlink_sysio_writer_worker(padico_vnode_t vnode)
Definition vnode_hfd.c:272
static int vnode_hfd_callback_writer(int fd, void *key)
Definition vnode_hfd.c:363
#define VLINK_SYSIO_DIRECT_SEND_THRESHOLD
Definition vnode_hfd.c:36
int vnode_hfd_close(padico_vnode_t vnode)
Definition vnode_hfd.c:152
static int vlink_sysio_reader_worker(padico_vnode_t vnode)
The function which reads data.
Definition vnode_hfd.c:204
static int vnode_hfd_callback_reader(int fd, void *key)
Definition vnode_hfd.c:324
int vnode_hfd_fcntl(padico_vnode_t vnode, int cmd, void *arg)
Definition vnode_hfd.c:183
void vnode_hfd_write_post(padico_vnode_t vnode)
Definition vnode_hfd.c:119
void vnode_hfd_read_post(padico_vnode_t vnode)
Definition vnode_hfd.c:75
void vnode_hfd_create(padico_vnode_t vnode, int fd, int flags)
flags: O_RDONLY | O_WRONLY | O_RDWR
Definition vnode_hfd.c:47