[CRIU] Re: [PATCH 6/6] parasite: Add DPARASITE make option in debug sake

Pavel Emelyanov xemul at parallels.com
Tue Feb 14 09:23:17 EST 2012


On 02/14/2012 05:42 PM, Cyrill Gorcunov wrote:
> parasite is ugly beast and need own debug facility
> due to specifics it runs on.

I don't like compile-time debugging configuration. It's a nightmare
do debug the sockets.c file due to dprintk-s in it :(

That said -- I don't want more of this stuff creep into the code. Better
think on improving logging of the whole project. The best we can have is
-v N option to crtools code specifying the log-level of everybody. And
pr_err/pr_perror, pr_warning, pr_info, pr_debug helpers to print the stuff.

> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  Makefile   |    4 ++
>  parasite.c |   99 ++++++++++++++++++++++++++++++++++++++++-------------------
>  2 files changed, 71 insertions(+), 32 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index ad775db..91a7b21 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -16,6 +16,10 @@ ifeq ($(DEBUG),1)
>  	DEFINES += -DCR_DEBUG
>  endif
>  
> +ifeq ($(DPARASITE),1)
> +	DEFINES += -DPARASITE_DEBUG
> +endif
> +
>  WARNINGS	+= -Wall -Wno-unused
>  CFLAGS		+= $(WARNINGS) $(DEFINES)
>  
> diff --git a/parasite.c b/parasite.c
> index 3ec0f22..7866e99 100644
> --- a/parasite.c
> +++ b/parasite.c
> @@ -21,6 +21,18 @@
>  
>  #ifdef CONFIG_X86_64
>  
> +#ifdef PARASITE_DEBUG
> +# define dwrite_msg(msg)	sys_write_msg(msg)
> +# define dwrite_func_name()			\
> +	do {					\
> +		sys_write_msg(__func__);	\
> +		sys_write_msg("\n");		\
> +	} while (0)
> +#else
> +# define dwrite_msg(msg)
> +# define dwrite_func_name()
> +#endif
> +
>  static void __parasite_data *brk_start;
>  static void __parasite_data *brk_end;
>  static void __parasite_data *brk_tail;
> @@ -33,36 +45,6 @@ static int __parasite_data tsock = -1;
>  static unsigned char __parasite_data hex[] = "0123456789abcdef";
>  static unsigned char __parasite_data hexbuf[32];
>  
> -static void brk_init(void *brk)
> -{
> -	brk_start = brk_tail = brk;
> -	brk_end = brk_start + PARASITE_BRK_SIZE;
> -}
> -
> -static void *brk_alloc(unsigned long bytes)
> -{
> -	void *addr = NULL;
> -	if (brk_end > (brk_tail + bytes)) {
> -		addr	= brk_tail;
> -		brk_tail+= bytes;
> -	}
> -	return addr;
> -}
> -
> -static void brk_free(unsigned long bytes)
> -{
> -	if (brk_start >= (brk_tail - bytes))
> -		brk_tail -= bytes;
> -}
> -
> -static unsigned long builtin_strlen(char *str)
> -{
> -	unsigned long len = 0;
> -	while (*str++)
> -		len++;
> -	return len;
> -}
> -
>  static unsigned char *long2hex(unsigned long v)
>  {
>  	unsigned char *p = hexbuf;
> @@ -80,11 +62,43 @@ static unsigned char *long2hex(unsigned long v)
>  static void sys_write_msg(const char *msg)
>  {
>  	int size = 0;
> +
>  	while (msg[size])
>  		size++;
> +
>  	sys_write(logfd, msg, size);
>  }
>  
> +static void brk_init(void *brk)
> +{
> +	dwrite_func_name();
> +
> +	brk_start = brk_tail = brk;
> +	brk_end = brk_start + PARASITE_BRK_SIZE;
> +}
> +
> +static void *brk_alloc(unsigned long bytes)
> +{
> +	void *addr = NULL;
> +
> +	dwrite_func_name();
> +
> +	if (brk_end > (brk_tail + bytes)) {
> +		addr	= brk_tail;
> +		brk_tail+= bytes;
> +	}
> +
> +	return addr;
> +}
> +
> +static void brk_free(unsigned long bytes)
> +{
> +	dwrite_func_name();
> +
> +	if (brk_start >= (brk_tail - bytes))
> +		brk_tail -= bytes;
> +}
> +
>  static inline int should_dump_page(struct vma_entry *vmae, unsigned char mincore_flags)
>  {
>  #ifdef PAGE_ANON
> @@ -101,6 +115,8 @@ static int fd_pages[2] = { -1, -1 };
>  
>  static int dump_pages_init(parasite_status_t *st)
>  {
> +	dwrite_func_name();
> +
>  	fd_pages[PG_PRIV] = recv_fd(tsock);
>  	if (fd_pages[PG_PRIV] < 0)
>  		goto err;
> @@ -131,6 +147,8 @@ static int dump_pages(struct parasite_dump_pages_args *args)
>  	unsigned char *map;
>  	int ret = PARASITE_ERR_FAIL, fd;
>  
> +	dwrite_func_name();
> +
>  	args->nrpages_dumped = 0;
>  	prot_old = prot_new = 0;
>  
> @@ -246,8 +264,11 @@ err:
>  
>  static int dump_pages_fini(parasite_status_t *st)
>  {
> +	dwrite_func_name();
> +
>  	sys_close(fd_pages[PG_PRIV]);
>  	sys_close(fd_pages[PG_SHARED]);
> +
>  	return 0;
>  }
>  
> @@ -256,9 +277,10 @@ static int dump_sigact(parasite_status_t *st)
>  	rt_sigaction_t act;
>  	struct sa_entry e;
>  	int fd, sig;
> -
>  	int ret = PARASITE_ERR_FAIL;
>  
> +	dwrite_func_name();
> +
>  	fd = recv_fd(tsock);
>  	if (fd < 0)
>  		return fd;
> @@ -305,6 +327,8 @@ static int dump_itimer(int which, int fd, parasite_status_t *st)
>  	int ret;
>  	struct itimer_entry ie;
>  
> +	dwrite_func_name();
> +
>  	ret = sys_getitimer(which, &val);
>  	if (ret < 0) {
>  		sys_write_msg("getitimer failed\n");
> @@ -332,9 +356,10 @@ static int dump_itimers(parasite_status_t *st)
>  	rt_sigaction_t act;
>  	struct sa_entry e;
>  	int fd, sig;
> -
>  	int ret = PARASITE_ERR_FAIL;
>  
> +	dwrite_func_name();
> +
>  	fd = recv_fd(tsock);
>  	if (fd < 0)
>  		return fd;
> @@ -365,6 +390,8 @@ static int dump_misc(struct parasite_dump_misc *args)
>  {
>  	parasite_status_t *st = &args->status;
>  
> +	dwrite_func_name();
> +
>  	args->secbits = sys_prctl(PR_GET_SECUREBITS, 0, 0, 0, 0);
>  	args->brk = sys_brk(0);
>  
> @@ -376,6 +403,8 @@ static int init(struct parasite_init_args *args)
>  {
>  	int ret;
>  
> +	dwrite_func_name();
> +
>  	tsock = sys_socket(PF_UNIX, SOCK_DGRAM, 0);
>  	if (tsock < 0) {
>  		return -1;
> @@ -393,6 +422,8 @@ static int set_logfd()
>  {
>  	int ret;
>  
> +	dwrite_func_name();
> +
>  	ret = recv_fd(tsock);
>  	if (ret >= 0)
>  		logfd = ret;
> @@ -402,6 +433,8 @@ static int set_logfd()
>  
>  static int fini()
>  {
> +	dwrite_func_name();
> +
>  	if (logfd > STDFILENO_MAX)
>  		sys_close(logfd);
>  
> @@ -413,6 +446,8 @@ static int fini()
>  
>  static int __used parasite_service(unsigned long cmd, void *args, void *brk)
>  {
> +	dwrite_func_name();
> +
>  	brk_init(brk);
>  
>  	BUILD_BUG_ON(sizeof(struct parasite_dump_pages_args) > PARASITE_ARG_SIZE);



More information about the CRIU mailing list