1 #define DEBUG_SUBSYSTEM S_PORTALS
3 #include <libcfs/libcfs.h>
4 #include <libcfs/kp30.h>
6 #define PORTAL_MINOR 240
10 kportal_daemonize (char *str)
12 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,63))
16 snprintf (current->comm, sizeof (current->comm), "%s", str);
21 kportal_blockallsigs ()
25 SIGNAL_MASK_LOCK(current, flags);
26 sigfillset(¤t->blocked);
28 SIGNAL_MASK_UNLOCK(current, flags);
31 int portal_ioctl_getdata(char *buf, char *end, void *arg)
33 struct portal_ioctl_hdr *hdr;
34 struct portal_ioctl_data *data;
38 hdr = (struct portal_ioctl_hdr *)buf;
39 data = (struct portal_ioctl_data *)buf;
41 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
45 if (hdr->ioc_version != PORTAL_IOCTL_VERSION) {
46 CERROR("PORTALS: version mismatch kernel vs application\n");
50 if (hdr->ioc_len + buf >= end) {
51 CERROR("PORTALS: user buffer exceeds kernel buffer\n");
56 if (hdr->ioc_len < sizeof(struct portal_ioctl_data)) {
57 CERROR("PORTALS: user buffer too small for ioctl\n");
61 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
65 if (portal_ioctl_is_invalid(data)) {
66 CERROR("PORTALS: ioctl not correctly formatted\n");
70 if (data->ioc_inllen1)
71 data->ioc_inlbuf1 = &data->ioc_bulk[0];
73 if (data->ioc_inllen2)
74 data->ioc_inlbuf2 = &data->ioc_bulk[0] +
75 size_round(data->ioc_inllen1);
80 extern struct cfs_psdev_ops libcfs_psdev_ops;
83 libcfs_psdev_open(struct inode * inode, struct file * file)
85 struct portals_device_userstate **pdu = NULL;
90 pdu = (struct portals_device_userstate **)&file->private_data;
91 if (libcfs_psdev_ops.p_open != NULL)
92 rc = libcfs_psdev_ops.p_open(0, (void *)pdu);
98 /* called when closing /dev/device */
100 libcfs_psdev_release(struct inode * inode, struct file * file)
102 struct portals_device_userstate *pdu;
107 pdu = file->private_data;
108 if (libcfs_psdev_ops.p_close != NULL)
109 rc = libcfs_psdev_ops.p_close(0, (void *)pdu);
116 libcfs_ioctl(struct inode *inode, struct file *file,
117 unsigned int cmd, unsigned long arg)
119 struct cfs_psdev_file pfile;
122 if (current->fsuid != 0)
125 if ( _IOC_TYPE(cmd) != IOC_PORTAL_TYPE ||
126 _IOC_NR(cmd) < IOC_PORTAL_MIN_NR ||
127 _IOC_NR(cmd) > IOC_PORTAL_MAX_NR ) {
128 CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
129 _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
133 /* Handle platform-dependent IOC requests */
135 case IOC_PORTAL_PANIC:
136 if (!capable (CAP_SYS_BOOT))
138 panic("debugctl-invoked panic");
140 case IOC_PORTAL_MEMHOG:
141 if (!capable (CAP_SYS_ADMIN))
147 pfile.private_data = file->private_data;
148 if (libcfs_psdev_ops.p_ioctl != NULL)
149 rc = libcfs_psdev_ops.p_ioctl(&pfile, cmd, (void *)arg);
155 static struct file_operations libcfs_fops = {
157 open: libcfs_psdev_open,
158 release: libcfs_psdev_release
161 cfs_psdev_t libcfs_dev = {
167 EXPORT_SYMBOL(kportal_blockallsigs);
168 EXPORT_SYMBOL(kportal_daemonize);