0.33c : parallelize start/stop of jails up to gMaxThreads
This commit is contained in:
parent
6f9bb504be
commit
7575da794e
@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
gVersion = "0.33b"
|
gVersion = "0.33c"
|
||||||
|
|
||||||
// TODO : Get from $jail_zpool/defaults.json
|
// TODO : Get from $jail_zpool/defaults.json
|
||||||
MIN_DYN_DEVFS_RULESET = 1000
|
MIN_DYN_DEVFS_RULESET = 1000
|
||||||
|
48
cmd/start.go
48
cmd/start.go
@ -4,6 +4,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"errors"
|
"errors"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -1055,6 +1056,9 @@ func cleanAfterStartCrash() {
|
|||||||
// Start all jails with boot=true, in priority order
|
// Start all jails with boot=true, in priority order
|
||||||
func StartJailsAtBoot() {
|
func StartJailsAtBoot() {
|
||||||
var startList []Jail
|
var startList []Jail
|
||||||
|
var wg *sync.WaitGroup
|
||||||
|
var curThNb int
|
||||||
|
var curPri int
|
||||||
|
|
||||||
// Get boot enabled jails
|
// Get boot enabled jails
|
||||||
for _, j := range gJails {
|
for _, j := range gJails {
|
||||||
@ -1072,11 +1076,51 @@ func StartJailsAtBoot() {
|
|||||||
}
|
}
|
||||||
JailsOrderedBy(fct.Interface().(jailLessFunc)).Sort(startList)
|
JailsOrderedBy(fct.Interface().(jailLessFunc)).Sort(startList)
|
||||||
|
|
||||||
for _, j := range startList {
|
wg = new(sync.WaitGroup)
|
||||||
|
curThNb = 0
|
||||||
|
for i, j := range startList {
|
||||||
jFullName := fmt.Sprintf("%s/%s", j.Datastore, j.Name)
|
jFullName := fmt.Sprintf("%s/%s", j.Datastore, j.Name)
|
||||||
log.Debugf("Starting %s with priority %s\n", jFullName, j.Config.Priority)
|
log.Debugf("Starting %s with priority %s\n", jFullName, j.Config.Priority)
|
||||||
StartJail([]string{jFullName})
|
jailPri, err := strconv.Atoi(j.Config.Priority)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("Invalid format for Priority (Jail %s)\n", jFullName))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curThNb >= gMaxThreads || i == 0) {
|
||||||
|
// FIXME : Use a pool instead of waiting for all threads to run a new one
|
||||||
|
wg.Wait()
|
||||||
|
curThNb = 0
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
curThNb++
|
||||||
|
curPri = jailPri
|
||||||
|
go func(jailFullName string) {
|
||||||
|
defer wg.Done()
|
||||||
|
StartJail([]string{jailFullName})
|
||||||
|
}(jFullName)
|
||||||
|
} else {
|
||||||
|
if (curPri == jailPri) {
|
||||||
|
wg.Add(1)
|
||||||
|
curThNb++
|
||||||
|
go func(jailFullName string) {
|
||||||
|
defer wg.Done()
|
||||||
|
StartJail([]string{jailFullName})
|
||||||
|
}(jFullName)
|
||||||
|
} else {
|
||||||
|
wg.Wait()
|
||||||
|
curThNb = 0
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
curThNb++
|
||||||
|
curPri = jailPri
|
||||||
|
go func(jailFullName string) {
|
||||||
|
defer wg.Done()
|
||||||
|
StartJail([]string{jailFullName})
|
||||||
|
}(jFullName)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
66
cmd/stop.go
66
cmd/stop.go
@ -4,6 +4,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"fmt"
|
"fmt"
|
||||||
//"log"
|
//"log"
|
||||||
|
"sync"
|
||||||
"errors"
|
"errors"
|
||||||
"regexp"
|
"regexp"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -169,8 +170,13 @@ func stopJail(jail *Jail) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stop all running jails by reverse priority
|
// Stop all running jails by reverse priority
|
||||||
|
// Parallelize up to gMaxThreads
|
||||||
|
// Only parallelize same priority level jails
|
||||||
func StopAllRunningJails() {
|
func StopAllRunningJails() {
|
||||||
var stopList []Jail
|
var stopList []Jail
|
||||||
|
var wg *sync.WaitGroup
|
||||||
|
var curThNb int
|
||||||
|
var curPri int
|
||||||
|
|
||||||
// Get boot enabled jails
|
// Get boot enabled jails
|
||||||
for _, j := range gJails {
|
for _, j := range gJails {
|
||||||
@ -187,12 +193,53 @@ func StopAllRunningJails() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
JailsOrderedBy(fct.Interface().(jailLessFunc)).Sort(stopList)
|
JailsOrderedBy(fct.Interface().(jailLessFunc)).Sort(stopList)
|
||||||
|
|
||||||
for _, j := range stopList {
|
|
||||||
|
wg = new(sync.WaitGroup)
|
||||||
|
curThNb = 0
|
||||||
|
for i, j := range stopList {
|
||||||
jFullName := fmt.Sprintf("%s/%s", j.Datastore, j.Name)
|
jFullName := fmt.Sprintf("%s/%s", j.Datastore, j.Name)
|
||||||
log.Debugf("Stopping %s with priority %s\n", jFullName, j.Config.Priority)
|
log.Debugf("Stopping %s with priority %s\n", jFullName, j.Config.Priority)
|
||||||
StopJail([]string{jFullName})
|
jailPri, err := strconv.Atoi(j.Config.Priority)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("Invalid format for Priority (Jail %s)\n", jFullName))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curThNb >= gMaxThreads || i == 0) {
|
||||||
|
// FIXME : Use a pool instead of waiting for all threads to run a new one
|
||||||
|
wg.Wait()
|
||||||
|
curThNb = 0
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
curThNb++
|
||||||
|
curPri = jailPri
|
||||||
|
go func(jailFullName string) {
|
||||||
|
defer wg.Done()
|
||||||
|
StopJail([]string{jailFullName})
|
||||||
|
}(jFullName)
|
||||||
|
} else {
|
||||||
|
if (curPri == jailPri) {
|
||||||
|
wg.Add(1)
|
||||||
|
curThNb++
|
||||||
|
go func(jailFullName string) {
|
||||||
|
defer wg.Done()
|
||||||
|
StopJail([]string{jailFullName})
|
||||||
|
}(jFullName)
|
||||||
|
} else {
|
||||||
|
wg.Wait()
|
||||||
|
curThNb = 0
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
curThNb++
|
||||||
|
curPri = jailPri
|
||||||
|
go func(jailFullName string) {
|
||||||
|
defer wg.Done()
|
||||||
|
StopJail([]string{jailFullName})
|
||||||
|
}(jFullName)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -243,8 +290,16 @@ func StopJail(args []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
cvers = strings.TrimRight(cvers, "\n")
|
cvers = strings.TrimRight(cvers, "\n")
|
||||||
fmt.Sprintf(cj.Config.Release, cvers)
|
|
||||||
cj.ConfigUpdated = true
|
//fmt.Sprintf(cj.Config.Release, cvers)
|
||||||
|
//cj.Config.Release = cvers
|
||||||
|
//cj.ConfigUpdated = true
|
||||||
|
|
||||||
|
// This is working in this context, but value is not available in WriteConfigToDisk context :/
|
||||||
|
setStructFieldValue(cj, "Config.Release", cvers)
|
||||||
|
fmt.Printf("DEBUG: release was set, now is : %s\n", cj.Config.Release)
|
||||||
|
|
||||||
|
// We need to get the real Config object, not a copy of it
|
||||||
|
|
||||||
out, err := executeCommand(fmt.Sprintf("rctl jail:%s", cj.InternalName))
|
out, err := executeCommand(fmt.Sprintf("rctl jail:%s", cj.InternalName))
|
||||||
if err == nil && len(out) > 0 {
|
if err == nil && len(out) > 0 {
|
||||||
@ -410,6 +465,7 @@ func StopJail(args []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("DEBUG: release = %s\n", cj.Config.Release)
|
||||||
WriteConfigToDisk(cj.Name, false, true)
|
WriteConfigToDisk(cj.Name, false, true)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,8 @@ import (
|
|||||||
const (
|
const (
|
||||||
ipv4re = `[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}`
|
ipv4re = `[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}`
|
||||||
ifconfigipv4re = `inet[[:space:]](` + ipv4re + `)`
|
ifconfigipv4re = `inet[[:space:]](` + ipv4re + `)`
|
||||||
|
// Maximum thread qty for start/stop
|
||||||
|
gMaxThreads = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
Loading…
Reference in New Issue
Block a user