From: Radosław Korzeniewski Date: Tue, 30 Nov 2021 16:48:18 +0000 (+0100) Subject: pluginlib: A better handling of STAT:/... command in metaplugin. X-Git-Tag: Beta-15.0.0~737 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e87161b427c72a85b18136c73e31cf37d09502b0;p=thirdparty%2Fbacula.git pluginlib: A better handling of STAT:/... command in metaplugin. --- diff --git a/bacula/src/plugins/fd/pluginlib/metaplugin.cpp b/bacula/src/plugins/fd/pluginlib/metaplugin.cpp index 05ef0bb47..4c716cf88 100644 --- a/bacula/src/plugins/fd/pluginlib/metaplugin.cpp +++ b/bacula/src/plugins/fd/pluginlib/metaplugin.cpp @@ -786,6 +786,7 @@ bRC METAPLUGIN::send_parameters(bpContext *ctx, char *command) "regress_error_restore_stderr", "regress_backup_plugin_objects", "regress_backup_other_file", + "regress_backup_external_stat", "regress_error_backup_abort", "regress_metadata_support", "regress_standard_error_backup", @@ -2385,7 +2386,8 @@ bRC METAPLUGIN::startBackupFile(bpContext *ctx, struct save_pkt *sp) return bRC_Error; case metaplugin::attributes::Status_OK: - if (sp->type != FT_LNK) { + if (sp->type != FT_LNK) + { reqparams--; } continue; diff --git a/bacula/src/plugins/fd/pluginlib/metaplugin_attributes.cpp b/bacula/src/plugins/fd/pluginlib/metaplugin_attributes.cpp index f69d1a88d..7ec7056ff 100644 --- a/bacula/src/plugins/fd/pluginlib/metaplugin_attributes.cpp +++ b/bacula/src/plugins/fd/pluginlib/metaplugin_attributes.cpp @@ -71,8 +71,12 @@ namespace attributes if (rc < 0) { // error - DMSG1(ctx, DERROR, "Invalid path: %s\n", param.c_str()); - return Invalid_Stat_Packet; + berrno be; + DMSG3(ctx, DERROR, "Invalid STAT path: %s Err=%s (%d)\n", param.c_str(), be.bstrerror(), be.code()); + JMSG3(ctx, M_ERROR, "Invalid STAT path: %s Err=%s (%d)\n", param.c_str(), be.bstrerror(), be.code()); + memset(&sp->statp, 0, sizeof(sp->statp)); + sp->type = FT_REG; + return Status_Handled; } // stat is working as expected DMSG1(ctx, DDEBUG, "read_scan_stat_command():stat: %o\n", sp->statp.st_mode); @@ -97,7 +101,9 @@ namespace attributes // error reading link value DMSG2(ctx, DERROR, "Error reading link value. Err=%s (%d)", be.bstrerror(), be.code()); JMSG3(ctx, M_ERROR, "Error reading link value: %s, Err=%s (%d)", param.c_str(), be.bstrerror(), be.code()); - return Status_Error; + memset(&sp->statp, 0, sizeof(sp->statp)); + sp->type = FT_REG; + return Status_Handled; } lname.c_str()[rc] = '\0'; sp->link = lname.c_str(); diff --git a/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c b/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c index 7291fd921..2ec429298 100644 --- a/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c +++ b/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c @@ -73,6 +73,7 @@ bool regress_metadata_support = false; bool regress_standard_error_backup = false; bool regress_cancel_backup = false; bool regress_cancel_restore = false; +bool regress_backup_external_stat = false; bool Job_Level_Incremental = false; @@ -1211,6 +1212,19 @@ void perform_backup() signal_eod(); signal_eod(); + // + if (regress_backup_external_stat) + { + // the file with external stat(2) packet + snprintf(buf, BIGBUFLEN, "FNAME:%s/java/%d/stat.error\n", PLUGINPREFIX, mypid); + write_plugin('C', buf); + snprintf(buf, BIGBUFLEN, "STAT:%s\n", "/nonexistent.file"); + write_plugin('C', buf); + write_plugin('I', "TEST18NEX"); + signal_eod(); + signal_eod(); + } + // this plugin object should be the latest item to backup if (regress_backup_plugin_objects) { @@ -1669,67 +1683,88 @@ int main(int argc, char** argv) { // "regress_cancel_backup", // "regress_cancel_restore", - if (strcmp(buf, "regress_error_plugin_params=1\n") == 0) { + if (strcmp(buf, "regress_error_plugin_params=1\n") == 0) + { regress_error_plugin_params = true; continue; } - if (strcmp(buf, "regress_error_start_job=1\n") == 0) { + if (strcmp(buf, "regress_error_start_job=1\n") == 0) + { regress_error_start_job = true; continue; } - if (strcmp(buf, "regress_error_backup_no_files=1\n") == 0) { + if (strcmp(buf, "regress_error_backup_no_files=1\n") == 0) + { regress_error_backup_no_files = true; continue; } - if (strcmp(buf, "regress_error_backup_stderr=1\n") == 0) { + if (strcmp(buf, "regress_error_backup_stderr=1\n") == 0) + { regress_error_backup_stderr = true; continue; } - if (strcmp(buf, "regress_error_estimate_stderr=1\n") == 0) { + if (strcmp(buf, "regress_error_estimate_stderr=1\n") == 0) + { regress_error_estimate_stderr = true; continue; } - if (strcmp(buf, "regress_error_listing_stderr=1\n") == 0) { + if (strcmp(buf, "regress_error_listing_stderr=1\n") == 0) + { regress_error_listing_stderr = true; continue; } - if (strcmp(buf, "regress_error_restore_stderr=1\n") == 0) { + if (strcmp(buf, "regress_error_restore_stderr=1\n") == 0) + { regress_error_restore_stderr = true; continue; } - if (strcmp(buf, "regress_backup_plugin_objects=1\n") == 0) { + if (strcmp(buf, "regress_backup_plugin_objects=1\n") == 0) + { regress_backup_plugin_objects = true; continue; } - if (strcmp(buf, "regress_error_backup_abort=1\n") == 0) { + if (strcmp(buf, "regress_error_backup_abort=1\n") == 0) + { regress_error_backup_abort = true; continue; } - if (strcmp(buf, "regress_backup_other_file=1\n") == 0) { + if (strcmp(buf, "regress_backup_other_file=1\n") == 0) + { regress_backup_other_file = true; continue; } - if (strcmp(buf, "regress_metadata_support=1\n") == 0) { + if (strcmp(buf, "regress_backup_external_stat=1\n") == 0) + { + regress_backup_external_stat = true; + continue; + } + if (strcmp(buf, "regress_metadata_support=1\n") == 0) + { regress_metadata_support = true; continue; } - if (strcmp(buf, "regress_standard_error_backup=1\n") == 0) { + if (strcmp(buf, "regress_standard_error_backup=1\n") == 0) + { regress_standard_error_backup = true; continue; } - if (strcmp(buf, "regress_cancel_backup=1\n") == 0) { + if (strcmp(buf, "regress_cancel_backup=1\n") == 0) + { regress_cancel_backup = true; continue; } - if (strcmp(buf, "regress_cancel_restore=1\n") == 0) { + if (strcmp(buf, "regress_cancel_restore=1\n") == 0) + { regress_cancel_restore = true; continue; } - if (sscanf(buf, "listing=%s\n", buf) == 1){ + if (sscanf(buf, "listing=%s\n", buf) == 1) + { strcpy(listing, buf); continue; } - if (sscanf(buf, "query=%s\n", buf) == 1){ + if (sscanf(buf, "query=%s\n", buf) == 1) + { strcpy(query, buf); continue; } @@ -1739,14 +1774,17 @@ int main(int argc, char** argv) { continue; } } - if (regress_cancel_restore || regress_cancel_backup) { - if (signal(SIGUSR1, catch_function) == SIG_ERR){ + if (regress_cancel_restore || regress_cancel_backup) + { + if (signal(SIGUSR1, catch_function) == SIG_ERR) + { LOG("Cannot setup signal handler!"); exit(EXIT_BACKEND_SIGNAL_HANDLER_ERROR); } } write_plugin('I', "TEST3"); - if (!regress_error_plugin_params){ + if (!regress_error_plugin_params) + { signal_eod(); } else { write_plugin('E', "We do not accept your TEST3E! AsRequest."); @@ -1756,7 +1794,8 @@ int main(int argc, char** argv) { len = read_plugin(buf); write_plugin('I', "TEST4"); - if (regress_error_start_job){ + if (regress_error_start_job) + { write_plugin('A', "We do not accept your TEST4E! AsRequest."); goto Term; }