aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Dryomov <idryomov@gmail.com>2017-01-25 12:16:23 -0500
committerIlya Dryomov <idryomov@gmail.com>2017-02-20 06:16:15 -0500
commitbc81207ea9fc01896cbc102f025f1ebb2c4bae1d (patch)
tree36eae11bd2c62b09a043bbe8f8879465994137a9
parent67e2b65274e3c5fc9100544c1f90adcc85dbe597 (diff)
rbd: factor out __rbd_osd_req_create()
Factor OSD request allocation and initialization code out into __rbd_osd_req_create(). Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Reviewed-by: Jason Dillaman <dillaman@redhat.com>
-rw-r--r--drivers/block/rbd.c103
1 files changed, 40 insertions, 63 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index c975d49e612c..b44b457b4dc7 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -1952,6 +1952,38 @@ static void rbd_osd_req_format_write(struct rbd_obj_request *obj_request)
1952 osd_req->r_data_offset = obj_request->offset; 1952 osd_req->r_data_offset = obj_request->offset;
1953} 1953}
1954 1954
1955static struct ceph_osd_request *
1956__rbd_osd_req_create(struct rbd_device *rbd_dev,
1957 struct ceph_snap_context *snapc,
1958 int num_ops, unsigned int flags,
1959 struct rbd_obj_request *obj_request)
1960{
1961 struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc;
1962 struct ceph_osd_request *req;
1963
1964 req = ceph_osdc_alloc_request(osdc, snapc, num_ops, false, GFP_NOIO);
1965 if (!req)
1966 return NULL;
1967
1968 req->r_flags = flags;
1969 req->r_callback = rbd_osd_req_callback;
1970 req->r_priv = obj_request;
1971
1972 req->r_base_oloc.pool = rbd_dev->layout.pool_id;
1973 if (ceph_oid_aprintf(&req->r_base_oid, GFP_NOIO, "%s",
1974 obj_request->object_name))
1975 goto err_req;
1976
1977 if (ceph_osdc_alloc_messages(req, GFP_NOIO))
1978 goto err_req;
1979
1980 return req;
1981
1982err_req:
1983 ceph_osdc_put_request(req);
1984 return NULL;
1985}
1986
1955/* 1987/*
1956 * Create an osd request. A read request has one osd op (read). 1988 * Create an osd request. A read request has one osd op (read).
1957 * A write request has either one (watch) or two (hint+write) osd ops. 1989 * A write request has either one (watch) or two (hint+write) osd ops.
@@ -1965,8 +1997,6 @@ static struct ceph_osd_request *rbd_osd_req_create(
1965 struct rbd_obj_request *obj_request) 1997 struct rbd_obj_request *obj_request)
1966{ 1998{
1967 struct ceph_snap_context *snapc = NULL; 1999 struct ceph_snap_context *snapc = NULL;
1968 struct ceph_osd_client *osdc;
1969 struct ceph_osd_request *osd_req;
1970 2000
1971 if (obj_request_img_data_test(obj_request) && 2001 if (obj_request_img_data_test(obj_request) &&
1972 (op_type == OBJ_OP_DISCARD || op_type == OBJ_OP_WRITE)) { 2002 (op_type == OBJ_OP_DISCARD || op_type == OBJ_OP_WRITE)) {
@@ -1981,35 +2011,10 @@ static struct ceph_osd_request *rbd_osd_req_create(
1981 2011
1982 rbd_assert(num_ops == 1 || ((op_type == OBJ_OP_WRITE) && num_ops == 2)); 2012 rbd_assert(num_ops == 1 || ((op_type == OBJ_OP_WRITE) && num_ops == 2));
1983 2013
1984 /* Allocate and initialize the request, for the num_ops ops */ 2014 return __rbd_osd_req_create(rbd_dev, snapc, num_ops,
1985 2015 (op_type == OBJ_OP_WRITE || op_type == OBJ_OP_DISCARD) ?
1986 osdc = &rbd_dev->rbd_client->client->osdc; 2016 CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK : CEPH_OSD_FLAG_READ,
1987 osd_req = ceph_osdc_alloc_request(osdc, snapc, num_ops, false, 2017 obj_request);
1988 GFP_NOIO);
1989 if (!osd_req)
1990 goto fail;
1991
1992 if (op_type == OBJ_OP_WRITE || op_type == OBJ_OP_DISCARD)
1993 osd_req->r_flags = CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK;
1994 else
1995 osd_req->r_flags = CEPH_OSD_FLAG_READ;
1996
1997 osd_req->r_callback = rbd_osd_req_callback;
1998 osd_req->r_priv = obj_request;
1999
2000 osd_req->r_base_oloc.pool = rbd_dev->layout.pool_id;
2001 if (ceph_oid_aprintf(&osd_req->r_base_oid, GFP_NOIO, "%s",
2002 obj_request->object_name))
2003 goto fail;
2004
2005 if (ceph_osdc_alloc_messages(osd_req, GFP_NOIO))
2006 goto fail;
2007
2008 return osd_req;
2009
2010fail:
2011 ceph_osdc_put_request(osd_req);
2012 return NULL;
2013} 2018}
2014 2019
2015/* 2020/*
@@ -2022,10 +2027,6 @@ static struct ceph_osd_request *
2022rbd_osd_req_create_copyup(struct rbd_obj_request *obj_request) 2027rbd_osd_req_create_copyup(struct rbd_obj_request *obj_request)
2023{ 2028{
2024 struct rbd_img_request *img_request; 2029 struct rbd_img_request *img_request;
2025 struct ceph_snap_context *snapc;
2026 struct rbd_device *rbd_dev;
2027 struct ceph_osd_client *osdc;
2028 struct ceph_osd_request *osd_req;
2029 int num_osd_ops = 3; 2030 int num_osd_ops = 3;
2030 2031
2031 rbd_assert(obj_request_img_data_test(obj_request)); 2032 rbd_assert(obj_request_img_data_test(obj_request));
@@ -2037,36 +2038,12 @@ rbd_osd_req_create_copyup(struct rbd_obj_request *obj_request)
2037 if (img_request_discard_test(img_request)) 2038 if (img_request_discard_test(img_request))
2038 num_osd_ops = 2; 2039 num_osd_ops = 2;
2039 2040
2040 /* Allocate and initialize the request, for all the ops */ 2041 return __rbd_osd_req_create(img_request->rbd_dev,
2041 2042 img_request->snapc, num_osd_ops,
2042 snapc = img_request->snapc; 2043 CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK,
2043 rbd_dev = img_request->rbd_dev; 2044 obj_request);
2044 osdc = &rbd_dev->rbd_client->client->osdc;
2045 osd_req = ceph_osdc_alloc_request(osdc, snapc, num_osd_ops,
2046 false, GFP_NOIO);
2047 if (!osd_req)
2048 goto fail;
2049
2050 osd_req->r_flags = CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK;
2051 osd_req->r_callback = rbd_osd_req_callback;
2052 osd_req->r_priv = obj_request;
2053
2054 osd_req->r_base_oloc.pool = rbd_dev->layout.pool_id;
2055 if (ceph_oid_aprintf(&osd_req->r_base_oid, GFP_NOIO, "%s",
2056 obj_request->object_name))
2057 goto fail;
2058
2059 if (ceph_osdc_alloc_messages(osd_req, GFP_NOIO))
2060 goto fail;
2061
2062 return osd_req;
2063
2064fail:
2065 ceph_osdc_put_request(osd_req);
2066 return NULL;
2067} 2045}
2068 2046
2069
2070static void rbd_osd_req_destroy(struct ceph_osd_request *osd_req) 2047static void rbd_osd_req_destroy(struct ceph_osd_request *osd_req)
2071{ 2048{
2072 ceph_osdc_put_request(osd_req); 2049 ceph_osdc_put_request(osd_req);