From cc685733a58293f2a186d98e20842ada10419076 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Wed, 14 May 2008 17:20:20 +0000 Subject: [PATCH] Interface versioning between iSCSI-SCST kernel and user space parts, iscsi_u.h renamed to iscsi_scst.h. Property svn:ignore adjusted accordingly. Docs updated. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@371 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/Makefile | 19 +++++++---- iscsi-scst/README | 6 ++++ .../include/{iscsi_u.h => iscsi_scst.h} | 34 ++++++++++--------- iscsi-scst/include/iscsi_scst_ver.h | 16 +++++++++ iscsi-scst/kernel/config.c | 31 ++++++++++++++++- iscsi-scst/kernel/event.c | 2 +- iscsi-scst/kernel/iscsi.h | 2 +- iscsi-scst/usr/ctldev.c | 23 +++++++++---- iscsi-scst/usr/iscsi_scstd.c | 4 +-- iscsi-scst/usr/iscsid.h | 2 +- 10 files changed, 102 insertions(+), 37 deletions(-) rename iscsi-scst/include/{iscsi_u.h => iscsi_scst.h} (74%) create mode 100644 iscsi-scst/include/iscsi_scst_ver.h diff --git a/iscsi-scst/Makefile b/iscsi-scst/Makefile index 9f4797595..245ae74d9 100644 --- a/iscsi-scst/Makefile +++ b/iscsi-scst/Makefile @@ -1,11 +1,9 @@ # -# Makefile for the Linux kernel device drivers. +# Makefile for iSCSI-SCST # # Note! Dependencies are done automagically by 'make dep', which also # removes any old dependencies. DON'T put your own dependencies here # unless it's something special (not a .c file). -# -# Note 2! The CFLAGS definitions are now in the main makefile. SCST_DIR := $(shell pwd)/../scst/src SUBDIRS := $(shell pwd) @@ -21,7 +19,7 @@ else KDIR ?= /lib/modules/$(KVER)/build endif -all: progs mods +all: include/iscsi_scst_itf_ver.h progs mods mods: Modules.symvers Module.symvers $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd)/kernel modules @@ -29,9 +27,15 @@ mods: Modules.symvers Module.symvers progs: $(MAKE) -C usr -install: all kernel/iscsi-scst.ko usr/iscsi-scstd usr/iscsi-scst-adm +include/iscsi_scst_itf_ver.h: include/iscsi_scst.h + echo "/* Autogenerated, don't edit */" >include/iscsi_scst_itf_ver.h + echo "" >>include/iscsi_scst_itf_ver.h + echo -n "#define ISCSI_SCST_INTERFACE_VERSION " >>include/iscsi_scst_itf_ver.h + echo "\"`sha1sum include/iscsi_scst.h|awk '{printf $$1}'`\"" >>include/iscsi_scst_itf_ver.h + +install: all @install -vD usr/iscsi-scstd $(DISTDIR)/usr/local/sbin/iscsi-scstd - @install -vD usr/iscsi-scst-adm $(DISTDIR)/usr/local/sbin/iscsi-scst-adm + -@install -vD usr/iscsi-scst-adm $(DISTDIR)/usr/local/sbin/iscsi-scst-adm if [ -f /etc/debian_version ]; then \ install -vD -m 755 etc/initd/initd.debian $(DISTDIR)/etc/init.d/iscsi-scst; \ elif [ -f /etc/redhat-release ]; then \ @@ -70,7 +74,8 @@ clean: $(MAKE) -C usr clean $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd)/kernel clean rm -f kernel/Modules.symvers kernel/Module.symvers \ - kernel/Module.markers kernel/modules.order + kernel/Module.markers kernel/modules.order \ + include/iscsi_scst_itf_ver.h extraclean: clean diff --git a/iscsi-scst/README b/iscsi-scst/README index 07742bc32..16bd66433 100644 --- a/iscsi-scst/README +++ b/iscsi-scst/README @@ -32,6 +32,12 @@ Installation Basically as in README-IET, where file names are changed as specified above. +If during compilation you see message like "*** No rule to make target +`xxx.h', needed by `yyy.o'. Stop.", then your autogenerated +dependencies don't match your compiler configuration anymore. You should +run "make extraclean" to remove them. On the next compilation they will +be regenerated. + If you experience problems during kernel module load or running, check your system and/or kernel logs (or run dmesg command for the few most recent kernel messages). diff --git a/iscsi-scst/include/iscsi_u.h b/iscsi-scst/include/iscsi_scst.h similarity index 74% rename from iscsi-scst/include/iscsi_u.h rename to iscsi-scst/include/iscsi_scst.h index 1badfbac8..4a1c9a7a9 100644 --- a/iscsi-scst/include/iscsi_u.h +++ b/iscsi-scst/include/iscsi_scst.h @@ -13,21 +13,22 @@ * GNU General Public License for more details. */ -#ifndef _ISCSI_U_H -#define _ISCSI_U_H +#ifndef _ISCSI_SCST_U_H +#define _ISCSI_SCST_U_H #ifndef __KERNEL__ #include #endif -#define ISCSI_VERSION_STRING "0.9.6/0.4.15r148" +#include "iscsi_scst_ver.h" +#include "iscsi_scst_itf_ver.h" /* The maximum length of 223 bytes in the RFC. */ -#define ISCSI_NAME_LEN 256 +#define ISCSI_NAME_LEN 256 #define ISCSI_LISTEN_PORT 3260 -#define SCSI_ID_LEN 24 +#define SCSI_ID_LEN 24 #ifndef aligned_u64 #define aligned_u64 uint64_t __attribute__((aligned(8))) @@ -47,7 +48,7 @@ struct session_info { u32 exp_cmd_sn; }; -#define DIGEST_ALL (DIGEST_NONE | DIGEST_CRC32C) +#define DIGEST_ALL (DIGEST_NONE | DIGEST_CRC32C) #define DIGEST_NONE (1 << 0) #define DIGEST_CRC32C (1 << 1) @@ -126,16 +127,17 @@ struct iscsi_event { #define NETLINK_ISCSI_SCST 25 -#define ADD_TARGET _IOW('i', 0, struct target_info) -#define DEL_TARGET _IOW('i', 1, struct target_info) -#define ADD_SESSION _IOW('i', 2, struct session_info) -#define DEL_SESSION _IOW('i', 3, struct session_info) -#define GET_SESSION_INFO _IOWR('i', 4, struct session_info) -#define ADD_CONN _IOW('i', 5, struct conn_info) -#define DEL_CONN _IOW('i', 6, struct conn_info) -#define GET_CONN_INFO _IOWR('i', 7, struct conn_info) -#define ISCSI_PARAM_SET _IOW('i', 8, struct iscsi_param_info) -#define ISCSI_PARAM_GET _IOWR('i', 9, struct iscsi_param_info) +#define REGISTER_USERD _IOW('s', 0, const char*) +#define ADD_TARGET _IOW('s', 1, struct target_info) +#define DEL_TARGET _IOW('s', 2, struct target_info) +#define ADD_SESSION _IOW('s', 3, struct session_info) +#define DEL_SESSION _IOW('s', 4, struct session_info) +#define GET_SESSION_INFO _IOWR('s', 5, struct session_info) +#define ADD_CONN _IOW('s', 6, struct conn_info) +#define DEL_CONN _IOW('s', 7, struct conn_info) +#define GET_CONN_INFO _IOWR('s', 8, struct conn_info) +#define ISCSI_PARAM_SET _IOW('s', 9, struct iscsi_param_info) +#define ISCSI_PARAM_GET _IOWR('s', 10, struct iscsi_param_info) static inline int iscsi_is_key_declarative(int key) { diff --git a/iscsi-scst/include/iscsi_scst_ver.h b/iscsi-scst/include/iscsi_scst_ver.h new file mode 100644 index 000000000..e1599925d --- /dev/null +++ b/iscsi-scst/include/iscsi_scst_ver.h @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2007 Vladislav Bolkhovitin + * Copyright (C) 2007 CMS Distribution Limited + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#define ISCSI_VERSION_STRING "0.9.6/0.4.15r148" diff --git a/iscsi-scst/kernel/config.c b/iscsi-scst/kernel/config.c index 8fb0a6220..29001383a 100644 --- a/iscsi-scst/kernel/config.c +++ b/iscsi-scst/kernel/config.c @@ -369,12 +369,40 @@ static int add_target(unsigned long ptr) return err; } +static int iscsi_check_version(unsigned long arg) +{ + char ver[sizeof(ISCSI_SCST_INTERFACE_VERSION)+1]; + int res; + + res = copy_from_user(ver, (void*)arg, sizeof(ver)); + if (res < 0) { + PRINT_ERROR("%s", "Unable to get version string"); + goto out; + } + ver[sizeof(ver)-1] = '\0'; + + if (strcmp(ver, ISCSI_SCST_INTERFACE_VERSION) != 0) { + PRINT_ERROR("Incorrect version of user space %s (needed %s)", + ver, ISCSI_SCST_INTERFACE_VERSION); + res = -EINVAL; + goto out; + } + +out: + return res; +} + static long ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct iscsi_target *target = NULL; long err; u32 id; + if (cmd == REGISTER_USERD) { + err = iscsi_check_version(arg); + goto out; + } + if ((err = get_user(id, (u32 *) arg)) != 0) goto out; @@ -441,10 +469,11 @@ static long ioctl(struct file *file, unsigned int cmd, unsigned long arg) case GET_CONN_INFO: err = get_conn_info(target, arg); break; - + default: PRINT_ERROR("invalid ioctl cmd %x", cmd); err = -EINVAL; + break; } mutex_unlock(&target->target_mutex); diff --git a/iscsi-scst/kernel/event.c b/iscsi-scst/kernel/event.c index 5e2cb2037..480bc9c4d 100644 --- a/iscsi-scst/kernel/event.c +++ b/iscsi-scst/kernel/event.c @@ -18,7 +18,7 @@ */ #include -#include "iscsi_u.h" +#include "iscsi_scst.h" #include "iscsi.h" static struct sock *nl; diff --git a/iscsi-scst/kernel/iscsi.h b/iscsi-scst/kernel/iscsi.h index e0368e114..cb3c039d1 100644 --- a/iscsi-scst/kernel/iscsi.h +++ b/iscsi-scst/kernel/iscsi.h @@ -26,7 +26,7 @@ #include #include "iscsi_hdr.h" -#include "iscsi_u.h" +#include "iscsi_scst.h" #include "iscsi_dbg.h" diff --git a/iscsi-scst/usr/ctldev.c b/iscsi-scst/usr/ctldev.c index 41929d644..34417ac43 100644 --- a/iscsi-scst/usr/ctldev.c +++ b/iscsi-scst/usr/ctldev.c @@ -40,11 +40,12 @@ static int ctrdev_open(void) char devname[256]; char buf[256]; int devn; - int ctlfd; + int ctlfd = -1; + int err; if (!(f = fopen("/proc/devices", "r"))) { perror("Cannot open control path to the driver\n"); - return -1; + goto out; } devn = 0; @@ -63,24 +64,32 @@ static int ctrdev_open(void) fclose(f); if (!devn) { - printf - ("cannot find iscsictl in /proc/devices - " + printf("cannot find iscsictl in /proc/devices - " "make sure the module is loaded\n"); - return -1; + goto out; } unlink(CTL_DEVICE); if (mknod(CTL_DEVICE, (S_IFCHR | 0600), (devn << 8))) { printf("cannot create %s %d\n", CTL_DEVICE, errno); - return -1; + goto out; } ctlfd = open(CTL_DEVICE, O_RDWR); if (ctlfd < 0) { printf("cannot open %s %d\n", CTL_DEVICE, errno); - return -1; + goto out; } + err = ioctl(ctlfd, REGISTER_USERD, ISCSI_SCST_INTERFACE_VERSION); + if (err < 0) { + log_error("Unable to register: %s\n", strerror(errno)); + close(ctlfd); + ctlfd = -1; + goto out; + } + +out: return ctlfd; } diff --git a/iscsi-scst/usr/iscsi_scstd.c b/iscsi-scst/usr/iscsi_scstd.c index 2ff27476b..66c07a29a 100644 --- a/iscsi-scst/usr/iscsi_scstd.c +++ b/iscsi-scst/usr/iscsi_scstd.c @@ -573,10 +573,8 @@ int main(int argc, char **argv) exit(-1); }; - if ((ctrl_fd = ki->ctldev_open()) < 0) { - perror("ctldev fd\n"); + if ((ctrl_fd = ki->ctldev_open()) < 0) exit(-1); - } if ((ipc_fd = iscsi_adm_request_listen()) < 0) { perror("ipc fd\n"); diff --git a/iscsi-scst/usr/iscsid.h b/iscsi-scst/usr/iscsid.h index 9ecaa2bcc..0aaffc582 100644 --- a/iscsi-scst/usr/iscsid.h +++ b/iscsi-scst/usr/iscsid.h @@ -22,7 +22,7 @@ #include "types.h" #include "iscsi_hdr.h" -#include "iscsi_u.h" +#include "iscsi_scst.h" #include "param.h" #include "config.h" #include "misc.h"