Print this page
5056 ZFS deadlock on db_mtx and dn_holds
Reviewed by: Will Andrews <willa@spectralogic.com>
Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Approved by: Dan McDonald <danmcd@omniti.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/zfs/sys/dmu.h
          +++ new/usr/src/uts/common/fs/zfs/sys/dmu.h
↓ open down ↓ 18 lines elided ↑ open up ↑
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   * Copyright (c) 2011, 2014 by Delphix. All rights reserved.
  25   25   * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
  26   26   * Copyright (c) 2012, Joyent, Inc. All rights reserved.
  27   27   * Copyright 2013 DEY Storage Systems, Inc.
  28   28   * Copyright 2014 HybridCluster. All rights reserved.
       29 + * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
  29   30   */
  30   31  
  31   32  /* Portions Copyright 2010 Robert Milkowski */
  32   33  
  33   34  #ifndef _SYS_DMU_H
  34   35  #define _SYS_DMU_H
  35   36  
  36   37  /*
  37   38   * This file describes the interface that the DMU provides for its
  38   39   * consumers.
  39   40   *
  40   41   * The DMU also interacts with the SPA.  That interface is described in
  41   42   * dmu_spa.h.
  42   43   */
  43   44  
       45 +#include <sys/zfs_context.h>
  44   46  #include <sys/inttypes.h>
  45      -#include <sys/types.h>
  46      -#include <sys/param.h>
  47   47  #include <sys/cred.h>
  48      -#include <sys/time.h>
  49   48  #include <sys/fs/zfs.h>
  50   49  
  51   50  #ifdef  __cplusplus
  52   51  extern "C" {
  53   52  #endif
  54   53  
  55   54  struct uio;
  56   55  struct xuio;
  57   56  struct page;
  58   57  struct vnode;
↓ open down ↓ 225 lines elided ↑ open up ↑
 284  283  int dsl_dataset_rename_snapshot(const char *fsname,
 285  284      const char *oldsnapname, const char *newsnapname, boolean_t recursive);
 286  285  
 287  286  typedef struct dmu_buf {
 288  287          uint64_t db_object;             /* object that this buffer is part of */
 289  288          uint64_t db_offset;             /* byte offset in this object */
 290  289          uint64_t db_size;               /* size of buffer in bytes */
 291  290          void *db_data;                  /* data in buffer */
 292  291  } dmu_buf_t;
 293  292  
 294      -typedef void dmu_buf_evict_func_t(struct dmu_buf *db, void *user_ptr);
 295      -
 296  293  /*
 297  294   * The names of zap entries in the DIRECTORY_OBJECT of the MOS.
 298  295   */
 299  296  #define DMU_POOL_DIRECTORY_OBJECT       1
 300  297  #define DMU_POOL_CONFIG                 "config"
 301  298  #define DMU_POOL_FEATURES_FOR_WRITE     "features_for_write"
 302  299  #define DMU_POOL_FEATURES_FOR_READ      "features_for_read"
 303  300  #define DMU_POOL_FEATURE_DESCRIPTIONS   "feature_descriptions"
 304  301  #define DMU_POOL_FEATURE_ENABLED_TXG    "feature_enabled_txg"
 305  302  #define DMU_POOL_ROOT_DATASET           "root_dataset"
↓ open down ↓ 165 lines elided ↑ open up ↑
 471  468   *
 472  469   * dmu_buf_rele_array releases the hold on an array of dmu_buf_t*'s, and
 473  470   * frees the array.  The hold on the array of buffers MUST be released
 474  471   * with dmu_buf_rele_array.  You can NOT release the hold on each buffer
 475  472   * individually with dmu_buf_rele.
 476  473   */
 477  474  int dmu_buf_hold_array_by_bonus(dmu_buf_t *db, uint64_t offset,
 478  475      uint64_t length, int read, void *tag, int *numbufsp, dmu_buf_t ***dbpp);
 479  476  void dmu_buf_rele_array(dmu_buf_t **, int numbufs, void *tag);
 480  477  
      478 +typedef void dmu_buf_evict_func_t(void *user_ptr);
      479 +
 481  480  /*
 482      - * Returns NULL on success, or the existing user ptr if it's already
 483      - * been set.
      481 + * A DMU buffer user object may be associated with a dbuf for the
      482 + * duration of its lifetime.  This allows the user of a dbuf (client)
      483 + * to attach private data to a dbuf (e.g. in-core only data such as a
      484 + * dnode_children_t, zap_t, or zap_leaf_t) and be optionally notified
      485 + * when that dbuf has been evicted.  Clients typically respond to the
      486 + * eviction notification by freeing their private data, thus ensuring
      487 + * the same lifetime for both dbuf and private data.
 484  488   *
 485      - * user_ptr is for use by the user and can be obtained via dmu_buf_get_user().
      489 + * The mapping from a dmu_buf_user_t to any client private data is the
      490 + * client's responsibility.  All current consumers of the API with private
      491 + * data embed a dmu_buf_user_t as the first member of the structure for
      492 + * their private data.  This allows conversions between the two types
      493 + * with a simple cast.  Since the DMU buf user API never needs access
      494 + * to the private data, other strategies can be employed if necessary
      495 + * or convenient for the client (e.g. using container_of() to do the
      496 + * conversion for private data that cannot have the dmu_buf_user_t as
      497 + * its first member).
 486  498   *
 487      - * If non-NULL, pageout func will be called when this buffer is being
 488      - * excised from the cache, so that you can clean up the data structure
 489      - * pointed to by user_ptr.
      499 + * Eviction callbacks are executed without the dbuf mutex held or any
      500 + * other type of mechanism to guarantee that the dbuf is still available.
      501 + * For this reason, users must assume the dbuf has already been freed
      502 + * and not reference the dbuf from the callback context.
 490  503   *
 491      - * dmu_evict_user() will call the pageout func for all buffers in a
 492      - * objset with a given pageout func.
      504 + * Users requesting "immediate eviction" are notified as soon as the dbuf
      505 + * is only referenced by dirty records (dirties == holds).  Otherwise the
      506 + * notification occurs after eviction processing for the dbuf begins.
 493  507   */
 494      -void *dmu_buf_set_user(dmu_buf_t *db, void *user_ptr,
 495      -    dmu_buf_evict_func_t *pageout_func);
      508 +typedef struct dmu_buf_user {
      509 +        /*
      510 +         * Asynchronous user eviction callback state.
      511 +         */
      512 +        taskq_ent_t     dbu_tqent;
      513 +
      514 +        /* This instance's eviction function pointer. */
      515 +        dmu_buf_evict_func_t *dbu_evict_func;
      516 +#ifdef ZFS_DEBUG
      517 +        /*
      518 +         * Pointer to user's dbuf pointer.  NULL for clients that do
      519 +         * not associate a dbuf with their user data.
      520 +         *
      521 +         * The dbuf pointer is cleared upon eviction so as to catch
      522 +         * use-after-evict bugs in clients.
      523 +         */
      524 +        dmu_buf_t **dbu_clear_on_evict_dbufp;
      525 +#endif
      526 +} dmu_buf_user_t;
      527 +
 496  528  /*
 497      - * set_user_ie is the same as set_user, but request immediate eviction
 498      - * when hold count goes to zero.
      529 + * Initialize the given dmu_buf_user_t instance with the eviction function
      530 + * evict_func, to be called when the user is evicted.
      531 + *
      532 + * NOTE: This function should only be called once on a given dmu_buf_user_t.
      533 + *       To allow enforcement of this, dbu must already be zeroed on entry.
 499  534   */
 500      -void *dmu_buf_set_user_ie(dmu_buf_t *db, void *user_ptr,
 501      -    dmu_buf_evict_func_t *pageout_func);
 502      -void *dmu_buf_update_user(dmu_buf_t *db_fake, void *old_user_ptr,
 503      -    void *user_ptr, dmu_buf_evict_func_t *pageout_func);
 504      -void dmu_evict_user(objset_t *os, dmu_buf_evict_func_t *func);
      535 +#ifdef __lint
      536 +/* Very ugly, but it beats issuing suppression directives in many Makefiles. */
      537 +extern void
      538 +dmu_buf_init_user(dmu_buf_user_t *dbu, dmu_buf_evict_func_t *evict_func,
      539 +    dmu_buf_t **clear_on_evict_dbufp);
      540 +#else /* __lint */
      541 +inline void
      542 +dmu_buf_init_user(dmu_buf_user_t *dbu, dmu_buf_evict_func_t *evict_func,
      543 +    dmu_buf_t **clear_on_evict_dbufp)
      544 +{
      545 +        ASSERT(dbu->dbu_evict_func == NULL);
      546 +        ASSERT(evict_func != NULL);
      547 +        dbu->dbu_evict_func = evict_func;
      548 +#ifdef ZFS_DEBUG
      549 +        dbu->dbu_clear_on_evict_dbufp = clear_on_evict_dbufp;
      550 +#endif
      551 +}
      552 +#endif /* __lint */
 505  553  
 506  554  /*
 507      - * Returns the user_ptr set with dmu_buf_set_user(), or NULL if not set.
      555 + * Attach user data to a dbuf and mark it for normal (when the dbuf's
      556 + * data is cleared or its reference count goes to zero) eviction processing.
      557 + *
      558 + * Returns NULL on success, or the existing user if another user currently
      559 + * owns the buffer.
 508  560   */
      561 +void *dmu_buf_set_user(dmu_buf_t *db, dmu_buf_user_t *user);
      562 +
      563 +/*
      564 + * Attach user data to a dbuf and mark it for immediate (its dirty and
      565 + * reference counts are equal) eviction processing.
      566 + *
      567 + * Returns NULL on success, or the existing user if another user currently
      568 + * owns the buffer.
      569 + */
      570 +void *dmu_buf_set_user_ie(dmu_buf_t *db, dmu_buf_user_t *user);
      571 +
      572 +/*
      573 + * Replace the current user of a dbuf.
      574 + *
      575 + * If given the current user of a dbuf, replaces the dbuf's user with
      576 + * "new_user" and returns the user data pointer that was replaced.
      577 + * Otherwise returns the current, and unmodified, dbuf user pointer.
      578 + */
      579 +void *dmu_buf_replace_user(dmu_buf_t *db,
      580 +    dmu_buf_user_t *old_user, dmu_buf_user_t *new_user);
      581 +
      582 +/*
      583 + * Remove the specified user data for a DMU buffer.
      584 + *
      585 + * Returns the user that was removed on success, or the current user if
      586 + * another user currently owns the buffer.
      587 + */
      588 +void *dmu_buf_remove_user(dmu_buf_t *db, dmu_buf_user_t *user);
      589 +
      590 +/*
      591 + * Returns the user data (dmu_buf_user_t *) associated with this dbuf.
      592 + */
 509  593  void *dmu_buf_get_user(dmu_buf_t *db);
 510  594  
      595 +/* Block until any in-progress dmu buf user evictions complete. */
      596 +void dmu_buf_user_evict_wait(void);
      597 +
 511  598  /*
 512  599   * Returns the blkptr associated with this dbuf, or NULL if not set.
 513  600   */
 514  601  struct blkptr *dmu_buf_get_blkptr(dmu_buf_t *db);
 515  602  
 516  603  /*
 517  604   * Indicate that you are going to modify the buffer's data (db_data).
 518  605   *
 519  606   * The transaction (tx) must be assigned to a txg (ie. you've called
 520  607   * dmu_tx_assign()).  The buffer's object must be held in the tx
↓ open down ↓ 307 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX