|
6 | 6 | "fmt" |
7 | 7 | "os" |
8 | 8 | "path/filepath" |
| 9 | + "slices" |
9 | 10 | "strings" |
10 | 11 |
|
11 | 12 | "github.com/canonical/microceph/microceph/api/types" |
@@ -99,24 +100,15 @@ func GetCephFsAllVolumeMirrorMap(ctx context.Context) (MirrorPathMap, error) { |
99 | 100 |
|
100 | 101 | // GetCephFSSubvolumeMirrorState fetches the subvolume mirroring state for the CephFS volume. |
101 | 102 | 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 |
105 | 104 |
|
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)) |
112 | 106 | } |
113 | 107 |
|
114 | 108 | // GetCephFSMirrorPathState checks whether requested path is in mirror paths list |
115 | 109 | 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 |
120 | 112 | } |
121 | 113 |
|
122 | 114 | return StateDisabledReplication, nil |
@@ -149,29 +141,29 @@ func GetCephFsMirrorPeerStatus(ctx context.Context, adminSockPath string, volume |
149 | 141 | // FindCephFsMirrorAdminSockPath tests relevant admin socks and returns the correct one. |
150 | 142 | // Some CephFSMirror commands can only work with admin socket. |
151 | 143 | func FindCephFsMirrorAdminSockPath() (string, error) { |
152 | | - run_path := constants.GetPathConst().RunPath |
| 144 | + runPath := constants.GetPathConst().RunPath |
153 | 145 |
|
154 | | - open_sockets, err := os.ReadDir(run_path) |
| 146 | + openSockets, err := os.ReadDir(runPath) |
155 | 147 | 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) |
157 | 149 | return "", err |
158 | 150 | } |
159 | 151 |
|
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 { |
162 | 154 | logger.Debugf("MIRCFS: checking file : %s", socket.Name()) |
163 | 155 |
|
164 | 156 | if !strings.Contains(socket.Name(), "ceph-client.cephfs-mirror") { |
165 | 157 | continue |
166 | 158 | } |
167 | 159 |
|
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) |
170 | 162 | if err != nil { |
171 | 163 | continue |
172 | 164 | } |
173 | 165 |
|
174 | | - return full_sock_path, nil |
| 166 | + return fullSockPath, nil |
175 | 167 | } |
176 | 168 |
|
177 | 169 | return "", nil |
|
0 commit comments