[openib-general] [PATCH 6/6] [RFC] iser socket
Or Gerlitz
ogerlitz at voltaire.com
Wed Feb 22 06:37:24 PST 2006
+ note that data is never moved on the socket via send/recv but
only by calls from iscsi_iser.c to iser_send_control/command/dataout
+ data originting/resuling in user space (eg login request/respose)
is moved down/up by open iscsi using netlink
--- /ulp/iser-x/iser_socket.c 2006-02-22 15:07:03.000000000 +0200
+++ /ulp/iser/iser_socket.c 2006-02-22 13:39:07.000000000 +0200
@@ -1 +1,214 @@
+/*
+ * Copyright (c) 2005, 2006 Voltaire, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses. You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * $Id: iser_socket.c 5442 2006-02-19 09:05:17Z ogerlitz $
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/tcp.h>
+
+#include "iscsi_iser.h"
+#include "iser_socket.h"
+
+#define PF_ISER AF_ISER
+
+static int iser_sock_create(struct socket *, int);
+static int iser_sock_release(struct socket *);
+static int iser_sock_connect(struct socket *, struct sockaddr *, int, int);
+static int iser_sock_shutdown(struct socket *,int);
+static int iser_sock_getsockopt(struct socket *,int,int,char __user *,int __user *);
+static unsigned int iser_sock_poll(struct file *,struct socket *,
+ struct poll_table_struct *);
+
+struct iser_sock {
+ struct sock sock;
+ struct iser_conn iser_conn;
+};
+
+static struct net_proto_family iser_proto_family = {
+ .family = PF_ISER,
+ .create = iser_sock_create,
+ .authentication = 0,
+ .encryption = 0,
+ .encrypt_net = 0
+};
+
+static struct proto_ops iser_proto_ops = {
+ .family = AF_ISER,
+ .owner = THIS_MODULE,
+
+ .connect = iser_sock_connect,
+ .release = iser_sock_release,
+ .shutdown = iser_sock_shutdown,
+
+ .bind = sock_no_bind,
+ .poll = iser_sock_poll,
+ .socketpair = sock_no_socketpair,
+ .accept = sock_no_accept,
+ .getname = sock_no_getname,
+ .ioctl = sock_no_ioctl,
+ .listen = sock_no_listen,
+ .setsockopt = sock_setsockopt,
+ .getsockopt = iser_sock_getsockopt,
+ .sendmsg = sock_no_sendmsg,
+ .recvmsg = sock_no_recvmsg,
+ .mmap = sock_no_mmap,
+ .sendpage = sock_no_sendpage
+};
+
+static struct proto iser_sock_proto = {
+ .name = "ib_iser",
+ .owner = THIS_MODULE,
+ .obj_size = sizeof(struct iser_sock)
+};
+
+struct iser_conn *iser_conn_from_sock(struct socket *sock)
+{
+ struct iser_sock *iser_sk = (struct iser_sock *)sock->sk;
+
+ return &iser_sk->iser_conn;
+}
+
+struct socket *iser_conn_to_sock(struct iser_conn *p_iser_conn)
+{
+ struct iser_sock *iser_sk;
+ iser_sk = container_of(p_iser_conn, struct iser_sock, iser_conn);
+
+ return iser_sk->sock.sk_socket;
+}
+
+int iser_register_sockets(void)
+{
+ int error;
+
+ error = proto_register(&iser_sock_proto, 1);
+ if (error < 0) {
+ iser_err("proto_register failed (%d)\n", error);
+ return error;
+ }
+
+ error = sock_register(&iser_proto_family);
+ if (error < 0) {
+ iser_err("sock_register failed (%d)\n", error);
+ proto_unregister(&iser_sock_proto);
+ }
+
+ return 0;
+}
+
+void iser_unreg_sockets(void)
+{
+ sock_unregister(PF_ISER);
+ proto_unregister(&iser_sock_proto);
+}
+
+static int iser_sock_create(struct socket *sock, int protocol)
+{
+ struct iser_sock *iser_sk = NULL;
+
+ if (sock->type != SOCK_STREAM)
+ return -ESOCKTNOSUPPORT;
+
+ iser_sk = (struct iser_sock *)sk_alloc(PF_INET, GFP_KERNEL,
+ &iser_sock_proto, 1);
+ if (iser_sk == NULL)
+ return -ENOBUFS;
+
+ sock_init_data(sock, &iser_sk->sock);
+ iser_sk->sock.sk_destruct = NULL;
+ iser_sk->sock.sk_family = PF_ISER;
+ iser_sk->sock.sk_sndbuf = 64*1024;
+
+ iser_conn_init(&iser_sk->iser_conn);
+
+ sock->ops = &iser_proto_ops;
+ sock->state = SS_UNCONNECTED;
+ sock_graft(&iser_sk->sock, sock);
+
+ return 0;
+}
+
+int iser_sock_connect(struct socket *sock, struct sockaddr *uservaddr,
+ int sockaddr_len, int flags)
+{
+ struct sockaddr_in *dst_addr = (struct sockaddr_in *)uservaddr;
+ struct iser_sock *iser_sk = (struct iser_sock *)sock->sk;
+ struct iser_conn *p_iser_conn = &iser_sk->iser_conn;
+ int err = 0;
+
+ iser_err("dst_addr ip %.8x (%d.%d.%d.%d) port %.4x=%d\n",
+ dst_addr->sin_addr.s_addr, NIPQUAD(dst_addr->sin_addr),
+ dst_addr->sin_port, dst_addr->sin_port);
+
+ err = iser_connect(p_iser_conn, NULL, dst_addr);
+ if (err)
+ iser_err("conn_establish failed: %d\n", err);
+ return err;
+}
+
+static inline void iser_sock_free(struct socket *sock)
+{
+ struct sock *sk = sock->sk;
+ sock->sk = NULL;
+ sock_orphan(sk);
+ sk_free(sk);
+}
+
+int iser_sock_release(struct socket *sock)
+{
+ struct iser_sock *iser_sock = (struct iser_sock *)sock->sk;
+ struct iser_conn *p_iser_conn = &iser_sock->iser_conn;
+ int iser_err = 0;
+
+ if (atomic_read(&p_iser_conn->state) == ISER_CONN_DOWN)
+ iser_sock_free(sock);
+ else
+ iser_err = -EPERM;
+ return iser_err;
+}
+
+int iser_sock_shutdown(struct socket *sock, int how)
+{
+ return 0;
+}
+
+static int iser_sock_getsockopt(struct socket *sock, int level, int optname,
+ char __user *optval, int __user *optlen)
+{
+ return 0;
+}
+
+static unsigned int iser_sock_poll(struct file *file, struct socket *sock,
+ struct poll_table_struct *wait)
+{
+ return POLLOUT;
+}
--- /ulp/iser-x/iser_socket.h 2006-02-22 15:07:04.000000000 +0200
+++ /ulp/iser/iser_socket.h 2006-02-22 13:39:06.000000000 +0200
@@ -1 +1,49 @@
+/*
+ * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses. You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * $Id: iser_socket.h 5314 2006-02-06 15:47:06Z ogerlitz $
+ */
+#ifndef __ISER_SOCKETS_H__
+#define __ISER_SOCKETS_H__
+
+#include <linux/net.h>
+
+struct iser_conn;
+
+#define AF_ISER 28 /* to be defined properly */
+
+int iser_register_sockets(void);
+void iser_unreg_sockets(void);
+
+struct iser_conn *iser_conn_from_sock(struct socket *sock);
+struct socket *iser_conn_to_sock(struct iser_conn *p_iser_conn);
+#endif /* __ISER_SOCKETS_H__ */
More information about the general
mailing list