in target_core_pr.c [1866:1961]
static int core_scsi3_update_aptpl_buf(
struct se_device *dev,
unsigned char *buf,
u32 pr_aptpl_buf_len)
{
struct se_portal_group *tpg;
struct t10_pr_registration *pr_reg;
unsigned char tmp[512], isid_buf[32];
ssize_t len = 0;
int reg_count = 0;
int ret = 0;
spin_lock(&dev->dev_reservation_lock);
spin_lock(&dev->t10_pr.registration_lock);
/*
* Walk the registration list..
*/
list_for_each_entry(pr_reg, &dev->t10_pr.registration_list,
pr_reg_list) {
tmp[0] = '\0';
isid_buf[0] = '\0';
tpg = pr_reg->pr_reg_nacl->se_tpg;
/*
* Write out any ISID value to APTPL metadata that was included
* in the original registration.
*/
if (pr_reg->isid_present_at_reg)
snprintf(isid_buf, 32, "initiator_sid=%s\n",
pr_reg->pr_reg_isid);
/*
* Include special metadata if the pr_reg matches the
* reservation holder.
*/
if (dev->dev_pr_res_holder == pr_reg) {
snprintf(tmp, 512, "PR_REG_START: %d"
"\ninitiator_fabric=%s\n"
"initiator_node=%s\n%s"
"sa_res_key=%llu\n"
"res_holder=1\nres_type=%02x\n"
"res_scope=%02x\nres_all_tg_pt=%d\n"
"mapped_lun=%llu\n", reg_count,
tpg->se_tpg_tfo->fabric_name,
pr_reg->pr_reg_nacl->initiatorname, isid_buf,
pr_reg->pr_res_key, pr_reg->pr_res_type,
pr_reg->pr_res_scope, pr_reg->pr_reg_all_tg_pt,
pr_reg->pr_res_mapped_lun);
} else {
snprintf(tmp, 512, "PR_REG_START: %d\n"
"initiator_fabric=%s\ninitiator_node=%s\n%s"
"sa_res_key=%llu\nres_holder=0\n"
"res_all_tg_pt=%d\nmapped_lun=%llu\n",
reg_count, tpg->se_tpg_tfo->fabric_name,
pr_reg->pr_reg_nacl->initiatorname, isid_buf,
pr_reg->pr_res_key, pr_reg->pr_reg_all_tg_pt,
pr_reg->pr_res_mapped_lun);
}
if ((len + strlen(tmp) >= pr_aptpl_buf_len)) {
pr_err("Unable to update renaming APTPL metadata,"
" reallocating larger buffer\n");
ret = -EMSGSIZE;
goto out;
}
len += sprintf(buf+len, "%s", tmp);
/*
* Include information about the associated SCSI target port.
*/
snprintf(tmp, 512, "target_fabric=%s\ntarget_node=%s\n"
"tpgt=%hu\nport_rtpi=%hu\ntarget_lun=%llu\nPR_REG_END:"
" %d\n", tpg->se_tpg_tfo->fabric_name,
tpg->se_tpg_tfo->tpg_get_wwn(tpg),
tpg->se_tpg_tfo->tpg_get_tag(tpg),
pr_reg->tg_pt_sep_rtpi, pr_reg->pr_aptpl_target_lun,
reg_count);
if ((len + strlen(tmp) >= pr_aptpl_buf_len)) {
pr_err("Unable to update renaming APTPL metadata,"
" reallocating larger buffer\n");
ret = -EMSGSIZE;
goto out;
}
len += sprintf(buf+len, "%s", tmp);
reg_count++;
}
if (!reg_count)
len += sprintf(buf+len, "No Registrations or Reservations");
out:
spin_unlock(&dev->t10_pr.registration_lock);
spin_unlock(&dev->dev_reservation_lock);
return ret;
}