00001
00002
00003
00004
00005
00006
00007
00008 #define _GNU_SOURCE // for O_DIRECT
00009
00010 #include "ad_xfs.h"
00011 #include <sys/ioctl.h>
00012 #ifdef HAVE_STDDEF_H
00013 #include <stddef.h>
00014 #endif
00015
00016 #ifndef HAVE_LSEEK64
00017 #define lseek64 lseek
00018 #endif
00019
00020 void ADIOI_XFS_Open(ADIO_File fd, int *error_code)
00021 {
00022 int perm, amode, amode_direct, factor;
00023 unsigned int old_mask;
00024 struct dioattr st;
00025 static char myname[] = "ADIOI_XFS_OPEN";
00026 unsigned read_chunk_sz = fd->hints->fs_hints.xfs.read_chunk_sz;
00027 unsigned write_chunk_sz = fd->hints->fs_hints.xfs.write_chunk_sz;
00028
00029 if (fd->perm == ADIO_PERM_NULL) {
00030 old_mask = umask(022);
00031 umask(old_mask);
00032 perm = old_mask ^ 0666;
00033 }
00034 else perm = fd->perm;
00035
00036 amode = 0;
00037 if (fd->access_mode & ADIO_CREATE)
00038 amode = amode | O_CREAT;
00039 if (fd->access_mode & ADIO_RDONLY)
00040 amode = amode | O_RDONLY;
00041 if (fd->access_mode & ADIO_WRONLY)
00042 amode = amode | O_WRONLY;
00043 if (fd->access_mode & ADIO_RDWR)
00044 amode = amode | O_RDWR;
00045
00046 amode_direct = amode | O_DIRECT;
00047
00048 if (fd->access_mode & ADIO_EXCL)
00049 amode = amode | O_EXCL;
00050
00051 fd->fd_sys = open(fd->filename, amode, perm);
00052
00053 fd->fd_direct = open(fd->filename, amode_direct, perm);
00054 if (fd->fd_direct != -1) {
00055
00056 #if defined(MPISGI)
00057 ioctl(fd->fd_direct, XFS_IOC_DIOINFO, &st);
00058 #else
00059 fcntl(fd->fd_direct, F_DIOINFO, &st);
00060 #endif
00061
00062 fd->d_mem = st.d_mem;
00063 fd->d_miniosz = st.d_miniosz;
00064
00065 if (read_chunk_sz == 0) {
00066 fd->hints->fs_hints.xfs.read_chunk_sz = st.d_maxiosz;
00067 } else {
00068
00069
00070
00071
00072 factor = read_chunk_sz / fd->d_miniosz;
00073 if (factor == 0 || read_chunk_sz != fd->d_miniosz * factor) {
00074 fd->hints->fs_hints.xfs.read_chunk_sz =
00075 fd->d_miniosz * (factor + 1);
00076 }
00077 }
00078
00079 if (write_chunk_sz == 0) {
00080 fd->hints->fs_hints.xfs.write_chunk_sz = st.d_maxiosz;
00081 } else {
00082
00083
00084
00085
00086 factor = write_chunk_sz / fd->d_miniosz;
00087 if (factor == 0 || write_chunk_sz != fd->d_miniosz * factor) {
00088 fd->hints->fs_hints.xfs.write_chunk_sz =
00089 fd->d_miniosz * (factor + 1);
00090 }
00091 }
00092
00093 if (fd->d_mem > XFS_MEMALIGN) {
00094 FPRINTF(stderr, "MPI: Run-time Direct-IO memory alignment, %d, does not match compile-time value, %d.\n",
00095 fd->d_mem, XFS_MEMALIGN);
00096 FPRINTF(stderr, "MPI: Report this error and rerun with Direct-IO disabled.\n");
00097 close(fd->fd_direct);
00098 fd->fd_direct = -1;
00099 }
00100 }
00101
00102 if ((fd->fd_sys != -1) && (fd->access_mode & ADIO_APPEND))
00103 fd->fp_ind = lseek64(fd->fd_sys, 0, SEEK_END);
00104
00105 fd->fp_sys_posn = -1;
00106
00107 if ((fd->fd_sys == -1) || (fd->fd_direct == -1)) {
00108 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00109 myname, __LINE__, MPI_ERR_IO, "**io",
00110 "**io %s", strerror(errno));
00111 }
00112 else *error_code = MPI_SUCCESS;
00113 }