hugetlb: modular state for hugetlb page size
[safe/jmp/linux-2.6] / ipc / shm.c
index 5e296b0..a726aeb 100644 (file)
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -126,18 +126,6 @@ static inline struct shmid_kernel *shm_lock_down(struct ipc_namespace *ns,
        return container_of(ipcp, struct shmid_kernel, shm_perm);
 }
 
-static inline struct shmid_kernel *shm_lock_check_down(
-                                               struct ipc_namespace *ns,
-                                               int id)
-{
-       struct kern_ipc_perm *ipcp = ipc_lock_check_down(&shm_ids(ns), id);
-
-       if (IS_ERR(ipcp))
-               return (struct shmid_kernel *)ipcp;
-
-       return container_of(ipcp, struct shmid_kernel, shm_perm);
-}
-
 /*
  * shm_lock_(check_) routines are called in the paths where the rw_mutex
  * is not held.
@@ -589,7 +577,8 @@ static void shm_get_stat(struct ipc_namespace *ns, unsigned long *rss,
 
                if (is_file_hugepages(shp->shm_file)) {
                        struct address_space *mapping = inode->i_mapping;
-                       *rss += (HPAGE_SIZE/PAGE_SIZE)*mapping->nrpages;
+                       struct hstate *h = hstate_file(shp->shm_file);
+                       *rss += pages_per_huge_page(h) * mapping->nrpages;
                } else {
                        struct shmem_inode_info *info = SHMEM_I(inode);
                        spin_lock(&info->lock);
@@ -620,33 +609,11 @@ static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd,
                        return -EFAULT;
        }
 
-       down_write(&shm_ids(ns).rw_mutex);
-       shp = shm_lock_check_down(ns, shmid);
-       if (IS_ERR(shp)) {
-               err = PTR_ERR(shp);
-               goto out_up;
-       }
-
-       ipcp = &shp->shm_perm;
-
-       err = audit_ipc_obj(ipcp);
-       if (err)
-               goto out_unlock;
-
-       if (cmd == IPC_SET) {
-               err = audit_ipc_set_perm(0, shmid64.shm_perm.uid,
-                                        shmid64.shm_perm.gid,
-                                        shmid64.shm_perm.mode);
-               if (err)
-                       goto out_unlock;
-       }
+       ipcp = ipcctl_pre_down(&shm_ids(ns), shmid, cmd, &shmid64.shm_perm, 0);
+       if (IS_ERR(ipcp))
+               return PTR_ERR(ipcp);
 
-       if (current->euid != ipcp->uid &&
-           current->euid != ipcp->cuid &&
-           !capable(CAP_SYS_ADMIN)) {
-               err = -EPERM;
-               goto out_unlock;
-       }
+       shp = container_of(ipcp, struct shmid_kernel, shm_perm);
 
        err = security_shm_shmctl(shp, cmd);
        if (err)
@@ -656,10 +623,7 @@ static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd,
                do_shm_rmid(ns, ipcp);
                goto out_up;
        case IPC_SET:
-               ipcp->uid = shmid64.shm_perm.uid;
-               ipcp->gid = shmid64.shm_perm.gid;
-               ipcp->mode = (ipcp->mode & ~S_IRWXUGO)
-                       | (shmid64.shm_perm.mode & S_IRWXUGO);
+               ipc_update_perm(&shmid64.shm_perm, ipcp);
                shp->shm_ctim = get_seconds();
                break;
        default:
@@ -931,8 +895,6 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
        if (!sfd)
                goto out_put_dentry;
 
-       err = -ENOMEM;
-
        file = alloc_file(path.mnt, path.dentry, f_mode, &shm_file_operations);
        if (!file)
                goto out_free;
@@ -1097,16 +1059,16 @@ asmlinkage long sys_shmdt(char __user *shmaddr)
 static int sysvipc_shm_proc_show(struct seq_file *s, void *it)
 {
        struct shmid_kernel *shp = it;
-       char *format;
 
-#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"
+#if BITS_PER_LONG <= 32
+#define SIZE_SPEC "%10lu"
+#else
+#define SIZE_SPEC "%21lu"
+#endif
 
-       if (sizeof(size_t) <= sizeof(int))
-               format = SMALL_STRING;
-       else
-               format = BIG_STRING;
-       return seq_printf(s, format,
+       return seq_printf(s,
+                         "%10d %10d  %4o " SIZE_SPEC " %5u %5u  "
+                         "%5lu %5u %5u %5u %5u %10lu %10lu %10lu\n",
                          shp->shm_perm.key,
                          shp->shm_perm.id,
                          shp->shm_perm.mode,