From 8a88ae6ce413dacc363cb9d5802965d8c5dca332 Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Mon, 24 Oct 2011 08:27:40 +0530 Subject: pump: Change crawl to accommodate afr_lookup changes Change-Id: I895574dd6fa411784eb5282c799ccf3ff7c65625 BUG: 3747 Reviewed-on: http://review.gluster.com/635 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- xlators/cluster/afr/src/pump.c | 121 ++++++++++++++++++++++++++--------------- 1 file changed, 78 insertions(+), 43 deletions(-) (limited to 'xlators') diff --git a/xlators/cluster/afr/src/pump.c b/xlators/cluster/afr/src/pump.c index b756e1664fc..0eb57ac2408 100644 --- a/xlators/cluster/afr/src/pump.c +++ b/xlators/cluster/afr/src/pump.c @@ -335,24 +335,62 @@ pump_save_file_stats (xlator_t *this, const char *path) return 0; } -static int -gf_pump_traverse_directory (loc_t *loc, uuid_t gfid) +static void +_generate_gfid_on_empty (uuid_t gfid) { - xlator_t *this = NULL; - afr_private_t *priv = NULL; - fd_t *fd = NULL; + if (uuid_is_null (gfid)) + uuid_generate (gfid); +} - off_t offset = 0; - loc_t entry_loc; - gf_dirent_t *entry = NULL; - gf_dirent_t *tmp = NULL; - gf_dirent_t entries; +static void +_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); +} - struct iatt iatt, parent; - dict_t *xattr_rsp; +static void +_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); + loc->ino = iatt->ia_ino; + loc->inode->ino = iatt->ia_ino; +} - int ret = 0; - gf_boolean_t is_directory_empty = _gf_true; +static void +_wipe_loc (loc_t *loc) +{ + loc_wipe (loc); + uuid_clear (loc->gfid); + uuid_clear (loc->pargfid); + loc->ino = 0; +} + +static int +gf_pump_traverse_directory (loc_t *loc, uuid_t gfid) +{ + xlator_t *this = NULL; + afr_private_t *priv = 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; + + xattr_req = dict_new (); + if (!xattr_req) { + ret = -1; + goto out; + } INIT_LIST_HEAD (&entries.list); this = THIS; @@ -379,6 +417,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, @@ -390,45 +429,39 @@ gf_pump_traverse_directory (loc_t *loc, uuid_t gfid) gf_log (this->name, GF_LOG_DEBUG, "found readdir entry=%s", entry->d_name); + _wipe_loc (&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; - - entry_loc.ino = iatt.ia_ino; - entry_loc.inode->ino = iatt.ia_ino; - - 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, + _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); + _empty_gfid_on_set (gfid, ret, &iatt); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "%s: lookup failed", + entry_loc.path); + continue; + } + _fill_loc_info (&entry_loc, &iatt, &parent); pump_update_resume_state (this, entry_loc.path); @@ -442,10 +475,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, @@ -456,10 +485,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); @@ -473,6 +502,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; } -- cgit