Skip to contentSkip to conversation

qemu-nbd daemonizing?

Qemu-devel Michael Tokarev 2 participants 6 messages Jan 14, 2012 – Jan 15, 2012

lore
Share & tools
lore
#0 lore raw

After looking at the yesterdays issue with non-absolute paths for qemu-nbd arguments and daemon(3), I've a question.

Why qemu-nbd daemonizes, and does that only when device argument is given (dropping -v/verbose case for now)?

This raises two questions:

- shouldn't it do the same daemonizing in case of usual tcp export?

- shouldn't the daemonizing itself be controlled by an option (like -d), and why we can't just send it to background using "&" shell constuct?

And while at it, I wonder why it is really unix-only? There's nothing unix-specific in there exept two things:
it is the device handling (/dev/nbdX) and all the hacks around this (including this daemonizing). The rest should work on win32 just fine.

Thanks,

/mjt

#1 lore raw
Quoted 11 lines · Michael Tokarev

After looking at the yesterdays issue with non-absolute paths for qemu-nbd arguments and daemon(3), I've a question.

Why qemu-nbd daemonizes, and does that only when device argument is given (dropping -v/verbose case for now)?

This raises two questions:

- shouldn't it do the same daemonizing in case of usual tcp export?

Perhaps yes, but in that case you cannot use "qemu-nbd -d" to kill the daemonized process. Also, one of the best things of systemd is that it handles daemonization on its own, so nowadays it is better not to have process send themselves into background by default.

Quoted 3 lines

- shouldn't the daemonizing itself be controlled by an option (like -d), and why we can't just send it to background using "&" shell constuct?

Daemonization does more than "&" (the double fork+setsid process).

Quoted 5 lines

And while at it, I wonder why it is really unix-only? There's nothing unix-specific in there exept two things:
it is the device handling (/dev/nbdX) and all the hacks around this (including this daemonizing). The rest should work on win32 just fine.

I think it's just historical.

Paolo

#2 lore raw
Quoted 8 lines · Paolo Bonzini
Quoted 7 lines · Michael Tokarev

After looking at the yesterdays issue with non-absolute paths for qemu-nbd arguments and daemon(3), I've a question.

Why qemu-nbd daemonizes, and does that only when device argument is given (dropping -v/verbose case for now)?

Quoted 7 lines
Quoted 4 lines

This raises two questions:

- shouldn't it do the same daemonizing in case of usual tcp export?

Perhaps yes, but in that case you cannot use "qemu-nbd -d" to kill the daemonized process.

Sorry? qemu-nbd -d will connect to the socket the daemonized daemon is listening on, the same way as it is done now -- nothing really changes there.

Quoted 3 lines

Also, one of the best things of systemd is that it handles daemonization on its own, so nowadays it is better not to have process send themselves into background by default.

First, not all the world is systemd. Second, my question was merely about consistency -- -c does daemonizing currently and there's no way to stop it from doing so, regular tcp case does not do any daemonizing.

Quoted 5 lines
Quoted 3 lines

- shouldn't the daemonizing itself be controlled by an option (like -d), and why we can't just send it to background using "&" shell constuct?

Daemonization does more than "&" (the double fork+setsid process).

Sure. We've setsid and shell redirection for that if you wish.

The primary question was why -c daemonizes unconditionally.

Quoted 7 lines
Quoted 5 lines

And while at it, I wonder why it is really unix-only? There's nothing unix-specific in there exept two things:
it is the device handling (/dev/nbdX) and all the hacks around this (including this daemonizing). The rest should work on win32 just fine.

I think it's just historical.

qemu-nbd was runnable on win32 before, so historically it was exactly the opposite. I asked you because you mentioned it is linux-only for the first time, but indeed, at that time it wasn't compilable on win32 already.

Thanks,

/mjt

#3 lore raw
Quoted 14 lines · Michael Tokarev
Quoted 13 lines · Paolo Bonzini
Quoted 11 lines · Michael Tokarev

After looking at the yesterdays issue with non-absolute paths for qemu-nbd arguments and daemon(3), I've a question.

Why qemu-nbd daemonizes, and does that only when device argument is given (dropping -v/verbose case for now)?

This raises two questions:

- shouldn't it do the same daemonizing in case of usual tcp export?

Quoted 6 lines
Quoted 2 lines

Perhaps yes, but in that case you cannot use "qemu-nbd -d" to kill the daemonized process.

Sorry? qemu-nbd -d will connect to the socket the daemonized daemon is listening on, the same way as it is done now -- nothing really changes there.

No, "qemu-nbd -d" will connect to the /dev/nbdX device and tell the kernel to disconnect. This will terminate the daemon (as long as you didn't use --persistent, at least).

Quoted 7 lines
Quoted 3 lines

Also, one of the best things of systemd is that it handles daemonization on its own, so nowadays it is better not to have process send themselves into background by default.

First, not all the world is systemd. Second, my question was merely about consistency -- -c does daemonizing currently and there's no way to stop it from doing so

--verbose is a counterintuitive way not to daemonize, but it works.

Quoted 1 line

The primary question was why -c daemonizes unconditionally.

I don't know. But I don't think daemonizing is really a feature, just something historical that we have to deal with.

Quoted 4 lines

qemu-nbd was runnable on win32 before, so historically it
was exactly the opposite. I asked you because you mentioned
it is linux-only for the first time, but indeed, at that time it wasn't compilable on win32 already.

Fixing it would be good indeed. We can use qemu-thread for that for example. But it looks like the third commit ever to qemu-nbd.c already made it non-Linux-only. I don't think there ever was a release that supported qemu-nbd on Win32, right?

Paolo

#4 lore raw
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Michael Tokarev
Quoted 13 lines · Paolo Bonzini
Quoted 11 lines · Michael Tokarev

After looking at the yesterdays issue with non-absolute paths for qemu-nbd arguments and daemon(3), I've a question.

Why qemu-nbd daemonizes, and does that only when device argument is given (dropping -v/verbose case for now)?

This raises two questions:

- shouldn't it do the same daemonizing in case of usual tcp export?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Perhaps yes, but in that case you cannot use "qemu-nbd -d" to kill the daemonized process.

Sorry? qemu-nbd -d will connect to the socket the daemonized daemon is listening on, the same way as it is done now -- nothing really changes there.

No, "qemu-nbd -d" will connect to the /dev/nbdX device and tell the kernel to disconnect. This will terminate the daemon (as long as you didn't use --persistent, at least).

Whatever. In any case qemu-nbd is able to terminate currently running daemon, nothing changes with addition daemonizing here or without - that was my point.

Quoted 9 lines
Quoted 7 lines
Quoted 3 lines

Also, one of the best things of systemd is that it handles daemonization on its own, so nowadays it is better not to have process send themselves into background by default.

First, not all the world is systemd. Second, my question was merely about consistency -- -c does daemonizing currently and there's no way to stop it from doing so

--verbose is a counterintuitive way not to daemonize, but it works.

I know it works (with additional bonus - it shows extra messages). It wasn't my question.

Quoted 3 lines
Quoted 1 line

The primary question was why -c daemonizes unconditionally.

I don't know. But I don't think daemonizing is really a feature, just something historical that we have to deal with.

Aha. So can't it just go away, or be controlled by another option, not related to -c ? I think it should be good.

Quoted 6 lines
Quoted 4 lines

qemu-nbd was runnable on win32 before, so historically it
was exactly the opposite. I asked you because you mentioned
it is linux-only for the first time, but indeed, at that time it wasn't compilable on win32 already.

Fixing it would be good indeed. We can use qemu-thread for that for example. But it looks like the third commit ever to qemu-nbd.c already made it non-Linux-only. I don't think there ever was a release that supported qemu-nbd on Win32, right?

It is kinda trivial to fix this. But this task becomes completely unrealistic if that will involve another discussion like we currently have.

Thanks,

/mjt

#5 lore raw
Quoted 23 lines · Michael Tokarev
Quoted 22 lines · Paolo Bonzini
Quoted 20 lines · Michael Tokarev
Quoted 8 lines · Paolo Bonzini
Quoted 7 lines · Michael Tokarev

After looking at the yesterdays issue with non-absolute paths for qemu-nbd arguments and daemon(3), I've a question.

Why qemu-nbd daemonizes, and does that only when device argument is given (dropping -v/verbose case for now)?

Quoted 7 lines
Quoted 4 lines

This raises two questions:

- shouldn't it do the same daemonizing in case of usual tcp export?

Perhaps yes, but in that case you cannot use "qemu-nbd -d" to kill the daemonized process.

Sorry? qemu-nbd -d will connect to the socket the daemonized daemon is listening on, the same way as it is done now -- nothing really changes there.

Quoted 7 lines
Quoted 3 lines

No, "qemu-nbd -d" will connect to the /dev/nbdX device and tell thekernel to disconnect. This will terminate the daemon (as long as you didn't use --persistent, at least).

Whatever. In any case qemu-nbd is able to terminate currently running daemon, nothing changes with addition daemonizing here or without - that was my point.

Not "whatever", and not "in any case". qemu-nbd is able to terminate a currently running daemon indirectly, by detaching /dev/nbd. The same cannot be done in the TCP export case (where --persistent is used more often than not). The point is that qemu-nbd only daemonizes when there is a simple way to terminate it externally.

Could it have been done better? Yes. Do we have to deal with it? Yes.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

The primary question was why -c daemonizes unconditionally.

I don't know. But I don't think daemonizing is really a feature, just something historical that we have to deal with.

Aha. So can't it just go away, or be controlled by another option, not related to -c ? I think it should be good.

I think it could go away, but I'm quite torn. It does make sense.

Leaving the current historical default "as is", but also allowing daemonization in the TCP case makes sense too. However, you need to preserve the way exit statuses are sent for initialization problems, even where daemonizing.

To fix this you would have to add three options: --pidfile (to terminate a currently running daemon), --daemonize, --no-daemonize. Honestly, I don't think it's worth it, but I wouldn't refuse patches and, of course, improving the documentation would also be a very good idea.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

qemu-nbd was runnable on win32 before, so historically it
was exactly the opposite. I asked you because you mentioned
it is linux-only for the first time, but indeed, at that time it wasn't compilable on win32 already.

Quoted 8 lines
Quoted 4 lines

Fixing it would be good indeed. We can use qemu-thread for that forexample. But it looks like the third commit ever to qemu-nbd.c already made it non-Linux-only. I don't think there ever was a release that supported qemu-nbd on Win32, right?

It is kinda trivial to fix this. But this task becomes completely unrealistic if that will involve another discussion like we currently have.

I'm pretty sure it shouldn't. This discussion is happening because you haven't completely read the code, which has more nuances than you think.
Threads, daemonization, error messages, exit statuses, all this
together makes it quite complex.

Paolo