Skip to contentSkip to conversation

InfiniBand Transport (IBTRS) and Network Block Device (IBNBD)

PATCH Superseded Jack Wang 10 participants 148 messages Jun 20, 2019 – Oct 2, 2019 Page 2 of 2

Subsystems (3)

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#73 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

In reply to Bart Van Assche
Quoted 5 lines · Bart Van Assche
Quoted 1 line · Jack Wang

+MODULE_VERSION(IBNBD_VER_STRING);

No version numbers in upstream code please.

Will drop this, thanks.

Quoted 10 lines

drivers/block/ibnbd/ibnbd-clt.c line 45

Quoted 7 lines
drivers/block/ibnbd/ibnbd-clt.c new file +6 -0
+/*
+ * This is for closing devices when unloading the module:
+ * we might be closing a lot (>256) of devices in parallel
+ * and it is better not to use the system_wq.
+ */
+static struct workqueue_struct *unload_wq;

I think that a better motivation is needed for the introduction of a new workqueue.

We didn't want to pollute the system workqueue when unmapping a big number of devices at once in parallel. Will reiterate on it.

Quoted 4 lines
Quoted 2 lines

+#define KERNEL_SECTOR_SIZE 512

Please use SECTOR_SIZE instead of redefining it.

Right.

Quoted 14 lines
Quoted 14 lines
drivers/block/ibnbd/ibnbd-clt.c new file +13 -0
+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)
Quoted 8 lines

drivers/block/ibnbd/ibnbd-clt.c line 152

Quoted 5 lines
drivers/block/ibnbd/ibnbd-clt.c new file +5 -0
+             ibnbd_err(dev, "Failed to change device size from"
+                       " %zu to %zu, err: %d\n", dev->nsectors,
+                       new_nsectors, err);
+     return err;
+}

Since this function changes the block device size, I think that the name ibnbd_clt_revalidate_disk() is confusing. Please rename this function.

I guess ibnbd_clt_resize_disk() would be more appropriate.

Quoted 10 lines
Quoted 9 lines

+/**
+ * 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.

+ */

Quoted 2 lines

What does it mean to requeue a queue? Queue elements can be requeued but a queue in its entirety not. Please make this comment more clear.

Will fix the comment. The right wording should probably be "..., which need to be rerun". We have a list of "stopped" queues for each cpu. We need to select a list and a queue on that list to rerun, when an IO is completed.

Quoted 42 lines
Quoted 8 lines

+/**
+ * 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.
Quoted 7 lines

+ *
+ * Return:
+ * True if the queue was requeued, false otherwise.
+ *
+ * Context:
+ * Does not matter.
+ */

Same comment here.

Quoted 16 lines

+/**
+ * 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.
Quoted 7 lines

+ *
+ * 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.
+ */

Quoted 4 lines

Same comment here.

A more general question is why ibnbd needs its own queue management while no other block driver needs this?

Each IBNBD device promises to have a queue_depth (of say 512) on each of its num_cpus hardware queues. In fact we can only process a queue_depth inflights at once on the whole ibtrs session connecting a given client with a given server. Those 512 inflights (corresponding to the number of buffers reserved by the server for this particular client) have to be shared among all the devices mapped on this session. This leads to the situation, that we receive more requests than we can process at the moment. So we need to stop queues and start them again later in some fair fashion.

Quoted 24 lines
Quoted 24 lines
drivers/block/ibnbd/ibnbd-clt.c new file +23 -0
+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;
+
+     iu = blk_mq_rq_to_pdu(rq);
+     ibnbd_put_tag(sess, iu->tag);
+     blk_mq_end_request(rq, iu->status);
+}
+
+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;
+
+     if (softirq_enable) {
+             blk_mq_complete_request(rq);
+     } else {
+             ibnbd_put_tag(dev->sess, iu->tag);
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+             blk_mq_end_request(rq, iu->status);
+     }

Block drivers must call blk_mq_complete_request() instead of blk_mq_end_request() to complete a request after processing of the request has been started. Calling blk_mq_end_request() to complete a request is racy in case a timeout occurs while blk_mq_end_request() is in progress.

I need some time to give this part a closer look.

Quoted 8 lines

drivers/block/ibnbd/ibnbd-clt.c line 459

Quoted 4 lines
drivers/block/ibnbd/ibnbd-clt.c new file +3 -0
+static void msg_conf(void *priv, int errno)
+{
+     struct ibnbd_iu *iu = (struct ibnbd_iu *)priv;

The kernel code I'm familiar with does not cast void pointers explicitly into another type. Please follow that convention and leave the cast out from the above and also from similar statements.

msg_conf() is a callback which IBNBD passes down with a request to IBTRS when calling ibtrs_clt_request(). msg_conf() is called when a request is completed with a pointer to a struct defined in IBNBD. So IBTRS as transport doesn't know what's inside the private pointer which IBNBD passed down with the request, it's opaque, since struct ibnbd_iu is not visible in IBTRS. I will try to find how others avoid a cast in similar situations.

Quoted 17 lines
Quoted 4 lines
drivers/block/ibnbd/ibnbd-clt.c new file +3 -0
+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,

drivers/block/ibnbd/ibnbd-clt.c line 482

Quoted 10 lines
drivers/block/ibnbd/ibnbd-clt.c new file +10 -0
+                     void (*conf)(struct work_struct *work),
+                     int *errno, bool wait)
+{
+     int err;
+
+     INIT_WORK(&iu->work, conf);
+     err = ibtrs_clt_request(dir, msg_conf, ibtrs, iu->tag,
+                             iu, vec, nr, len, sg, sg_len);
+     if (!err && wait) {
+             wait_event(iu->comp.wait, iu->comp.errno != INT_MAX);

This looks weird. Why is this a wait_event() call instead of a wait_for_completion() call?

Looks, we could just use a wait_for_completion here.

Quoted 13 lines
Quoted 13 lines
drivers/block/ibnbd/ibnbd-clt.c new file +12 -0
+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_TAG_SHARED;
+     tags->cmd_size          = sizeof(struct ibnbd_iu);
Quoted 8 lines

drivers/block/ibnbd/ibnbd-clt.c line 794

Quoted 4 lines
drivers/block/ibnbd/ibnbd-clt.c new file +4 -0
+     tags->nr_hw_queues      = num_online_cpus();
+
+     return blk_mq_alloc_tag_set(tags);
+}

Forward declarations should be avoided when possible. Can the forward declaration of ibnbd_mq_ops be avoided by moving the definition of setup_mq_tags() down?

Yes we can by moving a couple of things around, thank you!

Quoted 13 lines

drivers/block/ibnbd/ibnbd-clt.c line 808

Quoted 8 lines
drivers/block/ibnbd/ibnbd-clt.c new file +7 -0
+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);
+}

The placement of the smp_wmb() call looks wrong to me. Since wake_up_all() and wait_event() already guarantee acquire/release behavior, I think that the explicit barriers can be left out from this function and also from wait_for_ibtrs_connection().

I will have to look into this part again. At first glance wmb seems to have to be after Sess->ibtrs_ready = true.

Quoted 13 lines
Quoted 13 lines
drivers/block/ibnbd/ibnbd-clt.c new file +12 -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);
Quoted 8 lines

drivers/block/ibnbd/ibnbd-clt.c line 917

Quoted 4 lines
drivers/block/ibnbd/ibnbd-clt.c new file +4 -0
+     /* After unlock session can be freed, so careful */
+     schedule();
+     mutex_lock(&sess_lock);
+}

This doesn't look right: any random wake_up() call can wake up this function. Shouldn't there be a loop in this function that causes the schedule() call to be repeated until the disconnect has happened?

The loop is inside __find_and_get_sess(), which is calling that function. We need to schedule() here in order for another thread to be able to remove the dying session we just found and tried to get reference to from the list of sessions, so that we can go over the list again in __find_and_get_sess().

Quoted 51 lines
Quoted 51 lines
drivers/block/ibnbd/ibnbd-clt.c new file +49 -0
+
+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;
+             }
+             /*
+              * 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;
+}
Quoted 15 lines

drivers/block/ibnbd/ibnbd-clt.c line 977

Quoted 11 lines
drivers/block/ibnbd/ibnbd-clt.c new file +11 -0
+
+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;
+}

Shouldn't __find_and_get_sess() function increase the reference count of sess before it returns? In other words, what prevents that the session is freed from another thread before find_and_get_sess() returns?

It does increase the refcount inside __find_and_get_sess() (...ibnbd_clt_get_sess(sess) call).

Quoted 18 lines

drivers/block/ibnbd/ibnbd-clt.c line 1122

Quoted 12 lines
drivers/block/ibnbd/ibnbd-clt.c new file +12 -0
+/*
+ * Get iorio of current task
+ */
+static short ibnbd_current_ioprio(void)
+{
+     struct task_struct *tsp = current;
+     unsigned short prio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0);
+
+     if (likely(tsp->io_context))
+             prio = tsp->io_context->ioprio;
+     return prio;
+}

ibnbd should use req_get_ioprio() and should not look at current->io_context->ioprio. I think it is the responsibility of the block layer to extract the I/O priority from the task context. As an example, here is how the aio code does this:

Quoted 2 lines
                req->ki_ioprio = get_current_ioprio();

Didn't notice the get_current_ioprio(), thank you. ibnbd_current_ioprio() is doing exactly the same, will drop it.

Quoted 25 lines
Quoted 25 lines
drivers/block/ibnbd/ibnbd-clt.c new file +25 -0
+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;
Quoted 8 lines

drivers/block/ibnbd/ibnbd-clt.c line 1287

Quoted 5 lines
drivers/block/ibnbd/ibnbd-clt.c new file +5 -0
+     }
+
+     ibnbd_put_tag(dev->sess, iu->tag);
+     return BLK_STS_IOERR;
+}

Every other block driver relies on the block layer core for tag allocation. Why does ibnbd need its own tag management?

Those tags are wrappers around the transport layer (ibtrs) "permits" (ibtrs_tags) - one such ibtrs_tag/"permits" is a reservation of one particular memory chunk on server side. Those "permits" are shared among all the devices mapped on a given session and all their hardware queues. Maybe we should use a different word like "permit" for them to avoid confusion?

Quoted 46 lines

drivers/block/ibnbd/ibnbd-clt.c line 1359

Quoted 12 lines
drivers/block/ibnbd/ibnbd-clt.c new file +11 -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);
+
+     /*
+      * we don't support discards to "discontiguous" segments
+      * in on request
               ^^
               one?
Quoted 21 lines
drivers/block/ibnbd/ibnbd-clt.c new file +20 -0
+      */
+     blk_queue_max_discard_segments(dev->queue, 1);
+
+     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)
+             blk_queue_flag_set(QUEUE_FLAG_DISCARD, dev->queue);
+     if (dev->secure_discard)
+             blk_queue_flag_set(QUEUE_FLAG_SECERASE, dev->queue);
+
+     blk_queue_flag_set(QUEUE_FLAG_SAME_COMP, dev->queue);
+     blk_queue_flag_set(QUEUE_FLAG_SAME_FORCE, dev->queue);
+     blk_queue_max_segments(dev->queue, dev->max_segments);
+     blk_queue_io_opt(dev->queue, dev->sess->max_io_size);
+     blk_queue_virt_boundary(dev->queue, 4095);
+     blk_queue_write_cache(dev->queue, true, true);
+     dev->queue->queuedata = dev;
+}
 
+static void destroy_gen_disk(struct ibnbd_clt_dev *dev)

drivers/block/ibnbd/ibnbd-clt.c

Quoted 10 lines
drivers/block/ibnbd/ibnbd-clt.c new file +9 -0
+{
+     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);
Quoted 3 lines

Please remove the above seven lines. blk_cleanup_queue() calls blk_set_queue_dying() and the second call in blk_set_queue_dying() is blk_freeze_queue_start().

Thanks, will check this out.

Quoted 14 lines

drivers/block/ibnbd/ibnbd-clt.c line 1651

Quoted 13 lines
drivers/block/ibnbd/ibnbd-clt.c new file +11 -0
+     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 */
                                                             ^^^^^^^
Quoted 2 lines

Please chose terminology that is more appropriate for a professional context.

Will rephrase the comment, thanks.

Quoted 8 lines

drivers/block/ibnbd/ibnbd-clt.c line 1656

Quoted 6 lines
drivers/block/ibnbd/ibnbd-clt.c new file +5 -0
+                     sysfs_remove_file_self(&dev->kobj, sysfs_self);
+             kobject_del(&dev->kobj);
+             kobject_put(&dev->kobj);
+     }
+}

Bart.

#74 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

Quoted 12 lines · Danil Kipnis
Quoted 10 lines · Bart Van Assche

drivers/block/ibnbd/ibnbd-clt.c line 45

Quoted 6 lines · Jack Wang
drivers/block/ibnbd/ibnbd-clt.c new file +6 -0
+/*
+ * This is for closing devices when unloading the module:
+ * we might be closing a lot (>256) of devices in parallel
+ * and it is better not to use the system_wq.
+ */
+static struct workqueue_struct *unload_wq;

I think that a better motivation is needed for the introduction of a new workqueue.

Quoted 2 lines

We didn't want to pollute the system workqueue when unmapping a big number of devices at once in parallel. Will reiterate on it.

There are multiple system workqueues. From <linux/workqueue.h>:

extern struct workqueue_struct *system_wq;
extern struct workqueue_struct *system_highpri_wq;
extern struct workqueue_struct *system_long_wq;
extern struct workqueue_struct *system_unbound_wq;
extern struct workqueue_struct *system_freezable_wq; extern struct workqueue_struct *system_power_efficient_wq; extern struct workqueue_struct *system_freezable_power_efficient_wq;

Has it been considered to use e.g. system_long_wq?

Quoted 12 lines
Quoted 2 lines

A more general question is why ibnbd needs its own queue management while no other block driver needs this?

Each IBNBD device promises to have a queue_depth (of say 512) on each of its num_cpus hardware queues. In fact we can only process a queue_depth inflights at once on the whole ibtrs session connecting a given client with a given server. Those 512 inflights (corresponding to the number of buffers reserved by the server for this particular client) have to be shared among all the devices mapped on this session. This leads to the situation, that we receive more requests than we can process at the moment. So we need to stop queues and start them again later in some fair fashion.

Can a single CPU really sustain a queue depth of 512 commands? Is it really necessary to have one hardware queue per CPU or is e.g. four queues per NUMA node sufficient? Has it been considered to send the number of hardware queues that the initiator wants to use and also the command depth per queue during login to the target side? That would allow the target side to allocate an independent set of buffers for each initiator hardware queue and would allow to remove the queue management at the initiator side. This might even yield better performance.

Quoted 7 lines
Quoted 7 lines

drivers/block/ibnbd/ibnbd-clt.c line 459

Quoted 3 lines
drivers/block/ibnbd/ibnbd-clt.c new file +3 -0
+static void msg_conf(void *priv, int errno)
+{
+     struct ibnbd_iu *iu = (struct ibnbd_iu *)priv;

The kernel code I'm familiar with does not cast void pointers explicitly into another type. Please follow that convention and leave the cast out from the above and also from similar statements.

Quoted 7 lines

msg_conf() is a callback which IBNBD passes down with a request to IBTRS when calling ibtrs_clt_request(). msg_conf() is called when a request is completed with a pointer to a struct defined in IBNBD. So IBTRS as transport doesn't know what's inside the private pointer which IBNBD passed down with the request, it's opaque, since struct ibnbd_iu is not visible in IBTRS. I will try to find how others avoid a cast in similar situations.

Are you aware that the C language can cast a void pointer into a non-void pointer implicitly, that means, without having to use a cast?

Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
drivers/block/ibnbd/ibnbd-clt.c new file +12 -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);
Quoted 8 lines

drivers/block/ibnbd/ibnbd-clt.c line 917

Quoted 4 lines
drivers/block/ibnbd/ibnbd-clt.c new file +4 -0
+     /* After unlock session can be freed, so careful */
+     schedule();
+     mutex_lock(&sess_lock);
+}

This doesn't look right: any random wake_up() call can wake up this function. Shouldn't there be a loop in this function that causes the schedule() call to be repeated until the disconnect has happened?

Quoted 5 lines

The loop is inside __find_and_get_sess(), which is calling that function. We need to schedule() here in order for another thread to be able to remove the dying session we just found and tried to get reference to from the list of sessions, so that we can go over the list again in __find_and_get_sess().

Thanks for the clarification.

Bart.

#75 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

Quoted 27 lines · Bart Van Assche
Quoted 12 lines · Danil Kipnis
Quoted 10 lines · Bart Van Assche

drivers/block/ibnbd/ibnbd-clt.c line 45

Quoted 6 lines · Jack Wang
drivers/block/ibnbd/ibnbd-clt.c new file +6 -0
+/*
+ * This is for closing devices when unloading the module:
+ * we might be closing a lot (>256) of devices in parallel
+ * and it is better not to use the system_wq.
+ */
+static struct workqueue_struct *unload_wq;

I think that a better motivation is needed for the introduction of a new workqueue.

Quoted 2 lines

We didn't want to pollute the system workqueue when unmapping a big number of devices at once in parallel. Will reiterate on it.

There are multiple system workqueues. From <linux/workqueue.h>:

extern struct workqueue_struct *system_wq;
extern struct workqueue_struct *system_highpri_wq;
extern struct workqueue_struct *system_long_wq;
extern struct workqueue_struct *system_unbound_wq;
extern struct workqueue_struct *system_freezable_wq; extern struct workqueue_struct *system_power_efficient_wq; extern struct workqueue_struct *system_freezable_power_efficient_wq;

Quoted 1 line

Has it been considered to use e.g. system_long_wq?

Will try to switch to system_long_wq, I do agree that a new wq for just closing devices does make an impression of an overreaction.

Quoted 14 lines
Quoted 4 lines
Quoted 3 lines

A more general question is why ibnbd needs its own queue management while no other block driver needs this?

Quoted 9 lines

Each IBNBD device promises to have a queue_depth (of say 512) on each of its num_cpus hardware queues. In fact we can only process a queue_depth inflights at once on the whole ibtrs session connecting a given client with a given server. Those 512 inflights (corresponding to the number of buffers reserved by the server for this particular client) have to be shared among all the devices mapped on this session. This leads to the situation, that we receive more requests than we can process at the moment. So we need to stop queues and start them again later in some fair fashion.

Quoted 8 lines

Can a single CPU really sustain a queue depth of 512 commands? Is it really necessary to have one hardware queue per CPU or is e.g. four queues per NUMA node sufficient? Has it been considered to send the number of hardware queues that the initiator wants to use and also the command depth per queue during login to the target side? That would allow the target side to allocate an independent set of buffers for each initiator hardware queue and would allow to remove the queue management at the initiator side. This might even yield better performance.

We needed a way which would allow us to address one particular
requirement: we'd like to be able to "enforce" that a response to an IO would be processed on the same CPU the IO was originally submitted on. In order to be able to do so we establish one rdma connection per cpu, each having a separate cq_vector. The administrator can then assign the corresponding IRQs to distinct CPUs. The server always replies to an IO on the same connection he received the request on. If the administrator did configure the /proc/irq/y/smp_affinity accordingly, the response sent by the server will generate interrupt on the same cpu, the IO was originally submitted on. The administrator can configure IRQs differently, for example assign a given irq (<->cq_vector) to a range of cpus belonging to a numa node, or whatever assignment is best for his use-case.
Our transport module IBTRS establishes number of cpus connections between a client and a server. The user of the transport module (i.e. IBNBD) has no knowledge about the rdma connections, it only has a pointer to an abstract "session", which connects him somehow to a remote host. IBNBD as a user of IBTRS creates block devices and uses a given "session" to send IOs from all the block devices it created for that session. That means IBNBD is limited in maximum number of his inflights toward a given remote host by the capability of the corresponding "session". So it needs to share the resources provided by the session (in our current model those resources are in fact some pre registered buffers on server side) among his devices. It is possible to extend the IBTRS API so that the user (IBNBD) could specify how many connections he wants to have on the session to be established. It is also possible to extend the ibtrs_clt_get_tag API (this is to get a send "permit") with a parameter specifying the connection, the future IO is to be send on.
We now might have to change our communication model in IBTRS a bit in order to fix the potential security problem raised during the recent RDMA MC: https://etherpad.net/p/LPC2019_RDMA.

Quoted 16 lines
Quoted 8 lines
Quoted 8 lines

drivers/block/ibnbd/ibnbd-clt.c line 459

Quoted 4 lines
drivers/block/ibnbd/ibnbd-clt.c new file +3 -0
+static void msg_conf(void *priv, int errno)
+{
+     struct ibnbd_iu *iu = (struct ibnbd_iu *)priv;

The kernel code I'm familiar with does not cast void pointers explicitly into another type. Please follow that convention and leave the cast out from the above and also from similar statements.

Quoted 7 lines

msg_conf() is a callback which IBNBD passes down with a request to IBTRS when calling ibtrs_clt_request(). msg_conf() is called when a request is completed with a pointer to a struct defined in IBNBD. So IBTRS as transport doesn't know what's inside the private pointer which IBNBD passed down with the request, it's opaque, since struct ibnbd_iu is not visible in IBTRS. I will try to find how others avoid a cast in similar situations.

Quoted 2 lines

Are you aware that the C language can cast a void pointer into a non-void pointer implicitly, that means, without having to use a cast?

Oh, I misunderstood your original comment: you suggest to just remove the explicit (struct ibnbd_iu *) and similar casts from void pointers. I think an explicit cast makes it easier for readers to follow the code. But it does say "Casting the return value which is a void pointer is redundant." at least in the "Allocating Memory" section of
https://www.kernel.org/doc/html/v4.10/process/coding-style.html and seems others don't do that, at least not when declaring a variable. Will drop those casts.

#76 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

Quoted 46 lines
Quoted 14 lines
Quoted 13 lines · Bart Van Assche
Quoted 2 lines

A more general question is why ibnbd needs its own queue management while no other block driver needs this?

Each IBNBD device promises to have a queue_depth (of say 512) on each of its num_cpus hardware queues. In fact we can only process a queue_depth inflights at once on the whole ibtrs session connecting a given client with a given server. Those 512 inflights (corresponding to the number of buffers reserved by the server for this particular client) have to be shared among all the devices mapped on this session. This leads to the situation, that we receive more requests than we can process at the moment. So we need to stop queues and start them again later in some fair fashion.

Quoted 8 lines

Can a single CPU really sustain a queue depth of 512 commands? Is it really necessary to have one hardware queue per CPU or is e.g. four queues per NUMA node sufficient? Has it been considered to send the number of hardware queues that the initiator wants to use and also the command depth per queue during login to the target side? That would allow the target side to allocate an independent set of buffers for each initiator hardware queue and would allow to remove the queue management at the initiator side. This might even yield better performance.

We needed a way which would allow us to address one particular
requirement: we'd like to be able to "enforce" that a response to an IO would be processed on the same CPU the IO was originally submitted on. In order to be able to do so we establish one rdma connection per cpu, each having a separate cq_vector. The administrator can then assign the corresponding IRQs to distinct CPUs. The server always replies to an IO on the same connection he received the request on. If the administrator did configure the /proc/irq/y/smp_affinity accordingly, the response sent by the server will generate interrupt on the same cpu, the IO was originally submitted on. The administrator can configure IRQs differently, for example assign a given irq (<->cq_vector) to a range of cpus belonging to a numa node, or whatever assignment is best for his use-case.
Our transport module IBTRS establishes number of cpus connections between a client and a server. The user of the transport module (i.e. IBNBD) has no knowledge about the rdma connections, it only has a pointer to an abstract "session", which connects him somehow to a remote host. IBNBD as a user of IBTRS creates block devices and uses a given "session" to send IOs from all the block devices it created for that session. That means IBNBD is limited in maximum number of his inflights toward a given remote host by the capability of the corresponding "session". So it needs to share the resources provided by the session (in our current model those resources are in fact some pre registered buffers on server side) among his devices.

Quoted 9 lines

It is possible to extend the IBTRS API so that the user (IBNBD) could specify how many connections he wants to have on the session to be established. It is also possible to extend the ibtrs_clt_get_tag API (this is to get a send "permit") with a parameter specifying the connection, the future IO is to be send on.
We now might have to change our communication model in IBTRS a bit in order to fix the potential security problem raised during the recent RDMA MC: https://etherpad.net/p/LPC2019_RDMA.

I'm not familiar with dm code, but don't they need to deal with the same situation: if I configure 100 logical volumes on top of a single NVME drive with X hardware queues, each queue_depth deep, then each dm block device would need to advertise X hardware queues in order to achieve highest performance in case only this one volume is accessed, while in fact those X physical queues have to be shared among all 100 logical volumes, if they are accessed in parallel?

#77 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

Quoted 7 lines · Danil Kipnis

I'm not familiar with dm code, but don't they need to deal with the same situation: if I configure 100 logical volumes on top of a single NVME drive with X hardware queues, each queue_depth deep, then each dm block device would need to advertise X hardware queues in order to achieve highest performance in case only this one volume is accessed, while in fact those X physical queues have to be shared among all 100 logical volumes, if they are accessed in parallel?

Combining multiple queues (a) into a single queue (b) that is smaller than the combined source queues without sacrificing performance is tricky. We already have one such implementation in the block layer core and it took considerable time to get that implementation right. See e.g. blk_mq_sched_mark_restart_hctx() and blk_mq_sched_restart().

dm drivers are expected to return DM_MAPIO_REQUEUE or DM_MAPIO_DELAY_REQUEUE if the queue (b) is full. It turned out to be difficult to get this right in the dm-mpath driver and at the same time to achieve good performance.

The ibnbd driver introduces a third implementation of code that combines multiple (per-cpu) queues into one queue per CPU. It is considered important in the Linux kernel to avoid code duplication. Hence my question whether ibnbd can reuse the block layer infrastructure for sharing tag sets.

Thanks,

Bart.

#78 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

Quoted 10 lines · Bart Van Assche
Quoted 7 lines · Danil Kipnis

I'm not familiar with dm code, but don't they need to deal with the same situation: if I configure 100 logical volumes on top of a single NVME drive with X hardware queues, each queue_depth deep, then each dm block device would need to advertise X hardware queues in order to achieve highest performance in case only this one volume is accessed, while in fact those X physical queues have to be shared among all 100 logical volumes, if they are accessed in parallel?

Quoted 5 lines

Combining multiple queues (a) into a single queue (b) that is smaller than the combined source queues without sacrificing performance is tricky. We already have one such implementation in the block layer core and it took considerable time to get that implementation right. See e.g. blk_mq_sched_mark_restart_hctx() and blk_mq_sched_restart().

We will need some time, to check if we can reuse those...

Quoted 4 lines

dm drivers are expected to return DM_MAPIO_REQUEUE or DM_MAPIO_DELAY_REQUEUE if the queue (b) is full. It turned out to be difficult to get this right in the dm-mpath driver and at the same time to achieve good performance.

We also first tried to just return error codes in case we can't process an incoming request, but this was causing huge performance degradation when number of devices mapped over the same session is growing. Since we introduced those per cpu per devices lists of stopped queues, we do scale very well.

Quoted 6 lines

The ibnbd driver introduces a third implementation of code that combines multiple (per-cpu) queues into one queue per CPU. It is considered important in the Linux kernel to avoid code duplication. Hence my question whether ibnbd can reuse the block layer infrastructure for sharing tag sets.

Yes, will have to reiterate on this.

#79 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

In reply to Bart Van Assche
Quoted 5 lines · Bart Van Assche

Combining multiple queues (a) into a single queue (b) that is smaller than the combined source queues without sacrificing performance is tricky. We already have one such implementation in the block layer core and it took considerable time to get that implementation right. See e.g. blk_mq_sched_mark_restart_hctx() and blk_mq_sched_restart().

Roma, can you please estimate the performance impact in case we switch to it?

#80 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

Quoted 9 lines · Danil Kipnis
Quoted 5 lines · Bart Van Assche

Combining multiple queues (a) into a single queue (b) that is smaller than the combined source queues without sacrificing performance is tricky. We already have one such implementation in the block layer core and it took considerable time to get that implementation right. See e.g. blk_mq_sched_mark_restart_hctx() and blk_mq_sched_restart().

Roma, can you please estimate the performance impact in case we switch to it?

As I remember correctly I could not reuse the whole machinery with those restarts from block core because shared tags are shared only between hardware queues, i.e. different hardware queues share different tags sets. IBTRS has many hardware queues (independent RDMA connections) but only one tags set, which is equally shared between block devices. What I dreamed about is something like BLK_MQ_F_TAG_GLOBALLY_SHARED support in block layer.

--
Roman

#81 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

Quoted 7 lines · Roman Penyaev

As I remember correctly I could not reuse the whole machinery with those restarts from block core because shared tags are shared only between hardware queues, i.e. different hardware queues share different tags sets. IBTRS has many hardware queues (independent RDMA connections) but only one tags set, which is equally shared between block devices. What I dreamed about is something like BLK_MQ_F_TAG_GLOBALLY_SHARED support in block layer.

A patch series that adds support for sharing tag sets across hardware queues is pending. See also "[PATCH V3 0/8] blk-mq & scsi: fix reply queue selection and improve host wide tagset" (https://lore.kernel.org/linux-block/[email protected]/). Would that patch series allow to remove the queue management code from ibnbd?

Thanks,

Bart.

#82 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

Quoted 10 lines · Bart Van Assche
Quoted 7 lines · Roman Penyaev

As I remember correctly I could not reuse the whole machinery with those restarts from block core because shared tags are shared only between hardware queues, i.e. different hardware queues share different tags sets. IBTRS has many hardware queues (independent RDMA connections) but only one tags set, which is equally shared between block devices. What I dreamed about is something like BLK_MQ_F_TAG_GLOBALLY_SHARED support in block layer.

Quoted 6 lines

A patch series that adds support for sharing tag sets across hardware queues is pending. See also "[PATCH V3 0/8] blk-mq & scsi: fix reply queue selection and improve host wide tagset"
(https://lore.kernel.org/linux-block/[email protected]/).
Would that patch series allow to remove the queue management code from ibnbd?

Hi Bart,

No, it seems this thingy is a bit different. According to my understanding patches 3 and 4 from this patchset do the
following: 1# split equally the whole queue depth on number of hardware queues and 2# return tag number which is unique host-wide (more or less similar to unique_tag, right?).

2# is not needed for ibtrs, and 1# can be easy done by dividing queue_depth on number of hw queues on tag set allocation, e.g. something like the following:

    ...
    tags->nr_hw_queues = num_online_cpus();
    tags->queue_depth  = sess->queue_deph / tags->nr_hw_queues;

    blk_mq_alloc_tag_set(tags);

And this trick won't work out for the performance. ibtrs client has a single resource: set of buffer chunks received from a server side. And these buffers should be dynamically distributed between IO producers according to the load. Having a hard split of the whole queue depth between hw queues we can forget about a dynamic load distribution, here is an example:

- say server shares 1024 buffer chunks for a session (do not remember what is the actual number).

- 1024 buffers are equally divided between hw queues, let's say 64 (number of cpus), so each queue is 16 requests depth.

- only several CPUs produce IO, and instead of occupying the whole "bandwidth" of a session, i.e. 1024 buffer chunks, we limit ourselves to a small queue depth of an each hw queue.

And performance drops significantly when number of IO producers is smaller than number of hw queues (CPUs), and it can be easily tested and proved.

So for this particular ibtrs case tags should be globally shared, and seems (unfortunately) there is no any other similar requirements for other block devices.

--
Roman

#83 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

Quoted 36 lines · Roman Penyaev

No, it seems this thingy is a bit different. According to my understanding patches 3 and 4 from this patchset do the
following: 1# split equally the whole queue depth on number of hardware queues and 2# return tag number which is unique host-wide (more or less similar to unique_tag, right?).

2# is not needed for ibtrs, and 1# can be easy done by dividing queue_depth on number of hw queues on tag set allocation, e.g. something like the following:

    ...
    tags->nr_hw_queues = num_online_cpus();
    tags->queue_depth  = sess->queue_deph / tags->nr_hw_queues;

    blk_mq_alloc_tag_set(tags);

And this trick won't work out for the performance. ibtrs client has a single resource: set of buffer chunks received from a server side. And these buffers should be dynamically distributed between IO producers according to the load. Having a hard split of the whole queue depth between hw queues we can forget about a dynamic load distribution, here is an example:

- say server shares 1024 buffer chunks for a session (do not remember what is the actual number).

- 1024 buffers are equally divided between hw queues, let's say 64 (number of cpus), so each queue is 16 requests depth.

- only several CPUs produce IO, and instead of occupying the whole "bandwidth" of a session, i.e. 1024 buffer chunks, we limit ourselves to a small queue depth of an each hw queue.

Quoted 7 lines

And performance drops significantly when number of IO producers is smaller than number of hw queues (CPUs), and it can be easily tested and proved.

So for this particular ibtrs case tags should be globally shared, and seems (unfortunately) there is no any other similar requirements for other block devices.

I don't see any difference between what you describe here and 100 dm volumes sitting on top of a single NVME device.

#84 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

Quoted 40 lines · Danil Kipnis
Quoted 39 lines · Roman Penyaev

No, it seems this thingy is a bit different. According to my understanding patches 3 and 4 from this patchset do the
following: 1# split equally the whole queue depth on number of hardware queues and 2# return tag number which is unique host-wide (more or less similar to unique_tag, right?).

2# is not needed for ibtrs, and 1# can be easy done by dividing queue_depth on number of hw queues on tag set allocation, e.g. something like the following:

     ...
     tags->nr_hw_queues = num_online_cpus();
     tags->queue_depth  = sess->queue_deph / tags->nr_hw_queues;

     blk_mq_alloc_tag_set(tags);

And this trick won't work out for the performance. ibtrs client has a single resource: set of buffer chunks received from a server side. And these buffers should be dynamically distributed between IO producers according to the load. Having a hard split of the whole queue depth between hw queues we can forget about a dynamic load distribution, here is an example:

- say server shares 1024 buffer chunks for a session (do not remember what is the actual number).

- 1024 buffers are equally divided between hw queues, let's say 64 (number of cpus), so each queue is 16 requests depth.

- only several CPUs produce IO, and instead of occupying the whole "bandwidth" of a session, i.e. 1024 buffer chunks, we limit ourselves to a small queue depth of an each hw queue.

And performance drops significantly when number of IO producers is smaller than number of hw queues (CPUs), and it can be easily tested and proved.

Quoted 5 lines
Quoted 3 lines

So for this particular ibtrs case tags should be globally shared, and seems (unfortunately) there is no any other similar requirements for other block devices.

I don't see any difference between what you describe here and 100 dm volumes sitting on top of a single NVME device.

Hallo Christoph,

am I wrong?

Thank you,

Danil.

#85 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

In reply to Roman Penyaev
Quoted 35 lines · Roman Penyaev

No, it seems this thingy is a bit different. According to my understanding patches 3 and 4 from this patchset do the
following: 1# split equally the whole queue depth on number of hardware queues and 2# return tag number which is unique host-wide (more or less similar to unique_tag, right?).

2# is not needed for ibtrs, and 1# can be easy done by dividing queue_depth on number of hw queues on tag set allocation, e.g. something like the following:

     ...
     tags->nr_hw_queues = num_online_cpus();
     tags->queue_depth  = sess->queue_deph / tags->nr_hw_queues;

     blk_mq_alloc_tag_set(tags);

And this trick won't work out for the performance. ibtrs client has a single resource: set of buffer chunks received from a server side. And these buffers should be dynamically distributed between IO producers according to the load. Having a hard split of the whole queue depth between hw queues we can forget about a dynamic load distribution, here is an example:

- say server shares 1024 buffer chunks for a session (do not remember what is the actual number).

- 1024 buffers are equally divided between hw queues, let's say 64 (number of cpus), so each queue is 16 requests depth.

- only several CPUs produce IO, and instead of occupying the whole "bandwidth" of a session, i.e. 1024 buffer chunks, we limit ourselves to a small queue depth of an each hw queue.

Quoted 7 lines

And performance drops significantly when number of IO producers is smaller than number of hw queues (CPUs), and it can be easily tested and proved.

So for this particular ibtrs case tags should be globally shared, and seems (unfortunately) there is no any other similar requirements for other block devices.

Hi Roman,

I agree that BLK_MQ_F_HOST_TAGS partitions a tag set across hardware queues while ibnbd shares a single tag set across multiple hardware queues. Since such sharing may be useful for other block drivers, isn't that something that should be implemented in the block layer core instead of in the ibnbd driver? If that logic would be moved into the block layer core, would that allow to reuse the queue restarting logic that already exists in the block layer core?

Thanks,

Bart.

#86 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

Quoted 47 lines · Bart Van Assche
Quoted 35 lines · Roman Penyaev

No, it seems this thingy is a bit different. According to my understanding patches 3 and 4 from this patchset do the
following: 1# split equally the whole queue depth on number of hardware queues and 2# return tag number which is unique host-wide (more or less similar to unique_tag, right?).

2# is not needed for ibtrs, and 1# can be easy done by dividing queue_depth on number of hw queues on tag set allocation, e.g. something like the following:

     ...
     tags->nr_hw_queues = num_online_cpus();
     tags->queue_depth  = sess->queue_deph / tags->nr_hw_queues;

     blk_mq_alloc_tag_set(tags);

And this trick won't work out for the performance. ibtrs client has a single resource: set of buffer chunks received from a server side. And these buffers should be dynamically distributed between IO producers according to the load. Having a hard split of the whole queue depth between hw queues we can forget about a dynamic load distribution, here is an example:

- say server shares 1024 buffer chunks for a session (do not remember what is the actual number).

- 1024 buffers are equally divided between hw queues, let's say 64 (number of cpus), so each queue is 16 requests depth.

- only several CPUs produce IO, and instead of occupying the whole "bandwidth" of a session, i.e. 1024 buffer chunks, we limit ourselves to a small queue depth of an each hw queue.

Quoted 7 lines

And performance drops significantly when number of IO producers is smaller than number of hw queues (CPUs), and it can be easily tested and proved.

So for this particular ibtrs case tags should be globally shared, and seems (unfortunately) there is no any other similar requirements for other block devices.

Hi Roman,

Quoted 7 lines

I agree that BLK_MQ_F_HOST_TAGS partitions a tag set across hardware queues while ibnbd shares a single tag set across multiple hardware queues. Since such sharing may be useful for other block drivers, isn't that something that should be implemented in the block layer core instead of in the ibnbd driver? If that logic would be moved into the block layer core, would that allow to reuse the queue restarting logic that already exists in the block layer core?

Definitely yes, but what other block drivers you have in mind?

--
Roman

#87 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

Quoted 10 lines · Roman Penyaev
Quoted 7 lines · Bart Van Assche

I agree that BLK_MQ_F_HOST_TAGS partitions a tag set across hardware queues while ibnbd shares a single tag set across multiple hardware queues. Since such sharing may be useful for other block drivers, isn't that something that should be implemented in the block layer core instead of in the ibnbd driver? If that logic would be moved into the block layer core, would that allow to reuse the queue restarting logic that already exists in the block layer core?

Definitely yes, but what other block drivers you have in mind?

I'd like to hear the opinion of Jens and Christoph about this topic. My concern is that if the code for sharing a tag set across hwqs stays in the ibnbd driver and if another block driver is submitted in the future that needs the same logic that in order to end up with a single implementation of the tag set sharing code that the authors of the new driver would have to be asked to modify the ibnbd driver. I think it would be inappropriate to ask the authors of such a new driver to modify the ibnbd driver.

Bart.

#88 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

In reply to Bart Van Assche
Quoted 23 lines
Quoted 23 lines
drivers/block/ibnbd/ibnbd-clt.c new file +23 -0
+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;
+
+     iu = blk_mq_rq_to_pdu(rq);
+     ibnbd_put_tag(sess, iu->tag);
+     blk_mq_end_request(rq, iu->status);
+}
+
+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;
+
+     if (softirq_enable) {
+             blk_mq_complete_request(rq);
+     } else {
+             ibnbd_put_tag(dev->sess, iu->tag);
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+             blk_mq_end_request(rq, iu->status);
+     }

Block drivers must call blk_mq_complete_request() instead of blk_mq_end_request() to complete a request after processing of the request has been started. Calling blk_mq_end_request() to complete a request is racy in case a timeout occurs while blk_mq_end_request() is in progress.

Hi Bart,

Could you elaborate a bit more, blk_mq_end_request is exported function and used by a lot of block drivers: scsi, dm, etc.
Is there an open bug report for the problem?

Regards,
Jinpu

#89 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

Quoted 32 lines · Jinpu Wang
Quoted 23 lines
Quoted 23 lines
drivers/block/ibnbd/ibnbd-clt.c new file +23 -0
+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;
+
+     iu = blk_mq_rq_to_pdu(rq);
+     ibnbd_put_tag(sess, iu->tag);
+     blk_mq_end_request(rq, iu->status);
+}
+
+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;
+
+     if (softirq_enable) {
+             blk_mq_complete_request(rq);
+     } else {
+             ibnbd_put_tag(dev->sess, iu->tag);
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+             blk_mq_end_request(rq, iu->status);
+     }

Block drivers must call blk_mq_complete_request() instead of blk_mq_end_request() to complete a request after processing of the request has been started. Calling blk_mq_end_request() to complete a request is racy in case a timeout occurs while blk_mq_end_request() is in progress.

Quoted 3 lines

Could you elaborate a bit more, blk_mq_end_request is exported function and used by a lot of block drivers: scsi, dm, etc.
Is there an open bug report for the problem?

Hi Jinpu,

There is only one blk_mq_end_request() call in the SCSI code and it's inside the FC timeout handler (fc_bsg_job_timeout()). Calling blk_mq_end_request() from inside a timeout handler is fine but not to report to the block layer that a request has completed from outside the timeout handler after a request has started.

The device mapper calls blk_mq_complete_request() to report request completion to the block layer. See also dm_complete_request(). blk_mq_end_request() is only called by the device mapper from inside dm_softirq_done(). That last function is called from inside blk_mq_complete_request() and is not called directly.

The NVMe PCIe driver only calls blk_mq_end_request() from inside nvme_complete_rq(). nvme_complete_rq() is called by the PCIe driver from inside nvme_pci_complete_rq() and that last function is called from inside blk_mq_complete_request().

In other words, the SCSI core, the device mapper and the NVMe PCIe driver all use blk_mq_complete_request() to report request completion to the block layer from outside timeout handlers after a request has been started.

This is not a new requirement. I think that the legacy block layer equivalent, blk_complete_request(), was introduced in 2006 and that since then block drivers are required to call blk_complete_request() to report completion of requests from outside a timeout handler after these have been started.

Bart.

#90 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

Quoted 62 lines · Bart Van Assche
Quoted 32 lines · Jinpu Wang
Quoted 23 lines
Quoted 23 lines
drivers/block/ibnbd/ibnbd-clt.c new file +23 -0
+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;
+
+     iu = blk_mq_rq_to_pdu(rq);
+     ibnbd_put_tag(sess, iu->tag);
+     blk_mq_end_request(rq, iu->status);
+}
+
+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;
+
+     if (softirq_enable) {
+             blk_mq_complete_request(rq);
+     } else {
+             ibnbd_put_tag(dev->sess, iu->tag);
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+             blk_mq_end_request(rq, iu->status);
+     }

Block drivers must call blk_mq_complete_request() instead of blk_mq_end_request() to complete a request after processing of the request has been started. Calling blk_mq_end_request() to complete a request is racy in case a timeout occurs while blk_mq_end_request() is in progress.

Quoted 3 lines

Could you elaborate a bit more, blk_mq_end_request is exported function and used by a lot of block drivers: scsi, dm, etc.
Is there an open bug report for the problem?

Hi Jinpu,

There is only one blk_mq_end_request() call in the SCSI code and it's inside the FC timeout handler (fc_bsg_job_timeout()). Calling blk_mq_end_request() from inside a timeout handler is fine but not to report to the block layer that a request has completed from outside the timeout handler after a request has started.

The device mapper calls blk_mq_complete_request() to report request completion to the block layer. See also dm_complete_request(). blk_mq_end_request() is only called by the device mapper from inside dm_softirq_done(). That last function is called from inside blk_mq_complete_request() and is not called directly.

The NVMe PCIe driver only calls blk_mq_end_request() from inside nvme_complete_rq(). nvme_complete_rq() is called by the PCIe driver from inside nvme_pci_complete_rq() and that last function is called from inside blk_mq_complete_request().

In other words, the SCSI core, the device mapper and the NVMe PCIe driver all use blk_mq_complete_request() to report request completion to the block layer from outside timeout handlers after a request has been started.

Quoted 7 lines

This is not a new requirement. I think that the legacy block layer equivalent, blk_complete_request(), was introduced in 2006 and that since then block drivers are required to call blk_complete_request() to report completion of requests from outside a timeout handler after these have been started.

Bart.

Thanks for the detailed explanation, I will switch to blk_mq_complete_request(), will also drop the softirq_done module parameter, not useful.

Regards,
Jinpu

#91 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

In reply to Bart Van Assche
Quoted 12 lines

drivers/block/ibnbd/ibnbd-clt.c line 1640

Quoted 11 lines
drivers/block/ibnbd/ibnbd-clt.c new file +10 -0
+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);
Quoted 4 lines

Please remove the above seven lines. blk_cleanup_queue() calls blk_set_queue_dying() and the second call in blk_set_queue_dying() is blk_freeze_queue_start().

It was an old bug we had in 2016, we retested with newer kernel like 4.14+, the bug is fixed,
I will remove the above seven lines.

Thanks
Jinpu

#92 lore raw

Re: [PATCH v4 17/25] ibnbd: client: main functionality

In reply to Jack Wang
Quoted 1 line · Jack Wang

From: Roman Pen <[email protected]>

A "From" address should be a valid email address. For the above address I got the following reply:

550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces.

Bart.

author
#93 lore raw

PATCH v4 18/25 ibnbd: client: sysfs interface functions

In reply to Jack Wang

From: Roman Pen <[email protected]>

This is the sysfs interface to IBNBD block devices on client side:

/sys/devices/virtual/ibnbd-client/ctl/

    |- 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 | 691 ++++++++++++++++++++++++++
 1 file changed, 691 insertions(+)
 create mode 100644 drivers/block/ibnbd/ibnbd-clt-sysfs.c
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +691 -0
new file mode 100644
index 000000000000..4fd365e68e0f
@@ -0,0 +1,691 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * 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]>
+ *          Swapnil Ingle <[email protected]>
+ *
+ * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
+ * Authors: Roman Penyaev <[email protected]>
+ *          Jack Wang <[email protected]>
+ *          Danil Kipnis <[email protected]>
+ */
+
+#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 <linux/device.h>
+#include <rdma/ib.h>
+#include <rdma/rdma_cm.h>
+
+#include "ibnbd-clt.h"
+
+static struct device *ibnbd_dev;
+static struct class *ibnbd_dev_class;
+static struct kobject *ibnbd_devs_kobj;
+
+enum {
+	IBNBD_OPT_ERR		= 0,
+	IBNBD_OPT_PATH		= 1 << 0,
+	IBNBD_OPT_DEV_PATH	= 1 << 1,
+	IBNBD_OPT_ACCESS_MODE	= 1 << 3,
+	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_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_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;
+
+	sep_opt = strstrip(options);
+	strip(sep_opt);
+	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:
+			if (p_cnt >= max_path_cnt) {
+				pr_err("map_device: too many (> %zu) paths "
+				       "provided\n", max_path_cnt);
+				ret = -ENOMEM;
+				goto out;
+			}
+			p = match_strdup(args);
+			if (!p) {
+				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_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_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_access_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_access_mode_str(dev->access_mode));
+}
+
+static struct kobj_attribute ibnbd_clt_access_mode =
+	__ATTR(access_mode, 0444, ibnbd_clt_access_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);
+}
+
+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 *opt, *options;
+	bool force;
+	int err;
+
+	opt = kstrdup(buf, GFP_KERNEL);
+	if (!opt)
+		return -ENOMEM;
+
+	options = strstrip(opt);
+	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(opt);
+
+	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, &sectors);
+	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 *opt, *options;
+	int err;
+
+	opt = kstrdup(buf, GFP_KERNEL);
+	if (!opt)
+		return -ENOMEM;
+
+	options = strstrip(opt);
+	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(opt);
+
+	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_session_attr.attr,
+	&ibnbd_clt_io_mode.attr,
+	&ibnbd_clt_access_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_devs_kobj, 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>]"
+			 " [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_devs_kobj, 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_io_mode io_mode = IBNBD_AUTOIO;
+
+	struct sockaddr_storage *addrs;
+	struct ibtrs_addr paths[6];
+	size_t path_cnt;
+
+	addrs = kcalloc(ARRAY_SIZE(paths) * 2, sizeof(*addrs), GFP_KERNEL);
+	if (!addrs)
+		return -ENOMEM;
+
+	for (path_cnt = 0; path_cnt < ARRAY_SIZE(paths); path_cnt++) {
+		paths[path_cnt].src = &addrs[path_cnt * 2];
+		paths[path_cnt].dst = &addrs[path_cnt * 2 + 1];
+	}
+
+	ret = ibnbd_clt_parse_map_options(buf, sessname, paths,
+					  &path_cnt, ARRAY_SIZE(paths),
+					  pathname, &access_mode, &io_mode);
+	if (ret)
+		goto out;
+
+	pr_info("Mapping device %s on session %s, (access_mode: %s, "
+		"io_mode: %s)\n", pathname, sessname,
+		ibnbd_access_mode_str(access_mode), ibnbd_io_mode_str(io_mode));
+
+	dev = ibnbd_clt_map_device(sessname, paths, path_cnt, pathname,
+				   access_mode, io_mode);
+	if (unlikely(IS_ERR(dev))) {
+		ret = PTR_ERR(dev);
+		goto out;
+	}
+
+	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;
+
+	kfree(addrs);
+	return count;
+
+unmap_dev:
+	ibnbd_clt_unmap_device(dev, true, NULL);
+out:
+	kfree(addrs);
+	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;
+
+	ibnbd_dev_class = class_create(THIS_MODULE, "ibnbd-client");
+	if (unlikely(IS_ERR(ibnbd_dev_class)))
+		return PTR_ERR(ibnbd_dev_class);
+
+	ibnbd_dev = device_create(ibnbd_dev_class, NULL,
+				  MKDEV(0, 0), NULL, "ctl");
+	if (unlikely(IS_ERR(ibnbd_dev))) {
+		err = PTR_ERR(ibnbd_dev);
+		goto cls_destroy;
+	}
+	ibnbd_devs_kobj = kobject_create_and_add("devices", &ibnbd_dev->kobj);
+	if (unlikely(!ibnbd_devs_kobj)) {
+		err = -ENOMEM;
+		goto dev_destroy;
+	}
+	err = sysfs_create_group(&ibnbd_dev->kobj, &default_attr_group);
+	if (unlikely(err))
+		goto put_devs_kobj;
+
+	return 0;
+
+put_devs_kobj:
+	kobject_del(ibnbd_devs_kobj);
+	kobject_put(ibnbd_devs_kobj);
+dev_destroy:
+	device_destroy(ibnbd_dev_class, MKDEV(0, 0));
+cls_destroy:
+	class_destroy(ibnbd_dev_class);
+
+	return err;
+}
+
+void ibnbd_clt_destroy_default_group(void)
+{
+	sysfs_remove_group(&ibnbd_dev->kobj, &default_attr_group);
+}
+
+void ibnbd_clt_destroy_sysfs_files(void)
+{
+	kobject_del(ibnbd_devs_kobj);
+	kobject_put(ibnbd_devs_kobj);
+	device_destroy(ibnbd_dev_class, MKDEV(0, 0));
+	class_destroy(ibnbd_dev_class);
+}
Signature · 1 line
2.17.1
#94 lore raw

Re: [PATCH v4 18/25] ibnbd: client: sysfs interface functions

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 25

Quoted 2 lines · Jack Wang
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +2 -0
+#undef pr_fmt
+#define pr_fmt(fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt

Including the line number in all messages is too much information. Please don't do this. Additionally, this will make the line number occur twice in messages produced by pr_debug().

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 57

Quoted 5 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +5 -0
+static unsigned int ibnbd_opt_mandatory[] = {
+	IBNBD_OPT_PATH,
+	IBNBD_OPT_DEV_PATH,
+	IBNBD_OPT_SESSNAME,
+};

Should this array have been declared const?

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 80

Quoted 13 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +13 -0
+/* 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';
+}

This function can remove a newline from the middle of a string. Are you sure that's what you want?

Is it useful to strip newline characters only and to keep other whitespace? Could this function be dropped and can the callers use strim() instead?

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 90

Quoted 9 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +9 -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_io_mode *io_mode)
+{

Please introduce a structure for all the output parameters of this function and pass a pointer to that structure to this function. That will make it easier to introduce support for new parameters.

Quoted 5 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +5 -0
+	char *options, *sep_opt;
+	char *p;
+	substring_t args[MAX_OPT_ARGS];
+	int opt_mask = 0;
+	int token;

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 105

Quoted 10 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +10 -0
+	int ret = -EINVAL;
+	int i;
+	int p_cnt = 0;
+
+	options = kstrdup(buf, GFP_KERNEL);
+	if (!options)
+		return -ENOMEM;
+
+	sep_opt = strstrip(options);
+	strip(sep_opt);

Are you sure that strstrip() does not remove trailing newline characters?

Quoted 13 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +13 -0
+	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;

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 128

Quoted 10 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +10 -0
+			}
+			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;

Please change sessname from a fixed size buffer into a dynamically allocated buffer. That will remove the need to perform a strlcpy() and will also allow to remove the NAME_MAX checks.

Quoted 5 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +5 -0
+		case IBNBD_OPT_DEV_PATH:
+			p = match_strdup(args);
+			if (!p) {
+				ret = -ENOMEM;
+				goto out;

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 170

Quoted 10 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +10 -0
+			}
+			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;

Same comment here - please change pathname from a fixed-size array into a dynamically allocated buffer.

Quoted 12 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +12 -0
+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 */

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 261

Quoted 10 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +10 -0
+		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");
+	}
+}

Please remove the superfluous parentheses from around the DEV_STATE_* constants.

Additionally, using scnprintf() here is overkill. snprintf() should be sufficient.

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 264

Quoted 2 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +2 -0
+static struct kobj_attribute ibnbd_clt_state_attr =
+	__ATTR(state, 0444, ibnbd_clt_state_show, NULL);

Please use DEVICE_ATTR_RO() instead of __ATTR() for all read-only attributes.

Quoted 17 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +17 -0
+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 *opt, *options;
+	bool force;
+	int err;
+
+	opt = kstrdup(buf, GFP_KERNEL);
+	if (!opt)
+		return -ENOMEM;
+
+	options = strstrip(opt);
+	strip(options);
+
+	dev = container_of(kobj, struct ibnbd_clt_dev, kobj);

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 342

Quoted 10 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +10 -0
+
+	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;
+	}

Wasn't sysfs_streq() introduced to avoid having to duplicate and strip the input string?

Quoted 13 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +13 -0
+	/*
+	 * 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;

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 369

Quoted 10 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +10 -0
+	}
+
+	/*
+	 * Here device can be vanished!
+	 */
+
+	err = count;
+
+module_put:
+	module_put(THIS_MODULE);

I've never before seen a module_get() / module_put() pair inside a sysfs
callback function. Can this race be fixed by making
ibnbd_destroy_sessions() remove this sysfs attribute before it tries to destroy any sessions?

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 491

Quoted 10 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +10 -0
+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_devs_kobj, dev->blk_symlink_name);
+}

I haven't been able to find any other sysfs code that calls module_is_live()? Please elaborate why that check is needed.

Quoted 25 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +25 -0
+int ibnbd_clt_create_sysfs_files(void)
+{
+	int err;
+
+	ibnbd_dev_class = class_create(THIS_MODULE, "ibnbd-client");
+	if (unlikely(IS_ERR(ibnbd_dev_class)))
+		return PTR_ERR(ibnbd_dev_class);
+
+	ibnbd_dev = device_create(ibnbd_dev_class, NULL,
+				  MKDEV(0, 0), NULL, "ctl");
+	if (unlikely(IS_ERR(ibnbd_dev))) {
+		err = PTR_ERR(ibnbd_dev);
+		goto cls_destroy;
+	}
+	ibnbd_devs_kobj = kobject_create_and_add("devices", &ibnbd_dev->kobj);
+	if (unlikely(!ibnbd_devs_kobj)) {
+		err = -ENOMEM;
+		goto dev_destroy;
+	}
+	err = sysfs_create_group(&ibnbd_dev->kobj, &default_attr_group);
+	if (unlikely(err))
+		goto put_devs_kobj;
+
+	return 0;
+

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 678

Quoted 10 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +10 -0
+put_devs_kobj:
+	kobject_del(ibnbd_devs_kobj);
+	kobject_put(ibnbd_devs_kobj);
+dev_destroy:
+	device_destroy(ibnbd_dev_class, MKDEV(0, 0));
+cls_destroy:
+	class_destroy(ibnbd_dev_class);
+
+	return err;
+}

I think this is the wrong way to create a device node because this approach will inform udev about device creation before the sysfs group has been created. Please use device_create_with_groups() instead of calling device_create() and sysfs_create_group() separately.

Bart.

#95 lore raw

Re: [PATCH v4 18/25] ibnbd: client: sysfs interface functions

Quoted 8 lines · Bart Van Assche

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 25

Quoted 2 lines · Jack Wang
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +2 -0
+#undef pr_fmt
+#define pr_fmt(fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt

Including the line number in all messages is too much information. Please don't do this. Additionally, this will make the line number occur twice in messages produced by pr_debug().

We feel it's quite handy for debugging to have line number, I checked in mainline,
some driver even include __func__ and __LINE__.
Also did a test, the line number occur only once from pr_debug.

Quoted 8 lines

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 57

Quoted 6 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +5 -0
+static unsigned int ibnbd_opt_mandatory[] = {
+     IBNBD_OPT_PATH,
+     IBNBD_OPT_DEV_PATH,
+     IBNBD_OPT_SESSNAME,
+};

Should this array have been declared const?

Sounds good.

Quoted 17 lines
Quoted 4 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +3 -0
+/* remove new line from string */
+static void strip(char *s)
+{

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 80

Quoted 10 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +10 -0
+    char *p = s;
+
+    while (*s != '\0') {
+            if (*s != '\n')
+                    *p++ = *s++;
+            else
+                    ++s;
+    }
+    *p = '\0';
+}

This function can remove a newline from the middle of a string. Are you sure that's what you want?

Yes, we want a strip all newline in the string, when print with

Quoted 3 lines

Is it useful to strip newline characters only and to keep other whitespace? Could this function be dropped and can the callers use strim() instead?

We strstrip/strim afterwards to remove the whitespace.

Quoted 24 lines

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 90

Quoted 10 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +9 -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_io_mode *io_mode)
+{

Please introduce a structure for all the output parameters of this function and pass a pointer to that structure to this function. That will make it easier to introduce support for new parameters.

Quoted 9 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +9 -0
+     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;
+
Quoted 8 lines

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 105

Quoted 6 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +6 -0
+     options = kstrdup(buf, GFP_KERNEL);
+     if (!options)
+             return -ENOMEM;
+
+     sep_opt = strstrip(options);
+     strip(sep_opt);

Are you sure that strstrip() does not remove trailing newline characters?

Yes, it only removes the whitespace

Quoted 20 lines
Quoted 20 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +19 -0
+     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;
Quoted 8 lines

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 128

Quoted 4 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +4 -0
+                     }
+                     strlcpy(sessname, p, NAME_MAX);
+                     kfree(p);
+                     break;

Please change sessname from a fixed size buffer into a dynamically allocated buffer. That will remove the need to perform a strlcpy() and will also allow to remove the NAME_MAX checks.

We can change sessname to be dynamically allocated, but I think the the NAME_MAX check
is not conflicting, we don't want to have that long sessname anyway.

Quoted 17 lines
Quoted 6 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +5 -0
+             case IBNBD_OPT_DEV_PATH:
+                     p = match_strdup(args);
+                     if (!p) {
+                             ret = -ENOMEM;
+                             goto out;

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 170

Quoted 10 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +10 -0
+                     }
+                     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;
Quoted 2 lines

Same comment here - please change pathname from a fixed-size array into a dynamically allocated buffer.

Ditto

Quoted 27 lines
Quoted 13 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +12 -0
+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 */

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 261

Quoted 10 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +10 -0
+             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");
+     }
+}

Please remove the superfluous parentheses from around the DEV_STATE_* constants.

Quoted 2 lines

Additionally, using scnprintf() here is overkill. snprintf() should be sufficient.

You're right, will address both.

Quoted 6 lines

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 264

Quoted 3 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +2 -0
+static struct kobj_attribute ibnbd_clt_state_attr =
+     __ATTR(state, 0444, ibnbd_clt_state_show, NULL);

Please use DEVICE_ATTR_RO() instead of __ATTR() for all read-only attributes.

DEVICE_ATTR_RO doesn't fit here, will use __ATTR_RO, thanks

Quoted 23 lines
Quoted 23 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +22 -0
+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 *opt, *options;
+     bool force;
+     int err;
+
+     opt = kstrdup(buf, GFP_KERNEL);
+     if (!opt)
+             return -ENOMEM;
+
+     options = strstrip(opt);
+     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;
Quoted 8 lines

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 342

Quoted 5 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +5 -0
+     } else {
+             ibnbd_err(dev, "unmap_device: Invalid value: %s\n", options);
+             err = -EINVAL;
+             goto out;
+     }

Wasn't sysfs_streq() introduced to avoid having to duplicate and strip the input string?

sysfs_streq is only tolerant for trailing newline. we use strstrip to strip whitespaces, strip for newlines.

Quoted 21 lines
Quoted 21 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +20 -0
+     /*
+      * 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;
Quoted 8 lines

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 369

Quoted 3 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +3 -0
+
+module_put:
+     module_put(THIS_MODULE);

I've never before seen a module_get() / module_put() pair inside a sysfs
callback function. Can this race be fixed by making
ibnbd_destroy_sessions() remove this sysfs attribute before it tries to destroy any sessions?

That's the first thing we do in ibnbd_destroy_sessions already.

Quoted 14 lines

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 491

Quoted 11 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +10 -0
+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_devs_kobj, dev->blk_symlink_name);
+}

I haven't been able to find any other sysfs code that calls module_is_live()? Please elaborate why that check is needed.

The reason might be lost in the dust, I can retest without module_* to see if our tests don't break

Quoted 42 lines
Quoted 26 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +25 -0
+int ibnbd_clt_create_sysfs_files(void)
+{
+     int err;
+
+     ibnbd_dev_class = class_create(THIS_MODULE, "ibnbd-client");
+     if (unlikely(IS_ERR(ibnbd_dev_class)))
+             return PTR_ERR(ibnbd_dev_class);
+
+     ibnbd_dev = device_create(ibnbd_dev_class, NULL,
+                               MKDEV(0, 0), NULL, "ctl");
+     if (unlikely(IS_ERR(ibnbd_dev))) {
+             err = PTR_ERR(ibnbd_dev);
+             goto cls_destroy;
+     }
+     ibnbd_devs_kobj = kobject_create_and_add("devices", &ibnbd_dev->kobj);
+     if (unlikely(!ibnbd_devs_kobj)) {
+             err = -ENOMEM;
+             goto dev_destroy;
+     }
+     err = sysfs_create_group(&ibnbd_dev->kobj, &default_attr_group);
+     if (unlikely(err))
+             goto put_devs_kobj;
+
+     return 0;
+

drivers/block/ibnbd/ibnbd-clt-sysfs.c line 678

Quoted 10 lines
drivers/block/ibnbd/ibnbd-clt-sysfs.c new file +10 -0
+put_devs_kobj:
+     kobject_del(ibnbd_devs_kobj);
+     kobject_put(ibnbd_devs_kobj);
+dev_destroy:
+     device_destroy(ibnbd_dev_class, MKDEV(0, 0));
+cls_destroy:
+     class_destroy(ibnbd_dev_class);
+
+     return err;
+}

I think this is the wrong way to create a device node because this approach will inform udev about device creation before the sysfs group has been created. Please use device_create_with_groups() instead of calling device_create() and sysfs_create_group() separately.

Quoted 1 line

Bart.

I'm not aware of device_create_with_groups, will try it out.

Thanks,
Jinpu

author
#96 lore raw

PATCH v4 19/25 ibnbd: server: private header with server structs and functions

In reply to Jack Wang

From: Roman Pen <[email protected]>

This 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 | 94 +++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)
 create mode 100644 drivers/block/ibnbd/ibnbd-srv.h
drivers/block/ibnbd/ibnbd-srv.h new file +94 -0
new file mode 100644
index 000000000000..6e46c3e97bf4
@@ -0,0 +1,94 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * 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]>
+ *
+ * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
+ * Authors: Roman Penyaev <[email protected]>
+ *          Jack Wang <[email protected]>
+ *          Danil Kipnis <[email protected]>
+ */
+
+#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];
+	enum ibnbd_access_mode		access_mode;
+};
+
+/* 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.17.1
author
#97 lore raw

PATCH v4 20/25 ibnbd: server: main functionality

In reply to Jack Wang

From: Roman Pen <[email protected]>

This 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 | 945 ++++++++++++++++++++++++++++++++
 1 file changed, 945 insertions(+)
 create mode 100644 drivers/block/ibnbd/ibnbd-srv.c
drivers/block/ibnbd/ibnbd-srv.c new file +945 -0
new file mode 100644
index 000000000000..07b4ae49fda2
@@ -0,0 +1,945 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * 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]>
+ *
+ * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
+ * Authors: Roman Penyaev <[email protected]>
+ *          Jack Wang <[email protected]>
+ *          Danil Kipnis <[email protected]>
+ */
+
+#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 dev_search_path."
+		 " When a device is mapped this path is prepended to the"
+		 " device path from the map device operation.  If %SESSNAME%"
+		 " is specified in a path, then device will be searched in a"
+		 " session namespace."
+		 " (default: " DEFAULT_DEV_SEARCH_PATH ")");
+
+static int def_io_mode = IBNBD_BLOCKIO;
+
+static int def_io_mode_set(const char *val, const struct kernel_param *kp)
+{
+	int io_mode, rc;
+
+	rc = kstrtoint(val, 0, &io_mode);
+	if (unlikely(rc))
+		return rc;
+
+	switch (io_mode) {
+	case IBNBD_FILEIO:
+	case IBNBD_BLOCKIO:
+		def_io_mode = io_mode;
+		return 0;
+	default:
+		return -EINVAL;
+	}
+}
+
+static const struct kernel_param_ops def_io_mode_ops = {
+	.set	= def_io_mode_set,
+	.get	= param_get_int,
+};
+module_param_cb(def_io_mode, &def_io_mode_ops, &def_io_mode, 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),
+				  srv_sess->ver < IBNBD_PROTO_VER_MAJOR ||
+				  usrlen < sizeof(*msg) ?
+				  0 : le16_to_cpu(msg->prio), 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_exit(&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);
+
+	err = bioset_init(&srv_sess->sess_bio_set, srv_sess->queue_depth, 0,
+			  BIOSET_NEED_BVECS);
+	if (err) {
+		pr_err("Allocating srv_session for session %s failed\n",
+		       sessname);
+		kfree(srv_sess);
+		return err;
+	}
+
+	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(le32_to_cpu(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;
+	sdev->access_mode	= open_msg->access_mode;
+
+	return sdev;
+}
+
+static char *ibnbd_srv_get_full_path(struct ibnbd_srv_session *srv_sess,
+				     const char *dev_name)
+{
+	char *full_path;
+	char *a, *b;
+
+	full_path = kmalloc(PATH_MAX, GFP_KERNEL);
+	if (!full_path)
+		return ERR_PTR(-ENOMEM);
+
+	/*
+	 * Replace %SESSNAME% with a real session name in order to
+	 * create device namespace.
+	 */
+	a = strnstr(dev_search_path, "%SESSNAME%", sizeof(dev_search_path));
+	if (a) {
+		int len = a - dev_search_path;
+
+		len = snprintf(full_path, PATH_MAX, "%.*s/%s/%s", len,
+			       dev_search_path, srv_sess->sessname, dev_name);
+		if (len >= PATH_MAX) {
+			pr_err("Tooooo looong path: %s, %s, %s\n",
+			       dev_search_path, srv_sess->sessname, dev_name);
+			kfree(full_path);
+			return ERR_PTR(-EINVAL);
+		}
+	} else {
+		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_PROTO_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_PROTO_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(srv_sess, 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, proto %s\n",
+		KBUILD_MODNAME, IBNBD_VER_STRING, IBNBD_PROTO_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.17.1
#98 lore raw

Re: [PATCH v4 20/25] ibnbd: server: main functionality

drivers/block/ibnbd/ibnbd-srv.c line 24

Quoted 2 lines · Jack Wang
drivers/block/ibnbd/ibnbd-srv.c new file +2 -0
+#undef pr_fmt
+#define pr_fmt(fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt

Same comment here as for a previous patch - please do not include line number information in pr_fmt().

drivers/block/ibnbd/ibnbd-srv.c line 35

Quoted 4 lines
drivers/block/ibnbd/ibnbd-srv.c new file +4 -0
+MODULE_AUTHOR("[email protected]");
+MODULE_VERSION(IBNBD_VER_STRING);
+MODULE_DESCRIPTION("InfiniBand Network Block Device Server");
+MODULE_LICENSE("GPL");

Please remove the version number (MODULE_VERSION()).

Quoted 1 line

+static char dev_search_path[PATH_MAX] = DEFAULT_DEV_SEARCH_PATH;

Please change dev_search_path[] into a dynamically allocated string to avoid a hard-coded length limit.

drivers/block/ibnbd/ibnbd-srv.c line 51

Quoted 2 lines
drivers/block/ibnbd/ibnbd-srv.c new file +2 -0
+	if (dup[strlen(dup) - 1] == '\n')
+		dup[strlen(dup) - 1] = '\0';

Can this be changed into a call to strim()?

drivers/block/ibnbd/ibnbd-srv.c line 144

Quoted 11 lines
drivers/block/ibnbd/ibnbd-srv.c new file +11 -0
+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);
+}

Since ibtrs_srv_resp_rdma() starts an RDMA WRITE without waiting for the write completion, shouldn't the session reference be retained until the completion for that RDMA WRITE has been received? In other words, is there a risk with the current approach that the buffer that is being transferred to the client will be freed before the RDMA WRITE has finished?

Quoted 7 lines
drivers/block/ibnbd/ibnbd-srv.c new file +7 -0
+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);

drivers/block/ibnbd/ibnbd-srv.c line 162

Quoted 10 lines
drivers/block/ibnbd/ibnbd-srv.c new file +10 -0
+	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;
+}

Something that is not important: isn't the sess_dev check superfluous in the if-statement just above the return statement? If ret == 1, does that imply that sess_dev != 0 ?

Has it been considered to return -ENODEV instead of -ENXIO if no device is found?

drivers/block/ibnbd/ibnbd-srv.c line 339

Quoted 4 lines
drivers/block/ibnbd/ibnbd-srv.c new file +3 -0
+static int create_sess(struct ibtrs_srv *ibtrs)
+{
[ ... ]
+	strlcpy(srv_sess->sessname, sessname, sizeof(srv_sess->sessname));

Please change the session name into a dynamically allocated string such that strdup() can be used instead of strlcpy().

drivers/block/ibnbd/ibnbd-srv.c line 398

Quoted 9 lines
drivers/block/ibnbd/ibnbd-srv.c new file +9 -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);

Can the code be reordered such that these forward declarations can be dropped?

Quoted 4 lines
drivers/block/ibnbd/ibnbd-srv.c new file +4 -0
+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,

drivers/block/ibnbd/ibnbd-srv.c line 651

Quoted 10 lines
drivers/block/ibnbd/ibnbd-srv.c new file +10 -0
+			      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));

Can the path name be changed into a dynamically allocated string?

Quoted 20 lines
drivers/block/ibnbd/ibnbd-srv.c new file +20 -0
+static char *ibnbd_srv_get_full_path(struct ibnbd_srv_session *srv_sess,
+				     const char *dev_name)
+{
+	char *full_path;
+	char *a, *b;
+
+	full_path = kmalloc(PATH_MAX, GFP_KERNEL);
+	if (!full_path)
+		return ERR_PTR(-ENOMEM);
+
+	/*
+	 * Replace %SESSNAME% with a real session name in order to
+	 * create device namespace.
+	 */
+	a = strnstr(dev_search_path, "%SESSNAME%", sizeof(dev_search_path));
+	if (a) {
+		int len = a - dev_search_path;
+
+		len = snprintf(full_path, PATH_MAX, "%.*s/%s/%s", len,
+			       dev_search_path, srv_sess->sessname, dev_name);

drivers/block/ibnbd/ibnbd-srv.c line 691

Quoted 10 lines
drivers/block/ibnbd/ibnbd-srv.c new file +10 -0
+		if (len >= PATH_MAX) {
+			pr_err("Tooooo looong path: %s, %s, %s\n",
+			       dev_search_path, srv_sess->sessname, dev_name);
+			kfree(full_path);
+			return ERR_PTR(-EINVAL);
+		}
+	} else {
+		snprintf(full_path, PATH_MAX, "%s/%s",
+			 dev_search_path, dev_name);
+	}

Has it been considered to use kasprintf() instead of kmalloc() + snprintf()?

drivers/block/ibnbd/ibnbd-srv.c line 722

Quoted 12 lines
drivers/block/ibnbd/ibnbd-srv.c new file +12 -0
+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_PROTO_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_PROTO_VER_MAJOR);

Has this patch been verified with checkpatch? I think checkpatch recommends not to split literal strings.

Quoted 10 lines
drivers/block/ibnbd/ibnbd-srv.c new file +10 -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;

drivers/block/ibnbd/ibnbd-srv.c line 749

Quoted 10 lines
drivers/block/ibnbd/ibnbd-srv.c new file +10 -0
+
+	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;
+}

Is explicit the list_empty() check really necessary? Would the behavior of this function change if that check is left out?

Has the posted code been compiled with W=1? I'm asking this because the documentation of the function arguments is missing from the kernel-doc header. I expect that a warning will be reported if this code is compiled with W=1.

Thanks,

Bart.

#99 lore raw

Re: [PATCH v4 20/25] ibnbd: server: main functionality

Quoted 7 lines · Bart Van Assche

drivers/block/ibnbd/ibnbd-srv.c line 24

Quoted 2 lines · Jack Wang
drivers/block/ibnbd/ibnbd-srv.c new file +2 -0
+#undef pr_fmt
+#define pr_fmt(fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt

Same comment here as for a previous patch - please do not include line number information in pr_fmt().

Will drop it, thanks.

Quoted 6 lines

drivers/block/ibnbd/ibnbd-srv.c line 35

Quoted 4 lines
drivers/block/ibnbd/ibnbd-srv.c new file +4 -0
+MODULE_AUTHOR("[email protected]");
+MODULE_VERSION(IBNBD_VER_STRING);
+MODULE_DESCRIPTION("InfiniBand Network Block Device Server");
+MODULE_LICENSE("GPL");

Please remove the version number (MODULE_VERSION()).

OK.

Quoted 4 lines
Quoted 1 line

+static char dev_search_path[PATH_MAX] = DEFAULT_DEV_SEARCH_PATH;

Please change dev_search_path[] into a dynamically allocated string to avoid a hard-coded length limit.

OK.

Quoted 4 lines

drivers/block/ibnbd/ibnbd-srv.c line 51

Quoted 2 lines
drivers/block/ibnbd/ibnbd-srv.c new file +2 -0
+     if (dup[strlen(dup) - 1] == '\n')
+             dup[strlen(dup) - 1] = '\0';

Can this be changed into a call to strim()?

A directory name can start and end with spaces, for example this
works: mkdir " x "

Quoted 9 lines
Quoted 9 lines
drivers/block/ibnbd/ibnbd-srv.c new file +9 -0
+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);
+
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+     kfree(priv);
+}

Since ibtrs_srv_resp_rdma() starts an RDMA WRITE without waiting for the write completion, shouldn't the session reference be retained until the completion for that RDMA WRITE has been received? In other words, is there a risk with the current approach that the buffer that is being transferred to the client will be freed before the RDMA WRITE has finished?

ibtrs-srv.c is keeping track of inflights. When closing session it first marks the queue as closing, so that no new write requests would be posted, when IBNBD calls ibtrs_srv_resp_rdma():
1831 if (ibtrs_srv_change_state_get_old(sess, IBTRS_SRV_CLOSING,
1832 &old_state)
Then ibtrs-srv schedules the ibtrs_srv_close_work, that drains the queue and then waits for all inflights to return from IBNBD:
...
1274 ib_drain_qp(con->c.qp);

1275         }
1276         /* Wait for all inflights */
1277         ibtrs_srv_wait_ops_ids(sess);

....
Only then the resources can be deallocated:
1282 unmap_cont_bufs(sess);
1283 ibtrs_srv_free_ops_ids(sess);

Quoted 14 lines
Quoted 14 lines
drivers/block/ibnbd/ibnbd-srv.c new file +13 -0
+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))
Quoted 8 lines

drivers/block/ibnbd/ibnbd-srv.c line 162

Quoted 4 lines
drivers/block/ibnbd/ibnbd-srv.c new file +4 -0
+             return ERR_PTR(-ENXIO);
+
+     return sess_dev;
+}

Something that is not important: isn't the sess_dev check superfluous in the if-statement just above the return statement? If ret == 1, does that imply that sess_dev != 0 ?

We want to have found the device (sess_dev != NULL) and we want to have been able to take reference to it (ret != 0)... You are right, if ret != 0 then sess_dev can't be NULL.

Quoted 2 lines

Has it been considered to return -ENODEV instead of -ENXIO if no device is found?

The backend block device, i.e. /dev/nullb0, is still there and might even be still exported over other session(s). So we thought "No such device or address" is more appropriate.

Quoted 8 lines

drivers/block/ibnbd/ibnbd-srv.c line 339

Quoted 5 lines
drivers/block/ibnbd/ibnbd-srv.c new file +3 -0
+static int create_sess(struct ibtrs_srv *ibtrs)
+{
[ ... ]
+     strlcpy(srv_sess->sessname, sessname, sizeof(srv_sess->sessname));

Please change the session name into a dynamically allocated string such that strdup() can be used instead of strlcpy().

OK.

Quoted 13 lines

drivers/block/ibnbd/ibnbd-srv.c line 398

Quoted 10 lines
drivers/block/ibnbd/ibnbd-srv.c new file +9 -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);

Can the code be reordered such that these forward declarations can be dropped?

Will try to.

Quoted 17 lines
Quoted 5 lines
drivers/block/ibnbd/ibnbd-srv.c new file +4 -0
+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,

drivers/block/ibnbd/ibnbd-srv.c line 651

Quoted 10 lines
drivers/block/ibnbd/ibnbd-srv.c new file +10 -0
+                           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));

Can the path name be changed into a dynamically allocated string?

Probably we could just do strdup() and free it afterwards...

Quoted 25 lines
Quoted 25 lines
drivers/block/ibnbd/ibnbd-srv.c new file +24 -0
+static char *ibnbd_srv_get_full_path(struct ibnbd_srv_session *srv_sess,
+                                  const char *dev_name)
+{
+     char *full_path;
+     char *a, *b;
+
+     full_path = kmalloc(PATH_MAX, GFP_KERNEL);
+     if (!full_path)
+             return ERR_PTR(-ENOMEM);
+
+     /*
+      * Replace %SESSNAME% with a real session name in order to
+      * create device namespace.
+      */
+     a = strnstr(dev_search_path, "%SESSNAME%", sizeof(dev_search_path));
+     if (a) {
+             int len = a - dev_search_path;
+
+             len = snprintf(full_path, PATH_MAX, "%.*s/%s/%s", len,
+                            dev_search_path, srv_sess->sessname, dev_name);
+             if (len >= PATH_MAX) {
+                     pr_err("Tooooo looong path: %s, %s, %s\n",
+                            dev_search_path, srv_sess->sessname, dev_name);
+                     kfree(full_path);
Quoted 8 lines

drivers/block/ibnbd/ibnbd-srv.c line 691

Quoted 6 lines
drivers/block/ibnbd/ibnbd-srv.c new file +6 -0
+                     return ERR_PTR(-EINVAL);
+             }
+     } else {
+             snprintf(full_path, PATH_MAX, "%s/%s",
+                      dev_search_path, dev_name);
+     }

Has it been considered to use kasprintf() instead of kmalloc() + snprintf()?

I didn't know there is kasprintf()... Looks it would fit here.

Quoted 7 lines
Quoted 7 lines
drivers/block/ibnbd/ibnbd-srv.c new file +7 -0
+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;
Quoted 8 lines

drivers/block/ibnbd/ibnbd-srv.c line 722

Quoted 5 lines
drivers/block/ibnbd/ibnbd-srv.c new file +5 -0
+
+     srv_sess->ver = min_t(u8, sess_info_msg->ver, IBNBD_PROTO_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_PROTO_VER_MAJOR);

Has this patch been verified with checkpatch? I think checkpatch recommends not to split literal strings.

Yes it does complain about our splitted strings. But it's either splitted string or line over 80 chars or "Avoid line continuations in quoted strings" if we use backslash on previous line. I don't know how to avoid all three of them.

Quoted 15 lines
Quoted 15 lines
drivers/block/ibnbd/ibnbd-srv.c new file +15 -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)
Quoted 8 lines

drivers/block/ibnbd/ibnbd-srv.c line 749

Quoted 5 lines
drivers/block/ibnbd/ibnbd-srv.c new file +5 -0
+             if (!strcmp(sess_dev->pathname, dev_name))
+                     return sess_dev;
+
+     return NULL;
+}

Is explicit the list_empty() check really necessary? Would the behavior of this function change if that check is left out?

Will drop the check and fix if necessary if doesn't work without (which I hope it does), thanks.

Quoted 4 lines

Has the posted code been compiled with W=1? I'm asking this because the documentation of the function arguments is missing from the kernel-doc header. I expect that a warning will be reported if this code is compiled with W=1.

Yes it does, I didn't know about W=1. Will fix those warnings, thank you!

Quoted 4 lines

Thanks,

Bart.

#100 lore raw

Re: [PATCH v4 20/25] ibnbd: server: main functionality

Quoted 18 lines · Danil Kipnis
Quoted 16 lines · Bart Van Assche

drivers/block/ibnbd/ibnbd-srv.c line 722

Quoted 12 lines · Jack Wang
drivers/block/ibnbd/ibnbd-srv.c new file +12 -0
+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_PROTO_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_PROTO_VER_MAJOR);

Has this patch been verified with checkpatch? I think checkpatch recommends not to split literal strings.

Quoted 4 lines

Yes it does complain about our splitted strings. But it's either splitted string or line over 80 chars or "Avoid line continuations in quoted strings" if we use backslash on previous line. I don't know how to avoid all three of them.

Checkpatch shouldn't complain about constant strings that exceed 80 columns. If it complains about such strings then that's a checkpatch bug.

Bart.

#101 lore raw

Re: [PATCH v4 20/25] ibnbd: server: main functionality

Quoted 20 lines · Bart Van Assche
Quoted 18 lines · Danil Kipnis
Quoted 16 lines · Bart Van Assche

drivers/block/ibnbd/ibnbd-srv.c line 722

Quoted 12 lines · Jack Wang
drivers/block/ibnbd/ibnbd-srv.c new file +12 -0
+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_PROTO_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_PROTO_VER_MAJOR);

Has this patch been verified with checkpatch? I think checkpatch recommends not to split literal strings.

Quoted 7 lines
Quoted 4 lines

Yes it does complain about our splitted strings. But it's either splitted string or line over 80 chars or "Avoid line continuations in quoted strings" if we use backslash on previous line. I don't know how to avoid all three of them.

Checkpatch shouldn't complain about constant strings that exceed 80 columns. If it complains about such strings then that's a checkpatch bug.

It doesn't in deed... Will concat those splitted quoted string, thank you.

author
#102 lore raw

PATCH v4 21/25 ibnbd: server: functionality for IO submission to file or block dev

In reply to Jack Wang

From: Roman Pen <[email protected]>

This provides helper functions for IO submission to file or block dev.

---
 drivers/block/ibnbd/ibnbd-srv-dev.c | 408 ++++++++++++++++++++++++++++
 drivers/block/ibnbd/ibnbd-srv-dev.h | 143 ++++++++++
 2 files changed, 551 insertions(+)
 create mode 100644 drivers/block/ibnbd/ibnbd-srv-dev.c
 create mode 100644 drivers/block/ibnbd/ibnbd-srv-dev.h
drivers/block/ibnbd/ibnbd-srv-dev.c new file +408 -0
new file mode 100644
index 000000000000..5c1a518638b2
@@ -0,0 +1,408 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * 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]>
+ *
+ * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
+ * Authors: Roman Penyaev <[email protected]>
+ *          Jack Wang <[email protected]>
+ *          Danil Kipnis <[email protected]>
+ */
+
+#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;
+	} else {
+		ret = -EINVAL;
+		goto err;
+	}
+
+	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, short prio,
+				   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_prio(bio, prio);
+	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,
+			short prio, 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, prio, 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 +143 -0

143 lines not on this page · raw message

Signature · 1 line
2.17.1
#103 lore raw

Re: [PATCH v4 21/25] ibnbd: server: functionality for IO submission to file or block dev

drivers/block/ibnbd/ibnbd-srv-dev.c line 24

Quoted 2 lines · Jack Wang
drivers/block/ibnbd/ibnbd-srv-dev.c new file +2 -0
+#undef pr_fmt
+#define pr_fmt(fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt

Same comment as for a previous patch: please do not include line number information in pr_fmt().

Quoted 5 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +5 -0
+static int ibnbd_dev_vfs_open(struct ibnbd_dev *dev, const char *path,
+			      fmode_t flags)
+{
+	int oflags = O_DSYNC; /* enable write-through */
+

drivers/block/ibnbd/ibnbd-srv-dev.c line 94

Quoted 10 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +10 -0
+	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);
+}

Isn't the use of O_DSYNC something that should be configurable?

Quoted 15 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +15 -0
+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)

drivers/block/ibnbd/ibnbd-srv-dev.c line 120

Quoted 10 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +10 -0
+			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;

This looks really weird. Why to call ibnbd_dev_blk_open() first for file I/O mode? Why to set dev->blk_open_flags to FMODE_READ in file I/O mode?

Quoted 29 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +29 -0
+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, short prio,
+				   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;

drivers/block/ibnbd/ibnbd-srv-dev.c line 254

Quoted 10 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +10 -0
+	bio->bi_opf		= ibnbd_to_bio_flags(flags);
+	bio->bi_iter.bi_sector	= sector;
+	bio->bi_iter.bi_size	= bi_size;
+	bio_set_prio(bio, prio);
+	bio_set_dev(bio, dev->bdev);
+
+	submit_bio(bio);
+
+	return 0;
+}

Can struct bio and struct ibnbd_dev_blk_io be combined into a single data structure by passing the size of the latter data structure as the front_pad argument to bioset_init()?

Quoted 75 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +75 -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;

drivers/block/ibnbd/ibnbd-srv-dev.c line 391

Quoted 10 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +10 -0
+	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;
+}

Please use the in-kernel asynchronous I/O API instead of kernel_read() and kernel_write() and remove the fileio_wq workqueue. Examples of how to use call_read_iter() and call_write_iter() are available in the loop driver and also in drivers/target/target_core_file.c.

drivers/block/ibnbd/ibnbd-srv-dev.h line 46

Quoted 6 lines
drivers/block/ibnbd/ibnbd-srv-dev.h new file +6 -0
+/** ibnbd_dev_init() - Initialize ibnbd_dev
+ *
+ * This functions initialized the ibnbd-dev component.
+ * It has to be called 1x time before ibnbd_dev_open() is used
+ */
+int ibnbd_dev_init(void);

It is great so see kernel-doc headers above functions but I'm not sure these should be in .h files. I think most kernel developers prefer to see kernel-doc headers for functions in .c files because that makes it more likely that the implementation and the documentation stay in sync.

Thanks,

Bart.

#104 lore raw

Re: [PATCH v4 21/25] ibnbd: server: functionality for IO submission to file or block dev

Sorry for the slow reply.

Quoted 7 lines · Bart Van Assche

drivers/block/ibnbd/ibnbd-srv-dev.c line 24

Quoted 2 lines · Jack Wang
drivers/block/ibnbd/ibnbd-srv-dev.c new file +2 -0
+#undef pr_fmt
+#define pr_fmt(fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt

Same comment as for a previous patch: please do not include line number information in pr_fmt().

Ok, will be removed.

Quoted 10 lines
Quoted 10 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +9 -0
+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;
Quoted 8 lines

drivers/block/ibnbd/ibnbd-srv-dev.c line 94

Quoted 6 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +6 -0
+     else
+             return -EINVAL;
+
+     dev->file = filp_open(path, oflags, 0);
+     return PTR_ERR_OR_ZERO(dev->file);
+}

Isn't the use of O_DSYNC something that should be configurable?

I know scst allow O_DSYNC to be configured, but in our production, we only use with O_DSYNC,
we sure can add options to allow it to configure it, but we don't
have a need yet.

Quoted 21 lines
Quoted 21 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +20 -0
+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)
Quoted 8 lines

drivers/block/ibnbd/ibnbd-srv-dev.c line 120

Quoted 5 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +5 -0
+                     goto err;
+
+             ret = ibnbd_dev_vfs_open(dev, path, flags);
+             if (ret)
+                     goto blk_put;

This looks really weird. Why to call ibnbd_dev_blk_open() first for file I/O mode? Why to set dev->blk_open_flags to FMODE_READ in file I/O mode?

The reason behind is we want to be able to symlink to the block device. And for File io mode, we only allow exporting block device.

Quoted 36 lines
Quoted 36 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +35 -0
+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, short prio,
+                                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_prio(bio, prio);
+     bio_set_dev(bio, dev->bdev);
+
Quoted 8 lines

drivers/block/ibnbd/ibnbd-srv-dev.c line 254

Quoted 4 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +4 -0
+     submit_bio(bio);
+
+     return 0;
+}

Can struct bio and struct ibnbd_dev_blk_io be combined into a single data structure by passing the size of the latter data structure as the front_pad argument to bioset_init()?

Thanks for the suggestion, will look into it, looks we can embed struct bio to struct ibnbd_dev_blk_io.

Quoted 83 lines
Quoted 83 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +82 -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;
+     }
Quoted 8 lines

drivers/block/ibnbd/ibnbd-srv-dev.c line 60

Quoted 3 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +3 -0
+
+     return 0;
+}

Please use the in-kernel asynchronous I/O API instead of kernel_read() and kernel_write() and remove the fileio_wq workqueue. Examples of how to use call_read_iter() and call_write_iter() are available in the loop driver and also in drivers/target/target_core_file.c.

What the benefits of using call_read_iter/call_write_iter, does it offer better performance?

Quoted 13 lines

drivers/block/ibnbd/ibnbd-srv-dev.h line 46

Quoted 7 lines
drivers/block/ibnbd/ibnbd-srv-dev.h new file +6 -0
+/** ibnbd_dev_init() - Initialize ibnbd_dev
+ *
+ * This functions initialized the ibnbd-dev component.
+ * It has to be called 1x time before ibnbd_dev_open() is used
+ */
+int ibnbd_dev_init(void);

It is great so see kernel-doc headers above functions but I'm not sure these should be in .h files. I think most kernel developers prefer to see kernel-doc headers for functions in .c files because that makes it more likely that the implementation and the documentation stay in sync.

Ok, will move the kernel doc to source code.
I feel for exported functions, it's more common to do it in header files. For this case, I think it's fine to move the kernel-doc to the c file.

Thanks,
Jinpu

#105 lore raw

Re: [PATCH v4 21/25] ibnbd: server: functionality for IO submission to file or block dev

Quoted 7 lines · Jinpu Wang
Quoted 2 lines · Bart Van Assche

On 6/20/19 8:03 AM, Jack Wang wrote:
Isn't the use of O_DSYNC something that should be configurable?

I know scst allow O_DSYNC to be configured, but in our production, we only use with O_DSYNC,
we sure can add options to allow it to configure it, but we don't
have a need yet.

Shouldn't upstream code be general purpose instead of only satisfying the need of a single user?

Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +20 -0
+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)
Quoted 8 lines

drivers/block/ibnbd/ibnbd-srv-dev.c line 120

Quoted 5 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +5 -0
+                     goto err;
+
+             ret = ibnbd_dev_vfs_open(dev, path, flags);
+             if (ret)
+                     goto blk_put;

This looks really weird. Why to call ibnbd_dev_blk_open() first for file I/O mode? Why to set dev->blk_open_flags to FMODE_READ in file I/O mode?

Quoted 2 lines

The reason behind is we want to be able to symlink to the block device. And for File io mode, we only allow exporting block device.

This sounds weird to me ...

Quoted 7 lines
Quoted 4 lines

Please use the in-kernel asynchronous I/O API instead of kernel_read() and kernel_write() and remove the fileio_wq workqueue. Examples of how to use call_read_iter() and call_write_iter() are available in the loop driver and also in drivers/target/target_core_file.c.

What the benefits of using call_read_iter/call_write_iter, does it offer better performance?

The benefits of using in-kernel asynchronous I/O I know of are:
* Better performance due to fewer context switches. For the posted code as many kernel threads will be active as the queue depth. So more context switches will be triggered than necessary.
* Removal the file I/O workqueue and hence a reduction of the number of kernel threads.

Thanks,

Bart.

#106 lore raw

Re: [PATCH v4 21/25] ibnbd: server: functionality for IO submission to file or block dev

Quoted 20 lines · Bart Van Assche
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +20 -0
+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)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/block/ibnbd/ibnbd-srv-dev.c line 120

Quoted 5 lines
drivers/block/ibnbd/ibnbd-srv-dev.c new file +5 -0
+                     goto err;
+
+             ret = ibnbd_dev_vfs_open(dev, path, flags);
+             if (ret)
+                     goto blk_put;

This looks really weird. Why to call ibnbd_dev_blk_open() first for file I/O mode? Why to set dev->blk_open_flags to FMODE_READ in file I/O mode?

Bart, would it in your opinion be OK to drop the file_io support in IBNBD entirely? We implemented this feature in the beginning of the project to see whether it could be beneficial in some use cases, but never actually found any.

#107 lore raw

Re: [PATCH v4 21/25] ibnbd: server: functionality for IO submission to file or block dev

Quoted 8 lines · Danil Kipnis
Quoted 2 lines · Bart Van Assche
Quoted 2 lines
Quoted 2 lines

This looks really weird. Why to call ibnbd_dev_blk_open() first for file I/O mode? Why to set dev->blk_open_flags to FMODE_READ in file I/O mode?

Bart, would it in your opinion be OK to drop the file_io support in IBNBD entirely? We implemented this feature in the beginning of the project to see whether it could be beneficial in some use cases, but never actually found any.

I think that's reasonable since the loop driver can be used to convert a file into a block device.

Bart.

#108 lore raw

Re: [PATCH v4 21/25] ibnbd: server: functionality for IO submission to file or block dev

Quoted 7 lines
Quoted 4 lines

Bart, would it in your opinion be OK to drop the file_io support in IBNBD entirely? We implemented this feature in the beginning of the project to see whether it could be beneficial in some use cases, but never actually found any.

I think that's reasonable since the loop driver can be used to convert a file into a block device.

Jack, shall we drop it?

#109 lore raw

Re: [PATCH v4 21/25] ibnbd: server: functionality for IO submission to file or block dev

Quoted 9 lines · Danil Kipnis
Quoted 8 lines
Quoted 5 lines

Bart, would it in your opinion be OK to drop the file_io support in IBNBD entirely? We implemented this feature in the beginning of the project to see whether it could be beneficial in some use cases, but never actually found any.

I think that's reasonable since the loop driver can be used to convert a file into a block device.

Jack, shall we drop it?

Yes, we should drop it in next round.

author
#110 lore raw

PATCH v4 22/25 ibnbd: server: sysfs interface functions

In reply to Jack Wang

From: Roman Pen <[email protected]>

This is the sysfs interface to IBNBD mapped devices on server side:

/sys/devices/virtual/ibnbd-server/ctl/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 | 270 ++++++++++++++++++++++++++
 1 file changed, 270 insertions(+)
 create mode 100644 drivers/block/ibnbd/ibnbd-srv-sysfs.c
drivers/block/ibnbd/ibnbd-srv-sysfs.c new file +270 -0
new file mode 100644
index 000000000000..2b40514950ed
@@ -0,0 +1,270 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * 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]>
+ *
+ * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
+ * Authors: Roman Penyaev <[email protected]>
+ *          Jack Wang <[email protected]>
+ *          Danil Kipnis <[email protected]>
+ */
+
+#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 <linux/device.h>
+
+#include "ibnbd-srv.h"
+
+static struct device *ibnbd_dev;
+static struct class *ibnbd_dev_class;
+static struct kobject *ibnbd_devs_kobj;
+
+static ssize_t ibnbd_srv_dev_mode_show(struct kobject *kobj,
+				       struct kobj_attribute *attr,
+				       char *page)
+{
+	struct ibnbd_srv_dev *srv_dev;
+
+	srv_dev = container_of(kobj, struct ibnbd_srv_dev, dev_kobj);
+
+	return scnprintf(page, PAGE_SIZE, "%s\n",
+			 ibnbd_io_mode_str(srv_dev->mode));
+}
+
+static struct kobj_attribute ibnbd_srv_dev_mode_attr =
+	__ATTR(io_mode, 0444, ibnbd_srv_dev_mode_show, NULL);
+
+static struct attribute *ibnbd_srv_default_dev_attrs[] = {
+	&ibnbd_srv_dev_mode_attr.attr,
+	NULL,
+};
+
+static struct attribute_group ibnbd_srv_default_dev_attr_group = {
+	.attrs = ibnbd_srv_default_dev_attrs,
+};
+
+static struct kobj_type ktype = {
+	.sysfs_ops	= &kobj_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, &ktype,
+				   ibnbd_devs_kobj, dir_name);
+	if (ret)
+		return ret;
+
+	ret = kobject_init_and_add(&dev->dev_sessions_kobj,
+				   &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_access_mode_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",
+			 ibnbd_access_mode_str(sess_dev->access_mode));
+}
+
+static struct kobj_attribute ibnbd_srv_dev_session_access_mode_attr =
+	__ATTR(access_mode, 0444,
+	       ibnbd_srv_dev_session_access_mode_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_access_mode_attr.attr,
+	&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	= &kobj_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_dev_class = class_create(THIS_MODULE, "ibnbd-server");
+	if (unlikely(IS_ERR(ibnbd_dev_class)))
+		return PTR_ERR(ibnbd_dev_class);
+
+	ibnbd_dev = device_create(ibnbd_dev_class, NULL,
+				  MKDEV(0, 0), NULL, "ctl");
+	if (unlikely(IS_ERR(ibnbd_dev))) {
+		err = PTR_ERR(ibnbd_dev);
+		goto cls_destroy;
+	}
+	ibnbd_devs_kobj = kobject_create_and_add("devices", &ibnbd_dev->kobj);
+	if (unlikely(!ibnbd_devs_kobj)) {
+		err = -ENOMEM;
+		goto dev_destroy;
+	}
+
+	return 0;
+
+dev_destroy:
+	device_destroy(ibnbd_dev_class, MKDEV(0, 0));
+cls_destroy:
+	class_destroy(ibnbd_dev_class);
+
+	return err;
+}
+
+void ibnbd_srv_destroy_sysfs_files(void)
+{
+	kobject_del(ibnbd_devs_kobj);
+	kobject_put(ibnbd_devs_kobj);
+	device_destroy(ibnbd_dev_class, MKDEV(0, 0));
+	class_destroy(ibnbd_dev_class);
+}
Signature · 1 line
2.17.1
author
#111 lore raw

PATCH v4 23/25 ibnbd: include client and server modules into kernel compilation

In reply to Jack Wang

From: Roman Pen <[email protected]>

Add IBNBD Makefile, Kconfig and also corresponding lines into upper block layer files.

---
 drivers/block/Kconfig        |  2 ++
 drivers/block/Makefile       |  1 +
 drivers/block/ibnbd/Kconfig  | 24 ++++++++++++++++++++++++
 drivers/block/ibnbd/Makefile | 13 +++++++++++++
 4 files changed, 40 insertions(+)
 create mode 100644 drivers/block/ibnbd/Kconfig
 create mode 100644 drivers/block/ibnbd/Makefile
drivers/block/Kconfig +2 -0
index 20bb4bfa4be6..9904c030d488 100644
@@ -468,4 +468,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
index a53cc1e3a2d3..bde0b015e07a 100644
@@ -36,6 +36,7 @@ obj-$(CONFIG_BLK_DEV_PCIESSD_MTIP32XX)	+= mtip32xx/
 
 obj-$(CONFIG_BLK_DEV_RSXX) += rsxx/
 obj-$(CONFIG_ZRAM) += zram/
+obj-$(CONFIG_BLK_DEV_IBNBD)	+= ibnbd/
 
 obj-$(CONFIG_BLK_DEV_NULL_BLK)	+= null_blk.o
 null_blk-objs	:= null_blk_main.o
drivers/block/ibnbd/Kconfig new file +24 -0
new file mode 100644
index 000000000000..936a91c8392e
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+config BLK_DEV_IBNBD
+	bool
+
+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
new file mode 100644
index 000000000000..4eb817a16ed2
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+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
Signature · 1 line
2.17.1
author
#112 lore raw

PATCH v4 24/25 ibnbd: a bit of documentation

In reply to Jack Wang

From: Roman Pen <[email protected]>

README with description of major sysfs entries.

---
 drivers/block/ibnbd/README | 315 +++++++++++++++++++++++++++++++++++++
 1 file changed, 315 insertions(+)
 create mode 100644 drivers/block/ibnbd/README
drivers/block/ibnbd/README new file +315 -0
new file mode 100644
index 000000000000..ce9293c290b9
@@ -0,0 +1,315 @@
+***************************************
+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 transferred 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/devices/virtual/ibnbd-client/ctl/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/devices/virtual/ibnbd-client/ctl/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>]
+  > [io_mode=<fileio|blockio>]" > map_device
+  >
+  > addr ::= [ ip:<ipv4> | ip:<ipv6> | gid:<gid> ]
+
+Entries under /sys/devices/virtual/ibnbd-client/ctl/
+=======================================
+
+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>]
+    [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/devices/virtual/ibnbd-client/ctl/devices
+         will be created.
+
+         If 'dev_search_path' contains '%SESSNAME%', then each session can
+         have different devices namespace, e.g. server was configured with
+         the following parameter "dev_search_path=/run/ibnbd-devs/%SESSNAME%",
+         client has this string "sessname=blya device_path=sda", then server
+         will try to open: /run/ibnbd-devs/blya/sda.
+
+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.
+
+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/devices/virtual/ibnbd-client/ctl/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/devices/virtual/ibnbd-client/ctl/devices/<device_id>/dev)
+
+How to find the <device_id> of the device is described on the next
+section.
+
+Entries under /sys/devices/virtual/ibnbd-client/ctl/devices/
+============================================================
+
+For each device mapped on the client a new symbolic link is created as
+/sys/devices/virtual/ibnbd-client/ctl/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.
+
+io_mode (RO)
+------------
+
+Contains the way device is accessed: blockio or fileio
+
+access_mode (RO)
+----------------
+
+Contains the device access mode: ro, rw or migration.
+
+======================
+Server Sysfs Interface
+======================
+
+Entries under /sys/devices/virtual/ibnbd-server/ctl/
+====================================================
+
+When a client maps a device, a directory entry with the name of the
+block device is created under /sys/devices/virtual/ibnbd-server/ctl/devices/.
+
+Entries under /sys/devices/virtual/ibnbd-server/ctl/devices/<device_name>/
+==========================================================================
+
+block_dev (link)
+---------------
+
+Is a symlink to the sysfs entry of the exported device.
+
+Example:
+
+  block_dev -> ../../../../devices/virtual/block/ram0
+
+io_mode (RO)
+-----------
+
+Contains the way device is accessed: blockio or fileio
+
+Entries under /sys/devices/virtual/ibnbd-server/ctl/devices/<device_name>/sessions/
+===================================================================================
+
+For each client a particular device is exported to, following directory will be
+created:
+
+/sys/devices/virtual/ibnbd-server/ctl/devices/<device_name>/sessions/<session-name>/
+
+When the device is unmapped by that client, the directory will be removed.
+
+Entries under /sys/devices/virtual/ibnbd-server/ctl/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.
+
+access_mode (RO)
+-----------------
+
+Contains the device access mode: ro, rw or migration.
+
+
+==============================
+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: "/".
+
+dev_search_path option can also contain %SESSNAME% in order to provide
+different deviec namespaces for different sessions.  See "device_path"
+option for details.
+
+==============================
+Protocol (ibnbd/ibnbd-proto.h)
+==============================
+
+1. Before mapping first device from a given server, client sends an
+IBNBD_MSG_SESS_INFO to the server. Server responds with
+IBNBD_MSG_SESS_INFO_RSP. Currently the messages only contain the protocol
+version for backward compatibility.
+
+2. Client requests to open a device by sending IBNBD_MSG_OPEN message. This
+contains the path to the device, access mode (read-only or writable), and
+io_mode which specifies if the device should be opened as block device or
+using file io. Server responds to the message with IBNBD_MSG_OPEN_RSP. This
+contains a 32 bit device id to be used for  IOs and device "geometry" related
+information: side, max_hw_sectors, etc.
+
+3. Client attaches IBNBD_MSG_IO to each IO message send to a device. This
+message contains device id, provided by server in his ibnbd_msg_open_rsp,
+sector to be accessed, read-write flags and bi_size.
+
+4. Client closes a device by sending IBNBD_MSG_CLOSE which contains only the
+device id provided by the server.
+
Signature · 1 line
2.17.1
#113 lore raw

Re: [PATCH v4 24/25] ibnbd: a bit of documentation

Quoted 3 lines · Jack Wang

From: Roman Pen <[email protected]>

README with description of major sysfs entries.

Please have a look at Documentation/ABI/README and follow the instructions from that document.

Thanks,

Bart.

#114 lore raw

Re: [PATCH v4 24/25] ibnbd: a bit of documentation

Quoted 4 lines · Bart Van Assche
Quoted 2 lines · Jack Wang

From: Roman Pen <[email protected]>

Quoted 8 lines
Quoted 1 line

README with description of major sysfs entries.

Please have a look at Documentation/ABI/README and follow the instructions from that document.

Thanks,

Bart.

Thanks, will move the sysfs description to Documentation/ABI/testing/[sysfs-class-ibnbd-client|sysfs-block-ibnbd], will also move ibtrs sysfs description there.

Regards,
Jinpu

author
#115 lore raw

PATCH v4 25/25 MAINTAINERS: Add maintainer for IBNBD/IBTRS modules

In reply to Jack Wang

From: Roman Pen <[email protected]>

---
 MAINTAINERS | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
MAINTAINERS +14 -0
index a6954776a37e..0b7fd93f738d 100644
@@ -7590,6 +7590,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.17.1
#116 lore raw

Re: [PATCH v4 25/25] MAINTAINERS: Add maintainer for IBNBD/IBTRS modules

Quoted 15 lines · Jack Wang

From: Roman Pen <[email protected]>

---
 MAINTAINERS | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
MAINTAINERS +0 -0
index a6954776a37e..0b7fd93f738d 100644
@@ -7590,6 +7590,20 @@ IBM ServeRAID RAID DRIVER
 S:	Orphan
 F:	drivers/scsi/ips.*

MAINTAINERS IBM ServeRAID RAID DRIVER · line 7601

Quoted 10 lines
MAINTAINERS +9 -0
 
+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]>

I don't know if it rule or not, but can you please add real person/persons to Maintainers list? Many times, those global support lists are simply ignored.

MAINTAINERS IBM ServeRAID RAID DRIVER · line 7604

Quoted 3 lines
MAINTAINERS +3 -0
+L:	[email protected]
+S:	Maintained
+T:	git git://github.com/profitbricks/ibnbd.git

How did you imagine patch flow for ULP, while your tree is external to RDMA tree?

Quoted 8 lines
MAINTAINERS +2 -1
+F:	drivers/infiniband/ulp/ibtrs/
+
 ICH LPC AND GPIO DRIVER
 M:	Peter Tyser <[email protected]>
 S:	Maintained
--

2.17.1

#117 lore raw

Re: [PATCH v4 25/25] MAINTAINERS: Add maintainer for IBNBD/IBTRS modules

Quoted 18 lines · Leon Romanovsky
Quoted 16 lines · Jack Wang

From: Roman Pen <[email protected]>

---
 MAINTAINERS | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
MAINTAINERS +0 -0
index a6954776a37e..0b7fd93f738d 100644
@@ -7590,6 +7590,20 @@ IBM ServeRAID RAID DRIVER
 S:   Orphan
 F:   drivers/scsi/ips.*
 
Quoted 13 lines

MAINTAINERS IBM ServeRAID RAID DRIVER · line 7601

Quoted 9 lines
MAINTAINERS +9 -0
+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]>

I don't know if it rule or not, but can you please add real person/persons to Maintainers list? Many times, those global support lists are simply ignored.

Sure, we can use my and Danil 's name in next round.

Quoted 7 lines

MAINTAINERS IBM ServeRAID RAID DRIVER · line 7604

Quoted 4 lines
MAINTAINERS +3 -0
+L:   [email protected]
+S:   Maintained
+T:   git git://github.com/profitbricks/ibnbd.git

How did you imagine patch flow for ULP, while your tree is external to RDMA tree?

Plan was we gather the patch in the git tree, and
send patches to the list via git send email, do we accept pull request from github?
What the preferred way?

Thanks Leon.
Jack

Quoted 9 lines
Quoted 9 lines
MAINTAINERS +2 -1
+F:   drivers/infiniband/ulp/ibtrs/
+
 ICH LPC AND GPIO DRIVER
 M:   Peter Tyser <[email protected]>
 S:   Maintained
--

2.17.1

#118 lore raw

Re: [PATCH v4 25/25] MAINTAINERS: Add maintainer for IBNBD/IBTRS modules

Quoted 43 lines · Jinpu Wang
Quoted 18 lines · Leon Romanovsky
Quoted 16 lines · Jack Wang

From: Roman Pen <[email protected]>

---
 MAINTAINERS | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
MAINTAINERS +0 -0
index a6954776a37e..0b7fd93f738d 100644
@@ -7590,6 +7590,20 @@ IBM ServeRAID RAID DRIVER
 S:   Orphan
 F:   drivers/scsi/ips.*
 
Quoted 13 lines

MAINTAINERS IBM ServeRAID RAID DRIVER · line 7601

Quoted 9 lines
MAINTAINERS +9 -0
+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]>

I don't know if it rule or not, but can you please add real person/persons to Maintainers list? Many times, those global support lists are simply ignored.

Sure, we can use my and Danil 's name in next round.

Quoted 7 lines

MAINTAINERS IBM ServeRAID RAID DRIVER · line 7604

Quoted 4 lines
MAINTAINERS +3 -0
+L:   [email protected]
+S:   Maintained
+T:   git git://github.com/profitbricks/ibnbd.git

How did you imagine patch flow for ULP, while your tree is external to RDMA tree?

Quoted 4 lines

Plan was we gather the patch in the git tree, and
send patches to the list via git send email, do we accept pull request from github?
What the preferred way?

The preferred way is to start with sending patches directly to the mailing and allow RDMA maintainers to collect and apply them by themselves. It gives an easy way to other people to do cross-subsystem changes and we are doing a lot of them.

Till you will be asked to send PRs the "T:" link should point to RDMA subsystem.

Thanks

Quoted 12 lines

Thanks Leon.
Jack

Quoted 9 lines
Quoted 9 lines
MAINTAINERS +2 -1
+F:   drivers/infiniband/ulp/ibtrs/
+
 ICH LPC AND GPIO DRIVER
 M:   Peter Tyser <[email protected]>
 S:   Maintained
--

2.17.1

#119 lore raw

Re: [PATCH v4 25/25] MAINTAINERS: Add maintainer for IBNBD/IBTRS modules

In reply to Jack Wang
Quoted 23 lines · Jack Wang

From: Roman Pen <[email protected]>

---
  MAINTAINERS | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
MAINTAINERS +7 -0
index a6954776a37e..0b7fd93f738d 100644
@@ -7590,6 +7590,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/
+

MAINTAINERS IBM ServeRAID RAID DRIVER · line 7609

Quoted 10 lines
MAINTAINERS +7 -0
+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

I think the T: entry is for kernel trees against which developers should prepare their patches. Since the ibnbd repository on github is an out-of-tree kernel driver I don't think that it should appear in the MAINTAINERS file.

Bart.

#120 lore raw

Re: [PATCH v4 25/25] MAINTAINERS: Add maintainer for IBNBD/IBTRS modules

Quoted 41 lines · Bart Van Assche
Quoted 23 lines · Jack Wang

From: Roman Pen <[email protected]>

---
  MAINTAINERS | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
MAINTAINERS +7 -0
index a6954776a37e..0b7fd93f738d 100644
@@ -7590,6 +7590,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/
+

MAINTAINERS IBM ServeRAID RAID DRIVER · line 7609

Quoted 10 lines
MAINTAINERS +7 -0
+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

I think the T: entry is for kernel trees against which developers should prepare their patches. Since the ibnbd repository on github is an out-of-tree kernel driver I don't think that it should appear in the MAINTAINERS file.

Quoted 3 lines

Bart.

Ok, we will remove the link to github.

Thanks,
Jinpu

#121 lore raw
In reply to Jack Wang

Hallo Doug, Hallo Jason, Hallo Jens, Hallo Greg,

Could you please provide some feedback to the IBNBD driver and the IBTRS library?
So far we addressed all the requests provided by the community and continue to maintain our code up-to-date with the upstream kernel while having an extra compatibility layer for older kernels in our out-of-tree repository.
I understand that SRP and NVMEoF which are in the kernel already do provide equivalent functionality for the majority of the use cases. IBNBD on the other hand is showing higher performance and more importantly includes the IBTRS - a general purpose library to establish connections and transport BIO-like read/write sg-lists over RDMA, while SRP is targeting SCSI and NVMEoF is addressing NVME. While I believe IBNBD does meet the kernel coding standards, it doesn't have a lot of users, while SRP and NVMEoF are widely accepted. Do you think it would make sense for us to rework our patchset and try pushing it for staging tree first, so that we can proof IBNBD is well maintained, beneficial for the eco-system, find a proper location for it within block/rdma subsystems? This would make it easier for people to try it out and would also be a huge step for us in terms of maintenance effort.
The names IBNBD and IBTRS are in fact misleading. IBTRS sits on top of RDMA and is not bound to IB (We will evaluate IBTRS with ROCE in the near future). Do you think it would make sense to rename the driver to RNBD/RTRS?

Thank you,
Best Regards,
Danil

Quoted 215 lines · Jack Wang

Hi all,

Here is v4 of IBNBD/IBTRS patches, which have minor changes

Changelog
---------
v4:
o Protocol extended to transport IO priorities
o Support for Mellanox ConnectX-4/X-5
o Minor sysfs extentions (display access mode on server side)
o Bug fixes: cleaning up sysfs folders, race on deallocation of resources
o Style fixes

v3:
o Sparse fixes:
- le32 -> le16 conversion
- pcpu and RCU wrong declaration
- sysfs: dynamically alloc array of sockaddr structures to reduce size of a stack frame

o Rename sysfs folder on client and server sides to show source and destination addresses of the connection, i.e.:
.../<session-name>/paths/<src@dst>/

o Remove external inclusions from Makefiles.
* https://lwn.net/Articles/756994/

v2:
o IBNBD:
- No legacy request IO mode, only MQ is left.

o IBTRS:
- No FMR registration, only FR is left.

* https://lwn.net/Articles/755075/

v1:
- IBTRS: 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.

* https://lwn.net/Articles/746342/

v0:
- Initial submission

* https://lwn.net/Articles/718181/

Introduction
-------------

IBTRS (InfiniBand Transport) is a reliable high speed transport library which allows for establishing connection between client and server machines via RDMA. It is based on RDMA-CM, so expect also to support RoCE and iWARP, but we mainly tested in IB environment. It is optimized to transfer (read/write) IO blocks 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, i.e. in IBTRS terminology, an IBTRS path is a set of RDMA CMs and particular path is selected according to the load-balancing policy. It can be used for other components not bind to IBNBD.

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.

- IBNBD/IBTRS is developed in order to map thin provisioned volumes, thus internal protocol is simple.
- 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.
- IBNBD/IBTRS is fast.
Old comparison results:
https://www.spinics.net/lists/linux-rdma/msg48799.html
New comparison results: see performance measurements section below.

Key features of IBTRS transport library and IBNBD block device:

o High throughput and low latency due to:
- Only two RDMA messages per IO.
- IMM InfiniBand messages on responses to reduce round trip latency.
- Simplified memory management: memory allocation happens once on server side when IBTRS session is established.

o IO fail-over and load-balancing by using multipath. According to our test loads additional path brings ~20% of bandwidth.

o Simple configuration of IBNBD:
- Server side is completely passive: volumes do not need to be explicitly exported.
- Only IB port GID and device path needed on client side to map a block device.
- A device is remapped automatically i.e. after storage reboot.

Commits for kernel can be found here:

   https://github.com/ionos-enterprise/ibnbd/tree/linux-5.2-rc3--ibnbd-v4

The out-of-tree modules are here:
https://github.com/ionos-enterprise/ibnbd

Vault 2017 presentation:
https://events.static.linuxfound.org/sites/events/files/slides/IBNBD-Vault-2017.pdf

Performance measurements
------------------------

o IBNBD and NVMEoRDMA

Performance results for the v5.2-rc3 kernel

Roman Pen (25):
sysfs: export sysfs_remove_file_self()
ibtrs: public interface header to establish RDMA connections
ibtrs: private headers with IBTRS protocol structs and helpers
ibtrs: core: lib functions shared between client and server modules
ibtrs: client: private header with client structs and functions
ibtrs: client: main functionality
ibtrs: client: statistics functions
ibtrs: client: sysfs interface functions
ibtrs: server: private header with server structs and functions
ibtrs: server: main functionality
ibtrs: server: statistics functions
ibtrs: server: sysfs interface functions
ibtrs: include client and server modules into kernel compilation
ibtrs: a bit of documentation
ibnbd: private headers with IBNBD protocol structs and helpers
ibnbd: client: private header with client structs and functions
ibnbd: client: main functionality
ibnbd: client: sysfs interface functions
ibnbd: server: private header with server structs and functions
ibnbd: server: main functionality
ibnbd: server: functionality for IO submission to file or block dev
ibnbd: server: sysfs interface functions
ibnbd: include client and server modules into kernel compilation
ibnbd: a bit of documentation
MAINTAINERS: Add maintainer for IBNBD/IBTRS modules

 MAINTAINERS                                   |   14 +
 drivers/block/Kconfig                         |    2 +
 drivers/block/Makefile                        |    1 +
 drivers/block/ibnbd/Kconfig                   |   24 +
 drivers/block/ibnbd/Makefile                  |   13 +
 drivers/block/ibnbd/README                    |  315 ++
 drivers/block/ibnbd/ibnbd-clt-sysfs.c         |  691 ++++
 drivers/block/ibnbd/ibnbd-clt.c               | 1832 +++++++++++
 drivers/block/ibnbd/ibnbd-clt.h               |  166 +
 drivers/block/ibnbd/ibnbd-log.h               |   59 +
 drivers/block/ibnbd/ibnbd-proto.h             |  378 +++
 drivers/block/ibnbd/ibnbd-srv-dev.c           |  408 +++
 drivers/block/ibnbd/ibnbd-srv-dev.h           |  143 +
 drivers/block/ibnbd/ibnbd-srv-sysfs.c         |  270 ++
 drivers/block/ibnbd/ibnbd-srv.c               |  945 ++++++
 drivers/block/ibnbd/ibnbd-srv.h               |   94 +
 drivers/infiniband/Kconfig                    |    1 +
 drivers/infiniband/ulp/Makefile               |    1 +
 drivers/infiniband/ulp/ibtrs/Kconfig          |   22 +
 drivers/infiniband/ulp/ibtrs/Makefile         |   15 +
 drivers/infiniband/ulp/ibtrs/README           |  385 +++
 .../infiniband/ulp/ibtrs/ibtrs-clt-stats.c    |  447 +++
 .../infiniband/ulp/ibtrs/ibtrs-clt-sysfs.c    |  514 +++
 drivers/infiniband/ulp/ibtrs/ibtrs-clt.c      | 2844 +++++++++++++++++
 drivers/infiniband/ulp/ibtrs/ibtrs-clt.h      |  308 ++
 drivers/infiniband/ulp/ibtrs/ibtrs-log.h      |   84 +
 drivers/infiniband/ulp/ibtrs/ibtrs-pri.h      |  463 +++
 .../infiniband/ulp/ibtrs/ibtrs-srv-stats.c    |  103 +
 .../infiniband/ulp/ibtrs/ibtrs-srv-sysfs.c    |  303 ++
 drivers/infiniband/ulp/ibtrs/ibtrs-srv.c      | 1998 ++++++++++++
 drivers/infiniband/ulp/ibtrs/ibtrs-srv.h      |  170 +
 drivers/infiniband/ulp/ibtrs/ibtrs.c          |  610 ++++
 drivers/infiniband/ulp/ibtrs/ibtrs.h          |  318 ++
 fs/sysfs/file.c                               |    1 +
 34 files changed, 13942 insertions(+)
 create mode 100644 drivers/block/ibnbd/Kconfig
 create mode 100644 drivers/block/ibnbd/Makefile
 create mode 100644 drivers/block/ibnbd/README
 create mode 100644 drivers/block/ibnbd/ibnbd-clt-sysfs.c
 create mode 100644 drivers/block/ibnbd/ibnbd-clt.c
 create mode 100644 drivers/block/ibnbd/ibnbd-clt.h
 create mode 100644 drivers/block/ibnbd/ibnbd-log.h
 create mode 100644 drivers/block/ibnbd/ibnbd-proto.h
 create mode 100644 drivers/block/ibnbd/ibnbd-srv-dev.c
 create mode 100644 drivers/block/ibnbd/ibnbd-srv-dev.h
 create mode 100644 drivers/block/ibnbd/ibnbd-srv-sysfs.c
 create mode 100644 drivers/block/ibnbd/ibnbd-srv.c
 create mode 100644 drivers/block/ibnbd/ibnbd-srv.h
 create mode 100644 drivers/infiniband/ulp/ibtrs/Kconfig
 create mode 100644 drivers/infiniband/ulp/ibtrs/Makefile
 create mode 100644 drivers/infiniband/ulp/ibtrs/README
 create mode 100644 drivers/infiniband/ulp/ibtrs/ibtrs-clt-stats.c
 create mode 100644 drivers/infiniband/ulp/ibtrs/ibtrs-clt-sysfs.c
 create mode 100644 drivers/infiniband/ulp/ibtrs/ibtrs-clt.c
 create mode 100644 drivers/infiniband/ulp/ibtrs/ibtrs-clt.h
 create mode 100644 drivers/infiniband/ulp/ibtrs/ibtrs-log.h
 create mode 100644 drivers/infiniband/ulp/ibtrs/ibtrs-pri.h
 create mode 100644 drivers/infiniband/ulp/ibtrs/ibtrs-srv-stats.c
 create mode 100644 drivers/infiniband/ulp/ibtrs/ibtrs-srv-sysfs.c
 create mode 100644 drivers/infiniband/ulp/ibtrs/ibtrs-srv.c
 create mode 100644 drivers/infiniband/ulp/ibtrs/ibtrs-srv.h
 create mode 100644 drivers/infiniband/ulp/ibtrs/ibtrs.c
 create mode 100644 drivers/infiniband/ulp/ibtrs/ibtrs.h

--
2.17.1

#122 lore raw
Quoted 18 lines · Danil Kipnis

Hallo Doug, Hallo Jason, Hallo Jens, Hallo Greg,

Could you please provide some feedback to the IBNBD driver and the IBTRS library?
So far we addressed all the requests provided by the community and continue to maintain our code up-to-date with the upstream kernel while having an extra compatibility layer for older kernels in our out-of-tree repository.
I understand that SRP and NVMEoF which are in the kernel already do provide equivalent functionality for the majority of the use cases. IBNBD on the other hand is showing higher performance and more importantly includes the IBTRS - a general purpose library to establish connections and transport BIO-like read/write sg-lists over RDMA, while SRP is targeting SCSI and NVMEoF is addressing NVME. While I believe IBNBD does meet the kernel coding standards, it doesn't have a lot of users, while SRP and NVMEoF are widely accepted. Do you think it would make sense for us to rework our patchset and try pushing it for staging tree first, so that we can proof IBNBD is well maintained,

Quoted 8 lines

beneficial for the eco-system, find a proper location for it within block/rdma subsystems? This would make it easier for people to try it out and would also be a huge step for us in terms of maintenance effort.
The names IBNBD and IBTRS are in fact misleading. IBTRS sits on top of RDMA and is not bound to IB (We will evaluate IBTRS with ROCE in the near future). Do you think it would make sense to rename the driver to RNBD/RTRS?

It is better to avoid "staging" tree, because it will lack attention of relevant people and your efforts will be lost once you will try to move out of staging. We are all remembering Lustre and don't want to see it again.

Back then, you was asked to provide support for performance superiority. Can you please share any numbers with us?

Thanks

maintainer
#123 lore raw
Quoted 28 lines · Leon Romanovsky
Quoted 18 lines · Danil Kipnis

Hallo Doug, Hallo Jason, Hallo Jens, Hallo Greg,

Could you please provide some feedback to the IBNBD driver and the IBTRS library?
So far we addressed all the requests provided by the community and continue to maintain our code up-to-date with the upstream kernel while having an extra compatibility layer for older kernels in our out-of-tree repository.
I understand that SRP and NVMEoF which are in the kernel already do provide equivalent functionality for the majority of the use cases. IBNBD on the other hand is showing higher performance and more importantly includes the IBTRS - a general purpose library to establish connections and transport BIO-like read/write sg-lists over RDMA, while SRP is targeting SCSI and NVMEoF is addressing NVME. While I believe IBNBD does meet the kernel coding standards, it doesn't have a lot of users, while SRP and NVMEoF are widely accepted. Do you think it would make sense for us to rework our patchset and try pushing it for staging tree first, so that we can proof IBNBD is well maintained,

Quoted 8 lines

beneficial for the eco-system, find a proper location for it within block/rdma subsystems? This would make it easier for people to try it out and would also be a huge step for us in terms of maintenance effort.
The names IBNBD and IBTRS are in fact misleading. IBTRS sits on top of RDMA and is not bound to IB (We will evaluate IBTRS with ROCE in the near future). Do you think it would make sense to rename the driver to RNBD/RTRS?

Quoted 4 lines

It is better to avoid "staging" tree, because it will lack attention of relevant people and your efforts will be lost once you will try to move out of staging. We are all remembering Lustre and don't want to see it again.

That's up to the developers, that had nothing to do with the fact that the code was in the staging tree. If the Lustre developers had actually done the requested work, it would have moved out of the staging tree.

So if these developers are willing to do the work to get something out of staging, and into the "real" part of the kernel, I will gladly take it.

But I will note that it is almost always easier to just do the work ahead of time, and merge it in "correctly" than to go from staging into the real part of the kernel. But it's up to the developers what they want to do.

thanks,

greg k-h

author
#124 lore raw
Quoted 35 lines · Greg KH <[email protected]> 于2019年7月9日周二 下午1:17写道:
Quoted 28 lines · Leon Romanovsky
Quoted 18 lines · Danil Kipnis

Hallo Doug, Hallo Jason, Hallo Jens, Hallo Greg,

Could you please provide some feedback to the IBNBD driver and the IBTRS library?
So far we addressed all the requests provided by the community and continue to maintain our code up-to-date with the upstream kernel while having an extra compatibility layer for older kernels in our out-of-tree repository.
I understand that SRP and NVMEoF which are in the kernel already do provide equivalent functionality for the majority of the use cases. IBNBD on the other hand is showing higher performance and more importantly includes the IBTRS - a general purpose library to establish connections and transport BIO-like read/write sg-lists over RDMA, while SRP is targeting SCSI and NVMEoF is addressing NVME. While I believe IBNBD does meet the kernel coding standards, it doesn't have a lot of users, while SRP and NVMEoF are widely accepted. Do you think it would make sense for us to rework our patchset and try pushing it for staging tree first, so that we can proof IBNBD is well maintained,

Quoted 8 lines

beneficial for the eco-system, find a proper location for it within block/rdma subsystems? This would make it easier for people to try it out and would also be a huge step for us in terms of maintenance effort.
The names IBNBD and IBTRS are in fact misleading. IBTRS sits on top of RDMA and is not bound to IB (We will evaluate IBTRS with ROCE in the near future). Do you think it would make sense to rename the driver to RNBD/RTRS?

Quoted 4 lines

It is better to avoid "staging" tree, because it will lack attention of relevant people and your efforts will be lost once you will try to move out of staging. We are all remembering Lustre and don't want to see it again.

Quoted 7 lines

That's up to the developers, that had nothing to do with the fact that the code was in the staging tree. If the Lustre developers had actually done the requested work, it would have moved out of the staging tree.

So if these developers are willing to do the work to get something out of staging, and into the "real" part of the kernel, I will gladly take it.

Thanks Greg,

This is encouraging, we ARE willing to do the work to get IBNBD/IBTRS merged to upstream kernel. We regularly contribute to stable kernel also upsteam, backport patches, testing
stable rc release etc. We believe in opensource and the power of community.

Sure, we will try to go with so called real kernel, this is also what we are doing
and did in the past, but since v3, we did not receive any real feedback.

We will see how thing will go.

Thanks again!
Jack Wang @ 1 & 1 IONOS Cloud GmbH

Quoted 9 lines

But I will note that it is almost always easier to just do the work ahead of time, and merge it in "correctly" than to go from staging into the real part of the kernel. But it's up to the developers what they want to do.

thanks,

greg k-h

#125 lore raw
In reply to Greg KH
Quoted 34 lines · Greg KH
Quoted 28 lines · Leon Romanovsky
Quoted 18 lines · Danil Kipnis

Hallo Doug, Hallo Jason, Hallo Jens, Hallo Greg,

Could you please provide some feedback to the IBNBD driver and the IBTRS library?
So far we addressed all the requests provided by the community and continue to maintain our code up-to-date with the upstream kernel while having an extra compatibility layer for older kernels in our out-of-tree repository.
I understand that SRP and NVMEoF which are in the kernel already do provide equivalent functionality for the majority of the use cases. IBNBD on the other hand is showing higher performance and more importantly includes the IBTRS - a general purpose library to establish connections and transport BIO-like read/write sg-lists over RDMA, while SRP is targeting SCSI and NVMEoF is addressing NVME. While I believe IBNBD does meet the kernel coding standards, it doesn't have a lot of users, while SRP and NVMEoF are widely accepted. Do you think it would make sense for us to rework our patchset and try pushing it for staging tree first, so that we can proof IBNBD is well maintained,

Quoted 8 lines

beneficial for the eco-system, find a proper location for it within block/rdma subsystems? This would make it easier for people to try it out and would also be a huge step for us in terms of maintenance effort.
The names IBNBD and IBTRS are in fact misleading. IBTRS sits on top of RDMA and is not bound to IB (We will evaluate IBTRS with ROCE in the near future). Do you think it would make sense to rename the driver to RNBD/RTRS?

Quoted 4 lines

It is better to avoid "staging" tree, because it will lack attention of relevant people and your efforts will be lost once you will try to move out of staging. We are all remembering Lustre and don't want to see it again.

Quoted 7 lines

That's up to the developers, that had nothing to do with the fact that the code was in the staging tree. If the Lustre developers had actually done the requested work, it would have moved out of the staging tree.

So if these developers are willing to do the work to get something out of staging, and into the "real" part of the kernel, I will gladly take it.

Greg,

It is not matter of how much *real* work developers will do, but it is a matter of guidance to do *right* thing, which is hard to achieve if people mentioned in the beginning of this thread wouldn't look on staging code.

Quoted 9 lines

But I will note that it is almost always easier to just do the work ahead of time, and merge it in "correctly" than to go from staging into the real part of the kernel. But it's up to the developers what they want to do.

thanks,

greg k-h

#126 lore raw
In reply to Greg KH
Quoted 3 lines · Greg KH

So if these developers are willing to do the work to get something out of staging, and into the "real" part of the kernel, I will gladly take it.

Linus once famously said "given enough eyeballs, all bugs are shallow". There are already two block-over-RDMA driver pairs upstream (NVMeOF and SRP). Accepting the IBTRS and IBNBD drivers upstream would reduce the number of users of the upstream block-over-RDMA drivers and hence would fragment the block-over-RDMA driver user base further. Additionally, I'm not yet convinced that the interesting parts of IBNBD cannot be integrated into the existing upstream drivers. So it's not clear to me whether taking the IBTRS and IBNBD drivers upstream would help the Linux user community.

Bart.

author
#127 lore raw
In reply to Leon Romanovsky
Quoted 29 lines · Leon Romanovsky <[email protected]> 于2019年7月9日周二 下午1:00写道:
Quoted 18 lines · Danil Kipnis

Hallo Doug, Hallo Jason, Hallo Jens, Hallo Greg,

Could you please provide some feedback to the IBNBD driver and the IBTRS library?
So far we addressed all the requests provided by the community and continue to maintain our code up-to-date with the upstream kernel while having an extra compatibility layer for older kernels in our out-of-tree repository.
I understand that SRP and NVMEoF which are in the kernel already do provide equivalent functionality for the majority of the use cases. IBNBD on the other hand is showing higher performance and more importantly includes the IBTRS - a general purpose library to establish connections and transport BIO-like read/write sg-lists over RDMA, while SRP is targeting SCSI and NVMEoF is addressing NVME. While I believe IBNBD does meet the kernel coding standards, it doesn't have a lot of users, while SRP and NVMEoF are widely accepted. Do you think it would make sense for us to rework our patchset and try pushing it for staging tree first, so that we can proof IBNBD is well maintained,

Quoted 8 lines

beneficial for the eco-system, find a proper location for it within block/rdma subsystems? This would make it easier for people to try it out and would also be a huge step for us in terms of maintenance effort.
The names IBNBD and IBTRS are in fact misleading. IBTRS sits on top of RDMA and is not bound to IB (We will evaluate IBTRS with ROCE in the near future). Do you think it would make sense to rename the driver to RNBD/RTRS?

Quoted 7 lines

It is better to avoid "staging" tree, because it will lack attention of relevant people and your efforts will be lost once you will try to move out of staging. We are all remembering Lustre and don't want to see it again.

Back then, you was asked to provide support for performance superiority. Can you please share any numbers with us?

Hi Leon,

Thanks for you feedback.

For performance numbers, Danil did intensive benchmark, and create some PDF with graphes here:
https://github.com/ionos-enterprise/ibnbd/tree/master/performance/v4-v5.2-rc3

It includes both single path results also different multipath policy results.

If you have any question regarding the results, please let us know.

Quoted 2 lines

Thanks

Thanks
Jack Wang

#128 lore raw
Quoted 41 lines · Jinpu Wang
Quoted 29 lines · Leon Romanovsky <[email protected]> 于2019年7月9日周二 下午1:00写道:
Quoted 18 lines · Danil Kipnis

Hallo Doug, Hallo Jason, Hallo Jens, Hallo Greg,

Could you please provide some feedback to the IBNBD driver and the IBTRS library?
So far we addressed all the requests provided by the community and continue to maintain our code up-to-date with the upstream kernel while having an extra compatibility layer for older kernels in our out-of-tree repository.
I understand that SRP and NVMEoF which are in the kernel already do provide equivalent functionality for the majority of the use cases. IBNBD on the other hand is showing higher performance and more importantly includes the IBTRS - a general purpose library to establish connections and transport BIO-like read/write sg-lists over RDMA, while SRP is targeting SCSI and NVMEoF is addressing NVME. While I believe IBNBD does meet the kernel coding standards, it doesn't have a lot of users, while SRP and NVMEoF are widely accepted. Do you think it would make sense for us to rework our patchset and try pushing it for staging tree first, so that we can proof IBNBD is well maintained,

Quoted 8 lines

beneficial for the eco-system, find a proper location for it within block/rdma subsystems? This would make it easier for people to try it out and would also be a huge step for us in terms of maintenance effort.
The names IBNBD and IBTRS are in fact misleading. IBTRS sits on top of RDMA and is not bound to IB (We will evaluate IBTRS with ROCE in the near future). Do you think it would make sense to rename the driver to RNBD/RTRS?

Quoted 7 lines

It is better to avoid "staging" tree, because it will lack attention of relevant people and your efforts will be lost once you will try to move out of staging. We are all remembering Lustre and don't want to see it again.

Back then, you was asked to provide support for performance superiority. Can you please share any numbers with us?

Hi Leon,

Thanks for you feedback.

Quoted 7 lines

For performance numbers, Danil did intensive benchmark, and create some PDF with graphes here:
https://github.com/ionos-enterprise/ibnbd/tree/master/performance/v4-v5.2-rc3

It includes both single path results also different multipath policy results.

If you have any question regarding the results, please let us know.

I kind of recall that last time the perf numbers were skewed toward IBNBD because the invalidation model for MR was wrong - did this get fixed?

Jason

#129 lore raw
Quoted 49 lines · Jason Gunthorpe
Quoted 47 lines · Jinpu Wang
Quoted 29 lines · Leon Romanovsky <[email protected]> 于2019年7月9日周二 下午1:00写道:
Quoted 18 lines · Danil Kipnis

Hallo Doug, Hallo Jason, Hallo Jens, Hallo Greg,

Could you please provide some feedback to the IBNBD driver and the IBTRS library?
So far we addressed all the requests provided by the community and continue to maintain our code up-to-date with the upstream kernel while having an extra compatibility layer for older kernels in our out-of-tree repository.
I understand that SRP and NVMEoF which are in the kernel already do provide equivalent functionality for the majority of the use cases. IBNBD on the other hand is showing higher performance and more importantly includes the IBTRS - a general purpose library to establish connections and transport BIO-like read/write sg-lists over RDMA, while SRP is targeting SCSI and NVMEoF is addressing NVME. While I believe IBNBD does meet the kernel coding standards, it doesn't have a lot of users, while SRP and NVMEoF are widely accepted. Do you think it would make sense for us to rework our patchset and try pushing it for staging tree first, so that we can proof IBNBD is well maintained,

Quoted 8 lines

beneficial for the eco-system, find a proper location for it within block/rdma subsystems? This would make it easier for people to try it out and would also be a huge step for us in terms of maintenance effort.
The names IBNBD and IBTRS are in fact misleading. IBTRS sits on top of RDMA and is not bound to IB (We will evaluate IBTRS with ROCE in the near future). Do you think it would make sense to rename the driver to RNBD/RTRS?

Quoted 7 lines

It is better to avoid "staging" tree, because it will lack attention of relevant people and your efforts will be lost once you will try to move out of staging. We are all remembering Lustre and don't want to see it again.

Back then, you was asked to provide support for performance superiority. Can you please share any numbers with us?

Hi Leon,

Thanks for you feedback.

For performance numbers, Danil did intensive benchmark, and create some PDF with graphes here:
https://github.com/ionos-enterprise/ibnbd/tree/master/performance/v4-v5.2-rc3

It includes both single path results also different multipath policy results.

Quoted 7 lines
Quoted 1 line

If you have any question regarding the results, please let us know.

I kind of recall that last time the perf numbers were skewed toward IBNBD because the invalidation model for MR was wrong - did this get fixed?

Jason

Thanks Jason for feedback.
Can you be more specific about "the invalidation model for MR was wrong"

I checked in the history of the email thread, only found
"I think from the RDMA side, before we accept something like this, I'd like to hear from Christoph, Chuck or Sagi that the dataplane implementation of this is correct, eg it uses the MRs properly and invalidates at the right time, sequences with dma_ops as required, etc.
"
And no reply from any of you since then.

Thanks,
Jack

#130 lore raw
Quoted 52 lines · Jinpu Wang
Quoted 51 lines · Jason Gunthorpe
Quoted 48 lines · Jinpu Wang
Quoted 29 lines · Leon Romanovsky <[email protected]> 于2019年7月9日周二 下午1:00写道:
Quoted 18 lines · Danil Kipnis

Hallo Doug, Hallo Jason, Hallo Jens, Hallo Greg,

Could you please provide some feedback to the IBNBD driver and the IBTRS library?
So far we addressed all the requests provided by the community and continue to maintain our code up-to-date with the upstream kernel while having an extra compatibility layer for older kernels in our out-of-tree repository.
I understand that SRP and NVMEoF which are in the kernel already do provide equivalent functionality for the majority of the use cases. IBNBD on the other hand is showing higher performance and more importantly includes the IBTRS - a general purpose library to establish connections and transport BIO-like read/write sg-lists over RDMA, while SRP is targeting SCSI and NVMEoF is addressing NVME. While I believe IBNBD does meet the kernel coding standards, it doesn't have a lot of users, while SRP and NVMEoF are widely accepted. Do you think it would make sense for us to rework our patchset and try pushing it for staging tree first, so that we can proof IBNBD is well maintained,

Quoted 8 lines

beneficial for the eco-system, find a proper location for it within block/rdma subsystems? This would make it easier for people to try it out and would also be a huge step for us in terms of maintenance effort.
The names IBNBD and IBTRS are in fact misleading. IBTRS sits on top of RDMA and is not bound to IB (We will evaluate IBTRS with ROCE in the near future). Do you think it would make sense to rename the driver to RNBD/RTRS?

Quoted 7 lines

It is better to avoid "staging" tree, because it will lack attention of relevant people and your efforts will be lost once you will try to move out of staging. We are all remembering Lustre and don't want to see it again.

Back then, you was asked to provide support for performance superiority. Can you please share any numbers with us?

Hi Leon,

Thanks for you feedback.

For performance numbers, Danil did intensive benchmark, and create some PDF with graphes here:
https://github.com/ionos-enterprise/ibnbd/tree/master/performance/v4-v5.2-rc3

It includes both single path results also different multipath policy results.

If you have any question regarding the results, please let us know.

Quoted 8 lines
Quoted 5 lines

I kind of recall that last time the perf numbers were skewed toward IBNBD because the invalidation model for MR was wrong - did this get fixed?

Jason

Thanks Jason for feedback.
Can you be more specific about "the invalidation model for MR was wrong"

MR's must be invalidated before data is handed over to the block layer. It can't leave MRs open for access and then touch the memory the MR covers.

IMHO this is the most likely explanation for any performance difference from nvme..

Quoted 8 lines

I checked in the history of the email thread, only found
"I think from the RDMA side, before we accept something like this, I'd like to hear from Christoph, Chuck or Sagi that the dataplane implementation of this is correct, eg it uses the MRs properly and invalidates at the right time, sequences with dma_ops as required, etc.
"
And no reply from any of you since then.

This task still needs to happen..

Jason

#131 lore raw
Quoted 79 lines · Jason Gunthorpe
Quoted 52 lines · Jinpu Wang
Quoted 51 lines · Jason Gunthorpe
Quoted 48 lines · Jinpu Wang
Quoted 29 lines · Leon Romanovsky <[email protected]> 于2019年7月9日周二 下午1:00写道:
Quoted 18 lines · Danil Kipnis

Hallo Doug, Hallo Jason, Hallo Jens, Hallo Greg,

Could you please provide some feedback to the IBNBD driver and the IBTRS library?
So far we addressed all the requests provided by the community and continue to maintain our code up-to-date with the upstream kernel while having an extra compatibility layer for older kernels in our out-of-tree repository.
I understand that SRP and NVMEoF which are in the kernel already do provide equivalent functionality for the majority of the use cases. IBNBD on the other hand is showing higher performance and more importantly includes the IBTRS - a general purpose library to establish connections and transport BIO-like read/write sg-lists over RDMA, while SRP is targeting SCSI and NVMEoF is addressing NVME. While I believe IBNBD does meet the kernel coding standards, it doesn't have a lot of users, while SRP and NVMEoF are widely accepted. Do you think it would make sense for us to rework our patchset and try pushing it for staging tree first, so that we can proof IBNBD is well maintained,

Quoted 8 lines

beneficial for the eco-system, find a proper location for it within block/rdma subsystems? This would make it easier for people to try it out and would also be a huge step for us in terms of maintenance effort.
The names IBNBD and IBTRS are in fact misleading. IBTRS sits on top of RDMA and is not bound to IB (We will evaluate IBTRS with ROCE in the near future). Do you think it would make sense to rename the driver to RNBD/RTRS?

Quoted 7 lines

It is better to avoid "staging" tree, because it will lack attention of relevant people and your efforts will be lost once you will try to move out of staging. We are all remembering Lustre and don't want to see it again.

Back then, you was asked to provide support for performance superiority. Can you please share any numbers with us?

Hi Leon,

Thanks for you feedback.

For performance numbers, Danil did intensive benchmark, and create some PDF with graphes here:
https://github.com/ionos-enterprise/ibnbd/tree/master/performance/v4-v5.2-rc3

It includes both single path results also different multipath policy results.

If you have any question regarding the results, please let us know.

Quoted 8 lines
Quoted 5 lines

I kind of recall that last time the perf numbers were skewed toward IBNBD because the invalidation model for MR was wrong - did this get fixed?

Jason

Thanks Jason for feedback.
Can you be more specific about "the invalidation model for MR was wrong"

MR's must be invalidated before data is handed over to the block layer. It can't leave MRs open for access and then touch the memory the MR covers.

IMHO this is the most likely explanation for any performance difference from nvme..

Quoted 8 lines

I checked in the history of the email thread, only found
"I think from the RDMA side, before we accept something like this, I'd like to hear from Christoph, Chuck or Sagi that the dataplane implementation of this is correct, eg it uses the MRs properly and invalidates at the right time, sequences with dma_ops as required, etc.
"
And no reply from any of you since then.

Quoted 3 lines

This task still needs to happen..

Jason

We did extensive testing and cross-checked how iser and nvmeof does invalidation of MR,
doesn't find a problem.

+ Chuck
It will be appreciated if Christoph, Chuck, Sagi or Bart could give a check, thank you in advance.

Thanks
Jack

#132 lore raw
In reply to Jason Gunthorpe
Quoted 7 lines
Quoted 3 lines

Thanks Jason for feedback.
Can you be more specific about "the invalidation model for MR was wrong"

MR's must be invalidated before data is handed over to the block layer. It can't leave MRs open for access and then touch the memory the MR covers.

Jason is referring to these fixes:
2f122e4f5107 ("nvme-rdma: wait for local invalidation before completing a request") 4af7f7ff92a4 ("nvme-rdma: don't complete requests before a send work request has completed") b4b591c87f2b ("nvme-rdma: don't suppress send completions")

#133 lore raw

Hi Sagi,

thanks a lot for the information. We are doing the right thing regarding the invalidation (your 2f122e4f5107), but we do use unsignalled sends and need to fix that. Please correct me if I'm
wrong: The patches (b4b591c87f2b, b4b591c87f2b) fix the problem that if the ack from target is lost for some reason, the initiators HCA will resend it even after the request is completed.
But doesn't the same problem persist also other way around: for the lost acks from client? I mean, target is did a send for the "read" IOs; client completed the request (after invalidation, refcount dropped to 0, etc), but the ack is not delivered to the HCA of the target, so the target will also resend it. This seems unfixable, since the client can't possible know if the server received his ack or not? Doesn't the problem go away, if rdma_conn_param.retry_count is just set to 0?

Thanks for your help,
Best,
Danil.

Quoted 15 lines · Sagi Grimberg
Quoted 8 lines
Quoted 4 lines

Thanks Jason for feedback.
Can you be more specific about "the invalidation model for MR was wrong"

MR's must be invalidated before data is handed over to the block layer. It can't leave MRs open for access and then touch the memory the MR covers.

Jason is referring to these fixes:
2f122e4f5107 ("nvme-rdma: wait for local invalidation before completing a request")
4af7f7ff92a4 ("nvme-rdma: don't complete requests before a send work request has completed")
b4b591c87f2b ("nvme-rdma: don't suppress send completions")

#134 lore raw
In reply to Leon Romanovsky

Hi Leon,

thanks for the feedback!

Quoted 29 lines · Leon Romanovsky
Quoted 18 lines · Danil Kipnis

Hallo Doug, Hallo Jason, Hallo Jens, Hallo Greg,

Could you please provide some feedback to the IBNBD driver and the IBTRS library?
So far we addressed all the requests provided by the community and continue to maintain our code up-to-date with the upstream kernel while having an extra compatibility layer for older kernels in our out-of-tree repository.
I understand that SRP and NVMEoF which are in the kernel already do provide equivalent functionality for the majority of the use cases. IBNBD on the other hand is showing higher performance and more importantly includes the IBTRS - a general purpose library to establish connections and transport BIO-like read/write sg-lists over RDMA, while SRP is targeting SCSI and NVMEoF is addressing NVME. While I believe IBNBD does meet the kernel coding standards, it doesn't have a lot of users, while SRP and NVMEoF are widely accepted. Do you think it would make sense for us to rework our patchset and try pushing it for staging tree first, so that we can proof IBNBD is well maintained,

Quoted 8 lines

beneficial for the eco-system, find a proper location for it within block/rdma subsystems? This would make it easier for people to try it out and would also be a huge step for us in terms of maintenance effort.
The names IBNBD and IBTRS are in fact misleading. IBTRS sits on top of RDMA and is not bound to IB (We will evaluate IBTRS with ROCE in the near future). Do you think it would make sense to rename the driver to RNBD/RTRS?

Quoted 6 lines

It is better to avoid "staging" tree, because it will lack attention of relevant people and your efforts will be lost once you will try to move out of staging. We are all remembering Lustre and don't want to see it again.

Back then, you was asked to provide support for performance superiority.

I have only theories of why ibnbd is showing better numbers than nvmeof:
1. The way we utilize the MQ framework in IBNBD. We promise to have queue_depth (say 512) requests on each of the num_cpus hardware queues of each device, but in fact we have only queue_depth for the whole "session" toward a given server. The moment we have queue_depth inflights we need stop the queue (on a device on a cpu) we get more requests on. We need to start them again after some requests are completed. We maintain per cpu lists of stopped HW queues, a bitmap showing which lists are not empty, etc. to wake them up in a round-robin fashion to avoid starvation of any devices.
2. We only do rdma writes with imm. A server reserves queue_depth of max_io_size buffers for a given client. The client manages those himself. Client uses imm field to tell to the server which buffer has been written (and where) and server uses the imm field to send back errno. If our max_io_size is 64K and queue_depth 512 and client only issues 4K IOs all the time, then 60*512K memory is wasted. On the other hand we do no buffer allocation/registration in io path on server side. Server sends rdma addresses and keys to those preregistered buffers on connection establishment and deallocates/unregisters them when a session is closed. That's for writes. For reads, client registers user buffers (after fr) and sends the addresses and keys to the server (with an rdma write with imm). Server rdma writes into those buffers. Client does the unregistering/invalidation and completes the request.

Quoted 1 line

Can you please share any numbers with us?

Apart from github
(https://github.com/ionos-enterprise/ibnbd/tree/master/performance/v4-v5.2-rc3)
the performance results for v5.2-rc3 on two different systems can be accessed under dcd.ionos.com/ibnbd-performance-report. The page allows to filter out test scenarios interesting for comparison.

Quoted 2 lines

Thanks

#135 lore raw
In reply to Danil Kipnis
Quoted 4 lines · Danil Kipnis

Hallo Doug, Hallo Jason, Hallo Jens, Hallo Greg,

Could you please provide some feedback to the IBNBD driver and the IBTRS library?

From my perspective you need to get people from the block community to go over this.

It is the merge window right now so nobody is really looking at patches, you may need to resend it after rc1 to get attention.

Jason

#136 lore raw
In reply to Danil Kipnis

Hi Danil and Jack,

Quoted 5 lines

Hallo Doug, Hallo Jason, Hallo Jens, Hallo Greg,

Could you please provide some feedback to the IBNBD driver and the IBTRS library?
So far we addressed all the requests provided by the community

That is not exactly correct AFAIR,

My main issues which were raised before are:
- IMO there isn't any justification to this ibtrs layering separation given that the only user of this is your ibnbd. Unless you are trying to submit another consumer, you should avoid adding another subsystem that is not really general purpose.

- ibtrs in general is using almost no infrastructure from the existing kernel subsystems. Examples are:
- tag allocation mechanism (which I'm not clear why its needed)
- rdma rw abstraction similar to what we have in the core
- list_next_or_null_rr_rcu ??
- few other examples sprinkled around..

Another question, from what I understand from the code, the client always rdma_writes data on writes (with imm) from a remote pool of server buffers dedicated to it. Essentially all writes are immediate (no rdma reads ever). How is that different than using send wrs to a set of pre-posted recv buffers (like all others are doing)? Is it faster?

Also, given that the server pre-allocate a substantial amount of memory for each connection, is it documented the requirements from the server side? Usually kernel implementations (especially upstream ones) will avoid imposing such large longstanding memory requirements on the system by default. I don't have a firm stand on this, but wanted to highlight this as you are sending this for upstream inclusion.

and

Quoted 3 lines

continue to maintain our code up-to-date with the upstream kernel while having an extra compatibility layer for older kernels in our out-of-tree repository.

Overall, while I absolutely support your cause to lower your maintenance overhead by having this sit upstream, I don't see why this can be helpful to anyone else in the rdma community. If instead you can crystallize why/how ibnbd is faster than anything else, and perhaps contribute a common infrastructure piece (or enhance an existing one) such that other existing ulps can leverage, it will be a lot more compelling to include it upstream.

Quoted 6 lines

I understand that SRP and NVMEoF which are in the kernel already do provide equivalent functionality for the majority of the use cases. IBNBD on the other hand is showing higher performance and more importantly includes the IBTRS - a general purpose library to establish connections and transport BIO-like read/write sg-lists over RDMA,

But who needs it? Can other ulps use it or pieces of it? I keep failing to understand why is this a benefit if its specific to your ibnbd?

#137 lore raw
Quoted 5 lines · Sagi Grimberg

Another question, from what I understand from the code, the client always rdma_writes data on writes (with imm) from a remote pool of server buffers dedicated to it. Essentially all writes are immediate (no rdma reads ever). How is that different than using send wrs to a set of pre-posted recv buffers (like all others are doing)? Is it faster?

RDMA WRITE only is generally a bit faster, and if you use a buffer pool in a smart way it is possible to get very good data packing. With SEND the number of recvq entries dictates how big the rx buffer can be, or you waste even more memory by using partial send buffers..

A scheme like this seems like a high performance idea, but on the other side, I have no idea how you could possibly manage invalidations efficiently with a shared RX buffer pool...

The RXer has to push out an invalidation for the shared buffer pool MR, but we don't have protocols for partial MR invalidation.

Which is back to my earlier thought that the main reason this perfoms better is because it doesn't have synchronous MR invalidation.

Maybe this is fine, but it needs to be made very clear that it uses this insecure operating model to get higher performance..

Jason

#138 lore raw
Quoted 9 lines
Quoted 6 lines

Another question, from what I understand from the code, the client always rdma_writes data on writes (with imm) from a remote pool of server buffers dedicated to it. Essentially all writes are immediate (no rdma reads ever). How is that different than using send wrs to a set of pre-posted recv buffers (like all others are doing)? Is it faster?

RDMA WRITE only is generally a bit faster, and if you use a buffer pool in a smart way it is possible to get very good data packing.

There is no packing, its used exactly as send/recv, but with a remote buffer pool (pool of 512K buffers) and the client selects one and rdma write with imm to it.

Quoted 3 lines

With
SEND the number of recvq entries dictates how big the rx buffer can be, or you waste even more memory by using partial send buffers..

This is exactly how it used here.

Quoted 3 lines

A scheme like this seems like a high performance idea, but on the other side, I have no idea how you could possibly manage invalidations efficiently with a shared RX buffer pool...

There are no invalidations, this remote server pool is registered once and long lived with the session.

Quoted 5 lines

The RXer has to push out an invalidation for the shared buffer pool MR, but we don't have protocols for partial MR invalidation.

Which is back to my earlier thought that the main reason this perfoms better is because it doesn't have synchronous MR invalidation.

This issue only exists on the client side. The server never invalidates any of its buffers.

Quoted 2 lines

Maybe this is fine, but it needs to be made very clear that it uses this insecure operating model to get higher performance..

I still do not understand why this should give any notice-able performance advantage.

#139 lore raw
Quoted 7 lines · Sagi Grimberg
Quoted 7 lines
Quoted 6 lines

Another question, from what I understand from the code, the client always rdma_writes data on writes (with imm) from a remote pool of server buffers dedicated to it. Essentially all writes are immediate (no rdma reads ever). How is that different than using send wrs to a set of pre-posted recv buffers (like all others are doing)? Is it faster?

Quoted 6 lines
Quoted 2 lines

RDMA WRITE only is generally a bit faster, and if you use a buffer pool in a smart way it is possible to get very good data packing.

There is no packing, its used exactly as send/recv, but with a remote buffer pool (pool of 512K buffers) and the client selects one and rdma write with imm to it.

Well that makes little sense then:)

Quoted 5 lines
Quoted 2 lines

Maybe this is fine, but it needs to be made very clear that it uses this insecure operating model to get higher performance..

I still do not understand why this should give any notice-able performance advantage.

Usually omitting invalidations gives a healthy bump.

Also, RDMA WRITE is generally faster than READ at the HW level in various ways.

Jason

#140 lore raw
Quoted 8 lines
Quoted 3 lines

I still do not understand why this should give any notice-able performance advantage.

Usually omitting invalidations gives a healthy bump.

Also, RDMA WRITE is generally faster than READ at the HW level in various ways.

Yes, but this should be essentially identical to running nvme-rdma with 512KB of immediate-data (the nvme term is in-capsule data).

In the upstream nvme target we have inline_data_size port attribute that is tunable for that (defaults to PAGE_SIZE).

#141 lore raw

Hi Sagi,

thanks a lot for the analysis. I didn't know about about the inline_data_size parameter in nvmet. It is at PAGE_SIZE on our systems.
Will rerun our benchmarks with
echo 2097152 > /sys/kernel/config/nvmet/ports/1/param_inline_data_size echo 2097152 > /sys/kernel/config/nvmet/ports/2/param_inline_data_size before enabling the port.
Best
Danil.

Quoted 15 lines · Sagi Grimberg
Quoted 9 lines
Quoted 4 lines

I still do not understand why this should give any notice-able performance advantage.

Usually omitting invalidations gives a healthy bump.

Also, RDMA WRITE is generally faster than READ at the HW level in various ways.

Yes, but this should be essentially identical to running nvme-rdma with 512KB of immediate-data (the nvme term is in-capsule data).

In the upstream nvme target we have inline_data_size port attribute that is tunable for that (defaults to PAGE_SIZE).

Signature · 18 lines
Danil Kipnis
Linux Kernel Developer

1&1 IONOS Cloud GmbH | Greifswalder Str. 207 | 10405 Berlin | Germany
E-mail: [email protected] | Web: www.ionos.de


Head Office: Berlin, Germany
District Court Berlin Charlottenburg, Registration number: HRB 125506 B
Executive Management: Christoph Steffens, Matthias Steinberg, Achim Weiss

Member of United Internet

This e-mail may contain confidential and/or privileged information. If
you are not the intended recipient of this e-mail, you are hereby
notified that saving, distribution or use of the content of this
e-mail in any way is prohibited. If you have received this e-mail in
error, please notify the sender and delete the e-mail.
#142 lore raw
In reply to Sagi Grimberg

Hi Sagi,

thanks a lot for the detailed reply. Answers inline below:

Quoted 9 lines · Sagi Grimberg

Hi Danil and Jack,

Quoted 5 lines

Hallo Doug, Hallo Jason, Hallo Jens, Hallo Greg,

Could you please provide some feedback to the IBNBD driver and the IBTRS library?
So far we addressed all the requests provided by the community

Quoted 7 lines

That is not exactly correct AFAIR,

My main issues which were raised before are:
- IMO there isn't any justification to this ibtrs layering separation given that the only user of this is your ibnbd. Unless you are trying to submit another consumer, you should avoid adding another subsystem that is not really general purpose.

We designed ibtrs not only with the IBNBD in mind but also as the transport layer for a distributed SDS. We'd like to be able to do what ceph is capable of (automatic up/down scaling of the storage cluster, automatic recovery) but using in-kernel rdma-based IO transport drivers, thin-provisioned volume managers, etc. to keep the highest possible performance. That modest plan of ours should among others cover for the following:
When using IBNBD/SRP/NVMEoF to export devices (say, thin-provisioned volumes) from server to client and building an (md-)raid on top of the imported devices on client side in order to provide for redundancy across different machines, one gets very decent throughput and low latency, since the IOs are sent in parallel to the storage machines. One downside of this setup, is that the resync traffic has to flow over the client, where the md-raid is sitting. Ideally the resync traffic should flow directly between the two "legs" (storage machines) of the raid. The server side of such a "distributed raid" capable of this direct syncing between the array members would necessarily require to have some logic on server side and hence could also sit on top of ibtrs. (To continue the analogy, the "server" side of an md-raid build on top of say two NVMEoF devices are just two block devices, which couldn't communicate with each other)
All in all itbrs is a library to establish a "fat", multipath, autoreconnectable connection between two hosts on top of rdma, optimized for transport of IO traffic.

Quoted 3 lines

- ibtrs in general is using almost no infrastructure from the existing kernel subsystems. Examples are:
- tag allocation mechanism (which I'm not clear why its needed)

As you correctly noticed our client manages the buffers allocated and registered by the server on the connection establishment. Our tags are just a mechanism to take and release those buffers for incoming requests on client side. Since the buffers allocated by the server are to be shared between all the devices mapped from that server and all their HW queues (each having num_cpus of them) the mechanism behind get_tag/put_tag also takes care of the fairness.

Quoted 1 line

- rdma rw abstraction similar to what we have in the core

On the one hand we have only single IO related function:
ibtrs_clt_request(READ/WRITE, session,...), which executes rdma write with imm, or requests an rdma write with imm to be executed by the server. On the other hand we provide an abstraction to establish and manage what we call "session", which consist of multiple paths (to do failover and multipath with different policies), where each path consists of num_cpu rdma connections. Once you established a session you can add or remove paths from it on the fly. In case the connection to server is lost, the client does periodic attempts to reconnect automatically. On the server side you get just sg-lists with a direction READ or WRITE as requested by the client. We designed this interface not only as the minimum required to build a block device on top of rdma but also with a distributed raid in mind.

Quoted 1 line

- list_next_or_null_rr_rcu ??

We use that for multipath. The macro (and more importantly the way we use it) has been reviewed by Linus and quit closely by Paul E. McKenney. AFAIR the conclusion was that Romans implementation is correct, but too tricky to use correctly in order to be included into kernel as a public interface. See https://lkml.org/lkml/2018/5/18/659

Quoted 1 line

- few other examples sprinkled around..

To my best knowledge we addressed everything we got comments on and will definitely do so in the future.

Quoted 5 lines

Another question, from what I understand from the code, the client always rdma_writes data on writes (with imm) from a remote pool of server buffers dedicated to it. Essentially all writes are immediate (no rdma reads ever). How is that different than using send wrs to a set of pre-posted recv buffers (like all others are doing)? Is it faster?

At the very beginning of the project we did some measurements and saw, that it is faster. I'm not sure if this is still true, since the hardware and the drivers and rdma subsystem did change in that time. Also it seemed to make the code simpler.

Quoted 6 lines

Also, given that the server pre-allocate a substantial amount of memory for each connection, is it documented the requirements from the server side? Usually kernel implementations (especially upstream ones) will avoid imposing such large longstanding memory requirements on the system by default. I don't have a firm stand on this, but wanted to highlight this as you are sending this for upstream inclusion.

We definitely need to stress that somewhere. Will include into readme and add to the cover letter next time. Our memory management is indeed basically absent in favor of performance: The server reserves queue_depth of say 512K buffers. Each buffer is used by client for single IO only, no matter how big the request is. So if client only issues 4K IOs, we do waste 508*queue_depth K of memory. We were aiming for lowest possible latency from the beginning. It is probably possible to implement some clever allocator on the server side which wouldn't affect the performance a lot.

Quoted 21 lines

and

Quoted 3 lines

continue to maintain our code up-to-date with the upstream kernel while having an extra compatibility layer for older kernels in our out-of-tree repository.

Overall, while I absolutely support your cause to lower your maintenance overhead by having this sit upstream, I don't see why this can be helpful to anyone else in the rdma community. If instead you can crystallize why/how ibnbd is faster than anything else, and perhaps contribute a common infrastructure piece (or enhance an existing one) such that other existing ulps can leverage, it will be a lot more compelling to include it upstream.

Quoted 6 lines

I understand that SRP and NVMEoF which are in the kernel already do provide equivalent functionality for the majority of the use cases. IBNBD on the other hand is showing higher performance and more importantly includes the IBTRS - a general purpose library to establish connections and transport BIO-like read/write sg-lists over RDMA,

Quoted 2 lines

But who needs it? Can other ulps use it or pieces of it? I keep failing to understand why is this a benefit if its specific to your ibnbd?

See above and please ask if you have more questions to this.

Thank you,
Danil.

#143 lore raw
Quoted 6 lines
Quoted 6 lines

My main issues which were raised before are:
- IMO there isn't any justification to this ibtrs layering separation given that the only user of this is your ibnbd. Unless you are trying to submit another consumer, you should avoid adding another subsystem that is not really general purpose.

Quoted 6 lines

We designed ibtrs not only with the IBNBD in mind but also as the transport layer for a distributed SDS. We'd like to be able to do what ceph is capable of (automatic up/down scaling of the storage cluster, automatic recovery) but using in-kernel rdma-based IO transport drivers, thin-provisioned volume managers, etc. to keep the highest possible performance.

Sounds lovely, but still very much bound to your ibnbd. And that part is not included in the patch set, so I still don't see why should this be considered as a "generic" transport subsystem (it clearly isn't).

Quoted 3 lines

All in all itbrs is a library to establish a "fat", multipath, autoreconnectable connection between two hosts on top of rdma, optimized for transport of IO traffic.

That is also dictating a wire-protocol which makes it useless to pretty much any other consumer. Personally, I don't see how this library would ever be used outside of your ibnbd.

Quoted 10 lines
Quoted 3 lines

- ibtrs in general is using almost no infrastructure from the existing kernel subsystems. Examples are:
- tag allocation mechanism (which I'm not clear why its needed)

As you correctly noticed our client manages the buffers allocated and registered by the server on the connection establishment. Our tags are just a mechanism to take and release those buffers for incoming requests on client side. Since the buffers allocated by the server are to be shared between all the devices mapped from that server and all their HW queues (each having num_cpus of them) the mechanism behind get_tag/put_tag also takes care of the fairness.

We have infrastructure for this, sbitmaps.

Quoted 5 lines
Quoted 1 line

- rdma rw abstraction similar to what we have in the core

On the one hand we have only single IO related function:
ibtrs_clt_request(READ/WRITE, session,...), which executes rdma write with imm, or requests an rdma write with imm to be executed by the server.

For sure you can enhance the rw API to have imm support?

Quoted 4 lines

On the other hand we provide an abstraction to establish and manage what we call "session", which consist of multiple paths (to do failover and multipath with different policies), where each path consists of num_cpu rdma connections.

That's fine, but it doesn't mean that it also needs to re-write infrastructure that we already have.

Quoted 7 lines

Once you established a session
you can add or remove paths from it on the fly. In case the connection to server is lost, the client does periodic attempts to reconnect automatically. On the server side you get just sg-lists with a direction READ or WRITE as requested by the client. We designed this interface not only as the minimum required to build a block device on top of rdma but also with a distributed raid in mind.

I suggest you take a look at the rw API and use that in your transport.

Quoted 7 lines
Quoted 5 lines

Another question, from what I understand from the code, the client always rdma_writes data on writes (with imm) from a remote pool of server buffers dedicated to it. Essentially all writes are immediate (no rdma reads ever). How is that different than using send wrs to a set of pre-posted recv buffers (like all others are doing)? Is it faster?

At the very beginning of the project we did some measurements and saw, that it is faster. I'm not sure if this is still true

Its not significantly faster (can't imagine why it would be). What could make a difference is probably the fact that you never do rdma reads for I/O writes which might be better. Also perhaps the fact that you normally don't wait for send completions before completing I/O (which is broken), and the fact that you batch recv operations.

I would be interested to understand what indeed makes ibnbd run faster though.

Quoted 6 lines
Quoted 6 lines

Also, given that the server pre-allocate a substantial amount of memory for each connection, is it documented the requirements from the server side? Usually kernel implementations (especially upstream ones) will avoid imposing such large longstanding memory requirements on the system by default. I don't have a firm stand on this, but wanted to highlight this as you are sending this for upstream inclusion.

Quoted 9 lines

We definitely need to stress that somewhere. Will include into readme and add to the cover letter next time. Our memory management is indeed basically absent in favor of performance: The server reserves queue_depth of say 512K buffers. Each buffer is used by client for single IO only, no matter how big the request is. So if client only issues 4K IOs, we do waste 508*queue_depth K of memory. We were aiming for lowest possible latency from the beginning. It is probably possible to implement some clever allocator on the server side which wouldn't affect the performance a lot.

Or you can fallback to rdma_read like the rest of the ulps.

author
#144 lore raw

Hi Sagi,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Another question, from what I understand from the code, the client always rdma_writes data on writes (with imm) from a remote pool of server buffers dedicated to it. Essentially all writes are immediate (no rdma reads ever). How is that different than using send wrs to a set of pre-posted recv buffers (like all others are doing)? Is it faster?

Quoted 8 lines
Quoted 2 lines

At the very beginning of the project we did some measurements and saw, that it is faster. I'm not sure if this is still true

Its not significantly faster (can't imagine why it would be). What could make a difference is probably the fact that you never do rdma reads for I/O writes which might be better. Also perhaps the fact that you normally don't wait for send completions before completing I/O (which is broken), and the fact that you batch recv operations.

I don't know how do you come to the conclusion we don't wait for send completion before completing IO.

We do chain wr on successfull read request from server, see funtion rdma_write_sg,

318 static int rdma_write_sg(struct ibtrs_srv_op *id) 319 {

 320         struct ibtrs_srv_sess *sess = to_srv_sess(id->con->c.sess);
 321         dma_addr_t dma_addr = sess->dma_addr[id->msg_id];
 322         struct ibtrs_srv *srv = sess->srv;
 323         struct ib_send_wr inv_wr, imm_wr;
 324         struct ib_rdma_wr *wr = NULL;

snip
333 need_inval = le16_to_cpu(id->rd_msg->flags) &
IBTRS_MSG_NEED_INVAL_F;
snip

 357                 wr->wr.wr_cqe   = &io_comp_cqe;
 358                 wr->wr.sg_list  = list;
 359                 wr->wr.num_sge  = 1;
 360                 wr->remote_addr = le64_to_cpu(id->rd_msg->desc[i].addr);
 361                 wr->rkey        = le32_to_cpu(id->rd_msg->desc[i].key);

snip
368 if (i < (sg_cnt - 1))
369 wr->wr.next = &id->tx_wr[i + 1].wr;
370 else if (need_inval)
371 wr->wr.next = &inv_wr;
372 else
373 wr->wr.next = &imm_wr;
374

 375                 wr->wr.opcode = IB_WR_RDMA_WRITE;
 376                 wr->wr.ex.imm_data = 0;
 377                 wr->wr.send_flags  = 0;
snip
 386         if (need_inval) {
 387                 inv_wr.next = &imm_wr;
 388                 inv_wr.wr_cqe = &io_comp_cqe;
 389                 inv_wr.sg_list = NULL;
 390                 inv_wr.num_sge = 0;
 391                 inv_wr.opcode = IB_WR_SEND_WITH_INV;
 392                 inv_wr.send_flags = 0;
 393                 inv_wr.ex.invalidate_rkey = rkey;
 394         }
 395         imm_wr.next = NULL;
 396         imm_wr.wr_cqe = &io_comp_cqe;
 397         imm_wr.sg_list = NULL;
 398         imm_wr.num_sge = 0;
 399         imm_wr.opcode = IB_WR_RDMA_WRITE_WITH_IMM;
 400         imm_wr.send_flags = flags;
 401         imm_wr.ex.imm_data = cpu_to_be32(ibtrs_to_io_rsp_imm(id->msg_id,

402 0,
need_inval));
403

when we need to do invalidation of remote memory, there will chain WR togather, last 2 are inv_wr, and imm_wr.
imm_wr is the last one, this is important, due to the fact RC QP are ordered, we know when when we received IB_WC_RECV_RDMA_WITH_IMM and w_inval is true, hardware should already finished it's job to invalidate the MR.
If server fails to invalidate, we will do local invalidation, and wait for completion.

On client side
284 static void complete_rdma_req(struct ibtrs_clt_io_req *req, int errno,
285 bool notify, bool can_wait)
286 {

 287         struct ibtrs_clt_con *con = req->con;
 288         struct ibtrs_clt_sess *sess;
 289         struct ibtrs_clt *clt;
 290         int err;

291
292 if (WARN_ON(!req->in_use))
293 return;
294 if (WARN_ON(!req->con))
295 return;
296 sess = to_clt_sess(con->c.sess);
297 clt = sess->clt;
298
299 if (req->sg_cnt) {
300 if (unlikely(req->dir == DMA_FROM_DEVICE &&
req->need_inv)) {
301 /*

 302                          * We are here to invalidate RDMA read requests
 303                          * ourselves.  In normal scenario server should
 304                          * send INV for all requested RDMA reads, but
 305                          * we are here, thus two things could happen:
 306                          *
 307                          *    1.  this is failover, when errno != 0
 308                          *        and can_wait == 1,
 309                          *
 310                          *    2.  something totally bad happened and
 311                          *        server forgot to send INV, so we
 312                          *        should do that ourselves.
 313                          */

314
315 if (likely(can_wait)) {
316 req->need_inv_comp = true;
317 } else {
318 /* This should be IO path, so
always notify */

 319                                 WARN_ON(!notify);
 320                                 /* Save errno for INV callback */
 321                                 req->inv_errno = errno;

322 }
323
324 err = ibtrs_inv_rkey(req);
325 if (unlikely(err)) {
326 ibtrs_err(sess, "Send INV WR
key=%#x: %d\n",
327 req->mr->rkey, err);
328 } else if (likely(can_wait)) {
329 wait_for_completion(&req->inv_comp);
330 } else {
330 } else {
331 /*

 332                                  * Something went wrong, so request will be
 333                                  * completed from INV callback.
 334                                  */

335 WARN_ON_ONCE(1);
336
337 return;
338 }
339 }
340 ib_dma_unmap_sg(sess->s.dev->ib_dev, req->sglist,
341 req->sg_cnt, req->dir);
342 }
343 if (sess->stats.enable_rdma_lat)
344 ibtrs_clt_update_rdma_lat(&sess->stats,
345 req->dir == DMA_FROM_DEVICE,
346 jiffies_to_msecs(jiffies -
req->start_jiffies));
347 ibtrs_clt_decrease_inflight(&sess->stats);
348
349 req->in_use = false;
350 req->con = NULL;
351
352 if (notify)
353 req->conf(req->priv, errno);
354 }

356 static void process_io_rsp(struct ibtrs_clt_sess *sess, u32
msg_id,
357 s16 errno, bool w_inval)
358 {
359 struct ibtrs_clt_io_req *req;
360
361 if (WARN_ON(msg_id >= sess->queue_depth))
362 return;
363

 364         req = &sess->reqs[msg_id];
 365         /* Drop need_inv if server responsed with invalidation */
 366         req->need_inv &= !w_inval;
 367         complete_rdma_req(req, errno, true, false);

368 }

Hope this clears the doubt.

Regards,
Jack

#145 lore raw
Quoted 17 lines

Hi Sagi,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Another question, from what I understand from the code, the client always rdma_writes data on writes (with imm) from a remote pool of server buffers dedicated to it. Essentially all writes are immediate (no rdma reads ever). How is that different than using send wrs to a set of pre-posted recv buffers (like all others are doing)? Is it faster?

Quoted 8 lines
Quoted 2 lines

At the very beginning of the project we did some measurements and saw, that it is faster. I'm not sure if this is still true

Its not significantly faster (can't imagine why it would be). What could make a difference is probably the fact that you never do rdma reads for I/O writes which might be better. Also perhaps the fact that you normally don't wait for send completions before completing I/O (which is broken), and the fact that you batch recv operations.

Quoted 5 lines

I don't know how do you come to the conclusion we don't wait for send completion before completing IO.

We do chain wr on successfull read request from server, see funtion rdma_write_sg,

I was referring to the client side

author
#146 lore raw
Quoted 18 lines · Sagi Grimberg <[email protected]> 于2019年7月12日周五 下午9:40写道:
Quoted 18 lines

Hi Sagi,

Quoted 13 lines
Quoted 7 lines
Quoted 5 lines

Another question, from what I understand from the code, the client always rdma_writes data on writes (with imm) from a remote pool of server buffers dedicated to it. Essentially all writes are immediate (no rdma reads ever). How is that different than using send wrs to a set of pre-posted recv buffers (like all others are doing)? Is it faster?

At the very beginning of the project we did some measurements and saw, that it is faster. I'm not sure if this is still true

Its not significantly faster (can't imagine why it would be). What could make a difference is probably the fact that you never do rdma reads for I/O writes which might be better. Also perhaps the fact that you normally don't wait for send completions before completing I/O (which is broken), and the fact that you batch recv operations.

Quoted 7 lines
Quoted 5 lines

I don't know how do you come to the conclusion we don't wait for send completion before completing IO.

We do chain wr on successfull read request from server, see funtion rdma_write_sg,

I was referring to the client side

Hi Sagi,

I checked the 3 commits you mentioned in earlier thread again, I now get your point.
You meant the behavior following commits try to fix.

4af7f7ff92a4 ("nvme-rdma: don't complete requests before a send work request has completed")
b4b591c87f2b ("nvme-rdma: don't suppress send completions")

In this sense, ibtrs client side are not waiting for the completions for RDMA WRITE WR to finish.
But we did it right for local invalidation.

I checked SRP/iser, they are not even wait for local invalidation, no signal flag set.

If it's a problem, we should fix them too, maybe more.

My question is do you see the behavior (HCA retry send due to drop ack ) in the field,
is it possible to reproduce?

Thanks,
Jack

#147 lore raw
In reply to Sagi Grimberg
Quoted 14 lines · Sagi Grimberg
Quoted 7 lines
Quoted 7 lines

My main issues which were raised before are:
- IMO there isn't any justification to this ibtrs layering separation given that the only user of this is your ibnbd. Unless you are trying to submit another consumer, you should avoid adding another subsystem that is not really general purpose.

Quoted 6 lines

We designed ibtrs not only with the IBNBD in mind but also as the transport layer for a distributed SDS. We'd like to be able to do what ceph is capable of (automatic up/down scaling of the storage cluster, automatic recovery) but using in-kernel rdma-based IO transport drivers, thin-provisioned volume managers, etc. to keep the highest possible performance.

Quoted 3 lines

Sounds lovely, but still very much bound to your ibnbd. And that part is not included in the patch set, so I still don't see why should this be considered as a "generic" transport subsystem (it clearly isn't).

Having IBTRS sit on a storage enables that storage to communicate with other storages (forward requests, request read from other storages i.e. for sync traffic). IBTRS is generic in the sense that it removes the strict separation into initiator (converting BIOs into some hardware specific protocol messages) and target (which forwards those messages to some local device supporting that protocol).
It appears less generic to me to talk SCSI or NVME between storages if some storages have SCSI, other NVME disks or LVM volumes, or mixed setup. IBTRS allows to just send or request read of an sg-list between machines over rdma - the very minimum required to transport a BIO. It would in-deed support our case with the library if we would propose at least two users of it. We now only have a very early stage prototype capable of organizing storages in pools, multiplexing io between different storages, etc. sitting on top of ibtrs, it's not functional yet. On the other hand ibnbd with ibtrs alone already make over 10000 lines.

Quoted 7 lines
Quoted 3 lines

All in all itbrs is a library to establish a "fat", multipath, autoreconnectable connection between two hosts on top of rdma, optimized for transport of IO traffic.

That is also dictating a wire-protocol which makes it useless to pretty much any other consumer. Personally, I don't see how this library would ever be used outside of your ibnbd.

Its true, IBTRS also imposes a protocol for connection establishment and IO path. I think at least the IO part we did reduce to a bare minimum:
350 * Write *
351
352 1. When processing a write request client selects one of the memory chunks 353 on the server side and rdma writes there the user data, user header and the 354 IBTRS_MSG_RDMA_WRITE message. Apart from the type (write), the message only 355 contains size of the user header. The client tells the server which chunk has
356 been accessed and at what offset the IBTRS_MSG_RDMA_WRITE can be found by 357 using the IMM field.
358
359 2. When confirming a write request server sends an "empty" rdma message with 360 an immediate field. The 32 bit field is used to specify the outstanding 361 inflight IO and for the error code.
362
363 CLT SRV
364 usr_data + usr_hdr + ibtrs_msg_rdma_write -----------------> [IBTRS_IO_REQ_IMM]
365 [IBTRS_IO_RSP_IMM] <----------------- (id + errno)
366
367 * Read *
368
369 1. When processing a read request client selects one of the memory chunks 370 on the server side and rdma writes there the user header and the 371 IBTRS_MSG_RDMA_READ message. This message contains the type (read), size of 372 the user header, flags (specifying if memory invalidation is necessary) and the
373 list of addresses along with keys for the data to be read into. 374
375 2. When confirming a read request server transfers the requested data first, 376 attaches an invalidation message if requested and finally an "empty" rdma 377 message with an immediate field. The 32 bit field is used to specify the 378 outstanding inflight IO and the error code.
379
380 CLT SRV
381 usr_hdr + ibtrs_msg_rdma_read --------------> [IBTRS_IO_REQ_IMM]
382 [IBTRS_IO_RSP_IMM] <-------------- usr_data + (id + errno)
383 or in case client requested invalidation:
384 [IBTRS_IO_RSP_IMM_W_INV] <-------------- usr_data + (INV) +
(id + errno)

Quoted 11 lines
Quoted 10 lines
Quoted 3 lines

- ibtrs in general is using almost no infrastructure from the existing kernel subsystems. Examples are:
- tag allocation mechanism (which I'm not clear why its needed)

As you correctly noticed our client manages the buffers allocated and registered by the server on the connection establishment. Our tags are just a mechanism to take and release those buffers for incoming requests on client side. Since the buffers allocated by the server are to be shared between all the devices mapped from that server and all their HW queues (each having num_cpus of them) the mechanism behind get_tag/put_tag also takes care of the fairness.

Quoted 1 line

We have infrastructure for this, sbitmaps.

AFAIR Roman did try to use sbitmap but found no benefits in terms of readability or number of lines:
" What is left unchanged on IBTRS side but was suggested to modify:
- Bart suggested to use sbitmap instead of calling find_first_zero_bit()
and friends. I found calling pure bit API is more explicit in comparison to sbitmap - there is no need in using sbitmap_queue and all the power of wait queues, no benefits in terms of LoC as well." https://lwn.net/Articles/756994/

If sbitmap is a must for our use case from the infrastructure point of view, we will reiterate on it.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

- rdma rw abstraction similar to what we have in the core

On the one hand we have only single IO related function:
ibtrs_clt_request(READ/WRITE, session,...), which executes rdma write with imm, or requests an rdma write with imm to be executed by the server.

For sure you can enhance the rw API to have imm support?

I'm not familiar with the architectural intention behind rw.c. Extending the API with the support of imm field is (I guess) doable.

Quoted 7 lines
Quoted 4 lines

On the other hand we provide an abstraction to establish and manage what we call "session", which consist of multiple paths (to do failover and multipath with different policies), where each path consists of num_cpu rdma connections.

That's fine, but it doesn't mean that it also needs to re-write infrastructure that we already have.

Do you refer to rw.c?

Quoted 9 lines
Quoted 7 lines

Once you established a session
you can add or remove paths from it on the fly. In case the connection to server is lost, the client does periodic attempts to reconnect automatically. On the server side you get just sg-lists with a direction READ or WRITE as requested by the client. We designed this interface not only as the minimum required to build a block device on top of rdma but also with a distributed raid in mind.

I suggest you take a look at the rw API and use that in your transport.

We will look into rw.c. Do you suggest we move the multipath and the multiple QPs per path and connection establishment on *top* of it or *into* it?

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

Another question, from what I understand from the code, the client always rdma_writes data on writes (with imm) from a remote pool of server buffers dedicated to it. Essentially all writes are immediate (no rdma reads ever). How is that different than using send wrs to a set of pre-posted recv buffers (like all others are doing)? Is it faster?

At the very beginning of the project we did some measurements and saw, that it is faster. I'm not sure if this is still true

Quoted 8 lines

Its not significantly faster (can't imagine why it would be). What could make a difference is probably the fact that you never do rdma reads for I/O writes which might be better. Also perhaps the fact that you normally don't wait for send completions before completing I/O (which is broken), and the fact that you batch recv operations.

I would be interested to understand what indeed makes ibnbd run faster though.

Yes, we would like to understand this too. I will try increasing the inline_data_size on nvme in our benchmarks as the next step to check if this influences the results.

Quoted 16 lines
Quoted 6 lines
Quoted 6 lines

Also, given that the server pre-allocate a substantial amount of memory for each connection, is it documented the requirements from the server side? Usually kernel implementations (especially upstream ones) will avoid imposing such large longstanding memory requirements on the system by default. I don't have a firm stand on this, but wanted to highlight this as you are sending this for upstream inclusion.

Quoted 9 lines

We definitely need to stress that somewhere. Will include into readme and add to the cover letter next time. Our memory management is indeed basically absent in favor of performance: The server reserves queue_depth of say 512K buffers. Each buffer is used by client for single IO only, no matter how big the request is. So if client only issues 4K IOs, we do waste 508*queue_depth K of memory. We were aiming for lowest possible latency from the beginning. It is probably possible to implement some clever allocator on the server side which wouldn't affect the performance a lot.

Quoted 1 line

Or you can fallback to rdma_read like the rest of the ulps.

We currently have a single round trip for every write IO: write + ack. Wouldn't switching to rdma_read make 2 round trips out of it: command
+ rdma_read + ack?