Bug 223383 - pathconf querying for posix_falloc not supported on freebsd
Summary: pathconf querying for posix_falloc not supported on freebsd
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-02 17:38 UTC by Enji Cooper
Modified: 2017-11-16 21:45 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Enji Cooper freebsd_committer 2017-11-02 17:38:00 UTC
We don’t support querying for posix_falloc support at the filesystem level, but we probably should.

Here’s the Austin bug from 2013 for reference: http://austingroupbugs.net/view.php?id=687 .

Here’s one part of where it should be supported: https://svnweb.freebsd.org/base/head/sys/sys/unistd.h?revision=306651
Comment 1 Mark Millard 2017-11-04 11:04:12 UTC
FYI:

lld is now broken on zfs because it use fallocate.
I had this happen for a amd64 -> aarch64 cross
buildworld where it refused to try to deal
with making a libc.so.7.full file.

llvm has the code (note the EOPNOTSUPP use):

std::error_code resize_file(int FD, uint64_t Size) {
#if defined(HAVE_POSIX_FALLOCATE)
 // If we have posix_fallocate use it. Unlike ftruncate it always allocates
 // space, so we get an error if the disk is full.
 if (int Err = ::posix_fallocate(FD, 0, Size)) {
   if (Err != EOPNOTSUPP)
     return std::error_code(Err, std::generic_category());
 }
#endif
 // Use ftruncate as a fallback. It may or may not allocate space. At least on
 // OS X with HFS+ it does.
 if (::ftruncate(FD, Size) == -1)
   return std::error_code(errno, std::generic_category());

 return std::error_code();
}


See, for example,

https://lists.freebsd.org/pipermail/freebsd-toolchain/2017-November/003413.html

for other details that lead to the eventual
error message from lld.

I reverted to using devel/aarch64-binutils
for now.
Comment 2 Mark Millard 2017-11-04 11:14:48 UTC
(In reply to Mark Millard from comment #1)

Note: I'm not sure I can self host a buildworld
involving lld on amd64 at this point: lld is
likely broken in the same way as the cross
compiler was, as of when I jumped to:

# uname -apKU
FreeBSD FreeBSDx64OPC 12.0-CURRENT FreeBSD 12.0-CURRENT  r325369M  amd64 amd64 1200052 1200052

from before the disabling of fallocate.

I may have to use binutils to do the next
update.
Comment 3 Enji Cooper freebsd_committer 2017-11-04 19:49:23 UTC
(In reply to Mark Millard from comment #1)

Please file a separate bug for this. Thanks!
Comment 4 Mark Millard 2017-11-05 00:24:10 UTC
(In reply to Ngie Cooper from comment #3)

Done.

Bugzilla 223440 notes lld and possibly
more in world that needs review and
possible adjustment.

Ed Maste already has a patch on the lists
for llvm in order for lld to be well
behaved. See:

https://lists.freebsd.org/pipermail/freebsd-current/2017-November/067432.html

It fixed the problem that I saw.

I do not know if any of the existing use
would ever be adjusted to use what is
proposed here or not. It does not seem
likely for the llvm code involved in lld:
Ed's change looks appropriate to that
context to me.
Comment 5 commit-hook freebsd_committer 2017-11-05 00:52:25 UTC
A commit references this bug:

Author: emaste
Date: Sun Nov  5 00:51:53 UTC 2017
New revision: 325420
URL: https://svnweb.freebsd.org/changeset/base/325420

Log:
  lld: accept EINVAL to indicate posix_fallocate is unsupported

  As of r325320 posix_fallocate on a ZFS filesystem returns EINVAL to
  indicate that the operation is not supported. (I think this is a strange
  choice of errno on the part of POSIX.)

  PR:		223383, 223440
  Reported by:	Mark Millard
  Tested by:	Mark Millard
  MFC after:	3 days
  Sponsored by:	The FreeBSD Foundation

Changes:
  head/contrib/llvm/lib/Support/Unix/Path.inc
Comment 6 John Baldwin freebsd_committer freebsd_triage 2017-11-06 22:51:28 UTC
Note that POSIX has not yet settled on a pathconf() variable for fallocate.  That link is just a discussion, but we can't implement it until they decide to adopt something.
Comment 7 commit-hook freebsd_committer 2017-11-08 00:43:10 UTC
A commit references this bug:

Author: emaste
Date: Wed Nov  8 00:39:04 UTC 2017
New revision: 325523
URL: https://svnweb.freebsd.org/changeset/base/325523

Log:
  MFC r325420: lld: accept EINVAL to indicate posix_fallocate is unsupported

  As of r325320 posix_fallocate on a ZFS filesystem returns EINVAL to
  indicate that the operation is not supported. (I think this is a strange
  choice of errno on the part of POSIX.)

  PR:		223383, 223440
  Reported by:	Mark Millard
  Sponsored by:	The FreeBSD Foundation

Changes:
_U  stable/11/
  stable/11/contrib/llvm/lib/Support/Unix/Path.inc
Comment 8 Ed Maste freebsd_committer 2017-11-09 14:49:14 UTC
Unassign: I fixed up the problem reported by Mark Millard in this PR but am not currently working on pathconf.
Comment 9 commit-hook freebsd_committer 2017-11-12 09:10:07 UTC
A commit references this bug:

Author: brooks
Date: Sun Nov 12 09:09:35 UTC 2017
New revision: 454025
URL: https://svnweb.freebsd.org/changeset/ports/454025

Log:
  Merge from src:

  lld: accept EINVAL to indicate posix_fallocate is unsupported

  As of r325320 posix_fallocate on a ZFS filesystem returns EINVAL to
  indicate that the operation is not supported. (I think this is a strange
  choice of errno on the part of POSIX.)

  PR:		223383, 223440
  Reported by:	Mark Millard

Changes:
  head/devel/llvm50/Makefile
  head/devel/llvm50/files/patch-lib_Support_Unix_Path.inc
Comment 10 Andriy Gapon freebsd_committer 2017-11-12 09:12:24 UTC
(In reply to commit-hook from comment #9)
Thank you!
Comment 11 Mark Millard 2017-11-12 23:30:35 UTC
(In reply to commit-hook from comment #9)

Note: I reported devel/llvm50 but I do not have
devel/llvm40 or earlier installed to test.

I'd not be surprised if a large range of:

devel/llvm*

were broken on zfs after the fallocate fix for
zfs.
Comment 12 Ed Maste freebsd_committer 2017-11-13 00:46:50 UTC
devel/llvm40 could probably make effective use of the change (if the issue also exists there).  On earlier versions LLD is probably not usable enough to worry.
Comment 13 commit-hook freebsd_committer 2017-11-13 01:45:52 UTC
A commit references this bug:

Author: brooks
Date: Mon Nov 13 01:45:13 UTC 2017
New revision: 454093
URL: https://svnweb.freebsd.org/changeset/ports/454093

Log:
  Merge from src and upstream LLVM:

  lld: accept EINVAL to indicate posix_fallocate is unsupported

  As of r325320 posix_fallocate on a ZFS filesystem returns EINVAL to
  indicate that the operation is not supported. (I think this is a strange
  choice of errno on the part of POSIX.)

  PR:		223383, 223440
  Reported by:	Mark Millard

Changes:
  head/devel/llvm40/Makefile
  head/devel/llvm40/files/patch-lib_Support_Unix_Path.inc
Comment 14 Brooks Davis freebsd_committer 2017-11-13 02:13:08 UTC
llvm40 and llvm50 had the issue.  llvm39 does not include posix_fallocate() use and I assume earlier versions do not as well.  I'll be updating llvm-devel to pick up the fix from upstream and patching llvm-cheri* soon.
Comment 15 commit-hook freebsd_committer 2017-11-13 02:48:45 UTC
A commit references this bug:

Author: brooks
Date: Mon Nov 13 02:47:52 UTC 2017
New revision: 454097
URL: https://svnweb.freebsd.org/changeset/ports/454097

Log:
  Update to a new snapshot.

  This includes the fix for posix_fallocate not being supported on ZFS.

  PR:		223383, 223440
  Reported by:	Mark Millard

Changes:
  head/devel/llvm-devel/Makefile
  head/devel/llvm-devel/Makefile.snapshot
  head/devel/llvm-devel/distinfo
  head/devel/llvm-devel/pkg-plist
Comment 16 commit-hook freebsd_committer 2017-11-16 21:45:24 UTC
A commit references this bug:

Author: brooks
Date: Thu Nov 16 21:44:19 UTC 2017
New revision: 454342
URL: https://svnweb.freebsd.org/changeset/ports/454342

Log:
  Update to a new snapshot and apply the patch for posix_fallocate()
  support being remove for ZFS

  PR:		223383, 223440
  Sponsored by:	DARPA, AFRL

Changes:
  head/devel/llvm-cheri/Makefile
  head/devel/llvm-cheri/Makefile.snapshot
  head/devel/llvm-cheri/distinfo
  head/devel/llvm-cheri/files/gen-Makefile.snapshot.sh
  head/devel/llvm-cheri/files/patch-lib_Support_Unix_Path.inc
  head/devel/llvm-cheri/pkg-plist