diff options
Diffstat (limited to 'drivers/md/raid6main.c')
-rw-r--r-- | drivers/md/raid6main.c | 152 |
1 files changed, 117 insertions, 35 deletions
diff --git a/drivers/md/raid6main.c b/drivers/md/raid6main.c index f618a53b98be..cd477ebf2ee4 100644 --- a/drivers/md/raid6main.c +++ b/drivers/md/raid6main.c | |||
@@ -115,7 +115,7 @@ static void __release_stripe(raid6_conf_t *conf, struct stripe_head *sh) | |||
115 | list_add_tail(&sh->lru, &conf->inactive_list); | 115 | list_add_tail(&sh->lru, &conf->inactive_list); |
116 | atomic_dec(&conf->active_stripes); | 116 | atomic_dec(&conf->active_stripes); |
117 | if (!conf->inactive_blocked || | 117 | if (!conf->inactive_blocked || |
118 | atomic_read(&conf->active_stripes) < (NR_STRIPES*3/4)) | 118 | atomic_read(&conf->active_stripes) < (conf->max_nr_stripes*3/4)) |
119 | wake_up(&conf->wait_for_stripe); | 119 | wake_up(&conf->wait_for_stripe); |
120 | } | 120 | } |
121 | } | 121 | } |
@@ -273,7 +273,8 @@ static struct stripe_head *get_active_stripe(raid6_conf_t *conf, sector_t sector | |||
273 | conf->inactive_blocked = 1; | 273 | conf->inactive_blocked = 1; |
274 | wait_event_lock_irq(conf->wait_for_stripe, | 274 | wait_event_lock_irq(conf->wait_for_stripe, |
275 | !list_empty(&conf->inactive_list) && | 275 | !list_empty(&conf->inactive_list) && |
276 | (atomic_read(&conf->active_stripes) < (NR_STRIPES *3/4) | 276 | (atomic_read(&conf->active_stripes) |
277 | < (conf->max_nr_stripes *3/4) | ||
277 | || !conf->inactive_blocked), | 278 | || !conf->inactive_blocked), |
278 | conf->device_lock, | 279 | conf->device_lock, |
279 | unplug_slaves(conf->mddev); | 280 | unplug_slaves(conf->mddev); |
@@ -302,9 +303,31 @@ static struct stripe_head *get_active_stripe(raid6_conf_t *conf, sector_t sector | |||
302 | return sh; | 303 | return sh; |
303 | } | 304 | } |
304 | 305 | ||
305 | static int grow_stripes(raid6_conf_t *conf, int num) | 306 | static int grow_one_stripe(raid6_conf_t *conf) |
306 | { | 307 | { |
307 | struct stripe_head *sh; | 308 | struct stripe_head *sh; |
309 | sh = kmem_cache_alloc(conf->slab_cache, GFP_KERNEL); | ||
310 | if (!sh) | ||
311 | return 0; | ||
312 | memset(sh, 0, sizeof(*sh) + (conf->raid_disks-1)*sizeof(struct r5dev)); | ||
313 | sh->raid_conf = conf; | ||
314 | spin_lock_init(&sh->lock); | ||
315 | |||
316 | if (grow_buffers(sh, conf->raid_disks)) { | ||
317 | shrink_buffers(sh, conf->raid_disks); | ||
318 | kmem_cache_free(conf->slab_cache, sh); | ||
319 | return 0; | ||
320 | } | ||
321 | /* we just created an active stripe so... */ | ||
322 | atomic_set(&sh->count, 1); | ||
323 | atomic_inc(&conf->active_stripes); | ||
324 | INIT_LIST_HEAD(&sh->lru); | ||
325 | release_stripe(sh); | ||
326 | return 1; | ||
327 | } | ||
328 | |||
329 | static int grow_stripes(raid6_conf_t *conf, int num) | ||
330 | { | ||
308 | kmem_cache_t *sc; | 331 | kmem_cache_t *sc; |
309 | int devs = conf->raid_disks; | 332 | int devs = conf->raid_disks; |
310 | 333 | ||
@@ -316,45 +339,35 @@ static int grow_stripes(raid6_conf_t *conf, int num) | |||
316 | if (!sc) | 339 | if (!sc) |
317 | return 1; | 340 | return 1; |
318 | conf->slab_cache = sc; | 341 | conf->slab_cache = sc; |
319 | while (num--) { | 342 | while (num--) |
320 | sh = kmem_cache_alloc(sc, GFP_KERNEL); | 343 | if (!grow_one_stripe(conf)) |
321 | if (!sh) | ||
322 | return 1; | ||
323 | memset(sh, 0, sizeof(*sh) + (devs-1)*sizeof(struct r5dev)); | ||
324 | sh->raid_conf = conf; | ||
325 | spin_lock_init(&sh->lock); | ||
326 | |||
327 | if (grow_buffers(sh, conf->raid_disks)) { | ||
328 | shrink_buffers(sh, conf->raid_disks); | ||
329 | kmem_cache_free(sc, sh); | ||
330 | return 1; | 344 | return 1; |
331 | } | ||
332 | /* we just created an active stripe so... */ | ||
333 | atomic_set(&sh->count, 1); | ||
334 | atomic_inc(&conf->active_stripes); | ||
335 | INIT_LIST_HEAD(&sh->lru); | ||
336 | release_stripe(sh); | ||
337 | } | ||
338 | return 0; | 345 | return 0; |
339 | } | 346 | } |
340 | 347 | ||
341 | static void shrink_stripes(raid6_conf_t *conf) | 348 | static int drop_one_stripe(raid6_conf_t *conf) |
342 | { | 349 | { |
343 | struct stripe_head *sh; | 350 | struct stripe_head *sh; |
351 | spin_lock_irq(&conf->device_lock); | ||
352 | sh = get_free_stripe(conf); | ||
353 | spin_unlock_irq(&conf->device_lock); | ||
354 | if (!sh) | ||
355 | return 0; | ||
356 | if (atomic_read(&sh->count)) | ||
357 | BUG(); | ||
358 | shrink_buffers(sh, conf->raid_disks); | ||
359 | kmem_cache_free(conf->slab_cache, sh); | ||
360 | atomic_dec(&conf->active_stripes); | ||
361 | return 1; | ||
362 | } | ||
344 | 363 | ||
345 | while (1) { | 364 | static void shrink_stripes(raid6_conf_t *conf) |
346 | spin_lock_irq(&conf->device_lock); | 365 | { |
347 | sh = get_free_stripe(conf); | 366 | while (drop_one_stripe(conf)) |
348 | spin_unlock_irq(&conf->device_lock); | 367 | ; |
349 | if (!sh) | 368 | |
350 | break; | 369 | if (conf->slab_cache) |
351 | if (atomic_read(&sh->count)) | 370 | kmem_cache_destroy(conf->slab_cache); |
352 | BUG(); | ||
353 | shrink_buffers(sh, conf->raid_disks); | ||
354 | kmem_cache_free(conf->slab_cache, sh); | ||
355 | atomic_dec(&conf->active_stripes); | ||
356 | } | ||
357 | kmem_cache_destroy(conf->slab_cache); | ||
358 | conf->slab_cache = NULL; | 371 | conf->slab_cache = NULL; |
359 | } | 372 | } |
360 | 373 | ||
@@ -1912,6 +1925,74 @@ static void raid6d (mddev_t *mddev) | |||
1912 | PRINTK("--- raid6d inactive\n"); | 1925 | PRINTK("--- raid6d inactive\n"); |
1913 | } | 1926 | } |
1914 | 1927 | ||
1928 | static ssize_t | ||
1929 | raid6_show_stripe_cache_size(mddev_t *mddev, char *page) | ||
1930 | { | ||
1931 | raid6_conf_t *conf = mddev_to_conf(mddev); | ||
1932 | if (conf) | ||
1933 | return sprintf(page, "%d\n", conf->max_nr_stripes); | ||
1934 | else | ||
1935 | return 0; | ||
1936 | } | ||
1937 | |||
1938 | static ssize_t | ||
1939 | raid6_store_stripe_cache_size(mddev_t *mddev, const char *page, size_t len) | ||
1940 | { | ||
1941 | raid6_conf_t *conf = mddev_to_conf(mddev); | ||
1942 | char *end; | ||
1943 | int new; | ||
1944 | if (len >= PAGE_SIZE) | ||
1945 | return -EINVAL; | ||
1946 | if (!conf) | ||
1947 | return -ENODEV; | ||
1948 | |||
1949 | new = simple_strtoul(page, &end, 10); | ||
1950 | if (!*page || (*end && *end != '\n') ) | ||
1951 | return -EINVAL; | ||
1952 | if (new <= 16 || new > 32768) | ||
1953 | return -EINVAL; | ||
1954 | while (new < conf->max_nr_stripes) { | ||
1955 | if (drop_one_stripe(conf)) | ||
1956 | conf->max_nr_stripes--; | ||
1957 | else | ||
1958 | break; | ||
1959 | } | ||
1960 | while (new > conf->max_nr_stripes) { | ||
1961 | if (grow_one_stripe(conf)) | ||
1962 | conf->max_nr_stripes++; | ||
1963 | else break; | ||
1964 | } | ||
1965 | return len; | ||
1966 | } | ||
1967 | |||
1968 | static struct md_sysfs_entry | ||
1969 | raid6_stripecache_size = __ATTR(stripe_cache_size, S_IRUGO | S_IWUSR, | ||
1970 | raid6_show_stripe_cache_size, | ||
1971 | raid6_store_stripe_cache_size); | ||
1972 | |||
1973 | static ssize_t | ||
1974 | stripe_cache_active_show(mddev_t *mddev, char *page) | ||
1975 | { | ||
1976 | raid6_conf_t *conf = mddev_to_conf(mddev); | ||
1977 | if (conf) | ||
1978 | return sprintf(page, "%d\n", atomic_read(&conf->active_stripes)); | ||
1979 | else | ||
1980 | return 0; | ||
1981 | } | ||
1982 | |||
1983 | static struct md_sysfs_entry | ||
1984 | raid6_stripecache_active = __ATTR_RO(stripe_cache_active); | ||
1985 | |||
1986 | static struct attribute *raid6_attrs[] = { | ||
1987 | &raid6_stripecache_size.attr, | ||
1988 | &raid6_stripecache_active.attr, | ||
1989 | NULL, | ||
1990 | }; | ||
1991 | static struct attribute_group raid6_attrs_group = { | ||
1992 | .name = NULL, | ||
1993 | .attrs = raid6_attrs, | ||
1994 | }; | ||
1995 | |||
1915 | static int run(mddev_t *mddev) | 1996 | static int run(mddev_t *mddev) |
1916 | { | 1997 | { |
1917 | raid6_conf_t *conf; | 1998 | raid6_conf_t *conf; |
@@ -2095,6 +2176,7 @@ static int stop (mddev_t *mddev) | |||
2095 | shrink_stripes(conf); | 2176 | shrink_stripes(conf); |
2096 | kfree(conf->stripe_hashtbl); | 2177 | kfree(conf->stripe_hashtbl); |
2097 | blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ | 2178 | blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ |
2179 | sysfs_remove_group(&mddev->kobj, &raid6_attrs_group); | ||
2098 | kfree(conf); | 2180 | kfree(conf); |
2099 | mddev->private = NULL; | 2181 | mddev->private = NULL; |
2100 | return 0; | 2182 | return 0; |