* [Qemu-devel] [PULL 0/3] NBD pull request for 2012-02-17
@ 2012-02-17 11:43 Paolo Bonzini
2012-02-17 11:43 ` [Qemu-devel] [PATCH 1/3] do not chdir(/) in qemu-nbd before opening all files Paolo Bonzini
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Paolo Bonzini @ 2012-02-17 11:43 UTC (permalink / raw)
To: qemu-devel
Anthony,
The following changes since commit 9de36b1a7cf61aa8be365f13c81668b3e19fbc7f:
Make -machine/-enable-kvm options merge into a single list (2012-02-17 09:10:13 +0100)
are available in the git repository at:
git://github.com/bonzini/qemu.git nbd-for-anthony
Michael Tokarev (1):
do not chdir(/) in qemu-nbd before opening all files
Paolo Bonzini (2):
open /dev/nbd in nbd_client_thread
nbd: add git tree to MAINTAINERS
MAINTAINERS | 1 +
qemu-nbd.c | 42 +++++++++++++++++++++++-------------------
2 files changed, 24 insertions(+), 19 deletions(-)
--
1.7.7.6
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 1/3] do not chdir(/) in qemu-nbd before opening all files
2012-02-17 11:43 [Qemu-devel] [PULL 0/3] NBD pull request for 2012-02-17 Paolo Bonzini
@ 2012-02-17 11:43 ` Paolo Bonzini
2012-02-17 11:43 ` [Qemu-devel] [PATCH 2/3] open /dev/nbd in nbd_client_thread Paolo Bonzini
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2012-02-17 11:43 UTC (permalink / raw)
To: qemu-devel; +Cc: Michael Tokarev
From: Michael Tokarev <mjt@tls.msk.ru>
When qemu-nbd becomes a daemon it calls daemon(3) with
nochdir=0, so daemon(3) changes current directory to /.
But at this time, qemu-nbd did not open any user-specified
files yet, so by changing current directory, all non-absolute
paths becomes wrong. The solution is to pass nochdir=1 to
daemon(3) function, and to chdir("/") after all init has
been performed, before entering the main loop, -- just like
a good daemon should do.
This patch is applicable for -stable.
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
qemu-nbd.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/qemu-nbd.c b/qemu-nbd.c
index eb61c33..e189cf8 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -429,7 +429,7 @@ int main(int argc, char **argv)
pid = fork();
if (pid == 0) {
close(stderr_fd[0]);
- ret = qemu_daemon(0, 0);
+ ret = qemu_daemon(1, 0);
/* Temporarily redirect stderr to the parent's pipe... */
dup2(stderr_fd[1], STDERR_FILENO);
@@ -527,6 +527,12 @@ int main(int argc, char **argv)
qemu_set_fd_handler2(fd, nbd_can_accept, nbd_accept, NULL,
(void *)(uintptr_t)fd);
+ /* now when the initialization is (almost) complete, chdir("/")
+ * to free any busy filesystems */
+ if (chdir("/") < 0) {
+ err(EXIT_FAILURE, "Could not chdir to root directory");
+ }
+
do {
main_loop_wait(false);
} while (!sigterm_reported && (persistent || !nbd_started || nb_fds > 0));
--
1.7.7.6
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 2/3] open /dev/nbd in nbd_client_thread
2012-02-17 11:43 [Qemu-devel] [PULL 0/3] NBD pull request for 2012-02-17 Paolo Bonzini
2012-02-17 11:43 ` [Qemu-devel] [PATCH 1/3] do not chdir(/) in qemu-nbd before opening all files Paolo Bonzini
@ 2012-02-17 11:43 ` Paolo Bonzini
2012-02-17 11:43 ` [Qemu-devel] [PATCH 3/3] nbd: add git tree to MAINTAINERS Paolo Bonzini
2012-02-17 13:53 ` [Qemu-devel] [PULL 0/3] NBD pull request for 2012-02-17 Anthony Liguori
3 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2012-02-17 11:43 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
qemu-nbd.c | 34 ++++++++++++++++------------------
1 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/qemu-nbd.c b/qemu-nbd.c
index e189cf8..d4e7041 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -37,7 +37,6 @@
static NBDExport *exp;
static int verbose;
-static char *device;
static char *srcpath;
static char *sockpath;
static bool sigterm_reported;
@@ -178,6 +177,7 @@ static void termsig_handler(int signum)
static void *show_parts(void *arg)
{
+ char *device = arg;
int nbd;
/* linux just needs an open() to trigger
@@ -194,11 +194,11 @@ static void *show_parts(void *arg)
static void *nbd_client_thread(void *arg)
{
- int fd = *(int *)arg;
+ char *device = arg;
off_t size;
size_t blocksize;
uint32_t nbdflags;
- int sock;
+ int fd, sock;
int ret;
pthread_t show_parts_thread;
@@ -213,13 +213,20 @@ static void *nbd_client_thread(void *arg)
goto out;
}
+ fd = open(device, O_RDWR);
+ if (fd == -1) {
+ /* Linux-only, we can use %m in printf. */
+ fprintf(stderr, "Failed to open %s: %m", device);
+ goto out;
+ }
+
ret = nbd_init(fd, sock, nbdflags, size, blocksize);
if (ret == -1) {
goto out;
}
/* update partition table */
- pthread_create(&show_parts_thread, NULL, show_parts, NULL);
+ pthread_create(&show_parts_thread, NULL, show_parts, device);
if (verbose) {
fprintf(stderr, "NBD device %s is now connected to %s\n",
@@ -273,6 +280,7 @@ int main(int argc, char **argv)
uint32_t nbdflags = 0;
bool disconnect = false;
const char *bindto = "0.0.0.0";
+ char *device = NULL;
int port = NBD_DEFAULT_PORT;
off_t fd_size;
const char *sopt = "hVb:o:p:rsnP:c:dvk:e:t";
@@ -466,19 +474,9 @@ int main(int argc, char **argv)
}
}
- if (device) {
- /* Open before spawning new threads. In the future, we may
- * drop privileges after opening.
- */
- fd = open(device, O_RDWR);
- if (fd == -1) {
- err(EXIT_FAILURE, "Failed to open %s", device);
- }
-
- if (sockpath == NULL) {
- sockpath = g_malloc(128);
- snprintf(sockpath, 128, SOCKET_PATH, basename(device));
- }
+ if (device != NULL && sockpath == NULL) {
+ sockpath = g_malloc(128);
+ snprintf(sockpath, 128, SOCKET_PATH, basename(device));
}
bdrv_init();
@@ -513,7 +511,7 @@ int main(int argc, char **argv)
if (device) {
int ret;
- ret = pthread_create(&client_thread, NULL, nbd_client_thread, &fd);
+ ret = pthread_create(&client_thread, NULL, nbd_client_thread, device);
if (ret != 0) {
errx(EXIT_FAILURE, "Failed to create client thread: %s",
strerror(ret));
--
1.7.7.6
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 3/3] nbd: add git tree to MAINTAINERS
2012-02-17 11:43 [Qemu-devel] [PULL 0/3] NBD pull request for 2012-02-17 Paolo Bonzini
2012-02-17 11:43 ` [Qemu-devel] [PATCH 1/3] do not chdir(/) in qemu-nbd before opening all files Paolo Bonzini
2012-02-17 11:43 ` [Qemu-devel] [PATCH 2/3] open /dev/nbd in nbd_client_thread Paolo Bonzini
@ 2012-02-17 11:43 ` Paolo Bonzini
2012-02-17 13:53 ` [Qemu-devel] [PULL 0/3] NBD pull request for 2012-02-17 Anthony Liguori
3 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2012-02-17 11:43 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
MAINTAINERS | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/MAINTAINERS b/MAINTAINERS
index 173e893..6a9c981 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -510,6 +510,7 @@ S: Odd Fixes
F: block/nbd.c
F: nbd.*
F: qemu-nbd.c
+T: git://github.com/bonzini/qemu.git nbd-next
SLIRP
M: Jan Kiszka <jan.kiszka@siemens.com>
--
1.7.7.6
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PULL 0/3] NBD pull request for 2012-02-17
2012-02-17 11:43 [Qemu-devel] [PULL 0/3] NBD pull request for 2012-02-17 Paolo Bonzini
` (2 preceding siblings ...)
2012-02-17 11:43 ` [Qemu-devel] [PATCH 3/3] nbd: add git tree to MAINTAINERS Paolo Bonzini
@ 2012-02-17 13:53 ` Anthony Liguori
3 siblings, 0 replies; 5+ messages in thread
From: Anthony Liguori @ 2012-02-17 13:53 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel
On 02/17/2012 05:43 AM, Paolo Bonzini wrote:
> Anthony,
>
> The following changes since commit 9de36b1a7cf61aa8be365f13c81668b3e19fbc7f:
>
> Make -machine/-enable-kvm options merge into a single list (2012-02-17 09:10:13 +0100)
>
> are available in the git repository at:
> git://github.com/bonzini/qemu.git nbd-for-anthony
Pulled. Thanks.
Regards,
Anthony Liguori
>
> Michael Tokarev (1):
> do not chdir(/) in qemu-nbd before opening all files
>
> Paolo Bonzini (2):
> open /dev/nbd in nbd_client_thread
> nbd: add git tree to MAINTAINERS
>
> MAINTAINERS | 1 +
> qemu-nbd.c | 42 +++++++++++++++++++++++-------------------
> 2 files changed, 24 insertions(+), 19 deletions(-)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-02-17 13:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-17 11:43 [Qemu-devel] [PULL 0/3] NBD pull request for 2012-02-17 Paolo Bonzini
2012-02-17 11:43 ` [Qemu-devel] [PATCH 1/3] do not chdir(/) in qemu-nbd before opening all files Paolo Bonzini
2012-02-17 11:43 ` [Qemu-devel] [PATCH 2/3] open /dev/nbd in nbd_client_thread Paolo Bonzini
2012-02-17 11:43 ` [Qemu-devel] [PATCH 3/3] nbd: add git tree to MAINTAINERS Paolo Bonzini
2012-02-17 13:53 ` [Qemu-devel] [PULL 0/3] NBD pull request for 2012-02-17 Anthony Liguori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).