diff options
author | Chunwei Chen <[email protected]> | 2016-04-11 14:53:48 -0700 |
---|---|---|
committer | Ned Bass <[email protected]> | 2016-09-05 16:07:08 -0700 |
commit | 703c9f5893f6b137b723ed819d61bc5fa9140954 (patch) | |
tree | 48b00ec895205bb508215a2f031eed69d1a796c9 /include/sys/zfs_rlock.h | |
parent | 2ea36ad824f97c8fbe9cabc171fb88ac2430798b (diff) |
Remove dummy znode from zvol_state
struct zvol_state contains a dummy znode, which is around 1KB on x64,
only for zfs_range_lock. But in reality, other than z_range_lock and
z_range_avl, zfs_range_lock only need znode on regular file, which
means we add 1KB on a structure and gain nothing.
In this patch, we remove the dummy znode for zvol_state. In order to
do that, we also need to refactor zfs_range_lock a bit. We move
z_range_lock and z_range_avl pair out of znode_t to form zfs_rlock_t.
This new struct replaces znode_t as the main handle inside the range
lock functions.
We also add pointers to z_size, z_blksz, and z_max_blksz so range lock
code doesn't depend on znode_t. This allows non-ZPL consumers like
Lustre to use the range locks with their equivalent znode_t structure.
Signed-off-by: Chunwei Chen <[email protected]>
Signed-off-by: Boris Protopopov <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #4510
Diffstat (limited to 'include/sys/zfs_rlock.h')
-rw-r--r-- | include/sys/zfs_rlock.h | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/include/sys/zfs_rlock.h b/include/sys/zfs_rlock.h index ea5e40369..5322f3bc7 100644 --- a/include/sys/zfs_rlock.h +++ b/include/sys/zfs_rlock.h @@ -32,7 +32,9 @@ extern "C" { #ifdef _KERNEL -#include <sys/zfs_znode.h> +#include <sys/list.h> +#include <sys/avl.h> +#include <sys/condvar.h> typedef enum { RL_READER, @@ -40,8 +42,16 @@ typedef enum { RL_APPEND } rl_type_t; +typedef struct zfs_rlock { + kmutex_t zr_mutex; /* protects changes to zr_avl */ + avl_tree_t zr_avl; /* avl tree of range locks */ + uint64_t *zr_size; /* points to znode->z_size */ + uint_t *zr_blksz; /* points to znode->z_blksz */ + uint64_t *zr_max_blksz; /* points to zsb->z_max_blksz */ +} zfs_rlock_t; + typedef struct rl { - znode_t *r_zp; /* znode this lock applies to */ + zfs_rlock_t *r_zrl; avl_node_t r_node; /* avl node link */ uint64_t r_off; /* file range offset */ uint64_t r_len; /* file range length */ @@ -61,7 +71,8 @@ typedef struct rl { * is converted to RL_WRITER that specified to lock from the start of the * end of file. Returns the range lock structure. */ -rl_t *zfs_range_lock(znode_t *zp, uint64_t off, uint64_t len, rl_type_t type); +rl_t *zfs_range_lock(zfs_rlock_t *zrl, uint64_t off, uint64_t len, + rl_type_t type); /* Unlock range and destroy range lock structure. */ void zfs_range_unlock(rl_t *rl); @@ -78,6 +89,23 @@ void zfs_range_reduce(rl_t *rl, uint64_t off, uint64_t len); */ int zfs_range_compare(const void *arg1, const void *arg2); +static inline void +zfs_rlock_init(zfs_rlock_t *zrl) +{ + mutex_init(&zrl->zr_mutex, NULL, MUTEX_DEFAULT, NULL); + avl_create(&zrl->zr_avl, zfs_range_compare, + sizeof (rl_t), offsetof(rl_t, r_node)); + zrl->zr_size = NULL; + zrl->zr_blksz = NULL; + zrl->zr_max_blksz = NULL; +} + +static inline void +zfs_rlock_destroy(zfs_rlock_t *zrl) +{ + avl_destroy(&zrl->zr_avl); + mutex_destroy(&zrl->zr_mutex); +} #endif /* _KERNEL */ #ifdef __cplusplus |