From: Jack Wang <jinpu.wang-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
To: linux-block-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
axboe-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org,
hch-jcswGhMUV9g@public.gmane.org,
mail-99BIx50xQYGELgA04lAiVw@public.gmane.org,
Milind.dumbare-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
yun.wang-EIkl63zCoXaH+58JC4qpiA@public.gmane.org,
Jack Wang <jinpu.wang-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>,
Kleber Souza
<kleber.souza-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>,
Danil Kipnis
<danil.kipnis-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>,
Roman Pen <roman.penyaev-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
Subject: [PATCH 17/28] ibnbd_clt: add header shared in ibnbd_client
Date: Fri, 24 Mar 2017 11:45:32 +0100 [thread overview]
Message-ID: <1490352343-20075-18-git-send-email-jinpu.wangl@profitbricks.com> (raw)
In-Reply-To: <1490352343-20075-1-git-send-email-jinpu.wangl-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
From: Jack Wang <jinpu.wang-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
Signed-off-by: Jack Wang <jinpu.wang-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
Signed-off-by: Kleber Souza <kleber.souza-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
Signed-off-by: Danil Kipnis <danil.kipnis-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
Signed-off-by: Roman Pen <roman.penyaev-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
---
drivers/block/ibnbd_client/ibnbd_clt.h | 231 +++++++++++++++++++++++++++++++++
1 file changed, 231 insertions(+)
create mode 100644 drivers/block/ibnbd_client/ibnbd_clt.h
diff --git a/drivers/block/ibnbd_client/ibnbd_clt.h b/drivers/block/ibnbd_client/ibnbd_clt.h
new file mode 100644
index 0000000..3f0db78
--- /dev/null
+++ b/drivers/block/ibnbd_client/ibnbd_clt.h
@@ -0,0 +1,231 @@
+/*
+ * InfiniBand Network Block Driver
+ *
+ * Copyright (c) 2014 - 2017 ProfitBricks GmbH. All rights reserved.
+ * Authors: Fabian Holler < mail-99BIx50xQYGELgA04lAiVw@public.gmane.org>
+ * Jack Wang <jinpu.wang-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
+ * Kleber Souza <kleber.souza-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
+ * Danil Kipnis <danil.kipnis-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
+ * Roman Pen <roman.penyaev-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
+ * Milind Dumbare <Milind.dumbare-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * substantially similar to the "NO WARRANTY" disclaimer below
+ * ("Disclaimer") and any redistribution must be conditioned upon
+ * including a substantially similar Disclaimer requirement for further
+ * binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ * of any contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+#ifndef _IBNBD_CLT_H
+#define _IBNBD_CLT_H
+#include <linux/blkdev.h>
+#include <linux/wait.h> /* for wait_queue_head_t */
+#include <linux/in.h> /* for sockaddr_in */
+#include <linux/inet.h> /* for sockaddr_in */
+#include <linux/blk-mq.h>
+#include "ibnbd_clt_log.h"
+#include "../ibnbd_inc/ibnbd.h"
+#include "../ibnbd_inc/ibnbd-proto.h" /* ibnbd protocol messages */
+#include <rdma/ibtrs_clt.h> /* for ibtrs api */
+#include <rdma/ibtrs.h>
+
+#define IP_PREFIX "ip:"
+#define IP_PREFIX_LEN strlen(IP_PREFIX)
+#define GID_PREFIX "gid:"
+#define GID_PREFIX_LEN strlen(GID_PREFIX)
+
+#define BMAX_SEGMENTS 31
+#define RECONNECT_DELAY 30
+#define MAX_RECONNECTS -1
+
+enum ibnbd_dev_state {
+ DEV_STATE_INIT,
+ DEV_STATE_INIT_CLOSED,
+ DEV_STATE_CLOSED,
+ DEV_STATE_UNMAPPED,
+ DEV_STATE_OPEN
+};
+
+enum ibnbd_queue_mode {
+ BLK_MQ,
+ BLK_RQ
+};
+
+struct ibnbd_iu {
+ struct request *rq;
+ struct ibtrs_tag *tag;
+ struct ibnbd_dev *dev;
+ struct ibnbd_msg_io msg;
+ int errno;
+ struct scatterlist sglist[BMAX_SEGMENTS];
+};
+
+struct ibnbd_cpu_qlist {
+ struct list_head requeue_list;
+ spinlock_t requeue_lock;
+ unsigned int cpu;
+};
+
+enum sess_state {
+ SESS_STATE_READY,
+ SESS_STATE_DISCONNECTED,
+ SESS_STATE_DESTROYED,
+};
+
+struct ibnbd_session {
+ struct list_head list;
+ struct ibtrs_session *sess;
+ struct ibnbd_cpu_qlist __percpu
+ *cpu_queues;
+ DECLARE_BITMAP(cpu_queues_bm, NR_CPUS);
+ int __percpu *cpu_rr; /* per-cpu var for CPU round-robin */
+ atomic_t busy;
+ int queue_depth;
+ u32 max_io_size;
+ struct blk_mq_tag_set tag_set;
+ struct mutex lock; /* protects state and devs_list */
+ struct list_head devs_list; /* list of struct ibnbd_dev */
+ struct kref refcount;
+ struct sockaddr_storage addr;
+ char str_addr[IBTRS_ADDRLEN];
+ char hostname[MAXHOSTNAMELEN];
+ enum sess_state state;
+ u8 ver; /* protocol version */
+ struct completion *sess_info_compl;
+};
+
+struct ibnbd_work {
+ struct work_struct work;
+ struct ibnbd_session *sess;
+};
+
+/**
+ * Submission queues.
+ */
+struct ibnbd_queue {
+ struct list_head requeue_list;
+ unsigned long in_list;
+ struct ibnbd_dev *dev;
+ struct blk_mq_hw_ctx *hctx;
+};
+
+struct ibnbd_dev {
+ struct list_head g_list;
+ struct ibnbd_session *sess;
+ struct request_queue *queue;
+ struct ibnbd_queue *hw_queues;
+ struct delayed_work rq_delay_work;
+ u32 device_id;
+ u32 clt_device_id;
+ struct completion *open_compl; /* completion for open msg */
+ int open_errno;
+ struct mutex lock;
+ enum ibnbd_dev_state dev_state;
+ enum ibnbd_queue_mode queue_mode;
+ enum ibnbd_io_mode io_mode; /* user requested */
+ enum ibnbd_io_mode remote_io_mode; /* server really used */
+ /* local Idr index - used to track minor number allocations. */
+ char pathname[NAME_MAX];
+ enum ibnbd_access_mode access_mode;
+ bool read_only;
+ bool rotational;
+ u32 max_hw_sectors;
+ u32 max_write_same_sectors;
+ u32 max_discard_sectors;
+ u32 discard_zeroes_data;
+ u32 discard_granularity;
+ u32 discard_alignment;
+ u16 secure_discard;
+ u16 physical_block_size;
+ u16 logical_block_size;
+ u16 max_segments;
+ size_t nsectors;
+ u64 size; /* device size in bytes */
+ struct list_head list;
+ struct gendisk *gd;
+ struct kobject kobj;
+ char blk_symlink_name[NAME_MAX];
+ struct completion *close_compl;
+ atomic_t refcount;
+};
+
+static inline const char *ibnbd_queue_mode_str(enum ibnbd_queue_mode mode)
+{
+ switch (mode) {
+ case BLK_RQ:
+ return "rq";
+ case BLK_MQ:
+ return "mq";
+ default:
+ return "unknown";
+ }
+}
+
+int ibnbd_close_device(struct ibnbd_dev *dev, bool force);
+struct ibnbd_session *ibnbd_create_session(const struct sockaddr_storage *addr);
+struct ibnbd_session *ibnbd_clt_find_sess(const struct sockaddr_storage *addr);
+void ibnbd_clt_sess_release(struct kref *ref);
+struct ibnbd_dev *ibnbd_client_add_device(struct ibnbd_session *sess,
+ const char *pathname,
+ enum ibnbd_access_mode access_mode,
+ enum ibnbd_queue_mode queue_mode,
+ enum ibnbd_io_mode io_mode);
+void ibnbd_destroy_gen_disk(struct ibnbd_dev *dev);
+int ibnbd_addr_to_str(const struct sockaddr_storage *addr,
+ char *buf, size_t len);
+bool ibnbd_clt_dev_is_open(struct ibnbd_dev *dev);
+bool ibnbd_clt_dev_is_mapped(const char *pathname);
+int open_remote_device(struct ibnbd_dev *dev);
+
+const char *ibnbd_clt_get_io_mode(const struct ibnbd_dev *dev);
+
+#define ERR_DEVS(sess, fmt, ...) \
+({ struct ibnbd_dev *dev; \
+ \
+ mutex_lock(&sess->lock); \
+ list_for_each_entry(dev, &sess->devs_list, list) \
+ pr_err("ibnbd L%d <%s@%s> ERR:" fmt, \
+ __LINE__, dev->pathname, dev->sess->str_addr,\
+ ##__VA_ARGS__); \
+ mutex_unlock(&sess->lock); \
+})
+
+#define INFO_DEVS(sess, fmt, ...) \
+({ struct ibnbd_dev *dev; \
+ \
+ mutex_lock(&sess->lock); \
+ list_for_each_entry(dev, &sess->devs_list, list) \
+ pr_info("ibnbd <%s@%s> ERR:" fmt, \
+ dev->pathname, dev->sess->str_addr,\
+ ##__VA_ARGS__); \
+ mutex_unlock(&sess->lock); \
+})
+#endif /* _IBNBD_CLT_H */
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-03-24 10:45 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-24 10:45 [RFC PATCH 00/28] INFINIBAND NETWORK BLOCK DEVICE (IBNBD) Jack Wang
2017-03-24 10:45 ` [PATCH 02/28] ibtrs: add header for log MICROs shared between ibtrs_client and ibtrs_server Jack Wang
2017-03-24 10:45 ` [PATCH 03/28] ibtrs_lib: add common functions shared by client and server Jack Wang
2017-03-24 10:45 ` [PATCH 04/28] ibtrs_clt: add header file for exported interface Jack Wang
2017-03-24 10:45 ` [PATCH 06/28] ibtrs_clt: add header file shared only in ibtrs_client Jack Wang
2017-03-24 10:45 ` [PATCH 07/28] ibtrs_clt: add files for sysfs interface Jack Wang
2017-03-24 10:45 ` [PATCH 08/28] ibtrs_clt: add Makefile and Kconfig Jack Wang
[not found] ` <1490352343-20075-9-git-send-email-jinpu.wangl-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
2017-03-25 5:51 ` kbuild test robot
2017-03-25 6:55 ` kbuild test robot
2017-03-24 10:45 ` [PATCH 10/28] ibtrs_srv: add main functionality for ibtrs_server Jack Wang
2017-03-24 10:45 ` [PATCH 12/28] ibtrs_srv: add sysfs interface Jack Wang
2017-03-24 10:45 ` [PATCH 14/28] ibnbd: add headers shared by ibnbd_client and ibnbd_server Jack Wang
2017-03-24 10:45 ` [PATCH 19/28] ibnbd_clt: add log helpers Jack Wang
[not found] ` <1490352343-20075-1-git-send-email-jinpu.wangl-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
2017-03-24 10:45 ` [PATCH 01/28] ibtrs: add header shared between ibtrs_client and ibtrs_server Jack Wang
2017-03-24 12:35 ` Johannes Thumshirn
[not found] ` <20170324123546.GG3571-qw2SdCWA0PpjqqEj2zc+bA@public.gmane.org>
2017-03-24 12:54 ` Jinpu Wang
[not found] ` <CAMGffEn7Q+Tchaj4RXV1zMk0MzHqGRv=0W5Vd1G_-GvZaG8tPA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-24 14:31 ` Johannes Thumshirn
2017-03-24 14:35 ` Jinpu Wang
2017-03-24 10:45 ` [PATCH 05/28] ibtrs_clt: main functionality of ibtrs_client Jack Wang
2017-03-24 10:45 ` [PATCH 09/28] ibtrs_srv: add header file for exported interface Jack Wang
2017-03-24 10:45 ` [PATCH 11/28] ibtrs_srv: add header shared in ibtrs_server Jack Wang
2017-03-24 10:45 ` [PATCH 13/28] ibtrs_srv: add Makefile and Kconfig Jack Wang
2017-03-25 7:55 ` kbuild test robot
[not found] ` <1490352343-20075-14-git-send-email-jinpu.wangl-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
2017-03-25 10:54 ` kbuild test robot
2017-03-24 10:45 ` [PATCH 15/28] ibnbd: add shared library functions Jack Wang
2017-03-24 10:45 ` [PATCH 16/28] ibnbd_clt: add main functionality of ibnbd_client Jack Wang
2017-03-24 10:45 ` Jack Wang [this message]
2017-03-24 10:45 ` [PATCH 18/28] ibnbd_clt: add sysfs interface Jack Wang
2017-03-24 10:45 ` [PATCH 20/28] ibnbd_clt: add Makefile and Kconfig Jack Wang
2017-03-25 8:38 ` kbuild test robot
2017-03-25 11:17 ` kbuild test robot
2017-03-24 10:45 ` [PATCH 21/28] ibnbd_srv: add header shared in ibnbd_server Jack Wang
2017-03-24 10:45 ` [PATCH 23/28] ibnbd_srv: add abstraction for submit IO to file or block device Jack Wang
2017-03-24 10:45 ` [PATCH 25/28] ibnbd_srv: add sysfs interface Jack Wang
2017-03-24 12:15 ` [RFC PATCH 00/28] INFINIBAND NETWORK BLOCK DEVICE (IBNBD) Johannes Thumshirn
[not found] ` <20170324121526.GF3571-qw2SdCWA0PpjqqEj2zc+bA@public.gmane.org>
2017-03-24 12:46 ` Jinpu Wang
2017-03-24 12:48 ` Johannes Thumshirn
2017-03-24 13:31 ` Bart Van Assche
[not found] ` <1490362271.2516.4.camel-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2017-03-24 14:24 ` Jinpu Wang
2017-03-27 2:20 ` Sagi Grimberg
2017-03-27 10:21 ` Jinpu Wang
[not found] ` <CAMGffEmgsP9GjQQp63matwxpzJT+SZu+VPU+Co-h99b8D5g5Zw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-28 14:17 ` Roman Penyaev
2017-03-24 10:45 ` [PATCH 22/28] ibnbd_srv: add main functionality Jack Wang
2017-03-24 10:45 ` [PATCH 24/28] ibnbd_srv: add log helpers Jack Wang
2017-03-24 10:45 ` [PATCH 26/28] ibnbd_srv: add Makefile and Kconfig Jack Wang
[not found] ` <1490352343-20075-27-git-send-email-jinpu.wangl-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
2017-03-25 9:27 ` kbuild test robot
2017-03-24 10:45 ` [PATCH 27/28] ibnbd: add doc for how to use ibnbd and sysfs interface Jack Wang
2017-03-25 7:44 ` kbuild test robot
2017-03-24 10:45 ` [PATCH 28/28] MAINTRAINERS: Add maintainer for IBNBD/IBTRS Jack Wang
2017-03-24 14:20 ` [RFC PATCH 00/28] INFINIBAND NETWORK BLOCK DEVICE (IBNBD) Steve Wise
2017-03-24 14:37 ` Jinpu Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1490352343-20075-18-git-send-email-jinpu.wangl@profitbricks.com \
--to=jinpu.wang-eikl63zcoxah+58jc4qpia@public.gmane.org \
--cc=Milind.dumbare-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=axboe-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org \
--cc=danil.kipnis-EIkl63zCoXaH+58JC4qpiA@public.gmane.org \
--cc=dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=hch-jcswGhMUV9g@public.gmane.org \
--cc=kleber.souza-EIkl63zCoXaH+58JC4qpiA@public.gmane.org \
--cc=linux-block-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mail-99BIx50xQYGELgA04lAiVw@public.gmane.org \
--cc=roman.penyaev-EIkl63zCoXaH+58JC4qpiA@public.gmane.org \
--cc=yun.wang-EIkl63zCoXaH+58JC4qpiA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).