Commit 943df7d6 authored by Pavel Emelyanov's avatar Pavel Emelyanov

page-server: Tune up the encode/decode helpers

Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent ac05c73a
...@@ -48,11 +48,11 @@ static void psi2iovec(struct page_server_iov *ps, struct iovec *iov) ...@@ -48,11 +48,11 @@ static void psi2iovec(struct page_server_iov *ps, struct iovec *iov)
#define PS_TYPE_PID (1) #define PS_TYPE_PID (1)
#define PS_TYPE_SHMEM (2) #define PS_TYPE_SHMEM (2)
/* /*
* XXX: When adding new types here check decode_pm_type for legacy * XXX: When adding new types here check decode_pm for legacy
* numbers that can be met from older CRIUs * numbers that can be met from older CRIUs
*/ */
static inline u64 encode_pm_id(int type, long id) static inline u64 encode_pm(int type, long id)
{ {
if (type == CR_FD_PAGEMAP) if (type == CR_FD_PAGEMAP)
type = PS_TYPE_PID; type = PS_TYPE_PID;
...@@ -66,7 +66,7 @@ static inline u64 encode_pm_id(int type, long id) ...@@ -66,7 +66,7 @@ static inline u64 encode_pm_id(int type, long id)
return ((u64)id) << PS_TYPE_BITS | type; return ((u64)id) << PS_TYPE_BITS | type;
} }
static int decode_pm_type(u64 dst_id) static int decode_pm(u64 dst_id, long *id)
{ {
int type; int type;
...@@ -83,6 +83,7 @@ static int decode_pm_type(u64 dst_id) ...@@ -83,6 +83,7 @@ static int decode_pm_type(u64 dst_id)
case 16: /* 1.2 */ case 16: /* 1.2 */
case 17: /* 1.0 1.1 */ case 17: /* 1.0 1.1 */
case PS_TYPE_PID: case PS_TYPE_PID:
*id = dst_id >> PS_TYPE_BITS;
type = CR_FD_PAGEMAP; type = CR_FD_PAGEMAP;
break; break;
case 27: /* 1.3 */ case 27: /* 1.3 */
...@@ -92,6 +93,7 @@ static int decode_pm_type(u64 dst_id) ...@@ -92,6 +93,7 @@ static int decode_pm_type(u64 dst_id)
case 33: /* 1.0 1.1 3.1 3.2 */ case 33: /* 1.0 1.1 3.1 3.2 */
case 34: /* 2.* 3.0 */ case 34: /* 2.* 3.0 */
case PS_TYPE_SHMEM: case PS_TYPE_SHMEM:
*id = dst_id >> PS_TYPE_BITS;
type = CR_FD_SHMEM_PAGEMAP; type = CR_FD_SHMEM_PAGEMAP;
break; break;
default: default:
...@@ -102,11 +104,6 @@ static int decode_pm_type(u64 dst_id) ...@@ -102,11 +104,6 @@ static int decode_pm_type(u64 dst_id)
return type; return type;
} }
static long decode_pm_id(u64 dst_id)
{
return (long)(dst_id >> PS_TYPE_BITS);
}
static inline int send_psi(int sk, u32 cmd, u32 nr_pages, u64 vaddr, u64 dst_id) static inline int send_psi(int sk, u32 cmd, u32 nr_pages, u64 vaddr, u64 dst_id)
{ {
struct page_server_iov pi = { struct page_server_iov pi = {
...@@ -171,7 +168,7 @@ static int open_page_server_xfer(struct page_xfer *xfer, int fd_type, long id) ...@@ -171,7 +168,7 @@ static int open_page_server_xfer(struct page_xfer *xfer, int fd_type, long id)
xfer->write_pages = write_pages_to_server; xfer->write_pages = write_pages_to_server;
xfer->write_hole = write_hole_to_server; xfer->write_hole = write_hole_to_server;
xfer->close = close_server_xfer; xfer->close = close_server_xfer;
xfer->dst_id = encode_pm_id(fd_type, id); xfer->dst_id = encode_pm(fd_type, id);
xfer->parent = NULL; xfer->parent = NULL;
if (send_psi(xfer->sk, PS_IOV_OPEN2, 0, 0, xfer->dst_id)) { if (send_psi(xfer->sk, PS_IOV_OPEN2, 0, 0, xfer->dst_id)) {
...@@ -479,9 +476,7 @@ static int page_server_check_parent(int sk, struct page_server_iov *pi) ...@@ -479,9 +476,7 @@ static int page_server_check_parent(int sk, struct page_server_iov *pi)
int type, ret; int type, ret;
long id; long id;
type = decode_pm_type(pi->dst_id); type = decode_pm(pi->dst_id, &id);
id = decode_pm_id(pi->dst_id);
if (type == -1) { if (type == -1) {
pr_err("Unknown pagemap type received\n"); pr_err("Unknown pagemap type received\n");
return -1; return -1;
...@@ -505,7 +500,7 @@ static int check_parent_server_xfer(int fd_type, long id) ...@@ -505,7 +500,7 @@ static int check_parent_server_xfer(int fd_type, long id)
int has_parent; int has_parent;
pi.cmd = PS_IOV_PARENT; pi.cmd = PS_IOV_PARENT;
pi.dst_id = encode_pm_id(fd_type, id); pi.dst_id = encode_pm(fd_type, id);
if (write(page_server_sk, &pi, sizeof(pi)) != sizeof(pi)) { if (write(page_server_sk, &pi, sizeof(pi)) != sizeof(pi)) {
pr_perror("Can't write to page server"); pr_perror("Can't write to page server");
...@@ -552,8 +547,7 @@ static int page_server_open(int sk, struct page_server_iov *pi) ...@@ -552,8 +547,7 @@ static int page_server_open(int sk, struct page_server_iov *pi)
int type; int type;
long id; long id;
type = decode_pm_type(pi->dst_id); type = decode_pm(pi->dst_id, &id);
id = decode_pm_id(pi->dst_id);
if (type == -1) { if (type == -1) {
pr_err("Unknown pagemap type received\n"); pr_err("Unknown pagemap type received\n");
return -1; return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment