Changeset View
Changeset View
Standalone View
Standalone View
sys/cam/ctl/ctl_backend_block.c
Context not available. | |||||
#include <sys/sdt.h> | #include <sys/sdt.h> | ||||
#include <sys/devicestat.h> | #include <sys/devicestat.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/nv.h> | |||||
#include <sys/dnv.h> | |||||
#include <geom/geom.h> | #include <geom/geom.h> | ||||
Context not available. | |||||
struct ctl_be_lun *cbe_lun; | struct ctl_be_lun *cbe_lun; | ||||
struct ctl_be_block_filedata *file_data; | struct ctl_be_block_filedata *file_data; | ||||
struct ctl_lun_create_params *params; | struct ctl_lun_create_params *params; | ||||
char *value; | const char *value; | ||||
struct vattr vattr; | struct vattr vattr; | ||||
off_t ps, pss, po, pos, us, uss, uo, uos; | off_t ps, pss, po, pos, us, uss, uo, uos; | ||||
int error; | int error; | ||||
Context not available. | |||||
us = ps = vattr.va_blocksize; | us = ps = vattr.va_blocksize; | ||||
uo = po = 0; | uo = po = 0; | ||||
value = ctl_get_opt(&cbe_lun->options, "pblocksize"); | value = dnvlist_get_string(cbe_lun->options, "pblocksize", NULL); | ||||
if (value != NULL) | if (value != NULL) | ||||
ctl_expand_number(value, &ps); | ctl_expand_number(value, &ps); | ||||
value = ctl_get_opt(&cbe_lun->options, "pblockoffset"); | value = dnvlist_get_string(cbe_lun->options, "pblockoffset", NULL); | ||||
if (value != NULL) | if (value != NULL) | ||||
ctl_expand_number(value, &po); | ctl_expand_number(value, &po); | ||||
pss = ps / cbe_lun->blocksize; | pss = ps / cbe_lun->blocksize; | ||||
Context not available. | |||||
cbe_lun->pblockoff = (pss - pos) % pss; | cbe_lun->pblockoff = (pss - pos) % pss; | ||||
} | } | ||||
value = ctl_get_opt(&cbe_lun->options, "ublocksize"); | value = dnvlist_get_string(cbe_lun->options, "ublocksize", NULL); | ||||
if (value != NULL) | if (value != NULL) | ||||
ctl_expand_number(value, &us); | ctl_expand_number(value, &us); | ||||
value = ctl_get_opt(&cbe_lun->options, "ublockoffset"); | value = dnvlist_get_string(cbe_lun->options, "ublockoffset", NULL); | ||||
if (value != NULL) | if (value != NULL) | ||||
ctl_expand_number(value, &uo); | ctl_expand_number(value, &uo); | ||||
uss = us / cbe_lun->blocksize; | uss = us / cbe_lun->blocksize; | ||||
Context not available. | |||||
struct ctl_lun_create_params *params; | struct ctl_lun_create_params *params; | ||||
struct cdevsw *csw; | struct cdevsw *csw; | ||||
struct cdev *dev; | struct cdev *dev; | ||||
char *value; | const char *value; | ||||
int error, atomic, maxio, ref, unmap, tmp; | int error, atomic, maxio, ref, unmap, tmp; | ||||
off_t ps, pss, po, pos, us, uss, uo, uos, otmp; | off_t ps, pss, po, pos, us, uss, uo, uos, otmp; | ||||
Context not available. | |||||
us = ps; | us = ps; | ||||
uo = po; | uo = po; | ||||
value = ctl_get_opt(&cbe_lun->options, "pblocksize"); | value = dnvlist_get_string(cbe_lun->options, "pblocksize", NULL); | ||||
if (value != NULL) | if (value != NULL) | ||||
ctl_expand_number(value, &ps); | ctl_expand_number(value, &ps); | ||||
value = ctl_get_opt(&cbe_lun->options, "pblockoffset"); | value = dnvlist_get_string(cbe_lun->options, "pblockoffset", NULL); | ||||
if (value != NULL) | if (value != NULL) | ||||
ctl_expand_number(value, &po); | ctl_expand_number(value, &po); | ||||
pss = ps / cbe_lun->blocksize; | pss = ps / cbe_lun->blocksize; | ||||
Context not available. | |||||
cbe_lun->pblockoff = (pss - pos) % pss; | cbe_lun->pblockoff = (pss - pos) % pss; | ||||
} | } | ||||
value = ctl_get_opt(&cbe_lun->options, "ublocksize"); | value = dnvlist_get_string(cbe_lun->options, "ublocksize", NULL); | ||||
if (value != NULL) | if (value != NULL) | ||||
ctl_expand_number(value, &us); | ctl_expand_number(value, &us); | ||||
value = ctl_get_opt(&cbe_lun->options, "ublockoffset"); | value = dnvlist_get_string(cbe_lun->options, "ublockoffset", NULL); | ||||
if (value != NULL) | if (value != NULL) | ||||
ctl_expand_number(value, &uo); | ctl_expand_number(value, &uo); | ||||
uss = us / cbe_lun->blocksize; | uss = us / cbe_lun->blocksize; | ||||
Context not available. | |||||
curthread); | curthread); | ||||
unmap = (error == 0) ? arg.value.i : 0; | unmap = (error == 0) ? arg.value.i : 0; | ||||
} | } | ||||
value = ctl_get_opt(&cbe_lun->options, "unmap"); | value = dnvlist_get_string(cbe_lun->options, "unmap", NULL); | ||||
if (value != NULL) | if (value != NULL) | ||||
unmap = (strcmp(value, "on") == 0); | unmap = (strcmp(value, "on") == 0); | ||||
if (unmap) | if (unmap) | ||||
Context not available. | |||||
{ | { | ||||
struct ctl_be_lun *cbe_lun = &be_lun->cbe_lun; | struct ctl_be_lun *cbe_lun = &be_lun->cbe_lun; | ||||
struct nameidata nd; | struct nameidata nd; | ||||
char *value; | const char *value; | ||||
int error, flags; | int error, flags; | ||||
error = 0; | error = 0; | ||||
Context not available. | |||||
} | } | ||||
pwd_ensure_dirs(); | pwd_ensure_dirs(); | ||||
value = ctl_get_opt(&cbe_lun->options, "file"); | value = dnvlist_get_string(cbe_lun->options, "file", NULL); | ||||
if (value == NULL) { | if (value == NULL) { | ||||
snprintf(req->error_str, sizeof(req->error_str), | snprintf(req->error_str, sizeof(req->error_str), | ||||
"no file argument specified"); | "no file argument specified"); | ||||
Context not available. | |||||
be_lun->dev_path = strdup(value, M_CTLBLK); | be_lun->dev_path = strdup(value, M_CTLBLK); | ||||
flags = FREAD; | flags = FREAD; | ||||
value = ctl_get_opt(&cbe_lun->options, "readonly"); | value = dnvlist_get_string(cbe_lun->options, "readonly", NULL); | ||||
if (value != NULL) { | if (value != NULL) { | ||||
if (strcmp(value, "on") != 0) | if (strcmp(value, "on") != 0) | ||||
flags |= FWRITE; | flags |= FWRITE; | ||||
Context not available. | |||||
cbe_lun->serseq = CTL_LUN_SERSEQ_OFF; | cbe_lun->serseq = CTL_LUN_SERSEQ_OFF; | ||||
if (be_lun->dispatch != ctl_be_block_dispatch_dev) | if (be_lun->dispatch != ctl_be_block_dispatch_dev) | ||||
cbe_lun->serseq = CTL_LUN_SERSEQ_READ; | cbe_lun->serseq = CTL_LUN_SERSEQ_READ; | ||||
value = ctl_get_opt(&cbe_lun->options, "serseq"); | value = dnvlist_get_string(cbe_lun->options, "serseq", NULL); | ||||
if (value != NULL && strcmp(value, "on") == 0) | if (value != NULL && strcmp(value, "on") == 0) | ||||
cbe_lun->serseq = CTL_LUN_SERSEQ_ON; | cbe_lun->serseq = CTL_LUN_SERSEQ_ON; | ||||
else if (value != NULL && strcmp(value, "read") == 0) | else if (value != NULL && strcmp(value, "read") == 0) | ||||
Context not available. | |||||
struct ctl_lun_create_params *params; | struct ctl_lun_create_params *params; | ||||
char num_thread_str[16]; | char num_thread_str[16]; | ||||
char tmpstr[32]; | char tmpstr[32]; | ||||
char *value; | const char *value; | ||||
int retval, num_threads; | int retval, num_threads; | ||||
int tmp_num_threads; | int tmp_num_threads; | ||||
Context not available. | |||||
sprintf(be_lun->lunname, "cblk%d", softc->num_luns); | sprintf(be_lun->lunname, "cblk%d", softc->num_luns); | ||||
mtx_init(&be_lun->io_lock, "cblk io lock", NULL, MTX_DEF); | mtx_init(&be_lun->io_lock, "cblk io lock", NULL, MTX_DEF); | ||||
mtx_init(&be_lun->queue_lock, "cblk queue lock", NULL, MTX_DEF); | mtx_init(&be_lun->queue_lock, "cblk queue lock", NULL, MTX_DEF); | ||||
ctl_init_opts(&cbe_lun->options, | cbe_lun->options = nvlist_clone(req->args_nvl); | ||||
req->num_be_args, req->kern_be_args); | |||||
be_lun->lun_zone = uma_zcreate(be_lun->lunname, CTLBLK_MAX_SEG, | be_lun->lun_zone = uma_zcreate(be_lun->lunname, CTLBLK_MAX_SEG, | ||||
NULL, NULL, NULL, NULL, /*align*/ 0, /*flags*/0); | NULL, NULL, NULL, NULL, /*align*/ 0, /*flags*/0); | ||||
if (be_lun->lun_zone == NULL) { | if (be_lun->lun_zone == NULL) { | ||||
Context not available. | |||||
cbe_lun->lun_type = T_DIRECT; | cbe_lun->lun_type = T_DIRECT; | ||||
be_lun->flags = CTL_BE_BLOCK_LUN_UNCONFIGURED; | be_lun->flags = CTL_BE_BLOCK_LUN_UNCONFIGURED; | ||||
cbe_lun->flags = 0; | cbe_lun->flags = 0; | ||||
value = ctl_get_opt(&cbe_lun->options, "ha_role"); | value = dnvlist_get_string(cbe_lun->options, "ha_role", NULL); | ||||
if (value != NULL) { | if (value != NULL) { | ||||
if (strcmp(value, "primary") == 0) | if (strcmp(value, "primary") == 0) | ||||
cbe_lun->flags |= CTL_LUN_FLAG_PRIMARY; | cbe_lun->flags |= CTL_LUN_FLAG_PRIMARY; | ||||
Context not available. | |||||
num_threads = 1; | num_threads = 1; | ||||
} | } | ||||
value = ctl_get_opt(&cbe_lun->options, "num_threads"); | value = dnvlist_get_string(cbe_lun->options, "num_threads", NULL); | ||||
if (value != NULL) { | if (value != NULL) { | ||||
tmp_num_threads = strtol(value, NULL, 0); | tmp_num_threads = strtol(value, NULL, 0); | ||||
Context not available. | |||||
free(be_lun->dev_path, M_CTLBLK); | free(be_lun->dev_path, M_CTLBLK); | ||||
if (be_lun->lun_zone != NULL) | if (be_lun->lun_zone != NULL) | ||||
uma_zdestroy(be_lun->lun_zone); | uma_zdestroy(be_lun->lun_zone); | ||||
ctl_free_opts(&cbe_lun->options); | nvlist_destroy(cbe_lun->options); | ||||
mtx_destroy(&be_lun->queue_lock); | mtx_destroy(&be_lun->queue_lock); | ||||
mtx_destroy(&be_lun->io_lock); | mtx_destroy(&be_lun->io_lock); | ||||
free(be_lun, M_CTLBLK); | free(be_lun, M_CTLBLK); | ||||
Context not available. | |||||
uma_zdestroy(be_lun->lun_zone); | uma_zdestroy(be_lun->lun_zone); | ||||
ctl_free_opts(&cbe_lun->options); | nvlist_destroy(cbe_lun->options); | ||||
free(be_lun->dev_path, M_CTLBLK); | free(be_lun->dev_path, M_CTLBLK); | ||||
mtx_destroy(&be_lun->queue_lock); | mtx_destroy(&be_lun->queue_lock); | ||||
mtx_destroy(&be_lun->io_lock); | mtx_destroy(&be_lun->io_lock); | ||||
Context not available. | |||||
struct ctl_lun_modify_params *params; | struct ctl_lun_modify_params *params; | ||||
struct ctl_be_block_lun *be_lun; | struct ctl_be_block_lun *be_lun; | ||||
struct ctl_be_lun *cbe_lun; | struct ctl_be_lun *cbe_lun; | ||||
char *value; | const char *value; | ||||
uint64_t oldsize; | uint64_t oldsize; | ||||
int error, wasprim; | int error, wasprim; | ||||
Context not available. | |||||
if (params->lun_size_bytes != 0) | if (params->lun_size_bytes != 0) | ||||
be_lun->params.lun_size_bytes = params->lun_size_bytes; | be_lun->params.lun_size_bytes = params->lun_size_bytes; | ||||
ctl_update_opts(&cbe_lun->options, req->num_be_args, req->kern_be_args); | |||||
nvlist_destroy(cbe_lun->options); | |||||
cbe_lun->options = nvlist_clone(req->args_nvl); | |||||
wasprim = (cbe_lun->flags & CTL_LUN_FLAG_PRIMARY); | wasprim = (cbe_lun->flags & CTL_LUN_FLAG_PRIMARY); | ||||
value = ctl_get_opt(&cbe_lun->options, "ha_role"); | value = dnvlist_get_string(cbe_lun->options, "ha_role", NULL); | ||||
if (value != NULL) { | if (value != NULL) { | ||||
if (strcmp(value, "primary") == 0) | if (strcmp(value, "primary") == 0) | ||||
cbe_lun->flags |= CTL_LUN_FLAG_PRIMARY; | cbe_lun->flags |= CTL_LUN_FLAG_PRIMARY; | ||||
Context not available. |