aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/ctld/kernel.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/ctld/kernel.c')
-rw-r--r--usr.sbin/ctld/kernel.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/usr.sbin/ctld/kernel.c b/usr.sbin/ctld/kernel.c
index b75527f16dbb8..b9658b5c73eae 100644
--- a/usr.sbin/ctld/kernel.c
+++ b/usr.sbin/ctld/kernel.c
@@ -108,6 +108,7 @@ struct cctl_lun_nv {
struct cctl_lun {
uint64_t lun_id;
char *backend_type;
+ uint8_t device_type;
uint64_t size_blocks;
uint32_t blocksize;
char *serial_number;
@@ -119,6 +120,7 @@ struct cctl_lun {
struct cctl_port {
uint32_t port_id;
+ char *port_frontend;
char *port_name;
int pp;
int vp;
@@ -220,6 +222,8 @@ cctl_end_element(void *user_data, const char *name)
if (strcmp(name, "backend_type") == 0) {
cur_lun->backend_type = str;
str = NULL;
+ } else if (strcmp(name, "lun_type") == 0) {
+ cur_lun->device_type = strtoull(str, NULL, 0);
} else if (strcmp(name, "size") == 0) {
cur_lun->size_blocks = strtoull(str, NULL, 0);
} else if (strcmp(name, "blocksize") == 0) {
@@ -331,7 +335,10 @@ cctl_end_pelement(void *user_data, const char *name)
devlist->cur_sb[devlist->level] = NULL;
devlist->level--;
- if (strcmp(name, "port_name") == 0) {
+ if (strcmp(name, "frontend_type") == 0) {
+ cur_port->port_frontend = str;
+ str = NULL;
+ } else if (strcmp(name, "port_name") == 0) {
cur_port->port_name = str;
str = NULL;
} else if (strcmp(name, "physical_port") == 0) {
@@ -471,7 +478,7 @@ retry_port:
return (NULL);
}
- if (list.status == CTL_PORT_LIST_ERROR) {
+ if (list.status == CTL_LUN_LIST_ERROR) {
log_warnx("error returned from CTL_PORT_LIST ioctl: %s",
list.error_str);
free(str);
@@ -506,6 +513,8 @@ retry_port:
name = NULL;
STAILQ_FOREACH(port, &devlist.port_list, links) {
+ if (strcmp(port->port_frontend, "ha") == 0)
+ continue;
if (name)
free(name);
if (port->pp == 0 && port->vp == 0)
@@ -604,6 +613,7 @@ retry_port:
continue;
}
lun_set_backend(cl, lun->backend_type);
+ lun_set_device_type(cl, lun->device_type);
lun_set_blocksize(cl, lun->blocksize);
lun_set_device_id(cl, lun->device_id);
lun_set_serial(cl, lun->serial_number);
@@ -656,8 +666,13 @@ kernel_lun_add(struct lun *lun)
if (lun->l_size != 0)
req.reqdata.create.lun_size_bytes = lun->l_size;
+ if (lun->l_ctl_lun >= 0) {
+ req.reqdata.create.req_lun_id = lun->l_ctl_lun;
+ req.reqdata.create.flags |= CTL_LUN_FLAG_ID_REQ;
+ }
+
req.reqdata.create.flags |= CTL_LUN_FLAG_DEV_TYPE;
- req.reqdata.create.device_type = T_DIRECT;
+ req.reqdata.create.device_type = lun->l_device_type;
if (lun->l_serial != NULL) {
strncpy(req.reqdata.create.serial_num, lun->l_serial,
@@ -1024,11 +1039,13 @@ kernel_port_add(struct port *port)
}
int
-kernel_port_update(struct port *port)
+kernel_port_update(struct port *port, struct port *oport)
{
struct ctl_lun_map lm;
struct target *targ = port->p_target;
+ struct target *otarg = oport->p_target;
int error, i;
+ uint32_t olun;
/* Map configured LUNs and unmap others */
for (i = 0; i < MAX_LUNS; i++) {
@@ -1038,6 +1055,12 @@ kernel_port_update(struct port *port)
lm.lun = UINT32_MAX;
else
lm.lun = targ->t_luns[i]->l_ctl_lun;
+ if (otarg->t_luns[i] == NULL)
+ olun = UINT32_MAX;
+ else
+ olun = otarg->t_luns[i]->l_ctl_lun;
+ if (lm.lun == olun)
+ continue;
error = ioctl(ctl_fd, CTL_LUN_MAP, &lm);
if (error != 0)
log_warn("CTL_LUN_MAP ioctl failed");