Whamcloud - gitweb
LU-8468 kernel: kernel update RHEL7.2 [3.10.0-327.28.2.el7]
[fs/lustre-release.git] / lustre / contrib / mpich-1.2.6-lustre.patch
1 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/ad_lustre.c mpich-1.2.6/romio/adio/ad_lustre/ad_lustre.c
2 --- mpich-1.2.6/romio/adio/ad_lustre/ad_lustre.c        1969-12-31 19:00:00.000000000 -0500
3 +++ mpich-1.2.6/romio/adio/ad_lustre/ad_lustre.c        2005-12-06 11:54:37.883130927 -0500
4 @@ -0,0 +1,37 @@
5 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
6 +/* 
7 + *   $Id: ad_lustre.c,v 1.1.1.1 2004/11/04 11:03:38 liam Exp $
8 + *
9 + *   Copyright (C) 2001 University of Chicago. 
10 + *   See COPYRIGHT notice in top-level directory.
11 + */
12 +
13 +#include "ad_lustre.h"
14 +
15 +/* adioi.h has the ADIOI_Fns_struct define */
16 +#include "adioi.h"
17 +
18 +struct ADIOI_Fns_struct ADIO_LUSTRE_operations = {
19 +    ADIOI_LUSTRE_Open, /* Open */
20 +    ADIOI_LUSTRE_ReadContig, /* ReadContig */
21 +    ADIOI_LUSTRE_WriteContig, /* WriteContig */
22 +    ADIOI_GEN_ReadStridedColl, /* ReadStridedColl */
23 +    ADIOI_GEN_WriteStridedColl, /* WriteStridedColl */
24 +    ADIOI_GEN_SeekIndividual, /* SeekIndividual */
25 +    ADIOI_LUSTRE_Fcntl, /* Fcntl */
26 +    ADIOI_LUSTRE_SetInfo, /* SetInfo */
27 +    ADIOI_GEN_ReadStrided, /* ReadStrided */
28 +    ADIOI_GEN_WriteStrided, /* WriteStrided */
29 +    ADIOI_LUSTRE_Close, /* Close */
30 +    ADIOI_LUSTRE_IreadContig, /* IreadContig */
31 +    ADIOI_LUSTRE_IwriteContig, /* IwriteContig */
32 +    ADIOI_LUSTRE_ReadDone, /* ReadDone */
33 +    ADIOI_LUSTRE_WriteDone, /* WriteDone */
34 +    ADIOI_LUSTRE_ReadComplete, /* ReadComplete */
35 +    ADIOI_LUSTRE_WriteComplete, /* WriteComplete */
36 +    ADIOI_LUSTRE_IreadStrided, /* IreadStrided */
37 +    ADIOI_LUSTRE_IwriteStrided, /* IwriteStrided */
38 +    ADIOI_GEN_Flush, /* Flush */
39 +    ADIOI_LUSTRE_Resize, /* Resize */
40 +    ADIOI_GEN_Delete, /* Delete */
41 +};
42 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_close.c mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_close.c
43 --- mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_close.c  1969-12-31 19:00:00.000000000 -0500
44 +++ mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_close.c  2005-12-06 11:54:37.895129327 -0500
45 @@ -0,0 +1,32 @@
46 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
47 +/* 
48 + *   $Id: ad_lustre_close.c,v 1.1.1.1 2004/11/04 11:03:38 liam Exp $    
49 + *
50 + *   Copyright (C) 1997 University of Chicago. 
51 + *   See COPYRIGHT notice in top-level directory.
52 + */
53 +
54 +#include "ad_lustre.h"
55 +
56 +void ADIOI_LUSTRE_Close(ADIO_File fd, int *error_code)
57 +{
58 +    int err;
59 +#if defined(MPICH2) || !defined(PRINT_ERR_MSG)
60 +    static char myname[] = "ADIOI_LUSTRE_CLOSE";
61 +#endif
62 +
63 +    err = close(fd->fd_sys);
64 +    if (err == -1) {
65 +#ifdef MPICH2
66 +       *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
67 +           "**io %s", strerror(errno));
68 +#elif defined(PRINT_ERR_MSG)
69 +                       *error_code = MPI_ERR_UNKNOWN;
70 +#else
71 +       *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
72 +                             myname, "I/O Error", "%s", strerror(errno));
73 +       ADIOI_Error(fd, *error_code, myname);       
74 +#endif
75 +    }
76 +    else *error_code = MPI_SUCCESS;
77 +}
78 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_done.c mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_done.c
79 --- mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_done.c   1969-12-31 19:00:00.000000000 -0500
80 +++ mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_done.c   2005-12-06 11:54:37.898128927 -0500
81 @@ -0,0 +1,188 @@
82 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
83 +/* 
84 + *   $Id: ad_lustre_done.c,v 1.1.1.1 2004/11/04 11:03:38 liam Exp $    
85 + *
86 + *   Copyright (C) 1997 University of Chicago. 
87 + *   See COPYRIGHT notice in top-level directory.
88 + */
89 +
90 +#include "ad_lustre.h"
91 +
92 +int ADIOI_LUSTRE_ReadDone(ADIO_Request *request, ADIO_Status *status, int *error_code)  
93 +{
94 +#ifndef NO_AIO
95 +    int done=0;
96 +#if defined(MPICH2) || !defined(PRINT_ERR_MSG)
97 +    static char myname[] = "ADIOI_LUSTRE_READDONE";
98 +#endif
99 +#ifdef AIO_SUN 
100 +    aio_result_t *result=0, *tmp;
101 +#else
102 +    int err;
103 +#endif
104 +#ifdef AIO_HANDLE_IN_AIOCB
105 +    struct aiocb *tmp1;
106 +#endif
107 +#endif
108 +
109 +    if (*request == ADIO_REQUEST_NULL) {
110 +       *error_code = MPI_SUCCESS;
111 +       return 1;
112 +    }
113 +
114 +#ifdef NO_AIO
115 +/* HP, FreeBSD, Linux */
116 +#ifdef HAVE_STATUS_SET_BYTES
117 +    MPIR_Status_set_bytes(status, (*request)->datatype, (*request)->nbytes);
118 +#endif
119 +    (*request)->fd->async_count--;
120 +    ADIOI_Free_request((ADIOI_Req_node *) (*request));
121 +    *request = ADIO_REQUEST_NULL;
122 +    *error_code = MPI_SUCCESS;
123 +    return 1;
124 +#endif    
125 +
126 +#ifdef AIO_SUN
127 +    if ((*request)->queued) {
128 +       tmp = (aio_result_t *) (*request)->handle;
129 +       if (tmp->aio_return == AIO_INPROGRESS) {
130 +           done = 0;
131 +           *error_code = MPI_SUCCESS;
132 +       }
133 +       else if (tmp->aio_return != -1) {
134 +           result = (aio_result_t *) aiowait(0); /* dequeue any one request */
135 +           done = 1;
136 +           (*request)->nbytes = tmp->aio_return;
137 +           *error_code = MPI_SUCCESS;
138 +       }
139 +       else {
140 +#ifdef MPICH2
141 +           *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
142 +               "**io %s", strerror(tmp->aio_errno));
143 +           return;
144 +#elif defined(PRINT_ERR_MSG)
145 +           *error_code = MPI_ERR_UNKNOWN;
146 +#else
147 +           *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
148 +                        myname, "I/O Error", "%s", strerror(tmp->aio_errno));
149 +           ADIOI_Error((*request)->fd, *error_code, myname);       
150 +#endif
151 +       }
152 +    } /* if ((*request)->queued) ... */
153 +    else {
154 +       /* ADIOI_Complete_Async completed this request, but request object
155 +           was not freed. */
156 +       done = 1;
157 +       *error_code = MPI_SUCCESS;
158 +    }
159 +#ifdef HAVE_STATUS_SET_BYTES
160 +    if (done && ((*request)->nbytes != -1))
161 +       MPIR_Status_set_bytes(status, (*request)->datatype, (*request)->nbytes);
162 +#endif
163 +
164 +#endif
165 +
166 +#ifdef AIO_HANDLE_IN_AIOCB
167 +/* IBM */
168 +    if ((*request)->queued) {
169 +       tmp1 = (struct aiocb *) (*request)->handle;
170 +       errno = aio_error(tmp1->aio_handle);
171 +       if (errno == EINPROG) {
172 +           done = 0;
173 +           *error_code = MPI_SUCCESS;
174 +       }
175 +       else {
176 +           err = aio_return(tmp1->aio_handle);
177 +           (*request)->nbytes = err;
178 +           errno = aio_error(tmp1->aio_handle);
179 +       
180 +           done = 1;
181 +
182 +           if (err == -1) {
183 +#ifdef MPICH2
184 +               *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
185 +                   "**io %s", strerror(errno));
186 +               return;
187 +#elif defined(PRINT_ERR_MSG)
188 +                               *error_code = MPI_ERR_UNKNOWN;
189 +#else
190 +               *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
191 +                             myname, "I/O Error", "%s", strerror(errno));
192 +               ADIOI_Error((*request)->fd, *error_code, myname);           
193 +#endif
194 +           }
195 +           else *error_code = MPI_SUCCESS;
196 +       }
197 +    } /* if ((*request)->queued) */
198 +    else {
199 +       done = 1;
200 +       *error_code = MPI_SUCCESS;
201 +    }
202 +#ifdef HAVE_STATUS_SET_BYTES
203 +    if (done && ((*request)->nbytes != -1))
204 +       MPIR_Status_set_bytes(status, (*request)->datatype, (*request)->nbytes);
205 +#endif
206 +
207 +#elif (!defined(NO_AIO) && !defined(AIO_SUN))
208 +/* DEC, SGI IRIX 5 and 6 */
209 +    if ((*request)->queued) {
210 +       errno = aio_error((const struct aiocb *) (*request)->handle);
211 +       if (errno == EINPROGRESS) {
212 +           done = 0;
213 +           *error_code = MPI_SUCCESS;
214 +       }
215 +       else {
216 +           err = aio_return((struct aiocb *) (*request)->handle); 
217 +           (*request)->nbytes = err;
218 +           errno = aio_error((struct aiocb *) (*request)->handle);
219 +
220 +           done = 1;
221 +
222 +           if (err == -1) {
223 +#ifdef MPICH2
224 +               *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
225 +                   "**io %s", strerror(errno));
226 +               return;
227 +#elif defined(PRINT_ERR_MSG)
228 +                               *error_code = MPI_ERR_UNKNOWN;
229 +#else /* MPICH-1 */
230 +               *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
231 +                             myname, "I/O Error", "%s", strerror(errno));
232 +               ADIOI_Error((*request)->fd, *error_code, myname);           
233 +#endif
234 +           }
235 +           else *error_code = MPI_SUCCESS;
236 +       }
237 +    } /* if ((*request)->queued) */
238 +    else {
239 +       done = 1;
240 +       *error_code = MPI_SUCCESS;
241 +    }
242 +#ifdef HAVE_STATUS_SET_BYTES
243 +    if (done && ((*request)->nbytes != -1))
244 +       MPIR_Status_set_bytes(status, (*request)->datatype, (*request)->nbytes);
245 +#endif
246 +
247 +#endif
248 +
249 +#ifndef NO_AIO
250 +    if (done) {
251 +       /* if request is still queued in the system, it is also there
252 +           on ADIOI_Async_list. Delete it from there. */
253 +       if ((*request)->queued) ADIOI_Del_req_from_list(request);
254 +
255 +       (*request)->fd->async_count--;
256 +       if ((*request)->handle) ADIOI_Free((*request)->handle);
257 +       ADIOI_Free_request((ADIOI_Req_node *) (*request));
258 +       *request = ADIO_REQUEST_NULL;
259 +    }
260 +    return done;
261 +#endif
262 +
263 +}
264 +
265 +
266 +int ADIOI_LUSTRE_WriteDone(ADIO_Request *request, ADIO_Status *status, int *error_code)  
267 +{
268 +    return ADIOI_LUSTRE_ReadDone(request, status, error_code);
269 +} 
270 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_fcntl.c mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_fcntl.c
271 --- mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_fcntl.c  1969-12-31 19:00:00.000000000 -0500
272 +++ mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_fcntl.c  2005-12-06 11:54:37.901128527 -0500
273 @@ -0,0 +1,126 @@
274 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
275 +/* 
276 + *   $Id: ad_lustre_fcntl.c,v 1.1.1.1 2004/11/04 11:03:38 liam Exp $    
277 + *
278 + *   Copyright (C) 1997 University of Chicago. 
279 + *   See COPYRIGHT notice in top-level directory.
280 + */
281 +
282 +#include "ad_lustre.h"
283 +#include "adio_extern.h"
284 +/* #ifdef MPISGI
285 +#include "mpisgi2.h"
286 +#endif */
287 +
288 +void ADIOI_LUSTRE_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct, int *error_code)
289 +{
290 +    int i, ntimes;
291 +    ADIO_Offset curr_fsize, alloc_size, size, len, done;
292 +    ADIO_Status status;
293 +    char *buf;
294 +#if defined(MPICH2) || !defined(PRINT_ERR_MSG)
295 +    static char myname[] = "ADIOI_LUSTRE_FCNTL";
296 +#endif
297 +
298 +    switch(flag) {
299 +    case ADIO_FCNTL_GET_FSIZE:
300 +       fcntl_struct->fsize = lseek(fd->fd_sys, 0, SEEK_END);
301 +       if (fd->fp_sys_posn != -1) 
302 +            lseek(fd->fd_sys, fd->fp_sys_posn, SEEK_SET);
303 +       if (fcntl_struct->fsize == -1) {
304 +#ifdef MPICH2
305 +           *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
306 +               "**io %s", strerror(errno));
307 +#elif defined(PRINT_ERR_MSG)
308 +                       *error_code = MPI_ERR_UNKNOWN;
309 +#else /* MPICH-1 */
310 +           *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
311 +                             myname, "I/O Error", "%s", strerror(errno));
312 +           ADIOI_Error(fd, *error_code, myname);           
313 +#endif
314 +       }
315 +       else *error_code = MPI_SUCCESS;
316 +       break;
317 +
318 +    case ADIO_FCNTL_SET_DISKSPACE:
319 +       /* will be called by one process only */
320 +       /* On file systems with no preallocation function, I have to 
321 +           explicitly write 
322 +           to allocate space. Since there could be holes in the file, 
323 +           I need to read up to the current file size, write it back, 
324 +           and then write beyond that depending on how much 
325 +           preallocation is needed.
326 +           read/write in sizes of no more than ADIOI_PREALLOC_BUFSZ */
327 +
328 +       curr_fsize = lseek(fd->fd_sys, 0, SEEK_END);
329 +       alloc_size = fcntl_struct->diskspace;
330 +
331 +       size = ADIOI_MIN(curr_fsize, alloc_size);
332 +       
333 +       ntimes = (size + ADIOI_PREALLOC_BUFSZ - 1)/ADIOI_PREALLOC_BUFSZ;
334 +       buf = (char *) ADIOI_Malloc(ADIOI_PREALLOC_BUFSZ);
335 +       done = 0;
336 +
337 +       for (i=0; i<ntimes; i++) {
338 +           len = ADIOI_MIN(size-done, ADIOI_PREALLOC_BUFSZ);
339 +           ADIO_ReadContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET, done,
340 +                           &status, error_code);
341 +           if (*error_code != MPI_SUCCESS) {
342 +               ADIOI_Free(buf);
343 +#ifdef MPICH2
344 +               *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
345 +                   "**io %s", strerror(errno));
346 +#elif defined(PRINT_ERR_MSG)
347 +               FPRINTF(stderr, "ADIOI_LUSTRE_Fcntl: To preallocate disk space, ROMIO needs to read the file and write it back, but is unable to read the file. Please give the file read permission and open it with MPI_MODE_RDWR.\n");
348 +               MPI_Abort(MPI_COMM_WORLD, 1);
349 +#else /* MPICH-1 */
350 +               *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_PREALLOC_PERM,
351 +                             myname, (char *) 0, (char *) 0);
352 +               ADIOI_Error(fd, *error_code, myname);
353 +#endif
354 +                return;  
355 +           }
356 +           ADIO_WriteContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET, 
357 +                             done, &status, error_code);
358 +           if (*error_code != MPI_SUCCESS) return;
359 +           done += len;
360 +       }
361 +
362 +       if (alloc_size > curr_fsize) {
363 +           memset(buf, 0, ADIOI_PREALLOC_BUFSZ); 
364 +           size = alloc_size - curr_fsize;
365 +           ntimes = (size + ADIOI_PREALLOC_BUFSZ - 1)/ADIOI_PREALLOC_BUFSZ;
366 +           for (i=0; i<ntimes; i++) {
367 +               len = ADIOI_MIN(alloc_size-done, ADIOI_PREALLOC_BUFSZ);
368 +               ADIO_WriteContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET, 
369 +                                done, &status, error_code);
370 +               if (*error_code != MPI_SUCCESS) return;
371 +               done += len;  
372 +           }
373 +       }
374 +       ADIOI_Free(buf);
375 +       if (fd->fp_sys_posn != -1) 
376 +           lseek(fd->fd_sys, fd->fp_sys_posn, SEEK_SET);
377 +       *error_code = MPI_SUCCESS;
378 +       break;
379 +
380 +    case ADIO_FCNTL_SET_IOMODE:
381 +        /* for implementing PFS I/O modes. will not occur in MPI-IO
382 +           implementation.*/
383 +       if (fd->iomode != fcntl_struct->iomode) {
384 +           fd->iomode = fcntl_struct->iomode;
385 +           MPI_Barrier(MPI_COMM_WORLD);
386 +       }
387 +       *error_code = MPI_SUCCESS;
388 +       break;
389 +
390 +    case ADIO_FCNTL_SET_ATOMICITY:
391 +       fd->atomicity = (fcntl_struct->atomicity == 0) ? 0 : 1;
392 +       *error_code = MPI_SUCCESS;
393 +       break;
394 +
395 +    default:
396 +       FPRINTF(stderr, "Unknown flag passed to ADIOI_LUSTRE_Fcntl\n");
397 +       MPI_Abort(MPI_COMM_WORLD, 1);
398 +    }
399 +}
400 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_flush.c mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_flush.c
401 --- mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_flush.c  1969-12-31 19:00:00.000000000 -0500
402 +++ mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_flush.c  2005-12-06 11:54:37.903128261 -0500
403 @@ -0,0 +1,14 @@
404 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
405 +/* 
406 + *   $Id: ad_lustre_flush.c,v 1.1.1.1 2004/11/04 11:03:38 liam Exp $    
407 + *
408 + *   Copyright (C) 1997 University of Chicago. 
409 + *   See COPYRIGHT notice in top-level directory.
410 + */
411 +
412 +#include "ad_lustre.h"
413 +
414 +void ADIOI_LUSTRE_Flush(ADIO_File fd, int *error_code)
415 +{
416 +    ADIOI_GEN_Flush(fd, error_code);
417 +}
418 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/ad_lustre.h mpich-1.2.6/romio/adio/ad_lustre/ad_lustre.h
419 --- mpich-1.2.6/romio/adio/ad_lustre/ad_lustre.h        1969-12-31 19:00:00.000000000 -0500
420 +++ mpich-1.2.6/romio/adio/ad_lustre/ad_lustre.h        2005-12-06 11:54:37.891129861 -0500
421 @@ -0,0 +1,36 @@
422 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
423 +/* 
424 + *   $Id: ad_lustre.h,v 1.2 2005/07/07 14:38:17 liam Exp $    
425 + *
426 + *   Copyright (C) 1997 University of Chicago. 
427 + *   See COPYRIGHT notice in top-level directory.
428 + */
429 +
430 +#ifndef AD_UNIX_INCLUDE
431 +#define AD_UNIX_INCLUDE
432 +
433 +/* temp*/
434 +#define HAVE_ASM_TYPES_H 1
435 +
436 +#include <unistd.h>
437 +#include <linux/types.h>
438 +#include <fcntl.h>
439 +#include <sys/ioctl.h>
440 +#include "lustre/lustre_user.h"
441 +#include "adio.h"
442 +
443 +#ifndef NO_AIO
444 +#ifdef AIO_SUN
445 +#include <sys/asynch.h>
446 +#else
447 +#include <aio.h>
448 +#ifdef NEEDS_ADIOCB_T
449 +typedef struct adiocb adiocb_t;
450 +#endif
451 +#endif
452 +#endif
453 +
454 +int ADIOI_LUSTRE_aio(ADIO_File fd, void *buf, int len, ADIO_Offset offset,
455 +                 int wr, void *handle);
456 +
457 +#endif
458 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_hints.c mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_hints.c
459 --- mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_hints.c  1969-12-31 19:00:00.000000000 -0500
460 +++ mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_hints.c  2005-12-06 11:54:37.904128127 -0500
461 @@ -0,0 +1,130 @@
462 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
463 +/* 
464 + *   $Id: ad_lustre_hints.c,v 1.2 2005/07/07 14:38:17 liam Exp $    
465 + *
466 + *   Copyright (C) 1997 University of Chicago. 
467 + *   See COPYRIGHT notice in top-level directory.
468 + */
469 +
470 +#include "ad_lustre.h"
471 +
472 +void ADIOI_LUSTRE_SetInfo(ADIO_File fd, MPI_Info users_info, int *error_code)
473 +{
474 +    char *value, *value_in_fd;
475 +    int flag, tmp_val, str_factor=-1, str_unit=0, start_iodev=-1;
476 +    struct lov_user_md lum = { 0 };
477 +    int err, myrank, fd_sys, perm, amode, old_mask;
478 +
479 +    if ( (fd->info) == MPI_INFO_NULL) {
480 +       /* This must be part of the open call. can set striping parameters 
481 +           if necessary. */ 
482 +       MPI_Info_create(&(fd->info));
483 +       
484 +       /* has user specified striping or server buffering parameters 
485 +           and do they have the same value on all processes? */
486 +       if (users_info != MPI_INFO_NULL) {
487 +           value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
488 +
489 +           MPI_Info_get(users_info, "striping_factor", MPI_MAX_INFO_VAL, 
490 +                        value, &flag);
491 +           if (flag) {
492 +               str_factor=atoi(value);
493 +               tmp_val = str_factor;
494 +               MPI_Bcast(&tmp_val, 1, MPI_INT, 0, fd->comm);
495 +               if (tmp_val != str_factor) {
496 +                   FPRINTF(stderr, "ADIOI_LUSTRE_SetInfo: the value for key \"striping_factor\" must be the same on all processes\n");
497 +                   MPI_Abort(MPI_COMM_WORLD, 1);
498 +               }
499 +           }
500 +
501 +           MPI_Info_get(users_info, "striping_unit", MPI_MAX_INFO_VAL, 
502 +                        value, &flag);
503 +           if (flag) {
504 +               str_unit=atoi(value);
505 +               tmp_val = str_unit;
506 +               MPI_Bcast(&tmp_val, 1, MPI_INT, 0, fd->comm);
507 +               if (tmp_val != str_unit) {
508 +                   FPRINTF(stderr, "ADIOI_LUSTRE_SetInfo: the value for key \"striping_unit\" must be the same on all processes\n");
509 +                   MPI_Abort(MPI_COMM_WORLD, 1);
510 +               }
511 +           }
512 +
513 +           MPI_Info_get(users_info, "start_iodevice", MPI_MAX_INFO_VAL, 
514 +                        value, &flag);
515 +           if (flag) {
516 +               start_iodev=atoi(value);
517 +               tmp_val = start_iodev;
518 +               MPI_Bcast(&tmp_val, 1, MPI_INT, 0, fd->comm);
519 +               if (tmp_val != start_iodev) {
520 +                   FPRINTF(stderr, "ADIOI_LUSTRE_SetInfo: the value for key \"start_iodevice\" must be the same on all processes\n");
521 +                   MPI_Abort(MPI_COMM_WORLD, 1);
522 +               }
523 +           }
524 +
525 +         /* if user has specified striping info, process 0 tries to set it */
526 +           if ((str_factor > 0) || (str_unit > 0) || (start_iodev >= 0)) {
527 +               MPI_Comm_rank(fd->comm, &myrank);
528 +               if (!myrank) {
529 +                   if (fd->perm == ADIO_PERM_NULL) {
530 +                       old_mask = umask(022);
531 +                       umask(old_mask);
532 +                       perm = old_mask ^ 0666;
533 +                   }
534 +                   else perm = fd->perm;
535 +
536 +                   amode = 0;
537 +                   if (fd->access_mode & ADIO_CREATE)
538 +                       amode = amode | O_CREAT;
539 +                   if (fd->access_mode & ADIO_RDWR ||
540 +                       (fd->access_mode & ADIO_RDONLY &&
541 +                        fd->access_mode & ADIO_WRONLY))
542 +                       amode = amode | O_RDWR;
543 +                   else if (fd->access_mode & ADIO_WRONLY)
544 +                       amode = amode | O_WRONLY;
545 +                   else if (fd->access_mode & ADIO_RDONLY)
546 +                       amode = amode | O_RDONLY;
547 +                   if (fd->access_mode & ADIO_EXCL)
548 +                       amode = amode | O_EXCL;
549 +
550 +                   /* we need to create file so ensure this is set */
551 +                    amode = amode | O_LOV_DELAY_CREATE | O_CREAT;
552 +
553 +                    fd_sys = open(fd->filename, amode, perm);
554 +                    if (fd_sys == -1) { 
555 +                       if (errno != EEXIST) 
556 +                           FPRINTF(stderr, "ADIOI_LUSTRE_SetInfo: Failure to open file %s %d %d\n",strerror(errno), amode, perm);
557 +                    } else {
558 +                        lum.lmm_magic = LOV_USER_MAGIC;
559 +                        lum.lmm_pattern = 0;
560 +                        lum.lmm_stripe_size = str_unit;
561 +                        lum.lmm_stripe_count = str_factor;
562 +                        lum.lmm_stripe_offset = start_iodev;
563 +
564 +                        err = ioctl(fd_sys, LL_IOC_LOV_SETSTRIPE, &lum);
565 +                        if (err == -1 && errno != EEXIST) { 
566 +                           FPRINTF(stderr, "ADIOI_LUSTRE_SetInfo: Failure to set stripe info %s \n",strerror(errno));
567 +                        }
568 +
569 +                        close(fd_sys);
570 +                   }
571 +
572 +               }
573 +               MPI_Barrier(fd->comm);
574 +           }
575 +
576 +           ADIOI_Free(value);
577 +       }
578 +       
579 +       /* set the values for collective I/O and data sieving parameters */
580 +       ADIOI_GEN_SetInfo(fd, users_info, error_code);
581 +    }
582 +    
583 +    else {
584 +       /* The file has been opened previously and fd->fd_sys is a valid
585 +           file descriptor. cannot set striping parameters now. */
586 +       
587 +       /* set the values for collective I/O and data sieving parameters */
588 +       ADIOI_GEN_SetInfo(fd, users_info, error_code);
589 +
590 +    }
591 +    
592 +    *error_code = MPI_SUCCESS;
593 +}
594 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_iread.c mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_iread.c
595 --- mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_iread.c  1969-12-31 19:00:00.000000000 -0500
596 +++ mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_iread.c  2005-12-06 11:54:37.904128127 -0500
597 @@ -0,0 +1,106 @@
598 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
599 +/* 
600 + *   $Id: ad_lustre_iread.c,v 1.1.1.1 2004/11/04 11:03:38 liam Exp $    
601 + *
602 + *   Copyright (C) 1997 University of Chicago. 
603 + *   See COPYRIGHT notice in top-level directory.
604 + */
605 +
606 +#include "ad_lustre.h"
607 +
608 +void ADIOI_LUSTRE_IreadContig(ADIO_File fd, void *buf, int count, 
609 +                MPI_Datatype datatype, int file_ptr_type,
610 +                ADIO_Offset offset, ADIO_Request *request, int *error_code)  
611 +{
612 +    int len, typesize;
613 +#ifdef NO_AIO
614 +    ADIO_Status status;
615 +#else
616 +    int err=-1;
617 +#if defined(MPICH2) || !defined(PRINT_ERR_MSG)
618 +    static char myname[] = "ADIOI_LUSTRE_IREADCONTIG";
619 +#endif
620 +#endif
621 +
622 +    (*request) = ADIOI_Malloc_request();
623 +    (*request)->optype = ADIOI_READ;
624 +    (*request)->fd = fd;
625 +    (*request)->datatype = datatype;
626 +
627 +    MPI_Type_size(datatype, &typesize);
628 +    len = count * typesize;
629 +
630 +#ifdef NO_AIO
631 +    /* HP, FreeBSD, Linux */
632 +    /* no support for nonblocking I/O. Use blocking I/O. */
633 +
634 +    ADIOI_LUSTRE_ReadContig(fd, buf, len, MPI_BYTE, file_ptr_type, offset, 
635 +                        &status, error_code);  
636 +    (*request)->queued = 0;
637 +#ifdef HAVE_STATUS_SET_BYTES
638 +    if (*error_code == MPI_SUCCESS) {
639 +       MPI_Get_elements(&status, MPI_BYTE, &len);
640 +       (*request)->nbytes = len;
641 +    }
642 +#endif
643 +
644 +#else
645 +    if (file_ptr_type == ADIO_INDIVIDUAL) offset = fd->fp_ind;
646 +    err = ADIOI_LUSTRE_aio(fd, buf, len, offset, 0, &((*request)->handle));
647 +    if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind += len;
648 +
649 +    (*request)->queued = 1;
650 +    ADIOI_Add_req_to_list(request);
651 +
652 +    if (err == -1) {
653 +#ifdef MPICH2
654 +       *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
655 +           "**io %s", strerror(errno));
656 +       return;
657 +#elif defined(PRINT_ERR_MSG)
658 +                       *error_code = MPI_ERR_UNKNOWN;
659 +#else /* MPICH-1 */
660 +       *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
661 +                             myname, "I/O Error", "%s", strerror(errno));
662 +       ADIOI_Error(fd, *error_code, myname);       
663 +#endif
664 +    }
665 +    else *error_code = MPI_SUCCESS;
666 +#endif  /* NO_AIO */
667 +
668 +    fd->fp_sys_posn = -1;   /* set it to null. */
669 +    fd->async_count++;
670 +}
671 +
672 +
673 +
674 +void ADIOI_LUSTRE_IreadStrided(ADIO_File fd, void *buf, int count, 
675 +                      MPI_Datatype datatype, int file_ptr_type,
676 +                       ADIO_Offset offset, ADIO_Request *request, int
677 +                       *error_code)
678 +{
679 +    ADIO_Status status;
680 +#ifdef HAVE_STATUS_SET_BYTES
681 +    int typesize;
682 +#endif
683 +
684 +    *request = ADIOI_Malloc_request();
685 +    (*request)->optype = ADIOI_READ;
686 +    (*request)->fd = fd;
687 +    (*request)->datatype = datatype;
688 +    (*request)->queued = 0;
689 +    (*request)->handle = 0;
690 +
691 +/* call the blocking version. It is faster because it does data sieving. */
692 +    ADIOI_LUSTRE_ReadStrided(fd, buf, count, datatype, file_ptr_type, 
693 +                            offset, &status, error_code);  
694 +
695 +    fd->async_count++;
696 +
697 +#ifdef HAVE_STATUS_SET_BYTES
698 +    if (*error_code == MPI_SUCCESS) {
699 +       MPI_Type_size(datatype, &typesize);
700 +       (*request)->nbytes = count * typesize;
701 +    }
702 +#endif
703 +}
704 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_iwrite.c mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_iwrite.c
705 --- mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_iwrite.c 1969-12-31 19:00:00.000000000 -0500
706 +++ mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_iwrite.c 2005-12-06 11:54:37.906127861 -0500
707 @@ -0,0 +1,268 @@
708 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
709 +/* 
710 + *   $Id: ad_lustre_iwrite.c,v 1.1.1.1 2004/11/04 11:03:38 liam Exp $    
711 + *
712 + *   Copyright (C) 1997 University of Chicago. 
713 + *   See COPYRIGHT notice in top-level directory.
714 + */
715 +
716 +#include "ad_lustre.h"
717 +
718 +void ADIOI_LUSTRE_IwriteContig(ADIO_File fd, void *buf, int count, 
719 +                MPI_Datatype datatype, int file_ptr_type,
720 +                ADIO_Offset offset, ADIO_Request *request, int *error_code)  
721 +{
722 +    int len, typesize;
723 +#ifdef NO_AIO
724 +    ADIO_Status status;
725 +#else
726 +    int err=-1;
727 +#if defined(MPICH2) || !defined(PRINT_ERR_MSG)
728 +    static char myname[] = "ADIOI_LUSTRE_IWRITECONTIG";
729 +#endif
730 +#endif
731 +
732 +    *request = ADIOI_Malloc_request();
733 +    (*request)->optype = ADIOI_WRITE;
734 +    (*request)->fd = fd;
735 +    (*request)->datatype = datatype;
736 +
737 +    MPI_Type_size(datatype, &typesize);
738 +    len = count * typesize;
739 +
740 +#ifdef NO_AIO
741 +    /* HP, FreeBSD, Linux */
742 +    /* no support for nonblocking I/O. Use blocking I/O. */
743 +
744 +    ADIOI_LUSTRE_WriteContig(fd, buf, len, MPI_BYTE, file_ptr_type, offset, 
745 +                         &status, error_code);  
746 +    (*request)->queued = 0;
747 +#ifdef HAVE_STATUS_SET_BYTES
748 +    if (*error_code == MPI_SUCCESS) {
749 +       MPI_Get_elements(&status, MPI_BYTE, &len);
750 +       (*request)->nbytes = len;
751 +    }
752 +#endif
753 +
754 +#else
755 +    if (file_ptr_type == ADIO_INDIVIDUAL) offset = fd->fp_ind;
756 +    err = ADIOI_LUSTRE_aio(fd, buf, len, offset, 1, &((*request)->handle));
757 +    if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind += len;
758 +
759 +    (*request)->queued = 1;
760 +    ADIOI_Add_req_to_list(request);
761 +
762 +    if (err == -1) {
763 +#ifdef MPICH2
764 +       *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
765 +           "**io %s", strerror(errno));
766 +       return;
767 +#elif defined(PRINT_ERR_MSG)
768 +                       *error_code = MPI_ERR_UNKNOWN;
769 +#else /* MPICH-1 */
770 +       *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
771 +                             myname, "I/O Error", "%s", strerror(errno));
772 +       ADIOI_Error(fd, *error_code, myname);       
773 +#endif
774 +    }
775 +    else *error_code = MPI_SUCCESS;
776 +#endif /* NO_AIO */
777 +
778 +    fd->fp_sys_posn = -1;   /* set it to null. */
779 +    fd->async_count++;
780 +}
781 +
782 +
783 +
784 +
785 +void ADIOI_LUSTRE_IwriteStrided(ADIO_File fd, void *buf, int count, 
786 +                      MPI_Datatype datatype, int file_ptr_type,
787 +                       ADIO_Offset offset, ADIO_Request *request, int
788 +                       *error_code)
789 +{
790 +    ADIO_Status status;
791 +#ifdef HAVE_STATUS_SET_BYTES
792 +    int typesize;
793 +#endif
794 +
795 +    *request = ADIOI_Malloc_request();
796 +    (*request)->optype = ADIOI_WRITE;
797 +    (*request)->fd = fd;
798 +    (*request)->datatype = datatype;
799 +    (*request)->queued = 0;
800 +    (*request)->handle = 0;
801 +
802 +/* call the blocking version. It is faster because it does data sieving. */
803 +    ADIOI_LUSTRE_WriteStrided(fd, buf, count, datatype, file_ptr_type, 
804 +                            offset, &status, error_code);  
805 +
806 +    fd->async_count++;
807 +
808 +#ifdef HAVE_STATUS_SET_BYTES
809 +    if (*error_code == MPI_SUCCESS) {
810 +       MPI_Type_size(datatype, &typesize);
811 +       (*request)->nbytes = count * typesize;
812 +    }
813 +#endif
814 +}
815 +
816 +
817 +/* This function is for implementation convenience. It is not user-visible.
818 +   It takes care of the differences in the interface for nonblocking I/O
819 +   on various Unix machines! If wr==1 write, wr==0 read. */
820 +
821 +int ADIOI_LUSTRE_aio(ADIO_File fd, void *buf, int len, ADIO_Offset offset,
822 +                 int wr, void *handle)
823 +{
824 +    int err=-1, fd_sys;
825 +
826 +#ifndef NO_AIO
827 +    int error_code;
828 +#ifdef AIO_SUN 
829 +    aio_result_t *result;
830 +#else
831 +    struct aiocb *aiocbp;
832 +#endif
833 +#endif
834 +
835 +    fd_sys = fd->fd_sys;
836 +
837 +#ifdef AIO_SUN
838 +    result = (aio_result_t *) ADIOI_Malloc(sizeof(aio_result_t));
839 +    result->aio_return = AIO_INPROGRESS;
840 +    if (wr) err = aiowrite(fd_sys, buf, len, offset, SEEK_SET, result); 
841 +    else err = aioread(fd_sys, buf, len, offset, SEEK_SET, result);
842 +
843 +    if (err == -1) {
844 +       if (errno == EAGAIN) { 
845 +       /* the man pages say EPROCLIM, but in reality errno is set to EAGAIN! */
846 +
847 +        /* exceeded the max. no. of outstanding requests.
848 +           complete all previous async. requests and try again.*/
849 +
850 +           ADIOI_Complete_async(&error_code);
851 +           if (wr) err = aiowrite(fd_sys, buf, len, offset, SEEK_SET, result); 
852 +           else err = aioread(fd_sys, buf, len, offset, SEEK_SET, result);
853 +
854 +           while (err == -1) {
855 +               if (errno == EAGAIN) {
856 +                    /* sleep and try again */
857 +                    sleep(1);
858 +                   if (wr) err = aiowrite(fd_sys, buf, len, offset, SEEK_SET, result); 
859 +                   else err = aioread(fd_sys, buf, len, offset, SEEK_SET, result);
860 +               }
861 +                else {
862 +                    FPRINTF(stderr, "Unknown errno %d in ADIOI_LUSTRE_aio\n", errno);
863 +                    MPI_Abort(MPI_COMM_WORLD, 1);
864 +                }
865 +           }
866 +       }
867 +        else {
868 +            FPRINTF(stderr, "Unknown errno %d in ADIOI_LUSTRE_aio\n", errno);
869 +            MPI_Abort(MPI_COMM_WORLD, 1);
870 +        }
871 +    }
872 +
873 +    *((aio_result_t **) handle) = result;
874 +#endif
875 +
876 +#ifdef NO_FD_IN_AIOCB
877 +/* IBM */
878 +    aiocbp = (struct aiocb *) ADIOI_Malloc(sizeof(struct aiocb));
879 +    aiocbp->aio_whence = SEEK_SET;
880 +    aiocbp->aio_offset = offset;
881 +    aiocbp->aio_buf = buf;
882 +    aiocbp->aio_nbytes = len;
883 +    if (wr) err = aio_write(fd_sys, aiocbp);
884 +    else err = aio_read(fd_sys, aiocbp);
885 +
886 +    if (err == -1) {
887 +       if (errno == EAGAIN) {
888 +        /* exceeded the max. no. of outstanding requests.
889 +          complete all previous async. requests and try again. */
890 +
891 +           ADIOI_Complete_async(&error_code);
892 +           if (wr) err = aio_write(fd_sys, aiocbp);
893 +           else err = aio_read(fd_sys, aiocbp);
894 +
895 +            while (err == -1) {
896 +                if (errno == EAGAIN) {
897 +                    /* sleep and try again */
898 +                    sleep(1);
899 +                   if (wr) err = aio_write(fd_sys, aiocbp);
900 +                   else err = aio_read(fd_sys, aiocbp);
901 +               }
902 +                else {
903 +                    FPRINTF(stderr, "Unknown errno %d in ADIOI_LUSTRE_aio\n", errno);
904 +                    MPI_Abort(MPI_COMM_WORLD, 1);
905 +                }
906 +            }
907 +       }
908 +        else {
909 +            FPRINTF(stderr, "Unknown errno %d in ADIOI_LUSTRE_aio\n", errno);
910 +            MPI_Abort(MPI_COMM_WORLD, 1);
911 +        }
912 +    }
913 +
914 +    *((struct aiocb **) handle) = aiocbp;
915 +
916 +#elif (!defined(NO_AIO) && !defined(AIO_SUN))
917 +/* DEC, SGI IRIX 5 and 6 */
918 +
919 +    aiocbp = (struct aiocb *) ADIOI_Calloc(sizeof(struct aiocb), 1);
920 +    aiocbp->aio_fildes = fd_sys;
921 +    aiocbp->aio_offset = offset;
922 +    aiocbp->aio_buf = buf;
923 +    aiocbp->aio_nbytes = len;
924 +
925 +#ifdef AIO_PRIORITY_DEFAULT
926 +/* DEC */
927 +    aiocbp->aio_reqprio = AIO_PRIO_DFL;   /* not needed in DEC Unix 4.0 */
928 +    aiocbp->aio_sigevent.sigev_signo = 0;
929 +#else
930 +    aiocbp->aio_reqprio = 0;
931 +#endif
932 +
933 +#ifdef AIO_SIGNOTIFY_NONE
934 +/* SGI IRIX 6 */
935 +    aiocbp->aio_sigevent.sigev_notify = SIGEV_NONE;
936 +#else
937 +    aiocbp->aio_sigevent.sigev_signo = 0;
938 +#endif
939 +
940 +    if (wr) err = aio_write(aiocbp);
941 +    else err = aio_read(aiocbp);
942 +
943 +    if (err == -1) {
944 +       if (errno == EAGAIN) {
945 +        /* exceeded the max. no. of outstanding requests.
946 +           complete all previous async. requests and try again. */
947 +
948 +           ADIOI_Complete_async(&error_code);
949 +           if (wr) err = aio_write(aiocbp);
950 +           else err = aio_read(aiocbp);
951 +
952 +           while (err == -1) {
953 +               if (errno == EAGAIN) {
954 +                   /* sleep and try again */
955 +                   sleep(1);
956 +                   if (wr) err = aio_write(aiocbp);
957 +                   else err = aio_read(aiocbp);
958 +               }
959 +               else {
960 +                   FPRINTF(stderr, "Unknown errno %d in ADIOI_LUSTRE_aio\n", errno);
961 +                   MPI_Abort(MPI_COMM_WORLD, 1);
962 +               }
963 +           }
964 +        }
965 +       else {
966 +           FPRINTF(stderr, "Unknown errno %d in ADIOI_LUSTRE_aio\n", errno);
967 +           MPI_Abort(MPI_COMM_WORLD, 1);
968 +       }
969 +    }
970 +
971 +    *((struct aiocb **) handle) = aiocbp;
972 +#endif
973 +
974 +    return err;
975 +}
976 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_open.c mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_open.c
977 --- mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_open.c   1969-12-31 19:00:00.000000000 -0500
978 +++ mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_open.c   2005-12-06 11:54:37.906127861 -0500
979 @@ -0,0 +1,100 @@
980 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
981 +/* 
982 + *   $Id: ad_lustre_open.c,v 1.1.1.1 2004/11/04 11:03:38 liam Exp $    
983 + *
984 + *   Copyright (C) 1997 University of Chicago. 
985 + *   See COPYRIGHT notice in top-level directory.
986 + */
987 +
988 +#include "ad_lustre.h"
989 +
990 +void ADIOI_LUSTRE_Open(ADIO_File fd, int *error_code)
991 +{
992 +    int perm, old_mask, amode;
993 +    struct lov_user_md lum = { 0 };
994 +    char *value;
995 +
996 +#if defined(MPICH2) || !defined(PRINT_ERR_MSG)
997 +    static char myname[] = "ADIOI_LUSTRE_OPEN";
998 +#endif
999 +
1000 +    if (fd->perm == ADIO_PERM_NULL) {
1001 +       old_mask = umask(022);
1002 +       umask(old_mask);
1003 +       perm = old_mask ^ 0666;
1004 +    }
1005 +    else perm = fd->perm;
1006 +
1007 +    amode = 0;
1008 +    if (fd->access_mode & ADIO_CREATE)
1009 +       amode = amode | O_CREAT;
1010 +    if (fd->access_mode & ADIO_RDONLY)
1011 +       amode = amode | O_RDONLY;
1012 +    if (fd->access_mode & ADIO_WRONLY)
1013 +       amode = amode | O_WRONLY;
1014 +    if (fd->access_mode & ADIO_RDWR)
1015 +       amode = amode | O_RDWR;
1016 +    if (fd->access_mode & ADIO_EXCL)
1017 +       amode = amode | O_EXCL;
1018 +
1019 +    fd->fd_sys = open(fd->filename, amode, perm);
1020 +
1021 +    if (fd->fd_sys != -1) {
1022 +        int err;
1023 +
1024 +        value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
1025 +
1026 +        /* get file striping information and set it in info */
1027 +        lum.lmm_magic = LOV_USER_MAGIC;
1028 +        err = ioctl(fd->fd_sys, LL_IOC_LOV_GETSTRIPE, (void *) &lum);
1029 +
1030 +        if (!err) {
1031 +            sprintf(value, "%d", lum.lmm_stripe_size);
1032 +            MPI_Info_set(fd->info, "striping_unit", value);
1033 +
1034 +            sprintf(value, "%d", lum.lmm_stripe_count);
1035 +            MPI_Info_set(fd->info, "striping_factor", value);
1036 +
1037 +            sprintf(value, "%d", lum.lmm_stripe_offset);
1038 +            MPI_Info_set(fd->info, "start_iodevice", value);
1039 +        }
1040 +        ADIOI_Free(value);
1041 +
1042 +        if (fd->access_mode & ADIO_APPEND)
1043 +            fd->fp_ind = fd->fp_sys_posn = lseek(fd->fd_sys, 0, SEEK_END);
1044 +    }
1045 +
1046 +
1047 +    if ((fd->fd_sys != -1) && (fd->access_mode & ADIO_APPEND))
1048 +       fd->fp_ind = fd->fp_sys_posn = lseek(fd->fd_sys, 0, SEEK_END);
1049 +
1050 +    if (fd->fd_sys == -1) {
1051 +#ifdef MPICH2
1052 +       if (errno == ENAMETOOLONG)
1053 +           *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_BAD_FILE, "**filenamelong", "**filenamelong %s %d", fd->filename, strlen(fd->filename) );
1054 +       else if (errno == ENOENT)
1055 +           *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_NO_SUCH_FILE, "**filenoexist", "**filenoexist %s", fd->filename );
1056 +       else if (errno == ENOTDIR || errno == ELOOP)
1057 +           *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_BAD_FILE, "**filenamedir", "**filenamedir %s", fd->filename );
1058 +       else if (errno == EACCES) {
1059 +           *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_ACCESS, "**fileaccess", "**fileaccess %s", 
1060 +                                              fd->filename );
1061 +       }
1062 +       else if (errno == EROFS) {
1063 +           /* Read only file or file system and write access requested */
1064 +           *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_READ_ONLY, "**ioneedrd", 0 );
1065 +       }
1066 +       else {
1067 +           *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
1068 +           "**io %s", strerror(errno));
1069 +       }
1070 +#elif defined(PRINT_ERR_MSG)
1071 +                       *error_code = MPI_ERR_UNKNOWN;
1072 +#else /* MPICH-1 */
1073 +       *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
1074 +                             myname, "I/O Error", "%s", strerror(errno));
1075 +       ADIOI_Error(ADIO_FILE_NULL, *error_code, myname);           
1076 +#endif
1077 +    }
1078 +    else *error_code = MPI_SUCCESS;
1079 +}
1080 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_rdcoll.c mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_rdcoll.c
1081 --- mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_rdcoll.c 1969-12-31 19:00:00.000000000 -0500
1082 +++ mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_rdcoll.c 2005-12-06 11:54:37.907127727 -0500
1083 @@ -0,0 +1,18 @@
1084 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
1085 +/* 
1086 + *   $Id: ad_lustre_rdcoll.c,v 1.1.1.1 2004/11/04 11:03:38 liam Exp $    
1087 + *
1088 + *   Copyright (C) 1997 University of Chicago. 
1089 + *   See COPYRIGHT notice in top-level directory.
1090 + */
1091 +
1092 +#include "ad_lustre.h"
1093 +
1094 +void ADIOI_LUSTRE_ReadStridedColl(ADIO_File fd, void *buf, int count,
1095 +                       MPI_Datatype datatype, int file_ptr_type,
1096 +                       ADIO_Offset offset, ADIO_Status *status, int
1097 +                       *error_code)
1098 +{
1099 +    ADIOI_GEN_ReadStridedColl(fd, buf, count, datatype, file_ptr_type,
1100 +                             offset, status, error_code);
1101 +}
1102 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_read.c mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_read.c
1103 --- mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_read.c   1969-12-31 19:00:00.000000000 -0500
1104 +++ mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_read.c   2005-12-06 11:54:37.907127727 -0500
1105 @@ -0,0 +1,67 @@
1106 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
1107 +/* 
1108 + *   $Id: ad_lustre_read.c,v 1.1.1.1 2004/11/04 11:03:38 liam Exp $    
1109 + *
1110 + *   Copyright (C) 1997 University of Chicago. 
1111 + *   See COPYRIGHT notice in top-level directory.
1112 + */
1113 +
1114 +#include "ad_lustre.h"
1115 +
1116 +void ADIOI_LUSTRE_ReadContig(ADIO_File fd, void *buf, int count, 
1117 +                     MPI_Datatype datatype, int file_ptr_type,
1118 +                    ADIO_Offset offset, ADIO_Status *status, int *error_code)
1119 +{
1120 +    int err=-1, datatype_size, len;
1121 +#if defined(MPICH2) || !defined(PRINT_ERR_MSG)
1122 +    static char myname[] = "ADIOI_LUSTRE_READCONTIG";
1123 +#endif
1124 +
1125 +    MPI_Type_size(datatype, &datatype_size);
1126 +    len = datatype_size * count;
1127 +
1128 +    if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
1129 +       if (fd->fp_sys_posn != offset) 
1130 +           lseek(fd->fd_sys, offset, SEEK_SET);
1131 +       err = read(fd->fd_sys, buf, len);
1132 +       fd->fp_sys_posn = offset + len;
1133 +       /* individual file pointer not updated */        
1134 +    }
1135 +    else {  /* read from curr. location of ind. file pointer */
1136 +       if (fd->fp_sys_posn != fd->fp_ind)
1137 +           lseek(fd->fd_sys, fd->fp_ind, SEEK_SET);
1138 +       err = read(fd->fd_sys, buf, len);
1139 +       fd->fp_ind += err; 
1140 +       fd->fp_sys_posn = fd->fp_ind;
1141 +    }         
1142 +
1143 +#ifdef HAVE_STATUS_SET_BYTES
1144 +    if (err != -1) MPIR_Status_set_bytes(status, datatype, err);
1145 +#endif
1146 +
1147 +    if (err == -1) {
1148 +#ifdef MPICH2
1149 +       *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
1150 +           "**io %s", strerror(errno));
1151 +#elif defined(PRINT_ERR_MSG)
1152 +                       *error_code = MPI_ERR_UNKNOWN;
1153 +#else /* MPICH-1 */
1154 +       *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
1155 +                             myname, "I/O Error", "%s", strerror(errno));
1156 +       ADIOI_Error(fd, *error_code, myname);       
1157 +#endif
1158 +    }
1159 +    else *error_code = MPI_SUCCESS;
1160 +}
1161 +
1162 +
1163 +
1164 +
1165 +void ADIOI_LUSTRE_ReadStrided(ADIO_File fd, void *buf, int count,
1166 +                       MPI_Datatype datatype, int file_ptr_type,
1167 +                       ADIO_Offset offset, ADIO_Status *status, int
1168 +                       *error_code)
1169 +{
1170 +    ADIOI_GEN_ReadStrided(fd, buf, count, datatype, file_ptr_type,
1171 +                        offset, status, error_code);
1172 +}
1173 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_resize.c mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_resize.c
1174 --- mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_resize.c 1969-12-31 19:00:00.000000000 -0500
1175 +++ mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_resize.c 2005-12-06 11:54:37.909127460 -0500
1176 @@ -0,0 +1,32 @@
1177 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
1178 +/* 
1179 + *   $Id: ad_lustre_resize.c,v 1.1.1.1 2004/11/04 11:03:38 liam Exp $    
1180 + *
1181 + *   Copyright (C) 1997 University of Chicago. 
1182 + *   See COPYRIGHT notice in top-level directory.
1183 + */
1184 +
1185 +#include "ad_lustre.h"
1186 +
1187 +void ADIOI_LUSTRE_Resize(ADIO_File fd, ADIO_Offset size, int *error_code)
1188 +{
1189 +    int err;
1190 +#if defined(MPICH2) || !defined(PRINT_ERR_MSG)
1191 +    static char myname[] = "ADIOI_LUSTRE_RESIZE";
1192 +#endif
1193 +    
1194 +    err = ftruncate(fd->fd_sys, size);
1195 +    if (err == -1) {
1196 +#ifdef MPICH2
1197 +       *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
1198 +           "**io %s", strerror(errno));
1199 +#elif defined(PRINT_ERR_MSG)
1200 +                       *error_code = MPI_ERR_UNKNOWN;
1201 +#else /* MPICH-1 */
1202 +       *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
1203 +                             myname, "I/O Error", "%s", strerror(errno));
1204 +       ADIOI_Error(fd, *error_code, myname);       
1205 +#endif
1206 +    }
1207 +    else *error_code = MPI_SUCCESS;
1208 +}
1209 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_seek.c mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_seek.c
1210 --- mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_seek.c   1969-12-31 19:00:00.000000000 -0500
1211 +++ mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_seek.c   2005-12-06 11:54:37.911127194 -0500
1212 @@ -0,0 +1,15 @@
1213 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
1214 +/* 
1215 + *   $Id: ad_lustre_seek.c,v 1.1.1.1 2004/11/04 11:03:38 liam Exp $    
1216 + *
1217 + *   Copyright (C) 1997 University of Chicago. 
1218 + *   See COPYRIGHT notice in top-level directory.
1219 + */
1220 +
1221 +#include "ad_lustre.h"
1222 +
1223 +ADIO_Offset ADIOI_LUSTRE_SeekIndividual(ADIO_File fd, ADIO_Offset offset, 
1224 +                     int whence, int *error_code)
1225 +{
1226 +    return ADIOI_GEN_SeekIndividual(fd, offset, whence, error_code);
1227 +}
1228 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_wait.c mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_wait.c
1229 --- mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_wait.c   1969-12-31 19:00:00.000000000 -0500
1230 +++ mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_wait.c   2005-12-06 11:54:37.914126794 -0500
1231 @@ -0,0 +1,188 @@
1232 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
1233 +/* 
1234 + *   $Id: ad_lustre_wait.c,v 1.1.1.1 2004/11/04 11:03:38 liam Exp $    
1235 + *
1236 + *   Copyright (C) 1997 University of Chicago. 
1237 + *   See COPYRIGHT notice in top-level directory.
1238 + */
1239 +
1240 +#include "ad_lustre.h"
1241 +
1242 +void ADIOI_LUSTRE_ReadComplete(ADIO_Request *request, ADIO_Status *status, int *error_code)  
1243 +{
1244 +#ifndef NO_AIO
1245 +#if defined(MPICH2) || !defined(PRINT_ERR_MSG)
1246 +    static char myname[] = "ADIOI_LUSTRE_READCOMPLETE";
1247 +#endif
1248 +#ifdef AIO_SUN 
1249 +    aio_result_t *result=0, *tmp;
1250 +#else
1251 +    int err;
1252 +#endif
1253 +#ifdef AIO_HANDLE_IN_AIOCB
1254 +    struct aiocb *tmp1;
1255 +#endif
1256 +#endif
1257 +
1258 +    if (*request == ADIO_REQUEST_NULL) {
1259 +       *error_code = MPI_SUCCESS;
1260 +       return;
1261 +    }
1262 +
1263 +#ifdef AIO_SUN
1264 +    if ((*request)->queued) {  /* dequeue it */
1265 +       tmp = (aio_result_t *) (*request)->handle;
1266 +       while (tmp->aio_return == AIO_INPROGRESS) usleep(1000); 
1267 +       /* sleep for 1 ms., until done. Is 1 ms. a good number? */
1268 +       /* when done, dequeue any one request */
1269 +       result = (aio_result_t *) aiowait(0);
1270 +
1271 +        (*request)->nbytes = tmp->aio_return;
1272 +
1273 +       if (tmp->aio_return == -1) {
1274 +#ifdef MPICH2
1275 +           *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
1276 +               "**io %s", strerror(tmp->aio_errno));
1277 +           return;
1278 +#elif defined(PRINT_ERR_MSG)
1279 +                       *error_code = MPI_ERR_UNKNOWN;
1280 +#else /* MPICH-1 */
1281 +           *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
1282 +                         myname, "I/O Error", "%s", strerror(tmp->aio_errno));
1283 +           ADIOI_Error((*request)->fd, *error_code, myname);       
1284 +#endif
1285 +       }
1286 +       else *error_code = MPI_SUCCESS;
1287 +
1288 +/* aiowait only dequeues a request. The completion of a request can be
1289 +   checked by just checking the aio_return flag in the handle passed
1290 +   to the original aioread()/aiowrite(). Therefore, I need to ensure
1291 +   that aiowait() is called exactly once for each previous
1292 +   aioread()/aiowrite(). This is also taken care of in ADIOI_xxxDone */
1293 +    }
1294 +    else *error_code = MPI_SUCCESS;
1295 +
1296 +#ifdef HAVE_STATUS_SET_BYTES
1297 +    if ((*request)->nbytes != -1)
1298 +       MPIR_Status_set_bytes(status, (*request)->datatype, (*request)->nbytes);
1299 +#endif
1300 +
1301 +#endif
1302 +    
1303 +#ifdef AIO_HANDLE_IN_AIOCB
1304 +/* IBM */
1305 +    if ((*request)->queued) {
1306 +       do {
1307 +           err = aio_suspend(1, (struct aiocb **) &((*request)->handle));
1308 +       } while ((err == -1) && (errno == EINTR));
1309 +
1310 +       tmp1 = (struct aiocb *) (*request)->handle;
1311 +       if (err != -1) {
1312 +           err = aio_return(tmp1->aio_handle);
1313 +           (*request)->nbytes = err;
1314 +           errno = aio_error(tmp1->aio_handle);
1315 +       }
1316 +       else (*request)->nbytes = -1;
1317 +
1318 +/* on DEC, it is required to call aio_return to dequeue the request.
1319 +   IBM man pages don't indicate what function to use for dequeue.
1320 +   I'm assuming it is aio_return! POSIX says aio_return may be called 
1321 +   only once on a given handle. */
1322 +
1323 +       if (err == -1) {
1324 +#ifdef MPICH2
1325 +           *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
1326 +               "**io %s", strerror(errno));
1327 +           return;
1328 +#elif defined(PRINT_ERR_MSG)
1329 +                       *error_code = MPI_ERR_UNKNOWN;
1330 +#else /* MPICH-1 */
1331 +           *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
1332 +             myname, "I/O Error", "%s", strerror(errno));
1333 +           ADIOI_Error((*request)->fd, *error_code, myname);       
1334 +#endif
1335 +       }
1336 +       else *error_code = MPI_SUCCESS;
1337 +    } /* if ((*request)->queued)  */
1338 +    else *error_code = MPI_SUCCESS;
1339 +
1340 +#ifdef HAVE_STATUS_SET_BYTES
1341 +    if ((*request)->nbytes != -1)
1342 +       MPIR_Status_set_bytes(status, (*request)->datatype, (*request)->nbytes);
1343 +#endif
1344 +
1345 +#elif (!defined(NO_AIO) && !defined(AIO_SUN))
1346 +/* DEC, SGI IRIX 5 and 6 */
1347 +    if ((*request)->queued) {
1348 +       do {
1349 +           err = aio_suspend((const aiocb_t **) &((*request)->handle), 1, 0);
1350 +       } while ((err == -1) && (errno == EINTR));
1351 +
1352 +       if (err != -1) {
1353 +           err = aio_return((struct aiocb *) (*request)->handle); 
1354 +           (*request)->nbytes = err;
1355 +           errno = aio_error((struct aiocb *) (*request)->handle);
1356 +       }
1357 +       else (*request)->nbytes = -1;
1358 +
1359 +       if (err == -1) {
1360 +#ifdef MPICH2
1361 +           *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
1362 +               "**io %s", strerror(errno));
1363 +           return;
1364 +#elif defined(PRINT_ERR_MSG)
1365 +                       *error_code = MPI_ERR_UNKNOWN;
1366 +#else /* MPICH-1 */
1367 +           *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
1368 +                           myname, "I/O Error", "%s", strerror(errno));
1369 +           ADIOI_Error((*request)->fd, *error_code, myname);       
1370 +#endif
1371 +       }
1372 +       else *error_code = MPI_SUCCESS;
1373 +    } /* if ((*request)->queued) */
1374 +    else *error_code = MPI_SUCCESS;
1375 +#ifdef HAVE_STATUS_SET_BYTES
1376 +    if ((*request)->nbytes != -1)
1377 +       MPIR_Status_set_bytes(status, (*request)->datatype, (*request)->nbytes);
1378 +#endif
1379 +#endif
1380 +
1381 +#ifndef NO_AIO
1382 +    if ((*request)->queued != -1) {
1383 +
1384 +       /* queued = -1 is an internal hack used when the request must
1385 +          be completed, but the request object should not be
1386 +          freed. This is used in ADIOI_Complete_async, because the user
1387 +          will call MPI_Wait later, which would require status to
1388 +          be filled. Ugly but works. queued = -1 should be used only
1389 +          in ADIOI_Complete_async. 
1390 +           This should not affect the user in any way. */
1391 +
1392 +       /* if request is still queued in the system, it is also there
1393 +           on ADIOI_Async_list. Delete it from there. */
1394 +       if ((*request)->queued) ADIOI_Del_req_from_list(request);
1395 +
1396 +       (*request)->fd->async_count--;
1397 +       if ((*request)->handle) ADIOI_Free((*request)->handle);
1398 +       ADIOI_Free_request((ADIOI_Req_node *) (*request));
1399 +       *request = ADIO_REQUEST_NULL;
1400 +    }
1401 +
1402 +#else
1403 +/* HP, FreeBSD, Linux */
1404 +
1405 +#ifdef HAVE_STATUS_SET_BYTES
1406 +    MPIR_Status_set_bytes(status, (*request)->datatype, (*request)->nbytes);
1407 +#endif
1408 +    (*request)->fd->async_count--;
1409 +    ADIOI_Free_request((ADIOI_Req_node *) (*request));
1410 +    *request = ADIO_REQUEST_NULL;
1411 +    *error_code = MPI_SUCCESS;
1412 +#endif    
1413 +}
1414 +
1415 +
1416 +void ADIOI_LUSTRE_WriteComplete(ADIO_Request *request, ADIO_Status *status, int *error_code)  
1417 +{
1418 +    ADIOI_LUSTRE_ReadComplete(request, status, error_code);
1419 +}
1420 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_wrcoll.c mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_wrcoll.c
1421 --- mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_wrcoll.c 1969-12-31 19:00:00.000000000 -0500
1422 +++ mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_wrcoll.c 2005-12-06 11:54:37.914126794 -0500
1423 @@ -0,0 +1,18 @@
1424 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
1425 +/* 
1426 + *   $Id: ad_lustre_wrcoll.c,v 1.1.1.1 2004/11/04 11:03:38 liam Exp $    
1427 + *
1428 + *   Copyright (C) 1997 University of Chicago. 
1429 + *   See COPYRIGHT notice in top-level directory.
1430 + */
1431 +
1432 +#include "ad_lustre.h"
1433 +
1434 +void ADIOI_LUSTRE_WriteStridedColl(ADIO_File fd, void *buf, int count,
1435 +                       MPI_Datatype datatype, int file_ptr_type,
1436 +                       ADIO_Offset offset, ADIO_Status *status, int
1437 +                       *error_code)
1438 +{
1439 +    ADIOI_GEN_WriteStridedColl(fd, buf, count, datatype, file_ptr_type,
1440 +                             offset, status, error_code);
1441 +}
1442 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_write.c mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_write.c
1443 --- mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_write.c  1969-12-31 19:00:00.000000000 -0500
1444 +++ mpich-1.2.6/romio/adio/ad_lustre/ad_lustre_write.c  2005-12-06 11:54:37.914126794 -0500
1445 @@ -0,0 +1,66 @@
1446 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
1447 +/* 
1448 + *   $Id: ad_lustre_write.c,v 1.1.1.1 2004/11/04 11:03:38 liam Exp $    
1449 + *
1450 + *   Copyright (C) 1997 University of Chicago. 
1451 + *   See COPYRIGHT notice in top-level directory.
1452 + */
1453 +
1454 +#include "ad_lustre.h"
1455 +
1456 +void ADIOI_LUSTRE_WriteContig(ADIO_File fd, void *buf, int count, 
1457 +                   MPI_Datatype datatype, int file_ptr_type,
1458 +                  ADIO_Offset offset, ADIO_Status *status, int *error_code)
1459 +{
1460 +    int err=-1, datatype_size, len;
1461 +#if defined(MPICH2) || !defined(PRINT_ERR_MSG)
1462 +    static char myname[] = "ADIOI_LUSTRE_WRITECONTIG";
1463 +#endif
1464 +
1465 +    MPI_Type_size(datatype, &datatype_size);
1466 +    len = datatype_size * count;
1467 +
1468 +    if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
1469 +       if (fd->fp_sys_posn != offset)
1470 +           lseek(fd->fd_sys, offset, SEEK_SET);
1471 +       err = write(fd->fd_sys, buf, len);
1472 +       fd->fp_sys_posn = offset + err;
1473 +       /* individual file pointer not updated */        
1474 +    }
1475 +    else { /* write from curr. location of ind. file pointer */
1476 +       if (fd->fp_sys_posn != fd->fp_ind)
1477 +           lseek(fd->fd_sys, fd->fp_ind, SEEK_SET);
1478 +       err = write(fd->fd_sys, buf, len);
1479 +       fd->fp_ind += err;
1480 +       fd->fp_sys_posn = fd->fp_ind;
1481 +    }
1482 +
1483 +#ifdef HAVE_STATUS_SET_BYTES
1484 +    if (err != -1 && status) MPIR_Status_set_bytes(status, datatype, err);
1485 +#endif
1486 +
1487 +    if (err == -1) {
1488 +#ifdef MPICH2
1489 +       *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
1490 +           "**io %s", strerror(errno));
1491 +#elif defined(PRINT_ERR_MSG)
1492 +                       *error_code = MPI_ERR_UNKNOWN;
1493 +#else
1494 +       *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
1495 +                             myname, "I/O Error", "%s", strerror(errno));
1496 +       ADIOI_Error(fd, *error_code, myname);
1497 +#endif
1498 +    }
1499 +    else *error_code = MPI_SUCCESS;
1500 +}
1501 +
1502 +
1503 +
1504 +void ADIOI_LUSTRE_WriteStrided(ADIO_File fd, void *buf, int count,
1505 +                       MPI_Datatype datatype, int file_ptr_type,
1506 +                       ADIO_Offset offset, ADIO_Status *status, int
1507 +                       *error_code)
1508 +{
1509 +    ADIOI_GEN_WriteStrided(fd, buf, count, datatype, file_ptr_type,
1510 +                        offset, status, error_code);
1511 +}
1512 diff -r -u --new-file mpich-1.2.6/romio/adio/ad_lustre/Makefile.in mpich-1.2.6/romio/adio/ad_lustre/Makefile.in
1513 --- mpich-1.2.6/romio/adio/ad_lustre/Makefile.in        1969-12-31 19:00:00.000000000 -0500
1514 +++ mpich-1.2.6/romio/adio/ad_lustre/Makefile.in        2005-12-06 11:54:37.883130927 -0500
1515 @@ -0,0 +1,47 @@
1516 +CC          = @CC@
1517 +AR          = @AR@
1518 +LIBNAME     = @LIBNAME@
1519 +srcdir      = @srcdir@
1520 +CC_SHL      = @CC_SHL@
1521 +SHLIBNAME   = @SHLIBNAME@
1522 +
1523 +INCLUDE_DIR = -I@MPI_INCLUDE_DIR@ -I${srcdir}/../include -I../include
1524 +CFLAGS      = @CFLAGS@ $(INCLUDE_DIR)
1525 +
1526 +C_COMPILE_SHL = $(CC_SHL) @CFLAGS@ $(INCLUDE_DIR)
1527 +
1528 +@VPATH@
1529 +
1530 +AD_LUSTRE_OBJECTS = ad_lustre_close.o ad_lustre_read.o \
1531 +      ad_lustre_open.o ad_lustre_write.o ad_lustre_done.o \
1532 +      ad_lustre_fcntl.o ad_lustre_iread.o ad_lustre_iwrite.o ad_lustre_wait.o \
1533 +      ad_lustre_resize.o ad_lustre_hints.o \
1534 +      ad_lustre.o
1535 +
1536 +
1537 +default: $(LIBNAME)
1538 +       @if [ "@ENABLE_SHLIB@" != "none" ] ; then \
1539 +           $(MAKE) $(SHLIBNAME).la ;\
1540 +       fi
1541 +
1542 +.SUFFIXES: $(SUFFIXES) .p .lo
1543 +
1544 +.c.o:
1545 +       $(CC) $(CFLAGS) -c $<
1546 +.c.lo:
1547 +       $(C_COMPILE_SHL) -c $<
1548 +       @mv -f $*.o $*.lo
1549 +
1550 +$(LIBNAME): $(AD_LUSTRE_OBJECTS)
1551 +       $(AR) $(LIBNAME) $(AD_LUSTRE_OBJECTS)
1552 +
1553 +AD_LUSTRE_LOOBJECTS=$(AD_LUSTRE_OBJECTS:.o=.lo)
1554 +$(SHLIBNAME).la: $(AD_LUSTRE_LOOBJECTS)
1555 +       $(AR) $(SHLIBNAME).la $(AD_LUSTRE_LOOBJECTS)
1556 +
1557 +coverage:
1558 +       -@for file in  ${AD_LUSTRE_OBJECTS:.o=.c} ; do \
1559 +               gcov -b -f $$file ; done
1560 +
1561 +clean:
1562 +       @rm -f *.o *.lo
1563 --- mpich-1.2.6/romio/Makefile.in       2004-01-27 18:27:35.000000000 -0500
1564 +++ mpich-1.2.6/romio/Makefile.in       2005-12-06 11:54:38.000000000 -0500
1565 @@ -14,7 +14,7 @@ DIRS        = mpi-io adio/common
1566  MPIO_DIRS   = mpi-io
1567  EXTRA_SRC_DIRS = @EXTRA_SRC_DIRS@
1568  FILE_SYS_DIRS = @FILE_SYS_DIRS@
1569 -ALL_DIRS    = mpi-io mpi-io/fortran mpi2-other/info mpi2-other/info/fortran mpi2-other/array mpi2-other/array/fortran adio/common adio/ad_pfs adio/ad_piofs adio/ad_nfs adio/ad_ufs adio/ad_xfs adio/ad_hfs adio/ad_sfs adio/ad_testfs adio/ad_pvfs adio/ad_pvfs2 test
1570 +ALL_DIRS    = mpi-io mpi-io/fortran mpi2-other/info mpi2-other/info/fortran mpi2-other/array mpi2-other/array/fortran adio/common adio/ad_pfs adio/ad_piofs adio/ad_nfs adio/ad_ufs adio/ad_xfs adio/ad_hfs adio/ad_sfs adio/ad_testfs adio/ad_pvfs adio/ad_pvfs2 adio/ad_lustre test
1571  SHELL       = /bin/sh
1572  
1573  @VPATH@
1574 --- mpich-1.2.6/romio/configure.in      2004-08-02 09:37:31.000000000 -0400
1575 +++ mpich-1.2.6/romio/configure.in      2005-12-06 11:54:38.000000000 -0500
1576 @@ -90,7 +90,7 @@ MPIO_REQ_REAL_POBJECTS="_iotest.o _iowai
1577  #
1578  have_aio=no
1579  #
1580 -known_filesystems="nfs ufs pfs piofs pvfs pvfs2 testfs xfs hfs sfs"
1581 +known_filesystems="nfs ufs pfs piofs pvfs pvfs2 testfs xfs hfs sfs lustre"
1582  known_mpi_impls="mpich_mpi sgi_mpi hp_mpi cray_mpi lam_mpi"
1583  #
1584  # Defaults
1585 @@ -1270,6 +1270,9 @@ fi
1586  if test -n "$file_system_testfs"; then
1587      AC_DEFINE(ROMIO_TESTFS,1,[Define for TESTFS])
1588  fi
1589 +if test -n "$file_system_lustre"; then
1590 +    AC_DEFINE(ROMIO_LUSTRE,1,[Define for LUSTRE])
1591 +fi
1592  if test -n "$file_system_piofs"; then
1593      AC_DEFINE(PIOFS,1,[Define for PIOFS])
1594      USER_CFLAGS="$USER_CFLAGS -bI:/usr/include/piofs/piofs.exp"
1595 @@ -1634,7 +1637,7 @@ AC_OUTPUT(Makefile localdefs mpi-io/Make
1596                    adio/ad_nfs/Makefile adio/ad_ufs/Makefile \
1597                    adio/ad_xfs/Makefile adio/ad_hfs/Makefile \
1598                    adio/ad_sfs/Makefile adio/ad_pfs/Makefile \
1599 -                  adio/ad_testfs/Makefile adio/ad_pvfs/Makefile \
1600 +                  adio/ad_testfs/Makefile adio/ad_lustre/Makefile adio/ad_pvfs/Makefile \
1601                    adio/ad_pvfs2/Makefile adio/ad_piofs/Makefile \
1602                     mpi-io/fortran/Makefile mpi2-other/info/fortran/Makefile \
1603                     mpi2-other/array/fortran/Makefile test/fmisc.f \
1604 --- mpich-1.2.6/romio/configure 2004-08-04 12:08:28.000000000 -0400
1605 +++ mpich-1.2.6/romio/configure 2005-12-06 11:54:38.000000000 -0500
1606 @@ -623,7 +623,7 @@ MPIO_REQ_REAL_POBJECTS="_iotest.o _iowai
1607  #
1608  have_aio=no
1609  #
1610 -known_filesystems="nfs ufs pfs piofs pvfs pvfs2 testfs xfs hfs sfs"
1611 +known_filesystems="nfs ufs pfs piofs pvfs pvfs2 testfs lustre xfs hfs sfs"
1612  known_mpi_impls="mpich_mpi sgi_mpi hp_mpi cray_mpi lam_mpi"
1613  #
1614  # Defaults
1615 @@ -4022,6 +4022,13 @@ if test -n "$file_system_testfs"; then
1616  EOF
1617  
1618  fi
1619 +if test -n "$file_system_lustre"; then
1620 +    cat >> confdefs.h <<\EOF
1621 +#define LUSTRE 1
1622 +EOF
1623 +
1624 +fi
1625 +
1626  if test -n "$file_system_piofs"; then
1627      cat >> confdefs.h <<\EOF
1628  #define PIOFS 1
1629 @@ -4746,7 +4753,7 @@ trap 'rm -fr `echo "Makefile localdefs m
1630                    adio/ad_xfs/Makefile adio/ad_hfs/Makefile \
1631                    adio/ad_sfs/Makefile adio/ad_pfs/Makefile \
1632                    adio/ad_testfs/Makefile adio/ad_pvfs/Makefile \
1633 -                  adio/ad_pvfs2/Makefile adio/ad_piofs/Makefile \
1634 +                  adio/ad_pvfs2/Makefile adio/ad_piofs/Makefile adio/ad_lustre/Makefile\
1635                     mpi-io/fortran/Makefile mpi2-other/info/fortran/Makefile \
1636                     mpi2-other/array/fortran/Makefile test/fmisc.f \
1637                     test/fcoll_test.f test/pfcoll_test.f test/fperf.f  adio/include/romioconf.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
1638 @@ -4912,7 +4919,7 @@ CONFIG_FILES=\${CONFIG_FILES-"Makefile l
1639                    adio/ad_nfs/Makefile adio/ad_ufs/Makefile \
1640                    adio/ad_xfs/Makefile adio/ad_hfs/Makefile \
1641                    adio/ad_sfs/Makefile adio/ad_pfs/Makefile \
1642 -                  adio/ad_testfs/Makefile adio/ad_pvfs/Makefile \
1643 +                  adio/ad_testfs/Makefile adio/ad_lustre/Makefile adio/ad_pvfs/Makefile \
1644                    adio/ad_pvfs2/Makefile adio/ad_piofs/Makefile \
1645                     mpi-io/fortran/Makefile mpi2-other/info/fortran/Makefile \
1646                     mpi2-other/array/fortran/Makefile test/fmisc.f \
1647 --- mpich-1.2.6/romio/adio/include/romioconf.h.in       2004-08-04 12:08:28.000000000 -0400
1648 +++ mpich-1.2.6/romio/adio/include/romioconf.h.in       2005-12-06 11:54:38.000000000 -0500
1649 @@ -192,6 +192,9 @@
1650  /* Define for TESTFS */
1651  #undef ROMIO_TESTFS
1652  
1653 +/* Define for LUSTRE */
1654 +#undef LUSTRE
1655 +
1656  /* Define for PIOFS */
1657  #undef PIOFS
1658  
1659 --- mpich-1.2.6/romio/adio/include/mpio_error.h 2002-11-15 11:26:23.000000000 -0500
1660 +++ mpich-1.2.6/romio/adio/include/mpio_error.h 2005-12-06 11:54:38.000000000 -0500
1661 @@ -62,6 +62,7 @@
1662  #define MPIR_ERR_FILETYPE 33 
1663  #define MPIR_ERR_NO_NTFS 35
1664  #define MPIR_ERR_NO_TESTFS 36
1665 +#define MPIR_ERR_NO_LUSTRE 37
1666  
1667  /* MPI_ERR_COMM */
1668  #ifndef MPIR_ERR_COMM_NULL
1669 --- mpich-1.2.6/romio/adio/include/adioi_fs_proto.h     2003-06-24 18:48:23.000000000 -0400
1670 +++ mpich-1.2.6/romio/adio/include/adioi_fs_proto.h     2005-12-06 11:54:38.000000000 -0500
1671 @@ -261,6 +261,68 @@ ADIO_Offset ADIOI_UFS_SeekIndividual(ADI
1672  void ADIOI_UFS_SetInfo(ADIO_File fd, MPI_Info users_info, int *error_code);
1673  #endif
1674  
1675 +#ifdef LUSTRE
1676 +extern struct ADIOI_Fns_struct ADIO_LUSTRE_operations;
1677 +
1678 +void ADIOI_LUSTRE_Open(ADIO_File fd, int *error_code);
1679 +void ADIOI_LUSTRE_Close(ADIO_File fd, int *error_code);
1680 +void ADIOI_LUSTRE_ReadContig(ADIO_File fd, void *buf, int count, 
1681 +                      MPI_Datatype datatype, int file_ptr_type,
1682 +                     ADIO_Offset offset, ADIO_Status *status, int
1683 +                    *error_code);
1684 +void ADIOI_LUSTRE_WriteContig(ADIO_File fd, void *buf, int count, 
1685 +                      MPI_Datatype datatype, int file_ptr_type,
1686 +                      ADIO_Offset offset, ADIO_Status *status, int
1687 +                     *error_code);   
1688 +void ADIOI_LUSTRE_IwriteContig(ADIO_File fd, void *buf, int count, 
1689 +                      MPI_Datatype datatype, int file_ptr_type,
1690 +                      ADIO_Offset offset, ADIO_Request *request, int
1691 +                     *error_code);   
1692 +void ADIOI_LUSTRE_IreadContig(ADIO_File fd, void *buf, int count, 
1693 +                      MPI_Datatype datatype, int file_ptr_type,
1694 +                      ADIO_Offset offset, ADIO_Request *request, int
1695 +                     *error_code);   
1696 +int ADIOI_LUSTRE_ReadDone(ADIO_Request *request, ADIO_Status *status, int
1697 +                      *error_code);
1698 +int ADIOI_LUSTRE_WriteDone(ADIO_Request *request, ADIO_Status *status, int
1699 +                      *error_code);
1700 +void ADIOI_LUSTRE_ReadComplete(ADIO_Request *request, ADIO_Status *status, int
1701 +                      *error_code); 
1702 +void ADIOI_LUSTRE_WriteComplete(ADIO_Request *request, ADIO_Status *status,
1703 +                       int *error_code); 
1704 +void ADIOI_LUSTRE_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct, int
1705 +               *error_code); 
1706 +void ADIOI_LUSTRE_WriteStrided(ADIO_File fd, void *buf, int count,
1707 +                      MPI_Datatype datatype, int file_ptr_type,
1708 +                      ADIO_Offset offset, ADIO_Status *status, int
1709 +                      *error_code);
1710 +void ADIOI_LUSTRE_ReadStrided(ADIO_File fd, void *buf, int count,
1711 +                      MPI_Datatype datatype, int file_ptr_type,
1712 +                      ADIO_Offset offset, ADIO_Status *status, int
1713 +                      *error_code);
1714 +void ADIOI_LUSTRE_WriteStridedColl(ADIO_File fd, void *buf, int count,
1715 +                      MPI_Datatype datatype, int file_ptr_type,
1716 +                      ADIO_Offset offset, ADIO_Status *status, int
1717 +                      *error_code);
1718 +void ADIOI_LUSTRE_ReadStridedColl(ADIO_File fd, void *buf, int count,
1719 +                      MPI_Datatype datatype, int file_ptr_type,
1720 +                      ADIO_Offset offset, ADIO_Status *status, int
1721 +                      *error_code);
1722 +void ADIOI_LUSTRE_IreadStrided(ADIO_File fd, void *buf, int count,
1723 +                      MPI_Datatype datatype, int file_ptr_type,
1724 +                      ADIO_Offset offset, ADIO_Request *request, int
1725 +                      *error_code);
1726 +void ADIOI_LUSTRE_IwriteStrided(ADIO_File fd, void *buf, int count,
1727 +                      MPI_Datatype datatype, int file_ptr_type,
1728 +                      ADIO_Offset offset, ADIO_Request *request, int
1729 +                      *error_code);
1730 +void ADIOI_LUSTRE_Flush(ADIO_File fd, int *error_code);
1731 +void ADIOI_LUSTRE_Resize(ADIO_File fd, ADIO_Offset size, int *error_code);
1732 +ADIO_Offset ADIOI_LUSTRE_SeekIndividual(ADIO_File fd, ADIO_Offset offset, 
1733 +                       int whence, int *error_code);
1734 +void ADIOI_LUSTRE_SetInfo(ADIO_File fd, MPI_Info users_info, int *error_code);
1735 +#endif
1736 +
1737  #ifdef ROMIO_NTFS
1738  extern struct ADIOI_Fns_struct ADIO_NTFS_operations;
1739  
1740 --- mpich-1.2.6/romio/adio/include/adio.h       2004-06-07 13:59:57.000000000 -0400
1741 +++ mpich-1.2.6/romio/adio/include/adio.h       2005-12-06 11:54:38.000000000 -0500
1742 @@ -276,6 +276,7 @@ typedef struct {
1743  #define ADIO_NTFS                158   /* NTFS for Windows NT */
1744  #define ADIO_TESTFS              159   /* fake file system for testing */
1745  #define ADIO_PVFS2               160   /* PVFS2: 2nd generation PVFS */
1746 +#define ADIO_LUSTRE              161   /* Lustre */
1747  
1748  #define ADIO_SEEK_SET            SEEK_SET
1749  #define ADIO_SEEK_CUR            SEEK_CUR
1750 --- mpich-1.2.6/romio/adio/common/setfn.c       2003-06-24 18:48:18.000000000 -0400
1751 +++ mpich-1.2.6/romio/adio/common/setfn.c       2005-12-06 11:54:38.000000000 -0500
1752 @@ -114,6 +114,16 @@ void ADIOI_SetFunctions(ADIO_File fd)
1753  #endif
1754         break;
1755  
1756 +    case ADIO_LUSTRE:
1757 +#ifdef LUSTRE 
1758 +        *(fd->fns) = ADIO_LUSTRE_operations;
1759 +#else   
1760 +        FPRINTF(stderr, "ADIOI_SetFunctions: ROMIO has not been configured to use the LUSTRE file system\n");
1761 +        MPI_Abort(MPI_COMM_WORLD, 1);
1762 +#endif 
1763 +        break;
1764 +
1765 +
1766      default:
1767         FPRINTF(stderr, "ADIOI_SetFunctions: Unsupported file system type\n");
1768          MPI_Abort(MPI_COMM_WORLD, 1);
1769 --- mpich-1.2.6/romio/adio/common/ad_fstype.c   2003-09-04 16:24:44.000000000 -0400
1770 +++ mpich-1.2.6/romio/adio/common/ad_fstype.c   2005-12-06 11:54:38.000000000 -0500
1771 @@ -204,6 +204,11 @@ static void ADIO_FileSysType_fncall(char
1772         }
1773      }
1774  #elif defined(LINUX)
1775 +#warning use correct include
1776 +# if defined (LUSTRE)
1777 +#define LL_SUPER_MAGIC 0x0BD00BD0
1778 +# endif
1779 +
1780      do {
1781         err = statfs(filename, &fsbuf);
1782      } while (err && (errno == ESTALE));
1783 @@ -218,6 +223,9 @@ static void ADIO_FileSysType_fncall(char
1784      else {
1785         /* FPRINTF(stderr, "%d\n", fsbuf.f_type);*/
1786         if (fsbuf.f_type == NFS_SUPER_MAGIC) *fstype = ADIO_NFS;
1787 +# if defined (LUSTRE)
1788 +       else if (fsbuf.f_type == LL_SUPER_MAGIC) *fstype = ADIO_LUSTRE;
1789 +#endif
1790  # if defined(ROMIO_PVFS)
1791         else if (fsbuf.f_type == PVFS_SUPER_MAGIC) *fstype = ADIO_PVFS;
1792  # endif
1793 @@ -359,6 +367,11 @@ static void ADIO_FileSysType_prefix(char
1794      {
1795         *fstype = ADIO_TESTFS;
1796      }
1797 +    else if (!strncmp(filename, "lustre:", 7) 
1798 +            || !strncmp(filename, "LUSTRE:", 7))
1799 +    {
1800 +       *fstype = ADIO_LUSTRE;
1801 +    }
1802      else {
1803  #ifdef ROMIO_NTFS
1804         *fstype = ADIO_NTFS;
1805 @@ -644,6 +657,24 @@ void ADIO_ResolveFileType(MPI_Comm comm,
1806         *ops = &ADIO_TESTFS_operations;
1807  #endif
1808      }
1809 +    if (file_system == ADIO_LUSTRE) {
1810 +#ifndef LUSTRE 
1811 +# ifdef MPICH2
1812 +       *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**iofstypeunsupported", 0);
1813 +       return;
1814 +# elif defined(PRINT_ERR_MSG)
1815 +       FPRINTF(stderr, "ADIO_ResolveFileType: ROMIO has not been configured to use the LUSTRE file system\n");
1816 +       MPI_Abort(MPI_COMM_WORLD, 1);
1817 +# else /* MPICH-1 */
1818 +       myerrcode = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ERR_NO_LUSTRE,
1819 +                                    myname, (char *) 0, (char *) 0);
1820 +       *error_code = ADIOI_Error(MPI_FILE_NULL, myerrcode, myname);
1821 +# endif
1822 +       return;
1823 +#else
1824 +       *ops = &ADIO_LUSTRE_operations;
1825 +#endif
1826 +    }
1827      *error_code = MPI_SUCCESS;
1828      *fstype = file_system;
1829      return;