|
4 | 4 | "context" |
5 | 5 | "errors" |
6 | 6 | "fmt" |
| 7 | + "io/fs" |
7 | 8 | "net/http" |
8 | 9 | "os" |
9 | 10 | "path/filepath" |
@@ -83,6 +84,7 @@ var patches = []patch{ |
83 | 84 | {name: "storage_unset_invalid_block_settings", stage: patchPostDaemonStorage, run: patchStorageUnsetInvalidBlockSettings}, |
84 | 85 | {name: "storage_move_custom_iso_block_volumes_v2", stage: patchPostDaemonStorage, run: patchStorageRenameCustomISOBlockVolumesV2}, |
85 | 86 | {name: "storage_unset_invalid_block_settings_v2", stage: patchPostDaemonStorage, run: patchStorageUnsetInvalidBlockSettingsV2}, |
| 87 | + {name: "pool_fix_default_permissions", stage: patchPostDaemonStorage, run: patchDefaultStoragePermissions}, |
86 | 88 | } |
87 | 89 |
|
88 | 90 | type patch struct { |
@@ -1249,4 +1251,34 @@ DELETE FROM storage_volumes_config |
1249 | 1251 | return err |
1250 | 1252 | } |
1251 | 1253 |
|
| 1254 | +// patchDefaultStoragePermissions re-applies the default modes to all storage pools. |
| 1255 | +func patchDefaultStoragePermissions(_ string, d *Daemon) error { |
| 1256 | + s := d.State() |
| 1257 | + |
| 1258 | + pools, err := s.DB.Cluster.GetStoragePoolNames() |
| 1259 | + if err != nil { |
| 1260 | + // Skip the rest of the patch if no storage pools were found. |
| 1261 | + if api.StatusErrorCheck(err, http.StatusNotFound) { |
| 1262 | + return nil |
| 1263 | + } |
| 1264 | + |
| 1265 | + return fmt.Errorf("Failed getting storage pool names: %w", err) |
| 1266 | + } |
| 1267 | + |
| 1268 | + for _, pool := range pools { |
| 1269 | + for _, volEntry := range storageDrivers.BaseDirectories { |
| 1270 | + for _, volDir := range volEntry.Paths { |
| 1271 | + path := storageDrivers.GetPoolMountPath(pool) + "/" + volDir |
| 1272 | + |
| 1273 | + err := os.Chmod(path, volEntry.Mode) |
| 1274 | + if err != nil && !errors.Is(err, fs.ErrNotExist) { |
| 1275 | + return fmt.Errorf("Failed to set directory mode %q: %w", path, err) |
| 1276 | + } |
| 1277 | + } |
| 1278 | + } |
| 1279 | + } |
| 1280 | + |
| 1281 | + return nil |
| 1282 | +} |
| 1283 | + |
1252 | 1284 | // Patches end here |
0 commit comments