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, 2017, 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
35 #include <linux/miscdevice.h>
36 #include <linux/user_namespace.h>
37 #ifdef HAVE_UIDGID_HEADER
38 # include <linux/uidgid.h>
40 #include <linux/atomic.h>
41 #include <linux/list.h>
43 #include <obd_support.h>
44 #include <obd_class.h>
45 #include <uapi/linux/lnet/lnetctl.h>
46 #include <lustre_debug.h>
47 #include <lustre_kernelcomm.h>
48 #include <lprocfs_status.h>
49 #include <cl_object.h>
50 #ifdef HAVE_SERVER_SUPPORT
51 # include <dt_object.h>
52 # include <md_object.h>
53 #endif /* HAVE_SERVER_SUPPORT */
54 #include <uapi/linux/lustre/lustre_ioctl.h>
55 #include "llog_internal.h"
58 static __u64 obd_max_alloc;
63 static DEFINE_SPINLOCK(obd_updatemax_lock);
65 /* The following are visible and mutable through /proc/sys/lustre/. */
66 unsigned int obd_debug_peer_on_timeout;
67 EXPORT_SYMBOL(obd_debug_peer_on_timeout);
68 unsigned int obd_dump_on_timeout;
69 EXPORT_SYMBOL(obd_dump_on_timeout);
70 unsigned int obd_dump_on_eviction;
71 EXPORT_SYMBOL(obd_dump_on_eviction);
72 unsigned int obd_lbug_on_eviction;
73 EXPORT_SYMBOL(obd_lbug_on_eviction);
74 unsigned long obd_max_dirty_pages;
75 EXPORT_SYMBOL(obd_max_dirty_pages);
76 atomic_long_t obd_dirty_pages;
77 EXPORT_SYMBOL(obd_dirty_pages);
78 unsigned int obd_timeout = OBD_TIMEOUT_DEFAULT; /* seconds */
79 EXPORT_SYMBOL(obd_timeout);
80 unsigned int ldlm_timeout = LDLM_TIMEOUT_DEFAULT; /* seconds */
81 EXPORT_SYMBOL(ldlm_timeout);
82 unsigned int obd_timeout_set;
83 EXPORT_SYMBOL(obd_timeout_set);
84 unsigned int ldlm_timeout_set;
85 EXPORT_SYMBOL(ldlm_timeout_set);
86 /* bulk transfer timeout, give up after 100s by default */
87 unsigned int bulk_timeout = 100; /* seconds */
88 EXPORT_SYMBOL(bulk_timeout);
89 /* Adaptive timeout defs here instead of ptlrpc module for /proc/sys/ access */
90 unsigned int at_min = 0;
91 EXPORT_SYMBOL(at_min);
92 unsigned int at_max = 600;
93 EXPORT_SYMBOL(at_max);
94 unsigned int at_history = 600;
95 EXPORT_SYMBOL(at_history);
96 int at_early_margin = 5;
97 EXPORT_SYMBOL(at_early_margin);
99 EXPORT_SYMBOL(at_extra);
101 atomic_long_t obd_dirty_transit_pages;
102 EXPORT_SYMBOL(obd_dirty_transit_pages);
104 #ifdef CONFIG_PROC_FS
105 struct lprocfs_stats *obd_memory = NULL;
106 EXPORT_SYMBOL(obd_memory);
109 static int class_resolve_dev_name(__u32 len, const char *name)
116 CERROR("No name passed,!\n");
117 GOTO(out, rc = -EINVAL);
119 if (name[len - 1] != 0) {
120 CERROR("Name not nul terminated!\n");
121 GOTO(out, rc = -EINVAL);
124 CDEBUG(D_IOCTL, "device name %s\n", name);
125 dev = class_name2dev(name);
127 CDEBUG(D_IOCTL, "No device for name %s!\n", name);
128 GOTO(out, rc = -EINVAL);
131 CDEBUG(D_IOCTL, "device name %s, dev %d\n", name, dev);
138 #define OBD_MAX_IOCTL_BUFFER 8192
140 static int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
142 if (data->ioc_len > BIT(30)) {
143 CERROR("OBD ioctl: ioc_len larger than 1<<30\n");
147 if (data->ioc_inllen1 > BIT(30)) {
148 CERROR("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
152 if (data->ioc_inllen2 > BIT(30)) {
153 CERROR("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
157 if (data->ioc_inllen3 > BIT(30)) {
158 CERROR("OBD ioctl: ioc_inllen3 larger than 1<<30\n");
162 if (data->ioc_inllen4 > BIT(30)) {
163 CERROR("OBD ioctl: ioc_inllen4 larger than 1<<30\n");
167 if (data->ioc_inlbuf1 && data->ioc_inllen1 == 0) {
168 CERROR("OBD ioctl: inlbuf1 pointer but 0 length\n");
172 if (data->ioc_inlbuf2 && data->ioc_inllen2 == 0) {
173 CERROR("OBD ioctl: inlbuf2 pointer but 0 length\n");
177 if (data->ioc_inlbuf3 && data->ioc_inllen3 == 0) {
178 CERROR("OBD ioctl: inlbuf3 pointer but 0 length\n");
182 if (data->ioc_inlbuf4 && data->ioc_inllen4 == 0) {
183 CERROR("OBD ioctl: inlbuf4 pointer but 0 length\n");
187 if (data->ioc_pbuf1 && data->ioc_plen1 == 0) {
188 CERROR("OBD ioctl: pbuf1 pointer but 0 length\n");
192 if (data->ioc_pbuf2 && data->ioc_plen2 == 0) {
193 CERROR("OBD ioctl: pbuf2 pointer but 0 length\n");
197 if (!data->ioc_pbuf1 && data->ioc_plen1 != 0) {
198 CERROR("OBD ioctl: plen1 set but NULL pointer\n");
202 if (!data->ioc_pbuf2 && data->ioc_plen2 != 0) {
203 CERROR("OBD ioctl: plen2 set but NULL pointer\n");
207 if (obd_ioctl_packlen(data) > data->ioc_len) {
208 CERROR("OBD ioctl: packlen exceeds ioc_len (%d > %d)\n",
209 obd_ioctl_packlen(data), data->ioc_len);
216 /* buffer MUST be at least the size of obd_ioctl_hdr */
217 int obd_ioctl_getdata(char **buf, int *len, void __user *arg)
219 struct obd_ioctl_hdr hdr;
220 struct obd_ioctl_data *data;
224 if (copy_from_user(&hdr, arg, sizeof(hdr)))
227 if (hdr.ioc_version != OBD_IOCTL_VERSION) {
228 CERROR("Version mismatch kernel (%x) vs application (%x)\n",
229 OBD_IOCTL_VERSION, hdr.ioc_version);
233 if (hdr.ioc_len > OBD_MAX_IOCTL_BUFFER) {
234 CERROR("User buffer len %d exceeds %d max buffer\n",
235 hdr.ioc_len, OBD_MAX_IOCTL_BUFFER);
239 if (hdr.ioc_len < sizeof(struct obd_ioctl_data)) {
240 CERROR("User buffer too small for ioctl (%d)\n", hdr.ioc_len);
244 /* When there are lots of processes calling vmalloc on multi-core
245 * system, the high lock contention will hurt performance badly,
246 * obdfilter-survey is an example, which relies on ioctl. So we'd
247 * better avoid vmalloc on ioctl path. LU-66
249 OBD_ALLOC_LARGE(*buf, hdr.ioc_len);
251 CERROR("Cannot allocate control buffer of len %d\n",
256 data = (struct obd_ioctl_data *)*buf;
258 if (copy_from_user(*buf, arg, hdr.ioc_len)) {
259 OBD_FREE_LARGE(*buf, hdr.ioc_len);
263 if (obd_ioctl_is_invalid(data)) {
264 CERROR("ioctl not correctly formatted\n");
265 OBD_FREE_LARGE(*buf, hdr.ioc_len);
269 if (data->ioc_inllen1) {
270 data->ioc_inlbuf1 = &data->ioc_bulk[0];
271 offset += cfs_size_round(data->ioc_inllen1);
274 if (data->ioc_inllen2) {
275 data->ioc_inlbuf2 = &data->ioc_bulk[0] + offset;
276 offset += cfs_size_round(data->ioc_inllen2);
279 if (data->ioc_inllen3) {
280 data->ioc_inlbuf3 = &data->ioc_bulk[0] + offset;
281 offset += cfs_size_round(data->ioc_inllen3);
284 if (data->ioc_inllen4)
285 data->ioc_inlbuf4 = &data->ioc_bulk[0] + offset;
289 EXPORT_SYMBOL(obd_ioctl_getdata);
291 int class_handle_ioctl(unsigned int cmd, unsigned long arg)
294 struct obd_ioctl_data *data;
295 struct obd_device *obd = NULL;
296 int err = 0, len = 0;
299 CDEBUG(D_IOCTL, "cmd = %x\n", cmd);
300 if (obd_ioctl_getdata(&buf, &len, (void __user *)arg)) {
301 CERROR("OBD ioctl: data error\n");
304 data = (struct obd_ioctl_data *)buf;
307 case OBD_IOC_PROCESS_CFG: {
308 struct lustre_cfg *lcfg;
310 if (!data->ioc_plen1 || !data->ioc_pbuf1) {
311 CERROR("No config buffer passed!\n");
312 GOTO(out, err = -EINVAL);
314 OBD_ALLOC(lcfg, data->ioc_plen1);
316 GOTO(out, err = -ENOMEM);
317 err = copy_from_user(lcfg, data->ioc_pbuf1,
320 err = lustre_cfg_sanity_check(lcfg, data->ioc_plen1);
322 err = class_process_config(lcfg);
324 OBD_FREE(lcfg, data->ioc_plen1);
328 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
329 case OBD_GET_VERSION: {
332 if (!data->ioc_inlbuf1) {
333 CERROR("No buffer passed in ioctl\n");
334 GOTO(out, err = -EINVAL);
337 if (strlen(LUSTRE_VERSION_STRING) + 1 > data->ioc_inllen1) {
338 CERROR("ioctl buffer too small to hold version\n");
339 GOTO(out, err = -EINVAL);
344 CWARN("%s: ioctl(OBD_GET_VERSION) is deprecated, "
345 "use llapi_get_version_string() and/or relink\n",
348 memcpy(data->ioc_bulk, LUSTRE_VERSION_STRING,
349 strlen(LUSTRE_VERSION_STRING) + 1);
351 if (copy_to_user((void __user *)arg, data, len))
356 case OBD_IOC_NAME2DEV: {
357 /* Resolve a device name. This does not change the
358 * currently selected device.
362 dev = class_resolve_dev_name(data->ioc_inllen1,
366 GOTO(out, err = -EINVAL);
368 if (copy_to_user((void __user *)arg, data, sizeof(*data)))
373 case OBD_IOC_UUID2DEV: {
374 /* Resolve a device uuid. This does not change the
375 * currently selected device.
378 struct obd_uuid uuid;
380 if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
381 CERROR("No UUID passed!\n");
382 GOTO(out, err = -EINVAL);
384 if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) {
385 CERROR("UUID not NUL terminated!\n");
386 GOTO(out, err = -EINVAL);
389 CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
390 obd_str2uuid(&uuid, data->ioc_inlbuf1);
391 dev = class_uuid2dev(&uuid);
394 CDEBUG(D_IOCTL, "No device for UUID %s!\n",
396 GOTO(out, err = -EINVAL);
399 CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1,
401 if (copy_to_user((void __user *)arg, data, sizeof(*data)))
406 case OBD_IOC_GETDEVICE: {
407 int index = data->ioc_count;
410 if (!data->ioc_inlbuf1) {
411 CERROR("No buffer passed in ioctl\n");
412 GOTO(out, err = -EINVAL);
414 if (data->ioc_inllen1 < 128) {
415 CERROR("ioctl buffer too small to hold version\n");
416 GOTO(out, err = -EINVAL);
419 obd = class_num2obd(index);
421 GOTO(out, err = -ENOENT);
423 if (obd->obd_stopping)
425 else if (obd->obd_inactive)
427 else if (obd->obd_set_up)
429 else if (obd->obd_attached)
434 str = (char *)data->ioc_bulk;
435 snprintf(str, len - sizeof(*data), "%3d %s %s %s %s %d",
436 (int)index, status, obd->obd_type->typ_name,
437 obd->obd_name, obd->obd_uuid.uuid,
438 atomic_read(&obd->obd_refcount));
440 if (copy_to_user((void __user *)arg, data, len))
448 if (data->ioc_dev == OBD_DEV_BY_DEVNAME) {
449 if (data->ioc_inllen4 <= 0 || data->ioc_inlbuf4 == NULL)
450 GOTO(out, err = -EINVAL);
451 if (strnlen(data->ioc_inlbuf4, MAX_OBD_NAME) >= MAX_OBD_NAME)
452 GOTO(out, err = -EINVAL);
453 obd = class_name2obd(data->ioc_inlbuf4);
454 } else if (data->ioc_dev < class_devno_max()) {
455 obd = class_num2obd(data->ioc_dev);
457 CERROR("OBD ioctl: No device\n");
458 GOTO(out, err = -EINVAL);
462 CERROR("OBD ioctl : No Device %d\n", data->ioc_dev);
463 GOTO(out, err = -EINVAL);
465 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
467 if (!obd->obd_set_up || obd->obd_stopping) {
468 CERROR("OBD ioctl: device not setup %d \n", data->ioc_dev);
469 GOTO(out, err = -EINVAL);
473 case OBD_IOC_NO_TRANSNO: {
474 if (!obd->obd_attached) {
475 CERROR("Device %d not attached\n", obd->obd_minor);
476 GOTO(out, err = -ENODEV);
478 CDEBUG(D_HA, "%s: disabling committed-transno notification\n",
480 obd->obd_no_transno = 1;
485 err = obd_iocontrol(cmd, obd->obd_self_export, len, data, NULL);
489 if (copy_to_user((void __user *)arg, data, len))
496 OBD_FREE_LARGE(buf, len);
498 } /* class_handle_ioctl */
500 /* opening /dev/obd */
501 static int obd_class_open(struct inode * inode, struct file * file)
504 try_module_get(THIS_MODULE);
508 /* closing /dev/obd */
509 static int obd_class_release(struct inode * inode, struct file * file)
513 module_put(THIS_MODULE);
517 /* to control /dev/obd */
518 static long obd_class_ioctl(struct file *filp, unsigned int cmd,
524 /* Allow non-root access for some limited ioctls */
525 if (!cfs_capable(CFS_CAP_SYS_ADMIN))
526 RETURN(err = -EACCES);
528 if ((cmd & 0xffffff00) == ((int)'T') << 8) /* ignore all tty ioctls */
529 RETURN(err = -ENOTTY);
531 err = class_handle_ioctl(cmd, (unsigned long)arg);
536 /* declare character device */
537 static struct file_operations obd_psdev_fops = {
538 .owner = THIS_MODULE,
539 .unlocked_ioctl = obd_class_ioctl, /* unlocked_ioctl */
540 .open = obd_class_open, /* open */
541 .release = obd_class_release, /* release */
545 struct miscdevice obd_psdev = {
546 .minor = MISC_DYNAMIC_MINOR,
547 .name = OBD_DEV_NAME,
548 .fops = &obd_psdev_fops,
551 static int obd_init_checks(void)
553 __u64 u64val, div64val;
557 CDEBUG(D_INFO, "OBD_OBJECT_EOF = %#llx\n", (__u64)OBD_OBJECT_EOF);
559 u64val = OBD_OBJECT_EOF;
560 CDEBUG(D_INFO, "u64val OBD_OBJECT_EOF = %#llx\n", u64val);
561 if (u64val != OBD_OBJECT_EOF) {
562 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
563 u64val, (int)sizeof(u64val));
566 len = snprintf(buf, sizeof(buf), "%#llx", u64val);
568 CWARN("u64 hex wrong length! strlen(%s)=%d != 18\n", buf, len);
572 div64val = OBD_OBJECT_EOF;
573 CDEBUG(D_INFO, "u64val OBD_OBJECT_EOF = %#llx\n", u64val);
574 if (u64val != OBD_OBJECT_EOF) {
575 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
576 u64val, (int)sizeof(u64val));
579 if (u64val >> 8 != OBD_OBJECT_EOF >> 8) {
580 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
581 u64val, (int)sizeof(u64val));
584 if (do_div(div64val, 256) != (u64val & 255)) {
585 CERROR("do_div(%#llx,256) != %llu\n", u64val, u64val & 255);
588 if (u64val >> 8 != div64val) {
589 CERROR("do_div(%#llx,256) %llu != %llu\n",
590 u64val, div64val, u64val >> 8);
593 len = snprintf(buf, sizeof(buf), "%#llx", u64val);
595 CWARN("u64 hex wrong length! strlen(%s)=%d != 18\n", buf, len);
598 len = snprintf(buf, sizeof(buf), "%llu", u64val);
600 CWARN("u64 wrong length! strlen(%s)=%d != 20\n", buf, len);
603 len = snprintf(buf, sizeof(buf), "%lld", u64val);
605 CWARN("s64 wrong length! strlen(%s)=%d != 2\n", buf, len);
608 if ((u64val & ~PAGE_MASK) >= PAGE_SIZE) {
609 CWARN("mask failed: u64val %llu >= %llu\n", u64val,
617 static int __init obdclass_init(void)
621 LCONSOLE_INFO("Lustre: Build Version: "LUSTRE_VERSION_STRING"\n");
625 err = obd_init_checks();
626 if (err == -EOVERFLOW)
629 #ifdef CONFIG_PROC_FS
630 obd_memory = lprocfs_alloc_stats(OBD_STATS_NUM,
631 LPROCFS_STATS_FLAG_NONE |
632 LPROCFS_STATS_FLAG_IRQ_SAFE);
633 if (obd_memory == NULL) {
634 CERROR("kmalloc of 'obd_memory' failed\n");
638 lprocfs_counter_init(obd_memory, OBD_MEMORY_STAT,
639 LPROCFS_CNTR_AVGMINMAX,
642 err = obd_zombie_impexp_init();
644 goto cleanup_obd_memory;
646 err = class_handle_init();
648 goto cleanup_zombie_impexp;
650 err = misc_register(&obd_psdev);
652 CERROR("cannot register OBD miscdevice: err = %d\n", err);
653 goto cleanup_class_handle;
656 /* Default the dirty page cache cap to 1/2 of system memory.
657 * For clients with less memory, a larger fraction is needed
658 * for other purposes (mostly for BGL). */
659 if (cfs_totalram_pages() <= 512 << (20 - PAGE_SHIFT))
660 obd_max_dirty_pages = cfs_totalram_pages() / 4;
662 obd_max_dirty_pages = cfs_totalram_pages() / 2;
664 err = obd_init_caches();
666 goto cleanup_deregister;
668 err = class_procfs_init();
672 err = lu_global_init();
674 goto cleanup_class_procfs;
676 err = cl_global_init();
678 goto cleanup_lu_global;
680 #ifdef HAVE_SERVER_SUPPORT
681 err = dt_global_init();
683 goto cleanup_cl_global;
685 err = lu_ucred_global_init();
687 goto cleanup_dt_global;
688 #endif /* HAVE_SERVER_SUPPORT */
690 err = llog_info_init();
692 #ifdef HAVE_SERVER_SUPPORT
693 goto cleanup_lu_ucred_global;
694 #else /* !HAVE_SERVER_SUPPORT */
695 goto cleanup_cl_global;
696 #endif /* HAVE_SERVER_SUPPORT */
698 err = lustre_register_fs();
700 /* simulate a late OOM situation now to require all
701 * alloc'ed/initialized resources to be freed */
702 if (OBD_FAIL_CHECK(OBD_FAIL_OBDCLASS_MODULE_LOAD)) {
703 /* fake error but filesystem has been registered */
704 lustre_unregister_fs();
705 /* force error to ensure module will be unloaded/cleaned */
710 goto cleanup_llog_info;
717 #ifdef HAVE_SERVER_SUPPORT
718 cleanup_lu_ucred_global:
719 lu_ucred_global_fini();
723 #endif /* HAVE_SERVER_SUPPORT */
731 cleanup_class_procfs:
732 class_procfs_clean();
735 obd_cleanup_caches();
738 misc_deregister(&obd_psdev);
740 cleanup_class_handle:
741 class_handle_cleanup();
743 cleanup_zombie_impexp:
744 obd_zombie_impexp_stop();
747 #ifdef CONFIG_PROC_FS
748 lprocfs_free_stats(&obd_memory);
754 void obd_update_maxusage(void)
758 max = obd_memory_sum();
760 spin_lock(&obd_updatemax_lock);
761 if (max > obd_max_alloc)
763 spin_unlock(&obd_updatemax_lock);
765 EXPORT_SYMBOL(obd_update_maxusage);
767 #ifdef CONFIG_PROC_FS
768 __u64 obd_memory_max(void)
772 obd_update_maxusage();
773 spin_lock(&obd_updatemax_lock);
775 spin_unlock(&obd_updatemax_lock);
779 #endif /* CONFIG_PROC_FS */
781 static void __exit obdclass_exit(void)
783 #ifdef CONFIG_PROC_FS
786 #endif /* CONFIG_PROC_FS */
789 lustre_unregister_fs();
791 misc_deregister(&obd_psdev);
793 #ifdef HAVE_SERVER_SUPPORT
794 lu_ucred_global_fini();
796 #endif /* HAVE_SERVER_SUPPORT */
800 obd_cleanup_caches();
802 class_procfs_clean();
804 class_handle_cleanup();
805 class_del_uuid(NULL); /* Delete all UUIDs. */
806 obd_zombie_impexp_stop();
808 #ifdef CONFIG_PROC_FS
809 memory_leaked = obd_memory_sum();
810 memory_max = obd_memory_max();
812 lprocfs_free_stats(&obd_memory);
813 /* the below message is checked in test-framework.sh check_mem_leak() */
814 CDEBUG((memory_leaked) ? D_ERROR : D_INFO,
815 "obd_memory max: %llu, leaked: %llu\n",
816 memory_max, memory_leaked);
817 #endif /* CONFIG_PROC_FS */
822 void obd_heat_clear(struct obd_heat_instance *instance, int count)
826 memset(instance, 0, sizeof(*instance) * count);
829 EXPORT_SYMBOL(obd_heat_clear);
832 * The file heat is calculated for every time interval period I. The access
833 * frequency during each period is counted. The file heat is only recalculated
834 * at the end of a time period. And a percentage of the former file heat is
835 * lost when recalculated. The recursion formula to calculate the heat of the
836 * file f is as follow:
838 * Hi+1(f) = (1-P)*Hi(f)+ P*Ci
840 * Where Hi is the heat value in the period between time points i*I and
841 * (i+1)*I; Ci is the access count in the period; the symbol P refers to the
842 * weight of Ci. The larger the value the value of P is, the more influence Ci
843 * has on the file heat.
845 void obd_heat_decay(struct obd_heat_instance *instance, __u64 time_second,
846 unsigned int weight, unsigned int period_second)
852 if (instance->ohi_time_second > time_second) {
853 obd_heat_clear(instance, 1);
857 if (instance->ohi_time_second == 0)
860 for (second = instance->ohi_time_second + period_second;
861 second < time_second;
862 second += period_second) {
863 instance->ohi_heat = instance->ohi_heat *
864 (256 - weight) / 256 +
865 instance->ohi_count * weight / 256;
866 instance->ohi_count = 0;
867 instance->ohi_time_second = second;
871 EXPORT_SYMBOL(obd_heat_decay);
873 __u64 obd_heat_get(struct obd_heat_instance *instance, unsigned int time_second,
874 unsigned int weight, unsigned int period_second)
878 obd_heat_decay(instance, time_second, weight, period_second);
880 if (instance->ohi_count == 0)
881 RETURN(instance->ohi_heat);
883 RETURN(instance->ohi_heat * (256 - weight) / 256 +
884 instance->ohi_count * weight / 256);
886 EXPORT_SYMBOL(obd_heat_get);
888 void obd_heat_add(struct obd_heat_instance *instance,
889 unsigned int time_second, __u64 count,
890 unsigned int weight, unsigned int period_second)
894 obd_heat_decay(instance, time_second, weight, period_second);
895 if (instance->ohi_time_second == 0) {
896 instance->ohi_time_second = time_second;
897 instance->ohi_heat = 0;
898 instance->ohi_count = count;
900 instance->ohi_count += count;
904 EXPORT_SYMBOL(obd_heat_add);
906 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
907 MODULE_DESCRIPTION("Lustre Class Driver");
908 MODULE_VERSION(LUSTRE_VERSION_STRING);
909 MODULE_LICENSE("GPL");
911 module_init(obdclass_init);
912 module_exit(obdclass_exit);