From 129cac067c4e9bdca5301d361d21e87500540195 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Sat, 23 Dec 2017 04:30:51 +0000 Subject: [PATCH] Merged revisions 7253-7266,7268-7271 via svnmerge from svn+ssh://svn.code.sf.net/p/scst/svn/trunk ........ r7253 | vlnb | 2017-10-11 20:22:02 -0700 (Wed, 11 Oct 2017) | 3 lines scst: add example of active non-optimized setup ........ r7254 | bvassche | 2017-10-12 07:56:44 -0700 (Thu, 12 Oct 2017) | 1 line qla2x00t: Fix scst_debug.h include path for the in-tree build ........ r7255 | bvassche | 2017-10-12 08:03:13 -0700 (Thu, 12 Oct 2017) | 1 line scripts/specialize-patch: Fix #elif handling ........ r7256 | vlnb | 2017-10-13 19:18:56 -0700 (Fri, 13 Oct 2017) | 3 lines Unpdate for kernels 4.12+ ........ r7257 | bvassche | 2017-11-11 21:01:16 -0800 (Sat, 11 Nov 2017) | 1 line iscsi-scst/usr/Makefile: Pass -Wno-format-truncation if supported ........ r7258 | bvassche | 2017-11-12 21:48:16 -0800 (Sun, 12 Nov 2017) | 4 lines ib_srpt: Kernel 4.14 build fix Signed-off-by: Peter Vyazovik ........ r7259 | bvassche | 2017-11-12 21:49:08 -0800 (Sun, 12 Nov 2017) | 1 line scst: Introduce the kernel v4.14 bio_set_dev() macro ........ r7260 | bvassche | 2017-11-12 21:50:44 -0800 (Sun, 12 Nov 2017) | 5 lines scst, iscsi-scst: Introduce scst_read(), scst_write(), scst_readv() and scst_writev() This makes it easier to add support for new kernel versions, e.g. kernel version v4.14. ........ r7261 | bvassche | 2017-11-13 08:00:09 -0800 (Mon, 13 Nov 2017) | 1 line scst/src/scst_lib.c: Fix recently introduced checkpatch complaints ........ r7262 | bvassche | 2017-11-13 08:18:00 -0800 (Mon, 13 Nov 2017) | 4 lines scst: Fix build for kernels 3.15 and older blk_rq_set_block_pc() was introduced in kernel 3.16. ........ r7263 | bvassche | 2017-11-13 08:24:16 -0800 (Mon, 13 Nov 2017) | 1 line nightly build: Update kernel versions ........ r7264 | bvassche | 2017-11-13 08:47:10 -0800 (Mon, 13 Nov 2017) | 1 line scst: Address two checkpatch warnings ........ r7265 | bvassche | 2017-11-13 08:47:43 -0800 (Mon, 13 Nov 2017) | 1 line scst/src/scst_targ: Use READ_ONCE() instead of ACCESS_ONCE() ........ r7266 | bvassche | 2017-11-13 08:49:39 -0800 (Mon, 13 Nov 2017) | 1 line fcst/fcst.h: Add identifier names ........ r7268 | bvassche | 2017-11-14 08:37:24 -0800 (Tue, 14 Nov 2017) | 1 line scst: Fix kernel <= 2.6.30 build ........ r7269 | bvassche | 2017-11-14 18:45:57 -0800 (Tue, 14 Nov 2017) | 1 line nightly/bin/nightly: Clone the source code tree quietly ........ r7270 | bvassche | 2017-11-14 18:47:06 -0800 (Tue, 14 Nov 2017) | 1 line nightly build: Update kernel versions ........ r7271 | bvassche | 2017-11-14 18:48:03 -0800 (Tue, 14 Nov 2017) | 1 line nightly/conf/nightly.sendmail: Use mail if mutt is not available ........ git-svn-id: http://svn.code.sf.net/p/scst/svn/branches/3.3.x@7288 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- fcst/fcst.h | 38 +++++---- iscsi-scst/kernel/iscsi.h | 56 +++++++------ iscsi-scst/kernel/nthread.c | 4 +- iscsi-scst/usr/Makefile | 7 +- nightly/bin/nightly | 2 +- nightly/conf/nightly.conf | 13 +-- nightly/conf/nightly.sendmail | 14 ++-- qla2x00t/qla2x00-target/qla2x00t.h | 4 + qla2x00t/qla_bsg.c | 15 +++- qla2x00t/qla_isr.c | 19 +++++ scripts/specialize-patch | 3 +- scst/README | 122 +++++++++++++++++++++++++++- scst/README_in-tree | 122 +++++++++++++++++++++++++++- scst/include/backport.h | 57 ++++++++----- scst/include/scst.h | 14 +++- scst/src/dev_handlers/scst_vdisk.c | 23 +++--- scst/src/scst_dlm.c | 2 +- scst/src/scst_lib.c | 124 ++++++++++++++++++++++++----- scst/src/scst_pres.c | 24 +++--- scst/src/scst_targ.c | 4 +- srpt/src/ib_srpt.c | 7 +- 21 files changed, 521 insertions(+), 153 deletions(-) diff --git a/fcst/fcst.h b/fcst/fcst.h index bc4e3a838..d1846c6d8 100644 --- a/fcst/fcst.h +++ b/fcst/fcst.h @@ -146,36 +146,34 @@ extern struct fc4_prov ft_prov; /* * SCST interface. */ -int ft_send_response(struct scst_cmd *); -int ft_send_xfer_rdy(struct scst_cmd *); -void ft_cmd_timeout(struct scst_cmd *); -void ft_cmd_free(struct scst_cmd *); -void ft_cmd_tm_done(struct scst_mgmt_cmd *); -int ft_tgt_release(struct scst_tgt *); -int ft_tgt_enable(struct scst_tgt *, bool); -bool ft_tgt_enabled(struct scst_tgt *); -int ft_report_aen(struct scst_aen *); -int ft_get_transport_id(struct scst_tgt *, struct scst_session *, uint8_t **); +int ft_send_response(struct scst_cmd *cmd); +int ft_send_xfer_rdy(struct scst_cmd *cmd); +void ft_cmd_timeout(struct scst_cmd *cmd); +void ft_cmd_free(struct scst_cmd *cmd); +void ft_cmd_tm_done(struct scst_mgmt_cmd *mcmd); +int ft_tgt_release(struct scst_tgt *tgt); +int ft_tgt_enable(struct scst_tgt *tgt, bool enable); +bool ft_tgt_enabled(struct scst_tgt *tgt); +int ft_report_aen(struct scst_aen *aen); +int ft_get_transport_id(struct scst_tgt *tgt, struct scst_session *scst_sess, + uint8_t **result); /* * Session interface. */ -int ft_lport_notify(struct notifier_block *, unsigned long, void *); -void ft_lport_add(struct fc_lport *, void *); -void ft_lport_del(struct fc_lport *, void *); +int ft_lport_notify(struct notifier_block *nb, unsigned long event, void *arg); +void ft_lport_add(struct fc_lport *lport, void *arg); +void ft_lport_del(struct fc_lport *lport, void *arg); /* * other internal functions. */ -int ft_thread(void *); bool ft_test_and_set_cmd_state(struct ft_cmd *fcmd, enum ft_cmd_state old, enum ft_cmd_state new); -void ft_recv_req(struct ft_sess *, struct fc_frame *); -void ft_recv_write_data(struct scst_cmd *, struct fc_frame *); -int ft_send_read_data(struct scst_cmd *); -struct ft_tpg *ft_lport_find_tpg(struct fc_lport *); -struct ft_node_acl *ft_acl_get(struct ft_tpg *, struct fc_rport_priv *); -void ft_cmd_dump(struct scst_cmd *, const char *); +void ft_recv_req(struct ft_sess *sess, struct fc_frame *fp); +void ft_recv_write_data(struct scst_cmd *cmd, struct fc_frame *fp); +int ft_send_read_data(struct scst_cmd *cmd); +void ft_cmd_dump(struct scst_cmd *cmd, const char *caller); /* #define FCST_INJECT_SEND_ERRORS 2 */ diff --git a/iscsi-scst/kernel/iscsi.h b/iscsi-scst/kernel/iscsi.h index deaac7fb7..6c7f0a926 100644 --- a/iscsi-scst/kernel/iscsi.h +++ b/iscsi-scst/kernel/iscsi.h @@ -540,15 +540,15 @@ extern struct kmem_cache *iscsi_conn_cache; extern struct kmem_cache *iscsi_sess_cache; /* iscsi.c */ -extern struct iscsi_cmnd *cmnd_alloc(struct iscsi_conn *, +extern struct iscsi_cmnd *cmnd_alloc(struct iscsi_conn *conn, struct iscsi_cmnd *parent); -extern int cmnd_rx_start(struct iscsi_cmnd *); +extern int cmnd_rx_start(struct iscsi_cmnd *cmnd); extern int cmnd_rx_continue(struct iscsi_cmnd *req); -extern void cmnd_rx_end(struct iscsi_cmnd *); -extern void cmnd_tx_start(struct iscsi_cmnd *); -extern void cmnd_tx_end(struct iscsi_cmnd *); +extern void cmnd_rx_end(struct iscsi_cmnd *cmnd); +extern void cmnd_tx_start(struct iscsi_cmnd *cmnd); +extern void cmnd_tx_end(struct iscsi_cmnd *cmnd); extern void req_cmnd_release_force(struct iscsi_cmnd *req); -extern void rsp_cmnd_release(struct iscsi_cmnd *); +extern void rsp_cmnd_release(struct iscsi_cmnd *cmnd); extern void iscsi_drop_delayed_tm_rsp(struct iscsi_cmnd *tm_rsp); extern void cmnd_done(struct iscsi_cmnd *cmnd); extern void conn_abort(struct iscsi_conn *conn); @@ -567,19 +567,21 @@ extern void iscsi_threads_pool_put(struct iscsi_thread_pool *p); #ifndef CONFIG_SCST_PROC extern struct kobj_type iscsi_conn_ktype; #endif -extern struct iscsi_conn *conn_lookup(struct iscsi_session *, u16); -extern void conn_reinst_finished(struct iscsi_conn *); -extern int __add_conn(struct iscsi_session *, struct iscsi_kern_conn_info *); -extern int __del_conn(struct iscsi_session *, struct iscsi_kern_conn_info *); -extern void conn_free(struct iscsi_conn *); +extern struct iscsi_conn *conn_lookup(struct iscsi_session *session, u16 cid); +extern void conn_reinst_finished(struct iscsi_conn *conn); +extern int __add_conn(struct iscsi_session *session, + struct iscsi_kern_conn_info *info); +extern int __del_conn(struct iscsi_session *session, + struct iscsi_kern_conn_info *info); +extern void conn_free(struct iscsi_conn *conn); extern void iscsi_make_conn_rd_active(struct iscsi_conn *conn); #define ISCSI_CONN_ACTIVE_CLOSE 1 #define ISCSI_CONN_DELETING 2 -extern void __mark_conn_closed(struct iscsi_conn *, int); -extern void mark_conn_closed(struct iscsi_conn *); -extern void iscsi_make_conn_wr_active(struct iscsi_conn *); +extern void __mark_conn_closed(struct iscsi_conn *conn, int flags); +extern void mark_conn_closed(struct iscsi_conn *conn); +extern void iscsi_make_conn_wr_active(struct iscsi_conn *conn); #ifdef CONFIG_SCST_PROC -extern void conn_info_show(struct seq_file *, struct iscsi_session *); +extern void conn_info_show(struct seq_file *seq, struct iscsi_session *session); #endif extern void iscsi_check_tm_data_wait_timeouts(struct iscsi_conn *conn, bool force); @@ -607,8 +609,8 @@ extern ssize_t iscsi_sysfs_send_event(uint32_t tid, enum iscsi_kern_event_code code, const char *param1, const char *param2, void **data); #endif -extern struct iscsi_target *target_lookup_by_id(u32); -extern int __add_target(struct iscsi_kern_target_info *); +extern struct iscsi_target *target_lookup_by_id(u32 id); +extern int __add_target(struct iscsi_kern_target_info *info); extern int __del_target(u32 id); extern ssize_t iscsi_sysfs_add_target(const char *target_name, char *params); extern ssize_t iscsi_sysfs_del_target(const char *target_name); @@ -637,23 +639,25 @@ extern const struct attribute *iscsi_sess_attrs[]; extern const struct attribute *iscsi_acg_attrs[]; #endif extern const struct file_operations session_seq_fops; -extern struct iscsi_session *session_lookup(struct iscsi_target *, u64); -extern void sess_reinst_finished(struct iscsi_session *); -extern int __add_session(struct iscsi_target *, - struct iscsi_kern_session_info *); -extern int __del_session(struct iscsi_target *, u64); +extern struct iscsi_session *session_lookup(struct iscsi_target *target, + u64 sid); +extern void sess_reinst_finished(struct iscsi_session *session); +extern int __add_session(struct iscsi_target *target, + struct iscsi_kern_session_info *info); +extern int __del_session(struct iscsi_target *target, u64 sid); extern int session_free(struct iscsi_session *session, bool del); extern void iscsi_sess_force_close(struct iscsi_session *sess); /* params.c */ extern const char *iscsi_get_digest_name(int val, char *res); extern const char *iscsi_get_bool_value(int val); -extern int iscsi_params_set(struct iscsi_target *, - struct iscsi_kern_params_info *, int); +extern int iscsi_params_set(struct iscsi_target *target, + struct iscsi_kern_params_info *info, int set); /* event.c */ -extern int event_send(u32, u64, u32, u32, enum iscsi_kern_event_code, - const char *param1, const char *param2); +extern int event_send(u32 tid, u64 sid, u32 cid, u32 cookie, + enum iscsi_kern_event_code code, + const char *param1, const char *param2); extern int event_init(void); extern void event_exit(void); diff --git a/iscsi-scst/kernel/nthread.c b/iscsi-scst/kernel/nthread.c index 24b481c6d..c8322d104 100644 --- a/iscsi-scst/kernel/nthread.c +++ b/iscsi-scst/kernel/nthread.c @@ -1372,9 +1372,7 @@ static int write_data(struct iscsi_conn *conn) retry: oldfs = get_fs(); set_fs(KERNEL_DS); - res = vfs_writev(file, - (struct iovec __force __user *)iop, - count, &off, 0); + res = scst_writev(file, iop, count, &off); set_fs(oldfs); TRACE_WRITE("sid %#Lx, cid %u, res %d, iov_len %zd", (unsigned long long int)conn->session->sid, diff --git a/iscsi-scst/usr/Makefile b/iscsi-scst/usr/Makefile index 20752622c..7a766763d 100644 --- a/iscsi-scst/usr/Makefile +++ b/iscsi-scst/usr/Makefile @@ -18,6 +18,9 @@ ifndef PREFIX PREFIX=/usr/local endif +cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \ + > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) + SRCS_D = iscsid.c iscsi_scstd.c conn.c session.c target.c message.c ctldev.c \ log.c chap.c event.c param.c config.c isns.c md5.c sha1.c \ misc.c @@ -28,7 +31,9 @@ OBJS_ADM = $(SRCS_ADM:.c=.o) CFLAGS += -O2 -Wall -Wextra -Wstrict-prototypes -Wno-sign-compare \ -Wimplicit-function-declaration -Wno-unused-parameter \ - -Wno-missing-field-initializers -g -I../include -I$(SCST_INC_DIR) + -Wno-missing-field-initializers \ + $(call cc-option,-Wno-format-truncation) \ + -g -I../include -I$(SCST_INC_DIR) CFLAGS += -D_GNU_SOURCE # required for glibc >= 2.8 CFLAGS += $(LOCAL_CFLAGS) diff --git a/nightly/bin/nightly b/nightly/bin/nightly index 927f61e1a..9173eeac5 100755 --- a/nightly/bin/nightly +++ b/nightly/bin/nightly @@ -155,7 +155,7 @@ for logfile in old new ; do svn co -q -r {${date}} ${scst_repo} ${ABT_TMPDIR}/scst; \ else \ ( rmdir ${ABT_TMPDIR}/scst && \ - git clone ${scst_repo} ${ABT_TMPDIR}/scst && \ + git clone -q ${scst_repo} ${ABT_TMPDIR}/scst && \ cd ${ABT_TMPDIR}/scst && git reset --hard ${rev} ); \ fi" && runcmd ${logfile} \ diff --git a/nightly/conf/nightly.conf b/nightly/conf/nightly.conf index dd9629e0f..e75af2842 100644 --- a/nightly/conf/nightly.conf +++ b/nightly/conf/nightly.conf @@ -3,24 +3,25 @@ ABT_DETAILS="x86_64" ABT_JOBS=5 ABT_KERNELS=" \ -4.13.4 \ +4.14 \ +4.13.12-nc \ 4.12.14-nc \ 4.11.12-nc \ 4.10.17-nc \ -4.9.45-nc \ +4.9.61-nc \ 4.8.17-nc \ 4.7.10-nc \ 4.6.7-nc \ 4.5.7-nc \ -4.4.34-nc \ +4.4.65-nc \ 4.3.6-nc \ 4.2.8-nc \ -4.1.35-nc \ +4.1.38-nc \ 4.0.9-nc \ 3.19.8-nc \ -3.18.44-nc \ +3.18.51-nc \ 3.17.8-nc \ -3.16.39-nc \ +3.16.41-nc \ 3.15.10-nc \ 3.14.79-nc \ 3.13.11-nc \ diff --git a/nightly/conf/nightly.sendmail b/nightly/conf/nightly.sendmail index d28790ff3..7960ceb77 100755 --- a/nightly/conf/nightly.sendmail +++ b/nightly/conf/nightly.sendmail @@ -19,10 +19,14 @@ do esac done -if [ $# -ge 3 ]; then - gzip -9 <"$3" >"$3.gz" - mutt -s "$1" -a "$3.gz" ${recipients} < "$2" - rm -f "$3.gz" +if type mutt >/dev/null 2>&1; then + if [ $# -ge 3 ]; then + gzip -9 <"$3" >"$3.gz" + mutt -s "$1" -a "$3.gz" ${recipients} < "$2" + rm -f "$3.gz" + else + mutt -s "$1" ${recipients} < "$2" + fi else - mutt -s "$1" ${recipients} < "$2" + mail -s "$1" ${recipients} < "$2" fi diff --git a/qla2x00t/qla2x00-target/qla2x00t.h b/qla2x00t/qla2x00-target/qla2x00t.h index 313aab255..2886cc4d6 100644 --- a/qla2x00t/qla2x00-target/qla2x00t.h +++ b/qla2x00t/qla2x00-target/qla2x00t.h @@ -26,7 +26,11 @@ #include #include +#ifdef INSIDE_KERNEL_TREE +#include +#else #include +#endif /* Version numbers, the same as for the kernel */ #define Q2T_VERSION(a, b, c, d) (((a) << 030) + ((b) << 020) + (c) << 010 + (d)) diff --git a/qla2x00t/qla_bsg.c b/qla2x00t/qla_bsg.c index 587374b1b..5d90c8b63 100644 --- a/qla2x00t/qla_bsg.c +++ b/qla2x00t/qla_bsg.c @@ -2196,7 +2196,11 @@ qla24xx_bsg_timeout(struct bsg_job *bsg_job) ql_log(ql_log_warn, vha, 0x7089, "mbx abort_command " "failed.\n"); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) + scsi_req(bsg_job->req)->result = +#else bsg_job->req->errors = +#endif #ifndef NEW_LIBFC_API bsg_job->reply->result = -EIO; #else @@ -2206,7 +2210,11 @@ qla24xx_bsg_timeout(struct bsg_job *bsg_job) ql_dbg(ql_dbg_user, vha, 0x708a, "mbx abort_command " "success.\n"); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) + scsi_req(bsg_job->req)->result = +#else bsg_job->req->errors = +#endif #ifndef NEW_LIBFC_API bsg_job->reply->result = 0; #else @@ -2224,7 +2232,12 @@ qla24xx_bsg_timeout(struct bsg_job *bsg_job) #ifndef NEW_LIBFC_API bsg_job->req->errors = bsg_job->reply->result = -ENXIO; #else - bsg_job->req->errors = bsg_reply->result = -ENXIO; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) + scsi_req(bsg_job->req)->result = +#else + bsg_job->req->errors = +#endif + bsg_reply->result = -ENXIO; #endif return 0; diff --git a/qla2x00t/qla_isr.c b/qla2x00t/qla_isr.c index 880647c61..32be7c717 100644 --- a/qla2x00t/qla_isr.c +++ b/qla2x00t/qla_isr.c @@ -2705,6 +2705,7 @@ qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp) for (i = 0; i < ha->msix_count; i++) entries[i].entry = i; +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) ret = pci_enable_msix(ha->pdev, entries, ha->msix_count); if (ret) { if (ret < MIN_MSIX_COUNT) @@ -2726,6 +2727,24 @@ msix_failed: } ha->max_rsp_queues = ha->msix_count - 1; } +#else + ret = pci_enable_msix_range(ha->pdev, + entries, MIN_MSIX_COUNT, ha->msix_count); + if (ret < 0) { + ql_log(ql_log_fatal, vha, 0x00c7, + "MSI-X: Failed to enable support, " + "giving up -- %d/%d.\n", + ha->msix_count, ret); + goto msix_out; + } else if (ret < ha->msix_count) { + ql_log(ql_log_warn, vha, 0x00c6, + "MSI-X: Failed to enable support " + "with %d vectors, using %d vectors.\n", + ha->msix_count, ret); + ha->msix_count = ret; + ha->max_rsp_queues = ha->msix_count - 1; + } +#endif ha->msix_entries = kcalloc(ha->msix_count, sizeof(struct qla_msix_entry), GFP_KERNEL); if (!ha->msix_entries) { diff --git a/scripts/specialize-patch b/scripts/specialize-patch index 942ae35f3..4ebea034d 100755 --- a/scripts/specialize-patch +++ b/scripts/specialize-patch @@ -399,11 +399,12 @@ function handle_if(evaluated) if (debug) printf "/* debug specialize-patch: (e) %s */\n", evaluated evaluated = evaluate(evaluated) + sub("^+#if", "+#elif", evaluated); decision[if_nesting_level] = evaluated inv_decision[if_nesting_level] \ = evaluate(sprintf("+#if %s && !%s", \ substr(inv_decision[if_nesting_level], 6), \ - substr(evaluated, 6))) + substr(evaluated, 8))) if (debug) printf "/* debug specialize-patch: (f) %s / %s */\n", \ decision[if_nesting_level], inv_decision[if_nesting_level] diff --git a/scst/README b/scst/README index b05516d7d..20b1e3be3 100644 --- a/scst/README +++ b/scst/README @@ -1887,7 +1887,7 @@ information about ALUA support in Windows Server, see also: (http://msdn.microsoft.com/en-us/library/gg607458%28v=vs.85%29.aspx). Active/Non-Optimized via internal redirection -............................................... +............................................. The Active-Standby configuration is simple to understand and setup, however, it might have serious interoperability issues, because not all @@ -1921,8 +1921,8 @@ served to initiator(s) (consider for simplicity that there is only one served device) 5. Connect to this SCST device through this internal target from the -passive node. Now you have a local SCSI device on the passive side -pointing to the active node. +passive node, for instance, using iSCSI. Now you have a local SCSI +device on the passive side pointing to the active node. 6. Export this local device to the initiator(s) using SCST *path-through* handler (scst_disk). Pass-though is needed to redirect @@ -1954,8 +1954,122 @@ on the new passive node. 6. Finish ALUA states change. +Example using direct sysfs interface could look like: + +Active-Optimized node: + +modprobe scst +modprobe scst_disk +modprobe scst_vdisk + +# Main device, DRBD primary here +echo "add_device aa filename=/dev/drbd1" >/sys/kernel/scst_tgt/handlers/vdisk_blockio/mgmt + +# Redirect device, not used here. Coming from connecting via iSCSI to the +# corresponding redirect target on the other side. +DEVICE=10:0:0:0 +echo add_device $DEVICE >/sys/kernel/scst_tgt/handlers/dev_disk/mgmt + +service iscsi-scst start + +# This is a regular, user-visible target +echo "add_target iqn.2006-10.net.v:tgt " >/sys/kernel/scst_tgt/targets/iscsi/mgmt +echo 1 >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgt/rel_tgt_id +echo "add aa 0" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgt/luns/mgmt + +# This is redirect target, 192.168.9.x is the redirect network +echo "add_target iqn.2006-10.net.v:tgtR" >/sys/kernel/scst_tgt/targets/iscsi/mgmt +echo 2 >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgtR/rel_tgt_id +echo "add_target_attribute iqn.2006-10.net.v:tgtR allowed_portal 192.168.9.1" >/sys/kernel/scst_tgt/targets/iscsi/mgmt +echo "1" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgtR/forwarding +echo "add aa 0" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgtR/luns/mgmt + +echo 1 >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgt/enabled +echo 1 >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgtR/enabled + +echo 1 >/sys/kernel/scst_tgt/targets/iscsi/enabled + +# ALUA config + +echo create aa >/sys/kernel/scst_tgt/device_groups/mgmt +echo add aa >/sys/kernel/scst_tgt/device_groups/aa/devices/mgmt + +echo add tgt_a >/sys/kernel/scst_tgt/device_groups/aa/target_groups/mgmt +echo add iqn.2006-10.net.v:tgt >/sys/kernel/scst_tgt/device_groups/aa/target_groups/tgt_a/mgmt +echo 1 >/sys/kernel/scst_tgt/device_groups/aa/target_groups/tgt_a/group_id +echo active >/sys/kernel/scst_tgt/device_groups/aa/target_groups/tgt_a/state + +echo add tgt_n >/sys/kernel/scst_tgt/device_groups/aa/target_groups/mgmt +echo add iqn.2006-10.net.v:tgt1 >/sys/kernel/scst_tgt/device_groups/aa/target_groups/tgt_n/mgmt +echo 2 >/sys/kernel/scst_tgt/device_groups/aa/target_groups/tgt_n/iqn.2006-10.net.v:tgt1/rel_tgt_id +echo 2 >/sys/kernel/scst_tgt/device_groups/aa/target_groups/tgt_n/group_id +echo nonoptimized >/sys/kernel/scst_tgt/device_groups/aa/target_groups/tgt_n/state + +Active-Non-Optimized node: + +modprobe scst +modprobe scst_disk +modprobe scst_vdisk + +# Main device, DRBD secondary, not used here +echo "add_device aa filename=/dev/drbd1" >/sys/kernel/scst_tgt/handlers/vdisk_blockio/mgmt + +# Redirect device. Coming from connecting via iSCSI to the +# corresponding redirect target on the other side. +DEVICE=10:0:0:0 +echo add_device $DEVICE >/sys/kernel/scst_tgt/handlers/dev_disk/mgmt + +service iscsi-scst start + +echo "add_target iqn.2006-10.net.v:tgt1" >/sys/kernel/scst_tgt/targets/iscsi/mgmt +echo 2 >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgt1/rel_tgt_id +echo "add $DEVICE 0" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgt1/luns/mgmt + +# Redirect target, 192.168.9.x is the redirect network +echo "add_target iqn.2006-10.net.v:tgtR" >/sys/kernel/scst_tgt/targets/iscsi/mgmt +echo 2 >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgtR/rel_tgt_id +echo "add_target_attribute iqn.2006-10.net.v:tgtR allowed_portal 192.168.9.2" >/sys/kernel/scst_tgt/targets/iscsi/mgmt +echo "1" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgtR/forwarding +echo "add aa 0" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgtR/luns/mgmt + +echo 1 >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgt1/enabled + +echo 1 >/sys/kernel/scst_tgt/targets/iscsi/enabled +echo 1 >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgtR/enabled + +# ALUA config + +echo create $DEVICE >/sys/kernel/scst_tgt/device_groups/mgmt +echo add $DEVICE >/sys/kernel/scst_tgt/device_groups/$DEVICE/devices/mgmt + +echo add tgt_a >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/mgmt +echo add iqn.2006-10.net.v:tgt >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_a/mgmt +echo 1 >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_a/iqn.2006-10.net.v:tgt/rel_tgt_id +echo 1 >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_a/group_id +echo active >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_a/state + +echo add tgt_n >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/mgmt +echo add iqn.2006-10.net.v:tgt1 >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_n/mgmt +echo 1 >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_n/group_id +echo nonoptimized >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_n/state + +ALUA state switch after DRBD primary-secondary transition: + +Ex-Optimized: + +echo "replace_no_ua $DEVICE 0" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgt1/luns/mgmt +echo nonoptimized >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_a/state +echo active >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_n/state + +Ex-Non-Optimized: + +echo "replace_no_ua aa 0" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgt1/luns/mgmt +echo nonoptimized >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_a/state +echo active >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_n/state + If you have any questions, please read this above text at least 3 times -before asking. It might be tricky to understand. +before asking. It might be tricky to understand :-) + VAAI ---- diff --git a/scst/README_in-tree b/scst/README_in-tree index df0de84ba..7804e8652 100644 --- a/scst/README_in-tree +++ b/scst/README_in-tree @@ -1740,7 +1740,7 @@ information about ALUA support in Windows Server, see also: (http://msdn.microsoft.com/en-us/library/gg607458%28v=vs.85%29.aspx). Active/Non-Optimized via internal redirection -............................................... +............................................. The Active-Standby configuration is simple to understand and setup, however, it might have serious interoperability issues, because not all @@ -1774,8 +1774,8 @@ served to initiator(s) (consider for simplicity that there is only one served device) 5. Connect to this SCST device through this internal target from the -passive node. Now you have a local SCSI device on the passive side -pointing to the active node. +passive node, for instance, using iSCSI. Now you have a local SCSI +device on the passive side pointing to the active node. 6. Export this local device to the initiator(s) using SCST *path-through* handler (scst_disk). Pass-though is needed to redirect @@ -1807,8 +1807,122 @@ on the new passive node. 6. Finish ALUA states change. +Example using direct sysfs interface could look like: + +Active-Optimized node: + +modprobe scst +modprobe scst_disk +modprobe scst_vdisk + +# Main device, DRBD primary here +echo "add_device aa filename=/dev/drbd1" >/sys/kernel/scst_tgt/handlers/vdisk_blockio/mgmt + +# Redirect device, not used here. Coming from connecting via iSCSI to the +# corresponding redirect target on the other side. +DEVICE=10:0:0:0 +echo add_device $DEVICE >/sys/kernel/scst_tgt/handlers/dev_disk/mgmt + +service iscsi-scst start + +# This is a regular, user-visible target +echo "add_target iqn.2006-10.net.v:tgt " >/sys/kernel/scst_tgt/targets/iscsi/mgmt +echo 1 >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgt/rel_tgt_id +echo "add aa 0" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgt/luns/mgmt + +# This is redirect target, 192.168.9.x is the redirect network +echo "add_target iqn.2006-10.net.v:tgtR" >/sys/kernel/scst_tgt/targets/iscsi/mgmt +echo 2 >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgtR/rel_tgt_id +echo "add_target_attribute iqn.2006-10.net.v:tgtR allowed_portal 192.168.9.1" >/sys/kernel/scst_tgt/targets/iscsi/mgmt +echo "1" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgtR/forwarding +echo "add aa 0" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgtR/luns/mgmt + +echo 1 >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgt/enabled +echo 1 >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgtR/enabled + +echo 1 >/sys/kernel/scst_tgt/targets/iscsi/enabled + +# ALUA config + +echo create aa >/sys/kernel/scst_tgt/device_groups/mgmt +echo add aa >/sys/kernel/scst_tgt/device_groups/aa/devices/mgmt + +echo add tgt_a >/sys/kernel/scst_tgt/device_groups/aa/target_groups/mgmt +echo add iqn.2006-10.net.v:tgt >/sys/kernel/scst_tgt/device_groups/aa/target_groups/tgt_a/mgmt +echo 1 >/sys/kernel/scst_tgt/device_groups/aa/target_groups/tgt_a/group_id +echo active >/sys/kernel/scst_tgt/device_groups/aa/target_groups/tgt_a/state + +echo add tgt_n >/sys/kernel/scst_tgt/device_groups/aa/target_groups/mgmt +echo add iqn.2006-10.net.v:tgt1 >/sys/kernel/scst_tgt/device_groups/aa/target_groups/tgt_n/mgmt +echo 2 >/sys/kernel/scst_tgt/device_groups/aa/target_groups/tgt_n/iqn.2006-10.net.v:tgt1/rel_tgt_id +echo 2 >/sys/kernel/scst_tgt/device_groups/aa/target_groups/tgt_n/group_id +echo nonoptimized >/sys/kernel/scst_tgt/device_groups/aa/target_groups/tgt_n/state + +Active-Non-Optimized node: + +modprobe scst +modprobe scst_disk +modprobe scst_vdisk + +# Main device, DRBD secondary, not used here +echo "add_device aa filename=/dev/drbd1" >/sys/kernel/scst_tgt/handlers/vdisk_blockio/mgmt + +# Redirect device. Coming from connecting via iSCSI to the +# corresponding redirect target on the other side. +DEVICE=10:0:0:0 +echo add_device $DEVICE >/sys/kernel/scst_tgt/handlers/dev_disk/mgmt + +service iscsi-scst start + +echo "add_target iqn.2006-10.net.v:tgt1" >/sys/kernel/scst_tgt/targets/iscsi/mgmt +echo 2 >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgt1/rel_tgt_id +echo "add $DEVICE 0" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgt1/luns/mgmt + +# Redirect target, 192.168.9.x is the redirect network +echo "add_target iqn.2006-10.net.v:tgtR" >/sys/kernel/scst_tgt/targets/iscsi/mgmt +echo 2 >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgtR/rel_tgt_id +echo "add_target_attribute iqn.2006-10.net.v:tgtR allowed_portal 192.168.9.2" >/sys/kernel/scst_tgt/targets/iscsi/mgmt +echo "1" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgtR/forwarding +echo "add aa 0" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgtR/luns/mgmt + +echo 1 >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgt1/enabled + +echo 1 >/sys/kernel/scst_tgt/targets/iscsi/enabled +echo 1 >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgtR/enabled + +# ALUA config + +echo create $DEVICE >/sys/kernel/scst_tgt/device_groups/mgmt +echo add $DEVICE >/sys/kernel/scst_tgt/device_groups/$DEVICE/devices/mgmt + +echo add tgt_a >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/mgmt +echo add iqn.2006-10.net.v:tgt >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_a/mgmt +echo 1 >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_a/iqn.2006-10.net.v:tgt/rel_tgt_id +echo 1 >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_a/group_id +echo active >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_a/state + +echo add tgt_n >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/mgmt +echo add iqn.2006-10.net.v:tgt1 >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_n/mgmt +echo 1 >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_n/group_id +echo nonoptimized >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_n/state + +ALUA state switch after DRBD primary-secondary transition: + +Ex-Optimized: + +echo "replace_no_ua $DEVICE 0" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgt1/luns/mgmt +echo nonoptimized >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_a/state +echo active >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_n/state + +Ex-Non-Optimized: + +echo "replace_no_ua aa 0" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.v:tgt1/luns/mgmt +echo nonoptimized >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_a/state +echo active >/sys/kernel/scst_tgt/device_groups/$DEVICE/target_groups/tgt_n/state + If you have any questions, please read this above text at least 3 times -before asking. It might be tricky to understand. +before asking. It might be tricky to understand :-) + VAAI ---- diff --git a/scst/include/backport.h b/scst/include/backport.h index ee3f172c6..75af117c9 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -60,6 +60,14 @@ static inline struct bio_set *bioset_create_backport(unsigned int pool_size, #define BIOSET_NEED_BVECS 0 #endif +/* See also commit 74d46992e0d9. */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0) +static inline void bio_set_dev(struct bio *bio, struct block_device *bdev) +{ + bio->bi_bdev = bdev; +} +#endif + /* */ #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) @@ -239,27 +247,6 @@ static inline struct inode *file_inode(const struct file *f) } #endif -#if (!defined(CONFIG_SUSE_KERNEL) && \ - LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0)) || \ - LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0) -static inline ssize_t vfs_readv_backport(struct file *file, - const struct iovec __user *vec, - unsigned long vlen, loff_t *pos, - int flags) -{ - return vfs_readv(file, vec, vlen, pos); -} -static inline ssize_t vfs_writev_backport(struct file *file, - const struct iovec __user *vec, - unsigned long vlen, loff_t *pos, - int flags) -{ - return vfs_writev(file, vec, vlen, pos); -} -#define vfs_readv vfs_readv_backport -#define vfs_writev vfs_writev_backport -#endif - #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) static inline int vfs_fsync_backport(struct file *file, int datasync) { @@ -759,4 +746,32 @@ static inline int scsi_bidi_cmnd(struct scsi_cmnd *cmd) } #endif +/* */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) +static inline struct request *scsi_req(struct request *rq) +{ + return rq; +} + +static inline void scsi_req_init(struct request *rq) +{ +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0) + rq->cmd_type = REQ_TYPE_BLOCK_PC; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) + rq->data_len = 0; + rq->sector = (sector_t) -1; +#else + rq->__data_len = 0; + rq->__sector = (sector_t) -1; +#endif + rq->bio = rq->biotail = NULL; + memset(rq->__cmd, 0, sizeof(rq->__cmd)); + rq->cmd = rq->__cmd; +#else + return blk_rq_set_block_pc(rq); +#endif +} +#endif + #endif /* _SCST_BACKPORT_H_ */ diff --git a/scst/include/scst.h b/scst/include/scst.h index c4f15dfa1..e08d52a2a 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -5536,7 +5536,7 @@ static inline void prepare_to_wait_exclusive_head(struct wait_queue_head *wq_hea * * Caller must hold lock of type @lock_type on @lock. */ -#define wait_event_locked(wq, condition, lock_type, lock) \ +#define wait_event_locked(wq, condition, lock_type, lock) do { \ if (!(condition)) { \ DEFINE_WAIT(__wait); \ \ @@ -5550,7 +5550,8 @@ if (!(condition)) { \ spin_ ## lock_type(&(lock)); \ } while (!(condition)); \ finish_wait(&(wq), &__wait); \ -} +} \ +} while (0) /* Only use get_unaligned_be24() if reading p - 1 is allowed. */ static inline uint32_t get_unaligned_be24(const uint8_t *const p) @@ -5712,9 +5713,16 @@ struct scst_data_descriptor { uint64_t sdd_blocks; }; +ssize_t scst_read(struct file *file, void *buf, size_t count, loff_t *pos); +ssize_t scst_write(struct file *file, const void *buf, size_t count, + loff_t *pos); +ssize_t scst_readv(struct file *file, const struct iovec *vec, + unsigned long vlen, loff_t *pos); +ssize_t scst_writev(struct file *file, const struct iovec *vec, + unsigned long vlen, loff_t *pos); void scst_write_same(struct scst_cmd *cmd, struct scst_data_descriptor *where); int scst_scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, - int data_direction, void *buffer, unsigned bufflen, + int data_direction, void *buffer, unsigned int bufflen, unsigned char *sense, int timeout, int retries, u64 flags); diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 17a4e7e41..bc96e7f3d 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -2112,8 +2112,7 @@ static int vdisk_format_dif(struct scst_cmd *cmd, uint64_t start_lba, full_len, (long long)loff); /* WRITE */ - err = vfs_writev(fd, (struct iovec __force __user *)iv, - iv_count, &loff, 0); + err = scst_writev(fd, iv, iv_count, &loff); if (err < 0) { PRINT_ERROR("Formatting DIF write() returned %lld from " "%zd", err, full_len); @@ -5962,8 +5961,7 @@ static int vdev_read_dif_tags(struct vdisk_cmd_params *p) iv_count, full_len, (long long)loff); /* READ */ - err = vfs_readv(fd, (struct iovec __force __user *)iv, iv_count, - &loff, 0); + err = scst_readv(fd, iv, iv_count, &loff); if ((err < 0) || (err < full_len)) { unsigned long flags; @@ -6091,8 +6089,7 @@ restart: TRACE_DBG("Writing DIF: eiv_count %d, full_len %zd", eiv_count, full_len); /* WRITE */ - err = vfs_writev(fd, (struct iovec __force __user *)eiv, - eiv_count, &loff, 0); + err = scst_writev(fd, eiv, eiv_count, &loff); if (err < 0) { unsigned long flags; @@ -6233,8 +6230,7 @@ static enum compl_status_e fileio_exec_read(struct vdisk_cmd_params *p) TRACE_DBG("Reading iv_count %d, full_len %zd", iv_count, full_len); /* READ */ - err = vfs_readv(fd, (struct iovec __force __user *)iv, iv_count, - &loff, 0); + err = scst_readv(fd, iv, iv_count, &loff); if ((err < 0) || (err < full_len)) { PRINT_ERROR("readv() returned %lld from %zd", (unsigned long long int)err, @@ -6427,8 +6423,7 @@ restart: TRACE_DBG("Writing: eiv_count %d, full_len %zd", eiv_count, full_len); /* WRITE */ - err = vfs_writev(fd, (struct iovec __force __user *)eiv, - eiv_count, &loff, 0); + err = scst_writev(fd, eiv, eiv_count, &loff); if (err < 0) { PRINT_ERROR("write() returned %lld from %zd", (unsigned long long int)err, @@ -6919,7 +6914,7 @@ static void blockio_exec_rw(struct vdisk_cmd_params *p, bool write, bool fua) #else bio->bi_sector = lba_start0 << (block_shift - 9); #endif - bio->bi_bdev = bdev; + bio_set_dev(bio, bdev); bio->bi_private = blockio_work; #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30)) && (LINUX_VERSION_CODE <= KERNEL_VERSION(3, 6, 0)) bio->bi_destructor = blockio_bio_destructor; @@ -7103,7 +7098,7 @@ static int vdisk_blockio_flush(struct block_device *bdev, gfp_t gfp_mask, } bio->bi_end_io = vdev_flush_end_io; bio->bi_private = cmd; - bio->bi_bdev = bdev; + bio_set_dev(bio, bdev); #if (!defined(CONFIG_SUSE_KERNEL) && \ LINUX_VERSION_CODE < KERNEL_VERSION(4, 8, 0)) || \ LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0) @@ -7262,7 +7257,7 @@ static ssize_t blockio_read_sync(struct scst_vdisk_dev *virt_dev, void *buf, #else bio_set_op_attrs(bio, REQ_OP_READ, REQ_SYNC); #endif - bio->bi_bdev = bdev; + bio_set_dev(bio, bdev); bio->bi_end_io = blockio_end_sync_io; bio->bi_private = &s; #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30)) && (LINUX_VERSION_CODE <= KERNEL_VERSION(3, 6, 0)) @@ -7325,7 +7320,7 @@ static ssize_t fileio_read_sync(struct file *fd, void *buf, size_t len, old_fs = get_fs(); set_fs(get_ds()); - ret = vfs_read(fd, (char __force __user *)buf, len, loff); + ret = scst_read(fd, buf, len, loff); set_fs(old_fs); return ret; diff --git a/scst/src/scst_dlm.c b/scst/src/scst_dlm.c index 130e61522..26e64535a 100644 --- a/scst/src/scst_dlm.c +++ b/scst/src/scst_dlm.c @@ -511,7 +511,7 @@ static int scst_read_file(const char *path, char *buf, int buf_len) goto out; } pos = 0; - ret = vfs_read(f, (char __force __user *)buf, buf_len, &pos); + ret = scst_read(f, buf, buf_len, &pos); if (ret >= 0) buf[min(ret, buf_len - 1)] = '\0'; filp_close(f, NULL); diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 04e39b4a7..c7c1241ec 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -5861,6 +5861,101 @@ static void scst_complete_request_sense(struct scst_cmd *req_cmd) return; } +ssize_t scst_read(struct file *file, void *buf, size_t count, loff_t *pos) +{ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) + struct iovec iov = { + .iov_base = (void __force __user *)buf, + .iov_len = count + }; + + return scst_readv(file, &iov, 1, pos); +#else + return vfs_read(file, (void __force __user *)buf, count, pos); +#endif +} +EXPORT_SYMBOL(scst_read); + +ssize_t scst_write(struct file *file, const void *buf, size_t count, + loff_t *pos) +{ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) + struct iovec iov = { + .iov_base = (void __force __user *)buf, + .iov_len = count + }; + + return scst_writev(file, &iov, 1, pos); +#else + return vfs_write(file, (void __force __user *)buf, count, pos); +#endif +} +EXPORT_SYMBOL(scst_write); + +ssize_t scst_readv(struct file *file, const struct iovec *vec, + unsigned long vlen, loff_t *pos) +{ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) + struct iovec iovstack[UIO_FASTIOV]; + struct iovec *iov = iovstack; + struct iov_iter iter; + ssize_t ret; + + ret = import_iovec(READ, (const struct iovec __force __user *)vec, vlen, + ARRAY_SIZE(iovstack), &iov, &iter); + if (ret < 0) + return ret; + ret = vfs_iter_read(file, &iter, pos, 0); + kfree(iov); + return ret; +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) || \ + (defined(CONFIG_SUSE_KERNEL) && \ + LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) + return vfs_readv(file, (const struct iovec __user *)vec, vlen, pos, 0); +#else + return vfs_readv(file, (const struct iovec __user *)vec, vlen, pos); +#endif +} +EXPORT_SYMBOL(scst_readv); + +/** + * scst_writev - write a buffer to a file + * @file: File to write to. + * @vec: Pointer to first element of struct iovec array. + * @vlen: Number of elements of the iovec array. + * @pos: Position in @file where to start writing. + * + * Note: although @vec->iov_base has type void __user*, it points at kernel + * data and not at data in user space. + */ +ssize_t scst_writev(struct file *file, const struct iovec *vec, + unsigned long vlen, loff_t *pos) +{ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) + struct iovec iovstack[UIO_FASTIOV]; + struct iovec *iov = iovstack; + struct iov_iter iter; + ssize_t ret; + + ret = import_iovec(WRITE, (const struct iovec __force __user *)vec, + vlen, ARRAY_SIZE(iovstack), &iov, &iter); + if (ret < 0) + return ret; + file_start_write(file); + ret = vfs_iter_write(file, &iter, pos, 0); + file_end_write(file); + kfree(iov); + return ret; +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) || \ + (defined(CONFIG_SUSE_KERNEL) && \ + LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) + return vfs_writev(file, (const struct iovec __user *)vec, vlen, pos, 0); +#else + return vfs_writev(file, (const struct iovec __user *)vec, vlen, pos); +#endif +} +EXPORT_SYMBOL(scst_writev); + struct scst_ws_sg_tail { struct scatterlist *sg; int sg_cnt; @@ -6780,7 +6875,7 @@ out: } int scst_scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, - int data_direction, void *buffer, unsigned bufflen, + int data_direction, void *buffer, unsigned int bufflen, unsigned char *sense, int timeout, int retries, u64 flags) { return scsi_execute(sdev, cmd, data_direction, buffer, bufflen, sense, @@ -7862,11 +7957,7 @@ static struct request *blk_make_request(struct request_queue *q, if (IS_ERR(rq)) return rq; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0) scsi_req_init(scsi_req(rq)); -#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) - scsi_req_init(rq); -#endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) rq->cmd_flags = bio_data_dir(bio) == READ ? REQ_OP_SCSI_IN : REQ_OP_SCSI_OUT; @@ -8098,15 +8189,9 @@ static struct request *blk_map_kern_sg(struct request_queue *q, if (unlikely(!rq)) return ERR_PTR(-ENOMEM); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0) scsi_req_init(scsi_req(rq)); -#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) - scsi_req_init(rq); -#endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) rq->cmd_flags = reading ? REQ_OP_SCSI_IN : REQ_OP_SCSI_OUT; -#else - blk_rq_set_block_pc(rq); #endif goto out; } @@ -8401,12 +8486,7 @@ int scst_scsi_exec_async(struct scst_cmd *cmd, void *data, sioc->data = data; sioc->done = done; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) req = scsi_req(rq); -#else - req = rq; -#endif - req->cmd_len = cmd_len; if (req->cmd_len <= BLK_MAX_CDB) { memset(req->cmd, 0, BLK_MAX_CDB); /* ATAPI hates garbage after CDB */ @@ -14872,14 +14952,14 @@ int scst_copy_file(const char *src, const char *dest) } pos = 0; - res = vfs_read(file_src, (void __force __user *)buf, file_size, &pos); + res = scst_read(file_src, buf, file_size, &pos); if (res != file_size) { PRINT_ERROR("Unable to read file '%s' - error %d", src, res); goto out_skip; } pos = 0; - res = vfs_write(file_dest, (void __force __user *)buf, file_size, &pos); + res = scst_write(file_dest, buf, file_size, &pos); if (res != file_size) { PRINT_ERROR("Unable to write to '%s' - error %d", dest, res); goto out_skip; @@ -14973,7 +15053,7 @@ int scst_write_file_transactional(const char *name, const char *name1, pos = signature_len+1; - res = vfs_write(file, (void const __force __user *)buf, size, &pos); + res = scst_write(file, buf, size, &pos); if (res != size) goto write_error; @@ -14984,11 +15064,11 @@ int scst_write_file_transactional(const char *name, const char *name1, } pos = 0; - res = vfs_write(file, (void const __force __user *)signature, signature_len, &pos); + res = scst_write(file, signature, signature_len, &pos); if (res != signature_len) goto write_error; - res = vfs_write(file, (void __force __user *)&n, sizeof(n), &pos); + res = scst_write(file, &n, sizeof(n), &pos); if (res != sizeof(n)) goto write_error; @@ -15070,7 +15150,7 @@ static int __scst_read_file_transactional(const char *file_name, } pos = 0; - res = vfs_read(file, (void __force __user *)buf, file_size, &pos); + res = scst_read(file, buf, file_size, &pos); if (res != file_size) { PRINT_ERROR("Unable to read file '%s' - error %d", file_name, res); if (res > 0) diff --git a/scst/src/scst_pres.c b/scst/src/scst_pres.c index 02f4d68ff..467f5ec0e 100644 --- a/scst/src/scst_pres.c +++ b/scst/src/scst_pres.c @@ -720,7 +720,7 @@ static int scst_pr_do_load_device_file(struct scst_device *dev, } pos = 0; - rc = vfs_read(file, (void __force __user *)buf, file_size, &pos); + rc = scst_read(file, buf, file_size, &pos); if (rc != file_size) { PRINT_ERROR("Unable to read file '%s' - error %d", file_name, rc); @@ -925,7 +925,7 @@ void scst_pr_sync_device_file(struct scst_device *dev) */ sign = 0; pos = 0; - res = vfs_write(file, (void __force __user *)&sign, sizeof(sign), &pos); + res = scst_write(file, &sign, sizeof(sign), &pos); if (res != sizeof(sign)) goto write_error; @@ -933,7 +933,7 @@ void scst_pr_sync_device_file(struct scst_device *dev) * version */ version = SCST_PR_FILE_VERSION; - res = vfs_write(file, (void __force __user *)&version, sizeof(version), &pos); + res = scst_write(file, &version, sizeof(version), &pos); if (res != sizeof(version)) goto write_error; @@ -941,7 +941,7 @@ void scst_pr_sync_device_file(struct scst_device *dev) * APTPL */ aptpl = dev->pr_aptpl; - res = vfs_write(file, (void __force __user *)&aptpl, sizeof(aptpl), &pos); + res = scst_write(file, &aptpl, sizeof(aptpl), &pos); if (res != sizeof(aptpl)) goto write_error; @@ -949,15 +949,15 @@ void scst_pr_sync_device_file(struct scst_device *dev) * reservation */ pr_is_set = dev->pr_is_set; - res = vfs_write(file, (void __force __user *)&pr_is_set, sizeof(pr_is_set), &pos); + res = scst_write(file, &pr_is_set, sizeof(pr_is_set), &pos); if (res != sizeof(pr_is_set)) goto write_error; - res = vfs_write(file, (void __force __user *)&dev->pr_type, sizeof(dev->pr_type), &pos); + res = scst_write(file, &dev->pr_type, sizeof(dev->pr_type), &pos); if (res != sizeof(dev->pr_type)) goto write_error; - res = vfs_write(file, (void __force __user *)&dev->pr_scope, sizeof(dev->pr_scope), &pos); + res = scst_write(file, &dev->pr_scope, sizeof(dev->pr_scope), &pos); if (res != sizeof(dev->pr_scope)) goto write_error; @@ -971,23 +971,23 @@ void scst_pr_sync_device_file(struct scst_device *dev) is_holder = (dev->pr_holder == reg); - res = vfs_write(file, (void __force __user *)&is_holder, + res = scst_write(file, &is_holder, sizeof(is_holder), &pos); if (res != sizeof(is_holder)) goto write_error; size = scst_tid_size(reg->transport_id); - res = vfs_write(file, (void __force __user *)reg->transport_id, + res = scst_write(file, reg->transport_id, size, &pos); if (res != size) goto write_error; - res = vfs_write(file, (void __force __user *)®->key, + res = scst_write(file, ®->key, sizeof(reg->key), &pos); if (res != sizeof(reg->key)) goto write_error; - res = vfs_write(file, (void __force __user *)®->rel_tgt_id, + res = scst_write(file, ®->rel_tgt_id, sizeof(reg->rel_tgt_id), &pos); if (res != sizeof(reg->rel_tgt_id)) goto write_error; @@ -1001,7 +1001,7 @@ void scst_pr_sync_device_file(struct scst_device *dev) sign = SCST_PR_FILE_SIGN; pos = 0; - res = vfs_write(file, (void __force __user *)&sign, sizeof(sign), &pos); + res = scst_write(file, &sign, sizeof(sign), &pos); if (res != sizeof(sign)) goto write_error; diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index d6c14cb2c..8e876ccd0 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -3836,8 +3836,8 @@ static int scst_exec_check_sn(struct scst_cmd **active_cmd) /* dev->qerr can be changed behind our back */ q = cmd->dev->qerr; - /* ACCESS_ONCE doesn't work for bit fields */ - qerr = ACCESS_ONCE(q); + /* READ_ONCE doesn't work for bit fields */ + qerr = READ_ONCE(q); switch (qerr) { case SCST_QERR_2_RESERVED: diff --git a/srpt/src/ib_srpt.c b/srpt/src/ib_srpt.c index a936c434a..921fec475 100644 --- a/srpt/src/ib_srpt.c +++ b/srpt/src/ib_srpt.c @@ -4477,12 +4477,7 @@ static void srpt_add_one(struct ib_device *device) INIT_IB_EVENT_HANDLER(&sdev->event_handler, sdev->device, srpt_event_handler); - ret = ib_register_event_handler(&sdev->event_handler); - if (ret) { - pr_err("ib_register_event_handler() failed: %d\n", ret); - goto err_cm; - } - + ib_register_event_handler(&sdev->event_handler); atomic_inc(&srpt_device_count); out: ib_set_client_data(device, &srpt_client, sdev);