All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Marzinski <bmarzins@redhat.com>
To: mwilck@suse.com
Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>,
	dm-devel@lists.linux.dev, Li Xiao Keng <lixiaokeng@huawei.com>,
	Miao Guanqin <miaoguanqin@huawei.com>,
	Guan Junxiong <guanjunxiong@huawei.com>
Subject: Re: [PATCH v2 04/14] libmultipath: io_err_stat: don't free aio memory before completion
Date: Fri, 27 Oct 2023 14:55:22 -0400	[thread overview]
Message-ID: <ZTwHmj0xhXHDdeHE@bmarzins-01.fast.rdu2.eng.redhat.com> (raw)
In-Reply-To: <20231026174153.1133-5-mwilck@suse.com>

On Thu, Oct 26, 2023 at 07:41:43PM +0200, mwilck@suse.com wrote:
> From: Martin Wilck <mwilck@suse.com>
> 
> It is wrong to assume that aio data structures can be reused or freed
> after io_cancel(). io_cancel() will almost always return -EINPROGRESS,
> anyway. Use the io_starttime field to indicate whether an io event
> has been completed by the kernel. Make sure no in-flight buffers are freed.
> 
> Fixes https://github.com/opensvc/multipath-tools/issues/73.
> 
> Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
> Cc: Li Xiao Keng <lixiaokeng@huawei.com>
> Cc: Miao Guanqin <miaoguanqin@huawei.com>
> Cc: Guan Junxiong <guanjunxiong@huawei.com>
> ---
>  libmultipath/io_err_stat.c | 26 ++++++++++++++++----------
>  1 file changed, 16 insertions(+), 10 deletions(-)
> 
> diff --git a/libmultipath/io_err_stat.c b/libmultipath/io_err_stat.c
> index dc1c252..c474c34 100644
> --- a/libmultipath/io_err_stat.c
> +++ b/libmultipath/io_err_stat.c
> @@ -111,10 +111,14 @@ static int init_each_dio_ctx(struct dio_ctx *ct, int blksize,
>  	return 0;
>  }
>  
> -static void deinit_each_dio_ctx(struct dio_ctx *ct)
> +static int deinit_each_dio_ctx(struct dio_ctx *ct)
>  {
> -	if (ct->buf)
> -		free(ct->buf);
> +	if (!ct->buf)
> +		return 0;
> +	if (ct->io_starttime.tv_sec != 0 || ct->io_starttime.tv_nsec != 0)
> +		return 1;
> +	free(ct->buf);
> +	return 0;
>  }
>  
>  static int setup_directio_ctx(struct io_err_stat_path *p)
> @@ -164,6 +168,7 @@ fail_close:
>  static void free_io_err_stat_path(struct io_err_stat_path *p)
>  {
>  	int i;
> +	int inflight = 0;
>  
>  	if (!p)
>  		return;
> @@ -173,8 +178,13 @@ static void free_io_err_stat_path(struct io_err_stat_path *p)
>  	cancel_inflight_io(p);
>  
>  	for (i = 0; i < CONCUR_NR_EVENT; i++)
> -		deinit_each_dio_ctx(p->dio_ctx_array + i);
> -	free(p->dio_ctx_array);
> +		inflight += deinit_each_dio_ctx(p->dio_ctx_array + i);
> +
> +	if (!inflight)
> +		free(p->dio_ctx_array);
> +	else
> +		io_err_stat_log(2, "%s: can't free aio space of %s, %d IOs in flight",
> +				__func__, p->devname, inflight);
>  
>  	if (p->fd > 0)
>  		close(p->fd);
> @@ -503,7 +513,7 @@ static int try_to_cancel_timeout_io(struct dio_ctx *ct, struct timespec *t,
>  	int		rc = PATH_UNCHECKED;
>  	int		r;
>  
> -	if (ct->io_starttime.tv_sec == 0)
> +	if (ct->io_starttime.tv_sec == 0 && ct->io_starttime.tv_nsec == 0)
>  		return rc;
>  	timespecsub(t, &ct->io_starttime, &difftime);
>  	if (difftime.tv_sec > IOTIMEOUT_SEC) {
> @@ -514,8 +524,6 @@ static int try_to_cancel_timeout_io(struct dio_ctx *ct, struct timespec *t,
>  		if (r)
>  			io_err_stat_log(5, "%s: io_cancel error %i",
>  					dev, errno);
> -		ct->io_starttime.tv_sec = 0;
> -		ct->io_starttime.tv_nsec = 0;
>  		rc = PATH_TIMEOUT;
>  	} else {
>  		rc = PATH_PENDING;
> @@ -559,8 +567,6 @@ static void cancel_inflight_io(struct io_err_stat_path *pp)
>  		if (r)
>  			io_err_stat_log(5, "%s: io_cancel error %d, %i",
>  					pp->devname, r, errno);
> -		ct->io_starttime.tv_sec = 0;
> -		ct->io_starttime.tv_nsec = 0;
>  	}
>  }
>  
> -- 
> 2.42.0


  reply	other threads:[~2023-10-27 18:55 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-26 17:41 [PATCH v2 00/14] multipath: aio, systemd, and documentation improvements mwilck
2023-10-26 17:41 ` [PATCH v2 01/14] libmultipath: reduce log level of directio messages mwilck
2023-10-26 17:41 ` [PATCH v2 02/14] libmultipath: directio: don't reset ct->running after io_cancel() mwilck
2023-10-27 18:54   ` Benjamin Marzinski
2023-10-26 17:41 ` [PATCH v2 03/14] libmultipath: directio: fix error handling mwilck
2023-10-27 18:54   ` Benjamin Marzinski
2023-10-26 17:41 ` [PATCH v2 04/14] libmultipath: io_err_stat: don't free aio memory before completion mwilck
2023-10-27 18:55   ` Benjamin Marzinski [this message]
2023-10-26 17:41 ` [PATCH v2 05/14] libmultipath: io_err_stat: call io_destroy() inside free_io_err_pathvec() mwilck
2023-10-27 18:55   ` Benjamin Marzinski
2023-10-26 17:41 ` [PATCH v2 06/14] libmultipath: io_err_stat: use higher number of aio slots mwilck
2023-10-27 18:56   ` Benjamin Marzinski
2023-10-26 17:41 ` [PATCH v2 07/14] libmultipath: io_err_stat: fix error handling mwilck
2023-10-27 19:09   ` Benjamin Marzinski
2023-10-26 17:41 ` [PATCH v2 08/14] multipathd.service: require modprobe@dm_multipath.service if available mwilck
2023-10-27 19:09   ` Benjamin Marzinski
2023-10-27 20:05   ` Benjamin Marzinski
2023-10-30 11:45     ` Martin Wilck
2023-10-26 17:41 ` [PATCH v2 09/14] libmpathutil: remove systemd_service_enabled() mwilck
2023-10-26 17:41 ` [PATCH v2 10/14] multipath.conf.5: fix typo mwilck
2023-10-27 19:10   ` Benjamin Marzinski
2023-10-26 17:41 ` [PATCH v2 11/14] Makefile.inc, README.md: fix docs for prefix in split-usr case mwilck
2023-10-27 19:27   ` Benjamin Marzinski
2023-10-26 17:41 ` [PATCH v2 12/14] README.md: update mailing list and contributing information mwilck
2023-10-27 19:29   ` Benjamin Marzinski
2023-10-30 11:41     ` Martin Wilck
2023-10-26 17:41 ` [PATCH v2 13/14] README.md: Extend the section about NVMe mwilck
2023-10-27 19:34   ` Benjamin Marzinski
2023-10-26 17:41 ` [PATCH v2 14/14] README.md: fix formatting of Changelog section mwilck
2023-10-27 19:35   ` Benjamin Marzinski

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=ZTwHmj0xhXHDdeHE@bmarzins-01.fast.rdu2.eng.redhat.com \
    --to=bmarzins@redhat.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=guanjunxiong@huawei.com \
    --cc=lixiaokeng@huawei.com \
    --cc=miaoguanqin@huawei.com \
    --cc=mwilck@suse.com \
    /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.