aboutsummaryrefslogtreecommitdiffstats
path: root/module/zfs/zfs_rlock.c
diff options
context:
space:
mode:
authorMatthew Macy <[email protected]>2019-11-06 10:54:25 -0800
committerBrian Behlendorf <[email protected]>2019-11-06 10:54:25 -0800
commit27ece2ee4d9a3e814edfc6ff7cbbc56537d94b59 (patch)
treea3bdd269a93adec8d0904544a807a3d1ccc848ba /module/zfs/zfs_rlock.c
parent1c47c2c42cdc809ce998d7a5b7b0df145201ad89 (diff)
Move platform specific parts of zfs_znode.h to platform code
Some of the znode fields are different and functions consuming an inode don't exist on FreeBSD. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Jorgen Lundman <[email protected]> Signed-off-by: Matt Macy <[email protected]> Closes #9536
Diffstat (limited to 'module/zfs/zfs_rlock.c')
-rw-r--r--module/zfs/zfs_rlock.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/module/zfs/zfs_rlock.c b/module/zfs/zfs_rlock.c
index 3158f4320..091b37f9f 100644
--- a/module/zfs/zfs_rlock.c
+++ b/module/zfs/zfs_rlock.c
@@ -38,6 +38,20 @@
* rangelock_reduce(lr, off, len); // optional
* rangelock_exit(lr);
*
+ * Range locking rules
+ * --------------------
+ * 1. When truncating a file (zfs_create, zfs_setattr, zfs_space) the whole
+ * file range needs to be locked as RL_WRITER. Only then can the pages be
+ * freed etc and zp_size reset. zp_size must be set within range lock.
+ * 2. For writes and punching holes (zfs_write & zfs_space) just the range
+ * being written or freed needs to be locked as RL_WRITER.
+ * Multiple writes at the end of the file must coordinate zp_size updates
+ * to ensure data isn't lost. A compare and swap loop is currently used
+ * to ensure the file size is at least the offset last written.
+ * 3. For reads (zfs_read, zfs_get_data & zfs_putapage) just the range being
+ * read needs to be locked as RL_READER. A check against zp_size can then
+ * be made for reading beyond end of file.
+ *
* AVL tree
* --------
* An AVL tree is used to maintain the state of the existing ranges
@@ -99,6 +113,7 @@
#include <sys/zfs_context.h>
#include <sys/zfs_rlock.h>
+
/*
* AVL comparison function used to order range locks
* Locks are ordered on the start offset of the range.