Skip to content

Commit b8b5c07

Browse files
ismaelpuertoceph-csi-bot
authored andcommitted
cephfs: pin subvolume in its own subvolume group
The "fs subvolume pin" manager command was issued through go-ceph's PinSubVolume helper, which does not accept a subvolume group. Ceph then looked the subvolume up in the default group and returned ENOENT for subvolumes created in a non-default group, which is the case for ceph-csi (and the e2e test uses the "e2e" group): failed to pin subvolume csi-vol-... in fs myfs: rados: ret=-2, No such file or directory: "subvolume 'csi-vol-...' does not exist" Issue the "fs subvolume pin" command directly with group_name set, via a new MgrCommand passthrough on ClusterConnection, so pinning works for any subvolume group. Assisted-by: goose <noreply@block.xyz> Signed-off-by: Ismael Puerto Freire <ismaelpf@inditex.com>
1 parent ac31e7c commit b8b5c07

2 files changed

Lines changed: 34 additions & 11 deletions

File tree

internal/cephfs/core/volume.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package core
1818

1919
import (
2020
"context"
21+
"encoding/json"
2122
"errors"
2223
"fmt"
2324
"path"
@@ -333,24 +334,35 @@ func checkSubvolumeHasFeature(feature string, subVolFeatures []string) bool {
333334
// pinType can be "export", "distributed" or "random".
334335
// pinSetting is the value for the pin (e.g. MDS rank "2", "true"/"false").
335336
//
336-
// NOTE: go-ceph's PinSubVolume does not accept a subvolume group argument
337-
// (only PinSubVolumeGroup does, and that pins the group, not an individual
338-
// subvolume). As a result the pin is applied against Ceph's default subvolume
339-
// group. A subvolume group can be configured per StorageClass in ceph-csi
340-
// (parameter "subvolumeGroup"), so this is a known limitation until go-ceph
341-
// exposes a PinSubVolume variant that accepts the group.
337+
// go-ceph's typed PinSubVolume helper does not accept a subvolume group, so it
338+
// would always target Ceph's default group and fail for subvolumes created in
339+
// a non-default group (as ceph-csi does). To support any group, the "fs
340+
// subvolume pin" manager command is issued directly with the group_name set.
342341
//
343342
// Similar To:
344343
//
345-
// ceph fs subvolume pin <vol_name> <sub_name> <pin_type> <pin_setting>
344+
// ceph fs subvolume pin <vol_name> <sub_name> <pin_type> <pin_setting> \
345+
// --group_name=<group>
346346
func (s *subVolumeClient) PinVolume(ctx context.Context, pinType, pinSetting string) error {
347-
fsa, err := s.conn.GetFSAdmin()
347+
cmd := map[string]string{
348+
"prefix": "fs subvolume pin",
349+
"format": "json",
350+
"vol_name": s.FsName,
351+
"sub_name": s.VolID,
352+
"group_name": s.SubvolumeGroup,
353+
"pin_type": pinType,
354+
"pin_setting": pinSetting,
355+
}
356+
357+
buf, err := json.Marshal(cmd)
348358
if err != nil {
349-
return fmt.Errorf("could not get FSAdmin to pin subvolume %s: %w", s.VolID, err)
359+
return fmt.Errorf("failed to marshal pin command for subvolume %s: %w", s.VolID, err)
350360
}
351-
_, err = fsa.PinSubVolume(s.FsName, s.VolID, pinType, pinSetting)
361+
362+
_, _, err = s.conn.MgrCommand([][]byte{buf})
352363
if err != nil {
353-
return fmt.Errorf("failed to pin subvolume %s in fs %s: %w", s.VolID, s.FsName, err)
364+
return fmt.Errorf("failed to pin subvolume %s in fs %s (group %s): %w",
365+
s.VolID, s.FsName, s.SubvolumeGroup, err)
354366
}
355367

356368
return nil

internal/util/connection.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,14 @@ func (cc *ClusterConnection) GetAddrs() (string, error) {
170170

171171
return cc.conn.GetAddrs()
172172
}
173+
174+
// MgrCommand sends a raw JSON-encoded command to the Ceph manager and returns
175+
// its output. It is used for manager commands that are not (yet) exposed by a
176+
// typed go-ceph helper.
177+
func (cc *ClusterConnection) MgrCommand(args [][]byte) ([]byte, string, error) {
178+
if cc.conn == nil {
179+
return nil, "", errors.New("cluster is not connected yet")
180+
}
181+
182+
return cc.conn.MgrCommand(args)
183+
}

0 commit comments

Comments
 (0)