scst: Replace sprintf() with scnprintf() in sysfs callbacks

Replace all uses of sprintf() with scnprintf() in sysfs attribute
callbacks to eliminate the risk of buffer overflows.

This patch does not change any functionality.
This commit is contained in:
Gleb Chesnokov
2025-05-16 13:27:25 +03:00
parent 4ce8735a92
commit 9cbca53830
13 changed files with 703 additions and 633 deletions

View File

@@ -25,28 +25,30 @@ static LIST_HEAD(iscsi_attrs_list);
static ssize_t iscsi_version_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
ssize_t ret = 0;
TRACE_ENTRY();
sprintf(buf, "%s\n", ISCSI_VERSION_STRING);
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%s\n", ISCSI_VERSION_STRING);
#ifdef CONFIG_SCST_EXTRACHECKS
strcat(buf, "EXTRACHECKS\n");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "EXTRACHECKS\n");
#endif
#ifdef CONFIG_SCST_TRACING
strcat(buf, "TRACING\n");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "TRACING\n");
#endif
#ifdef CONFIG_SCST_DEBUG
strcat(buf, "DEBUG\n");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "DEBUG\n");
#endif
#ifdef CONFIG_SCST_ISCSI_DEBUG_DIGEST_FAILURES
strcat(buf, "DEBUG_DIGEST_FAILURES\n");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "DEBUG_DIGEST_FAILURES\n");
#endif
TRACE_EXIT();
return strlen(buf);
return ret;
}
static struct kobj_attribute iscsi_version_attr =
@@ -54,22 +56,24 @@ static struct kobj_attribute iscsi_version_attr =
static ssize_t iscsi_open_state_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
ssize_t ret;
switch (ctr_open_state) {
case ISCSI_CTR_OPEN_STATE_CLOSED:
sprintf(buf, "closed\n");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "closed\n");
break;
case ISCSI_CTR_OPEN_STATE_OPEN:
sprintf(buf, "open\n");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "open\n");
break;
case ISCSI_CTR_OPEN_STATE_CLOSING:
sprintf(buf, "closing\n");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "closing\n");
break;
default:
sprintf(buf, "unknown\n");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "unknown\n");
break;
}
return strlen(buf);
return ret;
}
static struct kobj_attribute iscsi_open_state_attr =

View File

@@ -187,17 +187,17 @@ static struct kobj_attribute iscsi_conn_transport_attr =
static ssize_t iscsi_conn_cid_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
int pos;
struct iscsi_conn *conn;
ssize_t ret;
TRACE_ENTRY();
conn = container_of(kobj, struct iscsi_conn, conn_kobj);
pos = sprintf(buf, "%u", conn->cid);
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%u", conn->cid);
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static struct kobj_attribute iscsi_conn_cid_attr =

View File

@@ -380,19 +380,16 @@ void iscsi_sess_force_close(struct iscsi_session *sess)
#define ISCSI_SESS_BOOL_PARAM_ATTR(name, exported_name) \
static ssize_t iscsi_sess_show_##name(struct kobject *kobj, \
struct kobj_attribute *attr, char *buf) \
struct kobj_attribute *attr, char *buf) \
{ \
int pos; \
struct scst_session *scst_sess; \
struct iscsi_session *sess; \
\
scst_sess = container_of(kobj, struct scst_session, sess_kobj); \
sess = (struct iscsi_session *)scst_sess_get_tgt_priv(scst_sess); \
\
pos = sprintf(buf, "%s\n", \
iscsi_get_bool_value(sess->sess_params.name)); \
\
return pos; \
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", \
iscsi_get_bool_value(sess->sess_params.name)); \
} \
\
static struct kobj_attribute iscsi_sess_attr_##name = \
@@ -400,42 +397,37 @@ static struct kobj_attribute iscsi_sess_attr_##name = \
#define ISCSI_SESS_INT_PARAM_ATTR(name, exported_name) \
static ssize_t iscsi_sess_show_##name(struct kobject *kobj, \
struct kobj_attribute *attr, char *buf) \
struct kobj_attribute *attr, char *buf) \
{ \
int pos; \
struct scst_session *scst_sess; \
struct iscsi_session *sess; \
\
scst_sess = container_of(kobj, struct scst_session, sess_kobj); \
sess = (struct iscsi_session *)scst_sess_get_tgt_priv(scst_sess); \
\
pos = sprintf(buf, "%d\n", sess->sess_params.name); \
\
return pos; \
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", \
sess->sess_params.name); \
} \
\
static struct kobj_attribute iscsi_sess_attr_##name = \
__ATTR(exported_name, 0444, iscsi_sess_show_##name, NULL)
#define ISCSI_SESS_DIGEST_PARAM_ATTR(name, exported_name) \
static ssize_t iscsi_sess_show_##name(struct kobject *kobj, \
struct kobj_attribute *attr, char *buf) \
{ \
int pos; \
struct scst_session *scst_sess; \
struct iscsi_session *sess; \
char digest_name[64]; \
\
scst_sess = container_of(kobj, struct scst_session, sess_kobj); \
sess = (struct iscsi_session *)scst_sess_get_tgt_priv(scst_sess); \
\
pos = sprintf(buf, "%s\n", iscsi_get_digest_name( \
sess->sess_params.name, digest_name)); \
\
return pos; \
} \
\
static struct kobj_attribute iscsi_sess_attr_##name = \
#define ISCSI_SESS_DIGEST_PARAM_ATTR(name, exported_name) \
static ssize_t iscsi_sess_show_##name(struct kobject *kobj, \
struct kobj_attribute *attr, char *buf) \
{ \
struct scst_session *scst_sess; \
struct iscsi_session *sess; \
char digest_name[64]; \
\
scst_sess = container_of(kobj, struct scst_session, sess_kobj); \
sess = (struct iscsi_session *)scst_sess_get_tgt_priv(scst_sess); \
\
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", \
iscsi_get_digest_name(sess->sess_params.name, digest_name)); \
} \
\
static struct kobj_attribute iscsi_sess_attr_##name = \
__ATTR(exported_name, 0444, iscsi_sess_show_##name, NULL)
ISCSI_SESS_BOOL_PARAM_ATTR(initial_r2t, InitialR2T);
@@ -450,19 +442,19 @@ ISCSI_SESS_DIGEST_PARAM_ATTR(data_digest, DataDigest);
static ssize_t iscsi_sess_sid_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
int pos;
struct scst_session *scst_sess;
struct iscsi_session *sess;
ssize_t ret;
TRACE_ENTRY();
scst_sess = container_of(kobj, struct scst_session, sess_kobj);
sess = (struct iscsi_session *)scst_sess_get_tgt_priv(scst_sess);
pos = sprintf(buf, "%llx\n", sess->sid);
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%llx\n", sess->sid);
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static struct kobj_attribute iscsi_attr_sess_sid =
@@ -471,19 +463,19 @@ static struct kobj_attribute iscsi_attr_sess_sid =
static ssize_t iscsi_sess_reinstating_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
int pos;
struct scst_session *scst_sess;
struct iscsi_session *sess;
ssize_t ret;
TRACE_ENTRY();
scst_sess = container_of(kobj, struct scst_session, sess_kobj);
sess = (struct iscsi_session *)scst_sess_get_tgt_priv(scst_sess);
pos = sprintf(buf, "%d\n", sess->sess_reinstating ? 1 : 0);
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", sess->sess_reinstating ? 1 : 0);
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static struct kobj_attribute iscsi_sess_attr_reinstating =

View File

@@ -393,9 +393,9 @@ void target_del_all(void)
static ssize_t iscsi_tgt_tid_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
int res = -E_TGT_PRIV_NOT_YET_SET;
struct scst_tgt *scst_tgt;
struct iscsi_target *tgt;
ssize_t res = -E_TGT_PRIV_NOT_YET_SET;
TRACE_ENTRY();
@@ -404,7 +404,7 @@ static ssize_t iscsi_tgt_tid_show(struct kobject *kobj, struct kobj_attribute *a
if (!tgt)
goto out;
res = sprintf(buf, "%u\n", tgt->tid);
res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%u\n", tgt->tid);
out:
TRACE_EXIT_RES(res);
@@ -568,19 +568,20 @@ ssize_t iscsi_sysfs_mgmt_cmd(char *cmd)
static ssize_t iscsi_acg_sess_dedicated_threads_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
int pos;
struct scst_acg *acg;
bool dedicated;
ssize_t ret;
TRACE_ENTRY();
acg = container_of(kobj, struct scst_acg, acg_kobj);
dedicated = scst_get_acg_tgt_priv(acg);
pos = sprintf(buf, "%d\n%s", dedicated, dedicated ? SCST_SYSFS_KEY_MARK "\n" : "");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
dedicated, dedicated ? SCST_SYSFS_KEY_MARK "\n" : "");
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t iscsi_acg_sess_dedicated_threads_store(struct kobject *kobj,

View File

@@ -893,31 +893,34 @@ static void sqa_qla2xxx_shutdown_sess(struct fc_port *sess)
static ssize_t sqa_version_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
sprintf(buf, "INTERFACE=%s\nSCST=%s\nQLOGIC=%s\n", SQA_VERSION,
SCST_VERSION_NAME, QLA2XXX_VERSION);
ssize_t ret = 0;
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret,
"INTERFACE=%s\nSCST=%s\nQLOGIC=%s\n",
SQA_VERSION, SCST_VERSION_NAME, QLA2XXX_VERSION);
#ifdef CONFIG_SCST_EXTRACHECKS
strcat(buf, "EXTRACHECKS\n");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "EXTRACHECKS\n");
#endif
#ifdef CONFIG_SCST_TRACING
strcat(buf, "TRACING\n");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "TRACING\n");
#endif
#ifdef CONFIG_SCST_DEBUG
strcat(buf, "DEBUG\n");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "DEBUG\n");
#endif
#ifdef CONFIG_QLA_TGT_DEBUG_WORK_IN_THREAD
strcat(buf, "QLA_TGT_DEBUG_WORK_IN_THREAD\n");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "QLA_TGT_DEBUG_WORK_IN_THREAD\n");
#endif
#ifdef CONFIG_QLA_TGT_DEBUG_SRR
strcat(buf, "DEBUG_SRR\n");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "DEBUG_SRR\n");
#endif
TRACE_EXIT();
return strlen(buf);
return ret;
}
static ssize_t sqa_hw_target_show(struct kobject *kobj,
@@ -932,7 +935,8 @@ static ssize_t sqa_hw_target_show(struct kobject *kobj,
tgt = sqa_tgt->qla_tgt;
return sprintf(buf, "%d\n", (tgt->vha->vp_idx == 0) ? 1 : 0);
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n",
tgt->vha->vp_idx == 0 ? 1 : 0);
}
static ssize_t sqa_node_name_show(struct kobject *kobj,
@@ -969,9 +973,11 @@ static ssize_t sqa_node_name_show(struct kobject *kobj,
if (res != 0)
goto out;
res = sprintf(buf, "%s\n", wwn);
res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", wwn);
if (ha->tgt.node_name_set)
res += sprintf(&buf[res], "%s\n", SCST_SYSFS_KEY_MARK);
res += scnprintf(buf + res, SCST_SYSFS_BLOCK_SIZE - res, "%s\n",
SCST_SYSFS_KEY_MARK);
kfree(wwn);
@@ -1066,7 +1072,7 @@ static ssize_t sqa_vp_parent_host_show(struct kobject *kobj,
if (res != 0)
goto out;
res = sprintf(buf, "%s\n%s\n", wwn, SCST_SYSFS_KEY_MARK);
res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s\n", wwn, SCST_SYSFS_KEY_MARK);
kfree(wwn);
@@ -1083,20 +1089,16 @@ static ssize_t sqa_show_expl_conf_enabled(struct kobject *kobj,
struct sqa_scst_tgt *sqa_tgt;
struct qla_tgt *tgt;
struct qla_hw_data *ha;
ssize_t size;
scst_tgt = container_of(kobj, struct scst_tgt, tgt_kobj);
sqa_tgt = scst_tgt_get_tgt_priv(scst_tgt);
tgt = sqa_tgt->qla_tgt;
ha = tgt->ha;
size = scnprintf(buffer, PAGE_SIZE, "%d\n%s",
return scnprintf(buffer, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
ha->base_qpair->enable_explicit_conf,
ha->base_qpair->enable_explicit_conf ?
SCST_SYSFS_KEY_MARK "\n" : "");
return size;
}
static ssize_t sqa_store_expl_conf_enabled(struct kobject *kobj,

View File

@@ -6705,39 +6705,38 @@ out:
return res;
}
static ssize_t q2t_version_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
static ssize_t q2t_version_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
sprintf(buf, "%s\n", Q2T_VERSION_STRING);
size_t ret = 0;
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%s\n", Q2T_VERSION_STRING);
#ifdef CONFIG_SCST_EXTRACHECKS
strcat(buf, "EXTRACHECKS\n");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "EXTRACHECKS\n");
#endif
#ifdef CONFIG_SCST_TRACING
strcat(buf, "TRACING\n");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "TRACING\n");
#endif
#ifdef CONFIG_SCST_DEBUG
strcat(buf, "DEBUG\n");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "DEBUG\n");
#endif
#ifdef CONFIG_QLA_TGT_DEBUG_WORK_IN_THREAD
strcat(buf, "QLA_TGT_DEBUG_WORK_IN_THREAD\n");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "QLA_TGT_DEBUG_WORK_IN_THREAD\n");
#endif
TRACE_EXIT();
return strlen(buf);
return ret;
}
static ssize_t q2t_hw_target_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
static ssize_t q2t_hw_target_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
return sprintf(buf, "%d\n", 1);
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", 1);
}
static ssize_t q2t_node_name_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
static ssize_t q2t_node_name_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
struct scst_tgt *scst_tgt;
struct q2t_tgt *tgt;
@@ -6758,11 +6757,12 @@ static ssize_t q2t_node_name_show(struct kobject *kobj,
if (res != 0)
goto out;
res = sprintf(buf, "%s\n", wwn);
res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", wwn);
/* For virtual ports it's always key */
if (vha->node_name_set || (vha->vp_idx != 0))
res += sprintf(&buf[res], "%s\n", SCST_SYSFS_KEY_MARK);
res += scnprintf(buf + res, SCST_SYSFS_BLOCK_SIZE - res, "%s\n",
SCST_SYSFS_KEY_MARK);
kfree(wwn);
@@ -6837,15 +6837,14 @@ out_default:
goto abort;
}
static ssize_t q2t_port_name_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
static ssize_t q2t_port_name_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
struct scst_tgt *scst_tgt;
struct q2t_tgt *tgt;
scsi_qla_host_t *vha;
ssize_t res = -E_TGT_PRIV_NOT_YET_SET;
char *wwn;
uint8_t *port_name;
ssize_t res = -E_TGT_PRIV_NOT_YET_SET;
/* Can be called for both HW and V ports */
@@ -6861,11 +6860,12 @@ static ssize_t q2t_port_name_show(struct kobject *kobj,
if (res != 0)
goto out;
res = sprintf(buf, "%s\n", wwn);
res = scnprintf(buf, "%s\n", wwn);
/* For virtual ports it's always key */
if ((vha->vp_idx != 0) || vha->port_name_set)
res += sprintf(&buf[res], "%s\n", SCST_SYSFS_KEY_MARK);
res += scnprintf(buf + res, SCST_SYSFS_BLOCK_SIZE - res, "%s\n",
SCST_SYSFS_KEY_MARK);
kfree(wwn);
@@ -6939,14 +6939,14 @@ out_default:
goto abort;
}
static ssize_t q2t_vp_parent_host_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
static ssize_t q2t_vp_parent_host_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
struct scst_tgt *scst_tgt;
struct q2t_tgt *tgt;
scsi_qla_host_t *base_vha;
ssize_t res = -E_TGT_PRIV_NOT_YET_SET;
char *wwn;
ssize_t res = -E_TGT_PRIV_NOT_YET_SET;
scst_tgt = container_of(kobj, struct scst_tgt, tgt_kobj);
tgt = scst_tgt_get_tgt_priv(scst_tgt);
@@ -6958,7 +6958,7 @@ static ssize_t q2t_vp_parent_host_show(struct kobject *kobj,
if (res != 0)
goto out;
res = sprintf(buf, "%s\n%s\n", wwn, SCST_SYSFS_KEY_MARK);
res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s\n", wwn, SCST_SYSFS_KEY_MARK);
kfree(wwn);

View File

@@ -565,9 +565,9 @@ static ssize_t disk_sysfs_cluster_mode_show(struct kobject *kobj, struct kobj_at
struct scst_device *dev = container_of(kobj, struct scst_device,
dev_kobj);
return sprintf(buf, "%d\n%s", dev->cluster_mode,
dev->cluster_mode ?
SCST_SYSFS_KEY_MARK "\n" : "");
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
dev->cluster_mode,
dev->cluster_mode ? SCST_SYSFS_KEY_MARK "\n" : "");
}
static int disk_sysfs_process_cluster_mode_store(struct scst_sysfs_work_item *work)

View File

@@ -7732,8 +7732,8 @@ static ssize_t vdev_size_show(struct kobject *kobj, struct kobj_attribute *attr,
*/
key = !(virt_dev->nullio && size == VDISK_NULLIO_SIZE) && !size_shift;
return sprintf(buf, "%llu\n%s", size >> size_shift,
key ? SCST_SYSFS_KEY_MARK "\n" : "");
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%llu\n%s",
size >> size_shift, key ? SCST_SYSFS_KEY_MARK "\n" : "");
}
static ssize_t vdev_sysfs_size_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
@@ -7755,19 +7755,19 @@ static ssize_t vdev_sysfs_size_mb_show(struct kobject *kobj, struct kobj_attribu
static ssize_t vdisk_sysfs_blocksize_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
int pos = 0;
struct scst_device *dev;
ssize_t ret;
TRACE_ENTRY();
dev = container_of(kobj, struct scst_device, dev_kobj);
pos = sprintf(buf, "%d\n%s", dev->block_size,
dev->block_size == (1 << DEF_DISK_BLOCK_SHIFT) ? "" :
SCST_SYSFS_KEY_MARK "\n");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
dev->block_size, dev->block_size == (1 << DEF_DISK_BLOCK_SHIFT) ? "" :
SCST_SYSFS_KEY_MARK "\n");
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t vdisk_opt_trans_len_store(struct kobject *kobj,
@@ -7805,65 +7805,67 @@ static ssize_t vdisk_opt_trans_len_show(struct kobject *kobj,
container_of(kobj, struct scst_device, dev_kobj);
struct scst_vdisk_dev *virt_dev = dev->dh_priv;
return sprintf(buf, "%d\n%s", virt_dev->opt_trans_len,
virt_dev->opt_trans_len_set ? SCST_SYSFS_KEY_MARK "\n" :
"");
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
virt_dev->opt_trans_len,
virt_dev->opt_trans_len_set ? SCST_SYSFS_KEY_MARK "\n" : "");
}
static ssize_t vdisk_sysfs_rd_only_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
int pos = 0;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
ssize_t ret;
TRACE_ENTRY();
dev = container_of(kobj, struct scst_device, dev_kobj);
virt_dev = dev->dh_priv;
pos = sprintf(buf, "%d\n%s", virt_dev->rd_only,
virt_dev->rd_only == DEF_RD_ONLY ? "" : SCST_SYSFS_KEY_MARK "\n");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
virt_dev->rd_only,
virt_dev->rd_only == DEF_RD_ONLY ? "" : SCST_SYSFS_KEY_MARK "\n");
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t vdisk_sysfs_wt_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
int pos = 0;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
ssize_t ret;
TRACE_ENTRY();
dev = container_of(kobj, struct scst_device, dev_kobj);
virt_dev = dev->dh_priv;
pos = sprintf(buf, "%d\n%s", virt_dev->wt_flag,
virt_dev->wt_flag == DEF_WRITE_THROUGH ? "" : SCST_SYSFS_KEY_MARK "\n");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
virt_dev->wt_flag,
virt_dev->wt_flag == DEF_WRITE_THROUGH ? "" : SCST_SYSFS_KEY_MARK "\n");
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t vdisk_sysfs_tp_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
int pos = 0;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
ssize_t ret;
TRACE_ENTRY();
dev = container_of(kobj, struct scst_device, dev_kobj);
virt_dev = dev->dh_priv;
pos = sprintf(buf, "%d\n%s", virt_dev->thin_provisioned,
virt_dev->thin_provisioned_manually_set ?
SCST_SYSFS_KEY_MARK "\n" : "");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
virt_dev->thin_provisioned,
virt_dev->thin_provisioned_manually_set ? SCST_SYSFS_KEY_MARK "\n" : "");
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t vdisk_sysfs_gen_tp_soft_threshold_reached_UA(struct kobject *kobj,
@@ -7898,9 +7900,9 @@ static ssize_t vdisk_sysfs_expl_alua_show(struct kobject *kobj,
struct scst_device *dev = container_of(kobj, struct scst_device,
dev_kobj);
return sprintf(buf, "%d\n%s", dev->expl_alua,
dev->expl_alua != DEF_EXPL_ALUA ?
SCST_SYSFS_KEY_MARK "\n" : "");
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
dev->expl_alua,
dev->expl_alua != DEF_EXPL_ALUA ? SCST_SYSFS_KEY_MARK "\n" : "");
}
static ssize_t vdisk_sysfs_expl_alua_store(struct kobject *kobj,
@@ -7926,39 +7928,41 @@ static ssize_t vdisk_sysfs_expl_alua_store(struct kobject *kobj,
static ssize_t vdisk_sysfs_nv_cache_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
int pos = 0;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
ssize_t ret;
TRACE_ENTRY();
dev = container_of(kobj, struct scst_device, dev_kobj);
virt_dev = dev->dh_priv;
pos = sprintf(buf, "%d\n%s", virt_dev->nv_cache,
virt_dev->nv_cache == DEF_NV_CACHE ? "" : SCST_SYSFS_KEY_MARK "\n");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
virt_dev->nv_cache,
virt_dev->nv_cache == DEF_NV_CACHE ? "" : SCST_SYSFS_KEY_MARK "\n");
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t vdisk_sysfs_o_direct_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
int pos = 0;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
ssize_t ret;
TRACE_ENTRY();
dev = container_of(kobj, struct scst_device, dev_kobj);
virt_dev = dev->dh_priv;
pos = sprintf(buf, "%d\n%s", virt_dev->o_direct_flag,
virt_dev->o_direct_flag == DEF_O_DIRECT ? "" : SCST_SYSFS_KEY_MARK "\n");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
virt_dev->o_direct_flag,
virt_dev->o_direct_flag == DEF_O_DIRECT ? "" : SCST_SYSFS_KEY_MARK "\n");
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t vdev_sysfs_dummy_show(struct kobject *kobj,
@@ -7968,8 +7972,9 @@ static ssize_t vdev_sysfs_dummy_show(struct kobject *kobj,
dev_kobj);
struct scst_vdisk_dev *virt_dev = dev->dh_priv;
return sprintf(buf, "%d\n%s", virt_dev->dummy,
virt_dev->dummy != DEF_DUMMY ? SCST_SYSFS_KEY_MARK "\n" : "");
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
virt_dev->dummy,
virt_dev->dummy != DEF_DUMMY ? SCST_SYSFS_KEY_MARK "\n" : "");
}
static ssize_t vdev_sysfs_rz_show(struct kobject *kobj,
@@ -7980,8 +7985,9 @@ static ssize_t vdev_sysfs_rz_show(struct kobject *kobj,
struct scst_vdisk_dev *virt_dev = dev->dh_priv;
bool read_zero = virt_dev->read_zero;
return sprintf(buf, "%d\n%s", read_zero, read_zero != DEF_READ_ZERO ?
SCST_SYSFS_KEY_MARK "\n" : "");
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
read_zero,
read_zero != DEF_READ_ZERO ? SCST_SYSFS_KEY_MARK "\n" : "");
}
static ssize_t vdev_sysfs_rz_store(struct kobject *kobj,
@@ -8016,63 +8022,66 @@ out:
static ssize_t vdisk_sysfs_removable_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
int pos = 0;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
ssize_t ret;
TRACE_ENTRY();
dev = container_of(kobj, struct scst_device, dev_kobj);
virt_dev = dev->dh_priv;
pos = sprintf(buf, "%d\n", virt_dev->removable);
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", virt_dev->removable);
if (virt_dev->dev->type != TYPE_ROM && virt_dev->removable != DEF_REMOVABLE)
pos += sprintf(&buf[pos], "%s\n", SCST_SYSFS_KEY_MARK);
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%s\n",
SCST_SYSFS_KEY_MARK);
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t vdisk_sysfs_tst_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
int pos = 0;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
ssize_t ret;
TRACE_ENTRY();
dev = container_of(kobj, struct scst_device, dev_kobj);
virt_dev = dev->dh_priv;
pos = sprintf(buf, "%d\n", virt_dev->tst);
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", virt_dev->tst);
if (virt_dev->tst != DEF_TST)
pos += sprintf(&buf[pos], "%s\n", SCST_SYSFS_KEY_MARK);
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%s\n",
SCST_SYSFS_KEY_MARK);
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t vdisk_sysfs_rotational_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
int pos = 0;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
ssize_t ret;
TRACE_ENTRY();
dev = container_of(kobj, struct scst_device, dev_kobj);
virt_dev = dev->dh_priv;
pos = sprintf(buf, "%d\n", virt_dev->rotational);
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", virt_dev->rotational);
if (virt_dev->rotational != DEF_ROTATIONAL)
pos += sprintf(&buf[pos], "%s\n", SCST_SYSFS_KEY_MARK);
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%s\n",
SCST_SYSFS_KEY_MARK);
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static int vdev_sysfs_process_get_filename(struct scst_sysfs_work_item *work)
@@ -8280,9 +8289,9 @@ static ssize_t vdev_sysfs_cluster_mode_show(struct kobject *kobj, struct kobj_at
{
struct scst_device *dev = container_of(kobj, struct scst_device, dev_kobj);
return sprintf(buf, "%d\n%s", dev->cluster_mode,
dev->cluster_mode ?
SCST_SYSFS_KEY_MARK "\n" : "");
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
dev->cluster_mode,
dev->cluster_mode ? SCST_SYSFS_KEY_MARK "\n" : "");
}
static int vdev_sysfs_process_cluster_mode_store(struct scst_sysfs_work_item *work)
@@ -8456,9 +8465,9 @@ static ssize_t vdev_sysfs_t10_vend_id_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
int pos;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
ssize_t ret;
TRACE_ENTRY();
@@ -8466,13 +8475,13 @@ static ssize_t vdev_sysfs_t10_vend_id_show(struct kobject *kobj,
virt_dev = dev->dh_priv;
read_lock(&vdisk_serial_rwlock);
pos = sprintf(buf, "%s\n%s", virt_dev->t10_vend_id,
virt_dev->t10_vend_id_set ? SCST_SYSFS_KEY_MARK "\n" :
"");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s",
virt_dev->t10_vend_id,
virt_dev->t10_vend_id_set ? SCST_SYSFS_KEY_MARK "\n" : "");
read_unlock(&vdisk_serial_rwlock);
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t vdev_sysfs_vend_specific_id_store(struct kobject *kobj,
@@ -8516,9 +8525,9 @@ static ssize_t vdev_sysfs_vend_specific_id_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
int pos;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
ssize_t ret;
TRACE_ENTRY();
@@ -8526,13 +8535,13 @@ static ssize_t vdev_sysfs_vend_specific_id_show(struct kobject *kobj,
virt_dev = dev->dh_priv;
read_lock(&vdisk_serial_rwlock);
pos = sprintf(buf, "%s\n%s", virt_dev->vend_specific_id,
virt_dev->vend_specific_id_set ?
SCST_SYSFS_KEY_MARK "\n" : "");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s",
virt_dev->vend_specific_id,
virt_dev->vend_specific_id_set ? SCST_SYSFS_KEY_MARK "\n" : "");
read_unlock(&vdisk_serial_rwlock);
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t vdev_sysfs_prod_id_store(struct kobject *kobj,
@@ -8576,9 +8585,9 @@ static ssize_t vdev_sysfs_prod_id_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
int pos;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
ssize_t ret;
TRACE_ENTRY();
@@ -8586,12 +8595,13 @@ static ssize_t vdev_sysfs_prod_id_show(struct kobject *kobj,
virt_dev = dev->dh_priv;
read_lock(&vdisk_serial_rwlock);
pos = sprintf(buf, "%s\n%s", virt_dev->prod_id,
virt_dev->prod_id_set ? SCST_SYSFS_KEY_MARK "\n" : "");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s",
virt_dev->prod_id,
virt_dev->prod_id_set ? SCST_SYSFS_KEY_MARK "\n" : "");
read_unlock(&vdisk_serial_rwlock);
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t vdev_sysfs_prod_rev_lvl_store(struct kobject *kobj,
@@ -8635,9 +8645,9 @@ static ssize_t vdev_sysfs_prod_rev_lvl_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
int pos;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
ssize_t ret;
TRACE_ENTRY();
@@ -8645,13 +8655,13 @@ static ssize_t vdev_sysfs_prod_rev_lvl_show(struct kobject *kobj,
virt_dev = dev->dh_priv;
read_lock(&vdisk_serial_rwlock);
pos = sprintf(buf, "%s\n%s", virt_dev->prod_rev_lvl,
virt_dev->prod_rev_lvl_set ? SCST_SYSFS_KEY_MARK "\n" :
"");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s",
virt_dev->prod_rev_lvl,
virt_dev->prod_rev_lvl_set ? SCST_SYSFS_KEY_MARK "\n" : "");
read_unlock(&vdisk_serial_rwlock);
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t vdev_sysfs_scsi_device_name_store(struct kobject *kobj, struct kobj_attribute *attr,
@@ -8696,9 +8706,9 @@ out:
static ssize_t vdev_sysfs_scsi_device_name_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
int pos;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
ssize_t ret;
TRACE_ENTRY();
@@ -8706,12 +8716,13 @@ static ssize_t vdev_sysfs_scsi_device_name_show(struct kobject *kobj, struct kob
virt_dev = dev->dh_priv;
read_lock(&vdisk_serial_rwlock);
pos = sprintf(buf, "%s\n%s", virt_dev->scsi_device_name,
virt_dev->scsi_device_name_set ? SCST_SYSFS_KEY_MARK "\n" : "");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s",
virt_dev->scsi_device_name,
virt_dev->scsi_device_name_set ? SCST_SYSFS_KEY_MARK "\n" : "");
read_unlock(&vdisk_serial_rwlock);
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t vdev_sysfs_t10_dev_id_store(struct kobject *kobj, struct kobj_attribute *attr,
@@ -8754,9 +8765,9 @@ out:
static ssize_t vdev_sysfs_t10_dev_id_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
int pos = 0;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
ssize_t ret;
TRACE_ENTRY();
@@ -8764,12 +8775,13 @@ static ssize_t vdev_sysfs_t10_dev_id_show(struct kobject *kobj, struct kobj_attr
virt_dev = dev->dh_priv;
read_lock(&vdisk_serial_rwlock);
pos = sprintf(buf, "%s\n%s", virt_dev->t10_dev_id,
virt_dev->t10_dev_id_set ? SCST_SYSFS_KEY_MARK "\n" : "");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s",
virt_dev->t10_dev_id,
virt_dev->t10_dev_id_set ? SCST_SYSFS_KEY_MARK "\n" : "");
read_unlock(&vdisk_serial_rwlock);
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t vdev_sysfs_eui64_id_store(struct kobject *kobj,
@@ -8822,23 +8834,27 @@ out:
static ssize_t vdev_sysfs_eui64_id_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
int i, pos = 0;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
int i;
ssize_t ret = 0;
dev = container_of(kobj, struct scst_device, dev_kobj);
virt_dev = dev->dh_priv;
read_lock(&vdisk_serial_rwlock);
if (virt_dev->eui64_id_len)
pos += sprintf(buf + pos, "0x");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "0x");
for (i = 0; i < virt_dev->eui64_id_len; i++)
pos += sprintf(buf + pos, "%02x", virt_dev->eui64_id[i]);
pos += sprintf(buf + pos, "\n%s", virt_dev->eui64_id_len ?
SCST_SYSFS_KEY_MARK "\n" : "");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%02x",
virt_dev->eui64_id[i]);
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "\n%s",
virt_dev->eui64_id_len ? SCST_SYSFS_KEY_MARK "\n" : "");
read_unlock(&vdisk_serial_rwlock);
return pos;
return ret;
}
static ssize_t vdev_sysfs_naa_id_store(struct kobject *kobj,
@@ -8897,23 +8913,27 @@ out:
static ssize_t vdev_sysfs_naa_id_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
int i, pos = 0;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
int i;
ssize_t ret = 0;
dev = container_of(kobj, struct scst_device, dev_kobj);
virt_dev = dev->dh_priv;
read_lock(&vdisk_serial_rwlock);
if (virt_dev->naa_id_len)
pos += sprintf(buf + pos, "0x");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "0x");
for (i = 0; i < virt_dev->naa_id_len; i++)
pos += sprintf(buf + pos, "%02x", virt_dev->naa_id[i]);
pos += sprintf(buf + pos, "\n%s", virt_dev->naa_id_len ?
SCST_SYSFS_KEY_MARK "\n" : "");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%02x",
virt_dev->naa_id[i]);
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "\n%s",
virt_dev->naa_id_len ? SCST_SYSFS_KEY_MARK "\n" : "");
read_unlock(&vdisk_serial_rwlock);
return pos;
return ret;
}
static ssize_t vdev_sysfs_usn_store(struct kobject *kobj, struct kobj_attribute *attr,
@@ -8968,9 +8988,9 @@ out_unlock:
static ssize_t vdev_sysfs_usn_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
int pos = 0;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
ssize_t ret;
TRACE_ENTRY();
@@ -8978,12 +8998,13 @@ static ssize_t vdev_sysfs_usn_show(struct kobject *kobj, struct kobj_attribute *
virt_dev = dev->dh_priv;
read_lock(&vdisk_serial_rwlock);
pos = sprintf(buf, "%s\n%s", virt_dev->usn,
virt_dev->usn_set ? SCST_SYSFS_KEY_MARK "\n" : "");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s",
virt_dev->usn,
virt_dev->usn_set ? SCST_SYSFS_KEY_MARK "\n" : "");
read_unlock(&vdisk_serial_rwlock);
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t vdev_sysfs_inq_vend_specific_store(struct kobject *kobj,
@@ -9027,7 +9048,7 @@ static ssize_t vdev_sysfs_inq_vend_specific_show(struct kobject *kobj,
virt_dev = dev->dh_priv;
read_lock(&vdisk_serial_rwlock);
pos = snprintf(buf, PAGE_SIZE, "%.*s\n%s",
pos = snprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%.*s\n%s",
virt_dev->inq_vend_specific_len,
virt_dev->inq_vend_specific,
virt_dev->inq_vend_specific_len ?
@@ -9048,7 +9069,7 @@ static ssize_t vdev_sysfs_active_show(struct kobject *kobj,
dev = container_of(kobj, struct scst_device, dev_kobj);
virt_dev = dev->dh_priv;
pos = snprintf(buf, PAGE_SIZE, "%d\n%s",
pos = snprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
virt_dev->dev_active,
virt_dev->dev_active != DEF_DEV_ACTIVE ?
SCST_SYSFS_KEY_MARK "\n" : "");
@@ -9158,22 +9179,24 @@ static ssize_t vdev_sysfs_bind_alua_state_show(struct kobject *kobj,
{
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
int pos;
unsigned int bind_alua_state;
ssize_t ret;
TRACE_ENTRY();
dev = container_of(kobj, struct scst_device, dev_kobj);
virt_dev = dev->dh_priv;
spin_lock(&virt_dev->flags_lock);
bind_alua_state = virt_dev->bind_alua_state;
spin_unlock(&virt_dev->flags_lock);
pos = sprintf(buf, "%d\n%s", bind_alua_state,
bind_alua_state != DEF_BIND_ALUA_STATE ?
SCST_SYSFS_KEY_MARK "\n" : "");
TRACE_EXIT_RES(pos);
return pos;
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
bind_alua_state,
bind_alua_state != DEF_BIND_ALUA_STATE ? SCST_SYSFS_KEY_MARK "\n" : "");
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t vdev_sysfs_bind_alua_state_store(struct kobject *kobj,
@@ -9235,26 +9258,28 @@ static ssize_t vdev_async_show(struct kobject *kobj,
container_of(kobj, struct scst_device, dev_kobj);
struct scst_vdisk_dev *virt_dev = dev->dh_priv;
return sprintf(buf, "%d\n%s", virt_dev->async,
virt_dev->async ? SCST_SYSFS_KEY_MARK "\n" : "");
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
virt_dev->async,
virt_dev->async ? SCST_SYSFS_KEY_MARK "\n" : "");
}
static ssize_t vdev_dif_filename_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
int pos = 0;
struct scst_device *dev;
struct scst_vdisk_dev *virt_dev;
ssize_t ret;
TRACE_ENTRY();
dev = container_of(kobj, struct scst_device, dev_kobj);
virt_dev = dev->dh_priv;
pos = sprintf(buf, "%s\n%s", virt_dev->dif_filename,
virt_dev->dif_filename ? SCST_SYSFS_KEY_MARK "\n" : "");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s",
virt_dev->dif_filename,
virt_dev->dif_filename ? SCST_SYSFS_KEY_MARK "\n" : "");
TRACE_EXIT_RES(pos);
return pos;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t vdev_lb_per_pb_exp_store(struct kobject *kobj, struct kobj_attribute *attr,
@@ -9286,9 +9311,10 @@ static ssize_t vdev_lb_per_pb_exp_show(struct kobject *kobj, struct kobj_attribu
container_of(kobj, struct scst_device, dev_kobj);
struct scst_vdisk_dev *virt_dev = dev->dh_priv;
return sprintf(buf, "%d\n%s", virt_dev->lb_per_pb_exp,
virt_dev->lb_per_pb_exp == DEF_LB_PER_PB_EXP ? "" :
SCST_SYSFS_KEY_MARK "\n");
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
virt_dev->lb_per_pb_exp,
virt_dev->lb_per_pb_exp == DEF_LB_PER_PB_EXP ? "" :
SCST_SYSFS_KEY_MARK "\n");
}
static struct kobj_attribute vdev_active_attr =

View File

@@ -3708,19 +3708,20 @@ out:
}
static ssize_t scst_cm_allow_not_conn_copy_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
static ssize_t scst_cm_allow_not_conn_copy_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
ssize_t res;
ssize_t ret;
TRACE_ENTRY();
res = sprintf(buf, "%d\n%s", scst_cm_allow_not_connected_copy,
(scst_cm_allow_not_connected_copy == SCST_ALLOW_NOT_CONN_COPY_DEF) ?
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s",
scst_cm_allow_not_connected_copy,
scst_cm_allow_not_connected_copy == SCST_ALLOW_NOT_CONN_COPY_DEF ?
"" : SCST_SYSFS_KEY_MARK "\n");
TRACE_EXIT_RES(res);
return res;
TRACE_EXIT_RES(ret);
return ret;
}
static ssize_t scst_cm_allow_not_conn_copy_store(struct kobject *kobj,

View File

@@ -1904,12 +1904,12 @@ void scst_sgv_pools_deinit(void)
return;
}
static ssize_t sgv_sysfs_stat_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
static ssize_t sgv_sysfs_stat_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
struct sgv_pool *pool;
int i, total = 0, hit = 0, merged = 0, allocated = 0;
int oa, om, res;
int oa, om;
ssize_t ret;
pool = container_of(kobj, struct sgv_pool, sgv_kobj);
@@ -1925,14 +1925,15 @@ static ssize_t sgv_sysfs_stat_show(struct kobject *kobj,
merged += atomic_read(&pool->cache_acc[i].merged);
}
res = sprintf(buf, "%-30s %-11s %-11s %-11s %-11s", "Name", "Hit", "Total",
"% merged", "Cached (P/I/O)");
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%-30s %-11s %-11s %-11s %-11s",
"Name", "Hit", "Total", "% merged", "Cached (P/I/O)");
res += sprintf(&buf[res], "\n%-30s %-11d %-11d %-11d %d/%d/%d\n",
pool->name, hit, total,
(allocated != 0) ? merged*100/allocated : 0,
pool->cached_pages, pool->inactive_cached_pages,
pool->cached_entries);
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret,
"\n%-30s %-11d %-11d %-11d %d/%d/%d\n",
pool->name, hit, total,
allocated != 0 ? merged * 100 / allocated : 0,
pool->cached_pages, pool->inactive_cached_pages,
pool->cached_entries);
for (i = 0; i < SGV_POOL_ELEMENTS; i++) {
int t = atomic_read(&pool->cache_acc[i].total_alloc) -
@@ -1940,11 +1941,12 @@ static ssize_t sgv_sysfs_stat_show(struct kobject *kobj,
allocated = t * (1 << i);
merged = atomic_read(&pool->cache_acc[i].merged);
res += sprintf(&buf[res], " %-28s %-11d %-11d %d\n",
pool->cache_names[i],
atomic_read(&pool->cache_acc[i].hit_alloc),
atomic_read(&pool->cache_acc[i].total_alloc),
(allocated != 0) ? merged*100/allocated : 0);
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret,
" %-28s %-11d %-11d %d\n",
pool->cache_names[i],
atomic_read(&pool->cache_acc[i].hit_alloc),
atomic_read(&pool->cache_acc[i].total_alloc),
allocated != 0 ? merged * 100 / allocated : 0);
}
allocated = atomic_read(&pool->big_pages);
@@ -1952,12 +1954,13 @@ static ssize_t sgv_sysfs_stat_show(struct kobject *kobj,
oa = atomic_read(&pool->other_pages);
om = atomic_read(&pool->other_merged);
res += sprintf(&buf[res], " %-40s %d/%-9d %d/%d\n", "big/other",
atomic_read(&pool->big_alloc), atomic_read(&pool->other_alloc),
(allocated != 0) ? merged*100/allocated : 0,
(oa != 0) ? om/oa : 0);
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret,
" %-40s %d/%-9d %d/%d\n", "big/other",
atomic_read(&pool->big_alloc), atomic_read(&pool->other_alloc),
allocated != 0 ? merged * 100 / allocated : 0,
oa != 0 ? om / oa : 0);
return res;
return ret;
}
static ssize_t sgv_sysfs_stat_reset(struct kobject *kobj,
@@ -1989,11 +1992,12 @@ static ssize_t sgv_sysfs_stat_reset(struct kobject *kobj,
return count;
}
static ssize_t sgv_sysfs_global_stat_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
static ssize_t sgv_sysfs_global_stat_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
struct sgv_pool *pool;
int inactive_pages = 0, res;
int inactive_pages = 0;
size_t ret;
TRACE_ENTRY();
@@ -2004,21 +2008,22 @@ static ssize_t sgv_sysfs_global_stat_show(struct kobject *kobj,
spin_unlock_bh(&sgv_pools_lock);
#ifdef CONFIG_SCST_NO_TOTAL_MEM_CHECKS
res = sprintf(buf, "%-42s %d\n", "Inactive pages", inactive_pages);
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%-42s %d\n", "Inactive pages",
inactive_pages);
#else
res = sprintf(buf, "%-42s %d/%d\n%-42s %d/%d\n%-42s %d/%d\n"
"%-42s %-11d\n",
"Inactive/active pages", inactive_pages,
atomic_read(&sgv_pages_total) - inactive_pages,
"Hi/lo watermarks [pages]", sgv_hi_wmk, sgv_lo_wmk,
"Hi watermark releases/failures",
atomic_read(&sgv_releases_on_hiwmk),
atomic_read(&sgv_releases_on_hiwmk_failed),
"Other allocs", atomic_read(&sgv_other_total_alloc));
ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%-42s %d/%d\n%-42s %d/%d\n%-42s %d/%d\n"
"%-42s %-11d\n",
"Inactive/active pages", inactive_pages,
atomic_read(&sgv_pages_total) - inactive_pages,
"Hi/lo watermarks [pages]", sgv_hi_wmk, sgv_lo_wmk,
"Hi watermark releases/failures",
atomic_read(&sgv_releases_on_hiwmk),
atomic_read(&sgv_releases_on_hiwmk_failed),
"Other allocs", atomic_read(&sgv_other_total_alloc));
#endif
TRACE_EXIT();
return res;
return ret;
}
static ssize_t sgv_sysfs_global_stat_reset(struct kobject *kobj,

File diff suppressed because it is too large Load Diff

View File

@@ -244,22 +244,26 @@ out:
static ssize_t scst_local_version_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
sprintf(buf, "%s/%s\n", SCST_LOCAL_VERSION, scst_local_version_date);
ssize_t ret = 0;
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%s/%s\n",
SCST_LOCAL_VERSION, scst_local_version_date);
#ifdef CONFIG_SCST_EXTRACHECKS
strcat(buf, "EXTRACHECKS\n");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "EXTRACHECKS\n");
#endif
#ifdef CONFIG_SCST_TRACING
strcat(buf, "TRACING\n");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "TRACING\n");
#endif
#ifdef CONFIG_SCST_DEBUG
strcat(buf, "DEBUG\n");
ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "DEBUG\n");
#endif
TRACE_EXIT();
return strlen(buf);
return ret;
}
static struct kobj_attribute scst_local_version_attr =
@@ -267,10 +271,10 @@ static struct kobj_attribute scst_local_version_attr =
static ssize_t scst_local_stats_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
return sprintf(buf,
"Aborts: %d, Device Resets: %d, Target Resets: %d\n",
atomic_read(&num_aborts), atomic_read(&num_dev_resets),
atomic_read(&num_target_resets));
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE,
"Aborts: %d, Device Resets: %d, Target Resets: %d\n",
atomic_read(&num_aborts), atomic_read(&num_dev_resets),
atomic_read(&num_target_resets));
}
static struct kobj_attribute scst_local_stats_attr =
@@ -304,10 +308,10 @@ static ssize_t scst_local_scsi_transport_version_show(struct kobject *kobj,
goto out_up;
if (tgt->scsi_transport_version != 0)
res = sprintf(buf, "0x%x\n%s", tgt->scsi_transport_version,
SCST_SYSFS_KEY_MARK "\n");
res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "0x%x\n%s",
tgt->scsi_transport_version, SCST_SYSFS_KEY_MARK "\n");
else
res = sprintf(buf, "0x%x\n", 0x0BE0); /* SAS */
res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "0x%x\n", 0x0BE0); /* SAS */
out_up:
up_read(&scst_local_exit_rwsem);
@@ -372,8 +376,9 @@ static ssize_t scst_local_phys_transport_version_show(struct kobject *kobj,
if (!tgt)
goto out_up;
res = sprintf(buf, "0x%x\n%s", tgt->phys_transport_version,
tgt->phys_transport_version != 0 ? SCST_SYSFS_KEY_MARK "\n" : "");
res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "0x%x\n%s",
tgt->phys_transport_version,
tgt->phys_transport_version != 0 ? SCST_SYSFS_KEY_MARK "\n" : "");
out_up:
up_read(&scst_local_exit_rwsem);
@@ -446,11 +451,11 @@ static struct kobj_attribute scst_local_host_no_attr = __ATTR_RO(host_no);
static ssize_t scst_local_transport_id_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
ssize_t res;
struct scst_session *scst_sess;
struct scst_local_sess *sess;
uint8_t *tr_id;
int tr_id_len, i;
ssize_t res;
if (down_read_trylock(&scst_local_exit_rwsem) == 0)
return -ENOENT;
@@ -471,7 +476,7 @@ static ssize_t scst_local_transport_id_show(struct kobject *kobj, struct kobj_at
res = 0;
for (i = 0; i < tr_id_len; i++)
res += sprintf(&buf[res], "%c", tr_id[i]);
res += scnprintf(buf + res, SCST_SYSFS_BLOCK_SIZE - res, "%c", tr_id[i]);
if (!sess->transport_id)
kfree(tr_id);

View File

@@ -4013,13 +4013,13 @@ static ssize_t srpt_show_device(struct kobject *kobj,
tgt_kobj);
struct srpt_port *sport = scst_tgt_get_tgt_priv(scst_tgt);
struct srpt_device *sdev;
int res = -E_TGT_PRIV_NOT_YET_SET;
ssize_t res = -E_TGT_PRIV_NOT_YET_SET;
if (!sport)
goto out;
sdev = sport->sdev;
res = sprintf(buf, "%s\n", dev_name(&sdev->device->dev));
res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", dev_name(&sdev->device->dev));
out:
return res;
@@ -4039,7 +4039,7 @@ static ssize_t srpt_show_link_layer(struct kobject *kobj,
tgt_kobj);
struct srpt_port *sport = scst_tgt_get_tgt_priv(scst_tgt);
const char *lln = "Unknown";
int res = -E_TGT_PRIV_NOT_YET_SET;
ssize_t res = -E_TGT_PRIV_NOT_YET_SET;
if (!sport)
goto out;
@@ -4055,7 +4055,7 @@ static ssize_t srpt_show_link_layer(struct kobject *kobj,
default:
break;
}
res = sprintf(buf, "%s\n", lln);
res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", lln);
out:
return res;
@@ -4125,25 +4125,23 @@ static ssize_t show_login_info(struct kobject *kobj,
struct scst_tgt *scst_tgt = container_of(kobj, struct scst_tgt,
tgt_kobj);
struct srpt_port *sport = scst_tgt_get_tgt_priv(scst_tgt);
int res = -E_TGT_PRIV_NOT_YET_SET;
ssize_t res = -E_TGT_PRIV_NOT_YET_SET;
if (!sport)
goto out;
res = sprintf(buf,
"tid_ext=%016llx,ioc_guid=%016llx,pkey=ffff,"
"dgid=%04x%04x%04x%04x%04x%04x%04x%04x,"
"service_id=%016llx\n",
srpt_service_guid, srpt_service_guid,
be16_to_cpu(((__be16 *) sport->gid.raw)[0]),
be16_to_cpu(((__be16 *) sport->gid.raw)[1]),
be16_to_cpu(((__be16 *) sport->gid.raw)[2]),
be16_to_cpu(((__be16 *) sport->gid.raw)[3]),
be16_to_cpu(((__be16 *) sport->gid.raw)[4]),
be16_to_cpu(((__be16 *) sport->gid.raw)[5]),
be16_to_cpu(((__be16 *) sport->gid.raw)[6]),
be16_to_cpu(((__be16 *) sport->gid.raw)[7]),
srpt_service_guid);
res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE,
"tid_ext=%016llx,ioc_guid=%016llx,pkey=ffff,dgid=%04x%04x%04x%04x%04x%04x%04x%04x,service_id=%016llx\n",
srpt_service_guid, srpt_service_guid,
be16_to_cpu(((__be16 *) sport->gid.raw)[0]),
be16_to_cpu(((__be16 *) sport->gid.raw)[1]),
be16_to_cpu(((__be16 *) sport->gid.raw)[2]),
be16_to_cpu(((__be16 *) sport->gid.raw)[3]),
be16_to_cpu(((__be16 *) sport->gid.raw)[4]),
be16_to_cpu(((__be16 *) sport->gid.raw)[5]),
be16_to_cpu(((__be16 *) sport->gid.raw)[6]),
be16_to_cpu(((__be16 *) sport->gid.raw)[7]),
srpt_service_guid);
out:
return res;
@@ -4171,7 +4169,8 @@ static ssize_t show_req_lim(struct kobject *kobj,
ch = scst_sess_get_tgt_priv(sess);
if (!ch)
return -ENOENT;
return sprintf(buf, "%d\n", ch->req_lim);
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", ch->req_lim);
}
static ssize_t show_req_lim_delta(struct kobject *kobj,
@@ -4184,7 +4183,8 @@ static ssize_t show_req_lim_delta(struct kobject *kobj,
ch = scst_sess_get_tgt_priv(sess);
if (!ch)
return -ENOENT;
return sprintf(buf, "%d\n", ch->req_lim_delta);
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", ch->req_lim_delta);
}
static ssize_t show_ch_state(struct kobject *kobj, struct kobj_attribute *attr,
@@ -4197,7 +4197,8 @@ static ssize_t show_ch_state(struct kobject *kobj, struct kobj_attribute *attr,
ch = scst_sess_get_tgt_priv(sess);
if (!ch)
return -ENOENT;
return sprintf(buf, "%s\n", get_ch_state_name(ch->state));
return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", get_ch_state_name(ch->state));
}
static ssize_t show_comp_vector(struct kobject *kobj,
@@ -4208,7 +4209,8 @@ static ssize_t show_comp_vector(struct kobject *kobj,
sess = container_of(kobj, struct scst_session, sess_kobj);
ch = scst_sess_get_tgt_priv(sess);
return ch ? sprintf(buf, "%u\n", ch->comp_vector) : -ENOENT;
return ch ? scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%u\n", ch->comp_vector) : -ENOENT;
}
static const struct kobj_attribute srpt_req_lim_attr =