Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+40 -63
+40 -63
drivers/block/rbd.c
··· 1952 1952 osd_req->r_data_offset = obj_request->offset; 1953 1953 } 1954 1954 1955 + static 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 + 1982 + err_req: 1983 + ceph_osdc_put_request(req); 1984 + return NULL; 1985 + } 1986 + 1955 1987 /* 1956 1988 * Create an osd request. A read request has one osd op (read). 1957 1989 * A write request has either one (watch) or two (hint+write) osd ops. ··· 1997 1965 struct rbd_obj_request *obj_request) 1998 1966 { 1999 1967 struct ceph_snap_context *snapc = NULL; 2000 - struct ceph_osd_client *osdc; 2001 - struct ceph_osd_request *osd_req; 2002 1968 2003 1969 if (obj_request_img_data_test(obj_request) && 2004 1970 (op_type == OBJ_OP_DISCARD || op_type == OBJ_OP_WRITE)) { ··· 2011 1981 2012 1982 rbd_assert(num_ops == 1 || ((op_type == OBJ_OP_WRITE) && num_ops == 2)); 2013 1983 2014 - /* Allocate and initialize the request, for the num_ops ops */ 2015 - 2016 - osdc = &rbd_dev->rbd_client->client->osdc; 2017 - osd_req = ceph_osdc_alloc_request(osdc, snapc, num_ops, false, 2018 - GFP_NOIO); 2019 - if (!osd_req) 2020 - goto fail; 2021 - 2022 - if (op_type == OBJ_OP_WRITE || op_type == OBJ_OP_DISCARD) 2023 - osd_req->r_flags = CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK; 2024 - else 2025 - osd_req->r_flags = CEPH_OSD_FLAG_READ; 2026 - 2027 - osd_req->r_callback = rbd_osd_req_callback; 2028 - osd_req->r_priv = obj_request; 2029 - 2030 - osd_req->r_base_oloc.pool = rbd_dev->layout.pool_id; 2031 - if (ceph_oid_aprintf(&osd_req->r_base_oid, GFP_NOIO, "%s", 2032 - obj_request->object_name)) 2033 - goto fail; 2034 - 2035 - if (ceph_osdc_alloc_messages(osd_req, GFP_NOIO)) 2036 - goto fail; 2037 - 2038 - return osd_req; 2039 - 2040 - fail: 2041 - ceph_osdc_put_request(osd_req); 2042 - return NULL; 1984 + return __rbd_osd_req_create(rbd_dev, snapc, num_ops, 1985 + (op_type == OBJ_OP_WRITE || op_type == OBJ_OP_DISCARD) ? 1986 + CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK : CEPH_OSD_FLAG_READ, 1987 + obj_request); 2043 1988 } 2044 1989 2045 1990 /* ··· 2027 2022 rbd_osd_req_create_copyup(struct rbd_obj_request *obj_request) 2028 2023 { 2029 2024 struct rbd_img_request *img_request; 2030 - struct ceph_snap_context *snapc; 2031 - struct rbd_device *rbd_dev; 2032 - struct ceph_osd_client *osdc; 2033 - struct ceph_osd_request *osd_req; 2034 2025 int num_osd_ops = 3; 2035 2026 2036 2027 rbd_assert(obj_request_img_data_test(obj_request)); ··· 2038 2037 if (img_request_discard_test(img_request)) 2039 2038 num_osd_ops = 2; 2040 2039 2041 - /* Allocate and initialize the request, for all the ops */ 2042 - 2043 - snapc = img_request->snapc; 2044 - rbd_dev = img_request->rbd_dev; 2045 - osdc = &rbd_dev->rbd_client->client->osdc; 2046 - osd_req = ceph_osdc_alloc_request(osdc, snapc, num_osd_ops, 2047 - false, GFP_NOIO); 2048 - if (!osd_req) 2049 - goto fail; 2050 - 2051 - osd_req->r_flags = CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK; 2052 - osd_req->r_callback = rbd_osd_req_callback; 2053 - osd_req->r_priv = obj_request; 2054 - 2055 - osd_req->r_base_oloc.pool = rbd_dev->layout.pool_id; 2056 - if (ceph_oid_aprintf(&osd_req->r_base_oid, GFP_NOIO, "%s", 2057 - obj_request->object_name)) 2058 - goto fail; 2059 - 2060 - if (ceph_osdc_alloc_messages(osd_req, GFP_NOIO)) 2061 - goto fail; 2062 - 2063 - return osd_req; 2064 - 2065 - fail: 2066 - ceph_osdc_put_request(osd_req); 2067 - return NULL; 2040 + return __rbd_osd_req_create(img_request->rbd_dev, 2041 + img_request->snapc, num_osd_ops, 2042 + CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK, 2043 + obj_request); 2068 2044 } 2069 - 2070 2045 2071 2046 static void rbd_osd_req_destroy(struct ceph_osd_request *osd_req) 2072 2047 {