1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Object Devices Class Driver
6 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * These are the only exported functions, they provide some generic
24 * infrastructure for managing object devices
27 #define DEBUG_SUBSYSTEM S_CLASS
29 # define EXPORT_SYMTAB
32 #include <linux/config.h> /* for CONFIG_PROC_FS */
33 #include <linux/module.h>
34 #include <linux/errno.h>
35 #include <linux/kernel.h>
36 #include <linux/major.h>
37 #include <linux/sched.h>
39 #include <linux/slab.h>
40 #include <linux/ioport.h>
41 #include <linux/fcntl.h>
42 #include <linux/delay.h>
43 #include <linux/skbuff.h>
44 #include <linux/proc_fs.h>
46 #include <linux/poll.h>
47 #include <linux/init.h>
48 #include <linux/list.h>
49 #include <linux/highmem.h>
51 #include <asm/ioctls.h>
52 #include <asm/system.h>
54 #include <asm/uaccess.h>
55 #include <linux/miscdevice.h>
56 #include <linux/smp_lock.h>
57 #include <linux/seq_file.h>
59 # include <liblustre.h>
62 #include <linux/obd_support.h>
63 #include <linux/obd_class.h>
64 #include <linux/lustre_debug.h>
65 #include <linux/lprocfs_status.h>
67 #include <linux/lustre_build_version.h>
68 #include <linux/lustre_version.h>
70 #include <libcfs/list.h>
73 /* liblustre workaround */
74 atomic_t portal_kmemory = {0};
77 struct obd_device obd_dev[MAX_OBD_DEVICES];
78 struct list_head obd_types;
79 spinlock_t obd_dev_lock;
87 /* The following are visible and mutable through /proc/sys/lustre/. */
88 unsigned int obd_fail_loc;
89 unsigned int obd_dump_on_timeout;
90 unsigned int obd_timeout = 100;
91 unsigned int ldlm_timeout = 6;
92 char obd_lustre_upcall[128] = "DEFAULT"; /* or NONE or /full/path/to/upcall */
93 unsigned int obd_sync_filter = 1; /* = 1, sync by default */
95 DECLARE_WAIT_QUEUE_HEAD(obd_race_waitq);
99 unsigned int obd_print_fail_loc(void)
101 CWARN("obd_fail_loc = %x\n", obd_fail_loc);
105 /* opening /dev/obd */
106 static int obd_class_open(struct inode * inode, struct file * file)
114 /* closing /dev/obd */
115 static int obd_class_release(struct inode * inode, struct file * file)
124 static inline void obd_data2conn(struct lustre_handle *conn,
125 struct obd_ioctl_data *data)
127 memset(conn, 0, sizeof *conn);
128 conn->cookie = data->ioc_cookie;
131 static inline void obd_conn2data(struct obd_ioctl_data *data,
132 struct lustre_handle *conn)
134 data->ioc_cookie = conn->cookie;
137 int class_resolve_dev_name(uint32_t len, char *name)
143 CERROR("No name passed,!\n");
144 GOTO(out, rc = -EINVAL);
146 if (name[len - 1] != 0) {
147 CERROR("Name not nul terminated!\n");
148 GOTO(out, rc = -EINVAL);
151 CDEBUG(D_IOCTL, "device name %s\n", name);
152 dev = class_name2dev(name);
154 CDEBUG(D_IOCTL, "No device for name %s!\n", name);
155 GOTO(out, rc = -EINVAL);
158 CDEBUG(D_IOCTL, "device name %s, dev %d\n", name, dev);
165 int class_handle_ioctl(unsigned int cmd, unsigned long arg)
168 struct obd_ioctl_data *data;
169 struct portals_debug_ioctl_data *debug_data;
170 struct obd_device *obd = NULL;
171 int err = 0, len = 0;
174 if (current->fsuid != 0)
175 RETURN(err = -EACCES);
177 if ((cmd & 0xffffff00) == ((int)'T') << 8) /* ignore all tty ioctls */
178 RETURN(err = -ENOTTY);
180 /* only for debugging */
181 if (cmd == PTL_IOC_DEBUG_MASK) {
182 debug_data = (struct portals_debug_ioctl_data*)arg;
183 portal_subsystem_debug = debug_data->subs;
184 portal_debug = debug_data->debug;
188 CDEBUG(D_IOCTL, "cmd = %x, obd = %p\n", cmd, obd);
189 if (obd_ioctl_getdata(&buf, &len, (void *)arg)) {
190 CERROR("OBD ioctl: data error\n");
191 GOTO(out, err = -EINVAL);
193 data = (struct obd_ioctl_data *)buf;
196 case OBD_IOC_PROCESS_CFG: {
198 struct lustre_cfg *lcfg;
200 if (!data->ioc_plen1 || !data->ioc_pbuf1) {
201 CERROR("No config buffer passed!\n");
202 GOTO(out, err = -EINVAL);
204 err = lustre_cfg_getdata(&buf, data->ioc_plen1,
208 lcfg = (struct lustre_cfg* ) buf;
210 err = class_process_config(lcfg);
211 lustre_cfg_freedata(buf, data->ioc_plen1);
215 case OBD_GET_VERSION:
216 if (!data->ioc_inlbuf1) {
217 CERROR("No buffer passed in ioctl\n");
218 GOTO(out, err = -EINVAL);
221 if (strlen(BUILD_VERSION) + 1 > data->ioc_inllen1) {
222 CERROR("ioctl buffer too small to hold version\n");
223 GOTO(out, err = -EINVAL);
226 memcpy(data->ioc_bulk, BUILD_VERSION,
227 strlen(BUILD_VERSION) + 1);
229 err = copy_to_user((void *)arg, data, len);
234 case OBD_IOC_NAME2DEV: {
235 /* Resolve a device name. This does not change the
236 * currently selected device.
240 dev = class_resolve_dev_name(data->ioc_inllen1,
244 GOTO(out, err = -EINVAL);
246 err = copy_to_user((void *)arg, data, sizeof(*data));
252 case OBD_IOC_UUID2DEV: {
253 /* Resolve a device uuid. This does not change the
254 * currently selected device.
257 struct obd_uuid uuid;
259 if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
260 CERROR("No UUID passed!\n");
261 GOTO(out, err = -EINVAL);
263 if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) {
264 CERROR("UUID not NUL terminated!\n");
265 GOTO(out, err = -EINVAL);
268 CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
269 obd_str2uuid(&uuid, data->ioc_inlbuf1);
270 dev = class_uuid2dev(&uuid);
273 CDEBUG(D_IOCTL, "No device for UUID %s!\n",
275 GOTO(out, err = -EINVAL);
278 CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1,
280 err = copy_to_user((void *)arg, data, sizeof(*data));
287 case OBD_IOC_CLOSE_UUID: {
290 CDEBUG(D_IOCTL, "closing all connections to uuid %s\n",
292 lustre_uuid_to_peer(data->ioc_inlbuf1, &peer_nal, &peer_nid);
298 if (data->ioc_dev >= MAX_OBD_DEVICES) {
299 CERROR("OBD ioctl: No device\n");
300 GOTO(out, err = -EINVAL);
302 obd = &obd_dev[data->ioc_dev];
303 if (!(obd && obd->obd_set_up) || obd->obd_stopping) {
304 CERROR("OBD ioctl: device not setup %d \n", data->ioc_dev);
305 GOTO(out, err = -EINVAL);
309 case OBD_IOC_NO_TRANSNO: {
310 if (!obd->obd_attached) {
311 CERROR("Device %d not attached\n", obd->obd_minor);
312 GOTO(out, err = -ENODEV);
315 "disabling committed-transno notifications on %d\n",
317 obd->obd_no_transno = 1;
322 err = obd_iocontrol(cmd, obd->obd_self_export, len, data, NULL);
326 err = copy_to_user((void *)arg, data, len);
335 obd_ioctl_freedata(buf, len);
337 } /* class_handle_ioctl */
341 #define OBD_MINOR 241
343 /* to control /dev/obd */
344 static int obd_class_ioctl(struct inode *inode, struct file *filp,
345 unsigned int cmd, unsigned long arg)
347 return class_handle_ioctl(cmd, arg);
350 /* declare character device */
351 static struct file_operations obd_psdev_fops = {
352 .owner = THIS_MODULE,
353 .ioctl = obd_class_ioctl, /* ioctl */
354 .open = obd_class_open, /* open */
355 .release = obd_class_release, /* release */
359 static struct miscdevice obd_psdev = {
362 .fops = &obd_psdev_fops,
365 void *obd_psdev = NULL;
368 EXPORT_SYMBOL(obd_dev);
369 EXPORT_SYMBOL(obdo_cachep);
370 EXPORT_SYMBOL(obd_fail_loc);
371 EXPORT_SYMBOL(obd_print_fail_loc);
372 EXPORT_SYMBOL(obd_race_waitq);
373 EXPORT_SYMBOL(obd_dump_on_timeout);
374 EXPORT_SYMBOL(ldlm_timeout);
375 EXPORT_SYMBOL(obd_timeout);
376 EXPORT_SYMBOL(obd_lustre_upcall);
377 EXPORT_SYMBOL(obd_sync_filter);
378 EXPORT_SYMBOL(ptlrpc_put_connection_superhack);
379 EXPORT_SYMBOL(ptlrpc_abort_inflight_superhack);
380 EXPORT_SYMBOL(proc_lustre_root);
382 EXPORT_SYMBOL(class_register_type);
383 EXPORT_SYMBOL(class_unregister_type);
384 EXPORT_SYMBOL(class_get_type);
385 EXPORT_SYMBOL(class_put_type);
386 EXPORT_SYMBOL(class_name2dev);
387 EXPORT_SYMBOL(class_name2obd);
388 EXPORT_SYMBOL(class_uuid2dev);
389 EXPORT_SYMBOL(class_uuid2obd);
390 EXPORT_SYMBOL(class_find_client_obd);
391 EXPORT_SYMBOL(class_devices_in_group);
392 EXPORT_SYMBOL(__class_export_put);
393 EXPORT_SYMBOL(class_new_export);
394 EXPORT_SYMBOL(class_unlink_export);
395 EXPORT_SYMBOL(class_import_get);
396 EXPORT_SYMBOL(class_import_put);
397 EXPORT_SYMBOL(class_new_import);
398 EXPORT_SYMBOL(class_destroy_import);
399 EXPORT_SYMBOL(class_connect);
400 EXPORT_SYMBOL(class_conn2export);
401 EXPORT_SYMBOL(class_exp2obd);
402 EXPORT_SYMBOL(class_conn2obd);
403 EXPORT_SYMBOL(class_exp2cliimp);
404 EXPORT_SYMBOL(class_conn2cliimp);
405 EXPORT_SYMBOL(class_disconnect);
406 EXPORT_SYMBOL(class_disconnect_exports);
407 EXPORT_SYMBOL(class_disconnect_stale_exports);
409 EXPORT_SYMBOL(oig_init);
410 EXPORT_SYMBOL(oig_release);
411 EXPORT_SYMBOL(oig_add_one);
412 EXPORT_SYMBOL(oig_wait);
413 EXPORT_SYMBOL(oig_complete_one);
416 EXPORT_SYMBOL(class_uuid_unparse);
417 EXPORT_SYMBOL(lustre_uuid_to_peer);
419 EXPORT_SYMBOL(class_handle_hash);
420 EXPORT_SYMBOL(class_handle_unhash);
421 EXPORT_SYMBOL(class_handle2object);
424 EXPORT_SYMBOL(class_get_profile);
425 EXPORT_SYMBOL(class_del_profile);
426 EXPORT_SYMBOL(class_process_config);
427 EXPORT_SYMBOL(class_config_process_llog);
428 EXPORT_SYMBOL(class_config_dump_llog);
431 EXPORT_SYMBOL(mea_name2idx);
432 EXPORT_SYMBOL(raw_name2idx);
435 int obd_proc_read_version(char *page, char **start, off_t off, int count,
436 int *eof, void *data)
439 return snprintf(page, count, "%s\n", BUILD_VERSION);
442 int obd_proc_read_kernel_version(char *page, char **start, off_t off, int count,
443 int *eof, void *data)
446 return snprintf(page, count, "%u\n", LUSTRE_KERNEL_VERSION);
449 int obd_proc_read_pinger(char *page, char **start, off_t off, int count,
450 int *eof, void *data)
453 return snprintf(page, count, "%s\n",
463 /* FIXME move these staff to proper place */
464 int (*lustre_secinit_downcall_handler)(const char *buffer,
466 EXPORT_SYMBOL(lustre_secinit_downcall_handler);
468 int obd_proc_write_secinit(struct file *file, const char *buffer,
469 unsigned long count, void *data)
473 if (lustre_secinit_downcall_handler) {
474 rc = (*lustre_secinit_downcall_handler)((char *)buffer, count);
484 /* Root for /proc/fs/lustre */
485 struct proc_dir_entry *proc_lustre_root = NULL;
486 struct lprocfs_vars lprocfs_base[] = {
487 { "version", obd_proc_read_version, NULL, NULL },
488 { "kernel_version", obd_proc_read_kernel_version, NULL, NULL },
489 { "pinger", obd_proc_read_pinger, NULL, NULL },
491 { "secinit", NULL, obd_proc_write_secinit, NULL },
496 static void *obd_device_list_seq_start(struct seq_file *p, loff_t*pos)
498 if (*pos >= MAX_OBD_DEVICES)
500 return &obd_dev[*pos];
503 static void obd_device_list_seq_stop(struct seq_file *p, void *v)
507 static void *obd_device_list_seq_next(struct seq_file *p, void *v, loff_t *pos)
510 if (*pos >= MAX_OBD_DEVICES)
512 return &obd_dev[*pos];
515 static int obd_device_list_seq_show(struct seq_file *p, void *v)
517 struct obd_device *obd = (struct obd_device *)v;
518 int index = obd - &obd_dev[0];
523 if (obd->obd_stopping)
525 else if (obd->obd_set_up)
527 else if (obd->obd_attached)
532 return seq_printf(p, "%3d %s %s %s %s %d\n",
533 (int)index, status, obd->obd_type->typ_name,
534 obd->obd_name, obd->obd_uuid.uuid,
535 atomic_read(&obd->obd_refcount));
538 struct seq_operations obd_device_list_sops = {
539 .start = obd_device_list_seq_start,
540 .stop = obd_device_list_seq_stop,
541 .next = obd_device_list_seq_next,
542 .show = obd_device_list_seq_show,
545 static int obd_device_list_open(struct inode *inode, struct file *file)
547 struct proc_dir_entry *dp = PDE(inode);
548 struct seq_file *seq;
549 int rc = seq_open(file, &obd_device_list_sops);
554 seq = file->private_data;
555 seq->private = dp->data;
560 struct file_operations obd_device_list_fops = {
561 .owner = THIS_MODULE,
562 .open = obd_device_list_open,
565 .release = seq_release,
570 static int __init init_obdclass(void)
572 int init_obdclass(void)
575 struct obd_device *obd;
577 struct proc_dir_entry *entry;
582 printk(KERN_INFO "Lustre: OBD class driver Build Version: "
583 BUILD_VERSION", info@clusterfs.com\n");
585 class_init_uuidlist();
586 err = class_handle_init();
590 spin_lock_init(&obd_dev_lock);
591 INIT_LIST_HEAD(&obd_types);
593 err = misc_register(&obd_psdev);
595 CERROR("cannot register %d err %d\n", OBD_MINOR, err);
599 /* This struct is already zerod for us (static global) */
600 for (i = 0, obd = obd_dev; i < MAX_OBD_DEVICES; i++, obd++)
603 err = obd_init_caches();
612 proc_lustre_root = proc_mkdir("lustre", proc_root_fs);
613 if (!proc_lustre_root) {
615 "LustreError: error registering /proc/fs/lustre\n");
618 proc_version = lprocfs_add_vars(proc_lustre_root, lprocfs_base, NULL);
619 entry = create_proc_entry("devices", 0444, proc_lustre_root);
621 printk(KERN_ERR "LustreError: error registering "
622 "/proc/fs/lustre/devices\n");
623 lprocfs_remove(proc_lustre_root);
626 entry->proc_fops = &obd_device_list_fops;
631 /* liblustre doesn't call cleanup_obdclass, apparently. we carry on in this
632 * ifdef to the end of the file to cover module and versioning goo.*/
635 static void cleanup_obdclass(void)
640 misc_deregister(&obd_psdev);
641 for (i = 0; i < MAX_OBD_DEVICES; i++) {
642 struct obd_device *obd = &obd_dev[i];
643 if (obd->obd_type && obd->obd_set_up &&
644 OBT(obd) && OBP(obd, detach)) {
645 /* XXX should this call generic detach otherwise? */
646 OBP(obd, detach)(obd);
650 obd_cleanup_caches();
653 if (proc_lustre_root) {
654 lprocfs_remove(proc_lustre_root);
655 proc_lustre_root = NULL;
659 class_handle_cleanup();
660 class_exit_uuidlist();
664 /* Check that we're building against the appropriate version of the Lustre
666 #include <linux/lustre_version.h>
667 #define LUSTRE_MIN_VERSION 500
668 #define LUSTRE_MAX_VERSION 500
669 #if (LUSTRE_KERNEL_VERSION < LUSTRE_MIN_VERSION)
670 # error Cannot continue: Your Lustre kernel patch is older than the sources
671 #elif (LUSTRE_KERNEL_VERSION > LUSTRE_MAX_VERSION)
672 # error Cannot continue: Your Lustre sources are older than the kernel patch
675 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
676 MODULE_DESCRIPTION("Lustre Class Driver Build Version: " BUILD_VERSION);
677 MODULE_LICENSE("GPL");
679 module_init(init_obdclass);
680 module_exit(cleanup_obdclass);