aboutsummaryrefslogtreecommitdiffstats
path: root/virt
diff options
context:
space:
mode:
authorHamo <hamo.by@gmail.com>2011-12-15 01:23:16 -0500
committerAvi Kivity <avi@redhat.com>2011-12-27 04:22:33 -0500
commit4f69b6805c4f818cf7f4126978cc4a54c489119f (patch)
tree74f32a6cb922e285bfbeb5dba4ef872088fb8d55 /virt
parentd546cb406ea0d83e2d39ec14221957a24f88a622 (diff)
KVM: ensure that debugfs entries have been created
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> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'virt')
-rw-r--r--virt/kvm/kvm_main.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 0835c4b90d2f..7287bf5d1c9e 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2654,15 +2654,29 @@ static const struct file_operations *stat_fops[] = {
2654 [KVM_STAT_VM] = &vm_stat_fops, 2654 [KVM_STAT_VM] = &vm_stat_fops,
2655}; 2655};
2656 2656
2657static void kvm_init_debug(void) 2657static int kvm_init_debug(void)
2658{ 2658{
2659 int r = -EFAULT;
2659 struct kvm_stats_debugfs_item *p; 2660 struct kvm_stats_debugfs_item *p;
2660 2661
2661 kvm_debugfs_dir = debugfs_create_dir("kvm", NULL); 2662 kvm_debugfs_dir = debugfs_create_dir("kvm", NULL);
2662 for (p = debugfs_entries; p->name; ++p) 2663 if (kvm_debugfs_dir == NULL)
2664 goto out;
2665
2666 for (p = debugfs_entries; p->name; ++p) {
2663 p->dentry = debugfs_create_file(p->name, 0444, kvm_debugfs_dir, 2667 p->dentry = debugfs_create_file(p->name, 0444, kvm_debugfs_dir,
2664 (void *)(long)p->offset, 2668 (void *)(long)p->offset,
2665 stat_fops[p->kind]); 2669 stat_fops[p->kind]);
2670 if (p->dentry == NULL)
2671 goto out_dir;
2672 }
2673
2674 return 0;
2675
2676out_dir:
2677 debugfs_remove_recursive(kvm_debugfs_dir);
2678out:
2679 return r;
2666} 2680}
2667 2681
2668static void kvm_exit_debug(void) 2682static void kvm_exit_debug(void)
@@ -2806,10 +2820,16 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
2806 kvm_preempt_ops.sched_in = kvm_sched_in; 2820 kvm_preempt_ops.sched_in = kvm_sched_in;
2807 kvm_preempt_ops.sched_out = kvm_sched_out; 2821 kvm_preempt_ops.sched_out = kvm_sched_out;
2808 2822
2809 kvm_init_debug(); 2823 r = kvm_init_debug();
2824 if (r) {
2825 printk(KERN_ERR "kvm: create debugfs files failed\n");
2826 goto out_undebugfs;
2827 }
2810 2828
2811 return 0; 2829 return 0;
2812 2830
2831out_undebugfs:
2832 unregister_syscore_ops(&kvm_syscore_ops);
2813out_unreg: 2833out_unreg:
2814 kvm_async_pf_deinit(); 2834 kvm_async_pf_deinit();
2815out_free: 2835out_free: