diff mbox

[2/2] kvm tools: handle failure of command

Message ID 1312944249-4946-2-git-send-email-walimisdev@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

walimis Aug. 10, 2011, 2:44 a.m. UTC
handle failure of calling command function, especially, only handle
EPERM error now.

Signed-off-by: Liming Wang <walimisdev@gmail.com>
---
 tools/kvm/kvm-cmd.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

Comments

Pekka Enberg Aug. 10, 2011, 5:02 a.m. UTC | #1
On Wed, Aug 10, 2011 at 5:44 AM, Liming Wang <walimisdev@gmail.com> wrote:
> handle failure of calling command function, especially, only handle
> EPERM error now.
>
> Signed-off-by: Liming Wang <walimisdev@gmail.com>

I applied the patch because I absolutely loved the error handling
cleanups from the previous patch. However, out of curiosity, are you
seeing EPERM with some command in particular?

> ---
>  tools/kvm/kvm-cmd.c |   11 ++++++++++-
>  1 files changed, 10 insertions(+), 1 deletions(-)
>
> diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c
> index 63a2dbf..6cd4270 100644
> --- a/tools/kvm/kvm-cmd.c
> +++ b/tools/kvm/kvm-cmd.c
> @@ -15,6 +15,7 @@
>  #include "kvm/builtin-help.h"
>  #include "kvm/kvm-cmd.h"
>  #include "kvm/builtin-run.h"
> +#include "kvm/util.h"
>
>  struct cmd_struct kvm_commands[] = {
>        { "pause",      kvm_cmd_pause,          NULL,         0 },
> @@ -59,6 +60,7 @@ int handle_command(struct cmd_struct *command, int argc, const char **argv)
>  {
>        struct cmd_struct *p;
>        const char *prefix = NULL;
> +       int ret = 0;
>
>        if (!argv || !*argv) {
>                p = kvm_get_command(command, "help");
> @@ -74,5 +76,12 @@ int handle_command(struct cmd_struct *command, int argc, const char **argv)
>                return EINVAL;
>        }
>
> -       return p->fn(argc - 1, &argv[1], prefix);
> +       ret = p->fn(argc - 1, &argv[1], prefix);
> +       if (ret < 0)
> +       {
> +               if (errno == EPERM)
> +                       die("Permission error - are you root?");
> +       }
> +
> +       return ret;
>  }
> --
> 1.7.0.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
walimis Aug. 10, 2011, 5:03 a.m. UTC | #2
On Wed, Aug 10, 2011 at 08:02:01AM +0300, Pekka Enberg wrote:
>On Wed, Aug 10, 2011 at 5:44 AM, Liming Wang <walimisdev@gmail.com> wrote:
>> handle failure of calling command function, especially, only handle
>> EPERM error now.
>>
>> Signed-off-by: Liming Wang <walimisdev@gmail.com>
>
>I applied the patch because I absolutely loved the error handling
>cleanups from the previous patch. However, out of curiosity, are you
>seeing EPERM with some command in particular?
Yes. Because I'm using ubuntu and if I don't use sudo to execute
"kvm pause", pause command can't work and doesn't prompt anything.
BTW, do you always login as "root" user?

walimis
>
>> ---
>> ?ools/kvm/kvm-cmd.c | ? 11 ++++++++++-
>> ?1 files changed, 10 insertions(+), 1 deletions(-)
>>
>> diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c
>> index 63a2dbf..6cd4270 100644
>> --- a/tools/kvm/kvm-cmd.c
>> +++ b/tools/kvm/kvm-cmd.c
>> @@ -15,6 +15,7 @@
>> ?#include "kvm/builtin-help.h"
>> ?#include "kvm/kvm-cmd.h"
>> ?#include "kvm/builtin-run.h"
>> +#include "kvm/util.h"
>>
>> ?truct cmd_struct kvm_commands[] = {
>> ? ? ? ? "pause", ? ? ?vm_cmd_pause, ? ? ? ? ?ULL, ? ? ? ? 0 },
>> @@ -59,6 +60,7 @@ int handle_command(struct cmd_struct *command, int argc, const char **argv)
>> ?
>> ? ? ? ?truct cmd_struct *p;
>> ? ? ? ?onst char *prefix = NULL;
>> + ? ? ? int ret = 0;
>>
>> ? ? ? ?f (!argv || !*argv) {
>> ? ? ? ? ? ? ? ? = kvm_get_command(command, "help");
>> @@ -74,5 +76,12 @@ int handle_command(struct cmd_struct *command, int argc, const char **argv)
>> ? ? ? ? ? ? ? ?eturn EINVAL;
>> ? ? ? ?
>>
>> - ? ? ? return p->fn(argc - 1, &argv[1], prefix);
>> + ? ? ? ret = p->fn(argc - 1, &argv[1], prefix);
>> + ? ? ? if (ret < 0)
>> + ? ? ? {
>> + ? ? ? ? ? ? ? if (errno == EPERM)
>> + ? ? ? ? ? ? ? ? ? ? ? die("Permission error - are you root?");
>> + ? ? ? }
>> +
>> + ? ? ? return ret;
>> ?
>> --
>> 1.7.0.4
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe kvm" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at ?ttp://vger.kernel.org/majordomo-info.html
>>
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pekka Enberg Aug. 10, 2011, 5:30 a.m. UTC | #3
On 8/10/11 8:03 AM, walimis wrote:
> On Wed, Aug 10, 2011 at 08:02:01AM +0300, Pekka Enberg wrote:
>> On Wed, Aug 10, 2011 at 5:44 AM, Liming Wang<walimisdev@gmail.com>  wrote:
>>> handle failure of calling command function, especially, only handle
>>> EPERM error now.
>>>
>>> Signed-off-by: Liming Wang<walimisdev@gmail.com>
>> I applied the patch because I absolutely loved the error handling
>> cleanups from the previous patch. However, out of curiosity, are you
>> seeing EPERM with some command in particular?
> Yes. Because I'm using ubuntu and if I don't use sudo to execute
> "kvm pause", pause command can't work and doesn't prompt anything.

That's odd. I don't use sudo with the tool either. Sasha?
> BTW, do you always login as "root" user?

Depends on which image you're using.

                             Pekka
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
walimis Aug. 10, 2011, 5:33 a.m. UTC | #4
On Wed, Aug 10, 2011 at 08:30:19AM +0300, Pekka Enberg wrote:
>On 8/10/11 8:03 AM, walimis wrote:
>>On Wed, Aug 10, 2011 at 08:02:01AM +0300, Pekka Enberg wrote:
>>>On Wed, Aug 10, 2011 at 5:44 AM, Liming Wang<walimisdev@gmail.com>  wrote:
>>>>handle failure of calling command function, especially, only handle
>>>>EPERM error now.
>>>>
>>>>Signed-off-by: Liming Wang<walimisdev@gmail.com>
>>>I applied the patch because I absolutely loved the error handling
>>>cleanups from the previous patch. However, out of curiosity, are you
>>>seeing EPERM with some command in particular?
>>Yes. Because I'm using ubuntu and if I don't use sudo to execute
>>"kvm pause", pause command can't work and doesn't prompt anything.
>
>That's odd. I don't use sudo with the tool either. Sasha?
If I don't use sudo to run "kvm run", kvm prompt me:
  Fatal, could not open /dev/kvm: Permission denied

So I use sudo to execute "kvm run".
>>BTW, do you always login as "root" user?
>
>Depends on which image you're using.
I don't refer to the guest image. I mean that in your host PC, which user
you login and operate as.

walimis
>
>                            Pekka
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pekka Enberg Aug. 10, 2011, 5:53 a.m. UTC | #5
On Wed, Aug 10, 2011 at 8:33 AM, walimis <walimisdev@gmail.com> wrote:
>>>Yes. Because I'm using ubuntu and if I don't use sudo to execute
>>>"kvm pause", pause command can't work and doesn't prompt anything.
>>
>>That's odd. I don't use sudo with the tool either. Sasha?
> If I don't use sudo to run "kvm run", kvm prompt me:
>  Fatal, could not open /dev/kvm: Permission denied

You should probably just add yourself to the 'kvm' group:

https://help.ubuntu.com/community/KVM/Installation

> So I use sudo to execute "kvm run".
>>>BTW, do you always login as "root" user?
>>
>>Depends on which image you're using.
> I don't refer to the guest image. I mean that in your host PC, which user
> you login and operate as.

Heh, I never login as 'root' to the host machine. :-)

                        Pekka
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
walimis Aug. 10, 2011, 6:12 a.m. UTC | #6
On Wed, Aug 10, 2011 at 08:53:53AM +0300, Pekka Enberg wrote:
>On Wed, Aug 10, 2011 at 8:33 AM, walimis <walimisdev@gmail.com> wrote:
>>>>Yes. Because I'm using ubuntu and if I don't use sudo to execute
>>>>"kvm pause", pause command can't work and doesn't prompt anything.
>>>
>>>That's odd. I don't use sudo with the tool either. Sasha?
>> If I don't use sudo to run "kvm run", kvm prompt me:
>> ?atal, could not open /dev/kvm: Permission denied
>
>You should probably just add yourself to the 'kvm' group:
>
>https://help.ubuntu.com/community/KVM/Installation
OK, that works for me to access /dev/kvm without sudo. Thanks.
But another sudo requirement is to use tap interface:
  Warning: Config tap device error. Are you root?

So how do you use tap interface in your environment?

walimis
>
>> So I use sudo to execute "kvm run".
>>>>BTW, do you always login as "root" user?
>>>
>>>Depends on which image you're using.
>> I don't refer to the guest image. I mean that in your host PC, which user
>> you login and operate as.
>
>Heh, I never login as 'root' to the host machine. :-)
>
>                        Pekka
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
walimis Aug. 10, 2011, 6:32 a.m. UTC | #7
On Wed, Aug 10, 2011 at 09:35:12AM +0300, Pekka Enberg wrote:
>On Wed, Aug 10, 2011 at 9:12 AM, walimis <walimisdev@gmail.com> wrote:
>> On Wed, Aug 10, 2011 at 08:53:53AM +0300, Pekka Enberg wrote:
>>>On Wed, Aug 10, 2011 at 8:33 AM, walimis <walimisdev@gmail.com> wrote:
>>>>>>Yes. Because I'm using ubuntu and if I don't use sudo to execute
>>>>>>"kvm pause", pause command can't work and doesn't prompt anything.
>>>>>
>>>>>That's odd. I don't use sudo with the tool either. Sasha?
>>>> If I don't use sudo to run "kvm run", kvm prompt me:
>>>> ?atal, could not open /dev/kvm: Permission denied
>>>
>>>You should probably just add yourself to the 'kvm' group:
>>>
>>>https://help.ubuntu.com/community/KVM/Installation
>> OK, that works for me to access /dev/kvm without sudo. Thanks.
>> But another sudo requirement is to use tap interface:
>>  Warning: Config tap device error. Are you root?
>>
>> So how do you use tap interface in your environment?
>
>I don't use it. We enable userspace networking by default so all you
>need to do in the guest is to make sure dhcp is enabled and you should
>have a working network setup. Does that not work for you?
I used to use tap to enable network for guest os, so that I can mount 
nfs rootfs. meanwhile, I can access the guest os from host os through the
network. For kvm tools, I don't know how to do that through userspace 
networking. Maybe we need a brief explanation in README.

walimis
>
>                        Pekka
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pekka Enberg Aug. 10, 2011, 6:35 a.m. UTC | #8
On Wed, Aug 10, 2011 at 9:12 AM, walimis <walimisdev@gmail.com> wrote:
> On Wed, Aug 10, 2011 at 08:53:53AM +0300, Pekka Enberg wrote:
>>On Wed, Aug 10, 2011 at 8:33 AM, walimis <walimisdev@gmail.com> wrote:
>>>>>Yes. Because I'm using ubuntu and if I don't use sudo to execute
>>>>>"kvm pause", pause command can't work and doesn't prompt anything.
>>>>
>>>>That's odd. I don't use sudo with the tool either. Sasha?
>>> If I don't use sudo to run "kvm run", kvm prompt me:
>>> ?atal, could not open /dev/kvm: Permission denied
>>
>>You should probably just add yourself to the 'kvm' group:
>>
>>https://help.ubuntu.com/community/KVM/Installation
> OK, that works for me to access /dev/kvm without sudo. Thanks.
> But another sudo requirement is to use tap interface:
>  Warning: Config tap device error. Are you root?
>
> So how do you use tap interface in your environment?

I don't use it. We enable userspace networking by default so all you
need to do in the guest is to make sure dhcp is enabled and you should
have a working network setup. Does that not work for you?

                        Pekka
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pekka Enberg Aug. 10, 2011, 6:49 a.m. UTC | #9
On Wed, Aug 10, 2011 at 9:32 AM, walimis <walimisdev@gmail.com> wrote:
> I used to use tap to enable network for guest os, so that I can mount
> nfs rootfs. meanwhile, I can access the guest os from host os through the
> network. For kvm tools, I don't know how to do that through userspace
> networking. Maybe we need a brief explanation in README.

Right. I've never used that. Asias is that supported?
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Asias He Aug. 10, 2011, 9:28 a.m. UTC | #10
On 08/10/2011 02:49 PM, Pekka Enberg wrote:
> On Wed, Aug 10, 2011 at 9:32 AM, walimis <walimisdev@gmail.com> wrote:
>> I used to use tap to enable network for guest os, so that I can mount
>> nfs rootfs. meanwhile, I can access the guest os from host os through the
>> network. For kvm tools, I don't know how to do that through userspace
>> networking. Maybe we need a brief explanation in README.
> 
> Right. I've never used that. Asias is that supported?
> 

I have not tried nfs with our user mode network. But I think walimis can
do it with

	sudo ./kvm --network tap

We need sudo because we need CAP_NET_ADMIN to open /dev/net/tun.

By default, the ip address in host side is:

192.168.33.1/24

In guest side, you need to config a ip address for our guest:

	$ sudo ifconfig eth0 192.168.33.15
	$ sudo route add default gw 192.168.33.1
	$ ping 192.168.33.1

That's it.

If you want to access the real world in guest, try NAT or Bridge the tap
device.
diff mbox

Patch

diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c
index 63a2dbf..6cd4270 100644
--- a/tools/kvm/kvm-cmd.c
+++ b/tools/kvm/kvm-cmd.c
@@ -15,6 +15,7 @@ 
 #include "kvm/builtin-help.h"
 #include "kvm/kvm-cmd.h"
 #include "kvm/builtin-run.h"
+#include "kvm/util.h"
 
 struct cmd_struct kvm_commands[] = {
 	{ "pause",	kvm_cmd_pause,		NULL,         0 },
@@ -59,6 +60,7 @@  int handle_command(struct cmd_struct *command, int argc, const char **argv)
 {
 	struct cmd_struct *p;
 	const char *prefix = NULL;
+	int ret = 0;
 
 	if (!argv || !*argv) {
 		p = kvm_get_command(command, "help");
@@ -74,5 +76,12 @@  int handle_command(struct cmd_struct *command, int argc, const char **argv)
 		return EINVAL;
 	}
 
-	return p->fn(argc - 1, &argv[1], prefix);
+	ret = p->fn(argc - 1, &argv[1], prefix);
+	if (ret < 0)
+	{
+		if (errno == EPERM)
+			die("Permission error - are you root?");
+	}
+
+	return ret;
 }