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

fix the disk mount point querying #41

Merged
merged 2 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (pc *PrepareJvmCommand) insertPrepareRecord(prepareType string, flags ...st
}

func (pc *PrepareJvmCommand) handlePrepareResponse(uid string, cmd *cobra.Command, response *transport.Response) error {
response.Result = uid
if !response.Success {
GetDS().UpdatePreparationRecordByUid(uid, "Error", response.Err)
return response
Expand Down
16 changes: 14 additions & 2 deletions cli/query_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,24 @@ func (qdc *QueryDiskCommand) queryDiskInfo(command *cobra.Command, arg string) e
switch arg {
case MountPointArg:
response := exec.NewLocalChannel().Run(context.TODO(), "df",
fmt.Sprintf(`-h | grep -v 'Mounted on' | awk '{print $NF}' | tr '\n' ' '`))
fmt.Sprintf(`-h | awk 'NR!=1 {print $1","$NF}' | tr '\n' ' '`))
if !response.Success {
return response
}
disks := response.Result.(string)
command.Println(transport.ReturnSuccess(strings.Fields(disks)))
fields := strings.Fields(disks)
var result = make([]string, 0)
for _, disk := range fields {
// TODO Check the file system prefix, but should check the file system type
if strings.HasPrefix(disk, "/") {
arr := strings.Split(disk, ",")
if len(arr) < 2 {
continue
}
result = append(result, arr[1])
}
}
command.Println(transport.ReturnSuccess(result))
default:
return fmt.Errorf("the %s argument not found", arg)
}
Expand Down
8 changes: 4 additions & 4 deletions exec/os/bin/dropnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ func handleDropSpecifyPort(remotePort string, localPort string, channel *exec.Lo
}
if remotePort != "" {
response = channel.Run(ctx, "iptables",
fmt.Sprintf(`-A OUTPUT -p tcp --dport %s -j DROP`, localPort))
fmt.Sprintf(`-A OUTPUT -p tcp --dport %s -j DROP`, remotePort))
if !response.Success {
stopDropNet(localPort, remotePort)
printErrAndExit(response.Err)
}
response = channel.Run(ctx, "iptables",
fmt.Sprintf(`-A OUTPUT -p udp --dport %s -j DROP`, localPort))
fmt.Sprintf(`-A OUTPUT -p udp --dport %s -j DROP`, remotePort))
if !response.Success {
stopDropNet(localPort, remotePort)
printErrAndExit(response.Err)
Expand All @@ -80,7 +80,7 @@ func stopDropNet(localPort, remotePort string) {
channel.Run(ctx, "iptables", fmt.Sprintf(`-D INPUT -p udp --dport %s -j DROP`, localPort))
}
if remotePort != "" {
channel.Run(ctx, "iptables", fmt.Sprintf(`-D OUTPUT -p tcp --dport %s -j DROP`, localPort))
channel.Run(ctx, "iptables", fmt.Sprintf(`-D OUTPUT -p udp --dport %s -j DROP`, localPort))
channel.Run(ctx, "iptables", fmt.Sprintf(`-D OUTPUT -p tcp --dport %s -j DROP`, remotePort))
channel.Run(ctx, "iptables", fmt.Sprintf(`-D OUTPUT -p udp --dport %s -j DROP`, remotePort))
}
}
17 changes: 4 additions & 13 deletions exec/os/bin/filldisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,11 @@ func main() {
func startFill(mountPoint, size string) {
channel := exec.NewLocalChannel()
ctx := context.Background()
response := channel.Run(ctx, "df", fmt.Sprintf(`-h %s | grep -v 'Mounted on' | awk '{print $NF}'`, mountPoint))
if !response.Success {
printErrAndExit(response.Err)
}
path := strings.TrimSpace(response.Result.(string))
if len(path) == 0 {
printErrAndExit("cannot find disk mount point")
}
if path[len(path)-1:] != "/" {
path = path + "/"
if mountPoint == "" {
printErrAndExit("mount-point flag is empty")
}
// "if" arg in dd command is file system value, but "of" arg value is related to mount point
dataFile := fmt.Sprintf("%s%s", path, fillDataFile)
response = channel.Run(ctx, "dd", fmt.Sprintf(`if=/dev/zero of=%s bs=1b count=1 iflag=fullblock`, dataFile))
dataFile := fmt.Sprintf("%s%s", mountPoint, fillDataFile)
response := channel.Run(ctx, "dd", fmt.Sprintf(`if=/dev/zero of=%s bs=1b count=1 iflag=fullblock`, dataFile))
if !response.Success {
stopFill(mountPoint)
printErrAndExit(response.Err)
Expand Down