Skip to content

Commit

Permalink
Use libgfapi, or fall back to the gluster CLI to fetch the volfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Julian committed Feb 24, 2015
1 parent 3181687 commit 4f9a2d1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 109 deletions.
55 changes: 55 additions & 0 deletions splitmount/rpc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/python

import ctypes
import ctypes.util
import subprocess

def cli_get_volfile (host, volume):
res = subprocess.check_output(["/usr/sbin/gluster","--remote-host={}".format(host),
"system","getspec",volume])
return res

def api_get_volfile (host, volume):
# This is set to a large value to exercise the "buffer not big enough"
# path. More realistically, you'd just start with a huge buffer.
BUF_LEN = 0
fs = api.glfs_new(volume)
#api.glfs_set_logging(fs,"/dev/stderr",7)
api.glfs_set_volfile_server(fs,"tcp",host,24007)
api.glfs_init(fs)
vbuf = ctypes.create_string_buffer(BUF_LEN)
vlen = api.glfs_get_volfile(fs,vbuf,BUF_LEN)
if vlen < 0:
vlen = BUF_LEN - vlen
vbuf = ctypes.create_string_buffer(vlen)
vlen = api.glfs_get_volfile(fs,vbuf,vlen)
api.glfs_fini(fs)
if vlen <= 0:
return vlen
return vbuf.value[:vlen]

api = ctypes.CDLL(ctypes.util.find_library("gfapi"))
try:
api.glfs_get_volfile.argtypes = [ctypes.c_void_p,
ctypes.c_void_p,
ctypes.c_ulong]
api.glfs_get_volfile.restype = ctypes.c_long;
get_volfile = api_get_volfile
except:
get_volfile = cli_get_volfile

if __name__ == "__main__":
import sys

try:
res = apply(get_volfile,sys.argv[1:3])
except:
print "fetching volfile failed (volume not started?)"
raise

try:
for line in res.split('\n'):
print line
except:
print "bad return value %s" % res
raise
Empty file removed splitmount/rpc/__init__.py
Empty file.
107 changes: 0 additions & 107 deletions splitmount/rpc/fetchvol.py

This file was deleted.

4 changes: 2 additions & 2 deletions splitmount/splitmount.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#
# Copyright 2014, Joe Julian <[email protected]>
#
import rpc.fetchvol
import rpc
import os,sys,re
import tempfile
import subprocess
Expand Down Expand Up @@ -50,7 +50,7 @@ def main():
print 'of that directory, or choose another directory.'
exit(1)

orig_vol = rpc.fetchvol.fetch_volfile(server, volume)
orig_vol = rpc.get_volfile(server, volume)
regex = re.compile(r'(^volume\s.+?end-volume)', re.VERBOSE|re.MULTILINE|re.DOTALL)
graph = [ x.strip("\n") for x in regex.split(orig_vol) if x.strip("\n") ]
newgraph = []
Expand Down

0 comments on commit 4f9a2d1

Please sign in to comment.