@@ -337,10 +337,7 @@ struct rbd_img_request {
337337 u64 snap_id ; /* for reads */
338338 struct ceph_snap_context * snapc ; /* for writes */
339339 };
340- union {
341- struct request * rq ; /* block request */
342- struct rbd_obj_request * obj_request ; /* obj req initiator */
343- };
340+ struct rbd_obj_request * obj_request ; /* obj req initiator */
344341
345342 struct list_head lock_item ;
346343 struct list_head object_extents ; /* obj_req.ex structs */
@@ -1610,29 +1607,18 @@ static bool rbd_dev_parent_get(struct rbd_device *rbd_dev)
16101607 return counter > 0 ;
16111608}
16121609
1613- /*
1614- * Caller is responsible for filling in the list of object requests
1615- * that comprises the image request, and the Linux request pointer
1616- * (if there is one).
1617- */
1618- static struct rbd_img_request * rbd_img_request_create (
1619- struct rbd_device * rbd_dev ,
1620- enum obj_operation_type op_type )
1610+ static void rbd_img_request_init (struct rbd_img_request * img_request ,
1611+ struct rbd_device * rbd_dev ,
1612+ enum obj_operation_type op_type )
16211613{
1622- struct rbd_img_request * img_request ;
1623-
1624- img_request = kmem_cache_zalloc (rbd_img_request_cache , GFP_NOIO );
1625- if (!img_request )
1626- return NULL ;
1614+ memset (img_request , 0 , sizeof (* img_request ));
16271615
16281616 img_request -> rbd_dev = rbd_dev ;
16291617 img_request -> op_type = op_type ;
16301618
16311619 INIT_LIST_HEAD (& img_request -> lock_item );
16321620 INIT_LIST_HEAD (& img_request -> object_extents );
16331621 mutex_init (& img_request -> state_mutex );
1634-
1635- return img_request ;
16361622}
16371623
16381624static void rbd_img_capture_header (struct rbd_img_request * img_req )
@@ -1667,7 +1653,8 @@ static void rbd_img_request_destroy(struct rbd_img_request *img_request)
16671653 if (rbd_img_is_write (img_request ))
16681654 ceph_put_snap_context (img_request -> snapc );
16691655
1670- kmem_cache_free (rbd_img_request_cache , img_request );
1656+ if (test_bit (IMG_REQ_CHILD , & img_request -> flags ))
1657+ kmem_cache_free (rbd_img_request_cache , img_request );
16711658}
16721659
16731660#define BITS_PER_OBJ 2
@@ -2834,10 +2821,11 @@ static int rbd_obj_read_from_parent(struct rbd_obj_request *obj_req)
28342821 struct rbd_img_request * child_img_req ;
28352822 int ret ;
28362823
2837- child_img_req = rbd_img_request_create ( parent , OBJ_OP_READ );
2824+ child_img_req = kmem_cache_alloc ( rbd_img_request_cache , GFP_NOIO );
28382825 if (!child_img_req )
28392826 return - ENOMEM ;
28402827
2828+ rbd_img_request_init (child_img_req , parent , OBJ_OP_READ );
28412829 __set_bit (IMG_REQ_CHILD , & child_img_req -> flags );
28422830 child_img_req -> obj_request = obj_req ;
28432831
@@ -3638,7 +3626,7 @@ static void rbd_img_handle_request(struct rbd_img_request *img_req, int result)
36383626 goto again ;
36393627 }
36403628 } else {
3641- struct request * rq = img_req -> rq ;
3629+ struct request * rq = blk_mq_rq_from_pdu ( img_req ) ;
36423630
36433631 rbd_img_request_destroy (img_req );
36443632 blk_mq_end_request (rq , errno_to_blk_status (result ));
@@ -4692,68 +4680,25 @@ static int rbd_obj_method_sync(struct rbd_device *rbd_dev,
46924680
46934681static void rbd_queue_workfn (struct work_struct * work )
46944682{
4695- struct request * rq = blk_mq_rq_from_pdu (work );
4696- struct rbd_device * rbd_dev = rq -> q -> queuedata ;
4697- struct rbd_img_request * img_request ;
4683+ struct rbd_img_request * img_request =
4684+ container_of (work , struct rbd_img_request , work );
4685+ struct rbd_device * rbd_dev = img_request -> rbd_dev ;
4686+ enum obj_operation_type op_type = img_request -> op_type ;
4687+ struct request * rq = blk_mq_rq_from_pdu (img_request );
46984688 u64 offset = (u64 )blk_rq_pos (rq ) << SECTOR_SHIFT ;
46994689 u64 length = blk_rq_bytes (rq );
4700- enum obj_operation_type op_type ;
47014690 u64 mapping_size ;
47024691 int result ;
47034692
4704- switch (req_op (rq )) {
4705- case REQ_OP_DISCARD :
4706- op_type = OBJ_OP_DISCARD ;
4707- break ;
4708- case REQ_OP_WRITE_ZEROES :
4709- op_type = OBJ_OP_ZEROOUT ;
4710- break ;
4711- case REQ_OP_WRITE :
4712- op_type = OBJ_OP_WRITE ;
4713- break ;
4714- case REQ_OP_READ :
4715- op_type = OBJ_OP_READ ;
4716- break ;
4717- default :
4718- dout ("%s: non-fs request type %d\n" , __func__ , req_op (rq ));
4719- result = - EIO ;
4720- goto err ;
4721- }
4722-
47234693 /* Ignore/skip any zero-length requests */
4724-
47254694 if (!length ) {
47264695 dout ("%s: zero-length request\n" , __func__ );
47274696 result = 0 ;
4728- goto err_rq ;
4729- }
4730-
4731- if (op_type != OBJ_OP_READ ) {
4732- if (rbd_is_ro (rbd_dev )) {
4733- rbd_warn (rbd_dev , "%s on read-only mapping" ,
4734- obj_op_name (op_type ));
4735- result = - EIO ;
4736- goto err ;
4737- }
4738- rbd_assert (!rbd_is_snap (rbd_dev ));
4739- }
4740-
4741- if (offset && length > U64_MAX - offset + 1 ) {
4742- rbd_warn (rbd_dev , "bad request range (%llu~%llu)" , offset ,
4743- length );
4744- result = - EINVAL ;
4745- goto err_rq ; /* Shouldn't happen */
4697+ goto err_img_request ;
47464698 }
47474699
47484700 blk_mq_start_request (rq );
47494701
4750- img_request = rbd_img_request_create (rbd_dev , op_type );
4751- if (!img_request ) {
4752- result = - ENOMEM ;
4753- goto err_rq ;
4754- }
4755- img_request -> rq = rq ;
4756-
47574702 down_read (& rbd_dev -> header_rwsem );
47584703 mapping_size = rbd_dev -> mapping .size ;
47594704 rbd_img_capture_header (img_request );
@@ -4782,21 +4727,50 @@ static void rbd_queue_workfn(struct work_struct *work)
47824727
47834728err_img_request :
47844729 rbd_img_request_destroy (img_request );
4785- err_rq :
47864730 if (result )
47874731 rbd_warn (rbd_dev , "%s %llx at %llx result %d" ,
47884732 obj_op_name (op_type ), length , offset , result );
4789- err :
47904733 blk_mq_end_request (rq , errno_to_blk_status (result ));
47914734}
47924735
47934736static blk_status_t rbd_queue_rq (struct blk_mq_hw_ctx * hctx ,
47944737 const struct blk_mq_queue_data * bd )
47954738{
4796- struct request * rq = bd -> rq ;
4797- struct work_struct * work = blk_mq_rq_to_pdu (rq );
4739+ struct rbd_device * rbd_dev = hctx -> queue -> queuedata ;
4740+ struct rbd_img_request * img_req = blk_mq_rq_to_pdu (bd -> rq );
4741+ enum obj_operation_type op_type ;
47984742
4799- queue_work (rbd_wq , work );
4743+ switch (req_op (bd -> rq )) {
4744+ case REQ_OP_DISCARD :
4745+ op_type = OBJ_OP_DISCARD ;
4746+ break ;
4747+ case REQ_OP_WRITE_ZEROES :
4748+ op_type = OBJ_OP_ZEROOUT ;
4749+ break ;
4750+ case REQ_OP_WRITE :
4751+ op_type = OBJ_OP_WRITE ;
4752+ break ;
4753+ case REQ_OP_READ :
4754+ op_type = OBJ_OP_READ ;
4755+ break ;
4756+ default :
4757+ rbd_warn (rbd_dev , "unknown req_op %d" , req_op (bd -> rq ));
4758+ return BLK_STS_IOERR ;
4759+ }
4760+
4761+ rbd_img_request_init (img_req , rbd_dev , op_type );
4762+
4763+ if (rbd_img_is_write (img_req )) {
4764+ if (rbd_is_ro (rbd_dev )) {
4765+ rbd_warn (rbd_dev , "%s on read-only mapping" ,
4766+ obj_op_name (img_req -> op_type ));
4767+ return BLK_STS_IOERR ;
4768+ }
4769+ rbd_assert (!rbd_is_snap (rbd_dev ));
4770+ }
4771+
4772+ INIT_WORK (& img_req -> work , rbd_queue_workfn );
4773+ queue_work (rbd_wq , & img_req -> work );
48004774 return BLK_STS_OK ;
48014775}
48024776
@@ -4963,18 +4937,8 @@ static int rbd_dev_refresh(struct rbd_device *rbd_dev)
49634937 return ret ;
49644938}
49654939
4966- static int rbd_init_request (struct blk_mq_tag_set * set , struct request * rq ,
4967- unsigned int hctx_idx , unsigned int numa_node )
4968- {
4969- struct work_struct * work = blk_mq_rq_to_pdu (rq );
4970-
4971- INIT_WORK (work , rbd_queue_workfn );
4972- return 0 ;
4973- }
4974-
49754940static const struct blk_mq_ops rbd_mq_ops = {
49764941 .queue_rq = rbd_queue_rq ,
4977- .init_request = rbd_init_request ,
49784942};
49794943
49804944static int rbd_init_disk (struct rbd_device * rbd_dev )
@@ -5007,7 +4971,7 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
50074971 rbd_dev -> tag_set .numa_node = NUMA_NO_NODE ;
50084972 rbd_dev -> tag_set .flags = BLK_MQ_F_SHOULD_MERGE ;
50094973 rbd_dev -> tag_set .nr_hw_queues = 1 ;
5010- rbd_dev -> tag_set .cmd_size = sizeof (struct work_struct );
4974+ rbd_dev -> tag_set .cmd_size = sizeof (struct rbd_img_request );
50114975
50124976 err = blk_mq_alloc_tag_set (& rbd_dev -> tag_set );
50134977 if (err )
0 commit comments