git: 839d0755fea8 - main - ctld: Convert to C++
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 02 Apr 2025 18:43:31 UTC
The branch main has been updated by jhb:
URL: https://cgit.FreeBSD.org/src/commit/?id=839d0755fea8ef761698b50fa5f293546ae832a8
commit 839d0755fea8ef761698b50fa5f293546ae832a8
Author: John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2025-04-02 18:41:35 +0000
Commit: John Baldwin <jhb@FreeBSD.org>
CommitDate: 2025-04-02 18:41:35 +0000
ctld: Convert to C++
This is the minimal set of changes need to compile as C++ so git can
handle the rename correctly.
Reviewed by: asomers
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D49139
---
usr.sbin/ctld/Makefile | 6 ++---
usr.sbin/ctld/{conf.c => conf.cc} | 0
usr.sbin/ctld/conf.h | 4 ++++
usr.sbin/ctld/{ctld.c => ctld.cc} | 35 ++++++++++++++++-------------
usr.sbin/ctld/{discovery.c => discovery.cc} | 0
usr.sbin/ctld/{isns.c => isns.cc} | 6 ++---
usr.sbin/ctld/{kernel.c => kernel.cc} | 12 +++++-----
usr.sbin/ctld/{login.c => login.cc} | 8 +++----
usr.sbin/ctld/{uclparse.c => uclparse.cc} | 0
9 files changed, 39 insertions(+), 32 deletions(-)
diff --git a/usr.sbin/ctld/Makefile b/usr.sbin/ctld/Makefile
index 787a608c37be..f96f3152e061 100644
--- a/usr.sbin/ctld/Makefile
+++ b/usr.sbin/ctld/Makefile
@@ -4,9 +4,9 @@ CFLAGS+=-I${SRCTOP}/contrib/libucl/include
.PATH: ${SRCTOP}/contrib/libucl/include
PACKAGE= iscsi
-PROG= ctld
-SRCS= ctld.c conf.c discovery.c isns.c kernel.c
-SRCS+= login.c parse.y token.l y.tab.h uclparse.c
+PROG_CXX= ctld
+SRCS= ctld.cc conf.cc discovery.cc isns.cc kernel.cc
+SRCS+= login.cc parse.y token.l y.tab.h uclparse.cc
CFLAGS+= -I${.CURDIR}
CFLAGS+= -I${SRCTOP}/sys
CFLAGS+= -I${SRCTOP}/sys/cam/ctl
diff --git a/usr.sbin/ctld/conf.c b/usr.sbin/ctld/conf.cc
similarity index 100%
rename from usr.sbin/ctld/conf.c
rename to usr.sbin/ctld/conf.cc
diff --git a/usr.sbin/ctld/conf.h b/usr.sbin/ctld/conf.h
index d8f036e67136..6e287ce70436 100644
--- a/usr.sbin/ctld/conf.h
+++ b/usr.sbin/ctld/conf.h
@@ -36,6 +36,8 @@
* ctld.
*/
+__BEGIN_DECLS
+
bool auth_group_start(const char *name);
void auth_group_finish(void);
bool auth_group_add_chap(const char *user, const char *secret);
@@ -97,4 +99,6 @@ bool lun_set_size(uint64_t value);
bool parse_conf(const char *path);
+__END_DECLS
+
#endif /* !__CONF_H__ */
diff --git a/usr.sbin/ctld/ctld.c b/usr.sbin/ctld/ctld.cc
similarity index 98%
rename from usr.sbin/ctld/ctld.c
rename to usr.sbin/ctld/ctld.cc
index 21d833df5f83..f07ee7b34cd7 100644
--- a/usr.sbin/ctld/ctld.c
+++ b/usr.sbin/ctld/ctld.cc
@@ -77,6 +77,9 @@ static struct connection_ops conn_ops = {
#ifdef ICL_KERNEL_PROXY
.pdu_receive_proxy = pdu_receive_proxy,
.pdu_send_proxy = pdu_send_proxy,
+#else
+ .pdu_receive_proxy = nullptr,
+ .pdu_send_proxy = nullptr,
#endif
.fail = pdu_fail,
};
@@ -95,7 +98,7 @@ conf_new(void)
{
struct conf *conf;
- conf = calloc(1, sizeof(*conf));
+ conf = reinterpret_cast<struct conf *>(calloc(1, sizeof(*conf)));
if (conf == NULL)
log_err(1, "calloc");
TAILQ_INIT(&conf->conf_luns);
@@ -145,7 +148,7 @@ auth_new(struct auth_group *ag)
{
struct auth *auth;
- auth = calloc(1, sizeof(*auth));
+ auth = reinterpret_cast<struct auth *>(calloc(1, sizeof(*auth)));
if (auth == NULL)
log_err(1, "calloc");
auth->a_auth_group = ag;
@@ -303,7 +306,7 @@ auth_name_new(struct auth_group *ag, const char *name)
{
struct auth_name *an;
- an = calloc(1, sizeof(*an));
+ an = reinterpret_cast<struct auth_name *>(calloc(1, sizeof(*an)));
if (an == NULL)
log_err(1, "calloc");
an->an_auth_group = ag;
@@ -361,7 +364,7 @@ auth_portal_new(struct auth_group *ag, const char *portal)
char *net, *mask, *str, *tmp;
int len, dm, m;
- ap = calloc(1, sizeof(*ap));
+ ap = reinterpret_cast<struct auth_portal *>(calloc(1, sizeof(*ap)));
if (ap == NULL)
log_err(1, "calloc");
ap->ap_auth_group = ag;
@@ -494,7 +497,7 @@ auth_group_new(struct conf *conf, const char *name)
}
}
- ag = calloc(1, sizeof(*ag));
+ ag = reinterpret_cast<struct auth_group *>(calloc(1, sizeof(*ag)));
if (ag == NULL)
log_err(1, "calloc");
if (name != NULL)
@@ -547,7 +550,7 @@ portal_new(struct portal_group *pg)
{
struct portal *portal;
- portal = calloc(1, sizeof(*portal));
+ portal = reinterpret_cast<struct portal *>(calloc(1, sizeof(*portal)));
if (portal == NULL)
log_err(1, "calloc");
TAILQ_INIT(&portal->p_targets);
@@ -578,7 +581,7 @@ portal_group_new(struct conf *conf, const char *name)
return (NULL);
}
- pg = calloc(1, sizeof(*pg));
+ pg = reinterpret_cast<struct portal_group *>(calloc(1, sizeof(*pg)));
if (pg == NULL)
log_err(1, "calloc");
pg->pg_name = checked_strdup(name);
@@ -711,7 +714,7 @@ isns_new(struct conf *conf, const char *addr)
{
struct isns *isns;
- isns = calloc(1, sizeof(*isns));
+ isns = reinterpret_cast<struct isns *>(calloc(1, sizeof(*isns)));
if (isns == NULL)
log_err(1, "calloc");
isns->i_conf = conf;
@@ -973,7 +976,7 @@ pport_new(struct kports *kports, const char *name, uint32_t ctl_port)
{
struct pport *pp;
- pp = calloc(1, sizeof(*pp));
+ pp = reinterpret_cast<struct pport *>(calloc(1, sizeof(*pp)));
if (pp == NULL)
log_err(1, "calloc");
pp->pp_kports = kports;
@@ -1032,7 +1035,7 @@ port_new(struct conf *conf, struct target *target, struct portal_group *pg)
free(name);
return (NULL);
}
- port = calloc(1, sizeof(*port));
+ port = reinterpret_cast<struct port *>(calloc(1, sizeof(*port)));
if (port == NULL)
log_err(1, "calloc");
port->p_conf = conf;
@@ -1077,7 +1080,7 @@ port_new_ioctl(struct conf *conf, struct kports *kports, struct target *target,
free(name);
return (NULL);
}
- port = calloc(1, sizeof(*port));
+ port = reinterpret_cast<struct port *>(calloc(1, sizeof(*port)));
if (port == NULL)
log_err(1, "calloc");
port->p_conf = conf;
@@ -1106,7 +1109,7 @@ port_new_pp(struct conf *conf, struct target *target, struct pport *pp)
free(name);
return (NULL);
}
- port = calloc(1, sizeof(*port));
+ port = reinterpret_cast<struct port *>(calloc(1, sizeof(*port)));
if (port == NULL)
log_err(1, "calloc");
port->p_conf = conf;
@@ -1187,7 +1190,7 @@ target_new(struct conf *conf, const char *name)
if (valid_iscsi_name(name, log_warnx) == false) {
return (NULL);
}
- targ = calloc(1, sizeof(*targ));
+ targ = reinterpret_cast<struct target *>(calloc(1, sizeof(*targ)));
if (targ == NULL)
log_err(1, "calloc");
targ->t_name = checked_strdup(name);
@@ -1245,7 +1248,7 @@ lun_new(struct conf *conf, const char *name)
return (NULL);
}
- lun = calloc(1, sizeof(*lun));
+ lun = reinterpret_cast<struct lun *>(calloc(1, sizeof(*lun)));
if (lun == NULL)
log_err(1, "calloc");
lun->l_conf = conf;
@@ -1365,7 +1368,7 @@ connection_new(struct portal *portal, int fd, const char *host,
{
struct ctld_connection *conn;
- conn = calloc(1, sizeof(*conn));
+ conn = reinterpret_cast<struct ctld_connection *>(calloc(1, sizeof(*conn)));
if (conn == NULL)
log_err(1, "calloc");
connection_init(&conn->conn, &conn_ops, proxy_mode);
@@ -2254,7 +2257,7 @@ found:
switch (kev.filter) {
case EVFILT_READ:
- portal = kev.udata;
+ portal = reinterpret_cast<struct portal *>(kev.udata);
assert(portal->p_socket == (int)kev.ident);
client_salen = sizeof(client_sa);
diff --git a/usr.sbin/ctld/discovery.c b/usr.sbin/ctld/discovery.cc
similarity index 100%
rename from usr.sbin/ctld/discovery.c
rename to usr.sbin/ctld/discovery.cc
diff --git a/usr.sbin/ctld/isns.c b/usr.sbin/ctld/isns.cc
similarity index 96%
rename from usr.sbin/ctld/isns.c
rename to usr.sbin/ctld/isns.cc
index 0b836324ff47..e4d3744b84dc 100644
--- a/usr.sbin/ctld/isns.c
+++ b/usr.sbin/ctld/isns.cc
@@ -48,14 +48,14 @@ isns_req_alloc(void)
{
struct isns_req *req;
- req = calloc(1, sizeof(struct isns_req));
+ req = reinterpret_cast<struct isns_req *>(calloc(1, sizeof(struct isns_req)));
if (req == NULL) {
log_err(1, "calloc");
return (NULL);
}
req->ir_buflen = sizeof(struct isns_hdr);
req->ir_usedlen = 0;
- req->ir_buf = calloc(1, req->ir_buflen);
+ req->ir_buf = reinterpret_cast<uint8_t *>(calloc(1, req->ir_buflen));
if (req->ir_buf == NULL) {
free(req);
log_err(1, "calloc");
@@ -101,7 +101,7 @@ isns_req_getspace(struct isns_req *req, uint32_t len)
log_err(1, "realloc");
return (1);
}
- req->ir_buf = newbuf;
+ req->ir_buf = reinterpret_cast<uint8_t *>(newbuf);
req->ir_buflen = newlen;
return (0);
}
diff --git a/usr.sbin/ctld/kernel.c b/usr.sbin/ctld/kernel.cc
similarity index 98%
rename from usr.sbin/ctld/kernel.c
rename to usr.sbin/ctld/kernel.cc
index 06ca99ce9d1f..9ddf22b9f4e0 100644
--- a/usr.sbin/ctld/kernel.c
+++ b/usr.sbin/ctld/kernel.cc
@@ -170,7 +170,7 @@ cctl_start_element(void *user_data, const char *name, const char **attr)
log_errx(1, "%s: improper lun element nesting",
__func__);
- cur_lun = calloc(1, sizeof(*cur_lun));
+ cur_lun = reinterpret_cast<struct cctl_lun *>(calloc(1, sizeof(*cur_lun)));
if (cur_lun == NULL)
log_err(1, "%s: cannot allocate %zd bytes", __func__,
sizeof(*cur_lun));
@@ -287,7 +287,7 @@ cctl_start_pelement(void *user_data, const char *name, const char **attr)
log_errx(1, "%s: improper port element nesting (%s)",
__func__, name);
- cur_port = calloc(1, sizeof(*cur_port));
+ cur_port = reinterpret_cast<struct cctl_port *>(calloc(1, sizeof(*cur_port)));
if (cur_port == NULL)
log_err(1, "%s: cannot allocate %zd bytes", __func__,
sizeof(*cur_port));
@@ -422,7 +422,7 @@ conf_new_from_kernel(struct kports *kports)
str = NULL;
len = 4096;
retry:
- str = realloc(str, len);
+ str = reinterpret_cast<char *>(realloc(str, len));
if (str == NULL)
log_err(1, "realloc");
@@ -471,7 +471,7 @@ retry:
str = NULL;
len = 4096;
retry_port:
- str = realloc(str, len);
+ str = reinterpret_cast<char *>(realloc(str, len));
if (str == NULL)
log_err(1, "realloc");
@@ -691,13 +691,13 @@ kernel_lun_add(struct lun *lun)
req.reqdata.create.device_type = lun->l_device_type;
if (lun->l_serial != NULL) {
- strncpy(req.reqdata.create.serial_num, lun->l_serial,
+ strncpy((char *)req.reqdata.create.serial_num, lun->l_serial,
sizeof(req.reqdata.create.serial_num));
req.reqdata.create.flags |= CTL_LUN_FLAG_SERIAL_NUM;
}
if (lun->l_device_id != NULL) {
- strncpy(req.reqdata.create.device_id, lun->l_device_id,
+ strncpy((char *)req.reqdata.create.device_id, lun->l_device_id,
sizeof(req.reqdata.create.device_id));
req.reqdata.create.flags |= CTL_LUN_FLAG_DEVID;
}
diff --git a/usr.sbin/ctld/login.c b/usr.sbin/ctld/login.cc
similarity index 99%
rename from usr.sbin/ctld/login.c
rename to usr.sbin/ctld/login.cc
index 8833779c825f..84d329964ada 100644
--- a/usr.sbin/ctld/login.c
+++ b/usr.sbin/ctld/login.cc
@@ -47,7 +47,7 @@
#define MAX_DATA_SEGMENT_LENGTH (128 * 1024)
static void login_send_error(struct pdu *request,
- char class, char detail);
+ char error_class, char detail);
static void
kernel_limits(const char *offload, int s, int *max_recv_dsl, int *max_send_dsl,
@@ -230,16 +230,16 @@ login_new_response(struct pdu *request)
}
static void
-login_send_error(struct pdu *request, char class, char detail)
+login_send_error(struct pdu *request, char error_class, char detail)
{
struct pdu *response;
struct iscsi_bhs_login_response *bhslr2;
log_debugx("sending Login Response PDU with failure class 0x%x/0x%x; "
- "see next line for reason", class, detail);
+ "see next line for reason", error_class, detail);
response = login_new_response(request);
bhslr2 = (struct iscsi_bhs_login_response *)response->pdu_bhs;
- bhslr2->bhslr_status_class = class;
+ bhslr2->bhslr_status_class = error_class;
bhslr2->bhslr_status_detail = detail;
pdu_send(response);
diff --git a/usr.sbin/ctld/uclparse.c b/usr.sbin/ctld/uclparse.cc
similarity index 100%
rename from usr.sbin/ctld/uclparse.c
rename to usr.sbin/ctld/uclparse.cc