summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarshavardhana <harsha@gluster.com>2011-07-21 16:43:46 -0700
committerAnand Avati <avati@gluster.com>2011-07-23 12:28:37 -0700
commitbe32fb15e66869cfab37f80b86578b2b7d203432 (patch)
tree37958f2746ce2fbb8ed594b1bdedb1e417dbd4a9
parentb127d0fd7b6c452d3f355c3fc11b068c55b0d457 (diff)
Preserve atimes and mtimes during rebalance
Applications relying on mtime get affected by existing rebalance since it always updates destination file to latest timestamp. - Use utimes to update destination path with existing values from earlier stat call. Change-Id: I809a8d3ca13c5317da66737356c24e82d795ff78 BUG: 3210 Reviewed-on: http://review.gluster.com/74 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@gluster.com>
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-rebalance.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-rebalance.c b/xlators/mgmt/glusterd/src/glusterd-rebalance.c
index 6e478b07361..3b04dc2be10 100644
--- a/xlators/mgmt/glusterd/src/glusterd-rebalance.c
+++ b/xlators/mgmt/glusterd/src/glusterd-rebalance.c
@@ -23,6 +23,7 @@
#endif
#include <inttypes.h>
#include <sys/resource.h>
+#include <sys/time.h>
#include "globals.h"
#include "compat.h"
@@ -111,6 +112,7 @@ gf_glusterd_rebalance_move_data (glusterd_volinfo_t *volinfo, const char *dir)
char value[16] = {0,};
char linkinfo[PATH_MAX] = {0,};
char file_not_copied_fully = 0;
+ struct timeval times[2] = {{0,},{0,}};
if (!volinfo->defrag)
goto out;
@@ -207,7 +209,7 @@ gf_glusterd_rebalance_move_data (glusterd_volinfo_t *volinfo, const char *dir)
ret = fchown (dst_fd, stbuf.st_uid, stbuf.st_gid);
if (ret) {
- gf_log ("", GF_LOG_WARNING,
+ gf_log (THIS->name, GF_LOG_WARNING,
"failed to set the uid/gid of file %s: %s",
tmp_filename, strerror (errno));
}
@@ -252,6 +254,20 @@ gf_glusterd_rebalance_move_data (glusterd_volinfo_t *volinfo, const char *dir)
continue;
}
+ times[0].tv_sec = stbuf.st_atime;
+ times[0].tv_usec = 0;
+
+ times[1].tv_sec = stbuf.st_mtime;
+ times[1].tv_usec = 0;
+
+ ret = utimes (tmp_filename, times);
+
+ if (ret < 0) {
+ gf_log (THIS->name, GF_LOG_WARNING,
+ "failed to set the atime/mtime of file %s: %s",
+ tmp_filename, strerror (errno));
+ }
+
ret = rename (tmp_filename, full_path);
if (ret != -1) {
LOCK (&defrag->lock);