Lazy-load base layer with fanotify #6
I think it is possible that we have some data in the buffer, we should not throw it away (if n > 0).
If this happens we probably want to terminate the process. Let's either call klog.Fatalf or return here, and handle the error cleanly (eventually cancelling the top-level context). Given this is a filesystem, we probably want to try handling it cleanly
Let's return an error, and make sure we log the error somewhere - it looks like this is silent failure.
Let's carefully decode the event and return an error on unexpected events
Log if this fails
Log if this fails
Let's fail closed
Could we refactor this into a type downloadOperation, and then we do something like this:
d.lazyLoader.Lock()
downloadOperation, found := d.lazyLoader.downloadOperations[path]
if !found {
downloadOperation = newDownloadOperation(path)
d.lazyLoader.downloadOperations[path] = downloadOperation
}
d.lazyLoader.Unlock()
downloadOperation.Download(ctx, ...)
Let's cleanly close down in this case
This should take a ctx
Let's cache this connection
Are these real results or simulated?
In general I would prefer an e2e test to these very specific unit tests
We should not store ctx, we should prefer to pass it into the functions instead.
Maybe rootContextCancelFunc would be clearer
Do not store ctx, pass it down instead
rootContextCancelFunc
Log if error from unix.Close
I think it's safe to just call a cancellation function multiple times
You can assume the cancellation function is set. Create a constructor if you prefer
Let's put this into a goroutine that runs alongside where we start the grpc server, and waits for the context to exit
Maybe it would be easier to return an error and have the caller call shutdownCleanly (and log the error)
Is there a mask constant? Or should we just do metadata.Mask != unix.FAN_OPEN_PERM
Split this into its own mutex (possible a RWMutex?)
Is there a better way to get the file info? If not, let's add a comment
Let's add a comment that we fallthrough here
Yes, use t.Context
Let's replace this with an e2e test
Do we need this when we run with hostPID true?
ap-e2e is failing. Please run and fix. Also start an AGENTS.md file that describes how you should run dev/ci/presubmits/ap-e2e locally before submitting
Approved these changes.
justinsb
codebot-robot
Resolves #5
We have explored and implemented an optional hybrid on-demand lazy loader for the base layer of AgentFS volumes using the Linux
fanotifypermission events API (FAN_CLASS_PRE_CONTENT&FAN_OPEN_PERM).What was done:
1. Design Document: Created
docs/experiments/lazy-load.mdto document the architectural analysis, comparing EROFS andfanotifyfor on-demand base layer population.2. Experimental Flag: Added a
--lazy-load-thresholdflag (default-1to disable, specifies threshold in bytes).3. Sparse Placeholders: When registering files above the threshold, sparse placeholders of the correct metadata size are generated rather than pre-downloaded, allowing the volume to mount and the application container to start instantly.
4. On-Demand Interception: Created a background
fanotifylistener inagentfs-node-daemon. When non-daemon processes attempt to open sparse placeholders,FAN_OPEN_PERMevents are intercepted to block the process, download the file from the controller, write the file data, and resume the caller seamlessly.5. Safe Fallback: Added immediate fallback to non-lazy-load mode if the host environment does not support or permit
fanotifyoperations.6. Concurrency Controls & Unit Tests: Handled multiple concurrent file opens through a thread-safe coordination mechanism where only one thread downloads and the rest wait. Added unit tests in
cmd/agentfs-node-daemon/main_test.goto verify this logic.