summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Mooney <patrick.f.mooney@gmail.com>2015-08-03 21:07:03 +0000
committerPatrick Mooney <patrick.f.mooney@gmail.com>2015-08-04 14:50:11 +0000
commit307a938260b178544e5468346c1a036e497c7dd0 (patch)
treeb74f7efe7b912a1605a24fdb8b2776d387aefc84
parentd344bb94c9dd0af3517b39e23cc0f252b1aa64e1 (diff)
downloadillumos-joyent-307a938260b178544e5468346c1a036e497c7dd0.tar.gz
OS-4590 lxbrand wants /proc/sys/vm/swappiness
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
-rw-r--r--usr/src/uts/common/brand/lx/procfs/lx_proc.h7
-rw-r--r--usr/src/uts/common/brand/lx/procfs/lx_prsubr.c7
-rw-r--r--usr/src/uts/common/brand/lx/procfs/lx_prvnops.c85
3 files changed, 73 insertions, 26 deletions
diff --git a/usr/src/uts/common/brand/lx/procfs/lx_proc.h b/usr/src/uts/common/brand/lx/procfs/lx_proc.h
index 20cb987974..f331e25db2 100644
--- a/usr/src/uts/common/brand/lx/procfs/lx_proc.h
+++ b/usr/src/uts/common/brand/lx/procfs/lx_proc.h
@@ -205,9 +205,10 @@ typedef enum lxpr_nodetype {
LXPR_SYS_KERNEL_RAND_BOOTID, /* /proc/sys/kernel/random/boot_id */
LXPR_SYS_KERNEL_SHMMAX, /* /proc/sys/kernel/shmmax */
LXPR_SYS_KERNEL_THREADS_MAX, /* /proc/sys/kernel/threads-max */
- LXPR_SYS_VMDIR, /* /proc/sys/vm */
- LXPR_SYS_KERNEL_VM_MINFR_KB, /* /proc/sys/vm/min_free_kbytes */
- LXPR_SYS_KERNEL_VM_NHUGEP, /* /proc/sys/vm/nr_hugepages */
+ LXPR_SYS_VMDIR, /* /proc/sys/vm */
+ LXPR_SYS_VM_MINFR_KB, /* /proc/sys/vm/min_free_kbytes */
+ LXPR_SYS_VM_NHUGEP, /* /proc/sys/vm/nr_hugepages */
+ LXPR_SYS_VM_SWAPPINESS, /* /proc/sys/vm/swappiness */
LXPR_UPTIME, /* /proc/uptime */
LXPR_VERSION, /* /proc/version */
LXPR_NFILES /* number of lx /proc file types */
diff --git a/usr/src/uts/common/brand/lx/procfs/lx_prsubr.c b/usr/src/uts/common/brand/lx/procfs/lx_prsubr.c
index c621406f92..bfc710a6e5 100644
--- a/usr/src/uts/common/brand/lx/procfs/lx_prsubr.c
+++ b/usr/src/uts/common/brand/lx/procfs/lx_prsubr.c
@@ -534,6 +534,13 @@ lxpr_getnode(vnode_t *dp, lxpr_nodetype_t type, proc_t *p, int desc)
lxpnp->lxpr_mode = 0400; /* read-only by owner only */
break;
+ case LXPR_SYS_VM_SWAPPINESS:
+ case LXPR_PID_OOM_SCR_ADJ:
+ case LXPR_PID_TID_OOM_SCR_ADJ:
+ vp->v_type = VREG;
+ lxpnp->lxpr_mode = 0644;
+ break;
+
default:
vp->v_type = VREG;
lxpnp->lxpr_mode = 0444; /* read-only by all */
diff --git a/usr/src/uts/common/brand/lx/procfs/lx_prvnops.c b/usr/src/uts/common/brand/lx/procfs/lx_prvnops.c
index 0cd07b0a4d..5d66a00b37 100644
--- a/usr/src/uts/common/brand/lx/procfs/lx_prvnops.c
+++ b/usr/src/uts/common/brand/lx/procfs/lx_prvnops.c
@@ -212,6 +212,7 @@ static void lxpr_read_sys_kernel_shmmax(lxpr_node_t *, lxpr_uiobuf_t *);
static void lxpr_read_sys_kernel_threads_max(lxpr_node_t *, lxpr_uiobuf_t *);
static void lxpr_read_sys_vm_minfr_kb(lxpr_node_t *, lxpr_uiobuf_t *);
static void lxpr_read_sys_vm_nhpages(lxpr_node_t *, lxpr_uiobuf_t *);
+static void lxpr_read_sys_vm_swappiness(lxpr_node_t *, lxpr_uiobuf_t *);
/*
* Simple conversion
@@ -329,7 +330,7 @@ static lxpr_dirent_t tiddir[] = {
{ LXPR_PID_MAPS, "maps" },
{ LXPR_PID_MEM, "mem" },
{ LXPR_PID_MOUNTINFO, "mountinfo" },
- { LXPR_PID_OOM_SCR_ADJ, "oom_score_adj" },
+ { LXPR_PID_TID_OOM_SCR_ADJ, "oom_score_adj" },
{ LXPR_PID_ROOTDIR, "root" },
{ LXPR_PID_TID_STAT, "stat" },
{ LXPR_PID_STATM, "statm" },
@@ -461,8 +462,9 @@ static lxpr_dirent_t sys_randdir[] = {
* contents of /proc/sys/vm directory
*/
static lxpr_dirent_t sys_vmdir[] = {
- { LXPR_SYS_KERNEL_VM_MINFR_KB, "min_free_kbytes" },
- { LXPR_SYS_KERNEL_VM_NHUGEP, "nr_hugepages" },
+ { LXPR_SYS_VM_MINFR_KB, "min_free_kbytes" },
+ { LXPR_SYS_VM_NHUGEP, "nr_hugepages" },
+ { LXPR_SYS_VM_SWAPPINESS, "swappiness" },
};
#define SYS_VMDIRFILES (sizeof (sys_vmdir) / sizeof (sys_vmdir[0]))
@@ -479,9 +481,17 @@ lxpr_open(vnode_t **vpp, int flag, cred_t *cr, caller_context_t *ct)
vnode_t *rvp;
int error = 0;
- /* Restrict writes to oom_score_adj for now */
- if (flag & FWRITE && type != LXPR_PID_OOM_SCR_ADJ)
- return (EPERM);
+ if (flag & FWRITE) {
+ /* Restrict writes to certain files */
+ switch (type) {
+ case LXPR_PID_OOM_SCR_ADJ:
+ case LXPR_PID_TID_OOM_SCR_ADJ:
+ case LXPR_SYS_VM_SWAPPINESS:
+ break;
+ default:
+ return (EPERM);
+ }
+ }
/*
* If we are opening an underlying file only allow regular files,
@@ -649,6 +659,7 @@ static void (*lxpr_read_function[LXPR_NFILES])() = {
lxpr_read_invalid, /* /proc/sys/vm */
lxpr_read_sys_vm_minfr_kb, /* /proc/sys/vm/min_free_kbytes */
lxpr_read_sys_vm_nhpages, /* /proc/sys/vm/nr_hugepages */
+ lxpr_read_sys_vm_swappiness, /* /proc/sys/vm/swappiness */
lxpr_read_uptime, /* /proc/uptime */
lxpr_read_version, /* /proc/version */
};
@@ -760,6 +771,7 @@ static vnode_t *(*lxpr_lookup_function[LXPR_NFILES])() = {
lxpr_lookup_sys_vmdir, /* /proc/sys/vm */
lxpr_lookup_not_a_dir, /* /proc/sys/vm/min_free_kbytes */
lxpr_lookup_not_a_dir, /* /proc/sys/vm/nr_hugepages */
+ lxpr_lookup_not_a_dir, /* /proc/sys/vm/swappiness */
lxpr_lookup_not_a_dir, /* /proc/uptime */
lxpr_lookup_not_a_dir, /* /proc/version */
};
@@ -871,6 +883,7 @@ static int (*lxpr_readdir_function[LXPR_NFILES])() = {
lxpr_readdir_sys_vmdir, /* /proc/sys/vm */
lxpr_readdir_not_a_dir, /* /proc/sys/vm/min_free_kbytes */
lxpr_readdir_not_a_dir, /* /proc/sys/vm/nr_hugepages */
+ lxpr_readdir_not_a_dir, /* /proc/sys/vm/swappiness */
lxpr_readdir_not_a_dir, /* /proc/uptime */
lxpr_readdir_not_a_dir, /* /proc/version */
};
@@ -3841,14 +3854,21 @@ lxpr_read_sys_kernel_threads_max(lxpr_node_t *lxpnp, lxpr_uiobuf_t *uiobuf)
static void
lxpr_read_sys_vm_minfr_kb(lxpr_node_t *lxpnp, lxpr_uiobuf_t *uiobuf)
{
- ASSERT(lxpnp->lxpr_type == LXPR_SYS_KERNEL_VM_MINFR_KB);
+ ASSERT(lxpnp->lxpr_type == LXPR_SYS_VM_MINFR_KB);
lxpr_uiobuf_printf(uiobuf, "%d\n", 0);
}
static void
lxpr_read_sys_vm_nhpages(lxpr_node_t *lxpnp, lxpr_uiobuf_t *uiobuf)
{
- ASSERT(lxpnp->lxpr_type == LXPR_SYS_KERNEL_VM_NHUGEP);
+ ASSERT(lxpnp->lxpr_type == LXPR_SYS_VM_NHUGEP);
+ lxpr_uiobuf_printf(uiobuf, "%d\n", 0);
+}
+
+static void
+lxpr_read_sys_vm_swappiness(lxpr_node_t *lxpnp, lxpr_uiobuf_t *uiobuf)
+{
+ ASSERT(lxpnp->lxpr_type == LXPR_SYS_VM_SWAPPINESS);
lxpr_uiobuf_printf(uiobuf, "%d\n", 0);
}
@@ -4273,12 +4293,21 @@ static int
lxpr_access(vnode_t *vp, int mode, int flags, cred_t *cr, caller_context_t *ct)
{
lxpr_node_t *lxpnp = VTOLXP(vp);
+ lxpr_nodetype_t type = lxpnp->lxpr_type;
int shift = 0;
proc_t *tp;
/* lx /proc is a read only file system */
- if (mode & VWRITE)
- return (EROFS);
+ if (mode & VWRITE) {
+ switch (type) {
+ case LXPR_SYS_VM_SWAPPINESS:
+ case LXPR_PID_OOM_SCR_ADJ:
+ case LXPR_PID_TID_OOM_SCR_ADJ:
+ break;
+ default:
+ return (EROFS);
+ }
+ }
/*
* If this is a restricted file, check access permissions.
@@ -5698,34 +5727,44 @@ lxpr_create(struct vnode *dvp, char *nm, struct vattr *vap,
return (EEXIST);
/*
- * We're currently restricting O_CREAT to the oom_score_adj file.
+ * We're currently restricting O_CREAT to:
+ * - /proc/<pid>/oom_score_adj
+ * - /proc/<pid>/task/<tid>/oom_score_adj
+ * - /proc/sys/vm/swappiness
*/
- if (strcmp(nm, "oom_score_adj") != 0)
- return (EPERM);
-
- if (type == LXPR_PIDDIR) {
+ if ((type == LXPR_PIDDIR || type == LXPR_PID_TASK_IDDIR) &&
+ strcmp(nm, "oom_score_adj") == 0) {
proc_t *p;
p = lxpr_lock(lxpnp->lxpr_pid);
- if (p != NULL)
+ if (p != NULL) {
vp = lxpr_lookup_common(dvp, nm, p, piddir,
PIDDIRFILES);
+ }
lxpr_unlock(p);
+ } else if (type == LXPR_SYS_VMDIR && strcmp(nm, "swappiness") == 0) {
+ vp = lxpr_lookup_common(dvp, nm, NULL, sys_vmdir,
+ SYS_VMDIRFILES);
}
- if (vp != NULL) { /* name found */
- /*
- * Creating an existing file, allow it for regular files.
- */
+ if (vp != NULL) {
+ /* Creating an existing file, allow it for regular files. */
if (vp->v_type == VDIR)
return (EISDIR);
+ /* confirm permissions against existing file */
+ if ((error = lxpr_access(vp, mode, 0, cred, ct)) != 0) {
+ VN_RELE(vp);
+ return (error);
+ }
+
*vpp = vp;
return (0);
}
/*
- * proc doesn't allow creation of additional, non-subsystem specific
- * files in a dir
+ * Linux proc does not allow creation of addition, non-subsystem
+ * specific files inside the hierarchy. ENOENT is tossed when such
+ * actions are attempted.
*/
- return (EPERM);
+ return (ENOENT);
}