]> granicus.if.org Git - zfs/commitdiff
Modifying XATTRs doesnt change the ctime
authorGaurav Kumar <gaurkuma@users.noreply.github.com>
Wed, 13 Sep 2017 19:20:07 +0000 (12:20 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Wed, 13 Sep 2017 19:20:07 +0000 (12:20 -0700)
Changing any metadata, should modify the ctime.

Reviewed-by: Chunwei Chen <tuxoko@gmail.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: gaurkuma <gauravk.18@gmail.com>
Closes #3644
Closes #6586

module/zfs/zfs_sa.c
module/zfs/zpl_xattr.c
tests/zfs-tests/tests/functional/ctime/Makefile.am
tests/zfs-tests/tests/functional/ctime/ctime.c [moved from tests/zfs-tests/tests/functional/ctime/ctime_001_pos.c with 94% similarity]
tests/zfs-tests/tests/functional/ctime/ctime_001_pos.ksh [new file with mode: 0644]

index 08e881cc372dea0277fac5e2fbbb218589987b56..3eff6acc6f3ebb6eb3c430c05b766c5f600b5902 100644 (file)
@@ -248,8 +248,17 @@ zfs_sa_set_xattr(znode_t *zp)
        if (error) {
                dmu_tx_abort(tx);
        } else {
-               VERIFY0(sa_update(zp->z_sa_hdl, SA_ZPL_DXATTR(zfsvfs),
-                   obj, size, tx));
+               int count = 0;
+               sa_bulk_attr_t bulk[2];
+               uint64_t ctime[2];
+
+               zfs_tstamp_update_setup(zp, STATE_CHANGED, NULL, ctime);
+               SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_DXATTR(zfsvfs),
+                   NULL, obj, size);
+               SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs),
+                   NULL, &ctime, 16);
+               VERIFY0(sa_bulk_update(zp->z_sa_hdl, bulk, count, tx));
+
                dmu_tx_commit(tx);
        }
 out_free:
index d3bb4bbf8c49dea572c222608341356ec4f228ff..0c626b122193fde87444a6737ced0d27a733a913 100644 (file)
@@ -495,6 +495,12 @@ zpl_xattr_set_dir(struct inode *ip, const char *name, const void *value,
                error = wrote;
 
 out:
+
+       if (error == 0) {
+               ip->i_ctime = current_time(ip);
+               zfs_mark_inode_dirty(ip);
+       }
+
        if (vap)
                kmem_free(vap, sizeof (vattr_t));
 
index 1c7c26d99a89519d7227f541f424e53fbaea0bf4..e7479ae81056d83d48f78d3773997f720bc2ab8e 100644 (file)
@@ -3,10 +3,11 @@ include $(top_srcdir)/config/Rules.am
 pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/ctime
 
 dist_pkgdata_SCRIPTS = \
+       ctime_001_pos.ksh \
        cleanup.ksh \
        setup.ksh
 
 pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/ctime
 
-pkgexec_PROGRAMS = ctime_001_pos
-ctime_001_pos_SOURCES = ctime_001_pos.c
+pkgexec_PROGRAMS = ctime
+ctime_SOURCES = ctime.c
similarity index 94%
rename from tests/zfs-tests/tests/functional/ctime/ctime_001_pos.c
rename to tests/zfs-tests/tests/functional/ctime/ctime.c
index 73528d21d214cd183792631deb80c8b2361a632e..ba8af15fec9be162eeff0def68ef18fa9307ba01 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/xattr.h>
 #include <utime.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -250,6 +251,24 @@ do_chown(const char *pfile)
        return (ret);
 }
 
+static int
+do_xattr(const char *pfile)
+{
+       int ret = 0;
+       char *value = "user.value";
+
+       if (pfile == NULL) {
+               return (-1);
+       }
+
+       if (setxattr(pfile, "user.x", value, strlen(value), 0) == -1) {
+               (void) fprintf(stderr, "setxattr(%s, %d, %d) failed with errno "
+                   "%d\n", pfile, (int)getuid(), (int)getgid(), errno);
+               return (1);
+       }
+       return (ret);
+}
+
 static void
 cleanup(void)
 {
@@ -270,6 +289,7 @@ static timetest_t timetest_table[] = {
        { ST_CTIME,     "st_ctime",     do_chown        },
        { ST_CTIME,     "st_ctime",     do_link         },
        { ST_CTIME,     "st_ctime",     do_utime        },
+       { ST_CTIME,     "st_ctime",     do_xattr        },
 };
 
 #define        NCOMMAND (sizeof (timetest_table) / sizeof (timetest_table[0]))
@@ -281,7 +301,6 @@ main(int argc, char *argv[])
        int i, ret, fd;
        char *penv[] = {"TESTDIR", "TESTFILE0"};
 
-       (void) fprintf(stdout, "Verify [acm]time is modified appropriately.\n");
        (void) atexit(cleanup);
 
        /*
@@ -347,6 +366,5 @@ main(int argc, char *argv[])
                }
        }
 
-       (void) fprintf(stdout, "PASS\n");
        return (0);
 }
diff --git a/tests/zfs-tests/tests/functional/ctime/ctime_001_pos.ksh b/tests/zfs-tests/tests/functional/ctime/ctime_001_pos.ksh
new file mode 100644 (file)
index 0000000..de12efe
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+# . $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+#
+# Verify [acm]time is modified appropriately with xattr=on|sa
+
+set -A args "sa" "on"
+
+log_note "Verify [acm]time is modified appropriately."
+
+for arg in ${args[*]}; do
+       log_note "Testing with xattr set to $arg"
+       log_must zfs set xattr=$arg $TESTPOOL
+       log_must $STF_SUITE/tests/functional/ctime/ctime
+done
+
+log_pass "PASS"