1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2012, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
39 #define DEBUG_SUBSYSTEM S_LNET
41 #include <libcfs/libcfs.h>
43 #define LNET_MINOR 240
45 int libcfs_ioctl_getdata(char *buf, char *end, void *arg)
47 struct libcfs_ioctl_hdr *hdr;
48 struct libcfs_ioctl_data *data;
52 hdr = (struct libcfs_ioctl_hdr *)buf;
53 data = (struct libcfs_ioctl_data *)buf;
55 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
59 if (hdr->ioc_version != LIBCFS_IOCTL_VERSION) {
60 CERROR("PORTALS: version mismatch kernel vs application\n");
64 if (hdr->ioc_len + buf >= end) {
65 CERROR("PORTALS: user buffer exceeds kernel buffer\n");
70 if (hdr->ioc_len < sizeof(struct libcfs_ioctl_data)) {
71 CERROR("PORTALS: user buffer too small for ioctl\n");
75 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
79 if (libcfs_ioctl_is_invalid(data)) {
80 CERROR("PORTALS: ioctl not correctly formatted\n");
84 if (data->ioc_inllen1)
85 data->ioc_inlbuf1 = &data->ioc_bulk[0];
87 if (data->ioc_inllen2)
88 data->ioc_inlbuf2 = &data->ioc_bulk[0] +
89 cfs_size_round(data->ioc_inllen1);
94 int libcfs_ioctl_popdata(void *arg, void *data, int size)
96 if (copy_to_user((char *)arg, data, size))
101 extern struct cfs_psdev_ops libcfs_psdev_ops;
104 libcfs_psdev_open(struct inode * inode, struct file * file)
106 struct libcfs_device_userstate **pdu = NULL;
111 pdu = (struct libcfs_device_userstate **)&file->private_data;
112 if (libcfs_psdev_ops.p_open != NULL)
113 rc = libcfs_psdev_ops.p_open(0, (void *)pdu);
119 /* called when closing /dev/device */
121 libcfs_psdev_release(struct inode * inode, struct file * file)
123 struct libcfs_device_userstate *pdu;
128 pdu = file->private_data;
129 if (libcfs_psdev_ops.p_close != NULL)
130 rc = libcfs_psdev_ops.p_close(0, (void *)pdu);
137 #ifdef HAVE_UNLOCKED_IOCTL
138 static long libcfs_ioctl(struct file *file,
139 unsigned int cmd, unsigned long arg)
141 static int libcfs_ioctl(struct inode *inode, struct file *file,
142 unsigned int cmd, unsigned long arg)
145 struct cfs_psdev_file pfile;
148 if (current_fsuid() != 0)
151 if ( _IOC_TYPE(cmd) != IOC_LIBCFS_TYPE ||
152 _IOC_NR(cmd) < IOC_LIBCFS_MIN_NR ||
153 _IOC_NR(cmd) > IOC_LIBCFS_MAX_NR ) {
154 CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
155 _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
159 /* Handle platform-dependent IOC requests */
161 case IOC_LIBCFS_PANIC:
162 if (!cfs_capable(CFS_CAP_SYS_BOOT))
164 panic("debugctl-invoked panic");
166 case IOC_LIBCFS_MEMHOG:
167 if (!cfs_capable(CFS_CAP_SYS_ADMIN))
173 pfile.private_data = file->private_data;
174 if (libcfs_psdev_ops.p_ioctl != NULL)
175 rc = libcfs_psdev_ops.p_ioctl(&pfile, cmd, (void *)arg);
181 static struct file_operations libcfs_fops = {
182 #ifdef HAVE_UNLOCKED_IOCTL
183 unlocked_ioctl: libcfs_ioctl,
187 open : libcfs_psdev_open,
188 release : libcfs_psdev_release
191 cfs_psdev_t libcfs_dev = {