Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

fs inspector support for namazu container #162

Merged
merged 1 commit into from
Aug 2, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ explorePolicy = "random"
# Default: true
enableProcInspector = true
procWatchInterval = "1s"
# Default: true (for volumes (`-v /foo:/bar`))
enableFSInspector = true
```
For other parameters, please refer to [`config.go`](nmz/util/config/config.go) and [`randompolicy.go`](nmz/explorepolicy/random/randompolicy.go).

Expand Down
7 changes: 6 additions & 1 deletion nmz/cli/container/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ func Run(args []string) int {
return 1
}

dockerOpt, err = container.StartNamazuRoutinesPre(dockerOpt, nmzCfg)
if err != nil {
panic(log.Critical(err))
}

client, err := ns.NewDockerClient()
if err != nil {
panic(log.Critical(err))
Expand All @@ -113,7 +118,7 @@ func Run(args []string) int {
log.Info("Namazu container is running the container in background, but Namazu itself keeps running in foreground.")
}

err = container.StartNamazuRoutines(c, nmzCfg)
err = container.StartNamazuRoutinesPost(c, nmzCfg)
if err != nil {
panic(log.Critical(err))
}
Expand Down
38 changes: 38 additions & 0 deletions nmz/container/fs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (C) 2015 Nippon Telegraph and Telephone Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package container

import (
"github.com/osrg/hookfs/hookfs"
"github.com/osrg/namazu/nmz/inspector/fs"
ocutil "github.com/osrg/namazu/nmz/util/orchestrator"
)

func ServeFSInspector(orig, mountpoint string) error {
hook := fs.FilesystemInspector{
OrchestratorURL: ocutil.LocalOrchestratorURL,
EntityID: "_namazu_container_fs_inspector_" + orig,
}
fs, err := hookfs.NewHookFs(orig, mountpoint, &hook)
if err != nil {
return err
}
if err = fs.Serve(); err != nil {
return err
}
// NOTREACHED
return nil
}
32 changes: 31 additions & 1 deletion nmz/container/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ package container

import (
"fmt"
"io/ioutil"
"strings"

log "github.com/cihub/seelog"
docker "github.com/fsouza/go-dockerclient"
"github.com/osrg/namazu/nmz/util/config"
)

func StartNamazuRoutines(c *docker.Container, cfg config.Config) error {
func StartNamazuRoutinesPre(dockerOpt *docker.CreateContainerOptions, cfg config.Config) (*docker.CreateContainerOptions, error) {
log.Debugf("Starting Orchestrator")
go func() {
oerr := StartOrchestrator(cfg)
Expand All @@ -32,6 +34,34 @@ func StartNamazuRoutines(c *docker.Container, cfg config.Config) error {
}
}()

var newBinds []string
for _, bind := range dockerOpt.HostConfig.Binds {
split := strings.Split(bind, ":")
if len(split) != 2 {
return dockerOpt, fmt.Errorf("bind is expected to be <foo>:<bar>, got %s", bind)
}
bindSrc, bindDst := split[0], split[1]
mountpoint, err := ioutil.TempDir("", "nmz-container-fs-inspector")
if err != nil {
return dockerOpt, err
}
if cfg.GetBool("container.enableFSInspector") {
log.Debugf("Starting Filesystem Inspector for %s (on %s)", bindSrc, mountpoint)
log.Warnf("Please run `fusermount -i %s` manually on exit", mountpoint)
go func() {
ierr := ServeFSInspector(bindSrc, mountpoint)
if ierr != nil {
panic(log.Critical(ierr))
}
}()
}
newBinds = append(newBinds, fmt.Sprintf("%s:%s", mountpoint, bindDst))
}
dockerOpt.HostConfig.Binds = newBinds
return dockerOpt, nil
}

func StartNamazuRoutinesPost(c *docker.Container, cfg config.Config) error {
if cfg.GetBool("container.enableEthernetInspector") {
nfqNum := cfg.GetInt("container.ethernetNFQNumber")
if nfqNum <= 0 {
Expand Down
1 change: 1 addition & 0 deletions nmz/util/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func New() Config {
cfg.SetDefault("container", map[string]interface{}{
"enableEthernetInspector": false,
"enableProcInspector": true,
"enableFSInspector": true,
"ethernetNFQNumber": 42,
"procWatchInterval": time.Second,
})
Expand Down