All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
To: Juergen Gross <jgross@suse.com>
Cc: minios-devel@lists.xenproject.org,
	xen-devel@lists.xenproject.org, wl@xen.org
Subject: Re: [MINIOS PATCH v3 2/5] reset file type in close() in one place only
Date: Sun, 16 Jan 2022 21:33:23 +0100	[thread overview]
Message-ID: <20220116203323.ebf75ksyfvy4qoim@begin> (raw)
In-Reply-To: <20220116064527.23519-3-jgross@suse.com>

Juergen Gross, le dim. 16 janv. 2022 07:45:24 +0100, a ecrit:
> Today the file type in struct file is set to FTYPE_NONE for each
> file type individually. Do that at the end of close() handling for
> all types.
> 
> While at it wipe the complete struct file, too, in order to avoid
> old data creeping into a new allocated struct file.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
> V2:
> - new patch
> V3:
> - add error handling (Andrew Cooper)
> - use BUILD_BUG_ON() (Andrew Cooper)
> ---
>  lib/sys.c | 56 ++++++++++++++++++++++++++++---------------------------
>  lib/xs.c  |  1 -
>  2 files changed, 29 insertions(+), 28 deletions(-)
> 
> diff --git a/lib/sys.c b/lib/sys.c
> index 9a03875c..7df77cc6 100644
> --- a/lib/sys.c
> +++ b/lib/sys.c
> @@ -265,7 +265,7 @@ int read(int fd, void *buf, size_t nbytes)
>              return ret;
>          }
>  #ifdef HAVE_LWIP
> -	case FTYPE_SOCKET:
> +        case FTYPE_SOCKET:
>  	    return lwip_read(files[fd].fd, buf, nbytes);
>  #endif
>  #ifdef CONFIG_NETFRONT
> @@ -424,84 +424,86 @@ int fsync(int fd) {
>  
>  int close(int fd)
>  {
> +    int res = 0;
> +
> +    if ( fd < 0 || fd >= ARRAY_SIZE(files) )
> +        goto error;
> +
>      printk("close(%d)\n", fd);
>      switch (files[fd].type) {
>          default:
> -	    files[fd].type = FTYPE_NONE;
> -	    return 0;
> +            break;
>  #ifdef CONFIG_XENBUS
>  	case FTYPE_XENBUS:
>              xs_daemon_close((void*)(intptr_t) fd);
> -            return 0;
> +            break;
>  #endif
>  #ifdef HAVE_LWIP
> -	case FTYPE_SOCKET: {
> -	    int res = lwip_close(files[fd].fd);
> -	    files[fd].type = FTYPE_NONE;
> -	    return res;
> -	}
> +	case FTYPE_SOCKET:
> +            res = lwip_close(files[fd].fd);
> +            break;
>  #endif
>  #ifdef CONFIG_LIBXENCTRL
>  	case FTYPE_XC:
>  	    minios_interface_close_fd(fd);
> -	    return 0;
> +            break;
>  #endif
>  #ifdef CONFIG_LIBXENEVTCHN
>  	case FTYPE_EVTCHN:
>  	    minios_evtchn_close_fd(fd);
> -            return 0;
> +            break;
>  #endif
>  #ifdef CONFIG_LIBXENGNTTAB
>  	case FTYPE_GNTMAP:
>  	    minios_gnttab_close_fd(fd);
> -	    return 0;
> +            break;
>  #endif
>  #ifdef CONFIG_NETFRONT
>  	case FTYPE_TAP:
>  	    shutdown_netfront(files[fd].dev);
> -	    files[fd].type = FTYPE_NONE;
> -	    return 0;
> +            break;
>  #endif
>  #ifdef CONFIG_BLKFRONT
>  	case FTYPE_BLK:
>              shutdown_blkfront(files[fd].dev);
> -	    files[fd].type = FTYPE_NONE;
> -	    return 0;
> +            break;
>  #endif
>  #ifdef CONFIG_TPMFRONT
>  	case FTYPE_TPMFRONT:
>              shutdown_tpmfront(files[fd].dev);
> -	    files[fd].type = FTYPE_NONE;
> -	    return 0;
> +            break;
>  #endif
>  #ifdef CONFIG_TPM_TIS
>  	case FTYPE_TPM_TIS:
>              shutdown_tpm_tis(files[fd].dev);
> -	    files[fd].type = FTYPE_NONE;
> -	    return 0;
> +            break;
>  #endif
>  #ifdef CONFIG_KBDFRONT
>  	case FTYPE_KBD:
>              shutdown_kbdfront(files[fd].dev);
> -            files[fd].type = FTYPE_NONE;
> -            return 0;
> +            break;
>  #endif
>  #ifdef CONFIG_FBFRONT
>  	case FTYPE_FB:
>              shutdown_fbfront(files[fd].dev);
> -            files[fd].type = FTYPE_NONE;
> -            return 0;
> +            break;
>  #endif
>  #ifdef CONFIG_CONSFRONT
>          case FTYPE_SAVEFILE:
>          case FTYPE_CONSOLE:
>              fini_consfront(files[fd].dev);
> -            files[fd].type = FTYPE_NONE;
> -            return 0;
> +            break;
>  #endif
>  	case FTYPE_NONE:
> -	    break;
> +            goto error;
>      }
> +
> +    memset(files + fd, 0, sizeof(struct file));
> +    BUILD_BUG_ON(FTYPE_NONE != 0);
> +
> +    return res;
> +
> + error:
>      printk("close(%d): Bad descriptor\n", fd);
>      errno = EBADF;
>      return -1;
> diff --git a/lib/xs.c b/lib/xs.c
> index 0459f52f..4af0f960 100644
> --- a/lib/xs.c
> +++ b/lib/xs.c
> @@ -35,7 +35,6 @@ void xs_daemon_close(struct xs_handle *h)
>          next = event->next;
>          free(event);
>      }
> -    files[fd].type = FTYPE_NONE;
>  }
>  
>  int xs_fileno(struct xs_handle *h)
> -- 
> 2.26.2
> 

-- 
Samuel
/*
 * [...] Note that 120 sec is defined in the protocol as the maximum
 * possible RTT.  I guess we'll have to use something other than TCP
 * to talk to the University of Mars.
 * PAWS allows us longer timeouts and large windows, so once implemented
 * ftp to mars will work nicely.
 */
(from /usr/src/linux/net/inet/tcp.c, concerning RTT [retransmission timeout])


  reply	other threads:[~2022-01-16 20:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-16  6:45 [MINIOS PATCH v3 0/5] mini-os: remove struct file dependency on config Juergen Gross
2022-01-16  6:45 ` [MINIOS PATCH v3 1/5] introduce get_file_from_fd() Juergen Gross
2022-01-16  6:45 ` [MINIOS PATCH v3 2/5] reset file type in close() in one place only Juergen Gross
2022-01-16 20:33   ` Samuel Thibault [this message]
2022-01-16  6:45 ` [MINIOS PATCH v3 3/5] remove file type FTYPE_XC Juergen Gross
2022-01-16 20:34   ` Samuel Thibault
2022-01-16  6:45 ` [MINIOS PATCH v3 4/5] use function vectors instead of switch for file operations Juergen Gross
2022-01-16 20:39   ` Samuel Thibault
2022-01-16  6:45 ` [MINIOS PATCH v3 5/5] add CONFIG_LIBXS item Juergen Gross
2022-01-16 20:40   ` Samuel Thibault
2022-01-16 20:41 ` [MINIOS PATCH v3 0/5] mini-os: remove struct file dependency on config Samuel Thibault

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220116203323.ebf75ksyfvy4qoim@begin \
    --to=samuel.thibault@ens-lyon.org \
    --cc=jgross@suse.com \
    --cc=minios-devel@lists.xenproject.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.