Skip to content

Commit 13488d5

Browse files
committed
rbd: stop copying num_osd_ops in rbd_obj_issue_copyup()
In preparation for deep-flatten feature, stop copying num_osd_ops from the original request in rbd_obj_issue_copyup(). Split the calculation into count_{write,zeroout}_ops() respectively and determine whether the assert_exists guard is needed with the new rbd_obj_copyup_enabled(). As a nice side effect, we no longer guard in the writefull case as the copyup'ed object is always fully overwritten. Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent e28eded commit 13488d5

File tree

1 file changed

+59
-31
lines changed

1 file changed

+59
-31
lines changed

drivers/block/rbd.c

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,18 @@ static bool rbd_obj_is_tail(struct rbd_obj_request *obj_req)
14241424
rbd_dev->layout.object_size;
14251425
}
14261426

1427+
/*
1428+
* Must be called after rbd_obj_calc_img_extents().
1429+
*/
1430+
static bool rbd_obj_copyup_enabled(struct rbd_obj_request *obj_req)
1431+
{
1432+
if (!obj_req->num_img_extents ||
1433+
rbd_obj_is_entire(obj_req))
1434+
return false;
1435+
1436+
return true;
1437+
}
1438+
14271439
static u64 rbd_obj_img_extents_bytes(struct rbd_obj_request *obj_req)
14281440
{
14291441
return ceph_file_extents_bytes(obj_req->img_extents,
@@ -1810,6 +1822,11 @@ static int __rbd_obj_setup_stat(struct rbd_obj_request *obj_req,
18101822
return 0;
18111823
}
18121824

1825+
static int count_write_ops(struct rbd_obj_request *obj_req)
1826+
{
1827+
return 2; /* setallochint + write/writefull */
1828+
}
1829+
18131830
static void __rbd_obj_setup_write(struct rbd_obj_request *obj_req,
18141831
unsigned int which)
18151832
{
@@ -1836,29 +1853,29 @@ static void __rbd_obj_setup_write(struct rbd_obj_request *obj_req,
18361853
static int rbd_obj_setup_write(struct rbd_obj_request *obj_req)
18371854
{
18381855
unsigned int num_osd_ops, which = 0;
1856+
bool need_guard;
18391857
int ret;
18401858

18411859
/* reverse map the entire object onto the parent */
18421860
ret = rbd_obj_calc_img_extents(obj_req, true);
18431861
if (ret)
18441862
return ret;
18451863

1846-
if (obj_req->num_img_extents) {
1847-
obj_req->write_state = RBD_OBJ_WRITE_GUARD;
1848-
num_osd_ops = 3; /* stat + setallochint + write/writefull */
1849-
} else {
1850-
obj_req->write_state = RBD_OBJ_WRITE_FLAT;
1851-
num_osd_ops = 2; /* setallochint + write/writefull */
1852-
}
1864+
need_guard = rbd_obj_copyup_enabled(obj_req);
1865+
num_osd_ops = need_guard + count_write_ops(obj_req);
18531866

18541867
obj_req->osd_req = rbd_osd_req_create(obj_req, num_osd_ops);
18551868
if (!obj_req->osd_req)
18561869
return -ENOMEM;
18571870

1858-
if (obj_req->num_img_extents) {
1871+
if (need_guard) {
18591872
ret = __rbd_obj_setup_stat(obj_req, which++);
18601873
if (ret)
18611874
return ret;
1875+
1876+
obj_req->write_state = RBD_OBJ_WRITE_GUARD;
1877+
} else {
1878+
obj_req->write_state = RBD_OBJ_WRITE_FLAT;
18621879
}
18631880

18641881
__rbd_obj_setup_write(obj_req, which);
@@ -1919,6 +1936,18 @@ static int rbd_obj_setup_discard(struct rbd_obj_request *obj_req)
19191936
return 0;
19201937
}
19211938

1939+
static int count_zeroout_ops(struct rbd_obj_request *obj_req)
1940+
{
1941+
int num_osd_ops;
1942+
1943+
if (rbd_obj_is_entire(obj_req) && obj_req->num_img_extents)
1944+
num_osd_ops = 2; /* create + truncate */
1945+
else
1946+
num_osd_ops = 1; /* delete/truncate/zero */
1947+
1948+
return num_osd_ops;
1949+
}
1950+
19221951
static void __rbd_obj_setup_zeroout(struct rbd_obj_request *obj_req,
19231952
unsigned int which)
19241953
{
@@ -1950,37 +1979,29 @@ static void __rbd_obj_setup_zeroout(struct rbd_obj_request *obj_req,
19501979
static int rbd_obj_setup_zeroout(struct rbd_obj_request *obj_req)
19511980
{
19521981
unsigned int num_osd_ops, which = 0;
1982+
bool need_guard;
19531983
int ret;
19541984

19551985
/* reverse map the entire object onto the parent */
19561986
ret = rbd_obj_calc_img_extents(obj_req, true);
19571987
if (ret)
19581988
return ret;
19591989

1960-
if (rbd_obj_is_entire(obj_req)) {
1961-
obj_req->write_state = RBD_OBJ_WRITE_FLAT;
1962-
if (obj_req->num_img_extents)
1963-
num_osd_ops = 2; /* create + truncate */
1964-
else
1965-
num_osd_ops = 1; /* delete */
1966-
} else {
1967-
if (obj_req->num_img_extents) {
1968-
obj_req->write_state = RBD_OBJ_WRITE_GUARD;
1969-
num_osd_ops = 2; /* stat + truncate/zero */
1970-
} else {
1971-
obj_req->write_state = RBD_OBJ_WRITE_FLAT;
1972-
num_osd_ops = 1; /* truncate/zero */
1973-
}
1974-
}
1990+
need_guard = rbd_obj_copyup_enabled(obj_req);
1991+
num_osd_ops = need_guard + count_zeroout_ops(obj_req);
19751992

19761993
obj_req->osd_req = rbd_osd_req_create(obj_req, num_osd_ops);
19771994
if (!obj_req->osd_req)
19781995
return -ENOMEM;
19791996

1980-
if (!rbd_obj_is_entire(obj_req) && obj_req->num_img_extents) {
1997+
if (need_guard) {
19811998
ret = __rbd_obj_setup_stat(obj_req, which++);
19821999
if (ret)
19832000
return ret;
2001+
2002+
obj_req->write_state = RBD_OBJ_WRITE_GUARD;
2003+
} else {
2004+
obj_req->write_state = RBD_OBJ_WRITE_FLAT;
19842005
}
19852006

19862007
__rbd_obj_setup_zeroout(obj_req, which);
@@ -2439,18 +2460,25 @@ static bool is_zero_bvecs(struct bio_vec *bvecs, u32 bytes)
24392460

24402461
static int rbd_obj_issue_copyup(struct rbd_obj_request *obj_req, u32 bytes)
24412462
{
2442-
unsigned int num_osd_ops = obj_req->osd_req->r_num_ops;
2463+
struct rbd_img_request *img_req = obj_req->img_request;
2464+
unsigned int num_osd_ops = 1;
24432465
int ret;
24442466

24452467
dout("%s obj_req %p bytes %u\n", __func__, obj_req, bytes);
24462468
rbd_assert(obj_req->osd_req->r_ops[0].op == CEPH_OSD_OP_STAT);
24472469
rbd_osd_req_destroy(obj_req->osd_req);
24482470

2449-
/*
2450-
* Create a copyup request with the same number of OSD ops as
2451-
* the original request. The original request was stat + op(s),
2452-
* the new copyup request will be copyup + the same op(s).
2453-
*/
2471+
switch (img_req->op_type) {
2472+
case OBJ_OP_WRITE:
2473+
num_osd_ops += count_write_ops(obj_req);
2474+
break;
2475+
case OBJ_OP_ZEROOUT:
2476+
num_osd_ops += count_zeroout_ops(obj_req);
2477+
break;
2478+
default:
2479+
rbd_assert(0);
2480+
}
2481+
24542482
obj_req->osd_req = rbd_osd_req_create(obj_req, num_osd_ops);
24552483
if (!obj_req->osd_req)
24562484
return -ENOMEM;
@@ -2473,7 +2501,7 @@ static int rbd_obj_issue_copyup(struct rbd_obj_request *obj_req, u32 bytes)
24732501
obj_req->copyup_bvec_count,
24742502
bytes);
24752503

2476-
switch (obj_req->img_request->op_type) {
2504+
switch (img_req->op_type) {
24772505
case OBJ_OP_WRITE:
24782506
__rbd_obj_setup_write(obj_req, 1);
24792507
break;

0 commit comments

Comments
 (0)