Skip to content

gofer: do not stat cached regular files during PrepareSave by default - #16346

Merged
copybara-service[bot] merged 1 commit into
gvisor:masterfrom
DARSHANR007:issue-16208/gofer-preparesave-stat
Oct 27, 2026
Merged

copybara-service[bot] merged 1 commit into
gvisor:masterfrom
DARSHANR007:issue-16208/gofer-preparesave-stat

Conversation

@DARSHANR007

Copy link
Copy Markdown
Contributor

The problem ? , refer #16208

When you run runsc checkpoint, gVisor pauses the container to save its state.

On shared mounts, gVisor was calling stat on every single cached file one by one. Each stat call sends a message to the host and waits for an answer.

This metadata was only collected to check file sizes and edit times on restore. But runsc never turns on this check by default.

If a container has thousands of files (like node_modules or Python packages), the container was frozen for seconds just doing useless stat calls.


My suggestion

We skip these stat calls during save by default.

We add an option called ValidateMetadata (set to false by default). Now, gVisor only calls stat if the user explicitly asks for it with --validate-metadata.


Code change

In pkg/sentry/fsimpl/gofer/save_restore.go:

- if !d.fs.cachedMetadataAuthoritative() {
+ if opts.ValidateMetadata && !d.fs.cachedMetadataAuthoritative() {
      if err := d.inode.updateMetadata(ctx); err != nil {
          return err
      }
  }

Stats

Cached Files Host stat Calls (Before) Host stat Calls (Now) Pause Downtime (Before) Pause Downtime (Now)
500 files 500 calls 0 ~50 ms – 150 ms < 1 ms
1,000 files 1,000 calls 0 ~100 ms – 300 ms < 1 ms
5,000 files 5,000 calls 0 ~500 ms – 1,500 ms < 1 ms
10,000 files 10,000 calls 0 1.0 s – 3.0 s ~2 ms

Added unit tests in pkg/sentry/vfs/save_restore_test.go to test that options pass correctly.
Added test and benchmark in pkg/sentry/fsimpl/gofer/gofer_test.go

fixes #16208

Comment thread pkg/sentry/vfs/save_restore_test.go Resolved
Comment thread pkg/sentry/fsimpl/fuse/save_restore.go Resolved
Comment thread runsc/cmd/checkpoint.go Resolved
Comment thread pkg/sentry/fsimpl/gofer/save_restore.go Resolved
@DARSHANR007
DARSHANR007 requested a review from ayushr2 October 25, 2026 07:19

@ayushr2 ayushr2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash your commits.

@DARSHANR007
DARSHANR007 force-pushed the issue-16208/gofer-preparesave-stat branch from 50dda0e to 1bbc9e8 Compare October 26, 2026 04:16
@DARSHANR007
DARSHANR007 requested a review from ayushr2 October 26, 2026 04:18
Comment thread pkg/sentry/fsimpl/gofer/gofer_test.go Resolved
Comment thread pkg/sentry/fsimpl/gofer/gofer_test.go Resolved
@DARSHANR007
DARSHANR007 force-pushed the issue-16208/gofer-preparesave-stat branch from 1bbc9e8 to b514b1f Compare October 26, 2026 07:35
@DARSHANR007
DARSHANR007 requested a review from ayushr2 October 26, 2026 07:43
Comment thread pkg/sentry/vfs/save_restore.go Resolved
@ayushr2

ayushr2 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

LGTM otherwise

During PrepareSave, the gofer filesystem refreshes metadata for each
cached regular file when cached metadata is not authoritative (e.g.
shared mounts). This was done to populate file size and mtime for
validation during restore. runsc never enables this validation, so
these sequential stat calls while the sandbox is paused add unnecessary
latency.

Add PrepareSaveOptions to vfs and gate the stat calls behind
ValidateMetadata (off by default). Plumb the option through the kernel.

Signed-off-by: darsh <[email protected]>
@DARSHANR007
DARSHANR007 force-pushed the issue-16208/gofer-preparesave-stat branch from b514b1f to fced933 Compare October 26, 2026 08:33
@DARSHANR007
DARSHANR007 requested a review from ayushr2 October 26, 2026 08:38
@EtiennePerot EtiennePerot added the ready to pull Causes the PR to be imported into Google. Will be removed soon. label Oct 27, 2026
@EtiennePerot EtiennePerot added this to the Lightspeed milestone Oct 27, 2026
@milantracy

Copy link
Copy Markdown
Member

I benchmark the PR to significance, the performance gain is real, even though it is smaller than than PR claims

  • lisafs: checkpoint is 12-13% faster, about 12 µs saved for each open file (one gofer round trip).
  • directfs (the default): checkpoint is 1-2% faster, about 1 µs saved for each open file (one host fstat).

thanks @DARSHANR007

goos: linux
goarch: amd64

                                                      │   base.txt   │               pr.txt                │
                                                      │    sec/op    │   sec/op     vs base                │
CheckpointLeaveRunning/openfiles=1000/directfs=true      94.99m ± 1%   93.46m ± 1%   -1.61% (p=0.002 n=32)
CheckpointLeaveRunning/openfiles=1000/directfs=false    105.80m ± 2%   93.49m ± 1%  -11.64% (p=0.000 n=32)
CheckpointLeaveRunning/openfiles=10000/directfs=true     761.2m ± 4%   747.2m ± 3%        ~ (p=0.100 n=32)
CheckpointLeaveRunning/openfiles=10000/directfs=false    881.3m ± 1%   767.0m ± 1%  -12.97% (p=0.000 n=32)
geomean                                                  286.5m        266.0m        -7.17%

n=64, directfs with 10000 files (not significant at n=32)

goos: linux
goarch: amd64
pkg: pr16346/checkpoint
                                                     │ n64/base.txt │             n64/pr.txt             │
                                                     │    sec/op    │   sec/op     vs base               │
CheckpointLeaveRunning/openfiles=10000/directfs=true    762.0m ± 1%   754.1m ± 1%  -1.04% (p=0.000 n=64)

n=20

                                                      │   base.txt   │               pr.txt                │
                                                      │    sec/op    │   sec/op     vs base                │
CheckpointLeaveRunning/openfiles=1000/directfs=true      99.38m ± 1%   98.05m ± 1%        ~ (p=0.068 n=20)
CheckpointLeaveRunning/openfiles=1000/directfs=false    111.37m ± 2%   99.25m ± 1%  -10.88% (p=0.000 n=20)
CheckpointLeaveRunning/openfiles=10000/directfs=true     768.9m ± 2%   753.6m ± 1%   -1.99% (p=0.012 n=20)
CheckpointLeaveRunning/openfiles=10000/directfs=false    837.9m ± 1%   723.8m ± 1%  -13.61% (p=0.000 n=20)
geomean                                                  290.6m        269.9m        -7.11%

copybara-service Bot pushed a commit that referenced this pull request Oct 27, 2026
##  The problem ? , refer #16208

When you run `runsc checkpoint`, gVisor pauses the container to save its state.

On shared mounts, gVisor was calling `stat` on **every single cached file** one by one. Each `stat` call sends a message to the host and waits for an answer.

This metadata was only collected to check file sizes and edit times on restore. But `runsc` **never turns on this check by default**.

If a container has thousands of files (like `node_modules` or Python packages), the container was frozen for seconds just doing useless `stat` calls.

---

## My suggestion

We skip these `stat` calls during save by default.

We add an option called `ValidateMetadata` (set to `false` by default). Now, gVisor only calls `stat` if the user explicitly asks for it with `--validate-metadata`.

---

## Code change

In `pkg/sentry/fsimpl/gofer/save_restore.go`:

```diff
- if !d.fs.cachedMetadataAuthoritative() {
+ if opts.ValidateMetadata && !d.fs.cachedMetadataAuthoritative() {
      if err := d.inode.updateMetadata(ctx); err != nil {
          return err
      }
  }
```

---

## Stats

| **Cached Files** | **Host `stat` Calls (Before)** | **Host `stat` Calls (Now)** | **Pause Downtime (Before)** | **Pause Downtime (Now)** |
| :--------------- | :----------------------------- | :-------------------------- | :-------------------------- | :----------------------- |
| **500 files**    | 500 calls                      | 0                           | ~50 ms – 150 ms             | < 1 ms                   |
| **1,000 files**  | 1,000 calls                    | 0                           | ~100 ms – 300 ms            | < 1 ms                   |
| **5,000 files**  | 5,000 calls                    | 0                           | ~500 ms – 1,500 ms          | < 1 ms                   |
| **10,000 files** | 10,000 calls                   | 0                           | 1.0 s – 3.0 s               | ~2 ms                    |

Added unit tests in ``pkg/sentry/vfs/save_restore_test.go`` to test that options pass correctly.
Added test and benchmark in ``pkg/sentry/fsimpl/gofer/gofer_test.go``

fixes #16208

FUTURE_COPYBARA_INTEGRATE_REVIEW=#16346 from DARSHANR007:issue-16208/gofer-preparesave-stat fced933
PiperOrigin-RevId: 1007708632
copybara-service Bot pushed a commit that referenced this pull request Oct 27, 2026
##  The problem ? , refer #16208

When you run `runsc checkpoint`, gVisor pauses the container to save its state.

On shared mounts, gVisor was calling `stat` on **every single cached file** one by one. Each `stat` call sends a message to the host and waits for an answer.

This metadata was only collected to check file sizes and edit times on restore. But `runsc` **never turns on this check by default**.

If a container has thousands of files (like `node_modules` or Python packages), the container was frozen for seconds just doing useless `stat` calls.

---

## My suggestion

We skip these `stat` calls during save by default.

We add an option called `ValidateMetadata` (set to `false` by default). Now, gVisor only calls `stat` if the user explicitly asks for it with `--validate-metadata`.

---

## Code change

In `pkg/sentry/fsimpl/gofer/save_restore.go`:

```diff
- if !d.fs.cachedMetadataAuthoritative() {
+ if opts.ValidateMetadata && !d.fs.cachedMetadataAuthoritative() {
      if err := d.inode.updateMetadata(ctx); err != nil {
          return err
      }
  }
```

---

## Stats

| **Cached Files** | **Host `stat` Calls (Before)** | **Host `stat` Calls (Now)** | **Pause Downtime (Before)** | **Pause Downtime (Now)** |
| :--------------- | :----------------------------- | :-------------------------- | :-------------------------- | :----------------------- |
| **500 files**    | 500 calls                      | 0                           | ~50 ms – 150 ms             | < 1 ms                   |
| **1,000 files**  | 1,000 calls                    | 0                           | ~100 ms – 300 ms            | < 1 ms                   |
| **5,000 files**  | 5,000 calls                    | 0                           | ~500 ms – 1,500 ms          | < 1 ms                   |
| **10,000 files** | 10,000 calls                   | 0                           | 1.0 s – 3.0 s               | ~2 ms                    |

Added unit tests in ``pkg/sentry/vfs/save_restore_test.go`` to test that options pass correctly.
Added test and benchmark in ``pkg/sentry/fsimpl/gofer/gofer_test.go``

fixes #16208

FUTURE_COPYBARA_INTEGRATE_REVIEW=#16346 from DARSHANR007:issue-16208/gofer-preparesave-stat fced933
PiperOrigin-RevId: 1007708632
@DARSHANR007

Copy link
Copy Markdown
Contributor Author

I benchmark the PR to significance, the performance gain is real, even though it is smaller than than PR claims

  • lisafs: checkpoint is 12-13% faster, about 12 µs saved for each open file (one gofer round trip).
  • directfs (the default): checkpoint is 1-2% faster, about 1 µs saved for each open file (one host fstat).

thanks @DARSHANR007

goos: linux
goarch: amd64

                                                      │   base.txt   │               pr.txt                │
                                                      │    sec/op    │   sec/op     vs base                │
CheckpointLeaveRunning/openfiles=1000/directfs=true      94.99m ± 1%   93.46m ± 1%   -1.61% (p=0.002 n=32)
CheckpointLeaveRunning/openfiles=1000/directfs=false    105.80m ± 2%   93.49m ± 1%  -11.64% (p=0.000 n=32)
CheckpointLeaveRunning/openfiles=10000/directfs=true     761.2m ± 4%   747.2m ± 3%        ~ (p=0.100 n=32)
CheckpointLeaveRunning/openfiles=10000/directfs=false    881.3m ± 1%   767.0m ± 1%  -12.97% (p=0.000 n=32)
geomean                                                  286.5m        266.0m        -7.17%

n=64, directfs with 10000 files (not significant at n=32)

goos: linux
goarch: amd64
pkg: pr16346/checkpoint
                                                     │ n64/base.txt │             n64/pr.txt             │
                                                     │    sec/op    │   sec/op     vs base               │
CheckpointLeaveRunning/openfiles=10000/directfs=true    762.0m ± 1%   754.1m ± 1%  -1.04% (p=0.000 n=64)

n=20

                                                      │   base.txt   │               pr.txt                │
                                                      │    sec/op    │   sec/op     vs base                │
CheckpointLeaveRunning/openfiles=1000/directfs=true      99.38m ± 1%   98.05m ± 1%        ~ (p=0.068 n=20)
CheckpointLeaveRunning/openfiles=1000/directfs=false    111.37m ± 2%   99.25m ± 1%  -10.88% (p=0.000 n=20)
CheckpointLeaveRunning/openfiles=10000/directfs=true     768.9m ± 2%   753.6m ± 1%   -1.99% (p=0.012 n=20)
CheckpointLeaveRunning/openfiles=10000/directfs=false    837.9m ± 1%   723.8m ± 1%  -13.61% (p=0.000 n=20)
geomean                                                  290.6m        269.9m        -7.11%

Thanks a lot @milantracy benchmarks. Really glad to see the numbers back up the change across the runs

copybara-service Bot pushed a commit that referenced this pull request Oct 27, 2026
##  The problem ? , refer #16208

When you run `runsc checkpoint`, gVisor pauses the container to save its state.

On shared mounts, gVisor was calling `stat` on **every single cached file** one by one. Each `stat` call sends a message to the host and waits for an answer.

This metadata was only collected to check file sizes and edit times on restore. But `runsc` **never turns on this check by default**.

If a container has thousands of files (like `node_modules` or Python packages), the container was frozen for seconds just doing useless `stat` calls.

---

## My suggestion

We skip these `stat` calls during save by default.

We add an option called `ValidateMetadata` (set to `false` by default). Now, gVisor only calls `stat` if the user explicitly asks for it with `--validate-metadata`.

---

## Code change

In `pkg/sentry/fsimpl/gofer/save_restore.go`:

```diff
- if !d.fs.cachedMetadataAuthoritative() {
+ if opts.ValidateMetadata && !d.fs.cachedMetadataAuthoritative() {
      if err := d.inode.updateMetadata(ctx); err != nil {
          return err
      }
  }
```

---

## Stats

| **Cached Files** | **Host `stat` Calls (Before)** | **Host `stat` Calls (Now)** | **Pause Downtime (Before)** | **Pause Downtime (Now)** |
| :--------------- | :----------------------------- | :-------------------------- | :-------------------------- | :----------------------- |
| **500 files**    | 500 calls                      | 0                           | ~50 ms – 150 ms             | < 1 ms                   |
| **1,000 files**  | 1,000 calls                    | 0                           | ~100 ms – 300 ms            | < 1 ms                   |
| **5,000 files**  | 5,000 calls                    | 0                           | ~500 ms – 1,500 ms          | < 1 ms                   |
| **10,000 files** | 10,000 calls                   | 0                           | 1.0 s – 3.0 s               | ~2 ms                    |

Added unit tests in ``pkg/sentry/vfs/save_restore_test.go`` to test that options pass correctly.
Added test and benchmark in ``pkg/sentry/fsimpl/gofer/gofer_test.go``

fixes #16208

FUTURE_COPYBARA_INTEGRATE_REVIEW=#16346 from DARSHANR007:issue-16208/gofer-preparesave-stat fced933
PiperOrigin-RevId: 1007708632
copybara-service Bot pushed a commit that referenced this pull request Oct 27, 2026
##  The problem ? , refer #16208

When you run `runsc checkpoint`, gVisor pauses the container to save its state.

On shared mounts, gVisor was calling `stat` on **every single cached file** one by one. Each `stat` call sends a message to the host and waits for an answer.

This metadata was only collected to check file sizes and edit times on restore. But `runsc` **never turns on this check by default**.

If a container has thousands of files (like `node_modules` or Python packages), the container was frozen for seconds just doing useless `stat` calls.

---

## My suggestion

We skip these `stat` calls during save by default.

We add an option called `ValidateMetadata` (set to `false` by default). Now, gVisor only calls `stat` if the user explicitly asks for it with `--validate-metadata`.

---

## Code change

In `pkg/sentry/fsimpl/gofer/save_restore.go`:

```diff
- if !d.fs.cachedMetadataAuthoritative() {
+ if opts.ValidateMetadata && !d.fs.cachedMetadataAuthoritative() {
      if err := d.inode.updateMetadata(ctx); err != nil {
          return err
      }
  }
```

---

## Stats

| **Cached Files** | **Host `stat` Calls (Before)** | **Host `stat` Calls (Now)** | **Pause Downtime (Before)** | **Pause Downtime (Now)** |
| :--------------- | :----------------------------- | :-------------------------- | :-------------------------- | :----------------------- |
| **500 files**    | 500 calls                      | 0                           | ~50 ms – 150 ms             | < 1 ms                   |
| **1,000 files**  | 1,000 calls                    | 0                           | ~100 ms – 300 ms            | < 1 ms                   |
| **5,000 files**  | 5,000 calls                    | 0                           | ~500 ms – 1,500 ms          | < 1 ms                   |
| **10,000 files** | 10,000 calls                   | 0                           | 1.0 s – 3.0 s               | ~2 ms                    |

Added unit tests in ``pkg/sentry/vfs/save_restore_test.go`` to test that options pass correctly.
Added test and benchmark in ``pkg/sentry/fsimpl/gofer/gofer_test.go``

fixes #16208

FUTURE_COPYBARA_INTEGRATE_REVIEW=#16346 from DARSHANR007:issue-16208/gofer-preparesave-stat fced933
PiperOrigin-RevId: 1007745122
copybara-service Bot pushed a commit that referenced this pull request Oct 27, 2026
##  The problem ? , refer #16208

When you run `runsc checkpoint`, gVisor pauses the container to save its state.

On shared mounts, gVisor was calling `stat` on **every single cached file** one by one. Each `stat` call sends a message to the host and waits for an answer.

This metadata was only collected to check file sizes and edit times on restore. But `runsc` **never turns on this check by default**.

If a container has thousands of files (like `node_modules` or Python packages), the container was frozen for seconds just doing useless `stat` calls.

---

## My suggestion

We skip these `stat` calls during save by default.

We add an option called `ValidateMetadata` (set to `false` by default). Now, gVisor only calls `stat` if the user explicitly asks for it with `--validate-metadata`.

---

## Code change

In `pkg/sentry/fsimpl/gofer/save_restore.go`:

```diff
- if !d.fs.cachedMetadataAuthoritative() {
+ if opts.ValidateMetadata && !d.fs.cachedMetadataAuthoritative() {
      if err := d.inode.updateMetadata(ctx); err != nil {
          return err
      }
  }
```

---

## Stats

| **Cached Files** | **Host `stat` Calls (Before)** | **Host `stat` Calls (Now)** | **Pause Downtime (Before)** | **Pause Downtime (Now)** |
| :--------------- | :----------------------------- | :-------------------------- | :-------------------------- | :----------------------- |
| **500 files**    | 500 calls                      | 0                           | ~50 ms – 150 ms             | < 1 ms                   |
| **1,000 files**  | 1,000 calls                    | 0                           | ~100 ms – 300 ms            | < 1 ms                   |
| **5,000 files**  | 5,000 calls                    | 0                           | ~500 ms – 1,500 ms          | < 1 ms                   |
| **10,000 files** | 10,000 calls                   | 0                           | 1.0 s – 3.0 s               | ~2 ms                    |

Added unit tests in ``pkg/sentry/vfs/save_restore_test.go`` to test that options pass correctly.
Added test and benchmark in ``pkg/sentry/fsimpl/gofer/gofer_test.go``

fixes #16208

FUTURE_COPYBARA_INTEGRATE_REVIEW=#16346 from DARSHANR007:issue-16208/gofer-preparesave-stat fced933
PiperOrigin-RevId: 1007708632
@copybara-service
copybara-service Bot merged commit 8229bcb into gvisor:master Oct 27, 2026
13 of 14 checks passed
copybara-service Bot pushed a commit that referenced this pull request Nov 10, 2026
On shared mounts backed by a path-based lisafs server that does not pin
open host file descriptors (or by a host filesystem such as FUSE/NFS
where an open O_PATH FD does not prevent inode-number reuse), unlinking
a file lets the backing filesystem immediately recycle its (dev, ino)
pair for a newly created file of a different type while the sentry still
holds the old gofer.inode in filesystem.inodeByKey (via an open FD, the
dentry cache, or deferred invalidation cleanup during OpenAt). Since
commit 8229bcb ("Merge pull request #16346 from
DARSHANR007:issue-16208/gofer-preparesave-stat") began refreshing cached
inode metadata on filesystem.inodeByKey hits in newLisafsDentry and
newDirectfsDentry, matching solely on (dev, ino) adopts the stale
gofer.inode and panics in updateMetadataFromStatxLocked on the file-type
mismatch:

  --- FAIL: TestOpenAtRecycledInoTypeChange (0.02s)
  panic: lisafsInode file type changed from 0140000 to 0100000

Require the cached inode's file type to match the newly walked file type
in getOrCreateInode (for both lisafs and directfs, tested via lisafs),
matching the existing check in doRevalidationLisafs. When the file type
differs, allocate a fresh gofer.inode and replace the
filesystem.inodeByKey entry while leaving the old gofer.inode isolated
for any remaining references, and guard filesystem.inodeByKey deletion
on inode teardown with pointer identity so destroying the superseded
inode does not evict the replacement. Same-type (dev, ino) reuse remains
indistinguishable from a hard link without inode generation numbers.

PiperOrigin-RevId: 1017652055
copybara-service Bot pushed a commit that referenced this pull request Nov 10, 2026
On shared mounts backed by a path-based lisafs server that does not pin
open host file descriptors (or by a host filesystem such as FUSE/NFS
where an open O_PATH FD does not prevent inode-number reuse), unlinking
a file lets the backing filesystem immediately recycle its (dev, ino)
pair for a newly created file of a different type while the sentry still
holds the old gofer.inode in filesystem.inodeByKey (via an open FD, the
dentry cache, or deferred invalidation cleanup during OpenAt). Since
commit 8229bcb ("Merge pull request #16346 from
DARSHANR007:issue-16208/gofer-preparesave-stat") began refreshing cached
inode metadata on filesystem.inodeByKey hits in newLisafsDentry and
newDirectfsDentry, matching solely on (dev, ino) adopts the stale
gofer.inode and panics in updateMetadataFromStatxLocked on the file-type
mismatch:

  --- FAIL: TestOpenAtRecycledInoTypeChange (0.02s)
  panic: lisafsInode file type changed from 0140000 to 0100000

Require the cached inode's file type to match the newly walked file type
in getOrCreateInode (for both lisafs and directfs, tested via lisafs),
matching the existing check in doRevalidationLisafs. When the file type
differs, allocate a fresh gofer.inode and replace the
filesystem.inodeByKey entry while leaving the old gofer.inode isolated
for any remaining references, and guard filesystem.inodeByKey deletion
on inode teardown with pointer identity so destroying the superseded
inode does not evict the replacement. Same-type (dev, ino) reuse remains
indistinguishable from a hard link without inode generation numbers.

PiperOrigin-RevId: 1017652055
copybara-service Bot pushed a commit that referenced this pull request Nov 10, 2026
On shared mounts backed by a path-based lisafs server that does not pin
open host file descriptors (or by a host filesystem such as FUSE/NFS
where an open O_PATH FD does not prevent inode-number reuse), unlinking
a file lets the backing filesystem immediately recycle its (dev, ino)
pair for a newly created file of a different type while the sentry still
holds the old gofer.inode in filesystem.inodeByKey (via an open FD, the
dentry cache, or deferred invalidation cleanup during OpenAt). Since
commit 8229bcb ("Merge pull request #16346 from
DARSHANR007:issue-16208/gofer-preparesave-stat") began refreshing cached
inode metadata on filesystem.inodeByKey hits in newLisafsDentry and
newDirectfsDentry, matching solely on (dev, ino) adopts the stale
gofer.inode and panics in updateMetadataFromStatxLocked on the file-type
mismatch:

  --- FAIL: TestOpenAtRecycledInoTypeChange (0.02s)
  panic: lisafsInode file type changed from 0140000 to 0100000

Require the cached inode's file type to match the newly walked file type
in getOrCreateInode (for both lisafs and directfs, tested via lisafs),
matching the existing check in doRevalidationLisafs. When the file type
differs, allocate a fresh gofer.inode and replace the
filesystem.inodeByKey entry while leaving the old gofer.inode isolated
for any remaining references, and guard filesystem.inodeByKey deletion
on inode teardown with pointer identity so destroying the superseded
inode does not evict the replacement. Same-type (dev, ino) reuse remains
indistinguishable from a hard link without inode generation numbers.

PiperOrigin-RevId: 1017652055
copybara-service Bot pushed a commit that referenced this pull request Nov 12, 2026
On shared mounts backed by a path-based lisafs server that does not pin
open host file descriptors (or by a host filesystem such as FUSE/NFS
where an open O_PATH FD does not prevent inode-number reuse), unlinking
a file lets the backing filesystem immediately recycle its (dev, ino)
pair for a newly created file of a different type while the sentry still
holds the old gofer.inode in filesystem.inodeByKey (via an open FD, the
dentry cache, or deferred invalidation cleanup during OpenAt). Since
commit 8229bcb ("Merge pull request #16346 from
DARSHANR007:issue-16208/gofer-preparesave-stat") began refreshing cached
inode metadata on filesystem.inodeByKey hits in newLisafsDentry and
newDirectfsDentry, matching solely on (dev, ino) adopts the stale
gofer.inode and panics in updateMetadataFromStatxLocked on the file-type
mismatch:

  --- FAIL: TestOpenAtRecycledInoTypeChange (0.02s)
  panic: lisafsInode file type changed from 0140000 to 0100000

Require the cached inode's file type to match the newly walked file type
in getOrCreateInode (for both lisafs and directfs, tested via lisafs),
matching the existing check in doRevalidationLisafs. When the file type
differs, allocate a fresh gofer.inode and replace the
filesystem.inodeByKey entry while leaving the old gofer.inode isolated
for any remaining references, and guard filesystem.inodeByKey deletion
on inode teardown with pointer identity so destroying the superseded
inode does not evict the replacement.

PiperOrigin-RevId: 1017652055
copybara-service Bot pushed a commit that referenced this pull request Nov 13, 2026
On shared mounts backed by a path-based lisafs server that does not pin
open host file descriptors (or by a host filesystem such as FUSE/NFS
where an open O_PATH FD does not prevent inode-number reuse), unlinking
a file lets the backing filesystem immediately recycle its (dev, ino)
pair for a newly created file of a different type while the sentry still
holds the old gofer.inode in filesystem.inodeByKey (via an open FD, the
dentry cache, or deferred invalidation cleanup during OpenAt). Since
commit 8229bcb ("Merge pull request #16346 from
DARSHANR007:issue-16208/gofer-preparesave-stat") began refreshing cached
inode metadata on filesystem.inodeByKey hits in newLisafsDentry and
newDirectfsDentry, matching solely on (dev, ino) adopts the stale
gofer.inode and panics in updateMetadataFromStatxLocked on the file-type
mismatch:

  --- FAIL: TestOpenAtRecycledInoTypeChange (0.02s)
  panic: lisafsInode file type changed from 0140000 to 0100000

Require the cached inode's file type to match the newly walked file type
in getOrCreateInode (for both lisafs and directfs, tested via lisafs),
matching the existing check in doRevalidationLisafs. When the file type
differs, allocate a fresh gofer.inode and replace the
filesystem.inodeByKey entry while leaving the old gofer.inode isolated
for any remaining references, and guard filesystem.inodeByKey deletion
on inode teardown with pointer identity so destroying the superseded
inode does not evict the replacement.

PiperOrigin-RevId: 1017652055
copybara-service Bot pushed a commit that referenced this pull request Nov 13, 2026
On shared mounts backed by a path-based lisafs server that does not pin
open host file descriptors (or by a host filesystem such as FUSE/NFS
where an open O_PATH FD does not prevent inode-number reuse), unlinking
a file lets the backing filesystem immediately recycle its (dev, ino)
pair for a newly created file of a different type while the sentry still
holds the old gofer.inode in filesystem.inodeByKey (via an open FD, the
dentry cache, or deferred invalidation cleanup during OpenAt). Since
commit 8229bcb ("Merge pull request #16346 from
DARSHANR007:issue-16208/gofer-preparesave-stat") began refreshing cached
inode metadata on filesystem.inodeByKey hits in newLisafsDentry and
newDirectfsDentry, matching solely on (dev, ino) adopts the stale
gofer.inode and panics in updateMetadataFromStatxLocked on the file-type
mismatch:

  --- FAIL: TestOpenAtRecycledInoTypeChange (0.02s)
  panic: lisafsInode file type changed from 0140000 to 0100000

Require the cached inode's file type to match the newly walked file type
in getOrCreateInode (for both lisafs and directfs, tested via lisafs),
matching the existing check in doRevalidationLisafs. When the file type
differs, allocate a fresh gofer.inode and replace the
filesystem.inodeByKey entry while leaving the old gofer.inode isolated
for any remaining references, and guard filesystem.inodeByKey deletion
on inode teardown with pointer identity so destroying the superseded
inode does not evict the replacement.

PiperOrigin-RevId: 1017652055
copybara-service Bot pushed a commit that referenced this pull request Nov 13, 2026
On shared mounts backed by a path-based lisafs server that does not pin
open host file descriptors (or by a host filesystem such as FUSE/NFS
where an open O_PATH FD does not prevent inode-number reuse), unlinking
a file lets the backing filesystem immediately recycle its (dev, ino)
pair for a newly created file of a different type while the sentry still
holds the old gofer.inode in filesystem.inodeByKey (via an open FD, the
dentry cache, or deferred invalidation cleanup during OpenAt). Since
commit 8229bcb ("Merge pull request #16346 from
DARSHANR007:issue-16208/gofer-preparesave-stat") began refreshing cached
inode metadata on filesystem.inodeByKey hits in newLisafsDentry and
newDirectfsDentry, matching solely on (dev, ino) adopts the stale
gofer.inode and panics in updateMetadataFromStatxLocked on the file-type
mismatch:

  --- FAIL: TestOpenAtRecycledInoTypeChange (0.02s)
  panic: lisafsInode file type changed from 0140000 to 0100000

Require the cached inode's file type to match the newly walked file type
in getOrCreateInode (for both lisafs and directfs, tested via lisafs),
matching the existing check in doRevalidationLisafs. When the file type
differs, allocate a fresh gofer.inode and replace the
filesystem.inodeByKey entry while leaving the old gofer.inode isolated
for any remaining references, and guard filesystem.inodeByKey deletion
on inode teardown with pointer identity so destroying the superseded
inode does not evict the replacement.

PiperOrigin-RevId: 1020610841
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to pull Causes the PR to be imported into Google. Will be removed soon.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimization: Don't stat every cached gofer file during checkpoint when restore does not validate metadata

4 participants