rbd: factor out __rbd_osd_req_create()
authorIlya Dryomov <idryomov@gmail.com>
Mon, 25 Feb 2019 10:42:26 +0000 (11:42 +0100)
committerIlya Dryomov <idryomov@gmail.com>
Tue, 5 Mar 2019 17:55:17 +0000 (18:55 +0100)
Allow passing a custom snapshot context: NULL for read and an empty
snapshot context for deep-copyup.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
drivers/block/rbd.c

index c247938..6691552 100644 (file)
@@ -1486,18 +1486,16 @@ static void rbd_osd_req_format_write(struct rbd_obj_request *obj_request)
 }
 
 static struct ceph_osd_request *
-rbd_osd_req_create(struct rbd_obj_request *obj_req, unsigned int num_ops)
+__rbd_osd_req_create(struct rbd_obj_request *obj_req,
+                    struct ceph_snap_context *snapc, unsigned int num_ops)
 {
-       struct rbd_img_request *img_req = obj_req->img_request;
-       struct rbd_device *rbd_dev = img_req->rbd_dev;
+       struct rbd_device *rbd_dev = obj_req->img_request->rbd_dev;
        struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc;
        struct ceph_osd_request *req;
        const char *name_format = rbd_dev->image_format == 1 ?
                                      RBD_V1_DATA_FORMAT : RBD_V2_DATA_FORMAT;
 
-       req = ceph_osdc_alloc_request(osdc,
-                       (rbd_img_is_write(img_req) ? img_req->snapc : NULL),
-                       num_ops, false, GFP_NOIO);
+       req = ceph_osdc_alloc_request(osdc, snapc, num_ops, false, GFP_NOIO);
        if (!req)
                return NULL;
 
@@ -1522,6 +1520,13 @@ err_req:
        return NULL;
 }
 
+static struct ceph_osd_request *
+rbd_osd_req_create(struct rbd_obj_request *obj_req, unsigned int num_ops)
+{
+       return __rbd_osd_req_create(obj_req, obj_req->img_request->snapc,
+                                   num_ops);
+}
+
 static void rbd_osd_req_destroy(struct ceph_osd_request *osd_req)
 {
        ceph_osdc_put_request(osd_req);
@@ -1769,7 +1774,7 @@ static void rbd_osd_req_setup_data(struct rbd_obj_request *obj_req, u32 which)
 
 static int rbd_obj_setup_read(struct rbd_obj_request *obj_req)
 {
-       obj_req->osd_req = rbd_osd_req_create(obj_req, 1);
+       obj_req->osd_req = __rbd_osd_req_create(obj_req, NULL, 1);
        if (!obj_req->osd_req)
                return -ENOMEM;