Re: [lxc-devel] do pid1 and pid2 run in the same network namespace
On 02/22/2011 07:41 AM, Maheswara Reddy C - ERS, HCL Tech wrote: > Hi All, > > > > Does this way both pid1 and pid2 run in the same network namespace? Or please > suggest any other way Mahesh, please tell us what you want to do. If you want to create a new network namespace, it is not mandatory to use clone. The following program will create a new network stack and all new processes will inherit this network namespace. #include #include #include int main(int argc, char *argv[]) { pid_t pid; if (unshare(CLONE_NEWNET)) { perror("unshare"); return 1; } pid = fork(); if (pid < 0) { perror("fork"); return 1; } if (!pid) { execl("/bin/bash", "/bin/bash", NULL); perror("execl"); } return waitpid(pid, NULL, 0); } I recommand you read the documentation http://lxc.sourceforge.net/doc/sigops/appcr.pdf Thanks -- Daniel -- Index, Search & Analyze Logs and other IT data in Real-Time with Splunk Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. Free Software Download: http://p.sf.net/sfu/splunk-dev2dev ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
Re: [lxc-devel] do pid1 and pid2 run in the same network namespace
Hi Daniel, I have to create 10 namespaces(network), in each namespace I have to run two different processes. Thanks Mahesh -Original Message- From: Daniel Lezcano [mailto:daniel.lezc...@free.fr] Sent: Tuesday, February 22, 2011 2:47 PM To: Maheswara Reddy C - ERS, HCL Tech Cc: lxc-devel@lists.sourceforge.net Subject: Re: [lxc-devel] do pid1 and pid2 run in the same network namespace On 02/22/2011 07:41 AM, Maheswara Reddy C - ERS, HCL Tech wrote: > Hi All, > > > > Does this way both pid1 and pid2 run in the same network namespace? Or please > suggest any other way Mahesh, please tell us what you want to do. If you want to create a new network namespace, it is not mandatory to use clone. The following program will create a new network stack and all new processes will inherit this network namespace. #include #include #include int main(int argc, char *argv[]) { pid_t pid; if (unshare(CLONE_NEWNET)) { perror("unshare"); return 1; } pid = fork(); if (pid < 0) { perror("fork"); return 1; } if (!pid) { execl("/bin/bash", "/bin/bash", NULL); perror("execl"); } return waitpid(pid, NULL, 0); } I recommand you read the documentation http://lxc.sourceforge.net/doc/sigops/appcr.pdf Thanks -- Daniel ::DISCLAIMER:: --- The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. It shall not attach any liability on the originator or HCL or its affiliates. Any views or opinions presented in this email are solely those of the author and may not necessarily reflect the opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. Before opening any mail and attachments please check them for viruses and defect. --- -- Index, Search & Analyze Logs and other IT data in Real-Time with Splunk Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. Free Software Download: http://p.sf.net/sfu/splunk-dev2dev ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
Re: [lxc-devel] do pid1 and pid2 run in the same network namespace
On 02/22/2011 10:44 AM, Maheswara Reddy C - ERS, HCL Tech wrote: > Hi Daniel, > > I have to create 10 namespaces(network), in each namespace I have to run two > different processes. Then it is quite easy. You just have to fork ten times the routine in the program I gave you in the previous email. > -Original Message- > From: Daniel Lezcano [mailto:daniel.lezc...@free.fr] > Sent: Tuesday, February 22, 2011 2:47 PM > To: Maheswara Reddy C - ERS, HCL Tech > Cc: lxc-devel@lists.sourceforge.net > Subject: Re: [lxc-devel] do pid1 and pid2 run in the same network namespace > > On 02/22/2011 07:41 AM, Maheswara Reddy C - ERS, HCL Tech wrote: >> Hi All, >> >> >> >> Does this way both pid1 and pid2 run in the same network namespace? Or >> please suggest any other way > Mahesh, > > please tell us what you want to do. > > If you want to create a new network namespace, it is not mandatory to > use clone. The following program will create a new network stack and all > new processes will inherit this network namespace. > > #include > #include > #include > > int main(int argc, char *argv[]) > { > > pid_t pid; > > if (unshare(CLONE_NEWNET)) { > perror("unshare"); > return 1; > } > > pid = fork(); > if (pid< 0) { > perror("fork"); > return 1; > } > > if (!pid) { > execl("/bin/bash", "/bin/bash", NULL); > perror("execl"); > } > > return waitpid(pid, NULL, 0); > } > > I recommand you read the documentation > http://lxc.sourceforge.net/doc/sigops/appcr.pdf > > Thanks > -- Daniel > > > > ::DISCLAIMER:: > --- > > The contents of this e-mail and any attachment(s) are confidential and > intended for the named recipient(s) only. > It shall not attach any liability on the originator or HCL or its affiliates. > Any views or opinions presented in > this email are solely those of the author and may not necessarily reflect the > opinions of HCL or its affiliates. > Any form of reproduction, dissemination, copying, disclosure, modification, > distribution and / or publication of > this message without the prior written consent of the author of this e-mail > is strictly prohibited. If you have > received this email in error please delete it and notify the sender > immediately. Before opening any mail and > attachments please check them for viruses and defect. > > --- > -- Index, Search & Analyze Logs and other IT data in Real-Time with Splunk Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. Free Software Download: http://p.sf.net/sfu/splunk-dev2dev ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
Re: [lxc-devel] do pid1 and pid2 run in the same network namespace
>Then it is quite easy. You just have to fork ten times the routine in the >program I gave you in the previous email. Hi Daniel, But I want to run two different (fork() run same copy) process/threads in each namespace, that's why I am using clone() which take function pointer of each process/thered to start. Thanks Mahesh > -Original Message- > From: Daniel Lezcano [mailto:daniel.lezc...@free.fr] > Sent: Tuesday, February 22, 2011 2:47 PM > To: Maheswara Reddy C - ERS, HCL Tech > Cc: lxc-devel@lists.sourceforge.net > Subject: Re: [lxc-devel] do pid1 and pid2 run in the same network namespace > > On 02/22/2011 07:41 AM, Maheswara Reddy C - ERS, HCL Tech wrote: >> Hi All, >> >> >> >> Does this way both pid1 and pid2 run in the same network namespace? Or >> please suggest any other way > Mahesh, > > please tell us what you want to do. > > If you want to create a new network namespace, it is not mandatory to > use clone. The following program will create a new network stack and all > new processes will inherit this network namespace. > > #include > #include > #include > > int main(int argc, char *argv[]) > { > > pid_t pid; > > if (unshare(CLONE_NEWNET)) { > perror("unshare"); > return 1; > } > > pid = fork(); > if (pid< 0) { > perror("fork"); > return 1; > } > > if (!pid) { > execl("/bin/bash", "/bin/bash", NULL); > perror("execl"); > } > > return waitpid(pid, NULL, 0); > } > > I recommand you read the documentation > http://lxc.sourceforge.net/doc/sigops/appcr.pdf > > Thanks > -- Daniel > > > > ::DISCLAIMER:: > --- > > The contents of this e-mail and any attachment(s) are confidential and > intended for the named recipient(s) only. > It shall not attach any liability on the originator or HCL or its affiliates. > Any views or opinions presented in > this email are solely those of the author and may not necessarily reflect the > opinions of HCL or its affiliates. > Any form of reproduction, dissemination, copying, disclosure, modification, > distribution and / or publication of > this message without the prior written consent of the author of this e-mail > is strictly prohibited. If you have > received this email in error please delete it and notify the sender > immediately. Before opening any mail and > attachments please check them for viruses and defect. > > --- > -- Index, Search & Analyze Logs and other IT data in Real-Time with Splunk Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. Free Software Download: http://p.sf.net/sfu/splunk-dev2dev ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] Two different (functionality) processes in same namespace
Hi, Shall I program this way to create 10 namespaces, with each namespace run 2 different processes or any better way. #include #include #include int main(int argc, char *argv[]) { for(i=0;i<10;i++) { pid_t pid1[10],pid2[10]; int flag1= CLONE_NEWNS|CLONE_NETNET, flag2=0; int(*fun1[10]( ); // initialize statically int(*fun2[10]( ); Pid1[i] = clone(fun1[i],0,flag1,0); // process 1 Pid2[i] = clone(fun2[i],0,flag2,0); // process 2 } } ::DISCLAIMER:: --- The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. It shall not attach any liability on the originator or HCL or its affiliates. Any views or opinions presented in this email are solely those of the author and may not necessarily reflect the opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. Before opening any mail and attachments please check them for viruses and defect. --- -- Index, Search & Analyze Logs and other IT data in Real-Time with Splunk Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. Free Software Download: http://p.sf.net/sfu/splunk-dev2dev ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
Re: [lxc-devel] do pid1 and pid2 run in the same network namespace
On 02/22/2011 12:22 PM, Maheswara Reddy C - ERS, HCL Tech wrote: >> Then it is quite easy. You just have to fork ten times the routine in the >> program I gave you in the previous email. > Hi Daniel, > > But I want to run two different (fork() run same copy) process/threads in > each namespace, that's why I am using clone() which take function pointer of > each process/thered to start. Have fun ;) #include #include #include #include #include #include #include #define NRNS 10 int myroutine1(void) { return 0; } int myroutine2(void) { return 0; } int main(int argc, char *argv[]) { int i; pid_t pid; for (i = 0; i< NRNS; i++) { /* create a new network namespace for my childs */ if (unshare(CLONE_NEWNET)) { perror("unshare"); return 1; } pid = fork(); if (pid< 0) { perror("fork"); return 1; } if (!pid) exit(myroutine1()); pid = fork(); if (pid< 0) { perror("fork2"); return 1; } if (!pid) exit(myroutine2()); } /* create a new netns to not share with the last one * At the end we have 10 netns + 1 this one */ if (unshare(CLONE_NEWNET)) { perror("unshare2"); return 1; } for (;;) { pid = wait(NULL); if (pid< 0) { if (errno == ECHILD) return 0; if (errno == EINTR) continue; perror("wait"); return 1; } } } -- Index, Search & Analyze Logs and other IT data in Real-Time with Splunk Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. Free Software Download: http://p.sf.net/sfu/splunk-dev2dev ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
Re: [lxc-devel] Two different (functionality) processes in same namespace
On 02/22/2011 12:47 PM, Maheswara Reddy C - ERS, HCL Tech wrote: > Hi, > Shall I program this way to create 10 namespaces, with each namespace run 2 > different processes or any better way. > > #include > #include > #include > > int main(int argc, char *argv[]) > { > > for(i=0;i<10;i++) > { > pid_t pid1[10],pid2[10]; > > int flag1= CLONE_NEWNS|CLONE_NETNET, flag2=0; > > int(*fun1[10]( ); // initialize statically > int(*fun2[10]( ); > > >Pid1[i] = clone(fun1[i],0,flag1,0); // process 1 Process Pid1[i] will have its own network namespace. >Pid2[i] = clone(fun2[i],0,flag2,0); // process 2 > Process Pid2[i] will inherit the initial network namespace... I guess that isn't what you want. If you want Pid2[i] to be in the same network namespace as Pid1[i], then Pid2[i] should be a child of Pid1[i]. Or as Daniel suggests in another mail, consider using unshare(). > } > > } > > > ::DISCLAIMER:: > --- > > The contents of this e-mail and any attachment(s) are confidential and > intended for the named recipient(s) only. > It shall not attach any liability on the originator or HCL or its affiliates. > Any views or opinions presented in > this email are solely those of the author and may not necessarily reflect the > opinions of HCL or its affiliates. > Any form of reproduction, dissemination, copying, disclosure, modification, > distribution and / or publication of > this message without the prior written consent of the author of this e-mail > is strictly prohibited. If you have > received this email in error please delete it and notify the sender > immediately. Before opening any mail and > attachments please check them for viruses and defect. > > --- > > -- > Index, Search& Analyze Logs and other IT data in Real-Time with Splunk > Collect, index and harness all the fast moving IT data generated by your > applications, servers and devices whether physical, virtual or in the cloud. > Deliver compliance at lower cost and gain new business insights. > Free Software Download: http://p.sf.net/sfu/splunk-dev2dev > ___ > Lxc-devel mailing list > Lxc-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/lxc-devel -- Gregory Kurz gk...@fr.ibm.com Software Engineer @ IBM/Meiosys http://www.ibm.com Tel +33 (0)534 638 479 Fax +33 (0)561 400 420 "Anarchy is about taking complete responsibility for yourself." Alan Moore. -- Index, Search & Analyze Logs and other IT data in Real-Time with Splunk Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. Free Software Download: http://p.sf.net/sfu/splunk-dev2dev ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] Anybody looked at unshare(2)?
It looks like clone flags aren't the only way to create a new namespace, any existing process can move to a new namespace via unshare(2). This sounds like you could fairly easily make a super_chroot() function that does most of the container stuff. The hard part would be doing mount points, device setup, and TTY I/O. (How much of this requires a host daemon? I still haven't properly investigated how the current container TTY stuff behind lxc-console works...) Rob -- Free Software Download: Index, Search & Analyze Logs and other IT data in Real-Time with Splunk. Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. http://p.sf.net/sfu/splunk-dev2dev ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] Anybody used FUSE in a container?
After investigating I don't see any reason sshfs shouldn't work just fine in a container out of the box (all the network stuff happens in userspace), but I can't create the FUSE dev node from within the container because mknod doesn't work from the container's root. I thought the point of linking in a capabilities library was to let the container's root do that sort of thing? What's the status of dev namespaces in current vanilla? Rob -- Free Software Download: Index, Search & Analyze Logs and other IT data in Real-Time with Splunk. Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. http://p.sf.net/sfu/splunk-dev2dev ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
Re: [lxc-devel] do pid1 and pid2 run in the same network namespace
Hi Daniel, We could able to create ten (N) number of namespaces, how can we identify the specified namespace. Shall we use the return value of unshare() , as unique namespace ID ? Thanks Mahesh -Original Message- From: Daniel Lezcano [mailto:daniel.lezc...@free.fr] Sent: Tuesday, February 22, 2011 5:26 PM To: Maheswara Reddy C - ERS, HCL Tech Cc: lxc-devel@lists.sourceforge.net Subject: Re: [lxc-devel] do pid1 and pid2 run in the same network namespace On 02/22/2011 12:22 PM, Maheswara Reddy C - ERS, HCL Tech wrote: >> Then it is quite easy. You just have to fork ten times the routine in the >> program I gave you in the previous email. > Hi Daniel, > > But I want to run two different (fork() run same copy) process/threads in > each namespace, that's why I am using clone() which take function pointer of > each process/thered to start. Have fun ;) #include #include #include #include #include #include #include #define NRNS 10 int myroutine1(void) { return 0; } int myroutine2(void) { return 0; } int main(int argc, char *argv[]) { int i; pid_t pid; for (i = 0; i< NRNS; i++) { /* create a new network namespace for my childs */ if (unshare(CLONE_NEWNET)) { perror("unshare"); return 1; } pid = fork(); if (pid< 0) { perror("fork"); return 1; } if (!pid) exit(myroutine1()); pid = fork(); if (pid< 0) { perror("fork2"); return 1; } if (!pid) exit(myroutine2()); } /* create a new netns to not share with the last one * At the end we have 10 netns + 1 this one */ if (unshare(CLONE_NEWNET)) { perror("unshare2"); return 1; } for (;;) { pid = wait(NULL); if (pid< 0) { if (errno == ECHILD) return 0; if (errno == EINTR) continue; perror("wait"); return 1; } } } ::DISCLAIMER:: --- The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. It shall not attach any liability on the originator or HCL or its affiliates. Any views or opinions presented in this email are solely those of the author and may not necessarily reflect the opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. Before opening any mail and attachments please check them for viruses and defect. --- -- Free Software Download: Index, Search & Analyze Logs and other IT data in Real-Time with Splunk. Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. http://p.sf.net/sfu/splunk-dev2dev ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel