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 #include <linux/uidgid.h>
38 #include <linux/atomic.h>
39 #include <linux/list.h>
41 #include <obd_support.h>
42 #include <obd_class.h>
43 #include <uapi/linux/lnet/lnetctl.h>
44 #include <lustre_debug.h>
45 #include <lustre_kernelcomm.h>
46 #include <lprocfs_status.h>
47 #include <cl_object.h>
48 #ifdef HAVE_SERVER_SUPPORT
49 # include <dt_object.h>
50 # include <md_object.h>
51 #endif /* HAVE_SERVER_SUPPORT */
52 #include <uapi/linux/lustre/lustre_ioctl.h>
53 #include "llog_internal.h"
56 static __u64 obd_max_alloc;
61 static DEFINE_SPINLOCK(obd_updatemax_lock);
63 /* The following are visible and mutable through /proc/sys/lustre/. */
64 unsigned int obd_debug_peer_on_timeout;
65 EXPORT_SYMBOL(obd_debug_peer_on_timeout);
66 unsigned int obd_dump_on_timeout;
67 EXPORT_SYMBOL(obd_dump_on_timeout);
68 unsigned int obd_dump_on_eviction;
69 EXPORT_SYMBOL(obd_dump_on_eviction);
70 unsigned int obd_lbug_on_eviction;
71 EXPORT_SYMBOL(obd_lbug_on_eviction);
72 unsigned long obd_max_dirty_pages;
73 EXPORT_SYMBOL(obd_max_dirty_pages);
74 atomic_long_t obd_dirty_pages;
75 EXPORT_SYMBOL(obd_dirty_pages);
76 unsigned int obd_timeout = OBD_TIMEOUT_DEFAULT; /* seconds */
77 EXPORT_SYMBOL(obd_timeout);
78 unsigned int ldlm_timeout = LDLM_TIMEOUT_DEFAULT; /* seconds */
79 EXPORT_SYMBOL(ldlm_timeout);
80 unsigned int obd_timeout_set;
81 EXPORT_SYMBOL(obd_timeout_set);
82 unsigned int ldlm_timeout_set;
83 EXPORT_SYMBOL(ldlm_timeout_set);
84 /* bulk transfer timeout, give up after 100s by default */
85 unsigned int bulk_timeout = 100; /* seconds */
86 EXPORT_SYMBOL(bulk_timeout);
87 /* Adaptive timeout defs here instead of ptlrpc module for /proc/sys/ access */
88 unsigned int at_min = 0;
89 EXPORT_SYMBOL(at_min);
90 unsigned int at_max = 600;
91 EXPORT_SYMBOL(at_max);
92 unsigned int at_history = 600;
93 EXPORT_SYMBOL(at_history);
94 int at_early_margin = 5;
95 EXPORT_SYMBOL(at_early_margin);
97 EXPORT_SYMBOL(at_extra);
100 struct lprocfs_stats *obd_memory = NULL;
101 EXPORT_SYMBOL(obd_memory);
104 static int class_resolve_dev_name(__u32 len, const char *name)
111 CERROR("No name passed,!\n");
112 GOTO(out, rc = -EINVAL);
114 if (name[len - 1] != 0) {
115 CERROR("Name not nul terminated!\n");
116 GOTO(out, rc = -EINVAL);
119 CDEBUG(D_IOCTL, "device name %s\n", name);
120 dev = class_name2dev(name);
122 CDEBUG(D_IOCTL, "No device for name %s!\n", name);
123 GOTO(out, rc = -EINVAL);
126 CDEBUG(D_IOCTL, "device name %s, dev %d\n", name, dev);
133 #define OBD_MAX_IOCTL_BUFFER 8192
135 static int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
137 if (data->ioc_len > BIT(30)) {
138 CERROR("OBD ioctl: ioc_len larger than 1<<30\n");
142 if (data->ioc_inllen1 > BIT(30)) {
143 CERROR("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
147 if (data->ioc_inllen2 > BIT(30)) {
148 CERROR("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
152 if (data->ioc_inllen3 > BIT(30)) {
153 CERROR("OBD ioctl: ioc_inllen3 larger than 1<<30\n");
157 if (data->ioc_inllen4 > BIT(30)) {
158 CERROR("OBD ioctl: ioc_inllen4 larger than 1<<30\n");
162 if (data->ioc_inlbuf1 && data->ioc_inllen1 == 0) {
163 CERROR("OBD ioctl: inlbuf1 pointer but 0 length\n");
167 if (data->ioc_inlbuf2 && data->ioc_inllen2 == 0) {
168 CERROR("OBD ioctl: inlbuf2 pointer but 0 length\n");
172 if (data->ioc_inlbuf3 && data->ioc_inllen3 == 0) {
173 CERROR("OBD ioctl: inlbuf3 pointer but 0 length\n");
177 if (data->ioc_inlbuf4 && data->ioc_inllen4 == 0) {
178 CERROR("OBD ioctl: inlbuf4 pointer but 0 length\n");
182 if (data->ioc_pbuf1 && data->ioc_plen1 == 0) {
183 CERROR("OBD ioctl: pbuf1 pointer but 0 length\n");
187 if (data->ioc_pbuf2 && data->ioc_plen2 == 0) {
188 CERROR("OBD ioctl: pbuf2 pointer but 0 length\n");
192 if (!data->ioc_pbuf1 && data->ioc_plen1 != 0) {
193 CERROR("OBD ioctl: plen1 set but NULL pointer\n");
197 if (!data->ioc_pbuf2 && data->ioc_plen2 != 0) {
198 CERROR("OBD ioctl: plen2 set but NULL pointer\n");
202 if (obd_ioctl_packlen(data) > data->ioc_len) {
203 CERROR("OBD ioctl: packlen exceeds ioc_len (%d > %d)\n",
204 obd_ioctl_packlen(data), data->ioc_len);
211 /* buffer MUST be at least the size of obd_ioctl_hdr */
212 int obd_ioctl_getdata(char **buf, int *len, void __user *arg)
214 struct obd_ioctl_hdr hdr;
215 struct obd_ioctl_data *data;
219 if (copy_from_user(&hdr, arg, sizeof(hdr)))
222 if (hdr.ioc_version != OBD_IOCTL_VERSION) {
223 CERROR("Version mismatch kernel (%x) vs application (%x)\n",
224 OBD_IOCTL_VERSION, hdr.ioc_version);
228 if (hdr.ioc_len > OBD_MAX_IOCTL_BUFFER) {
229 CERROR("User buffer len %d exceeds %d max buffer\n",
230 hdr.ioc_len, OBD_MAX_IOCTL_BUFFER);
234 if (hdr.ioc_len < sizeof(struct obd_ioctl_data)) {
235 CERROR("User buffer too small for ioctl (%d)\n", hdr.ioc_len);
239 /* When there are lots of processes calling vmalloc on multi-core
240 * system, the high lock contention will hurt performance badly,
241 * obdfilter-survey is an example, which relies on ioctl. So we'd
242 * better avoid vmalloc on ioctl path. LU-66
244 OBD_ALLOC_LARGE(*buf, hdr.ioc_len);
246 CERROR("Cannot allocate control buffer of len %d\n",
251 data = (struct obd_ioctl_data *)*buf;
253 if (copy_from_user(*buf, arg, hdr.ioc_len)) {
254 OBD_FREE_LARGE(*buf, hdr.ioc_len);
258 if (obd_ioctl_is_invalid(data)) {
259 CERROR("ioctl not correctly formatted\n");
260 OBD_FREE_LARGE(*buf, hdr.ioc_len);
264 if (data->ioc_inllen1) {
265 data->ioc_inlbuf1 = &data->ioc_bulk[0];
266 offset += cfs_size_round(data->ioc_inllen1);
269 if (data->ioc_inllen2) {
270 data->ioc_inlbuf2 = &data->ioc_bulk[0] + offset;
271 offset += cfs_size_round(data->ioc_inllen2);
274 if (data->ioc_inllen3) {
275 data->ioc_inlbuf3 = &data->ioc_bulk[0] + offset;
276 offset += cfs_size_round(data->ioc_inllen3);
279 if (data->ioc_inllen4)
280 data->ioc_inlbuf4 = &data->ioc_bulk[0] + offset;
284 EXPORT_SYMBOL(obd_ioctl_getdata);
286 int class_handle_ioctl(unsigned int cmd, unsigned long arg)
289 struct obd_ioctl_data *data;
290 struct obd_device *obd = NULL;
291 int err = 0, len = 0;
294 CDEBUG(D_IOCTL, "cmd = %x\n", cmd);
295 if (obd_ioctl_getdata(&buf, &len, (void __user *)arg)) {
296 CERROR("OBD ioctl: data error\n");
299 data = (struct obd_ioctl_data *)buf;
302 case OBD_IOC_PROCESS_CFG: {
303 struct lustre_cfg *lcfg;
305 if (!data->ioc_plen1 || !data->ioc_pbuf1) {
306 CERROR("No config buffer passed!\n");
307 GOTO(out, err = -EINVAL);
309 OBD_ALLOC(lcfg, data->ioc_plen1);
311 GOTO(out, err = -ENOMEM);
312 err = copy_from_user(lcfg, data->ioc_pbuf1,
315 err = lustre_cfg_sanity_check(lcfg, data->ioc_plen1);
317 err = class_process_config(lcfg);
319 OBD_FREE(lcfg, data->ioc_plen1);
323 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
324 case OBD_GET_VERSION: {
327 if (!data->ioc_inlbuf1) {
328 CERROR("No buffer passed in ioctl\n");
329 GOTO(out, err = -EINVAL);
332 if (strlen(LUSTRE_VERSION_STRING) + 1 > data->ioc_inllen1) {
333 CERROR("ioctl buffer too small to hold version\n");
334 GOTO(out, err = -EINVAL);
339 CWARN("%s: ioctl(OBD_GET_VERSION) is deprecated, "
340 "use llapi_get_version_string() and/or relink\n",
343 memcpy(data->ioc_bulk, LUSTRE_VERSION_STRING,
344 strlen(LUSTRE_VERSION_STRING) + 1);
346 if (copy_to_user((void __user *)arg, data, len))
351 case OBD_IOC_NAME2DEV: {
352 /* Resolve a device name. This does not change the
353 * currently selected device.
357 dev = class_resolve_dev_name(data->ioc_inllen1,
361 GOTO(out, err = -EINVAL);
363 if (copy_to_user((void __user *)arg, data, sizeof(*data)))
368 case OBD_IOC_UUID2DEV: {
369 /* Resolve a device uuid. This does not change the
370 * currently selected device.
373 struct obd_uuid uuid;
375 if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
376 CERROR("No UUID passed!\n");
377 GOTO(out, err = -EINVAL);
379 if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) {
380 CERROR("UUID not NUL terminated!\n");
381 GOTO(out, err = -EINVAL);
384 CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
385 obd_str2uuid(&uuid, data->ioc_inlbuf1);
386 dev = class_uuid2dev(&uuid);
389 CDEBUG(D_IOCTL, "No device for UUID %s!\n",
391 GOTO(out, err = -EINVAL);
394 CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1,
396 if (copy_to_user((void __user *)arg, data, sizeof(*data)))
401 case OBD_IOC_GETDEVICE: {
402 int index = data->ioc_count;
405 if (!data->ioc_inlbuf1) {
406 CERROR("No buffer passed in ioctl\n");
407 GOTO(out, err = -EINVAL);
409 if (data->ioc_inllen1 < 128) {
410 CERROR("ioctl buffer too small to hold version\n");
411 GOTO(out, err = -EINVAL);
414 obd = class_num2obd(index);
416 GOTO(out, err = -ENOENT);
418 if (obd->obd_stopping)
420 else if (obd->obd_inactive)
422 else if (obd->obd_set_up)
424 else if (obd->obd_attached)
429 str = (char *)data->ioc_bulk;
430 snprintf(str, len - sizeof(*data), "%3d %s %s %s %s %d",
431 (int)index, status, obd->obd_type->typ_name,
432 obd->obd_name, obd->obd_uuid.uuid,
433 atomic_read(&obd->obd_refcount));
435 if (copy_to_user((void __user *)arg, data, len))
443 if (data->ioc_dev == OBD_DEV_BY_DEVNAME) {
444 if (data->ioc_inllen4 <= 0 || data->ioc_inlbuf4 == NULL)
445 GOTO(out, err = -EINVAL);
446 if (strnlen(data->ioc_inlbuf4, MAX_OBD_NAME) >= MAX_OBD_NAME)
447 GOTO(out, err = -EINVAL);
448 obd = class_name2obd(data->ioc_inlbuf4);
449 } else if (data->ioc_dev < class_devno_max()) {
450 obd = class_num2obd(data->ioc_dev);
452 CERROR("OBD ioctl: No device\n");
453 GOTO(out, err = -EINVAL);
457 CERROR("OBD ioctl : No Device %d\n", data->ioc_dev);
458 GOTO(out, err = -EINVAL);
460 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
462 if (!obd->obd_set_up || obd->obd_stopping) {
463 CERROR("OBD ioctl: device not setup %d \n", data->ioc_dev);
464 GOTO(out, err = -EINVAL);
468 case OBD_IOC_NO_TRANSNO: {
469 if (!obd->obd_attached) {
470 CERROR("Device %d not attached\n", obd->obd_minor);
471 GOTO(out, err = -ENODEV);
473 CDEBUG(D_HA, "%s: disabling committed-transno notification\n",
475 obd->obd_no_transno = 1;
480 err = obd_iocontrol(cmd, obd->obd_self_export, len, data, NULL);
484 if (copy_to_user((void __user *)arg, data, len))
491 OBD_FREE_LARGE(buf, len);
493 } /* class_handle_ioctl */
495 /* to control /dev/obd */
496 static long obd_class_ioctl(struct file *filp, unsigned int cmd,
502 /* Allow non-root access for some limited ioctls */
503 if (!cfs_capable(CFS_CAP_SYS_ADMIN))
504 RETURN(err = -EACCES);
506 if ((cmd & 0xffffff00) == ((int)'T') << 8) /* ignore all tty ioctls */
507 RETURN(err = -ENOTTY);
509 err = class_handle_ioctl(cmd, (unsigned long)arg);
514 /* declare character device */
515 static struct file_operations obd_psdev_fops = {
516 .owner = THIS_MODULE,
517 .unlocked_ioctl = obd_class_ioctl, /* unlocked_ioctl */
521 struct miscdevice obd_psdev = {
522 .minor = MISC_DYNAMIC_MINOR,
523 .name = OBD_DEV_NAME,
524 .fops = &obd_psdev_fops,
527 static int obd_init_checks(void)
529 __u64 u64val, div64val;
533 CDEBUG(D_INFO, "OBD_OBJECT_EOF = %#llx\n", (__u64)OBD_OBJECT_EOF);
535 u64val = OBD_OBJECT_EOF;
536 CDEBUG(D_INFO, "u64val OBD_OBJECT_EOF = %#llx\n", u64val);
537 if (u64val != OBD_OBJECT_EOF) {
538 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
539 u64val, (int)sizeof(u64val));
542 len = snprintf(buf, sizeof(buf), "%#llx", u64val);
544 CWARN("u64 hex wrong length! strlen(%s)=%d != 18\n", buf, len);
548 div64val = OBD_OBJECT_EOF;
549 CDEBUG(D_INFO, "u64val OBD_OBJECT_EOF = %#llx\n", u64val);
550 if (u64val != OBD_OBJECT_EOF) {
551 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
552 u64val, (int)sizeof(u64val));
555 if (u64val >> 8 != OBD_OBJECT_EOF >> 8) {
556 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
557 u64val, (int)sizeof(u64val));
560 if (do_div(div64val, 256) != (u64val & 255)) {
561 CERROR("do_div(%#llx,256) != %llu\n", u64val, u64val & 255);
564 if (u64val >> 8 != div64val) {
565 CERROR("do_div(%#llx,256) %llu != %llu\n",
566 u64val, div64val, u64val >> 8);
569 len = snprintf(buf, sizeof(buf), "%#llx", u64val);
571 CWARN("u64 hex wrong length! strlen(%s)=%d != 18\n", buf, len);
574 len = snprintf(buf, sizeof(buf), "%llu", u64val);
576 CWARN("u64 wrong length! strlen(%s)=%d != 20\n", buf, len);
579 len = snprintf(buf, sizeof(buf), "%lld", u64val);
581 CWARN("s64 wrong length! strlen(%s)=%d != 2\n", buf, len);
584 if ((u64val & ~PAGE_MASK) >= PAGE_SIZE) {
585 CWARN("mask failed: u64val %llu >= %llu\n", u64val,
593 static int __init obdclass_init(void)
597 LCONSOLE_INFO("Lustre: Build Version: "LUSTRE_VERSION_STRING"\n");
601 err = obd_init_checks();
602 if (err == -EOVERFLOW)
605 #ifdef CONFIG_PROC_FS
606 obd_memory = lprocfs_alloc_stats(OBD_STATS_NUM,
607 LPROCFS_STATS_FLAG_NONE |
608 LPROCFS_STATS_FLAG_IRQ_SAFE);
609 if (obd_memory == NULL) {
610 CERROR("kmalloc of 'obd_memory' failed\n");
614 lprocfs_counter_init(obd_memory, OBD_MEMORY_STAT,
615 LPROCFS_CNTR_AVGMINMAX,
618 err = obd_zombie_impexp_init();
620 goto cleanup_obd_memory;
622 err = class_handle_init();
624 goto cleanup_zombie_impexp;
626 err = misc_register(&obd_psdev);
628 CERROR("cannot register OBD miscdevice: err = %d\n", err);
629 goto cleanup_class_handle;
632 /* Default the dirty page cache cap to 1/2 of system memory.
633 * For clients with less memory, a larger fraction is needed
634 * for other purposes (mostly for BGL). */
635 if (cfs_totalram_pages() <= 512 << (20 - PAGE_SHIFT))
636 obd_max_dirty_pages = cfs_totalram_pages() / 4;
638 obd_max_dirty_pages = cfs_totalram_pages() / 2;
640 err = obd_init_caches();
642 goto cleanup_deregister;
644 err = class_procfs_init();
648 err = lu_global_init();
650 goto cleanup_class_procfs;
652 err = cl_global_init();
654 goto cleanup_lu_global;
656 #ifdef HAVE_SERVER_SUPPORT
657 err = dt_global_init();
659 goto cleanup_cl_global;
661 err = lu_ucred_global_init();
663 goto cleanup_dt_global;
664 #endif /* HAVE_SERVER_SUPPORT */
666 err = llog_info_init();
668 #ifdef HAVE_SERVER_SUPPORT
669 goto cleanup_lu_ucred_global;
670 #else /* !HAVE_SERVER_SUPPORT */
671 goto cleanup_cl_global;
672 #endif /* HAVE_SERVER_SUPPORT */
674 err = lustre_register_fs();
676 /* simulate a late OOM situation now to require all
677 * alloc'ed/initialized resources to be freed */
678 if (OBD_FAIL_CHECK(OBD_FAIL_OBDCLASS_MODULE_LOAD)) {
679 /* fake error but filesystem has been registered */
680 lustre_unregister_fs();
681 /* force error to ensure module will be unloaded/cleaned */
686 goto cleanup_llog_info;
693 #ifdef HAVE_SERVER_SUPPORT
694 cleanup_lu_ucred_global:
695 lu_ucred_global_fini();
699 #endif /* HAVE_SERVER_SUPPORT */
707 cleanup_class_procfs:
708 class_procfs_clean();
711 obd_cleanup_caches();
714 misc_deregister(&obd_psdev);
716 cleanup_class_handle:
717 class_handle_cleanup();
719 cleanup_zombie_impexp:
720 obd_zombie_impexp_stop();
723 #ifdef CONFIG_PROC_FS
724 lprocfs_free_stats(&obd_memory);
730 void obd_update_maxusage(void)
734 max = obd_memory_sum();
736 spin_lock(&obd_updatemax_lock);
737 if (max > obd_max_alloc)
739 spin_unlock(&obd_updatemax_lock);
741 EXPORT_SYMBOL(obd_update_maxusage);
743 #ifdef CONFIG_PROC_FS
744 __u64 obd_memory_max(void)
748 obd_update_maxusage();
749 spin_lock(&obd_updatemax_lock);
751 spin_unlock(&obd_updatemax_lock);
755 #endif /* CONFIG_PROC_FS */
757 static void __exit obdclass_exit(void)
759 #ifdef CONFIG_PROC_FS
762 #endif /* CONFIG_PROC_FS */
765 lustre_unregister_fs();
767 misc_deregister(&obd_psdev);
769 #ifdef HAVE_SERVER_SUPPORT
770 lu_ucred_global_fini();
772 #endif /* HAVE_SERVER_SUPPORT */
776 obd_cleanup_caches();
778 class_procfs_clean();
780 class_handle_cleanup();
781 class_del_uuid(NULL); /* Delete all UUIDs. */
782 obd_zombie_impexp_stop();
784 #ifdef CONFIG_PROC_FS
785 memory_leaked = obd_memory_sum();
786 memory_max = obd_memory_max();
788 lprocfs_free_stats(&obd_memory);
789 /* the below message is checked in test-framework.sh check_mem_leak() */
790 CDEBUG((memory_leaked) ? D_ERROR : D_INFO,
791 "obd_memory max: %llu, leaked: %llu\n",
792 memory_max, memory_leaked);
793 #endif /* CONFIG_PROC_FS */
798 void obd_heat_clear(struct obd_heat_instance *instance, int count)
802 memset(instance, 0, sizeof(*instance) * count);
805 EXPORT_SYMBOL(obd_heat_clear);
808 * The file heat is calculated for every time interval period I. The access
809 * frequency during each period is counted. The file heat is only recalculated
810 * at the end of a time period. And a percentage of the former file heat is
811 * lost when recalculated. The recursion formula to calculate the heat of the
812 * file f is as follow:
814 * Hi+1(f) = (1-P)*Hi(f)+ P*Ci
816 * Where Hi is the heat value in the period between time points i*I and
817 * (i+1)*I; Ci is the access count in the period; the symbol P refers to the
818 * weight of Ci. The larger the value the value of P is, the more influence Ci
819 * has on the file heat.
821 void obd_heat_decay(struct obd_heat_instance *instance, __u64 time_second,
822 unsigned int weight, unsigned int period_second)
828 if (instance->ohi_time_second > time_second) {
829 obd_heat_clear(instance, 1);
833 if (instance->ohi_time_second == 0)
836 for (second = instance->ohi_time_second + period_second;
837 second < time_second;
838 second += period_second) {
839 instance->ohi_heat = instance->ohi_heat *
840 (256 - weight) / 256 +
841 instance->ohi_count * weight / 256;
842 instance->ohi_count = 0;
843 instance->ohi_time_second = second;
847 EXPORT_SYMBOL(obd_heat_decay);
849 __u64 obd_heat_get(struct obd_heat_instance *instance, unsigned int time_second,
850 unsigned int weight, unsigned int period_second)
854 obd_heat_decay(instance, time_second, weight, period_second);
856 if (instance->ohi_count == 0)
857 RETURN(instance->ohi_heat);
859 RETURN(instance->ohi_heat * (256 - weight) / 256 +
860 instance->ohi_count * weight / 256);
862 EXPORT_SYMBOL(obd_heat_get);
864 void obd_heat_add(struct obd_heat_instance *instance,
865 unsigned int time_second, __u64 count,
866 unsigned int weight, unsigned int period_second)
870 obd_heat_decay(instance, time_second, weight, period_second);
871 if (instance->ohi_time_second == 0) {
872 instance->ohi_time_second = time_second;
873 instance->ohi_heat = 0;
874 instance->ohi_count = count;
876 instance->ohi_count += count;
880 EXPORT_SYMBOL(obd_heat_add);
882 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
883 MODULE_DESCRIPTION("Lustre Class Driver");
884 MODULE_VERSION(LUSTRE_VERSION_STRING);
885 MODULE_LICENSE("GPL");
887 module_init(obdclass_init);
888 module_exit(obdclass_exit);