Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for utimensat(2) #6

Merged
merged 1 commit into from
Apr 2, 2017
Merged

Add tests for utimensat(2) #6

merged 1 commit into from
Apr 2, 2017

Conversation

asomers
Copy link
Collaborator

@asomers asomers commented Jan 26, 2017

Add tests for utimensat(2). They pass on FreeBSD/UFS. They fail on FreeBSD/ZFS (but I have a fix ready). I haven't tested them on Linux or Illumos.

uqs pushed a commit to freebsd/freebsd-src that referenced this pull request Feb 9, 2017
sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
	* In zfs_freebsd_setattr, if the caller wants to set the birthtime,
	  set the bits that zfs_settattr expects

	* In zfs_setattr, if XAT_CREATETIME is set, set xoa_createtime,
	  expected by zfs_xvattr_set.  The two levels of indirection seem
	  excessive, but it minimizes diffs vs OpenZFS.

	* In zfs_setattr, check for overflow of va_birthtime (from delphij)

	* Remove red herring in zfs_getattr

sys/cddl/contrib/opensolaris/uts/common/sys/vnode.h
	* Un-booby-trap some macros

New tests are under review at pjd/pjdfstest#6

Reviewed by:	avg
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D9353


git-svn-id: svn+ssh://svn.freebsd.org/base/head@313483 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
uqs pushed a commit to freebsd/freebsd-src that referenced this pull request Feb 9, 2017
sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
	* In zfs_freebsd_setattr, if the caller wants to set the birthtime,
	  set the bits that zfs_settattr expects

	* In zfs_setattr, if XAT_CREATETIME is set, set xoa_createtime,
	  expected by zfs_xvattr_set.  The two levels of indirection seem
	  excessive, but it minimizes diffs vs OpenZFS.

	* In zfs_setattr, check for overflow of va_birthtime (from delphij)

	* Remove red herring in zfs_getattr

sys/cddl/contrib/opensolaris/uts/common/sys/vnode.h
	* Un-booby-trap some macros

New tests are under review at pjd/pjdfstest#6

Reviewed by:	avg
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D9353
Copy link
Collaborator

@ngie-eign ngie-eign left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a first-pass at the change. I'll look at it further when I have some time to do so.

pjdfstest.c Outdated
printf("%lld", (long long)sp->st_mtime);
else if (strcmp(what, "mtime_ns") == 0)
printf("%lld", (long long)sp->st_mtim.tv_nsec);
else if (strcmp(what, "birthtime") == 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A #ifdef will need to be added for this: FreeBSD is the only OS that supports .birthtime in struct stat.

cd ${n1}

DATE1=1900000000 #Sun Mar 17 11:46:40 MDT 2030
DATE2=1950000000 #Fri Oct 17 04:40:00 MDT 2031
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a problem with architectures/OSes that don't support 64-bit time_t?

Copy link
Collaborator Author

@asomers asomers Feb 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. I chose all of those constants to fit within 32 bits.


expect 0 mkdir ${n1} 0755
cdir=`pwd`
cd ${n1}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be expect-ed so we're sure that we're going to the proper directory before and after the test and not just littering temporary files where the test is being run from... whether or not pjdfstest does this 100% of the time elsewhere though is a good question. If not, then it should be fixed everywhere in a separate commit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, pjdfstest generally doesn't do that. Let's do that separately.

echo "not ok 4 mtime was not updated"
fi
if [ "$delta_atime" -gt 0 ]; then
if [ "$delta_atime" -lt 300 ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, why 5 mins?

delta_atime=$(( $new_atime - $old_atime ))

if [ "$delta_mtime" -gt 0 ]; then
if [ "$delta_mtime" -lt 300 ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Why 5 mins?
  • Why isn't this value a constant?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no way for pjdfstest to know exactly what time will get set when it says UTIME_NOW. So it checks for anything that's "approximately now". It can't even know what direction the error will be, because ntp or something may come and change the clock. Five minutes is a pretty arbitrary margin of error. I'll constantify it.

. ${dir}/../misc.sh
echo "1..7"

require utimensat
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These calls should be moved up before the test plan summaries -- the reason why is that if the require fails, then it'll print out something like:

1..7
1..1

This will confuse the TAP parsers. I know this will cause kyua to choke at least (and I think prove will reject the test because of the test plan mismatch).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'll just delete it, because utimensat is part of POSIX and AFAIK everything supports it (but I don't have a OSX machine to check). I'll add a separate require statement for the birthtime-specific tests.


require utimensat

UTIME_NOW=-1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better for these constants to be symbolic and referenced in the C code -- there's no telling whether or not all of the constants are defined with the same values.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call. Looks like it's different on Linux.

#! /bin/sh
# $FreeBSD$

desc="utimensat can update birthtimes"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please skip if not run on FreeBSD.

bdrewery pushed a commit to bdrewery/freebsd that referenced this pull request Feb 15, 2017
sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
	* In zfs_freebsd_setattr, if the caller wants to set the birthtime,
	  set the bits that zfs_settattr expects

	* In zfs_setattr, if XAT_CREATETIME is set, set xoa_createtime,
	  expected by zfs_xvattr_set.  The two levels of indirection seem
	  excessive, but it minimizes diffs vs OpenZFS.

	* In zfs_setattr, check for overflow of va_birthtime (from delphij)

	* Remove red herring in zfs_getattr

sys/cddl/contrib/opensolaris/uts/common/sys/vnode.h
	* Un-booby-trap some macros

New tests are under review at pjd/pjdfstest#6

Reviewed by:	avg
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D9353


git-svn-id: svn+ssh://svn.freebsd.org/base/head@313483 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
brooksdavis pushed a commit to CTSRD-CHERI/cheribsd that referenced this pull request Feb 28, 2017
sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
	* In zfs_freebsd_setattr, if the caller wants to set the birthtime,
	  set the bits that zfs_settattr expects

	* In zfs_setattr, if XAT_CREATETIME is set, set xoa_createtime,
	  expected by zfs_xvattr_set.  The two levels of indirection seem
	  excessive, but it minimizes diffs vs OpenZFS.

	* In zfs_setattr, check for overflow of va_birthtime (from delphij)

	* Remove red herring in zfs_getattr

sys/cddl/contrib/opensolaris/uts/common/sys/vnode.h
	* Un-booby-trap some macros

New tests are under review at pjd/pjdfstest#6

Reviewed by:	avg
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D9353
@asomers
Copy link
Collaborator Author

asomers commented Mar 8, 2017

@pjd are you interested in this PR? If not, I can submit it directly to FreeBSD.

Copy link
Collaborator

@ngie-eign ngie-eign left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look good to me.

uqs pushed a commit to freebsd/freebsd-src that referenced this pull request Apr 2, 2017
Fix setting birthtime in ZFS

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
	* In zfs_freebsd_setattr, if the caller wants to set the birthtime,
	  set the bits that zfs_settattr expects

	* In zfs_setattr, if XAT_CREATETIME is set, set xoa_createtime,
	  expected by zfs_xvattr_set.  The two levels of indirection seem
	  excessive, but it minimizes diffs vs OpenZFS.

	* In zfs_setattr, check for overflow of va_birthtime (from delphij)

	* Remove red herring in zfs_getattr

sys/cddl/contrib/opensolaris/uts/common/sys/vnode.h
	* Un-booby-trap some macros

New tests are under review at pjd/pjdfstest#6

Reviewed by:	avg
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D9353
The st_birthtime tests are only supported on FreeBSD, but everything
else is universal.
@ngie-eign
Copy link
Collaborator

ngie-eign commented Apr 3, 2017

This change unfortunately broke OS X again. I'm trying to figure out more details about struct stat between the OSes. Once I have an idea of how things are split up, I'll send out another PR.

mat813 pushed a commit to mat813/freebsd that referenced this pull request Apr 3, 2017
Fix setting birthtime in ZFS

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
	* In zfs_freebsd_setattr, if the caller wants to set the birthtime,
	  set the bits that zfs_settattr expects

	* In zfs_setattr, if XAT_CREATETIME is set, set xoa_createtime,
	  expected by zfs_xvattr_set.  The two levels of indirection seem
	  excessive, but it minimizes diffs vs OpenZFS.

	* In zfs_setattr, check for overflow of va_birthtime (from delphij)

	* Remove red herring in zfs_getattr

sys/cddl/contrib/opensolaris/uts/common/sys/vnode.h
	* Un-booby-trap some macros

New tests are under review at pjd/pjdfstest#6

Reviewed by:	avg
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D9353


git-svn-id: https://svn.freebsd.org/base/stable/11@316391 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants