Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cephfs: upgrading mount syntax #5090

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions internal/cephfs/mounter/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,24 @@ func (m *kernelMounter) mountKernel(
m.needsModprobe = false
}

fsID, err := volOptions.GetFSID()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't we use existing GetFSID() instead?

Suggested change
fsID, err := volOptions.GetFSID()
fsID, err := volOptions.GetConnection().GetFSID()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

volOptions.GetConnection() can return nil, so it is not really safe. A new GetFSID() would prevent any incorrect usage, now, and possibly in the future.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think the checking is needed, Connect and Destroy do the checking too.
And I've squashed the commits.

Copy link
Contributor

@iPraveenParihar iPraveenParihar Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

volOptions.GetConnection() can return nil, so it is not really safe. A new GetFSID() would prevent any incorrect usage, now, and possibly in the future.

when volOptions struct is created, we make sure we have the connection set. There is no way GetConnection() could return nil.

IMO, GetConnection() should be handling the nil check, or the GetConnection() caller should check for nil and proceed.

as we have similar usage at some places. for example -

ioctx, err := volOptions.GetConnection().GetIoctx(volOptions.MetadataPool)
if err != nil {
log.ErrorLog(ctx, "Failed to create ioctx: %s", err)
return err
}
defer ioctx.Destroy()

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[:]...)
Expand Down
13 changes: 13 additions & 0 deletions internal/cephfs/store/volumeoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down