mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-26 00:00:23 +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:
parent
70998571aa
commit
6d24080851
@ -220,6 +220,7 @@ func (ns *NodeServer) NodeStageVolume(
|
|||||||
|
|
||||||
volOptions.MapOptions = req.GetVolumeContext()["mapOptions"]
|
volOptions.MapOptions = req.GetVolumeContext()["mapOptions"]
|
||||||
volOptions.UnmapOptions = req.GetVolumeContext()["unmapOptions"]
|
volOptions.UnmapOptions = req.GetVolumeContext()["unmapOptions"]
|
||||||
|
volOptions.Mounter = req.GetVolumeContext()["mounter"]
|
||||||
|
|
||||||
// Stash image details prior to mapping the image (useful during Unstage as it has no
|
// Stash image details prior to mapping the image (useful during Unstage as it has no
|
||||||
// voloptions passed to the RPC as per the CSI spec)
|
// voloptions passed to the RPC as per the CSI spec)
|
||||||
@ -315,6 +316,17 @@ func (ns *NodeServer) stageTransaction(
|
|||||||
util.DebugLog(ctx, "rbd image: %s/%s was successfully mapped at %s\n",
|
util.DebugLog(ctx, "rbd image: %s/%s was successfully mapped at %s\n",
|
||||||
req.GetVolumeId(), volOptions.Pool, devicePath)
|
req.GetVolumeId(), volOptions.Pool, devicePath)
|
||||||
|
|
||||||
|
// userspace mounters like nbd need the device path as a reference while
|
||||||
|
// restarting the userspace processes on a nodeplugin restart. For kernel
|
||||||
|
// mounter(krbd) we don't need it as there won't be any process running
|
||||||
|
// in userspace, hence we don't store the device path for krbd devices.
|
||||||
|
if volOptions.Mounter == rbdNbdMounter {
|
||||||
|
err = updateRBDImageMetadataStash(req.GetStagingTargetPath(), devicePath)
|
||||||
|
if err != nil {
|
||||||
|
return transaction, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if volOptions.isEncrypted() {
|
if volOptions.isEncrypted() {
|
||||||
devicePath, err = ns.processEncryptedDevice(ctx, volOptions, devicePath)
|
devicePath, err = ns.processEncryptedDevice(ctx, volOptions, devicePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1380,6 +1380,7 @@ type rbdImageMetadataStash struct {
|
|||||||
UnmapOptions string `json:"unmapOptions"`
|
UnmapOptions string `json:"unmapOptions"`
|
||||||
NbdAccess bool `json:"accessType"`
|
NbdAccess bool `json:"accessType"`
|
||||||
Encrypted bool `json:"encrypted"`
|
Encrypted bool `json:"encrypted"`
|
||||||
|
DevicePath string `json:"device"` // holds NBD device path for now
|
||||||
}
|
}
|
||||||
|
|
||||||
// file name in which image metadata is stashed.
|
// file name in which image metadata is stashed.
|
||||||
@ -1447,6 +1448,32 @@ func lookupRBDImageMetadataStash(metaDataPath string) (rbdImageMetadataStash, er
|
|||||||
return imgMeta, nil
|
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.
|
// cleanupRBDImageMetadataStash cleans up any stashed metadata at passed in path.
|
||||||
func cleanupRBDImageMetadataStash(metaDataPath string) error {
|
func cleanupRBDImageMetadataStash(metaDataPath string) error {
|
||||||
fPath := filepath.Join(metaDataPath, stashFileName)
|
fPath := filepath.Join(metaDataPath, stashFileName)
|
||||||
|
Loading…
Reference in New Issue
Block a user