Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

Mike Waychison and committed by
Linus Torvalds
19b4946c ae781774

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