summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libglusterfs/src/dict.h1
-rw-r--r--xlators/cluster/afr/src/afr-self-heald.c18
-rw-r--r--xlators/cluster/afr/src/afr-self-heald.h9
-rw-r--r--xlators/cluster/afr/src/pump.c90
4 files changed, 67 insertions, 51 deletions
diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h
index 462397885d2..c51c7d8f785 100644
--- a/libglusterfs/src/dict.h
+++ b/libglusterfs/src/dict.h
@@ -73,6 +73,7 @@ void data_destroy (data_t *data);
int32_t dict_set (dict_t *this, char *key, data_t *value);
data_t *dict_get (dict_t *this, char *key);
void dict_del (dict_t *this, char *key);
+int dict_reset (dict_t *dict);
int32_t dict_serialized_length (dict_t *dict);
int32_t dict_serialize (dict_t *dict, char *buf);
diff --git a/xlators/cluster/afr/src/afr-self-heald.c b/xlators/cluster/afr/src/afr-self-heald.c
index dd0dd86da0c..afddf62c2e4 100644
--- a/xlators/cluster/afr/src/afr-self-heald.c
+++ b/xlators/cluster/afr/src/afr-self-heald.c
@@ -84,22 +84,22 @@ out:
return ret;
}
-static void
-_generate_gfid_on_empty (uuid_t gfid)
+inline void
+afr_generate_gfid_on_empty (uuid_t gfid)
{
if (uuid_is_null (gfid))
uuid_generate (gfid);
}
-static void
-_empty_gfid_on_set (uuid_t gfid, int lookup_status, struct iatt *iatt)
+inline void
+afr_empty_gfid_on_set (uuid_t gfid, int lookup_status, struct iatt *iatt)
{
if (lookup_status || !uuid_compare (gfid, iatt->ia_gfid))
uuid_clear (gfid);
}
-static void
-_fill_loc_info (loc_t *loc, struct iatt *iatt, struct iatt *parent)
+inline void
+afr_fill_loc_info (loc_t *loc, struct iatt *iatt, struct iatt *parent)
{
afr_update_loc_gfids (loc, iatt, parent);
uuid_copy (loc->inode->gfid, iatt->ia_gfid);
@@ -139,7 +139,7 @@ _perform_self_heal (xlator_t *this, loc_t *parentloc, gf_dirent_t *entries,
if (ret)
goto out;
- _generate_gfid_on_empty (gfid);
+ afr_generate_gfid_on_empty (gfid);
ret = afr_set_dict_gfid (xattr_req, gfid);
if (ret)
goto out;
@@ -147,12 +147,12 @@ _perform_self_heal (xlator_t *this, loc_t *parentloc, gf_dirent_t *entries,
ret = syncop_lookup (this, &entry_loc, xattr_req,
&iatt, NULL, &parent);
- _empty_gfid_on_set (gfid, ret, &iatt);
+ afr_empty_gfid_on_set (gfid, ret, &iatt);
//Don't fail the crawl if lookup fails as it
//could be because of split-brain
if (ret || (!IA_ISDIR (iatt.ia_type)))
continue;
- _fill_loc_info (&entry_loc, &iatt, &parent);
+ afr_fill_loc_info (&entry_loc, &iatt, &parent);
ret = _crawl_directory (&entry_loc, pid, gfid);
}
ret = 0;
diff --git a/xlators/cluster/afr/src/afr-self-heald.h b/xlators/cluster/afr/src/afr-self-heald.h
index 5d7892fa785..d5f9552c1d5 100644
--- a/xlators/cluster/afr/src/afr-self-heald.h
+++ b/xlators/cluster/afr/src/afr-self-heald.h
@@ -37,4 +37,13 @@ void afr_build_root_loc (inode_t *inode, loc_t *loc);
int afr_set_root_gfid (dict_t *dict);
+inline void
+afr_generate_gfid_on_empty (uuid_t gfid);
+
+inline void
+afr_empty_gfid_on_set (uuid_t gfid, int lookup_status, struct iatt *iatt);
+
+inline void
+afr_fill_loc_info (loc_t *loc, struct iatt *iatt, struct iatt *parent);
+
#endif /* __AFR_SELF_HEALD_H__ */
diff --git a/xlators/cluster/afr/src/pump.c b/xlators/cluster/afr/src/pump.c
index 9154c2eadbf..9ad29c69b6d 100644
--- a/xlators/cluster/afr/src/pump.c
+++ b/xlators/cluster/afr/src/pump.c
@@ -325,20 +325,26 @@ pump_save_file_stats (xlator_t *this, const char *path)
static int
gf_pump_traverse_directory (loc_t *loc, uuid_t gfid)
{
- xlator_t *this = NULL;
- fd_t *fd = NULL;
-
- off_t offset = 0;
- loc_t entry_loc;
- gf_dirent_t *entry = NULL;
- gf_dirent_t *tmp = NULL;
- gf_dirent_t entries;
-
- struct iatt iatt, parent;
- dict_t *xattr_rsp;
+ xlator_t *this = NULL;
+ fd_t *fd = NULL;
+ off_t offset = 0;
+ loc_t entry_loc = {0};
+ gf_dirent_t *entry = NULL;
+ gf_dirent_t *tmp = NULL;
+ gf_dirent_t entries;
+ struct iatt iatt = {0};
+ struct iatt parent = {0};
+ dict_t *xattr_rsp = NULL;
+ int ret = 0;
+ gf_boolean_t is_directory_empty = _gf_true;
+ dict_t *xattr_req = NULL;
+ gf_boolean_t free_entries = _gf_false;
- int ret = 0;
- gf_boolean_t is_directory_empty = _gf_true;
+ xattr_req = dict_new ();
+ if (!xattr_req) {
+ ret = -1;
+ goto out;
+ }
INIT_LIST_HEAD (&entries.list);
this = THIS;
@@ -364,6 +370,7 @@ gf_pump_traverse_directory (loc_t *loc, uuid_t gfid)
loc->path, ret);
while (syncop_readdirp (this, fd, 131072, offset, &entries)) {
+ free_entries = _gf_true;
if (list_empty (&entries.list)) {
gf_log (this->name, GF_LOG_TRACE,
@@ -375,43 +382,40 @@ gf_pump_traverse_directory (loc_t *loc, uuid_t gfid)
gf_log (this->name, GF_LOG_DEBUG,
"found readdir entry=%s", entry->d_name);
- ret = afr_build_child_loc (this, &entry_loc, loc,
- entry->d_name);
+ loc_wipe (&entry_loc);
+ ret = afr_build_child_loc (this, &entry_loc,
+ loc, entry->d_name);
if (ret)
goto out;
if (!IS_ENTRY_CWD (entry->d_name) &&
- !IS_ENTRY_PARENT (entry->d_name)) {
+ !IS_ENTRY_PARENT (entry->d_name)) {
is_directory_empty = _gf_false;
- ret = syncop_lookup (this, &entry_loc, NULL,
- &iatt, &xattr_rsp, &parent);
- if (ret)
- continue;
-
- if (uuid_is_null (iatt.ia_gfid)) {
- uuid_generate (gfid);
- uuid_copy (entry_loc.inode->gfid,
- gfid);
- } else {
- uuid_copy (entry_loc.inode->gfid,
- iatt.ia_gfid);
- }
-
gf_log (this->name, GF_LOG_DEBUG,
"lookup %s => %"PRId64,
entry_loc.path,
iatt.ia_ino);
- ret = syncop_lookup (this, &entry_loc, NULL,
+ afr_generate_gfid_on_empty (gfid);
+ ret = dict_reset (xattr_req);
+ if (ret)
+ goto out;
+ ret = afr_set_dict_gfid (xattr_req, gfid);
+ if (ret)
+ goto out;
+ ret = syncop_lookup (this, &entry_loc, xattr_req,
&iatt, &xattr_rsp, &parent);
-
- gf_log (this->name, GF_LOG_DEBUG,
- "second lookup ret=%d: %s => %"PRId64,
- ret,
- entry_loc.path,
- iatt.ia_ino);
+ afr_empty_gfid_on_set (gfid, ret, &iatt);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "%s: lookup failed",
+ entry_loc.path);
+ continue;
+ }
+ afr_fill_loc_info (&entry_loc, &iatt,
+ &parent);
pump_update_resume_state (this, entry_loc.path);
@@ -425,10 +429,6 @@ gf_pump_traverse_directory (loc_t *loc, uuid_t gfid)
goto out;
}
- gf_log (this->name, GF_LOG_TRACE,
- "type of file=%d, IFDIR=%d",
- iatt.ia_type, IA_IFDIR);
-
if (IA_ISDIR (iatt.ia_type)) {
if (is_pump_traversal_allowed (this, entry_loc.path)) {
gf_log (this->name, GF_LOG_TRACE,
@@ -439,10 +439,10 @@ gf_pump_traverse_directory (loc_t *loc, uuid_t gfid)
}
}
offset = entry->d_off;
- loc_wipe (&entry_loc);
}
gf_dirent_free (&entries);
+ free_entries = _gf_false;
gf_log (this->name, GF_LOG_TRACE,
"offset incremented to %d",
(int32_t ) offset);
@@ -456,6 +456,12 @@ gf_pump_traverse_directory (loc_t *loc, uuid_t gfid)
}
out:
+ if (xattr_req)
+ dict_unref (xattr_req);
+ if (entry_loc.path)
+ loc_wipe (&entry_loc);
+ if (free_entries)
+ gf_dirent_free (&entries);
return 0;
}