| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/** |
| 2 |
|
|
* This file is part of the CernVM File System. |
| 3 |
|
|
*/ |
| 4 |
|
|
|
| 5 |
|
|
#ifndef CVMFS_SWISSKNIFE_SCRUB_H_ |
| 6 |
|
|
#define CVMFS_SWISSKNIFE_SCRUB_H_ |
| 7 |
|
|
|
| 8 |
|
|
#include <cassert> |
| 9 |
|
|
#include <string> |
| 10 |
|
|
|
| 11 |
|
|
#include "crypto/hash.h" |
| 12 |
|
|
#include "ingestion/pipeline.h" |
| 13 |
|
|
#include "swissknife.h" |
| 14 |
|
|
|
| 15 |
|
|
namespace swissknife { |
| 16 |
|
|
|
| 17 |
|
|
class CommandScrub : public Command { |
| 18 |
|
|
public: |
| 19 |
|
|
CommandScrub(); |
| 20 |
|
|
~CommandScrub(); |
| 21 |
|
✗ |
virtual std::string GetName() const { return "scrub"; } |
| 22 |
|
✗ |
virtual std::string GetDescription() const { |
| 23 |
|
|
return "CernVM File System repository file storage checker. Finds silent " |
| 24 |
|
|
"disk corruptions by recomputing all file content checksums in the " |
| 25 |
|
✗ |
"backend file storage."; |
| 26 |
|
|
} |
| 27 |
|
|
virtual ParameterList GetParams() const; |
| 28 |
|
|
int Main(const ArgumentList &args); |
| 29 |
|
|
|
| 30 |
|
|
|
| 31 |
|
|
protected: |
| 32 |
|
|
struct Alerts { |
| 33 |
|
|
enum Type { |
| 34 |
|
|
kUnexpectedFile = 1, |
| 35 |
|
|
kUnexpectedSymlink, |
| 36 |
|
|
kUnexpectedSubdir, |
| 37 |
|
|
kUnexpectedModifier, |
| 38 |
|
|
kMalformedHash, |
| 39 |
|
|
kMalformedCasSubdir, |
| 40 |
|
|
kContentHashMismatch, |
| 41 |
|
|
kNumberOfErrorTypes // This should _always_ stay the last entry! |
| 42 |
|
|
}; |
| 43 |
|
|
|
| 44 |
|
|
static const char *ToString(const Type t); |
| 45 |
|
|
}; |
| 46 |
|
|
|
| 47 |
|
|
void FileCallback(const std::string &relative_path, |
| 48 |
|
|
const std::string &file_name); |
| 49 |
|
|
void DirCallback(const std::string &relative_path, |
| 50 |
|
|
const std::string &dir_name); |
| 51 |
|
|
void SymlinkCallback(const std::string &relative_path, |
| 52 |
|
|
const std::string &symlink_name); |
| 53 |
|
|
|
| 54 |
|
|
void OnFileHashed(const ScrubbingResult &scrubbing_result); |
| 55 |
|
|
|
| 56 |
|
|
void PrintAlert(const Alerts::Type type, |
| 57 |
|
|
const std::string &path, |
| 58 |
|
|
const std::string &affected_hash = "") const; |
| 59 |
|
|
void ShowAlertsHelpMessage() const; |
| 60 |
|
|
|
| 61 |
|
|
private: |
| 62 |
|
|
std::string CheckPathAndExtractHash(const std::string &relative_path, |
| 63 |
|
|
const std::string &file_name, |
| 64 |
|
|
const std::string &full_path) const; |
| 65 |
|
|
bool CheckHashString(const std::string &hash_string, |
| 66 |
|
|
const std::string &full_path) const; |
| 67 |
|
|
|
| 68 |
|
|
std::string MakeFullPath(const std::string &relative_path, |
| 69 |
|
|
const std::string &file_name) const; |
| 70 |
|
|
std::string MakeRelativePath(const std::string &full_path); |
| 71 |
|
|
|
| 72 |
|
|
ScrubbingPipeline pipeline_scrubbing_; |
| 73 |
|
|
std::string repo_path_; |
| 74 |
|
|
bool machine_readable_output_; |
| 75 |
|
|
|
| 76 |
|
|
mutable unsigned int alerts_; |
| 77 |
|
|
mutable pthread_mutex_t alerts_mutex_; |
| 78 |
|
|
}; |
| 79 |
|
|
|
| 80 |
|
|
} // namespace swissknife |
| 81 |
|
|
|
| 82 |
|
|
#endif // CVMFS_SWISSKNIFE_SCRUB_H_ |
| 83 |
|
|
|