From: Ondrej Kozina Date: Mon, 25 Feb 2013 17:48:25 +0000 (+0100) Subject: - add support for XA undo statistics X-Git-Tag: v0.1.3~18^2~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=04a8a5a5e4fb6e654358bee328cd055e5c9976d5;p=thirdparty%2Fsnapper.git - add support for XA undo statistics --- diff --git a/snapper/Comparison.cc b/snapper/Comparison.cc index 4db8f173..100e967a 100644 --- a/snapper/Comparison.cc +++ b/snapper/Comparison.cc @@ -26,6 +26,7 @@ #include #include +#include "config.h" #include "snapper/Comparison.h" #include "snapper/Snapper.h" #include "snapper/Log.h" @@ -258,6 +259,17 @@ namespace snapper return files.getUndoStatistic(); } +#ifdef ENABLE_XATTRS + XAUndoStatistic + Comparison::getXAUndoStatistic() const + { + if (getSnapshot1()->isCurrent()) + throw IllegalSnapshotException(); + + return files.getXAUndoStatistic(); + } +#endif + vector Comparison::getUndoSteps() const diff --git a/snapper/Comparison.h b/snapper/Comparison.h index 7576c836..c0884c44 100644 --- a/snapper/Comparison.h +++ b/snapper/Comparison.h @@ -50,6 +50,9 @@ namespace snapper void umount() const; UndoStatistic getUndoStatistic() const; +#ifdef ENABLE_XATTRS + XAUndoStatistic getXAUndoStatistic() const; +#endif vector getUndoSteps() const; diff --git a/snapper/File.cc b/snapper/File.cc index d5e916ae..f1028c29 100644 --- a/snapper/File.cc +++ b/snapper/File.cc @@ -590,7 +590,7 @@ namespace snapper } */ bool - File::modifyXattributes() const + File::modifyXattributes() { bool ret_val; @@ -601,6 +601,12 @@ namespace snapper XAModification xa_mod(xa_src, xa_dest); y2deb("xa_modmap(xa_dest) object: " << xa_mod); + xaCreated = xa_mod.getXaCreateNum(); + xaDeleted = xa_mod.getXaDeleteNum(); + xaReplaced = xa_mod.getXaReplaceNum(); + + y2deb("xaCreated:" << xaCreated << ",xaDeleted:" << xaDeleted << ",xaReplaced:" << xaReplaced); + ret_val = xa_mod.serializeTo(getAbsolutePath(LOC_SYSTEM)); } catch (XAttributesException xae) { @@ -610,6 +616,42 @@ namespace snapper return ret_val; } + XAUndoStatistic& operator+=(XAUndoStatistic &out, const XAUndoStatistic &src) + { + out.numCreate += src.numCreate; + out.numDelete += src.numDelete; + out.numReplace += src.numReplace; + + return out; + } + + XAUndoStatistic + File::getXAUndoStatistic() const + { + XAUndoStatistic xs; + + xs.numCreate = xaCreated; + xs.numDelete = xaDeleted; + xs.numReplace = xaReplaced; + + return xs; + } + + XAUndoStatistic + Files::getXAUndoStatistic() const + { + XAUndoStatistic xs; + + for (vector::const_iterator it = entries.begin(); it != entries.end(); ++it) + { + if (it->getUndo() && (it->getPreToPostStatus() & (DELETED | XATTRS | TYPE))) + { + xs += it->getXAUndoStatistic(); + } + } + + return xs; + } #endif bool diff --git a/snapper/File.h b/snapper/File.h index c61e69c9..f3843925 100644 --- a/snapper/File.h +++ b/snapper/File.h @@ -23,7 +23,7 @@ #ifndef SNAPPER_FILE_H #define SNAPPER_FILE_H - +#include "config.h" #include #include @@ -77,6 +77,19 @@ namespace snapper friend std::ostream& operator<<(std::ostream& s, const UndoStatistic& rs); }; +#ifdef ENABLE_XATTRS + struct XAUndoStatistic + { + XAUndoStatistic(): numCreate(0), numReplace(0), numDelete(0) {} + + unsigned int numCreate; + unsigned int numReplace; + unsigned int numDelete; + + friend XAUndoStatistic& operator+=(XAUndoStatistic&, const XAUndoStatistic&); + }; +#endif + struct UndoStep { @@ -103,6 +116,9 @@ namespace snapper File(const FilePaths* file_paths, const string& name, unsigned int pre_to_post_status) : file_paths(file_paths), name(name), pre_to_post_status(pre_to_post_status), pre_to_system_status(-1), post_to_system_status(-1), undo(false) +#ifdef ENABLE_XATTRS + ,xaCreated(0), xaDeleted(0), xaReplaced(0) +#endif {} const string& getName() const { return name; } @@ -123,6 +139,9 @@ namespace snapper friend std::ostream& operator<<(std::ostream& s, const File& file); +#ifdef ENABLE_XATTRS + XAUndoStatistic getXAUndoStatistic() const; +#endif private: bool createParentDirectories(const string& path) const; @@ -135,9 +154,7 @@ namespace snapper bool deleteAllTypes() const; bool modifyAllTypes() const; -#ifdef ENABLE_XATTRS - bool modifyXattributes() const; -#endif + const FilePaths* file_paths; string name; @@ -148,6 +165,13 @@ namespace snapper bool undo; +#ifdef ENABLE_XATTRS + bool modifyXattributes(); + + unsigned int xaCreated; + unsigned int xaDeleted; + unsigned int xaReplaced; +#endif }; @@ -184,7 +208,9 @@ namespace snapper vector getUndoSteps() const; bool doUndoStep(const UndoStep& undo_step); - +#ifdef ENABLE_XATTRS + XAUndoStatistic getXAUndoStatistic() const; +#endif protected: void push_back(File file) { entries.push_back(file); } diff --git a/snapper/XAttributes.cc b/snapper/XAttributes.cc index 211707df..cd8e87ea 100644 --- a/snapper/XAttributes.cc +++ b/snapper/XAttributes.cc @@ -384,6 +384,24 @@ namespace snapper return true; } + unsigned int + XAModification::getXaCreateNum() const + { + return this->operator[](XA_CREATE).size(); + } + + unsigned int + XAModification::getXaDeleteNum() const + { + return this->operator[](XA_DELETE).size(); + } + + unsigned int + XAModification::getXaReplaceNum() const + { + return this->operator[](XA_REPLACE).size(); + } + ostream& operator<<(ostream &out, const XAModification &xa_mod) { diff --git a/snapper/XAttributes.h b/snapper/XAttributes.h index 9319aeb4..c1e8b201 100644 --- a/snapper/XAttributes.h +++ b/snapper/XAttributes.h @@ -93,6 +93,11 @@ namespace snapper bool isEmpty() const; bool serializeTo(const string&) const; + + unsigned int getXaCreateNum() const; + unsigned int getXaDeleteNum() const; + unsigned int getXaReplaceNum() const; + xa_mod_citer cbegin() const { return xamodmap.begin(); }; xa_mod_citer cend() const { return xamodmap.end(); }; diff --git a/testsuite-real/common.cc b/testsuite-real/common.cc index e9048297..7c1da5ce 100644 --- a/testsuite-real/common.cc +++ b/testsuite-real/common.cc @@ -4,6 +4,7 @@ #include #include +#include "config.h" #include "common.h" #include @@ -27,6 +28,9 @@ Snapshots::iterator first; Snapshots::iterator second; unsigned int numCreateErrors, numModifyErrors, numDeleteErrors; +#ifdef ENABLE_XATTRS +unsigned int xaCreate, xaReplace, xaDelete; +#endif void @@ -81,6 +85,16 @@ check_undo_statistics(unsigned int numCreate, unsigned int numModify, unsigned i } +#ifdef ENABLE_XATTRS +void +check_xa_undo_statistics(unsigned int xaNumCreate, unsigned xaNumReplace, unsigned int xaNumDelete) +{ + check_equal(xaCreate, xaNumCreate); + check_equal(xaDelete, xaNumDelete); + check_equal(xaReplace, xaNumReplace); +} +#endif + void undo() { @@ -120,6 +134,14 @@ undo() } cout << "undoing done" << endl; + +#ifdef ENABLE_XATTRS + XAUndoStatistic xs = files.getXAUndoStatistic(); + xaCreate = xs.numCreate; + xaReplace = xs.numReplace; + xaDelete = xs.numDelete; +#endif + } diff --git a/testsuite-real/common.h b/testsuite-real/common.h index 1b4d1d38..7ea57107 100644 --- a/testsuite-real/common.h +++ b/testsuite-real/common.h @@ -50,6 +50,7 @@ void first_snapshot(); void second_snapshot(); void check_undo_statistics(unsigned int numCreate, unsigned int numModify, unsigned int numDelete); +void check_xa_undo_statistics(unsigned int xaNumCreate, unsigned int xaNumReplace, unsigned int xaNumDelete); void undo(); void check_undo_errors(unsigned int numCreate, unsigned int numModify, unsigned int numDelete); diff --git a/testsuite-real/xattrs1.cc b/testsuite-real/xattrs1.cc index ed90a718..ebf2589e 100644 --- a/testsuite-real/xattrs1.cc +++ b/testsuite-real/xattrs1.cc @@ -21,16 +21,21 @@ main() run_command("setfacl -b file1"); xattr_remove("user.aaa","/testsuite/file1"); xattr_replace("user.bbb", "bbb-new-value", "/testsuite/file1"); + xattr_create("user.ccc", "ccc-value", "/testsuite/file1"); second_snapshot(); + undo(); + check_undo_statistics(0, 1, 0); - undo(); + check_xa_undo_statistics(2, 1, 1); check_undo_errors(0, 0, 0); check_first(); + cleanup(); + exit(EXIT_SUCCESS); }