diff options
author | Brian Behlendorf <[email protected]> | 2012-10-23 09:17:29 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2012-10-23 09:36:19 -0700 |
commit | 71c9f0b00307e6ee703eef9eba91e7640731c458 (patch) | |
tree | 22829d5df4c548f911338dc4e981b9389322296a /include | |
parent | 1e0c2c2ccfb720be81051a43c405fad173775963 (diff) |
Make kstat.ks_update() callback atomic
Move the kstat ks_update() callback under the ks_lock. This
enables dynamically sized kstats without modification to the
kstat API.
* Create a kstat with the KSTAT_FLAG_VIRTUAL flag.
* Register a ->ks_update() callback which does:
o Frees any existing ks_data buffer.
o Set ks_data_size to the kstat array size.
o Set ks_data to an allocated buffer of size ks_data_size
o Populate the array of buffers with the required data.
The buffer allocated in the ks_update() callback is guaranteed
to remain allocated and valid while the proc sequence handler
iterates over the buffer. The lock will not be dropped until
kstat_seq_stop() function is run making it safe for concurrent
access. To allow the ks_update() callback to perform memory
allocations the lock was changed to a mutex.
Signed-off-by: Brian Behlendorf <[email protected]>
Diffstat (limited to 'include')
-rw-r--r-- | include/sys/kstat.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/include/sys/kstat.h b/include/sys/kstat.h index e4c88c82b..45386d49a 100644 --- a/include/sys/kstat.h +++ b/include/sys/kstat.h @@ -30,6 +30,7 @@ #include <sys/types.h> #include <sys/time.h> #include <sys/kmem.h> +#include <sys/mutex.h> #define KSTAT_STRLEN 31 @@ -98,7 +99,7 @@ typedef struct kstat_s { struct proc_dir_entry *ks_proc; /* proc linkage */ kstat_update_t *ks_update; /* dynamic updates */ void *ks_private; /* private data */ - spinlock_t ks_lock; /* kstat data lock */ + kmutex_t ks_lock; /* kstat data lock */ struct list_head ks_list; /* kstat linkage */ } kstat_t; |