summaryrefslogtreecommitdiff
path: root/9ns/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-01 22:59:16 -0300
committerGabriel Schneider <[email protected]>2026-10-01 22:59:16 -0300
commite66b2cfcf4e196ec04c73a33364cb567dbcc5d18 (patch)
tree4ef76cb38748dfbb086ce2c2e07a99109ef807a7 /9ns/src
parent34834165e2b54dd6ac26babd1e9d0443f1f53ee4 (diff)
downloadcloud9-e66b2cfcf4e196ec04c73a33364cb567dbcc5d18.tar.gz
cloud9-e66b2cfcf4e196ec04c73a33364cb567dbcc5d18.zip
9ns: regular files open with FOPEN_PARALLEL_DIRECT_WRITES, so a write that waits on another write to the same file (an Edit filter writing the ctl its Edit came by) is not queued behind it
Linux 6.2 (FUSE 7.38) takes the inode lock shared for such a write unless it appends or goes past the file's end; older kernels ignore the bit. An O_TRUNC open still takes the lock outright, so a second writer that truncates (`>`) still waits; `1<>` does not. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to '9ns/src')
-rw-r--r--9ns/src/bridge.zig8
-rw-r--r--9ns/src/fuse.zig6
2 files changed, 10 insertions, 4 deletions
diff --git a/9ns/src/bridge.zig b/9ns/src/bridge.zig
index 07bd5d8..97e0882 100644
--- a/9ns/src/bridge.zig
+++ b/9ns/src/bridge.zig
@@ -643,8 +643,8 @@ const Bridge = struct {
fn openFlags(is_dir: bool, stream: bool, direct_io: bool) u32 {
if (is_dir) return 0;
- if (stream) return fuse.FOPEN_DIRECT_IO | fuse.FOPEN_NONSEEKABLE;
- return if (direct_io) fuse.FOPEN_DIRECT_IO else 0;
+ if (stream) return fuse.FOPEN_DIRECT_IO | fuse.FOPEN_NONSEEKABLE | fuse.FOPEN_PARALLEL_DIRECT_WRITES;
+ return if (direct_io) fuse.FOPEN_DIRECT_IO | fuse.FOPEN_PARALLEL_DIRECT_WRITES else 0;
}
fn newHandle(b: *Bridge, fid: u32, nodeid: u64) HandlerError!u64 {
@@ -2581,8 +2581,8 @@ test "attr mapping: DMDIR → S_IFDIR|perm, length → size/blocks" {
test "a file whose stat length is 0 opens direct and nonseekable, whatever the cache option" {
for ([_]bool{ false, true }) |direct_io| {
- try std.testing.expectEqual(fuse.FOPEN_DIRECT_IO | fuse.FOPEN_NONSEEKABLE, Bridge.openFlags(false, true, direct_io));
- try std.testing.expectEqual(@as(u32, if (direct_io) fuse.FOPEN_DIRECT_IO else 0), Bridge.openFlags(false, false, direct_io));
+ try std.testing.expectEqual(fuse.FOPEN_DIRECT_IO | fuse.FOPEN_NONSEEKABLE | fuse.FOPEN_PARALLEL_DIRECT_WRITES, Bridge.openFlags(false, true, direct_io));
+ try std.testing.expectEqual(@as(u32, if (direct_io) fuse.FOPEN_DIRECT_IO | fuse.FOPEN_PARALLEL_DIRECT_WRITES else 0), Bridge.openFlags(false, false, direct_io));
try std.testing.expectEqual(@as(u32, 0), Bridge.openFlags(true, true, direct_io));
}
}
diff --git a/9ns/src/fuse.zig b/9ns/src/fuse.zig
index e45abc2..5f7b22a 100644
--- a/9ns/src/fuse.zig
+++ b/9ns/src/fuse.zig
@@ -27,6 +27,12 @@ pub const root_id: u64 = 1;
pub const FOPEN_DIRECT_IO: u32 = 1 << 0;
pub const FOPEN_KEEP_CACHE: u32 = 1 << 1;
pub const FOPEN_NONSEEKABLE: u32 = 1 << 2;
+/// Direct writes to one inode go to the server side by side, not one at a
+/// time under the inode's lock (protocol 7.38, Linux 6.2; older kernels
+/// ignore the bit). A write the server answers only once another write to
+/// the same file has run (an Edit whose filter writes the ctl it came by)
+/// otherwise waits on itself.
+pub const FOPEN_PARALLEL_DIRECT_WRITES: u32 = 1 << 6;
pub const FUSE_ASYNC_READ: u32 = 1 << 0;
/// The kernel passes O_TRUNC in OPEN instead of a separate SETATTR(size=0); 9P has OTRUNC for exactly this.