Fix deadlock in specialFileFD.pwrite

When file is regular and metadata cache is authoritative, metadata lock
is taken. The code deadlocks trying to acquire the metadata lock
again to update time stampts.

PiperOrigin-RevId: 354584594
This commit is contained in:
Fabricio Voznika
2021-01-29 12:18:42 -08:00
committed by gVisor bot
parent 25284ae3c9
commit 0fa534f116
+7 -2
View File
@@ -299,10 +299,15 @@ func (fd *specialFileFD) pwrite(ctx context.Context, src usermem.IOSequence, off
src = src.TakeFirst64(limit)
}
// Do a buffered write. See rationale in PRead.
if d.cachedMetadataAuthoritative() {
d.touchCMtime()
if fd.isRegularFile {
d.touchCMtimeLocked()
} else {
d.touchCMtime()
}
}
// Do a buffered write. See rationale in PRead.
buf := make([]byte, src.NumBytes())
copied, copyErr := src.CopyIn(ctx, buf)
if copied == 0 && copyErr != nil {