Esempio n. 1
0
/*
 * 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 */

        return ((void *)fd);
}
Esempio n. 2
0
/*
 * 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);
}
Esempio n. 3
0
/*
 * 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;
#ifdef HAVE_LUSTRE_LUSTRE_USER_H
        char path[PATH_MAX] = "";
        int ost_count = 0;
        int ost_list[MAX_OST_COUNT];
#endif

        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;
                        if(param->lustre_use_all_osts == -1){
                                opts.lmm_stripe_offset = param->lustre_start_ost;
                        }
#ifdef HAVE_LUSTRE_LIBLUSTREAPI_H
                        /* Set lustre_start_ost if asked */
                        else {
                                /* Get information about available FS's OSTs */
                                getcwd(path, sizeof(path));
                                get_active_ost_list(path,&ost_count,ost_list);
                                /* In the case where all OSTs will be used */
                                if(param->lustre_use_all_osts == 0) {
                                        opts.lmm_stripe_offset = ost_list[rank%ost_count];
                                } else {
                                        /* Only a number of OSTs is specified */
                                        if(param->lustre_ost_list[0] < 0) {
                                                opts.lmm_stripe_offset = ost_list[rank%param->lustre_use_all_osts];
                                        }
                                        /* a list of OSTs is specified */
                                        else {
                                                opts.lmm_stripe_offset = param->lustre_ost_list[rank%param->lustre_use_all_osts];
                                        }
                                }
                        }
#endif
                        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 */

        return ((void *)fd);
}