rbd: support nbd on euler or arm

Signed-off-by: muxuelan <muxuelan@cmss.chinamobile.com>
This commit is contained in:
muxuelan 2023-11-28 19:57:01 +08:00 committed by mergify[bot]
parent 6f0d9a5d59
commit 4f04748c87

View File

@ -143,11 +143,23 @@ type detachRBDImageArgs struct {
// getDeviceList queries rbd about mapped devices and returns a list of deviceInfo // getDeviceList queries rbd about mapped devices and returns a list of deviceInfo
// It will selectively list devices mapped using krbd or nbd as specified by accessType. // It will selectively list devices mapped using krbd or nbd as specified by accessType.
func getDeviceList(ctx context.Context, accessType string) ([]deviceInfo, error) { func getDeviceList(ctx context.Context, accessType string) ([]deviceInfo, error) {
var (
stdout string
err error
)
if accessType == accessTypeKRbd {
// rbd device list --format json --device-type [krbd|nbd] // rbd device list --format json --device-type [krbd|nbd]
stdout, _, err := util.ExecCommand(ctx, rbd, "device", "list", "--format="+"json", "--device-type", accessType) stdout, _, err = util.ExecCommand(ctx, rbd, "device", "list", "--format=json", "--device-type", accessType)
if err != nil { if err != nil {
return nil, fmt.Errorf("error getting device list from rbd for devices of type (%s): %w", accessType, err) return nil, fmt.Errorf("error getting device list from rbd for devices of type (%s): %w", accessType, err)
} }
} else {
stdout, _, err = util.ExecCommand(ctx, "rbd-nbd", "list-mapped", "--format=json")
if err != nil {
return nil, fmt.Errorf("error getting device list from rbd-nbd for devices of type (%s): %w", accessType, err)
}
}
var devices []*rbdDeviceInfo var devices []*rbdDeviceInfo
err = json.Unmarshal([]byte(stdout), &devices) err = json.Unmarshal([]byte(stdout), &devices)
@ -352,29 +364,27 @@ func attachRBDImage(ctx context.Context, volOptions *rbdVolume, device string, c
} }
func appendNbdDeviceTypeAndOptions(cmdArgs []string, userOptions, cookie string) []string { func appendNbdDeviceTypeAndOptions(cmdArgs []string, userOptions, cookie string) []string {
cmdArgs = append(cmdArgs, "--device-type", accessTypeNbd)
isUnmap := CheckSliceContains(cmdArgs, "unmap") isUnmap := CheckSliceContains(cmdArgs, "unmap")
if !isUnmap { if !isUnmap {
if !strings.Contains(userOptions, useNbdNetlink) { if !strings.Contains(userOptions, useNbdNetlink) {
cmdArgs = append(cmdArgs, "--options", useNbdNetlink) cmdArgs = append(cmdArgs, "--"+useNbdNetlink)
} }
if !strings.Contains(userOptions, setNbdReattach) { if !strings.Contains(userOptions, setNbdReattach) {
cmdArgs = append(cmdArgs, "--options", fmt.Sprintf("%s=%d", setNbdReattach, defaultNbdReAttachTimeout)) cmdArgs = append(cmdArgs, fmt.Sprintf("--%s=%d", setNbdReattach, defaultNbdReAttachTimeout))
} }
if !strings.Contains(userOptions, setNbdIOTimeout) { if !strings.Contains(userOptions, setNbdIOTimeout) {
cmdArgs = append(cmdArgs, "--options", fmt.Sprintf("%s=%d", setNbdIOTimeout, defaultNbdIOTimeout)) cmdArgs = append(cmdArgs, fmt.Sprintf("--%s=%d", setNbdIOTimeout, defaultNbdIOTimeout))
} }
if hasNBDCookieSupport { if hasNBDCookieSupport {
cmdArgs = append(cmdArgs, "--options", fmt.Sprintf("cookie=%s", cookie)) cmdArgs = append(cmdArgs, fmt.Sprintf("--cookie=%s", cookie))
} }
} }
if userOptions != "" { if userOptions != "" {
// userOptions is appended after, possibly overriding the above // userOptions is appended after, possibly overriding the above
// default options. // default options.
cmdArgs = append(cmdArgs, "--options", userOptions) cmdArgs = append(cmdArgs, "--"+userOptions)
} }
return cmdArgs return cmdArgs
@ -436,13 +446,13 @@ func createPath(ctx context.Context, volOpt *rbdVolume, device string, cr *util.
if volOpt.Mounter == rbdTonbd && hasNBD { if volOpt.Mounter == rbdTonbd && hasNBD {
isNbd = true isNbd = true
} }
cli := rbd
if isNbd { if isNbd {
cli = rbdNbdMounter
mapArgs = append(mapArgs, "--log-file", mapArgs = append(mapArgs, "--log-file",
getCephClientLogFileName(volOpt.VolID, volOpt.LogDir, "rbd-nbd")) getCephClientLogFileName(volOpt.VolID, volOpt.LogDir, "rbd-nbd"))
} }
cli := rbd
if device != "" { if device != "" {
// TODO: use rbd cli for attach/detach in the future // TODO: use rbd cli for attach/detach in the future
cli = rbdNbdMounter cli = rbdNbdMounter
@ -576,7 +586,13 @@ func detachRBDImageOrDeviceSpec(
unmapArgs = appendKRbdDeviceTypeAndOptions(unmapArgs, dArgs.unmapOptions) unmapArgs = appendKRbdDeviceTypeAndOptions(unmapArgs, dArgs.unmapOptions)
} }
_, stderr, err := util.ExecCommand(ctx, rbd, unmapArgs...) var err error
var stderr string
if dArgs.isNbd {
_, stderr, err = util.ExecCommand(ctx, rbdTonbd, unmapArgs...)
} else {
_, stderr, err = util.ExecCommand(ctx, rbd, unmapArgs...)
}
if err != nil { if err != nil {
// Messages for krbd and nbd differ, hence checking either of them for missing mapping // Messages for krbd and nbd differ, hence checking either of them for missing mapping
// This is not applicable when a device path is passed in // This is not applicable when a device path is passed in