From 0e8fdad5e48c15b98c29470a991aaa71a4147b56 Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Mon, 19 May 2025 16:46:24 +0300 Subject: [PATCH] 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. --- 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 | 56 +- 15 files changed, 622 insertions(+), 586 deletions(-) diff --git a/iscsi-scst/kernel/config.c b/iscsi-scst/kernel/config.c index d86c349ca..e17fa2444 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 dcc6a0fe5..8c087b07d 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 9bfe05ccc..d77081a12 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 84d86ecc7..b1ec29e9c 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 4f86e6a1b..53b54e9ce 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 1282e2799..8717b122e 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 20f276dd9..aa60068e1 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -37,8 +37,11 @@ #include #include #include /* struct scatterlist */ +#include #include /* kmalloc() */ #include /* sizeof_field() */ +#include +#include #include #include #include @@ -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 + /* */ #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 a892e2a2f..6b891cf25 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 7d3de9c44..cfd9ce21d 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 2c317612f..87c7e269a 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 d7bb44e25..510dc0f19 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 056afaabd..537b90c7c 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 bf4b31e02..d780b895d 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 \" >mgmt\n" - " echo \"del_attribute \" >mgmt\n" : "", - tgtt->tgt_optional_attributes ? - " echo \"add_target_attribute target_name \" >mgmt\n" - " echo \"del_target_attribute target_name \" >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 \" >mgmt\n" + " echo \"del_attribute \" >mgmt\n" : "", + tgtt->tgt_optional_attributes ? + " echo \"add_target_attribute target_name \" >mgmt\n" + " echo \"del_target_attribute target_name \" >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, - ", hw_dif_type1_supported"); + ret += sysfs_emit_at(buf, ret, ", hw_dif_type1_supported"); if (tgt->tgt_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 (tgt->tgt_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 (tgt->tgt_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 (tgt->tgt_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 (tgt->tgt_supported_dif_block_sizes) { const int *p = tgt->tgt_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++; } } @@ -2804,17 +2789,17 @@ static ssize_t scst_tgt_dif_checks_failed_show(struct kobject *kobj, struct kobj tgt = container_of(kobj, struct scst_tgt, tgt_kobj); - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, - "\tapp\tref\tguard\ntgt\t%d\t%d\t%d\nscst\t%d\t%d\t%d\ndev\t%d\t%d\t%d\n", - atomic_read(&tgt->tgt_dif_app_failed_tgt), - atomic_read(&tgt->tgt_dif_ref_failed_tgt), - atomic_read(&tgt->tgt_dif_guard_failed_tgt), - atomic_read(&tgt->tgt_dif_app_failed_scst), - atomic_read(&tgt->tgt_dif_ref_failed_scst), - atomic_read(&tgt->tgt_dif_guard_failed_scst), - atomic_read(&tgt->tgt_dif_app_failed_dev), - atomic_read(&tgt->tgt_dif_ref_failed_dev), - atomic_read(&tgt->tgt_dif_guard_failed_dev)); + return sysfs_emit(buf, + "\tapp\tref\tguard\ntgt\t%d\t%d\t%d\nscst\t%d\t%d\t%d\ndev\t%d\t%d\t%d\n", + atomic_read(&tgt->tgt_dif_app_failed_tgt), + atomic_read(&tgt->tgt_dif_ref_failed_tgt), + atomic_read(&tgt->tgt_dif_guard_failed_tgt), + atomic_read(&tgt->tgt_dif_app_failed_scst), + atomic_read(&tgt->tgt_dif_ref_failed_scst), + atomic_read(&tgt->tgt_dif_guard_failed_scst), + atomic_read(&tgt->tgt_dif_app_failed_dev), + atomic_read(&tgt->tgt_dif_ref_failed_dev), + atomic_read(&tgt->tgt_dif_guard_failed_dev)); } static ssize_t scst_tgt_dif_checks_failed_store(struct kobject *kobj, struct kobj_attribute *attr, @@ -2889,7 +2874,7 @@ static ssize_t scst_tgt_sysfs_##attr##_show(struct kobject *kobj, \ scst_sysfs_work_get(work); \ res = scst_sysfs_queue_wait_work(work); \ if (res == 0) \ - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s", work->res_buf); \ + res = sysfs_emit(buf, "%s", work->res_buf); \ scst_sysfs_work_put(work); \ \ out: \ @@ -3095,10 +3080,10 @@ static ssize_t scst_dev_sysfs_type_show(struct kobject *kobj, struct kobj_attrib dev = container_of(kobj, struct scst_device, dev_kobj); - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d - %s\n", - dev->type, - (unsigned int)dev->type >= ARRAY_SIZE(scst_dev_handler_types) ? - "unknown" : scst_dev_handler_types[dev->type]); + return sysfs_emit(buf, "%d - %s\n", + dev->type, + (unsigned int)dev->type >= ARRAY_SIZE(scst_dev_handler_types) ? + "unknown" : scst_dev_handler_types[dev->type]); } static struct kobj_attribute dev_type_attr = @@ -3116,9 +3101,9 @@ static ssize_t scst_dev_sysfs_pr_file_name_show(struct kobject *kobj, res = mutex_lock_interruptible(&dev->dev_pr_mutex); if (res != 0) goto out; - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s", - dev->pr_file_name ? : "", - dev->pr_file_name_is_set ? SCST_SYSFS_KEY_MARK "\n" : ""); + res = sysfs_emit(buf, "%s\n%s", + dev->pr_file_name ? : "", + dev->pr_file_name_is_set ? SCST_SYSFS_KEY_MARK "\n" : ""); mutex_unlock(&dev->dev_pr_mutex); out: @@ -3357,10 +3342,10 @@ static ssize_t scst_dev_sysfs_threads_num_show(struct kobject *kobj, struct kobj dev = container_of(kobj, struct scst_device, dev_kobj); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s", - dev->threads_num, - dev->threads_num != dev->handler->threads_num ? - SCST_SYSFS_KEY_MARK "\n" : ""); + ret = sysfs_emit(buf, "%d\n%s", + dev->threads_num, + dev->threads_num != dev->handler->threads_num ? + SCST_SYSFS_KEY_MARK "\n" : ""); TRACE_EXIT_RES(ret); return ret; @@ -3427,28 +3412,28 @@ static ssize_t scst_dev_sysfs_threads_pool_type_show(struct kobject *kobj, dev = container_of(kobj, struct scst_device, dev_kobj); if (dev->threads_num == 0) { - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "Async\n"); + ret = sysfs_emit(buf, "Async\n"); goto out; } else if (dev->threads_num < 0) { - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "Not valid\n"); + ret = sysfs_emit(buf, "Not valid\n"); goto out; } switch (dev->threads_pool_type) { case SCST_THREADS_POOL_PER_INITIATOR: - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s", - SCST_THREADS_POOL_PER_INITIATOR_STR, - dev->threads_pool_type != dev->handler->threads_pool_type ? - SCST_SYSFS_KEY_MARK "\n" : ""); + ret = sysfs_emit(buf, "%s\n%s", + SCST_THREADS_POOL_PER_INITIATOR_STR, + dev->threads_pool_type != dev->handler->threads_pool_type ? + SCST_SYSFS_KEY_MARK "\n" : ""); break; case SCST_THREADS_POOL_SHARED: - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s", - SCST_THREADS_POOL_SHARED_STR, - dev->threads_pool_type != dev->handler->threads_pool_type ? - SCST_SYSFS_KEY_MARK "\n" : ""); + ret = sysfs_emit(buf, "%s\n%s", + SCST_THREADS_POOL_SHARED_STR, + dev->threads_pool_type != dev->handler->threads_pool_type ? + SCST_SYSFS_KEY_MARK "\n" : ""); break; default: - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "Unknown\n"); + ret = sysfs_emit(buf, "Unknown\n"); break; } @@ -3516,10 +3501,10 @@ static ssize_t scst_dev_sysfs_max_tgt_dev_commands_show(struct kobject *kobj, dev = container_of(kobj, struct scst_device, dev_kobj); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s", - dev->max_tgt_dev_commands, - dev->max_tgt_dev_commands != dev->handler->max_tgt_dev_commands ? - SCST_SYSFS_KEY_MARK "\n" : ""); + ret = sysfs_emit(buf, "%d\n%s", + dev->max_tgt_dev_commands, + dev->max_tgt_dev_commands != dev->handler->max_tgt_dev_commands ? + SCST_SYSFS_KEY_MARK "\n" : ""); TRACE_EXIT_RES(ret); return ret; @@ -3576,9 +3561,9 @@ static ssize_t scst_dev_numa_node_id_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->dev_numa_node_id, - dev->dev_numa_node_id != NUMA_NO_NODE ? SCST_SYSFS_KEY_MARK "\n" : ""); + ret = sysfs_emit(buf, "%d\n%s", + dev->dev_numa_node_id, + dev->dev_numa_node_id != NUMA_NO_NODE ? SCST_SYSFS_KEY_MARK "\n" : ""); TRACE_EXIT_RES(ret); return ret; @@ -3634,8 +3619,8 @@ static ssize_t scst_dev_block_show(struct kobject *kobj, struct kobj_attribute * dev = container_of(kobj, struct scst_device, dev_kobj); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d %d\n", - READ_ONCE(dev->ext_blocks_cnt), dev->ext_blocking_pending); + ret = sysfs_emit(buf, "%d %d\n", + READ_ONCE(dev->ext_blocks_cnt), dev->ext_blocking_pending); TRACE_EXIT_RES(ret); return ret; @@ -3981,30 +3966,26 @@ static ssize_t scst_dev_dif_mode_show(struct kobject *kobj, struct kobj_attribut dev = container_of(kobj, struct scst_device, dev_kobj); if (dev->dev_dif_mode == SCST_DIF_MODE_NONE) { - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "None\n"); + ret = sysfs_emit(buf, "None\n"); } else { ssize_t pos = ret; if (dev->dev_dif_mode & SCST_DIF_MODE_TGT) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, - "%s", SCST_DIF_MODE_TGT_STR); + ret += sysfs_emit_at(buf, ret, "%s", SCST_DIF_MODE_TGT_STR); if (dev->dev_dif_mode & SCST_DIF_MODE_SCST) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, - "%s%s", ret == pos ? "" : "|", SCST_DIF_MODE_SCST_STR); + ret += sysfs_emit_at(buf, ret, "%s%s", + ret == pos ? "" : "|", SCST_DIF_MODE_SCST_STR); if (dev->dev_dif_mode & SCST_DIF_MODE_DEV_CHECK) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, - "%s%s", ret == pos ? "" : "|", - SCST_DIF_MODE_DEV_CHECK_STR); + ret += sysfs_emit_at(buf, ret, "%s%s", + ret == pos ? "" : "|", SCST_DIF_MODE_DEV_CHECK_STR); if (dev->dev_dif_mode & SCST_DIF_MODE_DEV_STORE) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, - "%s%s", ret == pos ? "" : "|", - SCST_DIF_MODE_DEV_STORE_STR); + ret += sysfs_emit_at(buf, ret, "%s%s", + ret == pos ? "" : "|", SCST_DIF_MODE_DEV_STORE_STR); - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, - "\n%s", SCST_SYSFS_KEY_MARK "\n"); + ret += sysfs_emit_at(buf, ret, "\n%s\n", SCST_SYSFS_KEY_MARK); } TRACE_EXIT_RES(ret); @@ -4023,9 +4004,9 @@ static ssize_t scst_dev_dif_type_show(struct kobject *kobj, struct kobj_attribut dev = container_of(kobj, struct scst_device, dev_kobj); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s", - dev->dev_dif_type, - dev->dev_dif_type != 0 ? SCST_SYSFS_KEY_MARK "\n" : ""); + ret = sysfs_emit(buf, "%d\n%s", + dev->dev_dif_type, + dev->dev_dif_type != 0 ? SCST_SYSFS_KEY_MARK "\n" : ""); TRACE_EXIT_RES(ret); return ret; @@ -4079,9 +4060,9 @@ static ssize_t scst_dev_sysfs_dif_static_app_tag_show(struct kobject *kobj, a = scst_dev_get_dif_static_app_tag_combined(dev); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "0x%llx\n%s", - (unsigned long long)be64_to_cpu(a), - (a != SCST_DIF_NO_CHECK_APP_TAG) ? SCST_SYSFS_KEY_MARK "\n" : ""); + ret = sysfs_emit(buf, "0x%llx\n%s", + (unsigned long long)be64_to_cpu(a), + a != SCST_DIF_NO_CHECK_APP_TAG ? SCST_SYSFS_KEY_MARK "\n" : ""); TRACE_EXIT_RES(ret); return ret; @@ -4139,7 +4120,7 @@ static ssize_t scst_tgt_dev_thread_index_show(struct kobject *kobj, struct scst_tgt_dev *tgt_dev = container_of(kobj, struct scst_tgt_dev, tgt_dev_kobj); - return scnprintf(buffer, SCST_SYSFS_BLOCK_SIZE, "%d\n", tgt_dev->thread_index); + return sysfs_emit(buffer, "%d\n", tgt_dev->thread_index); } static struct kobj_attribute tgt_dev_thread_idx_attr = @@ -4157,10 +4138,10 @@ static ssize_t scst_tgt_dev_thread_pid_show(struct kobject *kobj, spin_lock(&cmd_threads->thr_lock); list_for_each_entry(t, &cmd_threads->threads_list, thread_list_entry) - ret += scnprintf(buffer + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%d%s", - task_pid_vnr(t->cmd_thread), - list_is_last(&t->thread_list_entry, - &cmd_threads->threads_list) ? "\n" : " "); + ret += sysfs_emit_at(buffer, ret, "%d%s", + task_pid_vnr(t->cmd_thread), + list_is_last(&t->thread_list_entry, + &cmd_threads->threads_list) ? "\n" : " "); spin_unlock(&cmd_threads->thr_lock); return ret; @@ -4176,8 +4157,8 @@ static ssize_t scst_tgt_dev_active_commands_show(struct kobject *kobj, struct ko tgt_dev = container_of(kobj, struct scst_tgt_dev, tgt_dev_kobj); - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", - atomic_read(&tgt_dev->tgt_dev_cmd_count)); + return sysfs_emit(buf, "%d\n", + atomic_read(&tgt_dev->tgt_dev_cmd_count)); } static struct kobj_attribute tgt_dev_active_commands_attr = @@ -4190,17 +4171,17 @@ static ssize_t scst_tgt_dev_dif_checks_failed_show(struct kobject *kobj, tgt_dev = container_of(kobj, struct scst_tgt_dev, tgt_dev_kobj); - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, - "\tapp\tref\tguard\ntgt\t%d\t%d\t%d\nscst\t%d\t%d\t%d\ndev\t%d\t%d\t%d\n", - atomic_read(&tgt_dev->tgt_dev_dif_app_failed_tgt), - atomic_read(&tgt_dev->tgt_dev_dif_ref_failed_tgt), - atomic_read(&tgt_dev->tgt_dev_dif_guard_failed_tgt), - atomic_read(&tgt_dev->tgt_dev_dif_app_failed_scst), - atomic_read(&tgt_dev->tgt_dev_dif_ref_failed_scst), - atomic_read(&tgt_dev->tgt_dev_dif_guard_failed_scst), - atomic_read(&tgt_dev->tgt_dev_dif_app_failed_dev), - atomic_read(&tgt_dev->tgt_dev_dif_ref_failed_dev), - atomic_read(&tgt_dev->tgt_dev_dif_guard_failed_dev)); + return sysfs_emit(buf, + "\tapp\tref\tguard\ntgt\t%d\t%d\t%d\nscst\t%d\t%d\t%d\ndev\t%d\t%d\t%d\n", + atomic_read(&tgt_dev->tgt_dev_dif_app_failed_tgt), + atomic_read(&tgt_dev->tgt_dev_dif_ref_failed_tgt), + atomic_read(&tgt_dev->tgt_dev_dif_guard_failed_tgt), + atomic_read(&tgt_dev->tgt_dev_dif_app_failed_scst), + atomic_read(&tgt_dev->tgt_dev_dif_ref_failed_scst), + atomic_read(&tgt_dev->tgt_dev_dif_guard_failed_scst), + atomic_read(&tgt_dev->tgt_dev_dif_app_failed_dev), + atomic_read(&tgt_dev->tgt_dev_dif_ref_failed_dev), + atomic_read(&tgt_dev->tgt_dev_dif_guard_failed_dev)); } static ssize_t scst_tgt_dev_dif_checks_failed_store(struct kobject *kobj, @@ -4385,8 +4366,7 @@ static ssize_t scst_sess_latency_show(struct kobject *kobj, struct kobj_attribut goto out; } - res += scnprintf(buf + res, SCST_SYSFS_BLOCK_SIZE - res, - "state count min max avg stddev\n"); + res += sysfs_emit_at(buf, res, "state count min max avg stddev\n"); spin_lock_irq(&sess->lat_stats_lock); for (k = 0; k < SCST_CMD_STATE_COUNT; k++) { @@ -4410,25 +4390,25 @@ static ssize_t scst_sess_latency_show(struct kobject *kobj, struct kobj_attribut avg_mod_10 = do_div(avg_div_10, 10); stddev_div_10 = stddev; stddev_mod_10 = do_div(stddev_div_10, 10); - res += scnprintf(buf + res, SCST_SYSFS_BLOCK_SIZE - res, - "%s %d %lld.%01d %lld.%01d %lld.%01d %lld.%01d us\n", - state_name, d->count, - d_min_div_10, d_min_mod_10, - d_max_div_10, d_max_mod_10, - avg_div_10, avg_mod_10, - stddev_div_10, stddev_mod_10); + res += sysfs_emit_at(buf, res, + "%s %d %lld.%01d %lld.%01d %lld.%01d %lld.%01d us\n", + state_name, d->count, + d_min_div_10, d_min_mod_10, + d_max_div_10, d_max_mod_10, + avg_div_10, avg_mod_10, + stddev_div_10, stddev_mod_10); #ifdef SCST_MEASURE_CLOCK_CYCLES min = d->minc * 10000 / (tsc_khz / 100); max = d->maxc * 10000 / (tsc_khz / 100); avg = d->sumc * 10000 / (d->count * 1ull * tsc_khz / 100); stddev = calc_stddev(d->sumsqc, d->sumc, d->count) * 1000000 / tsc_khz; - res += scnprintf(buf + res, SCST_SYSFS_BLOCK_SIZE - res, - "%s %d %lld.%01lld %lld.%01lld %lld.%01lld %lld.%01lld cc -> us\n", - state_name, d->count, - min / 10, min % 10, - max / 10, max % 10, - avg / 10, avg % 10, - stddev / 10, stddev % 10); + res += sysfs_emit_at(buf, res, + "%s %d %lld.%01lld %lld.%01lld %lld.%01lld %lld.%01lld cc -> us\n", + state_name, d->count, + min / 10, min % 10, + max / 10, max % 10, + avg / 10, avg % 10, + stddev / 10, stddev % 10); sumc += d->sumc; sumsqc += d->sumsqc; #else @@ -4444,10 +4424,10 @@ static ssize_t scst_sess_latency_show(struct kobject *kobj, struct kobj_attribut #ifdef SCST_MEASURE_CLOCK_CYCLES avg = numst * sumc / (count * 1ull * tsc_khz / 1000000); stddev = calc_stddev(sumsqc, sumc, count) * numst * 1000000 / tsc_khz; - res += scnprintf(buf + res, SCST_SYSFS_BLOCK_SIZE - res, - "total %d - - %lld.%01lld %lld.%01lld cc -> us\n", - count / numst, avg / 10, avg % 10, stddev / 10, - stddev % 10); + res += sysfs_emit_at(buf, res, + "total %d - - %lld.%01lld %lld.%01lld cc -> us\n", + count / numst, avg / 10, avg % 10, stddev / 10, + stddev % 10); #else avg = numst * sum; do_div(avg, count); @@ -4456,10 +4436,10 @@ static ssize_t scst_sess_latency_show(struct kobject *kobj, struct kobj_attribut avg_mod_10 = do_div(avg_div_10, 10); stddev_div_10 = stddev; stddev_mod_10 = do_div(stddev_div_10, 10); - res += scnprintf(buf + res, SCST_SYSFS_BLOCK_SIZE - res, - "total %d - - %lld.%01d %lld.%01d us\n", - count / numst, avg_div_10, avg_mod_10, - stddev_div_10, stddev_mod_10); + res += sysfs_emit_at(buf, res, + "total %d - - %lld.%01d %lld.%01d us\n", + count / numst, avg_div_10, avg_mod_10, + stddev_div_10, stddev_mod_10); #endif } @@ -4488,7 +4468,7 @@ static ssize_t scst_sess_sysfs_commands_show(struct kobject *kobj, struct kobj_a sess = container_of(kobj, struct scst_session, sess_kobj); - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", atomic_read(&sess->sess_cmd_count)); + return sysfs_emit(buf, "%d\n", atomic_read(&sess->sess_cmd_count)); } static struct kobj_attribute session_commands_attr = @@ -4544,7 +4524,7 @@ static ssize_t scst_sess_sysfs_active_commands_show(struct kobject *kobj, res = scst_sysfs_queue_wait_work(work); if (res != -EAGAIN) - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", res); + res = sysfs_emit(buf, "%d\n", res); out: return res; @@ -4619,7 +4599,7 @@ static ssize_t scst_sess_sysfs_dif_checks_failed_show(struct kobject *kobj, if (res != 0) goto out_put; - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s", work->res_buf); + res = sysfs_emit(buf, "%s", work->res_buf); out_put: scst_sysfs_work_put(work); @@ -4707,7 +4687,7 @@ static ssize_t scst_sess_sysfs_initiator_name_show(struct kobject *kobj, sess = container_of(kobj, struct scst_session, sess_kobj); - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", sess->initiator_name); + return sysfs_emit(buf, "%s\n", sess->initiator_name); } static struct kobj_attribute session_initiator_name_attr = @@ -4732,7 +4712,7 @@ static ssize_t scst_sess_sysfs_##exported_name##_show(struct kobject *kobj, \ v = sess->io_stats[dir].name; \ if (kb) \ v >>= 10; \ - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%llu\n", (unsigned long long)v); \ + return sysfs_emit(buf, "%llu\n", (unsigned long long)v); \ } \ \ static ssize_t scst_sess_sysfs_##exported_name##_store(struct kobject *kobj, \ @@ -5046,9 +5026,9 @@ static ssize_t scst_lun_rd_only_show(struct kobject *kobj, struct kobj_attribute acg_dev = container_of(kobj, struct scst_acg_dev, acg_dev_kobj); if (acg_dev->acg_dev_rd_only || acg_dev->dev->dev_rd_only) - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s\n", 1, SCST_SYSFS_KEY_MARK); + return sysfs_emit(buf, "%d\n%s\n", 1, SCST_SYSFS_KEY_MARK); else - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", 0); + return sysfs_emit(buf, "%d\n", 0); } static struct kobj_attribute lun_options_attr = @@ -5170,9 +5150,9 @@ static ssize_t scst_acg_ini_mgmt_show(struct kobject *kobj, struct kobj_attribut "Usage: echo \"add INITIATOR_NAME\" >mgmt\n" " echo \"del INITIATOR_NAME\" >mgmt\n" " echo \"move INITIATOR_NAME DEST_GROUP_NAME\" >mgmt\n" - " echo \"clear\" >mgmt\n"; + " echo \"clear\" >mgmt"; - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s", help); + return sysfs_emit(buf, "%s\n", help); } static int scst_process_acg_ini_mgmt_store(char *buffer, struct scst_tgt *tgt, @@ -5602,7 +5582,7 @@ out_del: static ssize_t scst_acn_file_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", attr->attr.name); + return sysfs_emit(buf, "%s\n", attr->attr.name); } int scst_acn_sysfs_create(struct scst_acn *acn) @@ -5741,10 +5721,10 @@ static ssize_t scst_devt_type_show(struct kobject *kobj, struct kobj_attribute * devt = container_of(kobj, struct scst_dev_type, devt_kobj); - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d - %s\n", - devt->type, - (unsigned int)devt->type >= ARRAY_SIZE(scst_dev_handler_types) ? - "unknown" : scst_dev_handler_types[devt->type]); + return sysfs_emit(buf, "%d - %s\n", + devt->type, + (unsigned int)devt->type >= ARRAY_SIZE(scst_dev_handler_types) ? + "unknown" : scst_dev_handler_types[devt->type]); } static struct kobj_attribute scst_devt_type_attr = @@ -5807,25 +5787,25 @@ static ssize_t scst_devt_mgmt_show(struct kobject *kobj, struct kobj_attribute * devt = container_of(kobj, struct scst_dev_type, devt_kobj); p = scst_dev_params(devt); - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, help, - devt->devt_optional_attributes ? - " echo \"add_attribute \" >mgmt\n" - " echo \"del_attribute \" >mgmt\n" : "", - devt->dev_optional_attributes ? - " echo \"add_device_attribute device_name \" >mgmt\n" - " echo \"del_device_attribute device_name \" >mgmt\n" : "", - devt->mgmt_cmd_help ? devt->mgmt_cmd_help : "", - devt->mgmt_cmd_help ? "\n" : "", - p ?: "", - devt->add_device_parameters ? "\n" : "", - devt->devt_optional_attributes ? - "The following dev handler attributes available: " : "", - devt->devt_optional_attributes ? devt->devt_optional_attributes : "", - devt->devt_optional_attributes ? "\n" : "", - devt->dev_optional_attributes ? - "The following device attributes available: " : "", - devt->dev_optional_attributes ? devt->dev_optional_attributes : "", - devt->dev_optional_attributes ? "\n" : ""); + res = sysfs_emit(buf, help, + devt->devt_optional_attributes ? + " echo \"add_attribute \" >mgmt\n" + " echo \"del_attribute \" >mgmt\n" : "", + devt->dev_optional_attributes ? + " echo \"add_device_attribute device_name \" >mgmt\n" + " echo \"del_device_attribute device_name \" >mgmt\n" : "", + devt->mgmt_cmd_help ? devt->mgmt_cmd_help : "", + devt->mgmt_cmd_help ? "\n" : "", + p ?: "", + devt->add_device_parameters ? "\n" : "", + devt->devt_optional_attributes ? + "The following dev handler attributes available: " : "", + devt->devt_optional_attributes ? devt->devt_optional_attributes : "", + devt->devt_optional_attributes ? "\n" : "", + devt->dev_optional_attributes ? + "The following device attributes available: " : "", + devt->dev_optional_attributes ? devt->dev_optional_attributes : "", + devt->dev_optional_attributes ? "\n" : ""); kfree(p); return res; } @@ -5947,9 +5927,9 @@ static ssize_t scst_devt_pass_through_mgmt_show(struct kobject *kobj, struct kob { static const char help[] = "Usage: echo \"add_device H:C:I:L\" >mgmt\n" - " echo \"del_device H:C:I:L\" >mgmt\n"; + " echo \"del_device H:C:I:L\" >mgmt"; - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s", help); + return sysfs_emit(buf, "%s\n", help); } static int scst_process_devt_pass_through_mgmt_store(char *buffer, struct scst_dev_type *devt) @@ -6193,7 +6173,7 @@ static ssize_t scst_dg_devs_mgmt_show(struct kobject *kobj, struct kobj_attribut "Usage: echo \"add device\" >mgmt\n" " echo \"del device\" >mgmt\n"; - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, help); + return sysfs_emit(buf, help); } static int scst_dg_devs_mgmt_store_work_fn(struct scst_sysfs_work_item *w) @@ -6285,8 +6265,8 @@ static ssize_t scst_tg_tgt_rel_tgt_id_show(struct kobject *kobj, struct scst_tg_tgt *tg_tgt; tg_tgt = container_of(kobj, struct scst_tg_tgt, kobj); - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%u\n" SCST_SYSFS_KEY_MARK "\n", - tg_tgt->rel_tgt_id); + return sysfs_emit(buf, "%u\n" SCST_SYSFS_KEY_MARK "\n", + tg_tgt->rel_tgt_id); } static ssize_t scst_tg_tgt_rel_tgt_id_store(struct kobject *kobj, @@ -6374,8 +6354,8 @@ static ssize_t scst_tg_group_id_show(struct kobject *kobj, struct scst_target_group *tg; tg = container_of(kobj, struct scst_target_group, kobj); - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%u\n" SCST_SYSFS_KEY_MARK "\n", - tg->group_id); + return sysfs_emit(buf, "%u\n" SCST_SYSFS_KEY_MARK "\n", + tg->group_id); } static ssize_t scst_tg_group_id_store(struct kobject *kobj, @@ -6414,8 +6394,8 @@ static ssize_t scst_tg_preferred_show(struct kobject *kobj, tg = container_of(kobj, struct scst_target_group, kobj); - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%u\n%s", tg->preferred, - tg->preferred ? SCST_SYSFS_KEY_MARK "\n" : ""); + return sysfs_emit(buf, "%u\n%s", tg->preferred, + tg->preferred ? SCST_SYSFS_KEY_MARK "\n" : ""); } static int scst_tg_preferred_store_work_fn(struct scst_sysfs_work_item *w) @@ -6487,8 +6467,8 @@ static ssize_t scst_tg_state_show(struct kobject *kobj, tg = container_of(kobj, struct scst_target_group, kobj); n = scst_alua_state_name(tg->state); - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n" SCST_SYSFS_KEY_MARK "\n", - n ? n : "???"); + return sysfs_emit(buf, "%s\n" SCST_SYSFS_KEY_MARK "\n", + n ? n : "???"); } static int scst_tg_state_store_work_fn(struct scst_sysfs_work_item *w) @@ -6565,7 +6545,7 @@ static ssize_t scst_tg_mgmt_show(struct kobject *kobj, "Usage: echo \"add target\" >mgmt\n" " echo \"del target\" >mgmt\n"; - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, help); + return sysfs_emit(buf, help); } static int scst_tg_mgmt_store_work_fn(struct scst_sysfs_work_item *w) @@ -6687,7 +6667,7 @@ static ssize_t scst_dg_tgs_mgmt_show(struct kobject *kobj, struct kobj_attribute "Usage: echo \"create group_name\" >mgmt\n" " echo \"del group_name\" >mgmt\n"; - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, help); + return sysfs_emit(buf, help); } static int scst_dg_tgs_mgmt_store_work_fn(struct scst_sysfs_work_item *w) @@ -6827,7 +6807,7 @@ static ssize_t scst_device_groups_mgmt_show(struct kobject *kobj, "Usage: echo \"create group_name\" >mgmt\n" " echo \"del group_name\" >mgmt\n"; - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, help); + return sysfs_emit(buf, help); } static ssize_t scst_device_groups_mgmt_store(struct kobject *kobj, @@ -6883,7 +6863,7 @@ static struct kobject scst_sysfs_root_kobj; static ssize_t scst_measure_latency_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", atomic_read(&scst_measure_latency)); + return sysfs_emit(buf, "%d\n", atomic_read(&scst_measure_latency)); } static void scst_free_lat_stats_mem(void) @@ -6985,10 +6965,10 @@ static ssize_t scst_threads_show(struct kobject *kobj, struct kobj_attribute *at TRACE_ENTRY(); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s", - scst_main_cmd_threads.nr_threads, - (scst_main_cmd_threads.nr_threads != scst_threads) ? - SCST_SYSFS_KEY_MARK "\n" : ""); + ret = sysfs_emit(buf, "%d\n%s", + scst_main_cmd_threads.nr_threads, + (scst_main_cmd_threads.nr_threads != scst_threads) ? + SCST_SYSFS_KEY_MARK "\n" : ""); TRACE_EXIT(); @@ -7092,9 +7072,9 @@ static ssize_t scst_setup_id_show(struct kobject *kobj, TRACE_ENTRY(); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "0x%x\n%s\n", - scst_setup_id, - scst_setup_id == 0 ? "" : SCST_SYSFS_KEY_MARK); + ret = sysfs_emit(buf, "0x%x\n%s", + scst_setup_id, + scst_setup_id == 0 ? "" : SCST_SYSFS_KEY_MARK "\n"); TRACE_EXIT(); @@ -7135,10 +7115,10 @@ static ssize_t scst_max_tasklet_cmd_show(struct kobject *kobj, struct kobj_attri TRACE_ENTRY(); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s\n", - scst_max_tasklet_cmd, - scst_max_tasklet_cmd == SCST_DEF_MAX_TASKLET_CMD ? - "" : SCST_SYSFS_KEY_MARK); + ret = sysfs_emit(buf, "%d\n%s", + scst_max_tasklet_cmd, + scst_max_tasklet_cmd == SCST_DEF_MAX_TASKLET_CMD ? + "" : SCST_SYSFS_KEY_MARK "\n"); TRACE_EXIT(); @@ -7180,9 +7160,9 @@ static ssize_t scst_poll_us_show(struct kobject *kobj, struct kobj_attribute *at TRACE_ENTRY(); do_div(t, 1000); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%lld\n%s\n", - t, - scst_poll_ns == SCST_DEF_POLL_NS ? "" : SCST_SYSFS_KEY_MARK); + ret = sysfs_emit(buf, "%lld\n%s", + t, + scst_poll_ns == SCST_DEF_POLL_NS ? "" : SCST_SYSFS_KEY_MARK "\n"); TRACE_EXIT(); @@ -7225,7 +7205,7 @@ static ssize_t scst_suspend_show(struct kobject *kobj, TRACE_ENTRY(); - ret = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", scst_get_suspend_count()); + ret = sysfs_emit(buf, "%d\n", scst_get_suspend_count()); TRACE_EXIT(); @@ -7304,9 +7284,9 @@ static struct kobj_attribute scst_main_trace_level_attr = static ssize_t scst_force_global_sgv_pool_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n%s\n", - scst_force_global_sgv_pool, - scst_force_global_sgv_pool ? SCST_SYSFS_KEY_MARK "\n" : ""); + return sysfs_emit(buf, "%d\n%s", + scst_force_global_sgv_pool, + scst_force_global_sgv_pool ? SCST_SYSFS_KEY_MARK "\n" : ""); } static ssize_t scst_force_global_sgv_pool_store(struct kobject *kobj, struct kobj_attribute *attr, @@ -7378,7 +7358,7 @@ static ssize_t scst_show_trace_cmds(struct kobject *kobj, if (res != 0) goto put; - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s", work->res_buf); + res = sysfs_emit(buf, "%s", work->res_buf); put: scst_sysfs_work_put(work); @@ -7409,7 +7389,7 @@ put: static ssize_t scst_show_trace_mcmds(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { struct scst_sysfs_work_item *work; - int res; + ssize_t res; res = scst_alloc_sysfs_work(scst_process_show_trace_mcmds, true, &work); @@ -7422,7 +7402,7 @@ static ssize_t scst_show_trace_mcmds(struct kobject *kobj, struct kobj_attribute if (res != 0) goto put; - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s", work->res_buf); + res = sysfs_emit(buf, "%s", work->res_buf); put: scst_sysfs_work_put(work); @@ -7443,26 +7423,15 @@ static ssize_t scst_version_show(struct kobject *kobj, TRACE_ENTRY(); - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "SCST version: %s\n", - SCST_VERSION_STRING); - - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "SCST build date: %s\n", - SCST_BUILD_DATE_STRING); - - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "SCST git commit sha1: %s\n", - SCST_GIT_COMMIT_STRING); - - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "SCST kver: %s\n", - SCST_KVER_STRING); - - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "SCST build number: %s\n", - SCST_BUILD_NUMBER_STRING); - - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "SCST arch type: %s\n", - SCST_ARCH_TYPE_STRING); + ret += sysfs_emit_at(buf, ret, "SCST version: %s\n", SCST_VERSION_STRING); + ret += sysfs_emit_at(buf, ret, "SCST build date: %s\n", SCST_BUILD_DATE_STRING); + ret += sysfs_emit_at(buf, ret, "SCST git commit sha1: %s\n", SCST_GIT_COMMIT_STRING); + ret += sysfs_emit_at(buf, ret, "SCST kver: %s\n", SCST_KVER_STRING); + ret += sysfs_emit_at(buf, ret, "SCST build number: %s\n", SCST_BUILD_NUMBER_STRING); + ret += sysfs_emit_at(buf, ret, "SCST arch type: %s\n", SCST_ARCH_TYPE_STRING); if (scst_dump_config(config, sizeof(config))) - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%s\n", config); + ret += sysfs_emit_at(buf, ret, "%s\n", config); TRACE_EXIT(); @@ -7484,7 +7453,7 @@ static ssize_t scst_last_sysfs_mgmt_res_show(struct kobject *kobj, struct kobj_a if (active_sysfs_works > 0) res = -EAGAIN; else - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", last_sysfs_work_res); + res = sysfs_emit(buf, "%d\n", last_sysfs_work_res); spin_unlock(&sysfs_work_lock); TRACE_EXIT_RES(res); @@ -7501,8 +7470,8 @@ static ssize_t scst_cluster_name_show(struct kobject *kobj, struct kobj_attribut TRACE_ENTRY(); if (scst_cluster_name) - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s", - scst_cluster_name, SCST_SYSFS_KEY_MARK "\n"); + res = sysfs_emit(buf, "%s\n%s", + scst_cluster_name, SCST_SYSFS_KEY_MARK "\n"); TRACE_EXIT_RES(res); return res; diff --git a/scst_local/scst_local.c b/scst_local/scst_local.c index 82c16f7af..c17011603 100644 --- a/scst_local/scst_local.c +++ b/scst_local/scst_local.c @@ -246,19 +246,19 @@ static ssize_t scst_local_version_show(struct kobject *kobj, struct kobj_attribu { ssize_t ret = 0; - ret += scnprintf(buf + ret, SCST_SYSFS_BLOCK_SIZE - ret, "%s/%s\n", - SCST_LOCAL_VERSION, scst_local_version_date); + ret += sysfs_emit_at(buf, ret, "%s/%s\n", + SCST_LOCAL_VERSION, scst_local_version_date); #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 TRACE_EXIT(); @@ -271,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 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)); + return sysfs_emit(buf, + "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 = @@ -308,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 = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "0x%x\n%s", - tgt->scsi_transport_version, SCST_SYSFS_KEY_MARK "\n"); + res = sysfs_emit(buf, "0x%x\n%s\n", + tgt->scsi_transport_version, SCST_SYSFS_KEY_MARK); else - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "0x%x\n", 0x0BE0); /* SAS */ + res = sysfs_emit(buf, "0x%x\n", 0x0BE0); /* SAS */ out_up: up_read(&scst_local_exit_rwsem); @@ -376,9 +376,9 @@ static ssize_t scst_local_phys_transport_version_show(struct kobject *kobj, if (!tgt) goto out_up; - 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" : ""); + res = sysfs_emit(buf, "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,7 +446,7 @@ static ssize_t host_no_show(struct kobject *kobj, struct kobj_attribute *attr, c if (!host) return -EINVAL; - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%u\n", host->host_no); + return sysfs_emit(buf, "%u\n", host->host_no); } static struct kobj_attribute scst_local_host_no_attr = __ATTR_RO(host_no); @@ -479,7 +479,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 += scnprintf(buf + res, SCST_SYSFS_BLOCK_SIZE - res, "%c", tr_id[i]); + res += sysfs_emit_at(buf, res, "%c", tr_id[i]); if (!sess->transport_id) kfree(tr_id); diff --git a/srpt/src/ib_srpt.c b/srpt/src/ib_srpt.c index 27aece6a5..7286365e8 100644 --- a/srpt/src/ib_srpt.c +++ b/srpt/src/ib_srpt.c @@ -3956,11 +3956,10 @@ static ssize_t show_comp_v_mask(struct kobject *kobj, #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0) res = cpumask_scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, &sport->comp_v_mask); #else - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%*pb", - cpumask_pr_args(&sport->comp_v_mask)); + res = sysfs_emit(buf, "%*pb", + cpumask_pr_args(&sport->comp_v_mask)); #endif - res += scnprintf(buf + res, SCST_SYSFS_BLOCK_SIZE - res, "\n%s\n", - SCST_SYSFS_KEY_MARK); + res += sysfs_emit_at(buf, res, "\n%s\n", SCST_SYSFS_KEY_MARK); out: return res; @@ -4019,7 +4018,7 @@ static ssize_t srpt_show_device(struct kobject *kobj, goto out; sdev = sport->sdev; - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", dev_name(&sdev->device->dev)); + res = sysfs_emit(buf, "%s\n", dev_name(&sdev->device->dev)); out: return res; @@ -4055,7 +4054,7 @@ static ssize_t srpt_show_link_layer(struct kobject *kobj, default: break; } - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", lln); + res = sysfs_emit(buf, "%s\n", lln); out: return res; @@ -4074,10 +4073,10 @@ static ssize_t show_port_id(struct kobject *kobj, struct kobj_attribute *attr, c goto out; mutex_lock(&sport->mutex); - res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n%s", - sport->port_id, - strcmp(sport->port_id, DEFAULT_SRPT_ID_STRING) ? - SCST_SYSFS_KEY_MARK "\n" : ""); + res = sysfs_emit(buf, "%s\n%s", + sport->port_id, + strcmp(sport->port_id, DEFAULT_SRPT_ID_STRING) ? + SCST_SYSFS_KEY_MARK "\n" : ""); mutex_unlock(&sport->mutex); out: @@ -4127,18 +4126,18 @@ static ssize_t show_login_info(struct kobject *kobj, if (!sport) goto out; - 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); + res = sysfs_emit(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); out: return res; @@ -4167,7 +4166,7 @@ static ssize_t show_req_lim(struct kobject *kobj, if (!ch) return -ENOENT; - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", ch->req_lim); + return sysfs_emit(buf, "%d\n", ch->req_lim); } static ssize_t show_req_lim_delta(struct kobject *kobj, @@ -4181,7 +4180,7 @@ static ssize_t show_req_lim_delta(struct kobject *kobj, if (!ch) return -ENOENT; - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%d\n", ch->req_lim_delta); + return sysfs_emit(buf, "%d\n", ch->req_lim_delta); } static ssize_t show_ch_state(struct kobject *kobj, struct kobj_attribute *attr, @@ -4195,7 +4194,7 @@ static ssize_t show_ch_state(struct kobject *kobj, struct kobj_attribute *attr, if (!ch) return -ENOENT; - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%s\n", get_ch_state_name(ch->state)); + return sysfs_emit(buf, "%s\n", get_ch_state_name(ch->state)); } static ssize_t show_comp_vector(struct kobject *kobj, @@ -4205,9 +4204,12 @@ static ssize_t show_comp_vector(struct kobject *kobj, struct srpt_rdma_ch *ch; sess = container_of(kobj, struct scst_session, sess_kobj); - ch = scst_sess_get_tgt_priv(sess); - return ch ? scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, "%u\n", ch->comp_vector) : -ENOENT; + ch = scst_sess_get_tgt_priv(sess); + if (!ch) + return -ENOENT; + + return sysfs_emit(buf, "%u\n", ch->comp_vector); } static const struct kobj_attribute srpt_req_lim_attr =