diff --git a/lustre/mds/mds_open.c b/lustre/mds/mds_open.c
index a5ea97b6a837371ff407e4c64606b2e208eb3c8f..862011ab37ebbc86198c75cb422eb43f45a81aee 100644
--- a/lustre/mds/mds_open.c
+++ b/lustre/mds/mds_open.c
@@ -1399,55 +1399,43 @@ int mds_mfd_close(struct ptlrpc_request *req, int offset,
                 goto out; /* Don't bother updating attrs on unlinked inode */
         }
 
-#if 0
-        if (request_body != NULL && mfd->mfd_mode & FMODE_WRITE && rc == 0) {
-                /* Update the on-disk attributes if this was the last write
-                 * close, and all information was provided (i.e., rc == 0)
-                 *
-                 * XXX this should probably be abstracted with mds_reint_setattr
-                 */
-
-                if (request_body->valid & OBD_MD_FLMTIME &&
-                    LTIME_S(iattr.ia_mtime) > LTIME_S(inode->i_mtime)) {
-                        LTIME_S(iattr.ia_mtime) = request_body->mtime;
-                        iattr.ia_valid |= ATTR_MTIME;
-                }
-                if (request_body->valid & OBD_MD_FLCTIME &&
-                    LTIME_S(iattr.ia_ctime) > LTIME_S(inode->i_ctime)) {
-                        LTIME_S(iattr.ia_ctime) = request_body->ctime;
-                        iattr.ia_valid |= ATTR_CTIME;
-                }
-
-                /* XXX can't set block count with fsfilt_setattr (!) */
-                if (request_body->valid & OBD_MD_FLSIZE) {
-                        iattr.ia_valid |= ATTR_SIZE;
-                        iattr.ia_size = request_body->size;
-                }
-                /* iattr.ia_blocks = request_body->blocks */
-
-        }
-#endif
         if (request_body != NULL) {
-               if (request_body->valid & OBD_MD_FLMTIME) {
-                      LTIME_S(iattr.ia_mtime) = request_body->mtime;
-                      if (LTIME_S(iattr.ia_mtime) > LTIME_S(inode->i_mtime) &&
-                          ((request_body->valid & OBD_MD_FLCTIME) == 0 ||
-                           request_body->ctime > LTIME_S(inode->i_ctime)))
-                              iattr.ia_valid |= ATTR_MTIME;
+               if ((request_body->valid & OBD_MD_FLCTIME) &&
+                   (request_body->ctime > LTIME_S(inode->i_ctime))) {
+                       LTIME_S(iattr.ia_ctime) = request_body->ctime;
+                       iattr.ia_valid |= ATTR_CTIME;
+               }
+
+               if ((request_body->valid & OBD_MD_FLMTIME) &&
+                   (request_body->mtime > LTIME_S(inode->i_mtime)) &&
+                   (iattr.ia_valid & ATTR_CTIME)) {
+                       LTIME_S(iattr.ia_mtime) = request_body->mtime;
+                       iattr.ia_valid |= ATTR_MTIME;
                }
 
-               if (request_body->valid & OBD_MD_FLATIME) {
-                       /* Only start a transaction to write out only the atime
-                        * if it is more out-of-date than the specified limit.
-                        * If we are already going to write out the inode then
-                        * update the atime anyway.
-                        */
+               /* Only start a transaction to write out only the atime
+                * if it is more out-of-date than the specified limit.
+                * If we are already going to write out the inode then
+                * update the atime anyway.
+                */
+               if ((request_body->valid & OBD_MD_FLATIME) &&
+                   ((request_body->atime >
+                     LTIME_S(inode->i_atime) + mds->mds_atime_diff) ||
+                    (iattr.ia_valid != 0 &&
+                     request_body->atime > LTIME_S(inode->i_atime)))) {
                        LTIME_S(iattr.ia_atime) = request_body->atime;
-                       if ((LTIME_S(iattr.ia_atime) >
-                            LTIME_S(inode->i_atime) + mds->mds_atime_diff) ||
-                           (iattr.ia_valid != 0 &&
-                            LTIME_S(iattr.ia_atime) > LTIME_S(inode->i_atime)))
-                               iattr.ia_valid |= ATTR_ATIME;
+                       iattr.ia_valid |= ATTR_ATIME;
+               }
+
+               /* Store a rough estimate of the file size on the MDS for
+                * tools like e2scan and HSM that are just using this for
+                * rough decision making and will get the proper size later.
+                * This is NOT guaranteed to be correct with multiple
+                * writers, but is only needed until SOM is done. b=11063 */
+               if ((request_body->valid & OBD_MD_FLSIZE) &&
+                   (iattr.ia_valid != 0)) {
+                       iattr.ia_size = request_body->size;
+                       iattr.ia_valid |= ATTR_SIZE;
                }
         }
 
diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh
index 04d69b69f2a6383cc15f2290724310dbda6a1efd..472129e767a5393f073e8fa13f1d01a46914444c 100644
--- a/lustre/tests/sanity.sh
+++ b/lustre/tests/sanity.sh
@@ -1611,6 +1611,70 @@ test_39() {
 }
 run_test 39 "mtime changed on create ==========================="
 
+function get_times() {
+        FILE=$1
+        TIME=$2
+        
+        i=0
+        for time in `stat -c "%X %Y %Z" $FILE`; do
+                eval "$TIME[$i]=$time"
+                i=$(($i + 1))
+        done
+}
+
+test_39b() {
+        ATIME=0
+        MTIME=1
+        CTIME=2
+        mkdir -p $DIR/$tdir
+        cp -p /etc/passwd $DIR/$tdir/fopen
+        cp -p /etc/passwd $DIR/$tdir/flink
+        cp -p /etc/passwd $DIR/$tdir/funlink
+        cp -p /etc/passwd $DIR/$tdir/frename
+        ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
+
+        get_times $DIR/$tdir/fopen OPEN_OLD
+        get_times $DIR/$tdir/flink LINK_OLD
+        get_times $DIR/$tdir/funlink UNLINK_OLD
+        get_times $DIR/$tdir/frename RENAME_OLD
+
+        sleep 1
+        echo "aaaaaa" >> $DIR/$tdir/fopen
+        echo "aaaaaa" >> $DIR/$tdir/flink
+        echo "aaaaaa" >> $DIR/$tdir/funlink
+        echo "aaaaaa" >> $DIR/$tdir/frename
+
+        get_times $DIR/$tdir/fopen OPEN_NEW
+        get_times $DIR/$tdir/flink LINK_NEW
+        get_times $DIR/$tdir/funlink UNLINK_NEW
+        get_times $DIR/$tdir/frename RENAME_NEW
+        
+        cat $DIR/$tdir/fopen > /dev/null
+        ln $DIR/$tdir/flink $DIR/$tdir/flink2
+        rm -f $DIR/$tdir/funlink2
+        mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
+
+        get_times $DIR/$tdir/fopen OPEN_NEW2
+        get_times $DIR/$tdir/flink LINK_NEW2
+        get_times $DIR/$tdir/funlink UNLINK_NEW2
+        get_times $DIR/$tdir/frename2 RENAME_NEW2
+        echo ${OPEN_OLD[1]},${OPEN_NEW[$MTIME]},${OPEN_NEW2[$MTIME]}
+        echo ${LINK_OLD[1]},${LINK_NEW[$MTIME]},${LINK_NEW2[$MTIME]}
+        echo ${UNLINK_OLD[1]},${UNLINK_NEW[$MTIME]},${UNLINK_NEW2[$MTIME]}
+        echo ${RENAME_OLD[1]},${RENAME_NEW[$MTIME]},${RENAME_NEW2[$MTIME]}
+
+        
+        [ ${OPEN_NEW2[$MTIME]} -eq ${OPEN_NEW[$MTIME]} ] || \
+                error "open file reverses mtime"
+        [ ${LINK_NEW2[$MTIME]} -eq ${LINK_NEW[$MTIME]} ] || \
+                error "link file reverses mtime"
+        [ ${UNLINK_NEW2[$MTIME]} -eq ${UNLINK_NEW[$MTIME]} ] || \
+                error "unlink file reverses mtime"
+        [ ${RENAME_NEW2[$MTIME]} -eq ${RENAME_NEW[$MTIME]} ] || \
+                error "rename file reverses mtime"
+}
+run_test 39b "mtime change on close ============================"
+
 test_40() {
 	dd if=/dev/zero of=$DIR/f40 bs=4096 count=1
 	$RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/f40 && error