s390/cio: Introduce on-close CHSC IOCTLs
authorMichael Holzheu <holzheu@linux.vnet.ibm.com>
Thu, 6 Jun 2013 07:50:21 +0000 (09:50 +0200)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Wed, 26 Jun 2013 19:10:12 +0000 (21:10 +0200)
Introduce two new ioctls CHSC_ON_CLOSE_SET and CHSC_ON_CLOSE_REMOVE
that allow to add and remove one CHSC that is unconditionally executed
when the CHSC device node is closed.

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

index 6e5307fbeb1e8397690a5746c1e92f01fa391c82..65dc694725a85d29ba5d15781afff89fd717c59e 100644 (file)
@@ -137,5 +137,7 @@ struct chsc_cpd_info {
 #define CHSC_INFO_CPD _IOWR(CHSC_IOCTL_MAGIC, 0x87, struct chsc_cpd_info)
 #define CHSC_INFO_DCAL _IOWR(CHSC_IOCTL_MAGIC, 0x88, struct chsc_dcal)
 #define CHSC_START_SYNC _IOWR(CHSC_IOCTL_MAGIC, 0x89, struct chsc_sync_area)
+#define CHSC_ON_CLOSE_SET _IOWR(CHSC_IOCTL_MAGIC, 0x8a, struct chsc_async_area)
+#define CHSC_ON_CLOSE_REMOVE _IO(CHSC_IOCTL_MAGIC, 0x8b)
 
 #endif
index 5fe9f8c4b4fb8ad58e54e607d0019a0702e3e341..64cd60063ffc765e22aa9baa5f084374ee01507f 100644 (file)
 static debug_info_t *chsc_debug_msg_id;
 static debug_info_t *chsc_debug_log_id;
 
+static struct chsc_request *on_close_request;
+static struct chsc_async_area *on_close_chsc_area;
+static DEFINE_MUTEX(on_close_mutex);
+
 #define CHSC_MSG(imp, args...) do {                                    \
                debug_sprintf_event(chsc_debug_msg_id, imp , ##args);   \
        } while (0)
@@ -362,6 +366,68 @@ out_free:
        return ret;
 }
 
+static int chsc_ioctl_on_close_set(void __user *user_area)
+{
+       char dbf[13];
+       int ret;
+
+       mutex_lock(&on_close_mutex);
+       if (on_close_chsc_area) {
+               ret = -EBUSY;
+               goto out_unlock;
+       }
+       on_close_request = kzalloc(sizeof(*on_close_request), GFP_KERNEL);
+       if (!on_close_request) {
+               ret = -ENOMEM;
+               goto out_unlock;
+       }
+       on_close_chsc_area = (void *)get_zeroed_page(GFP_DMA | GFP_KERNEL);
+       if (!on_close_chsc_area) {
+               ret = -ENOMEM;
+               goto out_free_request;
+       }
+       if (copy_from_user(on_close_chsc_area, user_area, PAGE_SIZE)) {
+               ret = -EFAULT;
+               goto out_free_chsc;
+       }
+       ret = 0;
+       goto out_unlock;
+
+out_free_chsc:
+       free_page((unsigned long)on_close_chsc_area);
+       on_close_chsc_area = NULL;
+out_free_request:
+       kfree(on_close_request);
+       on_close_request = NULL;
+out_unlock:
+       mutex_unlock(&on_close_mutex);
+       sprintf(dbf, "ocsret:%d", ret);
+       CHSC_LOG(0, dbf);
+       return ret;
+}
+
+static int chsc_ioctl_on_close_remove(void)
+{
+       char dbf[13];
+       int ret;
+
+       mutex_lock(&on_close_mutex);
+       if (!on_close_chsc_area) {
+               ret = -ENOENT;
+               goto out_unlock;
+       }
+       free_page((unsigned long)on_close_chsc_area);
+       on_close_chsc_area = NULL;
+       kfree(on_close_request);
+       on_close_request = NULL;
+       ret = 0;
+out_unlock:
+       mutex_unlock(&on_close_mutex);
+       sprintf(dbf, "ocrret:%d", ret);
+       CHSC_LOG(0, dbf);
+       return ret;
+}
+
 static int chsc_ioctl_start_sync(void __user *user_area)
 {
        struct chsc_sync_area *chsc_area;
@@ -842,6 +908,10 @@ static long chsc_ioctl(struct file *filp, unsigned int cmd,
                return chsc_ioctl_chpd(argp);
        case CHSC_INFO_DCAL:
                return chsc_ioctl_dcal(argp);
+       case CHSC_ON_CLOSE_SET:
+               return chsc_ioctl_on_close_set(argp);
+       case CHSC_ON_CLOSE_REMOVE:
+               return chsc_ioctl_on_close_remove();
        default: /* unknown ioctl number */
                return -ENOIOCTLCMD;
        }
@@ -860,6 +930,30 @@ static int chsc_open(struct inode *inode, struct file *file)
 
 static int chsc_release(struct inode *inode, struct file *filp)
 {
+       char dbf[13];
+       int ret;
+
+       mutex_lock(&on_close_mutex);
+       if (!on_close_chsc_area)
+               goto out_unlock;
+       init_completion(&on_close_request->completion);
+       CHSC_LOG(0, "on_close");
+       chsc_log_command(on_close_chsc_area);
+       spin_lock_irq(&chsc_lock);
+       ret = chsc_async(on_close_chsc_area, on_close_request);
+       spin_unlock_irq(&chsc_lock);
+       if (ret == -EINPROGRESS) {
+               wait_for_completion(&on_close_request->completion);
+               ret = chsc_examine_irb(on_close_request);
+       }
+       sprintf(dbf, "relret:%d", ret);
+       CHSC_LOG(0, dbf);
+       free_page((unsigned long)on_close_chsc_area);
+       on_close_chsc_area = NULL;
+       kfree(on_close_request);
+       on_close_request = NULL;
+out_unlock:
+       mutex_unlock(&on_close_mutex);
        atomic_inc(&chsc_ready_for_use);
        return 0;
 }