Re: method for communication between containers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear Daniel,
Your suggestion is right. I followed your method and used mmap(), it works well. Now I can realize data exchange between containers.
Thank you for your help.
Cheng

-----Original Message-----
From: Daniel P. Berrange [mailto:berrange@xxxxxxxxxx] 
Sent: 2014年3月3日 21:42
To: WANG Cheng D
Cc: libvirt-users@xxxxxxxxxx
Subject: Re:  method for communication between containers

On Mon, Mar 03, 2014 at 01:39:03PM +0000, WANG Cheng D wrote:
> Dear Daniel,
> Thank you for your email.
> According to your suggestion, I tried to use the shared memory filesystem for data exchange between the host machine and the container. The steps are as follows:
> 
> 1) create an empty file in the host machine (/tmp1/file1).
> 2) run #chmod 777 /tmp1 and #chmod 777 /tmp1/file1.
> 3) expose /tmp1 to the container by configuring the container with the following XML scripts.
>      <filesystem type="mount" accessmode="passthrough">
>       <source dir="/tmp1"/>
>       <target dir="/tmp1"/>
>     </filesystem>
> 4) write two programs: program1 writes a string to the shared memory
>                    program2 reads the string from the shared memory
>    and compile both programs in the host machine.
>    both of the two programs use ftok() and shmget() to obtain the shmfs id.
> 5) a. if we run both program1 and program2 in the host machine, the program2 can read the string that program1 has written.
>   b. if we run both program1 and program2 in the container, both programs also work well.
>   c. if we run program1 in the host and run program2 in the container,
>    program2 fails. the ftok() function can return the expected value,
>    but shmget(...,0,0) fails and prompts "No such files". It seems that
>    the exposed file cannot be recognized by shmget() function, although
>    ftok() can work and return the value.
> 
> Do you have an idea?

Yes, the IPCS namespace causes the container's 'shmget' call to be isolated from the host, so using shmget & other similar SysV-IPC APIs will fail.

What I was thinking though was that you'd be able to open() the file in the shared memory fs, and then use mmap() to map its data into RAM in the container. 

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

_______________________________________________
libvirt-users mailing list
libvirt-users@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvirt-users





[Index of Archives]     [Virt Tools]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]

  Powered by Linux