2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-22 01:51:51 +00:00
criu/Makefile

258 lines
5.5 KiB
Makefile
Raw Normal View History

#
# Common definitions
#
ifeq ($(strip $(V)),)
E = @echo
Q = @
else
E = @\#
Q =
endif
FIND := find
CSCOPE := cscope
TAGS := ctags
RM := rm
LD := ld
HEXDUMP := hexdump
CC := gcc
ECHO := echo
NM := nm
AWK := awk
SH := bash
MAKE := make
OBJCOPY := objcopy
# 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
LDARCH := i386:x86-64
endif
SRC_DIR ?= $(shell pwd)
ARCH_DIR := $(SRC_DIR)/arch/$(ARCH)
$(if $(wildcard $(ARCH_DIR)),,$(error "The architecture $(ARCH) isn't supported"))
CFLAGS += -I$(SRC_DIR)/include -I$(SRC_DIR)/pie -I$(ARCH_DIR) -iquote $(ARCH_DIR)/include -fno-strict-aliasing
LIBS := -lrt -lpthread -lprotobuf-c
DEFINES += -D_FILE_OFFSET_BITS=64
DEFINES += -D_GNU_SOURCE
WARNINGS := -Wall
ifneq ($(WERROR),0)
WARNINGS += -Werror
endif
ifeq ($(DEBUG),1)
DEFINES += -DCR_DEBUG
endif
ifeq ($(DEBUG),1)
DEFINES += -DCR_DEBUG
CFLAGS += -O0 -ggdb3
else
CFLAGS += -O2
endif
CFLAGS += $(WARNINGS) $(DEFINES)
SYSCALL-LIB = $(SRC_DIR)/arch/$(ARCH)/syscalls.o
PROTOBUF-LIB = $(SRC_DIR)/protobuf/protobuf-lib.o
export E Q CC ECHO MAKE CFLAGS LIBS ARCH DEFINES MAKEFLAGS SRC_DIR SYSCALL-LIB SH ARCH_DIR OBJCOPY LDARCH
PROGRAM := crtools
OBJS += parasite-syscall.o
OBJS += cr-restore.o
OBJS += crtools.o
OBJS += image.o
OBJS += net.o
OBJS += proc_parse.o
OBJS += cr-dump.o
OBJS += cr-show.o
OBJS += cr-check.o
OBJS += util.o
OBJS += util-net.o
OBJS += sysctl.o
OBJS += ptrace.o
OBJS += kcmp-ids.o
OBJS += rbtree.o
OBJS += log.o
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 22:12:03 +04:00
OBJS += libnetlink.o
OBJS += sockets.o
OBJS += sk-inet.o
OBJS += sk-tcp.o
OBJS += sk-unix.o
OBJS += sk-packet.o
OBJS += sk-queue.o
OBJS += files.o
OBJS += files-reg.o
OBJS += pipes.o
OBJS += fifo.o
files: Use sys_kcmp to find file descriptor duplicates v4 We switch generic-object-id concept with sys_kcmp approach, which implies changes of image format a bit (and since it's early time for project overall, we're allowed to). In short -- previously every file descriptor had an ID generated by a kernel and exported via procfs. If the appropriate file descriptors were the same objects in kernel memory -- the IDs did match up to bit. It allows us to figure out which files were actually the identical ones and should be restored in a special way. Once sys_kcmp system call was merged into the kernel, we've got a new opprotunity -- to use this syscall instead. The syscall basically compares kernel objects and returns ordered results suitable for objects sorting in a userspace. For us it means -- we treat every file descriptor as a combination of 'genid' and 'subid'. While 'genid' serves for fast comparison between fds, the 'subid' is kind of a second key, which guarantees uniqueness of genid+subid tuple over all file descritors found in a process (or group of processes). To be able to find and dump file descriptors in a single pass we collect every fd into a global rbtree, where (!) each node might become a root for a subtree as well. The main tree carries only non-equal genid. If we find genid which is already in tree, we need to make sure that it's either indeed a duplicate or not. For this we use sys_kcmp syscall and if we find that file descriptors are different -- we simply put new fd into a subtree. Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-02-28 18:27:28 +04:00
OBJS += file-ids.o
OBJS += namespaces.o
OBJS += uts_ns.o
OBJS += ipc_ns.o
OBJS += netfilter.o
OBJS += shmem.o
OBJS += eventfd.o
OBJS += eventpoll.o
OBJS += mount.o
OBJS += fsnotify.o
OBJS += signalfd.o
OBJS += pstree.o
OBJS += protobuf.o
tty: Add checkpoint/restore for unix terminals v6 Usually the PTYs represent a pair of links -- master peer and slave peer. Master peer must be opened before slave. Internally, when kernel creates master peer it also generates a slave interface in a form of /dev/pts/N, where N is that named pty "index". Master/slave connection unambiguously identified by this index. Still, one master can carry multiple slaves -- for example a user opens one master via /dev/ptmx and appropriate /dev/pts/N in sequence. The result will be the following master `- slave 1 `- slave 2 both slave will have same master index but different file descriptors. Still inside the kernel pty parameters are same for both slaves. Thus only one slave parameters should be restored, there is no need to carry all parameters for every slave peer we've found. Not yet addressed problems: - At moment of restore the master peer might be already closed for any reason so to resolve such problem we need to open a fake master peer with proper index and hook a slave on it, then we close master peer. - Need to figure out how to deal with ttys which have some data in buffers not yet flushed, at moment this data will be simply lost during c/r - Need to restore control terminals - Need to fetch tty flags such as exclusive/packet-mode, this can't be done without kernel patching [ avagin@: - ideas on contol terminals restore - overall code redesign and simplification ] v4: - drop redundant pid from dump_chrdev - make sure optional fown is passed on regular ptys - add a comments about zeroifying termios - get rid of redundant empty line in files.c v5 (by avagin@): - complete rework of tty image format, now we have two files -- tty.img and tty-info.img. The idea behind to reduce data being stored. v6 (by xemul@): - packet mode should be set to true in image, until properly fetched from the kernel - verify image data on retrieval Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> CC: Andrey Vagin <avagin@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:00:54 +04:00
OBJS += tty.o
OBJS += cr-exec.o
OBJS += cpu.o
OBJS += file-lock.o
OBJS += $(ARCH_DIR)/crtools.o
DEPS := $(patsubst %.o,%.d,$(OBJS))
.PHONY: all zdtm test rebuild clean distclean tags cscope \
docs help pie protobuf $(ARCH)
ifeq ($(GCOV),1)
%.o $(PROGRAM): override CFLAGS += --coverage
endif
all: pie
$(Q) $(MAKE) $(PROGRAM)
pie: protobuf $(ARCH)
$(Q) $(MAKE) -C pie/
protobuf:
$(Q) $(MAKE) -C protobuf/
$(ARCH):
$(Q) $(MAKE) -C arch/$(ARCH)/
%.o: %.c
$(E) " CC " $@
$(Q) $(CC) -c $(CFLAGS) $< -o $@
%.i: %.c
$(E) " CC " $@
$(Q) $(CC) -E $(CFLAGS) $< -o $@
%.s: %.c
$(E) " CC " $@
$(Q) $(CC) -S $(CFLAGS) -fverbose-asm $< -o $@
%.d: %.c
$(E) " DEP " $@
$(Q) $(CC) -M -MT $@ -MT $(patsubst %.d,%.o,$@) $(CFLAGS) $< -o $@
$(PROGRAM): $(OBJS) $(SYSCALL-LIB) $(PROTOBUF-LIB)
$(E) " LINK " $@
$(Q) $(CC) $(CFLAGS) $^ $(LIBS) -o $@
zdtm: all
$(Q) $(MAKE) -C test/zdtm all
test: zdtm
$(Q) $(SH) test/zdtm.sh
rebuild:
$(E) " FORCE-REBUILD"
$(Q) $(RM) -f ./*.o
$(Q) $(RM) -f ./*.d
$(Q) $(RM) -f ./protobuf/*.pb-c.c
$(Q) $(RM) -f ./protobuf/*.pb-c.h
$(Q) $(MAKE)
clean:
$(E) " CLEAN"
$(Q) $(RM) -f ./*.o
$(Q) $(RM) -f ./*.d
$(Q) $(RM) -f ./*.i
$(Q) $(RM) -f ./*.img
$(Q) $(RM) -f ./*.out
$(Q) $(RM) -f ./*.bin
$(Q) $(RM) -f ./$(PROGRAM)
$(Q) $(RM) -rf ./test/dump/
$(Q) $(RM) -f ./*.gcov ./*.gcda ./*.gcno
$(Q) $(RM) -rf ./gcov
$(Q) $(RM) -rf ./test/lib/
$(Q) $(RM) -rf ./test/lib64/
$(Q) $(MAKE) -C protobuf/ clean
$(Q) $(MAKE) -C arch/$(ARCH)/ clean
$(Q) $(MAKE) -C pie/ clean
$(Q) $(MAKE) -C test/zdtm cleandep
$(Q) $(MAKE) -C test/zdtm clean
$(Q) $(MAKE) -C test/zdtm cleanout
$(Q) $(MAKE) -C Documentation clean
distclean: clean
$(E) " DISTCLEAN"
$(Q) $(RM) -f ./tags
$(Q) $(RM) -f ./cscope*
tags:
$(E) " GEN" $@
$(Q) $(RM) -f tags
$(Q) $(FIND) . -name '*.[hcS]' ! -path './.*' -print | xargs ctags -a
cscope:
$(E) " GEN" $@
$(Q) $(FIND) . -name '*.[hcS]' ! -path './.*' -print > cscope.files
$(Q) $(CSCOPE) -bkqu
docs:
$(Q) $(MAKE) -s -C Documentation all
help:
$(E) ' Targets:'
$(E) ' all - Build all [*] targets'
$(E) ' * crtools - Build crtools'
$(E) ' zdtm - Build zdtm test-suite'
$(E) ' docs - Build documentation'
$(E) ' clean - Clean everything'
$(E) ' tags - Generate tags file (ctags)'
$(E) ' cscope - Generate cscope database'
$(E) ' rebuild - Force-rebuild of [*] targets'
$(E) ' test - Run zdtm test-suite'
gcov:
$(E) " GCOV"
$(Q) mkdir gcov && \
cd gcov && \
cp ../*.gcno ../*.c ../test/root/crtools/ && \
geninfo --no-checksum --output-filename crtools.l.info --no-recursion .. && \
geninfo --no-checksum --output-filename crtools.ns.info --no-recursion ../test/root/crtools && \
sed -i 's#/test/root/crtools##' crtools.ns.info && \
lcov -a crtools.l.info -a crtools.ns.info -o crtools.info && \
genhtml -o html crtools.info
deps-targets := $(OBJS) $(patsubst %.o,%.s,$(OBJS)) $(patsubst %.o,%.i,$(OBJS)) $(PROGRAM)
.DEFAULT_GOAL := all
ifneq ($(filter $(deps-targets), $(MAKECMDGOALS)),)
INCDEPS := 1
endif
ifeq ($(INCDEPS),1)
-include $(DEPS)
endif