Skip to content

Commit

Permalink
drm: add output option
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Moody <moody20@llnl.gov>
  • Loading branch information
adammoody committed Jun 12, 2019
1 parent c0f8fc4 commit 5725e04
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 16 deletions.
10 changes: 10 additions & 0 deletions doc/rst/drm.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ OPTIONS
Read source list from FILE. FILE must be generated by another tool
from the mpiFileUtils suite.

.. option:: -o, --output FILE

Write the list of items drm attempts to delete to FILE in mpiFileUtils format.
Format can be changed with --text option.

.. option:: -t, --text

Must be used with the --output option. Write list of items drm attempts
to delete to FILE in ascii text format.

.. option:: -l, --lite

Walk file system without stat.
Expand Down
63 changes: 47 additions & 16 deletions src/drm/drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ static void print_usage(void)
printf("\n");
printf("Options:\n");
printf(" -i, --input <file> - read list from file\n");
printf(" -o, --output <file> - write list to file in binary format\n");
printf(" -t, --text - use with -o; write processed list to file in ascii format\n");
printf(" -l, --lite - walk file system without stat\n");
printf(" --exclude <regex> - exclude from command entries that match the regex\n");
printf(" --match <regex> - apply command only to entries that match the regex\n");
Expand Down Expand Up @@ -66,13 +68,15 @@ int main(int argc, char** argv)
mfu_walk_opts_t* walk_opts = mfu_walk_opts_new();

/* parse command line options */
char* inputname = NULL;
char* regex_exp = NULL;
int walk = 0;
int exclude = 0;
int name = 0;
int dryrun = 0;
int traceless = 0;
char* inputname = NULL;
char* outputname = NULL;
char* regex_exp = NULL;
int walk = 0;
int exclude = 0;
int name = 0;
int dryrun = 0;
int traceless = 0;
int text = 0;
/* Don't stat on walk by default */
walk_opts->use_stat = 0;

Expand All @@ -82,6 +86,8 @@ int main(int argc, char** argv)
int option_index = 0;
static struct option long_options[] = {
{"input", 1, 0, 'i'},
{"output", 1, 0, 'o'},
{"text", 0, 0, 't'},
{"lite", 0, 0, 'l'},
{"exclude", 1, 0, 'e'},
{"match", 1, 0, 'a'},
Expand All @@ -99,7 +105,7 @@ int main(int argc, char** argv)
int usage = 0;
while (1) {
int c = getopt_long(
argc, argv, "i:lTvqh",
argc, argv, "i:o:tlTvqh",
long_options, &option_index
);

Expand All @@ -111,6 +117,12 @@ int main(int argc, char** argv)
case 'i':
inputname = MFU_STRDUP(optarg);
break;
case 'o':
outputname = MFU_STRDUP(optarg);
break;
case 't':
text = 1;
break;
case 'l':
/* don't stat each file during the walk */
walk_opts->use_stat = 0;
Expand Down Expand Up @@ -165,13 +177,6 @@ int main(int argc, char** argv)
}
}

if (dryrun && walk_opts->remove) {
printf("Cannot perform dryrun with aggressive delete option. Program is safely exiting. Please do a dryrun then run an aggressive delete separately. These two options cannot both be specified for the same program run \n");
mfu_finalize();
MPI_Finalize();
return 1;
}

/* check that we got a valid progress value */
if (mfu_progress_timeout < 0) {
if (rank == 0) {
Expand Down Expand Up @@ -213,6 +218,20 @@ int main(int argc, char** argv)
}
}

/* check that user didn't ask for a dryrun, but then specify
* an aggressive delete while walking */
if (dryrun && walk && walk_opts->remove) {
MFU_LOG(MFU_LOG_ERR, "Cannot perform dryrun with aggressive delete option. Program is safely exiting. Please do a dryrun then run an aggressive delete separately. These two options cannot both be specified for the same program run.");
usage = 1;
}

/* since we don't get a full list back from the walk when using
* --agressive, we can't write a good output file */
if (outputname != NULL && walk && walk_opts->remove) {
MFU_LOG(MFU_LOG_ERR, "Cannot write output file with aggressive delete option. Program is safely exiting. These two options cannot both be specified for the same program run.");
usage = 1;
}

/* print usage if we need to */
if (usage) {
if (rank == 0) {
Expand Down Expand Up @@ -260,8 +279,17 @@ int main(int argc, char** argv)
mfu_flist_unlink(srclist, traceless);
}

/* write data to cache file */
if (outputname != NULL) {
if (!text) {
mfu_flist_write_cache(outputname, srclist);
} else {
mfu_flist_write_text(outputname, srclist);
}
}

/* free list if it was used */
if (filtered_flist != MFU_FLIST_NULL){
if (filtered_flist != MFU_FLIST_NULL) {
/* free the filtered flist (if any) */
mfu_flist_free(&filtered_flist);
}
Expand All @@ -278,6 +306,9 @@ int main(int argc, char** argv)
/* free the regex string if we have one */
mfu_free(&regex_exp);

/* free the output file name */
mfu_free(&outputname);

/* free the input file name */
mfu_free(&inputname);

Expand Down

0 comments on commit 5725e04

Please sign in to comment.