]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
s390/cio: Make /dev/chsc a single-open device
authorMichael Holzheu <holzheu@linux.vnet.ibm.com>
Thu, 6 Jun 2013 07:49:09 +0000 (09:49 +0200)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Mon, 10 Jun 2013 14:06:19 +0000 (16:06 +0200)
In order to allow serialization of dynamic I/O with this patch
the /dev/chsc character device can only be accessed by one
single opener. Any subsequent open calls are rejected with EBUSY.

Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
drivers/s390/cio/chsc_sch.c

index 190fc844d8149622638c84348e2aefd3b59a4121..5fe9f8c4b4fb8ad58e54e607d0019a0702e3e341 100644 (file)
@@ -847,9 +847,27 @@ static long chsc_ioctl(struct file *filp, unsigned int cmd,
        }
 }
 
+static atomic_t chsc_ready_for_use = ATOMIC_INIT(1);
+
+static int chsc_open(struct inode *inode, struct file *file)
+{
+       if (!atomic_dec_and_test(&chsc_ready_for_use)) {
+               atomic_inc(&chsc_ready_for_use);
+               return -EBUSY;
+       }
+       return nonseekable_open(inode, file);
+}
+
+static int chsc_release(struct inode *inode, struct file *filp)
+{
+       atomic_inc(&chsc_ready_for_use);
+       return 0;
+}
+
 static const struct file_operations chsc_fops = {
        .owner = THIS_MODULE,
-       .open = nonseekable_open,
+       .open = chsc_open,
+       .release = chsc_release,
        .unlocked_ioctl = chsc_ioctl,
        .compat_ioctl = chsc_ioctl,
        .llseek = no_llseek,