Commit 549998b1 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

sysctl: Pass number of requests in argument

This saves memory.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent c8154faf
......@@ -7,7 +7,7 @@ struct sysctl_req {
int type;
};
extern int sysctl_op(struct sysctl_req *req, int op);
extern int sysctl_op(struct sysctl_req *req, size_t nr_req, int op);
enum {
CTL_READ,
......
......@@ -179,10 +179,9 @@ static int dump_ipc_msg_queue_messages(struct cr_img *img, const IpcMsgEntry *ms
int ret, msg_cnt = 0;
struct sysctl_req req[] = {
{ "kernel/msgmax", &msgmax, CTL_U32 },
{ },
};
ret = sysctl_op(req, CTL_READ);
ret = sysctl_op(req, ARRAY_SIZE(req), CTL_READ);
if (ret < 0) {
pr_err("Failed to read max IPC message size\n");
goto err;
......@@ -304,19 +303,17 @@ static int ipc_sysctl_req(IpcVarEntry *e, int op)
{ "kernel/shmall", &e->shm_ctlall, CTL_U64 },
{ "kernel/shmmni", &e->shm_ctlmni, CTL_U32 },
{ "kernel/shm_rmid_forced", &e->shm_rmid_forced, CTL_U32 },
{ },
};
struct sysctl_req req_mq[] = {
{ "fs/mqueue/queues_max", &e->mq_queues_max, CTL_U32 },
{ "fs/mqueue/msg_max", &e->mq_msg_max, CTL_U32 },
{ "fs/mqueue/msgsize_max", &e->mq_msgsize_max, CTL_U32 },
{ },
};
int ret;
ret = sysctl_op(req, op);
ret = sysctl_op(req, ARRAY_SIZE(req), op);
if (ret)
return ret;
......@@ -325,7 +322,7 @@ static int ipc_sysctl_req(IpcVarEntry *e, int op)
return 0;
}
return sysctl_op(req_mq, op);
return sysctl_op(req_mq, ARRAY_SIZE(req_mq), op);
}
/*
......@@ -555,11 +552,10 @@ static int prepare_ipc_sem_desc(struct cr_img *img, const IpcSemEntry *sem)
int ret, id;
struct sysctl_req req[] = {
{ "kernel/sem_next_id", &sem->desc->id, CTL_U32 },
{ },
};
struct semid_ds semid;
ret = sysctl_op(req, CTL_WRITE);
ret = sysctl_op(req, ARRAY_SIZE(req), CTL_WRITE);
if (ret < 0) {
pr_err("Failed to set desired IPC sem ID\n");
return ret;
......@@ -692,11 +688,10 @@ static int prepare_ipc_msg_queue(struct cr_img *img, const IpcMsgEntry *msq)
int ret, id;
struct sysctl_req req[] = {
{ "kernel/msg_next_id", &msq->desc->id, CTL_U32 },
{ },
};
struct msqid_ds msqid;
ret = sysctl_op(req, CTL_WRITE);
ret = sysctl_op(req, ARRAY_SIZE(req), CTL_WRITE);
if (ret < 0) {
pr_err("Failed to set desired IPC msg ID\n");
return ret;
......@@ -804,11 +799,10 @@ static int prepare_ipc_shm_seg(struct cr_img *img, const IpcShmEntry *shm)
int ret, id;
struct sysctl_req req[] = {
{ "kernel/shm_next_id", &shm->desc->id, CTL_U32 },
{ },
};
struct shmid_ds shmid;
ret = sysctl_op(req, CTL_WRITE);
ret = sysctl_op(req, ARRAY_SIZE(req), CTL_WRITE);
if (ret < 0) {
pr_err("Failed to set desired IPC shm ID\n");
return ret;
......
......@@ -198,14 +198,13 @@ static int tcp_read_sysctl_limits(void)
struct sysctl_req req[] = {
{ "net/ipv4/tcp_rmem", &vect[1], CTL_U32A(ARRAY_SIZE(vect[1])) },
{ },
};
/*
* Lets figure out which exactly amount of memory is
* availabe for send/read queues on restore.
*/
ret = sysctl_op(req, CTL_READ);
ret = sysctl_op(req, ARRAY_SIZE(req), CTL_READ);
if (ret) {
pr_warn("TCP mem sysctls are not available. Using defaults.\n");
goto out;
......@@ -250,10 +249,9 @@ static int get_last_cap(void)
{
struct sysctl_req req[] = {
{ "kernel/cap_last_cap", &kdat.last_cap, CTL_U32 },
{ },
};
return sysctl_op(req, CTL_READ);
return sysctl_op(req, ARRAY_SIZE(req), CTL_READ);
}
static bool kerndat_has_memfd_create(void)
......
......@@ -109,7 +109,7 @@ static int ipv4_conf_op(char *tgt, int *conf, int op, NetnsEntry **netns)
}
req[ri].name = NULL;
ret = sysctl_op(req, op);
ret = sysctl_op(req, ri ? ri - 1 : 0, op);
if (ret < 0) {
pr_err("Failed to %s %s/<confs>\n", (op == CTL_READ)?"read":"write", tgt);
return -1;
......
......@@ -166,7 +166,7 @@ static int __sysctl_op(int dir, struct sysctl_req *req, int op)
return ret;
}
int sysctl_op(struct sysctl_req *req, int op)
int sysctl_op(struct sysctl_req *req, size_t nr_req, int op)
{
int ret = 0;
int dir = -1;
......@@ -177,7 +177,7 @@ int sysctl_op(struct sysctl_req *req, int op)
return -1;
}
while (req->name) {
while (nr_req--) {
ret = __sysctl_op(dir, req, op);
if (ret < 0)
break;
......
......@@ -43,10 +43,9 @@ int prepare_utsns(int pid)
int ret;
struct cr_img *img;
UtsnsEntry *ue;
struct sysctl_req req[3] = {
struct sysctl_req req[] = {
{ "kernel/hostname" },
{ "kernel/domainname" },
{ },
};
img = open_image(CR_FD_UTSNS, O_RSTR, pid);
......@@ -62,7 +61,7 @@ int prepare_utsns(int pid)
req[1].arg = ue->domainname;
req[1].type = CTL_STR(strlen(ue->domainname));
ret = sysctl_op(req, CTL_WRITE);
ret = sysctl_op(req, ARRAY_SIZE(req), CTL_WRITE);
utsns_entry__free_unpacked(ue, NULL);
out:
close_image(img);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment