@@ -26,6 +26,8 @@ import (
2626 "github.com/google/uuid"
2727
2828 nvme2 "github.com/NearNodeFlash/nnf-ec/internal/switchtec/pkg/nvme"
29+ event "github.com/NearNodeFlash/nnf-ec/pkg/manager-event"
30+ msgreg "github.com/NearNodeFlash/nnf-ec/pkg/manager-message-registry/registries"
2931 nvme "github.com/NearNodeFlash/nnf-ec/pkg/manager-nvme"
3032 "github.com/NearNodeFlash/nnf-ec/pkg/persistent"
3133 sf "github.com/NearNodeFlash/nnf-ec/pkg/rfsf/pkg/models"
@@ -208,20 +210,21 @@ func (p *StoragePool) replaceMissingVolumes() error {
208210 return nil
209211 }
210212
211- // Attempt to locate a storage device that is not providing a volume
212- // and use it to replace the missing volume
213+ // Attempt to locate a storage device that is not providing a volume in this pool,
214+ // and create a new volume on it to replace the missing volume.
213215 // This is a best effort attempt to replace the missing volume
214- // and may not be successful if there are no available storage devices
215- // or if the storage device is not able to provide a volume
216+ // and may not be successful if there are no available storage devices,
217+ // or if the storage device is not able to provide a volume.
216218 // This is not a failure condition, but rather a best effort attempt
217- // to replace the missing volume
219+ // to replace the missing volume.
218220 // The caller should check the missing volumes list to determine
219221 // if there are any missing volumes that were not replaced
220222 unusedStorages := p .locateUnusedStorage ()
221223 if len (unusedStorages ) == 0 {
222224 return fmt .Errorf ("Unable to find unused storage" )
223225 }
224226
227+ // It's all or nothing, we need to replace all the missing volumes or none.
225228 if len (unusedStorages ) < len (p .missingVolumes ) {
226229 log .V (2 ).Info ("not enough unused storage" , "unusedStorageCount" , len (unusedStorages ), "missingVolumeCount" , len (p .missingVolumes ))
227230 return fmt .Errorf ("Not enough unused storage to replace missing volumes" )
@@ -236,22 +239,29 @@ func (p *StoragePool) replaceMissingVolumes() error {
236239 for idx , missingVolume := range p .missingVolumes {
237240 log := log .WithValues ("missingVolume" , missingVolume )
238241
239- log .V ( 2 ). Info ("replace missing volume" , "missingVolume" , missingVolume )
242+ log .Info ("replace missing volume" )
240243 storage := unusedStorages [idx ]
241244
242245 volume , err := nvme .CreateVolume (storage , p .volumeCapacity )
243246 if err != nil {
244247 log .Error (err , "Failed to create replacement volume" )
245248 return fmt .Errorf ("Failed to create volume: %v" , err )
246249 }
247- log .V (2 ).Info ("created replacement volume" , "volume" , volume .Id ())
248250 pv := nvme.ProvidingVolume {
249251 Storage : storage ,
250252 VolumeId : volume .Id (),
251253 }
254+ log .Info ("created replacement volume" , "storage" , storage .SerialNumber (), "volume" , pv .VolumeId )
252255
253256 p .providingVolumes = append (p .providingVolumes , pv )
254257
258+ event .EventManager .PublishResourceEvent (msgreg .StoragePoolPatchedNnf (
259+ p .id ,
260+ missingVolume .SerialNumber ,
261+ volume .Id (),
262+ pv .Storage .SerialNumber (),
263+ pv .VolumeId ), p )
264+
255265 // TODO: Find the serialnumber/volumeid in any other storage pools and
256266 // invalidate that volumeid to prevent reuse. Should probably store
257267 // that new value some how too.
0 commit comments