-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathvolumetypes.go
645 lines (567 loc) · 23.2 KB
/
volumetypes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
// Copyright (c) 2020 Zededa, Inc.
// SPDX-License-Identifier: Apache-2.0
package types
import (
"fmt"
"strings"
"time"
"github.com/google/go-cmp/cmp"
zconfig "github.com/lf-edge/eve-api/go/config"
"github.com/lf-edge/eve/pkg/pillar/base"
uuid "github.com/satori/go.uuid"
)
// VolumeConfig specifies the needed information for volumes
type VolumeConfig struct {
VolumeID uuid.UUID
ContentID uuid.UUID
VolumeContentOriginType zconfig.VolumeContentOriginType
MaxVolSize uint64
ReadOnly bool
GenerationCounter int64
LocalGenerationCounter int64
Encrypted bool
DisplayName string
HasNoAppReferences bool
Target zconfig.Target
CustomMeta string
}
// Key is volume UUID which will be unique
func (config VolumeConfig) Key() string {
return fmt.Sprintf("%s#%d", config.VolumeID.String(),
config.GenerationCounter+config.LocalGenerationCounter)
}
// LogCreate :
func (config VolumeConfig) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.VolumeConfigLogType, config.DisplayName,
config.VolumeID, config.LogKey())
if logObject == nil {
return
}
logObject.CloneAndAddField("content-id", config.ContentID).
AddField("max-vol-size-int64", config.MaxVolSize).
AddField("generation-counter-int64", config.GenerationCounter).
AddField("local-generation-counter-int64", config.LocalGenerationCounter).
Noticef("Volume config create")
}
// LogModify :
func (config VolumeConfig) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.VolumeConfigLogType, config.DisplayName,
config.VolumeID, config.LogKey())
oldConfig, ok := old.(VolumeConfig)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of VolumeConfig type")
}
if oldConfig.ContentID != config.ContentID ||
oldConfig.MaxVolSize != config.MaxVolSize {
logObject.CloneAndAddField("content-id", config.ContentID).
AddField("max-vol-size-int64", config.MaxVolSize).
AddField("old-content-id", oldConfig.ContentID).
AddField("old-max-vol-size-int64", oldConfig.MaxVolSize).
Noticef("Volume config modify")
} else {
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldConfig, config)).
Noticef("Volume config modify other change")
}
}
// LogDelete :
func (config VolumeConfig) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.VolumeConfigLogType, config.DisplayName,
config.VolumeID, config.LogKey())
logObject.CloneAndAddField("content-id", config.ContentID).
AddField("max-vol-size-int64", config.MaxVolSize).
AddField("generation-counter-int64", config.GenerationCounter).
AddField("local-generation-counter-int64", config.LocalGenerationCounter).
Noticef("Volume config delete")
base.DeleteLogObject(logBase, config.LogKey())
}
// LogKey :
func (config VolumeConfig) LogKey() string {
return string(base.VolumeConfigLogType) + "-" + config.Key()
}
// volumeSubState is type for defining additional statuses for VolumeStatus
type volumeSubState uint8
// Enum of volumeSubState variants
const (
VolumeSubStateInitial volumeSubState = iota
VolumeSubStatePreparing
VolumeSubStatePrepareDone
VolumeSubStateCreated
VolumeSubStateDeleting
)
// VolumeStatus is response from volumemgr about status of volumes
type VolumeStatus struct {
VolumeID uuid.UUID
ContentID uuid.UUID
VolumeContentOriginType zconfig.VolumeContentOriginType
MaxVolSize uint64
ReadOnly bool
GenerationCounter int64
LocalGenerationCounter int64
Encrypted bool
DisplayName string
State SwState
SubState volumeSubState
RefCount uint
LastRefCountChangeTime time.Time
Progress uint // In percent i.e., 0-100
TotalSize int64 // expected size as reported by the downloader, if any
CurrentSize int64 // current total downloaded size as reported by the downloader
FileLocation string // Location of filestystem
CreateTime time.Time
ContentFormat zconfig.Format
LastUse time.Time
PreReboot bool // Was volume last use prior to device reboot?
ReferenceName string
WWN string
Target zconfig.Target
CustomMeta string
ErrorAndTimeWithSource
}
// Key is volume UUID which will be unique
func (status VolumeStatus) Key() string {
return fmt.Sprintf("%s#%d", status.VolumeID.String(),
status.GenerationCounter+status.LocalGenerationCounter)
}
// IsContainer will return true if content tree attached
// to the volume is of container type
func (status VolumeStatus) IsContainer() bool {
return status.ContentFormat == zconfig.Format_CONTAINER
}
// PathName returns the path of the volume
func (status VolumeStatus) PathName() string {
baseDir := VolumeClearDirName
if status.Encrypted {
baseDir = VolumeEncryptedDirName
}
return fmt.Sprintf("%s/%s#%d.%s", baseDir, status.VolumeID.String(),
status.GenerationCounter+status.LocalGenerationCounter,
strings.ToLower(status.ContentFormat.String()))
}
// GetPVCName : returns the volume name for kubernetes(longhorn)
// Kubernetes does not allow special characters like '#' in the object names.
// so we need to generate a PVC name.
func (status VolumeStatus) GetPVCName() string {
return fmt.Sprintf("%s-pvc-%d", status.VolumeID.String(),
status.GenerationCounter+status.LocalGenerationCounter)
}
// LogCreate :
func (status VolumeStatus) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.VolumeStatusLogType, status.DisplayName,
status.VolumeID, status.LogKey())
if logObject == nil {
return
}
logObject.CloneAndAddField("content-id", status.ContentID).
AddField("max-vol-size-int64", status.MaxVolSize).
AddField("state", status.State.String()).
AddField("progress-int64", status.Progress).
AddField("refcount-int64", status.RefCount).
AddField("filelocation", status.FileLocation).
Noticef("Volume status create")
}
// LogModify :
func (status VolumeStatus) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.VolumeStatusLogType, status.DisplayName,
status.VolumeID, status.LogKey())
oldStatus, ok := old.(VolumeStatus)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of VolumeStatus type")
}
if oldStatus.ContentID != status.ContentID ||
oldStatus.MaxVolSize != status.MaxVolSize ||
oldStatus.State != status.State ||
oldStatus.Progress != status.Progress ||
oldStatus.RefCount != status.RefCount ||
oldStatus.FileLocation != status.FileLocation {
logObject.CloneAndAddField("content-id", status.ContentID).
AddField("max-vol-size-int64", status.MaxVolSize).
AddField("state", status.State.String()).
AddField("progress-int64", status.Progress).
AddField("refcount-int64", status.RefCount).
AddField("filelocation", status.FileLocation).
AddField("old-content-id", oldStatus.ContentID).
AddField("old-max-vol-size-int64", oldStatus.MaxVolSize).
AddField("old-state", oldStatus.State.String()).
AddField("old-progress-int64", oldStatus.Progress).
AddField("old-refcount-int64", oldStatus.RefCount).
AddField("old-filelocation", oldStatus.FileLocation).
Noticef("Volume status modify")
} else {
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldStatus, status)).
Noticef("Volume status modify other change")
}
}
// LogDelete :
func (status VolumeStatus) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.VolumeStatusLogType, status.DisplayName,
status.VolumeID, status.LogKey())
logObject.CloneAndAddField("content-id", status.ContentID).
AddField("max-vol-size-int64", status.MaxVolSize).
AddField("state", status.State.String()).
AddField("progress-int64", status.Progress).
AddField("refcount-int64", status.RefCount).
AddField("filelocation", status.FileLocation).
Noticef("Volume status delete")
base.DeleteLogObject(logBase, status.LogKey())
}
// LogKey :
func (status VolumeStatus) LogKey() string {
return string(base.VolumeStatusLogType) + "-" + status.Key()
}
// VolumesSnapshotAction is the action to perform on the snapshot
type VolumesSnapshotAction uint8
const (
// VolumesSnapshotUnspecifiedAction is the default value
VolumesSnapshotUnspecifiedAction VolumesSnapshotAction = iota
// VolumesSnapshotCreate is used to create a snapshot
VolumesSnapshotCreate
// VolumesSnapshotRollback is used to roll back to a snapshot
VolumesSnapshotRollback
// VolumesSnapshotDelete is used to delete a snapshot
VolumesSnapshotDelete
)
func (action VolumesSnapshotAction) String() string {
switch action {
case VolumesSnapshotCreate:
return "Create"
case VolumesSnapshotRollback:
return "Rollback"
case VolumesSnapshotDelete:
return "Delete"
default:
return "Unspecified"
}
}
// VolumesSnapshotConfig is used to send snapshot requests from zedmanager to volumemgr
type VolumesSnapshotConfig struct {
// SnapshotID is the ID of the snapshot
SnapshotID string
// Action is the action to perform on the snapshot
Action VolumesSnapshotAction
// VolumeIDs is a list of volumes to snapshot
VolumeIDs []uuid.UUID
// AppUUID used as a backlink to the app
AppUUID uuid.UUID
}
// Key returns unique key for the snapshot
func (config VolumesSnapshotConfig) Key() string {
return config.SnapshotID
}
// VolumesSnapshotStatus is used to send snapshot status from volumemgr to zedmanager
type VolumesSnapshotStatus struct {
// SnapshotID is the ID of the snapshot, critical field
SnapshotID string `mandatory:"true"`
// Metadata is a map of volumeID to metadata, depending on the volume type. Critical field.
VolumeSnapshotMeta map[string]interface{} `mandatory:"true"`
// TimeCreated is the time the snapshot was created, reported by FS-specific code
TimeCreated time.Time
// AppUUID used as a backlink to the app, critical field
AppUUID uuid.UUID `mandatory:"true"`
// RefCount is the number of times the snapshot is used. Necessary to trigger the handleModify handler
RefCount int
// ResultOfAction is the type of action that was performed on the snapshot that resulted in this status
ResultOfAction VolumesSnapshotAction
// ErrorAndTimeWithSource provides SetErrorNow() and ClearError()
ErrorAndTimeWithSource
}
// Key returns unique key for the snapshot
func (status VolumesSnapshotStatus) Key() string {
return status.SnapshotID
}
// VolumeRefConfig : Used for communication from zedagent to volumemgr, contains info from AppInstanceConfig
type VolumeRefConfig struct {
// this part shows the link between the volume and the app
VolumeID uuid.UUID
GenerationCounter int64
LocalGenerationCounter int64
AppUUID uuid.UUID
// this information comes from AppInstanceConfig and remains constant
MountDir string
// this part is for communication between zedmanager and volumemgr (set by zedmanager)
VerifyOnly bool // controls whether the volumemgr should only download and verify the volume (true) or also create it (false)
}
// Key : VolumeRefConfig unique key (used to uniquely identify the current struct, mostly for pubsub) - the same as for the corresponding VolumeRefStatus
func (config VolumeRefConfig) Key() string {
return fmt.Sprintf("%s#%d#%s", config.VolumeID.String(),
config.GenerationCounter+config.LocalGenerationCounter, config.AppUUID.String())
}
// VolumeKey : Unique key of volume referenced in VolumeRefConfig (used to uniquely identify the volume, attached to the app instance)
func (config VolumeRefConfig) VolumeKey() string {
return fmt.Sprintf("%s#%d", config.VolumeID.String(),
config.GenerationCounter+config.LocalGenerationCounter)
}
// LogCreate :
func (config VolumeRefConfig) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.VolumeRefConfigLogType, "",
config.VolumeID, config.LogKey())
if logObject == nil {
return
}
logObject.CloneAndAddField("generation-counter-int64", config.GenerationCounter).
AddField("local-generation-counter-int64", config.LocalGenerationCounter).
Noticef("Volume ref config create")
}
// LogModify :
func (config VolumeRefConfig) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.VolumeRefConfigLogType, "",
config.VolumeID, config.LogKey())
oldConfig, ok := old.(VolumeRefConfig)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of VolumeRefConfig type")
}
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldConfig, config)).
Noticef("Volume ref config modify other change")
}
// LogDelete :
func (config VolumeRefConfig) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.VolumeRefConfigLogType, "",
config.VolumeID, config.LogKey())
logObject.Noticef("Volume ref config delete")
base.DeleteLogObject(logBase, config.LogKey())
}
// LogKey :
func (config VolumeRefConfig) LogKey() string {
return string(base.VolumeRefConfigLogType) + "-" + config.Key()
}
// VolumeRefStatus : Reference to a Volume specified separately in the API
// If a volume is purged (re-created from scratch) it will either have a new
// UUID or a new generationCount
type VolumeRefStatus struct {
VolumeID uuid.UUID
GenerationCounter int64
LocalGenerationCounter int64
AppUUID uuid.UUID
State SwState
ActiveFileLocation string
ContentFormat zconfig.Format
ReadOnly bool
DisplayName string
MaxVolSize uint64
PendingAdd bool // Flag to identify whether volume ref config published or not
WWN string
VerifyOnly bool
Target zconfig.Target
CustomMeta string
ReferenceName string
ErrorAndTimeWithSource
}
// Key : VolumeRefStatus unique key (used to uniquely identify the current struct, mostly for pubsub) - the same as for the corresponding VolumeRefConfig
func (status VolumeRefStatus) Key() string {
return fmt.Sprintf("%s#%d#%s", status.VolumeID.String(),
status.GenerationCounter+status.LocalGenerationCounter, status.AppUUID.String())
}
// VolumeKey : Unique key of volume referenced in VolumeRefStatus (used to uniquely identify the volume, attached to the app instance)
func (status VolumeRefStatus) VolumeKey() string {
return fmt.Sprintf("%s#%d", status.VolumeID.String(),
status.GenerationCounter+status.LocalGenerationCounter)
}
// IsContainer will return true if content tree attached
// to the volume ref is of container type
func (status VolumeRefStatus) IsContainer() bool {
return status.ContentFormat == zconfig.Format_CONTAINER
}
// LogCreate :
func (status VolumeRefStatus) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.VolumeRefStatusLogType, status.DisplayName,
status.VolumeID, status.LogKey())
if logObject == nil {
return
}
logObject.CloneAndAddField("generation-counter-int64", status.GenerationCounter).
AddField("local-generation-counter-int64", status.LocalGenerationCounter).
AddField("state", status.State.String()).
AddField("filelocation", status.ActiveFileLocation).
AddField("content-format", status.ContentFormat).
AddField("read-only-bool", status.ReadOnly).
AddField("displayname", status.DisplayName).
AddField("max-vol-size-int64", status.MaxVolSize).
AddField("pending-add-bool", status.PendingAdd).
Noticef("Volume ref status create")
}
// LogModify :
func (status VolumeRefStatus) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.VolumeRefStatusLogType, status.DisplayName,
status.VolumeID, status.LogKey())
oldStatus, ok := old.(VolumeRefStatus)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of VolumeRefStatus type")
}
if oldStatus.State != status.State ||
oldStatus.ActiveFileLocation != status.ActiveFileLocation ||
oldStatus.ContentFormat != status.ContentFormat ||
oldStatus.ReadOnly != status.ReadOnly ||
oldStatus.DisplayName != status.DisplayName ||
oldStatus.MaxVolSize != status.MaxVolSize ||
oldStatus.PendingAdd != status.PendingAdd {
logObject.CloneAndAddField("state", status.State.String()).
AddField("filelocation", status.ActiveFileLocation).
AddField("content-format", status.ContentFormat).
AddField("read-only-bool", status.ReadOnly).
AddField("displayname", status.DisplayName).
AddField("max-vol-size-int64", status.MaxVolSize).
AddField("pending-add-bool", status.PendingAdd).
AddField("old-state", oldStatus.State.String()).
AddField("old-filelocation", oldStatus.ActiveFileLocation).
AddField("content-format", oldStatus.ContentFormat).
AddField("read-only-bool", oldStatus.ReadOnly).
AddField("displayname", oldStatus.DisplayName).
AddField("old-max-vol-size-int64", oldStatus.MaxVolSize).
AddField("Pending-add-bool", oldStatus.PendingAdd).
Noticef("Volume ref status modify")
}
}
// LogDelete :
func (status VolumeRefStatus) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.VolumeRefStatusLogType, status.DisplayName,
status.VolumeID, status.LogKey())
logObject.CloneAndAddField("generation-counter-int64", status.GenerationCounter).
AddField("local-generation-counter-int64", status.LocalGenerationCounter).
AddField("state", status.State.String()).
AddField("filelocation", status.ActiveFileLocation).
AddField("content-format", status.ContentFormat).
AddField("read-only-bool", status.ReadOnly).
AddField("displayname", status.DisplayName).
AddField("max-vol-size-int64", status.MaxVolSize).
AddField("pending-add-bool", status.PendingAdd).
Noticef("Volume ref status delete")
base.DeleteLogObject(logBase, status.LogKey())
}
// LogKey :
func (status VolumeRefStatus) LogKey() string {
return string(base.VolumeRefStatusLogType) + "-" + status.Key()
}
// VolumeCreatePending is temporary store for volumes that are creating
// After successful creating operation we should delete this object
type VolumeCreatePending struct {
VolumeID uuid.UUID
GenerationCounter int64
LocalGenerationCounter int64
ContentFormat zconfig.Format
Encrypted bool
}
// Key : VolumeCreatePending unique key
func (status VolumeCreatePending) Key() string {
return fmt.Sprintf("%s#%d", status.VolumeID.String(),
status.GenerationCounter+status.LocalGenerationCounter)
}
// LogKey :
func (status VolumeCreatePending) LogKey() string {
return string(base.VolumeCreatePendingLogType) + "-" + status.Key()
}
// PathName returns the path of the volume
func (status VolumeCreatePending) PathName() string {
baseDir := VolumeClearDirName
if status.Encrypted {
baseDir = VolumeEncryptedDirName
}
return fmt.Sprintf("%s/%s#%d.%s", baseDir, status.VolumeID.String(),
status.GenerationCounter+status.LocalGenerationCounter,
strings.ToLower(status.ContentFormat.String()))
}
// IsContainer will return true if content tree attached
// to the volume is of container type
func (status VolumeCreatePending) IsContainer() bool {
return status.ContentFormat == zconfig.Format_CONTAINER
}
// VolumeCreatePendingFromVolumeStatus returns VolumeCreatePending for provided VolumeStatus
func VolumeCreatePendingFromVolumeStatus(status VolumeStatus) VolumeCreatePending {
return VolumeCreatePending{
VolumeID: status.VolumeID,
GenerationCounter: status.GenerationCounter,
LocalGenerationCounter: status.LocalGenerationCounter,
ContentFormat: status.ContentFormat,
Encrypted: status.Encrypted,
}
}
// LogCreate :
func (status VolumeCreatePending) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.VolumeCreatePendingLogType, "",
status.VolumeID, status.LogKey())
if logObject == nil {
return
}
logObject.CloneAndAddField("generation-counter-int64", status.GenerationCounter).
AddField("local-generation-counter-int64", status.LocalGenerationCounter).
AddField("content-format", status.ContentFormat).
AddField("encrypted", status.Encrypted).
Noticef("Volume create pending create")
}
// LogModify :
func (status VolumeCreatePending) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.VolumeCreatePendingLogType, "",
status.VolumeID, status.LogKey())
oldStatus, ok := old.(VolumeCreatePending)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of VolumeCreatePending type")
}
if oldStatus.GenerationCounter != status.GenerationCounter ||
oldStatus.LocalGenerationCounter != status.LocalGenerationCounter ||
oldStatus.ContentFormat != status.ContentFormat ||
oldStatus.Encrypted != status.Encrypted {
logObject.CloneAndAddField("generation-counter-int64", status.GenerationCounter).
AddField("local-generation-counter-int64", status.LocalGenerationCounter).
AddField("content-format", status.ContentFormat).
AddField("encrypted", status.Encrypted).
AddField("old-generation-counter-int64", oldStatus.GenerationCounter).
AddField("old-local-generation-counter-int64", oldStatus.LocalGenerationCounter).
AddField("old-content-format", oldStatus.ContentFormat).
AddField("old-encrypted", oldStatus.Encrypted).
Noticef("Volume create pending modify")
}
}
// LogDelete :
func (status VolumeCreatePending) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.VolumeCreatePendingLogType, "",
status.VolumeID, status.LogKey())
logObject.CloneAndAddField("generation-counter-int64", status.GenerationCounter).
AddField("local-generation-counter-int64", status.LocalGenerationCounter).
AddField("content-format", status.ContentFormat).
AddField("encrypted", status.Encrypted).
Noticef("Volume create pending delete")
base.DeleteLogObject(logBase, status.LogKey())
}
// VolumeMgrStatus :
type VolumeMgrStatus struct {
Name string
Initialized bool
RemainingSpace uint64 // In bytes. Takes into account "reserved" for dom0
}
// Key :
func (status VolumeMgrStatus) Key() string {
return status.Name
}
// LogCreate :
func (status VolumeMgrStatus) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.VolumeMgrStatusLogType, status.Name,
nilUUID, status.LogKey())
if logObject == nil {
return
}
logObject.Noticef("Zedagent status create")
}
// LogModify :
func (status VolumeMgrStatus) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.VolumeMgrStatusLogType, status.Name,
nilUUID, status.LogKey())
oldStatus, ok := old.(VolumeMgrStatus)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of VolumeMgrStatus type")
}
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldStatus, status)).
Noticef("Zedagent status modify")
}
// LogDelete :
func (status VolumeMgrStatus) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.VolumeMgrStatusLogType, status.Name,
nilUUID, status.LogKey())
logObject.Noticef("Zedagent status delete")
base.DeleteLogObject(logBase, status.LogKey())
}
// LogKey :
func (status VolumeMgrStatus) LogKey() string {
return string(base.VolumeMgrStatusLogType) + "-" + status.Key()
}