Skip to content

Commit 25e6bae

Browse files
ukernelliewegas
authored andcommitted
ceph: use pagelist to present MDS request data
Current code uses page array to present MDS request data. Pages in the array are allocated/freed by caller of ceph_mdsc_do_request(). If request is interrupted, the pages can be freed while they are still being used by the request message. The fix is use pagelist to present MDS request data. Pagelist is reference counted. Signed-off-by: Yan, Zheng <zyan@redhat.com> Reviewed-by: Sage Weil <sage@redhat.com>
1 parent e4339d2 commit 25e6bae

3 files changed

Lines changed: 28 additions & 39 deletions

File tree

‎fs/ceph/mds_client.c‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,8 @@ void ceph_mdsc_release_request(struct kref *kref)
543543
}
544544
kfree(req->r_path1);
545545
kfree(req->r_path2);
546+
if (req->r_pagelist)
547+
ceph_pagelist_release(req->r_pagelist);
546548
put_request_session(req);
547549
ceph_unreserve_caps(req->r_mdsc, &req->r_caps_reservation);
548550
kfree(req);
@@ -1916,13 +1918,15 @@ static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc,
19161918
msg->front.iov_len = p - msg->front.iov_base;
19171919
msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
19181920

1919-
if (req->r_data_len) {
1920-
/* outbound data set only by ceph_sync_setxattr() */
1921-
BUG_ON(!req->r_pages);
1922-
ceph_msg_data_add_pages(msg, req->r_pages, req->r_data_len, 0);
1921+
if (req->r_pagelist) {
1922+
struct ceph_pagelist *pagelist = req->r_pagelist;
1923+
atomic_inc(&pagelist->refcnt);
1924+
ceph_msg_data_add_pagelist(msg, pagelist);
1925+
msg->hdr.data_len = cpu_to_le32(pagelist->length);
1926+
} else {
1927+
msg->hdr.data_len = 0;
19231928
}
19241929

1925-
msg->hdr.data_len = cpu_to_le32(req->r_data_len);
19261930
msg->hdr.data_off = cpu_to_le16(0);
19271931

19281932
out_free2:

‎fs/ceph/mds_client.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ struct ceph_mds_request {
202202
bool r_direct_is_hash; /* true if r_direct_hash is valid */
203203

204204
/* data payload is used for xattr ops */
205-
struct page **r_pages;
206-
int r_num_pages;
207-
int r_data_len;
205+
struct ceph_pagelist *r_pagelist;
208206

209207
/* what caps shall we drop? */
210208
int r_inode_drop, r_inode_unless;

‎fs/ceph/xattr.c‎

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <linux/ceph/ceph_debug.h>
2+
#include <linux/ceph/pagelist.h>
23

34
#include "super.h"
45
#include "mds_client.h"
@@ -850,35 +851,25 @@ static int ceph_sync_setxattr(struct dentry *dentry, const char *name,
850851
struct ceph_inode_info *ci = ceph_inode(inode);
851852
struct ceph_mds_request *req;
852853
struct ceph_mds_client *mdsc = fsc->mdsc;
854+
struct ceph_pagelist *pagelist = NULL;
853855
int err;
854-
int i, nr_pages;
855-
struct page **pages = NULL;
856-
void *kaddr;
857-
858-
/* copy value into some pages */
859-
nr_pages = calc_pages_for(0, size);
860-
if (nr_pages) {
861-
pages = kmalloc(sizeof(pages[0])*nr_pages, GFP_NOFS);
862-
if (!pages)
856+
857+
if (value) {
858+
/* copy value into pagelist */
859+
pagelist = kmalloc(sizeof(*pagelist), GFP_NOFS);
860+
if (!pagelist)
863861
return -ENOMEM;
864-
err = -ENOMEM;
865-
for (i = 0; i < nr_pages; i++) {
866-
pages[i] = __page_cache_alloc(GFP_NOFS);
867-
if (!pages[i]) {
868-
nr_pages = i;
869-
goto out;
870-
}
871-
kaddr = kmap(pages[i]);
872-
memcpy(kaddr, value + i*PAGE_CACHE_SIZE,
873-
min(PAGE_CACHE_SIZE, size-i*PAGE_CACHE_SIZE));
874-
}
862+
863+
ceph_pagelist_init(pagelist);
864+
err = ceph_pagelist_append(pagelist, value, size);
865+
if (err)
866+
goto out;
867+
} else {
868+
flags |= CEPH_XATTR_REMOVE;
875869
}
876870

877871
dout("setxattr value=%.*s\n", (int)size, value);
878872

879-
if (!value)
880-
flags |= CEPH_XATTR_REMOVE;
881-
882873
/* do request */
883874
req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETXATTR,
884875
USE_AUTH_MDS);
@@ -893,21 +884,17 @@ static int ceph_sync_setxattr(struct dentry *dentry, const char *name,
893884
req->r_args.setxattr.flags = cpu_to_le32(flags);
894885
req->r_path2 = kstrdup(name, GFP_NOFS);
895886

896-
req->r_pages = pages;
897-
req->r_num_pages = nr_pages;
898-
req->r_data_len = size;
887+
req->r_pagelist = pagelist;
888+
pagelist = NULL;
899889

900890
dout("xattr.ver (before): %lld\n", ci->i_xattrs.version);
901891
err = ceph_mdsc_do_request(mdsc, NULL, req);
902892
ceph_mdsc_put_request(req);
903893
dout("xattr.ver (after): %lld\n", ci->i_xattrs.version);
904894

905895
out:
906-
if (pages) {
907-
for (i = 0; i < nr_pages; i++)
908-
__free_page(pages[i]);
909-
kfree(pages);
910-
}
896+
if (pagelist)
897+
ceph_pagelist_release(pagelist);
911898
return err;
912899
}
913900

0 commit comments

Comments
 (0)