* Cycle through L2ARC devices. This is how L2ARC load balances. * If a device is returned, this also returns holding the spa config lock. */
| 8103 | * If a device is returned, this also returns holding the spa config lock. |
| 8104 | */ |
| 8105 | static l2arc_dev_t * |
| 8106 | l2arc_dev_get_next(void) |
| 8107 | { |
| 8108 | l2arc_dev_t *first, *next = NULL; |
| 8109 | |
| 8110 | /* |
| 8111 | * Lock out the removal of spas (spa_namespace_lock), then removal |
| 8112 | * of cache devices (l2arc_dev_mtx). Once a device has been selected, |
| 8113 | * both locks will be dropped and a spa config lock held instead. |
| 8114 | */ |
| 8115 | mutex_enter(&spa_namespace_lock); |
| 8116 | mutex_enter(&l2arc_dev_mtx); |
| 8117 | |
| 8118 | /* if there are no vdevs, there is nothing to do */ |
| 8119 | if (l2arc_ndev == 0) |
| 8120 | goto out; |
| 8121 | |
| 8122 | first = NULL; |
| 8123 | next = l2arc_dev_last; |
| 8124 | do { |
| 8125 | /* loop around the list looking for a non-faulted vdev */ |
| 8126 | if (next == NULL) { |
| 8127 | next = list_head(l2arc_dev_list); |
| 8128 | } else { |
| 8129 | next = list_next(l2arc_dev_list, next); |
| 8130 | if (next == NULL) |
| 8131 | next = list_head(l2arc_dev_list); |
| 8132 | } |
| 8133 | |
| 8134 | /* if we have come back to the start, bail out */ |
| 8135 | if (first == NULL) |
| 8136 | first = next; |
| 8137 | else if (next == first) |
| 8138 | break; |
| 8139 | |
| 8140 | } while (vdev_is_dead(next->l2ad_vdev) || next->l2ad_rebuild || |
| 8141 | next->l2ad_trim_all); |
| 8142 | |
| 8143 | /* if we were unable to find any usable vdevs, return NULL */ |
| 8144 | if (vdev_is_dead(next->l2ad_vdev) || next->l2ad_rebuild || |
| 8145 | next->l2ad_trim_all) |
| 8146 | next = NULL; |
| 8147 | |
| 8148 | l2arc_dev_last = next; |
| 8149 | |
| 8150 | out: |
| 8151 | mutex_exit(&l2arc_dev_mtx); |
| 8152 | |
| 8153 | /* |
| 8154 | * Grab the config lock to prevent the 'next' device from being |
| 8155 | * removed while we are writing to it. |
| 8156 | */ |
| 8157 | if (next != NULL) |
| 8158 | spa_config_enter(next->l2ad_spa, SCL_L2ARC, next, RW_READER); |
| 8159 | mutex_exit(&spa_namespace_lock); |
| 8160 | |
| 8161 | return (next); |
| 8162 | } |
no test coverage detected