Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

implement (re)store of proxy's state #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ LOCALSTATEDIR := /var

SOURCES := $(shell find . 2>&1 | grep -E '.*\.(c|h|go)$$')
PROXY_SOCKET := $(LOCALSTATEDIR)/run/clear-containers/proxy.sock
STORE_STATE_DIR := $(LOCALSTATEDIR)/run/clear-containers/proxy/

DESCRIBE := $(shell git describe 2> /dev/null || true)
DESCRIBE_DIRTY := $(if $(shell git status --porcelain --untracked-files=no 2> /dev/null),${DESCRIBE}-dirty,${DESCRIBE})
Expand Down Expand Up @@ -53,7 +54,7 @@ all: cc-proxy $(UNIT_FILES)

cc-proxy: $(SOURCES) Makefile
$(QUIET_GOBUILD)go build -i -o $@ -ldflags \
"-X main.DefaultSocketPath=$(PROXY_SOCKET) -X main.Version=$(VERSION)"
"-X main.DefaultSocketPath=$(PROXY_SOCKET) -X main.Version=$(VERSION) -X main.storeStateDir=$(STORE_STATE_DIR)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you could fix the other variables as they don't need to be upper case since they don't need to be exported.

Copy link
Author

@dvoytik dvoytik Oct 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like not to mix other refactoring in one patch if you don't mind. But if you insist, I could write a separate patch and make it as a part of this PR though.


#
# Tests
Expand Down
42 changes: 34 additions & 8 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@ func registerVM(data []byte, userData interface{}, response *handlerResponse) {

client.vm = vm

if err := storeVMState(vm); err != nil {
logContID(vm.containerID).Errorf(
"couldn't store a VM state: %v", err)
}

if err := storeProxyState(proxy); err != nil {
proxyLog.Errorf("couldn't store proxy's state: %v", err)
}

if proxyKSM != nil {
proxyKSM.kick()
}
Expand Down Expand Up @@ -300,6 +309,15 @@ func attachVM(data []byte, userData interface{}, response *handlerResponse) {
client.log.Infof("AttachVM(containerId=%s)", payload.ContainerID)

client.vm = vm

if err := storeVMState(vm); err != nil {
logContID(vm.containerID).Errorf(
"couldn't store a VM state: %v", err)
}

if err := storeProxyState(proxy); err != nil {
proxyLog.Errorf("couldn't store proxy's state: %v", err)
}
}

// "UnregisterVM"
Expand Down Expand Up @@ -330,9 +348,10 @@ func unregisterVM(data []byte, userData interface{}, response *handlerResponse)

client.log.Info("UnregisterVM()")

proxy.Lock()
delete(proxy.vms, vm.containerID)
proxy.Unlock()
if err := delVMAndState(proxy, vm); err != nil {
logContID(payload.ContainerID).Warnf("Error deleting state: %v",
err)
}

client.vm = nil
}
Expand Down Expand Up @@ -627,12 +646,19 @@ func (proxy *proxy) init() error {
// Force a coredump + full stacktrace on internal error
debug.SetTraceback("crash")

// flags
proxy.enableVMConsole = logrus.GetLevel() == logrus.DebugLevel
stateIsRestored, err := restoreAllState(proxy)
if err != nil {
proxyLog.Errorf("Restoring failed: %v", err)
}

if !stateIsRestored {
// flags
proxy.enableVMConsole = logrus.GetLevel() == logrus.DebugLevel

// Open the proxy socket
if proxy.socketPath, err = getSocketPath(); err != nil {
return fmt.Errorf("couldn't get a rigth socket path: %v", err)
// Open the proxy socket
if proxy.socketPath, err = getSocketPath(); err != nil {
return fmt.Errorf("couldn't get a right socket path: %v", err)
}
}
fds := listenFds()

Expand Down
Loading