]> git.proxmox.com Git - mirror_spl-debian.git/commit - include/sys/kstat.h
Make kstat.ks_update() callback atomic
authorBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 23 Oct 2012 16:17:29 +0000 (09:17 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 23 Oct 2012 16:36:19 +0000 (09:36 -0700)
commit71c9f0b00307e6ee703eef9eba91e7640731c458
tree22829d5df4c548f911338dc4e981b9389322296a
parent1e0c2c2ccfb720be81051a43c405fad173775963
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>
include/sys/kstat.h
module/spl/spl-kstat.c