On Sat, Mar 28, 2020 at 5:45 AM Bart Van Assche <bvanassche@xxxxxxx> wrote: > > On 2020-03-20 05:16, Jack Wang wrote: > > +static void rnbd_clt_put_dev(struct rnbd_clt_dev *dev) > > +{ > > + might_sleep(); > > + > > + if (refcount_dec_and_test(&dev->refcount)) { > > + mutex_lock(&ida_lock); > > + ida_simple_remove(&index_ida, dev->clt_device_id); > > + mutex_unlock(&ida_lock); > > + kfree(dev->hw_queues); > > + rnbd_clt_put_sess(dev->sess); > > + mutex_destroy(&dev->lock); > > + kfree(dev); > > + } > > +} > > Please use the coding style that is used elsewhere in the kernel, namely > return early to keep the indentation level low. Ok, will fix the coding style. > > > +enum { > > + RNBD_DELAY_10ms = 10, > > + RNBD_DELAY_IFBUSY = -1, > > +}; > > How about removing the RNBD_DELAY_10ms constant and using 10/*ms*/ instead? Sounds good. > > > +enum { > > + NO_WAIT = 0, > > + WAIT = 1 > > +}; > > + > > +static int send_usr_msg(struct rtrs_clt *rtrs, int dir, > > + struct rnbd_iu *iu, struct kvec *vec, size_t nr, > > + size_t len, struct scatterlist *sg, unsigned int sg_len, > > + void (*conf)(struct work_struct *work), > > + int *errno, bool wait) > > Are the NO_WAIT and WAIT perhaps values that are passed as the last > argument to send_usr_msg()? If so, please use a proper enumeration type > instead of 'bool'. You're right, seems better to just remove the enum, "bool wait" is self-explained. > > > +static int rnbd_client_getgeo(struct block_device *block_device, > > + struct hd_geometry *geo) > > +{ > > + u64 size; > > + struct rnbd_clt_dev *dev; > > + > > + dev = block_device->bd_disk->private_data; > > + size = dev->size * (dev->logical_block_size / SECTOR_SIZE); > > + geo->cylinders = (size & ~0x3f) >> 6; /* size/64 */ > > + geo->heads = 4; > > + geo->sectors = 16; > > + geo->start = 0; > > + > > + return 0; > > +} > > Is the "& ~0x3f" in the above function perhaps superfluous? yes, will remove. > > > +static void rnbd_clt_dev_kick_mq_queue(struct rnbd_clt_dev *dev, > > + struct blk_mq_hw_ctx *hctx, > > + int delay) > > +{ > > + struct rnbd_queue *q = hctx->driver_data; > > + > > + if (delay != RNBD_DELAY_IFBUSY) > > + blk_mq_delay_run_hw_queue(hctx, delay); > > + else if (unlikely(!rnbd_clt_dev_add_to_requeue(dev, q))) > > + /* > > + * If session is not busy we have to restart > > + * the queue ourselves. > > + */ > > + blk_mq_delay_run_hw_queue(hctx, RNBD_DELAY_10ms); > > +} > > I think the above code will be easier to read if RNBD_DELAY_10ms is > changed into 10/*ms*/. ok > > > +static blk_status_t rnbd_queue_rq(struct blk_mq_hw_ctx *hctx, > > + const struct blk_mq_queue_data *bd) > > +{ > > + struct request *rq = bd->rq; > > + struct rnbd_clt_dev *dev = rq->rq_disk->private_data; > > + struct rnbd_iu *iu = blk_mq_rq_to_pdu(rq); > > + int err; > > + > > + if (unlikely(dev->dev_state != DEV_STATE_MAPPED)) > > + return BLK_STS_IOERR; > > + > > + iu->permit = rnbd_get_permit(dev->sess, RTRS_IO_CON, > > + RTRS_PERMIT_NOWAIT); > > + if (unlikely(!iu->permit)) { > > + rnbd_clt_dev_kick_mq_queue(dev, hctx, RNBD_DELAY_IFBUSY); > > + return BLK_STS_RESOURCE; > > + } > > + > > + blk_mq_start_request(rq); > > + err = rnbd_client_xfer_request(dev, rq, iu); > > + if (likely(err == 0)) > > + return BLK_STS_OK; > > + if (unlikely(err == -EAGAIN || err == -ENOMEM)) { > > + rnbd_clt_dev_kick_mq_queue(dev, hctx, RNBD_DELAY_10ms); > > + rnbd_put_permit(dev->sess, iu->permit); > > + return BLK_STS_RESOURCE; > > + } > > + > > + rnbd_put_permit(dev->sess, iu->permit); > > + return BLK_STS_IOERR; > > +} > > Would it be possible to use the .get_budget / .put_budget callbacks for > obtaining / releasing a "permit" object? I'm asking this because it was > really tricky to get the .get_budget / .put_budget calls right in the > block layer core. See also commit 0bca799b9280 ("blk-mq: order getting > budget and driver tag") # v4.17. Will check if we can use .get_budget/put_budget call back. > > Thanks, > > Bart. Thanks Bart