MINOR: shctx: Add a maximum object size parameter.
This patch adds a new parameter to shctx_init() function to be used to
limit the size of each shared object, -1 value meaning "no limit".
diff --git a/src/shctx.c b/src/shctx.c
index 2a149a1..604fd7d 100644
--- a/src/shctx.c
+++ b/src/shctx.c
@@ -43,6 +43,13 @@
if (data_len > shctx->nbav * shctx->block_size)
goto out;
+ /* Check the object size limit. */
+ if (shctx->max_obj_size > 0) {
+ if ((first && first->len + data_len > shctx->max_obj_size) ||
+ (!first && data_len > shctx->max_obj_size))
+ goto out;
+ }
+
/* Note that <remain> is nul only if <first> is not nul. */
remain = 1;
if (first) {
@@ -284,7 +291,8 @@
* Returns: -1 on alloc failure, <maxblocks> if it performs context alloc,
* and 0 if cache is already allocated.
*/
-int shctx_init(struct shared_context **orig_shctx, int maxblocks, int blocksize, int extra, int shared)
+int shctx_init(struct shared_context **orig_shctx, int maxblocks, int blocksize,
+ int maxobjsz, int extra, int shared)
{
int i;
struct shared_context *shctx;
@@ -351,6 +359,7 @@
LIST_INIT(&shctx->hot);
shctx->block_size = blocksize;
+ shctx->max_obj_size = maxobjsz;
/* init the free blocks after the shared context struct */
cur = (void *)shctx + sizeof(struct shared_context) + extra;