Commit 19b4946ca9d1e35d4c641dcebe27378de34f3ddd

Authored by Mike Waychison
Committed by Linus Torvalds
1 parent ae7817745e

[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: Mike Waychison <mikew@google.com>
Cc: Manfred Spraul <manfred@colorfullife.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

Showing 5 changed files with 80 additions and 163 deletions Side-by-side Diff

... ... @@ -77,6 +77,7 @@
77 77 /* one msq_queue structure for each present queue on the system */
78 78 struct msg_queue {
79 79 struct kern_ipc_perm q_perm;
  80 + int q_id;
80 81 time_t q_stime; /* last msgsnd time */
81 82 time_t q_rtime; /* last msgrcv time */
82 83 time_t q_ctime; /* last change time */
... ... @@ -88,6 +88,7 @@
88 88 /* One sem_array data structure for each set of semaphores in the system. */
89 89 struct sem_array {
90 90 struct kern_ipc_perm sem_perm; /* permissions .. see ipc.h */
  91 + int sem_id;
91 92 time_t sem_otime; /* last semop time */
92 93 time_t sem_ctime; /* last change time */
93 94 struct sem *sem_base; /* ptr to first semaphore in array */
... ... @@ -26,6 +26,7 @@
26 26 #include <linux/sched.h>
27 27 #include <linux/syscalls.h>
28 28 #include <linux/audit.h>
  29 +#include <linux/seq_file.h>
29 30 #include <asm/current.h>
30 31 #include <asm/uaccess.h>
31 32 #include "util.h"
32 33  
... ... @@ -74,16 +75,16 @@
74 75 static void freeque (struct msg_queue *msq, int id);
75 76 static int newque (key_t key, int msgflg);
76 77 #ifdef CONFIG_PROC_FS
77   -static int sysvipc_msg_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data);
  78 +static int sysvipc_msg_proc_show(struct seq_file *s, void *it);
78 79 #endif
79 80  
80 81 void __init msg_init (void)
81 82 {
82 83 ipc_init_ids(&msg_ids,msg_ctlmni);
83   -
84   -#ifdef CONFIG_PROC_FS
85   - create_proc_read_entry("sysvipc/msg", 0, NULL, sysvipc_msg_read_proc, NULL);
86   -#endif
  84 + ipc_init_proc_interface("sysvipc/msg",
  85 + " key msqid perms cbytes qnum lspid lrpid uid gid cuid cgid stime rtime ctime\n",
  86 + &msg_ids,
  87 + sysvipc_msg_proc_show);
87 88 }
88 89  
89 90 static int newque (key_t key, int msgflg)
... ... @@ -113,6 +114,7 @@
113 114 return -ENOSPC;
114 115 }
115 116  
  117 + msq->q_id = msg_buildid(id,msq->q_perm.seq);
116 118 msq->q_stime = msq->q_rtime = 0;
117 119 msq->q_ctime = get_seconds();
118 120 msq->q_cbytes = msq->q_qnum = 0;
... ... @@ -123,7 +125,7 @@
123 125 INIT_LIST_HEAD(&msq->q_senders);
124 126 msg_unlock(msq);
125 127  
126   - return msg_buildid(id,msq->q_perm.seq);
  128 + return msq->q_id;
127 129 }
128 130  
129 131 static inline void ss_add(struct msg_queue* msq, struct msg_sender* mss)
130 132  
131 133  
... ... @@ -808,56 +810,26 @@
808 810 }
809 811  
810 812 #ifdef CONFIG_PROC_FS
811   -static int sysvipc_msg_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data)
  813 +static int sysvipc_msg_proc_show(struct seq_file *s, void *it)
812 814 {
813   - off_t pos = 0;
814   - off_t begin = 0;
815   - int i, len = 0;
  815 + struct msg_queue *msq = it;
816 816  
817   - down(&msg_ids.sem);
818   - len += sprintf(buffer, " key msqid perms cbytes qnum lspid lrpid uid gid cuid cgid stime rtime ctime\n");
819   -
820   - for(i = 0; i <= msg_ids.max_id; i++) {
821   - struct msg_queue * msq;
822   - msq = msg_lock(i);
823   - if(msq != NULL) {
824   - len += sprintf(buffer + len, "%10d %10d %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %10lu %10lu %10lu\n",
825   - msq->q_perm.key,
826   - msg_buildid(i,msq->q_perm.seq),
827   - msq->q_perm.mode,
828   - msq->q_cbytes,
829   - msq->q_qnum,
830   - msq->q_lspid,
831   - msq->q_lrpid,
832   - msq->q_perm.uid,
833   - msq->q_perm.gid,
834   - msq->q_perm.cuid,
835   - msq->q_perm.cgid,
836   - msq->q_stime,
837   - msq->q_rtime,
838   - msq->q_ctime);
839   - msg_unlock(msq);
840   -
841   - pos += len;
842   - if(pos < offset) {
843   - len = 0;
844   - begin = pos;
845   - }
846   - if(pos > offset + length)
847   - goto done;
848   - }
849   -
850   - }
851   - *eof = 1;
852   -done:
853   - up(&msg_ids.sem);
854   - *start = buffer + (offset - begin);
855   - len -= (offset - begin);
856   - if(len > length)
857   - len = length;
858   - if(len < 0)
859   - len = 0;
860   - return len;
  817 + return seq_printf(s,
  818 + "%10d %10d %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %10lu %10lu %10lu\n",
  819 + msq->q_perm.key,
  820 + msq->q_id,
  821 + msq->q_perm.mode,
  822 + msq->q_cbytes,
  823 + msq->q_qnum,
  824 + msq->q_lspid,
  825 + msq->q_lrpid,
  826 + msq->q_perm.uid,
  827 + msq->q_perm.gid,
  828 + msq->q_perm.cuid,
  829 + msq->q_perm.cgid,
  830 + msq->q_stime,
  831 + msq->q_rtime,
  832 + msq->q_ctime);
861 833 }
862 834 #endif
... ... @@ -73,6 +73,7 @@
73 73 #include <linux/security.h>
74 74 #include <linux/syscalls.h>
75 75 #include <linux/audit.h>
  76 +#include <linux/seq_file.h>
76 77 #include <asm/uaccess.h>
77 78 #include "util.h"
78 79  
... ... @@ -89,7 +90,7 @@
89 90 static int newary (key_t, int, int);
90 91 static void freeary (struct sem_array *sma, int id);
91 92 #ifdef CONFIG_PROC_FS
92   -static int sysvipc_sem_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data);
  93 +static int sysvipc_sem_proc_show(struct seq_file *s, void *it);
93 94 #endif
94 95  
95 96 #define SEMMSL_FAST 256 /* 512 bytes on stack */
... ... @@ -116,10 +117,10 @@
116 117 {
117 118 used_sems = 0;
118 119 ipc_init_ids(&sem_ids,sc_semmni);
119   -
120   -#ifdef CONFIG_PROC_FS
121   - create_proc_read_entry("sysvipc/sem", 0, NULL, sysvipc_sem_read_proc, NULL);
122   -#endif
  120 + ipc_init_proc_interface("sysvipc/sem",
  121 + " key semid perms nsems uid gid cuid cgid otime ctime\n",
  122 + &sem_ids,
  123 + sysvipc_sem_proc_show);
123 124 }
124 125  
125 126 /*
... ... @@ -193,6 +194,7 @@
193 194 }
194 195 used_sems += nsems;
195 196  
  197 + sma->sem_id = sem_buildid(id, sma->sem_perm.seq);
196 198 sma->sem_base = (struct sem *) &sma[1];
197 199 /* sma->sem_pending = NULL; */
198 200 sma->sem_pending_last = &sma->sem_pending;
... ... @@ -201,7 +203,7 @@
201 203 sma->sem_ctime = get_seconds();
202 204 sem_unlock(sma);
203 205  
204   - return sem_buildid(id, sma->sem_perm.seq);
  206 + return sma->sem_id;
205 207 }
206 208  
207 209 asmlinkage long sys_semget (key_t key, int nsems, int semflg)
208 210  
209 211  
... ... @@ -1328,51 +1330,22 @@
1328 1330 }
1329 1331  
1330 1332 #ifdef CONFIG_PROC_FS
1331   -static int sysvipc_sem_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data)
  1333 +static int sysvipc_sem_proc_show(struct seq_file *s, void *it)
1332 1334 {
1333   - off_t pos = 0;
1334   - off_t begin = 0;
1335   - int i, len = 0;
  1335 + struct sem_array *sma = it;
1336 1336  
1337   - len += sprintf(buffer, " key semid perms nsems uid gid cuid cgid otime ctime\n");
1338   - down(&sem_ids.sem);
1339   -
1340   - for(i = 0; i <= sem_ids.max_id; i++) {
1341   - struct sem_array *sma;
1342   - sma = sem_lock(i);
1343   - if(sma) {
1344   - len += sprintf(buffer + len, "%10d %10d %4o %10lu %5u %5u %5u %5u %10lu %10lu\n",
1345   - sma->sem_perm.key,
1346   - sem_buildid(i,sma->sem_perm.seq),
1347   - sma->sem_perm.mode,
1348   - sma->sem_nsems,
1349   - sma->sem_perm.uid,
1350   - sma->sem_perm.gid,
1351   - sma->sem_perm.cuid,
1352   - sma->sem_perm.cgid,
1353   - sma->sem_otime,
1354   - sma->sem_ctime);
1355   - sem_unlock(sma);
1356   -
1357   - pos += len;
1358   - if(pos < offset) {
1359   - len = 0;
1360   - begin = pos;
1361   - }
1362   - if(pos > offset + length)
1363   - goto done;
1364   - }
1365   - }
1366   - *eof = 1;
1367   -done:
1368   - up(&sem_ids.sem);
1369   - *start = buffer + (offset - begin);
1370   - len -= (offset - begin);
1371   - if(len > length)
1372   - len = length;
1373   - if(len < 0)
1374   - len = 0;
1375   - return len;
  1337 + return seq_printf(s,
  1338 + "%10d %10d %4o %10lu %5u %5u %5u %5u %10lu %10lu\n",
  1339 + sma->sem_perm.key,
  1340 + sma->sem_id,
  1341 + sma->sem_perm.mode,
  1342 + sma->sem_nsems,
  1343 + sma->sem_perm.uid,
  1344 + sma->sem_perm.gid,
  1345 + sma->sem_perm.cuid,
  1346 + sma->sem_perm.cgid,
  1347 + sma->sem_otime,
  1348 + sma->sem_ctime);
1376 1349 }
1377 1350 #endif
... ... @@ -23,12 +23,12 @@
23 23 #include <linux/init.h>
24 24 #include <linux/file.h>
25 25 #include <linux/mman.h>
26   -#include <linux/proc_fs.h>
27 26 #include <linux/shmem_fs.h>
28 27 #include <linux/security.h>
29 28 #include <linux/syscalls.h>
30 29 #include <linux/audit.h>
31 30 #include <linux/ptrace.h>
  31 +#include <linux/seq_file.h>
32 32  
33 33 #include <asm/uaccess.h>
34 34  
... ... @@ -51,7 +51,7 @@
51 51 static void shm_open (struct vm_area_struct *shmd);
52 52 static void shm_close (struct vm_area_struct *shmd);
53 53 #ifdef CONFIG_PROC_FS
54   -static int sysvipc_shm_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data);
  54 +static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
55 55 #endif
56 56  
57 57 size_t shm_ctlmax = SHMMAX;
... ... @@ -63,9 +63,10 @@
63 63 void __init shm_init (void)
64 64 {
65 65 ipc_init_ids(&shm_ids, 1);
66   -#ifdef CONFIG_PROC_FS
67   - create_proc_read_entry("sysvipc/shm", 0, NULL, sysvipc_shm_read_proc, NULL);
68   -#endif
  66 + ipc_init_proc_interface("sysvipc/shm",
  67 + " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime\n",
  68 + &shm_ids,
  69 + sysvipc_shm_proc_show);
69 70 }
70 71  
71 72 static inline int shm_checkid(struct shmid_kernel *s, int id)
72 73  
73 74  
74 75  
75 76  
... ... @@ -869,64 +870,33 @@
869 870 }
870 871  
871 872 #ifdef CONFIG_PROC_FS
872   -static int sysvipc_shm_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data)
  873 +static int sysvipc_shm_proc_show(struct seq_file *s, void *it)
873 874 {
874   - off_t pos = 0;
875   - off_t begin = 0;
876   - int i, len = 0;
  875 + struct shmid_kernel *shp = it;
  876 + char *format;
877 877  
878   - down(&shm_ids.sem);
879   - len += sprintf(buffer, " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime\n");
880   -
881   - for(i = 0; i <= shm_ids.max_id; i++) {
882   - struct shmid_kernel* shp;
883   -
884   - shp = shm_lock(i);
885   - if(shp!=NULL) {
886 878 #define SMALL_STRING "%10d %10d %4o %10u %5u %5u %5d %5u %5u %5u %5u %10lu %10lu %10lu\n"
887 879 #define BIG_STRING "%10d %10d %4o %21u %5u %5u %5d %5u %5u %5u %5u %10lu %10lu %10lu\n"
888   - char *format;
889 880  
890   - if (sizeof(size_t) <= sizeof(int))
891   - format = SMALL_STRING;
892   - else
893   - format = BIG_STRING;
894   - len += sprintf(buffer + len, format,
895   - shp->shm_perm.key,
896   - shm_buildid(i, shp->shm_perm.seq),
897   - shp->shm_flags,
898   - shp->shm_segsz,
899   - shp->shm_cprid,
900   - shp->shm_lprid,
901   - is_file_hugepages(shp->shm_file) ? (file_count(shp->shm_file) - 1) : shp->shm_nattch,
902   - shp->shm_perm.uid,
903   - shp->shm_perm.gid,
904   - shp->shm_perm.cuid,
905   - shp->shm_perm.cgid,
906   - shp->shm_atim,
907   - shp->shm_dtim,
908   - shp->shm_ctim);
909   - shm_unlock(shp);
910   -
911   - pos += len;
912   - if(pos < offset) {
913   - len = 0;
914   - begin = pos;
915   - }
916   - if(pos > offset + length)
917   - goto done;
918   - }
919   - }
920   - *eof = 1;
921   -done:
922   - up(&shm_ids.sem);
923   - *start = buffer + (offset - begin);
924   - len -= (offset - begin);
925   - if(len > length)
926   - len = length;
927   - if(len < 0)
928   - len = 0;
929   - return len;
  881 + if (sizeof(size_t) <= sizeof(int))
  882 + format = SMALL_STRING;
  883 + else
  884 + format = BIG_STRING;
  885 + return seq_printf(s, format,
  886 + shp->shm_perm.key,
  887 + shp->id,
  888 + shp->shm_flags,
  889 + shp->shm_segsz,
  890 + shp->shm_cprid,
  891 + shp->shm_lprid,
  892 + is_file_hugepages(shp->shm_file) ? (file_count(shp->shm_file) - 1) : shp->shm_nattch,
  893 + shp->shm_perm.uid,
  894 + shp->shm_perm.gid,
  895 + shp->shm_perm.cuid,
  896 + shp->shm_perm.cgid,
  897 + shp->shm_atim,
  898 + shp->shm_dtim,
  899 + shp->shm_ctim);
930 900 }
931 901 #endif