Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: engine unmap uses write lock #1447

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg/controller/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -1118,14 +1118,14 @@ func (c *Controller) ReadAt(b []byte, off int64) (int, error) {
func (c *Controller) UnmapAt(length uint32, off int64) (int, error) {
// TODO: Need to fail unmap requests
// if the volume is purging snapshots or creating backups.
c.RLock()
c.Lock()

if off < 0 || off+int64(length) > c.size {
// This is a legitimate error (which is handled by tgt/liblonghorn at a higher level). Since tgt/liblonghorn
// does not actually print the error, print it here.
err := fmt.Errorf("EOF: unmap of %v bytes at offset %v is beyond volume size %v", length, off, c.size)
logrus.WithError(err).Error("Failed to unmap")
c.RUnlock()
c.Unlock()
return 0, err
}
if c.hasWOReplica() {
Expand All @@ -1134,7 +1134,7 @@ func (c *Controller) UnmapAt(length uint32, off int64) (int, error) {
// will remain paused for the entire duration of the rebuild.
err := fmt.Errorf("cannot unmap %v bytes at offset %v while rebuilding is in progress", length, off)
logrus.WithError(err).Warn("Failed to unmap")
c.RUnlock()
c.Unlock()
return 0, nil
}
if c.isExpanding {
Expand All @@ -1143,13 +1143,13 @@ func (c *Controller) UnmapAt(length uint32, off int64) (int, error) {
// trimmed, so it can try again.
err := fmt.Errorf("cannot unmap %v bytes at offset %v while expansion in is progress", length, off)
logrus.WithError(err).Error("Failed to unmap")
c.RUnlock()
c.Unlock()
return 0, err
}

// startTime := time.Now()
n, err := c.backend.UnmapAt(length, off)
c.RUnlock()
c.Unlock()
if err != nil {
return n, c.handleError(err)
}
Expand Down