Skip to content

Instantly share code, notes, and snippets.

@pcarranza
Created February 8, 2018 23:21
Show Gist options
  • Save pcarranza/df74e8aea88436298692828eb74501ba to your computer and use it in GitHub Desktop.
Save pcarranza/df74e8aea88436298692828eb74501ba to your computer and use it in GitHub Desktop.
Patch that makes iscscitarget-dkms compile correctly on hypriot rpi
--- iscsitarget-1.4.20.3+svn502/kernel/nthread.c 2014-05-06 20:59:55.000000000 +0000
+++ iscsitarget-1.4.20.3+svn502-working/kernel/nthread.c 2018-02-08 13:39:47.141949006 +0000
@@ -42,9 +42,14 @@
len = (len + 3) & -4; // XXX ???
conn->read_iov[0].iov_base = data;
conn->read_iov[0].iov_len = len;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
conn->read_msg.msg_iov = conn->read_iov;
conn->read_msg.msg_iovlen = 1;
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) */
conn->read_size = (len + 3) & -4;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+ iov_iter_init(&conn->read_msg.msg_iter, READ, conn->read_iov, 1, conn->read_size);
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
}
static void iscsi_conn_read_ahs(struct iscsi_conn *conn, struct iscsi_cmnd *cmnd)
@@ -83,14 +88,31 @@
static void forward_iov(struct msghdr *msg, int len)
{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+ struct iovec *iov;
+
+ while (msg->msg_iter.iov->iov_len <= len) {
+ len -= msg->msg_iter.iov->iov_len;
+ msg->msg_iter.iov++;
+ msg->msg_iter.nr_segs--;
+ }
+#else
while (msg->msg_iov->iov_len <= len) {
len -= msg->msg_iov->iov_len;
msg->msg_iov++;
msg->msg_iovlen--;
}
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+ /* XXX: discards const ... */
+ iov = msg->msg_iter.iov;
+ iov->iov_base = (char *) msg->msg_iter.iov->iov_base + len;
+ iov->iov_len -= len;
+#else
msg->msg_iov->iov_base = (char *) msg->msg_iov->iov_base + len;
msg->msg_iov->iov_len -= len;
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
}
static int do_recv(struct iscsi_conn *conn, int state)
@@ -98,6 +120,9 @@
mm_segment_t oldfs;
struct msghdr msg;
struct iovec iov[ISCSI_CONN_IOV_MAX];
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+ size_t iovlen = ISCSI_CONN_IOV_MAX;
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
int i, len, res;
if (!test_bit(CONN_ACTIVE, &conn->state)) {
@@ -110,12 +135,23 @@
goto out;
}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+ if (conn->read_msg.msg_iter.nr_segs < iovlen)
+ iovlen = conn->read_msg.msg_iter.nr_segs;
+
+ for (i = 0, len = 0; i < iovlen; i++) {
+ iov[i] = conn->read_msg.msg_iter.iov[i];
+ len += iov[i].iov_len;
+ }
+ iov_iter_init(&msg.msg_iter, READ, iov, iovlen, len);
+#else
msg.msg_iov = iov;
msg.msg_iovlen = min_t(size_t, conn->read_msg.msg_iovlen, ISCSI_CONN_IOV_MAX);
for (i = 0, len = 0; i < msg.msg_iovlen; i++) {
iov[i] = conn->read_msg.msg_iov[i];
len += iov[i].iov_len;
}
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
oldfs = get_fs();
set_fs(get_ds());
--- iscsitarget-1.4.20.3+svn502/kernel/iscsi.c 2014-05-06 20:59:55.000000000 +0000
+++ iscsitarget-1.4.20.3+svn502-working/kernel/iscsi.c 2018-02-08 13:39:47.141949006 +0000
@@ -489,8 +489,12 @@
}
conn->read_iov[i].iov_base = addr;
conn->read_iov[i].iov_len = size;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+ iov_iter_init(&conn->read_msg.msg_iter, READ, conn->read_iov, ++i, conn->read_size);
+#else
conn->read_msg.msg_iov = conn->read_iov;
conn->read_msg.msg_iovlen = ++i;
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
}
static void iscsi_cmnd_reject(struct iscsi_cmnd *req, int reason)
@@ -718,7 +722,9 @@
idx = offset >> PAGE_CACHE_SHIFT;
offset &= ~PAGE_CACHE_MASK;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
conn->read_msg.msg_iov = conn->read_iov;
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) */
conn->read_size = size = (size + 3) & -4;
conn->read_overflow = 0;
@@ -730,16 +736,25 @@
conn->read_iov[i].iov_base = addr + offset;
if (offset + size <= PAGE_CACHE_SIZE) {
conn->read_iov[i].iov_len = size;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+ iov_iter_init(&conn->read_msg.msg_iter, READ, conn->read_iov, ++i, conn->read_size);
+#else
conn->read_msg.msg_iovlen = ++i;
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
break;
}
conn->read_iov[i].iov_len = PAGE_CACHE_SIZE - offset;
size -= conn->read_iov[i].iov_len;
offset = 0;
if (++i >= ISCSI_CONN_IOV_MAX) {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
conn->read_msg.msg_iovlen = i;
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) */
conn->read_overflow = size;
conn->read_size -= size;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+ iov_iter_init(&conn->read_msg.msg_iter, READ, conn->read_iov, i, conn->read_size);
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
break;
}
@@ -918,7 +933,9 @@
if ((size = cmnd->pdu.datasize)) {
size = (size + 3) & -4;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
conn->read_msg.msg_iov = conn->read_iov;
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) */
if (cmnd->pdu.bhs.itt != cpu_to_be32(ISCSI_RESERVED_TAG)) {
struct tio *tio;
int pg_cnt = get_pgcnt(size);
@@ -946,7 +963,11 @@
}
assert(!size);
conn->read_overflow = size;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+ iov_iter_init(&conn->read_msg.msg_iter, READ, conn->read_iov, i, conn->read_size);
+#else
conn->read_msg.msg_iovlen = i;
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
}
out:
@@ -986,7 +1007,11 @@
set_cmnd_lunit(req);
switch (req_hdr->scb[0]) {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+ case SERVICE_ACTION_IN_16:
+#else
case SERVICE_ACTION_IN:
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
if ((req_hdr->scb[1] & 0x1f) != 0x10)
goto error;
case INQUIRY:
--- iscsitarget-1.4.20.3+svn502/kernel/volume.c 2014-05-06 20:59:55.000000000 +0000
+++ iscsitarget-1.4.20.3+svn502-working/kernel/volume.c 2018-02-08 13:39:47.141949006 +0000
@@ -398,7 +398,11 @@
case READ_CAPACITY:
/* allowed commands when reserved */
break;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+ case SERVICE_ACTION_IN_16:
+#else
case SERVICE_ACTION_IN:
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
if ((scb[1] & 0x1F) == 0x10)
break;
/* fall through */
@@ -465,7 +469,11 @@
if (excl_access_ro && !registered)
err = -EBUSY;
break;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+ case SERVICE_ACTION_IN_16:
+#else
case SERVICE_ACTION_IN:
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
if ((scb[1] & 0x1F) == 0x10)
break;
/* fall through */
--- iscsitarget-1.4.20.3+svn502/kernel/conn.c 2014-05-06 20:59:55.000000000 +0000
+++ iscsitarget-1.4.20.3+svn502-working/kernel/conn.c 2018-02-08 13:39:47.131949111 +0000
@@ -127,7 +127,11 @@
dprintk(D_GENERIC, "%llu\n", (unsigned long long) session->sid);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+ conn->sock = SOCKET_I(file_inode(conn->file));
+#else
conn->sock = SOCKET_I(conn->file->f_dentry->d_inode);
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
conn->sock->sk->sk_user_data = conn;
write_lock_bh(&conn->sock->sk->sk_callback_lock);
--- iscsitarget-1.4.20.3+svn502/kernel/target_disk.c 2014-05-06 20:59:55.000000000 +0000
+++ iscsitarget-1.4.20.3+svn502-working/kernel/target_disk.c 2018-02-08 13:39:47.141949006 +0000
@@ -606,7 +606,11 @@
case REQUEST_SENSE:
send_data_rsp(cmnd, build_request_sense_response);
break;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+ case SERVICE_ACTION_IN_16:
+#else
case SERVICE_ACTION_IN:
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
send_data_rsp(cmnd, build_service_action_in_response);
break;
case READ_6:
--- iscsitarget-1.4.20.3+svn502/kernel/file-io.c 2014-05-06 20:59:55.000000000 +0000
+++ iscsitarget-1.4.20.3+svn502-working/kernel/file-io.c 2018-02-08 13:39:47.131949111 +0000
@@ -69,7 +69,11 @@
static int fileio_sync(struct iet_volume *lu, struct tio *tio)
{
struct fileio_data *p = lu->private;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+ struct inode *inode = file_inode(p->filp);
+#else
struct inode *inode = p->filp->f_dentry->d_inode;
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
struct address_space *mapping = inode->i_mapping;
loff_t ppos, count;
int res;
@@ -213,7 +217,11 @@
eprintk("%d\n", err);
goto out;
}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+ inode = file_inode(p->filp);
+#else
inode = p->filp->f_dentry->d_inode;
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
if (S_ISREG(inode->i_mode))
;
--- iscsitarget-1.4.20.3+svn502/kernel/block-io.c 2014-05-06 20:59:55.000000000 +0000
+++ iscsitarget-1.4.20.3+svn502-working/kernel/block-io.c 2018-02-08 13:43:05.039942052 +0000
@@ -33,7 +33,7 @@
{
struct tio_work *tio_work = bio->bi_private;
- error = test_bit(BIO_UPTODATE, &bio->bi_flags) ? error : -EIO;
+ error = bio->bi_error ? -EIO : error;
if (error)
atomic_set(&tio_work->error, error);
@@ -61,15 +61,10 @@
u32 size = tio->size;
u32 tio_index = 0;
- int max_pages = 1;
int err = 0;
loff_t ppos = tio->offset;
- /* Calculate max_pages for bio_alloc (memory saver) */
- if (bdev_q)
- max_pages = bio_get_nr_vecs(bio_data->bdev);
-
tio_work = kzalloc(sizeof (*tio_work), GFP_KERNEL);
if (!tio_work)
return -ENOMEM;
@@ -80,7 +75,7 @@
/* Main processing loop, allocate and fill all bios */
while (size && tio_index < tio->pg_cnt) {
- bio = bio_alloc(GFP_KERNEL, min(max_pages, BIO_MAX_PAGES));
+ bio = bio_alloc(GFP_KERNEL, BIO_MAX_PAGES);
if (!bio) {
err = -ENOMEM;
goto out;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment