Skip to content

Commit

Permalink
driver: ring_buf_size is now a module parameter
Browse files Browse the repository at this point in the history
sysdig-CLA-1.0-signed-off-by: Nicolas Vanheuverzwijn <[email protected]>
  • Loading branch information
nvanheuverzwijn committed Aug 5, 2020
1 parent 758bc8c commit 43905bd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
28 changes: 28 additions & 0 deletions driver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2628,10 +2628,38 @@ void sysdig_exit(void)
#endif
}

static int set_ring_buf_size(const char *val, const struct kernel_param *kp)
{
int n = 0, ret;

ret = kstrtoint(val, 10, &n);
if (ret != 0)
return -EINVAL;
else if (n < 2 * PAGE_SIZE) {
pr_err("Ring buffer size too small (%ld bytes, must be at least %ld bytes)\n",
(long)n,
(long)PAGE_SIZE * 2);
return -EINVAL;
}
else if (n / PAGE_SIZE * PAGE_SIZE != n) {
pr_err("Ring buffer size is not a multiple of the page size\n");
return -EINVAL;
}

return param_set_int(val, kp);
}

static const struct kernel_param_ops ring_buf_size_param_ops = {
.set = set_ring_buf_size,
.get = param_get_int,
};

module_init(sysdig_init);
module_exit(sysdig_exit);
module_param(max_consumers, uint, 0444);
MODULE_PARM_DESC(max_consumers, "Maximum number of consumers that can simultaneously open the devices");
module_param_cb(ring_buf_size, &ring_buf_size_param_ops, &ring_buf_size, 0660);
MODULE_PARM_DESC(ring_buf_size, "Size of the ring buffer containing syscall");
#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 20)
module_param(verbose, bool, 0444);
#endif
Expand Down
9 changes: 9 additions & 0 deletions userspace/libscap/scap.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,15 @@ scap_t* scap_open_live_int(char *error, int32_t *rc,
//
// Allocate the device descriptors.
//

FILE * fp = fopen("/sys/module/" SYSFS_NAME "/parameters/ring_buf_size", "r");
if (fp == NULL){
snprintf(error, SCAP_LASTERR_SIZE, "Could not read module parameter ring_buf_size at '/sys/module/" SYSFS_NAME "/parameters/ring_buf_size'");
*rc = SCAP_FAILURE;
return NULL;
}
fscanf(fp, "%d", &ring_buf_size);

len = ring_buf_size * 2;

for(j = 0, all_scanned_devs = 0; j < handle->m_ndevs && all_scanned_devs < handle->m_ncpus; ++all_scanned_devs)
Expand Down

0 comments on commit 43905bd

Please sign in to comment.