mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-03 15:55:53 +00:00
zdtm: lib: add {read,write}_data helpers
Some tests expect that all the data will be handled in a single invocation of read/write system call. But it possible to have short read/write on a loaded system and this is not an error. Add helper functions that will reliably read/write the entire buffer. Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
committed by
Andrei Vagin
parent
39d65fba82
commit
a76ff847d6
@@ -40,3 +40,36 @@ int pipe_in2out(int infd, int outfd, uint8_t *buffer, int length)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int read_data(int fd, unsigned char *buf, int size)
|
||||||
|
{
|
||||||
|
int cur = 0;
|
||||||
|
int ret;
|
||||||
|
while (cur != size) {
|
||||||
|
ret = read(fd, buf + cur, size - cur);
|
||||||
|
if (ret <= 0) {
|
||||||
|
pr_perror("read(%d) = %d", size - cur, ret);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
cur += ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int write_data(int fd, const unsigned char *buf, int size)
|
||||||
|
{
|
||||||
|
int cur = 0;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
while (cur != size) {
|
||||||
|
ret = write(fd, buf + cur, size - cur);
|
||||||
|
if (ret <= 0) {
|
||||||
|
pr_perror("write(%d) = %d", size - cur, ret);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
cur += ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@@ -55,6 +55,8 @@ extern int datasum(const uint8_t *buffer, unsigned length, uint32_t *crc);
|
|||||||
/* streaming helpers */
|
/* streaming helpers */
|
||||||
extern int set_nonblock(int fd, int on);
|
extern int set_nonblock(int fd, int on);
|
||||||
extern int pipe_in2out(int infd, int outfd, uint8_t *buffer, int length);
|
extern int pipe_in2out(int infd, int outfd, uint8_t *buffer, int length);
|
||||||
|
extern int read_data(int fd, unsigned char *buf, int len);
|
||||||
|
extern int write_data(int fd, const unsigned char *buf, int len);
|
||||||
|
|
||||||
/* command line args */
|
/* command line args */
|
||||||
struct long_opt {
|
struct long_opt {
|
||||||
|
Reference in New Issue
Block a user