mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 10:37:35 +03:00
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 <behlendorf1@llnl.gov>
This commit is contained in:
+2
-1
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user