summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAravinda VK <avishwan@redhat.com>2014-11-10 12:41:49 +0530
committerVenky Shankar <vshankar@redhat.com>2015-01-18 04:30:42 -0800
commitdec4700c663975896f3aad1b4e59257263b4f4ac (patch)
tree11bab12cd2ca1789d271838d887e45572b34c045
parent2466f4debbb629cf847c42f5d317cd5627b095c1 (diff)
features/changelog: Cleanup .processing and .current directory
On changelog_register cleanup .processing, .history/.processing, .current and .history/.current from the working directory. Moved glusterd_recursive_rmdir and glusterd_for_each_entry to common place(libglusterfs) and renamed as recursive_rmdir and GF_FOR_EACH_ENTRY_IN_DIR respectively BUG: 1162057 Change-Id: I1f98468a344cead039026762a805437b2f9e507b Signed-off-by: Aravinda VK <avishwan@redhat.com> Reviewed-on: http://review.gluster.org/9082 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Venky Shankar <vshankar@redhat.com> Tested-by: Venky Shankar <vshankar@redhat.com>
-rw-r--r--libglusterfs/src/common-utils.c72
-rw-r--r--libglusterfs/src/common-utils.h17
-rw-r--r--xlators/features/changelog/lib/src/gf-changelog.c21
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-hooks.c4
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c6
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.c22
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.h14
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c72
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h3
9 files changed, 126 insertions, 105 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index b1afa082844..3bd7c3d8fa2 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -3558,3 +3558,75 @@ err:
GF_FREE (absolute_path);
return ret;
}
+
+/* This is an utility function which will recursively delete
+ * a folder and its contents.
+ *
+ * @param delete_path folder to be deleted.
+ *
+ * @return 0 on success and -1 on failure.
+ */
+int
+recursive_rmdir (const char *delete_path)
+{
+ int ret = -1;
+ char path[PATH_MAX] = {0,};
+ struct stat st = {0,};
+ DIR *dir = NULL;
+ struct dirent *entry = NULL;
+ xlator_t *this = NULL;
+
+ this = THIS;
+ GF_ASSERT (this);
+ GF_VALIDATE_OR_GOTO (this->name, delete_path, out);
+
+ dir = opendir (delete_path);
+ if (!dir) {
+ gf_log (this->name, GF_LOG_DEBUG, "Failed to open directory %s."
+ " Reason : %s", delete_path, strerror (errno));
+ ret = 0;
+ goto out;
+ }
+
+ GF_FOR_EACH_ENTRY_IN_DIR (entry, dir);
+ while (entry) {
+ snprintf (path, PATH_MAX, "%s/%s", delete_path, entry->d_name);
+ ret = lstat (path, &st);
+ if (ret == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "Failed to stat "
+ "entry %s : %s", path, strerror (errno));
+ goto out;
+ }
+
+ if (S_ISDIR (st.st_mode))
+ ret = recursive_rmdir (path);
+ else
+ ret = unlink (path);
+
+ if (ret) {
+ gf_log (this->name, GF_LOG_DEBUG, " Failed to remove "
+ "%s. Reason : %s", path, strerror (errno));
+ }
+
+ gf_log (this->name, GF_LOG_DEBUG, "%s %s",
+ ret ? "Failed to remove":"Removed",
+ entry->d_name);
+
+ GF_FOR_EACH_ENTRY_IN_DIR (entry, dir);
+ }
+
+ ret = closedir (dir);
+ if (ret) {
+ gf_log (this->name, GF_LOG_DEBUG, "Failed to close dir %s. "
+ "Reason : %s", delete_path, strerror (errno));
+ }
+
+ ret = rmdir (delete_path);
+ if (ret) {
+ gf_log (this->name, GF_LOG_DEBUG, "Failed to rmdir: %s,err: %s",
+ delete_path, strerror (errno));
+ }
+
+out:
+ return ret;
+}
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index 23a932b71aa..2a46f768e75 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -28,6 +28,7 @@
#include <alloca.h>
#endif
#include <limits.h>
+#include <fnmatch.h>
void trap (void);
@@ -273,6 +274,19 @@ union gf_sock_union {
#define IOV_MIN(n) min(IOV_MAX,n)
+#define GF_FOR_EACH_ENTRY_IN_DIR(entry, dir) \
+ do {\
+ entry = NULL;\
+ if (dir) { \
+ entry = readdir (dir); \
+ while (entry && (!strcmp (entry->d_name, ".") || \
+ !fnmatch ("*.tmp", entry->d_name, 0) || \
+ !strcmp (entry->d_name, ".."))) { \
+ entry = readdir (dir); \
+ } \
+ } \
+ } while (0)
+
static inline void
iov_free (struct iovec *vector, int count)
{
@@ -660,4 +674,7 @@ fop_log_level (glusterfs_fop_t fop, int op_errno);
int32_t
gf_build_absolute_path (char *current_path, char *relative_path, char **path);
+int
+recursive_rmdir (const char *delete_path);
+
#endif /* _COMMON_UTILS_H */
diff --git a/xlators/features/changelog/lib/src/gf-changelog.c b/xlators/features/changelog/lib/src/gf-changelog.c
index f3f6ffbe976..a2257a66930 100644
--- a/xlators/features/changelog/lib/src/gf-changelog.c
+++ b/xlators/features/changelog/lib/src/gf-changelog.c
@@ -108,10 +108,22 @@ gf_changelog_open_dirs (gf_changelog_t *gfc)
DIR *dir = NULL;
int tracker_fd = 0;
char tracker_path[PATH_MAX] = {0,};
+ xlator_t *this = NULL;
+
+ this = THIS;
+ GF_ASSERT (this);
(void) snprintf (gfc->gfc_current_dir, PATH_MAX,
"%s/"GF_CHANGELOG_CURRENT_DIR"/",
gfc->gfc_working_dir);
+
+ ret = recursive_rmdir (gfc->gfc_current_dir);
+ if (ret)
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to rmdir: %s, err: %s",
+ gfc->gfc_current_dir, strerror (errno));
+ goto out;
+
ret = mkdir_p (gfc->gfc_current_dir, 0600, _gf_false);
if (ret)
goto out;
@@ -119,6 +131,7 @@ gf_changelog_open_dirs (gf_changelog_t *gfc)
(void) snprintf (gfc->gfc_processed_dir, PATH_MAX,
"%s/"GF_CHANGELOG_PROCESSED_DIR"/",
gfc->gfc_working_dir);
+
ret = mkdir_p (gfc->gfc_processed_dir, 0600, _gf_false);
if (ret)
goto out;
@@ -126,6 +139,14 @@ gf_changelog_open_dirs (gf_changelog_t *gfc)
(void) snprintf (gfc->gfc_processing_dir, PATH_MAX,
"%s/"GF_CHANGELOG_PROCESSING_DIR"/",
gfc->gfc_working_dir);
+
+ ret = recursive_rmdir (gfc->gfc_processing_dir);
+ if (ret)
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to rmdir: %s, err: %s",
+ gfc->gfc_processing_dir, strerror (errno));
+ goto out;
+
ret = mkdir_p (gfc->gfc_processing_dir, 0600, _gf_false);
if (ret)
goto out;
diff --git a/xlators/mgmt/glusterd/src/glusterd-hooks.c b/xlators/mgmt/glusterd/src/glusterd-hooks.c
index f36764e4832..f875c8d36d3 100644
--- a/xlators/mgmt/glusterd/src/glusterd-hooks.c
+++ b/xlators/mgmt/glusterd/src/glusterd-hooks.c
@@ -337,7 +337,7 @@ glusterd_hooks_run_hooks (char *hooks_path, glusterd_op_t op, dict_t *op_ctx,
ret = -1;
line_count = 0;
- glusterd_for_each_entry (entry, hookdir);
+ GF_FOR_EACH_ENTRY_IN_DIR (entry, hookdir);
while (entry) {
if (line_count == N-1) {
N *= 2;
@@ -351,7 +351,7 @@ glusterd_hooks_run_hooks (char *hooks_path, glusterd_op_t op, dict_t *op_ctx,
line_count++;
}
- glusterd_for_each_entry (entry, hookdir);
+ GF_FOR_EACH_ENTRY_IN_DIR (entry, hookdir);
}
lines[line_count] = NULL;
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index 759f5c460f6..f1e5fbb7dda 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -2493,7 +2493,7 @@ remove_brick_path:
}
if (is_brick_dir_present == _gf_true) {
- ret = glusterd_recursive_rmdir (brick_dir);
+ ret = recursive_rmdir (brick_dir);
if (ret) {
if (errno == ENOTEMPTY) {
/* Will occur when multiple glusterds
@@ -7208,7 +7208,7 @@ glusterd_snapshot_restore_cleanup (dict_t *rsp_dict,
}
/* Delete the backup copy of volume folder */
- ret = glusterd_recursive_rmdir (delete_path);
+ ret = recursive_rmdir (delete_path);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to remove "
"backup dir (%s)", delete_path);
@@ -7255,7 +7255,7 @@ glusterd_snapshot_revert_partial_restored_vol (glusterd_volinfo_t *volinfo,
/* Since snapshot restore failed we cannot rely on the volume
* data stored under vols folder. Therefore delete the origin
* volume's backend folder.*/
- ret = glusterd_recursive_rmdir (pathname);
+ ret = recursive_rmdir (pathname);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to remove "
"%s directory", pathname);
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index bde97ceadc9..54c8263a292 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -636,7 +636,7 @@ glusterd_store_remove_bricks (glusterd_volinfo_t *volinfo, char *delete_path)
dir = opendir (brickdir);
- glusterd_for_each_entry (entry, dir);
+ GF_FOR_EACH_ENTRY_IN_DIR (entry, dir);
while (entry) {
snprintf (path, sizeof (path), "%s/%s",
@@ -646,7 +646,7 @@ glusterd_store_remove_bricks (glusterd_volinfo_t *volinfo, char *delete_path)
gf_log (this->name, GF_LOG_DEBUG, "Unable to unlink %s, "
"reason: %s", path, strerror(errno));
}
- glusterd_for_each_entry (entry, dir);
+ GF_FOR_EACH_ENTRY_IN_DIR (entry, dir);
}
closedir (dir);
@@ -1702,7 +1702,7 @@ glusterd_store_delete_volume (glusterd_volinfo_t *volinfo)
goto out;
}
- ret = glusterd_recursive_rmdir (trashdir);
+ ret = recursive_rmdir (trashdir);
if (ret) {
gf_log (this->name, GF_LOG_DEBUG, "Failed to rmdir: %s, Reason:"
" %s", trashdir, strerror (errno));
@@ -1774,7 +1774,7 @@ glusterd_store_delete_snap (glusterd_snap_t *snap)
goto out;
}
- glusterd_for_each_entry (entry, dir);
+ GF_FOR_EACH_ENTRY_IN_DIR (entry, dir);
while (entry) {
snprintf (path, PATH_MAX, "%s/%s", delete_path, entry->d_name);
ret = stat (path, &st);
@@ -1799,7 +1799,7 @@ glusterd_store_delete_snap (glusterd_snap_t *snap)
entry->d_name);
stat_failed:
memset (path, 0, sizeof(path));
- glusterd_for_each_entry (entry, dir);
+ GF_FOR_EACH_ENTRY_IN_DIR (entry, dir);
}
ret = closedir (dir);
@@ -3050,7 +3050,7 @@ glusterd_store_retrieve_volumes (xlator_t *this, glusterd_snap_t *snap)
goto out;
}
- glusterd_for_each_entry (entry, dir);
+ GF_FOR_EACH_ENTRY_IN_DIR (entry, dir);
while (entry) {
if (snap && ((!strcmp (entry->d_name, "geo-replication")) ||
@@ -3084,7 +3084,7 @@ glusterd_store_retrieve_volumes (xlator_t *this, glusterd_snap_t *snap)
}
next:
- glusterd_for_each_entry (entry, dir);
+ GF_FOR_EACH_ENTRY_IN_DIR (entry, dir);
}
ret = 0;
@@ -3584,7 +3584,7 @@ glusterd_store_retrieve_snaps (xlator_t *this)
goto out;
}
- glusterd_for_each_entry (entry, dir);
+ GF_FOR_EACH_ENTRY_IN_DIR (entry, dir);
while (entry) {
if (strcmp (entry->d_name, GLUSTERD_MISSED_SNAPS_LIST_FILE)) {
@@ -3596,7 +3596,7 @@ glusterd_store_retrieve_snaps (xlator_t *this)
goto out;
}
}
- glusterd_for_each_entry (entry, dir);
+ GF_FOR_EACH_ENTRY_IN_DIR (entry, dir);
}
/* Retrieve missed_snaps_list */
@@ -4010,7 +4010,7 @@ glusterd_store_retrieve_peers (xlator_t *this)
goto out;
}
- glusterd_for_each_entry (entry, dir);
+ GF_FOR_EACH_ENTRY_IN_DIR (entry, dir);
while (entry) {
snprintf (filepath, PATH_MAX, "%s/%s", path, entry->d_name);
@@ -4087,7 +4087,7 @@ glusterd_store_retrieve_peers (xlator_t *this)
peerinfo->shandle = shandle;
peerinfo = NULL;
- glusterd_for_each_entry (entry, dir);
+ GF_FOR_EACH_ENTRY_IN_DIR (entry, dir);
}
args.mode = GD_MODE_ON;
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.h b/xlators/mgmt/glusterd/src/glusterd-store.h
index 99bbb39683a..b2d21d3a70c 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.h
+++ b/xlators/mgmt/glusterd/src/glusterd-store.h
@@ -95,20 +95,6 @@ typedef enum glusterd_store_ver_ac_{
#define GLUSTERD_STORE_KEY_VOL_CAPS "caps"
-#define glusterd_for_each_entry(entry, dir) \
- do {\
- entry = NULL;\
- if (dir) {\
- entry = readdir (dir);\
- while (entry && (!strcmp (entry->d_name, ".") ||\
- !fnmatch ("*.tmp", entry->d_name, 0) ||\
- !strcmp (entry->d_name, ".."))) {\
- entry = readdir (dir);\
- }\
- }\
- } while (0); \
-
-
int32_t
glusterd_store_volinfo (glusterd_volinfo_t *volinfo, glusterd_volinfo_ver_ac_t ac);
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index a7c7bd9cb88..5ff09d5a4ce 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -9884,78 +9884,6 @@ glusterd_compare_volume_name(struct list_head *list1, struct list_head *list2)
return strcmp(volinfo1->volname, volinfo2->volname);
}
-/* This is an utility function which will recursively delete
- * a folder and its contents.
- *
- * @param delete_path folder to be deleted.
- *
- * @return 0 on success and -1 on failure.
- */
-int
-glusterd_recursive_rmdir (const char *delete_path)
-{
- int ret = -1;
- char path [PATH_MAX] = {0,};
- struct stat st = {0,};
- DIR *dir = NULL;
- struct dirent *entry = NULL;
- xlator_t *this = NULL;
-
- this = THIS;
- GF_ASSERT (this);
- GF_VALIDATE_OR_GOTO (this->name, delete_path, out);
-
- dir = opendir (delete_path);
- if (!dir) {
- gf_log (this->name, GF_LOG_DEBUG, "Failed to open directory %s."
- " Reason : %s", delete_path, strerror (errno));
- ret = 0;
- goto out;
- }
-
- glusterd_for_each_entry (entry, dir);
- while (entry) {
- snprintf (path, PATH_MAX, "%s/%s", delete_path, entry->d_name);
- ret = lstat (path, &st);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_DEBUG, "Failed to stat "
- "entry %s : %s", path, strerror (errno));
- goto out;
- }
-
- if (S_ISDIR (st.st_mode))
- ret = glusterd_recursive_rmdir (path);
- else
- ret = unlink (path);
-
- if (ret) {
- gf_log (this->name, GF_LOG_DEBUG, " Failed to remove "
- "%s. Reason : %s", path, strerror (errno));
- }
-
- gf_log (this->name, GF_LOG_DEBUG, "%s %s",
- ret ? "Failed to remove":"Removed",
- entry->d_name);
-
- glusterd_for_each_entry (entry, dir);
- }
-
- ret = closedir (dir);
- if (ret) {
- gf_log (this->name, GF_LOG_DEBUG, "Failed to close dir %s. "
- "Reason : %s", delete_path, strerror (errno));
- }
-
- ret = rmdir (delete_path);
- if (ret) {
- gf_log (this->name, GF_LOG_DEBUG, "Failed to rmdir: %s,err: %s",
- delete_path, strerror (errno));
- }
-
-out:
- return ret;
-}
-
static int
gd_default_synctask_cbk (int ret, call_frame_t *frame, void *opaque)
{
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index 6c3c8ffed62..f14c6119fe1 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -674,9 +674,6 @@ glusterd_lvm_snapshot_remove (dict_t *rsp_dict, glusterd_volinfo_t *snap_vol);
gf_boolean_t
gd_vol_is_geo_rep_active (glusterd_volinfo_t *volinfo);
-int
-glusterd_recursive_rmdir (const char *delete_path);
-
int32_t
glusterd_get_brick_mount_dir (char *brickpath, char *hostname, char *mount_dir);