diff options
Diffstat (limited to 'sys-kernel/spl/files')
12 files changed, 1390 insertions, 0 deletions
diff --git a/sys-kernel/spl/files/spl-0.6.0_rc13-fix-on_each_cpu-autotools-check.patch b/sys-kernel/spl/files/spl-0.6.0_rc13-fix-on_each_cpu-autotools-check.patch new file mode 100644 index 000000000000..e8eaa385c642 --- /dev/null +++ b/sys-kernel/spl/files/spl-0.6.0_rc13-fix-on_each_cpu-autotools-check.patch @@ -0,0 +1,46 @@ +From 050cd84e628e5d827a0b345cda12b97253fccd37 Mon Sep 17 00:00:00 2001 +From: Brian Behlendorf <behlendorf1@llnl.gov> +Date: Mon, 7 Jan 2013 14:09:09 -0800 +Subject: [PATCH] Linux compat 3.7.1, on_each_cpu() + +Some kernels require that we include the 'linux/irqflags.h' +header for the SPL_AC_3ARGS_ON_EACH_CPU check. Otherwise, +the functions local_irq_enable()/local_irq_disable() will not +be defined and the prototype will be misdetected as the four +argument version. + +This change actually include 'linux/interrupt.h' which in turn +includes 'linux/irqflags.h' to be as generic as possible. + +Additionally, passing NULL as the function can result in a +gcc error because the on_each_cpu() macro executes it +unconditionally. To make the test more robust we pass the +dummy function on_each_cpu_func(). + +Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> +Closes #204 +--- + config/spl-build.m4 | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/config/spl-build.m4 b/config/spl-build.m4 +index f710d8e..6e4afed 100644 +--- a/config/spl-build.m4 ++++ b/config/spl-build.m4 +@@ -1312,9 +1312,12 @@ dnl # + AC_DEFUN([SPL_AC_3ARGS_ON_EACH_CPU], [ + AC_MSG_CHECKING([whether on_each_cpu() wants 3 args]) + SPL_LINUX_TRY_COMPILE([ ++ #include <linux/interrupt.h> + #include <linux/smp.h> ++ ++ void on_each_cpu_func(void *data) { return; } + ],[ +- on_each_cpu(NULL, NULL, 0); ++ on_each_cpu(on_each_cpu_func, NULL, 0); + ],[ + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_3ARGS_ON_EACH_CPU, 1, +-- +1.7.10 + diff --git a/sys-kernel/spl/files/spl-0.6.0_rc13-fix-soft-lockup.patch b/sys-kernel/spl/files/spl-0.6.0_rc13-fix-soft-lockup.patch new file mode 100644 index 000000000000..99227feb04a2 --- /dev/null +++ b/sys-kernel/spl/files/spl-0.6.0_rc13-fix-soft-lockup.patch @@ -0,0 +1,179 @@ +From d4899f4747fd03be748fd1a589b9db5786fa1375 Mon Sep 17 00:00:00 2001 +From: Brian Behlendorf <behlendorf1@llnl.gov> +Date: Fri, 11 Jan 2013 14:29:32 -0800 +Subject: [PATCH] kmem-cache: Fix slab ageing soft lockup + +Commit a10287e00d13c4c4dbbff14f42b00b03da363fcb slightly reworked +the slab ageing code such that it is no longer dependent on the +Linux delayed work queue interfaces. + +This was good for portability and performance, but it requires us +to use the on_each_cpu() function to execute the spl_magazine_age() +function. That means that the function is now executing in interrupt +context whereas before it was scheduled in normal process context. +And that means we need to be slightly more careful about the locking +in the interrupt handler. + +With the reworked code it's possible that we'll be holding the +skc->skc_lock and be interrupted to handle the spl_magazine_age() +IRQ. This will result in a deadlock and soft lockup errors unless +we're careful to detect the contention and avoid taking the lock in +the interupt handler. So that's what this patch does. + +Alternately, (and slightly more conventionally) we could have used +spin_lock_irqsave() to prevent this race entirely but I'd perfer to +avoid disabling interrupts as much as possible due to performance +concerns. There is absolutely no penalty for us not aging objects +out of the magazine due to contention. + +Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> +Signed-off-by: Prakash Surya <surya1@llnl.gov> +Closes zfsonlinux/zfs#1193 +--- + module/spl/spl-kmem.c | 94 +++++++++++++++++++++++++++---------------------- + 1 file changed, 51 insertions(+), 43 deletions(-) + +diff --git a/module/spl/spl-kmem.c b/module/spl/spl-kmem.c +index bc08a55..cc5961e 100644 +--- a/module/spl/spl-kmem.c ++++ b/module/spl/spl-kmem.c +@@ -827,8 +827,7 @@ char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap) + struct rw_semaphore spl_kmem_cache_sem; /* Cache list lock */ + taskq_t *spl_kmem_cache_taskq; /* Task queue for ageing / reclaim */ + +-static int spl_cache_flush(spl_kmem_cache_t *skc, +- spl_kmem_magazine_t *skm, int flush); ++static void spl_cache_shrink(spl_kmem_cache_t *skc, void *obj); + + SPL_SHRINKER_CALLBACK_FWD_DECLARE(spl_kmem_cache_generic_shrinker); + SPL_SHRINKER_DECLARE(spl_kmem_cache_shrinker, +@@ -1244,6 +1243,38 @@ static int spl_cache_flush(spl_kmem_cache_t *skc, + SRETURN(0); + } + ++/* ++ * Release objects from the per-cpu magazine back to their slab. The flush ++ * argument contains the max number of entries to remove from the magazine. ++ */ ++static void ++__spl_cache_flush(spl_kmem_cache_t *skc, spl_kmem_magazine_t *skm, int flush) ++{ ++ int i, count = MIN(flush, skm->skm_avail); ++ SENTRY; ++ ++ ASSERT(skc->skc_magic == SKC_MAGIC); ++ ASSERT(skm->skm_magic == SKM_MAGIC); ++ ASSERT(spin_is_locked(&skc->skc_lock)); ++ ++ for (i = 0; i < count; i++) ++ spl_cache_shrink(skc, skm->skm_objs[i]); ++ ++ skm->skm_avail -= count; ++ memmove(skm->skm_objs, &(skm->skm_objs[count]), ++ sizeof(void *) * skm->skm_avail); ++ ++ SEXIT; ++} ++ ++static void ++spl_cache_flush(spl_kmem_cache_t *skc, spl_kmem_magazine_t *skm, int flush) ++{ ++ spin_lock(&skc->skc_lock); ++ __spl_cache_flush(skc, skm, flush); ++ spin_unlock(&skc->skc_lock); ++} ++ + static void + spl_magazine_age(void *data) + { +@@ -1252,10 +1283,23 @@ static int spl_cache_flush(spl_kmem_cache_t *skc, + + ASSERT(skm->skm_magic == SKM_MAGIC); + ASSERT(skm->skm_cpu == smp_processor_id()); ++ ASSERT(irqs_disabled()); ++ ++ /* There are no available objects or they are too young to age out */ ++ if ((skm->skm_avail == 0) || ++ time_before(jiffies, skm->skm_age + skc->skc_delay * HZ)) ++ return; + +- if (skm->skm_avail > 0) +- if (time_after(jiffies, skm->skm_age + skc->skc_delay * HZ)) +- (void) spl_cache_flush(skc, skm, skm->skm_refill); ++ /* ++ * Because we're executing in interrupt context we may have ++ * interrupted the holder of this lock. To avoid a potential ++ * deadlock return if the lock is contended. ++ */ ++ if (!spin_trylock(&skc->skc_lock)) ++ return; ++ ++ __spl_cache_flush(skc, skm, skm->skm_refill); ++ spin_unlock(&skc->skc_lock); + } + + /* +@@ -1451,7 +1495,7 @@ static int spl_cache_flush(spl_kmem_cache_t *skc, + + for_each_online_cpu(i) { + skm = skc->skc_mag[i]; +- (void)spl_cache_flush(skc, skm, skm->skm_avail); ++ spl_cache_flush(skc, skm, skm->skm_avail); + spl_magazine_free(skm); + } + +@@ -1932,42 +1976,6 @@ static int spl_cache_flush(spl_kmem_cache_t *skc, + } + + /* +- * Release a batch of objects from a per-cpu magazine back to their +- * respective slabs. This occurs when we exceed the magazine size, +- * are under memory pressure, when the cache is idle, or during +- * cache cleanup. The flush argument contains the number of entries +- * to remove from the magazine. +- */ +-static int +-spl_cache_flush(spl_kmem_cache_t *skc, spl_kmem_magazine_t *skm, int flush) +-{ +- int i, count = MIN(flush, skm->skm_avail); +- SENTRY; +- +- ASSERT(skc->skc_magic == SKC_MAGIC); +- ASSERT(skm->skm_magic == SKM_MAGIC); +- +- /* +- * XXX: Currently we simply return objects from the magazine to +- * the slabs in fifo order. The ideal thing to do from a memory +- * fragmentation standpoint is to cheaply determine the set of +- * objects in the magazine which will result in the largest +- * number of free slabs if released from the magazine. +- */ +- spin_lock(&skc->skc_lock); +- for (i = 0; i < count; i++) +- spl_cache_shrink(skc, skm->skm_objs[i]); +- +- skm->skm_avail -= count; +- memmove(skm->skm_objs, &(skm->skm_objs[count]), +- sizeof(void *) * skm->skm_avail); +- +- spin_unlock(&skc->skc_lock); +- +- SRETURN(count); +-} +- +-/* + * Allocate an object from the per-cpu magazine, or if the magazine + * is empty directly allocate from a slab and repopulate the magazine. + */ +@@ -2053,7 +2061,7 @@ static int spl_cache_flush(spl_kmem_cache_t *skc, + + /* Per-CPU cache full, flush it to make space */ + if (unlikely(skm->skm_avail >= skm->skm_size)) +- (void)spl_cache_flush(skc, skm, skm->skm_refill); ++ spl_cache_flush(skc, skm, skm->skm_refill); + + /* Available space in cache, use it */ + skm->skm_objs[skm->skm_avail++] = obj; +-- +1.7.10 + diff --git a/sys-kernel/spl/files/spl-0.6.0_rc14-fix-atomic64-checks.patch b/sys-kernel/spl/files/spl-0.6.0_rc14-fix-atomic64-checks.patch new file mode 100644 index 000000000000..9ac8a4308dd6 --- /dev/null +++ b/sys-kernel/spl/files/spl-0.6.0_rc14-fix-atomic64-checks.patch @@ -0,0 +1,70 @@ +From dd3678fc29d75286b57e705454bbd7e60e1b44e0 Mon Sep 17 00:00:00 2001 +From: Brian Behlendorf <behlendorf1@llnl.gov> +Date: Tue, 5 Feb 2013 09:35:43 -0800 +Subject: [PATCH] Fix atomic64_* autoconf checks + +The SPL_AC_ATOMIC_SPINLOCK, SPL_AC_TYPE_ATOMIC64_CMPXCHG, and +SPL_AC_TYPE_ATOMIC64_XCHG were all directly including the +'asm/atomic.h' header. As of Linux 3.4 this header was removed +which results in a build failure. + +The right thing to do is include 'linux/atomic.h' however we +can't safely do this because it doesn't exist in 2.6.26 kernels. +Therefore, we include 'linux/fs.h' which in turn includes the +correct atomic header regardless of the kernel version. + +When these incorrect APIs are used in ZFS the following build +failure results. + + arc.c:791:80: warning: '__ret' may be used uninitialized + in this function [-Wuninitialized] + arc.c:791:1875: error: call to '__cmpxchg_wrong_size' + declared with attribute error: Bad argument size for cmpxchg + +Since this is all Linux 2.6.24 compatibility code there's +an argument to be made that it should be removed because +kernels this old are not supported. However, because we're +so close to a release I'm going to leave it in place for now. + +Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> +Closes zfsonlinux/zfs#814 +Closes zfsonlinux/zfs#1254 +--- + config/spl-build.m4 | 7 +++---- + 1 file changed, 3 insertions(+), 4 deletions(-) + +diff --git a/config/spl-build.m4 b/config/spl-build.m4 +index e9695de..8518404 100644 +--- a/config/spl-build.m4 ++++ b/config/spl-build.m4 +@@ -777,7 +777,7 @@ AC_DEFUN([SPL_AC_ATOMIC_SPINLOCK], [ + [enable_atomic_spinlocks=check]) + + SPL_LINUX_TRY_COMPILE([ +- #include <asm/atomic.h> ++ #include <linux/fs.h> + ],[ + atomic64_t *ptr __attribute__ ((unused)); + ],[ +@@ -820,8 +820,7 @@ dnl # + AC_DEFUN([SPL_AC_TYPE_ATOMIC64_CMPXCHG], + [AC_MSG_CHECKING([whether kernel defines atomic64_cmpxchg]) + SPL_LINUX_TRY_COMPILE([ +- #include <asm/atomic.h> +- #include <asm/system.h> ++ #include <linux/fs.h> + ],[ + atomic64_cmpxchg((atomic64_t *)NULL, 0, 0); + ],[ +@@ -840,7 +839,7 @@ dnl # + AC_DEFUN([SPL_AC_TYPE_ATOMIC64_XCHG], + [AC_MSG_CHECKING([whether kernel defines atomic64_xchg]) + SPL_LINUX_TRY_COMPILE([ +- #include <asm/atomic.h> ++ #include <linux/fs.h> + ],[ + atomic64_xchg((atomic64_t *)NULL, 0); + ],[ +-- +1.7.10 + diff --git a/sys-kernel/spl/files/spl-0.6.0_rc14-fix-mutex-owner-check.patch b/sys-kernel/spl/files/spl-0.6.0_rc14-fix-mutex-owner-check.patch new file mode 100644 index 000000000000..ee7314d3cf32 --- /dev/null +++ b/sys-kernel/spl/files/spl-0.6.0_rc14-fix-mutex-owner-check.patch @@ -0,0 +1,33 @@ +From a0625691b39468d04eb716919e237f96a3987b48 Mon Sep 17 00:00:00 2001 +From: Richard Yao <ryao@cs.stonybrook.edu> +Date: Tue, 5 Feb 2013 16:42:29 -0500 +Subject: [PATCH] Fix HAVE_MUTEX_OWNER_TASK_STRUCT autotools check on PPC64 + +The HAVE_MUTEX_OWNER_TASK_STRUCT fails on PPC64 with the following +error: + +error: 'current' undeclared (first use in this function) + +We include linux/sched.h to ensure that current is available. + +Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu> +Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> +--- + config/spl-build.m4 | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/config/spl-build.m4 b/config/spl-build.m4 +index 8518404..4cb7e1d 100644 +--- a/config/spl-build.m4 ++++ b/config/spl-build.m4 +@@ -1269,6 +1269,7 @@ AC_DEFUN([SPL_AC_MUTEX_OWNER_TASK_STRUCT], [ + EXTRA_KCFLAGS="-Werror" + SPL_LINUX_TRY_COMPILE([ + #include <linux/mutex.h> ++ #include <linux/sched.h> + ],[ + struct mutex mtx __attribute__ ((unused)); + mtx.owner = current; +-- +1.7.10 + diff --git a/sys-kernel/spl/files/spl-0.6.0_rc14-linux-3.9-compat.patch b/sys-kernel/spl/files/spl-0.6.0_rc14-linux-3.9-compat.patch new file mode 100644 index 000000000000..5f9a4c698803 --- /dev/null +++ b/sys-kernel/spl/files/spl-0.6.0_rc14-linux-3.9-compat.patch @@ -0,0 +1,237 @@ +diff --git a/config/spl-build.m4 b/config/spl-build.m4 +index 3dcc05e..6a8e658 100644 +--- a/config/spl-build.m4 ++++ b/config/spl-build.m4 +@@ -64,6 +64,7 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [ + SPL_AC_USER_PATH_DIR + SPL_AC_SET_FS_PWD + SPL_AC_2ARGS_SET_FS_PWD ++ SPL_AC_SET_FS_PWD_WITH_CONST + SPL_AC_2ARGS_VFS_UNLINK + SPL_AC_4ARGS_VFS_RENAME + SPL_AC_VFS_FSYNC +@@ -88,6 +89,8 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [ + SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE + SPL_AC_SHRINK_CONTROL_STRUCT + SPL_AC_RWSEM_SPINLOCK_IS_RAW ++ SPL_AC_SCHED_RT_HEADER ++ SPL_AC_2ARGS_VFS_GETATTR + ]) + + AC_DEFUN([SPL_AC_MODULE_SYMVERS], [ +@@ -1684,12 +1687,55 @@ AC_DEFUN([SPL_AC_2ARGS_SET_FS_PWD], + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_2ARGS_SET_FS_PWD, 1, + [set_fs_pwd() wants 2 args]) ++ HAVE_2ARGS_SET_FS_PWD=yes + ],[ + AC_MSG_RESULT(no) + ]) + ]) + + dnl # ++dnl # 3.9 API change ++dnl # set_fs_pwd takes const struct path * ++dnl # ++AC_DEFUN([SPL_AC_SET_FS_PWD_WITH_CONST], ++if test "x$HAVE_2ARGS_SET_FS_PWD" = xyes; then ++ tmp_flags="$EXTRA_KCFLAGS" ++ EXTRA_KCFLAGS="-Werror" ++ [AC_MSG_CHECKING([whether set_fs_pwd() requires const struct path *]) ++ SPL_LINUX_TRY_COMPILE([ ++ #include <linux/spinlock.h> ++ #include <linux/fs_struct.h> ++ #include <linux/path.h> ++ void (*const set_fs_pwd_func) ++ (struct fs_struct *, const struct path *) ++ = set_fs_pwd; ++ ],[ ++ return 0; ++ ],[ ++ AC_MSG_RESULT(yes) ++ AC_DEFINE(HAVE_SET_FS_PWD_WITH_CONST, 1, ++ [set_fs_pwd() needs const path *]) ++ ],[ ++ SPL_LINUX_TRY_COMPILE([ ++ #include <linux/spinlock.h> ++ #include <linux/fs_struct.h> ++ #include <linux/path.h> ++ void (*const set_fs_pwd_func) ++ (struct fs_struct *, struct path *) ++ = set_fs_pwd; ++ ],[ ++ return 0; ++ ],[ ++ AC_MSG_RESULT(no) ++ ],[ ++ AC_MSG_ERROR(unknown) ++ ]) ++ ]) ++ EXTRA_KCFLAGS="$tmp_flags" ++fi ++]) ++ ++dnl # + dnl # SLES API change, never adopted in mainline, + dnl # Third 'struct vfsmount *' argument removed. + dnl # +@@ -2217,3 +2263,53 @@ AC_DEFUN([SPL_AC_RWSEM_SPINLOCK_IS_RAW], [ + ]) + EXTRA_KCFLAGS="$tmp_flags" + ]) ++ ++dnl # ++dnl # 3.9 API change, ++dnl # Moved things from linux/sched.h to linux/sched/rt.h ++dnl # ++AC_DEFUN([SPL_AC_SCHED_RT_HEADER], ++ [AC_MSG_CHECKING([whether header linux/sched/rt.h exists]) ++ SPL_LINUX_TRY_COMPILE([ ++ #include <linux/sched.h> ++ #include <linux/sched/rt.h> ++ ],[ ++ return 0; ++ ],[ ++ AC_DEFINE(HAVE_SCHED_RT_HEADER, 1, [linux/sched/rt.h exists]) ++ AC_MSG_RESULT(yes) ++ ],[ ++ AC_MSG_RESULT(no) ++ ]) ++]) ++ ++dnl # ++dnl # 3.9 API change, ++dnl # vfs_getattr() uses 2 args ++dnl # It takes struct path * instead of struct vfsmount * and struct dentry * ++dnl # ++AC_DEFUN([SPL_AC_2ARGS_VFS_GETATTR], [ ++ AC_MSG_CHECKING([whether vfs_getattr() wants]) ++ SPL_LINUX_TRY_COMPILE([ ++ #include <linux/fs.h> ++ ],[ ++ vfs_getattr((struct path *) NULL, ++ (struct kstat *)NULL); ++ ],[ ++ AC_MSG_RESULT(2 args) ++ AC_DEFINE(HAVE_2ARGS_VFS_GETATTR, 1, ++ [vfs_getattr wants 2 args]) ++ ],[ ++ SPL_LINUX_TRY_COMPILE([ ++ #include <linux/fs.h> ++ ],[ ++ vfs_getattr((struct vfsmount *)NULL, ++ (struct dentry *)NULL, ++ (struct kstat *)NULL); ++ ],[ ++ AC_MSG_RESULT(3 args) ++ ],[ ++ AC_MSG_ERROR(unknown) ++ ]) ++ ]) ++]) +diff --git a/include/sys/sysmacros.h b/include/sys/sysmacros.h +index 7c4da67..b4778b7 100644 +--- a/include/sys/sysmacros.h ++++ b/include/sys/sysmacros.h +@@ -26,12 +26,17 @@ + #define _SPL_SYSMACROS_H + + #include <linux/module.h> ++#include <linux/sched.h> + #include <linux/cpumask.h> + #include <sys/debug.h> + #include <sys/varargs.h> + #include <sys/zone.h> + #include <sys/signal.h> + ++#ifdef HAVE_SCHED_RT_HEADER ++#include <linux/sched/rt.h> ++#endif ++ + #ifndef _KERNEL + #define _KERNEL __KERNEL__ + #endif +diff --git a/module/spl/spl-kmem.c b/module/spl/spl-kmem.c +index e3538b5..f9c1114 100644 +--- a/module/spl/spl-kmem.c ++++ b/module/spl/spl-kmem.c +@@ -404,7 +404,8 @@ kmem_del_init(spinlock_t *lock, struct hlist_head *table, int bits, const void * + spin_lock_irqsave(lock, flags); + + head = &table[hash_ptr(addr, bits)]; +- hlist_for_each_entry_rcu(p, node, head, kd_hlist) { ++ hlist_for_each_rcu(node, head) { ++ p = list_entry_rcu(node, struct kmem_debug, kd_hlist); + if (p->kd_addr == addr) { + hlist_del_init(&p->kd_hlist); + list_del_init(&p->kd_list); +diff --git a/module/spl/spl-tsd.c b/module/spl/spl-tsd.c +index d7749cf..6e5605b 100644 +--- a/module/spl/spl-tsd.c ++++ b/module/spl/spl-tsd.c +@@ -113,7 +113,8 @@ tsd_hash_search(tsd_hash_table_t *table, uint_t key, pid_t pid) + hash = hash_long((ulong_t)key * (ulong_t)pid, table->ht_bits); + bin = &table->ht_bins[hash]; + spin_lock(&bin->hb_lock); +- hlist_for_each_entry(entry, node, &bin->hb_head, he_list) { ++ hlist_for_each(node, &bin->hb_head) { ++ entry = list_entry(node, tsd_hash_entry_t, he_list); + if ((entry->he_key == key) && (entry->he_pid == pid)) { + spin_unlock(&bin->hb_lock); + SRETURN(entry); +diff --git a/module/spl/spl-vnode.c b/module/spl/spl-vnode.c +index 4d571c6..dac452c 100644 +--- a/module/spl/spl-vnode.c ++++ b/module/spl/spl-vnode.c +@@ -175,7 +175,11 @@ vn_open(const char *path, uio_seg_t seg, int flags, int mode, + if (IS_ERR(fp)) + SRETURN(-PTR_ERR(fp)); + +- rc = vfs_getattr(fp->f_vfsmnt, fp->f_dentry, &stat); ++#ifdef HAVE_2ARGS_VFS_GETATTR ++ rc = vfs_getattr(&fp->f_path, &stat); ++#else ++ rc = vfs_getattr(fp->f_path.mnt, fp->f_dentry, &stat); ++#endif + if (rc) { + filp_close(fp, 0); + SRETURN(-rc); +@@ -602,7 +606,11 @@ vn_getattr(vnode_t *vp, vattr_t *vap, int flags, void *x3, void *x4) + + fp = vp->v_file; + +- rc = vfs_getattr(fp->f_vfsmnt, fp->f_dentry, &stat); ++#ifdef HAVE_2ARGS_VFS_GETATTR ++ rc = vfs_getattr(&fp->f_path, &stat); ++#else ++ rc = vfs_getattr(fp->f_path.mnt, fp->f_dentry, &stat); ++#endif + if (rc) + SRETURN(-rc); + +@@ -754,7 +762,12 @@ vn_getf(int fd) + if (vp == NULL) + SGOTO(out_fget, rc); + +- if (vfs_getattr(lfp->f_vfsmnt, lfp->f_dentry, &stat)) ++#ifdef HAVE_2ARGS_VFS_GETATTR ++ rc = vfs_getattr(&lfp->f_path, &stat); ++#else ++ rc = vfs_getattr(lfp->f_path.mnt, lfp->f_dentry, &stat); ++#endif ++ if (rc) + SGOTO(out_vnode, rc); + + mutex_enter(&vp->v_lock); +@@ -827,7 +840,11 @@ EXPORT_SYMBOL(releasef); + # ifdef HAVE_2ARGS_SET_FS_PWD + /* Used from 2.6.25 - 2.6.31+ */ + void ++# ifdef HAVE_SET_FS_PWD_WITH_CONST ++set_fs_pwd(struct fs_struct *fs, const struct path *path) ++# else + set_fs_pwd(struct fs_struct *fs, struct path *path) ++# endif + { + struct path old_pwd; + diff --git a/sys-kernel/spl/files/spl-0.6.0_rc14-no-cond_resched.patch b/sys-kernel/spl/files/spl-0.6.0_rc14-no-cond_resched.patch new file mode 100644 index 000000000000..9f1d692d0371 --- /dev/null +++ b/sys-kernel/spl/files/spl-0.6.0_rc14-no-cond_resched.patch @@ -0,0 +1,38 @@ +From 58a382c73ad3393d7591421950624e75d3c4aea1 Mon Sep 17 00:00:00 2001 +From: Richard Yao <ryao@cs.stonybrook.edu> +Date: Thu, 21 Mar 2013 13:21:11 -0400 +Subject: [PATCH] Do not call cond_resched() in spl_slab_reclaim() + +Calling cond_resched() after each object is freed and then after each +slab is freed can cause slabs of objects to live for excessive periods +of time following reclaimation. This interferes with the kernel's own +memory management when called from kswapd and can cause direct reclaim +to occur in response to memory pressure that should have been resolved. + +Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu> +--- + module/spl/spl-kmem.c | 3 --- + 1 file changed, 3 deletions(-) + +diff --git a/module/spl/spl-kmem.c b/module/spl/spl-kmem.c +index f9c1114..a0ca2d2 100644 +--- a/module/spl/spl-kmem.c ++++ b/module/spl/spl-kmem.c +@@ -1112,14 +1112,11 @@ char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap) + + if (skc->skc_flags & KMC_OFFSLAB) + kv_free(skc, sko->sko_addr, size); +- +- cond_resched(); + } + + list_for_each_entry_safe(sks, m, &sks_list, sks_list) { + ASSERT(sks->sks_magic == SKS_MAGIC); + kv_free(skc, sks, skc->skc_slab_size); +- cond_resched(); + } + + SEXIT; +-- +1.8.1.5 + diff --git a/sys-kernel/spl/files/spl-0.6.0_rc14-simplify-hostid-logic.patch b/sys-kernel/spl/files/spl-0.6.0_rc14-simplify-hostid-logic.patch new file mode 100644 index 000000000000..3d5199fb4eb6 --- /dev/null +++ b/sys-kernel/spl/files/spl-0.6.0_rc14-simplify-hostid-logic.patch @@ -0,0 +1,181 @@ +From f47f028ae6f039c13d3138e2ee1c0056a3a3f789 Mon Sep 17 00:00:00 2001 +From: Richard Yao <ryao@cs.stonybrook.edu> +Date: Mon, 11 Mar 2013 21:16:36 -0400 +Subject: [PATCH] Simplify hostid logic + +There is plenty of compatibility code for a hw_hostid +that isn't used by anything. At the same time, there are apparently +issues with the current hostid logic. coredumb in #zfsonlinux on +freenode reported that Fedora 17 changes its hostid on every boot, which +required force importing his pool. A suggestion by wca was to adopt +FreeBSD's behavior, where it treats hostid as zero if /etc/hostid does +not exist + +Adopting FreeBSD's behavior permits us to eliminate plenty of code, +including a userland helper that invokes the system's hostid as a +fallback. + +Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu> +--- + include/sys/sysmacros.h | 1 - + include/sys/systeminfo.h | 3 +-- + module/spl/spl-generic.c | 55 ++++++------------------------------------------ + module/spl/spl-proc.c | 11 ---------- + 4 files changed, 7 insertions(+), 63 deletions(-) + +diff --git a/include/sys/sysmacros.h b/include/sys/sysmacros.h +index 7c4da67..4dd2685 100644 +--- a/include/sys/sysmacros.h ++++ b/include/sys/sysmacros.h +@@ -138,7 +138,6 @@ + /* Missing globals */ + extern char spl_version[32]; + extern unsigned long spl_hostid; +-extern char hw_serial[11]; + + /* Missing misc functions */ + extern int highbit(unsigned long i); +diff --git a/include/sys/systeminfo.h b/include/sys/systeminfo.h +index e22a085..a4c1984 100644 +--- a/include/sys/systeminfo.h ++++ b/include/sys/systeminfo.h +@@ -25,6 +25,5 @@ + #ifndef _SPL_SYSTEMINFO_H + #define _SPL_SYSTEMINFO_H + +-#define HW_INVALID_HOSTID 0xFFFFFFFF /* an invalid hostid */ + #define HW_HOSTID_LEN 11 /* minimum buffer size needed */ + /* to hold a decimal or hex */ +diff --git a/module/spl/spl-generic.c b/module/spl/spl-generic.c +index 3cef489..b8e2ed1 100644 +--- a/module/spl/spl-generic.c ++++ b/module/spl/spl-generic.c +@@ -52,14 +52,11 @@ + char spl_version[32] = "SPL v" SPL_META_VERSION "-" SPL_META_RELEASE; + EXPORT_SYMBOL(spl_version); + +-unsigned long spl_hostid = HW_INVALID_HOSTID; ++unsigned long spl_hostid = 0; + EXPORT_SYMBOL(spl_hostid); + module_param(spl_hostid, ulong, 0644); + MODULE_PARM_DESC(spl_hostid, "The system hostid."); + +-char hw_serial[HW_HOSTID_LEN] = "<none>"; +-EXPORT_SYMBOL(hw_serial); +- + proc_t p0 = { 0 }; + EXPORT_SYMBOL(p0); + +@@ -467,7 +464,7 @@ struct new_utsname *__utsname(void) + int result; + uint64_t size; + struct _buf *file; +- unsigned long hostid = 0; ++ uint32_t hostid = 0; + + file = kobj_open_file(spl_hostid_path); + +@@ -511,45 +508,10 @@ struct new_utsname *__utsname(void) + return 0; + } + +-#define GET_HOSTID_CMD \ +- "exec 0</dev/null " \ +- " 1>/proc/sys/kernel/spl/hostid " \ +- " 2>/dev/null; " \ +- "hostid" +- +-static int +-hostid_exec(void) +-{ +- char *argv[] = { "/bin/sh", +- "-c", +- GET_HOSTID_CMD, +- NULL }; +- char *envp[] = { "HOME=/", +- "TERM=linux", +- "PATH=/sbin:/usr/sbin:/bin:/usr/bin", +- NULL }; +- int rc; +- +- /* Doing address resolution in the kernel is tricky and just +- * not a good idea in general. So to set the proper 'hw_serial' +- * use the usermodehelper support to ask '/bin/sh' to run +- * '/usr/bin/hostid' and redirect the result to /proc/sys/spl/hostid +- * for us to use. It's a horrific solution but it will do for now. +- */ +- rc = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC); +- if (rc) +- printk("SPL: Failed user helper '%s %s %s', rc = %d\n", +- argv[0], argv[1], argv[2], rc); +- +- return rc; +-} +- + uint32_t + zone_get_hostid(void *zone) + { + static int first = 1; +- unsigned long hostid; +- int rc; + + /* Only the global zone is supported */ + ASSERT(zone == NULL); +@@ -559,21 +521,16 @@ struct new_utsname *__utsname(void) + + /* + * Get the hostid if it was not passed as a module parameter. +- * Try reading the /etc/hostid file directly, and then fall +- * back to calling the /usr/bin/hostid utility. ++ * Try reading the /etc/hostid file directly. + */ +- if ((spl_hostid == HW_INVALID_HOSTID) && +- (rc = hostid_read()) && (rc = hostid_exec())) +- return HW_INVALID_HOSTID; ++ if (hostid_read()) ++ spl_hostid = 0; + + printk(KERN_NOTICE "SPL: using hostid 0x%08x\n", + (unsigned int) spl_hostid); + } + +- if (ddi_strtoul(hw_serial, NULL, HW_HOSTID_LEN-1, &hostid) != 0) +- return HW_INVALID_HOSTID; +- +- return (uint32_t)hostid; ++ return spl_hostid; + } + EXPORT_SYMBOL(zone_get_hostid); + +diff --git a/module/spl/spl-proc.c b/module/spl/spl-proc.c +index cd4fa1b..1113cf2 100644 +--- a/module/spl/spl-proc.c ++++ b/module/spl/spl-proc.c +@@ -506,9 +506,6 @@ enum { + if (str == end) + SRETURN(-EINVAL); + +- (void) snprintf(hw_serial, HW_HOSTID_LEN, "%lu", spl_hostid); +- hw_serial[HW_HOSTID_LEN - 1] = '\0'; +- *ppos += *lenp; + } else { + len = snprintf(str, sizeof(str), "%lx", spl_hostid); + if (*ppos >= len) +@@ -1051,14 +1048,6 @@ enum { + .mode = 0644, + .proc_handler = &proc_dohostid, + }, +- { +- CTL_NAME (CTL_HW_SERIAL) +- .procname = "hw_serial", +- .data = hw_serial, +- .maxlen = sizeof(hw_serial), +- .mode = 0444, +- .proc_handler = &proc_dostring, +- }, + #ifndef HAVE_KALLSYMS_LOOKUP_NAME + { + CTL_NAME (CTL_KALLSYMS) +-- +1.8.1.5 + diff --git a/sys-kernel/spl/files/spl-0.6.0_rc9-alias-km-sleep-with-km-pushpage.patch b/sys-kernel/spl/files/spl-0.6.0_rc9-alias-km-sleep-with-km-pushpage.patch new file mode 100644 index 000000000000..fb0e5914e773 --- /dev/null +++ b/sys-kernel/spl/files/spl-0.6.0_rc9-alias-km-sleep-with-km-pushpage.patch @@ -0,0 +1,56 @@ +From 5c072b45b66e841ebc7952db7860c2ee7b024b08 Mon Sep 17 00:00:00 2001 +From: Richard Yao <ryao@cs.stonybrook.edu> +Date: Mon, 25 Jun 2012 20:05:00 -0400 +Subject: [PATCH] Make KM_SLEEP an alias of KM_PUSHPAGE Use GFP_NOIO in + KM_SLEEP + +This should prevent direct reclaim issues without requiring +Linux-specific changes to code from Solaris. This is what is done in +FreeBSD. + +Note that a change to __taskq_dispatch() module/spl/spl-taskq.c is +needed to make this work. Changing KM_PUSHPAGE to use GFP_NOIO is fine, +but adding __GFP_HIGH to that triggers a hard-coded panic in +__taskq_dispatch() during zvol initialization. Removing the hard coded +panic has no ill effects. + +Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu> +--- + include/sys/kmem.h | 2 +- + module/spl/spl-taskq.c | 7 ++++--- + 2 files changed, 5 insertions(+), 4 deletions(-) + +diff --git a/include/sys/kmem.h b/include/sys/kmem.h +index 796af44..633278b 100644 +--- a/include/sys/kmem.h ++++ b/include/sys/kmem.h +@@ -41,7 +41,7 @@ + /* + * Memory allocation interfaces + */ +-#define KM_SLEEP GFP_KERNEL /* Can sleep, never fails */ ++#define KM_SLEEP (GFP_NOIO | __GFP_HIGH) /* Can sleep, never fails */ + #define KM_NOSLEEP GFP_ATOMIC /* Can not sleep, may fail */ + #define KM_PUSHPAGE (GFP_NOIO | __GFP_HIGH) /* Use reserved memory */ + #define KM_NODEBUG __GFP_NOWARN /* Suppress warnings */ +diff --git a/module/spl/spl-taskq.c b/module/spl/spl-taskq.c +index 0c546c7..5ab387e 100644 +--- a/module/spl/spl-taskq.c ++++ b/module/spl/spl-taskq.c +@@ -255,9 +255,10 @@ + if (!(flags & (TQ_SLEEP | TQ_NOSLEEP))) + flags |= TQ_SLEEP; + +- if (unlikely(in_atomic() && (flags & TQ_SLEEP))) +- PANIC("May schedule while atomic: %s/0x%08x/%d\n", +- current->comm, preempt_count(), current->pid); ++ /* FIXME: Why does this fail when KM_SLEEP contains __GFP_HIGHMEM? */ ++ //if (unlikely(in_atomic() && (flags & TQ_SLEEP))) ++ // PANIC("May schedule while atomic: %s/0x%08x/%d\n", ++ // current->comm, preempt_count(), current->pid); + + spin_lock_irqsave(&tq->tq_lock, tq->tq_lock_flags); + +-- +1.7.10 + diff --git a/sys-kernel/spl/files/spl-0.6.1-builtin-fix.patch b/sys-kernel/spl/files/spl-0.6.1-builtin-fix.patch new file mode 100644 index 000000000000..6be0c6d06ffe --- /dev/null +++ b/sys-kernel/spl/files/spl-0.6.1-builtin-fix.patch @@ -0,0 +1,28 @@ +From 991857cac5929fa149820722b8e8cd90f874670c Mon Sep 17 00:00:00 2001 +From: Matthew Thode <mthode@mthode.org> +Date: Fri, 21 Jun 2013 14:55:07 -0400 +Subject: [PATCH] Copy spl.release.in to kernel dir + +Required when compiling ZFS in the kernel. + +Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> +Closes #253 +--- + copy-builtin | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/copy-builtin b/copy-builtin +index 3277270..cd98b7a 100755 +--- a/copy-builtin ++++ b/copy-builtin +@@ -33,6 +33,7 @@ rm -rf "$KERNEL_DIR/include/spl" "$KERNEL_DIR/spl" + cp --recursive include "$KERNEL_DIR/include/spl" + cp --recursive module "$KERNEL_DIR/spl" + cp spl_config.h "$KERNEL_DIR/" ++cp spl.release.in "$KERNEL_DIR/" + + adjust_obj_paths() + { +-- +1.8.1.6 + diff --git a/sys-kernel/spl/files/spl-0.6.1-constify-ctl_table.patch b/sys-kernel/spl/files/spl-0.6.1-constify-ctl_table.patch new file mode 100644 index 000000000000..e17cbad4ce81 --- /dev/null +++ b/sys-kernel/spl/files/spl-0.6.1-constify-ctl_table.patch @@ -0,0 +1,63 @@ +diff --git a/module/spl/spl-proc.c b/module/spl/spl-proc.c +index cd4fa1b..3cac8a1 100644 +--- a/module/spl/spl-proc.c ++++ b/module/spl/spl-proc.c +@@ -37,6 +37,12 @@ + + #define SS_DEBUG_SUBSYS SS_PROC + ++#ifdef CONSTIFY_PLUGIN ++typedef struct ctl_table __no_const spl_ctl_table; ++#else ++typedef struct ctl_table spl_ctl_table; ++#endif ++ + #ifdef DEBUG_KMEM + static unsigned long table_min = 0; + static unsigned long table_max = ~0; +@@ -323,7 +329,7 @@ enum { + SPL_PROC_HANDLER(proc_console_max_delay_cs) + { + int rc, max_delay_cs; +- struct ctl_table dummy = *table; ++ spl_ctl_table dummy = *table; + long d; + SENTRY; + +@@ -355,7 +361,7 @@ enum { + SPL_PROC_HANDLER(proc_console_min_delay_cs) + { + int rc, min_delay_cs; +- struct ctl_table dummy = *table; ++ spl_ctl_table dummy = *table; + long d; + SENTRY; + +@@ -387,7 +393,7 @@ enum { + SPL_PROC_HANDLER(proc_console_backoff) + { + int rc, backoff; +- struct ctl_table dummy = *table; ++ spl_ctl_table dummy = *table; + SENTRY; + + dummy.data = &backoff; +@@ -417,7 +423,7 @@ enum { + { + int rc = 0; + unsigned long min = 0, max = ~0, val; +- struct ctl_table dummy = *table; ++ spl_ctl_table dummy = *table; + SENTRY; + + dummy.data = &val; +@@ -444,7 +450,7 @@ enum { + { + int rc = 0; + unsigned long min = 0, max = ~0, val = 0, mask; +- struct ctl_table dummy = *table; ++ spl_ctl_table dummy = *table; + spl_kmem_cache_t *skc; + SENTRY; + +-- diff --git a/sys-kernel/spl/files/spl-0.6.1-fix-delay.patch b/sys-kernel/spl/files/spl-0.6.1-fix-delay.patch new file mode 100644 index 000000000000..42f1f59c7299 --- /dev/null +++ b/sys-kernel/spl/files/spl-0.6.1-fix-delay.patch @@ -0,0 +1,33 @@ +From ab59be7bc752481db64df07c821e2ae6bf2ae71b Mon Sep 17 00:00:00 2001 +From: Brian Behlendorf <behlendorf1@llnl.gov> +Date: Wed, 1 May 2013 16:20:28 -0700 +Subject: [PATCH] Fix delay() + +Somewhat amazingly it went unnoticed that the delay() function +doesn't actually cause the task to block. Since the task state +is never changed from TASK_RUNNING before schedule_timeout() the +scheduler allows to task to continue running without any delay. +Using schedule_timeout_interruptible() resolves the issue by +correctly setting TASK_UNINTERRUPTIBLE. + +Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> +--- + include/sys/timer.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/include/sys/timer.h b/include/sys/timer.h +index 13ef404..2542510 100644 +--- a/include/sys/timer.h ++++ b/include/sys/timer.h +@@ -35,7 +35,7 @@ + #define ddi_get_lbolt() ((clock_t)jiffies) + #define ddi_get_lbolt64() ((int64_t)get_jiffies_64()) + +-#define delay(ticks) schedule_timeout((long)(ticks)) ++#define delay(ticks) schedule_timeout_uninterruptible(ticks) + + #define SEC_TO_TICK(sec) ((sec) * HZ) + #define MSEC_TO_TICK(ms) msecs_to_jiffies(ms) +-- +1.8.1.6 + diff --git a/sys-kernel/spl/files/spl-0.6.1-linux-3.10-compat.patch b/sys-kernel/spl/files/spl-0.6.1-linux-3.10-compat.patch new file mode 100644 index 000000000000..aac1c926bbb4 --- /dev/null +++ b/sys-kernel/spl/files/spl-0.6.1-linux-3.10-compat.patch @@ -0,0 +1,426 @@ +diff --git a/config/spl-build.m4 b/config/spl-build.m4 +index 8a8e3ba..da179e3 100644 +--- a/config/spl-build.m4 ++++ b/config/spl-build.m4 +@@ -33,6 +33,8 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [ + SPL_AC_TASK_CURR + SPL_AC_CTL_UNNUMBERED + SPL_AC_CTL_NAME ++ SPL_AC_VMALLOC_INFO ++ SPL_AC_PDE_DATA + SPL_AC_FLS64 + SPL_AC_DEVICE_CREATE + SPL_AC_5ARGS_DEVICE_CREATE +@@ -1358,6 +1360,43 @@ AC_DEFUN([SPL_AC_GET_VMALLOC_INFO], + ]) + + dnl # ++dnl # 3.10 API change, ++dnl # struct vmalloc_info is now declared in linux/vmalloc.h ++dnl # ++AC_DEFUN([SPL_AC_VMALLOC_INFO], [ ++ AC_MSG_CHECKING([whether struct vmalloc_info is declared]) ++ SPL_LINUX_TRY_COMPILE([ ++ #include <linux/vmalloc.h> ++ struct vmalloc_info { void *a; }; ++ ],[ ++ return 0; ++ ],[ ++ AC_MSG_RESULT(no) ++ ],[ ++ AC_MSG_RESULT(yes) ++ AC_DEFINE(HAVE_VMALLOC_INFO, 1, [yes]) ++ ]) ++]) ++ ++dnl # ++dnl # 3.10 API change, ++dnl # PDE is replaced by PDE_DATA ++dnl # ++AC_DEFUN([SPL_AC_PDE_DATA], [ ++ AC_MSG_CHECKING([whether PDE_DATA() is available]) ++ SPL_LINUX_TRY_COMPILE_SYMBOL([ ++ #include <linux/proc_fs.h> ++ ], [ ++ PDE_DATA(NULL); ++ ], [PDE_DATA], [], [ ++ AC_MSG_RESULT(yes) ++ AC_DEFINE(HAVE_PDE_DATA, 1, [yes]) ++ ],[ ++ AC_MSG_RESULT(no) ++ ]) ++]) ++ ++dnl # + dnl # 2.6.17 API change + dnl # The helper functions first_online_pgdat(), next_online_pgdat(), and + dnl # next_zone() are introduced to simplify for_each_zone(). These symbols +diff --git a/include/linux/proc_compat.h b/include/linux/proc_compat.h +index 434ffa3..7b044e7 100644 +--- a/include/linux/proc_compat.h ++++ b/include/linux/proc_compat.h +@@ -43,9 +43,6 @@ + #endif + + extern struct proc_dir_entry *proc_spl_kstat; +-struct proc_dir_entry *proc_dir_entry_find(struct proc_dir_entry *root, +- const char *str); +-int proc_dir_entries(struct proc_dir_entry *root); + + int spl_proc_init(void); + void spl_proc_fini(void); +diff --git a/include/sys/kstat.h b/include/sys/kstat.h +index 9275c1e..da3c589 100644 +--- a/include/sys/kstat.h ++++ b/include/sys/kstat.h +@@ -83,6 +83,13 @@ struct kstat_s; + typedef int kid_t; /* unique kstat id */ + typedef int kstat_update_t(struct kstat_s *, int); /* dynamic update cb */ + ++typedef struct kstat_module { ++ char ksm_name[KSTAT_STRLEN+1]; /* module name */ ++ struct list_head ksm_module_list; /* module linkage */ ++ struct list_head ksm_kstat_list; /* list of kstat entries */ ++ struct proc_dir_entry *ksm_proc; /* proc entry */ ++} kstat_module_t; ++ + typedef struct kstat_s { + int ks_magic; /* magic value */ + kid_t ks_kid; /* unique kstat ID */ +@@ -102,6 +109,7 @@ typedef struct kstat_s { + void *ks_private; /* private data */ + kmutex_t ks_lock; /* kstat data lock */ + struct list_head ks_list; /* kstat linkage */ ++ kstat_module_t *ks_owner; /* kstat module linkage */ + } kstat_t; + + typedef struct kstat_named_s { +diff --git a/include/sys/vmsystm.h b/include/sys/vmsystm.h +index 9c52d28..34aea2b 100644 +--- a/include/sys/vmsystm.h ++++ b/include/sys/vmsystm.h +@@ -74,10 +74,12 @@ extern size_t vmem_size(vmem_t *vmp, int typemask); + #ifndef HAVE_GET_VMALLOC_INFO + #ifdef CONFIG_MMU + ++#ifndef HAVE_VMALLOC_INFO + struct vmalloc_info { + unsigned long used; + unsigned long largest_chunk; + }; ++#endif + + typedef void (*get_vmalloc_info_t)(struct vmalloc_info *); + extern get_vmalloc_info_t get_vmalloc_info_fn; +diff --git a/module/spl/spl-kstat.c b/module/spl/spl-kstat.c +index b7e4b94..4e900c0 100644 +--- a/module/spl/spl-kstat.c ++++ b/module/spl/spl-kstat.c +@@ -33,9 +33,12 @@ + #endif + + #define SS_DEBUG_SUBSYS SS_KSTAT ++#ifndef HAVE_PDE_DATA ++#define PDE_DATA(x) (PDE(x)->data) ++#endif + +-static spinlock_t kstat_lock; +-static struct list_head kstat_list; ++static kmutex_t kstat_module_lock; ++static struct list_head kstat_module_list; + static kid_t kstat_id; + + static void +@@ -348,6 +351,47 @@ static struct seq_operations kstat_seq_ops = { + .stop = kstat_seq_stop, + }; + ++static kstat_module_t * ++kstat_find_module(char *name) ++{ ++ kstat_module_t *module; ++ ++ list_for_each_entry(module, &kstat_module_list, ksm_module_list) ++ if (strncmp(name, module->ksm_name, KSTAT_STRLEN) == 0) ++ return (module); ++ ++ return (NULL); ++} ++ ++static kstat_module_t * ++kstat_create_module(char *name) ++{ ++ kstat_module_t *module; ++ struct proc_dir_entry *pde; ++ ++ pde = proc_mkdir(name, proc_spl_kstat); ++ if (pde == NULL) ++ return (NULL); ++ ++ module = kmem_alloc(sizeof (kstat_module_t), KM_SLEEP); ++ module->ksm_proc = pde; ++ strlcpy(module->ksm_name, name, KSTAT_STRLEN+1); ++ INIT_LIST_HEAD(&module->ksm_kstat_list); ++ list_add_tail(&module->ksm_module_list, &kstat_module_list); ++ ++ return (module); ++ ++} ++ ++static void ++kstat_delete_module(kstat_module_t *module) ++{ ++ ASSERT(list_empty(&module->ksm_kstat_list)); ++ remove_proc_entry(module->ksm_name, proc_spl_kstat); ++ list_del(&module->ksm_module_list); ++ kmem_free(module, sizeof(kstat_module_t)); ++} ++ + static int + proc_kstat_open(struct inode *inode, struct file *filp) + { +@@ -359,7 +403,7 @@ proc_kstat_open(struct inode *inode, struct file *filp) + return rc; + + f = filp->private_data; +- f->private = PDE(inode)->data; ++ f->private = PDE_DATA(inode); + + return rc; + } +@@ -390,10 +434,10 @@ __kstat_create(const char *ks_module, int ks_instance, const char *ks_name, + if (ksp == NULL) + return ksp; + +- spin_lock(&kstat_lock); ++ mutex_enter(&kstat_module_lock); + ksp->ks_kid = kstat_id; + kstat_id++; +- spin_unlock(&kstat_lock); ++ mutex_exit(&kstat_module_lock); + + ksp->ks_magic = KS_MAGIC; + mutex_init(&ksp->ks_lock, NULL, MUTEX_DEFAULT, NULL); +@@ -456,71 +500,64 @@ EXPORT_SYMBOL(__kstat_create); + void + __kstat_install(kstat_t *ksp) + { +- struct proc_dir_entry *de_module, *de_name; ++ kstat_module_t *module; + kstat_t *tmp; +- int rc = 0; +- SENTRY; +- +- spin_lock(&kstat_lock); + +- /* Item may only be added to the list once */ +- list_for_each_entry(tmp, &kstat_list, ks_list) { +- if (tmp == ksp) { +- spin_unlock(&kstat_lock); +- SGOTO(out, rc = -EEXIST); +- } +- } ++ ASSERT(ksp); + +- list_add_tail(&ksp->ks_list, &kstat_list); +- spin_unlock(&kstat_lock); ++ mutex_enter(&kstat_module_lock); + +- de_module = proc_dir_entry_find(proc_spl_kstat, ksp->ks_module); +- if (de_module == NULL) { +- de_module = proc_mkdir(ksp->ks_module, proc_spl_kstat); +- if (de_module == NULL) +- SGOTO(out, rc = -EUNATCH); ++ module = kstat_find_module(ksp->ks_module); ++ if (module == NULL) { ++ module = kstat_create_module(ksp->ks_module); ++ if (module == NULL) ++ goto out; + } + +- de_name = create_proc_entry(ksp->ks_name, 0444, de_module); +- if (de_name == NULL) +- SGOTO(out, rc = -EUNATCH); ++ /* ++ * Only one entry by this name per-module, on failure the module ++ * shouldn't be deleted because we know it has at least one entry. ++ */ ++ list_for_each_entry(tmp, &module->ksm_kstat_list, ks_list) ++ if (strncmp(tmp->ks_name, ksp->ks_name, KSTAT_STRLEN) == 0) ++ goto out; ++ ++ list_add_tail(&ksp->ks_list, &module->ksm_kstat_list); + + mutex_enter(&ksp->ks_lock); +- ksp->ks_proc = de_name; +- de_name->proc_fops = &proc_kstat_operations; +- de_name->data = (void *)ksp; ++ ksp->ks_owner = module; ++ ksp->ks_proc = proc_create_data(ksp->ks_name, 0444, ++ module->ksm_proc, &proc_kstat_operations, (void *)ksp); ++ if (ksp->ks_proc == NULL) { ++ list_del_init(&ksp->ks_list); ++ if (list_empty(&module->ksm_kstat_list)) ++ kstat_delete_module(module); ++ } + mutex_exit(&ksp->ks_lock); + out: +- if (rc) { +- spin_lock(&kstat_lock); +- list_del_init(&ksp->ks_list); +- spin_unlock(&kstat_lock); +- } +- +- SEXIT; ++ mutex_exit(&kstat_module_lock); + } + EXPORT_SYMBOL(__kstat_install); + + void + __kstat_delete(kstat_t *ksp) + { +- struct proc_dir_entry *de_module; ++ kstat_module_t *module = ksp->ks_owner; + +- spin_lock(&kstat_lock); +- list_del_init(&ksp->ks_list); +- spin_unlock(&kstat_lock); ++ mutex_enter(&kstat_module_lock); ++ list_del_init(&ksp->ks_list); ++ mutex_exit(&kstat_module_lock); + +- if (ksp->ks_proc) { +- de_module = ksp->ks_proc->parent; +- remove_proc_entry(ksp->ks_name, de_module); ++ if (ksp->ks_proc) { ++ remove_proc_entry(ksp->ks_name, module->ksm_proc); + +- /* Remove top level module directory if it's empty */ +- if (proc_dir_entries(de_module) == 0) +- remove_proc_entry(de_module->name, de_module->parent); ++ /* Remove top level module directory if it's empty */ ++ if (list_empty(&module->ksm_kstat_list)) ++ kstat_delete_module(module); + } + + if (!(ksp->ks_flags & KSTAT_FLAG_VIRTUAL)) +- kmem_free(ksp->ks_data, ksp->ks_data_size); ++ kmem_free(ksp->ks_data, ksp->ks_data_size); + + mutex_destroy(&ksp->ks_lock); + kmem_free(ksp, sizeof(*ksp)); +@@ -533,8 +570,8 @@ int + spl_kstat_init(void) + { + SENTRY; +- spin_lock_init(&kstat_lock); +- INIT_LIST_HEAD(&kstat_list); ++ mutex_init(&kstat_module_lock, NULL, MUTEX_DEFAULT, NULL); ++ INIT_LIST_HEAD(&kstat_module_list); + kstat_id = 0; + SRETURN(0); + } +@@ -543,7 +580,8 @@ void + spl_kstat_fini(void) + { + SENTRY; +- ASSERT(list_empty(&kstat_list)); ++ ASSERT(list_empty(&kstat_module_list)); ++ mutex_destroy(&kstat_module_lock); + SEXIT; + } + +diff --git a/module/spl/spl-proc.c b/module/spl/spl-proc.c +index cd4fa1b..b8379d0 100644 +--- a/module/spl/spl-proc.c ++++ b/module/spl/spl-proc.c +@@ -1120,39 +1120,6 @@ static struct ctl_table spl_root[] = { + { 0 } + }; + +-static int +-proc_dir_entry_match(int len, const char *name, struct proc_dir_entry *de) +-{ +- if (de->namelen != len) +- return 0; +- +- return !memcmp(name, de->name, len); +-} +- +-struct proc_dir_entry * +-proc_dir_entry_find(struct proc_dir_entry *root, const char *str) +-{ +- struct proc_dir_entry *de; +- +- for (de = root->subdir; de; de = de->next) +- if (proc_dir_entry_match(strlen(str), str, de)) +- return de; +- +- return NULL; +-} +- +-int +-proc_dir_entries(struct proc_dir_entry *root) +-{ +- struct proc_dir_entry *de; +- int i = 0; +- +- for (de = root->subdir; de; de = de->next) +- i++; +- +- return i; +-} +- + int + spl_proc_init(void) + { +@@ -1174,11 +1141,11 @@ spl_proc_init(void) + if (proc_spl_kmem == NULL) + SGOTO(out, rc = -EUNATCH); + +- proc_spl_kmem_slab = create_proc_entry("slab", 0444, proc_spl_kmem); ++ proc_spl_kmem_slab = proc_create_data("slab", 0444, ++ proc_spl_kmem, &proc_slab_operations, NULL); + if (proc_spl_kmem_slab == NULL) + SGOTO(out, rc = -EUNATCH); + +- proc_spl_kmem_slab->proc_fops = &proc_slab_operations; + #endif /* DEBUG_KMEM */ + + proc_spl_kstat = proc_mkdir("kstat", proc_spl); +diff --git a/module/splat/splat-atomic.c b/module/splat/splat-atomic.c +index df3b38f..f702196 100644 +--- a/module/splat/splat-atomic.c ++++ b/module/splat/splat-atomic.c +@@ -26,6 +26,7 @@ + + #include <sys/atomic.h> + #include <sys/thread.h> ++#include <linux/slab.h> + #include "splat-internal.h" + + #define SPLAT_ATOMIC_NAME "atomic" +diff --git a/module/splat/splat-thread.c b/module/splat/splat-thread.c +index a1e70db..e55acd0 100644 +--- a/module/splat/splat-thread.c ++++ b/module/splat/splat-thread.c +@@ -26,6 +26,7 @@ + + #include <sys/thread.h> + #include <sys/random.h> ++#include <linux/slab.h> + #include "splat-internal.h" + + #define SPLAT_THREAD_NAME "thread" +diff --git a/module/splat/splat-time.c b/module/splat/splat-time.c +index ca60c45..cd513c9 100644 +--- a/module/splat/splat-time.c ++++ b/module/splat/splat-time.c +@@ -25,6 +25,7 @@ + \*****************************************************************************/ + + #include <sys/time.h> ++#include <linux/slab.h> + #include "splat-internal.h" + + #define SPLAT_TIME_NAME "time" |