From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Serge E. Hallyn" Subject: Re: [RFC v14-rc2][PATCH 1/7] ipc: allow allocation of an ipc object with desired identifier Date: Thu, 2 Apr 2009 12:22:33 -0500 Message-ID: <20090402172233.GB9984@us.ibm.com> References: <1238477552-17083-1-git-send-email-orenl@cs.columbia.edu> <1238477552-17083-2-git-send-email-orenl@cs.columbia.edu> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <1238477552-17083-2-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: Oren Laadan Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, Dave Hansen List-Id: containers.vger.kernel.org Quoting Oren Laadan (orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org): > -int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size) > +int > +ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int size, int req_id) > { > uid_t euid; > gid_t egid; > + int lid = 0; > int id, err; > > if (size > IPCMNI) > @@ -268,28 +270,41 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size) > if (ids->in_use >= size) > return -ENOSPC; > > + if (req_id >= 0) > + lid = ipcid_to_idx(req_id); > + > spin_lock_init(&new->lock); > new->deleted = 0; > rcu_read_lock(); > spin_lock(&new->lock); > > - err = idr_get_new(&ids->ipcs_idr, new, &id); > + err = idr_get_new_above(&ids->ipcs_idr, new, lid, &id); > if (err) { > spin_unlock(&new->lock); > rcu_read_unlock(); > return err; > } > > + if (req_id >= 0) { > + if (id != lid) { > + idr_remove(&ids->ipcs_idr, id); > + spin_unlock(&new->lock); > + rcu_read_unlock(); > + return -EBUSY; > + } > + new->seq = req_id / SEQ_MULTIPLIER; Should this be new->seq = req_id % ids->seq_max; ? > + } else { > + new->seq = ids->seq++; > + if (ids->seq > ids->seq_max) > + ids->seq = 0; > + } > + > ids->in_use++; > > current_euid_egid(&euid, &egid); > new->cuid = new->uid = euid; > new->gid = new->cgid = egid; > > - new->seq = ids->seq++; > - if(ids->seq > ids->seq_max) > - ids->seq = 0; > -