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 #ifdef CONFIG_PROC_FS
102 struct lprocfs_stats *obd_memory = NULL;
103 EXPORT_SYMBOL(obd_memory);
106 static int class_resolve_dev_name(__u32 len, const char *name)
113 CERROR("No name passed,!\n");
114 GOTO(out, rc = -EINVAL);
116 if (name[len - 1] != 0) {
117 CERROR("Name not nul terminated!\n");
118 GOTO(out, rc = -EINVAL);
121 CDEBUG(D_IOCTL, "device name %s\n", name);
122 dev = class_name2dev(name);
124 CDEBUG(D_IOCTL, "No device for name %s!\n", name);
125 GOTO(out, rc = -EINVAL);
128 CDEBUG(D_IOCTL, "device name %s, dev %d\n", name, dev);
135 #define OBD_MAX_IOCTL_BUFFER 8192
137 static int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
139 if (data->ioc_len > BIT(30)) {
140 CERROR("OBD ioctl: ioc_len larger than 1<<30\n");
144 if (data->ioc_inllen1 > BIT(30)) {
145 CERROR("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
149 if (data->ioc_inllen2 > BIT(30)) {
150 CERROR("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
154 if (data->ioc_inllen3 > BIT(30)) {
155 CERROR("OBD ioctl: ioc_inllen3 larger than 1<<30\n");
159 if (data->ioc_inllen4 > BIT(30)) {
160 CERROR("OBD ioctl: ioc_inllen4 larger than 1<<30\n");
164 if (data->ioc_inlbuf1 && data->ioc_inllen1 == 0) {
165 CERROR("OBD ioctl: inlbuf1 pointer but 0 length\n");
169 if (data->ioc_inlbuf2 && data->ioc_inllen2 == 0) {
170 CERROR("OBD ioctl: inlbuf2 pointer but 0 length\n");
174 if (data->ioc_inlbuf3 && data->ioc_inllen3 == 0) {
175 CERROR("OBD ioctl: inlbuf3 pointer but 0 length\n");
179 if (data->ioc_inlbuf4 && data->ioc_inllen4 == 0) {
180 CERROR("OBD ioctl: inlbuf4 pointer but 0 length\n");
184 if (data->ioc_pbuf1 && data->ioc_plen1 == 0) {
185 CERROR("OBD ioctl: pbuf1 pointer but 0 length\n");
189 if (data->ioc_pbuf2 && data->ioc_plen2 == 0) {
190 CERROR("OBD ioctl: pbuf2 pointer but 0 length\n");
194 if (!data->ioc_pbuf1 && data->ioc_plen1 != 0) {
195 CERROR("OBD ioctl: plen1 set but NULL pointer\n");
199 if (!data->ioc_pbuf2 && data->ioc_plen2 != 0) {
200 CERROR("OBD ioctl: plen2 set but NULL pointer\n");
204 if (obd_ioctl_packlen(data) > data->ioc_len) {
205 CERROR("OBD ioctl: packlen exceeds ioc_len (%d > %d)\n",
206 obd_ioctl_packlen(data), data->ioc_len);
213 /* buffer MUST be at least the size of obd_ioctl_hdr */
214 int obd_ioctl_getdata(char **buf, int *len, void __user *arg)
216 struct obd_ioctl_hdr hdr;
217 struct obd_ioctl_data *data;
221 if (copy_from_user(&hdr, arg, sizeof(hdr)))
224 if (hdr.ioc_version != OBD_IOCTL_VERSION) {
225 CERROR("Version mismatch kernel (%x) vs application (%x)\n",
226 OBD_IOCTL_VERSION, hdr.ioc_version);
230 if (hdr.ioc_len > OBD_MAX_IOCTL_BUFFER) {
231 CERROR("User buffer len %d exceeds %d max buffer\n",
232 hdr.ioc_len, OBD_MAX_IOCTL_BUFFER);
236 if (hdr.ioc_len < sizeof(struct obd_ioctl_data)) {
237 CERROR("User buffer too small for ioctl (%d)\n", hdr.ioc_len);
241 /* When there are lots of processes calling vmalloc on multi-core
242 * system, the high lock contention will hurt performance badly,
243 * obdfilter-survey is an example, which relies on ioctl. So we'd
244 * better avoid vmalloc on ioctl path. LU-66
246 OBD_ALLOC_LARGE(*buf, hdr.ioc_len);
248 CERROR("Cannot allocate control buffer of len %d\n",
253 data = (struct obd_ioctl_data *)*buf;
255 if (copy_from_user(*buf, arg, hdr.ioc_len)) {
256 OBD_FREE_LARGE(*buf, hdr.ioc_len);
260 if (obd_ioctl_is_invalid(data)) {
261 CERROR("ioctl not correctly formatted\n");
262 OBD_FREE_LARGE(*buf, hdr.ioc_len);
266 if (data->ioc_inllen1) {
267 data->ioc_inlbuf1 = &data->ioc_bulk[0];
268 offset += cfs_size_round(data->ioc_inllen1);
271 if (data->ioc_inllen2) {
272 data->ioc_inlbuf2 = &data->ioc_bulk[0] + offset;
273 offset += cfs_size_round(data->ioc_inllen2);
276 if (data->ioc_inllen3) {
277 data->ioc_inlbuf3 = &data->ioc_bulk[0] + offset;
278 offset += cfs_size_round(data->ioc_inllen3);
281 if (data->ioc_inllen4)
282 data->ioc_inlbuf4 = &data->ioc_bulk[0] + offset;
286 EXPORT_SYMBOL(obd_ioctl_getdata);
288 int class_handle_ioctl(unsigned int cmd, unsigned long arg)
291 struct obd_ioctl_data *data;
292 struct obd_device *obd = NULL;
293 int err = 0, len = 0;
296 CDEBUG(D_IOCTL, "cmd = %x\n", cmd);
297 if (obd_ioctl_getdata(&buf, &len, (void __user *)arg)) {
298 CERROR("OBD ioctl: data error\n");
301 data = (struct obd_ioctl_data *)buf;
304 case OBD_IOC_PROCESS_CFG: {
305 struct lustre_cfg *lcfg;
307 if (!data->ioc_plen1 || !data->ioc_pbuf1) {
308 CERROR("No config buffer passed!\n");
309 GOTO(out, err = -EINVAL);
311 OBD_ALLOC(lcfg, data->ioc_plen1);
313 GOTO(out, err = -ENOMEM);
314 err = copy_from_user(lcfg, data->ioc_pbuf1,
317 err = lustre_cfg_sanity_check(lcfg, data->ioc_plen1);
319 err = class_process_config(lcfg);
321 OBD_FREE(lcfg, data->ioc_plen1);
325 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
326 case OBD_GET_VERSION: {
329 if (!data->ioc_inlbuf1) {
330 CERROR("No buffer passed in ioctl\n");
331 GOTO(out, err = -EINVAL);
334 if (strlen(LUSTRE_VERSION_STRING) + 1 > data->ioc_inllen1) {
335 CERROR("ioctl buffer too small to hold version\n");
336 GOTO(out, err = -EINVAL);
341 CWARN("%s: ioctl(OBD_GET_VERSION) is deprecated, "
342 "use llapi_get_version_string() and/or relink\n",
345 memcpy(data->ioc_bulk, LUSTRE_VERSION_STRING,
346 strlen(LUSTRE_VERSION_STRING) + 1);
348 if (copy_to_user((void __user *)arg, data, len))
353 case OBD_IOC_NAME2DEV: {
354 /* Resolve a device name. This does not change the
355 * currently selected device.
359 dev = class_resolve_dev_name(data->ioc_inllen1,
363 GOTO(out, err = -EINVAL);
365 if (copy_to_user((void __user *)arg, data, sizeof(*data)))
370 case OBD_IOC_UUID2DEV: {
371 /* Resolve a device uuid. This does not change the
372 * currently selected device.
375 struct obd_uuid uuid;
377 if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
378 CERROR("No UUID passed!\n");
379 GOTO(out, err = -EINVAL);
381 if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) {
382 CERROR("UUID not NUL terminated!\n");
383 GOTO(out, err = -EINVAL);
386 CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
387 obd_str2uuid(&uuid, data->ioc_inlbuf1);
388 dev = class_uuid2dev(&uuid);
391 CDEBUG(D_IOCTL, "No device for UUID %s!\n",
393 GOTO(out, err = -EINVAL);
396 CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1,
398 if (copy_to_user((void __user *)arg, data, sizeof(*data)))
403 case OBD_IOC_GETDEVICE: {
404 int index = data->ioc_count;
407 if (!data->ioc_inlbuf1) {
408 CERROR("No buffer passed in ioctl\n");
409 GOTO(out, err = -EINVAL);
411 if (data->ioc_inllen1 < 128) {
412 CERROR("ioctl buffer too small to hold version\n");
413 GOTO(out, err = -EINVAL);
416 obd = class_num2obd(index);
418 GOTO(out, err = -ENOENT);
420 if (obd->obd_stopping)
422 else if (obd->obd_inactive)
424 else if (obd->obd_set_up)
426 else if (obd->obd_attached)
431 str = (char *)data->ioc_bulk;
432 snprintf(str, len - sizeof(*data), "%3d %s %s %s %s %d",
433 (int)index, status, obd->obd_type->typ_name,
434 obd->obd_name, obd->obd_uuid.uuid,
435 atomic_read(&obd->obd_refcount));
437 if (copy_to_user((void __user *)arg, data, len))
445 if (data->ioc_dev == OBD_DEV_BY_DEVNAME) {
446 if (data->ioc_inllen4 <= 0 || data->ioc_inlbuf4 == NULL)
447 GOTO(out, err = -EINVAL);
448 if (strnlen(data->ioc_inlbuf4, MAX_OBD_NAME) >= MAX_OBD_NAME)
449 GOTO(out, err = -EINVAL);
450 obd = class_name2obd(data->ioc_inlbuf4);
451 } else if (data->ioc_dev < class_devno_max()) {
452 obd = class_num2obd(data->ioc_dev);
454 CERROR("OBD ioctl: No device\n");
455 GOTO(out, err = -EINVAL);
459 CERROR("OBD ioctl : No Device %d\n", data->ioc_dev);
460 GOTO(out, err = -EINVAL);
462 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
464 if (!obd->obd_set_up || obd->obd_stopping) {
465 CERROR("OBD ioctl: device not setup %d \n", data->ioc_dev);
466 GOTO(out, err = -EINVAL);
470 case OBD_IOC_NO_TRANSNO: {
471 if (!obd->obd_attached) {
472 CERROR("Device %d not attached\n", obd->obd_minor);
473 GOTO(out, err = -ENODEV);
475 CDEBUG(D_HA, "%s: disabling committed-transno notification\n",
477 obd->obd_no_transno = 1;
482 err = obd_iocontrol(cmd, obd->obd_self_export, len, data, NULL);
486 if (copy_to_user((void __user *)arg, data, len))
493 OBD_FREE_LARGE(buf, len);
495 } /* class_handle_ioctl */
497 /* opening /dev/obd */
498 static int obd_class_open(struct inode * inode, struct file * file)
501 try_module_get(THIS_MODULE);
505 /* closing /dev/obd */
506 static int obd_class_release(struct inode * inode, struct file * file)
510 module_put(THIS_MODULE);
514 /* to control /dev/obd */
515 static long obd_class_ioctl(struct file *filp, unsigned int cmd,
521 /* Allow non-root access for some limited ioctls */
522 if (!cfs_capable(CFS_CAP_SYS_ADMIN))
523 RETURN(err = -EACCES);
525 if ((cmd & 0xffffff00) == ((int)'T') << 8) /* ignore all tty ioctls */
526 RETURN(err = -ENOTTY);
528 err = class_handle_ioctl(cmd, (unsigned long)arg);
533 /* declare character device */
534 static struct file_operations obd_psdev_fops = {
535 .owner = THIS_MODULE,
536 .unlocked_ioctl = obd_class_ioctl, /* unlocked_ioctl */
537 .open = obd_class_open, /* open */
538 .release = obd_class_release, /* release */
542 struct miscdevice obd_psdev = {
543 .minor = MISC_DYNAMIC_MINOR,
544 .name = OBD_DEV_NAME,
545 .fops = &obd_psdev_fops,
548 static int obd_init_checks(void)
550 __u64 u64val, div64val;
554 CDEBUG(D_INFO, "OBD_OBJECT_EOF = %#llx\n", (__u64)OBD_OBJECT_EOF);
556 u64val = OBD_OBJECT_EOF;
557 CDEBUG(D_INFO, "u64val OBD_OBJECT_EOF = %#llx\n", u64val);
558 if (u64val != OBD_OBJECT_EOF) {
559 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
560 u64val, (int)sizeof(u64val));
563 len = snprintf(buf, sizeof(buf), "%#llx", u64val);
565 CWARN("u64 hex wrong length! strlen(%s)=%d != 18\n", buf, len);
569 div64val = OBD_OBJECT_EOF;
570 CDEBUG(D_INFO, "u64val OBD_OBJECT_EOF = %#llx\n", u64val);
571 if (u64val != OBD_OBJECT_EOF) {
572 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
573 u64val, (int)sizeof(u64val));
576 if (u64val >> 8 != OBD_OBJECT_EOF >> 8) {
577 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
578 u64val, (int)sizeof(u64val));
581 if (do_div(div64val, 256) != (u64val & 255)) {
582 CERROR("do_div(%#llx,256) != %llu\n", u64val, u64val & 255);
585 if (u64val >> 8 != div64val) {
586 CERROR("do_div(%#llx,256) %llu != %llu\n",
587 u64val, div64val, u64val >> 8);
590 len = snprintf(buf, sizeof(buf), "%#llx", u64val);
592 CWARN("u64 hex wrong length! strlen(%s)=%d != 18\n", buf, len);
595 len = snprintf(buf, sizeof(buf), "%llu", u64val);
597 CWARN("u64 wrong length! strlen(%s)=%d != 20\n", buf, len);
600 len = snprintf(buf, sizeof(buf), "%lld", u64val);
602 CWARN("s64 wrong length! strlen(%s)=%d != 2\n", buf, len);
605 if ((u64val & ~PAGE_MASK) >= PAGE_SIZE) {
606 CWARN("mask failed: u64val %llu >= %llu\n", u64val,
614 static int __init obdclass_init(void)
618 LCONSOLE_INFO("Lustre: Build Version: "LUSTRE_VERSION_STRING"\n");
622 err = obd_init_checks();
623 if (err == -EOVERFLOW)
626 #ifdef CONFIG_PROC_FS
627 obd_memory = lprocfs_alloc_stats(OBD_STATS_NUM,
628 LPROCFS_STATS_FLAG_NONE |
629 LPROCFS_STATS_FLAG_IRQ_SAFE);
630 if (obd_memory == NULL) {
631 CERROR("kmalloc of 'obd_memory' failed\n");
635 lprocfs_counter_init(obd_memory, OBD_MEMORY_STAT,
636 LPROCFS_CNTR_AVGMINMAX,
639 err = obd_zombie_impexp_init();
641 goto cleanup_obd_memory;
643 err = class_handle_init();
645 goto cleanup_zombie_impexp;
647 err = misc_register(&obd_psdev);
649 CERROR("cannot register OBD miscdevice: err = %d\n", err);
650 goto cleanup_class_handle;
653 /* Default the dirty page cache cap to 1/2 of system memory.
654 * For clients with less memory, a larger fraction is needed
655 * for other purposes (mostly for BGL). */
656 if (cfs_totalram_pages() <= 512 << (20 - PAGE_SHIFT))
657 obd_max_dirty_pages = cfs_totalram_pages() / 4;
659 obd_max_dirty_pages = cfs_totalram_pages() / 2;
661 err = obd_init_caches();
663 goto cleanup_deregister;
665 err = class_procfs_init();
669 err = lu_global_init();
671 goto cleanup_class_procfs;
673 err = cl_global_init();
675 goto cleanup_lu_global;
677 #ifdef HAVE_SERVER_SUPPORT
678 err = dt_global_init();
680 goto cleanup_cl_global;
682 err = lu_ucred_global_init();
684 goto cleanup_dt_global;
685 #endif /* HAVE_SERVER_SUPPORT */
687 err = llog_info_init();
689 #ifdef HAVE_SERVER_SUPPORT
690 goto cleanup_lu_ucred_global;
691 #else /* !HAVE_SERVER_SUPPORT */
692 goto cleanup_cl_global;
693 #endif /* HAVE_SERVER_SUPPORT */
695 err = lustre_register_fs();
697 /* simulate a late OOM situation now to require all
698 * alloc'ed/initialized resources to be freed */
699 if (OBD_FAIL_CHECK(OBD_FAIL_OBDCLASS_MODULE_LOAD)) {
700 /* fake error but filesystem has been registered */
701 lustre_unregister_fs();
702 /* force error to ensure module will be unloaded/cleaned */
707 goto cleanup_llog_info;
714 #ifdef HAVE_SERVER_SUPPORT
715 cleanup_lu_ucred_global:
716 lu_ucred_global_fini();
720 #endif /* HAVE_SERVER_SUPPORT */
728 cleanup_class_procfs:
729 class_procfs_clean();
732 obd_cleanup_caches();
735 misc_deregister(&obd_psdev);
737 cleanup_class_handle:
738 class_handle_cleanup();
740 cleanup_zombie_impexp:
741 obd_zombie_impexp_stop();
744 #ifdef CONFIG_PROC_FS
745 lprocfs_free_stats(&obd_memory);
751 void obd_update_maxusage(void)
755 max = obd_memory_sum();
757 spin_lock(&obd_updatemax_lock);
758 if (max > obd_max_alloc)
760 spin_unlock(&obd_updatemax_lock);
762 EXPORT_SYMBOL(obd_update_maxusage);
764 #ifdef CONFIG_PROC_FS
765 __u64 obd_memory_max(void)
769 obd_update_maxusage();
770 spin_lock(&obd_updatemax_lock);
772 spin_unlock(&obd_updatemax_lock);
776 #endif /* CONFIG_PROC_FS */
778 static void __exit obdclass_exit(void)
780 #ifdef CONFIG_PROC_FS
783 #endif /* CONFIG_PROC_FS */
786 lustre_unregister_fs();
788 misc_deregister(&obd_psdev);
790 #ifdef HAVE_SERVER_SUPPORT
791 lu_ucred_global_fini();
793 #endif /* HAVE_SERVER_SUPPORT */
797 obd_cleanup_caches();
799 class_procfs_clean();
801 class_handle_cleanup();
802 class_del_uuid(NULL); /* Delete all UUIDs. */
803 obd_zombie_impexp_stop();
805 #ifdef CONFIG_PROC_FS
806 memory_leaked = obd_memory_sum();
807 memory_max = obd_memory_max();
809 lprocfs_free_stats(&obd_memory);
810 /* the below message is checked in test-framework.sh check_mem_leak() */
811 CDEBUG((memory_leaked) ? D_ERROR : D_INFO,
812 "obd_memory max: %llu, leaked: %llu\n",
813 memory_max, memory_leaked);
814 #endif /* CONFIG_PROC_FS */
819 void obd_heat_clear(struct obd_heat_instance *instance, int count)
823 memset(instance, 0, sizeof(*instance) * count);
826 EXPORT_SYMBOL(obd_heat_clear);
829 * The file heat is calculated for every time interval period I. The access
830 * frequency during each period is counted. The file heat is only recalculated
831 * at the end of a time period. And a percentage of the former file heat is
832 * lost when recalculated. The recursion formula to calculate the heat of the
833 * file f is as follow:
835 * Hi+1(f) = (1-P)*Hi(f)+ P*Ci
837 * Where Hi is the heat value in the period between time points i*I and
838 * (i+1)*I; Ci is the access count in the period; the symbol P refers to the
839 * weight of Ci. The larger the value the value of P is, the more influence Ci
840 * has on the file heat.
842 void obd_heat_decay(struct obd_heat_instance *instance, __u64 time_second,
843 unsigned int weight, unsigned int period_second)
849 if (instance->ohi_time_second > time_second) {
850 obd_heat_clear(instance, 1);
854 if (instance->ohi_time_second == 0)
857 for (second = instance->ohi_time_second + period_second;
858 second < time_second;
859 second += period_second) {
860 instance->ohi_heat = instance->ohi_heat *
861 (256 - weight) / 256 +
862 instance->ohi_count * weight / 256;
863 instance->ohi_count = 0;
864 instance->ohi_time_second = second;
868 EXPORT_SYMBOL(obd_heat_decay);
870 __u64 obd_heat_get(struct obd_heat_instance *instance, unsigned int time_second,
871 unsigned int weight, unsigned int period_second)
875 obd_heat_decay(instance, time_second, weight, period_second);
877 if (instance->ohi_count == 0)
878 RETURN(instance->ohi_heat);
880 RETURN(instance->ohi_heat * (256 - weight) / 256 +
881 instance->ohi_count * weight / 256);
883 EXPORT_SYMBOL(obd_heat_get);
885 void obd_heat_add(struct obd_heat_instance *instance,
886 unsigned int time_second, __u64 count,
887 unsigned int weight, unsigned int period_second)
891 obd_heat_decay(instance, time_second, weight, period_second);
892 if (instance->ohi_time_second == 0) {
893 instance->ohi_time_second = time_second;
894 instance->ohi_heat = 0;
895 instance->ohi_count = count;
897 instance->ohi_count += count;
901 EXPORT_SYMBOL(obd_heat_add);
903 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
904 MODULE_DESCRIPTION("Lustre Class Driver");
905 MODULE_VERSION(LUSTRE_VERSION_STRING);
906 MODULE_LICENSE("GPL");
908 module_init(obdclass_init);
909 module_exit(obdclass_exit);