Whamcloud - gitweb
b=21760 start bulk unregistering at the same time as reply unlink
[fs/lustre-release.git] / lustre / contrib / adio-lustre-mpich2-v03.patch
1 diff -ruNp romio-orig/adio/ad_lustre/ad_lustre.c romio-ornl/adio/ad_lustre/ad_lustre.c
2 --- romio-orig/adio/ad_lustre/ad_lustre.c       1969-12-31 19:00:00.000000000 -0500
3 +++ romio-ornl/adio/ad_lustre/ad_lustre.c       2007-11-10 07:13:32.554840000 -0500
4 @@ -0,0 +1,34 @@
5 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
6 +/* 
7 + *   Copyright (C) 2001 University of Chicago. 
8 + *   See COPYRIGHT notice in top-level directory.
9 + *
10 + *   Copyright (C) 2007 Oak Ridge National Laboratory
11 + */
12 +
13 +#include "ad_lustre.h"
14 +
15 +struct ADIOI_Fns_struct ADIO_LUSTRE_operations = {
16 +    ADIOI_LUSTRE_Open, /* Open */
17 +    ADIOI_LUSTRE_ReadContig, /* ReadContig */
18 +    ADIOI_LUSTRE_WriteContig, /* WriteContig */
19 +    ADIOI_LUSTRE_ReadStridedColl, /* ReadStridedColl */
20 +    ADIOI_LUSTRE_WriteStridedColl, /* WriteStridedColl */
21 +    ADIOI_GEN_SeekIndividual, /* SeekIndividual */
22 +    ADIOI_LUSTRE_Fcntl, /* Fcntl */
23 +    ADIOI_LUSTRE_SetInfo, /* SetInfo */
24 +    ADIOI_GEN_ReadStrided, /* ReadStrided */
25 +    ADIOI_GEN_WriteStrided, /* WriteStrided */
26 +    ADIOI_LUSTRE_Close, /* Close */
27 +    ADIOI_GEN_IreadContig, /* IreadContig */
28 +    ADIOI_GEN_IwriteContig, /* IwriteContig */
29 +    ADIOI_GEN_IODone, /* ReadDone */
30 +    ADIOI_GEN_IODone, /* WriteDone */
31 +    ADIOI_GEN_IOComplete, /* ReadComplete */
32 +    ADIOI_GEN_IOComplete, /* WriteComplete */
33 +    ADIOI_GEN_IreadStrided, /* IreadStrided */
34 +    ADIOI_GEN_IwriteStrided, /* IwriteStrided */
35 +    ADIOI_GEN_Flush, /* Flush */
36 +    ADIOI_GEN_Resize, /* Resize */
37 +    ADIOI_GEN_Delete, /* Delete */
38 +};
39 diff -ruNp romio-orig/adio/ad_lustre/ad_lustre_close.c romio-ornl/adio/ad_lustre/ad_lustre_close.c
40 --- romio-orig/adio/ad_lustre/ad_lustre_close.c 1969-12-31 19:00:00.000000000 -0500
41 +++ romio-ornl/adio/ad_lustre/ad_lustre_close.c 2007-11-10 07:13:32.557840000 -0500
42 @@ -0,0 +1,40 @@
43 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
44 +/* 
45 + *
46 + *   Copyright (C) 1997 University of Chicago. 
47 + *   See COPYRIGHT notice in top-level directory.
48 + *
49 + *   Copyright (C) 2007 Oak Ridge National Laboratory
50 + */
51 +
52 +#include "ad_lustre.h"
53 +
54 +#ifdef PROFILE
55 +#include "mpe.h"
56 +#endif
57 +
58 +void ADIOI_LUSTRE_Close(ADIO_File fd, int *error_code)
59 +{
60 +    int err, derr=0;
61 +    static char myname[] = "ADIOI_LUSTRE_CLOSE";
62 +
63 +#ifdef PROFILE
64 +    MPE_Log_event(9, 0, "start close");
65 +#endif
66 +
67 +    err = close(fd->fd_sys);
68 +
69 +#ifdef PROFILE
70 +    MPE_Log_event(10, 0, "end close");
71 +#endif
72 +
73 +    fd->fd_sys    = -1;
74 +
75 +    if (err == -1 || derr == -1) {
76 +       *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
77 +                                          myname, __LINE__, MPI_ERR_IO,
78 +                                          "**io",
79 +                                          "**io %s", strerror(errno));
80 +    }
81 +    else *error_code = MPI_SUCCESS;
82 +}
83 diff -ruNp romio-orig/adio/ad_lustre/ad_lustre_fcntl.c romio-ornl/adio/ad_lustre/ad_lustre_fcntl.c
84 --- romio-orig/adio/ad_lustre/ad_lustre_fcntl.c 1969-12-31 19:00:00.000000000 -0500
85 +++ romio-ornl/adio/ad_lustre/ad_lustre_fcntl.c 2007-11-10 07:13:32.561833000 -0500
86 @@ -0,0 +1,97 @@
87 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
88 +/* 
89 + *   Copyright (C) 1997 University of Chicago. 
90 + *   See COPYRIGHT notice in top-level directory.
91 + *
92 + *   Copyright (C) 2007 Oak Ridge National Laboratory
93 + */
94 +
95 +#include "ad_lustre.h"
96 +#include "adio_extern.h"
97 +
98 +void ADIOI_LUSTRE_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct, int *error_code)
99 +{
100 +    int i, ntimes;
101 +    ADIO_Offset curr_fsize, alloc_size, size, len, done;
102 +    ADIO_Status status;
103 +    char *buf;
104 +#if defined(MPICH2) || !defined(PRINT_ERR_MSG)
105 +    static char myname[] = "ADIOI_LUSTRE_FCNTL";
106 +#endif
107 +
108 +    switch(flag) {
109 +    case ADIO_FCNTL_GET_FSIZE:
110 +       fcntl_struct->fsize = lseek(fd->fd_sys, 0, SEEK_END);
111 +       if (fd->fp_sys_posn != -1) 
112 +            lseek(fd->fd_sys, fd->fp_sys_posn, SEEK_SET);
113 +       if (fcntl_struct->fsize == -1) {
114 +           *error_code = MPIR_Err_create_code(MPI_SUCCESS, 
115 +                   MPIR_ERR_RECOVERABLE, myname, __LINE__, 
116 +                   MPI_ERR_IO, "**io", "**io %s", strerror(errno));
117 +       }
118 +       else *error_code = MPI_SUCCESS;
119 +       break;
120 +
121 +    case ADIO_FCNTL_SET_DISKSPACE:
122 +       /* will be called by one process only */
123 +       /* On file systems with no preallocation function, I have to 
124 +           explicitly write 
125 +           to allocate space. Since there could be holes in the file, 
126 +           I need to read up to the current file size, write it back, 
127 +           and then write beyond that depending on how much 
128 +           preallocation is needed.
129 +           read/write in sizes of no more than ADIOI_PREALLOC_BUFSZ */
130 +
131 +       curr_fsize = lseek(fd->fd_sys, 0, SEEK_END);
132 +       alloc_size = fcntl_struct->diskspace;
133 +
134 +       size = ADIOI_MIN(curr_fsize, alloc_size);
135 +       
136 +       ntimes = (size + ADIOI_PREALLOC_BUFSZ - 1)/ADIOI_PREALLOC_BUFSZ;
137 +       buf = (char *) ADIOI_Malloc(ADIOI_PREALLOC_BUFSZ);
138 +       done = 0;
139 +
140 +       for (i=0; i<ntimes; i++) {
141 +           len = ADIOI_MIN(size-done, ADIOI_PREALLOC_BUFSZ);
142 +           ADIO_ReadContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET, done,
143 +                           &status, error_code);
144 +           if (*error_code != MPI_SUCCESS) {
145 +               *error_code = MPIR_Err_create_code(MPI_SUCCESS, 
146 +                       MPIR_ERR_RECOVERABLE, myname, __LINE__, 
147 +                       MPI_ERR_IO, "**io", "**io %s", strerror(errno));
148 +                return;  
149 +           }
150 +           ADIO_WriteContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET, 
151 +                             done, &status, error_code);
152 +           if (*error_code != MPI_SUCCESS) return;
153 +           done += len;
154 +       }
155 +
156 +       if (alloc_size > curr_fsize) {
157 +           memset(buf, 0, ADIOI_PREALLOC_BUFSZ); 
158 +           size = alloc_size - curr_fsize;
159 +           ntimes = (size + ADIOI_PREALLOC_BUFSZ - 1)/ADIOI_PREALLOC_BUFSZ;
160 +           for (i=0; i<ntimes; i++) {
161 +               len = ADIOI_MIN(alloc_size-done, ADIOI_PREALLOC_BUFSZ);
162 +               ADIO_WriteContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET, 
163 +                                done, &status, error_code);
164 +               if (*error_code != MPI_SUCCESS) return;
165 +               done += len;  
166 +           }
167 +       }
168 +       ADIOI_Free(buf);
169 +       if (fd->fp_sys_posn != -1) 
170 +           lseek(fd->fd_sys, fd->fp_sys_posn, SEEK_SET);
171 +       *error_code = MPI_SUCCESS;
172 +       break;
173 +
174 +    case ADIO_FCNTL_SET_ATOMICITY:
175 +       fd->atomicity = (fcntl_struct->atomicity == 0) ? 0 : 1;
176 +       *error_code = MPI_SUCCESS;
177 +       break;
178 +
179 +    default:
180 +       FPRINTF(stderr, "Unknown flag passed to ADIOI_LUSTRE_Fcntl\n");
181 +       MPI_Abort(MPI_COMM_WORLD, 1);
182 +    }
183 +}
184 diff -ruNp romio-orig/adio/ad_lustre/ad_lustre.h romio-ornl/adio/ad_lustre/ad_lustre.h
185 --- romio-orig/adio/ad_lustre/ad_lustre.h       1969-12-31 19:00:00.000000000 -0500
186 +++ romio-ornl/adio/ad_lustre/ad_lustre.h       2007-11-10 07:13:32.565828000 -0500
187 @@ -0,0 +1,34 @@
188 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
189 +/* 
190 + *   Copyright (C) 1997 University of Chicago. 
191 + *   See COPYRIGHT notice in top-level directory.
192 + *
193 + *   Copyright (C) 2007 Oak Ridge National Laboratory
194 + */
195 +
196 +#ifndef AD_UNIX_INCLUDE
197 +#define AD_UNIX_INCLUDE
198 +
199 +/* temp*/
200 +#define HAVE_ASM_TYPES_H 1
201 +
202 +#include <unistd.h>
203 +#include <linux/types.h>
204 +#include <fcntl.h>
205 +#include <sys/ioctl.h>
206 +#include "lustre/lustre_user.h"
207 +#include "adio.h"
208 +/*#include "adioi.h"*/
209 +
210 +#ifdef HAVE_SIGNAL_H
211 +#include <signal.h>
212 +#endif
213 +
214 +#ifdef HAVE_AIO_H
215 +#include <aio.h>
216 +#ifdef HAVE_SYS_AIO_H
217 +#include <sys/aio.h>
218 +#endif
219 +#endif /* End of HAVE_SYS_AIO_H */
220 +
221 +#endif /* End of AD_UNIX_INCLUDE */
222 diff -ruNp romio-orig/adio/ad_lustre/ad_lustre_hints.c romio-ornl/adio/ad_lustre/ad_lustre_hints.c
223 --- romio-orig/adio/ad_lustre/ad_lustre_hints.c 1969-12-31 19:00:00.000000000 -0500
224 +++ romio-ornl/adio/ad_lustre/ad_lustre_hints.c 2007-11-10 07:13:32.569824000 -0500
225 @@ -0,0 +1,122 @@
226 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
227 +/* 
228 + *   Copyright (C) 1997 University of Chicago. 
229 + *   See COPYRIGHT notice in top-level directory.
230 + *
231 + *   Copyright (C) 2007 Oak Ridge National Laboratory
232 + */
233 +
234 +#include "ad_lustre.h"
235 +
236 +void ADIOI_LUSTRE_SetInfo(ADIO_File fd, MPI_Info users_info, int *error_code)
237 +{
238 +    char *value, *value_in_fd;
239 +    int flag, tmp_val[3], str_factor=-1, str_unit=0, start_iodev=-1;
240 +    struct lov_user_md lum = { 0 };
241 +    int err, myrank, fd_sys, perm, amode, old_mask;
242 +
243 +    if ( (fd->info) == MPI_INFO_NULL) {
244 +       /* This must be part of the open call. can set striping parameters 
245 +           if necessary. */ 
246 +       MPI_Info_create(&(fd->info));
247 +       
248 +       /* has user specified striping or server buffering parameters 
249 +           and do they have the same value on all processes? */
250 +       if (users_info != MPI_INFO_NULL) {
251 +           value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
252 +
253 +           MPI_Info_get(users_info, "striping_unit", MPI_MAX_INFO_VAL, 
254 +                        value, &flag);
255 +           if (flag) {
256 +               str_unit=atoi(value);
257 +           }
258 +
259 +           MPI_Info_get(users_info, "striping_factor", MPI_MAX_INFO_VAL, 
260 +                        value, &flag);
261 +           if (flag) {
262 +               str_factor=atoi(value);
263 +           } 
264 +
265 +           MPI_Info_get(users_info, "start_iodevice", MPI_MAX_INFO_VAL, 
266 +                        value, &flag);
267 +           if (flag) {
268 +               start_iodev=atoi(value);
269 +           }
270 +
271 +           ADIOI_Free(value);
272 +       }
273 +
274 +       MPI_Comm_rank(fd->comm, &myrank);
275 +       if (myrank == 0) {
276 +           tmp_val[0] = str_factor;
277 +           tmp_val[1] = str_unit;
278 +           tmp_val[2] = start_iodev;
279 +       }
280 +       MPI_Bcast(tmp_val, 3, MPI_INT, 0, fd->comm);
281 +
282 +       if (tmp_val[0] != str_factor 
283 +               || tmp_val[1] != str_unit 
284 +               || tmp_val[2] != start_iodev) {
285 +           FPRINTF(stderr, "ADIOI_LUSTRE_SetInfo: All keys"
286 +                   "-striping_factor:striping_unit:start_iodevice "
287 +                   "need to be identical across all processes\n");
288 +           MPI_Abort(MPI_COMM_WORLD, 1);
289 +               } else if ((str_factor > 0) || (str_unit > 0) || (start_iodev >= 0)) {
290 +            /* if user has specified striping info, process 0 tries to set it */
291 +           if (!myrank) {
292 +               if (fd->perm == ADIO_PERM_NULL) {
293 +                   old_mask = umask(022);
294 +                   umask(old_mask);
295 +                   perm = old_mask ^ 0666;
296 +               }
297 +               else perm = fd->perm;
298 +
299 +               amode = 0;
300 +               if (fd->access_mode & ADIO_CREATE)
301 +                   amode = amode | O_CREAT;
302 +               if (fd->access_mode & ADIO_RDONLY)
303 +                   amode = amode | O_RDONLY;
304 +               if (fd->access_mode & ADIO_WRONLY)
305 +                   amode = amode | O_WRONLY;
306 +               if (fd->access_mode & ADIO_RDWR)
307 +                   amode = amode | O_RDWR;
308 +               if (fd->access_mode & ADIO_EXCL)
309 +                   amode = amode | O_EXCL;
310 +
311 +               /* we need to create file so ensure this is set */
312 +               amode = amode | O_LOV_DELAY_CREATE | O_CREAT;
313 +
314 +               fd_sys = open(fd->filename, amode, perm);
315 +               if (fd_sys == -1) { 
316 +                   if (errno != EEXIST) 
317 +                       fprintf(stderr, 
318 +                               "Failure to open file %s %d %d\n",strerror(errno), amode, perm);
319 +               } else {
320 +                   lum.lmm_magic = LOV_USER_MAGIC;
321 +                   lum.lmm_pattern = 0;
322 +                   lum.lmm_stripe_size = str_unit;
323 +                   lum.lmm_stripe_count = str_factor;
324 +                   lum.lmm_stripe_offset = start_iodev;
325 +
326 +                   err = ioctl(fd_sys, LL_IOC_LOV_SETSTRIPE, &lum);
327 +                   if (err == -1 && errno != EEXIST) { 
328 +                       fprintf(stderr, "Failure to set stripe info %s \n", strerror(errno));
329 +                   }
330 +                   close(fd_sys);
331 +              }
332 +           } /* End of striping parameters validation */
333 +       }
334 +       
335 +       MPI_Barrier(fd->comm);
336 +       /* set the values for collective I/O and data sieving parameters */
337 +       ADIOI_GEN_SetInfo(fd, users_info, error_code);
338 +    } else {
339 +       /* The file has been opened previously and fd->fd_sys is a valid
340 +           file descriptor. cannot set striping parameters now. */
341 +       
342 +       /* set the values for collective I/O and data sieving parameters */
343 +       ADIOI_GEN_SetInfo(fd, users_info, error_code);
344 +    }
345
346 +    *error_code = MPI_SUCCESS;
347 +}
348 diff -ruNp romio-orig/adio/ad_lustre/ad_lustre_open.c romio-ornl/adio/ad_lustre/ad_lustre_open.c
349 --- romio-orig/adio/ad_lustre/ad_lustre_open.c  1969-12-31 19:00:00.000000000 -0500
350 +++ romio-ornl/adio/ad_lustre/ad_lustre_open.c  2007-11-10 08:22:01.202750000 -0500
351 @@ -0,0 +1,120 @@
352 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
353 +/* 
354 + *   Copyright (C) 1997 University of Chicago. 
355 + *   See COPYRIGHT notice in top-level directory.
356 + *
357 + *   Copyright (C) 2007 Oak Ridge National Laboratory
358 + */
359 +
360 +#include "ad_lustre.h"
361 +
362 +void ADIOI_LUSTRE_Open(ADIO_File fd, int *error_code)
363 +{
364 +    int perm, old_mask, amode;
365 +    struct lov_user_md lum = { 0 };
366 +    char *value;
367 +
368 +#if defined(MPICH2) || !defined(PRINT_ERR_MSG)
369 +    static char myname[] = "ADIOI_LUSTRE_OPEN";
370 +#endif
371 +
372 +    if (fd->perm == ADIO_PERM_NULL) {
373 +       old_mask = umask(022);
374 +       umask(old_mask);
375 +       perm = old_mask ^ 0666;
376 +    }
377 +    else perm = fd->perm;
378 +
379 +    amode = 0;
380 +    if (fd->access_mode & ADIO_CREATE)
381 +       amode = amode | O_CREAT;
382 +    if (fd->access_mode & ADIO_RDONLY)
383 +       amode = amode | O_RDONLY;
384 +    if (fd->access_mode & ADIO_WRONLY)
385 +       amode = amode | O_WRONLY;
386 +    if (fd->access_mode & ADIO_RDWR)
387 +       amode = amode | O_RDWR;
388 +    if (fd->access_mode & ADIO_EXCL)
389 +       amode = amode | O_EXCL;
390 +
391 +    fd->fd_sys = open(fd->filename, amode, perm);
392 +
393 +    if (fd->fd_sys != -1) {
394 +        int err;
395 +
396 +        value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
397 +
398 +        /* get file striping information and set it in info */
399 +        lum.lmm_magic = LOV_USER_MAGIC;
400 +        err = ioctl(fd->fd_sys, LL_IOC_LOV_GETSTRIPE, (void *) &lum);
401 +
402 +        if (!err) {
403 +            sprintf(value, "%d", lum.lmm_stripe_size);
404 +            MPI_Info_set(fd->info, "striping_unit", value);
405 +
406 +            sprintf(value, "%d", lum.lmm_stripe_count);
407 +            MPI_Info_set(fd->info, "striping_factor", value);
408 +
409 +            sprintf(value, "%d", lum.lmm_stripe_offset);
410 +            MPI_Info_set(fd->info, "start_iodevice", value);
411 +        }
412 +        ADIOI_Free(value);
413 +
414 +        if (fd->access_mode & ADIO_APPEND)
415 +            fd->fp_ind = fd->fp_sys_posn = lseek(fd->fd_sys, 0, SEEK_END);
416 +    }
417 +
418 +    if ((fd->fd_sys != -1) && (fd->access_mode & ADIO_APPEND))
419 +       fd->fp_ind = fd->fp_sys_posn = lseek(fd->fd_sys, 0, SEEK_END);
420 +
421 +    /* --BEGIN ERROR HANDLING-- */
422 +    if (fd->fd_sys == -1) {
423 +       if (errno == ENAMETOOLONG)
424 +           *error_code = MPIO_Err_create_code(MPI_SUCCESS,
425 +                                              MPIR_ERR_RECOVERABLE, myname,
426 +                                              __LINE__, MPI_ERR_BAD_FILE,
427 +                                              "**filenamelong",
428 +                                              "**filenamelong %s %d",
429 +                                              fd->filename,
430 +                                              strlen(fd->filename));
431 +       else if (errno == ENOENT)
432 +           *error_code = MPIO_Err_create_code(MPI_SUCCESS,
433 +                                              MPIR_ERR_RECOVERABLE, myname,
434 +                                              __LINE__, MPI_ERR_NO_SUCH_FILE,
435 +                                              "**filenoexist",
436 +                                              "**filenoexist %s",
437 +                                              fd->filename);
438 +       else if (errno == ENOTDIR || errno == ELOOP)
439 +           *error_code = MPIO_Err_create_code(MPI_SUCCESS,
440 +                                              MPIR_ERR_RECOVERABLE,
441 +                                              myname, __LINE__,
442 +                                              MPI_ERR_BAD_FILE,
443 +                                              "**filenamedir",
444 +                                              "**filenamedir %s",
445 +                                              fd->filename);
446 +       else if (errno == EACCES) {
447 +           *error_code = MPIO_Err_create_code(MPI_SUCCESS,
448 +                                              MPIR_ERR_RECOVERABLE, myname,
449 +                                              __LINE__, MPI_ERR_ACCESS,
450 +                                              "**fileaccess",
451 +                                              "**fileaccess %s", 
452 +                                              fd->filename );
453 +       }
454 +       else if (errno == EROFS) {
455 +           /* Read only file or file system and write access requested */
456 +           *error_code = MPIO_Err_create_code(MPI_SUCCESS,
457 +                                              MPIR_ERR_RECOVERABLE, myname,
458 +                                              __LINE__, MPI_ERR_READ_ONLY,
459 +                                              "**ioneedrd", 0 );
460 +       }
461 +       else {
462 +           *error_code = MPIO_Err_create_code(MPI_SUCCESS,
463 +                                              MPIR_ERR_RECOVERABLE, myname,
464 +                                              __LINE__, MPI_ERR_IO, "**io",
465 +                                              "**io %s", strerror(errno));
466 +       }
467 +    }
468 +    /* --END ERROR HANDLING-- */
469 +    else *error_code = MPI_SUCCESS;
470 +
471 +}
472 diff -ruNp romio-orig/adio/ad_lustre/ad_lustre_rdcoll.c romio-ornl/adio/ad_lustre/ad_lustre_rdcoll.c
473 --- romio-orig/adio/ad_lustre/ad_lustre_rdcoll.c        1969-12-31 19:00:00.000000000 -0500
474 +++ romio-ornl/adio/ad_lustre/ad_lustre_rdcoll.c        2007-11-10 07:13:32.577816000 -0500
475 @@ -0,0 +1,18 @@
476 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
477 +/* 
478 + *   Copyright (C) 1997 University of Chicago. 
479 + *   See COPYRIGHT notice in top-level directory.
480 + *
481 + *   Copyright (C) 2007 Oak Ridge National Laboratory
482 + */
483 +
484 +#include "ad_lustre.h"
485 +
486 +void ADIOI_LUSTRE_ReadStridedColl(ADIO_File fd, void *buf, int count,
487 +                       MPI_Datatype datatype, int file_ptr_type,
488 +                       ADIO_Offset offset, ADIO_Status *status, int
489 +                       *error_code)
490 +{
491 +    ADIOI_GEN_ReadStridedColl(fd, buf, count, datatype, file_ptr_type,
492 +                             offset, status, error_code);
493 +}
494 diff -ruNp romio-orig/adio/ad_lustre/ad_lustre_rwcontig.c romio-ornl/adio/ad_lustre/ad_lustre_rwcontig.c
495 --- romio-orig/adio/ad_lustre/ad_lustre_rwcontig.c      1969-12-31 19:00:00.000000000 -0500
496 +++ romio-ornl/adio/ad_lustre/ad_lustre_rwcontig.c      2007-11-10 07:13:32.581814000 -0500
497 @@ -0,0 +1,85 @@
498 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
499 +/* 
500 + *   Copyright (C) 1997 University of Chicago. 
501 + *   See COPYRIGHT notice in top-level directory.
502 + *
503 + *   Copyright (C) 2007 Oak Ridge National Laboratory
504 + */
505 +
506 +#include "ad_lustre.h"
507 +
508 +static void ADIOI_LUSTRE_IOContig(ADIO_File fd, void *buf, int count, 
509 +                   MPI_Datatype datatype, int file_ptr_type,
510 +                  ADIO_Offset offset, ADIO_Status *status, 
511 +                  int io_mode, int *error_code);
512 +
513 +static void ADIOI_LUSTRE_IOContig(ADIO_File fd, void *buf, int count, 
514 +                   MPI_Datatype datatype, int file_ptr_type,
515 +                  ADIO_Offset offset, ADIO_Status *status, 
516 +                  int io_mode, int *error_code)
517 +{
518 +    int err=-1, datatype_size, len;
519 +#if defined(MPICH2) || !defined(PRINT_ERR_MSG)
520 +    static char myname[] = "ADIOI_LUSTRE_IOCONTIG";
521 +#endif
522 +
523 +    MPI_Type_size(datatype, &datatype_size);
524 +    len = datatype_size * count;
525 +
526 +    if (file_ptr_type == ADIO_INDIVIDUAL) {
527 +       offset = fd->fp_ind;
528 +    }
529 +
530 +    if (fd->fp_sys_posn != offset) {
531 +       err = lseek(fd->fd_sys, offset, SEEK_SET);
532 +       if (err == -1) goto ioerr;
533 +    }
534 +    
535 +    if (io_mode)
536 +       err = write(fd->fd_sys, buf, len);
537 +    else 
538 +       err = read(fd->fd_sys, buf, len);
539 +
540 +    if (err == -1) goto ioerr;
541 +    fd->fp_sys_posn = offset + err;
542 +
543 +    if (file_ptr_type == ADIO_INDIVIDUAL) {
544 +       fd->fp_ind += err; 
545 +    }
546 +
547 +#ifdef HAVE_STATUS_SET_BYTES
548 +    if (status) MPIR_Status_set_bytes(status, datatype, err);
549 +#endif
550 +    *error_code = MPI_SUCCESS;
551 +
552 +ioerr:
553 +    /* --BEGIN ERROR HANDLING-- */
554 +    if (err == -1) {
555 +       *error_code = MPIO_Err_create_code(MPI_SUCCESS,
556 +                                          MPIR_ERR_RECOVERABLE,
557 +                                          myname, __LINE__,
558 +                                          MPI_ERR_IO, "**io",
559 +                                          "**io %s", strerror(errno));
560 +       fd->fp_sys_posn = -1;
561 +       return;
562 +    }
563 +    /* --END ERROR HANDLING-- */
564 +}
565 +
566 +void ADIOI_LUSTRE_WriteContig(ADIO_File fd, void *buf, int count, 
567 +                   MPI_Datatype datatype, int file_ptr_type,
568 +                  ADIO_Offset offset, ADIO_Status *status, int *error_code)
569 +{
570 +    ADIOI_LUSTRE_IOContig(fd, buf, count, 
571 +                   datatype, file_ptr_type,
572 +                  offset, status, 1, error_code);
573 +}
574 +
575 +void ADIOI_LUSTRE_ReadContig(ADIO_File fd, void *buf, int count, 
576 +                   MPI_Datatype datatype, int file_ptr_type,
577 +                  ADIO_Offset offset, ADIO_Status *status, int *error_code)
578 +{
579 +    ADIOI_LUSTRE_IOContig(fd, buf, count, 
580 +                   datatype, file_ptr_type,
581 +                  offset, status, 0, error_code);
582 +}
583 diff -ruNp romio-orig/adio/ad_lustre/ad_lustre_wrcoll.c romio-ornl/adio/ad_lustre/ad_lustre_wrcoll.c
584 --- romio-orig/adio/ad_lustre/ad_lustre_wrcoll.c        1969-12-31 19:00:00.000000000 -0500
585 +++ romio-ornl/adio/ad_lustre/ad_lustre_wrcoll.c        2007-11-10 07:13:32.585808000 -0500
586 @@ -0,0 +1,18 @@
587 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
588 +/* 
589 + *   Copyright (C) 1997 University of Chicago. 
590 + *   See COPYRIGHT notice in top-level directory.
591 + *
592 + *   Copyright (C) 2007 Oak Ridge National Laboratory
593 + */
594 +
595 +#include "ad_lustre.h"
596 +
597 +void ADIOI_LUSTRE_WriteStridedColl(ADIO_File fd, void *buf, int count,
598 +                       MPI_Datatype datatype, int file_ptr_type,
599 +                       ADIO_Offset offset, ADIO_Status *status, int
600 +                       *error_code)
601 +{
602 +    ADIOI_GEN_WriteStridedColl(fd, buf, count, datatype, file_ptr_type,
603 +                             offset, status, error_code);
604 +}
605 diff -ruNp romio-orig/adio/ad_lustre/Makefile.in romio-ornl/adio/ad_lustre/Makefile.in
606 --- romio-orig/adio/ad_lustre/Makefile.in       1969-12-31 19:00:00.000000000 -0500
607 +++ romio-ornl/adio/ad_lustre/Makefile.in       2007-11-10 07:13:32.589807000 -0500
608 @@ -0,0 +1,49 @@
609 +CC          = @CC@
610 +AR          = @AR@
611 +RANLIB      = @RANLIB@
612 +LIBNAME     = @LIBNAME@
613 +srcdir      = @srcdir@
614 +CC_SHL      = @CC_SHL@
615 +SHLIBNAME   = @SHLIBNAME@
616 +
617 +INCLUDE_DIR = -I@MPI_INCLUDE_DIR@ -I${srcdir}/../include -I../include -I../../include -I${srcdir}/../../../../include -I../../../../include
618 +CFLAGS      = @CPPFLAGS@ @CFLAGS@ $(INCLUDE_DIR)
619 +
620 +top_builddir  = @master_topbuild_dir@
621 +LIBTOOL       = @LIBTOOL@
622 +C_COMPILE_SHL = $(CC_SHL) @CFLAGS@ $(INCLUDE_DIR)
623 +
624 +@VPATH@
625 +
626 +AD_LUSTRE_OBJECTS = ad_lustre.o ad_lustre_open.o \
627 +      ad_lustre_rwcontig.o \
628 +      ad_lustre_wrcoll.o ad_lustre_rdcoll.o  \
629 +      ad_lustre_fcntl.o ad_lustre_hints.o ad_lustre_close.o
630 +
631 +default: $(LIBNAME)
632 +       @if [ "@ENABLE_SHLIB@" != "none" ] ; then \
633 +           $(MAKE) $(SHLIBNAME).la ;\
634 +       fi
635 +
636 +.SUFFIXES: $(SUFFIXES) .p .lo
637 +
638 +.c.o:
639 +       $(CC) $(CFLAGS) -c $<
640 +.c.lo:
641 +       $(C_COMPILE_SHL) -c $< -o _s$*.o
642 +       @mv -f _s$*.o $*.lo
643 +
644 +$(LIBNAME): $(AD_LUSTRE_OBJECTS)
645 +       $(AR) $(LIBNAME) $(AD_LUSTRE_OBJECTS)
646 +       $(RANLIB) $(LIBNAME)
647 +
648 +AD_LUSTRE_LOOBJECTS=$(AD_LUSTRE_OBJECTS:.o=.lo)
649 +$(SHLIBNAME).la: $(AD_LUSTRE_LOOBJECTS)
650 +       $(AR) $(SHLIBNAME).la $(AD_LUSTRE_LOOBJECTS)
651 +
652 +coverage:
653 +       -@for file in  ${AD_LUSTRE_OBJECTS:.o=.c} ; do \
654 +               gcov -b -f $$file ; done
655 +
656 +clean:
657 +       @rm -f *.o *.lo
658 diff -ruNp romio-orig/adio/ad_lustre/README romio-ornl/adio/ad_lustre/README
659 --- romio-orig/adio/ad_lustre/README    1969-12-31 19:00:00.000000000 -0500
660 +++ romio-ornl/adio/ad_lustre/README    2007-11-10 08:41:15.992364000 -0500
661 @@ -0,0 +1,29 @@
662 +-----------------------------------------------------
663 +V03: 
664 +-----------------------------------------------------
665 +  o Correct detection of fs_type when lustre: prefix is not given
666 +  o Further fix on stripe alignment
667 +  o Tested/Enabled striping hints over Cray XT (Catamount and CNL)
668 +
669 +-----------------------------------------------------
670 +V02:
671 +-----------------------------------------------------
672 +The Lustre ADIO driver has been cleaned up quite a lot. Compared 
673 +to the intital posting, here are the changes:
674 +  o Removal of dead/redundant code
675 +  o Removal of asynchronous IO piece as it appears outdated
676 +  o Bug fixes for setting Lustre Hints
677 +  o Bug fixes for data sieving 
678 +  o Improved Setsize operation with one process calling ftruncate 
679 +  o Improved collective IO with domain partitioning on 
680 +    Lustre stripe boundary
681 +
682 +Contributing:
683 +  o You may contribute via many different ways, such as 
684 +    testing results, bug reports, and new feature patches.
685 +  o We appreciate any courtesy reference of this work.
686 +  o Disclaimer: you are welcome to try the code, but at your own risk. 
687 +
688 +Contact info:
689 +    For more info, visit http://ft.ornl.gov/projects/io/
690 +
691 diff -ruNp romio-orig/adio/common/ad_aggregate.c romio-ornl/adio/common/ad_aggregate.c
692 --- romio-orig/adio/common/ad_aggregate.c       2007-11-10 07:12:18.105362000 -0500
693 +++ romio-ornl/adio/common/ad_aggregate.c       2007-11-10 07:30:02.418363000 -0500
694 @@ -2,6 +2,8 @@
695  /* 
696   *   Copyright (C) 1997-2001 University of Chicago. 
697   *   See COPYRIGHT notice in top-level directory.
698 + *
699 + *   Copyright (C) 2007 Oak Ridge National Laboratory
700   */
701  
702  #include "adio.h"
703 @@ -9,6 +11,8 @@
704  
705  #undef AGG_DEBUG
706  
707 +#define ALIGNDOWN(sz, al) ((sz)/al*al)
708 +
709  /* This file contains four functions:
710   *
711   * ADIOI_Calc_aggregator()
712 @@ -87,7 +91,12 @@ int ADIOI_Calc_aggregator(ADIO_File fd,
713  #endif
714      
715      /* get an index into our array of aggregators */
716 -    rank_index = (int) ((off - min_off + fd_size)/ fd_size - 1);
717 +    if (fd->file_system == ADIO_LUSTRE)
718 +       rank_index = (int) ((off - ALIGNDOWN(min_off, fd_size) + fd_size)/
719 +               fd_size - 1);
720 +    else
721 +       rank_index = (int) ((off - min_off + fd_size)/ fd_size - 1);
722 +
723  
724      /* we index into fd_end with rank_index, and fd_end was allocated to be no
725       * bigger than fd->hins->cb_nodes.   If we ever violate that, we're
726 @@ -130,6 +139,7 @@ void ADIOI_Calc_file_domains(ADIO_Offset
727          * do that, but this routine would be the place for it */
728  
729      ADIO_Offset min_st_offset, max_end_offset, *fd_start, *fd_end, fd_size;
730 +    int alignment = *fd_size_ptr;
731      int i;
732  
733  #ifdef AGG_DEBUG
734 @@ -154,6 +164,10 @@ void ADIOI_Calc_file_domains(ADIO_Offset
735     processes */ 
736      fd_size = ((max_end_offset - min_st_offset + 1) + nprocs_for_coll -
737                1)/nprocs_for_coll; 
738 +    if (alignment) {
739 +       fd_size = (fd_size + alignment -1 ) / alignment * alignment;
740 +    }
741 +
742      /* ceiling division as in HPF block distribution */
743  
744      *fd_start_ptr = (ADIO_Offset *)
745 @@ -165,7 +179,10 @@ void ADIOI_Calc_file_domains(ADIO_Offset
746      fd_end = *fd_end_ptr;
747  
748      fd_start[0] = min_st_offset;
749 -    fd_end[0] = min_st_offset + fd_size - 1;
750 +    if (alignment)
751 +       fd_end[0] = ALIGNDOWN(min_st_offset, fd_size) + fd_size - 1;
752 +    else
753 +       fd_end[0] = min_st_offset + fd_size - 1;
754  
755      for (i=1; i<nprocs_for_coll; i++) {
756         fd_start[i] = fd_end[i-1] + 1;
757 diff -ruNp romio-orig/adio/common/ad_fstype.c romio-ornl/adio/common/ad_fstype.c
758 --- romio-orig/adio/common/ad_fstype.c  2007-11-10 07:12:18.128343000 -0500
759 +++ romio-ornl/adio/common/ad_fstype.c  2007-11-10 08:21:48.329637000 -0500
760 @@ -317,6 +317,15 @@ static void ADIO_FileSysType_fncall(char
761      }
762  # endif
763  
764 +/*#if defined(LINUX) && defined(ROMIO_LUSTRE)*/
765 +#ifdef ROMIO_LUSTRE
766 +#define LL_SUPER_MAGIC 0x0BD00BD0
767 +    if (fsbuf.f_type == LL_SUPER_MAGIC) {
768 +       *fstype = ADIO_LUSTRE;
769 +       return;
770 +    }
771 +# endif
772 +
773  # ifdef PAN_KERNEL_FS_CLIENT_SUPER_MAGIC
774      if (fsbuf.f_type == PAN_KERNEL_FS_CLIENT_SUPER_MAGIC) {
775         *fstype = ADIO_PANFS;
776 @@ -467,6 +476,11 @@ static void ADIO_FileSysType_prefix(char
777      {
778         *fstype = ADIO_GRIDFTP;
779      }
780 +    else if (!strncmp(filename, "lustre:", 7) 
781 +            || !strncmp(filename, "LUSTRE:", 7))
782 +    {
783 +       *fstype = ADIO_LUSTRE;
784 +    }
785      else {
786  #ifdef ROMIO_NTFS
787         *fstype = ADIO_NTFS;
788 @@ -681,6 +695,14 @@ void ADIO_ResolveFileType(MPI_Comm comm,
789         *ops = &ADIO_GRIDFTP_operations;
790  #endif
791      }
792 +    if (file_system == ADIO_LUSTRE) {
793 +#ifndef ROMIO_LUSTRE 
794 +       *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**iofstypeunsupported", 0);
795 +       return;
796 +#else
797 +       *ops = &ADIO_LUSTRE_operations;
798 +#endif
799 +    }
800      *error_code = MPI_SUCCESS;
801      *fstype = file_system;
802      return;
803 diff -ruNp romio-orig/adio/common/ad_read_coll.c romio-ornl/adio/common/ad_read_coll.c
804 --- romio-orig/adio/common/ad_read_coll.c       2007-11-10 07:12:18.174296000 -0500
805 +++ romio-ornl/adio/common/ad_read_coll.c       2007-11-10 07:37:15.747604000 -0500
806 @@ -3,6 +3,8 @@
807   *
808   *   Copyright (C) 1997 University of Chicago. 
809   *   See COPYRIGHT notice in top-level directory.
810 + *
811 + *   Copyright (C) 2007 Oak Ridge National Laboratory
812   */
813  
814  #include "adio.h"
815 @@ -67,7 +69,7 @@ void ADIOI_GEN_ReadStridedColl(ADIO_File
816      int i, filetype_is_contig, nprocs, nprocs_for_coll, myrank;
817      int contig_access_count=0, interleave_count = 0, buftype_is_contig;
818      int *count_my_req_per_proc, count_my_req_procs, count_others_req_procs;
819 -    ADIO_Offset start_offset, end_offset, orig_fp, fd_size, min_st_offset, off;
820 +    ADIO_Offset start_offset, end_offset, orig_fp, fd_size=0, min_st_offset, off;
821      ADIO_Offset *offset_list = NULL, *st_offsets = NULL, *fd_start = NULL,
822         *fd_end = NULL, *end_offsets = NULL;
823      int *len_list = NULL, *buf_idx = NULL;
824 @@ -126,6 +128,8 @@ void ADIOI_GEN_ReadStridedColl(ADIO_File
825      if (fd->hints->cb_read == ADIOI_HINT_DISABLE
826         || (!interleave_count && (fd->hints->cb_read == ADIOI_HINT_AUTO))) 
827      {
828 +       int filerange_is_contig = 0; 
829 +
830         /* don't do aggregation */
831         if (fd->hints->cb_read != ADIOI_HINT_DISABLE) {
832             ADIOI_Free(offset_list);
833 @@ -136,8 +140,13 @@ void ADIOI_GEN_ReadStridedColl(ADIO_File
834  
835         fd->fp_ind = orig_fp;
836         ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
837 +       if (!filetype_is_contig)
838 +           ADIOI_Filetype_range_iscontig(fd, offset, file_ptr_type, 
839 +                   datatype, count, &filerange_is_contig);
840 +
841 +       if (buftype_is_contig && (filetype_is_contig ||
842 +                   filerange_is_contig)) {
843  
844 -       if (buftype_is_contig && filetype_is_contig) {
845             if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
846                 off = fd->disp + (fd->etype_size) * offset;
847                 ADIO_ReadContig(fd, buf, count, datatype, ADIO_EXPLICIT_OFFSET,
848 @@ -168,6 +177,19 @@ void ADIOI_GEN_ReadStridedColl(ADIO_File
849       * needs to be mapped to an actual rank in the communicator later.
850       *
851       */
852 +    if (fd->file_system == ADIO_LUSTRE) {
853 +       char *value;
854 +       int sflag;
855 +        value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
856 +       MPI_Info_get(fd->info, "striping_unit", MPI_MAX_INFO_VAL, 
857 +               value, &sflag);
858 +       if (sflag)
859 +           fd_size = atoi(value);
860 +       else
861 +           fd_size = ADIOI_LUSTRE_STRIPE_DFLT;
862 +       ADIOI_Free(value);
863 +    }
864 +
865      ADIOI_Calc_file_domains(st_offsets, end_offsets, nprocs,
866                             nprocs_for_coll, &min_st_offset,
867                             &fd_start, &fd_end, &fd_size);
868 diff -ruNp romio-orig/adio/common/ad_write_coll.c romio-ornl/adio/common/ad_write_coll.c
869 --- romio-orig/adio/common/ad_write_coll.c      2007-11-10 07:12:18.203267000 -0500
870 +++ romio-ornl/adio/common/ad_write_coll.c      2007-11-10 07:38:00.351958000 -0500
871 @@ -3,6 +3,8 @@
872   *
873   *   Copyright (C) 1997 University of Chicago. 
874   *   See COPYRIGHT notice in top-level directory.
875 + *
876 + *   Copyright (C) 2007 Oak Ridge National Laboratory
877   */
878  
879  #include "adio.h"
880 @@ -69,7 +71,7 @@ void ADIOI_GEN_WriteStridedColl(ADIO_Fil
881      int i, filetype_is_contig, nprocs, nprocs_for_coll, myrank;
882      int contig_access_count=0, interleave_count = 0, buftype_is_contig;
883      int *count_my_req_per_proc, count_my_req_procs, count_others_req_procs;
884 -    ADIO_Offset orig_fp, start_offset, end_offset, fd_size, min_st_offset, off;
885 +    ADIO_Offset orig_fp, start_offset, end_offset, fd_size=0, min_st_offset, off;
886      ADIO_Offset *offset_list = NULL, *st_offsets = NULL, *fd_start = NULL,
887         *fd_end = NULL, *end_offsets = NULL;
888      int *buf_idx = NULL, *len_list = NULL;
889 @@ -123,6 +125,8 @@ void ADIOI_GEN_WriteStridedColl(ADIO_Fil
890      if (fd->hints->cb_write == ADIOI_HINT_DISABLE ||
891         (!interleave_count && (fd->hints->cb_write == ADIOI_HINT_AUTO)))
892      {
893 +       int filerange_is_contig = 0; 
894 +
895         /* use independent accesses */
896         if (fd->hints->cb_write != ADIOI_HINT_DISABLE) {
897             ADIOI_Free(offset_list);
898 @@ -133,8 +137,12 @@ void ADIOI_GEN_WriteStridedColl(ADIO_Fil
899  
900         fd->fp_ind = orig_fp;
901          ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
902 +       if (!filetype_is_contig)
903 +           ADIOI_Filetype_range_iscontig(fd, offset, file_ptr_type, 
904 +                   datatype, count, &filerange_is_contig);
905  
906 -        if (buftype_is_contig && filetype_is_contig) {
907 +       if (buftype_is_contig && (filetype_is_contig ||
908 +                   filerange_is_contig)) {
909              if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
910                  off = fd->disp + (fd->etype_size) * offset;
911                  ADIO_WriteContig(fd, buf, count, datatype,
912 @@ -154,6 +162,19 @@ void ADIOI_GEN_WriteStridedColl(ADIO_Fil
913     done by (logically) dividing the file into file domains (FDs); each
914     process may directly access only its own file domain. */
915  
916 +    if (fd->file_system == ADIO_LUSTRE) {
917 +       char *value;
918 +       int sflag;
919 +        value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
920 +       MPI_Info_get(fd->info, "striping_unit", MPI_MAX_INFO_VAL, 
921 +               value, &sflag);
922 +       if (sflag) 
923 +           fd_size = atoi(value);
924 +       else
925 +           fd_size = ADIOI_LUSTRE_STRIPE_DFLT;
926 +       ADIOI_Free(value);
927 +    }
928 +
929      ADIOI_Calc_file_domains(st_offsets, end_offsets, nprocs,
930                             nprocs_for_coll, &min_st_offset,
931                             &fd_start, &fd_end, &fd_size);   
932 diff -ruNp romio-orig/adio/common/iscontig.c romio-ornl/adio/common/iscontig.c
933 --- romio-orig/adio/common/iscontig.c   2007-11-10 07:12:18.258209000 -0500
934 +++ romio-ornl/adio/common/iscontig.c   2007-11-10 07:13:32.648745000 -0500
935 @@ -2,9 +2,12 @@
936  /* 
937   *   Copyright (C) 1997 University of Chicago. 
938   *   See COPYRIGHT notice in top-level directory.
939 + *
940 + *   Copyright (C) 2007 Oak Ridge National Laboratory
941   */
942  
943  #include "adio.h"
944 +#include "adio_extern.h"
945  /* #ifdef MPISGI
946  #include "mpisgi2.h"
947  #endif */
948 @@ -101,3 +104,85 @@ void ADIOI_Datatype_iscontig(MPI_Datatyp
949         in other cases as well.*/
950  }
951  #endif
952 +
953 +void ADIOI_Filetype_range_start(ADIO_File fd, ADIO_Offset offset, int file_ptr_type,
954 +       int *start_index, int *start_ftype, int *start_offset, int *start_io_size)
955 +{
956 +    ADIOI_Flatlist_node *flat_file;
957 +    ADIO_Offset disp, abs_off_in_filetype=0;
958 +    MPI_Aint filetype_extent; 
959 +
960 +    int i, st_io_size=0, st_index=0;
961 +    int sum, n_etypes_in_filetype, size_in_filetype;
962 +    int n_filetypes, etype_in_filetype;
963 +    int flag, filetype_size, etype_size;
964 +
965 +    flat_file = ADIOI_Flatlist;
966 +    while (flat_file->type != fd->filetype) flat_file = flat_file->next;
967 +    disp = fd->disp;
968 +
969 +    MPI_Type_size(fd->filetype, &filetype_size);
970 +    MPI_Type_extent(fd->filetype, &filetype_extent);
971 +    etype_size = fd->etype_size;
972 +
973 +    if (file_ptr_type == ADIO_INDIVIDUAL) {
974 +       offset = fd->fp_ind; /* in bytes */
975 +       n_filetypes = -1;
976 +       flag = 0;
977 +       while (!flag) {
978 +           n_filetypes++;
979 +           for (i=0; i<flat_file->count; i++) {
980 +               if (disp + flat_file->indices[i] + 
981 +                   (ADIO_Offset) n_filetypes*filetype_extent + flat_file->blocklens[i] 
982 +                       >= offset) {
983 +                   st_index = i;
984 +                   st_io_size = (int) (disp + flat_file->indices[i] + 
985 +                           (ADIO_Offset) n_filetypes*filetype_extent
986 +                            + flat_file->blocklens[i] - offset);
987 +                   flag = 1;
988 +                   break;
989 +               }
990 +           }
991 +       }
992 +    } else {
993 +       n_etypes_in_filetype = filetype_size/etype_size;
994 +       n_filetypes = (int) (offset / n_etypes_in_filetype);
995 +       etype_in_filetype = (int) (offset % n_etypes_in_filetype);
996 +       size_in_filetype = etype_in_filetype * etype_size;
997 +
998 +       sum = 0;
999 +       for (i=0; i<flat_file->count; i++) {
1000 +           sum += flat_file->blocklens[i];
1001 +           if (sum > size_in_filetype) {
1002 +               st_index = i;
1003 +               st_io_size = sum - size_in_filetype;
1004 +               abs_off_in_filetype = flat_file->indices[i] +
1005 +                   size_in_filetype - (sum - flat_file->blocklens[i]);
1006 +               break;
1007 +           }
1008 +       }
1009 +
1010 +       /* abs. offset in bytes in the file */
1011 +       offset = disp + (ADIO_Offset) n_filetypes*filetype_extent + abs_off_in_filetype;
1012 +    }
1013 +
1014 +    *start_index   = st_index;
1015 +    *start_io_size = st_io_size;
1016 +    *start_offset  = offset;
1017 +    *start_ftype   = n_filetypes;
1018 +}
1019 +
1020 +void ADIOI_Filetype_range_iscontig(ADIO_File fd, ADIO_Offset offset, 
1021 +       int file_ptr_type, MPI_Datatype datatype, int count, int *flag)
1022 +{
1023 +    int srclen, datatype_size;
1024 +    int st_index, st_ftype, st_offset, st_io_size;
1025 +
1026 +    MPI_Type_size(datatype, &datatype_size);
1027 +    srclen = datatype_size * count;
1028 +
1029 +    ADIOI_Filetype_range_start(fd, offset, file_ptr_type,
1030 +           &st_index, &st_ftype, &st_offset, &st_io_size);
1031 +    *flag = st_io_size >= srclen ? 1 : 0;
1032 +}
1033 +
1034 diff -ruNp romio-orig/adio/include/adio.h romio-ornl/adio/include/adio.h
1035 --- romio-orig/adio/include/adio.h      2007-11-10 07:12:18.302169000 -0500
1036 +++ romio-ornl/adio/include/adio.h      2007-11-10 07:13:32.654738000 -0500
1037 @@ -289,6 +289,7 @@ typedef struct {
1038  #define ADIO_PVFS2               160   /* PVFS2: 2nd generation PVFS */
1039  #define ADIO_PANFS               161   /* Panasas FS */
1040  #define ADIO_GRIDFTP             162   /* Globus GridFTP */
1041 +#define ADIO_LUSTRE              163   /* Lustre */
1042  
1043  #define ADIO_SEEK_SET            SEEK_SET
1044  #define ADIO_SEEK_CUR            SEEK_CUR
1045 diff -ruNp romio-orig/adio/include/adioi_fs_proto.h romio-ornl/adio/include/adioi_fs_proto.h
1046 --- romio-orig/adio/include/adioi_fs_proto.h    2007-11-10 07:12:18.318156000 -0500
1047 +++ romio-ornl/adio/include/adioi_fs_proto.h    2007-11-10 07:13:32.658735000 -0500
1048 @@ -49,6 +49,32 @@ extern struct ADIOI_Fns_struct ADIO_SFS_
1049  /* prototypes are in adio/ad_sfs/ad_sfs.h */
1050  #endif
1051  
1052 +#ifdef ROMIO_LUSTRE
1053 +extern struct ADIOI_Fns_struct ADIO_LUSTRE_operations;
1054 +
1055 +void ADIOI_LUSTRE_Open(ADIO_File fd, int *error_code);
1056 +void ADIOI_LUSTRE_Close(ADIO_File fd, int *error_code);
1057 +void ADIOI_LUSTRE_ReadContig(ADIO_File fd, void *buf, int count, 
1058 +                      MPI_Datatype datatype, int file_ptr_type,
1059 +                     ADIO_Offset offset, ADIO_Status *status, int
1060 +                    *error_code);
1061 +void ADIOI_LUSTRE_WriteContig(ADIO_File fd, void *buf, int count, 
1062 +                      MPI_Datatype datatype, int file_ptr_type,
1063 +                      ADIO_Offset offset, ADIO_Status *status, int
1064 +                     *error_code);   
1065 +void ADIOI_LUSTRE_WriteStridedColl(ADIO_File fd, void *buf, int count,
1066 +                      MPI_Datatype datatype, int file_ptr_type,
1067 +                      ADIO_Offset offset, ADIO_Status *status, int
1068 +                      *error_code);
1069 +void ADIOI_LUSTRE_ReadStridedColl(ADIO_File fd, void *buf, int count,
1070 +                      MPI_Datatype datatype, int file_ptr_type,
1071 +                      ADIO_Offset offset, ADIO_Status *status, int
1072 +                      *error_code);
1073 +void ADIOI_LUSTRE_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct,
1074 +                      int *error_code);
1075 +void ADIOI_LUSTRE_SetInfo(ADIO_File fd, MPI_Info users_info, int *error_code);
1076 +#endif
1077 +
1078  #ifdef ROMIO_NTFS
1079  extern struct ADIOI_Fns_struct ADIO_NTFS_operations;
1080  /* prototypes are in adio/ad_ntfs/ad_ntfs.h */
1081 diff -ruNp romio-orig/adio/include/adioi.h romio-ornl/adio/include/adioi.h
1082 --- romio-orig/adio/include/adioi.h     2007-11-10 07:12:18.310161000 -0500
1083 +++ romio-ornl/adio/include/adioi.h     2007-11-10 07:36:19.895514000 -0500
1084 @@ -3,6 +3,8 @@
1085   *
1086   *   Copyright (C) 1997 University of Chicago. 
1087   *   See COPYRIGHT notice in top-level directory.
1088 + *
1089 + *   Copyright (C) 2007 Oak Ridge National Laboratory
1090   */
1091  
1092  
1093 @@ -184,6 +186,7 @@ struct ADIOI_Fns_struct {
1094  #define ADIOI_PREALLOC_BUFSZ      16777216    /* buffer size used to 
1095                                                  preallocate disk space */
1096  
1097 +#define ADIOI_LUSTRE_STRIPE_DFLT         (1<<20)
1098  
1099  /* default values for some hints */
1100      /* buffer size for collective I/O = 16 MB */
1101 @@ -295,6 +298,10 @@ void *ADIOI_Calloc_fn(size_t nelem, size
1102  void *ADIOI_Realloc_fn(void *ptr, size_t size, int lineno, char *fname);
1103  void ADIOI_Free_fn(void *ptr, int lineno, char *fname);
1104  void ADIOI_Datatype_iscontig(MPI_Datatype datatype, int *flag);
1105 +void ADIOI_Filetype_range_iscontig(ADIO_File fd, ADIO_Offset offset, 
1106 +       int file_ptr_type, MPI_Datatype datatype, int count, int *flag);
1107 +void ADIOI_Filetype_range_start(ADIO_File fd, ADIO_Offset offset, int file_ptr_type,
1108 +       int *start_index, int *start_ftype, int *start_offset, int *start_io_size);
1109  void ADIOI_Get_position(ADIO_File fd, ADIO_Offset *offset);
1110  void ADIOI_Get_eof_offset(ADIO_File fd, ADIO_Offset *eof_offset);
1111  void ADIOI_Get_byte_offset(ADIO_File fd, ADIO_Offset offset,
1112 diff -ruNp romio-orig/adio/include/mpio_error.h romio-ornl/adio/include/mpio_error.h
1113 --- romio-orig/adio/include/mpio_error.h        2007-11-10 07:12:18.321147000 -0500
1114 +++ romio-ornl/adio/include/mpio_error.h        2007-11-10 07:13:32.669723000 -0500
1115 @@ -63,6 +63,7 @@
1116  #define MPIR_ERR_FILETYPE 33 
1117  #define MPIR_ERR_NO_NTFS 35
1118  #define MPIR_ERR_NO_TESTFS 36
1119 +#define MPIR_ERR_NO_LUSTRE 37
1120  
1121  /* MPI_ERR_COMM */
1122  #ifndef MPIR_ERR_COMM_NULL
1123 diff -ruNp romio-orig/adio/include/romioconf.h.in romio-ornl/adio/include/romioconf.h.in
1124 --- romio-orig/adio/include/romioconf.h.in      2007-11-10 07:12:18.331143000 -0500
1125 +++ romio-ornl/adio/include/romioconf.h.in      2007-11-10 07:13:32.675717000 -0500
1126 @@ -282,6 +282,9 @@
1127  /* Define for ROMIO with PVFS2 */
1128  #undef ROMIO_PVFS2
1129  
1130 +/* Define for ROMIO with LUSTRE */
1131 +#undef ROMIO_LUSTRE
1132 +
1133  /* Define if int64_t must be defined for PVFS */
1134  #undef ROMIO_PVFS_NEEDS_INT64_DEFINITION
1135  
1136 diff -ruNp romio-orig/configure romio-ornl/configure
1137 --- romio-orig/configure        2007-11-10 07:12:19.455013000 -0500
1138 +++ romio-ornl/configure        2007-11-10 07:15:22.506785000 -0500
1139 @@ -1402,7 +1402,7 @@ MPIO_REQ_REAL_POBJECTS="_iotest.o _iowai
1140  #
1141  have_aio=no
1142  #
1143 -known_filesystems="nfs ufs pfs pvfs pvfs2 testfs xfs panfs gridftp"
1144 +known_filesystems="nfs ufs pfs pvfs pvfs2 testfs xfs panfs gridftp lustre"
1145  known_mpi_impls="mpich2_mpi mpich_mpi sgi_mpi hp_mpi cray_mpi lam_mpi"
1146  #
1147  # Defaults
1148 @@ -7630,6 +7630,14 @@ _ACEOF
1149  
1150  fi
1151  
1152 +if test -n "$file_system_lustre"; then
1153 +
1154 +cat >>confdefs.h <<\_ACEOF
1155 +#define ROMIO_LUSTRE 1
1156 +_ACEOF
1157 +
1158 +fi
1159 +
1160  #
1161  # Check for presence and characteristics of async. I/O calls if
1162  # not disabled.
1163 @@ -12139,7 +12147,7 @@ rm -f adio/include/romioconf.h ${use_top
1164  # are active will be called by the top level ROMIO make
1165            ac_config_commands="$ac_config_commands default-1"
1166  
1167 -                                                                                                                                                                                                                                                                                                                                                    ac_config_files="$ac_config_files Makefile localdefs mpi-io/Makefile mpi2-other/info/Makefile mpi2-other/array/Makefile adio/common/Makefile test/Makefile test/misc.c test/large_file.c test/runtests util/romioinstall include/mpio.h include/mpiof.h adio/ad_nfs/Makefile adio/ad_ufs/Makefile adio/ad_panfs/Makefile adio/ad_xfs/Makefile adio/ad_sfs/Makefile adio/ad_pfs/Makefile adio/ad_testfs/Makefile adio/ad_pvfs/Makefile adio/ad_pvfs2/Makefile adio/ad_gridftp/Makefile mpi-io/fortran/Makefile mpi2-other/info/fortran/Makefile mpi2-other/array/fortran/Makefile test/fmisc.f test/fcoll_test.f test/pfcoll_test.f test/fperf.f mpi-io/glue/mpich2/Makefile mpi-io/glue/mpich1/Makefile mpi-io/glue/default/Makefile common/dataloop/Makefile"
1168 +                                                                                                                                                                                                                                                                                                                                                    ac_config_files="$ac_config_files Makefile localdefs mpi-io/Makefile mpi2-other/info/Makefile mpi2-other/array/Makefile adio/common/Makefile test/Makefile test/misc.c test/large_file.c test/runtests util/romioinstall include/mpio.h include/mpiof.h adio/ad_nfs/Makefile adio/ad_ufs/Makefile adio/ad_panfs/Makefile adio/ad_xfs/Makefile adio/ad_sfs/Makefile adio/ad_pfs/Makefile adio/ad_testfs/Makefile adio/ad_pvfs/Makefile adio/ad_pvfs2/Makefile adio/ad_gridftp/Makefile adio/ad_lustre/Makefile mpi-io/fortran/Makefile mpi2-other/info/fortran/Makefile mpi2-other/array/fortran/Makefile test/fmisc.f test/fcoll_test.f test/pfcoll_test.f test/fperf.f mpi-io/glue/mpich2/Makefile mpi-io/glue/mpich1/Makefile mpi-io/glue/default/Makefile common/dataloop/Makefile"
1169  cat >confcache <<\_ACEOF
1170  # This file is a shell script that caches the results of configure
1171  # tests run on this system so they can be shared between configure
1172 @@ -12697,6 +12705,7 @@ do
1173    "adio/ad_pvfs/Makefile" ) CONFIG_FILES="$CONFIG_FILES adio/ad_pvfs/Makefile" ;;
1174    "adio/ad_pvfs2/Makefile" ) CONFIG_FILES="$CONFIG_FILES adio/ad_pvfs2/Makefile" ;;
1175    "adio/ad_gridftp/Makefile" ) CONFIG_FILES="$CONFIG_FILES adio/ad_gridftp/Makefile" ;;
1176 +  "adio/ad_lustre/Makefile" ) CONFIG_FILES="$CONFIG_FILES adio/ad_lustre/Makefile" ;;
1177    "mpi-io/fortran/Makefile" ) CONFIG_FILES="$CONFIG_FILES mpi-io/fortran/Makefile" ;;
1178    "mpi2-other/info/fortran/Makefile" ) CONFIG_FILES="$CONFIG_FILES mpi2-other/info/fortran/Makefile" ;;
1179    "mpi2-other/array/fortran/Makefile" ) CONFIG_FILES="$CONFIG_FILES mpi2-other/array/fortran/Makefile" ;;
1180 diff -ruNp romio-orig/configure.in romio-ornl/configure.in
1181 --- romio-orig/configure.in     2007-11-10 07:12:18.367105000 -0500
1182 +++ romio-ornl/configure.in     2007-11-10 07:13:32.707687000 -0500
1183 @@ -93,7 +93,7 @@ MPIO_REQ_REAL_POBJECTS="_iotest.o _iowai
1184  #
1185  have_aio=no
1186  #
1187 -known_filesystems="nfs ufs pfs pvfs pvfs2 testfs xfs panfs gridftp"
1188 +known_filesystems="nfs ufs pfs pvfs pvfs2 testfs xfs panfs gridftp lustre"
1189  known_mpi_impls="mpich2_mpi mpich_mpi sgi_mpi hp_mpi cray_mpi lam_mpi"
1190  #
1191  # Defaults
1192 @@ -1097,6 +1097,9 @@ fi
1193  if test -n "$file_system_testfs"; then
1194      AC_DEFINE(ROMIO_TESTFS,1,[Define for ROMIO with TESTFS])
1195  fi
1196 +if test -n "$file_system_lustre"; then
1197 +    AC_DEFINE(ROMIO_LUSTRE,1,[Define for ROMIO with LUSTRE])
1198 +fi
1199  
1200  if test -n "$file_system_xfs"; then
1201      AC_DEFINE(ROMIO_XFS,1,[Define for ROMIO with XFS])
1202 @@ -2101,6 +2104,7 @@ AC_OUTPUT(Makefile localdefs mpi-io/Make
1203                    adio/ad_testfs/Makefile adio/ad_pvfs/Makefile \
1204                    adio/ad_pvfs2/Makefile \
1205                    adio/ad_gridftp/Makefile \
1206 +                  adio/ad_lustre/Makefile \
1207                     mpi-io/fortran/Makefile mpi2-other/info/fortran/Makefile \
1208                     mpi2-other/array/fortran/Makefile test/fmisc.f \
1209                     test/fcoll_test.f test/pfcoll_test.f test/fperf.f \
1210 diff -ruNp romio-orig/Makefile.in romio-ornl/Makefile.in
1211 --- romio-orig/Makefile.in      2007-11-10 07:12:18.357110000 -0500
1212 +++ romio-ornl/Makefile.in      2007-11-10 07:13:32.712681000 -0500
1213 @@ -15,7 +15,7 @@ DIRS        = mpi-io adio/common @GLUE_D
1214  MPIO_DIRS   = mpi-io
1215  EXTRA_SRC_DIRS = @EXTRA_SRC_DIRS@
1216  FILE_SYS_DIRS = @FILE_SYS_DIRS@
1217 -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_panfs adio/ad_gridftp test mpi-io/glue/default mpi-io/glue/mpich1 mpi-io/glue/mpich2
1218 +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_panfs adio/ad_gridftp adio/ad_lustre test mpi-io/glue/default mpi-io/glue/mpich1 mpi-io/glue/mpich2
1219  SHELL       = /bin/sh
1220  
1221  @VPATH@