summaryrefslogtreecommitdiffstats
path: root/xlators/cluster/dht/src/dht-rebalance.c
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/cluster/dht/src/dht-rebalance.c')
-rw-r--r--xlators/cluster/dht/src/dht-rebalance.c274
1 files changed, 183 insertions, 91 deletions
diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c
index 7a19b82c4f0..10fd878041e 100644
--- a/xlators/cluster/dht/src/dht-rebalance.c
+++ b/xlators/cluster/dht/src/dht-rebalance.c
@@ -376,6 +376,50 @@ out:
return ret;
}
+
+static int
+__check_file_has_hardlink (xlator_t *this, loc_t *loc,
+ struct iatt *stbuf, dict_t *xattrs, int flags,
+ gf_defrag_info_t *defrag)
+{
+ int ret = 0;
+
+ if (flags == GF_DHT_MIGRATE_HARDLINK_IN_PROGRESS) {
+ ret = 0;
+ return ret;
+ }
+ if (stbuf->ia_nlink > 1) {
+ /* support for decomission */
+ if (flags == GF_DHT_MIGRATE_HARDLINK) {
+ synclock_lock (&defrag->link_lock);
+ ret = gf_defrag_handle_hardlink
+ (this, loc, xattrs, stbuf);
+ synclock_unlock (&defrag->link_lock);
+ /*
+ Returning zero will force the file to be remigrated.
+ Checkout gf_defrag_handle_hardlink for more information.
+ */
+ if (ret && ret != -2) {
+ gf_msg (this->name, GF_LOG_WARNING, 0,
+ DHT_MSG_MIGRATE_FILE_FAILED,
+ "Migrate file failed:"
+ "%s: failed to migrate file with link",
+ loc->path);
+ }
+ } else {
+ gf_msg (this->name, GF_LOG_WARNING, 0,
+ DHT_MSG_MIGRATE_FILE_FAILED,
+ "Migrate file failed:"
+ "%s: file has hardlinks", loc->path);
+ ret = -ENOTSUP;
+ }
+ }
+
+ return ret;
+}
+
+
+
/*
return values
0 : File will be migrated
@@ -424,40 +468,9 @@ __is_file_migratable (xlator_t *this, loc_t *loc,
}
}
- if (flags == GF_DHT_MIGRATE_HARDLINK_IN_PROGRESS) {
- ret = 0;
- goto out;
- }
-
- if (stbuf->ia_nlink > 1) {
- /* support for decomission */
- if (flags == GF_DHT_MIGRATE_HARDLINK) {
- synclock_lock (&defrag->link_lock);
- ret = gf_defrag_handle_hardlink
- (this, loc, xattrs, stbuf);
- synclock_unlock (&defrag->link_lock);
- /*
- Returning zero will force the file to be remigrated.
- Checkout gf_defrag_handle_hardlink for more information.
- */
- if (ret && ret != -2) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- DHT_MSG_MIGRATE_FILE_FAILED,
- "Migrate file failed:"
- "%s: failed to migrate file with link",
- loc->path);
- }
- } else {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- DHT_MSG_MIGRATE_FILE_FAILED,
- "Migrate file failed:"
- "%s: file has hardlinks", loc->path);
- ret = -ENOTSUP;
- }
- goto out;
- }
-
- ret = 0;
+ /* Check if file has hardlink*/
+ ret = __check_file_has_hardlink (this, loc, stbuf, xattrs,
+ flags, defrag);
out:
return ret;
@@ -1337,8 +1350,13 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to,
goto out;
}
+ if (xattr_rsp) {
+ /* we no more require this key */
+ dict_del (dict, conf->link_xattr_name);
+ dict_unref (xattr_rsp);
+ }
- ret = syncop_fstat (from, src_fd, &stbuf, NULL, NULL);
+ ret = syncop_fstat (from, src_fd, &stbuf, dict, &xattr_rsp);
if (ret) {
gf_msg (this->name, GF_LOG_ERROR, -ret,
DHT_MSG_MIGRATE_FILE_FAILED,
@@ -1348,6 +1366,15 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to,
goto out;
}
+ /* Check again if file has hardlink */
+ ret = __check_file_has_hardlink (this, loc, &stbuf, xattr_rsp,
+ flag, defrag);
+ if (ret) {
+ if (ret == -2)
+ ret = 0;
+ goto out;
+ }
+
/* Try to preserve 'holes' while migrating data */
if (stbuf.ia_size > (stbuf.ia_blocks * GF_DISK_SECTOR_SIZE))
file_has_holes = 1;
@@ -2335,6 +2362,7 @@ gf_defrag_get_entry (xlator_t *this, int i, struct dht_container **container,
struct dht_container *tmp_container = NULL;
xlator_t *hashed_subvol = NULL;
xlator_t *cached_subvol = NULL;
+ int fop_errno = 0;
if (defrag->defrag_status != GF_DEFRAG_STATUS_STARTED) {
ret = -1;
@@ -2358,11 +2386,11 @@ gf_defrag_get_entry (xlator_t *this, int i, struct dht_container **container,
}
if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
+ gf_msg (this->name, GF_LOG_WARNING, -ret,
DHT_MSG_MIGRATE_DATA_FAILED,
- "%s: Migrate data failed: Readdir returned"
- " %s. Aborting migrate-data", loc->path,
- strerror(-ret));
+ "Readdirp failed. Aborting data migration for "
+ "directory: %s", loc->path);
+ fop_errno = -ret;
ret = -1;
goto out;
}
@@ -2494,9 +2522,9 @@ gf_defrag_get_entry (xlator_t *this, int i, struct dht_container **container,
ret = syncop_lookup (this, &entry_loc, NULL, NULL,
NULL, NULL);
if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
+ gf_msg (this->name, GF_LOG_WARNING, -ret,
DHT_MSG_MIGRATE_FILE_FAILED,
- "Migrate file failed:%s lookup failed",
+ "lookup failed for file:%s",
entry_loc.path);
if (-ret != ENOENT && -ret != ESTALE) {
@@ -2617,6 +2645,9 @@ out:
if (xattr_rsp)
dict_unref (xattr_rsp);
+
+
+ errno = fop_errno;
return ret;
}
@@ -2642,6 +2673,7 @@ gf_defrag_process_dir (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc,
int throttle_up = 0;
struct dir_dfmeta *dir_dfmeta = NULL;
int should_commit_hash = 1;
+ int fop_errno = 0;
gf_log (this->name, GF_LOG_INFO, "migrate data called on %s",
loc->path);
@@ -2664,10 +2696,11 @@ gf_defrag_process_dir (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc,
ret = syncop_opendir (this, loc, fd, NULL, NULL);
if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
+ gf_msg (this->name, GF_LOG_WARNING, 0,
DHT_MSG_MIGRATE_DATA_FAILED,
"Migrate data failed: Failed to open dir %s",
loc->path);
+ fop_errno = -ret;
ret = -1;
goto out;
}
@@ -2814,9 +2847,12 @@ gf_defrag_process_dir (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc,
migrate_data, dir_dfmeta,
xattr_req,
&should_commit_hash);
+
if (ret) {
- gf_log ("DHT", GF_LOG_INFO, "Found critical "
+ fop_errno = errno;
+ gf_log ("this->name", GF_LOG_WARNING, "Found "
"error from gf_defrag_get_entry");
+
ret = -1;
goto out;
}
@@ -2874,6 +2910,7 @@ out:
ret = 2;
}
+ errno = fop_errno;
return ret;
}
int
@@ -3043,7 +3080,6 @@ out:
return ret;
}
-
int
gf_defrag_fix_layout (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc,
dict_t *fix_layout, dict_t *migrate_data)
@@ -3067,14 +3103,33 @@ gf_defrag_fix_layout (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc,
goto out;
}
-
-
ret = syncop_lookup (this, loc, &iatt, NULL, NULL, NULL);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Lookup failed on %s",
- loc->path);
- ret = -1;
- goto out;
+ if (strcmp (loc->path, "/") == 0) {
+ gf_msg (this->name, GF_LOG_ERROR, -ret,
+ DHT_MSG_DIR_LOOKUP_FAILED,
+ "lookup failed for:%s", loc->path);
+
+ defrag->total_failures++;
+ ret = -1;
+ goto out;
+ }
+
+ if (-ret == ENOENT || -ret == ESTALE) {
+ gf_msg (this->name, GF_LOG_INFO, errno,
+ DHT_MSG_DIR_LOOKUP_FAILED,
+ "Dir:%s renamed or removed. Skipping",
+ loc->path);
+ ret = 0;
+ goto out;
+ } else {
+ gf_msg (this->name, GF_LOG_ERROR, -ret,
+ DHT_MSG_DIR_LOOKUP_FAILED,
+ "lookup failed for:%s", loc->path);
+
+ defrag->total_failures++;
+ goto out;
+ }
}
if ((defrag->cmd != GF_DEFRAG_CMD_START_TIER) &&
@@ -3082,18 +3137,24 @@ gf_defrag_fix_layout (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc,
ret = gf_defrag_process_dir (this, defrag, loc, migrate_data);
if (ret && ret != 2) {
- defrag->total_failures++;
+ if (errno == ENOENT || errno == ESTALE) {
+ ret = 0;
+ goto out;
+ } else {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- DHT_MSG_DEFRAG_PROCESS_DIR_FAILED,
- "gf_defrag_process_dir failed for directory: %s"
- , loc->path);
+ defrag->total_failures++;
- if (conf->decommission_in_progress) {
- goto out;
- }
+ gf_msg (this->name, GF_LOG_ERROR, 0,
+ DHT_MSG_DEFRAG_PROCESS_DIR_FAILED,
+ "gf_defrag_process_dir failed for "
+ "directory: %s", loc->path);
- should_commit_hash = 0;
+ if (conf->decommission_in_progress) {
+ goto out;
+ }
+
+ should_commit_hash = 0;
+ }
} else if (ret == 2) {
should_commit_hash = 0;
}
@@ -3110,8 +3171,14 @@ gf_defrag_fix_layout (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc,
ret = syncop_opendir (this, loc, fd, NULL, NULL);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to open dir %s",
- loc->path);
+ if (-ret == ENOENT || -ret == ESTALE) {
+ ret = 0;
+ goto out;
+ }
+
+ gf_log (this->name, GF_LOG_ERROR, "Failed to open dir %s, "
+ "err:%d", loc->path, -ret);
+
ret = -1;
goto out;
}
@@ -3123,8 +3190,15 @@ gf_defrag_fix_layout (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc,
{
if (ret < 0) {
- gf_log (this->name, GF_LOG_ERROR, "Readdir returned %s"
- ". Aborting fix-layout",strerror(-ret));
+ if (-ret == ENOENT || -ret == ESTALE) {
+ ret = 0;
+ goto out;
+ }
+
+ gf_msg (this->name, GF_LOG_ERROR, -ret,
+ DHT_MSG_READDIR_ERROR, "readdirp failed for "
+ "path %s. Aborting fix-layout", loc->path);
+
ret = -1;
goto out;
}
@@ -3216,43 +3290,63 @@ gf_defrag_fix_layout (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc,
ret = syncop_lookup (this, &entry_loc, &iatt, NULL,
NULL, NULL);
- /*Check whether it is ENOENT or ESTALE*/
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "%s"
- " lookup failed with %d",
- entry_loc.path, -ret);
-
- if (!conf->decommission_in_progress &&
- -ret != ENOENT && -ret != ESTALE) {
- should_commit_hash = 0;
+ if (-ret == ENOENT || -ret == ESTALE) {
+ gf_msg (this->name, GF_LOG_INFO, errno,
+ DHT_MSG_DIR_LOOKUP_FAILED,
+ "Dir:%s renamed or removed. "
+ "Skipping", loc->path);
+ ret = 0;
+ continue;
+ } else {
+ gf_msg (this->name, GF_LOG_ERROR, -ret,
+ DHT_MSG_DIR_LOOKUP_FAILED,
+ "lookup failed for:%s",
+ entry_loc.path);
+ defrag->total_failures++;
+ if (conf->decommission_in_progress) {
+ defrag->defrag_status =
+ GF_DEFRAG_STATUS_FAILED;
+ ret = -1;
+ goto out;
+ } else {
+ should_commit_hash = 0;
+ continue;
+ }
}
-
- continue;
}
ret = syncop_setxattr (this, &entry_loc, fix_layout,
0, NULL, NULL);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Setxattr "
- "failed for %s", entry_loc.path);
-
- defrag->total_failures++;
-
- /*Don't go for fix-layout of child subtree if"
- fix-layout failed*/
- if (conf->decommission_in_progress) {
- defrag->defrag_status =
- GF_DEFRAG_STATUS_FAILED;
-
- ret = -1;
-
- goto out;
- } else {
+ if (-ret == ENOENT || -ret == ESTALE) {
+ gf_msg (this->name, GF_LOG_INFO, -ret,
+ DHT_MSG_LAYOUT_FIX_FAILED,
+ "Setxattr failed. Dir %s "
+ "renamed or removed",
+ entry_loc.path);
+ ret = 0;
continue;
+ } else {
+
+ gf_msg (this->name, GF_LOG_ERROR, -ret,
+ DHT_MSG_LAYOUT_FIX_FAILED,
+ "Setxattr failed for %s",
+ entry_loc.path);
+
+ defrag->total_failures++;
+
+ if (conf->decommission_in_progress) {
+ defrag->defrag_status =
+ GF_DEFRAG_STATUS_FAILED;
+ ret = -1;
+ goto out;
+ } else {
+ continue;
+ }
}
}
-
/* A return value of 2 means, either process_dir or
* lookup of a dir failed. Hence, don't commit hash
* for the current directory*/
@@ -3272,8 +3366,6 @@ gf_defrag_fix_layout (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc,
defrag->defrag_status =
GF_DEFRAG_STATUS_FAILED;
- ret = -1;
-
goto out;
} else {
/* Let's not commit-hash if