mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-23 15:11:16 +00:00
ceph: simplify ceph_buffer interface
We never allocate the ceph_buffer and buffer separtely, so use a single constructor. Disallow put on NULL buffer; make the caller check. Signed-off-by: Sage Weil <sage@newdream.net>
This commit is contained in:
parent
dd26d857a7
commit
b6c1d5b81e
5 changed files with 35 additions and 29 deletions
|
@ -2,23 +2,38 @@
|
||||||
#include "ceph_debug.h"
|
#include "ceph_debug.h"
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
|
||||||
struct ceph_buffer *ceph_buffer_new(gfp_t gfp)
|
struct ceph_buffer *ceph_buffer_new(size_t len, gfp_t gfp)
|
||||||
{
|
{
|
||||||
struct ceph_buffer *b;
|
struct ceph_buffer *b;
|
||||||
|
|
||||||
b = kmalloc(sizeof(*b), gfp);
|
b = kmalloc(sizeof(*b), gfp);
|
||||||
if (!b)
|
if (!b)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
b->vec.iov_base = kmalloc(len, gfp | __GFP_NOWARN);
|
||||||
|
if (b->vec.iov_base) {
|
||||||
|
b->is_vmalloc = false;
|
||||||
|
} else {
|
||||||
|
b->vec.iov_base = __vmalloc(len, gfp, PAGE_KERNEL);
|
||||||
|
if (!b->vec.iov_base) {
|
||||||
|
kfree(b);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
b->is_vmalloc = true;
|
||||||
|
}
|
||||||
|
|
||||||
kref_init(&b->kref);
|
kref_init(&b->kref);
|
||||||
b->vec.iov_base = NULL;
|
b->alloc_len = len;
|
||||||
b->vec.iov_len = 0;
|
b->vec.iov_len = len;
|
||||||
b->alloc_len = 0;
|
dout("buffer_new %p\n", b);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ceph_buffer_release(struct kref *kref)
|
void ceph_buffer_release(struct kref *kref)
|
||||||
{
|
{
|
||||||
struct ceph_buffer *b = container_of(kref, struct ceph_buffer, kref);
|
struct ceph_buffer *b = container_of(kref, struct ceph_buffer, kref);
|
||||||
|
|
||||||
|
dout("buffer_release %p\n", b);
|
||||||
if (b->vec.iov_base) {
|
if (b->vec.iov_base) {
|
||||||
if (b->is_vmalloc)
|
if (b->is_vmalloc)
|
||||||
vfree(b->vec.iov_base);
|
vfree(b->vec.iov_base);
|
||||||
|
|
|
@ -20,8 +20,8 @@ struct ceph_buffer {
|
||||||
bool is_vmalloc;
|
bool is_vmalloc;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ceph_buffer *ceph_buffer_new(gfp_t gfp);
|
extern struct ceph_buffer *ceph_buffer_new(size_t len, gfp_t gfp);
|
||||||
int ceph_buffer_alloc(struct ceph_buffer *b, int len, gfp_t gfp);
|
extern void ceph_buffer_release(struct kref *kref);
|
||||||
|
|
||||||
static inline struct ceph_buffer *ceph_buffer_get(struct ceph_buffer *b)
|
static inline struct ceph_buffer *ceph_buffer_get(struct ceph_buffer *b)
|
||||||
{
|
{
|
||||||
|
@ -29,23 +29,9 @@ static inline struct ceph_buffer *ceph_buffer_get(struct ceph_buffer *b)
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ceph_buffer_release(struct kref *kref);
|
|
||||||
|
|
||||||
static inline void ceph_buffer_put(struct ceph_buffer *b)
|
static inline void ceph_buffer_put(struct ceph_buffer *b)
|
||||||
{
|
{
|
||||||
if (b)
|
|
||||||
kref_put(&b->kref, ceph_buffer_release);
|
kref_put(&b->kref, ceph_buffer_release);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline struct ceph_buffer *ceph_buffer_new_alloc(int len, gfp_t gfp)
|
|
||||||
{
|
|
||||||
struct ceph_buffer *b = ceph_buffer_new(gfp);
|
|
||||||
|
|
||||||
if (b && ceph_buffer_alloc(b, len, gfp) < 0) {
|
|
||||||
ceph_buffer_put(b);
|
|
||||||
b = NULL;
|
|
||||||
}
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -383,7 +383,9 @@ void ceph_destroy_inode(struct inode *inode)
|
||||||
}
|
}
|
||||||
|
|
||||||
__ceph_destroy_xattrs(ci);
|
__ceph_destroy_xattrs(ci);
|
||||||
|
if (ci->i_xattrs.blob)
|
||||||
ceph_buffer_put(ci->i_xattrs.blob);
|
ceph_buffer_put(ci->i_xattrs.blob);
|
||||||
|
if (ci->i_xattrs.prealloc_blob)
|
||||||
ceph_buffer_put(ci->i_xattrs.prealloc_blob);
|
ceph_buffer_put(ci->i_xattrs.prealloc_blob);
|
||||||
|
|
||||||
kmem_cache_free(ceph_inode_cachep, ci);
|
kmem_cache_free(ceph_inode_cachep, ci);
|
||||||
|
@ -526,7 +528,7 @@ static int fill_inode(struct inode *inode,
|
||||||
* bytes are the xattr count).
|
* bytes are the xattr count).
|
||||||
*/
|
*/
|
||||||
if (iinfo->xattr_len > 4) {
|
if (iinfo->xattr_len > 4) {
|
||||||
xattr_blob = ceph_buffer_new_alloc(iinfo->xattr_len, GFP_NOFS);
|
xattr_blob = ceph_buffer_new(iinfo->xattr_len, GFP_NOFS);
|
||||||
if (!xattr_blob)
|
if (!xattr_blob)
|
||||||
pr_err("fill_inode ENOMEM xattr blob %d bytes\n",
|
pr_err("fill_inode ENOMEM xattr blob %d bytes\n",
|
||||||
iinfo->xattr_len);
|
iinfo->xattr_len);
|
||||||
|
@ -715,6 +717,7 @@ no_change:
|
||||||
err = 0;
|
err = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
if (xattr_blob)
|
||||||
ceph_buffer_put(xattr_blob);
|
ceph_buffer_put(xattr_blob);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2047,7 +2047,7 @@ int ceph_alloc_middle(struct ceph_connection *con, struct ceph_msg *msg)
|
||||||
BUG_ON(!middle_len);
|
BUG_ON(!middle_len);
|
||||||
BUG_ON(msg->middle);
|
BUG_ON(msg->middle);
|
||||||
|
|
||||||
msg->middle = ceph_buffer_new_alloc(middle_len, GFP_NOFS);
|
msg->middle = ceph_buffer_new(middle_len, GFP_NOFS);
|
||||||
if (!msg->middle)
|
if (!msg->middle)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -482,6 +482,7 @@ void __ceph_build_xattrs_blob(struct ceph_inode_info *ci)
|
||||||
ci->i_xattrs.prealloc_blob->vec.iov_len =
|
ci->i_xattrs.prealloc_blob->vec.iov_len =
|
||||||
dest - ci->i_xattrs.prealloc_blob->vec.iov_base;
|
dest - ci->i_xattrs.prealloc_blob->vec.iov_base;
|
||||||
|
|
||||||
|
if (ci->i_xattrs.blob)
|
||||||
ceph_buffer_put(ci->i_xattrs.blob);
|
ceph_buffer_put(ci->i_xattrs.blob);
|
||||||
ci->i_xattrs.blob = ci->i_xattrs.prealloc_blob;
|
ci->i_xattrs.blob = ci->i_xattrs.prealloc_blob;
|
||||||
ci->i_xattrs.prealloc_blob = NULL;
|
ci->i_xattrs.prealloc_blob = NULL;
|
||||||
|
@ -745,10 +746,11 @@ retry:
|
||||||
|
|
||||||
spin_unlock(&inode->i_lock);
|
spin_unlock(&inode->i_lock);
|
||||||
dout(" preaallocating new blob size=%d\n", required_blob_size);
|
dout(" preaallocating new blob size=%d\n", required_blob_size);
|
||||||
blob = ceph_buffer_new_alloc(required_blob_size, GFP_NOFS);
|
blob = ceph_buffer_new(required_blob_size, GFP_NOFS);
|
||||||
if (!blob)
|
if (!blob)
|
||||||
goto out;
|
goto out;
|
||||||
spin_lock(&inode->i_lock);
|
spin_lock(&inode->i_lock);
|
||||||
|
if (ci->i_xattrs.prealloc_blob)
|
||||||
ceph_buffer_put(ci->i_xattrs.prealloc_blob);
|
ceph_buffer_put(ci->i_xattrs.prealloc_blob);
|
||||||
ci->i_xattrs.prealloc_blob = blob;
|
ci->i_xattrs.prealloc_blob = blob;
|
||||||
goto retry;
|
goto retry;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue