* Take a malloced and zeroed devstat structure given to us, fill it in * and add it to the queue of devices. */
| 113 | * and add it to the queue of devices. |
| 114 | */ |
| 115 | static void |
| 116 | devstat_add_entry(struct devstat *ds, const void *dev_name, |
| 117 | int unit_number, uint32_t block_size, |
| 118 | devstat_support_flags flags, |
| 119 | devstat_type_flags device_type, |
| 120 | devstat_priority priority) |
| 121 | { |
| 122 | struct devstatlist *devstat_head; |
| 123 | struct devstat *ds_tmp; |
| 124 | |
| 125 | mtx_assert(&devstat_mutex, MA_OWNED); |
| 126 | devstat_num_devs++; |
| 127 | |
| 128 | devstat_head = &device_statq; |
| 129 | |
| 130 | /* |
| 131 | * Priority sort. Each driver passes in its priority when it adds |
| 132 | * its devstat entry. Drivers are sorted first by priority, and |
| 133 | * then by probe order. |
| 134 | * |
| 135 | * For the first device, we just insert it, since the priority |
| 136 | * doesn't really matter yet. Subsequent devices are inserted into |
| 137 | * the list using the order outlined above. |
| 138 | */ |
| 139 | if (devstat_num_devs == 1) |
| 140 | STAILQ_INSERT_TAIL(devstat_head, ds, dev_links); |
| 141 | else { |
| 142 | STAILQ_FOREACH(ds_tmp, devstat_head, dev_links) { |
| 143 | struct devstat *ds_next; |
| 144 | |
| 145 | ds_next = STAILQ_NEXT(ds_tmp, dev_links); |
| 146 | |
| 147 | /* |
| 148 | * If we find a break between higher and lower |
| 149 | * priority items, and if this item fits in the |
| 150 | * break, insert it. This also applies if the |
| 151 | * "lower priority item" is the end of the list. |
| 152 | */ |
| 153 | if ((priority <= ds_tmp->priority) |
| 154 | && ((ds_next == NULL) |
| 155 | || (priority > ds_next->priority))) { |
| 156 | STAILQ_INSERT_AFTER(devstat_head, ds_tmp, ds, |
| 157 | dev_links); |
| 158 | break; |
| 159 | } else if (priority > ds_tmp->priority) { |
| 160 | /* |
| 161 | * If this is the case, we should be able |
| 162 | * to insert ourselves at the head of the |
| 163 | * list. If we can't, something is wrong. |
| 164 | */ |
| 165 | if (ds_tmp == STAILQ_FIRST(devstat_head)) { |
| 166 | STAILQ_INSERT_HEAD(devstat_head, |
| 167 | ds, dev_links); |
| 168 | break; |
| 169 | } else { |
| 170 | STAILQ_INSERT_TAIL(devstat_head, |
| 171 | ds, dev_links); |
| 172 | printf("devstat_add_entry: HELP! " |
no test coverage detected