Deleted Added
full compact
ctl.c (273731) ctl.c (274154)
1/*-
2 * Copyright (c) 2003-2009 Silicon Graphics International Corp.
3 * Copyright (c) 2012 The FreeBSD Foundation
4 * All rights reserved.
5 *
6 * Portions of this software were developed by Edward Tomasz Napierala
7 * under sponsorship from the FreeBSD Foundation.
8 *

--- 28 unchanged lines hidden (view full) ---

37 * CAM Target Layer, a SCSI device emulation subsystem.
38 *
39 * Author: Ken Merry <ken@FreeBSD.org>
40 */
41
42#define _CTL_C
43
44#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2003-2009 Silicon Graphics International Corp.
3 * Copyright (c) 2012 The FreeBSD Foundation
4 * All rights reserved.
5 *
6 * Portions of this software were developed by Edward Tomasz Napierala
7 * under sponsorship from the FreeBSD Foundation.
8 *

--- 28 unchanged lines hidden (view full) ---

37 * CAM Target Layer, a SCSI device emulation subsystem.
38 *
39 * Author: Ken Merry <ken@FreeBSD.org>
40 */
41
42#define _CTL_C
43
44#include <sys/cdefs.h>
45__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl.c 273731 2014-10-27 09:30:57Z mav $");
45__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl.c 274154 2014-11-06 00:48:36Z mav $");
46
47#include <sys/param.h>
48#include <sys/systm.h>
49#include <sys/ctype.h>
50#include <sys/kernel.h>
51#include <sys/types.h>
52#include <sys/kthread.h>
53#include <sys/bio.h>

--- 78 unchanged lines hidden (view full) ---

132static struct scsi_da_rw_recovery_page rw_er_page_default = {
133 /*page_code*/SMS_RW_ERROR_RECOVERY_PAGE,
134 /*page_length*/sizeof(struct scsi_da_rw_recovery_page) - 2,
135 /*byte3*/SMS_RWER_AWRE|SMS_RWER_ARRE,
136 /*read_retry_count*/0,
137 /*correction_span*/0,
138 /*head_offset_count*/0,
139 /*data_strobe_offset_cnt*/0,
46
47#include <sys/param.h>
48#include <sys/systm.h>
49#include <sys/ctype.h>
50#include <sys/kernel.h>
51#include <sys/types.h>
52#include <sys/kthread.h>
53#include <sys/bio.h>

--- 78 unchanged lines hidden (view full) ---

132static struct scsi_da_rw_recovery_page rw_er_page_default = {
133 /*page_code*/SMS_RW_ERROR_RECOVERY_PAGE,
134 /*page_length*/sizeof(struct scsi_da_rw_recovery_page) - 2,
135 /*byte3*/SMS_RWER_AWRE|SMS_RWER_ARRE,
136 /*read_retry_count*/0,
137 /*correction_span*/0,
138 /*head_offset_count*/0,
139 /*data_strobe_offset_cnt*/0,
140 /*byte8*/0,
140 /*byte8*/SMS_RWER_LBPERE,
141 /*write_retry_count*/0,
142 /*reserved2*/0,
143 /*recovery_time_limit*/{0, 0},
144};
145
146static struct scsi_da_rw_recovery_page rw_er_page_changeable = {
147 /*page_code*/SMS_RW_ERROR_RECOVERY_PAGE,
148 /*page_length*/sizeof(struct scsi_da_rw_recovery_page) - 2,

--- 143 unchanged lines hidden (view full) ---

292 /*page_code*/SMS_INFO_EXCEPTIONS_PAGE,
293 /*page_length*/sizeof(struct scsi_info_exceptions_page) - 2,
294 /*info_flags*/0,
295 /*mrie*/0,
296 /*interval_timer*/{0, 0, 0, 0},
297 /*report_count*/{0, 0, 0, 0}
298};
299
141 /*write_retry_count*/0,
142 /*reserved2*/0,
143 /*recovery_time_limit*/{0, 0},
144};
145
146static struct scsi_da_rw_recovery_page rw_er_page_changeable = {
147 /*page_code*/SMS_RW_ERROR_RECOVERY_PAGE,
148 /*page_length*/sizeof(struct scsi_da_rw_recovery_page) - 2,

--- 143 unchanged lines hidden (view full) ---

292 /*page_code*/SMS_INFO_EXCEPTIONS_PAGE,
293 /*page_length*/sizeof(struct scsi_info_exceptions_page) - 2,
294 /*info_flags*/0,
295 /*mrie*/0,
296 /*interval_timer*/{0, 0, 0, 0},
297 /*report_count*/{0, 0, 0, 0}
298};
299
300static struct scsi_logical_block_provisioning_page lbp_page_default = {
300#define CTL_LBPM_LEN (sizeof(struct ctl_logical_block_provisioning_page) - 4)
301
302static struct ctl_logical_block_provisioning_page lbp_page_default = {{
301 /*page_code*/SMS_INFO_EXCEPTIONS_PAGE | SMPH_SPF,
302 /*subpage_code*/0x02,
303 /*page_code*/SMS_INFO_EXCEPTIONS_PAGE | SMPH_SPF,
304 /*subpage_code*/0x02,
303 /*page_length*/{0, sizeof(struct scsi_logical_block_provisioning_page) - 4},
305 /*page_length*/{CTL_LBPM_LEN >> 8, CTL_LBPM_LEN},
304 /*flags*/0,
305 /*reserved*/{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
306 /*flags*/0,
307 /*reserved*/{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
306 /*descr*/{}
308 /*descr*/{}},
309 {{/*flags*/0,
310 /*resource*/0x01,
311 /*reserved*/{0, 0},
312 /*count*/{0, 0, 0, 0}},
313 {/*flags*/0,
314 /*resource*/0x02,
315 /*reserved*/{0, 0},
316 /*count*/{0, 0, 0, 0}},
317 {/*flags*/0,
318 /*resource*/0xf1,
319 /*reserved*/{0, 0},
320 /*count*/{0, 0, 0, 0}},
321 {/*flags*/0,
322 /*resource*/0xf2,
323 /*reserved*/{0, 0},
324 /*count*/{0, 0, 0, 0}}
325 }
307};
308
326};
327
309static struct scsi_logical_block_provisioning_page lbp_page_changeable = {
328static struct ctl_logical_block_provisioning_page lbp_page_changeable = {{
310 /*page_code*/SMS_INFO_EXCEPTIONS_PAGE | SMPH_SPF,
311 /*subpage_code*/0x02,
329 /*page_code*/SMS_INFO_EXCEPTIONS_PAGE | SMPH_SPF,
330 /*subpage_code*/0x02,
312 /*page_length*/{0, sizeof(struct scsi_logical_block_provisioning_page) - 4},
331 /*page_length*/{CTL_LBPM_LEN >> 8, CTL_LBPM_LEN},
313 /*flags*/0,
314 /*reserved*/{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
332 /*flags*/0,
333 /*reserved*/{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
315 /*descr*/{}
334 /*descr*/{}},
335 {{/*flags*/0,
336 /*resource*/0,
337 /*reserved*/{0, 0},
338 /*count*/{0, 0, 0, 0}},
339 {/*flags*/0,
340 /*resource*/0,
341 /*reserved*/{0, 0},
342 /*count*/{0, 0, 0, 0}},
343 {/*flags*/0,
344 /*resource*/0,
345 /*reserved*/{0, 0},
346 /*count*/{0, 0, 0, 0}},
347 {/*flags*/0,
348 /*resource*/0,
349 /*reserved*/{0, 0},
350 /*count*/{0, 0, 0, 0}}
351 }
316};
317
318/*
319 * XXX KDM move these into the softc.
320 */
321static int rcv_sync_msg;
322static int persis_offset;
323static uint8_t ctl_pause_rtr;

--- 118 unchanged lines hidden (view full) ---

442static void ctl_datamove_remote_read_cb(struct ctl_ha_dt_req *rq);
443static int ctl_datamove_remote_sgl_setup(union ctl_io *io);
444static int ctl_datamove_remote_xfer(union ctl_io *io, unsigned command,
445 ctl_ha_dt_cb callback);
446static void ctl_datamove_remote_read(union ctl_io *io);
447static void ctl_datamove_remote(union ctl_io *io);
448static int ctl_process_done(union ctl_io *io);
449static void ctl_lun_thread(void *arg);
352};
353
354/*
355 * XXX KDM move these into the softc.
356 */
357static int rcv_sync_msg;
358static int persis_offset;
359static uint8_t ctl_pause_rtr;

--- 118 unchanged lines hidden (view full) ---

478static void ctl_datamove_remote_read_cb(struct ctl_ha_dt_req *rq);
479static int ctl_datamove_remote_sgl_setup(union ctl_io *io);
480static int ctl_datamove_remote_xfer(union ctl_io *io, unsigned command,
481 ctl_ha_dt_cb callback);
482static void ctl_datamove_remote_read(union ctl_io *io);
483static void ctl_datamove_remote(union ctl_io *io);
484static int ctl_process_done(union ctl_io *io);
485static void ctl_lun_thread(void *arg);
486static void ctl_thresh_thread(void *arg);
450static void ctl_work_thread(void *arg);
451static void ctl_enqueue_incoming(union ctl_io *io);
452static void ctl_enqueue_rtr(union ctl_io *io);
453static void ctl_enqueue_done(union ctl_io *io);
454static void ctl_enqueue_isc(union ctl_io *io);
455static const struct ctl_cmd_entry *
456 ctl_get_cmd_entry(struct ctl_scsiio *ctsio, int *sa);
457static const struct ctl_cmd_entry *

--- 622 unchanged lines hidden (view full) ---

1080 &softc->ctl_proc, NULL, 0, 0, "ctl", "lun");
1081 if (error != 0) {
1082 printf("error creating CTL lun thread!\n");
1083 ctl_pool_free(internal_pool);
1084 ctl_pool_free(emergency_pool);
1085 ctl_pool_free(other_pool);
1086 return (error);
1087 }
487static void ctl_work_thread(void *arg);
488static void ctl_enqueue_incoming(union ctl_io *io);
489static void ctl_enqueue_rtr(union ctl_io *io);
490static void ctl_enqueue_done(union ctl_io *io);
491static void ctl_enqueue_isc(union ctl_io *io);
492static const struct ctl_cmd_entry *
493 ctl_get_cmd_entry(struct ctl_scsiio *ctsio, int *sa);
494static const struct ctl_cmd_entry *

--- 622 unchanged lines hidden (view full) ---

1117 &softc->ctl_proc, NULL, 0, 0, "ctl", "lun");
1118 if (error != 0) {
1119 printf("error creating CTL lun thread!\n");
1120 ctl_pool_free(internal_pool);
1121 ctl_pool_free(emergency_pool);
1122 ctl_pool_free(other_pool);
1123 return (error);
1124 }
1125 error = kproc_kthread_add(ctl_thresh_thread, softc,
1126 &softc->ctl_proc, NULL, 0, 0, "ctl", "thresh");
1127 if (error != 0) {
1128 printf("error creating CTL threshold thread!\n");
1129 ctl_pool_free(internal_pool);
1130 ctl_pool_free(emergency_pool);
1131 ctl_pool_free(other_pool);
1132 return (error);
1133 }
1088 if (bootverbose)
1089 printf("ctl: CAM Target Layer loaded\n");
1090
1091 /*
1092 * Initialize the ioctl front end.
1093 */
1094 ctl_frontend_register(&ioctl_frontend);
1095 port = &softc->ioctl_info.port;

--- 2890 unchanged lines hidden (view full) ---

3986 dest->io_hdr.pool = pool_ref;
3987 /*
3988 * We need to know that this is an internal copy, and doesn't need
3989 * to get passed back to the FETD that allocated it.
3990 */
3991 dest->io_hdr.flags |= CTL_FLAG_INT_COPY;
3992}
3993
1134 if (bootverbose)
1135 printf("ctl: CAM Target Layer loaded\n");
1136
1137 /*
1138 * Initialize the ioctl front end.
1139 */
1140 ctl_frontend_register(&ioctl_frontend);
1141 port = &softc->ioctl_info.port;

--- 2890 unchanged lines hidden (view full) ---

4032 dest->io_hdr.pool = pool_ref;
4033 /*
4034 * We need to know that this is an internal copy, and doesn't need
4035 * to get passed back to the FETD that allocated it.
4036 */
4037 dest->io_hdr.flags |= CTL_FLAG_INT_COPY;
4038}
4039
4040static int
4041ctl_expand_number(const char *buf, uint64_t *num)
4042{
4043 char *endptr;
4044 uint64_t number;
4045 unsigned shift;
4046
4047 number = strtoq(buf, &endptr, 0);
4048
4049 switch (tolower((unsigned char)*endptr)) {
4050 case 'e':
4051 shift = 60;
4052 break;
4053 case 'p':
4054 shift = 50;
4055 break;
4056 case 't':
4057 shift = 40;
4058 break;
4059 case 'g':
4060 shift = 30;
4061 break;
4062 case 'm':
4063 shift = 20;
4064 break;
4065 case 'k':
4066 shift = 10;
4067 break;
4068 case 'b':
4069 case '\0': /* No unit. */
4070 *num = number;
4071 return (0);
4072 default:
4073 /* Unrecognized unit. */
4074 return (-1);
4075 }
4076
4077 if ((number << shift) >> shift != number) {
4078 /* Overflow */
4079 return (-1);
4080 }
4081 *num = number << shift;
4082 return (0);
4083}
4084
4085
3994/*
3995 * This routine could be used in the future to load default and/or saved
3996 * mode page parameters for a particuar lun.
3997 */
3998static int
3999ctl_init_page_index(struct ctl_lun *lun)
4000{
4001 int i;
4002 struct ctl_page_index *page_index;
4003 const char *value;
4086/*
4087 * This routine could be used in the future to load default and/or saved
4088 * mode page parameters for a particuar lun.
4089 */
4090static int
4091ctl_init_page_index(struct ctl_lun *lun)
4092{
4093 int i;
4094 struct ctl_page_index *page_index;
4095 const char *value;
4096 uint64_t ival;
4004
4005 memcpy(&lun->mode_pages.index, page_index_template,
4006 sizeof(page_index_template));
4007
4008 for (i = 0; i < CTL_NUM_MODE_PAGES; i++) {
4009
4010 page_index = &lun->mode_pages.index[i];
4011 /*

--- 228 unchanged lines hidden (view full) ---

4240 &ie_page_default,
4241 sizeof(ie_page_default));
4242 memcpy(&lun->mode_pages.ie_page[CTL_PAGE_SAVED],
4243 &ie_page_default,
4244 sizeof(ie_page_default));
4245 page_index->page_data =
4246 (uint8_t *)lun->mode_pages.ie_page;
4247 break;
4097
4098 memcpy(&lun->mode_pages.index, page_index_template,
4099 sizeof(page_index_template));
4100
4101 for (i = 0; i < CTL_NUM_MODE_PAGES; i++) {
4102
4103 page_index = &lun->mode_pages.index[i];
4104 /*

--- 228 unchanged lines hidden (view full) ---

4333 &ie_page_default,
4334 sizeof(ie_page_default));
4335 memcpy(&lun->mode_pages.ie_page[CTL_PAGE_SAVED],
4336 &ie_page_default,
4337 sizeof(ie_page_default));
4338 page_index->page_data =
4339 (uint8_t *)lun->mode_pages.ie_page;
4340 break;
4248 case 0x02:
4249 memcpy(&lun->mode_pages.lbp_page[CTL_PAGE_CURRENT],
4341 case 0x02: {
4342 struct ctl_logical_block_provisioning_page *page;
4343
4344 memcpy(&lun->mode_pages.lbp_page[CTL_PAGE_DEFAULT],
4250 &lbp_page_default,
4251 sizeof(lbp_page_default));
4252 memcpy(&lun->mode_pages.lbp_page[
4253 CTL_PAGE_CHANGEABLE], &lbp_page_changeable,
4254 sizeof(lbp_page_changeable));
4345 &lbp_page_default,
4346 sizeof(lbp_page_default));
4347 memcpy(&lun->mode_pages.lbp_page[
4348 CTL_PAGE_CHANGEABLE], &lbp_page_changeable,
4349 sizeof(lbp_page_changeable));
4255 memcpy(&lun->mode_pages.lbp_page[CTL_PAGE_DEFAULT],
4256 &lbp_page_default,
4257 sizeof(lbp_page_default));
4258 memcpy(&lun->mode_pages.lbp_page[CTL_PAGE_SAVED],
4259 &lbp_page_default,
4260 sizeof(lbp_page_default));
4350 memcpy(&lun->mode_pages.lbp_page[CTL_PAGE_SAVED],
4351 &lbp_page_default,
4352 sizeof(lbp_page_default));
4353 page = &lun->mode_pages.lbp_page[CTL_PAGE_SAVED];
4354 value = ctl_get_opt(&lun->be_lun->options,
4355 "avail-threshold");
4356 if (value != NULL &&
4357 ctl_expand_number(value, &ival) == 0) {
4358 page->descr[0].flags |= SLBPPD_ENABLED |
4359 SLBPPD_ARMING_DEC;
4360 if (lun->be_lun->blocksize)
4361 ival /= lun->be_lun->blocksize;
4362 else
4363 ival /= 512;
4364 scsi_ulto4b(ival >> CTL_LBP_EXPONENT,
4365 page->descr[0].count);
4366 }
4367 value = ctl_get_opt(&lun->be_lun->options,
4368 "used-threshold");
4369 if (value != NULL &&
4370 ctl_expand_number(value, &ival) == 0) {
4371 page->descr[1].flags |= SLBPPD_ENABLED |
4372 SLBPPD_ARMING_INC;
4373 if (lun->be_lun->blocksize)
4374 ival /= lun->be_lun->blocksize;
4375 else
4376 ival /= 512;
4377 scsi_ulto4b(ival >> CTL_LBP_EXPONENT,
4378 page->descr[1].count);
4379 }
4380 value = ctl_get_opt(&lun->be_lun->options,
4381 "pool-avail-threshold");
4382 if (value != NULL &&
4383 ctl_expand_number(value, &ival) == 0) {
4384 page->descr[2].flags |= SLBPPD_ENABLED |
4385 SLBPPD_ARMING_DEC;
4386 if (lun->be_lun->blocksize)
4387 ival /= lun->be_lun->blocksize;
4388 else
4389 ival /= 512;
4390 scsi_ulto4b(ival >> CTL_LBP_EXPONENT,
4391 page->descr[2].count);
4392 }
4393 value = ctl_get_opt(&lun->be_lun->options,
4394 "pool-used-threshold");
4395 if (value != NULL &&
4396 ctl_expand_number(value, &ival) == 0) {
4397 page->descr[3].flags |= SLBPPD_ENABLED |
4398 SLBPPD_ARMING_INC;
4399 if (lun->be_lun->blocksize)
4400 ival /= lun->be_lun->blocksize;
4401 else
4402 ival /= 512;
4403 scsi_ulto4b(ival >> CTL_LBP_EXPONENT,
4404 page->descr[3].count);
4405 }
4406 memcpy(&lun->mode_pages.lbp_page[CTL_PAGE_CURRENT],
4407 &lun->mode_pages.lbp_page[CTL_PAGE_SAVED],
4408 sizeof(lbp_page_default));
4261 page_index->page_data =
4262 (uint8_t *)lun->mode_pages.lbp_page;
4409 page_index->page_data =
4410 (uint8_t *)lun->mode_pages.lbp_page;
4263 }
4411 }}
4264 break;
4265 }
4266 case SMS_VENDOR_SPECIFIC_PAGE:{
4267 switch (page_index->subpage) {
4268 case DBGCNF_SUBPAGE_CODE: {
4269 struct copan_debugconf_subpage *current_page,
4270 *saved_page;
4271

--- 42 unchanged lines hidden (view full) ---

4314
4315 return (CTL_RETVAL_COMPLETE);
4316}
4317
4318static int
4319ctl_init_log_page_index(struct ctl_lun *lun)
4320{
4321 struct ctl_page_index *page_index;
4412 break;
4413 }
4414 case SMS_VENDOR_SPECIFIC_PAGE:{
4415 switch (page_index->subpage) {
4416 case DBGCNF_SUBPAGE_CODE: {
4417 struct copan_debugconf_subpage *current_page,
4418 *saved_page;
4419

--- 42 unchanged lines hidden (view full) ---

4462
4463 return (CTL_RETVAL_COMPLETE);
4464}
4465
4466static int
4467ctl_init_log_page_index(struct ctl_lun *lun)
4468{
4469 struct ctl_page_index *page_index;
4322 int i, j, prev;
4470 int i, j, k, prev;
4323
4324 memcpy(&lun->log_pages.index, log_page_index_template,
4325 sizeof(log_page_index_template));
4326
4327 prev = -1;
4471
4472 memcpy(&lun->log_pages.index, log_page_index_template,
4473 sizeof(log_page_index_template));
4474
4475 prev = -1;
4328 for (i = 0, j = 0; i < CTL_NUM_LOG_PAGES; i++) {
4476 for (i = 0, j = 0, k = 0; i < CTL_NUM_LOG_PAGES; i++) {
4329
4330 page_index = &lun->log_pages.index[i];
4331 /*
4332 * If this is a disk-only mode page, there's no point in
4333 * setting it up. For some pages, we have to have some
4334 * basic information about the disk in order to calculate the
4335 * mode page data.
4336 */
4337 if ((lun->be_lun->lun_type != T_DIRECT)
4338 && (page_index->page_flags & CTL_PAGE_FLAG_DISK_ONLY))
4339 continue;
4340
4477
4478 page_index = &lun->log_pages.index[i];
4479 /*
4480 * If this is a disk-only mode page, there's no point in
4481 * setting it up. For some pages, we have to have some
4482 * basic information about the disk in order to calculate the
4483 * mode page data.
4484 */
4485 if ((lun->be_lun->lun_type != T_DIRECT)
4486 && (page_index->page_flags & CTL_PAGE_FLAG_DISK_ONLY))
4487 continue;
4488
4489 if (page_index->page_code == SLS_LOGICAL_BLOCK_PROVISIONING &&
4490 ((lun->be_lun->flags & CTL_LUN_FLAG_UNMAP) == 0 ||
4491 lun->backend->lun_attr == NULL))
4492 continue;
4493
4341 if (page_index->page_code != prev) {
4342 lun->log_pages.pages_page[j] = page_index->page_code;
4343 prev = page_index->page_code;
4344 j++;
4345 }
4494 if (page_index->page_code != prev) {
4495 lun->log_pages.pages_page[j] = page_index->page_code;
4496 prev = page_index->page_code;
4497 j++;
4498 }
4346 lun->log_pages.subpages_page[i*2] = page_index->page_code;
4347 lun->log_pages.subpages_page[i*2+1] = page_index->subpage;
4499 lun->log_pages.subpages_page[k*2] = page_index->page_code;
4500 lun->log_pages.subpages_page[k*2+1] = page_index->subpage;
4501 k++;
4348 }
4349 lun->log_pages.index[0].page_data = &lun->log_pages.pages_page[0];
4350 lun->log_pages.index[0].page_len = j;
4351 lun->log_pages.index[1].page_data = &lun->log_pages.subpages_page[0];
4502 }
4503 lun->log_pages.index[0].page_data = &lun->log_pages.pages_page[0];
4504 lun->log_pages.index[0].page_len = j;
4505 lun->log_pages.index[1].page_data = &lun->log_pages.subpages_page[0];
4352 lun->log_pages.index[1].page_len = i * 2;
4506 lun->log_pages.index[1].page_len = k * 2;
4507 lun->log_pages.index[2].page_data = &lun->log_pages.lbp_page[0];
4508 lun->log_pages.index[2].page_len = 12*CTL_NUM_LBP_PARAMS;
4353
4354 return (CTL_RETVAL_COMPLETE);
4355}
4356
4357static int
4358hex2bin(const char *str, uint8_t *buf, int buf_size)
4359{
4360 int i;

--- 2572 unchanged lines hidden (view full) ---

6933 ctsio->io_hdr.flags |= CTL_FLAG_ALLOCATED;
6934 ctsio->be_move_done = ctl_config_move_done;
6935 ctl_datamove((union ctl_io *)ctsio);
6936
6937 return (CTL_RETVAL_COMPLETE);
6938}
6939
6940int
4509
4510 return (CTL_RETVAL_COMPLETE);
4511}
4512
4513static int
4514hex2bin(const char *str, uint8_t *buf, int buf_size)
4515{
4516 int i;

--- 2572 unchanged lines hidden (view full) ---

7089 ctsio->io_hdr.flags |= CTL_FLAG_ALLOCATED;
7090 ctsio->be_move_done = ctl_config_move_done;
7091 ctl_datamove((union ctl_io *)ctsio);
7092
7093 return (CTL_RETVAL_COMPLETE);
7094}
7095
7096int
7097ctl_lbp_log_sense_handler(struct ctl_scsiio *ctsio,
7098 struct ctl_page_index *page_index,
7099 int pc)
7100{
7101 struct ctl_lun *lun;
7102 struct scsi_log_param_header *phdr;
7103 uint8_t *data;
7104 uint64_t val;
7105
7106 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
7107 data = page_index->page_data;
7108
7109 if (lun->backend->lun_attr != NULL &&
7110 (val = lun->backend->lun_attr(lun->be_lun->be_lun, "blocksavail"))
7111 != UINT64_MAX) {
7112 phdr = (struct scsi_log_param_header *)data;
7113 scsi_ulto2b(0x0001, phdr->param_code);
7114 phdr->param_control = SLP_LBIN | SLP_LP;
7115 phdr->param_len = 8;
7116 data = (uint8_t *)(phdr + 1);
7117 scsi_ulto4b(val >> CTL_LBP_EXPONENT, data);
7118 data[4] = 0x01; /* per-LUN */
7119 data += phdr->param_len;
7120 }
7121
7122 if (lun->backend->lun_attr != NULL &&
7123 (val = lun->backend->lun_attr(lun->be_lun->be_lun, "blocksused"))
7124 != UINT64_MAX) {
7125 phdr = (struct scsi_log_param_header *)data;
7126 scsi_ulto2b(0x0002, phdr->param_code);
7127 phdr->param_control = SLP_LBIN | SLP_LP;
7128 phdr->param_len = 8;
7129 data = (uint8_t *)(phdr + 1);
7130 scsi_ulto4b(val >> CTL_LBP_EXPONENT, data);
7131 data[4] = 0x02; /* per-pool */
7132 data += phdr->param_len;
7133 }
7134
7135 if (lun->backend->lun_attr != NULL &&
7136 (val = lun->backend->lun_attr(lun->be_lun->be_lun, "poolblocksavail"))
7137 != UINT64_MAX) {
7138 phdr = (struct scsi_log_param_header *)data;
7139 scsi_ulto2b(0x00f1, phdr->param_code);
7140 phdr->param_control = SLP_LBIN | SLP_LP;
7141 phdr->param_len = 8;
7142 data = (uint8_t *)(phdr + 1);
7143 scsi_ulto4b(val >> CTL_LBP_EXPONENT, data);
7144 data[4] = 0x02; /* per-pool */
7145 data += phdr->param_len;
7146 }
7147
7148 if (lun->backend->lun_attr != NULL &&
7149 (val = lun->backend->lun_attr(lun->be_lun->be_lun, "poolblocksused"))
7150 != UINT64_MAX) {
7151 phdr = (struct scsi_log_param_header *)data;
7152 scsi_ulto2b(0x00f2, phdr->param_code);
7153 phdr->param_control = SLP_LBIN | SLP_LP;
7154 phdr->param_len = 8;
7155 data = (uint8_t *)(phdr + 1);
7156 scsi_ulto4b(val >> CTL_LBP_EXPONENT, data);
7157 data[4] = 0x02; /* per-pool */
7158 data += phdr->param_len;
7159 }
7160
7161 page_index->page_len = data - page_index->page_data;
7162 return (0);
7163}
7164
7165int
6941ctl_log_sense(struct ctl_scsiio *ctsio)
6942{
6943 struct ctl_lun *lun;
6944 int i, pc, page_code, subpage;
6945 int alloc_len, total_len;
6946 struct ctl_page_index *page_index;
6947 struct scsi_log_sense *cdb;
6948 struct scsi_log_header *header;

--- 3291 unchanged lines hidden (view full) ---

10240 lbp_ptr->device = (SID_QUAL_LU_CONNECTED << 5) |
10241 lun->be_lun->lun_type;
10242 else
10243 lbp_ptr->device = (SID_QUAL_LU_OFFLINE << 5) | T_DIRECT;
10244
10245 lbp_ptr->page_code = SVPD_LBP;
10246 scsi_ulto2b(sizeof(*lbp_ptr) - 4, lbp_ptr->page_length);
10247 if (lun != NULL && lun->be_lun->flags & CTL_LUN_FLAG_UNMAP) {
7166ctl_log_sense(struct ctl_scsiio *ctsio)
7167{
7168 struct ctl_lun *lun;
7169 int i, pc, page_code, subpage;
7170 int alloc_len, total_len;
7171 struct ctl_page_index *page_index;
7172 struct scsi_log_sense *cdb;
7173 struct scsi_log_header *header;

--- 3291 unchanged lines hidden (view full) ---

10465 lbp_ptr->device = (SID_QUAL_LU_CONNECTED << 5) |
10466 lun->be_lun->lun_type;
10467 else
10468 lbp_ptr->device = (SID_QUAL_LU_OFFLINE << 5) | T_DIRECT;
10469
10470 lbp_ptr->page_code = SVPD_LBP;
10471 scsi_ulto2b(sizeof(*lbp_ptr) - 4, lbp_ptr->page_length);
10472 if (lun != NULL && lun->be_lun->flags & CTL_LUN_FLAG_UNMAP) {
10473 lbp_ptr->threshold_exponent = CTL_LBP_EXPONENT;
10248 lbp_ptr->flags = SVPD_LBP_UNMAP | SVPD_LBP_WS16 |
10249 SVPD_LBP_WS10 | SVPD_LBP_RZ | SVPD_LBP_ANC_SUP;
10474 lbp_ptr->flags = SVPD_LBP_UNMAP | SVPD_LBP_WS16 |
10475 SVPD_LBP_WS10 | SVPD_LBP_RZ | SVPD_LBP_ANC_SUP;
10250 lbp_ptr->prov_type = SVPD_LBP_RESOURCE;
10476 lbp_ptr->prov_type = SVPD_LBP_THIN;
10251 }
10252
10253 ctsio->scsi_status = SCSI_STATUS_OK;
10254 ctsio->io_hdr.flags |= CTL_FLAG_ALLOCATED;
10255 ctsio->be_move_done = ctl_config_move_done;
10256 ctl_datamove((union ctl_io *)ctsio);
10257
10258 return (CTL_RETVAL_COMPLETE);

--- 3730 unchanged lines hidden (view full) ---

13989
13990 /* Sleep until we have something to do. */
13991 mtx_sleep(&softc->pending_lun_queue, &softc->ctl_lock,
13992 PDROP | PRIBIO, "-", 0);
13993 }
13994}
13995
13996static void
10477 }
10478
10479 ctsio->scsi_status = SCSI_STATUS_OK;
10480 ctsio->io_hdr.flags |= CTL_FLAG_ALLOCATED;
10481 ctsio->be_move_done = ctl_config_move_done;
10482 ctl_datamove((union ctl_io *)ctsio);
10483
10484 return (CTL_RETVAL_COMPLETE);

--- 3730 unchanged lines hidden (view full) ---

14215
14216 /* Sleep until we have something to do. */
14217 mtx_sleep(&softc->pending_lun_queue, &softc->ctl_lock,
14218 PDROP | PRIBIO, "-", 0);
14219 }
14220}
14221
14222static void
14223ctl_thresh_thread(void *arg)
14224{
14225 struct ctl_softc *softc = (struct ctl_softc *)arg;
14226 struct ctl_lun *lun;
14227 struct ctl_be_lun *be_lun;
14228 struct scsi_da_rw_recovery_page *rwpage;
14229 struct ctl_logical_block_provisioning_page *page;
14230 const char *attr;
14231 uint64_t thres, val;
14232 int i, e;
14233
14234 CTL_DEBUG_PRINT(("ctl_thresh_thread starting\n"));
14235
14236 for (;;) {
14237 mtx_lock(&softc->ctl_lock);
14238 STAILQ_FOREACH(lun, &softc->lun_list, links) {
14239 be_lun = lun->be_lun;
14240 if ((lun->flags & CTL_LUN_DISABLED) ||
14241 (lun->flags & CTL_LUN_OFFLINE) ||
14242 (be_lun->flags & CTL_LUN_FLAG_UNMAP) == 0 ||
14243 lun->backend->lun_attr == NULL)
14244 continue;
14245 rwpage = &lun->mode_pages.rw_er_page[CTL_PAGE_CURRENT];
14246 if ((rwpage->byte8 & SMS_RWER_LBPERE) == 0)
14247 continue;
14248 e = 0;
14249 page = &lun->mode_pages.lbp_page[CTL_PAGE_CURRENT];
14250 for (i = 0; i < CTL_NUM_LBP_THRESH; i++) {
14251 if ((page->descr[i].flags & SLBPPD_ENABLED) == 0)
14252 continue;
14253 thres = scsi_4btoul(page->descr[i].count);
14254 thres <<= CTL_LBP_EXPONENT;
14255 switch (page->descr[i].resource) {
14256 case 0x01:
14257 attr = "blocksavail";
14258 break;
14259 case 0x02:
14260 attr = "blocksused";
14261 break;
14262 case 0xf1:
14263 attr = "poolblocksavail";
14264 break;
14265 case 0xf2:
14266 attr = "poolblocksused";
14267 break;
14268 default:
14269 continue;
14270 }
14271 mtx_unlock(&softc->ctl_lock); // XXX
14272 val = lun->backend->lun_attr(
14273 lun->be_lun->be_lun, attr);
14274 mtx_lock(&softc->ctl_lock);
14275 if (val == UINT64_MAX)
14276 continue;
14277 if ((page->descr[i].flags & SLBPPD_ARMING_MASK)
14278 == SLBPPD_ARMING_INC)
14279 e |= (val >= thres);
14280 else
14281 e |= (val <= thres);
14282 }
14283 mtx_lock(&lun->lun_lock);
14284 if (e) {
14285 if (lun->lasttpt == 0 ||
14286 time_uptime - lun->lasttpt >= CTL_LBP_UA_PERIOD) {
14287 lun->lasttpt = time_uptime;
14288 for (i = 0; i < CTL_MAX_INITIATORS; i++)
14289 lun->pending_ua[i] |=
14290 CTL_UA_THIN_PROV_THRES;
14291 }
14292 } else {
14293 lun->lasttpt = 0;
14294 for (i = 0; i < CTL_MAX_INITIATORS; i++)
14295 lun->pending_ua[i] &= ~CTL_UA_THIN_PROV_THRES;
14296 }
14297 mtx_unlock(&lun->lun_lock);
14298 }
14299 mtx_unlock(&softc->ctl_lock);
14300 pause("-", CTL_LBP_PERIOD * hz);
14301 }
14302}
14303
14304static void
13997ctl_enqueue_incoming(union ctl_io *io)
13998{
13999 struct ctl_softc *softc = control_softc;
14000 struct ctl_thread *thr;
14001 u_int idx;
14002
14003 idx = (io->io_hdr.nexus.targ_port * 127 +
14004 io->io_hdr.nexus.initid.id) % worker_threads;

--- 149 unchanged lines hidden ---
14305ctl_enqueue_incoming(union ctl_io *io)
14306{
14307 struct ctl_softc *softc = control_softc;
14308 struct ctl_thread *thr;
14309 u_int idx;
14310
14311 idx = (io->io_hdr.nexus.targ_port * 127 +
14312 io->io_hdr.nexus.initid.id) % worker_threads;

--- 149 unchanged lines hidden ---