about summary refs log tree commit diff
path: root/tvix/castore/src
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2024-04-15T10·52+0300
committerclbot <clbot@tvl.fyi>2024-04-15T13·54+0000
commitd3d88431f3fab17f545b459273d180f433a1b419 (patch)
tree84d2c4d699fa8bbb4db7f2be45770b74929e4a04 /tvix/castore/src
parent34d9d54aae4b5ff2b6a231ca986c987568a03bda (diff)
feat(tvix/castore/fs): assign read[dir*]/release[dir] ops to parent span r/7919
When a directory or file is open()'ed, we already put some data into
a lookup table, and subsequent operations then use the returned handle
id.

By also adding the span that's been created during these calls into the
lookup table, we can properly set the span parent for these requests,
nicely connecting the individual operations to the bigger picture.

Change-Id: Ia354842fccdbc7f45c2d3efda3acf058b2dbc48e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11429
Reviewed-by: Connor Brewster <cbrewster@hey.com>
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: Brian Olsen <me@griff.name>
Diffstat (limited to 'tvix/castore/src')
-rw-r--r--tvix/castore/src/fs/mod.rs33
1 files changed, 20 insertions, 13 deletions
diff --git a/tvix/castore/src/fs/mod.rs b/tvix/castore/src/fs/mod.rs
index 3113d1e384ea..89a9986202ea 100644
--- a/tvix/castore/src/fs/mod.rs
+++ b/tvix/castore/src/fs/mod.rs
@@ -102,14 +102,21 @@ pub struct TvixStoreFs<BS, DS, RN> {
     /// This holds all opendir handles (for the root inode)
     /// They point to the rx part of the channel producing the listing.
     #[allow(clippy::type_complexity)]
-    dir_handles:
-        RwLock<HashMap<u64, Arc<Mutex<mpsc::Receiver<(usize, Result<Node, crate::Error>)>>>>>,
+    dir_handles: RwLock<
+        HashMap<
+            u64,
+            (
+                Span,
+                Arc<Mutex<mpsc::Receiver<(usize, Result<Node, crate::Error>)>>>,
+            ),
+        >,
+    >,
 
     next_dir_handle: AtomicU64,
 
     /// This holds all open file handles
     #[allow(clippy::type_complexity)]
-    file_handles: RwLock<HashMap<u64, Arc<Mutex<Box<dyn BlobReader>>>>>,
+    file_handles: RwLock<HashMap<u64, (Span, Arc<Mutex<Box<dyn BlobReader>>>)>>,
 
     next_file_handle: AtomicU64,
 
@@ -422,7 +429,7 @@ where
             debug!("add dir handle {}", dh);
             self.dir_handles
                 .write()
-                .insert(dh, Arc::new(Mutex::new(rx)));
+                .insert(dh, (Span::current(), Arc::new(Mutex::new(rx))));
 
             return Ok((
                 Some(dh),
@@ -433,7 +440,7 @@ where
         Ok((None, OpenOptions::empty()))
     }
 
-    #[tracing::instrument(skip_all, fields(rq.inode = inode, rq.handle = handle, rq.offset = offset))]
+    #[tracing::instrument(skip_all, fields(rq.inode = inode, rq.handle = handle, rq.offset = offset), parent = self.dir_handles.read().get(&handle).and_then(|x| x.0.id()))]
     fn readdir(
         &self,
         _ctx: &Context,
@@ -451,7 +458,7 @@ where
             }
 
             // get the handle from [self.dir_handles]
-            let rx = match self.dir_handles.read().get(&handle) {
+            let (_span, rx) = match self.dir_handles.read().get(&handle) {
                 Some(rx) => rx.clone(),
                 None => {
                     warn!("dir handle {} unknown", handle);
@@ -533,7 +540,7 @@ where
         Ok(())
     }
 
-    #[tracing::instrument(skip_all, fields(rq.inode = inode, rq.handle = handle))]
+    #[tracing::instrument(skip_all, fields(rq.inode = inode, rq.handle = handle), parent = self.dir_handles.read().get(&handle).and_then(|x| x.0.id()))]
     fn readdirplus(
         &self,
         _ctx: &Context,
@@ -554,7 +561,7 @@ where
             }
 
             // get the handle from [self.dir_handles]
-            let rx = match self.dir_handles.read().get(&handle) {
+            let (_span, rx) = match self.dir_handles.read().get(&handle) {
                 Some(rx) => rx.clone(),
                 None => {
                     warn!("dir handle {} unknown", handle);
@@ -657,7 +664,7 @@ where
         Ok(())
     }
 
-    #[tracing::instrument(skip_all, fields(rq.inode = inode, rq.handle = handle))]
+    #[tracing::instrument(skip_all, fields(rq.inode = inode, rq.handle = handle), parent = self.dir_handles.read().get(&handle).and_then(|x| x.0.id()))]
     fn releasedir(
         &self,
         _ctx: &Context,
@@ -728,7 +735,7 @@ where
                         debug!("add file handle {}", fh);
                         self.file_handles
                             .write()
-                            .insert(fh, Arc::new(Mutex::new(blob_reader)));
+                            .insert(fh, (Span::current(), Arc::new(Mutex::new(blob_reader))));
 
                         Ok((
                             Some(fh),
@@ -740,7 +747,7 @@ where
         }
     }
 
-    #[tracing::instrument(skip_all, fields(rq.inode = inode, rq.handle = handle))]
+    #[tracing::instrument(skip_all, fields(rq.inode = inode, rq.handle = handle), parent = self.file_handles.read().get(&handle).and_then(|x| x.0.id()))]
     fn release(
         &self,
         _ctx: &Context,
@@ -763,7 +770,7 @@ where
         Ok(())
     }
 
-    #[tracing::instrument(skip_all, fields(rq.inode = inode, rq.offset = offset, rq.size = size))]
+    #[tracing::instrument(skip_all, fields(rq.inode = inode, rq.offset = offset, rq.size = size), parent = self.file_handles.read().get(&handle).and_then(|x| x.0.id()))]
     fn read(
         &self,
         _ctx: &Context,
@@ -780,7 +787,7 @@ where
         // We need to take out the blob reader from self.file_handles, so we can
         // interact with it in the separate task.
         // On success, we pass it back out of the task, so we can put it back in self.file_handles.
-        let blob_reader = self
+        let (_span, blob_reader) = self
             .file_handles
             .read()
             .get(&handle)