From 4992f2f8f3deb837e18d111013367be5d5fff0a6 Mon Sep 17 00:00:00 2001 From: Aravinda VK Date: Thu, 11 Jun 2015 18:37:16 +0530 Subject: [PATCH 63/73] tools/glusterfind: Cleanup glusterfind dir after a volume delete If `glusterfind delete` command was not run before volume delete, stale session directories exists in /var/lib/glusterd/glusterfind directories. Also shows these sessions in `glusterfind list` When Volume is deleted, Post hook will be run which cleans up the stale session directories BUG: 1224880 Change-Id: I54c46c30313e92c1bb4cb07918ed2029b375462c Signed-off-by: Aravinda VK Reviewed-On: http://review.gluster.org/10944 Reviewed-On: http://review.gluster.org/11186 Reviewed-on: https://code.engineering.redhat.com/gerrit/50541 Reviewed-by: Saravanakumar Arumugam --- extras/hook-scripts/Makefile.am | 7 ++- extras/hook-scripts/S57glusterfind-delete-post.py | 60 +++++++++++++++++++++ glusterfs.spec.in | 6 ++ 3 files changed, 72 insertions(+), 1 deletions(-) create mode 100755 extras/hook-scripts/S57glusterfind-delete-post.py diff --git a/extras/hook-scripts/Makefile.am b/extras/hook-scripts/Makefile.am index 771b37e..b5e2ae6 100644 --- a/extras/hook-scripts/Makefile.am +++ b/extras/hook-scripts/Makefile.am @@ -1,7 +1,12 @@ -EXTRA_DIST = S40ufo-stop.py S56glusterd-geo-rep-create-post.sh +EXTRA_DIST = S40ufo-stop.py S56glusterd-geo-rep-create-post.sh \ + S57glusterfind-delete-post.py + SUBDIRS = add-brick set start stop reset scriptsdir = $(GLUSTERD_WORKDIR)/hooks/1/gsync-create/post/ if USE_GEOREP scripts_SCRIPTS = S56glusterd-geo-rep-create-post.sh endif + +deletehookscriptsdir = $(GLUSTERD_WORKDIR)/hooks/1/delete/post/ +deletehookscripts_SCRIPTS = S57glusterfind-delete-post.py diff --git a/extras/hook-scripts/S57glusterfind-delete-post.py b/extras/hook-scripts/S57glusterfind-delete-post.py new file mode 100755 index 0000000..70edb56 --- /dev/null +++ b/extras/hook-scripts/S57glusterfind-delete-post.py @@ -0,0 +1,60 @@ +#!/usr/bin/python +import os +import shutil +from errno import ENOENT +from subprocess import Popen, PIPE +from argparse import ArgumentParser + + +DEFAULT_GLUSTERD_WORKDIR = "/var/lib/glusterd" + + +def handle_rm_error(func, path, exc_info): + if exc_info[1].errno == ENOENT: + return + + raise exc_info[1] + + +def get_glusterd_workdir(): + p = Popen(["gluster", "system::", "getwd"], + stdout=PIPE, stderr=PIPE) + + out, _ = p.communicate() + + if p.returncode == 0: + return out.strip() + else: + return DEFAULT_GLUSTERD_WORKDIR + + +def get_args(): + parser = ArgumentParser(description="Volume delete post hook script") + parser.add_argument("--volname") + return parser.parse_args() + + +def main(): + args = get_args() + glusterfind_dir = os.path.join(get_glusterd_workdir(), "glusterfind") + + # Check all session directories, if any directory found for + # the deleted volume, cleanup all the session directories + for session in os.listdir(glusterfind_dir): + # Possible session directory + volume_session_path = os.path.join(glusterfind_dir, + session, + args.volname) + if os.path.exists(volume_session_path): + shutil.rmtree(volume_session_path, onerror=handle_rm_error) + + # Try to Remove directory, if any other dir exists for different + # volume, then rmdir will fail with ENOTEMPTY which is fine + try: + os.rmdir(os.path.join(glusterfind_dir, session)) + except (OSError, IOError): + pass + + +if __name__ == "__main__": + main() diff --git a/glusterfs.spec.in b/glusterfs.spec.in index 4b02f85..aadfe70 100644 --- a/glusterfs.spec.in +++ b/glusterfs.spec.in @@ -991,6 +991,9 @@ fi %exclude %{_libexecdir}/glusterfs/glusterfind %exclude %{_bindir}/glusterfind %exclude %{_libexecdir}/glusterfs/peer_add_secret_pub +%{_sharedstatedir}/glusterd/hooks/1/delete/post/S57glusterfind-delete-post.py +%exclude %{_sharedstatedir}/glusterd/hooks/1/delete/post/S57glusterfind-delete-post.pyc +%exclude %{_sharedstatedir}/glusterd/hooks/1/delete/post/S57glusterfind-delete-post.pyo # exclude server files %exclude %{_sharedstatedir}/glusterd/* %exclude %{_sysconfdir}/glusterfs @@ -1789,6 +1792,9 @@ end %endif %changelog +* Thu Jun 11 2015 Aravinda VK +- Added post hook for volume delete as part of glusterfind (#1225551) + * Thu Jun 11 2015 Atin Mukherjee - Security hardening flags inclusion (#1200815) -- 1.7.1