Skip to content

Commit d4fbae6

Browse files
fix: subvolume path construction
Signed-off-by: Utkarsh Bhatt <utkarsh.bhatt@canonical.com>
1 parent 018efd5 commit d4fbae6

3 files changed

Lines changed: 22 additions & 29 deletions

File tree

microceph/ceph/cephfs_mirror.go

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"path/filepath"
9+
"slices"
910
"strings"
1011

1112
"github.com/canonical/microceph/microceph/api/types"
@@ -99,24 +100,15 @@ func GetCephFsAllVolumeMirrorMap(ctx context.Context) (MirrorPathMap, error) {
99100

100101
// GetCephFSSubvolumeMirrorState fetches the subvolume mirroring state for the CephFS volume.
101102
func GetCephFSSubvolumeMirrorState(rh *CephfsReplicationHandler) (ReplicationState, error) {
102-
subvolumegroup := rh.Request.SubvolumeGroup
103-
subvolume := rh.Request.Subvolume
104-
volume := rh.Request.Volume
103+
r := rh.Request
105104

106-
subvolumePath, err := GetCephFSSubvolumePath(volume, subvolumegroup, subvolume)
107-
if err != nil {
108-
return StateInvalidReplication, err
109-
}
110-
111-
return GetCephFSMirrorPathState(rh, subvolumePath)
105+
return GetCephFSMirrorPathState(rh, GetCephFSSubvolumePath(r.SubvolumeGroup, r.Subvolume))
112106
}
113107

114108
// GetCephFSMirrorPathState checks whether requested path is in mirror paths list
115109
func GetCephFSMirrorPathState(rh *CephfsReplicationHandler, path string) (ReplicationState, error) {
116-
for _, mirrorPath := range rh.MirrorList {
117-
if path == mirrorPath {
118-
return StateEnabledReplication, nil
119-
}
110+
if slices.Contains(rh.MirrorList, path) {
111+
return StateEnabledReplication, nil
120112
}
121113

122114
return StateDisabledReplication, nil
@@ -149,29 +141,29 @@ func GetCephFsMirrorPeerStatus(ctx context.Context, adminSockPath string, volume
149141
// FindCephFsMirrorAdminSockPath tests relevant admin socks and returns the correct one.
150142
// Some CephFSMirror commands can only work with admin socket.
151143
func FindCephFsMirrorAdminSockPath() (string, error) {
152-
run_path := constants.GetPathConst().RunPath
144+
runPath := constants.GetPathConst().RunPath
153145

154-
open_sockets, err := os.ReadDir(run_path)
146+
openSockets, err := os.ReadDir(runPath)
155147
if err != nil {
156-
logger.Errorf("failed to read run path %s: %v", run_path, err)
148+
logger.Errorf("failed to read run path %s: %v", runPath, err)
157149
return "", err
158150
}
159151

160-
logger.Debugf("MIRCFS: found %d open sockets in %s", len(open_sockets), run_path)
161-
for _, socket := range open_sockets {
152+
logger.Debugf("MIRCFS: found %d open sockets in %s", len(openSockets), runPath)
153+
for _, socket := range openSockets {
162154
logger.Debugf("MIRCFS: checking file : %s", socket.Name())
163155

164156
if !strings.Contains(socket.Name(), "ceph-client.cephfs-mirror") {
165157
continue
166158
}
167159

168-
full_sock_path := filepath.Join(run_path, socket.Name())
169-
err = CheckFsMirrorHelperCommands(full_sock_path)
160+
fullSockPath := filepath.Join(runPath, socket.Name())
161+
err = CheckFsMirrorHelperCommands(fullSockPath)
170162
if err != nil {
171163
continue
172164
}
173165

174-
return full_sock_path, nil
166+
return fullSockPath, nil
175167
}
176168

177169
return "", nil

microceph/ceph/cephfs_volume.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ func CephFsSubvolumePathDeconstruct(path string) (subvolumegroup string, subvolu
6666
return "", "", fmt.Errorf("invalid CephFS subvolume path: %s", path)
6767
}
6868

69+
logger.Debugf("FSVOL: %+v", parts)
70+
6971
subvolumegroup = parts[CephFsSubVolumeGroupIndex]
7072
subvolume = parts[CephFsSubVolumeIndex]
7173

@@ -170,14 +172,13 @@ func GetCephFSSubvolumes(volume Volume, subvolumegroup string) ([]Subvolume, err
170172
}
171173

172174
// GetCephFSSubvolumePath retrieves the full path of a specified subvolume within a CephFS volume and subvolume group.
173-
func GetCephFSSubvolumePath(volume string, subvolumegroup string, subvolume string) (string, error) {
174-
var args []string
175-
175+
func GetCephFSSubvolumePath(subvolumegroup string, subvolume string) string {
176+
var retval string
176177
if len(subvolumegroup) != 0 {
177-
args = []string{"fs", "subvolume", "getpath", volume, subvolume, subvolumegroup}
178+
retval = fmt.Sprintf("/volumes/%s/%s/", subvolumegroup, subvolume)
178179
} else {
179-
args = []string{"fs", "subvolume", "getpath", volume, subvolume}
180+
retval = fmt.Sprintf("/volumes/_nogroup/%s/", subvolume)
180181
}
181182

182-
return cephRun(args...)
183+
return retval
183184
}

microceph/ceph/replication_cephfs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (rh *CephfsReplicationHandler) DisableHandler(ctx context.Context, args ...
160160
case types.CephfsResourceVolume:
161161
err = disableCephFSVolumeMirror(ctx, rh.Request, rh.MirrorList)
162162
case types.CephfsResourceSubvolume:
163-
err = cephFSSnapshotMirrorRemovePath(ctx, rh.Request.Volume, fmt.Sprintf("/volumes/%s/%s", rh.Request.SubvolumeGroup, rh.Request.Subvolume))
163+
err = cephFSSnapshotMirrorRemovePath(ctx, rh.Request.Volume, GetCephFSSubvolumePath(rh.Request.SubvolumeGroup, rh.Request.Subvolume))
164164
case types.CephfsResourceDirectory:
165165
err = cephFSSnapshotMirrorRemovePath(ctx, rh.Request.Volume, rh.Request.DirPath)
166166
default:
@@ -405,7 +405,7 @@ func enableCephFSResourceMirror(ctx context.Context, request types.CephfsReplica
405405

406406
switch request.ResourceType {
407407
case types.CephfsResourceSubvolume:
408-
resourcePath = fmt.Sprintf("/volumes/%s/%s", request.SubvolumeGroup, request.Subvolume)
408+
resourcePath = GetCephFSSubvolumePath(request.SubvolumeGroup, request.Subvolume)
409409
case types.CephfsResourceDirectory:
410410
resourcePath = request.DirPath
411411
default:

0 commit comments

Comments
 (0)