File: ad_pvfs2_common.c

package info (click to toggle)
openmpi 5.0.8-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 201,692 kB
  • sloc: ansic: 613,078; makefile: 42,353; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,179; python: 1,859; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (141 lines) | stat: -rw-r--r-- 4,205 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

#include "ad_pvfs2.h"
#include "ad_pvfs2_common.h"
#include <unistd.h>
#include <sys/types.h>
#include <time.h>
#include <stdlib.h>

/* maybe give romio access to the globalconfig struct */
/* keyval hack to both tell us if we've already initialized pvfs2 and also
 * close it down when mpi exits */
int ADIOI_PVFS2_Initialized = MPI_KEYVAL_INVALID;

void ADIOI_PVFS2_End(int *error_code)
{
    int ret;
    static char myname[] = "ADIOI_PVFS2_END";

    ret = PVFS_sys_finalize();

    /* --BEGIN ERROR HANDLING-- */
    if (ret != 0) {
        *error_code = MPIO_Err_create_code(MPI_SUCCESS,
                                           MPIR_ERR_RECOVERABLE,
                                           myname, __LINE__,
                                           ADIOI_PVFS2_error_convert(ret),
                                           "Error in PVFS_sys_finalize", 0);
        return;
    }
    /* --END ERROR HANDLING-- */

    *error_code = MPI_SUCCESS;
}

int ADIOI_PVFS2_End_call(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state)
{
    int error_code;
    ADIOI_PVFS2_End(&error_code);
    MPI_Keyval_free(&keyval);
    return error_code;
}

void ADIOI_PVFS2_Init(int *error_code)
{
    int ret;
    static char myname[] = "ADIOI_PVFS2_INIT";
    char *ncache_timeout;

    /* do nothing if we've already fired up the pvfs2 interface */
    if (ADIOI_PVFS2_Initialized != MPI_KEYVAL_INVALID) {
        *error_code = MPI_SUCCESS;
        return;
    }

    /* for consistency, we should disable the pvfs2 ncache.  If the
     * environtment variable is already set, assume a  user knows it
     * won't be a problem */
    ncache_timeout = getenv("PVFS2_NCACHE_TIMEOUT");
    if (ncache_timeout == NULL)
        setenv("PVFS2_NCACHE_TIMEOUT", "0", 1);

    ret = PVFS_util_init_defaults();
    if (ret < 0) {
        *error_code = MPIO_Err_create_code(MPI_SUCCESS,
                                           MPIR_ERR_RECOVERABLE,
                                           myname, __LINE__,
                                           ADIOI_PVFS2_error_convert(ret),
                                           "Error in PVFS_util_init_defaults", 0);
        PVFS_perror("PVFS_util_init_defaults", ret);

        return;
    }

    MPI_Keyval_create(MPI_NULL_COPY_FN, ADIOI_PVFS2_End_call, &ADIOI_PVFS2_Initialized, (void *) 0);
    /* just like romio does, we make a dummy attribute so we
     * get cleaned up */
    MPI_Attr_put(MPI_COMM_SELF, ADIOI_PVFS2_Initialized, (void *) 0);
}

void ADIOI_PVFS2_makeattribs(PVFS_sys_attr * attribs)
{
    memset(attribs, 0, sizeof(PVFS_sys_attr));

    attribs->owner = geteuid();
    attribs->group = getegid();
    attribs->perms = 0644;
    attribs->mask = PVFS_ATTR_SYS_ALL_SETABLE;
    attribs->atime = time(NULL);
    attribs->mtime = attribs->atime;
    attribs->ctime = attribs->atime;
}


void ADIOI_PVFS2_makecredentials(PVFS_credentials * credentials)
{
    memset(credentials, 0, sizeof(PVFS_credentials));

    PVFS_util_gen_credentials(credentials);
}

int ADIOI_PVFS2_error_convert(int pvfs_error)
{
    switch (pvfs_error) {
        case PVFS_EPERM:
        case PVFS_EACCES:
            return MPI_ERR_ACCESS;
        case PVFS_ENOENT:
        case PVFS_ENXIO:
        case PVFS_ENODEV:
            return MPI_ERR_NO_SUCH_FILE;
        case PVFS_EIO:
            return MPI_ERR_IO;
        case PVFS_EEXIST:
            return MPI_ERR_FILE_EXISTS;
        case PVFS_ENOTDIR:     /* ??? */
        case PVFS_EISDIR:      /* ??? */
        case PVFS_ENAMETOOLONG:
            return MPI_ERR_BAD_FILE;
        case PVFS_EINVAL:
            return MPI_ERR_FILE;
        case PVFS_EFBIG:       /* ??? */
        case PVFS_ENOSPC:
            return MPI_ERR_NO_SPACE;
        case PVFS_EROFS:
            return MPI_ERR_READ_ONLY;
        case PVFS_ENOSYS:
            return MPI_ERR_UNSUPPORTED_OPERATION;
            /* PVFS does not support quotas */
        case EDQUOT:
            return MPI_ERR_QUOTA;
        case PVFS_ENOMEM:
            return MPI_ERR_INTERN;
        default:
            return MPI_UNDEFINED;
    }

}