dm.c (a794015597a2d9b437470c7692aac77e5fc08cd2) | dm.c (042d2a9bcd80fe12d4b0871706aa9dd2231e8238) |
---|---|
1/* 2 * Copyright (C) 2001, 2002 Sistina Software (UK) Limited. 3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. 4 * 5 * This file is released under the GPL. 6 */ 7 8#include "dm.h" --- 2019 unchanged lines hidden (view full) --- 2028{ 2029 set_capacity(md->disk, size); 2030 2031 mutex_lock(&md->bdev->bd_inode->i_mutex); 2032 i_size_write(md->bdev->bd_inode, (loff_t)size << SECTOR_SHIFT); 2033 mutex_unlock(&md->bdev->bd_inode->i_mutex); 2034} 2035 | 1/* 2 * Copyright (C) 2001, 2002 Sistina Software (UK) Limited. 3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. 4 * 5 * This file is released under the GPL. 6 */ 7 8#include "dm.h" --- 2019 unchanged lines hidden (view full) --- 2028{ 2029 set_capacity(md->disk, size); 2030 2031 mutex_lock(&md->bdev->bd_inode->i_mutex); 2032 i_size_write(md->bdev->bd_inode, (loff_t)size << SECTOR_SHIFT); 2033 mutex_unlock(&md->bdev->bd_inode->i_mutex); 2034} 2035 |
2036static int __bind(struct mapped_device *md, struct dm_table *t, 2037 struct queue_limits *limits) | 2036/* 2037 * Returns old map, which caller must destroy. 2038 */ 2039static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, 2040 struct queue_limits *limits) |
2038{ | 2041{ |
2042 struct dm_table *old_map; |
|
2039 struct request_queue *q = md->queue; 2040 sector_t size; 2041 unsigned long flags; 2042 2043 size = dm_table_get_size(t); 2044 2045 /* 2046 * Wipe any geometry if the size of the table changed. 2047 */ 2048 if (size != get_capacity(md->disk)) 2049 memset(&md->geometry, 0, sizeof(md->geometry)); 2050 2051 __set_size(md, size); 2052 | 2043 struct request_queue *q = md->queue; 2044 sector_t size; 2045 unsigned long flags; 2046 2047 size = dm_table_get_size(t); 2048 2049 /* 2050 * Wipe any geometry if the size of the table changed. 2051 */ 2052 if (size != get_capacity(md->disk)) 2053 memset(&md->geometry, 0, sizeof(md->geometry)); 2054 2055 __set_size(md, size); 2056 |
2053 if (!size) { 2054 dm_table_destroy(t); 2055 return 0; 2056 } 2057 | |
2058 dm_table_event_callback(t, event_callback, md); 2059 2060 /* 2061 * The queue hasn't been stopped yet, if the old table type wasn't 2062 * for request-based during suspension. So stop it to prevent 2063 * I/O mapping before resume. 2064 * This must be done before setting the queue restrictions, 2065 * because request-based dm may be run just after the setting. 2066 */ 2067 if (dm_table_request_based(t) && !blk_queue_stopped(q)) 2068 stop_queue(q); 2069 2070 __bind_mempools(md, t); 2071 2072 write_lock_irqsave(&md->map_lock, flags); | 2057 dm_table_event_callback(t, event_callback, md); 2058 2059 /* 2060 * The queue hasn't been stopped yet, if the old table type wasn't 2061 * for request-based during suspension. So stop it to prevent 2062 * I/O mapping before resume. 2063 * This must be done before setting the queue restrictions, 2064 * because request-based dm may be run just after the setting. 2065 */ 2066 if (dm_table_request_based(t) && !blk_queue_stopped(q)) 2067 stop_queue(q); 2068 2069 __bind_mempools(md, t); 2070 2071 write_lock_irqsave(&md->map_lock, flags); |
2072 old_map = md->map; |
|
2073 md->map = t; 2074 dm_table_set_restrictions(t, q, limits); 2075 write_unlock_irqrestore(&md->map_lock, flags); 2076 | 2073 md->map = t; 2074 dm_table_set_restrictions(t, q, limits); 2075 write_unlock_irqrestore(&md->map_lock, flags); 2076 |
2077 return 0; | 2077 return old_map; |
2078} 2079 2080/* 2081 * Returns unbound table for the caller to free. 2082 */ 2083static struct dm_table *__unbind(struct mapped_device *md) 2084{ 2085 struct dm_table *map = md->map; --- 277 unchanged lines hidden (view full) --- 2363 blk_end_request_all(rq, error); 2364 2365 blk_run_queue(q); 2366 2367 dm_put(md); 2368} 2369 2370/* | 2078} 2079 2080/* 2081 * Returns unbound table for the caller to free. 2082 */ 2083static struct dm_table *__unbind(struct mapped_device *md) 2084{ 2085 struct dm_table *map = md->map; --- 277 unchanged lines hidden (view full) --- 2363 blk_end_request_all(rq, error); 2364 2365 blk_run_queue(q); 2366 2367 dm_put(md); 2368} 2369 2370/* |
2371 * Swap in a new table (destroying old one). | 2371 * Swap in a new table, returning the old one for the caller to destroy. |
2372 */ | 2372 */ |
2373int dm_swap_table(struct mapped_device *md, struct dm_table *table) | 2373struct dm_table *dm_swap_table(struct mapped_device *md, struct dm_table *table) |
2374{ | 2374{ |
2375 struct dm_table *map; | 2375 struct dm_table *map = ERR_PTR(-EINVAL); |
2376 struct queue_limits limits; | 2376 struct queue_limits limits; |
2377 int r = -EINVAL; | 2377 int r; |
2378 2379 mutex_lock(&md->suspend_lock); 2380 2381 /* device must be suspended */ 2382 if (!dm_suspended(md)) 2383 goto out; 2384 2385 r = dm_calculate_queue_limits(table, &limits); | 2378 2379 mutex_lock(&md->suspend_lock); 2380 2381 /* device must be suspended */ 2382 if (!dm_suspended(md)) 2383 goto out; 2384 2385 r = dm_calculate_queue_limits(table, &limits); |
2386 if (r) | 2386 if (r) { 2387 map = ERR_PTR(r); |
2387 goto out; | 2388 goto out; |
2389 } |
|
2388 2389 /* cannot change the device type, once a table is bound */ 2390 if (md->map && 2391 (dm_table_get_type(md->map) != dm_table_get_type(table))) { 2392 DMWARN("can't change the device type after a table is bound"); 2393 goto out; 2394 } 2395 | 2390 2391 /* cannot change the device type, once a table is bound */ 2392 if (md->map && 2393 (dm_table_get_type(md->map) != dm_table_get_type(table))) { 2394 DMWARN("can't change the device type after a table is bound"); 2395 goto out; 2396 } 2397 |
2396 map = __unbind(md); 2397 r = __bind(md, table, &limits); 2398 dm_table_destroy(map); | 2398 map = __bind(md, table, &limits); |
2399 2400out: 2401 mutex_unlock(&md->suspend_lock); | 2399 2400out: 2401 mutex_unlock(&md->suspend_lock); |
2402 return r; | 2402 return map; |
2403} 2404 2405/* 2406 * Functions to lock and unlock any filesystem running on the 2407 * device. 2408 */ 2409static int lock_fs(struct mapped_device *md) 2410{ --- 361 unchanged lines hidden --- | 2403} 2404 2405/* 2406 * Functions to lock and unlock any filesystem running on the 2407 * device. 2408 */ 2409static int lock_fs(struct mapped_device *md) 2410{ --- 361 unchanged lines hidden --- |