[CRIU] [PATCH 07/18] sk-unix: Use native types in unix_sk_info

Kirill Tkhai ktkhai at virtuozzo.com
Mon Apr 10 01:43:40 PDT 2017


I'm not insist on u8:1, but in general there may be a profit:

$ cat a.c
#include <stdio.h>
#include <stdint.h>

struct A {
        uint32_t a;
        uint8_t b:1;
        uint8_t c:1;
        uint8_t d:1;
        uint8_t e:1;
        uint8_t f:1;
};

struct B {
        uint32_t a;
        uint8_t b;
        uint8_t c;
        uint8_t d;
        uint8_t e;
        uint8_t f;
};


main(void)
{
        printf("%u %u\n", sizeof(struct A), sizeof(struct B));

}

$ ./a.out

8 12

On 10.04.2017 01:28, Cyrill Gorcunov wrote:
> I think using native types is better here -- no need
> for bitfields used solely as a flags and u32 for not
> known profit as well.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  criu/sk-unix.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/criu/sk-unix.c b/criu/sk-unix.c
> index 54d6d8d8ce0b..0bd6f3670324 100644
> --- a/criu/sk-unix.c
> +++ b/criu/sk-unix.c
> @@ -792,9 +792,9 @@ struct unix_sk_info {
>  	 * once although it may be open by more than one tid. This is the peer
>  	 * that should do the queueing.
>  	 */
> -	u32			queuer;
> -	u8			bound:1;
> -	u8			listen:1;
> +	unsigned int		queuer;
> +	bool			bound;
> +	bool			listen;
>  };
>  
>  #define USK_PAIR_MASTER		0x1
> @@ -1076,7 +1076,7 @@ static int bind_unix_sk(int sk, struct unix_sk_info *ui)
>  	}
>  
>  	if (ui->ue->state != TCP_LISTEN) {
> -		ui->bound = 1;
> +		ui->bound = true;
>  		wake_connected_sockets(ui);
>  	}
>  
> @@ -1274,7 +1274,7 @@ static int open_unixsk_standalone(struct unix_sk_info *ui, int *new_fd)
>  			pr_perror("Can't make usk listen");
>  			return -1;
>  		}
> -		ui->listen = 1;
> +		ui->listen = true;
>  		wake_connected_sockets(ui);
>  	}
>  
> @@ -1398,8 +1398,8 @@ static int collect_one_unixsk(void *o, ProtobufCMessage *base, struct cr_img *i)
>  
>  	ui->queuer = 0;
>  	ui->peer = NULL;
> -	ui->bound = 0;
> -	ui->listen = 0;
> +	ui->bound = false;
> +	ui->listen = false;
>  	INIT_LIST_HEAD(&ui->connected);
>  	INIT_LIST_HEAD(&ui->node);
>  	ui->flags = 0;
> 


More information about the CRIU mailing list