Whamcloud - gitweb
LU-1346 libcfs: cleanup libcfs primitive (linux-prim.h)
[fs/lustre-release.git] / libcfs / include / libcfs / darwin / darwin-prim.h
index 7bc7af3..8385acc 100644 (file)
 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
 #endif
 
+#ifndef EXPORT_SYMBOL
+# define EXPORT_SYMBOL(s)
+#endif
+
 #ifdef __KERNEL__
 #include <sys/types.h>
 #include <sys/systm.h>
@@ -103,10 +107,9 @@ extern kern_return_t            cfs_symbol_put(const char *);
  */
 #define        CONFIG_SYSCTL   1
 
-typedef struct sysctl_oid *     cfs_sysctl_table_t;
-typedef cfs_sysctl_table_t      cfs_sysctl_table_header_t;
-cfs_sysctl_table_header_t      *cfs_register_sysctl_table (cfs_sysctl_table_t *table, int arg);
-void cfs_unregister_sysctl_table (cfs_sysctl_table_header_t *table);
+#define ctl_table sysctl_oid
+struct ctl_table *register_sysctl_table(struct ctl_table *table);
+void unregister_sysctl_table(struct ctl_table *table);
 
 /*
  * Proc file system APIs, no /proc fs support in OSX
@@ -128,20 +131,20 @@ typedef int (cfs_write_proc_t)(struct file *file, const char *buffer,
 /*
  * cfs pseudo device
  *
- * cfs_psdev_t
- * cfs_psdev_register:
- * cfs_psdev_deregister:
+ * struct miscdevice
+ * misc_register:
+ * misc_deregister:
  */
-typedef struct {
+struct miscdevice{
        int             index;
        void            *handle;
        const char      *name;
        struct cdevsw   *devsw;
        void            *private;
-} cfs_psdev_t;
+};
 
-extern kern_return_t            cfs_psdev_register(cfs_psdev_t *);
-extern kern_return_t            cfs_psdev_deregister(cfs_psdev_t *);
+extern kern_return_t            misc_register(struct miscdevice *);
+extern kern_return_t            misc_deregister(struct miscdevice *);
 
 /*
  * Task struct and ...
@@ -153,27 +156,26 @@ extern void             *get_bsdtask_info(task_t);
 
 #ifdef __DARWIN8__
 
-typedef struct {}              cfs_task_t;
-#define cfs_current()          ((cfs_task_t *)current_thread())
+typedef struct task_struct {};
+#define current                ((struct task_struct *)current_thread())
 #else  /* !__DARWIN8__ */
 
-typedef struct uthread         cfs_task_t;
+#define task_struct uthread
 
 #define current_uthread()       ((struct uthread *)get_bsdthread_info(current_act()))
-#define cfs_current()          current_uthread()
+#define current                current_uthread()
 
 #endif /* !__DARWIN8__ */
 
-#define cfs_task_lock(t)       do {;} while (0)
-#define cfs_task_unlock(t)     do {;} while (0)
+#define task_lock(t)   do {;} while (0)
+#define task_unlock(t) do {;} while (0)
 
 #define set_current_state(s)   do {;} while (0)
 
-#define CFS_DECL_JOURNAL_DATA  
-#define CFS_PUSH_JOURNAL       do {;} while(0)
-#define CFS_POP_JOURNAL                do {;} while(0)
+#define DECL_JOURNAL_DATA
+#define PUSH_JOURNAL   do {;} while(0)
+#define POP_JOURNAL            do {;} while(0)
 
-#define THREAD_NAME(comm, fmt, a...)
 /*
  * Kernel thread:
  *
@@ -202,10 +204,8 @@ extern task_t      kernel_task;
 
 #define CLONE_SIGNAL    (CLONE_SIGHAND | CLONE_THREAD)
 
-#define CFS_DAEMON_FLAGS (CLONE_VM | CLONE_FILES)
-
-extern int cfs_create_thread(cfs_thread_t func, void *arg, unsigned long flag);
-
+extern struct task_struct kthread_run(cfs_thread_t func, void *arg,
+                             const char namefmt[], ...);
 
 /*
  * Wait Queue implementation
@@ -214,34 +214,32 @@ extern int cfs_create_thread(cfs_thread_t func, void *arg, unsigned long flag);
  */
 typedef struct cfs_waitq {
        struct ksleep_chan wq_ksleep_chan;
-} cfs_waitq_t;
+} wait_queue_head_t;
 
 typedef struct cfs_waitlink {
        struct cfs_waitq   *wl_waitq;
        struct ksleep_link  wl_ksleep_link;
-} cfs_waitlink_t;
-
-typedef int cfs_task_state_t;
+} wait_queue_t;
 
-#define CFS_TASK_INTERRUPTIBLE THREAD_ABORTSAFE
-#define CFS_TASK_UNINT         THREAD_UNINT
+#define TASK_INTERRUPTIBLE     THREAD_ABORTSAFE
+#define TASK_UNINTERRUPTIBLE           THREAD_UNINT
 
-void cfs_waitq_init(struct cfs_waitq *waitq);
-void cfs_waitlink_init(struct cfs_waitlink *link);
+void init_waitqueue_head(struct cfs_waitq *waitq);
+void init_waitqueue_entry_current(struct cfs_waitlink *link);
 
-void cfs_waitq_add(struct cfs_waitq *waitq, struct cfs_waitlink *link);
-void cfs_waitq_add_exclusive(struct cfs_waitq *waitq,
+void add_wait_queue(struct cfs_waitq *waitq, struct cfs_waitlink *link);
+void add_wait_queue_exclusive(struct cfs_waitq *waitq,
                             struct cfs_waitlink *link);
-void cfs_waitq_del(struct cfs_waitq *waitq, struct cfs_waitlink *link);
-int  cfs_waitq_active(struct cfs_waitq *waitq);
+void remove_wait_queue(struct cfs_waitq *waitq, struct cfs_waitlink *link);
+int  waitqueue_active(struct cfs_waitq *waitq);
 
-void cfs_waitq_signal(struct cfs_waitq *waitq);
-void cfs_waitq_signal_nr(struct cfs_waitq *waitq, int nr);
-void cfs_waitq_broadcast(struct cfs_waitq *waitq);
+void wake_up(struct cfs_waitq *waitq);
+void wake_up_nr(struct cfs_waitq *waitq, int nr);
+void wake_up_all(struct cfs_waitq *waitq);
 
-void cfs_waitq_wait(struct cfs_waitlink *link, cfs_task_state_t state);
-cfs_duration_t cfs_waitq_timedwait(struct cfs_waitlink *link,
-                                  cfs_task_state_t state, 
+void waitq_wait(struct cfs_waitlink *link, long state);
+cfs_duration_t waitq_timedwait(struct cfs_waitlink *link,
+                                  long state,
                                   cfs_duration_t timeout);
 
 /*
@@ -251,7 +249,7 @@ cfs_duration_t cfs_waitq_timedwait(struct cfs_waitlink *link,
 extern void thread_set_timer_deadline(__u64 deadline);
 extern void thread_cancel_timer(void);
 
-static inline int cfs_schedule_timeout(int state, int64_t timeout)
+static inline int schedule_timeout(int state, int64_t timeout)
 {
        int          result;
        
@@ -277,22 +275,22 @@ static inline int cfs_schedule_timeout(int state, int64_t timeout)
        return result;
 }
 
-#define cfs_schedule() cfs_schedule_timeout(CFS_TASK_UNINT, CFS_TICK)
-#define cfs_pause(tick)        cfs_schedule_timeout(CFS_TASK_UNINT, tick)
+#define schedule()     schedule_timeout(TASK_UNINTERRUPTIBLE, CFS_TICK)
+#define cfs_pause(tick)        schedule_timeout(TASK_UNINTERRUPTIBLE, tick)
 
 #define __wait_event(wq, condition)                            \
 do {                                                           \
        struct cfs_waitlink __wait;                             \
                                                                \
-       cfs_waitlink_init(&__wait);                             \
+       init_waitqueue_entry_current(&__wait);                  \
        for (;;) {                                              \
-               cfs_waitq_add(&wq, &__wait);                    \
+               add_wait_queue(&wq, &__wait);                   \
                if (condition)                                  \
                        break;                                  \
-               cfs_waitq_wait(&__wait, CFS_TASK_UNINT);        \
-               cfs_waitq_del(&wq, &__wait);                    \
+               waitq_wait(&__wait, TASK_UNINTERRUPTIBLE);      \
+               remove_wait_queue(&wq, &__wait);                \
        }                                                       \
-       cfs_waitq_del(&wq, &__wait);                            \
+       remove_wait_queue(&wq, &__wait);                        \
 } while (0)
 
 #define wait_event(wq, condition)                              \
@@ -306,24 +304,24 @@ do {                                                              \
 do {                                                           \
        struct cfs_waitlink __wait;                             \
                                                                \
-       cfs_waitlink_init(&__wait);                             \
+       init_waitqueue_entry_current(&__wait);                  \
        for (;;) {                                              \
                if (ex == 0)                                    \
-                       cfs_waitq_add(&wq, &__wait);            \
+                       add_wait_queue(&wq, &__wait);           \
                else                                            \
-                       cfs_waitq_add_exclusive(&wq, &__wait);  \
+                       add_wait_queue_exclusive(&wq, &__wait); \
                if (condition)                                  \
                        break;                                  \
                if (!cfs_signal_pending()) {                    \
-                       cfs_waitq_wait(&__wait,                 \
-                                      CFS_TASK_INTERRUPTIBLE); \
-                       cfs_waitq_del(&wq, &__wait);            \
+                       waitq_wait(&__wait,                     \
+                                      TASK_INTERRUPTIBLE);     \
+                       remove_wait_queue(&wq, &__wait);        \
                        continue;                               \
                }                                               \
                ret = -ERESTARTSYS;                             \
                break;                                          \
        }                                                       \
-       cfs_waitq_del(&wq, &__wait);                            \
+       remove_wait_queue(&wq, &__wait);                        \
 } while (0)
 
 #define wait_event_interruptible(wq, condition)                        \
@@ -354,37 +352,35 @@ extern void       wakeup_one __P((void * chan));
        } while (0)
        
 /* used in couple of places */
-static inline void sleep_on(cfs_waitq_t *waitq)
+static inline void sleep_on(wait_queue_head_t *waitq)
 {
-       cfs_waitlink_t link;
+       wait_queue_t link;
        
-       cfs_waitlink_init(&link);
-       cfs_waitq_add(waitq, &link);
-       cfs_waitq_wait(&link, CFS_TASK_UNINT);
-       cfs_waitq_del(waitq, &link);
+       init_waitqueue_entry_current(&link);
+       add_wait_queue(waitq, &link);
+       waitq_wait(&link, TASK_UNINTERRUPTIBLE);
+       remove_wait_queue(waitq, &link);
 }
 
 /*
  * Signal
  */
-typedef sigset_t       cfs_sigset_t;
 
-#define SIGNAL_MASK_ASSERT()
 /*
  * Timer
  */
-typedef struct cfs_timer {
+struct timer_list {
        struct ktimer t;
-} cfs_timer_t;
+};
 
 #define cfs_init_timer(t)      do {} while(0)
-void cfs_timer_init(struct cfs_timer *t, void (*func)(unsigned long), void *arg);
-void cfs_timer_done(struct cfs_timer *t);
-void cfs_timer_arm(struct cfs_timer *t, cfs_time_t deadline);
-void cfs_timer_disarm(struct cfs_timer *t);
-int  cfs_timer_is_armed(struct cfs_timer *t);
+void cfs_timer_init(struct timer_list *t, void (*func)(unsigned long), void *arg);
+void cfs_timer_done(struct timer_list *t);
+void cfs_timer_arm(struct timer_list *t, cfs_time_t deadline);
+void cfs_timer_disarm(struct timer_list *t);
+int  cfs_timer_is_armed(struct timer_list *t);
 
-cfs_time_t cfs_timer_deadline(struct cfs_timer *t);
+cfs_time_t cfs_timer_deadline(struct timer_list *t);
 
 /*
  * Ioctl
@@ -420,7 +416,6 @@ cfs_time_t cfs_timer_deadline(struct cfs_timer *t);
 /* XXX smp_call_function is not supported in xnu */
 #define smp_call_function(f, a, n, w)          do {} while(0)
 int cfs_online_cpus(void);
-#define smp_num_cpus                           cfs_online_cpus()
 
 /*
  * Misc
@@ -434,10 +429,10 @@ extern int is_suser(void);
 #define unlikely(exp) (exp)
 #endif
 
-#define lock_kernel()                          do {} while(0)
-#define unlock_kernel()                                do {} while(0)
+#define lock_kernel()                                  do {} while(0)
+#define unlock_kernel()                                        do {} while(0)
 
-#define USERMODEHELPER(path, argv, envp)       (0)
+#define call_usermodehelper(path, argv, envp, 1)       (0)
 
 #define cfs_module(name, version, init, fini)                          \
 extern kern_return_t _start(kmod_info_t *ki, void *data);              \
@@ -484,7 +479,6 @@ static inline int request_module(const char *name, ...)
 #define __init
 #endif
 
-#define EXPORT_SYMBOL(s)
 #define MODULE_AUTHOR(s)
 #define MODULE_DESCRIPTION(s)
 #define MODULE_LICENSE(s)