X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=libcfs%2Finclude%2Flibcfs%2Flinux%2Flinux-misc.h;h=b9963e48c77c69691550486d38ae35144e1aaa21;hb=refs%2Fchanges%2F41%2F44541%2F16;hp=351eaa721aa346b0a8c05a68c27ed7a85aba1133;hpb=cda0a8abf5bbfe0f3fc12454c1d3d8efdcbda17c;p=fs%2Flustre-release.git diff --git a/libcfs/include/libcfs/linux/linux-misc.h b/libcfs/include/libcfs/linux/linux-misc.h index 351eaa7..b9963e4 100644 --- a/libcfs/include/libcfs/linux/linux-misc.h +++ b/libcfs/include/libcfs/linux/linux-misc.h @@ -27,90 +27,41 @@ */ /* * 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 +/* 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 #include #include - -#ifdef HAVE_SYSCTL_CTLNAME -#define INIT_CTL_NAME .ctl_name = CTL_UNNUMBERED, -#define INIT_STRATEGY .strategy = &sysctl_intvec, +#include +#include + +#ifndef HAVE_IOV_ITER_TYPE +#ifdef HAVE_IOV_ITER_HAS_TYPE_MEMBER +#define iter_is_iovec(iter) ((iter)->type & ITER_IOVEC) +#define iov_iter_is_kvec(iter) ((iter)->type & ITER_KVEC) +#define iov_iter_is_bvec(iter) ((iter)->type & ITER_BVEC) +#define iov_iter_is_pipe(iter) ((iter)->type & ITER_PIPE) +#define iov_iter_is_discard(iter) ((iter)->type & ITER_DISCARD) #else -#define INIT_CTL_NAME -#define INIT_STRATEGY +#define iter_is_iovec(iter) 1 +#define iov_iter_is_kvec(iter) 0 +#define iov_iter_is_bvec(iter) 0 +#define iov_iter_is_pipe(iter) 0 +#define iov_iter_is_discard(iter) 0 #endif +#endif /* HAVE_IOV_ITER_TYPE */ -#ifndef HAVE_MODULE_PARAM_LOCKING -static DEFINE_MUTEX(param_lock); -#endif - -#ifndef HAVE_UIDGID_HEADER - -#ifndef _LINUX_UIDGID_H -#define _LINUX_UIDGID_H - -typedef uid_t kuid_t; -typedef gid_t kgid_t; - -#define INVALID_UID -1 -#define INVALID_GID -1 - -#define GLOBAL_ROOT_UID 0 -#define GLOBAL_ROOT_GID 0 - -static inline uid_t __kuid_val(kuid_t uid) -{ - return uid; -} - -static inline gid_t __kgid_val(kgid_t gid) -{ - return gid; -} - -static inline kuid_t make_kuid(struct user_namespace *from, uid_t uid) -{ - return uid; -} - -static inline kgid_t make_kgid(struct user_namespace *from, gid_t gid) -{ - return gid; -} - -static inline uid_t from_kuid(struct user_namespace *to, kuid_t uid) -{ - return uid; -} - -static inline gid_t from_kgid(struct user_namespace *to, kgid_t gid) -{ - return gid; -} - -static inline bool uid_eq(kuid_t left, kuid_t right) -{ - return left == right; -} - -static inline bool uid_valid(kuid_t uid) -{ - return uid != (typeof(uid))INVALID_UID; -} - -static inline bool gid_valid(kgid_t gid) -{ - return gid != (typeof(gid))INVALID_GID; -} -#endif /* _LINUX_UIDGID_H */ - -#endif - -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, + loff_t *pos); /* * For RHEL6 struct kernel_parm_ops doesn't exist. Also @@ -127,33 +78,88 @@ int cfs_get_environ(const char *key, char *value, int *val_len); #ifndef HAVE_KERNEL_PARAM_LOCK static inline void kernel_param_unlock(struct module *mod) { -#ifndef HAVE_MODULE_PARAM_LOCKING - mutex_unlock(¶m_lock); -#else __kernel_param_unlock(); -#endif } static inline void kernel_param_lock(struct module *mod) { -#ifndef HAVE_MODULE_PARAM_LOCKING - mutex_lock(¶m_lock); -#else __kernel_param_lock(); -#endif } #endif /* ! HAVE_KERNEL_PARAM_LOCK */ -#ifndef HAVE_KSTRTOUL -static inline int kstrtoul(const char *s, unsigned int base, unsigned long *res) -{ - char *end = (char *)s; +int cfs_apply_workqueue_attrs(struct workqueue_struct *wq, + const struct workqueue_attrs *attrs); - *res = simple_strtoul(s, &end, base); - if (end - s == 0) - return -EINVAL; - return 0; +#ifndef HAVE_KSTRTOBOOL_FROM_USER + +#define kstrtobool strtobool + +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_KSTRTOUL */ +#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 +/** + * container_of_safe - cast a member of a structure out to the containing structure + * @ptr: the pointer to the member. + * @type: the type of the container struct this is embedded in. + * @member: the name of the member within the struct. + * + * If IS_ERR_OR_NULL(ptr), ptr is returned unchanged. + * + * Note: Copied from Linux 5.6, with BUILD_BUG_ON_MSG section removed. + */ +#define container_of_safe(ptr, type, member) ({ \ + void *__mptr = (void *)(ptr); \ + IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) : \ + ((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 + +#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__ */