]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: timer cleanup
authorSasha Levin <levinsasha928@gmail.com>
Wed, 5 Sep 2012 08:31:50 +0000 (10:31 +0200)
committerPekka Enberg <penberg@kernel.org>
Wed, 5 Sep 2012 13:22:37 +0000 (16:22 +0300)
Make the timer init/exit follow the rest of the code, and move it out of
builtin-run.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/builtin-run.c
tools/kvm/include/kvm/kvm.h
tools/kvm/kvm.c

index 5e6daa8ae679df32a4c3b39e2688b74e336d26b4..a1825a145563d0e93f34dccef7bce910d75cb547 100644 (file)
@@ -1203,7 +1203,11 @@ static int kvm_cmd_run_init(int argc, const char **argv)
         * come after this (it may set up device trees etc.)
         */
 
-       kvm__start_timer(kvm);
+       r = kvm_timer__init(kvm);
+       if (r < 0) {
+               pr_err("kvm_timer__init() failed with error %d\n", r);
+               goto fail;
+       }
 
        if (kvm->cfg.firmware_filename) {
                if (!kvm__load_firmware(kvm, kvm->cfg.firmware_filename))
@@ -1258,9 +1262,13 @@ static void kvm_cmd_run_exit(int guest_ret)
        if (r < 0)
                pr_warning("irq__exit() failed with error %d\n", r);
 
+       r = kvm_timer__exit(kvm);
+       if (r < 0)
+               pr_warning("kvm_timer__exit() failed with error %d\n", r);
+
        r = fb__exit(kvm);
        if (r < 0)
-               pr_warning("fb__exit() failed with error %d\n", r);
+               pr_warning("kvm_timer__exit() failed with error %d\n", r);
 
        r = virtio_scsi_exit(kvm);
        if (r < 0)
index d3b6dab19d8089d8a9ac1070d1d59c3c5f8a1f5c..2cd30e47d53b469e7a4c70593aeb5f05b9656f23 100644 (file)
@@ -68,8 +68,8 @@ int kvm__exit(struct kvm *kvm);
 bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename);
 bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename,
                        const char *initrd_filename, const char *kernel_cmdline, u16 vidmode);
-void kvm__start_timer(struct kvm *kvm);
-void kvm__stop_timer(struct kvm *kvm);
+int kvm_timer__init(struct kvm *kvm);
+int kvm_timer__exit(struct kvm *kvm);
 void kvm__irq_line(struct kvm *kvm, int irq, int level);
 void kvm__irq_trigger(struct kvm *kvm, int irq);
 bool kvm__emulate_io(struct kvm *kvm, u16 port, void *data, int direction, int size, u32 count);
index eeac0f6ae0d692a1477ce9f976f6427016ed3ba6..42a0f06f41a9fe53704d6d89b2dc4c73defe98b3 100644 (file)
@@ -254,8 +254,6 @@ int kvm__enumerate_instances(int (*callback)(const char *name, int fd))
 
 int kvm__exit(struct kvm *kvm)
 {
-       kvm__stop_timer(kvm);
-
        kvm__arch_delete_ram(kvm);
        kvm_ipc__stop();
        kvm__remove_socket(kvm->cfg.guest_name);
@@ -478,10 +476,11 @@ found_kernel:
  * userspace hypervisor into the guest at periodical intervals. Please note
  * that clock interrupt, for example, is not handled here.
  */
-void kvm__start_timer(struct kvm *kvm)
+int kvm_timer__init(struct kvm *kvm)
 {
        struct itimerspec its;
        struct sigevent sev;
+       int r;
 
        memset(&sev, 0, sizeof(struct sigevent));
        sev.sigev_value.sival_int       = 0;
@@ -489,25 +488,33 @@ void kvm__start_timer(struct kvm *kvm)
        sev.sigev_signo                 = SIGALRM;
        sev._sigev_un._tid              = syscall(__NR_gettid);
 
-       if (timer_create(CLOCK_REALTIME, &sev, &kvm->timerid) < 0)
-               die("timer_create()");
+       r = timer_create(CLOCK_REALTIME, &sev, &kvm->timerid);
+       if (r < 0)
+               return r;
 
        its.it_value.tv_sec             = TIMER_INTERVAL_NS / 1000000000;
        its.it_value.tv_nsec            = TIMER_INTERVAL_NS % 1000000000;
        its.it_interval.tv_sec          = its.it_value.tv_sec;
        its.it_interval.tv_nsec         = its.it_value.tv_nsec;
 
-       if (timer_settime(kvm->timerid, 0, &its, NULL) < 0)
-               die("timer_settime()");
+       r = timer_settime(kvm->timerid, 0, &its, NULL);
+       if (r < 0) {
+               timer_delete(kvm->timerid);
+               return r;
+       }
+
+       return 0;
 }
 
-void kvm__stop_timer(struct kvm *kvm)
+int kvm_timer__exit(struct kvm *kvm)
 {
        if (kvm->timerid)
                if (timer_delete(kvm->timerid) < 0)
                        die("timer_delete()");
 
        kvm->timerid = 0;
+
+       return 0;
 }
 
 void kvm__dump_mem(struct kvm *kvm, unsigned long addr, unsigned long size)