libceph: reference counting pagelist
Subsystems (2)
PATCH 1/3 libceph: reference counting pagelist
this allow pagelist to present data that may be sent multiple times.
--- fs/ceph/mds_client.c | 1 - include/linux/ceph/pagelist.h | 5 ++++- net/ceph/messenger.c | 4 +--- net/ceph/pagelist.c | 8 ++++++-- 4 files changed, 11 insertions(+), 7 deletions(-)
fs/ceph/mds_client.c +0 -1
@@ -2796,7 +2796,6 @@ fail:mutex_unlock (&session->s_mutex); fail_nomsg:ceph_pagelist_release (pagelist); -kfree (pagelist); fail_nopagelist:pr_err ("error %d preparing reconnect for mds%d\n" , err, mds);return ;
include/linux/ceph/pagelist.h +4 -1
@@ -2,6 +2,7 @@#define __FS_CEPH_PAGELIST_H#include <linux/list.h> +#include <linux/atomic.h> struct ceph_pagelist {struct list_head head;
@@ -10,6 +11,7 @@ struct ceph_pagelist {size_t room;struct list_head free_list;size_t num_pages_free; +atomic_t refcnt; };struct ceph_pagelist_cursor {
@@ -26,9 +28,10 @@ static inline void ceph_pagelist_init(struct ceph_pagelist *pl) pl->room =0 ;INIT_LIST_HEAD (&pl->free_list); pl->num_pages_free =0 ; +atomic_set (&pl->refcnt,1 ); } -extern int ceph_pagelist_release (struct ceph_pagelist *pl); +extern void ceph_pagelist_release (struct ceph_pagelist *pl);extern int ceph_pagelist_append (struct ceph_pagelist *pl,const void *d,size_t l);
net/ceph/messenger.c +1 -3
@@ -3071,10 +3071,8 @@ static void ceph_msg_data_destroy(struct ceph_msg_data *data)return ;WARN_ON (!list_empty (&data->links)); -if (data->type ==CEPH_MSG_DATA_PAGELIST ) { +if (data->type ==CEPH_MSG_DATA_PAGELIST )ceph_pagelist_release (data->pagelist); -kfree (data->pagelist); - }kmem_cache_free (ceph_msg_data_cache, data); }
net/ceph/pagelist.c +6 -2
@@ -1,5 +1,6 @@#include <linux/module.h> #include <linux/gfp.h> +#include <linux/slab.h> #include <linux/pagemap.h> #include <linux/highmem.h> #include <linux/ceph/pagelist.h>
@@ -13,8 +14,10 @@ static void ceph_pagelist_unmap_tail(struct ceph_pagelist *pl) } } -int ceph_pagelist_release (struct ceph_pagelist *pl) +void ceph_pagelist_release (struct ceph_pagelist *pl) { +if (!atomic_dec_and_test (&pl->refcnt)) +return ;ceph_pagelist_unmap_tail (pl);while (!list_empty (&pl->head)) { struct page *page = list_first_entry(&pl->head, struct page,
@@ -23,7 +26,8 @@ int ceph_pagelist_release(struct ceph_pagelist *pl)__free_page (page); }ceph_pagelist_free_reserve (pl); -return 0 ; +kfree (pl); +return ; }EXPORT_SYMBOL (ceph_pagelist_release);
Signature · 1 line
1.9.3
PATCH 2/3 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.
--- fs/ceph/mds_client.c | 14 +++++++++----- fs/ceph/mds_client.h | 4 +--- fs/ceph/xattr.c | 46 ++++++++++++++++------------------------------ 3 files changed, 26 insertions(+), 38 deletions(-)
fs/ceph/mds_client.c +9 -5
@@ -542,6 +542,8 @@ void ceph_mdsc_release_request(struct kref *kref) }kfree (req->r_path1);kfree (req->r_path2); +if (req->r_pagelist) +ceph_pagelist_release (req->r_pagelist);put_request_session (req);ceph_unreserve_caps (req->r_mdsc, &req->r_caps_reservation);kfree (req);
@@ -1847,13 +1849,15 @@ static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc, msg->front.iov_len = p - msg->front.iov_base; msg->hdr.front_len =cpu_to_le32 (msg->front.iov_len); -if (req->r_data_len) { -/* outbound data set only by ceph_sync_setxattr() */ -BUG_ON (!req->r_pages); -ceph_msg_data_add_pages (msg, req->r_pages, req->r_data_len,0 ); +if (req->r_pagelist) { +struct ceph_pagelist *pagelist = req->r_pagelist; +atomic_inc (&pagelist->refcnt); +ceph_msg_data_add_pagelist (msg, pagelist); + msg->hdr.data_len =cpu_to_le32 (pagelist->length); + }else { + msg->hdr.data_len =0 ; } - msg->hdr.data_len =cpu_to_le32 (req->r_data_len); msg->hdr.data_off =cpu_to_le16 (0 ); out_free2:
fs/ceph/mds_client.h +1 -3
@@ -202,9 +202,7 @@ struct ceph_mds_request {bool r_direct_is_hash;/* true if r_direct_hash is valid */ /* data payload is used for xattr ops */ -struct page **r_pages; -int r_num_pages; -int r_data_len; +struct ceph_pagelist *r_pagelist;/* what caps shall we drop? */ int r_inode_drop, r_inode_unless;
fs/ceph/xattr.c +16 -30
68 lines not on this page · raw message
Signature · 1 line
1.9.3
Re: [PATCH 2/3] ceph: use pagelist to present MDS request data
Quoted 9 lines · Zheng
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 <[email protected]>
So much nicer!
Quoted 140 lines
--- fs/ceph/mds_client.c | 14 +++++++++----- fs/ceph/mds_client.h | 4 +--- fs/ceph/xattr.c | 46 ++++++++++++++++------------------------------ 3 files changed, 26 insertions(+), 38 deletions(-)fs/ceph/mds_client.c +9
-5@@ -542,6 +542,8 @@ void ceph_mdsc_release_request(struct kref *kref) }kfree (req->r_path1);kfree (req->r_path2); +if (req->r_pagelist) +ceph_pagelist_release (req->r_pagelist);put_request_session (req);ceph_unreserve_caps (req->r_mdsc, &req->r_caps_reservation);kfree (req);@@ -1847,13 +1849,15 @@ static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc, msg->front.iov_len = p - msg->front.iov_base; msg->hdr.front_len =cpu_to_le32 (msg->front.iov_len); -if (req->r_data_len) { -/* outbound data set only by ceph_sync_setxattr() */ -BUG_ON (!req->r_pages); -ceph_msg_data_add_pages (msg, req->r_pages, req->r_data_len,0 ); +if (req->r_pagelist) { +struct ceph_pagelist *pagelist = req->r_pagelist; +atomic_inc (&pagelist->refcnt); +ceph_msg_data_add_pagelist (msg, pagelist); + msg->hdr.data_len =cpu_to_le32 (pagelist->length); + }else { + msg->hdr.data_len =0 ; } - msg->hdr.data_len =cpu_to_le32 (req->r_data_len); msg->hdr.data_off =cpu_to_le16 (0 ); out_free2:fs/ceph/mds_client.h +1
-3@@ -202,9 +202,7 @@ struct ceph_mds_request {bool r_direct_is_hash;/* true if r_direct_hash is valid */ /* data payload is used for xattr ops */ -struct page **r_pages; -int r_num_pages; -int r_data_len; +struct ceph_pagelist *r_pagelist;/* what caps shall we drop? */ int r_inode_drop, r_inode_unless;fs/ceph/xattr.c +16
-30@@ -1,4 +1,5 @@#include <linux/ceph/ceph_debug.h> +#include <linux/ceph/pagelist.h> #include "super.h" #include "mds_client.h" @@ -852,28 +853,17 @@ static int ceph_sync_setxattr(struct dentry *dentry, const char *name,struct ceph_mds_request *req;struct ceph_mds_client *mdsc = fsc->mdsc;int err; -int i, nr_pages; -struct page **pages =NULL ; -void *kaddr; - -/* copy value into some pages */ - nr_pages =calc_pages_for (0 , size); -if (nr_pages) { - pages =kmalloc (sizeof (pages[0 ])*nr_pages,GFP_NOFS ); -if (!pages) -return -ENOMEM ; - err = -ENOMEM ; -for (i =0 ; i < nr_pages; i++) { - pages[i] =__page_cache_alloc (GFP_NOFS ); -if (!pages[i]) { - nr_pages = i; - goto out; - } - kaddr =kmap (pages[i]); -memcpy (kaddr, value + i*PAGE_CACHE_SIZE , -min (PAGE_CACHE_SIZE , size-i*PAGE_CACHE_SIZE )); - } - } +struct ceph_pagelist *pagelist; + +/* copy value into pagelist */ + pagelist =kmalloc (sizeof (*pagelist),GFP_NOFS ); +if (!pagelist) +return -ENOMEM ; + +ceph_pagelist_init (pagelist); + err =ceph_pagelist_append (pagelist, value, size); +if (err) + goto out;dout ("setxattr value=%.*s\n" , (int )size, value);@@ -894,9 +884,8 @@ static int ceph_sync_setxattr(struct dentry *dentry, const char *name, req->r_args.setxattr.flags =cpu_to_le32 (flags); req->r_path2 =kstrdup (name,GFP_NOFS ); - req->r_pages = pages; - req->r_num_pages = nr_pages; - req->r_data_len = size; + req->r_pagelist = pagelist; + pagelist =NULL ;dout ("xattr.ver (before): %lld\n" , ci->i_xattrs.version); err =ceph_mdsc_do_request (mdsc,NULL , req);@@ -904,11 +893,8 @@ static int ceph_sync_setxattr(struct dentry *dentry, const char *name,dout ("xattr.ver (after): %lld\n" , ci->i_xattrs.version); out: -if (pages) { -for (i =0 ; i < nr_pages; i++) -__free_page (pages[i]); -kfree (pages); - } +if (pagelist) +ceph_pagelist_release (pagelist);return err; }Signature · 6 lines
1.9.3 -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/3 ceph: include the initial ACL in create/mkdir/mknod MDS requests
In reply to Yan, ZhengCurrent code set new file/directory's initial ACL in a non-atomic manner.
Client first sends request to MDS to create new file/directory, then set the initial ACL after the new file/directory is successfully created.
The fix is include the initial ACL in create/mkdir/mknod MDS requests. So MDS can handle creating file/directory and setting the initial ACL in one request.
--- fs/ceph/acl.c | 125 ++++++++++++++++++++++++++++++++++++++++++++------------ fs/ceph/dir.c | 41 ++++++++++++++----- fs/ceph/file.c | 27 +++++++++--- fs/ceph/super.h | 24 ++++++++--- 4 files changed, 170 insertions(+), 47 deletions(-)
fs/ceph/acl.c +99 -26
@@ -169,36 +169,109 @@ out:return ret; } -int ceph_init_acl (struct dentry *dentry,struct inode *inode,struct inode *dir) +int ceph_pre_init_acls (struct inode *dir,umode_t *mode, +struct ceph_acls_info *info) { -struct posix_acl *default_acl, *acl; -umode_t new_mode = inode->i_mode; -int error; - - error =posix_acl_create (dir, &new_mode, &default_acl, &acl); -if (error) -return error; - -if (!default_acl && !acl) { -cache_no_acl (inode); -if (new_mode != inode->i_mode) { -struct iattr newattrs = { - .ia_mode = new_mode, - .ia_valid =ATTR_MODE , - }; - error =ceph_setattr (dentry, &newattrs); +struct posix_acl *acl, *default_acl; +size_t val_size1 =0 , val_size2 =0 ; +struct ceph_pagelist *pagelist =NULL ; +void *tmp_buf =NULL ; +int err; + + err =posix_acl_create (dir, mode, &default_acl, &acl); +if (err) +return err; + +if (acl) { +int ret =posix_acl_equiv_mode (acl, mode); +if (ret <0 ) + goto out_err; +if (ret ==0 ) { +posix_acl_release (acl); + acl =NULL ; } -return error; } -if (default_acl) { - error =ceph_set_acl (inode, default_acl,ACL_TYPE_DEFAULT ); -posix_acl_release (default_acl); - } +if (!default_acl && !acl) +return 0 ; + +if (acl) + val_size1 =posix_acl_xattr_size (acl->a_count); +if (default_acl) + val_size2 =posix_acl_xattr_size (default_acl->a_count); + + err = -ENOMEM ; + tmp_buf =kmalloc (max (val_size1, val_size2),GFP_NOFS ); +if (!tmp_buf) + goto out_err; + pagelist =kmalloc (sizeof (struct ceph_pagelist ),GFP_NOFS ); +if (!pagelist) + goto out_err; +ceph_pagelist_init (pagelist); + + err =ceph_pagelist_reserve (pagelist,PAGE_SIZE ); +if (err) + goto out_err; + +ceph_pagelist_encode_32 (pagelist, acl && default_acl ?2 :1 ); +if (acl) { -if (!error) - error =ceph_set_acl (inode, acl,ACL_TYPE_ACCESS ); -posix_acl_release (acl); +size_t len =strlen (POSIX_ACL_XATTR_ACCESS ); + err =ceph_pagelist_reserve (pagelist, len + val_size1 +8 ); +if (err) + goto out_err; +ceph_pagelist_encode_string (pagelist,POSIX_ACL_XATTR_ACCESS , + len); + err =posix_acl_to_xattr (&init_user_ns, acl, + tmp_buf, val_size1); +if (err <0 ) + goto out_err; +ceph_pagelist_encode_32 (pagelist, val_size1); +ceph_pagelist_append (pagelist, tmp_buf, val_size1); } -return error; +if (default_acl) { +size_t len =strlen (POSIX_ACL_XATTR_DEFAULT ); + err =ceph_pagelist_reserve (pagelist, len + val_size2 +8 ); +if (err) + goto out_err; + err =ceph_pagelist_encode_string (pagelist, +POSIX_ACL_XATTR_DEFAULT , len); + err =posix_acl_to_xattr (&init_user_ns, default_acl, + tmp_buf, val_size2); +if (err <0 ) + goto out_err; +ceph_pagelist_encode_32 (pagelist, val_size2); +ceph_pagelist_append (pagelist, tmp_buf, val_size2); + } + +kfree (tmp_buf); + + info->acl = acl; + info->default_acl = default_acl; + info->pagelist = pagelist; +return 0 ; + +out_err: +posix_acl_release (acl); +posix_acl_release (default_acl); +kfree (tmp_buf); +if (pagelist) +ceph_pagelist_release (pagelist); +return err; +} + +void ceph_init_inode_acls (struct inode * inode,struct ceph_acls_info *info) +{ +if (!inode) +return ; +ceph_set_cached_acl (inode,ACL_TYPE_ACCESS , info->acl); +ceph_set_cached_acl (inode,ACL_TYPE_DEFAULT , info->default_acl); +} + +void ceph_release_acls_info (struct ceph_acls_info *info) +{ +posix_acl_release (info->acl); +posix_acl_release (info->default_acl); +if (info->pagelist) +ceph_pagelist_release (info->pagelist); }
fs/ceph/dir.c +31 -10
107 lines not on this page · raw message
fs/ceph/file.c +21 -6
@@ -235,6 +235,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,struct ceph_mds_client *mdsc = fsc->mdsc;struct ceph_mds_request *req;struct dentry *dn; +struct ceph_acls_info acls = {};int err; dout("atomic_open %p dentry %p '%.*s' %s flags %d mode 0%o\n",
@@ -248,22 +249,34 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,if (err <0 )return err; +if (flags &O_CREAT ) { + err =ceph_pre_init_acls (dir, &mode, &acls); +if (err <0 ) +return err; + } +/* do the open */ req =prepare_open_request (dir->i_sb, flags, mode); -if (IS_ERR (req)) -return PTR_ERR (req); +if (IS_ERR (req)) { + err =PTR_ERR (req); + goto out_acl; + } req->r_dentry =dget (dentry); req->r_num_caps =2 ;if (flags &O_CREAT ) { req->r_dentry_drop =CEPH_CAP_FILE_SHARED ; req->r_dentry_unless =CEPH_CAP_FILE_EXCL ; +if (acls.pagelist) { + req->r_pagelist = acls.pagelist; + acls.pagelist =NULL ; + } } req->r_locked_dir = dir;/* caller holds dir->i_mutex */ err =ceph_mdsc_do_request (mdsc, (flags & (O_CREAT |O_TRUNC )) ? dir :NULL , req);if (err) - goto out_err; + goto out_req; err =ceph_handle_snapdir (req, dentry, err);if (err ==0 && (flags &O_CREAT ) && !req->r_reply_info.head->is_dentry)
@@ -278,7 +291,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, dn =NULL ; }if (err) - goto out_err; + goto out_req;if (dn || dentry->d_inode ==NULL ||S_ISLNK (dentry->d_inode->i_mode)) {/* make vfs retry on splice, ENOENT, or symlink */ dout ("atomic_open finish_no_open on dn %p\n" , dn);
@@ -286,15 +299,17 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, }else {dout ("atomic_open finish_open on dn %p\n" , dn);if (req->r_op ==CEPH_MDS_OP_CREATE && req->r_reply_info.has_create_ino) { -ceph_init_acl (dentry, dentry->d_inode, dir); +ceph_init_inode_acls (dentry->d_inode, &acls); *opened |=FILE_CREATED ; } err =finish_open (file, dentry, ceph_open, opened); } -out_err: +out_req:if (!req->r_err && req->r_target_inode)ceph_put_fmode (ceph_inode (req->r_target_inode), req->r_fmode);ceph_mdsc_put_request (req); +out_acl: +ceph_release_acls_info (&acls);dout ("atomic_open result=%d\n" , err);return err; }
fs/ceph/super.h +19 -5
@@ -733,15 +733,23 @@ extern void __ceph_build_xattrs_blob(struct ceph_inode_info *ci);extern void __ceph_destroy_xattrs (struct ceph_inode_info *ci);extern void __init ceph_xattr_init (void );extern void ceph_xattr_exit (void ); +extern const struct xattr_handler *ceph_xattr_handlers[];/* acl.c */ -extern const struct xattr_handler *ceph_xattr_handlers[]; +struct ceph_acls_info { +void *default_acl; +void *acl; +struct ceph_pagelist *pagelist; +};#ifdef CONFIG_CEPH_FS_POSIX_ACL struct posix_acl *ceph_get_acl (struct inode *,int );int ceph_set_acl (struct inode *inode,struct posix_acl *acl,int type); -int ceph_init_acl (struct dentry *,struct inode *,struct inode *); +int ceph_pre_init_acls (struct inode *dir,umode_t *mode, +struct ceph_acls_info *info); +void ceph_init_inode_acls (struct inode *inode,struct ceph_acls_info *info); +void ceph_release_acls_info (struct ceph_acls_info *info);static inline void ceph_forget_all_cached_acls (struct inode *inode) {
@@ -753,12 +761,18 @@ static inline void ceph_forget_all_cached_acls(struct inode *inode)#define ceph_get_acl NULL#define ceph_set_acl NULL -static inline int ceph_init_acl (struct dentry *dentry,struct inode *inode, -struct inode *dir) +static inline int ceph_pre_init_acls (struct inode *dir,umode_t *mode, +struct ceph_acls_info *info) {return 0 ; } - +static inline void ceph_init_inode_acls (struct inode *inode, +struct ceph_acls_info *info) +{ +} +static inline void ceph_release_acls_info (struct ceph_acls_info *info) +{ +}static inline int ceph_acl_chmod (struct dentry *dentry,struct inode *inode) {return 0 ;
Signature · 1 line
1.9.3
Re: [PATCH 3/3] ceph: include the initial ACL in create/mkdir/mknod MDS requests
Quoted 10 lines · Zheng
Current code set new file/directory's initial ACL in a non-atomic manner.
Client first sends request to MDS to create new file/directory, then set the initial ACL after the new file/directory is successfully created.The fix is include the initial ACL in create/mkdir/mknod MDS requests. So MDS can handle creating file/directory and setting the initial ACL in one request.
Signed-off-by Yan, Zheng <[email protected]>
Quoted 405 lines
--- fs/ceph/acl.c | 125 ++++++++++++++++++++++++++++++++++++++++++++------------ fs/ceph/dir.c | 41 ++++++++++++++----- fs/ceph/file.c | 27 +++++++++--- fs/ceph/super.h | 24 ++++++++--- 4 files changed, 170 insertions(+), 47 deletions(-)fs/ceph/acl.c +99
-26@@ -169,36 +169,109 @@ out:return ret; } -int ceph_init_acl (struct dentry *dentry,struct inode *inode,struct inode *dir) +int ceph_pre_init_acls (struct inode *dir,umode_t *mode, +struct ceph_acls_info *info) { -struct posix_acl *default_acl, *acl; -umode_t new_mode = inode->i_mode; -int error; - - error =posix_acl_create (dir, &new_mode, &default_acl, &acl); -if (error) -return error; - -if (!default_acl && !acl) { -cache_no_acl (inode); -if (new_mode != inode->i_mode) { -struct iattr newattrs = { - .ia_mode = new_mode, - .ia_valid =ATTR_MODE , - }; - error =ceph_setattr (dentry, &newattrs); +struct posix_acl *acl, *default_acl; +size_t val_size1 =0 , val_size2 =0 ; +struct ceph_pagelist *pagelist =NULL ; +void *tmp_buf =NULL ; +int err; + + err =posix_acl_create (dir, mode, &default_acl, &acl); +if (err) +return err; + +if (acl) { +int ret =posix_acl_equiv_mode (acl, mode); +if (ret <0 ) + goto out_err; +if (ret ==0 ) { +posix_acl_release (acl); + acl =NULL ; } -return error; } -if (default_acl) { - error =ceph_set_acl (inode, default_acl,ACL_TYPE_DEFAULT ); -posix_acl_release (default_acl); - } +if (!default_acl && !acl) +return 0 ; + +if (acl) + val_size1 =posix_acl_xattr_size (acl->a_count); +if (default_acl) + val_size2 =posix_acl_xattr_size (default_acl->a_count); + + err = -ENOMEM ; + tmp_buf =kmalloc (max (val_size1, val_size2),GFP_NOFS ); +if (!tmp_buf) + goto out_err; + pagelist =kmalloc (sizeof (struct ceph_pagelist ),GFP_NOFS ); +if (!pagelist) + goto out_err; +ceph_pagelist_init (pagelist); + + err =ceph_pagelist_reserve (pagelist,PAGE_SIZE ); +if (err) + goto out_err; + +ceph_pagelist_encode_32 (pagelist, acl && default_acl ?2 :1 ); +if (acl) { -if (!error) - error =ceph_set_acl (inode, acl,ACL_TYPE_ACCESS ); -posix_acl_release (acl); +size_t len =strlen (POSIX_ACL_XATTR_ACCESS ); + err =ceph_pagelist_reserve (pagelist, len + val_size1 +8 ); +if (err) + goto out_err; +ceph_pagelist_encode_string (pagelist,POSIX_ACL_XATTR_ACCESS , + len); + err =posix_acl_to_xattr (&init_user_ns, acl, + tmp_buf, val_size1); +if (err <0 ) + goto out_err; +ceph_pagelist_encode_32 (pagelist, val_size1); +ceph_pagelist_append (pagelist, tmp_buf, val_size1); } -return error; +if (default_acl) { +size_t len =strlen (POSIX_ACL_XATTR_DEFAULT ); + err =ceph_pagelist_reserve (pagelist, len + val_size2 +8 ); +if (err) + goto out_err; + err =ceph_pagelist_encode_string (pagelist, +POSIX_ACL_XATTR_DEFAULT , len); + err =posix_acl_to_xattr (&init_user_ns, default_acl, + tmp_buf, val_size2); +if (err <0 ) + goto out_err; +ceph_pagelist_encode_32 (pagelist, val_size2); +ceph_pagelist_append (pagelist, tmp_buf, val_size2); + } + +kfree (tmp_buf); + + info->acl = acl; + info->default_acl = default_acl; + info->pagelist = pagelist; +return 0 ; + +out_err: +posix_acl_release (acl); +posix_acl_release (default_acl); +kfree (tmp_buf); +if (pagelist) +ceph_pagelist_release (pagelist); +return err; +} + +void ceph_init_inode_acls (struct inode * inode,struct ceph_acls_info *info) +{ +if (!inode) +return ; +ceph_set_cached_acl (inode,ACL_TYPE_ACCESS , info->acl); +ceph_set_cached_acl (inode,ACL_TYPE_DEFAULT , info->default_acl); +} + +void ceph_release_acls_info (struct ceph_acls_info *info) +{ +posix_acl_release (info->acl); +posix_acl_release (info->default_acl); +if (info->pagelist) +ceph_pagelist_release (info->pagelist); }fs/ceph/dir.c +31
-10@@ -682,17 +682,22 @@ static int ceph_mknod(struct inode *dir, struct dentry *dentry,struct ceph_fs_client *fsc =ceph_sb_to_client (dir->i_sb);struct ceph_mds_client *mdsc = fsc->mdsc;struct ceph_mds_request *req; +struct ceph_acls_info acls = {};int err;if (ceph_snap (dir) !=CEPH_NOSNAP )return -EROFS ; + err =ceph_pre_init_acls (dir, &mode, &acls); +if (err <0 ) +return err; +dout ("mknod in dir %p dentry %p mode 0%ho rdev %d\n" , dir, dentry, mode, rdev); req =ceph_mdsc_create_request (mdsc,CEPH_MDS_OP_MKNOD ,USE_AUTH_MDS );if (IS_ERR (req)) { -d_drop (dentry); -return PTR_ERR (req); + err =PTR_ERR (req); + goto out; } req->r_dentry =dget (dentry); req->r_num_caps =2 ;@@ -701,15 +706,20 @@ static int ceph_mknod(struct inode *dir, struct dentry *dentry, req->r_args.mknod.rdev =cpu_to_le32 (rdev); req->r_dentry_drop =CEPH_CAP_FILE_SHARED ; req->r_dentry_unless =CEPH_CAP_FILE_EXCL ; +if (acls.pagelist) { + req->r_pagelist = acls.pagelist; + acls.pagelist =NULL ; + } err =ceph_mdsc_do_request (mdsc, dir, req);if (!err && !req->r_reply_info.head->is_dentry) err =ceph_handle_notrace_create (dir, dentry);ceph_mdsc_put_request (req); - +out:if (!err) -ceph_init_acl (dentry, dentry->d_inode, dir); +ceph_init_inode_acls (dentry->d_inode, &acls);else d_drop (dentry); +ceph_release_acls_info (&acls);return err; }@@ -733,8 +743,8 @@ static int ceph_symlink(struct inode *dir, struct dentry *dentry,dout ("symlink in dir %p dentry %p to '%s'\n" , dir, dentry, dest); req =ceph_mdsc_create_request (mdsc,CEPH_MDS_OP_SYMLINK ,USE_AUTH_MDS );if (IS_ERR (req)) { -d_drop (dentry); -return PTR_ERR (req); + err =PTR_ERR (req); + goto out; } req->r_dentry =dget (dentry); req->r_num_caps =2 ;@@ -746,9 +756,8 @@ static int ceph_symlink(struct inode *dir, struct dentry *dentry,if (!err && !req->r_reply_info.head->is_dentry) err =ceph_handle_notrace_create (dir, dentry);ceph_mdsc_put_request (req); -if (!err) -ceph_init_acl (dentry, dentry->d_inode, dir); -else +out: +if (err)d_drop (dentry);return err; }@@ -758,6 +767,7 @@ static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)struct ceph_fs_client *fsc =ceph_sb_to_client (dir->i_sb);struct ceph_mds_client *mdsc = fsc->mdsc;struct ceph_mds_request *req; +struct ceph_acls_info acls = {};int err = -EROFS ;int op;@@ -772,6 +782,12 @@ static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) }else { goto out; } + + mode |=S_IFDIR ; + err =ceph_pre_init_acls (dir, &mode, &acls); +if (err <0 ) + goto out; + req =ceph_mdsc_create_request (mdsc, op,USE_AUTH_MDS );if (IS_ERR (req)) { err =PTR_ERR (req);@@ -784,15 +800,20 @@ static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) req->r_args.mkdir.mode =cpu_to_le32 (mode); req->r_dentry_drop =CEPH_CAP_FILE_SHARED ; req->r_dentry_unless =CEPH_CAP_FILE_EXCL ; +if (acls.pagelist) { + req->r_pagelist = acls.pagelist; + acls.pagelist =NULL ; + } err =ceph_mdsc_do_request (mdsc, dir, req);if (!err && !req->r_reply_info.head->is_dentry) err =ceph_handle_notrace_create (dir, dentry);ceph_mdsc_put_request (req); out:if (!err) -ceph_init_acl (dentry, dentry->d_inode, dir); +ceph_init_inode_acls (dentry->d_inode, &acls);else d_drop (dentry); +ceph_release_acls_info (&acls);return err; }fs/ceph/file.c +21
-6@@ -235,6 +235,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,struct ceph_mds_client *mdsc = fsc->mdsc;struct ceph_mds_request *req;struct dentry *dn; +struct ceph_acls_info acls = {};int err; dout("atomic_open %p dentry %p '%.*s' %s flags %d mode 0%o\n",@@ -248,22 +249,34 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,if (err <0 )return err; +if (flags &O_CREAT ) { + err =ceph_pre_init_acls (dir, &mode, &acls); +if (err <0 ) +return err; + } +/* do the open */ req =prepare_open_request (dir->i_sb, flags, mode); -if (IS_ERR (req)) -return PTR_ERR (req); +if (IS_ERR (req)) { + err =PTR_ERR (req); + goto out_acl; + } req->r_dentry =dget (dentry); req->r_num_caps =2 ;if (flags &O_CREAT ) { req->r_dentry_drop =CEPH_CAP_FILE_SHARED ; req->r_dentry_unless =CEPH_CAP_FILE_EXCL ; +if (acls.pagelist) { + req->r_pagelist = acls.pagelist; + acls.pagelist =NULL ; + } } req->r_locked_dir = dir;/* caller holds dir->i_mutex */ err =ceph_mdsc_do_request (mdsc, (flags & (O_CREAT |O_TRUNC )) ? dir :NULL , req);if (err) - goto out_err; + goto out_req; err =ceph_handle_snapdir (req, dentry, err);if (err ==0 && (flags &O_CREAT ) && !req->r_reply_info.head->is_dentry)@@ -278,7 +291,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, dn =NULL ; }if (err) - goto out_err; + goto out_req;if (dn || dentry->d_inode ==NULL ||S_ISLNK (dentry->d_inode->i_mode)) {/* make vfs retry on splice, ENOENT, or symlink */ dout ("atomic_open finish_no_open on dn %p\n" , dn);@@ -286,15 +299,17 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, }else {dout ("atomic_open finish_open on dn %p\n" , dn);if (req->r_op ==CEPH_MDS_OP_CREATE && req->r_reply_info.has_create_ino) { -ceph_init_acl (dentry, dentry->d_inode, dir); +ceph_init_inode_acls (dentry->d_inode, &acls); *opened |=FILE_CREATED ; } err =finish_open (file, dentry, ceph_open, opened); } -out_err: +out_req:if (!req->r_err && req->r_target_inode)ceph_put_fmode (ceph_inode (req->r_target_inode), req->r_fmode);ceph_mdsc_put_request (req); +out_acl: +ceph_release_acls_info (&acls);dout ("atomic_open result=%d\n" , err);return err; }fs/ceph/super.h +19
-5@@ -733,15 +733,23 @@ extern void __ceph_build_xattrs_blob(struct ceph_inode_info *ci);extern void __ceph_destroy_xattrs (struct ceph_inode_info *ci);extern void __init ceph_xattr_init (void );extern void ceph_xattr_exit (void ); +extern const struct xattr_handler *ceph_xattr_handlers[];/* acl.c */ -extern const struct xattr_handler *ceph_xattr_handlers[]; +struct ceph_acls_info { +void *default_acl; +void *acl; +struct ceph_pagelist *pagelist; +};#ifdef CONFIG_CEPH_FS_POSIX_ACL struct posix_acl *ceph_get_acl (struct inode *,int );int ceph_set_acl (struct inode *inode,struct posix_acl *acl,int type); -int ceph_init_acl (struct dentry *,struct inode *,struct inode *); +int ceph_pre_init_acls (struct inode *dir,umode_t *mode, +struct ceph_acls_info *info); +void ceph_init_inode_acls (struct inode *inode,struct ceph_acls_info *info); +void ceph_release_acls_info (struct ceph_acls_info *info);static inline void ceph_forget_all_cached_acls (struct inode *inode) {@@ -753,12 +761,18 @@ static inline void ceph_forget_all_cached_acls(struct inode *inode)#define ceph_get_acl NULL#define ceph_set_acl NULL -static inline int ceph_init_acl (struct dentry *dentry,struct inode *inode, -struct inode *dir) +static inline int ceph_pre_init_acls (struct inode *dir,umode_t *mode, +struct ceph_acls_info *info) {return 0 ; } - +static inline void ceph_init_inode_acls (struct inode *inode, +struct ceph_acls_info *info) +{ +} +static inline void ceph_release_acls_info (struct ceph_acls_info *info) +{ +}static inline int ceph_acl_chmod (struct dentry *dentry,struct inode *inode) {return 0 ;Signature · 6 lines
1.9.3 -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 3 lines · Zheng
this allow pagelist to present data that may be sent multiple times.
Signed-off-by Yan, Zheng <[email protected]>
Quoted 109 lines
--- fs/ceph/mds_client.c | 1 - include/linux/ceph/pagelist.h | 5 ++++- net/ceph/messenger.c | 4 +--- net/ceph/pagelist.c | 8 ++++++-- 4 files changed, 11 insertions(+), 7 deletions(-)fs/ceph/mds_client.c +0
-1@@ -2796,7 +2796,6 @@ fail:mutex_unlock (&session->s_mutex); fail_nomsg:ceph_pagelist_release (pagelist); -kfree (pagelist); fail_nopagelist:pr_err ("error %d preparing reconnect for mds%d\n" , err, mds);return ;include/linux/ceph/pagelist.h +4
-1@@ -2,6 +2,7 @@#define __FS_CEPH_PAGELIST_H#include <linux/list.h> +#include <linux/atomic.h> struct ceph_pagelist {struct list_head head;@@ -10,6 +11,7 @@ struct ceph_pagelist {size_t room;struct list_head free_list;size_t num_pages_free; +atomic_t refcnt; };struct ceph_pagelist_cursor {@@ -26,9 +28,10 @@ static inline void ceph_pagelist_init(struct ceph_pagelist *pl) pl->room =0 ;INIT_LIST_HEAD (&pl->free_list); pl->num_pages_free =0 ; +atomic_set (&pl->refcnt,1 ); } -extern int ceph_pagelist_release (struct ceph_pagelist *pl); +extern void ceph_pagelist_release (struct ceph_pagelist *pl);extern int ceph_pagelist_append (struct ceph_pagelist *pl,const void *d,size_t l);net/ceph/messenger.c +1
-3@@ -3071,10 +3071,8 @@ static void ceph_msg_data_destroy(struct ceph_msg_data *data)return ;WARN_ON (!list_empty (&data->links)); -if (data->type ==CEPH_MSG_DATA_PAGELIST ) { +if (data->type ==CEPH_MSG_DATA_PAGELIST )ceph_pagelist_release (data->pagelist); -kfree (data->pagelist); - }kmem_cache_free (ceph_msg_data_cache, data); }net/ceph/pagelist.c +6
-2@@ -1,5 +1,6 @@#include <linux/module.h> #include <linux/gfp.h> +#include <linux/slab.h> #include <linux/pagemap.h> #include <linux/highmem.h> #include <linux/ceph/pagelist.h> @@ -13,8 +14,10 @@ static void ceph_pagelist_unmap_tail(struct ceph_pagelist *pl) } } -int ceph_pagelist_release (struct ceph_pagelist *pl) +void ceph_pagelist_release (struct ceph_pagelist *pl) { +if (!atomic_dec_and_test (&pl->refcnt)) +return ;ceph_pagelist_unmap_tail (pl);while (!list_empty (&pl->head)) { struct page *page = list_first_entry(&pl->head, struct page,@@ -23,7 +26,8 @@ int ceph_pagelist_release(struct ceph_pagelist *pl)__free_page (page); }ceph_pagelist_free_reserve (pl); -return 0 ; +kfree (pl); +return ; }EXPORT_SYMBOL (ceph_pagelist_release);Signature · 6 lines
1.9.3 -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 1 line · Zheng
this allow pagelist to present data that may be sent multiple times.
Hmm, actually we probably should use the kref code for this, even though the refcounting is trivial.
sage
Quoted 111 lines
Signed-off-by Yan, Zheng <[email protected]>--- fs/ceph/mds_client.c | 1 - include/linux/ceph/pagelist.h | 5 ++++- net/ceph/messenger.c | 4 +--- net/ceph/pagelist.c | 8 ++++++-- 4 files changed, 11 insertions(+), 7 deletions(-)fs/ceph/mds_client.c +0
-1@@ -2796,7 +2796,6 @@ fail:mutex_unlock (&session->s_mutex); fail_nomsg:ceph_pagelist_release (pagelist); -kfree (pagelist); fail_nopagelist:pr_err ("error %d preparing reconnect for mds%d\n" , err, mds);return ;include/linux/ceph/pagelist.h +4
-1@@ -2,6 +2,7 @@#define __FS_CEPH_PAGELIST_H#include <linux/list.h> +#include <linux/atomic.h> struct ceph_pagelist {struct list_head head;@@ -10,6 +11,7 @@ struct ceph_pagelist {size_t room;struct list_head free_list;size_t num_pages_free; +atomic_t refcnt; };struct ceph_pagelist_cursor {@@ -26,9 +28,10 @@ static inline void ceph_pagelist_init(struct ceph_pagelist *pl) pl->room =0 ;INIT_LIST_HEAD (&pl->free_list); pl->num_pages_free =0 ; +atomic_set (&pl->refcnt,1 ); } -extern int ceph_pagelist_release (struct ceph_pagelist *pl); +extern void ceph_pagelist_release (struct ceph_pagelist *pl);extern int ceph_pagelist_append (struct ceph_pagelist *pl,const void *d,size_t l);net/ceph/messenger.c +1
-3@@ -3071,10 +3071,8 @@ static void ceph_msg_data_destroy(struct ceph_msg_data *data)return ;WARN_ON (!list_empty (&data->links)); -if (data->type ==CEPH_MSG_DATA_PAGELIST ) { +if (data->type ==CEPH_MSG_DATA_PAGELIST )ceph_pagelist_release (data->pagelist); -kfree (data->pagelist); - }kmem_cache_free (ceph_msg_data_cache, data); }net/ceph/pagelist.c +6
-2@@ -1,5 +1,6 @@#include <linux/module.h> #include <linux/gfp.h> +#include <linux/slab.h> #include <linux/pagemap.h> #include <linux/highmem.h> #include <linux/ceph/pagelist.h> @@ -13,8 +14,10 @@ static void ceph_pagelist_unmap_tail(struct ceph_pagelist *pl) } } -int ceph_pagelist_release (struct ceph_pagelist *pl) +void ceph_pagelist_release (struct ceph_pagelist *pl) { +if (!atomic_dec_and_test (&pl->refcnt)) +return ;ceph_pagelist_unmap_tail (pl);while (!list_empty (&pl->head)) { struct page *page = list_first_entry(&pl->head, struct page,@@ -23,7 +26,8 @@ int ceph_pagelist_release(struct ceph_pagelist *pl)__free_page (page); }ceph_pagelist_free_reserve (pl); -return 0 ; +kfree (pl); +return ; }EXPORT_SYMBOL (ceph_pagelist_release);Signature · 6 lines
1.9.3 -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html