* [PATCH] kvm: ensure that debugfs entries have been created
@ 2011-12-15 6:23 Hamo
2011-12-19 14:20 ` Yang Hamo Bai
2011-12-22 10:47 ` Marcelo Tosatti
0 siblings, 2 replies; 3+ messages in thread
From: Hamo @ 2011-12-15 6:23 UTC (permalink / raw)
To: avi, mtosatti; +Cc: kvm, linux-kernel
by checking the return value from kvm_init_debug, we
can ensure that the entries under debugfs for KVM have
been created correctly.
Signed-off-by: Yang Bai <hamo.by@gmail.com>
---
virt/kvm/kvm_main.c | 26 +++++++++++++++++++++++---
1 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index d9cfb78..a338273 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2612,15 +2612,29 @@ static const struct file_operations *stat_fops[] = {
[KVM_STAT_VM] = &vm_stat_fops,
};
-static void kvm_init_debug(void)
+static int kvm_init_debug(void)
{
+ int r = -EFAULT;
struct kvm_stats_debugfs_item *p;
kvm_debugfs_dir = debugfs_create_dir("kvm", NULL);
- for (p = debugfs_entries; p->name; ++p)
+ if (kvm_debugfs_dir == NULL)
+ goto out;
+
+ for (p = debugfs_entries; p->name; ++p) {
p->dentry = debugfs_create_file(p->name, 0444, kvm_debugfs_dir,
(void *)(long)p->offset,
stat_fops[p->kind]);
+ if (p->dentry == NULL)
+ goto out_dir;
+ }
+
+ return 0;
+
+out_dir:
+ debugfs_remove_recursive(kvm_debugfs_dir);
+out:
+ return r;
}
static void kvm_exit_debug(void)
@@ -2764,10 +2778,16 @@ int kvm_init(void *opaque, unsigned vcpu_size,
unsigned vcpu_align,
kvm_preempt_ops.sched_in = kvm_sched_in;
kvm_preempt_ops.sched_out = kvm_sched_out;
- kvm_init_debug();
+ r = kvm_init_debug();
+ if (r) {
+ printk(KERN_ERR "kvm: create debugfs files failed\n");
+ goto out_undebugfs;
+ }
return 0;
+out_undebugfs:
+ unregister_syscore_ops(&kvm_syscore_ops);
out_unreg:
kvm_async_pf_deinit();
out_free:
--
1.7.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] kvm: ensure that debugfs entries have been created
2011-12-15 6:23 [PATCH] kvm: ensure that debugfs entries have been created Hamo
@ 2011-12-19 14:20 ` Yang Hamo Bai
2011-12-22 10:47 ` Marcelo Tosatti
1 sibling, 0 replies; 3+ messages in thread
From: Yang Hamo Bai @ 2011-12-19 14:20 UTC (permalink / raw)
To: avi, mtosatti; +Cc: kvm, linux-kernel
On Thu, Dec 15, 2011 at 2:23 PM, Hamo <hamo.by@gmail.com> wrote:
> by checking the return value from kvm_init_debug, we
> can ensure that the entries under debugfs for KVM have
> been created correctly.
>
> Signed-off-by: Yang Bai <hamo.by@gmail.com>
> ---
> virt/kvm/kvm_main.c | 26 +++++++++++++++++++++++---
> 1 files changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index d9cfb78..a338273 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -2612,15 +2612,29 @@ static const struct file_operations *stat_fops[] = {
> [KVM_STAT_VM] = &vm_stat_fops,
> };
>
> -static void kvm_init_debug(void)
> +static int kvm_init_debug(void)
> {
> + int r = -EFAULT;
> struct kvm_stats_debugfs_item *p;
>
> kvm_debugfs_dir = debugfs_create_dir("kvm", NULL);
> - for (p = debugfs_entries; p->name; ++p)
> + if (kvm_debugfs_dir == NULL)
> + goto out;
> +
> + for (p = debugfs_entries; p->name; ++p) {
> p->dentry = debugfs_create_file(p->name, 0444, kvm_debugfs_dir,
> (void *)(long)p->offset,
> stat_fops[p->kind]);
> + if (p->dentry == NULL)
> + goto out_dir;
> + }
> +
> + return 0;
> +
> +out_dir:
> + debugfs_remove_recursive(kvm_debugfs_dir);
> +out:
> + return r;
> }
>
> static void kvm_exit_debug(void)
> @@ -2764,10 +2778,16 @@ int kvm_init(void *opaque, unsigned vcpu_size,
> unsigned vcpu_align,
> kvm_preempt_ops.sched_in = kvm_sched_in;
> kvm_preempt_ops.sched_out = kvm_sched_out;
>
> - kvm_init_debug();
> + r = kvm_init_debug();
> + if (r) {
> + printk(KERN_ERR "kvm: create debugfs files failed\n");
> + goto out_undebugfs;
> + }
>
> return 0;
>
> +out_undebugfs:
> + unregister_syscore_ops(&kvm_syscore_ops);
> out_unreg:
> kvm_async_pf_deinit();
> out_free:
> --
> 1.7.1
Ping.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kvm: ensure that debugfs entries have been created
2011-12-15 6:23 [PATCH] kvm: ensure that debugfs entries have been created Hamo
2011-12-19 14:20 ` Yang Hamo Bai
@ 2011-12-22 10:47 ` Marcelo Tosatti
1 sibling, 0 replies; 3+ messages in thread
From: Marcelo Tosatti @ 2011-12-22 10:47 UTC (permalink / raw)
To: Hamo; +Cc: avi, kvm, linux-kernel
On Thu, Dec 15, 2011 at 02:23:16PM +0800, Hamo wrote:
> by checking the return value from kvm_init_debug, we
> can ensure that the entries under debugfs for KVM have
> been created correctly.
>
> Signed-off-by: Yang Bai <hamo.by@gmail.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-12-22 14:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-15 6:23 [PATCH] kvm: ensure that debugfs entries have been created Hamo
2011-12-19 14:20 ` Yang Hamo Bai
2011-12-22 10:47 ` Marcelo Tosatti
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.