Whamcloud - gitweb
LU-15420 build: fixes to support building on Ubuntu 22.04 LTS
[fs/lustre-release.git] / libcfs / include / libcfs / linux / linux-misc.h
index ab1e2ff..faec22b 100644 (file)
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  */
 
 #ifndef __LIBCFS_LINUX_MISC_H__
 #define __LIBCFS_LINUX_MISC_H__
 
 #include <linux/fs.h>
+/* Since Commit 2f8b544477e6 ("block,fs: untangle fs.h and blk_types.h")
+ * fs.h doesn't include blk_types.h, but we need it.
+ */
+#include <linux/blk_types.h>
 #include <linux/mutex.h>
 #include <linux/user_namespace.h>
 #include <linux/uio.h>
+#include <linux/kallsyms.h>
 
 #ifndef HAVE_IOV_ITER_TYPE
 #ifdef HAVE_IOV_ITER_HAS_TYPE_MEMBER
@@ -54,8 +58,6 @@
 #endif
 #endif /* HAVE_IOV_ITER_TYPE */
 
-int cfs_get_environ(const char *key, char *value, int *val_len);
-
 int cfs_kernel_write(struct file *filp, const void *buf, size_t count,
                     loff_t *pos);
 ssize_t cfs_kernel_read(struct file *file, void *buf, size_t count,
@@ -95,6 +97,31 @@ int cfs_apply_workqueue_attrs(struct workqueue_struct *wq,
 int kstrtobool_from_user(const char __user *s, size_t count, bool *res);
 #endif /* HAVE_KSTRTOBOOL_FROM_USER */
 
+#ifndef HAVE_MATCH_WILDCARD
+bool match_wildcard(const char *pattern, const char *str);
+#endif /* !HAVE_MATCH_WILDCARD */
+
+#ifndef HAVE_KREF_READ
+static inline int kref_read(const struct kref *kref)
+{
+       return atomic_read(&kref->refcount);
+}
+#endif /* HAVE_KREF_READ */
+
+#ifdef HAVE_FORCE_SIG_WITH_TASK
+#define cfs_force_sig(sig, task)       force_sig((sig), (task))
+#else
+#define cfs_force_sig(sig, task)                                       \
+do {                                                                   \
+       unsigned long flags;                                            \
+                                                                       \
+       spin_lock_irqsave(&task->sighand->siglock, flags);              \
+       task->sighand->action[sig - 1].sa.sa_handler = SIG_DFL;         \
+       send_sig(sig, task, 1);                                         \
+       spin_unlock_irqrestore(&task->sighand->siglock, flags);         \
+} while (0)
+#endif
+
 void cfs_arch_init(void);
 
 #ifndef container_of_safe
@@ -114,4 +141,29 @@ void cfs_arch_init(void);
                ((type *)(__mptr - offsetof(type, member))); })
 #endif
 
+/*
+ * Linux v4.15-rc2-5-g4229a470175b added sizeof_field()
+ * Linux v5.5-rc4-1-g1f07dcc459d5 removed FIELD_SIZEOF()
+ * Proved a sizeof_field in terms of FIELD_SIZEOF() when one is not provided
+ */
+#ifndef sizeof_field
+#define sizeof_field(type, member)     FIELD_SIZEOF(type, member)
+#endif
+
+#ifndef HAVE_TASK_IS_RUNNING
+#define task_is_running(task)          (task->state == TASK_RUNNING)
+#endif
+
+#ifdef HAVE_KALLSYMS_LOOKUP_NAME
+static inline void *cfs_kallsyms_lookup_name(const char *name)
+{
+       return (void *)kallsyms_lookup_name(name);
+}
+#else
+static inline void *cfs_kallsyms_lookup_name(const char *name)
+{
+       return NULL;
+}
+#endif
+
 #endif /* __LIBCFS_LINUX_MISC_H__ */