Bug #15291
closedzfs-tests errno flaws exposed by 15220
100%
Description
While testing SmartOS 20221229, I found several regressions in the ZFS test suite.
> /opt/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_001_pos > /opt/zfs-tests/tests/functional/grow_pool/grow_pool_001_pos > /opt/zfs-tests/tests/functional/grow_replicas/grow_replicas_001_pos > /opt/zfs-tests/tests/functional/no_space/enospc_001_pos > /opt/zfs-tests/tests/functional/quota/quota_001_pos > /opt/zfs-tests/tests/functional/quota/quota_002_pos > /opt/zfs-tests/tests/functional/quota/quota_003_pos > /opt/zfs-tests/tests/functional/quota/quota_004_pos > /opt/zfs-tests/tests/functional/reservation/reservation_008_pos > /opt/zfs-tests/tests/functional/reservation/reservation_009_pos > /opt/zfs-tests/tests/functional/reservation/reservation_010_pos > /opt/zfs-tests/tests/functional/reservation/reservation_012_pos > /opt/zfs-tests/tests/functional/reservation/reservation_015_pos > /opt/zfs-tests/tests/functional/reservation/reservation_016_pos > /opt/zfs-tests/tests/functional/write_dirs/write_dirs_001_pos > /opt/zfs-tests/tests/functional/write_dirs/write_dirs_002_pos > /opt/zfs-tests/tests/functional/zvol/zvol_ENOSPC/zvol_ENOSPC_001_pos
Checking the first one I discovered that the support programs are expected to use errno for the exit code. We were failing because in at least one case errno was ENOTTY, not the expected (and printed by the test program) ENOSPC.
I put in a debug printf into the ksh script for zpool_clear_001_pos and found it:
SUCCESS: zpool create -f testpool1 mirror /var/tmp/testdir/file.0 /var/tmp/testdir/file.1 /var/tmp/testdir/file.2 SUCCESS: zfs create testpool1/fs open /testpool1/fs/f.3: failed [No space left on device]28. Aborting! KEBE SAYS ret is 25
Three zfs-tests binaries: file_write, file_check, and mktree have a pattern with possible misbehaviors:
/* * Given an operation (create/overwrite/append), open the file * accordingly and perform a write of the appropriate type. */ if ((bigfd = open(filename, oflag, 0666)) == -1) { (void) printf("open %s: failed [%s]%d. Aborting!\n", filename, strerror(errno), errno); /* XXX KEBE ASKS -> did errno change? */ exit(errno); }
I could not reproduce this in a toy program, but I did introduce a "exitcode" local that saves off errno immediate for return. Here's an example fix.
/* * Given an operation (create/overwrite/append), open the file * accordingly and perform a write of the appropriate type. */ if ((bigfd = open(filename, oflag, 0666)) == -1) { int exitcode = errno; /* Save it off now! */ (void) printf("open %s: failed [%s]%d. Aborting!\n", filename, strerror(errno), errno); exit(exitcode); }
Related issues
Updated by Dan McDonald 5 months ago
- Related to Bug #15220: isatty should return reasonable errnos added
Updated by Dan McDonald 5 months ago
This fix (or at the very least an early version of it) has made all of the aforementioned tests revert back to PASS, which is a win.
I also wonder if this should be pushed up to OpenZFS? Their https://github.com/openzfs/zfs/blob/master/tests/zfs-tests/cmd/file/file_write.c#L193-L207 at least shows the same antipattern.
Updated by Electric Monk 5 months ago
- Status changed from New to Closed
- % Done changed from 0 to 100
git commit b533ad075c7539225e3c982a46b1cd11554788d9
commit b533ad075c7539225e3c982a46b1cd11554788d9 Author: Dan McDonald <danmcd@mnx.io> Date: 2023-01-04T14:40:41.000Z 15291 zfs-tests errno flaws exposed by 15220 Reviewed by: Toomas Soome <tsoome@me.com> Reviewed by: Norm Jacobs <naj@snapcon.com> Reviewed by: Gordon Ross <gordon.w.ross@gmail.com> Approved by: Patrick Mooney <pmooney@pfmooney.com>
Updated by Dan McDonald 5 months ago
- Related to Bug #15294: Successful read/write calls should not set errno added
Updated by Dan McDonald 5 months ago
It's possible that if #15294 gets fixed this may be rendered extraneous. For now, however, this fix will be in -gate.