forked from davidsaOpenu/xv6-ns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial implementation for pidns, not all tests pass
Change-Id: I1035aa1a4382f2b65ea6f1bed5e2d565c1cb6b07
- Loading branch information
1 parent
43794a7
commit 066d869
Showing
15 changed files
with
193 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ OBJS = \ | |
main.o\ | ||
mount.o\ | ||
mount_ns.o\ | ||
pid_ns.o\ | ||
mp.o\ | ||
namespace.o\ | ||
picirq.o\ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,4 +77,4 @@ struct mount_ns* newmount_ns() | |
{ | ||
struct mount_ns* mount_ns = allocmount_ns(); | ||
return mount_ns; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
struct nsproxy { | ||
int ref; | ||
struct mount_ns* mount_ns; | ||
struct pid_ns* pid_ns; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
#define MOUNT_NS (1) | ||
#define MOUNT_NS (1) | ||
#define PID_NS (2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "types.h" | ||
#include "defs.h" | ||
#include "param.h" | ||
#include "memlayout.h" | ||
#include "mmu.h" | ||
#include "x86.h" | ||
#include "proc.h" | ||
#include "spinlock.h" | ||
#include "wstatus.h" | ||
#include "pid_ns.h" | ||
#include "namespace.h" | ||
|
||
struct { | ||
struct spinlock lock; | ||
struct pid_ns namespaces[NNAMESPACE]; | ||
} pidnstable; | ||
|
||
void pid_ns_init() | ||
{ | ||
initlock(&pidnstable.lock, "pidns"); | ||
for (int i = 0; i < NNAMESPACE; i++) { | ||
initlock(&pidnstable.namespaces[i].lock, "pidns"); | ||
pidnstable.namespaces[i].ref = 0; | ||
} | ||
} | ||
|
||
void pid_ns_put(struct pid_ns* pid_ns) | ||
{ | ||
acquire(&pidnstable.lock); | ||
pid_ns->ref--; | ||
release(&pidnstable.lock); | ||
} | ||
|
||
void pid_ns_get(struct pid_ns* pid_ns) | ||
{ | ||
acquire(&pidnstable.lock); | ||
pid_ns->ref++; | ||
release(&pidnstable.lock); | ||
} | ||
|
||
struct pid_ns* pid_ns_alloc() { | ||
acquire(&pidnstable.lock); | ||
for (int i = 0; i < NNAMESPACE; i++) { | ||
struct pid_ns* pid_ns = &pidnstable.namespaces[i]; | ||
if (pid_ns->ref == 0) { | ||
pid_ns->ref = 1; | ||
release(&pidnstable.lock); | ||
return pid_ns; | ||
} | ||
} | ||
release(&pidnstable.lock); | ||
panic("out of pid_ns objects"); | ||
} | ||
|
||
void pid_ns_init_ns(struct pid_ns* pid_ns, struct pid_ns* parent) { | ||
pid_ns->parent = parent; | ||
pid_ns->next_pid = 1; | ||
} | ||
struct pid_ns* pid_ns_dup(struct pid_ns* pid_ns) { | ||
pid_ns_get(pid_ns); | ||
return pid_ns; | ||
} | ||
|
||
struct pid_ns* pid_ns_new(struct pid_ns* parent) { | ||
struct pid_ns * pid_ns = pid_ns_alloc(); | ||
pid_ns_init_ns(pid_ns, parent); | ||
return pid_ns; | ||
} | ||
|
||
int pid_ns_next_pid(struct pid_ns* pid_ns) { | ||
acquire(&pid_ns->lock); | ||
int pid = pid_ns->next_pid++; | ||
release(&pid_ns->lock); | ||
return pid; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#define MAX_PID_NS_DEPTH 4 | ||
|
||
struct pid_ns { | ||
int ref; | ||
struct pid_ns* parent; | ||
struct spinlock lock; | ||
int next_pid; | ||
}; | ||
|
||
void pid_ns_init(); | ||
void pid_ns_put(struct pid_ns* pid_ns); | ||
void pid_ns_get(struct pid_ns* pid_ns); | ||
int pid_ns_next_pid(struct pid_ns* pid_ns); | ||
struct pid_ns* pid_ns_new(struct pid_ns* parent); | ||
struct pid_ns* pid_ns_dup(struct pid_ns* pid_ns); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.