qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

socket_scm_helper: Accept fd directly

This gives us more freedom about the fd that is passed to qemu, allowing
us to e.g. pass sockets.

Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>

authored by

Max Reitz and committed by
Kevin Wolf
d35172b4 5fcbdf50

+18 -11
+18 -11
tests/qemu-iotests/socket_scm_helper.c
··· 60 60 } 61 61 62 62 /* Convert string to fd number. */ 63 - static int get_fd_num(const char *fd_str) 63 + static int get_fd_num(const char *fd_str, bool silent) 64 64 { 65 65 int sock; 66 66 char *err; ··· 68 68 errno = 0; 69 69 sock = strtol(fd_str, &err, 10); 70 70 if (errno) { 71 - fprintf(stderr, "Failed in strtol for socket fd, reason: %s\n", 72 - strerror(errno)); 71 + if (!silent) { 72 + fprintf(stderr, "Failed in strtol for socket fd, reason: %s\n", 73 + strerror(errno)); 74 + } 73 75 return -1; 74 76 } 75 77 if (!*fd_str || *err || sock < 0) { 76 - fprintf(stderr, "bad numerical value for socket fd '%s'\n", fd_str); 78 + if (!silent) { 79 + fprintf(stderr, "bad numerical value for socket fd '%s'\n", fd_str); 80 + } 77 81 return -1; 78 82 } 79 83 ··· 104 108 } 105 109 106 110 107 - sock = get_fd_num(argv[1]); 111 + sock = get_fd_num(argv[1], false); 108 112 if (sock < 0) { 109 113 return EXIT_FAILURE; 110 114 } 111 115 112 - /* Now only open a file in readonly mode for test purpose. If more precise 113 - control is needed, use python script in file operation, which is 114 - supposed to fork and exec this program. */ 115 - fd = open(argv[2], O_RDONLY); 116 + fd = get_fd_num(argv[2], true); 116 117 if (fd < 0) { 117 - fprintf(stderr, "Failed to open file '%s'\n", argv[2]); 118 - return EXIT_FAILURE; 118 + /* Now only open a file in readonly mode for test purpose. If more 119 + precise control is needed, use python script in file operation, which 120 + is supposed to fork and exec this program. */ 121 + fd = open(argv[2], O_RDONLY); 122 + if (fd < 0) { 123 + fprintf(stderr, "Failed to open file '%s'\n", argv[2]); 124 + return EXIT_FAILURE; 125 + } 119 126 } 120 127 121 128 ret = send_fd(sock, fd);