Skip to content

Commit 07d3676

Browse files
authored
Merge pull request #2355 from stgraber/storage
incusd/storage: Fix EnsureMountPath to avoid resetting permissions
2 parents 5f9895e + 9057c57 commit 07d3676

11 files changed

+84
-78
lines changed

internal/server/storage/backend.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5925,7 +5925,7 @@ func (b *backend) ImportCustomVolume(projectName string, poolVol *backupConfig.C
59255925
vol := b.GetVolume(drivers.VolumeTypeCustom, drivers.ContentType(poolVol.Volume.ContentType), volStorageName, volumeConfig)
59265926

59275927
// Create the mount path if needed.
5928-
err = vol.EnsureMountPath()
5928+
err = vol.EnsureMountPath(false)
59295929
if err != nil {
59305930
return nil, err
59315931
}
@@ -5939,7 +5939,7 @@ func (b *backend) ImportCustomVolume(projectName string, poolVol *backupConfig.C
59395939
return nil, err
59405940
}
59415941

5942-
err = snapVol.EnsureMountPath()
5942+
err = snapVol.EnsureMountPath(false)
59435943
if err != nil {
59445944
return nil, err
59455945
}
@@ -7021,7 +7021,7 @@ func (b *backend) ImportInstance(inst instance.Instance, poolVol *backupConfig.C
70217021
return nil, err
70227022
}
70237023

7024-
err = vol.EnsureMountPath()
7024+
err = vol.EnsureMountPath(false)
70257025
if err != nil {
70267026
return nil, err
70277027
}
@@ -7074,7 +7074,7 @@ func (b *backend) ImportInstance(inst instance.Instance, poolVol *backupConfig.C
70747074
return nil, err
70757075
}
70767076

7077-
err = snapVol.EnsureMountPath()
7077+
err = snapVol.EnsureMountPath(false)
70787078
if err != nil {
70797079
return nil, err
70807080
}

internal/server/storage/drivers/driver_btrfs_volumes.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (d *btrfs) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Op
135135
}
136136

137137
// Tweak any permissions that need tweaking after filling.
138-
err = vol.EnsureMountPath()
138+
err = vol.EnsureMountPath(true)
139139
if err != nil {
140140
return err
141141
}
@@ -452,7 +452,7 @@ func (d *btrfs) CreateVolumeFromCopy(vol Volume, srcVol Volume, copySnapshots bo
452452
}
453453

454454
// Fixup permissions after snapshot created.
455-
err = vol.EnsureMountPath()
455+
err = vol.EnsureMountPath(false)
456456
if err != nil {
457457
return err
458458
}
@@ -1198,7 +1198,7 @@ func (d *btrfs) MountVolume(vol Volume, op *operations.Operation) error {
11981198
// Don't attempt to modify the permission of an existing custom volume root.
11991199
// A user inside the instance may have modified this and we don't want to reset it on restart.
12001200
if !util.PathExists(vol.MountPath()) || vol.volType != VolumeTypeCustom {
1201-
err := vol.EnsureMountPath()
1201+
err := vol.EnsureMountPath(false)
12021202
if err != nil {
12031203
return err
12041204
}
@@ -1865,7 +1865,7 @@ func (d *btrfs) MountVolumeSnapshot(snapVol Volume, op *operations.Operation) er
18651865
// Don't attempt to modify the permission of an existing custom volume root.
18661866
// A user inside the instance may have modified this and we don't want to reset it on restart.
18671867
if !util.PathExists(snapPath) || snapVol.volType != VolumeTypeCustom {
1868-
err := snapVol.EnsureMountPath()
1868+
err := snapVol.EnsureMountPath(false)
18691869
if err != nil {
18701870
return err
18711871
}

internal/server/storage/drivers/driver_ceph_volumes.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (d *ceph) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Ope
5555

5656
if vol.contentType == ContentTypeFS {
5757
// Create mountpoint.
58-
err := vol.EnsureMountPath()
58+
err := vol.EnsureMountPath(true)
5959
if err != nil {
6060
return err
6161
}
@@ -225,7 +225,7 @@ func (d *ceph) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Ope
225225
if vol.contentType == ContentTypeFS {
226226
// Run EnsureMountPath again after mounting and filling to ensure the mount directory has
227227
// the correct permissions set.
228-
err = vol.EnsureMountPath()
228+
err = vol.EnsureMountPath(true)
229229
if err != nil {
230230
return err
231231
}
@@ -350,7 +350,7 @@ func (d *ceph) CreateVolumeFromCopy(vol Volume, srcVol Volume, copySnapshots boo
350350

351351
// Mount the volume and ensure the permissions are set correctly inside the mounted volume.
352352
err = v.MountTask(func(_ string, _ *operations.Operation) error {
353-
return v.EnsureMountPath()
353+
return v.EnsureMountPath(false)
354354
}, op)
355355
if err != nil {
356356
return err
@@ -500,7 +500,7 @@ func (d *ceph) CreateVolumeFromCopy(vol Volume, srcVol Volume, copySnapshots boo
500500
return err
501501
}
502502

503-
err = snapVol.EnsureMountPath()
503+
err = snapVol.EnsureMountPath(false)
504504
if err != nil {
505505
return err
506506
}
@@ -526,7 +526,7 @@ func (d *ceph) CreateVolumeFromCopy(vol Volume, srcVol Volume, copySnapshots boo
526526
// CreateVolumeFromMigration creates a volume being sent via a migration.
527527
func (d *ceph) CreateVolumeFromMigration(vol Volume, conn io.ReadWriteCloser, volTargetArgs localMigration.VolumeTargetArgs, preFiller *VolumeFiller, op *operations.Operation) error {
528528
if volTargetArgs.ClusterMoveSourceName != "" && volTargetArgs.StoragePool == "" {
529-
err := vol.EnsureMountPath()
529+
err := vol.EnsureMountPath(false)
530530
if err != nil {
531531
return err
532532
}
@@ -571,7 +571,7 @@ func (d *ceph) CreateVolumeFromMigration(vol Volume, conn io.ReadWriteCloser, vo
571571
}
572572
}
573573

574-
err = vol.EnsureMountPath()
574+
err = vol.EnsureMountPath(false)
575575
if err != nil {
576576
return err
577577
}
@@ -599,7 +599,7 @@ func (d *ceph) CreateVolumeFromMigration(vol Volume, conn io.ReadWriteCloser, vo
599599
return err
600600
}
601601

602-
err = snapVol.EnsureMountPath()
602+
err = snapVol.EnsureMountPath(false)
603603
if err != nil {
604604
return err
605605
}
@@ -1206,7 +1206,7 @@ func (d *ceph) MountVolume(vol Volume, op *operations.Operation) error {
12061206
if vol.contentType == ContentTypeFS {
12071207
mountPath := vol.MountPath()
12081208
if !linux.IsMountPoint(mountPath) {
1209-
err := vol.EnsureMountPath()
1209+
err := vol.EnsureMountPath(false)
12101210
if err != nil {
12111211
return err
12121212
}
@@ -1501,7 +1501,7 @@ func (d *ceph) CreateVolumeSnapshot(snapVol Volume, op *operations.Operation) er
15011501
return err
15021502
}
15031503

1504-
err = snapVol.EnsureMountPath()
1504+
err = snapVol.EnsureMountPath(false)
15051505
if err != nil {
15061506
return err
15071507
}
@@ -1601,7 +1601,7 @@ func (d *ceph) MountVolumeSnapshot(snapVol Volume, op *operations.Operation) err
16011601
mountPath := snapVol.MountPath()
16021602

16031603
if snapVol.contentType == ContentTypeFS && !linux.IsMountPoint(mountPath) {
1604-
err := snapVol.EnsureMountPath()
1604+
err := snapVol.EnsureMountPath(false)
16051605
if err != nil {
16061606
return err
16071607
}

internal/server/storage/drivers/driver_cephfs_volumes.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (d *cephfs) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.O
3737

3838
// Create the main volume path.
3939
volPath := vol.MountPath()
40-
err := vol.EnsureMountPath()
40+
err := vol.EnsureMountPath(true)
4141
if err != nil {
4242
return err
4343
}
@@ -77,7 +77,7 @@ func (d *cephfs) CreateVolumeFromCopy(vol Volume, srcVol Volume, copySnapshots b
7777

7878
// Create the main volume path.
7979
volPath := vol.MountPath()
80-
err := vol.EnsureMountPath()
80+
err := vol.EnsureMountPath(false)
8181
if err != nil {
8282
return err
8383
}
@@ -148,7 +148,7 @@ func (d *cephfs) CreateVolumeFromCopy(vol Volume, srcVol Volume, copySnapshots b
148148

149149
// Run EnsureMountPath after mounting and copying to ensure the mounted directory has the
150150
// correct permissions set.
151-
return vol.EnsureMountPath()
151+
return vol.EnsureMountPath(false)
152152
}, op)
153153
if err != nil {
154154
return err
@@ -166,7 +166,7 @@ func (d *cephfs) CreateVolumeFromMigration(vol Volume, conn io.ReadWriteCloser,
166166

167167
// Create the main volume path.
168168
volPath := vol.MountPath()
169-
err := vol.EnsureMountPath()
169+
err := vol.EnsureMountPath(false)
170170
if err != nil {
171171
return err
172172
}

internal/server/storage/drivers/driver_dir_volumes.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (d *dir) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Oper
3535
}
3636

3737
// Create the volume itself.
38-
err := vol.EnsureMountPath()
38+
err := vol.EnsureMountPath(true)
3939
if err != nil {
4040
return err
4141
}
@@ -379,7 +379,7 @@ func (d *dir) MountVolume(vol Volume, op *operations.Operation) error {
379379
// Don't attempt to modify the permission of an existing custom volume root.
380380
// A user inside the instance may have modified this and we don't want to reset it on restart.
381381
if !util.PathExists(vol.MountPath()) || vol.volType != VolumeTypeCustom {
382-
err := vol.EnsureMountPath()
382+
err := vol.EnsureMountPath(false)
383383
if err != nil {
384384
return err
385385
}
@@ -429,7 +429,7 @@ func (d *dir) CreateVolumeSnapshot(snapVol Volume, op *operations.Operation) err
429429
parentName, _, _ := api.GetParentAndSnapshotName(snapVol.name)
430430

431431
// Create snapshot directory.
432-
err := snapVol.EnsureMountPath()
432+
err := snapVol.EnsureMountPath(false)
433433
if err != nil {
434434
return err
435435
}
@@ -523,7 +523,7 @@ func (d *dir) MountVolumeSnapshot(snapVol Volume, op *operations.Operation) erro
523523
// Don't attempt to modify the permission of an existing custom volume root.
524524
// A user inside the instance may have modified this and we don't want to reset it on restart.
525525
if !util.PathExists(snapPath) || snapVol.volType != VolumeTypeCustom {
526-
err := snapVol.EnsureMountPath()
526+
err := snapVol.EnsureMountPath(false)
527527
if err != nil {
528528
return err
529529
}

internal/server/storage/drivers/driver_linstor_volumes.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (d *linstor) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.
110110

111111
if vol.contentType == ContentTypeFS {
112112
// Create mountpoint.
113-
err := vol.EnsureMountPath()
113+
err := vol.EnsureMountPath(true)
114114
if err != nil {
115115
return err
116116
}
@@ -241,7 +241,7 @@ func (d *linstor) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.
241241
if vol.contentType == ContentTypeFS {
242242
// Run EnsureMountPath again after mounting and filling to ensure the mount directory has
243243
// the correct permissions set.
244-
err = vol.EnsureMountPath()
244+
err = vol.EnsureMountPath(true)
245245
if err != nil {
246246
return err
247247
}
@@ -289,7 +289,7 @@ func (d *linstor) CreateVolumeFromCopy(vol Volume, srcVol Volume, copySnapshots
289289
// ISO volumes like filesystem volumes when performing the copy. This implies
290290
// that the mount path for the volume must exist before the copying starts.
291291
if srcVol.contentType == ContentTypeISO {
292-
err := srcVol.EnsureMountPath()
292+
err := srcVol.EnsureMountPath(false)
293293
if err != nil {
294294
return err
295295
}
@@ -333,7 +333,7 @@ func (d *linstor) CreateVolumeFromCopy(vol Volume, srcVol Volume, copySnapshots
333333
}
334334

335335
// Create mountpoint.
336-
err = vol.EnsureMountPath()
336+
err = vol.EnsureMountPath(false)
337337
if err != nil {
338338
return err
339339
}
@@ -549,7 +549,7 @@ func (d *linstor) MountVolume(vol Volume, op *operations.Operation) error {
549549
mountPath := vol.MountPath()
550550
l.Debug("Content type FS", logger.Ctx{"mountPath": mountPath})
551551
if !linux.IsMountPoint(mountPath) {
552-
err := vol.EnsureMountPath()
552+
err := vol.EnsureMountPath(false)
553553
if err != nil {
554554
return err
555555
}
@@ -697,7 +697,7 @@ func (d *linstor) CreateVolumeSnapshot(snapVol Volume, op *operations.Operation)
697697
return err
698698
}
699699

700-
err = snapVol.EnsureMountPath()
700+
err = snapVol.EnsureMountPath(false)
701701
if err != nil {
702702
return err
703703
}
@@ -884,7 +884,7 @@ func (d *linstor) MountVolumeSnapshot(snapVol Volume, op *operations.Operation)
884884
mountPath := snapVol.MountPath()
885885
l.Debug("Content type FS", logger.Ctx{"mountPath": mountPath})
886886
if !linux.IsMountPoint(mountPath) {
887-
err := snapVol.EnsureMountPath()
887+
err := snapVol.EnsureMountPath(false)
888888
if err != nil {
889889
return err
890890
}
@@ -1164,7 +1164,7 @@ func (d *linstor) CreateVolumeFromMigration(vol Volume, conn io.ReadWriteCloser,
11641164
return err
11651165
}
11661166

1167-
err = vol.EnsureMountPath()
1167+
err = vol.EnsureMountPath(false)
11681168
if err != nil {
11691169
return err
11701170
}
@@ -1175,7 +1175,7 @@ func (d *linstor) CreateVolumeFromMigration(vol Volume, conn io.ReadWriteCloser,
11751175
if vol.IsVMBlock() {
11761176
fsVol := vol.NewVMBlockFilesystemVolume()
11771177

1178-
err = fsVol.EnsureMountPath()
1178+
err = fsVol.EnsureMountPath(false)
11791179
if err != nil {
11801180
return err
11811181
}

internal/server/storage/drivers/driver_lvm_utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ func (d *lvm) copyThinpoolVolume(vol, srcVol Volume, srcSnapshots []Volume, refr
661661
}
662662

663663
newSnapVolPath := newSnapVol.MountPath()
664-
err = newSnapVol.EnsureMountPath()
664+
err = newSnapVol.EnsureMountPath(false)
665665
if err != nil {
666666
return err
667667
}
@@ -712,7 +712,7 @@ func (d *lvm) copyThinpoolVolume(vol, srcVol Volume, srcSnapshots []Volume, refr
712712
}
713713
} else {
714714
volPath := vol.MountPath()
715-
err := vol.EnsureMountPath()
715+
err := vol.EnsureMountPath(false)
716716
if err != nil {
717717
return err
718718
}
@@ -756,7 +756,7 @@ func (d *lvm) copyThinpoolVolume(vol, srcVol Volume, srcSnapshots []Volume, refr
756756

757757
// Mount the volume and ensure the permissions are set correctly inside the mounted volume.
758758
err = vol.MountTask(func(_ string, _ *operations.Operation) error {
759-
return vol.EnsureMountPath()
759+
return vol.EnsureMountPath(false)
760760
}, nil)
761761
if err != nil {
762762
return err

0 commit comments

Comments
 (0)