lguest: make write() operation smp aware
authorGlauber de Oliveira Costa <gcosta@redhat.com>
Mon, 7 Jan 2008 13:05:26 +0000 (11:05 -0200)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 30 Jan 2008 11:50:07 +0000 (22:50 +1100)
This patch makes the write() file operation smp aware. Which means, receiving
the vcpu_id value through the offset parameter, and being well aware to which
vcpu we're talking to.

Signed-off-by: Glauber de Oliveira Costa <gcosta@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
drivers/lguest/lguest_user.c

index 9f0a4432994709288f3ef4fb6091cc22c6e4f130..2562082a3ea3fdfd5a1b56e1358e25848cea1eb9 100644 (file)
@@ -227,14 +227,21 @@ static ssize_t write(struct file *file, const char __user *in,
        struct lguest *lg = file->private_data;
        const unsigned long __user *input = (const unsigned long __user *)in;
        unsigned long req;
+       struct lg_cpu *cpu;
+       unsigned int cpu_id = *off;
 
        if (get_user(req, input) != 0)
                return -EFAULT;
        input++;
 
        /* If you haven't initialized, you must do that first. */
-       if (req != LHREQ_INITIALIZE && !lg)
-               return -EINVAL;
+       if (req != LHREQ_INITIALIZE) {
+               if (!lg || (cpu_id >= lg->nr_cpus))
+                       return -EINVAL;
+               cpu = &lg->cpus[cpu_id];
+               if (!cpu)
+                       return -EINVAL;
+       }
 
        /* Once the Guest is dead, all you can do is read() why it died. */
        if (lg && lg->dead)