cephfs: upgrading mount syntax

The old syntax is almost deprecated,and there are reasons to upgrade it
- old syntax is lack of fsid(critical for debugging and observability)
- mds_namespace is deprecated, it might be inappropriate to continue using it
- kernel will try new syntax first and then the old one, it's a waste

Signed-off-by: mageekchiu <qiukang@mail.ustc.edu.cn>
This commit is contained in:
mageekchiu 2025-02-27 21:15:05 +08:00
parent 0cfb2b012b
commit b8d3b21fef
2 changed files with 45 additions and 11 deletions

View File

@ -72,25 +72,24 @@ func (m *kernelMounter) mountKernel(
m.needsModprobe = false
}
fsID, err := volOptions.GetFSID()
if err != nil {
return fmt.Errorf("failed to get fsID, stop mounting: %w", err)
}
args := []string{
"-t", "ceph",
fmt.Sprintf("%s:%s", volOptions.Monitors, volOptions.RootPath),
fmt.Sprintf("%s@%s.%s=%s", cr.ID, fsID, volOptions.FsName, volOptions.RootPath),
mountPoint,
}
optionsStr := fmt.Sprintf("name=%s,secretfile=%s", cr.ID, cr.KeyFile)
mdsNamespace := ""
if volOptions.FsName != "" {
mdsNamespace = "mds_namespace=" + volOptions.FsName
}
optionsStr = util.MountOptionsAdd(optionsStr, mdsNamespace, volOptions.KernelMountOptions, netDev)
optionsStr := fmt.Sprintf("mon_addr=%s,secretfile=%s", strings.ReplaceAll(volOptions.Monitors, ",", "/"), cr.KeyFile)
optionsStr = util.MountOptionsAdd(optionsStr, volOptions.KernelMountOptions, netDev)
args = append(args, "-o", optionsStr)
var (
stderr string
err error
)
var stderr string
if volOptions.NetNamespaceFilePath != "" {
_, stderr, err = util.ExecuteCommandWithNSEnter(ctx, volOptions.NetNamespaceFilePath, "mount", args[:]...)

View File

@ -101,6 +101,19 @@ func (vo *VolumeOptions) Destroy() {
}
}
func (vo *VolumeOptions) GetFSID() (string, error) {
if vo.conn == nil {
return "", errors.New("cluster not connected yet")
}
fsID, err := vo.conn.GetFSID()
if err != nil {
return "", err
}
return fsID, nil
}
func validateNonEmptyField(field, fieldName string) error {
if field == "" {
return fmt.Errorf("parameter '%s' cannot be empty", fieldName)
@ -680,6 +693,17 @@ func NewVolumeOptionsFromMonitorList(
opts.BackingSnapshot = true
}
cr, err := util.NewAdminCredentials(secrets)
if err != nil {
return nil, nil, err
}
defer cr.DeleteCredentials()
err = opts.Connect(cr)
if err != nil {
return nil, nil, err
}
return &opts, &vid, nil
}
@ -759,6 +783,17 @@ func NewVolumeOptionsFromStaticVolume(
opts.BackingSnapshot = true
}
cr, err := util.NewAdminCredentials(secrets)
if err != nil {
return nil, nil, err
}
defer cr.DeleteCredentials()
err = opts.Connect(cr)
if err != nil {
return nil, nil, err
}
return &opts, &vid, nil
}