Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 CNEX Labs |
| 3 | * Initial release: Javier Gonzalez <javier@cnexlabs.com> |
| 4 | * Matias Bjorling <matias@cnexlabs.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License version |
| 8 | * 2 as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * Implementation of a physical block-device target for Open-channel SSDs. |
| 16 | * |
| 17 | * pblk-sysfs.c - pblk's sysfs |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include "pblk.h" |
| 22 | |
| 23 | static ssize_t pblk_sysfs_luns_show(struct pblk *pblk, char *page) |
| 24 | { |
| 25 | struct nvm_tgt_dev *dev = pblk->dev; |
| 26 | struct nvm_geo *geo = &dev->geo; |
| 27 | struct pblk_lun *rlun; |
| 28 | ssize_t sz = 0; |
| 29 | int i; |
| 30 | |
| 31 | for (i = 0; i < geo->nr_luns; i++) { |
| 32 | int active = 1; |
| 33 | |
| 34 | rlun = &pblk->luns[i]; |
| 35 | if (!down_trylock(&rlun->wr_sem)) { |
| 36 | active = 0; |
| 37 | up(&rlun->wr_sem); |
| 38 | } |
| 39 | sz += snprintf(page + sz, PAGE_SIZE - sz, |
| 40 | "pblk: pos:%d, ch:%d, lun:%d - %d\n", |
| 41 | i, |
| 42 | rlun->bppa.g.ch, |
| 43 | rlun->bppa.g.lun, |
| 44 | active); |
| 45 | } |
| 46 | |
| 47 | return sz; |
| 48 | } |
| 49 | |
| 50 | static ssize_t pblk_sysfs_rate_limiter(struct pblk *pblk, char *page) |
| 51 | { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 52 | int free_blocks, total_blocks; |
| 53 | int rb_user_max, rb_user_cnt; |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 54 | int rb_gc_max, rb_gc_cnt, rb_budget, rb_state; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 55 | |
| 56 | free_blocks = atomic_read(&pblk->rl.free_blocks); |
| 57 | rb_user_max = pblk->rl.rb_user_max; |
| 58 | rb_user_cnt = atomic_read(&pblk->rl.rb_user_cnt); |
| 59 | rb_gc_max = pblk->rl.rb_gc_max; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 60 | rb_gc_cnt = atomic_read(&pblk->rl.rb_gc_cnt); |
| 61 | rb_budget = pblk->rl.rb_budget; |
| 62 | rb_state = pblk->rl.rb_state; |
| 63 | |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 64 | total_blocks = pblk->rl.total_blocks; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 65 | |
| 66 | return snprintf(page, PAGE_SIZE, |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 67 | "u:%u/%u,gc:%u/%u(%u/%u)(stop:<%u,full:>%u,free:%d/%d)-%d\n", |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 68 | rb_user_cnt, |
| 69 | rb_user_max, |
| 70 | rb_gc_cnt, |
| 71 | rb_gc_max, |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 72 | rb_state, |
| 73 | rb_budget, |
| 74 | pblk->rl.low, |
| 75 | pblk->rl.high, |
| 76 | free_blocks, |
| 77 | total_blocks, |
| 78 | READ_ONCE(pblk->rl.rb_user_active)); |
| 79 | } |
| 80 | |
| 81 | static ssize_t pblk_sysfs_gc_state_show(struct pblk *pblk, char *page) |
| 82 | { |
| 83 | int gc_enabled, gc_active; |
| 84 | |
| 85 | pblk_gc_sysfs_state_show(pblk, &gc_enabled, &gc_active); |
| 86 | return snprintf(page, PAGE_SIZE, "gc_enabled=%d, gc_active=%d\n", |
| 87 | gc_enabled, gc_active); |
| 88 | } |
| 89 | |
| 90 | static ssize_t pblk_sysfs_stats(struct pblk *pblk, char *page) |
| 91 | { |
| 92 | ssize_t sz; |
| 93 | |
| 94 | sz = snprintf(page, PAGE_SIZE, |
| 95 | "read_failed=%lu, read_high_ecc=%lu, read_empty=%lu, read_failed_gc=%lu, write_failed=%lu, erase_failed=%lu\n", |
| 96 | atomic_long_read(&pblk->read_failed), |
| 97 | atomic_long_read(&pblk->read_high_ecc), |
| 98 | atomic_long_read(&pblk->read_empty), |
| 99 | atomic_long_read(&pblk->read_failed_gc), |
| 100 | atomic_long_read(&pblk->write_failed), |
| 101 | atomic_long_read(&pblk->erase_failed)); |
| 102 | |
| 103 | return sz; |
| 104 | } |
| 105 | |
| 106 | static ssize_t pblk_sysfs_write_buffer(struct pblk *pblk, char *page) |
| 107 | { |
| 108 | return pblk_rb_sysfs(&pblk->rwb, page); |
| 109 | } |
| 110 | |
| 111 | static ssize_t pblk_sysfs_ppaf(struct pblk *pblk, char *page) |
| 112 | { |
| 113 | struct nvm_tgt_dev *dev = pblk->dev; |
| 114 | struct nvm_geo *geo = &dev->geo; |
| 115 | ssize_t sz = 0; |
| 116 | |
| 117 | sz = snprintf(page, PAGE_SIZE - sz, |
| 118 | "g:(b:%d)blk:%d/%d,pg:%d/%d,lun:%d/%d,ch:%d/%d,pl:%d/%d,sec:%d/%d\n", |
| 119 | pblk->ppaf_bitsize, |
| 120 | pblk->ppaf.blk_offset, geo->ppaf.blk_len, |
| 121 | pblk->ppaf.pg_offset, geo->ppaf.pg_len, |
| 122 | pblk->ppaf.lun_offset, geo->ppaf.lun_len, |
| 123 | pblk->ppaf.ch_offset, geo->ppaf.ch_len, |
| 124 | pblk->ppaf.pln_offset, geo->ppaf.pln_len, |
| 125 | pblk->ppaf.sec_offset, geo->ppaf.sect_len); |
| 126 | |
| 127 | sz += snprintf(page + sz, PAGE_SIZE - sz, |
| 128 | "d:blk:%d/%d,pg:%d/%d,lun:%d/%d,ch:%d/%d,pl:%d/%d,sec:%d/%d\n", |
| 129 | geo->ppaf.blk_offset, geo->ppaf.blk_len, |
| 130 | geo->ppaf.pg_offset, geo->ppaf.pg_len, |
| 131 | geo->ppaf.lun_offset, geo->ppaf.lun_len, |
| 132 | geo->ppaf.ch_offset, geo->ppaf.ch_len, |
| 133 | geo->ppaf.pln_offset, geo->ppaf.pln_len, |
| 134 | geo->ppaf.sect_offset, geo->ppaf.sect_len); |
| 135 | |
| 136 | return sz; |
| 137 | } |
| 138 | |
| 139 | static ssize_t pblk_sysfs_lines(struct pblk *pblk, char *page) |
| 140 | { |
| 141 | struct nvm_tgt_dev *dev = pblk->dev; |
| 142 | struct nvm_geo *geo = &dev->geo; |
| 143 | struct pblk_line_meta *lm = &pblk->lm; |
| 144 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 145 | struct pblk_line *line; |
| 146 | ssize_t sz = 0; |
| 147 | int nr_free_lines; |
| 148 | int cur_data, cur_log; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 149 | int free_line_cnt = 0, closed_line_cnt = 0, emeta_line_cnt = 0; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 150 | int d_line_cnt = 0, l_line_cnt = 0; |
| 151 | int gc_full = 0, gc_high = 0, gc_mid = 0, gc_low = 0, gc_empty = 0; |
Javier González | fd1b015 | 2017-06-26 11:57:18 +0200 | [diff] [blame] | 152 | int bad = 0, cor = 0; |
Javier González | 0880a9a | 2017-06-26 11:57:19 +0200 | [diff] [blame] | 153 | int msecs = 0, cur_sec = 0, vsc = 0, sec_in_line = 0; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 154 | int map_weight = 0, meta_weight = 0; |
| 155 | |
| 156 | spin_lock(&l_mg->free_lock); |
| 157 | cur_data = (l_mg->data_line) ? l_mg->data_line->id : -1; |
| 158 | cur_log = (l_mg->log_line) ? l_mg->log_line->id : -1; |
| 159 | nr_free_lines = l_mg->nr_free_lines; |
| 160 | |
| 161 | list_for_each_entry(line, &l_mg->free_list, list) |
| 162 | free_line_cnt++; |
| 163 | spin_unlock(&l_mg->free_lock); |
| 164 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 165 | spin_lock(&l_mg->close_lock); |
| 166 | list_for_each_entry(line, &l_mg->emeta_list, list) |
| 167 | emeta_line_cnt++; |
| 168 | spin_unlock(&l_mg->close_lock); |
| 169 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 170 | spin_lock(&l_mg->gc_lock); |
| 171 | list_for_each_entry(line, &l_mg->gc_full_list, list) { |
| 172 | if (line->type == PBLK_LINETYPE_DATA) |
| 173 | d_line_cnt++; |
| 174 | else if (line->type == PBLK_LINETYPE_LOG) |
| 175 | l_line_cnt++; |
| 176 | closed_line_cnt++; |
| 177 | gc_full++; |
| 178 | } |
| 179 | |
| 180 | list_for_each_entry(line, &l_mg->gc_high_list, list) { |
| 181 | if (line->type == PBLK_LINETYPE_DATA) |
| 182 | d_line_cnt++; |
| 183 | else if (line->type == PBLK_LINETYPE_LOG) |
| 184 | l_line_cnt++; |
| 185 | closed_line_cnt++; |
| 186 | gc_high++; |
| 187 | } |
| 188 | |
| 189 | list_for_each_entry(line, &l_mg->gc_mid_list, list) { |
| 190 | if (line->type == PBLK_LINETYPE_DATA) |
| 191 | d_line_cnt++; |
| 192 | else if (line->type == PBLK_LINETYPE_LOG) |
| 193 | l_line_cnt++; |
| 194 | closed_line_cnt++; |
| 195 | gc_mid++; |
| 196 | } |
| 197 | |
| 198 | list_for_each_entry(line, &l_mg->gc_low_list, list) { |
| 199 | if (line->type == PBLK_LINETYPE_DATA) |
| 200 | d_line_cnt++; |
| 201 | else if (line->type == PBLK_LINETYPE_LOG) |
| 202 | l_line_cnt++; |
| 203 | closed_line_cnt++; |
| 204 | gc_low++; |
| 205 | } |
| 206 | |
| 207 | list_for_each_entry(line, &l_mg->gc_empty_list, list) { |
| 208 | if (line->type == PBLK_LINETYPE_DATA) |
| 209 | d_line_cnt++; |
| 210 | else if (line->type == PBLK_LINETYPE_LOG) |
| 211 | l_line_cnt++; |
| 212 | closed_line_cnt++; |
| 213 | gc_empty++; |
| 214 | } |
| 215 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 216 | list_for_each_entry(line, &l_mg->bad_list, list) |
| 217 | bad++; |
| 218 | list_for_each_entry(line, &l_mg->corrupt_list, list) |
| 219 | cor++; |
| 220 | spin_unlock(&l_mg->gc_lock); |
| 221 | |
| 222 | spin_lock(&l_mg->free_lock); |
| 223 | if (l_mg->data_line) { |
| 224 | cur_sec = l_mg->data_line->cur_sec; |
| 225 | msecs = l_mg->data_line->left_msecs; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 226 | vsc = le32_to_cpu(*l_mg->data_line->vsc); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 227 | sec_in_line = l_mg->data_line->sec_in_line; |
| 228 | meta_weight = bitmap_weight(&l_mg->meta_bitmap, |
| 229 | PBLK_DATA_LINES); |
| 230 | map_weight = bitmap_weight(l_mg->data_line->map_bitmap, |
| 231 | lm->sec_per_line); |
| 232 | } |
| 233 | spin_unlock(&l_mg->free_lock); |
| 234 | |
| 235 | if (nr_free_lines != free_line_cnt) |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 236 | pr_err("pblk: corrupted free line list:%d/%d\n", |
| 237 | nr_free_lines, free_line_cnt); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 238 | |
| 239 | sz = snprintf(page, PAGE_SIZE - sz, |
| 240 | "line: nluns:%d, nblks:%d, nsecs:%d\n", |
| 241 | geo->nr_luns, lm->blk_per_line, lm->sec_per_line); |
| 242 | |
| 243 | sz += snprintf(page + sz, PAGE_SIZE - sz, |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 244 | "lines:d:%d,l:%d-f:%d,m:%d/%d,c:%d,b:%d,co:%d(d:%d,l:%d)t:%d\n", |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 245 | cur_data, cur_log, |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 246 | nr_free_lines, |
| 247 | emeta_line_cnt, meta_weight, |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 248 | closed_line_cnt, |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 249 | bad, cor, |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 250 | d_line_cnt, l_line_cnt, |
| 251 | l_mg->nr_lines); |
| 252 | |
| 253 | sz += snprintf(page + sz, PAGE_SIZE - sz, |
| 254 | "GC: full:%d, high:%d, mid:%d, low:%d, empty:%d, queue:%d\n", |
| 255 | gc_full, gc_high, gc_mid, gc_low, gc_empty, |
| 256 | atomic_read(&pblk->gc.inflight_gc)); |
| 257 | |
| 258 | sz += snprintf(page + sz, PAGE_SIZE - sz, |
Javier González | 0880a9a | 2017-06-26 11:57:19 +0200 | [diff] [blame] | 259 | "data (%d) cur:%d, left:%d, vsc:%d, s:%d, map:%d/%d (%d)\n", |
| 260 | cur_data, cur_sec, msecs, vsc, sec_in_line, |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 261 | map_weight, lm->sec_per_line, |
| 262 | atomic_read(&pblk->inflight_io)); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 263 | |
| 264 | return sz; |
| 265 | } |
| 266 | |
| 267 | static ssize_t pblk_sysfs_lines_info(struct pblk *pblk, char *page) |
| 268 | { |
| 269 | struct nvm_tgt_dev *dev = pblk->dev; |
| 270 | struct nvm_geo *geo = &dev->geo; |
| 271 | struct pblk_line_meta *lm = &pblk->lm; |
| 272 | ssize_t sz = 0; |
| 273 | |
| 274 | sz = snprintf(page, PAGE_SIZE - sz, |
| 275 | "smeta - len:%d, secs:%d\n", |
| 276 | lm->smeta_len, lm->smeta_sec); |
| 277 | sz += snprintf(page + sz, PAGE_SIZE - sz, |
| 278 | "emeta - len:%d, sec:%d, bb_start:%d\n", |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 279 | lm->emeta_len[0], lm->emeta_sec[0], |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 280 | lm->emeta_bb); |
| 281 | sz += snprintf(page + sz, PAGE_SIZE - sz, |
| 282 | "bitmap lengths: sec:%d, blk:%d, lun:%d\n", |
| 283 | lm->sec_bitmap_len, |
| 284 | lm->blk_bitmap_len, |
| 285 | lm->lun_bitmap_len); |
| 286 | sz += snprintf(page + sz, PAGE_SIZE - sz, |
| 287 | "blk_line:%d, sec_line:%d, sec_blk:%d\n", |
| 288 | lm->blk_per_line, |
| 289 | lm->sec_per_line, |
| 290 | geo->sec_per_blk); |
| 291 | |
| 292 | return sz; |
| 293 | } |
| 294 | |
Javier González | c2e9f5d | 2017-06-26 11:57:14 +0200 | [diff] [blame] | 295 | static ssize_t pblk_sysfs_get_sec_per_write(struct pblk *pblk, char *page) |
| 296 | { |
| 297 | return snprintf(page, PAGE_SIZE, "%d\n", pblk->sec_per_write); |
| 298 | } |
| 299 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 300 | #ifdef CONFIG_NVM_DEBUG |
| 301 | static ssize_t pblk_sysfs_stats_debug(struct pblk *pblk, char *page) |
| 302 | { |
| 303 | return snprintf(page, PAGE_SIZE, |
Javier González | 0880a9a | 2017-06-26 11:57:19 +0200 | [diff] [blame] | 304 | "%lu\t%lu\t%lu\t%lu\t%lu\t%lu\t%lu\t%lu\t%lu\t%lu\t%lu\t%lu\t%lu\n", |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 305 | atomic_long_read(&pblk->inflight_writes), |
| 306 | atomic_long_read(&pblk->inflight_reads), |
| 307 | atomic_long_read(&pblk->req_writes), |
| 308 | atomic_long_read(&pblk->nr_flush), |
| 309 | atomic_long_read(&pblk->padded_writes), |
| 310 | atomic_long_read(&pblk->padded_wb), |
| 311 | atomic_long_read(&pblk->sub_writes), |
| 312 | atomic_long_read(&pblk->sync_writes), |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 313 | atomic_long_read(&pblk->recov_writes), |
| 314 | atomic_long_read(&pblk->recov_gc_writes), |
| 315 | atomic_long_read(&pblk->recov_gc_reads), |
Javier González | db7ada3 | 2017-06-26 11:57:13 +0200 | [diff] [blame] | 316 | atomic_long_read(&pblk->cache_reads), |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 317 | atomic_long_read(&pblk->sync_reads)); |
| 318 | } |
| 319 | #endif |
| 320 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 321 | static ssize_t pblk_sysfs_gc_force(struct pblk *pblk, const char *page, |
| 322 | size_t len) |
| 323 | { |
| 324 | size_t c_len; |
Javier González | 653cbb8 | 2017-06-30 17:56:36 +0200 | [diff] [blame^] | 325 | int force; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 326 | |
| 327 | c_len = strcspn(page, "\n"); |
| 328 | if (c_len >= len) |
| 329 | return -EINVAL; |
| 330 | |
| 331 | if (kstrtouint(page, 0, &force)) |
| 332 | return -EINVAL; |
| 333 | |
Javier González | 653cbb8 | 2017-06-30 17:56:36 +0200 | [diff] [blame^] | 334 | pblk_gc_sysfs_force(pblk, force); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 335 | |
| 336 | return len; |
| 337 | } |
| 338 | |
Javier González | c2e9f5d | 2017-06-26 11:57:14 +0200 | [diff] [blame] | 339 | static ssize_t pblk_sysfs_set_sec_per_write(struct pblk *pblk, |
| 340 | const char *page, size_t len) |
| 341 | { |
| 342 | size_t c_len; |
| 343 | int sec_per_write; |
| 344 | |
| 345 | c_len = strcspn(page, "\n"); |
| 346 | if (c_len >= len) |
| 347 | return -EINVAL; |
| 348 | |
| 349 | if (kstrtouint(page, 0, &sec_per_write)) |
| 350 | return -EINVAL; |
| 351 | |
| 352 | if (sec_per_write < pblk->min_write_pgs |
| 353 | || sec_per_write > pblk->max_write_pgs |
| 354 | || sec_per_write % pblk->min_write_pgs != 0) |
| 355 | return -EINVAL; |
| 356 | |
| 357 | pblk_set_sec_per_write(pblk, sec_per_write); |
| 358 | |
| 359 | return len; |
| 360 | } |
| 361 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 362 | static struct attribute sys_write_luns = { |
| 363 | .name = "write_luns", |
| 364 | .mode = 0444, |
| 365 | }; |
| 366 | |
| 367 | static struct attribute sys_rate_limiter_attr = { |
| 368 | .name = "rate_limiter", |
| 369 | .mode = 0444, |
| 370 | }; |
| 371 | |
| 372 | static struct attribute sys_gc_state = { |
| 373 | .name = "gc_state", |
| 374 | .mode = 0444, |
| 375 | }; |
| 376 | |
| 377 | static struct attribute sys_errors_attr = { |
| 378 | .name = "errors", |
| 379 | .mode = 0444, |
| 380 | }; |
| 381 | |
| 382 | static struct attribute sys_rb_attr = { |
| 383 | .name = "write_buffer", |
| 384 | .mode = 0444, |
| 385 | }; |
| 386 | |
| 387 | static struct attribute sys_stats_ppaf_attr = { |
| 388 | .name = "ppa_format", |
| 389 | .mode = 0444, |
| 390 | }; |
| 391 | |
| 392 | static struct attribute sys_lines_attr = { |
| 393 | .name = "lines", |
| 394 | .mode = 0444, |
| 395 | }; |
| 396 | |
| 397 | static struct attribute sys_lines_info_attr = { |
| 398 | .name = "lines_info", |
| 399 | .mode = 0444, |
| 400 | }; |
| 401 | |
| 402 | static struct attribute sys_gc_force = { |
| 403 | .name = "gc_force", |
| 404 | .mode = 0200, |
| 405 | }; |
| 406 | |
Javier González | c2e9f5d | 2017-06-26 11:57:14 +0200 | [diff] [blame] | 407 | static struct attribute sys_max_sec_per_write = { |
| 408 | .name = "max_sec_per_write", |
| 409 | .mode = 0644, |
| 410 | }; |
| 411 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 412 | #ifdef CONFIG_NVM_DEBUG |
| 413 | static struct attribute sys_stats_debug_attr = { |
| 414 | .name = "stats", |
| 415 | .mode = 0444, |
| 416 | }; |
| 417 | #endif |
| 418 | |
| 419 | static struct attribute *pblk_attrs[] = { |
| 420 | &sys_write_luns, |
| 421 | &sys_rate_limiter_attr, |
| 422 | &sys_errors_attr, |
| 423 | &sys_gc_state, |
| 424 | &sys_gc_force, |
Javier González | c2e9f5d | 2017-06-26 11:57:14 +0200 | [diff] [blame] | 425 | &sys_max_sec_per_write, |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 426 | &sys_rb_attr, |
| 427 | &sys_stats_ppaf_attr, |
| 428 | &sys_lines_attr, |
| 429 | &sys_lines_info_attr, |
| 430 | #ifdef CONFIG_NVM_DEBUG |
| 431 | &sys_stats_debug_attr, |
| 432 | #endif |
| 433 | NULL, |
| 434 | }; |
| 435 | |
| 436 | static ssize_t pblk_sysfs_show(struct kobject *kobj, struct attribute *attr, |
| 437 | char *buf) |
| 438 | { |
| 439 | struct pblk *pblk = container_of(kobj, struct pblk, kobj); |
| 440 | |
| 441 | if (strcmp(attr->name, "rate_limiter") == 0) |
| 442 | return pblk_sysfs_rate_limiter(pblk, buf); |
| 443 | else if (strcmp(attr->name, "write_luns") == 0) |
| 444 | return pblk_sysfs_luns_show(pblk, buf); |
| 445 | else if (strcmp(attr->name, "gc_state") == 0) |
| 446 | return pblk_sysfs_gc_state_show(pblk, buf); |
| 447 | else if (strcmp(attr->name, "errors") == 0) |
| 448 | return pblk_sysfs_stats(pblk, buf); |
| 449 | else if (strcmp(attr->name, "write_buffer") == 0) |
| 450 | return pblk_sysfs_write_buffer(pblk, buf); |
| 451 | else if (strcmp(attr->name, "ppa_format") == 0) |
| 452 | return pblk_sysfs_ppaf(pblk, buf); |
| 453 | else if (strcmp(attr->name, "lines") == 0) |
| 454 | return pblk_sysfs_lines(pblk, buf); |
| 455 | else if (strcmp(attr->name, "lines_info") == 0) |
| 456 | return pblk_sysfs_lines_info(pblk, buf); |
Javier González | c2e9f5d | 2017-06-26 11:57:14 +0200 | [diff] [blame] | 457 | else if (strcmp(attr->name, "max_sec_per_write") == 0) |
| 458 | return pblk_sysfs_get_sec_per_write(pblk, buf); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 459 | #ifdef CONFIG_NVM_DEBUG |
| 460 | else if (strcmp(attr->name, "stats") == 0) |
| 461 | return pblk_sysfs_stats_debug(pblk, buf); |
| 462 | #endif |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | static ssize_t pblk_sysfs_store(struct kobject *kobj, struct attribute *attr, |
| 467 | const char *buf, size_t len) |
| 468 | { |
| 469 | struct pblk *pblk = container_of(kobj, struct pblk, kobj); |
| 470 | |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 471 | if (strcmp(attr->name, "gc_force") == 0) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 472 | return pblk_sysfs_gc_force(pblk, buf, len); |
Javier González | c2e9f5d | 2017-06-26 11:57:14 +0200 | [diff] [blame] | 473 | else if (strcmp(attr->name, "max_sec_per_write") == 0) |
| 474 | return pblk_sysfs_set_sec_per_write(pblk, buf, len); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | static const struct sysfs_ops pblk_sysfs_ops = { |
| 480 | .show = pblk_sysfs_show, |
| 481 | .store = pblk_sysfs_store, |
| 482 | }; |
| 483 | |
| 484 | static struct kobj_type pblk_ktype = { |
| 485 | .sysfs_ops = &pblk_sysfs_ops, |
| 486 | .default_attrs = pblk_attrs, |
| 487 | }; |
| 488 | |
| 489 | int pblk_sysfs_init(struct gendisk *tdisk) |
| 490 | { |
| 491 | struct pblk *pblk = tdisk->private_data; |
| 492 | struct device *parent_dev = disk_to_dev(pblk->disk); |
| 493 | int ret; |
| 494 | |
| 495 | ret = kobject_init_and_add(&pblk->kobj, &pblk_ktype, |
| 496 | kobject_get(&parent_dev->kobj), |
| 497 | "%s", "pblk"); |
| 498 | if (ret) { |
| 499 | pr_err("pblk: could not register %s/pblk\n", |
| 500 | tdisk->disk_name); |
| 501 | return ret; |
| 502 | } |
| 503 | |
| 504 | kobject_uevent(&pblk->kobj, KOBJ_ADD); |
| 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | void pblk_sysfs_exit(struct gendisk *tdisk) |
| 509 | { |
| 510 | struct pblk *pblk = tdisk->private_data; |
| 511 | |
| 512 | kobject_uevent(&pblk->kobj, KOBJ_REMOVE); |
| 513 | kobject_del(&pblk->kobj); |
| 514 | kobject_put(&pblk->kobj); |
| 515 | } |