Skip to content

Commit 2b2b4aa

Browse files
shuo-wumergify[bot]
authored andcommitted
fix: engine unmap uses write lock
Otherwise, there will be a race between unmap and write operations. Longhorn 6406 Signed-off-by: Shuo Wu <[email protected]>
1 parent d69d913 commit 2b2b4aa

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

pkg/controller/control.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -1118,14 +1118,14 @@ func (c *Controller) ReadAt(b []byte, off int64) (int, error) {
11181118
func (c *Controller) UnmapAt(length uint32, off int64) (int, error) {
11191119
// TODO: Need to fail unmap requests
11201120
// if the volume is purging snapshots or creating backups.
1121-
c.RLock()
1121+
c.Lock()
11221122

11231123
if off < 0 || off+int64(length) > c.size {
11241124
// This is a legitimate error (which is handled by tgt/liblonghorn at a higher level). Since tgt/liblonghorn
11251125
// does not actually print the error, print it here.
11261126
err := fmt.Errorf("EOF: unmap of %v bytes at offset %v is beyond volume size %v", length, off, c.size)
11271127
logrus.WithError(err).Error("Failed to unmap")
1128-
c.RUnlock()
1128+
c.Unlock()
11291129
return 0, err
11301130
}
11311131
if c.hasWOReplica() {
@@ -1134,7 +1134,7 @@ func (c *Controller) UnmapAt(length uint32, off int64) (int, error) {
11341134
// will remain paused for the entire duration of the rebuild.
11351135
err := fmt.Errorf("cannot unmap %v bytes at offset %v while rebuilding is in progress", length, off)
11361136
logrus.WithError(err).Warn("Failed to unmap")
1137-
c.RUnlock()
1137+
c.Unlock()
11381138
return 0, nil
11391139
}
11401140
if c.isExpanding {
@@ -1143,13 +1143,13 @@ func (c *Controller) UnmapAt(length uint32, off int64) (int, error) {
11431143
// trimmed, so it can try again.
11441144
err := fmt.Errorf("cannot unmap %v bytes at offset %v while expansion in is progress", length, off)
11451145
logrus.WithError(err).Error("Failed to unmap")
1146-
c.RUnlock()
1146+
c.Unlock()
11471147
return 0, err
11481148
}
11491149

11501150
// startTime := time.Now()
11511151
n, err := c.backend.UnmapAt(length, off)
1152-
c.RUnlock()
1152+
c.Unlock()
11531153
if err != nil {
11541154
return n, c.handleError(err)
11551155
}

0 commit comments

Comments
 (0)