From: Gleb C. <lna...@ya...> - 2025-05-19 17:49:32
|
Commit: 0e8fdad GitHub URL: https://github.com/SCST-project/scst/commit/0e8fdad5e48c15b98c29470a991aaa71a4147b56 Author: Gleb Chesnokov Date: 2025-05-19T20:46:54+03:00 Log Message: ----------- scst: Use sysfs_emit/sysfs_emit_at instead of scnprintf() Replace scnprintf() with sysfs_emit() and sysfs_emit_at() in sysfs show handlers. These helper functions are specifically designed for sysfs output, providing safer handling of buffer lengths and consistency across kernel sysfs interfaces. This patch does not change any functionality. Modified Paths: -------------- iscsi-scst/kernel/config.c | 20 +- iscsi-scst/kernel/conn.c | 66 +- iscsi-scst/kernel/session.c | 26 +- iscsi-scst/kernel/target.c | 6 +- qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.c | 33 +- qla2x00t/qla2x00-target/qla2x00t.c | 35 +- scst/include/backport.h | 76 ++ scst/src/dev_handlers/scst_disk.c | 6 +- scst/src/dev_handlers/scst_user.c | 28 +- scst/src/dev_handlers/scst_vdisk.c | 187 +++-- scst/src/scst_copy_mgr.c | 8 +- scst/src/scst_mem.c | 60 +- scst/src/scst_sysfs.c | 567 +++++++-------- scst_local/scst_local.c | 34 +- srpt/src/ib_srpt.c | 54 +- 15 files changed, 621 insertions(+), 585 deletions(-) =================================================================== diff --git a/iscsi-scst/kernel/config.c b/iscsi-scst/kernel/config.c index d86c349..e17fa24 100644 --- a/iscsi-scst/kernel/config.c +++ b/iscsi-scst/kernel/config.c @@ -29,22 +29,22 @@ static ssize_t iscsi_version_show(struct kobject *kobj, struct kobj_attribute *a TRACE_ENTRY(); - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%s\n", ISCSI_VERSION_STRING); + ret += sysfs_emit_at(buf, ret, "%s\n", ISCSI_VERSION_STRING); #ifdef CONFIG_SCST_EXTRACHECKS - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "EXTRACHECKS\n"); + ret += sysfs_emit_at(buf, ret, "EXTRACHECKS\n"); #endif #ifdef CONFIG_SCST_TRACING - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "TRACING\n"); + ret += sysfs_emit_at(buf, ret, "TRACING\n"); #endif #ifdef CONFIG_SCST_DEBUG - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "DEBUG\n"); + ret += sysfs_emit_at(buf, ret, "DEBUG\n"); #endif #ifdef CONFIG_SCST_ISCSI_DEBUG_DIGEST_FAILURES - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "DEBUG_DIGEST_FAILURES\n"); + ret += sysfs_emit_at(buf, ret, "DEBUG_DIGEST_FAILURES\n"); #endif TRACE_EXIT(); @@ -60,16 +60,16 @@ static ssize_t iscsi_open_state_show(struct kobject *kobj, struct kobj_attribute switch (ctr_open_state) { case ISCSI_CTR_OPEN_STATE_CLOSED: - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "closed\n"); + ret = sysfs_emit(buf, "closed\n"); break; case ISCSI_CTR_OPEN_STATE_OPEN: - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "open\n"); + ret = sysfs_emit(buf, "open\n"); break; case ISCSI_CTR_OPEN_STATE_CLOSING: - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "closing\n"); + ret = sysfs_emit(buf, "closing\n"); break; default: - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "unknown\n"); + ret = sysfs_emit(buf, "unknown\n"); break; } @@ -442,7 +442,7 @@ static ssize_t iscsi_attr_show(struct kobject *kobj, struct kobj_attribute *attr if (pos != 0) goto out; - pos = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", (char *)value); + pos = sysfs_emit(buf, "%s\n", (char *)value); kfree(value); diff --git a/iscsi-scst/kernel/conn.c b/iscsi-scst/kernel/conn.c index dcc6a0f..8c087b0 100644 --- a/iscsi-scst/kernel/conn.c +++ b/iscsi-scst/kernel/conn.c @@ -35,43 +35,43 @@ static struct lockdep_map scst_conn_dep_map = STATIC_LOCKDEP_MAP_INIT("iscsi_conn_kref", &scst_conn_key); #endif -static int print_conn_state(char *p, size_t size, struct iscsi_conn *conn) +static ssize_t print_conn_state(char *buf, size_t size, struct iscsi_conn *conn) { - int pos = 0; + ssize_t ret = 0; if (conn->closing) { - pos += scnprintf(p, size, "closing"); + ret += scnprintf(buf, size, "closing"); goto out; } switch (conn->rd_state) { case ISCSI_CONN_RD_STATE_PROCESSING: - pos += scnprintf(&p[pos], size - pos, "read_processing "); + ret += scnprintf(buf + ret, size - ret, "read_processing "); break; case ISCSI_CONN_RD_STATE_IN_LIST: - pos += scnprintf(&p[pos], size - pos, "in_read_list "); + ret += scnprintf(buf + ret, size - ret, "in_read_list "); break; } switch (conn->wr_state) { case ISCSI_CONN_WR_STATE_PROCESSING: - pos += scnprintf(&p[pos], size - pos, "write_processing "); + ret += scnprintf(buf + ret, size - ret, "write_processing "); break; case ISCSI_CONN_WR_STATE_IN_LIST: - pos += scnprintf(&p[pos], size - pos, "in_write_list "); + ret += scnprintf(buf + ret, size - ret, "in_write_list "); break; case ISCSI_CONN_WR_STATE_SPACE_WAIT: - pos += scnprintf(&p[pos], size - pos, "space_waiting "); + ret += scnprintf(buf + ret, size - ret, "space_waiting "); break; } if (test_bit(ISCSI_CONN_REINSTATING, &conn->conn_aflags)) - pos += scnprintf(&p[pos], size - pos, "reinstating "); - else if (pos == 0) - pos += scnprintf(&p[pos], size - pos, "established idle "); + ret += scnprintf(buf + ret, size - ret, "reinstating "); + else if (ret == 0) + ret += scnprintf(buf + ret, size - ret, "established idle "); out: - return pos; + return ret; } static void iscsi_conn_release(struct kobject *kobj) @@ -98,17 +98,17 @@ static ssize_t iscsi_get_initiator_ip(struct iscsi_conn *conn, char *buf, int si static ssize_t iscsi_conn_ip_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 = iscsi_get_initiator_ip(conn, buf, SCST_SYSFS_BLOCK_SIZE); + ret = iscsi_get_initiator_ip(conn, buf, SCST_SYSFS_BLOCK_SIZE); - TRACE_EXIT_RES(pos); - return pos; + TRACE_EXIT_RES(ret); + return ret; } static struct kobj_attribute iscsi_conn_ip_attr = @@ -116,8 +116,8 @@ static struct kobj_attribute iscsi_conn_ip_attr = static ssize_t iscsi_get_target_ip(struct iscsi_conn *conn, char *buf, int size) { - int pos; struct sock *sk; + ssize_t ret; TRACE_ENTRY(); @@ -127,40 +127,40 @@ static ssize_t iscsi_get_target_ip(struct iscsi_conn *conn, char *buf, int size) sk = conn->sock->sk; switch (sk->sk_family) { case AF_INET: - pos = scnprintf(buf, size, "%pI4", &inet_sk(sk)->inet_saddr); + ret = scnprintf(buf, size, "%pI4", &inet_sk(sk)->inet_saddr); break; #ifdef CONFIG_IPV6 case AF_INET6: #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0) - pos = scnprintf(buf, size, "[%pI6]", &inet6_sk(sk)->saddr); + ret = scnprintf(buf, size, "[%pI6]", &inet6_sk(sk)->saddr); #else - pos = scnprintf(buf, size, "[%pI6]", &sk->sk_v6_rcv_saddr); + ret = scnprintf(buf, size, "[%pI6]", &sk->sk_v6_rcv_saddr); #endif #endif break; default: - pos = scnprintf(buf, size, "Unknown family %d", sk->sk_family); + ret = scnprintf(buf, size, "Unknown family %d", sk->sk_family); break; } - TRACE_EXIT_RES(pos); - return pos; + TRACE_EXIT_RES(ret); + return ret; } static ssize_t iscsi_conn_target_ip_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 = iscsi_get_target_ip(conn, buf, SCST_SYSFS_BLOCK_SIZE); + ret = iscsi_get_target_ip(conn, buf, SCST_SYSFS_BLOCK_SIZE); - TRACE_EXIT_RES(pos); - return pos; + TRACE_EXIT_RES(ret); + return ret; } static struct kobj_attribute iscsi_conn_target_ip_attr = @@ -176,7 +176,7 @@ static ssize_t iscsi_conn_transport_show(struct kobject *kobj, struct kobj_attri conn = container_of(kobj, struct iscsi_conn, conn_kobj); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", conn->transport->name); + ret = sysfs_emit(buf, "%s\n", conn->transport->name); TRACE_EXIT_RES(ret); return ret; @@ -194,7 +194,7 @@ static ssize_t iscsi_conn_cid_show(struct kobject *kobj, struct kobj_attribute * conn = container_of(kobj, struct iscsi_conn, conn_kobj); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%u", conn->cid); + ret = sysfs_emit(buf, "%u", conn->cid); TRACE_EXIT_RES(ret); return ret; @@ -205,17 +205,17 @@ static struct kobj_attribute iscsi_conn_cid_attr = static ssize_t iscsi_conn_state_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 = print_conn_state(buf, SCST_SYSFS_BLOCK_SIZE, conn); + ret = print_conn_state(buf, SCST_SYSFS_BLOCK_SIZE, conn); - TRACE_EXIT_RES(pos); - return pos; + TRACE_EXIT_RES(ret); + return ret; } static struct kobj_attribute iscsi_conn_state_attr = diff --git a/iscsi-scst/kernel/session.c b/iscsi-scst/kernel/session.c index 9bfe05c..d77081a 100644 --- a/iscsi-scst/kernel/session.c +++ b/iscsi-scst/kernel/session.c @@ -388,8 +388,8 @@ static ssize_t iscsi_sess_show_##name(struct kobject *kobj, \ 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_bool_value(sess->sess_params.name)); \ + return sysfs_emit(buf, "%s\n", \ + iscsi_get_bool_value(sess->sess_params.name)); \ } \ \ static struct kobj_attribute iscsi_sess_attr_##name = \ @@ -405,8 +405,8 @@ static ssize_t iscsi_sess_show_##name(struct kobject *kobj, \ 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, "%d\n", \ - sess->sess_params.name); \ + return sysfs_emit(buf, "%d\n", \ + sess->sess_params.name); \ } \ \ static struct kobj_attribute iscsi_sess_attr_##name = \ @@ -423,8 +423,8 @@ static ssize_t iscsi_sess_show_##name(struct kobject *kobj, \ 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)); \ + return sysfs_emit(buf, "%s\n", \ + iscsi_get_digest_name(sess->sess_params.name, digest_name)); \ } \ \ static struct kobj_attribute iscsi_sess_attr_##name = \ @@ -451,7 +451,7 @@ static ssize_t iscsi_sess_sid_show(struct kobject *kobj, struct kobj_attribute * scst_sess = container_of(kobj, struct scst_session, sess_kobj); sess = (struct iscsi_session *)scst_sess_get_tgt_priv(scst_sess); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%llx\n", sess->sid); + ret = sysfs_emit(buf, "%llx\n", sess->sid); TRACE_EXIT_RES(ret); return ret; @@ -472,7 +472,7 @@ static ssize_t iscsi_sess_reinstating_show(struct kobject *kobj, struct kobj_att scst_sess = container_of(kobj, struct scst_session, sess_kobj); sess = (struct iscsi_session *)scst_sess_get_tgt_priv(scst_sess); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", sess->sess_reinstating ? 1 : 0); + ret = sysfs_emit(buf, "%d\n", sess->sess_reinstating ? 1 : 0); TRACE_EXIT_RES(ret); return ret; @@ -497,11 +497,11 @@ static ssize_t iscsi_sess_thread_pid_show(struct kobject *kobj, struct kobj_attr mutex_lock(&thr_pool->tp_mutex); list_for_each_entry(t, &thr_pool->threads_list, threads_list_entry) - res += scnprintf(buf + res, SCST_SYSFS_BLOCK_SIZE - res, "%d%s", - task_pid_vnr(t->thr), - list_is_last(&t->threads_list_entry, - &thr_pool->threads_list) ? - "\n" : " "); + res += sysfs_emit_at(buf, res, "%d%s", + task_pid_vnr(t->thr), + list_is_last(&t->threads_list_entry, + &thr_pool->threads_list) ? + "\n" : " "); mutex_unlock(&thr_pool->tp_mutex); out: diff --git a/iscsi-scst/kernel/target.c b/iscsi-scst/kernel/target.c index 84d86ec..b1ec29e 100644 --- a/iscsi-scst/kernel/target.c +++ b/iscsi-scst/kernel/target.c @@ -404,7 +404,7 @@ static ssize_t iscsi_tgt_tid_show(struct kobject *kobj, struct kobj_attribute *a if (!tgt) goto out; - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%u\n", tgt->tid); + res = sysfs_emit(buf, "%u\n", tgt->tid); out: TRACE_EXIT_RES(res); @@ -577,8 +577,8 @@ static ssize_t iscsi_acg_sess_dedicated_threads_show(struct kobject *kobj, acg = container_of(kobj, struct scst_acg, acg_kobj); dedicated = scst_get_acg_tgt_priv(acg); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s", - dedicated, dedicated ? SCST_SYSFS_KEY_MARK "\n" : ""); + ret = sysfs_emit(buf, "%d\n%s", + dedicated, dedicated ? SCST_SYSFS_KEY_MARK "\n" : ""); TRACE_EXIT_RES(ret); return ret; diff --git a/qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.c b/qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.c index 4f86e6a..53b54e9 100644 --- a/qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.c +++ b/qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.c @@ -895,28 +895,27 @@ static ssize_t sqa_version_show(struct kobject *kobj, { 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); + ret += sysfs_emit_at(buf, ret, "INTERFACE=%s\nSCST=%s\nQLOGIC=%s\n", + SQA_VERSION, SCST_VERSION_NAME, QLA2XXX_VERSION); #ifdef CONFIG_SCST_EXTRACHECKS - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "EXTRACHECKS\n"); + ret += sysfs_emit_at(buf, ret, "EXTRACHECKS\n"); #endif #ifdef CONFIG_SCST_TRACING - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "TRACING\n"); + ret += sysfs_emit_at(buf, ret, "TRACING\n"); #endif #ifdef CONFIG_SCST_DEBUG - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "DEBUG\n"); + ret += sysfs_emit_at(buf, ret, "DEBUG\n"); #endif #ifdef CONFIG_QLA_TGT_DEBUG_WORK_IN_THREAD - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "QLA_TGT_DEBUG_WORK_IN_THREAD\n"); + ret += sysfs_emit_at(buf, ret, "QLA_TGT_DEBUG_WORK_IN_THREAD\n"); #endif #ifdef CONFIG_QLA_TGT_DEBUG_SRR - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "DEBUG_SRR\n"); + ret += sysfs_emit_at(buf, ret, "DEBUG_SRR\n"); #endif TRACE_EXIT(); @@ -935,8 +934,7 @@ static ssize_t sqa_hw_target_show(struct kobject *kobj, tgt = sqa_tgt->qla_tgt; - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", - tgt->vha->vp_idx == 0 ? 1 : 0); + return sysfs_emit(buf, "%d\n", tgt->vha->vp_idx == 0 ? 1 : 0); } static ssize_t sqa_node_name_show(struct kobject *kobj, @@ -973,11 +971,10 @@ static ssize_t sqa_node_name_show(struct kobject *kobj, if (res != 0) goto out; - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", wwn); + res = sysfs_emit(buf, "%s\n", wwn); if (ha->tgt.node_name_set) - res += scnprintf(buf + res, SCST_SYSFS_BLOCK_SIZE - res, "%s\n", - SCST_SYSFS_KEY_MARK); + res += sysfs_emit_at(buf, res, "%s\n", SCST_SYSFS_KEY_MARK); kfree(wwn); @@ -1072,7 +1069,7 @@ static ssize_t sqa_vp_parent_host_show(struct kobject *kobj, if (res != 0) goto out; - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s\n", wwn, SCST_SYSFS_KEY_MARK); + res = sysfs_emit(buf, "%s\n%s\n", wwn, SCST_SYSFS_KEY_MARK); kfree(wwn); @@ -1095,10 +1092,10 @@ static ssize_t sqa_show_expl_conf_enabled(struct kobject *kobj, tgt = sqa_tgt->qla_tgt; ha = tgt->ha; - 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 sysfs_emit(buffer, "%d\n%s", + ha->base_qpair->enable_explicit_conf, + ha->base_qpair->enable_explicit_conf ? + SCST_SYSFS_KEY_MARK "\n" : ""); } static ssize_t sqa_store_expl_conf_enabled(struct kobject *kobj, diff --git a/qla2x00t/qla2x00-target/qla2x00t.c b/qla2x00t/qla2x00-target/qla2x00t.c index 1282e27..8717b12 100644 --- a/qla2x00t/qla2x00-target/qla2x00t.c +++ b/qla2x00t/qla2x00-target/qla2x00t.c @@ -6601,8 +6601,8 @@ out: } -static ssize_t q2t_show_expl_conf_enabled(struct kobject *kobj, - struct kobj_attribute *attr, char *buffer) +static ssize_t q2t_show_expl_conf_enabled(struct kobject *kobj, struct kobj_attribute *attr, + char *buffer) { struct scst_tgt *scst_tgt; struct q2t_tgt *tgt; @@ -6613,11 +6613,12 @@ static ssize_t q2t_show_expl_conf_enabled(struct kobject *kobj, tgt = scst_tgt_get_tgt_priv(scst_tgt); if (!tgt) goto out; + vha = tgt->vha; - res = scnprintf(buffer, PAGE_SIZE, "%d\n%s", - vha->hw->enable_explicit_conf, - vha->hw->enable_explicit_conf ? SCST_SYSFS_KEY_MARK "\n" : ""); + res = sysfs_emit(buffer, "%d\n%s", + vha->hw->enable_explicit_conf, + vha->hw->enable_explicit_conf ? SCST_SYSFS_KEY_MARK "\n" : ""); out: return res; @@ -6709,22 +6710,22 @@ static ssize_t q2t_version_show(struct kobject *kobj, struct kobj_attribute *att { size_t ret = 0; - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%s\n", Q2T_VERSION_STRING); + ret += sysfs_emit_at(buf, ret, "%s\n", Q2T_VERSION_STRING); #ifdef CONFIG_SCST_EXTRACHECKS - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "EXTRACHECKS\n"); + ret += sysfs_emit_at(buf, ret, "EXTRACHECKS\n"); #endif #ifdef CONFIG_SCST_TRACING - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "TRACING\n"); + ret += sysfs_emit_at(buf, ret, "TRACING\n"); #endif #ifdef CONFIG_SCST_DEBUG - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "DEBUG\n"); + ret += sysfs_emit_at(buf, ret, "DEBUG\n"); #endif #ifdef CONFIG_QLA_TGT_DEBUG_WORK_IN_THREAD - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "QLA_TGT_DEBUG_WORK_IN_THREAD\n"); + ret += sysfs_emit_at(buf, ret, "QLA_TGT_DEBUG_WORK_IN_THREAD\n"); #endif TRACE_EXIT(); @@ -6733,7 +6734,7 @@ static ssize_t q2t_version_show(struct kobject *kobj, struct kobj_attribute *att static ssize_t q2t_hw_target_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", 1); + return sysfs_emit(buf, "%d\n", 1); } static ssize_t q2t_node_name_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) @@ -6757,12 +6758,11 @@ static ssize_t q2t_node_name_show(struct kobject *kobj, struct kobj_attribute *a if (res != 0) goto out; - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", wwn); + res = sysfs_emit(buf, "%s\n", wwn); /* For virtual ports it's always key */ if (vha->node_name_set || (vha->vp_idx != 0)) - res += scnprintf(buf + res, SCST_SYSFS_BLOCK_SIZE - res, "%s\n", - SCST_SYSFS_KEY_MARK); + res += sysfs_emit_at(buf, res, "%s\n", SCST_SYSFS_KEY_MARK); kfree(wwn); @@ -6860,12 +6860,11 @@ static ssize_t q2t_port_name_show(struct kobject *kobj, struct kobj_attribute *a if (res != 0) goto out; - res = scnprintf(buf, "%s\n", wwn); + res = sysfs_emit(buf, "%s\n", wwn); /* For virtual ports it's always key */ if ((vha->vp_idx != 0) || vha->port_name_set) - res += scnprintf(buf + res, SCST_SYSFS_BLOCK_SIZE - res, "%s\n", - SCST_SYSFS_KEY_MARK); + res += sysfs_emit_at(buf, res, "%s\n", SCST_SYSFS_KEY_MARK); kfree(wwn); @@ -6958,7 +6957,7 @@ static ssize_t q2t_vp_parent_host_show(struct kobject *kobj, struct kobj_attribu if (res != 0) goto out; - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s\n", wwn, SCST_SYSFS_KEY_MARK); + res = sysfs_emit(buf, "%s\n%s\n", wwn, SCST_SYSFS_KEY_MARK); kfree(wwn); diff --git a/scst/include/backport.h b/scst/include/backport.h index 20f276d..aa60068 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -37,8 +37,11 @@ #include <linux/iocontext.h> #include <linux/kobject_ns.h> #include <linux/scatterlist.h> /* struct scatterlist */ +#include <linux/shrinker.h> #include <linux/slab.h> /* kmalloc() */ #include <linux/stddef.h> /* sizeof_field() */ +#include <linux/string.h> +#include <linux/sysfs.h> #include <linux/timer.h> #include <linux/vmalloc.h> #include <linux/workqueue.h> @@ -1565,6 +1568,79 @@ static inline ssize_t strscpy(char *dest, const char *src, size_t count) #define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store) #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0) && \ + (LINUX_VERSION_CODE >> 8 != KERNEL_VERSION(4, 9, 0) >> 8 || \ + LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 260)) && \ + (LINUX_VERSION_CODE >> 8 != KERNEL_VERSION(4, 14, 0) >> 8 || \ + LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 224)) && \ + (LINUX_VERSION_CODE >> 8 != KERNEL_VERSION(4, 19, 0) >> 8 || \ + LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 179)) && \ + (LINUX_VERSION_CODE >> 8 != KERNEL_VERSION(5, 4, 0) >> 8 || \ + LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 103)) +/* + * See also commit 2efc459d06f1 ("sysfs: Add sysfs_emit and sysfs_emit_at to format sysfs output") + * # v5.10. + * See also commit f3c3dcf35532 # v4.9.260. + * See also commit 390881843b4f # v4.14.224. + * See also commit cb1f69d53ac8 # v4.19.179. + * See also commit 5f4243642873 # v5.4.103. + */ +static inline __printf(2, 3) +int sysfs_emit(char *buf, const char *fmt, ...) +{ + va_list args; + int len; + + if (WARN(!buf || +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 20, 0) + /* + * For kernel releases older than 4.20, using the SLUB allocator will cause + * this alignment check to fail as that allocator did NOT align kmalloc + * allocations on a PAGE_SIZE boundary. + */ + false, +#else + offset_in_page(buf), +#endif + "invalid sysfs_emit: buf:%p\n", buf)) + return 0; + + va_start(args, fmt); + len = vscnprintf(buf, PAGE_SIZE, fmt, args); + va_end(args); + + return len; +} + +static inline __printf(3, 4) +int sysfs_emit_at(char *buf, int at, const char *fmt, ...) +{ + va_list args; + int len; + + if (WARN(!buf || +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 20, 0) + /* + * For kernel releases older than 4.20, using the SLUB allocator will cause + * this alignment check to fail as that allocator did NOT align kmalloc + * allocations on a PAGE_SIZE boundary. + */ + false || +#else + offset_in_page(buf) || +#endif + at < 0 || at >= PAGE_SIZE, + "invalid sysfs_emit_at: buf:%p at:%d\n", buf, at)) + return 0; + + va_start(args, fmt); + len = vscnprintf(buf + at, PAGE_SIZE - at, fmt, args); + va_end(args); + + return len; +} +#endif + /* <linux/t10-pi.h> */ #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0) diff --git a/scst/src/dev_handlers/scst_disk.c b/scst/src/dev_handlers/scst_disk.c index a892e2a..6b891cf 100644 --- a/scst/src/dev_handlers/scst_disk.c +++ b/scst/src/dev_handlers/scst_disk.c @@ -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 scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s", - dev->cluster_mode, - dev->cluster_mode ? SCST_SYSFS_KEY_MARK "\n" : ""); + return sysfs_emit(buf, "%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) diff --git a/scst/src/dev_handlers/scst_user.c b/scst/src/dev_handlers/scst_user.c index 7d3de9c..cfd9ce2 100644 --- a/scst/src/dev_handlers/scst_user.c +++ b/scst/src/dev_handlers/scst_user.c @@ -3897,10 +3897,10 @@ out: static ssize_t dev_user_sysfs_commands_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - int pos = 0, ppos, i; struct scst_device *dev; struct scst_user_dev *udev; unsigned long flags; + int i, ret = 0, pos; TRACE_ENTRY(); @@ -3913,26 +3913,24 @@ static ssize_t dev_user_sysfs_commands_show(struct kobject *kobj, struct kobj_at struct scst_user_cmd *ucmd; list_for_each_entry(ucmd, head, hash_list_entry) { - ppos = pos; - pos += scnprintf(&buf[pos], - SCST_SYSFS_BLOCK_SIZE - pos, - "ucmd %p (state %x, ref %d), sent_to_user %d, seen_by_user %d, aborted %d, jammed %d, scst_cmd %p\n", - ucmd, ucmd->state, - atomic_read(&ucmd->ucmd_ref), - ucmd->sent_to_user, ucmd->seen_by_user, - ucmd->aborted, ucmd->jammed, ucmd->cmd); - if (pos >= SCST_SYSFS_BLOCK_SIZE - 1) { - ppos += scnprintf(&buf[ppos], - SCST_SYSFS_BLOCK_SIZE - ppos, "...\n"); - pos = ppos; + pos = ret; + ret += sysfs_emit_at(buf, ret, + "ucmd %p (state %x, ref %d), sent_to_user %d, seen_by_user %d, aborted %d, jammed %d, scst_cmd %p\n", + ucmd, ucmd->state, + atomic_read(&ucmd->ucmd_ref), + ucmd->sent_to_user, ucmd->seen_by_user, + ucmd->aborted, ucmd->jammed, ucmd->cmd); + if (ret >= SCST_SYSFS_BLOCK_SIZE - 1) { + pos += sysfs_emit_at(buf, pos, "...\n"); + ret = pos; break; } } } spin_unlock_irqrestore(&udev->udev_cmd_threads.cmd_list_lock, flags); - TRACE_EXIT_RES(pos); - return pos; + TRACE_EXIT_RES(ret); + return ret; } static inline int test_cleanup_list(void) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 2c31761..87c7e26 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -7734,8 +7734,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 scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%llu\n%s", - size >> size_shift, key ? SCST_SYSFS_KEY_MARK "\n" : ""); + return sysfs_emit(buf, "%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) @@ -7764,9 +7764,9 @@ static ssize_t vdisk_sysfs_blocksize_show(struct kobject *kobj, struct kobj_attr dev = container_of(kobj, struct scst_device, dev_kobj); - 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"); + ret = sysfs_emit(buf, "%d\n%s", + dev->block_size, dev->block_size == (1 << DEF_DISK_BLOCK_SHIFT) ? "" : + SCST_SYSFS_KEY_MARK "\n"); TRACE_EXIT_RES(ret); return ret; @@ -7807,9 +7807,9 @@ 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 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" : ""); + return sysfs_emit(buf, "%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, @@ -7824,9 +7824,9 @@ static ssize_t vdisk_sysfs_rd_only_show(struct kobject *kobj, struct kobj_attrib dev = container_of(kobj, struct scst_device, dev_kobj); virt_dev = dev->dh_priv; - 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"); + ret = sysfs_emit(buf, "%d\n%s", + virt_dev->rd_only, + virt_dev->rd_only == DEF_RD_ONLY ? "" : SCST_SYSFS_KEY_MARK "\n"); TRACE_EXIT_RES(ret); return ret; @@ -7843,9 +7843,9 @@ static ssize_t vdisk_sysfs_wt_show(struct kobject *kobj, struct kobj_attribute * dev = container_of(kobj, struct scst_device, dev_kobj); virt_dev = dev->dh_priv; - 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"); + ret = sysfs_emit(buf, "%d\n%s", + virt_dev->wt_flag, + virt_dev->wt_flag == DEF_WRITE_THROUGH ? "" : SCST_SYSFS_KEY_MARK "\n"); TRACE_EXIT_RES(ret); return ret; @@ -7862,9 +7862,9 @@ static ssize_t vdisk_sysfs_tp_show(struct kobject *kobj, struct kobj_attribute * dev = container_of(kobj, struct scst_device, dev_kobj); virt_dev = dev->dh_priv; - 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" : ""); + ret = sysfs_emit(buf, "%d\n%s", + virt_dev->thin_provisioned, + virt_dev->thin_provisioned_manually_set ? SCST_SYSFS_KEY_MARK "\n" : ""); TRACE_EXIT_RES(ret); return ret; @@ -7902,9 +7902,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 scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s", - dev->expl_alua, - dev->expl_alua != DEF_EXPL_ALUA ? SCST_SYSFS_KEY_MARK "\n" : ""); + return sysfs_emit(buf, "%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, @@ -7939,9 +7939,9 @@ static ssize_t vdisk_sysfs_nv_cache_show(struct kobject *kobj, struct kobj_attri dev = container_of(kobj, struct scst_device, dev_kobj); virt_dev = dev->dh_priv; - 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"); + ret = sysfs_emit(buf, "%d\n%s", + virt_dev->nv_cache, + virt_dev->nv_cache == DEF_NV_CACHE ? "" : SCST_SYSFS_KEY_MARK "\n"); TRACE_EXIT_RES(ret); return ret; @@ -7959,9 +7959,9 @@ static ssize_t vdisk_sysfs_o_direct_show(struct kobject *kobj, struct kobj_attri dev = container_of(kobj, struct scst_device, dev_kobj); virt_dev = dev->dh_priv; - 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"); + ret = sysfs_emit(buf, "%d\n%s", + virt_dev->o_direct_flag, + virt_dev->o_direct_flag == DEF_O_DIRECT ? "" : SCST_SYSFS_KEY_MARK "\n"); TRACE_EXIT_RES(ret); return ret; @@ -7974,9 +7974,9 @@ static ssize_t vdev_sysfs_dummy_show(struct kobject *kobj, dev_kobj); struct scst_vdisk_dev *virt_dev = dev->dh_priv; - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s", - virt_dev->dummy, - virt_dev->dummy != DEF_DUMMY ? SCST_SYSFS_KEY_MARK "\n" : ""); + return sysfs_emit(buf, "%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, @@ -7987,9 +7987,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 scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s", - read_zero, - read_zero != DEF_READ_ZERO ? SCST_SYSFS_KEY_MARK "\n" : ""); + return sysfs_emit(buf, "%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, @@ -8033,11 +8033,10 @@ static ssize_t vdisk_sysfs_removable_show(struct kobject *kobj, struct kobj_attr dev = container_of(kobj, struct scst_device, dev_kobj); virt_dev = dev->dh_priv; - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", virt_dev->removable); + ret = sysfs_emit(buf, "%d\n", virt_dev->removable); if (virt_dev->dev->type != TYPE_ROM && virt_dev->removable != DEF_REMOVABLE) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%s\n", - SCST_SYSFS_KEY_MARK); + ret += sysfs_emit_at(buf, ret, "%s\n", SCST_SYSFS_KEY_MARK); TRACE_EXIT_RES(ret); return ret; @@ -8054,11 +8053,10 @@ static ssize_t vdisk_sysfs_tst_show(struct kobject *kobj, struct kobj_attribute dev = container_of(kobj, struct scst_device, dev_kobj); virt_dev = dev->dh_priv; - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", virt_dev->tst); + ret = sysfs_emit(buf, "%d\n", virt_dev->tst); if (virt_dev->tst != DEF_TST) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%s\n", - SCST_SYSFS_KEY_MARK); + ret += sysfs_emit_at(buf, ret, "%s\n", SCST_SYSFS_KEY_MARK); TRACE_EXIT_RES(ret); return ret; @@ -8076,11 +8074,10 @@ static ssize_t vdisk_sysfs_rotational_show(struct kobject *kobj, struct kobj_att dev = container_of(kobj, struct scst_device, dev_kobj); virt_dev = dev->dh_priv; - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", virt_dev->rotational); + ret = sysfs_emit(buf, "%d\n", virt_dev->rotational); if (virt_dev->rotational != DEF_ROTATIONAL) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%s\n", - SCST_SYSFS_KEY_MARK); + ret += sysfs_emit_at(buf, ret, "%s\n", SCST_SYSFS_KEY_MARK); TRACE_EXIT_RES(ret); return ret; @@ -8175,7 +8172,7 @@ static ssize_t vdev_sysfs_filename_show(struct kobject *kobj, struct kobj_attrib if (res != 0) goto out_put; - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", work->res_buf); + res = sysfs_emit(buf, "%s\n", work->res_buf); out_put: scst_sysfs_work_put(work); @@ -8291,9 +8288,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 scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s", - dev->cluster_mode, - dev->cluster_mode ? SCST_SYSFS_KEY_MARK "\n" : ""); + return sysfs_emit(buf, "%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) @@ -8477,9 +8474,9 @@ static ssize_t vdev_sysfs_t10_vend_id_show(struct kobject *kobj, virt_dev = dev->dh_priv; read_lock(&vdisk_serial_rwlock); - 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" : ""); + ret = sysfs_emit(buf, "%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(ret); @@ -8537,9 +8534,9 @@ static ssize_t vdev_sysfs_vend_specific_id_show(struct kobject *kobj, virt_dev = dev->dh_priv; read_lock(&vdisk_serial_rwlock); - 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" : ""); + ret = sysfs_emit(buf, "%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(ret); @@ -8597,9 +8594,9 @@ static ssize_t vdev_sysfs_prod_id_show(struct kobject *kobj, virt_dev = dev->dh_priv; read_lock(&vdisk_serial_rwlock); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s", - virt_dev->prod_id, - virt_dev->prod_id_set ? SCST_SYSFS_KEY_MARK "\n" : ""); + ret = sysfs_emit(buf, "%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(ret); @@ -8657,9 +8654,9 @@ static ssize_t vdev_sysfs_prod_rev_lvl_show(struct kobject *kobj, virt_dev = dev->dh_priv; read_lock(&vdisk_serial_rwlock); - 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" : ""); + ret = sysfs_emit(buf, "%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(ret); @@ -8718,9 +8715,9 @@ static ssize_t vdev_sysfs_scsi_device_name_show(struct kobject *kobj, struct kob virt_dev = dev->dh_priv; read_lock(&vdisk_serial_rwlock); - 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" : ""); + ret = sysfs_emit(buf, "%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(ret); @@ -8777,9 +8774,9 @@ 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); - 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" : ""); + ret = sysfs_emit(buf, "%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(ret); @@ -8846,14 +8843,13 @@ static ssize_t vdev_sysfs_eui64_id_show(struct kobject *kobj, read_lock(&vdisk_serial_rwlock); if (virt_dev->eui64_id_len) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "0x"); + ret += sysfs_emit_at(buf, ret, "0x"); for (i = 0; i < virt_dev->eui64_id_len; i++) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%02x", - virt_dev->eui64_id[i]); + ret += sysfs_emit_at(buf, 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" : ""); + ret += sysfs_emit_at(buf, ret, "\n%s", + virt_dev->eui64_id_len ? SCST_SYSFS_KEY_MARK "\n" : ""); read_unlock(&vdisk_serial_rwlock); return ret; @@ -8925,14 +8921,13 @@ static ssize_t vdev_sysfs_naa_id_show(struct kobject *kobj, struct kobj_attribut read_lock(&vdisk_serial_rwlock); if (virt_dev->naa_id_len) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "0x"); + ret += sysfs_emit_at(buf, ret, "0x"); for (i = 0; i < virt_dev->naa_id_len; i++) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%02x", - virt_dev->naa_id[i]); + ret += sysfs_emit_at(buf, 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" : ""); + ret += sysfs_emit_at(buf, ret, "\n%s", + virt_dev->naa_id_len ? SCST_SYSFS_KEY_MARK "\n" : ""); read_unlock(&vdisk_serial_rwlock); return ret; @@ -9000,9 +8995,9 @@ static ssize_t vdev_sysfs_usn_show(struct kobject *kobj, struct kobj_attribute * virt_dev = dev->dh_priv; read_lock(&vdisk_serial_rwlock); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s", - virt_dev->usn, - virt_dev->usn_set ? SCST_SYSFS_KEY_MARK "\n" : ""); + ret = sysfs_emit(buf, "%s\n%s", + virt_dev->usn, + virt_dev->usn_set ? SCST_SYSFS_KEY_MARK "\n" : ""); read_unlock(&vdisk_serial_rwlock); TRACE_EXIT_RES(ret); @@ -9050,10 +9045,10 @@ static ssize_t vdev_sysfs_inq_vend_specific_show(struct kobject *kobj, virt_dev = dev->dh_priv; read_lock(&vdisk_serial_rwlock); - ret = scnprintf(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 ? SCST_SYSFS_KEY_MARK "\n" : ""); + ret = sysfs_emit(buf, "%.*s\n%s", + virt_dev->inq_vend_specific_len, + virt_dev->inq_vend_specific, + virt_dev->inq_vend_specific_len ? SCST_SYSFS_KEY_MARK "\n" : ""); read_unlock(&vdisk_serial_rwlock); return ret; @@ -9069,9 +9064,9 @@ static ssize_t vdev_sysfs_active_show(struct kobject *kobj, dev = container_of(kobj, struct scst_device, dev_kobj); virt_dev = dev->dh_priv; - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s", - virt_dev->dev_active, - virt_dev->dev_active != DEF_DEV_ACTIVE ? SCST_SYSFS_KEY_MARK "\n" : ""); + return sysfs_emit(buf, "%d\n%s", + virt_dev->dev_active, + virt_dev->dev_active != DEF_DEV_ACTIVE ? SCST_SYSFS_KEY_MARK "\n" : ""); } static int vdev_sysfs_process_active_store(struct scst_sysfs_work_item *work) @@ -9188,9 +9183,9 @@ static ssize_t vdev_sysfs_bind_alua_state_show(struct kobject *kobj, bind_alua_state = virt_dev->bind_alua_state; spin_unlock(&virt_dev->flags_lock); - 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" : ""); + ret = sysfs_emit(buf, "%d\n%s", + bind_alua_state, + bind_alua_state != DEF_BIND_ALUA_STATE ? SCST_SYSFS_KEY_MARK "\n" : ""); TRACE_EXIT_RES(ret); return ret; @@ -9255,9 +9250,9 @@ 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 scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s", - virt_dev->async, - virt_dev->async ? SCST_SYSFS_KEY_MARK "\n" : ""); + return sysfs_emit(buf, "%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) @@ -9271,9 +9266,9 @@ static ssize_t vdev_dif_filename_show(struct kobject *kobj, struct kobj_attribut dev = container_of(kobj, struct scst_device, dev_kobj); virt_dev = dev->dh_priv; - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s", - virt_dev->dif_filename, - virt_dev->dif_filename ? SCST_SYSFS_KEY_MARK "\n" : ""); + ret = sysfs_emit(buf, "%s\n%s", + virt_dev->dif_filename, + virt_dev->dif_filename ? SCST_SYSFS_KEY_MARK "\n" : ""); TRACE_EXIT_RES(ret); return ret; @@ -9308,10 +9303,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 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"); + return sysfs_emit(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"); } static struct kobj_attribute vdev_active_attr = diff --git a/scst/src/scst_copy_mgr.c b/scst/src/scst_copy_mgr.c index d7bb44e..510dc0f 100644 --- a/scst/src/scst_copy_mgr.c +++ b/scst/src/scst_copy_mgr.c @@ -3715,10 +3715,10 @@ static ssize_t scst_cm_allow_not_conn_copy_show(struct kobject *kobj, struct kob TRACE_ENTRY(); - 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"); + ret = sysfs_emit(buf, "%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(ret); return ret; diff --git a/scst/src/scst_mem.c b/scst/src/scst_mem.c index 056afaa..537b90c 100644 --- a/scst/src/scst_mem.c +++ b/scst/src/scst_mem.c @@ -1925,15 +1925,15 @@ static ssize_t sgv_sysfs_stat_show(struct kobject *kobj, struct kobj_attribute * merged += atomic_read(&pool->cache_acc[i].merged); } - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%-30s %-11s %-11s %-11s %-11s", - "Name", "Hit", "Total", "% merged", "Cached (P/I/O)"); + ret = sysfs_emit(buf, "%-30s %-11s %-11s %-11s %-11s", + "Name", "Hit", "Total", "% merged", "Cached (P/I/O)"); - 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); + ret += sysfs_emit_at(buf, 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) - @@ -1941,12 +1941,12 @@ static ssize_t sgv_sysfs_stat_show(struct kobject *kobj, struct kobj_attribute * allocated = t * (1 << i); merged = atomic_read(&pool->cache_acc[i].merged); - 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); + ret += sysfs_emit_at(buf, 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); @@ -1954,11 +1954,11 @@ static ssize_t sgv_sysfs_stat_show(struct kobject *kobj, struct kobj_attribute * oa = atomic_read(&pool->other_pages); om = atomic_read(&pool->other_merged); - 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); + ret += sysfs_emit_at(buf, 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 ret; } @@ -2008,18 +2008,18 @@ static ssize_t sgv_sysfs_global_stat_show(struct kobject *kobj, struct kobj_attr spin_unlock_bh(&sgv_pools_lock); #ifdef CONFIG_SCST_NO_TOTAL_MEM_CHECKS - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%-42s %d\n", "Inactive pages", - inactive_pages); + ret = sysfs_emit(buf, "%-42s %d\n", "Inactive pages", + inactive_pages); #else - 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)); + ret = sysfs_emit(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)); #endif TRACE_EXIT(); diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index bf4b31e..d780b89 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -142,8 +142,8 @@ static ssize_t scst_read_trace_tbl(const struct scst_trace_log *tbl, char *buf, while (t->token) { if (log_level & t->val) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%s%s", - ret == 0 ? "" : " | ", t->token); + ret += sysfs_emit_at(buf, ret, "%s%s", + ret == 0 ? "" : " | ", t->token); t++; } @@ -159,26 +159,26 @@ static ssize_t scst_trace_level_show(const struct scst_trace_log *local_tbl, ret += scst_read_trace_tbl(scst_trace_tbl, buf, log_level, ret); ret += scst_read_trace_tbl(local_tbl, buf, log_level, ret); - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, - "\n\n\nUsage:\n" - " echo \"all|none|default\" >trace_level\n" - " echo \"value DEC|0xHEX|0OCT\" >trace_level\n" - " echo \"add|del TOKEN\" >trace_level\n" + ret += sysfs_emit_at(buf, ret, + "\n\n\nUsage:\n" + " echo \"all|none|default\" >trace_level\n" + " echo \"value DEC|0xHEX|0OCT\" >trace_level\n" + " echo \"add|del TOKEN\" >trace_level\n" #ifdef CONFIG_SCST_DEBUG - "\nwhere TOKEN is one of [debug, function, line, pid,\n" + "\nwhere TOKEN is one of [debug, function, line, pid,\n" #ifndef GENERATING_UPSTREAM_PATCH - " entryexit, buff, mem, sg, out_of_mem,\n" + " entryexit, buff, mem, sg, out_of_mem,\n" #else - " buff, mem, sg, out_of_mem,\n" + " buff, mem, sg, out_of_mem,\n" #endif - " special, scsi, mgmt, minor,\n" - " mgmt_dbg, scsi_serializing,\n" - " retry, pr, block%s]\n", + " special, scsi, mgmt, minor,\n" + " mgmt_dbg, scsi_serializing,\n" + " retry, pr, block%s]\n", #else /* CONFIG_SCST_DEBUG */ - "\nwhere TOKEN is one of [function, line, pid, out_of_mem, special, scsi, mgmt, minor, scsi_serializing, retry, pr%s]\n", + "\nwhere TOKEN is one of [function, line, pid, out_of_mem, special, scsi, mgmt, minor, scsi_serializing, retry, pr%s]\n", #endif /* CONFIG_SCST_DEBUG */ - help ? help : ""); + help ? help : ""); return ret; } @@ -849,27 +849,27 @@ static ssize_t scst_tgtt_mgmt_show(struct kobject *kobj, struct kobj_attribute * tgtt = container_of(kobj, struct scst_tgt_template, tgtt_kobj); - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, help, - tgtt->tgtt_optional_attributes ? - " echo \"add_attribute <attribute> <value>\" >mgmt\n" - " echo \"del_attribute <attribute> <value>\" >mgmt\n" : "", - tgtt->tgt_optional_attributes ? - " echo \"add_target_attribute target_name <attribute> <value>\" >mgmt\n" - " echo \"del_target_attribute target_name <attribute> <value>\" >mgmt\n" : "", - tgtt->mgmt_cmd_help ? tgtt->mgmt_cmd_help : "", - tgtt->mgmt_cmd_help ? "\n" : "", - tgtt->add_target_parameters ? - "The following parameters available: " : "", - tgtt->add_target_parameters ? tgtt->add_target_parameters : "", - tgtt->add_target_parameters ? "\n" : "", - tgtt->tgtt_optional_attributes ? - "The following target driver attributes available: " : "", - tgtt->tgtt_optional_attributes ? tgtt->tgtt_optional_attributes : "", - tgtt->tgtt_optional_attributes ? "\n" : "", - tgtt->tgt_optional_attributes ? - "The following target attributes available: " : "", - tgtt->tgt_optional_attributes ? tgtt->tgt_optional_attributes : "", - tgtt->tgt_optional_attributes ? "\n" : ""); + return sysfs_emit(buf, help, + tgtt->tgtt_optional_attributes ? + " echo \"add_attribute <attribute> <value>\" >mgmt\n" + " echo \"del_attribute <attribute> <value>\" >mgmt\n" : "", + tgtt->tgt_optional_attributes ? + " echo \"add_target_attribute target_name <attribute> <value>\" >mgmt\n" + " echo \"del_target_attribute target_name <attribute> <value>\" >mgmt\n" : "", + tgtt->mgmt_cmd_help ? tgtt->mgmt_cmd_help : "", + tgtt->mgmt_cmd_help ? "\n" : "", + tgtt->add_target_parameters ? + "The following parameters available: " : "", + tgtt->add_target_parameters ? tgtt->add_target_parameters : "", + tgtt->add_target_parameters ? "\n" : "", + tgtt->tgtt_optional_attributes ? + "The following target driver attributes available: " : "", + tgtt->tgtt_optional_attributes ? tgtt->tgtt_optional_attributes : "", + tgtt->tgtt_optional_attributes ? "\n" : "", + tgtt->tgt_optional_attributes ? + "The following target attributes available: " : "", + tgtt->tgt_optional_attributes ? tgtt->tgt_optional_attributes : "", + tgtt->tgt_optional_attributes ? "\n" : ""); } static int scst_process_tgtt_mgmt_store(char *buffer, struct scst_tgt_template *tgtt) @@ -989,42 +989,35 @@ static ssize_t scst_tgtt_dif_capable_show(struct kobject *kobj, struct kobj_attr EXTRACHECKS_BUG_ON(!tgtt->dif_supported); - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, - "dif_supported"); + ret += sysfs_emit_at(buf, ret, "dif_supported"); if (tgtt->hw_dif_type1_supported) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, - ", hw_dif_type1_supported"); + ret += sysfs_emit_at(buf, ret, ", hw_dif_type1_supported"); if (tgtt->hw_dif_type2_supported) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, - ", hw_dif_type2_supported"); + ret += sysfs_emit_at(buf, ret, ", hw_dif_type2_supported"); if (tgtt->hw_dif_type3_supported) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, - ", hw_dif_type3_supported"); + ret += sysfs_emit_at(buf, ret, ", hw_dif_type3_supported"); if (tgtt->hw_dif_ip_supported) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, - ", hw_dif_ip_supported"); + ret += sysfs_emit_at(buf, ret, ", hw_dif_ip_supported"); if (tgtt->hw_dif_same_sg_layout_required) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, - ", hw_dif_same_sg_layout_required"); + ret += sysfs_emit_at(buf, ret, ", hw_dif_same_sg_layout_required"); - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "\n"); + ret += sysfs_emit_at(buf, ret, "\n"); if (tgtt->supported_dif_block_sizes) { const int *p = tgtt->supported_dif_block_sizes; ssize_t pos; - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, - "Supported blocks: "); + ret += sysfs_emit_at(buf, ret, "Supported blocks: "); pos = ret; while (*p != 0) { - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, - "%s%d", ret == pos ? "" : ", ", *p); + ret += sysfs_emit_at(buf, ret, "%s%d", + ret == pos ? "" : ", ", *p); p++; } } @@ -1492,9 +1485,9 @@ static ssize_t scst_luns_mgmt_show(struct kobject *kobj, " echo \"clear\" >mgmt\n" "\n" "where parameters are one or more param_name=value pairs separated by ';'\n" - "\nThe following parameters available: read_only\n"; + "\nThe following parameters available: read_only"; - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s", help); + return sysfs_emit(buf, "%s\n", help); } static ssize_t scst_luns_mgmt_store(struct kobject *kobj, @@ -1525,22 +1518,21 @@ static ssize_t __scst_acg_addr_method_show(struct scst_acg *acg, char *buf) switch (acg->addr_method) { case SCST_LUN_ADDR_METHOD_FLAT: - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "FLAT\n"); + ret = sysfs_emit(buf, "FLAT\n"); break; case SCST_LUN_ADDR_METHOD_PERIPHERAL: - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "PERIPHERAL\n"); + ret = sysfs_emit(buf, "PERIPHERAL\n"); break; case SCST_LUN_ADDR_METHOD_LUN: - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "LUN\n"); + ret = sysfs_emit(buf, "LUN\n"); break; default: - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "UNKNOWN\n"); + ret = sysfs_emit(buf, "UNKNOWN\n"); break; } if (acg->addr_method != acg->tgt->tgtt->preferred_addr_method) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, - "%s\n", SCST_SYSFS_KEY_MARK); + ret += sysfs_emit_at(buf, ret, "%s\n", SCST_SYSFS_KEY_MARK); return ret; } @@ -1604,19 +1596,19 @@ static ssize_t __scst_acg_io_grouping_type_show(struct scst_acg *acg, char *buf) switch (acg->acg_io_grouping_type) { case SCST_IO_GROUPING_AUTO: - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", SCST_IO_GROUPING_AUTO_STR); + ret = sysfs_emit(buf, "%s\n", SCST_IO_GROUPING_AUTO_STR); break; case SCST_IO_GROUPING_THIS_GROUP_ONLY: - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s\n", - SCST_IO_GROUPING_THIS_GROUP_ONLY_STR, SCST_SYSFS_KEY_MARK); + ret = sysfs_emit(buf, "%s\n%s\n", + SCST_IO_GROUPING_THIS_GROUP_ONLY_STR, SCST_SYSFS_KEY_MARK); break; case SCST_IO_GROUPING_NEVER: - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s\n", - SCST_IO_GROUPING_NEVER_STR, SCST_SYSFS_KEY_MARK); + ret = sysfs_emit(buf, "%s\n%s\n", + SCST_IO_GROUPING_NEVER_STR, SCST_SYSFS_KEY_MARK); break; default: - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s\n", - acg->acg_io_grouping_type, SCST_SYSFS_KEY_MARK); + ret = sysfs_emit(buf, "%d\n%s\n", + acg->acg_io_grouping_type, SCST_SYSFS_KEY_MARK); break; } @@ -1758,7 +1750,7 @@ static ssize_t __scst_acg_black_hole_show(struct scst_acg *acg, char *buf) { int t = acg->acg_black_hole_type; - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", t); + return sysfs_emit(buf, "%d\n", t); } static ssize_t __scst_acg_black_hole_store(struct scst_acg *acg, const char *buf, size_t count) @@ -1882,13 +1874,12 @@ static ssize_t __scst_acg_cpu_mask_show(struct scst_acg *acg, char *buf) #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0) ret = cpumask_scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, &acg->acg_cpu_mask); #else - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%*pb", cpumask_pr_args(&acg->acg_cpu_mask)); + ret = sysfs_emit(buf, "%*pb", cpumask_pr_args(&acg->acg_cpu_mask)); #endif if (!cpumask_equal(&acg->acg_cpu_mask, &default_cpu_mask)) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, - "\n%s\n", SCST_SYSFS_KEY_MARK); + ret += sysfs_emit_at(buf, ret, "\n%s\n", SCST_SYSFS_KEY_MARK); else - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "\n"); + ret += sysfs_emit_at(buf, ret, "\n"); return ret; } @@ -2047,9 +2038,9 @@ static ssize_t scst_ini_group_mgmt_show(struct kobject *kobj, struct kobj_attrib { static const char help[] = "Usage: echo \"create GROUP_NAME\" >mgmt\n" - " echo \"del GROUP_NAME\" >mgmt\n"; + " echo \"del GROUP_NAME\" >mgmt"; - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s", help); + return sysfs_emit(buf, "%s\n", help); } static int scst_process_ini_group_mgmt_store(char *buffer, struct scst_tgt *tgt) @@ -2202,7 +2193,7 @@ static ssize_t scst_tgt_enable_show(struct kobject *kobj, struct kobj_attribute enabled = tgt->tgtt->is_target_enabled(tgt); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", enabled ? 1 : 0); + ret = sysfs_emit(buf, "%d\n", enabled ? 1 : 0); TRACE_EXIT_RES(ret); return ret; @@ -2312,9 +2303,9 @@ static ssize_t scst_rel_tgt_id_show(struct kobject *kobj, struct kobj_attribute tgt = container_of(kobj, struct scst_tgt, tgt_kobj); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s", - tgt->rel_tgt_id, - tgt->rel_tgt_id != 0 ? SCST_SYSFS_KEY_MARK "\n" : ""); + ret = sysfs_emit(buf, "%d\n%s", + tgt->rel_tgt_id, + tgt->rel_tgt_id != 0 ? SCST_SYSFS_KEY_MARK "\n" : ""); TRACE_EXIT_RES(ret); return ret; @@ -2417,9 +2408,9 @@ static ssize_t scst_tgt_forward_src_show(struct kobject *kobj, struct kobj_attri { struct scst_tgt *tgt = container_of(kobj, struct scst_tgt, tgt_kobj); - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s", - tgt->tgt_forward_src, - tgt->tgt_forward_src ? SCST_SYSFS_KEY_MARK "\n" : ""); + return sysfs_emit(buf, "%d\n%s", + tgt->tgt_forward_src, + tgt->tgt_forward_src ? SCST_SYSFS_KEY_MARK "\n" : ""); } static ssize_t scst_tgt_forward_src_store(struct kobject *kobj, struct kobj_attribute *attr, @@ -2460,9 +2451,9 @@ static ssize_t scst_tgt_forward_dst_show(struct kobject *kobj, struct kobj_attri tgt = container_of(kobj, struct scst_tgt, tgt_kobj); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s", - tgt->tgt_forward_dst, - tgt->tgt_forward_dst ? SCST_SYSFS_KEY_MARK "\n" : ""); + ret = sysfs_emit(buf, "%d\n%s", + tgt->tgt_forward_dst, + tgt->tgt_forward_dst ? SCST_SYSFS_KEY_MARK "\n" : ""); TRACE_EXIT_RES(ret); return ret; @@ -2561,9 +2552,9 @@ static ssize_t scst_tgt_aen_disabled_show(struct kobject *kobj, struct kobj_attr tgt = container_of(kobj, struct scst_tgt, tgt_kobj); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s", - tgt->tgt_aen_disabled, - tgt->tgt_aen_disabled ? SCST_SYSFS_KEY_MARK "\n" : ""); + ret = sysfs_emit(buf, "%d\n%s", + tgt->tgt_aen_disabled, + tgt->tgt_aen_disabled ? SCST_SYSFS_KEY_MARK "\n" : ""); TRACE_EXIT_RES(ret); return ret; @@ -2659,8 +2650,8 @@ static ssize_t scst_tgt_comment_show(struct kobject *kobj, struct kobj_attribute tgt = container_of(kobj, struct scst_tgt, tgt_kobj); if (tgt->tgt_comment) - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s", - tgt->tgt_comment, SCST_SYSFS_KEY_MARK "\n"); + ret = sysfs_emit(buf, "%s\n%s\n", + tgt->tgt_comment, SCST_SYSFS_KEY_MARK); else ret = 0; @@ -2752,40 +2743,34 @@ static ssize_t scst_tgt_dif_capable_show(struct kobject *kobj, struct kobj_attri EXTRACHECKS_BUG_ON(!tgt->tgt_dif_supported); - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "dif_supported"); + ret += sysfs_emit_at(buf, ret, "dif_supported"); if (tgt->tgt_hw_dif_type1_supported) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, - ... [truncated message content] |