[blobfs] Add additional annotations.

Add additional lock annotations and some TODOs about future
parallelization.

Change-Id: Iccbe05f1500f2f4698ba077d7c6e69f7b09c11ba
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/512519
Reviewed-by: Martin Lindsay <mlindsay@google.com>
Commit-Queue: Brett Wilson <brettw@google.com>
diff --git a/src/storage/blobfs/blob.cc b/src/storage/blobfs/blob.cc
index f05e07d..612b920 100644
--- a/src/storage/blobfs/blob.cc
+++ b/src/storage/blobfs/blob.cc
@@ -778,6 +778,11 @@
 
 zx_status_t Blob::ReadInternal(void* data, size_t len, size_t off, size_t* actual) {
   TRACE_DURATION("blobfs", "Blobfs::ReadInternal", "len", len, "off", off);
+
+  // TODO(fxbug.dev/74088) allow multiple reads at a time as long as the blob is completely
+  // loaded. This may involve moving the lock to LoadVmosFromDisk and auditing the inode_ and vmo_
+  // usage in the code below to see if we can guarantee it won't change out from under us outside
+  // the lock.
   std::lock_guard lock(mutex_);
 
   if (state() != BlobState::kReadable) {
@@ -1086,10 +1091,16 @@
 
 zx_status_t Blob::GetAttributes(fs::VnodeAttributes* a) {
   auto event = blobfs_->Metrics()->NewLatencyEvent(fs_metrics::Event::kGetAttr);
+
+  // SizeData() expects to be called outside the lock.
+  auto content_size = SizeData();
+
+  std::lock_guard lock(mutex_);
+
   *a = fs::VnodeAttributes();
   a->mode = V_TYPE_FILE | V_IRUSR;
-  a->inode = Ino();
-  a->content_size = SizeData();
+  a->inode = map_index_;
+  a->content_size = content_size;
   a->storage_size = inode_.block_count * kBlobfsBlockSize;
   a->link_count = 1;
   a->creation_time = 0;
diff --git a/src/storage/blobfs/blob.h b/src/storage/blobfs/blob.h
index 84a41bb..2e86d4e 100644
--- a/src/storage/blobfs/blob.h
+++ b/src/storage/blobfs/blob.h
@@ -397,7 +397,7 @@
   // - blob_size
   // - block_count
   // To save space, we could avoid holding onto the entire inode.
-  Inode inode_ = {};
+  Inode inode_ FS_TA_GUARDED(mutex_) = {};
 
   // Data used exclusively during writeback.
   struct WriteInfo;