+rmultiop_start() {
+ local client=$1
+ local file=$2
+ local cmds=$3
+
+ # We need to run do_node in bg, because pdsh does not exit
+ # if child process of run script exists.
+ # I.e. pdsh does not exit when runmultiop_bg_pause exited,
+ # because of multiop_bg_pause -> $MULTIOP_PROG &
+ # By the same reason we need sleep a bit after do_nodes starts
+ # to let runmultiop_bg_pause start muliop and
+ # update /tmp/multiop_bg.pid ;
+ # The rm /tmp/multiop_bg.pid guarantees here that
+ # we have the updated by runmultiop_bg_pause
+ # /tmp/multiop_bg.pid file
+
+ local pid_file=$TMP/multiop_bg.pid.$$
+ do_node $client "rm -f $pid_file && MULTIOP_PID_FILE=$pid_file LUSTRE= runmultiop_bg_pause $file $cmds" &
+ local pid=$!
+ sleep 3
+ local multiop_pid
+ multiop_pid=$(do_node $client cat $pid_file)
+ [ -n "$multiop_pid" ] || error "$client : Can not get multiop_pid from $pid_file "
+ eval export $(client_var_name $client)_multiop_pid=$multiop_pid
+ eval export $(client_var_name $client)_do_node_pid=$pid
+ local var=$(client_var_name $client)_multiop_pid
+ echo client $client multiop_bg started multiop_pid=${!var}
+ return $?
+}
+
+rmultiop_stop() {
+ local client=$1
+ local multiop_pid=$(client_var_name $client)_multiop_pid
+ local do_node_pid=$(client_var_name $client)_do_node_pid
+
+ echo "Stopping multiop_pid=${!multiop_pid} (kill ${!multiop_pid} on $client)"
+ do_node $client kill -USR1 ${!multiop_pid}
+
+ wait ${!do_node_pid}
+}
+
+get_version() {
+ local var=${SINGLEMDS}_svc
+ local client=$1
+ local file=$2
+ local fid
+
+ fid=$(do_node $client $LFS path2fid $file)
+ do_facet $SINGLEMDS $LCTL --device ${!var} getobjversion $fid
+}
+
+test_0a() {
+ local file=$DIR/$tfile
+ local pre
+ local post
+
+ do_node $CLIENT1 mcreate $file
+ pre=$(get_version $CLIENT1 $file)
+ do_node $CLIENT1 openfile -f O_RDWR $file
+ post=$(get_version $CLIENT1 $file)
+ if (($pre != $post)); then
+ error "version changed unexpectedly: pre $pre, post $post"
+ fi
+}
+run_test 0a "open and close do not change versions"
+
+test_0b() {
+ local var=${SINGLEMDS}_svc
+
+ do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
+ do_node $CLIENT1 mkdir -p -m 755 $DIR/$tdir
+
+ replay_barrier $SINGLEMDS
+ do_node $CLIENT2 chmod 777 $DIR/$tdir
+ do_node $CLIENT1 openfile -f O_RDWR:O_CREAT $DIR/$tdir/$tfile
+ zconf_umount $CLIENT2 $MOUNT
+ facet_failover $SINGLEMDS
+
+ client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
+ if ! do_node $CLIENT1 $CHECKSTAT -a $DIR/$tdir/$tfile; then
+ error "open succeeded unexpectedly"
+ fi
+ zconf_mount $CLIENT2 $MOUNT
+}
+run_test 0b "open (O_CREAT) checks version of parent"
+
+test_0c() {
+ local var=${SINGLEMDS}_svc
+
+ do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
+ do_node $CLIENT1 mkdir -p -m 755 $DIR/$tdir
+ do_node $CLIENT1 openfile -f O_RDWR:O_CREAT -m 0644 $DIR/$tdir/$tfile
+
+ replay_barrier $SINGLEMDS
+ do_node $CLIENT2 chmod 777 $DIR/$tdir
+ do_node $CLIENT2 chmod 666 $DIR/$tdir/$tfile
+ rmultiop_start $CLIENT1 $DIR/$tdir/$tfile o_c
+ zconf_umount $CLIENT2 $MOUNT
+ facet_failover $SINGLEMDS
+ client_up $CLIENT1 || error "$CLIENT1 evicted"
+
+ rmultiop_stop $CLIENT1 || error "close failed"
+ zconf_mount $CLIENT2 $MOUNT
+}
+run_test 0c "open (non O_CREAT) does not checks versions"
+
+test_0d() {
+ local pre
+ local post
+
+ pre=$(get_version $CLIENT1 $DIR)
+ do_node $CLIENT1 mkfifo $DIR/$tfile
+ post=$(get_version $CLIENT1 $DIR)
+ if (($pre == $post)); then
+ error "version not changed: pre $pre, post $post"
+ fi
+}
+run_test 0d "create changes version of parent"
+
+test_0e() {
+ local var=${SINGLEMDS}_svc
+
+ do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
+ do_node $CLIENT1 mkdir -p -m 755 $DIR/$tdir
+
+ replay_barrier $SINGLEMDS
+ do_node $CLIENT2 chmod 777 $DIR/$tdir
+ do_node $CLIENT1 mkfifo $DIR/$tdir/$tfile
+ zconf_umount $CLIENT2 $MOUNT
+ facet_failover $SINGLEMDS
+
+ client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
+ if ! do_node $CLIENT1 $CHECKSTAT -a $DIR/$tdir/$tfile; then
+ error "create succeeded unexpectedly"
+ fi
+ zconf_mount $CLIENT2 $MOUNT
+}
+run_test 0e "create checks version of parent"
+
+test_0f() {
+ local pre
+ local post
+
+ do_node $CLIENT1 mcreate $DIR/$tfile
+ pre=$(get_version $CLIENT1 $DIR)
+ do_node $CLIENT1 rm $DIR/$tfile
+ post=$(get_version $CLIENT1 $DIR)
+ if (($pre == $post)); then
+ error "version not changed: pre $pre, post $post"
+ fi
+}
+run_test 0f "unlink changes version of parent"
+
+test_0g() {
+ local var=${SINGLEMDS}_svc
+
+ do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
+ do_node $CLIENT1 mkdir -p -m 755 $DIR/$tdir
+ do_node $CLIENT1 mcreate $DIR/$tdir/$tfile
+
+ replay_barrier $SINGLEMDS
+ do_node $CLIENT2 chmod 777 $DIR/$tdir
+ do_node $CLIENT1 rm $DIR/$tdir/$tfile
+ zconf_umount $CLIENT2 $MOUNT
+ facet_failover $SINGLEMDS
+
+ client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
+ if do_node $CLIENT1 $CHECKSTAT -a $DIR/$tdir/$tfile; then
+ error "unlink succeeded unexpectedly"
+ fi
+ zconf_mount $CLIENT2 $MOUNT
+}
+run_test 0g "unlink checks version of parent"
+
+test_0h() {
+ local file=$DIR/$tfile
+ local pre
+ local post
+
+ do_node $CLIENT1 mcreate $file
+ pre=$(get_version $CLIENT1 $file)
+ do_node $CLIENT1 chown $RUNAS_ID $file
+ post=$(get_version $CLIENT1 $file)
+ if (($pre == $post)); then
+ error "version not changed: pre $pre, post $post"
+ fi
+}
+run_test 0h "setattr of UID changes versions"
+
+test_0i() {
+ local file=$DIR/$tfile
+ local pre
+ local post
+
+ do_node $CLIENT1 mcreate $file
+ pre=$(get_version $CLIENT1 $file)
+ do_node $CLIENT1 chown :$RUNAS_ID $file
+ post=$(get_version $CLIENT1 $file)
+ if (($pre == $post)); then
+ error "version not changed: pre $pre, post $post"
+ fi
+}
+run_test 0i "setattr of GID changes versions"
+
+test_0j() {
+ local file=$DIR/$tfile
+ local var=${SINGLEMDS}_svc
+
+ do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
+ do_node $CLIENT1 mcreate $file
+
+ replay_barrier $SINGLEMDS
+ do_node $CLIENT2 chown :$RUNAS_ID $file
+ do_node $CLIENT1 chown $RUNAS_ID $file
+ zconf_umount $CLIENT2 $MOUNT
+ facet_failover $SINGLEMDS
+
+ client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
+ if ! do_node $CLIENT1 $CHECKSTAT -u \\\#$UID $file; then
+ error "setattr of UID succeeded unexpectedly"
+ fi
+ zconf_mount $CLIENT2 $MOUNT
+}
+run_test 0j "setattr of UID checks versions"
+
+test_0k() {
+ local file=$DIR/$tfile
+ local var=${SINGLEMDS}_svc
+
+ do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
+ do_node $CLIENT1 mcreate $file
+
+ replay_barrier $SINGLEMDS
+ do_node $CLIENT2 chown $RUNAS_ID $file
+ do_node $CLIENT1 chown :$RUNAS_ID $file
+ zconf_umount $CLIENT2 $MOUNT
+ facet_failover $SINGLEMDS
+
+ client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
+ if ! do_node $CLIENT1 $CHECKSTAT -g \\\#$UID $file; then
+ error "setattr of GID succeeded unexpectedly"
+ fi
+ zconf_mount $CLIENT2 $MOUNT
+}
+run_test 0k "setattr of GID checks versions"
+
+test_0l() {
+ local file=$DIR/$tfile
+ local pre
+ local post
+
+ do_node $CLIENT1 openfile -f O_RDWR:O_CREAT -m 0644 $file
+ pre=$(get_version $CLIENT1 $file)
+ do_node $CLIENT1 chmod 666 $file
+ post=$(get_version $CLIENT1 $file)
+ if (($pre == $post)); then
+ error "version not changed: pre $pre, post $post"
+ fi
+}
+run_test 0l "setattr of permission changes versions"
+
+test_0m() {
+ local file=$DIR/$tfile
+ local var=${SINGLEMDS}_svc
+
+ do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
+ do_node $CLIENT1 openfile -f O_RDWR:O_CREAT -m 0644 $file
+
+ replay_barrier $SINGLEMDS
+ do_node $CLIENT2 chown :$RUNAS_ID $file
+ do_node $CLIENT1 chmod 666 $file
+ zconf_umount $CLIENT2 $MOUNT
+ facet_failover $SINGLEMDS
+
+ client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
+ if ! do_node $CLIENT1 $CHECKSTAT -p 0644 $file; then
+ error "setattr of permission succeeded unexpectedly"
+ fi
+ zconf_mount $CLIENT2 $MOUNT
+}
+run_test 0m "setattr of permission checks versions"
+
+test_0n() {
+ local file=$DIR/$tfile
+ local pre
+ local post
+
+ do_node $CLIENT1 mcreate $file
+ pre=$(get_version $CLIENT1 $file)
+ do_node $CLIENT1 chattr +i $file
+ post=$(get_version $CLIENT1 $file)
+ do_node $CLIENT1 chattr -i $file
+ if (($pre == $post)); then
+ error "version not changed: pre $pre, post $post"
+ fi
+}
+run_test 0n "setattr of flags changes versions"
+
+checkattr() {
+ local client=$1
+ local attr=$2
+ local file=$3
+ local rc
+
+ if ((${#attr} != 1)); then
+ error "checking multiple attributes not implemented yet"
+ fi
+ do_node $client lsattr $file | cut -d ' ' -f 1 | grep -q $attr
+}
+
+test_0o() {
+ local file=$DIR/$tfile
+ local rc
+ local var=${SINGLEMDS}_svc
+
+ do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
+ do_node $CLIENT1 openfile -f O_RDWR:O_CREAT -m 0644 $file
+
+ replay_barrier $SINGLEMDS
+ do_node $CLIENT2 chmod 666 $file
+ do_node $CLIENT1 chattr +i $file
+ zconf_umount $CLIENT2 $MOUNT
+ facet_failover $SINGLEMDS
+
+ client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
+ checkattr $CLIENT1 i $file
+ rc=$?
+ do_node $CLIENT1 chattr -i $file
+ if [ $rc -eq 0 ]; then
+ error "setattr of flags succeeded unexpectedly"
+ fi
+ zconf_mount $CLIENT2 $MOUNT
+}
+run_test 0o "setattr of flags checks versions"
+
+test_0p() {
+ local file=$DIR/$tfile
+ local pre
+ local post
+ local ad_orig
+ local var=${SINGLEMDS}_svc
+
+ ad_orig=$(do_facet $SINGLEMDS "$LCTL get_param mdd.${!var}.atime_diff")
+ do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.atime_diff=0"
+ do_node $CLIENT1 mcreate $file
+ pre=$(get_version $CLIENT1 $file)
+ do_node $CLIENT1 touch $file
+ post=$(get_version $CLIENT1 $file)
+ #
+ # We don't fail MDS in this test. atime_diff shall be
+ # restored to its original value.
+ #
+ do_facet $SINGLEMDS "$LCTL set_param $ad_orig"
+ if (($pre != $post)); then
+ error "version changed unexpectedly: pre $pre, post $post"
+ fi
+}
+run_test 0p "setattr of times does not change versions"
+
+test_0q() {
+ local file=$DIR/$tfile
+ local pre
+ local post
+
+ do_node $CLIENT1 mcreate $file
+ pre=$(get_version $CLIENT1 $file)
+ do_node $CLIENT1 truncate $file 1
+ post=$(get_version $CLIENT1 $file)
+ if (($pre != $post)); then
+ error "version changed unexpectedly: pre $pre, post $post"
+ fi
+}
+run_test 0q "setattr of size does not change versions"
+
+test_0r() {
+ local file=$DIR/$tfile
+ local mtime_pre
+ local mtime_post
+ local mtime
+ local var=${SINGLEMDS}_svc
+
+ do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
+ do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.atime_diff=0"
+ do_node $CLIENT1 openfile -f O_RDWR:O_CREAT -m 0644 $file
+
+ replay_barrier $SINGLEMDS
+ do_node $CLIENT2 chmod 666 $file
+ do_node $CLIENT1 truncate $file 1
+ sleep 1
+ mtime_pre=$(do_node $CLIENT1 stat --format=%Y $file)
+ do_node $CLIENT1 touch $file
+ mtime_post=$(do_node $CLIENT1 stat --format=%Y $file)
+ zconf_umount $CLIENT2 $MOUNT
+ facet_failover $SINGLEMDS
+
+ client_up $CLIENT1 || error "$CLIENT1 evicted"
+ if (($mtime_pre >= $mtime_post)); then
+ error "time not changed: pre $mtime_pre, post $mtime_post"
+ fi
+ if ! do_node $CLIENT1 $CHECKSTAT -s 1 $file; then
+ error "setattr of size failed"
+ fi
+ mtime=$(do_node $CLIENT1 stat --format=%Y $file)
+ if (($mtime != $mtime_post)); then
+ error "setattr of times failed: expected $mtime_post, got $mtime"
+ fi
+ zconf_mount $CLIENT2 $MOUNT
+}
+run_test 0r "setattr of times and size does not check versions"
+
+test_0s() {
+ local pre
+ local post
+ local tp_pre
+ local tp_post
+
+ do_node $CLIENT1 mcreate $DIR/$tfile
+ do_node $CLIENT1 mkdir -p $DIR/$tdir
+ pre=$(get_version $CLIENT1 $DIR/$tfile)
+ tp_pre=$(get_version $CLIENT1 $DIR/$tdir)
+ do_node $CLIENT1 link $DIR/$tfile $DIR/$tdir/$tfile
+ post=$(get_version $CLIENT1 $DIR/$tfile)
+ tp_post=$(get_version $CLIENT1 $DIR/$tdir)
+ if (($pre == $post)); then
+ error "version of source not changed: pre $pre, post $post"
+ fi
+ if (($tp_pre == $tp_post)); then
+ error "version of target parent not changed: pre $tp_pre, post $tp_post"
+ fi
+}
+run_test 0s "link changes versions of source and target parent"
+
+test_0t() {
+ local var=${SINGLEMDS}_svc
+
+ do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
+ do_node $CLIENT1 mcreate $DIR/$tfile
+ do_node $CLIENT1 mkdir -p -m 755 $DIR/$tdir
+
+ replay_barrier $SINGLEMDS
+ do_node $CLIENT2 chmod 777 $DIR/$tdir
+ do_node $CLIENT1 link $DIR/$tfile $DIR/$tdir/$tfile
+ zconf_umount $CLIENT2 $MOUNT
+ facet_failover $SINGLEMDS
+
+ client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
+ if ! do_node $CLIENT1 $CHECKSTAT -a $DIR/$tdir/$tfile; then
+ error "link should fail"
+ fi
+ zconf_mount $CLIENT2 $MOUNT
+}
+run_test 0t "link checks version of target parent"
+
+test_0u() {
+ local var=${SINGLEMDS}_svc
+
+ do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
+ do_node $CLIENT1 openfile -f O_RDWR:O_CREAT -m 0644 $DIR/$tfile
+ do_node $CLIENT1 mkdir -p $DIR/$tdir
+
+ replay_barrier $SINGLEMDS
+ do_node $CLIENT2 chmod 666 $DIR/$tfile
+ do_node $CLIENT1 link $DIR/$tfile $DIR/$tdir/$tfile
+ zconf_umount $CLIENT2 $MOUNT
+ facet_failover $SINGLEMDS
+
+ client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
+ if ! do_node $CLIENT1 $CHECKSTAT -a $DIR/$tdir/$tfile; then
+ error "link should fail"
+ fi
+ zconf_mount $CLIENT2 $MOUNT
+}
+run_test 0u "link checks version of source"
+
+test_0v() {
+ local sp_pre
+ local tp_pre
+ local sp_post
+ local tp_post
+
+ do_node $CLIENT1 mcreate $DIR/$tfile
+ do_node $CLIENT1 mkdir -p $DIR/$tdir
+ sp_pre=$(get_version $CLIENT1 $DIR)
+ tp_pre=$(get_version $CLIENT1 $DIR/$tdir)
+ do_node $CLIENT1 mv $DIR/$tfile $DIR/$tdir/$tfile
+ sp_post=$(get_version $CLIENT1 $DIR)
+ tp_post=$(get_version $CLIENT1 $DIR/$tdir)
+ if (($sp_pre == $sp_post)); then
+ error "version of source parent not changed: pre $sp_pre, post $sp_post"
+ fi
+ if (($tp_pre == $tp_post)); then
+ error "version of target parent not changed: pre $tp_pre, post $tp_post"
+ fi
+}
+run_test 0v "rename changes versions of source parent and target parent"
+
+test_0w() {
+ local pre
+ local post
+
+ do_node $CLIENT1 mcreate $DIR/$tfile
+ pre=$(get_version $CLIENT1 $DIR)
+ do_node $CLIENT1 mv $DIR/$tfile $DIR/$tfile-new
+ post=$(get_version $CLIENT1 $DIR)
+ if (($pre == $post)); then
+ error "version of parent not changed: pre $pre, post $post"
+ fi
+}
+run_test 0w "rename within same dir changes version of parent"
+
+test_0x() {
+ local var=${SINGLEMDS}_svc
+
+ do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
+ do_node $CLIENT1 mcreate $DIR/$tfile
+ do_node $CLIENT1 mkdir -p -m 755 $DIR/$tdir
+
+ replay_barrier $SINGLEMDS
+ do_node $CLIENT2 chmod 777 $DIR
+ do_node $CLIENT1 mv $DIR/$tfile $DIR/$tdir/$tfile
+ zconf_umount $CLIENT2 $MOUNT
+ facet_failover $SINGLEMDS
+
+ client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
+ if do_node $CLIENT1 $CHECKSTAT -a $DIR/$tfile; then
+ error "rename should fail"
+ fi
+ zconf_mount $CLIENT2 $MOUNT
+}
+run_test 0x "rename checks version of source parent"
+
+test_0y() {
+ local var=${SINGLEMDS}_svc
+
+ do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
+ do_node $CLIENT1 mcreate $DIR/$tfile
+ do_node $CLIENT1 mkdir -p -m 755 $DIR/$tdir
+
+ replay_barrier $SINGLEMDS
+ do_node $CLIENT2 chmod 777 $DIR/$tdir
+ do_node $CLIENT1 mv $DIR/$tfile $DIR/$tdir/$tfile
+ zconf_umount $CLIENT2 $MOUNT
+ facet_failover $SINGLEMDS
+
+ client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
+ if do_node $CLIENT1 $CHECKSTAT -a $DIR/$tfile; then
+ error "rename should fail"
+ fi
+ zconf_mount $CLIENT2 $MOUNT
+}
+run_test 0y "rename checks version of target parent"
+