criu/Makefile
Pavel Emelyanov c5eb61e866 Unix sockets initial support
Currently it can only work with stream sockets, which have no skbs in queues
(listening or established -- both work OK).

The cpt part uses the sock_diag engine that was merged to Dave recently to
collect sockets. Then it dumps sockets by checking the filesystem ID of a
failed-to-open through /proc/pid/fd descriptors (sockets do not allow for
such tricks with opens through proc) against SOCKFS_TYPE.

The rst part is more tricky. Listen sockets are just restored, this is simple.
Connected sockets are restored like this:

1. One end establishes a listening anon socket at the desired descriptor;
2. The other end just creates a socket at the desired descriptor;
3. All sockets, that are to be connect()-ed call connect. Unix sockets
   do not block connect() till the accept() time and thus we continue with...
4. ... all listening sockets call accept() and ... dup2 the new fd into the
   accepting end.

There's a problem with this approach -- socket names are not preserved, but
looking into our OpenVZ implementation I think this is OK for existing apps.

What should be done next is:

1. Need to merge the file IDs patches in our tree and make Andrey to
   support files sharing. This will solve the

	sk = socket();
	fork();

   case. Currently it simply doesn't work :(

2. Need to add support for DGRAM sockets -- I wrote comment how to do it
   in the can_dump_unix_sk()

3. Need to add support for in-flight connections

4. Implement support for UDP sockets (quite simple)

5. Implement support for listening TCP sockets (also not very complex)

6. Implement support for connected TCP scokets (hard one, Tejun's patches are not
   very good for this from my POV)

Cyrill, plz, apply this patch and put the above descriptions onto wiki docs (do we
have the plans page yet?).

Andrey, plz, take care of unix sockets tests in zdtm. Most likely it won't work till
you do the shared files support for sockets.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-26 23:25:04 +04:00

156 lines
3.2 KiB
Makefile

ifeq ($(strip $(V)),)
E = @echo
Q = @
else
E = @\#
Q =
endif
export E Q
FIND := find
CSCOPE := cscope
TAGS := ctags
RM := rm
LD := ld
HEXDUMP := hexdump
CC := gcc
ECHO := echo
NM := nm
AWK := awk
SH := sh
MAKE := make
CFLAGS += -I./include
CFLAGS += -O0 -ggdb3
LIBS += -lrt -lpthread
# Additional ARCH settings for x86
ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
-e s/arm.*/arm/ -e s/sa110/arm/ \
-e s/s390x/s390/ -e s/parisc64/parisc/ \
-e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
-e s/sh[234].*/sh/ )
uname_M := $(shell uname -m | sed -e s/i.86/i386/)
ifeq ($(uname_M),i386)
ARCH := x86
DEFINES += -DCONFIG_X86_32
endif
ifeq ($(uname_M),x86_64)
ARCH := x86
DEFINES += -DCONFIG_X86_64
endif
DEFINES += -D_FILE_OFFSET_BITS=64
DEFINES += -D_GNU_SOURCE
ifneq ($(WERROR),0)
WARNINGS += -Werror
endif
WARNINGS += -Wall -Wno-unused
CFLAGS += $(WARNINGS) $(DEFINES)
PROGRAM := crtools
export CC ECHO MAKE CFLAGS LIBS ARCH DEFINES
all: $(PROGRAM)
OBJS += crtools.o
OBJS += parasite-syscall.o
OBJS += cr-dump.o
OBJS += cr-restore.o
OBJS += cr-show.o
OBJS += util.o
OBJS += ptrace.o
OBJS += restorer.o
OBJS += log.o
OBJS += libnetlink.o
OBJS += sockets.o
DEPS := $(patsubst %.o,%.d,$(OBJS))
HEADERS := $(shell find ./include/* -name '*.h' -print)
OBJS-BLOB += parasite.o
DEPS-BLOB += $(patsubst %.o,%.d,$(OBJS-BLOB))
SRCS-BLOB += $(patsubst %.o,%.c,$(OBJS-BLOB))
HEAD-BLOB-GEN := $(patsubst %.o,%-blob.h,$(OBJS-BLOB))
HEAD-BIN := $(patsubst %.o,%.bin,$(OBJS-BLOB))
HEAD-LDS := $(patsubst %.o,%.lds.S,$(OBJS-BLOB))
HEAD-IDS := $(patsubst %.h,%_h__,$(subst -,_,$(HEAD-BLOB)))
$(OBJS-BLOB): $(SRCS-BLOB)
$(E) " CC " $@
$(Q) $(CC) -c $(CFLAGS) -fpic $< -o $@
$(HEAD-BIN): $(OBJS-BLOB) $(HEAD-LDS)
$(E) " GEN " $@
$(Q) $(LD) -T $(patsubst %.bin,%.lds.S,$@) $< -o $@
$(HEAD-BLOB-GEN): $(HEAD-BIN) $(DEPS-BLOB)
$(E) " GEN " $@
$(Q) $(SH) gen-offsets.sh \
parasite_h__ \
parasite_blob_offset__ \
parasite_blob \
$(OBJS-BLOB) \
$(HEAD-BIN) > parasite-blob.h
$(Q) sync
$(OBJS): $(DEPS) $(HEAD-BLOB-GEN)
%.o: %.c
$(E) " CC " $@
$(Q) $(CC) -c $(CFLAGS) $< -o $@
$(PROGRAM): $(OBJS)
$(E) " LINK " $@
$(Q) $(CC) $(CFLAGS) $(OBJS) $(LIBS) -o $@
$(DEPS): $(HEAD-BLOB-GEN) $(HEADERS)
%.d: %.c
$(Q) $(CC) -M -MT $(patsubst %.d,%.o,$@) $(CFLAGS) $< -o $@
$(DEPS-BLOB): $(SRCS-BLOB)
$(Q) $(CC) -M -MT $(patsubst %.d,%.o,$@) $(CFLAGS) $< -o $@
test:
$(Q) $(MAKE) -C test all
.PHONY: test
rebuild:
$(E) " FORCE-REBUILD"
$(Q) $(RM) -f ./*.o
$(Q) $(RM) -f ./*.d
$(Q) $(MAKE)
.PHONY: rebuild
clean:
$(E) " CLEAN"
$(Q) $(RM) -f ./*.o
$(Q) $(RM) -f ./*.d
$(Q) $(RM) -f ./*.img
$(Q) $(RM) -f ./*.out
$(Q) $(RM) -f ./*.bin
$(Q) $(RM) -f ./tags
$(Q) $(RM) -f ./cscope*
$(Q) $(RM) -f ./$(PROGRAM)
$(Q) $(RM) -f ./$(HEAD-BLOB-GEN)
$(Q) $(MAKE) -C test clean
.PHONY: clean
tags:
$(E) " GEN" $@
$(Q) $(RM) -f tags
$(Q) $(FIND) . -name '*.[hcS]' -print | xargs ctags -a
.PHONY: tags
cscope:
$(E) " GEN" $@
$(Q) $(FIND) . -name '*.[hcS]' -print > cscope.files
$(Q) $(CSCOPE) -bkqu
.PHONY: cscope