diff mbox series

[080/104] virtiofsd: add helper for lo_data cleanup

Message ID 20191212163904.159893-81-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: Liu Bo <bo.liu@linux.alibaba.com>

This offers an helper function for lo_data's cleanup.

Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
---
 tools/virtiofsd/passthrough_ll.c | 37 ++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 16 deletions(-)

Comments

Daniel P. Berrangé Jan. 7, 2020, 11:40 a.m. UTC | #1
On Thu, Dec 12, 2019 at 04:38:40PM +0000, Dr. David Alan Gilbert (git) wrote:
> From: Liu Bo <bo.liu@linux.alibaba.com>
> 
> This offers an helper function for lo_data's cleanup.
> 
> Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
> ---
>  tools/virtiofsd/passthrough_ll.c | 37 ++++++++++++++++++--------------
>  1 file changed, 21 insertions(+), 16 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


> 
> diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
> index 45cf466178..097033aa00 100644
> --- a/tools/virtiofsd/passthrough_ll.c
> +++ b/tools/virtiofsd/passthrough_ll.c
> @@ -2439,6 +2439,26 @@ static gboolean lo_key_equal(gconstpointer a, gconstpointer b)
>      return la->ino == lb->ino && la->dev == lb->dev;
>  }
>  
> +static void fuse_lo_data_cleanup(struct lo_data *lo)
> +{
> +    if (lo->inodes) {
> +        g_hash_table_destroy(lo->inodes);
> +    }
> +    lo_map_destroy(&lo->fd_map);
> +    lo_map_destroy(&lo->dirp_map);
> +    lo_map_destroy(&lo->ino_map);
> +
> +    if (lo->proc_self_fd >= 0) {
> +        close(lo->proc_self_fd);
> +    }
> +
> +    if (lo->root.fd >= 0) {
> +        close(lo->root.fd);
> +    }
> +
> +    free((char *)lo->source);

This will need changing if you follow my comment on prev patch about
removing the const & cast

> +}
> +
>  int main(int argc, char *argv[])
>  {
>      struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
> @@ -2594,22 +2614,7 @@ err_out2:
>  err_out1:
>      fuse_opt_free_args(&args);
>  
> -    if (lo.inodes) {
> -        g_hash_table_destroy(lo.inodes);
> -    }
> -    lo_map_destroy(&lo.fd_map);
> -    lo_map_destroy(&lo.dirp_map);
> -    lo_map_destroy(&lo.ino_map);
> -
> -    if (lo.proc_self_fd >= 0) {
> -        close(lo.proc_self_fd);
> -    }
> -
> -    if (lo.root.fd >= 0) {
> -        close(lo.root.fd);
> -    }
> -
> -    free((char *)lo.source);
> +    fuse_lo_data_cleanup(&lo);
>  
>      return ret ? 1 : 0;
>  }
> -- 
> 2.23.0
> 
> 

Regards,
Daniel
Dr. David Alan Gilbert Jan. 9, 2020, 5:41 p.m. UTC | #2
* Daniel P. Berrangé (berrange@redhat.com) wrote:
> On Thu, Dec 12, 2019 at 04:38:40PM +0000, Dr. David Alan Gilbert (git) wrote:
> > From: Liu Bo <bo.liu@linux.alibaba.com>
> > 
> > This offers an helper function for lo_data's cleanup.
> > 
> > Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
> > ---
> >  tools/virtiofsd/passthrough_ll.c | 37 ++++++++++++++++++--------------
> >  1 file changed, 21 insertions(+), 16 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Thanks.

> 
> > 
> > diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
> > index 45cf466178..097033aa00 100644
> > --- a/tools/virtiofsd/passthrough_ll.c
> > +++ b/tools/virtiofsd/passthrough_ll.c
> > @@ -2439,6 +2439,26 @@ static gboolean lo_key_equal(gconstpointer a, gconstpointer b)
> >      return la->ino == lb->ino && la->dev == lb->dev;
> >  }
> >  
> > +static void fuse_lo_data_cleanup(struct lo_data *lo)
> > +{
> > +    if (lo->inodes) {
> > +        g_hash_table_destroy(lo->inodes);
> > +    }
> > +    lo_map_destroy(&lo->fd_map);
> > +    lo_map_destroy(&lo->dirp_map);
> > +    lo_map_destroy(&lo->ino_map);
> > +
> > +    if (lo->proc_self_fd >= 0) {
> > +        close(lo->proc_self_fd);
> > +    }
> > +
> > +    if (lo->root.fd >= 0) {
> > +        close(lo->root.fd);
> > +    }
> > +
> > +    free((char *)lo->source);
> 
> This will need changing if you follow my comment on prev patch about
> removing the const & cast

Done.

> 
> > +}
> > +
> >  int main(int argc, char *argv[])
> >  {
> >      struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
> > @@ -2594,22 +2614,7 @@ err_out2:
> >  err_out1:
> >      fuse_opt_free_args(&args);
> >  
> > -    if (lo.inodes) {
> > -        g_hash_table_destroy(lo.inodes);
> > -    }
> > -    lo_map_destroy(&lo.fd_map);
> > -    lo_map_destroy(&lo.dirp_map);
> > -    lo_map_destroy(&lo.ino_map);
> > -
> > -    if (lo.proc_self_fd >= 0) {
> > -        close(lo.proc_self_fd);
> > -    }
> > -
> > -    if (lo.root.fd >= 0) {
> > -        close(lo.root.fd);
> > -    }
> > -
> > -    free((char *)lo.source);
> > +    fuse_lo_data_cleanup(&lo);
> >  
> >      return ret ? 1 : 0;
> >  }
> > -- 
> > 2.23.0
> > 
> > 
> 
> Regards,
> Daniel
> -- 
> |: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org         -o-            https://fstop138.berrange.com :|
> |: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
diff mbox series

Patch

diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 45cf466178..097033aa00 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -2439,6 +2439,26 @@  static gboolean lo_key_equal(gconstpointer a, gconstpointer b)
     return la->ino == lb->ino && la->dev == lb->dev;
 }
 
+static void fuse_lo_data_cleanup(struct lo_data *lo)
+{
+    if (lo->inodes) {
+        g_hash_table_destroy(lo->inodes);
+    }
+    lo_map_destroy(&lo->fd_map);
+    lo_map_destroy(&lo->dirp_map);
+    lo_map_destroy(&lo->ino_map);
+
+    if (lo->proc_self_fd >= 0) {
+        close(lo->proc_self_fd);
+    }
+
+    if (lo->root.fd >= 0) {
+        close(lo->root.fd);
+    }
+
+    free((char *)lo->source);
+}
+
 int main(int argc, char *argv[])
 {
     struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
@@ -2594,22 +2614,7 @@  err_out2:
 err_out1:
     fuse_opt_free_args(&args);
 
-    if (lo.inodes) {
-        g_hash_table_destroy(lo.inodes);
-    }
-    lo_map_destroy(&lo.fd_map);
-    lo_map_destroy(&lo.dirp_map);
-    lo_map_destroy(&lo.ino_map);
-
-    if (lo.proc_self_fd >= 0) {
-        close(lo.proc_self_fd);
-    }
-
-    if (lo.root.fd >= 0) {
-        close(lo.root.fd);
-    }
-
-    free((char *)lo.source);
+    fuse_lo_data_cleanup(&lo);
 
     return ret ? 1 : 0;
 }