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>
66 #include <linux/lustre_build_version.h>
67 #include <portals/list.h>
68 #include "llog_internal.h"
70 struct semaphore obd_conf_sem; /* serialize configuration commands */
71 struct obd_device obd_dev[MAX_OBD_DEVICES];
72 struct list_head obd_types;
78 /* The following are visible and mutable through /proc/sys/lustre/. */
79 unsigned int obd_fail_loc;
80 unsigned int obd_timeout = 100;
81 char obd_lustre_upcall[128] = "/usr/lib/lustre/lustre_upcall";
82 unsigned int obd_sync_filter; /* = 0, don't sync by default */
85 /* opening /dev/obd */
86 static int obd_class_open(struct inode * inode, struct file * file)
94 /* closing /dev/obd */
95 static int obd_class_release(struct inode * inode, struct file * file)
104 static inline void obd_data2conn(struct lustre_handle *conn,
105 struct obd_ioctl_data *data)
107 memset(conn, 0, sizeof *conn);
108 conn->cookie = data->ioc_cookie;
111 static inline void obd_conn2data(struct obd_ioctl_data *data,
112 struct lustre_handle *conn)
114 data->ioc_cookie = conn->cookie;
117 int class_resolve_dev_name(uint32_t len, char *name)
123 CERROR("No name passed,!\n");
124 GOTO(out, rc = -EINVAL);
126 if (name[len - 1] != 0) {
127 CERROR("Name not nul terminated!\n");
128 GOTO(out, rc = -EINVAL);
131 CDEBUG(D_IOCTL, "device name %s\n", name);
132 dev = class_name2dev(name);
134 CDEBUG(D_IOCTL, "No device for name %s!\n", name);
135 GOTO(out, rc = -EINVAL);
138 CDEBUG(D_IOCTL, "device name %s, dev %d\n", name, dev);
145 int class_handle_ioctl(unsigned int cmd, unsigned long arg)
148 struct obd_ioctl_data *data;
149 struct portals_debug_ioctl_data *debug_data;
150 struct obd_device *obd = NULL;
151 int err = 0, len = 0, serialised = 0;
154 if (current->fsuid != 0)
155 RETURN(err = -EACCES);
157 if ((cmd & 0xffffff00) == ((int)'T') << 8) /* ignore all tty ioctls */
158 RETURN(err = -ENOTTY);
160 /* only for debugging */
161 if (cmd == PTL_IOC_DEBUG_MASK) {
162 debug_data = (struct portals_debug_ioctl_data*)arg;
163 portal_subsystem_debug = debug_data->subs;
164 portal_debug = debug_data->debug;
169 case OBD_IOC_BRW_WRITE:
170 case OBD_IOC_BRW_READ:
171 case OBD_IOC_GETATTR:
172 case ECHO_IOC_ENQUEUE:
173 case ECHO_IOC_CANCEL:
174 case OBD_IOC_CLIENT_RECOVER:
175 case OBD_IOC_CATLOGLIST:
176 case OBD_IOC_LLOG_INFO:
177 case OBD_IOC_LLOG_PRINT:
178 case OBD_IOC_LLOG_CANCEL:
179 case OBD_IOC_LLOG_CHECK:
180 case OBD_IOC_LLOG_REMOVE:
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 /* FIXME hack to liblustre dump, remove when switch
203 data->ioc_pbuf1 = data->ioc_inlbuf1;
204 data->ioc_plen1 = data->ioc_inllen1;
206 if (!data->ioc_plen1 || !data->ioc_pbuf1) {
207 CERROR("No config buffer passed!\n");
208 GOTO(out, err = -EINVAL);
210 err = lustre_cfg_getdata(&buf, data->ioc_plen1,
214 lcfg = (struct lustre_cfg* ) buf;
216 err = class_process_config(lcfg);
217 lustre_cfg_freedata(buf, data->ioc_plen1);
223 char *buf2 = data->ioc_bulk;
224 int remains = data->ioc_inllen1;
226 if (!data->ioc_inlbuf1) {
227 CERROR("No buffer passed!\n");
228 GOTO(out, err = -EINVAL);
232 for (i = 0 ; i < MAX_OBD_DEVICES ; i++) {
235 struct obd_device *obd = &obd_dev[i];
239 if (obd->obd_stopping)
241 else if (obd->obd_set_up)
243 else if (obd->obd_attached)
247 l = snprintf(buf2, remains, "%2d %s %s %s %s %d\n",
248 i, status, obd->obd_type->typ_name,
249 obd->obd_name, obd->obd_uuid.uuid,
250 obd->obd_type->typ_refcnt);
254 CERROR("not enough space for device listing\n");
259 err = copy_to_user((void *)arg, data, len);
265 case OBD_GET_VERSION:
266 if (!data->ioc_inlbuf1) {
267 CERROR("No buffer passed in ioctl\n");
268 GOTO(out, err = -EINVAL);
271 if (strlen(BUILD_VERSION) + 1 > data->ioc_inllen1) {
272 CERROR("ioctl buffer too small to hold version\n");
273 GOTO(out, err = -EINVAL);
276 memcpy(data->ioc_bulk, BUILD_VERSION,
277 strlen(BUILD_VERSION) + 1);
279 err = copy_to_user((void *)arg, data, len);
284 case OBD_IOC_NAME2DEV: {
285 /* Resolve a device name. This does not change the
286 * currently selected device.
290 dev = class_resolve_dev_name(data->ioc_inllen1,
294 GOTO(out, err = -EINVAL);
296 err = copy_to_user((void *)arg, data, sizeof(*data));
302 case OBD_IOC_UUID2DEV: {
303 /* Resolve a device uuid. This does not change the
304 * currently selected device.
307 struct obd_uuid uuid;
309 if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
310 CERROR("No UUID passed!\n");
311 GOTO(out, err = -EINVAL);
313 if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) {
314 CERROR("UUID not NUL terminated!\n");
315 GOTO(out, err = -EINVAL);
318 CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
319 obd_str2uuid(&uuid, data->ioc_inlbuf1);
320 dev = class_uuid2dev(&uuid);
323 CDEBUG(D_IOCTL, "No device for UUID %s!\n",
325 GOTO(out, err = -EINVAL);
328 CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1,
330 err = copy_to_user((void *)arg, data, sizeof(*data));
337 case OBD_IOC_CLOSE_UUID: {
338 struct lustre_peer peer;
339 CDEBUG(D_IOCTL, "closing all connections to uuid %s\n",
341 lustre_uuid_to_peer(data->ioc_inlbuf1, &peer);
347 if (data->ioc_dev >= MAX_OBD_DEVICES) {
348 CERROR("OBD ioctl: No device\n");
349 GOTO(out, err = -EINVAL);
351 obd = &obd_dev[data->ioc_dev];
352 if (!(obd && obd->obd_set_up) || obd->obd_stopping) {
353 CERROR("OBD ioctl: device not setup %d \n", data->ioc_dev);
354 GOTO(out, err = -EINVAL);
358 case OBD_IOC_NO_TRANSNO: {
359 if (!obd->obd_attached) {
360 CERROR("Device %d not attached\n", obd->obd_minor);
361 GOTO(out, err = -ENODEV);
364 "disabling committed-transno notifications on %d\n",
366 obd->obd_no_transno = 1;
371 err = obd_iocontrol(cmd, obd->obd_self_export, len, data, NULL);
375 err = copy_to_user((void *)arg, data, len);
384 obd_ioctl_freedata(buf, len);
388 } /* class_handle_ioctl */
392 #define OBD_MINOR 241
394 /* to control /dev/obd */
395 static int obd_class_ioctl(struct inode *inode, struct file *filp,
396 unsigned int cmd, unsigned long arg)
398 return class_handle_ioctl(cmd, arg);
401 /* declare character device */
402 static struct file_operations obd_psdev_fops = {
403 ioctl: obd_class_ioctl, /* ioctl */
404 open: obd_class_open, /* open */
405 release: obd_class_release, /* release */
409 static struct miscdevice obd_psdev = {
415 void *obd_psdev = NULL;
418 EXPORT_SYMBOL(obd_dev);
419 EXPORT_SYMBOL(obdo_cachep);
420 EXPORT_SYMBOL(obd_memory);
421 EXPORT_SYMBOL(obd_memmax);
422 EXPORT_SYMBOL(obd_fail_loc);
423 EXPORT_SYMBOL(obd_timeout);
424 EXPORT_SYMBOL(obd_lustre_upcall);
425 EXPORT_SYMBOL(obd_sync_filter);
426 EXPORT_SYMBOL(ptlrpc_put_connection_superhack);
427 EXPORT_SYMBOL(ptlrpc_abort_inflight_superhack);
428 EXPORT_SYMBOL(proc_lustre_root);
430 EXPORT_SYMBOL(class_register_type);
431 EXPORT_SYMBOL(class_unregister_type);
432 EXPORT_SYMBOL(class_get_type);
433 EXPORT_SYMBOL(class_put_type);
434 EXPORT_SYMBOL(class_name2dev);
435 EXPORT_SYMBOL(class_name2obd);
436 EXPORT_SYMBOL(class_uuid2dev);
437 EXPORT_SYMBOL(class_uuid2obd);
438 EXPORT_SYMBOL(class_find_client_obd);
439 EXPORT_SYMBOL(__class_export_put);
440 EXPORT_SYMBOL(class_new_export);
441 EXPORT_SYMBOL(class_unlink_export);
442 EXPORT_SYMBOL(class_import_get);
443 EXPORT_SYMBOL(class_import_put);
444 EXPORT_SYMBOL(class_new_import);
445 EXPORT_SYMBOL(class_destroy_import);
446 EXPORT_SYMBOL(class_connect);
447 EXPORT_SYMBOL(class_conn2export);
448 EXPORT_SYMBOL(class_exp2obd);
449 EXPORT_SYMBOL(class_conn2obd);
450 EXPORT_SYMBOL(class_exp2cliimp);
451 EXPORT_SYMBOL(class_conn2cliimp);
452 EXPORT_SYMBOL(class_disconnect);
453 EXPORT_SYMBOL(class_disconnect_exports);
455 EXPORT_SYMBOL(osic_init);
456 EXPORT_SYMBOL(osic_release);
457 EXPORT_SYMBOL(osic_add_one);
458 EXPORT_SYMBOL(osic_wait);
459 EXPORT_SYMBOL(osic_complete_one);
462 EXPORT_SYMBOL(class_uuid_unparse);
463 EXPORT_SYMBOL(lustre_uuid_to_peer);
465 EXPORT_SYMBOL(class_handle_hash);
466 EXPORT_SYMBOL(class_handle_unhash);
467 EXPORT_SYMBOL(class_handle2object);
470 EXPORT_SYMBOL(class_get_profile);
471 EXPORT_SYMBOL(class_process_config);
472 EXPORT_SYMBOL(class_config_parse_llog);
473 EXPORT_SYMBOL(class_config_dump_llog);
474 EXPORT_SYMBOL(class_attach);
475 EXPORT_SYMBOL(class_setup);
476 EXPORT_SYMBOL(class_cleanup);
477 EXPORT_SYMBOL(class_detach);
480 int obd_proc_read_version(char *page, char **start, off_t off, int count,
481 int *eof, void *data)
484 return snprintf(page, count, "%s\n", BUILD_VERSION);
487 int obd_proc_read_pinger(char *page, char **start, off_t off, int count,
488 int *eof, void *data)
491 return snprintf(page, count, "%s\n",
500 /* Root for /proc/fs/lustre */
501 struct proc_dir_entry *proc_lustre_root = NULL;
502 struct lprocfs_vars lprocfs_base[] = {
503 { "version", obd_proc_read_version, NULL, NULL },
504 { "pinger", obd_proc_read_pinger, NULL, NULL },
508 static void *obd_device_list_seq_start(struct seq_file *p, loff_t*pos)
510 if (*pos >= MAX_OBD_DEVICES)
512 return &obd_dev[*pos];
515 static void obd_device_list_seq_stop(struct seq_file *p, void *v)
519 static void *obd_device_list_seq_next(struct seq_file *p, void *v, loff_t *pos)
522 if (*pos >= MAX_OBD_DEVICES)
524 return &obd_dev[*pos];
527 static int obd_device_list_seq_show(struct seq_file *p, void *v)
529 struct obd_device *obd = (struct obd_device *)v;
530 int index = obd - &obd_dev[0];
535 if (obd->obd_stopping)
537 else if (obd->obd_set_up)
539 else if (obd->obd_attached)
544 return seq_printf(p, "%3d %s %s %s %s %d\n",
545 (int)index, status, obd->obd_type->typ_name,
546 obd->obd_name, obd->obd_uuid.uuid,
547 atomic_read(&obd->obd_refcount));
550 struct seq_operations obd_device_list_sops = {
551 .start = obd_device_list_seq_start,
552 .stop = obd_device_list_seq_stop,
553 .next = obd_device_list_seq_next,
554 .show = obd_device_list_seq_show,
557 static int obd_device_list_open(struct inode *inode, struct file *file)
559 struct proc_dir_entry *dp = PDE(inode);
560 struct seq_file *seq;
561 int rc = seq_open(file, &obd_device_list_sops);
566 seq = file->private_data;
567 seq->private = dp->data;
572 struct file_operations obd_device_list_fops = {
573 .open = obd_device_list_open,
576 .release = seq_release,
581 static int __init init_obdclass(void)
583 int init_obdclass(void)
586 struct obd_device *obd;
588 struct proc_dir_entry *entry;
593 printk(KERN_INFO "Lustre: OBD class driver Build Version: "
594 BUILD_VERSION", info@clusterfs.com\n");
596 class_init_uuidlist();
597 err = class_handle_init();
601 sema_init(&obd_conf_sem, 1);
602 INIT_LIST_HEAD(&obd_types);
604 err = misc_register(&obd_psdev);
606 CERROR("cannot register %d err %d\n", OBD_MINOR, err);
610 /* This struct is already zerod for us (static global) */
611 for (i = 0, obd = obd_dev; i < MAX_OBD_DEVICES; i++, obd++)
614 err = obd_init_caches();
623 proc_lustre_root = proc_mkdir("lustre", proc_root_fs);
624 if (!proc_lustre_root) {
626 "LustreError: error registering /proc/fs/lustre\n");
629 proc_version = lprocfs_add_vars(proc_lustre_root, lprocfs_base, NULL);
630 entry = create_proc_entry("devices", 0444, proc_lustre_root);
632 printk(KERN_ERR "LustreError: error registering "
633 "/proc/fs/lustre/devices\n");
634 lprocfs_remove(proc_lustre_root);
637 entry->proc_fops = &obd_device_list_fops;
643 static void /*__exit*/ cleanup_obdclass(void)
645 static void cleanup_obdclass(void)
651 misc_deregister(&obd_psdev);
652 for (i = 0; i < MAX_OBD_DEVICES; i++) {
653 struct obd_device *obd = &obd_dev[i];
654 if (obd->obd_type && obd->obd_set_up &&
655 OBT(obd) && OBP(obd, detach)) {
656 /* XXX should this call generic detach otherwise? */
657 OBP(obd, detach)(obd);
661 obd_cleanup_caches();
666 if (proc_lustre_root) {
667 lprocfs_remove(proc_lustre_root);
668 proc_lustre_root = NULL;
672 class_handle_cleanup();
673 class_exit_uuidlist();
675 leaked = atomic_read(&obd_memory);
676 CDEBUG(leaked ? D_ERROR : D_INFO,
677 "obd mem max: %d leaked: %d\n", obd_memmax, leaked);
682 /* Check that we're building against the appropriate version of the Lustre
685 #include <linux/lustre_version.h>
686 #define LUSTRE_MIN_VERSION 28
687 #define LUSTRE_MAX_VERSION 32
688 #if (LUSTRE_KERNEL_VERSION < LUSTRE_MIN_VERSION)
689 # error Cannot continue: Your Lustre kernel patch is older than the sources
690 #elif (LUSTRE_KERNEL_VERSION > LUSTRE_MAX_VERSION)
691 # error Cannot continue: Your Lustre sources are older than the kernel patch
694 # warning "Lib Lustre - no versioning information"
698 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
699 MODULE_DESCRIPTION("Lustre Class Driver Build Version: " BUILD_VERSION);
700 MODULE_LICENSE("GPL");
702 module_init(init_obdclass);
703 module_exit(cleanup_obdclass);