InfiniBand Transport (IBTRS) and Network Block Device (IBNBD)
Subsystems (2)
PATCH 16/24 ibnbd: client: main functionality
In reply to Roman PenThis is main functionality of ibnbd-client module, which provides interface to map remote device as local block device /dev/ibnbd<N> and feeds IBTRS with IO requests.
--- drivers/block/ibnbd/ibnbd-clt.c | 1959 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 1959 insertions(+)
drivers/block/ibnbd/ibnbd-clt.c new file +1959 -0
@@ -0,0 +1,1959 @@ +/* +* InfiniBand Network Block Driver +* +* Copyright (c) 2014 - 2017 ProfitBricks GmbH. All rights reserved. +* Authors: Fabian Holler <[email protected]> +* Jack Wang <[email protected]> +* Kleber Souza <[email protected]> +* Danil Kipnis <[email protected]> +* Roman Penyaev <[email protected]> +* Milind Dumbare <[email protected]> +* +* Copyright (c) 2017 - 2018 ProfitBricks GmbH. All rights reserved. +* Authors: Danil Kipnis <[email protected]> +* Roman Penyaev <[email protected]> +* +* 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; either version 2 +* of the License, or (at your option) any later version. +* +* 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#undef pr_fmt +#define pr_fmt (fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt + +#include <linux/module.h> +#include <linux/blkdev.h> +#include <linux/hdreg.h> +#include <linux/scatterlist.h> +#include <linux/idr.h> + +#include "ibnbd-clt.h" + +MODULE_AUTHOR ("[email protected]" ); +MODULE_DESCRIPTION ("InfiniBand Network Block Device Client" ); +MODULE_VERSION (IBNBD_VER_STRING ); +MODULE_LICENSE ("GPL" ); + +static int ibnbd_client_major; +static DEFINE_IDA (index_ida); +static DEFINE_MUTEX (ida_lock); +static DEFINE_MUTEX (sess_lock); +static LIST_HEAD (sess_list); + +static bool softirq_enable; +module_param (softirq_enable, bool,0444 ); +MODULE_PARM_DESC (softirq_enable,"finish request in softirq_fn." +" (default: 0)" ); +/* +* Maximum number of partitions an instance can have. +* 6 bits = 64 minors = 63 partitions (one minor is used for the device itself) +*/ +#define IBNBD_PART_BITS 6 +#define KERNEL_SECTOR_SIZE 512 + +static inline bool ibnbd_clt_get_sess (struct ibnbd_clt_session *sess) +{ +return refcount_inc_not_zero (&sess->refcount); +} + +static void free_sess (struct ibnbd_clt_session *sess); + +static void ibnbd_clt_put_sess (struct ibnbd_clt_session *sess) +{ +might_sleep (); + +if (refcount_dec_and_test (&sess->refcount)) +free_sess (sess); +} + +static inline bool ibnbd_clt_dev_is_mapped (struct ibnbd_clt_dev *dev) +{ +return dev->dev_state ==DEV_STATE_MAPPED ; +} + +static void ibnbd_clt_put_dev (struct ibnbd_clt_dev *dev) +{ +might_sleep (); + +if (refcount_dec_and_test (&dev->refcount)) { +mutex_lock (&ida_lock); +ida_simple_remove (&index_ida, dev->clt_device_id); +mutex_unlock (&ida_lock); +kfree (dev->hw_queues); +ibnbd_clt_put_sess (dev->sess); +kfree (dev); + } +} + +static inline bool ibnbd_clt_get_dev (struct ibnbd_clt_dev *dev) +{ +return refcount_inc_not_zero (&dev->refcount); +} + +static void ibnbd_clt_set_dev_attr (struct ibnbd_clt_dev *dev, +const struct ibnbd_msg_open_rsp *rsp) +{ +struct ibnbd_clt_session *sess = dev->sess; + + dev->device_id =le32_to_cpu (rsp->device_id); + dev->nsectors =le64_to_cpu (rsp->nsectors); + dev->logical_block_size =le16_to_cpu (rsp->logical_block_size); + dev->physical_block_size =le16_to_cpu (rsp->physical_block_size); + dev->max_write_same_sectors =le32_to_cpu (rsp->max_write_same_sectors); + dev->max_discard_sectors =le32_to_cpu (rsp->max_discard_sectors); + dev->discard_granularity =le32_to_cpu (rsp->discard_granularity); + dev->discard_alignment =le32_to_cpu (rsp->discard_alignment); + dev->secure_discard =le16_to_cpu (rsp->secure_discard); + dev->rotational = rsp->rotational; + dev->remote_io_mode = rsp->io_mode; + + dev->max_hw_sectors = sess->max_io_size / dev->logical_block_size; + dev->max_segments =BMAX_SEGMENTS ; + +if (dev->remote_io_mode ==IBNBD_BLOCKIO ) { + dev->max_hw_sectors =min_t (u32, dev->max_hw_sectors, +le32_to_cpu (rsp->max_hw_sectors)); + dev->max_segments =min_t (u16, dev->max_segments, +le16_to_cpu (rsp->max_segments)); + } +} + +static int ibnbd_clt_revalidate_disk (struct ibnbd_clt_dev *dev, +size_t new_nsectors) +{ +int err =0 ; + +ibnbd_info (dev,"Device size changed from %zu to %zu sectors\n" , + dev->nsectors, new_nsectors); + dev->nsectors = new_nsectors; +set_capacity (dev->gd, + dev->nsectors * (dev->logical_block_size / +KERNEL_SECTOR_SIZE )); + err =revalidate_disk (dev->gd); +if (err) +ibnbd_err (dev,"Failed to change device size from" +" %zu to %zu, err: %d\n" , dev->nsectors, + new_nsectors, err); +return err; +} + +static int process_msg_open_rsp (struct ibnbd_clt_dev *dev, +struct ibnbd_msg_open_rsp *rsp) +{ +int err =0 ; + +mutex_lock (&dev->lock); +if (dev->dev_state ==DEV_STATE_UNMAPPED ) { +ibnbd_info (dev,"Ignoring Open-Response message from server for " +" unmapped device\n" ); + err = -ENOENT ; + goto out; + } +if (dev->dev_state ==DEV_STATE_MAPPED_DISCONNECTED ) { +u64 nsectors =le64_to_cpu (rsp->nsectors); + +/* +* If the device was remapped and the size changed in the +* meantime we need to revalidate it +*/ +if (dev->nsectors != nsectors) +ibnbd_clt_revalidate_disk (dev, nsectors); +ibnbd_info (dev,"Device online, device remapped successfully\n" ); + } +ibnbd_clt_set_dev_attr (dev, rsp); + dev->dev_state =DEV_STATE_MAPPED ; + +out: +mutex_unlock (&dev->lock); + +return err; +} + +int ibnbd_clt_resize_disk (struct ibnbd_clt_dev *dev,size_t newsize) +{ +int ret =0 ; + +mutex_lock (&dev->lock); +if (dev->dev_state !=DEV_STATE_MAPPED ) { +pr_err ("Failed to set new size of the device, " +"device is not opened\n" ); + ret = -ENOENT ; + goto out; + } + ret =ibnbd_clt_revalidate_disk (dev, newsize); + +out: +mutex_unlock (&dev->lock); + +return ret; +} + +static void ibnbd_blk_delay_work (struct work_struct *work) +{ +struct ibnbd_clt_dev *dev; + + dev = container_of(work, struct ibnbd_clt_dev, rq_delay_work.work); +spin_lock_irq (dev->queue->queue_lock); +blk_start_queue (dev->queue); +spin_unlock_irq (dev->queue->queue_lock); +} + +/** +* What is the difference between this and original blk_delay_queue() ? +* Here the stop queue flag is cleared, so we are like MQ. +*/ +static void ibnbd_blk_delay_queue (struct ibnbd_clt_dev *dev, +unsigned long msecs) +{ +int cpu =get_cpu (); + +kblockd_schedule_delayed_work_on (cpu, &dev->rq_delay_work, +msecs_to_jiffies (msecs)); +put_cpu (); +} + +static inline void ibnbd_clt_dev_requeue (struct ibnbd_queue *q) +{ +struct ibnbd_clt_dev *dev = q->dev; + +if (dev->queue_mode ==BLK_MQ ) { +if (WARN_ON (!q->hctx)) +return ; +blk_mq_delay_queue (q->hctx,0 ); + }else if (dev->queue_mode ==BLK_RQ ) { +ibnbd_blk_delay_queue (q->dev,0 ); + }else { +WARN (1 ,"We support requeueing only for RQ or MQ" ); + } +} + +enum { + IBNBD_DELAY_10ms =10 , +IBNBD_DELAY_IFBUSY =-1 , +}; + +/** +* ibnbd_get_cpu_qlist() - finds a list with HW queues to be requeued +* +* Description: +* Each CPU has a list of HW queues, which needs to be requeed. If a list +* is not empty - it is marked with a bit. This function finds first +* set bit in a bitmap and returns corresponding CPU list. +*/ +static struct ibnbd_cpu_qlist * +ibnbd_get_cpu_qlist (struct ibnbd_clt_session *sess,int cpu) +{ +int bit; + +/* First half */ + bit =find_next_bit (sess->cpu_queues_bm, nr_cpu_ids, cpu); +if (bit < nr_cpu_ids) { +return per_cpu_ptr (sess->cpu_queues, bit); + }else if (cpu !=0 ) { +/* Second half */ + bit =find_next_bit (sess->cpu_queues_bm, cpu,0 ); +if (bit < cpu) +return per_cpu_ptr (sess->cpu_queues, bit); + } + +return NULL ; +} + +static inline int nxt_cpu (int cpu) +{ +return (cpu +1 ) % nr_cpu_ids; +} + +/** +* ibnbd_requeue_if_needed() - requeue if CPU queue is marked as non empty +* +* Description: +* Each CPU has it's own list of HW queues, which should be requeued. +* Function finds such list with HW queues, takes a list lock, picks up +* the first HW queue out of the list and requeues it. +* +* Return: +* True if the queue was requeued, false otherwise. +* +* Context: +* Does not matter. +*/ +static inline bool ibnbd_requeue_if_needed (struct ibnbd_clt_session *sess) +{ +struct ibnbd_queue *q =NULL ; +struct ibnbd_cpu_qlist *cpu_q; +unsigned long flags; +int *cpup; + +/* +* To keep fairness and not to let other queues starve we always +* try to wake up someone else in round-robin manner. That of course +* increases latency but queues always have a chance to be executed. +*/ + cpup =get_cpu_ptr (sess->cpu_rr); +for (cpu_q =ibnbd_get_cpu_qlist (sess,nxt_cpu (*cpup)); cpu_q; + cpu_q =ibnbd_get_cpu_qlist (sess,nxt_cpu (cpu_q->cpu))) { +if (!spin_trylock_irqsave (&cpu_q->requeue_lock, flags)) +continue ; +if (likely (test_bit (cpu_q->cpu, sess->cpu_queues_bm))) { + q =list_first_entry_or_null (&cpu_q->requeue_list, +typeof (*q), requeue_list); +if (WARN_ON (!q)) + goto clear_bit; +list_del_init (&q->requeue_list); +clear_bit_unlock (0 , &q->in_list); + +if (list_empty (&cpu_q->requeue_list)) { +/* Clear bit if nothing is left */ +clear_bit: +clear_bit (cpu_q->cpu, sess->cpu_queues_bm); + } + } +spin_unlock_irqrestore (&cpu_q->requeue_lock, flags); + +if (q) +break ; + } + +/** +* Saves the CPU that is going to be requeued on the per-cpu var. Just +* incrementing it doesn't work because ibnbd_get_cpu_qlist() will +* always return the first CPU with something on the queue list when the +* value stored on the var is greater than the last CPU with something +* on the list. +*/ +if (cpu_q) + *cpup = cpu_q->cpu; +put_cpu_var (sess->cpu_rr); + +if (q) +ibnbd_clt_dev_requeue (q); + +return !!q; +} + +/** +* ibnbd_requeue_all_if_idle() - requeue all queues left in the list if +* session is idling (there are no requests in-flight). +* +* Description: +* This function tries to rerun all stopped queues if there are no +* requests in-flight anymore. This function tries to solve an obvious +* problem, when number of tags < than number of queues (hctx), which +* are stopped and put to sleep. If last tag, which has been just put, +* does not wake up all left queues (hctxs), IO requests hang forever. +* +* That can happen when all number of tags, say N, have been exhausted +* from one CPU, and we have many block devices per session, say M. +* Each block device has it's own queue (hctx) for each CPU, so eventually +* we can put that number of queues (hctxs) to sleep: M x nr_cpu_ids. +* If number of tags N < M x nr_cpu_ids finally we will get an IO hang. +* +* To avoid this hang last caller of ibnbd_put_tag() (last caller is the +* one who observes sess->busy == 0) must wake up all remaining queues. +* +* Context: +* Does not matter. +*/ +static inline void ibnbd_requeue_all_if_idle (struct ibnbd_clt_session *sess) +{ +bool requeued; + +do { + requeued =ibnbd_requeue_if_needed (sess); + }while (atomic_read (&sess->busy) ==0 && requeued); +} + +static struct ibtrs_tag *ibnbd_get_tag (struct ibnbd_clt_session *sess, +enum ibtrs_clt_con_type con_type, +int wait) +{ +struct ibtrs_tag *tag; + + tag =ibtrs_clt_get_tag (sess->ibtrs, con_type, + wait ?IBTRS_TAG_WAIT :IBTRS_TAG_NOWAIT ); +if (likely (tag)) +/* We have a subtle rare case here, when all tags can be +* consumed before busy counter increased. This is safe, +* because loser will get NULL as a tag, observe 0 busy +* counter and immediately restart the queue himself. +*/ +atomic_inc (&sess->busy); + +return tag; +} + +static void ibnbd_put_tag (struct ibnbd_clt_session *sess,struct ibtrs_tag *tag) +{ +ibtrs_clt_put_tag (sess->ibtrs, tag); +atomic_dec (&sess->busy); +/* Paired with ibnbd_clt_dev_add_to_requeue(). Decrement first +* and then check queue bits. +*/ +smp_mb__after_atomic (); +ibnbd_requeue_all_if_idle (sess); +} + +static struct ibnbd_iu *ibnbd_get_iu (struct ibnbd_clt_session *sess, +enum ibtrs_clt_con_type con_type, +int wait) +{ +struct ibnbd_iu *iu; +struct ibtrs_tag *tag; + + tag =ibnbd_get_tag (sess, con_type, + wait ?IBTRS_TAG_WAIT :IBTRS_TAG_NOWAIT ); +if (unlikely (!tag)) +return NULL ; + iu =ibtrs_tag_to_pdu (tag); + iu->tag = tag;/* yes, ibtrs_tag_from_pdu() can be nice here, +* but also we have to think about MQ mode +*/ + +return iu; +} + +static void ibnbd_put_iu (struct ibnbd_clt_session *sess,struct ibnbd_iu *iu) +{ +ibnbd_put_tag (sess, iu->tag); +} + +static void ibnbd_softirq_done_fn (struct request *rq) +{ +struct ibnbd_clt_dev *dev = rq->rq_disk->private_data; +struct ibnbd_clt_session *sess = dev->sess; +struct ibnbd_iu *iu; + +switch (dev->queue_mode) { +case BLK_MQ : + iu =blk_mq_rq_to_pdu (rq); +ibnbd_put_tag (sess, iu->tag); +blk_mq_end_request (rq, iu->status); +break ; +case BLK_RQ : + iu = rq->special; +blk_end_request_all (rq, iu->status); +break ; +default : +WARN (true,"dev->queue_mode , contains unexpected" +" value: %d. Memory Corruption? Inflight I/O stalled!\n" , + dev->queue_mode); +return ; + } +} + +static void msg_io_conf (void *priv,int errno) +{ +struct ibnbd_iu *iu = (struct ibnbd_iu *)priv; +struct ibnbd_clt_dev *dev = iu->dev; +struct request *rq = iu->rq; + + iu->status = errno ?BLK_STS_IOERR :BLK_STS_OK ; + +switch (dev->queue_mode) { +case BLK_MQ : +if (softirq_enable) { +blk_mq_complete_request (rq); + }else { +ibnbd_put_tag (dev->sess, iu->tag); +blk_mq_end_request (rq, iu->status); + } +break ; +case BLK_RQ : +if (softirq_enable) +blk_complete_request (rq); +else +blk_end_request_all (rq, iu->status); +break ; +default : +WARN (true,"dev->queue_mode , contains unexpected" +" value: %d. Memory Corruption? Inflight I/O stalled!\n" , + dev->queue_mode); +return ; + } + +if (errno) +ibnbd_info_rl (dev,"%s I/O failed with err: %d\n" , +rq_data_dir (rq) ==READ ?"read" :"write" , + errno); +} + +static void init_iu_comp (struct ibnbd_iu *iu,struct ibnbd_iu_comp *comp) +{ +init_waitqueue_head (&comp->wait); + comp->errno =INT_MAX ; + iu->comp = comp; +} + +static void deinit_iu_comp (struct ibnbd_iu *iu) +{ + iu->comp =NULL ; +} + +static void wake_up_iu_comp (struct ibnbd_iu *iu,int errno) +{ +struct ibnbd_iu_comp *comp = iu->comp; + +if (comp) { + comp->errno = errno; +wake_up (&comp->wait); +deinit_iu_comp (iu); + } +} + +static void wait_iu_comp (struct ibnbd_iu_comp *comp) +{ +wait_event (comp->wait, comp->errno !=INT_MAX ); +} + +static void msg_conf (void *priv,int errno) +{ +struct ibnbd_iu *iu = (struct ibnbd_iu *)priv; + + iu->errno = errno; +schedule_work (&iu->work); +} + +enum { +NO_WAIT =0 , +WAIT =1 +}; + +static int send_usr_msg (struct ibtrs_clt *ibtrs,int dir, +struct ibnbd_iu *iu,struct kvec *vec,size_t nr, +size_t len,struct scatterlist *sg,unsigned int sg_len, +void (*conf)(struct work_struct *work), +int *errno,bool wait) +{ +struct ibnbd_iu_comp comp; +int err; + +if (wait) +init_iu_comp (iu, &comp); +INIT_WORK (&iu->work, conf); + err =ibtrs_clt_request (dir, msg_conf, ibtrs, iu->tag, + iu, vec, nr, len, sg, sg_len); +if (unlikely (err)) { +deinit_iu_comp (iu); + }else if (wait) { +wait_iu_comp (&comp); + *errno = comp.errno; + }else { + *errno =0 ; + } + +return err; +} + +static void msg_close_conf (struct work_struct *work) +{ + struct ibnbd_iu *iu = container_of(work, struct ibnbd_iu, work); +struct ibnbd_clt_dev *dev = iu->dev; + +wake_up_iu_comp (iu, iu->errno); +ibnbd_put_iu (dev->sess, iu); +ibnbd_clt_put_dev (dev); +} + +static int send_msg_close (struct ibnbd_clt_dev *dev,u32 device_id,bool wait) +{ +struct ibnbd_clt_session *sess = dev->sess; +struct ibnbd_msg_close msg; +struct ibnbd_iu *iu; +struct kvec vec = { + .iov_base = &msg, + .iov_len =sizeof (msg) + }; +int err, errno; + + iu =ibnbd_get_iu (sess,IBTRS_USR_CON ,IBTRS_TAG_WAIT ); +if (unlikely (!iu)) +return -ENOMEM ; + + iu->buf =NULL ; + iu->dev = dev; + +sg_mark_end (&iu->sglist[0 ]); + + msg.hdr.type =cpu_to_le16 (IBNBD_MSG_CLOSE ); + msg.device_id =cpu_to_le32 (device_id); + +ibnbd_clt_get_dev (dev); + err =send_usr_msg (sess->ibtrs,WRITE , iu, &vec,1 ,0 ,NULL ,0 , + msg_close_conf, &errno, wait); +if (unlikely (err)) { +ibnbd_clt_put_dev (dev); +ibnbd_put_iu (sess, iu); + }else { + err = errno; + } + +return err; +} + +static void msg_open_conf (struct work_struct *work) +{ + struct ibnbd_iu *iu = container_of(work, struct ibnbd_iu, work); +struct ibnbd_msg_open_rsp *rsp = iu->buf; +struct ibnbd_clt_dev *dev = iu->dev; +int errno = iu->errno; + +if (errno) { +ibnbd_err (dev,"Opening failed, server responded: %d\n" , errno); + }else { + errno =process_msg_open_rsp (dev, rsp); +if (unlikely (errno)) { +u32 device_id =le32_to_cpu (rsp->device_id); +/* +* If server thinks its fine, but we fail to process +* then be nice and send a close to server. +*/ + (void )send_msg_close (dev, device_id,NO_WAIT ); + } + } +kfree (rsp); +wake_up_iu_comp (iu, errno); +ibnbd_put_iu (dev->sess, iu); +ibnbd_clt_put_dev (dev); +} + +static void msg_sess_info_conf (struct work_struct *work) +{ + struct ibnbd_iu *iu = container_of(work, struct ibnbd_iu, work); +struct ibnbd_msg_sess_info_rsp *rsp = iu->buf; +struct ibnbd_clt_session *sess = iu->sess; + +if (likely (!iu->errno)) + sess->ver =min_t (u8, rsp->ver,IBNBD_VER_MAJOR ); + +kfree (rsp); +wake_up_iu_comp (iu, iu->errno); +ibnbd_put_iu (sess, iu); +ibnbd_clt_put_sess (sess); +} + +static int send_msg_open (struct ibnbd_clt_dev *dev,bool wait) +{ +struct ibnbd_clt_session *sess = dev->sess; +struct ibnbd_msg_open_rsp *rsp; +struct ibnbd_msg_open msg; +struct ibnbd_iu *iu; +struct kvec vec = { + .iov_base = &msg, + .iov_len =sizeof (msg) + }; +int err, errno; + + rsp =kzalloc (sizeof (*rsp),GFP_KERNEL ); +if (unlikely (!rsp)) +return -ENOMEM ; + + iu =ibnbd_get_iu (sess,IBTRS_USR_CON ,IBTRS_TAG_WAIT ); +if (unlikely (!iu)) { +kfree (rsp); +return -ENOMEM ; + } + + iu->buf = rsp; + iu->dev = dev; + +sg_init_one (iu->sglist, rsp,sizeof (*rsp)); + + msg.hdr.type =cpu_to_le16 (IBNBD_MSG_OPEN ); + msg.access_mode = dev->access_mode; + msg.io_mode = dev->io_mode; +strlcpy (msg.dev_name, dev->pathname,sizeof (msg.dev_name)); + +ibnbd_clt_get_dev (dev); + err =send_usr_msg (sess->ibtrs,READ , iu, + &vec,1 ,sizeof (*rsp), iu->sglist,1 , + msg_open_conf, &errno, wait); +if (unlikely (err)) { +ibnbd_clt_put_dev (dev); +ibnbd_put_iu (sess, iu); +kfree (rsp); + }else { + err = errno; + } + +return err; +} + +static int send_msg_sess_info (struct ibnbd_clt_session *sess,bool wait) +{ +struct ibnbd_msg_sess_info_rsp *rsp; +struct ibnbd_msg_sess_info msg; +struct ibnbd_iu *iu; +struct kvec vec = { + .iov_base = &msg, + .iov_len =sizeof (msg) + }; +int err, errno; + + rsp =kzalloc (sizeof (*rsp),GFP_KERNEL ); +if (unlikely (!rsp)) +return -ENOMEM ; + + iu =ibnbd_get_iu (sess,IBTRS_USR_CON ,IBTRS_TAG_WAIT ); +if (unlikely (!iu)) { +kfree (rsp); +return -ENOMEM ; + } + + iu->buf = rsp; + iu->sess = sess; + +sg_init_one (iu->sglist, rsp,sizeof (*rsp)); + + msg.hdr.type =cpu_to_le16 (IBNBD_MSG_SESS_INFO ); + msg.ver =IBNBD_VER_MAJOR ; + +ibnbd_clt_get_sess (sess); + err =send_usr_msg (sess->ibtrs,READ , iu, + &vec,1 ,sizeof (*rsp), iu->sglist,1 , + msg_sess_info_conf, &errno, wait); +if (unlikely (err)) { +ibnbd_clt_put_sess (sess); +ibnbd_put_iu (sess, iu); +kfree (rsp); + }else { + err = errno; + } + +return err; +} + +static void set_dev_states_to_disconnected (struct ibnbd_clt_session *sess) +{ +struct ibnbd_clt_dev *dev; + +mutex_lock (&sess->lock); +list_for_each_entry (dev, &sess->devs_list, list) { +ibnbd_err (dev,"Device disconnected.\n" ); + +mutex_lock (&dev->lock); +if (dev->dev_state ==DEV_STATE_MAPPED ) + dev->dev_state =DEV_STATE_MAPPED_DISCONNECTED ; +mutex_unlock (&dev->lock); + } +mutex_unlock (&sess->lock); +} + +static void remap_devs (struct ibnbd_clt_session *sess) +{ +struct ibnbd_clt_dev *dev; +struct ibtrs_attrs attrs; +int err; + +/* +* Careful here: we are called from IBTRS link event directly, +* thus we can't send any IBTRS request and wait for response +* or IBTRS will not be able to complete request with failure +* if something goes wrong (failing of outstanding requests +* happens exactly from the context where we are blocking now). +* +* So to avoid deadlocks each usr message sent from here must +* be asynchronous. +*/ + + err =send_msg_sess_info (sess,NO_WAIT ); +if (unlikely (err)) { +pr_err ("send_msg_sess_info(\"%s\"): %d\n" , sess->sessname, err); +return ; + } + +ibtrs_clt_query (sess->ibtrs, &attrs); +mutex_lock (&sess->lock); + sess->max_io_size = attrs.max_io_size; + +list_for_each_entry (dev, &sess->devs_list, list) { +bool skip; + +mutex_lock (&dev->lock); + skip = (dev->dev_state ==DEV_STATE_INIT ); +mutex_unlock (&dev->lock); +if (skip) +/* +* When device is establishing connection for the first +* time - do not remap, it will be closed soon. +*/ +continue ; + +ibnbd_info (dev,"session reconnected, remapping device\n" ); + err =send_msg_open (dev,NO_WAIT ); +if (unlikely (err)) { +ibnbd_err (dev,"send_msg_open(): %d\n" , err); +break ; + } + } +mutex_unlock (&sess->lock); +} + +static void ibnbd_clt_link_ev (void *priv,enum ibtrs_clt_link_ev ev) +{ +struct ibnbd_clt_session *sess = priv; + +switch (ev) { +case IBTRS_CLT_LINK_EV_DISCONNECTED : +set_dev_states_to_disconnected (sess); +break ; +case IBTRS_CLT_LINK_EV_RECONNECTED : +remap_devs (sess); +break ; +default : +pr_err ("Unknown session event received (%d), session: %s\n" , + ev, sess->sessname); + } +} + +static void ibnbd_init_cpu_qlists (struct ibnbd_cpu_qlist __percpu *cpu_queues) +{ +unsigned int cpu; +struct ibnbd_cpu_qlist *cpu_q; + +for_each_possible_cpu (cpu) { + cpu_q =per_cpu_ptr (cpu_queues, cpu); + + cpu_q->cpu = cpu; +INIT_LIST_HEAD (&cpu_q->requeue_list); +spin_lock_init (&cpu_q->requeue_lock); + } +} + +static struct blk_mq_ops ibnbd_mq_ops; +static int setup_mq_tags (struct ibnbd_clt_session *sess) +{ +struct blk_mq_tag_set *tags = &sess->tag_set; + +memset (tags,0 ,sizeof (*tags)); + tags->ops = &ibnbd_mq_ops; + tags->queue_depth = sess->queue_depth; + tags->numa_node =NUMA_NO_NODE ; + tags->flags =BLK_MQ_F_SHOULD_MERGE | +BLK_MQ_F_SG_MERGE | +BLK_MQ_F_TAG_SHARED ; + tags->cmd_size =sizeof (struct ibnbd_iu ); + tags->nr_hw_queues =num_online_cpus (); + +return blk_mq_alloc_tag_set (tags); +} + +static void destroy_mq_tags (struct ibnbd_clt_session *sess) +{ +blk_mq_free_tag_set (&sess->tag_set); +} + +static inline void wake_up_ibtrs_waiters (struct ibnbd_clt_session *sess) +{ +/* paired with rmb() in wait_for_ibtrs_connection() */ +smp_wmb (); + sess->ibtrs_ready = true; +wake_up_all (&sess->ibtrs_waitq); +} + +static void close_ibtrs (struct ibnbd_clt_session *sess) +{ +might_sleep (); + +if (!IS_ERR_OR_NULL (sess->ibtrs)) { +ibtrs_clt_close (sess->ibtrs); + sess->ibtrs =NULL ; +wake_up_ibtrs_waiters (sess); + } +} + +static void free_sess (struct ibnbd_clt_session *sess) +{ +WARN_ON (!list_empty (&sess->devs_list)); + +might_sleep (); + +close_ibtrs (sess); +destroy_mq_tags (sess); +if (!list_empty (&sess->list)) { +mutex_lock (&sess_lock); +list_del (&sess->list); +mutex_unlock (&sess_lock); + } +free_percpu (sess->cpu_queues); +free_percpu (sess->cpu_rr); +kfree (sess); +} + +static struct ibnbd_clt_session *alloc_sess (const char *sessname, +const struct ibtrs_addr *paths, +size_t path_cnt) +{ +struct ibnbd_clt_session *sess; +int err, cpu; + + sess =kzalloc_node (sizeof (*sess),GFP_KERNEL ,NUMA_NO_NODE ); +if (unlikely (!sess)) { +pr_err ("Failed to create session %s," +" allocating session struct failed\n" , sessname); +return ERR_PTR (-ENOMEM ); + } +strlcpy (sess->sessname, sessname,sizeof (sess->sessname)); +atomic_set (&sess->busy,0 ); +mutex_init (&sess->lock); +INIT_LIST_HEAD (&sess->devs_list); +INIT_LIST_HEAD (&sess->list); +bitmap_zero (sess->cpu_queues_bm,NR_CPUS ); +init_waitqueue_head (&sess->ibtrs_waitq); +refcount_set (&sess->refcount,1 ); + + sess->cpu_queues = alloc_percpu(struct ibnbd_cpu_qlist); +if (unlikely (!sess->cpu_queues)) { +pr_err ("Failed to create session to %s," +" alloc of percpu var (cpu_queues) failed\n" , sessname); + err = -ENOMEM ; + goto err; + } +ibnbd_init_cpu_qlists (sess->cpu_queues); + +/** +* That is simple percpu variable which stores cpu indeces, which are +* incremented on each access. We need that for the sake of fairness +* to wake up queues in a round-robin manner. +*/ + sess->cpu_rr =alloc_percpu (int); +if (unlikely (!sess->cpu_rr)) { +pr_err ("Failed to create session %s," +" alloc of percpu var (cpu_rr) failed\n" , sessname); + err = -ENOMEM ; + goto err; + } +for_each_possible_cpu (cpu) + *per_cpu_ptr (sess->cpu_rr, cpu) = cpu; + +return sess; + +err: +free_sess (sess); + +return ERR_PTR (err); +} + +static int wait_for_ibtrs_connection (struct ibnbd_clt_session *sess) +{ +wait_event (sess->ibtrs_waitq, sess->ibtrs_ready); +/* paired with wmb() in wake_up_ibtrs_waiters() */ +smp_rmb (); +if (unlikely (IS_ERR_OR_NULL (sess->ibtrs))) +return -ECONNRESET ; + +return 0 ; +} + +static void wait_for_ibtrs_disconnection (struct ibnbd_clt_session *sess) +__releases(&sess_lock) +__acquires(&sess_lock) +{ +DEFINE_WAIT_FUNC (wait, autoremove_wake_function); + +prepare_to_wait (&sess->ibtrs_waitq, &wait,TASK_UNINTERRUPTIBLE ); +if (IS_ERR_OR_NULL (sess->ibtrs)) { +finish_wait (&sess->ibtrs_waitq, &wait); +return ; + } +mutex_unlock (&sess_lock); +/* After unlock session can be freed, so careful */ +schedule (); +mutex_lock (&sess_lock); +} + +static struct ibnbd_clt_session *__find_and_get_sess (const char *sessname) +__releases(&sess_lock) +__acquires(&sess_lock) +{ +struct ibnbd_clt_session *sess; +int err; + +again: +list_for_each_entry (sess, &sess_list, list) { +if (strcmp (sessname, sess->sessname)) +continue ; + +if (unlikely (sess->ibtrs_ready &&IS_ERR_OR_NULL (sess->ibtrs))) +/* +* No IBTRS connection, session is dying. +*/ +continue ; + +if (likely (ibnbd_clt_get_sess (sess))) { +/* +* Alive session is found, wait for IBTRS connection. +*/ +mutex_unlock (&sess_lock); + err =wait_for_ibtrs_connection (sess); +if (unlikely (err)) +ibnbd_clt_put_sess (sess); +mutex_lock (&sess_lock); + +if (unlikely (err)) +/* Session is dying, repeat the loop */ + goto again; + +return sess; + }else { +/* +* Ref is 0, session is dying, wait for IBTRS disconnect +* in order to avoid session names clashes. +*/ +wait_for_ibtrs_disconnection (sess); +/* +* IBTRS is disconnected and soon session will be freed, +* so repeat a loop. +*/ + goto again; + } + } + +return NULL ; +} + +static struct ibnbd_clt_session *find_and_get_sess (const char *sessname) +{ +struct ibnbd_clt_session *sess; + +mutex_lock (&sess_lock); + sess =__find_and_get_sess (sessname); +mutex_unlock (&sess_lock); + +return sess; +} + +static struct ibnbd_clt_session * +find_and_get_or_insert_sess (struct ibnbd_clt_session *sess) +{ +struct ibnbd_clt_session *found; + +mutex_lock (&sess_lock); + found =__find_and_get_sess (sess->sessname); +if (!found) +list_add (&sess->list, &sess_list); +mutex_unlock (&sess_lock); + +return found; +} + +static struct ibnbd_clt_session * +find_and_get_or_create_sess (const char *sessname, +const struct ibtrs_addr *paths, +size_t path_cnt) +{ +struct ibnbd_clt_session *sess, *found; +struct ibtrs_attrs attrs; +int err; + + sess =find_and_get_sess (sessname); +if (IS_ERR (sess) || sess) +/* Either success or error path */ +return sess; + + sess =alloc_sess (sessname, paths, path_cnt); +if (unlikely (IS_ERR (sess))) +return sess; + + found =find_and_get_or_insert_sess (sess); +if (IS_ERR (found) || found) { +/* Either success or error path */ +free_sess (sess); + +return found; + } +/* +* Nothing was found, establish ibtrs connection and proceed further. +*/ + sess->ibtrs =ibtrs_clt_open (sess, ibnbd_clt_link_ev, sessname, + paths, path_cnt,IBTRS_PORT , +sizeof (struct ibnbd_iu ), +RECONNECT_DELAY ,BMAX_SEGMENTS , +MAX_RECONNECTS ); +if (unlikely (IS_ERR (sess->ibtrs))) { + err =PTR_ERR (sess->ibtrs); + goto wake_up_and_put; + } +ibtrs_clt_query (sess->ibtrs, &attrs); + sess->max_io_size = attrs.max_io_size; + sess->queue_depth = attrs.queue_depth; + + err =setup_mq_tags (sess); +if (unlikely (err)) + goto close_ibtrs; + + err =send_msg_sess_info (sess,WAIT ); +if (unlikely (err)) + goto close_ibtrs; + +wake_up_ibtrs_waiters (sess); + +return sess; + +close_ibtrs: +close_ibtrs (sess); +put_sess: +ibnbd_clt_put_sess (sess); + +return ERR_PTR (err); + +wake_up_and_put: +wake_up_ibtrs_waiters (sess); + goto put_sess; +} + +static int ibnbd_client_open (struct block_device *block_device,fmode_t mode) +{ +struct ibnbd_clt_dev *dev = block_device->bd_disk->private_data; + +if (dev->read_only && (mode &FMODE_WRITE )) +return -EPERM ; + +if (dev->dev_state ==DEV_STATE_UNMAPPED || + !ibnbd_clt_get_dev (dev)) +return -EIO ; + +return 0 ; +} + +static void ibnbd_client_release (struct gendisk *gen,fmode_t mode) +{ +struct ibnbd_clt_dev *dev = gen->private_data; + +ibnbd_clt_put_dev (dev); +} + +static int ibnbd_client_getgeo (struct block_device *block_device, +struct hd_geometry *geo) +{ +u64 size; +struct ibnbd_clt_dev *dev; + + dev = block_device->bd_disk->private_data; + size = dev->size * (dev->logical_block_size /KERNEL_SECTOR_SIZE ); + geo->cylinders = (size & ~0x3f ) >>6 ;/* size/64 */ + geo->heads =4 ; + geo->sectors =16 ; + geo->start =0 ; + +return 0 ; +} + +static const struct block_device_operations ibnbd_client_ops = { + .owner =THIS_MODULE , + .open = ibnbd_client_open, + .release = ibnbd_client_release, + .getgeo = ibnbd_client_getgeo +}; + +static size_t ibnbd_clt_get_sg_size (struct scatterlist *sglist,u32 len) +{ +struct scatterlist *sg; +size_t tsize =0 ; +int i; + +for_each_sg (sglist, sg, len, i) + tsize += sg->length; +return tsize; +} + +static int ibnbd_client_xfer_request (struct ibnbd_clt_dev *dev, +struct request *rq, +struct ibnbd_iu *iu) +{ +struct ibtrs_clt *ibtrs = dev->sess->ibtrs; +struct ibtrs_tag *tag = iu->tag; +struct ibnbd_msg_io msg; +unsigned int sg_cnt; +struct kvec vec; +size_t size; +int err; + + iu->rq = rq; + iu->dev = dev; + msg.sector =cpu_to_le64 (blk_rq_pos (rq)); + msg.bi_size =cpu_to_le32 (blk_rq_bytes (rq)); + msg.rw =cpu_to_le32 (rq_to_ibnbd_flags (rq)); + + sg_cnt =blk_rq_map_sg (dev->queue, rq, iu->sglist); +if (sg_cnt ==0 ) +/* Do not forget to mark the end */ +sg_mark_end (&iu->sglist[0 ]); + + msg.hdr.type =cpu_to_le16 (IBNBD_MSG_IO ); + msg.device_id =cpu_to_le32 (dev->device_id); + + vec = (struct kvec ) { + .iov_base = &msg, + .iov_len =sizeof (msg) + }; + + size =ibnbd_clt_get_sg_size (iu->sglist, sg_cnt); + err =ibtrs_clt_request (rq_data_dir (rq), msg_io_conf, ibtrs, tag, + iu, &vec,1 , size, iu->sglist, sg_cnt); +if (unlikely (err)) { +ibnbd_err_rl (dev,"IBTRS failed to transfer IO, err: %d\n" , + err); +return err; + } + +return 0 ; +} + +/** +* ibnbd_clt_dev_add_to_requeue() - add device to requeue if session is busy +* +* Description: +* If session is busy, that means someone will requeue us when resources +* are freed. If session is not doing anything - device is not added to +* the list and @false is returned. +*/ +static inline bool ibnbd_clt_dev_add_to_requeue (struct ibnbd_clt_dev *dev, +struct ibnbd_queue *q) +{ +struct ibnbd_clt_session *sess = dev->sess; +struct ibnbd_cpu_qlist *cpu_q; +unsigned long flags; +bool added = true; +bool need_set; + + cpu_q =get_cpu_ptr (sess->cpu_queues); +spin_lock_irqsave (&cpu_q->requeue_lock, flags); + +if (likely (!test_and_set_bit_lock (0 , &q->in_list))) { +if (WARN_ON (!list_empty (&q->requeue_list))) + goto unlock; + + need_set = !test_bit (cpu_q->cpu, sess->cpu_queues_bm); +if (need_set) { +set_bit (cpu_q->cpu, sess->cpu_queues_bm); +/* Paired with ibnbd_put_tag(). Set a bit first +* and then observe the busy counter. +*/ +smp_mb__before_atomic (); + } +if (likely (atomic_read (&sess->busy))) { +list_add_tail (&q->requeue_list, &cpu_q->requeue_list); + }else { +/* Very unlikely, but possible: busy counter was +* observed as zero. Drop all bits and return +* false to restart the queue by ourselves. +*/ +if (need_set) +clear_bit (cpu_q->cpu, sess->cpu_queues_bm); +clear_bit_unlock (0 , &q->in_list); + added = false; + } + } +unlock: +spin_unlock_irqrestore (&cpu_q->requeue_lock, flags); +put_cpu_ptr (sess->cpu_queues); + +return added; +} + +static void ibnbd_clt_dev_kick_mq_queue (struct ibnbd_clt_dev *dev, +struct blk_mq_hw_ctx *hctx, +int delay) +{ +struct ibnbd_queue *q = hctx->driver_data; + +if (WARN_ON (dev->queue_mode !=BLK_MQ )) +return ; +blk_mq_stop_hw_queue (hctx); + +if (delay !=IBNBD_DELAY_IFBUSY ) +blk_mq_delay_queue (hctx, delay); +else if (unlikely (!ibnbd_clt_dev_add_to_requeue (dev, q))) +/* If session is not busy we have to restart +* the queue ourselves. +*/ +blk_mq_delay_queue (hctx, IBNBD_DELAY_10ms); +} + +static void ibnbd_clt_dev_kick_queue (struct ibnbd_clt_dev *dev,int delay) +{ +if (WARN_ON (dev->queue_mode !=BLK_RQ )) +return ; +blk_stop_queue (dev->queue); + +if (delay !=IBNBD_DELAY_IFBUSY ) +ibnbd_blk_delay_queue (dev, delay); +else if (unlikely (!ibnbd_clt_dev_add_to_requeue (dev, dev->hw_queues))) +/* If session is not busy we have to restart +* the queue ourselves. +*/ +ibnbd_blk_delay_queue (dev, IBNBD_DELAY_10ms); +} + +static blk_status_t ibnbd_queue_rq (struct blk_mq_hw_ctx *hctx, +const struct blk_mq_queue_data *bd) +{ +struct request *rq = bd->rq; +struct ibnbd_clt_dev *dev = rq->rq_disk->private_data; +struct ibnbd_iu *iu =blk_mq_rq_to_pdu (rq); +int err; + +if (unlikely (!ibnbd_clt_dev_is_mapped (dev))) +return BLK_STS_IOERR ; + + iu->tag =ibnbd_get_tag (dev->sess,IBTRS_IO_CON ,IBTRS_TAG_NOWAIT ); +if (unlikely (!iu->tag)) { +ibnbd_clt_dev_kick_mq_queue (dev, hctx,IBNBD_DELAY_IFBUSY ); +return BLK_STS_RESOURCE ; + } + +blk_mq_start_request (rq); + err =ibnbd_client_xfer_request (dev, rq, iu); +if (likely (err ==0 )) +return BLK_STS_OK ; +if (unlikely (err == -EAGAIN || err == -ENOMEM )) { +ibnbd_clt_dev_kick_mq_queue (dev, hctx, IBNBD_DELAY_10ms); +ibnbd_put_tag (dev->sess, iu->tag); +return BLK_STS_RESOURCE ; + } + +ibnbd_put_tag (dev->sess, iu->tag); +return BLK_STS_IOERR ; +} + +static int ibnbd_init_request (struct blk_mq_tag_set *set,struct request *rq, +unsigned int hctx_idx,unsigned int numa_node) +{ +struct ibnbd_iu *iu =blk_mq_rq_to_pdu (rq); + +sg_init_table (iu->sglist,BMAX_SEGMENTS ); +return 0 ; +} + +static inline void ibnbd_init_hw_queue (struct ibnbd_clt_dev *dev, +struct ibnbd_queue *q, +struct blk_mq_hw_ctx *hctx) +{ +INIT_LIST_HEAD (&q->requeue_list); + q->dev = dev; + q->hctx = hctx; +} + +static void ibnbd_init_mq_hw_queues (struct ibnbd_clt_dev *dev) +{ +int i; +struct blk_mq_hw_ctx *hctx; +struct ibnbd_queue *q; + +queue_for_each_hw_ctx (dev->queue, hctx, i) { + q = &dev->hw_queues[i]; +ibnbd_init_hw_queue (dev, q, hctx); + hctx->driver_data = q; + } +} + +static struct blk_mq_ops ibnbd_mq_ops = { + .queue_rq = ibnbd_queue_rq, + .init_request = ibnbd_init_request, + .complete = ibnbd_softirq_done_fn, +}; + +static int index_to_minor (int index) +{ +return index <<IBNBD_PART_BITS ; +} + +static int minor_to_index (int minor) +{ +return minor >>IBNBD_PART_BITS ; +} + +static int ibnbd_rq_prep_fn (struct request_queue *q,struct request *rq) +{ +struct ibnbd_clt_dev *dev = q->queuedata; +struct ibnbd_iu *iu; + + iu =ibnbd_get_iu (dev->sess,IBTRS_TAG_NOWAIT ,IBTRS_IO_CON ); +if (likely (iu)) { + rq->special = iu; + rq->rq_flags |=RQF_DONTPREP ; + +return BLKPREP_OK ; + } + +ibnbd_clt_dev_kick_queue (dev,IBNBD_DELAY_IFBUSY ); +return BLKPREP_DEFER ; +} + +static void ibnbd_rq_unprep_fn (struct request_queue *q,struct request *rq) +{ +struct ibnbd_clt_dev *dev = q->queuedata; + +if (WARN_ON (!rq->special)) +return ; +ibnbd_put_iu (dev->sess, rq->special); + rq->special =NULL ; + rq->rq_flags &= ~RQF_DONTPREP ; +} + +static void ibnbd_clt_request (struct request_queue *q) +__must_hold(q->queue_lock) +{ +int err; +struct request *req; +struct ibnbd_iu *iu; +struct ibnbd_clt_dev *dev = q->queuedata; + +while ((req =blk_fetch_request (q)) !=NULL ) { +spin_unlock_irq (q->queue_lock); + +if (unlikely (!ibnbd_clt_dev_is_mapped (dev))) { + err = -EIO ; + goto next; + } + + iu = req->special; +if (WARN_ON (!iu)) { + err = -EIO ; + goto next; + } + +sg_init_table (iu->sglist, dev->max_segments); + err =ibnbd_client_xfer_request (dev, req, iu); +next: +if (unlikely (err == -EAGAIN || err == -ENOMEM )) { +ibnbd_rq_unprep_fn (q, req); +spin_lock_irq (q->queue_lock); +blk_requeue_request (q, req); +ibnbd_clt_dev_kick_queue (dev, IBNBD_DELAY_10ms); +break ; + }else if (err) { +blk_end_request_all (req, err); + } + +spin_lock_irq (q->queue_lock); + } +} + +static int setup_mq_dev (struct ibnbd_clt_dev *dev) +{ + dev->queue =blk_mq_init_queue (&dev->sess->tag_set); +if (IS_ERR (dev->queue)) { +ibnbd_err (dev, +"Initializing multiqueue queue failed, err: %ld\n" , +PTR_ERR (dev->queue)); +return PTR_ERR (dev->queue); + } +ibnbd_init_mq_hw_queues (dev); +return 0 ; +} + +static int setup_rq_dev (struct ibnbd_clt_dev *dev) +{ + dev->queue =blk_init_queue (ibnbd_clt_request,NULL ); +if (IS_ERR_OR_NULL (dev->queue)) { +if (IS_ERR (dev->queue)) { +ibnbd_err (dev,"Initializing request queue failed, " +"err: %ld\n" ,PTR_ERR (dev->queue)); +return PTR_ERR (dev->queue); + } +ibnbd_err (dev,"Initializing request queue failed\n" ); +return -ENOMEM ; + } + +blk_queue_prep_rq (dev->queue, ibnbd_rq_prep_fn); +blk_queue_softirq_done (dev->queue, ibnbd_softirq_done_fn); +blk_queue_unprep_rq (dev->queue, ibnbd_rq_unprep_fn); + +return 0 ; +} + +static void setup_request_queue (struct ibnbd_clt_dev *dev) +{ +blk_queue_logical_block_size (dev->queue, dev->logical_block_size); +blk_queue_physical_block_size (dev->queue, dev->physical_block_size); +blk_queue_max_hw_sectors (dev->queue, dev->max_hw_sectors); +blk_queue_max_write_same_sectors (dev->queue, + dev->max_write_same_sectors); + +blk_queue_max_discard_sectors (dev->queue, dev->max_discard_sectors); + dev->queue->limits.discard_granularity = dev->discard_granularity; + dev->queue->limits.discard_alignment = dev->discard_alignment; +if (dev->max_discard_sectors) +queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , dev->queue); +if (dev->secure_discard) +queue_flag_set_unlocked (QUEUE_FLAG_SECERASE , dev->queue); + +queue_flag_set_unlocked (QUEUE_FLAG_SAME_COMP , dev->queue); +queue_flag_set_unlocked (QUEUE_FLAG_SAME_FORCE , dev->queue); +/* our hca only support 32 sg cnt, proto use one, so 31 left */ +blk_queue_max_segments (dev->queue, dev->max_segments); +blk_queue_io_opt (dev->queue, dev->sess->max_io_size); +blk_queue_write_cache (dev->queue, true, true); + dev->queue->queuedata = dev; +} + +static void ibnbd_clt_setup_gen_disk (struct ibnbd_clt_dev *dev,int idx) +{ + dev->gd->major = ibnbd_client_major; + dev->gd->first_minor =index_to_minor (idx); + dev->gd->fops = &ibnbd_client_ops; + dev->gd->queue = dev->queue; + dev->gd->private_data = dev; +snprintf (dev->gd->disk_name,sizeof (dev->gd->disk_name),"ibnbd%d" , + idx); +pr_debug ("disk_name=%s, capacity=%zu, queue_mode=%s\n" , + dev->gd->disk_name, + dev->nsectors * (dev->logical_block_size /KERNEL_SECTOR_SIZE ), +ibnbd_queue_mode_str (dev->queue_mode)); + +set_capacity (dev->gd, dev->nsectors * (dev->logical_block_size / +KERNEL_SECTOR_SIZE )); + +if (dev->access_mode ==IBNBD_ACCESS_RO ) { + dev->read_only = true; +set_disk_ro (dev->gd, true); + }else { + dev->read_only = false; + } + +if (!dev->rotational) +queue_flag_set_unlocked (QUEUE_FLAG_NONROT , dev->queue); +} + +static void ibnbd_clt_add_gen_disk (struct ibnbd_clt_dev *dev) +{ +add_disk (dev->gd); +} + +static int ibnbd_client_setup_device (struct ibnbd_clt_session *sess, +struct ibnbd_clt_dev *dev,int idx) +{ +int err; + + dev->size = dev->nsectors * dev->logical_block_size; + +switch (dev->queue_mode) { +case BLK_MQ : + err =setup_mq_dev (dev); +break ; +case BLK_RQ : + err =setup_rq_dev (dev); +break ; +default : + err = -EINVAL ; + } + +if (err) +return err; + +setup_request_queue (dev); + + dev->gd =alloc_disk_node (1 <<IBNBD_PART_BITS ,NUMA_NO_NODE ); +if (!dev->gd) { +ibnbd_err (dev,"Failed to allocate disk node\n" ); +blk_cleanup_queue (dev->queue); +return -ENOMEM ; + } + +ibnbd_clt_setup_gen_disk (dev, idx); + +return 0 ; +} + +static struct ibnbd_clt_dev *init_dev (struct ibnbd_clt_session *sess, +enum ibnbd_access_mode access_mode, +enum ibnbd_queue_mode queue_mode, +enum ibnbd_io_mode io_mode, +const char *pathname) +{ +int ret; +struct ibnbd_clt_dev *dev; +size_t nr; + + dev =kzalloc_node (sizeof (*dev),GFP_KERNEL ,NUMA_NO_NODE ); +if (!dev) +return ERR_PTR (-ENOMEM ); + + nr = (queue_mode ==BLK_MQ ? nr_cpu_ids :1 ); + dev->hw_queues =kcalloc (nr,sizeof (*dev->hw_queues),GFP_KERNEL ); +if (unlikely (!dev->hw_queues)) { +pr_err ("Failed to initialize device '%s' from session" +" %s, allocating hw_queues failed." , pathname, + sess->sessname); + ret = -ENOMEM ; + goto out_alloc; + } +if (queue_mode ==BLK_RQ ) +ibnbd_init_hw_queue (dev, dev->hw_queues,NULL ); +mutex_lock (&ida_lock); + ret =ida_simple_get (&index_ida,0 ,minor_to_index (1 <<MINORBITS ), +GFP_KERNEL ); +mutex_unlock (&ida_lock); +if (ret <0 ) { +pr_err ("Failed to initialize device '%s' from session %s," +" allocating idr failed, err: %d\n" , pathname, + sess->sessname, ret); + goto out_queues; + } + dev->clt_device_id = ret; + dev->sess = sess; + dev->access_mode = access_mode; + dev->queue_mode = queue_mode; + dev->io_mode = io_mode; +strlcpy (dev->pathname, pathname,sizeof (dev->pathname)); +INIT_DELAYED_WORK (&dev->rq_delay_work, ibnbd_blk_delay_work); +mutex_init (&dev->lock); +refcount_set (&dev->refcount,1 ); + dev->dev_state =DEV_STATE_INIT ; + +/* +* Here we called from sysfs entry, thus clt-sysfs is +* responsible that session will not disappear. +*/ +ibnbd_clt_get_sess (sess); + +return dev; + +out_queues: +kfree (dev->hw_queues); +out_alloc: +kfree (dev); +return ERR_PTR (ret); +} + +static bool __exists_dev (const char *pathname) +{ +struct ibnbd_clt_session *sess; +struct ibnbd_clt_dev *dev; +bool found = false; + +list_for_each_entry (sess, &sess_list, list) { +mutex_lock (&sess->lock); +list_for_each_entry (dev, &sess->devs_list, list) { +if (!strncmp (dev->pathname, pathname, +sizeof (dev->pathname))) { + found = true; +break ; + } + } +mutex_unlock (&sess->lock); +if (found) +break ; + } + +return found; +} + +static bool exists_devpath (const char *pathname) +{ +bool found; + +mutex_lock (&sess_lock); + found =__exists_dev (pathname); +mutex_unlock (&sess_lock); + +return found; +} + +static bool insert_dev_if_not_exists_devpath (const char *pathname, +struct ibnbd_clt_session *sess, +struct ibnbd_clt_dev *dev) +{ +bool found; + +mutex_lock (&sess_lock); + found =__exists_dev (pathname); +if (!found) { +mutex_lock (&sess->lock); +list_add_tail (&dev->list, &sess->devs_list); +mutex_unlock (&sess->lock); + } +mutex_unlock (&sess_lock); + +return found; +} + +static void delete_dev (struct ibnbd_clt_dev *dev) +{ +struct ibnbd_clt_session *sess = dev->sess; + +mutex_lock (&sess->lock); +list_del (&dev->list); +mutex_unlock (&sess->lock); +} + +struct ibnbd_clt_dev *ibnbd_clt_map_device (const char *sessname, +struct ibtrs_addr *paths, +size_t path_cnt, +const char *pathname, +enum ibnbd_access_mode access_mode, +enum ibnbd_queue_mode queue_mode, +enum ibnbd_io_mode io_mode) +{ +struct ibnbd_clt_session *sess; +struct ibnbd_clt_dev *dev; +int ret; + +if (unlikely (exists_devpath (pathname))) +return ERR_PTR (-EEXIST ); + + sess =find_and_get_or_create_sess (sessname, paths, path_cnt); +if (unlikely (IS_ERR (sess))) +return ERR_CAST (sess); + + dev =init_dev (sess, access_mode, queue_mode, io_mode, pathname); +if (unlikely (IS_ERR (dev))) { +pr_err ("map_device: failed to map device '%s' from session %s," +" can't initialize device, err: %ld\n" , pathname, + sess->sessname,PTR_ERR (dev)); + ret =PTR_ERR (dev); + goto put_sess; + } +if (unlikely (insert_dev_if_not_exists_devpath (pathname, sess, dev))) { + ret = -EEXIST ; + goto put_dev; + } + ret =send_msg_open (dev,WAIT ); +if (unlikely (ret)) { +ibnbd_err (dev,"map_device: failed, can't open remote device," +" err: %d\n" , ret); + goto del_dev; + } +mutex_lock (&dev->lock); +pr_debug ("Opened remote device: session=%s, path='%s'\n" , + sess->sessname, pathname); + ret =ibnbd_client_setup_device (sess, dev, dev->clt_device_id); +if (ret) { +ibnbd_err (dev,"map_device: Failed to configure device, err: %d\n" , + ret); +mutex_unlock (&dev->lock); + goto del_dev; + } + +ibnbd_info (dev,"map_device: Device mapped as %s (nsectors: %zu," +" logical_block_size: %d, physical_block_size: %d," +" max_write_same_sectors: %d, max_discard_sectors: %d," +" discard_granularity: %d, discard_alignment: %d, " +"secure_discard: %d, max_segments: %d, max_hw_sectors: %d, " +"rotational: %d)\n" , + dev->gd->disk_name, dev->nsectors, dev->logical_block_size, + dev->physical_block_size, dev->max_write_same_sectors, + dev->max_discard_sectors, dev->discard_granularity, + dev->discard_alignment, dev->secure_discard, + dev->max_segments, dev->max_hw_sectors, dev->rotational); + +mutex_unlock (&dev->lock); + +ibnbd_clt_add_gen_disk (dev); +ibnbd_clt_put_sess (sess); + +return dev; + +del_dev: +delete_dev (dev); +put_dev: +ibnbd_clt_put_dev (dev); +put_sess: +ibnbd_clt_put_sess (sess); + +return ERR_PTR (ret); +} + +static void destroy_gen_disk (struct ibnbd_clt_dev *dev) +{ +del_gendisk (dev->gd); +/* +* Before marking queue as dying (blk_cleanup_queue() does that) +* we have to be sure that everything in-flight has gone. +* Blink with freeze/unfreeze. +*/ +blk_mq_freeze_queue (dev->queue); +blk_mq_unfreeze_queue (dev->queue); +blk_cleanup_queue (dev->queue); +put_disk (dev->gd); +} + +static void destroy_sysfs (struct ibnbd_clt_dev *dev, +const struct attribute *sysfs_self) +{ +ibnbd_clt_remove_dev_symlink (dev); +if (dev->kobj.state_initialized) { +if (sysfs_self) +/* To avoid deadlock firstly commit suicide */ +ibnbd_sysfs_remove_file_self (&dev->kobj, sysfs_self); +kobject_del (&dev->kobj); +kobject_put (&dev->kobj); + } +} + +int ibnbd_clt_unmap_device (struct ibnbd_clt_dev *dev,bool force, +const struct attribute *sysfs_self) +{ +struct ibnbd_clt_session *sess = dev->sess; +enum ibnbd_clt_dev_state prev_state; +int refcount, ret =0 ; + +mutex_lock (&dev->lock); +if (dev->dev_state ==DEV_STATE_UNMAPPED ) { +ibnbd_info (dev,"Device is already being unmapped\n" ); + ret = -EALREADY ; + goto err; + } + refcount =refcount_read (&dev->refcount); +if (!force && refcount >1 ) { +ibnbd_err (dev,"Closing device failed, device is in use," +" (%d device users)\n" , refcount -1 ); + ret = -EBUSY ; + goto err; + } + prev_state = dev->dev_state; + dev->dev_state =DEV_STATE_UNMAPPED ; +mutex_unlock (&dev->lock); + +delete_dev (dev); + +if (prev_state ==DEV_STATE_MAPPED && sess->ibtrs) +send_msg_close (dev, dev->device_id,WAIT ); + +ibnbd_info (dev,"Device is unmapped\n" ); +destroy_sysfs (dev, sysfs_self); +destroy_gen_disk (dev); + +/* Likely last reference put */ +ibnbd_clt_put_dev (dev); + +/* +* Here device and session can be vanished! +*/ + +return 0 ; +err: +mutex_unlock (&dev->lock); + +return ret; +} + +int ibnbd_clt_remap_device (struct ibnbd_clt_dev *dev) +{ +int err; + +mutex_lock (&dev->lock); +if (likely (dev->dev_state ==DEV_STATE_MAPPED_DISCONNECTED )) + err =0 ; +else if (dev->dev_state ==DEV_STATE_UNMAPPED ) + err = -ENODEV ; +else if (dev->dev_state ==DEV_STATE_MAPPED ) + err = -EALREADY ; +else + err = -EBUSY ; +mutex_unlock (&dev->lock); +if (likely (!err)) { +ibnbd_info (dev,"Remapping device.\n" ); + err =send_msg_open (dev,WAIT ); +if (unlikely (err)) +ibnbd_err (dev,"remap_device: %d\n" , err); + } + +return err; +} + +static void unmap_device_work (struct work_struct *work) +{ +struct ibnbd_clt_dev *dev; + + dev =container_of (work,typeof (*dev), unmap_on_rmmod_work); +ibnbd_clt_unmap_device (dev, true,NULL ); +} + +static void ibnbd_destroy_sessions (void ) +{ +struct ibnbd_clt_session *sess, *sn; +struct ibnbd_clt_dev *dev, *tn; + +/* Firstly forbid access through sysfs interface */ +ibnbd_clt_destroy_default_group (); +ibnbd_clt_destroy_sysfs_files (); + +/* +* Here at this point there is no any concurrent access to sessions +* list and devices list: +* 1. New session or device can'be be created - session sysfs files +* are removed. +* 2. Device or session can't be removed - module reference is taken +* into account in unmap device sysfs callback. +* 3. No IO requests inflight - each file open of block_dev increases +* module reference in get_disk(). +* +* But still there can be user requests inflights, which are sent by +* asynchronous send_msg_*() functions, thus before unmapping devices +* IBTRS session must be explicitly closed. +*/ + +list_for_each_entry_safe (sess, sn, &sess_list, list) { +ibnbd_clt_get_sess (sess); +close_ibtrs (sess); +list_for_each_entry_safe (dev, tn, &sess->devs_list, list) { +/* +* Here unmap happens in parallel for only one reason: +* blk_cleanup_queue() takes around half a second, so +* on huge amount of devices the whole module unload +* procedure takes minutes. +*/ +INIT_WORK (&dev->unmap_on_rmmod_work, unmap_device_work); +schedule_work (&dev->unmap_on_rmmod_work); + } +ibnbd_clt_put_sess (sess); + } +/* Wait for all scheduled unmap works */ +flush_scheduled_work (); +WARN_ON (!list_empty (&sess_list)); +} + +static int __init ibnbd_client_init (void ) +{ +int err; + +pr_info ("Loading module %s, version %s: (softirq_enable: %d)\n" , +KBUILD_MODNAME ,IBNBD_VER_STRING , softirq_enable); + + ibnbd_client_major =register_blkdev (ibnbd_client_major,"ibnbd" ); +if (ibnbd_client_major <=0 ) { +pr_err ("Failed to load module," +" block device registration failed\n" ); + err = -EBUSY ; + goto out; + } + + err =ibnbd_clt_create_sysfs_files (); +if (err) { +pr_err ("Failed to load module," +" creating sysfs device files failed, err: %d\n" , + err); + goto out_unregister_blk; + } + +return 0 ; + +out_unregister_blk: +unregister_blkdev (ibnbd_client_major,"ibnbd" ); +out: +return err; +} + +static void __exit ibnbd_client_exit(void) +{ +pr_info ("Unloading module\n" ); +ibnbd_destroy_sessions (); +unregister_blkdev (ibnbd_client_major,"ibnbd" ); +ida_destroy (&index_ida); +pr_info ("Module unloaded\n" ); +} + +module_init (ibnbd_client_init); +module_exit (ibnbd_client_exit);
Signature · 1 line
2.13.1
Jens Axboe
maintainerRe: [PATCH 16/24] ibnbd: client: main functionality
Quoted 3 lines · Roman Pen
This is main functionality of ibnbd-client module, which provides interface to map remote device as local block device /dev/ibnbd<N> and feeds IBTRS with IO requests.
Kill the legacy IO path for this, the driver should only support blk-mq. Hence kill off your BLK_RQ part, that will eliminate the dual path you have too.
Signature · 1 line
Jens Axboe
Re: [PATCH 16/24] ibnbd: client: main functionality
Quoted 8 lines · Jens Axboe
Quoted 3 lines · Roman Pen
This is main functionality of ibnbd-client module, which provides interface to map remote device as local block device /dev/ibnbd<N> and feeds IBTRS with IO requests.
Kill the legacy IO path for this, the driver should only support blk-mq. Hence kill off your
BLK_RQpart, that will eliminate the dual path you have too.
ok, sounds good, frankly, we did not use rq very long time.
--
Roman
PATCH 17/24 ibnbd: client: sysfs interface functions
In reply to Roman PenThis is the sysfs interface to IBNBD block devices on client side:
/sys/kernel/ibnbd_client/
|- map_device
| *** maps remote device
|
|- devices/*** all mapped devices
/sys/block/ibnbd<N>/ibnbd_client/
|- unmap_device
| *** unmaps device
|
|- state
| *** device state
|
|- session
| *** session name
|
|- mapping_path*** path of the dev that was mapped on server
--- drivers/block/ibnbd/ibnbd-clt-sysfs.c | 723 ++++++++++++++++++++++++++++++++++ 1 file changed, 723 insertions(+)
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +723 -0
@@ -0,0 +1,723 @@ +/* +* InfiniBand Network Block Driver +* +* Copyright (c) 2014 - 2017 ProfitBricks GmbH. All rights reserved. +* Authors: Fabian Holler <[email protected]> +* Jack Wang <[email protected]> +* Kleber Souza <[email protected]> +* Danil Kipnis <[email protected]> +* Roman Penyaev <[email protected]> +* Milind Dumbare <[email protected]> +* +* Copyright (c) 2017 - 2018 ProfitBricks GmbH. All rights reserved. +* Authors: Danil Kipnis <[email protected]> +* Roman Penyaev <[email protected]> +* +* 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; either version 2 +* of the License, or (at your option) any later version. +* +* 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#undef pr_fmt +#define pr_fmt (fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt + +#include <linux/types.h> +#include <linux/ctype.h> +#include <linux/parser.h> +#include <linux/module.h> +#include <linux/in6.h> +#include <linux/fs.h> +#include <linux/uaccess.h> +#include <rdma/ib.h> +#include <rdma/rdma_cm.h> + +#include "ibnbd-clt.h" + +static struct kobject *ibnbd_kobject; +static struct kobject *ibnbd_devices_kobject; + +enum { +IBNBD_OPT_ERR =0 , +IBNBD_OPT_PATH =1 <<0 , +IBNBD_OPT_DEV_PATH =1 <<1 , +IBNBD_OPT_ACCESS_MODE =1 <<3 , +IBNBD_OPT_INPUT_MODE =1 <<4 , +IBNBD_OPT_IO_MODE =1 <<5 , +IBNBD_OPT_SESSNAME =1 <<6 , +}; + +static unsigned int ibnbd_opt_mandatory[] = { +IBNBD_OPT_PATH , +IBNBD_OPT_DEV_PATH , +IBNBD_OPT_SESSNAME , +}; + +static const match_table_t ibnbd_opt_tokens = { + {IBNBD_OPT_PATH ,"path=%s" }, + {IBNBD_OPT_DEV_PATH ,"device_path=%s" }, + {IBNBD_OPT_ACCESS_MODE ,"access_mode=%s" }, + {IBNBD_OPT_INPUT_MODE ,"input_mode=%s" }, + {IBNBD_OPT_IO_MODE ,"io_mode=%s" }, + {IBNBD_OPT_SESSNAME ,"sessname=%s" }, + {IBNBD_OPT_ERR ,NULL }, +}; + +/* remove new line from string */ +static void strip (char *s) +{ +char *p = s; + +while (*s !='\0' ) { +if (*s !='\n' ) + *p++ = *s++; +else + ++s; + } + *p ='\0' ; +} + +static int ibnbd_clt_parse_map_options (const char *buf, +char *sessname, +struct ibtrs_addr *paths, +size_t *path_cnt, +size_t max_path_cnt, +char *pathname, +enum ibnbd_access_mode *access_mode, +enum ibnbd_queue_mode *queue_mode, +enum ibnbd_io_mode *io_mode) +{ +char *options, *sep_opt; +char *p; +substring_t args[MAX_OPT_ARGS ]; +int opt_mask =0 ; +int token; +int ret = -EINVAL ; +int i; +int p_cnt =0 ; + + options =kstrdup (buf,GFP_KERNEL ); +if (!options) +return -ENOMEM ; + + options =strstrip (options); +strip (options); + sep_opt = options; +while ((p =strsep (&sep_opt," " )) !=NULL ) { +if (!*p) +continue ; + + token =match_token (p, ibnbd_opt_tokens, args); + opt_mask |= token; + +switch (token) { +case IBNBD_OPT_SESSNAME : + p =match_strdup (args); +if (!p) { + ret = -ENOMEM ; + goto out; + } +if (strlen (p) >NAME_MAX ) { +pr_err ("map_device: sessname too long\n" ); + ret = -EINVAL ; +kfree (p); + goto out; + } +strlcpy (sessname, p,NAME_MAX ); +kfree (p); +break ; + +case IBNBD_OPT_PATH : + p =match_strdup (args); +if (!p || p_cnt >= max_path_cnt) { + ret = -ENOMEM ; + goto out; + } + + ret =ibtrs_addr_to_sockaddr (p,strlen (p),IBTRS_PORT , + &paths[p_cnt]); +if (ret) { +pr_err ("Can't parse path %s: %d\n" , p, ret); +kfree (p); + goto out; + } + + p_cnt++; + +kfree (p); +break ; + +case IBNBD_OPT_DEV_PATH : + p =match_strdup (args); +if (!p) { + ret = -ENOMEM ; + goto out; + } +if (strlen (p) >NAME_MAX ) { +pr_err ("map_device: Device path too long\n" ); + ret = -EINVAL ; +kfree (p); + goto out; + } +strlcpy (pathname, p,NAME_MAX ); +kfree (p); +break ; + +case IBNBD_OPT_ACCESS_MODE : + p =match_strdup (args); +if (!p) { + ret = -ENOMEM ; + goto out; + } + +if (!strcmp (p,"ro" )) { + *access_mode =IBNBD_ACCESS_RO ; + }else if (!strcmp (p,"rw" )) { + *access_mode =IBNBD_ACCESS_RW ; + }else if (!strcmp (p,"migration" )) { + *access_mode =IBNBD_ACCESS_MIGRATION ; + }else { +pr_err ("map_device: Invalid access_mode:" +" '%s'\n" , p); + ret = -EINVAL ; +kfree (p); + goto out; + } + +kfree (p); +break ; + +case IBNBD_OPT_INPUT_MODE : + p =match_strdup (args); +if (!p) { + ret = -ENOMEM ; + goto out; + } +if (!strcmp (p,"mq" )) { + *queue_mode =BLK_MQ ; + }else if (!strcmp (p,"rq" )) { + *queue_mode =BLK_RQ ; + }else { +pr_err ("map_device: Invalid input_mode: " +"'%s'.\n" , p); + ret = -EINVAL ; +kfree (p); + goto out; + } +kfree (p); +break ; + +case IBNBD_OPT_IO_MODE : + p =match_strdup (args); +if (!p) { + ret = -ENOMEM ; + goto out; + } +if (!strcmp (p,"blockio" )) { + *io_mode =IBNBD_BLOCKIO ; + }else if (!strcmp (p,"fileio" )) { + *io_mode =IBNBD_FILEIO ; + }else { +pr_err ("map_device: Invalid io_mode: '%s'.\n" , + p); + ret = -EINVAL ; +kfree (p); + goto out; + } +kfree (p); +break ; + +default : +pr_err ("map_device: Unknown parameter or missing value" +" '%s'\n" , p); + ret = -EINVAL ; + goto out; + } + } + +for (i =0 ; i <ARRAY_SIZE (ibnbd_opt_mandatory); i++) { +if ((opt_mask & ibnbd_opt_mandatory[i])) { + ret =0 ; + }else { +pr_err ("map_device: Parameters missing\n" ); + ret = -EINVAL ; +break ; + } + } + +out: + *path_cnt = p_cnt; +kfree (options); +return ret; +} + +static ssize_t ibnbd_clt_state_show (struct kobject *kobj, +struct kobj_attribute *attr,char *page) +{ +struct ibnbd_clt_dev *dev; + + dev = container_of(kobj, struct ibnbd_clt_dev, kobj); + +switch (dev->dev_state) { +case (DEV_STATE_INIT ): +return scnprintf (page,PAGE_SIZE ,"init\n" ); +case (DEV_STATE_MAPPED ): +/* TODO fix cli tool before changing to proper state */ +return scnprintf (page,PAGE_SIZE ,"open\n" ); +case (DEV_STATE_MAPPED_DISCONNECTED ): +/* TODO fix cli tool before changing to proper state */ +return scnprintf (page,PAGE_SIZE ,"closed\n" ); +case (DEV_STATE_UNMAPPED ): +return scnprintf (page,PAGE_SIZE ,"unmapped\n" ); +default : +return scnprintf (page,PAGE_SIZE ,"unknown\n" ); + } +} + +static struct kobj_attribute ibnbd_clt_state_attr = +__ATTR (state,0444 , ibnbd_clt_state_show,NULL ); + +static ssize_t ibnbd_clt_input_mode_show (struct kobject *kobj, +struct kobj_attribute *attr, +char *page) +{ +struct ibnbd_clt_dev *dev; + + dev = container_of(kobj, struct ibnbd_clt_dev, kobj); + +return scnprintf (page,PAGE_SIZE ,"%s\n" , +ibnbd_queue_mode_str (dev->queue_mode)); +} + +static struct kobj_attribute ibnbd_clt_input_mode_attr = +__ATTR (input_mode,0444 , ibnbd_clt_input_mode_show,NULL ); + +static ssize_t ibnbd_clt_mapping_path_show (struct kobject *kobj, +struct kobj_attribute *attr, +char *page) +{ +struct ibnbd_clt_dev *dev; + + dev = container_of(kobj, struct ibnbd_clt_dev, kobj); + +return scnprintf (page,PAGE_SIZE ,"%s\n" , dev->pathname); +} + +static struct kobj_attribute ibnbd_clt_mapping_path_attr = +__ATTR (mapping_path,0444 , ibnbd_clt_mapping_path_show,NULL ); + +static ssize_t ibnbd_clt_io_mode_show (struct kobject *kobj, +struct kobj_attribute *attr,char *page) +{ +struct ibnbd_clt_dev *dev; + + dev = container_of(kobj, struct ibnbd_clt_dev, kobj); + +return scnprintf (page,PAGE_SIZE ,"%s\n" , +ibnbd_io_mode_str (dev->remote_io_mode)); +} + +static struct kobj_attribute ibnbd_clt_io_mode = +__ATTR (io_mode,0444 , ibnbd_clt_io_mode_show,NULL ); + +static ssize_t ibnbd_clt_unmap_dev_show (struct kobject *kobj, +struct kobj_attribute *attr,char *page) +{ +return scnprintf (page,PAGE_SIZE ,"Usage: echo <normal|force> > %s\n" , + attr->attr.name); +} + +void ibnbd_sysfs_remove_file_self (struct kobject *kobj, +const struct attribute *attr) +{ +struct device_attribute dattr = { + .attr.name = attr->name + }; +struct device *device; + +/* +* Unfortunately original sysfs_remove_file_self() is not exported, +* so consider this as a hack to call self removal of a sysfs entry +* just using another "door". +*/ + + device =container_of (kobj,typeof (*device), kobj); +device_remove_file_self (device, &dattr); +} + +static ssize_t ibnbd_clt_unmap_dev_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t count) +{ +struct ibnbd_clt_dev *dev; +char *options; +bool force; +int err; + + options =kstrdup (buf,GFP_KERNEL ); +if (!options) +return -ENOMEM ; + + options =strstrip (options); +strip (options); + + dev = container_of(kobj, struct ibnbd_clt_dev, kobj); + +if (sysfs_streq (options,"normal" )) { + force = false; + }else if (sysfs_streq (options,"force" )) { + force = true; + }else { +ibnbd_err (dev,"unmap_device: Invalid value: %s\n" , options); + err = -EINVAL ; + goto out; + } + +ibnbd_info (dev,"Unmapping device, option: %s.\n" , + force ?"force" :"normal" ); + +/* +* We take explicit module reference only for one reason: do not +* race with lockless ibnbd_destroy_sessions(). +*/ +if (!try_module_get (THIS_MODULE )) { + err = -ENODEV ; + goto out; + } + err =ibnbd_clt_unmap_device (dev, force, &attr->attr); +if (unlikely (err)) { +if (unlikely (err != -EALREADY )) +ibnbd_err (dev,"unmap_device: %d\n" , err); + goto module_put; + } + +/* +* Here device can be vanished! +*/ + + err = count; + +module_put: +module_put (THIS_MODULE ); +out: +kfree (options); + +return err; +} + +static struct kobj_attribute ibnbd_clt_unmap_device_attr = +__ATTR (unmap_device,0644 , ibnbd_clt_unmap_dev_show, + ibnbd_clt_unmap_dev_store); + +static ssize_t ibnbd_clt_resize_dev_show (struct kobject *kobj, +struct kobj_attribute *attr, +char *page) +{ +return scnprintf (page,PAGE_SIZE , +"Usage: echo <new size in sectors> > %s\n" , + attr->attr.name); +} + +static ssize_t ibnbd_clt_resize_dev_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t count) +{ +int ret; +unsigned long sectors; +struct ibnbd_clt_dev *dev; + + dev = container_of(kobj, struct ibnbd_clt_dev, kobj); + + ret =kstrtoul (buf,0 , §ors); +if (ret) +return ret; + + ret =ibnbd_clt_resize_disk (dev, (size_t )sectors); +if (ret) +return ret; + +return count; +} + +static struct kobj_attribute ibnbd_clt_resize_dev_attr = +__ATTR (resize,0644 , ibnbd_clt_resize_dev_show, + ibnbd_clt_resize_dev_store); + +static ssize_t ibnbd_clt_remap_dev_show (struct kobject *kobj, +struct kobj_attribute *attr,char *page) +{ +return scnprintf (page,PAGE_SIZE ,"Usage: echo <1> > %s\n" , + attr->attr.name); +} + +static ssize_t ibnbd_clt_remap_dev_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t count) +{ +struct ibnbd_clt_dev *dev; +char *options; +int err; + + options =kstrdup (buf,GFP_KERNEL ); +if (!options) +return -ENOMEM ; + + options =strstrip (options); +strip (options); + + dev = container_of(kobj, struct ibnbd_clt_dev, kobj); +if (!sysfs_streq (options,"1" )) { +ibnbd_err (dev,"remap_device: Invalid value: %s\n" , options); + err = -EINVAL ; + goto out; + } + err =ibnbd_clt_remap_device (dev); +if (likely (!err)) + err = count; + +out: +kfree (options); + +return err; +} + +static struct kobj_attribute ibnbd_clt_remap_device_attr = +__ATTR (remap_device,0644 , ibnbd_clt_remap_dev_show, + ibnbd_clt_remap_dev_store); + +static ssize_t ibnbd_clt_session_show (struct kobject *kobj, +struct kobj_attribute *attr, +char *page) +{ +struct ibnbd_clt_dev *dev; + + dev = container_of(kobj, struct ibnbd_clt_dev, kobj); + +return scnprintf (page,PAGE_SIZE ,"%s\n" , dev->sess->sessname); +} + +static struct kobj_attribute ibnbd_clt_session_attr = +__ATTR (session,0444 , ibnbd_clt_session_show,NULL ); + +static struct attribute *ibnbd_dev_attrs[] = { + &ibnbd_clt_unmap_device_attr.attr, + &ibnbd_clt_resize_dev_attr.attr, + &ibnbd_clt_remap_device_attr.attr, + &ibnbd_clt_mapping_path_attr.attr, + &ibnbd_clt_state_attr.attr, + &ibnbd_clt_input_mode_attr.attr, + &ibnbd_clt_session_attr.attr, + &ibnbd_clt_io_mode.attr, +NULL , +}; + +void ibnbd_clt_remove_dev_symlink (struct ibnbd_clt_dev *dev) +{ +/* +* The module_is_live() check is crucial and helps to avoid annoying +* sysfs warning raised in sysfs_remove_link(), when the whole sysfs +* path was just removed, see ibnbd_close_sessions(). +*/ +if (strlen (dev->blk_symlink_name) &&module_is_live (THIS_MODULE )) +sysfs_remove_link (ibnbd_devices_kobject, dev->blk_symlink_name); +} + +static struct kobj_type ibnbd_dev_ktype = { + .sysfs_ops = &kobj_sysfs_ops, + .default_attrs = ibnbd_dev_attrs, +}; + +static int ibnbd_clt_add_dev_kobj (struct ibnbd_clt_dev *dev) +{ +int ret; +struct kobject *gd_kobj = &disk_to_dev (dev->gd)->kobj; + + ret =kobject_init_and_add (&dev->kobj, &ibnbd_dev_ktype, gd_kobj,"%s" , +"ibnbd" ); +if (ret) +ibnbd_err (dev,"Failed to create device sysfs dir, err: %d\n" , + ret); + +return ret; +} + +static ssize_t ibnbd_clt_map_device_show (struct kobject *kobj, +struct kobj_attribute *attr, +char *page) +{ +return scnprintf (page,PAGE_SIZE ,"Usage: echo \"" +"sessname=<name of the ibtrs session>" +" path=<[srcaddr,]dstaddr>" +" [path=<[srcaddr,]dstaddr>]" +" device_path=<full path on remote side>" +" [access_mode=<ro|rw|migration>]" +" [input_mode=<mq|rq>]" +" [io_mode=<fileio|blockio>]\" > %s\n\n" +"addr ::= [ ip:<ipv4> | ip:<ipv6> | gid:<gid> ]\n" , + attr->attr.name); +} + +static int ibnbd_clt_get_path_name (struct ibnbd_clt_dev *dev,char *buf, +size_t len) +{ +int ret; +char pathname[NAME_MAX ], *s; + +strlcpy (pathname, dev->pathname,sizeof (pathname)); +while ((s =strchr (pathname,'/' ))) + s[0 ] ='!' ; + + ret =snprintf (buf, len,"%s" , pathname); +if (ret >= len) +return -ENAMETOOLONG ; + +return 0 ; +} + +static int ibnbd_clt_add_dev_symlink (struct ibnbd_clt_dev *dev) +{ +struct kobject *gd_kobj = &disk_to_dev (dev->gd)->kobj; +int ret; + + ret =ibnbd_clt_get_path_name (dev, dev->blk_symlink_name, +sizeof (dev->blk_symlink_name)); +if (ret) { +ibnbd_err (dev,"Failed to get /sys/block symlink path, err: %d\n" , + ret); + goto out_err; + } + + ret =sysfs_create_link (ibnbd_devices_kobject, gd_kobj, + dev->blk_symlink_name); +if (ret) { +ibnbd_err (dev,"Creating /sys/block symlink failed, err: %d\n" , + ret); + goto out_err; + } + +return 0 ; + +out_err: + dev->blk_symlink_name[0 ] ='\0' ; +return ret; +} + +static ssize_t ibnbd_clt_map_device_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t count) +{ +struct ibnbd_clt_dev *dev; +int ret; +char pathname[NAME_MAX ]; +char sessname[NAME_MAX ]; +enum ibnbd_access_mode access_mode =IBNBD_ACCESS_RW ; +enum ibnbd_queue_mode queue_mode =BLK_MQ ; +enum ibnbd_io_mode io_mode =IBNBD_AUTOIO ; + +size_t path_cnt; +struct ibtrs_addr paths[3 ]; +struct sockaddr_storage saddr[ARRAY_SIZE (paths)]; +struct sockaddr_storage daddr[ARRAY_SIZE (paths)]; + +for (path_cnt =0 ; path_cnt <ARRAY_SIZE (paths); path_cnt++) { + paths[path_cnt].src = (struct sockaddr *)&saddr[path_cnt]; + paths[path_cnt].dst = (struct sockaddr *)&daddr[path_cnt]; + } + + ret =ibnbd_clt_parse_map_options (buf, sessname, paths, + &path_cnt,ARRAY_SIZE (paths), + pathname, &access_mode, + &queue_mode, &io_mode); +if (ret) +return ret; + +pr_info ("Mapping device %s on session %s," +" (access_mode: %s, input_mode: %s, io_mode: %s)\n" , + pathname, sessname,ibnbd_access_mode_str (access_mode), +ibnbd_queue_mode_str (queue_mode),ibnbd_io_mode_str (io_mode)); + + dev =ibnbd_clt_map_device (sessname, paths, path_cnt, pathname, + access_mode, queue_mode, io_mode); +if (unlikely (IS_ERR (dev))) +return PTR_ERR (dev); + + ret =ibnbd_clt_add_dev_kobj (dev); +if (unlikely (ret)) + goto unmap_dev; + + ret =ibnbd_clt_add_dev_symlink (dev); +if (ret) + goto unmap_dev; + +return count; + +unmap_dev: +ibnbd_clt_unmap_device (dev, true,NULL ); + +return ret; +} + +static struct kobj_attribute ibnbd_clt_map_device_attr = +__ATTR (map_device,0644 , + ibnbd_clt_map_device_show, ibnbd_clt_map_device_store); + +static struct attribute *default_attrs[] = { + &ibnbd_clt_map_device_attr.attr, +NULL , +}; + +static struct attribute_group default_attr_group = { + .attrs = default_attrs, +}; + +int ibnbd_clt_create_sysfs_files (void ) +{ +int err =0 ; + + ibnbd_kobject =kobject_create_and_add (KBUILD_MODNAME , kernel_kobj); +if (!ibnbd_kobject) { + err = -ENOMEM ; + goto err1; + } + + ibnbd_devices_kobject =kobject_create_and_add ("devices" , + ibnbd_kobject); +if (!ibnbd_devices_kobject) { + err = -ENOMEM ; + goto err2; + } + + err =sysfs_create_group (ibnbd_kobject, &default_attr_group); +if (err) + goto err3; + +return 0 ; + +err3: +kobject_put (ibnbd_devices_kobject); +err2: +kobject_put (ibnbd_kobject); +err1: +return err; +} + +void ibnbd_clt_destroy_default_group (void ) +{ +sysfs_remove_group (ibnbd_kobject, &default_attr_group); +} + +void ibnbd_clt_destroy_sysfs_files (void ) +{ +kobject_del (ibnbd_devices_kobject); +kobject_put (ibnbd_devices_kobject); +kobject_del (ibnbd_kobject); +kobject_put (ibnbd_kobject); +}
Signature · 6 lines
2.13.1 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 18/24 ibnbd: server: private header with server structs and functions
In reply to Roman PenThis header describes main structs and functions used by ibnbd-server module, namely structs for managing sessions from different clients and mapped (opened) devices.
--- drivers/block/ibnbd/ibnbd-srv.h | 100 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+)
drivers/block/ibnbd/ibnbd-srv.h new file +100 -0
@@ -0,0 +1,100 @@ +/* +* InfiniBand Network Block Driver +* +* Copyright (c) 2014 - 2017 ProfitBricks GmbH. All rights reserved. +* Authors: Fabian Holler <[email protected]> +* Jack Wang <[email protected]> +* Kleber Souza <[email protected]> +* Danil Kipnis <[email protected]> +* Roman Penyaev <[email protected]> +* Milind Dumbare <[email protected]> +* +* Copyright (c) 2017 - 2018 ProfitBricks GmbH. All rights reserved. +* Authors: Danil Kipnis <[email protected]> +* Roman Penyaev <[email protected]> +* +* 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; either version 2 +* of the License, or (at your option) any later version. +* +* 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef IBNBD_SRV_H +#define IBNBD_SRV_H + +#include <linux/types.h> +#include <linux/idr.h> +#include <linux/kref.h> + +#include "ibtrs.h" +#include "ibnbd-proto.h" +#include "ibnbd-log.h" + +struct ibnbd_srv_session { +/* Entry inside global sess_list */ +struct list_head list; +struct ibtrs_srv *ibtrs; +char sessname[NAME_MAX ]; +int queue_depth; +struct bio_set *sess_bio_set; + +rwlock_t index_lock____cacheline_aligned ; +struct idr index_idr; +/* List of struct ibnbd_srv_sess_dev */ +struct list_head sess_dev_list; +struct mutex lock; +u8 ver; +}; + +struct ibnbd_srv_dev { +/* Entry inside global dev_list */ +struct list_head list; +struct kobject dev_kobj; +struct kobject dev_sessions_kobj; +struct kref kref; +char id[NAME_MAX ]; +/* List of ibnbd_srv_sess_dev structs */ +struct list_head sess_dev_list; +struct mutex lock; +int open_write_cnt; +enum ibnbd_io_mode mode; +}; + +/* Structure which binds N devices and N sessions */ +struct ibnbd_srv_sess_dev { +/* Entry inside ibnbd_srv_dev struct */ +struct list_head dev_list; +/* Entry inside ibnbd_srv_session struct */ +struct list_head sess_list; +struct ibnbd_dev *ibnbd_dev; +struct ibnbd_srv_session *sess; +struct ibnbd_srv_dev *dev; +struct kobject kobj; +struct completion *sysfs_release_compl; +u32 device_id; +fmode_t open_flags; +struct kref kref; +struct completion *destroy_comp; +char pathname[NAME_MAX ]; +}; + +/* ibnbd-srv-sysfs.c */ + +int ibnbd_srv_create_dev_sysfs (struct ibnbd_srv_dev *dev, +struct block_device *bdev, +const char *dir_name); +void ibnbd_srv_destroy_dev_sysfs (struct ibnbd_srv_dev *dev); +int ibnbd_srv_create_dev_session_sysfs (struct ibnbd_srv_sess_dev *sess_dev); +void ibnbd_srv_destroy_dev_session_sysfs (struct ibnbd_srv_sess_dev *sess_dev); +int ibnbd_srv_create_sysfs_files (void ); +void ibnbd_srv_destroy_sysfs_files (void ); + +#endif /* IBNBD_SRV_H */
Signature · 1 line
2.13.1
PATCH 19/24 ibnbd: server: main functionality
In reply to Roman PenThis is main functionality of ibnbd-server module, which handles IBTRS events and IBNBD protocol requests, like map (open) or unmap (close) device. Also server side is responsible for processing incoming IBTRS IO requests and forward them to local mapped devices.
--- drivers/block/ibnbd/ibnbd-srv.c | 901 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 901 insertions(+)
drivers/block/ibnbd/ibnbd-srv.c new file +901 -0
@@ -0,0 +1,901 @@ +/* +* InfiniBand Network Block Driver +* +* Copyright (c) 2014 - 2017 ProfitBricks GmbH. All rights reserved. +* Authors: Fabian Holler <[email protected]> +* Jack Wang <[email protected]> +* Kleber Souza <[email protected]> +* Danil Kipnis <[email protected]> +* Roman Penyaev <[email protected]> +* Milind Dumbare <[email protected]> +* +* Copyright (c) 2017 - 2018 ProfitBricks GmbH. All rights reserved. +* Authors: Danil Kipnis <[email protected]> +* Roman Penyaev <[email protected]> +* +* 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; either version 2 +* of the License, or (at your option) any later version. +* +* 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#undef pr_fmt +#define pr_fmt (fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt + +#include <linux/module.h> +#include <linux/blkdev.h> + +#include "ibnbd-srv.h" +#include "ibnbd-srv-dev.h" + +MODULE_AUTHOR ("[email protected]" ); +MODULE_VERSION (IBNBD_VER_STRING ); +MODULE_DESCRIPTION ("InfiniBand Network Block Device Server" ); +MODULE_LICENSE ("GPL" ); + +#define DEFAULT_DEV_SEARCH_PATH "/" + +static char dev_search_path[PATH_MAX ] =DEFAULT_DEV_SEARCH_PATH ; + +static int dev_search_path_set (const char *val,const struct kernel_param *kp) +{ +char *dup; + +if (strlen (val) >=sizeof (dev_search_path)) +return -EINVAL ; + + dup =kstrdup (val,GFP_KERNEL ); + +if (dup[strlen (dup) -1 ] =='\n' ) + dup[strlen (dup) -1 ] ='\0' ; + +strlcpy (dev_search_path, dup,sizeof (dev_search_path)); + +kfree (dup); +pr_info ("dev_search_path changed to '%s'\n" , dev_search_path); + +return 0 ; +} + +static struct kparam_string dev_search_path_kparam_str = { + .maxlen =sizeof (dev_search_path), + .string = dev_search_path +}; + +static const struct kernel_param_ops dev_search_path_ops = { + .set = dev_search_path_set, + .get = param_get_string, +}; + +module_param_cb (dev_search_path, &dev_search_path_ops, + &dev_search_path_kparam_str,0444 ); +MODULE_PARM_DESC (dev_search_path,"Sets the device_search_path." +" When a device is mapped this path is prepended to the" +" device_path from the map_device operation." +" (default: " DEFAULT_DEV_SEARCH_PATH ")" ); + +static int def_io_mode =IBNBD_BLOCKIO ; +module_param (def_io_mode, int,0444 ); +MODULE_PARM_DESC(def_io_mode, "By default, export devices in" + " blockio(" __stringify(_IBNBD_BLOCKIO) ") or" + " fileio(" __stringify(_IBNBD_FILEIO) ") mode." + " (default: " __stringify(_IBNBD_BLOCKIO) " (blockio))"); + +static DEFINE_MUTEX (sess_lock); +static DEFINE_SPINLOCK (dev_lock); + +static LIST_HEAD (sess_list); +static LIST_HEAD (dev_list); + +struct ibnbd_io_private { +struct ibtrs_srv_op *id; +struct ibnbd_srv_sess_dev *sess_dev; +}; + +static void ibnbd_sess_dev_release (struct kref *kref) +{ +struct ibnbd_srv_sess_dev *sess_dev; + + sess_dev = container_of(kref, struct ibnbd_srv_sess_dev, kref); +complete (sess_dev->destroy_comp); +} + +static inline void ibnbd_put_sess_dev (struct ibnbd_srv_sess_dev *sess_dev) +{ +kref_put (&sess_dev->kref, ibnbd_sess_dev_release); +} + +static void ibnbd_endio (void *priv,int error) +{ +struct ibnbd_io_private *ibnbd_priv = priv; +struct ibnbd_srv_sess_dev *sess_dev = ibnbd_priv->sess_dev; + +ibnbd_put_sess_dev (sess_dev); + +ibtrs_srv_resp_rdma (ibnbd_priv->id, error); + +kfree (priv); +} + +static struct ibnbd_srv_sess_dev * +ibnbd_get_sess_dev (int dev_id,struct ibnbd_srv_session *srv_sess) +{ +struct ibnbd_srv_sess_dev *sess_dev; +int ret =0 ; + +read_lock (&srv_sess->index_lock); + sess_dev =idr_find (&srv_sess->index_idr, dev_id); +if (likely (sess_dev)) + ret =kref_get_unless_zero (&sess_dev->kref); +read_unlock (&srv_sess->index_lock); + +if (unlikely (!sess_dev || !ret)) +return ERR_PTR (-ENXIO ); + +return sess_dev; +} + +static int process_rdma (struct ibtrs_srv *sess, +struct ibnbd_srv_session *srv_sess, +struct ibtrs_srv_op *id,void *data,u32 datalen, +const void *usr,size_t usrlen) +{ +const struct ibnbd_msg_io *msg = usr; +struct ibnbd_io_private *priv; +struct ibnbd_srv_sess_dev *sess_dev; +u32 dev_id; +int err; + + priv =kmalloc (sizeof (*priv),GFP_KERNEL ); +if (unlikely (!priv)) +return -ENOMEM ; + + dev_id =le32_to_cpu (msg->device_id); + + sess_dev =ibnbd_get_sess_dev (dev_id, srv_sess); +if (unlikely (IS_ERR (sess_dev))) { +pr_err_ratelimited ("Got I/O request on session %s for " +"unknown device id %d\n" , + srv_sess->sessname, dev_id); + err = -ENOTCONN ; + goto err; + } + + priv->sess_dev = sess_dev; + priv->id = id; + + err =ibnbd_dev_submit_io (sess_dev->ibnbd_dev,le64_to_cpu (msg->sector), + data, datalen,le32_to_cpu (msg->bi_size), +le32_to_cpu (msg->rw), priv); +if (unlikely (err)) { +ibnbd_err (sess_dev, +"Submitting I/O to device failed, err: %d\n" , err); + goto sess_dev_put; + } + +return 0 ; + +sess_dev_put: +ibnbd_put_sess_dev (sess_dev); +err: +kfree (priv); +return err; +} + +static void destroy_device (struct ibnbd_srv_dev *dev) +{ +WARN (!list_empty (&dev->sess_dev_list), +"Device %s is being destroyed but still in use!\n" , + dev->id); + +spin_lock (&dev_lock); +list_del (&dev->list); +spin_unlock (&dev_lock); + +if (dev->dev_kobj.state_in_sysfs) +/* +* Destroy kobj only if it was really created. +* The following call should be sync, because +* we free the memory afterwards. +*/ +ibnbd_srv_destroy_dev_sysfs (dev); + +kfree (dev); +} + +static void destroy_device_cb (struct kref *kref) +{ +struct ibnbd_srv_dev *dev; + + dev = container_of(kref, struct ibnbd_srv_dev, kref); + +destroy_device (dev); +} + +static void ibnbd_put_srv_dev (struct ibnbd_srv_dev *dev) +{ +kref_put (&dev->kref, destroy_device_cb); +} + +static void ibnbd_destroy_sess_dev (struct ibnbd_srv_sess_dev *sess_dev) +{ +DECLARE_COMPLETION_ONSTACK (dc); + +write_lock (&sess_dev->sess->index_lock); +idr_remove (&sess_dev->sess->index_idr, sess_dev->device_id); +write_unlock (&sess_dev->sess->index_lock); + + sess_dev->destroy_comp = &dc; +ibnbd_put_sess_dev (sess_dev); +wait_for_completion (&dc); + +ibnbd_dev_close (sess_dev->ibnbd_dev); +list_del (&sess_dev->sess_list); +mutex_lock (&sess_dev->dev->lock); +list_del (&sess_dev->dev_list); +if (sess_dev->open_flags &FMODE_WRITE ) + sess_dev->dev->open_write_cnt--; +mutex_unlock (&sess_dev->dev->lock); + +ibnbd_put_srv_dev (sess_dev->dev); + +ibnbd_info (sess_dev,"Device closed\n" ); +kfree (sess_dev); +} + +static void destroy_sess (struct ibnbd_srv_session *srv_sess) +{ +struct ibnbd_srv_sess_dev *sess_dev, *tmp; + +if (list_empty (&srv_sess->sess_dev_list)) + goto out; + +mutex_lock (&srv_sess->lock); +list_for_each_entry_safe (sess_dev, tmp, &srv_sess->sess_dev_list, + sess_list) { +ibnbd_srv_destroy_dev_session_sysfs (sess_dev); +ibnbd_destroy_sess_dev (sess_dev); + } +mutex_unlock (&srv_sess->lock); + +out: +idr_destroy (&srv_sess->index_idr); +bioset_free (srv_sess->sess_bio_set); + +pr_info ("IBTRS Session %s disconnected\n" , srv_sess->sessname); + +mutex_lock (&sess_lock); +list_del (&srv_sess->list); +mutex_unlock (&sess_lock); + +kfree (srv_sess); +} + +static int create_sess (struct ibtrs_srv *ibtrs) +{ +struct ibnbd_srv_session *srv_sess; +char sessname[NAME_MAX ]; +int err; + + err =ibtrs_srv_get_sess_name (ibtrs, sessname,sizeof (sessname)); +if (unlikely (err)) { +pr_err ("ibtrs_srv_get_sess_name(%s): %d\n" , sessname, err); + +return err; + } + srv_sess =kzalloc (sizeof (*srv_sess),GFP_KERNEL ); +if (!srv_sess) +return -ENOMEM ; + srv_sess->queue_depth =ibtrs_srv_get_queue_depth (ibtrs); + srv_sess->sess_bio_set =bioset_create (srv_sess->queue_depth,0 , +BIOSET_NEED_BVECS ); +if (!srv_sess->sess_bio_set) { +pr_err ("Allocating srv_session for session %s failed\n" , + sessname); +kfree (srv_sess); +return -ENOMEM ; + } + +idr_init (&srv_sess->index_idr); +rwlock_init (&srv_sess->index_lock); +INIT_LIST_HEAD (&srv_sess->sess_dev_list); +mutex_init (&srv_sess->lock); +mutex_lock (&sess_lock); +list_add (&srv_sess->list, &sess_list); +mutex_unlock (&sess_lock); + + srv_sess->ibtrs = ibtrs; + srv_sess->queue_depth =ibtrs_srv_get_queue_depth (ibtrs); +strlcpy (srv_sess->sessname, sessname,sizeof (srv_sess->sessname)); + +ibtrs_srv_set_sess_priv (ibtrs, srv_sess); + +return 0 ; +} + +static int ibnbd_srv_link_ev (struct ibtrs_srv *ibtrs, +enum ibtrs_srv_link_ev ev,void *priv) +{ +struct ibnbd_srv_session *srv_sess = priv; + +switch (ev) { +case IBTRS_SRV_LINK_EV_CONNECTED : +return create_sess (ibtrs); + +case IBTRS_SRV_LINK_EV_DISCONNECTED : +if (WARN_ON (!srv_sess)) +return -EINVAL ; + +destroy_sess (srv_sess); +return 0 ; + +default : +pr_warn ("Received unknown IBTRS session event %d from session" +" %s\n" , ev, srv_sess->sessname); +return -EINVAL ; + } +} + +static int process_msg_close (struct ibtrs_srv *ibtrs, +struct ibnbd_srv_session *srv_sess, +void *data,size_t datalen,const void *usr, +size_t usrlen) +{ +const struct ibnbd_msg_close *close_msg = usr; +struct ibnbd_srv_sess_dev *sess_dev; + + sess_dev =ibnbd_get_sess_dev (close_msg->device_id, srv_sess); +if (unlikely (IS_ERR (sess_dev))) +return 0 ; + +ibnbd_srv_destroy_dev_session_sysfs (sess_dev); +ibnbd_put_sess_dev (sess_dev); +mutex_lock (&srv_sess->lock); +ibnbd_destroy_sess_dev (sess_dev); +mutex_unlock (&srv_sess->lock); +return 0 ; +} + +static int process_msg_open (struct ibtrs_srv *ibtrs, +struct ibnbd_srv_session *srv_sess, +const void *msg,size_t len, +void *data,size_t datalen); + +static int process_msg_sess_info (struct ibtrs_srv *ibtrs, +struct ibnbd_srv_session *srv_sess, +const void *msg,size_t len, +void *data,size_t datalen); + +static int ibnbd_srv_rdma_ev (struct ibtrs_srv *ibtrs,void *priv, +struct ibtrs_srv_op *id,int dir, +void *data,size_t datalen,const void *usr, +size_t usrlen) +{ +struct ibnbd_srv_session *srv_sess = priv; +const struct ibnbd_msg_hdr *hdr = usr; +int ret =0 ; +u16 type; + +if (unlikely (WARN_ON (!srv_sess))) +return -ENODEV ; + + type =le16_to_cpu (hdr->type); + +switch (type) { +case IBNBD_MSG_IO : +return process_rdma (ibtrs, srv_sess, id, data, datalen, usr, + usrlen); +case IBNBD_MSG_CLOSE : + ret =process_msg_close (ibtrs, srv_sess, data, datalen, + usr, usrlen); +break ; +case IBNBD_MSG_OPEN : + ret =process_msg_open (ibtrs, srv_sess, usr, usrlen, + data, datalen); +break ; +case IBNBD_MSG_SESS_INFO : + ret =process_msg_sess_info (ibtrs, srv_sess, usr, usrlen, + data, datalen); +break ; +default : +pr_warn ("Received unexpected message type %d with dir %d from" +" session %s\n" , type, dir, srv_sess->sessname); +return -EINVAL ; + } + +ibtrs_srv_resp_rdma (id, ret); +return 0 ; +} + +static struct ibnbd_srv_sess_dev +*ibnbd_sess_dev_alloc (struct ibnbd_srv_session *srv_sess) +{ +struct ibnbd_srv_sess_dev *sess_dev; +int error; + + sess_dev =kzalloc (sizeof (*sess_dev),GFP_KERNEL ); +if (!sess_dev) +return ERR_PTR (-ENOMEM ); + +idr_preload (GFP_KERNEL ); +write_lock (&srv_sess->index_lock); + + error =idr_alloc (&srv_sess->index_idr, sess_dev,0 ,-1 ,GFP_NOWAIT ); +if (error <0 ) { +pr_warn ("Allocating idr failed, err: %d\n" , error); + goto out_unlock; + } + + sess_dev->device_id = error; + error =0 ; + +out_unlock: +write_unlock (&srv_sess->index_lock); +idr_preload_end (); +if (error) { +kfree (sess_dev); +return ERR_PTR (error); + } + +return sess_dev; +} + +static struct ibnbd_srv_dev *ibnbd_srv_init_srv_dev (const char *id, +enum ibnbd_io_mode mode) +{ +struct ibnbd_srv_dev *dev; + + dev =kzalloc (sizeof (*dev),GFP_KERNEL ); +if (!dev) +return ERR_PTR (-ENOMEM ); + +strlcpy (dev->id, id,sizeof (dev->id)); + dev->mode = mode; +kref_init (&dev->kref); +INIT_LIST_HEAD (&dev->sess_dev_list); +mutex_init (&dev->lock); + +return dev; +} + +static struct ibnbd_srv_dev * +ibnbd_srv_find_or_add_srv_dev (struct ibnbd_srv_dev *new_dev) +{ +struct ibnbd_srv_dev *dev; + +spin_lock (&dev_lock); +list_for_each_entry (dev, &dev_list, list) { +if (!strncmp (dev->id, new_dev->id,sizeof (dev->id))) { +if (!kref_get_unless_zero (&dev->kref)) +/* +* We lost the race, device is almost dead. +* Continue traversing to find a valid one. +*/ +continue ; +spin_unlock (&dev_lock); +return dev; + } + } +list_add (&new_dev->list, &dev_list); +spin_unlock (&dev_lock); + +return new_dev; +} + +static int ibnbd_srv_check_update_open_perm (struct ibnbd_srv_dev *srv_dev, +struct ibnbd_srv_session *srv_sess, +enum ibnbd_io_mode io_mode, +enum ibnbd_access_mode access_mode) +{ +int ret = -EPERM ; + +mutex_lock (&srv_dev->lock); + +if (srv_dev->mode != io_mode) { +pr_err ("Mapping device '%s' for session %s in %s mode forbidden," +" device is already mapped from other client(s) in" +" %s mode\n" , srv_dev->id, srv_sess->sessname, +ibnbd_io_mode_str (io_mode), +ibnbd_io_mode_str (srv_dev->mode)); + goto out; + } + +switch (access_mode) { +case IBNBD_ACCESS_RO : + ret =0 ; +break ; +case IBNBD_ACCESS_RW : +if (srv_dev->open_write_cnt ==0 ) { + srv_dev->open_write_cnt++; + ret =0 ; + }else { +pr_err ("Mapping device '%s' for session %s with" +" RW permissions failed. Device already opened" +" as 'RW' by %d client(s) in %s mode.\n" , + srv_dev->id, srv_sess->sessname, + srv_dev->open_write_cnt, +ibnbd_io_mode_str (srv_dev->mode)); + } +break ; +case IBNBD_ACCESS_MIGRATION : +if (srv_dev->open_write_cnt <2 ) { + srv_dev->open_write_cnt++; + ret =0 ; + }else { +pr_err ("Mapping device '%s' for session %s with" +" migration permissions failed. Device already" +" opened as 'RW' by %d client(s) in %s mode.\n" , + srv_dev->id, srv_sess->sessname, + srv_dev->open_write_cnt, +ibnbd_io_mode_str (srv_dev->mode)); + } +break ; +default : +pr_err ("Received mapping request for device '%s' on session %s" +" with invalid access mode: %d\n" , srv_dev->id, + srv_sess->sessname, access_mode); + ret = -EINVAL ; + } + +out: +mutex_unlock (&srv_dev->lock); + +return ret; +} + +static struct ibnbd_srv_dev * +ibnbd_srv_get_or_create_srv_dev (struct ibnbd_dev *ibnbd_dev, +struct ibnbd_srv_session *srv_sess, +enum ibnbd_io_mode io_mode, +enum ibnbd_access_mode access_mode) +{ +int ret; +struct ibnbd_srv_dev *new_dev, *dev; + + new_dev =ibnbd_srv_init_srv_dev (ibnbd_dev->name, io_mode); +if (IS_ERR (new_dev)) +return new_dev; + + dev =ibnbd_srv_find_or_add_srv_dev (new_dev); +if (dev != new_dev) +kfree (new_dev); + + ret =ibnbd_srv_check_update_open_perm (dev, srv_sess, io_mode, + access_mode); +if (ret) { +ibnbd_put_srv_dev (dev); +return ERR_PTR (ret); + } + +return dev; +} + +static void ibnbd_srv_fill_msg_open_rsp (struct ibnbd_msg_open_rsp *rsp, +struct ibnbd_srv_sess_dev *sess_dev) +{ +struct ibnbd_dev *ibnbd_dev = sess_dev->ibnbd_dev; + + rsp->hdr.type =cpu_to_le16 (IBNBD_MSG_OPEN_RSP ); + rsp->device_id = +cpu_to_le32 (sess_dev->device_id); + rsp->nsectors = +cpu_to_le64 (get_capacity (ibnbd_dev->bdev->bd_disk)); + rsp->logical_block_size = +cpu_to_le16 (ibnbd_dev_get_logical_bsize (ibnbd_dev)); + rsp->physical_block_size = +cpu_to_le16 (ibnbd_dev_get_phys_bsize (ibnbd_dev)); + rsp->max_segments = +cpu_to_le16 (ibnbd_dev_get_max_segs (ibnbd_dev)); + rsp->max_hw_sectors = +cpu_to_le32 (ibnbd_dev_get_max_hw_sects (ibnbd_dev)); + rsp->max_write_same_sectors = +cpu_to_le32 (ibnbd_dev_get_max_write_same_sects (ibnbd_dev)); + rsp->max_discard_sectors = +cpu_to_le32 (ibnbd_dev_get_max_discard_sects (ibnbd_dev)); + rsp->discard_granularity = +cpu_to_le32 (ibnbd_dev_get_discard_granularity (ibnbd_dev)); + rsp->discard_alignment = +cpu_to_le32 (ibnbd_dev_get_discard_alignment (ibnbd_dev)); + rsp->secure_discard = +cpu_to_le16 (ibnbd_dev_get_secure_discard (ibnbd_dev)); + rsp->rotational = + !blk_queue_nonrot (bdev_get_queue (ibnbd_dev->bdev)); + rsp->io_mode = + ibnbd_dev->mode; +} + +static struct ibnbd_srv_sess_dev * +ibnbd_srv_create_set_sess_dev (struct ibnbd_srv_session *srv_sess, +const struct ibnbd_msg_open *open_msg, +struct ibnbd_dev *ibnbd_dev,fmode_t open_flags, +struct ibnbd_srv_dev *srv_dev) +{ +struct ibnbd_srv_sess_dev *sdev =ibnbd_sess_dev_alloc (srv_sess); + +if (IS_ERR (sdev)) +return sdev; + +kref_init (&sdev->kref); + +strlcpy (sdev->pathname, open_msg->dev_name,sizeof (sdev->pathname)); + + sdev->ibnbd_dev = ibnbd_dev; + sdev->sess = srv_sess; + sdev->dev = srv_dev; + sdev->open_flags = open_flags; + +return sdev; +} + +static char *ibnbd_srv_get_full_path (const char *dev_name) +{ +char *full_path; +char *a, *b; + + full_path =kmalloc (PATH_MAX ,GFP_KERNEL ); +if (!full_path) +return ERR_PTR (-ENOMEM ); + +snprintf (full_path,PATH_MAX ,"%s/%s" , dev_search_path, dev_name); + +/* eliminitate duplicated slashes */ + a =strchr (full_path,'/' ); + b = a; +while (*b !='\0' ) { +if (*b =='/' && *a =='/' ) { + b++; + }else { + a++; + *a = *b; + b++; + } + } + a++; + *a ='\0' ; + +return full_path; +} + +static int process_msg_sess_info (struct ibtrs_srv *ibtrs, +struct ibnbd_srv_session *srv_sess, +const void *msg,size_t len, +void *data,size_t datalen) +{ +const struct ibnbd_msg_sess_info *sess_info_msg = msg; +struct ibnbd_msg_sess_info_rsp *rsp = data; + + srv_sess->ver =min_t (u8, sess_info_msg->ver,IBNBD_VER_MAJOR ); +pr_debug ("Session %s using protocol version %d (client version: %d," +" server version: %d)\n" , srv_sess->sessname, + srv_sess->ver, sess_info_msg->ver,IBNBD_VER_MAJOR ); + + rsp->hdr.type =cpu_to_le16 (IBNBD_MSG_SESS_INFO_RSP ); + rsp->ver = srv_sess->ver; + +return 0 ; +} + +/** +* find_srv_sess_dev() - a dev is already opened by this name +* +* Return struct ibnbd_srv_sess_dev if srv_sess already opened the dev_name +* NULL if the session didn't open the device yet. +*/ +static struct ibnbd_srv_sess_dev * +find_srv_sess_dev (struct ibnbd_srv_session *srv_sess,const char *dev_name) +{ +struct ibnbd_srv_sess_dev *sess_dev; + +if (list_empty (&srv_sess->sess_dev_list)) +return NULL ; + +list_for_each_entry (sess_dev, &srv_sess->sess_dev_list, sess_list) +if (!strcmp (sess_dev->pathname, dev_name)) +return sess_dev; + +return NULL ; +} + +static int process_msg_open (struct ibtrs_srv *ibtrs, +struct ibnbd_srv_session *srv_sess, +const void *msg,size_t len, +void *data,size_t datalen) +{ +int ret; +struct ibnbd_srv_dev *srv_dev; +struct ibnbd_srv_sess_dev *srv_sess_dev; +const struct ibnbd_msg_open *open_msg = msg; +fmode_t open_flags; +char *full_path; +struct ibnbd_dev *ibnbd_dev; +enum ibnbd_io_mode io_mode; +struct ibnbd_msg_open_rsp *rsp = data; + +pr_debug ("Open message received: session='%s' path='%s' access_mode=%d" +" io_mode=%d\n" , srv_sess->sessname, open_msg->dev_name, + open_msg->access_mode, open_msg->io_mode); + open_flags =FMODE_READ ; +if (open_msg->access_mode !=IBNBD_ACCESS_RO ) + open_flags |=FMODE_WRITE ; + +mutex_lock (&srv_sess->lock); + + srv_sess_dev =find_srv_sess_dev (srv_sess, open_msg->dev_name); +if (srv_sess_dev) + goto fill_response; + +if ((strlen (dev_search_path) +strlen (open_msg->dev_name)) + >=PATH_MAX ) { +pr_err ("Opening device for session %s failed, device path too" +" long. '%s/%s' is longer than PATH_MAX (%d)\n" , + srv_sess->sessname, dev_search_path, open_msg->dev_name, +PATH_MAX ); + ret = -EINVAL ; + goto reject; + } + full_path =ibnbd_srv_get_full_path (open_msg->dev_name); +if (IS_ERR (full_path)) { + ret =PTR_ERR (full_path); +pr_err ("Opening device '%s' for client %s failed," +" failed to get device full path, err: %d\n" , + open_msg->dev_name, srv_sess->sessname, ret); + goto reject; + } + +if (open_msg->io_mode ==IBNBD_BLOCKIO ) + io_mode =IBNBD_BLOCKIO ; +else if (open_msg->io_mode ==IBNBD_FILEIO ) + io_mode =IBNBD_FILEIO ; +else + io_mode = def_io_mode; + + ibnbd_dev =ibnbd_dev_open (full_path, open_flags, io_mode, + srv_sess->sess_bio_set, ibnbd_endio); +if (IS_ERR (ibnbd_dev)) { +pr_err ("Opening device '%s' on session %s failed," +" failed to open the block device, err: %ld\n" , + full_path, srv_sess->sessname,PTR_ERR (ibnbd_dev)); + ret =PTR_ERR (ibnbd_dev); + goto free_path; + } + + srv_dev =ibnbd_srv_get_or_create_srv_dev (ibnbd_dev, srv_sess, io_mode, + open_msg->access_mode); +if (IS_ERR (srv_dev)) { +pr_err ("Opening device '%s' on session %s failed," +" creating srv_dev failed, err: %ld\n" , + full_path, srv_sess->sessname,PTR_ERR (srv_dev)); + ret =PTR_ERR (srv_dev); + goto ibnbd_dev_close; + } + + srv_sess_dev =ibnbd_srv_create_set_sess_dev (srv_sess, open_msg, + ibnbd_dev, open_flags, + srv_dev); +if (IS_ERR (srv_sess_dev)) { +pr_err ("Opening device '%s' on session %s failed," +" creating sess_dev failed, err: %ld\n" , + full_path, srv_sess->sessname,PTR_ERR (srv_sess_dev)); + ret =PTR_ERR (srv_sess_dev); + goto srv_dev_put; + } + +/* Create the srv_dev sysfs files if they haven't been created yet. The +* reason to delay the creation is not to create the sysfs files before +* we are sure the device can be opened. +*/ +mutex_lock (&srv_dev->lock); +if (!srv_dev->dev_kobj.state_in_sysfs) { + ret =ibnbd_srv_create_dev_sysfs (srv_dev, ibnbd_dev->bdev, + ibnbd_dev->name); +if (ret) { +mutex_unlock (&srv_dev->lock); +ibnbd_err (srv_sess_dev,"Opening device failed, failed to" +" create device sysfs files, err: %d\n" , + ret); + goto free_srv_sess_dev; + } + } + + ret =ibnbd_srv_create_dev_session_sysfs (srv_sess_dev); +if (ret) { +mutex_unlock (&srv_dev->lock); +ibnbd_err (srv_sess_dev,"Opening device failed, failed to create" +" dev client sysfs files, err: %d\n" , ret); + goto free_srv_sess_dev; + } + +list_add (&srv_sess_dev->dev_list, &srv_dev->sess_dev_list); +mutex_unlock (&srv_dev->lock); + +list_add (&srv_sess_dev->sess_list, &srv_sess->sess_dev_list); + +ibnbd_info (srv_sess_dev,"Opened device '%s' in %s mode\n" , + srv_dev->id,ibnbd_io_mode_str (io_mode)); + +kfree (full_path); + +fill_response: +ibnbd_srv_fill_msg_open_rsp (rsp, srv_sess_dev); +mutex_unlock (&srv_sess->lock); +return 0 ; + +free_srv_sess_dev: +write_lock (&srv_sess->index_lock); +idr_remove (&srv_sess->index_idr, srv_sess_dev->device_id); +write_unlock (&srv_sess->index_lock); +kfree (srv_sess_dev); +srv_dev_put: +if (open_msg->access_mode !=IBNBD_ACCESS_RO ) { +mutex_lock (&srv_dev->lock); + srv_dev->open_write_cnt--; +mutex_unlock (&srv_dev->lock); + } +ibnbd_put_srv_dev (srv_dev); +ibnbd_dev_close: +ibnbd_dev_close (ibnbd_dev); +free_path: +kfree (full_path); +reject: +mutex_unlock (&srv_sess->lock); +return ret; +} + +static struct ibtrs_srv_ctx *ibtrs_ctx; + +static int __init ibnbd_srv_init_module (void ) +{ +int err; + +pr_info ("Loading module %s, version %s\n" , +KBUILD_MODNAME ,IBNBD_VER_STRING ); + + ibtrs_ctx =ibtrs_srv_open (ibnbd_srv_rdma_ev, ibnbd_srv_link_ev, +IBTRS_PORT ); +if (unlikely (IS_ERR (ibtrs_ctx))) { + err =PTR_ERR (ibtrs_ctx); +pr_err ("ibtrs_srv_open(), err: %d\n" , err); + goto out; + } + err =ibnbd_dev_init (); +if (err) { +pr_err ("ibnbd_dev_init(), err: %d\n" , err); + goto srv_close; + } + + err =ibnbd_srv_create_sysfs_files (); +if (err) { +pr_err ("ibnbd_srv_create_sysfs_files(), err: %d\n" , err); + goto dev_destroy; + } + +return 0 ; + +dev_destroy: +ibnbd_dev_destroy (); +srv_close: +ibtrs_srv_close (ibtrs_ctx); +out: + +return err; +} + +static void __exit ibnbd_srv_cleanup_module(void) +{ +ibtrs_srv_close (ibtrs_ctx); +WARN_ON (!list_empty (&sess_list)); +ibnbd_srv_destroy_sysfs_files (); +ibnbd_dev_destroy (); +pr_info ("Module unloaded\n" ); +} + +module_init (ibnbd_srv_init_module); +module_exit (ibnbd_srv_cleanup_module);
Signature · 1 line
2.13.1
PATCH 20/24 ibnbd: server: functionality for IO submission to file or block dev
In reply to Roman PenThis provides helper functions for IO submission to file or block dev.
--- drivers/block/ibnbd/ibnbd-srv-dev.c | 410 ++++++++++++++++++++++++++++++++++++ drivers/block/ibnbd/ibnbd-srv-dev.h | 149 +++++++++++++ 2 files changed, 559 insertions(+)
drivers/block/ibnbd/ibnbd-srv-dev.c new file +410 -0
@@ -0,0 +1,410 @@ +/* +* InfiniBand Network Block Driver +* +* Copyright (c) 2014 - 2017 ProfitBricks GmbH. All rights reserved. +* Authors: Fabian Holler <[email protected]> +* Jack Wang <[email protected]> +* Kleber Souza <[email protected]> +* Danil Kipnis <[email protected]> +* Roman Penyaev <[email protected]> +* Milind Dumbare <[email protected]> +* +* Copyright (c) 2017 - 2018 ProfitBricks GmbH. All rights reserved. +* Authors: Danil Kipnis <[email protected]> +* Roman Penyaev <[email protected]> +* +* 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; either version 2 +* of the License, or (at your option) any later version. +* +* 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#undef pr_fmt +#define pr_fmt (fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt + +#include "ibnbd-srv-dev.h" +#include "ibnbd-log.h" + +#define IBNBD_DEV_MAX_FILEIO_ACTIVE_WORKERS 0 + +struct ibnbd_dev_file_io_work { +struct ibnbd_dev *dev; +void *priv; + +sector_t sector; +void *data; +size_t len; +size_t bi_size; +enum ibnbd_io_flags flags; + +struct work_struct work; +}; + +struct ibnbd_dev_blk_io { +struct ibnbd_dev *dev; +void *priv; +}; + +static struct workqueue_struct *fileio_wq; + +int ibnbd_dev_init (void ) +{ + fileio_wq =alloc_workqueue ("%s" ,WQ_UNBOUND , +IBNBD_DEV_MAX_FILEIO_ACTIVE_WORKERS , +"ibnbd_server_fileio_wq" ); +if (!fileio_wq) +return -ENOMEM ; + +return 0 ; +} + +void ibnbd_dev_destroy (void ) +{ +destroy_workqueue (fileio_wq); +} + +static inline struct block_device *ibnbd_dev_open_bdev (const char *path, +fmode_t flags) +{ +return blkdev_get_by_path (path, flags,THIS_MODULE ); +} + +static int ibnbd_dev_blk_open (struct ibnbd_dev *dev,const char *path, +fmode_t flags) +{ + dev->bdev =ibnbd_dev_open_bdev (path, flags); +return PTR_ERR_OR_ZERO (dev->bdev); +} + +static int ibnbd_dev_vfs_open (struct ibnbd_dev *dev,const char *path, +fmode_t flags) +{ +int oflags =O_DSYNC ;/* enable write-through */ + +if (flags &FMODE_WRITE ) + oflags |=O_RDWR ; +else if (flags &FMODE_READ ) + oflags |=O_RDONLY ; +else +return -EINVAL ; + + dev->file =filp_open (path, oflags,0 ); +return PTR_ERR_OR_ZERO (dev->file); +} + +struct ibnbd_dev *ibnbd_dev_open (const char *path,fmode_t flags, +enum ibnbd_io_mode mode,struct bio_set *bs, +ibnbd_dev_io_fn io_cb) +{ +struct ibnbd_dev *dev; +int ret; + + dev =kzalloc (sizeof (*dev),GFP_KERNEL ); +if (!dev) +return ERR_PTR (-ENOMEM ); + +if (mode ==IBNBD_BLOCKIO ) { + dev->blk_open_flags = flags; + ret =ibnbd_dev_blk_open (dev, path, dev->blk_open_flags); +if (ret) + goto err; + }else if (mode ==IBNBD_FILEIO ) { + dev->blk_open_flags =FMODE_READ ; + ret =ibnbd_dev_blk_open (dev, path, dev->blk_open_flags); +if (ret) + goto err; + + ret =ibnbd_dev_vfs_open (dev, path, flags); +if (ret) + goto blk_put; + } + + dev->blk_open_flags = flags; + dev->mode = mode; + dev->io_cb = io_cb; +bdevname (dev->bdev, dev->name); + dev->ibd_bio_set = bs; + +return dev; + +blk_put: +blkdev_put (dev->bdev, dev->blk_open_flags); +err: +kfree (dev); +return ERR_PTR (ret); +} + +void ibnbd_dev_close (struct ibnbd_dev *dev) +{ +flush_workqueue (fileio_wq); +blkdev_put (dev->bdev, dev->blk_open_flags); +if (dev->mode ==IBNBD_FILEIO ) +filp_close (dev->file, dev->file); +kfree (dev); +} + +static void ibnbd_dev_bi_end_io (struct bio *bio) +{ +struct ibnbd_dev_blk_io *io = bio->bi_private; + + io->dev->io_cb (io->priv,blk_status_to_errno (bio->bi_status)); +bio_put (bio); +kfree (io); +} + +static void bio_map_kern_endio (struct bio *bio) +{ +bio_put (bio); +} + +/** +* ibnbd_bio_map_kern - map kernel address into bio +* @q: the struct request_queue for the bio +* @data: pointer to buffer to map +* @bs: bio_set to use. +* @len: length in bytes +* @gfp_mask: allocation flags for bio allocation +* +* Map the kernel address into a bio suitable for io to a block +* device. Returns an error pointer in case of error. +*/ +static struct bio *ibnbd_bio_map_kern (struct request_queue *q,void *data, +struct bio_set *bs, +unsigned int len,gfp_t gfp_mask) +{ +unsigned long kaddr = (unsigned long )data; +unsigned long end = (kaddr + len +PAGE_SIZE -1 ) >>PAGE_SHIFT ; +unsigned long start = kaddr >>PAGE_SHIFT ; +const int nr_pages = end - start; +int offset, i; +struct bio *bio; + + bio =bio_alloc_bioset (gfp_mask, nr_pages, bs); +if (!bio) +return ERR_PTR (-ENOMEM ); + + offset =offset_in_page (kaddr); +for (i =0 ; i < nr_pages; i++) { +unsigned int bytes =PAGE_SIZE - offset; + +if (len <=0 ) +break ; + +if (bytes > len) + bytes = len; + +if (bio_add_pc_page (q, bio,virt_to_page (data), bytes, + offset) < bytes) { +/* we don't support partial mappings */ +bio_put (bio); +return ERR_PTR (-EINVAL ); + } + + data += bytes; + len -= bytes; + offset =0 ; + } + + bio->bi_end_io = bio_map_kern_endio; +return bio; +} + +static int ibnbd_dev_blk_submit_io (struct ibnbd_dev *dev,sector_t sector, +void *data,size_t len,u32 bi_size, +enum ibnbd_io_flags flags,void *priv) +{ +struct request_queue *q =bdev_get_queue (dev->bdev); +struct ibnbd_dev_blk_io *io; +struct bio *bio; + +/* check if the buffer is suitable for bdev */ +if (unlikely (WARN_ON (!blk_rq_aligned (q, (unsigned long )data, len)))) +return -EINVAL ; + +/* Generate bio with pages pointing to the rdma buffer */ + bio =ibnbd_bio_map_kern (q, data, dev->ibd_bio_set, len,GFP_KERNEL ); +if (unlikely (IS_ERR (bio))) +return PTR_ERR (bio); + + io =kmalloc (sizeof (*io),GFP_KERNEL ); +if (unlikely (!io)) { +bio_put (bio); +return -ENOMEM ; + } + + io->dev = dev; + io->priv = priv; + + bio->bi_end_io = ibnbd_dev_bi_end_io; + bio->bi_private = io; + bio->bi_opf =ibnbd_to_bio_flags (flags); + bio->bi_iter.bi_sector = sector; + bio->bi_iter.bi_size = bi_size; +bio_set_dev (bio, dev->bdev); + +submit_bio (bio); + +return 0 ; +} + +static int ibnbd_dev_file_handle_flush (struct ibnbd_dev_file_io_work *w, +loff_t start) +{ +int ret; +loff_t end; +int len = w->bi_size; + +if (len) + end = start + len -1 ; +else + end =LLONG_MAX ; + + ret =vfs_fsync_range (w->dev->file, start, end,1 ); +if (unlikely (ret)) +pr_info_ratelimited ("I/O FLUSH failed on %s, vfs_sync err: %d\n" , + w->dev->name, ret); +return ret; +} + +static int ibnbd_dev_file_handle_fua (struct ibnbd_dev_file_io_work *w, +loff_t start) +{ +int ret; +loff_t end; +int len = w->bi_size; + +if (len) + end = start + len -1 ; +else + end =LLONG_MAX ; + + ret =vfs_fsync_range (w->dev->file, start, end,1 ); +if (unlikely (ret)) +pr_info_ratelimited ("I/O FUA failed on %s, vfs_sync err: %d\n" , + w->dev->name, ret); +return ret; +} + +static int ibnbd_dev_file_handle_write_same (struct ibnbd_dev_file_io_work *w) +{ +int i; + +if (unlikely (WARN_ON (w->bi_size % w->len))) +return -EINVAL ; + +for (i =1 ; i < w->bi_size / w->len; i++) +memcpy (w->data + i * w->len, w->data, w->len); + +return 0 ; +} + +static void ibnbd_dev_file_submit_io_worker (struct work_struct *w) +{ +struct ibnbd_dev_file_io_work *dev_work; +struct file *f; +int ret, len; +loff_t off; + + dev_work = container_of(w, struct ibnbd_dev_file_io_work, work); + off = dev_work->sector *ibnbd_dev_get_logical_bsize (dev_work->dev); + f = dev_work->dev->file; + len = dev_work->bi_size; + +if (ibnbd_op (dev_work->flags) ==IBNBD_OP_FLUSH ) { + ret =ibnbd_dev_file_handle_flush (dev_work, off); +if (unlikely (ret)) + goto out; + } + +if (ibnbd_op (dev_work->flags) ==IBNBD_OP_WRITE_SAME ) { + ret =ibnbd_dev_file_handle_write_same (dev_work); +if (unlikely (ret)) + goto out; + } + +/* TODO Implement support for DIRECT */ +if (dev_work->bi_size) { +loff_t off_tmp = off; + +if (ibnbd_op (dev_work->flags) ==IBNBD_OP_WRITE ) + ret =kernel_write (f, dev_work->data, dev_work->bi_size, + &off_tmp); +else + ret =kernel_read (f, dev_work->data, dev_work->bi_size, + &off_tmp); + +if (unlikely (ret <0 )) { + goto out; + }else if (unlikely (ret != dev_work->bi_size)) { +/* TODO implement support for partial completions */ + ret = -EIO ; + goto out; + }else { + ret =0 ; + } + } + +if (dev_work->flags &IBNBD_F_FUA ) + ret =ibnbd_dev_file_handle_fua (dev_work, off); +out: + dev_work->dev->io_cb (dev_work->priv, ret); +kfree (dev_work); +} + +static int ibnbd_dev_file_submit_io (struct ibnbd_dev *dev,sector_t sector, +void *data,size_t len,size_t bi_size, +enum ibnbd_io_flags flags,void *priv) +{ +struct ibnbd_dev_file_io_work *w; + +if (!ibnbd_flags_supported (flags)) { +pr_info_ratelimited ("Unsupported I/O flags: 0x%x on device " +"%s\n" , flags, dev->name); +return -ENOTSUPP ; + } + + w =kmalloc (sizeof (*w),GFP_KERNEL ); +if (!w) +return -ENOMEM ; + + w->dev = dev; + w->priv = priv; + w->sector = sector; + w->data = data; + w->len = len; + w->bi_size = bi_size; + w->flags = flags; +INIT_WORK (&w->work, ibnbd_dev_file_submit_io_worker); + +if (unlikely (!queue_work (fileio_wq, &w->work))) { +kfree (w); +return -EEXIST ; + } + +return 0 ; +} + +int ibnbd_dev_submit_io (struct ibnbd_dev *dev,sector_t sector,void *data, +size_t len,u32 bi_size,enum ibnbd_io_flags flags, +void *priv) +{ +if (dev->mode ==IBNBD_FILEIO ) +return ibnbd_dev_file_submit_io (dev, sector, data, len, bi_size, + flags, priv); +else if (dev->mode ==IBNBD_BLOCKIO ) +return ibnbd_dev_blk_submit_io (dev, sector, data, len, bi_size, + flags, priv); + +pr_warn ("Submitting I/O to %s failed, dev->mode contains invalid " +"value: '%d', memory corrupted?" , dev->name, dev->mode); + +return -EINVAL ; +}
drivers/block/ibnbd/ibnbd-srv-dev.h new file +149 -0
149 lines not on this page · raw message
Signature · 1 line
2.13.1
PATCH 21/24 ibnbd: server: sysfs interface functions
In reply to Roman PenThis is the sysfs interface to IBNBD mapped devices on server side:
/sys/kernel/ibnbd_server/devices/<device_name>/
|- block_dev
| *** link pointing to the corresponding block device sysfs entry
|
|- sessions/<session-name>/
| *** sessions directory
|
|- read_only
| *** is devices mapped as read only
|
|- mapping_path*** relative device path provided by the client during mapping
--- drivers/block/ibnbd/ibnbd-srv-sysfs.c | 264 ++++++++++++++++++++++++++++++++++ 1 file changed, 264 insertions(+)
drivers/block/ibnbd/ibnbd-srv-sysfs.c new file +264 -0
@@ -0,0 +1,264 @@ +/* +* InfiniBand Network Block Driver +* +* Copyright (c) 2014 - 2017 ProfitBricks GmbH. All rights reserved. +* Authors: Fabian Holler <[email protected]> +* Jack Wang <[email protected]> +* Kleber Souza <[email protected]> +* Danil Kipnis <[email protected]> +* Roman Penyaev <[email protected]> +* Milind Dumbare <[email protected]> +* +* Copyright (c) 2017 - 2018 ProfitBricks GmbH. All rights reserved. +* Authors: Danil Kipnis <[email protected]> +* Roman Penyaev <[email protected]> +* +* 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; either version 2 +* of the License, or (at your option) any later version. +* +* 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#undef pr_fmt +#define pr_fmt (fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt + +#include <uapi/linux/limits.h> +#include <linux/kobject.h> +#include <linux/sysfs.h> +#include <linux/stat.h> +#include <linux/genhd.h> +#include <linux/list.h> +#include <linux/moduleparam.h> + +#include "ibnbd-srv.h" + +static struct kobject *ibnbd_srv_kobj; +static struct kobject *ibnbd_srv_devices_kobj; + +static struct attribute *ibnbd_srv_default_dev_attrs[] = { +NULL , +}; + +static struct attribute_group ibnbd_srv_default_dev_attr_group = { + .attrs = ibnbd_srv_default_dev_attrs, +}; + +static ssize_t ibnbd_srv_attr_show (struct kobject *kobj,struct attribute *attr, +char *page) +{ +struct kobj_attribute *kattr; +int ret = -EIO ; + + kattr = container_of(attr, struct kobj_attribute, attr); +if (kattr->show) + ret = kattr->show (kobj, kattr, page); +return ret; +} + +static ssize_t ibnbd_srv_attr_store (struct kobject *kobj, +struct attribute *attr, +const char *page,size_t length) +{ +struct kobj_attribute *kattr; +int ret = -EIO ; + + kattr = container_of(attr, struct kobj_attribute, attr); +if (kattr->store) + ret = kattr->store (kobj, kattr, page, length); +return ret; +} + +static const struct sysfs_ops ibnbd_srv_sysfs_ops = { + .show = ibnbd_srv_attr_show, + .store = ibnbd_srv_attr_store, +}; + +static struct kobj_type ibnbd_srv_dev_ktype = { + .sysfs_ops = &ibnbd_srv_sysfs_ops, +}; + +static struct kobj_type ibnbd_srv_dev_sessions_ktype = { + .sysfs_ops = &ibnbd_srv_sysfs_ops, +}; + +int ibnbd_srv_create_dev_sysfs (struct ibnbd_srv_dev *dev, +struct block_device *bdev, +const char *dir_name) +{ +struct kobject *bdev_kobj; +int ret; + + ret =kobject_init_and_add (&dev->dev_kobj, &ibnbd_srv_dev_ktype, + ibnbd_srv_devices_kobj, dir_name); +if (ret) +return ret; + + ret =kobject_init_and_add (&dev->dev_sessions_kobj, + &ibnbd_srv_dev_sessions_ktype, + &dev->dev_kobj,"sessions" ); +if (ret) + goto err; + + ret =sysfs_create_group (&dev->dev_kobj, + &ibnbd_srv_default_dev_attr_group); +if (ret) + goto err2; + + bdev_kobj = &disk_to_dev (bdev->bd_disk)->kobj; + ret =sysfs_create_link (&dev->dev_kobj, bdev_kobj,"block_dev" ); +if (ret) + goto err3; + +return 0 ; + +err3: +sysfs_remove_group (&dev->dev_kobj, + &ibnbd_srv_default_dev_attr_group); +err2: +kobject_del (&dev->dev_sessions_kobj); +kobject_put (&dev->dev_sessions_kobj); +err: +kobject_del (&dev->dev_kobj); +kobject_put (&dev->dev_kobj); +return ret; +} + +void ibnbd_srv_destroy_dev_sysfs (struct ibnbd_srv_dev *dev) +{ +sysfs_remove_link (&dev->dev_kobj,"block_dev" ); +sysfs_remove_group (&dev->dev_kobj, &ibnbd_srv_default_dev_attr_group); +kobject_del (&dev->dev_sessions_kobj); +kobject_put (&dev->dev_sessions_kobj); +kobject_del (&dev->dev_kobj); +kobject_put (&dev->dev_kobj); +} + +static ssize_t ibnbd_srv_dev_session_ro_show (struct kobject *kobj, +struct kobj_attribute *attr, +char *page) +{ +struct ibnbd_srv_sess_dev *sess_dev; + + sess_dev = container_of(kobj, struct ibnbd_srv_sess_dev, kobj); + +return scnprintf (page,PAGE_SIZE ,"%s\n" , + (sess_dev->open_flags &FMODE_WRITE ) ?"0" :"1" ); +} + +static struct kobj_attribute ibnbd_srv_dev_session_ro_attr = +__ATTR (read_only,0444 , + ibnbd_srv_dev_session_ro_show, +NULL ); + +static ssize_t +ibnbd_srv_dev_session_mapping_path_show (struct kobject *kobj, +struct kobj_attribute *attr,char *page) +{ +struct ibnbd_srv_sess_dev *sess_dev; + + sess_dev = container_of(kobj, struct ibnbd_srv_sess_dev, kobj); + +return scnprintf (page,PAGE_SIZE ,"%s\n" , sess_dev->pathname); +} + +static struct kobj_attribute ibnbd_srv_dev_session_mapping_path_attr = +__ATTR (mapping_path,0444 , + ibnbd_srv_dev_session_mapping_path_show, +NULL ); + +static struct attribute *ibnbd_srv_default_dev_sessions_attrs[] = { + &ibnbd_srv_dev_session_ro_attr.attr, + &ibnbd_srv_dev_session_mapping_path_attr.attr, +NULL , +}; + +static struct attribute_group ibnbd_srv_default_dev_session_attr_group = { + .attrs = ibnbd_srv_default_dev_sessions_attrs, +}; + +void ibnbd_srv_destroy_dev_session_sysfs (struct ibnbd_srv_sess_dev *sess_dev) +{ +DECLARE_COMPLETION_ONSTACK (sysfs_compl); + +sysfs_remove_group (&sess_dev->kobj, + &ibnbd_srv_default_dev_session_attr_group); + + sess_dev->sysfs_release_compl = &sysfs_compl; +kobject_del (&sess_dev->kobj); +kobject_put (&sess_dev->kobj); +wait_for_completion (&sysfs_compl); +} + +static void ibnbd_srv_sess_dev_release (struct kobject *kobj) +{ +struct ibnbd_srv_sess_dev *sess_dev; + + sess_dev = container_of(kobj, struct ibnbd_srv_sess_dev, kobj); +if (sess_dev->sysfs_release_compl) +complete_all (sess_dev->sysfs_release_compl); +} + +static struct kobj_type ibnbd_srv_sess_dev_ktype = { + .sysfs_ops = &ibnbd_srv_sysfs_ops, + .release = ibnbd_srv_sess_dev_release, +}; + +int ibnbd_srv_create_dev_session_sysfs (struct ibnbd_srv_sess_dev *sess_dev) +{ +int ret; + + ret =kobject_init_and_add (&sess_dev->kobj, &ibnbd_srv_sess_dev_ktype, + &sess_dev->dev->dev_sessions_kobj,"%s" , + sess_dev->sess->sessname); +if (ret) +return ret; + + ret =sysfs_create_group (&sess_dev->kobj, + &ibnbd_srv_default_dev_session_attr_group); +if (ret) + goto err; + +return 0 ; + +err: +kobject_del (&sess_dev->kobj); +kobject_put (&sess_dev->kobj); + +return ret; +} + +int ibnbd_srv_create_sysfs_files (void ) +{ +int err; + + ibnbd_srv_kobj =kobject_create_and_add (KBUILD_MODNAME , kernel_kobj); +if (!ibnbd_srv_kobj) +return -ENOMEM ; + + ibnbd_srv_devices_kobj =kobject_create_and_add ("devices" , + ibnbd_srv_kobj); +if (!ibnbd_srv_devices_kobj) { + err = -ENOMEM ; + goto err; + } + +return 0 ; + +err: +kobject_put (ibnbd_srv_kobj); +return err; +} + +void ibnbd_srv_destroy_sysfs_files (void ) +{ +kobject_put (ibnbd_srv_devices_kobj); +kobject_put (ibnbd_srv_kobj); +}
Signature · 1 line
2.13.1
PATCH 22/24 ibnbd: include client and server modules into kernel compilation
In reply to Roman PenAdd IBNBD Makefile, Kconfig and also corresponding lines into upper block layer files.
--- drivers/block/Kconfig | 2 ++ drivers/block/Makefile | 1 + drivers/block/ibnbd/Kconfig | 22 ++++++++++++++++++++++ drivers/block/ibnbd/Makefile | 13 +++++++++++++ 4 files changed, 38 insertions(+)
drivers/block/Kconfig +2 -0
@@ -477,4 +477,6 @@ config BLK_DEV_RSXX To compile this driver as a module, choose M here: the module will be called rsxx. +source "drivers/block/ibnbd/Kconfig" + endif # BLK_DEV
drivers/block/Makefile +1 -0
@@ -38,6 +38,7 @@ obj-$(CONFIG_BLK_DEV_PCIESSD_MTIP32XX) += mtip32xx/ obj-$(CONFIG_BLK_DEV_RSXX) += rsxx/ obj-$(CONFIG_BLK_DEV_NULL_BLK) += null_blk.o obj-$(CONFIG_ZRAM) += zram/ +obj-$(CONFIG_BLK_DEV_IBNBD) += ibnbd/ skd-y := skd_main.o swim_mod-y := swim.o swim_asm.o
drivers/block/ibnbd/Kconfig new file +22 -0
@@ -0,0 +1,22 @@ +config BLK_DEV_IBNBD + boolean + +config BLK_DEV_IBNBD_CLIENT + tristate "Network block device driver on top of IBTRS transport" + depends on INFINIBAND_IBTRS_CLIENT + select BLK_DEV_IBNBD + help + IBNBD client allows for mapping of a remote block devices over + IBTRS protocol from a target system where IBNBD server is running. + + If unsure, say N. + +config BLK_DEV_IBNBD_SERVER + tristate "Network block device over RDMA Infiniband server support" + depends on INFINIBAND_IBTRS_SERVER + select BLK_DEV_IBNBD + help + IBNBD server allows for exporting local block devices to a remote client + over IBTRS protocol. + + If unsure, say N.
drivers/block/ibnbd/Makefile new file +13 -0
@@ -0,0 +1,13 @@ +ccflags-y := -Idrivers/infiniband/ulp/ibtrs + +ibnbd-client-y := ibnbd-clt.o \ + ibnbd-clt-sysfs.o + +ibnbd-server-y := ibnbd-srv.o \ + ibnbd-srv-dev.o \ + ibnbd-srv-sysfs.o + +obj-$(CONFIG_BLK_DEV_IBNBD_CLIENT) += ibnbd-client.o +obj-$(CONFIG_BLK_DEV_IBNBD_SERVER) += ibnbd-server.o + +-include $(src)/compat/compat.mk
Signature · 1 line
2.13.1
PATCH 23/24 ibnbd: a bit of documentation
In reply to Roman PenREADME with description of major sysfs entries.
--- drivers/block/ibnbd/README | 272 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 272 insertions(+)
drivers/block/ibnbd/README new file +272 -0
@@ -0,0 +1,272 @@ +*************************************** +Infiniband Network Block Device (IBNBD) +*************************************** + +Introduction +------------ + +IBNBD (InfiniBand Network Block Device) is a pair of kernel modules +(client and server) that allow for remote access of a block device on +the server over IBTRS protocol using the RDMA (InfiniBand, RoCE, iWarp) +transport. After being mapped, the remote block devices can be accessed +on the client side as local block devices. + +I/O is transfered between client and server by the IBTRS transport +modules. The administration of IBNBD and IBTRS modules is done via +sysfs entries. + +Requirements +------------ + + IBTRS kernel modules + +Quick Start +----------- + +Server side: + # modprobe ibnbd_server + +Client side: + # modprobe ibnbd_client + # echo "sessname=blya path=ip:10.50.100.66 device_path=/dev/ram0" > \ + /sys/kernel/ibnbd_client/map_device + + Where "sessname=" is a session name, a string to identify the session + on client and on server sides; "path=" is a destination IP address or + a pair of a source and a destination IPs, separated by comma. Multiple + "path=" options can be specified in order to use multipath (see IBTRS + description for details); "device_path=" is the block device to be + mapped from the server side. After the session to the server machine is + established, the mapped device will appear on the client side under + /dev/ibnbd<N>. + + +====================== +Client Sysfs Interface +====================== + +All sysfs files that are not read-only provide the usage information on read: + +Example: + # cat /sys/kernel/ibnbd_client/map_device + + > Usage: echo "sessname=<name of the ibtrs session> path=<[srcaddr,]dstaddr> + > [path=<[srcaddr,]dstaddr>] device_path=<full path on remote side> + > [access_mode=<ro|rw|migration>] [input_mode=<mq|rq>] + > [io_mode=<fileio|blockio>]" > map_device + > + > addr ::= [ ip:<ipv4> | ip:<ipv6> | gid:<gid> ] + +Entries under /sys/kernel/ibnbd_client/ +======================================= + +map_device (RW) +--------------- + +Expected format is the following: + + sessname=<name of the ibtrs session> + path=<[srcaddr,]dstaddr> [path=<[srcaddr,]dstaddr> ...] + device_path=<full path on remote side> + [access_mode=<ro|rw|migration>] + [input_mode=<mq|rq>] + [io_mode=<fileio|blockio>] + +Where: + +sessname: accepts a string not bigger than 256 chars, which identifies + a given session on the client and on the server. + I.e. "clt_hostname-srv_hostname" could be a natural choice. + +path: describes a connection between the client and the server by + specifying destination and, when required, the source address. + The addresses are to be provided in the following format: + + ip:<IPv6> + ip:<IPv4> + gid:<GID> + + for example: + + path=ip:10.0.0.66 + The single addr is treated as the destination. + The connection will be established to this + server from any client IP address. + + path=ip:10.0.0.66,ip:10.0.1.66 + First addr is the source address and the second + is the destination. + + If multiple "path=" options are specified multiple connection + will be established and data will be sent according to + the selected multipath policy (see IBTRS mp_policy sysfs entry + description). + +device_path: Path to the block device on the server side. Path is specified + relative to the directory on server side configured in the + 'dev_search_path' module parameter of the ibnbd_server. + The ibnbd_server prepends the <device_path> received from client + with <dev_search_path> and tries to open the + <dev_search_path>/<device_path> block device. On success, + a /dev/ibnbd<N> device file, a /sys/block/ibnbd_client/ibnbd<N>/ + directory and an entry in /sys/kernel/ibnbd_client/devices will be + created. + +access_mode: the access_mode parameter specifies if the device is to be + mapped as "ro" read-only or "rw" read-write. The server allows + a device to be exported in rw mode only once. The "migration" + access mode has to be specified if a second mapping in read-write + mode is desired. + + By default "rw" is used. + +input_mode: the input_mode parameter specifies the internal I/O + processing mode of the block device on the client. Accepts + "mq" and "rq". + + By default "mq" mode is used. + +io_mode: the io_mode parameter specifies if the device on the server + will be opened as block device "blockio" or as file "fileio". + When the device is opened as file, the VFS page cache is used + for read I/O operations, write I/O operations bypass the page + cache and go directly to disk (except meta updates, like file + access time). + + By default "blockio" mode is used. + +Exit Codes: + +If the device is already mapped it will fail with EEXIST. If the input +has an invalid format it will return EINVAL. If the device path cannot +be found on the server, it will fail with ENOENT. + +Finding device file after mapping +--------------------------------- + +After mapping, the device file can be found by: + o The symlink /sys/kernel/ibnbd_client/devices/<device_id> points to + /sys/block/<dev-name>. The last part of the symlink destination is + the same as the device name. By extracting the last part of the + path the path to the device /dev/<dev-name> can be build. + + o /dev/block/$(cat /sys/kernel/ibnbd_client/devices/<device_id>/dev) + +How to find the <device_id> of the device is described on the next +section. + +Entries under /sys/kernel/ibnbd_client/devices/ +=============================================== + +For each device mapped on the client a new symbolic link is created as +/sys/kernel/ibnbd_client/devices/<device_id>, which points to the block +device created by ibnbd (/sys/block/ibnbd<N>/). The <device_id> of each +device is created as follows: + +- If the 'device_path' provided during mapping contains slashes ("/"), + they are replaced by exclamation mark ("!") and used as as the + <device_id>. Otherwise, the <device_id> will be the same as the + "device_path" provided. + +Entries under /sys/block/ibnbd<N>/ibnbd_client/ +=============================================== + +unmap_device (RW) +----------------- + +To unmap a volume, "normal" or "force" has to be written to: + /sys/block/ibnbd<N>/ibnbd_client/unmap_device + +When "normal" is used, the operation will fail with EBUSY if any process +is using the device. When "force" is used, the device is also unmapped +when device is in use. All I/Os that are in progress will fail. + +Example: + + # echo "normal" > /sys/block/ibnbd0/ibnbd/unmap_device + +state (RO) +---------- + +The file contains the current state of the block device. The state file +returns "open" when the device is successfully mapped from the server +and accepting I/O requests. When the connection to the server gets +disconnected in case of an error (e.g. link failure), the state file +returns "closed" and all I/O requests submitted to it will fail with -EIO. + +session (RO) +------------ + +IBNBD uses IBTRS session to transport the data between client and +server. The entry "session" contains the name of the session, that +was used to establish the IBTRS session. It's the same name that +was passed as server parameter to the map_device entry. + +mapping_path (RO) +----------------- + +Contains the path that was passed as "device_path" to the map_device +operation. + +====================== +Server Sysfs Interface +====================== + +Entries under /sys/kernel/ibnbd_server/ +======================================= + +When a client maps a device, a directory entry with the name of the +block device is created under /sys/kernel/ibnbd_server/devices/. + +Entries under /sys/kernel/ibnbd_server/devices/<device_name>/ +============================================================= + +block_dev (link) +--------------- + +Is a symlink to the sysfs entry of the exported device. + +Example: + + block_dev -> ../../../../devices/virtual/block/ram0 + +Entries under /sys/kernel/ibnbd_server/devices/<device_name>/sessions/ +====================================================================== + +For each client a particular device is exported to, following directory will be +created: + +/sys/kernel/ibnbd_server/devices/<device_name>/sessions/<session-name>/ + +When the device is unmapped by that client, the directory will be removed. + +Entries under /sys/kernel/ibnbd_server/devices/<device_name>/sessions/<session-name> +==================================================================================== + +read_only (RO) +-------------- + +Contains '1' if device is mapped read-only, otherwise '0'. + +mapping_path (RO) +----------------- + +Contains the relative device path provided by the user during mapping. + +============================== +IBNBD-Server Module Parameters +============================== + +dev_search_path +--------------- + +When a device is mapped from the client, the server generates the path +to the block device on the server side by concatenating dev_search_path +and the "device_path" that was specified in the map_device operation. + +The default dev_search_path is: "/". + +Contact +------- + +Mailing list: "IBNBD/IBTRS Storage Team" <[email protected]>
Signature · 1 line
2.13.1
Re: [PATCH 23/24] ibnbd: a bit of documentation
T24gRnJpLCAyMDE4LTAyLTAyIGF0IDE1OjA5ICswMTAwLCBSb21hbiBQZW4gd3JvdGU6DQo+ICtF bnRyaWVzIHVuZGVyIC9zeXMva2VybmVsL2libmJkX2NsaWVudC8NCj4gKz09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PQ0KPiBbIC4uLiBdDQoNCllvdSB3aWxsIG5lZWQgR3Jl ZyBLSCdzIHBlcm1pc3Npb24gdG8gYWRkIG5ldyBlbnRyaWVzIGRpcmVjdGx5IHVuZGVyIC9zeXMv a2VybmVsLg0KU2luY2UgSSB0aGluayB0aGF0IGl0IGlzIHVubGlrZWx5IHRoYXQgaGUgd2lsbCBn aXZlIHRoYXQgcGVybWlzc2lvbjogaGF2ZSB5b3UNCmNvbnNpZGVyZWQgdG8gYWRkIHRoZSBuZXcg Y2xpZW50IGVudHJpZXMgdW5kZXIgL3N5cy9jbGFzcy9ibG9jayBmb3IgdGhlIGNsaWVudCBhbmQN Ci9zeXMva2VybmVsL2NvbmZpZ2ZzL2libmJkIGZvciB0aGUgdGFyZ2V0LCBzaW1pbGFyIHRvIHdo YXQgdGhlIE5WTWVPRiBkcml2ZXJzIGRvDQp0b2RheT8NCg0KQmFydC4=
Re: [PATCH 23/24] ibnbd: a bit of documentation
Quoted 10 lines · Bart Van Assche
Quoted 3 lines · Roman Pen
+Entries under
/sys/kernel/ibnbd_client/
+=======================================
[ ... ]You will need Greg KH's permission to add new entries directly under
/sys/kernel. Since I think that it is unlikely that he will give that permission: have you considered to add the new client entries under/sys/class/blockfor the client and/sys/kernel/configfs/ibnbdfor the target, similar to what the NVMeOF drivers do today?
/sys/kernel was chosen ages ago and I completely forgot to move it to configfs. IBTRS is not a block device, so for some read-only entries (statistics or states)
something else should be probably used, not configfs. Or it is fine to read state
of the connection from configfs? For me sounds a bit weird.
--
Roman
Re: [PATCH 23/24] ibnbd: a bit of documentation
Quoted 7 lines
/sys/kernelwas chosen ages ago and I completely forgot to move it to configfs. IBTRS is not a block device, so for some read-only entries (statistics or states)
something else should be probably used, not configfs. Or it is fine to read state
of the connection from configfs? For me sounds a bit weird.
Configs go via configfs, states and alike go to sysfs (but you need your own class device).
PATCH 24/24 MAINTAINERS: Add maintainer for IBNBD/IBTRS modules
In reply to Roman Pen--- MAINTAINERS | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
MAINTAINERS +14 -0
@@ -6714,6 +6714,20 @@ IBM ServeRAID RAID DRIVER S: Orphan F: drivers/scsi/ips.* +IBNBD BLOCK DRIVERS +M: IBNBD/IBTRS Storage Team <[email protected]> +L: [email protected] +S: Maintained +T: git git://github.com/profitbricks/ibnbd.git +F: drivers/block/ibnbd/ + +IBTRS TRANSPORT DRIVERS +M: IBNBD/IBTRS Storage Team <[email protected]> +L: [email protected] +S: Maintained +T: git git://github.com/profitbricks/ibnbd.git +F: drivers/infiniband/ulp/ibtrs/ + ICH LPC AND GPIO DRIVER M: Peter Tyser <[email protected]> S: Maintained
Signature · 1 line
2.13.1
T24gRnJpLCAyMDE4LTAyLTAyIGF0IDE1OjA4ICswMTAwLCBSb21hbiBQZW4gd3JvdGU6DQo+IFNp bmNlIHRoZSBmaXJzdCB2ZXJzaW9uIHRoZSBmb2xsb3dpbmcgd2FzIGNoYW5nZWQ6DQo+IA0KPiAg ICAtIExvYWQtYmFsYW5jaW5nIGFuZCBJTyBmYWlsLW92ZXIgdXNpbmcgbXVsdGlwYXRoIGZlYXR1 cmVzIHdlcmUgYWRkZWQuDQo+ICAgIC0gTWFqb3IgcGFydHMgb2YgdGhlIGNvZGUgd2VyZSByZXdy aXR0ZW4sIHNpbXBsaWZpZWQgYW5kIG92ZXJhbGwgY29kZQ0KPiAgICAgIHNpemUgd2FzIHJlZHVj ZWQgYnkgYSBxdWFydGVyLg0KDQpUaGF0IGlzIGludGVyZXN0aW5nIHRvIGtub3csIGJ1dCB3aGF0 IGhhcHBlbmVkIHRvIHRoZSBmZWVkYmFjayB0aGF0IFNhZ2kgYW5kDQpJIHByb3ZpZGVkIG9uIHYx PyBIYXMgdGhhdCBmZWVkYmFjayBiZWVuIGFkZHJlc3NlZD8gU2VlIGFsc28NCmh0dHBzOi8vd3d3 LnNwaW5pY3MubmV0L2xpc3RzL2xpbnV4LXJkbWEvbXNnNDc4MTkuaHRtbCBhbmQNCmh0dHBzOi8v d3d3LnNwaW5pY3MubmV0L2xpc3RzL2xpbnV4LXJkbWEvbXNnNDc4NzkuaHRtbC4NCg0KUmVnYXJk aW5nIG11bHRpcGF0aCBzdXBwb3J0OiB0aGVyZSBhcmUgYWxyZWFkeSB0d28gbXVsdGlwYXRoIGlt cGxlbWVudGF0aW9ucw0KdXBzdHJlYW0gKGRtLW1wYXRoIGFuZCB0aGUgbXVsdGlwYXRoIGltcGxl bWVudGF0aW9uIGluIHRoZSBOVk1lIGluaXRpYXRvcikuDQpJJ20gbm90IHN1cmUgd2Ugd2FudCBh IHRoaXJkIG11bHRpcGF0aCBpbXBsZW1lbnRhdGlvbiBpbiB0aGUgTGludXgga2VybmVsLg0KDQpU aGFua3MsDQoNCkJhcnQu
Quoted 7 lines · Bart Van Assche
Quoted 5 lines · Roman Pen
Since the first version the following was changed:
- Load-balancing and IO fail-over using multipath features were added.
- Major parts of the code were rewritten, simplified and overall code size was reduced by a quarter.
Quoted 8 lines
That is interesting to know, but what happened to the feedback that Sagi and I provided on v1? Has that feedback been addressed? See also
https://www.spinics.net/lists/linux-rdma/msg47819.html and
https://www.spinics.net/lists/linux-rdma/msg47879.html.Regarding multipath support: there are already two multipath implementations upstream (dm-mpath and the multipath implementation in the NVMe initiator). I'm not sure we want a third multipath implementation in the Linux kernel.
There's more than that. There was also md-multipath, and smc-r includes another version of multipath, plus I assume we support mptcp as well.
But, to be fair, the different multipaths in this list serve different purposes and I'm not sure they could all be generalized out and served by a single multipath code. Although, fortunately, md-multipath is deprecated, so no need to worry about it, and it is only dm-multipath and nvme multipath that deal directly with block devices and assume block semantics. If I read the cover letter right (and I haven't dug into the code to confirm this), the ibtrs multipath has much more in common with smc-r multipath, where it doesn't really assume a block layer device sits on top of it, it's more of a pure network multipath, which the implementation of smc-r is and mptcp would be too. I would like to see a core RDMA multipath implementation soon that would abstract out some of these multipath tasks, at least across RDMA links, and that didn't have the current limitations (smc-r only supports RoCE links, and it sounds like ibtrs only supports IB like links, but maybe I'm wrong there, I haven't looked at the patches yet).
Signature · 3 lines
Doug Ledford <[email protected]> GPG KeyID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD
Quoted 20 lines · Doug Ledford
Quoted 7 lines · Bart Van Assche
Quoted 5 lines · Roman Pen
Since the first version the following was changed:
- Load-balancing and IO fail-over using multipath features were added.
- Major parts of the code were rewritten, simplified and overall code size was reduced by a quarter.Quoted 8 lines
That is interesting to know, but what happened to the feedback that Sagi and I provided on v1? Has that feedback been addressed? See also
https://www.spinics.net/lists/linux-rdma/msg47819.html and
https://www.spinics.net/lists/linux-rdma/msg47879.html.Regarding multipath support: there are already two multipath implementations upstream (dm-mpath and the multipath implementation in the NVMe initiator). I'm not sure we want a third multipath implementation in the Linux kernel.
There's more than that. There was also md-multipath, and smc-r includes another version of multipath, plus I assume we support mptcp as well.
Quoted 15 lines
But, to be fair, the different multipaths in this list serve different purposes and I'm not sure they could all be generalized out and served by a single multipath code. Although, fortunately, md-multipath is deprecated, so no need to worry about it, and it is only dm-multipath and nvme multipath that deal directly with block devices and assume block semantics. If I read the cover letter right (and I haven't dug into the code to confirm this), the ibtrs multipath has much more in common with smc-r multipath, where it doesn't really assume a block layer device sits on top of it, it's more of a pure network multipath, which the implementation of smc-r is and mptcp would be too. I would like to see a core RDMA multipath implementation soon that would abstract out some of these multipath tasks, at least across RDMA links, and that didn't have the current limitations (smc-r only supports RoCE links, and it sounds like ibtrs only supports IB like links, but maybe I'm wrong there, I haven't looked at the patches yet).
Hi Doug, hi Bart,
Thanks for your valuable input, here is my 2 cents:
IBTRS multipath is indeed a network multipath, with sysfs interface to remove/add path dynamically.
IBTRS is built on rdma-cm, so expect to support RoCE and iWARP, but we mainly tested in IB environment,
slightly tested on RXE.
Regards,
Signature · 2 lines
Jack Wang Linux Kernel Developer
Hi Doug,
thanks for the feedback. You read the cover letter correctly: our transport library implements multipath (load balancing and failover) on top of RDMA API. Its name "IBTRS" is slightly misleading in that regard: it can sit on top of ROCE as well. The library allows for "bundling" multiple rdma "paths" (source addr - destination addr pair) into one "session". So our session consists of one or more paths and each path under the hood consists of as many QPs (each connecting source with destination) as there are CPUs on the client system. The user load (In our case IBNBD is a block device and generates some block requests) is load-balanced on per cpu-basis. I understand, this is something very different to what smc-r is doing. Am I right? Do you know what stage MP-RDMA development currently is?
Best,
Danil Kipnis.
Quoted 46 lines · Doug Ledford
Quoted 4 lines · Bart Van Assche
Quoted 3 lines · Roman Pen
Since the first version the following was changed:
- Load-balancing and IO fail-over using multipath features were
added.
Quoted 1 line
Quoted 1 line
- Major parts of the code were rewritten, simplified and overall
code
Quoted 3 lines
Quoted 1 line
size was reduced by a quarter.
That is interesting to know, but what happened to the feedback that Sagi
and
Quoted 5 lines
I provided on v1? Has that feedback been addressed? See also
https://www.spinics.net/lists/linux-rdma/msg47819.html and
https://www.spinics.net/lists/linux-rdma/msg47879.html.Regarding multipath support: there are already two multipath
implementations
Quoted 1 line
upstream (dm-mpath and the multipath implementation in the NVMe
initiator).
Quoted 1 line
I'm not sure we want a third multipath implementation in the Linux
kernel.
There's more than that. There was also md-multipath, and smc-r includes another version of multipath, plus I assume we support mptcp as well.
But, to be fair, the different multipaths in this list serve different purposes and I'm not sure they could all be generalized out and served by a single multipath code. Although, fortunately, md-multipath is deprecated, so no need to worry about it, and it is only dm-multipath and nvme multipath that deal directly with block devices and assume block semantics. If I read the cover letter right (and I haven't dug into the code to confirm this), the ibtrs multipath has much more in common with smc-r multipath, where it doesn't really assume a block layer device sits on top of it, it's more of a pure network multipath, which the implementation of smc-r is and mptcp would be too. I would like to see a core RDMA multipath implementation soon that would abstract out some of these multipath tasks, at least across RDMA links, and that didn't have the current limitations (smc-r only supports RoCE links, and it sounds like ibtrs only supports IB like links, but maybe I'm wrong there, I haven't looked at the patches yet).
--
Doug Ledford <[email protected]>GPG KeyID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD
T24gRnJpLCAyMDE4LTAyLTAyIGF0IDE1OjA4ICswMTAwLCBSb21hbiBQZW4gd3JvdGU6DQo+IG8g U2ltcGxlIGNvbmZpZ3VyYXRpb24gb2YgSUJOQkQ6DQo+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CBhbmQgY29uZmlndXJlZCBiZWZvcmUgdGhlIEdJRCBoYXMg YmVlbiBhc3NpZ25lZCB0bw0KYWxsIFJETUEgcG9ydHMuDQoNClRoYW5rcywNCg0KQmFydC4=
Hi Bart,
My another 2 cents:)
Quoted 8 lines · Bart Van Assche
Quoted 3 lines · Roman Pen
o Simple configuration of IBNBD:
- Server side is completely passive: volumes do not need to be explicitly exported.That sounds like a security hole? I think the ability to configure whether or not an initiator is allowed to log in is essential and also which volumes an initiator has access to.
Our design target for well controlled production environment, so security is handle in other layer.
On server side, admin can set the dev_search_path in module parameter to set parent directory,
this will concatenate with the path client send in open message to open a block device.
Quoted 12 lines
Quoted 3 lines
- Only IB port GID and device path needed on client side to map a block device.
I think IP addressing is preferred over GID addressing in RoCE networks. Additionally, have you noticed that GUID configuration support has been added to the upstream
ib_srptdriver? Using GIDs has a very important disadvantage, namely that at least in IB networks the prefix will change if the subnet manager is reconfigured. Additionally, in IB networks it may happen that the target driver is loaded and configured before the GID has been assigned to all RDMA ports.
Quoted 3 lines
Thanks,
Bart.
Sorry, the above description is not accurate, IBNBD/IBTRS support GID/IPv4/IPv6 addressing.
We will adjust in next post.
Thanks,
Signature · 2 lines
Jack Wang Linux Kernel Developer
Quoted 10 lines
Hi Bart,
My another 2 cents:)
Quoted 5 lines · Bart Van Assche
Quoted 3 lines · Roman Pen
o Simple configuration of IBNBD:
- Server side is completely passive: volumes do not need to be explicitly exported.
Quoted 5 lines
Quoted 3 lines
That sounds like a security hole? I think the ability to configure whether or not an initiator is allowed to log in is essential and also which volumes an initiator has access to.
Our design target for well controlled production environment, so security is handle in other layer.
What will happen to a new adopter of the code you are contributing?
Quoted 20 lines
Quoted 20 lines
Hi Bart,
My another 2 cents:)
Quoted 13 lines · Bart Van Assche
Quoted 4 lines · Roman Pen
o Simple configuration of IBNBD:
- Server side is completely passive: volumes do not need to be explicitly exported.That sounds like a security hole? I think the ability to configure whether or
not an initiator is allowed to log in is essential and also which volumes an
initiator has access to.
Quoted 5 lines
Quoted 2 lines
Our design target for well controlled production environment, so security is handle in other layer.
What will happen to a new adopter of the code you are contributing?
Hi Sagi, Hi Bart,
thanks for your feedback.
We considered the "storage cluster" setup, where each ibnbd client has access to each ibnbd server. Each ibnbd server manages devices under his "dev_search_path" and can provide access to them to any ibnbd client in the network. On top of that Ibnbd server has an additional "artificial" restriction, that a device can be mapped in writable-mode by only one client at once.
Signature · 1 line
Danil
Quoted 24 lines
Quoted 24 lines
Quoted 22 lines
Hi Bart,
My another 2 cents:)
Quoted 8 lines · Bart Van Assche
Quoted 4 lines · Roman Pen
o Simple configuration of IBNBD:
- Server side is completely passive: volumes do not need to be explicitly exported.Quoted 5 lines
That sounds like a security hole? I think the ability to configure whether or
not an initiator is allowed to log in is essential and also which volumes an
initiator has access to.Our design target for well controlled production environment, so security is handle in other layer.
Quoted 8 lines
Quoted 1 line
What will happen to a new adopter of the code you are contributing?
Hi Sagi, Hi Bart,
thanks for your feedback.
We considered the "storage cluster" setup, where each ibnbd client has access to each ibnbd server. Each ibnbd server manages devices under his "dev_search_path" and can provide access to them to any ibnbd client in the network.
I don't understand how that helps?
Quoted 3 lines
On top of that Ibnbd server has an additional
"artificial" restriction, that a device can be mapped in writable-mode by only one client at once.
I think one would still need the option to disallow readable export as well.
Quoted 43 lines · Sagi Grimberg
Quoted 33 lines
Quoted 25 lines
Quoted 25 lines
Hi Bart,
My another 2 cents:)
Quoted 17 lines · Bart Van Assche
Quoted 5 lines · Roman Pen
o Simple configuration of IBNBD:
- Server side is completely passive: volumes do not need to be explicitly exported.That sounds like a security hole? I think the ability to configure whether or
not an initiator is allowed to log in is essential and also which volumes
an
initiator has access to.Quoted 6 lines
Quoted 2 lines
Our design target for well controlled production environment, so security is handle in other layer.
What will happen to a new adopter of the code you are contributing?
Quoted 6 lines
Hi Sagi, Hi Bart,
thanks for your feedback.
We considered the "storage cluster" setup, where each ibnbd client has access to each ibnbd server. Each ibnbd server manages devices under his "dev_search_path" and can provide access to them to any ibnbd client in the network.I don't understand how that helps?
Quoted 7 lines
Quoted 3 lines
On top of that Ibnbd server has an additional
"artificial" restriction, that a device can be mapped in writable-mode by only one client at once.I think one would still need the option to disallow readable export as well.
It just occurred to me, that we could easily extend the interface in such a way that each client (i.e. each session) would have on server side her own directory with the devices it can access. I.e. instead of just "dev_search_path" per server, any client would be able to only access devices under <dev_search_path>/session_name. (session name must already be generated by each client in a unique way). This way one could have an explicit control over which devices can be accessed by which clients. Do you think that would do it?
Quoted 8 lines · Danil Kipnis
It just occurred to me, that we could easily extend the interface in such a way that each client (i.e. each session) would have on server side her own directory with the devices it can access. I.e. instead of just "
dev_search_path" per server, any client would be able to only access devices under <dev_search_path>/session_name. (session name must already be generated by each client in a unique way). This way one could have an explicit control over which devices can be accessed by which clients. Do you think that would do it?
Hello Danil,
That sounds interesting to me. However, I think that approach requires to configure client access completely before the kernel target side module is loaded. It does not allow to configure permissions dynamically after the kernel target module has been loaded. Additionally, I don't see how to support attributes per (initiator, block device) pair with that approach. LIO e.g. supports the /sys/kernel/config/target/srpt/*/*/acls/*/lun_*/write_protect attribute. You may want to implement similar functionality if you want to convince more users to use IBNBD.
Thanks,
Bart.
Quoted 24 lines · Bart Van Assche
Quoted 9 lines · Danil Kipnis
It just occurred to me, that we could easily extend the interface in such a way that each client (i.e. each session) would have on server side her own directory with the devices it can access. I.e. instead of just "
dev_search_path" per server, any client would be able to only access devices under <dev_search_path>/session_name. (session name must already be generated by each client in a unique way). This way one could have an explicit control over which devices can be accessed by which clients. Do you think that would do it?Hello Danil,
That sounds interesting to me. However, I think that approach requires to configure client access completely before the kernel target side module is loaded. It does not allow to configure permissions dynamically after the kernel target module has been loaded. Additionally, I don't see how to support attributes per (initiator, block device) pair with that approach. LIO e.g. supports the
/sys/kernel/config/target/srpt/*/*/acls/*/lun_*/write_protectattribute. You may want to implement similar functionality if you want to convince more users to use IBNBD.
Quoted 3 lines
Thanks,
Bart.
Hello Bart,
the configuration (which devices can be accessed by a particular client) can happen also after the kernel target module is loaded. The directory in <dev_search_path> is a module parameter and is fixed. It contains for example "/ibnbd_devices/". But a particular client X would be able to only access the devices located in the subdirectory "/ibnbd_devices/client_x/". (The sessionname here is client_x) One can add or remove the devices from that directory (those are just symlinks to /dev/xxx) at any time - before or after the server module is loaded. But you are right, we need something additional in order to be able to specify which devices a client can access writable and which readonly. May be another subdirectories "wr" and "ro" for each client:
those under /ibnbd_devices/client_x/ro/ can only be read by client_x and those in /ibnbd_devices/client_x/wr/ can also be written to?
Thanks,
Danil.
T24gVHVlLCAyMDE4LTAyLTA2IGF0IDEwOjQ0ICswMTAwLCBEYW5pbCBLaXBuaXMgd3JvdGU6DQo+ IHRoZSBjb25maWd1cmF0aW9uICh3aGljaCBkZXZpY2VzIGNhbiBiZSBhY2Nlc3NlZCBieSBhIHBh cnRpY3VsYXINCj4gY2xpZW50KSBjYW4gaGFwcGVuIGFsc28gYWZ0ZXIgdGhlIGtlcm5lbCB0YXJn ZXQgbW9kdWxlIGlzIGxvYWRlZC4gVGhlDQo+IGRpcmVjdG9yeSBpbiA8ZGV2X3NlYXJjaF9wYXRo PiBpcyBhIG1vZHVsZSBwYXJhbWV0ZXIgYW5kIGlzIGZpeGVkLiBJdA0KPiBjb250YWlucyBmb3Ig ZXhhbXBsZSAiL2libmJkX2RldmljZXMvIi4gQnV0IGEgcGFydGljdWxhciBjbGllbnQgWA0KPiB3 b3VsZCBiZSBhYmxlIHRvIG9ubHkgYWNjZXNzIHRoZSBkZXZpY2VzIGxvY2F0ZWQgaW4gdGhlIHN1 YmRpcmVjdG9yeQ0KPiAiL2libmJkX2RldmljZXMvY2xpZW50X3gvIi4gKFRoZSBzZXNzaW9ubmFt ZSBoZXJlIGlzIGNsaWVudF94KSBPbmUgY2FuDQo+IGFkZCBvciByZW1vdmUgdGhlIGRldmljZXMg ZnJvbSB0aGF0IGRpcmVjdG9yeSAodGhvc2UgYXJlIGp1c3Qgc3ltbGlua3MNCj4gdG8gL2Rldi94 eHgpIGF0IGFueSB0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N0b3JhZ2UgdGFyZ2V0IGV4cGVjdCBm dWxsIGNvbnRyb2wgb3ZlciB3aGljaCBzdG9yYWdlIGRldmljZXMgYXJlIGV4cG9ydGVkDQphbmQg YWxzbyBvdmVyIHdoaWNoIGNsaWVudHMgZG8gaGF2ZSBhbmQgZG8gbm90IGhhdmUgYWNjZXNzLg0K DQpCYXJ0Lg==
Quoted 19 lines · Bart Van Assche
Quoted 9 lines · Jinpu Wang
Hi Bart,
My another 2 cents:)
Quoted 5 lines · Bart Van Assche
Quoted 3 lines · Roman Pen
o Simple configuration of IBNBD:
- Server side is completely passive: volumes do not need to be explicitly exported.Quoted 8 lines
Quoted 3 lines
That sounds like a security hole? I think the ability to configure whether or not an initiator is allowed to log in is essential and also which volumes an initiator has access to.
Our design target for well controlled production environment, so security is handle in other layer. On server side, admin can set the
dev_search_pathin module parameter to set parent directory, this will concatenate with the path client send in open message to open a block device.
Quoted 8 lines
Hello Jack,
That approach may work well for your employer but sorry I don't think this is sufficient for an upstream driver. I think that most users who configure a network storage target expect full control over which storage devices are exported and also over which clients do have and do not have access.
Bart.
Hello Bart,
I agree for general purpose, it may be good to have better access control.
Thanks,
Signature · 2 lines
Jack Wang Linux Kernel Developer
Quoted 4 lines · Bart Van Assche
That approach may work well for your employer but sorry I don't think this is sufficient for an upstream driver. I think that most users who configure a network storage target expect full control over which storage devices are exported and also over which clients do have and do not have access.
Well is that actually true for IPoIB? It seems that I can arbitrarily attach to any partition I want without access control. In many ways some of the RDMA layers and modules are loose with security since performance is what matters mostly and deployments occur in separate production environments.
We have had security issues (that not fully resolved yet) with the RDMA RPC API for years.. So maybe lets relax on the security requirements a bit?
Quoted 13 lines · Christopher Lameter
Quoted 4 lines · Bart Van Assche
That approach may work well for your employer but sorry I don't think this is sufficient for an upstream driver. I think that most users who configure a network storage target expect full control over which storage devices are exported and also over which clients do have and do not have access.
Well is that actually true for IPoIB? It seems that I can arbitrarily attach to any partition I want without access control. In many ways some of the RDMA layers and modules are loose with security since performance is what matters mostly and deployments occur in separate production environments.
Quoted 4 lines
We have had security issues (that not fully resolved yet) with the RDMA RPC API for years.. So maybe lets relax on the security requirements a bit?
Frankly speaking I do not understand the "security" about this kind of block devices and RDMA in particular. I can admit that personally I do not see the whole picture, so can someone provide the real usecase/scenario? What we have in our datacenters is trusted environment (do others exist?). You need a volume, you create it. You need to map a volume remotely - you map it. Of course there are provisioning checks, rw/ro checks, etc. But in general any IP/key checks (is that client really a "good" guy or not?) are simply useless. So the question is: are there real life setups where some of the local IB network members can be untrusted?
--
Roman
T24gV2VkLCAyMDE4LTAyLTA3IGF0IDE4OjE4ICswMTAwLCBSb21hbiBQZW55YWV2IHdyb3RlOg0K PiBTbyB0aGUgcXVlc3Rpb24gaXM6IGFyZSB0aGVyZSByZWFsIGxpZmUgc2V0dXBzIHdoZXJlDQo+ IHNvbWUgb2YgdGhlIGxvY2FsIElCIG5ldHdvcmsgbWVtYmVycyBjYW4gYmUgdW50cnVzdGVkPw0K DQpIZWxsbyBSb21hbiwNCg0KWW91IG1heSB3YW50IHRvIHJlYWQgbW9yZSBhYm91dCB0aGUgbGF0 ZXN0IGV2b2x1dGlvbnMgd2l0aCByZWdhcmQgdG8gbmV0d29yaw0Kc2VjdXJpdHkuIEFuIGFydGlj bGUgdGhhdCBJIGNhbiByZWNvbW1lbmQgaXMgdGhlIGZvbGxvd2luZzogIkdvb2dsZSByZXZlYWxz DQpvd24gc2VjdXJpdHkgcmVnaW1lIHBvbGljeSB0cnVzdHMgbm8gbmV0d29yaywgYW55d2hlcmUs IGV2ZXIiDQooaHR0cHM6Ly93d3cudGhlcmVnaXN0ZXIuY28udWsvMjAxNi8wNC8wNi9nb29nbGVz X2JleW9uZGNvcnBfc2VjdXJpdHlfcG9saWN5LykuDQoNCklmIGRhdGEtY2VudGVycyB3b3VsZCBz dGFydCBkZXBsb3lpbmcgUkRNQSBhbW9uZyB0aGVpciBlbnRpcmUgZGF0YSBjZW50ZXJzDQoobWF5 YmUgdGhleSBhcmUgYWxyZWFkeSBkb2luZyB0aGlzKSB0aGVuIEkgdGhpbmsgdGhleSB3aWxsIHdh bnQgdG8gcmVzdHJpY3QNCmFjY2VzcyB0byBibG9jayBkZXZpY2VzIHRvIG9ubHkgdGhvc2UgaW5p dGlhdG9yIHN5c3RlbXMgdGhhdCBuZWVkIGl0Lg0KDQpUaGFua3MsDQoNCkJhcnQuDQoNCg0K
Quoted 11 lines · Bart Van Assche
Quoted 2 lines · Roman Penyaev
So the question is: are there real life setups where some of the local IB network members can be untrusted?
Hello Roman,
You may want to read more about the latest evolutions with regard to network security. An article that I can recommend is the following: "Google reveals own security regime policy trusts no network, anywhere, ever"
(https://www.theregister.co.uk/2016/04/06/googles_beyondcorp_security_policy/).
Quoted 9 lines
If data-centers would start deploying RDMA among their entire data centers (maybe they are already doing this) then I think they will want to restrict access to block devices to only those initiator systems that need it.
Thanks,
Bart.
Hi Bart,
thanks for the link to the article. To the best of my understanding, the guys suggest to authenticate the devices first and only then authenticate the users who use the devices in order to get access to a corporate service. They also mention in the presentation the current trend of moving corporate services into the cloud. But I think this is not about the devices from which that cloud is build of. Isn't a cloud first build out of devices connected via IB and then users (and their devices) are provided access to the services of that cloud as a whole? If a malicious user already plugged his device into an IB switch of a cloud internal infrastructure, isn't it game over anyway? Can't he just take the hard drives instead of mapping them?
Thanks,
Danil.
T24gVGh1LCAyMDE4LTAyLTA4IGF0IDE4OjM4ICswMTAwLCBEYW5pbCBLaXBuaXMgd3JvdGU6DQo+ IHRoYW5rcyBmb3IgdGhlIGxpbmsgdG8gdGhlIGFydGljbGUuIFRvIHRoZSBiZXN0IG9mIG15IHVu ZGVyc3RhbmRpbmcsDQo+IHRoZSBndXlzIHN1Z2dlc3QgdG8gYXV0aGVudGljYXRlIHRoZSBkZXZp Y2VzIGZpcnN0IGFuZCBvbmx5IHRoZW4NCj4gYXV0aGVudGljYXRlIHRoZSB1c2VycyB3aG8gdXNl IHRoZSBkZXZpY2VzIGluIG9yZGVyIHRvIGdldCBh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SBob3dldmVyIHJlc3RyaWN0cyBhY2Nlc3MgYmFzZWQNCm9uIHRoZSBpbml0aWF0b3IgSVAg YWRkcmVzcyB0aGVuIHRoYXQgd291bGQgbWFrZSBpdCBoYXJkZXIgZm9yIGEgcGVuZXRyYXRvcg0K dG8gYWNjZXNzIHRoZSBleHBvcnRlZCBibG9jayBzdG9yYWdlIGRldmljZXMuIEluc3RlYWQgb2Yg anVzdCBwZW5ldHJhdGluZyB0aGUNCm5ldHdvcmsgYWNjZXNzLCBJUCBhZGRyZXNzIHNwb29maW5n IHdvdWxkIGhhdmUgdG8gYmUgdXNlZCBvciBhY2Nlc3Mgd291bGQNCmhhdmUgdG8gYmUgb2J0YWlu ZWQgdG8gYSBzeXN0ZW0gdGhhdCBoYXMgYmVlbiBncmFudGVkIGFjY2VzcyB0byB0aGUgdGFyZ2V0 DQpzeXN0ZW0uDQoNClRoYW5rcywNCg0KQmFydC4NCg0KDQo=
Hi Doug,
thanks for the feedback. You read the cover letter correctly: our transport library implements multipath (load balancing and failover) on top of RDMA API. Its name "IBTRS" is slightly misleading in that
regard: it can sit on top of ROCE as well. The library allows for "bundling" multiple rdma "paths" (source addr - destination addr pair) into one "session". So our session consists of one or more paths and each path under the hood consists of as many QPs (each connecting source with destination) as there are CPUs on the client system. The user load (In our case IBNBD is a block device and generates some block requests) is load-balanced on per cpu-basis.
I understand, this is something very different to what smc-r is doing. Am I right? Do you know what stage MP-RDMA development currently is?
Best,
Danil Kipnis.
P.S. Sorry for the duplicate if any, first mail was returned cause of html.
On Thu, Feb 8, 2018 at 7:10 PM Bart Van Assche <[email protected]> wro= te:
Quoted 14 lines · Danil Kipnis
Quoted 11 lines
thanks for the link to the article. To the best of my understanding, the guys suggest to authenticate the devices first and only then authenticate the users who use the devices in order to get access to a corporate service. They also mention in the presentation the current trend of moving corporate services into the cloud. But I think this is not about the devices from which that cloud is build of. Isn't a cloud first build out of devices connected via IB and then users (and their devices) are provided access to the services of that cloud as a whole? If a malicious user already plugged his device into an IB switch of a cloud internal infrastructure, isn't it game over anyway? Can't he just take the hard drives instead of mapping them?
Quoted 3 lines
Hello Danil,
It seems like we each have been focussing on different aspects of the art=
icle.
Quoted 2 lines
The reason I referred to that article is because I read the following in that article: "Unlike the conventional perimeter security model, BeyondCo=
rp
Quoted 1 line
doesn=E2=80=99t gate access to services and tools based on a user=E2=80=
=99s physical location
Quoted 1 line
or the originating network [ ... ] The zero trust architecture spells tro=
uble
Quoted 1 line
for traditional attacks that rely on penetrating a tough perimeter to wal=
tz
Quoted 1 line
freely within an open internal network." Suppose e.g. that an organizatio=
n
Quoted 1 line
decides to use RoCE or iWARP for connectivity between block storage initi=
ator
Quoted 1 line
systems and block storage target systems and that it has a single company=
-
Quoted 1 line
wide Ethernet network. If the target system does not restrict access base=
d
Quoted 1 line
on initiator IP address then any penetrator would be able to access all t=
he
Quoted 1 line
block devices exported by the target after a SoftRoCE or SoftiWARP initia=
tor
Quoted 1 line
driver has been loaded. If the target system however restricts access bas=
ed
Quoted 1 line
on the initiator IP address then that would make it harder for a penetrat=
or
Quoted 1 line
to access the exported block storage devices. Instead of just penetrating=
the
Quoted 2 lines
network access, IP address spoofing would have to be used or access would have to be obtained to a system that has been granted access to the targe=
t
Quoted 7 lines
system.
Thanks,
Bart.
--=20
Danil Kipnis
Linux Kernel Developer
Hi Roman and the team,
Quoted 5 lines · Roman Pen
This series introduces IBNBD/IBTRS modules.
IBTRS (InfiniBand Transport) is a reliable high speed transport library which allows for establishing connection between client and server machines via RDMA.
So its not strictly infiniband correct?
It is optimized to transfer (read/write) IO blocks
Quoted 7 lines
in the sense that it follows the BIO semantics of providing the possibility to either write data from a scatter-gather list to the remote side or to request ("read") data transfer from the remote side into a given set of buffers.
IBTRS is multipath capable and provides I/O fail-over and load-balancing functionality.
Couple of questions on your multipath implementation?
1. What was your main objective over dm-multipath?
2. What was the consideration of this implementation over creating a stand-alone bio based device node to reinject the bio to the original block device?
Quoted 11 lines
IBNBD (InfiniBand Network Block Device) is a pair of kernel modules (client and server) that allow for remote access of a block device on the server over IBTRS protocol. After being mapped, the remote block devices can be accessed on the client side as local block devices. Internally IBNBD uses IBTRS as an RDMA transport library.
Why?
- IBNBD/IBTRS is developed in order to map thin provisioned volumes, thus internal protocol is simple and consists of several request types only without awareness of underlaying hardware devices.
Can you explain how the protocol is developed for thin-p? What are the essence of how its suited for it?
Quoted 4 lines
- IBTRS was developed as an independent RDMA transport library, which supports fail-over and load-balancing policies using multipath, thus it can be used for any other IO needs rather than only for block device.
What do you mean by "any other IO"?
Quoted 4 lines
- IBNBD/IBTRS is faster than NVME over RDMA. Old comparison results:
https://www.spinics.net/lists/linux-rdma/msg48799.html
(I retested on latest 4.14 kernel - there is no any significant
difference, thus I post the old link).
That is interesting to learn.
Reading your reference brings a couple of questions though,
- Its unclear to me how ibnbd performs reads without performing memory registration. Is it using the global dma rkey?
- Its unclear to me how there is a difference in noreg in writes, because for small writes nvme-rdma never register memory (it uses inline data).
- Looks like with nvme-rdma you max out your iops at 1.6 MIOPs, that seems considerably low against other reports. Can you try and explain what was the bottleneck? This can be a potential bug and I (and the rest of the community is interesting in knowing more details).
- srp/scst comparison is really not fair having it in legacy request mode. Can you please repeat it and report a bug to either linux-rdma or to the scst mailing list?
- Your latency measurements are surprisingly high for a null target device (even for low end nvme device actually) regardless of the transport implementation.
For example:
- QD=1 read latency is 648.95 for ibnbd (I assume usecs right?) which is fairly high. on nvme-rdma its 1058 us, which means over 1 millisecond and even 1.254 ms for srp. Last time I tested nvme-rdma read QD=1 latency I got ~14 us. So something does not add up here. If this is not some configuration issue, then we have serious bugs to handle..
- QD=16 the read latencies are > 10ms for null devices?! I'm having troubles understanding how you were able to get such high latencies (> 100 ms for QD>=100)
Can you share more information about your setup? It would really help us understand more.
Quoted 2 lines
- Major parts of the code were rewritten, simplified and overall code size was reduced by a quarter.
That is good to know.
Hi Roman and the team (again), replying to my own email :)
I forgot to mention that first of all thank you for upstreaming your work! I fully support your goal to have your production driver upstream to minimize your maintenance efforts. I hope that my feedback didn't came across with a different impression, that was certainly not my intent.
It would be great if you can address and/or reply to my feedback (as well as others) and re-spin it again.
Cheers,
Sagi.
Hi Sagi and all,
Quoted 7 lines · Sagi Grimberg
Hi Roman and the team (again), replying to my own email :)
I forgot to mention that first of all thank you for upstreaming your work! I fully support your goal to have your production driver upstream to minimize your maintenance efforts. I hope that my feedback didn't came across with a different impression, that was certainly not my intent.
Well, I've just recovered from two heart attacks, which I got while reading your replies, but now I am fine, thanks :)
Quoted 2 lines
It would be great if you can address and/or reply to my feedback (as well as others) and re-spin it again.
Jokes aside, we would like to thank you all, guys, for valuable feedback. I got a lot of useful remarks from you Sagi and you Bart. We will try to cover them in next version and will provide up-to-date comparison results.
--
Roman
T24gTW9uLCAyMDE4LTAyLTA1IGF0IDE0OjE2ICswMjAwLCBTYWdpIEdyaW1iZXJnIHdyb3RlOg0K PiAtIFlvdXIgbGF0ZW5jeSBtZWFzdXJlbWVudHMgYXJlIHN1cnByaXNpbmdseSBoaWdoIGZvciBh IG51bGwgdGFyZ2V0DQo+ICAgIGRldmljZSAoZXZlbiBmb3IgbG93IGVuZCBudm1lIGRldmljZSBh Y3R1YWxseSkgcmVnYXJkbGVzcyBvZiB0aGUNCj4gICAgdHJhbnNwb3J0IGltcGxlbWVudGF0aW9u Lg0KPiANCj4gRm9yIGV4YW1wbGU6DQo+IC0gUUQ9MSByZWFkIGxhdGVuY3kgaXMgNjQ4Ljk1IGZv ciBpYm5iZCAoSSBhc3N1bWUgdXNlY3MgcmlnaHQ/KSB3aGljaCBpcw0KPiAgICBmYWlybHkgaGln aC4gb24gbnZtZS1yZG1hIGl0cyAxMDU4IHVzLCB3aGljaCBtZWFucyBvdmVyIDEgbWlsbGlzZWNv bmQNCj4gICAgYW5kIGV2ZW4gMS4yNTQgbXMgZm9yIHNycC4gTGFzdCB0aW1lIEkgdGVzdGVkIG52 bWUtcmRtYSByZWFkIFFEPTENCj4gICAgbGF0ZW5jeSBJIGdvdCB+MTQgdXMu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D0xMjgNCg0KSWYgeW91IHdhbnQgdG8ga2Vl cCB0aGUgcGlwZWxpbmUgZnVsbCBJIHRoaW5rIHRoYXQgeW91IG5lZWQgdG8gc2V0IHRoZQ0KaW9k ZXB0aF9iYXRjaF9zdWJtaXQgcGFyYW1ldGVyIHRvIGEgdmFsdWUgdGhhdCBpcyBtdWNoIGxvd2Vy IHRoYW4gaW9kZXB0aC4NCkkgdGhpbmsgdGhhdCBzZXR0aW5nIGlvZGVwdGhfYmF0Y2hfc3VibWl0 IGVxdWFsIHRvIGlvZGVwdGggd2lsbCB5aWVsZA0Kc3Vib3B0aW1hbCBJT1BTIHJlc3VsdHMuIEpl bnMsIHBsZWFzZSBjb3JyZWN0IG1lIGlmIEkgZ290IHRoaXMgd3JvbmcuDQoNClRoYW5rcywNCg0K QmFydC4NCg0KDQo=
Hi Bart,
Quoted 25 lines · Bart Van Assche
Quoted 11 lines · Sagi Grimberg
- Your latency measurements are surprisingly high for a null target device (even for low end nvme device actually) regardless of the transport implementation.
For example:
- QD=1 read latency is 648.95 for ibnbd (I assume usecs right?) which is fairly high. on nvme-rdma its 1058 us, which means over 1 millisecond and even 1.254 ms for srp. Last time I tested nvme-rdma read QD=1 latency I got ~14 us. So something does not add up here. If this is not some configuration issue, then we have serious bugs to handle..Quoted 6 lines
- QD=16 the read latencies are > 10ms for null devices?! I'm having troubles understanding how you were able to get such high latencies (> 100 ms for QD>=100)
Can you share more information about your setup? It would really help us understand more.
I would also appreciate it if more information could be provided about the measurement results. In addition to answering Sagi's questions, would it be possible to share the fio job that was used for measuring latency? In
https://events.static.linuxfound.org/sites/events/files/slides/Copy%20of%20IBNBD-Vault-2017-5.pdf
I found the following:
Quoted 7 lines
iodepth=128
iodepth_batch_submit=128If you want to keep the pipeline full I think that you need to set the
iodepth_batch_submitparameter to a value that is much lower than iodepth. I think that settingiodepth_batch_submitequal to iodepth will yield suboptimal IOPS results. Jens, please correct me if I got this wrong.
Sorry, Bart, I would answer here in a few words (I would like to answer in details tomorrow on Sagi's mail).
Everything (fio jobs, setup, etc) is given in the same link:
https://www.spinics.net/lists/linux-rdma/msg48799.html
at the bottom you will find links on google docs with many pages and archived fio jobs and scripts. (I do not remember exactly, one year passed, but there should be everything).
Regarding smaller iodepth_batch_submit - that decreases performance. Once I played with that, even introduced new iodepth_batch_complete_max option for fio, but then I decided to stop and simply chose this configuration, which provides me fastest results.
--
Roman
T24gTW9uLCAyMDE4LTAyLTA1IGF0IDE4OjE2ICswMTAwLCBSb21hbiBQZW55YWV2IHdyb3RlOg0K PiBFdmVyeXRoaW5nIChmaW8gam9icywgc2V0dXAsIGV0YykgaXMgZ2l2ZW4gaW4gdGhlIHNhbWUg bGluazoNCj4gDQo+IGh0dHBzOi8vd3d3LnNwaW5pY3MubmV0L2xpc3RzL2xpbnV4LXJkbWEvbXNn NDg3OTkuaHRtbA0KPiANCj4gYXQgdGhlIGJvdHRvbSB5b3Ugd2lsbCBmaW5kIGxpbmtzIG9uIGdv b2dsZSBkb2NzIHdpdGggbWFueSBwYWdlcw0KPiBhbmQgYXJjaGl2ZWQgZmlvIGpvYnMgYW5kIHNj cmlwdHMuIChJIGRvIG5vdCByZW1lbWJlciBleGFjdGx5LA0KPiBvbmUgeWVhciBwYXNzZWQsIGJ1 dCB0aGVyZSBzaG91bGQgYmUgZXZlcnl0aGluZykuDQo+IA0KPiBSZWdhcmRpbmcgc21hbGxlciBp b2RlcHRoX2JhdGNoX3N1Ym1pdCAtIHRoYXQgZGVjcmVhc2VzIHBlcmZvcm1hbmNlLg0KPiBPbmNl IEkgcGxheWVkIHdpdGggdGhhdCwgZXZlbiBpbnRyb2R1Y2VkIG5ldyBpb2RlcHRoX2JhdGNoX2Nv bXBsZXRlX21heA0KPiBvcHRpb24gZm9yIGZpbywgYnV0IHRoZW4gSSBkZWNpZGVkIHRvIHN0b3Ag YW5kIHNpbXBseSBjaG9zZSB0aGlzDQo+IGNvbmZpZ3VyYXRpb24sIHdoaWNoIHByb3ZpZGVzIG1l IGZhc3Rlc3QgcmVzdWx0cy4NCg0KSGVsbG8gUm9tYW4sDQoNClRoYXQncyB3ZWlyZC4gRm9yIHdo aWNoIHByb3RvY29scyBkaWQgcmVkdWNpbmcgaW9kZXB0aF9iYXRjaF9zdWJtaXQgbGVhZA0KdG8g bG93ZXIgcGVyZm9ybWFuY2U6IGFsbCB0aGUgdGVzdGVkIHByb3RvY29scyBvciBvbmx5IHNvbWUg b2YgdGhlbT8NCg0KVGhhbmtzLA0KDQpCYXJ0Lg==
Quoted 14 lines · Bart Van Assche
Quoted 4 lines · Roman Penyaev
Everything (fio jobs, setup, etc) is given in the same link:
Quoted 8 lines
at the bottom you will find links on google docs with many pages and archived fio jobs and scripts. (I do not remember exactly, one year passed, but there should be everything).
Regarding smaller
iodepth_batch_submit- that decreases performance. Once I played with that, even introduced newiodepth_batch_complete_maxoption for fio, but then I decided to stop and simply chose this configuration, which provides me fastest results.
Quoted 4 lines
Hello Roman,
That's weird. For which protocols did reducing
iodepth_batch_submitlead to lower performance: all the tested protocols or only some of them?
Hi Bart,
Seems that does not depend on protocol (when I tested it was true for nvme and ibnbd). That depends on a load. On high load (1 or few fio jobs are dedicated to each cpu, and we have 64 cpus) it turns out to be faster to wait completions for all queue for that particular block dev, instead of switching from kernel to userspace for each completed IO.
But I can assure you that performance difference is very minor, it exists, but it does not change the whole picture of what you see on this google sheet. So what I tried to achieve is to squeeze everything I could, nothing more.
--
Roman
Hi Sagi,
Quoted 4 lines · Sagi Grimberg
Hi Roman and the team,
Quoted 1 line · Roman Pen
Quoted 8 lines
Quoted 5 lines
This series introduces IBNBD/IBTRS modules.
IBTRS (InfiniBand Transport) is a reliable high speed transport library which allows for establishing connection between client and server machines via RDMA.
So its not strictly infiniband correct?
This is RDMA. Original IB prefix is a bit confusing, that's true.
Quoted 7 lines
It is optimized to transfer (read/write) IO blocks
Quoted 6 lines
in the sense that it follows the BIO semantics of providing the possibility to either write data from a scatter-gather list to the remote side or to request ("read") data transfer from the remote side into a given set of buffers.
Quoted 6 lines
Quoted 2 lines
IBTRS is multipath capable and provides I/O fail-over and load-balancing functionality.
Couple of questions on your multipath implementation?
1. What was your main objective over dm-multipath?
No objections, mpath is a part of the transport ibtrs library.
Quoted 3 lines
2. What was the consideration of this implementation over creating a stand-alone bio based device node to reinject the bio to the original block device?
ibnbd and ibtrs are separate, on fail-over or load-balancing we work with IO requests inside a library.
Quoted 8 lines
Quoted 8 lines
IBNBD (InfiniBand Network Block Device) is a pair of kernel modules (client and server) that allow for remote access of a block device on the server over IBTRS protocol. After being mapped, the remote block devices can be accessed on the client side as local block devices. Internally IBNBD uses IBTRS as an RDMA transport library.
Why?
Quoted 7 lines
Quoted 3 lines
- IBNBD/IBTRS is developed in order to map thin provisioned volumes, thus internal protocol is simple and consists of several request types only without awareness of underlaying hardware devices.
Can you explain how the protocol is developed for thin-p? What are the essence of how its suited for it?
Here I wanted to emphasize, that we do not support any HW commands, like nvme does, thus internal protocol consists of several commands. So answering on your question "how the protocol is developed for thin-p" I would put it another way around: "protocol does nothing to support real device, because all we need is to map thin-p volumes". It is just simpler.
Quoted 7 lines
Quoted 4 lines
- IBTRS was developed as an independent RDMA transport library, which supports fail-over and load-balancing policies using multipath, thus it can be used for any other IO needs rather than only for block device.
What do you mean by "any other IO"?
I mean other IO producers, not only ibnbd, since this is just a transport library.
Quoted 7 lines
Quoted 5 lines
- IBNBD/IBTRS is faster than NVME over RDMA. Old comparison results:
https://www.spinics.net/lists/linux-rdma/msg48799.html
(I retested on latest 4.14 kernel - there is no any significant
difference, thus I post the old link).
Quoted 5 lines
That is interesting to learn.
Reading your reference brings a couple of questions though,
- Its unclear to me how ibnbd performs reads without performing memory registration. Is it using the global dma rkey?
Yes, global rkey.
WRITE: writes from client
READ: writes from server
Quoted 3 lines
- Its unclear to me how there is a difference in noreg in writes, because for small writes nvme-rdma never register memory (it uses inline data).
No support for that.
Quoted 4 lines
- Looks like with nvme-rdma you max out your iops at 1.6 MIOPs, that seems considerably low against other reports. Can you try and explain what was the bottleneck? This can be a potential bug and I (and the rest of the community is interesting in knowing more details).
Sure, I can try. BTW, what are other reports and numbers?
Quoted 3 lines
- srp/scst comparison is really not fair having it in legacy request mode. Can you please repeat it and report a bug to either linux-rdma or to the scst mailing list?
Yep, I can retest with mq.
Quoted 3 lines
- Your latency measurements are surprisingly high for a null target device (even for low end nvme device actually) regardless of the transport implementation.
Hm, network configuration? These are results on machines dedicated to our team for testing in one of our datacenters. Nothing special in configuration.
Quoted 10 lines
For example:
- QD=1 read latency is 648.95 for ibnbd (I assume usecs right?) which is fairly high. on nvme-rdma its 1058 us, which means over 1 millisecond and even 1.254 ms for srp. Last time I tested nvme-rdma read QD=1 latency I got ~14 us. So something does not add up here. If this is not some configuration issue, then we have serious bugs to handle..- QD=16 the read latencies are > 10ms for null devices?! I'm having troubles understanding how you were able to get such high latencies (> 100 ms for QD>=100)
What QD stands for? queue depth? This is not a queue depth, this is how many fio jobs are dedicated.
And regarding latencies: I can suspect only network configuration.
Quoted 2 lines
Can you share more information about your setup? It would really help us understand more.
Everything is specified in the google doc sheet. Also you can download the fio files, links are also provided, at the bottom.
https://www.spinics.net/lists/linux-rdma/msg48799.html
[1] FIO runner and results extractor script:
https://drive.google.com/open?id=0B8_SivzwHdgSS2RKcmc4bWg0YjA
[2] Archive with FIO configurations and results:
https://drive.google.com/open?id=0B8_SivzwHdgSaDlhMXV6THhoRXc
[3] Google sheet with performance measurements:
https://drive.google.com/open?id=1sCTBKLA5gbhhkgd2USZXY43VL3zLidzdqDeObZn9Edc
[4] NVMEoF configuration:
https://drive.google.com/open?id=0B8_SivzwHdgSTzRjbGtmaVR6LWM
[5] SCST configuration:
https://drive.google.com/open?id=0B8_SivzwHdgSM1B5eGpKWmFJMFk
--
Roman
T24gVHVlLCAyMDE4LTAyLTA2IGF0IDE0OjEyICswMTAwLCBSb21hbiBQZW55YWV2IHdyb3RlOg0K PiBPbiBNb24sIEZlYiA1LCAyMDE4IGF0IDE6MTYgUE0sIFNhZ2kgR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Z2luZyB0aGUgU0NTVCBTR1YgY2FjaGUgZnJvbSBhIGdsb2JhbCBpbnRvIGEgcGVy LUNQVQ0KY2FjaGU/IFJlZ2FyZGluZyB0aGUgU1JQIG1lYXN1cmVtZW50czogaGF2ZSB5b3UgdHJp ZWQgdG8gc2V0IHRoZQ0KbmV2ZXJfcmVnaXN0ZXIga2VybmVsIG1vZHVsZSBwYXJhbWV0ZXIgdG8g dHJ1ZT8gSSdtIGFza2luZyB0aGlzIGJlY2F1c2UgSQ0KdGhpbmsgdGhhdCBtb2RlIGlzIG1vc3Qg c2ltaWxhciB0byBob3cgdGhlIElCTkJEIGluaXRpYXRvciBkcml2ZXIgd29ya3MuDQoNClRoYW5r cywNCg0KQmFydC4=
Quoted 9 lines · Bart Van Assche
Quoted 8 lines · Roman Penyaev
Quoted 4 lines · Sagi Grimberg
[ ... ]
- srp/scst comparison is really not fair having it in legacy request mode. Can you please repeat it and report a bug to either linux-rdma or to the scst mailing list?Yep, I can retest with mq.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
- Your latency measurements are surprisingly high for a null target device (even for low end nvme device actually) regardless of the transport implementation.
Hm, network configuration? These are results on machines dedicated to our team for testing in one of our datacenters. Nothing special in configuration.
Hello Bart,
Quoted 5 lines
I agree that the latency numbers are way too high for a null target device. Last time I measured latency for the SRP protocol against an SCST target
+ null block driver at the target side and ConnectX-3 adapters I measured a latency of about 14 microseconds. That's almost 100 times less than the measurement results in https://www.spinics.net/lists/linux-rdma/msg48799.html.
Here is the following configuration of the setup:
Initiator and target HW configuration:
AMD Opteron 6386 SE, 64CPU, 128Gb
InfiniBand: Mellanox Technologies MT26428
[ConnectX VPI PCIe 2.0 5GT/s - IB QDR / 10GigE]
Also, I remember that between initiator and target there were two IB switches. Unfortunately, I can't repeat the same configuration, but will retest as soon as we get new HW.
Quoted 4 lines
Something else I would like to understand better is how much of the latency gap between NVMeOF/SRP and IBNBD can be closed without changing the wire protocol. Was e.g. support for immediate data present in the NVMeOF and/or SRP drivers used on your test setup?
I did not get the question. IBTRS uses empty messages with only imm_data field set to respond on IO. This is a part of the IBTRS protocol. I do not understand how can immediate data be present in other drivers, if those do not use it in their protocols. I am lost here.
Quoted 5 lines
Are you aware that the NVMeOF target driver calls
page_alloc()from the hot path but that there are plans to avoid these calls in the hot path by using a caching mechanism similar to
the SGV cache in SCST? Are you aware that a significant latency reduction
can be achieved by changing the SCST SGV cache from a global into a per-CPU
cache?
No, I am not aware. That is nice, that there is a lot of room for performance tweaks. I will definitely retest on fresh kernel once everything is done on nvme, scst or ibtrs (especially when we get rid of fmrs and UNSAFE rkeys). Maybe there are some other parameters which can be also tweaked?
Quoted 3 lines
Regarding the SRP measurements: have you tried to set the
never_registerkernel module parameter to true? I'm asking this because I think that mode is most similar to how the IBNBD initiator driver works.
yes, according to my notes from that link (frankly, I do not remember, but that is what I wrote 1 year ago):
* Where suffixes mean:
_noreg - modules on initiator side (ib_srp, nvme_rdma) were loaded
with 'register_always=N' param
That what you are asking, right?
--
Roman
T24gV2VkLCAyMDE4LTAyLTA3IGF0IDEzOjU3ICswMTAwLCBSb21hbiBQZW55YWV2IHdyb3RlOg0K PiBPbiBUdWUsIEZlYiA2LCAyMDE4IGF0IDU6MDEgUE0sIEJhcnQgVmFuIEFzc2NoZSA8QmFydC5W YW5Bc3NjaGVAd2RjLmNvbT4gd3JvdGU6DQo+ID4gT24gVHVlLCAyMDE4LTAyLTA2IGF0IDE0OjEy ICswMTAwLCBSb21hbiBQZW55YWV2IHdyb3RlOg0KPiA+IFNvbWV0aGluZyBlbHNlIEkgd291bGQg bGlrZSB0byB1bmRlcnN0YW5kIGJldHRlciBpcyBob3cgbXVjaCBvZiB0aGUgbGF0ZW5jeQ0KPiA+ IGdhcCBiZXR3ZWVuIE5WTWVPRi9TUlAgYW5kIElCTkJEIGNhbiBiZSBjbG9zZWQgd2l0aG91dCBj aGFuZ2luZyB0aGUgd2lyZQ0KPiA+IHByb3RvY29sLiBXYXMgZS5nLiBzdXBwb3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