[CRIU] Re: [RFC 0/4] Lets try PB again
    Pavel Emelyanov 
    xemul at parallels.com
       
    Fri Jul  6 08:21:25 EDT 2012
    
    
  
On 07/06/2012 04:10 PM, Cyrill Gorcunov wrote:
> Hi guys, here is another attempt for PB sake. Take a look,
> I'm converting reg-files now but wanted to share the code
> early.
> 
> 
I definitely like it :) Few questions a comments:
> @@ -206,13 +208,15 @@ int prepare_fd_pid(int pid, struct rst_info *rst_info)
>  	}
>  
>  	while (1) {
> -		struct fdinfo_entry e;
> +		FdinfoEntry *e;
>  
> -		ret = read_img_eof(fdinfo_fd, &e);
> +		ret = pb_read_eof(fdinfo_fd, &e, fdinfo_entry__unpack);
>  		if (ret <= 0)
>  			break;
>  
> -		ret = collect_fd(pid, &e, rst_info);
> +		ret = collect_fd(pid, e, rst_info);
> +		fdinfo_entry__free_unpacked(e, NULL);
> +
>  		if (ret < 0)
>  			break;
>  	}
Is there a way to unpack an object into a static buffer rather than
allocating one dynamically?
> -err:
> -	return ret;
> +	return pb_write(fdset_fd(cr_fdset, CR_FD_FDINFO), &e,
> +			fdinfo_entry__get_packed_size,
> +			fdinfo_entry__pack);
I'd appreciate if this looked like
pc_write(fd, &e, fdinfo_entry);
where __get_packet_size and __pack are concatenated inside the macro
> +#define pb_read_op(__fd, __obj_pptr, __unpack, __op)				\
> +({										\
> +	int __ret = -1;								\
> +	u32 __size;								\
> +	u8 *__buf;								\
> +										\
> +	__ret = read_img ##__op(__fd, &__size);					\
> +	if (__ret > 0) {							\
> +		__buf = xmalloc(__size);					\
> +		if (__buf) {							\
> +			__ret = read_img_buf(__fd, __buf, __size);		\
> +			if (__ret > 0)						\
> +				*(__obj_pptr) = __unpack(NULL, __size, __buf);	\
> +			xfree(__buf);						\
> +		} else								\
> +			__ret = -1;						\
> +	}									\
> +										\
> +	__ret;									\
> +})
> +#define pb_write(__fd, __obj_ptr, __get_pksize, __pack)				\
> +({										\
> +	u32 __size = __get_pksize(__obj_ptr);					\
> +	u8 *__buf = xmalloc(__size);						\
> +	int __ret = -1;								\
> +										\
> +	if (__buf) {								\
> +		__pack(__obj_ptr, __buf);					\
> +		__ret = write_img(__fd, &__size);				\
> +		if (!__ret)							\
> +			__ret = write_img_buf(__fd, __buf, __size);		\
> +		xfree(__buf);							\
> +	}									\
> +										\
> +	__ret;									\
> +})
That's too big for a macro. Turn it into a macro + outlined function.
    
    
More information about the CRIU
mailing list