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 EXPORT_SYMBOL(obd_devs
);
48 struct list_head obd_types
;
49 DEFINE_RWLOCK(obd_dev_lock
);
51 /* The following are visible and mutable through /sys/fs/lustre. */
52 unsigned int obd_debug_peer_on_timeout
;
53 EXPORT_SYMBOL(obd_debug_peer_on_timeout
);
54 unsigned int obd_dump_on_timeout
;
55 EXPORT_SYMBOL(obd_dump_on_timeout
);
56 unsigned int obd_dump_on_eviction
;
57 EXPORT_SYMBOL(obd_dump_on_eviction
);
58 unsigned int obd_max_dirty_pages
= 256;
59 EXPORT_SYMBOL(obd_max_dirty_pages
);
60 atomic_t obd_dirty_pages
;
61 EXPORT_SYMBOL(obd_dirty_pages
);
62 unsigned int obd_timeout
= OBD_TIMEOUT_DEFAULT
; /* seconds */
63 EXPORT_SYMBOL(obd_timeout
);
64 unsigned int obd_timeout_set
;
65 EXPORT_SYMBOL(obd_timeout_set
);
66 /* Adaptive timeout defs here instead of ptlrpc module for /sys/fs/ access */
68 EXPORT_SYMBOL(at_min
);
69 unsigned int at_max
= 600;
70 EXPORT_SYMBOL(at_max
);
71 unsigned int at_history
= 600;
72 EXPORT_SYMBOL(at_history
);
73 int at_early_margin
= 5;
74 EXPORT_SYMBOL(at_early_margin
);
76 EXPORT_SYMBOL(at_extra
);
78 atomic_t obd_dirty_transit_pages
;
79 EXPORT_SYMBOL(obd_dirty_transit_pages
);
81 char obd_jobid_var
[JOBSTATS_JOBID_VAR_MAX_LEN
+ 1] = JOBSTATS_DISABLE
;
82 EXPORT_SYMBOL(obd_jobid_var
);
84 char obd_jobid_node
[JOBSTATS_JOBID_SIZE
+ 1];
86 /* Get jobid of current process from stored variable or calculate
87 * it from pid and user_id.
89 * Historically this was also done by reading the environment variable
90 * stored in between the "env_start" & "env_end" of task struct.
91 * This is now deprecated.
93 int lustre_get_jobid(char *jobid
)
95 memset(jobid
, 0, JOBSTATS_JOBID_SIZE
);
96 /* Jobstats isn't enabled */
97 if (strcmp(obd_jobid_var
, JOBSTATS_DISABLE
) == 0)
100 /* Use process name + fsuid as jobid */
101 if (strcmp(obd_jobid_var
, JOBSTATS_PROCNAME_UID
) == 0) {
102 snprintf(jobid
, JOBSTATS_JOBID_SIZE
, "%s.%u",
104 from_kuid(&init_user_ns
, current_fsuid()));
108 /* Whole node dedicated to single job */
109 if (strcmp(obd_jobid_var
, JOBSTATS_NODELOCAL
) == 0) {
110 strcpy(jobid
, obd_jobid_node
);
116 EXPORT_SYMBOL(lustre_get_jobid
);
118 static int class_resolve_dev_name(__u32 len
, const char *name
)
124 CERROR("No name passed,!\n");
128 if (name
[len
- 1] != 0) {
129 CERROR("Name not nul terminated!\n");
134 CDEBUG(D_IOCTL
, "device name %s\n", name
);
135 dev
= class_name2dev(name
);
137 CDEBUG(D_IOCTL
, "No device for name %s!\n", name
);
142 CDEBUG(D_IOCTL
, "device name %s, dev %d\n", name
, dev
);
149 int class_handle_ioctl(unsigned int cmd
, unsigned long arg
)
152 struct obd_ioctl_data
*data
;
153 struct libcfs_debug_ioctl_data
*debug_data
;
154 struct obd_device
*obd
= NULL
;
155 int err
= 0, len
= 0;
157 /* only for debugging */
158 if (cmd
== LIBCFS_IOC_DEBUG_MASK
) {
159 debug_data
= (struct libcfs_debug_ioctl_data
*)arg
;
160 libcfs_subsystem_debug
= debug_data
->subs
;
161 libcfs_debug
= debug_data
->debug
;
165 CDEBUG(D_IOCTL
, "cmd = %x\n", cmd
);
166 if (obd_ioctl_getdata(&buf
, &len
, (void __user
*)arg
)) {
167 CERROR("OBD ioctl: data error\n");
170 data
= (struct obd_ioctl_data
*)buf
;
173 case OBD_IOC_PROCESS_CFG
: {
174 struct lustre_cfg
*lcfg
;
176 if (!data
->ioc_plen1
|| !data
->ioc_pbuf1
) {
177 CERROR("No config buffer passed!\n");
181 lcfg
= kzalloc(data
->ioc_plen1
, GFP_NOFS
);
186 err
= copy_from_user(lcfg
, data
->ioc_pbuf1
, data
->ioc_plen1
);
188 err
= lustre_cfg_sanity_check(lcfg
, data
->ioc_plen1
);
190 err
= class_process_config(lcfg
);
196 case OBD_GET_VERSION
:
197 if (!data
->ioc_inlbuf1
) {
198 CERROR("No buffer passed in ioctl\n");
203 if (strlen(LUSTRE_VERSION_STRING
) + 1 > data
->ioc_inllen1
) {
204 CERROR("ioctl buffer too small to hold version\n");
209 memcpy(data
->ioc_bulk
, LUSTRE_VERSION_STRING
,
210 strlen(LUSTRE_VERSION_STRING
) + 1);
212 err
= obd_ioctl_popdata((void __user
*)arg
, data
, len
);
217 case OBD_IOC_NAME2DEV
: {
218 /* Resolve a device name. This does not change the
219 * currently selected device.
223 dev
= class_resolve_dev_name(data
->ioc_inllen1
,
231 err
= obd_ioctl_popdata((void __user
*)arg
, data
,
238 case OBD_IOC_UUID2DEV
: {
239 /* Resolve a device uuid. This does not change the
240 * currently selected device.
243 struct obd_uuid uuid
;
245 if (!data
->ioc_inllen1
|| !data
->ioc_inlbuf1
) {
246 CERROR("No UUID passed!\n");
250 if (data
->ioc_inlbuf1
[data
->ioc_inllen1
- 1] != 0) {
251 CERROR("UUID not NUL terminated!\n");
256 CDEBUG(D_IOCTL
, "device name %s\n", data
->ioc_inlbuf1
);
257 obd_str2uuid(&uuid
, data
->ioc_inlbuf1
);
258 dev
= class_uuid2dev(&uuid
);
261 CDEBUG(D_IOCTL
, "No device for UUID %s!\n",
267 CDEBUG(D_IOCTL
, "device name %s, dev %d\n", data
->ioc_inlbuf1
,
269 err
= obd_ioctl_popdata((void __user
*)arg
, data
,
276 case OBD_IOC_GETDEVICE
: {
277 int index
= data
->ioc_count
;
280 if (!data
->ioc_inlbuf1
) {
281 CERROR("No buffer passed in ioctl\n");
285 if (data
->ioc_inllen1
< 128) {
286 CERROR("ioctl buffer too small to hold version\n");
291 obd
= class_num2obd(index
);
297 if (obd
->obd_stopping
)
299 else if (obd
->obd_set_up
)
301 else if (obd
->obd_attached
)
305 str
= (char *)data
->ioc_bulk
;
306 snprintf(str
, len
- sizeof(*data
), "%3d %s %s %s %s %d",
307 (int)index
, status
, obd
->obd_type
->typ_name
,
308 obd
->obd_name
, obd
->obd_uuid
.uuid
,
309 atomic_read(&obd
->obd_refcount
));
310 err
= obd_ioctl_popdata((void __user
*)arg
, data
, len
);
317 if (data
->ioc_dev
== OBD_DEV_BY_DEVNAME
) {
318 if (data
->ioc_inllen4
<= 0 || !data
->ioc_inlbuf4
) {
322 if (strnlen(data
->ioc_inlbuf4
, MAX_OBD_NAME
) >= MAX_OBD_NAME
) {
326 obd
= class_name2obd(data
->ioc_inlbuf4
);
327 } else if (data
->ioc_dev
< class_devno_max()) {
328 obd
= class_num2obd(data
->ioc_dev
);
330 CERROR("OBD ioctl: No device\n");
336 CERROR("OBD ioctl : No Device %d\n", data
->ioc_dev
);
340 LASSERT(obd
->obd_magic
== OBD_DEVICE_MAGIC
);
342 if (!obd
->obd_set_up
|| obd
->obd_stopping
) {
343 CERROR("OBD ioctl: device not setup %d\n", data
->ioc_dev
);
349 case OBD_IOC_NO_TRANSNO
: {
350 if (!obd
->obd_attached
) {
351 CERROR("Device %d not attached\n", obd
->obd_minor
);
355 CDEBUG(D_HA
, "%s: disabling committed-transno notification\n",
357 obd
->obd_no_transno
= 1;
363 err
= obd_iocontrol(cmd
, obd
->obd_self_export
, len
, data
, NULL
);
367 err
= obd_ioctl_popdata((void __user
*)arg
, data
, len
);
376 obd_ioctl_freedata(buf
, len
);
378 } /* class_handle_ioctl */
380 #define OBD_INIT_CHECK
381 static int obd_init_checks(void)
383 __u64 u64val
, div64val
;
387 CDEBUG(D_INFO
, "LPU64=%s, LPD64=%s, LPX64=%s\n", "%llu", "%lld", "%#llx");
389 CDEBUG(D_INFO
, "OBD_OBJECT_EOF = %#llx\n", (__u64
)OBD_OBJECT_EOF
);
391 u64val
= OBD_OBJECT_EOF
;
392 CDEBUG(D_INFO
, "u64val OBD_OBJECT_EOF = %#llx\n", u64val
);
393 if (u64val
!= OBD_OBJECT_EOF
) {
394 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
395 u64val
, (int)sizeof(u64val
));
398 len
= snprintf(buf
, sizeof(buf
), "%#llx", u64val
);
400 CWARN("LPX64 wrong length! strlen(%s)=%d != 18\n", buf
, len
);
404 div64val
= OBD_OBJECT_EOF
;
405 CDEBUG(D_INFO
, "u64val OBD_OBJECT_EOF = %#llx\n", u64val
);
406 if (u64val
!= OBD_OBJECT_EOF
) {
407 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
408 u64val
, (int)sizeof(u64val
));
411 if (u64val
>> 8 != OBD_OBJECT_EOF
>> 8) {
412 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
413 u64val
, (int)sizeof(u64val
));
416 if (do_div(div64val
, 256) != (u64val
& 255)) {
417 CERROR("do_div(%#llx,256) != %llu\n", u64val
, u64val
& 255);
420 if (u64val
>> 8 != div64val
) {
421 CERROR("do_div(%#llx,256) %llu != %llu\n",
422 u64val
, div64val
, u64val
>> 8);
425 len
= snprintf(buf
, sizeof(buf
), "%#llx", u64val
);
427 CWARN("LPX64 wrong length! strlen(%s)=%d != 18\n", buf
, len
);
430 len
= snprintf(buf
, sizeof(buf
), "%llu", u64val
);
432 CWARN("LPU64 wrong length! strlen(%s)=%d != 20\n", buf
, len
);
435 len
= snprintf(buf
, sizeof(buf
), "%lld", u64val
);
437 CWARN("LPD64 wrong length! strlen(%s)=%d != 2\n", buf
, len
);
440 if ((u64val
& ~PAGE_MASK
) >= PAGE_SIZE
) {
441 CWARN("mask failed: u64val %llu >= %llu\n", u64val
,
449 extern int class_procfs_init(void);
450 extern int class_procfs_clean(void);
452 static int __init
obdclass_init(void)
456 int lustre_register_fs(void);
458 LCONSOLE_INFO("Lustre: Build Version: " LUSTRE_VERSION_STRING
"\n");
460 spin_lock_init(&obd_types_lock
);
461 obd_zombie_impexp_init();
463 err
= obd_init_checks();
464 if (err
== -EOVERFLOW
)
467 class_init_uuidlist();
468 err
= class_handle_init();
472 INIT_LIST_HEAD(&obd_types
);
474 err
= misc_register(&obd_psdev
);
476 CERROR("cannot register %d err %d\n", OBD_DEV_MINOR
, err
);
480 /* This struct is already zeroed for us (static global) */
481 for (i
= 0; i
< class_devno_max(); i
++)
484 /* Default the dirty page cache cap to 1/2 of system memory.
485 * For clients with less memory, a larger fraction is needed
486 * for other purposes (mostly for BGL).
488 if (totalram_pages
<= 512 << (20 - PAGE_SHIFT
))
489 obd_max_dirty_pages
= totalram_pages
/ 4;
491 obd_max_dirty_pages
= totalram_pages
/ 2;
493 err
= obd_init_caches();
497 err
= class_procfs_init();
501 err
= obd_sysctl_init();
505 err
= lu_global_init();
509 err
= cl_global_init();
513 err
= llog_info_init();
517 err
= lustre_register_fs();
522 static void obdclass_exit(void)
524 int lustre_unregister_fs(void);
526 lustre_unregister_fs();
528 misc_deregister(&obd_psdev
);
533 obd_cleanup_caches();
535 class_procfs_clean();
537 class_handle_cleanup();
538 class_exit_uuidlist();
539 obd_zombie_impexp_stop();
542 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
543 MODULE_DESCRIPTION("Lustre Class Driver");
544 MODULE_VERSION(LUSTRE_VERSION_STRING
);
545 MODULE_LICENSE("GPL");
547 module_init(obdclass_init
);
548 module_exit(obdclass_exit
);