diff mbox series

[071/104] virtiofsd: extract root inode init into setup_root()

Message ID 20191212163904.159893-72-dgilbert@redhat.com
State New
Headers show
Series virtiofs daemon [all] | expand

Commit Message

Dr. David Alan Gilbert Dec. 12, 2019, 4:38 p.m. UTC
From: Miklos Szeredi <mszeredi@redhat.com>

Inititialize the root inode in a single place.

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 tools/virtiofsd/passthrough_ll.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

Comments

Misono Tomohiro Jan. 16, 2020, 7:20 a.m. UTC | #1
> From: Miklos Szeredi <mszeredi@redhat.com>
> 
> Inititialize the root inode in a single place.
> 
> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  tools/virtiofsd/passthrough_ll.c | 26 ++++++++++++++++++++++++--
>  1 file changed, 24 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
> index ef8b88e3d1..0f33c3c5e9 100644
> --- a/tools/virtiofsd/passthrough_ll.c
> +++ b/tools/virtiofsd/passthrough_ll.c
> @@ -2336,6 +2336,29 @@ static void log_func(enum fuse_log_level level, const char *_fmt, va_list ap)
>      }
>  }
>  
> +static void setup_root(struct lo_data *lo, struct lo_inode *root)
> +{
> +    int fd, res;
> +    struct stat stat;
> +
> +    fd = open("/", O_PATH);
> +    if (fd == -1) {
> +        fuse_log(FUSE_LOG_ERR, "open(%s, O_PATH): %m\n", lo->source);
> +        exit(1);
> +    }
> +
> +    res = fstatat(fd, "", &stat, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
> +    if (res == -1) {
> +        fuse_log(FUSE_LOG_ERR, "fstatat(%s): %m\n", lo->source);
> +        exit(1);
> +    }
> +
> +    root->fd = fd;
> +    root->ino = stat.st_ino;
> +    root->dev = stat.st_dev;
> +    root->refcount = 2;
> +}
> +
>  int main(int argc, char *argv[])
>  {
>      struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
> @@ -2411,8 +2434,6 @@ int main(int argc, char *argv[])
>      if (lo.debug) {
>          current_log_level = FUSE_LOG_DEBUG;
>      }
> -    lo.root.refcount = 2;
> -
>      if (lo.source) {
>          struct stat stat;
>          int res;
> @@ -2480,6 +2501,7 @@ int main(int argc, char *argv[])
>  
>      setup_sandbox(&lo, se, opts.syslog);
>  
> +    setup_root(&lo, &lo.root);
>      /* Block until ctrl+c or fusermount -u */
>      ret = virtio_loop(se);

Following block still remains in main():
2933    lo.root.is_symlink = false;
...
2952    lo.root.fd = open(lo.source, O_PATH);
2953
2954    if (lo.root.fd == -1) {
2955        fuse_log(FUSE_LOG_ERR, "open(\"%s\", O_PATH): %m\n", lo.source);
2956        exit(1);
2957    }

L.2933 should be included in lo_setup_root() and can we just remove L.2952-2957?

Thanks,
Misono
Dr. David Alan Gilbert Jan. 16, 2020, 3:51 p.m. UTC | #2
* Misono Tomohiro (misono.tomohiro@jp.fujitsu.com) wrote:
> > From: Miklos Szeredi <mszeredi@redhat.com>
> > 
> > Inititialize the root inode in a single place.
> > 
> > Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
> > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> > ---
> >  tools/virtiofsd/passthrough_ll.c | 26 ++++++++++++++++++++++++--
> >  1 file changed, 24 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
> > index ef8b88e3d1..0f33c3c5e9 100644
> > --- a/tools/virtiofsd/passthrough_ll.c
> > +++ b/tools/virtiofsd/passthrough_ll.c
> > @@ -2336,6 +2336,29 @@ static void log_func(enum fuse_log_level level, const char *_fmt, va_list ap)
> >      }
> >  }
> >  
> > +static void setup_root(struct lo_data *lo, struct lo_inode *root)
> > +{
> > +    int fd, res;
> > +    struct stat stat;
> > +
> > +    fd = open("/", O_PATH);
> > +    if (fd == -1) {
> > +        fuse_log(FUSE_LOG_ERR, "open(%s, O_PATH): %m\n", lo->source);
> > +        exit(1);
> > +    }
> > +
> > +    res = fstatat(fd, "", &stat, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
> > +    if (res == -1) {
> > +        fuse_log(FUSE_LOG_ERR, "fstatat(%s): %m\n", lo->source);
> > +        exit(1);
> > +    }
> > +
> > +    root->fd = fd;
> > +    root->ino = stat.st_ino;
> > +    root->dev = stat.st_dev;
> > +    root->refcount = 2;
> > +}
> > +
> >  int main(int argc, char *argv[])
> >  {
> >      struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
> > @@ -2411,8 +2434,6 @@ int main(int argc, char *argv[])
> >      if (lo.debug) {
> >          current_log_level = FUSE_LOG_DEBUG;
> >      }
> > -    lo.root.refcount = 2;
> > -
> >      if (lo.source) {
> >          struct stat stat;
> >          int res;
> > @@ -2480,6 +2501,7 @@ int main(int argc, char *argv[])
> >  
> >      setup_sandbox(&lo, se, opts.syslog);
> >  
> > +    setup_root(&lo, &lo.root);
> >      /* Block until ctrl+c or fusermount -u */
> >      ret = virtio_loop(se);
> 
> Following block still remains in main():
> 2933    lo.root.is_symlink = false;
> ...
> 2952    lo.root.fd = open(lo.source, O_PATH);
> 2953
> 2954    if (lo.root.fd == -1) {
> 2955        fuse_log(FUSE_LOG_ERR, "open(\"%s\", O_PATH): %m\n", lo.source);
> 2956        exit(1);
> 2957    }
> 
> L.2933 should be included in lo_setup_root() and can we just remove L.2952-2957?

Yes agreed; thanks I've fixed that up.

Dave

> Thanks,
> Misono
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
Sergio Lopez Jan. 20, 2020, 10:09 a.m. UTC | #3
Dr. David Alan Gilbert (git) <dgilbert@redhat.com> writes:

> From: Miklos Szeredi <mszeredi@redhat.com>
>
> Inititialize the root inode in a single place.
>
> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  tools/virtiofsd/passthrough_ll.c | 26 ++++++++++++++++++++++++--
>  1 file changed, 24 insertions(+), 2 deletions(-)

Reviewed-by: Sergio Lopez <slp@redhat.com>
diff mbox series

Patch

diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index ef8b88e3d1..0f33c3c5e9 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -2336,6 +2336,29 @@  static void log_func(enum fuse_log_level level, const char *_fmt, va_list ap)
     }
 }
 
+static void setup_root(struct lo_data *lo, struct lo_inode *root)
+{
+    int fd, res;
+    struct stat stat;
+
+    fd = open("/", O_PATH);
+    if (fd == -1) {
+        fuse_log(FUSE_LOG_ERR, "open(%s, O_PATH): %m\n", lo->source);
+        exit(1);
+    }
+
+    res = fstatat(fd, "", &stat, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
+    if (res == -1) {
+        fuse_log(FUSE_LOG_ERR, "fstatat(%s): %m\n", lo->source);
+        exit(1);
+    }
+
+    root->fd = fd;
+    root->ino = stat.st_ino;
+    root->dev = stat.st_dev;
+    root->refcount = 2;
+}
+
 int main(int argc, char *argv[])
 {
     struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
@@ -2411,8 +2434,6 @@  int main(int argc, char *argv[])
     if (lo.debug) {
         current_log_level = FUSE_LOG_DEBUG;
     }
-    lo.root.refcount = 2;
-
     if (lo.source) {
         struct stat stat;
         int res;
@@ -2480,6 +2501,7 @@  int main(int argc, char *argv[])
 
     setup_sandbox(&lo, se, opts.syslog);
 
+    setup_root(&lo, &lo.root);
     /* Block until ctrl+c or fusermount -u */
     ret = virtio_loop(se);