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

Re: [Minios-devel] [UNIKRAFT PATCH v3 2/3] lib/devfs: Add /dev/null and /dev/zero support



Okay, great. Thanks!

Reviewed-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>

On 17.02.20 17:11, Stefan Teodorescu wrote:
Sure, you can change it if there is any problem, I have just copy pasted it from another file.

Thanks,
Stefan

On Mon, 17 Feb 2020 at 18:04, Simon Kuenzer <simon.kuenzer@xxxxxxxxx <mailto:simon.kuenzer@xxxxxxxxx>> wrote:

    Thanks for the update! See my comment inline.

    On 14.02.20 16:41, stefanl.teodorescu@xxxxxxxxx
    <mailto:stefanl.teodorescu@xxxxxxxxx> wrote:
     > From: Costin Lupu <costin.lupu@xxxxxxxxx
    <mailto:costin.lupu@xxxxxxxxx>>
     >
     > This is shamelessly copied and adapted from our implementation
     > for /dev/random device support.
     >
     > Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx
    <mailto:costin.lupu@xxxxxxxxx>>
     > Signed-off-by: Stefan Teodorescu <stefanl.teodorescu@xxxxxxxxx
    <mailto:stefanl.teodorescu@xxxxxxxxx>>
     > ---
     >   lib/devfs/Config.uk               |  17 ++++
     >   lib/devfs/Makefile.uk             |   1 +
     >   lib/devfs/null.c                  | 145
    ++++++++++++++++++++++++++++++
     >   lib/vfscore/include/vfscore/uio.h |   1 +
     >   4 files changed, 164 insertions(+)
     >   create mode 100644 lib/devfs/null.c
     >
     > diff --git a/lib/devfs/Config.uk b/lib/devfs/Config.uk
     > index 6f21c01c..af61747f 100644
     > --- a/lib/devfs/Config.uk
     > +++ b/lib/devfs/Config.uk
     > @@ -8,4 +8,21 @@ if LIBDEVFS
     >           bool "Mount /dev during boot"
     >       depends on LIBVFSCORE_AUTOMOUNT_ROOTFS
     >           default n
     > +
     > +     # hidden
     > +     config LIBDEVFS_DEV_NULL_ZERO
     > +             bool
     > +             default n
     > +
     > +     config LIBDEVFS_DEV_NULL
     > +             bool "Register null device"
     > +             default y if LIBDEVFS_AUTOMOUNT
     > +             select LIBDEVFS_DEV_NULL_ZERO
     > +             default n
     > +
     > +     config LIBDEVFS_DEV_ZERO
     > +             bool "Register zero device"
     > +             default y if LIBDEVFS_AUTOMOUNT
     > +             select LIBDEVFS_DEV_NULL_ZERO
     > +             default n
     >   endif
     > diff --git a/lib/devfs/Makefile.uk b/lib/devfs/Makefile.uk
     > index c496fd56..b23ebf15 100644
     > --- a/lib/devfs/Makefile.uk
     > +++ b/lib/devfs/Makefile.uk
     > @@ -6,3 +6,4 @@ LIBDEVFS_CFLAGS-$(call gcc_version_ge,8,0) +=
    -Wno-cast-function-type
     >
     >   LIBDEVFS_SRCS-y += $(LIBDEVFS_BASE)/device.c
     >   LIBDEVFS_SRCS-y += $(LIBDEVFS_BASE)/devfs_vnops.c
     > +LIBDEVFS_SRCS-$(CONFIG_LIBDEVFS_DEV_NULL_ZERO) +=
    $(LIBDEVFS_BASE)/null.c
     > diff --git a/lib/devfs/null.c b/lib/devfs/null.c
     > new file mode 100644
     > index 00000000..60ada995
     > --- /dev/null
     > +++ b/lib/devfs/null.c
     > @@ -0,0 +1,145 @@
     > +/* SPDX-License-Identifier: BSD-3-Clause */
     > +/*
     > + * Authors: Costin Lupu <costin.lupu@xxxxxxxxx
    <mailto:costin.lupu@xxxxxxxxx>>
     > + *
     > + * Copyright (c) 2019, University Politehnica of Bucharest. All
    rights reserved.
     > + *
     > + * Redistribution and use in source and binary forms, with or
    without
     > + * modification, are permitted provided that the following
    conditions
     > + * are met:
     > + *
     > + * 1. Redistributions of source code must retain the above copyright
     > + *    notice, this list of conditions and the following disclaimer.
     > + * 2. Redistributions in binary form must reproduce the above
    copyright
     > + *    notice, this list of conditions and the following
    disclaimer in the
     > + *    documentation and/or other materials provided with the
    distribution.
     > + * 3. Neither the name of the copyright holder nor the names of its
     > + *    contributors may be used to endorse or promote products
    derived from
     > + *    this software without specific prior written permission.
     > + *
     > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
    CONTRIBUTORS "AS IS"
     > + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE
     > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
    PARTICULAR PURPOSE
     > + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
    CONTRIBUTORS BE
     > + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    EXEMPLARY, OR
     > + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    PROCUREMENT OF
     > + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    OR BUSINESS
     > + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    WHETHER IN
     > + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    OTHERWISE)
     > + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
    ADVISED OF THE
     > + * POSSIBILITY OF SUCH DAMAGE.
     > + *
     > + * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.

    I know that you probably copied this license header from another file
    but we noticed that this sentence is probably in conflict with the
    license ahead. Can this be removed? With your okay, I would do it for
    you while upstreaming.

     > + */
     > +
     > +#include <uk/config.h>
     > +#include <stdlib.h>
     > +#include <string.h>
     > +#include <uk/ctors.h>
     > +#include <uk/print.h>
     > +#include <vfscore/uio.h>
     > +#include <devfs/device.h>
     > +
     > +
     > +int dev_null_write(struct device *dev __unused, struct uio *uio,
    int flags __unused)
     > +{
     > +     uio->uio_resid = 0;
     > +     return 0;
     > +}
     > +
     > +int dev_null_open(struct device *device __unused, int mode __unused)
     > +{
     > +     return 0;
     > +}
     > +
     > +
     > +int dev_null_close(struct device *device __unused)
     > +{
     > +     return 0;
     > +}
     > +
     > +#ifdef CONFIG_LIBDEVFS_DEV_NULL
     > +
     > +#define DEV_NULL_NAME "null"
     > +
     > +int dev_null_read(struct device *dev __unused, struct uio *uio,
    int flags __unused)
     > +{
     > +     uio->uio_resid = uio->uio_iov->iov_len;
     > +     return 0;
     > +}
     > +
     > +static struct devops null_devops = {
     > +     .read = dev_null_read,
     > +     .write = dev_null_write,
     > +     .open = dev_null_open,
     > +     .close = dev_null_close,
     > +};
     > +
     > +static struct driver drv_null = {
     > +     .devops = &null_devops,
     > +     .devsz = 0,
     > +     .name = DEV_NULL_NAME
     > +};
     > +#endif
     > +
     > +#ifdef CONFIG_LIBDEVFS_DEV_ZERO
     > +
     > +#define DEV_ZERO_NAME "zero"
     > +
     > +int dev_zero_read(struct device *dev __unused, struct uio *uio,
    int flags __unused)
     > +{
     > +     size_t count;
     > +     char *buf;
     > +
     > +     buf = uio->uio_iov->iov_base;
     > +     count = uio->uio_iov->iov_len;
     > +
     > +     memset(buf, 0, count);
     > +     uio->uio_resid = 0;
     > +     return 0;
     > +}
     > +
     > +static struct devops zero_devops = {
     > +     .read = dev_zero_read,
     > +     .write = dev_null_write,
     > +     .open = dev_null_open,
     > +     .close = dev_null_close,
     > +};
     > +
     > +static struct driver drv_zero = {
     > +     .devops = &zero_devops,
     > +     .devsz = 0,
     > +     .name = DEV_ZERO_NAME
     > +};
     > +#endif
     > +
     > +static int devfs_register_null(void)
     > +{
     > +     struct device *dev;
     > +
     > +#ifdef CONFIG_LIBDEVFS_DEV_NULL
     > +     uk_pr_debug("Register '%s' to devfs\n", DEV_NULL_NAME);
     > +
     > +     /* register /dev/null */
     > +     dev = device_create(&drv_null, DEV_NULL_NAME, D_CHR);
     > +     if (dev == NULL) {
     > +             uk_pr_err("Failed to register '%s' to devfs\n",
    DEV_NULL_NAME);
     > +             return -1;
     > +     }
     > +#endif
     > +
     > +#ifdef CONFIG_LIBDEVFS_DEV_ZERO
     > +     uk_pr_debug("Register '%s' to devfs\n", DEV_ZERO_NAME);
     > +
     > +     /* register /dev/zero */
     > +     dev = device_create(&drv_zero, DEV_ZERO_NAME, D_CHR);
     > +     if (dev == NULL) {
     > +             uk_pr_err("Failed to register '%s' to devfs\n",
    DEV_ZERO_NAME);
     > +             return -1;
     > +     }
     > +#endif
     > +
     > +     return 0;
     > +}
     > +
     > +devfs_initcall(devfs_register_null);
     > diff --git a/lib/vfscore/include/vfscore/uio.h
    b/lib/vfscore/include/vfscore/uio.h
     > index 83dd5b9a..b14fdb82 100644
     > --- a/lib/vfscore/include/vfscore/uio.h
     > +++ b/lib/vfscore/include/vfscore/uio.h
     > @@ -36,6 +36,7 @@
     >   #include <sys/types.h>
     >   #include <sys/uio.h>
     >   #include <limits.h>
     > +#include <uk/assert.h>
     >
     >   enum        uio_rw { UIO_READ, UIO_WRITE };
     >
     >


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.