Skip to content

Commit 3c5df89

Browse files
jdurginidryomov
authored andcommitted
rbd: read image size for discard check safely
In rbd_img_request_fill() the image size is only checked to determine whether we can truncate an object instead of zeroing it for discard requests. Take rbd_dev->header_rwsem while reading the image size, and move this read into the discard check, so that non-discard ops don't need to take the semaphore in this function. Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
1 parent 90e98c5 commit 3c5df89

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

‎drivers/block/rbd.c‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,7 +2332,6 @@ static int rbd_img_request_fill(struct rbd_img_request *img_request,
23322332
(int)type, data_desc);
23332333

23342334
img_offset = img_request->offset;
2335-
img_end = rbd_dev->header.image_size;
23362335
resid = img_request->length;
23372336
rbd_assert(resid > 0);
23382337

@@ -2397,13 +2396,20 @@ static int rbd_img_request_fill(struct rbd_img_request *img_request,
23972396
if (!offset && (length == object_size)
23982397
&& (!img_request_layered_test(img_request) ||
23992398
(rbd_dev->parent_overlap <=
2400-
obj_request->img_offset)))
2399+
obj_request->img_offset))) {
24012400
opcode = CEPH_OSD_OP_DELETE;
2402-
else if ((offset + length == object_size) ||
2403-
(obj_request->img_offset + length == img_end))
2401+
} else if ((offset + length == object_size)) {
24042402
opcode = CEPH_OSD_OP_TRUNCATE;
2405-
else
2406-
opcode = CEPH_OSD_OP_ZERO;
2403+
} else {
2404+
down_read(&rbd_dev->header_rwsem);
2405+
img_end = rbd_dev->header.image_size;
2406+
up_read(&rbd_dev->header_rwsem);
2407+
2408+
if (obj_request->img_offset + length == img_end)
2409+
opcode = CEPH_OSD_OP_TRUNCATE;
2410+
else
2411+
opcode = CEPH_OSD_OP_ZERO;
2412+
}
24072413
} else if (img_request_write_test(img_request)) {
24082414
op_type = OBJ_OP_WRITE;
24092415
opcode = CEPH_OSD_OP_WRITE;

0 commit comments

Comments
 (0)