* Re: [patch 1/4][resend] fuse-procfs: proxy proc files [not found] ` <20090904165149.491603361-+lpkiSBCrgqwGcPS5fe+fxcU4LlsiAD9x8DZ0lRKBDr1ENwx4SLHqw@public.gmane.org> @ 2009-09-11 2:57 ` Serge E. Hallyn 2009-09-14 20:38 ` Krzysztof Taraszka 1 sibling, 0 replies; 5+ messages in thread From: Serge E. Hallyn @ 2009-09-11 2:57 UTC (permalink / raw) To: Daniel Lezcano Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, kt-S89nZTSLPHGGdvJs77BJ7Q, lxc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f Quoting Daniel Lezcano (daniel.lezcano-GANU6spQydw@public.gmane.org): > This patch makes possible to mount the fuse-procfs on top of /proc > and display the content of /proc via fuse. > > Signed-off-by: Daniel Lezcano <daniel.lezcano-GANU6spQydw@public.gmane.org> Thanks, Daniel. This is neat. How were you thinking of configuring this? A config file read at mount? Actually one question I have is: > +static int procfs_read(const char *path, char *buf, size_t size, > + off_t offset, struct fuse_file_info *fi) > +{ > + int ret; > + struct procfs_file *pfile = (typeof(pfile))fi->fh;; > + > + switch (pfile->type) { > + > + case PROCFS_PROXY: > + ret = read(pfile->file.proxy.fd, buf, size); Are you supposed to do something with the offset? I don't see any seek method in fuse_operations, does fuse keep the fp internally and send it along as offset to read? > + if (ret < 0) > + return -errno; > + break; > + } > + > + return ret; > +} -serge ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch 1/4][resend] fuse-procfs: proxy proc files [not found] ` <20090904165149.491603361-+lpkiSBCrgqwGcPS5fe+fxcU4LlsiAD9x8DZ0lRKBDr1ENwx4SLHqw@public.gmane.org> 2009-09-11 2:57 ` [patch 1/4][resend] fuse-procfs: proxy proc files Serge E. Hallyn @ 2009-09-14 20:38 ` Krzysztof Taraszka [not found] ` <ac1c4bf20909141338p3e13c1d6sc71899b7859bd963-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 1 sibling, 1 reply; 5+ messages in thread From: Krzysztof Taraszka @ 2009-09-14 20:38 UTC (permalink / raw) To: Daniel Lezcano Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, lxc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f Hi Daniel, right now I do not have any new tasks so I can take a look your patches and... they won't to apply (patches from 2 to 4). Can you send me your current procfs.c single file with patches added? Thanks -- K 2009/9/4 Daniel Lezcano <daniel.lezcano-GANU6spQydw@public.gmane.org> > This patch makes possible to mount the fuse-procfs on top of /proc > and display the content of /proc via fuse. > > Signed-off-by: Daniel Lezcano <daniel.lezcano-GANU6spQydw@public.gmane.org> > --- > procfs.c | 246 > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 246 insertions(+) > > Index: lxcfs/procfs.c > =================================================================== > --- /dev/null > +++ lxcfs/procfs.c > @@ -0,0 +1,246 @@ > + > +#include <fuse.h> > + > +#include <stdio.h> > +#include <stdlib.h> > +#include <string.h> > +#include <libgen.h> > +#include <errno.h> > +#include <dirent.h> > +#include <mntent.h> > +#include <limits.h> > +#include <fcntl.h> > +#include <sys/types.h> > +#include <sys/stat.h> > +#include <sys/param.h> > + > +enum { > + PROCFS_PROXY, > +}; > + > +struct procfs_info { > + DIR *procdir; > + DIR *subdir; > +}; > + > +struct proxy_file { > + int fd; > +}; > + > +struct procfs_file { > + int type; > + union { > + struct proxy_file proxy; > + } file; > +}; > + > +static int procfs_readlink(const char *path, char *buf, size_t bufsiz) > +{ > + struct fuse_context *context = fuse_get_context(); > + struct procfs_info *fsinfo = context->private_data; > + char *bname = strchr(path, '/'); > + int ret; > + > + if (strcmp(path, "/")) > + bname += 1; > + > + ret = readlinkat(dirfd(fsinfo->procdir), bname, buf, bufsiz); > + if (ret < 0) > + return -errno; > + > + buf[ret] = '\0'; > + > + return 0; > +} > + > +static int procfs_getattr(const char *path, struct stat *stbuf) > +{ > + struct fuse_context *context = fuse_get_context(); > + struct procfs_info *fsinfo = context->private_data; > + char *bname = strchr(path, '/'); > + > + if (strcmp(path, "/")) > + bname += 1; > + > + if (fstatat(dirfd(fsinfo->procdir), bname, stbuf, > AT_SYMLINK_NOFOLLOW)) > + return -errno; > + > + return 0; > +} > + > +static int procfs_open(const char *path, struct fuse_file_info *fi) > +{ > + struct fuse_context *context = fuse_get_context(); > + struct procfs_info *fsinfo = context->private_data; > + char *bname = strchr(path, '/'); > + struct procfs_file *pfile; > + > + if (strcmp(path, "/")) > + bname += 1; > + > + pfile = malloc(sizeof(*pfile)); > + if (!pfile) > + return -ENOMEM; > + > + pfile->type = PROCFS_PROXY; > + pfile->file.proxy.fd = openat(dirfd(fsinfo->procdir), bname, > fi->flags); > + if (pfile->file.proxy.fd < 0) { > + free(pfile); > + return -errno; > + } > + > + fi->fh = (typeof(fi->fh))pfile; > + > + return 0; > +} > + > +static int procfs_read(const char *path, char *buf, size_t size, > + off_t offset, struct fuse_file_info *fi) > +{ > + int ret; > + struct procfs_file *pfile = (typeof(pfile))fi->fh;; > + > + switch (pfile->type) { > + > + case PROCFS_PROXY: > + ret = read(pfile->file.proxy.fd, buf, size); > + if (ret < 0) > + return -errno; > + break; > + } > + > + return ret; > +} > + > +static int procfs_write(const char *path, const char *buf, size_t size, > + off_t offset, struct fuse_file_info *fi) > +{ > + int ret; > + struct procfs_file *pfile = (typeof(pfile))fi->fh;; > + > + switch (pfile->type) { > + > + case PROCFS_PROXY: > + ret = write(pfile->file.proxy.fd, buf, size); > + if (ret < 0) > + return -errno; > + break; > + } > + > + return ret; > +} > + > +static int procfs_release(const char *path, struct fuse_file_info *fi) > +{ > + struct procfs_file *pfile = (typeof(pfile))fi->fh;; > + > + switch (pfile->type) { > + > + case PROCFS_PROXY: > + if (close(pfile->file.proxy.fd)) > + return -errno; > + break; > + } > + > + return 0; > +} > + > +static int procfs_opendir(const char *path, struct fuse_file_info *fi) > +{ > + struct fuse_context *context = fuse_get_context(); > + struct procfs_info *fsinfo = context->private_data; > + char *bname = strchr(path, '/'); > + int fd; > + > + if (!strcmp(path, "/")) { > + fsinfo->subdir = fsinfo->procdir; > + return 0; > + } > + > + fd = openat(dirfd(fsinfo->procdir), bname + 1, O_DIRECTORY); > + if (fd < 0) > + return -errno; > + > + fsinfo->subdir = fdopendir(fd); > + > + return 0; > +} > + > +static int procfs_readdir(const char *path, void *buf, fuse_fill_dir_t > filler, > + off_t offset, struct fuse_file_info *fi) > +{ > + struct fuse_context *context = fuse_get_context(); > + struct procfs_info *fsinfo = context->private_data; > + struct dirent dirent, *direntp; > + > + if (!offset) > + rewinddir(fsinfo->subdir); > + > + while (!readdir_r(fsinfo->subdir, &dirent, &direntp) && direntp) > + if (filler(buf, direntp->d_name, NULL, offset++)) > + break; > + > + return 0; > +} > + > +static int procfs_releasedir(const char *path, struct fuse_file_info *fi) > +{ > + struct fuse_context *context = fuse_get_context(); > + struct procfs_info *fsinfo = context->private_data; > + DIR *subdir = fsinfo->subdir; > + > + fsinfo->subdir = NULL; > + if (subdir && subdir != fsinfo->procdir) > + closedir(subdir); > + > + return 0; > +} > + > +static void *procfs_init(struct fuse_conn_info *conn) > +{ > + struct procfs_info *fsinfo; > + > + fsinfo = malloc(sizeof(*fsinfo)); > + if (!fsinfo) > + return NULL; > + > + fsinfo->procdir = opendir("/proc"); > + if (!fsinfo->procdir) > + goto out_free_fsinfo; > + > + fsinfo->subdir = NULL; > +out: > + return fsinfo; > + > +out_free_fsinfo: > + free(fsinfo); > + fsinfo = NULL; > + goto out; > +} > + > +static void procfs_destroy(void *private_data) > +{ > + struct procfs_info *fsinfo = private_data; > + > + closedir(fsinfo->procdir); > + free(fsinfo); > +} > + > +static struct fuse_operations procfs_ops = { > + .readlink = procfs_readlink, > + .getattr = procfs_getattr, > + .open = procfs_open, > + .read = procfs_read, > + .write = procfs_write, > + .opendir = procfs_opendir, > + .releasedir = procfs_releasedir, > + .readdir = procfs_readdir, > + .release = procfs_release, > + .init = procfs_init, > + .destroy = procfs_destroy, > +}; > + > +int main(int argc, char *argv[]) > +{ > + return fuse_main(argc, argv, &procfs_ops, NULL); > +} > > ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <ac1c4bf20909141338p3e13c1d6sc71899b7859bd963-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [patch 1/4][resend] fuse-procfs: proxy proc files [not found] ` <ac1c4bf20909141338p3e13c1d6sc71899b7859bd963-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2009-09-14 21:13 ` Daniel Lezcano [not found] ` <4AAEB1FA.3070102-GANU6spQydw@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Daniel Lezcano @ 2009-09-14 21:13 UTC (permalink / raw) To: kt-S89nZTSLPHGGdvJs77BJ7Q Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, lxc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f [-- Attachment #1: Type: text/plain, Size: 384 bytes --] Krzysztof Taraszka wrote: > Hi Daniel, > > right now I do not have any new tasks so I can take a look your patches > and... they won't to apply (patches from 2 to 4). > Can you send me your current procfs.c single file with patches added? > > Thanks > Sure, in attachment the procfs.tar.gz which is a directory containing the patches. Just untar and quilt push -a. -- Daniel [-- Attachment #2: procfs.tar.gz --] [-- Type: application/x-gzip, Size: 6688 bytes --] [-- Attachment #3: Type: text/plain, Size: 206 bytes --] _______________________________________________ Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org https://lists.linux-foundation.org/mailman/listinfo/containers ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <4AAEB1FA.3070102-GANU6spQydw@public.gmane.org>]
* Re: [patch 1/4][resend] fuse-procfs: proxy proc files [not found] ` <4AAEB1FA.3070102-GANU6spQydw@public.gmane.org> @ 2009-09-28 9:33 ` Krzysztof Taraszka [not found] ` <ac1c4bf20909280233r5cd94343m30ac00c6ef9e1d10-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Krzysztof Taraszka @ 2009-09-28 9:33 UTC (permalink / raw) To: Daniel Lezcano Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, lxc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f Thank you Daniel. I have a little problem with fuse and containers. Do I have to add the fuse device to the container? When I tried to mount procfs I received: container2:/# ./procfs -odirect_io /proc/meminfo fuse: device not found, try 'modprobe fuse' first The fuse module was loaded on host. What I did wrong? I am asking because I am working around user space scripts for managing lxc (written in bash, init.d script, few lxc-create-* scripts based on distro, etc) and I would like to add this development future to this scripts. Right now I have few nice and good looking userspace scripts. Would be great If I may do the deb and rpm package with lxc user scripts and lxc-tools or add my scripts to lxc-tools tree. More about that in this week in the different thread. Hope you will give me the direction guys. 2009/9/14 Daniel Lezcano <daniel.lezcano-GANU6spQydw@public.gmane.org> > Krzysztof Taraszka wrote: > >> Hi Daniel, >> >> right now I do not have any new tasks so I can take a look your patches >> and... they won't to apply (patches from 2 to 4). >> Can you send me your current procfs.c single file with patches added? >> >> Thanks >> >> > Sure, in attachment the procfs.tar.gz which is a directory containing the > patches. > Just untar and quilt push -a. > > -- Daniel > > > ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <ac1c4bf20909280233r5cd94343m30ac00c6ef9e1d10-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [patch 1/4][resend] fuse-procfs: proxy proc files [not found] ` <ac1c4bf20909280233r5cd94343m30ac00c6ef9e1d10-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2009-09-28 15:47 ` Daniel Lezcano 0 siblings, 0 replies; 5+ messages in thread From: Daniel Lezcano @ 2009-09-28 15:47 UTC (permalink / raw) To: kt-S89nZTSLPHGGdvJs77BJ7Q Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, lxc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f Krzysztof Taraszka wrote: > Thank you Daniel. > I have a little problem with fuse and containers. Do I have to add the fuse > device to the container? > When I tried to mount procfs I received: > > container2:/# ./procfs -odirect_io /proc/meminfo > fuse: device not found, try 'modprobe fuse' first > > The fuse module was loaded on host. What I did wrong? I am asking because I > am working around user space scripts for managing lxc (written in bash, > init.d script, few lxc-create-* scripts based on distro, etc) and I would > like to add this development future to this scripts. > Right now I have few nice and good looking userspace scripts. > Would be great If I may do the deb and rpm package with lxc user scripts and > lxc-tools or add my scripts to lxc-tools tree. > Let's see :) > More about that in this week in the different thread. Hope you will give me > the direction guys. > I think the command line is not right. Fuse uses at the /proc directory when initializating, so that have to be done in two steps: Can you try: lxc-execute -n foo /bin/bash (from the shell in the container): procfs -o direct_io /tmp/<tmpdir> mount --bind /tmp/<tmpdir> /proc echo 268435456 > /cgroup/foo/memory.memsw.limit_in_bytes echo 268435456 > /cgroup/foo/memory.limit_in_bytes * before exiting the container: umount /proc fusermount -u /tmp/<tmpfile> If you do 'ls /proc', you should see everything expect the /proc/sys directory. If you do 'cat /proc/meminfo', you should see: MemTotal: 262144 kB MemFree: 250684 kB SwapTotal: 262144 kB SwapFree: 0 kB ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-09-28 15:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20090904162556.407556958@mai-009101017029.toulouse-stg.fr.ibm.com>
[not found] ` <20090904165149.491603361@mai-009101017029.toulouse-stg.fr.ibm.com>
[not found] ` <20090904165149.491603361-+lpkiSBCrgqwGcPS5fe+fxcU4LlsiAD9x8DZ0lRKBDr1ENwx4SLHqw@public.gmane.org>
2009-09-11 2:57 ` [patch 1/4][resend] fuse-procfs: proxy proc files Serge E. Hallyn
2009-09-14 20:38 ` Krzysztof Taraszka
[not found] ` <ac1c4bf20909141338p3e13c1d6sc71899b7859bd963-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-09-14 21:13 ` Daniel Lezcano
[not found] ` <4AAEB1FA.3070102-GANU6spQydw@public.gmane.org>
2009-09-28 9:33 ` Krzysztof Taraszka
[not found] ` <ac1c4bf20909280233r5cd94343m30ac00c6ef9e1d10-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-09-28 15:47 ` Daniel Lezcano
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.