mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
journal: change omap set func to handle multiple key-value pairs
For any function that sets more than one key on a single oid setting them as a batch will be more efficient. Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
parent
a8409eccc8
commit
c14cbee132
@ -105,10 +105,10 @@ func removeMapKeys(
|
||||
return err
|
||||
}
|
||||
|
||||
func setOneOMapKey(
|
||||
func setOMapKeys(
|
||||
ctx context.Context,
|
||||
conn *Connection,
|
||||
poolName, namespace, oMapName, oMapKey, keyValue string) error {
|
||||
poolName, namespace, oid string, pairs map[string]string) error {
|
||||
// fetch and configure the rados ioctx
|
||||
ioctx, err := conn.conn.GetIoctx(poolName)
|
||||
if err != nil {
|
||||
@ -120,20 +120,21 @@ func setOneOMapKey(
|
||||
ioctx.SetNamespace(namespace)
|
||||
}
|
||||
|
||||
pairs := map[string][]byte{
|
||||
oMapKey: []byte(keyValue),
|
||||
bpairs := make(map[string][]byte, len(pairs))
|
||||
for k, v := range pairs {
|
||||
bpairs[k] = []byte(v)
|
||||
}
|
||||
err = ioctx.SetOmap(oMapName, pairs)
|
||||
err = ioctx.SetOmap(oid, bpairs)
|
||||
if err != nil {
|
||||
klog.Errorf(
|
||||
util.Log(ctx, "failed setting omap key (pool=%q, namespace=%q, name=%q, key=%q, value=%q): %v"),
|
||||
poolName, namespace, oMapName, oMapKey, keyValue, err)
|
||||
} else {
|
||||
klog.Infof(
|
||||
util.Log(ctx, "XXX set omap key (pool=%q, namespace=%q, name=%q, key=%q, value=%q): %v"),
|
||||
poolName, namespace, oMapName, oMapKey, keyValue, err)
|
||||
util.Log(ctx, "failed setting omap keys (pool=%q, namespace=%q, name=%q, pairs=%+v): %v"),
|
||||
poolName, namespace, oid, pairs, err)
|
||||
return err
|
||||
}
|
||||
return err
|
||||
klog.V(4).Infof(
|
||||
util.Log(ctx, "set omap keys (pool=%q, namespace=%q, name=%q): %+v)"),
|
||||
poolName, namespace, oid, pairs)
|
||||
return nil
|
||||
}
|
||||
|
||||
func omapPoolError(poolName string, err error) error {
|
||||
|
@ -517,8 +517,8 @@ func (conn *Connection) ReserveName(ctx context.Context,
|
||||
nameKeyVal = volUUID
|
||||
}
|
||||
|
||||
err = setOneOMapKey(ctx, conn, journalPool, cj.namespace, cj.csiDirectory,
|
||||
cj.csiNameKeyPrefix+reqName, nameKeyVal)
|
||||
err = setOMapKeys(ctx, conn, journalPool, cj.namespace, cj.csiDirectory,
|
||||
map[string]string{cj.csiNameKeyPrefix + reqName: nameKeyVal})
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
@ -532,30 +532,21 @@ func (conn *Connection) ReserveName(ctx context.Context,
|
||||
}
|
||||
}()
|
||||
|
||||
oid := cj.cephUUIDDirectoryPrefix + volUUID
|
||||
omapValues := map[string]string{}
|
||||
|
||||
// NOTE: UUID directory is stored on the same pool as the image, helps determine image attributes
|
||||
// and also CSI journal pool, when only the VolumeID is passed in (e.g DeleteVolume/DeleteSnapshot,
|
||||
// VolID during CreateSnapshot).
|
||||
// Update UUID directory to store CSI request name
|
||||
err = setOneOMapKey(ctx, conn, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID,
|
||||
cj.csiNameKey, reqName)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
omapValues[cj.csiNameKey] = reqName
|
||||
|
||||
// Update UUID directory to store image name
|
||||
err = setOneOMapKey(ctx, conn, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID,
|
||||
cj.csiImageKey, imageName)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
omapValues[cj.csiImageKey] = imageName
|
||||
|
||||
// Update UUID directory to store encryption values
|
||||
if kmsConf != "" {
|
||||
err = setOneOMapKey(ctx, conn, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID,
|
||||
cj.encryptKMSKey, kmsConf)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
omapValues[cj.encryptKMSKey] = kmsConf
|
||||
}
|
||||
|
||||
if journalPool != imagePool && journalPoolID != util.InvalidPoolID {
|
||||
@ -564,22 +555,18 @@ func (conn *Connection) ReserveName(ctx context.Context,
|
||||
journalPoolIDStr := hex.EncodeToString(buf64)
|
||||
|
||||
// Update UUID directory to store CSI journal pool name (prefer ID instead of name to be pool rename proof)
|
||||
err = setOneOMapKey(ctx, conn, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID,
|
||||
cj.csiJournalPool, journalPoolIDStr)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
omapValues[cj.csiJournalPool] = journalPoolIDStr
|
||||
}
|
||||
|
||||
if snapSource {
|
||||
// Update UUID directory to store source volume UUID in case of snapshots
|
||||
err = setOneOMapKey(ctx, conn, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID,
|
||||
cj.cephSnapSourceKey, parentName)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
omapValues[cj.cephSnapSourceKey] = parentName
|
||||
}
|
||||
|
||||
err = setOMapKeys(ctx, conn, journalPool, cj.namespace, oid, omapValues)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
return volUUID, imageName, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user