Commit 6f661320 authored by Shane Snyder's avatar Shane Snyder

add rename support to POSIX module

parent d20ef28f
...@@ -30,6 +30,10 @@ ...@@ -30,6 +30,10 @@
X(POSIX_FSYNCS) \ X(POSIX_FSYNCS) \
/* count of posix fdatasyncs */\ /* count of posix fdatasyncs */\
X(POSIX_FDSYNCS) \ X(POSIX_FDSYNCS) \
/* count of renames (as source file) */\
X(POSIX_RENAME_SOURCES) \
/* count of renames (as target file) */\
X(POSIX_RENAME_TARGETS) \
/* mode of file */\ /* mode of file */\
X(POSIX_MODE) \ X(POSIX_MODE) \
/* total bytes read */\ /* total bytes read */\
......
...@@ -82,6 +82,7 @@ DARSHAN_FORWARD_DECL(aio_return, ssize_t, (struct aiocb *aiocbp)); ...@@ -82,6 +82,7 @@ DARSHAN_FORWARD_DECL(aio_return, ssize_t, (struct aiocb *aiocbp));
DARSHAN_FORWARD_DECL(aio_return64, ssize_t, (struct aiocb64 *aiocbp)); DARSHAN_FORWARD_DECL(aio_return64, ssize_t, (struct aiocb64 *aiocbp));
DARSHAN_FORWARD_DECL(lio_listio, int, (int mode, struct aiocb *const aiocb_list[], int nitems, struct sigevent *sevp)); DARSHAN_FORWARD_DECL(lio_listio, int, (int mode, struct aiocb *const aiocb_list[], int nitems, struct sigevent *sevp));
DARSHAN_FORWARD_DECL(lio_listio64, int, (int mode, struct aiocb64 *const aiocb_list[], int nitems, struct sigevent *sevp)); DARSHAN_FORWARD_DECL(lio_listio64, int, (int mode, struct aiocb64 *const aiocb_list[], int nitems, struct sigevent *sevp));
DARSHAN_FORWARD_DECL(rename, int, (const char *oldpath, const char *newpath));
/* The posix_file_record_ref structure maintains necessary runtime metadata /* The posix_file_record_ref structure maintains necessary runtime metadata
* for the POSIX file record (darshan_posix_file structure, defined in * for the POSIX file record (darshan_posix_file structure, defined in
...@@ -1402,6 +1403,70 @@ int DARSHAN_DECL(lio_listio64)(int mode, struct aiocb64 *const aiocb_list[], ...@@ -1402,6 +1403,70 @@ int DARSHAN_DECL(lio_listio64)(int mode, struct aiocb64 *const aiocb_list[],
return(ret); return(ret);
} }
int DARSHAN_DECL(rename)(const char *oldpath, const char *newpath)
{
int ret;
double tm1, tm2;
char *oldpath_clean, *newpath_clean;
darshan_record_id old_rec_id, new_rec_id;
struct posix_file_record_ref *old_rec_ref, *new_rec_ref;
MAP_OR_FAIL(rename);
tm1 = darshan_core_wtime();
ret = __real_rename(oldpath, newpath);
tm2 = darshan_core_wtime();
if(ret == 0)
{
oldpath_clean = darshan_clean_file_path(oldpath);
if(!oldpath_clean) oldpath_clean = (char *)oldpath;
if(darshan_core_excluded_path(oldpath_clean))
{
if(oldpath_clean != oldpath) free(oldpath_clean);
return(ret);
}
old_rec_id = darshan_core_gen_record_id(oldpath_clean);
POSIX_PRE_RECORD();
old_rec_ref = darshan_lookup_record_ref(posix_runtime->rec_id_hash,
&old_rec_id, sizeof(darshan_record_id));
if(!old_rec_ref)
{
POSIX_POST_RECORD();
if(oldpath_clean != oldpath) free(oldpath_clean);
return(ret);
}
old_rec_ref->file_rec->counters[POSIX_RENAME_SOURCES] += 1;
DARSHAN_TIMER_INC_NO_OVERLAP(old_rec_ref->file_rec->fcounters[POSIX_F_META_TIME],
tm1, tm2, old_rec_ref->last_meta_end);
newpath_clean = darshan_clean_file_path(newpath);
if(!newpath_clean) newpath_clean = (char *)newpath;
if(darshan_core_excluded_path(newpath_clean))
{
POSIX_POST_RECORD();
if(oldpath_clean != oldpath) free(oldpath_clean);
if(newpath_clean != newpath) free(newpath_clean);
return(ret);
}
new_rec_id = darshan_core_gen_record_id(newpath_clean);
new_rec_ref = darshan_lookup_record_ref(posix_runtime->rec_id_hash,
&new_rec_id, sizeof(darshan_record_id));
if(!new_rec_ref)
new_rec_ref = posix_track_new_file_record(new_rec_id, newpath_clean);
if(new_rec_ref)
new_rec_ref->file_rec->counters[POSIX_RENAME_TARGETS] += 1;
POSIX_POST_RECORD();
if(oldpath_clean != oldpath) free(oldpath_clean);
if(newpath_clean != newpath) free(newpath_clean);
}
return(ret);
}
/********************************************************** /**********************************************************
* Internal functions for manipulating POSIX module state * * Internal functions for manipulating POSIX module state *
**********************************************************/ **********************************************************/
......
...@@ -40,3 +40,4 @@ ...@@ -40,3 +40,4 @@
--wrap=lio_listio --wrap=lio_listio
--wrap=lio_listio64 --wrap=lio_listio64
--wrap=fileno --wrap=fileno
--wrap=rename
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment