/* * Open a file through the POSIX interface. */ static void *POSIX_Open(char *testFileName, IOR_param_t * param) { int fd_oflag = O_BINARY; int *fd; fd = (int *)malloc(sizeof(int)); if (fd == NULL) ERR("Unable to malloc file descriptor"); if (param->useO_DIRECT == TRUE) set_o_direct_flag(&fd_oflag); fd_oflag |= O_RDWR; *fd = open64(testFileName, fd_oflag); if (*fd < 0) ERR("open64 failed"); #ifdef HAVE_LUSTRE_LUSTRE_USER_H if (param->lustre_ignore_locks) { int lustre_ioctl_flags = LL_FILE_IGNORE_LOCK; if (verbose >= VERBOSE_1) { fprintf(stdout, "** Disabling lustre range locking **\n"); } if (ioctl(*fd, LL_IOC_SETFLAGS, &lustre_ioctl_flags) == -1) ERR("ioctl(LL_IOC_SETFLAGS) failed"); } #endif /* HAVE_LUSTRE_LUSTRE_USER_H */ #ifdef HAVE_GPFS_FCNTL_H if(param->gpfs_release_token) { gpfs_free_all_locks(*fd); } #endif return ((void *)fd); }
void ADIOI_GPFS_Open(ADIO_File fd, int *error_code) { int perm, old_mask, amode, rank, rc; static char myname[] = "ADIOI_GPFS_OPEN"; /* set internal variables for tuning environment variables */ ad_gpfs_get_env_vars(); if (fd->perm == ADIO_PERM_NULL) { old_mask = umask(022); umask(old_mask); perm = old_mask ^ 0666; } else perm = fd->perm; amode = 0; if (fd->access_mode & ADIO_CREATE) amode = amode | O_CREAT; if (fd->access_mode & ADIO_RDONLY) amode = amode | O_RDONLY; if (fd->access_mode & ADIO_WRONLY) amode = amode | O_WRONLY; if (fd->access_mode & ADIO_RDWR) amode = amode | O_RDWR; if (fd->access_mode & ADIO_EXCL) amode = amode | O_EXCL; #ifdef ADIOI_MPE_LOGGING MPE_Log_event(ADIOI_MPE_open_a, 0, NULL); #endif fd->fd_sys = open(fd->filename, amode, perm); #ifdef ADIOI_MPE_LOGGING MPE_Log_event(ADIOI_MPE_open_b, 0, NULL); #endif DBG_FPRINTF(stderr,"open('%s',%#X,%#X) rc=%d, errno=%d\n",fd->filename,amode,perm,fd->fd_sys,errno); fd->fd_direct = -1; if (gpfsmpio_devnullio == 1) { fd->null_fd = open("/dev/null", O_RDWR); } else { fd->null_fd = -1; } if ((fd->fd_sys != -1) && (fd->access_mode & ADIO_APPEND)) fd->fp_ind = fd->fp_sys_posn = lseek(fd->fd_sys, 0, SEEK_END); if(fd->fd_sys != -1) { fd->blksize = 1048576; /* default to 1M */ #ifdef ADIOI_MPE_LOGGING MPE_Log_event(ADIOI_MPE_stat_a, 0, NULL); #endif /* in this fs-specific routine, we might not be called over entire * communicator (deferred open). Collect statistics on one process. * ADIOI_GEN_Opencoll (common-code caller) will take care of the * broadcast */ MPI_Comm_rank(fd->comm, &rank); if ((rank == fd->hints->ranklist[0]) || (fd->comm == MPI_COMM_SELF)) { struct stat64 gpfs_statbuf; /* Get the (real) underlying file system block size */ rc = stat64(fd->filename, &gpfs_statbuf); if (rc >= 0) { fd->blksize = gpfs_statbuf.st_blksize; DBGV_FPRINTF(stderr,"Successful stat '%s'. Blocksize=%ld\n", fd->filename,gpfs_statbuf.st_blksize); } else { DBGV_FPRINTF(stderr,"Stat '%s' failed with rc=%d, errno=%d\n", fd->filename,rc,errno); } } /* all other ranks have incorrect fd->blocksize, but ADIOI_GEN_Opencoll * will take care of that in both standard and deferred-open case */ #ifdef ADIOI_MPE_LOGGING MPE_Log_event(ADIOI_MPE_stat_b, 0, NULL); #endif #ifdef HAVE_GPFS_FCNTL_H /* in parallel workload, might be helpful to immediately release block * tokens. Or, system call overhead will outweigh any benefits... */ if (getenv("ROMIO_GPFS_FREE_LOCKS")!=NULL) gpfs_free_all_locks(fd->fd_sys); #endif } if (fd->fd_sys == -1) { *error_code = ADIOI_Err_create_code(myname, fd->filename, errno); } else *error_code = MPI_SUCCESS; }
/* * Creat and open a file through the POSIX interface. */ static void *POSIX_Create(char *testFileName, IOR_param_t * param) { int fd_oflag = O_BINARY; int *fd; fd = (int *)malloc(sizeof(int)); if (fd == NULL) ERR("Unable to malloc file descriptor"); if (param->useO_DIRECT == TRUE) set_o_direct_flag(&fd_oflag); #ifdef HAVE_LUSTRE_LUSTRE_USER_H if (param->lustre_set_striping) { /* In the single-shared-file case, task 0 has to creat the file with the Lustre striping options before any other processes open the file */ if (!param->filePerProc && rank != 0) { MPI_CHECK(MPI_Barrier(testComm), "barrier error"); fd_oflag |= O_RDWR; *fd = open64(testFileName, fd_oflag, 0664); if (*fd < 0) ERR("open64() failed"); } else { struct lov_user_md opts = { 0 }; /* Setup Lustre IOCTL striping pattern structure */ opts.lmm_magic = LOV_USER_MAGIC; opts.lmm_stripe_size = param->lustre_stripe_size; opts.lmm_stripe_offset = param->lustre_start_ost; opts.lmm_stripe_count = param->lustre_stripe_count; /* File needs to be opened O_EXCL because we cannot set Lustre striping information on a pre-existing file. */ fd_oflag |= O_CREAT | O_EXCL | O_RDWR | O_LOV_DELAY_CREATE; *fd = open64(testFileName, fd_oflag, 0664); if (*fd < 0) { fprintf(stdout, "\nUnable to open '%s': %s\n", testFileName, strerror(errno)); MPI_CHECK(MPI_Abort(MPI_COMM_WORLD, -1), "MPI_Abort() error"); } else if (ioctl(*fd, LL_IOC_LOV_SETSTRIPE, &opts)) { char *errmsg = "stripe already set"; if (errno != EEXIST && errno != EALREADY) errmsg = strerror(errno); fprintf(stdout, "\nError on ioctl for '%s' (%d): %s\n", testFileName, *fd, errmsg); MPI_CHECK(MPI_Abort(MPI_COMM_WORLD, -1), "MPI_Abort() error"); } if (!param->filePerProc) MPI_CHECK(MPI_Barrier(testComm), "barrier error"); } } else { #endif /* HAVE_LUSTRE_LUSTRE_USER_H */ fd_oflag |= O_CREAT | O_RDWR; *fd = open64(testFileName, fd_oflag, 0664); if (*fd < 0) ERR("open64() failed"); #ifdef HAVE_LUSTRE_LUSTRE_USER_H } if (param->lustre_ignore_locks) { int lustre_ioctl_flags = LL_FILE_IGNORE_LOCK; if (ioctl(*fd, LL_IOC_SETFLAGS, &lustre_ioctl_flags) == -1) ERR("ioctl(LL_IOC_SETFLAGS) failed"); } #endif /* HAVE_LUSTRE_LUSTRE_USER_H */ #ifdef HAVE_GPFS_FCNTL_H /* in the single shared file case, immediately release all locks, with * the intent that we can avoid some byte range lock revocation: * everyone will be writing/reading from individual regions */ if (param->gpfs_release_token ) { gpfs_free_all_locks(*fd); } #endif return ((void *)fd); }