Skip to content

Commit

Permalink
Updating how we file datapatterns work
Browse files Browse the repository at this point in the history
Previously when the option -datapattern file/wholefile was used, XDD
would open the file for every target and keep it open till the run was
over. This is really unnecessary as the file only needs to be opened to
read the datapattern in to set the datapattern in the target. Once that
has happen, the file can immediately be closed. This is a good idea as
there are limits to how many files can be opened in Linux (ulimit). XDD
should not tie up the number of avialable open file descriptors just to
set a datapattern over an entire XDD run.

The code has been updated to open the file, set the target data_pattern
buffer, and then immediately close the file. I have added a new
functional test case test_xdd_file_datapattern.sh to test out that these
this modification did not break the expected functionality of
-datapattern file/wholefile.

Signed-off-by: Brian Atkinson <[email protected]>
  • Loading branch information
bwatkinson committed Mar 18, 2024
1 parent 2468c98 commit a71e892
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/base/target_cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ xdd_target_thread_cleanup(target_data_t *tdp) {
/* If the file target opend a file for the data pattern we must close
* the files and clean up the data_pattern buffer
*/
close(tdp->dpp_fd);
free(tdp->td_dpp->data_pattern);
}
free(tdp->td_dpp);
Expand Down
18 changes: 11 additions & 7 deletions src/client/parse_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ xddfunc_datapattern(xdd_plan_t *planp, int32_t argc, char *argv[], uint32_t flag
}
} else if (strcmp(pattern_type, "file") == 0 || strcmp(pattern_type, "wholefile") == 0) {
retval++;
int dp_fd;

if (argc <= args+2) {
fprintf(xgp->errout, "%s: not enough arguments specified for the option '-datapattern'\n", xgp->progname);
return(0);
Expand Down Expand Up @@ -583,15 +585,16 @@ xddfunc_datapattern(xdd_plan_t *planp, int32_t argc, char *argv[], uint32_t flag
(char *)argv[args+2]);
return(0);
}
tdp->dpp_fd = open(tdp->td_dpp->data_pattern_filename, O_RDONLY);
if (tdp->dpp_fd < 0) {
dp_fd = open(tdp->td_dpp->data_pattern_filename, O_RDONLY);
if (dp_fd < 0) {
fprintf(xgp->errout, "%s: could not open %s\n", xgp->progname, tdp->td_dpp->data_pattern_filename);
return(0);
}
tdp->td_dpp->data_pattern = (unsigned char *)malloc(sizeof(unsigned char) * (tdp->td_dpp->data_pattern_length + 1));
memset(tdp->td_dpp->data_pattern, '\0', sizeof(unsigned char) * (tdp->td_dpp->data_pattern_length + 1));
pread(tdp->dpp_fd, tdp->td_dpp->data_pattern, tdp->td_dpp->data_pattern_length, 0);
} else {// Put this option into all Targets
pread(dp_fd, tdp->td_dpp->data_pattern, tdp->td_dpp->data_pattern_length, 0);
close(dp_fd);
} else {// Put this option into all Targets
if (flags & XDD_PARSE_PHASE2) {
tdp = planp->target_datap[0];
i = 0;
Expand All @@ -609,15 +612,16 @@ xddfunc_datapattern(xdd_plan_t *planp, int32_t argc, char *argv[], uint32_t flag
(char *)argv[args+2]);
return(0);
}
tdp->dpp_fd = open(tdp->td_dpp->data_pattern_filename, O_RDONLY);
if (tdp->dpp_fd < 0) {
dp_fd = open(tdp->td_dpp->data_pattern_filename, O_RDONLY);
if (dp_fd < 0) {
fprintf(xgp->errout, "%s: could not open %s\n", xgp->progname, tdp->td_dpp->data_pattern_filename);
return(0);
}
tdp->td_dpp->data_pattern_length = pattern_length;
tdp->td_dpp->data_pattern = (unsigned char *)malloc(sizeof(unsigned char) * (tdp->td_dpp->data_pattern_length + 1));
memset(tdp->td_dpp->data_pattern, '\0', sizeof(unsigned char) * (tdp->td_dpp->data_pattern_length + 1));
pread(tdp->dpp_fd, tdp->td_dpp->data_pattern, tdp->td_dpp->data_pattern_length, 0);
pread(dp_fd, tdp->td_dpp->data_pattern, tdp->td_dpp->data_pattern_length, 0);
close(dp_fd);
i++;
tdp = planp->target_datap[i];
}
Expand Down
1 change: 0 additions & 1 deletion src/common/xint_td.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ struct xint_target_data {
struct xint_e2e *td_e2ep; // Pointer to the e2e struct when needed
struct xint_extended_stats *td_esp; // Extended Stats Structure Pointer
struct xint_triggers *td_trigp; // Triggers Structure Pointer
int dpp_fd; // File descriptor for file data pattern
struct xint_data_pattern *td_dpp; // Data Pattern Structure Pointer
struct xint_raw *td_rawp; // RAW Data Structure Pointer
struct lockstep *td_lsp; // Pointer to the lockstep structure used by the lockstep option
Expand Down
1 change: 1 addition & 0 deletions tests/functional/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(FUNCTIONAL
test_xdd_createnewfiles.sh
test_xdd_createnewfiles2.sh
test_xdd_dryrun.sh
test_xdd_file_datapattern.sh
test_xdd_heartbeat_byte.sh
test_xdd_heartbeat_elapsed.sh
test_xdd_heartbeat_lf.sh
Expand Down
52 changes: 52 additions & 0 deletions tests/functional/test_xdd_file_datapattern.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
#
# Acceptance test for XDD.
#
# Validate the funtionality of -datapattern file/wholefile option by creating a file, setting the datapattern
# from that file and then verifying the contents match
#
# Description - terminates XDD after a given amount of seconds have passed
#
# Get absolute path to script
SCRIPT=${BASH_SOURCE[0]}
SCRIPTPATH=$(dirname "${SCRIPT}")

# Source the test configuration environment
source "${SCRIPTPATH}"/../test_config
source "${SCRIPTPATH}"/../common.sh

# Perform pre-test
initialize_test
test_dir="${XDDTEST_LOCAL_MOUNT}/${TESTNAME}"
log_file="$(get_log_file)"

input_file=$test_dir/data1.dat
output_file=$test_dir/data2.dat

# Create datapattern input file using dd
dd if=/dev/urandom of="${input_file}" bs=4k count=2

# Write out file using xdd with -datapattern file
"${XDDTEST_XDD_EXE}" -op write -reqsize 8 -numreqs 1 -datapattern file "${input_file}" -targets 1 "${output_file}" -qd 1 -passes 1
# Verify the contents of the file match
diff "${input_file}" "${output_file}"
if [[ $? -ne 0 ]]
then
rm "${input_file}" "${output_file}"
finalize_test 1 "Issue with setting datapattern from file with -datapattern file. Contents don't match."
fi

rm "${output_file}"
# Write out file using xdd with -datapattern wholefile
"${XDDTEST_XDD_EXE}" -op write -reqsize 8 -numreqs 1 -datapattern wholefile "${input_file}" -targets 1 "${output_file}" -qd 1 -passes 1
# Verify the contents of the file match
diff "${input_file}" "${output_file}"
if [[ $? -ne 0 ]]
then
rm "${input_file}" "${output_file}"
finalize_test 1 "Issue with setting datapattern from file with -datapattern file. Contents don't match."
fi
rm "${input_file}" "${output_file}"

# Test passed
finalize_test 0

0 comments on commit a71e892

Please sign in to comment.