Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 105970
b: refs/heads/master
c: 9eefe52
h: refs/heads/master
v: v3
  • Loading branch information
Nadia Derbey authored and Linus Torvalds committed Jul 25, 2008
1 parent ac800cd commit 920b24d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 20 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f1a43f93f0f3bab418800eaccb9e2e3b5427e173
refs/heads/master: 9eefe520c814f6f62c5d36a2ddcd3fb99dfdb30e
3 changes: 2 additions & 1 deletion trunk/include/linux/ipc_namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct ipc_namespace {
int msg_ctlmni;
atomic_t msg_bytes;
atomic_t msg_hdrs;
int auto_msgmni;

size_t shm_ctlmax;
size_t shm_ctlall;
Expand All @@ -53,7 +54,7 @@ extern atomic_t nr_ipc_ns;

extern int register_ipcns_notifier(struct ipc_namespace *);
extern int cond_register_ipcns_notifier(struct ipc_namespace *);
extern int unregister_ipcns_notifier(struct ipc_namespace *);
extern void unregister_ipcns_notifier(struct ipc_namespace *);
extern int ipcns_notify(unsigned long);

#else /* CONFIG_SYSVIPC */
Expand Down
72 changes: 59 additions & 13 deletions trunk/ipc/ipc_sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ static void *get_ipc(ctl_table *table)
}

/*
* Routine that is called when a tunable has successfully been changed by
* hand and it has a callback routine registered on the ipc namespace notifier
* chain: we don't want such tunables to be recomputed anymore upon memory
* add/remove or ipc namespace creation/removal.
* They can come back to a recomputable state by being set to a <0 value.
* Routine that is called when the file "auto_msgmni" has successfully been
* written.
* Two values are allowed:
* 0: unregister msgmni's callback routine from the ipc namespace notifier
* chain. This means that msgmni won't be recomputed anymore upon memory
* add/remove or ipc namespace creation/removal.
* 1: register back the callback routine.
*/
static void tunable_set_callback(int val)
static void ipc_auto_callback(int val)
{
if (val >= 0)
if (!val)
unregister_ipcns_notifier(current->nsproxy->ipc_ns);
else {
/*
Expand Down Expand Up @@ -71,7 +73,12 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
rc = proc_dointvec(&ipc_table, write, filp, buffer, lenp, ppos);

if (write && !rc && lenp_bef == *lenp)
tunable_set_callback(*((int *)(ipc_table.data)));
/*
* Tunable has successfully been changed by hand. Disable its
* automatic adjustment. This simply requires unregistering
* the notifiers that trigger recalculation.
*/
unregister_ipcns_notifier(current->nsproxy->ipc_ns);

return rc;
}
Expand All @@ -87,10 +94,39 @@ static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
lenp, ppos);
}

static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
{
struct ctl_table ipc_table;
size_t lenp_bef = *lenp;
int oldval;
int rc;

memcpy(&ipc_table, table, sizeof(ipc_table));
ipc_table.data = get_ipc(table);
oldval = *((int *)(ipc_table.data));

rc = proc_dointvec_minmax(&ipc_table, write, filp, buffer, lenp, ppos);

if (write && !rc && lenp_bef == *lenp) {
int newval = *((int *)(ipc_table.data));
/*
* The file "auto_msgmni" has correctly been set.
* React by (un)registering the corresponding tunable, if the
* value has changed.
*/
if (newval != oldval)
ipc_auto_callback(newval);
}

return rc;
}

#else
#define proc_ipc_doulongvec_minmax NULL
#define proc_ipc_dointvec NULL
#define proc_ipc_callback_dointvec NULL
#define proc_ipcauto_dointvec_minmax NULL
#endif

#ifdef CONFIG_SYSCTL_SYSCALL
Expand Down Expand Up @@ -142,14 +178,11 @@ static int sysctl_ipc_registered_data(ctl_table *table, int __user *name,
rc = sysctl_ipc_data(table, name, nlen, oldval, oldlenp, newval,
newlen);

if (newval && newlen && rc > 0) {
if (newval && newlen && rc > 0)
/*
* Tunable has successfully been changed from userland
*/
int *data = get_ipc(table);

tunable_set_callback(*data);
}
unregister_ipcns_notifier(current->nsproxy->ipc_ns);

return rc;
}
Expand All @@ -158,6 +191,9 @@ static int sysctl_ipc_registered_data(ctl_table *table, int __user *name,
#define sysctl_ipc_registered_data NULL
#endif

static int zero;
static int one = 1;

static struct ctl_table ipc_kern_table[] = {
{
.ctl_name = KERN_SHMMAX,
Expand Down Expand Up @@ -222,6 +258,16 @@ static struct ctl_table ipc_kern_table[] = {
.proc_handler = proc_ipc_dointvec,
.strategy = sysctl_ipc_data,
},
{
.ctl_name = CTL_UNNUMBERED,
.procname = "auto_msgmni",
.data = &init_ipc_ns.auto_msgmni,
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_ipcauto_dointvec_minmax,
.extra1 = &zero,
.extra2 = &one,
},
{}
};

Expand Down
20 changes: 15 additions & 5 deletions trunk/ipc/ipcns_notifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,35 @@ static int ipcns_callback(struct notifier_block *self,

int register_ipcns_notifier(struct ipc_namespace *ns)
{
int rc;

memset(&ns->ipcns_nb, 0, sizeof(ns->ipcns_nb));
ns->ipcns_nb.notifier_call = ipcns_callback;
ns->ipcns_nb.priority = IPCNS_CALLBACK_PRI;
return blocking_notifier_chain_register(&ipcns_chain, &ns->ipcns_nb);
rc = blocking_notifier_chain_register(&ipcns_chain, &ns->ipcns_nb);
if (!rc)
ns->auto_msgmni = 1;
return rc;
}

int cond_register_ipcns_notifier(struct ipc_namespace *ns)
{
int rc;

memset(&ns->ipcns_nb, 0, sizeof(ns->ipcns_nb));
ns->ipcns_nb.notifier_call = ipcns_callback;
ns->ipcns_nb.priority = IPCNS_CALLBACK_PRI;
return blocking_notifier_chain_cond_register(&ipcns_chain,
rc = blocking_notifier_chain_cond_register(&ipcns_chain,
&ns->ipcns_nb);
if (!rc)
ns->auto_msgmni = 1;
return rc;
}

int unregister_ipcns_notifier(struct ipc_namespace *ns)
void unregister_ipcns_notifier(struct ipc_namespace *ns)
{
return blocking_notifier_chain_unregister(&ipcns_chain,
&ns->ipcns_nb);
blocking_notifier_chain_unregister(&ipcns_chain, &ns->ipcns_nb);
ns->auto_msgmni = 0;
}

int ipcns_notify(unsigned long val)
Expand Down

0 comments on commit 920b24d

Please sign in to comment.