@@ -159,9 +159,10 @@ type Config struct {
159
159
// NewFSManager creates a new Manager instance for ZFS.
160
160
func NewFSManager (runner runners.Runner , config Config ) * Manager {
161
161
m := Manager {
162
- runner : runner ,
163
- config : config ,
164
- mu : & sync.Mutex {},
162
+ runner : runner ,
163
+ config : config ,
164
+ mu : & sync.Mutex {},
165
+ snapshots : make ([]resources.Snapshot , 0 ),
165
166
}
166
167
167
168
return & m
@@ -172,6 +173,11 @@ func (m *Manager) Pool() *resources.Pool {
172
173
return m .config .Pool
173
174
}
174
175
176
+ // UpdateConfig updates the manager's configuration.
177
+ func (m * Manager ) UpdateConfig (cfg Config ) {
178
+ m .config = cfg
179
+ }
180
+
175
181
// CreateClone creates a new ZFS clone.
176
182
func (m * Manager ) CreateClone (cloneName , snapshotID string ) error {
177
183
exists , err := m .cloneExists (cloneName )
@@ -316,14 +322,20 @@ func (m *Manager) CreateSnapshot(poolSuffix, dataStateAt string) (string, error)
316
322
return "" , fmt .Errorf ("failed to parse dataStateAt: %w" , err )
317
323
}
318
324
319
- m . addSnapshotToList ( resources.Snapshot {
325
+ newSnapshot := resources.Snapshot {
320
326
ID : snapshotName ,
321
327
CreatedAt : time .Now (),
322
328
DataStateAt : dataStateTime ,
323
329
Pool : m .config .Pool .Name ,
324
- })
330
+ }
331
+
332
+ if ! strings .HasSuffix (snapshotName , m .config .PreSnapshotSuffix ) {
333
+ m .addSnapshotToList (newSnapshot )
325
334
326
- go m .RefreshSnapshotList ()
335
+ log .Dbg ("New snapshot:" , newSnapshot )
336
+
337
+ m .RefreshSnapshotList ()
338
+ }
327
339
328
340
return snapshotName , nil
329
341
}
@@ -511,8 +523,11 @@ func (m *Manager) GetFilesystemState() (models.FileSystem, error) {
511
523
512
524
// SnapshotList returns a list of snapshots.
513
525
func (m * Manager ) SnapshotList () []resources.Snapshot {
514
- snapshotList := m .snapshots
515
- return snapshotList
526
+ m .mu .Lock ()
527
+ snapshots := m .snapshots
528
+ m .mu .Unlock ()
529
+
530
+ return snapshots
516
531
}
517
532
518
533
// RefreshSnapshotList updates the list of snapshots.
@@ -559,20 +574,22 @@ func (m *Manager) getSnapshots() ([]resources.Snapshot, error) {
559
574
560
575
func (m * Manager ) addSnapshotToList (snapshot resources.Snapshot ) {
561
576
m .mu .Lock ()
562
- m .snapshots = append (m . snapshots , snapshot )
577
+ m .snapshots = append ([]resources. Snapshot { snapshot }, m . snapshots ... )
563
578
m .mu .Unlock ()
564
579
}
565
580
566
581
func (m * Manager ) removeSnapshotFromList (snapshotName string ) {
582
+ m .mu .Lock ()
583
+
567
584
for i , snapshot := range m .snapshots {
568
585
if snapshot .ID == snapshotName {
569
- m .mu .Lock ()
570
- m .snapshots = append (m .snapshots [:i ], m .snapshots [i + 1 :]... )
571
- m .mu .Unlock ()
586
+ m .snapshots = append ((m .snapshots )[:i ], (m .snapshots )[i + 1 :]... )
572
587
573
588
break
574
589
}
575
590
}
591
+
592
+ m .mu .Unlock ()
576
593
}
577
594
578
595
// ListFilesystems lists ZFS file systems (clones, pools).
0 commit comments