diff options
Diffstat (limited to 'sys/gnu/fs/xfs/FreeBSD/support')
22 files changed, 1494 insertions, 0 deletions
diff --git a/sys/gnu/fs/xfs/FreeBSD/support/atomic.h b/sys/gnu/fs/xfs/FreeBSD/support/atomic.h new file mode 100644 index 0000000..f8b6c91 --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/atomic.h @@ -0,0 +1,37 @@ +#ifndef __XFS_SUPPORT_ATOMIC_H__ + +#include <sys/types.h> +#include <machine/atomic.h> + +typedef struct { + volatile unsigned int val; +} atomic_t; + +#define atomic_read(v) ((v)->val) +#define atomic_set(v, i) ((v)->val = (i)) + +#define atomic_add(i, v) atomic_add_int(&(v)->val, (i)) +#define atomic_inc(v) atomic_add_int(&(v)->val, 1) +#define atomic_dec(v) atomic_subtract_int(&(v)->val, 1) +#define atomic_sub(i, v) atomic_subtract_int(&(v)->val, (i)) +#define atomic_sub_and_test(i, v) (atomic_fetchadd_int(&(v)->val, (-i) == i) +#define atomic_dec_and_test(v) (atomic_fetchadd_int(&(v)->val, -1) == 1) + +/* + * This is used for two variables in XFS, one of which is a debug trace + * buffer index. + */ + +static __inline__ int atomicIncWithWrap(volatile unsigned int *ip, int val) +{ + unsigned int oldval, newval; + + do { + oldval = *ip; + newval = (oldval + 1 >= val) ? 0 : oldval + 1; + } while (atomic_cmpset_rel_int(ip, oldval, newval) == 0); + + return oldval; +} + +#endif /* __XFS_SUPPORT_ATOMIC_H__ */ diff --git a/sys/gnu/fs/xfs/FreeBSD/support/debug.c b/sys/gnu/fs/xfs/FreeBSD/support/debug.c new file mode 100644 index 0000000..72345f0 --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/debug.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * + * This program 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. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ + + +#include <sys/param.h> +#include <sys/proc.h> +#include <sys/kernel.h> +#include <sys/systm.h> +#include <sys/sysctl.h> +#include <machine/stdarg.h> + +#include <support/debug.h> + +SYSCTL_NODE(_debug, OID_AUTO, xfs, CTLFLAG_RD, 0, "XFS debug options"); + +static int verbosity = 10; +SYSCTL_INT(_debug_xfs, OID_AUTO, verbosity, CTLFLAG_RW, &verbosity, 0, ""); + +#ifdef DEBUG + +static int doass = 1; +SYSCTL_INT(_debug_xfs, OID_AUTO, assert, CTLFLAG_RW, &doass, 0, ""); + +void +assfail(char *a, char *f, int l) +{ + if (doass == 0) return; + panic("XFS assertion failed: %s, file: %s, line: %d\n", a, f, l); +} + +int +get_thread_id(void) +{ + return curthread->td_proc->p_pid; +} + +#endif + +void +cmn_err(register int level, char *fmt, ...) +{ + char *fp = fmt; + char message[256]; + va_list ap; + + if (verbosity < level) + return; + + va_start(ap, fmt); + if (*fmt == '!') fp++; + vsprintf(message, fp, ap); + printf("%s\n", message); + va_end(ap); +} + + +void +icmn_err(register int level, char *fmt, va_list ap) +{ + char message[256]; + + if (verbosity < level) + return; + + vsprintf(message, fmt, ap); + printf("cmn_err level %d %s\n",level, message); +} + diff --git a/sys/gnu/fs/xfs/FreeBSD/support/debug.h b/sys/gnu/fs/xfs/FreeBSD/support/debug.h new file mode 100644 index 0000000..6c82c84 --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/debug.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * + * This program 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. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ +#ifndef __XFS_SUPPORT_DEBUG_H__ +#define __XFS_SUPPORT_DEBUG_H__ + +#include <machine/stdarg.h> + +#define CE_DEBUG 7 /* debug */ +#define CE_CONT 6 /* continuation */ +#define CE_NOTE 5 /* notice */ +#define CE_WARN 4 /* warning */ +#define CE_ALERT 1 /* alert */ +#define CE_PANIC 0 /* panic */ + +extern void icmn_err(int, char *, va_list); +extern void cmn_err(int, char *, ...); + +#ifndef STATIC +# define STATIC static +#endif + +#if defined(INVARIANTS) +# ifndef DEBUG +# define DEBUG +# endif +#endif + +#if defined(DEBUG) +# ifdef lint +# define ASSERT(EX) ((void)0) /* avoid "constant in conditional" babble */ +# else +# define ASSERT(EX) ((EX)?((void)0):assfail(#EX, __FILE__, __LINE__)) +# endif /* lint */ +#else /* !DEBUG */ +# define ASSERT(x) ((void)0) +#endif /* !DEBUG */ + +#ifdef DEBUG +extern void assfail(char *, char *, int); +extern int get_thread_id(void); +#else +#define assfail(a, b, c) ((void)0) +#endif + +#define ASSERT_ALWAYS(EX) ((EX)?((void)0):assfail(#EX, __FILE__, __LINE__)) +#define debug_stop_all_cpus(param) /* param is "cpumask_t *" */ + +#endif /* __XFS_SUPPORT_DEBUG_H__ */ diff --git a/sys/gnu/fs/xfs/FreeBSD/support/kdb.c b/sys/gnu/fs/xfs/FreeBSD/support/kdb.c new file mode 100644 index 0000000..2d3aac6 --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/kdb.c @@ -0,0 +1,63 @@ +#include <sys/param.h> +#include <sys/kernel.h> +#include <sys/systm.h> + +#include <machine/db_machdep.h> + +#include "opt_ddb.h" +#ifdef DDB +#include <ddb/ddb.h> +#else +#error "Must have options for KDB, DDB in kernel config" +#endif + +#include <support/kdb.h> + +DB_SET(xfs, xfs_ddb_cmd, db_cmd_set, CS_MORE, NULL) +{ + db_error("No commands registered.\n"); +} + + +int +kdb_register(char *cmd, kdb_func_t func, char *usage, char *help, short minlen) +{ + return 0; +} + +int +kdb_unregister(char *cmd) +{ + return 0; +} + +int +kdbgetaddrarg(int argc, const char **argv, int *nextarg, + kdb_machreg_t *value, long *offset, char **name, struct pt_regs *regs) +{ + return 0; +} + +int +kdbnearsym(unsigned long addr, kdb_symtab_t *symtab) + +{ + return 0; +} + +void +kdb_printf(const char *fmt, ...) +{ +} + +int +kdb_getarea_size(void *res, unsigned long addr, size_t size) +{ + return 0; +} + +int +db_putarea_size(unsigned long addr, void *res, size_t size) +{ + return 0; +} diff --git a/sys/gnu/fs/xfs/FreeBSD/support/kdb.h b/sys/gnu/fs/xfs/FreeBSD/support/kdb.h new file mode 100644 index 0000000..d85bd6d --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/kdb.h @@ -0,0 +1,44 @@ +#ifndef __XFS_SUPPORT_KGDB_H__ +#define __XFS_SUPPORT_KGDB_H__ + +#define KDB_ARGCOUNT EINVAL + +struct pt_regs +{ + int dummy; +}; + +#define MODULE_AUTHOR(s) static char __module_author[] = s; +#define MODULE_DESCRIPTION(s) static char __module_description[] = s; +#define MODULE_LICENSE(s) static char __module_license[] = s + + +typedef int (*kdb_func_t)(int, const char **, const char **, struct pt_regs *); +typedef register_t kdb_machreg_t; + +/* + * Symbol table format. + */ +typedef struct __ksymtab { + unsigned long value; /* Address of symbol */ + const char *sym_name; /* Full symbol name, including any version */ + unsigned long sym_start; + unsigned long sym_end; +} kdb_symtab_t; + +extern int kdb_register(char *, kdb_func_t, char *, char *, short); +extern int kdb_unregister(char *); + +extern int kdbgetaddrarg(int, const char**, int*, kdb_machreg_t *, + long *, char **, struct pt_regs *); +extern int kdbnearsym(unsigned long, kdb_symtab_t *); +extern void kdb_printf(const char *,...) + __attribute__ ((format (printf, 1, 2))); + +extern int kdb_getarea_size(void *, unsigned long, size_t); +extern int kdb_putarea_size(unsigned long, void *, size_t); + +#define kdb_getarea(x,addr) kdb_getarea_size(&(x), addr, sizeof((x))) +#define kdb_putarea(addr,x) kdb_putarea_size(addr, &(x), sizeof((x))) + +#endif /* __XFS_SUPPORT_KGDB_H__ */ diff --git a/sys/gnu/fs/xfs/FreeBSD/support/kmem.c b/sys/gnu/fs/xfs/FreeBSD/support/kmem.c new file mode 100644 index 0000000..c98e4bc --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/kmem.c @@ -0,0 +1,3 @@ +#include <support/kmem.h> + +MALLOC_DEFINE(M_XFS, "XFSALLOC", "XFS memory"); diff --git a/sys/gnu/fs/xfs/FreeBSD/support/kmem.h b/sys/gnu/fs/xfs/FreeBSD/support/kmem.h new file mode 100644 index 0000000..f457302 --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/kmem.h @@ -0,0 +1,65 @@ +#ifndef __XFS_SUPPORT_KMEM_H__ +#define __XFS_SUPPORT_KMEM_H__ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/malloc.h> +#include <sys/kernel.h> +#include <sys/lock.h> +#include <sys/mutex.h> +#include <vm/uma.h> + +typedef unsigned long xfs_pflags_t; + +#define PFLAGS_TEST_NOIO() 0 +#define PFLAGS_TEST_FSTRANS() 0 + +#define PFLAGS_SET_NOIO(STATEP) do { \ +} while (0) + +#define PFLAGS_SET_FSTRANS(STATEP) do { \ +} while (0) + +#define PFLAGS_RESTORE(STATEP) do { \ +} while (0) + +#define PFLAGS_DUP(OSTATEP, NSTATEP) do { \ +} while (0) + +/* + * memory management routines + */ +#define KM_SLEEP M_WAITOK +#define KM_SLEEP_IO M_WAITOK +#define KM_NOFS M_WAITOK +#define KM_NOSLEEP M_NOWAIT +#define KM_CACHEALIGN 0 + +#define kmem_zone uma_zone + +typedef struct uma_zone kmem_zone_t; +typedef struct uma_zone xfs_zone_t; + +#define kmem_zone_init(len, name) \ + uma_zcreate(name, len, NULL, NULL, NULL, NULL, 0, 0) +#define kmem_zone_free(zone, ptr) \ + uma_zfree(zone, ptr) +#define kmem_cache_destroy(zone) \ + uma_zdestroy(zone) +#define kmem_zone_alloc(zone, flg) \ + uma_zalloc(zone, flg) +#define kmem_zone_zalloc(zone, flg) \ + uma_zalloc(zone, (flg) | M_ZERO) + +#define kmem_alloc(len, flg) \ + malloc(len, M_XFS, flg) +#define kmem_zalloc(len, flg) \ + malloc(len, M_XFS, (flg) | M_ZERO) +#define kmem_free(ptr, size) \ + free(ptr, M_XFS) +#define kmem_realloc(ptr, nsize, osize, flg) \ + realloc(ptr, nsize, M_XFS, flg) + +MALLOC_DECLARE(M_XFS); + +#endif /* __XFS_SUPPORT_KMEM_H__ */ diff --git a/sys/gnu/fs/xfs/FreeBSD/support/ktrace.c b/sys/gnu/fs/xfs/FreeBSD/support/ktrace.c new file mode 100644 index 0000000..462a665 --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/ktrace.c @@ -0,0 +1,348 @@ +/* + * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved. + * + * This program 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. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ + +#include <xfs.h> + +static kmem_zone_t *ktrace_hdr_zone; +static kmem_zone_t *ktrace_ent_zone; +static int ktrace_zentries; +static struct mtx wrap_lock; + +void +ktrace_init(int zentries) +{ + ktrace_zentries = zentries; + + ktrace_hdr_zone = kmem_zone_init(sizeof(ktrace_t), + "ktrace_hdr"); + ASSERT(ktrace_hdr_zone); + + ktrace_ent_zone = kmem_zone_init(ktrace_zentries + * sizeof(ktrace_entry_t), + "ktrace_ent"); + ASSERT(ktrace_ent_zone); + + mtx_init(&wrap_lock, "xfsktr", NULL, MTX_DEF); +} + +void +ktrace_uninit(void) +{ + kmem_cache_destroy(ktrace_hdr_zone); + kmem_cache_destroy(ktrace_ent_zone); + mtx_destroy(&wrap_lock); +} + +/* + * ktrace_alloc() + * + * Allocate a ktrace header and enough buffering for the given + * number of entries. + */ +ktrace_t * +ktrace_alloc(int nentries, int sleep) +{ + ktrace_t *ktp; + ktrace_entry_t *ktep; + + ktp = (ktrace_t*)kmem_zone_alloc(ktrace_hdr_zone, sleep); + + if (ktp == (ktrace_t*)NULL) { + /* + * KM_SLEEP callers don't expect failure. + */ + if (sleep & KM_SLEEP) + panic("ktrace_alloc: NULL memory on KM_SLEEP request!"); + + return NULL; + } + + /* + * Special treatment for buffers with the ktrace_zentries entries + */ + if (nentries == ktrace_zentries) { + ktep = (ktrace_entry_t*)kmem_zone_zalloc(ktrace_ent_zone, + sleep); + } else { + ktep = (ktrace_entry_t*)kmem_zalloc((nentries * sizeof(*ktep)), + sleep); + } + + if (ktep == NULL) { + /* + * KM_SLEEP callers don't expect failure. + */ + if (sleep & KM_SLEEP) + panic("ktrace_alloc: NULL memory on KM_SLEEP request!"); + + kmem_free(ktp, sizeof(*ktp)); + + return NULL; + } + + spinlock_init(&(ktp->kt_lock), "kt_lock"); + + ktp->kt_entries = ktep; + ktp->kt_nentries = nentries; + ktp->kt_index = 0; + ktp->kt_rollover = 0; + return ktp; +} + + +/* + * ktrace_free() + * + * Free up the ktrace header and buffer. It is up to the caller + * to ensure that no-one is referencing it. + */ +void +ktrace_free(ktrace_t *ktp) +{ + int entries_size; + + if (ktp == (ktrace_t *)NULL) + return; + + spinlock_destroy(&ktp->kt_lock); + + /* + * Special treatment for the Vnode trace buffer. + */ + if (ktp->kt_nentries == ktrace_zentries) { + kmem_zone_free(ktrace_ent_zone, ktp->kt_entries); + } else { + entries_size = (int)(ktp->kt_nentries * sizeof(ktrace_entry_t)); + + kmem_free(ktp->kt_entries, entries_size); + } + + kmem_zone_free(ktrace_hdr_zone, ktp); +} + + +/* + * Enter the given values into the "next" entry in the trace buffer. + * kt_index is always the index of the next entry to be filled. + */ +void +ktrace_enter( + ktrace_t *ktp, + void *val0, + void *val1, + void *val2, + void *val3, + void *val4, + void *val5, + void *val6, + void *val7, + void *val8, + void *val9, + void *val10, + void *val11, + void *val12, + void *val13, + void *val14, + void *val15) +{ + int index; + ktrace_entry_t *ktep; + + ASSERT(ktp != NULL); + + /* + * Grab an entry by pushing the index up to the next one. + */ + mtx_lock(&wrap_lock); + index = ktp->kt_index; + if (++ktp->kt_index == ktp->kt_nentries) + ktp->kt_index = 0; + mtx_unlock(&wrap_lock); + + if (!ktp->kt_rollover && index == ktp->kt_nentries - 1) + ktp->kt_rollover = 1; + + ASSERT((index >= 0) && (index < ktp->kt_nentries)); + + ktep = &(ktp->kt_entries[index]); + + ktep->val[0] = val0; + ktep->val[1] = val1; + ktep->val[2] = val2; + ktep->val[3] = val3; + ktep->val[4] = val4; + ktep->val[5] = val5; + ktep->val[6] = val6; + ktep->val[7] = val7; + ktep->val[8] = val8; + ktep->val[9] = val9; + ktep->val[10] = val10; + ktep->val[11] = val11; + ktep->val[12] = val12; + ktep->val[13] = val13; + ktep->val[14] = val14; + ktep->val[15] = val15; +} + +/* + * Return the number of entries in the trace buffer. + */ +int +ktrace_nentries( + ktrace_t *ktp) +{ + if (ktp == NULL) { + return 0; + } + + return (ktp->kt_rollover ? ktp->kt_nentries : ktp->kt_index); +} + +/* + * ktrace_first() + * + * This is used to find the start of the trace buffer. + * In conjunction with ktrace_next() it can be used to + * iterate through the entire trace buffer. This code does + * not do any locking because it is assumed that it is called + * from the debugger. + * + * The caller must pass in a pointer to a ktrace_snap + * structure in which we will keep some state used to + * iterate through the buffer. This state must not touched + * by any code outside of this module. + */ +ktrace_entry_t * +ktrace_first(ktrace_t *ktp, ktrace_snap_t *ktsp) +{ + ktrace_entry_t *ktep; + int index; + int nentries; + + if (ktp->kt_rollover) + index = ktp->kt_index; + else + index = 0; + + ktsp->ks_start = index; + ktep = &(ktp->kt_entries[index]); + + nentries = ktrace_nentries(ktp); + index++; + if (index < nentries) { + ktsp->ks_index = index; + } else { + ktsp->ks_index = 0; + if (index > nentries) + ktep = NULL; + } + return ktep; +} + +/* + * ktrace_next() + * + * This is used to iterate through the entries of the given + * trace buffer. The caller must pass in the ktrace_snap_t + * structure initialized by ktrace_first(). The return value + * will be either a pointer to the next ktrace_entry or NULL + * if all of the entries have been traversed. + */ +ktrace_entry_t * +ktrace_next( + ktrace_t *ktp, + ktrace_snap_t *ktsp) +{ + int index; + ktrace_entry_t *ktep; + + index = ktsp->ks_index; + if (index == ktsp->ks_start) { + ktep = NULL; + } else { + ktep = &ktp->kt_entries[index]; + } + + index++; + if (index == ktrace_nentries(ktp)) { + ktsp->ks_index = 0; + } else { + ktsp->ks_index = index; + } + + return ktep; +} + +/* + * ktrace_skip() + * + * Skip the next "count" entries and return the entry after that. + * Return NULL if this causes us to iterate past the beginning again. + */ +ktrace_entry_t * +ktrace_skip( + ktrace_t *ktp, + int count, + ktrace_snap_t *ktsp) +{ + int index; + int new_index; + ktrace_entry_t *ktep; + int nentries = ktrace_nentries(ktp); + + index = ktsp->ks_index; + new_index = index + count; + while (new_index >= nentries) { + new_index -= nentries; + } + if (index == ktsp->ks_start) { + /* + * We've iterated around to the start, so we're done. + */ + ktep = NULL; + } else if ((new_index < index) && (index < ktsp->ks_index)) { + /* + * We've skipped past the start again, so we're done. + */ + ktep = NULL; + ktsp->ks_index = ktsp->ks_start; + } else { + ktep = &(ktp->kt_entries[new_index]); + new_index++; + if (new_index == nentries) { + ktsp->ks_index = 0; + } else { + ktsp->ks_index = new_index; + } + } + return ktep; +} diff --git a/sys/gnu/fs/xfs/FreeBSD/support/ktrace.h b/sys/gnu/fs/xfs/FreeBSD/support/ktrace.h new file mode 100644 index 0000000..b566ef8 --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/ktrace.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved. + * + * This program 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. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ +#ifndef __XFS_SUPPORT_KTRACE_H__ +#define __XFS_SUPPORT_KTRACE_H__ + +#include <support/spin.h> + +/* + * Trace buffer entry structure. + */ +typedef struct ktrace_entry { + void *val[16]; +} ktrace_entry_t; + +/* + * Trace buffer header structure. + */ +typedef struct ktrace { + lock_t kt_lock; /* mutex to guard counters */ + int kt_nentries; /* number of entries in trace buf */ + int kt_index; /* current index in entries */ + int kt_rollover; + ktrace_entry_t *kt_entries; /* buffer of entries */ +} ktrace_t; + +/* + * Trace buffer snapshot structure. + */ +typedef struct ktrace_snap { + int ks_start; /* kt_index at time of snap */ + int ks_index; /* current index */ +} ktrace_snap_t; + + +#ifdef CONFIG_XFS_TRACE + +extern void ktrace_init(int zentries); +extern void ktrace_uninit(void); + +extern ktrace_t *ktrace_alloc(int, int); +extern void ktrace_free(ktrace_t *); + +extern void ktrace_enter( + ktrace_t *, + void *, + void *, + void *, + void *, + void *, + void *, + void *, + void *, + void *, + void *, + void *, + void *, + void *, + void *, + void *, + void *); + +extern ktrace_entry_t *ktrace_first(ktrace_t *, ktrace_snap_t *); +extern int ktrace_nentries(ktrace_t *); +extern ktrace_entry_t *ktrace_next(ktrace_t *, ktrace_snap_t *); +extern ktrace_entry_t *ktrace_skip(ktrace_t *, int, ktrace_snap_t *); + +#else +#define ktrace_init(x) do { } while (0) +#define ktrace_uninit() do { } while (0) +#endif /* CONFIG_XFS_TRACE */ + +#endif /* __XFS_SUPPORT_KTRACE_H__ */ diff --git a/sys/gnu/fs/xfs/FreeBSD/support/move.h b/sys/gnu/fs/xfs/FreeBSD/support/move.h new file mode 100644 index 0000000..856ec03 --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/move.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved. + * + * This program 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. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ + +#ifndef __XFS_SUPPORT_MOVE_H__ +#define __XFS_SUPPORT_MOVE_H__ + +#include <sys/uio.h> + +typedef struct iovec iovec_t; +typedef struct uio uio_t; + +static __inline__ int +uio_read(void *buf, int howmuch, struct uio *uiop) +{ + uiop->uio_rw = UIO_READ; + return uiomove(buf,howmuch,uiop); +} + +#endif /* __XFS_SUPPORT_MOVE_H__ */ diff --git a/sys/gnu/fs/xfs/FreeBSD/support/mrlock.c b/sys/gnu/fs/xfs/FreeBSD/support/mrlock.c new file mode 100644 index 0000000..9503039 --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/mrlock.c @@ -0,0 +1,49 @@ +#include <sys/param.h> +#include <support/mrlock.h> + +void +_sx_xfs_destroy(struct sx *sx) +{ + if (sx->sx_cnt == -1) + sx_xunlock(sx); + sx_destroy(sx); +} + +void +_sx_xfs_lock(struct sx *sx, int type, const char *file, int line) +{ + if (type == MR_ACCESS) + _sx_slock(sx, file, line); + else if (type == MR_UPDATE) + _sx_sunlock(sx, file, line); + else + panic("Invalid lock type passed"); +} + + +void +_sx_xfs_unlock(struct sx *sx, const char *file, int line) +{ + if (_sx_xfs_xowned(sx)) + _sx_xunlock(sx, file, line); + else if (_sx_xfs_sowned(sx)) + _sx_sunlock(sx, file, line); + else + panic("lock is not locked"); +} + +int +ismrlocked(mrlock_t *mrp, int type) +{ + if (type == MR_ACCESS) + return _sx_xfs_sowned(mrp); /* Read lock */ + else if (type == MR_UPDATE) + return _sx_xfs_xowned(mrp); /* Write lock */ + else if (type == (MR_UPDATE | MR_ACCESS)) + return _sx_xfs_sowned(mrp) || + _sx_xfs_xowned(mrp); /* Any type of lock held */ + return (mrp->sx_shrd_wcnt > 0 || mrp->sx_excl_wcnt > 0); +} + + + diff --git a/sys/gnu/fs/xfs/FreeBSD/support/mrlock.h b/sys/gnu/fs/xfs/FreeBSD/support/mrlock.h new file mode 100644 index 0000000..4e82d41 --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/mrlock.h @@ -0,0 +1,65 @@ +#ifndef __XFS_SUPPORT_MRLOCK_H__ +#define __XFS_SUPPORT_MRLOCK_H__ + +#include <sys/types.h> +#include <sys/systm.h> +#include <sys/lock.h> +#include <sys/mutex.h> +#include <sys/sx.h> + +#include <support/debug.h> + +/* + * Implement mrlocks on FreeBSD that work for XFS. + * Use FreeBSD sx lock and add necessary functions + * if additional functionality is requested + */ +typedef struct sx mrlock_t; + +#define MR_ACCESS 1 +#define MR_UPDATE 2 + +/* + * Compatibility defines, not really used + */ +#define MRLOCK_BARRIER 0x1 +#define MRLOCK_ALLOW_EQUAL_PRI 0x8 + +/* + * mraccessf/mrupdatef take flags to be passed in while sleeping; + * only PLTWAIT is currently supported. + */ +#define mrinit(lock, name) sx_init(lock, name) +#define mrlock_init(lock, type, name, seq) sx_init(lock, name) +#define mrfree(lock) _sx_xfs_destroy(lock) +#define mraccessf(lock, f) sx_slock(lock) +#define mrupdatef(lock, f) sx_xlock(lock) +#define mraccunlock(lock) sx_sunlock(lock) +#define mrtryaccess(lock) sx_try_slock(lock) +#define mrtryupdate(lock) sx_try_xlock(lock) +#define mraccess(mrp) mraccessf(mrp, 0) +#define mrupdate(mrp) mrupdatef(mrp, 0) +#define mrislocked_access(lock) _sx_xfs_xowned(lock) +#define mrislocked_update(lock) _sx_xfs_sowned(lock) +#define mrtrypromote(lock) sx_try_upgrade(lock) +#define mrdemote(lock) sx_downgrade(lock) + +int ismrlocked(mrlock_t *, int); +void _sx_xfs_lock(struct sx *sx, int type, const char *file, int line); +void _sx_xfs_unlock(struct sx *sx, const char *file, int line); +void _sx_xfs_destroy(struct sx *sx); +#define _sx_xfs_xowned(lock) ((lock)->sx_cnt < 0) +#define _sx_xfs_sowned(lock) ((lock)->sx_cnt > 0) + +/* + * Functions, not implemented in FreeBSD + */ +#define mrunlock(lock) \ + _sx_xfs_unlock(lock, __FILE__, __LINE__) + +#define mrlock(lock, type, flags) \ + _sx_xfs_lock(lock, type, __FILE__, __LINE__) + + + +#endif /* __XFS_SUPPORT_MRLOCK_H__ */ diff --git a/sys/gnu/fs/xfs/FreeBSD/support/mutex.h b/sys/gnu/fs/xfs/FreeBSD/support/mutex.h new file mode 100644 index 0000000..d9b89b3 --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/mutex.h @@ -0,0 +1,29 @@ +#ifndef __XFS_SUPPORT_MUTEX_H__ +#define __XFS_SUPPORT_MUTEX_H__ + +#include <sys/param.h> +#include <sys/lock.h> +#include <sys/mutex.h> +#include <sys/sx.h> + +/* + * Map the mutex'es from IRIX to FreeBSD. Irix holds mutexes across + * sleeps, so on FreeBSD we have a choice of sema, sx or lockmgr + * to use as a underlining implemenation. Go with sx always locked + * in exclusive mode for now as it gets all the benefits of witness + * checking. + */ +typedef struct sx mutex_t; + +#define mutex_init(lock, type, name) sx_init(lock, name) +#define mutex_lock(lock, num) sx_xlock(lock) +#define mutex_trylock(lock) sx_try_xlock(lock) +#define mutex_unlock(lock) sx_xunlock(lock) +#define mutex_destroy(lock) sx_destroy(lock) + +/* + * Type for mutex_init() + */ +#define MUTEX_DEFAULT 0 + +#endif /* __XFS_SUPPORT_MUTEX_H__ */ diff --git a/sys/gnu/fs/xfs/FreeBSD/support/rwlock.h b/sys/gnu/fs/xfs/FreeBSD/support/rwlock.h new file mode 100644 index 0000000..05f489e --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/rwlock.h @@ -0,0 +1,22 @@ +#ifndef __XFS_SUPPORT_RWLOCK_H__ +#define __XFS_SUPPORT_RWLOCK_H__ + +#include <sys/param.h> +#include <sys/lock.h> +#include <sys/mutex.h> +#include <sys/sx.h> + +typedef struct sx rwlock_t; +typedef int wait_queue_head_t; + +#define rwlock_init(lock) sx_init(lock, "rwlock") +#define rwlock_destroy(lock) sx_destroy(lock) +#define read_lock(lock) sx_slock(lock) +#define read_unlock(lock) sx_sunlock(lock) +#define write_lock(lock) sx_xlock(lock) +#define write_unlock(lock) sx_xunlock(lock) +#define rwlock_trypromote(lock) sx_try_upgrade(lock) +#define rwlock_demote(lock) sx_downgrade(lock) + + +#endif /* __XFS_SUPPORT_RWLOCK_H__ */ diff --git a/sys/gnu/fs/xfs/FreeBSD/support/rwsem.h b/sys/gnu/fs/xfs/FreeBSD/support/rwsem.h new file mode 100644 index 0000000..bb97232 --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/rwsem.h @@ -0,0 +1,21 @@ +#ifndef __XFS_SUPPORT_RWSEM_H__ +#define __XFS_SUPPORT_RWSEM_H__ + +#include <sys/param.h> +#include <sys/lock.h> +#include <sys/mutex.h> +#include <sys/sx.h> + +#define rw_semaphore sx + +#define init_rwsem(sem) sx_init(sem, "rwsem") +#define free_rwsem(sem) sx_destroy(sem) +#define down_read(sem) sx_slock(sem) +#define down_read_trylock(sem) sx_try_slock(sem) +#define down_write(sem) sx_xlock(sem) +#define down_write_trylock(sem) sx_try_xlock(sem) +#define up_read(sem) sx_sunlock(sem) +#define up_write(sem) sx_xunlock(sem) +#define downgrade_write(sem) sx_downgrade(sem) + +#endif /* __XFS_SUPPORT_RWSEM_H__ */ diff --git a/sys/gnu/fs/xfs/FreeBSD/support/sema.h b/sys/gnu/fs/xfs/FreeBSD/support/sema.h new file mode 100644 index 0000000..db7795b --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/sema.h @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef __XFS_SUPPORT_SEMA_H__ +#define __XFS_SUPPORT_SEMA_H__ + +#include <sys/sema.h> + +/* + * sema_t structure just maps to struct sema in FreeBSD kernel. + */ + +typedef struct sema sema_t; + +#define init_sema(sp, val, c, d) sema_init(sp, val, c) +#define initnsema(sp, val, name) sema_init(sp, val, name) +#define psema(sp, b) sema_wait(sp) +#define vsema(sp) sema_post(sp) +#define valusema(sp) sema_value(sp) +#define freesema(sp) sema_destroy(sp) +#define cpsema(sp) sema_trywait(sp) + +#endif /* __XFS_SUPPORT_SEMA_H__ */ diff --git a/sys/gnu/fs/xfs/FreeBSD/support/spin.h b/sys/gnu/fs/xfs/FreeBSD/support/spin.h new file mode 100644 index 0000000..2b09be4 --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/spin.h @@ -0,0 +1,42 @@ +#ifndef __XFS_SUPPORT_SPIN_H__ +#define __XFS_SUPPORT_SPIN_H__ + +#include <sys/param.h> +#include <sys/types.h> +#include <sys/lock.h> +#include <sys/mutex.h> + +#define SPLDECL(s) register_t s + +/* + * Map the spinlocks from IRIX to FreeBSD + */ +#define spinlock_init(lock, name) mtx_init(lock, name, NULL, MTX_DEF) +#define spinlock_destroy(lock) mtx_destroy(lock) + +/* + * Map lock_t from IRIX to FreeBSD mutexes + */ +typedef struct mtx lock_t; + +#define nested_spinunlock(lock) mtx_unlock(lock) +#define nested_spinlock(lock) mtx_lock(lock) +#define nested_spintrylock(lock) mtx_trylock(lock) + +#define spin_lock(lock) mtx_lock(lock) +#define spin_unlock(lock) mtx_unlock(lock) + +#if LOCK_DEBUG > 0 +#define mutex_spinlock(lock) (spin_lock(lock),0) +#else +static __inline register_t +mutex_spinlock(lock_t *lock) { mtx_lock(lock); return 0; } +#endif + +#define mutex_spinunlock(lock,s) \ + do { \ + spin_unlock(lock); \ + if (&s) {} \ + } while (0) + +#endif /* __XFS_SUPPORT_SPIN_H__ */ diff --git a/sys/gnu/fs/xfs/FreeBSD/support/support.h b/sys/gnu/fs/xfs/FreeBSD/support/support.h new file mode 100644 index 0000000..d7804fa --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/support.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * + * This program 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. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ +#ifndef __XFS_SUPPORT_H__ +#define __XFS_SUPPORT_H__ + +#include <support/types.h> +#include <support/arch.h> +#include <support/kmem.h> +#include <support/mrlock.h> +#include <support/spin.h> +#include <support/sv.h> +#include <support/ktrace.h> +#include <support/mutex.h> +#include <support/sema.h> +#include <support/atomic.h> +#include <support/debug.h> +#include <support/uuid.h> +#include <support/time.h> + +#endif /* __XFS_SUPPORT_H__ */ diff --git a/sys/gnu/fs/xfs/FreeBSD/support/sv.h b/sys/gnu/fs/xfs/FreeBSD/support/sv.h new file mode 100644 index 0000000..fa37129 --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/sv.h @@ -0,0 +1,34 @@ +#ifndef __XFS_SUPPORT_SV_H__ +#define __XFS_SUPPORT_SV_H__ + +#include <sys/condvar.h> + +/* + * Synchronisation variables + * + * parameters "pri", "svf" and "rts" are not (yet?) implemented + * + */ + +typedef struct cv sv_t; + +#define init_sv(sv,type,name,flag) \ + cv_init(sv, name) +#define sv_init(sv,flag,name) \ + cv_init(sv, name) +#define sv_wait(sv, pri, lock, spl) \ + cv_wait_unlock(sv, lock) +#define sv_signal(sv) \ + cv_signal(sv) +#define sv_broadcast(sv) \ + cv_broadcast(sv) +#define sv_destroy(sv) \ + cv_destroy(sv) + +#define SV_FIFO 0x0 /* sv_t is FIFO type */ +#define SV_LIFO 0x2 /* sv_t is LIFO type */ +#define SV_PRIO 0x4 /* sv_t is PRIO type */ +#define SV_KEYED 0x6 /* sv_t is KEYED type */ +#define SV_DEFAULT SV_FIFO + +#endif /* __XFS_SUPPORT_SV_H__ */ diff --git a/sys/gnu/fs/xfs/FreeBSD/support/time.h b/sys/gnu/fs/xfs/FreeBSD/support/time.h new file mode 100644 index 0000000..9b3a974 --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/time.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * + * This program 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. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ +#ifndef __XFS_SUPPORT_TIME_H__ +#define __XFS_SUPPORT_TIME_H__ + +#define delay(ticks) DELAY(ticks) + +#endif /* __XFS_SUPPORT_TIME_H__ */ diff --git a/sys/gnu/fs/xfs/FreeBSD/support/uuid.c b/sys/gnu/fs/xfs/FreeBSD/support/uuid.c new file mode 100644 index 0000000..55344c0 --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/uuid.c @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved. + * + * This program 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. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ + +#include <xfs_config.h> +#include <xfs_compat.h> +#include <xfs_types.h> +#include <xfs_arch.h> + +#include <support/uuid.h> +#include <support/kmem.h> +#include <support/debug.h> +#include <support/mutex.h> + +static mutex_t uuid_monitor; +static int uuid_table_size; +static uuid_t *uuid_table; + +void +uuid_init(void) +{ + mutex_init(&uuid_monitor, MUTEX_DEFAULT, "uuid_monitor"); +} + +void +uuid_cleanup(void) +{ + mutex_destroy(&uuid_monitor); +} + +/* + * uuid_getnodeuniq - obtain the node unique fields of a UUID. + * + * This is not in any way a standard or condoned UUID function; + * it just something that's needed for user-level file handles. + */ +void +uuid_getnodeuniq(uuid_t *uuid, int fsid [2]) +{ + char *uu = (char *)uuid; + + /* on IRIX, this function assumes big-endian fields within + * the uuid, so we use INT_GET to get the same result on + * little-endian systems + */ + + fsid[0] = (INT_GET(*(u_int16_t*)(uu+8), ARCH_CONVERT) << 16) + + INT_GET(*(u_int16_t*)(uu+4), ARCH_CONVERT); + fsid[1] = INT_GET(*(u_int32_t*)(uu ), ARCH_CONVERT); +} + +void +uuid_create_nil(uuid_t *uuid) +{ + memset(uuid, 0, sizeof(*uuid)); +} + +int +uuid_is_nil(uuid_t *uuid) +{ + int i; + char *cp = (char *)uuid; + + if (uuid == NULL) + return 0; + /* implied check of version number here... */ + for (i = 0; i < sizeof *uuid; i++) + if (*cp++) return 0; /* not nil */ + return 1; /* is nil */ +} + +int +uuid_equal(uuid_t *uuid1, uuid_t *uuid2) +{ + return memcmp(uuid1, uuid2, sizeof(uuid_t)) ? 0 : 1; +} + +/* + * Given a 128-bit uuid, return a 64-bit value by adding the top and bottom + * 64-bit words. NOTE: This function can not be changed EVER. Although + * brain-dead, some applications depend on this 64-bit value remaining + * persistent. Specifically, DMI vendors store the value as a persistent + * filehandle. + */ +__uint64_t +uuid_hash64(uuid_t *uuid) +{ + __uint64_t *sp = (__uint64_t *)uuid; + + return sp[0] + sp[1]; +} + +int +uuid_table_insert(uuid_t *uuid) +{ + int i, hole; + + mutex_lock(&uuid_monitor, PVFS); + for (i = 0, hole = -1; i < uuid_table_size; i++) { + if (uuid_is_nil(&uuid_table[i])) { + hole = i; + continue; + } + if (uuid_equal(uuid, &uuid_table[i])) { + mutex_unlock(&uuid_monitor); + return 0; + } + } + if (hole < 0) { + uuid_table = kmem_realloc(uuid_table, + (uuid_table_size + 1) * sizeof(*uuid_table), + uuid_table_size * sizeof(*uuid_table), + KM_SLEEP); + hole = uuid_table_size++; + } + uuid_table[hole] = *uuid; + mutex_unlock(&uuid_monitor); + return 1; +} + +void +uuid_table_remove(uuid_t *uuid) +{ + int i; + + mutex_lock(&uuid_monitor, PVFS); + for (i = 0; i < uuid_table_size; i++) { + if (uuid_is_nil(&uuid_table[i])) + continue; + if (!uuid_equal(uuid, &uuid_table[i])) + continue; + uuid_create_nil(&uuid_table[i]); + break; + } + ASSERT(i < uuid_table_size); + mutex_unlock(&uuid_monitor); +} diff --git a/sys/gnu/fs/xfs/FreeBSD/support/uuid.h b/sys/gnu/fs/xfs/FreeBSD/support/uuid.h new file mode 100644 index 0000000..d8f389a --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/uuid.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved. + * + * This program 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. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ +#ifndef __XFS_SUPPORT_UUID_H__ +#define __XFS_SUPPORT_UUID_H__ + +void uuid_init(void); +void uuid_cleanup(void); +void uuid_create_nil(uuid_t *uuid); +int uuid_is_nil(uuid_t *uuid); +int uuid_equal(uuid_t *uuid1, uuid_t *uuid2); +void uuid_getnodeuniq(uuid_t *uuid, int fsid [2]); +__uint64_t uuid_hash64(uuid_t *uuid); +int uuid_table_insert(uuid_t *uuid); +void uuid_table_remove(uuid_t *uuid); + +#endif /* __XFS_SUPPORT_UUID_H__ */ |