4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_LNET
39 #include <libcfs/libcfs.h>
41 #define LNET_MINOR 240
43 int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data)
45 if (libcfs_ioctl_is_invalid(data)) {
46 CERROR("LNET: ioctl not correctly formatted\n");
50 if (data->ioc_inllen1 != 0)
51 data->ioc_inlbuf1 = &data->ioc_bulk[0];
53 if (data->ioc_inllen2 != 0)
54 data->ioc_inlbuf2 = &data->ioc_bulk[0] +
55 cfs_size_round(data->ioc_inllen1);
60 int libcfs_ioctl_getdata_len(const struct libcfs_ioctl_hdr __user *arg,
63 struct libcfs_ioctl_hdr hdr;
66 if (copy_from_user(&hdr, arg, sizeof(hdr)))
69 if (hdr.ioc_version != LIBCFS_IOCTL_VERSION &&
70 hdr.ioc_version != LIBCFS_IOCTL_VERSION2) {
71 CERROR("LNET: version mismatch expected %#x, got %#x\n",
72 LIBCFS_IOCTL_VERSION, hdr.ioc_version);
81 int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr *buf, __u32 buf_len,
82 const void __user *arg)
86 if (copy_from_user(buf, arg, buf_len))
92 int libcfs_ioctl_popdata(void __user *arg, void *data, int size)
94 if (copy_to_user(arg, data, size))
99 extern struct cfs_psdev_ops libcfs_psdev_ops;
102 libcfs_psdev_open(struct inode * inode, struct file * file)
104 struct libcfs_device_userstate **pdu = NULL;
109 pdu = (struct libcfs_device_userstate **)&file->private_data;
110 if (libcfs_psdev_ops.p_open != NULL)
111 rc = libcfs_psdev_ops.p_open(0, (void *)pdu);
117 /* called when closing /dev/device */
119 libcfs_psdev_release(struct inode * inode, struct file * file)
121 struct libcfs_device_userstate *pdu;
126 pdu = file->private_data;
127 if (libcfs_psdev_ops.p_close != NULL)
128 rc = libcfs_psdev_ops.p_close(0, (void *)pdu);
134 static long libcfs_ioctl(struct file *file,
135 unsigned int cmd, unsigned long arg)
137 struct cfs_psdev_file pfile;
140 if (!capable(CAP_SYS_ADMIN))
143 if (_IOC_TYPE(cmd) != IOC_LIBCFS_TYPE ||
144 _IOC_NR(cmd) < IOC_LIBCFS_MIN_NR ||
145 _IOC_NR(cmd) > IOC_LIBCFS_MAX_NR) {
146 CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
147 _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
151 /* Handle platform-dependent IOC requests */
153 case IOC_LIBCFS_PANIC:
154 if (!cfs_capable(CFS_CAP_SYS_BOOT))
156 panic("debugctl-invoked panic");
158 case IOC_LIBCFS_MEMHOG:
159 if (!cfs_capable(CFS_CAP_SYS_ADMIN))
165 pfile.private_data = file->private_data;
166 if (libcfs_psdev_ops.p_ioctl != NULL)
167 rc = libcfs_psdev_ops.p_ioctl(&pfile, cmd, (void __user *)arg);
173 static struct file_operations libcfs_fops = {
174 unlocked_ioctl: libcfs_ioctl,
175 open : libcfs_psdev_open,
176 release : libcfs_psdev_release
179 struct miscdevice libcfs_dev = {