int lu_kmem_init(struct lu_kmem_descr *caches);
void lu_kmem_fini(struct lu_kmem_descr *caches);
-void lu_buf_free(struct lu_buf *buf);
-void lu_buf_alloc(struct lu_buf *buf, size_t size);
-void lu_buf_realloc(struct lu_buf *buf, size_t size);
-
-int lu_buf_check_and_grow(struct lu_buf *buf, size_t len);
-struct lu_buf *lu_buf_check_and_alloc(struct lu_buf *buf, size_t len);
-
extern __u32 lu_context_tags_default;
extern __u32 lu_session_tags_default;
}
lb_free:
- lu_buf_free(&buf);
+ kvfree(buf.lb_buf);
ldata_free:
kfree(ldata);
return rc;
int linkea_data_new(struct linkea_data *ldata, struct lu_buf *buf)
{
- ldata->ld_buf = lu_buf_check_and_alloc(buf, PAGE_SIZE);
- if (!ldata->ld_buf->lb_buf)
+ buf->lb_buf = kzalloc(PAGE_SIZE, GFP_NOFS);
+ if (!buf->lb_buf)
return -ENOMEM;
+ buf->lb_len = PAGE_SIZE;
+ ldata->ld_buf = buf;
ldata->ld_leh = ldata->ld_buf->lb_buf;
ldata->ld_leh->leh_magic = LINK_EA_MAGIC;
ldata->ld_leh->leh_len = sizeof(struct link_ea_header);
}
if (leh->leh_len + reclen > ldata->ld_buf->lb_len) {
- if (lu_buf_check_and_grow(ldata->ld_buf,
- leh->leh_len + reclen) < 0)
+ /* Note: this never happens as MAX_LINKEA_SIZE is 4096, while
+ * the initial allocation is PAGE_SIZE.
+ */
+ void *b = krealloc(ldata->ld_buf->lb_buf, leh->leh_len + reclen, GFP_NOFS);
+ if (!b)
return -ENOMEM;
- leh = ldata->ld_leh = ldata->ld_buf->lb_buf;
+ ldata->ld_buf->lb_len = leh->leh_len + reclen;
+ leh = ldata->ld_leh = ldata->ld_buf->lb_buf = b;
}
ldata->ld_lee = ldata->ld_buf->lb_buf + leh->leh_len;
}
}
EXPORT_SYMBOL(lu_kmem_fini);
-
-void lu_buf_free(struct lu_buf *buf)
-{
- LASSERT(buf);
- if (buf->lb_buf) {
- LASSERT(buf->lb_len > 0);
- kvfree(buf->lb_buf);
- buf->lb_buf = NULL;
- buf->lb_len = 0;
- }
-}
-EXPORT_SYMBOL(lu_buf_free);
-
-void lu_buf_alloc(struct lu_buf *buf, size_t size)
-{
- LASSERT(buf);
- LASSERT(!buf->lb_buf);
- LASSERT(!buf->lb_len);
- buf->lb_buf = libcfs_kvzalloc(size, GFP_NOFS);
- if (likely(buf->lb_buf))
- buf->lb_len = size;
-}
-EXPORT_SYMBOL(lu_buf_alloc);
-
-void lu_buf_realloc(struct lu_buf *buf, size_t size)
-{
- lu_buf_free(buf);
- lu_buf_alloc(buf, size);
-}
-EXPORT_SYMBOL(lu_buf_realloc);
-
-struct lu_buf *lu_buf_check_and_alloc(struct lu_buf *buf, size_t len)
-{
- if (!buf->lb_buf && !buf->lb_len)
- lu_buf_alloc(buf, len);
-
- if ((len > buf->lb_len) && buf->lb_buf)
- lu_buf_realloc(buf, len);
-
- return buf;
-}
-EXPORT_SYMBOL(lu_buf_check_and_alloc);
-
-/**
- * Increase the size of the \a buf.
- * preserves old data in buffer
- * old buffer remains unchanged on error
- * \retval 0 or -ENOMEM
- */
-int lu_buf_check_and_grow(struct lu_buf *buf, size_t len)
-{
- char *ptr;
-
- if (len <= buf->lb_len)
- return 0;
-
- ptr = libcfs_kvzalloc(len, GFP_NOFS);
- if (!ptr)
- return -ENOMEM;
-
- /* Free the old buf */
- if (buf->lb_buf) {
- memcpy(ptr, buf->lb_buf, buf->lb_len);
- kvfree(buf->lb_buf);
- }
-
- buf->lb_buf = ptr;
- buf->lb_len = len;
- return 0;
-}