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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #define DEBUG_SUBSYSTEM S_CLASS
34 # include <linux/atomic.h>
36 #include "../include/obd_support.h"
37 #include "../include/obd_class.h"
38 #include "../../include/linux/lnet/lnetctl.h"
39 #include "../include/lustre_debug.h"
40 #include "../include/lprocfs_status.h"
41 #include <linux/list.h>
42 #include "../include/cl_object.h"
43 #include "../include/lustre/lustre_ioctl.h"
44 #include "llog_internal.h"
46 struct obd_device *obd_devs[MAX_OBD_DEVICES];
47 struct list_head obd_types;
48 DEFINE_RWLOCK(obd_dev_lock);
50 /* The following are visible and mutable through /sys/fs/lustre. */
51 unsigned int obd_debug_peer_on_timeout;
52 EXPORT_SYMBOL(obd_debug_peer_on_timeout);
53 unsigned int obd_dump_on_timeout;
54 EXPORT_SYMBOL(obd_dump_on_timeout);
55 unsigned int obd_dump_on_eviction;
56 EXPORT_SYMBOL(obd_dump_on_eviction);
57 unsigned long obd_max_dirty_pages;
58 EXPORT_SYMBOL(obd_max_dirty_pages);
59 atomic_long_t obd_dirty_pages;
60 EXPORT_SYMBOL(obd_dirty_pages);
61 unsigned int obd_timeout = OBD_TIMEOUT_DEFAULT; /* seconds */
62 EXPORT_SYMBOL(obd_timeout);
63 unsigned int obd_timeout_set;
64 EXPORT_SYMBOL(obd_timeout_set);
65 /* Adaptive timeout defs here instead of ptlrpc module for /sys/fs/ access */
67 EXPORT_SYMBOL(at_min);
68 unsigned int at_max = 600;
69 EXPORT_SYMBOL(at_max);
70 unsigned int at_history = 600;
71 EXPORT_SYMBOL(at_history);
72 int at_early_margin = 5;
73 EXPORT_SYMBOL(at_early_margin);
75 EXPORT_SYMBOL(at_extra);
77 atomic_long_t obd_dirty_transit_pages;
78 EXPORT_SYMBOL(obd_dirty_transit_pages);
80 char obd_jobid_var[JOBSTATS_JOBID_VAR_MAX_LEN + 1] = JOBSTATS_DISABLE;
81 char obd_jobid_node[LUSTRE_JOBID_SIZE + 1];
83 /* Get jobid of current process from stored variable or calculate
84 * it from pid and user_id.
86 * Historically this was also done by reading the environment variable
87 * stored in between the "env_start" & "env_end" of task struct.
88 * This is now deprecated.
90 int lustre_get_jobid(char *jobid)
92 memset(jobid, 0, LUSTRE_JOBID_SIZE);
93 /* Jobstats isn't enabled */
94 if (strcmp(obd_jobid_var, JOBSTATS_DISABLE) == 0)
97 /* Use process name + fsuid as jobid */
98 if (strcmp(obd_jobid_var, JOBSTATS_PROCNAME_UID) == 0) {
99 snprintf(jobid, LUSTRE_JOBID_SIZE, "%s.%u",
101 from_kuid(&init_user_ns, current_fsuid()));
105 /* Whole node dedicated to single job */
106 if (strcmp(obd_jobid_var, JOBSTATS_NODELOCAL) == 0) {
107 strcpy(jobid, obd_jobid_node);
113 EXPORT_SYMBOL(lustre_get_jobid);
115 static int class_resolve_dev_name(__u32 len, const char *name)
121 CERROR("No name passed,!\n");
125 if (name[len - 1] != 0) {
126 CERROR("Name not nul terminated!\n");
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);
139 CDEBUG(D_IOCTL, "device name %s, dev %d\n", name, dev);
146 int class_handle_ioctl(unsigned int cmd, unsigned long arg)
149 struct obd_ioctl_data *data;
150 struct libcfs_debug_ioctl_data *debug_data;
151 struct obd_device *obd = NULL;
152 int err = 0, len = 0;
154 /* only for debugging */
155 if (cmd == LIBCFS_IOC_DEBUG_MASK) {
156 debug_data = (struct libcfs_debug_ioctl_data *)arg;
157 libcfs_subsystem_debug = debug_data->subs;
158 libcfs_debug = debug_data->debug;
162 CDEBUG(D_IOCTL, "cmd = %x\n", cmd);
163 if (obd_ioctl_getdata(&buf, &len, (void __user *)arg)) {
164 CERROR("OBD ioctl: data error\n");
167 data = (struct obd_ioctl_data *)buf;
170 case OBD_IOC_PROCESS_CFG: {
171 struct lustre_cfg *lcfg;
173 if (!data->ioc_plen1 || !data->ioc_pbuf1) {
174 CERROR("No config buffer passed!\n");
178 lcfg = kzalloc(data->ioc_plen1, GFP_NOFS);
183 err = copy_from_user(lcfg, data->ioc_pbuf1, data->ioc_plen1);
185 err = lustre_cfg_sanity_check(lcfg, data->ioc_plen1);
187 err = class_process_config(lcfg);
193 case OBD_GET_VERSION:
194 if (!data->ioc_inlbuf1) {
195 CERROR("No buffer passed in ioctl\n");
200 if (strlen(LUSTRE_VERSION_STRING) + 1 > data->ioc_inllen1) {
201 CERROR("ioctl buffer too small to hold version\n");
206 memcpy(data->ioc_bulk, LUSTRE_VERSION_STRING,
207 strlen(LUSTRE_VERSION_STRING) + 1);
209 err = obd_ioctl_popdata((void __user *)arg, data, len);
214 case OBD_IOC_NAME2DEV: {
215 /* Resolve a device name. This does not change the
216 * currently selected device.
220 dev = class_resolve_dev_name(data->ioc_inllen1,
228 err = obd_ioctl_popdata((void __user *)arg, data,
235 case OBD_IOC_UUID2DEV: {
236 /* Resolve a device uuid. This does not change the
237 * currently selected device.
240 struct obd_uuid uuid;
242 if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
243 CERROR("No UUID passed!\n");
247 if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) {
248 CERROR("UUID not NUL terminated!\n");
253 CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
254 obd_str2uuid(&uuid, data->ioc_inlbuf1);
255 dev = class_uuid2dev(&uuid);
258 CDEBUG(D_IOCTL, "No device for UUID %s!\n",
264 CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1,
266 err = obd_ioctl_popdata((void __user *)arg, data,
273 case OBD_IOC_GETDEVICE: {
274 int index = data->ioc_count;
277 if (!data->ioc_inlbuf1) {
278 CERROR("No buffer passed in ioctl\n");
282 if (data->ioc_inllen1 < 128) {
283 CERROR("ioctl buffer too small to hold version\n");
288 obd = class_num2obd(index);
294 if (obd->obd_stopping)
296 else if (obd->obd_set_up)
298 else if (obd->obd_attached)
302 str = (char *)data->ioc_bulk;
303 snprintf(str, len - sizeof(*data), "%3d %s %s %s %s %d",
304 (int)index, status, obd->obd_type->typ_name,
305 obd->obd_name, obd->obd_uuid.uuid,
306 atomic_read(&obd->obd_refcount));
307 err = obd_ioctl_popdata((void __user *)arg, data, len);
314 if (data->ioc_dev == OBD_DEV_BY_DEVNAME) {
315 if (data->ioc_inllen4 <= 0 || !data->ioc_inlbuf4) {
319 if (strnlen(data->ioc_inlbuf4, MAX_OBD_NAME) >= MAX_OBD_NAME) {
323 obd = class_name2obd(data->ioc_inlbuf4);
324 } else if (data->ioc_dev < class_devno_max()) {
325 obd = class_num2obd(data->ioc_dev);
327 CERROR("OBD ioctl: No device\n");
333 CERROR("OBD ioctl : No Device %d\n", data->ioc_dev);
337 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
339 if (!obd->obd_set_up || obd->obd_stopping) {
340 CERROR("OBD ioctl: device not setup %d\n", data->ioc_dev);
346 case OBD_IOC_NO_TRANSNO: {
347 if (!obd->obd_attached) {
348 CERROR("Device %d not attached\n", obd->obd_minor);
352 CDEBUG(D_HA, "%s: disabling committed-transno notification\n",
354 obd->obd_no_transno = 1;
360 err = obd_iocontrol(cmd, obd->obd_self_export, len, data, NULL);
364 err = obd_ioctl_popdata((void __user *)arg, data, len);
373 obd_ioctl_freedata(buf, len);
375 } /* class_handle_ioctl */
377 #define OBD_INIT_CHECK
378 static int obd_init_checks(void)
380 __u64 u64val, div64val;
384 CDEBUG(D_INFO, "LPU64=%s, LPD64=%s, LPX64=%s\n", "%llu", "%lld", "%#llx");
386 CDEBUG(D_INFO, "OBD_OBJECT_EOF = %#llx\n", (__u64)OBD_OBJECT_EOF);
388 u64val = OBD_OBJECT_EOF;
389 CDEBUG(D_INFO, "u64val OBD_OBJECT_EOF = %#llx\n", u64val);
390 if (u64val != OBD_OBJECT_EOF) {
391 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
392 u64val, (int)sizeof(u64val));
395 len = snprintf(buf, sizeof(buf), "%#llx", u64val);
397 CWARN("LPX64 wrong length! strlen(%s)=%d != 18\n", buf, len);
401 div64val = OBD_OBJECT_EOF;
402 CDEBUG(D_INFO, "u64val OBD_OBJECT_EOF = %#llx\n", u64val);
403 if (u64val != OBD_OBJECT_EOF) {
404 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
405 u64val, (int)sizeof(u64val));
408 if (u64val >> 8 != OBD_OBJECT_EOF >> 8) {
409 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
410 u64val, (int)sizeof(u64val));
413 if (do_div(div64val, 256) != (u64val & 255)) {
414 CERROR("do_div(%#llx,256) != %llu\n", u64val, u64val & 255);
417 if (u64val >> 8 != div64val) {
418 CERROR("do_div(%#llx,256) %llu != %llu\n",
419 u64val, div64val, u64val >> 8);
422 len = snprintf(buf, sizeof(buf), "%#llx", u64val);
424 CWARN("LPX64 wrong length! strlen(%s)=%d != 18\n", buf, len);
427 len = snprintf(buf, sizeof(buf), "%llu", u64val);
429 CWARN("LPU64 wrong length! strlen(%s)=%d != 20\n", buf, len);
432 len = snprintf(buf, sizeof(buf), "%lld", u64val);
434 CWARN("LPD64 wrong length! strlen(%s)=%d != 2\n", buf, len);
437 if ((u64val & ~PAGE_MASK) >= PAGE_SIZE) {
438 CWARN("mask failed: u64val %llu >= %llu\n", u64val,
446 static int __init obdclass_init(void)
450 LCONSOLE_INFO("Lustre: Build Version: " LUSTRE_VERSION_STRING "\n");
452 spin_lock_init(&obd_types_lock);
453 obd_zombie_impexp_init();
455 err = obd_init_checks();
456 if (err == -EOVERFLOW)
459 class_init_uuidlist();
460 err = class_handle_init();
464 INIT_LIST_HEAD(&obd_types);
466 err = misc_register(&obd_psdev);
468 CERROR("cannot register %d err %d\n", OBD_DEV_MINOR, err);
472 /* This struct is already zeroed for us (static global) */
473 for (i = 0; i < class_devno_max(); i++)
476 /* Default the dirty page cache cap to 1/2 of system memory.
477 * For clients with less memory, a larger fraction is needed
478 * for other purposes (mostly for BGL).
480 if (totalram_pages <= 512 << (20 - PAGE_SHIFT))
481 obd_max_dirty_pages = totalram_pages / 4;
483 obd_max_dirty_pages = totalram_pages / 2;
485 err = obd_init_caches();
489 err = class_procfs_init();
493 err = obd_sysctl_init();
497 err = lu_global_init();
501 err = cl_global_init();
505 err = llog_info_init();
509 err = lustre_register_fs();
514 static void obdclass_exit(void)
516 lustre_unregister_fs();
518 misc_deregister(&obd_psdev);
523 obd_cleanup_caches();
525 class_procfs_clean();
527 class_handle_cleanup();
528 class_exit_uuidlist();
529 obd_zombie_impexp_stop();
532 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
533 MODULE_DESCRIPTION("Lustre Class Driver");
534 MODULE_VERSION(LUSTRE_VERSION_STRING);
535 MODULE_LICENSE("GPL");
537 module_init(obdclass_init);
538 module_exit(obdclass_exit);