From be32fb15e66869cfab37f80b86578b2b7d203432 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 21 Jul 2011 16:43:46 -0700 Subject: 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 Reviewed-by: Anand Avati --- xlators/mgmt/glusterd/src/glusterd-rebalance.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 #include +#include #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); -- cgit