Re: [PATCH 2/3] kpartx: use opened loop device immediately

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

 



On Mon, 2021-11-15 at 21:22 +0100, mwilck@xxxxxxxx wrote:
> From: Martin Wilck <mwilck@xxxxxxxx>
> 
> The code in find_unused_loop_device() goes through circles to
> get an unused device, but it takes no care not to race with a
> different
> process opening the same loop device. Use the once-opened
> loop device for setup immediately instead of closing and re-opening
> it.
> 
> While at it, simplify the code somewhat.
> 
> Signed-off-by: Martin Wilck <mwilck@xxxxxxxx>
> ---
>  kpartx/kpartx.c |  4 +--
>  kpartx/lopart.c | 72 +++++++++++++++++++----------------------------
> --
>  kpartx/lopart.h |  3 +--
>  3 files changed, 29 insertions(+), 50 deletions(-)
> 
> diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c
> index 7bc6454..3c49999 100644
> --- a/kpartx/kpartx.c
> +++ b/kpartx/kpartx.c
>  
> @@ -266,11 +250,9 @@ int set_loop(const char *device, const char
> *file, int offset, int *loopro)
>                 }
>         }
>  
> -       if ((fd = open (device, mode)) < 0) {
> -               close(ffd);
> -               perror (device);
> +       *device = find_unused_loop_device(mode, &fd);
> +       if (!*device)
>                 return 1;

This leaks the file descriptor ffd. I'll re-post.

Regards
Martin


--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/dm-devel





[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux