mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rbd: update per volume metadata stash-file with devicePath
As part of stage transaction if the mounter is of type nbd, then capture device path after a successful rbd-nbd map. Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
70998571aa
commit
6d24080851
@ -1380,6 +1380,7 @@ type rbdImageMetadataStash struct {
|
||||
UnmapOptions string `json:"unmapOptions"`
|
||||
NbdAccess bool `json:"accessType"`
|
||||
Encrypted bool `json:"encrypted"`
|
||||
DevicePath string `json:"device"` // holds NBD device path for now
|
||||
}
|
||||
|
||||
// file name in which image metadata is stashed.
|
||||
@ -1447,6 +1448,32 @@ func lookupRBDImageMetadataStash(metaDataPath string) (rbdImageMetadataStash, er
|
||||
return imgMeta, nil
|
||||
}
|
||||
|
||||
// updateRBDImageMetadataStash reads and updates stashFile with the required
|
||||
// fields at the passed in path, in JSON format.
|
||||
func updateRBDImageMetadataStash(metaDataPath, device string) error {
|
||||
if device == "" {
|
||||
return errors.New("device is empty")
|
||||
}
|
||||
imgMeta, err := lookupRBDImageMetadataStash(metaDataPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find image metadata: %w", err)
|
||||
}
|
||||
imgMeta.DevicePath = device
|
||||
|
||||
encodedBytes, err := json.Marshal(imgMeta)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal JSON image metadata for spec:(%s) : %w", imgMeta.String(), err)
|
||||
}
|
||||
|
||||
fPath := filepath.Join(metaDataPath, stashFileName)
|
||||
err = ioutil.WriteFile(fPath, encodedBytes, 0600)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to stash JSON image metadata at path: (%s) for spec:(%s) : %w",
|
||||
fPath, imgMeta.String(), err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// cleanupRBDImageMetadataStash cleans up any stashed metadata at passed in path.
|
||||
func cleanupRBDImageMetadataStash(metaDataPath string) error {
|
||||
fPath := filepath.Join(metaDataPath, stashFileName)
|
||||
|
Reference in New Issue
Block a user