Skip to contentSkip to conversation

kernel: pid: Update documentation.

PATCH Superseded Varsha Rao 2 participants 5 messages Mar 26, 2017 – Mar 27, 2017 1 message not in the archive

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Varsha Rao

author
#1 lore raw

PATCH 1/3 kernel: pid: Update documentation.

In reply to a message not in the archive

This patch adds comments to update documentation.

---
 kernel/pid.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
kernel/pid.c +16 -0
index 0143ac0..0b0aad4 100644
@@ -43,6 +43,7 @@
 #define pid_hashfn(nr, ns)	\
 	hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
 static struct hlist_head *pid_hash;
+/* Doubly linked hash lists to find PID in given namespace. */
 static unsigned int pidhash_shift = 4;
 struct pid init_struct_pid = INIT_STRUCT_PID;
 
@@ -53,6 +54,7 @@ int pid_max = PID_MAX_DEFAULT;
 int pid_max_min = RESERVED_PIDS + 1;
 int pid_max_max = PID_MAX_LIMIT;
 
+/* mk_pid() returns distance between map and offset pidmap. */
 static inline int mk_pid(struct pid_namespace *pid_ns,
 		struct pidmap *map, int off)
 {
@@ -101,6 +103,7 @@ EXPORT_SYMBOL_GPL(init_pid_ns);
 
 static  __cacheline_aligned_in_smp DEFINE_SPINLOCK(pidmap_lock);
 
+/* free_pidmap() : It frees process id. */
 static void free_pidmap(struct upid *upid)
 {
 	int nr = upid->nr;
@@ -150,6 +153,9 @@ static void set_last_pid(struct pid_namespace *pid_ns, int base, int pid)
 	} while ((prev != last_write) && (pid_before(base, last_write, pid)));
 }
 
+/* alloc_pidmap(): Increments last pid by one and returns it if new pid
+ * is valid.
+ */
 static int alloc_pidmap(struct pid_namespace *pid_ns)
 {
 	int i, offset, max_scan, pid, last = pid_ns->last_pid;
@@ -212,6 +218,9 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
 	return -EAGAIN;
 }
 
+/* next_pidmap() is used to find the first pid which is greater than previous
+ * last allocated pid.
+ */
 int next_pidmap(struct pid_namespace *pid_ns, unsigned int last)
 {
 	int offset;
@@ -233,6 +242,7 @@ int next_pidmap(struct pid_namespace *pid_ns, unsigned int last)
 	return -1;
 }
 
+/* put_pid() checks whether pid can be reallocated. */
 void put_pid(struct pid *pid)
 {
 	struct pid_namespace *ns;
@@ -249,6 +259,9 @@ void put_pid(struct pid *pid)
 }
 EXPORT_SYMBOL_GPL(put_pid);
 
+/* delayed_put_pid(): Finds the real location of struct pid in the
+ * memory and checks whether it can be reallocated with put_pid().
+ */
 static void delayed_put_pid(struct rcu_head *rhp)
 {
 	struct pid *pid = container_of(rhp, struct pid, rcu);
@@ -293,6 +306,9 @@ void free_pid(struct pid *pid)
 	call_rcu(&pid->rcu, delayed_put_pid);
 }
 
+/* alloc_pid(): Allocates local pid for each multiple namespaces
+ * in which new process created is visible.
+ */
 struct pid *alloc_pid(struct pid_namespace *ns)
 {
 	struct pid *pid;
Signature · 1 line
2.9.3
author
#2 lore raw

PATCH 2/3 kernel: pid: Replace unsigned with unsigned int.

In reply to a message not in the archive

Replace unsigned with unsigned int, to fix the checkpatch issue.

---
 kernel/pid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/pid.c +1 -1
index 0b0aad4..c022239 100644
@@ -125,7 +125,7 @@ static int pid_before(int base, int a, int b)
 	 * (a - base + MAXUINT) % MAXUINT < (b - base + MAXUINT) % MAXUINT
 	 * and that mapping orders 'a' and 'b' with respect to 'base'.
 	 */
-	return (unsigned)(a - base) < (unsigned)(b - base);
+	return (unsigned int)(a - base) < (unsigned int)(b - base);
 }
 
 /*
Signature · 1 line
2.9.3
author
#5 lore raw

PATCH 3/3 kernel: pid: Add blank line after declarations.

In reply to a message not in the archive

Add a blank line after declarations, to fix the checkpatch issue.

---
 kernel/pid.c | 7 +++++++
 1 file changed, 7 insertions(+)
kernel/pid.c +7 -0
index c022239..64c0ce4 100644
@@ -147,6 +147,7 @@ static void set_last_pid(struct pid_namespace *pid_ns, int base, int pid)
 {
 	int prev;
 	int last_write = base;
+
 	do {
 		prev = last_write;
 		last_write = cmpxchg(&pid_ns->last_pid, prev, pid);
@@ -265,6 +266,7 @@ EXPORT_SYMBOL_GPL(put_pid);
 static void delayed_put_pid(struct rcu_head *rhp)
 {
 	struct pid *pid = container_of(rhp, struct pid, rcu);
+
 	put_pid(pid);
 }
 
@@ -404,6 +406,7 @@ EXPORT_SYMBOL_GPL(find_vpid);
 void attach_pid(struct task_struct *task, enum pid_type type)
 {
 	struct pid_link *link = &task->pids[type];
+
 	hlist_add_head_rcu(&link->node, &link->pid->tasks[type]);
 }
 
@@ -450,8 +453,10 @@ void transfer_pid(struct task_struct *old, struct task_struct *new,
 struct task_struct *pid_task(struct pid *pid, enum pid_type type)
 {
 	struct task_struct *result = NULL;
+
 	if (pid) {
 		struct hlist_node *first;
+
 		first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
 					      lockdep_tasklist_lock_is_held());
 		if (first)
@@ -479,6 +484,7 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
 {
 	struct pid *pid;
+
 	rcu_read_lock();
 	if (type != PIDTYPE_PID)
 		task = task->group_leader;
@@ -491,6 +497,7 @@ EXPORT_SYMBOL_GPL(get_task_pid);
 struct task_struct *get_pid_task(struct pid *pid, enum pid_type type)
 {
 	struct task_struct *result;
+
 	rcu_read_lock();
 	result = pid_task(pid, type);
 	if (result)
Signature · 1 line
2.9.3
#3 lore raw

Re: [Outreachy kernel] [PATCH 2/3] kernel: pid: Replace unsigned with unsigned int.

In reply to Varsha Rao
Quoted 12 lines · Varsha Rao

Replace unsigned with unsigned int, to fix the checkpatch issue.

---
 kernel/pid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/pid.c +0 -0
index 0b0aad4..c022239 100644

kernel/pid.c static int pid_before(int base, int a, int b) · line 129

Quoted 6 lines
kernel/pid.c +1 -1
@@ -125,7 +125,7 @@ static int pid_before(int base, int a, int b)
 	 * (a - base + MAXUINT) % MAXUINT < (b - base + MAXUINT) % MAXUINT
 	 * and that mapping orders 'a' and 'b' with respect to 'base'.
 	 */
-	return (unsigned)(a - base) < (unsigned)(b - base);
+	return (unsigned int)(a - base) < (unsigned int)(b - base);
 }

Unrelatedly, it looks like bool would be a more natural return type.

julia

Quoted 12 lines
kernel/pid.c +0 -1
 /*
--

2.9.3

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/58d7dfaa.c65b620a.68c66.766e%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.

author
#4 lore raw

Re: [Outreachy kernel] [PATCH 2/3] kernel: pid: Replace unsigned with unsigned int.

Quoted 20 lines · Varsha Rao
Quoted 13 lines

Replace unsigned with unsigned int, to fix the checkpatch issue.

Signed-off-by Varsha Rao <[email protected] <javascript:>>

---

 kernel/pid.c | 2 +- 
 1 file changed, 1 insertion(+), 1 deletion(-) 
kernel/pid.c +0 -0
index 0b0aad4..c022239 100644 

kernel/pid.c static int pid_before(int base, int a, int b) · line 125

Quoted 1 line
kernel/pid.c +0 -0
@@ -125,7 +125,7 @@ static int pid_before(int base, int a, int b) 
          * (a - base + MAXUINT) % MAXUINT < (b - base + MAXUINT) % 

MAXUINT

Quoted 8 lines

kernel/pid.c static int pid_before(int base, int a, int b) · line 129

Quoted 5 lines
kernel/pid.c +1 -1
          * and that mapping orders 'a' and 'b' with respect to 'base'. 
          */ 
-        return (unsigned)(a - base) < (unsigned)(b - base); 
+        return (unsigned int)(a - base) < (unsigned int)(b - base); 
 } 

Unrelatedly, it looks like bool would be a more natural return type.

I will change the return type to bool. Also It is called only once in
do while condition.
I will send new patch for it.

Regards,
Varsha Rao

Quoted 3 lines

julia