16 #define _XOPEN_SOURCE 700
28 #include "sion_error_handler.h"
41 #define DFUNCTION "_sion_dup"
52 int _sion_dup(
int sid,
int mode,
int rank, uint64_t key ) {
53 int rc = SION_NOT_SUCCESS, new_sid = SION_ID_NOT_VALID;
57 DPRINTFTS(-1,
"enter sion_dup");
58 DPRINTFP((2, DFUNCTION, -1,
"enter dup sid=%d\n",sid));
62 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN, DFUNCTION
": invalid sion_filedesc, returning %d ...\n", sid));
66 DPRINTFP((8, DFUNCTION, -1,
"invalid opened\n"));
67 return(_sion_errorprint_on_rank(SION_ID_NOT_VALID,_SION_ERROR_RETURN,sion_filedesc->
rank,
68 DFUNCTION
"[%2d]: file is not opened in read mode, returning ...", sion_filedesc->
rank));
71 _sion_print_filedesc(sion_filedesc, 512,
"_sion_dup_orig ", _SION_DEBUG_PRINT_ALL|_SION_DEBUG_PRINT_RECURSIVE);
76 return(_sion_errorprint_on_rank(SION_ID_NOT_VALID,_SION_ERROR_RETURN,sion_filedesc->
rank, DFUNCTION
"[%2d]: could not duplicate internal data structure, returning ...", sion_filedesc->
rank));
91 new_filedesc->
sid=new_sid;
98 DPRINTFP((8, DFUNCTION, -1,
"file is in state SION_FILESTATE_PAROPEN\n"));
104 DPRINTFP((8, DFUNCTION, -1,
"file is in state SION_FILESTATE_SEROPEN\n"));
106 return(_sion_errorprint_on_rank(SION_ID_NOT_VALID,_SION_ERROR_RETURN,sion_filedesc->
rank,
107 DFUNCTION
"[%2d]: mode not implemented, aborting ...", sion_filedesc->
rank));
112 DPRINTFP((8, DFUNCTION, -1,
"file is in state SION_FILESTATE_SEROPENRANK\n"));
114 return(_sion_errorprint_on_rank(SION_ID_NOT_VALID,_SION_ERROR_RETURN,sion_filedesc->
rank,
115 DFUNCTION
"[%2d]: mode not implemented, aborting ...", sion_filedesc->
rank));
120 DPRINTFP((8, DFUNCTION, -1,
"file is in state SION_FILESTATE_PAROPENMAPPEDMASTER\n"));
125 if (rc!=SION_SUCCESS) {
126 return(_sion_errorprint_on_rank(SION_ID_NOT_VALID,_SION_ERROR_RETURN,sion_filedesc->
rank,
127 DFUNCTION
"[%2d]: could not duplicate, returning ...", sion_filedesc->
rank));
141 _sion_print_filedesc(new_filedesc, 512,
"_sion_dup_clone", _SION_DEBUG_PRINT_ALL|_SION_DEBUG_PRINT_RECURSIVE);
143 DPRINTFP((2, DFUNCTION, -1,
"leave dup sid=%d new_sid=%d\n",sid,new_sid));
144 DPRINTFTS(-1,
"leave sion_dup");
151 #define DFUNCTION "_sion_dedup"
158 int rc = SION_SUCCESS;
159 int filenr, lfile, lrank;
163 DPRINTFTS(-1,
"enter sion_dedup");
164 DPRINTFP((2, DFUNCTION, -1,
"enter dedup sid=%d\n",sid));
168 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN, DFUNCTION
": invalid sion_filedesc, returning %d ...\n", sid));
172 return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc->
rank, DFUNCTION
"[%2d]: descriptor is not a duplicate, returning ...", sion_filedesc->
rank));
177 int numbytes, numfds;
179 DPRINTFP((2, DFUNCTION, -1,
"internal data size of sid %2d (%d bytes, %d fds) \n", sid,numbytes, numfds));
191 lrank=sion_filedesc->
rank;
192 sion_filedesc_sub=sion_filedesc->
multifiles[lfile];
193 if( (lrank>=0) && (lfile>=0)
197 DPRINTFP((2, DFUNCTION, -1,
"keyvalptr all_keyvalptr[%d] = %x\n",lrank,sion_filedesc->
keyvalptr));
199 DPRINTFP((2, DFUNCTION, -1,
"WARNING keyvalptr already set all_keyvalptr[%d] = %x new =%x \n",lrank,
208 for(filenr=0;filenr<sion_filedesc->
nfiles;filenr++) {
209 sion_filedesc_sub=sion_filedesc->
multifiles[filenr];
215 if (sion_filedesc_sub->
fileptr!=NULL) {
217 sion_filedesc_sub->
fileptr=NULL;
219 _sion_free_filedesc(sion_filedesc_sub);
229 _sion_free_filedesc(sion_filedesc);
230 sion_filedesc = NULL;
240 _sion_free_filedesc(sion_filedesc);
241 sion_filedesc = NULL;
244 DPRINTFP((2, DFUNCTION, -1,
"leave dedup sid=%d rc=%d\n",sid,rc));
245 DPRINTFTS(-1,
"leave sion_dedup");
253 #define DFUNCTION "_sion_dup_paropen"
260 int rc = SION_SUCCESS;
262 DPRINTFP((2, DFUNCTION, -1,
"enter \n"));
269 return(_sion_errorprint_on_rank(SION_ID_NOT_VALID,_SION_ERROR_RETURN,sion_filedesc->
rank,
270 DFUNCTION
"[%2d]: could not duplicate fileptr, returning ...", sion_filedesc->
rank));
282 DPRINTFP((2, DFUNCTION, -1,
"leave rc=%d\n",rc));
289 #define DFUNCTION "_sion_dup_paropenmappedmaster"
296 int rc = SION_SUCCESS;
298 int filenr, lfile, lrank;
300 DPRINTFP((2, DFUNCTION, -1,
"enter \n"));
304 lrank=sion_filedesc->
rank;
305 sion_filedesc_sub=sion_filedesc->
multifiles[lfile];
314 DPRINTFP((4, DFUNCTION, -1,
"store current information lrank=%d lastchunknr=%d\n", lrank,sion_filedesc_sub->
lastchunknr));
320 DPRINTFP((2, DFUNCTION, -1,
"keyvalptr all_keyvalptr[%d] = %x\n",lrank,sion_filedesc_sub->
keyvalptr));
329 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure vector of size %lu (sion_filedesc), aborting ...\n",
334 for(filenr=0;filenr<sion_filedesc->
nfiles;filenr++) {
343 DPRINTFP((2, DFUNCTION, -1,
" open file for multifiles[%d]\n",filenr));
347 return(_sion_errorprint_on_rank(SION_ID_NOT_VALID,_SION_ERROR_RETURN,sion_filedesc->
rank, DFUNCTION
348 "[%2d]: could not duplicate fileptr, returning ...", sion_filedesc->
rank));
372 lrank=sion_filedesc->
rank;
376 DPRINTFP((2, DFUNCTION, -1,
"set keyvalptr on lfile=%d,lrank=%d to %x\n",lfile,lrank,new_filedesc->
keyvalptr));
379 DPRINTFP((2, DFUNCTION, -1,
"leave rc=%d\n",rc));
387 #define DFUNCTION "_sion_dup_blocksizes"
394 int rc = SION_SUCCESS;
404 for (i = 0; i <= sion_filedesc->
lastchunknr; i++) {
416 #define DFUNCTION "_sion_dup_all_ds"
423 int rc = SION_SUCCESS;
426 DPRINTFP((32, DFUNCTION, sion_filedesc->
rank,
"ntasks=%d\n", sion_filedesc->
ntasks));
429 _sion_alloc_filedesc_all_chunksizes(new_filedesc);
430 _sion_alloc_filedesc_all_globalranks(new_filedesc);
431 _sion_alloc_filedesc_all_localranks(new_filedesc);
432 _sion_alloc_filedesc_all_startpointers(new_filedesc);
437 for(ltask=0;ltask<new_filedesc->
ntasks;ltask++) {
445 DPRINTFP((32, DFUNCTION, sion_filedesc->
rank,
" sel all_*[%d]\n", ltask));
448 DPRINTFP((32, DFUNCTION, sion_filedesc->
rank,
" sel all_blocksizes[0..%d]\n", new_filedesc->
maxchunks * new_filedesc->
ntasks));
458 #define DFUNCTION "_sion_dup_keyvalptr"
467 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
469 rc=_sion_keyval_dup_dataptr(sion_filedesc,new_filedesc);
471 DPRINTFP((2, DFUNCTION, -1,
"leave rc=%d\n",rc));
478 #define DFUNCTION "_sion_dup_all_keyvalptr"
485 int rc = SION_SUCCESS;
489 DPRINTFP((32, DFUNCTION, sion_filedesc->
rank,
"ntasks=%d\n", sion_filedesc->
ntasks));
492 _sion_alloc_filedesc_all_keyvalptr(new_filedesc);
496 for(ltask=0;ltask<new_filedesc->
ntasks;ltask++) {
500 _sion_keyval_dup_dataptr(sion_filedesc,new_filedesc);
502 DPRINTFP((2, DFUNCTION, -1,
"keyvalptr all_keyvalptr[%d] = %x\n",ltask,new_filedesc->
keyvalptr));
505 DPRINTFP((32, DFUNCTION, sion_filedesc->
rank,
" duplicated keyvalptr[%d]\n", ltask));
int _sion_buffer_flush(_sion_filedesc *sion_filedesc)
Flush buffer.
int sion_seek(int sid, int rank, int currentblocknr, sion_int64 posinblk)
Function to set the file pointer to a new position.
int sion_get_sizeof(int sid, int *numbytes, int *numfds)
Function returns size of internal data structure for sid.
#define SION_CURRENT_CHUNK
#define SION_DUP_RANK_KEY
int _sion_dup_paropenmappedmaster(_sion_filedesc *sion_filedesc, _sion_filedesc *new_filedesc)
Duplicate sion_filedesc if the file is opened in paropen_mapped_master.
int _sion_dup_paropen(_sion_filedesc *sion_filedesc, _sion_filedesc *new_filedesc)
Duplicate sion_filedesc if the file is opened in paropen_mapped_master.
int _sion_dup_all_keyvalptr(_sion_filedesc *sion_filedesc, _sion_filedesc *new_filedesc)
Duplicate the keyvalue data structures of sion_filedesc.
int _sion_dup_blocksizes(_sion_filedesc *sion_filedesc, _sion_filedesc *new_filedesc)
Duplicate the blocksizes array of sion_filedesc.
int _sion_dup(int sid, int mode, int rank, uint64_t key)
Create a duplicated sion file descriptor.
int _sion_dup_all_ds(_sion_filedesc *sion_filedesc, _sion_filedesc *new_filedesc)
Duplicate the all* array of sion_filedesc.
int _sion_dup_keyvalptr(_sion_filedesc *sion_filedesc, _sion_filedesc *new_filedesc)
Duplicate the keyvalue data structure of sion_filedesc.
int _sion_dedup(int sid)
Destroy a duplicated sion file descriptor.
void * _sion_vcdtovcon(int sid)
int _sion_vcdtype(int sid)
int _sion_newvcd(void *data, int type)
int _sion_freevcd(int sid)
#define SION_FILEDESCRIPTOR
int _sion_file_close(_sion_fileptr *sion_fileptr)
Close file and destroys fileptr structure.
sion_int64 _sion_file_set_position(_sion_fileptr *sion_fileptr, sion_int64 startpointer)
Set new position in file.
_sion_fileptr * _sion_file_open(const char *fname, unsigned int flags, unsigned int addflags)
Create and open a new file for writing.
int _sion_realloc_filedesc_blocklist(_sion_filedesc *sion_filedesc, sion_int32 maxchunks)
Increase the memory used by the internal sion structure for the blocklist.
int _sion_print_filedesc(_sion_filedesc *sion_filedesc, int level, char *desc, int flag)
Print the initialized sion file description.
_sion_filedesc * _sion_dup_filedesc(_sion_filedesc *sion_filedesc)
duplicates a filedesc data structure, not copying/reopen active file pointers
int _sion_alloc_filedesc_block_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion structure, fields for all chunksizes of all tasks.
#define SION_DESCSTATE_ORIG
#define SION_DESCSTATE_DUP_SEL_RANK
#define SION_FILEMODE_READ
#define SION_FILESTATE_SEROPENRANK
#define SION_FILESTATE_PAROPEN
#define SION_FILESTATE_SEROPENMASTER
#define SION_DESCSTATE_DUP_SEL_RANK_KEY
#define SION_FILESTATE_SEROPEN
#define SION_FILESTATE_PAROPENMAPPEDMASTER
Sion File Descriptor Structure.
sion_int64 * all_localranks
sion_int64 * all_blocksizes
sion_int64 * all_chunksizes
sion_int64 * all_currentpos
sion_int64 * all_currentblocknr
_sion_filedesc ** multifiles
sion_int64 * all_globalranks
sion_int32 currentblocknr
sion_int64 * all_startpointers
sion_int64 * all_blockcount