Skip to content

Commit aca39d9

Browse files
Luís Henriquesidryomov
authored andcommitted
libceph, ceph: move ceph_osdc_copy_from() into cephfs code
This patch moves ceph_osdc_copy_from() function out of libceph code into cephfs. There are no other users for this function, and there is the need (in another patch) to access internal ceph_osd_request struct members. Signed-off-by: Luís Henriques <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 17e9fc9 commit aca39d9

File tree

3 files changed

+80
-73
lines changed

3 files changed

+80
-73
lines changed

fs/ceph/file.c

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,13 +2211,63 @@ static int is_file_size_ok(struct inode *src_inode, struct inode *dst_inode,
22112211
return 0;
22122212
}
22132213

2214+
static struct ceph_osd_request *
2215+
ceph_alloc_copyfrom_request(struct ceph_osd_client *osdc,
2216+
u64 src_snapid,
2217+
struct ceph_object_id *src_oid,
2218+
struct ceph_object_locator *src_oloc,
2219+
struct ceph_object_id *dst_oid,
2220+
struct ceph_object_locator *dst_oloc,
2221+
u32 truncate_seq, u64 truncate_size)
2222+
{
2223+
struct ceph_osd_request *req;
2224+
int ret;
2225+
u32 src_fadvise_flags =
2226+
CEPH_OSD_OP_FLAG_FADVISE_SEQUENTIAL |
2227+
CEPH_OSD_OP_FLAG_FADVISE_NOCACHE;
2228+
u32 dst_fadvise_flags =
2229+
CEPH_OSD_OP_FLAG_FADVISE_SEQUENTIAL |
2230+
CEPH_OSD_OP_FLAG_FADVISE_DONTNEED;
2231+
2232+
req = ceph_osdc_alloc_request(osdc, NULL, 1, false, GFP_KERNEL);
2233+
if (!req)
2234+
return ERR_PTR(-ENOMEM);
2235+
2236+
req->r_flags = CEPH_OSD_FLAG_WRITE;
2237+
2238+
ceph_oloc_copy(&req->r_t.base_oloc, dst_oloc);
2239+
ceph_oid_copy(&req->r_t.base_oid, dst_oid);
2240+
2241+
ret = osd_req_op_copy_from_init(req, src_snapid, 0,
2242+
src_oid, src_oloc,
2243+
src_fadvise_flags,
2244+
dst_fadvise_flags,
2245+
truncate_seq,
2246+
truncate_size,
2247+
CEPH_OSD_COPY_FROM_FLAG_TRUNCATE_SEQ);
2248+
if (ret)
2249+
goto out;
2250+
2251+
ret = ceph_osdc_alloc_messages(req, GFP_KERNEL);
2252+
if (ret)
2253+
goto out;
2254+
2255+
return req;
2256+
2257+
out:
2258+
ceph_osdc_put_request(req);
2259+
return ERR_PTR(ret);
2260+
}
2261+
22142262
static ssize_t ceph_do_objects_copy(struct ceph_inode_info *src_ci, u64 *src_off,
22152263
struct ceph_inode_info *dst_ci, u64 *dst_off,
22162264
struct ceph_fs_client *fsc,
22172265
size_t len, unsigned int flags)
22182266
{
22192267
struct ceph_object_locator src_oloc, dst_oloc;
22202268
struct ceph_object_id src_oid, dst_oid;
2269+
struct ceph_osd_client *osdc;
2270+
struct ceph_osd_request *req;
22212271
size_t bytes = 0;
22222272
u64 src_objnum, src_objoff, dst_objnum, dst_objoff;
22232273
u32 src_objlen, dst_objlen;
@@ -2228,6 +2278,7 @@ static ssize_t ceph_do_objects_copy(struct ceph_inode_info *src_ci, u64 *src_off
22282278
src_oloc.pool_ns = ceph_try_get_string(src_ci->i_layout.pool_ns);
22292279
dst_oloc.pool = dst_ci->i_layout.pool_id;
22302280
dst_oloc.pool_ns = ceph_try_get_string(dst_ci->i_layout.pool_ns);
2281+
osdc = &fsc->client->osdc;
22312282

22322283
while (len >= object_size) {
22332284
ceph_calc_file_object_mapping(&src_ci->i_layout, *src_off,
@@ -2243,17 +2294,18 @@ static ssize_t ceph_do_objects_copy(struct ceph_inode_info *src_ci, u64 *src_off
22432294
ceph_oid_printf(&dst_oid, "%llx.%08llx",
22442295
dst_ci->i_vino.ino, dst_objnum);
22452296
/* Do an object remote copy */
2246-
ret = ceph_osdc_copy_from(&fsc->client->osdc,
2247-
src_ci->i_vino.snap, 0,
2248-
&src_oid, &src_oloc,
2249-
CEPH_OSD_OP_FLAG_FADVISE_SEQUENTIAL |
2250-
CEPH_OSD_OP_FLAG_FADVISE_NOCACHE,
2251-
&dst_oid, &dst_oloc,
2252-
CEPH_OSD_OP_FLAG_FADVISE_SEQUENTIAL |
2253-
CEPH_OSD_OP_FLAG_FADVISE_DONTNEED,
2254-
dst_ci->i_truncate_seq,
2255-
dst_ci->i_truncate_size,
2256-
CEPH_OSD_COPY_FROM_FLAG_TRUNCATE_SEQ);
2297+
req = ceph_alloc_copyfrom_request(osdc, src_ci->i_vino.snap,
2298+
&src_oid, &src_oloc,
2299+
&dst_oid, &dst_oloc,
2300+
dst_ci->i_truncate_seq,
2301+
dst_ci->i_truncate_size);
2302+
if (IS_ERR(req))
2303+
ret = PTR_ERR(req);
2304+
else {
2305+
ceph_osdc_start_request(osdc, req, false);
2306+
ret = ceph_osdc_wait_request(osdc, req);
2307+
ceph_osdc_put_request(req);
2308+
}
22572309
if (ret) {
22582310
if (ret == -EOPNOTSUPP) {
22592311
fsc->have_copy_from2 = false;

include/linux/ceph/osd_client.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,14 @@ extern void osd_req_op_alloc_hint_init(struct ceph_osd_request *osd_req,
475475
u64 expected_object_size,
476476
u64 expected_write_size,
477477
u32 flags);
478+
extern int osd_req_op_copy_from_init(struct ceph_osd_request *req,
479+
u64 src_snapid, u64 src_version,
480+
struct ceph_object_id *src_oid,
481+
struct ceph_object_locator *src_oloc,
482+
u32 src_fadvise_flags,
483+
u32 dst_fadvise_flags,
484+
u32 truncate_seq, u64 truncate_size,
485+
u8 copy_from_flags);
478486

479487
extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
480488
struct ceph_snap_context *snapc,
@@ -515,17 +523,6 @@ int ceph_osdc_call(struct ceph_osd_client *osdc,
515523
struct page *req_page, size_t req_len,
516524
struct page **resp_pages, size_t *resp_len);
517525

518-
int ceph_osdc_copy_from(struct ceph_osd_client *osdc,
519-
u64 src_snapid, u64 src_version,
520-
struct ceph_object_id *src_oid,
521-
struct ceph_object_locator *src_oloc,
522-
u32 src_fadvise_flags,
523-
struct ceph_object_id *dst_oid,
524-
struct ceph_object_locator *dst_oloc,
525-
u32 dst_fadvise_flags,
526-
u32 truncate_seq, u64 truncate_size,
527-
u8 copy_from_flags);
528-
529526
/* watch/notify */
530527
struct ceph_osd_linger_request *
531528
ceph_osdc_watch(struct ceph_osd_client *osdc,

net/ceph/osd_client.c

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5310,14 +5310,14 @@ void ceph_osdc_stop(struct ceph_osd_client *osdc)
53105310
ceph_msgpool_destroy(&osdc->msgpool_op_reply);
53115311
}
53125312

5313-
static int osd_req_op_copy_from_init(struct ceph_osd_request *req,
5314-
u64 src_snapid, u64 src_version,
5315-
struct ceph_object_id *src_oid,
5316-
struct ceph_object_locator *src_oloc,
5317-
u32 src_fadvise_flags,
5318-
u32 dst_fadvise_flags,
5319-
u32 truncate_seq, u64 truncate_size,
5320-
u8 copy_from_flags)
5313+
int osd_req_op_copy_from_init(struct ceph_osd_request *req,
5314+
u64 src_snapid, u64 src_version,
5315+
struct ceph_object_id *src_oid,
5316+
struct ceph_object_locator *src_oloc,
5317+
u32 src_fadvise_flags,
5318+
u32 dst_fadvise_flags,
5319+
u32 truncate_seq, u64 truncate_size,
5320+
u8 copy_from_flags)
53215321
{
53225322
struct ceph_osd_req_op *op;
53235323
struct page **pages;
@@ -5346,49 +5346,7 @@ static int osd_req_op_copy_from_init(struct ceph_osd_request *req,
53465346
op->indata_len, 0, false, true);
53475347
return 0;
53485348
}
5349-
5350-
int ceph_osdc_copy_from(struct ceph_osd_client *osdc,
5351-
u64 src_snapid, u64 src_version,
5352-
struct ceph_object_id *src_oid,
5353-
struct ceph_object_locator *src_oloc,
5354-
u32 src_fadvise_flags,
5355-
struct ceph_object_id *dst_oid,
5356-
struct ceph_object_locator *dst_oloc,
5357-
u32 dst_fadvise_flags,
5358-
u32 truncate_seq, u64 truncate_size,
5359-
u8 copy_from_flags)
5360-
{
5361-
struct ceph_osd_request *req;
5362-
int ret;
5363-
5364-
req = ceph_osdc_alloc_request(osdc, NULL, 1, false, GFP_KERNEL);
5365-
if (!req)
5366-
return -ENOMEM;
5367-
5368-
req->r_flags = CEPH_OSD_FLAG_WRITE;
5369-
5370-
ceph_oloc_copy(&req->r_t.base_oloc, dst_oloc);
5371-
ceph_oid_copy(&req->r_t.base_oid, dst_oid);
5372-
5373-
ret = osd_req_op_copy_from_init(req, src_snapid, src_version, src_oid,
5374-
src_oloc, src_fadvise_flags,
5375-
dst_fadvise_flags, truncate_seq,
5376-
truncate_size, copy_from_flags);
5377-
if (ret)
5378-
goto out;
5379-
5380-
ret = ceph_osdc_alloc_messages(req, GFP_KERNEL);
5381-
if (ret)
5382-
goto out;
5383-
5384-
ceph_osdc_start_request(osdc, req, false);
5385-
ret = ceph_osdc_wait_request(osdc, req);
5386-
5387-
out:
5388-
ceph_osdc_put_request(req);
5389-
return ret;
5390-
}
5391-
EXPORT_SYMBOL(ceph_osdc_copy_from);
5349+
EXPORT_SYMBOL(osd_req_op_copy_from_init);
53925350

53935351
int __init ceph_osdc_setup(void)
53945352
{

0 commit comments

Comments
 (0)