mirror of https://github.com/xemu-project/xemu.git
qemu-nbd: pass structure into nbd_client_thread instead of plain char*
We are going to pass additional flag inside next patch. Signed-off-by: Denis V. Lunev <den@openvz.org> CC: Eric Blake <eblake@redhat.com> CC: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> CC: <qemu-stable@nongnu.org> Message-ID: <20230717145544.194786-2-den@openvz.org> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
2c27fdc7a6
commit
03b6762144
19
qemu-nbd.c
19
qemu-nbd.c
|
@ -272,9 +272,13 @@ static void *show_parts(void *arg)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct NbdClientOpts {
|
||||||
|
char *device;
|
||||||
|
};
|
||||||
|
|
||||||
static void *nbd_client_thread(void *arg)
|
static void *nbd_client_thread(void *arg)
|
||||||
{
|
{
|
||||||
char *device = arg;
|
struct NbdClientOpts *opts = arg;
|
||||||
NBDExportInfo info = { .request_sizes = false, .name = g_strdup("") };
|
NBDExportInfo info = { .request_sizes = false, .name = g_strdup("") };
|
||||||
QIOChannelSocket *sioc;
|
QIOChannelSocket *sioc;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
|
@ -298,10 +302,10 @@ static void *nbd_client_thread(void *arg)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = open(device, O_RDWR);
|
fd = open(opts->device, O_RDWR);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
/* Linux-only, we can use %m in printf. */
|
/* Linux-only, we can use %m in printf. */
|
||||||
error_report("Failed to open %s: %m", device);
|
error_report("Failed to open %s: %m", opts->device);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,11 +315,11 @@ static void *nbd_client_thread(void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* update partition table */
|
/* update partition table */
|
||||||
pthread_create(&show_parts_thread, NULL, show_parts, device);
|
pthread_create(&show_parts_thread, NULL, show_parts, opts->device);
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
fprintf(stderr, "NBD device %s is now connected to %s\n",
|
fprintf(stderr, "NBD device %s is now connected to %s\n",
|
||||||
device, srcpath);
|
opts->device, srcpath);
|
||||||
} else {
|
} else {
|
||||||
/* Close stderr so that the qemu-nbd process exits. */
|
/* Close stderr so that the qemu-nbd process exits. */
|
||||||
dup2(STDOUT_FILENO, STDERR_FILENO);
|
dup2(STDOUT_FILENO, STDERR_FILENO);
|
||||||
|
@ -1125,8 +1129,11 @@ int main(int argc, char **argv)
|
||||||
if (device) {
|
if (device) {
|
||||||
#if HAVE_NBD_DEVICE
|
#if HAVE_NBD_DEVICE
|
||||||
int ret;
|
int ret;
|
||||||
|
struct NbdClientOpts opts = {
|
||||||
|
.device = device,
|
||||||
|
};
|
||||||
|
|
||||||
ret = pthread_create(&client_thread, NULL, nbd_client_thread, device);
|
ret = pthread_create(&client_thread, NULL, nbd_client_thread, &opts);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
error_report("Failed to create client thread: %s", strerror(ret));
|
error_report("Failed to create client thread: %s", strerror(ret));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
Loading…
Reference in New Issue