mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-17 20:00:23 +00:00
parse ceph-fuse PID with regexp
This commit is contained in:
parent
3a0d048186
commit
b779009770
@ -17,11 +17,11 @@ limitations under the License.
|
|||||||
package cephfs
|
package cephfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -39,6 +39,8 @@ var (
|
|||||||
// maps a mountpoint to PID of its FUSE daemon
|
// maps a mountpoint to PID of its FUSE daemon
|
||||||
fusePidMap = make(map[string]int)
|
fusePidMap = make(map[string]int)
|
||||||
fusePidMapMtx sync.Mutex
|
fusePidMapMtx sync.Mutex
|
||||||
|
|
||||||
|
fusePidRx = regexp.MustCompile(`(?m)^ceph-fuse\[(.+)\]: starting fuse$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Load available ceph mounters installed on system into availableMounters
|
// Load available ceph mounters installed on system into availableMounters
|
||||||
@ -128,24 +130,12 @@ func mountFuse(mountPoint string, cr *credentials, volOptions *volumeOptions, vo
|
|||||||
// We need "starting fuse" meaning the mount is ok
|
// We need "starting fuse" meaning the mount is ok
|
||||||
// and PID of the ceph-fuse daemon for unmount
|
// and PID of the ceph-fuse daemon for unmount
|
||||||
|
|
||||||
idx := bytes.Index(stderr, []byte("starting fuse"))
|
match := fusePidRx.FindSubmatch(stderr)
|
||||||
if idx < 0 {
|
if len(match) != 2 {
|
||||||
return fmt.Errorf("ceph-fuse failed: %s", stderr)
|
return fmt.Errorf("ceph-fuse failed: %s", stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
pidParseErr := fmt.Errorf("failed to read FUSE daemon PID: %s", stderr)
|
pid, err := strconv.Atoi(string(match[1]))
|
||||||
|
|
||||||
pidEnd := bytes.LastIndexByte(stderr[:idx], ']')
|
|
||||||
if pidEnd < 0 {
|
|
||||||
return pidParseErr
|
|
||||||
}
|
|
||||||
|
|
||||||
pidStart := bytes.LastIndexByte(stderr[:pidEnd], '[')
|
|
||||||
if pidStart < 0 {
|
|
||||||
return pidParseErr
|
|
||||||
}
|
|
||||||
|
|
||||||
pid, err := strconv.Atoi(string(stderr[pidStart+1 : pidEnd]))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to parse FUSE daemon PID: %v", err)
|
return fmt.Errorf("failed to parse FUSE daemon PID: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user