mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
rbd: implement snapinfo with go-ceph
moved snapinfo function from CLI to go-ceph for better performance Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
b3f1499cd4
commit
c30f91eead
@ -174,11 +174,6 @@ func (rs *rbdSnapshot) String() string {
|
|||||||
return fmt.Sprintf("%s/%s@%s", rs.Pool, rs.RbdImageName, rs.RbdSnapName)
|
return fmt.Sprintf("%s/%s@%s", rs.Pool, rs.RbdImageName, rs.RbdSnapName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// imageSpec returns the image-spec (pool/image) format of the snapshot
|
|
||||||
func (rs *rbdSnapshot) imageSpec() string {
|
|
||||||
return fmt.Sprintf("%s/%s", rs.Pool, rs.RbdImageName)
|
|
||||||
}
|
|
||||||
|
|
||||||
// createImage creates a new ceph image with provision and volume options.
|
// createImage creates a new ceph image with provision and volume options.
|
||||||
func createImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) error {
|
func createImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) error {
|
||||||
volSzMiB := fmt.Sprintf("%dM", util.RoundOffVolSize(pOpts.VolSize))
|
volSzMiB := fmt.Sprintf("%dM", util.RoundOffVolSize(pOpts.VolSize))
|
||||||
@ -809,45 +804,26 @@ getSnapInfo queries rbd about the snapshots of the given image and returns its m
|
|||||||
returns ErrImageNotFound if provided image is not found, and ErrSnapNotFound if provided snap
|
returns ErrImageNotFound if provided image is not found, and ErrSnapNotFound if provided snap
|
||||||
is not found in the images snapshot list
|
is not found in the images snapshot list
|
||||||
*/
|
*/
|
||||||
func (rs *rbdSnapshot) getSnapInfo(ctx context.Context, monitors string, cr *util.Credentials) (snapInfo, error) {
|
func (rv *rbdVolume) getSnapInfo(rbdSnap *rbdSnapshot) (librbd.SnapInfo, error) {
|
||||||
// rbd --format=json snap ls [image-spec]
|
invalidSnap := librbd.SnapInfo{}
|
||||||
|
image, err := rv.open()
|
||||||
var (
|
|
||||||
snpInfo snapInfo
|
|
||||||
snaps []snapInfo
|
|
||||||
)
|
|
||||||
|
|
||||||
stdout, stderr, err := util.ExecCommand(
|
|
||||||
"rbd",
|
|
||||||
"-m", monitors,
|
|
||||||
"--id", cr.ID,
|
|
||||||
"--keyfile="+cr.KeyFile,
|
|
||||||
"-c", util.CephConfigPath,
|
|
||||||
"--format="+"json",
|
|
||||||
"snap", "ls", rs.imageSpec())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf(util.Log(ctx, "failed getting snap (%s) information from image (%s): (%s)"),
|
return invalidSnap, err
|
||||||
rs.RbdSnapName, rs.imageSpec(), err)
|
|
||||||
if strings.Contains(string(stderr), "rbd: error opening image "+rs.RbdImageName+
|
|
||||||
": (2) No such file or directory") {
|
|
||||||
return snpInfo, ErrImageNotFound{rs.imageSpec(), err}
|
|
||||||
}
|
|
||||||
return snpInfo, err
|
|
||||||
}
|
}
|
||||||
|
defer image.Close()
|
||||||
|
|
||||||
err = json.Unmarshal(stdout, &snaps)
|
snaps, err := image.GetSnapshotNames()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf(util.Log(ctx, "failed to parse JSON output of image snap list (%s): (%s)"), rs.imageSpec(), err)
|
return invalidSnap, err
|
||||||
return snpInfo, fmt.Errorf("unmarshal failed: %+v. raw buffer response: %s", err, string(stdout))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, snap := range snaps {
|
for _, snap := range snaps {
|
||||||
if snap.Name == rs.RbdSnapName {
|
if snap.Name == rbdSnap.RbdSnapName {
|
||||||
return snap, nil
|
return snap, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return snpInfo, ErrSnapNotFound{rs.String(), fmt.Errorf("snap (%s) not found", rs)}
|
return invalidSnap, ErrSnapNotFound{rbdSnap.RbdSnapName, fmt.Errorf("snap %s not found", rbdSnap.String())}
|
||||||
}
|
}
|
||||||
|
|
||||||
// rbdImageMetadataStash strongly typed JSON spec for stashed RBD image metadata
|
// rbdImageMetadataStash strongly typed JSON spec for stashed RBD image metadata
|
||||||
|
Loading…
Reference in New Issue
Block a user