scripts/volfilter.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 50 insertions(+), 1 deletion(-)
New commits:
commit 928766a775474459a6bac9108506db3430264ea7
Author: Jeff Darcy <jdarcy(a)redhat.com>
Date: Tue Apr 19 11:46:27 2011 -0400
Changes got left out of previous cloudfsd-branch commit.
diff --git a/scripts/volfilter.py b/scripts/volfilter.py
index 98ab20e..1b61595 100755
--- a/scripts/volfilter.py
+++ b/scripts/volfilter.py
@@ -17,8 +17,52 @@
# You should have received a copy of the GNU Affero General Public License *
# along with CloudFS. If not, see <
http://www.gnu.org/licenses/>.
+import copy
import string
import sys
+import types
+
+good_xlators = [
+ "cluster/afr",
+ "cluster/dht",
+ "cluster/distribute",
+ "cluster/replicate",
+ "cluster/stripe",
+ "debug/io-stats",
+ "features/access-control",
+ "features/locks",
+ "features/marker",
+ "performance/io-threads",
+ "protocol/client",
+ "protocol/server",
+ "storage/posix",
+]
+
+def copy_stack (old_xl,suffix,recursive=False):
+ if recursive:
+ new_name = old_xl.name + "-" + suffix
+ else:
+ new_name = suffix
+ new_xl = Translator(new_name)
+ new_xl.type = old_xl.type
+ # The results with normal assignment here are . . . amusing.
+ new_xl.opts = copy.deepcopy(old_xl.opts)
+ for sv in old_xl.subvols:
+ new_xl.subvols.append(copy_stack(sv,suffix,True))
+ # Patch up the path at the bottom.
+ if new_xl.type == "storage/posix":
+ new_xl.opts["directory"] += ("/" + suffix)
+ return new_xl
+
+def cleanup (parent, graph):
+ if parent.type in good_xlators:
+ sv = []
+ for child in parent.subvols:
+ sv.append(cleanup(child,graph))
+ parent.subvols = sv
+ else:
+ parent = cleanup(parent.subvols[0],graph)
+ return parent
class Translator:
def __init__ (self, name):
@@ -31,7 +75,12 @@ class Translator:
return "<Translator %s>" % self.name
def load (path):
- fp = file(path,"r")
+ # If it's a string, open it; otherwise, assume it's already a
+ # file-like object (most notably from urllib*).
+ if type(path) in types.StringTypes:
+ fp = file(path,"r")
+ else:
+ fp = path
all_xlators = {}
xlator = None
last_xlator = None