]> git.proxmox.com Git - mirror_zfs.git/blobdiff - include/sys/dbuf.h
dmu: Allow buffer fills to fail
[mirror_zfs.git] / include / sys / dbuf.h
index f6880cdb28d6bdfce0612874691681fa824a6ac5..3808a04cba8011f517437baec1e83b66c3542f27 100644 (file)
@@ -6,7 +6,7 @@
  * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
  * See the License for the specific language governing permissions
  * and limitations under the License.
  *
@@ -20,7 +20,7 @@
  */
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2018 by Delphix. All rights reserved.
+ * Copyright (c) 2012, 2020 by Delphix. All rights reserved.
  * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
  * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
  */
@@ -34,7 +34,7 @@
 #include <sys/zio.h>
 #include <sys/arc.h>
 #include <sys/zfs_context.h>
-#include <sys/refcount.h>
+#include <sys/zfs_refcount.h>
 #include <sys/zrlock.h>
 #include <sys/multilist.h>
 
@@ -55,26 +55,31 @@ extern "C" {
 #define        DB_RF_NEVERWAIT         (1 << 4)
 #define        DB_RF_CACHED            (1 << 5)
 #define        DB_RF_NO_DECRYPT        (1 << 6)
+#define        DB_RF_PARTIAL_FIRST     (1 << 7)
+#define        DB_RF_PARTIAL_MORE      (1 << 8)
 
 /*
  * The simplified state transition diagram for dbufs looks like:
  *
- *             +----> READ ----+
- *             |               |
- *             |               V
- *  (alloc)-->UNCACHED      CACHED-->EVICTING-->(free)
- *             |               ^        ^
- *             |               |        |
- *             +----> FILL ----+        |
- *             |                        |
- *             |                        |
- *             +--------> NOFILL -------+
+ *                  +--> READ --+
+ *                  |           |
+ *                  |           V
+ *  (alloc)-->UNCACHED       CACHED-->EVICTING-->(free)
+ *             ^    |           ^        ^
+ *             |    |           |        |
+ *             |    +--> FILL --+        |
+ *             |    |                    |
+ *             |    |                    |
+ *             |    +------> NOFILL -----+
+ *             |               |
+ *             +---------------+
  *
  * DB_SEARCH is an invalid state for a dbuf. It is used by dbuf_free_range
  * to find all dbufs in a range of a dnode and must be less than any other
  * dbuf_states_t (see comment on dn_dbufs in dnode.h).
  */
 typedef enum dbuf_states {
+       DB_MARKER = -2,
        DB_SEARCH = -1,
        DB_UNCACHED,
        DB_FILL,
@@ -130,6 +135,16 @@ typedef struct dbuf_dirty_record {
        /* list link for dbuf dirty records */
        list_node_t dr_dbuf_node;
 
+       /*
+        * The dnode we are part of.  Note that the dnode can not be moved or
+        * evicted due to the hold that's added by dnode_setdirty() or
+        * dmu_objset_sync_dnodes(), and released by dnode_rele_task() or
+        * userquota_updates_task().  This hold is necessary for
+        * dirty_lightweight_leaf-type dirty records, which don't have a hold
+        * on a dbuf.
+        */
+       dnode_t *dr_dnode;
+
        /* pointer to parent dirty record */
        struct dbuf_dirty_record *dr_parent;
 
@@ -160,6 +175,7 @@ typedef struct dbuf_dirty_record {
                        override_states_t dr_override_state;
                        uint8_t dr_copies;
                        boolean_t dr_nopwrite;
+                       boolean_t dr_brtwrite;
                        boolean_t dr_has_raw_params;
 
                        /*
@@ -171,6 +187,17 @@ typedef struct dbuf_dirty_record {
                        uint8_t dr_iv[ZIO_DATA_IV_LEN];
                        uint8_t dr_mac[ZIO_DATA_MAC_LEN];
                } dl;
+               struct dirty_lightweight_leaf {
+                       /*
+                        * This dirty record refers to a leaf (level=0)
+                        * block, whose dbuf has not been instantiated for
+                        * performance reasons.
+                        */
+                       uint64_t dr_blkid;
+                       abd_t *dr_abd;
+                       zio_prop_t dr_props;
+                       zio_flag_t dr_flags;
+               } dll;
        } dt;
 } dbuf_dirty_record_t;
 
@@ -206,6 +233,13 @@ typedef struct dmu_buf_impl {
         */
        struct dmu_buf_impl *db_hash_next;
 
+       /*
+        * Our link on the owner dnodes's dn_dbufs list.
+        * Protected by its dn_dbufs_mtx.  Should be on the same cache line
+        * as db_level and db_blkid for the best avl_add() performance.
+        */
+       avl_node_t db_link;
+
        /* our block number */
        uint64_t db_blkid;
 
@@ -260,18 +294,14 @@ typedef struct dmu_buf_impl {
        /* List of dirty records for the buffer sorted newest to oldest. */
        list_t db_dirty_records;
 
-       /*
-        * Our link on the owner dnodes's dn_dbufs list.
-        * Protected by its dn_dbufs_mtx.
-        */
-       avl_node_t db_link;
-
        /* Link in dbuf_cache or dbuf_metadata_cache */
        multilist_node_t db_cache_link;
 
        /* Tells us which dbuf cache this dbuf is in, if any */
        dbuf_cached_state_t db_caching_status;
 
+       uint64_t db_hash;
+
        /* Data which is unique to data (leaf) blocks: */
 
        /* User callback information. */
@@ -297,17 +327,23 @@ typedef struct dmu_buf_impl {
        uint8_t db_pending_evict;
 
        uint8_t db_dirtycnt;
+
+       /* The buffer was partially read.  More reads may follow. */
+       uint8_t db_partial_read;
 } dmu_buf_impl_t;
 
-/* Note: the dbuf hash table is exposed only for the mdb module */
-#define        DBUF_MUTEXES 8192
-#define        DBUF_HASH_MUTEX(h, idx) (&(h)->hash_mutexes[(idx) & (DBUF_MUTEXES-1)])
+#define        DBUF_HASH_MUTEX(h, idx) \
+       (&(h)->hash_mutexes[(idx) & ((h)->hash_mutex_mask)])
+
 typedef struct dbuf_hash_table {
        uint64_t hash_table_mask;
+       uint64_t hash_mutex_mask;
        dmu_buf_impl_t **hash_table;
-       kmutex_t hash_mutexes[DBUF_MUTEXES];
+       kmutex_t *hash_mutexes;
 } dbuf_hash_table_t;
 
+typedef void (*dbuf_prefetch_fn)(void *, uint64_t, uint64_t, boolean_t);
+
 uint64_t dbuf_whichblock(const struct dnode *di, const int64_t level,
     const uint64_t offset);
 
@@ -316,46 +352,59 @@ int dbuf_spill_set_blksz(dmu_buf_t *db, uint64_t blksz, dmu_tx_t *tx);
 
 void dbuf_rm_spill(struct dnode *dn, dmu_tx_t *tx);
 
-dmu_buf_impl_t *dbuf_hold(struct dnode *dn, uint64_t blkid, void *tag);
+dmu_buf_impl_t *dbuf_hold(struct dnode *dn, uint64_t blkid, const void *tag);
 dmu_buf_impl_t *dbuf_hold_level(struct dnode *dn, int level, uint64_t blkid,
-    void *tag);
+    const void *tag);
 int dbuf_hold_impl(struct dnode *dn, uint8_t level, uint64_t blkid,
     boolean_t fail_sparse, boolean_t fail_uncached,
-    void *tag, dmu_buf_impl_t **dbp);
+    const void *tag, dmu_buf_impl_t **dbp);
 
-void dbuf_prefetch(struct dnode *dn, int64_t level, uint64_t blkid,
+int dbuf_prefetch_impl(struct dnode *dn, int64_t level, uint64_t blkid,
+    zio_priority_t prio, arc_flags_t aflags, dbuf_prefetch_fn cb,
+    void *arg);
+int dbuf_prefetch(struct dnode *dn, int64_t level, uint64_t blkid,
     zio_priority_t prio, arc_flags_t aflags);
 
-void dbuf_add_ref(dmu_buf_impl_t *db, void *tag);
+void dbuf_add_ref(dmu_buf_impl_t *db, const void *tag);
 boolean_t dbuf_try_add_ref(dmu_buf_t *db, objset_t *os, uint64_t obj,
-    uint64_t blkid, void *tag);
+    uint64_t blkid, const void *tag);
 uint64_t dbuf_refcount(dmu_buf_impl_t *db);
 
-void dbuf_rele(dmu_buf_impl_t *db, void *tag);
-void dbuf_rele_and_unlock(dmu_buf_impl_t *db, void *tag, boolean_t evicting);
+void dbuf_rele(dmu_buf_impl_t *db, const void *tag);
+void dbuf_rele_and_unlock(dmu_buf_impl_t *db, const void *tag,
+    boolean_t evicting);
 
 dmu_buf_impl_t *dbuf_find(struct objset *os, uint64_t object, uint8_t level,
-    uint64_t blkid);
+    uint64_t blkid, uint64_t *hash_out);
 
 int dbuf_read(dmu_buf_impl_t *db, zio_t *zio, uint32_t flags);
+void dmu_buf_will_clone(dmu_buf_t *db, dmu_tx_t *tx);
 void dmu_buf_will_not_fill(dmu_buf_t *db, dmu_tx_t *tx);
-void dmu_buf_will_fill(dmu_buf_t *db, dmu_tx_t *tx);
-void dmu_buf_fill_done(dmu_buf_t *db, dmu_tx_t *tx);
+void dmu_buf_will_fill(dmu_buf_t *db, dmu_tx_t *tx, boolean_t canfail);
+boolean_t dmu_buf_fill_done(dmu_buf_t *db, dmu_tx_t *tx, boolean_t failed);
 void dbuf_assign_arcbuf(dmu_buf_impl_t *db, arc_buf_t *buf, dmu_tx_t *tx);
 dbuf_dirty_record_t *dbuf_dirty(dmu_buf_impl_t *db, dmu_tx_t *tx);
+dbuf_dirty_record_t *dbuf_dirty_lightweight(dnode_t *dn, uint64_t blkid,
+    dmu_tx_t *tx);
+boolean_t dbuf_undirty(dmu_buf_impl_t *db, dmu_tx_t *tx);
 arc_buf_t *dbuf_loan_arcbuf(dmu_buf_impl_t *db);
 void dmu_buf_write_embedded(dmu_buf_t *dbuf, void *data,
     bp_embedded_type_t etype, enum zio_compress comp,
     int uncompressed_size, int compressed_size, int byteorder, dmu_tx_t *tx);
 
+int dmu_lightweight_write_by_dnode(dnode_t *dn, uint64_t offset, abd_t *abd,
+    const struct zio_prop *zp, zio_flag_t flags, dmu_tx_t *tx);
+
 void dmu_buf_redact(dmu_buf_t *dbuf, dmu_tx_t *tx);
 void dbuf_destroy(dmu_buf_impl_t *db);
 
 void dbuf_unoverride(dbuf_dirty_record_t *dr);
 void dbuf_sync_list(list_t *list, int level, dmu_tx_t *tx);
 void dbuf_release_bp(dmu_buf_impl_t *db);
-db_lock_type_t dmu_buf_lock_parent(dmu_buf_impl_t *db, krw_t rw, void *tag);
-void dmu_buf_unlock_parent(dmu_buf_impl_t *db, db_lock_type_t type, void *tag);
+db_lock_type_t dmu_buf_lock_parent(dmu_buf_impl_t *db, krw_t rw,
+    const void *tag);
+void dmu_buf_unlock_parent(dmu_buf_impl_t *db, db_lock_type_t type,
+    const void *tag);
 
 void dbuf_free_range(struct dnode *dn, uint64_t start, uint64_t end,
     struct dmu_tx *);
@@ -410,16 +459,7 @@ dbuf_find_dirty_eq(dmu_buf_impl_t *db, uint64_t txg)
        (dbuf_is_metadata(_db) &&                                       \
        ((_db)->db_objset->os_primary_cache == ZFS_CACHE_METADATA)))
 
-#define        DBUF_IS_L2CACHEABLE(_db)                                        \
-       ((_db)->db_objset->os_secondary_cache == ZFS_CACHE_ALL ||       \
-       (dbuf_is_metadata(_db) &&                                       \
-       ((_db)->db_objset->os_secondary_cache == ZFS_CACHE_METADATA)))
-
-#define        DNODE_LEVEL_IS_L2CACHEABLE(_dn, _level)                         \
-       ((_dn)->dn_objset->os_secondary_cache == ZFS_CACHE_ALL ||       \
-       (((_level) > 0 ||                                               \
-       DMU_OT_IS_METADATA((_dn)->dn_handle->dnh_dnode->dn_type)) &&    \
-       ((_dn)->dn_objset->os_secondary_cache == ZFS_CACHE_METADATA)))
+boolean_t dbuf_is_l2cacheable(dmu_buf_impl_t *db);
 
 #ifdef ZFS_DEBUG
 
@@ -433,7 +473,7 @@ dbuf_find_dirty_eq(dmu_buf_impl_t *db, uint64_t txg)
        char __db_buf[32]; \
        uint64_t __db_obj = (dbuf)->db.db_object; \
        if (__db_obj == DMU_META_DNODE_OBJECT) \
-               (void) strcpy(__db_buf, "mdn"); \
+               (void) strlcpy(__db_buf, "mdn", sizeof (__db_buf));     \
        else \
                (void) snprintf(__db_buf, sizeof (__db_buf), "%lld", \
                    (u_longlong_t)__db_obj); \
@@ -442,7 +482,7 @@ dbuf_find_dirty_eq(dmu_buf_impl_t *db, uint64_t txg)
            __db_buf, (dbuf)->db_level, \
            (u_longlong_t)(dbuf)->db_blkid, __VA_ARGS__); \
        } \
-_NOTE(CONSTCOND) } while (0)
+} while (0)
 
 #define        dprintf_dbuf_bp(db, bp, fmt, ...) do {                  \
        if (zfs_flags & ZFS_DEBUG_DPRINTF) {                    \
@@ -451,7 +491,7 @@ _NOTE(CONSTCOND) } while (0)
        dprintf_dbuf(db, fmt " %s\n", __VA_ARGS__, __blkbuf);   \
        kmem_free(__blkbuf, BP_SPRINTF_LEN);                    \
        }                                                       \
-_NOTE(CONSTCOND) } while (0)
+} while (0)
 
 #define        DBUF_VERIFY(db) dbuf_verify(db)