Skip to content

Commit b9712e0

Browse files
committed
A range another holder has is reported as one value, not either of two
⚠️⚠️ THE STANDARD THIS CALL COMES FROM NAMES TWO VALUES FOR ONE CONDITION AND LEAVES THE CHOICE TO THE SYSTEM. openkal names one. For a lock attempt that does not wait, a range another holder has is reported as EITHER of two errors --- the system decides. So a program written against the standard accepts both, and an implementation of openkal must NOT pass that choice on: `kal_err_again' is the answer a caller polls upon, and the other value translates to `kal_err_permission', which a caller reads as "asking again will not help" and acts upon by stopping. ⭐ NARROWED TO THE ATTEMPT THAT DOES NOT WAIT, because that is the only path for which the two values carry this meaning. A permission failure anywhere else keeps its own answer. ⚠️ Found by looking rather than by failing: this kernel answers the first value in practice, so the observation passes here either way. The sibling implementation is on a system whose lineage answers the other one, and the two implementations must not disagree about what a caller sees.
1 parent bd5ad20 commit b9712e0

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/fs.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,17 @@ static int lock_range(kal_file f, kal_u64 start, kal_u64 len,
332332
do {
333333
r = okm::sys(okm::nr_fcntl, fd, cmd, reinterpret_cast<okm_long>(&fl));
334334
} while (r == -okm::e_intr);
335-
return okm::failed(r) ? okm::translate(r) : kal_ok;
335+
if (!okm::failed(r)) return kal_ok;
336+
337+
// ⚠️⚠️ TWO VALUES MEAN ONE THING HERE, AND openkal NAMES ONE OF THEM. The
338+
// standard this call comes from reports a range another holder has as
339+
// EITHER of two values and leaves the choice to the system. openkal says
340+
// `kal_err_again', which a caller polls upon; the other translates to
341+
// `permission', which a caller reads as "asking again will not help".
342+
// Narrowed to the attempt that does not wait, where alone the two carry
343+
// this meaning.
344+
if (!wait && (-r == okm::e_acces || -r == okm::e_again)) return kal_err_again;
345+
return okm::translate(r);
336346
}
337347

338348
int kal_fs_lock(kal_file f, kal_u64 start, kal_u64 len, kal_uintptr mode) {

0 commit comments

Comments
 (0)