bug-hurd
[Top][All Lists]
Advanced

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

Re: [PATCH 2/6] eth-multiplexer: fix receiver lookups


From: Samuel Thibault
Subject: Re: [PATCH 2/6] eth-multiplexer: fix receiver lookups
Date: Sat, 12 Apr 2014 09:18:34 +0200
User-agent: Mutt/1.5.21+34 (58baf7c9f32f) (2010-12-30)

Justus Winter, le Fri 11 Apr 2014 15:34:10 +0200, a écrit :
> Previously, the device definitions were filtered using sed to replace
> the device_t type with mach_port_send_t to make the device argument of
> device_open polymorphic.  Rather than doing that, which makes it
> impossible to use translation functions, the definition of device_open
> has been amended.

Ack.

> * eth-multiplexer/Makefile: Remove ourdevice hack that changes
> device_t to mach_port_send_t.
> * eth-multiplexer/multiplexer.c: Likewise.
> * eth-multiplexer/device_impl.c: Fix all device_t receiver lookups.
> * eth-multiplexer/mig-decls.h: New file.
> * eth-multiplexer/mig-mutate.h: Add mutators.
> 
> fu_eth-multiplexer
> ---
>  eth-multiplexer/Makefile      |  8 ++----
>  eth-multiplexer/device_impl.c | 59 
> ++++++++++---------------------------------
>  eth-multiplexer/mig-decls.h   | 45 +++++++++++++++++++++++++++++++++
>  eth-multiplexer/mig-mutate.h  |  7 +++++
>  eth-multiplexer/multiplexer.c |  2 +-
>  5 files changed, 68 insertions(+), 53 deletions(-)
>  create mode 100644 eth-multiplexer/mig-decls.h
> 
> diff --git a/eth-multiplexer/Makefile b/eth-multiplexer/Makefile
> index 15d05a6..882c3d0 100644
> --- a/eth-multiplexer/Makefile
> +++ b/eth-multiplexer/Makefile
> @@ -21,18 +21,14 @@ target = eth-multiplexer
>  
>  #CFLAGS += -DDEBUG
>  SRCS = ethernet.c vdev.c multiplexer.c dev_stat.c netfs_impl.c notify_impl.c 
> device_impl.c demuxer.c
> -MIGSTUBS = ourdeviceServer.o notifyServer.o
> +MIGSTUBS = deviceServer.o notifyServer.o
>  MIGSFLAGS = -imacros $(srcdir)/mig-mutate.h
>  OBJS = $(SRCS:.c=.o) $(MIGSTUBS)
>  LCLHDRS = ethernet.h util.h vdev.h netfs_impl.h
> -DIST_FILES = ourdevice.defs notify.defs
> +DIST_FILES = device.defs notify.defs
>  HURDLIBS=ports fshelp shouldbeinlibc netfs bpf
>  OTHERLIBS = -lpthread
>  
>  CFLAGS += -I$(top_srcdir)/libbpf
>  
>  include ../Makeconf
> -
> -ourdevice.defs: device.defs
> -     $(CPP) $(CPPFLAGS) -x c $< | sed -e '/out[      ]*device[       ]*:[    
> ]*device_t/s/device_t/mach_port_send_t/' > $@
> -
> diff --git a/eth-multiplexer/device_impl.c b/eth-multiplexer/device_impl.c
> index 459d9c4..35a4da4 100644
> --- a/eth-multiplexer/device_impl.c
> +++ b/eth-multiplexer/device_impl.c
> @@ -27,7 +27,7 @@
>  
>  #include "ethernet.h"
>  #include "vdev.h"
> -#include "ourdevice_S.h"
> +#include "device_S.h"
>  #include "notify_S.h"
>  #include "bpf_impl.h"
>  #include "netfs_impl.h"
> @@ -40,38 +40,29 @@ extern struct port_info *notify_pi;
>  
>  /* Implementation of device interface */
>  kern_return_t
> -ds_xxx_device_set_status (device_t device, dev_flavor_t flavor,
> +ds_xxx_device_set_status (struct vether_device *vdev, dev_flavor_t flavor,
>                         dev_status_t status, size_t statu_cnt)
>  {
> -  struct vether_device *vdev = ports_lookup_port (port_bucket, device,
> -                                               vdev_portclass);
>    if (vdev == NULL)
>      return D_NO_SUCH_DEVICE;
> -  ports_port_deref (vdev);
>    return D_INVALID_OPERATION;
>  }
>  
>  kern_return_t
> -ds_xxx_device_get_status (device_t device, dev_flavor_t flavor,
> +ds_xxx_device_get_status (struct vether_device *vdev, dev_flavor_t flavor,
>                         dev_status_t status, size_t *statuscnt)
>  {
> -  struct vether_device *vdev = ports_lookup_port (port_bucket, device,
> -                                               vdev_portclass);
>    if (vdev == NULL)
>      return D_NO_SUCH_DEVICE;
> -  ports_port_deref (vdev);
>    return D_INVALID_OPERATION;
>  }
>  
>  kern_return_t
> -ds_xxx_device_set_filter (device_t device, mach_port_t rec,
> +ds_xxx_device_set_filter (struct vether_device *vdev, mach_port_t rec,
>                         int pri, filter_array_t filt, size_t len)
>  {
> -  struct vether_device *vdev = ports_lookup_port (port_bucket, device,
> -                                               vdev_portclass);
>    if (vdev == NULL)
>      return D_NO_SUCH_DEVICE;
> -  ports_port_deref (vdev);
>    return D_INVALID_OPERATION;
>  }
>  
> @@ -140,20 +131,18 @@ ds_device_open (mach_port_t master_port, mach_port_t 
> reply_port,
>  }
>  
>  kern_return_t
> -ds_device_close (device_t device)
> +ds_device_close (struct vether_device *device)
>  {
>    return 0;
>  }
>  
>  kern_return_t
> -ds_device_write (device_t device, mach_port_t reply_port,
> +ds_device_write (struct vether_device *vdev, mach_port_t reply_port,
>                mach_msg_type_name_t reply_type, dev_mode_t mode,
>                recnum_t recnum, io_buf_ptr_t data, size_t datalen,
>                int *bytes_written)
>  {
>    kern_return_t ret = 0;
> -  struct vether_device *vdev = ports_lookup_port (port_bucket, device,
> -                                               vdev_portclass);
>    if (vdev == NULL)
>      {
>        vm_deallocate (mach_task_self (), (vm_address_t) data, datalen);
> @@ -169,103 +158,82 @@ ds_device_write (device_t device, mach_port_t 
> reply_port,
>    /* The data in device_write() is transmifered out of line,
>     * so the server-side function has to deallocate it. */
>    vm_deallocate (mach_task_self (), (vm_address_t) data, datalen);
> -  ports_port_deref (vdev);
>    return ret;
>  }
>  
>  kern_return_t
> -ds_device_write_inband (device_t device, mach_port_t reply_port,
> +ds_device_write_inband (struct vether_device *vdev, mach_port_t reply_port,
>                       mach_msg_type_name_t reply_type, dev_mode_t mode,
>                       recnum_t recnum, io_buf_ptr_inband_t data,
>                       size_t datalen, int *bytes_written)
>  {
> -  struct vether_device *vdev = ports_lookup_port (port_bucket, device,
> -                                               vdev_portclass);
>    if (vdev == NULL)
>      return D_NO_SUCH_DEVICE;
> -  ports_port_deref (vdev);
>    return D_INVALID_OPERATION;
>  }
>  
>  kern_return_t
> -ds_device_read (device_t device, mach_port_t reply_port,
> +ds_device_read (struct vether_device *vdev, mach_port_t reply_port,
>               mach_msg_type_name_t reply_type, dev_mode_t mode,
>               recnum_t recnum, int bytes_wanted,
>               io_buf_ptr_t *data, size_t *datalen)
>  {
> -  struct vether_device *vdev = ports_lookup_port (port_bucket, device,
> -                                               vdev_portclass);
>    if (vdev == NULL)
>      return D_NO_SUCH_DEVICE;
> -  ports_port_deref (vdev);
>    return D_INVALID_OPERATION;
>  }
>  
>  kern_return_t
> -ds_device_read_inband (device_t device, mach_port_t reply_port,
> +ds_device_read_inband (struct vether_device *vdev, mach_port_t reply_port,
>                      mach_msg_type_name_t reply_type, dev_mode_t mode,
>                      recnum_t recnum, int bytes_wanted,
>                      io_buf_ptr_inband_t data, size_t *datalen)
>  {
> -  struct vether_device *vdev = ports_lookup_port (port_bucket, device,
> -                                               vdev_portclass);
>    if (vdev == NULL)
>      return D_NO_SUCH_DEVICE;
> -  ports_port_deref (vdev);
>    return D_INVALID_OPERATION;
>  }
>  
>  kern_return_t
> -ds_device_map (device_t device, vm_prot_t prot, vm_offset_t offset,
> +ds_device_map (struct vether_device *vdev, vm_prot_t prot, vm_offset_t 
> offset,
>              vm_size_t size, memory_object_t *pager, int unmap)
>  {
> -  struct vether_device *vdev = ports_lookup_port (port_bucket, device,
> -                                               vdev_portclass);
>    if (vdev == NULL)
>      return D_NO_SUCH_DEVICE;
> -  ports_port_deref (vdev);
>    return D_INVALID_OPERATION;
>  }
>  
>  kern_return_t
> -ds_device_set_status (device_t device, dev_flavor_t flavor,
> +ds_device_set_status (struct vether_device *vdev, dev_flavor_t flavor,
>                     dev_status_t status, size_t statuslen)
>  {
> -  struct vether_device *vdev = ports_lookup_port (port_bucket, device,
> -                                               vdev_portclass);
>    if (vdev == NULL)
>      return D_NO_SUCH_DEVICE;
> -  ports_port_deref (vdev);
>    return D_INVALID_OPERATION;
>  }
>  
>  kern_return_t
> -ds_device_get_status (device_t device, dev_flavor_t flavor,
> +ds_device_get_status (struct vether_device *vdev, dev_flavor_t flavor,
>                     dev_status_t status, size_t *statuslen)
>  {
>    extern io_return_t dev_getstat (struct vether_device *, dev_flavor_t,
>                                 dev_status_t, natural_t *);
>    kern_return_t ret = 0;
> -  struct vether_device *vdev = ports_lookup_port (port_bucket, device,
> -                                               vdev_portclass);
>    if (vdev == NULL)
>      return D_NO_SUCH_DEVICE;
>    if(ether_port != MACH_PORT_NULL)
>      ret = device_get_status (ether_port, flavor, status, statuslen);
>    else 
>      ret = dev_getstat (vdev, flavor, status, statuslen);
> -  ports_port_deref (vdev);
>    return ret;
>  }
>  
>  kern_return_t
> -ds_device_set_filter (device_t device, mach_port_t receive_port,
> +ds_device_set_filter (struct vether_device *vdev, mach_port_t receive_port,
>                     int priority, filter_array_t filter, size_t filterlen)
>  {
>    mach_port_t tmp;
>    kern_return_t err;
> -  struct vether_device *vdev = ports_lookup_port (port_bucket, device,
> -                                               vdev_portclass);
>    if (vdev == NULL)
>      return D_NO_SUCH_DEVICE;
>    err = mach_port_request_notification (mach_task_self (), receive_port, 
> @@ -279,6 +247,5 @@ ds_device_set_filter (device_t device, mach_port_t 
> receive_port,
>    err = net_set_filter (&vdev->port_list, receive_port,
>                       priority, filter, filterlen);
>  out:
> -  ports_port_deref (vdev);
>    return err;
>  }
> diff --git a/eth-multiplexer/mig-decls.h b/eth-multiplexer/mig-decls.h
> new file mode 100644
> index 0000000..a68e2ec
> --- /dev/null
> +++ b/eth-multiplexer/mig-decls.h
> @@ -0,0 +1,45 @@
> +/*
> +   Copyright (C) 2014 Free Software Foundation, Inc.
> +   Written by Justus Winter.
> +
> +   This file is part of the GNU Hurd.
> +
> +   The GNU Hurd is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU General Public License as
> +   published by the Free Software Foundation; either version 2, or (at
> +   your option) any later version.
> +
> +   The GNU Hurd is distributed in the hope that it will be useful, but
> +   WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with the GNU Hurd.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +#ifndef __ETH_MULTIPLEXER_MIG_DECLS_H__
> +#define __ETH_MULTIPLEXER_MIG_DECLS_H__
> +
> +#include <hurd/ports.h>
> +
> +typedef struct vether_device *vether_device_t;
> +
> +extern struct port_bucket *port_bucket;
> +extern struct port_class *vdev_portclass;
> +
> +/* Called by server stub functions.  */
> +
> +static inline struct vether_device * __attribute__ ((unused))
> +begin_using_device_port (mach_port_t port)
> +{
> +  return ports_lookup_port (port_bucket, port, vdev_portclass);
> +}
> +
> +static inline void __attribute__ ((unused))
> +end_using_device (struct vether_device *p)
> +{
> +  if (p)
> +    ports_port_deref (p);
> +}
> +
> +#endif /* __ETH_MULTIPLEXER_MIG_DECLS_H__ */
> diff --git a/eth-multiplexer/mig-mutate.h b/eth-multiplexer/mig-mutate.h
> index f692236..2403c29 100644
> --- a/eth-multiplexer/mig-mutate.h
> +++ b/eth-multiplexer/mig-mutate.h
> @@ -23,3 +23,10 @@
>    end_using_port_info (port_info_t)
>  #define NOTIFY_IMPORTS                                               \
>    import "libports/mig-decls.h";
> +
> +#define DEVICE_INTRAN                                                \
> +  vether_device_t begin_using_device_port (mach_port_t)
> +#define DEVICE_DESTRUCTOR                                    \
> +  end_using_device (vether_device_t)
> +#define DEVICE_IMPORTS                                               \
> +  import "eth-multiplexer/mig-decls.h";
> diff --git a/eth-multiplexer/multiplexer.c b/eth-multiplexer/multiplexer.c
> index 87578ec..c36ab78 100644
> --- a/eth-multiplexer/multiplexer.c
> +++ b/eth-multiplexer/multiplexer.c
> @@ -42,7 +42,7 @@
>  
>  #include "ethernet.h"
>  #include "vdev.h"
> -#include "ourdevice_S.h"
> +#include "device_S.h"
>  #include "notify_S.h"
>  #include "bpf_impl.h"
>  #include "netfs_impl.h"
> -- 
> 1.9.1
> 

-- 
Samuel
"...Unix, MS-DOS, and Windows NT (also known as the Good, the Bad, and
the Ugly)."
(By Matt Welsh)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]