Skip to content

Commit 78beb0f

Browse files
Luis Henriquesidryomov
authored andcommitted
ceph: use copy-from2 op in copy_file_range
Instead of using the copy-from operation, switch copy_file_range to the new copy-from2 operation, which allows to send the truncate_seq and truncate_size parameters. If an OSD does not support the copy-from2 operation it will return -EOPNOTSUPP. In that case, the kernel client will stop trying to do remote object copies for this fs client and will always use the generic VFS copy_file_range. Signed-off-by: Luis Henriques <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 045100c commit 78beb0f

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

fs/ceph/file.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,9 @@ static ssize_t __ceph_copy_file_range(struct file *src_file, loff_t src_off,
19741974
if (ceph_test_mount_opt(src_fsc, NOCOPYFROM))
19751975
return -EOPNOTSUPP;
19761976

1977+
if (!src_fsc->have_copy_from2)
1978+
return -EOPNOTSUPP;
1979+
19771980
/*
19781981
* Striped file layouts require that we copy partial objects, but the
19791982
* OSD copy-from operation only supports full-object copies. Limit
@@ -2101,8 +2104,14 @@ static ssize_t __ceph_copy_file_range(struct file *src_file, loff_t src_off,
21012104
CEPH_OSD_OP_FLAG_FADVISE_NOCACHE,
21022105
&dst_oid, &dst_oloc,
21032106
CEPH_OSD_OP_FLAG_FADVISE_SEQUENTIAL |
2104-
CEPH_OSD_OP_FLAG_FADVISE_DONTNEED, 0);
2107+
CEPH_OSD_OP_FLAG_FADVISE_DONTNEED,
2108+
dst_ci->i_truncate_seq, dst_ci->i_truncate_size,
2109+
CEPH_OSD_COPY_FROM_FLAG_TRUNCATE_SEQ);
21052110
if (err) {
2111+
if (err == -EOPNOTSUPP) {
2112+
src_fsc->have_copy_from2 = false;
2113+
pr_notice("OSDs don't support copy-from2; disabling copy offload\n");
2114+
}
21062115
dout("ceph_osdc_copy_from returned %d\n", err);
21072116
if (!ret)
21082117
ret = err;

fs/ceph/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
718718
fsc->sb = NULL;
719719
fsc->mount_state = CEPH_MOUNT_MOUNTING;
720720
fsc->filp_gen = 1;
721+
fsc->have_copy_from2 = true;
721722

722723
atomic_long_set(&fsc->writeback_count, 0);
723724

fs/ceph/super.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ struct ceph_fs_client {
106106
unsigned long last_auto_reconnect;
107107
bool blacklisted;
108108

109+
bool have_copy_from2;
110+
109111
u32 filp_gen;
110112
loff_t max_file_size;
111113

include/linux/ceph/osd_client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ int ceph_osdc_copy_from(struct ceph_osd_client *osdc,
534534
struct ceph_object_id *dst_oid,
535535
struct ceph_object_locator *dst_oloc,
536536
u32 dst_fadvise_flags,
537+
u32 truncate_seq, u64 truncate_size,
537538
u8 copy_from_flags);
538539

539540
/* watch/notify */

include/linux/ceph/rados.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ extern const char *ceph_osd_state_name(int s);
256256
\
257257
/* tiering */ \
258258
f(COPY_FROM, __CEPH_OSD_OP(WR, DATA, 26), "copy-from") \
259+
f(COPY_FROM2, __CEPH_OSD_OP(WR, DATA, 45), "copy-from2") \
259260
f(COPY_GET_CLASSIC, __CEPH_OSD_OP(RD, DATA, 27), "copy-get-classic") \
260261
f(UNDIRTY, __CEPH_OSD_OP(WR, DATA, 28), "undirty") \
261262
f(ISDIRTY, __CEPH_OSD_OP(RD, DATA, 29), "isdirty") \
@@ -446,6 +447,7 @@ enum {
446447
CEPH_OSD_COPY_FROM_FLAG_MAP_SNAP_CLONE = 8, /* map snap direct to
447448
* cloneid */
448449
CEPH_OSD_COPY_FROM_FLAG_RWORDERED = 16, /* order with write */
450+
CEPH_OSD_COPY_FROM_FLAG_TRUNCATE_SEQ = 32, /* send truncate_{seq,size} */
449451
};
450452

451453
enum {

net/ceph/osd_client.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ static void osd_req_op_data_release(struct ceph_osd_request *osd_req,
402402
case CEPH_OSD_OP_LIST_WATCHERS:
403403
ceph_osd_data_release(&op->list_watchers.response_data);
404404
break;
405-
case CEPH_OSD_OP_COPY_FROM:
405+
case CEPH_OSD_OP_COPY_FROM2:
406406
ceph_osd_data_release(&op->copy_from.osd_data);
407407
break;
408408
default:
@@ -697,7 +697,7 @@ static void get_num_data_items(struct ceph_osd_request *req,
697697
case CEPH_OSD_OP_SETXATTR:
698698
case CEPH_OSD_OP_CMPXATTR:
699699
case CEPH_OSD_OP_NOTIFY_ACK:
700-
case CEPH_OSD_OP_COPY_FROM:
700+
case CEPH_OSD_OP_COPY_FROM2:
701701
*num_request_data_items += 1;
702702
break;
703703

@@ -1029,7 +1029,7 @@ static u32 osd_req_encode_op(struct ceph_osd_op *dst,
10291029
case CEPH_OSD_OP_CREATE:
10301030
case CEPH_OSD_OP_DELETE:
10311031
break;
1032-
case CEPH_OSD_OP_COPY_FROM:
1032+
case CEPH_OSD_OP_COPY_FROM2:
10331033
dst->copy_from.snapid = cpu_to_le64(src->copy_from.snapid);
10341034
dst->copy_from.src_version =
10351035
cpu_to_le64(src->copy_from.src_version);
@@ -1966,7 +1966,7 @@ static void setup_request_data(struct ceph_osd_request *req)
19661966
ceph_osdc_msg_data_add(request_msg,
19671967
&op->notify_ack.request_data);
19681968
break;
1969-
case CEPH_OSD_OP_COPY_FROM:
1969+
case CEPH_OSD_OP_COPY_FROM2:
19701970
ceph_osdc_msg_data_add(request_msg,
19711971
&op->copy_from.osd_data);
19721972
break;
@@ -5315,6 +5315,7 @@ static int osd_req_op_copy_from_init(struct ceph_osd_request *req,
53155315
struct ceph_object_locator *src_oloc,
53165316
u32 src_fadvise_flags,
53175317
u32 dst_fadvise_flags,
5318+
u32 truncate_seq, u64 truncate_size,
53185319
u8 copy_from_flags)
53195320
{
53205321
struct ceph_osd_req_op *op;
@@ -5325,7 +5326,8 @@ static int osd_req_op_copy_from_init(struct ceph_osd_request *req,
53255326
if (IS_ERR(pages))
53265327
return PTR_ERR(pages);
53275328

5328-
op = _osd_req_op_init(req, 0, CEPH_OSD_OP_COPY_FROM, dst_fadvise_flags);
5329+
op = _osd_req_op_init(req, 0, CEPH_OSD_OP_COPY_FROM2,
5330+
dst_fadvise_flags);
53295331
op->copy_from.snapid = src_snapid;
53305332
op->copy_from.src_version = src_version;
53315333
op->copy_from.flags = copy_from_flags;
@@ -5335,6 +5337,8 @@ static int osd_req_op_copy_from_init(struct ceph_osd_request *req,
53355337
end = p + PAGE_SIZE;
53365338
ceph_encode_string(&p, end, src_oid->name, src_oid->name_len);
53375339
encode_oloc(&p, end, src_oloc);
5340+
ceph_encode_32(&p, truncate_seq);
5341+
ceph_encode_64(&p, truncate_size);
53385342
op->indata_len = PAGE_SIZE - (end - p);
53395343

53405344
ceph_osd_data_pages_init(&op->copy_from.osd_data, pages,
@@ -5350,6 +5354,7 @@ int ceph_osdc_copy_from(struct ceph_osd_client *osdc,
53505354
struct ceph_object_id *dst_oid,
53515355
struct ceph_object_locator *dst_oloc,
53525356
u32 dst_fadvise_flags,
5357+
u32 truncate_seq, u64 truncate_size,
53535358
u8 copy_from_flags)
53545359
{
53555360
struct ceph_osd_request *req;
@@ -5366,7 +5371,8 @@ int ceph_osdc_copy_from(struct ceph_osd_client *osdc,
53665371

53675372
ret = osd_req_op_copy_from_init(req, src_snapid, src_version, src_oid,
53685373
src_oloc, src_fadvise_flags,
5369-
dst_fadvise_flags, copy_from_flags);
5374+
dst_fadvise_flags, truncate_seq,
5375+
truncate_size, copy_from_flags);
53705376
if (ret)
53715377
goto out;
53725378

0 commit comments

Comments
 (0)