mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Alexandre Oliva <aoliva@redhat.com>
Cc: linux-kernel@vger.kernel.org, Neil Brown <neilb@suse.de>
Subject: Re: let md auto-detect 128+ raid members, fix potential race condition
Date: Sun, 30 Jul 2006 12:41:39 -0700	[thread overview]
Message-ID: <20060730124139.45861b47.akpm@osdl.org> (raw)
In-Reply-To: <ork65veg2y.fsf@free.oliva.athome.lsd.ic.unicamp.br>

On Sun, 30 Jul 2006 03:56:21 -0300
Alexandre Oliva <aoliva@redhat.com> wrote:

> I accidentally ran into the 128-devices limit in md.c's
> detected_devices.  It doesn't seem like a high-enough limit, and I
> don't quite see why we wouldn't use a list for this.
> 
> Besides, there appears to be a race condition in it:
> 
>          detected_devices[dev_cnt++] = dev;
> 
> won't atomically increment dev_cnt and use its previous value, unless
> there's something up the call stack that guarantees mutual exclusion.
> I don't see that this is the case.
> 
> Previously devices that exceeded the array would be silently
> discarded.  Now we'll only discard them if we run out of memory, and
> we'll report so if we do.

Neil cc'ed.

> Before I wrap up, a question on style: does it make sense to use
> kzmalloc to allocate this newly-created data structure that contains
> only a list_head and a dev_t, where the latter is immediately copied
> from another dev_t variable, and then the whole thing is added to a
> list?  I.e., could any list-checking present or future feature rely on
> list_head fields that might hurt if not zero-initialized, or would it
> be future-proof to just use kmalloc in this case?

I'd say that if all fields are going to be initialised, kzalloc() shouldn't
be used.

nits:

Index: kernel-2.6.17-1.2462.fc6/drivers/md/md.c
> ===================================================================
> --- kernel-2.6.17-1.2462.fc6.orig/drivers/md/md.c	2006-07-30 01:03:28.000000000 -0300
> +++ kernel-2.6.17-1.2462.fc6/drivers/md/md.c	2006-07-30 03:40:54.000000000 -0300
> @@ -1435,7 +1435,7 @@ static void unlock_rdev(mdk_rdev_t *rdev
>  	blkdev_put_partition(bdev);
>  }
>  
> -void md_autodetect_dev(dev_t dev);
> +int md_register_autodetect_dev(dev_t dev);

Put it in a header file, please.
 
> +int md_register_autodetect_dev(dev_t dev)
>  {
> -	if (dev_cnt >= 0 && dev_cnt < 127)
> -		detected_devices[dev_cnt++] = dev;
> +	struct detected_dev_list_t *ldev = kzalloc(sizeof (*ldev), GFP_KERNEL);
> +
> +	if (!ldev)
> +	  return -1;

whitespace broke.

>  }
> Index: kernel-2.6.17-1.2462.fc6/fs/partitions/check.c
> ===================================================================
> --- kernel-2.6.17-1.2462.fc6.orig/fs/partitions/check.c	2006-07-30 01:03:34.000000000 -0300
> +++ kernel-2.6.17-1.2462.fc6/fs/partitions/check.c	2006-07-30 03:41:02.000000000 -0300
> @@ -36,7 +36,7 @@
>  #include "karma.h"
>  
>  #ifdef CONFIG_BLK_DEV_MD
> -extern void md_autodetect_dev(dev_t dev);
> +extern int md_register_autodetect_dev(dev_t dev);
>  #endif

Again, let's find a header for this.

>  int warn_no_part = 1; /*This is ugly: should make genhd removable media aware*/
> @@ -471,8 +471,10 @@ int rescan_partitions(struct gendisk *di
>  		}
>  		add_partition(disk, p, from, size);
>  #ifdef CONFIG_BLK_DEV_MD
> -		if (state->parts[p].flags)
> -			md_autodetect_dev(bdev->bd_dev+p);
> +		if (state->parts[p].flags
> +		    && md_register_autodetect_dev(bdev->bd_dev+p))
> +			printk(KERN_ERR "md: out of memory registering %s%d\n",
> +			       disk->disk_name, p);
>  #endif

What happens if CONFIG_BLK_DEV_MD=m?

  reply	other threads:[~2006-07-30 19:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-30  6:56 Alexandre Oliva
2006-07-30 19:41 ` Andrew Morton [this message]
2006-07-30 20:56   ` Alexandre Oliva
2006-07-30 21:21     ` Andrew Morton
2006-07-30 23:20     ` Neil Brown
2006-07-31 16:34       ` Helge Hafting
2006-07-31 20:27       ` Alexandre Oliva
2006-07-31 21:48         ` David Greaves
2006-08-01  2:20           ` Alexandre Oliva
2006-08-01  8:28             ` Michael Tokarev
2006-08-01 21:24               ` Alexandre Oliva
2006-08-01  1:19         ` Neil Brown
2006-08-01  2:35           ` Alexandre Oliva
2006-08-01  3:33             ` Alexandre Oliva
2006-08-01 20:46               ` Alexandre Oliva
2006-08-02  6:37                 ` Luca Berra
2006-08-01 17:40       ` Bill Davidsen
2006-08-01 21:32         ` Alexandre Oliva
2006-08-02  6:47           ` Luca Berra
2006-08-02 16:47           ` Bill Davidsen

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=20060730124139.45861b47.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=aoliva@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neilb@suse.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®