10 #define _XOPEN_SOURCE 700 17 #include "sion_common.h" 18 #include "sion_const.h" 19 #include "sion_debug.h" 20 #include "sion_enums.h" 21 #include "sion_error_handler.h" 22 #include "sion_flags.h" 23 #include "sion_internal.h" 24 #include "sion_serial.h" 26 int sion_open(
char *fname,
const char *file_mode,
int *ntasks,
int *nfiles, int64_t **chunksizes, int32_t *fsblksize,
27 int **globalranks, FILE **fileptr)
30 _sion_flags_store *flags_store = _sion_parse_flags(file_mode);
32 return _sion_errorprint(
33 SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"_sion_open: could not parse file mode in %s, aborting ...\n", file_mode);
36 DPRINTFP((1,
"sion_open", 0,
"enter open of file %s in %s mode\n", fname, file_mode));
38 sid = _sion_open(fname, flags_store, ntasks, nfiles, chunksizes, fsblksize, globalranks, fileptr);
40 _sion_flags_destroy_store(&flags_store);
45 int sion_open_rank(
char *fname,
const char *file_mode, int64_t *chunksize, int32_t *fsblksize,
int *rank, FILE **fileptr)
49 DPRINTFTS(*rank,
"before open rank");
50 DPRINTFP((1,
"sion_open_rank", *rank,
"enter open of file %s in %s mode\n", fname, file_mode));
51 sid = _sion_open_rank(fname, file_mode, chunksize, fsblksize, rank, fileptr);
52 DPRINTFP((1,
"sion_open_rank", 0,
"leave open of file %s in %s mode sid=%d\n", fname, file_mode, sid));
53 DPRINTFTS(*rank,
"after open rank");
61 DPRINTFP((1,
"sion_close", -1,
"enter close sid=%d\n", sid));
62 rc = _sion_close_sid(sid);
63 DPRINTFP((1,
"sion_close", -1,
"leave close sid=%d\n", sid));
78 .keyval_mode = SION_KEYVAL_MODE_NONE,
80 .lowlevel_api = SION_LOWLEVEL_API_C};
83 void sion_options_set_chunksizes(
sion_options *options,
int n, int64_t chunksizes[])
85 options->chunksizes = chunksizes;
86 options->n_chunksizes = n;
89 void sion_options_set_fsblksize(
sion_options *options, int32_t fsblksize)
91 options->fsblksize = fsblksize;
94 void sion_options_set_multifile_number(
sion_options *options,
int multifile_number)
96 options->n_multifile = multifile_number;
99 void sion_options_set_keyval_mode(
sion_options *options, sion_keyval_mode keyval_mode)
101 options->keyval_mode = keyval_mode;
104 void sion_options_set_lowlevel_api(
sion_options *options, sion_lowlevel_api lowlevel_api)
106 options->lowlevel_api = lowlevel_api;
109 _sion_flags_store *_sion_options_into_flags_store(sion_open_mode mode,
const sion_options *options)
111 _sion_flags_store *flags_store = _sion_flags_create_store();
114 fprintf(stderr,
"could not create flags store.\n");
120 _sion_flags_add(flags_store,
"br",
"");
122 switch (options->keyval_mode) {
123 case SION_KEYVAL_MODE_NONE:
126 case SION_KEYVAL_MODE_DEFAULT:
128 case SION_KEYVAL_MODE_INLINE:
129 _sion_flags_add(flags_store,
"keyval",
"inline");
131 case SION_KEYVAL_MODE_META:
132 _sion_flags_add(flags_store,
"keyval",
"meta");
134 case SION_KEYVAL_MODE_HASH:
135 _sion_flags_add(flags_store,
"keyval",
"hash");
137 case SION_KEYVAL_MODE_UNKNOWN:
138 _sion_flags_add(flags_store,
"keyval",
"unknown");
142 fprintf(stderr,
"wrong keyval mode in read mode.\n");
143 _sion_flags_destroy_store(&flags_store);
148 case SION_OPEN_WRITE:
149 _sion_flags_add(flags_store,
"bw",
"");
151 switch (options->keyval_mode) {
152 case SION_KEYVAL_MODE_NONE:
155 case SION_KEYVAL_MODE_DEFAULT:
157 case SION_KEYVAL_MODE_INLINE:
158 _sion_flags_add(flags_store,
"keyval",
"inline");
160 case SION_KEYVAL_MODE_META:
161 _sion_flags_add(flags_store,
"keyval",
"meta");
163 case SION_KEYVAL_MODE_HASH:
164 _sion_flags_add(flags_store,
"keyval",
"hash");
168 fprintf(stderr,
"wrong keyval mode in read mode.\n");
169 _sion_flags_destroy_store(&flags_store);
176 switch (options->lowlevel_api) {
177 case SION_LOWLEVEL_API_C:
178 _sion_flags_add(flags_store,
"ansi",
"");
180 case SION_LOWLEVEL_API_POSIX:
181 _sion_flags_add(flags_store,
"posix",
"");
185 _sion_flags_update_mask(flags_store);
190 int sion_open_with_options(
const char *fname, sion_open_mode mode,
int n,
const sion_options *options_)
193 sion_options options = (options_) ? *options_ : sion_options_new();
195 int64_t *chunksizes = NULL;
196 if (!options.chunksizes) {
197 chunksizes = malloc(n *
sizeof(int64_t));
198 if (chunksizes == NULL) {
199 return _sion_errorprint(SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"%s: could not allocate memory for chunksizes\n", __func__);
201 for (
size_t i = 0; i < n; ++i) {
202 chunksizes[i] = 1024 * 1024;
205 if (options.n_chunksizes != n) {
206 return _sion_errorprint(SION_ID_NOT_VALID, _SION_ERROR_RETURN,
207 "%s: size of chunksizes array in options (%d) does not match number of logical files (%d)\n", __func__,
208 options.n_chunksizes, n);
212 _sion_flags_store *flags_store = _sion_options_into_flags_store(mode, &options);
217 int *globalranks = calloc(n,
sizeof(
int));
218 if (globalranks == NULL) {
220 return _sion_errorprint(SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"%s: could not allocate memory for globalranks\n", __func__);
223 int sid = _sion_open(fname, flags_store, &n, &options.n_multifile, (options.chunksizes) ? &options.chunksizes : &chunksizes,
224 &options.fsblksize, &globalranks, NULL);
229 _sion_flags_destroy_store(&flags_store);
int sion_open_rank(char *fname, const char *file_mode, int64_t *chunksize, int32_t *fsblksize, int *rank, FILE **fileptr)
Open a sion file for a specific rank.
int sion_close(int sid)
Close a sion file.
int sion_open(char *fname, const char *file_mode, int *ntasks, int *nfiles, int64_t **chunksizes, int32_t *fsblksize, int **globalranks, FILE **fileptr)
Open a sion file in serial mode.