Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scst: Port to Linux kernel v6.5 #178

Merged
merged 8 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/checkpatch_pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
SPDX_LICENSE_TAG
LINUX_VERSION_CODE
CONSTANT_COMPARISON
NEW_TYPEDEFS
SPACING
)
ignore_str=${ignore[*]}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/checkpatch_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
SPDX_LICENSE_TAG
LINUX_VERSION_CODE
CONSTANT_COMPARISON
NEW_TYPEDEFS
SPACING
)
ignore_str=${ignore[*]}
Expand Down
9 changes: 4 additions & 5 deletions iscsi-scst/kernel/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,6 @@ int conn_activate(struct iscsi_conn *conn)

static int conn_setup_sock(struct iscsi_conn *conn)
{
int res = 0;
int opt = 1;
mm_segment_t oldfs;
struct iscsi_session *session = conn->session;
Expand All @@ -750,12 +749,13 @@ static int conn_setup_sock(struct iscsi_conn *conn)

conn->sock = SOCKET_I(file_inode(conn->file));

#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 5, 0)
if (conn->sock->ops->sendpage == NULL) {
PRINT_ERROR("Socket for sid %llx doesn't support sendpage()",
(unsigned long long)session->sid);
res = -EINVAL;
goto out;
return -EINVAL;
}
#endif

#if 0
conn->sock->sk->sk_allocation = GFP_NOIO;
Expand All @@ -768,8 +768,7 @@ static int conn_setup_sock(struct iscsi_conn *conn)
KERNEL_SOCKPTR(&opt), sizeof(opt));
set_fs(oldfs);

out:
return res;
return 0;
}

void iscsi_tcp_conn_free(struct iscsi_conn *conn)
Expand Down
196 changes: 95 additions & 101 deletions iscsi-scst/kernel/nthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1095,69 +1095,79 @@ void req_add_to_write_timeout_list(struct iscsi_cmnd *req)

static int write_data(struct iscsi_conn *conn)
{
struct file *file;
struct kvec *iop;
struct socket *sock;
ssize_t (*sock_sendpage)(struct socket *, struct page *, int, size_t,
int);
ssize_t (*sendpage)(struct socket *, struct page *, int, size_t, int);
struct iscsi_cmnd *write_cmnd = conn->write_cmnd;
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 5, 0)
ssize_t (*sock_sendpage)(struct socket *sock, struct page *page,
int offset, size_t size, int flags);
#else
struct msghdr msg = {};
struct bio_vec bvec;
#endif
struct iscsi_cmnd *write_cmnd, *parent_req;
struct iscsi_cmnd *ref_cmd;
struct page *page;
struct scatterlist *sg;
int saved_size, size, sendsize;
int length, offset, idx;
int flags, res, count, sg_size;
size_t saved_size, size, sg_size;
size_t sendsize, length;
int offset, idx, flags, res = 0;
bool ref_cmd_to_parent;

TRACE_ENTRY();

write_cmnd = conn->write_cmnd;
parent_req = write_cmnd->parent_req;

iscsi_extracheck_is_wr_thread(conn);

if (!write_cmnd->own_sg) {
ref_cmd = write_cmnd->parent_req;
ref_cmd = parent_req;
ref_cmd_to_parent = true;
} else {
ref_cmd = write_cmnd;
ref_cmd_to_parent = false;
}

req_add_to_write_timeout_list(write_cmnd->parent_req);
req_add_to_write_timeout_list(parent_req);

file = conn->file;
size = conn->write_size;
saved_size = size;
iop = conn->write_iop;
count = conn->write_iop_used;
saved_size = size = conn->write_size;

if (iop) {
while (1) {
loff_t off = 0;
int rest;
if (conn->write_iop) {
struct file *file = conn->file;
struct kvec *iop = conn->write_iop;
int count = conn->write_iop_used;
loff_t off;

sBUG_ON(count > ARRAY_SIZE(conn->write_iov));

while (true) {
off = 0;

sBUG_ON(count > ARRAY_SIZE(conn->write_iov));
retry:
res = scst_writev(file, iop, count, &off);
TRACE_WRITE("sid %#Lx, cid %u, res %d, iov_len %zd",
(unsigned long long)conn->session->sid,
conn->cid, res, iop->iov_len);

if (unlikely(res <= 0)) {
if (res == -EINTR)
continue;

if (res == -EAGAIN) {
conn->write_iop = iop;
conn->write_iop_used = count;
goto out_iov;
} else if (res == -EINTR)
goto retry;
}

goto out_err;
}

rest = res;
size -= res;
while ((typeof(rest))iop->iov_len <= rest && rest) {
rest -= iop->iov_len;

while ((typeof(res))iop->iov_len <= res && res) {
res -= iop->iov_len;
iop++;
count--;
}

if (count == 0) {
conn->write_iop = NULL;
conn->write_iop_used = 0;
Expand All @@ -1167,8 +1177,8 @@ static int write_data(struct iscsi_conn *conn)
}
sBUG_ON(iop >
conn->write_iov + ARRAY_SIZE(conn->write_iov));
iop->iov_base += rest;
iop->iov_len -= rest;
iop->iov_base += res;
iop->iov_len -= res;
}
}

Expand All @@ -1180,15 +1190,19 @@ static int write_data(struct iscsi_conn *conn)
}

sock = conn->sock;
flags = MSG_DONTWAIT;

if (write_cmnd->parent_req->scst_cmd &&
write_cmnd->parent_req->scst_state != ISCSI_CMD_STATE_AEN &&
scst_cmd_get_dh_data_buff_alloced(write_cmnd->parent_req->scst_cmd))
sock_sendpage = sock_no_sendpage;
else
if (sg != write_cmnd->rsp_sg &&
(!parent_req->scst_cmd || parent_req->scst_state == ISCSI_CMD_STATE_AEN ||
!scst_cmd_get_dh_data_buff_alloced(parent_req->scst_cmd)))
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
flags |= MSG_SPLICE_PAGES;
#else
sock_sendpage = sock->ops->sendpage;
else
sock_sendpage = sock_no_sendpage;
#endif

flags = MSG_DONTWAIT;
sg_size = size;

if (sg != write_cmnd->rsp_sg) {
Expand All @@ -1201,8 +1215,8 @@ static int write_data(struct iscsi_conn *conn)
offset = conn->write_offset + sg[0].offset;
idx = offset >> PAGE_SHIFT;
offset &= ~PAGE_MASK;
length = min(size, (int)PAGE_SIZE - offset);
TRACE_WRITE("write_offset %d, sg_size %d, idx %d, offset %d, length %d",
length = min_t(size_t, size, PAGE_SIZE - offset);
TRACE_WRITE("write_offset %d, sg_size %lu, idx %d, offset %d, length %lu",
conn->write_offset, sg_size, idx, offset, length);
} else {
/*
Expand All @@ -1217,93 +1231,73 @@ static int write_data(struct iscsi_conn *conn)
}
length = sg[idx].length - offset;
offset += sg[idx].offset;
sock_sendpage = sock_no_sendpage;
TRACE_WRITE("rsp_sg: write_offset %d, sg_size %d, idx %d, "
"offset %d, length %d", conn->write_offset, sg_size,
idx, offset, length);
TRACE_WRITE("rsp_sg: write_offset %d, sg_size %lu, idx %d, offset %d, length %lu",
conn->write_offset, sg_size, idx, offset, length);
}
page = sg_page(&sg[idx]);

while (1) {
sendpage = sock_sendpage;

sendsize = min(size, length);
if (size <= sendsize) {
retry2:
res = sendpage(sock, page, offset, size, flags);
TRACE_WRITE("Final %s sid %#Lx, cid %u, res %d (page index %lu, offset %u, size %u, cmd %p, page %p)",
(sendpage != sock_no_sendpage) ?
"sendpage" : "sock_no_sendpage",
(unsigned long long)conn->session->sid,
conn->cid, res, page->index,
offset, size, write_cmnd, page);
while (true) {
sendsize = min_t(size_t, size, length);

if (sendsize == size)
flags &= ~MSG_MORE;
else
flags |= MSG_MORE;

while (sendsize) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 5, 0)
res = sock_sendpage(sock, page, offset, sendsize, flags);
#else
memset(&msg, 0, sizeof(struct msghdr));
msg.msg_flags = flags;

bvec_set_page(&bvec, page, sendsize, offset);
iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, sendsize);
res = sock_sendmsg(sock, &msg);
#endif
TRACE_WRITE(
"sid %#Lx cid %u: res %d (page[%p] index %lu, offset %u, sendsize %lu, size %lu, cmd %p)",
(unsigned long long)conn->session->sid, conn->cid,
res, page, page->index, offset, sendsize, size,
write_cmnd);

if (unlikely(res <= 0)) {
if (res == -EINTR)
goto retry2;
else
goto out_res;
}
continue;

if (res == -EAGAIN) {
conn->write_offset += sg_size - size;
goto out_iov;
}

if (res == size) {
conn->write_size = 0;
res = saved_size;
goto out;
goto out_err;
}

offset += res;
sendsize -= res;
size -= res;
goto retry2;
}

retry1:
res = sendpage(sock, page, offset, sendsize, flags | MSG_MORE);
TRACE_WRITE("%s sid %#Lx, cid %u, res %d (page index %lu, offset %u, sendsize %u, size %u, cmd %p, page %p)",
(sendpage != sock_no_sendpage) ? "sendpage" :
"sock_no_sendpage",
(unsigned long long)conn->session->sid, conn->cid,
res, page->index, offset, sendsize, size,
write_cmnd, page);
if (unlikely(res <= 0)) {
if (res == -EINTR)
goto retry1;
else
goto out_res;
}

size -= res;
if (size == 0)
goto out_iov;

if (res == sendsize) {
idx++;
EXTRACHECKS_BUG_ON(idx >= ref_cmd->sg_cnt);
page = sg_page(&sg[idx]);
length = sg[idx].length;
offset = sg[idx].offset;
} else {
offset += res;
sendsize -= res;
goto retry1;
}
idx++;
EXTRACHECKS_BUG_ON(idx >= ref_cmd->sg_cnt);
page = sg_page(&sg[idx]);
length = sg[idx].length;
offset = sg[idx].offset;
}

out_off:
conn->write_offset += sg_size - size;

out_iov:
conn->write_size = size;
if ((saved_size == size) && res == -EAGAIN)
goto out;

res = saved_size - size;
if (res != -EAGAIN || saved_size != size)
res = saved_size - size;

out:
TRACE_EXIT_RES(res);
return res;

out_res:
if (res == -EAGAIN)
goto out_off;
/* else go through */

out_err:
#ifndef CONFIG_SCST_DEBUG
if (!conn->closing) {
Expand Down
Loading