summaryrefslogtreecommitdiffstats
path: root/tools/glusterfind
diff options
context:
space:
mode:
authorAravinda VK <avishwan@redhat.com>2015-06-10 14:47:21 +0530
committerVijay Bellur <vbellur@redhat.com>2015-06-12 03:07:47 -0700
commit9e72abb08f37db017a83e0114e9cd07fd5151d30 (patch)
tree8d96e1f1664316b03381df56c328e1d90936dc74 /tools/glusterfind
parent57ecbbd6ce5b682a9e69c775ace48588d6535396 (diff)
tools/glusterfind: Cleanup session dir after delete
Sessions directories are created in /var/lib/glusterd/glusterfind/<SESSION>/<VOLUME>, only <VOLUME> dir is created since same session name can exists for two volumes. Now cleanup is added, <SESSION> dir will be removed if <SESSION> contains only one Volume. Change-Id: I236393659e63eb98342570e0255739f4adea4491 Signed-off-by: Aravinda VK <avishwan@redhat.com> BUG: 1230111 Reviewed-on: http://review.gluster.org/11157 Reviewed-by: Kotresh HR <khiremat@redhat.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com> Tested-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'tools/glusterfind')
-rw-r--r--tools/glusterfind/src/main.py11
-rw-r--r--tools/glusterfind/src/nodeagent.py10
2 files changed, 20 insertions, 1 deletions
diff --git a/tools/glusterfind/src/main.py b/tools/glusterfind/src/main.py
index 16dc18bd732..850024be2fe 100644
--- a/tools/glusterfind/src/main.py
+++ b/tools/glusterfind/src/main.py
@@ -9,7 +9,7 @@
# cases as published by the Free Software Foundation.
import sys
-from errno import ENOENT
+from errno import ENOENT, ENOTEMPTY
import time
from multiprocessing import Process
import os
@@ -454,6 +454,15 @@ def mode_delete(session_dir, args):
shutil.rmtree(os.path.join(session_dir, args.volume),
onerror=handle_rm_error)
+ # If the session contains only this volume, then cleanup the
+ # session directory. If a session contains multiple volumes
+ # then os.rmdir will fail with ENOTEMPTY
+ try:
+ os.rmdir(session_dir)
+ except OSError as e:
+ if not e.errno == ENOTEMPTY:
+ logger.warn("Failed to delete session directory: %s" % e)
+
def mode_list(session_dir, args):
"""
diff --git a/tools/glusterfind/src/nodeagent.py b/tools/glusterfind/src/nodeagent.py
index 2e8c2fc9759..e7ba4afa4cb 100644
--- a/tools/glusterfind/src/nodeagent.py
+++ b/tools/glusterfind/src/nodeagent.py
@@ -14,6 +14,7 @@ import os
import logging
from argparse import ArgumentParser, RawDescriptionHelpFormatter
import urllib
+from errno import ENOTEMPTY
from utils import setup_logger, mkdirp, handle_rm_error
import conf
@@ -78,6 +79,15 @@ def mode_delete(args):
shutil.rmtree(os.path.join(session_dir, args.volume),
onerror=handle_rm_error)
+ # If the session contains only this volume, then cleanup the
+ # session directory. If a session contains multiple volumes
+ # then os.rmdir will fail with ENOTEMPTY
+ try:
+ os.rmdir(session_dir)
+ except OSError as e:
+ if not e.errno == ENOTEMPTY:
+ logger.warn("Failed to delete session directory: %s" % e)
+
def _get_args():
parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter,