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