-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
+/*
+ * GPL HEADER START
*
- * Copyright (C) 2004 Cluster File Systems, Inc.
- * Author: Nikita Danilov <nikita@clusterfs.com>
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
*
- * This file is part of Lustre, http://www.lustre.org.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
*
- * Lustre is free software; you can redistribute it and/or modify it under the
- * terms of version 2 of the GNU General Public License as published by the
- * Free Software Foundation.
+ * 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
*
- * Lustre is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
+ * 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.
*
- * You should have received a copy of the GNU General Public License along
- * with Lustre; if not, write to the Free Software Foundation, Inc., 675 Mass
- * Ave, Cambridge, MA 02139, USA.
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
*
- * Implementation of portable time API for user-level.
+ * libcfs/include/libcfs/user-prim.h
*
+ * Author: Nikita Danilov <nikita@clusterfs.com>
*/
#ifndef __LIBCFS_USER_PRIM_H__
#ifndef __KERNEL__
-#include <stdlib.h>
-#include <string.h>
-#include <sys/signal.h>
-#include <sys/mman.h>
-#include <libcfs/list.h>
-#include <libcfs/user-time.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
+typedef struct proc_dir_entry cfs_proc_dir_entry_t;
-#ifdef HAVE_LIBPTHREAD
-#include <pthread.h>
+/*
+ * Just present a single processor until will add thread support.
+ */
+#ifndef smp_processor_id
+# define cfs_smp_processor_id() 0
+#else
+# define cfs_smp_processor_id() smp_processor_id()
+#endif
+#ifndef num_online_cpus
+# define cfs_num_online_cpus() 1
+#else
+# define cfs_num_online_cpus() num_online_cpus()
+#endif
+#ifndef num_possible_cpus
+# define cfs_num_possible_cpus() 1
+#else
+# define cfs_num_possible_cpus() num_possible_cpus()
+#endif
+#ifndef num_present_cpus
+# define cfs_num_present_cpus() 1
+#else
+# define cfs_num_present_cpus() num_present_cpus()
#endif
-
-
/*
- * Wait Queue. No-op implementation.
+ * Wait Queue.
*/
typedef struct cfs_waitlink {
- struct list_head sleeping;
+ cfs_list_t sleeping;
void *process;
} cfs_waitlink_t;
typedef struct cfs_waitq {
- struct list_head sleepers;
+ cfs_list_t sleepers;
} cfs_waitq_t;
-void cfs_waitq_init(struct cfs_waitq *waitq);
-void cfs_waitlink_init(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,
- struct cfs_waitlink *link);
-void cfs_waitq_forward(struct cfs_waitlink *link, struct cfs_waitq *waitq);
-void cfs_waitq_del(struct cfs_waitq *waitq, struct cfs_waitlink *link);
-int cfs_waitq_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 cfs_waitq_wait(struct cfs_waitlink *link, int state);
-int64_t cfs_waitq_timedwait(struct cfs_waitlink *link, int state, int64_t timeout);
-#define cfs_schedule_timeout(s, t) \
- do { \
- cfs_waitlink_t l; \
- cfs_waitq_timedwait(&l, s, t); \
- } while (0)
-
-#define CFS_TASK_INTERRUPTIBLE (0)
-#define CFS_TASK_UNINT (0)
-
-/* 2.4 defines */
-
-/* XXX
- * for this moment, liblusre will not rely OST for non-page-aligned write
- */
-#define LIBLUSTRE_HANDLE_UNALIGNED_PAGE
-
-struct page {
- void *addr;
- unsigned long index;
- struct list_head list;
- unsigned long private;
-
- /* internally used by liblustre file i/o */
- int _offset;
- int _count;
-#ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
- int _managed;
-#endif
- struct list_head _node;
-};
-
-typedef struct page cfs_page_t;
-
-#ifndef PAGE_SIZE
-
-/* 4K */
-#define CFS_PAGE_SHIFT 12
-#define CFS_PAGE_SIZE (1UL << CFS_PAGE_SHIFT)
-#define CFS_PAGE_MASK (~((__u64)CFS_PAGE_SIZE-1))
-
-#else
-
-#define CFS_PAGE_SIZE PAGE_SIZE
-#define CFS_PAGE_SHIFT PAGE_SHIFT
-#define CFS_PAGE_MASK (~((__u64)CFS_PAGE_SIZE-1))
-
-#endif
-
-cfs_page_t *cfs_alloc_page(unsigned int flags);
-void cfs_free_page(cfs_page_t *pg);
-void *cfs_page_address(cfs_page_t *pg);
-void *cfs_kmap(cfs_page_t *pg);
-void cfs_kunmap(cfs_page_t *pg);
-
-#define cfs_get_page(p) __I_should_not_be_called__(at_all)
-#define cfs_page_count(p) __I_should_not_be_called__(at_all)
-#define cfs_page_index(p) ((p)->index)
-
/*
- * Memory allocator
- * Inline function, so utils can use them without linking of libcfs
+ * Task states
*/
-#define __ALLOC_ZERO (1 << 2)
-static inline void *cfs_alloc(size_t nr_bytes, u_int32_t flags)
-{
- void *result;
+typedef long cfs_task_state_t;
- result = malloc(nr_bytes);
- if (result != NULL && (flags & __ALLOC_ZERO))
- memset(result, 0, nr_bytes);
- return result;
-}
+#define CFS_TASK_INTERRUPTIBLE (0)
+#define CFS_TASK_UNINT (1)
+#define CFS_TASK_RUNNING (2)
-#define cfs_free(addr) free(addr)
-#define cfs_alloc_large(nr_bytes) cfs_alloc(nr_bytes, 0)
-#define cfs_free_large(addr) cfs_free(addr)
+static inline void cfs_schedule(void) {}
+static inline void cfs_schedule_timeout(int64_t t) {}
-#define CFS_ALLOC_ATOMIC_TRY (0)
/*
- * SLAB allocator
+ * Lproc
*/
-typedef struct {
- int size;
-} cfs_mem_cache_t;
-
-#define SLAB_HWCACHE_ALIGN 0
-#define SLAB_KERNEL 0
-#define SLAB_NOFS 0
-
-cfs_mem_cache_t *
-cfs_mem_cache_create(const char *, size_t, size_t, unsigned long);
-int cfs_mem_cache_destroy(cfs_mem_cache_t *c);
-void *cfs_mem_cache_alloc(cfs_mem_cache_t *c, int gfp);
-void cfs_mem_cache_free(cfs_mem_cache_t *c, void *addr);
-
typedef int (cfs_read_proc_t)(char *page, char **start, off_t off,
int count, int *eof, void *data);
/*
* Timer
*/
-#include <sys/time.h>
typedef struct {
- struct list_head tl_list;
- void (*function)(unsigned long unused);
- unsigned long data;
+ cfs_list_t tl_list;
+ void (*function)(ulong_ptr_t unused);
+ ulong_ptr_t data;
long expires;
} cfs_timer_t;
-#define cfs_init_timer(t) do {} while(0)
-#define cfs_jiffies \
-({ \
- unsigned long _ret = 0; \
- struct timeval tv; \
- if (gettimeofday(&tv, NULL) == 0) \
- _ret = tv.tv_sec; \
- _ret; \
-})
-
-static inline int cfs_timer_init(cfs_timer_t *l, void (* func)(unsigned long), void *arg)
-{
- CFS_INIT_LIST_HEAD(&l->tl_list);
- l->function = func;
- l->data = (unsigned long)arg;
- return 0;
-}
-
-static inline int cfs_timer_is_armed(cfs_timer_t *l)
-{
- if (cfs_time_before(cfs_jiffies, l->expires))
- return 1;
- else
- return 0;
-}
-
-static inline void cfs_timer_arm(cfs_timer_t *l, int thetime)
-{
- l->expires = thetime;
-}
-
-static inline void cfs_timer_disarm(cfs_timer_t *l)
-{
-}
-
-static inline long cfs_timer_deadline(cfs_timer_t *l)
-{
- return l->expires;
-}
-
-#if 0
-#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);
-cfs_time_t cfs_timer_deadline(struct cfs_timer *t);
-#endif
-
-#define in_interrupt() (0)
-
-static inline void cfs_pause(cfs_duration_t d)
-{
- struct timespec s;
-
- cfs_duration_nsec(d, &s);
- nanosleep(&s, NULL);
-}
+#define cfs_in_interrupt() (0)
typedef void cfs_psdev_t;
return 0;
}
-#define cfs_lock_kernel() do {} while (0)
-#define cfs_sigfillset(l) do {} while (0)
+#define cfs_sigfillset(l) do {} while (0)
#define cfs_recalc_sigpending(l) do {} while (0)
-#define cfs_kernel_thread(l,m,n) LBUG()
+/* Fine, crash, but stop giving me compile warnings */
+#define cfs_kthread_run(fn,d,fmt,...) LBUG()
+
+#define CFS_DAEMON_FLAGS 0
+
+#define CFS_L1_CACHE_ALIGN(x) (x)
#ifdef HAVE_LIBPTHREAD
typedef int (*cfs_thread_t)(void *);
-int cfs_create_thread(cfs_thread_t func, void *arg);
+int cfs_create_thread(cfs_thread_t func, void *arg, unsigned long flags);
#else
#define cfs_create_thread(l,m) LBUG()
#endif
-int cfs_parse_int_tunable(int *value, char *name);
uid_t cfs_curproc_uid(void);
+gid_t cfs_curproc_gid(void);
+uid_t cfs_curproc_fsuid(void);
+gid_t cfs_curproc_fsgid(void);
+
+#ifndef HAVE_STRLCPY /* not in glibc for RHEL 5.x, remove when obsolete */
+size_t strlcpy(char *tgt, const char *src, size_t tgt_len);
+#endif
+
+#ifndef HAVE_STRLCAT /* not in glibc for RHEL 5.x, remove when obsolete */
+size_t strlcat(char *tgt, const char *src, size_t tgt_len);
+#endif
#define LIBCFS_REALLOC(ptr, size) realloc(ptr, size)
/*
* arithmetic
*/
+#ifndef do_div /* gcc only, platform-specific will override */
#define do_div(a,b) \
({ \
unsigned long remainder;\
(a) = (a) / (b); \
(remainder); \
})
+#endif
+
+/*
+ * Groups
+ */
+typedef struct cfs_group_info {
+
+} cfs_group_info_t;
+
+#ifndef min
+# define min(x,y) ((x)<(y) ? (x) : (y))
+#endif
+
+#ifndef max
+# define max(x,y) ((x)>(y) ? (x) : (y))
+#endif
+
+#define cfs_get_random_bytes_prim(val, size) (*val) = 0
+
+/* utility libcfs init/fini entries */
+#ifdef __WINNT__
+extern int libcfs_arch_init(void);
+extern void libcfs_arch_cleanup(void);
+#else /* !__WINNT__ */
+static inline int libcfs_arch_init(void) {
+ return 0;
+}
+static inline void libcfs_arch_cleanup(void) {
+}
+/* __WINNT__ */
+#endif
+
+/* proc interface wrappers for non-win OS */
+#ifndef __WINNT__
+#define cfs_proc_open open
+#define cfs_proc_mknod mknod
+#define cfs_proc_ioctl ioctl
+#define cfs_proc_close close
+#define cfs_proc_read read
+#define cfs_proc_write write
+#define cfs_proc_fopen fopen
+#define cfs_proc_fclose fclose
+#define cfs_proc_fgets fgets
+/* !__WINNT__ */
+#endif
/* !__KERNEL__ */
#endif