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 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #include <mach/mach_types.h>
41 #include <miscfs/devfs/devfs.h>
43 #define DEBUG_SUBSYSTEM S_LNET
44 #include <libcfs/libcfs.h>
46 int libcfs_ioctl_getdata(char *buf, char *end, void *arg)
48 struct libcfs_ioctl_hdr *hdr;
49 struct libcfs_ioctl_data *data;
53 hdr = (struct libcfs_ioctl_hdr *)buf;
54 data = (struct libcfs_ioctl_data *)buf;
55 /* libcfs_ioctl_data has been copied in by ioctl of osx */
56 memcpy(buf, arg, sizeof(struct libcfs_ioctl_data));
58 if (hdr->ioc_version != LIBCFS_IOCTL_VERSION) {
59 CERROR("LIBCFS: version mismatch kernel vs application\n");
63 if (hdr->ioc_len + buf >= end) {
64 CERROR("LIBCFS: user buffer exceeds kernel buffer\n");
68 if (hdr->ioc_len < sizeof(struct libcfs_ioctl_data)) {
69 CERROR("LIBCFS: user buffer too small for ioctl\n");
72 buf += size_round(sizeof(*data));
74 if (data->ioc_inllen1) {
75 err = copy_from_user(buf, data->ioc_inlbuf1, size_round(data->ioc_inllen1));
78 data->ioc_inlbuf1 = buf;
79 buf += size_round(data->ioc_inllen1);
82 if (data->ioc_inllen2) {
83 copy_from_user(buf, data->ioc_inlbuf2, size_round(data->ioc_inllen2));
86 data->ioc_inlbuf2 = buf;
92 int libcfs_ioctl_popdata(void *arg, void *data, int size)
95 * system call will copy out ioctl arg to user space
97 memcpy(arg, data, size);
101 extern struct cfs_psdev_ops libcfs_psdev_ops;
102 struct libcfs_device_userstate *mdev_state[16];
105 libcfs_psdev_open(dev_t dev, int flags, int devtype, struct proc *p)
107 struct libcfs_device_userstate *mstat = NULL;
112 if (devid > 16) return (ENXIO);
114 if (libcfs_psdev_ops.p_open != NULL)
115 rc = -libcfs_psdev_ops.p_open(0, &mstat);
119 mdev_state[devid] = mstat;
124 libcfs_psdev_close(dev_t dev, int flags, int mode, struct proc *p)
130 if (devid > 16) return (ENXIO);
132 if (libcfs_psdev_ops.p_close != NULL)
133 rc = -libcfs_psdev_ops.p_close(0, mdev_state[devid]);
137 mdev_state[devid] = NULL;
142 libcfs_ioctl (dev_t dev, u_long cmd, caddr_t arg, int flag, struct proc *p)
145 struct cfs_psdev_file pfile;
149 if (devid > 16) return (ENXIO);
155 pfile.private_data = mdev_state[devid];
157 if (libcfs_psdev_ops.p_ioctl != NULL)
158 rc = -libcfs_psdev_ops.p_ioctl(&pfile, cmd, (void *)arg);
164 static struct cdevsw libcfs_devsw =
166 .d_open = libcfs_psdev_open,
167 .d_close = libcfs_psdev_close,
169 .d_write = eno_rdwrt,
170 .d_ioctl = libcfs_ioctl,
172 .d_reset = eno_reset,
174 .d_select = eno_select,
176 .d_strategy = eno_strat,
182 cfs_psdev_t libcfs_dev = {
190 extern spinlock_t trace_cpu_serializer;
191 extern void cfs_sync_init(void);
192 extern void cfs_sync_fini(void);
193 extern int cfs_sysctl_init(void);
194 extern void cfs_sysctl_fini(void);
195 extern int cfs_mem_init(void);
196 extern int cfs_mem_fini(void);
197 extern void raw_page_death_row_clean(void);
198 extern void cfs_thread_agent_init(void);
199 extern void cfs_thread_agent_fini(void);
200 extern void cfs_symbol_init(void);
201 extern void cfs_symbol_fini(void);
203 int libcfs_arch_init(void)
208 cfs_thread_agent_init();
211 spin_lock_init(&trace_cpu_serializer);
216 void libcfs_arch_cleanup(void)
218 spin_lock_done(&trace_cpu_serializer);
221 cfs_thread_agent_fini();