Commit 19b4946c authored by Mike Waychison's avatar Mike Waychison Committed by Linus Torvalds

[PATCH] ipc: convert /proc/sysvipc/* to generic seq_file interface

Change the /proc/sysvipc/shm|sem|msg files to use the generic seq_file
implementation for struct ipc_ids.
Signed-off-by: default avatarMike Waychison <mikew@google.com>
Cc: Manfred Spraul <manfred@colorfullife.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent ae781774
...@@ -77,6 +77,7 @@ struct msg_msg { ...@@ -77,6 +77,7 @@ struct msg_msg {
/* one msq_queue structure for each present queue on the system */ /* one msq_queue structure for each present queue on the system */
struct msg_queue { struct msg_queue {
struct kern_ipc_perm q_perm; struct kern_ipc_perm q_perm;
int q_id;
time_t q_stime; /* last msgsnd time */ time_t q_stime; /* last msgsnd time */
time_t q_rtime; /* last msgrcv time */ time_t q_rtime; /* last msgrcv time */
time_t q_ctime; /* last change time */ time_t q_ctime; /* last change time */
......
...@@ -88,6 +88,7 @@ struct sem { ...@@ -88,6 +88,7 @@ struct sem {
/* One sem_array data structure for each set of semaphores in the system. */ /* One sem_array data structure for each set of semaphores in the system. */
struct sem_array { struct sem_array {
struct kern_ipc_perm sem_perm; /* permissions .. see ipc.h */ struct kern_ipc_perm sem_perm; /* permissions .. see ipc.h */
int sem_id;
time_t sem_otime; /* last semop time */ time_t sem_otime; /* last semop time */
time_t sem_ctime; /* last change time */ time_t sem_ctime; /* last change time */
struct sem *sem_base; /* ptr to first semaphore in array */ struct sem *sem_base; /* ptr to first semaphore in array */
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/syscalls.h> #include <linux/syscalls.h>
#include <linux/audit.h> #include <linux/audit.h>
#include <linux/seq_file.h>
#include <asm/current.h> #include <asm/current.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include "util.h" #include "util.h"
...@@ -74,16 +75,16 @@ static struct ipc_ids msg_ids; ...@@ -74,16 +75,16 @@ static struct ipc_ids msg_ids;
static void freeque (struct msg_queue *msq, int id); static void freeque (struct msg_queue *msq, int id);
static int newque (key_t key, int msgflg); static int newque (key_t key, int msgflg);
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
static int sysvipc_msg_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data); static int sysvipc_msg_proc_show(struct seq_file *s, void *it);
#endif #endif
void __init msg_init (void) void __init msg_init (void)
{ {
ipc_init_ids(&msg_ids,msg_ctlmni); ipc_init_ids(&msg_ids,msg_ctlmni);
ipc_init_proc_interface("sysvipc/msg",
#ifdef CONFIG_PROC_FS " key msqid perms cbytes qnum lspid lrpid uid gid cuid cgid stime rtime ctime\n",
create_proc_read_entry("sysvipc/msg", 0, NULL, sysvipc_msg_read_proc, NULL); &msg_ids,
#endif sysvipc_msg_proc_show);
} }
static int newque (key_t key, int msgflg) static int newque (key_t key, int msgflg)
...@@ -113,6 +114,7 @@ static int newque (key_t key, int msgflg) ...@@ -113,6 +114,7 @@ static int newque (key_t key, int msgflg)
return -ENOSPC; return -ENOSPC;
} }
msq->q_id = msg_buildid(id,msq->q_perm.seq);
msq->q_stime = msq->q_rtime = 0; msq->q_stime = msq->q_rtime = 0;
msq->q_ctime = get_seconds(); msq->q_ctime = get_seconds();
msq->q_cbytes = msq->q_qnum = 0; msq->q_cbytes = msq->q_qnum = 0;
...@@ -123,7 +125,7 @@ static int newque (key_t key, int msgflg) ...@@ -123,7 +125,7 @@ static int newque (key_t key, int msgflg)
INIT_LIST_HEAD(&msq->q_senders); INIT_LIST_HEAD(&msq->q_senders);
msg_unlock(msq); msg_unlock(msq);
return msg_buildid(id,msq->q_perm.seq); return msq->q_id;
} }
static inline void ss_add(struct msg_queue* msq, struct msg_sender* mss) static inline void ss_add(struct msg_queue* msq, struct msg_sender* mss)
...@@ -808,55 +810,25 @@ out_unlock: ...@@ -808,55 +810,25 @@ out_unlock:
} }
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
static int sysvipc_msg_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data) static int sysvipc_msg_proc_show(struct seq_file *s, void *it)
{ {
off_t pos = 0; struct msg_queue *msq = it;
off_t begin = 0;
int i, len = 0; return seq_printf(s,
"%10d %10d %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %10lu %10lu %10lu\n",
down(&msg_ids.sem); msq->q_perm.key,
len += sprintf(buffer, " key msqid perms cbytes qnum lspid lrpid uid gid cuid cgid stime rtime ctime\n"); msq->q_id,
msq->q_perm.mode,
for(i = 0; i <= msg_ids.max_id; i++) { msq->q_cbytes,
struct msg_queue * msq; msq->q_qnum,
msq = msg_lock(i); msq->q_lspid,
if(msq != NULL) { msq->q_lrpid,
len += sprintf(buffer + len, "%10d %10d %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %10lu %10lu %10lu\n", msq->q_perm.uid,
msq->q_perm.key, msq->q_perm.gid,
msg_buildid(i,msq->q_perm.seq), msq->q_perm.cuid,
msq->q_perm.mode, msq->q_perm.cgid,
msq->q_cbytes, msq->q_stime,
msq->q_qnum, msq->q_rtime,
msq->q_lspid, msq->q_ctime);
msq->q_lrpid,
msq->q_perm.uid,
msq->q_perm.gid,
msq->q_perm.cuid,
msq->q_perm.cgid,
msq->q_stime,
msq->q_rtime,
msq->q_ctime);
msg_unlock(msq);
pos += len;
if(pos < offset) {
len = 0;
begin = pos;
}
if(pos > offset + length)
goto done;
}
}
*eof = 1;
done:
up(&msg_ids.sem);
*start = buffer + (offset - begin);
len -= (offset - begin);
if(len > length)
len = length;
if(len < 0)
len = 0;
return len;
} }
#endif #endif
...@@ -73,6 +73,7 @@ ...@@ -73,6 +73,7 @@
#include <linux/security.h> #include <linux/security.h>
#include <linux/syscalls.h> #include <linux/syscalls.h>
#include <linux/audit.h> #include <linux/audit.h>
#include <linux/seq_file.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include "util.h" #include "util.h"
...@@ -89,7 +90,7 @@ static struct ipc_ids sem_ids; ...@@ -89,7 +90,7 @@ static struct ipc_ids sem_ids;
static int newary (key_t, int, int); static int newary (key_t, int, int);
static void freeary (struct sem_array *sma, int id); static void freeary (struct sem_array *sma, int id);
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
static int sysvipc_sem_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data); static int sysvipc_sem_proc_show(struct seq_file *s, void *it);
#endif #endif
#define SEMMSL_FAST 256 /* 512 bytes on stack */ #define SEMMSL_FAST 256 /* 512 bytes on stack */
...@@ -116,10 +117,10 @@ void __init sem_init (void) ...@@ -116,10 +117,10 @@ void __init sem_init (void)
{ {
used_sems = 0; used_sems = 0;
ipc_init_ids(&sem_ids,sc_semmni); ipc_init_ids(&sem_ids,sc_semmni);
ipc_init_proc_interface("sysvipc/sem",
#ifdef CONFIG_PROC_FS " key semid perms nsems uid gid cuid cgid otime ctime\n",
create_proc_read_entry("sysvipc/sem", 0, NULL, sysvipc_sem_read_proc, NULL); &sem_ids,
#endif sysvipc_sem_proc_show);
} }
/* /*
...@@ -193,6 +194,7 @@ static int newary (key_t key, int nsems, int semflg) ...@@ -193,6 +194,7 @@ static int newary (key_t key, int nsems, int semflg)
} }
used_sems += nsems; used_sems += nsems;
sma->sem_id = sem_buildid(id, sma->sem_perm.seq);
sma->sem_base = (struct sem *) &sma[1]; sma->sem_base = (struct sem *) &sma[1];
/* sma->sem_pending = NULL; */ /* sma->sem_pending = NULL; */
sma->sem_pending_last = &sma->sem_pending; sma->sem_pending_last = &sma->sem_pending;
...@@ -201,7 +203,7 @@ static int newary (key_t key, int nsems, int semflg) ...@@ -201,7 +203,7 @@ static int newary (key_t key, int nsems, int semflg)
sma->sem_ctime = get_seconds(); sma->sem_ctime = get_seconds();
sem_unlock(sma); sem_unlock(sma);
return sem_buildid(id, sma->sem_perm.seq); return sma->sem_id;
} }
asmlinkage long sys_semget (key_t key, int nsems, int semflg) asmlinkage long sys_semget (key_t key, int nsems, int semflg)
...@@ -1328,50 +1330,21 @@ next_entry: ...@@ -1328,50 +1330,21 @@ next_entry:
} }
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
static int sysvipc_sem_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data) static int sysvipc_sem_proc_show(struct seq_file *s, void *it)
{ {
off_t pos = 0; struct sem_array *sma = it;
off_t begin = 0;
int i, len = 0; return seq_printf(s,
"%10d %10d %4o %10lu %5u %5u %5u %5u %10lu %10lu\n",
len += sprintf(buffer, " key semid perms nsems uid gid cuid cgid otime ctime\n"); sma->sem_perm.key,
down(&sem_ids.sem); sma->sem_id,
sma->sem_perm.mode,
for(i = 0; i <= sem_ids.max_id; i++) { sma->sem_nsems,
struct sem_array *sma; sma->sem_perm.uid,
sma = sem_lock(i); sma->sem_perm.gid,
if(sma) { sma->sem_perm.cuid,
len += sprintf(buffer + len, "%10d %10d %4o %10lu %5u %5u %5u %5u %10lu %10lu\n", sma->sem_perm.cgid,
sma->sem_perm.key, sma->sem_otime,
sem_buildid(i,sma->sem_perm.seq), sma->sem_ctime);
sma->sem_perm.mode,
sma->sem_nsems,
sma->sem_perm.uid,
sma->sem_perm.gid,
sma->sem_perm.cuid,
sma->sem_perm.cgid,
sma->sem_otime,
sma->sem_ctime);
sem_unlock(sma);
pos += len;
if(pos < offset) {
len = 0;
begin = pos;
}
if(pos > offset + length)
goto done;
}
}
*eof = 1;
done:
up(&sem_ids.sem);
*start = buffer + (offset - begin);
len -= (offset - begin);
if(len > length)
len = length;
if(len < 0)
len = 0;
return len;
} }
#endif #endif
...@@ -23,12 +23,12 @@ ...@@ -23,12 +23,12 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/file.h> #include <linux/file.h>
#include <linux/mman.h> #include <linux/mman.h>
#include <linux/proc_fs.h>
#include <linux/shmem_fs.h> #include <linux/shmem_fs.h>
#include <linux/security.h> #include <linux/security.h>
#include <linux/syscalls.h> #include <linux/syscalls.h>
#include <linux/audit.h> #include <linux/audit.h>
#include <linux/ptrace.h> #include <linux/ptrace.h>
#include <linux/seq_file.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
...@@ -51,7 +51,7 @@ static int newseg (key_t key, int shmflg, size_t size); ...@@ -51,7 +51,7 @@ static int newseg (key_t key, int shmflg, size_t size);
static void shm_open (struct vm_area_struct *shmd); static void shm_open (struct vm_area_struct *shmd);
static void shm_close (struct vm_area_struct *shmd); static void shm_close (struct vm_area_struct *shmd);
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
static int sysvipc_shm_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data); static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
#endif #endif
size_t shm_ctlmax = SHMMAX; size_t shm_ctlmax = SHMMAX;
...@@ -63,9 +63,10 @@ static int shm_tot; /* total number of shared memory pages */ ...@@ -63,9 +63,10 @@ static int shm_tot; /* total number of shared memory pages */
void __init shm_init (void) void __init shm_init (void)
{ {
ipc_init_ids(&shm_ids, 1); ipc_init_ids(&shm_ids, 1);
#ifdef CONFIG_PROC_FS ipc_init_proc_interface("sysvipc/shm",
create_proc_read_entry("sysvipc/shm", 0, NULL, sysvipc_shm_read_proc, NULL); " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime\n",
#endif &shm_ids,
sysvipc_shm_proc_show);
} }
static inline int shm_checkid(struct shmid_kernel *s, int id) static inline int shm_checkid(struct shmid_kernel *s, int id)
...@@ -869,63 +870,32 @@ asmlinkage long sys_shmdt(char __user *shmaddr) ...@@ -869,63 +870,32 @@ asmlinkage long sys_shmdt(char __user *shmaddr)
} }
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
static int sysvipc_shm_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data) static int sysvipc_shm_proc_show(struct seq_file *s, void *it)
{ {
off_t pos = 0; struct shmid_kernel *shp = it;
off_t begin = 0; char *format;
int i, len = 0;
down(&shm_ids.sem);
len += sprintf(buffer, " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime\n");
for(i = 0; i <= shm_ids.max_id; i++) {
struct shmid_kernel* shp;
shp = shm_lock(i);
if(shp!=NULL) {
#define SMALL_STRING "%10d %10d %4o %10u %5u %5u %5d %5u %5u %5u %5u %10lu %10lu %10lu\n" #define SMALL_STRING "%10d %10d %4o %10u %5u %5u %5d %5u %5u %5u %5u %10lu %10lu %10lu\n"
#define BIG_STRING "%10d %10d %4o %21u %5u %5u %5d %5u %5u %5u %5u %10lu %10lu %10lu\n" #define BIG_STRING "%10d %10d %4o %21u %5u %5u %5d %5u %5u %5u %5u %10lu %10lu %10lu\n"
char *format;
if (sizeof(size_t) <= sizeof(int)) if (sizeof(size_t) <= sizeof(int))
format = SMALL_STRING; format = SMALL_STRING;
else else
format = BIG_STRING; format = BIG_STRING;
len += sprintf(buffer + len, format, return seq_printf(s, format,
shp->shm_perm.key, shp->shm_perm.key,
shm_buildid(i, shp->shm_perm.seq), shp->id,
shp->shm_flags, shp->shm_flags,
shp->shm_segsz, shp->shm_segsz,
shp->shm_cprid, shp->shm_cprid,
shp->shm_lprid, shp->shm_lprid,
is_file_hugepages(shp->shm_file) ? (file_count(shp->shm_file) - 1) : shp->shm_nattch, is_file_hugepages(shp->shm_file) ? (file_count(shp->shm_file) - 1) : shp->shm_nattch,
shp->shm_perm.uid, shp->shm_perm.uid,
shp->shm_perm.gid, shp->shm_perm.gid,
shp->shm_perm.cuid, shp->shm_perm.cuid,
shp->shm_perm.cgid, shp->shm_perm.cgid,
shp->shm_atim, shp->shm_atim,
shp->shm_dtim, shp->shm_dtim,
shp->shm_ctim); shp->shm_ctim);
shm_unlock(shp);
pos += len;
if(pos < offset) {
len = 0;
begin = pos;
}
if(pos > offset + length)
goto done;
}
}
*eof = 1;
done:
up(&shm_ids.sem);
*start = buffer + (offset - begin);
len -= (offset - begin);
if(len > length)
len = length;
if(len < 0)
len = 0;
return len;
} }
#endif #endif
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