Skip to content
Snippets Groups Projects

Resolve "Segmentation fault in sfind"

Closed Ramon Nou requested to merge 138-segmentation-fault-in-sfind into master
1 unresolved thread
Compare and Show latest version
1 file
+ 24
17
Compare changes
  • Side-by-side
  • Inline
+ 24
17
@@ -50,19 +50,19 @@ extern "C" int gkfs_getsingleserverdir(const char *path,
* servers */
typedef struct {
std::string workdir{};
int just_count;
int just_count = 0;
int print_by_process;
char *results_dir;
std::string results_dir{};
int stonewall_timer;
int print_rates;
char *timestamp_file;
char *name_pattern;
std::string timestamp_file{};
char * name_pattern;
regex_t name_regex;
uint64_t size;
int num_servers;
char *mountdir;
std::string mountdir{};
// optimizing parameters NOT USED
int queue_length;
int max_entries_per_iter;
@@ -103,8 +103,8 @@ static void pfind_print_help(pfind_options_t *res) {
"Optional flags\n"
"\t-h: prints the help\n"
"\t--help: prints the help without initializing MPI\n",res->workdir.c_str(),
res->timestamp_file, res->name_pattern, res->num_servers,
res->mountdir );
res->timestamp_file.c_str(), res->name_pattern, res->num_servers,
res->mountdir.c_str() );
}
int pfind_size;
pfind_options_t *pfind_parse_args(int argc, char **argv, int force_print_help){
@@ -114,6 +114,7 @@ pfind_options_t *pfind_parse_args(int argc, char **argv, int force_print_help){
pfind_options_t *res = (pfind_options_t *)malloc(sizeof(pfind_options_t));
memset(res, 0, sizeof(pfind_options_t));
auto print_help = force_print_help;
res->workdir = "./";
@@ -151,7 +152,10 @@ pfind_options_t *pfind_parse_args(int argc, char **argv, int force_print_help){
res->name_pattern = (char *)malloc(strlen(argv[i + 1]) * 4 + 100);
// transform a traditional name pattern to a regex:
char *str = argv[i + 1];
char *out = res->name_pattern;
char * out = res->name_pattern;
auto pos = 0;
for (size_t i = 0; i < strlen(str); i++) {
if (str[i] == '*') {
@@ -280,8 +284,7 @@ void dirProcess(const string path, unsigned long long &checked,
struct dirent_extended *getdir = (struct dirent_extended *)malloc(
(sizeof(struct dirent_extended) + 255) * 1024 * 100);
memset(getdir, 0, (sizeof(struct dirent_extended) + 255) * 1024 * 100);
// cout << "PROCESSING " << world_rank << "/"<< world_size << " = " << path <<
// endl;
for (auto server = 0; server < opt->num_servers; server++) {
unsigned long long total_size = 0;
@@ -289,7 +292,7 @@ void dirProcess(const string path, unsigned long long &checked,
path.c_str(), getdir,
(sizeof(struct dirent_extended) + 255) * 1024 * 100, server);
struct dirent_extended *temp = getdir;
if (opt->verbosity) cout << "[" << n << "] " << path.c_str() << endl;
while (total_size < n) {
if (strlen(temp->d_name) == 0)
break;
@@ -307,15 +310,18 @@ void dirProcess(const string path, unsigned long long &checked,
}
/* Find filtering */
auto timeOK = true;
if (opt->timestamp_file) {
if (opt->timestamp_file.size()) {
if ((uint64_t)temp->ctime < runtime.ctime_min)
timeOK = false;
}
if (timeOK and (temp->size == opt->size or opt->size == std::numeric_limits<uint64_t>::max()))
if (!(opt->name_pattern &&
regexec(&opt->name_regex, temp->d_name, 0, nullptr, 0)))
found++;
checked++;
if (opt->verbosity) cout << temp->d_name << endl;
temp = reinterpret_cast<dirent_extended *>(reinterpret_cast<char *>(temp) + temp->d_reclen);
}
}
@@ -329,11 +335,11 @@ int process(pfind_options_t *opt) {
checked = 0;
memset(&runtime, 0, sizeof(pfind_runtime_options_t));
/* Get timestamp file */
if (opt->timestamp_file) {
if (opt->timestamp_file.size()) {
if (pfind_rank == 0) {
static struct stat timer_file{};
if (lstat(opt->timestamp_file, &timer_file) != 0) {
printf("Could not open: \"%s\", error: %s", opt->timestamp_file,
if (lstat(opt->timestamp_file.c_str(), &timer_file) != 0) {
printf("Could not open: \"%s\", error: %s", opt->timestamp_file.c_str(),
strerror(errno));
pfind_abort("\n");
}
@@ -343,15 +349,16 @@ int process(pfind_options_t *opt) {
queue<string> dirs;
string workdir = opt->workdir;
workdir = workdir.substr(strlen(opt->mountdir), workdir.size());
workdir = workdir.substr(opt->mountdir.size(), workdir.size());
if (workdir.size() == 0)
workdir = "/";
dirs.push(workdir);
do {
string processpath = dirs.front();
dirs.pop();
if (opt->verbosity) cout << processpath << endl;
dirProcess(processpath, checked, found, dirs, 0, 1, opt);
// cout << "NO more paths " << dirs.size() << endl;
} while (!dirs.empty());
Loading