Whamcloud - gitweb
LU-9859 libcfs: delete libcfs/linux/libcfs.h
[fs/lustre-release.git] / libcfs / libcfs / linux / linux-prim.c
index 072f679..6c10376 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
 #include <linux/kernel.h>
 #include <linux/fs_struct.h>
 #include <linux/sched.h>
-
+#ifdef HAVE_SCHED_HEADERS
+#include <linux/sched/signal.h>
+#include <linux/sched/mm.h>
+#endif
 #include <libcfs/libcfs.h>
 
 #if defined(CONFIG_KGDB)
 #include <asm/kgdb.h>
 #endif
 
-void cfs_init_timer(struct timer_list *t)
+#ifndef HAVE_KTIME_GET_TS64
+void ktime_get_ts64(struct timespec64 *ts)
 {
-       init_timer(t);
-}
-EXPORT_SYMBOL(cfs_init_timer);
+       struct timespec now;
 
-void cfs_timer_init(struct timer_list *t, cfs_timer_func_t *func, void *arg)
-{
-       init_timer(t);
-       t->function = func;
-       t->data = (unsigned long)arg;
+       ktime_get_ts(&now);
+       *ts = timespec_to_timespec64(now);
 }
-EXPORT_SYMBOL(cfs_timer_init);
+EXPORT_SYMBOL(ktime_get_ts64);
+#endif /* HAVE_KTIME_GET_TS64 */
 
-void cfs_timer_done(struct timer_list *t)
+#ifndef HAVE_KTIME_GET_REAL_TS64
+void ktime_get_real_ts64(struct timespec64 *ts)
 {
-       return;
-}
-EXPORT_SYMBOL(cfs_timer_done);
+       struct timespec now;
 
-void cfs_timer_arm(struct timer_list *t, cfs_time_t deadline)
-{
-       mod_timer(t, deadline);
+       getnstimeofday(&now);
+       *ts = timespec_to_timespec64(now);
 }
-EXPORT_SYMBOL(cfs_timer_arm);
+EXPORT_SYMBOL(ktime_get_real_ts64);
+#endif /* HAVE_KTIME_GET_REAL_TS64 */
 
-void cfs_timer_disarm(struct timer_list *t)
+#ifndef HAVE_KTIME_GET_REAL_SECONDS
+/*
+ * Get the seconds portion of CLOCK_REALTIME (wall clock).
+ * This is the clock that can be altered by NTP and is
+ * independent of a reboot.
+ */
+time64_t ktime_get_real_seconds(void)
 {
-       del_timer(t);
+       return (time64_t)get_seconds();
 }
-EXPORT_SYMBOL(cfs_timer_disarm);
+EXPORT_SYMBOL(ktime_get_real_seconds);
+#endif /* HAVE_KTIME_GET_REAL_SECONDS */
 
-int  cfs_timer_is_armed(struct timer_list *t)
+#ifndef HAVE_KTIME_GET_SECONDS
+/*
+ * Get the seconds portion of CLOCK_MONOTONIC
+ * This clock is immutable and is reset across
+ * reboots. For older platforms this is a
+ * wrapper around get_seconds which is valid
+ * until 2038. By that time this will be gone
+ * one would hope.
+ */
+time64_t ktime_get_seconds(void)
 {
-       return timer_pending(t);
-}
-EXPORT_SYMBOL(cfs_timer_is_armed);
+       struct timespec64 now;
 
-cfs_time_t cfs_timer_deadline(struct timer_list *t)
-{
-       return t->expires;
+       ktime_get_ts64(&now);
+       return now.tv_sec;
 }
-EXPORT_SYMBOL(cfs_timer_deadline);
+EXPORT_SYMBOL(ktime_get_seconds);
+#endif /* HAVE_KTIME_GET_SECONDS */
 
-void cfs_enter_debugger(void)
+#ifndef HAVE_KSET_FIND_OBJ
+struct kobject *kset_find_obj(struct kset *kset, const char *name)
 {
-#if defined(CONFIG_KGDB)
-//        BREAKPOINT();
-#else
-        /* nothing */
-#endif
+       struct kobject *ret = NULL;
+       struct kobject *k;
+
+       spin_lock(&kset->list_lock);
+
+       list_for_each_entry(k, &kset->list, entry) {
+               if (kobject_name(k) && !strcmp(kobject_name(k), name)) {
+                       if (kref_get_unless_zero(&k->kref))
+                               ret = k;
+                       break;
+               }
+       }
+
+       spin_unlock(&kset->list_lock);
+       return ret;
 }
-EXPORT_SYMBOL(cfs_enter_debugger);
+EXPORT_SYMBOL_GPL(kset_find_obj);
+#endif
 
 sigset_t
 cfs_block_allsigs(void)