Whamcloud - gitweb
LU-9680 utils: add netlink infrastructure
[fs/lustre-release.git] / libcfs / libcfs / linux / linux-prim.c
index 1f29c52..1bdab05 100644 (file)
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  */
 
 #define DEBUG_SUBSYSTEM S_LNET
 
-#include <linux/kallsyms.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/fs.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 <linux/slab.h>
 #include <linux/uaccess.h>
+#include <net/netlink.h>
 
 #if defined(CONFIG_KGDB)
 #include <asm/kgdb.h>
 #endif
 
 #include <libcfs/linux/linux-time.h>
+#include <libcfs/linux/linux-wait.h>
+#include <libcfs/linux/linux-misc.h>
 
 #ifndef HAVE_KTIME_GET_TS64
 void ktime_get_ts64(struct timespec64 *ts)
@@ -110,19 +110,27 @@ static int (*cfs_apply_workqueue_attrs_t)(struct workqueue_struct *wq,
 int cfs_apply_workqueue_attrs(struct workqueue_struct *wq,
                              const struct workqueue_attrs *attrs)
 {
-       return cfs_apply_workqueue_attrs_t(wq, attrs);
+       if (cfs_apply_workqueue_attrs_t)
+               return cfs_apply_workqueue_attrs_t(wq, attrs);
+       return 0;
 }
 EXPORT_SYMBOL_GPL(cfs_apply_workqueue_attrs);
 
-struct kmem_cache (*cfs_radix_tree_node_cachep);
+#ifndef HAVE_XARRAY_SUPPORT
+struct kmem_cache (*radix_tree_node_cachep);
+#endif
 
-void cfs_arch_init(void)
+void __init cfs_arch_init(void)
 {
 #ifndef HAVE_WAIT_VAR_EVENT
        wait_bit_init();
 #endif
        cfs_apply_workqueue_attrs_t =
-               (void *)kallsyms_lookup_name("apply_workqueue_attrs");
+               (void *)cfs_kallsyms_lookup_name("apply_workqueue_attrs");
+#ifndef HAVE_XARRAY_SUPPORT
+       radix_tree_node_cachep =
+               (void *)cfs_kallsyms_lookup_name("radix_tree_node_cachep");
+#endif
 }
 
 int cfs_kernel_write(struct file *filp, const void *buf, size_t count,
@@ -194,54 +202,21 @@ int kstrtobool_from_user(const char __user *s, size_t count, bool *res)
 EXPORT_SYMBOL(kstrtobool_from_user);
 #endif /* !HAVE_KSTRTOBOOL_FROM_USER */
 
-sigset_t cfs_block_sigs(unsigned long sigs)
-{
-       unsigned long  flags;
-       sigset_t        old;
-
-       spin_lock_irqsave(&current->sighand->siglock, flags);
-       old = current->blocked;
-       sigaddsetmask(&current->blocked, sigs);
-       recalc_sigpending();
-       spin_unlock_irqrestore(&current->sighand->siglock, flags);
-       return old;
-}
-EXPORT_SYMBOL(cfs_block_sigs);
-
-/* Block all signals except for the @sigs */
-sigset_t cfs_block_sigsinv(unsigned long sigs)
-{
-       unsigned long flags;
-       sigset_t old;
-
-       spin_lock_irqsave(&current->sighand->siglock, flags);
-       old = current->blocked;
-       sigaddsetmask(&current->blocked, ~sigs);
-       recalc_sigpending();
-       spin_unlock_irqrestore(&current->sighand->siglock, flags);
-       return old;
-}
-EXPORT_SYMBOL(cfs_block_sigsinv);
-
-void
-cfs_restore_sigs(sigset_t old)
+#ifndef HAVE_NLA_STRDUP
+char *nla_strdup(const struct nlattr *nla, gfp_t flags)
 {
-       unsigned long  flags;
-
-       spin_lock_irqsave(&current->sighand->siglock, flags);
-       current->blocked = old;
-       recalc_sigpending();
-       spin_unlock_irqrestore(&current->sighand->siglock, flags);
-}
-EXPORT_SYMBOL(cfs_restore_sigs);
+       size_t srclen = nla_len(nla);
+       char *src = nla_data(nla), *dst;
 
-void
-cfs_clear_sigpending(void)
-{
-       unsigned long flags;
+       if (srclen > 0 && src[srclen - 1] == '\0')
+               srclen--;
 
-       spin_lock_irqsave(&current->sighand->siglock, flags);
-       clear_tsk_thread_flag(current, TIF_SIGPENDING);
-       spin_unlock_irqrestore(&current->sighand->siglock, flags);
+       dst = kmalloc(srclen + 1, flags);
+       if (dst != NULL) {
+               memcpy(dst, src, srclen);
+               dst[srclen] = '\0';
+       }
+       return dst;
 }
-EXPORT_SYMBOL(cfs_clear_sigpending);
+EXPORT_SYMBOL(nla_strdup);
+#endif /* !HAVE_NLA_STRDUP */